@maci-protocol/coordinator 0.0.0-ci.e0aedb2 → 0.0.0-ci.e47bd6e
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/LICENSE +1 -2
- package/README.md +13 -6
- package/build/hardhat.config.cjs +3 -0
- package/build/hardhat.config.cjs.map +1 -1
- package/build/hardhat.config.d.cts +3 -0
- package/build/scripts/generateMaciKeyPair.js +2 -2
- package/build/scripts/generateMaciKeyPair.js.map +1 -1
- package/build/tests/constants.d.ts +0 -1
- package/build/tests/constants.d.ts.map +1 -1
- package/build/tests/constants.js +0 -1
- package/build/tests/constants.js.map +1 -1
- package/build/tests/e2e.aa.test.js +17 -22
- package/build/tests/e2e.aa.test.js.map +1 -1
- package/build/tests/e2e.deploy.test.js +119 -82
- package/build/tests/e2e.deploy.test.js.map +1 -1
- package/build/tests/utils.d.ts +6 -0
- package/build/tests/utils.d.ts.map +1 -1
- package/build/tests/utils.js +12 -3
- package/build/tests/utils.js.map +1 -1
- package/build/ts/common/__tests__/common.test.js +7 -11
- package/build/ts/common/__tests__/common.test.js.map +1 -1
- package/build/ts/common/accountAbstraction.d.ts +2 -19
- package/build/ts/common/accountAbstraction.d.ts.map +1 -1
- package/build/ts/common/accountAbstraction.js +15 -44
- package/build/ts/common/accountAbstraction.js.map +1 -1
- package/build/ts/common/chain.d.ts +16 -0
- package/build/ts/common/chain.d.ts.map +1 -0
- package/build/ts/common/chain.js +35 -0
- package/build/ts/common/chain.js.map +1 -0
- package/build/ts/common/errors.d.ts +17 -18
- package/build/ts/common/errors.d.ts.map +1 -1
- package/build/ts/common/errors.js +17 -18
- package/build/ts/common/errors.js.map +1 -1
- package/build/ts/common/index.d.ts +2 -0
- package/build/ts/common/index.d.ts.map +1 -1
- package/build/ts/common/index.js +2 -0
- package/build/ts/common/index.js.map +1 -1
- package/build/ts/common/types.d.ts +2 -3
- package/build/ts/common/types.d.ts.map +1 -1
- package/build/ts/deployer/__tests__/deployer.service.test.js +30 -289
- package/build/ts/deployer/__tests__/deployer.service.test.js.map +1 -1
- package/build/ts/deployer/__tests__/utils.d.ts +30 -1
- package/build/ts/deployer/__tests__/utils.d.ts.map +1 -1
- package/build/ts/deployer/__tests__/utils.js +46 -11
- package/build/ts/deployer/__tests__/utils.js.map +1 -1
- package/build/ts/deployer/deployer.service.d.ts +17 -53
- package/build/ts/deployer/deployer.service.d.ts.map +1 -1
- package/build/ts/deployer/deployer.service.js +174 -461
- package/build/ts/deployer/deployer.service.js.map +1 -1
- package/build/ts/deployer/dto.d.ts +4 -4
- package/build/ts/deployer/dto.d.ts.map +1 -1
- package/build/ts/deployer/dto.js +9 -1
- package/build/ts/deployer/dto.js.map +1 -1
- package/build/ts/deployer/types.d.ts +62 -24
- package/build/ts/deployer/types.d.ts.map +1 -1
- package/build/ts/file/__tests__/file.service.test.js +12 -11
- package/build/ts/file/__tests__/file.service.test.js.map +1 -1
- package/build/ts/file/file.service.d.ts +4 -3
- package/build/ts/file/file.service.d.ts.map +1 -1
- package/build/ts/file/file.service.js +14 -9
- package/build/ts/file/file.service.js.map +1 -1
- package/build/ts/file/types.d.ts +2 -2
- package/build/ts/file/types.d.ts.map +1 -1
- package/build/ts/proof/__tests__/proof.controller.test.js +5 -2
- package/build/ts/proof/__tests__/proof.controller.test.js.map +1 -1
- package/build/ts/proof/__tests__/proof.gateway.test.js +6 -2
- package/build/ts/proof/__tests__/proof.gateway.test.js.map +1 -1
- package/build/ts/proof/__tests__/proof.service.test.js +12 -10
- package/build/ts/proof/__tests__/proof.service.test.js.map +1 -1
- package/build/ts/proof/dto.d.ts +13 -11
- package/build/ts/proof/dto.d.ts.map +1 -1
- package/build/ts/proof/dto.js +51 -29
- package/build/ts/proof/dto.js.map +1 -1
- package/build/ts/proof/proof.controller.d.ts +3 -2
- package/build/ts/proof/proof.controller.d.ts.map +1 -1
- package/build/ts/proof/proof.controller.js.map +1 -1
- package/build/ts/proof/proof.service.d.ts +3 -3
- package/build/ts/proof/proof.service.d.ts.map +1 -1
- package/build/ts/proof/proof.service.js +40 -120
- package/build/ts/proof/proof.service.js.map +1 -1
- package/build/ts/proof/types.d.ts +18 -10
- package/build/ts/proof/types.d.ts.map +1 -1
- package/build/ts/sessionKeys/provider/KernelEIP1193Provider.d.ts +53 -0
- package/build/ts/sessionKeys/provider/KernelEIP1193Provider.d.ts.map +1 -0
- package/build/ts/sessionKeys/provider/KernelEIP1193Provider.js +105 -0
- package/build/ts/sessionKeys/provider/KernelEIP1193Provider.js.map +1 -0
- package/build/ts/sessionKeys/sessionKeys.service.d.ts +13 -2
- package/build/ts/sessionKeys/sessionKeys.service.d.ts.map +1 -1
- package/build/ts/sessionKeys/sessionKeys.service.js +22 -4
- package/build/ts/sessionKeys/sessionKeys.service.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +30 -30
- package/build/ts/deployer/utils.d.ts +0 -8
- package/build/ts/deployer/utils.d.ts.map +0 -1
- package/build/ts/deployer/utils.js +0 -9
- package/build/ts/deployer/utils.js.map +0 -1
|
@@ -8,15 +8,14 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
var ProofGeneratorService_1;
|
|
11
|
-
import { Keypair,
|
|
12
|
-
import { Deployment, EContracts,
|
|
11
|
+
import { Keypair, PrivateKey, PublicKey } from "@maci-protocol/domainobjs";
|
|
12
|
+
import { Deployment, EContracts, getPoll, mergeSignups, EMode, } from "@maci-protocol/sdk";
|
|
13
|
+
import { generateProofs, proveOnChain } from "@maci-protocol/sdk";
|
|
13
14
|
import { Logger, Injectable } from "@nestjs/common";
|
|
14
|
-
import { ZeroAddress } from "ethers";
|
|
15
15
|
import hre from "hardhat";
|
|
16
16
|
import fs from "fs";
|
|
17
17
|
import path from "path";
|
|
18
18
|
import { ErrorCodes } from "../common";
|
|
19
|
-
import { getPublicClient } from "../common/accountAbstraction";
|
|
20
19
|
import { CryptoService } from "../crypto/crypto.service";
|
|
21
20
|
import { FileService } from "../file/file.service";
|
|
22
21
|
import { SessionKeysService } from "../sessionKeys/sessionKeys.service";
|
|
@@ -65,13 +64,9 @@ let ProofGeneratorService = ProofGeneratorService_1 = class ProofGeneratorServic
|
|
|
65
64
|
* @param args - generate proofs arguments
|
|
66
65
|
* @returns - generated proofs for message processing and tally
|
|
67
66
|
*/
|
|
68
|
-
async generate({ poll, maciContractAddress,
|
|
67
|
+
async generate({ approval, sessionKeyAddress, chain, poll, maciContractAddress, mode, encryptedCoordinatorPrivateKey, startBlock, endBlock, blocksPerBatch, }, options) {
|
|
69
68
|
try {
|
|
70
|
-
const
|
|
71
|
-
name: EContracts.MACI,
|
|
72
|
-
address: maciContractAddress,
|
|
73
|
-
});
|
|
74
|
-
const signer = await this.deployment.getDeployer();
|
|
69
|
+
const signer = await this.sessionKeysService.getCoordinatorSigner(chain, sessionKeyAddress, approval);
|
|
75
70
|
const pollData = await getPoll({
|
|
76
71
|
maciAddress: maciContractAddress,
|
|
77
72
|
pollId: poll,
|
|
@@ -81,58 +76,40 @@ let ProofGeneratorService = ProofGeneratorService_1 = class ProofGeneratorServic
|
|
|
81
76
|
name: EContracts.Poll,
|
|
82
77
|
address: pollData.address,
|
|
83
78
|
});
|
|
84
|
-
const
|
|
85
|
-
pollContract.coordinatorPubKey(),
|
|
86
|
-
pollContract.stateMerged(),
|
|
87
|
-
]);
|
|
88
|
-
if (!isStateAqMerged) {
|
|
89
|
-
this.logger.error(`Error: ${ErrorCodes.NOT_MERGED_STATE_TREE}, state tree is not merged`);
|
|
90
|
-
throw new Error(ErrorCodes.NOT_MERGED_STATE_TREE.toString());
|
|
91
|
-
}
|
|
79
|
+
const coordinatorPublicKey = await pollContract.coordinatorPublicKey();
|
|
92
80
|
const { privateKey } = await this.fileService.getPrivateKey();
|
|
93
|
-
const maciPrivateKey =
|
|
81
|
+
const maciPrivateKey = PrivateKey.deserialize(this.cryptoService.decrypt(privateKey, encryptedCoordinatorPrivateKey));
|
|
94
82
|
const coordinatorKeypair = new Keypair(maciPrivateKey);
|
|
95
|
-
const publicKey = new
|
|
83
|
+
const publicKey = new PublicKey([
|
|
96
84
|
BigInt(coordinatorPublicKey.x.toString()),
|
|
97
85
|
BigInt(coordinatorPublicKey.y.toString()),
|
|
98
86
|
]);
|
|
99
|
-
if (!coordinatorKeypair.
|
|
87
|
+
if (!coordinatorKeypair.publicKey.equals(publicKey)) {
|
|
100
88
|
this.logger.error(`Error: ${ErrorCodes.PRIVATE_KEY_MISMATCH}, wrong private key`);
|
|
101
89
|
throw new Error(ErrorCodes.PRIVATE_KEY_MISMATCH.toString());
|
|
102
90
|
}
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
pollId: poll,
|
|
91
|
+
// There are only QV and Non-QV modes available for tally circuit
|
|
92
|
+
const tally = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_TALLY_ZKEY_NAME, mode === EMode.QV ? mode : EMode.NON_QV);
|
|
93
|
+
const messageProcessor = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_MESSAGE_PROCESS_ZKEY_NAME, mode);
|
|
94
|
+
const { processProofs, tallyProofs, tallyData } = await generateProofs({
|
|
95
|
+
outputDir: path.resolve("./proofs"),
|
|
96
|
+
coordinatorPrivateKey: maciPrivateKey.serialize(),
|
|
110
97
|
signer,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
const foundPoll = maciState.polls.get(BigInt(poll));
|
|
119
|
-
if (!foundPoll) {
|
|
120
|
-
this.logger.error(`Error: ${ErrorCodes.POLL_NOT_FOUND}, Poll ${poll} not found in maci state`);
|
|
121
|
-
throw new Error(ErrorCodes.POLL_NOT_FOUND.toString());
|
|
122
|
-
}
|
|
123
|
-
const proofGenerator = new ProofGenerator({
|
|
124
|
-
poll: foundPoll,
|
|
125
|
-
maciContractAddress,
|
|
126
|
-
tallyContractAddress,
|
|
127
|
-
tally: this.fileService.getZkeyFilePaths(process.env.COORDINATOR_TALLY_ZKEY_NAME, useQuadraticVoting),
|
|
128
|
-
mp: this.fileService.getZkeyFilePaths(process.env.COORDINATOR_MESSAGE_PROCESS_ZKEY_NAME, useQuadraticVoting),
|
|
98
|
+
maciAddress: maciContractAddress,
|
|
99
|
+
pollId: BigInt(poll),
|
|
100
|
+
startBlock,
|
|
101
|
+
endBlock,
|
|
102
|
+
blocksPerBatch,
|
|
129
103
|
rapidsnark: process.env.COORDINATOR_RAPIDSNARK_EXE,
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
104
|
+
mode,
|
|
105
|
+
voteTallyZkey: tally.zkey,
|
|
106
|
+
voteTallyWitnessGenerator: tally.witnessGenerator,
|
|
107
|
+
voteTallyWasm: tally.wasm,
|
|
108
|
+
messageProcessorZkey: messageProcessor.zkey,
|
|
109
|
+
messageProcessorWitnessGenerator: messageProcessor.witnessGenerator,
|
|
110
|
+
messageProcessorWasm: messageProcessor.wasm,
|
|
111
|
+
tallyFile: path.resolve("./tally.json"),
|
|
133
112
|
});
|
|
134
|
-
const processProofs = await proofGenerator.generateMpProofs(options);
|
|
135
|
-
const { proofs: tallyProofs, tallyData } = await proofGenerator.generateTallyProofs(hre.network.name, String(hre.network.config.chainId || 1), options);
|
|
136
113
|
return {
|
|
137
114
|
processProofs,
|
|
138
115
|
tallyProofs,
|
|
@@ -151,9 +128,7 @@ let ProofGeneratorService = ProofGeneratorService_1 = class ProofGeneratorServic
|
|
|
151
128
|
* @returns whether the proofs were successfully merged
|
|
152
129
|
*/
|
|
153
130
|
async merge({ maciContractAddress, pollId, approval, sessionKeyAddress, chain }) {
|
|
154
|
-
|
|
155
|
-
const kernelClient = await this.sessionKeysService.generateClientFromSessionKey(sessionKeyAddress, approval, chain);
|
|
156
|
-
const signer = await this.sessionKeysService.getKernelClientSigner(kernelClient);
|
|
131
|
+
const signer = await this.sessionKeysService.getCoordinatorSigner(chain, sessionKeyAddress, approval);
|
|
157
132
|
await mergeSignups({
|
|
158
133
|
maciAddress: maciContractAddress,
|
|
159
134
|
pollId: BigInt(pollId),
|
|
@@ -166,74 +141,19 @@ let ProofGeneratorService = ProofGeneratorService_1 = class ProofGeneratorServic
|
|
|
166
141
|
*
|
|
167
142
|
* @param args - submit proofs on-chain arguments
|
|
168
143
|
*/
|
|
169
|
-
async submit({ maciContractAddress, pollId, chain }) {
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
});
|
|
178
|
-
const pollAddress = pollContracts.poll;
|
|
179
|
-
if (pollAddress.toLowerCase() === ZeroAddress.toLowerCase()) {
|
|
180
|
-
this.logger.error(`Error: ${ErrorCodes.POLL_NOT_FOUND}, Poll ${pollId} not found`);
|
|
181
|
-
throw new Error(ErrorCodes.POLL_NOT_FOUND.toString());
|
|
182
|
-
}
|
|
183
|
-
// check if state tree has been merged
|
|
184
|
-
const isStateMerged = await publicClient.readContract({
|
|
185
|
-
address: pollAddress,
|
|
186
|
-
abi: PollFactory.abi,
|
|
187
|
-
functionName: "stateMerged",
|
|
144
|
+
async submit({ maciContractAddress, pollId, sessionKeyAddress, approval, chain, }) {
|
|
145
|
+
const signer = await this.sessionKeysService.getCoordinatorSigner(chain, sessionKeyAddress, approval);
|
|
146
|
+
const tallyData = await proveOnChain({
|
|
147
|
+
pollId: BigInt(pollId),
|
|
148
|
+
maciAddress: maciContractAddress,
|
|
149
|
+
proofDir: "./proofs",
|
|
150
|
+
tallyFile: "./tally.json",
|
|
151
|
+
signer,
|
|
188
152
|
});
|
|
189
|
-
if (!
|
|
190
|
-
|
|
191
|
-
throw new Error(ErrorCodes.NOT_MERGED_STATE_TREE.toString());
|
|
153
|
+
if (!tallyData) {
|
|
154
|
+
throw new Error("Tally data is undefined");
|
|
192
155
|
}
|
|
193
|
-
|
|
194
|
-
this.deployment.getContract({
|
|
195
|
-
name: EContracts.MACI,
|
|
196
|
-
address: maciContractAddress,
|
|
197
|
-
}),
|
|
198
|
-
this.deployment.getContract({
|
|
199
|
-
name: EContracts.MessageProcessor,
|
|
200
|
-
address: pollContracts.messageProcessor,
|
|
201
|
-
}),
|
|
202
|
-
this.deployment.getContract({
|
|
203
|
-
name: EContracts.Poll,
|
|
204
|
-
address: pollContracts.poll,
|
|
205
|
-
}),
|
|
206
|
-
this.deployment.getContract({
|
|
207
|
-
name: EContracts.Tally,
|
|
208
|
-
address: pollContracts.tally,
|
|
209
|
-
}),
|
|
210
|
-
this.deployment.getContract({ name: EContracts.VkRegistry }),
|
|
211
|
-
this.deployment.getContract({ name: EContracts.Verifier }),
|
|
212
|
-
]);
|
|
213
|
-
const prover = new Prover({
|
|
214
|
-
maciContract,
|
|
215
|
-
mpContract,
|
|
216
|
-
pollContract,
|
|
217
|
-
tallyContract,
|
|
218
|
-
vkRegistryContract,
|
|
219
|
-
verifierContract,
|
|
220
|
-
});
|
|
221
|
-
const data = {
|
|
222
|
-
processProofs: await this.readProofs(path.resolve("./proofs"), "process"),
|
|
223
|
-
tallyProofs: await this.readProofs(path.resolve("./proofs"), "tally"),
|
|
224
|
-
};
|
|
225
|
-
// prove message processing
|
|
226
|
-
await prover.proveMessageProcessing(data.processProofs);
|
|
227
|
-
// read tally data
|
|
228
|
-
const tallyData = await fs.promises
|
|
229
|
-
.readFile("./tally.json", "utf8")
|
|
230
|
-
.then((result) => JSON.parse(result));
|
|
231
|
-
// prove tally
|
|
232
|
-
await prover.proveTally(data.tallyProofs);
|
|
233
|
-
// submit results
|
|
234
|
-
const voteOptions = Number(await pollContract.voteOptions());
|
|
235
|
-
await prover.submitResults(tallyData, voteOptions);
|
|
236
|
-
return true;
|
|
156
|
+
return tallyData;
|
|
237
157
|
}
|
|
238
158
|
};
|
|
239
159
|
ProofGeneratorService = ProofGeneratorService_1 = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proof.service.js","sourceRoot":"","sources":["../../../ts/proof/proof.service.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"proof.service.js","sourceRoot":"","sources":["../../../ts/proof/proof.service.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3E,OAAO,EACL,UAAU,EACV,UAAU,EAGV,OAAO,EACP,YAAY,EACZ,KAAK,GACN,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAsB,cAAc,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACtF,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,GAAG,MAAM,SAAS,CAAC;AAE1B,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAIxB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAExE;;GAEG;AAEI,IAAM,qBAAqB,6BAA3B,MAAM,qBAAqB;IAeb;IACA;IACA;IAhBnB;;OAEG;IACc,UAAU,CAAa;IAExC;;OAEG;IACc,MAAM,CAAS;IAEhC;;OAEG;IACH,YACmB,aAA4B,EAC5B,WAAwB,EACxB,kBAAsC;QAFtC,kBAAa,GAAb,aAAa,CAAe;QAC5B,gBAAW,GAAX,WAAW,CAAa;QACxB,uBAAkB,GAAlB,kBAAkB,CAAoB;QAEvD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,WAAW,CAAC,EAAE,GAAG,EAA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mB;YAChC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;YACtB,MAAM;SACP,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAM,CAAC,EACX,mBAAmB,EACnB,MAAM,EACN,iBAAiB,EACjB,QAAQ,EACR,KAAK,GACa;QAClB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,oBAAoB,CAAC,KAAK,EAAE,iBAAiB,EAAE,QAAQ,CAAC,CAAC;QAEtG,MAAM,SAAS,GAAG,MAAM,YAAY,CAAC;YACnC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;YACtB,WAAW,EAAE,mBAAmB;YAChC,QAAQ,EAAE,UAAU;YACpB,SAAS,EAAE,cAAc;YACzB,MAAM;SACP,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC7C,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF,CAAA;AAnLY,qBAAqB;IADjC,UAAU,EAAE;qCAgBuB,aAAa;QACf,WAAW;QACJ,kBAAkB;GAjB9C,qBAAqB,CAmLjC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ITallyData, IProof } from "@maci-protocol/sdk";
|
|
1
|
+
import type { ITallyData, IProof, EMode } from "@maci-protocol/sdk";
|
|
2
2
|
import type { Hex } from "viem";
|
|
3
3
|
import { ESupportedNetworks } from "../common";
|
|
4
4
|
/**
|
|
@@ -24,6 +24,18 @@ export interface IReadProofsResults {
|
|
|
24
24
|
* Interface that represents generate proofs arguments
|
|
25
25
|
*/
|
|
26
26
|
export interface IGenerateArgs {
|
|
27
|
+
/**
|
|
28
|
+
* Approval for the session key
|
|
29
|
+
*/
|
|
30
|
+
approval?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Session key address
|
|
33
|
+
*/
|
|
34
|
+
sessionKeyAddress?: Hex;
|
|
35
|
+
/**
|
|
36
|
+
* Chain
|
|
37
|
+
*/
|
|
38
|
+
chain: ESupportedNetworks;
|
|
27
39
|
/**
|
|
28
40
|
* Poll id
|
|
29
41
|
*/
|
|
@@ -32,14 +44,10 @@ export interface IGenerateArgs {
|
|
|
32
44
|
* Maci contract address
|
|
33
45
|
*/
|
|
34
46
|
maciContractAddress: string;
|
|
35
|
-
/**
|
|
36
|
-
* Tally contract address
|
|
37
|
-
*/
|
|
38
|
-
tallyContractAddress: string;
|
|
39
47
|
/**
|
|
40
48
|
* Whether to use Qv or NonQv
|
|
41
49
|
*/
|
|
42
|
-
|
|
50
|
+
mode: EMode;
|
|
43
51
|
/**
|
|
44
52
|
* Encrypted coordinator private key with RSA public key (see .env.example)
|
|
45
53
|
*/
|
|
@@ -102,11 +110,11 @@ export interface IMergeArgs {
|
|
|
102
110
|
/**
|
|
103
111
|
* Approval for the session key
|
|
104
112
|
*/
|
|
105
|
-
approval
|
|
113
|
+
approval?: string;
|
|
106
114
|
/**
|
|
107
115
|
* Session key address
|
|
108
116
|
*/
|
|
109
|
-
sessionKeyAddress
|
|
117
|
+
sessionKeyAddress?: Hex;
|
|
110
118
|
/**
|
|
111
119
|
* Chain
|
|
112
120
|
*/
|
|
@@ -127,11 +135,11 @@ export interface ISubmitProofsArgs {
|
|
|
127
135
|
/**
|
|
128
136
|
* Approval for the session key
|
|
129
137
|
*/
|
|
130
|
-
approval
|
|
138
|
+
approval?: string;
|
|
131
139
|
/**
|
|
132
140
|
* Session key address
|
|
133
141
|
*/
|
|
134
|
-
sessionKeyAddress
|
|
142
|
+
sessionKeyAddress?: Hex;
|
|
135
143
|
/**
|
|
136
144
|
* Chain
|
|
137
145
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../ts/proof/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,oB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AEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,iBAAiB,CAAC,EAAE,GAAG,CAAC;IAExB;;OAEG;IACH,KAAK,EAAE,kBAAkB,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,iBAAiB,CAAC,EAAE,GAAG,CAAC;IAExB;;OAEG;IACH,KAAK,EAAE,kBAAkB,CAAC;CAC3B"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { KernelAccountClient } from "@zerodev/sdk";
|
|
2
|
+
import { encodeFunctionData } from "viem";
|
|
3
|
+
import { EventEmitter } from "events";
|
|
4
|
+
import type { EIP1193Parameters, EIP1193RequestFn, Hex } from "viem";
|
|
5
|
+
export declare const SafeCreateCallAbi: readonly [{
|
|
6
|
+
readonly name: "performCreate";
|
|
7
|
+
readonly type: "function";
|
|
8
|
+
readonly stateMutability: "nonpayable";
|
|
9
|
+
readonly inputs: readonly [{
|
|
10
|
+
readonly type: "uint256";
|
|
11
|
+
readonly name: "value";
|
|
12
|
+
}, {
|
|
13
|
+
readonly type: "bytes";
|
|
14
|
+
readonly name: "deploymentData";
|
|
15
|
+
}];
|
|
16
|
+
readonly outputs: readonly [{
|
|
17
|
+
readonly type: "address";
|
|
18
|
+
readonly name: "newContract";
|
|
19
|
+
}];
|
|
20
|
+
}, {
|
|
21
|
+
readonly name: "performCreate2";
|
|
22
|
+
readonly type: "function";
|
|
23
|
+
readonly stateMutability: "nonpayable";
|
|
24
|
+
readonly inputs: readonly [{
|
|
25
|
+
readonly type: "uint256";
|
|
26
|
+
readonly name: "value";
|
|
27
|
+
}, {
|
|
28
|
+
readonly type: "bytes";
|
|
29
|
+
readonly name: "deploymentData";
|
|
30
|
+
}, {
|
|
31
|
+
readonly type: "bytes32";
|
|
32
|
+
readonly name: "salt";
|
|
33
|
+
}];
|
|
34
|
+
readonly outputs: readonly [{
|
|
35
|
+
readonly type: "address";
|
|
36
|
+
readonly name: "newContract";
|
|
37
|
+
}];
|
|
38
|
+
}];
|
|
39
|
+
type EncodeExecuteDelegateCallArgs = Parameters<typeof encodeFunctionData<typeof SafeCreateCallAbi, "performCreate">>[0]["args"];
|
|
40
|
+
export declare const encodeSafeCreateCall: (args: EncodeExecuteDelegateCallArgs) => Hex;
|
|
41
|
+
export declare class KernelEIP1193Provider extends EventEmitter {
|
|
42
|
+
private kernelClient;
|
|
43
|
+
constructor(kernelClient: KernelAccountClient);
|
|
44
|
+
request({ method, params }: EIP1193Parameters): ReturnType<EIP1193RequestFn>;
|
|
45
|
+
private handleEthRequestAccounts;
|
|
46
|
+
private handleEthAccounts;
|
|
47
|
+
private handleEthSendTransaction;
|
|
48
|
+
private handleEthSign;
|
|
49
|
+
private handlePersonalSign;
|
|
50
|
+
private handleEthSignTypedDataV4;
|
|
51
|
+
}
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=KernelEIP1193Provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KernelEIP1193Provider.d.ts","sourceRoot":"","sources":["../../../../ts/sessionKeys/provider/KernelEIP1193Provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,kBAAkB,EAAY,MAAM,MAAM,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAQ,GAAG,EAA8C,MAAM,MAAM,CAAC;AAEvH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAG5B,CAAC;AAEH,KAAK,6BAA6B,GAAG,UAAU,CAC7C,OAAO,kBAAkB,CAAC,OAAO,iBAAiB,EAAE,eAAe,CAAC,CACrE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAEb,eAAO,MAAM,oBAAoB,GAAI,MAAM,6BAA6B,KAAG,GAKvE,CAAC;AAEL,qBAAa,qBAAsB,SAAQ,YAAY;IACrD,OAAO,CAAC,YAAY,CAAsB;gBAE9B,YAAY,EAAE,mBAAmB;IAKvC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAW,EAAE,EAAE,iBAAiB,GAAG,UAAU,CAAC,gBAAgB,CAAC;IAoBvF,OAAO,CAAC,wBAAwB;IAQhC,OAAO,CAAC,iBAAiB;YAQX,wBAAwB;YAexB,aAAa;YAiBb,kBAAkB;YAiBlB,wBAAwB;CA0BvC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { safeCreateCallAddress } from "@zerodev/sdk/constants";
|
|
2
|
+
import { encodeFunctionData, parseAbi } from "viem";
|
|
3
|
+
import { EventEmitter } from "events";
|
|
4
|
+
export const SafeCreateCallAbi = parseAbi([
|
|
5
|
+
"function performCreate(uint256 value, bytes memory deploymentData) public returns (address newContract)",
|
|
6
|
+
"function performCreate2(uint256 value, bytes memory deploymentData, bytes32 salt) public returns (address newContract)",
|
|
7
|
+
]);
|
|
8
|
+
export const encodeSafeCreateCall = (args) => encodeFunctionData({
|
|
9
|
+
abi: SafeCreateCallAbi,
|
|
10
|
+
functionName: "performCreate",
|
|
11
|
+
args,
|
|
12
|
+
});
|
|
13
|
+
export class KernelEIP1193Provider extends EventEmitter {
|
|
14
|
+
kernelClient;
|
|
15
|
+
constructor(kernelClient) {
|
|
16
|
+
super();
|
|
17
|
+
this.kernelClient = kernelClient;
|
|
18
|
+
}
|
|
19
|
+
async request({ method, params = [] }) {
|
|
20
|
+
switch (method) {
|
|
21
|
+
case "eth_requestAccounts":
|
|
22
|
+
return this.handleEthRequestAccounts();
|
|
23
|
+
case "eth_accounts":
|
|
24
|
+
return this.handleEthAccounts();
|
|
25
|
+
case "eth_sendTransaction":
|
|
26
|
+
return this.handleEthSendTransaction(params);
|
|
27
|
+
case "eth_sign":
|
|
28
|
+
return this.handleEthSign(params);
|
|
29
|
+
case "personal_sign":
|
|
30
|
+
return this.handlePersonalSign(params);
|
|
31
|
+
case "eth_signTypedData":
|
|
32
|
+
case "eth_signTypedData_v4":
|
|
33
|
+
return this.handleEthSignTypedDataV4(params);
|
|
34
|
+
default:
|
|
35
|
+
return this.kernelClient.transport.request({ method, params });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
handleEthRequestAccounts() {
|
|
39
|
+
if (!this.kernelClient.account) {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
return [this.kernelClient.account.address];
|
|
43
|
+
}
|
|
44
|
+
handleEthAccounts() {
|
|
45
|
+
if (!this.kernelClient.account) {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
return [this.kernelClient.account.address];
|
|
49
|
+
}
|
|
50
|
+
async handleEthSendTransaction(params) {
|
|
51
|
+
const [tx] = params;
|
|
52
|
+
if (!("to" in tx) && tx.data) {
|
|
53
|
+
// contract deployment
|
|
54
|
+
tx.data = encodeSafeCreateCall([0n, tx.data]);
|
|
55
|
+
tx.to = safeCreateCallAddress;
|
|
56
|
+
return this.kernelClient.sendTransaction(tx);
|
|
57
|
+
}
|
|
58
|
+
// eth transaction (function call or eth transfer)
|
|
59
|
+
return this.kernelClient.sendTransaction(tx);
|
|
60
|
+
}
|
|
61
|
+
async handleEthSign(params) {
|
|
62
|
+
if (!this.kernelClient.account) {
|
|
63
|
+
throw new Error("account not connected!");
|
|
64
|
+
}
|
|
65
|
+
const [address, message] = params;
|
|
66
|
+
if (address.toLowerCase() !== this.kernelClient.account.address.toLowerCase()) {
|
|
67
|
+
throw new Error("cannot sign for address that is not the current account");
|
|
68
|
+
}
|
|
69
|
+
return this.kernelClient.signMessage({
|
|
70
|
+
message,
|
|
71
|
+
account: this.kernelClient.account,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async handlePersonalSign(params) {
|
|
75
|
+
if (!this.kernelClient.account) {
|
|
76
|
+
throw new Error("account not connected!");
|
|
77
|
+
}
|
|
78
|
+
const [message, address] = params;
|
|
79
|
+
if (address.toLowerCase() !== this.kernelClient.account.address.toLowerCase()) {
|
|
80
|
+
throw new Error("cannot sign for address that is not the current account");
|
|
81
|
+
}
|
|
82
|
+
return this.kernelClient.signMessage({
|
|
83
|
+
message,
|
|
84
|
+
account: this.kernelClient.account,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
async handleEthSignTypedDataV4(params) {
|
|
88
|
+
if (!this.kernelClient.account) {
|
|
89
|
+
throw new Error("account not connected!");
|
|
90
|
+
}
|
|
91
|
+
const [address, typedDataJSON] = params;
|
|
92
|
+
const typedData = JSON.parse(typedDataJSON);
|
|
93
|
+
if (address.toLowerCase() !== this.kernelClient.account.address.toLowerCase()) {
|
|
94
|
+
throw new Error("cannot sign for address that is not the current account");
|
|
95
|
+
}
|
|
96
|
+
return this.kernelClient.signTypedData({
|
|
97
|
+
account: this.kernelClient.account,
|
|
98
|
+
domain: typedData.domain,
|
|
99
|
+
types: typedData.types,
|
|
100
|
+
message: typedData.message,
|
|
101
|
+
primaryType: typedData.primaryType,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=KernelEIP1193Provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KernelEIP1193Provider.js","sourceRoot":"","sources":["../../../../ts/sessionKeys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EAAE,CAAC;YAC9E,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;QAC7E,CAAC;QAED,OAAO,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC;YACrC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,OAAO;YAClC,MAAM,EAAE,SAAS,CAAC,MAAM;YACxB,KAAK,EAAE,SAAS,CAAC,KAAK;YACtB,OAAO,EAAE,SAAS,CAAC,OAAO;YAC1B,WAAW,EAAE,SAAS,CAAC,WAAW;SACnC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Signer } from "ethers";
|
|
2
|
+
import type { AASigner } from "@maci-protocol/contracts";
|
|
2
3
|
import type { Hex } from "viem";
|
|
3
4
|
import { ESupportedNetworks, KernelClientType } from "../common";
|
|
4
5
|
import { FileService } from "../file/file.service";
|
|
@@ -39,7 +40,17 @@ export declare class SessionKeysService {
|
|
|
39
40
|
* @param kernelClient - kernel client
|
|
40
41
|
* @returns signer
|
|
41
42
|
*/
|
|
42
|
-
getKernelClientSigner(kernelClient: KernelClientType): Promise<
|
|
43
|
+
getKernelClientSigner(kernelClient: KernelClientType): Promise<AASigner>;
|
|
44
|
+
/**
|
|
45
|
+
* Get a signer that would execute all the contract interactions in the coordinator service.
|
|
46
|
+
* There are particular cases where the AA signer does not work so we default to the normal signer.
|
|
47
|
+
* (e.g. `deployPoll`)
|
|
48
|
+
* @param chain - the chain to use
|
|
49
|
+
* @param sessionKeyAddress - the address of the session key. Defaults to normal signer if not provided
|
|
50
|
+
* @param approval - the approval string. Defaults to normal signer if not provided
|
|
51
|
+
* @returns a signer
|
|
52
|
+
*/
|
|
53
|
+
getCoordinatorSigner(chain: ESupportedNetworks, sessionKeyAddress?: Hex, approval?: string): Promise<AASigner | Signer>;
|
|
43
54
|
/**
|
|
44
55
|
* Deactivate a session key
|
|
45
56
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessionKeys.service.d.ts","sourceRoot":"","sources":["../../../ts/sessionKeys/sessionKeys.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sessionKeys.service.d.ts","sourceRoot":"","sources":["../../../ts/sessionKeys/sessionKeys.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAEhC,OAAO,EAAc,kBAAkB,EAAa,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAExF,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAEpD;;GAEG;AACH,qBACa,kBAAkB;IAWjB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAVxC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC;;;;OAIG;gBAC0B,WAAW,EAAE,WAAW;IAIrD;;;;OAIG;IACG,kBAAkB,IAAI,OAAO,CAAC,yBAAyB,CAAC;IAiB9D;;;;;;;OAOG;IACG,4BAA4B,CAChC,iBAAiB,EAAE,GAAG,EACtB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,kBAAkB,GACxB,OAAO,CAAC,gBAAgB,CAAC;IAkB5B;;;;;OAKG;IACG,qBAAqB,CAAC,YAAY,EAAE,gBAAgB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAU9E;;;;;;;;OAQG;IACG,oBAAoB,CACxB,KAAK,EAAE,kBAAkB,EACzB,iBAAiB,CAAC,EAAE,GAAG,EACvB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC;IAS7B;;;;OAIG;IACH,oBAAoB,CAAC,iBAAiB,EAAE,GAAG,GAAG,IAAI;CAGnD"}
|
|
@@ -10,12 +10,12 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
var SessionKeysService_1;
|
|
11
11
|
import { Injectable, Logger } from "@nestjs/common";
|
|
12
12
|
import { toECDSASigner } from "@zerodev/permissions/signers";
|
|
13
|
-
import { KernelEIP1193Provider } from "@zerodev/sdk";
|
|
14
13
|
import { BrowserProvider } from "ethers";
|
|
15
14
|
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
|
|
16
|
-
import { ErrorCodes } from "../common";
|
|
15
|
+
import { ErrorCodes, getSigner } from "../common";
|
|
17
16
|
import { getKernelClient } from "../common/accountAbstraction";
|
|
18
17
|
import { FileService } from "../file/file.service";
|
|
18
|
+
import { KernelEIP1193Provider } from "./provider/KernelEIP1193Provider";
|
|
19
19
|
/**
|
|
20
20
|
* SessionKeysService is responsible for generating and managing session keys.
|
|
21
21
|
*/
|
|
@@ -71,7 +71,7 @@ let SessionKeysService = SessionKeysService_1 = class SessionKeysService {
|
|
|
71
71
|
return kernelClient;
|
|
72
72
|
}
|
|
73
73
|
catch (error) {
|
|
74
|
-
this.logger.error(
|
|
74
|
+
this.logger.error("Error:", error);
|
|
75
75
|
throw new Error(ErrorCodes.INVALID_APPROVAL.toString());
|
|
76
76
|
}
|
|
77
77
|
}
|
|
@@ -85,7 +85,25 @@ let SessionKeysService = SessionKeysService_1 = class SessionKeysService {
|
|
|
85
85
|
const kernelProvider = new KernelEIP1193Provider(kernelClient);
|
|
86
86
|
const ethersProvider = new BrowserProvider(kernelProvider);
|
|
87
87
|
const signer = await ethersProvider.getSigner();
|
|
88
|
-
|
|
88
|
+
const aaSigner = signer;
|
|
89
|
+
aaSigner.isAA = true;
|
|
90
|
+
return aaSigner;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get a signer that would execute all the contract interactions in the coordinator service.
|
|
94
|
+
* There are particular cases where the AA signer does not work so we default to the normal signer.
|
|
95
|
+
* (e.g. `deployPoll`)
|
|
96
|
+
* @param chain - the chain to use
|
|
97
|
+
* @param sessionKeyAddress - the address of the session key. Defaults to normal signer if not provided
|
|
98
|
+
* @param approval - the approval string. Defaults to normal signer if not provided
|
|
99
|
+
* @returns a signer
|
|
100
|
+
*/
|
|
101
|
+
async getCoordinatorSigner(chain, sessionKeyAddress, approval) {
|
|
102
|
+
if (sessionKeyAddress && approval) {
|
|
103
|
+
const kernelClient = await this.generateClientFromSessionKey(sessionKeyAddress, approval, chain);
|
|
104
|
+
return this.getKernelClientSigner(kernelClient);
|
|
105
|
+
}
|
|
106
|
+
return getSigner(chain);
|
|
89
107
|
}
|
|
90
108
|
/**
|
|
91
109
|
* Deactivate a session key
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessionKeys.service.js","sourceRoot":"","sources":["../../../ts/sessionKeys/sessionKeys.service.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"sessionKeys.service.js","sourceRoot":"","sources":["../../../ts/sessionKeys/sessionKeys.service.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAU,MAAM,QAAQ,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAKxE,OAAO,EAAE,UAAU,EAAsB,SAAS,EAAoB,MAAM,WAAW,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,k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