Skip to content

Commit

Permalink
Fix indy fallback format in presentation from holder (openwallet-foun…
Browse files Browse the repository at this point in the history
…dation#3413)

Signed-off-by: jamshale <[email protected]>
  • Loading branch information
jamshale authored Dec 20, 2024
1 parent efe14c7 commit 1aacd1b
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ async def create_pres(
pres_ex_record=pres_ex_record,
requested_credentials=requested_credentials,
)

# This is used for the fallback to indy format. Should be removed when indy
# format retired
if request_data.get("indy"):
return IndyPresExchangeHandler(self.profile).get_format_data(
PRES_20, presentation_proof
)
return self.get_format_data(PRES_20, presentation_proof)

async def receive_pres(self, message: V20Pres, pres_ex_record: V20PresExRecord):
Expand Down
28 changes: 11 additions & 17 deletions scenarios/examples/anoncreds_issuance_and_revocation/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@
"""

import asyncio
import json
from os import getenv
from secrets import token_hex
from typing import Any, Dict, List, Mapping, Optional, Tuple, Type, Union

from acapy_controller import Controller
from acapy_controller.controller import Minimal, MinType
from acapy_controller.logging import logging_to_stdout
from acapy_controller.models import (
CreateWalletResponse,
V20CredExRecordIndy,
V20PresExRecord,
V20PresExRecordList,
)
from acapy_controller.protocols import (
Expand All @@ -25,17 +20,14 @@
params,
)
from aiohttp import ClientSession

from examples.util import (
SchemaResultAnoncreds,
CredDefResultAnoncreds,
anoncreds_presentation_summary,
auto_select_credentials_for_presentation_request,
SchemaResultAnoncreds,
anoncreds_issue_credential_v2,
anoncreds_present_proof_v2,
anoncreds_presentation_summary,
)


AGENCY = getenv("AGENCY", "http://agency:3001")
HOLDER_ANONCREDS = getenv("HOLDER_ANONCREDS", "http://holder_anoncreds:3001")
HOLDER_INDY = getenv("HOLDER_INDY", "http://holder_indy:3001")
Expand All @@ -55,13 +47,15 @@ async def main():
response=CreateWalletResponse,
)

async with Controller(
base_url=AGENCY,
wallet_id=issuer.wallet_id,
subwallet_token=issuer.token,
) as issuer, Controller(base_url=HOLDER_ANONCREDS) as holder_anoncreds, Controller(
base_url=HOLDER_INDY
) as holder_indy:
async with (
Controller(
base_url=AGENCY,
wallet_id=issuer.wallet_id,
subwallet_token=issuer.token,
) as issuer,
Controller(base_url=HOLDER_ANONCREDS) as holder_anoncreds,
Controller(base_url=HOLDER_INDY) as holder_indy,
):
"""
This section of the test script demonstrates the issuance, presentation and
revocation of a credential where both the issuer is not anoncreds capable
Expand Down
88 changes: 47 additions & 41 deletions scenarios/examples/restart_anoncreds_upgrade/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,25 @@
"""

import asyncio
from os import getenv
import json
import time

import docker
from docker.errors import NotFound
from docker.models.containers import Container
from os import getenv

from acapy_controller import Controller
from acapy_controller.logging import logging_to_stdout
from acapy_controller.protocols import (
connection,
didexchange,
indy_anoncred_credential_artifacts,
indy_anoncred_onboard,
indy_anoncreds_publish_revocation,
indy_anoncreds_revoke,
indy_issue_credential_v2,
indy_present_proof_v2,
)

from examples.util import (
healthy,
unhealthy,
wait_until_healthy,
update_wallet_type,
get_wallet_name,
anoncreds_presentation_summary,
auto_select_credentials_for_presentation_request,
anoncreds_issue_credential_v2,
anoncreds_present_proof_v2,
get_wallet_name,
update_wallet_type,
wait_until_healthy,
)

import docker

ALICE = getenv("ALICE", "http://alice:3001")
BOB_ASKAR = getenv("BOB_ASKAR", "http://bob-askar:3001")
Expand Down Expand Up @@ -111,7 +97,7 @@ async def upgrade_wallet_and_shutdown_container(
agent_controller,
agent_container,
):
agent_command = agent_container.attrs['Config']['Cmd']
agent_command = agent_container.attrs["Config"]["Cmd"]

# command is a List, find the wallet type and replace "askar" with "askar-anoncreds"
correct_wallet_type = update_wallet_type(agent_command, "askar-anoncreds")
Expand All @@ -129,7 +115,7 @@ async def upgrade_wallet_and_shutdown_container(
await asyncio.sleep(2)

print(">>> waiting for container to exit ...")
agent_id = agent_container.attrs['Id']
agent_id = agent_container.attrs["Id"]
wait_until_healthy(client, agent_id, is_healthy=False)
agent_container.remove()

Expand All @@ -144,17 +130,17 @@ def start_new_container(
):
print(">>> start new container ...")
new_agent_container = client.containers.run(
'acapy-test',
"acapy-test",
command=agent_command,
detach=True,
environment={'RUST_LOG': 'aries-askar::log::target=error'},
healthcheck=agent_container.attrs['Config']['Healthcheck'],
environment={"RUST_LOG": "aries-askar::log::target=error"},
healthcheck=agent_container.attrs["Config"]["Healthcheck"],
name=agent_label,
network=agent_container.attrs['HostConfig']['NetworkMode'],
ports=agent_container.attrs['NetworkSettings']['Ports'],
network=agent_container.attrs["HostConfig"]["NetworkMode"],
ports=agent_container.attrs["NetworkSettings"]["Ports"],
)
print(">>> new container:", agent_label, json.dumps(new_agent_container.attrs))
new_agent_id = new_agent_container.attrs['Id']
new_agent_id = new_agent_container.attrs["Id"]

wait_until_healthy(client, new_agent_id)
print(">>> new container is healthy")
Expand Down Expand Up @@ -198,7 +184,10 @@ async def main():
alice_conns["askar"] = alice_conn
bob_conns["askar"] = bob_conn

async with Controller(base_url=ALICE) as alice, Controller(base_url=BOB_ANONCREDS) as bob:
async with (
Controller(base_url=ALICE) as alice,
Controller(base_url=BOB_ANONCREDS) as bob,
):
# connect to Bob (Anoncreds wallet) and issue (and revoke) some credentials
(alice_conn, bob_conn) = await connect_agents_and_issue_credentials(
alice,
Expand All @@ -210,7 +199,10 @@ async def main():
alice_conns["anoncreds"] = alice_conn
bob_conns["anoncreds"] = bob_conn

async with Controller(base_url=ALICE) as alice, Controller(base_url=BOB_ASKAR_ANON) as bob:
async with (
Controller(base_url=ALICE) as alice,
Controller(base_url=BOB_ASKAR_ANON) as bob,
):
# connect to Bob (Askar wallet which will be upgraded) and issue (and revoke) some credentials
(alice_conn, bob_conn) = await connect_agents_and_issue_credentials(
alice,
Expand All @@ -229,24 +221,29 @@ async def main():
containers = client.containers.list(all=True)
docker_containers = {}
for container in containers:
if 'com.docker.compose.service' in container.attrs['Config']['Labels']:
container_name = container.attrs['Config']['Labels']['com.docker.compose.service']
container_id = container.attrs['Id']
container_is_running = container.attrs['State']['Running']
docker_containers[container_name] = {'Id': container_id, 'Running': container_is_running}
if "com.docker.compose.service" in container.attrs["Config"]["Labels"]:
container_name = container.attrs["Config"]["Labels"][
"com.docker.compose.service"
]
container_id = container.attrs["Id"]
container_is_running = container.attrs["State"]["Running"]
docker_containers[container_name] = {
"Id": container_id,
"Running": container_is_running,
}
print(">>> container:", container_name, docker_containers[container_name])

alice_docker_container = docker_containers['alice']
alice_container = client.containers.get(alice_docker_container['Id'])
alice_docker_container = docker_containers["alice"]
alice_container = client.containers.get(alice_docker_container["Id"])
async with Controller(base_url=ALICE) as alice:
alice_command = await upgrade_wallet_and_shutdown_container(
client,
alice,
alice_container,
)

bob_docker_container = docker_containers['bob-askar-anon']
bob_container = client.containers.get(bob_docker_container['Id'])
bob_docker_container = docker_containers["bob-askar-anon"]
bob_container = client.containers.get(bob_docker_container["Id"])
async with Controller(base_url=BOB_ASKAR_ANON) as bob:
bob_command = await upgrade_wallet_and_shutdown_container(
client,
Expand Down Expand Up @@ -274,7 +271,10 @@ async def main():
)

# run some more tests ... alice should still be connected to bob for example ...
async with Controller(base_url=ALICE) as alice, Controller(base_url=BOB_ASKAR) as bob:
async with (
Controller(base_url=ALICE) as alice,
Controller(base_url=BOB_ASKAR) as bob,
):
# Present the the credential's attributes
print(">>> present proof ... again ...")
await anoncreds_present_proof_v2(
Expand All @@ -286,7 +286,10 @@ async def main():
)
print(">>> Done! (again)")

async with Controller(base_url=ALICE) as alice, Controller(base_url=BOB_ANONCREDS) as bob:
async with (
Controller(base_url=ALICE) as alice,
Controller(base_url=BOB_ANONCREDS) as bob,
):
# Present the the credential's attributes
print(">>> present proof ... again ...")
await anoncreds_present_proof_v2(
Expand All @@ -298,7 +301,10 @@ async def main():
)
print(">>> Done! (again)")

async with Controller(base_url=ALICE) as alice, Controller(base_url=BOB_ASKAR_ANON) as bob:
async with (
Controller(base_url=ALICE) as alice,
Controller(base_url=BOB_ASKAR_ANON) as bob,
):
# Present the the credential's attributes
print(">>> present proof ... again ...")
await anoncreds_present_proof_v2(
Expand Down
25 changes: 12 additions & 13 deletions scenarios/examples/util.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
import json
import time
from dataclasses import dataclass
from secrets import randbelow
from typing import Any, Dict, List, Mapping, Optional, Tuple, Type, Union
from uuid import uuid4
import time

import docker
from docker.models.containers import Container

from acapy_controller import Controller
from acapy_controller.controller import Minimal, MinType
from acapy_controller.logging import logging_to_stdout
from acapy_controller.models import (
CreateWalletResponse,
V20CredExRecordIndy,
V20PresExRecord,
V20PresExRecordList,
)

from docker.models.containers import Container


# docker utilities:
def healthy(container: Container) -> bool:
"""Check if container is healthy."""
inspect_results = container.attrs
return inspect_results["State"]["Running"] and inspect_results["State"]["Health"]["Status"] == "healthy"
return (
inspect_results["State"]["Running"]
and inspect_results["State"]["Health"]["Status"] == "healthy"
)


def unhealthy(container: Container) -> bool:
Expand All @@ -45,18 +44,18 @@ def wait_until_healthy(client, container_id: str, attempts: int = 350, is_health
raise TimeoutError("Timed out waiting for container")


def update_wallet_type(agent_command: List, wallet_type:str) -> str:
for i in range(len(agent_command)-1):
def update_wallet_type(agent_command: List, wallet_type: str) -> str:
for i in range(len(agent_command) - 1):
if agent_command[i] == "--wallet-type":
agent_command[i+1] = wallet_type
agent_command[i + 1] = wallet_type
return wallet_type
raise Exception("Error unable to upgrade wallet type to askar-anoncreds")


def get_wallet_name(agent_command: List) -> str:
for i in range(len(agent_command)-1):
for i in range(len(agent_command) - 1):
if agent_command[i] == "--wallet-name":
return agent_command[i+1]
return agent_command[i + 1]
raise Exception("Error unable to upgrade wallet type to askar-anoncreds")


Expand Down

0 comments on commit 1aacd1b

Please sign in to comment.