@crisp-e3/sdk 0.4.0 → 0.4.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/index.js +17 -7
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
// src/constants.ts
|
|
2
|
-
import os from "os";
|
|
3
2
|
import { hashMessage } from "viem";
|
|
4
3
|
var CRISP_SERVER_TOKEN_TREE_ENDPOINT = "state/token-holders";
|
|
5
4
|
var CRISP_SERVER_STATE_LITE_ENDPOINT = "state/lite";
|
|
6
5
|
var MERKLE_TREE_MAX_DEPTH = 20;
|
|
7
|
-
var OPTIMAL_THREAD_COUNT = Math.max(
|
|
8
|
-
1,
|
|
9
|
-
(typeof os.availableParallelism === "function" ? os.availableParallelism() : os.cpus().length) - 1
|
|
10
|
-
);
|
|
11
6
|
var HALF_LARGEST_MINIMUM_DEGREE = 28;
|
|
12
7
|
var MAXIMUM_VOTE_VALUE = BigInt(Math.pow(2, HALF_LARGEST_MINIMUM_DEGREE) - 1);
|
|
13
8
|
var SIGNATURE_MESSAGE = "CRISP: Sign this message to prove ownership of your Ethereum account";
|
|
@@ -179,6 +174,20 @@ var getAddressFromSignature = async (signature) => {
|
|
|
179
174
|
const publicKey = await recoverPublicKey({ hash: SIGNATURE_MESSAGE_HASH, signature });
|
|
180
175
|
return publicKeyToAddress(publicKey);
|
|
181
176
|
};
|
|
177
|
+
async function getOptimalThreadCount() {
|
|
178
|
+
if (typeof process !== "undefined" && process.versions?.node) {
|
|
179
|
+
try {
|
|
180
|
+
const os = await import("os");
|
|
181
|
+
const cpuCount = typeof os.availableParallelism === "function" ? os.availableParallelism() : os.cpus().length;
|
|
182
|
+
return Math.max(1, cpuCount - 1);
|
|
183
|
+
} catch {
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (typeof navigator !== "undefined" && navigator.hardwareConcurrency) {
|
|
187
|
+
return Math.max(1, navigator.hardwareConcurrency - 1);
|
|
188
|
+
}
|
|
189
|
+
return 5;
|
|
190
|
+
}
|
|
182
191
|
|
|
183
192
|
// src/vote.ts
|
|
184
193
|
import { ZKInputsGenerator } from "@crisp-e3/zk-inputs";
|
|
@@ -191,6 +200,7 @@ var crisp_circuit_default = { noir_version: "1.0.0-beta.15+83245db91dcf63420ef4b
|
|
|
191
200
|
// src/vote.ts
|
|
192
201
|
import { bytesToHex, encodeAbiParameters, parseAbiParameters, numberToHex, getAddress } from "viem/utils";
|
|
193
202
|
var zkInputsGenerator = ZKInputsGenerator.withDefaults();
|
|
203
|
+
var optimalThreadCount = await getOptimalThreadCount();
|
|
194
204
|
var encodeVote = (vote) => {
|
|
195
205
|
const bfvParams = zkInputsGenerator.getBFVParams();
|
|
196
206
|
const voteArray = [];
|
|
@@ -267,7 +277,7 @@ var generateWitness = async (crispInputs) => {
|
|
|
267
277
|
};
|
|
268
278
|
var generateProof = async (crispInputs) => {
|
|
269
279
|
const witness = await generateWitness(crispInputs);
|
|
270
|
-
const backend = new UltraHonkBackend(crisp_circuit_default.bytecode, { threads:
|
|
280
|
+
const backend = new UltraHonkBackend(crisp_circuit_default.bytecode, { threads: optimalThreadCount });
|
|
271
281
|
const proof = await backend.generateProof(witness, { keccakZK: true });
|
|
272
282
|
await backend.destroy();
|
|
273
283
|
return proof;
|
|
@@ -302,7 +312,7 @@ var generateMaskVoteProof = async (maskVoteProofInputs) => {
|
|
|
302
312
|
return generateProof(crispInputs);
|
|
303
313
|
};
|
|
304
314
|
var verifyProof = async (proof) => {
|
|
305
|
-
const backend = new UltraHonkBackend(crisp_circuit_default.bytecode, { threads:
|
|
315
|
+
const backend = new UltraHonkBackend(crisp_circuit_default.bytecode, { threads: optimalThreadCount });
|
|
306
316
|
const isValid = await backend.verifyProof(proof, { keccakZK: true });
|
|
307
317
|
await backend.destroy();
|
|
308
318
|
return isValid;
|