Repository navigation
feat(bip39): stretch any text - #441
Conversation
Architecture Inside the changed components — 1 viewComponent view — Derivation Engine Internal modules handling phrase evaluation, PBKDF2 stretching, and blockchain warnings
Data flow Review ✨ Nothing flagged · reviewed Tip The diagrams are links. Click one to open it on the canvas, then press W or click play to walk through the change 🪧 More tips
Thanks for using PR Lens! It's free for OSS. If it helped, a star helps other teams find it. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
cubic analysis
1 issue found across 18 files
Confidence score: 4/5
- In
src/tools.ts, theanyTextdescription implies it works with every chain, but setting it withchain: "polkadot"throws. Update the description to call out the Polkadot exception.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/tools.ts">
<violation number="1" location="src/tools.ts:254">
P2: This description makes `anyText` sound available for every chain, but selecting `chain: "polkadot"` still throws when the flag is set. Mention the Polkadot exception so callers do not follow this description into a guaranteed error.</violation>
</file>
Linked issue analysis
Linked issue: agntn/keys#439: Derive BIP39 seeds from text outside the word list
| Status | Acceptance criteria | Notes |
|---|---|---|
| ✅ | Opt in to stretching text without BIP39 word checks | anyText routes invalid phrases through text stretching, while the default path still rejects them. |
| ✅ | Derive the expected NFKD BIP39 PBKDF2 seed | The anyText vectors verify the specified seed, including the issue's example text and empty passphrase. |
| ✅ | Expose the option in seed, wallet, and scan tools | The tool schemas and handlers accept anyText, and MCP tests cover seed derivation, wallet derivation, and scanning. |
Architecture diagram
sequenceDiagram
participant Tool as Agent Tools (keys_bip39_seed_derive, keys_hd_wallet_derive, keys_hd_wallet_scan)
participant Args as Argument Validation
participant BIP39 as BIP39 Utils
participant HD as HD Wallet Utils
participant Blockchain as Blockchain Layer
participant Polkadot as Polkadot Chain
Note over Tool,Polkadot: anyText: stretch any text as Electrum's BIP39 option
Tool->>Args: Pass mnemonic + anyText flag
Args->>Args: booleanFlag(anyText) validation
alt anyText = true
Args->>BIP39: inspectBIP39Mnemonic(text)
BIP39-->>Args: Inspection result (invalid, checksumValid null)
Args->>Args: readPhrase() - checks anyText override
alt Valid BIP39 phrase
Args->>BIP39: mnemonicToSeed(phrase, { anyText: false })
BIP39-->>Args: Standard BIP39 seed
Args-->>Tool: Seed, no warnings
else Invalid phrase but anyText = true
Args->>BIP39: mnemonicToSeed(text, { anyText: true })
BIP39->>BIP39: stretchText() - PBKDF2 with BIP39 rounds
BIP39-->>Args: Seed from stretched text
Args-->>Tool: Seed + ANY_TEXT_WARNING
end
else anyText = false (default)
Args->>BIP39: inspectBIP39Mnemonic(text)
BIP39-->>Args: Inspection (invalid)
Args-->>Tool: Error: Invalid BIP39 mnemonic
end
Note over Tool,HD: HD Wallet Derivation Flow
Tool->>HD: deriveMnemonicKey(mnemonic, { anyText })
HD->>HD: mnemonicSeed() - readPhrase() decision
alt Read as text
HD->>BIP39: mnemonicToSeed(text, { anyText: true })
BIP39-->>HD: Seed + readAsText: true
HD->>HD: deriveSeedKey(seed, path)
HD-->>Blockchain: privateKey + readAsText flag
Blockchain->>Blockchain: Add ANY_TEXT_WARNING to wallet
Blockchain-->>Tool: Wallet with warning
else Valid phrase (even with anyText)
HD->>BIP39: mnemonicToSeed(phrase, { anyText: false })
BIP39-->>HD: Standard seed
HD->>HD: deriveSeedKey(seed, path)
HD-->>Blockchain: privateKey, no readAsText
Blockchain-->>Tool: Wallet, BIP39 warnings only
end
Note over Polkadot: Polkadot refusal when anyText = true
Tool->>Polkadot: deriveHDWallet(mnemonic, { anyText: true })
alt anyText true
Polkadot-->>Tool: Error: "drop anyText" (needs BIP39 entropy)
else anyText false/undefined
Polkadot->>Polkadot: Normal BIP39 entropy derivation
end
Note over Tool,Blockchain: HD Wallet Scan Flow
Tool->>HD: scanHdWallet with anyText
HD->>HD: bip39ScanSource() - readPhrase() with allowInvalidChecksum + anyText
alt anyText = true and not valid
HD->>BIP39: mnemonicToSeed(text, { anyText: true })
BIP39-->>HD: Seed
HD->>HD: Scan addresses with seed
HD-->>Tool: Scan results + ANY_TEXT_WARNING
else anyText = false
HD-->>Tool: Skip with invalid mnemonic reason
end
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 7 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 2 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Requires human review: Auto-approval blocked by 2 unresolved issues from previous reviews.
Re-trigger cubic
🔸 What this resolves
Closes #439
🔶 Why it's needed
This adds
anyText, which stretches any text into a BIP39 seed the way Electrum's "BIP39 seed" option does, where the library used to stop at "Invalid mnemonic".