@0xpolygonid/js-sdk 1.18.3 → 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.
@@ -80698,12 +80698,20 @@ var PolygonIdSdk = (function (exports) {
80698
80698
  },
80699
80699
  allowedIssuers: [did.string()]
80700
80700
  });
80701
- if (credentials.length) {
80701
+ // if credential exists with the same credential status type we return this credential
80702
+ if (credentials.length === 1 &&
80703
+ credentials[0].credentialStatus.type === opts.revocationOpts.type) {
80702
80704
  return {
80703
80705
  did,
80704
80706
  credential: credentials[0]
80705
80707
  };
80706
80708
  }
80709
+ // 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.
80710
+ // in this way credential status of auth credential can be upgraded
80711
+ for (let i = 0; i < credentials.length; i++) {
80712
+ await this._credentialWallet.remove(credentials[i].id);
80713
+ }
80714
+ // otherwise we create a new credential
80707
80715
  const credential = await this.createAuthBJJCredential(did, pubKey, authClaim, currentState, opts.revocationOpts);
80708
80716
  const index = authClaim.hIndex();
80709
80717
  const { proof } = await claimsTree.generateProof(index, ctr);
@@ -80721,10 +80729,13 @@ var PolygonIdSdk = (function (exports) {
80721
80729
  coreClaim: authClaim
80722
80730
  });
80723
80731
  credential.proof = [mtpProof];
80724
- await this.publishRevocationInfoByCredentialStatusType(did, opts.revocationOpts.type, {
80725
- rhsUrl: opts.revocationOpts.id,
80726
- onChain: opts.revocationOpts.onChain
80727
- });
80732
+ // only if user specified that genesis state publishing is not needed we won't do this.
80733
+ if (!opts.revocationOpts.genesisPublishingDisabled) {
80734
+ await this.publishRevocationInfoByCredentialStatusType(did, opts.revocationOpts.type, {
80735
+ rhsUrl: opts.revocationOpts.id,
80736
+ onChain: opts.revocationOpts.onChain
80737
+ });
80738
+ }
80728
80739
  await this._credentialWallet.save(credential);
80729
80740
  return {
80730
80741
  did,
@@ -81087,23 +81098,13 @@ var PolygonIdSdk = (function (exports) {
81087
81098
  throw new Error(`there is no registered publisher to save hash is not registered for ${credentialStatusType} is not registered`);
81088
81099
  }
81089
81100
  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
- }
81101
+ const tree = opts?.treeModel ?? (await this.getDIDTreeModel(issuerDID));
81102
+ nodes = await getNodesRepresentation(opts?.revokedNonces ?? [], {
81103
+ revocationTree: tree.revocationTree,
81104
+ claimsTree: tree.claimsTree,
81105
+ state: tree.state,
81106
+ rootsTree: tree.rootsTree
81107
+ }, tree.state);
81107
81108
  if (!nodes.length) {
81108
81109
  return;
81109
81110
  }