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

Endorser support for updating DID endpoints on ledger #1696

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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repos:
args: ["--config", ".commitlint.config.js"]
additional_dependencies: ['@commitlint/config-conventional']
- repo: https://github.com/psf/black
rev: 20.8b1
rev: 22.3.0
hooks:
- id: black
stages: [commit]
Expand Down
2 changes: 2 additions & 0 deletions aries_cloudagent/ledger/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ async def update_endpoint_for_did(
did: str,
endpoint: str,
endpoint_type: EndpointType = EndpointType.ENDPOINT,
write_ledger: bool = True,
endorser_did: str = None,
) -> bool:
"""Check and update the endpoint on the ledger.

Expand Down
27 changes: 26 additions & 1 deletion aries_cloudagent/ledger/indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,12 @@ async def get_endpoint_for_did(
return address

async def update_endpoint_for_did(
self, did: str, endpoint: str, endpoint_type: EndpointType = None
self,
did: str,
endpoint: str,
endpoint_type: EndpointType = None,
write_ledger: bool = True,
endorser_did: str = None,
) -> bool:
"""Check and update the endpoint on the ledger.

Expand All @@ -897,6 +902,12 @@ async def update_endpoint_for_did(
endpoint: The endpoint address
endpoint_type: The type of the endpoint
"""
public_info = await self.get_wallet_public_did()
if not public_info:
raise BadLedgerRequestError(
"Cannot update endpoint at ledger without a public DID"
)

if not endpoint_type:
endpoint_type = EndpointType.ENDPOINT

Expand Down Expand Up @@ -925,6 +936,20 @@ async def update_endpoint_for_did(
request_json = await indy.ledger.build_attrib_request(
nym, nym, None, attr_json, None
)

if endorser_did and not write_ledger:
request_json = await indy.ledger.append_request_endorser(
request_json, endorser_did
)
resp = await self._submit(
request_json,
True,
sign_did=public_info,
write_ledger=write_ledger,
)
if not write_ledger:
return {"signed_txn": resp}

await self._submit(request_json, True, True)
return True
return False
Expand Down
25 changes: 24 additions & 1 deletion aries_cloudagent/ledger/indy_vdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,12 @@ async def get_endpoint_for_did(
return address

async def update_endpoint_for_did(
self, did: str, endpoint: str, endpoint_type: EndpointType = None
self,
did: str,
endpoint: str,
endpoint_type: EndpointType = None,
write_ledger: bool = True,
endorser_did: str = None,
) -> bool:
"""Check and update the endpoint on the ledger.

Expand All @@ -902,6 +907,12 @@ async def update_endpoint_for_did(
endpoint: The endpoint address
endpoint_type: The type of the endpoint
"""
public_info = await self.get_wallet_public_did()
if not public_info:
raise BadLedgerRequestError(
"Cannot update endpoint at ledger without a public DID"
)

if not endpoint_type:
endpoint_type = EndpointType.ENDPOINT

Expand Down Expand Up @@ -930,6 +941,18 @@ async def update_endpoint_for_did(
attrib_req = ledger.build_attrib_request(
nym, nym, None, attr_json, None
)

if endorser_did and not write_ledger:
attrib_req.set_endorser(endorser_did)
resp = await self._submit(
attrib_req,
True,
sign_did=public_info,
write_ledger=write_ledger,
)
if not write_ledger:
return {"signed_txn": resp}

except VdrError as err:
raise LedgerError("Exception when building attribute request") from err

Expand Down
12 changes: 11 additions & 1 deletion aries_cloudagent/wallet/askar.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@ async def set_did_endpoint(
endpoint: str,
ledger: BaseLedger,
endpoint_type: EndpointType = None,
write_ledger: bool = True,
endorser_did: str = None,
):
"""
Update the endpoint for a DID in the wallet, send to ledger if public or posted.
Expand Down Expand Up @@ -478,7 +480,15 @@ async def set_did_endpoint(
)
if not ledger.read_only:
async with ledger:
await ledger.update_endpoint_for_did(did, endpoint, endpoint_type)
attrib_def = await ledger.update_endpoint_for_did(
did,
endpoint,
endpoint_type,
write_ledger=write_ledger,
endorser_did=endorser_did,
)
if not write_ledger:
return attrib_def

await self.replace_local_did_metadata(did, metadata)

Expand Down
2 changes: 2 additions & 0 deletions aries_cloudagent/wallet/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ async def set_did_endpoint(
endpoint: str,
_ledger: BaseLedger,
endpoint_type: EndpointType = None,
write_ledger: bool = True,
endorser_did: str = None,
):
"""
Update the endpoint for a DID in the wallet, send to ledger if public or posted.
Expand Down
12 changes: 11 additions & 1 deletion aries_cloudagent/wallet/indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,8 @@ async def set_did_endpoint(
endpoint: str,
ledger: BaseLedger,
endpoint_type: EndpointType = None,
write_ledger: bool = True,
endorser_did: str = None,
):
"""
Update the endpoint for a DID in the wallet, send to ledger if public or posted.
Expand Down Expand Up @@ -738,7 +740,15 @@ async def set_did_endpoint(
)
if not ledger.read_only:
async with ledger:
await ledger.update_endpoint_for_did(did, endpoint, endpoint_type)
attrib_def = await ledger.update_endpoint_for_did(
did,
endpoint,
endpoint_type,
write_ledger=write_ledger,
endorser_did=endorser_did,
)
if not write_ledger:
return attrib_def

await self.replace_local_did_metadata(did, metadata)

Expand Down
Loading