@0xpolygonid/js-sdk 1.8.0 → 1.8.2

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.
@@ -57076,7 +57076,10 @@ class AtomicQueryV3OnChainInputs extends BaseConfig {
57076
57076
  valueProof.value = 0n;
57077
57077
  valueProof.mtp = new Proof();
57078
57078
  }
57079
- const treeState = this.claim.nonRevProof.treeState;
57079
+ let treeState = this.claim.nonRevProof.treeState;
57080
+ if (this.proofType === ProofType.BJJSignature && this.skipClaimRevocationCheck) {
57081
+ treeState = this.claim.signatureProof?.issuerAuthNonRevProof.treeState;
57082
+ }
57080
57083
  if (!treeState) {
57081
57084
  throw new Error(CircuitError.EmptyTreeState);
57082
57085
  }
@@ -57132,27 +57135,32 @@ class AtomicQueryV3OnChainInputs extends BaseConfig {
57132
57135
  s.isRevocationChecked = 0;
57133
57136
  }
57134
57137
  if (this.proofType === ProofType.BJJSignature) {
57138
+ const sigProof = this.claim.signatureProof;
57135
57139
  s.proofType = '1';
57136
- s.issuerClaimSignatureR8x = this.claim.signatureProof?.signature.R8[0].toString();
57137
- s.issuerClaimSignatureR8y = this.claim.signatureProof?.signature.R8[1].toString();
57138
- s.issuerClaimSignatureS = this.claim.signatureProof?.signature.S.toString();
57139
- s.issuerAuthClaim = this.claim.signatureProof?.issuerAuthClaim?.marshalJson();
57140
- s.issuerAuthClaimMtp = prepareSiblingsStr(this.claim.signatureProof?.issuerAuthIncProof.proof, this.getMTLevel());
57140
+ s.issuerClaimSignatureR8x = sigProof.signature.R8[0].toString();
57141
+ s.issuerClaimSignatureR8y = sigProof.signature.R8[1].toString();
57142
+ s.issuerClaimSignatureS = sigProof.signature.S.toString();
57143
+ s.issuerAuthClaim = sigProof.issuerAuthClaim?.marshalJson();
57144
+ s.issuerAuthClaimMtp = prepareSiblingsStr(sigProof.issuerAuthIncProof.proof, this.getMTLevel());
57141
57145
  const issuerAuthTreeState = this.claim.nonRevProof.treeState;
57142
57146
  if (!issuerAuthTreeState) {
57143
57147
  throw new Error(CircuitError.EmptyTreeState);
57144
57148
  }
57145
- s.issuerAuthClaimsTreeRoot = issuerAuthTreeState.claimsRoot.bigInt().toString();
57146
- s.issuerAuthRevTreeRoot = issuerAuthTreeState.revocationRoot.bigInt().toString();
57147
- s.issuerAuthRootsTreeRoot = issuerAuthTreeState.rootOfRoots.bigInt().toString();
57148
- s.issuerAuthClaimNonRevMtp = prepareSiblingsStr(this.claim.signatureProof?.issuerAuthNonRevProof.proof, this.getMTLevel());
57149
- const nodeAuxIssuerAuthNonRev = getNodeAuxValue(this.claim.signatureProof?.issuerAuthNonRevProof.proof);
57149
+ s.issuerAuthClaimsTreeRoot = sigProof.issuerAuthIncProof.treeState?.claimsRoot
57150
+ .bigInt()
57151
+ .toString();
57152
+ s.issuerAuthRevTreeRoot = sigProof.issuerAuthIncProof.treeState?.revocationRoot
57153
+ .bigInt()
57154
+ .toString();
57155
+ s.issuerAuthRootsTreeRoot = sigProof.issuerAuthIncProof.treeState?.rootOfRoots
57156
+ .bigInt()
57157
+ .toString();
57158
+ s.issuerAuthClaimNonRevMtp = prepareSiblingsStr(sigProof.issuerAuthNonRevProof.proof, this.getMTLevel());
57159
+ const nodeAuxIssuerAuthNonRev = getNodeAuxValue(sigProof.issuerAuthNonRevProof.proof);
57150
57160
  s.issuerAuthClaimNonRevMtpAuxHi = nodeAuxIssuerAuthNonRev.key.bigInt().toString();
57151
57161
  s.issuerAuthClaimNonRevMtpAuxHv = nodeAuxIssuerAuthNonRev.value.bigInt().toString();
57152
57162
  s.issuerAuthClaimNonRevMtpNoAux = nodeAuxIssuerAuthNonRev.noAux;
57153
- s.issuerAuthState = this.claim.signatureProof?.issuerAuthIncProof.treeState?.state
57154
- .bigInt()
57155
- .toString();
57163
+ s.issuerAuthState = sigProof.issuerAuthIncProof.treeState?.state.bigInt().toString();
57156
57164
  this.fillMTPProofsWithZero(s);
57157
57165
  }
57158
57166
  else if (this.proofType === ProofType.Iden3SparseMerkleTreeProof) {
@@ -61435,6 +61443,16 @@ class CredentialWallet {
61435
61443
  }
61436
61444
  throw new Error('all auth bjj credentials are revoked');
61437
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
+ }
61438
61456
  /**
61439
61457
  * {@inheritDoc ICredentialWallet.getRevocationStatusFromCredential}
61440
61458
  */
@@ -61716,13 +61734,19 @@ class IdentityWallet {
61716
61734
  this._storage = _storage;
61717
61735
  this._credentialWallet = _credentialWallet;
61718
61736
  this._opts = _opts;
61737
+ this._credentialStatusPublisherRegistry = this.getCredentialStatusPublisherRegistry(_opts);
61738
+ }
61739
+ getCredentialStatusPublisherRegistry(_opts) {
61719
61740
  if (!_opts?.credentialStatusPublisherRegistry) {
61720
- this._credentialStatusPublisherRegistry = new CredentialStatusPublisherRegistry();
61721
- 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;
61722
61747
  }
61723
61748
  else {
61724
- this._credentialStatusPublisherRegistry = this._opts
61725
- ?.credentialStatusPublisherRegistry;
61749
+ return this._opts?.credentialStatusPublisherRegistry;
61726
61750
  }
61727
61751
  }
61728
61752
  /**
@@ -61960,7 +61984,7 @@ class IdentityWallet {
61960
61984
  catch (e) {
61961
61985
  throw new Error(`Error create w3c credential ${e.message}`);
61962
61986
  }
61963
- const issuerAuthBJJCredential = await this._credentialWallet.getAuthBJJCredential(issuerDID);
61987
+ const { authCredential: issuerAuthBJJCredential } = await this.getActualAuthCredential(issuerDID);
61964
61988
  const coreClaimOpts = {
61965
61989
  revNonce: req.revocationOpts.nonce,
61966
61990
  subjectPosition: req.subjectPosition,
@@ -61969,7 +61993,7 @@ class IdentityWallet {
61969
61993
  version: 0,
61970
61994
  merklizeOpts: { ...opts, documentLoader: loader }
61971
61995
  };
61972
- const coreClaim = await Parser.parseClaim(credential, coreClaimOpts);
61996
+ const coreClaim = await credential.toCoreClaim(coreClaimOpts);
61973
61997
  const { hi, hv } = coreClaim.hiHv();
61974
61998
  const coreClaimHash = poseidon.hash([hi, hv]);
61975
61999
  const signature = await this.signChallenge(coreClaimHash, issuerAuthBJJCredential);
@@ -61994,6 +62018,25 @@ class IdentityWallet {
61994
62018
  credential.proof = [sigProof];
61995
62019
  return credential;
61996
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
+ }
61997
62040
  /** {@inheritDoc IIdentityWallet.revokeCredential} */
61998
62041
  async revokeCredential(issuerDID, credential) {
61999
62042
  const issuerTree = await this.getDIDTreeModel(issuerDID);
@@ -62906,8 +62949,8 @@ class InputGenerator {
62906
62949
  circuitInputs.proofType = proofType;
62907
62950
  circuitInputs.linkNonce = params.linkNonce ?? BigInt(0);
62908
62951
  circuitInputs.verifierID = params.verifierDid ? DID.idFromDID(params.verifierDid) : undefined;
62909
- circuitInputs.nullifierSessionID = proofReq.params?.nullifierSessionID
62910
- ? BigInt(proofReq.params?.nullifierSessionID?.toString())
62952
+ circuitInputs.nullifierSessionID = proofReq.params?.nullifierSessionId
62953
+ ? BigInt(proofReq.params?.nullifierSessionId?.toString())
62911
62954
  : BigInt(0);
62912
62955
  let isEthIdentity = true;
62913
62956
  try {
@@ -63016,9 +63059,7 @@ class InputGenerator {
63016
63059
  return circuitClaim;
63017
63060
  }
63018
63061
  async prepareAuthBJJCredential(did, treeStateInfo) {
63019
- const authCredential = await this._credentialWallet.getAuthBJJCredential(did);
63020
- const incProof = await this._identityWallet.generateCredentialMtp(did, authCredential, treeStateInfo);
63021
- const nonRevProof = await this._identityWallet.generateNonRevocationMtp(did, authCredential, treeStateInfo);
63062
+ const { authCredential, incProof, nonRevProof } = await this._identityWallet.getActualAuthCredential(did, treeStateInfo);
63022
63063
  const authCoreClaim = authCredential.getCoreClaimFromProof(ProofType.Iden3SparseMerkleTreeProof);
63023
63064
  if (!authCoreClaim) {
63024
63065
  throw new Error('auth core claim is not defined for auth bjj credential');