@@ -159,7 +159,7 @@ var HypersignVerifiableCredential = /** @class */ (function () {
159
159
return new Date ( date ) . toISOString ( ) . slice ( 0 , - 5 ) + 'Z' ;
160
160
}
161
161
else {
162
- return new Date ( ) . toISOString ( ) . slice ( 0 , - 5 ) + 'Z' ;
162
+ return new Date ( new Date ( ) . getTime ( ) - 100000 ) . toISOString ( ) . slice ( 0 , - 5 ) + 'Z' ;
163
163
}
164
164
} ;
165
165
HypersignVerifiableCredential . prototype . sha256Hash = function ( message ) {
@@ -349,7 +349,7 @@ var HypersignVerifiableCredential = /** @class */ (function () {
349
349
} ;
350
350
HypersignVerifiableCredential . prototype . issueCredential = function ( params ) {
351
351
return __awaiter ( this , void 0 , void 0 , function ( ) {
352
- var signerDidDoc , publicKeyId , publicKeyVerMethod , convertedKeyPair , keyPair , suite , credentialHash , credentialStatus , proofValue , issuerDID , issuerDidDoc , issuerPublicKeyId , issuerPublicKeyVerMethod , proof , resp , signedVC ;
352
+ var signerDidDoc , publicKeyId , publicKeyVerMethod , convertedKeyPair , keyPair , suite , credentialHash , credentialStatus , proofValue , issuerDID , issuerDidDoc , issuerPublicKeyId , issuerPublicKeyVerMethod , proof , signedVC , resp ;
353
353
return __generator ( this , function ( _a ) {
354
354
switch ( _a . label ) {
355
355
case 0 :
@@ -365,6 +365,9 @@ var HypersignVerifiableCredential = /** @class */ (function () {
365
365
if ( ! params . issuerDid ) {
366
366
throw new Error ( 'HID-SSI-SDK:: Error: params.issuerDid is required to issue credential' ) ;
367
367
}
368
+ if ( params . registerCredential == undefined ) {
369
+ params . registerCredential = true ;
370
+ }
368
371
return [ 4 /*yield*/ , this . hsDid . resolve ( { did : params . issuerDid } ) ] ;
369
372
case 1 :
370
373
signerDidDoc = ( _a . sent ( ) ) . didDocument ;
@@ -415,20 +418,162 @@ var HypersignVerifiableCredential = /** @class */ (function () {
415
418
proofValue : proofValue ,
416
419
proofPurpose : constants_1 . VC . PROOF_PURPOSE ,
417
420
} ;
418
- return [ 4 /*yield*/ , this . credStatusRPC . registerCredentialStatus ( credentialStatus , proof ) ] ;
419
- case 5 :
420
- resp = _a . sent ( ) ;
421
- if ( ! resp || resp . code != 0 ) {
422
- throw new Error ( 'HID-SSI-SDK:: Error while issuing the credential error = ' + resp . rawLog ) ;
423
- }
424
421
return [ 4 /*yield*/ , vc_js_1 . default . issue ( {
425
422
credential : params . credential ,
426
423
suite : suite ,
427
424
documentLoader : jsonld_1 . documentLoader ,
428
425
} ) ] ;
429
- case 6 :
426
+ case 5 :
430
427
signedVC = _a . sent ( ) ;
428
+ if ( ! params . registerCredential ) return [ 3 /*break*/ , 7 ] ;
429
+ return [ 4 /*yield*/ , this . credStatusRPC . registerCredentialStatus ( credentialStatus , proof ) ] ;
430
+ case 6 :
431
+ resp = _a . sent ( ) ;
432
+ if ( ! resp || resp . code != 0 ) {
433
+ throw new Error ( 'HID-SSI-SDK:: Error while issuing the credential error = ' + resp . rawLog ) ;
434
+ }
431
435
return [ 2 /*return*/ , signedVC ] ;
436
+ case 7 : return [ 2 /*return*/ , { signedVC : signedVC , credentialStatus : credentialStatus , proof : proof } ] ;
437
+ }
438
+ } ) ;
439
+ } ) ;
440
+ } ;
441
+ HypersignVerifiableCredential . prototype . registerCredentialStatus = function ( credentialStatus , proof ) {
442
+ return __awaiter ( this , void 0 , void 0 , function ( ) {
443
+ var resp ;
444
+ return __generator ( this , function ( _a ) {
445
+ switch ( _a . label ) {
446
+ case 0 :
447
+ if ( ! credentialStatus || ! proof )
448
+ throw new Error ( 'HID-SSI-SDK:: Error: credentialStatus and proof are required to register credential status' ) ;
449
+ return [ 4 /*yield*/ , this . credStatusRPC . registerCredentialStatus ( credentialStatus , proof ) ] ;
450
+ case 1 :
451
+ resp = _a . sent ( ) ;
452
+ if ( ! resp || resp . code != 0 ) {
453
+ throw new Error ( 'HID-SSI-SDK:: Error while issuing the credential error = ' + resp . rawLog ) ;
454
+ }
455
+ return [ 2 /*return*/ , resp ] ;
456
+ }
457
+ } ) ;
458
+ } ) ;
459
+ } ;
460
+ HypersignVerifiableCredential . prototype . updateCredentialStatus = function ( params ) {
461
+ return __awaiter ( this , void 0 , void 0 , function ( ) {
462
+ var signerDidDoc , publicKeyId , publicKeyVerMethod , convertedKeyPair , keyPair , suite , claim , credentialStatus , proofValue , issuerDID , issuerDidDoc , issuerPublicKeyId , issuerPublicKeyVerMethod , proof , resp ;
463
+ return __generator ( this , function ( _a ) {
464
+ switch ( _a . label ) {
465
+ case 0 :
466
+ if ( ! params . verificationMethodId ) {
467
+ throw new Error ( 'HID-SSI-SDK:: Error: params.verificationMethodId is required revoke credential' ) ;
468
+ }
469
+ if ( ! params . credStatus ) {
470
+ throw new Error ( 'HID-SSI-SDK:: Error: params.credential is required to revoke credential' ) ;
471
+ }
472
+ if ( ! params . privateKey ) {
473
+ throw new Error ( 'HID-SSI-SDK:: Error: params.privateKey is required to revoke credential' ) ;
474
+ }
475
+ if ( ! params . issuerDid ) {
476
+ throw new Error ( 'HID-SSI-SDK:: Error: params.issuerDid is required to revoke credential' ) ;
477
+ }
478
+ if ( ! params . status ) {
479
+ throw new Error ( 'HID-SSI-SDK:: Error: params.status is required to revoke credential' ) ;
480
+ }
481
+ return [ 4 /*yield*/ , this . hsDid . resolve ( { did : params . issuerDid } ) ] ;
482
+ case 1 :
483
+ signerDidDoc = ( _a . sent ( ) ) . didDocument ;
484
+ if ( ! signerDidDoc )
485
+ throw new Error ( 'Could not resolve issuerDid = ' + params . issuerDid ) ;
486
+ publicKeyId = params . verificationMethodId ;
487
+ publicKeyVerMethod = signerDidDoc [ 'verificationMethod' ] . find ( function ( x ) { return x . id == publicKeyId ; } ) ;
488
+ convertedKeyPair = utils_1 . default . convertedStableLibKeysIntoEd25519verificationkey2020 ( {
489
+ publicKey : publicKeyVerMethod . publicKeyMultibase ,
490
+ } ) ;
491
+ publicKeyVerMethod [ 'publicKeyMultibase' ] = convertedKeyPair . publicKeyMultibase ;
492
+ return [ 4 /*yield*/ , ed25519_verification_key_2020_1 . Ed25519VerificationKey2020 . from ( __assign ( { privateKeyMultibase : params . privateKey } , publicKeyVerMethod ) ) ] ;
493
+ case 2 :
494
+ keyPair = _a . sent ( ) ;
495
+ suite = new ed25519_signature_2020_1 . Ed25519Signature2020 ( {
496
+ verificationMethod : publicKeyId ,
497
+ key : keyPair ,
498
+ } ) ;
499
+ /// Before we issue the credential the credential status has to be added
500
+ /// for that we will call RegisterCredentialStatus RPC
501
+ // Let us generate credentialHash first
502
+ params . status = params . status . toUpperCase ( ) ;
503
+ claim = params . credStatus . claim ;
504
+ credentialStatus = {
505
+ claim : {
506
+ id : claim . id ,
507
+ currentStatus : constants_1 . VC . CRED_STATUS_TYPES [ params . status ] ,
508
+ statusReason : params . statusReason ? params . statusReason : constants_1 . VC . CRED_STATUS_REASON_TYPES [ params . status ] ,
509
+ } ,
510
+ issuer : params . credStatus . issuer ,
511
+ issuanceDate : params . credStatus . issuanceDate ,
512
+ expirationDate : params . credStatus . expirationDate ,
513
+ credentialHash : params . credStatus . credentialHash ,
514
+ } ;
515
+ return [ 4 /*yield*/ , this . sign ( {
516
+ message : JSON . stringify ( credentialStatus ) ,
517
+ privateKeyMultibase : params . privateKey ,
518
+ } ) ] ;
519
+ case 3 :
520
+ proofValue = _a . sent ( ) ;
521
+ return [ 4 /*yield*/ , this . hsDid . resolve ( { did : params . credStatus . issuer } ) ] ;
522
+ case 4 :
523
+ issuerDID = ( _a . sent ( ) ) . didDocument ;
524
+ issuerDidDoc = issuerDID ;
525
+ issuerPublicKeyId = params . verificationMethodId ;
526
+ issuerPublicKeyVerMethod = issuerDidDoc . verificationMethod . find ( function ( x ) { return x . id == issuerPublicKeyId ; } ) ;
527
+ proof = {
528
+ type : constants_1 . VC . VERIFICATION_METHOD_TYPE ,
529
+ created : params . credStatus . issuanceDate ,
530
+ updated : this . dateNow ( ) ,
531
+ verificationMethod : issuerPublicKeyVerMethod . id ,
532
+ proofValue : proofValue ,
533
+ proofPurpose : constants_1 . VC . PROOF_PURPOSE ,
534
+ } ;
535
+ return [ 4 /*yield*/ , this . credStatusRPC . registerCredentialStatus ( credentialStatus , proof ) ] ;
536
+ case 5 :
537
+ resp = _a . sent ( ) ;
538
+ if ( ! resp || resp . code != 0 ) {
539
+ throw new Error ( 'HID-SSI-SDK:: Error while revoking the credential error = ' + resp . rawLog ) ;
540
+ }
541
+ return [ 2 /*return*/ , resp ] ;
542
+ }
543
+ } ) ;
544
+ } ) ;
545
+ } ;
546
+ HypersignVerifiableCredential . prototype . generateRegisterCredentialStatusTxnMessage = function ( credentialStatus , proof ) {
547
+ return __awaiter ( this , void 0 , void 0 , function ( ) {
548
+ var txnMessage ;
549
+ return __generator ( this , function ( _a ) {
550
+ switch ( _a . label ) {
551
+ case 0 :
552
+ if ( ! credentialStatus || ! proof )
553
+ throw new Error ( 'HID-SSI-SDK:: Error: credentialStatus and proof are required to register credential status' ) ;
554
+ return [ 4 /*yield*/ , this . credStatusRPC . generateCredentialStatusTxnMessage ( credentialStatus , proof ) ] ;
555
+ case 1 :
556
+ txnMessage = _a . sent ( ) ;
557
+ return [ 2 /*return*/ , txnMessage ] ;
558
+ }
559
+ } ) ;
560
+ } ) ;
561
+ } ;
562
+ HypersignVerifiableCredential . prototype . registerCredentialStatusTxnBulk = function ( txnMessage ) {
563
+ return __awaiter ( this , void 0 , void 0 , function ( ) {
564
+ var resp ;
565
+ return __generator ( this , function ( _a ) {
566
+ switch ( _a . label ) {
567
+ case 0 :
568
+ if ( ! txnMessage )
569
+ throw new Error ( 'HID-SSI-SDK:: Error: txnMessage is required to register credential status' ) ;
570
+ return [ 4 /*yield*/ , this . credStatusRPC . registerCredentialStatusBulk ( txnMessage ) ] ;
571
+ case 1 :
572
+ resp = _a . sent ( ) ;
573
+ if ( ! resp || resp . code != 0 ) {
574
+ throw new Error ( 'HID-SSI-SDK:: Error while issuing the credential error = ' + resp . rawLog ) ;
575
+ }
576
+ return [ 2 /*return*/ , resp ] ;
432
577
}
433
578
} ) ;
434
579
} ) ;
0 commit comments