diff options
| author | mtg0001 <106211915+mtg0001@users.noreply.github.com> | 2026-08-01 12:23:28 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-01 12:23:28 -0300 |
| commit | 64b9507846846e468ebba7e00fb59971edceca3b (patch) | |
| tree | 4ddd4d19289c74cc6c75f7e2cdb9910d1640f751 /src/bip32.h | |
| parent | 6503250913140ca13104f479d9acd4559284bc6e (diff) | |
Add BIP39 and BIP32 foundation tests (#83)
Co-authored-by: Gilcimar Duarte <ti@gpm.infra>
Diffstat (limited to 'src/bip32.h')
| -rw-r--r-- | src/bip32.h | 53 |
1 files changed, 53 insertions, 0 deletions
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 @@ | |||
| 1 | // Copyright (c) 2026 Bitflash developers | ||
| 2 | // Distributed under the MIT/X11 software license. | ||
| 3 | // | ||
| 4 | // BIP39/BIP32 primitives for deterministic wallet work. | ||
| 5 | // | ||
| 6 | // This module is deliberately independent from wallet.dat and GUI code. It is | ||
| 7 | // the auditable foundation: mnemonic generation/validation, seed derivation, | ||
| 8 | // and hardened private child derivation over secp256k1. | ||
| 9 | |||
| 10 | #ifndef BITFLASH_BIP32_H | ||
| 11 | #define BITFLASH_BIP32_H | ||
| 12 | |||
| 13 | #include <string> | ||
| 14 | #include <vector> | ||
| 15 | |||
| 16 | namespace bitflash | ||
| 17 | { | ||
| 18 | |||
| 19 | struct BIP32PrivateNode | ||
| 20 | { | ||
| 21 | std::vector<unsigned char> privateKey; // 32-byte scalar | ||
| 22 | std::vector<unsigned char> chainCode; // 32 bytes | ||
| 23 | }; | ||
| 24 | |||
| 25 | bool BIP39EntropyToMnemonic(const std::vector<unsigned char>& entropy, | ||
| 26 | std::string& mnemonicOut, | ||
| 27 | std::string& errorOut); | ||
| 28 | |||
| 29 | bool BIP39GenerateMnemonic(std::string& mnemonicOut, | ||
| 30 | std::string& errorOut, | ||
| 31 | unsigned int entropyBytes = 16); | ||
| 32 | |||
| 33 | bool BIP39ValidateMnemonic(const std::string& mnemonic, | ||
| 34 | std::string& normalizedOut, | ||
| 35 | std::string& errorOut); | ||
| 36 | |||
| 37 | bool BIP39MnemonicToSeed(const std::string& mnemonic, | ||
| 38 | const std::string& passphrase, | ||
| 39 | std::vector<unsigned char>& seedOut, | ||
| 40 | std::string& errorOut); | ||
| 41 | |||
| 42 | bool BIP32MasterFromSeed(const std::vector<unsigned char>& seed, | ||
| 43 | BIP32PrivateNode& nodeOut, | ||
| 44 | std::string& errorOut); | ||
| 45 | |||
| 46 | bool BIP32DeriveHardenedChild(const BIP32PrivateNode& parent, | ||
| 47 | unsigned int childIndex, | ||
| 48 | BIP32PrivateNode& childOut, | ||
| 49 | std::string& errorOut); | ||
| 50 | |||
| 51 | } // namespace bitflash | ||
| 52 | |||
| 53 | #endif | ||