From 64b9507846846e468ebba7e00fb59971edceca3b Mon Sep 17 00:00:00 2001 From: mtg0001 <106211915+mtg0001@users.noreply.github.com> Date: Sat, 1 Aug 2026 12:23:28 -0300 Subject: Add BIP39 and BIP32 foundation tests (#83) Co-authored-by: Gilcimar Duarte --- src/bip32.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/bip32.h (limited to 'src/bip32.h') diff --git a/src/bip32.h b/src/bip32.h new file mode 100644 index 0000000..a029444 --- /dev/null +++ b/src/bip32.h @@ -0,0 +1,53 @@ +// Copyright (c) 2026 Bitflash developers +// Distributed under the MIT/X11 software license. +// +// BIP39/BIP32 primitives for deterministic wallet work. +// +// This module is deliberately independent from wallet.dat and GUI code. It is +// the auditable foundation: mnemonic generation/validation, seed derivation, +// and hardened private child derivation over secp256k1. + +#ifndef BITFLASH_BIP32_H +#define BITFLASH_BIP32_H + +#include +#include + +namespace bitflash +{ + +struct BIP32PrivateNode +{ + std::vector privateKey; // 32-byte scalar + std::vector chainCode; // 32 bytes +}; + +bool BIP39EntropyToMnemonic(const std::vector& entropy, + std::string& mnemonicOut, + std::string& errorOut); + +bool BIP39GenerateMnemonic(std::string& mnemonicOut, + std::string& errorOut, + unsigned int entropyBytes = 16); + +bool BIP39ValidateMnemonic(const std::string& mnemonic, + std::string& normalizedOut, + std::string& errorOut); + +bool BIP39MnemonicToSeed(const std::string& mnemonic, + const std::string& passphrase, + std::vector& seedOut, + std::string& errorOut); + +bool BIP32MasterFromSeed(const std::vector& seed, + BIP32PrivateNode& nodeOut, + std::string& errorOut); + +bool BIP32DeriveHardenedChild(const BIP32PrivateNode& parent, + unsigned int childIndex, + BIP32PrivateNode& childOut, + std::string& errorOut); + +} // namespace bitflash + +#endif -- cgit v1.2.3