fix(signer): sanitize chain state on reconnect to prevent stale address#345
Open
mehmetkr-31 wants to merge 1 commit into
Open
fix(signer): sanitize chain state on reconnect to prevent stale address#345mehmetkr-31 wants to merge 1 commit into
mehmetkr-31 wants to merge 1 commit into
Conversation
When a Signer is reconstructed after cleanup (e.g., reconnect), the constructor reads account.chain from the store. If the store was cleared, account.chain is undefined and the fallback used params.metadata.appChainIds which could be stale or missing, defaulting to chain id 1 (mainnet). This caused two problems: 1. Incorrect public address returned after reconnect on Base (chain id 8453) 2. handleGetCapabilitiesRequest failing because accounts array was empty until the next successful handshake The fix prefers the chains array already registered in the store before falling back to metadata, ensuring the correct chain context is preserved across reconnect cycles.
Collaborator
🟡 Heimdall Review Status
|
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.
Summary
Fixes #214 — incorrect or missing public address after reconnecting signer.
Root Cause
When
Signeris reconstructed aftercleanup()(e.g., page reload + reconnect):account.chainfrom the store.cleanup(),account.chainisundefined.params.metadata.appChainIds?.[0] ?? 1could be stale, missing, or default to chain id 1 (Ethereum mainnet) even when the user was on Base (8453).this.accountsto remain empty until the next handshake, andhandleGetCapabilitiesRequestto throwunauthorized.Fix
Prefer the
chainsarray already registered in the store before falling back to constructor metadata:Constructor:
cleanup():
This ensures the correct chain context (e.g., Base mainnet 8453) is preserved across reconnect cycles instead of silently falling back to Ethereum mainnet.
Test Plan
yarn workspace @base-org/account test --run→ 999/999 passRelated Issues