@crisp-e3/sdk 0.14.0 → 0.16.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/README.md +4 -3
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +40 -5
- package/dist/index.js +36 -2755
- package/dist/index.js.map +1 -1
- package/dist/workers/generateCircuitInputs.worker.js +5 -1
- package/dist/workers/generateCircuitInputs.worker.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -81,6 +81,15 @@ type MerkleProof = {
|
|
|
81
81
|
* Type representing a vote
|
|
82
82
|
*/
|
|
83
83
|
type Vote = number[];
|
|
84
|
+
/**
|
|
85
|
+
* Type representing a decoded tally: one total per option.
|
|
86
|
+
*
|
|
87
|
+
* @remarks
|
|
88
|
+
* Uses `bigint` because an aggregated tally coefficient is a sum over all ballots,
|
|
89
|
+
* so a total can exceed `Number.MAX_SAFE_INTEGER`. This matches the `BigUint` the
|
|
90
|
+
* CRISP server returns and the `uint256` the CRISP contract returns.
|
|
91
|
+
*/
|
|
92
|
+
type TallyResult = bigint[];
|
|
84
93
|
type ProofData = {
|
|
85
94
|
publicInputs: string[];
|
|
86
95
|
proof: Uint8Array;
|
|
@@ -405,6 +414,17 @@ declare const getScaledBalance: (balance: bigint, decimals: bigint) => bigint;
|
|
|
405
414
|
* encoding, encryption, decryption, and tally decoding.
|
|
406
415
|
*/
|
|
407
416
|
|
|
417
|
+
/**
|
|
418
|
+
* Encodes vote choices into a polynomial coefficient array for BFV encryption.
|
|
419
|
+
* Each choice occupies floor(MAX_MSG_NON_ZERO_COEFFS / n) binary coefficients;
|
|
420
|
+
* remaining slots in the first MAX_MSG_NON_ZERO_COEFFS coeffs are zero; then
|
|
421
|
+
* the vector is padded to the BFV degree.
|
|
422
|
+
*
|
|
423
|
+
* @param vote - Array of numeric values per choice (e.g. [10, 5] for 2 options)
|
|
424
|
+
* @returns Array of 0s and 1s representing coefficients
|
|
425
|
+
* @throws If vote has fewer than 2 choices, any value exceeds max for its segment, or degree is too small
|
|
426
|
+
*/
|
|
427
|
+
declare const encodeVote: (vote: Vote) => number[];
|
|
408
428
|
/**
|
|
409
429
|
* Encrypts an encoded vote using BFV homomorphic encryption.
|
|
410
430
|
*
|
|
@@ -414,14 +434,29 @@ declare const getScaledBalance: (balance: bigint, decimals: bigint) => bigint;
|
|
|
414
434
|
*/
|
|
415
435
|
declare const encryptVote: (vote: Vote, publicKey: Uint8Array) => Uint8Array;
|
|
416
436
|
/**
|
|
417
|
-
* Decodes raw tally bytes (or
|
|
437
|
+
* Decodes raw tally bytes (or coefficients) into a total per choice.
|
|
418
438
|
* Expects the same segment layout as used in encodeVote.
|
|
419
439
|
*
|
|
420
|
-
*
|
|
440
|
+
* Mirrors `crisp_utils::decode_tally` (Rust) and `CRISPProgram.decodeTally` (Solidity):
|
|
441
|
+
* only the first MAX_MSG_NON_ZERO_COEFFS coefficients carry the payload, split into
|
|
442
|
+
* `floor(MAX_MSG_NON_ZERO_COEFFS / numChoices)` binary coefficients per choice, MSB first.
|
|
443
|
+
*
|
|
444
|
+
* @param tallyBytes - Hex string, or the polynomial coefficients from tally/decryption
|
|
445
|
+
* @param numChoices - Number of vote options: an integer from 2 to MAX_VOTE_OPTIONS
|
|
446
|
+
* @returns One total per choice
|
|
447
|
+
* @throws If numChoices is outside 2..MAX_VOTE_OPTIONS or not an integer, or there are fewer
|
|
448
|
+
* coefficients than the payload region
|
|
449
|
+
*/
|
|
450
|
+
declare const decodeTally: (tallyBytes: string | number[] | bigint[], numChoices: number) => TallyResult;
|
|
451
|
+
/**
|
|
452
|
+
* Decrypts a BFV-encrypted vote and decodes it to vote values.
|
|
453
|
+
*
|
|
454
|
+
* @param ciphertext - Encrypted vote
|
|
455
|
+
* @param secretKey - BFV secret key
|
|
421
456
|
* @param numChoices - Number of vote options
|
|
422
|
-
* @returns
|
|
457
|
+
* @returns One total per choice
|
|
423
458
|
*/
|
|
424
|
-
declare const
|
|
459
|
+
declare const decryptVote: (ciphertext: Uint8Array, secretKey: Uint8Array, numChoices: number) => TallyResult;
|
|
425
460
|
/**
|
|
426
461
|
* Generates a BFV keypair for vote encryption and decryption.
|
|
427
462
|
*
|
|
@@ -596,4 +631,4 @@ declare class CrispSDK {
|
|
|
596
631
|
getPreviousCiphertext(e3Id: number, address: string): Promise<Uint8Array | undefined>;
|
|
597
632
|
}
|
|
598
633
|
|
|
599
|
-
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 OnChainRoundData, 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, getOnChainRoundData, getPreviousCiphertext, getRoundCiphertext, getRoundDetails, getRoundPublicKey, getRoundResult, getRoundStateLite, getRoundTokenDetails, getScaledBalance, getTokenHolderHashes, getTotalSupplyAt, getTreeData, getVoteStatus, getZeroVote, hashLeaf, requestNewRound, validateVote, verifyProof };
|
|
634
|
+
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 OnChainRoundData, type ProofData, type RoundDetails, SIGNATURE_MESSAGE, SIGNATURE_MESSAGE_HASH, type TallyResult, type TokenDetails, type TokenHolder, type Vote, type VoteProofInputs, type VoteResponseStatus, type VoteStatusResponse, type WebResultResponse, broadcastVote, decodeTally, decryptVote, destroyBBApi, encodeSolidityProof, encodeVote, encryptVote, generateBFVKeys, generateMaskVoteProof, generateMerkleProof, generateMerkleTree, generateVoteProof, getAddressFromSignature, getAllRoundResults, getBalanceAt, getCurrentRound, getEligibleAddresses, getMaxVoteValue, getOnChainRoundData, getPreviousCiphertext, getRoundCiphertext, getRoundDetails, getRoundPublicKey, getRoundResult, getRoundStateLite, getRoundTokenDetails, getScaledBalance, getTokenHolderHashes, getTotalSupplyAt, getTreeData, getVoteStatus, getZeroVote, hashLeaf, requestNewRound, validateVote, verifyProof };
|