@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.
- package/dist/browser/esm/index.js +240 -124
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +243 -124
- package/dist/browser/umd/index.js.map +1 -1
- package/dist/node/cjs/circuits/atomic-query-v3-on-chain.js +8 -25
- package/dist/node/cjs/circuits/atomic-query-v3.js +6 -5
- package/dist/node/cjs/circuits/common.js +1 -1
- package/dist/node/cjs/circuits/comparer.js +24 -3
- package/dist/node/cjs/circuits/linked-multi-query.js +6 -17
- package/dist/node/cjs/circuits/models.js +47 -3
- package/dist/node/cjs/iden3comm/handlers/auth.js +5 -3
- package/dist/node/cjs/iden3comm/handlers/contract-request.js +3 -11
- package/dist/node/cjs/proof/common.js +11 -5
- package/dist/node/cjs/proof/provers/inputs-generator.js +6 -10
- package/dist/node/cjs/proof/verifiers/index.js +1 -0
- package/dist/node/cjs/proof/verifiers/pub-signals-verifier.js +37 -22
- package/dist/node/cjs/proof/verifiers/query-hash.js +40 -0
- package/dist/node/cjs/proof/verifiers/query.js +24 -16
- package/dist/node/cjs/schema-processor/utils.js +2 -2
- package/dist/node/cjs/storage/filters/jsonQuery.js +28 -2
- package/dist/node/cjs/verifiable/core-utils.js +3 -3
- package/dist/node/cjs/verifiable/credential.js +1 -1
- package/dist/node/esm/circuits/atomic-query-v3-on-chain.js +9 -26
- package/dist/node/esm/circuits/atomic-query-v3.js +7 -6
- package/dist/node/esm/circuits/common.js +1 -1
- package/dist/node/esm/circuits/comparer.js +24 -3
- package/dist/node/esm/circuits/linked-multi-query.js +7 -18
- package/dist/node/esm/circuits/models.js +48 -4
- package/dist/node/esm/iden3comm/handlers/auth.js +5 -3
- package/dist/node/esm/iden3comm/handlers/contract-request.js +4 -12
- package/dist/node/esm/proof/common.js +12 -6
- package/dist/node/esm/proof/provers/inputs-generator.js +7 -11
- package/dist/node/esm/proof/verifiers/index.js +1 -0
- package/dist/node/esm/proof/verifiers/pub-signals-verifier.js +41 -26
- package/dist/node/esm/proof/verifiers/query-hash.js +35 -0
- package/dist/node/esm/proof/verifiers/query.js +23 -16
- package/dist/node/esm/schema-processor/utils.js +3 -3
- package/dist/node/esm/storage/filters/jsonQuery.js +28 -2
- package/dist/node/esm/verifiable/core-utils.js +1 -1
- package/dist/node/esm/verifiable/credential.js +2 -2
- package/dist/types/circuits/atomic-query-v3-on-chain.d.ts +4 -8
- package/dist/types/circuits/atomic-query-v3.d.ts +2 -2
- package/dist/types/circuits/common.d.ts +1 -1
- package/dist/types/circuits/comparer.d.ts +4 -0
- package/dist/types/circuits/linked-multi-query.d.ts +0 -1
- package/dist/types/circuits/models.d.ts +7 -4
- package/dist/types/iden3comm/types/protocol/contract-request.d.ts +1 -0
- package/dist/types/proof/verifiers/index.d.ts +1 -0
- package/dist/types/proof/verifiers/query-hash.d.ts +3 -0
- package/dist/types/proof/verifiers/query.d.ts +1 -0
- package/dist/types/schema-processor/utils.d.ts +1 -1
- package/dist/types/storage/filters/jsonQuery.d.ts +1 -1
- package/dist/types/verifiable/core-utils.d.ts +1 -1
- package/package.json +1 -1
|
@@ -26,13 +26,14 @@ class AtomicQueryV3OnChainInputs extends common_1.BaseConfig {
|
|
|
26
26
|
if (!this.query.values) {
|
|
27
27
|
throw new Error(models_1.CircuitError.EmptyQueryValue);
|
|
28
28
|
}
|
|
29
|
+
this.query.validateValueArraySize(this.getValueArrSize());
|
|
29
30
|
if (!this.proofType) {
|
|
30
31
|
throw new Error(models_1.CircuitError.InvalidProofType);
|
|
31
32
|
}
|
|
32
33
|
if (!this.challenge) {
|
|
33
34
|
throw new Error(models_1.CircuitError.EmptyChallenge);
|
|
34
35
|
}
|
|
35
|
-
if (this.
|
|
36
|
+
if (this.isBJJAuthEnabled === 1) {
|
|
36
37
|
if (!this.authClaimIncMtp) {
|
|
37
38
|
throw new Error(models_1.CircuitError.EmptyAuthClaimProof);
|
|
38
39
|
}
|
|
@@ -148,7 +149,7 @@ class AtomicQueryV3OnChainInputs extends common_1.BaseConfig {
|
|
|
148
149
|
isRevocationChecked: 1
|
|
149
150
|
};
|
|
150
151
|
s.challenge = this.challenge?.toString();
|
|
151
|
-
if (this.
|
|
152
|
+
if (this.isBJJAuthEnabled === 1) {
|
|
152
153
|
s.authClaim = this.authClaim?.marshalJson();
|
|
153
154
|
s.userClaimsTreeRoot = this.treeState.claimsRoot?.bigInt().toString();
|
|
154
155
|
s.userRevTreeRoot = this.treeState.revocationRoot?.bigInt().toString();
|
|
@@ -223,18 +224,18 @@ class AtomicQueryV3OnChainInputs extends common_1.BaseConfig {
|
|
|
223
224
|
s.issuerClaimNonRevMtpAuxHi = nodeAuxNonRev.key.bigInt().toString();
|
|
224
225
|
s.issuerClaimNonRevMtpAuxHv = nodeAuxNonRev.value.bigInt().toString();
|
|
225
226
|
s.issuerClaimNonRevMtpNoAux = nodeAuxNonRev.noAux;
|
|
226
|
-
s.claimPathNotExists = (0, common_1.existenceToInt)(valueProof.mtp.existence);
|
|
227
227
|
const nodAuxJSONLD = (0, common_1.getNodeAuxValue)(valueProof.mtp);
|
|
228
228
|
s.claimPathMtpNoAux = nodAuxJSONLD.noAux;
|
|
229
229
|
s.claimPathMtpAuxHi = nodAuxJSONLD.key.bigInt().toString();
|
|
230
230
|
s.claimPathMtpAuxHv = nodAuxJSONLD.value.bigInt().toString();
|
|
231
231
|
s.claimPathKey = valueProof.path.toString();
|
|
232
|
+
s.valueArraySize = this.query.values.length;
|
|
232
233
|
const values = (0, common_1.prepareCircuitArrayValues)(this.query.values, this.getValueArrSize());
|
|
233
234
|
s.value = (0, common_1.bigIntArrayToStringArray)(values);
|
|
234
235
|
s.linkNonce = this.linkNonce.toString();
|
|
235
236
|
s.verifierID = this.verifierID?.bigInt().toString() ?? '0';
|
|
236
237
|
s.nullifierSessionID = this.nullifierSessionID.toString();
|
|
237
|
-
s.
|
|
238
|
+
s.isBJJAuthEnabled = this.isBJJAuthEnabled.toString();
|
|
238
239
|
return utils_1.byteEncoder.encode(JSON.stringify(s));
|
|
239
240
|
}
|
|
240
241
|
}
|
|
@@ -247,7 +248,6 @@ class AtomicQueryV3OnChainPubSignals extends common_1.BaseConfig {
|
|
|
247
248
|
// PubSignalsUnmarshal unmarshal credentialAtomicQueryV3.circom public signals
|
|
248
249
|
pubSignalsUnmarshal(data) {
|
|
249
250
|
// expected order:
|
|
250
|
-
// merklized
|
|
251
251
|
// userID
|
|
252
252
|
// circuitQueryHash
|
|
253
253
|
// issuerState
|
|
@@ -259,17 +259,11 @@ class AtomicQueryV3OnChainPubSignals extends common_1.BaseConfig {
|
|
|
259
259
|
// challenge
|
|
260
260
|
// gistRoot
|
|
261
261
|
// issuerID
|
|
262
|
-
// isRevocationChecked
|
|
263
262
|
// issuerClaimNonRevState
|
|
264
263
|
// timestamp
|
|
265
|
-
//
|
|
266
|
-
// nullifierSessionID
|
|
267
|
-
// authEnabled
|
|
264
|
+
// isBJJAuthEnabled
|
|
268
265
|
const sVals = JSON.parse(utils_1.byteDecoder.decode(data));
|
|
269
266
|
let fieldIdx = 0;
|
|
270
|
-
// -- merklized
|
|
271
|
-
this.merklized = parseInt(sVals[fieldIdx]);
|
|
272
|
-
fieldIdx++;
|
|
273
267
|
// - userID
|
|
274
268
|
this.userID = js_iden3_core_1.Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
275
269
|
fieldIdx++;
|
|
@@ -303,25 +297,14 @@ class AtomicQueryV3OnChainPubSignals extends common_1.BaseConfig {
|
|
|
303
297
|
// - issuerID
|
|
304
298
|
this.issuerID = js_iden3_core_1.Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
305
299
|
fieldIdx++;
|
|
306
|
-
// - isRevocationChecked
|
|
307
|
-
this.isRevocationChecked = parseInt(sVals[fieldIdx]);
|
|
308
|
-
fieldIdx++;
|
|
309
300
|
// - issuerClaimNonRevState
|
|
310
301
|
this.issuerClaimNonRevState = js_merkletree_1.Hash.fromString(sVals[fieldIdx]);
|
|
311
302
|
fieldIdx++;
|
|
312
303
|
// - timestamp
|
|
313
304
|
this.timestamp = parseInt(sVals[fieldIdx]);
|
|
314
305
|
fieldIdx++;
|
|
315
|
-
// -
|
|
316
|
-
|
|
317
|
-
this.verifierID = js_iden3_core_1.Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
318
|
-
}
|
|
319
|
-
fieldIdx++;
|
|
320
|
-
// - nullifierSessionID
|
|
321
|
-
this.nullifierSessionID = BigInt(sVals[fieldIdx]);
|
|
322
|
-
fieldIdx++;
|
|
323
|
-
// - authEnabled
|
|
324
|
-
this.authEnabled = parseInt(sVals[fieldIdx]);
|
|
306
|
+
// - isBJJAuthEnabled
|
|
307
|
+
this.isBJJAuthEnabled = parseInt(sVals[fieldIdx]);
|
|
325
308
|
return this;
|
|
326
309
|
}
|
|
327
310
|
}
|
|
@@ -26,6 +26,7 @@ class AtomicQueryV3Inputs extends common_1.BaseConfig {
|
|
|
26
26
|
if (!this.query.values) {
|
|
27
27
|
throw new Error(models_1.CircuitError.EmptyQueryValue);
|
|
28
28
|
}
|
|
29
|
+
this.query.validateValueArraySize(this.getValueArrSize());
|
|
29
30
|
if (!this.proofType) {
|
|
30
31
|
throw new Error(models_1.CircuitError.InvalidProofType);
|
|
31
32
|
}
|
|
@@ -155,12 +156,12 @@ class AtomicQueryV3Inputs extends common_1.BaseConfig {
|
|
|
155
156
|
s.issuerClaimNonRevMtpAuxHi = nodeAuxNonRev.key.bigInt().toString();
|
|
156
157
|
s.issuerClaimNonRevMtpAuxHv = nodeAuxNonRev.value.bigInt().toString();
|
|
157
158
|
s.issuerClaimNonRevMtpNoAux = nodeAuxNonRev.noAux;
|
|
158
|
-
s.claimPathNotExists = (0, common_1.existenceToInt)(valueProof.mtp.existence);
|
|
159
159
|
const nodAuxJSONLD = (0, common_1.getNodeAuxValue)(valueProof.mtp);
|
|
160
160
|
s.claimPathMtpNoAux = nodAuxJSONLD.noAux;
|
|
161
161
|
s.claimPathMtpAuxHi = nodAuxJSONLD.key.bigInt().toString();
|
|
162
162
|
s.claimPathMtpAuxHv = nodAuxJSONLD.value.bigInt().toString();
|
|
163
163
|
s.claimPathKey = valueProof.path.toString();
|
|
164
|
+
s.valueArraySize = this.query.values.length;
|
|
164
165
|
const values = (0, common_1.prepareCircuitArrayValues)(this.query.values, this.getValueArrSize());
|
|
165
166
|
s.value = (0, common_1.bigIntArrayToStringArray)(values);
|
|
166
167
|
s.linkNonce = this.linkNonce.toString();
|
|
@@ -195,11 +196,11 @@ class AtomicQueryV3PubSignals extends common_1.BaseConfig {
|
|
|
195
196
|
// issuerClaimNonRevState
|
|
196
197
|
// timestamp
|
|
197
198
|
// claimSchema
|
|
198
|
-
// claimPathNotExists
|
|
199
199
|
// claimPathKey
|
|
200
200
|
// slotIndex
|
|
201
201
|
// operator
|
|
202
202
|
// value
|
|
203
|
+
// valueArraySize
|
|
203
204
|
// verifierID
|
|
204
205
|
// nullifierSessionID
|
|
205
206
|
// 19 is a number of fields in AtomicQueryV3PubSignals before values, values is last element in the proof and
|
|
@@ -250,9 +251,6 @@ class AtomicQueryV3PubSignals extends common_1.BaseConfig {
|
|
|
250
251
|
// - claimSchema
|
|
251
252
|
this.claimSchema = js_iden3_core_1.SchemaHash.newSchemaHashFromInt(BigInt(sVals[fieldIdx]));
|
|
252
253
|
fieldIdx++;
|
|
253
|
-
// - ClaimPathNotExists
|
|
254
|
-
this.claimPathNotExists = parseInt(sVals[fieldIdx]);
|
|
255
|
-
fieldIdx++;
|
|
256
254
|
// - ClaimPathKey
|
|
257
255
|
this.claimPathKey = BigInt(sVals[fieldIdx]);
|
|
258
256
|
fieldIdx++;
|
|
@@ -267,6 +265,9 @@ class AtomicQueryV3PubSignals extends common_1.BaseConfig {
|
|
|
267
265
|
this.value.push(BigInt(sVals[fieldIdx]));
|
|
268
266
|
fieldIdx++;
|
|
269
267
|
}
|
|
268
|
+
// - valueArraySize
|
|
269
|
+
this.valueArraySize = parseInt(sVals[fieldIdx]);
|
|
270
|
+
fieldIdx++;
|
|
270
271
|
// - verifierID
|
|
271
272
|
if (sVals[fieldIdx] !== '0') {
|
|
272
273
|
this.verifierID = js_iden3_core_1.Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
@@ -45,7 +45,7 @@ class BaseConfig {
|
|
|
45
45
|
* @returns number
|
|
46
46
|
*/
|
|
47
47
|
getValueArrSize() {
|
|
48
|
-
return this.
|
|
48
|
+
return this.maxValueArraySize ? this.maxValueArraySize : exports.defaultValueArraySize;
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* getMTLevelOnChain return level on chain for given circuit
|
|
@@ -33,6 +33,8 @@ var Operators;
|
|
|
33
33
|
Operators[Operators["LTE"] = 7] = "LTE";
|
|
34
34
|
Operators[Operators["GTE"] = 8] = "GTE";
|
|
35
35
|
Operators[Operators["BETWEEN"] = 9] = "BETWEEN";
|
|
36
|
+
Operators[Operators["NONBETWEEN"] = 10] = "NONBETWEEN";
|
|
37
|
+
Operators[Operators["EXISTS"] = 11] = "EXISTS";
|
|
36
38
|
Operators[Operators["SD"] = 16] = "SD";
|
|
37
39
|
Operators[Operators["NULLIFY"] = 17] = "NULLIFY";
|
|
38
40
|
})(Operators = exports.Operators || (exports.Operators = {}));
|
|
@@ -48,12 +50,17 @@ exports.QueryOperators = {
|
|
|
48
50
|
$lte: Operators.LTE,
|
|
49
51
|
$gte: Operators.GTE,
|
|
50
52
|
$between: Operators.BETWEEN,
|
|
53
|
+
$nonbetween: Operators.NONBETWEEN,
|
|
54
|
+
$exists: Operators.EXISTS,
|
|
51
55
|
$sd: Operators.SD,
|
|
52
56
|
$nullify: Operators.NULLIFY
|
|
53
57
|
};
|
|
54
58
|
const allOperations = Object.values(exports.QueryOperators);
|
|
55
59
|
exports.availableTypesOperators = new Map([
|
|
56
|
-
[
|
|
60
|
+
[
|
|
61
|
+
XSDNS.Boolean,
|
|
62
|
+
[exports.QueryOperators.$eq, exports.QueryOperators.$ne, exports.QueryOperators.$sd, exports.QueryOperators.$exists]
|
|
63
|
+
],
|
|
57
64
|
[XSDNS.Integer, allOperations],
|
|
58
65
|
[XSDNS.NonNegativeInteger, allOperations],
|
|
59
66
|
[XSDNS.PositiveInteger, allOperations],
|
|
@@ -64,7 +71,8 @@ exports.availableTypesOperators = new Map([
|
|
|
64
71
|
exports.QueryOperators.$ne,
|
|
65
72
|
exports.QueryOperators.$in,
|
|
66
73
|
exports.QueryOperators.$nin,
|
|
67
|
-
exports.QueryOperators.$sd
|
|
74
|
+
exports.QueryOperators.$sd,
|
|
75
|
+
exports.QueryOperators.$exists
|
|
68
76
|
]
|
|
69
77
|
],
|
|
70
78
|
[
|
|
@@ -74,7 +82,8 @@ exports.availableTypesOperators = new Map([
|
|
|
74
82
|
exports.QueryOperators.$ne,
|
|
75
83
|
exports.QueryOperators.$in,
|
|
76
84
|
exports.QueryOperators.$nin,
|
|
77
|
-
exports.QueryOperators.$sd
|
|
85
|
+
exports.QueryOperators.$sd,
|
|
86
|
+
exports.QueryOperators.$exists
|
|
78
87
|
]
|
|
79
88
|
],
|
|
80
89
|
[XSDNS.DateTime, allOperations]
|
|
@@ -167,6 +176,16 @@ class Vector {
|
|
|
167
176
|
return this.y.includes(this.x);
|
|
168
177
|
case Operators.NIN:
|
|
169
178
|
return !this.y.includes(this.x);
|
|
179
|
+
case Operators.BETWEEN:
|
|
180
|
+
if (this.y.length !== 2) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
return this.x >= this.y[0] && this.x <= this.y[1];
|
|
184
|
+
case Operators.NONBETWEEN:
|
|
185
|
+
if (this.y.length !== 2) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
return this.x < this.y[0] || this.x > this.y[1];
|
|
170
189
|
default:
|
|
171
190
|
throw new Error('unknown compare type for vector');
|
|
172
191
|
}
|
|
@@ -193,6 +212,8 @@ const factoryComparer = (x, y, operator) => {
|
|
|
193
212
|
return new Scalar(x, y[0]);
|
|
194
213
|
case Operators.IN:
|
|
195
214
|
case Operators.NIN:
|
|
215
|
+
case Operators.BETWEEN:
|
|
216
|
+
case Operators.NONBETWEEN:
|
|
196
217
|
return new Vector(x, y);
|
|
197
218
|
default:
|
|
198
219
|
throw new Error('unknown compare type');
|
|
@@ -15,8 +15,6 @@ const models_1 = require("./models");
|
|
|
15
15
|
class LinkedMultiQueryInputs extends common_1.BaseConfig {
|
|
16
16
|
// InputsMarshal returns Circom private inputs for linkedMultiQueryInputs.circom
|
|
17
17
|
inputsMarshal() {
|
|
18
|
-
const enabled = [];
|
|
19
|
-
const claimPathNotExists = [];
|
|
20
18
|
const claimPathMtp = [];
|
|
21
19
|
const claimPathMtpNoAux = [];
|
|
22
20
|
const claimPathMtpAuxHi = [];
|
|
@@ -26,10 +24,9 @@ class LinkedMultiQueryInputs extends common_1.BaseConfig {
|
|
|
26
24
|
const slotIndex = [];
|
|
27
25
|
const operator = [];
|
|
28
26
|
const value = [];
|
|
27
|
+
const valueArraySize = [];
|
|
29
28
|
for (let i = 0; i < LinkedMultiQueryInputs.queryCount; i++) {
|
|
30
29
|
if (!this.query[i]) {
|
|
31
|
-
enabled.push(0);
|
|
32
|
-
claimPathNotExists.push(0);
|
|
33
30
|
claimPathMtp.push(new Array(this.getMTLevelsClaim()).fill('0'));
|
|
34
31
|
claimPathMtpNoAux.push('0');
|
|
35
32
|
claimPathMtpAuxHi.push('0');
|
|
@@ -40,9 +37,9 @@ class LinkedMultiQueryInputs extends common_1.BaseConfig {
|
|
|
40
37
|
operator.push(0);
|
|
41
38
|
const valuesArr = (0, common_1.prepareCircuitArrayValues)([], this.getValueArrSize());
|
|
42
39
|
value.push((0, common_1.bigIntArrayToStringArray)(valuesArr));
|
|
40
|
+
valueArraySize.push(0);
|
|
43
41
|
continue;
|
|
44
42
|
}
|
|
45
|
-
enabled.push(1);
|
|
46
43
|
let valueProof = this.query[i].valueProof;
|
|
47
44
|
if (!valueProof) {
|
|
48
45
|
valueProof = new models_1.ValueProof();
|
|
@@ -50,7 +47,6 @@ class LinkedMultiQueryInputs extends common_1.BaseConfig {
|
|
|
50
47
|
valueProof.value = 0n;
|
|
51
48
|
valueProof.mtp = new js_merkletree_1.Proof();
|
|
52
49
|
}
|
|
53
|
-
claimPathNotExists.push((0, common_1.existenceToInt)(valueProof.mtp.existence));
|
|
54
50
|
claimPathMtp.push((0, common_1.prepareSiblingsStr)(valueProof.mtp, this.getMTLevelsClaim()));
|
|
55
51
|
const nodAuxJSONLD = (0, common_1.getNodeAuxValue)(valueProof.mtp);
|
|
56
52
|
claimPathMtpNoAux.push(nodAuxJSONLD.noAux);
|
|
@@ -60,15 +56,14 @@ class LinkedMultiQueryInputs extends common_1.BaseConfig {
|
|
|
60
56
|
claimPathValue.push(valueProof.value.toString());
|
|
61
57
|
slotIndex.push(this.query[i].slotIndex);
|
|
62
58
|
operator.push(this.query[i].operator);
|
|
59
|
+
valueArraySize.push(this.query[i].values.length);
|
|
63
60
|
const valuesArr = (0, common_1.prepareCircuitArrayValues)(this.query[i].values, this.getValueArrSize());
|
|
64
61
|
value.push((0, common_1.bigIntArrayToStringArray)(valuesArr));
|
|
65
62
|
}
|
|
66
63
|
const s = {
|
|
67
64
|
linkNonce: this.linkNonce.toString(),
|
|
68
65
|
issuerClaim: this.claim.marshalJson(),
|
|
69
|
-
enabled,
|
|
70
66
|
claimSchema: this.claim.getSchemaHash().bigInt().toString(),
|
|
71
|
-
claimPathNotExists,
|
|
72
67
|
claimPathMtp,
|
|
73
68
|
claimPathMtpNoAux,
|
|
74
69
|
claimPathMtpAuxHi,
|
|
@@ -77,7 +72,8 @@ class LinkedMultiQueryInputs extends common_1.BaseConfig {
|
|
|
77
72
|
claimPathValue,
|
|
78
73
|
slotIndex,
|
|
79
74
|
operator,
|
|
80
|
-
value
|
|
75
|
+
value,
|
|
76
|
+
valueArraySize
|
|
81
77
|
};
|
|
82
78
|
return utils_1.byteEncoder.encode(JSON.stringify(s));
|
|
83
79
|
}
|
|
@@ -100,7 +96,7 @@ class LinkedMultiQueryPubSignals {
|
|
|
100
96
|
* @returns LinkedMultiQueryPubSignals
|
|
101
97
|
*/
|
|
102
98
|
pubSignalsUnmarshal(data) {
|
|
103
|
-
const len =
|
|
99
|
+
const len = 22;
|
|
104
100
|
const queryLength = LinkedMultiQueryInputs.queryCount;
|
|
105
101
|
const sVals = JSON.parse(utils_1.byteDecoder.decode(data));
|
|
106
102
|
if (sVals.length !== len) {
|
|
@@ -125,13 +121,6 @@ class LinkedMultiQueryPubSignals {
|
|
|
125
121
|
this.circuitQueryHash.push(BigInt(sVals[fieldIdx]));
|
|
126
122
|
fieldIdx++;
|
|
127
123
|
}
|
|
128
|
-
// - enabled
|
|
129
|
-
this.enabled = [];
|
|
130
|
-
for (let i = 0; i < queryLength; i++) {
|
|
131
|
-
const enabledNum = parseInt(sVals[fieldIdx]);
|
|
132
|
-
this.enabled.push(enabledNum === 1);
|
|
133
|
-
fieldIdx++;
|
|
134
|
-
}
|
|
135
124
|
return this;
|
|
136
125
|
}
|
|
137
126
|
}
|
|
@@ -20,6 +20,48 @@ class Query {
|
|
|
20
20
|
this.values?.some((v) => typeof v !== 'bigint'))
|
|
21
21
|
throw new Error(CircuitError.EmptyQueryValue);
|
|
22
22
|
}
|
|
23
|
+
validateValueArraySize(maxArrSize) {
|
|
24
|
+
switch (this.values.length) {
|
|
25
|
+
case 0: {
|
|
26
|
+
const zeroArrSizeOps = [comparer_1.Operators.NOOP, comparer_1.Operators.SD, comparer_1.Operators.NULLIFY];
|
|
27
|
+
if (!zeroArrSizeOps.includes(this.operator)) {
|
|
28
|
+
throw new Error(CircuitError.InvalidValuesArrSize);
|
|
29
|
+
}
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
case 1: {
|
|
33
|
+
const oneArrSizeOps = [
|
|
34
|
+
comparer_1.Operators.EQ,
|
|
35
|
+
comparer_1.Operators.LT,
|
|
36
|
+
comparer_1.Operators.GT,
|
|
37
|
+
comparer_1.Operators.NE,
|
|
38
|
+
comparer_1.Operators.LTE,
|
|
39
|
+
comparer_1.Operators.GTE,
|
|
40
|
+
comparer_1.Operators.EXISTS
|
|
41
|
+
];
|
|
42
|
+
if (!oneArrSizeOps.includes(this.operator)) {
|
|
43
|
+
throw new Error(CircuitError.InvalidValuesArrSize);
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
case 2: {
|
|
48
|
+
const twoArrSizeOps = [comparer_1.Operators.BETWEEN, comparer_1.Operators.NONBETWEEN];
|
|
49
|
+
if (!twoArrSizeOps.includes(this.operator)) {
|
|
50
|
+
throw new Error(CircuitError.InvalidValuesArrSize);
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
default: {
|
|
55
|
+
const maxArrSizeOps = [comparer_1.Operators.IN, comparer_1.Operators.NIN];
|
|
56
|
+
if (!maxArrSizeOps.includes(this.operator)) {
|
|
57
|
+
throw new Error(CircuitError.InvalidOperationType);
|
|
58
|
+
}
|
|
59
|
+
if (!this.values.length || this.values.length > maxArrSize) {
|
|
60
|
+
throw new Error(CircuitError.InvalidValuesArrSize);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
23
65
|
}
|
|
24
66
|
exports.Query = Query;
|
|
25
67
|
/**
|
|
@@ -45,17 +87,17 @@ var CircuitId;
|
|
|
45
87
|
* @beta
|
|
46
88
|
*/
|
|
47
89
|
// AtomicQueryV3CircuitID is a type for credentialAtomicQueryV3.circom
|
|
48
|
-
CircuitId["AtomicQueryV3"] = "credentialAtomicQueryV3-beta.
|
|
90
|
+
CircuitId["AtomicQueryV3"] = "credentialAtomicQueryV3-beta.1";
|
|
49
91
|
/**
|
|
50
92
|
* @beta
|
|
51
93
|
*/
|
|
52
94
|
// AtomicQueryV3OnChainCircuitID is a type for credentialAtomicQueryV3OnChain.circom
|
|
53
|
-
CircuitId["AtomicQueryV3OnChain"] = "credentialAtomicQueryV3OnChain-beta.
|
|
95
|
+
CircuitId["AtomicQueryV3OnChain"] = "credentialAtomicQueryV3OnChain-beta.1";
|
|
54
96
|
/**
|
|
55
97
|
* @beta
|
|
56
98
|
*/
|
|
57
99
|
// LinkedMultiQuery is a type for linkedMultiQuery.circom
|
|
58
|
-
CircuitId["LinkedMultiQuery10"] = "linkedMultiQuery10-beta.
|
|
100
|
+
CircuitId["LinkedMultiQuery10"] = "linkedMultiQuery10-beta.1";
|
|
59
101
|
})(CircuitId = exports.CircuitId || (exports.CircuitId = {}));
|
|
60
102
|
/**
|
|
61
103
|
* Claim structure for circuit inputs
|
|
@@ -93,6 +135,8 @@ var CircuitError;
|
|
|
93
135
|
CircuitError["EmptyTreeState"] = "empty tree state";
|
|
94
136
|
CircuitError["EmptyRequestID"] = "empty request ID";
|
|
95
137
|
CircuitError["InvalidProofType"] = "invalid proof type";
|
|
138
|
+
CircuitError["InvalidValuesArrSize"] = "invalid query Values array size";
|
|
139
|
+
CircuitError["InvalidOperationType"] = "invalid operation type";
|
|
96
140
|
})(CircuitError = exports.CircuitError || (exports.CircuitError = {}));
|
|
97
141
|
/**
|
|
98
142
|
* ValueProof represents a Merkle Proof for a value stored as MT
|
|
@@ -97,6 +97,7 @@ class AuthHandler {
|
|
|
97
97
|
if (message.type !== constants_2.PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_REQUEST_MESSAGE_TYPE) {
|
|
98
98
|
throw new Error('Invalid media type');
|
|
99
99
|
}
|
|
100
|
+
authRequest.body.scope = authRequest.body.scope || [];
|
|
100
101
|
return authRequest;
|
|
101
102
|
}
|
|
102
103
|
/**
|
|
@@ -208,7 +209,8 @@ class AuthHandler {
|
|
|
208
209
|
throw new Error(`sender of the request is not a target of response - expected ${request.from}, given ${response.to}`);
|
|
209
210
|
}
|
|
210
211
|
this.verifyAuthRequest(request);
|
|
211
|
-
const requestScope = request.body.scope;
|
|
212
|
+
const requestScope = request.body.scope || [];
|
|
213
|
+
const responseScope = response.body.scope || [];
|
|
212
214
|
if (!response.from) {
|
|
213
215
|
throw new Error(`proof response doesn't contain from field`);
|
|
214
216
|
}
|
|
@@ -216,7 +218,7 @@ class AuthHandler {
|
|
|
216
218
|
// group requests by query group id
|
|
217
219
|
for (const proofRequest of requestScope) {
|
|
218
220
|
const groupId = proofRequest.query.groupId;
|
|
219
|
-
const proofResp =
|
|
221
|
+
const proofResp = responseScope.find((resp) => resp.id === proofRequest.id);
|
|
220
222
|
if (!proofResp) {
|
|
221
223
|
throw new Error(`proof is not given for requestId ${proofRequest.id}`);
|
|
222
224
|
}
|
|
@@ -252,7 +254,7 @@ class AuthHandler {
|
|
|
252
254
|
}
|
|
253
255
|
verifyAuthRequest(request) {
|
|
254
256
|
const groupIdValidationMap = {};
|
|
255
|
-
const requestScope = request.body.scope;
|
|
257
|
+
const requestScope = request.body.scope || [];
|
|
256
258
|
for (const proofRequest of requestScope) {
|
|
257
259
|
const groupId = proofRequest.query.groupId;
|
|
258
260
|
if (groupId) {
|
|
@@ -4,7 +4,6 @@ exports.ContractRequestHandler = void 0;
|
|
|
4
4
|
const models_1 = require("../../circuits/models");
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
6
|
const js_iden3_core_1 = require("@iden3/js-iden3-core");
|
|
7
|
-
const utils_1 = require("../../utils");
|
|
8
7
|
/**
|
|
9
8
|
*
|
|
10
9
|
* Allows to process ContractInvokeRequest protocol message
|
|
@@ -44,6 +43,7 @@ class ContractRequestHandler {
|
|
|
44
43
|
if (message.type !== constants_1.PROTOCOL_MESSAGE_TYPE.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE) {
|
|
45
44
|
throw new Error('Invalid media type');
|
|
46
45
|
}
|
|
46
|
+
ciRequest.body.scope = ciRequest.body.scope || [];
|
|
47
47
|
return ciRequest;
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
@@ -63,19 +63,11 @@ class ContractRequestHandler {
|
|
|
63
63
|
throw new Error("Can't sign transaction. Provide Signer in options.");
|
|
64
64
|
}
|
|
65
65
|
const zkRequests = [];
|
|
66
|
-
const {
|
|
66
|
+
const { chain_id } = ciRequest.body.transaction_data;
|
|
67
67
|
const networkFlag = Object.keys(js_iden3_core_1.ChainIds).find((key) => js_iden3_core_1.ChainIds[key] === chain_id);
|
|
68
68
|
if (!networkFlag) {
|
|
69
69
|
throw new Error(`Invalid chain id ${chain_id}`);
|
|
70
70
|
}
|
|
71
|
-
const [blockchain, networkId] = networkFlag.split(':');
|
|
72
|
-
const verifierId = (0, utils_1.buildVerifierId)(contract_address, {
|
|
73
|
-
blockchain,
|
|
74
|
-
networkId,
|
|
75
|
-
// 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.
|
|
76
|
-
method: js_iden3_core_1.DidMethod.Iden3
|
|
77
|
-
});
|
|
78
|
-
const verifierDid = js_iden3_core_1.DID.parseFromId(verifierId);
|
|
79
71
|
for (const proofReq of ciRequest.body.scope) {
|
|
80
72
|
if (!this._allowedCircuits.includes(proofReq.circuitId)) {
|
|
81
73
|
throw new Error(`Can't handle circuit ${proofReq.circuitId}. Only onchain circuits are allowed.`);
|
|
@@ -84,7 +76,7 @@ class ContractRequestHandler {
|
|
|
84
76
|
const zkpRes = await this._proofService.generateProof(proofReq, did, {
|
|
85
77
|
skipRevocation: query.skipClaimRevocationCheck ?? false,
|
|
86
78
|
challenge: opts.challenge,
|
|
87
|
-
verifierDid
|
|
79
|
+
verifierDid: ciRequest.from ? js_iden3_core_1.DID.parse(ciRequest.from) : undefined
|
|
88
80
|
});
|
|
89
81
|
zkRequests.push(zkpRes);
|
|
90
82
|
}
|
|
@@ -90,16 +90,21 @@ const parseCredentialSubject = (credentialSubject) => {
|
|
|
90
90
|
};
|
|
91
91
|
exports.parseCredentialSubject = parseCredentialSubject;
|
|
92
92
|
const parseQueryMetadata = async (propertyQuery, ldContextJSON, credentialType, options) => {
|
|
93
|
-
const datatype = await js_jsonld_merklization_1.Path.newTypeFromContext(ldContextJSON, `${credentialType}.${propertyQuery.fieldName}`, options);
|
|
94
93
|
const query = {
|
|
95
94
|
...propertyQuery,
|
|
96
95
|
slotIndex: 0,
|
|
97
96
|
merklizedSchema: false,
|
|
98
|
-
datatype:
|
|
97
|
+
datatype: '',
|
|
99
98
|
claimPathKey: BigInt(0),
|
|
100
99
|
values: [],
|
|
101
100
|
path: new js_jsonld_merklization_1.Path()
|
|
102
101
|
};
|
|
102
|
+
if (!propertyQuery.fieldName && propertyQuery.operator !== circuits_1.Operators.NOOP) {
|
|
103
|
+
throw new Error('query must have a field name if operator is not $noop');
|
|
104
|
+
}
|
|
105
|
+
if (propertyQuery.fieldName) {
|
|
106
|
+
query.datatype = await js_jsonld_merklization_1.Path.newTypeFromContext(ldContextJSON, `${credentialType}.${propertyQuery.fieldName}`, options);
|
|
107
|
+
}
|
|
103
108
|
const serAttr = await (0, verifiable_1.getSerializationAttrFromContext)(JSON.parse(ldContextJSON), options, credentialType);
|
|
104
109
|
if (!serAttr) {
|
|
105
110
|
query.merklizedSchema = true;
|
|
@@ -121,9 +126,10 @@ const parseQueryMetadata = async (propertyQuery, ldContextJSON, credentialType,
|
|
|
121
126
|
}
|
|
122
127
|
}
|
|
123
128
|
if (propertyQuery.operatorValue) {
|
|
124
|
-
if (!(0, circuits_1.isValidOperation)(datatype, propertyQuery.operator)) {
|
|
125
|
-
throw new Error(`operator ${propertyQuery.operator} is not supported for datatype ${datatype}`);
|
|
129
|
+
if (!(0, circuits_1.isValidOperation)(query.datatype, propertyQuery.operator)) {
|
|
130
|
+
throw new Error(`operator ${propertyQuery.operator} is not supported for datatype ${query.datatype}`);
|
|
126
131
|
}
|
|
132
|
+
const datatype = propertyQuery.operator === circuits_1.Operators.EXISTS ? circuits_1.XSDNS.Boolean : query.datatype;
|
|
127
133
|
query.values = await (0, exports.transformQueryValueToBigInts)(propertyQuery.operatorValue, datatype);
|
|
128
134
|
}
|
|
129
135
|
return query;
|
|
@@ -135,7 +141,7 @@ const parseQueriesMetadata = async (credentialType, ldContextJSON, credentialSub
|
|
|
135
141
|
};
|
|
136
142
|
exports.parseQueriesMetadata = parseQueriesMetadata;
|
|
137
143
|
const transformQueryValueToBigInts = async (value, ldType) => {
|
|
138
|
-
const values =
|
|
144
|
+
const values = [];
|
|
139
145
|
if (Array.isArray(value)) {
|
|
140
146
|
for (let index = 0; index < value.length; index++) {
|
|
141
147
|
values[index] = await js_jsonld_merklization_1.Merklizer.hashValue(ldType, value[index]);
|
|
@@ -205,10 +205,8 @@ class InputGenerator {
|
|
|
205
205
|
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
206
206
|
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
207
207
|
const query = circuitQueries[0];
|
|
208
|
-
query.values =
|
|
209
|
-
|
|
210
|
-
? new Array(circuits_1.defaultValueArraySize).fill(0)
|
|
211
|
-
: query.values;
|
|
208
|
+
query.values = [circuits_1.Operators.SD, circuits_1.Operators.NOOP].includes(query.operator) ? [] : query.values;
|
|
209
|
+
query.valueProof = query.operator === circuits_1.Operators.NOOP ? new circuits_1.ValueProof() : query.valueProof;
|
|
212
210
|
circuitInputs.query = query;
|
|
213
211
|
circuitInputs.currentTimeStamp = (0, js_iden3_core_1.getUnixTimestamp)(new Date());
|
|
214
212
|
circuitInputs.proofType = proofType;
|
|
@@ -256,10 +254,8 @@ class InputGenerator {
|
|
|
256
254
|
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
257
255
|
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
258
256
|
const query = circuitQueries[0];
|
|
259
|
-
query.values =
|
|
260
|
-
|
|
261
|
-
? new Array(circuits_1.defaultValueArraySize).fill(0)
|
|
262
|
-
: query.values;
|
|
257
|
+
query.values = [circuits_1.Operators.SD, circuits_1.Operators.NOOP].includes(query.operator) ? [] : query.values;
|
|
258
|
+
query.valueProof = query.operator === circuits_1.Operators.NOOP ? new circuits_1.ValueProof() : query.valueProof;
|
|
263
259
|
circuitInputs.query = query;
|
|
264
260
|
circuitInputs.currentTimeStamp = (0, js_iden3_core_1.getUnixTimestamp)(new Date());
|
|
265
261
|
circuitInputs.proofType = proofType;
|
|
@@ -275,7 +271,7 @@ class InputGenerator {
|
|
|
275
271
|
catch {
|
|
276
272
|
isEthIdentity = false;
|
|
277
273
|
}
|
|
278
|
-
circuitInputs.
|
|
274
|
+
circuitInputs.isBJJAuthEnabled = isEthIdentity ? 0 : 1;
|
|
279
275
|
circuitInputs.challenge = BigInt(params.challenge ?? 0);
|
|
280
276
|
const { nonce: authProfileNonce, genesisDID } = await this._identityWallet.getGenesisDIDMetadata(identifier);
|
|
281
277
|
const id = js_iden3_core_1.DID.idFromDID(genesisDID);
|
|
@@ -283,7 +279,7 @@ class InputGenerator {
|
|
|
283
279
|
const gistProof = (0, common_1.toGISTProof)(stateProof);
|
|
284
280
|
circuitInputs.gistProof = gistProof;
|
|
285
281
|
// auth inputs
|
|
286
|
-
if (circuitInputs.
|
|
282
|
+
if (circuitInputs.isBJJAuthEnabled === 1) {
|
|
287
283
|
const authPrepared = await this.prepareAuthBJJCredential(genesisDID);
|
|
288
284
|
const authClaimData = await this.newCircuitClaimData({
|
|
289
285
|
credential: authPrepared.credential,
|
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./pub-signals-verifier"), exports);
|
|
18
18
|
__exportStar(require("./query"), exports);
|
|
19
|
+
__exportStar(require("./query-hash"), exports);
|