@vocdoni/davinci-sdk 0.0.6 → 0.1.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 +51 -31
- package/dist/contracts.d.ts +22 -10
- package/dist/index.d.ts +112 -92
- package/dist/index.js +151 -144
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +147 -142
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +151 -144
- package/dist/sequencer.d.ts +12 -7
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ yarn add @vocdoni/davinci-sdk
|
|
|
20
20
|
### Basic Usage
|
|
21
21
|
|
|
22
22
|
```typescript
|
|
23
|
-
import { DavinciSDK,
|
|
23
|
+
import { DavinciSDK, OffchainCensus } from '@vocdoni/davinci-sdk';
|
|
24
24
|
import { Wallet } from 'ethers';
|
|
25
25
|
|
|
26
26
|
// Initialize the SDK
|
|
@@ -34,7 +34,7 @@ const sdk = new DavinciSDK({
|
|
|
34
34
|
await sdk.init();
|
|
35
35
|
|
|
36
36
|
// 1. Create a census with eligible voters
|
|
37
|
-
const census = new
|
|
37
|
+
const census = new OffchainCensus(); // Supports both plain and weighted voting
|
|
38
38
|
census.add([
|
|
39
39
|
'0x1234567890123456789012345678901234567890',
|
|
40
40
|
'0x2345678901234567890123456789012345678901',
|
|
@@ -152,14 +152,16 @@ The SDK provides simple-to-use census classes that make voter management easy. C
|
|
|
152
152
|
|
|
153
153
|
### Census Types
|
|
154
154
|
|
|
155
|
-
####
|
|
155
|
+
#### OffchainCensus - Static Merkle Tree Census
|
|
156
156
|
|
|
157
|
-
|
|
157
|
+
A flexible census that supports both plain addresses (equal voting power) and weighted participants.
|
|
158
|
+
|
|
159
|
+
**Plain addresses (everyone gets weight = 1):**
|
|
158
160
|
|
|
159
161
|
```typescript
|
|
160
|
-
import {
|
|
162
|
+
import { OffchainCensus } from '@vocdoni/davinci-sdk';
|
|
161
163
|
|
|
162
|
-
const census = new
|
|
164
|
+
const census = new OffchainCensus();
|
|
163
165
|
census.add([
|
|
164
166
|
'0x1234567890123456789012345678901234567890',
|
|
165
167
|
'0xabcdefabcdefabcdefabcdefabcdefabcdefabcd',
|
|
@@ -168,19 +170,19 @@ census.add([
|
|
|
168
170
|
|
|
169
171
|
// Use directly in process creation - SDK auto-publishes!
|
|
170
172
|
const process = await sdk.createProcess({
|
|
171
|
-
census: census, // ✨ Auto-published!
|
|
173
|
+
census: census, // ✨ Auto-published! maxVoters auto-calculated!
|
|
172
174
|
// ... rest of config
|
|
173
175
|
});
|
|
174
176
|
```
|
|
175
177
|
|
|
176
|
-
|
|
178
|
+
**Weighted participants (custom voting power):**
|
|
177
179
|
|
|
178
|
-
|
|
180
|
+
Supports flexible weight types: **string**, **number**, or **bigint**.
|
|
179
181
|
|
|
180
182
|
```typescript
|
|
181
|
-
import {
|
|
183
|
+
import { OffchainCensus } from '@vocdoni/davinci-sdk';
|
|
182
184
|
|
|
183
|
-
const census = new
|
|
185
|
+
const census = new OffchainCensus();
|
|
184
186
|
|
|
185
187
|
census.add([
|
|
186
188
|
{ key: '0x123...', weight: "1" }, // string
|
|
@@ -188,7 +190,27 @@ census.add([
|
|
|
188
190
|
{ key: '0x789...', weight: 100n }, // bigint
|
|
189
191
|
]);
|
|
190
192
|
|
|
191
|
-
// Auto-published when creating process
|
|
193
|
+
// Auto-published when creating process, maxVoters auto-set to participant count
|
|
194
|
+
const process = await sdk.createProcess({
|
|
195
|
+
census: census,
|
|
196
|
+
// ... rest of config
|
|
197
|
+
});
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
#### OffchainDynamicCensus - Updatable Merkle Tree Census
|
|
201
|
+
|
|
202
|
+
Similar to OffchainCensus but allows census updates after process creation.
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
import { OffchainDynamicCensus } from '@vocdoni/davinci-sdk';
|
|
206
|
+
|
|
207
|
+
const census = new OffchainDynamicCensus();
|
|
208
|
+
census.add([
|
|
209
|
+
{ key: '0x123...', weight: 10 },
|
|
210
|
+
{ key: '0x456...', weight: 20 }
|
|
211
|
+
]);
|
|
212
|
+
|
|
213
|
+
// Auto-published and updatable
|
|
192
214
|
const process = await sdk.createProcess({
|
|
193
215
|
census: census,
|
|
194
216
|
// ... rest of config
|
|
@@ -204,12 +226,12 @@ import { CspCensus } from '@vocdoni/davinci-sdk';
|
|
|
204
226
|
|
|
205
227
|
const census = new CspCensus(
|
|
206
228
|
"0x1234567890abcdef", // Root hash (public key)
|
|
207
|
-
"https://csp-server.com"
|
|
208
|
-
1000 // Expected number of voters
|
|
229
|
+
"https://csp-server.com" // CSP URL
|
|
209
230
|
);
|
|
210
231
|
|
|
211
232
|
const process = await sdk.createProcess({
|
|
212
233
|
census: census,
|
|
234
|
+
maxVoters: 1000, // Required for CSP census
|
|
213
235
|
// ... rest of config
|
|
214
236
|
});
|
|
215
237
|
```
|
|
@@ -219,17 +241,17 @@ const process = await sdk.createProcess({
|
|
|
219
241
|
For censuses already published to the network.
|
|
220
242
|
|
|
221
243
|
```typescript
|
|
222
|
-
import { PublishedCensus,
|
|
244
|
+
import { PublishedCensus, CensusOrigin } from '@vocdoni/davinci-sdk';
|
|
223
245
|
|
|
224
246
|
const census = new PublishedCensus(
|
|
225
|
-
|
|
247
|
+
CensusOrigin.OffchainStatic,
|
|
226
248
|
"0xroot...",
|
|
227
|
-
"ipfs://uri..."
|
|
228
|
-
100 // size
|
|
249
|
+
"ipfs://uri..."
|
|
229
250
|
);
|
|
230
251
|
|
|
231
252
|
const process = await sdk.createProcess({
|
|
232
253
|
census: census,
|
|
254
|
+
maxVoters: 100, // Required for pre-published census
|
|
233
255
|
// ... rest of config
|
|
234
256
|
});
|
|
235
257
|
```
|
|
@@ -239,7 +261,7 @@ const process = await sdk.createProcess({
|
|
|
239
261
|
The SDK automatically publishes unpublished censuses when creating a process:
|
|
240
262
|
|
|
241
263
|
```typescript
|
|
242
|
-
const census = new
|
|
264
|
+
const census = new OffchainCensus();
|
|
243
265
|
census.add(['0x123...', '0x456...']);
|
|
244
266
|
|
|
245
267
|
console.log(census.isPublished); // false
|
|
@@ -257,10 +279,10 @@ console.log(census.censusURI); // Published URI
|
|
|
257
279
|
|
|
258
280
|
### Flexible Weight Types
|
|
259
281
|
|
|
260
|
-
|
|
282
|
+
OffchainCensus accepts weights as strings, numbers, or bigints for maximum flexibility:
|
|
261
283
|
|
|
262
284
|
```typescript
|
|
263
|
-
const census = new
|
|
285
|
+
const census = new OffchainCensus();
|
|
264
286
|
|
|
265
287
|
// String weights (recommended for very large numbers)
|
|
266
288
|
census.add({ key: '0x123...', weight: "999999999999" });
|
|
@@ -282,7 +304,7 @@ census.add([
|
|
|
282
304
|
### Census Operations
|
|
283
305
|
|
|
284
306
|
```typescript
|
|
285
|
-
const census = new
|
|
307
|
+
const census = new OffchainCensus();
|
|
286
308
|
|
|
287
309
|
// Add single participant
|
|
288
310
|
census.add({ key: '0x123...', weight: 5 });
|
|
@@ -310,7 +332,6 @@ const participants = census.participants;
|
|
|
310
332
|
if (census.isPublished) {
|
|
311
333
|
console.log('Root:', census.censusRoot);
|
|
312
334
|
console.log('URI:', census.censusURI);
|
|
313
|
-
console.log('Size:', census.size);
|
|
314
335
|
}
|
|
315
336
|
```
|
|
316
337
|
|
|
@@ -321,11 +342,11 @@ For advanced use cases, you can still provide census data manually:
|
|
|
321
342
|
```typescript
|
|
322
343
|
const process = await sdk.createProcess({
|
|
323
344
|
census: {
|
|
324
|
-
type: CensusOrigin.
|
|
345
|
+
type: CensusOrigin.OffchainStatic,
|
|
325
346
|
root: "0xabc...",
|
|
326
|
-
size: 100,
|
|
327
347
|
uri: "ipfs://..."
|
|
328
348
|
},
|
|
349
|
+
maxVoters: 100, // Required for manual census config
|
|
329
350
|
// ... rest of config
|
|
330
351
|
});
|
|
331
352
|
```
|
|
@@ -406,9 +427,8 @@ const processResult = await sdk.createProcess({
|
|
|
406
427
|
|
|
407
428
|
// Census configuration
|
|
408
429
|
census: {
|
|
409
|
-
type: CensusOrigin.
|
|
430
|
+
type: CensusOrigin.OffchainStatic,
|
|
410
431
|
root: "0x...",
|
|
411
|
-
size: 1000,
|
|
412
432
|
uri: "ipfs://..."
|
|
413
433
|
},
|
|
414
434
|
|
|
@@ -431,8 +451,8 @@ const processResult = await sdk.createProcess({
|
|
|
431
451
|
minValueSum: "0"
|
|
432
452
|
},
|
|
433
453
|
|
|
434
|
-
// Maximum voters (
|
|
435
|
-
maxVoters: 500,
|
|
454
|
+
// Maximum voters (required for manual census config)
|
|
455
|
+
maxVoters: 500,
|
|
436
456
|
|
|
437
457
|
// Questions
|
|
438
458
|
questions: [{
|
|
@@ -662,11 +682,11 @@ async function completeVotingExample() {
|
|
|
662
682
|
title: "Community Budget Allocation",
|
|
663
683
|
description: "Decide how to allocate our community budget",
|
|
664
684
|
census: {
|
|
665
|
-
type: CensusOrigin.
|
|
685
|
+
type: CensusOrigin.OffchainStatic,
|
|
666
686
|
root: publishResult.root,
|
|
667
|
-
size: censusSize,
|
|
668
687
|
uri: publishResult.uri
|
|
669
688
|
},
|
|
689
|
+
maxVoters: censusSize,
|
|
670
690
|
timing: {
|
|
671
691
|
startDate: new Date(Date.now() + 60000), // Start in 1 minute
|
|
672
692
|
duration: 3600 // 1 hour
|
package/dist/contracts.d.ts
CHANGED
|
@@ -224,6 +224,11 @@ declare class ProcessStatusError extends ContractServiceError {
|
|
|
224
224
|
*/
|
|
225
225
|
declare class ProcessCensusError extends ContractServiceError {
|
|
226
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Error thrown when the census origin does not allow to modify the census root or uri.
|
|
229
|
+
*/
|
|
230
|
+
declare class CensusNotUpdatable extends ContractServiceError {
|
|
231
|
+
}
|
|
227
232
|
/**
|
|
228
233
|
* Error thrown when process duration change fails.
|
|
229
234
|
*/
|
|
@@ -302,12 +307,15 @@ type ProcessCensusUpdatedCallback = EntityCallback<[string, string, string]>;
|
|
|
302
307
|
*/
|
|
303
308
|
type ProcessDurationChangedCallback = EntityCallback<[string, bigint]>;
|
|
304
309
|
/**
|
|
305
|
-
* Callback for when a process state
|
|
310
|
+
* Callback for when a process state transitions (valid state transition published).
|
|
306
311
|
* @param processID - The process ID
|
|
307
312
|
* @param sender - Address of the account that updated the state root
|
|
308
|
-
* @param
|
|
313
|
+
* @param oldStateRoot - The state root before the state transition
|
|
314
|
+
* @param newStateRoot - The new state root after the state transition
|
|
315
|
+
* @param newVotersCount - The number of single voters for the process updated after the state transition
|
|
316
|
+
* @param newOverwrittenVotesCount - The number of votes that has been overwritten updated after the state transition
|
|
309
317
|
*/
|
|
310
|
-
type
|
|
318
|
+
type ProcessStateTransitionedCallback = EntityCallback<[string, string, bigint, bigint, bigint, bigint]>;
|
|
311
319
|
/**
|
|
312
320
|
* Callback for when process results are set.
|
|
313
321
|
* @param processID - The process ID
|
|
@@ -359,10 +367,14 @@ declare class OrganizationRegistryService extends SmartContractService {
|
|
|
359
367
|
* Census origin types
|
|
360
368
|
*/
|
|
361
369
|
declare enum CensusOrigin {
|
|
362
|
-
/**
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
|
|
370
|
+
/** Offchain static Merkle Tree census */
|
|
371
|
+
OffchainStatic = 1,
|
|
372
|
+
/** Offchain dynamic Merkle Tree census */
|
|
373
|
+
OffchainDynamic = 2,
|
|
374
|
+
/** Onchain Merkle Tree census */
|
|
375
|
+
Onchain = 3,
|
|
376
|
+
/** Credential Service Provider (CSP) census using EdDSA BLS12-377 */
|
|
377
|
+
CSP = 4
|
|
366
378
|
}
|
|
367
379
|
|
|
368
380
|
interface BallotMode {
|
|
@@ -523,11 +535,11 @@ declare class ProcessRegistryService extends SmartContractService {
|
|
|
523
535
|
onProcessStatusChanged(cb: ProcessStatusChangedCallback): void;
|
|
524
536
|
onCensusUpdated(cb: ProcessCensusUpdatedCallback): void;
|
|
525
537
|
onProcessDurationChanged(cb: ProcessDurationChangedCallback): void;
|
|
526
|
-
|
|
538
|
+
onStateTransitioned(cb: ProcessStateTransitionedCallback): void;
|
|
527
539
|
onProcessResultsSet(cb: ProcessResultsSetCallback): void;
|
|
528
540
|
onProcessMaxVotersChanged(cb: ProcessMaxVotersChangedCallback): void;
|
|
529
541
|
removeAllListeners(): void;
|
|
530
542
|
}
|
|
531
543
|
|
|
532
|
-
export { ContractServiceError, OrganizationAdministratorError, OrganizationCreateError, OrganizationDeleteError, OrganizationRegistryService, OrganizationUpdateError, ProcessCensusError, ProcessCreateError, ProcessDurationError, ProcessRegistryService, ProcessResultError, ProcessStateTransitionError, ProcessStatus, ProcessStatusError, SmartContractService, TxStatus };
|
|
533
|
-
export type { EntityCallback, OrganizationAdministratorAddedCallback, OrganizationAdministratorRemovedCallback, OrganizationCreatedCallback, OrganizationInfo, OrganizationUpdatedCallback, ProcessCensusUpdatedCallback, ProcessCreatedCallback, ProcessDurationChangedCallback, ProcessMaxVotersChangedCallback, ProcessResultsSetCallback,
|
|
544
|
+
export { CensusNotUpdatable, ContractServiceError, OrganizationAdministratorError, OrganizationCreateError, OrganizationDeleteError, OrganizationRegistryService, OrganizationUpdateError, ProcessCensusError, ProcessCreateError, ProcessDurationError, ProcessRegistryService, ProcessResultError, ProcessStateTransitionError, ProcessStatus, ProcessStatusError, SmartContractService, TxStatus };
|
|
545
|
+
export type { EntityCallback, OrganizationAdministratorAddedCallback, OrganizationAdministratorRemovedCallback, OrganizationCreatedCallback, OrganizationInfo, OrganizationUpdatedCallback, ProcessCensusUpdatedCallback, ProcessCreatedCallback, ProcessDurationChangedCallback, ProcessMaxVotersChangedCallback, ProcessResultsSetCallback, ProcessStateTransitionedCallback, ProcessStatusChangedCallback, TxStatusEvent };
|
package/dist/index.d.ts
CHANGED
|
@@ -108,12 +108,16 @@ declare class BaseService {
|
|
|
108
108
|
* Census origin types
|
|
109
109
|
*/
|
|
110
110
|
declare enum CensusOrigin {
|
|
111
|
-
/**
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
111
|
+
/** Offchain static Merkle Tree census */
|
|
112
|
+
OffchainStatic = 1,
|
|
113
|
+
/** Offchain dynamic Merkle Tree census */
|
|
114
|
+
OffchainDynamic = 2,
|
|
115
|
+
/** Onchain Merkle Tree census */
|
|
116
|
+
Onchain = 3,
|
|
117
|
+
/** Credential Service Provider (CSP) census using EdDSA BLS12-377 */
|
|
118
|
+
CSP = 4
|
|
119
|
+
}
|
|
120
|
+
interface CensusParticipant {
|
|
117
121
|
key: string;
|
|
118
122
|
weight?: string;
|
|
119
123
|
}
|
|
@@ -124,18 +128,18 @@ interface BaseCensusProof {
|
|
|
124
128
|
address: string;
|
|
125
129
|
/** The weight as a decimal string. */
|
|
126
130
|
weight: string;
|
|
127
|
-
/** Census origin type:
|
|
131
|
+
/** Census origin type: OffchainStatic/OffchainDynamic/Onchain for merkle proofs, CSP for csp proofs */
|
|
128
132
|
censusOrigin: CensusOrigin;
|
|
129
133
|
}
|
|
130
134
|
interface MerkleCensusProof extends BaseCensusProof {
|
|
131
|
-
censusOrigin: CensusOrigin.
|
|
135
|
+
censusOrigin: CensusOrigin.OffchainStatic | CensusOrigin.OffchainDynamic | CensusOrigin.Onchain;
|
|
132
136
|
/** The leaf value (hex-prefixed weight). */
|
|
133
137
|
value: string;
|
|
134
138
|
/** The serialized sibling path (hex-prefixed). */
|
|
135
139
|
siblings: string;
|
|
136
140
|
}
|
|
137
141
|
interface CSPCensusProof extends BaseCensusProof {
|
|
138
|
-
censusOrigin: CensusOrigin.
|
|
142
|
+
censusOrigin: CensusOrigin.CSP;
|
|
139
143
|
/** The process id signed with the address (hex-prefixed). */
|
|
140
144
|
processId: string;
|
|
141
145
|
/** The public key of the csp (hex-prefixed). */
|
|
@@ -271,8 +275,8 @@ declare class VocdoniCensusService extends BaseService {
|
|
|
271
275
|
*/
|
|
272
276
|
getCensusUri(relativePath: string): string;
|
|
273
277
|
createCensus(): Promise<string>;
|
|
274
|
-
addParticipants(censusId: string, participants: CensusParticipant
|
|
275
|
-
getParticipants(censusId: string): Promise<CensusParticipant
|
|
278
|
+
addParticipants(censusId: string, participants: CensusParticipant[]): Promise<void>;
|
|
279
|
+
getParticipants(censusId: string): Promise<CensusParticipant[]>;
|
|
276
280
|
getCensusRoot(censusId: string): Promise<string>;
|
|
277
281
|
getCensusSizeById(censusId: string): Promise<number>;
|
|
278
282
|
getCensusSizeByRoot(censusRoot: string): Promise<number>;
|
|
@@ -285,21 +289,6 @@ declare class VocdoniCensusService extends BaseService {
|
|
|
285
289
|
getHealth(): Promise<HealthResponse>;
|
|
286
290
|
}
|
|
287
291
|
|
|
288
|
-
/**
|
|
289
|
-
* Census type enumeration
|
|
290
|
-
*/
|
|
291
|
-
declare enum CensusType {
|
|
292
|
-
PLAIN = "plain",
|
|
293
|
-
WEIGHTED = "weighted",
|
|
294
|
-
CSP = "csp"
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Re-export CensusParticipant from types for convenience
|
|
298
|
-
* Extended to make weight required (base type has optional weight)
|
|
299
|
-
*/
|
|
300
|
-
interface CensusParticipant extends CensusParticipant$1 {
|
|
301
|
-
weight: string;
|
|
302
|
-
}
|
|
303
292
|
/**
|
|
304
293
|
* Abstract base class for all census types
|
|
305
294
|
*/
|
|
@@ -307,75 +296,48 @@ declare abstract class Census {
|
|
|
307
296
|
protected _censusId: string | null;
|
|
308
297
|
protected _censusRoot: string | null;
|
|
309
298
|
protected _censusURI: string | null;
|
|
310
|
-
protected
|
|
311
|
-
|
|
312
|
-
constructor(type: CensusType);
|
|
299
|
+
protected _censusOrigin: CensusOrigin;
|
|
300
|
+
constructor(censusOrigin: CensusOrigin);
|
|
313
301
|
get censusId(): string | null;
|
|
314
302
|
get censusRoot(): string | null;
|
|
315
303
|
get censusURI(): string | null;
|
|
316
|
-
get type(): CensusType;
|
|
317
|
-
get size(): number | null;
|
|
318
304
|
get isPublished(): boolean;
|
|
319
305
|
/**
|
|
320
|
-
*
|
|
306
|
+
* Get the census origin (OffchainStatic, OffchainDynamic, Onchain, or CSP)
|
|
321
307
|
*/
|
|
322
308
|
get censusOrigin(): CensusOrigin;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* Plain census where all participants have equal voting power (weight=1)
|
|
327
|
-
* Simpler API - just add addresses without specifying weights
|
|
328
|
-
*/
|
|
329
|
-
declare class PlainCensus extends Census {
|
|
330
|
-
private _participants;
|
|
331
|
-
constructor();
|
|
332
|
-
/**
|
|
333
|
-
* Add participant(s) with automatic weight=1
|
|
334
|
-
* @param addresses - Single address or array of addresses
|
|
335
|
-
*/
|
|
336
|
-
add(addresses: string | string[]): void;
|
|
337
|
-
/**
|
|
338
|
-
* Remove participant by address
|
|
339
|
-
*/
|
|
340
|
-
remove(address: string): void;
|
|
341
|
-
/**
|
|
342
|
-
* Get all participants as CensusParticipant array (for API)
|
|
343
|
-
* All participants have weight="1"
|
|
344
|
-
*/
|
|
345
|
-
get participants(): CensusParticipant[];
|
|
346
309
|
/**
|
|
347
|
-
*
|
|
310
|
+
* Check if this census requires publishing via the Census API
|
|
311
|
+
* Merkle censuses (OffchainStatic, OffchainDynamic) need to be published
|
|
312
|
+
* Onchain and CSP censuses are ready immediately upon construction
|
|
348
313
|
*/
|
|
349
|
-
get
|
|
350
|
-
private validateAddress;
|
|
351
|
-
/**
|
|
352
|
-
* Internal method called after publishing
|
|
353
|
-
* @internal
|
|
354
|
-
*/
|
|
355
|
-
_setPublishedData(root: string, uri: string, size: number, censusId?: string): void;
|
|
314
|
+
get requiresPublishing(): boolean;
|
|
356
315
|
}
|
|
357
316
|
|
|
358
317
|
/**
|
|
359
|
-
* Participant with flexible weight type for
|
|
318
|
+
* Participant with flexible weight type for MerkleCensus
|
|
360
319
|
* Weight can be string, number, or bigint - will be normalized to string internally
|
|
361
320
|
*/
|
|
362
|
-
interface
|
|
321
|
+
interface Participant {
|
|
363
322
|
key: string;
|
|
364
323
|
weight: string | number | bigint;
|
|
365
324
|
}
|
|
366
325
|
/**
|
|
367
|
-
*
|
|
368
|
-
*
|
|
326
|
+
* Abstract base class for Merkle Tree censuses
|
|
327
|
+
* Supports both plain addresses (weight=1) and weighted participants
|
|
369
328
|
*/
|
|
370
|
-
declare class
|
|
329
|
+
declare abstract class MerkleCensus extends Census {
|
|
371
330
|
private _participants;
|
|
372
|
-
constructor();
|
|
331
|
+
constructor(censusOrigin: CensusOrigin);
|
|
373
332
|
/**
|
|
374
|
-
* Add participant(s)
|
|
375
|
-
*
|
|
376
|
-
*
|
|
333
|
+
* Add participant(s) - supports both plain addresses and weighted participants
|
|
334
|
+
* @param data - Can be:
|
|
335
|
+
* - string: single address (weight=1)
|
|
336
|
+
* - string[]: array of addresses (weight=1 for all)
|
|
337
|
+
* - {key: string, weight: string|number|bigint}: single weighted participant
|
|
338
|
+
* - Array of weighted participants
|
|
377
339
|
*/
|
|
378
|
-
add(
|
|
340
|
+
add(data: string | string[] | Participant | Participant[]): void;
|
|
379
341
|
/**
|
|
380
342
|
* Remove participant by address
|
|
381
343
|
*/
|
|
@@ -392,16 +354,58 @@ declare class WeightedCensus extends Census {
|
|
|
392
354
|
* Get weight for specific address
|
|
393
355
|
*/
|
|
394
356
|
getWeight(address: string): string | undefined;
|
|
357
|
+
/**
|
|
358
|
+
* Internal method to add a plain address with a given weight
|
|
359
|
+
*/
|
|
360
|
+
private addAddress;
|
|
361
|
+
/**
|
|
362
|
+
* Internal method to add a weighted participant
|
|
363
|
+
*/
|
|
364
|
+
private addParticipant;
|
|
395
365
|
/**
|
|
396
366
|
* Normalizes weight from string, number, or bigint to string
|
|
397
367
|
*/
|
|
398
368
|
private normalizeWeight;
|
|
399
|
-
|
|
369
|
+
/**
|
|
370
|
+
* Validates Ethereum address format
|
|
371
|
+
*/
|
|
372
|
+
private validateAddress;
|
|
400
373
|
/**
|
|
401
374
|
* Internal method called after publishing
|
|
402
375
|
* @internal
|
|
403
376
|
*/
|
|
404
|
-
_setPublishedData(root: string, uri: string,
|
|
377
|
+
_setPublishedData(root: string, uri: string, censusId?: string): void;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Offchain static Merkle Tree census (most common)
|
|
382
|
+
* Supports both plain addresses (weight=1) and weighted participants
|
|
383
|
+
*/
|
|
384
|
+
declare class OffchainCensus extends MerkleCensus {
|
|
385
|
+
constructor();
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Offchain dynamic Merkle Tree census
|
|
390
|
+
* Supports both plain addresses (weight=1) and weighted participants
|
|
391
|
+
*/
|
|
392
|
+
declare class OffchainDynamicCensus extends MerkleCensus {
|
|
393
|
+
constructor();
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Onchain census that references a smart contract
|
|
398
|
+
* Does not require publishing as it references an existing on-chain contract
|
|
399
|
+
*/
|
|
400
|
+
declare class OnchainCensus extends Census {
|
|
401
|
+
private _contractAddress;
|
|
402
|
+
/**
|
|
403
|
+
* Creates an OnchainCensus
|
|
404
|
+
* @param contractAddress - The address of the smart contract (e.g., ERC20, ERC721)
|
|
405
|
+
* @param uri - Optional URI with census information
|
|
406
|
+
*/
|
|
407
|
+
constructor(contractAddress: string, uri?: string);
|
|
408
|
+
get contractAddress(): string;
|
|
405
409
|
}
|
|
406
410
|
|
|
407
411
|
/**
|
|
@@ -411,17 +415,23 @@ declare class WeightedCensus extends Census {
|
|
|
411
415
|
declare class CspCensus extends Census {
|
|
412
416
|
private _publicKey;
|
|
413
417
|
private _cspURI;
|
|
414
|
-
constructor(publicKey: string, cspURI: string
|
|
418
|
+
constructor(publicKey: string, cspURI: string);
|
|
415
419
|
get publicKey(): string;
|
|
416
420
|
get cspURI(): string;
|
|
417
421
|
}
|
|
418
422
|
|
|
419
423
|
/**
|
|
420
424
|
* Published census - represents a census that has already been published
|
|
421
|
-
* Use this when you have the census root
|
|
425
|
+
* Use this when you have the census root and URI from a previous publication
|
|
422
426
|
*/
|
|
423
427
|
declare class PublishedCensus extends Census {
|
|
424
|
-
|
|
428
|
+
/**
|
|
429
|
+
* Creates a PublishedCensus from existing census data
|
|
430
|
+
* @param censusOrigin - The census origin (OffchainStatic, OffchainDynamic, Onchain, or CSP)
|
|
431
|
+
* @param root - The census root
|
|
432
|
+
* @param uri - The census URI
|
|
433
|
+
*/
|
|
434
|
+
constructor(censusOrigin: CensusOrigin, root: string, uri: string);
|
|
425
435
|
}
|
|
426
436
|
|
|
427
437
|
/**
|
|
@@ -431,19 +441,18 @@ declare class CensusOrchestrator {
|
|
|
431
441
|
private censusService;
|
|
432
442
|
constructor(censusService: VocdoniCensusService);
|
|
433
443
|
/**
|
|
434
|
-
* Publishes a
|
|
444
|
+
* Publishes a MerkleCensus (OffchainCensus, OffchainDynamicCensus, or OnchainCensus)
|
|
435
445
|
* Creates a working census, adds participants, and publishes it
|
|
436
446
|
*/
|
|
437
|
-
publish(census:
|
|
447
|
+
publish(census: MerkleCensus): Promise<void>;
|
|
438
448
|
/**
|
|
439
449
|
* Gets census data for process creation
|
|
440
|
-
* Throws if census is not published
|
|
450
|
+
* Throws if census is not ready (published for Merkle/CSP, or constructed for Onchain)
|
|
441
451
|
*/
|
|
442
452
|
getCensusData(census: Census): {
|
|
443
453
|
type: CensusOrigin;
|
|
444
454
|
root: string;
|
|
445
455
|
uri: string;
|
|
446
|
-
size: number;
|
|
447
456
|
};
|
|
448
457
|
}
|
|
449
458
|
|
|
@@ -496,6 +505,7 @@ interface GetProcessResponse {
|
|
|
496
505
|
ballotMode: BallotMode;
|
|
497
506
|
census: CensusData;
|
|
498
507
|
votersCount: string;
|
|
508
|
+
maxVoters: string;
|
|
499
509
|
overwrittenVotesCount: string;
|
|
500
510
|
isAcceptingVotes: boolean;
|
|
501
511
|
sequencerStats: {
|
|
@@ -857,12 +867,15 @@ type ProcessCensusUpdatedCallback = EntityCallback<[string, string, string]>;
|
|
|
857
867
|
*/
|
|
858
868
|
type ProcessDurationChangedCallback = EntityCallback<[string, bigint]>;
|
|
859
869
|
/**
|
|
860
|
-
* Callback for when a process state
|
|
870
|
+
* Callback for when a process state transitions (valid state transition published).
|
|
861
871
|
* @param processID - The process ID
|
|
862
872
|
* @param sender - Address of the account that updated the state root
|
|
863
|
-
* @param
|
|
873
|
+
* @param oldStateRoot - The state root before the state transition
|
|
874
|
+
* @param newStateRoot - The new state root after the state transition
|
|
875
|
+
* @param newVotersCount - The number of single voters for the process updated after the state transition
|
|
876
|
+
* @param newOverwrittenVotesCount - The number of votes that has been overwritten updated after the state transition
|
|
864
877
|
*/
|
|
865
|
-
type
|
|
878
|
+
type ProcessStateTransitionedCallback = EntityCallback<[string, string, bigint, bigint, bigint, bigint]>;
|
|
866
879
|
/**
|
|
867
880
|
* Callback for when process results are set.
|
|
868
881
|
* @param processID - The process ID
|
|
@@ -951,7 +964,7 @@ declare class ProcessRegistryService extends SmartContractService {
|
|
|
951
964
|
onProcessStatusChanged(cb: ProcessStatusChangedCallback): void;
|
|
952
965
|
onCensusUpdated(cb: ProcessCensusUpdatedCallback): void;
|
|
953
966
|
onProcessDurationChanged(cb: ProcessDurationChangedCallback): void;
|
|
954
|
-
|
|
967
|
+
onStateTransitioned(cb: ProcessStateTransitionedCallback): void;
|
|
955
968
|
onProcessResultsSet(cb: ProcessResultsSetCallback): void;
|
|
956
969
|
onProcessMaxVotersChanged(cb: ProcessMaxVotersChangedCallback): void;
|
|
957
970
|
removeAllListeners(): void;
|
|
@@ -1251,8 +1264,10 @@ interface BaseProcessConfig {
|
|
|
1251
1264
|
endDate?: Date | string | number;
|
|
1252
1265
|
};
|
|
1253
1266
|
/**
|
|
1254
|
-
* Maximum number of voters allowed for this process
|
|
1255
|
-
*
|
|
1267
|
+
* Maximum number of voters allowed for this process
|
|
1268
|
+
* Optional only if census is a published MerkleCensus (OffchainCensus/OffchainDynamicCensus)
|
|
1269
|
+
* - defaults to participant count from the census
|
|
1270
|
+
* Required in all other cases (OnchainCensus, CspCensus, manual config, unpublished census)
|
|
1256
1271
|
*/
|
|
1257
1272
|
maxVoters?: number;
|
|
1258
1273
|
}
|
|
@@ -1877,6 +1892,11 @@ declare class ProcessStatusError extends ContractServiceError {
|
|
|
1877
1892
|
*/
|
|
1878
1893
|
declare class ProcessCensusError extends ContractServiceError {
|
|
1879
1894
|
}
|
|
1895
|
+
/**
|
|
1896
|
+
* Error thrown when the census origin does not allow to modify the census root or uri.
|
|
1897
|
+
*/
|
|
1898
|
+
declare class CensusNotUpdatable extends ContractServiceError {
|
|
1899
|
+
}
|
|
1880
1900
|
/**
|
|
1881
1901
|
* Error thrown when process duration change fails.
|
|
1882
1902
|
*/
|
|
@@ -2064,7 +2084,7 @@ declare class DavinciSDK {
|
|
|
2064
2084
|
* title: "My Election",
|
|
2065
2085
|
* description: "A simple election",
|
|
2066
2086
|
* census: {
|
|
2067
|
-
* type: CensusOrigin.
|
|
2087
|
+
* type: CensusOrigin.OffchainStatic,
|
|
2068
2088
|
* root: "0x1234...",
|
|
2069
2089
|
* size: 100,
|
|
2070
2090
|
* uri: "ipfs://..."
|
|
@@ -2145,7 +2165,7 @@ declare class DavinciSDK {
|
|
|
2145
2165
|
* title: "My Election",
|
|
2146
2166
|
* description: "A simple election",
|
|
2147
2167
|
* census: {
|
|
2148
|
-
* type: CensusOrigin.
|
|
2168
|
+
* type: CensusOrigin.OffchainStatic,
|
|
2149
2169
|
* root: "0x1234...",
|
|
2150
2170
|
* size: 100,
|
|
2151
2171
|
* uri: "ipfs://your-census-uri"
|
|
@@ -2683,5 +2703,5 @@ declare class DavinciSDK {
|
|
|
2683
2703
|
private ensureProvider;
|
|
2684
2704
|
}
|
|
2685
2705
|
|
|
2686
|
-
export { BaseService, Census, CensusOrchestrator, CensusOrigin,
|
|
2687
|
-
export type { AbstainProperties, AnyJson, ApiError, ApprovalProperties, BallotMode, BaseCensusProof, BaseProcess, BudgetProperties, CSPCensusProof, CSPCensusProofProvider, CSPSignOutput, CensusData, CensusParticipant
|
|
2706
|
+
export { BaseService, Census, CensusNotUpdatable, CensusOrchestrator, CensusOrigin, CircomProof, ContractServiceError, CspCensus, DavinciCrypto, DavinciSDK, ElectionMetadataTemplate, ElectionResultsTypeNames, MerkleCensus, OffchainCensus, OffchainDynamicCensus, OnchainCensus, OrganizationAdministratorError, OrganizationCreateError, OrganizationDeleteError, OrganizationRegistryService, OrganizationUpdateError, ProcessCensusError, ProcessCreateError, ProcessDurationError, ProcessOrchestrationService, ProcessRegistryService, ProcessResultError, ProcessStateTransitionError, ProcessStatus, ProcessStatusError, PublishedCensus, SmartContractService, TxStatus, VocdoniApiService, VocdoniCensusService, VocdoniSequencerService, VoteOrchestrationService, VoteStatus, assertCSPCensusProof, assertMerkleCensusProof, createProcessSignatureMessage, getElectionMetadataTemplate, isCSPCensusProof, isMerkleCensusProof, signProcessCreation, validateProcessId };
|
|
2707
|
+
export type { AbstainProperties, AnyJson, ApiError, ApprovalProperties, BallotMode, BaseCensusProof, BaseProcess, BudgetProperties, CSPCensusProof, CSPCensusProofProvider, CSPSignOutput, CensusData, CensusParticipant, CensusProof, CensusProviders, CensusSizeResponse, Choice, ChoiceProperties, CircomProofOptions, CreateProcessRequest, CreateProcessResponse, CustomMeta, DavinciCryptoCiphertext, DavinciCryptoInputs, DavinciCryptoOptions, DavinciCryptoOutput, DavinciSDKConfig, ElectionMetadata, ElectionResultsType, EncryptionKey, EntityCallback, GetProcessResponse, Groth16Proof, HealthResponse, IChoice, IQuestion, InfoResponse, JsonArray, JsonMap, ListProcessesResponse, MerkleCensusProof, MerkleCensusProofProvider, MultiLanguage, OrganizationAdministratorAddedCallback, OrganizationAdministratorRemovedCallback, OrganizationCreatedCallback, OrganizationInfo, OrganizationUpdatedCallback, Participant, ParticipantInfoResponse, ProcessCensusUpdatedCallback, ProcessConfig, ProcessConfigWithMetadata, ProcessConfigWithMetadataUri, ProcessCreatedCallback, ProcessCreationResult, ProcessDurationChangedCallback, ProcessInfo, ProcessMaxVotersChangedCallback, ProcessQuestion, ProcessResultsSetCallback, ProcessStateTransitionedCallback, ProcessStatusChangedCallback, ProofInputs, ProtocolVersion, PublishCensusResponse, QuadraticProperties, Question, SequencerStats, Snapshot, SnapshotsQueryParams, SnapshotsResponse, TxStatusEvent, VocdoniApiServiceConfig, VoteBallot, VoteCiphertext, VoteConfig, VoteOrchestrationConfig, VoteProof, VoteRequest, VoteResult, VoteStatusInfo, VoteStatusResponse, WorkerStats, WorkersResponse };
|