@0xpolygonid/js-sdk 1.18.2 → 1.18.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -63,8 +63,8 @@ class CredentialWallet {
63
63
  request.context.push(verifiable_1.VerifiableConstants.JSONLD_SCHEMA.IDEN3_DISPLAY_METHOD);
64
64
  }
65
65
  const context = [
66
- ...request.context,
67
66
  verifiable_1.VerifiableConstants.JSONLD_SCHEMA.W3C_CREDENTIAL_2018,
67
+ ...request.context,
68
68
  verifiable_1.VerifiableConstants.JSONLD_SCHEMA.IDEN3_CREDENTIAL,
69
69
  schema.$metadata.uris['jsonLdContext']
70
70
  ];
@@ -176,12 +176,20 @@ class IdentityWallet {
176
176
  },
177
177
  allowedIssuers: [did.string()]
178
178
  });
179
- if (credentials.length) {
179
+ // if credential exists with the same credential status type we return this credential
180
+ if (credentials.length === 1 &&
181
+ credentials[0].credentialStatus.type === opts.revocationOpts.type) {
180
182
  return {
181
183
  did,
182
184
  credential: credentials[0]
183
185
  };
184
186
  }
187
+ // 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.
188
+ // in this way credential status of auth credential can be upgraded
189
+ for (let i = 0; i < credentials.length; i++) {
190
+ await this._credentialWallet.remove(credentials[i].id);
191
+ }
192
+ // otherwise we create a new credential
185
193
  const credential = await this.createAuthBJJCredential(did, pubKey, authClaim, currentState, opts.revocationOpts);
186
194
  const index = authClaim.hIndex();
187
195
  const { proof } = await claimsTree.generateProof(index, ctr);
@@ -199,10 +207,13 @@ class IdentityWallet {
199
207
  coreClaim: authClaim
200
208
  });
201
209
  credential.proof = [mtpProof];
202
- await this.publishRevocationInfoByCredentialStatusType(did, opts.revocationOpts.type, {
203
- rhsUrl: opts.revocationOpts.id,
204
- onChain: opts.revocationOpts.onChain
205
- });
210
+ // only if user specified that genesis state publishing is not needed we won't do this.
211
+ if (!opts.revocationOpts.genesisPublishingDisabled) {
212
+ await this.publishRevocationInfoByCredentialStatusType(did, opts.revocationOpts.type, {
213
+ rhsUrl: opts.revocationOpts.id,
214
+ onChain: opts.revocationOpts.onChain
215
+ });
216
+ }
206
217
  await this._credentialWallet.save(credential);
207
218
  return {
208
219
  did,
@@ -565,23 +576,13 @@ class IdentityWallet {
565
576
  throw new Error(`there is no registered publisher to save hash is not registered for ${credentialStatusType} is not registered`);
566
577
  }
567
578
  let nodes = [];
568
- if (opts?.treeModel) {
569
- nodes = await (0, credentials_1.getNodesRepresentation)(opts.revokedNonces, {
570
- revocationTree: opts.treeModel.revocationTree,
571
- claimsTree: opts.treeModel.claimsTree,
572
- state: opts.treeModel.state,
573
- rootsTree: opts.treeModel.rootsTree
574
- }, opts.treeModel.state);
575
- }
576
- else {
577
- const treeState = await this.getDIDTreeModel(issuerDID);
578
- nodes = await (0, credentials_1.getNodesRepresentation)(opts?.revokedNonces, {
579
- revocationTree: treeState.revocationTree,
580
- claimsTree: treeState.claimsTree,
581
- state: treeState.state,
582
- rootsTree: treeState.rootsTree
583
- }, treeState.state);
584
- }
579
+ const tree = opts?.treeModel ?? (await this.getDIDTreeModel(issuerDID));
580
+ nodes = await (0, credentials_1.getNodesRepresentation)(opts?.revokedNonces ?? [], {
581
+ revocationTree: tree.revocationTree,
582
+ claimsTree: tree.claimsTree,
583
+ state: tree.state,
584
+ rootsTree: tree.rootsTree
585
+ }, tree.state);
585
586
  if (!nodes.length) {
586
587
  return;
587
588
  }
@@ -37,8 +37,8 @@ export class CredentialWallet {
37
37
  request.context.push(VerifiableConstants.JSONLD_SCHEMA.IDEN3_DISPLAY_METHOD);
38
38
  }
39
39
  const context = [
40
- ...request.context,
41
40
  VerifiableConstants.JSONLD_SCHEMA.W3C_CREDENTIAL_2018,
41
+ ...request.context,
42
42
  VerifiableConstants.JSONLD_SCHEMA.IDEN3_CREDENTIAL,
43
43
  schema.$metadata.uris['jsonLdContext']
44
44
  ];
@@ -150,12 +150,20 @@ export class IdentityWallet {
150
150
  },
151
151
  allowedIssuers: [did.string()]
152
152
  });
153
- if (credentials.length) {
153
+ // if credential exists with the same credential status type we return this credential
154
+ if (credentials.length === 1 &&
155
+ credentials[0].credentialStatus.type === opts.revocationOpts.type) {
154
156
  return {
155
157
  did,
156
158
  credential: credentials[0]
157
159
  };
158
160
  }
161
+ // 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.
162
+ // in this way credential status of auth credential can be upgraded
163
+ for (let i = 0; i < credentials.length; i++) {
164
+ await this._credentialWallet.remove(credentials[i].id);
165
+ }
166
+ // otherwise we create a new credential
159
167
  const credential = await this.createAuthBJJCredential(did, pubKey, authClaim, currentState, opts.revocationOpts);
160
168
  const index = authClaim.hIndex();
161
169
  const { proof } = await claimsTree.generateProof(index, ctr);
@@ -173,10 +181,13 @@ export class IdentityWallet {
173
181
  coreClaim: authClaim
174
182
  });
175
183
  credential.proof = [mtpProof];
176
- await this.publishRevocationInfoByCredentialStatusType(did, opts.revocationOpts.type, {
177
- rhsUrl: opts.revocationOpts.id,
178
- onChain: opts.revocationOpts.onChain
179
- });
184
+ // only if user specified that genesis state publishing is not needed we won't do this.
185
+ if (!opts.revocationOpts.genesisPublishingDisabled) {
186
+ await this.publishRevocationInfoByCredentialStatusType(did, opts.revocationOpts.type, {
187
+ rhsUrl: opts.revocationOpts.id,
188
+ onChain: opts.revocationOpts.onChain
189
+ });
190
+ }
180
191
  await this._credentialWallet.save(credential);
181
192
  return {
182
193
  did,
@@ -539,23 +550,13 @@ export class IdentityWallet {
539
550
  throw new Error(`there is no registered publisher to save hash is not registered for ${credentialStatusType} is not registered`);
540
551
  }
541
552
  let nodes = [];
542
- if (opts?.treeModel) {
543
- nodes = await getNodesRepresentation(opts.revokedNonces, {
544
- revocationTree: opts.treeModel.revocationTree,
545
- claimsTree: opts.treeModel.claimsTree,
546
- state: opts.treeModel.state,
547
- rootsTree: opts.treeModel.rootsTree
548
- }, opts.treeModel.state);
549
- }
550
- else {
551
- const treeState = await this.getDIDTreeModel(issuerDID);
552
- nodes = await getNodesRepresentation(opts?.revokedNonces, {
553
- revocationTree: treeState.revocationTree,
554
- claimsTree: treeState.claimsTree,
555
- state: treeState.state,
556
- rootsTree: treeState.rootsTree
557
- }, treeState.state);
558
- }
553
+ const tree = opts?.treeModel ?? (await this.getDIDTreeModel(issuerDID));
554
+ nodes = await getNodesRepresentation(opts?.revokedNonces ?? [], {
555
+ revocationTree: tree.revocationTree,
556
+ claimsTree: tree.claimsTree,
557
+ state: tree.state,
558
+ rootsTree: tree.rootsTree
559
+ }, tree.state);
559
560
  if (!nodes.length) {
560
561
  return;
561
562
  }
@@ -24,13 +24,19 @@ export type IdentityCreationOptions = {
24
24
  /**
25
25
  * Options for creating Auth BJJ credential
26
26
  * seed - seed to generate BJJ key pair
27
- * revocationOpts -
27
+ * revocationOpts
28
+ * nonce - explicit revocation nonce to use
29
+ * onChain - onchain status related option
30
+ * txCallback - defines how the TransactionReceipt is handled
31
+ * publishMode - specifies the work of transaction polling type: sync / async / callback
32
+ * genesisPublishingDisabled - genesis is publishing by default. Set `true` to prevent genesis publishing
28
33
  */
29
34
  export type AuthBJJCredentialCreationOptions = {
30
35
  revocationOpts: {
31
36
  id: string;
32
37
  type: CredentialStatusType;
33
38
  nonce?: number;
39
+ genesisPublishingDisabled?: boolean;
34
40
  onChain?: {
35
41
  txCallback?: (tx: TransactionReceipt) => Promise<void>;
36
42
  publishMode?: PublishMode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xpolygonid/js-sdk",
3
- "version": "1.18.2",
3
+ "version": "1.18.4",
4
4
  "description": "SDK to work with Polygon ID",
5
5
  "main": "dist/node/cjs/index.js",
6
6
  "module": "dist/node/esm/index.js",