fix: prevent seed replacement when retrieveSeed fails during unlock#12
Open
ben-kaufman wants to merge 1 commit intotetherto:mainfrom
Open
fix: prevent seed replacement when retrieveSeed fails during unlock#12ben-kaufman wants to merge 1 commit intotetherto:mainfrom
ben-kaufman wants to merge 1 commit intotetherto:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
WDKService.createWallet()is used for both wallet creation and unlock. WhenretrieveSeed()returns null, it silently falls back tocreateSeed(), generating a new random seed and overwriting the existing one in Keychain.During the unlock flow,
unlockWallet()inwallet-context.tsxcallsWDKService.createWallet()directly. IfretrieveSeed()fails (biometric cancelled, Keychain corrupted after iOS passcode change, partial storage loss), the user's wallet is silently replaced. All funds become inaccessible with no error shown.Why the fallback is dead code during creation
The context-layer
createWallet()already callsWDKService.createSeed()orWDKService.importSeedPhrase()beforeWDKService.createWallet(). By the time the service method runs, the seed is already stored andretrieveSeed()will succeed. ThecreateSeed()fallback never executes in the creation path.WDKService.createWallet()main role is not to generate seeds, but to initializes the WDK worklet using a previously stored seed. Seed generation is handled upstream bycreateSeed()orimportSeedPhrase(), which the context-layer wrapper always calls before reaching this method.Why the fallback is destructive during unlock
unlockWallet()callsWDKService.createWallet()with no prior seed creation step. IfretrieveSeed()returns null:createSeed()generates new random entropyWDK_STORAGE_ENTROPY,WDK_STORAGE_SEED, andWDK_STORAGE_SALTin Keychain, there's no "already exists" guardretrieveSeed()returns null for benign reasonsIt checks three Keychain entries (
entropy,seed,salt). If any one is missing, for example due to partial Keychain corruption, failed migration, or biometric access timeout, it returns null. None of these warrant replacing the wallet.Fix
In
WDKService.createWallet(), replace thecreateSeed()fallback with a thrown error:let seed = await this.retrieveSeed(params.prf); if (!seed) { - seed = await this.createSeed(params); + throw new Error('Seed retrieval failed. Please restore from recovery phrase.'); }