@crisp-e3/sdk 0.11.0 → 0.13.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.
package/dist/index.d.ts CHANGED
@@ -25,26 +25,9 @@ declare const getBalanceAt: (voterAddress: string, tokenAddress: string, snapsho
25
25
  */
26
26
  declare const getTotalSupplyAt: (tokenAddress: string, snapshotBlock: number, chainId: number) => Promise<bigint>;
27
27
 
28
- /**
29
- * Type representing the details of a specific round returned by the CRISP server
30
- */
31
- type RoundDetailsResponse = {
32
- id: string;
33
- chain_id: string;
34
- interfold_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
28
  /**
47
29
  * Type representing the details of a specific round in a more convenient format
30
+ * (camelCase view of the server's `state/lite` response)
48
31
  */
49
32
  type RoundDetails = {
50
33
  e3Id: bigint;
@@ -53,13 +36,27 @@ type RoundDetails = {
53
36
  status: string;
54
37
  voteCount: bigint;
55
38
  startTime: bigint;
56
- duration: bigint;
57
- expiration: bigint;
39
+ endTime: bigint;
58
40
  startBlock: bigint;
59
- committeePublicKey: string[];
41
+ committeePublicKey: Uint8Array;
60
42
  emojis: [string, string];
61
43
  tokenAddress: string;
62
44
  balanceThreshold: bigint;
45
+ numOptions: bigint;
46
+ requester: string;
47
+ creditMode: CreditMode;
48
+ credits?: bigint;
49
+ };
50
+ /**
51
+ * Type representing the round data stored in the CRISPProgram contract
52
+ */
53
+ type OnChainRoundData = {
54
+ merkleRoot: bigint;
55
+ paramsHash: `0x${string}`;
56
+ numOptions: bigint;
57
+ creditMode: CreditMode;
58
+ inputRoot: bigint;
59
+ numberOfVotes: bigint;
63
60
  };
64
61
  /**
65
62
  * Type representing the token details required for participation in a round
@@ -124,6 +121,96 @@ type VoteProofRequest = {
124
121
  messageHash: `0x${string}`;
125
122
  slotAddress: string;
126
123
  };
124
+ /**
125
+ * Type representing the current round returned by the CRISP server (`rounds/current`)
126
+ */
127
+ type CurrentRoundResponse = {
128
+ id: number;
129
+ };
130
+ /**
131
+ * Type representing the lite state of a round returned by the CRISP server (`state/lite`)
132
+ */
133
+ type E3StateLiteResponse = {
134
+ id: number;
135
+ chain_id: number;
136
+ interfold_address: string;
137
+ status: string;
138
+ vote_count: number;
139
+ start_time: number;
140
+ end_time: number;
141
+ start_block: number;
142
+ committee_public_key: number[];
143
+ emojis: [string, string];
144
+ token_address: string;
145
+ balance_threshold: string;
146
+ num_options: string;
147
+ requester: string;
148
+ credit_mode: CreditMode;
149
+ credits: string | null;
150
+ };
151
+ /**
152
+ * Type representing a generic message response from the CRISP server
153
+ */
154
+ type JsonResponse = {
155
+ response: string;
156
+ };
157
+ /**
158
+ * Type representing a request to start a new E3 round (`rounds/request`)
159
+ */
160
+ type NewRoundRequest = {
161
+ cronApiKey: string;
162
+ tokenAddress: string;
163
+ balanceThreshold: string;
164
+ };
165
+ /**
166
+ * Type representing a request to broadcast an encrypted vote (`voting/broadcast`)
167
+ */
168
+ type BroadcastVoteRequest = {
169
+ e3Id: number;
170
+ encodedProof: string;
171
+ address: string;
172
+ };
173
+ /**
174
+ * The status of a vote broadcast returned by the CRISP server
175
+ */
176
+ type VoteResponseStatus = 'success' | 'user_already_voted' | 'failed_broadcast';
177
+ /**
178
+ * Type representing the response to a vote broadcast (`voting/broadcast`)
179
+ */
180
+ type BroadcastVoteResponse = {
181
+ status: VoteResponseStatus;
182
+ tx_hash: string | null;
183
+ message: string | null;
184
+ is_vote_update?: boolean;
185
+ };
186
+ /**
187
+ * Type representing the vote status of an address in a round (`voting/status`)
188
+ */
189
+ type VoteStatusResponse = {
190
+ round_id: number;
191
+ address: string;
192
+ has_voted: boolean;
193
+ round_status: string | null;
194
+ };
195
+ /**
196
+ * Type representing the result of a round (`state/result` and `state/all`)
197
+ */
198
+ type WebResultResponse = {
199
+ round_id: number;
200
+ tally: string[];
201
+ option_1_emoji: string;
202
+ option_2_emoji: string;
203
+ total_votes: number;
204
+ end_time: number;
205
+ requester: string;
206
+ };
207
+ /**
208
+ * Type representing a token holder with their address and balance (`state/eligible-addresses`)
209
+ */
210
+ type TokenHolder = {
211
+ address: string;
212
+ balance: string;
213
+ };
127
214
  /**
128
215
  * Enum representing the credit mode for a round, which can be either constant or custom.
129
216
  * In constant mode, all voters receive the same amount of credits, while in custom mode,
@@ -135,7 +222,10 @@ declare enum CreditMode {
135
222
  }
136
223
 
137
224
  /**
138
- * Get the details of a specific round
225
+ * Get the details of a specific round in a camelCase convenience format
226
+ * @param serverUrl - The base URL of the CRISP server
227
+ * @param e3Id - The e3Id of the round
228
+ * @returns The round details
139
229
  */
140
230
  declare const getRoundDetails: (serverUrl: string, e3Id: number) => Promise<RoundDetails>;
141
231
  /**
@@ -145,6 +235,19 @@ declare const getRoundDetails: (serverUrl: string, e3Id: number) => Promise<Roun
145
235
  * @returns The token address, balance threshold and snapshot block
146
236
  */
147
237
  declare const getRoundTokenDetails: (serverUrl: string, e3Id: number) => Promise<TokenDetails>;
238
+ /**
239
+ * Get the round data stored in the CRISPProgram contract, such as the merkle root
240
+ * of the census and the merkle root of the encrypted votes published so far.
241
+ *
242
+ * Unlike {@link getRoundDetails}, this reads directly from the chain and so does not
243
+ * depend on the CRISP server.
244
+ *
245
+ * @param programAddress - The address of the CRISPProgram contract
246
+ * @param e3Id - The e3Id of the round
247
+ * @param chainId - The chain ID of the network the program is deployed on
248
+ * @returns The on chain round data
249
+ */
250
+ declare const getOnChainRoundData: (programAddress: string, e3Id: number, chainId: number) => Promise<OnChainRoundData>;
148
251
  /**
149
252
  * Get the previous ciphertext for a slot from the CRISP server.
150
253
  * Returns undefined when the slot is empty (404).
@@ -156,6 +259,88 @@ declare const getRoundTokenDetails: (serverUrl: string, e3Id: number) => Promise
156
259
  */
157
260
  declare const getPreviousCiphertext: (serverUrl: string, e3Id: number, address: string) => Promise<Uint8Array | undefined>;
158
261
 
262
+ /**
263
+ * Get the current (most recent) round, optionally filtered by requester addresses.
264
+ * Returns undefined when no current round exists (404).
265
+ * @param serverUrl - The base URL of the CRISP server
266
+ * @param requesters - Optional list of requester addresses to filter by (only the first is used by the server)
267
+ * @returns The current round id, or undefined if none exists
268
+ */
269
+ declare const getCurrentRound: (serverUrl: string, requesters?: string[]) => Promise<CurrentRoundResponse | undefined>;
270
+ /**
271
+ * Get the committee public key for a given round.
272
+ * @param serverUrl - The base URL of the CRISP server
273
+ * @param e3Id - The e3Id of the round
274
+ * @returns The committee public key bytes
275
+ */
276
+ declare const getRoundPublicKey: (serverUrl: string, e3Id: number) => Promise<Uint8Array>;
277
+ /**
278
+ * Get the ciphertext output for a given round.
279
+ * @param serverUrl - The base URL of the CRISP server
280
+ * @param e3Id - The e3Id of the round
281
+ * @returns The ciphertext output bytes
282
+ */
283
+ declare const getRoundCiphertext: (serverUrl: string, e3Id: number) => Promise<Uint8Array>;
284
+ /**
285
+ * Request a new E3 round. Requires the server's cron API key.
286
+ * @param serverUrl - The base URL of the CRISP server
287
+ * @param request - The new round request (cron API key, token address and balance threshold)
288
+ * @returns The server confirmation message
289
+ */
290
+ declare const requestNewRound: (serverUrl: string, request: NewRoundRequest) => Promise<JsonResponse>;
291
+ /**
292
+ * Broadcast an encrypted vote through the CRISP server, which relays it on-chain.
293
+ * @param serverUrl - The base URL of the CRISP server
294
+ * @param request - The vote request (round id, hex encoded proof and voter address)
295
+ * @returns The broadcast result, including the transaction hash on success
296
+ */
297
+ declare const broadcastVote: (serverUrl: string, request: BroadcastVoteRequest) => Promise<BroadcastVoteResponse>;
298
+ /**
299
+ * Get the vote status for an address in a specific round.
300
+ * @param serverUrl - The base URL of the CRISP server
301
+ * @param e3Id - The e3Id of the round
302
+ * @param address - The voter address
303
+ * @returns The vote status for the address
304
+ */
305
+ declare const getVoteStatus: (serverUrl: string, e3Id: number, address: string) => Promise<VoteStatusResponse>;
306
+ /**
307
+ * Get the result for a given round.
308
+ * @param serverUrl - The base URL of the CRISP server
309
+ * @param e3Id - The e3Id of the round
310
+ * @returns The round result (tally, emojis, total votes, end time and requester)
311
+ */
312
+ declare const getRoundResult: (serverUrl: string, e3Id: number) => Promise<WebResultResponse>;
313
+ /**
314
+ * Get the results for all rounds, optionally filtered by requester addresses.
315
+ * @param serverUrl - The base URL of the CRISP server
316
+ * @param requesters - Optional list of requester addresses to filter by
317
+ * @returns The results for all matching rounds
318
+ */
319
+ declare const getAllRoundResults: (serverUrl: string, requesters?: string[]) => Promise<WebResultResponse[]>;
320
+ /**
321
+ * Get the lite state for a given round, as returned by the server (snake_case fields).
322
+ * See `getRoundDetails` in `state.ts` for a camelCase convenience wrapper over this endpoint.
323
+ * @param serverUrl - The base URL of the CRISP server
324
+ * @param e3Id - The e3Id of the round
325
+ * @returns The lite round state
326
+ */
327
+ declare const getRoundStateLite: (serverUrl: string, e3Id: number) => Promise<E3StateLiteResponse>;
328
+ /**
329
+ * Get the token holder hashes (hash(address, balance)) for a given round.
330
+ * These are the Merkle tree leaves used for eligibility proofs.
331
+ * @param serverUrl - The base URL of the CRISP server
332
+ * @param e3Id - The e3Id of the round
333
+ * @returns The list of token holder hashes
334
+ */
335
+ declare const getTokenHolderHashes: (serverUrl: string, e3Id: number) => Promise<string[]>;
336
+ /**
337
+ * Get the eligible addresses and their balances for a given round.
338
+ * @param serverUrl - The base URL of the CRISP server
339
+ * @param e3Id - The e3Id of the round
340
+ * @returns The list of eligible token holders
341
+ */
342
+ declare const getEligibleAddresses: (serverUrl: string, e3Id: number) => Promise<TokenHolder[]>;
343
+
159
344
  declare const MERKLE_TREE_MAX_DEPTH = 20;
160
345
  declare const MAX_MSG_NON_ZERO_COEFFS = 100;
161
346
  declare const MAX_VOTE_OPTIONS = 10;
@@ -309,6 +494,104 @@ declare class CrispSDK {
309
494
  * @returns A promise that resolves to the generated proof data.
310
495
  */
311
496
  generateVoteProof(voteProofInputs: VoteProofRequest): Promise<ProofData>;
497
+ /**
498
+ * Get the current (most recent) round, optionally filtered by requester addresses.
499
+ * @param requesters - Optional list of requester addresses to filter by
500
+ * @returns The current round id, or undefined if no round exists
501
+ */
502
+ getCurrentRound(requesters?: string[]): Promise<CurrentRoundResponse | undefined>;
503
+ /**
504
+ * Get the committee public key for a given round.
505
+ * @param e3Id - The e3Id of the round
506
+ * @returns The committee public key bytes
507
+ */
508
+ getRoundPublicKey(e3Id: number): Promise<Uint8Array>;
509
+ /**
510
+ * Get the ciphertext output for a given round.
511
+ * @param e3Id - The e3Id of the round
512
+ * @returns The ciphertext output bytes
513
+ */
514
+ getRoundCiphertext(e3Id: number): Promise<Uint8Array>;
515
+ /**
516
+ * Request a new E3 round. Requires the server's cron API key.
517
+ * @param request - The new round request (cron API key, token address and balance threshold)
518
+ * @returns The server confirmation message
519
+ */
520
+ requestNewRound(request: NewRoundRequest): Promise<JsonResponse>;
521
+ /**
522
+ * Broadcast an encrypted vote through the CRISP server, which relays it on-chain.
523
+ * @param request - The vote request (round id, hex encoded proof and voter address)
524
+ * @returns The broadcast result, including the transaction hash on success
525
+ */
526
+ broadcastVote(request: BroadcastVoteRequest): Promise<BroadcastVoteResponse>;
527
+ /**
528
+ * Get the vote status for an address in a specific round.
529
+ * @param e3Id - The e3Id of the round
530
+ * @param address - The voter address
531
+ * @returns The vote status for the address
532
+ */
533
+ getVoteStatus(e3Id: number, address: string): Promise<VoteStatusResponse>;
534
+ /**
535
+ * Get the result for a given round.
536
+ * @param e3Id - The e3Id of the round
537
+ * @returns The round result (tally, emojis, total votes, end time and requester)
538
+ */
539
+ getRoundResult(e3Id: number): Promise<WebResultResponse>;
540
+ /**
541
+ * Get the results for all rounds, optionally filtered by requester addresses.
542
+ * @param requesters - Optional list of requester addresses to filter by
543
+ * @returns The results for all matching rounds
544
+ */
545
+ getAllRoundResults(requesters?: string[]): Promise<WebResultResponse[]>;
546
+ /**
547
+ * Get the lite state for a given round, as returned by the server (snake_case fields).
548
+ * @param e3Id - The e3Id of the round
549
+ * @returns The lite round state
550
+ */
551
+ getRoundStateLite(e3Id: number): Promise<E3StateLiteResponse>;
552
+ /**
553
+ * Get the details of a specific round in a camelCase convenience format.
554
+ * @param e3Id - The e3Id of the round
555
+ * @returns The round details
556
+ */
557
+ getRoundDetails(e3Id: number): Promise<RoundDetails>;
558
+ /**
559
+ * Get the round data stored in the CRISPProgram contract, read directly from the chain.
560
+ *
561
+ * When the chain id is omitted it is looked up on the CRISP server.
562
+ *
563
+ * @param programAddress - The address of the CRISPProgram contract
564
+ * @param e3Id - The e3Id of the round
565
+ * @param chainId - The chain ID of the network the program is deployed on
566
+ * @returns The on chain round data
567
+ */
568
+ getOnChainRoundData(programAddress: string, e3Id: number, chainId?: number): Promise<OnChainRoundData>;
569
+ /**
570
+ * Get the token address, balance threshold and snapshot block for a specific round.
571
+ * @param e3Id - The e3Id of the round
572
+ * @returns The token details
573
+ */
574
+ getRoundTokenDetails(e3Id: number): Promise<TokenDetails>;
575
+ /**
576
+ * Get the token holder hashes (hash(address, balance)) for a given round.
577
+ * These are the Merkle tree leaves used for eligibility proofs.
578
+ * @param e3Id - The e3Id of the round
579
+ * @returns The list of token holder hashes
580
+ */
581
+ getTokenHolderHashes(e3Id: number): Promise<string[]>;
582
+ /**
583
+ * Get the eligible addresses and their balances for a given round.
584
+ * @param e3Id - The e3Id of the round
585
+ * @returns The list of eligible token holders
586
+ */
587
+ getEligibleAddresses(e3Id: number): Promise<TokenHolder[]>;
588
+ /**
589
+ * Get the previous ciphertext input for a slot address in a given round.
590
+ * @param e3Id - The e3Id of the round
591
+ * @param address - The address of the slot
592
+ * @returns The previous ciphertext, or undefined if the slot is empty
593
+ */
594
+ getPreviousCiphertext(e3Id: number, address: string): Promise<Uint8Array | undefined>;
312
595
  }
313
596
 
314
- export { CreditMode, CrispSDK, MAX_MSG_NON_ZERO_COEFFS, MAX_VOTE_OPTIONS, MERKLE_TREE_MAX_DEPTH, type MaskVoteProofInputs, type ProofData, type RoundDetails, type RoundDetailsResponse, SIGNATURE_MESSAGE, SIGNATURE_MESSAGE_HASH, type TokenDetails, type Vote, type VoteProofInputs, decodeTally, destroyBBApi, encodeSolidityProof, encryptVote, generateBFVKeys, generateMaskVoteProof, generateMerkleProof, generateMerkleTree, generateVoteProof, getAddressFromSignature, getBalanceAt, getMaxVoteValue, getPreviousCiphertext, getRoundDetails, getRoundTokenDetails, getScaledBalance, getTotalSupplyAt, getTreeData, getZeroVote, hashLeaf, validateVote, verifyProof };
597
+ export { type BroadcastVoteRequest, type BroadcastVoteResponse, CreditMode, CrispSDK, type CurrentRoundResponse, type E3StateLiteResponse, type JsonResponse, MAX_MSG_NON_ZERO_COEFFS, MAX_VOTE_OPTIONS, MERKLE_TREE_MAX_DEPTH, type MaskVoteProofInputs, type NewRoundRequest, type OnChainRoundData, type ProofData, type RoundDetails, SIGNATURE_MESSAGE, SIGNATURE_MESSAGE_HASH, type TokenDetails, type TokenHolder, type Vote, type VoteProofInputs, type VoteResponseStatus, type VoteStatusResponse, type WebResultResponse, broadcastVote, decodeTally, destroyBBApi, encodeSolidityProof, encryptVote, generateBFVKeys, generateMaskVoteProof, generateMerkleProof, generateMerkleTree, generateVoteProof, getAddressFromSignature, getAllRoundResults, getBalanceAt, getCurrentRound, getEligibleAddresses, getMaxVoteValue, getOnChainRoundData, getPreviousCiphertext, getRoundCiphertext, getRoundDetails, getRoundPublicKey, getRoundResult, getRoundStateLite, getRoundTokenDetails, getScaledBalance, getTokenHolderHashes, getTotalSupplyAt, getTreeData, getVoteStatus, getZeroVote, hashLeaf, requestNewRound, validateVote, verifyProof };