pqbip39
A no_std compatible Rust implementation of the BIP-39 mnemonic code standard for generating and validating mnemonic phrases used in cryptocurrency wallets.
Features
- Supports 12 to 33-word mnemonic phrases
- Generates seeds from mnemonics using PBKDF2
- Validates checksums and word counts
- Converts between entropy and mnemonic phrases
- Compatible with
no_stdenvironments - Optional
stdandzeroizefeatures - Full mnemonic secret protection via
secrecycrate — phrases, seeds, and entropy are wrapped inSecretString/SecretBox/SecretSlice
Installation
Add the following to your Cargo.toml:
[]
= "0.2.0"
Usage
Generating a Mnemonic
use ;
use OsRng;
const EN_WORDS: = ;
let mut rng = OsRng;
let mnemonic = generate.unwrap;
let phrase = mnemonic.to_phrase; // SecretString
println!;
Parsing a Mnemonic
use Mnemonic;
use SecretString;
const EN_WORDS: = ;
let phrase = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
let mnemonic = parse_str.unwrap;
Parsing without Checksum Validation
let mnemonic = parse_str_without_checksum.unwrap;
Converting to Seed
let seed = mnemonic.to_seed.unwrap;
// seed is SecretBox<[u8; 64]>, access via .expose_secret()
Converting to Entropy
let entropy = mnemonic.to_entropy; // SecretSlice<u8>
let bytes = entropy.expose_secret;
Converting from Entropy
let mnemonic = from_entropy.unwrap;
Getting the Checksum
let checksum: u8 = mnemonic.checksum;
Iterating Words
for word in mnemonic.words
Features
std(default): Enables Unicode normalization viaunicode-normalization.zeroize: Adds secure zeroing of sensitive data via thezeroizecrate.
To disable std (for no_std):
[]
= { = "0.2.0", = false }
Testing
Run tests with:
The library includes comprehensive tests for English and Japanese wordlists, entropy conversion, checksum validation, and PBKDF2 seed generation, including BIP-39 test vectors.
License
MIT