@0xpolygonid/js-sdk 1.9.1 → 1.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -125,12 +125,14 @@ const parseQueryMetadata = async (propertyQuery, ldContextJSON, credentialType,
125
125
  throw new Error(`field does not exist in the schema ${e.message}`);
126
126
  }
127
127
  }
128
- if (propertyQuery.operatorValue) {
128
+ if (propertyQuery.operatorValue !== undefined) {
129
129
  if (!(0, circuits_1.isValidOperation)(query.datatype, propertyQuery.operator)) {
130
130
  throw new Error(`operator ${propertyQuery.operator} is not supported for datatype ${query.datatype}`);
131
131
  }
132
- const datatype = propertyQuery.operator === circuits_1.Operators.EXISTS ? circuits_1.XSDNS.Boolean : query.datatype;
133
- query.values = await (0, exports.transformQueryValueToBigInts)(propertyQuery.operatorValue, datatype);
132
+ query.values =
133
+ propertyQuery.operator === circuits_1.Operators.EXISTS
134
+ ? transformExistsValue(propertyQuery.operatorValue)
135
+ : await (0, exports.transformQueryValueToBigInts)(propertyQuery.operatorValue, query.datatype);
134
136
  }
135
137
  return query;
136
138
  };
@@ -153,3 +155,9 @@ const transformQueryValueToBigInts = async (value, ldType) => {
153
155
  return values;
154
156
  };
155
157
  exports.transformQueryValueToBigInts = transformQueryValueToBigInts;
158
+ const transformExistsValue = (value) => {
159
+ if (typeof value == 'boolean') {
160
+ return [BigInt(value)];
161
+ }
162
+ throw new Error('exists operator value must be true or false');
163
+ };
@@ -191,10 +191,7 @@ class ProofService {
191
191
  query.valueProof = new circuits_1.ValueProof();
192
192
  query.valueProof.mtp = proof;
193
193
  query.valueProof.path = queryMetadata.claimPathKey;
194
- const mtEntry = await mtValue?.mtEntry();
195
- if (!mtEntry) {
196
- throw new Error(`can't merklize credential: no merkle tree entry found`);
197
- }
194
+ const mtEntry = (await mtValue?.mtEntry()) ?? 0n;
198
195
  query.valueProof.value = mtEntry;
199
196
  if (!queryMetadata.fieldName) {
200
197
  query.values = [mtEntry];
@@ -166,7 +166,7 @@ class FilterQuery {
166
166
  }
167
167
  const credentialPathValue = (0, exports.resolvePath)(credential, this.path);
168
168
  if ((credentialPathValue === null || credentialPathValue === undefined) &&
169
- this.operatorFunc !== existsComparator) {
169
+ this.operatorFunc !== exports.comparatorOptions.$exists) {
170
170
  return false;
171
171
  }
172
172
  if (this.isReverseParams) {
@@ -1,5 +1,5 @@
1
1
  import { Hash, Proof, ZERO_HASH } from '@iden3/js-merkletree';
2
- import { buildTreeState, isValidOperation, Operators, QueryOperators, XSDNS } from '../circuits';
2
+ import { buildTreeState, isValidOperation, Operators, QueryOperators } from '../circuits';
3
3
  import { buildFieldPath, getSerializationAttrFromContext, getFieldSlotIndex } from '../verifiable';
4
4
  import { Merklizer, Path } from '@iden3/js-jsonld-merklization';
5
5
  import { byteEncoder } from '../utils';
@@ -119,12 +119,14 @@ export const parseQueryMetadata = async (propertyQuery, ldContextJSON, credentia
119
119
  throw new Error(`field does not exist in the schema ${e.message}`);
120
120
  }
121
121
  }
122
- if (propertyQuery.operatorValue) {
122
+ if (propertyQuery.operatorValue !== undefined) {
123
123
  if (!isValidOperation(query.datatype, propertyQuery.operator)) {
124
124
  throw new Error(`operator ${propertyQuery.operator} is not supported for datatype ${query.datatype}`);
125
125
  }
126
- const datatype = propertyQuery.operator === Operators.EXISTS ? XSDNS.Boolean : query.datatype;
127
- query.values = await transformQueryValueToBigInts(propertyQuery.operatorValue, datatype);
126
+ query.values =
127
+ propertyQuery.operator === Operators.EXISTS
128
+ ? transformExistsValue(propertyQuery.operatorValue)
129
+ : await transformQueryValueToBigInts(propertyQuery.operatorValue, query.datatype);
128
130
  }
129
131
  return query;
130
132
  };
@@ -144,3 +146,9 @@ export const transformQueryValueToBigInts = async (value, ldType) => {
144
146
  }
145
147
  return values;
146
148
  };
149
+ const transformExistsValue = (value) => {
150
+ if (typeof value == 'boolean') {
151
+ return [BigInt(value)];
152
+ }
153
+ throw new Error('exists operator value must be true or false');
154
+ };
@@ -188,10 +188,7 @@ export class ProofService {
188
188
  query.valueProof = new ValueProof();
189
189
  query.valueProof.mtp = proof;
190
190
  query.valueProof.path = queryMetadata.claimPathKey;
191
- const mtEntry = await mtValue?.mtEntry();
192
- if (!mtEntry) {
193
- throw new Error(`can't merklize credential: no merkle tree entry found`);
194
- }
191
+ const mtEntry = (await mtValue?.mtEntry()) ?? 0n;
195
192
  query.valueProof.value = mtEntry;
196
193
  if (!queryMetadata.fieldName) {
197
194
  query.values = [mtEntry];
@@ -162,7 +162,7 @@ export class FilterQuery {
162
162
  }
163
163
  const credentialPathValue = resolvePath(credential, this.path);
164
164
  if ((credentialPathValue === null || credentialPathValue === undefined) &&
165
- this.operatorFunc !== existsComparator) {
165
+ this.operatorFunc !== comparatorOptions.$exists) {
166
166
  return false;
167
167
  }
168
168
  if (this.isReverseParams) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xpolygonid/js-sdk",
3
- "version": "1.9.1",
3
+ "version": "1.9.2",
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",