Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend presenting_revoked_credential example to ledger-agnostic endpoints using wallet=askar-anoncreds #169

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion acapy_controller/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ def __init__(
self.subwallet_token = subwallet_token
if subwallet_token:
self.headers["Authorization"] = f"Bearer {subwallet_token}"

self._event_queue: Optional[Queue[Event]] = event_queue

self._stack: Optional[AsyncExitStack] = None
Expand Down
65 changes: 60 additions & 5 deletions acapy_controller/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,17 +374,27 @@ async def indy_anoncred_onboard(agent: Controller):

@dataclass
class SchemaResult(Minimal):
"""Result of creating a schema."""
"""Result of creating a schema using /schemas."""

schema_id: str

@dataclass
class SchemaResultAnoncreds(Minimal):
"""Result of creating a schema using /anoncreds/schema."""

schema_state: dict

@dataclass
class CredDefResult(Minimal):
"""Result of creating a credential definition."""

credential_definition_id: str

@dataclass
class CredDefResultAnoncreds(Minimal):
"""Result of creating a credential definition using /anoncreds/credential-definition."""

credential_definition_state: dict

async def indy_anoncred_credential_artifacts(
agent: Controller,
Expand All @@ -394,8 +404,51 @@ async def indy_anoncred_credential_artifacts(
cred_def_tag: Optional[str] = None,
support_revocation: bool = False,
revocation_registry_size: Optional[int] = None,
anoncreds_wallet: bool = False,
issuerID: Optional[str] = None,
):
"""Prepare credential artifacts for indy anoncreds."""

# If using wallet=askar-anoncreds:
if anoncreds_wallet:
if issuerID is None:
raise ControllerError("If using askar-anoncreds wallet, issuerID must be specified.")

schema = (await agent.post(
"/anoncreds/schema",
json={
"schema": {
"attrNames": attributes,
"issuerId": issuerID,
"name": schema_name or "minimal-" + token_hex(8),
"version": schema_version or "1.0",
},
},
response=SchemaResultAnoncreds,
)).schema_state

cred_def = (await agent.post(
"/anoncreds/credential-definition",
json={
"credential_definition": {
"issuerId": issuerID,
"schemaId": schema["schema_id"],
"tag": cred_def_tag or token_hex(8),
},

"options": {
"revocation_registry_size": (
revocation_registry_size if revocation_registry_size else 10
),
"support_revocation": support_revocation,
},
},
response=CredDefResultAnoncreds,
)).credential_definition_state

return schema, cred_def

# If using wallet=askar
schema = await agent.post(
"/schemas",
json={
Expand Down Expand Up @@ -961,6 +1014,7 @@ async def indy_anoncreds_revoke(
publish: bool = False,
notify: bool = True,
notify_version: str = "v1_0",
anoncreds_wallet: bool = False,
):
"""Revoking an Indy credential using revocation revoke.

Expand All @@ -976,7 +1030,7 @@ async def indy_anoncreds_revoke(
# Passes in V10CredentialExchange
if isinstance(cred_ex, V10CredentialExchange):
await issuer.post(
url="/revocation/revoke",
url="{}/revocation/revoke".format("/anoncreds" if anoncreds_wallet else ""),
json={
"connection_id": holder_connection_id,
"rev_reg_id": cred_ex.revoc_reg_id,
Expand All @@ -990,7 +1044,7 @@ async def indy_anoncreds_revoke(
# Passes in V20CredExRecordDetail
elif isinstance(cred_ex, V20CredExRecordDetail) and cred_ex.indy:
await issuer.post(
url="/revocation/revoke",
url="{}/revocation/revoke".format("/anoncreds" if anoncreds_wallet else ""),
json={
"connection_id": holder_connection_id,
"rev_reg_id": cred_ex.indy.rev_reg_id,
Expand All @@ -1013,6 +1067,7 @@ async def indy_anoncreds_publish_revocation(
cred_ex: Union[V10CredentialExchange, V20CredExRecordDetail],
publish: bool = False,
notify: bool = True,
anoncreds_wallet: bool = False,
):
"""Publishing revocation of indy credential.

Expand All @@ -1021,7 +1076,7 @@ async def indy_anoncreds_publish_revocation(
"""
if isinstance(cred_ex, V10CredentialExchange):
await issuer.post(
url="/revocation/publish-revocations",
url="{}/revocation/publish-revocations".format("/anoncreds" if anoncreds_wallet else ""),
json={
"rev_reg_id": cred_ex.revoc_reg_id,
"cred_rev_id": cred_ex.revocation_id,
Expand All @@ -1032,7 +1087,7 @@ async def indy_anoncreds_publish_revocation(

elif isinstance(cred_ex, V20CredExRecordDetail) and cred_ex.indy:
await issuer.post(
url="/revocation/publish-revocations",
url="{}/revocation/publish-revocations".format("/anoncreds" if anoncreds_wallet else ""),
json={
"rev_reg_id": cred_ex.indy.rev_reg_id,
"cred_rev_id": cred_ex.indy.cred_rev_id,
Expand Down
104 changes: 104 additions & 0 deletions examples/presenting_revoked_credential_anoncreds/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
version: "3"
services:
alice:
image: ghcr.io/hyperledger/aries-cloudagent-python:py3.9-0.12.1
# image: acapy-test-image
# build:
# context: .
# dockerfile: Dockerfile.acapy
# args:
# acapy_url: https://github.com/Indicio-tech/aries-cloudagent-python@c1fed3c13d33e65979b08dd1eaf79dc84e3ce504
ports:
- "3003:3001"
command: >
start
--label Alice
--inbound-transport http 0.0.0.0 3000
--outbound-transport http
--endpoint http://alice:3000
--admin 0.0.0.0 3001
--admin-insecure-mode
--tails-server-base-url http://tails:6543
--genesis-url https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_testnet_genesis
--wallet-type askar-anoncreds
--wallet-name alice
--wallet-key insecure
--auto-provision
--log-level debug
--debug-webhooks
--notify-revocation
healthcheck:
test: curl -s -o /dev/null -w '%{http_code}' "http://localhost:3001/status/live" | grep "200" > /dev/null
start_period: 30s
interval: 7s
timeout: 5s
retries: 5
depends_on:
tails:
condition: service_started

bob:
image: ghcr.io/hyperledger/aries-cloudagent-python:py3.9-0.12.1
#image: bcgovimages/aries-cloudagent:py36-1.16-1_0.7.5
#image: bcgovimages/aries-cloudagent:py36-1.16-1_1.0.0-rc0
# image: acapy-test-image
# build:
# context: .
# dockerfile: Dockerfile.acapy
# args:
# acapy_url: https://github.com/Indicio-tech/aries-cloudagent-python@c1fed3c13d33e65979b08dd1eaf79dc84e3ce504
ports:
- "3004:3001"
command: >
start
--label Bob
--inbound-transport http 0.0.0.0 3000
--outbound-transport http
--endpoint http://bob:3000
--admin 0.0.0.0 3001
--admin-insecure-mode
--tails-server-base-url http://tails:6543
--genesis-url https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_testnet_genesis
--wallet-type askar-anoncreds
--wallet-name bob
--wallet-key insecure
--auto-provision
--log-level debug
--debug-webhooks
--monitor-revocation-notification
healthcheck:
test: curl -s -o /dev/null -w '%{http_code}' "http://localhost:3001/status/live" | grep "200" > /dev/null
start_period: 30s
interval: 7s
timeout: 5s
retries: 5

example:
container_name: controller
build:
context: ../..
environment:
- ALICE=http://alice:3001
- BOB=http://bob:3001
volumes:
- ./example.py:/usr/src/app/example.py:ro,z
command: python -m example
depends_on:
alice:
condition: service_healthy
bob:
condition: service_healthy

tails:
image: ghcr.io/bcgov/tails-server:latest
ports:
- 6544:6543
environment:
- GENESIS_URL=https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_testnet_genesis
command: >
tails-server
--host 0.0.0.0
--port 6543
--storage-path /tmp/tails-files
--log-level INFO

Loading
Loading