Skip to content

Commit 7fff35f

Browse files
committed
Merge branch 'feature/keytypes-pluggable' into feature/did-method-key-type-registry
2 parents 61128aa + a4cbef1 commit 7fff35f

66 files changed

Lines changed: 738 additions & 807 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

aries_cloudagent/config/default_context.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from ..utils.dependencies import is_indy_sdk_module_installed
1919
from ..utils.stats import Collector
2020
from ..wallet.did_method import DIDMethods
21+
from ..wallet.key_type import KeyTypes
2122
from .base_context import ContextBuilder
2223
from .injection_context import InjectionContext
2324
from .provider import CachedProvider, ClassProvider
@@ -51,6 +52,7 @@ async def build_context(self) -> InjectionContext:
5152
# Global did resolver
5253
context.injector.bind_instance(DIDResolver, DIDResolver([]))
5354
context.injector.bind_instance(DIDMethods, DIDMethods())
55+
context.injector.bind_instance(KeyTypes, KeyTypes())
5456

5557
await self.bind_providers(context)
5658
await self.load_plugins(context)
@@ -68,7 +70,8 @@ async def bind_providers(self, context: InjectionContext):
6870
# so it can be shared by all wallet instances. If we set it in the indy sdk
6971
# profile provider it could mean other wallets won't have access to the provider
7072
if is_indy_sdk_module_installed():
71-
from ..ledger.indy import IndySdkLedgerPool, IndySdkLedgerPoolProvider
73+
from ..ledger.indy import (IndySdkLedgerPool,
74+
IndySdkLedgerPoolProvider)
7275

7376
context.injector.bind_provider(
7477
IndySdkLedgerPool,

aries_cloudagent/config/wallet.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from ..wallet.crypto import seed_to_did
1313
from ..wallet.did_info import DIDInfo
1414
from ..wallet.did_method import SOV
15-
from ..wallet.key_type import KeyType
15+
from ..wallet.key_type import ED25519
1616
from .base import ConfigError
1717
from .injection_context import InjectionContext
1818

@@ -79,7 +79,7 @@ async def wallet_config(
7979
if wallet_seed and seed_to_did(wallet_seed) != public_did:
8080
if context.settings.get("wallet.replace_public_did"):
8181
replace_did_info = await wallet.create_local_did(
82-
method=SOV, key_type=KeyType.ED25519, seed=wallet_seed
82+
method=SOV, key_type=ED25519, seed=wallet_seed
8383
)
8484
public_did = replace_did_info.did
8585
await wallet.set_public_did(public_did)
@@ -100,7 +100,7 @@ async def wallet_config(
100100

101101
local_did_info = await wallet.create_local_did(
102102
method=SOV,
103-
key_type=KeyType.ED25519,
103+
key_type=ED25519,
104104
seed=wallet_seed,
105105
metadata=metadata,
106106
)
@@ -110,7 +110,7 @@ async def wallet_config(
110110
print(f"Verkey: {local_did_info.verkey}")
111111
else:
112112
public_did_info = await wallet.create_public_did(
113-
method=SOV, key_type=KeyType.ED25519, seed=wallet_seed
113+
method=SOV, key_type=ED25519, seed=wallet_seed
114114
)
115115
public_did = public_did_info.did
116116
if provision:
@@ -129,7 +129,7 @@ async def wallet_config(
129129
if test_seed:
130130
await wallet.create_local_did(
131131
method=SOV,
132-
key_type=KeyType.ED25519,
132+
key_type=ED25519,
133133
seed=test_seed,
134134
metadata={"endpoint": "1.2.3.4:8021"},
135135
)

aries_cloudagent/core/tests/test_conductor.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,19 @@
88
from ...config.injection_context import InjectionContext
99
from ...connections.models.conn_record import ConnRecord
1010
from ...connections.models.connection_target import ConnectionTarget
11-
from ...connections.models.diddoc import (
12-
DIDDoc,
13-
PublicKey,
14-
PublicKeyType,
15-
Service,
16-
)
11+
from ...connections.models.diddoc import (DIDDoc, PublicKey, PublicKeyType,
12+
Service)
1713
from ...core.event_bus import EventBus, MockEventBus
1814
from ...core.in_memory import InMemoryProfileManager
1915
from ...core.profile import ProfileManager
2016
from ...core.protocol_registry import ProtocolRegistry
21-
from ...protocols.coordinate_mediation.mediation_invite_store import (
22-
MediationInviteRecord,
23-
)
24-
from ...protocols.coordinate_mediation.v1_0.models.mediation_record import (
25-
MediationRecord,
26-
)
27-
from ...resolver.did_resolver import DIDResolver
2817
from ...multitenant.base import BaseMultitenantManager
2918
from ...multitenant.manager import MultitenantManager
19+
from ...protocols.coordinate_mediation.mediation_invite_store import \
20+
MediationInviteRecord
21+
from ...protocols.coordinate_mediation.v1_0.models.mediation_record import \
22+
MediationRecord
23+
from ...resolver.did_resolver import DIDResolver
3024
from ...storage.base import BaseStorage
3125
from ...storage.error import StorageNotFoundError
3226
from ...transport.inbound.message import InboundMessage
@@ -35,14 +29,13 @@
3529
from ...transport.outbound.manager import QueuedOutboundMessage
3630
from ...transport.outbound.message import OutboundMessage
3731
from ...transport.outbound.status import OutboundSendStatus
38-
from ...transport.wire_format import BaseWireFormat
3932
from ...transport.pack_format import PackWireFormat
33+
from ...transport.wire_format import BaseWireFormat
4034
from ...utils.stats import Collector
4135
from ...version import __version__
4236
from ...wallet.base import BaseWallet
43-
from ...wallet.key_type import KeyType
4437
from ...wallet.did_method import SOV
45-
38+
from ...wallet.key_type import ED25519
4639
from .. import conductor as test_module
4740

4841

@@ -132,7 +125,7 @@ async def test_startup(self):
132125
wallet = session.inject(BaseWallet)
133126
await wallet.create_public_did(
134127
SOV,
135-
KeyType.ED25519,
128+
ED25519,
136129
)
137130

138131
mock_inbound_mgr.return_value.setup.assert_awaited_once()
@@ -601,7 +594,7 @@ async def test_admin(self):
601594
wallet = session.inject(BaseWallet)
602595
await wallet.create_public_did(
603596
SOV,
604-
KeyType.ED25519,
597+
ED25519,
605598
)
606599

607600
with async_mock.patch.object(
@@ -645,7 +638,7 @@ async def test_admin_startx(self):
645638
wallet = session.inject(BaseWallet)
646639
await wallet.create_public_did(
647640
SOV,
648-
KeyType.ED25519,
641+
ED25519,
649642
)
650643

651644
with async_mock.patch.object(
@@ -717,7 +710,7 @@ async def test_start_static(self):
717710
wallet = session.inject(BaseWallet)
718711
await wallet.create_public_did(
719712
SOV,
720-
KeyType.ED25519,
713+
ED25519,
721714
)
722715

723716
mock_mgr.return_value.create_static_connection = async_mock.AsyncMock()
@@ -887,7 +880,7 @@ async def test_print_invite_connection(self):
887880
wallet = session.inject(BaseWallet)
888881
await wallet.create_public_did(
889882
SOV,
890-
KeyType.ED25519,
883+
ED25519,
891884
)
892885

893886
await conductor.start()
@@ -1390,7 +1383,7 @@ async def test_startup_x_version_mismatch(self):
13901383
wallet = session.inject(BaseWallet)
13911384
await wallet.create_public_did(
13921385
SOV,
1393-
KeyType.ED25519,
1386+
ED25519,
13941387
)
13951388

13961389
mock_inbound_mgr.return_value.setup.assert_awaited_once()
@@ -1427,7 +1420,7 @@ async def test_startup_x_no_storage_version(self):
14271420
wallet = session.inject(BaseWallet)
14281421
await wallet.create_public_did(
14291422
SOV,
1430-
KeyType.ED25519,
1423+
ED25519,
14311424
)
14321425

14331426
mock_inbound_mgr.return_value.setup.assert_awaited_once()

aries_cloudagent/did/did_key.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
"""DID Key class and resolver methods."""
22

33
from ..wallet.crypto import ed25519_pk_to_curve25519
4-
from ..wallet.key_type import KeyType
4+
from ..wallet.key_type import (
5+
BLS12381G1G2,
6+
ED25519,
7+
KeyType,
8+
BLS12381G1,
9+
X25519,
10+
BLS12381G2,
11+
KeyTypes,
12+
)
513
from ..wallet.util import b58_to_bytes, bytes_to_b58
614

715
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":
3139
return cls.from_public_key(public_key_bytes, key_type)
3240

3341
@classmethod
34-
def from_fingerprint(cls, fingerprint: str) -> "DIDKey":
42+
def from_fingerprint(cls, fingerprint: str, key_types=None) -> "DIDKey":
3543
"""Initialize new DIDKey instance from multibase encoded fingerprint.
3644
3745
The fingerprint contains both the public key and key type.
@@ -43,7 +51,9 @@ def from_fingerprint(cls, fingerprint: str) -> "DIDKey":
4351
key_bytes_with_prefix = b58_to_bytes(fingerprint[1:])
4452

4553
# Get associated key type with prefixed bytes
46-
key_type = KeyType.from_prefixed_bytes(key_bytes_with_prefix)
54+
if not key_types:
55+
key_types = KeyTypes()
56+
key_type = key_types.from_prefixed_bytes(key_bytes_with_prefix)
4757

4858
if not key_type:
4959
raise Exception(
@@ -169,8 +179,8 @@ def construct_did_key_bls12381g1g2(did_key: "DIDKey") -> dict:
169179
g1_public_key = did_key.public_key[:48]
170180
g2_public_key = did_key.public_key[48:]
171181

172-
bls12381g1_key = DIDKey.from_public_key(g1_public_key, KeyType.BLS12381G1)
173-
bls12381g2_key = DIDKey.from_public_key(g2_public_key, KeyType.BLS12381G2)
182+
bls12381g1_key = DIDKey.from_public_key(g1_public_key, BLS12381G1)
183+
bls12381g2_key = DIDKey.from_public_key(g2_public_key, BLS12381G2)
174184

175185
bls12381g1_key_id = f"{did_key.did}#{bls12381g1_key.fingerprint}"
176186
bls12381g2_key_id = f"{did_key.did}#{bls12381g2_key.fingerprint}"
@@ -241,7 +251,7 @@ def construct_did_key_ed25519(did_key: "DIDKey") -> dict:
241251
242252
"""
243253
curve25519 = ed25519_pk_to_curve25519(did_key.public_key)
244-
x25519 = DIDKey.from_public_key(curve25519, KeyType.X25519)
254+
x25519 = DIDKey.from_public_key(curve25519, X25519)
245255

246256
did_doc = construct_did_signature_key_base(
247257
id=did_key.did,
@@ -289,9 +299,9 @@ def construct_did_signature_key_base(
289299

290300

291301
DID_KEY_RESOLVERS = {
292-
KeyType.ED25519: construct_did_key_ed25519,
293-
KeyType.X25519: construct_did_key_x25519,
294-
KeyType.BLS12381G2: construct_did_key_bls12381g2,
295-
KeyType.BLS12381G1: construct_did_key_bls12381g1,
296-
KeyType.BLS12381G1G2: construct_did_key_bls12381g1g2,
302+
ED25519: construct_did_key_ed25519,
303+
X25519: construct_did_key_x25519,
304+
BLS12381G2: construct_did_key_bls12381g2,
305+
BLS12381G1: construct_did_key_bls12381g1,
306+
BLS12381G1G2: construct_did_key_bls12381g1g2,
297307
}

aries_cloudagent/did/tests/test_did_key_bls12381g1.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from unittest import TestCase
22

33

4-
from ...wallet.key_type import KeyType
4+
from ...wallet.key_type import BLS12381G1
55
from ...wallet.util import b58_to_bytes
66
from ..did_key import DIDKey, DID_KEY_RESOLVERS
77
from .test_dids import (
@@ -24,14 +24,12 @@
2424
class TestDIDKey(TestCase):
2525
def test_bls12381g1_from_public_key(self):
2626
key_bytes = b58_to_bytes(TEST_BLS12381G1_BASE58_KEY)
27-
did_key = DIDKey.from_public_key(key_bytes, KeyType.BLS12381G1)
27+
did_key = DIDKey.from_public_key(key_bytes, BLS12381G1)
2828

2929
assert did_key.did == TEST_BLS12381G1_DID
3030

3131
def test_bls12381g1_from_public_key_b58(self):
32-
did_key = DIDKey.from_public_key_b58(
33-
TEST_BLS12381G1_BASE58_KEY, KeyType.BLS12381G1
34-
)
32+
did_key = DIDKey.from_public_key_b58(TEST_BLS12381G1_BASE58_KEY, BLS12381G1)
3533

3634
assert did_key.did == TEST_BLS12381G1_DID
3735

@@ -53,20 +51,20 @@ def test_bls12381g1_properties(self):
5351
assert did_key.did == TEST_BLS12381G1_DID
5452
assert did_key.public_key_b58 == TEST_BLS12381G1_BASE58_KEY
5553
assert did_key.public_key == b58_to_bytes(TEST_BLS12381G1_BASE58_KEY)
56-
assert did_key.key_type == KeyType.BLS12381G1
54+
assert did_key.key_type == BLS12381G1
5755
assert did_key.key_id == TEST_BLS12381G1_KEY_ID
5856
assert did_key.prefixed_public_key == TEST_BLS12381G1_PREFIX_BYTES
5957

6058
def test_bls12381g1_diddoc(self):
6159
did_key = DIDKey.from_did(TEST_BLS12381G1_DID)
6260

63-
resolver = DID_KEY_RESOLVERS[KeyType.BLS12381G1]
61+
resolver = DID_KEY_RESOLVERS[BLS12381G1]
6462

6563
assert resolver(did_key) == did_key.did_doc
6664

6765
def test_bls12381g1_resolver(self):
6866
did_key = DIDKey.from_did(TEST_BLS12381G1_DID)
69-
resolver = DID_KEY_RESOLVERS[KeyType.BLS12381G1]
67+
resolver = DID_KEY_RESOLVERS[BLS12381G1]
7068
did_doc = resolver(did_key)
7169

7270
assert (

aries_cloudagent/did/tests/test_did_key_bls12381g1g2.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from unittest import TestCase
22

3-
from ...wallet.key_type import KeyType
3+
from ...wallet.key_type import BLS12381G1, BLS12381G1G2, BLS12381G2
44
from ...wallet.util import b58_to_bytes
55
from ..did_key import DIDKey, DID_KEY_RESOLVERS
66
from .test_dids import (
@@ -31,14 +31,12 @@
3131
class TestDIDKey(TestCase):
3232
def test_bls12381g1g2_from_public_key(self):
3333
key_bytes = b58_to_bytes(TEST_BLS12381G1G2_BASE58_KEY)
34-
did_key = DIDKey.from_public_key(key_bytes, KeyType.BLS12381G1G2)
34+
did_key = DIDKey.from_public_key(key_bytes, BLS12381G1G2)
3535

3636
assert did_key.did == TEST_BLS12381G1G2_DID
3737

3838
def test_bls12381g1g2_from_public_key_b58(self):
39-
did_key = DIDKey.from_public_key_b58(
40-
TEST_BLS12381G1G2_BASE58_KEY, KeyType.BLS12381G1G2
41-
)
39+
did_key = DIDKey.from_public_key_b58(TEST_BLS12381G1G2_BASE58_KEY, BLS12381G1G2)
4240

4341
assert did_key.did == TEST_BLS12381G1G2_DID
4442

@@ -60,21 +58,21 @@ def test_bls12381g1g2_properties(self):
6058
assert did_key.did == TEST_BLS12381G1G2_DID
6159
assert did_key.public_key_b58 == TEST_BLS12381G1G2_BASE58_KEY
6260
assert did_key.public_key == b58_to_bytes(TEST_BLS12381G1G2_BASE58_KEY)
63-
assert did_key.key_type == KeyType.BLS12381G1G2
61+
assert did_key.key_type == BLS12381G1G2
6462
assert did_key.prefixed_public_key == TEST_BLS12381G1G2_PREFIX_BYTES
6563

6664
def test_bls12381g1g2_diddoc(self):
6765
did_key = DIDKey.from_did(TEST_BLS12381G1G2_DID)
6866

69-
resolver = DID_KEY_RESOLVERS[KeyType.BLS12381G1G2]
67+
resolver = DID_KEY_RESOLVERS[BLS12381G1G2]
7068

7169
assert resolver(did_key) == did_key.did_doc
7270

7371
def test_bls12381g1g2_resolver(self):
7472
did_key = DIDKey.from_did(
7573
"did:key:z5TcESXuYUE9aZWYwSdrUEGK1HNQFHyTt4aVpaCTVZcDXQmUheFwfNZmRksaAbBneNm5KyE52SdJeRCN1g6PJmF31GsHWwFiqUDujvasK3wTiDr3vvkYwEJHt7H5RGEKYEp1ErtQtcEBgsgY2DA9JZkHj1J9HZ8MRDTguAhoFtR4aTBQhgnkP4SwVbxDYMEZoF2TMYn3s"
7674
)
77-
resolver = DID_KEY_RESOLVERS[KeyType.BLS12381G1G2]
75+
resolver = DID_KEY_RESOLVERS[BLS12381G1G2]
7876
did_doc = resolver(did_key)
7977

8078
assert (
@@ -88,24 +86,24 @@ def test_bls12381g1g1_to_g1(self):
8886
# TODO: add easier method to go form g1 <- g1g2 -> g2
8987
# First 48 bytes is g1 key
9088
g1_public_key = g1g2_did.public_key[:48]
91-
g1_did = DIDKey.from_public_key(g1_public_key, KeyType.BLS12381G1)
89+
g1_did = DIDKey.from_public_key(g1_public_key, BLS12381G1)
9290

9391
assert g1_did.fingerprint == TEST_BLS12381G1_FINGERPRINT
9492
assert g1_did.did == TEST_BLS12381G1_DID
9593
assert g1_did.public_key_b58 == TEST_BLS12381G1_BASE58_KEY
9694
assert g1_did.public_key == b58_to_bytes(TEST_BLS12381G1_BASE58_KEY)
97-
assert g1_did.key_type == KeyType.BLS12381G1
95+
assert g1_did.key_type == BLS12381G1
9896

9997
def test_bls12381g1g1_to_g2(self):
10098
g1g2_did = DIDKey.from_did(TEST_BLS12381G1G2_DID)
10199

102100
# TODO: add easier method to go form g1 <- g1g2 -> g2
103101
# From 48 bytes is g2 key
104102
g2_public_key = g1g2_did.public_key[48:]
105-
g2_did = DIDKey.from_public_key(g2_public_key, KeyType.BLS12381G2)
103+
g2_did = DIDKey.from_public_key(g2_public_key, BLS12381G2)
106104

107105
assert g2_did.fingerprint == TEST_BLS12381G2_FINGERPRINT
108106
assert g2_did.did == TEST_BLS12381G2_DID
109107
assert g2_did.public_key_b58 == TEST_BLS12381G2_BASE58_KEY
110108
assert g2_did.public_key == b58_to_bytes(TEST_BLS12381G2_BASE58_KEY)
111-
assert g2_did.key_type == KeyType.BLS12381G2
109+
assert g2_did.key_type == BLS12381G2

0 commit comments

Comments
 (0)