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

Feat/cleaning up indy anoncreds revocation methods #9

Merged
merged 1 commit into from
Oct 12, 2022
Merged
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
190 changes: 114 additions & 76 deletions controller/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ async def indy_issue_credential_v1(
attributes: Mapping[str, str],
) -> Tuple[V10CredentialExchange, V10CredentialExchange]:
"""Issue an indy credential using issue-credential/1.0.

Issuer and holder should already be connected.
"""
issuer_cred_ex = await issuer.post(
Expand Down Expand Up @@ -423,7 +422,6 @@ async def indy_issue_credential_v2(
attributes: Mapping[str, str],
) -> Tuple[V20CredExRecord, V20CredExRecord]:
"""Issue an indy credential using issue-credential/2.0.

Issuer and holder should already be connected.
"""

Expand Down Expand Up @@ -730,108 +728,148 @@ async def indy_present_proof_v2(

return holder_pres_ex, verifier_pres_ex

async def post_method(issuer: Controller,url,rev_reg_id,cred_rev_id,publish=False,notify=True):
await issuer.post(url,
json={"rev_reg_id": rev_reg_id,

async def post_method(
issuer: Controller,
url,
rev_reg_id,
cred_rev_id,
publish=False,
holder_connection_id: Optional[str] = None,
notify=True,
):
await issuer.post(
url,
json={
"connection_id": holder_connection_id,
"rev_reg_id": rev_reg_id,
"cred_rev_id": cred_rev_id,
"publish": publish,
"notify": notify},
response=None)
"notify": notify,
},
response=None,
)


async def indy_anoncreds_revoke(
issuer: Controller,
v10_credential_exchange_object=None,
v20_credential_exchange_object=None,
publish=False,
notify=True):
'''
Revoking an Indy credential using revocation revoke
V1.0: V10CredentialExchange
V2.0: VV20CredExRecordDetail
'''
holder_connection_id: Optional[str] = None,
v10_credential_exchange_object: Optional[V10CredentialExchange] = None,
v20_credential_exchange_object: Optional[V20CredExRecordDetail] = None,
publish: bool = False,
notify: bool = True,
):
"""Revoking an Indy credential using revocation revoke.
V1.0: V10CredentialExchange
V2.0: VV20CredExRecordDetail
"""
# Passes in V10CredentialExchange
if v10_credential_exchange_object:
post_method(url="/revocation/revoke",
rev_reg_id=v10_credential_exchange_object.revoc_reg_id,
cred_rev_id=v10_credential_exchange_object.revocation_id,
publish=publish,
notify=notify)

await post_method(
issuer,
url="/revocation/revoke",
rev_reg_id=v10_credential_exchange_object.revoc_reg_id,
cred_rev_id=v10_credential_exchange_object.revocation_id,
publish=publish,
holder_connection_id=holder_connection_id,
notify=notify,
)

# Passes in V20CredExRecordDetail
elif v20_credential_exchange_object:
post_method(url="/revocation/revoke",
rev_reg_id=v20_credential_exchange_object.indy.rev_reg_id,
cred_rev_id=v20_credential_exchange_object.indy.cred_rev_id,
publish=publish,
notify=notify)

elif v20_credential_exchange_object and v20_credential_exchange_object.indy:
await post_method(
issuer,
url="/revocation/revoke",
rev_reg_id=v20_credential_exchange_object.indy.rev_reg_id,
cred_rev_id=v20_credential_exchange_object.indy.cred_rev_id,
publish=publish,
holder_connection_id=holder_connection_id,
notify=notify,
)
else:
raise ValueError("If using V1.0, try passing in a V10CredentialExchange object. If using V2.0, try passing in a V20CredExRecordDetail object.")

raise ValueError(
"If using V1.0, try passing in a V10CredentialExchange object. If using V2.0, try passing in a V20CredExRecordDetail object."
)


async def indy_anoncreds_publish_revocation(
issuer: Controller,
v10_credential_exchange_object=None,
v20_credential_exchange_object=None,
publish=False,
notify=True):
v10_credential_exchange_object: Optional[V10CredentialExchange] = None,
v20_credential_exchange_object: Optional[V20CredExRecordDetail] = None,
publish: bool = False,
notify: bool = True,
):
if v10_credential_exchange_object:
await post_method(url="/revocation​/publish-revocations",
rev_reg_id=v10_credential_exchange_object.revoc_reg_id,
cred_rev_id=v10_credential_exchange_object.revocation_id,
publish=publish,
notify=notify)

elif v20_credential_exchange_object:
await post_method(url="/revocation​/publish-revocations",
rev_reg_id=v20_credential_exchange_object.indy.rev_reg_id,
cred_rev_id=v20_credential_exchange_object.indy.cred_rev_id,
publish=publish,
notify=notify)
await post_method(
issuer,
url="/revocation/publish-revocations",
rev_reg_id=v10_credential_exchange_object.revoc_reg_id,
cred_rev_id=v10_credential_exchange_object.revocation_id,
publish=publish,
notify=notify,
)

elif v20_credential_exchange_object and v20_credential_exchange_object.indy:
await post_method(
issuer,
url="/revocation/publish-revocations",
rev_reg_id=v20_credential_exchange_object.indy.rev_reg_id,
cred_rev_id=v20_credential_exchange_object.indy.cred_rev_id,
publish=publish,
notify=notify,
)
else:
raise ValueError("If using V1.0, try passing in a V10CredentialExchange object. If using V2.0, try passing in a V20CredExRecordDetail object.")

raise ValueError(
"If using V1.0, try passing in a V10CredentialExchange object. If using V2.0, try passing in a V20CredExRecordDetail object."
)


async def indy_anoncreds_proof_revocations(issuer: Controller,
async def indy_anoncreds_proof_revocations(
issuer: Controller,
holder: Controller,
issuer_connection_id: str,
holder_connection_id: str,
cred_def_id: str,
v10_credential_exchange_object=None,
v20_credential_exchange_object=None,
revocation_registry_id = None,
revocation_registry_id=None,
requested_attributes: Optional[List[Mapping[str, Any]]] = None,
requested_predicates: Optional[List[Mapping[str, Any]]] = None,
expiration_date=None):
'''
expiration_date=None,
):
"""
Proof of revocation
'''
if expiration_date==None:
"""
if expiration_date == None:
publish_revocation_ex = await issuer.post(
"/present-proof/send-request",
json={
"connection_id": issuer_connection_id,
"proof_request": {
"requested_attributes": requested_attributes,
"requested_predicates": requested_predicates,
"self_attested_attributes": {}
}},response=None)

"connection_id": issuer_connection_id,
"proof_request": {
"requested_attributes": requested_attributes,
"requested_predicates": requested_predicates,
"self_attested_attributes": {},
},
},
response=V10PresentationExchange,
)

else:
publish_revocation_ex = await issuer.post(
"/present-proof/send-request",
json={
"connection_id": issuer_connection_id,
"proof_request": {
"requested_attributes": requested_attributes,
"requested_predicates": requested_predicates,
"self_attested_attributes": {},

"non_revoked": # Optional, only check revocation if specified
{
"from": 0,
"to": expiration_date
}
}},response=None)

return(publish_revocation_ex)
"connection_id": issuer_connection_id,
"proof_request": {
"requested_attributes": requested_attributes,
"requested_predicates": requested_predicates,
"self_attested_attributes": {},
"non_revoked": { # Optional, only check revocation if specified
"from": 0,
"to": expiration_date,
},
},
},
response=V10PresentationExchange,
)

return publish_revocation_ex