def from_pubkey(cls, key: PublicKey) -> "ID": serialized_key = key.serialize() algo = multihash.Func.sha2_256 if ENABLE_INLINING and len(serialized_key) <= MAX_INLINE_KEY_LENGTH: algo = IDENTITY_MULTIHASH_CODE mh_digest = multihash.digest(serialized_key, algo) return cls(mh_digest.encode())
def deserialize_public_key(data: bytes) -> PublicKey: f = PublicKey.deserialize_from_protobuf(data) try: deserializer = key_type_to_public_key_deserializer[f.key_type] except KeyError: raise MissingDeserializerError({"key_type": f.key_type, "key": "public_key"}) return deserializer(f.data)
def _mk_score(public_key: PublicKey, nonce: bytes) -> bytes: return _mk_multihash_sha256(public_key.serialize() + nonce)
def make_exchange_message(pubkey: PublicKey) -> plaintext_pb2.Exchange: pubkey_pb = crypto_pb2.PublicKey( key_type=pubkey.get_type().value, data=pubkey.to_bytes() ) id_bytes = ID.from_pubkey(pubkey).to_bytes() return plaintext_pb2.Exchange(id=id_bytes, pubkey=pubkey_pb)
def make_data_to_be_signed(noise_static_pubkey: PublicKey) -> bytes: prefix_bytes = SIGNED_DATA_PREFIX.encode("utf-8") return prefix_bytes + noise_static_pubkey.to_bytes()
def deserialize_public_key(data: bytes) -> PublicKey: f = PublicKey.deserialize_from_protobuf(data) deserializer = key_type_to_public_key_deserializer[f.key_type] return deserializer(f.data)