@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.
- package/dist/browser/esm/index.js +420 -189
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +425 -189
- 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 +14 -55
- package/dist/node/cjs/iden3comm/handlers/common.js +85 -0
- package/dist/node/cjs/iden3comm/handlers/contract-request.js +6 -25
- package/dist/node/cjs/iden3comm/handlers/index.js +2 -0
- package/dist/node/cjs/iden3comm/handlers/revocation-status.js +119 -0
- package/dist/node/cjs/identity/identity-wallet.js +4 -0
- 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 +15 -56
- package/dist/node/esm/iden3comm/handlers/common.js +81 -0
- package/dist/node/esm/iden3comm/handlers/contract-request.js +7 -26
- package/dist/node/esm/iden3comm/handlers/index.js +2 -0
- package/dist/node/esm/iden3comm/handlers/revocation-status.js +92 -0
- package/dist/node/esm/identity/identity-wallet.js +4 -0
- 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/handlers/auth.d.ts +1 -0
- package/dist/types/iden3comm/handlers/common.d.ts +23 -0
- package/dist/types/iden3comm/handlers/contract-request.d.ts +1 -1
- package/dist/types/iden3comm/handlers/index.d.ts +2 -0
- package/dist/types/iden3comm/handlers/revocation-status.d.ts +59 -0
- package/dist/types/iden3comm/types/protocol/contract-request.d.ts +1 -0
- package/dist/types/identity/identity-wallet.d.ts +13 -1
- 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/dist/types/verifiable/credential.d.ts +1 -1
- package/dist/types/verifiable/proof.d.ts +5 -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
|
|
@@ -30,7 +30,8 @@ const js_iden3_core_1 = require("@iden3/js-iden3-core");
|
|
|
30
30
|
const js_jwz_1 = require("@iden3/js-jwz");
|
|
31
31
|
const uuid = __importStar(require("uuid"));
|
|
32
32
|
const utils_1 = require("../../utils");
|
|
33
|
-
const
|
|
33
|
+
const common_1 = require("./common");
|
|
34
|
+
const circuits_1 = require("../../circuits");
|
|
34
35
|
/**
|
|
35
36
|
* createAuthorizationRequest is a function to create protocol authorization request
|
|
36
37
|
* @param {string} reason - reason to request proof
|
|
@@ -87,6 +88,12 @@ class AuthHandler {
|
|
|
87
88
|
constructor(_packerMgr, _proofService) {
|
|
88
89
|
this._packerMgr = _packerMgr;
|
|
89
90
|
this._proofService = _proofService;
|
|
91
|
+
this._supportedCircuits = [
|
|
92
|
+
circuits_1.CircuitId.AtomicQueryV3,
|
|
93
|
+
circuits_1.CircuitId.AtomicQuerySigV2,
|
|
94
|
+
circuits_1.CircuitId.AtomicQueryMTPV2,
|
|
95
|
+
circuits_1.CircuitId.LinkedMultiQuery10
|
|
96
|
+
];
|
|
90
97
|
}
|
|
91
98
|
/**
|
|
92
99
|
* @inheritdoc IAuthHandler#parseAuthorizationRequest
|
|
@@ -121,6 +128,11 @@ class AuthHandler {
|
|
|
121
128
|
did = js_iden3_core_1.DID.parse(authRequest.to);
|
|
122
129
|
}
|
|
123
130
|
const guid = uuid.v4();
|
|
131
|
+
if (!authRequest.from) {
|
|
132
|
+
throw new Error('auth request should contain from field');
|
|
133
|
+
}
|
|
134
|
+
const from = js_iden3_core_1.DID.parse(authRequest.from);
|
|
135
|
+
const responseScope = await (0, common_1.processZeroKnowledgeProofRequests)(did, authRequest?.body.scope, from, this._proofService, { ...opts, supportedCircuits: this._supportedCircuits });
|
|
124
136
|
const authResponse = {
|
|
125
137
|
id: guid,
|
|
126
138
|
typ: opts.mediaType,
|
|
@@ -128,64 +140,11 @@ class AuthHandler {
|
|
|
128
140
|
thid: authRequest.thid ?? guid,
|
|
129
141
|
body: {
|
|
130
142
|
message: authRequest?.body?.message,
|
|
131
|
-
scope:
|
|
143
|
+
scope: responseScope
|
|
132
144
|
},
|
|
133
145
|
from: did.string(),
|
|
134
146
|
to: authRequest.from
|
|
135
147
|
};
|
|
136
|
-
const requestScope = authRequest.body.scope;
|
|
137
|
-
const combinedQueries = requestScope.reduce((acc, proofReq) => {
|
|
138
|
-
const groupId = proofReq.query.groupId;
|
|
139
|
-
if (!groupId) {
|
|
140
|
-
return acc;
|
|
141
|
-
}
|
|
142
|
-
const existedData = acc.get(groupId);
|
|
143
|
-
if (!existedData) {
|
|
144
|
-
const seed = (0, js_crypto_1.getRandomBytes)(12);
|
|
145
|
-
const dataView = new DataView(seed.buffer);
|
|
146
|
-
const linkNonce = dataView.getUint32(0);
|
|
147
|
-
acc.set(groupId, { query: proofReq.query, linkNonce });
|
|
148
|
-
return acc;
|
|
149
|
-
}
|
|
150
|
-
const credentialSubject = (0, utils_1.mergeObjects)(existedData.query.credentialSubject, proofReq.query.credentialSubject);
|
|
151
|
-
acc.set(groupId, {
|
|
152
|
-
...existedData,
|
|
153
|
-
query: {
|
|
154
|
-
skipClaimRevocationCheck: existedData.query.skipClaimRevocationCheck || proofReq.query.skipClaimRevocationCheck,
|
|
155
|
-
...existedData.query,
|
|
156
|
-
credentialSubject
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
return acc;
|
|
160
|
-
}, new Map());
|
|
161
|
-
const groupedCredentialsCache = new Map();
|
|
162
|
-
for (const proofReq of requestScope) {
|
|
163
|
-
const query = proofReq.query;
|
|
164
|
-
const groupId = query.groupId;
|
|
165
|
-
const combinedQueryData = combinedQueries.get(groupId);
|
|
166
|
-
if (groupId) {
|
|
167
|
-
if (!combinedQueryData) {
|
|
168
|
-
throw new Error(`Invalid group id ${query.groupId}`);
|
|
169
|
-
}
|
|
170
|
-
const combinedQuery = combinedQueryData.query;
|
|
171
|
-
if (!groupedCredentialsCache.has(groupId)) {
|
|
172
|
-
const credWithRevStatus = await this._proofService.findCredentialByProofQuery(did, combinedQueryData.query);
|
|
173
|
-
if (!credWithRevStatus.cred) {
|
|
174
|
-
throw new Error(`Credential not found for query ${JSON.stringify(combinedQuery)}`);
|
|
175
|
-
}
|
|
176
|
-
groupedCredentialsCache.set(groupId, credWithRevStatus);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
const credWithRevStatus = groupedCredentialsCache.get(groupId);
|
|
180
|
-
const zkpRes = await this._proofService.generateProof(proofReq, did, {
|
|
181
|
-
verifierDid: js_iden3_core_1.DID.parse(authRequest.from),
|
|
182
|
-
skipRevocation: Boolean(query.skipClaimRevocationCheck),
|
|
183
|
-
credential: credWithRevStatus?.cred,
|
|
184
|
-
credentialRevocationStatus: credWithRevStatus?.revStatus,
|
|
185
|
-
linkNonce: combinedQueryData?.linkNonce ? BigInt(combinedQueryData.linkNonce) : undefined
|
|
186
|
-
});
|
|
187
|
-
authResponse.body.scope.push(zkpRes);
|
|
188
|
-
}
|
|
189
148
|
const msgBytes = utils_1.byteEncoder.encode(JSON.stringify(authResponse));
|
|
190
149
|
const packerOpts = opts.mediaType === constants_1.MediaType.SignedMessage
|
|
191
150
|
? opts.packerOptions
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processZeroKnowledgeProofRequests = void 0;
|
|
4
|
+
const js_crypto_1 = require("@iden3/js-crypto");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
/**
|
|
7
|
+
* Groups the ZeroKnowledgeProofRequest objects based on their groupId.
|
|
8
|
+
* Returns a Map where the key is the groupId and the value is an object containing the query and linkNonce.
|
|
9
|
+
*
|
|
10
|
+
* @param requestScope - An array of ZeroKnowledgeProofRequest objects.
|
|
11
|
+
* @returns A Map<number, { query: JSONObject; linkNonce: number }> representing the grouped queries.
|
|
12
|
+
*/
|
|
13
|
+
const getGroupedQueries = (requestScope) => requestScope.reduce((acc, proofReq) => {
|
|
14
|
+
const groupId = proofReq.query.groupId;
|
|
15
|
+
if (!groupId) {
|
|
16
|
+
return acc;
|
|
17
|
+
}
|
|
18
|
+
const existedData = acc.get(groupId);
|
|
19
|
+
if (!existedData) {
|
|
20
|
+
const seed = (0, js_crypto_1.getRandomBytes)(12);
|
|
21
|
+
const dataView = new DataView(seed.buffer);
|
|
22
|
+
const linkNonce = dataView.getUint32(0);
|
|
23
|
+
acc.set(groupId, { query: proofReq.query, linkNonce });
|
|
24
|
+
return acc;
|
|
25
|
+
}
|
|
26
|
+
const credentialSubject = (0, utils_1.mergeObjects)(existedData.query.credentialSubject, proofReq.query.credentialSubject);
|
|
27
|
+
acc.set(groupId, {
|
|
28
|
+
...existedData,
|
|
29
|
+
query: {
|
|
30
|
+
skipClaimRevocationCheck: existedData.query.skipClaimRevocationCheck || proofReq.query.skipClaimRevocationCheck,
|
|
31
|
+
...existedData.query,
|
|
32
|
+
credentialSubject
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return acc;
|
|
36
|
+
}, new Map());
|
|
37
|
+
/**
|
|
38
|
+
* Processes zero knowledge proof requests.
|
|
39
|
+
*
|
|
40
|
+
* @param senderIdentifier - The identifier of the sender.
|
|
41
|
+
* @param requests - An array of zero knowledge proof requests.
|
|
42
|
+
* @param from - The identifier of the sender.
|
|
43
|
+
* @param proofService - The proof service.
|
|
44
|
+
* @param opts - Additional options for processing the requests.
|
|
45
|
+
* @returns A promise that resolves to an array of zero knowledge proof responses.
|
|
46
|
+
*/
|
|
47
|
+
const processZeroKnowledgeProofRequests = async (senderIdentifier, requests, from, proofService, opts) => {
|
|
48
|
+
const requestScope = requests ?? [];
|
|
49
|
+
const combinedQueries = getGroupedQueries(requestScope);
|
|
50
|
+
const groupedCredentialsCache = new Map();
|
|
51
|
+
const zkpResponses = [];
|
|
52
|
+
for (const proofReq of requestScope) {
|
|
53
|
+
if (!opts.supportedCircuits.includes(proofReq.circuitId)) {
|
|
54
|
+
throw new Error(`Circuit ${proofReq.circuitId} is not allowed`);
|
|
55
|
+
}
|
|
56
|
+
const query = proofReq.query;
|
|
57
|
+
const groupId = query.groupId;
|
|
58
|
+
const combinedQueryData = combinedQueries.get(groupId);
|
|
59
|
+
if (groupId) {
|
|
60
|
+
if (!combinedQueryData) {
|
|
61
|
+
throw new Error(`Invalid group id ${query.groupId}`);
|
|
62
|
+
}
|
|
63
|
+
const combinedQuery = combinedQueryData.query;
|
|
64
|
+
if (!groupedCredentialsCache.has(groupId)) {
|
|
65
|
+
const credWithRevStatus = await proofService.findCredentialByProofQuery(senderIdentifier, combinedQueryData.query);
|
|
66
|
+
if (!credWithRevStatus.cred) {
|
|
67
|
+
throw new Error(`Credential not found for query ${JSON.stringify(combinedQuery)}`);
|
|
68
|
+
}
|
|
69
|
+
groupedCredentialsCache.set(groupId, credWithRevStatus);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const credWithRevStatus = groupedCredentialsCache.get(groupId);
|
|
73
|
+
const zkpRes = await proofService.generateProof(proofReq, senderIdentifier, {
|
|
74
|
+
verifierDid: from,
|
|
75
|
+
challenge: opts.challenge,
|
|
76
|
+
skipRevocation: Boolean(query.skipClaimRevocationCheck),
|
|
77
|
+
credential: credWithRevStatus?.cred,
|
|
78
|
+
credentialRevocationStatus: credWithRevStatus?.revStatus,
|
|
79
|
+
linkNonce: combinedQueryData?.linkNonce ? BigInt(combinedQueryData.linkNonce) : undefined
|
|
80
|
+
});
|
|
81
|
+
zkpResponses.push(zkpRes);
|
|
82
|
+
}
|
|
83
|
+
return zkpResponses;
|
|
84
|
+
};
|
|
85
|
+
exports.processZeroKnowledgeProofRequests = processZeroKnowledgeProofRequests;
|
|
@@ -4,7 +4,7 @@ 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
|
|
7
|
+
const common_1 = require("./common");
|
|
8
8
|
/**
|
|
9
9
|
*
|
|
10
10
|
* Allows to process ContractInvokeRequest protocol message
|
|
@@ -26,7 +26,7 @@ class ContractRequestHandler {
|
|
|
26
26
|
this._packerMgr = _packerMgr;
|
|
27
27
|
this._proofService = _proofService;
|
|
28
28
|
this._zkpVerifier = _zkpVerifier;
|
|
29
|
-
this.
|
|
29
|
+
this._supportedCircuits = [
|
|
30
30
|
models_1.CircuitId.AtomicQueryMTPV2OnChain,
|
|
31
31
|
models_1.CircuitId.AtomicQuerySigV2OnChain,
|
|
32
32
|
models_1.CircuitId.AtomicQueryV3OnChain
|
|
@@ -63,33 +63,14 @@ class ContractRequestHandler {
|
|
|
63
63
|
if (!opts.ethSigner) {
|
|
64
64
|
throw new Error("Can't sign transaction. Provide Signer in options.");
|
|
65
65
|
}
|
|
66
|
-
const
|
|
67
|
-
const { contract_address, chain_id } = ciRequest.body.transaction_data;
|
|
66
|
+
const { chain_id } = ciRequest.body.transaction_data;
|
|
68
67
|
const networkFlag = Object.keys(js_iden3_core_1.ChainIds).find((key) => js_iden3_core_1.ChainIds[key] === chain_id);
|
|
69
68
|
if (!networkFlag) {
|
|
70
69
|
throw new Error(`Invalid chain id ${chain_id}`);
|
|
71
70
|
}
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
networkId,
|
|
76
|
-
// 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.
|
|
77
|
-
method: js_iden3_core_1.DidMethod.Iden3
|
|
78
|
-
});
|
|
79
|
-
const verifierDid = js_iden3_core_1.DID.parseFromId(verifierId);
|
|
80
|
-
for (const proofReq of ciRequest.body.scope) {
|
|
81
|
-
if (!this._allowedCircuits.includes(proofReq.circuitId)) {
|
|
82
|
-
throw new Error(`Can't handle circuit ${proofReq.circuitId}. Only onchain circuits are allowed.`);
|
|
83
|
-
}
|
|
84
|
-
const query = proofReq.query;
|
|
85
|
-
const zkpRes = await this._proofService.generateProof(proofReq, did, {
|
|
86
|
-
skipRevocation: query.skipClaimRevocationCheck ?? false,
|
|
87
|
-
challenge: opts.challenge,
|
|
88
|
-
verifierDid
|
|
89
|
-
});
|
|
90
|
-
zkRequests.push(zkpRes);
|
|
91
|
-
}
|
|
92
|
-
return this._zkpVerifier.submitZKPResponse(opts.ethSigner, ciRequest.body.transaction_data, zkRequests);
|
|
71
|
+
const verifierDid = ciRequest.from ? js_iden3_core_1.DID.parse(ciRequest.from) : undefined;
|
|
72
|
+
const zkpResponses = await (0, common_1.processZeroKnowledgeProofRequests)(did, ciRequest?.body?.scope, verifierDid, this._proofService, { ...opts, supportedCircuits: this._supportedCircuits });
|
|
73
|
+
return this._zkpVerifier.submitZKPResponse(opts.ethSigner, ciRequest.body.transaction_data, zkpResponses);
|
|
93
74
|
}
|
|
94
75
|
}
|
|
95
76
|
exports.ContractRequestHandler = ContractRequestHandler;
|
|
@@ -18,3 +18,5 @@ __exportStar(require("./auth"), exports);
|
|
|
18
18
|
__exportStar(require("./fetch"), exports);
|
|
19
19
|
__exportStar(require("./contract-request"), exports);
|
|
20
20
|
__exportStar(require("./refresh"), exports);
|
|
21
|
+
__exportStar(require("./revocation-status"), exports);
|
|
22
|
+
__exportStar(require("./common"), exports);
|