@crisp-e3/sdk 0.5.12 → 0.7.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 -6
- package/dist/index.d.ts +44 -27
- package/dist/index.js +3116 -213
- package/dist/index.js.map +1 -1
- package/dist/workers/generateCircuitInputs.worker.d.ts +2 -0
- package/dist/workers/generateCircuitInputs.worker.js +144 -0
- package/dist/workers/generateCircuitInputs.worker.js.map +1 -0
- package/package.json +13 -7
package/README.md
CHANGED
|
@@ -149,10 +149,10 @@ const address = await getAddressFromSignature(signature, messageHash)
|
|
|
149
149
|
#### State Utilities
|
|
150
150
|
|
|
151
151
|
```typescript
|
|
152
|
-
import { getPreviousCiphertext
|
|
152
|
+
import { getPreviousCiphertext } from '@crisp-e3/sdk'
|
|
153
153
|
|
|
154
154
|
const previousCiphertext = await getPreviousCiphertext(serverUrl, e3Id, slotAddress)
|
|
155
|
-
|
|
155
|
+
// Returns undefined when the slot is empty (404)
|
|
156
156
|
```
|
|
157
157
|
|
|
158
158
|
## API
|
|
@@ -170,10 +170,8 @@ const isEmpty = await getIsSlotEmpty(serverUrl, e3Id, slotAddress)
|
|
|
170
170
|
- `getRoundDetails(serverUrl: string, e3Id: number): Promise<RoundDetails>` - Get round details
|
|
171
171
|
- `getRoundTokenDetails(serverUrl: string, e3Id: number): Promise<TokenDetails>` - Get token details
|
|
172
172
|
for a round
|
|
173
|
-
- `getPreviousCiphertext(serverUrl: string, e3Id: number, address: string): Promise<Uint8Array>` -
|
|
174
|
-
Get previous ciphertext for a slot
|
|
175
|
-
- `getIsSlotEmpty(serverUrl: string, e3Id: number, address: string): Promise<boolean>` - Check if a
|
|
176
|
-
slot is empty
|
|
173
|
+
- `getPreviousCiphertext(serverUrl: string, e3Id: number, address: string): Promise<Uint8Array | undefined>` -
|
|
174
|
+
Get previous ciphertext for a slot (undefined when slot is empty)
|
|
177
175
|
|
|
178
176
|
### Token Functions
|
|
179
177
|
|
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 =
|
|
85
|
+
type Vote = number[];
|
|
86
86
|
type ProofData = {
|
|
87
87
|
publicInputs: string[];
|
|
88
88
|
proof: Uint8Array;
|
|
@@ -146,21 +146,15 @@ declare const getRoundDetails: (serverUrl: string, e3Id: number) => Promise<Roun
|
|
|
146
146
|
*/
|
|
147
147
|
declare const getRoundTokenDetails: (serverUrl: string, e3Id: number) => Promise<TokenDetails>;
|
|
148
148
|
/**
|
|
149
|
-
* Get the previous ciphertext for a slot from the CRISP server
|
|
149
|
+
* Get the previous ciphertext for a slot from the CRISP server.
|
|
150
|
+
* Returns undefined when the slot is empty (404).
|
|
151
|
+
*
|
|
150
152
|
* @param serverUrl - The base URL of the CRISP server
|
|
151
153
|
* @param e3Id - The e3Id of the round
|
|
152
154
|
* @param address - The address of the slot
|
|
153
|
-
* @returns The previous ciphertext for the slot
|
|
155
|
+
* @returns The previous ciphertext for the slot, or undefined if the slot is empty
|
|
154
156
|
*/
|
|
155
|
-
declare const getPreviousCiphertext: (serverUrl: string, e3Id: number, address: string) => Promise<Uint8Array>;
|
|
156
|
-
/**
|
|
157
|
-
* Check if a slot is empty for a given E3 ID and slot address
|
|
158
|
-
* @param serverUrl - The base URL of the CRISP server
|
|
159
|
-
* @param e3Id - The e3Id of the round
|
|
160
|
-
* @param address - The address of the slot
|
|
161
|
-
* @returns Whether the slot is empty or not
|
|
162
|
-
*/
|
|
163
|
-
declare const getIsSlotEmpty: (serverUrl: string, e3Id: number, address: string) => Promise<boolean>;
|
|
157
|
+
declare const getPreviousCiphertext: (serverUrl: string, e3Id: number, address: string) => Promise<Uint8Array | undefined>;
|
|
164
158
|
|
|
165
159
|
declare const MERKLE_TREE_MAX_DEPTH = 20;
|
|
166
160
|
/**
|
|
@@ -197,33 +191,51 @@ declare const getAddressFromSignature: (signature: `0x${string}`, messageHash?:
|
|
|
197
191
|
* @param numChoices Number of choices.
|
|
198
192
|
* @returns Maximum value per choice.
|
|
199
193
|
*/
|
|
200
|
-
declare const getMaxVoteValue: (numChoices: number) =>
|
|
194
|
+
declare const getMaxVoteValue: (numChoices: number) => number;
|
|
201
195
|
/**
|
|
202
196
|
* Get a zero vote with the given number of choices.
|
|
203
197
|
* @param numChoices Number of choices.
|
|
204
198
|
* @returns A zero vote with the given number of choices.
|
|
205
199
|
*/
|
|
206
|
-
declare const getZeroVote: (numChoices: number) =>
|
|
200
|
+
declare const getZeroVote: (numChoices: number) => number[];
|
|
207
201
|
|
|
208
202
|
/**
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
203
|
+
* Vote encoding and BFV encryption for the CRISP voting protocol.
|
|
204
|
+
*
|
|
205
|
+
* Encodes vote choices (numbers per option) into polynomial coefficient arrays
|
|
206
|
+
* suitable for BFV homomorphic encryption. Each choice is represented as a
|
|
207
|
+
* segment of binary digits, padded to fit the polynomial degree. Supports
|
|
208
|
+
* encoding, encryption, decryption, and tally decoding.
|
|
213
209
|
*/
|
|
214
|
-
|
|
210
|
+
|
|
215
211
|
/**
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
* @param
|
|
219
|
-
* @
|
|
212
|
+
* Encrypts an encoded vote using BFV homomorphic encryption.
|
|
213
|
+
*
|
|
214
|
+
* @param vote - Vote choices to encrypt
|
|
215
|
+
* @param publicKey - BFV public key
|
|
216
|
+
* @returns Encrypted ciphertext
|
|
220
217
|
*/
|
|
221
218
|
declare const encryptVote: (vote: Vote, publicKey: Uint8Array) => Uint8Array;
|
|
222
219
|
/**
|
|
223
|
-
*
|
|
224
|
-
*
|
|
220
|
+
* Decodes raw tally bytes (or hex string) into vote values per choice.
|
|
221
|
+
* Expects the same segment layout as used in encodeVote.
|
|
222
|
+
*
|
|
223
|
+
* @param tallyBytes - Hex string or array of decoded numbers from tally/decryption
|
|
224
|
+
* @param numChoices - Number of vote options
|
|
225
|
+
* @returns Vote array with one value per choice
|
|
226
|
+
*/
|
|
227
|
+
declare const decodeTally: (tallyBytes: string | number[], numChoices: number) => Vote;
|
|
228
|
+
/**
|
|
229
|
+
* Generates a BFV keypair for vote encryption and decryption.
|
|
230
|
+
*
|
|
231
|
+
* @returns Object with secretKey and publicKey as Uint8Arrays
|
|
225
232
|
*/
|
|
226
|
-
declare const
|
|
233
|
+
declare const generateBFVKeys: () => {
|
|
234
|
+
secretKey: Uint8Array;
|
|
235
|
+
publicKey: Uint8Array;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
declare const destroyBBApi: () => void;
|
|
227
239
|
/**
|
|
228
240
|
* Validate a vote.
|
|
229
241
|
* @param vote - The vote to validate.
|
|
@@ -278,10 +290,15 @@ declare class CrispSDK {
|
|
|
278
290
|
generateMaskVoteProof(maskProofInputs: MaskVoteProofRequest): Promise<ProofData>;
|
|
279
291
|
/**
|
|
280
292
|
* Generate a proof for a vote.
|
|
293
|
+
*
|
|
294
|
+
* Note: The previous ciphertext is not used in the proof computation. This method still calls
|
|
295
|
+
* the same server API (previous-ciphertext) as {@link generateMaskVoteProof} to prevent the
|
|
296
|
+
* server from inferring the vote type (mask vs normal) from the client's API usage pattern.
|
|
297
|
+
*
|
|
281
298
|
* @param voteProofInputs - The inputs required to generate the vote proof.
|
|
282
299
|
* @returns A promise that resolves to the generated proof data.
|
|
283
300
|
*/
|
|
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,
|
|
304
|
+
export { CreditMode, CrispSDK, MERKLE_TREE_MAX_DEPTH, type MaskVoteProofInputs, type ProofData, type RoundDetails, type RoundDetailsResponse, SIGNATURE_MESSAGE, SIGNATURE_MESSAGE_HASH, type TokenDetails, type Vote, type VoteProofInputs, decodeTally, destroyBBApi, encodeSolidityProof, encryptVote, generateBFVKeys, generateMaskVoteProof, generateMerkleProof, generateMerkleTree, generateVoteProof, getAddressFromSignature, getBalanceAt, getMaxVoteValue, getPreviousCiphertext, getRoundDetails, getRoundTokenDetails, getTotalSupplyAt, getTreeData, getZeroVote, hashLeaf, validateVote, verifyProof };
|