@@ -76,13 +76,19 @@ export type IdentityCreationOptions = {
76
76
/**
77
77
* Options for creating Auth BJJ credential
78
78
* seed - seed to generate BJJ key pair
79
- * revocationOpts -
79
+ * revocationOpts
80
+ * nonce - explicit revocation nonce to use
81
+ * onChain - onchain status related option
82
+ * txCallback - defines how the TransactionReceipt is handled
83
+ * publishMode - specifies the work of transaction polling type: sync / async / callback
84
+ * genesisPublishingDisabled - genesis is publishing by default. Set `true` to prevent genesis publishing
80
85
*/
81
86
export type AuthBJJCredentialCreationOptions = {
82
87
revocationOpts : {
83
88
id : string ;
84
89
type : CredentialStatusType ;
85
90
nonce ?: number ;
91
+ genesisPublishingDisabled ?: boolean ;
86
92
onChain ?: {
87
93
txCallback ?: ( tx : TransactionReceipt ) => Promise < void > ;
88
94
publishMode ?: PublishMode ;
@@ -661,13 +667,24 @@ export class IdentityWallet implements IIdentityWallet {
661
667
allowedIssuers : [ did . string ( ) ]
662
668
} ) ;
663
669
664
- if ( credentials . length ) {
670
+ // if credential exists with the same credential status type we return this credential
671
+ if (
672
+ credentials . length === 1 &&
673
+ credentials [ 0 ] . credentialStatus . type === opts . revocationOpts . type
674
+ ) {
665
675
return {
666
676
did,
667
677
credential : credentials [ 0 ]
668
678
} ;
669
679
}
670
680
681
+ // otherwise something is already wrong with storage as it has more than 1 credential in it or credential status type of existing credential is different from what user provides - We should remove everything and create new credential.
682
+ // in this way credential status of auth credential can be upgraded
683
+ for ( let i = 0 ; i < credentials . length ; i ++ ) {
684
+ await this . _credentialWallet . remove ( credentials [ i ] . id ) ;
685
+ }
686
+
687
+ // otherwise we create a new credential
671
688
const credential = await this . createAuthBJJCredential (
672
689
did ,
673
690
pubKey ,
@@ -695,10 +712,13 @@ export class IdentityWallet implements IIdentityWallet {
695
712
696
713
credential . proof = [ mtpProof ] ;
697
714
698
- await this . publishRevocationInfoByCredentialStatusType ( did , opts . revocationOpts . type , {
699
- rhsUrl : opts . revocationOpts . id ,
700
- onChain : opts . revocationOpts . onChain
701
- } ) ;
715
+ // only if user specified that genesis state publishing is not needed we won't do this.
716
+ if ( ! opts . revocationOpts . genesisPublishingDisabled ) {
717
+ await this . publishRevocationInfoByCredentialStatusType ( did , opts . revocationOpts . type , {
718
+ rhsUrl : opts . revocationOpts . id ,
719
+ onChain : opts . revocationOpts . onChain
720
+ } ) ;
721
+ }
702
722
703
723
await this . _credentialWallet . save ( credential ) ;
704
724
@@ -1248,30 +1268,18 @@ export class IdentityWallet implements IIdentityWallet {
1248
1268
}
1249
1269
1250
1270
let nodes : ProofNode [ ] = [ ] ;
1251
- if ( opts ?. treeModel ) {
1252
- nodes = await getNodesRepresentation (
1253
- opts . revokedNonces ,
1254
- {
1255
- revocationTree : opts . treeModel . revocationTree ,
1256
- claimsTree : opts . treeModel . claimsTree ,
1257
- state : opts . treeModel . state ,
1258
- rootsTree : opts . treeModel . rootsTree
1259
- } ,
1260
- opts . treeModel . state
1261
- ) ;
1262
- } else {
1263
- const treeState = await this . getDIDTreeModel ( issuerDID ) ;
1264
- nodes = await getNodesRepresentation (
1265
- opts ?. revokedNonces ,
1266
- {
1267
- revocationTree : treeState . revocationTree ,
1268
- claimsTree : treeState . claimsTree ,
1269
- state : treeState . state ,
1270
- rootsTree : treeState . rootsTree
1271
- } ,
1272
- treeState . state
1273
- ) ;
1274
- }
1271
+
1272
+ const tree = opts ?. treeModel ?? ( await this . getDIDTreeModel ( issuerDID ) ) ;
1273
+ nodes = await getNodesRepresentation (
1274
+ opts ?. revokedNonces ?? [ ] ,
1275
+ {
1276
+ revocationTree : tree . revocationTree ,
1277
+ claimsTree : tree . claimsTree ,
1278
+ state : tree . state ,
1279
+ rootsTree : tree . rootsTree
1280
+ } ,
1281
+ tree . state
1282
+ ) ;
1275
1283
1276
1284
if ( ! nodes . length ) {
1277
1285
return ;
0 commit comments