1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
// 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 private child derivation over secp256k1.
#ifndef BITFLASH_BIP32_H
#define BITFLASH_BIP32_H
#include <string>
#include <vector>
namespace bitflash
{
static const unsigned int BIP32_HARDENED = 0x80000000U;
struct BIP32PrivateNode
{
std::vector<unsigned char> privateKey; // 32-byte scalar
std::vector<unsigned char> chainCode; // 32 bytes
};
bool BIP39EntropyToMnemonic(const std::vector<unsigned char>& 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<unsigned char>& seedOut,
std::string& errorOut);
bool BIP32MasterFromSeed(const std::vector<unsigned char>& seed,
BIP32PrivateNode& nodeOut,
std::string& errorOut);
bool BIP32DeriveChild(const BIP32PrivateNode& parent,
unsigned int childNumber,
BIP32PrivateNode& childOut,
std::string& errorOut);
bool BIP32DerivePath(const BIP32PrivateNode& root,
const std::vector<unsigned int>& path,
BIP32PrivateNode& nodeOut,
std::string& errorOut);
bool BIP32DeriveHardenedChild(const BIP32PrivateNode& parent,
unsigned int childIndex,
BIP32PrivateNode& childOut,
std::string& errorOut);
} // namespace bitflash
#endif
|