From 52ed258d3ae9987f9d2da46d75e047b835278510 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Wed, 18 Sep 2024 23:03:49 -0400 Subject: [PATCH 1/2] feat: verify creds signed with Ed25519VerificationKey2020 Signed-off-by: Daniel Bluhm --- .../vc/ld_proofs/crypto/wallet_key_pair.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/aries_cloudagent/vc/ld_proofs/crypto/wallet_key_pair.py b/aries_cloudagent/vc/ld_proofs/crypto/wallet_key_pair.py index 8797e450b2..8e7d280b67 100644 --- a/aries_cloudagent/vc/ld_proofs/crypto/wallet_key_pair.py +++ b/aries_cloudagent/vc/ld_proofs/crypto/wallet_key_pair.py @@ -1,6 +1,7 @@ """Key pair based on base wallet interface.""" from typing import List, Optional, Union +from base58 import b58encode from ....core.profile import Profile from ....wallet.base import BaseWallet @@ -8,6 +9,7 @@ from ....wallet.util import b58_to_bytes from ..error import LinkedDataProofException from .key_pair import KeyPair +from ....utils.multiformats import multibase, multicodec class WalletKeyPair(KeyPair): @@ -57,15 +59,23 @@ async def verify(self, message: Union[List[bytes], bytes], signature: bytes) -> def from_verification_method(self, verification_method: dict) -> "WalletKeyPair": """Create new WalletKeyPair from public key in verification method.""" - if "publicKeyBase58" not in verification_method: + if "publicKeyBase58" in verification_method: + key_material = verification_method["publicKeyBase58"] + elif "sec:publicKeyMultibase" in verification_method: + # verification_method is framed + _, raw_key = multicodec.unwrap( + multibase.decode(verification_method["sec:publicKeyMultibase"]["@value"]) + ) + key_material = b58encode(raw_key).decode() + else: raise LinkedDataProofException( - "Unable to set public key from verification method: no publicKeyBase58" + f"Unrecognized verification method type: {verification_method}" ) return WalletKeyPair( profile=self.profile, key_type=self.key_type, - public_key_base58=verification_method["publicKeyBase58"], + public_key_base58=key_material, ) @property From fcad0230d2f30b4c29f6c3c7c651ffe129a5e80e Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Wed, 18 Sep 2024 23:10:48 -0400 Subject: [PATCH 2/2] fix: test case expecting old error Signed-off-by: Daniel Bluhm --- .../vc/ld_proofs/crypto/tests/test_wallet_key_pair.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aries_cloudagent/vc/ld_proofs/crypto/tests/test_wallet_key_pair.py b/aries_cloudagent/vc/ld_proofs/crypto/tests/test_wallet_key_pair.py index b668c3f107..026df73b26 100644 --- a/aries_cloudagent/vc/ld_proofs/crypto/tests/test_wallet_key_pair.py +++ b/aries_cloudagent/vc/ld_proofs/crypto/tests/test_wallet_key_pair.py @@ -76,4 +76,4 @@ async def test_from_verification_method_x_no_public_key_base58(self): with self.assertRaises(LinkedDataProofException) as context: key_pair.from_verification_method({}) - assert "no publicKeyBase58" in str(context.exception) + assert "Unrecognized" in str(context.exception)