fix: hydrate wallet state from SecureStore on cold start (fixes #34) - #58
Open
mac-dubem wants to merge 1 commit into
Open
fix: hydrate wallet state from SecureStore on cold start (fixes #34)#58mac-dubem wants to merge 1 commit into
mac-dubem wants to merge 1 commit into
Conversation
…-Wal#34) - Add hydrate() action to walletStore that reads secret from SecureStore and restores publicKey/isOnboarded before routing decisions - Update app/index.tsx to await hydration before rendering redirect, showing a loading spinner during the async check - No plaintext secret stored outside SecureStore — only the derived publicKey enters the zustand store - Regression test: verifies cold start with pre-existing SecureStore entry restores onboarded state; verifies no secret leaves state as not onboarded
5 tasks
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.
Root cause
useWalletStoreis a plain zustand store with no persistence middleware —isOnboardeddefaults tofalseon every cold start.app/index.tsxreads that in-memory flag synchronously to decide the initial route, so even whensecureStorage.tsholds a valid secret from a previous session, the app always redirects to/auth/welcome.Design decision
Instead of adding persistence middleware (which would either store the secret in plaintext via AsyncStorage or require a serialization layer), the fix adds an explicit
hydrate()action that runs once on mount:publicKeyviaStellarSdk.Keypair.fromSecret()and setisOnboarded: trueThe secret never enters the zustand store — only the derived public key and the boolean flag are stored in memory. Plaintext persistence outside SecureStore is avoided entirely.
Definition of done
walletStore.hydrate()reads from SecureStore viagetSecretKey()and restores state before routingpublicKeyis derived andisOnboardedset totrue; otherwise defaults remainpublicKey(not the secret) is stored in the zustand store; the secret stays in SecureStoresrc/store/__tests__/walletStore.test.tscovers both paths — secret present (onboarded restored) and secret absent (stays not onboarded)Evidence
All 16 tests pass (4 suites):
Adjacent behavior verified
app/auth/create.tsx): unchanged — still saves secret to SecureStore and callssetOnboarded(true)/setPublicKey()directlyapp/auth/import.tsx): unchanged — same pattern as create/auth/welcome,/tabs/home) unchanged; only the decision point inapp/index.tsxnow waits for hydrationCloses #34