diff --git a/aries_cloudagent/config/default_context.py b/aries_cloudagent/config/default_context.py index 0c5f90cac2..360f103fa1 100644 --- a/aries_cloudagent/config/default_context.py +++ b/aries_cloudagent/config/default_context.py @@ -1,27 +1,27 @@ """Classes for configuring the default injection context.""" -from .base_context import ContextBuilder -from .injection_context import InjectionContext -from .provider import CachedProvider, ClassProvider - from ..cache.base import BaseCache from ..cache.in_memory import InMemoryCache from ..core.event_bus import EventBus +from ..core.goal_code_registry import GoalCodeRegistry from ..core.plugin_registry import PluginRegistry from ..core.profile import ProfileManager, ProfileManagerProvider from ..core.protocol_registry import ProtocolRegistry -from ..core.goal_code_registry import GoalCodeRegistry -from ..resolver.did_resolver import DIDResolver -from ..tails.base import BaseTailsServer - from ..protocols.actionmenu.v1_0.base_service import BaseMenuService from ..protocols.actionmenu.v1_0.driver_service import DriverMenuService from ..protocols.didcomm_prefix import DIDCommPrefix from ..protocols.introduction.v0_1.base_service import BaseIntroductionService from ..protocols.introduction.v0_1.demo_service import DemoIntroductionService +from ..resolver.did_resolver import DIDResolver +from ..tails.base import BaseTailsServer from ..transport.wire_format import BaseWireFormat -from ..utils.stats import Collector from ..utils.dependencies import is_indy_sdk_module_installed +from ..utils.stats import Collector +from ..wallet.did_method import DIDMethods +from ..wallet.key_type import KeyTypes +from .base_context import ContextBuilder +from .injection_context import InjectionContext +from .provider import CachedProvider, ClassProvider class DefaultContextBuilder(ContextBuilder): @@ -51,6 +51,8 @@ async def build_context(self) -> InjectionContext: # Global did resolver context.injector.bind_instance(DIDResolver, DIDResolver([])) + context.injector.bind_instance(DIDMethods, DIDMethods()) + context.injector.bind_instance(KeyTypes, KeyTypes()) await self.bind_providers(context) await self.load_plugins(context) diff --git a/aries_cloudagent/config/wallet.py b/aries_cloudagent/config/wallet.py index 61e34b2a73..a49aae304f 100644 --- a/aries_cloudagent/config/wallet.py +++ b/aries_cloudagent/config/wallet.py @@ -11,8 +11,8 @@ from ..wallet.base import BaseWallet from ..wallet.crypto import seed_to_did from ..wallet.did_info import DIDInfo -from ..wallet.did_method import DIDMethod -from ..wallet.key_type import KeyType +from ..wallet.did_method import SOV +from ..wallet.key_type import ED25519 from .base import ConfigError from .injection_context import InjectionContext @@ -79,7 +79,7 @@ async def wallet_config( if wallet_seed and seed_to_did(wallet_seed) != public_did: if context.settings.get("wallet.replace_public_did"): replace_did_info = await wallet.create_local_did( - method=DIDMethod.SOV, key_type=KeyType.ED25519, seed=wallet_seed + method=SOV, key_type=ED25519, seed=wallet_seed ) public_did = replace_did_info.did await wallet.set_public_did(public_did) @@ -99,8 +99,8 @@ async def wallet_config( metadata = {"endpoint": endpoint} if endpoint else None local_did_info = await wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=wallet_seed, metadata=metadata, ) @@ -110,7 +110,7 @@ async def wallet_config( print(f"Verkey: {local_did_info.verkey}") else: public_did_info = await wallet.create_public_did( - method=DIDMethod.SOV, key_type=KeyType.ED25519, seed=wallet_seed + method=SOV, key_type=ED25519, seed=wallet_seed ) public_did = public_did_info.did if provision: @@ -128,8 +128,8 @@ async def wallet_config( test_seed = "testseed000000000000000000000001" if test_seed: await wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=test_seed, metadata={"endpoint": "1.2.3.4:8021"}, ) diff --git a/aries_cloudagent/core/tests/test_conductor.py b/aries_cloudagent/core/tests/test_conductor.py index fe94ad97ad..c105a66307 100644 --- a/aries_cloudagent/core/tests/test_conductor.py +++ b/aries_cloudagent/core/tests/test_conductor.py @@ -8,16 +8,13 @@ from ...config.injection_context import InjectionContext from ...connections.models.conn_record import ConnRecord from ...connections.models.connection_target import ConnectionTarget -from ...connections.models.diddoc import ( - DIDDoc, - PublicKey, - PublicKeyType, - Service, -) +from ...connections.models.diddoc import DIDDoc, PublicKey, PublicKeyType, Service from ...core.event_bus import EventBus, MockEventBus from ...core.in_memory import InMemoryProfileManager from ...core.profile import ProfileManager from ...core.protocol_registry import ProtocolRegistry +from ...multitenant.base import BaseMultitenantManager +from ...multitenant.manager import MultitenantManager from ...protocols.coordinate_mediation.mediation_invite_store import ( MediationInviteRecord, ) @@ -26,8 +23,6 @@ ) from ...protocols.out_of_band.v1_0.models.oob_record import OobRecord from ...resolver.did_resolver import DIDResolver -from ...multitenant.base import BaseMultitenantManager -from ...multitenant.manager import MultitenantManager from ...storage.base import BaseStorage from ...storage.error import StorageNotFoundError from ...transport.inbound.message import InboundMessage @@ -36,14 +31,13 @@ from ...transport.outbound.manager import QueuedOutboundMessage from ...transport.outbound.message import OutboundMessage from ...transport.outbound.status import OutboundSendStatus -from ...transport.wire_format import BaseWireFormat from ...transport.pack_format import PackWireFormat +from ...transport.wire_format import BaseWireFormat from ...utils.stats import Collector from ...version import __version__ from ...wallet.base import BaseWallet -from ...wallet.key_type import KeyType -from ...wallet.did_method import DIDMethod - +from ...wallet.did_method import SOV +from ...wallet.key_type import ED25519 from .. import conductor as test_module @@ -132,8 +126,8 @@ async def test_startup(self): wallet = session.inject(BaseWallet) await wallet.create_public_did( - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) mock_inbound_mgr.return_value.setup.assert_awaited_once() @@ -601,8 +595,8 @@ async def test_admin(self): session = await conductor.root_profile.session() wallet = session.inject(BaseWallet) await wallet.create_public_did( - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) with async_mock.patch.object( @@ -645,8 +639,8 @@ async def test_admin_startx(self): session = await conductor.root_profile.session() wallet = session.inject(BaseWallet) await wallet.create_public_did( - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) with async_mock.patch.object( @@ -717,8 +711,8 @@ async def test_start_static(self): session = await conductor.root_profile.session() wallet = session.inject(BaseWallet) await wallet.create_public_did( - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) mock_mgr.return_value.create_static_connection = async_mock.AsyncMock() @@ -887,8 +881,8 @@ async def test_print_invite_connection(self): session = await conductor.root_profile.session() wallet = session.inject(BaseWallet) await wallet.create_public_did( - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) await conductor.start() @@ -1401,8 +1395,8 @@ async def test_startup_x_version_mismatch(self): wallet = session.inject(BaseWallet) await wallet.create_public_did( - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) mock_inbound_mgr.return_value.setup.assert_awaited_once() @@ -1438,8 +1432,8 @@ async def test_startup_x_no_storage_version(self): wallet = session.inject(BaseWallet) await wallet.create_public_did( - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) mock_inbound_mgr.return_value.setup.assert_awaited_once() diff --git a/aries_cloudagent/did/did_key.py b/aries_cloudagent/did/did_key.py index 70101910fb..3a74971612 100644 --- a/aries_cloudagent/did/did_key.py +++ b/aries_cloudagent/did/did_key.py @@ -1,7 +1,15 @@ """DID Key class and resolver methods.""" from ..wallet.crypto import ed25519_pk_to_curve25519 -from ..wallet.key_type import KeyType +from ..wallet.key_type import ( + BLS12381G1G2, + ED25519, + KeyType, + BLS12381G1, + X25519, + BLS12381G2, + KeyTypes, +) from ..wallet.util import b58_to_bytes, bytes_to_b58 from ..vc.ld_proofs.constants import DID_V1_CONTEXT_URL @@ -31,7 +39,7 @@ def from_public_key_b58(cls, public_key: str, key_type: KeyType) -> "DIDKey": return cls.from_public_key(public_key_bytes, key_type) @classmethod - def from_fingerprint(cls, fingerprint: str) -> "DIDKey": + def from_fingerprint(cls, fingerprint: str, key_types=None) -> "DIDKey": """Initialize new DIDKey instance from multibase encoded fingerprint. The fingerprint contains both the public key and key type. @@ -43,7 +51,9 @@ def from_fingerprint(cls, fingerprint: str) -> "DIDKey": key_bytes_with_prefix = b58_to_bytes(fingerprint[1:]) # Get associated key type with prefixed bytes - key_type = KeyType.from_prefixed_bytes(key_bytes_with_prefix) + if not key_types: + key_types = KeyTypes() + key_type = key_types.from_prefixed_bytes(key_bytes_with_prefix) if not key_type: raise Exception( @@ -169,8 +179,8 @@ def construct_did_key_bls12381g1g2(did_key: "DIDKey") -> dict: g1_public_key = did_key.public_key[:48] g2_public_key = did_key.public_key[48:] - bls12381g1_key = DIDKey.from_public_key(g1_public_key, KeyType.BLS12381G1) - bls12381g2_key = DIDKey.from_public_key(g2_public_key, KeyType.BLS12381G2) + bls12381g1_key = DIDKey.from_public_key(g1_public_key, BLS12381G1) + bls12381g2_key = DIDKey.from_public_key(g2_public_key, BLS12381G2) bls12381g1_key_id = f"{did_key.did}#{bls12381g1_key.fingerprint}" bls12381g2_key_id = f"{did_key.did}#{bls12381g2_key.fingerprint}" @@ -241,7 +251,7 @@ def construct_did_key_ed25519(did_key: "DIDKey") -> dict: """ curve25519 = ed25519_pk_to_curve25519(did_key.public_key) - x25519 = DIDKey.from_public_key(curve25519, KeyType.X25519) + x25519 = DIDKey.from_public_key(curve25519, X25519) did_doc = construct_did_signature_key_base( id=did_key.did, @@ -289,9 +299,9 @@ def construct_did_signature_key_base( DID_KEY_RESOLVERS = { - KeyType.ED25519: construct_did_key_ed25519, - KeyType.X25519: construct_did_key_x25519, - KeyType.BLS12381G2: construct_did_key_bls12381g2, - KeyType.BLS12381G1: construct_did_key_bls12381g1, - KeyType.BLS12381G1G2: construct_did_key_bls12381g1g2, + ED25519: construct_did_key_ed25519, + X25519: construct_did_key_x25519, + BLS12381G2: construct_did_key_bls12381g2, + BLS12381G1: construct_did_key_bls12381g1, + BLS12381G1G2: construct_did_key_bls12381g1g2, } diff --git a/aries_cloudagent/did/tests/test_did_key_bls12381g1.py b/aries_cloudagent/did/tests/test_did_key_bls12381g1.py index 9b95465df4..f5b84b3bd0 100644 --- a/aries_cloudagent/did/tests/test_did_key_bls12381g1.py +++ b/aries_cloudagent/did/tests/test_did_key_bls12381g1.py @@ -1,7 +1,7 @@ from unittest import TestCase -from ...wallet.key_type import KeyType +from ...wallet.key_type import BLS12381G1 from ...wallet.util import b58_to_bytes from ..did_key import DIDKey, DID_KEY_RESOLVERS from .test_dids import ( @@ -24,14 +24,12 @@ class TestDIDKey(TestCase): def test_bls12381g1_from_public_key(self): key_bytes = b58_to_bytes(TEST_BLS12381G1_BASE58_KEY) - did_key = DIDKey.from_public_key(key_bytes, KeyType.BLS12381G1) + did_key = DIDKey.from_public_key(key_bytes, BLS12381G1) assert did_key.did == TEST_BLS12381G1_DID def test_bls12381g1_from_public_key_b58(self): - did_key = DIDKey.from_public_key_b58( - TEST_BLS12381G1_BASE58_KEY, KeyType.BLS12381G1 - ) + did_key = DIDKey.from_public_key_b58(TEST_BLS12381G1_BASE58_KEY, BLS12381G1) assert did_key.did == TEST_BLS12381G1_DID @@ -53,20 +51,20 @@ def test_bls12381g1_properties(self): assert did_key.did == TEST_BLS12381G1_DID assert did_key.public_key_b58 == TEST_BLS12381G1_BASE58_KEY assert did_key.public_key == b58_to_bytes(TEST_BLS12381G1_BASE58_KEY) - assert did_key.key_type == KeyType.BLS12381G1 + assert did_key.key_type == BLS12381G1 assert did_key.key_id == TEST_BLS12381G1_KEY_ID assert did_key.prefixed_public_key == TEST_BLS12381G1_PREFIX_BYTES def test_bls12381g1_diddoc(self): did_key = DIDKey.from_did(TEST_BLS12381G1_DID) - resolver = DID_KEY_RESOLVERS[KeyType.BLS12381G1] + resolver = DID_KEY_RESOLVERS[BLS12381G1] assert resolver(did_key) == did_key.did_doc def test_bls12381g1_resolver(self): did_key = DIDKey.from_did(TEST_BLS12381G1_DID) - resolver = DID_KEY_RESOLVERS[KeyType.BLS12381G1] + resolver = DID_KEY_RESOLVERS[BLS12381G1] did_doc = resolver(did_key) assert ( diff --git a/aries_cloudagent/did/tests/test_did_key_bls12381g1g2.py b/aries_cloudagent/did/tests/test_did_key_bls12381g1g2.py index 59e2a05907..f5ed77e64d 100644 --- a/aries_cloudagent/did/tests/test_did_key_bls12381g1g2.py +++ b/aries_cloudagent/did/tests/test_did_key_bls12381g1g2.py @@ -1,6 +1,6 @@ from unittest import TestCase -from ...wallet.key_type import KeyType +from ...wallet.key_type import BLS12381G1, BLS12381G1G2, BLS12381G2 from ...wallet.util import b58_to_bytes from ..did_key import DIDKey, DID_KEY_RESOLVERS from .test_dids import ( @@ -31,14 +31,12 @@ class TestDIDKey(TestCase): def test_bls12381g1g2_from_public_key(self): key_bytes = b58_to_bytes(TEST_BLS12381G1G2_BASE58_KEY) - did_key = DIDKey.from_public_key(key_bytes, KeyType.BLS12381G1G2) + did_key = DIDKey.from_public_key(key_bytes, BLS12381G1G2) assert did_key.did == TEST_BLS12381G1G2_DID def test_bls12381g1g2_from_public_key_b58(self): - did_key = DIDKey.from_public_key_b58( - TEST_BLS12381G1G2_BASE58_KEY, KeyType.BLS12381G1G2 - ) + did_key = DIDKey.from_public_key_b58(TEST_BLS12381G1G2_BASE58_KEY, BLS12381G1G2) assert did_key.did == TEST_BLS12381G1G2_DID @@ -60,13 +58,13 @@ def test_bls12381g1g2_properties(self): assert did_key.did == TEST_BLS12381G1G2_DID assert did_key.public_key_b58 == TEST_BLS12381G1G2_BASE58_KEY assert did_key.public_key == b58_to_bytes(TEST_BLS12381G1G2_BASE58_KEY) - assert did_key.key_type == KeyType.BLS12381G1G2 + assert did_key.key_type == BLS12381G1G2 assert did_key.prefixed_public_key == TEST_BLS12381G1G2_PREFIX_BYTES def test_bls12381g1g2_diddoc(self): did_key = DIDKey.from_did(TEST_BLS12381G1G2_DID) - resolver = DID_KEY_RESOLVERS[KeyType.BLS12381G1G2] + resolver = DID_KEY_RESOLVERS[BLS12381G1G2] assert resolver(did_key) == did_key.did_doc @@ -74,7 +72,7 @@ def test_bls12381g1g2_resolver(self): did_key = DIDKey.from_did( "did:key:z5TcESXuYUE9aZWYwSdrUEGK1HNQFHyTt4aVpaCTVZcDXQmUheFwfNZmRksaAbBneNm5KyE52SdJeRCN1g6PJmF31GsHWwFiqUDujvasK3wTiDr3vvkYwEJHt7H5RGEKYEp1ErtQtcEBgsgY2DA9JZkHj1J9HZ8MRDTguAhoFtR4aTBQhgnkP4SwVbxDYMEZoF2TMYn3s" ) - resolver = DID_KEY_RESOLVERS[KeyType.BLS12381G1G2] + resolver = DID_KEY_RESOLVERS[BLS12381G1G2] did_doc = resolver(did_key) assert ( @@ -88,13 +86,13 @@ def test_bls12381g1g1_to_g1(self): # TODO: add easier method to go form g1 <- g1g2 -> g2 # First 48 bytes is g1 key g1_public_key = g1g2_did.public_key[:48] - g1_did = DIDKey.from_public_key(g1_public_key, KeyType.BLS12381G1) + g1_did = DIDKey.from_public_key(g1_public_key, BLS12381G1) assert g1_did.fingerprint == TEST_BLS12381G1_FINGERPRINT assert g1_did.did == TEST_BLS12381G1_DID assert g1_did.public_key_b58 == TEST_BLS12381G1_BASE58_KEY assert g1_did.public_key == b58_to_bytes(TEST_BLS12381G1_BASE58_KEY) - assert g1_did.key_type == KeyType.BLS12381G1 + assert g1_did.key_type == BLS12381G1 def test_bls12381g1g1_to_g2(self): g1g2_did = DIDKey.from_did(TEST_BLS12381G1G2_DID) @@ -102,10 +100,10 @@ def test_bls12381g1g1_to_g2(self): # TODO: add easier method to go form g1 <- g1g2 -> g2 # From 48 bytes is g2 key g2_public_key = g1g2_did.public_key[48:] - g2_did = DIDKey.from_public_key(g2_public_key, KeyType.BLS12381G2) + g2_did = DIDKey.from_public_key(g2_public_key, BLS12381G2) assert g2_did.fingerprint == TEST_BLS12381G2_FINGERPRINT assert g2_did.did == TEST_BLS12381G2_DID assert g2_did.public_key_b58 == TEST_BLS12381G2_BASE58_KEY assert g2_did.public_key == b58_to_bytes(TEST_BLS12381G2_BASE58_KEY) - assert g2_did.key_type == KeyType.BLS12381G2 + assert g2_did.key_type == BLS12381G2 diff --git a/aries_cloudagent/did/tests/test_did_key_bls12381g2.py b/aries_cloudagent/did/tests/test_did_key_bls12381g2.py index 0f2cb67fc1..0eb4b4c8f4 100644 --- a/aries_cloudagent/did/tests/test_did_key_bls12381g2.py +++ b/aries_cloudagent/did/tests/test_did_key_bls12381g2.py @@ -1,6 +1,6 @@ from unittest import TestCase -from ...wallet.key_type import KeyType +from ...wallet.key_type import BLS12381G2 from ...wallet.util import b58_to_bytes from ..did_key import DIDKey, DID_KEY_RESOLVERS from .test_dids import ( @@ -19,14 +19,12 @@ class TestDIDKey(TestCase): def test_bls12381g2_from_public_key(self): key_bytes = b58_to_bytes(TEST_BLS12381G2_BASE58_KEY) - did_key = DIDKey.from_public_key(key_bytes, KeyType.BLS12381G2) + did_key = DIDKey.from_public_key(key_bytes, BLS12381G2) assert did_key.did == TEST_BLS12381G2_DID def test_bls12381g2_from_public_key_b58(self): - did_key = DIDKey.from_public_key_b58( - TEST_BLS12381G2_BASE58_KEY, KeyType.BLS12381G2 - ) + did_key = DIDKey.from_public_key_b58(TEST_BLS12381G2_BASE58_KEY, BLS12381G2) assert did_key.did == TEST_BLS12381G2_DID @@ -48,20 +46,20 @@ def test_bls12381g2_properties(self): assert did_key.did == TEST_BLS12381G2_DID assert did_key.public_key_b58 == TEST_BLS12381G2_BASE58_KEY assert did_key.public_key == b58_to_bytes(TEST_BLS12381G2_BASE58_KEY) - assert did_key.key_type == KeyType.BLS12381G2 + assert did_key.key_type == BLS12381G2 assert did_key.key_id == TEST_BLS12381G2_KEY_ID assert did_key.prefixed_public_key == TEST_BLS12381G2_PREFIX_BYTES def test_bls12381g2_diddoc(self): did_key = DIDKey.from_did(TEST_BLS12381G2_DID) - resolver = DID_KEY_RESOLVERS[KeyType.BLS12381G2] + resolver = DID_KEY_RESOLVERS[BLS12381G2] assert resolver(did_key) == did_key.did_doc def test_bls12381g2_resolver(self): did_key = DIDKey.from_did(TEST_BLS12381G2_DID) - resolver = DID_KEY_RESOLVERS[KeyType.BLS12381G2] + resolver = DID_KEY_RESOLVERS[BLS12381G2] did_doc = resolver(did_key) assert ( diff --git a/aries_cloudagent/did/tests/test_did_key_ed25519.py b/aries_cloudagent/did/tests/test_did_key_ed25519.py index 3911fc3e36..53c2eb8bf2 100644 --- a/aries_cloudagent/did/tests/test_did_key_ed25519.py +++ b/aries_cloudagent/did/tests/test_did_key_ed25519.py @@ -1,6 +1,6 @@ from unittest import TestCase -from ...wallet.key_type import KeyType +from ...wallet.key_type import ED25519 from ...wallet.util import b58_to_bytes from ..did_key import DIDKey, DID_KEY_RESOLVERS from .test_dids import DID_ED25519_z6MkmjY8GnV5i9YTDtPETC2uUAW6ejw3nk5mXF5yci5ab7th @@ -17,12 +17,12 @@ class TestDIDKey(TestCase): def test_ed25519_from_public_key(self): key_bytes = b58_to_bytes(TEST_ED25519_BASE58_KEY) - did_key = DIDKey.from_public_key(key_bytes, KeyType.ED25519) + did_key = DIDKey.from_public_key(key_bytes, ED25519) assert did_key.did == TEST_ED25519_DID def test_ed25519_from_public_key_b58(self): - did_key = DIDKey.from_public_key_b58(TEST_ED25519_BASE58_KEY, KeyType.ED25519) + did_key = DIDKey.from_public_key_b58(TEST_ED25519_BASE58_KEY, ED25519) assert did_key.did == TEST_ED25519_DID @@ -44,20 +44,20 @@ def test_ed25519_properties(self): assert did_key.did == TEST_ED25519_DID assert did_key.public_key_b58 == TEST_ED25519_BASE58_KEY assert did_key.public_key == b58_to_bytes(TEST_ED25519_BASE58_KEY) - assert did_key.key_type == KeyType.ED25519 + assert did_key.key_type == ED25519 assert did_key.key_id == TEST_ED25519_KEY_ID assert did_key.prefixed_public_key == TEST_ED25519_PREFIX_BYTES def test_ed25519_diddoc(self): did_key = DIDKey.from_did(TEST_ED25519_DID) - resolver = DID_KEY_RESOLVERS[KeyType.ED25519] + resolver = DID_KEY_RESOLVERS[ED25519] assert resolver(did_key) == did_key.did_doc def test_ed25519_resolver(self): did_key = DIDKey.from_did(TEST_ED25519_DID) - resolver = DID_KEY_RESOLVERS[KeyType.ED25519] + resolver = DID_KEY_RESOLVERS[ED25519] did_doc = resolver(did_key) # resolved using uniresolver, updated to did v1 diff --git a/aries_cloudagent/did/tests/test_did_key_x25519.py b/aries_cloudagent/did/tests/test_did_key_x25519.py index 924011f396..84513da814 100644 --- a/aries_cloudagent/did/tests/test_did_key_x25519.py +++ b/aries_cloudagent/did/tests/test_did_key_x25519.py @@ -1,6 +1,6 @@ from unittest import TestCase -from ...wallet.key_type import KeyType +from ...wallet.key_type import X25519 from ...wallet.util import b58_to_bytes from ..did_key import DIDKey, DID_KEY_RESOLVERS from .test_dids import DID_X25519_z6LShLeXRTzevtwcfehaGEzCMyL3bNsAeKCwcqwJxyCo63yE @@ -15,12 +15,12 @@ class TestDIDKey(TestCase): def test_x25519_from_public_key(self): key_bytes = b58_to_bytes(TEST_X25519_BASE58_KEY) - did_key = DIDKey.from_public_key(key_bytes, KeyType.X25519) + did_key = DIDKey.from_public_key(key_bytes, X25519) assert did_key.did == TEST_X25519_DID def test_x25519_from_public_key_b58(self): - did_key = DIDKey.from_public_key_b58(TEST_X25519_BASE58_KEY, KeyType.X25519) + did_key = DIDKey.from_public_key_b58(TEST_X25519_BASE58_KEY, X25519) assert did_key.did == TEST_X25519_DID @@ -42,20 +42,20 @@ def test_x25519_properties(self): assert did_key.did == TEST_X25519_DID assert did_key.public_key_b58 == TEST_X25519_BASE58_KEY assert did_key.public_key == b58_to_bytes(TEST_X25519_BASE58_KEY) - assert did_key.key_type == KeyType.X25519 + assert did_key.key_type == X25519 assert did_key.key_id == TEST_X25519_KEY_ID assert did_key.prefixed_public_key == TEST_X25519_PREFIX_BYTES def test_x25519_diddoc(self): did_key = DIDKey.from_did(TEST_X25519_DID) - resolver = DID_KEY_RESOLVERS[KeyType.X25519] + resolver = DID_KEY_RESOLVERS[X25519] assert resolver(did_key) == did_key.did_doc def test_x25519_resolver(self): did_key = DIDKey.from_did(TEST_X25519_DID) - resolver = DID_KEY_RESOLVERS[KeyType.X25519] + resolver = DID_KEY_RESOLVERS[X25519] did_doc = resolver(did_key) # resolved using uniresolver, updated to did v1 diff --git a/aries_cloudagent/ledger/tests/test_indy.py b/aries_cloudagent/ledger/tests/test_indy.py index bda1890c2a..0b36b67452 100644 --- a/aries_cloudagent/ledger/tests/test_indy.py +++ b/aries_cloudagent/ledger/tests/test_indy.py @@ -8,19 +8,17 @@ from asynctest import mock as async_mock, TestCase as AsyncTestCase from ...config.injection_context import InjectionContext -from ...core.in_memory import InMemoryProfile from ...cache.in_memory import InMemoryCache from ...indy.issuer import IndyIssuer, IndyIssuerError from ...indy.sdk.profile import IndySdkProfile -from ...indy.sdk.wallet_setup import IndyWalletConfig from ...storage.record import StorageRecord from ...wallet.base import BaseWallet from ...wallet.did_info import DIDInfo from ...wallet.did_posture import DIDPosture from ...wallet.error import WalletNotFoundError -from ...wallet.indy import IndyOpenWallet, IndySdkWallet -from ...wallet.key_type import KeyType -from ...wallet.did_method import DIDMethod +from ...wallet.indy import IndySdkWallet +from ...wallet.key_type import ED25519 +from ...wallet.did_method import SOV from ..endpoint_type import EndpointType from ..indy import ( @@ -70,8 +68,8 @@ async def setUp(self): did=self.test_did, verkey="3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx", metadata={"test": "test"}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) self.test_verkey = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx" context = InjectionContext() @@ -1219,8 +1217,8 @@ async def test_send_credential_definition( did=self.test_did, verkey=self.test_verkey, metadata=None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_did = mock_wallet_get_public_did.return_value ( @@ -1299,8 +1297,8 @@ async def test_send_credential_definition_endorse_only( self.test_did, self.test_verkey, None, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) async with ledger: ( @@ -1382,8 +1380,8 @@ async def test_send_credential_definition_exists_in_ledger_and_wallet( did=self.test_did, verkey=self.test_verkey, metadata=None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) async with ledger: @@ -1794,8 +1792,8 @@ async def test_send_credential_definition_on_ledger_in_wallet( did=self.test_did, verkey=self.test_verkey, metadata=None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_did = mock_wallet_get_public_did.return_value @@ -1868,8 +1866,8 @@ async def test_send_credential_definition_create_cred_def_exception( did=self.test_did, verkey=self.test_verkey, metadata=None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) async with ledger: with self.assertRaises(LedgerError): diff --git a/aries_cloudagent/ledger/tests/test_indy_vdr.py b/aries_cloudagent/ledger/tests/test_indy_vdr.py index f20781e838..5f820aeeab 100644 --- a/aries_cloudagent/ledger/tests/test_indy_vdr.py +++ b/aries_cloudagent/ledger/tests/test_indy_vdr.py @@ -9,8 +9,8 @@ from ...core.in_memory import InMemoryProfile from ...indy.issuer import IndyIssuer from ...wallet.base import BaseWallet -from ...wallet.key_type import KeyType -from ...wallet.did_method import DIDMethod +from ...wallet.key_type import KeyType, ED25519 +from ...wallet.did_method import SOV, DIDMethods from ...wallet.did_info import DIDInfo from ..endpoint_type import EndpointType @@ -67,7 +67,7 @@ async def test_submit_signed( ledger: IndyVdrLedger, ): wallet = (await ledger.profile.session()).wallet - test_did = await wallet.create_public_did(DIDMethod.SOV, KeyType.ED25519) + test_did = await wallet.create_public_did(SOV, ED25519) test_msg = indy_vdr.ledger.build_get_txn_request(test_did.did, 1, 1) async with ledger: @@ -120,7 +120,7 @@ async def test_submit_signed_taa_accept( ledger: IndyVdrLedger, ): wallet = (await ledger.profile.session()).wallet - test_did = await wallet.create_public_did(DIDMethod.SOV, KeyType.ED25519) + test_did = await wallet.create_public_did(SOV, ED25519) async with ledger: test_msg = indy_vdr.ledger.build_get_txn_request(test_did.did, 1, 1) @@ -188,7 +188,7 @@ async def test_txn_endorse( with pytest.raises(BadLedgerRequestError): await ledger.txn_endorse(request_json=test_msg.body) - test_did = await wallet.create_public_did(DIDMethod.SOV, KeyType.ED25519) + test_did = await wallet.create_public_did(SOV, ED25519) test_msg.set_endorser(test_did.did) endorsed_json = await ledger.txn_endorse(request_json=test_msg.body) @@ -201,7 +201,7 @@ async def test_send_schema( ledger: IndyVdrLedger, ): wallet = (await ledger.profile.session()).wallet - test_did = await wallet.create_public_did(DIDMethod.SOV, KeyType.ED25519) + test_did = await wallet.create_public_did(SOV, ED25519) issuer = async_mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ( "schema_issuer_did:schema_name:9.1", @@ -262,7 +262,7 @@ async def test_send_schema_already_exists( ledger: IndyVdrLedger, ): wallet = (await ledger.profile.session()).wallet - test_did = await wallet.create_public_did(DIDMethod.SOV, KeyType.ED25519) + test_did = await wallet.create_public_did(SOV, ED25519) issuer = async_mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ( "schema_issuer_did:schema_name:9.1", @@ -292,7 +292,7 @@ async def test_send_schema_ledger_read_only( ledger: IndyVdrLedger, ): wallet = (await ledger.profile.session()).wallet - test_did = await wallet.create_public_did(DIDMethod.SOV, KeyType.ED25519) + test_did = await wallet.create_public_did(SOV, ED25519) issuer = async_mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ( "schema_issuer_did:schema_name:9.1", @@ -321,7 +321,7 @@ async def test_send_schema_ledger_transaction_error( ledger: IndyVdrLedger, ): wallet = (await ledger.profile.session()).wallet - test_did = await wallet.create_public_did(DIDMethod.SOV, KeyType.ED25519) + test_did = await wallet.create_public_did(SOV, ED25519) issuer = async_mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ( "schema_issuer_did:schema_name:9.1", @@ -383,7 +383,7 @@ async def test_send_credential_definition( ledger: IndyVdrLedger, ): wallet = (await ledger.profile.session()).wallet - test_did = await wallet.create_public_did(DIDMethod.SOV, KeyType.ED25519) + test_did = await wallet.create_public_did(SOV, ED25519) schema_id = "55GkHamhTU1ZbTbV2ab9DE:2:schema_name:9.1" cred_def_id = "55GkHamhTU1ZbTbV2ab9DE:3:CL:99:tag" cred_def = { @@ -598,7 +598,7 @@ async def test_update_endpoint_for_did( ledger: IndyVdrLedger, ): wallet = (await ledger.profile.session()).wallet - test_did = await wallet.create_public_did(DIDMethod.SOV, KeyType.ED25519) + test_did = await wallet.create_public_did(SOV, ED25519) async with ledger: ledger.pool_handle.submit_request.side_effect = ( {"data": None}, @@ -675,7 +675,7 @@ async def test_construct_attr_json( async def test_update_endpoint_for_did_calls_attr_json(self, ledger: IndyVdrLedger): routing_keys = ["3YJCx3TqotDWFGv7JMR5erEvrmgu5y4FDqjR7sKWxgXn"] wallet = (await ledger.profile.session()).wallet - test_did = await wallet.create_public_did(DIDMethod.SOV, KeyType.ED25519) + test_did = await wallet.create_public_did(SOV, ED25519) async with ledger: with async_mock.patch.object( @@ -742,8 +742,8 @@ async def test_register_nym_local( ledger: IndyVdrLedger, ): wallet: BaseWallet = (await ledger.profile.session()).wallet - public_did = await wallet.create_public_did(DIDMethod.SOV, KeyType.ED25519) - post_did = await wallet.create_local_did(DIDMethod.SOV, KeyType.ED25519) + public_did = await wallet.create_public_did(SOV, ED25519) + post_did = await wallet.create_local_did(SOV, ED25519) async with ledger: await ledger.register_nym(post_did.did, post_did.verkey) did = await wallet.get_local_did(post_did.did) @@ -755,7 +755,7 @@ async def test_register_nym_non_local( ledger: IndyVdrLedger, ): wallet: BaseWallet = (await ledger.profile.session()).wallet - public_did = await wallet.create_public_did(DIDMethod.SOV, KeyType.ED25519) + public_did = await wallet.create_public_did(SOV, ED25519) async with ledger: await ledger.register_nym("55GkHamhTU1ZbTbV2ab9DE", "verkey") @@ -898,7 +898,7 @@ async def test_send_revoc_reg_def( ledger: IndyVdrLedger, ): wallet: BaseWallet = (await ledger.profile.session()).wallet - public_did = await wallet.create_public_did(DIDMethod.SOV, KeyType.ED25519) + public_did = await wallet.create_public_did(SOV, ED25519) async with ledger: reg_id = ( "55GkHamhTU1ZbTbV2ab9DE:4:55GkHamhTU1ZbTbV2ab9DE:3:CL:99:tag:CL_ACCUM:0" @@ -927,7 +927,7 @@ async def test_send_revoc_reg_entry( ledger: IndyVdrLedger, ): wallet: BaseWallet = (await ledger.profile.session()).wallet - public_did = await wallet.create_public_did(DIDMethod.SOV, KeyType.ED25519) + public_did = await wallet.create_public_did(SOV, ED25519) async with ledger: reg_id = ( "55GkHamhTU1ZbTbV2ab9DE:4:55GkHamhTU1ZbTbV2ab9DE:3:CL:99:tag:CL_ACCUM:0" @@ -966,7 +966,7 @@ async def test_credential_definition_id2schema_id(self, ledger: IndyVdrLedger): @pytest.mark.asyncio async def test_rotate_did_keypair(self, ledger: IndyVdrLedger): wallet = (await ledger.profile.session()).wallet - public_did = await wallet.create_public_did(DIDMethod.SOV, KeyType.ED25519) + public_did = await wallet.create_public_did(SOV, ED25519) async with ledger: with async_mock.patch.object( @@ -980,4 +980,5 @@ async def test_rotate_did_keypair(self, ledger: IndyVdrLedger): ] ), ): + ledger.profile.context.injector.bind_instance(DIDMethods, DIDMethods()) await ledger.rotate_public_did_keypair() diff --git a/aries_cloudagent/messaging/decorators/attach_decorator.py b/aries_cloudagent/messaging/decorators/attach_decorator.py index 309ebc6a68..66284378df 100644 --- a/aries_cloudagent/messaging/decorators/attach_decorator.py +++ b/aries_cloudagent/messaging/decorators/attach_decorator.py @@ -24,7 +24,7 @@ str_to_b64, unpad, ) -from ...wallet.key_type import KeyType +from ...wallet.key_type import ED25519 from ...did.did_key import DIDKey from ..models.base import BaseModel, BaseModelError, BaseModelSchema from ..valid import ( @@ -201,7 +201,7 @@ def did_key(verkey: str) -> str: if verkey.startswith("did:key:"): return verkey - return DIDKey.from_public_key_b58(verkey, KeyType.ED25519).did + return DIDKey.from_public_key_b58(verkey, ED25519).did def raw_key(verkey: str) -> str: @@ -440,13 +440,9 @@ async def verify(self, wallet: BaseWallet, signer_verkey: str = None) -> bool: verkey = bytes_to_b58(b64_to_bytes(protected["jwk"]["x"], urlsafe=True)) encoded_pk = DIDKey.from_did(protected["jwk"]["kid"]).public_key_b58 verkey_to_check.append(encoded_pk) - if not await wallet.verify_message( - sign_input, b_sig, verkey, KeyType.ED25519 - ): + if not await wallet.verify_message(sign_input, b_sig, verkey, ED25519): return False - if not await wallet.verify_message( - sign_input, b_sig, encoded_pk, KeyType.ED25519 - ): + if not await wallet.verify_message(sign_input, b_sig, encoded_pk, ED25519): return False if signer_verkey and signer_verkey not in verkey_to_check: return False diff --git a/aries_cloudagent/messaging/decorators/signature_decorator.py b/aries_cloudagent/messaging/decorators/signature_decorator.py index 71bf1c42ea..a8b67cce29 100644 --- a/aries_cloudagent/messaging/decorators/signature_decorator.py +++ b/aries_cloudagent/messaging/decorators/signature_decorator.py @@ -9,7 +9,7 @@ from ...protocols.didcomm_prefix import DIDCommPrefix from ...wallet.base import BaseWallet from ...wallet.util import b64_to_bytes, bytes_to_b64 -from ...wallet.key_type import KeyType +from ...wallet.key_type import ED25519 from ..models.base import BaseModel, BaseModelSchema from ..valid import Base64URL, BASE64URL, INDY_RAW_PUBLIC_KEY @@ -111,9 +111,7 @@ async def verify(self, wallet: BaseWallet) -> bool: return False msg_bin = b64_to_bytes(self.sig_data, urlsafe=True) sig_bin = b64_to_bytes(self.signature, urlsafe=True) - return await wallet.verify_message( - msg_bin, sig_bin, self.signer, KeyType.ED25519 - ) + return await wallet.verify_message(msg_bin, sig_bin, self.signer, ED25519) def __str__(self): """Get a string representation of this class.""" diff --git a/aries_cloudagent/messaging/decorators/tests/test_attach_decorator.py b/aries_cloudagent/messaging/decorators/tests/test_attach_decorator.py index 2687c7bf19..c0f1f26169 100644 --- a/aries_cloudagent/messaging/decorators/tests/test_attach_decorator.py +++ b/aries_cloudagent/messaging/decorators/tests/test_attach_decorator.py @@ -1,34 +1,27 @@ import json -import pytest import uuid - from copy import deepcopy from datetime import datetime, timezone from unittest import TestCase +import pytest + from ....indy.sdk.wallet_setup import IndyWalletConfig from ....messaging.models.base import BaseModelError +from ....wallet.did_method import SOV from ....wallet.indy import IndySdkWallet +from ....wallet.key_type import ED25519 from ....wallet.util import b64_to_bytes, bytes_to_b64 -from ....wallet.key_type import KeyType -from ....wallet.did_method import DIDMethod - from ..attach_decorator import ( AttachDecorator, - AttachDecoratorSchema, AttachDecoratorData, - AttachDecoratorDataSchema, AttachDecoratorData1JWS, - AttachDecoratorData1JWSSchema, AttachDecoratorDataJWS, - AttachDecoratorDataJWSSchema, AttachDecoratorDataJWSHeader, - AttachDecoratorDataJWSHeaderSchema, did_key, raw_key, ) - KID = "did:sov:LjgpST2rjsoxYegQDRm7EL#keys-4" INDY_CRED = { "schema_id": "LjgpST2rjsoxYegQDRm7EL:2:icon:1.0", @@ -433,9 +426,7 @@ def test_data_json_external_mutation(self): class TestAttachDecoratorSignature: @pytest.mark.asyncio async def test_did_raw_key(self, wallet, seed): - did_info = await wallet.create_local_did( - DIDMethod.SOV, KeyType.ED25519, seed[0] - ) + did_info = await wallet.create_local_did(SOV, ED25519, seed[0]) did_key0 = did_key(did_info.verkey) raw_key0 = raw_key(did_key0) assert raw_key0 != did_key0 @@ -457,8 +448,7 @@ async def test_indy_sign(self, wallet, seed): ) deco_indy_master = deepcopy(deco_indy) did_info = [ - await wallet.create_local_did(DIDMethod.SOV, KeyType.ED25519, seed[i]) - for i in [0, 1] + await wallet.create_local_did(SOV, ED25519, seed[i]) for i in [0, 1] ] assert deco_indy.data.signatures == 0 assert deco_indy.data.header_map() is None diff --git a/aries_cloudagent/messaging/decorators/tests/test_signature_decorator.py b/aries_cloudagent/messaging/decorators/tests/test_signature_decorator.py index c7d23a25e1..de863ca4b9 100644 --- a/aries_cloudagent/messaging/decorators/tests/test_signature_decorator.py +++ b/aries_cloudagent/messaging/decorators/tests/test_signature_decorator.py @@ -1,6 +1,6 @@ from asynctest import TestCase as AsyncTestCase -from ....wallet.key_type import KeyType +from ....wallet.key_type import ED25519 from ....core.in_memory import InMemoryProfile from ....protocols.trustping.v1_0.messages.ping import Ping from ....wallet.in_memory import InMemoryWallet @@ -43,7 +43,7 @@ async def test_create_decode_verify(self): profile = InMemoryProfile.test_profile() wallet = InMemoryWallet(profile) - key_info = await wallet.create_signing_key(KeyType.ED25519) + key_info = await wallet.create_signing_key(ED25519) deco = await SignatureDecorator.create( Ping(), key_info.verkey, wallet, timestamp=None diff --git a/aries_cloudagent/messaging/jsonld/credential.py b/aries_cloudagent/messaging/jsonld/credential.py index 23813276b0..5c693a0b63 100644 --- a/aries_cloudagent/messaging/jsonld/credential.py +++ b/aries_cloudagent/messaging/jsonld/credential.py @@ -5,7 +5,7 @@ from ...did.did_key import DIDKey from ...vc.ld_proofs import DocumentLoader from ...wallet.base import BaseWallet -from ...wallet.key_type import KeyType +from ...wallet.key_type import ED25519 from ...wallet.util import b64_to_bytes, b64_to_str, bytes_to_b64, str_to_b64 from .create_verify_data import create_verify_data @@ -18,7 +18,7 @@ def did_key(verkey: str) -> str: if verkey.startswith("did:key:"): return verkey - return DIDKey.from_public_key_b58(verkey, KeyType.ED25519).did + return DIDKey.from_public_key_b58(verkey, ED25519).did def b64encode(str): @@ -76,7 +76,7 @@ async def jws_verify(session, verify_data, signature, public_key): wallet = session.inject(BaseWallet) verified = await wallet.verify_message( - jws_to_verify, decoded_signature, public_key, KeyType.ED25519 + jws_to_verify, decoded_signature, public_key, ED25519 ) return verified diff --git a/aries_cloudagent/messaging/jsonld/tests/test_credential.py b/aries_cloudagent/messaging/jsonld/tests/test_credential.py index 297d5a3b0e..3046388533 100644 --- a/aries_cloudagent/messaging/jsonld/tests/test_credential.py +++ b/aries_cloudagent/messaging/jsonld/tests/test_credential.py @@ -13,7 +13,7 @@ from ....vc.ld_proofs import DocumentLoader from ....wallet.base import BaseWallet from ....wallet.in_memory import InMemoryWallet -from ....wallet.key_type import KeyType +from ....wallet.key_type import ED25519 from .. import credential as test_module from ..create_verify_data import DroppedAttributeError @@ -60,7 +60,7 @@ async def test_verify_jws_header(self): class TestOps(AsyncTestCase): async def setUp(self): self.wallet = InMemoryWallet(InMemoryProfile.test_profile()) - await self.wallet.create_signing_key(KeyType.ED25519, TEST_SEED) + await self.wallet.create_signing_key(ED25519, TEST_SEED) self.session = InMemoryProfile.test_session(bind={BaseWallet: self.wallet}) self.profile = self.session.profile diff --git a/aries_cloudagent/messaging/jsonld/tests/test_routes.py b/aries_cloudagent/messaging/jsonld/tests/test_routes.py index 129ac26515..ebddf2b9f3 100644 --- a/aries_cloudagent/messaging/jsonld/tests/test_routes.py +++ b/aries_cloudagent/messaging/jsonld/tests/test_routes.py @@ -14,9 +14,9 @@ from ....resolver.did_resolver import DIDResolver from ....vc.ld_proofs.document_loader import DocumentLoader from ....wallet.base import BaseWallet -from ....wallet.did_method import DIDMethod +from ....wallet.did_method import SOV from ....wallet.error import WalletError -from ....wallet.key_type import KeyType +from ....wallet.key_type import ED25519 from ..error import ( BadJWSHeaderError, DroppedAttributeError, @@ -275,7 +275,7 @@ async def setUp(self): DocumentLoader, custom_document_loader ) self.did_info = await (await self.context.session()).wallet.create_local_did( - DIDMethod.SOV, KeyType.ED25519 + SOV, ED25519 ) self.request_dict = { "context": self.context, diff --git a/aries_cloudagent/messaging/tests/test_agent_message.py b/aries_cloudagent/messaging/tests/test_agent_message.py index 4e1b87e28e..947328da63 100644 --- a/aries_cloudagent/messaging/tests/test_agent_message.py +++ b/aries_cloudagent/messaging/tests/test_agent_message.py @@ -4,7 +4,7 @@ from ...core.in_memory import InMemoryProfile from ...protocols.didcomm_prefix import DIDCommPrefix -from ...wallet.key_type import KeyType +from ...wallet.key_type import ED25519 from ..agent_message import AgentMessage, AgentMessageSchema from ..decorators.signature_decorator import SignatureDecorator @@ -72,7 +72,7 @@ class BadImplementationClass(AgentMessage): async def test_field_signature(self): session = InMemoryProfile.test_session() wallet = session.wallet - key_info = await wallet.create_signing_key(KeyType.ED25519) + key_info = await wallet.create_signing_key(ED25519) msg = SignedAgentMessage() msg.value = None diff --git a/aries_cloudagent/multitenant/tests/test_base.py b/aries_cloudagent/multitenant/tests/test_base.py index 6f7c7b7e78..8d3f849d27 100644 --- a/aries_cloudagent/multitenant/tests/test_base.py +++ b/aries_cloudagent/multitenant/tests/test_base.py @@ -18,9 +18,9 @@ from ...storage.error import StorageNotFoundError from ...storage.in_memory import InMemoryStorage from ...wallet.did_info import DIDInfo -from ...wallet.did_method import DIDMethod +from ...wallet.did_method import SOV from ...wallet.in_memory import InMemoryWallet -from ...wallet.key_type import KeyType +from ...wallet.key_type import ED25519 from ...wallet.models.wallet_record import WalletRecord from ..base import BaseMultitenantManager, MultitenantManagerError from ..error import WalletKeyMissingError @@ -244,8 +244,8 @@ async def test_create_wallet_adds_wallet_route(self): did="public-did", verkey="test_verkey", metadata={"meta": "data"}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_route_manager = async_mock.MagicMock() diff --git a/aries_cloudagent/protocols/connections/v1_0/manager.py b/aries_cloudagent/protocols/connections/v1_0/manager.py index d937b7ecb2..23c8057645 100644 --- a/aries_cloudagent/protocols/connections/v1_0/manager.py +++ b/aries_cloudagent/protocols/connections/v1_0/manager.py @@ -19,9 +19,9 @@ from ....wallet.base import BaseWallet from ....wallet.crypto import create_keypair, seed_to_did from ....wallet.did_info import DIDInfo -from ....wallet.did_method import DIDMethod +from ....wallet.did_method import SOV from ....wallet.error import WalletNotFoundError -from ....wallet.key_type import KeyType +from ....wallet.key_type import ED25519 from ....wallet.util import bytes_to_b58 from ...coordinate_mediation.v1_0.manager import MediationManager from ...discovery.v2_0.manager import V20DiscoveryMgr @@ -177,7 +177,7 @@ async def create_invitation( async with self.profile.session() as session: wallet = session.inject(BaseWallet) invitation_signing_key = await wallet.create_signing_key( - key_type=KeyType.ED25519 + key_type=ED25519 ) invitation_key = invitation_signing_key.verkey recipient_keys = [invitation_key] @@ -360,7 +360,7 @@ async def create_request( async with self.profile.session() as session: wallet = session.inject(BaseWallet) # Create new DID for connection - my_info = await wallet.create_local_did(DIDMethod.SOV, KeyType.ED25519) + my_info = await wallet.create_local_did(SOV, ED25519) connection.my_did = my_info.did # Idempotent; if routing has already been set up, no action taken @@ -467,9 +467,7 @@ async def receive_request( if connection.is_multiuse_invitation: async with self.profile.session() as session: wallet = session.inject(BaseWallet) - my_info = await wallet.create_local_did( - DIDMethod.SOV, KeyType.ED25519 - ) + my_info = await wallet.create_local_did(SOV, ED25519) new_connection = ConnRecord( invitation_key=connection_key, @@ -522,7 +520,7 @@ async def receive_request( else: # request from public did async with self.profile.session() as session: wallet = session.inject(BaseWallet) - my_info = await wallet.create_local_did(DIDMethod.SOV, KeyType.ED25519) + my_info = await wallet.create_local_did(SOV, ED25519) async with self.profile.session() as session: connection = await ConnRecord.retrieve_by_invitation_msg_id( @@ -613,7 +611,7 @@ async def create_response( else: async with self.profile.session() as session: wallet = session.inject(BaseWallet) - my_info = await wallet.create_local_did(DIDMethod.SOV, KeyType.ED25519) + my_info = await wallet.create_local_did(SOV, ED25519) connection.my_did = my_info.did # Idempotent; if routing has already been set up, no action taken @@ -830,9 +828,7 @@ async def create_static_connection( async with self.profile.session() as session: wallet = session.inject(BaseWallet) # seed and DID optional - my_info = await wallet.create_local_did( - DIDMethod.SOV, KeyType.ED25519, my_seed, my_did - ) + my_info = await wallet.create_local_did(SOV, ED25519, my_seed, my_did) # must provide their DID and verkey if the seed is not known if (not their_did or not their_verkey) and not their_seed: @@ -842,11 +838,9 @@ async def create_static_connection( if not their_did: their_did = seed_to_did(their_seed) if not their_verkey: - their_verkey_bin, _ = create_keypair(KeyType.ED25519, their_seed.encode()) + their_verkey_bin, _ = create_keypair(ED25519, their_seed.encode()) their_verkey = bytes_to_b58(their_verkey_bin) - their_info = DIDInfo( - their_did, their_verkey, {}, method=DIDMethod.SOV, key_type=KeyType.ED25519 - ) + their_info = DIDInfo(their_did, their_verkey, {}, method=SOV, key_type=ED25519) # Create connection record connection = ConnRecord( @@ -1106,7 +1100,7 @@ async def establish_inbound( my_info = await wallet.get_local_did(connection.my_did) else: # Create new DID for connection - my_info = await wallet.create_local_did(DIDMethod.SOV, KeyType.ED25519) + my_info = await wallet.create_local_did(SOV, ED25519) connection.my_did = my_info.did try: diff --git a/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_response.py b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_response.py index 98beb344fd..fd47e9c896 100644 --- a/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_response.py +++ b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_response.py @@ -2,7 +2,7 @@ from asynctest import TestCase as AsyncTestCase -from ......wallet.key_type import KeyType +from ......wallet.key_type import ED25519 from ......connections.models.diddoc import ( DIDDoc, PublicKey, @@ -108,7 +108,7 @@ async def test_make_model(self): ) session = InMemoryProfile.test_session() wallet = session.wallet - key_info = await wallet.create_signing_key(KeyType.ED25519) + key_info = await wallet.create_signing_key(ED25519) await connection_response.sign_field("connection", key_info.verkey, wallet) data = connection_response.serialize() model_instance = ConnectionResponse.deserialize(data) diff --git a/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py index 80efb456bf..be52b0aefb 100644 --- a/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py @@ -23,10 +23,10 @@ from .....storage.error import StorageNotFoundError from .....transport.inbound.receipt import MessageReceipt from .....wallet.base import DIDInfo -from .....wallet.did_method import DIDMethod +from .....wallet.did_method import SOV from .....wallet.error import WalletNotFoundError from .....wallet.in_memory import InMemoryWallet -from .....wallet.key_type import KeyType +from .....wallet.key_type import ED25519 from ....coordinate_mediation.v1_0.manager import MediationManager from ....coordinate_mediation.v1_0.route_manager import RouteManager from ....coordinate_mediation.v1_0.messages.mediate_request import MediationRequest @@ -120,8 +120,8 @@ async def test_create_invitation_public_and_multi_use_fails(self): self.test_did, self.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) with self.assertRaises(ConnectionManagerError): await self.manager.create_invitation(public=True, multi_use=True) @@ -166,8 +166,8 @@ async def test_create_invitation_public(self): self.test_did, self.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) connect_record, connect_invite = await self.manager.create_invitation( public=True, my_endpoint="testendpoint" @@ -231,8 +231,8 @@ async def test_create_invitation_multi_use(self): async def test_create_invitation_recipient_routing_endpoint(self): async with self.profile.session() as session: await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=self.test_seed, did=self.test_did, metadata=None, @@ -274,8 +274,8 @@ async def test_create_invitation_public_and_metadata_fails(self): self.test_did, self.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) with self.assertRaises(ConnectionManagerError): await self.manager.create_invitation( @@ -435,8 +435,8 @@ async def test_create_request_my_endpoint(self): async def test_create_request_my_did(self): async with self.profile.session() as session: await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=None, did=self.test_did, ) @@ -480,8 +480,8 @@ async def test_create_request_multitenant(self): self.test_did, self.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) await self.manager.create_request( ConnRecord( @@ -533,8 +533,8 @@ async def test_create_request_mediation_id(self): did=self.test_did, verkey=self.test_verkey, metadata={}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) create_local_did.return_value = did_info await self.manager.create_request( @@ -542,7 +542,7 @@ async def test_create_request_mediation_id(self): mediation_id=mediation_record.mediation_id, my_endpoint=self.test_endpoint, ) - create_local_did.assert_called_once_with(DIDMethod.SOV, KeyType.ED25519) + create_local_did.assert_called_once_with(SOV, ED25519) create_did_document.assert_called_once_with( self.manager, did_info, @@ -585,15 +585,15 @@ async def test_create_request_default_mediator(self): did=self.test_did, verkey=self.test_verkey, metadata={}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) create_local_did.return_value = did_info await self.manager.create_request( record, my_endpoint=self.test_endpoint, ) - create_local_did.assert_called_once_with(DIDMethod.SOV, KeyType.ED25519) + create_local_did.assert_called_once_with(SOV, ED25519) create_did_document.assert_called_once_with( self.manager, did_info, @@ -614,8 +614,8 @@ async def test_receive_request_public_did_oob_invite(self): recipient_did=self.test_did, recipient_did_public=True ) await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=None, did=self.test_did, ) @@ -654,8 +654,8 @@ async def test_receive_request_public_did_conn_invite(self): recipient_did=self.test_did, recipient_did_public=True ) await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=None, did=self.test_did, ) @@ -689,8 +689,8 @@ async def test_receive_request_public_did_no_did_doc(self): recipient_did=self.test_did, recipient_did_public=True ) await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=None, did=self.test_did, ) @@ -720,8 +720,8 @@ async def test_receive_request_public_did_wrong_did(self): recipient_did=self.test_did, recipient_did_public=True ) await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=None, did=self.test_did, ) @@ -749,8 +749,8 @@ async def test_receive_request_public_did_no_public_invites(self): receipt = MessageReceipt(recipient_did=self.test_did, recipient_did_public=True) async with self.profile.session() as session: await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=None, did=self.test_did, ) @@ -780,8 +780,8 @@ async def test_receive_request_public_did_no_auto_accept(self): recipient_did=self.test_did, recipient_did_public=True ) await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=None, did=self.test_did, ) @@ -867,8 +867,8 @@ async def test_create_response_multitenant(self): self.test_did, self.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) await self.manager.create_response( ConnRecord( @@ -941,8 +941,8 @@ async def test_create_response_mediation(self): did=self.test_did, verkey=self.test_verkey, metadata={}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) create_local_did.return_value = did_info await self.manager.create_response( @@ -950,7 +950,7 @@ async def test_create_response_mediation(self): mediation_id=mediation_record.mediation_id, my_endpoint=self.test_endpoint, ) - create_local_did.assert_called_once_with(DIDMethod.SOV, KeyType.ED25519) + create_local_did.assert_called_once_with(SOV, ED25519) create_did_document.assert_called_once_with( self.manager, did_info, @@ -1266,8 +1266,8 @@ async def test_create_static_connection_multitenant(self): self.test_did, self.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) await self.manager.create_static_connection( @@ -1299,8 +1299,8 @@ async def test_create_static_connection_multitenant_auto_disclose_features(self) self.test_did, self.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) await self.manager.create_static_connection( my_did=self.test_did, @@ -1331,8 +1331,8 @@ async def test_create_static_connection_multitenant_mediator(self): self.test_did, self.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) # With default mediator @@ -1359,8 +1359,8 @@ async def test_create_static_connection_multitenant_mediator(self): self.test_target_did, self.test_target_verkey, {}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) create_did_document.assert_has_calls( [ @@ -1537,8 +1537,8 @@ async def test_resolve_inbound_connection(self): self.test_did, self.test_verkey, {"posted": True}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_mgr_find_conn.return_value = mock_conn @@ -1589,8 +1589,8 @@ async def test_create_did_document(self): self.test_did, self.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_conn = async_mock.MagicMock( @@ -1622,8 +1622,8 @@ async def test_create_did_document_not_active(self): self.test_did, self.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_conn = async_mock.MagicMock( @@ -1650,8 +1650,8 @@ async def test_create_did_document_no_services(self): self.test_did, self.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_conn = async_mock.MagicMock( @@ -1685,8 +1685,8 @@ async def test_create_did_document_no_service_endpoint(self): self.test_did, self.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_conn = async_mock.MagicMock( @@ -1723,8 +1723,8 @@ async def test_create_did_document_no_service_recip_keys(self): self.test_did, self.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_conn = async_mock.MagicMock( @@ -1769,8 +1769,8 @@ async def test_create_did_document_mediation(self): self.test_did, self.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mediation_record = MediationRecord( role=MediationRecord.ROLE_CLIENT, @@ -1795,8 +1795,8 @@ async def test_create_did_document_multiple_mediators(self): self.test_did, self.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mediation_record1 = MediationRecord( role=MediationRecord.ROLE_CLIENT, @@ -1828,8 +1828,8 @@ async def test_create_did_document_mediation_svc_endpoints_overwritten(self): self.test_did, self.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mediation_record = MediationRecord( role=MediationRecord.ROLE_CLIENT, @@ -1863,8 +1863,8 @@ async def test_did_key_storage(self): async def test_get_connection_targets_conn_invitation_no_did(self): async with self.profile.session() as session: local_did = await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=self.test_seed, did=self.test_did, metadata=None, @@ -1922,8 +1922,8 @@ async def test_get_connection_targets_conn_invitation_no_did(self): async def test_get_connection_targets_retrieve_connection(self): async with self.profile.session() as session: local_did = await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=self.test_seed, did=self.test_did, metadata=None, @@ -1975,8 +1975,8 @@ async def test_get_conn_targets_conn_invitation_no_cache(self): async with self.profile.session() as session: self.context.injector.clear_binding(BaseCache) local_did = await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=self.test_seed, did=self.test_did, metadata=None, @@ -2025,8 +2025,8 @@ async def test_fetch_connection_targets_conn_invitation_did_no_resolver(self): async with self.profile.session() as session: self.context.injector.bind_instance(DIDResolver, DIDResolver([])) await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=self.test_seed, did=self.test_did, metadata=None, @@ -2071,8 +2071,8 @@ async def test_fetch_connection_targets_conn_invitation_did_resolver(self): self.context.injector.bind_instance(DIDResolver, self.resolver) local_did = await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=self.test_seed, did=self.test_did, metadata=None, @@ -2139,8 +2139,8 @@ async def test_fetch_connection_targets_conn_invitation_btcr_resolver(self): self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) self.context.injector.bind_instance(DIDResolver, self.resolver) local_did = await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=self.test_seed, did=did_doc.id, metadata=None, @@ -2204,8 +2204,8 @@ async def test_fetch_connection_targets_conn_invitation_btcr_without_services(se self.context.injector.bind_instance(DIDResolver, self.resolver) local_did = await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=self.test_seed, did=did_doc.id, metadata=None, @@ -2244,8 +2244,8 @@ async def test_fetch_connection_targets_conn_invitation_no_didcomm_services(self self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) self.context.injector.bind_instance(DIDResolver, self.resolver) await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=self.test_seed, did=did_doc.id, metadata=None, @@ -2290,8 +2290,8 @@ async def test_fetch_connection_targets_conn_invitation_unsupported_key_type(sel self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) self.context.injector.bind_instance(DIDResolver, self.resolver) local_did = await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=self.test_seed, did=did_doc.id, metadata=None, @@ -2319,8 +2319,8 @@ async def test_fetch_connection_targets_oob_invitation_svc_did_no_resolver(self) async with self.profile.session() as session: self.context.injector.bind_instance(DIDResolver, DIDResolver([])) await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=self.test_seed, did=self.test_did, metadata=None, @@ -2360,8 +2360,8 @@ async def test_fetch_connection_targets_oob_invitation_svc_did_resolver(self): self.context.injector.bind_instance(DIDResolver, self.resolver) local_did = await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=self.test_seed, did=self.test_did, metadata=None, @@ -2405,8 +2405,8 @@ async def test_fetch_connection_targets_oob_invitation_svc_block_resolver(self): self.context.injector.bind_instance(DIDResolver, self.resolver) local_did = await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=self.test_seed, did=self.test_did, metadata=None, @@ -2420,7 +2420,7 @@ async def test_fetch_connection_targets_oob_invitation_svc_block_resolver(self): service_endpoint=self.test_endpoint, recipient_keys=[ DIDKey.from_public_key_b58( - self.test_target_verkey, KeyType.ED25519 + self.test_target_verkey, ED25519 ).did ], routing_keys=[], @@ -2451,8 +2451,8 @@ async def test_fetch_connection_targets_oob_invitation_svc_block_resolver(self): async def test_fetch_connection_targets_conn_initiator_completed_no_their_did(self): async with self.profile.session() as session: await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=self.test_seed, did=self.test_did, metadata=None, @@ -2468,8 +2468,8 @@ async def test_fetch_connection_targets_conn_initiator_completed_no_their_did(se async def test_fetch_connection_targets_conn_completed_their_did(self): async with self.profile.session() as session: local_did = await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=self.test_seed, did=self.test_did, metadata=None, @@ -2499,8 +2499,8 @@ async def test_fetch_connection_targets_conn_completed_their_did(self): async def test_fetch_connection_targets_conn_no_invi_with_their_did(self): async with self.profile.session() as session: local_did = await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=self.test_seed, did=self.test_did, metadata=None, @@ -2554,8 +2554,8 @@ async def test_diddoc_connection_targets_diddoc_underspecified(self): async def test_establish_inbound(self): async with self.profile.session() as session: await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=self.test_seed, did=self.test_did, metadata=None, @@ -2584,8 +2584,8 @@ async def test_establish_inbound(self): async def test_establish_inbound_conn_rec_no_my_did(self): async with self.profile.session() as session: await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=self.test_seed, did=self.test_did, metadata=None, @@ -2613,8 +2613,8 @@ async def test_establish_inbound_conn_rec_no_my_did(self): async def test_establish_inbound_no_conn_record(self): async with self.profile.session() as session: await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=self.test_seed, did=self.test_did, metadata=None, @@ -2642,8 +2642,8 @@ async def test_establish_inbound_no_conn_record(self): async def test_establish_inbound_router_not_ready(self): async with self.profile.session() as session: await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=self.test_seed, did=self.test_did, metadata=None, diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/manager.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/manager.py index f525dd0088..8dd6a87442 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/manager.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/manager.py @@ -11,8 +11,8 @@ from ....storage.record import StorageRecord from ....wallet.base import BaseWallet from ....wallet.did_info import DIDInfo -from ....wallet.did_method import DIDMethod -from ....wallet.key_type import KeyType +from ....wallet.did_method import SOV +from ....wallet.key_type import ED25519 from ...routing.v1_0.manager import RoutingManager from ...routing.v1_0.models.route_record import RouteRecord from ...routing.v1_0.models.route_update import RouteUpdate @@ -111,8 +111,8 @@ async def _create_routing_did(self, session: ProfileSession) -> DIDInfo: wallet = session.inject(BaseWallet) storage = session.inject(BaseStorage) info = await wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, metadata={"type": "routing_did"}, ) record = StorageRecord( diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/normalization.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/normalization.py index 1d8610e60c..d699565367 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/normalization.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/normalization.py @@ -1,6 +1,6 @@ """Normalization methods used while transitioning to DID:Key method.""" from ....did.did_key import DIDKey -from ....wallet.key_type import KeyType +from ....wallet.key_type import ED25519 def normalize_from_did_key(key: str): @@ -16,4 +16,4 @@ def normalize_from_public_key(key: str): if key.startswith("did:key:"): return key - return DIDKey.from_public_key_b58(key, KeyType.ED25519).did + return DIDKey.from_public_key_b58(key, ED25519).did diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/route_manager.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/route_manager.py index 07da03fd51..04790475c3 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/route_manager.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/route_manager.py @@ -14,8 +14,8 @@ from ....storage.error import StorageNotFoundError from ....wallet.base import BaseWallet from ....wallet.did_info import DIDInfo -from ....wallet.did_method import DIDMethod -from ....wallet.key_type import KeyType +from ....wallet.did_method import SOV +from ....wallet.key_type import ED25519 from ...routing.v1_0.models.route_record import RouteRecord from .manager import MediationManager from .messages.keylist_update import KeylistUpdate @@ -40,7 +40,7 @@ async def get_or_create_my_did( async with profile.session() as session: wallet = session.inject(BaseWallet) # Create new DID for connection - my_info = await wallet.create_local_did(DIDMethod.SOV, KeyType.ED25519) + my_info = await wallet.create_local_did(SOV, ED25519) conn_record.my_did = my_info.did await conn_record.save(session, reason="Connection my did created") else: diff --git a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_request_handler.py b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_request_handler.py index ff76d6a9c6..8f8c4381b1 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_request_handler.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_request_handler.py @@ -9,8 +9,8 @@ Service, ) from ......core.in_memory import InMemoryProfile -from ......wallet.key_type import KeyType -from ......wallet.did_method import DIDMethod +from ......wallet.did_method import SOV +from ......wallet.key_type import ED25519 from ......messaging.decorators.attach_decorator import AttachDecorator from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -87,9 +87,7 @@ async def setUp(self): await self.conn_rec.save(self.session) wallet = self.session.wallet - self.did_info = await wallet.create_local_did( - method=DIDMethod.SOV, key_type=KeyType.ED25519 - ) + self.did_info = await wallet.create_local_did(method=SOV, key_type=ED25519) self.did_doc_attach = AttachDecorator.data_base64(self.did_doc().serialize()) await self.did_doc_attach.data.sign(self.did_info.verkey, wallet) diff --git a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_response_handler.py b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_response_handler.py index a161b5f325..ff9750ca14 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_response_handler.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_response_handler.py @@ -13,8 +13,8 @@ from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder from ......transport.inbound.receipt import MessageReceipt -from ......wallet.key_type import KeyType -from ......wallet.did_method import DIDMethod +from ......wallet.did_method import SOV +from ......wallet.key_type import ED25519 from .....problem_report.v1_0.message import ProblemReport from .....trustping.v1_0.messages.ping import Ping @@ -65,8 +65,8 @@ async def setUp(self): wallet = (await self.ctx.session()).wallet self.did_info = await wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) self.did_doc_attach = AttachDecorator.data_base64(self.did_doc().serialize()) diff --git a/aries_cloudagent/protocols/didexchange/v1_0/manager.py b/aries_cloudagent/protocols/didexchange/v1_0/manager.py index 587e6b56b5..2509766e9d 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/manager.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/manager.py @@ -23,10 +23,10 @@ from ....storage.error import StorageNotFoundError from ....transport.inbound.receipt import MessageReceipt from ....wallet.base import BaseWallet -from ....wallet.did_method import DIDMethod +from ....wallet.did_method import SOV from ....wallet.did_posture import DIDPosture from ....wallet.error import WalletError -from ....wallet.key_type import KeyType +from ....wallet.key_type import ED25519 from ...coordinate_mediation.v1_0.manager import MediationManager from ...discovery.v2_0.manager import V20DiscoveryMgr from ...out_of_band.v1_0.messages.invitation import ( @@ -284,8 +284,8 @@ async def create_request( async with self.profile.session() as session: wallet = session.inject(BaseWallet) my_info = await wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) conn_rec.my_did = my_info.did @@ -417,8 +417,8 @@ async def receive_request( async with self.profile.session() as session: wallet = session.inject(BaseWallet) my_info = await wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) new_conn_rec = ConnRecord( @@ -486,8 +486,8 @@ async def receive_request( async with self.profile.session() as session: wallet = session.inject(BaseWallet) my_info = await wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) auto_accept = bool( @@ -580,8 +580,8 @@ async def create_response( async with self.profile.session() as session: wallet = session.inject(BaseWallet) my_info = await wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) conn_rec.my_did = my_info.did diff --git a/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_request.py b/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_request.py index a7ad4f405f..37569858e6 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_request.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_request.py @@ -2,21 +2,13 @@ from asynctest import TestCase as AsyncTestCase -from ......connections.models.diddoc import ( - DIDDoc, - PublicKey, - PublicKeyType, - Service, -) -from ......wallet.did_method import DIDMethod -from ......wallet.key_type import KeyType +from ......connections.models.diddoc import DIDDoc, PublicKey, PublicKeyType, Service from ......core.in_memory import InMemoryProfile from ......messaging.decorators.attach_decorator import AttachDecorator - +from ......wallet.did_method import SOV +from ......wallet.key_type import ED25519 from .....didcomm_prefix import DIDCommPrefix - from ...message_types import DIDX_REQUEST - from ..request import DIDXRequest @@ -59,8 +51,8 @@ class TestDIDXRequest(AsyncTestCase, TestConfig): async def setUp(self): self.wallet = InMemoryProfile.test_session().wallet self.did_info = await self.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) did_doc_attach = AttachDecorator.data_base64(self.make_did_doc().serialize()) @@ -116,8 +108,8 @@ class TestDIDXRequestSchema(AsyncTestCase, TestConfig): async def setUp(self): self.wallet = InMemoryProfile.test_session().wallet self.did_info = await self.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) did_doc_attach = AttachDecorator.data_base64(self.make_did_doc().serialize()) diff --git a/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_response.py b/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_response.py index 9cf32b8359..59657ef2dc 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_response.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_response.py @@ -2,21 +2,13 @@ from asynctest import TestCase as AsyncTestCase -from ......connections.models.diddoc import ( - DIDDoc, - PublicKey, - PublicKeyType, - Service, -) -from ......wallet.did_method import DIDMethod -from ......wallet.key_type import KeyType +from ......connections.models.diddoc import DIDDoc, PublicKey, PublicKeyType, Service from ......core.in_memory import InMemoryProfile from ......messaging.decorators.attach_decorator import AttachDecorator - +from ......wallet.did_method import SOV +from ......wallet.key_type import ED25519 from .....didcomm_prefix import DIDCommPrefix - from ...message_types import DIDX_RESPONSE - from ..response import DIDXResponse @@ -58,8 +50,8 @@ class TestDIDXResponse(AsyncTestCase, TestConfig): async def setUp(self): self.wallet = InMemoryProfile.test_session().wallet self.did_info = await self.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) did_doc_attach = AttachDecorator.data_base64(self.make_did_doc().serialize()) @@ -112,8 +104,8 @@ class TestDIDXResponseSchema(AsyncTestCase, TestConfig): async def setUp(self): self.wallet = InMemoryProfile.test_session().wallet self.did_info = await self.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) did_doc_attach = AttachDecorator.data_base64(self.make_did_doc().serialize()) diff --git a/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py index 131d87670e..18f87d6b30 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py @@ -1,23 +1,21 @@ import json -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from asynctest import TestCase as AsyncTestCase +from asynctest import mock as async_mock from pydid import DIDDocument from .....cache.base import BaseCache from .....cache.in_memory import InMemoryCache +from .....connections.base_manager import BaseConnectionManagerError from .....connections.models.conn_record import ConnRecord from .....connections.models.connection_target import ConnectionTarget -from .....connections.models.diddoc import ( - DIDDoc, - PublicKey, - PublicKeyType, - Service, -) -from .....core.oob_processor import OobMessageProcessor +from .....connections.models.diddoc import DIDDoc, PublicKey, PublicKeyType, Service from .....core.in_memory import InMemoryProfile +from .....core.oob_processor import OobMessageProcessor +from .....did.did_key import DIDKey from .....ledger.base import BaseLedger -from .....messaging.responder import BaseResponder, MockResponder from .....messaging.decorators.attach_decorator import AttachDecorator +from .....messaging.responder import BaseResponder, MockResponder from .....multitenant.base import BaseMultitenantManager from .....multitenant.manager import MultitenantManager from .....resolver.base import ResolverError @@ -26,23 +24,18 @@ from .....storage.error import StorageNotFoundError from .....transport.inbound.receipt import MessageReceipt from .....wallet.did_info import DIDInfo +from .....wallet.did_method import SOV from .....wallet.error import WalletError from .....wallet.in_memory import InMemoryWallet -from .....wallet.did_method import DIDMethod -from .....wallet.key_type import KeyType -from .....did.did_key import DIDKey - -from .....connections.base_manager import BaseConnectionManagerError - +from .....wallet.key_type import ED25519 from ....coordinate_mediation.v1_0.manager import MediationManager -from ....coordinate_mediation.v1_0.route_manager import RouteManager from ....coordinate_mediation.v1_0.models.mediation_record import MediationRecord -from ....discovery.v2_0.manager import V20DiscoveryMgr +from ....coordinate_mediation.v1_0.route_manager import RouteManager from ....didcomm_prefix import DIDCommPrefix +from ....discovery.v2_0.manager import V20DiscoveryMgr from ....out_of_band.v1_0.manager import OutOfBandManager from ....out_of_band.v1_0.messages.invitation import HSProto, InvitationMessage from ....out_of_band.v1_0.messages.service import Service as OOBService - from .. import manager as test_module from ..manager import DIDXManager, DIDXManagerError @@ -114,8 +107,8 @@ async def setUp(self): self.context = self.profile.context async with self.profile.session() as session: self.did_info = await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) self.ledger = async_mock.create_autospec(BaseLedger) @@ -142,7 +135,7 @@ async def setUp(self): self.oob_manager = OutOfBandManager(self.profile) self.test_mediator_routing_keys = [ DIDKey.from_public_key_b58( - "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRR", KeyType.ED25519 + "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRR", ED25519 ).did ] self.test_mediator_conn_id = "mediator-conn-id" @@ -202,8 +195,8 @@ async def test_receive_invitation_oob_public_did(self): self.profile.context.update_settings({"public_invites": True}) public_did_info = None await session.wallet.create_public_did( - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) public_did_info = await session.wallet.get_public_did() with async_mock.patch.object( @@ -303,8 +296,8 @@ async def test_create_request_implicit(self): async def test_create_request_implicit_use_public_did(self): async with self.profile.session() as session: info_public = await session.wallet.create_public_did( - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) conn_rec = await self.manager.create_request_implicit( their_public_did=TestConfig.test_target_did, @@ -374,8 +367,8 @@ async def test_create_request_multitenant(self): TestConfig.test_did, TestConfig.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_attach_deco.data_base64 = async_mock.MagicMock( return_value=async_mock.MagicMock( @@ -502,8 +495,8 @@ async def test_receive_request_explicit_public_did(self): await mediation_record.save(session) await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=None, did=TestConfig.test_did, ) @@ -601,8 +594,8 @@ async def test_receive_request_invi_not_found(self): ) await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=None, did=TestConfig.test_did, ) @@ -633,8 +626,8 @@ async def test_receive_request_public_did_no_did_doc_attachment(self): ) await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=None, did=TestConfig.test_did, ) @@ -693,8 +686,8 @@ async def test_receive_request_public_did_x_not_public(self): ) await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=None, did=TestConfig.test_did, ) @@ -735,8 +728,8 @@ async def test_receive_request_public_did_x_wrong_did(self): ) await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=None, did=TestConfig.test_did, ) @@ -802,8 +795,8 @@ async def test_receive_request_public_did_x_did_doc_attach_bad_sig(self): ) await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=None, did=TestConfig.test_did, ) @@ -863,8 +856,8 @@ async def test_receive_request_public_did_no_public_invites(self): ) await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=None, did=TestConfig.test_did, ) @@ -910,8 +903,8 @@ async def test_receive_request_public_did_no_auto_accept(self): ) await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=None, did=TestConfig.test_did, ) @@ -1003,8 +996,8 @@ async def test_receive_request_peer_did(self): mock_conn_rec_state_request = ConnRecord.State.REQUEST await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=None, did=TestConfig.test_did, ) @@ -1077,8 +1070,8 @@ async def test_receive_request_peer_did_not_found_x(self): ) await session.wallet.create_local_did( - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, seed=None, did=TestConfig.test_did, ) @@ -1253,8 +1246,8 @@ async def test_create_response_multitenant(self): TestConfig.test_did, TestConfig.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_create_did_doc.return_value = async_mock.MagicMock( serialize=async_mock.MagicMock() @@ -1670,8 +1663,8 @@ async def test_create_did_document(self): TestConfig.test_did, TestConfig.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_conn = async_mock.MagicMock( @@ -1704,8 +1697,8 @@ async def test_create_did_document_not_completed(self): TestConfig.test_did, TestConfig.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_conn = async_mock.MagicMock( @@ -1732,8 +1725,8 @@ async def test_create_did_document_no_services(self): TestConfig.test_did, TestConfig.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_conn = async_mock.MagicMock( @@ -1767,8 +1760,8 @@ async def test_create_did_document_no_service_endpoint(self): TestConfig.test_did, TestConfig.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_conn = async_mock.MagicMock( @@ -1805,8 +1798,8 @@ async def test_create_did_document_no_service_recip_keys(self): TestConfig.test_did, TestConfig.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_conn = async_mock.MagicMock( @@ -1851,8 +1844,8 @@ async def test_did_key_storage(self): TestConfig.test_did, TestConfig.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) did_doc = self.make_did_doc( @@ -1897,8 +1890,8 @@ async def test_resolve_did_document_error(self): public_did_info = None async with self.profile.session() as session: await session.wallet.create_public_did( - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) public_did_info = await session.wallet.get_public_did() with async_mock.patch.object( diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py index f765843a03..1ce20b7ca5 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py @@ -2,31 +2,22 @@ import json import uuid -from aiohttp import web -from asynctest import mock as async_mock from asynctest import TestCase as AsyncTestCase +from asynctest import mock as async_mock from .....admin.request_context import AdminRequestContext from .....cache.base import BaseCache from .....cache.in_memory import InMemoryCache from .....connections.models.conn_record import ConnRecord -from .....core.in_memory import InMemoryProfile -from .....core.profile import Profile from .....ledger.base import BaseLedger from .....storage.error import StorageNotFoundError from .....wallet.base import BaseWallet -from .....wallet.did_info import DIDInfo -from .....wallet.did_method import DIDMethod -from .....wallet.key_type import KeyType - +from .....wallet.did_method import SOV +from .....wallet.key_type import ED25519 from ..manager import TransactionManager, TransactionManagerError -from ..messages.messages_attach import MessagesAttach -from ..messages.transaction_acknowledgement import TransactionAcknowledgement -from ..messages.transaction_request import TransactionRequest from ..models.transaction_record import TransactionRecord from ..transaction_jobs import TransactionJob - TEST_DID = "LjgpST2rjsoxYegQDRm7EL" SCHEMA_NAME = "bc-reg" SCHEMA_TXN = 12 @@ -125,8 +116,8 @@ async def setUp(self): async with self.profile.session() as session: self.wallet: BaseWallet = session.inject_or(BaseWallet) await self.wallet.create_local_did( - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, did="DJGEjaMunDtFtBVrn1qJMT", metadata={"meta": "data"}, ) diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py index d91b1ff8b8..611d1245ce 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py @@ -1,20 +1,18 @@ import asyncio import json -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from asynctest import TestCase as AsyncTestCase +from asynctest import mock as async_mock -from .....admin.request_context import AdminRequestContext from .....connections.models.conn_record import ConnRecord from .....core.in_memory import InMemoryProfile from .....ledger.base import BaseLedger from .....wallet.base import BaseWallet from .....wallet.did_info import DIDInfo -from .....wallet.did_method import DIDMethod -from .....wallet.key_type import KeyType - -from ..models.transaction_record import TransactionRecord +from .....wallet.did_method import SOV +from .....wallet.key_type import ED25519 from .. import routes as test_module - +from ..models.transaction_record import TransactionRecord TEST_DID = "LjgpST2rjsoxYegQDRm7EL" SCHEMA_NAME = "bc-reg" @@ -436,8 +434,8 @@ async def test_endorse_transaction_response(self): "did", "verkey", {"meta": "data"}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) ) ), @@ -515,8 +513,8 @@ async def test_endorse_transaction_response_not_found_x(self): "did", "verkey", {"meta": "data"}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) ) ), @@ -544,8 +542,8 @@ async def test_endorse_transaction_response_base_model_x(self): "did", "verkey", {"meta": "data"}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) ) ), @@ -579,8 +577,8 @@ async def test_endorse_transaction_response_no_jobs_x(self): "did", "verkey", {"meta": "data"}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) ) ), @@ -616,8 +614,8 @@ async def skip_test_endorse_transaction_response_no_ledger_x(self): "did", "verkey", {"meta": "data"}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) ) ), @@ -671,8 +669,8 @@ async def test_endorse_transaction_response_wrong_my_job_x(self): "did", "verkey", {"meta": "data"}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) ) ), @@ -714,8 +712,8 @@ async def skip_test_endorse_transaction_response_ledger_x(self): "did", "verkey", {"meta": "data"}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) ) ), @@ -772,8 +770,8 @@ async def test_endorse_transaction_response_txn_mgr_x(self): "did", "verkey", {"meta": "data"}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) ) ), @@ -824,8 +822,8 @@ async def test_refuse_transaction_response(self): "did", "verkey", {"meta": "data"}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) ) ), @@ -882,8 +880,8 @@ async def test_refuse_transaction_response_not_found_x(self): "did", "verkey", {"meta": "data"}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) ) ), @@ -912,8 +910,8 @@ async def test_refuse_transaction_response_conn_base_model_x(self): "did", "verkey", {"meta": "data"}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) ) ), @@ -947,8 +945,8 @@ async def test_refuse_transaction_response_no_jobs_x(self): "did", "verkey", {"meta": "data"}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) ) ), @@ -984,8 +982,8 @@ async def test_refuse_transaction_response_wrong_my_job_x(self): "did", "verkey", {"meta": "data"}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) ) ), @@ -1027,8 +1025,8 @@ async def test_refuse_transaction_response_txn_mgr_x(self): "did", "verkey", {"meta": "data"}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) ) ), diff --git a/aries_cloudagent/protocols/introduction/v0_1/tests/test_service.py b/aries_cloudagent/protocols/introduction/v0_1/tests/test_service.py index a2bff3f785..ea758821a8 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/tests/test_service.py +++ b/aries_cloudagent/protocols/introduction/v0_1/tests/test_service.py @@ -5,7 +5,7 @@ from .....messaging.request_context import RequestContext from .....messaging.responder import MockResponder from .....did.did_key import DIDKey -from .....wallet.key_type import KeyType +from .....wallet.key_type import ED25519 from ....didcomm_prefix import DIDCommPrefix from ....out_of_band.v1_0.message_types import INVITATION as OOB_INVITATION @@ -36,12 +36,10 @@ def setUp(self): _type="did-communication", did=TEST_DID, recipient_keys=[ - DIDKey.from_public_key_b58(TEST_VERKEY, KeyType.ED25519).did + DIDKey.from_public_key_b58(TEST_VERKEY, ED25519).did ], routing_keys=[ - DIDKey.from_public_key_b58( - TEST_ROUTE_VERKEY, KeyType.ED25519 - ).did + DIDKey.from_public_key_b58(TEST_ROUTE_VERKEY, ED25519).did ], service_endpoint=TEST_ENDPOINT, ) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/handler.py index 0efaf0c767..fc850070b4 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/handler.py @@ -1,5 +1,6 @@ """V2.0 issue-credential linked data proof credential format handler.""" + from ......vc.ld_proofs.error import LinkedDataProofException from ......vc.ld_proofs.check import get_properties_without_context import logging @@ -35,7 +36,7 @@ from ......vc.ld_proofs.constants import SECURITY_CONTEXT_BBS_URL from ......wallet.base import BaseWallet, DIDInfo from ......wallet.error import WalletNotFoundError -from ......wallet.key_type import KeyType +from ......wallet.key_type import BLS12381G2, ED25519 from ...message_types import ( ATTACHMENT_FORMAT, @@ -64,20 +65,20 @@ AuthenticationProofPurpose.term, } SUPPORTED_ISSUANCE_SUITES = {Ed25519Signature2018} -SIGNATURE_SUITE_KEY_TYPE_MAPPING = {Ed25519Signature2018: KeyType.ED25519} +SIGNATURE_SUITE_KEY_TYPE_MAPPING = {Ed25519Signature2018: ED25519} # We only want to add bbs suites to supported if the module is installed if BbsBlsSignature2020.BBS_SUPPORTED: SUPPORTED_ISSUANCE_SUITES.add(BbsBlsSignature2020) - SIGNATURE_SUITE_KEY_TYPE_MAPPING[BbsBlsSignature2020] = KeyType.BLS12381G2 + SIGNATURE_SUITE_KEY_TYPE_MAPPING[BbsBlsSignature2020] = BLS12381G2 PROOF_TYPE_SIGNATURE_SUITE_MAPPING = { - suite.signature_type: suite - for suite, key_type in SIGNATURE_SUITE_KEY_TYPE_MAPPING.items() + suite.signature_type: suite for suite in SIGNATURE_SUITE_KEY_TYPE_MAPPING } + KEY_TYPE_SIGNATURE_SUITE_MAPPING = { key_type: suite for suite, key_type in SIGNATURE_SUITE_KEY_TYPE_MAPPING.items() } diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py index a2f7cbeccb..ea4565a6b6 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py @@ -26,9 +26,9 @@ ) from .......vc.ld_proofs.constants import SECURITY_CONTEXT_BBS_URL from .......vc.tests.document_loader import custom_document_loader -from .......wallet.key_type import KeyType +from .......wallet.key_type import BLS12381G2, ED25519 from .......wallet.error import WalletNotFoundError -from .......wallet.did_method import DIDMethod +from .......wallet.did_method import SOV from .......wallet.base import BaseWallet from ....models.detail.ld_proof import V20CredExRecordLDProof @@ -48,7 +48,7 @@ CRED_20_ISSUE, ) -from ...handler import LOGGER, V20CredFormatError +from ...handler import V20CredFormatError from ..handler import LDProofCredFormatHandler from ..handler import LOGGER as LD_PROOF_LOGGER @@ -217,8 +217,8 @@ async def test_assert_can_issue_with_id_and_proof_type(self): did=TEST_DID_SOV, verkey="verkey", metadata={}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_did_info.return_value = did_info await self.handler._assert_can_issue_with_id_and_proof_type( @@ -229,8 +229,8 @@ async def test_assert_can_issue_with_id_and_proof_type(self): did=TEST_DID_SOV, verkey="verkey", metadata={}, - method=DIDMethod.SOV, - key_type=KeyType.BLS12381G2, + method=SOV, + key_type=BLS12381G2, ) mock_did_info.return_value = invalid_did_info with self.assertRaises(V20CredFormatError) as context: @@ -281,7 +281,7 @@ async def test_get_suite_for_detail(self): assert type(suite) == Ed25519Signature2018 assert suite.verification_method == DIDKey.from_did(TEST_DID_KEY).key_id assert suite.proof == {"created": LD_PROOF_VC_DETAIL["options"]["created"]} - assert suite.key_pair.key_type == KeyType.ED25519 + assert suite.key_pair.key_type == ED25519 assert suite.key_pair.public_key_base58 == mock_did_info.return_value.verkey mock_can_issue.assert_called_once_with( @@ -303,7 +303,7 @@ async def test_get_suite(self): assert type(suite) == BbsBlsSignature2020 assert suite.verification_method == "verification_method" assert suite.proof == proof - assert suite.key_pair.key_type == KeyType.BLS12381G2 + assert suite.key_pair.key_type == BLS12381G2 assert suite.key_pair.public_key_base58 == did_info.verkey suite = await self.handler._get_suite( @@ -316,7 +316,7 @@ async def test_get_suite(self): assert type(suite) == Ed25519Signature2018 assert suite.verification_method == "verification_method" assert suite.proof == proof - assert suite.key_pair.key_type == KeyType.ED25519 + assert suite.key_pair.key_type == ED25519 assert suite.key_pair.public_key_base58 == did_info.verkey async def test_get_verification_method(self): diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_routes.py b/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_routes.py index 3c72c33e75..7a689b66b4 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_routes.py @@ -2,10 +2,6 @@ from asynctest import mock as async_mock, TestCase as AsyncTestCase from .....admin.request_context import AdminRequestContext -from .....wallet.key_type import KeyType -from .....wallet.did_method import DIDMethod -from .....wallet.base import BaseWallet -from .....wallet.did_info import DIDInfo from .. import routes as test_module from ..formats.indy.handler import IndyCredFormatHandler diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/manager.py b/aries_cloudagent/protocols/out_of_band/v1_0/manager.py index dd0843045a..0792c2854d 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/manager.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/manager.py @@ -20,7 +20,7 @@ from ....storage.error import StorageNotFoundError from ....transport.inbound.receipt import MessageReceipt from ....wallet.base import BaseWallet -from ....wallet.key_type import KeyType +from ....wallet.key_type import ED25519 from ...connections.v1_0.manager import ConnectionManager from ...connections.v1_0.messages.connection_invitation import ConnectionInvitation from ...didcomm_prefix import DIDCommPrefix @@ -276,7 +276,7 @@ async def create_invitation( # Create and store new key for exchange async with self.profile.session() as session: wallet = session.inject(BaseWallet) - connection_key = await wallet.create_signing_key(KeyType.ED25519) + connection_key = await wallet.create_signing_key(ED25519) our_recipient_key = connection_key.verkey @@ -323,7 +323,7 @@ async def create_invitation( routing_keys = [ key if len(key.split(":")) == 3 - else DIDKey.from_public_key_b58(key, KeyType.ED25519).did + else DIDKey.from_public_key_b58(key, ED25519).did for key in routing_keys ] @@ -341,9 +341,7 @@ async def create_invitation( _id="#inline", _type="did-communication", recipient_keys=[ - DIDKey.from_public_key_b58( - connection_key.verkey, KeyType.ED25519 - ).did + DIDKey.from_public_key_b58(connection_key.verkey, ED25519).did ], service_endpoint=my_endpoint, routing_keys=routing_keys, @@ -535,7 +533,7 @@ async def receive_invitation( # Create and store new key for connectionless exchange async with self.profile.session() as session: wallet = session.inject(BaseWallet) - connection_key = await wallet.create_signing_key(KeyType.ED25519) + connection_key = await wallet.create_signing_key(ED25519) oob_record.our_recipient_key = connection_key.verkey oob_record.our_service = ServiceDecorator( recipient_keys=[connection_key.verkey], @@ -777,11 +775,11 @@ async def _perform_handshake( "id": "#inline", "type": "did-communication", "recipientKeys": [ - DIDKey.from_public_key_b58(key, KeyType.ED25519).did + DIDKey.from_public_key_b58(key, ED25519).did for key in recipient_keys ], "routingKeys": [ - DIDKey.from_public_key_b58(key, KeyType.ED25519).did + DIDKey.from_public_key_b58(key, ED25519).did for key in routing_keys ], "serviceEndpoint": endpoint, diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/messages/tests/test_invitation.py b/aries_cloudagent/protocols/out_of_band/v1_0/messages/tests/test_invitation.py index d00da45914..801b17680e 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/messages/tests/test_invitation.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/messages/tests/test_invitation.py @@ -4,7 +4,7 @@ from ......messaging.models.base import BaseModelError from ......did.did_key import DIDKey -from ......wallet.key_type import KeyType +from ......wallet.key_type import ED25519 from .....connections.v1_0.message_types import ARIES_PROTOCOL as CONN_PROTO from .....didcomm_prefix import DIDCommPrefix @@ -82,9 +82,7 @@ def test_wrap_serde(self): service = Service( _id="#inline", _type=DID_COMM, - recipient_keys=[ - DIDKey.from_public_key_b58(TEST_VERKEY, KeyType.ED25519).did - ], + recipient_keys=[DIDKey.from_public_key_b58(TEST_VERKEY, ED25519).did], service_endpoint="http://1.2.3.4:8080/service", ) data_deser = { @@ -112,9 +110,7 @@ def test_url_round_trip(self): service = Service( _id="#inline", _type=DID_COMM, - recipient_keys=[ - DIDKey.from_public_key_b58(TEST_VERKEY, KeyType.ED25519).did - ], + recipient_keys=[DIDKey.from_public_key_b58(TEST_VERKEY, ED25519).did], service_endpoint="http://1.2.3.4:8080/service", ) invi_msg = InvitationMessage( diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py index a9c03cc3da..07010c744c 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py @@ -66,9 +66,9 @@ from .....storage.error import StorageNotFoundError from .....transport.inbound.receipt import MessageReceipt from .....wallet.did_info import DIDInfo, KeyInfo -from .....wallet.did_method import DIDMethod +from .....wallet.did_method import SOV from .....wallet.in_memory import InMemoryWallet -from .....wallet.key_type import KeyType +from .....wallet.key_type import ED25519 from ....connections.v1_0.messages.connection_invitation import ConnectionInvitation from ....didcomm_prefix import DIDCommPrefix from ....issue_credential.v1_0.message_types import CREDENTIAL_OFFER @@ -380,8 +380,8 @@ async def test_create_invitation_handshake_succeeds(self): TestConfig.test_did, TestConfig.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) invi_rec = await self.manager.create_invitation( my_endpoint=TestConfig.test_endpoint, @@ -413,7 +413,7 @@ async def test_create_invitation_multitenant_local(self): self.multitenant_mgr, "get_default_mediator" ) as mock_get_default_mediator: mock_wallet_create_signing_key.return_value = KeyInfo( - TestConfig.test_verkey, None, KeyType.ED25519 + TestConfig.test_verkey, None, ED25519 ) mock_get_default_mediator.return_value = MediationRecord() await self.manager.create_invitation( @@ -440,8 +440,8 @@ async def test_create_invitation_multitenant_public(self): self.test_did, self.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) await self.manager.create_invitation( hs_protos=[HSProto.RFC23], @@ -515,8 +515,8 @@ async def test_create_invitation_attachment_v1_0_cred_offer(self): TestConfig.test_did, TestConfig.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_retrieve_cxid.return_value = async_mock.MagicMock( credential_offer_dict=self.CRED_OFFER_V1 @@ -549,8 +549,8 @@ async def test_create_invitation_attachment_v1_0_cred_offer_no_handshake(self): TestConfig.test_did, TestConfig.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_retrieve_cxid.return_value = async_mock.MagicMock( credential_offer_dict=self.CRED_OFFER_V1 @@ -587,8 +587,8 @@ async def test_create_invitation_attachment_v2_0_cred_offer(self): TestConfig.test_did, TestConfig.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_retrieve_cxid_v1.side_effect = test_module.StorageNotFoundError() mock_retrieve_cxid_v2.return_value = async_mock.MagicMock( @@ -625,8 +625,8 @@ async def test_create_invitation_attachment_present_proof_v1_0(self): TestConfig.test_did, TestConfig.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_retrieve_pxid.return_value = async_mock.MagicMock( presentation_request_dict=self.PRES_REQ_V1 @@ -664,8 +664,8 @@ async def test_create_invitation_attachment_present_proof_v2_0(self): TestConfig.test_did, TestConfig.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_retrieve_pxid_1.side_effect = StorageNotFoundError() mock_retrieve_pxid_2.return_value = async_mock.MagicMock( @@ -752,8 +752,8 @@ async def test_create_invitation_attachment_x(self): TestConfig.test_did, TestConfig.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) with self.assertRaises(OutOfBandManagerError) as context: await self.manager.create_invitation( @@ -810,7 +810,7 @@ async def test_create_invitation_peer_did(self): assert ( service["routingKeys"][0] == DIDKey.from_public_key_b58( - self.test_mediator_routing_keys[0], KeyType.ED25519 + self.test_mediator_routing_keys[0], ED25519 ).did ) assert service["serviceEndpoint"] == self.test_mediator_endpoint @@ -837,8 +837,8 @@ async def test_create_invitation_x_public_metadata(self): TestConfig.test_did, TestConfig.test_verkey, None, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) with self.assertRaises(OutOfBandManagerError) as context: await self.manager.create_invitation( @@ -1299,7 +1299,7 @@ async def test_receive_invitation_connection_protocol(self): recipient_keys=[ DIDKey.from_public_key_b58( "9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC", - KeyType.ED25519, + ED25519, ).did ], routing_keys=[], @@ -1574,7 +1574,7 @@ async def test_request_attach_oob_message_processor_connectionless(self): async_mock.CoroutineMock(), ) as mock_service_decorator_from_service: mock_create_signing_key.return_value = KeyInfo( - verkey="a-verkey", metadata={}, key_type=KeyType.ED25519 + verkey="a-verkey", metadata={}, key_type=ED25519 ) mock_service_decorator_from_service.return_value = mock_service_decorator oob_invitation = InvitationMessage( @@ -1591,7 +1591,7 @@ async def test_request_attach_oob_message_processor_connectionless(self): assert oob_record.our_service assert oob_record.state == OobRecord.STATE_PREPARE_RESPONSE - mock_create_signing_key.assert_called_once_with(KeyType.ED25519) + mock_create_signing_key.assert_called_once_with(ED25519) mock_oob_processor.handle_message.assert_called_once_with( self.profile, [attachment.content for attachment in requests_attach], @@ -1707,10 +1707,10 @@ async def test_service_decorator_from_service_object(self): oob_service = OobService( service_endpoint=TestConfig.test_endpoint, recipient_keys=[ - DIDKey.from_public_key_b58(TestConfig.test_verkey, KeyType.ED25519).did + DIDKey.from_public_key_b58(TestConfig.test_verkey, ED25519).did ], routing_keys=[ - DIDKey.from_public_key_b58(verkey, KeyType.ED25519).did + DIDKey.from_public_key_b58(verkey, ED25519).did for verkey in self.test_mediator_routing_keys ], ) diff --git a/aries_cloudagent/protocols/present_proof/dif/pres_exch_handler.py b/aries_cloudagent/protocols/present_proof/dif/pres_exch_handler.py index 638ce0fa3e..813dbe287d 100644 --- a/aries_cloudagent/protocols/present_proof/dif/pres_exch_handler.py +++ b/aries_cloudagent/protocols/present_proof/dif/pres_exch_handler.py @@ -40,7 +40,7 @@ from ....vc.vc_ld.prove import sign_presentation, create_presentation, derive_credential from ....wallet.base import BaseWallet, DIDInfo from ....wallet.error import WalletError, WalletNotFoundError -from ....wallet.key_type import KeyType +from ....wallet.key_type import BLS12381G2, ED25519 from .pres_exch import ( PresentationDefinition, @@ -73,14 +73,14 @@ class DIFPresExchHandler: """Base Presentation Exchange Handler.""" ISSUE_SIGNATURE_SUITE_KEY_TYPE_MAPPING = { - Ed25519Signature2018: KeyType.ED25519, + Ed25519Signature2018: ED25519, } if BbsBlsSignature2020.BBS_SUPPORTED: - ISSUE_SIGNATURE_SUITE_KEY_TYPE_MAPPING[BbsBlsSignature2020] = KeyType.BLS12381G2 + ISSUE_SIGNATURE_SUITE_KEY_TYPE_MAPPING[BbsBlsSignature2020] = BLS12381G2 DERIVE_SIGNATURE_SUITE_KEY_TYPE_MAPPING = { - BbsBlsSignatureProof2020: KeyType.BLS12381G2, + BbsBlsSignatureProof2020: BLS12381G2, } PROOF_TYPE_SIGNATURE_SUITE_MAPPING = { suite.signature_type: suite @@ -196,9 +196,9 @@ async def get_sign_key_credential_subject_id( issuer_id = None filtered_creds_list = [] if self.proof_type == BbsBlsSignature2020.signature_type: - reqd_key_type = KeyType.BLS12381G2 + reqd_key_type = BLS12381G2 else: - reqd_key_type = KeyType.ED25519 + reqd_key_type = ED25519 for cred in applicable_creds: if cred.subject_ids and len(cred.subject_ids) > 0: if not issuer_id: diff --git a/aries_cloudagent/protocols/present_proof/dif/tests/test_pres_exch_handler.py b/aries_cloudagent/protocols/present_proof/dif/tests/test_pres_exch_handler.py index 87587eb674..34faf21af2 100644 --- a/aries_cloudagent/protocols/present_proof/dif/tests/test_pres_exch_handler.py +++ b/aries_cloudagent/protocols/present_proof/dif/tests/test_pres_exch_handler.py @@ -6,13 +6,15 @@ import mock as async_mock import pytest +from aries_cloudagent.wallet.key_type import BLS12381G2, ED25519 + from .....core.in_memory import InMemoryProfile from .....did.did_key import DIDKey from .....resolver.did_resolver import DIDResolver from .....storage.vc_holder.vc_record import VCRecord from .....wallet.base import BaseWallet, DIDInfo from .....wallet.crypto import KeyType -from .....wallet.did_method import DIDMethod +from .....wallet.did_method import SOV, KEY from .....wallet.error import WalletNotFoundError from .....vc.ld_proofs import ( BbsBlsSignature2020, @@ -79,11 +81,11 @@ async def setup_tuple(profile): async with profile.session() as session: wallet = session.inject_or(BaseWallet) await wallet.create_local_did( - method=DIDMethod.SOV, key_type=KeyType.ED25519, did="WgWxqztrNooG92RXvxSTWv" + method=SOV, key_type=ED25519, did="WgWxqztrNooG92RXvxSTWv" ) await wallet.create_local_did( - method=DIDMethod.KEY, - key_type=KeyType.BLS12381G2, + method=KEY, + key_type=BLS12381G2, ) creds, pds = get_test_data() return creds, pds @@ -2031,8 +2033,8 @@ async def test_get_sign_key_credential_subject_id(self, profile): did="did:sov:LjgpST2rjsoxYegQDRm7EL", verkey="verkey", metadata={}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_did_info.return_value = did_info ( @@ -2096,8 +2098,8 @@ async def test_get_sign_key_credential_subject_id_error(self, profile): did="did:sov:LjgpST2rjsoxYegQDRm7EL", verkey="verkey", metadata={}, - method=DIDMethod.SOV, - key_type=KeyType.ED25519, + method=SOV, + key_type=ED25519, ) mock_did_info.return_value = did_info with pytest.raises(DIFPresExchError): @@ -2164,8 +2166,8 @@ async def test_get_sign_key_credential_subject_id_bbsbls(self, profile): did="did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL", verkey="verkey", metadata={}, - method=DIDMethod.KEY, - key_type=KeyType.BLS12381G2, + method=KEY, + key_type=BLS12381G2, ) mock_did_info.return_value = did_info ( @@ -2255,8 +2257,8 @@ async def test_create_vp_no_issuer(self, profile, setup_tuple): did="did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL", verkey="verkey", metadata={}, - method=DIDMethod.KEY, - key_type=KeyType.BLS12381G2, + method=KEY, + key_type=BLS12381G2, ) mock_did_info.return_value = did_info vp = await dif_pres_exch_handler.create_vp( @@ -2315,8 +2317,8 @@ async def test_create_vp_with_bbs_suite(self, profile, setup_tuple): did="did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL", verkey="verkey", metadata={}, - method=DIDMethod.KEY, - key_type=KeyType.BLS12381G2, + method=KEY, + key_type=BLS12381G2, ) mock_did_info.return_value = did_info vp = await dif_pres_exch_handler.create_vp( @@ -2369,8 +2371,8 @@ async def test_create_vp_no_issuer_with_bbs_suite(self, profile, setup_tuple): did="did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL", verkey="verkey", metadata={}, - method=DIDMethod.KEY, - key_type=KeyType.BLS12381G2, + method=KEY, + key_type=BLS12381G2, ) mock_did_info.return_value = did_info vp = await dif_pres_exch_handler.create_vp( diff --git a/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/handler.py b/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/handler.py index 9efff76b16..5459213d3f 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/handler.py @@ -21,7 +21,7 @@ ) from ......vc.vc_ld.verify import verify_presentation from ......wallet.base import BaseWallet -from ......wallet.key_type import KeyType +from ......wallet.key_type import ED25519, BLS12381G2 from .....problem_report.v1_0.message import ProblemReport @@ -56,14 +56,12 @@ class DIFPresFormatHandler(V20PresFormatHandler): format = V20PresFormat.Format.DIF ISSUE_SIGNATURE_SUITE_KEY_TYPE_MAPPING = { - Ed25519Signature2018: KeyType.ED25519, + Ed25519Signature2018: ED25519, } if BbsBlsSignature2020.BBS_SUPPORTED: - ISSUE_SIGNATURE_SUITE_KEY_TYPE_MAPPING[BbsBlsSignature2020] = KeyType.BLS12381G2 - ISSUE_SIGNATURE_SUITE_KEY_TYPE_MAPPING[ - BbsBlsSignatureProof2020 - ] = KeyType.BLS12381G2 + ISSUE_SIGNATURE_SUITE_KEY_TYPE_MAPPING[BbsBlsSignature2020] = BLS12381G2 + ISSUE_SIGNATURE_SUITE_KEY_TYPE_MAPPING[BbsBlsSignatureProof2020] = BLS12381G2 async def _get_all_suites(self, wallet: BaseWallet): """Get all supported suites for verifying presentation.""" diff --git a/aries_cloudagent/transport/tests/test_pack_format.py b/aries_cloudagent/transport/tests/test_pack_format.py index 1ca7b7f46f..02a7712e1c 100644 --- a/aries_cloudagent/transport/tests/test_pack_format.py +++ b/aries_cloudagent/transport/tests/test_pack_format.py @@ -1,19 +1,18 @@ import json - from base64 import b64encode -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from asynctest import TestCase as AsyncTestCase +from asynctest import mock as async_mock from ...core.in_memory import InMemoryProfile -from ...protocols.routing.v1_0.message_types import FORWARD from ...protocols.didcomm_prefix import DIDCommPrefix +from ...protocols.routing.v1_0.message_types import FORWARD from ...wallet.base import BaseWallet +from ...wallet.did_method import SOV from ...wallet.error import WalletError -from ...wallet.key_type import KeyType -from ...wallet.did_method import DIDMethod - +from ...wallet.key_type import ED25519 from .. import pack_format as test_module -from ..error import WireFormatEncodeError, WireFormatParseError, RecipientKeysError +from ..error import RecipientKeysError, WireFormatEncodeError, WireFormatParseError from ..pack_format import PackWireFormat @@ -140,7 +139,7 @@ async def test_fallback(self): async def test_encode_decode(self): local_did = await self.wallet.create_local_did( - method=DIDMethod.SOV, key_type=KeyType.ED25519, seed=self.test_seed + method=SOV, key_type=ED25519, seed=self.test_seed ) serializer = PackWireFormat() recipient_keys = (local_did.verkey,) @@ -174,10 +173,10 @@ async def test_encode_decode(self): async def test_forward(self): local_did = await self.wallet.create_local_did( - method=DIDMethod.SOV, key_type=KeyType.ED25519, seed=self.test_seed + method=SOV, key_type=ED25519, seed=self.test_seed ) router_did = await self.wallet.create_local_did( - method=DIDMethod.SOV, key_type=KeyType.ED25519, seed=self.test_routing_seed + method=SOV, key_type=ED25519, seed=self.test_routing_seed ) serializer = PackWireFormat() recipient_keys = (local_did.verkey,) diff --git a/aries_cloudagent/utils/tests/test_outofband.py b/aries_cloudagent/utils/tests/test_outofband.py index 2029553471..6e3821ff57 100644 --- a/aries_cloudagent/utils/tests/test_outofband.py +++ b/aries_cloudagent/utils/tests/test_outofband.py @@ -1,19 +1,16 @@ from asynctest import TestCase from ...protocols.out_of_band.v1_0.messages.invitation import InvitationMessage -from ...wallet.key_type import KeyType -from ...wallet.did_method import DIDMethod from ...wallet.did_info import DIDInfo - +from ...wallet.did_method import SOV +from ...wallet.key_type import ED25519 from .. import outofband as test_module class TestOutOfBand(TestCase): test_did = "55GkHamhTU1ZbTbV2ab9DE" test_verkey = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx" - test_did_info = DIDInfo( - test_did, test_verkey, None, method=DIDMethod.SOV, key_type=KeyType.ED25519 - ) + test_did_info = DIDInfo(test_did, test_verkey, None, method=SOV, key_type=ED25519) def test_serialize_oob(self): invi = InvitationMessage( 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 705ca244be..6c82afad01 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 @@ -1,5 +1,7 @@ from asynctest import TestCase, mock as async_mock +from aries_cloudagent.wallet.key_type import ED25519 + from .....wallet.key_pair import KeyType from ...error import LinkedDataProofException @@ -12,7 +14,7 @@ async def setUp(self): self.wallet = async_mock.MagicMock() async def test_sign_x_no_public_key(self): - key_pair = WalletKeyPair(wallet=self.wallet, key_type=KeyType.ED25519) + key_pair = WalletKeyPair(wallet=self.wallet, key_type=ED25519) with self.assertRaises(LinkedDataProofException) as context: await key_pair.sign(b"Message") @@ -22,7 +24,7 @@ async def test_sign(self): public_key_base58 = "verkey" key_pair = WalletKeyPair( wallet=self.wallet, - key_type=KeyType.ED25519, + key_type=ED25519, public_key_base58=public_key_base58, ) signed = async_mock.MagicMock() @@ -37,7 +39,7 @@ async def test_sign(self): ) async def test_verify_x_no_public_key(self): - key_pair = WalletKeyPair(wallet=self.wallet, key_type=KeyType.ED25519) + key_pair = WalletKeyPair(wallet=self.wallet, key_type=ED25519) with self.assertRaises(LinkedDataProofException) as context: await key_pair.verify(b"Message", b"signature") @@ -47,7 +49,7 @@ async def test_verify(self): public_key_base58 = "verkey" key_pair = WalletKeyPair( wallet=self.wallet, - key_type=KeyType.ED25519, + key_type=ED25519, public_key_base58=public_key_base58, ) self.wallet.verify_message = async_mock.CoroutineMock(return_value=True) @@ -59,11 +61,11 @@ async def test_verify(self): message=b"Message", signature=b"signature", from_verkey=public_key_base58, - key_type=KeyType.ED25519, + key_type=ED25519, ) async def test_from_verification_method_x_no_public_key_base58(self): - key_pair = WalletKeyPair(wallet=self.wallet, key_type=KeyType.ED25519) + key_pair = WalletKeyPair(wallet=self.wallet, key_type=ED25519) with self.assertRaises(LinkedDataProofException) as context: key_pair.from_verification_method({}) diff --git a/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_2020.py b/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_2020.py index f8bfdf6533..bb3bc4d523 100644 --- a/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_2020.py +++ b/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_2020.py @@ -1,6 +1,8 @@ from asynctest import TestCase, mock as async_mock import pytest +from aries_cloudagent.wallet.key_type import BLS12381G2 + from .....did.did_key import DIDKey from .....wallet.key_pair import KeyType from .....wallet.in_memory import InMemoryWallet @@ -30,20 +32,18 @@ async def setUp(self): self.profile = InMemoryProfile.test_profile() self.wallet = InMemoryWallet(self.profile) self.key = await self.wallet.create_signing_key( - key_type=KeyType.BLS12381G2, seed=self.test_seed + key_type=BLS12381G2, seed=self.test_seed ) self.verification_method = DIDKey.from_public_key_b58( - self.key.verkey, KeyType.BLS12381G2 + self.key.verkey, BLS12381G2 ).key_id self.sign_key_pair = WalletKeyPair( wallet=self.wallet, - key_type=KeyType.BLS12381G2, + key_type=BLS12381G2, public_key_base58=self.key.verkey, ) - self.verify_key_pair = WalletKeyPair( - wallet=self.wallet, key_type=KeyType.BLS12381G2 - ) + self.verify_key_pair = WalletKeyPair(wallet=self.wallet, key_type=BLS12381G2) async def test_sign_ld_proofs(self): signed = await sign( diff --git a/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_proof_2020.py b/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_proof_2020.py index e8a79e2297..67d027d770 100644 --- a/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_proof_2020.py +++ b/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_proof_2020.py @@ -1,6 +1,8 @@ from asynctest import TestCase, mock as async_mock import pytest +from aries_cloudagent.wallet.key_type import BLS12381G2 + from .....did.did_key import DIDKey from .....wallet.key_pair import KeyType from .....wallet.in_memory import InMemoryWallet @@ -39,13 +41,13 @@ async def setUp(self): self.profile = InMemoryProfile.test_profile() self.wallet = InMemoryWallet(self.profile) self.key = await self.wallet.create_signing_key( - key_type=KeyType.BLS12381G2, seed=self.test_seed + key_type=BLS12381G2, seed=self.test_seed ) self.verification_method = DIDKey.from_public_key_b58( - self.key.verkey, KeyType.BLS12381G2 + self.key.verkey, BLS12381G2 ).key_id - self.key_pair = WalletKeyPair(wallet=self.wallet, key_type=KeyType.BLS12381G2) + self.key_pair = WalletKeyPair(wallet=self.wallet, key_type=BLS12381G2) async def test_derive_ld_proofs(self): derived = await derive( diff --git a/aries_cloudagent/vc/ld_proofs/suites/tests/test_ed25519_signature_2018.py b/aries_cloudagent/vc/ld_proofs/suites/tests/test_ed25519_signature_2018.py index 613aec46ab..60bf0389f6 100644 --- a/aries_cloudagent/vc/ld_proofs/suites/tests/test_ed25519_signature_2018.py +++ b/aries_cloudagent/vc/ld_proofs/suites/tests/test_ed25519_signature_2018.py @@ -1,5 +1,7 @@ from asynctest import TestCase +from aries_cloudagent.wallet.key_type import ED25519 + from .....did.did_key import DIDKey from .....wallet.key_pair import KeyType @@ -29,20 +31,18 @@ async def setUp(self): self.profile = InMemoryProfile.test_profile() self.wallet = InMemoryWallet(self.profile) self.key = await self.wallet.create_signing_key( - key_type=KeyType.ED25519, seed=self.test_seed + key_type=ED25519, seed=self.test_seed ) self.verification_method = DIDKey.from_public_key_b58( - self.key.verkey, KeyType.ED25519 + self.key.verkey, ED25519 ).key_id self.sign_key_pair = WalletKeyPair( wallet=self.wallet, - key_type=KeyType.ED25519, + key_type=ED25519, public_key_base58=self.key.verkey, ) - self.verify_key_pair = WalletKeyPair( - wallet=self.wallet, key_type=KeyType.ED25519 - ) + self.verify_key_pair = WalletKeyPair(wallet=self.wallet, key_type=ED25519) async def test_sign_ld_proofs(self): signed = await sign( diff --git a/aries_cloudagent/vc/ld_proofs/tests/test_ld_proofs.py b/aries_cloudagent/vc/ld_proofs/tests/test_ld_proofs.py index 15d9ea5e90..0143cfe17f 100644 --- a/aries_cloudagent/vc/ld_proofs/tests/test_ld_proofs.py +++ b/aries_cloudagent/vc/ld_proofs/tests/test_ld_proofs.py @@ -4,7 +4,7 @@ from asynctest import TestCase -from ....wallet.key_type import KeyType +from ....wallet.key_type import BLS12381G2, ED25519 from ....did.did_key import DIDKey from ....wallet.in_memory import InMemoryWallet from ....core.in_memory import InMemoryProfile @@ -40,18 +40,18 @@ async def setUp(self): self.wallet = InMemoryWallet(self.profile) self.ed25519_key_info = await self.wallet.create_signing_key( - key_type=KeyType.ED25519, seed=self.test_seed + key_type=ED25519, seed=self.test_seed ) self.ed25519_verification_method = DIDKey.from_public_key_b58( - self.ed25519_key_info.verkey, KeyType.ED25519 + self.ed25519_key_info.verkey, ED25519 ).key_id self.bls12381g2_key_info = await self.wallet.create_signing_key( - key_type=KeyType.BLS12381G2, seed=self.test_seed + key_type=BLS12381G2, seed=self.test_seed ) self.bls12381g2_verification_method = DIDKey.from_public_key_b58( - self.bls12381g2_key_info.verkey, KeyType.BLS12381G2 + self.bls12381g2_key_info.verkey, BLS12381G2 ).key_id async def test_sign_Ed25519Signature2018(self): @@ -62,7 +62,7 @@ async def test_sign_Ed25519Signature2018(self): verification_method=self.ed25519_verification_method, key_pair=WalletKeyPair( wallet=self.wallet, - key_type=KeyType.ED25519, + key_type=ED25519, public_key_base58=self.ed25519_key_info.verkey, ), date=datetime(2019, 12, 11, 3, 50, 55, 0, timezone.utc), @@ -79,7 +79,7 @@ async def test_sign_Ed25519Signature2018(self): async def test_verify_Ed25519Signature2018(self): # Verification requires lot less input parameters suite = Ed25519Signature2018( - key_pair=WalletKeyPair(wallet=self.wallet, key_type=KeyType.ED25519), + key_pair=WalletKeyPair(wallet=self.wallet, key_type=ED25519), ) result = await verify( @@ -100,7 +100,7 @@ async def test_sign_BbsBlsSignature2020(self): verification_method=self.bls12381g2_verification_method, key_pair=WalletKeyPair( wallet=self.wallet, - key_type=KeyType.BLS12381G2, + key_type=BLS12381G2, public_key_base58=self.bls12381g2_key_info.verkey, ), date=datetime(2019, 12, 11, 3, 50, 55, 0), @@ -128,7 +128,7 @@ async def test_sign_BbsBlsSignature2020(self): async def test_verify_BbsBlsSignature2020(self): # Verification requires lot less input parameters suite = BbsBlsSignature2020( - key_pair=WalletKeyPair(wallet=self.wallet, key_type=KeyType.BLS12381G2), + key_pair=WalletKeyPair(wallet=self.wallet, key_type=BLS12381G2), ) result = await verify( @@ -144,7 +144,7 @@ async def test_verify_BbsBlsSignature2020(self): async def test_derive_BbsBlsSignatureProof2020(self): # Verification requires lot less input parameters suite = BbsBlsSignatureProof2020( - key_pair=WalletKeyPair(wallet=self.wallet, key_type=KeyType.BLS12381G2), + key_pair=WalletKeyPair(wallet=self.wallet, key_type=BLS12381G2), ) result = await derive( @@ -160,7 +160,7 @@ async def test_derive_BbsBlsSignatureProof2020(self): async def test_verify_BbsBlsSignatureProof2020(self): # Verification requires lot less input parameters suite = BbsBlsSignatureProof2020( - key_pair=WalletKeyPair(wallet=self.wallet, key_type=KeyType.BLS12381G2), + key_pair=WalletKeyPair(wallet=self.wallet, key_type=BLS12381G2), ) result = await verify( diff --git a/aries_cloudagent/vc/tests/test_bbs_mattr_interop.py b/aries_cloudagent/vc/tests/test_bbs_mattr_interop.py index 707dec1e6b..d9f4dde009 100644 --- a/aries_cloudagent/vc/tests/test_bbs_mattr_interop.py +++ b/aries_cloudagent/vc/tests/test_bbs_mattr_interop.py @@ -1,7 +1,7 @@ from asynctest import TestCase import pytest -from ...wallet.key_type import KeyType +from ...wallet.key_type import BLS12381G2 from ...wallet.util import b58_to_bytes from ...wallet.in_memory import InMemoryWallet from ...core.in_memory import InMemoryProfile @@ -45,23 +45,23 @@ async def setUp(self): "secret": b58_to_bytes(private_key_base58), "verkey": public_key_base58, "metadata": {}, - "key_type": KeyType.BLS12381G2, + "key_type": BLS12381G2, } self.signature_issuer_suite = BbsBlsSignature2020( verification_method="did:example:489398593#test", key_pair=WalletKeyPair( wallet=self.wallet, - key_type=KeyType.BLS12381G2, + key_type=BLS12381G2, public_key_base58=public_key_base58, ), ) self.signature_suite = BbsBlsSignature2020( - key_pair=WalletKeyPair(wallet=self.wallet, key_type=KeyType.BLS12381G2), + key_pair=WalletKeyPair(wallet=self.wallet, key_type=BLS12381G2), ) self.proof_suite = BbsBlsSignatureProof2020( - key_pair=WalletKeyPair(wallet=self.wallet, key_type=KeyType.BLS12381G2) + key_pair=WalletKeyPair(wallet=self.wallet, key_type=BLS12381G2) ) async def test_sign_bbs_vc_mattr(self): diff --git a/aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py b/aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py index 8fe29c799f..3c3643ec1a 100644 --- a/aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py +++ b/aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py @@ -3,7 +3,7 @@ import pytest -from ....wallet.key_type import KeyType +from ....wallet.key_type import BLS12381G2, ED25519 from ....did.did_key import DIDKey from ....wallet.in_memory import InMemoryWallet from ....core.in_memory import InMemoryProfile @@ -37,18 +37,18 @@ async def setUp(self): self.wallet = InMemoryWallet(self.profile) self.ed25519_key_info = await self.wallet.create_signing_key( - key_type=KeyType.ED25519, seed=self.test_seed + key_type=ED25519, seed=self.test_seed ) self.ed25519_verification_method = DIDKey.from_public_key_b58( - self.ed25519_key_info.verkey, KeyType.ED25519 + self.ed25519_key_info.verkey, ED25519 ).key_id self.bls12381g2_key_info = await self.wallet.create_signing_key( - key_type=KeyType.BLS12381G2, seed=self.test_seed + key_type=BLS12381G2, seed=self.test_seed ) self.bls12381g2_verification_method = DIDKey.from_public_key_b58( - self.bls12381g2_key_info.verkey, KeyType.BLS12381G2 + self.bls12381g2_key_info.verkey, BLS12381G2 ).key_id self.presentation_challenge = "2b1bbff6-e608-4368-bf84-67471b27e41c" @@ -61,7 +61,7 @@ async def test_issue_Ed25519Signature2018(self): verification_method=self.ed25519_verification_method, key_pair=WalletKeyPair( wallet=self.wallet, - key_type=KeyType.ED25519, + key_type=ED25519, public_key_base58=self.ed25519_key_info.verkey, ), date=datetime.strptime("2019-12-11T03:50:55Z", "%Y-%m-%dT%H:%M:%SZ"), @@ -103,7 +103,7 @@ async def test_derive_x_invalid_credential_structure(self): async def test_verify_Ed25519Signature2018(self): # Verification requires lot less input parameters suite = Ed25519Signature2018( - key_pair=WalletKeyPair(wallet=self.wallet, key_type=KeyType.ED25519), + key_pair=WalletKeyPair(wallet=self.wallet, key_type=ED25519), ) verified = await verify_credential( credential=CREDENTIAL_ISSUED, @@ -135,7 +135,7 @@ async def test_issue_BbsBlsSignature2020(self): verification_method=self.bls12381g2_verification_method, key_pair=WalletKeyPair( wallet=self.wallet, - key_type=KeyType.BLS12381G2, + key_type=BLS12381G2, public_key_base58=self.bls12381g2_key_info.verkey, ), date=datetime.strptime("2019-12-11T03:50:55Z", "%Y-%m-%dT%H:%M:%SZ"), @@ -158,7 +158,7 @@ async def test_issue_BbsBlsSignature2020(self): async def test_verify_BbsBlsSignature2020(self): # Verification requires lot less input parameters suite = BbsBlsSignature2020( - key_pair=WalletKeyPair(wallet=self.wallet, key_type=KeyType.BLS12381G2), + key_pair=WalletKeyPair(wallet=self.wallet, key_type=BLS12381G2), ) result = await verify_credential( credential=CREDENTIAL_ISSUED_BBS, @@ -185,7 +185,7 @@ async def test_create_presentation_x_invalid_credential_structures(self): verification_method=self.ed25519_verification_method, key_pair=WalletKeyPair( wallet=self.wallet, - key_type=KeyType.ED25519, + key_type=ED25519, public_key_base58=self.ed25519_key_info.verkey, ), date=datetime.strptime("2020-12-11T03:50:55Z", "%Y-%m-%dT%H:%M:%SZ"), @@ -218,7 +218,7 @@ async def test_sign_presentation_bbsbls(self): verification_method=self.bls12381g2_verification_method, key_pair=WalletKeyPair( wallet=self.wallet, - key_type=KeyType.BLS12381G2, + key_type=BLS12381G2, public_key_base58=self.bls12381g2_key_info.verkey, ), date=datetime.strptime("2020-12-11T03:50:55Z", "%Y-%m-%dT%H:%M:%SZ"), @@ -235,7 +235,7 @@ async def test_sign_presentation_bbsbls(self): async def test_verify_presentation(self): suite = Ed25519Signature2018( - key_pair=WalletKeyPair(wallet=self.wallet, key_type=KeyType.ED25519), + key_pair=WalletKeyPair(wallet=self.wallet, key_type=ED25519), ) verification_result = await verify_presentation( presentation=PRESENTATION_SIGNED, diff --git a/aries_cloudagent/wallet/askar.py b/aries_cloudagent/wallet/askar.py index f2a5c790c6..5d84df9f26 100644 --- a/aries_cloudagent/wallet/askar.py +++ b/aries_cloudagent/wallet/askar.py @@ -13,7 +13,6 @@ Key, KeyAlg, SeedMethod, - Session, ) from ..askar.didcomm.v1 import pack_message, unpack_message @@ -31,9 +30,9 @@ validate_seed, verify_signed_message, ) -from .did_method import DIDMethod +from .did_method import SOV, KEY, DIDMethod, DIDMethods from .error import WalletError, WalletDuplicateError, WalletNotFoundError -from .key_type import KeyType +from .key_type import BLS12381G2, ED25519, KeyType, KeyTypes from .util import b58_to_bytes, bytes_to_b58 CATEGORY_DID = "did" @@ -56,7 +55,7 @@ def __init__(self, session: AskarProfileSession): self._session = session @property - def session(self) -> Session: + def session(self) -> AskarProfileSession: """Accessor for Askar profile session instance.""" return self._session @@ -119,7 +118,7 @@ async def get_signing_key(self, verkey: str) -> KeyInfo: raise WalletNotFoundError("Unknown key: {}".format(verkey)) metadata = json.loads(key.metadata or "{}") # FIXME implement key types - return KeyInfo(verkey=verkey, metadata=metadata, key_type=KeyType.ED25519) + return KeyInfo(verkey=verkey, metadata=metadata, key_type=ED25519) async def replace_signing_key_metadata(self, verkey: str, metadata: dict): """ @@ -180,12 +179,12 @@ async def create_local_did( f" for DID method {method.method_name}" ) - if method == DIDMethod.KEY and did: + if method == KEY and did: raise WalletError("Not allowed to set DID for DID method 'key'") if not metadata: metadata = {} - if method not in [DIDMethod.SOV, DIDMethod.KEY]: + if method not in [SOV, KEY]: raise WalletError( f"Unsupported DID method for askar storage: {method.method_name}" ) @@ -206,7 +205,7 @@ async def create_local_did( else: raise WalletError("Error inserting key") from err - if method == DIDMethod.KEY: + if method == KEY: did = DIDKey.from_public_key(verkey_bytes, key_type).did elif not did: did = bytes_to_b58(verkey_bytes[:16]) @@ -257,7 +256,7 @@ async def get_local_dids(self) -> Sequence[DIDInfo]: ret = [] for item in await self._session.handle.fetch_all(CATEGORY_DID): - ret.append(_load_did_entry(item)) + ret.append(self._load_did_entry(item)) return ret async def get_local_did(self, did: str) -> DIDInfo: @@ -284,7 +283,7 @@ async def get_local_did(self, did: str) -> DIDInfo: raise WalletError("Error when fetching local DID") from err if not did: raise WalletNotFoundError("Unknown DID: {}".format(did)) - return _load_did_entry(did) + return self._load_did_entry(did) async def get_local_did_for_verkey(self, verkey: str) -> DIDInfo: """ @@ -308,7 +307,7 @@ async def get_local_did_for_verkey(self, verkey: str) -> DIDInfo: except AskarError as err: raise WalletError("Error when fetching local DID for verkey") from err if dids: - return _load_did_entry(dids[0]) + return self._load_did_entry(dids[0]) raise WalletNotFoundError("No DID defined for verkey: {}".format(verkey)) async def replace_local_did_metadata(self, did: str, metadata: dict): @@ -403,12 +402,12 @@ async def set_public_did(self, did: Union[str, DIDInfo]) -> DIDInfo: raise WalletError("Error when fetching local DID") from err if not item: raise WalletNotFoundError("Unknown DID: {}".format(did)) - info = _load_did_entry(item) + info = self._load_did_entry(item) else: info = did item = None - if info.method != DIDMethod.SOV: + if info.method != SOV: raise WalletError("Setting public DID is only allowed for did:sov DIDs") public = await self.get_public_did() @@ -462,7 +461,7 @@ async def set_did_endpoint( 'endpoint' affects local wallet """ did_info = await self.get_local_did(did) - if did_info.method != DIDMethod.SOV: + if did_info.method != SOV: raise WalletError("Setting DID endpoint is only allowed for did:sov DIDs") metadata = {**did_info.metadata} if not endpoint_type: @@ -507,14 +506,15 @@ async def rotate_did_keypair_start(self, did: str, next_seed: str = None) -> str """ # Check if DID can rotate keys - did_method = DIDMethod.from_did(did) + did_methods = self._session.inject(DIDMethods) + did_method: DIDMethod = did_methods.from_did(did) if not did_method.supports_rotation: raise WalletError( f"DID method '{did_method.method_name}' does not support key rotation." ) # create a new key to be rotated to (only did:sov/ED25519 supported for now) - keypair = _create_keypair(KeyType.ED25519, next_seed) + keypair = _create_keypair(ED25519, next_seed) verkey = bytes_to_b58(keypair.get_public_bytes()) try: await self._session.handle.insert_key( @@ -607,7 +607,7 @@ async def sign_message( return sign_message( message=message, secret=key.get_secret_bytes(), - key_type=KeyType.BLS12381G2, + key_type=BLS12381G2, ) else: @@ -650,7 +650,7 @@ async def verify_message( verkey = b58_to_bytes(from_verkey) - if key_type == KeyType.ED25519: + if key_type == ED25519: try: pk = Key.from_public_bytes(KeyAlg.ED25519, verkey) return pk.verify_signature(message, signature) @@ -727,24 +727,38 @@ async def unpack_message(self, enc_message: bytes) -> Tuple[str, str, str]: raise WalletError("Exception when unpacking message") from err return unpacked_json.decode("utf-8"), sender, recipient + def _load_did_entry(self, entry: Entry) -> DIDInfo: + """Convert a DID record into the expected DIDInfo format.""" + did_info = entry.value_json + did_methods: DIDMethods = self._session.inject(DIDMethods) + key_types: KeyTypes = self._session.inject(KeyTypes) + return DIDInfo( + did=did_info["did"], + verkey=did_info["verkey"], + metadata=did_info.get("metadata"), + method=did_methods.from_method(did_info.get("method", "sov")) or SOV, + key_type=key_types.from_key_type(did_info.get("verkey_type", "ed25519")) + or ED25519, + ) + def _create_keypair(key_type: KeyType, seed: Union[str, bytes] = None) -> Key: """Instantiate a new keypair with an optional seed value.""" - if key_type == KeyType.ED25519: + if key_type == ED25519: alg = KeyAlg.ED25519 method = None - # elif key_type == KeyType.BLS12381G1: + # elif key_type == BLS12381G1: # alg = KeyAlg.BLS12_381_G1 - elif key_type == KeyType.BLS12381G2: + elif key_type == BLS12381G2: alg = KeyAlg.BLS12_381_G2 method = SeedMethod.BlsKeyGen - # elif key_type == KeyType.BLS12381G1G2: + # elif key_type == BLS12381G1G2: # alg = KeyAlg.BLS12_381_G1G2 else: raise WalletError(f"Unsupported key algorithm: {key_type}") if seed: try: - if key_type == KeyType.ED25519: + if key_type == ED25519: # not a seed - it is the secret key seed = validate_seed(seed) return Key.from_secret_bytes(alg, seed) @@ -755,15 +769,3 @@ def _create_keypair(key_type: KeyType, seed: Union[str, bytes] = None) -> Key: raise WalletError("Invalid seed for key generation") from None else: return Key.generate(alg) - - -def _load_did_entry(entry: Entry) -> DIDInfo: - """Convert a DID record into the expected DIDInfo format.""" - did_info = entry.value_json - return DIDInfo( - did=did_info["did"], - verkey=did_info["verkey"], - metadata=did_info.get("metadata"), - method=DIDMethod.from_method(did_info.get("method", "sov")), - key_type=KeyType.from_key_type(did_info.get("verkey_type", "ed25519")), - ) diff --git a/aries_cloudagent/wallet/base.py b/aries_cloudagent/wallet/base.py index bbb1288061..46bbc3eab9 100644 --- a/aries_cloudagent/wallet/base.py +++ b/aries_cloudagent/wallet/base.py @@ -9,7 +9,7 @@ from .did_info import DIDInfo, KeyInfo from .key_type import KeyType -from .did_method import DIDMethod +from .did_method import SOV, DIDMethod class BaseWallet(ABC): @@ -241,7 +241,7 @@ async def set_did_endpoint( """ did_info = await self.get_local_did(did) - if did_info.method != DIDMethod.SOV: + if did_info.method != SOV: raise WalletError("Setting DID endpoint is only allowed for did:sov DIDs") metadata = {**did_info.metadata} if not endpoint_type: diff --git a/aries_cloudagent/wallet/crypto.py b/aries_cloudagent/wallet/crypto.py index 5e79c3c15f..f44e9cff77 100644 --- a/aries_cloudagent/wallet/crypto.py +++ b/aries_cloudagent/wallet/crypto.py @@ -14,7 +14,7 @@ from ..utils.jwe import JweRecipient, b64url, JweEnvelope, from_b64url from .error import WalletError from .util import bytes_to_b58, b64_to_bytes, b58_to_bytes, random_seed -from .key_type import KeyType +from .key_type import ED25519, BLS12381G2, KeyType from .bbs import ( create_bls12381g2_keypair, verify_signed_messages_bls12381g2, @@ -38,9 +38,9 @@ def create_keypair(key_type: KeyType, seed: bytes = None) -> Tuple[bytes, bytes] A tuple of (public key, secret key) """ - if key_type == KeyType.ED25519: + if key_type == ED25519: return create_ed25519_keypair(seed) - elif key_type == KeyType.BLS12381G2: + elif key_type == BLS12381G2: # This ensures python won't crash if bbs is not installed and not used return create_bls12381g2_keypair(seed) @@ -149,7 +149,7 @@ def sign_message( # Make messages list if not already for easier checking going forward messages = message if isinstance(message, list) else [message] - if key_type == KeyType.ED25519: + if key_type == ED25519: if len(messages) > 1: raise WalletError("ed25519 can only sign a single message") @@ -157,7 +157,7 @@ def sign_message( message=messages[0], secret=secret, ) - elif key_type == KeyType.BLS12381G2: + elif key_type == BLS12381G2: return sign_messages_bls12381g2(messages=messages, secret=secret) else: raise WalletError(f"Unsupported key type: {key_type.key_type}") @@ -201,14 +201,14 @@ def verify_signed_message( # Make messages list if not already for easier checking going forward messages = message if isinstance(message, list) else [message] - if key_type == KeyType.ED25519: + if key_type == ED25519: if len(messages) > 1: raise WalletError("ed25519 can only verify a single message") return verify_signed_message_ed25519( message=messages[0], signature=signature, verkey=verkey ) - elif key_type == KeyType.BLS12381G2: + elif key_type == BLS12381G2: try: return verify_signed_messages_bls12381g2( messages=messages, signature=signature, public_key=verkey diff --git a/aries_cloudagent/wallet/did_method.py b/aries_cloudagent/wallet/did_method.py index 797c26fd20..af971ea019 100644 --- a/aries_cloudagent/wallet/did_method.py +++ b/aries_cloudagent/wallet/did_method.py @@ -1,91 +1,82 @@ -"""Did method enum.""" +"""did method.py contains registry for did methods.""" -from typing import List, Mapping, NamedTuple, Optional -from enum import Enum +from typing import Dict, List, Mapping, Optional -from .key_type import KeyType from .error import BaseError - -DIDMethodSpec = NamedTuple( - "DIDMethodSpec", - [ - ("method_name", str), - ("supported_key_types", List[KeyType]), - ("supports_rotation", bool), - ], -) +from .key_type import BLS12381G2, ED25519, KeyType -class DIDMethod(Enum): - """DID Method class specifying DID methods with supported key types.""" +class DIDMethod: + """Class to represent a did method.""" - SOV = DIDMethodSpec( - method_name="sov", supported_key_types=[KeyType.ED25519], supports_rotation=True - ) - KEY = DIDMethodSpec( - method_name="key", - supported_key_types=[KeyType.ED25519, KeyType.BLS12381G2], - supports_rotation=False, - ) + def __init__(self, name: str, key_types: List[KeyType], rotation: bool = False): + """Construct did method class.""" + self._method_name: str = name + self._supported_key_types: List[KeyType] = key_types + self._supports_rotation: bool = rotation @property - def method_name(self) -> str: - """Getter for did method name. e.g. sov or key.""" - return self.value.method_name + def method_name(self): + """Get method name.""" + return self._method_name @property - def supported_key_types(self) -> List[KeyType]: - """Getter for supported key types of method.""" - return self.value.supported_key_types + def supports_rotation(self): + """Check rotation support.""" + return self._supports_rotation @property - def supports_rotation(self) -> bool: - """Check whether the current method supports key rotation.""" - return self.value.supports_rotation + def supported_key_types(self): + """Get supported key types.""" + return self._supported_key_types def supports_key_type(self, key_type: KeyType) -> bool: """Check whether the current method supports the key type.""" return key_type in self.supported_key_types - @classmethod - def from_metadata(cls, metadata: Mapping) -> "DIDMethod": - """Get DID method instance from metadata object. - Returns SOV if no metadata was found for backwards compatability. - """ - method = metadata.get("method") +SOV = DIDMethod(name="sov", key_types=[ED25519], rotation=True) +KEY = DIDMethod( + name="key", + key_types=[ED25519, BLS12381G2], + rotation=False, +) - # extract from metadata object - if method: - for did_method in DIDMethod: - if method == did_method.method_name: - return did_method - # return default SOV for backward compat - return DIDMethod.SOV +class DIDMethods: + """DID Method class specifying DID methods with supported key types.""" - @classmethod - def from_method(cls, method: str) -> Optional["DIDMethod"]: - """Get DID method instance from the method name.""" - for did_method in DIDMethod: - if method == did_method.method_name: - return did_method + def __init__(self) -> None: + """Construct did method registry.""" + self._registry: Dict[str, DIDMethod] = { + SOV.method_name: SOV, + KEY.method_name: KEY, + } - return None + def registered(self, method: str) -> bool: + """Check for a supported method.""" + return method in list(self._registry.items()) - @classmethod - def from_did(cls, did: str) -> "DIDMethod": - """Get DID method instance from the method name.""" - if not did.startswith("did:"): - # sov has no prefix - return DIDMethod.SOV + def register(self, method: DIDMethod): + """Register a new did method.""" + self._registry[method.method_name] = method - parts = did.split(":") - method_str = parts[1] + def from_method(self, method_name: str) -> Optional[DIDMethod]: + """Retrieve a did method from method name.""" + return self._registry.get(method_name) - method = DIDMethod.from_method(method_str) + def from_metadata(self, metadata: Mapping) -> Optional[DIDMethod]: + """Get DID method instance from metadata object. - if not method: - raise BaseError(f"Unsupported did method: {method_str}") + Returns SOV if no metadata was found for backwards compatibility. + """ + method_name: str = metadata.get("method", "sov") + return self.from_method(method_name) + def from_did(self, did: str) -> DIDMethod: + """Get DID method instance from the did url.""" + method_name = did.split(":")[1] if did.startswith("did:") else SOV.method_name + method: DIDMethod | None = self.from_method(method_name) + if not method: + raise BaseError(f"Unsupported did method: {method_name}") return method diff --git a/aries_cloudagent/wallet/in_memory.py b/aries_cloudagent/wallet/in_memory.py index f005ef1d21..f9bb03a37f 100644 --- a/aries_cloudagent/wallet/in_memory.py +++ b/aries_cloudagent/wallet/in_memory.py @@ -17,7 +17,7 @@ ) from .did_info import KeyInfo, DIDInfo from .did_posture import DIDPosture -from .did_method import DIDMethod +from .did_method import SOV, KEY, DIDMethod, DIDMethods from .error import WalletError, WalletDuplicateError, WalletNotFoundError from .key_type import KeyType from .util import b58_to_bytes, bytes_to_b58, random_seed @@ -132,8 +132,8 @@ async def rotate_did_keypair_start(self, did: str, next_seed: str = None) -> str local_did = self.profile.local_dids.get(did) if not local_did: raise WalletNotFoundError("Wallet owns no such DID: {}".format(did)) - - did_method = DIDMethod.from_did(did) + did_methods: DIDMethods = self.profile.context.inject(DIDMethods) + did_method: DIDMethod = did_methods.from_did(did) if not did_method.supports_rotation: raise WalletError( f"DID method '{did_method.method_name}' does not support key rotation." @@ -223,12 +223,12 @@ async def create_local_did( # We need some did method specific handling. If more did methods # are added it is probably better create a did method specific handler - if method == DIDMethod.KEY: + if method == KEY: if did: raise WalletError("Not allowed to set DID for DID method 'key'") did = DIDKey.from_public_key(verkey, key_type).did - elif method == DIDMethod.SOV: + elif method == SOV: if not did: did = bytes_to_b58(verkey[:16]) else: @@ -395,7 +395,7 @@ async def set_public_did(self, did: Union[str, DIDInfo]) -> DIDInfo: info = did did = info.did - if info.method != DIDMethod.SOV: + if info.method != SOV: raise WalletError("Setting public DID is only allowed for did:sov DIDs") public = await self.get_public_did() diff --git a/aries_cloudagent/wallet/indy.py b/aries_cloudagent/wallet/indy.py index 4e2406d04f..ea27f3132b 100644 --- a/aries_cloudagent/wallet/indy.py +++ b/aries_cloudagent/wallet/indy.py @@ -30,10 +30,10 @@ verify_signed_message, ) from .did_info import DIDInfo, KeyInfo -from .did_method import DIDMethod +from .did_method import SOV, KEY, DIDMethod from .error import WalletError, WalletDuplicateError, WalletNotFoundError from .key_pair import KeyPairStorageManager -from .key_type import KeyType +from .key_type import BLS12381G2, ED25519, KeyType, KeyTypes from .util import b58_to_bytes, bytes_to_b58, bytes_to_b64 @@ -48,17 +48,17 @@ class IndySdkWallet(BaseWallet): def __init__(self, opened: IndyOpenWallet): """Create a new IndySdkWallet instance.""" - self.opened = opened + self.opened: IndyOpenWallet = opened def __did_info_from_indy_info(self, info): metadata = json.loads(info["metadata"]) if info["metadata"] else {} did: str = info["did"] verkey = info["verkey"] - method = DIDMethod.KEY if did.startswith("did:key") else DIDMethod.SOV - key_type = KeyType.ED25519 + method = KEY if did.startswith("did:key") else SOV + key_type = ED25519 - if method == DIDMethod.KEY: + if method == KEY: did = DIDKey.from_public_key_b58(info["verkey"], key_type).did return DIDInfo( @@ -69,11 +69,13 @@ def __did_info_from_key_pair_info(self, info: dict): metadata = info["metadata"] verkey = info["verkey"] - # this needs to change if other did methods are added - method = DIDMethod.from_method(info["metadata"].get("method", "key")) - key_type = KeyType.from_key_type(info["key_type"]) + # TODO: inject context to support did method registry + method = SOV if metadata.get("method", "key") == SOV.method_name else KEY + # TODO: inject context to support keytype registry + key_types = KeyTypes() + key_type = key_types.from_key_type(info["key_type"]) - if method == DIDMethod.KEY: + if method == KEY: did = DIDKey.from_public_key_b58(info["verkey"], key_type).did return DIDInfo( @@ -83,7 +85,7 @@ def __did_info_from_key_pair_info(self, info: dict): async def __create_indy_signing_key( self, key_type: KeyType, metadata: dict, seed: str = None ) -> str: - if key_type != KeyType.ED25519: + if key_type != ED25519: raise WalletError(f"Unsupported key type: {key_type.key_type}") args = {} @@ -107,7 +109,7 @@ async def __create_indy_signing_key( async def __create_keypair_signing_key( self, key_type: KeyType, metadata: dict, seed: str = None ) -> str: - if key_type != KeyType.BLS12381G2: + if key_type != BLS12381G2: raise WalletError(f"Unsupported key type: {key_type.key_type}") public_key, secret_key = create_keypair(key_type, validate_seed(seed)) @@ -158,7 +160,7 @@ async def create_signing_key( metadata = {} # All ed25519 keys are handled by indy - if key_type == KeyType.ED25519: + if key_type == ED25519: verkey = await self.__create_indy_signing_key(key_type, metadata, seed) # All other (only bls12381g2 atm) are handled outside of indy else: @@ -173,7 +175,7 @@ async def __get_indy_signing_key(self, verkey: str) -> KeyInfo: return KeyInfo( verkey=verkey, metadata=json.loads(metadata) if metadata else {}, - key_type=KeyType.ED25519, + key_type=ED25519, ) except IndyError as x_indy: if x_indy.error_code == ErrorCode.WalletItemNotFound: @@ -190,10 +192,12 @@ async def __get_keypair_signing_key(self, verkey: str) -> KeyInfo: try: key_pair_mgr = KeyPairStorageManager(IndySdkStorage(self.opened)) key_pair = await key_pair_mgr.get_key_pair(verkey) + # TODO: inject context to support more keytypes + key_types = KeyTypes() return KeyInfo( verkey=verkey, metadata=key_pair["metadata"], - key_type=KeyType.from_key_type(key_pair["key_type"]), + key_type=key_types.from_key_type(key_pair["key_type"]) or BLS12381G2, ) except (StorageNotFoundError): raise WalletNotFoundError(f"Unknown key: {verkey}") @@ -246,7 +250,7 @@ async def replace_signing_key_metadata(self, verkey: str, metadata: dict): key_info = await self.get_signing_key(verkey) # All ed25519 keys are handled by indy - if key_info.key_type == KeyType.ED25519: + if key_info.key_type == ED25519: await indy.crypto.set_key_metadata( self.opened.handle, verkey, json.dumps(metadata) ) @@ -270,7 +274,9 @@ async def rotate_did_keypair_start(self, did: str, next_seed: str = None) -> str """ # Check if DID can rotate keys - did_method = DIDMethod.from_did(did) + # TODO: inject context for did method registry support + method_name = did.split(":")[1] if did.startswith("did:") else SOV.method_name + did_method = SOV if method_name == SOV.method_name else KEY if not did_method.supports_rotation: raise WalletError( f"DID method '{did_method.method_name}' does not support key rotation." @@ -324,11 +330,11 @@ async def __create_indy_local_did( *, did: str = None, ) -> DIDInfo: - if method not in [DIDMethod.SOV, DIDMethod.KEY]: + if method not in [SOV, KEY]: raise WalletError( f"Unsupported DID method for indy storage: {method.method_name}" ) - if key_type != KeyType.ED25519: + if key_type != ED25519: raise WalletError( f"Unsupported key type for indy storage: {key_type.key_type}" ) @@ -340,7 +346,7 @@ async def __create_indy_local_did( cfg["did"] = did # Create fully qualified did. This helps with determining the # did method when retrieving - if method != DIDMethod.SOV: + if method != SOV: cfg["method_name"] = method.method_name did_json = json.dumps(cfg) # crypto_type, cid - optional parameters skipped @@ -356,7 +362,7 @@ async def __create_indy_local_did( ) from x_indy # did key uses different format - if method == DIDMethod.KEY: + if method == KEY: did = DIDKey.from_public_key_b58(verkey, key_type).did await self.replace_local_did_metadata(did, metadata or {}) @@ -376,11 +382,11 @@ async def __create_keypair_local_did( metadata: dict = None, seed: str = None, ) -> DIDInfo: - if method != DIDMethod.KEY: + if method != KEY: raise WalletError( f"Unsupported DID method for keypair storage: {method.method_name}" ) - if key_type != KeyType.BLS12381G2: + if key_type != BLS12381G2: raise WalletError( f"Unsupported key type for keypair storage: {key_type.key_type}" ) @@ -444,11 +450,11 @@ async def create_local_did( f" for DID method {method.method_name}" ) - if method == DIDMethod.KEY and did: + if method == KEY and did: raise WalletError("Not allowed to set DID for DID method 'key'") # All ed25519 keys are handled by indy - if key_type == KeyType.ED25519: + if key_type == ED25519: return await self.__create_indy_local_did( method, key_type, metadata, seed, did=did ) @@ -477,7 +483,7 @@ async def get_local_dids(self) -> Sequence[DIDInfo]: # this needs to change if more did methods are added key_pair_mgr = KeyPairStorageManager(IndySdkStorage(self.opened)) key_pairs = await key_pair_mgr.find_key_pairs( - tag_query={"method": DIDMethod.KEY.method_name} + tag_query={"method": KEY.method_name} ) for key_pair in key_pairs: ret.append(self.__did_info_from_key_pair_info(key_pair)) @@ -487,17 +493,17 @@ async def get_local_dids(self) -> Sequence[DIDInfo]: async def __get_indy_local_did( self, method: DIDMethod, key_type: KeyType, did: str ) -> DIDInfo: - if method not in [DIDMethod.SOV, DIDMethod.KEY]: + if method not in [SOV, KEY]: raise WalletError( f"Unsupported DID method for indy storage: {method.method_name}" ) - if key_type != KeyType.ED25519: + if key_type != ED25519: raise WalletError( f"Unsupported DID type for indy storage: {key_type.key_type}" ) # key type is always ed25519, method not always key - if method == DIDMethod.KEY and key_type == KeyType.ED25519: + if method == KEY and key_type == ED25519: did_key = DIDKey.from_did(did) # Ed25519 did:keys are masked indy dids so transform to indy @@ -517,11 +523,11 @@ async def __get_indy_local_did( async def __get_keypair_local_did( self, method: DIDMethod, key_type: KeyType, did: str ): - if method != DIDMethod.KEY: + if method != KEY: raise WalletError( f"Unsupported DID method for keypair storage: {method.method_name}" ) - if key_type != KeyType.BLS12381G2: + if key_type != BLS12381G2: raise WalletError( f"Unsupported DID type for keypair storage: {key_type.key_type}" ) @@ -548,15 +554,17 @@ async def get_local_did(self, did: str) -> DIDInfo: WalletError: If there is a libindy error """ - method = DIDMethod.from_did(did) - key_type = KeyType.ED25519 + # TODO: inject context for did method registry support + method_name = did.split(":")[1] if did.startswith("did:") else SOV.method_name + method = SOV if method_name == SOV.method_name else KEY + key_type = ED25519 # If did key, the key type can differ - if method == DIDMethod.KEY: + if method == KEY: did_key = DIDKey.from_did(did) key_type = did_key.key_type - if key_type == KeyType.ED25519: + if key_type == ED25519: return await self.__get_indy_local_did(method, key_type, did) else: return await self.__get_keypair_local_did(method, key_type, did) @@ -596,7 +604,7 @@ async def replace_local_did_metadata(self, did: str, metadata: dict): did_info = await self.get_local_did(did) # throw exception if undefined # ed25519 keys are handled by indy - if did_info.key_type == KeyType.ED25519: + if did_info.key_type == ED25519: try: await indy.did.set_did_metadata( self.opened.handle, did, json.dumps(metadata) @@ -679,7 +687,7 @@ async def set_public_did(self, did: Union[str, DIDInfo]) -> DIDInfo: else: info = did - if info.method != DIDMethod.SOV: + if info.method != SOV: raise WalletError("Setting public DID is only allowed for did:sov DIDs") public = await self.get_public_did() @@ -724,7 +732,7 @@ async def set_did_endpoint( 'endpoint' affects local wallet """ did_info = await self.get_local_did(did) - if did_info.method != DIDMethod.SOV: + if did_info.method != SOV: raise WalletError("Setting DID endpoint is only allowed for did:sov DIDs") metadata = {**did_info.metadata} @@ -785,7 +793,7 @@ async def sign_message(self, message: bytes, from_verkey: str) -> bytes: key_info = await self.get_local_did_for_verkey(from_verkey) # ed25519 keys are handled by indy - if key_info.key_type == KeyType.ED25519: + if key_info.key_type == ED25519: try: result = await indy.crypto.crypto_sign( self.opened.handle, from_verkey, message @@ -837,7 +845,7 @@ async def verify_message( raise WalletError("Message not provided") # ed25519 keys are handled by indy - if key_type == KeyType.ED25519: + if key_type == ED25519: try: result = await indy.crypto.crypto_verify( from_verkey, message, signature diff --git a/aries_cloudagent/wallet/key_type.py b/aries_cloudagent/wallet/key_type.py index 57defdb521..9e16bb1dde 100644 --- a/aries_cloudagent/wallet/key_type.py +++ b/aries_cloudagent/wallet/key_type.py @@ -1,78 +1,95 @@ -"""Key type enum.""" +"""Key type code.""" -from enum import Enum -from typing import NamedTuple, Optional +from typing import Optional -# Define keys -KeySpec = NamedTuple( - "KeySpec", - [("key_type", str), ("multicodec_name", str), ("multicodec_prefix", int)], -) +class KeyType: + """Key Type class.""" -class KeyTypeException(BaseException): - """Key type exception.""" - - -class KeyType(Enum): - """KeyType Enum specifying key types with multicodec name.""" - - # NOTE: the py_multicodec library is outdated. We use hardcoded prefixes here - # until this PR gets released: https://github.com/multiformats/py-multicodec/pull/14 - # multicodec is also not used now, but may be used again if py_multicodec is updated - ED25519 = KeySpec("ed25519", "ed25519-pub", b"\xed\x01") - X25519 = KeySpec("x25519", "x25519-pub", b"\xec\x01") - BLS12381G1 = KeySpec("bls12381g1", "bls12_381-g1-pub", b"\xea\x01") - BLS12381G2 = KeySpec("bls12381g2", "bls12_381-g2-pub", b"\xeb\x01") - BLS12381G1G2 = KeySpec("bls12381g1g2", "bls12_381-g1g2-pub", b"\xee\x01") + def __init__(self, key_type: str, multicodec_name: str, multicodec_prefix: bytes): + """Construct key type.""" + self._type: str = key_type + self._name: str = multicodec_name + self._prefix: bytes = multicodec_prefix @property def key_type(self) -> str: - """Getter for key type identifier.""" - return self.value.key_type + """Get Key type, type.""" + return self._type @property def multicodec_name(self) -> str: - """Getter for multicodec name.""" - return self.value.multicodec_name + """Get key type multicodec name.""" + return self._name @property def multicodec_prefix(self) -> bytes: - """Getter for multicodec prefix.""" - return self.value.multicodec_prefix - - @classmethod - def from_multicodec_name(cls, multicodec_name: str) -> Optional["KeyType"]: + """Get key type multicodec prefix.""" + return self._prefix + + +# NOTE: the py_multicodec library is outdated. We use hardcoded prefixes here +# until this PR gets released: https://github.com/multiformats/py-multicodec/pull/14 +# multicodec is also not used now, but may be used again if py_multicodec is updated +ED25519: KeyType = KeyType("ed25519", "ed25519-pub", b"\xed\x01") +X25519: KeyType = KeyType("x25519", "x25519-pub", b"\xec\x01") +BLS12381G1: KeyType = KeyType("bls12381g1", "bls12_381-g1-pub", b"\xea\x01") +BLS12381G2: KeyType = KeyType("bls12381g2", "bls12_381-g2-pub", b"\xeb\x01") +BLS12381G1G2: KeyType = KeyType("bls12381g1g2", "bls12_381-g1g2-pub", b"\xee\x01") + + +class KeyTypes: + """KeyType class specifying key types with multicodec name.""" + + def __init__(self) -> None: + """Construct key type registry.""" + self._type_registry: dict[str, KeyType] = { + ED25519.key_type: ED25519, + X25519.key_type: X25519, + BLS12381G1.key_type: BLS12381G1, + BLS12381G2.key_type: BLS12381G2, + BLS12381G1G2.key_type: BLS12381G1G2, + } + self._name_registry: dict[str, KeyType] = { + ED25519.multicodec_name: ED25519, + X25519.multicodec_name: X25519, + BLS12381G1.multicodec_name: BLS12381G1, + BLS12381G2.multicodec_name: BLS12381G2, + BLS12381G1G2.multicodec_name: BLS12381G1G2, + } + self._prefix_registry: dict[bytes, KeyType] = { + ED25519.multicodec_prefix: ED25519, + X25519.multicodec_prefix: X25519, + BLS12381G1.multicodec_prefix: BLS12381G1, + BLS12381G2.multicodec_prefix: BLS12381G2, + BLS12381G1G2.multicodec_prefix: BLS12381G1G2, + } + + def register(self, key_type: KeyType): + """Register a new key type.""" + self._type_registry[key_type.key_type] = key_type + self._name_registry[key_type.multicodec_name] = key_type + self._prefix_registry[key_type.multicodec_prefix] = key_type + + def from_multicodec_name(self, multicodec_name: str) -> Optional["KeyType"]: """Get KeyType instance based on multicodec name. Returns None if not found.""" - for key_type in KeyType: - if key_type.multicodec_name == multicodec_name: - return key_type - - return None + return self._name_registry.get(multicodec_name) - @classmethod - def from_multicodec_prefix(cls, multicodec_prefix: bytes) -> Optional["KeyType"]: + def from_multicodec_prefix(self, multicodec_prefix: bytes) -> Optional["KeyType"]: """Get KeyType instance based on multicodec prefix. Returns None if not found.""" - for key_type in KeyType: - if key_type.multicodec_prefix == multicodec_prefix: - return key_type + return self._prefix_registry.get(multicodec_prefix) - return None - - @classmethod - def from_prefixed_bytes(cls, prefixed_bytes: bytes) -> Optional["KeyType"]: + def from_prefixed_bytes(self, prefixed_bytes: bytes) -> Optional["KeyType"]: """Get KeyType instance based on prefix in bytes. Returns None if not found.""" - for key_type in KeyType: - if prefixed_bytes.startswith(key_type.multicodec_prefix): - return key_type - - return None - - @classmethod - def from_key_type(cls, key_type: str) -> Optional["KeyType"]: + return next( + ( + key_type + for key_type in self._name_registry.values() + if prefixed_bytes.startswith(key_type.multicodec_prefix) + ), + None, + ) + + def from_key_type(self, key_type: str) -> Optional["KeyType"]: """Get KeyType instance from the key type identifier.""" - for _key_type in KeyType: - if _key_type.key_type == key_type: - return _key_type - - return None + return self._type_registry.get(key_type) diff --git a/aries_cloudagent/wallet/routes.py b/aries_cloudagent/wallet/routes.py index 1a1610955f..1c038957dc 100644 --- a/aries_cloudagent/wallet/routes.py +++ b/aries_cloudagent/wallet/routes.py @@ -38,10 +38,10 @@ from ..storage.error import StorageError, StorageNotFoundError from .base import BaseWallet from .did_info import DIDInfo -from .did_method import DIDMethod +from .did_method import SOV, KEY, DIDMethod, DIDMethods from .did_posture import DIDPosture from .error import WalletError, WalletNotFoundError -from .key_type import KeyType +from .key_type import BLS12381G2, ED25519, KeyTypes from .util import EVENT_LISTENER_PATTERN LOGGER = logging.getLogger(__name__) @@ -66,15 +66,15 @@ class DIDSchema(OpenAPISchema): ) method = fields.Str( description="Did method associated with the DID", - example=DIDMethod.SOV.method_name, - validate=validate.OneOf([method.method_name for method in DIDMethod]), + example=SOV.method_name, + validate=validate.OneOf( + [method.method_name for method in [SOV, KEY]] + ), # TODO: support more methods ) key_type = fields.Str( description="Key type associated with the DID", - example=KeyType.ED25519.key_type, - validate=validate.OneOf( - [KeyType.ED25519.key_type, KeyType.BLS12381G2.key_type] - ), + example=ED25519.key_type, + validate=validate.OneOf([ED25519.key_type, BLS12381G2.key_type]), ) @@ -136,16 +136,14 @@ class DIDListQueryStringSchema(OpenAPISchema): ) method = fields.Str( required=False, - example=DIDMethod.KEY.method_name, - validate=validate.OneOf([DIDMethod.KEY.method_name, DIDMethod.SOV.method_name]), + example=KEY.method_name, + validate=validate.OneOf([KEY.method_name, SOV.method_name]), description="DID method to query for. e.g. sov to only fetch indy/sov DIDs", ) key_type = fields.Str( required=False, - example=KeyType.ED25519.key_type, - validate=validate.OneOf( - [KeyType.ED25519.key_type, KeyType.BLS12381G2.key_type] - ), + example=ED25519.key_type, + validate=validate.OneOf([ED25519.key_type, BLS12381G2.key_type]), description="Key type to query for.", ) @@ -161,10 +159,8 @@ class DIDCreateOptionsSchema(OpenAPISchema): key_type = fields.Str( required=True, - example=KeyType.ED25519.key_type, - validate=validate.OneOf( - [KeyType.ED25519.key_type, KeyType.BLS12381G2.key_type] - ), + example=ED25519.key_type, + validate=validate.OneOf([ED25519.key_type, BLS12381G2.key_type]), ) @@ -173,9 +169,9 @@ class DIDCreateSchema(OpenAPISchema): method = fields.Str( required=False, - default=DIDMethod.SOV.method_name, - example=DIDMethod.SOV.method_name, - validate=validate.OneOf([DIDMethod.KEY.method_name, DIDMethod.SOV.method_name]), + default=SOV.method_name, + example=SOV.method_name, + validate=validate.OneOf([KEY.method_name, SOV.method_name]), ) options = fields.Nested( @@ -244,12 +240,16 @@ async def wallet_did_list(request: web.BaseRequest): context: AdminRequestContext = request["context"] filter_did = request.query.get("did") filter_verkey = request.query.get("verkey") - filter_method = DIDMethod.from_method(request.query.get("method")) filter_posture = DIDPosture.get(request.query.get("posture")) - filter_key_type = KeyType.from_key_type(request.query.get("key_type")) results = [] async with context.session() as session: - wallet = session.inject_or(BaseWallet) + did_methods: DIDMethods = session.inject(DIDMethods) + filter_method: DIDMethod | None = did_methods.from_method( + request.query.get("method") + ) + key_types = session.inject(KeyTypes) + filter_key_type = key_types.from_key_type(request.query.get("key_type", "")) + wallet: BaseWallet | None = session.inject_or(BaseWallet) if not wallet: raise web.HTTPForbidden(reason="No wallet available") if filter_posture is DIDPosture.PUBLIC: @@ -353,24 +353,27 @@ async def wallet_create_did(request: web.BaseRequest): body = {} # set default method and key type for backwards compat - key_type = ( - KeyType.from_key_type(body.get("options", {}).get("key_type")) - or KeyType.ED25519 - ) - method = DIDMethod.from_method(body.get("method")) or DIDMethod.SOV - if not method.supports_key_type(key_type): - raise web.HTTPForbidden( - reason=( - f"method {method.method_name} does not" - f" support key type {key_type.key_type}" - ) - ) seed = body.get("seed") or None if seed and not context.settings.get("wallet.allow_insecure_seed"): raise web.HTTPBadRequest(reason="Seed support is not enabled") info = None async with context.session() as session: + did_methods = session.inject(DIDMethods) + method = did_methods.from_method(body.get("method", "")) or SOV + key_types = session.inject(KeyTypes) + # set default method and key type for backwards compat + key_type = ( + key_types.from_key_type(body.get("options", {}).get("key_type", "")) + or ED25519 + ) + if not method.supports_key_type(key_type): + raise web.HTTPForbidden( + reason=( + f"method {method.method_name} does not" + f" support key type {key_type.key_type}" + ) + ) wallet = session.inject_or(BaseWallet) if not wallet: raise web.HTTPForbidden(reason="No wallet available") diff --git a/aries_cloudagent/wallet/tests/test_crypto.py b/aries_cloudagent/wallet/tests/test_crypto.py index 66f6fc770a..43b0d03452 100644 --- a/aries_cloudagent/wallet/tests/test_crypto.py +++ b/aries_cloudagent/wallet/tests/test_crypto.py @@ -3,7 +3,7 @@ from unittest import mock, TestCase -from ..key_type import KeyType +from ..key_type import BLS12381G1, ED25519 from ..error import WalletError from ...utils.jwe import JweRecipient from ..util import str_to_b64 @@ -32,9 +32,7 @@ def test_validate_seed(self): def test_seeds_keys(self): assert len(test_module.seed_to_did(SEED)) in (22, 23) - (public_key, secret_key) = test_module.create_keypair( - test_module.KeyType.ED25519 - ) + (public_key, secret_key) = test_module.create_keypair(test_module.ED25519) assert public_key assert secret_key @@ -156,28 +154,24 @@ def test_extract_pack_recipients_x(self): def test_sign_ed25519_x_multiple_messages(self): with self.assertRaises(WalletError) as context: - test_module.sign_message( - [b"message1", b"message2"], b"secret", KeyType.ED25519 - ) + test_module.sign_message([b"message1", b"message2"], b"secret", ED25519) assert "ed25519 can only sign a single message" in str(context.exception) def test_sign_x_unsupported_key_type(self): with self.assertRaises(WalletError) as context: - test_module.sign_message( - [b"message1", b"message2"], b"secret", KeyType.BLS12381G1 - ) + test_module.sign_message([b"message1", b"message2"], b"secret", BLS12381G1) assert "Unsupported key type: bls12381g1" in str(context.exception) def test_verify_ed25519_x_multiple_messages(self): with self.assertRaises(WalletError) as context: test_module.verify_signed_message( - [b"message1", b"message2"], b"signature", b"verkey", KeyType.ED25519 + [b"message1", b"message2"], b"signature", b"verkey", ED25519 ) assert "ed25519 can only verify a single message" in str(context.exception) def test_verify_x_unsupported_key_type(self): with self.assertRaises(WalletError) as context: test_module.verify_signed_message( - [b"message1", b"message2"], b"signature", b"verkey", KeyType.BLS12381G1 + [b"message1", b"message2"], b"signature", b"verkey", BLS12381G1 ) assert "Unsupported key type: bls12381g1" in str(context.exception) diff --git a/aries_cloudagent/wallet/tests/test_did_method.py b/aries_cloudagent/wallet/tests/test_did_method.py index 2134d01555..a952844383 100644 --- a/aries_cloudagent/wallet/tests/test_did_method.py +++ b/aries_cloudagent/wallet/tests/test_did_method.py @@ -1,7 +1,7 @@ from unittest import TestCase -from ..key_type import KeyType +from ..key_type import BLS12381G1, BLS12381G1G2, BLS12381G2, ED25519, X25519, KeyTypes ED25519_PREFIX_BYTES = b"\xed\x01" BLS12381G1_PREFIX_BYTES = b"\xea\x01" @@ -24,89 +24,77 @@ class TestKeyType(TestCase): def test_from_multicodec_name(self): - - assert KeyType.from_multicodec_name(ED25519_MULTICODEC_NAME) == KeyType.ED25519 - assert KeyType.from_multicodec_name(X25519_MULTICODEC_NAME) == KeyType.X25519 - assert ( - KeyType.from_multicodec_name(BLS12381G1_MULTICODEC_NAME) - == KeyType.BLS12381G1 - ) + key_types = KeyTypes() + assert key_types.from_multicodec_name(ED25519_MULTICODEC_NAME) == ED25519 + assert key_types.from_multicodec_name(X25519_MULTICODEC_NAME) == X25519 + assert key_types.from_multicodec_name(BLS12381G1_MULTICODEC_NAME) == BLS12381G1 + assert key_types.from_multicodec_name(BLS12381G2_MULTICODEC_NAME) == BLS12381G2 assert ( - KeyType.from_multicodec_name(BLS12381G2_MULTICODEC_NAME) - == KeyType.BLS12381G2 + key_types.from_multicodec_name(BLS12381G1G2_MULTICODEC_NAME) == BLS12381G1G2 ) - assert ( - KeyType.from_multicodec_name(BLS12381G1G2_MULTICODEC_NAME) - == KeyType.BLS12381G1G2 - ) - assert KeyType.from_multicodec_name("non-existing") == None + assert key_types.from_multicodec_name("non-existing") == None def test_from_key_type(self): - - assert KeyType.from_key_type(ED25519_KEY_NAME) == KeyType.ED25519 - assert KeyType.from_key_type(X25519_KEY_NAME) == KeyType.X25519 - assert KeyType.from_key_type(BLS12381G1_KEY_NAME) == KeyType.BLS12381G1 - assert KeyType.from_key_type(BLS12381G2_KEY_NAME) == KeyType.BLS12381G2 - assert KeyType.from_key_type(BLS12381G1G2_KEY_NAME) == KeyType.BLS12381G1G2 - assert KeyType.from_key_type("non-existing") == None + key_types = KeyTypes() + assert key_types.from_key_type(ED25519_KEY_NAME) == ED25519 + assert key_types.from_key_type(X25519_KEY_NAME) == X25519 + assert key_types.from_key_type(BLS12381G1_KEY_NAME) == BLS12381G1 + assert key_types.from_key_type(BLS12381G2_KEY_NAME) == BLS12381G2 + assert key_types.from_key_type(BLS12381G1G2_KEY_NAME) == BLS12381G1G2 + assert key_types.from_key_type("non-existing") == None def test_from_multicodec_prefix(self): - - assert KeyType.from_multicodec_prefix(ED25519_PREFIX_BYTES) == KeyType.ED25519 - assert KeyType.from_multicodec_prefix(X25519_PREFIX_BYTES) == KeyType.X25519 + key_types = KeyTypes() + assert key_types.from_multicodec_prefix(ED25519_PREFIX_BYTES) == ED25519 + assert key_types.from_multicodec_prefix(X25519_PREFIX_BYTES) == X25519 + assert key_types.from_multicodec_prefix(BLS12381G1_PREFIX_BYTES) == BLS12381G1 + assert key_types.from_multicodec_prefix(BLS12381G2_PREFIX_BYTES) == BLS12381G2 assert ( - KeyType.from_multicodec_prefix(BLS12381G1_PREFIX_BYTES) - == KeyType.BLS12381G1 + key_types.from_multicodec_prefix(BLS12381G1G2_PREFIX_BYTES) == BLS12381G1G2 ) - assert ( - KeyType.from_multicodec_prefix(BLS12381G2_PREFIX_BYTES) - == KeyType.BLS12381G2 - ) - assert ( - KeyType.from_multicodec_prefix(BLS12381G1G2_PREFIX_BYTES) - == KeyType.BLS12381G1G2 - ) - assert KeyType.from_multicodec_prefix(b"\xef\x01") == None + assert key_types.from_multicodec_prefix(b"\xef\x01") == None def test_from_prefixed_bytes(self): - + key_types = KeyTypes() assert ( - KeyType.from_prefixed_bytes( + key_types.from_prefixed_bytes( b"".join([ED25519_PREFIX_BYTES, b"random-bytes"]) ) - == KeyType.ED25519 + == ED25519 ) assert ( - KeyType.from_prefixed_bytes( + key_types.from_prefixed_bytes( b"".join([X25519_PREFIX_BYTES, b"random-bytes"]) ) - == KeyType.X25519 + == X25519 ) assert ( - KeyType.from_prefixed_bytes( + key_types.from_prefixed_bytes( b"".join([BLS12381G1_PREFIX_BYTES, b"random-bytes"]) ) - == KeyType.BLS12381G1 + == BLS12381G1 ) assert ( - KeyType.from_prefixed_bytes( + key_types.from_prefixed_bytes( b"".join([BLS12381G2_PREFIX_BYTES, b"random-bytes"]) ) - == KeyType.BLS12381G2 + == BLS12381G2 ) assert ( - KeyType.from_prefixed_bytes( + key_types.from_prefixed_bytes( b"".join([BLS12381G1G2_PREFIX_BYTES, b"random-bytes"]) ) - == KeyType.BLS12381G1G2 + == BLS12381G1G2 ) assert ( - KeyType.from_prefixed_bytes(b"".join([b"\xef\x01", b"other-random-bytes"])) + key_types.from_prefixed_bytes( + b"".join([b"\xef\x01", b"other-random-bytes"]) + ) == None ) def test_properties(self): - key_type = KeyType.ED25519 + key_type = ED25519 assert key_type.key_type == ED25519_KEY_NAME assert key_type.multicodec_name == ED25519_MULTICODEC_NAME diff --git a/aries_cloudagent/wallet/tests/test_in_memory_wallet.py b/aries_cloudagent/wallet/tests/test_in_memory_wallet.py index 6554336908..ecb3c97263 100644 --- a/aries_cloudagent/wallet/tests/test_in_memory_wallet.py +++ b/aries_cloudagent/wallet/tests/test_in_memory_wallet.py @@ -1,16 +1,13 @@ -import pytest import time +import pytest + from ...core.in_memory import InMemoryProfile from ...messaging.decorators.signature_decorator import SignatureDecorator +from ...wallet.did_method import KEY, SOV, DIDMethods +from ...wallet.error import WalletDuplicateError, WalletError, WalletNotFoundError from ...wallet.in_memory import InMemoryWallet -from ...wallet.key_type import KeyType -from ...wallet.did_method import DIDMethod -from ...wallet.error import ( - WalletError, - WalletDuplicateError, - WalletNotFoundError, -) +from ...wallet.key_type import BLS12381G1, BLS12381G1G2, BLS12381G2, ED25519, X25519 @pytest.fixture() @@ -45,56 +42,56 @@ class TestInMemoryWallet: @pytest.mark.asyncio async def test_create_signing_key_ed25519_random(self, wallet: InMemoryWallet): assert str(wallet) - info = await wallet.create_signing_key(KeyType.ED25519) + info = await wallet.create_signing_key(ED25519) assert info and info.verkey @pytest.mark.asyncio @pytest.mark.ursa_bbs_signatures async def test_create_signing_key_bls12381g2_random(self, wallet: InMemoryWallet): assert str(wallet) - info = await wallet.create_signing_key(KeyType.BLS12381G2) + info = await wallet.create_signing_key(BLS12381G2) assert info and info.verkey @pytest.mark.asyncio async def test_create_signing_key_ed25519_seeded(self, wallet: InMemoryWallet): - info = await wallet.create_signing_key(KeyType.ED25519, self.test_seed) + info = await wallet.create_signing_key(ED25519, self.test_seed) assert info.verkey == self.test_ed25519_verkey with pytest.raises(WalletDuplicateError): - await wallet.create_signing_key(KeyType.ED25519, self.test_seed) + await wallet.create_signing_key(ED25519, self.test_seed) with pytest.raises(WalletError): - await wallet.create_signing_key(KeyType.ED25519, "invalid-seed", None) + await wallet.create_signing_key(ED25519, "invalid-seed", None) @pytest.mark.asyncio @pytest.mark.ursa_bbs_signatures async def test_create_signing_key_bls12381g2_seeded(self, wallet: InMemoryWallet): - info = await wallet.create_signing_key(KeyType.BLS12381G2, self.test_seed) + info = await wallet.create_signing_key(BLS12381G2, self.test_seed) assert info.verkey == self.test_bls12381g2_verkey with pytest.raises(WalletDuplicateError): - await wallet.create_signing_key(KeyType.BLS12381G2, self.test_seed) + await wallet.create_signing_key(BLS12381G2, self.test_seed) with pytest.raises(WalletError): - await wallet.create_signing_key(KeyType.BLS12381G2, "invalid-seed", None) + await wallet.create_signing_key(BLS12381G2, "invalid-seed", None) @pytest.mark.asyncio async def test_create_signing_key_unsupported_key_type( self, wallet: InMemoryWallet ): with pytest.raises(WalletError): - await wallet.create_signing_key(KeyType.X25519) + await wallet.create_signing_key(X25519) with pytest.raises(WalletError): - await wallet.create_signing_key(KeyType.BLS12381G1) + await wallet.create_signing_key(BLS12381G1) with pytest.raises(WalletError): - await wallet.create_signing_key(KeyType.BLS12381G1G2) + await wallet.create_signing_key(BLS12381G1G2) @pytest.mark.asyncio async def test_signing_key_metadata(self, wallet: InMemoryWallet): info = await wallet.create_signing_key( - KeyType.ED25519, self.test_seed, self.test_metadata + ED25519, self.test_seed, self.test_metadata ) assert info.metadata == self.test_metadata info2 = await wallet.get_signing_key(self.test_ed25519_verkey) @@ -117,7 +114,7 @@ async def test_signing_key_metadata(self, wallet: InMemoryWallet): @pytest.mark.ursa_bbs_signatures async def test_signing_key_metadata_bls(self, wallet: InMemoryWallet): info = await wallet.create_signing_key( - KeyType.BLS12381G2, self.test_seed, self.test_metadata + BLS12381G2, self.test_seed, self.test_metadata ) assert info.metadata == self.test_metadata info2 = await wallet.get_signing_key(self.test_bls12381g2_verkey) @@ -130,20 +127,18 @@ async def test_signing_key_metadata_bls(self, wallet: InMemoryWallet): @pytest.mark.asyncio async def test_create_local_sov_random(self, wallet: InMemoryWallet): - info = await wallet.create_local_did(DIDMethod.SOV, KeyType.ED25519, None, None) + info = await wallet.create_local_did(SOV, ED25519, None, None) assert info and info.did and info.verkey @pytest.mark.asyncio async def test_create_local_key_random_ed25519(self, wallet: InMemoryWallet): - info = await wallet.create_local_did(DIDMethod.KEY, KeyType.ED25519, None, None) + info = await wallet.create_local_did(KEY, ED25519, None, None) assert info and info.did and info.verkey @pytest.mark.asyncio @pytest.mark.ursa_bbs_signatures async def test_create_local_key_random_bls12381g2(self, wallet: InMemoryWallet): - info = await wallet.create_local_did( - DIDMethod.KEY, KeyType.BLS12381G2, None, None - ) + info = await wallet.create_local_did(KEY, BLS12381G2, None, None) assert info and info.did and info.verkey @pytest.mark.asyncio @@ -151,65 +146,49 @@ async def test_create_local_incorrect_key_type_for_did_method( self, wallet: InMemoryWallet ): with pytest.raises(WalletError): - await wallet.create_local_did(DIDMethod.SOV, KeyType.BLS12381G2, None, None) + await wallet.create_local_did(SOV, BLS12381G2, None, None) @pytest.mark.asyncio async def test_create_local_sov_seeded(self, wallet: InMemoryWallet): - info = await wallet.create_local_did( - DIDMethod.SOV, KeyType.ED25519, self.test_seed, None - ) + info = await wallet.create_local_did(SOV, ED25519, self.test_seed, None) assert info.did == self.test_sov_did assert info.verkey == self.test_ed25519_verkey # should not raise WalletDuplicateError - same verkey - await wallet.create_local_did( - DIDMethod.SOV, KeyType.ED25519, self.test_seed, None - ) + await wallet.create_local_did(SOV, ED25519, self.test_seed, None) with pytest.raises(WalletError): - _ = await wallet.create_local_did( - DIDMethod.SOV, KeyType.ED25519, "invalid-seed", None - ) + _ = await wallet.create_local_did(SOV, ED25519, "invalid-seed", None) @pytest.mark.asyncio @pytest.mark.ursa_bbs_signatures async def test_create_local_key_seeded_bls12381g2(self, wallet: InMemoryWallet): - info = await wallet.create_local_did( - DIDMethod.KEY, KeyType.BLS12381G2, self.test_seed, None - ) + info = await wallet.create_local_did(KEY, BLS12381G2, self.test_seed, None) assert info.did == self.test_key_bls12381g2_did assert info.verkey == self.test_bls12381g2_verkey # should not raise WalletDuplicateError - same verkey - await wallet.create_local_did( - DIDMethod.KEY, KeyType.BLS12381G2, self.test_seed, None - ) + await wallet.create_local_did(KEY, BLS12381G2, self.test_seed, None) with pytest.raises(WalletError): - _ = await wallet.create_local_did( - DIDMethod.KEY, KeyType.BLS12381G2, "invalid-seed", None - ) + _ = await wallet.create_local_did(KEY, BLS12381G2, "invalid-seed", None) @pytest.mark.asyncio async def test_create_local_key_seeded_ed25519(self, wallet: InMemoryWallet): - info = await wallet.create_local_did( - DIDMethod.KEY, KeyType.ED25519, self.test_seed, None - ) + info = await wallet.create_local_did(KEY, ED25519, self.test_seed, None) assert info.did == self.test_key_ed25519_did assert info.verkey == self.test_ed25519_verkey # should not raise WalletDuplicateError - same verkey - await wallet.create_local_did( - DIDMethod.KEY, KeyType.ED25519, self.test_seed, None - ) + await wallet.create_local_did(KEY, ED25519, self.test_seed, None) with pytest.raises(WalletError): - _ = await wallet.create_local_did( - DIDMethod.KEY, KeyType.ED25519, "invalid-seed", None - ) + _ = await wallet.create_local_did(KEY, ED25519, "invalid-seed", None) @pytest.mark.asyncio async def test_rotate_did_keypair(self, wallet: InMemoryWallet): + if hasattr(wallet, "profile"): # check incase indysdkwallet is being used + wallet.profile.context.injector.bind_instance(DIDMethods, DIDMethods()) with pytest.raises(WalletNotFoundError): await wallet.rotate_did_keypair_start(self.test_sov_did) @@ -217,9 +196,9 @@ async def test_rotate_did_keypair(self, wallet: InMemoryWallet): await wallet.rotate_did_keypair_apply(self.test_sov_did) info = await wallet.create_local_did( - DIDMethod.SOV, KeyType.ED25519, self.test_seed, self.test_sov_did + SOV, ED25519, self.test_seed, self.test_sov_did ) - key_info = await wallet.create_local_did(DIDMethod.KEY, KeyType.ED25519) + key_info = await wallet.create_local_did(KEY, ED25519) with pytest.raises(WalletError): await wallet.rotate_did_keypair_apply(self.test_sov_did) @@ -238,26 +217,20 @@ async def test_rotate_did_keypair(self, wallet: InMemoryWallet): @pytest.mark.asyncio async def test_create_local_with_did(self, wallet: InMemoryWallet): - info = await wallet.create_local_did( - DIDMethod.SOV, KeyType.ED25519, None, self.test_sov_did - ) + info = await wallet.create_local_did(SOV, ED25519, None, self.test_sov_did) assert info.did == self.test_sov_did with pytest.raises(WalletDuplicateError): - await wallet.create_local_did( - DIDMethod.SOV, KeyType.ED25519, None, self.test_sov_did - ) + await wallet.create_local_did(SOV, ED25519, None, self.test_sov_did) with pytest.raises(WalletError) as context: - await wallet.create_local_did( - DIDMethod.KEY, KeyType.ED25519, None, "did:sov:random" - ) + await wallet.create_local_did(KEY, ED25519, None, "did:sov:random") assert "Not allowed to set DID for DID method 'key'" in str(context.value) @pytest.mark.asyncio async def test_local_verkey(self, wallet: InMemoryWallet): info = await wallet.create_local_did( - DIDMethod.SOV, KeyType.ED25519, self.test_seed, self.test_sov_did + SOV, ED25519, self.test_seed, self.test_sov_did ) assert info.did == self.test_sov_did assert info.verkey == self.test_ed25519_verkey @@ -273,7 +246,7 @@ async def test_local_verkey(self, wallet: InMemoryWallet): @pytest.mark.asyncio @pytest.mark.ursa_bbs_signatures async def test_local_verkey_bls12381g2(self, wallet: InMemoryWallet): - await wallet.create_local_did(DIDMethod.KEY, KeyType.BLS12381G2, self.test_seed) + await wallet.create_local_did(KEY, BLS12381G2, self.test_seed) bls_info_get = await wallet.get_local_did_for_verkey( self.test_bls12381g2_verkey ) @@ -288,8 +261,8 @@ async def test_local_verkey_bls12381g2(self, wallet: InMemoryWallet): @pytest.mark.asyncio async def test_local_metadata(self, wallet: InMemoryWallet): info = await wallet.create_local_did( - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, self.test_seed, self.test_sov_did, self.test_metadata, @@ -318,8 +291,8 @@ async def test_local_metadata(self, wallet: InMemoryWallet): @pytest.mark.ursa_bbs_signatures async def test_local_metadata_bbs(self, wallet: InMemoryWallet): info = await wallet.create_local_did( - DIDMethod.KEY, - KeyType.BLS12381G2, + KEY, + BLS12381G2, self.test_seed, None, self.test_metadata, @@ -338,8 +311,8 @@ async def test_local_metadata_bbs(self, wallet: InMemoryWallet): @pytest.mark.asyncio async def test_create_public_did(self, wallet: InMemoryWallet): info = await wallet.create_local_did( - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, self.test_seed, self.test_sov_did, self.test_metadata, @@ -350,8 +323,8 @@ async def test_create_public_did(self, wallet: InMemoryWallet): assert not posted info_public = await wallet.create_public_did( - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) assert info_public.metadata.get("posted") posted = await wallet.get_posted_dids() @@ -359,8 +332,8 @@ async def test_create_public_did(self, wallet: InMemoryWallet): # test replace info_replace = await wallet.create_public_did( - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) assert info_replace.metadata.get("posted") info_check = await wallet.get_local_did(info_public.did) @@ -376,8 +349,8 @@ async def test_create_public_did(self, wallet: InMemoryWallet): async def test_create_public_did_x_not_sov(self, wallet: InMemoryWallet): with pytest.raises(WalletError) as context: await wallet.create_public_did( - DIDMethod.KEY, - KeyType.ED25519, + KEY, + ED25519, ) assert "Setting public DID is only allowed for did:sov DIDs" in str( context.value @@ -389,16 +362,16 @@ async def test_create_public_did_x_unsupported_key_type_method( ): with pytest.raises(WalletError) as context: await wallet.create_public_did( - DIDMethod.SOV, - KeyType.BLS12381G2, + SOV, + BLS12381G2, ) assert "Invalid key type" in str(context.value) @pytest.mark.asyncio async def test_set_public_did(self, wallet: InMemoryWallet): info = await wallet.create_local_did( - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, self.test_seed, self.test_sov_did, self.test_metadata, @@ -413,7 +386,7 @@ async def test_set_public_did(self, wallet: InMemoryWallet): assert info_same.did == info.did assert info_same.metadata.get("posted") - info_new = await wallet.create_local_did(DIDMethod.SOV, KeyType.ED25519) + info_new = await wallet.create_local_did(SOV, ED25519) assert info_new.did != info_same.did loc = await wallet.get_local_did(self.test_sov_did) @@ -429,8 +402,8 @@ async def test_set_public_did(self, wallet: InMemoryWallet): @pytest.mark.asyncio async def test_set_public_did_x_not_sov(self, wallet: InMemoryWallet): info = await wallet.create_local_did( - DIDMethod.KEY, - KeyType.ED25519, + KEY, + ED25519, ) with pytest.raises(WalletError) as context: await wallet.set_public_did(info.did) @@ -441,28 +414,24 @@ async def test_set_public_did_x_not_sov(self, wallet: InMemoryWallet): @pytest.mark.asyncio async def test_sign_verify(self, wallet: InMemoryWallet): info = await wallet.create_local_did( - DIDMethod.SOV, KeyType.ED25519, self.test_seed, self.test_sov_did + SOV, ED25519, self.test_seed, self.test_sov_did ) message_bin = self.test_message.encode("ascii") signature = await wallet.sign_message(message_bin, info.verkey) assert signature == self.test_signature verify = await wallet.verify_message( - message_bin, signature, info.verkey, KeyType.ED25519 + message_bin, signature, info.verkey, ED25519 ) assert verify bad_sig = b"x" + signature[1:] - verify = await wallet.verify_message( - message_bin, bad_sig, info.verkey, KeyType.ED25519 - ) + verify = await wallet.verify_message(message_bin, bad_sig, info.verkey, ED25519) assert not verify bad_msg = b"x" + message_bin[1:] - verify = await wallet.verify_message( - bad_msg, signature, info.verkey, KeyType.ED25519 - ) + verify = await wallet.verify_message(bad_msg, signature, info.verkey, ED25519) assert not verify verify = await wallet.verify_message( - message_bin, signature, self.test_target_verkey, KeyType.ED25519 + message_bin, signature, self.test_target_verkey, ED25519 ) assert not verify @@ -478,46 +447,44 @@ async def test_sign_verify(self, wallet: InMemoryWallet): assert "Verkey not provided" in str(excinfo.value) with pytest.raises(WalletError) as excinfo: - await wallet.verify_message(message_bin, signature, None, KeyType.ED25519) + await wallet.verify_message(message_bin, signature, None, ED25519) assert "Verkey not provided" in str(excinfo.value) with pytest.raises(WalletError) as excinfo: - await wallet.verify_message(message_bin, None, info.verkey, KeyType.ED25519) + await wallet.verify_message(message_bin, None, info.verkey, ED25519) assert "Signature not provided" in str(excinfo.value) with pytest.raises(WalletError) as excinfo: - await wallet.verify_message(None, message_bin, info.verkey, KeyType.ED25519) + await wallet.verify_message(None, message_bin, info.verkey, ED25519) assert "Message not provided" in str(excinfo.value) @pytest.mark.asyncio @pytest.mark.ursa_bbs_signatures async def test_sign_verify_bbs(self, wallet: InMemoryWallet): - info = await wallet.create_local_did( - DIDMethod.KEY, KeyType.BLS12381G2, self.test_seed - ) + info = await wallet.create_local_did(KEY, BLS12381G2, self.test_seed) message_bin = self.test_message.encode("ascii") signature = await wallet.sign_message(message_bin, info.verkey) assert signature verify = await wallet.verify_message( - message_bin, signature, info.verkey, KeyType.BLS12381G2 + message_bin, signature, info.verkey, BLS12381G2 ) assert verify bad_msg = b"x" + message_bin[1:] verify = await wallet.verify_message( - bad_msg, signature, info.verkey, KeyType.BLS12381G2 + bad_msg, signature, info.verkey, BLS12381G2 ) assert not verify with pytest.raises(WalletError): bad_sig = b"x" + signature[1:] verify = await wallet.verify_message( - message_bin, bad_sig, info.verkey, KeyType.BLS12381G2 + message_bin, bad_sig, info.verkey, BLS12381G2 ) with pytest.raises(WalletError): await wallet.verify_message( - message_bin, signature, self.test_target_verkey, KeyType.BLS12381G2 + message_bin, signature, self.test_target_verkey, BLS12381G2 ) with pytest.raises(WalletError): @@ -532,28 +499,20 @@ async def test_sign_verify_bbs(self, wallet: InMemoryWallet): assert "Verkey not provided" in str(excinfo.value) with pytest.raises(WalletError) as excinfo: - await wallet.verify_message( - message_bin, signature, None, KeyType.BLS12381G2 - ) + await wallet.verify_message(message_bin, signature, None, BLS12381G2) assert "Verkey not provided" in str(excinfo.value) with pytest.raises(WalletError) as excinfo: - await wallet.verify_message( - message_bin, None, info.verkey, KeyType.BLS12381G2 - ) + await wallet.verify_message(message_bin, None, info.verkey, BLS12381G2) assert "Signature not provided" in str(excinfo.value) with pytest.raises(WalletError) as excinfo: - await wallet.verify_message( - None, message_bin, info.verkey, KeyType.BLS12381G2 - ) + await wallet.verify_message(None, message_bin, info.verkey, BLS12381G2) assert "Message not provided" in str(excinfo.value) @pytest.mark.asyncio async def test_pack_unpack(self, wallet: InMemoryWallet): - await wallet.create_local_did( - DIDMethod.SOV, KeyType.ED25519, self.test_seed, self.test_sov_did - ) + await wallet.create_local_did(SOV, ED25519, self.test_seed, self.test_sov_did) packed_anon = await wallet.pack_message( self.test_message, [self.test_ed25519_verkey] @@ -568,7 +527,7 @@ async def test_pack_unpack(self, wallet: InMemoryWallet): assert "Message not provided" in str(excinfo.value) await wallet.create_local_did( - DIDMethod.SOV, KeyType.ED25519, self.test_target_seed, self.test_target_did + SOV, ED25519, self.test_target_seed, self.test_target_did ) packed_auth = await wallet.pack_message( self.test_message, [self.test_target_verkey], self.test_ed25519_verkey @@ -587,7 +546,7 @@ async def test_pack_unpack(self, wallet: InMemoryWallet): @pytest.mark.asyncio async def test_signature_round_trip(self, wallet: InMemoryWallet): - key_info = await wallet.create_signing_key(KeyType.ED25519) + key_info = await wallet.create_signing_key(ED25519) msg = {"test": "signed field"} timestamp = int(time.time()) sig = await SignatureDecorator.create(msg, key_info.verkey, wallet, timestamp) @@ -600,8 +559,8 @@ async def test_signature_round_trip(self, wallet: InMemoryWallet): @pytest.mark.asyncio async def test_set_did_endpoint_x_not_sov(self, wallet: InMemoryWallet): info = await wallet.create_local_did( - DIDMethod.KEY, - KeyType.ED25519, + KEY, + ED25519, ) with pytest.raises(WalletError) as context: await wallet.set_did_endpoint( diff --git a/aries_cloudagent/wallet/tests/test_indy_wallet.py b/aries_cloudagent/wallet/tests/test_indy_wallet.py index 6044a6a658..8dfe821e58 100644 --- a/aries_cloudagent/wallet/tests/test_indy_wallet.py +++ b/aries_cloudagent/wallet/tests/test_indy_wallet.py @@ -7,25 +7,22 @@ import indy.did import indy.wallet import pytest - from asynctest import mock as async_mock -from ...core.in_memory import InMemoryProfile from ...config.injection_context import InjectionContext -from ...core.error import ProfileError, ProfileDuplicateError, ProfileNotFoundError +from ...core.error import ProfileDuplicateError, ProfileError, ProfileNotFoundError +from ...core.in_memory import InMemoryProfile from ...indy.sdk import wallet_setup as test_setup_module from ...indy.sdk.profile import IndySdkProfile, IndySdkProfileManager from ...indy.sdk.wallet_setup import IndyWalletConfig from ...ledger.endpoint_type import EndpointType -from ...wallet.key_type import KeyType -from ...wallet.did_method import DIDMethod from ...ledger.indy import IndySdkLedgerPool - +from ...wallet.did_method import SOV +from ...wallet.key_type import ED25519 from .. import indy as test_module from ..base import BaseWallet from ..in_memory import InMemoryWallet from ..indy import IndySdkWallet - from . import test_in_memory_wallet @@ -67,7 +64,7 @@ class TestIndySdkWallet(test_in_memory_wallet.TestInMemoryWallet): @pytest.mark.asyncio async def test_rotate_did_keypair_x(self, wallet: IndySdkWallet): info = await wallet.create_local_did( - DIDMethod.SOV, KeyType.ED25519, self.test_seed, self.test_sov_did + SOV, ED25519, self.test_seed, self.test_sov_did ) with async_mock.patch.object( @@ -99,7 +96,7 @@ async def test_create_signing_key_x(self, wallet: IndySdkWallet): test_module.ErrorCode.CommonIOError, {"message": "outlier"} ) with pytest.raises(test_module.WalletError) as excinfo: - await wallet.create_signing_key(KeyType.ED25519) + await wallet.create_signing_key(ED25519) assert "outlier" in str(excinfo.value) @pytest.mark.asyncio @@ -111,7 +108,7 @@ async def test_create_local_did_x(self, wallet: IndySdkWallet): test_module.ErrorCode.CommonIOError, {"message": "outlier"} ) with pytest.raises(test_module.WalletError) as excinfo: - await wallet.create_local_did(DIDMethod.SOV, KeyType.ED25519) + await wallet.create_local_did(SOV, ED25519) assert "outlier" in str(excinfo.value) @pytest.mark.asyncio @@ -120,8 +117,8 @@ async def test_set_did_endpoint_ledger(self, wallet: IndySdkWallet): read_only=False, update_endpoint_for_did=async_mock.CoroutineMock() ) info_pub = await wallet.create_public_did( - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) await wallet.set_did_endpoint(info_pub.did, "https://example.com", mock_ledger) mock_ledger.update_endpoint_for_did.assert_called_once_with( @@ -147,7 +144,7 @@ async def test_set_did_endpoint_ledger_with_routing_keys( mock_ledger = async_mock.MagicMock( read_only=False, update_endpoint_for_did=async_mock.CoroutineMock() ) - info_pub = await wallet.create_public_did(DIDMethod.SOV, KeyType.ED25519) + info_pub = await wallet.create_public_did(SOV, ED25519) await wallet.set_did_endpoint( info_pub.did, "https://example.com", mock_ledger, routing_keys=routing_keys ) @@ -167,8 +164,8 @@ async def test_set_did_endpoint_readonly_ledger(self, wallet: IndySdkWallet): read_only=True, update_endpoint_for_did=async_mock.CoroutineMock() ) info_pub = await wallet.create_public_did( - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) await wallet.set_did_endpoint(info_pub.did, "https://example.com", mock_ledger) mock_ledger.update_endpoint_for_did.assert_not_called() @@ -206,8 +203,8 @@ async def test_get_local_did_x(self, wallet: IndySdkWallet): @pytest.mark.asyncio async def test_replace_local_did_metadata_x(self, wallet: IndySdkWallet): info = await wallet.create_local_did( - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, self.test_seed, self.test_sov_did, self.test_metadata, @@ -239,7 +236,7 @@ async def test_verify_message_x(self, wallet: IndySdkWallet): b"hello world", b"signature", self.test_ed25519_verkey, - KeyType.ED25519, + ED25519, ) assert "outlier" in str(excinfo.value) @@ -247,7 +244,7 @@ async def test_verify_message_x(self, wallet: IndySdkWallet): test_module.ErrorCode.CommonInvalidStructure ) assert not await wallet.verify_message( - b"hello world", b"signature", self.test_ed25519_verkey, KeyType.ED25519 + b"hello world", b"signature", self.test_ed25519_verkey, ED25519 ) @pytest.mark.asyncio @@ -282,14 +279,12 @@ async def test_compare_pack_unpack(self, in_memory_wallet, wallet: IndySdkWallet """ Ensure that python-based pack/unpack is compatible with indy-sdk implementation """ - await in_memory_wallet.create_local_did( - DIDMethod.SOV, KeyType.ED25519, self.test_seed - ) + await in_memory_wallet.create_local_did(SOV, ED25519, self.test_seed) py_packed = await in_memory_wallet.pack_message( self.test_message, [self.test_verkey], self.test_verkey ) - await wallet.create_local_did(DIDMethod.SOV, KeyType.ED25519, self.test_seed) + await wallet.create_local_did(SOV, ED25519, self.test_seed) packed = await wallet.pack_message( self.test_message, [self.test_verkey], self.test_verkey ) @@ -820,7 +815,7 @@ async def test_postgres_wallet_works(self): opened = await postgres_wallet.create_wallet() wallet = IndySdkWallet(opened) - await wallet.create_local_did(DIDMethod.SOV, KeyType.ED25519, self.test_seed) + await wallet.create_local_did(SOV, ED25519, self.test_seed) py_packed = await wallet.pack_message( self.test_message, [self.test_verkey], self.test_verkey ) @@ -862,7 +857,7 @@ async def test_postgres_wallet_scheme_works(self): assert "Wallet was not removed" in str(excinfo.value) wallet = IndySdkWallet(opened) - await wallet.create_local_did(DIDMethod.SOV, KeyType.ED25519, self.test_seed) + await wallet.create_local_did(SOV, ED25519, self.test_seed) py_packed = await wallet.pack_message( self.test_message, [self.test_verkey], self.test_verkey ) @@ -899,7 +894,7 @@ async def test_postgres_wallet_scheme2_works(self): opened = await postgres_wallet.create_wallet() wallet = IndySdkWallet(opened) - await wallet.create_local_did(DIDMethod.SOV, KeyType.ED25519, self.test_seed) + await wallet.create_local_did(SOV, ED25519, self.test_seed) py_packed = await wallet.pack_message( self.test_message, [self.test_verkey], self.test_verkey ) diff --git a/aries_cloudagent/wallet/tests/test_key_pair.py b/aries_cloudagent/wallet/tests/test_key_pair.py index b81062d856..6d0ddccb67 100644 --- a/aries_cloudagent/wallet/tests/test_key_pair.py +++ b/aries_cloudagent/wallet/tests/test_key_pair.py @@ -4,7 +4,7 @@ from ...storage.error import StorageNotFoundError from ..util import bytes_to_b58 -from ..key_type import KeyType +from ..key_type import ED25519 from ...core.in_memory import InMemoryProfile from ...storage.in_memory import InMemoryStorage from ..key_pair import KeyPairStorageManager, KEY_PAIR_STORAGE_TYPE @@ -23,7 +23,7 @@ async def test_create_key_pair(self): await self.key_pair_mgr.store_key_pair( public_key=self.test_public_key, secret_key=self.test_secret, - key_type=KeyType.ED25519, + key_type=ED25519, ) verkey = bytes_to_b58(self.test_public_key) @@ -34,17 +34,17 @@ async def test_create_key_pair(self): value = json.loads(record.value) - assert record.tags == {"verkey": verkey, "key_type": KeyType.ED25519.key_type} + assert record.tags == {"verkey": verkey, "key_type": ED25519.key_type} assert value["verkey"] == verkey assert value["secret_key"] == bytes_to_b58(self.test_secret) assert value["metadata"] == {} - assert value["key_type"] == KeyType.ED25519.key_type + assert value["key_type"] == ED25519.key_type async def test_get_key_pair(self): await self.key_pair_mgr.store_key_pair( public_key=self.test_public_key, secret_key=self.test_secret, - key_type=KeyType.ED25519, + key_type=ED25519, ) verkey = bytes_to_b58(self.test_public_key) @@ -54,7 +54,7 @@ async def test_get_key_pair(self): assert key_pair["verkey"] == verkey assert key_pair["secret_key"] == bytes_to_b58(self.test_secret) assert key_pair["metadata"] == {} - assert key_pair["key_type"] == KeyType.ED25519.key_type + assert key_pair["key_type"] == ED25519.key_type async def test_get_key_pair_x_not_found(self): with self.assertRaises(StorageNotFoundError): @@ -64,7 +64,7 @@ async def test_delete_key_pair(self): await self.key_pair_mgr.store_key_pair( public_key=self.test_public_key, secret_key=self.test_secret, - key_type=KeyType.ED25519, + key_type=ED25519, ) verkey = bytes_to_b58(self.test_public_key) @@ -86,7 +86,7 @@ async def test_update_key_pair_metadata(self): await self.key_pair_mgr.store_key_pair( public_key=self.test_public_key, secret_key=self.test_secret, - key_type=KeyType.ED25519, + key_type=ED25519, metadata={"some": "data"}, ) diff --git a/aries_cloudagent/wallet/tests/test_key_type.py b/aries_cloudagent/wallet/tests/test_key_type.py index 0dc025a099..67730cbc55 100644 --- a/aries_cloudagent/wallet/tests/test_key_type.py +++ b/aries_cloudagent/wallet/tests/test_key_type.py @@ -1,41 +1,49 @@ from unittest import TestCase from ...core.error import BaseError -from ..did_method import DIDMethod -from ..key_type import KeyType +from ..did_method import KEY, SOV, DIDMethods +from ..key_type import BLS12381G2, ED25519 SOV_DID_METHOD_NAME = "sov" -SOV_SUPPORTED_KEY_TYPES = [KeyType.ED25519] +SOV_SUPPORTED_KEY_TYPES = [ED25519] KEY_DID_METHOD_NAME = "key" class TestDidMethod(TestCase): + """TestCases for did method""" + + did_methods = DIDMethods() + def test_from_metadata(self): - assert DIDMethod.from_metadata({"method": SOV_DID_METHOD_NAME}) == DIDMethod.SOV - assert DIDMethod.from_metadata({"method": KEY_DID_METHOD_NAME}) == DIDMethod.KEY + """Testing 'from_metadata'""" + assert self.did_methods.from_metadata({"method": SOV_DID_METHOD_NAME}) == SOV + assert self.did_methods.from_metadata({"method": KEY_DID_METHOD_NAME}) == KEY # test backwards compat - assert DIDMethod.from_metadata({}) == DIDMethod.SOV + assert self.did_methods.from_metadata({}) == SOV def test_from_method(self): - assert DIDMethod.from_method(SOV_DID_METHOD_NAME) == DIDMethod.SOV - assert DIDMethod.from_method(KEY_DID_METHOD_NAME) == DIDMethod.KEY - assert DIDMethod.from_method("random") == None + """Testing 'from_method'""" + assert self.did_methods.from_method(SOV_DID_METHOD_NAME) == SOV + assert self.did_methods.from_method(KEY_DID_METHOD_NAME) == KEY + assert self.did_methods.from_method("random") is None def test_from_did(self): - assert DIDMethod.from_did(f"did:{SOV_DID_METHOD_NAME}:xxxx") == DIDMethod.SOV - assert DIDMethod.from_did(f"did:{KEY_DID_METHOD_NAME}:xxxx") == DIDMethod.KEY + """Testing 'from_did'""" + assert self.did_methods.from_did(f"did:{SOV_DID_METHOD_NAME}:xxxx") == SOV + assert self.did_methods.from_did(f"did:{KEY_DID_METHOD_NAME}:xxxx") == KEY with self.assertRaises(BaseError) as context: - DIDMethod.from_did("did:unknown:something") + self.did_methods.from_did("did:unknown:something") assert "Unsupported did method: unknown" in str(context.exception) def test_properties(self): - method = DIDMethod.SOV + """Testing 'properties'""" + method = SOV assert method.method_name == SOV_DID_METHOD_NAME assert method.supported_key_types == SOV_SUPPORTED_KEY_TYPES - assert method.supports_rotation == True + assert method.supports_rotation is True - assert method.supports_key_type(KeyType.ED25519) == True - assert method.supports_key_type(KeyType.BLS12381G2) == False + assert method.supports_key_type(ED25519) == True + assert method.supports_key_type(BLS12381G2) == False diff --git a/aries_cloudagent/wallet/tests/test_routes.py b/aries_cloudagent/wallet/tests/test_routes.py index c6adb4b5dc..75abc4d483 100644 --- a/aries_cloudagent/wallet/tests/test_routes.py +++ b/aries_cloudagent/wallet/tests/test_routes.py @@ -1,15 +1,14 @@ import mock as async_mock -from async_case import IsolatedAsyncioTestCase - from aiohttp.web import HTTPForbidden +from async_case import IsolatedAsyncioTestCase -from .. import routes as test_module from ...admin.request_context import AdminRequestContext from ...core.in_memory import InMemoryProfile from ...ledger.base import BaseLedger from ...protocols.coordinate_mediation.v1_0.route_manager import RouteManager -from ...wallet.did_method import DIDMethod -from ...wallet.key_type import KeyType +from ...wallet.did_method import SOV, DIDMethods +from ...wallet.key_type import ED25519, KeyTypes +from .. import routes as test_module from ..base import BaseWallet from ..did_info import DIDInfo from ..did_posture import DIDPosture @@ -23,6 +22,7 @@ def setUp(self): self.context = AdminRequestContext.test_context( self.session_inject, self.profile ) + self.context.injector.bind_instance(KeyTypes, KeyTypes()) self.request_dict = { "context": self.context, "outbound_message_router": async_mock.AsyncMock(), @@ -38,6 +38,7 @@ def setUp(self): self.test_verkey = "verkey" self.test_posted_did = "posted-did" self.test_posted_verkey = "posted-verkey" + self.context.injector.bind_instance(DIDMethods, DIDMethods()) async def test_missing_wallet(self): self.session_inject[BaseWallet] = None @@ -71,8 +72,8 @@ def test_format_did_info(self): self.test_did, self.test_verkey, DIDPosture.WALLET_ONLY.metadata, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) result = test_module.format_did_info(did_info) assert ( @@ -85,8 +86,8 @@ def test_format_did_info(self): self.test_did, self.test_verkey, {"posted": True, "public": True}, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) result = test_module.format_did_info(did_info) assert result["posture"] == DIDPosture.PUBLIC.moniker @@ -95,8 +96,8 @@ def test_format_did_info(self): self.test_did, self.test_verkey, {"posted": True, "public": False}, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) result = test_module.format_did_info(did_info) assert result["posture"] == DIDPosture.POSTED.moniker @@ -109,8 +110,8 @@ async def test_create_did(self): self.test_did, self.test_verkey, DIDPosture.WALLET_ONLY.metadata, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) result = await test_module.wallet_create_did(self.request) json_response.assert_called_once_with( @@ -119,8 +120,8 @@ async def test_create_did(self): "did": self.test_did, "verkey": self.test_verkey, "posture": DIDPosture.WALLET_ONLY.moniker, - "key_type": KeyType.ED25519.key_type, - "method": DIDMethod.SOV.method_name, + "key_type": ED25519.key_type, + "method": SOV.method_name, } } ) @@ -147,15 +148,15 @@ async def test_did_list(self): self.test_did, self.test_verkey, DIDPosture.WALLET_ONLY.metadata, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ), DIDInfo( self.test_posted_did, self.test_posted_verkey, DIDPosture.POSTED.metadata, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ), ] result = await test_module.wallet_did_list(self.request) @@ -166,15 +167,15 @@ async def test_did_list(self): "did": self.test_posted_did, "verkey": self.test_posted_verkey, "posture": DIDPosture.POSTED.moniker, - "key_type": KeyType.ED25519.key_type, - "method": DIDMethod.SOV.method_name, + "key_type": ED25519.key_type, + "method": SOV.method_name, }, { "did": self.test_did, "verkey": self.test_verkey, "posture": DIDPosture.WALLET_ONLY.moniker, - "key_type": KeyType.ED25519.key_type, - "method": DIDMethod.SOV.method_name, + "key_type": ED25519.key_type, + "method": SOV.method_name, }, ] } @@ -191,16 +192,16 @@ async def test_did_list_filter_public(self): self.test_did, self.test_verkey, DIDPosture.PUBLIC.metadata, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) self.wallet.get_posted_dids.return_value = [ DIDInfo( self.test_posted_did, self.test_posted_verkey, DIDPosture.POSTED.metadata, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) ] result = await test_module.wallet_did_list(self.request) @@ -211,8 +212,8 @@ async def test_did_list_filter_public(self): "did": self.test_did, "verkey": self.test_verkey, "posture": DIDPosture.PUBLIC.moniker, - "key_type": KeyType.ED25519.key_type, - "method": DIDMethod.SOV.method_name, + "key_type": ED25519.key_type, + "method": SOV.method_name, } ] } @@ -229,8 +230,8 @@ async def test_did_list_filter_posted(self): self.test_did, self.test_verkey, DIDPosture.PUBLIC.metadata, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) self.wallet.get_posted_dids.return_value = [ DIDInfo( @@ -240,8 +241,8 @@ async def test_did_list_filter_posted(self): "posted": True, "public": False, }, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) ] result = await test_module.wallet_did_list(self.request) @@ -252,8 +253,8 @@ async def test_did_list_filter_posted(self): "did": self.test_posted_did, "verkey": self.test_posted_verkey, "posture": DIDPosture.POSTED.moniker, - "key_type": KeyType.ED25519.key_type, - "method": DIDMethod.SOV.method_name, + "key_type": ED25519.key_type, + "method": SOV.method_name, } ] } @@ -270,8 +271,8 @@ async def test_did_list_filter_did(self): self.test_did, self.test_verkey, DIDPosture.WALLET_ONLY.metadata, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) result = await test_module.wallet_did_list(self.request) json_response.assert_called_once_with( @@ -281,8 +282,8 @@ async def test_did_list_filter_did(self): "did": self.test_did, "verkey": self.test_verkey, "posture": DIDPosture.WALLET_ONLY.moniker, - "key_type": KeyType.ED25519.key_type, - "method": DIDMethod.SOV.method_name, + "key_type": ED25519.key_type, + "method": SOV.method_name, } ] } @@ -310,8 +311,8 @@ async def test_did_list_filter_verkey(self): self.test_did, self.test_verkey, DIDPosture.WALLET_ONLY.metadata, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) result = await test_module.wallet_did_list(self.request) json_response.assert_called_once_with( @@ -321,8 +322,8 @@ async def test_did_list_filter_verkey(self): "did": self.test_did, "verkey": self.test_verkey, "posture": DIDPosture.WALLET_ONLY.moniker, - "key_type": KeyType.ED25519.key_type, - "method": DIDMethod.SOV.method_name, + "key_type": ED25519.key_type, + "method": SOV.method_name, } ] } @@ -349,8 +350,8 @@ async def test_get_public_did(self): self.test_did, self.test_verkey, DIDPosture.PUBLIC.metadata, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) result = await test_module.wallet_get_public_did(self.request) json_response.assert_called_once_with( @@ -359,8 +360,8 @@ async def test_get_public_did(self): "did": self.test_did, "verkey": self.test_verkey, "posture": DIDPosture.PUBLIC.moniker, - "key_type": KeyType.ED25519.key_type, - "method": DIDMethod.SOV.method_name, + "key_type": ED25519.key_type, + "method": SOV.method_name, } } ) @@ -396,8 +397,8 @@ async def test_set_public_did(self): self.test_did, self.test_verkey, DIDPosture.PUBLIC.metadata, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) result = await test_module.wallet_set_public_did(self.request) self.wallet.set_public_did.assert_awaited_once() @@ -407,8 +408,8 @@ async def test_set_public_did(self): "did": self.test_did, "verkey": self.test_verkey, "posture": DIDPosture.PUBLIC.moniker, - "key_type": KeyType.ED25519.key_type, - "method": DIDMethod.SOV.method_name, + "key_type": ED25519.key_type, + "method": SOV.method_name, } } ) @@ -494,8 +495,8 @@ async def test_set_public_did_x(self): self.test_did, self.test_verkey, DIDPosture.PUBLIC.metadata, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) self.wallet.set_public_did.side_effect = test_module.WalletError() with self.assertRaises(test_module.web.HTTPBadRequest): @@ -525,8 +526,8 @@ async def test_set_public_did_no_wallet_did(self): self.test_did, self.test_verkey, DIDPosture.PUBLIC.metadata, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) self.wallet.set_public_did.side_effect = test_module.WalletNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): @@ -557,8 +558,8 @@ async def test_set_public_did_update_endpoint(self): self.test_did, self.test_verkey, {**DIDPosture.PUBLIC.metadata, "endpoint": "https://endpoint.com"}, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) result = await test_module.wallet_set_public_did(self.request) self.wallet.set_public_did.assert_awaited_once() @@ -568,8 +569,8 @@ async def test_set_public_did_update_endpoint(self): "did": self.test_did, "verkey": self.test_verkey, "posture": DIDPosture.PUBLIC.moniker, - "key_type": KeyType.ED25519.key_type, - "method": DIDMethod.SOV.method_name, + "key_type": ED25519.key_type, + "method": SOV.method_name, } } ) @@ -605,8 +606,8 @@ async def test_set_public_did_update_endpoint_use_default_update_in_wallet(self) self.test_did, self.test_verkey, DIDPosture.PUBLIC.metadata, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) self.wallet.get_local_did.return_value = did_info self.wallet.set_public_did.return_value = did_info @@ -626,8 +627,8 @@ async def test_set_public_did_update_endpoint_use_default_update_in_wallet(self) "did": self.test_did, "verkey": self.test_verkey, "posture": DIDPosture.PUBLIC.moniker, - "key_type": KeyType.ED25519.key_type, - "method": DIDMethod.SOV.method_name, + "key_type": ED25519.key_type, + "method": SOV.method_name, } } ) @@ -651,15 +652,15 @@ async def test_set_did_endpoint(self): self.test_did, self.test_verkey, {"public": False, "endpoint": "http://old-endpoint.ca"}, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) self.wallet.get_public_did.return_value = DIDInfo( self.test_did, self.test_verkey, DIDPosture.PUBLIC.metadata, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) with async_mock.patch.object( @@ -680,15 +681,15 @@ async def test_set_did_endpoint_public_did_no_ledger(self): self.test_did, self.test_verkey, {"public": False, "endpoint": "http://old-endpoint.ca"}, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) self.wallet.get_public_did.return_value = DIDInfo( self.test_did, self.test_verkey, DIDPosture.PUBLIC.metadata, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) self.wallet.set_did_endpoint.side_effect = test_module.LedgerConfigError() @@ -740,8 +741,8 @@ async def test_get_did_endpoint(self): self.test_did, self.test_verkey, {"public": False, "endpoint": "http://old-endpoint.ca"}, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) with async_mock.patch.object( @@ -788,8 +789,8 @@ async def test_rotate_did_keypair(self): "did", "verkey", {"public": False}, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) ) self.wallet.rotate_did_keypair_start = async_mock.AsyncMock() @@ -823,8 +824,8 @@ async def test_rotate_did_keypair_did_not_local(self): "did", "verkey", {"posted": True, "public": True}, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -838,8 +839,8 @@ async def test_rotate_did_keypair_x(self): "did", "verkey", {"public": False}, - DIDMethod.SOV, - KeyType.ED25519, + SOV, + ED25519, ) ) self.wallet.rotate_did_keypair_start = async_mock.AsyncMock(