def _cborize_byron_witnesses( keychain: seed.Keychain, inputs: list[CardanoTxInputType], tx_body_hash: bytes, protocol_magic: int, ) -> list[tuple[bytes, bytes, bytes, bytes]]: byron_witnesses = [] # include only one witness for each path paths = set() for tx_input in inputs: if is_byron_path(tx_input.address_n): paths.add(tuple(tx_input.address_n)) for path in paths: node = keychain.derive(list(path)) public_key = derive_public_key(keychain, list(path)) signature = ed25519.sign_ext(node.private_key(), node.private_key_ext(), tx_body_hash) chain_code = node.chain_code() address_attributes = cbor.encode( get_address_attributes(protocol_magic)) byron_witnesses.append( (public_key, signature, chain_code, address_attributes)) byron_witnesses.sort() return byron_witnesses
def _build_byron_witnesses( keychain: seed.Keychain, inputs: List[CardanoTxInputType], tx_body_hash: bytes, protocol_magic: int, ) -> List[Tuple[bytes, bytes, bytes, bytes]]: byron_witnesses = [] # include only one witness for each path paths = set() for input in inputs: if not is_byron_path(input.address_n): continue paths.add(tuple(input.address_n)) for path in paths: node = keychain.derive(list(path)) public_key = remove_ed25519_prefix(node.public_key()) signature = ed25519.sign_ext( node.private_key(), node.private_key_ext(), tx_body_hash ) chain_code = node.chain_code() address_attributes = cbor.encode(get_address_attributes(protocol_magic)) byron_witnesses.append((public_key, signature, chain_code, address_attributes)) return byron_witnesses
def _cborize_shelley_witness(keychain: seed.Keychain, tx_body_hash: bytes, path: List[int]) -> Tuple[bytes, bytes]: node = keychain.derive(path) signature = ed25519.sign_ext(node.private_key(), node.private_key_ext(), tx_body_hash) public_key = remove_ed25519_prefix(node.public_key()) return public_key, signature
def _sign_message(root_node, message: str, derivation_path: list): address, node = derive_address_and_node(root_node, derivation_path) signature = ed25519.sign_ext(node.private_key(), node.private_key_ext(), message) sig = CardanoMessageSignature() sig.public_key = seed.remove_ed25519_prefix(node.public_key()) sig.signature = signature return sig
def _build_witnesses(self, tx_aux_hash: str): witnesses = [] for index, node in enumerate(self.nodes): message = (b"\x01" + cbor.encode(self.protocol_magic) + b"\x58\x20" + tx_aux_hash) signature = ed25519.sign_ext(node.private_key(), node.private_key_ext(), message) extended_public_key = (remove_ed25519_prefix(node.public_key()) + node.chain_code()) witnesses.append([ self.types[index], cbor.Tagged(24, cbor.encode([extended_public_key, signature])), ]) return witnesses
def _build_witnesses(self, tx_aux_hash: str): witnesses = [] for input in self.inputs: _, node = derive_address_and_node(self.keychain, input.address_n) message = (b"\x01" + cbor.encode(self.protocol_magic) + b"\x58\x20" + tx_aux_hash) signature = ed25519.sign_ext(node.private_key(), node.private_key_ext(), message) extended_public_key = (remove_ed25519_prefix(node.public_key()) + node.chain_code()) witnesses.append([ (input.type or 0), cbor.Tagged(24, cbor.encode([extended_public_key, signature])), ]) return witnesses
def _create_catalyst_registration_payload_signature( keychain: seed.Keychain, catalyst_registration_payload: CatalystRegistrationPayload, path: list[int], ) -> bytes: node = keychain.derive(path) encoded_catalyst_registration = cbor.encode( {METADATA_KEY_CATALYST_REGISTRATION: catalyst_registration_payload}) catalyst_registration_hash = hashlib.blake2b( data=encoded_catalyst_registration, outlen=CATALYST_REGISTRATION_HASH_SIZE, ).digest() return ed25519.sign_ext(node.private_key(), node.private_key_ext(), catalyst_registration_hash)
def _build_witnesses(self, tx_aux_hash: str): witnesses = [] for index, node in enumerate(self.nodes): message = self.CARDANO_WITNESS_MAGIC_PREFIX + tx_aux_hash signature = ed25519.sign_ext( node.private_key(), node.private_key_ext(), message ) extended_public_key = ( seed.remove_ed25519_prefix(node.public_key()) + node.chain_code() ) witnesses.append( [ self.types[index], cbor.Tagged(24, cbor.encode([extended_public_key, signature])), ] ) return witnesses
def _build_shelley_witnesses( keychain: seed.Keychain, inputs: List[CardanoTxInputType], tx_body_hash: bytes, ) -> List[Tuple[bytes, bytes]]: shelley_witnesses = [] for input in inputs: if not is_shelley_path(input.address_n): continue node = keychain.derive(input.address_n) public_key = remove_ed25519_prefix(node.public_key()) signature = ed25519.sign_ext(node.private_key(), node.private_key_ext(), tx_body_hash) shelley_witnesses.append((public_key, signature)) return shelley_witnesses
def _sign_tx_hash(keychain: seed.Keychain, tx_body_hash: bytes, path: list[int]) -> bytes: node = keychain.derive(path) return ed25519.sign_ext(node.private_key(), node.private_key_ext(), tx_body_hash)