Skip to content

Commit

Permalink
Merge pull request openwallet-foundation#111 from Indicio-tech/featur…
Browse files Browse the repository at this point in the history
…e/anoncreds-admin-api-logic

routes logic calling anoncreds interface
  • Loading branch information
dbluhm authored Mar 17, 2023
2 parents 5271e1c + 75d41c2 commit 07375a6
Showing 1 changed file with 57 additions and 38 deletions.
95 changes: 57 additions & 38 deletions aries_cloudagent/anoncreds/anoncreds/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
)

from aries_cloudagent.anoncreds.models.anoncreds_schema import (
AnonCredsSchema,
PostSchemaResponseSchema,
SchemaPostQueryStringSchema,
AnonCredsRegistryGetSchemaSchema,
Expand Down Expand Up @@ -63,10 +64,10 @@ class CredIdMatchInfo(OpenAPISchema):
class CredDefSchema(OpenAPISchema):
"""Parameters and validators for credential definition."""

tag = fields.Str(
description="""The tag value passed in by the Issuer to
an AnonCred's Credential Definition create and store implementation."""
)
# tag = fields.Str(
# description="""The tag value passed in by the Issuer to
# an AnonCred's Credential Definition create and store implementation."""
# )
schemaId = fields.Str(
data_key="schemaId", description="Schema identifier", **ANONCREDS_SCHEMA_ID
)
Expand Down Expand Up @@ -188,10 +189,16 @@ async def schemas_post(request: web.BaseRequest):
schema_metadata : This fields contains metadata about the schema.
"""
# context: AdminRequestContext = request["context"]
parameters = await request.json()
context: AdminRequestContext = request["context"]
anon_creds_registry = context.inject(AnonCredsRegistry)
request_data = await request.json()
options = request_data.get("option")
schema_data = request_data.get("schema")

return web.json_response({"input": parameters})
schema: AnonCredsSchema = AnonCredsSchema.deserialize(schema_data)
#TODO: serialize return stuff.
result = anon_creds_registry.register_schema(options, schema)
return web.json_response(result)


@docs(tags=["anoncreds"], summary="")
Expand Down Expand Up @@ -226,18 +233,18 @@ async def schemas_get(request: web.BaseRequest):
Returns:
"""
# context: AdminRequestContext = request["context"]
context: AdminRequestContext = request["context"]
anon_creds_registry = context.inject(AnonCredsRegistry)
schema_issuer_did = request.query.get("schemaIssuerDid")
schema_name = request.query.get("schemaName")
schema_version = request.query.get("schemaVersion")

return web.json_response(
{
"schema_issuer_did": schema_issuer_did,
"schema_name": schema_name,
"schema_version": schema_version,
}
)
filter = {
"issuerId": schema_issuer_did,
"name": schema_name,
"version": schema_version,
}
schema_ids = anon_creds_registry.get_schemas(filter)
return web.json_response(schema_ids)


@docs(tags=["anoncreds"], summary="")
Expand All @@ -251,9 +258,23 @@ async def cred_def_post(request: web.BaseRequest):
Returns:
"""
# context: AdminRequestContext = request["context"]
context: AdminRequestContext = request["context"]
anon_creds_registry = context.inject(AnonCredsRegistry)
request_data = await request.json()
options = request_data.get("option")
data = request_data.get("credentialDefinition")

# TODO: find out if we need a model for this input.
cred_def = {
"issuer_id": data.get("issuerId"),
"schema_id": data.get("schemaId"),
# "tag":data.get("tag"),
"support_revocation": data.get("supportRevocation"),
"revocation_registrySize": data.get("revocationRegistrySize"),
}
result = anon_creds_registry.register_credential_definition(options, cred_def)
parameters = await request.json()
return web.json_response({"input": parameters})
return web.json_response(result)


@docs(tags=["anoncreds"], summary="")
Expand All @@ -267,9 +288,11 @@ async def cred_def_get(request: web.BaseRequest):
Returns:
"""
# context: AdminRequestContext = request["context"]
context: AdminRequestContext = request["context"]
anon_creds_registry = context.inject(AnonCredsRegistry)
credential_id = request.match_info["cred_def_id"]
return web.json_response({"cred_def_id": credential_id})
result = await anon_creds_registry.get_credential_definition(credential_id)
return web.json_response(result)


@docs(tags=["anoncreds"], summary="")
Expand All @@ -283,24 +306,20 @@ async def cred_defs_get(request: web.BaseRequest):
Returns:
"""
# context: AdminRequestContext = request["context"]
cred_def_id = request.query.get("credential_definition_id")
issuer_id = request.query.get("issuer_id")
schema_id = request.query.get("schema_id")
schema_issuer_id = request.query.get("schema_issuer_id")
schema_name = request.query.get("schema_name")
schema_version = request.query.get("schema_version")

return web.json_response(
{
"cred_def_id": cred_def_id,
"issuer_id": issuer_id,
"schema_id": schema_id,
"schema_issuer_id": schema_issuer_id,
"schema_name": schema_name,
"schema_version": schema_version,
}
)
context: AdminRequestContext = request["context"]
anon_creds_registry = context.inject(AnonCredsRegistry)
query = request.query

filter = {
"cred_def_id": query.get("credentialDefinitionId"),
"issuer_id": query.get("issuerId"),
"schema_id": query.get("schemaId"),
"schema_issuer_id": query.get("schemaIssuerId"),
"schema_name": query.get("schemaName"),
"schema_version": query.get("schemaVersion"),
}
cred_def_ids = anon_creds_registry.get_credential_definitions(filter)
return web.json_response(cred_def_ids)


async def register(app: web.Application):
Expand Down

0 comments on commit 07375a6

Please sign in to comment.