bitcoin_key/extkey.rs
1crate::ix!();
2
3pub struct ExtKey {
4 n_depth: u8,
5 vch_fingerprint: [u8; 4],
6 n_child: u32,
7 chaincode: ChainCode,
8 key: Key,
9}
10
11impl PartialEq<ExtKey> for ExtKey {
12
13 #[inline] fn eq(&self, other: &ExtKey) -> bool {
14 todo!();
15 /*
16 return a.nDepth == b.nDepth &&
17 memcmp(a.vchFingerprint, b.vchFingerprint, sizeof(vchFingerprint)) == 0 &&
18 a.nChild == b.nChild &&
19 a.chaincode == b.chaincode &&
20 a.key == b.key;
21 */
22 }
23}
24
25impl Eq for ExtKey {}
26
27impl ExtKey {
28
29 pub fn derive(&self,
30 out: &mut ExtKey,
31 n_child: u32) -> bool {
32
33 todo!();
34 /*
35 out.nDepth = nDepth + 1;
36 CKeyID id = key.GetPubKey().GetID();
37 memcpy(out.vchFingerprint, &id, 4);
38 out.nChild = _nChild;
39 return key.Derive(out.key, out.chaincode, _nChild, chaincode);
40 */
41 }
42
43 pub fn set_seed(&mut self,
44 seed: *const u8,
45 n_seed_len: u32) {
46
47 todo!();
48 /*
49 static const unsigned char hashkey[] = {'B','i','t','c','o','i','n',' ','s','e','e','d'};
50 std::vector<unsigned char, secure_allocator<unsigned char>> vout(64);
51 CHMAC_SHA512(hashkey, sizeof(hashkey)).Write(seed, nSeedLen).Finalize(vout.data());
52 key.Set(vout.data(), vout.data() + 32, true);
53 memcpy(chaincode.begin(), vout.data() + 32, 32);
54 nDepth = 0;
55 nChild = 0;
56 memset(vchFingerprint, 0, sizeof(vchFingerprint));
57 */
58 }
59
60 pub fn neuter(&self) -> ExtPubKey {
61
62 todo!();
63 /*
64 CExtPubKey ret;
65 ret.nDepth = nDepth;
66 memcpy(ret.vchFingerprint, vchFingerprint, 4);
67 ret.nChild = nChild;
68 ret.pubkey = key.GetPubKey();
69 ret.chaincode = chaincode;
70 return ret;
71 */
72 }
73
74 pub fn encode(&self, code: [u8; BIP32_EXTKEY_SIZE]) {
75
76 todo!();
77 /*
78 code[0] = nDepth;
79 memcpy(code+1, vchFingerprint, 4);
80 WriteBE32(code+5, nChild);
81 memcpy(code+9, chaincode.begin(), 32);
82 code[41] = 0;
83 assert(key.size() == 32);
84 memcpy(code+42, key.begin(), 32);
85 */
86 }
87
88 pub fn decode(&mut self, code: [u8; BIP32_EXTKEY_SIZE]) {
89
90 todo!();
91 /*
92 nDepth = code[0];
93 memcpy(vchFingerprint, code+1, 4);
94 nChild = ReadBE32(code+5);
95 memcpy(chaincode.begin(), code+9, 32);
96 key.Set(code+42, code+BIP32_EXTKEY_SIZE, true);
97 if ((nDepth == 0 && (nChild != 0 || ReadLE32(vchFingerprint) != 0)) || code[41] != 0) key = CKey();
98 */
99 }
100}