def derive_address_and_node(root_node, path: list): validate_derivation_path(path) derived_node = root_node.clone() # this means empty derivation path m/44'/1815' if len(path) == 2: address_payload = None address_attributes = {} else: if len(path) == 5: p = [path[2], path[4]] else: p = [path[2]] for indice in p: derived_node.derive_cardano(indice) hd_passphrase = _derive_hd_passphrase(root_node) address_payload = _encrypt_derivation_path(p, hd_passphrase) address_attributes = {1: cbor.encode(address_payload)} address_root = _get_address_root(derived_node, address_payload) address_type = 0 address_data = [address_root, address_attributes, address_type] address_data_encoded = cbor.encode(address_data) address = base58.encode( cbor.encode([ cbor.Tagged(24, address_data_encoded), crc.crc32(address_data_encoded) ])) return (address, derived_node)
def derive_address_and_node(keychain, path: list): node = keychain.derive(path) address_payload = None address_attributes = {} address_root = _get_address_root(node, address_payload) address_type = 0 address_data = [address_root, address_attributes, address_type] address_data_encoded = cbor.encode(address_data) address = base58.encode( cbor.encode( [cbor.Tagged(24, address_data_encoded), crc.crc32(address_data_encoded)] ) ) return (address, node)
def derive_address_and_node(root_node, path: list): derived_node = root_node.clone() address_payload = None address_attributes = {} for indice in path: derived_node.derive_cardano(indice) address_root = _get_address_root(derived_node, address_payload) address_type = 0 address_data = [address_root, address_attributes, address_type] address_data_encoded = cbor.encode(address_data) address = base58.encode( cbor.encode([ cbor.Tagged(24, address_data_encoded), crc.crc32(address_data_encoded) ])) return (address, derived_node)
def _decode_address_raw(address: bytes) -> bytes: try: address_unpacked = cbor.decode(address) except ValueError as e: if __debug__: log.exception(__name__, e) raise INVALID_ADDRESS if not isinstance(address_unpacked, list) or len(address_unpacked) != 2: raise INVALID_ADDRESS address_data_encoded = address_unpacked[0] if not isinstance(address_data_encoded, bytes): raise INVALID_ADDRESS address_crc = address_unpacked[1] if not isinstance(address_crc, int): raise INVALID_ADDRESS if address_crc != crc.crc32(address_data_encoded): raise INVALID_ADDRESS return address_data_encoded
def _decode_raw(address: bytes) -> bytes: try: address_unpacked = cbor.decode(address) except ValueError as e: if __debug__: log.exception(__name__, e) raise wire.ProcessError("Invalid address") if not isinstance(address_unpacked, list) or len(address_unpacked) != 2: raise wire.ProcessError("Invalid address") address_data_encoded = address_unpacked[0] if not isinstance(address_data_encoded, bytes): raise wire.ProcessError("Invalid address") address_crc = address_unpacked[1] if not isinstance(address_crc, int): raise wire.ProcessError("Invalid address") if address_crc != crc.crc32(address_data_encoded): raise wire.ProcessError("Invalid address") return address_data_encoded
def _encode_address_raw(address_data_encoded) -> bytes: return cbor.encode([ cbor.Tagged(24, address_data_encoded), crc.crc32(address_data_encoded) ])
def _encode_address_raw(address_data_encoded): return base58.encode( cbor.encode([ cbor.Tagged(24, address_data_encoded), crc.crc32(address_data_encoded) ]))
def test_crc32(self): for i, o in self.vectors_crc32: self.assertEqual(crc.crc32(i), o)