S2: BIP-39 mnemonics (Bitcoinex.BIP39)#109
Draft
SachinMeier wants to merge 2 commits into
Draft
Conversation
Collaborator
Author
|
Independent adversarial review (subagent) complete: no CRITICAL/MAJOR findings. All 24 inlined vectors re-verified against upstream (zero drift); independent Python BIP-39 implementation matched on mnemonic/seed/round-trip at all 5 entropy lengths with a Unicode passphrase. Addressed in the follow-up commit:
|
Add Bitcoinex.BIP39 with entropy_to_mnemonic/1, mnemonic_to_entropy/1, valid?/1, to_seed/2, and to_master_private_key/3. The english word list is loaded at compile time via Bitcoinex.Wordlist.load!/2 from priv/bip39_english.txt; seeds are derived with PBKDF2-HMAC-SHA512 (2048 iterations, 64 bytes) over the NFKD-normalized mnemonic and passphrase, and master keys via ExtendedKey.seed_to_master_private_key/2. Tests transcribe all 24 official Trezor english vectors inline as @bip39_vectors (test/data/bip39_vectors.json removed) and cover every error atom, NFKD normalization, seed/xprv derivation, plus stream_data properties: entropy round-trips for all five lengths, decoder fuzzing on arbitrary strings and random valid-word sequences, and 1-3 word substitutions never decoding to the original entropy. Also add a CHANGELOG Unreleased entry for BIP-39. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- reject non-canonical whitespace in mnemonic_to_entropy (single-space
separators only, matching the reference implementation) so validation
can never bless a mnemonic whose byte-exact seed differs from the
canonical form
- raise a clear ArgumentError on non-UTF8 mnemonic/passphrase in to_seed
- return {:error, "invalid extended private key prefix"} for unknown
prefix atoms instead of crashing in ExtendedKey
- drop redundant bare function head
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
421dd8f to
f259342
Compare
9896406 to
6b4eeab
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack: S0 → S1 → S2 → S3 → S4 → S5 → S6 (spec §3.2)
Bitcoinex.BIP39: entropy↔mnemonic with checksum validation,valid?/1,to_seed/2(PBKDF2-HMAC-SHA512, NFKD on mnemonic+passphrase),to_master_private_key/3feedingExtendedKey.seed_to_master_private_key/2🤖 Generated with Claude Code