@0xpolygonid/js-sdk 1.8.2 → 1.9.0

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 (54) hide show
  1. package/dist/browser/esm/index.js +240 -124
  2. package/dist/browser/esm/index.js.map +1 -1
  3. package/dist/browser/umd/index.js +243 -124
  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 +5 -3
  12. package/dist/node/cjs/iden3comm/handlers/contract-request.js +3 -11
  13. package/dist/node/cjs/proof/common.js +11 -5
  14. package/dist/node/cjs/proof/provers/inputs-generator.js +6 -10
  15. package/dist/node/cjs/proof/verifiers/index.js +1 -0
  16. package/dist/node/cjs/proof/verifiers/pub-signals-verifier.js +37 -22
  17. package/dist/node/cjs/proof/verifiers/query-hash.js +40 -0
  18. package/dist/node/cjs/proof/verifiers/query.js +24 -16
  19. package/dist/node/cjs/schema-processor/utils.js +2 -2
  20. package/dist/node/cjs/storage/filters/jsonQuery.js +28 -2
  21. package/dist/node/cjs/verifiable/core-utils.js +3 -3
  22. package/dist/node/cjs/verifiable/credential.js +1 -1
  23. package/dist/node/esm/circuits/atomic-query-v3-on-chain.js +9 -26
  24. package/dist/node/esm/circuits/atomic-query-v3.js +7 -6
  25. package/dist/node/esm/circuits/common.js +1 -1
  26. package/dist/node/esm/circuits/comparer.js +24 -3
  27. package/dist/node/esm/circuits/linked-multi-query.js +7 -18
  28. package/dist/node/esm/circuits/models.js +48 -4
  29. package/dist/node/esm/iden3comm/handlers/auth.js +5 -3
  30. package/dist/node/esm/iden3comm/handlers/contract-request.js +4 -12
  31. package/dist/node/esm/proof/common.js +12 -6
  32. package/dist/node/esm/proof/provers/inputs-generator.js +7 -11
  33. package/dist/node/esm/proof/verifiers/index.js +1 -0
  34. package/dist/node/esm/proof/verifiers/pub-signals-verifier.js +41 -26
  35. package/dist/node/esm/proof/verifiers/query-hash.js +35 -0
  36. package/dist/node/esm/proof/verifiers/query.js +23 -16
  37. package/dist/node/esm/schema-processor/utils.js +3 -3
  38. package/dist/node/esm/storage/filters/jsonQuery.js +28 -2
  39. package/dist/node/esm/verifiable/core-utils.js +1 -1
  40. package/dist/node/esm/verifiable/credential.js +2 -2
  41. package/dist/types/circuits/atomic-query-v3-on-chain.d.ts +4 -8
  42. package/dist/types/circuits/atomic-query-v3.d.ts +2 -2
  43. package/dist/types/circuits/common.d.ts +1 -1
  44. package/dist/types/circuits/comparer.d.ts +4 -0
  45. package/dist/types/circuits/linked-multi-query.d.ts +0 -1
  46. package/dist/types/circuits/models.d.ts +7 -4
  47. package/dist/types/iden3comm/types/protocol/contract-request.d.ts +1 -0
  48. package/dist/types/proof/verifiers/index.d.ts +1 -0
  49. package/dist/types/proof/verifiers/query-hash.d.ts +3 -0
  50. package/dist/types/proof/verifiers/query.d.ts +1 -0
  51. package/dist/types/schema-processor/utils.d.ts +1 -1
  52. package/dist/types/storage/filters/jsonQuery.d.ts +1 -1
  53. package/dist/types/verifiable/core-utils.d.ts +1 -1
  54. package/package.json +1 -1
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PubSignalsVerifier = exports.userStateError = void 0;
4
- const js_crypto_1 = require("@iden3/js-crypto");
5
4
  const js_iden3_core_1 = require("@iden3/js-iden3-core");
6
5
  const js_jsonld_merklization_1 = require("@iden3/js-jsonld-merklization");
7
6
  const utils_1 = require("../../utils");
@@ -15,6 +14,8 @@ const linked_multi_query_1 = require("../../circuits/linked-multi-query");
15
14
  const models_1 = require("../../circuits/models");
16
15
  const query_1 = require("./query");
17
16
  const common_2 = require("../common");
17
+ const circuits_1 = require("../../circuits");
18
+ const query_hash_1 = require("./query-hash");
18
19
  exports.userStateError = new Error(`user state is not valid`);
19
20
  const zeroInt = 0n;
20
21
  const defaultProofVerifyOpts = 1 * 60 * 60 * 1000; // 1 hour
@@ -112,7 +113,6 @@ class PubSignalsVerifier {
112
113
  timestamp: v3PubSignals.timestamp,
113
114
  merklized: v3PubSignals.merklized,
114
115
  claimPathKey: v3PubSignals.claimPathKey,
115
- claimPathNotExists: v3PubSignals.claimPathNotExists,
116
116
  valueArraySize: v3PubSignals.getValueArrSize(),
117
117
  isRevocationChecked: v3PubSignals.isRevocationChecked
118
118
  };
@@ -189,7 +189,7 @@ class PubSignalsVerifier {
189
189
  this.verifyIdOwnership(sender, challenge);
190
190
  return new common_1.BaseConfig();
191
191
  };
192
- this.linkedMultiQuery10Verify = async ({ query, pubSignals }) => {
192
+ this.linkedMultiQuery10Verify = async ({ query, verifiablePresentation, pubSignals }) => {
193
193
  let multiQueryPubSignals = new linked_multi_query_1.LinkedMultiQueryPubSignals();
194
194
  multiQueryPubSignals = multiQueryPubSignals.pubSignalsUnmarshal(utils_1.byteEncoder.encode(JSON.stringify(pubSignals)));
195
195
  // verify query
@@ -203,26 +203,41 @@ class PubSignalsVerifier {
203
203
  }
204
204
  const ldContextJSON = JSON.stringify(schema);
205
205
  const credentialSubject = query.credentialSubject;
206
- const schemaId = await js_jsonld_merklization_1.Path.getTypeIDFromContext(JSON.stringify(schema), query.type || '', ldOpts);
207
- const schemaHash = (0, verifiable_1.caclulateCoreSchemaHash)(utils_1.byteEncoder.encode(schemaId));
206
+ const schemaId = await js_jsonld_merklization_1.Path.getTypeIDFromContext(ldContextJSON, query.type || '', ldOpts);
207
+ const schemaHash = (0, verifiable_1.calculateCoreSchemaHash)(utils_1.byteEncoder.encode(schemaId));
208
208
  const queriesMetadata = await (0, common_2.parseQueriesMetadata)(query.type || '', ldContextJSON, credentialSubject, ldOpts);
209
- const queryHashes = queriesMetadata.map((queryMeta) => {
210
- const valueHash = js_crypto_1.poseidon.spongeHashX(queryMeta.values, 6);
211
- return js_crypto_1.poseidon.hash([
212
- schemaHash.bigInt(),
213
- BigInt(queryMeta.slotIndex),
214
- BigInt(queryMeta.operator),
215
- BigInt(queryMeta.claimPathKey),
216
- queryMeta.merklizedSchema ? 0n : 1n,
217
- valueHash
218
- ]);
219
- });
220
- const circuitQueryHashes = multiQueryPubSignals.circuitQueryHash
221
- .filter((i) => i !== 0n)
222
- .sort(utils_1.bigIntCompare);
223
- queryHashes.sort(utils_1.bigIntCompare);
224
- if (!queryHashes.every((queryHash, i) => queryHash === circuitQueryHashes[i])) {
225
- throw new Error('query hashes do not match');
209
+ const request = [];
210
+ const merklized = queriesMetadata[0]?.merklizedSchema ? 1 : 0;
211
+ for (let i = 0; i < linked_multi_query_1.LinkedMultiQueryInputs.queryCount; i++) {
212
+ const queryMeta = queriesMetadata[i];
213
+ const values = queryMeta?.values ?? [];
214
+ const valArrSize = values.length;
215
+ const queryHash = (0, query_hash_1.calculateQueryHashV3)(values, schemaHash, queryMeta?.slotIndex ?? 0, queryMeta?.operator ?? 0, queryMeta?.claimPathKey.toString() ?? 0, valArrSize, merklized, 0, 0, 0);
216
+ request.push({ queryHash, queryMeta });
217
+ }
218
+ const queryHashCompare = (a, b) => {
219
+ if (a.queryHash < b.queryHash)
220
+ return -1;
221
+ if (a.queryHash > b.queryHash)
222
+ return 1;
223
+ return 0;
224
+ };
225
+ const pubSignalsMeta = multiQueryPubSignals.circuitQueryHash.map((queryHash, index) => ({
226
+ queryHash,
227
+ operatorOutput: multiQueryPubSignals.operatorOutput[index]
228
+ }));
229
+ pubSignalsMeta.sort(queryHashCompare);
230
+ request.sort(queryHashCompare);
231
+ for (let i = 0; i < linked_multi_query_1.LinkedMultiQueryInputs.queryCount; i++) {
232
+ if (request[i].queryHash != pubSignalsMeta[i].queryHash) {
233
+ throw new Error('query hashes do not match');
234
+ }
235
+ if (request[i].queryMeta?.operator === circuits_1.Operators.SD) {
236
+ const disclosedValue = await (0, query_1.fieldValueFromVerifiablePresentation)(request[i].queryMeta.fieldName, verifiablePresentation, this._documentLoader);
237
+ if (disclosedValue != pubSignalsMeta[i].operatorOutput) {
238
+ throw new Error('disclosed value is not in the proof outputs');
239
+ }
240
+ }
226
241
  }
227
242
  return multiQueryPubSignals;
228
243
  };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateQueryHashV3 = exports.calculateQueryHashV2 = void 0;
4
+ const js_crypto_1 = require("@iden3/js-crypto");
5
+ const circuits_1 = require("../../circuits");
6
+ function calculateQueryHashV2(values, schema, slotIndex, operator, claimPathKey, claimPathNotExists) {
7
+ const expValue = (0, circuits_1.prepareCircuitArrayValues)(values, 64);
8
+ const valueHash = js_crypto_1.poseidon.spongeHashX(expValue, 6);
9
+ return js_crypto_1.poseidon.hash([
10
+ schema.bigInt(),
11
+ BigInt(slotIndex),
12
+ BigInt(operator),
13
+ BigInt(claimPathKey),
14
+ BigInt(claimPathNotExists),
15
+ valueHash
16
+ ]);
17
+ }
18
+ exports.calculateQueryHashV2 = calculateQueryHashV2;
19
+ function calculateQueryHashV3(values, schema, slotIndex, operator, claimPathKey, valueArraySize, merklized, isRevocationChecked, verifierID, nullifierSessionID) {
20
+ const expValue = (0, circuits_1.prepareCircuitArrayValues)(values, circuits_1.defaultValueArraySize);
21
+ const valueHash = js_crypto_1.poseidon.spongeHashX(expValue, 6);
22
+ const firstPartQueryHash = js_crypto_1.poseidon.hash([
23
+ schema.bigInt(),
24
+ BigInt(slotIndex),
25
+ BigInt(operator),
26
+ BigInt(claimPathKey),
27
+ BigInt(merklized),
28
+ valueHash
29
+ ]);
30
+ const queryHash = js_crypto_1.poseidon.hash([
31
+ firstPartQueryHash,
32
+ BigInt(valueArraySize),
33
+ BigInt(isRevocationChecked),
34
+ BigInt(verifierID),
35
+ BigInt(nullifierSessionID),
36
+ 0n
37
+ ]);
38
+ return queryHash;
39
+ }
40
+ exports.calculateQueryHashV3 = calculateQueryHashV3;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkQueryRequest = void 0;
3
+ exports.fieldValueFromVerifiablePresentation = exports.checkQueryRequest = void 0;
4
4
  const js_iden3_core_1 = require("@iden3/js-iden3-core");
5
5
  const js_jsonld_merklization_1 = require("@iden3/js-jsonld-merklization");
6
6
  const utils_1 = require("../../utils");
@@ -32,7 +32,7 @@ async function checkQueryRequest(query, outputs, circuitId, schemaLoader, verifi
32
32
  const schemaId = await js_jsonld_merklization_1.Path.getTypeIDFromContext(JSON.stringify(schema), query.type, {
33
33
  documentLoader: schemaLoader
34
34
  });
35
- const schemaHash = (0, verifiable_1.caclulateCoreSchemaHash)(utils_1.byteEncoder.encode(schemaId));
35
+ const schemaHash = (0, verifiable_1.calculateCoreSchemaHash)(utils_1.byteEncoder.encode(schemaId));
36
36
  if (schemaHash.bigInt() !== outputs.schemaHash.bigInt()) {
37
37
  throw new Error(`schema that was used is not equal to requested in query`);
38
38
  }
@@ -50,7 +50,8 @@ async function checkQueryRequest(query, outputs, circuitId, schemaLoader, verifi
50
50
  if (notSupportedOpIndx > -1) {
51
51
  throw new Error(`circuit ${circuitId} not support ${queriesMetadata[notSupportedOpIndx].operator} operator`);
52
52
  }
53
- queriesMetadata.forEach(async (metadata) => {
53
+ for (let i = 0; i < queriesMetadata.length; i++) {
54
+ const metadata = queriesMetadata[i];
54
55
  if (!query.type) {
55
56
  throw new Error(`proof query type is undefined`);
56
57
  }
@@ -103,7 +104,7 @@ async function checkQueryRequest(query, outputs, circuitId, schemaLoader, verifi
103
104
  if (timeDiff > acceptedProofGenerationDelay) {
104
105
  throw new Error('generated proof is outdated');
105
106
  }
106
- });
107
+ }
107
108
  return;
108
109
  }
109
110
  exports.checkQueryRequest = checkQueryRequest;
@@ -133,14 +134,14 @@ async function validateOperators(cq, outputs) {
133
134
  }
134
135
  for (let index = 0; index < outputs.value.length; index++) {
135
136
  if (outputs.value[index] !== cq.values[index]) {
137
+ if (outputs.value[index] === 0n && cq.values[index] === undefined) {
138
+ continue;
139
+ }
136
140
  throw new Error(`comparison value that was used is not equal to requested in query`);
137
141
  }
138
142
  }
139
143
  }
140
144
  async function validateDisclosure(cq, outputs, verifiablePresentation, ldLoader) {
141
- if (!verifiablePresentation) {
142
- throw new Error(`verifiablePresentation is required for selective disclosure request`);
143
- }
144
145
  if (outputs.operator !== comparer_1.Operators.EQ) {
145
146
  throw new Error(`operator for selective disclosure must be $eq`);
146
147
  }
@@ -149,6 +150,15 @@ async function validateDisclosure(cq, outputs, verifiablePresentation, ldLoader)
149
150
  throw new Error(`selective disclosure not available for array of values`);
150
151
  }
151
152
  }
153
+ const bi = await (0, exports.fieldValueFromVerifiablePresentation)(cq.fieldName, verifiablePresentation, ldLoader);
154
+ if (bi !== outputs.value[0]) {
155
+ throw new Error(`value that was used is not equal to requested in query`);
156
+ }
157
+ }
158
+ const fieldValueFromVerifiablePresentation = async (fieldName, verifiablePresentation, ldLoader) => {
159
+ if (!verifiablePresentation) {
160
+ throw new Error(`verifiablePresentation is required for selective disclosure request`);
161
+ }
152
162
  let mz;
153
163
  const strVerifiablePresentation = JSON.stringify(verifiablePresentation);
154
164
  try {
@@ -161,13 +171,13 @@ async function validateDisclosure(cq, outputs, verifiablePresentation, ldLoader)
161
171
  }
162
172
  let merklizedPath;
163
173
  try {
164
- const p = `verifiableCredential.credentialSubject.${cq.fieldName}`;
174
+ const p = `verifiableCredential.credentialSubject.${fieldName}`;
165
175
  merklizedPath = await js_jsonld_merklization_1.Path.fromDocument(null, strVerifiablePresentation, p, {
166
176
  documentLoader: ldLoader
167
177
  });
168
178
  }
169
179
  catch (e) {
170
- throw new Error(`can't build path to '${cq.fieldName}' key`);
180
+ throw new Error(`can't build path to '${fieldName}' key`);
171
181
  }
172
182
  let proof;
173
183
  let value;
@@ -175,16 +185,14 @@ async function validateDisclosure(cq, outputs, verifiablePresentation, ldLoader)
175
185
  ({ proof, value } = await mz.proof(merklizedPath));
176
186
  }
177
187
  catch (e) {
178
- throw new Error(`can't get value by path '${cq.fieldName}'`);
188
+ throw new Error(`can't get value by path '${fieldName}'`);
179
189
  }
180
190
  if (!value) {
181
- throw new Error(`can't get merkle value for field '${cq.fieldName}'`);
191
+ throw new Error(`can't get merkle value for field '${fieldName}'`);
182
192
  }
183
193
  if (!proof.existence) {
184
194
  throw new Error(`path [${merklizedPath.parts}] doesn't exist in verifiablePresentation document`);
185
195
  }
186
- const bi = await value.mtEntry();
187
- if (bi !== outputs.value[0]) {
188
- throw new Error(`value that was used is not equal to requested in query`);
189
- }
190
- }
196
+ return await value.mtEntry();
197
+ };
198
+ exports.fieldValueFromVerifiablePresentation = fieldValueFromVerifiablePresentation;
@@ -55,14 +55,14 @@ function checkDataInField(data) {
55
55
  exports.checkDataInField = checkDataInField;
56
56
  /**
57
57
  *
58
- * @deprecated The method should not be used. Use caclulateCoreSchemaHash from verifiable.
58
+ * @deprecated The method should not be used. Use calculateCoreSchemaHash from verifiable.
59
59
  * Calculates schema hash
60
60
  *
61
61
  * @param {Uint8Array} schemaId
62
62
  * @returns {*} {SchemaHash}
63
63
  */
64
64
  const createSchemaHash = (schemaId) => {
65
- return (0, verifiable_1.caclulateCoreSchemaHash)(schemaId);
65
+ return (0, verifiable_1.calculateCoreSchemaHash)(schemaId);
66
66
  };
67
67
  exports.createSchemaHash = createSchemaHash;
68
68
  /**
@@ -69,6 +69,19 @@ const lessThanOrEqual = (a, b) => {
69
69
  }
70
70
  return a <= b;
71
71
  };
72
+ // a - field value
73
+ // b - true / false (exists operator values)
74
+ const existsComparator = (a, b) => {
75
+ if (truthyValues.includes(b) && typeof a !== 'undefined') {
76
+ // if exists val is true , a field val exists
77
+ return true;
78
+ }
79
+ // if exists val is false , a field val doesn't exist
80
+ if (falsyValues.includes(b) && (a === undefined || (Array.isArray(a) && !a.length))) {
81
+ return true;
82
+ }
83
+ return false;
84
+ };
72
85
  const inOperator = (a, b) => {
73
86
  if (Array.isArray(a) && Array.isArray(b)) {
74
87
  return a.every((val) => b.includes(val));
@@ -81,9 +94,19 @@ const inOperator = (a, b) => {
81
94
  }
82
95
  return false;
83
96
  };
97
+ const betweenOperator = (a, b) => {
98
+ if (!Array.isArray(b) || b.length !== 2) {
99
+ throw new Error('$between/$nonbetween operator value should be 2 elements array');
100
+ }
101
+ if (Array.isArray(a)) {
102
+ return a.every((val) => val >= b[0] && val <= b[1]);
103
+ }
104
+ return a >= b[0] && a <= b[1];
105
+ };
84
106
  exports.comparatorOptions = {
85
107
  $noop: () => true,
86
108
  $sd: () => true,
109
+ $exists: (a, b) => existsComparator(a, b),
87
110
  $eq: (a, b) => equalsComparator(a, b),
88
111
  $in: (a, b) => inOperator(a, b),
89
112
  $nin: (a, b) => !inOperator(a, b),
@@ -91,7 +114,9 @@ exports.comparatorOptions = {
91
114
  $lt: (a, b) => !greaterThan(a, b),
92
115
  $ne: (a, b) => !equalsComparator(a, b),
93
116
  $gte: (a, b) => greaterThanOrEqual(a, b),
94
- $lte: (a, b) => lessThanOrEqual(a, b)
117
+ $lte: (a, b) => lessThanOrEqual(a, b),
118
+ $between: (a, b) => betweenOperator(a, b),
119
+ $nonbetween: (a, b) => !betweenOperator(a, b)
95
120
  };
96
121
  /**
97
122
  * credential search path resolver
@@ -140,7 +165,8 @@ class FilterQuery {
140
165
  throw new Error(SearchError.NotDefinedComparator);
141
166
  }
142
167
  const credentialPathValue = (0, exports.resolvePath)(credential, this.path);
143
- if (credentialPathValue === null || credentialPathValue === undefined) {
168
+ if ((credentialPathValue === null || credentialPathValue === undefined) &&
169
+ this.operatorFunc !== existsComparator) {
144
170
  return false;
145
171
  }
146
172
  if (this.isReverseParams) {
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.caclulateCoreSchemaHash = exports.parseCoreClaimSlots = exports.findCredentialType = exports.parseSerializationAttr = exports.getSerializationAttrFromParsedContext = exports.getSerializationAttrFromContext = exports.fillCoreClaimSlot = exports.getFieldSlotIndex = void 0;
26
+ exports.calculateCoreSchemaHash = exports.parseCoreClaimSlots = exports.findCredentialType = exports.parseSerializationAttr = exports.getSerializationAttrFromParsedContext = exports.getSerializationAttrFromContext = exports.fillCoreClaimSlot = exports.getFieldSlotIndex = void 0;
27
27
  const js_iden3_core_1 = require("@iden3/js-iden3-core");
28
28
  const js_jsonld_merklization_1 = require("@iden3/js-jsonld-merklization");
29
29
  const utils_1 = require("../utils");
@@ -227,8 +227,8 @@ exports.parseCoreClaimSlots = parseCoreClaimSlots;
227
227
  * @param {Uint8Array} schemaId
228
228
  * @returns {*} {SchemaHash}
229
229
  */
230
- const caclulateCoreSchemaHash = (schemaId) => {
230
+ const calculateCoreSchemaHash = (schemaId) => {
231
231
  const sHash = js_crypto_1.Hex.decodeString((0, js_sha3_1.keccak256)(schemaId));
232
232
  return new js_iden3_core_1.SchemaHash(sHash.slice(sHash.length - 16, sHash.length));
233
233
  };
234
- exports.caclulateCoreSchemaHash = caclulateCoreSchemaHash;
234
+ exports.calculateCoreSchemaHash = calculateCoreSchemaHash;
@@ -145,7 +145,7 @@ class W3CCredential {
145
145
  if (!nonMerklized && opts.merklizedRootPosition === constants_1.MerklizedRootPosition.None) {
146
146
  opts.merklizedRootPosition = constants_1.MerklizedRootPosition.Index;
147
147
  }
148
- const schemaHash = (0, core_utils_1.caclulateCoreSchemaHash)(utils_2.byteEncoder.encode(credentialType));
148
+ const schemaHash = (0, core_utils_1.calculateCoreSchemaHash)(utils_2.byteEncoder.encode(credentialType));
149
149
  const claim = js_iden3_core_1.Claim.newClaim(schemaHash, js_iden3_core_1.ClaimOptions.withIndexDataBytes(slots.indexA, slots.indexB), js_iden3_core_1.ClaimOptions.withValueDataBytes(slots.valueA, slots.valueB), js_iden3_core_1.ClaimOptions.withRevocationNonce(BigInt(opts.revNonce)), js_iden3_core_1.ClaimOptions.withVersion(opts.version));
150
150
  if (opts.updatable) {
151
151
  claim.setFlagUpdatable(opts.updatable);
@@ -1,5 +1,5 @@
1
1
  import { Claim, Id } from '@iden3/js-iden3-core';
2
- import { BaseConfig, bigIntArrayToStringArray, prepareSiblingsStr, existenceToInt, getNodeAuxValue, prepareCircuitArrayValues } from './common';
2
+ import { BaseConfig, bigIntArrayToStringArray, prepareSiblingsStr, getNodeAuxValue, prepareCircuitArrayValues } from './common';
3
3
  import { CircuitError, ValueProof } from './models';
4
4
  import { Hash, Proof, ZERO_HASH } from '@iden3/js-merkletree';
5
5
  import { byteDecoder, byteEncoder } from '../utils';
@@ -23,13 +23,14 @@ export class AtomicQueryV3OnChainInputs extends BaseConfig {
23
23
  if (!this.query.values) {
24
24
  throw new Error(CircuitError.EmptyQueryValue);
25
25
  }
26
+ this.query.validateValueArraySize(this.getValueArrSize());
26
27
  if (!this.proofType) {
27
28
  throw new Error(CircuitError.InvalidProofType);
28
29
  }
29
30
  if (!this.challenge) {
30
31
  throw new Error(CircuitError.EmptyChallenge);
31
32
  }
32
- if (this.authEnabled === 1) {
33
+ if (this.isBJJAuthEnabled === 1) {
33
34
  if (!this.authClaimIncMtp) {
34
35
  throw new Error(CircuitError.EmptyAuthClaimProof);
35
36
  }
@@ -145,7 +146,7 @@ export class AtomicQueryV3OnChainInputs extends BaseConfig {
145
146
  isRevocationChecked: 1
146
147
  };
147
148
  s.challenge = this.challenge?.toString();
148
- if (this.authEnabled === 1) {
149
+ if (this.isBJJAuthEnabled === 1) {
149
150
  s.authClaim = this.authClaim?.marshalJson();
150
151
  s.userClaimsTreeRoot = this.treeState.claimsRoot?.bigInt().toString();
151
152
  s.userRevTreeRoot = this.treeState.revocationRoot?.bigInt().toString();
@@ -220,18 +221,18 @@ export class AtomicQueryV3OnChainInputs extends BaseConfig {
220
221
  s.issuerClaimNonRevMtpAuxHi = nodeAuxNonRev.key.bigInt().toString();
221
222
  s.issuerClaimNonRevMtpAuxHv = nodeAuxNonRev.value.bigInt().toString();
222
223
  s.issuerClaimNonRevMtpNoAux = nodeAuxNonRev.noAux;
223
- s.claimPathNotExists = existenceToInt(valueProof.mtp.existence);
224
224
  const nodAuxJSONLD = getNodeAuxValue(valueProof.mtp);
225
225
  s.claimPathMtpNoAux = nodAuxJSONLD.noAux;
226
226
  s.claimPathMtpAuxHi = nodAuxJSONLD.key.bigInt().toString();
227
227
  s.claimPathMtpAuxHv = nodAuxJSONLD.value.bigInt().toString();
228
228
  s.claimPathKey = valueProof.path.toString();
229
+ s.valueArraySize = this.query.values.length;
229
230
  const values = prepareCircuitArrayValues(this.query.values, this.getValueArrSize());
230
231
  s.value = bigIntArrayToStringArray(values);
231
232
  s.linkNonce = this.linkNonce.toString();
232
233
  s.verifierID = this.verifierID?.bigInt().toString() ?? '0';
233
234
  s.nullifierSessionID = this.nullifierSessionID.toString();
234
- s.authEnabled = this.authEnabled.toString();
235
+ s.isBJJAuthEnabled = this.isBJJAuthEnabled.toString();
235
236
  return byteEncoder.encode(JSON.stringify(s));
236
237
  }
237
238
  }
@@ -243,7 +244,6 @@ export class AtomicQueryV3OnChainPubSignals extends BaseConfig {
243
244
  // PubSignalsUnmarshal unmarshal credentialAtomicQueryV3.circom public signals
244
245
  pubSignalsUnmarshal(data) {
245
246
  // expected order:
246
- // merklized
247
247
  // userID
248
248
  // circuitQueryHash
249
249
  // issuerState
@@ -255,17 +255,11 @@ export class AtomicQueryV3OnChainPubSignals extends BaseConfig {
255
255
  // challenge
256
256
  // gistRoot
257
257
  // issuerID
258
- // isRevocationChecked
259
258
  // issuerClaimNonRevState
260
259
  // timestamp
261
- // verifierID
262
- // nullifierSessionID
263
- // authEnabled
260
+ // isBJJAuthEnabled
264
261
  const sVals = JSON.parse(byteDecoder.decode(data));
265
262
  let fieldIdx = 0;
266
- // -- merklized
267
- this.merklized = parseInt(sVals[fieldIdx]);
268
- fieldIdx++;
269
263
  // - userID
270
264
  this.userID = Id.fromBigInt(BigInt(sVals[fieldIdx]));
271
265
  fieldIdx++;
@@ -299,25 +293,14 @@ export class AtomicQueryV3OnChainPubSignals extends BaseConfig {
299
293
  // - issuerID
300
294
  this.issuerID = Id.fromBigInt(BigInt(sVals[fieldIdx]));
301
295
  fieldIdx++;
302
- // - isRevocationChecked
303
- this.isRevocationChecked = parseInt(sVals[fieldIdx]);
304
- fieldIdx++;
305
296
  // - issuerClaimNonRevState
306
297
  this.issuerClaimNonRevState = Hash.fromString(sVals[fieldIdx]);
307
298
  fieldIdx++;
308
299
  // - timestamp
309
300
  this.timestamp = parseInt(sVals[fieldIdx]);
310
301
  fieldIdx++;
311
- // - verifierID
312
- if (sVals[fieldIdx] !== '0') {
313
- this.verifierID = Id.fromBigInt(BigInt(sVals[fieldIdx]));
314
- }
315
- fieldIdx++;
316
- // - nullifierSessionID
317
- this.nullifierSessionID = BigInt(sVals[fieldIdx]);
318
- fieldIdx++;
319
- // - authEnabled
320
- this.authEnabled = parseInt(sVals[fieldIdx]);
302
+ // - isBJJAuthEnabled
303
+ this.isBJJAuthEnabled = parseInt(sVals[fieldIdx]);
321
304
  return this;
322
305
  }
323
306
  }
@@ -1,5 +1,5 @@
1
1
  import { Claim, Id, SchemaHash } from '@iden3/js-iden3-core';
2
- import { BaseConfig, bigIntArrayToStringArray, prepareSiblingsStr, existenceToInt, getNodeAuxValue, prepareCircuitArrayValues } from './common';
2
+ import { BaseConfig, bigIntArrayToStringArray, prepareSiblingsStr, getNodeAuxValue, prepareCircuitArrayValues } from './common';
3
3
  import { CircuitError, ValueProof } from './models';
4
4
  import { Hash, Proof, ZERO_HASH } from '@iden3/js-merkletree';
5
5
  import { byteDecoder, byteEncoder } from '../utils';
@@ -23,6 +23,7 @@ export class AtomicQueryV3Inputs extends BaseConfig {
23
23
  if (!this.query.values) {
24
24
  throw new Error(CircuitError.EmptyQueryValue);
25
25
  }
26
+ this.query.validateValueArraySize(this.getValueArrSize());
26
27
  if (!this.proofType) {
27
28
  throw new Error(CircuitError.InvalidProofType);
28
29
  }
@@ -152,12 +153,12 @@ export class AtomicQueryV3Inputs extends BaseConfig {
152
153
  s.issuerClaimNonRevMtpAuxHi = nodeAuxNonRev.key.bigInt().toString();
153
154
  s.issuerClaimNonRevMtpAuxHv = nodeAuxNonRev.value.bigInt().toString();
154
155
  s.issuerClaimNonRevMtpNoAux = nodeAuxNonRev.noAux;
155
- s.claimPathNotExists = existenceToInt(valueProof.mtp.existence);
156
156
  const nodAuxJSONLD = getNodeAuxValue(valueProof.mtp);
157
157
  s.claimPathMtpNoAux = nodAuxJSONLD.noAux;
158
158
  s.claimPathMtpAuxHi = nodAuxJSONLD.key.bigInt().toString();
159
159
  s.claimPathMtpAuxHv = nodAuxJSONLD.value.bigInt().toString();
160
160
  s.claimPathKey = valueProof.path.toString();
161
+ s.valueArraySize = this.query.values.length;
161
162
  const values = prepareCircuitArrayValues(this.query.values, this.getValueArrSize());
162
163
  s.value = bigIntArrayToStringArray(values);
163
164
  s.linkNonce = this.linkNonce.toString();
@@ -191,11 +192,11 @@ export class AtomicQueryV3PubSignals extends BaseConfig {
191
192
  // issuerClaimNonRevState
192
193
  // timestamp
193
194
  // claimSchema
194
- // claimPathNotExists
195
195
  // claimPathKey
196
196
  // slotIndex
197
197
  // operator
198
198
  // value
199
+ // valueArraySize
199
200
  // verifierID
200
201
  // nullifierSessionID
201
202
  // 19 is a number of fields in AtomicQueryV3PubSignals before values, values is last element in the proof and
@@ -246,9 +247,6 @@ export class AtomicQueryV3PubSignals extends BaseConfig {
246
247
  // - claimSchema
247
248
  this.claimSchema = SchemaHash.newSchemaHashFromInt(BigInt(sVals[fieldIdx]));
248
249
  fieldIdx++;
249
- // - ClaimPathNotExists
250
- this.claimPathNotExists = parseInt(sVals[fieldIdx]);
251
- fieldIdx++;
252
250
  // - ClaimPathKey
253
251
  this.claimPathKey = BigInt(sVals[fieldIdx]);
254
252
  fieldIdx++;
@@ -263,6 +261,9 @@ export class AtomicQueryV3PubSignals extends BaseConfig {
263
261
  this.value.push(BigInt(sVals[fieldIdx]));
264
262
  fieldIdx++;
265
263
  }
264
+ // - valueArraySize
265
+ this.valueArraySize = parseInt(sVals[fieldIdx]);
266
+ fieldIdx++;
266
267
  // - verifierID
267
268
  if (sVals[fieldIdx] !== '0') {
268
269
  this.verifierID = Id.fromBigInt(BigInt(sVals[fieldIdx]));
@@ -42,7 +42,7 @@ export class BaseConfig {
42
42
  * @returns number
43
43
  */
44
44
  getValueArrSize() {
45
- return this.valueArraySize ? this.valueArraySize : defaultValueArraySize;
45
+ return this.maxValueArraySize ? this.maxValueArraySize : defaultValueArraySize;
46
46
  }
47
47
  /**
48
48
  * getMTLevelOnChain return level on chain for given circuit
@@ -30,6 +30,8 @@ export var Operators;
30
30
  Operators[Operators["LTE"] = 7] = "LTE";
31
31
  Operators[Operators["GTE"] = 8] = "GTE";
32
32
  Operators[Operators["BETWEEN"] = 9] = "BETWEEN";
33
+ Operators[Operators["NONBETWEEN"] = 10] = "NONBETWEEN";
34
+ Operators[Operators["EXISTS"] = 11] = "EXISTS";
33
35
  Operators[Operators["SD"] = 16] = "SD";
34
36
  Operators[Operators["NULLIFY"] = 17] = "NULLIFY";
35
37
  })(Operators || (Operators = {}));
@@ -45,12 +47,17 @@ export const QueryOperators = {
45
47
  $lte: Operators.LTE,
46
48
  $gte: Operators.GTE,
47
49
  $between: Operators.BETWEEN,
50
+ $nonbetween: Operators.NONBETWEEN,
51
+ $exists: Operators.EXISTS,
48
52
  $sd: Operators.SD,
49
53
  $nullify: Operators.NULLIFY
50
54
  };
51
55
  const allOperations = Object.values(QueryOperators);
52
56
  export const availableTypesOperators = new Map([
53
- [XSDNS.Boolean, [QueryOperators.$eq, QueryOperators.$ne, QueryOperators.$sd]],
57
+ [
58
+ XSDNS.Boolean,
59
+ [QueryOperators.$eq, QueryOperators.$ne, QueryOperators.$sd, QueryOperators.$exists]
60
+ ],
54
61
  [XSDNS.Integer, allOperations],
55
62
  [XSDNS.NonNegativeInteger, allOperations],
56
63
  [XSDNS.PositiveInteger, allOperations],
@@ -61,7 +68,8 @@ export const availableTypesOperators = new Map([
61
68
  QueryOperators.$ne,
62
69
  QueryOperators.$in,
63
70
  QueryOperators.$nin,
64
- QueryOperators.$sd
71
+ QueryOperators.$sd,
72
+ QueryOperators.$exists
65
73
  ]
66
74
  ],
67
75
  [
@@ -71,7 +79,8 @@ export const availableTypesOperators = new Map([
71
79
  QueryOperators.$ne,
72
80
  QueryOperators.$in,
73
81
  QueryOperators.$nin,
74
- QueryOperators.$sd
82
+ QueryOperators.$sd,
83
+ QueryOperators.$exists
75
84
  ]
76
85
  ],
77
86
  [XSDNS.DateTime, allOperations]
@@ -162,6 +171,16 @@ export class Vector {
162
171
  return this.y.includes(this.x);
163
172
  case Operators.NIN:
164
173
  return !this.y.includes(this.x);
174
+ case Operators.BETWEEN:
175
+ if (this.y.length !== 2) {
176
+ return false;
177
+ }
178
+ return this.x >= this.y[0] && this.x <= this.y[1];
179
+ case Operators.NONBETWEEN:
180
+ if (this.y.length !== 2) {
181
+ return false;
182
+ }
183
+ return this.x < this.y[0] || this.x > this.y[1];
165
184
  default:
166
185
  throw new Error('unknown compare type for vector');
167
186
  }
@@ -187,6 +206,8 @@ export const factoryComparer = (x, y, operator) => {
187
206
  return new Scalar(x, y[0]);
188
207
  case Operators.IN:
189
208
  case Operators.NIN:
209
+ case Operators.BETWEEN:
210
+ case Operators.NONBETWEEN:
190
211
  return new Vector(x, y);
191
212
  default:
192
213
  throw new Error('unknown compare type');