diff --git a/aries_cloudagent/anoncreds/default/did_indy/registry.py b/aries_cloudagent/anoncreds/default/did_indy/registry.py index bf1480721d..2e2833f28a 100644 --- a/aries_cloudagent/anoncreds/default/did_indy/registry.py +++ b/aries_cloudagent/anoncreds/default/did_indy/registry.py @@ -117,7 +117,3 @@ async def update_revocation_list( ) -> RevListResult: """Update a revocation list on the registry.""" raise NotImplementedError() - - async def txn_submit(self, profile: Profile, ledger_transaction: str) -> str: - """Submit a transaction to the ledger.""" - raise NotImplementedError() diff --git a/aries_cloudagent/anoncreds/default/did_web/registry.py b/aries_cloudagent/anoncreds/default/did_web/registry.py index c0480b81c7..70730cfd21 100644 --- a/aries_cloudagent/anoncreds/default/did_web/registry.py +++ b/aries_cloudagent/anoncreds/default/did_web/registry.py @@ -112,7 +112,3 @@ async def update_revocation_list( ) -> RevListResult: """Update a revocation list on the registry.""" raise NotImplementedError() - - async def txn_submit(self, profile: Profile, ledger_transaction: str) -> str: - """Submit a transaction to the ledger.""" - raise NotImplementedError() diff --git a/aries_cloudagent/anoncreds/default/legacy_indy/registry.py b/aries_cloudagent/anoncreds/default/legacy_indy/registry.py index 9b669c8a73..21988baebd 100644 --- a/aries_cloudagent/anoncreds/default/legacy_indy/registry.py +++ b/aries_cloudagent/anoncreds/default/legacy_indy/registry.py @@ -7,14 +7,7 @@ from base58 import alphabet -from aries_cloudagent.anoncreds.default.legacy_indy.author import get_endorser_info -from aries_cloudagent.protocols.endorse_transaction.v1_0.manager import ( - TransactionManager, - TransactionManagerError, -) -from aries_cloudagent.protocols.endorse_transaction.v1_0.util import is_author_role -from aries_cloudagent.storage.error import StorageError - +from ....anoncreds.default.legacy_indy.author import get_endorser_info from ....cache.base import BaseCache from ....config.injection_context import InjectionContext from ....core.profile import Profile @@ -30,8 +23,18 @@ IndyLedgerRequestsExecutor, ) from ....multitenant.base import BaseMultitenantManager -from ....revocation_anoncreds.models.issuer_cred_rev_record import IssuerCredRevRecord +from ....protocols.endorse_transaction.v1_0.manager import ( + TransactionManager, + TransactionManagerError, +) +from ....protocols.endorse_transaction.v1_0.util import is_author_role +from ....revocation_anoncreds.models.issuer_cred_rev_record import ( + IssuerCredRevRecord, +) from ....revocation_anoncreds.recover import generate_ledger_rrrecovery_txn +from ....storage.error import StorageError +from ....utils import sentinel +from ....wallet.did_info import DIDInfo from ...base import ( AnonCredsObjectAlreadyExists, AnonCredsObjectNotFound, @@ -823,7 +826,15 @@ async def fix_ledger_entry( return (rev_reg_delta, recovery_txn, applied_txn) - async def txn_submit(self, profile: Profile, ledger_transaction: str) -> str: + async def txn_submit( + self, + profile: Profile, + ledger_transaction: str, + sign: bool = None, + taa_accept: bool = None, + sign_did: DIDInfo = sentinel, + write_ledger: bool = True, + ) -> str: """Submit a transaction to the ledger.""" ledger = profile.inject(BaseLedger) @@ -832,7 +843,13 @@ async def txn_submit(self, profile: Profile, ledger_transaction: str) -> str: try: return await shield( - ledger.txn_submit(ledger_transaction, sign=False, taa_accept=False) + ledger.txn_submit( + ledger_transaction, + sign=sign, + taa_accept=taa_accept, + sign_did=sign_did, + write_ledger=write_ledger, + ) ) except LedgerError as err: raise AnonCredsRegistrationError(err.roll_up) from err diff --git a/aries_cloudagent/anoncreds/registry.py b/aries_cloudagent/anoncreds/registry.py index 74d5144b70..b1b84e3eb4 100644 --- a/aries_cloudagent/anoncreds/registry.py +++ b/aries_cloudagent/anoncreds/registry.py @@ -1,5 +1,4 @@ """AnonCreds Registry.""" -import json import logging from typing import List, Optional, Sequence @@ -185,10 +184,3 @@ async def update_revocation_list( return await registrar.update_revocation_list( profile, rev_reg_def, prev_list, curr_list, revoked, options ) - - async def txn_submit(self, profile: Profile, ledger_transaction: str) -> str: - """Submit a transaction to the ledger.""" - registrar = await self._registrar_for_identifier( - json.loads(ledger_transaction)["endorser"] - ) - return await registrar.txn_submit(profile, ledger_transaction) diff --git a/aries_cloudagent/ledger/base.py b/aries_cloudagent/ledger/base.py index 9c1f8efff3..2943f03bf2 100644 --- a/aries_cloudagent/ledger/base.py +++ b/aries_cloudagent/ledger/base.py @@ -591,6 +591,9 @@ async def send_schema_anoncreds( attribute_names: A list of schema attributes """ + from aries_cloudagent.anoncreds.default.legacy_indy.registry import ( + LegacyIndyRegistry, + ) public_info = await self.get_wallet_public_did() if not public_info: @@ -628,7 +631,9 @@ async def send_schema_anoncreds( ) try: - resp = await self.txn_submit( + legacy_indy_registry = LegacyIndyRegistry() + resp = await legacy_indy_registry.txn_submit( + self.profile, schema_req, sign=True, sign_did=public_info, diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/manager.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/manager.py index 60a864db9f..a8acbdfb81 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/manager.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/manager.py @@ -5,9 +5,7 @@ import uuid from asyncio import shield -from aries_cloudagent.anoncreds.events import notify_anoncreds_schema_event -from aries_cloudagent.anoncreds.registry import AnonCredsRegistry - +from ....anoncreds.events import notify_anoncreds_schema_event from ....connections.models.conn_record import ConnRecord from ....core.error import BaseError from ....core.profile import Profile @@ -420,9 +418,13 @@ async def complete_transaction( self._profile.context.settings.get_value("wallet.type") == "askar-anoncreds" ): - anoncreds_registry = self._profile.inject(AnonCredsRegistry) - ledger_response_json = await anoncreds_registry.txn_submit( - self._profile, ledger_transaction + from aries_cloudagent.anoncreds.default.legacy_indy.registry import ( + LegacyIndyRegistry, + ) + + legacy_indy_registry = LegacyIndyRegistry() + ledger_response_json = await legacy_indy_registry.txn_submit( + self._profile, ledger_transaction, sign=False, taa_accept=False ) else: ledger = self._profile.inject(BaseLedger) diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py index db1ac44d9c..8a00878368 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py @@ -3,15 +3,14 @@ import uuid from unittest import IsolatedAsyncioTestCase -from aries_cloudagent.anoncreds.registry import AnonCredsRegistry -from aries_cloudagent.tests import mock - from .....admin.request_context import AdminRequestContext +from .....anoncreds.default.legacy_indy.registry import LegacyIndyRegistry from .....cache.base import BaseCache from .....cache.in_memory import InMemoryCache from .....connections.models.conn_record import ConnRecord from .....ledger.base import BaseLedger from .....storage.error import StorageNotFoundError +from .....tests import mock from .....wallet.base import BaseWallet from .....wallet.did_method import SOV, DIDMethods from .....wallet.key_type import ED25519 @@ -498,23 +497,21 @@ async def test_complete_transaction(self): assert transaction_record.state == TransactionRecord.STATE_TRANSACTION_ACKED - async def test_complete_transaction_anoncreds(self): + @mock.patch.object( + LegacyIndyRegistry, + "txn_submit", + return_value=json.dumps( + { + "result": { + "txn": {"type": "101", "metadata": {"from": TEST_DID}}, + "txnMetadata": {"txnId": SCHEMA_ID}, + } + } + ), + ) + async def test_complete_transaction_anoncreds(self, mock_txn_submit): self.profile.settings.set_value("wallet.type", "askar-anoncreds") - self.profile.context.injector.bind_instance( - AnonCredsRegistry, - mock.MagicMock( - txn_submit=mock.CoroutineMock( - return_value=json.dumps( - { - "result": { - "txn": {"type": "101", "metadata": {"from": TEST_DID}}, - "txnMetadata": {"txnId": SCHEMA_ID}, - } - } - ) - ) - ), - ) + transaction_record = await self.manager.create_record( messages_attach=self.test_messages_attach, connection_id=self.test_connection_id, @@ -548,10 +545,7 @@ async def test_complete_transaction_anoncreds(self): save_record.assert_called_once() assert transaction_record.state == TransactionRecord.STATE_TRANSACTION_ACKED - # txn submit called from anoncreds registry - assert self.profile.context._injector.get_provider( - AnonCredsRegistry - )._instance.txn_submit.called + assert mock_txn_submit.called async def test_create_refuse_response_bad_state(self): transaction_record = await self.manager.create_record(