parent
9a8df5a4bb
commit
c80f0fbc52
@ -1,2 +0,0 @@
|
||||
include *.h
|
||||
include *.pyx
|
@ -1,40 +0,0 @@
|
||||
cimport c
|
||||
cimport cython
|
||||
|
||||
cdef class HDNode:
|
||||
|
||||
cdef c.HDNode node
|
||||
|
||||
def __init__(self, str serialized = None, HDNode copyfrom = None):
|
||||
if copyfrom is not None:
|
||||
self.node = copyfrom.node
|
||||
elif serialized is not None:
|
||||
if c.hdnode_deserialize(serialized, cython.address(self.node)) != 0:
|
||||
raise Exception('Invalid xpub/xprv provided')
|
||||
else:
|
||||
raise Exception('Need to provide serialized or node parameter')
|
||||
|
||||
def xpub(self):
|
||||
cdef char[120] string
|
||||
c.hdnode_serialize_public(cython.address(self.node), string, 120)
|
||||
return str(string)
|
||||
|
||||
def xprv(self):
|
||||
cdef char[120] string
|
||||
c.hdnode_serialize_private(cython.address(self.node), string, 120)
|
||||
return str(string)
|
||||
|
||||
def address(self):
|
||||
cdef char[40] string
|
||||
c.ecdsa_get_address(self.node.public_key, 0, string, 40)
|
||||
return str(string)
|
||||
|
||||
def public_ckd(self, int i):
|
||||
x = HDNode(copyfrom=self)
|
||||
c.hdnode_public_ckd(cython.address(x.node), i)
|
||||
return x
|
||||
|
||||
def private_ckd(self, unsigned int i):
|
||||
x = HDNode(copyfrom=self)
|
||||
c.hdnode_private_ckd(cython.address(x.node), i)
|
||||
return x
|
@ -1,22 +0,0 @@
|
||||
from libc.stdint cimport uint32_t, uint8_t
|
||||
|
||||
cdef extern from "bip32.h":
|
||||
|
||||
ctypedef struct HDNode:
|
||||
uint8_t public_key[33]
|
||||
|
||||
int hdnode_from_seed(const uint8_t *seed, int seed_len, const char *curve, HDNode *out)
|
||||
|
||||
int hdnode_private_ckd(HDNode *inout, uint32_t i)
|
||||
|
||||
int hdnode_public_ckd(HDNode *inout, uint32_t i)
|
||||
|
||||
void hdnode_serialize_public(const HDNode *node, char *str, int strsize)
|
||||
|
||||
void hdnode_serialize_private(const HDNode *node, char *str, int strsize)
|
||||
|
||||
int hdnode_deserialize(const char *str, HDNode *node)
|
||||
|
||||
cdef extern from "ecdsa.h":
|
||||
|
||||
void ecdsa_get_address(const uint8_t *pub_key, uint8_t version, char *addr, int addrsize)
|
@ -1,10 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
from TrezorCrypto import HDNode
|
||||
|
||||
x = HDNode('xpub6BcjTvRCYD4VvFQ8whztSXhbNyhS56eTd5P3g9Zvd3zPEeUeL5CUqBYX8NSd1b6Thitr8bZcSnesmXZH7KerMcc4tUkenBShYCtQ1L8ebVe')
|
||||
|
||||
y = x.public_ckd(0)
|
||||
|
||||
for i in range(1000):
|
||||
z = y.public_ckd(i)
|
||||
print i, z.address()
|
Loading…
Reference in new issue