This repository has been archived by the owner on Feb 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 738
/
Interaction.mm
634 lines (533 loc) · 38.5 KB
/
Interaction.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
#import <Foundation/Foundation.h>
#import <XCTest/XCTest.h>
#import <Indy/Indy.h>
#import "TestUtils.h"
#import "BlobStorageUtils.h"
@interface AnoncredsLedgerInteraction : XCTestCase
@end
@implementation AnoncredsLedgerInteraction
- (void)setUp {
[super setUp];
NSError *ret = [[PoolUtils sharedInstance] setProtocolVersion:[TestUtils protocolVersion]];
XCTAssertEqual(ret.code, Success, @"PoolUtils::setProtocolVersion() failed!");
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testAnoncredsRevocationInteractionForIssuanceOnDemand {
[TestUtils cleanupStorage];
NSError *ret;
// Create ledger config from genesis txn file
NSString *txnFilePath = [[PoolUtils sharedInstance] createGenesisTxnFileForTestPool:[TestUtils pool]
nodesCount:nil
txnFilePath:nil];
NSString *poolConfig = [[PoolUtils sharedInstance] poolConfigJsonForTxnFilePath:txnFilePath];
XCTAssertEqual(ret.code, Success, @"PoolUtils::createPoolLedgerConfigWithPoolName() failed!");
ret = [[PoolUtils sharedInstance] createPoolLedgerConfigWithPoolName:[TestUtils pool]
poolConfig:poolConfig];
XCTAssertEqual(ret.code, Success, @"createPoolLedgerConfigWithPoolName() failed!");
// Open pool ledger
__block IndyHandle poolHandle = 0;
ret = [[PoolUtils sharedInstance] openPoolLedger:[TestUtils pool]
config:nil
poolHandler:&poolHandle];
XCTAssertEqual(ret.code, Success, @"openPoolLedger() failed!");
// Create Issuer wallet, get wallet handle
IndyHandle issuerWalletHandle = 0;
ret = [[WalletUtils sharedInstance] createAndOpenWalletWithHandle:&issuerWalletHandle];
XCTAssertEqual(ret.code, Success, @"createAndOpenWalletWithPoolName() failed!");
// Create Prover wallet, get wallet handle
IndyHandle proverWalletHandle = 0;
ret = [[WalletUtils sharedInstance] createAndOpenWalletWithHandle:&proverWalletHandle];
XCTAssertEqual(ret.code, Success, @"createAndOpenWalletWithPoolName() failed!");
// Obtain default trustee did
NSString *trusteeDid = nil;
ret = [[DidUtils sharedInstance] createAndStoreMyDidWithWalletHandle:issuerWalletHandle
seed:[TestUtils trusteeSeed]
outMyDid:&trusteeDid
outMyVerkey:nil];
XCTAssertEqual(ret.code, Success, @"createAndStoreMyDidWithWalletHandle() failed!");
// Obtain issuer did
NSString *issuerDid = nil;
NSString *issuerVerkey = nil;
ret = [[DidUtils sharedInstance] createMyDidWithWalletHandle:issuerWalletHandle
myDidJson:@"{}"
outMyDid:&issuerDid
outMyVerkey:&issuerVerkey];
XCTAssertEqual(ret.code, Success, @"createMyDidWithWalletHandle() failed!");
// Trustee send Issuer DID to ledger
NSString *nymRequest = nil;
ret = [[LedgerUtils sharedInstance] buildNymRequestWithSubmitterDid:trusteeDid
targetDid:issuerDid
verkey:issuerVerkey
alias:nil
role:@"TRUSTEE"
outRequest:&nymRequest];
XCTAssertEqual(ret.code, Success, @"buildNymRequestWithSubmitterDid() failed!");
NSString *nymResponse = nil;
ret = [[LedgerUtils sharedInstance] signAndSubmitRequestWithPoolHandle:poolHandle
walletHandle:issuerWalletHandle
submitterDid:trusteeDid
requestJson:nymRequest
outResponseJson:&nymResponse];
XCTAssertEqual(ret.code, Success, @"signAndSubmitRequestWithPoolHandle() failed!");
// Obtain prover did
NSString *proverDid = nil;
NSString *proverVerkey = nil;
ret = [[DidUtils sharedInstance] createMyDidWithWalletHandle:proverWalletHandle
myDidJson:@"{}"
outMyDid:&proverDid
outMyVerkey:&proverVerkey];
XCTAssertEqual(ret.code, Success, @"createMyDidWithWalletHandle() failed!");
// Issuer create Schema
NSString *schemaId;
NSString *schemaJson;
ret = [[AnoncredsUtils sharedInstance] issuerCreateSchemaWithName:[TestUtils gvtSchemaName]
version:[TestUtils schemaVersion]
attrs:[TestUtils gvtSchemaAttrs]
issuerDID:issuerDid
schemaId:&schemaId
schemaJson:&schemaJson];
XCTAssertEqual(ret.code, Success, @"issuerCreateSchemaWithName() failed!");
// Issuer send schema to ledger
NSString *schemaRequest = nil;
ret = [[LedgerUtils sharedInstance] buildSchemaRequestWithSubmitterDid:issuerDid
data:schemaJson
resultJson:&schemaRequest];
XCTAssertEqual(ret.code, Success, @"buildSchemaRequestWithSubmitterDid() failed!");
NSString *schemaResponse = nil;
ret = [[LedgerUtils sharedInstance] signAndSubmitRequestWithPoolHandle:poolHandle
walletHandle:issuerWalletHandle
submitterDid:issuerDid
requestJson:schemaRequest
outResponseJson:&schemaResponse];
XCTAssertEqual(ret.code, Success, @"signAndSubmitRequestWithPoolHandle() failed!");
// Issuer gets schema from ledger
NSString *getSchemaRequest = nil;
ret = [[LedgerUtils sharedInstance] buildGetSchemaRequestWithSubmitterDid:issuerDid
id:schemaId
resultJson:&getSchemaRequest];
XCTAssertEqual(ret.code, Success, @"buildGetSchemaRequestWithSubmitterDid() failed!");
NSString *getSchemaResponse = nil;
ret = [[PoolUtils sharedInstance] sendRequestWithPoolHandle:poolHandle
request:getSchemaRequest
response:&getSchemaResponse];
XCTAssertEqual(ret.code, Success, @"sendRequestWithPoolHandle() failed!");
ret = [[LedgerUtils sharedInstance] parseGetSchemaResponse:getSchemaResponse
schemaId:&schemaId
schemaJson:&schemaJson];
XCTAssertEqual(ret.code, Success, @"parseGetSchemaResponse() failed!");
// Issuer create credential definition
NSString *credentialDefId;
NSString *credentialDefJSON;
ret = [[AnoncredsUtils sharedInstance] issuerCreateAndStoreCredentialDefForSchema:schemaJson
issuerDID:issuerDid
tag:[TestUtils tag]
type:nil
configJSON:@"{\"support_revocation\": true}"
walletHandle:issuerWalletHandle
credDefId:&credentialDefId
credDefJson:&credentialDefJSON];
XCTAssertEqual(ret.code, Success, @"issuerCreateAndStoreCredentialDefForSchema() failed!");
// Issuer send credential definition to ledger
NSString *credDefRequestJson;
ret = [[LedgerUtils sharedInstance] buildCredDefRequestWithSubmitterDid:issuerDid
data:credentialDefJSON
resultJson:&credDefRequestJson];
XCTAssertEqual(ret.code, Success, @"buildCredDefRequestWithSubmitterDid() failed!");
NSString *credDefResponse;
ret = [[LedgerUtils sharedInstance] signAndSubmitRequestWithPoolHandle:poolHandle
walletHandle:issuerWalletHandle
submitterDid:issuerDid
requestJson:credDefRequestJson
outResponseJson:&credDefResponse];
XCTAssertEqual(ret.code, Success, @"signAndSubmitRequestWithPoolHandle() failed!");
// Issuer create revocation registry
NSString *configJson = [[AnoncredsUtils sharedInstance] toJson:@{
@"max_cred_num": @(5),
@"issuance_type": @"ISSUANCE_ON_DEMAND"
}];
NSString *tailsWriterConfig = [[AnoncredsUtils sharedInstance] toJson:@{
@"base_dir": [TestUtils tmpFilePathAppending:@"tails"],
@"uri_pattern": @""
}];
NSNumber *tailsWriterHandle = nil;
ret = [[BlobStorageUtils sharedInstance] openWriterWithType:[TestUtils defaultType]
config:tailsWriterConfig
handle:&tailsWriterHandle];
XCTAssertEqual(ret.code, Success, @"openWriterWithType() failed!");
NSString *revocRegId;
NSString *revocRegDefJson;
NSString *revocRegEntryJson;
ret = [[AnoncredsUtils sharedInstance] issuerCreateAndStoreRevocRegForCredentialDefId:credentialDefId
issuerDID:issuerDid
type:nil
tag:[TestUtils tag]
configJSON:configJson
tailsWriterHandle:[tailsWriterHandle intValue]
walletHandle:issuerWalletHandle
revocRegId:&revocRegId
revocRegDefJson:&revocRegDefJson
revocRegEntryJson:&revocRegEntryJson];
XCTAssertEqual(ret.code, Success, @"issuerCreateAndStoreRevocRegForCredentialDefId() failed!");
// Issuer send revocation registry definition to ledger
NSString *revocRegDefRequestJson;
ret = [[LedgerUtils sharedInstance] buildRevocRegDefRequestWithSubmitterDid:issuerDid
data:revocRegDefJson
resultJson:&revocRegDefRequestJson];
XCTAssertEqual(ret.code, Success, @"buildRevocRegDefRequestWithSubmitterDid() failed!");
NSString *revocRegDefResponse;
ret = [[LedgerUtils sharedInstance] signAndSubmitRequestWithPoolHandle:poolHandle
walletHandle:issuerWalletHandle
submitterDid:issuerDid
requestJson:revocRegDefRequestJson
outResponseJson:&revocRegDefResponse];
XCTAssertEqual(ret.code, Success, @"signAndSubmitRequestWithPoolHandle() failed!");
// Issuer send revocation registry entry to ledger
NSString *revocRegEntryRequestJson;
ret = [[LedgerUtils sharedInstance] buildRevocRegEntryRequestWithSubmitterDid:issuerDid
type:@"CL_ACCUM"
revocRegDefId:revocRegId
value:revocRegEntryJson
resultJson:&revocRegEntryRequestJson];
XCTAssertEqual(ret.code, Success, @"buildRevocRegEntrtyRequestWithSubmitterDid() failed!");
NSString *revocRegEntryResponse;
ret = [[LedgerUtils sharedInstance] signAndSubmitRequestWithPoolHandle:poolHandle
walletHandle:issuerWalletHandle
submitterDid:issuerDid
requestJson:revocRegEntryRequestJson
outResponseJson:&revocRegEntryResponse];
XCTAssertEqual(ret.code, Success, @"signAndSubmitRequestWithPoolHandle() failed!");
// Issuance Credential for Prover
// Prover create Master Secret
ret = [[AnoncredsUtils sharedInstance] proverCreateMasterSecret:[TestUtils commonMasterSecretName]
walletHandle:proverWalletHandle
outMasterSecretId:nil];
XCTAssertEqual(ret.code, Success, @"proverCreateMasterSecret() failed!");
// Issuer create Credential Offer
NSString *credentialOfferJson = nil;
ret = [[AnoncredsUtils sharedInstance] issuerCreateCredentialOfferForCredDefId:credentialDefId
walletHandle:issuerWalletHandle
credOfferJson:&credentialOfferJson];
XCTAssertEqual(ret.code, Success, @"issuerCreateCredentialOfferForCredDefId() failed!");
// Prover gets credential definition from ledger
NSDictionary *credOffer = [NSDictionary fromString:credentialOfferJson];
NSString *getCredDefRequest;
ret = [[LedgerUtils sharedInstance] buildGetCredDefRequestWithSubmitterDid:proverDid
id:credOffer[@"cred_def_id"]
resultJson:&getCredDefRequest];
XCTAssertEqual(ret.code, Success, @"buildGetCredDefRequestWithSubmitterDid() failed!");
NSString *getCredDefResponse;
ret = [[PoolUtils sharedInstance] sendRequestWithPoolHandle:poolHandle
request:getCredDefRequest
response:&getCredDefResponse];
XCTAssertEqual(ret.code, Success, @"sendRequestWithPoolHandle() failed!");
ret = [[LedgerUtils sharedInstance] parseGetCredDefResponse:getCredDefResponse
credDefId:&credentialDefId
credDefJson:&credentialDefJSON];
XCTAssertEqual(ret.code, Success, @"parseGetCredDefResponse() failed!");
// Prover create Credential Request
NSString *credentialReq = nil;
NSString *credentialReqMetadata = nil;
ret = [[AnoncredsUtils sharedInstance] proverCreateCredentialReqForCredentialOffer:credentialOfferJson
credentialDefJSON:credentialDefJSON
proverDID:proverDid
masterSecretID:[TestUtils commonMasterSecretName]
walletHandle:proverWalletHandle
credReqJson:&credentialReq
credReqMetadataJson:&credentialReqMetadata];
XCTAssertEqual(ret.code, Success, @"proverCreateCredentialReqForCredentialOffer() failed!");
// Issuer create Tails reader
NSNumber *blobStorageReaderHandle = nil;
ret = [[BlobStorageUtils sharedInstance] openReaderWithType:[TestUtils defaultType]
config:tailsWriterConfig
handle:&blobStorageReaderHandle];
XCTAssertEqual(ret.code, Success, @"openReaderWithType() failed!");
// Issuer create Credential
NSString *credentialJson = nil;
NSString *credentialRevId = nil;
NSString *revocRegDeltaJson = nil;
ret = [[AnoncredsUtils sharedInstance] issuerCreateCredentialForCredentialRequest:credentialReq
credOfferJSON:credentialOfferJson
credValuesJSON:[[AnoncredsUtils sharedInstance] getGvtCredentialValuesJson]
revRegId:revocRegId
blobStorageReaderHandle:blobStorageReaderHandle
walletHandle:issuerWalletHandle
credJson:&credentialJson
credRevocId:&credentialRevId
revocRegDeltaJSON:&revocRegDeltaJson];
XCTAssertEqual(ret.code, Success, @"issuerCreateCredentialForCredentialRequest() failed!");
// Issuer send revocation registry delta to ledger
ret = [[LedgerUtils sharedInstance] buildRevocRegEntryRequestWithSubmitterDid:issuerDid
type:@"CL_ACCUM"
revocRegDefId:revocRegId
value:revocRegDeltaJson
resultJson:&revocRegEntryRequestJson];
XCTAssertEqual(ret.code, Success, @"buildRevocRegEntrtyRequestWithSubmitterDid() failed!");
ret = [[LedgerUtils sharedInstance] signAndSubmitRequestWithPoolHandle:poolHandle
walletHandle:issuerWalletHandle
submitterDid:issuerDid
requestJson:revocRegEntryRequestJson
outResponseJson:&revocRegEntryResponse];
XCTAssertEqual(ret.code, Success, @"signAndSubmitRequestWithPoolHandle() failed!");
NSDictionary *revocRegEntry = [NSDictionary fromString:revocRegEntryResponse];
NSNumber *entryTxnTime = revocRegEntry[@"result"][@"txnMetadata"][@"txnTime"];
// Prover gets revocation registry definition from ledger
NSDictionary *credential = [NSDictionary fromString:credentialJson];
NSString *getRevocRegDefRequest;
ret = [[LedgerUtils sharedInstance] buildGetRevocRegDefRequestWithSubmitterDid:proverDid
id:credential[@"rev_reg_id"]
resultJson:&getRevocRegDefRequest];
XCTAssertEqual(ret.code, Success, @"buildGetRevocRegDefRequestWithSubmitterDid() failed!");
NSString *getRevocRegDefResponse;
ret = [[PoolUtils sharedInstance] sendRequestWithPoolHandle:poolHandle
request:getRevocRegDefRequest
response:&getRevocRegDefResponse];
XCTAssertEqual(ret.code, Success, @"sendRequestWithPoolHandle() failed!");
ret = [[LedgerUtils sharedInstance] parseGetRevocRegDefResponse:getRevocRegDefResponse
revocRegDefId:&revocRegId
revocRegDefJson:&revocRegDefJson];
XCTAssertEqual(ret.code, Success, @"parseGetRevocRegDefResponse() failed!");
// Prover store received Credential
ret = [[AnoncredsUtils sharedInstance] proverStoreCredential:credentialJson
credID:[[AnoncredsUtils sharedInstance] credentialId1]
credReqMetadataJSON:credentialReqMetadata
credDefJSON:credentialDefJSON
revRegDefJSON:revocRegDefJson
walletHandle:proverWalletHandle
outCredId:nil];
XCTAssertEqual(ret.code, Success, @"proverStoreCredential() failed!");
// Prover gets Credentials for Proof Request
NSString *proofReqJson = [[AnoncredsUtils sharedInstance] toJson:@{
@"nonce": @"123432421212",
@"name": @"proof_req_1",
@"version": @"0.1",
@"requested_attributes": @{
@"attr1_referent": @{
@"name": @"name"
}
},
@"requested_predicates": @{
@"predicate1_referent": @{
@"name": @"age",
@"p_type": @">=",
@"p_value": @(18)
}
}
}];
NSString *credentialsJson = nil;
ret = [[AnoncredsUtils sharedInstance] proverGetCredentialsForProofReq:proofReqJson
walletHandle:proverWalletHandle
credentialsJson:&credentialsJson];
XCTAssertEqual(ret.code, Success, @"proverGetCredentialsForProofReq() failed!");
NSDictionary *credentials = [NSDictionary fromString:credentialsJson];
XCTAssertTrue(credentials, @"serialization failed");
NSDictionary *credentials_for_attr_1 = credentials[@"attrs"][@"attr1_referent"][0];
NSString *credentialReferent = credentials_for_attr_1[@"cred_info"][@"referent"];
// Prover gets revocation registry delta from ledger
NSNumber *timestamp = @([entryTxnTime intValue] + 100 );
NSString *getRevocRegDeltaRequest;
ret = [[LedgerUtils sharedInstance] buildGetRevocRegDeltaRequestWithSubmitterDid:proverDid
revocRegDefId:credentials_for_attr_1[@"cred_info"][@"rev_reg_id"]
from:@(-1)
to:timestamp
resultJson:&getRevocRegDeltaRequest];
XCTAssertEqual(ret.code, Success, @"buildGetRevocRegDeltaRequestWithSubmitterDid() failed!");
NSString *getRevocRegDeltaResponse;
ret = [[PoolUtils sharedInstance] sendRequestWithPoolHandle:poolHandle
request:getRevocRegDeltaRequest
response:&getRevocRegDeltaResponse];
XCTAssertEqual(ret.code, Success, @"sendRequestWithPoolHandle() failed!");
ret = [[LedgerUtils sharedInstance] parseGetRevocRegDeltaResponse:getRevocRegDeltaResponse
revocRegDefId:&revocRegId
revocRegDeltaJson:&revocRegDeltaJson
timestamp:×tamp];
XCTAssertEqual(ret.code, Success, @"parseGetRevocRegDeltaResponse() failed!");
// Prover create Revocation State
NSString *revocStateJson = nil;
ret = [[AnoncredsUtils sharedInstance] createRevocationStateForCredRevID:credentialRevId
timestamp:timestamp
revRegDefJSON:revocRegDefJson
revRegDeltaJSON:revocRegDeltaJson
blobStorageReaderHandle:blobStorageReaderHandle
revStateJson:&revocStateJson];
XCTAssertEqual(ret.code, Success, @"createRevocationStateForCredRevID() failed!");
// Prover create Proof
NSString *requestedCredentialsJson = [[AnoncredsUtils sharedInstance] toJson:@{
@"self_attested_attributes": @{},
@"requested_attributes": @{
@"attr1_referent": @{
@"cred_id": credentialReferent,
@"revealed": @(YES),
@"timestamp": timestamp
}
},
@"requested_predicates": @{
@"predicate1_referent": @{
@"cred_id": credentialReferent,
@"timestamp": timestamp
}
}
}];
NSString *schemasJson = [[AnoncredsUtils sharedInstance] toJson:@{schemaId: [NSDictionary fromString:schemaJson]}];
NSString *credentialDefsJson = [[AnoncredsUtils sharedInstance] toJson:@{credentialDefId: [NSDictionary fromString:credentialDefJSON]}];
NSString *revocStatesJson = [[AnoncredsUtils sharedInstance] toJson:@{revocRegId: @{[timestamp stringValue]: [NSDictionary fromString:revocStateJson]}}];
NSString *proofJson;
ret = [[AnoncredsUtils sharedInstance] proverCreateProofForRequest:proofReqJson
requestedCredentialsJSON:requestedCredentialsJson
masterSecretID:[TestUtils commonMasterSecretName]
schemasJSON:schemasJson
credentialDefsJSON:credentialDefsJson
revocStatesJSON:revocStatesJson
walletHandle:proverWalletHandle
proofJson:&proofJson];
XCTAssertEqual(ret.code, Success, @"proverCreateProofForRequest() failed!");
NSDictionary *proof = [NSDictionary fromString:proofJson];
NSDictionary *revealedAttr1 = proof[@"requested_proof"][@"revealed_attrs"][@"attr1_referent"];
NSString *raw = revealedAttr1[@"raw"];
XCTAssertTrue([raw isEqualToString:@"Alex"]);
// Verifier gets revocation registry from ledger
NSString *getRevocRegRequest;
ret = [[LedgerUtils sharedInstance] buildGetRevocRegRequestWithSubmitterDid:[TestUtils proverDid]
revocRegDefId:proof[@"identifiers"][0][@"rev_reg_id"]
timestamp:proof[@"identifiers"][0][@"timestamp"]
resultJson:&getRevocRegRequest];
XCTAssertEqual(ret.code, Success, @"buildGetRevocRegRequestWithSubmitterDid() failed!");
NSString *getRevocRegResponse;
ret = [[PoolUtils sharedInstance] sendRequestWithPoolHandle:poolHandle
request:getRevocRegRequest
response:&getRevocRegResponse];
XCTAssertEqual(ret.code, Success, @"sendRequestWithPoolHandle() failed!");
NSString *revocRegJson = nil;
ret = [[LedgerUtils sharedInstance] parseGetRevocRegResponse:getRevocRegResponse
revocRegDefId:&revocRegId
revocRegJson:&revocRegJson
timestamp:×tamp];
XCTAssertEqual(ret.code, Success, @"parseGetRevocRegResponse() failed!");
NSString *revocRegDefsJson = [[AnoncredsUtils sharedInstance] toJson:@{revocRegId: [NSDictionary fromString:revocRegDefJson]}];
NSString *revocRegsJson = [[AnoncredsUtils sharedInstance] toJson:@{revocRegId: @{[timestamp stringValue]: [NSDictionary fromString:revocRegJson]}}];
// Verifier verify proof
BOOL isValid = NO;
ret = [[AnoncredsUtils sharedInstance] verifierVerifyProofRequest:proofReqJson
proofJSON:proofJson
schemasJSON:schemasJson
credentialDefsJSON:credentialDefsJson
revocRegDefsJSON:revocRegDefsJson
revocRegsJSON:revocRegsJson
isValid:&isValid];
XCTAssertEqual(ret.code, Success, @"verifierVerifyProofRequest() failed!");
XCTAssertTrue(isValid, @"isValid == NO");
// Issuer revokes credential
ret = [[AnoncredsUtils sharedInstance] issuerRevokeCredentialByCredRevocId:credentialRevId
revRegId:revocRegId
blobStorageReaderHandle:blobStorageReaderHandle
walletHandle:issuerWalletHandle
revocRegDeltaJson:&revocRegDeltaJson];
XCTAssertEqual(ret.code, Success, @"issuerRevokeCredentialByCredRevocId() failed!");
// Issuer send revocation registry delta to ledger
ret = [[LedgerUtils sharedInstance] buildRevocRegEntryRequestWithSubmitterDid:issuerDid
type:@"CL_ACCUM"
revocRegDefId:revocRegId
value:revocRegDeltaJson
resultJson:&revocRegEntryRequestJson];
XCTAssertEqual(ret.code, Success, @"buildRevocRegEntrtyRequestWithSubmitterDid() failed!");
ret = [[LedgerUtils sharedInstance] signAndSubmitRequestWithPoolHandle:poolHandle
walletHandle:issuerWalletHandle
submitterDid:issuerDid
requestJson:revocRegEntryRequestJson
outResponseJson:&revocRegEntryResponse];
XCTAssertEqual(ret.code, Success, @"signAndSubmitRequestWithPoolHandle() failed!");
// Prover gets revocation registry delta from ledger
NSNumber *from = timestamp;
NSNumber *to = @([from intValue] + 200);
[NSThread sleepForTimeInterval:3];
ret = [[LedgerUtils sharedInstance] buildGetRevocRegDeltaRequestWithSubmitterDid:proverDid
revocRegDefId:credentials_for_attr_1[@"cred_info"][@"rev_reg_id"]
from:from
to:to
resultJson:&getRevocRegDeltaRequest];
XCTAssertEqual(ret.code, Success, @"buildGetRevocRegDeltaRequestWithSubmitterDid() failed!");
ret = [[PoolUtils sharedInstance] sendRequestWithPoolHandle:poolHandle
request:getRevocRegDeltaRequest
response:&getRevocRegDeltaResponse];
XCTAssertEqual(ret.code, Success, @"sendRequestWithPoolHandle() failed!");
ret = [[LedgerUtils sharedInstance] parseGetRevocRegDeltaResponse:getRevocRegDeltaResponse
revocRegDefId:&revocRegId
revocRegDeltaJson:&revocRegDeltaJson
timestamp:×tamp];
XCTAssertEqual(ret.code, Success, @"parseGetRevocRegDeltaResponse() failed!");
// Prover create Revocation State
ret = [[AnoncredsUtils sharedInstance] updateRevocationState:revocStateJson
credRevID:credentialRevId
timestamp:timestamp
revRegDefJSON:revocRegDefJson
revRegDeltaJSON:revocRegDeltaJson
blobStorageReaderHandle:blobStorageReaderHandle
updatedRevStateJson:&revocStateJson];
XCTAssertEqual(ret.code, Success, @"createRevocationStateForCredRevID() failed!");
// Prover create Proof
requestedCredentialsJson = [[AnoncredsUtils sharedInstance] toJson:@{
@"self_attested_attributes": @{},
@"requested_attributes": @{
@"attr1_referent": @{
@"cred_id": credentialReferent,
@"revealed": @(YES),
@"timestamp": timestamp
}
},
@"requested_predicates": @{
@"predicate1_referent": @{
@"cred_id": credentialReferent,
@"timestamp": timestamp
}
}
}];
revocStatesJson = [[AnoncredsUtils sharedInstance] toJson:@{revocRegId: @{[timestamp stringValue]: [NSDictionary fromString:revocStateJson]}}];
ret = [[AnoncredsUtils sharedInstance] proverCreateProofForRequest:proofReqJson
requestedCredentialsJSON:requestedCredentialsJson
masterSecretID:[TestUtils commonMasterSecretName]
schemasJSON:schemasJson
credentialDefsJSON:credentialDefsJson
revocStatesJSON:revocStatesJson
walletHandle:proverWalletHandle
proofJson:&proofJson];
XCTAssertEqual(ret.code, Success, @"proverCreateProofForRequest() failed!");
proof = [NSDictionary fromString:proofJson];
// Verifier gets revocation registry from ledger
ret = [[LedgerUtils sharedInstance] buildGetRevocRegRequestWithSubmitterDid:[TestUtils proverDid]
revocRegDefId:proof[@"identifiers"][0][@"rev_reg_id"]
timestamp:proof[@"identifiers"][0][@"timestamp"]
resultJson:&getRevocRegRequest];
XCTAssertEqual(ret.code, Success, @"buildGetRevocRegRequestWithSubmitterDid() failed!");
ret = [[PoolUtils sharedInstance] sendRequestWithPoolHandle:poolHandle
request:getRevocRegRequest
response:&getRevocRegResponse];
XCTAssertEqual(ret.code, Success, @"sendRequestWithPoolHandle() failed!");
ret = [[LedgerUtils sharedInstance] parseGetRevocRegResponse:getRevocRegResponse
revocRegDefId:&revocRegId
revocRegJson:&revocRegJson
timestamp:×tamp];
XCTAssertEqual(ret.code, Success, @"parseGetRevocRegResponse() failed!");
revocRegDefsJson = [[AnoncredsUtils sharedInstance] toJson:@{revocRegId: [NSDictionary fromString:revocRegDefJson]}];
revocRegsJson = [[AnoncredsUtils sharedInstance] toJson:@{revocRegId: @{[timestamp stringValue]: [NSDictionary fromString:revocRegJson]}}];
// Verifier verify proof
ret = [[AnoncredsUtils sharedInstance] verifierVerifyProofRequest:proofReqJson
proofJSON:proofJson
schemasJSON:schemasJson
credentialDefsJSON:credentialDefsJson
revocRegDefsJSON:revocRegDefsJson
revocRegsJSON:revocRegsJson
isValid:&isValid];
XCTAssertEqual(ret.code, Success, @"verifierVerifyProofRequest() failed!");
XCTAssertFalse(isValid, @"isValid == YES");
ret = [[WalletUtils sharedInstance] closeWalletWithHandle:issuerWalletHandle];
XCTAssertEqual(ret.code, Success, @"WalletUtils:closeWalletWithHandle failed");
ret = [[WalletUtils sharedInstance] closeWalletWithHandle:proverWalletHandle];
XCTAssertEqual(ret.code, Success, @"WalletUtils:closeWalletWithHandle failed");
ret = [[PoolUtils sharedInstance] closeHandle:poolHandle];
XCTAssertEqual(ret.code, Success, @"PoolUtils::closeHandle() failed!");
[TestUtils cleanupStorage];
}
@end