@@ -24,9 +24,7 @@ class ConnRecord(Minimal):
24
24
rfc23_state : str
25
25
26
26
27
- async def trustping (
28
- sender : Controller , conn : ConnRecord , comment : Optional [str ] = None
29
- ):
27
+ async def trustping (sender : Controller , conn : ConnRecord , comment : Optional [str ] = None ):
30
28
"""Send a trustping to the specified connection."""
31
29
await sender .post (
32
30
f"/connections/{ conn .connection_id } /send-ping" ,
@@ -372,20 +370,76 @@ async def indy_anoncred_onboard(agent: Controller):
372
370
return public_did
373
371
374
372
373
+ # Schema
375
374
@dataclass
376
375
class SchemaResult (Minimal ):
377
- """Result of creating a schema."""
376
+ """Result of creating a schema using /schemas."""
377
+
378
+ schema_id : str
379
+
378
380
381
+ @dataclass
382
+ class SchemaStateAnoncreds (Minimal ):
383
+ """schema_state field in SchemaResultAnoncreds."""
384
+
385
+ state : str
379
386
schema_id : str
387
+ schema : dict
380
388
381
389
390
+ @dataclass
391
+ class SchemaResultAnoncreds (Minimal ):
392
+ """Result of creating a schema using /anoncreds/schema."""
393
+
394
+ schema_state : SchemaStateAnoncreds
395
+ schema_metadata : dict
396
+ registration_metadata : dict
397
+ job_id : Optional [str ] = None
398
+
399
+ @classmethod
400
+ def deserialize (cls : Type [MinType ], value : Mapping [str , Any ]) -> MinType :
401
+ """Deserialize the cred def result record."""
402
+ value = dict (value )
403
+ value ["schema_state" ] = SchemaStateAnoncreds .deserialize (value ["schema_state" ])
404
+ return super ().deserialize (value )
405
+
406
+
407
+ # CredDefResult
382
408
@dataclass
383
409
class CredDefResult (Minimal ):
384
410
"""Result of creating a credential definition."""
385
411
386
412
credential_definition_id : str
387
413
388
414
415
+ @dataclass
416
+ class CredDefStateAnoncreds (Minimal ):
417
+ """credential_definition_state field in CredDefResult."""
418
+
419
+ state : str
420
+ credential_definition_id : str
421
+ credential_definition : dict
422
+
423
+
424
+ @dataclass
425
+ class CredDefResultAnoncreds (Minimal ):
426
+ """Result of creating a cred def using /anoncreds/credential-definition."""
427
+
428
+ credential_definition_state : CredDefStateAnoncreds
429
+ credential_definition_metadata : dict
430
+ registration_metadata : dict
431
+ job_id : Optional [str ] = None
432
+
433
+ @classmethod
434
+ def deserialize (cls : Type [MinType ], value : Mapping [str , Any ]) -> MinType :
435
+ """Deserialize the cred def result record."""
436
+ value = dict (value )
437
+ value ["credential_definition_state" ] = CredDefStateAnoncreds .deserialize (
438
+ value ["credential_definition_state" ]
439
+ )
440
+ return super ().deserialize (value )
441
+
442
+
389
443
async def indy_anoncred_credential_artifacts (
390
444
agent : Controller ,
391
445
attributes : List [str ],
@@ -394,8 +448,61 @@ async def indy_anoncred_credential_artifacts(
394
448
cred_def_tag : Optional [str ] = None ,
395
449
support_revocation : bool = False ,
396
450
revocation_registry_size : Optional [int ] = None ,
451
+ issuerID : Optional [str ] = None ,
397
452
):
398
453
"""Prepare credential artifacts for indy anoncreds."""
454
+ # Get wallet type
455
+ if agent .wallet_type is None :
456
+ raise ControllerError (
457
+ "Wallet type not found. Please correctly set up the controller."
458
+ )
459
+ anoncreds_wallet = agent .wallet_type == "askar-anoncreds"
460
+
461
+ # If using wallet=askar-anoncreds:
462
+ if anoncreds_wallet :
463
+ if issuerID is None :
464
+ raise ControllerError (
465
+ "If using askar-anoncreds wallet, issuerID must be specified."
466
+ )
467
+
468
+ schema = (
469
+ await agent .post (
470
+ "/anoncreds/schema" ,
471
+ json = {
472
+ "schema" : {
473
+ "attrNames" : attributes ,
474
+ "issuerId" : issuerID ,
475
+ "name" : schema_name or "minimal-" + token_hex (8 ),
476
+ "version" : schema_version or "1.0" ,
477
+ },
478
+ },
479
+ response = SchemaResultAnoncreds ,
480
+ )
481
+ ).schema_state
482
+
483
+ cred_def = (
484
+ await agent .post (
485
+ "/anoncreds/credential-definition" ,
486
+ json = {
487
+ "credential_definition" : {
488
+ "issuerId" : issuerID ,
489
+ "schemaId" : schema .schema_id ,
490
+ "tag" : cred_def_tag or token_hex (8 ),
491
+ },
492
+ "options" : {
493
+ "revocation_registry_size" : (
494
+ revocation_registry_size if revocation_registry_size else 10
495
+ ),
496
+ "support_revocation" : support_revocation ,
497
+ },
498
+ },
499
+ response = CredDefResultAnoncreds ,
500
+ )
501
+ ).credential_definition_state
502
+
503
+ return schema , cred_def
504
+
505
+ # If using wallet=askar
399
506
schema = await agent .post (
400
507
"/schemas" ,
401
508
json = {
@@ -967,6 +1074,13 @@ async def indy_anoncreds_revoke(
967
1074
V1.0: V10CredentialExchange
968
1075
V2.0: V20CredExRecordDetail.
969
1076
"""
1077
+ # Get wallet type
1078
+ if issuer .wallet_type is None :
1079
+ raise ControllerError (
1080
+ "Wallet type not found. Please correctly set up the controller."
1081
+ )
1082
+ anoncreds_wallet = issuer .wallet_type == "askar-anoncreds"
1083
+
970
1084
if notify and holder_connection_id is None :
971
1085
return (
972
1086
"If you are going to set notify to True,"
@@ -976,7 +1090,7 @@ async def indy_anoncreds_revoke(
976
1090
# Passes in V10CredentialExchange
977
1091
if isinstance (cred_ex , V10CredentialExchange ):
978
1092
await issuer .post (
979
- url = "/revocation/revoke" ,
1093
+ url = "{} /revocation/revoke" . format ( "/anoncreds" if anoncreds_wallet else "" ) ,
980
1094
json = {
981
1095
"connection_id" : holder_connection_id ,
982
1096
"rev_reg_id" : cred_ex .revoc_reg_id ,
@@ -990,7 +1104,7 @@ async def indy_anoncreds_revoke(
990
1104
# Passes in V20CredExRecordDetail
991
1105
elif isinstance (cred_ex , V20CredExRecordDetail ) and cred_ex .indy :
992
1106
await issuer .post (
993
- url = "/revocation/revoke" ,
1107
+ url = "{} /revocation/revoke" . format ( "/anoncreds" if anoncreds_wallet else "" ) ,
994
1108
json = {
995
1109
"connection_id" : holder_connection_id ,
996
1110
"rev_reg_id" : cred_ex .indy .rev_reg_id ,
@@ -1019,9 +1133,18 @@ async def indy_anoncreds_publish_revocation(
1019
1133
V1.0: V10CredentialExchange
1020
1134
V2.0: V20CredExRecordDetail.
1021
1135
"""
1136
+ # Get wallet type
1137
+ if issuer .wallet_type is None :
1138
+ raise ControllerError (
1139
+ "Wallet type not found. Please correctly set up the controller."
1140
+ )
1141
+ anoncreds_wallet = issuer .wallet_type == "askar-anoncreds"
1142
+
1022
1143
if isinstance (cred_ex , V10CredentialExchange ):
1023
1144
await issuer .post (
1024
- url = "/revocation/publish-revocations" ,
1145
+ url = "{}/revocation/publish-revocations" .format (
1146
+ "/anoncreds" if anoncreds_wallet else ""
1147
+ ),
1025
1148
json = {
1026
1149
"rev_reg_id" : cred_ex .revoc_reg_id ,
1027
1150
"cred_rev_id" : cred_ex .revocation_id ,
@@ -1032,7 +1155,9 @@ async def indy_anoncreds_publish_revocation(
1032
1155
1033
1156
elif isinstance (cred_ex , V20CredExRecordDetail ) and cred_ex .indy :
1034
1157
await issuer .post (
1035
- url = "/revocation/publish-revocations" ,
1158
+ url = "{}/revocation/publish-revocations" .format (
1159
+ "/anoncreds" if anoncreds_wallet else ""
1160
+ ),
1036
1161
json = {
1037
1162
"rev_reg_id" : cred_ex .indy .rev_reg_id ,
1038
1163
"cred_rev_id" : cred_ex .indy .cred_rev_id ,
0 commit comments