8000 feat(bip39): stretch any text by aeitwoen · Pull Request #441 · agntn/keys · GitHub
[go: up one dir, main page]

Skip to content

feat(bip39): stretch any text - #441

Merged
oritwoen merged 5 commits into
mainfrom
feat/bip39-any-text
Nov 28, 2026
Merged

oritwoen merged 5 commits into
mainfrom
feat/bip39-any-text

Conversation

@aeitwoen
@aeitwoen aeitwoen commented Nov 28, 2026 •
Copy link
Copy Markdown
Collaborator

🔸 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".

View guided diff


Read this PR faster    Follow each request

@aeitwoen
aeitwoen requested a review from oritwoen as a code owner November 28, 2026 16:41
@aeitwoen aeitwoen self-assigned this Nov 28, 2026
@coldtea-pr-lens
coldtea-pr-lens Bot commented Nov 28, 2026 •
Copy link
Copy Markdown
  • Redraw · drawn at 00db696, the branch has moved on

Architecture

Walkthrough of Electrum-style anyText stretching for BIP39 seeds and HD wallets, in five steps

Read this PR faster

Inside the changed components — 1 view

Component view — Derivation Engine

Internal modules handling phrase evaluation, PBKDF2 stretching, and blockchain warnings

Architecture view of Component view — Derivation Engine in agntn/keys

Data flow

Data flow diagram for agntn/keys at 00db696

Follow each request


Review

✨ Nothing flagged · reviewed 00db696


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
  • Run npx skills add coldteadotai/pr-lens, then tell your coding agent: "Diagram the change you just made with PR Lens and attach it to the pull request."
  • Run npx @coldtea/pr-lens-cli analyze --base origin/main on a branch, then npx @coldtea/pr-lens-cli render .pr-lens/graph.json. Same lenses, your own model key, before the pull request exists
  • Click the link under each diagram to open it on a canvas you can zoom, pan and step through
  • Open a diagram on the canvas, then press W or click play to walk through the change one step at a time
  • The CLI's render reads .github/pr-lens.yml and applies your renames, exclusions and lane pins at draw time
  • Set github.comment.collapsed: true in .github/pr-lens.yml to fold the comment behind one View architecture… row. Drawing still runs as before
  • Set github.draw: on-demand in .github/pr-lens.yml and PR Lens stops drawing pull requests on its own. Comment @pr-lens draw on a pull request when you want that one drawn
  • Add .github/workflows/pr-lens.yml with coldteadotai/pr-lens/packages/action@v0 and your model provider's key as its api-key to run PR Lens from your own CI. Any /chat/completions endpoint works
  • After a push, tick Redraw to draw the latest commit
  • Switch GitHub to dark mode and the diagrams follow. The moving dots are this pull request's data in motion
  • Set github.description: false in .github/pr-lens.yml to stop PR Lens adding buttons to your PR descriptions

Thanks for using PR Lens! It's free for OSS. If it helped, a star helps other teams find it.  Star PR Lens on GitHub

@chatgpt-codex-connector
chatgpt-codex-connector Bot commented Nov 28, 2026 •
Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T17:11:01.240474Z 4bd4d8e New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cubic-dev-ai cubic-dev-ai Bot 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.

cubic analysis

1 issue found across 18 files

Confidence score: 4/5

  • In src/tools.ts, the anyText description implies it works with every chain, but setting it with chain: "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
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread README.md Resolved
Comment thread test/mcp.test.ts Resolved
Comment thread src/tools.ts Resolved
Comment thread src/tool-schemas.ts Resolved
Comment thread extensions/pi/README.md Resolved
Comment thread src/utils/hd.ts Resolved
@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 7 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread test/mcp.test.ts Resolved
@cubic-dev-ai cubic-dev-ai Bot 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.

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

@cubic-dev-ai cubic-dev-ai Bot 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.

Auto-approved.

@oritwoen
oritwoen merged commit 391506a into main Nov 28, 2026
4 checks passed
@oritwoen
oritwoen deleted the feat/bip39-any-text branch November 28, 2026 17:57
@github-actions github-actions Bot mentioned this pull request Nov 28, 2026
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.

Derive BIP39 seeds from text outside the word list

2 participants

0