Skip to content

feat(wallet): derive PrivateKey/Wallet from BIP-39 mnemonic#429

Open
ozpool wants to merge 1 commit into
solana-foundation:mainfrom
ozpool:feat/wallet-from-mnemonic
Open

feat(wallet): derive PrivateKey/Wallet from BIP-39 mnemonic#429
ozpool wants to merge 1 commit into
solana-foundation:mainfrom
ozpool:feat/wallet-from-mnemonic

Conversation

@ozpool
Copy link
Copy Markdown

@ozpool ozpool commented May 11, 2026

Summary

Closes #297. Two community members have asked for an in-tree way to recover a Solana key from a mnemonic. Today every consumer rolls their own combination of a BIP-39 library and SLIP-0010 derivation, with the extra friction that BIP-32 is secp256k1-only and does not apply to ed25519.

This adds:

  • PrivateKeyFromMnemonic(mnemonic, passphrase) — uses the Phantom default path m/44'/501'/0'/0'
  • PrivateKeyFromMnemonicAtPath(mnemonic, passphrase, path) — custom SLIP-0010 path
  • PrivateKeyFromSeedAtPath(seed, path) — for callers that already have their own seed bytes
  • NewWalletFromMnemonic(mnemonic, passphrase) — convenience wrapper around the existing Wallet type
  • SolanaDerivationPath constant ("m/44'/501'/0'/0'")

Design notes

  • Mnemonic → seed: uses github.com/tyler-smith/go-bip39 (the de facto Go BIP-39 implementation, also used by btcsuite/btcd/btcutil/hdkeychain and Cosmos SDK forks). Single new direct dependency.
  • Seed → ed25519 key: in-tree SLIP-0010 implementation. SLIP-0010 ed25519 only defines hardened derivation and is small enough (~40 LOC) not to warrant pulling in a generic HD-key library.
  • Final seed → keypair: goes through the existing oasisprotocol/curve25519-voi ed25519, so the result is bit-identical to NewRandomPrivateKey output and works with the existing Sign / Validate / PublicKey methods unchanged.
  • All existing public API is untouched; this is purely additive.

Test plan

  • Official SLIP-0010 ed25519 vectors from satoshilabs/slips:
    • vector 1: m, m/0', m/0'/1', m/0'/1'/2', m/0'/1'/2'/2', m/0'/1'/2'/2'/1000000000'
    • vector 2: m, m/0'
  • Derivation-path parsing (empty / default / h / H / ' suffixes, non-hardened rejection, malformed input)
  • Mnemonic validation, determinism, passphrase sensitivity, path sensitivity
  • End-to-end Sign/Verify against the derived key
  • go vet ./... (only pre-existing warnings in rpc/ws/examples/...)
  • gofmt -l clean
  • Full root-package test suite passes

Closes solana-foundation#297. Two community members have requested an in-tree way to
recover a Solana key from a mnemonic; today every consumer rolls their
own combination of a BIP-39 library and SLIP-0010 derivation, with the
extra friction that BIP-32 is secp256k1-only and does not apply to
ed25519.

This adds:

  - PrivateKeyFromMnemonic(mnemonic, passphrase)            — Phantom default path m/44'/501'/0'/0'
  - PrivateKeyFromMnemonicAtPath(mnemonic, passphrase, path)
  - PrivateKeyFromSeedAtPath(seed, path)                    — for callers with their own seed
  - NewWalletFromMnemonic(mnemonic, passphrase)
  - SolanaDerivationPath constant ("m/44'/501'/0'/0'")

Mnemonic -> seed uses tyler-smith/go-bip39 (the de facto Go BIP-39
implementation, also used by btcsuite/btcd/btcutil/hdkeychain and
cosmos-sdk forks). Seed -> ed25519 key uses an in-tree SLIP-0010
implementation, since SLIP-0010 ed25519 only defines hardened
derivation and is small enough not to warrant pulling in a generic
HD-key library. Final seed -> keypair goes through the existing
oasisprotocol/curve25519-voi ed25519, so the result is bit-identical
to NewRandomPrivateKey output and works with the existing Sign /
Validate / PublicKey methods unchanged.

Tests cover:
  - the official SLIP-0010 ed25519 vectors (vector 1: m, m/0', m/0'/1',
    m/0'/1'/2', m/0'/1'/2'/2', m/0'/1'/2'/2'/1000000000'; vector 2: m,
    m/0') from satoshilabs/slips
  - derivation-path parsing (empty, default, h/H/' suffixes,
    non-hardened rejection, malformed input)
  - mnemonic validation, determinism, passphrase sensitivity, path
    sensitivity, and end-to-end Sign/Verify against the derived key
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.

Feature Request: Add method to generate Solana wallet from Mnemonic

1 participant