Skip to content

Commit 33a7849

Browse files
author
Vijay Soni
committed
fixed test errors
Signed-off-by: Vijay Soni <[email protected]>
1 parent 2b53895 commit 33a7849

File tree

5 files changed

+113
-5
lines changed

5 files changed

+113
-5
lines changed

scenarios/examples/did_indy_issuance_and_revocation/example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
didexchange,
1919
indy_anoncred_credential_artifacts,
2020
indy_issue_credential_v2,
21-
indy_present_proof_v2,
2221
params,
2322
)
2423
from aiohttp import ClientSession
24+
from examples.util import indy_present_proof_v2
2525

2626
ALICE = getenv("ALICE", "http://alice:3001")
2727
BOB = getenv("BOB", "http://bob:3001")

scenarios/examples/multitenancy/example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
didexchange,
1515
indy_anoncred_credential_artifacts,
1616
indy_issue_credential_v2,
17-
indy_present_proof_v2,
1817
params,
1918
)
2019
from aiohttp import ClientSession
20+
from examples.util import indy_present_proof_v2
2121

2222
AGENCY = getenv("AGENCY", "http://agency:3001")
2323

scenarios/examples/presenting_revoked_credential/example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
didexchange,
1919
indy_anoncred_credential_artifacts,
2020
indy_issue_credential_v2,
21-
indy_present_proof_v2,
2221
params,
2322
)
2423
from aiohttp import ClientSession
24+
from examples.util import indy_present_proof_v2
2525

2626
ALICE = getenv("ALICE", "http://alice:3001")
2727
BOB = getenv("BOB", "http://bob:3001")

scenarios/examples/simple_restart/example.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
indy_anoncred_credential_artifacts,
1515
indy_anoncred_onboard,
1616
indy_issue_credential_v2,
17-
indy_present_proof_v2,
1817
)
19-
from examples.util import wait_until_healthy
18+
from examples.util import indy_present_proof_v2, wait_until_healthy
2019

2120
import docker
2221

scenarios/examples/util.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Scenario helpers for ACA-Py examples."""
2+
13
import json
24
import time
35
from dataclasses import dataclass
@@ -41,6 +43,7 @@ def wait_until_healthy(client, container_id: str, attempts: int = 350, is_health
4143

4244

4345
def update_wallet_type(agent_command: List, wallet_type: str) -> str:
46+
"""Update the wallet type argument in a CLI command list."""
4447
for i in range(len(agent_command) - 1):
4548
if agent_command[i] == "--wallet-type":
4649
agent_command[i + 1] = wallet_type
@@ -49,6 +52,7 @@ def update_wallet_type(agent_command: List, wallet_type: str) -> str:
4952

5053

5154
def get_wallet_name(agent_command: List) -> str:
55+
"""Return the wallet name argument from a CLI command list."""
5256
for i in range(len(agent_command) - 1):
5357
if agent_command[i] == "--wallet-name":
5458
return agent_command[i + 1]
@@ -204,6 +208,111 @@ def auto_select_credentials_for_presentation_request(
204208
)
205209

206210

211+
async def indy_present_proof_v2(
212+
holder: Controller,
213+
verifier: Controller,
214+
holder_connection_id: str,
215+
verifier_connection_id: str,
216+
*,
217+
name: Optional[str] = None,
218+
version: Optional[str] = None,
219+
comment: Optional[str] = None,
220+
requested_attributes: Optional[List[Mapping[str, Any]]] = None,
221+
requested_predicates: Optional[List[Mapping[str, Any]]] = None,
222+
non_revoked: Optional[Mapping[str, int]] = None,
223+
cred_rev_id: Optional[str] = None,
224+
):
225+
"""Present a credential using present proof v2 (indy)."""
226+
attrs = {
227+
"name": name or "proof",
228+
"version": version or "0.1.0",
229+
"nonce": str(randbelow(10**10)),
230+
"requested_attributes": {
231+
str(uuid4()): attr for attr in requested_attributes or []
232+
},
233+
"requested_predicates": {
234+
str(uuid4()): pred for pred in requested_predicates or []
235+
},
236+
"non_revoked": (non_revoked if non_revoked else None),
237+
}
238+
239+
verifier_pres_ex = await verifier.post(
240+
"/present-proof-2.0/send-request",
241+
json={
242+
"auto_verify": False,
243+
"comment": comment or "Presentation request from minimal",
244+
"connection_id": verifier_connection_id,
245+
"presentation_request": {"indy": attrs},
246+
"trace": False,
247+
},
248+
response=V20PresExRecord,
249+
)
250+
verifier_pres_ex_id = verifier_pres_ex.pres_ex_id
251+
252+
holder_pres_ex = await holder.event_with_values(
253+
topic="present_proof_v2_0",
254+
event_type=V20PresExRecord,
255+
connection_id=holder_connection_id,
256+
state="request-received",
257+
)
258+
holder_pres_ex_id = holder_pres_ex.pres_ex_id
259+
260+
relevant_creds = await holder.get(
261+
f"/present-proof-2.0/records/{holder_pres_ex_id}/credentials",
262+
response=List[CredPrecis],
263+
)
264+
265+
if cred_rev_id:
266+
relevant_creds = [
267+
cred
268+
for cred in relevant_creds
269+
if cred.cred_info._extra.get("cred_rev_id") == cred_rev_id
270+
]
271+
272+
request_payload = _presentation_request_payload(holder_pres_ex)
273+
assert request_payload
274+
if "anoncreds" in request_payload or "indy" in request_payload:
275+
proof_request = request_payload.get("indy") or request_payload.get("anoncreds")
276+
else:
277+
proof_request = request_payload
278+
assert proof_request
279+
pres_spec = auto_select_credentials_for_presentation_request(
280+
proof_request, relevant_creds
281+
)
282+
await holder.post(
283+
f"/present-proof-2.0/records/{holder_pres_ex_id}/send-presentation",
284+
json={"indy": pres_spec.serialize()},
285+
response=V20PresExRecord,
286+
)
287+
288+
await verifier.event_with_values(
289+
topic="present_proof_v2_0",
290+
event_type=V20PresExRecord,
291+
pres_ex_id=verifier_pres_ex_id,
292+
state="presentation-received",
293+
)
294+
await verifier.post(
295+
f"/present-proof-2.0/records/{verifier_pres_ex_id}/verify-presentation",
296+
json={},
297+
response=V20PresExRecord,
298+
)
299+
verifier_pres_ex = await verifier.event_with_values(
300+
topic="present_proof_v2_0",
301+
event_type=V20PresExRecord,
302+
pres_ex_id=verifier_pres_ex_id,
303+
state="done",
304+
)
305+
306+
holder_pres_ex = await holder.event_with_values(
307+
topic="present_proof_v2_0",
308+
event_type=V20PresExRecord,
309+
pres_ex_id=holder_pres_ex_id,
310+
state="done",
311+
)
312+
313+
return holder_pres_ex, verifier_pres_ex
314+
315+
207316
async def anoncreds_issue_credential_v2(
208317
issuer: Controller,
209318
holder: Controller,

0 commit comments

Comments
 (0)