Skip to content

Commit

Permalink
Fix issuance date & proof web request
Browse files Browse the repository at this point in the history
Signed-off-by: Sarthak Vijayvergiya <[email protected]>
  • Loading branch information
supersonicwisd1 authored and sarthakvijayvergiya committed Apr 3, 2024
1 parent 9ded95b commit 53c24eb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
indy compatible, attachment is a valid verifiable credential
"""

import datetime
import json
import logging
from typing import Mapping, Tuple
Expand Down Expand Up @@ -36,6 +37,7 @@
from ......multitenant.base import BaseMultitenantManager
from ......revocation_anoncreds.models.issuer_cred_rev_record import IssuerCredRevRecord
from ......storage.base import BaseStorage
from ......wallet.base import BaseWallet
from ...message_types import (
ATTACHMENT_FORMAT,
CRED_20_ISSUE,
Expand Down Expand Up @@ -189,13 +191,18 @@ async def create_offer(
ledger = self.profile.inject(BaseLedger)
cache = self.profile.inject_or(BaseCache)

async with self.profile.session() as session:
wallet = session.inject(BaseWallet)
public_did_info = await wallet.get_public_did()
public_did = public_did_info.did

cred_def_id = await issuer.match_created_credential_definitions(
**cred_proposal_message.attachment(VCDICredFormatHandler.format)
)

async def _create():
offer_json = await issuer.create_credential_offer(cred_def_id)
return json.loads(offer_json)
offer_str = await issuer.create_credential_offer(cred_def_id)
return json.loads(offer_str)

multitenant_mgr = self.profile.inject_or(BaseMultitenantManager)
if multitenant_mgr:
Expand Down Expand Up @@ -254,12 +261,13 @@ async def _create():
{"@vocab": "https://www.w3.org/ns/credentials/issuer-dependent#"},
],
"type": ["VerifiableCredential"],
"issuer": "public_did",
"issuer": public_did,
"credentialSubject": cred_proposal_message.credential_preview.attr_dict(),
"issuanceDate": "2024-01-10T04:44:29.563418Z",
"issuanceDate": datetime.datetime.now(
datetime.timezone.utc
).isoformat(),
},
}

return self.get_format_data(CRED_20_OFFER, vcdi_cred_offer)

async def receive_offer(
Expand Down Expand Up @@ -295,7 +303,6 @@ async def create_request(
"cred_def_id"
]

# workaround for getting schema_id
ledger = self.profile.inject(BaseLedger)
multitenant_mgr = self.profile.inject_or(BaseMultitenantManager)
if multitenant_mgr:
Expand Down Expand Up @@ -404,7 +411,6 @@ async def issue_credential(
"cred_def_id"
]

# workaround for getting schema_id
ledger = self.profile.inject(BaseLedger)
multitenant_mgr = self.profile.inject_or(BaseMultitenantManager)
if multitenant_mgr:
Expand All @@ -421,8 +427,6 @@ async def issue_credential(
async with ledger:
schema_id = await ledger.credential_definition_id2schema_id(cred_def_id)

# IC - the method in AnonCredsIssuer assumes all the data structures are
# in the old "Indy" format ...
legacy_offer = {
"schema_id": schema_id,
"cred_def_id": cred_def_id,
Expand Down Expand Up @@ -464,20 +468,6 @@ async def issue_credential(
"credential": json.loads(credential),
}

# not sure about these ...
# assert detail_credential.credential and isinstance(
# detail_credential.credential, VerifiableCredential
# )
# assert detail_proof.binding_proof and isinstance(
# detail_proof.binding_proof, BindingProof
# )
# try:
# vc = await manager.issue(
# detail_credential.credential, detail_proof.binding_proof
# )
# except VcLdpManagerError as err:
# raise V20CredFormatError("Failed to issue credential") from err

result = self.get_format_data(CRED_20_ISSUE, vcdi_credential)

cred_rev_id = None
Expand Down
25 changes: 17 additions & 8 deletions demo/runners/faber.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def generate_proof_request_web_request(

elif cred_type == CRED_FORMAT_VC_DI:
proof_request_web_request = {
"comment": "test proof request for json-ld",
"comment": "Test proof request for VC-DI format",
"presentation_request": {
"dif": {
"options": {
Expand All @@ -354,16 +354,16 @@ def generate_proof_request_web_request(
"id": "32f54163-7166-48f1-93d8-ff217bdb0654",
"submission_requirements": [
{
"name": "Citizenship Information",
"name": "Degree Verification",
"rule": "pick",
"min": 1,
"from": "A",
}
],
"input_descriptors": [
{
"id": "citizenship_input_1",
"name": "EU Driver's License",
"id": "degree_input_1",
"name": "Degree Certificate",
"group": ["A"],
"schema": [
{
Expand All @@ -378,14 +378,23 @@ def generate_proof_request_web_request(
"fields": [
{
"path": [
"$.credentialSubject.givenName"
"$.credentialSubject.degree.name"
],
"purpose": "We need to verify that you have the required degree.",
"filter": {"type": "string"},
},
{
"path": [
"$.credentialSubject.birthDate"
],
"purpose": "The claim must be from one of the specified issuers",
"purpose": "To ensure you meet the age requirement.",
"filter": {
"type": "string",
"enum": ["JOHN", "CAI"],
"pattern": birth_date.strftime(
birth_date_format
),
},
}
},
],
},
}
Expand Down

0 comments on commit 53c24eb

Please sign in to comment.