@crisp-e3/sdk 0.5.2 → 0.5.3

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
@@ -94,11 +94,29 @@ type Vote = {
94
94
  no: bigint;
95
95
  };
96
96
  type MaskVoteProofInputs = {
97
- previousCiphertext?: Uint8Array;
97
+ publicKey: Uint8Array;
98
+ balance: bigint;
99
+ slotAddress: string;
98
100
  merkleLeaves: string[] | bigint[];
101
+ isFirstVote: boolean;
102
+ previousCiphertext: Uint8Array;
103
+ };
104
+ type MaskVoteProofRequest = {
105
+ e3Id: number;
99
106
  publicKey: Uint8Array;
100
107
  balance: bigint;
101
108
  slotAddress: string;
109
+ merkleLeaves: string[] | bigint[];
110
+ };
111
+ type VoteProofRequest = {
112
+ e3Id: number;
113
+ merkleLeaves: string[] | bigint[];
114
+ publicKey: Uint8Array;
115
+ balance: bigint;
116
+ vote: Vote;
117
+ signature: `0x${string}`;
118
+ messageHash: `0x${string}`;
119
+ slotAddress: string;
102
120
  };
103
121
  type VoteProofInputs = {
104
122
  merkleLeaves: string[] | bigint[];
@@ -106,8 +124,10 @@ type VoteProofInputs = {
106
124
  balance: bigint;
107
125
  vote: Vote;
108
126
  signature: `0x${string}`;
109
- previousCiphertext?: Uint8Array;
110
127
  messageHash: `0x${string}`;
128
+ slotAddress: string;
129
+ isFirstVote: boolean;
130
+ previousCiphertext: Uint8Array;
111
131
  };
112
132
 
113
133
  /**
@@ -121,13 +141,29 @@ declare const getRoundDetails: (serverUrl: string, e3Id: number) => Promise<Roun
121
141
  * @returns The token address, balance threshold and snapshot block
122
142
  */
123
143
  declare const getRoundTokenDetails: (serverUrl: string, e3Id: number) => Promise<TokenDetails>;
144
+ /**
145
+ * Get the previous ciphertext for a slot from the CRISP server
146
+ * @param serverUrl - The base URL of the CRISP server
147
+ * @param e3Id - The e3Id of the round
148
+ * @param address - The address of the slot
149
+ * @returns The previous ciphertext for the slot
150
+ */
151
+ declare const getPreviousCiphertext: (serverUrl: string, e3Id: number, address: string) => Promise<Uint8Array>;
152
+ /**
153
+ * Check if a slot is empty for a given E3 ID and slot address
154
+ * @param serverUrl - The base URL of the CRISP server
155
+ * @param e3Id - The e3Id of the round
156
+ * @param address - The address of the slot
157
+ * @returns Whether the slot is empty or not
158
+ */
159
+ declare const getIsSlotEmpty: (serverUrl: string, e3Id: number, address: string) => Promise<boolean>;
124
160
 
125
161
  declare const MERKLE_TREE_MAX_DEPTH = 20;
126
162
  /**
127
163
  * This is the maximum value for a vote (Yes or No). This is 2^50 - 1
128
164
  * The minimum degree that BFV should use is 100 (to accommodate both Yes and No votes)
129
165
  */
130
- declare const MAXIMUM_VOTE_VALUE: bigint;
166
+ declare const MAXIMUM_VOTE_VALUE: number;
131
167
  /**
132
168
  * Message used by users to prove ownership of their Ethereum account
133
169
  * This message is signed by the user's private key to authenticate their identity
@@ -156,18 +192,43 @@ declare const generateMerkleTree: (leaves: bigint[]) => LeanIMT;
156
192
  * @param leaves The leaves of the Merkle tree
157
193
  */
158
194
  declare const generateMerkleProof: (balance: bigint, address: string, leaves: bigint[] | string[]) => MerkleProof;
159
- declare const getAddressFromSignature: (signature: `0x${string}`, messageHash: `0x${string}`) => Promise<string>;
195
+ declare const getAddressFromSignature: (signature: `0x${string}`, messageHash?: `0x${string}`) => Promise<string>;
160
196
 
161
197
  /**
162
198
  * Decode an encoded tally into its decimal representation.
163
- * @param tally The encoded tally to decode.
199
+ * @param tallyBytes The encoded tally as a hex string (bytes).
164
200
  * @returns The decoded tally as an IVote.
165
201
  */
166
- declare const decodeTally: (tally: string[]) => Vote;
202
+ declare const decodeTally: (tallyBytes: string) => Vote;
203
+ /**
204
+ * Encrypt the vote using the public key.
205
+ * @param vote - The vote to encrypt.
206
+ * @param publicKey - The public key to use for encryption.
207
+ * @returns The encrypted vote as a Uint8Array.
208
+ */
167
209
  declare const encryptVote: (vote: Vote, publicKey: Uint8Array) => Uint8Array;
210
+ /**
211
+ * Generate a random public key.
212
+ * @returns The generated public key as a Uint8Array.
213
+ */
168
214
  declare const generatePublicKey: () => Uint8Array;
215
+ /**
216
+ * Generate a vote proof for the CRISP circuit given the vote proof inputs.
217
+ * @param voteProofInputs - The vote proof inputs.
218
+ * @returns The vote proof.
219
+ */
169
220
  declare const generateVoteProof: (voteProofInputs: VoteProofInputs) => Promise<ProofData>;
221
+ /**
222
+ * Generate a proof for a vote masking operation.
223
+ * @param maskVoteProofInputs The mask vote proof inputs.
224
+ * @returns
225
+ */
170
226
  declare const generateMaskVoteProof: (maskVoteProofInputs: MaskVoteProofInputs) => Promise<ProofData>;
227
+ /**
228
+ * Locally verify a Noir proof.
229
+ * @param proof - The proof to verify.
230
+ * @returns True if the proof is valid, false otherwise.
231
+ */
171
232
  declare const verifyProof: (proof: ProofData) => Promise<boolean>;
172
233
  /**
173
234
  * Encode the proof data into a format that can be used by the CRISP program in Solidity
@@ -177,4 +238,30 @@ declare const verifyProof: (proof: ProofData) => Promise<boolean>;
177
238
  */
178
239
  declare const encodeSolidityProof: (proof: ProofData) => Hex;
179
240
 
180
- export { MAXIMUM_VOTE_VALUE, MERKLE_TREE_MAX_DEPTH, type MaskVoteProofInputs, type RoundDetails, type RoundDetailsResponse, SIGNATURE_MESSAGE, SIGNATURE_MESSAGE_HASH, type TokenDetails, type Vote, type VoteProofInputs, decodeTally, encodeSolidityProof, encryptVote, generateMaskVoteProof, generateMerkleProof, generateMerkleTree, generatePublicKey, generateVoteProof, getAddressFromSignature, getBalanceAt, getRoundDetails, getRoundTokenDetails, getTotalSupplyAt, getTreeData, hashLeaf, verifyProof };
241
+ /**
242
+ * A class representing the Crisp SDK.
243
+ */
244
+ declare class CrispSDK {
245
+ /**
246
+ * The server URL for the Crisp SDK.
247
+ * It's used by methods that communicate directly with the Crisp server.
248
+ */
249
+ private serverUrl;
250
+ /**
251
+ * Create a new instance
252
+ * @param serverUrl
253
+ */
254
+ constructor(serverUrl: string);
255
+ /**
256
+ * Generate a proof for a vote masking.
257
+ */
258
+ generateMaskVoteProof(maskProofInputs: MaskVoteProofRequest): Promise<ProofData>;
259
+ /**
260
+ * Generate a proof for a vote.
261
+ * @param voteProofInputs - The inputs required to generate the vote proof.
262
+ * @returns A promise that resolves to the generated proof data.
263
+ */
264
+ generateVoteProof(voteProofInputs: VoteProofRequest): Promise<ProofData>;
265
+ }
266
+
267
+ export { CrispSDK, MAXIMUM_VOTE_VALUE, MERKLE_TREE_MAX_DEPTH, type MaskVoteProofInputs, type RoundDetails, type RoundDetailsResponse, SIGNATURE_MESSAGE, SIGNATURE_MESSAGE_HASH, type TokenDetails, type Vote, type VoteProofInputs, decodeTally, encodeSolidityProof, encryptVote, generateMaskVoteProof, generateMerkleProof, generateMerkleTree, generatePublicKey, generateVoteProof, getAddressFromSignature, getBalanceAt, getIsSlotEmpty, getPreviousCiphertext, getRoundDetails, getRoundTokenDetails, getTotalSupplyAt, getTreeData, hashLeaf, verifyProof };