Skip to content

FIX: ImportWallet and ImportSpeed derive the same seed at different paths - #151

Merged
theanmolsharma merged 2 commits into
CypherCommons:masterfrom
chaitika:fix/import-derivation-path-mismatch
Sep 2, 2026
Merged

FIX: ImportWallet and ImportSpeed derive the same seed at different paths#151
theanmolsharma merged 2 commits into
CypherCommons:masterfrom
chaitika:fix/import-derivation-path-mismatch

Conversation

@chaitika

@chaitika chaitika commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Problem

ImportWallet.tsx and ImportSpeed.tsx both build an HDSilentPaymentsWallet from a mnemonic (setSecret + validate), but only ImportWallet.tsx called setDerivationPath("m/84'/0'/0'") afterward. ImportSpeed.tsx never did, so it fell through to HDTaprootWallet's class default (m/86'/0'/0'). Same seed, imported through the two screens, watched two different sets of addresses.

ImportSpeed.tsx also threw a hardcoded English error string instead of using loc.

Fix

  • Added HDSilentPaymentsWallet.fromMnemonic(mnemonic), a shared factory both screens now call. It doesn't override the derivation path — both land on the class default m/86'/0'/0', one source of truth instead of two that can drift.
  • ImportSpeed.tsx's error now uses loc.wallet_birth.error_invalid_mnemonic (same key ImportWallet.tsx already uses for this case).

Left the pre-existing dead validation condition in ImportWallet.tsx (!wallet.validateMnemonic() && !wallet.getSecret()) untouched — that's #145's fix, out of scope here.

Testing

New fromMnemonic block in tests/unit/bip352.test.ts:

  • Asserts the factory derives at m/86'/0'/0'.
  • Cross-checked its xpub/address output against hd-taproot-wallet.test.ts's independent HDTaprootWallet fixture for the same mnemonic — exact match.
  • Confirms ImportWallet.tsx and ImportSpeed.tsx now produce byte-identical wallets for the same seed.

npm run lint && npm run tslint && npm run unit pass.

Copilot AI lite review requested due to automatic review settings September 1, 2026 08:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR unifies how HDSilentPaymentsWallet instances are constructed from a mnemonic across the two import screens to ensure both screens derive the same wallet (same derivation path and addresses), and aligns ImportSpeed’s invalid-mnemonic error with the existing localized string used elsewhere.

Changes:

  • Added HDSilentPaymentsWallet.fromMnemonic(mnemonic) factory and updated both import screens to use it (removing ImportWallet’s prior hardcoded m/84'/0'/0' override so both rely on the BIP86 default m/86'/0'/0').
  • Localized ImportSpeed’s invalid mnemonic error using loc.wallet_birth.error_invalid_mnemonic.
  • Added unit tests covering the new factory behavior and ensuring it matches manual setup for the same mnemonic.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
class/wallets/hd-bip352-wallet.ts Adds fromMnemonic() factory to centralize mnemonic-based wallet construction without overriding derivation path.
screen/wallets/ImportWallet.tsx Switches import flow to use fromMnemonic() (removing the previous hardcoded derivation path).
screen/wallets/ImportSpeed.tsx Switches import flow to use fromMnemonic() and replaces hardcoded English error with loc.
tests/unit/bip352.test.ts Adds tests verifying fromMnemonic() uses the BIP86 default path and matches manual setup outputs.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread screen/wallets/ImportWallet.tsx Outdated
Comment thread class/wallets/hd-bip352-wallet.ts Outdated
Comment thread class/wallets/hd-bip352-wallet.ts Outdated
Comment thread screen/wallets/ImportWallet.tsx Outdated
Comment thread screen/wallets/ImportSpeed.tsx Outdated
Comment thread screen/wallets/ImportWallet.tsx Outdated
Comment thread tests/unit/bip352.test.ts Outdated
Comment thread tests/unit/bip352.test.ts Outdated
chaitika and others added 2 commits September 2, 2026 10:32
…aths

ImportWallet.tsx forced m/84'/0'/0' after setSecret; ImportSpeed.tsx
never overrode the path, so it fell through to HDTaprootWallet's
m/86'/0'/0' default. Same seed, imported via the two screens, watched
two different sets of addresses.

Adds HDSilentPaymentsWallet.fromMnemonic(mnemonic), a shared factory
both screens now call, deliberately not overriding the derivation
path so both land on the class default. Also fixes ImportSpeed.tsx's
hardcoded English error string to use loc.
- hd-bip352-wallet.ts: add static readonly derivationPath, override
  setDerivationPath to throw (SP wallets never move off BIP-86), and let
  fromMnemonic take an optional passphrase
- ImportSpeed.tsx: invalid-mnemonic path now uses presentAlert + return
  (matching ImportWallet.tsx) instead of throw/catch with an untitled
  bare-message alert; passphrase passed into the factory instead of a
  separate setPassphrase call
- ImportWallet.tsx: drop redundant .trim() (setSecret already trims)
- bip352.test.ts: split the derivation-path invariant into its own
  describe block (was previously exercising the constructor default
  under a misleading 'fromMnemonic' describe), replace the tautological
  factory-vs-manual-setup comparison with a golden-vector test
  cross-checked against hd-taproot-wallet.test.ts's independent fixture
- importWallet.test.tsx: fix a pre-existing assertion still expecting
  the old m/84' path this PR removes

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S9qoCZXTiuCXN2GXZANv7C
Copilot AI review requested due to automatic review settings September 2, 2026 08:28
@chaitika
chaitika force-pushed the fix/import-derivation-path-mismatch branch from 8ce71d6 to 29a11d5 Compare September 2, 2026 08:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@theanmolsharma
theanmolsharma merged commit e2e2527 into CypherCommons:master Sep 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants