@0xpolygonid/js-sdk 1.8.1 → 1.8.3

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.
@@ -61582,6 +61582,16 @@ var PolygonIdSdk = (function (exports) {
61582
61582
  }
61583
61583
  throw new Error('all auth bjj credentials are revoked');
61584
61584
  }
61585
+ /**
61586
+ * {@inheritDoc ICredentialWallet.getAllAuthBJJCredentials}
61587
+ */
61588
+ async getAllAuthBJJCredentials(did) {
61589
+ return this._storage.credential.findCredentialsByQuery({
61590
+ context: VerifiableConstants.AUTH.AUTH_BJJ_CREDENTIAL_SCHEMA_JSONLD_URL,
61591
+ type: VerifiableConstants.AUTH.AUTH_BJJ_CREDENTIAL_TYPE,
61592
+ allowedIssuers: [did.string()]
61593
+ });
61594
+ }
61585
61595
  /**
61586
61596
  * {@inheritDoc ICredentialWallet.getRevocationStatusFromCredential}
61587
61597
  */
@@ -61863,13 +61873,19 @@ var PolygonIdSdk = (function (exports) {
61863
61873
  this._storage = _storage;
61864
61874
  this._credentialWallet = _credentialWallet;
61865
61875
  this._opts = _opts;
61876
+ this._credentialStatusPublisherRegistry = this.getCredentialStatusPublisherRegistry(_opts);
61877
+ }
61878
+ getCredentialStatusPublisherRegistry(_opts) {
61866
61879
  if (!_opts?.credentialStatusPublisherRegistry) {
61867
- this._credentialStatusPublisherRegistry = new CredentialStatusPublisherRegistry();
61868
- this._credentialStatusPublisherRegistry.register(exports.CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, new Iden3SmtRhsCredentialStatusPublisher());
61880
+ const registry = new CredentialStatusPublisherRegistry();
61881
+ const emptyPublisher = { publish: () => Promise.resolve() };
61882
+ registry.register(exports.CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, new Iden3SmtRhsCredentialStatusPublisher());
61883
+ registry.register(exports.CredentialStatusType.SparseMerkleTreeProof, emptyPublisher);
61884
+ registry.register(exports.CredentialStatusType.Iden3commRevocationStatusV1, emptyPublisher);
61885
+ return registry;
61869
61886
  }
61870
61887
  else {
61871
- this._credentialStatusPublisherRegistry = this._opts
61872
- ?.credentialStatusPublisherRegistry;
61888
+ return this._opts?.credentialStatusPublisherRegistry;
61873
61889
  }
61874
61890
  }
61875
61891
  /**
@@ -62107,7 +62123,7 @@ var PolygonIdSdk = (function (exports) {
62107
62123
  catch (e) {
62108
62124
  throw new Error(`Error create w3c credential ${e.message}`);
62109
62125
  }
62110
- const issuerAuthBJJCredential = await this._credentialWallet.getAuthBJJCredential(issuerDID);
62126
+ const { authCredential: issuerAuthBJJCredential } = await this.getActualAuthCredential(issuerDID);
62111
62127
  const coreClaimOpts = {
62112
62128
  revNonce: req.revocationOpts.nonce,
62113
62129
  subjectPosition: req.subjectPosition,
@@ -62116,7 +62132,7 @@ var PolygonIdSdk = (function (exports) {
62116
62132
  version: 0,
62117
62133
  merklizeOpts: { ...opts, documentLoader: loader }
62118
62134
  };
62119
- const coreClaim = await Parser.parseClaim(credential, coreClaimOpts);
62135
+ const coreClaim = await credential.toCoreClaim(coreClaimOpts);
62120
62136
  const { hi, hv } = coreClaim.hiHv();
62121
62137
  const coreClaimHash = $$2.hash([hi, hv]);
62122
62138
  const signature = await this.signChallenge(coreClaimHash, issuerAuthBJJCredential);
@@ -62141,6 +62157,25 @@ var PolygonIdSdk = (function (exports) {
62141
62157
  credential.proof = [sigProof];
62142
62158
  return credential;
62143
62159
  }
62160
+ /** {@inheritDoc IIdentityWallet.getActualAuthCredential} */
62161
+ async getActualAuthCredential(did, treeStateInfo) {
62162
+ const authCredentials = await this._credentialWallet.getAllAuthBJJCredentials(did);
62163
+ for (let i = 0; i < authCredentials.length; i++) {
62164
+ const incProof = await this.generateCredentialMtp(did, authCredentials[i], treeStateInfo);
62165
+ if (!incProof.proof.existence) {
62166
+ continue;
62167
+ }
62168
+ const nonRevProof = await this.generateNonRevocationMtp(did, authCredentials[i], treeStateInfo);
62169
+ if (!nonRevProof.proof.existence) {
62170
+ return {
62171
+ authCredential: authCredentials[i],
62172
+ incProof,
62173
+ nonRevProof
62174
+ };
62175
+ }
62176
+ }
62177
+ throw new Error('no auth credentials found');
62178
+ }
62144
62179
  /** {@inheritDoc IIdentityWallet.revokeCredential} */
62145
62180
  async revokeCredential(issuerDID, credential) {
62146
62181
  const issuerTree = await this.getDIDTreeModel(issuerDID);
@@ -83816,8 +83851,8 @@ var PolygonIdSdk = (function (exports) {
83816
83851
  circuitInputs.proofType = proofType;
83817
83852
  circuitInputs.linkNonce = params.linkNonce ?? BigInt(0);
83818
83853
  circuitInputs.verifierID = params.verifierDid ? W$2.idFromDID(params.verifierDid) : undefined;
83819
- circuitInputs.nullifierSessionID = proofReq.params?.nullifierSessionID
83820
- ? BigInt(proofReq.params?.nullifierSessionID?.toString())
83854
+ circuitInputs.nullifierSessionID = proofReq.params?.nullifierSessionId
83855
+ ? BigInt(proofReq.params?.nullifierSessionId?.toString())
83821
83856
  : BigInt(0);
83822
83857
  let isEthIdentity = true;
83823
83858
  try {
@@ -83926,9 +83961,7 @@ var PolygonIdSdk = (function (exports) {
83926
83961
  return circuitClaim;
83927
83962
  }
83928
83963
  async prepareAuthBJJCredential(did, treeStateInfo) {
83929
- const authCredential = await this._credentialWallet.getAuthBJJCredential(did);
83930
- const incProof = await this._identityWallet.generateCredentialMtp(did, authCredential, treeStateInfo);
83931
- const nonRevProof = await this._identityWallet.generateNonRevocationMtp(did, authCredential, treeStateInfo);
83964
+ const { authCredential, incProof, nonRevProof } = await this._identityWallet.getActualAuthCredential(did, treeStateInfo);
83932
83965
  const authCoreClaim = authCredential.getCoreClaimFromProof(exports.ProofType.Iden3SparseMerkleTreeProof);
83933
83966
  if (!authCoreClaim) {
83934
83967
  throw new Error('auth core claim is not defined for auth bjj credential');
@@ -85367,6 +85400,7 @@ var PolygonIdSdk = (function (exports) {
85367
85400
  if (message.type !== PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_REQUEST_MESSAGE_TYPE) {
85368
85401
  throw new Error('Invalid media type');
85369
85402
  }
85403
+ authRequest.body.scope = authRequest.body.scope || [];
85370
85404
  return authRequest;
85371
85405
  }
85372
85406
  /**
@@ -85478,7 +85512,8 @@ var PolygonIdSdk = (function (exports) {
85478
85512
  throw new Error(`sender of the request is not a target of response - expected ${request.from}, given ${response.to}`);
85479
85513
  }
85480
85514
  this.verifyAuthRequest(request);
85481
- const requestScope = request.body.scope;
85515
+ const requestScope = request.body.scope || [];
85516
+ const responseScope = response.body.scope || [];
85482
85517
  if (!response.from) {
85483
85518
  throw new Error(`proof response doesn't contain from field`);
85484
85519
  }
@@ -85486,7 +85521,7 @@ var PolygonIdSdk = (function (exports) {
85486
85521
  // group requests by query group id
85487
85522
  for (const proofRequest of requestScope) {
85488
85523
  const groupId = proofRequest.query.groupId;
85489
- const proofResp = response.body.scope.find((resp) => resp.id === proofRequest.id);
85524
+ const proofResp = responseScope.find((resp) => resp.id === proofRequest.id);
85490
85525
  if (!proofResp) {
85491
85526
  throw new Error(`proof is not given for requestId ${proofRequest.id}`);
85492
85527
  }
@@ -85522,7 +85557,7 @@ var PolygonIdSdk = (function (exports) {
85522
85557
  }
85523
85558
  verifyAuthRequest(request) {
85524
85559
  const groupIdValidationMap = {};
85525
- const requestScope = request.body.scope;
85560
+ const requestScope = request.body.scope || [];
85526
85561
  for (const proofRequest of requestScope) {
85527
85562
  const groupId = proofRequest.query.groupId;
85528
85563
  if (groupId) {
@@ -85740,6 +85775,7 @@ var PolygonIdSdk = (function (exports) {
85740
85775
  if (message.type !== PROTOCOL_MESSAGE_TYPE.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE) {
85741
85776
  throw new Error('Invalid media type');
85742
85777
  }
85778
+ ciRequest.body.scope = ciRequest.body.scope || [];
85743
85779
  return ciRequest;
85744
85780
  }
85745
85781
  /**