@0xpolygonid/js-sdk 1.27.1 → 1.27.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -319,6 +319,10 @@ class InputGenerator {
319
319
  circuitQueries.forEach((query) => {
320
320
  this.checkOperatorSupport(proofReq.circuitId, query.operator);
321
321
  });
322
+ circuitQueries.forEach((query) => {
323
+ query.values = [circuits_1.Operators.SD, circuits_1.Operators.NOOP].includes(query.operator) ? [] : query.values;
324
+ query.valueProof = query.operator === circuits_1.Operators.NOOP ? new circuits_1.ValueProof() : query.valueProof;
325
+ });
322
326
  return circuitInputs.inputsMarshal();
323
327
  };
324
328
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StandardJSONCredentialsQueryFilter = exports.FilterQuery = exports.resolvePath = exports.comparatorOptions = exports.SearchError = void 0;
3
+ exports.StandardJSONCredentialsQueryFilter = exports.FilterQuery = exports.resolvePath = exports.comparatorOptions = exports.SupportedDataFormat = exports.SearchError = void 0;
4
4
  /**
5
5
  * search errors
6
6
  *
@@ -11,6 +11,19 @@ var SearchError;
11
11
  SearchError["NotDefinedQueryKey"] = "not defined query key";
12
12
  SearchError["NotDefinedComparator"] = "not defined comparator";
13
13
  })(SearchError = exports.SearchError || (exports.SearchError = {}));
14
+ /**
15
+ * supported data formats
16
+ *
17
+ * @enum {number}
18
+ */
19
+ var SupportedDataFormat;
20
+ (function (SupportedDataFormat) {
21
+ SupportedDataFormat[SupportedDataFormat["BigInt"] = 0] = "BigInt";
22
+ SupportedDataFormat[SupportedDataFormat["Boolean"] = 1] = "Boolean";
23
+ SupportedDataFormat[SupportedDataFormat["Double"] = 2] = "Double";
24
+ SupportedDataFormat[SupportedDataFormat["DateTime"] = 3] = "DateTime";
25
+ SupportedDataFormat[SupportedDataFormat["String"] = 4] = "String";
26
+ })(SupportedDataFormat = exports.SupportedDataFormat || (exports.SupportedDataFormat = {}));
14
27
  const truthyValues = [true, 1, 'true'];
15
28
  const falsyValues = [false, 0, 'false'];
16
29
  const equalsComparator = (a, b) => {
@@ -34,40 +47,38 @@ const equalsComparator = (a, b) => {
34
47
  return a === b;
35
48
  };
36
49
  const greaterThan = (a, b) => {
37
- if (Array.isArray(a) && Array.isArray(b)) {
38
- return a.every((val, index) => val > b[index]);
39
- }
40
- if (!Array.isArray(a) && Array.isArray(b)) {
41
- return b.every((val) => a > val);
42
- }
43
- if (Array.isArray(a) && !Array.isArray(b)) {
44
- return a.every((val) => val > b);
45
- }
46
- return a > b;
50
+ const predicate = (a, b) => {
51
+ const dataFormat = detectDataFormat(a.toString());
52
+ switch (dataFormat) {
53
+ case SupportedDataFormat.BigInt:
54
+ case SupportedDataFormat.Boolean:
55
+ return BigInt(a) > BigInt(b);
56
+ case SupportedDataFormat.DateTime:
57
+ return Date.parse(a.toString()) > Date.parse(b.toString()); /// nanoseconds won't be compared.
58
+ case SupportedDataFormat.Double:
59
+ case SupportedDataFormat.String:
60
+ default:
61
+ return a > b;
62
+ }
63
+ };
64
+ return operatorIndependentCheck(a, b, predicate);
47
65
  };
48
66
  const greaterThanOrEqual = (a, b) => {
49
- if (Array.isArray(a) && Array.isArray(b)) {
50
- return a.every((val, index) => val >= b[index]);
51
- }
52
- if (!Array.isArray(a) && Array.isArray(b)) {
53
- return b.every((val) => a >= val);
54
- }
55
- if (Array.isArray(a) && !Array.isArray(b)) {
56
- return a.every((val) => val >= b);
57
- }
58
- return a >= b;
59
- };
60
- const lessThanOrEqual = (a, b) => {
61
- if (Array.isArray(a) && Array.isArray(b)) {
62
- return a.every((val, index) => val <= b[index]);
63
- }
64
- if (!Array.isArray(a) && Array.isArray(b)) {
65
- return b.every((val) => a <= val);
66
- }
67
- if (Array.isArray(a) && !Array.isArray(b)) {
68
- return a.every((val) => val <= b);
69
- }
70
- return a <= b;
67
+ const predicate = (a, b) => {
68
+ const dataFormat = detectDataFormat(a.toString());
69
+ switch (dataFormat) {
70
+ case SupportedDataFormat.BigInt:
71
+ case SupportedDataFormat.Boolean:
72
+ return BigInt(a) >= BigInt(b);
73
+ case SupportedDataFormat.DateTime:
74
+ return Date.parse(a.toString()) >= Date.parse(b.toString()); /// nanoseconds won't be compared.
75
+ case SupportedDataFormat.Double:
76
+ case SupportedDataFormat.String:
77
+ default:
78
+ return a >= b;
79
+ }
80
+ };
81
+ return operatorIndependentCheck(a, b, predicate);
71
82
  };
72
83
  // a - field value
73
84
  // b - true / false (exists operator values)
@@ -116,7 +127,7 @@ exports.comparatorOptions = {
116
127
  $lt: (a, b) => !greaterThanOrEqual(a, b),
117
128
  $ne: (a, b) => !equalsComparator(a, b),
118
129
  $gte: (a, b) => greaterThanOrEqual(a, b),
119
- $lte: (a, b) => lessThanOrEqual(a, b),
130
+ $lte: (a, b) => !greaterThan(a, b),
120
131
  $between: (a, b) => betweenOperator(a, b),
121
132
  $nonbetween: (a, b) => !betweenOperator(a, b)
122
133
  };
@@ -233,3 +244,32 @@ const StandardJSONCredentialsQueryFilter = (query) => {
233
244
  }, []);
234
245
  };
235
246
  exports.StandardJSONCredentialsQueryFilter = StandardJSONCredentialsQueryFilter;
247
+ const operatorIndependentCheck = (a, b, predicate) => {
248
+ if (Array.isArray(a) && Array.isArray(b)) {
249
+ return a.every((val, index) => predicate(val, b[index]));
250
+ }
251
+ if (!Array.isArray(a) && Array.isArray(b)) {
252
+ return b.every((val) => predicate(a, val));
253
+ }
254
+ if (Array.isArray(a) && !Array.isArray(b)) {
255
+ return a.every((val) => predicate(val, b));
256
+ }
257
+ // in this case a and b are not arrays
258
+ return predicate(a, b);
259
+ };
260
+ const regExBigInt = /^[+-]?\d+$/;
261
+ const regExDouble = /^(-?)(0|([1-9][0-9]*))(\\.[0-9]+)?$/;
262
+ const regExDateTimeRFC3339Nano =
263
+ /* eslint-disable-next-line */
264
+ /^([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(([Zz])|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))$/;
265
+ const regExBoolean = /^(true)|(false)$/;
266
+ const regExDateTimeYYYYMMDD = /^\d{4}-\d{2}-\d{2}$/;
267
+ const detectDataFormat = (s) => regExBigInt.test(s)
268
+ ? SupportedDataFormat.BigInt
269
+ : regExDouble.test(s)
270
+ ? SupportedDataFormat.Double
271
+ : regExDateTimeRFC3339Nano.test(s) || regExDateTimeYYYYMMDD.test(s)
272
+ ? SupportedDataFormat.DateTime
273
+ : regExBoolean.test(s)
274
+ ? SupportedDataFormat.Boolean
275
+ : SupportedDataFormat.String;
@@ -316,6 +316,10 @@ export class InputGenerator {
316
316
  circuitQueries.forEach((query) => {
317
317
  this.checkOperatorSupport(proofReq.circuitId, query.operator);
318
318
  });
319
+ circuitQueries.forEach((query) => {
320
+ query.values = [Operators.SD, Operators.NOOP].includes(query.operator) ? [] : query.values;
321
+ query.valueProof = query.operator === Operators.NOOP ? new ValueProof() : query.valueProof;
322
+ });
319
323
  return circuitInputs.inputsMarshal();
320
324
  };
321
325
  }
@@ -8,6 +8,19 @@ export var SearchError;
8
8
  SearchError["NotDefinedQueryKey"] = "not defined query key";
9
9
  SearchError["NotDefinedComparator"] = "not defined comparator";
10
10
  })(SearchError || (SearchError = {}));
11
+ /**
12
+ * supported data formats
13
+ *
14
+ * @enum {number}
15
+ */
16
+ export var SupportedDataFormat;
17
+ (function (SupportedDataFormat) {
18
+ SupportedDataFormat[SupportedDataFormat["BigInt"] = 0] = "BigInt";
19
+ SupportedDataFormat[SupportedDataFormat["Boolean"] = 1] = "Boolean";
20
+ SupportedDataFormat[SupportedDataFormat["Double"] = 2] = "Double";
21
+ SupportedDataFormat[SupportedDataFormat["DateTime"] = 3] = "DateTime";
22
+ SupportedDataFormat[SupportedDataFormat["String"] = 4] = "String";
23
+ })(SupportedDataFormat || (SupportedDataFormat = {}));
11
24
  const truthyValues = [true, 1, 'true'];
12
25
  const falsyValues = [false, 0, 'false'];
13
26
  const equalsComparator = (a, b) => {
@@ -31,40 +44,38 @@ const equalsComparator = (a, b) => {
31
44
  return a === b;
32
45
  };
33
46
  const greaterThan = (a, b) => {
34
- if (Array.isArray(a) && Array.isArray(b)) {
35
- return a.every((val, index) => val > b[index]);
36
- }
37
- if (!Array.isArray(a) && Array.isArray(b)) {
38
- return b.every((val) => a > val);
39
- }
40
- if (Array.isArray(a) && !Array.isArray(b)) {
41
- return a.every((val) => val > b);
42
- }
43
- return a > b;
47
+ const predicate = (a, b) => {
48
+ const dataFormat = detectDataFormat(a.toString());
49
+ switch (dataFormat) {
50
+ case SupportedDataFormat.BigInt:
51
+ case SupportedDataFormat.Boolean:
52
+ return BigInt(a) > BigInt(b);
53
+ case SupportedDataFormat.DateTime:
54
+ return Date.parse(a.toString()) > Date.parse(b.toString()); /// nanoseconds won't be compared.
55
+ case SupportedDataFormat.Double:
56
+ case SupportedDataFormat.String:
57
+ default:
58
+ return a > b;
59
+ }
60
+ };
61
+ return operatorIndependentCheck(a, b, predicate);
44
62
  };
45
63
  const greaterThanOrEqual = (a, b) => {
46
- if (Array.isArray(a) && Array.isArray(b)) {
47
- return a.every((val, index) => val >= b[index]);
48
- }
49
- if (!Array.isArray(a) && Array.isArray(b)) {
50
- return b.every((val) => a >= val);
51
- }
52
- if (Array.isArray(a) && !Array.isArray(b)) {
53
- return a.every((val) => val >= b);
54
- }
55
- return a >= b;
56
- };
57
- const lessThanOrEqual = (a, b) => {
58
- if (Array.isArray(a) && Array.isArray(b)) {
59
- return a.every((val, index) => val <= b[index]);
60
- }
61
- if (!Array.isArray(a) && Array.isArray(b)) {
62
- return b.every((val) => a <= val);
63
- }
64
- if (Array.isArray(a) && !Array.isArray(b)) {
65
- return a.every((val) => val <= b);
66
- }
67
- return a <= b;
64
+ const predicate = (a, b) => {
65
+ const dataFormat = detectDataFormat(a.toString());
66
+ switch (dataFormat) {
67
+ case SupportedDataFormat.BigInt:
68
+ case SupportedDataFormat.Boolean:
69
+ return BigInt(a) >= BigInt(b);
70
+ case SupportedDataFormat.DateTime:
71
+ return Date.parse(a.toString()) >= Date.parse(b.toString()); /// nanoseconds won't be compared.
72
+ case SupportedDataFormat.Double:
73
+ case SupportedDataFormat.String:
74
+ default:
75
+ return a >= b;
76
+ }
77
+ };
78
+ return operatorIndependentCheck(a, b, predicate);
68
79
  };
69
80
  // a - field value
70
81
  // b - true / false (exists operator values)
@@ -113,7 +124,7 @@ export const comparatorOptions = {
113
124
  $lt: (a, b) => !greaterThanOrEqual(a, b),
114
125
  $ne: (a, b) => !equalsComparator(a, b),
115
126
  $gte: (a, b) => greaterThanOrEqual(a, b),
116
- $lte: (a, b) => lessThanOrEqual(a, b),
127
+ $lte: (a, b) => !greaterThan(a, b),
117
128
  $between: (a, b) => betweenOperator(a, b),
118
129
  $nonbetween: (a, b) => !betweenOperator(a, b)
119
130
  };
@@ -227,3 +238,32 @@ export const StandardJSONCredentialsQueryFilter = (query) => {
227
238
  }
228
239
  }, []);
229
240
  };
241
+ const operatorIndependentCheck = (a, b, predicate) => {
242
+ if (Array.isArray(a) && Array.isArray(b)) {
243
+ return a.every((val, index) => predicate(val, b[index]));
244
+ }
245
+ if (!Array.isArray(a) && Array.isArray(b)) {
246
+ return b.every((val) => predicate(a, val));
247
+ }
248
+ if (Array.isArray(a) && !Array.isArray(b)) {
249
+ return a.every((val) => predicate(val, b));
250
+ }
251
+ // in this case a and b are not arrays
252
+ return predicate(a, b);
253
+ };
254
+ const regExBigInt = /^[+-]?\d+$/;
255
+ const regExDouble = /^(-?)(0|([1-9][0-9]*))(\\.[0-9]+)?$/;
256
+ const regExDateTimeRFC3339Nano =
257
+ /* eslint-disable-next-line */
258
+ /^([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(([Zz])|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))$/;
259
+ const regExBoolean = /^(true)|(false)$/;
260
+ const regExDateTimeYYYYMMDD = /^\d{4}-\d{2}-\d{2}$/;
261
+ const detectDataFormat = (s) => regExBigInt.test(s)
262
+ ? SupportedDataFormat.BigInt
263
+ : regExDouble.test(s)
264
+ ? SupportedDataFormat.Double
265
+ : regExDateTimeRFC3339Nano.test(s) || regExDateTimeYYYYMMDD.test(s)
266
+ ? SupportedDataFormat.DateTime
267
+ : regExBoolean.test(s)
268
+ ? SupportedDataFormat.Boolean
269
+ : SupportedDataFormat.String;
@@ -8,6 +8,18 @@ export declare enum SearchError {
8
8
  NotDefinedQueryKey = "not defined query key",
9
9
  NotDefinedComparator = "not defined comparator"
10
10
  }
11
+ /**
12
+ * supported data formats
13
+ *
14
+ * @enum {number}
15
+ */
16
+ export declare enum SupportedDataFormat {
17
+ BigInt = 0,
18
+ Boolean = 1,
19
+ Double = 2,
20
+ DateTime = 3,
21
+ String = 4
22
+ }
11
23
  /** allowed operators to search */
12
24
  export type FilterOperatorMethod = '$noop' | '$eq' | '$in' | '$nin' | '$gt' | '$lt' | '$ne' | '$gte' | '$lte' | '$sd' | '$exists' | '$between' | '$nonbetween';
13
25
  /** filter function type */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xpolygonid/js-sdk",
3
- "version": "1.27.1",
3
+ "version": "1.27.3",
4
4
  "description": "SDK to work with Polygon ID",
5
5
  "main": "dist/node/cjs/index.js",
6
6
  "module": "dist/node/esm/index.js",