Skip to content

Commit b6211a5

Browse files
committed
feat: enabling Indy2 DIDs to make connections using public did
1 parent d648a68 commit b6211a5

8 files changed

Lines changed: 276 additions & 94 deletions

File tree

aries_cloudagent/anoncreds/default/did_besu/registry.py

Lines changed: 20 additions & 68 deletions
Large diffs are not rendered by default.

aries_cloudagent/ledger/besu_vdr.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ async def send_credential_definition_anoncreds(
375375

376376
def _send_signed_transaction(
377377
self, contractFunction: ContractFunction, includeGasInTx: bool = True
378-
) -> TxReceipt:
378+
) -> TxReceipt:
379379
nonce = self.web3.eth.get_transaction_count(self.ledgerConfig.trusteeAccount)
380380
chain_id = self.web3.eth.chain_id
381381
txParams = {
@@ -385,26 +385,26 @@ def _send_signed_transaction(
385385
"gasPrice": self.web3.eth.gas_price,
386386
}
387387
if includeGasInTx:
388-
txParams["gas"] = 3000000
388+
txParams["gas"] = 3000000
389389
tx = contractFunction.build_transaction(txParams)
390390
# Sign transaction
391391
signed_tx = self.web3.eth.account.sign_transaction(
392392
tx, private_key=self.ledgerConfig.trusteePKey
393393
)
394394

395395
# Send transaction
396-
LOGGER.debug("Transaction: %s", signed_tx.rawTransaction)
396+
# LOGGER.debug("Transaction: %s", signed_tx.rawTransaction))
397+
LOGGER.debug("Sending contract function %s: tuple %s", contractFunction.fn_name, contractFunction.arguments)
397398
send_tx = self.web3.eth.send_raw_transaction(signed_tx.rawTransaction)
398399

399400
# Wait for transaction receipt
400-
tx_receipt = self.web3.eth.wait_for_transaction_receipt(send_tx)
401+
tx_receipt = self.web3.eth.wait_for_transaction_receipt(transaction_hash=send_tx, poll_latency=1.0)
401402

402403
if tx_receipt["status"] == 0:
403404
raise LedgerError("Transaction rollback")
404405

405406
return tx_receipt
406407

407-
408408
async def get_key_for_did(self, did: str) -> str:
409409
"""Get key for did."""
410410
LOGGER.info(f"Getting key for did {did}")
@@ -493,7 +493,7 @@ async def get_endpoint_for_did(
493493

494494
async def get_all_endpoints_for_did(self, did: str) -> dict:
495495
"""Getting all endpoints there is."""
496-
return {"endpoint": {"endpoint": await self.get_endpoint_for_did(did)}}
496+
return {"endpoint": await self.get_endpoint_for_did(did)}
497497

498498
async def register_nym(
499499
self,
@@ -740,4 +740,4 @@ def _didDocDictFromTuple(self, didDoc) -> dict:
740740
"service": service,
741741
"alsoKnownAs": alsoKnownAs,
742742
}
743-
return didDocument
743+
return didDocument

aries_cloudagent/messaging/valid.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import re
55

66
from base58 import alphabet
7-
87
from marshmallow.exceptions import ValidationError
98
from marshmallow.fields import Field
109
from marshmallow.validate import OneOf, Range, Regexp, Validator
@@ -338,7 +337,7 @@ class IndyDID(Regexp):
338337
"""Validate value against indy DID."""
339338

340339
EXAMPLE = "WgWxqztrNooG92RXvxSTWv"
341-
PATTERN = re.compile(rf"^(did:sov:)?[{B58}]{{21,22}}$|^(did:indy2)?:.+:[{B58}]{{21,22}}$")
340+
PATTERN = re.compile(rf"^(did:sov:)?[{B58}]{{21,22}}$")
342341

343342
def __init__(self):
344343
"""Initialize the instance."""
@@ -349,6 +348,21 @@ def __init__(self):
349348
)
350349

351350

351+
class Indy2DID(Regexp):
352+
"""Validate value against indy2 DID."""
353+
354+
EXAMPLE = "WgWxqztrNooG92RXvxSTWv"
355+
PATTERN = re.compile(rf"^(did:indy2)?:.+:[{B58}]{{21,22}}$")
356+
357+
def __init__(self):
358+
"""Initialize the instance."""
359+
360+
super().__init__(
361+
Indy2DID.PATTERN,
362+
error="Value {input} is not an indy decentralized identifier (DID)",
363+
)
364+
365+
352366
class DIDValidation(Regexp):
353367
"""Validate value against any valid DID spec."""
354368

@@ -423,7 +437,8 @@ def __init__(self):
423437
),
424438
)
425439

426-
# Modifiquei aqui
440+
441+
# Modifiquei aqui
427442
class IndyCredDefId(Regexp):
428443
"""Validate value against indy credential definition identifier specification."""
429444

@@ -433,7 +448,7 @@ class IndyCredDefId(Regexp):
433448
f":3" # cred def id marker
434449
f":CL" # sig alg
435450
rf":(([1-9][0-9]*)|([{B58}]{{21,22}}:2:.+:[0-9.]+))" # schema txn / id
436-
f":(.+)?$|" # tag
451+
f":(.+)?$|" # tag
437452
rf"^((did:indy2)?:.+:[{B58}]{{21,22}})" # issuer DID
438453
f"/anoncreds/v0/CLAIM_DEF/" # cred def id marker
439454
# f":CL" # sig alg
@@ -489,12 +504,12 @@ class IndyRevRegId(Regexp):
489504
rf"([{B58}]{{21,22}}):3:"
490505
rf"CL:(([1-9][0-9]*)|([{B58}]{{21,22}}:2:.+:[0-9.]+))(:.+)?:"
491506
rf"CL_ACCUM:(.+$)|^((did:indy2)?:.+:[{B58}]{{21,22}})" # issuer DID
492-
f"\/anoncreds\/v0\/REV_REG_DEF\/" # cred def id marker
493-
rf"((did:indy2)?:.+:[{B58}]{{21,22}})" # issuer DID
494-
f"\/anoncreds\/v0\/CLAIM_DEF\/" # cred def id marker
495-
# f":CL" # sig alg
496-
rf"((did:indy2)?:.+:[{B58}]{{21,22}}\/anoncreds\/v0\/SCHEMA\/.+\/[0-9.]+)" # schema txn / id
497-
f"\/(.+)?(:|\/)CL_ACCUM(:|\/).+$"
507+
f"\/anoncreds\/v0\/REV_REG_DEF\/" # cred def id marker
508+
rf"((did:indy2)?:.+:[{B58}]{{21,22}})" # issuer DID
509+
f"\/anoncreds\/v0\/CLAIM_DEF\/" # cred def id marker
510+
# f":CL" # sig alg
511+
rf"((did:indy2)?:.+:[{B58}]{{21,22}}\/anoncreds\/v0\/SCHEMA\/.+\/[0-9.]+)" # schema txn / id
512+
f"\/(.+)?(:|\/)CL_ACCUM(:|\/).+$"
498513
)
499514

500515
def __init__(self):

aries_cloudagent/protocols/connections/v1_0/manager.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Classes to manage connections."""
22

33
import logging
4-
from typing import Optional, Sequence, Tuple, Union, cast
54
import warnings
5+
from typing import Optional, Sequence, Tuple, Union, cast
66

77
from ....connections.base_manager import BaseConnectionManager
88
from ....connections.models.conn_record import ConnRecord
@@ -15,7 +15,7 @@
1515
from ....storage.error import StorageNotFoundError
1616
from ....transport.inbound.receipt import MessageReceipt
1717
from ....wallet.base import BaseWallet
18-
from ....wallet.did_method import SOV
18+
from ....wallet.did_method import INDY2, SOV
1919
from ....wallet.key_type import ED25519
2020
from ...coordinate_mediation.v1_0.manager import MediationManager
2121
from .message_types import ARIES_PROTOCOL as CONN_PROTO
@@ -180,7 +180,10 @@ async def create_invitation(
180180
# FIXME - allow ledger instance to format public DID with prefix?
181181
public_did_did = public_did.did
182182
if bool(IndyDID.PATTERN.match(public_did_did)):
183-
public_did_did = f"did:sov:{public_did.did}"
183+
if public_did.method == INDY2:
184+
public_did_did = f"did:indy2:indy_besu:{public_did.did}"
185+
else:
186+
public_did_did = f"did:sov:{public_did.did}"
184187

185188
invitation = ConnectionInvitation(
186189
label=my_label, did=public_did_did, image_url=image_url

aries_cloudagent/protocols/out_of_band/v1_0/manager.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import asyncio
44
import logging
55
import re
6-
from typing import List, Mapping, NamedTuple, Optional, Sequence, Text, Union
76
import uuid
7+
from typing import List, Mapping, NamedTuple, Optional, Sequence, Text, Union
88

99
from aries_cloudagent.protocols.coordinate_mediation.v1_0.route_manager import (
1010
RouteManager,
@@ -26,7 +26,7 @@
2626
from ....transport.inbound.receipt import MessageReceipt
2727
from ....wallet.base import BaseWallet
2828
from ....wallet.did_info import INVITATION_REUSE_KEY, DIDInfo
29-
from ....wallet.did_method import PEER2, PEER4
29+
from ....wallet.did_method import INDY2, PEER2, PEER4
3030
from ....wallet.key_type import ED25519
3131
from ...connections.v1_0.manager import ConnectionManager
3232
from ...connections.v1_0.messages.connection_invitation import ConnectionInvitation
@@ -42,8 +42,8 @@
4242
from .messages.problem_report import OOBProblemReport
4343
from .messages.reuse import HandshakeReuse
4444
from .messages.reuse_accept import HandshakeReuseAccept
45-
from .messages.service import Service as ServiceMessage
4645
from .messages.service import Service
46+
from .messages.service import Service as ServiceMessage
4747
from .models.invitation import InvitationRecord
4848
from .models.oob_record import OobRecord
4949

@@ -353,6 +353,7 @@ async def handle_did(
353353
mediation_record: Optional[MediationRecord],
354354
) -> CreateResult:
355355
"""Handle use_did invitation creation."""
356+
356357
invi_msg = InvitationMessage(
357358
_id=self.msg_id,
358359
label=self.my_label,
@@ -363,6 +364,7 @@ async def handle_did(
363364
version=self.version,
364365
image_url=self.image_url,
365366
)
367+
366368
endpoint, recipient_keys, routing_keys = await self.oob.resolve_invitation(
367369
did_info.did
368370
)
@@ -412,8 +414,11 @@ async def handle_public(
412414
)
413415

414416
if bool(IndyDID.PATTERN.match(public_did.did)):
417+
did = f"did:sov:{public_did.did}"
418+
if public_did.method == INDY2:
419+
did = f"did:indy2:indy_besu:{public_did.did}"
415420
public_did = DIDInfo(
416-
did=f"did:sov:{public_did.did}",
421+
did=did,
417422
verkey=public_did.verkey,
418423
metadata=public_did.metadata,
419424
method=public_did.method,
@@ -1048,7 +1053,7 @@ async def _perform_handshake(
10481053
# in an out-of-band message (RFC 0434).
10491054
# OR did:peer:2 or did:peer:4.
10501055

1051-
if service.startswith("did:peer"):
1056+
if service.startswith("did:peer") or service.startswith("did:indy2"):
10521057
public_did = service
10531058
if public_did.startswith("did:peer:4"):
10541059
public_did = self.long_did_peer_to_short(public_did)

aries_cloudagent/resolver/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ async def setup(context: InjectionContext):
4343
else:
4444
LOGGER.warning("Ledger is not configured, not loading IndyDIDResolver")
4545

46+
indy2_resolver = ClassProvider(
47+
"aries_cloudagent.resolver.default.indy2.Indy2DIDResolver"
48+
).provide(context.settings, context.injector)
49+
await indy2_resolver.setup(context)
50+
registry.register_resolver(indy2_resolver)
51+
4652
web_resolver = ClassProvider(
4753
"aries_cloudagent.resolver.default.web.WebDIDResolver"
4854
).provide(context.settings, context.injector)

0 commit comments

Comments
 (0)