@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.
@@ -20577,14 +20577,26 @@ var PolygonIdSdk = (function (exports) {
20577
20577
  * Returns profile DID based on did and profile nonce
20578
20578
  *
20579
20579
  * @param {DID} [did] - did from which profile will be derived
20580
- * @param {number} [profileNonce] - profile nonce
20580
+ * @param {number | string} [profileNonce] - profile nonce
20581
20581
  * @returns {DID}
20582
20582
  */
20583
20583
  const generateProfileDID = (did, profileNonce) => {
20584
20584
  const id = Z$2.idFromDID(did);
20585
- const profile = H$2.profileId(id, BigInt(profileNonce ?? 0));
20585
+ profileNonce = profileNonce ?? 0;
20586
+ if (!isBigInt(profileNonce)) {
20587
+ throw new Error('profile must be number or decimal string');
20588
+ }
20589
+ const profile = H$2.profileId(id, BigInt(profileNonce));
20586
20590
  return Z$2.parseFromId(profile);
20587
20591
  };
20592
+ const isBigInt = (x) => {
20593
+ try {
20594
+ return BigInt(x).toString() === x.toString();
20595
+ }
20596
+ catch {
20597
+ return false; // conversion to BigInt failed, surely it is not a BigInt
20598
+ }
20599
+ };
20588
20600
 
20589
20601
  // Unique ID creation requires a high quality random # generator. In the browser we therefore
20590
20602
  // require the crypto API and do not support built-in fallback to lower quality random number
@@ -80698,12 +80710,20 @@ var PolygonIdSdk = (function (exports) {
80698
80710
  },
80699
80711
  allowedIssuers: [did.string()]
80700
80712
  });
80701
- if (credentials.length) {
80713
+ // if credential exists with the same credential status type we return this credential
80714
+ if (credentials.length === 1 &&
80715
+ credentials[0].credentialStatus.type === opts.revocationOpts.type) {
80702
80716
  return {
80703
80717
  did,
80704
80718
  credential: credentials[0]
80705
80719
  };
80706
80720
  }
80721
+ // 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.
80722
+ // in this way credential status of auth credential can be upgraded
80723
+ for (let i = 0; i < credentials.length; i++) {
80724
+ await this._credentialWallet.remove(credentials[i].id);
80725
+ }
80726
+ // otherwise we create a new credential
80707
80727
  const credential = await this.createAuthBJJCredential(did, pubKey, authClaim, currentState, opts.revocationOpts);
80708
80728
  const index = authClaim.hIndex();
80709
80729
  const { proof } = await claimsTree.generateProof(index, ctr);
@@ -80721,10 +80741,13 @@ var PolygonIdSdk = (function (exports) {
80721
80741
  coreClaim: authClaim
80722
80742
  });
80723
80743
  credential.proof = [mtpProof];
80724
- await this.publishRevocationInfoByCredentialStatusType(did, opts.revocationOpts.type, {
80725
- rhsUrl: opts.revocationOpts.id,
80726
- onChain: opts.revocationOpts.onChain
80727
- });
80744
+ // only if user specified that genesis state publishing is not needed we won't do this.
80745
+ if (!opts.revocationOpts.genesisPublishingDisabled) {
80746
+ await this.publishRevocationInfoByCredentialStatusType(did, opts.revocationOpts.type, {
80747
+ rhsUrl: opts.revocationOpts.id,
80748
+ onChain: opts.revocationOpts.onChain
80749
+ });
80750
+ }
80728
80751
  await this._credentialWallet.save(credential);
80729
80752
  return {
80730
80753
  did,
@@ -81087,23 +81110,13 @@ var PolygonIdSdk = (function (exports) {
81087
81110
  throw new Error(`there is no registered publisher to save hash is not registered for ${credentialStatusType} is not registered`);
81088
81111
  }
81089
81112
  let nodes = [];
81090
- if (opts?.treeModel) {
81091
- nodes = await getNodesRepresentation(opts.revokedNonces, {
81092
- revocationTree: opts.treeModel.revocationTree,
81093
- claimsTree: opts.treeModel.claimsTree,
81094
- state: opts.treeModel.state,
81095
- rootsTree: opts.treeModel.rootsTree
81096
- }, opts.treeModel.state);
81097
- }
81098
- else {
81099
- const treeState = await this.getDIDTreeModel(issuerDID);
81100
- nodes = await getNodesRepresentation(opts?.revokedNonces, {
81101
- revocationTree: treeState.revocationTree,
81102
- claimsTree: treeState.claimsTree,
81103
- state: treeState.state,
81104
- rootsTree: treeState.rootsTree
81105
- }, treeState.state);
81106
- }
81113
+ const tree = opts?.treeModel ?? (await this.getDIDTreeModel(issuerDID));
81114
+ nodes = await getNodesRepresentation(opts?.revokedNonces ?? [], {
81115
+ revocationTree: tree.revocationTree,
81116
+ claimsTree: tree.claimsTree,
81117
+ state: tree.state,
81118
+ rootsTree: tree.rootsTree
81119
+ }, tree.state);
81107
81120
  if (!nodes.length) {
81108
81121
  return;
81109
81122
  }