Skip to content
2 changes: 1 addition & 1 deletion acapy_agent/anoncreds/default/did_web/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,4 @@ async def get_schema_info_by_id(
self, profile: Profile, schema_id: str
) -> AnonCredsSchemaInfo:
"""Get a schema info from the registry."""
return await super().get_schema_info_by_id(schema_id)
return await super().get_schema_info_by_id(profile, schema_id)
4 changes: 2 additions & 2 deletions acapy_agent/anoncreds/issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from .error_messages import ANONCREDS_PROFILE_REQUIRED_MSG
from .events import CredDefFinishedEvent
from .models.credential_definition import CredDef, CredDefResult
from .models.schema import AnonCredsSchema, SchemaResult, SchemaState
from .models.schema import AnonCredsSchema, GetSchemaResult, SchemaResult, SchemaState
from .registry import AnonCredsRegistry

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -379,7 +379,7 @@ async def create_and_register_credential_definition(

async def store_credential_definition(
self,
schema_result: SchemaResult,
schema_result: GetSchemaResult,
cred_def_result: CredDefResult,
cred_def_private: CredentialDefinitionPrivate,
key_proof: KeyCorrectnessProof,
Expand Down
2 changes: 1 addition & 1 deletion acapy_agent/anoncreds/models/credential_offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(
self,
c: Optional[str] = None,
xz_cap: Optional[str] = None,
xr_cap: Sequence[Sequence[str]] = None,
xr_cap: Optional[Sequence[Sequence[str]]] = None,
**kwargs,
):
"""Initialize XR cap for anoncreds key correctness proof."""
Expand Down
2 changes: 1 addition & 1 deletion acapy_agent/anoncreds/models/non_rev_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def covers(self, timestamp: Optional[int] = None) -> bool:
timestamp = timestamp or int(time())
return (self.fro or 0) <= timestamp <= (self.to or timestamp)

def timestamp(self) -> bool:
def timestamp(self) -> int:
"""Return a timestamp that the non-revocation interval covers."""
return self.to or self.fro or int(time())

Expand Down
4 changes: 2 additions & 2 deletions acapy_agent/anoncreds/models/predicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from collections import namedtuple
from enum import Enum
from typing import Any
from typing import Any, Union

Relation = namedtuple("Relation", "fortran wql math yes no")

Expand Down Expand Up @@ -55,7 +55,7 @@ def math(self) -> str:
return self.value.math

@staticmethod
def get(relation: str) -> "Predicate":
def get(relation: str) -> Union["Predicate", None]:
"""Return enum instance corresponding to input relation string."""

for pred in Predicate:
Expand Down
77 changes: 41 additions & 36 deletions acapy_agent/anoncreds/revocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import asyncio
import hashlib
import http
import json
import logging
import os
import time
Expand Down Expand Up @@ -238,7 +237,7 @@ async def store_revocation_registry_definition(
tags={
"cred_def_id": rev_reg_def.cred_def_id,
"state": result.revocation_registry_definition_state.state,
"active": json.dumps(False),
"active": "false",
},
)
await txn.handle.insert(
Expand Down Expand Up @@ -346,7 +345,7 @@ async def set_active_registry(self, rev_reg_def_id: str) -> None:
f"{CATEGORY_REV_REG_DEF} with id {rev_reg_def_id} could not be found"
)

if entry.tags["active"] == json.dumps(True):
if entry.tags["active"] == "true":
# NOTE If there are other registries set as active, we're not
# clearing them if the one we want to be active is already
# active. This probably isn't an issue.
Expand All @@ -357,7 +356,7 @@ async def set_active_registry(self, rev_reg_def_id: str) -> None:
old_active_entries = await txn.handle.fetch_all(
CATEGORY_REV_REG_DEF,
{
"active": json.dumps(True),
"active": "true",
"cred_def_id": cred_def_id,
},
for_update=True,
Expand All @@ -371,7 +370,7 @@ async def set_active_registry(self, rev_reg_def_id: str) -> None:

for old_entry in old_active_entries:
tags = old_entry.tags
tags["active"] = json.dumps(False)
tags["active"] = "false"
await txn.handle.replace(
CATEGORY_REV_REG_DEF,
old_entry.name,
Expand All @@ -380,7 +379,7 @@ async def set_active_registry(self, rev_reg_def_id: str) -> None:
)

tags = entry.tags
tags["active"] = json.dumps(True)
tags["active"] = "true"
await txn.handle.replace(
CATEGORY_REV_REG_DEF,
rev_reg_def_id,
Expand All @@ -407,19 +406,15 @@ async def create_and_register_revocation_list(
"Error retrieving required revocation registry definition data"
) from err

if not rev_reg_def_entry or not rev_reg_def_private_entry:
missing_items = []
if not rev_reg_def_entry:
missing_items.append("revocation registry definition")
if not rev_reg_def_private_entry:
missing_items.append("revocation registry private definition")

if missing_items:
raise AnonCredsRevocationError(
(
"Missing required revocation registry data: "
"revocation registry definition"
if not rev_reg_def_entry
else ""
),
(
"revocation registry private definition"
if not rev_reg_def_private_entry
else ""
),
f"Missing required revocation registry data: {', '.join(missing_items)}"
)

try:
Expand Down Expand Up @@ -484,7 +479,7 @@ async def store_revocation_registry_list(self, result: RevListResult) -> None:
},
tags={
"state": result.revocation_list_state.state,
"pending": json.dumps(False),
"pending": "false",
},
)

Expand Down Expand Up @@ -615,7 +610,7 @@ async def get_revocation_lists_with_pending_revocations(self) -> Sequence[str]:
async with self.profile.session() as session:
rev_list_entries = await session.handle.fetch_all(
CATEGORY_REV_LIST,
{"pending": json.dumps(True)},
{"pending": "true"},
)
except AskarError as err:
raise AnonCredsRevocationError("Error retrieving revocation list") from err
Expand Down Expand Up @@ -742,7 +737,7 @@ async def handle_full_registry(self, rev_reg_def_id: str) -> None:
rev_reg_defs = await session.handle.fetch_all(
CATEGORY_REV_REG_DEF,
{
"active": json.dumps(False),
"active": "false",
"cred_def_id": active_rev_reg_def.value_json["credDefId"],
"state": RevRegDefState.STATE_FINISHED,
},
Expand Down Expand Up @@ -787,9 +782,13 @@ async def handle_full_registry(self, rev_reg_def_id: str) -> None:
tag=str(uuid4()),
max_cred_num=active_rev_reg_def.value_json["value"]["maxCredNum"],
)
LOGGER.info(f"Previous rev_reg_def_id = {rev_reg_def_id}")
LOGGER.info(f"Current rev_reg_def_id = {backup_rev_reg_def_id}")
LOGGER.info(f"Backup reg = {backup_reg.rev_reg_def_id}")
LOGGER.debug(
"Previous rev_reg_def_id = %s.\nCurrent rev_reg_def_id = %s.\n"
"Backup reg = %s",
rev_reg_def_id,
backup_rev_reg_def_id,
backup_reg.rev_reg_def_id,
)

async def decommission_registry(self, cred_def_id: str) -> list:
"""Decommission post-init registries and start the next registry generation."""
Expand Down Expand Up @@ -825,7 +824,7 @@ async def decommission_registry(self, cred_def_id: str) -> list:
for rec in recs:
if rec.name != new_reg.rev_reg_def_id:
tags = rec.tags
tags["active"] = json.dumps(False)
tags["active"] = "false"
tags["state"] = RevRegDefState.STATE_DECOMMISSIONED
await txn.handle.replace(
CATEGORY_REV_REG_DEF,
Expand All @@ -843,9 +842,12 @@ async def decommission_registry(self, cred_def_id: str) -> list:
max_cred_num=active_reg.rev_reg_def.value.max_cred_num,
)

LOGGER.info(f"New registry = {new_reg}")
LOGGER.info(f"Backup registry = {backup_reg}")
LOGGER.debug(f"Decommissioned registries = {recs}")
LOGGER.debug(
"New registry = %s.\nBackup registry = %s.\nDecommissioned registries = %s",
new_reg,
backup_reg,
recs,
)
return recs

async def get_or_create_active_registry(self, cred_def_id: str) -> RevRegDefResult:
Expand All @@ -855,7 +857,7 @@ async def get_or_create_active_registry(self, cred_def_id: str) -> RevRegDefResu
CATEGORY_REV_REG_DEF,
{
"cred_def_id": cred_def_id,
"active": json.dumps(True),
"active": "true",
},
limit=1,
)
Expand Down Expand Up @@ -1419,7 +1421,7 @@ async def revoke_pending_credentials(
rev_info_upd["pending"] = (
list(skipped_crids) if skipped_crids else None
)
tags["pending"] = json.dumps(True if skipped_crids else False)
tags["pending"] = "true" if skipped_crids else "false"
await txn.handle.replace(
CATEGORY_REV_LIST,
revoc_reg_id,
Expand All @@ -1438,17 +1440,20 @@ async def revoke_pending_credentials(
) from err
break

revoked = list(rev_crids)
failed = [str(rev_id) for rev_id in sorted(failed_crids)]

result = RevokeResult(
prev=rev_list,
curr=RevList.from_native(updated_list) if updated_list else None,
revoked=list(rev_crids),
failed=[str(rev_id) for rev_id in sorted(failed_crids)],
revoked=revoked,
failed=failed,
)
LOGGER.info(
"Completed revocation process for registry %s: %d revoked, %d failed",
revoc_reg_id,
len(result.revoked),
len(result.failed),
len(revoked),
len(failed),
)
return result

Expand All @@ -1475,7 +1480,7 @@ async def mark_pending_revocations(self, rev_reg_def_id: str, *crids: int) -> No
value = entry.value_json
value["pending"] = pending
tags = entry.tags
tags["pending"] = json.dumps(True)
tags["pending"] = "true"
await txn.handle.replace(
CATEGORY_REV_LIST,
rev_reg_def_id,
Expand Down Expand Up @@ -1521,7 +1526,7 @@ async def clear_pending_revocations(
value["pending"] = set(value["pending"]) - set(crid_mask)

tags = entry.tags
tags["pending"] = json.dumps(False)
tags["pending"] = "false"
await txn.handle.replace(
CATEGORY_REV_LIST,
rev_reg_def_id,
Expand Down
4 changes: 0 additions & 4 deletions acapy_agent/anoncreds/revocation_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,10 @@ async def on_rev_reg_def(

if auto_create_revocation:
revoc = AnonCredsRevocation(profile)
failed_to_upload_tails = False
try:
await revoc.upload_tails_file(payload.rev_reg_def)
except AnonCredsRevocationError as err:
LOGGER.warning(f"Failed to upload tails file: {err}")
failed_to_upload_tails = True

if failed_to_upload_tails:
payload.options["failed_to_upload"] = True

await revoc.create_and_register_revocation_list(
Expand Down
40 changes: 25 additions & 15 deletions acapy_agent/protocols/endorse_transaction/v1_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@

from uuid_utils import uuid4

from acapy_agent.ledger.merkel_validation.constants import (
ATTRIB,
CLAIM_DEF,
NYM,
REVOC_REG_DEF,
REVOC_REG_ENTRY,
SCHEMA,
)

from ....anoncreds.issuer import AnonCredsIssuer
from ....anoncreds.revocation import AnonCredsRevocation
from ....connections.models.conn_record import ConnRecord
Expand Down Expand Up @@ -824,10 +833,12 @@ async def endorsed_txn_post_processing(
is_anoncreds = self._profile.settings.get("wallet.type") == "askar-anoncreds"

# write the wallet non-secrets record
if ledger_response["result"]["txn"]["type"] == "101":
txn = ledger_response["result"]["txn"]
txn_type = txn["type"]
if txn_type == SCHEMA:
# schema transaction
schema_id = ledger_response["result"]["txnMetadata"]["txnId"]
public_did = ledger_response["result"]["txn"]["metadata"]["from"]
public_did = txn["metadata"]["from"]
meta_data["context"]["schema_id"] = schema_id
meta_data["context"]["public_did"] = public_did

Expand All @@ -840,18 +851,18 @@ async def endorsed_txn_post_processing(
else:
await notify_schema_event(self._profile, schema_id, meta_data)

elif ledger_response["result"]["txn"]["type"] == "102":
elif txn_type == CLAIM_DEF:
# cred def transaction
async with ledger:
try:
schema_seq_no = str(ledger_response["result"]["txn"]["data"]["ref"])
schema_seq_no = str(txn["data"]["ref"])
schema_response = await shield(ledger.get_schema(schema_seq_no))
except (IndyIssuerError, LedgerError) as err:
raise TransactionManagerError(err.roll_up) from err

schema_id = schema_response["id"]
cred_def_id = ledger_response["result"]["txnMetadata"]["txnId"]
issuer_did = ledger_response["result"]["txn"]["metadata"]["from"]
issuer_did = txn["metadata"]["from"]
meta_data["context"]["schema_id"] = schema_id
meta_data["context"]["cred_def_id"] = cred_def_id
meta_data["context"]["issuer_did"] = issuer_did
Expand All @@ -866,7 +877,7 @@ async def endorsed_txn_post_processing(
else:
await notify_cred_def_event(self._profile, cred_def_id, meta_data)

elif ledger_response["result"]["txn"]["type"] == "113":
elif txn_type == REVOC_REG_DEF:
# revocation registry transaction
rev_reg_id = ledger_response["result"]["txnMetadata"]["txnId"]
meta_data["context"]["rev_reg_id"] = rev_reg_id
Expand All @@ -883,10 +894,10 @@ async def endorsed_txn_post_processing(
self._profile, rev_reg_id, meta_data
)

elif ledger_response["result"]["txn"]["type"] == "114":
elif txn_type == REVOC_REG_ENTRY:
# revocation entry transaction
rev_reg_id = ledger_response["result"]["txn"]["data"]["revocRegDefId"]
revoked = ledger_response["result"]["txn"]["data"]["value"].get("revoked", [])
rev_reg_id = txn["data"]["revocRegDefId"]
revoked = txn["data"]["value"].get("revoked", [])
meta_data["context"]["rev_reg_id"] = rev_reg_id
if is_anoncreds:
await AnonCredsRevocation(self._profile).finish_revocation_list(
Expand All @@ -897,16 +908,15 @@ async def endorsed_txn_post_processing(
self._profile, rev_reg_id, meta_data, revoked
)

elif ledger_response["result"]["txn"]["type"] == "1":
elif txn_type == NYM:
# write DID to ledger
did = ledger_response["result"]["txn"]["data"]["dest"]
did = txn["data"]["dest"]
await notify_endorse_did_event(self._profile, did, meta_data)

elif ledger_response["result"]["txn"]["type"] == "100":
elif txn_type == ATTRIB:
# write DID ATTRIB to ledger
did = ledger_response["result"]["txn"]["data"]["dest"]
did = txn["data"]["dest"]
await notify_endorse_did_attrib_event(self._profile, did, meta_data)

else:
# TODO unknown ledger transaction type, just ignore for now ...
pass
self._logger.debug("Unhandled ledger transaction type: %s", txn_type)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from .....messaging.agent_message import AgentMessage, AgentMessageSchema
from ..message_types import ATTACHED_MESSAGE

SCHEMA_TYPE = "101"
PROTOCOL_VERSION = "2"


Expand Down
Loading
Loading