@0xpolygonid/js-sdk 1.18.3 → 1.19.0

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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Polygon ID JS SDK
1
+ # Privado ID JS SDK
2
2
 
3
- SDK to work with Polygon ID using JavaScript and TypeScript languages.
3
+ SDK to work with Privado ID using JavaScript and TypeScript languages.
4
4
 
5
5
  ## Usage
6
6
 
@@ -20438,14 +20438,26 @@ const defineMerklizedRootPosition = (metadata, position) => {
20438
20438
  * Returns profile DID based on did and profile nonce
20439
20439
  *
20440
20440
  * @param {DID} [did] - did from which profile will be derived
20441
- * @param {number} [profileNonce] - profile nonce
20441
+ * @param {number | string} [profileNonce] - profile nonce
20442
20442
  * @returns {DID}
20443
20443
  */
20444
20444
  const generateProfileDID = (did, profileNonce) => {
20445
20445
  const id = DID.idFromDID(did);
20446
- const profile = Id$1.profileId(id, BigInt(profileNonce ?? 0));
20446
+ profileNonce = profileNonce ?? 0;
20447
+ if (!isBigInt(profileNonce)) {
20448
+ throw new Error('profile must be number or decimal string');
20449
+ }
20450
+ const profile = Id$1.profileId(id, BigInt(profileNonce));
20447
20451
  return DID.parseFromId(profile);
20448
20452
  };
20453
+ const isBigInt = (x) => {
20454
+ try {
20455
+ return BigInt(x).toString() === x.toString();
20456
+ }
20457
+ catch {
20458
+ return false; // conversion to BigInt failed, surely it is not a BigInt
20459
+ }
20460
+ };
20449
20461
 
20450
20462
  // Unique ID creation requires a high quality random # generator. In the browser we therefore
20451
20463
  // require the crypto API and do not support built-in fallback to lower quality random number
@@ -59816,12 +59828,20 @@ class IdentityWallet {
59816
59828
  },
59817
59829
  allowedIssuers: [did.string()]
59818
59830
  });
59819
- if (credentials.length) {
59831
+ // if credential exists with the same credential status type we return this credential
59832
+ if (credentials.length === 1 &&
59833
+ credentials[0].credentialStatus.type === opts.revocationOpts.type) {
59820
59834
  return {
59821
59835
  did,
59822
59836
  credential: credentials[0]
59823
59837
  };
59824
59838
  }
59839
+ // 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.
59840
+ // in this way credential status of auth credential can be upgraded
59841
+ for (let i = 0; i < credentials.length; i++) {
59842
+ await this._credentialWallet.remove(credentials[i].id);
59843
+ }
59844
+ // otherwise we create a new credential
59825
59845
  const credential = await this.createAuthBJJCredential(did, pubKey, authClaim, currentState, opts.revocationOpts);
59826
59846
  const index = authClaim.hIndex();
59827
59847
  const { proof } = await claimsTree.generateProof(index, ctr);
@@ -59839,10 +59859,13 @@ class IdentityWallet {
59839
59859
  coreClaim: authClaim
59840
59860
  });
59841
59861
  credential.proof = [mtpProof];
59842
- await this.publishRevocationInfoByCredentialStatusType(did, opts.revocationOpts.type, {
59843
- rhsUrl: opts.revocationOpts.id,
59844
- onChain: opts.revocationOpts.onChain
59845
- });
59862
+ // only if user specified that genesis state publishing is not needed we won't do this.
59863
+ if (!opts.revocationOpts.genesisPublishingDisabled) {
59864
+ await this.publishRevocationInfoByCredentialStatusType(did, opts.revocationOpts.type, {
59865
+ rhsUrl: opts.revocationOpts.id,
59866
+ onChain: opts.revocationOpts.onChain
59867
+ });
59868
+ }
59846
59869
  await this._credentialWallet.save(credential);
59847
59870
  return {
59848
59871
  did,
@@ -60205,23 +60228,13 @@ class IdentityWallet {
60205
60228
  throw new Error(`there is no registered publisher to save hash is not registered for ${credentialStatusType} is not registered`);
60206
60229
  }
60207
60230
  let nodes = [];
60208
- if (opts?.treeModel) {
60209
- nodes = await getNodesRepresentation(opts.revokedNonces, {
60210
- revocationTree: opts.treeModel.revocationTree,
60211
- claimsTree: opts.treeModel.claimsTree,
60212
- state: opts.treeModel.state,
60213
- rootsTree: opts.treeModel.rootsTree
60214
- }, opts.treeModel.state);
60215
- }
60216
- else {
60217
- const treeState = await this.getDIDTreeModel(issuerDID);
60218
- nodes = await getNodesRepresentation(opts?.revokedNonces, {
60219
- revocationTree: treeState.revocationTree,
60220
- claimsTree: treeState.claimsTree,
60221
- state: treeState.state,
60222
- rootsTree: treeState.rootsTree
60223
- }, treeState.state);
60224
- }
60231
+ const tree = opts?.treeModel ?? (await this.getDIDTreeModel(issuerDID));
60232
+ nodes = await getNodesRepresentation(opts?.revokedNonces ?? [], {
60233
+ revocationTree: tree.revocationTree,
60234
+ claimsTree: tree.claimsTree,
60235
+ state: tree.state,
60236
+ rootsTree: tree.rootsTree
60237
+ }, tree.state);
60225
60238
  if (!nodes.length) {
60226
60239
  return;
60227
60240
  }