Skip to content

Commit

Permalink
refactor: remove extra variables and comments
Browse files Browse the repository at this point in the history
Signed-off-by: EmadAnwer <[email protected]>
  • Loading branch information
EmadAnwer committed Jul 12, 2024
1 parent 0170055 commit 116a992
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 33 deletions.
27 changes: 13 additions & 14 deletions aries_cloudagent/anoncreds/tests/mock_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
},
"requested_predicates": {},
}

CONTEXT = [
"https://www.w3.org/2018/credentials/v1",
"https://w3id.org/security/data-integrity/v2",
{"@vocab": "https://www.w3.org/ns/credentials/issuer-dependent#"},
]
MOCK_W3CPRES = {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://w3id.org/security/data-integrity/v2",
{"@vocab": "https://www.w3.org/ns/credentials/issuer-dependent#"},
],
"@context": CONTEXT,
"type": ["VerifiablePresentation"],
"verifiableCredential": [
{
Expand Down Expand Up @@ -71,12 +71,10 @@
"challenge": "10275921379803826423",
},
}

W3C_CRED_DEF_ID = "DyZ6N8yDTQsdJazNGRG1Wa:3:CL:1255405:faber.agent.degree_schema"
MOCK_W3C_CRED = {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://w3id.org/security/data-integrity/v2",
{"@vocab": "https://www.w3.org/ns/credentials/issuer-dependent#"},
],
"@context": CONTEXT,
"type": ["VerifiableCredential"],
"issuer": "DyZ6N8yDTQsdJazNGRG1Wa",
"credentialSubject": {
Expand All @@ -91,7 +89,7 @@
"cryptosuite": "anoncreds-2023",
"type": "DataIntegrityProof",
"proofPurpose": "assertionMethod",
"verificationMethod": "DyZ6N8yDTQsdJazNGRG1Wa:3:CL:1255405:faber.agent.degree_schema",
"verificationMethod": W3C_CRED_DEF_ID,
"proofValue": "ukgGEqXNjaGVtYV9pZNkvRHlaNk44eURUUXNkSmF6TkdSRzFXYToyOmRlZ3JlZSBzY2hlbWE6OTQuNDYuNzGrY3JlZF9kZWZfaWTZPUR5WjZOOHlEVFFzZE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down Expand Up @@ -128,16 +126,17 @@
}
},
}

CREDS_W3C_METADATA = [
{
"schema_id": "DyZ6N8yDTQsdJazNGRG1Wa:2:degree schema:94.46.71",
"cred_def_id": "DyZ6N8yDTQsdJazNGRG1Wa:3:CL:1255405:faber.agent.degree_schema",
"cred_def_id": W3C_CRED_DEF_ID,
"proof_attrs": ["age-verification_attribute"],
"proof_preds": ["age-verification_predicate_0"],
}
]
CRED_DEFS = {
"DyZ6N8yDTQsdJazNGRG1Wa:3:CL:1255405:faber.agent.degree_schema": {
W3C_CRED_DEF_ID: {
"issuerId": "DyZ6N8yDTQsdJazNGRG1Wa",
"schemaId": "1255405",
"type": "CL",
Expand Down
1 change: 0 additions & 1 deletion aries_cloudagent/anoncreds/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,6 @@ async def verify_presentation_w3c(
) = await anoncreds_verifier.process_pres_identifiers(cred_metadata)

try:
# TODO not sure why this attr causes an error
del pres["presentation_submission"]

presentation = W3cPresentation.load(pres)
Expand Down
25 changes: 10 additions & 15 deletions aries_cloudagent/vc/vc_di/prove.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import asyncio
from hashlib import sha256
import re
from typing import Any, Tuple
from typing import Any, Optional, Tuple

from aries_cloudagent.anoncreds.registry import AnonCredsRegistry
from aries_cloudagent.revocation.models.revocation_registry import RevocationRegistry
from ..ld_proofs import (
AuthenticationProofPurpose,
ProofPurpose,
LinkedDataProofException,
)
Expand All @@ -30,7 +29,7 @@ async def create_signed_anoncreds_presentation(
presentation: dict,
credentials: list,
purpose: ProofPurpose = None,
challenge: str = None,
challenge: str,
domain: str = None,
) -> tuple[dict, dict, list]:
"""Sign the presentation with the passed signature suite.
Expand All @@ -56,13 +55,12 @@ async def create_signed_anoncreds_presentation(
dict: A verifiable presentation object
"""
if not purpose and not challenge:

if not challenge:
raise LinkedDataProofException(
'A "challenge" param is required when not providing a'
' "purpose" (for AuthenticationProofPurpose).'
)
if not purpose:
purpose = AuthenticationProofPurpose(challenge=challenge, domain=domain)

w3c_creds = await _load_w3c_credentials(credentials)
anoncreds_proofrequest, w3c_creds_metadata = await prepare_data_for_presentation(
Expand Down Expand Up @@ -122,7 +120,7 @@ async def create_rev_states(
w3c_creds_metadata: list,
rev_reg_defs: dict,
rev_reg_entries: dict,
) -> dict:
) -> Optional[dict]:
"""create_rev_states.
Args:
Expand Down Expand Up @@ -199,8 +197,8 @@ async def prepare_data_for_presentation(
pres_name = (
pres_definition.get("name") if pres_definition.get("name") else "Proof request"
)
hash = sha256(challenge.encode("utf-8")).hexdigest()
nonce = str(int(hash, 16))[:20]
challenge_hash = sha256(challenge.encode("utf-8")).hexdigest()
nonce = str(int(challenge_hash, 16))[:20]

anoncreds_proofrequest = {
"version": "1.0",
Expand Down Expand Up @@ -237,12 +235,9 @@ async def prepare_data_for_presentation(
] in ("allowed", "required")

non_revoked_interval = None
if requires_revoc_status:
if requires_revoc_status and w3c_cred.rev_reg_id:
anoncreds_registry = profile.inject(AnonCredsRegistry)

if not w3c_cred.rev_reg_id:
pass

result = await anoncreds_registry.get_revocation_list(
profile, w3c_cred.rev_reg_id, None
)
Expand Down Expand Up @@ -344,7 +339,7 @@ def _extract_cred_idx(item_path: str) -> int:
if match:
return int(match.group(1))
else:
raise Exception("No index found in path")
raise AnonCredsHolderError("No index found in path")


def _get_predicate_type_and_value(pred_filter: dict) -> Tuple[str, str]:
Expand Down Expand Up @@ -373,4 +368,4 @@ def _get_predicate_type_and_value(pred_filter: dict) -> Tuple[str, str]:
return (supported_properties[key], pred_filter[key])

# TODO more informative description
raise Exception()
raise AnonCredsHolderError("Unsupported predicate filter")
7 changes: 4 additions & 3 deletions aries_cloudagent/vc/vc_di/verify.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Verifiable Credential and Presentation verification methods."""

from aries_cloudagent.anoncreds.holder import AnonCredsHolderError
from ...core.profile import Profile
from ...anoncreds.verifier import AnonCredsVerifier
from ..ld_proofs import (
Expand All @@ -10,6 +11,7 @@
prepare_data_for_presentation,
_load_w3c_credentials,
)
from anoncreds import AnoncredsError


async def verify_signed_anoncredspresentation(
Expand Down Expand Up @@ -57,6 +59,5 @@ async def verify_signed_anoncredspresentation(
return await anoncreds_verifier.verify_presentation_w3c(
anoncreds_pres_req, presentation, cred_metadata
)
except Exception as e:
raise e
# return PresentationVerificationResult(verified=False, errors=[e])
except AnoncredsError as err:
raise AnonCredsHolderError("Error loading master secret") from err

0 comments on commit 116a992

Please sign in to comment.