@0xpolygonid/js-sdk 1.5.0 → 1.6.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 (83) hide show
  1. package/dist/browser/esm/index.js +1685 -468
  2. package/dist/browser/esm/index.js.map +1 -1
  3. package/dist/browser/umd/index.js +1706 -473
  4. package/dist/browser/umd/index.js.map +1 -1
  5. package/dist/node/cjs/circuits/atomic-query-mtp-v2-on-chain.js +1 -1
  6. package/dist/node/cjs/circuits/atomic-query-mtp-v2.js +1 -1
  7. package/dist/node/cjs/circuits/atomic-query-sig-v2-on-chain.js +2 -2
  8. package/dist/node/cjs/circuits/atomic-query-sig-v2.js +11 -14
  9. package/dist/node/cjs/circuits/atomic-query-v3-on-chain.js +320 -0
  10. package/dist/node/cjs/circuits/atomic-query-v3.js +275 -0
  11. package/dist/node/cjs/circuits/common.js +5 -7
  12. package/dist/node/cjs/circuits/comparer.js +57 -2
  13. package/dist/node/cjs/circuits/index.js +4 -0
  14. package/dist/node/cjs/circuits/linked-multi-query.js +128 -0
  15. package/dist/node/cjs/circuits/linked-nullifier.js +57 -0
  16. package/dist/node/cjs/circuits/models.js +25 -1
  17. package/dist/node/cjs/credentials/credential-wallet.js +2 -10
  18. package/dist/node/cjs/credentials/index.js +1 -0
  19. package/dist/node/cjs/credentials/utils.js +23 -0
  20. package/dist/node/cjs/iden3comm/handlers/auth.js +49 -8
  21. package/dist/node/cjs/iden3comm/handlers/contract-request.js +20 -8
  22. package/dist/node/cjs/proof/common.js +104 -1
  23. package/dist/node/cjs/proof/inputs-generator.js +393 -0
  24. package/dist/node/cjs/proof/proof-service.js +105 -372
  25. package/dist/node/cjs/schema-processor/json/parser.js +7 -0
  26. package/dist/node/cjs/schema-processor/json/validator.js +1 -0
  27. package/dist/node/cjs/storage/filters/jsonQuery.js +73 -8
  28. package/dist/node/cjs/utils/did-helper.js +14 -0
  29. package/dist/node/cjs/utils/index.js +2 -0
  30. package/dist/node/cjs/utils/object.js +42 -0
  31. package/dist/node/cjs/verifiable/presentation.js +34 -33
  32. package/dist/node/cjs/verifiable/proof.js +2 -0
  33. package/dist/node/esm/circuits/atomic-query-mtp-v2-on-chain.js +1 -1
  34. package/dist/node/esm/circuits/atomic-query-mtp-v2.js +1 -1
  35. package/dist/node/esm/circuits/atomic-query-sig-v2-on-chain.js +2 -2
  36. package/dist/node/esm/circuits/atomic-query-sig-v2.js +11 -14
  37. package/dist/node/esm/circuits/atomic-query-v3-on-chain.js +315 -0
  38. package/dist/node/esm/circuits/atomic-query-v3.js +270 -0
  39. package/dist/node/esm/circuits/common.js +4 -6
  40. package/dist/node/esm/circuits/comparer.js +55 -1
  41. package/dist/node/esm/circuits/index.js +4 -0
  42. package/dist/node/esm/circuits/linked-multi-query.js +123 -0
  43. package/dist/node/esm/circuits/linked-nullifier.js +52 -0
  44. package/dist/node/esm/circuits/models.js +25 -1
  45. package/dist/node/esm/credentials/credential-wallet.js +2 -10
  46. package/dist/node/esm/credentials/index.js +1 -0
  47. package/dist/node/esm/credentials/utils.js +19 -0
  48. package/dist/node/esm/iden3comm/handlers/auth.js +50 -9
  49. package/dist/node/esm/iden3comm/handlers/contract-request.js +20 -8
  50. package/dist/node/esm/proof/common.js +101 -2
  51. package/dist/node/esm/proof/inputs-generator.js +389 -0
  52. package/dist/node/esm/proof/proof-service.js +111 -377
  53. package/dist/node/esm/schema-processor/json/parser.js +7 -0
  54. package/dist/node/esm/schema-processor/json/validator.js +1 -0
  55. package/dist/node/esm/storage/filters/jsonQuery.js +74 -9
  56. package/dist/node/esm/utils/did-helper.js +10 -0
  57. package/dist/node/esm/utils/index.js +2 -0
  58. package/dist/node/esm/utils/object.js +38 -0
  59. package/dist/node/esm/verifiable/presentation.js +30 -29
  60. package/dist/node/esm/verifiable/proof.js +2 -0
  61. package/dist/types/circuits/atomic-query-mtp-v2.d.ts +13 -13
  62. package/dist/types/circuits/atomic-query-v3-on-chain.d.ts +142 -0
  63. package/dist/types/circuits/atomic-query-v3.d.ts +120 -0
  64. package/dist/types/circuits/common.d.ts +4 -4
  65. package/dist/types/circuits/comparer.d.ts +33 -1
  66. package/dist/types/circuits/index.d.ts +4 -0
  67. package/dist/types/circuits/linked-multi-query.d.ts +38 -0
  68. package/dist/types/circuits/linked-nullifier.d.ts +37 -0
  69. package/dist/types/circuits/models.d.ts +20 -2
  70. package/dist/types/credentials/index.d.ts +1 -0
  71. package/dist/types/credentials/utils.d.ts +12 -0
  72. package/dist/types/iden3comm/types/packer.d.ts +1 -2
  73. package/dist/types/iden3comm/types/protocol/auth.d.ts +1 -0
  74. package/dist/types/proof/common.d.ts +34 -3
  75. package/dist/types/proof/inputs-generator.d.ts +46 -0
  76. package/dist/types/proof/proof-service.d.ts +14 -25
  77. package/dist/types/schema-processor/json/parser.d.ts +1 -0
  78. package/dist/types/storage/filters/jsonQuery.d.ts +1 -1
  79. package/dist/types/utils/did-helper.d.ts +6 -0
  80. package/dist/types/utils/index.d.ts +2 -0
  81. package/dist/types/utils/object.d.ts +12 -0
  82. package/dist/types/verifiable/presentation.d.ts +6 -10
  83. package/package.json +3 -3
@@ -0,0 +1,275 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AtomicQueryV3PubSignals = exports.AtomicQueryV3Inputs = void 0;
4
+ const js_iden3_core_1 = require("@iden3/js-iden3-core");
5
+ const common_1 = require("./common");
6
+ const models_1 = require("./models");
7
+ const js_merkletree_1 = require("@iden3/js-merkletree");
8
+ const utils_1 = require("../utils");
9
+ const verifiable_1 = require("../verifiable");
10
+ const zero = '0';
11
+ /**
12
+ * AtomicQueryV3Inputs ZK private inputs for credentialAtomicQueryV3.circom
13
+ *
14
+ * @beta
15
+ * @class AtomicQueryV3Inputs
16
+ * @extends {BaseConfig}
17
+ */
18
+ class AtomicQueryV3Inputs extends common_1.BaseConfig {
19
+ validate() {
20
+ if (!this.requestID) {
21
+ throw new Error(models_1.CircuitError.EmptyRequestID);
22
+ }
23
+ if (!this.claim.nonRevProof.proof) {
24
+ throw new Error(models_1.CircuitError.EmptyClaimNonRevProof);
25
+ }
26
+ if (!this.query.values) {
27
+ throw new Error(models_1.CircuitError.EmptyQueryValue);
28
+ }
29
+ if (!this.proofType) {
30
+ throw new Error(models_1.CircuitError.InvalidProofType);
31
+ }
32
+ if (this.proofType === verifiable_1.ProofType.BJJSignature) {
33
+ if (!this.claim.signatureProof?.issuerAuthIncProof.proof) {
34
+ throw new Error(models_1.CircuitError.EmptyIssuerAuthClaimProof);
35
+ }
36
+ if (!this.claim.signatureProof.issuerAuthNonRevProof.proof) {
37
+ throw new Error(models_1.CircuitError.EmptyIssuerAuthClaimNonRevProof);
38
+ }
39
+ if (!this.claim.signatureProof.signature) {
40
+ throw new Error(models_1.CircuitError.EmptyClaimSignature);
41
+ }
42
+ }
43
+ if (this.proofType === verifiable_1.ProofType.Iden3SparseMerkleTreeProof) {
44
+ if (!this.claim?.incProof?.proof) {
45
+ throw new Error(models_1.CircuitError.EmptyClaimProof);
46
+ }
47
+ }
48
+ }
49
+ fillMTPProofsWithZero(s) {
50
+ s.issuerClaimMtp = (0, common_1.prepareSiblingsStr)(new js_merkletree_1.Proof(), this.getMTLevel());
51
+ s.issuerClaimClaimsTreeRoot = js_merkletree_1.ZERO_HASH.bigInt().toString();
52
+ s.issuerClaimRevTreeRoot = js_merkletree_1.ZERO_HASH.bigInt().toString();
53
+ s.issuerClaimRootsTreeRoot = js_merkletree_1.ZERO_HASH.bigInt().toString();
54
+ s.issuerClaimIdenState = js_merkletree_1.ZERO_HASH.bigInt().toString();
55
+ }
56
+ fillSigProofWithZero(s) {
57
+ s.issuerClaimSignatureR8x = zero;
58
+ s.issuerClaimSignatureR8y = zero;
59
+ s.issuerClaimSignatureS = zero;
60
+ s.issuerAuthClaim = new js_iden3_core_1.Claim().marshalJson();
61
+ s.issuerAuthClaimMtp = (0, common_1.prepareSiblingsStr)(new js_merkletree_1.Proof(), this.getMTLevel());
62
+ s.issuerAuthClaimsTreeRoot = zero;
63
+ s.issuerAuthRevTreeRoot = zero;
64
+ s.issuerAuthRootsTreeRoot = zero;
65
+ s.issuerAuthClaimNonRevMtp = (0, common_1.prepareSiblingsStr)(new js_merkletree_1.Proof(), this.getMTLevel());
66
+ s.issuerAuthClaimNonRevMtpAuxHi = js_merkletree_1.ZERO_HASH.bigInt().toString();
67
+ s.issuerAuthClaimNonRevMtpAuxHv = js_merkletree_1.ZERO_HASH.bigInt().toString();
68
+ s.issuerAuthClaimNonRevMtpNoAux = zero;
69
+ s.issuerAuthState = zero;
70
+ }
71
+ // InputsMarshal returns Circom private inputs for credentialAtomicQueryV3.circom
72
+ inputsMarshal() {
73
+ this.validate();
74
+ if (this.query.valueProof) {
75
+ this.query.validate();
76
+ this.query.valueProof.validate();
77
+ }
78
+ let valueProof = this.query.valueProof;
79
+ if (!valueProof) {
80
+ valueProof = new models_1.ValueProof();
81
+ valueProof.path = 0n;
82
+ valueProof.value = 0n;
83
+ valueProof.mtp = new js_merkletree_1.Proof();
84
+ }
85
+ let treeState = this.claim.nonRevProof.treeState;
86
+ if (this.proofType === verifiable_1.ProofType.BJJSignature && this.skipClaimRevocationCheck) {
87
+ treeState = this.claim.signatureProof?.issuerAuthNonRevProof.treeState;
88
+ }
89
+ if (!treeState) {
90
+ throw new Error(models_1.CircuitError.EmptyTreeState);
91
+ }
92
+ const s = {
93
+ requestID: this.requestID.toString(),
94
+ userGenesisID: this.id.bigInt().toString(),
95
+ profileNonce: this.profileNonce.toString(),
96
+ claimSubjectProfileNonce: this.claimSubjectProfileNonce.toString(),
97
+ issuerID: this.claim.issuerID.bigInt().toString(),
98
+ issuerClaim: this.claim.claim.marshalJson(),
99
+ issuerClaimNonRevClaimsTreeRoot: treeState.claimsRoot.bigInt().toString(),
100
+ issuerClaimNonRevRevTreeRoot: treeState.revocationRoot.bigInt().toString(),
101
+ issuerClaimNonRevRootsTreeRoot: treeState.rootOfRoots.bigInt().toString(),
102
+ issuerClaimNonRevState: treeState.state.bigInt().toString(),
103
+ issuerClaimNonRevMtp: (0, common_1.prepareSiblingsStr)(this.claim.nonRevProof.proof, this.getMTLevel()),
104
+ claimSchema: this.claim.claim.getSchemaHash().bigInt().toString(),
105
+ claimPathMtp: (0, common_1.prepareSiblingsStr)(valueProof.mtp, this.getMTLevelsClaim()),
106
+ claimPathValue: valueProof.value.toString(),
107
+ operator: this.query.operator,
108
+ timestamp: this.currentTimeStamp,
109
+ // value in this path in merklized json-ld document
110
+ slotIndex: this.query.slotIndex,
111
+ isRevocationChecked: 1
112
+ };
113
+ if (this.skipClaimRevocationCheck) {
114
+ s.isRevocationChecked = 0;
115
+ }
116
+ if (this.proofType === verifiable_1.ProofType.BJJSignature) {
117
+ s.proofType = '1';
118
+ s.issuerClaimSignatureR8x = this.claim.signatureProof?.signature.R8[0].toString();
119
+ s.issuerClaimSignatureR8y = this.claim.signatureProof?.signature.R8[1].toString();
120
+ s.issuerClaimSignatureS = this.claim.signatureProof?.signature.S.toString();
121
+ s.issuerAuthClaim = this.claim.signatureProof?.issuerAuthClaim?.marshalJson();
122
+ s.issuerAuthClaimMtp = (0, common_1.prepareSiblingsStr)(this.claim.signatureProof?.issuerAuthIncProof.proof, this.getMTLevel());
123
+ s.issuerAuthClaimsTreeRoot = treeState.claimsRoot.bigInt().toString();
124
+ s.issuerAuthRevTreeRoot = treeState.revocationRoot.bigInt().toString();
125
+ s.issuerAuthRootsTreeRoot = treeState.rootOfRoots.bigInt().toString();
126
+ s.issuerAuthClaimNonRevMtp = (0, common_1.prepareSiblingsStr)(this.claim.signatureProof?.issuerAuthNonRevProof.proof, this.getMTLevel());
127
+ const nodeAuxIssuerAuthNonRev = (0, common_1.getNodeAuxValue)(this.claim.signatureProof?.issuerAuthNonRevProof.proof);
128
+ s.issuerAuthClaimNonRevMtpAuxHi = nodeAuxIssuerAuthNonRev.key.bigInt().toString();
129
+ s.issuerAuthClaimNonRevMtpAuxHv = nodeAuxIssuerAuthNonRev.value.bigInt().toString();
130
+ s.issuerAuthClaimNonRevMtpNoAux = nodeAuxIssuerAuthNonRev.noAux;
131
+ s.issuerAuthState = this.claim.signatureProof?.issuerAuthIncProof.treeState?.state
132
+ .bigInt()
133
+ .toString();
134
+ this.fillMTPProofsWithZero(s);
135
+ }
136
+ else if (this.proofType === verifiable_1.ProofType.Iden3SparseMerkleTreeProof) {
137
+ s.proofType = '2';
138
+ const incProofTreeState = this.claim.incProof?.treeState;
139
+ if (!incProofTreeState) {
140
+ throw new Error(models_1.CircuitError.EmptyTreeState);
141
+ }
142
+ s.issuerClaimMtp = (0, common_1.prepareSiblingsStr)(this.claim.incProof?.proof, this.getMTLevel());
143
+ s.issuerClaimClaimsTreeRoot = incProofTreeState.claimsRoot.bigInt().toString();
144
+ s.issuerClaimRevTreeRoot = incProofTreeState.revocationRoot.bigInt().toString();
145
+ s.issuerClaimRootsTreeRoot = incProofTreeState.rootOfRoots.bigInt().toString();
146
+ s.issuerClaimIdenState = incProofTreeState.state.bigInt().toString();
147
+ this.fillSigProofWithZero(s);
148
+ }
149
+ const nodeAuxNonRev = (0, common_1.getNodeAuxValue)(this.claim.nonRevProof.proof);
150
+ s.issuerClaimNonRevMtpAuxHi = nodeAuxNonRev.key.bigInt().toString();
151
+ s.issuerClaimNonRevMtpAuxHv = nodeAuxNonRev.value.bigInt().toString();
152
+ s.issuerClaimNonRevMtpNoAux = nodeAuxNonRev.noAux;
153
+ s.claimPathNotExists = (0, common_1.existenceToInt)(valueProof.mtp.existence);
154
+ const nodAuxJSONLD = (0, common_1.getNodeAuxValue)(valueProof.mtp);
155
+ s.claimPathMtpNoAux = nodAuxJSONLD.noAux;
156
+ s.claimPathMtpAuxHi = nodAuxJSONLD.key.bigInt().toString();
157
+ s.claimPathMtpAuxHv = nodAuxJSONLD.value.bigInt().toString();
158
+ s.claimPathKey = valueProof.path.toString();
159
+ const values = (0, common_1.prepareCircuitArrayValues)(this.query.values, this.getValueArrSize());
160
+ s.value = (0, common_1.bigIntArrayToStringArray)(values);
161
+ s.linkNonce = this.linkNonce.toString();
162
+ s.verifierID = this.verifierID?.bigInt().toString() ?? '0';
163
+ s.nullifierSessionID = this.nullifierSessionID.toString();
164
+ return utils_1.byteEncoder.encode(JSON.stringify(s));
165
+ }
166
+ }
167
+ exports.AtomicQueryV3Inputs = AtomicQueryV3Inputs;
168
+ /**
169
+ * @beta
170
+ * AtomicQueryV3PubSignals public inputs
171
+ */
172
+ class AtomicQueryV3PubSignals extends common_1.BaseConfig {
173
+ constructor() {
174
+ super(...arguments);
175
+ this.value = [];
176
+ }
177
+ // PubSignalsUnmarshal unmarshal credentialAtomicQueryV3.circom public signals
178
+ pubSignalsUnmarshal(data) {
179
+ // expected order:
180
+ // merklized
181
+ // userID
182
+ // issuerState
183
+ // linkID
184
+ // nullifier
185
+ // operatorOutput
186
+ // proofType
187
+ // requestID
188
+ // issuerID
189
+ // isRevocationChecked
190
+ // issuerClaimNonRevState
191
+ // timestamp
192
+ // claimSchema
193
+ // claimPathNotExists
194
+ // claimPathKey
195
+ // slotIndex
196
+ // operator
197
+ // value
198
+ // verifierID
199
+ // nullifierSessionID
200
+ // 19 is a number of fields in AtomicQueryV3PubSignals before values, values is last element in the proof and
201
+ // it is length could be different base on the circuit configuration. The length could be modified by set value
202
+ // in ValueArraySize
203
+ const fieldLength = 19;
204
+ const sVals = JSON.parse(utils_1.byteDecoder.decode(data));
205
+ if (sVals.length !== fieldLength + this.getValueArrSize()) {
206
+ throw new Error(`invalid number of Output values expected ${fieldLength + this.getValueArrSize()} got ${sVals.length}`);
207
+ }
208
+ let fieldIdx = 0;
209
+ // -- merklized
210
+ this.merklized = parseInt(sVals[fieldIdx]);
211
+ fieldIdx++;
212
+ // - userID
213
+ this.userID = js_iden3_core_1.Id.fromBigInt(BigInt(sVals[fieldIdx]));
214
+ fieldIdx++;
215
+ // - issuerState
216
+ this.issuerState = js_merkletree_1.Hash.fromString(sVals[fieldIdx]);
217
+ fieldIdx++;
218
+ // - linkID
219
+ this.linkID = BigInt(sVals[fieldIdx]);
220
+ fieldIdx++;
221
+ // - nullifier
222
+ this.nullifier = BigInt(sVals[fieldIdx]);
223
+ fieldIdx++;
224
+ // - operatorOutput
225
+ this.operatorOutput = BigInt(sVals[fieldIdx]);
226
+ fieldIdx++;
227
+ // - proofType
228
+ this.proofType = parseInt(sVals[fieldIdx]);
229
+ fieldIdx++;
230
+ // - requestID
231
+ this.requestID = BigInt(sVals[fieldIdx]);
232
+ fieldIdx++;
233
+ // - issuerID
234
+ this.issuerID = js_iden3_core_1.Id.fromBigInt(BigInt(sVals[fieldIdx]));
235
+ fieldIdx++;
236
+ // - isRevocationChecked
237
+ this.isRevocationChecked = parseInt(sVals[fieldIdx]);
238
+ fieldIdx++;
239
+ // - issuerClaimNonRevState
240
+ this.issuerClaimNonRevState = js_merkletree_1.Hash.fromString(sVals[fieldIdx]);
241
+ fieldIdx++;
242
+ // - timestamp
243
+ this.timestamp = parseInt(sVals[fieldIdx]);
244
+ fieldIdx++;
245
+ // - claimSchema
246
+ this.claimSchema = js_iden3_core_1.SchemaHash.newSchemaHashFromInt(BigInt(sVals[fieldIdx]));
247
+ fieldIdx++;
248
+ // - ClaimPathNotExists
249
+ this.claimPathNotExists = parseInt(sVals[fieldIdx]);
250
+ fieldIdx++;
251
+ // - ClaimPathKey
252
+ this.claimPathKey = BigInt(sVals[fieldIdx]);
253
+ fieldIdx++;
254
+ // - slotIndex
255
+ this.slotIndex = parseInt(sVals[fieldIdx]);
256
+ fieldIdx++;
257
+ // - operator
258
+ this.operator = parseInt(sVals[fieldIdx]);
259
+ fieldIdx++;
260
+ // - values
261
+ for (let index = 0; index < this.getValueArrSize(); index++) {
262
+ this.value.push(BigInt(sVals[fieldIdx]));
263
+ fieldIdx++;
264
+ }
265
+ // - verifierID
266
+ if (sVals[fieldIdx] !== '0') {
267
+ this.verifierID = js_iden3_core_1.Id.fromBigInt(BigInt(sVals[fieldIdx]));
268
+ }
269
+ fieldIdx++;
270
+ // - nullifierSessionID
271
+ this.nullifierSessionID = BigInt(sVals[fieldIdx]);
272
+ return this;
273
+ }
274
+ }
275
+ exports.AtomicQueryV3PubSignals = AtomicQueryV3PubSignals;
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getProperties = exports.existenceToInt = exports.getNodeAuxValue = exports.bigIntArrayToStringArray = exports.prepareCircuitArrayValues = exports.prepareSiblingsStr = exports.buildTreeState = exports.strMTHex = exports.BaseConfig = exports.ErrorEmptyIssuerAuthClaimNonRevProof = exports.ErrorEmptyIssuerAuthClaimProof = exports.ErrorUserStateInRelayClaimProof = exports.ErrorEmptyClaimNonRevProof = exports.ErrorEmptyClaimProof = exports.ErrorEmptyClaimSignature = exports.ErrorEmptyChallengeSignature = exports.ErrorEmptyAuthClaimNonRevProof = exports.ErrorEmptyAuthClaimProof = exports.defaultMTLevelsClaimsMerklization = exports.defaultMTLevelsOnChain = exports.defaultValueArraySize = exports.defaultMTLevels = void 0;
3
+ exports.getProperties = exports.existenceToInt = exports.getNodeAuxValue = exports.bigIntArrayToStringArray = exports.prepareCircuitArrayValues = exports.prepareSiblingsStr = exports.buildTreeState = exports.strMTHex = exports.BaseConfig = exports.ErrorEmptyIssuerAuthClaimNonRevProof = exports.ErrorEmptyIssuerAuthClaimProof = exports.ErrorUserStateInRelayClaimProof = exports.ErrorEmptyClaimNonRevProof = exports.ErrorEmptyClaimProof = exports.ErrorEmptyClaimSignature = exports.ErrorEmptyChallengeSignature = exports.ErrorEmptyAuthClaimNonRevProof = exports.ErrorEmptyAuthClaimProof = exports.defaultMTLevelsClaim = exports.defaultMTLevelsOnChain = exports.defaultValueArraySize = exports.defaultMTLevels = void 0;
4
4
  const js_crypto_1 = require("@iden3/js-crypto");
5
5
  const js_merkletree_1 = require("@iden3/js-merkletree");
6
6
  exports.defaultMTLevels = 40; // max MT levels, default value for identity circuits
7
7
  exports.defaultValueArraySize = 64; // max value array size, default value for identity circuits
8
8
  exports.defaultMTLevelsOnChain = 64; // max MT levels on chain, default value for identity circuits
9
- exports.defaultMTLevelsClaimsMerklization = 32; // max MT levels of JSON-LD merklization on claim
9
+ exports.defaultMTLevelsClaim = 32; // max MT levels of JSON-LD merklization on claim
10
10
  exports.ErrorEmptyAuthClaimProof = 'empty auth claim mtp proof';
11
11
  exports.ErrorEmptyAuthClaimNonRevProof = 'empty auth claim non-revocation mtp proof';
12
12
  exports.ErrorEmptyChallengeSignature = 'empty challenge signature';
@@ -32,14 +32,12 @@ class BaseConfig {
32
32
  return this.mtLevel ? this.mtLevel : exports.defaultMTLevels;
33
33
  }
34
34
  /**
35
- * getMTLevel max circuit MT levels
35
+ * GetMTLevelsClaim max jsonld Claim levels
36
36
  *
37
37
  * @returns number
38
38
  */
39
- getMTLevelsClaimMerklization() {
40
- return this.mtLevelClaimsMerklization
41
- ? this.mtLevelClaimsMerklization
42
- : exports.defaultMTLevelsClaimsMerklization;
39
+ getMTLevelsClaim() {
40
+ return this.mtLevelClaim ? this.mtLevelClaim : exports.defaultMTLevelsClaim;
43
41
  }
44
42
  /**
45
43
  * GetValueArrSize return size of circuits value array size
@@ -1,6 +1,21 @@
1
1
  "use strict";
2
+ /**
3
+ * Represents the XSD namespace and its corresponding data types.
4
+ */
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.factoryComparer = exports.Vector = exports.Scalar = exports.QueryOperators = exports.Operators = void 0;
6
+ exports.factoryComparer = exports.Vector = exports.Scalar = exports.isValidOperation = exports.availableTypesOperators = exports.QueryOperators = exports.Operators = exports.XSDNS = void 0;
7
+ var XSDNS;
8
+ (function (XSDNS) {
9
+ XSDNS["Boolean"] = "http://www.w3.org/2001/XMLSchema#boolean";
10
+ XSDNS["Integer"] = "http://www.w3.org/2001/XMLSchema#integer";
11
+ XSDNS["NonNegativeInteger"] = "http://www.w3.org/2001/XMLSchema#nonNegativeInteger";
12
+ XSDNS["NonPositiveInteger"] = "http://www.w3.org/2001/XMLSchema#nonPositiveInteger";
13
+ XSDNS["NegativeInteger"] = "http://www.w3.org/2001/XMLSchema#negativeInteger";
14
+ XSDNS["PositiveInteger"] = "http://www.w3.org/2001/XMLSchema#positiveInteger";
15
+ XSDNS["DateTime"] = "http://www.w3.org/2001/XMLSchema#dateTime";
16
+ XSDNS["Double"] = "http://www.w3.org/2001/XMLSchema#double";
17
+ XSDNS["String"] = "http://www.w3.org/2001/XMLSchema#string";
18
+ })(XSDNS = exports.XSDNS || (exports.XSDNS = {}));
4
19
  /**
5
20
  * List of available operators.
6
21
  *
@@ -15,6 +30,11 @@ var Operators;
15
30
  Operators[Operators["IN"] = 4] = "IN";
16
31
  Operators[Operators["NIN"] = 5] = "NIN";
17
32
  Operators[Operators["NE"] = 6] = "NE";
33
+ Operators[Operators["LTE"] = 7] = "LTE";
34
+ Operators[Operators["GTE"] = 8] = "GTE";
35
+ Operators[Operators["BETWEEN"] = 9] = "BETWEEN";
36
+ Operators[Operators["SD"] = 16] = "SD";
37
+ Operators[Operators["NULLIFY"] = 17] = "NULLIFY";
18
38
  })(Operators = exports.Operators || (exports.Operators = {}));
19
39
  /** QueryOperators represents operators for atomic circuits */
20
40
  exports.QueryOperators = {
@@ -24,8 +44,43 @@ exports.QueryOperators = {
24
44
  $gt: Operators.GT,
25
45
  $in: Operators.IN,
26
46
  $nin: Operators.NIN,
27
- $ne: Operators.NE
47
+ $ne: Operators.NE,
48
+ $lte: Operators.LTE,
49
+ $gte: Operators.GTE,
50
+ $between: Operators.BETWEEN,
51
+ $sd: Operators.SD,
52
+ $nullify: Operators.NULLIFY
53
+ };
54
+ const allOperations = Object.values(exports.QueryOperators);
55
+ exports.availableTypesOperators = new Map([
56
+ [XSDNS.Boolean, [exports.QueryOperators.$eq, exports.QueryOperators.$ne]],
57
+ [XSDNS.Integer, allOperations],
58
+ [XSDNS.NonNegativeInteger, allOperations],
59
+ [XSDNS.PositiveInteger, allOperations],
60
+ [XSDNS.Double, [exports.QueryOperators.$eq, exports.QueryOperators.$ne, exports.QueryOperators.$in, exports.QueryOperators.$nin]],
61
+ [XSDNS.String, [exports.QueryOperators.$eq, exports.QueryOperators.$ne, exports.QueryOperators.$in, exports.QueryOperators.$nin]],
62
+ [XSDNS.DateTime, allOperations]
63
+ ]);
64
+ /**
65
+ * Checks if the given operation is valid for the specified datatype.
66
+ * @param datatype - The datatype to check the operation for.
67
+ * @param op - The operation to check.
68
+ * @returns True if the operation is valid, false otherwise.
69
+ */
70
+ const isValidOperation = (datatype, op) => {
71
+ if (op === Operators.NOOP) {
72
+ return true;
73
+ }
74
+ if (!exports.availableTypesOperators.has(datatype)) {
75
+ return false;
76
+ }
77
+ const ops = exports.availableTypesOperators.get(datatype);
78
+ if (!ops) {
79
+ return false;
80
+ }
81
+ return ops.includes(op);
28
82
  };
83
+ exports.isValidOperation = isValidOperation;
29
84
  /**
30
85
  * Scalar is used to compare two scalar value.
31
86
  *
@@ -20,6 +20,10 @@ __exportStar(require("./comparer"), exports);
20
20
  __exportStar(require("./atomic-query-mtp-v2"), exports);
21
21
  __exportStar(require("./atomic-query-mtp-v2-on-chain"), exports);
22
22
  __exportStar(require("./atomic-query-sig-v2"), exports);
23
+ __exportStar(require("./atomic-query-v3"), exports);
24
+ __exportStar(require("./atomic-query-v3-on-chain"), exports);
23
25
  __exportStar(require("./atomic-query-sig-v2-on-chain"), exports);
24
26
  __exportStar(require("./auth-v2"), exports);
25
27
  __exportStar(require("./state-transition"), exports);
28
+ __exportStar(require("./linked-nullifier"), exports);
29
+ __exportStar(require("./linked-multi-query"), exports);
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LinkedMultiQueryPubSignals = exports.LinkedMultiQueryInputs = void 0;
4
+ const utils_1 = require("../utils");
5
+ const common_1 = require("./common");
6
+ /**
7
+ * LinkedMultiQuery circuit representation
8
+ * Inputs and public signals declaration, marshalling and parsing
9
+ *
10
+ * @beta
11
+ * @class LinkedMultiQueryInputs
12
+ */
13
+ class LinkedMultiQueryInputs extends common_1.BaseConfig {
14
+ // InputsMarshal returns Circom private inputs for linkedMultiQueryInputs.circom
15
+ inputsMarshal() {
16
+ const enabled = [];
17
+ const claimPathNotExists = [];
18
+ const claimPathMtp = [];
19
+ const claimPathMtpNoAux = [];
20
+ const claimPathMtpAuxHi = [];
21
+ const claimPathMtpAuxHv = [];
22
+ const claimPathKey = [];
23
+ const claimPathValue = [];
24
+ const slotIndex = [];
25
+ const operator = [];
26
+ const value = [];
27
+ for (let i = 0; i < this.queryLength; i++) {
28
+ if (!this.query) {
29
+ enabled.push(0);
30
+ claimPathNotExists.push(0);
31
+ claimPathMtp.push([]);
32
+ claimPathMtpNoAux.push('0');
33
+ claimPathMtpAuxHi.push('0');
34
+ claimPathMtpAuxHv.push('0');
35
+ claimPathKey.push('0');
36
+ claimPathValue.push('0');
37
+ slotIndex.push(0);
38
+ operator.push(0);
39
+ const valuesArr = (0, common_1.prepareCircuitArrayValues)([], this.getValueArrSize());
40
+ value.push((0, common_1.bigIntArrayToStringArray)(valuesArr));
41
+ continue;
42
+ }
43
+ enabled.push(1);
44
+ const valueProof = this.query[i].valueProof;
45
+ claimPathNotExists.push((0, common_1.existenceToInt)(valueProof.mtp.existence));
46
+ claimPathMtp.push((0, common_1.prepareSiblingsStr)(valueProof.mtp, this.getMTLevelsClaim()));
47
+ const nodAuxJSONLD = (0, common_1.getNodeAuxValue)(valueProof.mtp);
48
+ claimPathMtpNoAux.push(nodAuxJSONLD.noAux);
49
+ claimPathMtpAuxHi.push(nodAuxJSONLD.key.bigInt().toString());
50
+ claimPathMtpAuxHv.push(nodAuxJSONLD.value.bigInt().toString());
51
+ claimPathKey.push(valueProof.path.toString());
52
+ claimPathValue.push(valueProof.value.toString());
53
+ slotIndex.push(this.query[i].slotIndex);
54
+ operator.push(this.query[i].operator);
55
+ const valuesArr = (0, common_1.prepareCircuitArrayValues)(this.query[i].values, this.getValueArrSize());
56
+ value.push((0, common_1.bigIntArrayToStringArray)(valuesArr));
57
+ }
58
+ const s = {
59
+ linkNonce: this.linkNonce.toString(),
60
+ issuerClaim: this.claim.marshalJson(),
61
+ enabled,
62
+ claimSchema: this.claim.getSchemaHash().bigInt().toString(),
63
+ claimPathNotExists,
64
+ claimPathMtp,
65
+ claimPathMtpNoAux,
66
+ claimPathMtpAuxHi,
67
+ claimPathMtpAuxHv,
68
+ claimPathKey,
69
+ claimPathValue,
70
+ slotIndex,
71
+ operator,
72
+ value
73
+ };
74
+ return utils_1.byteEncoder.encode(JSON.stringify(s));
75
+ }
76
+ }
77
+ exports.LinkedMultiQueryInputs = LinkedMultiQueryInputs;
78
+ // LinkedMultiQueryPubSignals linkedMultiQuery.circom public signals
79
+ /**
80
+ * public signals
81
+ *
82
+ * @beta
83
+ * @class LinkedMultiQueryPubSignals
84
+ */
85
+ class LinkedMultiQueryPubSignals {
86
+ /**
87
+ * PubSignalsUnmarshal unmarshal linkedMultiQuery.circom public inputs to LinkedMultiQueryPubSignals
88
+ *
89
+ * @beta
90
+ * @param {Uint8Array} data
91
+ * @returns LinkedMultiQueryPubSignals
92
+ */
93
+ pubSignalsUnmarshal(data, queryLength) {
94
+ const len = queryLength * 3 + 2;
95
+ const sVals = JSON.parse(utils_1.byteDecoder.decode(data));
96
+ if (sVals.length !== len) {
97
+ throw new Error(`invalid number of Output values expected ${len} got ${sVals.length}`);
98
+ }
99
+ let fieldIdx = 0;
100
+ // -- linkID
101
+ this.linkID = BigInt(sVals[fieldIdx]);
102
+ fieldIdx++;
103
+ // -- merklized
104
+ this.merklized = parseInt(sVals[fieldIdx]);
105
+ fieldIdx++;
106
+ // - operatorOutput
107
+ this.operatorOutput = [];
108
+ for (let i = 0; i < queryLength; i++) {
109
+ this.operatorOutput.push(BigInt(sVals[fieldIdx]));
110
+ fieldIdx++;
111
+ }
112
+ // - circuitQueryHash
113
+ this.circuitQueryHash = [];
114
+ for (let i = 0; i < queryLength; i++) {
115
+ this.circuitQueryHash.push(BigInt(sVals[fieldIdx]));
116
+ fieldIdx++;
117
+ }
118
+ // - enabled
119
+ this.enabled = [];
120
+ for (let i = 0; i < queryLength; i++) {
121
+ const enabledNum = parseInt(sVals[fieldIdx]);
122
+ this.enabled.push(enabledNum === 1);
123
+ fieldIdx++;
124
+ }
125
+ return this;
126
+ }
127
+ }
128
+ exports.LinkedMultiQueryPubSignals = LinkedMultiQueryPubSignals;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LinkedNullifierPubSignals = exports.LinkedNullifierInputs = void 0;
4
+ const js_iden3_core_1 = require("@iden3/js-iden3-core");
5
+ const utils_1 = require("../utils");
6
+ /**
7
+ * LinkedNullifier circuit representation
8
+ * Inputs and public signals declaration, marshalling and parsing
9
+ *
10
+ * @beta
11
+ * @class LinkedNullifierInputs
12
+ */
13
+ class LinkedNullifierInputs {
14
+ // InputsMarshal returns Circom private inputs for nullifier.circom
15
+ inputsMarshal() {
16
+ const s = {
17
+ linkNonce: this.linkNonce.toString(),
18
+ issuerClaim: this.issuerClaim.marshalJson(),
19
+ userGenesisID: this.id.bigInt().toString(),
20
+ claimSubjectProfileNonce: this.claimSubjectProfileNonce.toString(),
21
+ claimSchema: this.issuerClaim.getSchemaHash().bigInt().toString(),
22
+ verifierID: this.verifierID?.bigInt().toString() ?? '0',
23
+ nullifierSessionID: this.nullifierSessionID.toString()
24
+ };
25
+ return utils_1.byteEncoder.encode(JSON.stringify(s));
26
+ }
27
+ }
28
+ exports.LinkedNullifierInputs = LinkedNullifierInputs;
29
+ // LinkedNullifierPubSignals nullifier.circom public signals
30
+ /**
31
+ * public signals
32
+ *
33
+ * @beta
34
+ * @class LinkedNullifierPubSignals
35
+ */
36
+ class LinkedNullifierPubSignals {
37
+ /**
38
+ * PubSignalsUnmarshal unmarshal nullifier.circom public inputs to LinkedNullifierPubSignals
39
+ *
40
+ * @beta
41
+ * @param {Uint8Array} data
42
+ * @returns LinkedNullifierPubSignals
43
+ */
44
+ pubSignalsUnmarshal(data) {
45
+ const len = 4;
46
+ const sVals = JSON.parse(utils_1.byteDecoder.decode(data));
47
+ if (sVals.length !== len) {
48
+ throw new Error(`invalid number of Output values expected ${len} got ${sVals.length}`);
49
+ }
50
+ this.nullifier = BigInt(sVals[0]);
51
+ this.linkID = BigInt(sVals[1]);
52
+ this.verifierID = js_iden3_core_1.Id.fromBigInt(BigInt(sVals[2]));
53
+ this.nullifierSessionID = BigInt(sVals[3]);
54
+ return this;
55
+ }
56
+ }
57
+ exports.LinkedNullifierPubSignals = LinkedNullifierPubSignals;
@@ -15,7 +15,9 @@ class Query {
15
15
  *
16
16
  */
17
17
  validate() {
18
- if (this.operator !== comparer_1.QueryOperators.$noop && this.values?.some((v) => typeof v !== 'bigint'))
18
+ if (this.operator !== comparer_1.QueryOperators.$noop &&
19
+ this.operator !== comparer_1.QueryOperators.$sd &&
20
+ this.values?.some((v) => typeof v !== 'bigint'))
19
21
  throw new Error(CircuitError.EmptyQueryValue);
20
22
  }
21
23
  }
@@ -39,6 +41,26 @@ var CircuitId;
39
41
  CircuitId["AtomicQuerySigV2"] = "credentialAtomicQuerySigV2";
40
42
  // AtomicQuerySigOnChain is a type for credentialAtomicQuerySigOnChain.circom
41
43
  CircuitId["AtomicQuerySigV2OnChain"] = "credentialAtomicQuerySigV2OnChain";
44
+ /**
45
+ * @beta
46
+ */
47
+ // AtomicQueryV3CircuitID is a type for credentialAtomicQueryV3.circom
48
+ CircuitId["AtomicQueryV3"] = "credentialAtomicQueryV3-beta.0";
49
+ /**
50
+ * @beta
51
+ */
52
+ // AtomicQueryV3OnChainCircuitID is a type for credentialAtomicQueryV3OnChain.circom
53
+ CircuitId["AtomicQueryV3OnChain"] = "credentialAtomicQueryV3OnChain-beta.0";
54
+ /**
55
+ * @beta
56
+ */
57
+ // LinkedNullifier is a type for linkedNullifier.circom
58
+ CircuitId["LinkedNullifier"] = "linkedNullifier-beta.0";
59
+ /**
60
+ * @beta
61
+ */
62
+ // LinkedMultiQuery is a type for linkedMultiQuery.circom
63
+ CircuitId["LinkedMultiQuery10"] = "linkedMultiQuery10-beta.0";
42
64
  })(CircuitId = exports.CircuitId || (exports.CircuitId = {}));
43
65
  /**
44
66
  * Claim structure for circuit inputs
@@ -73,7 +95,9 @@ var CircuitError;
73
95
  CircuitError["EmptyId"] = "empty Id";
74
96
  CircuitError["EmptyChallenge"] = "empty challenge";
75
97
  CircuitError["EmptyGISTProof"] = "empty GIST merkle tree proof";
98
+ CircuitError["EmptyTreeState"] = "empty tree state";
76
99
  CircuitError["EmptyRequestID"] = "empty request ID";
100
+ CircuitError["InvalidProofType"] = "invalid proof type";
77
101
  })(CircuitError = exports.CircuitError || (exports.CircuitError = {}));
78
102
  /**
79
103
  * ValueProof represents a Merkle Proof for a value stored as MT
@@ -30,6 +30,7 @@ const uuid = __importStar(require("uuid"));
30
30
  const resolver_1 = require("./status/resolver");
31
31
  const sparse_merkle_tree_1 = require("./status/sparse-merkle-tree");
32
32
  const agent_revocation_1 = require("./status/agent-revocation");
33
+ const utils_1 = require("./utils");
33
34
  // ErrAllClaimsRevoked all claims are revoked.
34
35
  const ErrAllClaimsRevoked = 'all claims are revoked';
35
36
  /**
@@ -125,16 +126,7 @@ class CredentialWallet {
125
126
  ? mtpProof.issuerData.state
126
127
  : sigProof?.issuerData.state;
127
128
  const issuerDID = js_iden3_core_1.DID.parse(cred.issuer);
128
- let userDID;
129
- if (!cred.credentialSubject.id) {
130
- userDID = issuerDID;
131
- }
132
- else {
133
- if (typeof cred.credentialSubject.id !== 'string') {
134
- throw new Error('credential status `id` is not a string');
135
- }
136
- userDID = js_iden3_core_1.DID.parse(cred.credentialSubject.id);
137
- }
129
+ const userDID = (0, utils_1.getUserDIDFromCredential)(issuerDID, cred);
138
130
  const opts = {
139
131
  issuerGenesisState: stateInfo,
140
132
  issuerDID,
@@ -22,3 +22,4 @@ __exportStar(require("./status/agent-revocation"), exports);
22
22
  __exportStar(require("./status/utils"), exports);
23
23
  __exportStar(require("./credential-wallet"), exports);
24
24
  __exportStar(require("./rhs"), exports);
25
+ __exportStar(require("./utils"), exports);