2015-01-11 15:43:07 +00:00
|
|
|
cimport c
|
|
|
|
cimport cython
|
2015-07-06 16:48:11 +00:00
|
|
|
|
2015-01-11 15:43:07 +00:00
|
|
|
cdef class HDNode:
|
|
|
|
|
|
|
|
cdef c.HDNode node
|
|
|
|
|
2015-01-11 19:05:40 +00:00
|
|
|
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:
|
2015-01-11 15:43:07 +00:00
|
|
|
raise Exception('Invalid xpub/xprv provided')
|
2015-01-11 19:05:40 +00:00
|
|
|
else:
|
|
|
|
raise Exception('Need to provide serialized or node parameter')
|
2015-01-11 15:43:07 +00:00
|
|
|
|
|
|
|
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):
|
2015-01-11 19:05:40 +00:00
|
|
|
x = HDNode(copyfrom=self)
|
2015-01-11 15:43:07 +00:00
|
|
|
c.hdnode_public_ckd(cython.address(x.node), i)
|
|
|
|
return x
|
|
|
|
|
2015-07-06 16:43:30 +00:00
|
|
|
def private_ckd(self, unsigned int i):
|
2015-01-11 19:05:40 +00:00
|
|
|
x = HDNode(copyfrom=self)
|
2015-01-11 15:43:07 +00:00
|
|
|
c.hdnode_private_ckd(cython.address(x.node), i)
|
|
|
|
return x
|