@crisp-e3/sdk 0.11.0 → 0.12.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/.tsbuildinfo +1 -0
- package/dist/index.d.ts +271 -23
- package/dist/index.js +220 -15
- package/dist/index.js.map +1 -1
- package/dist/workers/generateCircuitInputs.worker.js.map +1 -1
- package/package.json +2 -2
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,16 @@ type RoundDetails = {
|
|
|
53
36
|
status: string;
|
|
54
37
|
voteCount: bigint;
|
|
55
38
|
startTime: bigint;
|
|
56
|
-
|
|
57
|
-
expiration: bigint;
|
|
39
|
+
endTime: bigint;
|
|
58
40
|
startBlock: bigint;
|
|
59
|
-
committeePublicKey:
|
|
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;
|
|
63
49
|
};
|
|
64
50
|
/**
|
|
65
51
|
* Type representing the token details required for participation in a round
|
|
@@ -124,6 +110,96 @@ type VoteProofRequest = {
|
|
|
124
110
|
messageHash: `0x${string}`;
|
|
125
111
|
slotAddress: string;
|
|
126
112
|
};
|
|
113
|
+
/**
|
|
114
|
+
* Type representing the current round returned by the CRISP server (`rounds/current`)
|
|
115
|
+
*/
|
|
116
|
+
type CurrentRoundResponse = {
|
|
117
|
+
id: number;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Type representing the lite state of a round returned by the CRISP server (`state/lite`)
|
|
121
|
+
*/
|
|
122
|
+
type E3StateLiteResponse = {
|
|
123
|
+
id: number;
|
|
124
|
+
chain_id: number;
|
|
125
|
+
interfold_address: string;
|
|
126
|
+
status: string;
|
|
127
|
+
vote_count: number;
|
|
128
|
+
start_time: number;
|
|
129
|
+
end_time: number;
|
|
130
|
+
start_block: number;
|
|
131
|
+
committee_public_key: number[];
|
|
132
|
+
emojis: [string, string];
|
|
133
|
+
token_address: string;
|
|
134
|
+
balance_threshold: string;
|
|
135
|
+
num_options: string;
|
|
136
|
+
requester: string;
|
|
137
|
+
credit_mode: CreditMode;
|
|
138
|
+
credits: string | null;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Type representing a generic message response from the CRISP server
|
|
142
|
+
*/
|
|
143
|
+
type JsonResponse = {
|
|
144
|
+
response: string;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Type representing a request to start a new E3 round (`rounds/request`)
|
|
148
|
+
*/
|
|
149
|
+
type NewRoundRequest = {
|
|
150
|
+
cronApiKey: string;
|
|
151
|
+
tokenAddress: string;
|
|
152
|
+
balanceThreshold: string;
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Type representing a request to broadcast an encrypted vote (`voting/broadcast`)
|
|
156
|
+
*/
|
|
157
|
+
type BroadcastVoteRequest = {
|
|
158
|
+
e3Id: number;
|
|
159
|
+
encodedProof: string;
|
|
160
|
+
address: string;
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* The status of a vote broadcast returned by the CRISP server
|
|
164
|
+
*/
|
|
165
|
+
type VoteResponseStatus = 'success' | 'user_already_voted' | 'failed_broadcast';
|
|
166
|
+
/**
|
|
167
|
+
* Type representing the response to a vote broadcast (`voting/broadcast`)
|
|
168
|
+
*/
|
|
169
|
+
type BroadcastVoteResponse = {
|
|
170
|
+
status: VoteResponseStatus;
|
|
171
|
+
tx_hash: string | null;
|
|
172
|
+
message: string | null;
|
|
173
|
+
is_vote_update?: boolean;
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Type representing the vote status of an address in a round (`voting/status`)
|
|
177
|
+
*/
|
|
178
|
+
type VoteStatusResponse = {
|
|
179
|
+
round_id: number;
|
|
180
|
+
address: string;
|
|
181
|
+
has_voted: boolean;
|
|
182
|
+
round_status: string | null;
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Type representing the result of a round (`state/result` and `state/all`)
|
|
186
|
+
*/
|
|
187
|
+
type WebResultResponse = {
|
|
188
|
+
round_id: number;
|
|
189
|
+
tally: string[];
|
|
190
|
+
option_1_emoji: string;
|
|
191
|
+
option_2_emoji: string;
|
|
192
|
+
total_votes: number;
|
|
193
|
+
end_time: number;
|
|
194
|
+
requester: string;
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* Type representing a token holder with their address and balance (`state/eligible-addresses`)
|
|
198
|
+
*/
|
|
199
|
+
type TokenHolder = {
|
|
200
|
+
address: string;
|
|
201
|
+
balance: string;
|
|
202
|
+
};
|
|
127
203
|
/**
|
|
128
204
|
* Enum representing the credit mode for a round, which can be either constant or custom.
|
|
129
205
|
* In constant mode, all voters receive the same amount of credits, while in custom mode,
|
|
@@ -135,7 +211,10 @@ declare enum CreditMode {
|
|
|
135
211
|
}
|
|
136
212
|
|
|
137
213
|
/**
|
|
138
|
-
* Get the details of a specific round
|
|
214
|
+
* Get the details of a specific round in a camelCase convenience format
|
|
215
|
+
* @param serverUrl - The base URL of the CRISP server
|
|
216
|
+
* @param e3Id - The e3Id of the round
|
|
217
|
+
* @returns The round details
|
|
139
218
|
*/
|
|
140
219
|
declare const getRoundDetails: (serverUrl: string, e3Id: number) => Promise<RoundDetails>;
|
|
141
220
|
/**
|
|
@@ -156,6 +235,88 @@ declare const getRoundTokenDetails: (serverUrl: string, e3Id: number) => Promise
|
|
|
156
235
|
*/
|
|
157
236
|
declare const getPreviousCiphertext: (serverUrl: string, e3Id: number, address: string) => Promise<Uint8Array | undefined>;
|
|
158
237
|
|
|
238
|
+
/**
|
|
239
|
+
* Get the current (most recent) round, optionally filtered by requester addresses.
|
|
240
|
+
* Returns undefined when no current round exists (404).
|
|
241
|
+
* @param serverUrl - The base URL of the CRISP server
|
|
242
|
+
* @param requesters - Optional list of requester addresses to filter by (only the first is used by the server)
|
|
243
|
+
* @returns The current round id, or undefined if none exists
|
|
244
|
+
*/
|
|
245
|
+
declare const getCurrentRound: (serverUrl: string, requesters?: string[]) => Promise<CurrentRoundResponse | undefined>;
|
|
246
|
+
/**
|
|
247
|
+
* Get the committee public key for a given round.
|
|
248
|
+
* @param serverUrl - The base URL of the CRISP server
|
|
249
|
+
* @param e3Id - The e3Id of the round
|
|
250
|
+
* @returns The committee public key bytes
|
|
251
|
+
*/
|
|
252
|
+
declare const getRoundPublicKey: (serverUrl: string, e3Id: number) => Promise<Uint8Array>;
|
|
253
|
+
/**
|
|
254
|
+
* Get the ciphertext output for a given round.
|
|
255
|
+
* @param serverUrl - The base URL of the CRISP server
|
|
256
|
+
* @param e3Id - The e3Id of the round
|
|
257
|
+
* @returns The ciphertext output bytes
|
|
258
|
+
*/
|
|
259
|
+
declare const getRoundCiphertext: (serverUrl: string, e3Id: number) => Promise<Uint8Array>;
|
|
260
|
+
/**
|
|
261
|
+
* Request a new E3 round. Requires the server's cron API key.
|
|
262
|
+
* @param serverUrl - The base URL of the CRISP server
|
|
263
|
+
* @param request - The new round request (cron API key, token address and balance threshold)
|
|
264
|
+
* @returns The server confirmation message
|
|
265
|
+
*/
|
|
266
|
+
declare const requestNewRound: (serverUrl: string, request: NewRoundRequest) => Promise<JsonResponse>;
|
|
267
|
+
/**
|
|
268
|
+
* Broadcast an encrypted vote through the CRISP server, which relays it on-chain.
|
|
269
|
+
* @param serverUrl - The base URL of the CRISP server
|
|
270
|
+
* @param request - The vote request (round id, hex encoded proof and voter address)
|
|
271
|
+
* @returns The broadcast result, including the transaction hash on success
|
|
272
|
+
*/
|
|
273
|
+
declare const broadcastVote: (serverUrl: string, request: BroadcastVoteRequest) => Promise<BroadcastVoteResponse>;
|
|
274
|
+
/**
|
|
275
|
+
* Get the vote status for an address in a specific round.
|
|
276
|
+
* @param serverUrl - The base URL of the CRISP server
|
|
277
|
+
* @param e3Id - The e3Id of the round
|
|
278
|
+
* @param address - The voter address
|
|
279
|
+
* @returns The vote status for the address
|
|
280
|
+
*/
|
|
281
|
+
declare const getVoteStatus: (serverUrl: string, e3Id: number, address: string) => Promise<VoteStatusResponse>;
|
|
282
|
+
/**
|
|
283
|
+
* Get the result for a given round.
|
|
284
|
+
* @param serverUrl - The base URL of the CRISP server
|
|
285
|
+
* @param e3Id - The e3Id of the round
|
|
286
|
+
* @returns The round result (tally, emojis, total votes, end time and requester)
|
|
287
|
+
*/
|
|
288
|
+
declare const getRoundResult: (serverUrl: string, e3Id: number) => Promise<WebResultResponse>;
|
|
289
|
+
/**
|
|
290
|
+
* Get the results for all rounds, optionally filtered by requester addresses.
|
|
291
|
+
* @param serverUrl - The base URL of the CRISP server
|
|
292
|
+
* @param requesters - Optional list of requester addresses to filter by
|
|
293
|
+
* @returns The results for all matching rounds
|
|
294
|
+
*/
|
|
295
|
+
declare const getAllRoundResults: (serverUrl: string, requesters?: string[]) => Promise<WebResultResponse[]>;
|
|
296
|
+
/**
|
|
297
|
+
* Get the lite state for a given round, as returned by the server (snake_case fields).
|
|
298
|
+
* See `getRoundDetails` in `state.ts` for a camelCase convenience wrapper over this endpoint.
|
|
299
|
+
* @param serverUrl - The base URL of the CRISP server
|
|
300
|
+
* @param e3Id - The e3Id of the round
|
|
301
|
+
* @returns The lite round state
|
|
302
|
+
*/
|
|
303
|
+
declare const getRoundStateLite: (serverUrl: string, e3Id: number) => Promise<E3StateLiteResponse>;
|
|
304
|
+
/**
|
|
305
|
+
* Get the token holder hashes (hash(address, balance)) for a given round.
|
|
306
|
+
* These are the Merkle tree leaves used for eligibility proofs.
|
|
307
|
+
* @param serverUrl - The base URL of the CRISP server
|
|
308
|
+
* @param e3Id - The e3Id of the round
|
|
309
|
+
* @returns The list of token holder hashes
|
|
310
|
+
*/
|
|
311
|
+
declare const getTokenHolderHashes: (serverUrl: string, e3Id: number) => Promise<string[]>;
|
|
312
|
+
/**
|
|
313
|
+
* Get the eligible addresses and their balances for a given round.
|
|
314
|
+
* @param serverUrl - The base URL of the CRISP server
|
|
315
|
+
* @param e3Id - The e3Id of the round
|
|
316
|
+
* @returns The list of eligible token holders
|
|
317
|
+
*/
|
|
318
|
+
declare const getEligibleAddresses: (serverUrl: string, e3Id: number) => Promise<TokenHolder[]>;
|
|
319
|
+
|
|
159
320
|
declare const MERKLE_TREE_MAX_DEPTH = 20;
|
|
160
321
|
declare const MAX_MSG_NON_ZERO_COEFFS = 100;
|
|
161
322
|
declare const MAX_VOTE_OPTIONS = 10;
|
|
@@ -309,6 +470,93 @@ declare class CrispSDK {
|
|
|
309
470
|
* @returns A promise that resolves to the generated proof data.
|
|
310
471
|
*/
|
|
311
472
|
generateVoteProof(voteProofInputs: VoteProofRequest): Promise<ProofData>;
|
|
473
|
+
/**
|
|
474
|
+
* Get the current (most recent) round, optionally filtered by requester addresses.
|
|
475
|
+
* @param requesters - Optional list of requester addresses to filter by
|
|
476
|
+
* @returns The current round id, or undefined if no round exists
|
|
477
|
+
*/
|
|
478
|
+
getCurrentRound(requesters?: string[]): Promise<CurrentRoundResponse | undefined>;
|
|
479
|
+
/**
|
|
480
|
+
* Get the committee public key for a given round.
|
|
481
|
+
* @param e3Id - The e3Id of the round
|
|
482
|
+
* @returns The committee public key bytes
|
|
483
|
+
*/
|
|
484
|
+
getRoundPublicKey(e3Id: number): Promise<Uint8Array>;
|
|
485
|
+
/**
|
|
486
|
+
* Get the ciphertext output for a given round.
|
|
487
|
+
* @param e3Id - The e3Id of the round
|
|
488
|
+
* @returns The ciphertext output bytes
|
|
489
|
+
*/
|
|
490
|
+
getRoundCiphertext(e3Id: number): Promise<Uint8Array>;
|
|
491
|
+
/**
|
|
492
|
+
* Request a new E3 round. Requires the server's cron API key.
|
|
493
|
+
* @param request - The new round request (cron API key, token address and balance threshold)
|
|
494
|
+
* @returns The server confirmation message
|
|
495
|
+
*/
|
|
496
|
+
requestNewRound(request: NewRoundRequest): Promise<JsonResponse>;
|
|
497
|
+
/**
|
|
498
|
+
* Broadcast an encrypted vote through the CRISP server, which relays it on-chain.
|
|
499
|
+
* @param request - The vote request (round id, hex encoded proof and voter address)
|
|
500
|
+
* @returns The broadcast result, including the transaction hash on success
|
|
501
|
+
*/
|
|
502
|
+
broadcastVote(request: BroadcastVoteRequest): Promise<BroadcastVoteResponse>;
|
|
503
|
+
/**
|
|
504
|
+
* Get the vote status for an address in a specific round.
|
|
505
|
+
* @param e3Id - The e3Id of the round
|
|
506
|
+
* @param address - The voter address
|
|
507
|
+
* @returns The vote status for the address
|
|
508
|
+
*/
|
|
509
|
+
getVoteStatus(e3Id: number, address: string): Promise<VoteStatusResponse>;
|
|
510
|
+
/**
|
|
511
|
+
* Get the result for a given round.
|
|
512
|
+
* @param e3Id - The e3Id of the round
|
|
513
|
+
* @returns The round result (tally, emojis, total votes, end time and requester)
|
|
514
|
+
*/
|
|
515
|
+
getRoundResult(e3Id: number): Promise<WebResultResponse>;
|
|
516
|
+
/**
|
|
517
|
+
* Get the results for all rounds, optionally filtered by requester addresses.
|
|
518
|
+
* @param requesters - Optional list of requester addresses to filter by
|
|
519
|
+
* @returns The results for all matching rounds
|
|
520
|
+
*/
|
|
521
|
+
getAllRoundResults(requesters?: string[]): Promise<WebResultResponse[]>;
|
|
522
|
+
/**
|
|
523
|
+
* Get the lite state for a given round, as returned by the server (snake_case fields).
|
|
524
|
+
* @param e3Id - The e3Id of the round
|
|
525
|
+
* @returns The lite round state
|
|
526
|
+
*/
|
|
527
|
+
getRoundStateLite(e3Id: number): Promise<E3StateLiteResponse>;
|
|
528
|
+
/**
|
|
529
|
+
* Get the details of a specific round in a camelCase convenience format.
|
|
530
|
+
* @param e3Id - The e3Id of the round
|
|
531
|
+
* @returns The round details
|
|
532
|
+
*/
|
|
533
|
+
getRoundDetails(e3Id: number): Promise<RoundDetails>;
|
|
534
|
+
/**
|
|
535
|
+
* Get the token address, balance threshold and snapshot block for a specific round.
|
|
536
|
+
* @param e3Id - The e3Id of the round
|
|
537
|
+
* @returns The token details
|
|
538
|
+
*/
|
|
539
|
+
getRoundTokenDetails(e3Id: number): Promise<TokenDetails>;
|
|
540
|
+
/**
|
|
541
|
+
* Get the token holder hashes (hash(address, balance)) for a given round.
|
|
542
|
+
* These are the Merkle tree leaves used for eligibility proofs.
|
|
543
|
+
* @param e3Id - The e3Id of the round
|
|
544
|
+
* @returns The list of token holder hashes
|
|
545
|
+
*/
|
|
546
|
+
getTokenHolderHashes(e3Id: number): Promise<string[]>;
|
|
547
|
+
/**
|
|
548
|
+
* Get the eligible addresses and their balances for a given round.
|
|
549
|
+
* @param e3Id - The e3Id of the round
|
|
550
|
+
* @returns The list of eligible token holders
|
|
551
|
+
*/
|
|
552
|
+
getEligibleAddresses(e3Id: number): Promise<TokenHolder[]>;
|
|
553
|
+
/**
|
|
554
|
+
* Get the previous ciphertext input for a slot address in a given round.
|
|
555
|
+
* @param e3Id - The e3Id of the round
|
|
556
|
+
* @param address - The address of the slot
|
|
557
|
+
* @returns The previous ciphertext, or undefined if the slot is empty
|
|
558
|
+
*/
|
|
559
|
+
getPreviousCiphertext(e3Id: number, address: string): Promise<Uint8Array | undefined>;
|
|
312
560
|
}
|
|
313
561
|
|
|
314
|
-
export { CreditMode, CrispSDK, MAX_MSG_NON_ZERO_COEFFS, MAX_VOTE_OPTIONS, MERKLE_TREE_MAX_DEPTH, type MaskVoteProofInputs, type
|
|
562
|
+
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 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, getPreviousCiphertext, getRoundCiphertext, getRoundDetails, getRoundPublicKey, getRoundResult, getRoundStateLite, getRoundTokenDetails, getScaledBalance, getTokenHolderHashes, getTotalSupplyAt, getTreeData, getVoteStatus, getZeroVote, hashLeaf, requestNewRound, validateVote, verifyProof };
|