@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.
@@ -61443,6 +61443,16 @@ class CredentialWallet {
61443
61443
  }
61444
61444
  throw new Error('all auth bjj credentials are revoked');
61445
61445
  }
61446
+ /**
61447
+ * {@inheritDoc ICredentialWallet.getAllAuthBJJCredentials}
61448
+ */
61449
+ async getAllAuthBJJCredentials(did) {
61450
+ return this._storage.credential.findCredentialsByQuery({
61451
+ context: VerifiableConstants.AUTH.AUTH_BJJ_CREDENTIAL_SCHEMA_JSONLD_URL,
61452
+ type: VerifiableConstants.AUTH.AUTH_BJJ_CREDENTIAL_TYPE,
61453
+ allowedIssuers: [did.string()]
61454
+ });
61455
+ }
61446
61456
  /**
61447
61457
  * {@inheritDoc ICredentialWallet.getRevocationStatusFromCredential}
61448
61458
  */
@@ -61724,13 +61734,19 @@ class IdentityWallet {
61724
61734
  this._storage = _storage;
61725
61735
  this._credentialWallet = _credentialWallet;
61726
61736
  this._opts = _opts;
61737
+ this._credentialStatusPublisherRegistry = this.getCredentialStatusPublisherRegistry(_opts);
61738
+ }
61739
+ getCredentialStatusPublisherRegistry(_opts) {
61727
61740
  if (!_opts?.credentialStatusPublisherRegistry) {
61728
- this._credentialStatusPublisherRegistry = new CredentialStatusPublisherRegistry();
61729
- this._credentialStatusPublisherRegistry.register(CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, new Iden3SmtRhsCredentialStatusPublisher());
61741
+ const registry = new CredentialStatusPublisherRegistry();
61742
+ const emptyPublisher = { publish: () => Promise.resolve() };
61743
+ registry.register(CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, new Iden3SmtRhsCredentialStatusPublisher());
61744
+ registry.register(CredentialStatusType.SparseMerkleTreeProof, emptyPublisher);
61745
+ registry.register(CredentialStatusType.Iden3commRevocationStatusV1, emptyPublisher);
61746
+ return registry;
61730
61747
  }
61731
61748
  else {
61732
- this._credentialStatusPublisherRegistry = this._opts
61733
- ?.credentialStatusPublisherRegistry;
61749
+ return this._opts?.credentialStatusPublisherRegistry;
61734
61750
  }
61735
61751
  }
61736
61752
  /**
@@ -61968,7 +61984,7 @@ class IdentityWallet {
61968
61984
  catch (e) {
61969
61985
  throw new Error(`Error create w3c credential ${e.message}`);
61970
61986
  }
61971
- const issuerAuthBJJCredential = await this._credentialWallet.getAuthBJJCredential(issuerDID);
61987
+ const { authCredential: issuerAuthBJJCredential } = await this.getActualAuthCredential(issuerDID);
61972
61988
  const coreClaimOpts = {
61973
61989
  revNonce: req.revocationOpts.nonce,
61974
61990
  subjectPosition: req.subjectPosition,
@@ -61977,7 +61993,7 @@ class IdentityWallet {
61977
61993
  version: 0,
61978
61994
  merklizeOpts: { ...opts, documentLoader: loader }
61979
61995
  };
61980
- const coreClaim = await Parser.parseClaim(credential, coreClaimOpts);
61996
+ const coreClaim = await credential.toCoreClaim(coreClaimOpts);
61981
61997
  const { hi, hv } = coreClaim.hiHv();
61982
61998
  const coreClaimHash = poseidon.hash([hi, hv]);
61983
61999
  const signature = await this.signChallenge(coreClaimHash, issuerAuthBJJCredential);
@@ -62002,6 +62018,25 @@ class IdentityWallet {
62002
62018
  credential.proof = [sigProof];
62003
62019
  return credential;
62004
62020
  }
62021
+ /** {@inheritDoc IIdentityWallet.getActualAuthCredential} */
62022
+ async getActualAuthCredential(did, treeStateInfo) {
62023
+ const authCredentials = await this._credentialWallet.getAllAuthBJJCredentials(did);
62024
+ for (let i = 0; i < authCredentials.length; i++) {
62025
+ const incProof = await this.generateCredentialMtp(did, authCredentials[i], treeStateInfo);
62026
+ if (!incProof.proof.existence) {
62027
+ continue;
62028
+ }
62029
+ const nonRevProof = await this.generateNonRevocationMtp(did, authCredentials[i], treeStateInfo);
62030
+ if (!nonRevProof.proof.existence) {
62031
+ return {
62032
+ authCredential: authCredentials[i],
62033
+ incProof,
62034
+ nonRevProof
62035
+ };
62036
+ }
62037
+ }
62038
+ throw new Error('no auth credentials found');
62039
+ }
62005
62040
  /** {@inheritDoc IIdentityWallet.revokeCredential} */
62006
62041
  async revokeCredential(issuerDID, credential) {
62007
62042
  const issuerTree = await this.getDIDTreeModel(issuerDID);
@@ -62914,8 +62949,8 @@ class InputGenerator {
62914
62949
  circuitInputs.proofType = proofType;
62915
62950
  circuitInputs.linkNonce = params.linkNonce ?? BigInt(0);
62916
62951
  circuitInputs.verifierID = params.verifierDid ? DID.idFromDID(params.verifierDid) : undefined;
62917
- circuitInputs.nullifierSessionID = proofReq.params?.nullifierSessionID
62918
- ? BigInt(proofReq.params?.nullifierSessionID?.toString())
62952
+ circuitInputs.nullifierSessionID = proofReq.params?.nullifierSessionId
62953
+ ? BigInt(proofReq.params?.nullifierSessionId?.toString())
62919
62954
  : BigInt(0);
62920
62955
  let isEthIdentity = true;
62921
62956
  try {
@@ -63024,9 +63059,7 @@ class InputGenerator {
63024
63059
  return circuitClaim;
63025
63060
  }
63026
63061
  async prepareAuthBJJCredential(did, treeStateInfo) {
63027
- const authCredential = await this._credentialWallet.getAuthBJJCredential(did);
63028
- const incProof = await this._identityWallet.generateCredentialMtp(did, authCredential, treeStateInfo);
63029
- const nonRevProof = await this._identityWallet.generateNonRevocationMtp(did, authCredential, treeStateInfo);
63062
+ const { authCredential, incProof, nonRevProof } = await this._identityWallet.getActualAuthCredential(did, treeStateInfo);
63030
63063
  const authCoreClaim = authCredential.getCoreClaimFromProof(ProofType.Iden3SparseMerkleTreeProof);
63031
63064
  if (!authCoreClaim) {
63032
63065
  throw new Error('auth core claim is not defined for auth bjj credential');
@@ -64463,6 +64496,7 @@ class AuthHandler {
64463
64496
  if (message.type !== PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_REQUEST_MESSAGE_TYPE) {
64464
64497
  throw new Error('Invalid media type');
64465
64498
  }
64499
+ authRequest.body.scope = authRequest.body.scope || [];
64466
64500
  return authRequest;
64467
64501
  }
64468
64502
  /**
@@ -64574,7 +64608,8 @@ class AuthHandler {
64574
64608
  throw new Error(`sender of the request is not a target of response - expected ${request.from}, given ${response.to}`);
64575
64609
  }
64576
64610
  this.verifyAuthRequest(request);
64577
- const requestScope = request.body.scope;
64611
+ const requestScope = request.body.scope || [];
64612
+ const responseScope = response.body.scope || [];
64578
64613
  if (!response.from) {
64579
64614
  throw new Error(`proof response doesn't contain from field`);
64580
64615
  }
@@ -64582,7 +64617,7 @@ class AuthHandler {
64582
64617
  // group requests by query group id
64583
64618
  for (const proofRequest of requestScope) {
64584
64619
  const groupId = proofRequest.query.groupId;
64585
- const proofResp = response.body.scope.find((resp) => resp.id === proofRequest.id);
64620
+ const proofResp = responseScope.find((resp) => resp.id === proofRequest.id);
64586
64621
  if (!proofResp) {
64587
64622
  throw new Error(`proof is not given for requestId ${proofRequest.id}`);
64588
64623
  }
@@ -64618,7 +64653,7 @@ class AuthHandler {
64618
64653
  }
64619
64654
  verifyAuthRequest(request) {
64620
64655
  const groupIdValidationMap = {};
64621
- const requestScope = request.body.scope;
64656
+ const requestScope = request.body.scope || [];
64622
64657
  for (const proofRequest of requestScope) {
64623
64658
  const groupId = proofRequest.query.groupId;
64624
64659
  if (groupId) {
@@ -64836,6 +64871,7 @@ class ContractRequestHandler {
64836
64871
  if (message.type !== PROTOCOL_MESSAGE_TYPE.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE) {
64837
64872
  throw new Error('Invalid media type');
64838
64873
  }
64874
+ ciRequest.body.scope = ciRequest.body.scope || [];
64839
64875
  return ciRequest;
64840
64876
  }
64841
64877
  /**