@crisp-e3/sdk 0.5.8 → 0.5.10

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
@@ -80,18 +80,9 @@ type MerkleProof = {
80
80
  indices: number[];
81
81
  };
82
82
  /**
83
- * Type representing a vote with power for 'yes' and 'no'
83
+ * Type representing a vote
84
84
  */
85
- type Vote = {
86
- /**
87
- * The voting power for 'yes' votes
88
- */
89
- yes: bigint;
90
- /**
91
- * The voting power for 'no' votes
92
- */
93
- no: bigint;
94
- };
85
+ type Vote = bigint[];
95
86
  type ProofData = {
96
87
  publicInputs: string[];
97
88
  proof: Uint8Array;
@@ -103,6 +94,7 @@ type MaskVoteProofInputs = {
103
94
  slotAddress: string;
104
95
  merkleLeaves: string[] | bigint[];
105
96
  previousCiphertext?: Uint8Array;
97
+ numOptions: number;
106
98
  };
107
99
  type MaskVoteProofRequest = {
108
100
  e3Id: number;
@@ -110,6 +102,7 @@ type MaskVoteProofRequest = {
110
102
  balance: bigint;
111
103
  slotAddress: string;
112
104
  merkleLeaves: string[] | bigint[];
105
+ numOptions: number;
113
106
  };
114
107
  type VoteProofInputs = {
115
108
  merkleLeaves: string[] | bigint[];
@@ -131,6 +124,15 @@ type VoteProofRequest = {
131
124
  messageHash: `0x${string}`;
132
125
  slotAddress: string;
133
126
  };
127
+ /**
128
+ * Enum representing the credit mode for a round, which can be either constant or custom.
129
+ * In constant mode, all voters receive the same amount of credits, while in custom mode,
130
+ * the credits can vary based on certain criteria (e.g., voter balance).
131
+ */
132
+ declare enum CreditMode {
133
+ CONSTANT = "0",
134
+ CUSTOM = "1"
135
+ }
134
136
 
135
137
  /**
136
138
  * Get the details of a specific round
@@ -161,11 +163,6 @@ declare const getPreviousCiphertext: (serverUrl: string, e3Id: number, address:
161
163
  declare const getIsSlotEmpty: (serverUrl: string, e3Id: number, address: string) => Promise<boolean>;
162
164
 
163
165
  declare const MERKLE_TREE_MAX_DEPTH = 20;
164
- /**
165
- * This is the maximum value for a vote (Yes or No). This is 2^50 - 1
166
- * The minimum degree that BFV should use is 100 (to accommodate both Yes and No votes)
167
- */
168
- declare const MAXIMUM_VOTE_VALUE: number;
169
166
  /**
170
167
  * Message used by users to prove ownership of their Ethereum account
171
168
  * This message is signed by the user's private key to authenticate their identity
@@ -195,13 +192,26 @@ declare const generateMerkleTree: (leaves: bigint[]) => LeanIMT;
195
192
  */
196
193
  declare const generateMerkleProof: (balance: bigint, address: string, leaves: bigint[] | string[]) => MerkleProof;
197
194
  declare const getAddressFromSignature: (signature: `0x${string}`, messageHash?: `0x${string}`) => Promise<string>;
195
+ /**
196
+ * Get the maximum vote value for a given number of choices.
197
+ * @param numChoices Number of choices.
198
+ * @returns Maximum value per choice.
199
+ */
200
+ declare const getMaxVoteValue: (numChoices: number) => bigint;
201
+ /**
202
+ * Get a zero vote with the given number of choices.
203
+ * @param numChoices Number of choices.
204
+ * @returns A zero vote with the given number of choices.
205
+ */
206
+ declare const getZeroVote: (numChoices: number) => bigint[];
198
207
 
199
208
  /**
200
- * Decode an encoded tally into its decimal representation.
201
- * @param tallyBytes The encoded tally as a hex string (bytes).
202
- * @returns The decoded tally as an IVote.
209
+ * Decode an encoded tally into vote counts for n choices.
210
+ * @param tallyBytes The encoded tally as a hex string.
211
+ * @param numChoices Number of choices.
212
+ * @returns Array of vote counts per choice.
203
213
  */
204
- declare const decodeTally: (tallyBytes: string) => Vote;
214
+ declare const decodeTally: (tallyBytes: string, numChoices: number) => Vote;
205
215
  /**
206
216
  * Encrypt the vote using the public key.
207
217
  * @param vote - The vote to encrypt.
@@ -214,6 +224,12 @@ declare const encryptVote: (vote: Vote, publicKey: Uint8Array) => Uint8Array;
214
224
  * @returns The generated public key as a Uint8Array.
215
225
  */
216
226
  declare const generatePublicKey: () => Uint8Array;
227
+ /**
228
+ * Validate a vote.
229
+ * @param vote - The vote to validate.
230
+ * @param balance - The balance of the voter.
231
+ */
232
+ declare const validateVote: (vote: Vote, balance: bigint) => void;
217
233
  /**
218
234
  * Generate a vote proof for the CRISP circuit given the vote proof inputs.
219
235
  * @param voteProofInputs - The vote proof inputs.
@@ -268,4 +284,4 @@ declare class CrispSDK {
268
284
  generateVoteProof(voteProofInputs: VoteProofRequest): Promise<ProofData>;
269
285
  }
270
286
 
271
- 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 };
287
+ export { CreditMode, 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 };