def child(self, i: int) -> 'Xpub':
        hardened = i >= 1 << 31

        if hardened:
            raise KeyDerivationError(
                'Cannot derive a hardened key from an extended public key')

        I = hmac.new(key=self.code,
                     msg=self.keydata() + int_to_bytes(i).rjust(4, b'\x00'),
                     digestmod=hashlib.sha512).digest()
        tmp = bytes_to_hex(self.keydata() + int_to_bytes(i).rjust(4, b'\x00'))

        I_L, I_R = I[:32], I[32:]

        key = WitPrivateKey(I_L).to_public().point + self.key.point
        ret_code = I_R
        path = self.path + f'/{i}'

        # TODO add point at infinity check
        return Xpub(WitPublicKey(key),
                    ret_code,
                    depth=self.depth + 1,
                    i=i,
                    parent=self.fingerprint(),
                    path=path)
Esempio n. 2
0
 def to_json(self, as_hex: bool = True):
     if self.public_key is None:
         return None
     return {
         'public_key': list(self.public_key)
     } if not as_hex else {
         'public_key': bytes_to_hex(self.public_key)
     }
Esempio n. 3
0
 def to_json(self, as_hex: bool = True):
     return {
         'proof': list(self.proof),
         'public_key': self.public_key.to_json()
     } if not as_hex else {
         'proof': bytes_to_hex(self.proof),
         'public_key': self.public_key.to_json()
     }
Esempio n. 4
0
 def to_json(self, as_hex: bool = True):
     return {
         'bytes': list(self._bytes),
         'compressed': self.compressed
     } if not as_hex else {
         'bytes': bytes_to_hex(self._bytes),
         'compressed': self.compressed
     }
Esempio n. 5
0
 def to_json(self, as_hex: bool = False):
     return {
         'kind':
         self.kind.to_string(),
         'url':
         self.url,
         'script':
         list(self.script) if not as_hex else bytes_to_hex(self.script)
     }
def to_slip32(master_key: Xprv) -> str:
    depth = master_key.depth
    chain_code = master_key.code
    private_key = master_key.key.bytes()

    slip_32 = int(depth).to_bytes(length=1, byteorder='big')
    slip_32 += chain_code
    slip_32 += b'\x00'
    slip_32 += private_key
    slip_32 += b'\x00'
    bech = bech32_encode_master_key(hrp='xprv', data=bytes_to_hex(slip_32))

    return bech
Esempio n. 7
0
 def to_address(self):
     return bech32_encode_address(hrp='wit', data=bytes_to_hex(self.hash))
Esempio n. 8
0
 def to_string(self):
     return bytes_to_hex(self.transaction_id.SHA256) + ':' + str(
         self.output_index)
Esempio n. 9
0
 def hex(self):
     return bytes_to_hex(self.msg)
Esempio n. 10
0
 def to_string(self):
     return bytes_to_hex(self.SHA256)
Esempio n. 11
0
 def to_json(self, as_hex: bool = False):
     return {
         'op': self.op,
         'args': list(self.args) if not as_hex else bytes_to_hex(self.args)
     }
Esempio n. 12
0
 def hex(self):
     return bytes_to_hex(self.encode())
Esempio n. 13
0
 def hex(self, compressed=True) -> str:
     return bytes_to_hex(self.encode(compressed=compressed))
Esempio n. 14
0
 def from_json(cls, data: dict):
     _bytes, _compressed = data.values()
     return WitPublicKey.from_hex(
         bytes_to_hex((int_to_bytes(_compressed) +
                       bytes(_bytes).rjust(32, b'\x00'))))
 def to_json(self, as_hex: bool = True):
     return {'der': list(self.der)} if not as_hex else {'der': bytes_to_hex(self.der)}