Exemplo n.º 1
0
def serialize_xpriv(k):
    b = b''
    b += HD_HEADER_PRIVATE
    b += convert.int_to_byte(k['depth'])
    b += k['fingerprint']
    b += convert.int_to_bytes(k['i'], 4)
    b += k['chaincode']
    b += b'\x00' + ecdsa.serialize_priv(k['priv'])
    return convert.bytes_to_b58check(b)
Exemplo n.º 2
0
def derive_xpriv(k, i):
    i = int(i)

    pub = ecdsa.priv_to_pub(k['priv'])
    pub_ser = ecdsa.serialize_pub(pub)
    priv_ser = ecdsa.serialize_priv(k['priv'])

    if i >= 2**31:
        hmacdata = b'\x00' + priv_ser + convert.int_to_bytes(i, 4)
    else:
        hmacdata = pub_ser + convert.int_to_bytes(i, 4)

    I = hmac.new(k['chaincode'], hmacdata, hashlib.sha512).digest()

    return {
        'depth': k['depth'] + 1,
        'fingerprint': hashes.hash160(pub_ser)[:4],
        'i': i,
        'chaincode': I[32:],
        'priv': ec.add_scalar(k['priv'], ecdsa.deserialize_priv(I[:32]))
    }
Exemplo n.º 3
0
 def test_serialize(self):
     for _ in range(10):
         priv = ecdsa.random_priv()
         ser = ecdsa.serialize_priv(priv)
         priv2 = ecdsa.deserialize_priv(ser)
         self.assertEqual(priv, priv2)