Skip to content

Commit

Permalink
feat: added did:web support
Browse files Browse the repository at this point in the history
  • Loading branch information
aritroCoder committed Aug 12, 2024
1 parent d3afb37 commit 32f115c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ async def _get_issue_suite(
verkey_id_strategy = self.profile.context.inject(BaseVerificationKeyStrategy)
verification_method = (
await verkey_id_strategy.get_verification_method_id_for_did(
issuer_id, self.profile, proof_purpose="assertionMethod"
issuer_id,
self.profile,
proof_type=self.proof_type,
proof_purpose="assertionMethod",
)
)

Expand Down
2 changes: 1 addition & 1 deletion aries_cloudagent/vc/vc_ld/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ async def _get_suite_for_document(
verification_method = (
options.verification_method
or await verkey_id_strategy.get_verification_method_id_for_did(
issuer_id, self.profile, proof_purpose="assertionMethod"
issuer_id, self.profile, proof_type, proof_purpose="assertionMethod"
)
)

Expand Down
23 changes: 18 additions & 5 deletions aries_cloudagent/wallet/default_verification_key_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ async def get_verification_method_id_for_did(
self,
did: str,
profile: Optional[Profile],
proof_type: Optional[str] = None,
allowed_verification_method_types: Optional[List[KeyType]] = None,
proof_purpose: Optional[str] = None,
) -> Optional[str]:
Expand All @@ -40,11 +41,18 @@ class DefaultVerificationKeyStrategy(BaseVerificationKeyStrategy):
Supports did:key: and did:sov only.
"""
def __init__(self):
"""Initialize the key types mapping."""
self.key_types_mapping = {
"Ed25519Signature2018": ["Ed25519VerificationKey2018"],
"Ed25519Signature2020": ["Ed25519VerificationKey2020", "Multikey"],
}

async def get_verification_method_id_for_did(
self,
did: str,
profile: Optional[Profile],
proof_type: Optional[str] = None,
allowed_verification_method_types: Optional[List[KeyType]] = None,
proof_purpose: Optional[str] = None,
) -> Optional[str]:
Expand All @@ -66,9 +74,14 @@ async def get_verification_method_id_for_did(
elif did.startswith("did:web:"):
did_resolver = profile.inject(DIDResolver)
did_document = await did_resolver.resolve(profile=profile, did=did)
# Get the verification method ID from the DID document
# take first verification method for now
verification_method_list = did_document.get("verificationMethod", {})
verification_method_id = verification_method_list[0].get("id")
return verification_method_id
if proof_type:
verification_method_types = self.key_types_mapping[proof_type]
verification_method_list = did_document.get("verificationMethod", None)
for method in verification_method_list:
if method.get("type") in verification_method_types:
return method.get("id")
else:
# taking the first verification method from did document
verification_method_id = verification_method_list[0].get("id")
return verification_method_id
return None

0 comments on commit 32f115c

Please sign in to comment.