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)
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) }
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() }
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 }
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
def to_address(self): return bech32_encode_address(hrp='wit', data=bytes_to_hex(self.hash))
def to_string(self): return bytes_to_hex(self.transaction_id.SHA256) + ':' + str( self.output_index)
def hex(self): return bytes_to_hex(self.msg)
def to_string(self): return bytes_to_hex(self.SHA256)
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) }
def hex(self): return bytes_to_hex(self.encode())
def hex(self, compressed=True) -> str: return bytes_to_hex(self.encode(compressed=compressed))
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)}