From ef2b031cda6df4a1d9d60369ee474ddfc05eaa24 Mon Sep 17 00:00:00 2001 From: jamshale Date: Tue, 16 Jan 2024 22:44:40 +0000 Subject: [PATCH] Implement scenario when author role not set Signed-off-by: jamshale --- .../anoncreds/default/legacy_indy/registry.py | 34 ++++++++++--------- demo/features/0586-sign-transaction.feature | 4 ++- demo/features/steps/0586-sign-transaction.py | 9 +++-- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/aries_cloudagent/anoncreds/default/legacy_indy/registry.py b/aries_cloudagent/anoncreds/default/legacy_indy/registry.py index c90ec73a4e..fc3de532ed 100644 --- a/aries_cloudagent/anoncreds/default/legacy_indy/registry.py +++ b/aries_cloudagent/anoncreds/default/legacy_indy/registry.py @@ -216,20 +216,26 @@ async def register_schema( } LOGGER.debug("schema value: %s", indy_schema) - # No endorser did then don't need endorsement endorser_did = None - if is_author_role(profile): + create_transaction = options.get("create_transaction_for_endorser", False) + + if is_author_role(profile) or create_transaction: endorser_did, endorser_connection_id = await get_endorser_info( profile, options ) + write_ledger = ( + True if endorser_did is None and not create_transaction else False + ) + + # Get either the transaction or the seq_no or the created schema async with ledger: try: result = await shield( ledger.send_schema_anoncreds( schema_id, indy_schema, - write_ledger=True if endorser_did is None else False, + write_ledger=write_ledger, endorser_did=endorser_did, ) ) @@ -245,13 +251,8 @@ async def register_schema( except (AnonCredsIssuerError, LedgerError) as err: raise AnonCredsRegistrationError("Failed to register schema") from err - meta_data = { - "context": {"schema_id": schema_id, "schema": schema.serialize()}, - "processing": {}, - } - - # Don't need endorsement, so return schema result - if not endorser_did: + # Didn't need endorsement, so return schema result + if write_ledger: return SchemaResult( job_id=None, schema_state=SchemaState( @@ -263,6 +264,12 @@ async def register_schema( schema_metadata={"seqNo": result}, ) + # Need endorsement, so execute transaction flow + meta_data = { + "context": {"schema_id": schema_id, "schema": schema.serialize()}, + "processing": {}, + } + (schema_id, schema_def) = result transaction_manager = TransactionManager(profile) try: @@ -279,12 +286,7 @@ async def register_schema( ( transaction, transaction_request, - ) = await transaction_manager.create_request( - transaction=transaction, - # TODO see if we need to parameterize these params - # expires_time=expires_time, - # endorser_write_txn=endorser_write_txn, - ) + ) = await transaction_manager.create_request(transaction=transaction) except (StorageError, TransactionManagerError) as err: raise AnonCredsRegistrationError( "Transaction manager failed to create request: " + err.roll_up diff --git a/demo/features/0586-sign-transaction.feature b/demo/features/0586-sign-transaction.feature index 49965bf970..b58eb27ca4 100644 --- a/demo/features/0586-sign-transaction.feature +++ b/demo/features/0586-sign-transaction.feature @@ -31,7 +31,9 @@ Feature: RFC 0586 Aries sign (endorse) transactions functions @WalletType_Askar_AnonCreds Examples: | Acme_capabilities | Bob_capabilities | Schema_name | - | --wallet-type askar-anoncreds | --wallet-type askar-anoncreds | anoncreds-testing | + | --wallet-type askar-anoncreds | --wallet-type askar-anoncreds | anoncreds-testing | + | --wallet-type askar-anoncreds | | driverslicense | + | | --wallet-type askar-anoncreds | anoncreds-testing | @T001.1-RFC0586 @GHA diff --git a/demo/features/steps/0586-sign-transaction.py b/demo/features/steps/0586-sign-transaction.py index d9de4c6bca..9020d71e11 100644 --- a/demo/features/steps/0586-sign-transaction.py +++ b/demo/features/steps/0586-sign-transaction.py @@ -111,6 +111,8 @@ def step_impl(context, agent_name, schema_name): ) else: schema_info["schema"]["issuerId"] = context.public_dids["AUTHOR"] + schema_info["options"]["create_transaction_for_endorser"] = True + schema_info["options"]["endorser_connection_id"] = connection_id created_txn = agent_container_POST( agent["agent"], "/anoncreds/schema", @@ -197,8 +199,6 @@ def step_impl(context, agent_name): def step_impl(context, agent_name, schema_name): agent = context.active_agents[agent_name] - schema_info = read_schema_data(schema_name) - schemas = {"schema_ids": []} i = 5 while 0 == len(schemas["schema_ids"]) and i > 0: @@ -208,7 +208,10 @@ def step_impl(context, agent_name, schema_name): assert len(schemas["schema_ids"]) == 1 schema_id = schemas["schema_ids"][0] - schema = agent_container_GET(agent["agent"], "/schemas/" + schema_id) + if agent["agent"].wallet_type != "askar-anoncreds": + agent_container_GET(agent["agent"], "/schemas/" + schema_id) + else: + agent_container_GET(agent["agent"], "/anoncreds/schema/" + schema_id) context.schema_name = schema_name