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

ensure ledger is open for any submission to it #561

Merged
Merged
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
55 changes: 33 additions & 22 deletions aries_cloudagent/ledger/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,20 @@ async def ledger_get_taa(request: web.BaseRequest):
reason += ": missing wallet-type?"
raise web.HTTPForbidden(reason=reason)

taa_info = await ledger.get_txn_author_agreement()
accepted = None
if taa_info["taa_required"]:
accept_record = await ledger.get_latest_txn_author_acceptance()
if accept_record:
accepted = {
"mechanism": accept_record["mechanism"],
"time": accept_record["time"],
}
taa_info["taa_accepted"] = accepted
async with ledger:
try:
taa_info = await ledger.get_txn_author_agreement()
accepted = None
if taa_info["taa_required"]:
accept_record = await ledger.get_latest_txn_author_acceptance()
if accept_record:
accepted = {
"mechanism": accept_record["mechanism"],
"time": accept_record["time"],
}
taa_info["taa_accepted"] = accepted
except LedgerError as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err

return web.json_response({"result": taa_info})

Expand All @@ -268,18 +272,25 @@ async def ledger_accept_taa(request: web.BaseRequest):
raise web.HTTPForbidden(reason=reason)

accept_input = await request.json()
taa_info = await ledger.get_txn_author_agreement()
if not taa_info["taa_required"]:
raise web.HTTPBadRequest(reason=f"Ledger {ledger.pool_name} TAA not available")
taa_record = {
"version": accept_input["version"],
"text": accept_input["text"],
"digest": ledger.taa_digest(accept_input["version"], accept_input["text"]),
}
try:
await ledger.accept_txn_author_agreement(taa_record, accept_input["mechanism"])
except StorageError as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err
async with ledger:
try:
taa_info = await ledger.get_txn_author_agreement()
if not taa_info["taa_required"]:
raise web.HTTPBadRequest(
reason=f"Ledger {ledger.pool_name} TAA not available"
)
taa_record = {
"version": accept_input["version"],
"text": accept_input["text"],
"digest": ledger.taa_digest(
accept_input["version"], accept_input["text"]
),
}
await ledger.accept_txn_author_agreement(
taa_record, accept_input["mechanism"]
)
except (LedgerError, StorageError) as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err

return web.json_response({})

Expand Down
25 changes: 13 additions & 12 deletions aries_cloudagent/verifier/indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,19 @@ async def pre_verify(self, pres_req: dict, pres: dict) -> (PreVerifyResult, str)
if "proof" not in pres:
return (PreVerifyResult.INCOMPLETE, "Missing 'proof'")

for (index, ident) in enumerate(pres["identifiers"]):
if not ident.get("timestamp"):
cred_def_id = ident["cred_def_id"]
cred_def = await self.ledger.get_credential_definition(cred_def_id)
if cred_def["value"].get("revocation"):
return (
PreVerifyResult.INCOMPLETE,
(
f"Missing timestamp in presentation identifier #{index} "
f"for cred def id {cred_def_id}"
),
)
async with self.ledger:
for (index, ident) in enumerate(pres["identifiers"]):
if not ident.get("timestamp"):
cred_def_id = ident["cred_def_id"]
cred_def = await self.ledger.get_credential_definition(cred_def_id)
if cred_def["value"].get("revocation"):
return (
PreVerifyResult.INCOMPLETE,
(
f"Missing timestamp in presentation identifier "
f"#{index} for cred def id {cred_def_id}"
),
)

for (uuid, req_pred) in pres_req["requested_predicates"].items():
try:
Expand Down