@crisp-e3/sdk 0.5.11 → 0.6.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
@@ -82,7 +82,7 @@ type MerkleProof = {
82
82
  /**
83
83
  * Type representing a vote
84
84
  */
85
- type Vote = bigint[];
85
+ type Vote = number[];
86
86
  type ProofData = {
87
87
  publicInputs: string[];
88
88
  proof: Uint8Array;
@@ -197,33 +197,50 @@ declare const getAddressFromSignature: (signature: `0x${string}`, messageHash?:
197
197
  * @param numChoices Number of choices.
198
198
  * @returns Maximum value per choice.
199
199
  */
200
- declare const getMaxVoteValue: (numChoices: number) => bigint;
200
+ declare const getMaxVoteValue: (numChoices: number) => number;
201
201
  /**
202
202
  * Get a zero vote with the given number of choices.
203
203
  * @param numChoices Number of choices.
204
204
  * @returns A zero vote with the given number of choices.
205
205
  */
206
- declare const getZeroVote: (numChoices: number) => bigint[];
206
+ declare const getZeroVote: (numChoices: number) => number[];
207
207
 
208
208
  /**
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.
209
+ * Vote encoding and BFV encryption for the CRISP voting protocol.
210
+ *
211
+ * Encodes vote choices (numbers per option) into polynomial coefficient arrays
212
+ * suitable for BFV homomorphic encryption. Each choice is represented as a
213
+ * segment of binary digits, padded to fit the polynomial degree. Supports
214
+ * encoding, encryption, decryption, and tally decoding.
213
215
  */
214
- declare const decodeTally: (tallyBytes: string, numChoices: number) => Vote;
216
+
215
217
  /**
216
- * Encrypt the vote using the public key.
217
- * @param vote - The vote to encrypt.
218
- * @param publicKey - The public key to use for encryption.
219
- * @returns The encrypted vote as a Uint8Array.
218
+ * Encrypts an encoded vote using BFV homomorphic encryption.
219
+ *
220
+ * @param vote - Vote choices to encrypt
221
+ * @param publicKey - BFV public key
222
+ * @returns Encrypted ciphertext
220
223
  */
221
224
  declare const encryptVote: (vote: Vote, publicKey: Uint8Array) => Uint8Array;
222
225
  /**
223
- * Generate a random public key.
224
- * @returns The generated public key as a Uint8Array.
226
+ * Decodes raw tally bytes (or hex string) into vote values per choice.
227
+ * Expects the same segment layout as used in encodeVote.
228
+ *
229
+ * @param tallyBytes - Hex string or array of decoded numbers from tally/decryption
230
+ * @param numChoices - Number of vote options
231
+ * @returns Vote array with one value per choice
232
+ */
233
+ declare const decodeTally: (tallyBytes: string | number[], numChoices: number) => Vote;
234
+ /**
235
+ * Generates a BFV keypair for vote encryption and decryption.
236
+ *
237
+ * @returns Object with secretKey and publicKey as Uint8Arrays
225
238
  */
226
- declare const generatePublicKey: () => Uint8Array;
239
+ declare const generateBFVKeys: () => {
240
+ secretKey: Uint8Array;
241
+ publicKey: Uint8Array;
242
+ };
243
+
227
244
  /**
228
245
  * Validate a vote.
229
246
  * @param vote - The vote to validate.
@@ -284,4 +301,4 @@ declare class CrispSDK {
284
301
  generateVoteProof(voteProofInputs: VoteProofRequest): Promise<ProofData>;
285
302
  }
286
303
 
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 };
304
+ 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, generateBFVKeys, generateMaskVoteProof, generateMerkleProof, generateMerkleTree, generateVoteProof, getAddressFromSignature, getBalanceAt, getIsSlotEmpty, getMaxVoteValue, getPreviousCiphertext, getRoundDetails, getRoundTokenDetails, getTotalSupplyAt, getTreeData, getZeroVote, hashLeaf, validateVote, verifyProof };