@crisp-e3/sdk 0.2.2-test → 0.2.3-test

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.d.cts DELETED
@@ -1,367 +0,0 @@
1
- import { LeanIMTMerkleProof, LeanIMT } from '@zk-kit/lean-imt';
2
- import { ProofData } from '@aztec/bb.js';
3
-
4
- /**
5
- * Get the merkle tree data from the CRISP server
6
- * @param serverUrl - The base URL of the CRISP server
7
- * @param e3Id - The e3Id of the round
8
- */
9
- declare const getTreeData: (serverUrl: string, e3Id: number) => Promise<bigint[]>;
10
- /**
11
- * Get the token balance at a specific block for a given address
12
- * @param voterAddress - The address of the voter
13
- * @param tokenAddress - The address of the token contract
14
- * @param snapshotBlock - The block number at which to get the balance
15
- * @param chainId - The chain ID of the network
16
- * @returns The token balance as a bigint
17
- */
18
- declare const getBalanceAt: (voterAddress: string, tokenAddress: string, snapshotBlock: number, chainId: number) => Promise<bigint>;
19
- /**
20
- * Get the total supply of a ERC20Votes Token at a specific block
21
- * @param tokenAddress The token address to query
22
- * @param snapshotBlock The block number at which to get the total supply
23
- * @param chainId The chain ID of the network
24
- * @returns The total supply as a bigint
25
- */
26
- declare const getTotalSupplyAt: (tokenAddress: string, snapshotBlock: number, chainId: number) => Promise<bigint>;
27
-
28
- /**
29
- * Interface representing the details of a specific round returned by the CRISP server
30
- */
31
- interface IRoundDetailsResponse {
32
- id: string;
33
- chain_id: string;
34
- enclave_address: string;
35
- status: string;
36
- vote_count: string;
37
- start_time: string;
38
- duration: string;
39
- expiration: string;
40
- start_block: string;
41
- committee_public_key: string[];
42
- emojis: [string, string];
43
- token_address: string;
44
- balance_threshold: string;
45
- }
46
- /**
47
- * Interface representing the details of a specific round in a more convenient format
48
- */
49
- interface IRoundDetails {
50
- e3Id: bigint;
51
- chainId: bigint;
52
- enclaveAddress: string;
53
- status: string;
54
- voteCount: bigint;
55
- startTime: bigint;
56
- duration: bigint;
57
- expiration: bigint;
58
- startBlock: bigint;
59
- committeePublicKey: string[];
60
- emojis: [string, string];
61
- tokenAddress: string;
62
- balanceThreshold: bigint;
63
- }
64
- /**
65
- * Interface representing the token details required for participation in a round
66
- */
67
- interface ITokenDetails {
68
- tokenAddress: string;
69
- threshold: bigint;
70
- snapshotBlock: bigint;
71
- }
72
- /**
73
- * Interface representing a Merkle proof
74
- */
75
- interface IMerkleProof {
76
- leaf: bigint;
77
- index: number;
78
- proof: LeanIMTMerkleProof<bigint>;
79
- length: number;
80
- indices: number[];
81
- }
82
- /**
83
- * Enum representing the voting modes
84
- */
85
- declare enum VotingMode {
86
- /**
87
- * Governance voting requires to spend all credits on one option
88
- they cannot be split
89
- */
90
- GOVERNANCE = "GOVERNANCE"
91
- }
92
- /**
93
- * Interface representing a vote with power for 'yes' and 'no'
94
- */
95
- interface IVote {
96
- /**
97
- * The voting power for 'yes' votes
98
- */
99
- yes: bigint;
100
- /**
101
- * The voting power for 'no' votes
102
- */
103
- no: bigint;
104
- }
105
- /**
106
- * Interface representing a vector with coefficients
107
- */
108
- interface Polynomial {
109
- coefficients: string[];
110
- }
111
- /**
112
- * Interface representing cryptographic parameters
113
- */
114
- interface GrecoCryptographicParams {
115
- q_mod_t: string;
116
- qis: string[];
117
- k0is: string[];
118
- }
119
- /**
120
- * Interface representing Greco bounds
121
- */
122
- interface GrecoBoundParams {
123
- e_bound: string;
124
- u_bound: string;
125
- k1_low_bound: string;
126
- k1_up_bound: string;
127
- p1_bounds: string[];
128
- p2_bounds: string[];
129
- pk_bounds: string[];
130
- r1_low_bounds: string[];
131
- r1_up_bounds: string[];
132
- r2_bounds: string[];
133
- }
134
- /**
135
- * Interface representing Greco parameters
136
- */
137
- interface GrecoParams {
138
- crypto: GrecoCryptographicParams;
139
- bounds: GrecoBoundParams;
140
- }
141
- /**
142
- * The inputs required for the CRISP circuit
143
- */
144
- interface CRISPCircuitInputs {
145
- prev_ct0is: Polynomial[];
146
- prev_ct1is: Polynomial[];
147
- sum_ct0is: Polynomial[];
148
- sum_ct1is: Polynomial[];
149
- sum_r0is: Polynomial[];
150
- sum_r1is: Polynomial[];
151
- params: GrecoParams;
152
- ct0is: Polynomial[];
153
- ct1is: Polynomial[];
154
- pk0is: Polynomial[];
155
- pk1is: Polynomial[];
156
- r1is: Polynomial[];
157
- r2is: Polynomial[];
158
- p1is: Polynomial[];
159
- p2is: Polynomial[];
160
- u: Polynomial;
161
- e0: Polynomial;
162
- e1: Polynomial;
163
- e0is: Polynomial[];
164
- k1: Polynomial;
165
- public_key_x: string[];
166
- public_key_y: string[];
167
- signature: string[];
168
- hashed_message: string[];
169
- merkle_root: string;
170
- merkle_proof_length: string;
171
- merkle_proof_indices: string[];
172
- merkle_proof_siblings: string[];
173
- slot_address: string;
174
- balance: string;
175
- is_first_vote: boolean;
176
- }
177
- /**
178
- * Interface representing the BFV parameters
179
- */
180
- interface BFVParams {
181
- degree: number;
182
- plaintextModulus: bigint;
183
- moduli: BigInt64Array;
184
- }
185
- /**
186
- * Interface representing the inputs for Noir signature verification
187
- */
188
- interface NoirSignatureInputs {
189
- /**
190
- * X coordinate of the public key
191
- */
192
- pub_key_x: Uint8Array;
193
- /**
194
- * Y coordinate of the public key
195
- */
196
- pub_key_y: Uint8Array;
197
- /**
198
- * The signature to verify
199
- */
200
- signature: Uint8Array;
201
- /**
202
- * The hashed message that was signed
203
- */
204
- hashed_message: Uint8Array;
205
- }
206
- /**
207
- * Parameters for encryptVoteAndGenerateCRISPInputs function
208
- */
209
- interface EncryptVoteAndGenerateCRISPInputsParams {
210
- encodedVote: string[];
211
- publicKey: Uint8Array;
212
- previousCiphertext: Uint8Array;
213
- signature: `0x${string}`;
214
- message: string;
215
- merkleData: IMerkleProof;
216
- balance: bigint;
217
- bfvParams?: BFVParams;
218
- slotAddress: string;
219
- isFirstVote: boolean;
220
- }
221
-
222
- /**
223
- * Get the details of a specific round
224
- */
225
- declare const getRoundDetails: (serverUrl: string, e3Id: number) => Promise<IRoundDetails>;
226
- /**
227
- * Get the token address, balance threshold and snapshot block for a specific round
228
- * @param serverUrl - The base URL of the CRISP server
229
- * @param e3Id - The e3Id of the round
230
- * @returns The token address, balance threshold and snapshot block
231
- */
232
- declare const getRoundTokenDetails: (serverUrl: string, e3Id: number) => Promise<ITokenDetails>;
233
-
234
- declare const CRISP_SERVER_TOKEN_TREE_ENDPOINT = "state/token-holders";
235
- declare const CRISP_SERVER_STATE_LITE_ENDPOINT = "state/lite";
236
- declare const MERKLE_TREE_MAX_DEPTH = 20;
237
- /**
238
- * Half the minimum degree needed to support the maxium vote value
239
- * If you change MAXIMUM_VOTE_VALUE, make sure to update this value too.
240
- */
241
- declare const HALF_LARGEST_MINIMUM_DEGREE = 28;
242
- /**
243
- * This is the maximum value for a vote (Yes or No). This is 2^28 - 1
244
- * The minimum degree that BFV should use is 56 (to accommodate both Yes and No votes)
245
- */
246
- declare const MAXIMUM_VOTE_VALUE: bigint;
247
- /**
248
- * Default BFV parameters for the CRISP ZK inputs generator.
249
- * These are the parameters used for the default testing purposes only.
250
- */
251
- declare const DEFAULT_BFV_PARAMS: BFVParams;
252
- /**
253
- * Mock message for masking signature
254
- */
255
- declare const MESSAGE = "Vote for round 0";
256
-
257
- /**
258
- * Hash a leaf node for the Merkle tree
259
- * @param address The voter's address
260
- * @param balance The voter's balance
261
- * @returns The hashed leaf as a bigint
262
- */
263
- declare const hashLeaf: (address: string, balance: string) => bigint;
264
- /**
265
- * Generate a new LeanIMT with the leaves provided
266
- * @param leaves The leaves of the Merkle tree
267
- * @returns the generated Merkle tree
268
- */
269
- declare const generateMerkleTree: (leaves: bigint[]) => LeanIMT;
270
- /**
271
- * Generate a Merkle proof for a given address to prove inclusion in the voters' list
272
- * @param threshold The minimum balance required to be eligible
273
- * @param balance The voter's balance
274
- * @param address The voter's address
275
- * @param leaves The leaves of the Merkle tree
276
- */
277
- declare const generateMerkleProof: (threshold: bigint, balance: bigint, address: string, leaves: bigint[]) => IMerkleProof;
278
- /**
279
- * Convert a number to its binary representation
280
- * @param number The number to convert to binary
281
- * @returns The binary representation of the number as a string
282
- */
283
- declare const toBinary: (number: bigint) => string;
284
-
285
- /**
286
- * This utility function calculates the first valid index for vote options
287
- * based on the total voting power and degree.
288
- * @dev This is needed to calculate the decoded plaintext
289
- * @dev Also, we will need to check in the circuit that anything within these indices is
290
- * either 0 or 1.
291
- * @param totalVotingPower The maximum vote amount (if a single voter had all of the power)
292
- * @param degree The degree of the polynomial
293
- */
294
- declare const calculateValidIndicesForPlaintext: (totalVotingPower: bigint, degree: number) => {
295
- yesIndex: number;
296
- noIndex: number;
297
- };
298
- /**
299
- * Encode a vote based on the voting mode
300
- * @param vote The vote to encode
301
- * @param votingMode The voting mode to use for encoding
302
- * @param votingPower The voting power of the voter
303
- * @param bfvParams The BFV parameters to use for encoding
304
- * @returns The encoded vote as a string
305
- */
306
- declare const encodeVote: (vote: IVote, votingMode: VotingMode, votingPower: bigint, bfvParams?: BFVParams) => string[];
307
- /**
308
- * Given an encoded tally, decode it into its decimal representation
309
- * @param tally The encoded tally to decode
310
- * @param votingMode The voting mode
311
- */
312
- declare const decodeTally: (tally: string[], votingMode: VotingMode) => IVote;
313
- /**
314
- * Validate whether a vote is valid for a given voting mode
315
- * @param votingMode The voting mode to validate against
316
- * @param vote The vote to validate
317
- * @param votingPower The voting power of the voter
318
- */
319
- declare const validateVote: (votingMode: VotingMode, vote: IVote, votingPower: bigint) => void;
320
- declare const encryptVote: (encodedVote: string[], publicKey: Uint8Array) => Promise<Uint8Array>;
321
- /**
322
- * This is a wrapper around enclave-e3/sdk encryption functions as CRISP circuit will require some more
323
- * input values which generic Greco do not need.
324
- * @param encodedVote The encoded vote as string array
325
- * @param publicKey The public key to use for encryption
326
- * @param previousCiphertext The previous ciphertext to use for addition operation
327
- * @param bfvParams The BFV parameters to use for encryption
328
- * @param merkleData The merkle proof data
329
- * @param message The message that was signed
330
- * @param signature The signature of the message
331
- * @param balance The voter's balance
332
- * @param slotAddress The voter's slot address
333
- * @param isFirstVote Whether this is the first vote for this slot
334
- * @returns The CRISP circuit inputs
335
- */
336
- declare const encryptVoteAndGenerateCRISPInputs: ({ encodedVote, publicKey, previousCiphertext, bfvParams, merkleData, message, signature, balance, slotAddress, isFirstVote, }: EncryptVoteAndGenerateCRISPInputsParams) => Promise<CRISPCircuitInputs>;
337
- /**
338
- * A function to generate the data required to mask a vote
339
- * @param voter The voter's address
340
- * @param publicKey The voter's public key
341
- * @param previousCiphertext The previous ciphertext
342
- * @param bfvParams The BFV parameters
343
- * @param merkleRoot The merkle root of the census tree
344
- * @param slotAddress The voter's slot address
345
- * @param isFirstVote Whether this is the first vote for this slot
346
- * @returns The CRISP circuit inputs for a mask vote
347
- */
348
- declare const generateMaskVote: (publicKey: Uint8Array, previousCiphertext: Uint8Array, bfvParams: BFVParams | undefined, merkleRoot: bigint, slotAddress: string, isFirstVote: boolean) => Promise<CRISPCircuitInputs>;
349
- declare const generateProof: (crispInputs: CRISPCircuitInputs) => Promise<ProofData>;
350
- declare const generateProofWithReturnValue: (crispInputs: CRISPCircuitInputs) => Promise<{
351
- returnValue: unknown;
352
- proof: ProofData;
353
- }>;
354
- declare const getCircuitOutputValue: (crispInputs: CRISPCircuitInputs) => Promise<{
355
- returnValue: unknown;
356
- }>;
357
- declare const verifyProof: (proof: ProofData) => Promise<boolean>;
358
-
359
- /**
360
- * Given a message and its signed version, extract the signature components
361
- * @param message The original message
362
- * @param signedMessage The signed message (signature)
363
- * @returns The extracted signature components
364
- */
365
- declare const extractSignature: (message: string, signedMessage: `0x${string}`) => Promise<NoirSignatureInputs>;
366
-
367
- export { type CRISPCircuitInputs, CRISP_SERVER_STATE_LITE_ENDPOINT, CRISP_SERVER_TOKEN_TREE_ENDPOINT, DEFAULT_BFV_PARAMS, HALF_LARGEST_MINIMUM_DEGREE, type IMerkleProof, type IRoundDetails, type IRoundDetailsResponse, type ITokenDetails, type IVote, MAXIMUM_VOTE_VALUE, MERKLE_TREE_MAX_DEPTH, MESSAGE, type NoirSignatureInputs, VotingMode, calculateValidIndicesForPlaintext, decodeTally, encodeVote, encryptVote, encryptVoteAndGenerateCRISPInputs, extractSignature, generateMaskVote, generateMerkleProof, generateMerkleTree, generateProof, generateProofWithReturnValue, getBalanceAt, getCircuitOutputValue, getRoundDetails, getRoundTokenDetails, getTotalSupplyAt, getTreeData, hashLeaf, toBinary, validateVote, verifyProof };