@vocdoni/davinci-sdk 0.0.1
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/LICENSE +661 -0
- package/README.md +635 -0
- package/dist/contracts.d.ts +512 -0
- package/dist/index.d.ts +1388 -0
- package/dist/index.js +2045 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2000 -0
- package/dist/index.mjs.map +1 -0
- package/dist/index.umd.js +2045 -0
- package/dist/sequencer.d.ts +538 -0
- package/package.json +103 -0
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
import { Signer, Wallet } from 'ethers';
|
|
2
|
+
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
3
|
+
|
|
4
|
+
type AnyJson = boolean | number | string | null | JsonArray | JsonMap | any;
|
|
5
|
+
interface JsonMap {
|
|
6
|
+
[key: string]: AnyJson;
|
|
7
|
+
}
|
|
8
|
+
interface JsonArray extends Array<AnyJson> {
|
|
9
|
+
}
|
|
10
|
+
type CustomMeta = AnyJson | JsonArray | JsonMap;
|
|
11
|
+
type MultiLanguage<T> = {
|
|
12
|
+
default: T;
|
|
13
|
+
[lang: string]: T;
|
|
14
|
+
};
|
|
15
|
+
interface IChoice {
|
|
16
|
+
title: MultiLanguage<string>;
|
|
17
|
+
value: number;
|
|
18
|
+
meta?: CustomMeta;
|
|
19
|
+
results?: string;
|
|
20
|
+
answer?: number;
|
|
21
|
+
}
|
|
22
|
+
interface IQuestion {
|
|
23
|
+
title: MultiLanguage<string>;
|
|
24
|
+
description?: MultiLanguage<string>;
|
|
25
|
+
numAbstains?: string;
|
|
26
|
+
meta?: CustomMeta;
|
|
27
|
+
choices: Array<IChoice>;
|
|
28
|
+
}
|
|
29
|
+
declare enum ElectionResultsTypeNames {
|
|
30
|
+
SINGLE_CHOICE_MULTIQUESTION = "single-choice-multiquestion",
|
|
31
|
+
MULTIPLE_CHOICE = "multiple-choice",
|
|
32
|
+
BUDGET = "budget-based",
|
|
33
|
+
APPROVAL = "approval",
|
|
34
|
+
QUADRATIC = "quadratic"
|
|
35
|
+
}
|
|
36
|
+
interface AbstainProperties {
|
|
37
|
+
canAbstain: boolean;
|
|
38
|
+
abstainValues: Array<string>;
|
|
39
|
+
}
|
|
40
|
+
interface ChoiceProperties {
|
|
41
|
+
repeatChoice: boolean;
|
|
42
|
+
numChoices: {
|
|
43
|
+
min: number;
|
|
44
|
+
max: number;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
interface BudgetProperties {
|
|
48
|
+
useCensusWeightAsBudget: boolean;
|
|
49
|
+
maxBudget: number;
|
|
50
|
+
minStep: number;
|
|
51
|
+
forceFullBudget: boolean;
|
|
52
|
+
}
|
|
53
|
+
interface ApprovalProperties {
|
|
54
|
+
rejectValue: number;
|
|
55
|
+
acceptValue: number;
|
|
56
|
+
}
|
|
57
|
+
interface QuadraticProperties extends BudgetProperties {
|
|
58
|
+
quadraticCost: number;
|
|
59
|
+
}
|
|
60
|
+
type ElectionResultsType = {
|
|
61
|
+
name: ElectionResultsTypeNames.SINGLE_CHOICE_MULTIQUESTION;
|
|
62
|
+
properties: Record<string, never>;
|
|
63
|
+
} | {
|
|
64
|
+
name: ElectionResultsTypeNames.MULTIPLE_CHOICE;
|
|
65
|
+
properties: AbstainProperties & ChoiceProperties;
|
|
66
|
+
} | {
|
|
67
|
+
name: ElectionResultsTypeNames.BUDGET;
|
|
68
|
+
properties: BudgetProperties;
|
|
69
|
+
} | {
|
|
70
|
+
name: ElectionResultsTypeNames.APPROVAL;
|
|
71
|
+
properties: ApprovalProperties;
|
|
72
|
+
} | {
|
|
73
|
+
name: ElectionResultsTypeNames.QUADRATIC;
|
|
74
|
+
properties: QuadraticProperties;
|
|
75
|
+
};
|
|
76
|
+
type ProtocolVersion = '1.1' | '1.2';
|
|
77
|
+
interface ElectionMetadata {
|
|
78
|
+
version: ProtocolVersion;
|
|
79
|
+
title: MultiLanguage<string>;
|
|
80
|
+
description: MultiLanguage<string>;
|
|
81
|
+
media: {
|
|
82
|
+
header: string;
|
|
83
|
+
logo: string;
|
|
84
|
+
};
|
|
85
|
+
meta?: {
|
|
86
|
+
[key: string]: any;
|
|
87
|
+
};
|
|
88
|
+
questions: Array<IQuestion>;
|
|
89
|
+
type: ElectionResultsType;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
declare class BaseService {
|
|
93
|
+
protected axios: AxiosInstance;
|
|
94
|
+
constructor(baseURL: string, config?: AxiosRequestConfig);
|
|
95
|
+
protected request<T>(config: AxiosRequestConfig): Promise<T>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Census origin types
|
|
100
|
+
*/
|
|
101
|
+
declare enum CensusOrigin {
|
|
102
|
+
/** Indicates that the census is derived from a Merkle Tree structure */
|
|
103
|
+
CensusOriginMerkleTree = 1,
|
|
104
|
+
/** Indicates that the census is provided by a Credential Service Provider (CSP) */
|
|
105
|
+
CensusOriginCSP = 2
|
|
106
|
+
}
|
|
107
|
+
interface BaseCensusProof {
|
|
108
|
+
/** The Merkle root (hex-prefixed). */
|
|
109
|
+
root: string;
|
|
110
|
+
/** The voter's address (hex-prefixed). */
|
|
111
|
+
address: string;
|
|
112
|
+
/** The weight as a decimal string. */
|
|
113
|
+
weight: string;
|
|
114
|
+
/** Census origin type: CensusOriginMerkleTree for merkle proofs, CensusOriginCSP for csp proofs */
|
|
115
|
+
censusOrigin: CensusOrigin;
|
|
116
|
+
}
|
|
117
|
+
interface MerkleCensusProof extends BaseCensusProof {
|
|
118
|
+
censusOrigin: CensusOrigin.CensusOriginMerkleTree;
|
|
119
|
+
/** The leaf value (hex-prefixed weight). */
|
|
120
|
+
value: string;
|
|
121
|
+
/** The serialized sibling path (hex-prefixed). */
|
|
122
|
+
siblings: string;
|
|
123
|
+
}
|
|
124
|
+
interface CSPCensusProof extends BaseCensusProof {
|
|
125
|
+
censusOrigin: CensusOrigin.CensusOriginCSP;
|
|
126
|
+
/** The process id signed with the address (hex-prefixed). */
|
|
127
|
+
processId: string;
|
|
128
|
+
/** The public key of the csp (hex-prefixed). */
|
|
129
|
+
publicKey: string;
|
|
130
|
+
/** The signature that proves that the voter is in the census (hex-prefixed). */
|
|
131
|
+
signature: string;
|
|
132
|
+
}
|
|
133
|
+
type CensusProof = MerkleCensusProof | CSPCensusProof;
|
|
134
|
+
|
|
135
|
+
interface BallotMode {
|
|
136
|
+
numFields: number;
|
|
137
|
+
maxValue: string;
|
|
138
|
+
minValue: string;
|
|
139
|
+
uniqueValues: boolean;
|
|
140
|
+
costFromWeight: boolean;
|
|
141
|
+
costExponent: number;
|
|
142
|
+
maxValueSum: string;
|
|
143
|
+
minValueSum: string;
|
|
144
|
+
}
|
|
145
|
+
interface Census {
|
|
146
|
+
censusOrigin: CensusOrigin;
|
|
147
|
+
maxVotes: string;
|
|
148
|
+
censusRoot: string;
|
|
149
|
+
censusURI: string;
|
|
150
|
+
}
|
|
151
|
+
interface EncryptionKey {
|
|
152
|
+
x: string;
|
|
153
|
+
y: string;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
interface CreateProcessRequest {
|
|
157
|
+
processId: string;
|
|
158
|
+
censusRoot: string;
|
|
159
|
+
ballotMode: BallotMode;
|
|
160
|
+
signature: string;
|
|
161
|
+
/**
|
|
162
|
+
* The censusOrigin specifies the origin type of the census used in the request.
|
|
163
|
+
* This attribute allows the API to determine how the census data should be processed or verified.
|
|
164
|
+
*/
|
|
165
|
+
censusOrigin: CensusOrigin;
|
|
166
|
+
}
|
|
167
|
+
interface CreateProcessResponse {
|
|
168
|
+
processId: string;
|
|
169
|
+
encryptionPubKey: [string, string];
|
|
170
|
+
stateRoot: string;
|
|
171
|
+
ballotMode: BallotMode;
|
|
172
|
+
}
|
|
173
|
+
interface GetProcessResponse {
|
|
174
|
+
id: string;
|
|
175
|
+
status: number;
|
|
176
|
+
organizationId: string;
|
|
177
|
+
encryptionKey: EncryptionKey;
|
|
178
|
+
stateRoot: string;
|
|
179
|
+
result: string[];
|
|
180
|
+
startTime: number;
|
|
181
|
+
duration: number;
|
|
182
|
+
metadataURI: string;
|
|
183
|
+
ballotMode: BallotMode;
|
|
184
|
+
census: Census;
|
|
185
|
+
metadata: {
|
|
186
|
+
title: Record<string, string>;
|
|
187
|
+
description: Record<string, string>;
|
|
188
|
+
media: {
|
|
189
|
+
header: string;
|
|
190
|
+
logo: string;
|
|
191
|
+
};
|
|
192
|
+
questions: {
|
|
193
|
+
title: Record<string, string>;
|
|
194
|
+
description: Record<string, string>;
|
|
195
|
+
choices: {
|
|
196
|
+
title: Record<string, string>;
|
|
197
|
+
value: number;
|
|
198
|
+
meta: Record<string, string>;
|
|
199
|
+
}[];
|
|
200
|
+
meta: Record<string, string>;
|
|
201
|
+
}[];
|
|
202
|
+
processType: {
|
|
203
|
+
name: string;
|
|
204
|
+
properties: Record<string, string>;
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
voteCount: string;
|
|
208
|
+
voteOverwrittenCount: string;
|
|
209
|
+
isAcceptingVotes: boolean;
|
|
210
|
+
sequencerStats: {
|
|
211
|
+
stateTransitionCount: number;
|
|
212
|
+
lastStateTransitionDate: string;
|
|
213
|
+
settledStateTransitionCount: number;
|
|
214
|
+
aggregatedVotesCount: number;
|
|
215
|
+
verifiedVotesCount: number;
|
|
216
|
+
pendingVotesCount: number;
|
|
217
|
+
currentBatchSize: number;
|
|
218
|
+
lastBatchSize: number;
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
interface VoteCiphertext {
|
|
222
|
+
c1: [string, string];
|
|
223
|
+
c2: [string, string];
|
|
224
|
+
}
|
|
225
|
+
interface VoteBallot {
|
|
226
|
+
curveType: string;
|
|
227
|
+
ciphertexts: VoteCiphertext[];
|
|
228
|
+
}
|
|
229
|
+
interface VoteProof {
|
|
230
|
+
pi_a: [string, string, string];
|
|
231
|
+
pi_b: [[string, string], [string, string], [string, string]];
|
|
232
|
+
pi_c: [string, string, string];
|
|
233
|
+
protocol: string;
|
|
234
|
+
}
|
|
235
|
+
interface VoteRequest {
|
|
236
|
+
/** The `processId` you obtained when creating the process. */
|
|
237
|
+
processId: string;
|
|
238
|
+
/** Your Merkle‐proof that you're in the census. */
|
|
239
|
+
censusProof: CensusProof;
|
|
240
|
+
/** Your encrypted ballot. */
|
|
241
|
+
ballot: VoteBallot;
|
|
242
|
+
/** The zkSNARK proof that the ballot is well‐formed. */
|
|
243
|
+
ballotProof: VoteProof;
|
|
244
|
+
/** Hash of the ballot inputs (decimal string). */
|
|
245
|
+
ballotInputsHash: string;
|
|
246
|
+
/** Your Ethereum address (hex-prefixed). */
|
|
247
|
+
address: string;
|
|
248
|
+
/** Signature over the raw bytes of the voteId. */
|
|
249
|
+
signature: string;
|
|
250
|
+
/** The vote ID (hex-prefixed). */
|
|
251
|
+
voteId: string;
|
|
252
|
+
}
|
|
253
|
+
interface InfoResponse {
|
|
254
|
+
circuitUrl: string;
|
|
255
|
+
circuitHash: string;
|
|
256
|
+
provingKeyUrl: string;
|
|
257
|
+
provingKeyHash: string;
|
|
258
|
+
verificationKeyUrl: string;
|
|
259
|
+
verificationKeyHash: string;
|
|
260
|
+
ballotProofWasmHelperUrl: string;
|
|
261
|
+
ballotProofWasmHelperHash: string;
|
|
262
|
+
ballotProofWasmHelperExecJsUrl: string;
|
|
263
|
+
ballotProofWasmHelperExecJsHash: string;
|
|
264
|
+
contracts: {
|
|
265
|
+
process: string;
|
|
266
|
+
organization: string;
|
|
267
|
+
stateTransitionVerifier: string;
|
|
268
|
+
resultsVerifier: string;
|
|
269
|
+
};
|
|
270
|
+
network: {
|
|
271
|
+
[key: string]: number;
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
declare enum VoteStatus {
|
|
275
|
+
Pending = "pending",
|
|
276
|
+
Verified = "verified",
|
|
277
|
+
Aggregated = "aggregated",
|
|
278
|
+
Processed = "processed",
|
|
279
|
+
Settled = "settled",
|
|
280
|
+
Error = "error"
|
|
281
|
+
}
|
|
282
|
+
interface VoteStatusResponse {
|
|
283
|
+
status: VoteStatus;
|
|
284
|
+
}
|
|
285
|
+
interface ListProcessesResponse {
|
|
286
|
+
processes: string[];
|
|
287
|
+
}
|
|
288
|
+
interface SequencerStats {
|
|
289
|
+
activeProcesses: number;
|
|
290
|
+
pendingVotes: number;
|
|
291
|
+
verifiedVotes: number;
|
|
292
|
+
aggregatedVotes: number;
|
|
293
|
+
stateTransitions: number;
|
|
294
|
+
settledStateTransitions: number;
|
|
295
|
+
lastStateTransitionDate: string;
|
|
296
|
+
}
|
|
297
|
+
interface WorkerStats {
|
|
298
|
+
name: string;
|
|
299
|
+
successCount: number;
|
|
300
|
+
failedCount: number;
|
|
301
|
+
}
|
|
302
|
+
interface WorkersResponse {
|
|
303
|
+
workers: WorkerStats[];
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Creates the signature message for process creation.
|
|
308
|
+
* @param processId - The process ID (with or without 0x prefix)
|
|
309
|
+
* @returns The message string to be signed
|
|
310
|
+
*/
|
|
311
|
+
declare function createProcessSignatureMessage(processId: string): string;
|
|
312
|
+
/**
|
|
313
|
+
* Signs the process creation message with the provided signer.
|
|
314
|
+
* @param processId - The process ID (with or without 0x prefix)
|
|
315
|
+
* @param signer - The signer (Wallet or Signer) to sign with
|
|
316
|
+
* @returns Promise resolving to the signature string
|
|
317
|
+
*/
|
|
318
|
+
declare function signProcessCreation(processId: string, signer: Signer | Wallet): Promise<string>;
|
|
319
|
+
/**
|
|
320
|
+
* Validates that a process ID is a valid 64-character hex string (32 bytes).
|
|
321
|
+
* @param processId - The process ID to validate
|
|
322
|
+
* @returns True if valid, false otherwise
|
|
323
|
+
*/
|
|
324
|
+
declare function validateProcessId(processId: string): boolean;
|
|
325
|
+
|
|
326
|
+
interface ProofInputs {
|
|
327
|
+
fields: string[];
|
|
328
|
+
num_fields: string;
|
|
329
|
+
unique_values: string;
|
|
330
|
+
max_value: string;
|
|
331
|
+
min_value: string;
|
|
332
|
+
max_value_sum: string;
|
|
333
|
+
min_value_sum: string;
|
|
334
|
+
cost_exponent: string;
|
|
335
|
+
cost_from_weight: string;
|
|
336
|
+
address: string;
|
|
337
|
+
weight: string;
|
|
338
|
+
process_id: string;
|
|
339
|
+
vote_id: string;
|
|
340
|
+
encryption_pubkey: [string, string];
|
|
341
|
+
k: string;
|
|
342
|
+
cipherfields: string[];
|
|
343
|
+
inputs_hash: string;
|
|
344
|
+
}
|
|
345
|
+
interface Groth16Proof {
|
|
346
|
+
pi_a: [string, string, string];
|
|
347
|
+
pi_b: [[string, string], [string, string], [string, string]];
|
|
348
|
+
pi_c: [string, string, string];
|
|
349
|
+
protocol: string;
|
|
350
|
+
curve: string;
|
|
351
|
+
}
|
|
352
|
+
interface CircomProofOptions {
|
|
353
|
+
wasmUrl?: string;
|
|
354
|
+
zkeyUrl?: string;
|
|
355
|
+
vkeyUrl?: string;
|
|
356
|
+
/** Optional SHA-256 hash to verify circuit WASM file integrity */
|
|
357
|
+
wasmHash?: string;
|
|
358
|
+
/** Optional SHA-256 hash to verify proving key file integrity */
|
|
359
|
+
zkeyHash?: string;
|
|
360
|
+
/** Optional SHA-256 hash to verify verification key file integrity */
|
|
361
|
+
vkeyHash?: string;
|
|
362
|
+
}
|
|
363
|
+
declare class CircomProof {
|
|
364
|
+
private readonly wasmUrl?;
|
|
365
|
+
private readonly zkeyUrl?;
|
|
366
|
+
private readonly vkeyUrl?;
|
|
367
|
+
private readonly wasmHash?;
|
|
368
|
+
private readonly zkeyHash?;
|
|
369
|
+
private readonly vkeyHash?;
|
|
370
|
+
private wasmCache;
|
|
371
|
+
private zkeyCache;
|
|
372
|
+
private vkeyCache;
|
|
373
|
+
constructor(opts?: CircomProofOptions);
|
|
374
|
+
/**
|
|
375
|
+
* Computes SHA-256 hash of the given data and compares it with the expected hash.
|
|
376
|
+
* @param data - The data to hash (string or ArrayBuffer or Uint8Array)
|
|
377
|
+
* @param expectedHash - The expected SHA-256 hash in hexadecimal format
|
|
378
|
+
* @param filename - The filename for error reporting
|
|
379
|
+
* @throws Error if the computed hash doesn't match the expected hash
|
|
380
|
+
*/
|
|
381
|
+
private verifyHash;
|
|
382
|
+
/**
|
|
383
|
+
* Generate a zk‐SNARK proof.
|
|
384
|
+
* If you didn't pass wasmUrl/zkeyUrl in the constructor you must supply them here.
|
|
385
|
+
*/
|
|
386
|
+
generate(inputs: ProofInputs, urls?: {
|
|
387
|
+
wasmUrl?: string;
|
|
388
|
+
zkeyUrl?: string;
|
|
389
|
+
}): Promise<{
|
|
390
|
+
proof: Groth16Proof;
|
|
391
|
+
publicSignals: string[];
|
|
392
|
+
}>;
|
|
393
|
+
verify(proof: Groth16Proof, publicSignals: string[], urlOverride?: string): Promise<boolean>;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
interface DavinciCryptoInputs {
|
|
397
|
+
address: string;
|
|
398
|
+
processID: string;
|
|
399
|
+
encryptionKey: [string, string];
|
|
400
|
+
k?: string;
|
|
401
|
+
weight: string;
|
|
402
|
+
fieldValues: string[];
|
|
403
|
+
ballotMode: BallotMode;
|
|
404
|
+
}
|
|
405
|
+
interface DavinciCryptoCiphertext {
|
|
406
|
+
c1: [string, string];
|
|
407
|
+
c2: [string, string];
|
|
408
|
+
}
|
|
409
|
+
interface DavinciCryptoOutput {
|
|
410
|
+
processId: string;
|
|
411
|
+
address: string;
|
|
412
|
+
ballot: {
|
|
413
|
+
curveType: string;
|
|
414
|
+
ciphertexts: DavinciCryptoCiphertext[];
|
|
415
|
+
};
|
|
416
|
+
ballotInputsHash: string;
|
|
417
|
+
voteId: string;
|
|
418
|
+
circomInputs: ProofInputs;
|
|
419
|
+
}
|
|
420
|
+
interface CSPSignOutput {
|
|
421
|
+
censusOrigin: CensusOrigin;
|
|
422
|
+
root: string;
|
|
423
|
+
address: string;
|
|
424
|
+
processId: string;
|
|
425
|
+
publicKey: string;
|
|
426
|
+
signature: string;
|
|
427
|
+
}
|
|
428
|
+
interface RawResult<T = any> {
|
|
429
|
+
error?: string;
|
|
430
|
+
data?: T;
|
|
431
|
+
}
|
|
432
|
+
interface GoDavinciCryptoWasm {
|
|
433
|
+
proofInputs(inputJson: string): RawResult<DavinciCryptoOutput>;
|
|
434
|
+
cspSign(censusOrigin: number, privKey: string, processId: string, address: string): RawResult<CSPSignOutput>;
|
|
435
|
+
cspVerify(cspProof: string): RawResult<boolean>;
|
|
436
|
+
cspCensusRoot(censusOrigin: number, privKey: string): RawResult<{
|
|
437
|
+
root: string;
|
|
438
|
+
}>;
|
|
439
|
+
}
|
|
440
|
+
declare global {
|
|
441
|
+
var Go: new () => {
|
|
442
|
+
importObject: Record<string, any>;
|
|
443
|
+
run(instance: WebAssembly.Instance): Promise<void>;
|
|
444
|
+
};
|
|
445
|
+
var DavinciCrypto: GoDavinciCryptoWasm;
|
|
446
|
+
}
|
|
447
|
+
interface DavinciCryptoOptions {
|
|
448
|
+
/** URL to wasm_exec.js */
|
|
449
|
+
wasmExecUrl: string;
|
|
450
|
+
/** URL to the compiled davinci_crypto.wasm */
|
|
451
|
+
wasmUrl: string;
|
|
452
|
+
/** How long (ms) to wait for the Go runtime to attach DavinciCrypto */
|
|
453
|
+
initTimeoutMs?: number;
|
|
454
|
+
/** Optional SHA-256 hash to verify wasm_exec.js integrity */
|
|
455
|
+
wasmExecHash?: string;
|
|
456
|
+
/** Optional SHA-256 hash to verify davinci_crypto.wasm integrity */
|
|
457
|
+
wasmHash?: string;
|
|
458
|
+
}
|
|
459
|
+
declare class DavinciCrypto {
|
|
460
|
+
private go;
|
|
461
|
+
private initialized;
|
|
462
|
+
private readonly wasmExecUrl;
|
|
463
|
+
private readonly wasmUrl;
|
|
464
|
+
private readonly initTimeoutMs;
|
|
465
|
+
private readonly wasmExecHash?;
|
|
466
|
+
private readonly wasmHash?;
|
|
467
|
+
private static wasmExecCache;
|
|
468
|
+
private static wasmBinaryCache;
|
|
469
|
+
constructor(opts: DavinciCryptoOptions);
|
|
470
|
+
/**
|
|
471
|
+
* Computes SHA-256 hash of the given data and compares it with the expected hash.
|
|
472
|
+
* @param data - The data to hash (string or ArrayBuffer)
|
|
473
|
+
* @param expectedHash - The expected SHA-256 hash in hexadecimal format
|
|
474
|
+
* @param filename - The filename for error reporting
|
|
475
|
+
* @throws Error if the computed hash doesn't match the expected hash
|
|
476
|
+
*/
|
|
477
|
+
private verifyHash;
|
|
478
|
+
/**
|
|
479
|
+
* Must be awaited before calling `proofInputs()`.
|
|
480
|
+
* Safe to call multiple times.
|
|
481
|
+
*/
|
|
482
|
+
init(): Promise<void>;
|
|
483
|
+
/**
|
|
484
|
+
* Convert your inputs into JSON, hand off to Go/WASM, then parse & return.
|
|
485
|
+
* @throws if called before `await init()`, or if Go returns an error
|
|
486
|
+
*/
|
|
487
|
+
proofInputs(inputs: DavinciCryptoInputs): Promise<DavinciCryptoOutput>;
|
|
488
|
+
/**
|
|
489
|
+
* Generate a CSP (Credential Service Provider) signature for census proof.
|
|
490
|
+
* @param censusOrigin - The census origin type (e.g., CensusOrigin.CensusOriginCSP)
|
|
491
|
+
* @param privKey - The private key in hex format
|
|
492
|
+
* @param processId - The process ID in hex format
|
|
493
|
+
* @param address - The address in hex format
|
|
494
|
+
* @returns The CSP proof as a parsed JSON object
|
|
495
|
+
* @throws if called before `await init()`, or if Go returns an error
|
|
496
|
+
*/
|
|
497
|
+
cspSign(censusOrigin: CensusOrigin, privKey: string, processId: string, address: string): Promise<CSPSignOutput>;
|
|
498
|
+
/**
|
|
499
|
+
* Verify a CSP (Credential Service Provider) proof.
|
|
500
|
+
* @param censusOrigin - The census origin type (e.g., CensusOrigin.CensusOriginCSP)
|
|
501
|
+
* @param root - The census root
|
|
502
|
+
* @param address - The address
|
|
503
|
+
* @param processId - The process ID
|
|
504
|
+
* @param publicKey - The public key
|
|
505
|
+
* @param signature - The signature
|
|
506
|
+
* @returns The verification result
|
|
507
|
+
* @throws if called before `await init()`, or if Go returns an error
|
|
508
|
+
*/
|
|
509
|
+
cspVerify(censusOrigin: CensusOrigin, root: string, address: string, processId: string, publicKey: string, signature: string): Promise<boolean>;
|
|
510
|
+
/**
|
|
511
|
+
* Generate a CSP (Credential Service Provider) census root.
|
|
512
|
+
* @param censusOrigin - The census origin type (e.g., CensusOrigin.CensusOriginCSP)
|
|
513
|
+
* @param privKey - The private key in hex format
|
|
514
|
+
* @returns The census root as a hexadecimal string
|
|
515
|
+
* @throws if called before `await init()`, or if Go returns an error
|
|
516
|
+
*/
|
|
517
|
+
cspCensusRoot(censusOrigin: CensusOrigin, privKey: string): Promise<string>;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
declare class VocdoniSequencerService extends BaseService {
|
|
521
|
+
constructor(baseURL: string);
|
|
522
|
+
ping(): Promise<void>;
|
|
523
|
+
createProcess(body: CreateProcessRequest): Promise<CreateProcessResponse>;
|
|
524
|
+
getProcess(processId: string): Promise<GetProcessResponse>;
|
|
525
|
+
listProcesses(): Promise<string[]>;
|
|
526
|
+
submitVote(vote: VoteRequest): Promise<void>;
|
|
527
|
+
getVoteStatus(processId: string, voteId: string): Promise<VoteStatusResponse>;
|
|
528
|
+
hasAddressVoted(processId: string, address: string): Promise<boolean>;
|
|
529
|
+
getInfo(): Promise<InfoResponse>;
|
|
530
|
+
pushMetadata(metadata: ElectionMetadata): Promise<string>;
|
|
531
|
+
getMetadata(hashOrUrl: string): Promise<ElectionMetadata>;
|
|
532
|
+
getMetadataUrl(hash: string): string;
|
|
533
|
+
getStats(): Promise<SequencerStats>;
|
|
534
|
+
getWorkers(): Promise<WorkersResponse>;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
export { CircomProof, DavinciCrypto, VocdoniSequencerService, VoteStatus, createProcessSignatureMessage, signProcessCreation, validateProcessId };
|
|
538
|
+
export type { CSPSignOutput, CircomProofOptions, CreateProcessRequest, CreateProcessResponse, DavinciCryptoCiphertext, DavinciCryptoInputs, DavinciCryptoOptions, DavinciCryptoOutput, GetProcessResponse, Groth16Proof, InfoResponse, ListProcessesResponse, ProofInputs, SequencerStats, VoteBallot, VoteCiphertext, VoteProof, VoteRequest, VoteStatusResponse, WorkerStats, WorkersResponse };
|
package/package.json
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vocdoni/davinci-sdk",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.mjs",
|
|
16
|
+
"require": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"clean": "rimraf dist",
|
|
21
|
+
"build": "yarn clean && rollup -c",
|
|
22
|
+
"dev": "rollup -c -w",
|
|
23
|
+
"lint": "eslint . --ext .ts",
|
|
24
|
+
"lint:fix": "eslint . --ext .ts --fix",
|
|
25
|
+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
26
|
+
"format:check": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
27
|
+
"lint-staged": "lint-staged",
|
|
28
|
+
"test": "yarn test:unit && yarn test:integration",
|
|
29
|
+
"test:unit": "yarn test:contracts:unit && yarn test:sequencer:unit",
|
|
30
|
+
"test:integration": "yarn test:contracts:integration && yarn test:sequencer:integration && yarn test:census:integration",
|
|
31
|
+
"test:contracts": "yarn test:contracts:unit && yarn test:contracts:integration",
|
|
32
|
+
"test:contracts:unit": "jest 'test/contracts/unit'",
|
|
33
|
+
"test:contracts:integration": "jest 'test/contracts/integration' --runInBand",
|
|
34
|
+
"test:sequencer": "yarn test:sequencer:unit && yarn test:sequencer:integration",
|
|
35
|
+
"test:sequencer:unit": "jest 'test/sequencer/unit'",
|
|
36
|
+
"test:sequencer:integration": "jest 'test/sequencer/integration' --runInBand",
|
|
37
|
+
"test:census": "yarn test:census:integration",
|
|
38
|
+
"test:census:integration": "jest 'test/census/integration' --runInBand"
|
|
39
|
+
},
|
|
40
|
+
"description": "A powerful TypeScript SDK for building decentralized voting applications on the Vocdoni DaVinci protocol with homomorphic encryption and zero-knowledge proofs",
|
|
41
|
+
"keywords": [
|
|
42
|
+
"vocdoni",
|
|
43
|
+
"davinci",
|
|
44
|
+
"voting",
|
|
45
|
+
"blockchain",
|
|
46
|
+
"ethereum",
|
|
47
|
+
"decentralized",
|
|
48
|
+
"privacy",
|
|
49
|
+
"homomorphic-encryption",
|
|
50
|
+
"zero-knowledge",
|
|
51
|
+
"zk-snarks",
|
|
52
|
+
"typescript",
|
|
53
|
+
"sdk",
|
|
54
|
+
"elections",
|
|
55
|
+
"governance",
|
|
56
|
+
"cryptography",
|
|
57
|
+
"web3"
|
|
58
|
+
],
|
|
59
|
+
"author": {
|
|
60
|
+
"name": "Vocdoni",
|
|
61
|
+
"email": "info@vocdoni.io",
|
|
62
|
+
"url": "https://vocdoni.io"
|
|
63
|
+
},
|
|
64
|
+
"license": "MIT",
|
|
65
|
+
"homepage": "https://github.com/vocdoni/davinci-sdk#readme",
|
|
66
|
+
"repository": {
|
|
67
|
+
"type": "git",
|
|
68
|
+
"url": "git+https://github.com/vocdoni/davinci-sdk.git"
|
|
69
|
+
},
|
|
70
|
+
"bugs": {
|
|
71
|
+
"url": "https://github.com/vocdoni/davinci-sdk/issues"
|
|
72
|
+
},
|
|
73
|
+
"dependencies": {
|
|
74
|
+
"@ethereumjs/common": "^4.4.0",
|
|
75
|
+
"@vocdoni/davinci-contracts": "0.0.18",
|
|
76
|
+
"axios": "^1.8.4",
|
|
77
|
+
"ethers": "^6.7.1",
|
|
78
|
+
"snarkjs": "^0.7.5"
|
|
79
|
+
},
|
|
80
|
+
"devDependencies": {
|
|
81
|
+
"lint-staged": "^15.2.0",
|
|
82
|
+
"@rollup/plugin-commonjs": "^28.0.3",
|
|
83
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
84
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
85
|
+
"@types/jest": "^29.5.4",
|
|
86
|
+
"@types/node": "^20.5.9",
|
|
87
|
+
"@typescript-eslint/eslint-plugin": "^6.6.0",
|
|
88
|
+
"@typescript-eslint/parser": "^6.6.0",
|
|
89
|
+
"dotenv": "^16.4.7",
|
|
90
|
+
"esbuild": "^0.25.2",
|
|
91
|
+
"eslint": "^8.48.0",
|
|
92
|
+
"jest": "^29.7.0",
|
|
93
|
+
"prettier": "^3.0.3",
|
|
94
|
+
"rimraf": "^5.0.1",
|
|
95
|
+
"rollup": "^4.0.0",
|
|
96
|
+
"rollup-plugin-copy": "^3.5.0",
|
|
97
|
+
"rollup-plugin-dts": "^6.2.1",
|
|
98
|
+
"rollup-plugin-esbuild": "^6.2.1",
|
|
99
|
+
"rollup-plugin-polyfill-node": "^0.13.0",
|
|
100
|
+
"ts-jest": "^29.3.1",
|
|
101
|
+
"typescript": "^5.2.2"
|
|
102
|
+
}
|
|
103
|
+
}
|