@crisp-e3/sdk 0.5.7 → 0.5.9

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
@@ -1,5 +1,4 @@
1
1
  import { LeanIMTMerkleProof, LeanIMT } from '@zk-kit/lean-imt';
2
- import { ProofData } from '@aztec/bb.js';
3
2
  import { Hex } from 'viem';
4
3
 
5
4
  /**
@@ -81,17 +80,13 @@ type MerkleProof = {
81
80
  indices: number[];
82
81
  };
83
82
  /**
84
- * Type representing a vote with power for 'yes' and 'no'
83
+ * Type representing a vote
85
84
  */
86
- type Vote = {
87
- /**
88
- * The voting power for 'yes' votes
89
- */
90
- yes: bigint;
91
- /**
92
- * The voting power for 'no' votes
93
- */
94
- no: bigint;
85
+ type Vote = bigint[];
86
+ type ProofData = {
87
+ publicInputs: string[];
88
+ proof: Uint8Array;
89
+ encryptedVote: Uint8Array;
95
90
  };
96
91
  type MaskVoteProofInputs = {
97
92
  publicKey: Uint8Array;
@@ -99,6 +94,7 @@ type MaskVoteProofInputs = {
99
94
  slotAddress: string;
100
95
  merkleLeaves: string[] | bigint[];
101
96
  previousCiphertext?: Uint8Array;
97
+ numOptions: number;
102
98
  };
103
99
  type MaskVoteProofRequest = {
104
100
  e3Id: number;
@@ -106,6 +102,7 @@ type MaskVoteProofRequest = {
106
102
  balance: bigint;
107
103
  slotAddress: string;
108
104
  merkleLeaves: string[] | bigint[];
105
+ numOptions: number;
109
106
  };
110
107
  type VoteProofInputs = {
111
108
  merkleLeaves: string[] | bigint[];
@@ -157,11 +154,6 @@ declare const getPreviousCiphertext: (serverUrl: string, e3Id: number, address:
157
154
  declare const getIsSlotEmpty: (serverUrl: string, e3Id: number, address: string) => Promise<boolean>;
158
155
 
159
156
  declare const MERKLE_TREE_MAX_DEPTH = 20;
160
- /**
161
- * This is the maximum value for a vote (Yes or No). This is 2^50 - 1
162
- * The minimum degree that BFV should use is 100 (to accommodate both Yes and No votes)
163
- */
164
- declare const MAXIMUM_VOTE_VALUE: number;
165
157
  /**
166
158
  * Message used by users to prove ownership of their Ethereum account
167
159
  * This message is signed by the user's private key to authenticate their identity
@@ -191,13 +183,26 @@ declare const generateMerkleTree: (leaves: bigint[]) => LeanIMT;
191
183
  */
192
184
  declare const generateMerkleProof: (balance: bigint, address: string, leaves: bigint[] | string[]) => MerkleProof;
193
185
  declare const getAddressFromSignature: (signature: `0x${string}`, messageHash?: `0x${string}`) => Promise<string>;
186
+ /**
187
+ * Get the maximum vote value for a given number of choices.
188
+ * @param numChoices Number of choices.
189
+ * @returns Maximum value per choice.
190
+ */
191
+ declare const getMaxVoteValue: (numChoices: number) => bigint;
192
+ /**
193
+ * Get a zero vote with the given number of choices.
194
+ * @param numChoices Number of choices.
195
+ * @returns A zero vote with the given number of choices.
196
+ */
197
+ declare const getZeroVote: (numChoices: number) => bigint[];
194
198
 
195
199
  /**
196
- * Decode an encoded tally into its decimal representation.
197
- * @param tallyBytes The encoded tally as a hex string (bytes).
198
- * @returns The decoded tally as an IVote.
200
+ * Decode an encoded tally into vote counts for n choices.
201
+ * @param tallyBytes The encoded tally as a hex string.
202
+ * @param numChoices Number of choices.
203
+ * @returns Array of vote counts per choice.
199
204
  */
200
- declare const decodeTally: (tallyBytes: string) => Vote;
205
+ declare const decodeTally: (tallyBytes: string, numChoices: number) => Vote;
201
206
  /**
202
207
  * Encrypt the vote using the public key.
203
208
  * @param vote - The vote to encrypt.
@@ -210,6 +215,12 @@ declare const encryptVote: (vote: Vote, publicKey: Uint8Array) => Uint8Array;
210
215
  * @returns The generated public key as a Uint8Array.
211
216
  */
212
217
  declare const generatePublicKey: () => Uint8Array;
218
+ /**
219
+ * Validate a vote.
220
+ * @param vote - The vote to validate.
221
+ * @param balance - The balance of the voter.
222
+ */
223
+ declare const validateVote: (vote: Vote, balance: bigint) => void;
213
224
  /**
214
225
  * Generate a vote proof for the CRISP circuit given the vote proof inputs.
215
226
  * @param voteProofInputs - The vote proof inputs.
@@ -234,7 +245,7 @@ declare const verifyProof: (proof: ProofData) => Promise<boolean>;
234
245
  * @param proof The proof data.
235
246
  * @returns The encoded proof data as a hex string.
236
247
  */
237
- declare const encodeSolidityProof: (proof: ProofData) => Hex;
248
+ declare const encodeSolidityProof: ({ publicInputs, proof, encryptedVote }: ProofData) => Hex;
238
249
 
239
250
  /**
240
251
  * A class representing the CRISP SDK.
@@ -264,4 +275,4 @@ declare class CrispSDK {
264
275
  generateVoteProof(voteProofInputs: VoteProofRequest): Promise<ProofData>;
265
276
  }
266
277
 
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 };
278
+ export { CrispSDK, 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, getMaxVoteValue, getPreviousCiphertext, getRoundDetails, getRoundTokenDetails, getTotalSupplyAt, getTreeData, getZeroVote, hashLeaf, validateVote, verifyProof };