-
Notifications
You must be signed in to change notification settings - Fork 9
/
modtcc-bip32.c
472 lines (417 loc) · 17.9 KB
/
modtcc-bip32.c
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
/*
* Copyright (c) Jan Pochyla, SatoshiLabs
*
* Licensed under TREZOR License
* see LICENSE file for details
*/
#include "py/objstr.h"
#include "bip32.h"
#include "curves.h"
/// class HDNode:
/// '''
/// BIP0032 HD node structure.
/// '''
typedef struct _mp_obj_HDNode_t {
mp_obj_base_t base;
uint32_t fingerprint;
bool have_private;
HDNode hdnode;
} mp_obj_HDNode_t;
STATIC const mp_obj_type_t mod_trezorcrypto_HDNode_type;
#define XPUB_MAXLEN 128
#define ADDRESS_MAXLEN 36
/// def __init__(self,
/// depth: int,
/// fingerprint: int,
/// child_num: int,
/// chain_code: bytes,
/// private_key: bytes = None,
/// public_key: bytes = None,
/// curve_name: str = None) -> None:
/// '''
/// '''
STATIC mp_obj_t mod_trezorcrypto_HDNode_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
// NOTE: mp_const_empty_bytes does not have NULL buf value! Look at the .len
STATIC const mp_arg_t allowed_args[] = {
{ MP_QSTR_depth, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_fingerprint, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_child_num, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_chain_code, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_empty_bytes} },
{ MP_QSTR_private_key, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_empty_bytes} },
{ MP_QSTR_public_key, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_empty_bytes} },
{ MP_QSTR_curve_name, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_empty_bytes} },
};
mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args), allowed_args, vals);
mp_buffer_info_t chain_code;
mp_buffer_info_t private_key;
mp_buffer_info_t public_key;
mp_buffer_info_t curve_name;
const mp_int_t depth = vals[0].u_int;
const mp_int_t fingerprint = vals[1].u_int;
const mp_int_t child_num = vals[2].u_int;
mp_get_buffer_raise(vals[3].u_obj, &chain_code, MP_BUFFER_READ);
mp_get_buffer_raise(vals[4].u_obj, &private_key, MP_BUFFER_READ);
mp_get_buffer_raise(vals[5].u_obj, &public_key, MP_BUFFER_READ);
mp_get_buffer_raise(vals[6].u_obj, &curve_name, MP_BUFFER_READ);
if (chain_code.len && 32 != chain_code.len) {
mp_raise_ValueError("chain_code is invalid");
}
if (!public_key.len && !private_key.len) {
mp_raise_ValueError("either public_key or private_key is required");
}
if (private_key.len && private_key.len != 32) {
mp_raise_ValueError("private_key is invalid");
}
if (public_key.len && public_key.len != 33) {
mp_raise_ValueError("public_key is invalid");
}
const curve_info *curve = NULL;
if (!curve_name.len) {
curve = get_curve_by_name(SECP256K1_NAME);
} else {
curve = get_curve_by_name(curve_name.buf);
}
if (NULL == curve) {
mp_raise_ValueError("curve_name is invalid");
}
mp_obj_HDNode_t *o = m_new_obj(mp_obj_HDNode_t);
o->base.type = type;
o->fingerprint = (uint32_t)fingerprint;
o->hdnode.depth = (uint32_t)depth;
o->hdnode.child_num = (uint32_t)child_num;
if (chain_code.len) {
memcpy(o->hdnode.chain_code, chain_code.buf, 32);
} else {
memset(o->hdnode.chain_code, 0, 32);
}
if (private_key.len) {
memcpy(o->hdnode.private_key, private_key.buf, 32);
o->have_private = true;
} else {
memset(o->hdnode.private_key, 0, 32);
o->have_private = false;
}
if (public_key.len) {
memcpy(o->hdnode.public_key, public_key.buf, 33);
} else {
memset(o->hdnode.public_key, 0, 33);
}
o->hdnode.curve = curve;
return MP_OBJ_FROM_PTR(o);
}
/// def derive(self, index: int) -> None:
/// '''
/// Derive a BIP0032 child node in place.
/// '''
STATIC mp_obj_t mod_trezorcrypto_HDNode_derive(mp_obj_t self, mp_obj_t index) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
uint32_t i = mp_obj_get_int_truncated(index);
uint32_t fp = hdnode_fingerprint(&o->hdnode);
int res;
if(!o->have_private) {
// must do a public derivation when we have no private key
res = hdnode_public_ckd(&o->hdnode, i);
} else {
res = hdnode_private_ckd(&o->hdnode, i);
}
if (!res) {
memset(&o->hdnode, 0, sizeof(o->hdnode));
mp_raise_ValueError("Failed to derive");
}
o->fingerprint = fp;
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_derive_obj, mod_trezorcrypto_HDNode_derive);
/// def derive_path(self, path: List[int]) -> None:
/// '''
/// Go through a list of indexes and iteratively derive a child node in place.
/// '''
STATIC mp_obj_t mod_trezorcrypto_HDNode_derive_path(mp_obj_t self, mp_obj_t path) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
// get path objects and length
size_t plen;
mp_obj_t *pitems;
mp_obj_get_array(path, &plen, &pitems);
if (plen > 32) {
mp_raise_ValueError("Path cannot be longer than 32 indexes");
}
// convert path to int array
uint32_t pi;
uint32_t pints[plen];
for (pi = 0; pi < plen; pi++) {
if (!MP_OBJ_IS_INT(pitems[pi])) {
mp_raise_TypeError("Index has to be int");
}
pints[pi] = mp_obj_get_int_truncated(pitems[pi]);
}
if (!hdnode_private_ckd_cached(&o->hdnode, pints, plen, &o->fingerprint)) {
// derivation failed, reset the state and raise
o->fingerprint = 0;
memset(&o->hdnode, 0, sizeof(o->hdnode));
mp_raise_ValueError("Failed to derive path");
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_derive_path_obj, mod_trezorcrypto_HDNode_derive_path);
STATIC mp_obj_t serialize_public_private(mp_obj_t self, bool use_public, uint32_t version) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
char xpub[XPUB_MAXLEN];
int written;
if (use_public) {
hdnode_fill_public_key(&o->hdnode);
written = hdnode_serialize_public(&o->hdnode, o->fingerprint, version, xpub, XPUB_MAXLEN);
} else {
written = hdnode_serialize_private(&o->hdnode, o->fingerprint, version, xpub, XPUB_MAXLEN);
}
if (written <= 0) {
mp_raise_ValueError("Failed to serialize");
}
return mp_obj_new_str(xpub, written - 1); // written includes 0 at the end
}
/// def serialize_public(self, version: int) -> str:
/// '''
/// Serialize the public info from HD node to base58 string.
/// '''
STATIC mp_obj_t mod_trezorcrypto_HDNode_serialize_public(mp_obj_t self, mp_obj_t version) {
uint32_t ver = mp_obj_get_int_truncated(version);
return serialize_public_private(self, true, ver);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_serialize_public_obj, mod_trezorcrypto_HDNode_serialize_public);
/// def serialize_private(self, version: int) -> str:
/// '''
/// Serialize the private info HD node to base58 string.
/// '''
STATIC mp_obj_t mod_trezorcrypto_HDNode_serialize_private(mp_obj_t self, mp_obj_t version) {
uint32_t ver = mp_obj_get_int_truncated(version);
return serialize_public_private(self, false, ver);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_serialize_private_obj, mod_trezorcrypto_HDNode_serialize_private);
/// def clone(self) -> HDNode:
/// '''
/// Returns a copy of the HD node.
/// '''
STATIC mp_obj_t mod_trezorcrypto_HDNode_clone(mp_obj_t self) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
mp_obj_HDNode_t *copy = m_new_obj(mp_obj_HDNode_t);
copy->base.type = &mod_trezorcrypto_HDNode_type;
copy->hdnode = o->hdnode;
copy->have_private = o->have_private;
copy->fingerprint = o->fingerprint;
return MP_OBJ_FROM_PTR(copy);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_clone_obj, mod_trezorcrypto_HDNode_clone);
/// def blank(self) -> HDNode:
/// '''
/// Blank out sensitive values in self. Object useless afterwards.
/// '''
STATIC mp_obj_t modtcc_HDNode_blank(mp_obj_t self) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
memset(&o->hdnode, 0, sizeof(HDNode));
o->fingerprint = 0;
o->have_private = false;
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(modtcc_HDNode_blank_obj, modtcc_HDNode_blank);
/// def depth(self) -> int:
/// '''
/// Returns a depth of the HD node.
/// '''
STATIC mp_obj_t mod_trezorcrypto_HDNode_depth(mp_obj_t self) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
return mp_obj_new_int_from_uint(o->hdnode.depth);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_depth_obj, mod_trezorcrypto_HDNode_depth);
/// def fingerprint(self) -> int:
/// '''
/// Returns a fingerprint of the HD node (hash of the parent public key).
/// '''
STATIC mp_obj_t mod_trezorcrypto_HDNode_fingerprint(mp_obj_t self) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
return mp_obj_new_int_from_uint(o->fingerprint);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_fingerprint_obj, mod_trezorcrypto_HDNode_fingerprint);
/// def my_fingerprint(self) -> int:
/// '''
/// Returns a fingerprint of this HD node (hash of its public key)... not the parent.
/// NOTE: this is a little-endian 32-bit number, not BE32 used elsewhere in this library.
/// '''
STATIC mp_obj_t mod_trezorcrypto_HDNode_my_fingerprint(mp_obj_t self) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
uint32_t fp = hdnode_fingerprint(&o->hdnode);
return mp_obj_new_int_from_uint(__builtin_bswap32(fp));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_my_fingerprint_obj, mod_trezorcrypto_HDNode_my_fingerprint);
/// def child_num(self) -> int:
/// '''
/// Returns a child index of the HD node.
/// '''
STATIC mp_obj_t mod_trezorcrypto_HDNode_child_num(mp_obj_t self) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
return mp_obj_new_int_from_uint(o->hdnode.child_num);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_child_num_obj, mod_trezorcrypto_HDNode_child_num);
/// def chain_code(self) -> bytes:
/// '''
/// Returns a chain code of the HD node.
/// '''
STATIC mp_obj_t mod_trezorcrypto_HDNode_chain_code(mp_obj_t self) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
return mp_obj_new_bytes(o->hdnode.chain_code, sizeof(o->hdnode.chain_code));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_chain_code_obj, mod_trezorcrypto_HDNode_chain_code);
/// def private_key(self) -> bytes:
/// '''
/// Returns a private key of the HD node.
/// '''
STATIC mp_obj_t mod_trezorcrypto_HDNode_private_key(mp_obj_t self) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
if(!o->have_private) {
return mp_const_none;
} else {
return mp_obj_new_bytes(o->hdnode.private_key, sizeof(o->hdnode.private_key));
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_private_key_obj, mod_trezorcrypto_HDNode_private_key);
/// def public_key(self) -> bytes:
/// '''
/// Returns a public key of the HD node.
/// '''
STATIC mp_obj_t mod_trezorcrypto_HDNode_public_key(mp_obj_t self) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
hdnode_fill_public_key(&o->hdnode);
return mp_obj_new_bytes(o->hdnode.public_key, sizeof(o->hdnode.public_key));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_public_key_obj, mod_trezorcrypto_HDNode_public_key);
/// def address(self, version: int) -> str:
/// '''
/// Compute a base58-encoded address string from the HD node.
/// '''
STATIC mp_obj_t mod_trezorcrypto_HDNode_address(mp_obj_t self, mp_obj_t version) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
uint32_t v = mp_obj_get_int_truncated(version);
char address[ADDRESS_MAXLEN];
hdnode_get_address(&o->hdnode, v, address, ADDRESS_MAXLEN);
return mp_obj_new_str(address, strlen(address));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_address_obj, mod_trezorcrypto_HDNode_address);
/// def address_raw(self) -> bytes[20]:
/// '''
/// Compute a ripemd160-hash of hash(pubkey). Always 20 bytes of binary.
/// '''
STATIC mp_obj_t mod_trezorcrypto_HDNode_address_raw(mp_obj_t self) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
// API requires a version, but we'll use zero and remove it.
uint8_t raw[21];
hdnode_get_address_raw(&o->hdnode, 0x0, raw);
return mp_obj_new_bytes(raw+1, 20);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_address_raw_obj, mod_trezorcrypto_HDNode_address_raw);
#if USE_ETHEREUM
/// def ethereum_pubkeyhash(self) -> bytes:
/// '''
/// Compute an Ethereum pubkeyhash (aka address) from the HD node.
/// '''
STATIC mp_obj_t mod_trezorcrypto_HDNode_ethereum_pubkeyhash(mp_obj_t self) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
uint8_t pkh[20];
hdnode_get_ethereum_pubkeyhash(&o->hdnode, pkh);
return mp_obj_new_bytes(pkh, sizeof(pkh));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_ethereum_pubkeyhash_obj, mod_trezorcrypto_HDNode_ethereum_pubkeyhash);
#endif
STATIC const mp_rom_map_elem_t mod_trezorcrypto_HDNode_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_derive), MP_ROM_PTR(&mod_trezorcrypto_HDNode_derive_obj) },
{ MP_ROM_QSTR(MP_QSTR_derive_path), MP_ROM_PTR(&mod_trezorcrypto_HDNode_derive_path_obj) },
{ MP_ROM_QSTR(MP_QSTR_serialize_private), MP_ROM_PTR(&mod_trezorcrypto_HDNode_serialize_private_obj) },
{ MP_ROM_QSTR(MP_QSTR_serialize_public), MP_ROM_PTR(&mod_trezorcrypto_HDNode_serialize_public_obj) },
{ MP_ROM_QSTR(MP_QSTR_clone), MP_ROM_PTR(&mod_trezorcrypto_HDNode_clone_obj) },
{ MP_ROM_QSTR(MP_QSTR_depth), MP_ROM_PTR(&mod_trezorcrypto_HDNode_depth_obj) },
{ MP_ROM_QSTR(MP_QSTR_fingerprint), MP_ROM_PTR(&mod_trezorcrypto_HDNode_fingerprint_obj) },
{ MP_ROM_QSTR(MP_QSTR_my_fingerprint), MP_ROM_PTR(&mod_trezorcrypto_HDNode_my_fingerprint_obj) },
{ MP_ROM_QSTR(MP_QSTR_child_num), MP_ROM_PTR(&mod_trezorcrypto_HDNode_child_num_obj) },
{ MP_ROM_QSTR(MP_QSTR_chain_code), MP_ROM_PTR(&mod_trezorcrypto_HDNode_chain_code_obj) },
{ MP_ROM_QSTR(MP_QSTR_private_key), MP_ROM_PTR(&mod_trezorcrypto_HDNode_private_key_obj) },
{ MP_ROM_QSTR(MP_QSTR_public_key), MP_ROM_PTR(&mod_trezorcrypto_HDNode_public_key_obj) },
{ MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&mod_trezorcrypto_HDNode_address_obj) },
{ MP_ROM_QSTR(MP_QSTR_address_raw), MP_ROM_PTR(&mod_trezorcrypto_HDNode_address_raw_obj) },
{ MP_ROM_QSTR(MP_QSTR_blank), MP_ROM_PTR(&modtcc_HDNode_blank_obj) },
#if USE_ETHEREUM
{ MP_ROM_QSTR(MP_QSTR_ethereum_pubkeyhash), MP_ROM_PTR(&mod_trezorcrypto_HDNode_ethereum_pubkeyhash_obj) },
#endif
};
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_HDNode_locals_dict, mod_trezorcrypto_HDNode_locals_dict_table);
STATIC const mp_obj_type_t mod_trezorcrypto_HDNode_type = {
{ &mp_type_type },
.name = MP_QSTR_HDNode,
.make_new = mod_trezorcrypto_HDNode_make_new,
.locals_dict = (void*)&mod_trezorcrypto_HDNode_locals_dict,
};
/// def deserialize(self, value: str, version_public: int, version_private: int) -> HDNode:
/// '''
/// Construct a BIP0032 HD node from a base58-serialized value.
/// '''
STATIC mp_obj_t mod_trezorcrypto_bip32_deserialize(mp_obj_t value, mp_obj_t version_public, mp_obj_t version_private) {
mp_buffer_info_t valueb;
mp_get_buffer_raise(value, &valueb, MP_BUFFER_READ);
if (valueb.len == 0) {
mp_raise_ValueError("Invalid value");
}
uint32_t vpub = mp_obj_get_int_truncated(version_public);
uint32_t vpriv = mp_obj_get_int_truncated(version_private);
HDNode hdnode;
uint32_t fingerprint;
if (hdnode_deserialize(valueb.buf, vpub, vpriv, SECP256K1_NAME, &hdnode, &fingerprint) < 0) {
mp_raise_ValueError("Failed to deserialize");
}
mp_obj_HDNode_t *o = m_new_obj(mp_obj_HDNode_t);
o->base.type = &mod_trezorcrypto_HDNode_type;
o->hdnode = hdnode;
o->fingerprint = fingerprint;
o->have_private = false;
for(int j=0; j<32; j++) {
if(hdnode.private_key[j] != 0) {
o->have_private = true;
break;
}
}
return MP_OBJ_FROM_PTR(o);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_bip32_deserialize_obj, mod_trezorcrypto_bip32_deserialize);
/// def from_seed(seed: bytes, curve_name: str) -> HDNode:
/// '''
/// Construct a BIP0032 HD node from a BIP0039 seed value.
/// '''
STATIC mp_obj_t mod_trezorcrypto_bip32_from_seed(mp_obj_t seed, mp_obj_t curve_name) {
mp_buffer_info_t seedb;
mp_get_buffer_raise(seed, &seedb, MP_BUFFER_READ);
if (seedb.len == 0) {
mp_raise_ValueError("Invalid seed");
}
mp_buffer_info_t curveb;
mp_get_buffer_raise(curve_name, &curveb, MP_BUFFER_READ);
if (curveb.len == 0) {
mp_raise_ValueError("Invalid curve name");
}
HDNode hdnode;
if (!hdnode_from_seed(seedb.buf, seedb.len, curveb.buf, &hdnode)) {
mp_raise_ValueError("Failed to derive the root node");
}
mp_obj_HDNode_t *o = m_new_obj(mp_obj_HDNode_t);
o->base.type = &mod_trezorcrypto_HDNode_type;
o->hdnode = hdnode;
o->have_private = true;
return MP_OBJ_FROM_PTR(o);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_bip32_from_seed_obj, mod_trezorcrypto_bip32_from_seed);
STATIC const mp_rom_map_elem_t mod_trezorcrypto_bip32_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bip32) },
{ MP_ROM_QSTR(MP_QSTR_HDNode), MP_ROM_PTR(&mod_trezorcrypto_HDNode_type) },
{ MP_ROM_QSTR(MP_QSTR_deserialize), MP_ROM_PTR(&mod_trezorcrypto_bip32_deserialize_obj) },
{ MP_ROM_QSTR(MP_QSTR_from_seed), MP_ROM_PTR(&mod_trezorcrypto_bip32_from_seed_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_bip32_globals, mod_trezorcrypto_bip32_globals_table);
STATIC const mp_obj_module_t mod_trezorcrypto_bip32_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&mod_trezorcrypto_bip32_globals,
};