Skip to content

Support four-letter BIP-39 prefixes during wallet import - #56

Open
dasdur-topmex wants to merge 1 commit into
nockbox:mainfrom
dasdur-topmex:feat/bip39-four-letter-prefix-import
Open

dasdur-topmex wants to merge 1 commit into
nockbox:mainfrom
dasdur-topmex:feat/bip39-four-letter-prefix-import

Conversation

@dasdur-topmex

Copy link
Copy Markdown

Summary

  • Accept unique four-letter prefixes for English BIP-39 words when restoring or importing V1 wallets.
  • Preserve exact complete words, exact four-character words, and valid words shorter than four characters.
  • Canonicalize the full mnemonic before duplicate checks, wallet derivation, and encrypted persistence.
  • Reject malformed, ambiguous, and non-ASCII tokens while retaining the existing BIP-39 checksum validation.

Implementation

  • Adds a shared normalizeAndValidateMnemonic helper using the existing English BIP-39 wordlist.
  • Applies normalization at the final import-screen submission boundary.
  • Repeats normalization at Vault.setup and Vault.createMnemonicSeedSource as the authoritative wallet boundary.
  • Uses the canonical full mnemonic for duplicate detection, hidden-seed restoration, derivation, and storage.
  • Preserves the existing field layout, keyboard behavior, phrase paste behavior, error presentation, and keyfile workflow.
  • Uses ASCII-only case handling so Unicode compatibility characters cannot case-fold into accepted English words or prefixes.

Scope

This change covers the V1 wallet flows for:

  • Initial wallet restoration
  • Adding another mnemonic seed
  • Manual 24-field entry
  • Full-phrase paste
  • Mixed complete-word and prefix input
  • Keyfile mnemonic import

The separate V0 migration flow is intentionally unchanged.

This change does not modify:

  • Mnemonic generation or entropy
  • BIP-39 checksum rules
  • Key derivation or wallet cryptography
  • WASM bindings
  • Storage schemas
  • Background message contracts
  • Dependencies or lockfiles

Validation

Repository checks

  • npm ci
  • npm run typecheck
  • npm run format:check
  • npm run build
  • git diff --check

The repository does not currently define an automated test runner or lint command.

Focused production-helper validation

  • Actual exported helper: 17/17 cases passed
  • Unicode case-fold rejection: 2/2 cases passed
  • Current English wordlist: 0 ambiguous four-letter prefixes

Coverage included:

  • Full canonical phrases
  • All-prefix phrases
  • Mixed full/prefix phrases
  • ASCII uppercase and whitespace normalization
  • Exact short words
  • Exact four-character words
  • Invalid short, long, punctuation, Unicode, and checksum cases
  • Idempotent canonicalization

Manual extension validation

Tested in an isolated disposable Brave profile using the unpacked production build:

  • Full-word and four-letter forms restored the same wallet identity
  • Mixed complete-word and prefix entry
  • Full, prefix, and mixed phrase paste
  • Exact short and exact four-character BIP-39 words
  • Invalid four-character prefix rejection
  • Invalid short-fragment rejection
  • Invalid longer-token rejection without truncation
  • Checksum-invalid phrase rejection
  • Duplicate-seed detection for full and shorthand forms
  • Keyfile shorthand import
  • Generated-wallet creation regression
  • ASCII uppercase shorthand
  • Unicode compatibility-character rejection

Security

Only public BIP-39 vectors and disposable wallet data were used during validation. No real mnemonic, private key, or production wallet data was used or committed.

Screenshots

Not applicable. This changes accepted import input behavior without changing the visual layout, and the repository does not document a screenshot requirement.

Maintainer Notes

  • Exact BIP-39 word membership takes precedence over four-letter-prefix expansion.
  • Prefix expansion applies only to non-exact tokens containing exactly four ASCII letters.
  • The existing BIP-39 validator remains authoritative for phrase length and checksum validity.
  • V0 migration support is intentionally outside this pull request.

Normalize valid English BIP-39 prefixes before wallet validation, derivation, duplicate checks, and persistence.
@greptile-apps

greptile-apps Bot commented Aug 25, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds canonical normalization of English BIP-39 mnemonics so wallet imports accept unique four-letter prefixes while preserving strict checksum validation.

  • Adds a shared ASCII-only mnemonic normalization and validation helper.
  • Normalizes manual and keyfile imports before submission.
  • Revalidates and persists canonical phrases at both authoritative vault creation boundaries.
  • Uses canonical phrases for address derivation and duplicate-seed detection.

Confidence Score: 5/5

The PR appears safe to merge, with canonical mnemonic handling consistently applied before wallet derivation and persistence.

Exact words retain precedence, shorthand tokens are restricted to four ASCII letters, the completed phrase must pass the existing BIP-39 validator, and all downstream vault operations use the same canonical value.

Important Files Changed

Filename Overview
extension/popup/screens/onboarding/ImportScreen.tsx Applies ASCII-only case normalization and canonical mnemonic validation at the final manual and keyfile import boundary without changing the surrounding flow contract.
extension/shared/vault.ts Canonicalizes mnemonics before duplicate checks, derivation, return values, and encrypted persistence in both vault setup and seed-source creation.
extension/shared/wallet-crypto.ts Adds exact-word-first expansion of unique four-letter English prefixes and retains authoritative BIP-39 checksum validation.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Manual phrase or V1 keyfile] --> B[Import screen normalization]
  B --> C{Valid English words or unique four-letter prefixes?}
  C -- No --> D[Show invalid phrase error]
  C -- Yes --> E[Canonical full mnemonic]
  E --> F[Vault boundary normalization]
  F --> G{BIP-39 checksum valid?}
  G -- No --> H[Reject import]
  G -- Yes --> I[Duplicate detection]
  I --> J[Address derivation]
  J --> K[Encrypted canonical persistence]
Loading

Reviews (1): Last reviewed commit: "feat: support four-letter BIP-39 prefixe..." | Re-trigger Greptile

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.

1 participant