@0xpolygonid/js-sdk 1.8.3 → 1.9.1

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.
Files changed (70) hide show
  1. package/dist/browser/esm/index.js +420 -189
  2. package/dist/browser/esm/index.js.map +1 -1
  3. package/dist/browser/umd/index.js +425 -189
  4. package/dist/browser/umd/index.js.map +1 -1
  5. package/dist/node/cjs/circuits/atomic-query-v3-on-chain.js +8 -25
  6. package/dist/node/cjs/circuits/atomic-query-v3.js +6 -5
  7. package/dist/node/cjs/circuits/common.js +1 -1
  8. package/dist/node/cjs/circuits/comparer.js +24 -3
  9. package/dist/node/cjs/circuits/linked-multi-query.js +6 -17
  10. package/dist/node/cjs/circuits/models.js +47 -3
  11. package/dist/node/cjs/iden3comm/handlers/auth.js +14 -55
  12. package/dist/node/cjs/iden3comm/handlers/common.js +85 -0
  13. package/dist/node/cjs/iden3comm/handlers/contract-request.js +6 -25
  14. package/dist/node/cjs/iden3comm/handlers/index.js +2 -0
  15. package/dist/node/cjs/iden3comm/handlers/revocation-status.js +119 -0
  16. package/dist/node/cjs/identity/identity-wallet.js +4 -0
  17. package/dist/node/cjs/proof/common.js +11 -5
  18. package/dist/node/cjs/proof/provers/inputs-generator.js +6 -10
  19. package/dist/node/cjs/proof/verifiers/index.js +1 -0
  20. package/dist/node/cjs/proof/verifiers/pub-signals-verifier.js +37 -22
  21. package/dist/node/cjs/proof/verifiers/query-hash.js +40 -0
  22. package/dist/node/cjs/proof/verifiers/query.js +24 -16
  23. package/dist/node/cjs/schema-processor/utils.js +2 -2
  24. package/dist/node/cjs/storage/filters/jsonQuery.js +28 -2
  25. package/dist/node/cjs/verifiable/core-utils.js +3 -3
  26. package/dist/node/cjs/verifiable/credential.js +1 -1
  27. package/dist/node/esm/circuits/atomic-query-v3-on-chain.js +9 -26
  28. package/dist/node/esm/circuits/atomic-query-v3.js +7 -6
  29. package/dist/node/esm/circuits/common.js +1 -1
  30. package/dist/node/esm/circuits/comparer.js +24 -3
  31. package/dist/node/esm/circuits/linked-multi-query.js +7 -18
  32. package/dist/node/esm/circuits/models.js +48 -4
  33. package/dist/node/esm/iden3comm/handlers/auth.js +15 -56
  34. package/dist/node/esm/iden3comm/handlers/common.js +81 -0
  35. package/dist/node/esm/iden3comm/handlers/contract-request.js +7 -26
  36. package/dist/node/esm/iden3comm/handlers/index.js +2 -0
  37. package/dist/node/esm/iden3comm/handlers/revocation-status.js +92 -0
  38. package/dist/node/esm/identity/identity-wallet.js +4 -0
  39. package/dist/node/esm/proof/common.js +12 -6
  40. package/dist/node/esm/proof/provers/inputs-generator.js +7 -11
  41. package/dist/node/esm/proof/verifiers/index.js +1 -0
  42. package/dist/node/esm/proof/verifiers/pub-signals-verifier.js +41 -26
  43. package/dist/node/esm/proof/verifiers/query-hash.js +35 -0
  44. package/dist/node/esm/proof/verifiers/query.js +23 -16
  45. package/dist/node/esm/schema-processor/utils.js +3 -3
  46. package/dist/node/esm/storage/filters/jsonQuery.js +28 -2
  47. package/dist/node/esm/verifiable/core-utils.js +1 -1
  48. package/dist/node/esm/verifiable/credential.js +2 -2
  49. package/dist/types/circuits/atomic-query-v3-on-chain.d.ts +4 -8
  50. package/dist/types/circuits/atomic-query-v3.d.ts +2 -2
  51. package/dist/types/circuits/common.d.ts +1 -1
  52. package/dist/types/circuits/comparer.d.ts +4 -0
  53. package/dist/types/circuits/linked-multi-query.d.ts +0 -1
  54. package/dist/types/circuits/models.d.ts +7 -4
  55. package/dist/types/iden3comm/handlers/auth.d.ts +1 -0
  56. package/dist/types/iden3comm/handlers/common.d.ts +23 -0
  57. package/dist/types/iden3comm/handlers/contract-request.d.ts +1 -1
  58. package/dist/types/iden3comm/handlers/index.d.ts +2 -0
  59. package/dist/types/iden3comm/handlers/revocation-status.d.ts +59 -0
  60. package/dist/types/iden3comm/types/protocol/contract-request.d.ts +1 -0
  61. package/dist/types/identity/identity-wallet.d.ts +13 -1
  62. package/dist/types/proof/verifiers/index.d.ts +1 -0
  63. package/dist/types/proof/verifiers/query-hash.d.ts +3 -0
  64. package/dist/types/proof/verifiers/query.d.ts +1 -0
  65. package/dist/types/schema-processor/utils.d.ts +1 -1
  66. package/dist/types/storage/filters/jsonQuery.d.ts +1 -1
  67. package/dist/types/verifiable/core-utils.d.ts +1 -1
  68. package/dist/types/verifiable/credential.d.ts +1 -1
  69. package/dist/types/verifiable/proof.d.ts +5 -1
  70. package/package.json +1 -1
@@ -27439,7 +27439,7 @@ var PolygonIdSdk = (function (exports) {
27439
27439
  * @param {Uint8Array} schemaId
27440
27440
  * @returns {*} {SchemaHash}
27441
27441
  */
27442
- const caclulateCoreSchemaHash = (schemaId) => {
27442
+ const calculateCoreSchemaHash = (schemaId) => {
27443
27443
  const sHash = b$5.decodeString(sha3Exports.keccak256(schemaId));
27444
27444
  return new B$3(sHash.slice(sHash.length - 16, sHash.length));
27445
27445
  };
@@ -27554,7 +27554,7 @@ var PolygonIdSdk = (function (exports) {
27554
27554
  if (!nonMerklized && opts.merklizedRootPosition === exports.MerklizedRootPosition.None) {
27555
27555
  opts.merklizedRootPosition = exports.MerklizedRootPosition.Index;
27556
27556
  }
27557
- const schemaHash = caclulateCoreSchemaHash(byteEncoder.encode(credentialType));
27557
+ const schemaHash = calculateCoreSchemaHash(byteEncoder.encode(credentialType));
27558
27558
  const claim = v$3.newClaim(schemaHash, C$3.withIndexDataBytes(slots.indexA, slots.indexB), C$3.withValueDataBytes(slots.valueA, slots.valueB), C$3.withRevocationNonce(BigInt(opts.revNonce)), C$3.withVersion(opts.version));
27559
27559
  if (opts.updatable) {
27560
27560
  claim.setFlagUpdatable(opts.updatable);
@@ -28486,14 +28486,14 @@ var PolygonIdSdk = (function (exports) {
28486
28486
  }
28487
28487
  /**
28488
28488
  *
28489
- * @deprecated The method should not be used. Use caclulateCoreSchemaHash from verifiable.
28489
+ * @deprecated The method should not be used. Use calculateCoreSchemaHash from verifiable.
28490
28490
  * Calculates schema hash
28491
28491
  *
28492
28492
  * @param {Uint8Array} schemaId
28493
28493
  * @returns {*} {SchemaHash}
28494
28494
  */
28495
28495
  const createSchemaHash = (schemaId) => {
28496
- return caclulateCoreSchemaHash(schemaId);
28496
+ return calculateCoreSchemaHash(schemaId);
28497
28497
  };
28498
28498
  /**
28499
28499
  *
@@ -55824,7 +55824,7 @@ var PolygonIdSdk = (function (exports) {
55824
55824
  * @returns number
55825
55825
  */
55826
55826
  getValueArrSize() {
55827
- return this.valueArraySize ? this.valueArraySize : defaultValueArraySize;
55827
+ return this.maxValueArraySize ? this.maxValueArraySize : defaultValueArraySize;
55828
55828
  }
55829
55829
  /**
55830
55830
  * getMTLevelOnChain return level on chain for given circuit
@@ -55992,6 +55992,8 @@ var PolygonIdSdk = (function (exports) {
55992
55992
  Operators[Operators["LTE"] = 7] = "LTE";
55993
55993
  Operators[Operators["GTE"] = 8] = "GTE";
55994
55994
  Operators[Operators["BETWEEN"] = 9] = "BETWEEN";
55995
+ Operators[Operators["NONBETWEEN"] = 10] = "NONBETWEEN";
55996
+ Operators[Operators["EXISTS"] = 11] = "EXISTS";
55995
55997
  Operators[Operators["SD"] = 16] = "SD";
55996
55998
  Operators[Operators["NULLIFY"] = 17] = "NULLIFY";
55997
55999
  })(exports.Operators || (exports.Operators = {}));
@@ -56007,12 +56009,17 @@ var PolygonIdSdk = (function (exports) {
56007
56009
  $lte: exports.Operators.LTE,
56008
56010
  $gte: exports.Operators.GTE,
56009
56011
  $between: exports.Operators.BETWEEN,
56012
+ $nonbetween: exports.Operators.NONBETWEEN,
56013
+ $exists: exports.Operators.EXISTS,
56010
56014
  $sd: exports.Operators.SD,
56011
56015
  $nullify: exports.Operators.NULLIFY
56012
56016
  };
56013
56017
  const allOperations$1 = Object.values(QueryOperators);
56014
56018
  const availableTypesOperators = new Map([
56015
- [exports.XSDNS.Boolean, [QueryOperators.$eq, QueryOperators.$ne, QueryOperators.$sd]],
56019
+ [
56020
+ exports.XSDNS.Boolean,
56021
+ [QueryOperators.$eq, QueryOperators.$ne, QueryOperators.$sd, QueryOperators.$exists]
56022
+ ],
56016
56023
  [exports.XSDNS.Integer, allOperations$1],
56017
56024
  [exports.XSDNS.NonNegativeInteger, allOperations$1],
56018
56025
  [exports.XSDNS.PositiveInteger, allOperations$1],
@@ -56023,7 +56030,8 @@ var PolygonIdSdk = (function (exports) {
56023
56030
  QueryOperators.$ne,
56024
56031
  QueryOperators.$in,
56025
56032
  QueryOperators.$nin,
56026
- QueryOperators.$sd
56033
+ QueryOperators.$sd,
56034
+ QueryOperators.$exists
56027
56035
  ]
56028
56036
  ],
56029
56037
  [
@@ -56033,7 +56041,8 @@ var PolygonIdSdk = (function (exports) {
56033
56041
  QueryOperators.$ne,
56034
56042
  QueryOperators.$in,
56035
56043
  QueryOperators.$nin,
56036
- QueryOperators.$sd
56044
+ QueryOperators.$sd,
56045
+ QueryOperators.$exists
56037
56046
  ]
56038
56047
  ],
56039
56048
  [exports.XSDNS.DateTime, allOperations$1]
@@ -56124,6 +56133,16 @@ var PolygonIdSdk = (function (exports) {
56124
56133
  return this.y.includes(this.x);
56125
56134
  case exports.Operators.NIN:
56126
56135
  return !this.y.includes(this.x);
56136
+ case exports.Operators.BETWEEN:
56137
+ if (this.y.length !== 2) {
56138
+ return false;
56139
+ }
56140
+ return this.x >= this.y[0] && this.x <= this.y[1];
56141
+ case exports.Operators.NONBETWEEN:
56142
+ if (this.y.length !== 2) {
56143
+ return false;
56144
+ }
56145
+ return this.x < this.y[0] || this.x > this.y[1];
56127
56146
  default:
56128
56147
  throw new Error('unknown compare type for vector');
56129
56148
  }
@@ -56149,6 +56168,8 @@ var PolygonIdSdk = (function (exports) {
56149
56168
  return new Scalar$1(x, y[0]);
56150
56169
  case exports.Operators.IN:
56151
56170
  case exports.Operators.NIN:
56171
+ case exports.Operators.BETWEEN:
56172
+ case exports.Operators.NONBETWEEN:
56152
56173
  return new Vector(x, y);
56153
56174
  default:
56154
56175
  throw new Error('unknown compare type');
@@ -56172,6 +56193,48 @@ var PolygonIdSdk = (function (exports) {
56172
56193
  this.values?.some((v) => typeof v !== 'bigint'))
56173
56194
  throw new Error(exports.CircuitError.EmptyQueryValue);
56174
56195
  }
56196
+ validateValueArraySize(maxArrSize) {
56197
+ switch (this.values.length) {
56198
+ case 0: {
56199
+ const zeroArrSizeOps = [exports.Operators.NOOP, exports.Operators.SD, exports.Operators.NULLIFY];
56200
+ if (!zeroArrSizeOps.includes(this.operator)) {
56201
+ throw new Error(exports.CircuitError.InvalidValuesArrSize);
56202
+ }
56203
+ return;
56204
+ }
56205
+ case 1: {
56206
+ const oneArrSizeOps = [
56207
+ exports.Operators.EQ,
56208
+ exports.Operators.LT,
56209
+ exports.Operators.GT,
56210
+ exports.Operators.NE,
56211
+ exports.Operators.LTE,
56212
+ exports.Operators.GTE,
56213
+ exports.Operators.EXISTS
56214
+ ];
56215
+ if (!oneArrSizeOps.includes(this.operator)) {
56216
+ throw new Error(exports.CircuitError.InvalidValuesArrSize);
56217
+ }
56218
+ return;
56219
+ }
56220
+ case 2: {
56221
+ const twoArrSizeOps = [exports.Operators.BETWEEN, exports.Operators.NONBETWEEN];
56222
+ if (!twoArrSizeOps.includes(this.operator)) {
56223
+ throw new Error(exports.CircuitError.InvalidValuesArrSize);
56224
+ }
56225
+ return;
56226
+ }
56227
+ default: {
56228
+ const maxArrSizeOps = [exports.Operators.IN, exports.Operators.NIN];
56229
+ if (!maxArrSizeOps.includes(this.operator)) {
56230
+ throw new Error(exports.CircuitError.InvalidOperationType);
56231
+ }
56232
+ if (!this.values.length || this.values.length > maxArrSize) {
56233
+ throw new Error(exports.CircuitError.InvalidValuesArrSize);
56234
+ }
56235
+ }
56236
+ }
56237
+ }
56175
56238
  }
56176
56239
  /**
56177
56240
  * CircuitID is alias for circuit identifier
@@ -56196,17 +56259,17 @@ var PolygonIdSdk = (function (exports) {
56196
56259
  * @beta
56197
56260
  */
56198
56261
  // AtomicQueryV3CircuitID is a type for credentialAtomicQueryV3.circom
56199
- CircuitId["AtomicQueryV3"] = "credentialAtomicQueryV3-beta.0";
56262
+ CircuitId["AtomicQueryV3"] = "credentialAtomicQueryV3-beta.1";
56200
56263
  /**
56201
56264
  * @beta
56202
56265
  */
56203
56266
  // AtomicQueryV3OnChainCircuitID is a type for credentialAtomicQueryV3OnChain.circom
56204
- CircuitId["AtomicQueryV3OnChain"] = "credentialAtomicQueryV3OnChain-beta.0";
56267
+ CircuitId["AtomicQueryV3OnChain"] = "credentialAtomicQueryV3OnChain-beta.1";
56205
56268
  /**
56206
56269
  * @beta
56207
56270
  */
56208
56271
  // LinkedMultiQuery is a type for linkedMultiQuery.circom
56209
- CircuitId["LinkedMultiQuery10"] = "linkedMultiQuery10-beta.0";
56272
+ CircuitId["LinkedMultiQuery10"] = "linkedMultiQuery10-beta.1";
56210
56273
  })(exports.CircuitId || (exports.CircuitId = {}));
56211
56274
  /**
56212
56275
  * Claim structure for circuit inputs
@@ -56243,6 +56306,8 @@ var PolygonIdSdk = (function (exports) {
56243
56306
  CircuitError["EmptyTreeState"] = "empty tree state";
56244
56307
  CircuitError["EmptyRequestID"] = "empty request ID";
56245
56308
  CircuitError["InvalidProofType"] = "invalid proof type";
56309
+ CircuitError["InvalidValuesArrSize"] = "invalid query Values array size";
56310
+ CircuitError["InvalidOperationType"] = "invalid operation type";
56246
56311
  })(exports.CircuitError || (exports.CircuitError = {}));
56247
56312
  /**
56248
56313
  * ValueProof represents a Merkle Proof for a value stored as MT
@@ -56852,6 +56917,7 @@ var PolygonIdSdk = (function (exports) {
56852
56917
  if (!this.query.values) {
56853
56918
  throw new Error(exports.CircuitError.EmptyQueryValue);
56854
56919
  }
56920
+ this.query.validateValueArraySize(this.getValueArrSize());
56855
56921
  if (!this.proofType) {
56856
56922
  throw new Error(exports.CircuitError.InvalidProofType);
56857
56923
  }
@@ -56981,12 +57047,12 @@ var PolygonIdSdk = (function (exports) {
56981
57047
  s.issuerClaimNonRevMtpAuxHi = nodeAuxNonRev.key.bigInt().toString();
56982
57048
  s.issuerClaimNonRevMtpAuxHv = nodeAuxNonRev.value.bigInt().toString();
56983
57049
  s.issuerClaimNonRevMtpNoAux = nodeAuxNonRev.noAux;
56984
- s.claimPathNotExists = existenceToInt(valueProof.mtp.existence);
56985
57050
  const nodAuxJSONLD = getNodeAuxValue(valueProof.mtp);
56986
57051
  s.claimPathMtpNoAux = nodAuxJSONLD.noAux;
56987
57052
  s.claimPathMtpAuxHi = nodAuxJSONLD.key.bigInt().toString();
56988
57053
  s.claimPathMtpAuxHv = nodAuxJSONLD.value.bigInt().toString();
56989
57054
  s.claimPathKey = valueProof.path.toString();
57055
+ s.valueArraySize = this.query.values.length;
56990
57056
  const values = prepareCircuitArrayValues(this.query.values, this.getValueArrSize());
56991
57057
  s.value = bigIntArrayToStringArray(values);
56992
57058
  s.linkNonce = this.linkNonce.toString();
@@ -57020,11 +57086,11 @@ var PolygonIdSdk = (function (exports) {
57020
57086
  // issuerClaimNonRevState
57021
57087
  // timestamp
57022
57088
  // claimSchema
57023
- // claimPathNotExists
57024
57089
  // claimPathKey
57025
57090
  // slotIndex
57026
57091
  // operator
57027
57092
  // value
57093
+ // valueArraySize
57028
57094
  // verifierID
57029
57095
  // nullifierSessionID
57030
57096
  // 19 is a number of fields in AtomicQueryV3PubSignals before values, values is last element in the proof and
@@ -57075,9 +57141,6 @@ var PolygonIdSdk = (function (exports) {
57075
57141
  // - claimSchema
57076
57142
  this.claimSchema = B$3.newSchemaHashFromInt(BigInt(sVals[fieldIdx]));
57077
57143
  fieldIdx++;
57078
- // - ClaimPathNotExists
57079
- this.claimPathNotExists = parseInt(sVals[fieldIdx]);
57080
- fieldIdx++;
57081
57144
  // - ClaimPathKey
57082
57145
  this.claimPathKey = BigInt(sVals[fieldIdx]);
57083
57146
  fieldIdx++;
@@ -57092,6 +57155,9 @@ var PolygonIdSdk = (function (exports) {
57092
57155
  this.value.push(BigInt(sVals[fieldIdx]));
57093
57156
  fieldIdx++;
57094
57157
  }
57158
+ // - valueArraySize
57159
+ this.valueArraySize = parseInt(sVals[fieldIdx]);
57160
+ fieldIdx++;
57095
57161
  // - verifierID
57096
57162
  if (sVals[fieldIdx] !== '0') {
57097
57163
  this.verifierID = k$2.fromBigInt(BigInt(sVals[fieldIdx]));
@@ -57122,13 +57188,14 @@ var PolygonIdSdk = (function (exports) {
57122
57188
  if (!this.query.values) {
57123
57189
  throw new Error(exports.CircuitError.EmptyQueryValue);
57124
57190
  }
57191
+ this.query.validateValueArraySize(this.getValueArrSize());
57125
57192
  if (!this.proofType) {
57126
57193
  throw new Error(exports.CircuitError.InvalidProofType);
57127
57194
  }
57128
57195
  if (!this.challenge) {
57129
57196
  throw new Error(exports.CircuitError.EmptyChallenge);
57130
57197
  }
57131
- if (this.authEnabled === 1) {
57198
+ if (this.isBJJAuthEnabled === 1) {
57132
57199
  if (!this.authClaimIncMtp) {
57133
57200
  throw new Error(exports.CircuitError.EmptyAuthClaimProof);
57134
57201
  }
@@ -57244,7 +57311,7 @@ var PolygonIdSdk = (function (exports) {
57244
57311
  isRevocationChecked: 1
57245
57312
  };
57246
57313
  s.challenge = this.challenge?.toString();
57247
- if (this.authEnabled === 1) {
57314
+ if (this.isBJJAuthEnabled === 1) {
57248
57315
  s.authClaim = this.authClaim?.marshalJson();
57249
57316
  s.userClaimsTreeRoot = this.treeState.claimsRoot?.bigInt().toString();
57250
57317
  s.userRevTreeRoot = this.treeState.revocationRoot?.bigInt().toString();
@@ -57319,18 +57386,18 @@ var PolygonIdSdk = (function (exports) {
57319
57386
  s.issuerClaimNonRevMtpAuxHi = nodeAuxNonRev.key.bigInt().toString();
57320
57387
  s.issuerClaimNonRevMtpAuxHv = nodeAuxNonRev.value.bigInt().toString();
57321
57388
  s.issuerClaimNonRevMtpNoAux = nodeAuxNonRev.noAux;
57322
- s.claimPathNotExists = existenceToInt(valueProof.mtp.existence);
57323
57389
  const nodAuxJSONLD = getNodeAuxValue(valueProof.mtp);
57324
57390
  s.claimPathMtpNoAux = nodAuxJSONLD.noAux;
57325
57391
  s.claimPathMtpAuxHi = nodAuxJSONLD.key.bigInt().toString();
57326
57392
  s.claimPathMtpAuxHv = nodAuxJSONLD.value.bigInt().toString();
57327
57393
  s.claimPathKey = valueProof.path.toString();
57394
+ s.valueArraySize = this.query.values.length;
57328
57395
  const values = prepareCircuitArrayValues(this.query.values, this.getValueArrSize());
57329
57396
  s.value = bigIntArrayToStringArray(values);
57330
57397
  s.linkNonce = this.linkNonce.toString();
57331
57398
  s.verifierID = this.verifierID?.bigInt().toString() ?? '0';
57332
57399
  s.nullifierSessionID = this.nullifierSessionID.toString();
57333
- s.authEnabled = this.authEnabled.toString();
57400
+ s.isBJJAuthEnabled = this.isBJJAuthEnabled.toString();
57334
57401
  return byteEncoder.encode(JSON.stringify(s));
57335
57402
  }
57336
57403
  }
@@ -57342,7 +57409,6 @@ var PolygonIdSdk = (function (exports) {
57342
57409
  // PubSignalsUnmarshal unmarshal credentialAtomicQueryV3.circom public signals
57343
57410
  pubSignalsUnmarshal(data) {
57344
57411
  // expected order:
57345
- // merklized
57346
57412
  // userID
57347
57413
  // circuitQueryHash
57348
57414
  // issuerState
@@ -57354,17 +57420,11 @@ var PolygonIdSdk = (function (exports) {
57354
57420
  // challenge
57355
57421
  // gistRoot
57356
57422
  // issuerID
57357
- // isRevocationChecked
57358
57423
  // issuerClaimNonRevState
57359
57424
  // timestamp
57360
- // verifierID
57361
- // nullifierSessionID
57362
- // authEnabled
57425
+ // isBJJAuthEnabled
57363
57426
  const sVals = JSON.parse(byteDecoder.decode(data));
57364
57427
  let fieldIdx = 0;
57365
- // -- merklized
57366
- this.merklized = parseInt(sVals[fieldIdx]);
57367
- fieldIdx++;
57368
57428
  // - userID
57369
57429
  this.userID = k$2.fromBigInt(BigInt(sVals[fieldIdx]));
57370
57430
  fieldIdx++;
@@ -57398,25 +57458,14 @@ var PolygonIdSdk = (function (exports) {
57398
57458
  // - issuerID
57399
57459
  this.issuerID = k$2.fromBigInt(BigInt(sVals[fieldIdx]));
57400
57460
  fieldIdx++;
57401
- // - isRevocationChecked
57402
- this.isRevocationChecked = parseInt(sVals[fieldIdx]);
57403
- fieldIdx++;
57404
57461
  // - issuerClaimNonRevState
57405
57462
  this.issuerClaimNonRevState = V$1.fromString(sVals[fieldIdx]);
57406
57463
  fieldIdx++;
57407
57464
  // - timestamp
57408
57465
  this.timestamp = parseInt(sVals[fieldIdx]);
57409
57466
  fieldIdx++;
57410
- // - verifierID
57411
- if (sVals[fieldIdx] !== '0') {
57412
- this.verifierID = k$2.fromBigInt(BigInt(sVals[fieldIdx]));
57413
- }
57414
- fieldIdx++;
57415
- // - nullifierSessionID
57416
- this.nullifierSessionID = BigInt(sVals[fieldIdx]);
57417
- fieldIdx++;
57418
- // - authEnabled
57419
- this.authEnabled = parseInt(sVals[fieldIdx]);
57467
+ // - isBJJAuthEnabled
57468
+ this.isBJJAuthEnabled = parseInt(sVals[fieldIdx]);
57420
57469
  return this;
57421
57470
  }
57422
57471
  }
@@ -57826,8 +57875,6 @@ var PolygonIdSdk = (function (exports) {
57826
57875
  class LinkedMultiQueryInputs extends BaseConfig {
57827
57876
  // InputsMarshal returns Circom private inputs for linkedMultiQueryInputs.circom
57828
57877
  inputsMarshal() {
57829
- const enabled = [];
57830
- const claimPathNotExists = [];
57831
57878
  const claimPathMtp = [];
57832
57879
  const claimPathMtpNoAux = [];
57833
57880
  const claimPathMtpAuxHi = [];
@@ -57837,10 +57884,9 @@ var PolygonIdSdk = (function (exports) {
57837
57884
  const slotIndex = [];
57838
57885
  const operator = [];
57839
57886
  const value = [];
57887
+ const valueArraySize = [];
57840
57888
  for (let i = 0; i < LinkedMultiQueryInputs.queryCount; i++) {
57841
57889
  if (!this.query[i]) {
57842
- enabled.push(0);
57843
- claimPathNotExists.push(0);
57844
57890
  claimPathMtp.push(new Array(this.getMTLevelsClaim()).fill('0'));
57845
57891
  claimPathMtpNoAux.push('0');
57846
57892
  claimPathMtpAuxHi.push('0');
@@ -57851,9 +57897,9 @@ var PolygonIdSdk = (function (exports) {
57851
57897
  operator.push(0);
57852
57898
  const valuesArr = prepareCircuitArrayValues([], this.getValueArrSize());
57853
57899
  value.push(bigIntArrayToStringArray(valuesArr));
57900
+ valueArraySize.push(0);
57854
57901
  continue;
57855
57902
  }
57856
- enabled.push(1);
57857
57903
  let valueProof = this.query[i].valueProof;
57858
57904
  if (!valueProof) {
57859
57905
  valueProof = new ValueProof();
@@ -57861,7 +57907,6 @@ var PolygonIdSdk = (function (exports) {
57861
57907
  valueProof.value = 0n;
57862
57908
  valueProof.mtp = new Kt$1();
57863
57909
  }
57864
- claimPathNotExists.push(existenceToInt(valueProof.mtp.existence));
57865
57910
  claimPathMtp.push(prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaim()));
57866
57911
  const nodAuxJSONLD = getNodeAuxValue(valueProof.mtp);
57867
57912
  claimPathMtpNoAux.push(nodAuxJSONLD.noAux);
@@ -57871,15 +57916,14 @@ var PolygonIdSdk = (function (exports) {
57871
57916
  claimPathValue.push(valueProof.value.toString());
57872
57917
  slotIndex.push(this.query[i].slotIndex);
57873
57918
  operator.push(this.query[i].operator);
57919
+ valueArraySize.push(this.query[i].values.length);
57874
57920
  const valuesArr = prepareCircuitArrayValues(this.query[i].values, this.getValueArrSize());
57875
57921
  value.push(bigIntArrayToStringArray(valuesArr));
57876
57922
  }
57877
57923
  const s = {
57878
57924
  linkNonce: this.linkNonce.toString(),
57879
57925
  issuerClaim: this.claim.marshalJson(),
57880
- enabled,
57881
57926
  claimSchema: this.claim.getSchemaHash().bigInt().toString(),
57882
- claimPathNotExists,
57883
57927
  claimPathMtp,
57884
57928
  claimPathMtpNoAux,
57885
57929
  claimPathMtpAuxHi,
@@ -57888,7 +57932,8 @@ var PolygonIdSdk = (function (exports) {
57888
57932
  claimPathValue,
57889
57933
  slotIndex,
57890
57934
  operator,
57891
- value
57935
+ value,
57936
+ valueArraySize
57892
57937
  };
57893
57938
  return byteEncoder.encode(JSON.stringify(s));
57894
57939
  }
@@ -57910,7 +57955,7 @@ var PolygonIdSdk = (function (exports) {
57910
57955
  * @returns LinkedMultiQueryPubSignals
57911
57956
  */
57912
57957
  pubSignalsUnmarshal(data) {
57913
- const len = 32;
57958
+ const len = 22;
57914
57959
  const queryLength = LinkedMultiQueryInputs.queryCount;
57915
57960
  const sVals = JSON.parse(byteDecoder.decode(data));
57916
57961
  if (sVals.length !== len) {
@@ -57935,13 +57980,6 @@ var PolygonIdSdk = (function (exports) {
57935
57980
  this.circuitQueryHash.push(BigInt(sVals[fieldIdx]));
57936
57981
  fieldIdx++;
57937
57982
  }
57938
- // - enabled
57939
- this.enabled = [];
57940
- for (let i = 0; i < queryLength; i++) {
57941
- const enabledNum = parseInt(sVals[fieldIdx]);
57942
- this.enabled.push(enabledNum === 1);
57943
- fieldIdx++;
57944
- }
57945
57983
  return this;
57946
57984
  }
57947
57985
  }
@@ -59974,6 +60012,19 @@ var PolygonIdSdk = (function (exports) {
59974
60012
  }
59975
60013
  return a <= b;
59976
60014
  };
60015
+ // a - field value
60016
+ // b - true / false (exists operator values)
60017
+ const existsComparator = (a, b) => {
60018
+ if (truthyValues.includes(b) && typeof a !== 'undefined') {
60019
+ // if exists val is true , a field val exists
60020
+ return true;
60021
+ }
60022
+ // if exists val is false , a field val doesn't exist
60023
+ if (falsyValues.includes(b) && (a === undefined || (Array.isArray(a) && !a.length))) {
60024
+ return true;
60025
+ }
60026
+ return false;
60027
+ };
59977
60028
  const inOperator = (a, b) => {
59978
60029
  if (Array.isArray(a) && Array.isArray(b)) {
59979
60030
  return a.every((val) => b.includes(val));
@@ -59986,9 +60037,19 @@ var PolygonIdSdk = (function (exports) {
59986
60037
  }
59987
60038
  return false;
59988
60039
  };
60040
+ const betweenOperator = (a, b) => {
60041
+ if (!Array.isArray(b) || b.length !== 2) {
60042
+ throw new Error('$between/$nonbetween operator value should be 2 elements array');
60043
+ }
60044
+ if (Array.isArray(a)) {
60045
+ return a.every((val) => val >= b[0] && val <= b[1]);
60046
+ }
60047
+ return a >= b[0] && a <= b[1];
60048
+ };
59989
60049
  const comparatorOptions = {
59990
60050
  $noop: () => true,
59991
60051
  $sd: () => true,
60052
+ $exists: (a, b) => existsComparator(a, b),
59992
60053
  $eq: (a, b) => equalsComparator(a, b),
59993
60054
  $in: (a, b) => inOperator(a, b),
59994
60055
  $nin: (a, b) => !inOperator(a, b),
@@ -59996,7 +60057,9 @@ var PolygonIdSdk = (function (exports) {
59996
60057
  $lt: (a, b) => !greaterThan(a, b),
59997
60058
  $ne: (a, b) => !equalsComparator(a, b),
59998
60059
  $gte: (a, b) => greaterThanOrEqual(a, b),
59999
- $lte: (a, b) => lessThanOrEqual(a, b)
60060
+ $lte: (a, b) => lessThanOrEqual(a, b),
60061
+ $between: (a, b) => betweenOperator(a, b),
60062
+ $nonbetween: (a, b) => !betweenOperator(a, b)
60000
60063
  };
60001
60064
  /**
60002
60065
  * credential search path resolver
@@ -60044,7 +60107,8 @@ var PolygonIdSdk = (function (exports) {
60044
60107
  throw new Error(exports.SearchError.NotDefinedComparator);
60045
60108
  }
60046
60109
  const credentialPathValue = resolvePath(credential, this.path);
60047
- if (credentialPathValue === null || credentialPathValue === undefined) {
60110
+ if ((credentialPathValue === null || credentialPathValue === undefined) &&
60111
+ this.operatorFunc !== existsComparator) {
60048
60112
  return false;
60049
60113
  }
60050
60114
  if (this.isReverseParams) {
@@ -62065,6 +62129,10 @@ var PolygonIdSdk = (function (exports) {
62065
62129
  async generateNonRevocationMtp(did, credential, treeState) {
62066
62130
  const coreClaim = await this.getCoreClaimFromCredential(credential);
62067
62131
  const revNonce = coreClaim.getRevocationNonce();
62132
+ return this.generateNonRevocationMtpWithNonce(did, revNonce, treeState);
62133
+ }
62134
+ /** {@inheritDoc IIdentityWallet.generateNonRevocationMtpWithNonce} */
62135
+ async generateNonRevocationMtpWithNonce(did, revNonce, treeState) {
62068
62136
  const treesModel = await this.getDIDTreeModel(did);
62069
62137
  const revocationTree = await this._storage.mt.getMerkleTreeByIdentifierAndType(did.string(), exports.MerkleTreeType.Revocations);
62070
62138
  const claimsRoot = await treesModel.claimsTree.root();
@@ -62429,16 +62497,21 @@ var PolygonIdSdk = (function (exports) {
62429
62497
  return queries;
62430
62498
  };
62431
62499
  const parseQueryMetadata = async (propertyQuery, ldContextJSON, credentialType, options) => {
62432
- const datatype = await lf.newTypeFromContext(ldContextJSON, `${credentialType}.${propertyQuery.fieldName}`, options);
62433
62500
  const query = {
62434
62501
  ...propertyQuery,
62435
62502
  slotIndex: 0,
62436
62503
  merklizedSchema: false,
62437
- datatype: datatype,
62504
+ datatype: '',
62438
62505
  claimPathKey: BigInt(0),
62439
62506
  values: [],
62440
62507
  path: new lf()
62441
62508
  };
62509
+ if (!propertyQuery.fieldName && propertyQuery.operator !== exports.Operators.NOOP) {
62510
+ throw new Error('query must have a field name if operator is not $noop');
62511
+ }
62512
+ if (propertyQuery.fieldName) {
62513
+ query.datatype = await lf.newTypeFromContext(ldContextJSON, `${credentialType}.${propertyQuery.fieldName}`, options);
62514
+ }
62442
62515
  const serAttr = await getSerializationAttrFromContext(JSON.parse(ldContextJSON), options, credentialType);
62443
62516
  if (!serAttr) {
62444
62517
  query.merklizedSchema = true;
@@ -62460,9 +62533,10 @@ var PolygonIdSdk = (function (exports) {
62460
62533
  }
62461
62534
  }
62462
62535
  if (propertyQuery.operatorValue) {
62463
- if (!isValidOperation(datatype, propertyQuery.operator)) {
62464
- throw new Error(`operator ${propertyQuery.operator} is not supported for datatype ${datatype}`);
62536
+ if (!isValidOperation(query.datatype, propertyQuery.operator)) {
62537
+ throw new Error(`operator ${propertyQuery.operator} is not supported for datatype ${query.datatype}`);
62465
62538
  }
62539
+ const datatype = propertyQuery.operator === exports.Operators.EXISTS ? exports.XSDNS.Boolean : query.datatype;
62466
62540
  query.values = await transformQueryValueToBigInts(propertyQuery.operatorValue, datatype);
62467
62541
  }
62468
62542
  return query;
@@ -62472,7 +62546,7 @@ var PolygonIdSdk = (function (exports) {
62472
62546
  return Promise.all(queriesMetadata.map((m) => parseQueryMetadata(m, ldContextJSON, credentialType, options)));
62473
62547
  };
62474
62548
  const transformQueryValueToBigInts = async (value, ldType) => {
62475
- const values = new Array(64).fill(BigInt(0));
62549
+ const values = [];
62476
62550
  if (Array.isArray(value)) {
62477
62551
  for (let index = 0; index < value.length; index++) {
62478
62552
  values[index] = await ff.hashValue(ldType, value[index]);
@@ -83791,10 +83865,8 @@ var PolygonIdSdk = (function (exports) {
83791
83865
  circuitInputs.profileNonce = BigInt(params.authProfileNonce);
83792
83866
  circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
83793
83867
  const query = circuitQueries[0];
83794
- query.values =
83795
- query.operator === exports.Operators.SD || query.operator === exports.Operators.NOOP
83796
- ? new Array(defaultValueArraySize).fill(0)
83797
- : query.values;
83868
+ query.values = [exports.Operators.SD, exports.Operators.NOOP].includes(query.operator) ? [] : query.values;
83869
+ query.valueProof = query.operator === exports.Operators.NOOP ? new ValueProof() : query.valueProof;
83798
83870
  circuitInputs.query = query;
83799
83871
  circuitInputs.currentTimeStamp = S$3(new Date());
83800
83872
  circuitInputs.proofType = proofType;
@@ -83842,10 +83914,8 @@ var PolygonIdSdk = (function (exports) {
83842
83914
  circuitInputs.profileNonce = BigInt(params.authProfileNonce);
83843
83915
  circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
83844
83916
  const query = circuitQueries[0];
83845
- query.values =
83846
- query.operator === exports.Operators.SD || query.operator === exports.Operators.NOOP
83847
- ? new Array(defaultValueArraySize).fill(0)
83848
- : query.values;
83917
+ query.values = [exports.Operators.SD, exports.Operators.NOOP].includes(query.operator) ? [] : query.values;
83918
+ query.valueProof = query.operator === exports.Operators.NOOP ? new ValueProof() : query.valueProof;
83849
83919
  circuitInputs.query = query;
83850
83920
  circuitInputs.currentTimeStamp = S$3(new Date());
83851
83921
  circuitInputs.proofType = proofType;
@@ -83861,7 +83931,7 @@ var PolygonIdSdk = (function (exports) {
83861
83931
  catch {
83862
83932
  isEthIdentity = false;
83863
83933
  }
83864
- circuitInputs.authEnabled = isEthIdentity ? 0 : 1;
83934
+ circuitInputs.isBJJAuthEnabled = isEthIdentity ? 0 : 1;
83865
83935
  circuitInputs.challenge = BigInt(params.challenge ?? 0);
83866
83936
  const { nonce: authProfileNonce, genesisDID } = await this._identityWallet.getGenesisDIDMetadata(identifier);
83867
83937
  const id = W$2.idFromDID(genesisDID);
@@ -83869,7 +83939,7 @@ var PolygonIdSdk = (function (exports) {
83869
83939
  const gistProof = toGISTProof(stateProof);
83870
83940
  circuitInputs.gistProof = gistProof;
83871
83941
  // auth inputs
83872
- if (circuitInputs.authEnabled === 1) {
83942
+ if (circuitInputs.isBJJAuthEnabled === 1) {
83873
83943
  const authPrepared = await this.prepareAuthBJJCredential(genesisDID);
83874
83944
  const authClaimData = await this.newCircuitClaimData({
83875
83945
  credential: authPrepared.credential,
@@ -84002,7 +84072,7 @@ var PolygonIdSdk = (function (exports) {
84002
84072
  const schemaId = await lf.getTypeIDFromContext(JSON.stringify(schema), query.type, {
84003
84073
  documentLoader: schemaLoader
84004
84074
  });
84005
- const schemaHash = caclulateCoreSchemaHash(byteEncoder.encode(schemaId));
84075
+ const schemaHash = calculateCoreSchemaHash(byteEncoder.encode(schemaId));
84006
84076
  if (schemaHash.bigInt() !== outputs.schemaHash.bigInt()) {
84007
84077
  throw new Error(`schema that was used is not equal to requested in query`);
84008
84078
  }
@@ -84020,7 +84090,8 @@ var PolygonIdSdk = (function (exports) {
84020
84090
  if (notSupportedOpIndx > -1) {
84021
84091
  throw new Error(`circuit ${circuitId} not support ${queriesMetadata[notSupportedOpIndx].operator} operator`);
84022
84092
  }
84023
- queriesMetadata.forEach(async (metadata) => {
84093
+ for (let i = 0; i < queriesMetadata.length; i++) {
84094
+ const metadata = queriesMetadata[i];
84024
84095
  if (!query.type) {
84025
84096
  throw new Error(`proof query type is undefined`);
84026
84097
  }
@@ -84073,7 +84144,7 @@ var PolygonIdSdk = (function (exports) {
84073
84144
  if (timeDiff > acceptedProofGenerationDelay) {
84074
84145
  throw new Error('generated proof is outdated');
84075
84146
  }
84076
- });
84147
+ }
84077
84148
  return;
84078
84149
  }
84079
84150
  async function validateEmptyCredentialSubject(cq, outputs) {
@@ -84102,14 +84173,14 @@ var PolygonIdSdk = (function (exports) {
84102
84173
  }
84103
84174
  for (let index = 0; index < outputs.value.length; index++) {
84104
84175
  if (outputs.value[index] !== cq.values[index]) {
84176
+ if (outputs.value[index] === 0n && cq.values[index] === undefined) {
84177
+ continue;
84178
+ }
84105
84179
  throw new Error(`comparison value that was used is not equal to requested in query`);
84106
84180
  }
84107
84181
  }
84108
84182
  }
84109
84183
  async function validateDisclosure(cq, outputs, verifiablePresentation, ldLoader) {
84110
- if (!verifiablePresentation) {
84111
- throw new Error(`verifiablePresentation is required for selective disclosure request`);
84112
- }
84113
84184
  if (outputs.operator !== exports.Operators.EQ) {
84114
84185
  throw new Error(`operator for selective disclosure must be $eq`);
84115
84186
  }
@@ -84118,6 +84189,15 @@ var PolygonIdSdk = (function (exports) {
84118
84189
  throw new Error(`selective disclosure not available for array of values`);
84119
84190
  }
84120
84191
  }
84192
+ const bi = await fieldValueFromVerifiablePresentation(cq.fieldName, verifiablePresentation, ldLoader);
84193
+ if (bi !== outputs.value[0]) {
84194
+ throw new Error(`value that was used is not equal to requested in query`);
84195
+ }
84196
+ }
84197
+ const fieldValueFromVerifiablePresentation = async (fieldName, verifiablePresentation, ldLoader) => {
84198
+ if (!verifiablePresentation) {
84199
+ throw new Error(`verifiablePresentation is required for selective disclosure request`);
84200
+ }
84121
84201
  let mz;
84122
84202
  const strVerifiablePresentation = JSON.stringify(verifiablePresentation);
84123
84203
  try {
@@ -84130,13 +84210,13 @@ var PolygonIdSdk = (function (exports) {
84130
84210
  }
84131
84211
  let merklizedPath;
84132
84212
  try {
84133
- const p = `verifiableCredential.credentialSubject.${cq.fieldName}`;
84213
+ const p = `verifiableCredential.credentialSubject.${fieldName}`;
84134
84214
  merklizedPath = await lf.fromDocument(null, strVerifiablePresentation, p, {
84135
84215
  documentLoader: ldLoader
84136
84216
  });
84137
84217
  }
84138
84218
  catch (e) {
84139
- throw new Error(`can't build path to '${cq.fieldName}' key`);
84219
+ throw new Error(`can't build path to '${fieldName}' key`);
84140
84220
  }
84141
84221
  let proof;
84142
84222
  let value;
@@ -84144,18 +84224,49 @@ var PolygonIdSdk = (function (exports) {
84144
84224
  ({ proof, value } = await mz.proof(merklizedPath));
84145
84225
  }
84146
84226
  catch (e) {
84147
- throw new Error(`can't get value by path '${cq.fieldName}'`);
84227
+ throw new Error(`can't get value by path '${fieldName}'`);
84148
84228
  }
84149
84229
  if (!value) {
84150
- throw new Error(`can't get merkle value for field '${cq.fieldName}'`);
84230
+ throw new Error(`can't get merkle value for field '${fieldName}'`);
84151
84231
  }
84152
84232
  if (!proof.existence) {
84153
84233
  throw new Error(`path [${merklizedPath.parts}] doesn't exist in verifiablePresentation document`);
84154
84234
  }
84155
- const bi = await value.mtEntry();
84156
- if (bi !== outputs.value[0]) {
84157
- throw new Error(`value that was used is not equal to requested in query`);
84158
- }
84235
+ return await value.mtEntry();
84236
+ };
84237
+
84238
+ function calculateQueryHashV2(values, schema, slotIndex, operator, claimPathKey, claimPathNotExists) {
84239
+ const expValue = prepareCircuitArrayValues(values, 64);
84240
+ const valueHash = $$2.spongeHashX(expValue, 6);
84241
+ return $$2.hash([
84242
+ schema.bigInt(),
84243
+ BigInt(slotIndex),
84244
+ BigInt(operator),
84245
+ BigInt(claimPathKey),
84246
+ BigInt(claimPathNotExists),
84247
+ valueHash
84248
+ ]);
84249
+ }
84250
+ function calculateQueryHashV3(values, schema, slotIndex, operator, claimPathKey, valueArraySize, merklized, isRevocationChecked, verifierID, nullifierSessionID) {
84251
+ const expValue = prepareCircuitArrayValues(values, defaultValueArraySize);
84252
+ const valueHash = $$2.spongeHashX(expValue, 6);
84253
+ const firstPartQueryHash = $$2.hash([
84254
+ schema.bigInt(),
84255
+ BigInt(slotIndex),
84256
+ BigInt(operator),
84257
+ BigInt(claimPathKey),
84258
+ BigInt(merklized),
84259
+ valueHash
84260
+ ]);
84261
+ const queryHash = $$2.hash([
84262
+ firstPartQueryHash,
84263
+ BigInt(valueArraySize),
84264
+ BigInt(isRevocationChecked),
84265
+ BigInt(verifierID),
84266
+ BigInt(nullifierSessionID),
84267
+ 0n
84268
+ ]);
84269
+ return queryHash;
84159
84270
  }
84160
84271
 
84161
84272
  const userStateError = new Error(`user state is not valid`);
@@ -84255,7 +84366,6 @@ var PolygonIdSdk = (function (exports) {
84255
84366
  timestamp: v3PubSignals.timestamp,
84256
84367
  merklized: v3PubSignals.merklized,
84257
84368
  claimPathKey: v3PubSignals.claimPathKey,
84258
- claimPathNotExists: v3PubSignals.claimPathNotExists,
84259
84369
  valueArraySize: v3PubSignals.getValueArrSize(),
84260
84370
  isRevocationChecked: v3PubSignals.isRevocationChecked
84261
84371
  };
@@ -84332,7 +84442,7 @@ var PolygonIdSdk = (function (exports) {
84332
84442
  this.verifyIdOwnership(sender, challenge);
84333
84443
  return new BaseConfig();
84334
84444
  };
84335
- this.linkedMultiQuery10Verify = async ({ query, pubSignals }) => {
84445
+ this.linkedMultiQuery10Verify = async ({ query, verifiablePresentation, pubSignals }) => {
84336
84446
  let multiQueryPubSignals = new LinkedMultiQueryPubSignals();
84337
84447
  multiQueryPubSignals = multiQueryPubSignals.pubSignalsUnmarshal(byteEncoder.encode(JSON.stringify(pubSignals)));
84338
84448
  // verify query
@@ -84346,26 +84456,41 @@ var PolygonIdSdk = (function (exports) {
84346
84456
  }
84347
84457
  const ldContextJSON = JSON.stringify(schema);
84348
84458
  const credentialSubject = query.credentialSubject;
84349
- const schemaId = await lf.getTypeIDFromContext(JSON.stringify(schema), query.type || '', ldOpts);
84350
- const schemaHash = caclulateCoreSchemaHash(byteEncoder.encode(schemaId));
84459
+ const schemaId = await lf.getTypeIDFromContext(ldContextJSON, query.type || '', ldOpts);
84460
+ const schemaHash = calculateCoreSchemaHash(byteEncoder.encode(schemaId));
84351
84461
  const queriesMetadata = await parseQueriesMetadata(query.type || '', ldContextJSON, credentialSubject, ldOpts);
84352
- const queryHashes = queriesMetadata.map((queryMeta) => {
84353
- const valueHash = $$2.spongeHashX(queryMeta.values, 6);
84354
- return $$2.hash([
84355
- schemaHash.bigInt(),
84356
- BigInt(queryMeta.slotIndex),
84357
- BigInt(queryMeta.operator),
84358
- BigInt(queryMeta.claimPathKey),
84359
- queryMeta.merklizedSchema ? 0n : 1n,
84360
- valueHash
84361
- ]);
84362
- });
84363
- const circuitQueryHashes = multiQueryPubSignals.circuitQueryHash
84364
- .filter((i) => i !== 0n)
84365
- .sort(bigIntCompare);
84366
- queryHashes.sort(bigIntCompare);
84367
- if (!queryHashes.every((queryHash, i) => queryHash === circuitQueryHashes[i])) {
84368
- throw new Error('query hashes do not match');
84462
+ const request = [];
84463
+ const merklized = queriesMetadata[0]?.merklizedSchema ? 1 : 0;
84464
+ for (let i = 0; i < LinkedMultiQueryInputs.queryCount; i++) {
84465
+ const queryMeta = queriesMetadata[i];
84466
+ const values = queryMeta?.values ?? [];
84467
+ const valArrSize = values.length;
84468
+ const queryHash = calculateQueryHashV3(values, schemaHash, queryMeta?.slotIndex ?? 0, queryMeta?.operator ?? 0, queryMeta?.claimPathKey.toString() ?? 0, valArrSize, merklized, 0, 0, 0);
84469
+ request.push({ queryHash, queryMeta });
84470
+ }
84471
+ const queryHashCompare = (a, b) => {
84472
+ if (a.queryHash < b.queryHash)
84473
+ return -1;
84474
+ if (a.queryHash > b.queryHash)
84475
+ return 1;
84476
+ return 0;
84477
+ };
84478
+ const pubSignalsMeta = multiQueryPubSignals.circuitQueryHash.map((queryHash, index) => ({
84479
+ queryHash,
84480
+ operatorOutput: multiQueryPubSignals.operatorOutput[index]
84481
+ }));
84482
+ pubSignalsMeta.sort(queryHashCompare);
84483
+ request.sort(queryHashCompare);
84484
+ for (let i = 0; i < LinkedMultiQueryInputs.queryCount; i++) {
84485
+ if (request[i].queryHash != pubSignalsMeta[i].queryHash) {
84486
+ throw new Error('query hashes do not match');
84487
+ }
84488
+ if (request[i].queryMeta?.operator === exports.Operators.SD) {
84489
+ const disclosedValue = await fieldValueFromVerifiablePresentation(request[i].queryMeta.fieldName, verifiablePresentation, this._documentLoader);
84490
+ if (disclosedValue != pubSignalsMeta[i].operatorOutput) {
84491
+ throw new Error('disclosed value is not in the proof outputs');
84492
+ }
84493
+ }
84369
84494
  }
84370
84495
  return multiQueryPubSignals;
84371
84496
  };
@@ -85336,6 +85461,86 @@ var PolygonIdSdk = (function (exports) {
85336
85461
  }
85337
85462
  }
85338
85463
 
85464
+ /**
85465
+ * Groups the ZeroKnowledgeProofRequest objects based on their groupId.
85466
+ * Returns a Map where the key is the groupId and the value is an object containing the query and linkNonce.
85467
+ *
85468
+ * @param requestScope - An array of ZeroKnowledgeProofRequest objects.
85469
+ * @returns A Map<number, { query: JSONObject; linkNonce: number }> representing the grouped queries.
85470
+ */
85471
+ const getGroupedQueries = (requestScope) => requestScope.reduce((acc, proofReq) => {
85472
+ const groupId = proofReq.query.groupId;
85473
+ if (!groupId) {
85474
+ return acc;
85475
+ }
85476
+ const existedData = acc.get(groupId);
85477
+ if (!existedData) {
85478
+ const seed = V$3(12);
85479
+ const dataView = new DataView(seed.buffer);
85480
+ const linkNonce = dataView.getUint32(0);
85481
+ acc.set(groupId, { query: proofReq.query, linkNonce });
85482
+ return acc;
85483
+ }
85484
+ const credentialSubject = mergeObjects(existedData.query.credentialSubject, proofReq.query.credentialSubject);
85485
+ acc.set(groupId, {
85486
+ ...existedData,
85487
+ query: {
85488
+ skipClaimRevocationCheck: existedData.query.skipClaimRevocationCheck || proofReq.query.skipClaimRevocationCheck,
85489
+ ...existedData.query,
85490
+ credentialSubject
85491
+ }
85492
+ });
85493
+ return acc;
85494
+ }, new Map());
85495
+ /**
85496
+ * Processes zero knowledge proof requests.
85497
+ *
85498
+ * @param senderIdentifier - The identifier of the sender.
85499
+ * @param requests - An array of zero knowledge proof requests.
85500
+ * @param from - The identifier of the sender.
85501
+ * @param proofService - The proof service.
85502
+ * @param opts - Additional options for processing the requests.
85503
+ * @returns A promise that resolves to an array of zero knowledge proof responses.
85504
+ */
85505
+ const processZeroKnowledgeProofRequests = async (senderIdentifier, requests, from, proofService, opts) => {
85506
+ const requestScope = requests ?? [];
85507
+ const combinedQueries = getGroupedQueries(requestScope);
85508
+ const groupedCredentialsCache = new Map();
85509
+ const zkpResponses = [];
85510
+ for (const proofReq of requestScope) {
85511
+ if (!opts.supportedCircuits.includes(proofReq.circuitId)) {
85512
+ throw new Error(`Circuit ${proofReq.circuitId} is not allowed`);
85513
+ }
85514
+ const query = proofReq.query;
85515
+ const groupId = query.groupId;
85516
+ const combinedQueryData = combinedQueries.get(groupId);
85517
+ if (groupId) {
85518
+ if (!combinedQueryData) {
85519
+ throw new Error(`Invalid group id ${query.groupId}`);
85520
+ }
85521
+ const combinedQuery = combinedQueryData.query;
85522
+ if (!groupedCredentialsCache.has(groupId)) {
85523
+ const credWithRevStatus = await proofService.findCredentialByProofQuery(senderIdentifier, combinedQueryData.query);
85524
+ if (!credWithRevStatus.cred) {
85525
+ throw new Error(`Credential not found for query ${JSON.stringify(combinedQuery)}`);
85526
+ }
85527
+ groupedCredentialsCache.set(groupId, credWithRevStatus);
85528
+ }
85529
+ }
85530
+ const credWithRevStatus = groupedCredentialsCache.get(groupId);
85531
+ const zkpRes = await proofService.generateProof(proofReq, senderIdentifier, {
85532
+ verifierDid: from,
85533
+ challenge: opts.challenge,
85534
+ skipRevocation: Boolean(query.skipClaimRevocationCheck),
85535
+ credential: credWithRevStatus?.cred,
85536
+ credentialRevocationStatus: credWithRevStatus?.revStatus,
85537
+ linkNonce: combinedQueryData?.linkNonce ? BigInt(combinedQueryData.linkNonce) : undefined
85538
+ });
85539
+ zkpResponses.push(zkpRes);
85540
+ }
85541
+ return zkpResponses;
85542
+ };
85543
+
85339
85544
  /**
85340
85545
  * createAuthorizationRequest is a function to create protocol authorization request
85341
85546
  * @param {string} reason - reason to request proof
@@ -85390,6 +85595,12 @@ var PolygonIdSdk = (function (exports) {
85390
85595
  constructor(_packerMgr, _proofService) {
85391
85596
  this._packerMgr = _packerMgr;
85392
85597
  this._proofService = _proofService;
85598
+ this._supportedCircuits = [
85599
+ exports.CircuitId.AtomicQueryV3,
85600
+ exports.CircuitId.AtomicQuerySigV2,
85601
+ exports.CircuitId.AtomicQueryMTPV2,
85602
+ exports.CircuitId.LinkedMultiQuery10
85603
+ ];
85393
85604
  }
85394
85605
  /**
85395
85606
  * @inheritdoc IAuthHandler#parseAuthorizationRequest
@@ -85424,6 +85635,11 @@ var PolygonIdSdk = (function (exports) {
85424
85635
  did = W$2.parse(authRequest.to);
85425
85636
  }
85426
85637
  const guid = v4();
85638
+ if (!authRequest.from) {
85639
+ throw new Error('auth request should contain from field');
85640
+ }
85641
+ const from = W$2.parse(authRequest.from);
85642
+ const responseScope = await processZeroKnowledgeProofRequests(did, authRequest?.body.scope, from, this._proofService, { ...opts, supportedCircuits: this._supportedCircuits });
85427
85643
  const authResponse = {
85428
85644
  id: guid,
85429
85645
  typ: opts.mediaType,
@@ -85431,64 +85647,11 @@ var PolygonIdSdk = (function (exports) {
85431
85647
  thid: authRequest.thid ?? guid,
85432
85648
  body: {
85433
85649
  message: authRequest?.body?.message,
85434
- scope: []
85650
+ scope: responseScope
85435
85651
  },
85436
85652
  from: did.string(),
85437
85653
  to: authRequest.from
85438
85654
  };
85439
- const requestScope = authRequest.body.scope;
85440
- const combinedQueries = requestScope.reduce((acc, proofReq) => {
85441
- const groupId = proofReq.query.groupId;
85442
- if (!groupId) {
85443
- return acc;
85444
- }
85445
- const existedData = acc.get(groupId);
85446
- if (!existedData) {
85447
- const seed = V$3(12);
85448
- const dataView = new DataView(seed.buffer);
85449
- const linkNonce = dataView.getUint32(0);
85450
- acc.set(groupId, { query: proofReq.query, linkNonce });
85451
- return acc;
85452
- }
85453
- const credentialSubject = mergeObjects(existedData.query.credentialSubject, proofReq.query.credentialSubject);
85454
- acc.set(groupId, {
85455
- ...existedData,
85456
- query: {
85457
- skipClaimRevocationCheck: existedData.query.skipClaimRevocationCheck || proofReq.query.skipClaimRevocationCheck,
85458
- ...existedData.query,
85459
- credentialSubject
85460
- }
85461
- });
85462
- return acc;
85463
- }, new Map());
85464
- const groupedCredentialsCache = new Map();
85465
- for (const proofReq of requestScope) {
85466
- const query = proofReq.query;
85467
- const groupId = query.groupId;
85468
- const combinedQueryData = combinedQueries.get(groupId);
85469
- if (groupId) {
85470
- if (!combinedQueryData) {
85471
- throw new Error(`Invalid group id ${query.groupId}`);
85472
- }
85473
- const combinedQuery = combinedQueryData.query;
85474
- if (!groupedCredentialsCache.has(groupId)) {
85475
- const credWithRevStatus = await this._proofService.findCredentialByProofQuery(did, combinedQueryData.query);
85476
- if (!credWithRevStatus.cred) {
85477
- throw new Error(`Credential not found for query ${JSON.stringify(combinedQuery)}`);
85478
- }
85479
- groupedCredentialsCache.set(groupId, credWithRevStatus);
85480
- }
85481
- }
85482
- const credWithRevStatus = groupedCredentialsCache.get(groupId);
85483
- const zkpRes = await this._proofService.generateProof(proofReq, did, {
85484
- verifierDid: W$2.parse(authRequest.from),
85485
- skipRevocation: Boolean(query.skipClaimRevocationCheck),
85486
- credential: credWithRevStatus?.cred,
85487
- credentialRevocationStatus: credWithRevStatus?.revStatus,
85488
- linkNonce: combinedQueryData?.linkNonce ? BigInt(combinedQueryData.linkNonce) : undefined
85489
- });
85490
- authResponse.body.scope.push(zkpRes);
85491
- }
85492
85655
  const msgBytes = byteEncoder.encode(JSON.stringify(authResponse));
85493
85656
  const packerOpts = opts.mediaType === MediaType.SignedMessage
85494
85657
  ? opts.packerOptions
@@ -85757,7 +85920,7 @@ var PolygonIdSdk = (function (exports) {
85757
85920
  this._packerMgr = _packerMgr;
85758
85921
  this._proofService = _proofService;
85759
85922
  this._zkpVerifier = _zkpVerifier;
85760
- this._allowedCircuits = [
85923
+ this._supportedCircuits = [
85761
85924
  exports.CircuitId.AtomicQueryMTPV2OnChain,
85762
85925
  exports.CircuitId.AtomicQuerySigV2OnChain,
85763
85926
  exports.CircuitId.AtomicQueryV3OnChain
@@ -85794,33 +85957,14 @@ var PolygonIdSdk = (function (exports) {
85794
85957
  if (!opts.ethSigner) {
85795
85958
  throw new Error("Can't sign transaction. Provide Signer in options.");
85796
85959
  }
85797
- const zkRequests = [];
85798
- const { contract_address, chain_id } = ciRequest.body.transaction_data;
85960
+ const { chain_id } = ciRequest.body.transaction_data;
85799
85961
  const networkFlag = Object.keys(u$2).find((key) => u$2[key] === chain_id);
85800
85962
  if (!networkFlag) {
85801
85963
  throw new Error(`Invalid chain id ${chain_id}`);
85802
85964
  }
85803
- const [blockchain, networkId] = networkFlag.split(':');
85804
- const verifierId = buildVerifierId(contract_address, {
85805
- blockchain,
85806
- networkId,
85807
- // DidMethod.Iden3 is used based on discussions: all onchain issuers have iden3 did method by default. This can be changed in the release of v3 circuit.
85808
- method: h$3.Iden3
85809
- });
85810
- const verifierDid = W$2.parseFromId(verifierId);
85811
- for (const proofReq of ciRequest.body.scope) {
85812
- if (!this._allowedCircuits.includes(proofReq.circuitId)) {
85813
- throw new Error(`Can't handle circuit ${proofReq.circuitId}. Only onchain circuits are allowed.`);
85814
- }
85815
- const query = proofReq.query;
85816
- const zkpRes = await this._proofService.generateProof(proofReq, did, {
85817
- skipRevocation: query.skipClaimRevocationCheck ?? false,
85818
- challenge: opts.challenge,
85819
- verifierDid
85820
- });
85821
- zkRequests.push(zkpRes);
85822
- }
85823
- return this._zkpVerifier.submitZKPResponse(opts.ethSigner, ciRequest.body.transaction_data, zkRequests);
85965
+ const verifierDid = ciRequest.from ? W$2.parse(ciRequest.from) : undefined;
85966
+ const zkpResponses = await processZeroKnowledgeProofRequests(did, ciRequest?.body?.scope, verifierDid, this._proofService, { ...opts, supportedCircuits: this._supportedCircuits });
85967
+ return this._zkpVerifier.submitZKPResponse(opts.ethSigner, ciRequest.body.transaction_data, zkpResponses);
85824
85968
  }
85825
85969
  }
85826
85970
 
@@ -85889,6 +86033,93 @@ var PolygonIdSdk = (function (exports) {
85889
86033
  }
85890
86034
  }
85891
86035
 
86036
+ /**
86037
+ *
86038
+ * Allows to process RevocationStatusRequest protocol message
86039
+ *
86040
+
86041
+ * @class RevocationStatusHandler
86042
+ * @implements implements IRevocationStatusHandler interface
86043
+ */
86044
+ class RevocationStatusHandler {
86045
+ /**
86046
+ * Creates an instance of RevocationStatusHandler.
86047
+ * @param {IPackageManager} _packerMgr - package manager to unpack message envelope
86048
+ * @param {IIdentityWallet} _identityWallet - identity wallet
86049
+ *
86050
+ */
86051
+ constructor(_packerMgr, _identityWallet) {
86052
+ this._packerMgr = _packerMgr;
86053
+ this._identityWallet = _identityWallet;
86054
+ }
86055
+ /**
86056
+ * @inheritdoc IRevocationStatusHandler#parseRevocationStatusRequest
86057
+ */
86058
+ async parseRevocationStatusRequest(request) {
86059
+ const { unpackedMessage: message } = await this._packerMgr.unpack(request);
86060
+ const ciRequest = message;
86061
+ if (message.type !== PROTOCOL_MESSAGE_TYPE.REVOCATION_STATUS_REQUEST_MESSAGE_TYPE) {
86062
+ throw new Error('Invalid media type');
86063
+ }
86064
+ return ciRequest;
86065
+ }
86066
+ /**
86067
+ * @inheritdoc IRevocationStatusHandler#handleRevocationStatusRequest
86068
+ */
86069
+ async handleRevocationStatusRequest(did, request, opts) {
86070
+ if (!opts) {
86071
+ opts = {
86072
+ mediaType: MediaType.PlainMessage
86073
+ };
86074
+ }
86075
+ if (opts.mediaType === MediaType.SignedMessage && !opts.packerOptions) {
86076
+ throw new Error(`jws packer options are required for ${MediaType.SignedMessage}`);
86077
+ }
86078
+ const rsRequest = await this.parseRevocationStatusRequest(request);
86079
+ if (!rsRequest.to) {
86080
+ throw new Error(`failed request. empty 'to' field`);
86081
+ }
86082
+ if (!rsRequest.from) {
86083
+ throw new Error(`failed request. empty 'from' field`);
86084
+ }
86085
+ if (!rsRequest.body?.revocation_nonce) {
86086
+ throw new Error(`failed request. empty 'revocation_nonce' field`);
86087
+ }
86088
+ const issuerDID = W$2.parse(rsRequest.to);
86089
+ const mtpWithTreeState = await this._identityWallet.generateNonRevocationMtpWithNonce(issuerDID, BigInt(rsRequest.body.revocation_nonce), opts?.treeState);
86090
+ const treeState = mtpWithTreeState.treeState;
86091
+ const revStatus = {
86092
+ issuer: {
86093
+ state: treeState?.state.string(),
86094
+ claimsTreeRoot: treeState.claimsRoot.string(),
86095
+ revocationTreeRoot: treeState.revocationRoot.string(),
86096
+ rootOfRoots: treeState.rootOfRoots.string()
86097
+ },
86098
+ mtp: mtpWithTreeState.proof
86099
+ };
86100
+ const packerOpts = opts.mediaType === MediaType.SignedMessage
86101
+ ? opts.packerOptions
86102
+ : {
86103
+ provingMethodAlg: T.provingMethodGroth16AuthV2Instance.methodAlg
86104
+ };
86105
+ const senderDID = W$2.parse(rsRequest.to);
86106
+ const guid = v4();
86107
+ const response = {
86108
+ id: guid,
86109
+ typ: MediaType.PlainMessage,
86110
+ type: PROTOCOL_MESSAGE_TYPE.REVOCATION_STATUS_RESPONSE_MESSAGE_TYPE,
86111
+ thid: rsRequest.thid ?? guid,
86112
+ body: revStatus,
86113
+ from: did.string(),
86114
+ to: rsRequest.from
86115
+ };
86116
+ return this._packerMgr.pack(opts.mediaType, byteEncoder.encode(JSON.stringify(response)), {
86117
+ senderDID,
86118
+ ...packerOpts
86119
+ });
86120
+ }
86121
+ }
86122
+
85892
86123
  exports.AbstractPrivateKeyStore = AbstractPrivateKeyStore;
85893
86124
  exports.AgentResolver = AgentResolver;
85894
86125
  exports.AtomicQueryMTPV2Inputs = AtomicQueryMTPV2Inputs;
@@ -85971,6 +86202,7 @@ var PolygonIdSdk = (function (exports) {
85971
86202
  exports.QueryOperators = QueryOperators;
85972
86203
  exports.RHSResolver = RHSResolver;
85973
86204
  exports.RefreshHandler = RefreshHandler;
86205
+ exports.RevocationStatusHandler = RevocationStatusHandler;
85974
86206
  exports.SDK_EVENTS = SDK_EVENTS;
85975
86207
  exports.Scalar = Scalar$1;
85976
86208
  exports.Sec256k1Provider = Sec256k1Provider;
@@ -85999,7 +86231,9 @@ var PolygonIdSdk = (function (exports) {
85999
86231
  exports.bytesToBase64url = bytesToBase64url;
86000
86232
  exports.bytesToHex = bytesToHex$1;
86001
86233
  exports.cacheLoader = cacheLoader;
86002
- exports.caclulateCoreSchemaHash = caclulateCoreSchemaHash;
86234
+ exports.calculateCoreSchemaHash = calculateCoreSchemaHash;
86235
+ exports.calculateQueryHashV2 = calculateQueryHashV2;
86236
+ exports.calculateQueryHashV3 = calculateQueryHashV3;
86003
86237
  exports.checkDataInField = checkDataInField;
86004
86238
  exports.checkQueryRequest = checkQueryRequest;
86005
86239
  exports.circuitValidator = circuitValidator;
@@ -86024,6 +86258,7 @@ var PolygonIdSdk = (function (exports) {
86024
86258
  exports.extractPublicKeyBytes = extractPublicKeyBytes;
86025
86259
  exports.factoryComparer = factoryComparer;
86026
86260
  exports.fieldToByteArray = fieldToByteArray;
86261
+ exports.fieldValueFromVerifiablePresentation = fieldValueFromVerifiablePresentation;
86027
86262
  exports.fillCoreClaimSlot = fillCoreClaimSlot;
86028
86263
  exports.fillSlot = fillSlot;
86029
86264
  exports.findCredentialType = findCredentialType;
@@ -86052,6 +86287,7 @@ var PolygonIdSdk = (function (exports) {
86052
86287
  exports.parseSerializationAttr = parseSerializationAttr;
86053
86288
  exports.prepareCircuitArrayValues = prepareCircuitArrayValues;
86054
86289
  exports.prepareSiblingsStr = prepareSiblingsStr;
86290
+ exports.processZeroKnowledgeProofRequests = processZeroKnowledgeProofRequests;
86055
86291
  exports.pushHashesToRHS = pushHashesToRHS;
86056
86292
  exports.resolveDIDDocumentAuth = resolveDIDDocumentAuth;
86057
86293
  exports.resolvePath = resolvePath;