// Copyright (c) 2016-2024 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #ifndef HUSH_WALLET_MNEMONIC_H #define HUSH_WALLET_MNEMONIC_H #include #include "zcash/zip32.h" // RawHDSeed // Thin, thread-safe C++ wrapper over the vendored BIP39 (trezor-crypto) library. // It reproduces SilentDragonXLite's tiny-bip39 0.6.2 conventions EXACTLY so the // same 24 words yield the same addresses in both wallets: // - English wordlist only (byte-identical to tiny-bip39's english.txt) // - empty BIP39 passphrase (no "25th word") // - PBKDF2-HMAC-SHA512, 2048 rounds, 64-byte seed // - the seed is derived from the CANONICAL phrase regenerated from entropy, // matching SDXLite's Mnemonic::from_entropy(entropy).phrase() round-trip. //! True if `phrase` is a valid BIP39 mnemonic (word list + checksum). bool MnemonicIsValid(const std::string& phrase); //! Parse `phrase` into its BIP39 entropy (16/20/24/28/32 bytes). Validates the //! checksum first. Returns false on any invalid input. bool MnemonicToEntropy(const std::string& phrase, RawHDSeed& entropyOut); //! Regenerate the canonical English mnemonic phrase from `entropy`. bool EntropyToMnemonic(const RawHDSeed& entropy, std::string& phraseOut); //! Derive the 64-byte BIP39 seed used for HD derivation from `entropy`, exactly //! as SilentDragonXLite does: canonical phrase from entropy, then PBKDF2 with an //! empty passphrase. bool Bip39SeedFromEntropy(const RawHDSeed& entropy, RawHDSeed& seed64Out); //! Generate fresh BIP39 entropy of `bits` (128/160/192/224/256) from the node //! CSPRNG, for creating a new mnemonic wallet. bool GenerateMnemonicEntropy(int bits, RawHDSeed& entropyOut); #endif // HUSH_WALLET_MNEMONIC_H