@crisp-e3/sdk 0.4.2 → 0.5.3
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 +99 -8
- package/dist/index.js +157 -37
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -94,11 +94,29 @@ type Vote = {
|
|
|
94
94
|
no: bigint;
|
|
95
95
|
};
|
|
96
96
|
type MaskVoteProofInputs = {
|
|
97
|
-
|
|
97
|
+
publicKey: Uint8Array;
|
|
98
|
+
balance: bigint;
|
|
99
|
+
slotAddress: string;
|
|
98
100
|
merkleLeaves: string[] | bigint[];
|
|
101
|
+
isFirstVote: boolean;
|
|
102
|
+
previousCiphertext: Uint8Array;
|
|
103
|
+
};
|
|
104
|
+
type MaskVoteProofRequest = {
|
|
105
|
+
e3Id: number;
|
|
99
106
|
publicKey: Uint8Array;
|
|
100
107
|
balance: bigint;
|
|
101
108
|
slotAddress: string;
|
|
109
|
+
merkleLeaves: string[] | bigint[];
|
|
110
|
+
};
|
|
111
|
+
type VoteProofRequest = {
|
|
112
|
+
e3Id: number;
|
|
113
|
+
merkleLeaves: string[] | bigint[];
|
|
114
|
+
publicKey: Uint8Array;
|
|
115
|
+
balance: bigint;
|
|
116
|
+
vote: Vote;
|
|
117
|
+
signature: `0x${string}`;
|
|
118
|
+
messageHash: `0x${string}`;
|
|
119
|
+
slotAddress: string;
|
|
102
120
|
};
|
|
103
121
|
type VoteProofInputs = {
|
|
104
122
|
merkleLeaves: string[] | bigint[];
|
|
@@ -106,6 +124,10 @@ type VoteProofInputs = {
|
|
|
106
124
|
balance: bigint;
|
|
107
125
|
vote: Vote;
|
|
108
126
|
signature: `0x${string}`;
|
|
127
|
+
messageHash: `0x${string}`;
|
|
128
|
+
slotAddress: string;
|
|
129
|
+
isFirstVote: boolean;
|
|
130
|
+
previousCiphertext: Uint8Array;
|
|
109
131
|
};
|
|
110
132
|
|
|
111
133
|
/**
|
|
@@ -119,18 +141,36 @@ declare const getRoundDetails: (serverUrl: string, e3Id: number) => Promise<Roun
|
|
|
119
141
|
* @returns The token address, balance threshold and snapshot block
|
|
120
142
|
*/
|
|
121
143
|
declare const getRoundTokenDetails: (serverUrl: string, e3Id: number) => Promise<TokenDetails>;
|
|
144
|
+
/**
|
|
145
|
+
* Get the previous ciphertext for a slot from the CRISP server
|
|
146
|
+
* @param serverUrl - The base URL of the CRISP server
|
|
147
|
+
* @param e3Id - The e3Id of the round
|
|
148
|
+
* @param address - The address of the slot
|
|
149
|
+
* @returns The previous ciphertext for the slot
|
|
150
|
+
*/
|
|
151
|
+
declare const getPreviousCiphertext: (serverUrl: string, e3Id: number, address: string) => Promise<Uint8Array>;
|
|
152
|
+
/**
|
|
153
|
+
* Check if a slot is empty for a given E3 ID and slot address
|
|
154
|
+
* @param serverUrl - The base URL of the CRISP server
|
|
155
|
+
* @param e3Id - The e3Id of the round
|
|
156
|
+
* @param address - The address of the slot
|
|
157
|
+
* @returns Whether the slot is empty or not
|
|
158
|
+
*/
|
|
159
|
+
declare const getIsSlotEmpty: (serverUrl: string, e3Id: number, address: string) => Promise<boolean>;
|
|
122
160
|
|
|
123
161
|
declare const MERKLE_TREE_MAX_DEPTH = 20;
|
|
124
162
|
/**
|
|
125
|
-
* This is the maximum value for a vote (Yes or No). This is 2^
|
|
126
|
-
* The minimum degree that BFV should use is
|
|
163
|
+
* This is the maximum value for a vote (Yes or No). This is 2^50 - 1
|
|
164
|
+
* The minimum degree that BFV should use is 100 (to accommodate both Yes and No votes)
|
|
127
165
|
*/
|
|
128
|
-
declare const MAXIMUM_VOTE_VALUE:
|
|
166
|
+
declare const MAXIMUM_VOTE_VALUE: number;
|
|
129
167
|
/**
|
|
130
168
|
* Message used by users to prove ownership of their Ethereum account
|
|
131
169
|
* This message is signed by the user's private key to authenticate their identity
|
|
170
|
+
* @notice Apps ideally want to use a different message to avoid signature reuse across different applications
|
|
132
171
|
*/
|
|
133
172
|
declare const SIGNATURE_MESSAGE = "CRISP: Sign this message to prove ownership of your Ethereum account";
|
|
173
|
+
declare const SIGNATURE_MESSAGE_HASH: `0x${string}`;
|
|
134
174
|
|
|
135
175
|
/**
|
|
136
176
|
* Hash a leaf node for the Merkle tree
|
|
@@ -152,18 +192,43 @@ declare const generateMerkleTree: (leaves: bigint[]) => LeanIMT;
|
|
|
152
192
|
* @param leaves The leaves of the Merkle tree
|
|
153
193
|
*/
|
|
154
194
|
declare const generateMerkleProof: (balance: bigint, address: string, leaves: bigint[] | string[]) => MerkleProof;
|
|
155
|
-
declare const getAddressFromSignature: (signature: `0x${string}`) => Promise<string>;
|
|
195
|
+
declare const getAddressFromSignature: (signature: `0x${string}`, messageHash?: `0x${string}`) => Promise<string>;
|
|
156
196
|
|
|
157
197
|
/**
|
|
158
198
|
* Decode an encoded tally into its decimal representation.
|
|
159
|
-
* @param
|
|
199
|
+
* @param tallyBytes The encoded tally as a hex string (bytes).
|
|
160
200
|
* @returns The decoded tally as an IVote.
|
|
161
201
|
*/
|
|
162
|
-
declare const decodeTally: (
|
|
202
|
+
declare const decodeTally: (tallyBytes: string) => Vote;
|
|
203
|
+
/**
|
|
204
|
+
* Encrypt the vote using the public key.
|
|
205
|
+
* @param vote - The vote to encrypt.
|
|
206
|
+
* @param publicKey - The public key to use for encryption.
|
|
207
|
+
* @returns The encrypted vote as a Uint8Array.
|
|
208
|
+
*/
|
|
163
209
|
declare const encryptVote: (vote: Vote, publicKey: Uint8Array) => Uint8Array;
|
|
210
|
+
/**
|
|
211
|
+
* Generate a random public key.
|
|
212
|
+
* @returns The generated public key as a Uint8Array.
|
|
213
|
+
*/
|
|
164
214
|
declare const generatePublicKey: () => Uint8Array;
|
|
215
|
+
/**
|
|
216
|
+
* Generate a vote proof for the CRISP circuit given the vote proof inputs.
|
|
217
|
+
* @param voteProofInputs - The vote proof inputs.
|
|
218
|
+
* @returns The vote proof.
|
|
219
|
+
*/
|
|
165
220
|
declare const generateVoteProof: (voteProofInputs: VoteProofInputs) => Promise<ProofData>;
|
|
221
|
+
/**
|
|
222
|
+
* Generate a proof for a vote masking operation.
|
|
223
|
+
* @param maskVoteProofInputs The mask vote proof inputs.
|
|
224
|
+
* @returns
|
|
225
|
+
*/
|
|
166
226
|
declare const generateMaskVoteProof: (maskVoteProofInputs: MaskVoteProofInputs) => Promise<ProofData>;
|
|
227
|
+
/**
|
|
228
|
+
* Locally verify a Noir proof.
|
|
229
|
+
* @param proof - The proof to verify.
|
|
230
|
+
* @returns True if the proof is valid, false otherwise.
|
|
231
|
+
*/
|
|
167
232
|
declare const verifyProof: (proof: ProofData) => Promise<boolean>;
|
|
168
233
|
/**
|
|
169
234
|
* Encode the proof data into a format that can be used by the CRISP program in Solidity
|
|
@@ -173,4 +238,30 @@ declare const verifyProof: (proof: ProofData) => Promise<boolean>;
|
|
|
173
238
|
*/
|
|
174
239
|
declare const encodeSolidityProof: (proof: ProofData) => Hex;
|
|
175
240
|
|
|
176
|
-
|
|
241
|
+
/**
|
|
242
|
+
* A class representing the Crisp SDK.
|
|
243
|
+
*/
|
|
244
|
+
declare class CrispSDK {
|
|
245
|
+
/**
|
|
246
|
+
* The server URL for the Crisp SDK.
|
|
247
|
+
* It's used by methods that communicate directly with the Crisp server.
|
|
248
|
+
*/
|
|
249
|
+
private serverUrl;
|
|
250
|
+
/**
|
|
251
|
+
* Create a new instance
|
|
252
|
+
* @param serverUrl
|
|
253
|
+
*/
|
|
254
|
+
constructor(serverUrl: string);
|
|
255
|
+
/**
|
|
256
|
+
* Generate a proof for a vote masking.
|
|
257
|
+
*/
|
|
258
|
+
generateMaskVoteProof(maskProofInputs: MaskVoteProofRequest): Promise<ProofData>;
|
|
259
|
+
/**
|
|
260
|
+
* Generate a proof for a vote.
|
|
261
|
+
* @param voteProofInputs - The inputs required to generate the vote proof.
|
|
262
|
+
* @returns A promise that resolves to the generated proof data.
|
|
263
|
+
*/
|
|
264
|
+
generateVoteProof(voteProofInputs: VoteProofRequest): Promise<ProofData>;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
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 };
|