@crisp-e3/sdk 0.16.0 → 0.18.0-insecure.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 CHANGED
@@ -16,6 +16,36 @@ npm install @crisp-e3/sdk
16
16
  - **Merkle Tree Utilities**: Generate proofs for voter inclusion in the eligibility tree
17
17
  - **Vote Proof Generation**: Create zero-knowledge proofs for votes and mask votes
18
18
  - **Proof Verification**: Verify generated proofs using Noir circuits
19
+ - **Selectable Parameters**: `insecure-512` and `secure-8192` circuits ship as separate entry points
20
+
21
+ ## Choosing a preset
22
+
23
+ Proving needs the BFV-shaped circuits, and those exist once per parameter set. They are not part of
24
+ the main entry point: the `secure-8192` set is far larger than `insecure-512`, and no consumer needs
25
+ both. Each ships as its own subpath, so your bundler pulls only the one you import.
26
+
27
+ ```ts
28
+ import { setCircuits } from '@crisp-e3/sdk'
29
+ import { loadCircuits } from '@crisp-e3/sdk/insecure-512' // or '@crisp-e3/sdk/secure-8192'
30
+
31
+ setCircuits(await loadCircuits())
32
+ ```
33
+
34
+ Register once at start-up, before the first `prepareBallot`/`generateProof`. There is deliberately
35
+ no default: a ballot proved against the wrong parameters is rejected on chain rather than locally,
36
+ so `generateProof` throws a directed error instead of guessing.
37
+
38
+ In a browser, load it through a dynamic `import()` so the circuits become their own chunk and the
39
+ app boots without them:
40
+
41
+ ```ts
42
+ const { loadCircuits } = await import('@crisp-e3/sdk/insecure-512')
43
+ setCircuits(await loadCircuits())
44
+ ```
45
+
46
+ `verifyProof`, `encodeVote`, `decodeTally` and the round/token helpers need no preset. The
47
+ aggregation circuits they use are proof-shaped rather than polynomial-shaped, so a single artifact
48
+ covers every preset and ships in the main entry point.
19
49
 
20
50
  ## Usage
21
51
 
@@ -31,7 +61,7 @@ const sdk = new CrispSDK(serverUrl)
31
61
 
32
62
  // Generate a vote proof (automatically fetches previous ciphertext if needed)
33
63
  const voteProof = await sdk.generateVoteProof({
34
- e3Id: 1,
64
+ e3Id: 1n,
35
65
  vote: { yes: 100n, no: 0n },
36
66
  publicKey: publicKeyBytes,
37
67
  signature: '0x...',
@@ -43,7 +73,7 @@ const voteProof = await sdk.generateVoteProof({
43
73
 
44
74
  // Generate a mask vote proof (automatically fetches previous ciphertext if needed)
45
75
  const maskProof = await sdk.generateMaskVoteProof({
46
- e3Id: 1,
76
+ e3Id: 1n,
47
77
  balance: 1000n,
48
78
  slotAddress: '0x...',
49
79
  publicKey: publicKeyBytes,
@@ -151,8 +181,11 @@ const address = await getAddressFromSignature(signature, messageHash)
151
181
  ```typescript
152
182
  import { getPreviousCiphertext } from '@crisp-e3/sdk'
153
183
 
154
- const previousCiphertext = await getPreviousCiphertext(serverUrl, e3Id, slotAddress)
155
- // Returns undefined when the slot is empty (404)
184
+ const head = await getPreviousCiphertext(serverUrl, e3Id, slotAddress)
185
+ // { ciphertext, index }, or undefined when the slot holds nothing usable (404).
186
+ // `index` is the entry a new input names as its parent. It is the end of the slot's chain of
187
+ // usable entries, not simply the newest one published: an entry whose bytes do not reproduce its
188
+ // commitment is never selected by the Secure Process, and never a valid parent.
156
189
  ```
157
190
 
158
191
  ## API
@@ -167,11 +200,12 @@ const previousCiphertext = await getPreviousCiphertext(serverUrl, e3Id, slotAddr
167
200
 
168
201
  ### State Functions
169
202
 
170
- - `getRoundDetails(serverUrl: string, e3Id: number): Promise<RoundDetails>` - Get round details
171
- - `getRoundTokenDetails(serverUrl: string, e3Id: number): Promise<TokenDetails>` - Get token details
203
+ - `getRoundDetails(serverUrl: string, e3Id: bigint): Promise<RoundDetails>` - Get round details
204
+ - `getRoundTokenDetails(serverUrl: string, e3Id: bigint): Promise<TokenDetails>` - Get token details
172
205
  for a round
173
- - `getPreviousCiphertext(serverUrl: string, e3Id: number, address: string): Promise<Uint8Array | undefined>` -
174
- Get previous ciphertext for a slot (undefined when slot is empty)
206
+ - `getPreviousCiphertext(serverUrl: string, e3Id: bigint, address: string): Promise<SlotHead | undefined>` -
207
+ Get the end of a slot's chain of usable entries, as `{ ciphertext, index }`. `index` is what a new
208
+ input names as its parent. Undefined when the slot holds nothing usable.
175
209
 
176
210
  ### Token Functions
177
211
 
@@ -179,7 +213,7 @@ const previousCiphertext = await getPreviousCiphertext(serverUrl, e3Id, slotAddr
179
213
  Get token balance at a specific block
180
214
  - `getTotalSupplyAt(tokenAddress: string, snapshotBlock: number, chainId: number): Promise<bigint>` -
181
215
  Get total supply at a specific block
182
- - `getTreeData(serverUrl: string, e3Id: number): Promise<bigint[]>` - Get merkle tree leaves from
216
+ - `getTreeData(serverUrl: string, e3Id: bigint): Promise<bigint[]>` - Get merkle tree leaves from
183
217
  server
184
218
 
185
219
  ### Vote Functions