Hierarchical deterministic keys
BIP-39 mnemonic phrases and BIP-32 extended keys over secp256k1.
Generate or load a BIP-39 mnemonic, derive its seed, load the BIP-32 master key from the seed and derive child keys along a path. Child keys convert to the existing ECDSA and Schnorr secp256k1 key classes for signing.
from oxcrypto.hash.sha2 import SHA2
from oxcrypto.hd.bip32 import BIP32
from oxcrypto.hd.bip39 import BIP39
mnemonic = BIP39.ENGLISH.generate(words=24)
master = BIP32.SECP256K1.load_mnemonic(mnemonic, passphrase="")
account = master.derive_path("m/84'/0'/0'")
key = account.derive_path("0/0")
signature = key.to_ecdsa().sign(b"message", hash=SHA2.SHA256)
assert account.public_key().derive_path("0/0").to_ecdsa().verify(
signature, b"message", hash=SHA2.SHA256
)Algorithms
- BIP-39 Mnemonic phrases in all ten official wordlists and PBKDF2 seed derivation.
- BIP-32 Extended keys over secp256k1 with
xprv/xpubserialization and path parsing.
Implementation and limitations
| Standards | BIP-39 and BIP-32 (both Deployed) |
| Crates | coins-bip39 0.17.2 and coins-bip32 0.17.2, MIT OR Apache-2.0, stable release line, no published audit |
| Backends | k256 0.14, hmac 0.13, pbkdf2 0.13 and sha2 0.11, the versions oxcrypto already uses |
| MSRV | Both crates declare Rust 1.85; oxcrypto builds them with Rust 1.88 |
| Experimental | No |
Bad entropy lengths, word counts, unknown words, failed checksums, malformed
extended keys and paths, and seeds outside 16 to 64 bytes raise ValueError.
Wrong argument types raise TypeError. Mnemonics and private keys cannot be
copied or pickled, and their repr shows only the language, word count or
depth. Mnemonic and private-key equality is constant time.
Zeroization
Mnemonic keeps only the entropy, in a coins-bip39 Entropy that is wiped
on drop. Phrases are rebuilt from it when needed: NFKD-normalized phrases,
PBKDF2 salts and seeds are held in Zeroizing buffers, and hmac and sha2
wipe their states because oxcrypto enables their zeroize features.
ExtendedPrivateKey holds a coins-bip32 XPriv, whose k256 signing key
and chain code are wiped on drop; derivation inputs and outputs and Base58
payloads are held in Zeroizing buffers. coins-bip32 does not wipe an
XPub, which is Copy, so ExtendedPublicKey stores the public key and key
information itself and wipes the chain code on drop. oxcrypto has not verified
the upstream zeroization independently.
Note
Zeroization does not cover:
- Phrases, passphrases, entropy, seeds and
xprvstrings passed in or returned as Pythonbytesorstr. Python owns these objects, does not wipe them, and may copy them, including the UTF-8 copy CPython caches inside astr. - Short-lived stack copies during a call: the padded HMAC key block in
hmac0.13, theXPubvaluescoins-bip32builds while deriving public keys and fingerprints, and moves ofCopychain codes.
Treat zeroization as defense in depth. It does not guarantee that secrets are gone from process memory.