def test_id_from_public_key(): key_pair = create_new_key_pair() public_key = key_pair.public_key key_bin = public_key.serialize() algo = multihash.Func.sha2_256 mh_digest = multihash.digest(key_bin, algo) expected = ID(mh_digest.encode()) actual = ID.from_pubkey(public_key) assert actual == expected
def test_peer_id_interop(): private_key_protobuf_bytes = base64.b64decode(PRIVATE_KEY_PROTOBUF_SERIALIZATION) private_key_protobuf = pb.PrivateKey() private_key_protobuf.ParseFromString(private_key_protobuf_bytes) private_key_data = private_key_protobuf.data private_key_impl = RSA.import_key(private_key_data) private_key = RSAPrivateKey(private_key_impl) public_key = private_key.get_public_key() peer_id = ID.from_pubkey(public_key) assert peer_id == EXPECTED_PEER_ID