1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-10-10 09:58:59 +00:00
trezor-firmware/cython/TrezorCrypto.pyx
2015-01-11 16:43:07 +01:00

39 lines
951 B
Cython

cimport c
cimport cython
cdef class HDNode:
cdef c.HDNode node
def __init__(self, initializer):
if isinstance(initializer, HDNode):
self.node = (<HDNode>initializer).node
elif isinstance(initializer, str) :
if c.hdnode_deserialize(initializer, cython.address(self.node)) != 0:
raise Exception('Invalid xpub/xprv provided')
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(self)
c.hdnode_public_ckd(cython.address(x.node), i)
return x
def private_ckd(self, int i):
x = HDNode(self)
c.hdnode_private_ckd(cython.address(x.node), i)
return x