Skip to content

Commit

Permalink
Merge branch 'main' into bbs_context
Browse files Browse the repository at this point in the history
  • Loading branch information
swcurran authored Jan 30, 2024
2 parents 5c5744d + 0b25f51 commit c3f0e7c
Show file tree
Hide file tree
Showing 16 changed files with 516 additions and 548 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/blackformat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ jobs:
with:
python-version: "3.9"
- name: Black Code Formatter Check
uses: psf/black@stable
# The version of black should be adjusted at the same time dev
# dependencies are updated.
uses: psf/black@24.1.1
7 changes: 4 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ repos:
args: ["--config", ".commitlint.config.js"]
additional_dependencies: ['@commitlint/config-conventional']
- repo: https://github.com/psf/black
rev: 23.7.0
# Ensure this is synced with pyproject.toml
rev: 24.1.1
hooks:
- id: black
stages: [commit]
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.0.285
# Ensure this is synced with pyproject.toml
rev: v0.1.2
hooks:
- id: ruff
stages: [commit]
Expand Down
2 changes: 0 additions & 2 deletions aries_cloudagent/ledger/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,8 @@ async def register_ledger_nym(request: web.BaseRequest):
if endorser_write_txn
else None
),
endorser_write_txn=endorser_write_txn,
# TODO see if we need to parameterize these params
# expires_time=expires_time,
# endorser_write_txn=endorser_write_txn,
)
txn = transaction.serialize()
except (StorageError, TransactionManagerError) as err:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ async def credential_definitions_send_credential_definition(request: web.BaseReq
transaction=transaction,
# TODO see if we need to parameterize these params
# expires_time=expires_time,
# endorser_write_txn=endorser_write_txn,
)
except (StorageError, TransactionManagerError) as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err
Expand Down
1 change: 0 additions & 1 deletion aries_cloudagent/messaging/schemas/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ async def schemas_send_schema(request: web.BaseRequest):
transaction=transaction,
# TODO see if we need to parameterize these params
# expires_time=expires_time,
# endorser_write_txn=endorser_write_txn,
)
except (StorageError, TransactionManagerError) as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
mgr = TransactionManager(context.profile)
try:
transaction = await mgr.receive_endorse_response(context.message)
except TransactionManagerError:
except TransactionManagerError as err:
self._logger.exception("Error receiving endorsed transaction response")
raise HandlerException(str(err))

# Automatically write transaction if flag is set
if context.settings.get("endorser.auto_write"):
Expand All @@ -52,3 +53,4 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
)
except (StorageError, TransactionManagerError) as err:
self._logger.exception(err)
raise HandlerException(str(err))
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ async def test_called_x(self):
request_context.connection_ready = True
handler = test_module.EndorsedTransactionResponseHandler()
responder = MockResponder()
await handler.handle(request_context, responder)
with self.assertRaises(test_module.HandlerException):
await handler.handle(request_context, responder)

mock_tran_mgr.return_value.receive_endorse_response.assert_called_once_with(
request_context.message
)
assert not responder.messages
50 changes: 24 additions & 26 deletions aries_cloudagent/protocols/endorse_transaction/v1_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async def create_request(
signature: str = None,
signed_request: dict = None,
expires_time: str = None,
endorser_write_txn: bool = None,
endorser_write_txn: bool = False,
author_goal_code: str = None,
signer_goal_code: str = None,
):
Expand Down Expand Up @@ -207,8 +207,6 @@ async def receive_request(self, request: TransactionRequest, connection_id: str)

return transaction

# todo - implementing changes for writing final transaction to the ledger
# (For Sign Transaction Protocol)
async def create_endorse_response(
self,
transaction: TransactionRecord,
Expand Down Expand Up @@ -331,19 +329,12 @@ async def create_endorse_response(
transaction.endorser_write_txn
and txn_goal_code == TransactionRecord.ENDORSE_TRANSACTION
):
# running as the endorser, we've been asked to write the transaction
ledger_response = await self.complete_transaction(transaction, True)
endorsed_transaction_response = EndorsedTransactionResponse(
transaction_id=transaction.thread_id,
thread_id=transaction._id,
signature_response=signature_response,
state=TransactionRecord.STATE_TRANSACTION_ACKED,
endorser_did=endorser_did,
ledger_response=ledger_response,
# no longer supported - if the author asks the endorser to write
# the transaction, raise an error
raise TransactionManagerError(
"Operation not supported, endorser cannot write the ledger transaction"
)

return transaction, endorsed_transaction_response

endorsed_transaction_response = EndorsedTransactionResponse(
transaction_id=transaction.thread_id,
thread_id=transaction._id,
Expand Down Expand Up @@ -385,14 +376,10 @@ async def receive_endorse_response(self, response: EndorsedTransactionResponse):
await transaction.save(session, reason="Received an endorsed response")

# this scenario is where the author has asked the endorser to write the ledger
# we are not supporting endorser ledger writes ...
if transaction.endorser_write_txn:
connection_id = transaction.connection_id
async with self._profile.session() as session:
connection_record = await ConnRecord.retrieve_by_id(
session, connection_id
)
await self.endorsed_txn_post_processing(
transaction, response.ledger_response, connection_record
raise TransactionManagerError(
"Endorser ledger writes are no longer supported"
)

return transaction
Expand All @@ -415,9 +402,18 @@ async def complete_transaction(

ledger_transaction = transaction.messages_attach[0]["data"]["json"]

# check if we (author) have requested the endorser to write the transaction
if (endorser and transaction.endorser_write_txn) or (
(not endorser) and (not transaction.endorser_write_txn)
# check our goal code!
txn_goal_code = (
transaction.signature_request[0]["signer_goal_code"]
if transaction.signature_request
and "signer_goal_code" in transaction.signature_request[0]
else TransactionRecord.ENDORSE_TRANSACTION
)

# if we are the author, we need to write the endorsed ledger transaction ...
# ... EXCEPT for DID transactions, which the endorser will write
if (not endorser) and (
txn_goal_code != TransactionRecord.WRITE_DID_TRANSACTION
):
ledger = self._profile.inject(BaseLedger)
if not ledger:
Expand Down Expand Up @@ -447,9 +443,11 @@ async def complete_transaction(
await transaction.save(session, reason="Completed transaction")

# this scenario is where the endorser is writing the transaction
# (called from self.create_endorse_response())
# shouldn't get to this point, but check and raise an error just in case
if endorser and transaction.endorser_write_txn:
return ledger_response
raise TransactionManagerError(
"Operation not supported, endorser cannot write the ledger transaction"
)

connection_id = transaction.connection_id
async with self._profile.session() as session:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ class Meta:
required=False,
metadata={
"description": (
"If True, Endorser will write the transaction after endorsing it"
"Request Endorser to write the ledger transaction, "
"this parameter is deprecated and no longer supported."
),
"example": True,
"example": False,
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,9 @@ class Meta:
required=False,
metadata={
"description": (
"If True, Endorser will write the transaction after endorsing it"
"Request Endorser to write the ledger transaction, "
"this parameter is deprecated and no longer supported."
),
"example": True,
"example": False,
},
)
15 changes: 1 addition & 14 deletions aries_cloudagent/protocols/endorse_transaction/v1_0/routes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Endorse Transaction handling admin routes."""

import json
import logging

from aiohttp import web
Expand Down Expand Up @@ -116,17 +115,6 @@ class DateSchema(OpenAPISchema):
)


class EndorserWriteLedgerTransactionSchema(OpenAPISchema):
"""Sets endorser_write_txn. Option for the endorser to write the transaction."""

endorser_write_txn = fields.Boolean(
required=False,
metadata={
"description": "Endorser will write the transaction after endorsing it"
},
)


class EndorserInfoSchema(OpenAPISchema):
"""Class for user to input the DID associated with the requested endorser."""

Expand Down Expand Up @@ -203,7 +191,6 @@ async def transactions_retrieve(request: web.BaseRequest):
summary="For author to send a transaction request",
)
@querystring_schema(TranIdMatchInfoSchema())
@querystring_schema(EndorserWriteLedgerTransactionSchema())
@request_schema(DateSchema())
@response_schema(TransactionRecordSchema(), 200)
async def transaction_create_request(request: web.BaseRequest):
Expand All @@ -218,7 +205,7 @@ async def transaction_create_request(request: web.BaseRequest):
context: AdminRequestContext = request["context"]
outbound_handler = request["outbound_message_router"]
transaction_id = request.query.get("tran_id")
endorser_write_txn = json.loads(request.query.get("endorser_write_txn", "false"))
endorser_write_txn = False

body = await request.json()
expires_time = body.get("expires_time")
Expand Down
4 changes: 0 additions & 4 deletions aries_cloudagent/revocation/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,6 @@ async def send_rev_reg_def(request: web.BaseRequest):
transaction=transaction,
# TODO see if we need to parameterize these params
# expires_time=expires_time,
# endorser_write_txn=endorser_write_txn,
)
except (StorageError, TransactionManagerError) as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err
Expand Down Expand Up @@ -1388,7 +1387,6 @@ async def send_rev_reg_entry(request: web.BaseRequest):
transaction=transaction,
# TODO see if we need to parameterize these params
# expires_time=expires_time,
# endorser_write_txn=endorser_write_txn,
)
except (StorageError, TransactionManagerError) as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err
Expand Down Expand Up @@ -1543,7 +1541,6 @@ async def generate(rr_record: IssuerRevRegRecord) -> dict:
transaction=revo_transaction,
# TODO see if we need to parameterize these params
# expires_time=expires_time,
# endorser_write_txn=endorser_write_txn,
)
except (StorageError, TransactionManagerError) as err:
raise TransactionManagerError(reason=err.roll_up) from err
Expand Down Expand Up @@ -1625,7 +1622,6 @@ async def on_revocation_entry_event(profile: Profile, event: Event):
transaction=revo_transaction,
# TODO see if we need to parameterize these params
# expires_time=expires_time,
# endorser_write_txn=endorser_write_txn,
)
except (StorageError, TransactionManagerError) as err:
raise RevocationError(err.roll_up) from err
Expand Down
3 changes: 0 additions & 3 deletions aries_cloudagent/wallet/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,6 @@ async def wallet_set_public_did(request: web.BaseRequest):
transaction=transaction,
# TODO see if we need to parameterize these params
# expires_time=expires_time,
# endorser_write_txn=endorser_write_txn,
)
except (StorageError, TransactionManagerError) as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err
Expand Down Expand Up @@ -975,7 +974,6 @@ async def wallet_set_did_endpoint(request: web.BaseRequest):
transaction=transaction,
# TODO see if we need to parameterize these params
# expires_time=expires_time,
# endorser_write_txn=endorser_write_txn,
)
except (StorageError, TransactionManagerError) as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err
Expand Down Expand Up @@ -1233,7 +1231,6 @@ async def on_register_nym_event(profile: Profile, event: Event):
transaction=transaction,
# TODO see if we need to parameterize these params
# expires_time=expires_time,
# endorser_write_txn=endorser_write_txn,
)
except (StorageError, TransactionManagerError) as err:
# log the error, but continue
Expand Down
1 change: 1 addition & 0 deletions demo/features/0586-sign-transaction.feature
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,4 @@ Feature: RFC 0586 Aries sign (endorse) transactions functions
Examples:
| Acme_capabilities | Bob_capabilities | Schema_name | Credential_data |
| --endorser-role endorser --revocation --public-did | --endorser-role author --revocation | driverslicense | Data_DL_NormalizedValues |
| --endorser-role endorser --revocation --public-did | --endorser-role author --revocation --multitenant | driverslicense | Data_DL_NormalizedValues |
Loading

0 comments on commit c3f0e7c

Please sign in to comment.