diff options
| author | bitflash-coin <bookofshamers@outlook.com> | 2026-08-04 06:34:32 -0700 |
|---|---|---|
| committer | bitflash-coin <bookofshamers@outlook.com> | 2026-08-04 06:34:32 -0700 |
| commit | 5ce650382352c1503f40abf08129ada69402af55 (patch) | |
| tree | 6a18198901f1e2c4933f1ac53c9365eec512bf63 /src/bip32.h | |
| parent | f34113291da7e5e3dc7d2468d4f9c212c05c584b (diff) | |
public commit
Diffstat (limited to 'src/bip32.h')
| -rw-r--r-- | src/bip32.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/bip32.h b/src/bip32.h new file mode 100644 index 0000000..e9862d5 --- /dev/null +++ b/src/bip32.h | |||
| @@ -0,0 +1,65 @@ | |||
| 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 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 | static const unsigned int BIP32_HARDENED = 0x80000000U; | ||
| 20 | |||
| 21 | struct BIP32PrivateNode | ||
| 22 | { | ||
| 23 | std::vector<unsigned char> privateKey; // 32-byte scalar | ||
| 24 | std::vector<unsigned char> chainCode; // 32 bytes | ||
| 25 | }; | ||
| 26 | |||
| 27 | bool BIP39EntropyToMnemonic(const std::vector<unsigned char>& entropy, | ||
| 28 | std::string& mnemonicOut, | ||
| 29 | std::string& errorOut); | ||
| 30 | |||
| 31 | bool BIP39GenerateMnemonic(std::string& mnemonicOut, | ||
| 32 | std::string& errorOut, | ||
| 33 | unsigned int entropyBytes = 16); | ||
| 34 | |||
| 35 | bool BIP39ValidateMnemonic(const std::string& mnemonic, | ||
| 36 | std::string& normalizedOut, | ||
| 37 | std::string& errorOut); | ||
| 38 | |||
| 39 | bool BIP39MnemonicToSeed(const std::string& mnemonic, | ||
| 40 | const std::string& passphrase, | ||
| 41 | std::vector<unsigned char>& seedOut, | ||
| 42 | std::string& errorOut); | ||
| 43 | |||
| 44 | bool BIP32MasterFromSeed(const std::vector<unsigned char>& seed, | ||
| 45 | BIP32PrivateNode& nodeOut, | ||
| 46 | std::string& errorOut); | ||
| 47 | |||
| 48 | bool BIP32DeriveChild(const BIP32PrivateNode& parent, | ||
| 49 | unsigned int childNumber, | ||
| 50 | BIP32PrivateNode& childOut, | ||
| 51 | std::string& errorOut); | ||
| 52 | |||
| 53 | bool BIP32DerivePath(const BIP32PrivateNode& root, | ||
| 54 | const std::vector<unsigned int>& path, | ||
| 55 | BIP32PrivateNode& nodeOut, | ||
| 56 | std::string& errorOut); | ||
| 57 | |||
| 58 | bool BIP32DeriveHardenedChild(const BIP32PrivateNode& parent, | ||
| 59 | unsigned int childIndex, | ||
| 60 | BIP32PrivateNode& childOut, | ||
| 61 | std::string& errorOut); | ||
| 62 | |||
| 63 | } // namespace bitflash | ||
| 64 | |||
| 65 | #endif | ||