@vocdoni/davinci-sdk 0.0.5 → 0.0.6
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 +48 -0
- package/dist/contracts.d.ts +14 -3
- package/dist/index.d.ts +128 -3
- package/dist/index.js +170 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +170 -1
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +170 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -431,6 +431,9 @@ const processResult = await sdk.createProcess({
|
|
|
431
431
|
minValueSum: "0"
|
|
432
432
|
},
|
|
433
433
|
|
|
434
|
+
// Maximum voters (optional, defaults to census size)
|
|
435
|
+
maxVoters: 500, // Limit the process to 500 voters
|
|
436
|
+
|
|
434
437
|
// Questions
|
|
435
438
|
questions: [{
|
|
436
439
|
title: "What is your preferred option?",
|
|
@@ -500,9 +503,54 @@ console.log('Title:', processInfo.title);
|
|
|
500
503
|
console.log('Status:', processInfo.status);
|
|
501
504
|
console.log('Start date:', processInfo.startDate);
|
|
502
505
|
console.log('End date:', processInfo.endDate);
|
|
506
|
+
console.log('Max voters:', processInfo.maxVoters);
|
|
507
|
+
console.log('Voters count:', processInfo.votersCount);
|
|
503
508
|
console.log('Questions:', processInfo.questions);
|
|
504
509
|
```
|
|
505
510
|
|
|
511
|
+
#### Managing Process MaxVoters
|
|
512
|
+
|
|
513
|
+
You can update the maximum number of voters allowed for a process after creation:
|
|
514
|
+
|
|
515
|
+
```typescript
|
|
516
|
+
// Update maxVoters limit
|
|
517
|
+
await sdk.setProcessMaxVoters(processId, 750);
|
|
518
|
+
|
|
519
|
+
console.log('MaxVoters updated to 750');
|
|
520
|
+
|
|
521
|
+
// Verify the change
|
|
522
|
+
const updatedProcess = await sdk.getProcess(processId);
|
|
523
|
+
console.log('New maxVoters:', updatedProcess.maxVoters);
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
For real-time transaction status updates, use the stream version:
|
|
527
|
+
|
|
528
|
+
```typescript
|
|
529
|
+
import { TxStatus } from '@vocdoni/davinci-sdk';
|
|
530
|
+
|
|
531
|
+
const stream = sdk.setProcessMaxVotersStream(processId, 750);
|
|
532
|
+
|
|
533
|
+
for await (const event of stream) {
|
|
534
|
+
switch (event.status) {
|
|
535
|
+
case TxStatus.Pending:
|
|
536
|
+
console.log("📝 Transaction submitted:", event.hash);
|
|
537
|
+
break;
|
|
538
|
+
|
|
539
|
+
case TxStatus.Completed:
|
|
540
|
+
console.log("✅ MaxVoters updated successfully");
|
|
541
|
+
break;
|
|
542
|
+
|
|
543
|
+
case TxStatus.Failed:
|
|
544
|
+
console.error("❌ Transaction failed:", event.error);
|
|
545
|
+
break;
|
|
546
|
+
|
|
547
|
+
case TxStatus.Reverted:
|
|
548
|
+
console.error("⚠️ Transaction reverted:", event.reason);
|
|
549
|
+
break;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
```
|
|
553
|
+
|
|
506
554
|
### Voting Operations
|
|
507
555
|
|
|
508
556
|
#### Submitting a Vote
|
package/dist/contracts.d.ts
CHANGED
|
@@ -315,6 +315,12 @@ type ProcessStateRootUpdatedCallback = EntityCallback<[string, string, bigint]>;
|
|
|
315
315
|
* @param result - The results array
|
|
316
316
|
*/
|
|
317
317
|
type ProcessResultsSetCallback = EntityCallback<[string, string, bigint[]]>;
|
|
318
|
+
/**
|
|
319
|
+
* Callback for when process maxVoters is changed.
|
|
320
|
+
* @param processID - The process ID
|
|
321
|
+
* @param maxVoters - The new maxVoters value
|
|
322
|
+
*/
|
|
323
|
+
type ProcessMaxVotersChangedCallback = EntityCallback<[string, bigint]>;
|
|
318
324
|
|
|
319
325
|
interface OrganizationInfo {
|
|
320
326
|
name: string;
|
|
@@ -463,13 +469,14 @@ declare class ProcessRegistryService extends SmartContractService {
|
|
|
463
469
|
getMaxCensusOrigin(): Promise<bigint>;
|
|
464
470
|
getMaxStatus(): Promise<bigint>;
|
|
465
471
|
getProcessNonce(address: string): Promise<bigint>;
|
|
466
|
-
getProcessDirect(processID: string): Promise<[bigint, string, _vocdoni_davinci_contracts_dist_src_ProcessRegistry.IProcessRegistry.EncryptionKeyStructOutput, bigint, bigint, bigint, bigint, bigint, bigint, bigint, string, _vocdoni_davinci_contracts_dist_src_ProcessRegistry.IProcessRegistry.BallotModeStructOutput, _vocdoni_davinci_contracts_dist_src_ProcessRegistry.IProcessRegistry.CensusStructOutput] & {
|
|
472
|
+
getProcessDirect(processID: string): Promise<[bigint, string, _vocdoni_davinci_contracts_dist_src_ProcessRegistry.IProcessRegistry.EncryptionKeyStructOutput, bigint, bigint, bigint, bigint, bigint, bigint, bigint, bigint, string, _vocdoni_davinci_contracts_dist_src_ProcessRegistry.IProcessRegistry.BallotModeStructOutput, _vocdoni_davinci_contracts_dist_src_ProcessRegistry.IProcessRegistry.CensusStructOutput] & {
|
|
467
473
|
status: bigint;
|
|
468
474
|
organizationId: string;
|
|
469
475
|
encryptionKey: _vocdoni_davinci_contracts_dist_src_ProcessRegistry.IProcessRegistry.EncryptionKeyStructOutput;
|
|
470
476
|
latestStateRoot: bigint;
|
|
471
477
|
startTime: bigint;
|
|
472
478
|
duration: bigint;
|
|
479
|
+
maxVoters: bigint;
|
|
473
480
|
votersCount: bigint;
|
|
474
481
|
overwrittenVotesCount: bigint;
|
|
475
482
|
creationBlock: bigint;
|
|
@@ -480,7 +487,7 @@ declare class ProcessRegistryService extends SmartContractService {
|
|
|
480
487
|
}>;
|
|
481
488
|
getRVerifier(): Promise<string>;
|
|
482
489
|
getSTVerifier(): Promise<string>;
|
|
483
|
-
newProcess(status: ProcessStatus, startTime: number, duration: number, ballotMode: BallotMode, census: CensusData, metadata: string, encryptionKey: EncryptionKey, initStateRoot: bigint): AsyncGenerator<TxStatusEvent<{
|
|
490
|
+
newProcess(status: ProcessStatus, startTime: number, duration: number, maxVoters: number, ballotMode: BallotMode, census: CensusData, metadata: string, encryptionKey: EncryptionKey, initStateRoot: bigint): AsyncGenerator<TxStatusEvent<{
|
|
484
491
|
success: boolean;
|
|
485
492
|
}>, void, unknown>;
|
|
486
493
|
setProcessStatus(processID: string, newStatus: ProcessStatus): AsyncGenerator<TxStatusEvent<{
|
|
@@ -492,6 +499,9 @@ declare class ProcessRegistryService extends SmartContractService {
|
|
|
492
499
|
setProcessDuration(processID: string, duration: number): AsyncGenerator<TxStatusEvent<{
|
|
493
500
|
success: boolean;
|
|
494
501
|
}>, void, unknown>;
|
|
502
|
+
setProcessMaxVoters(processID: string, maxVoters: number): AsyncGenerator<TxStatusEvent<{
|
|
503
|
+
success: boolean;
|
|
504
|
+
}>, void, unknown>;
|
|
495
505
|
/**
|
|
496
506
|
* Matches the on-chain `submitStateTransition(processId, proof, input)`
|
|
497
507
|
*/
|
|
@@ -515,8 +525,9 @@ declare class ProcessRegistryService extends SmartContractService {
|
|
|
515
525
|
onProcessDurationChanged(cb: ProcessDurationChangedCallback): void;
|
|
516
526
|
onStateRootUpdated(cb: ProcessStateRootUpdatedCallback): void;
|
|
517
527
|
onProcessResultsSet(cb: ProcessResultsSetCallback): void;
|
|
528
|
+
onProcessMaxVotersChanged(cb: ProcessMaxVotersChangedCallback): void;
|
|
518
529
|
removeAllListeners(): void;
|
|
519
530
|
}
|
|
520
531
|
|
|
521
532
|
export { ContractServiceError, OrganizationAdministratorError, OrganizationCreateError, OrganizationDeleteError, OrganizationRegistryService, OrganizationUpdateError, ProcessCensusError, ProcessCreateError, ProcessDurationError, ProcessRegistryService, ProcessResultError, ProcessStateTransitionError, ProcessStatus, ProcessStatusError, SmartContractService, TxStatus };
|
|
522
|
-
export type { EntityCallback, OrganizationAdministratorAddedCallback, OrganizationAdministratorRemovedCallback, OrganizationCreatedCallback, OrganizationInfo, OrganizationUpdatedCallback, ProcessCensusUpdatedCallback, ProcessCreatedCallback, ProcessDurationChangedCallback, ProcessResultsSetCallback, ProcessStateRootUpdatedCallback, ProcessStatusChangedCallback, TxStatusEvent };
|
|
533
|
+
export type { EntityCallback, OrganizationAdministratorAddedCallback, OrganizationAdministratorRemovedCallback, OrganizationCreatedCallback, OrganizationInfo, OrganizationUpdatedCallback, ProcessCensusUpdatedCallback, ProcessCreatedCallback, ProcessDurationChangedCallback, ProcessMaxVotersChangedCallback, ProcessResultsSetCallback, ProcessStateRootUpdatedCallback, ProcessStatusChangedCallback, TxStatusEvent };
|
package/dist/index.d.ts
CHANGED
|
@@ -870,6 +870,12 @@ type ProcessStateRootUpdatedCallback = EntityCallback<[string, string, bigint]>;
|
|
|
870
870
|
* @param result - The results array
|
|
871
871
|
*/
|
|
872
872
|
type ProcessResultsSetCallback = EntityCallback<[string, string, bigint[]]>;
|
|
873
|
+
/**
|
|
874
|
+
* Callback for when process maxVoters is changed.
|
|
875
|
+
* @param processID - The process ID
|
|
876
|
+
* @param maxVoters - The new maxVoters value
|
|
877
|
+
*/
|
|
878
|
+
type ProcessMaxVotersChangedCallback = EntityCallback<[string, bigint]>;
|
|
873
879
|
|
|
874
880
|
declare enum ProcessStatus {
|
|
875
881
|
READY = 0,
|
|
@@ -891,13 +897,14 @@ declare class ProcessRegistryService extends SmartContractService {
|
|
|
891
897
|
getMaxCensusOrigin(): Promise<bigint>;
|
|
892
898
|
getMaxStatus(): Promise<bigint>;
|
|
893
899
|
getProcessNonce(address: string): Promise<bigint>;
|
|
894
|
-
getProcessDirect(processID: string): Promise<[bigint, string, _vocdoni_davinci_contracts_dist_src_ProcessRegistry.IProcessRegistry.EncryptionKeyStructOutput, bigint, bigint, bigint, bigint, bigint, bigint, bigint, string, _vocdoni_davinci_contracts_dist_src_ProcessRegistry.IProcessRegistry.BallotModeStructOutput, _vocdoni_davinci_contracts_dist_src_ProcessRegistry.IProcessRegistry.CensusStructOutput] & {
|
|
900
|
+
getProcessDirect(processID: string): Promise<[bigint, string, _vocdoni_davinci_contracts_dist_src_ProcessRegistry.IProcessRegistry.EncryptionKeyStructOutput, bigint, bigint, bigint, bigint, bigint, bigint, bigint, bigint, string, _vocdoni_davinci_contracts_dist_src_ProcessRegistry.IProcessRegistry.BallotModeStructOutput, _vocdoni_davinci_contracts_dist_src_ProcessRegistry.IProcessRegistry.CensusStructOutput] & {
|
|
895
901
|
status: bigint;
|
|
896
902
|
organizationId: string;
|
|
897
903
|
encryptionKey: _vocdoni_davinci_contracts_dist_src_ProcessRegistry.IProcessRegistry.EncryptionKeyStructOutput;
|
|
898
904
|
latestStateRoot: bigint;
|
|
899
905
|
startTime: bigint;
|
|
900
906
|
duration: bigint;
|
|
907
|
+
maxVoters: bigint;
|
|
901
908
|
votersCount: bigint;
|
|
902
909
|
overwrittenVotesCount: bigint;
|
|
903
910
|
creationBlock: bigint;
|
|
@@ -908,7 +915,7 @@ declare class ProcessRegistryService extends SmartContractService {
|
|
|
908
915
|
}>;
|
|
909
916
|
getRVerifier(): Promise<string>;
|
|
910
917
|
getSTVerifier(): Promise<string>;
|
|
911
|
-
newProcess(status: ProcessStatus, startTime: number, duration: number, ballotMode: BallotMode, census: CensusData, metadata: string, encryptionKey: EncryptionKey, initStateRoot: bigint): AsyncGenerator<TxStatusEvent<{
|
|
918
|
+
newProcess(status: ProcessStatus, startTime: number, duration: number, maxVoters: number, ballotMode: BallotMode, census: CensusData, metadata: string, encryptionKey: EncryptionKey, initStateRoot: bigint): AsyncGenerator<TxStatusEvent<{
|
|
912
919
|
success: boolean;
|
|
913
920
|
}>, void, unknown>;
|
|
914
921
|
setProcessStatus(processID: string, newStatus: ProcessStatus): AsyncGenerator<TxStatusEvent<{
|
|
@@ -920,6 +927,9 @@ declare class ProcessRegistryService extends SmartContractService {
|
|
|
920
927
|
setProcessDuration(processID: string, duration: number): AsyncGenerator<TxStatusEvent<{
|
|
921
928
|
success: boolean;
|
|
922
929
|
}>, void, unknown>;
|
|
930
|
+
setProcessMaxVoters(processID: string, maxVoters: number): AsyncGenerator<TxStatusEvent<{
|
|
931
|
+
success: boolean;
|
|
932
|
+
}>, void, unknown>;
|
|
923
933
|
/**
|
|
924
934
|
* Matches the on-chain `submitStateTransition(processId, proof, input)`
|
|
925
935
|
*/
|
|
@@ -943,6 +953,7 @@ declare class ProcessRegistryService extends SmartContractService {
|
|
|
943
953
|
onProcessDurationChanged(cb: ProcessDurationChangedCallback): void;
|
|
944
954
|
onStateRootUpdated(cb: ProcessStateRootUpdatedCallback): void;
|
|
945
955
|
onProcessResultsSet(cb: ProcessResultsSetCallback): void;
|
|
956
|
+
onProcessMaxVotersChanged(cb: ProcessMaxVotersChangedCallback): void;
|
|
946
957
|
removeAllListeners(): void;
|
|
947
958
|
}
|
|
948
959
|
|
|
@@ -1239,6 +1250,11 @@ interface BaseProcessConfig {
|
|
|
1239
1250
|
/** End date/time (Date object, ISO string, or Unix timestamp, cannot be used with duration) */
|
|
1240
1251
|
endDate?: Date | string | number;
|
|
1241
1252
|
};
|
|
1253
|
+
/**
|
|
1254
|
+
* Maximum number of voters allowed for this process (optional, defaults to census size)
|
|
1255
|
+
* This parameter limits how many votes can be cast in the process.
|
|
1256
|
+
*/
|
|
1257
|
+
maxVoters?: number;
|
|
1242
1258
|
}
|
|
1243
1259
|
/**
|
|
1244
1260
|
* Process configuration with metadata fields (title, description, questions)
|
|
@@ -1292,6 +1308,8 @@ interface ProcessInfo extends BaseProcess {
|
|
|
1292
1308
|
duration: number;
|
|
1293
1309
|
/** Time remaining in seconds (0 if ended, negative if not started) */
|
|
1294
1310
|
timeRemaining: number;
|
|
1311
|
+
/** Maximum number of voters allowed */
|
|
1312
|
+
maxVoters: number;
|
|
1295
1313
|
/** Process results (array of BigInt values) */
|
|
1296
1314
|
result: bigint[];
|
|
1297
1315
|
/** Number of votes cast */
|
|
@@ -1592,6 +1610,56 @@ declare class ProcessOrchestrationService {
|
|
|
1592
1610
|
* ```
|
|
1593
1611
|
*/
|
|
1594
1612
|
resumeProcess(processId: string): Promise<void>;
|
|
1613
|
+
/**
|
|
1614
|
+
* Sets the maximum number of voters for a process.
|
|
1615
|
+
* Returns an async generator that yields transaction status events.
|
|
1616
|
+
*
|
|
1617
|
+
* @param processId - The process ID
|
|
1618
|
+
* @param maxVoters - The new maximum number of voters
|
|
1619
|
+
* @returns AsyncGenerator yielding transaction status events
|
|
1620
|
+
*
|
|
1621
|
+
* @example
|
|
1622
|
+
* ```typescript
|
|
1623
|
+
* const stream = sdk.setProcessMaxVotersStream("0x1234567890abcdef...", 500);
|
|
1624
|
+
*
|
|
1625
|
+
* for await (const event of stream) {
|
|
1626
|
+
* switch (event.status) {
|
|
1627
|
+
* case "pending":
|
|
1628
|
+
* console.log("Transaction pending:", event.hash);
|
|
1629
|
+
* break;
|
|
1630
|
+
* case "completed":
|
|
1631
|
+
* console.log("MaxVoters updated successfully");
|
|
1632
|
+
* break;
|
|
1633
|
+
* case "failed":
|
|
1634
|
+
* console.error("Transaction failed:", event.error);
|
|
1635
|
+
* break;
|
|
1636
|
+
* case "reverted":
|
|
1637
|
+
* console.error("Transaction reverted:", event.reason);
|
|
1638
|
+
* break;
|
|
1639
|
+
* }
|
|
1640
|
+
* }
|
|
1641
|
+
* ```
|
|
1642
|
+
*/
|
|
1643
|
+
setProcessMaxVotersStream(processId: string, maxVoters: number): AsyncGenerator<TxStatusEvent<{
|
|
1644
|
+
success: boolean;
|
|
1645
|
+
}>>;
|
|
1646
|
+
/**
|
|
1647
|
+
* Sets the maximum number of voters for a process.
|
|
1648
|
+
* This is a simplified method that waits for transaction completion.
|
|
1649
|
+
*
|
|
1650
|
+
* For real-time transaction status updates, use setProcessMaxVotersStream() instead.
|
|
1651
|
+
*
|
|
1652
|
+
* @param processId - The process ID
|
|
1653
|
+
* @param maxVoters - The new maximum number of voters
|
|
1654
|
+
* @returns Promise resolving when the maxVoters is updated
|
|
1655
|
+
*
|
|
1656
|
+
* @example
|
|
1657
|
+
* ```typescript
|
|
1658
|
+
* await sdk.setProcessMaxVoters("0x1234567890abcdef...", 500);
|
|
1659
|
+
* console.log("MaxVoters updated successfully");
|
|
1660
|
+
* ```
|
|
1661
|
+
*/
|
|
1662
|
+
setProcessMaxVoters(processId: string, maxVoters: number): Promise<void>;
|
|
1595
1663
|
}
|
|
1596
1664
|
|
|
1597
1665
|
/**
|
|
@@ -2531,6 +2599,63 @@ declare class DavinciSDK {
|
|
|
2531
2599
|
* ```
|
|
2532
2600
|
*/
|
|
2533
2601
|
resumeProcess(processId: string): Promise<void>;
|
|
2602
|
+
/**
|
|
2603
|
+
* Sets the maximum number of voters for a process and returns an async generator
|
|
2604
|
+
* that yields transaction status events. This allows you to change the voter limit
|
|
2605
|
+
* after process creation.
|
|
2606
|
+
*
|
|
2607
|
+
* Requires a signer with a provider for blockchain interactions.
|
|
2608
|
+
*
|
|
2609
|
+
* @param processId - The process ID
|
|
2610
|
+
* @param maxVoters - The new maximum number of voters
|
|
2611
|
+
* @returns AsyncGenerator yielding transaction status events
|
|
2612
|
+
* @throws Error if signer does not have a provider
|
|
2613
|
+
*
|
|
2614
|
+
* @example
|
|
2615
|
+
* ```typescript
|
|
2616
|
+
* const stream = sdk.setProcessMaxVotersStream("0x1234567890abcdef...", 500);
|
|
2617
|
+
*
|
|
2618
|
+
* for await (const event of stream) {
|
|
2619
|
+
* switch (event.status) {
|
|
2620
|
+
* case TxStatus.Pending:
|
|
2621
|
+
* console.log("Transaction pending:", event.hash);
|
|
2622
|
+
* break;
|
|
2623
|
+
* case TxStatus.Completed:
|
|
2624
|
+
* console.log("MaxVoters updated successfully");
|
|
2625
|
+
* break;
|
|
2626
|
+
* case TxStatus.Failed:
|
|
2627
|
+
* console.error("Transaction failed:", event.error);
|
|
2628
|
+
* break;
|
|
2629
|
+
* case TxStatus.Reverted:
|
|
2630
|
+
* console.error("Transaction reverted:", event.reason);
|
|
2631
|
+
* break;
|
|
2632
|
+
* }
|
|
2633
|
+
* }
|
|
2634
|
+
* ```
|
|
2635
|
+
*/
|
|
2636
|
+
setProcessMaxVotersStream(processId: string, maxVoters: number): AsyncGenerator<TxStatusEvent<{
|
|
2637
|
+
success: boolean;
|
|
2638
|
+
}>, any, any>;
|
|
2639
|
+
/**
|
|
2640
|
+
* Sets the maximum number of voters for a process.
|
|
2641
|
+
* This is the simplified method that waits for transaction completion.
|
|
2642
|
+
*
|
|
2643
|
+
* For real-time transaction status updates, use setProcessMaxVotersStream() instead.
|
|
2644
|
+
*
|
|
2645
|
+
* Requires a signer with a provider for blockchain interactions.
|
|
2646
|
+
*
|
|
2647
|
+
* @param processId - The process ID
|
|
2648
|
+
* @param maxVoters - The new maximum number of voters
|
|
2649
|
+
* @returns Promise resolving when the maxVoters is updated
|
|
2650
|
+
* @throws Error if signer does not have a provider
|
|
2651
|
+
*
|
|
2652
|
+
* @example
|
|
2653
|
+
* ```typescript
|
|
2654
|
+
* await sdk.setProcessMaxVoters("0x1234567890abcdef...", 500);
|
|
2655
|
+
* console.log("MaxVoters updated successfully");
|
|
2656
|
+
* ```
|
|
2657
|
+
*/
|
|
2658
|
+
setProcessMaxVoters(processId: string, maxVoters: number): Promise<void>;
|
|
2534
2659
|
/**
|
|
2535
2660
|
* Resolve contract address based on configuration priority:
|
|
2536
2661
|
* 1. Custom addresses from user config (if provided)
|
|
@@ -2559,4 +2684,4 @@ declare class DavinciSDK {
|
|
|
2559
2684
|
}
|
|
2560
2685
|
|
|
2561
2686
|
export { BaseService, Census, CensusOrchestrator, CensusOrigin, CensusType, CircomProof, ContractServiceError, CspCensus, DavinciCrypto, DavinciSDK, ElectionMetadataTemplate, ElectionResultsTypeNames, OrganizationAdministratorError, OrganizationCreateError, OrganizationDeleteError, OrganizationRegistryService, OrganizationUpdateError, PlainCensus, ProcessCensusError, ProcessCreateError, ProcessDurationError, ProcessOrchestrationService, ProcessRegistryService, ProcessResultError, ProcessStateTransitionError, ProcessStatus, ProcessStatusError, PublishedCensus, SmartContractService, TxStatus, VocdoniApiService, VocdoniCensusService, VocdoniSequencerService, VoteOrchestrationService, VoteStatus, WeightedCensus, assertCSPCensusProof, assertMerkleCensusProof, createProcessSignatureMessage, getElectionMetadataTemplate, isCSPCensusProof, isMerkleCensusProof, signProcessCreation, validateProcessId };
|
|
2562
|
-
export type { AbstainProperties, AnyJson, ApiError, ApprovalProperties, BallotMode, BaseCensusProof, BaseProcess, BudgetProperties, CSPCensusProof, CSPCensusProofProvider, CSPSignOutput, CensusData, CensusParticipant$1 as 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, ParticipantInfoResponse, ProcessCensusUpdatedCallback, ProcessConfig, ProcessConfigWithMetadata, ProcessConfigWithMetadataUri, ProcessCreatedCallback, ProcessCreationResult, ProcessDurationChangedCallback, ProcessInfo, ProcessQuestion, ProcessResultsSetCallback, ProcessStateRootUpdatedCallback, ProcessStatusChangedCallback, ProofInputs, ProtocolVersion, PublishCensusResponse, QuadraticProperties, Question, SequencerStats, Snapshot, SnapshotsQueryParams, SnapshotsResponse, TxStatusEvent, VocdoniApiServiceConfig, VoteBallot, VoteCiphertext, VoteConfig, VoteOrchestrationConfig, VoteProof, VoteRequest, VoteResult, VoteStatusInfo, VoteStatusResponse, WeightedParticipant, WorkerStats, WorkersResponse };
|
|
2687
|
+
export type { AbstainProperties, AnyJson, ApiError, ApprovalProperties, BallotMode, BaseCensusProof, BaseProcess, BudgetProperties, CSPCensusProof, CSPCensusProofProvider, CSPSignOutput, CensusData, CensusParticipant$1 as 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, ParticipantInfoResponse, ProcessCensusUpdatedCallback, ProcessConfig, ProcessConfigWithMetadata, ProcessConfigWithMetadataUri, ProcessCreatedCallback, ProcessCreationResult, ProcessDurationChangedCallback, ProcessInfo, ProcessMaxVotersChangedCallback, ProcessQuestion, ProcessResultsSetCallback, ProcessStateRootUpdatedCallback, ProcessStatusChangedCallback, ProofInputs, ProtocolVersion, PublishCensusResponse, QuadraticProperties, Question, SequencerStats, Snapshot, SnapshotsQueryParams, SnapshotsResponse, TxStatusEvent, VocdoniApiServiceConfig, VoteBallot, VoteCiphertext, VoteConfig, VoteOrchestrationConfig, VoteProof, VoteRequest, VoteResult, VoteStatusInfo, VoteStatusResponse, WeightedParticipant, WorkerStats, WorkersResponse };
|
package/dist/index.js
CHANGED
|
@@ -1006,7 +1006,7 @@ class ProcessRegistryService extends SmartContractService {
|
|
|
1006
1006
|
return this.contract.stVerifier();
|
|
1007
1007
|
}
|
|
1008
1008
|
// ─── WRITES ────────────────────────────────────────────────────────
|
|
1009
|
-
newProcess(status, startTime, duration, ballotMode, census, metadata, encryptionKey, initStateRoot) {
|
|
1009
|
+
newProcess(status, startTime, duration, maxVoters, ballotMode, census, metadata, encryptionKey, initStateRoot) {
|
|
1010
1010
|
const contractCensus = {
|
|
1011
1011
|
censusOrigin: BigInt(census.censusOrigin),
|
|
1012
1012
|
censusRoot: census.censusRoot,
|
|
@@ -1017,6 +1017,7 @@ class ProcessRegistryService extends SmartContractService {
|
|
|
1017
1017
|
status,
|
|
1018
1018
|
startTime,
|
|
1019
1019
|
duration,
|
|
1020
|
+
maxVoters,
|
|
1020
1021
|
ballotMode,
|
|
1021
1022
|
contractCensus,
|
|
1022
1023
|
metadata,
|
|
@@ -1057,6 +1058,14 @@ class ProcessRegistryService extends SmartContractService {
|
|
|
1057
1058
|
async () => ({ success: true })
|
|
1058
1059
|
);
|
|
1059
1060
|
}
|
|
1061
|
+
setProcessMaxVoters(processID, maxVoters) {
|
|
1062
|
+
return this.sendTx(
|
|
1063
|
+
this.contract.setProcessMaxVoters(processID, maxVoters).catch((e) => {
|
|
1064
|
+
throw new ProcessDurationError(e.message, "setMaxVoters");
|
|
1065
|
+
}),
|
|
1066
|
+
async () => ({ success: true })
|
|
1067
|
+
);
|
|
1068
|
+
}
|
|
1060
1069
|
/**
|
|
1061
1070
|
* Matches the on-chain `submitStateTransition(processId, proof, input)`
|
|
1062
1071
|
*/
|
|
@@ -1127,6 +1136,13 @@ class ProcessRegistryService extends SmartContractService {
|
|
|
1127
1136
|
cb
|
|
1128
1137
|
).catch((err) => console.error("Error setting up ProcessResultsSet listener:", err));
|
|
1129
1138
|
}
|
|
1139
|
+
onProcessMaxVotersChanged(cb) {
|
|
1140
|
+
this.setupEventListener(
|
|
1141
|
+
this.contract,
|
|
1142
|
+
this.contract.filters.ProcessMaxVotersChanged(),
|
|
1143
|
+
cb
|
|
1144
|
+
).catch((err) => console.error("Error setting up ProcessMaxVotersChanged listener:", err));
|
|
1145
|
+
}
|
|
1130
1146
|
removeAllListeners() {
|
|
1131
1147
|
this.contract.removeAllListeners();
|
|
1132
1148
|
this.clearPollingIntervals();
|
|
@@ -1232,6 +1248,7 @@ class ProcessOrchestrationService {
|
|
|
1232
1248
|
endDate: new Date(endTime * 1e3),
|
|
1233
1249
|
duration,
|
|
1234
1250
|
timeRemaining,
|
|
1251
|
+
maxVoters: Number(rawProcess.maxVoters),
|
|
1235
1252
|
result: rawProcess.result,
|
|
1236
1253
|
votersCount: Number(rawProcess.votersCount),
|
|
1237
1254
|
overwrittenVotesCount: Number(rawProcess.overwrittenVotesCount),
|
|
@@ -1286,6 +1303,7 @@ class ProcessOrchestrationService {
|
|
|
1286
1303
|
ProcessStatus.READY,
|
|
1287
1304
|
data.startTime,
|
|
1288
1305
|
data.duration,
|
|
1306
|
+
data.maxVoters,
|
|
1289
1307
|
data.ballotMode,
|
|
1290
1308
|
data.census,
|
|
1291
1309
|
data.metadataUri,
|
|
@@ -1373,6 +1391,7 @@ class ProcessOrchestrationService {
|
|
|
1373
1391
|
ballotMode,
|
|
1374
1392
|
signature
|
|
1375
1393
|
});
|
|
1394
|
+
const maxVoters = config.maxVoters ?? censusConfig.size;
|
|
1376
1395
|
const census = {
|
|
1377
1396
|
censusOrigin: censusConfig.type,
|
|
1378
1397
|
censusRoot,
|
|
@@ -1382,6 +1401,7 @@ class ProcessOrchestrationService {
|
|
|
1382
1401
|
processId,
|
|
1383
1402
|
startTime,
|
|
1384
1403
|
duration,
|
|
1404
|
+
maxVoters,
|
|
1385
1405
|
censusRoot,
|
|
1386
1406
|
ballotMode,
|
|
1387
1407
|
metadataUri,
|
|
@@ -1768,6 +1788,84 @@ class ProcessOrchestrationService {
|
|
|
1768
1788
|
}
|
|
1769
1789
|
throw new Error("Resume process stream ended unexpectedly");
|
|
1770
1790
|
}
|
|
1791
|
+
/**
|
|
1792
|
+
* Sets the maximum number of voters for a process.
|
|
1793
|
+
* Returns an async generator that yields transaction status events.
|
|
1794
|
+
*
|
|
1795
|
+
* @param processId - The process ID
|
|
1796
|
+
* @param maxVoters - The new maximum number of voters
|
|
1797
|
+
* @returns AsyncGenerator yielding transaction status events
|
|
1798
|
+
*
|
|
1799
|
+
* @example
|
|
1800
|
+
* ```typescript
|
|
1801
|
+
* const stream = sdk.setProcessMaxVotersStream("0x1234567890abcdef...", 500);
|
|
1802
|
+
*
|
|
1803
|
+
* for await (const event of stream) {
|
|
1804
|
+
* switch (event.status) {
|
|
1805
|
+
* case "pending":
|
|
1806
|
+
* console.log("Transaction pending:", event.hash);
|
|
1807
|
+
* break;
|
|
1808
|
+
* case "completed":
|
|
1809
|
+
* console.log("MaxVoters updated successfully");
|
|
1810
|
+
* break;
|
|
1811
|
+
* case "failed":
|
|
1812
|
+
* console.error("Transaction failed:", event.error);
|
|
1813
|
+
* break;
|
|
1814
|
+
* case "reverted":
|
|
1815
|
+
* console.error("Transaction reverted:", event.reason);
|
|
1816
|
+
* break;
|
|
1817
|
+
* }
|
|
1818
|
+
* }
|
|
1819
|
+
* ```
|
|
1820
|
+
*/
|
|
1821
|
+
async *setProcessMaxVotersStream(processId, maxVoters) {
|
|
1822
|
+
const txStream = this.processRegistry.setProcessMaxVoters(processId, maxVoters);
|
|
1823
|
+
for await (const event of txStream) {
|
|
1824
|
+
if (event.status === TxStatus.Pending) {
|
|
1825
|
+
yield { status: TxStatus.Pending, hash: event.hash };
|
|
1826
|
+
} else if (event.status === TxStatus.Completed) {
|
|
1827
|
+
yield {
|
|
1828
|
+
status: TxStatus.Completed,
|
|
1829
|
+
response: { success: true }
|
|
1830
|
+
};
|
|
1831
|
+
break;
|
|
1832
|
+
} else if (event.status === TxStatus.Failed) {
|
|
1833
|
+
yield { status: TxStatus.Failed, error: event.error };
|
|
1834
|
+
break;
|
|
1835
|
+
} else if (event.status === TxStatus.Reverted) {
|
|
1836
|
+
yield { status: TxStatus.Reverted, reason: event.reason };
|
|
1837
|
+
break;
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
/**
|
|
1842
|
+
* Sets the maximum number of voters for a process.
|
|
1843
|
+
* This is a simplified method that waits for transaction completion.
|
|
1844
|
+
*
|
|
1845
|
+
* For real-time transaction status updates, use setProcessMaxVotersStream() instead.
|
|
1846
|
+
*
|
|
1847
|
+
* @param processId - The process ID
|
|
1848
|
+
* @param maxVoters - The new maximum number of voters
|
|
1849
|
+
* @returns Promise resolving when the maxVoters is updated
|
|
1850
|
+
*
|
|
1851
|
+
* @example
|
|
1852
|
+
* ```typescript
|
|
1853
|
+
* await sdk.setProcessMaxVoters("0x1234567890abcdef...", 500);
|
|
1854
|
+
* console.log("MaxVoters updated successfully");
|
|
1855
|
+
* ```
|
|
1856
|
+
*/
|
|
1857
|
+
async setProcessMaxVoters(processId, maxVoters) {
|
|
1858
|
+
for await (const event of this.setProcessMaxVotersStream(processId, maxVoters)) {
|
|
1859
|
+
if (event.status === "completed") {
|
|
1860
|
+
return;
|
|
1861
|
+
} else if (event.status === "failed") {
|
|
1862
|
+
throw event.error;
|
|
1863
|
+
} else if (event.status === "reverted") {
|
|
1864
|
+
throw new Error(`Transaction reverted: ${event.reason || "unknown reason"}`);
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
throw new Error("Set process maxVoters stream ended unexpectedly");
|
|
1868
|
+
}
|
|
1771
1869
|
}
|
|
1772
1870
|
|
|
1773
1871
|
class CircomProof {
|
|
@@ -3272,6 +3370,77 @@ class DavinciSDK {
|
|
|
3272
3370
|
this.ensureProvider();
|
|
3273
3371
|
return this.processOrchestrator.resumeProcess(processId);
|
|
3274
3372
|
}
|
|
3373
|
+
/**
|
|
3374
|
+
* Sets the maximum number of voters for a process and returns an async generator
|
|
3375
|
+
* that yields transaction status events. This allows you to change the voter limit
|
|
3376
|
+
* after process creation.
|
|
3377
|
+
*
|
|
3378
|
+
* Requires a signer with a provider for blockchain interactions.
|
|
3379
|
+
*
|
|
3380
|
+
* @param processId - The process ID
|
|
3381
|
+
* @param maxVoters - The new maximum number of voters
|
|
3382
|
+
* @returns AsyncGenerator yielding transaction status events
|
|
3383
|
+
* @throws Error if signer does not have a provider
|
|
3384
|
+
*
|
|
3385
|
+
* @example
|
|
3386
|
+
* ```typescript
|
|
3387
|
+
* const stream = sdk.setProcessMaxVotersStream("0x1234567890abcdef...", 500);
|
|
3388
|
+
*
|
|
3389
|
+
* for await (const event of stream) {
|
|
3390
|
+
* switch (event.status) {
|
|
3391
|
+
* case TxStatus.Pending:
|
|
3392
|
+
* console.log("Transaction pending:", event.hash);
|
|
3393
|
+
* break;
|
|
3394
|
+
* case TxStatus.Completed:
|
|
3395
|
+
* console.log("MaxVoters updated successfully");
|
|
3396
|
+
* break;
|
|
3397
|
+
* case TxStatus.Failed:
|
|
3398
|
+
* console.error("Transaction failed:", event.error);
|
|
3399
|
+
* break;
|
|
3400
|
+
* case TxStatus.Reverted:
|
|
3401
|
+
* console.error("Transaction reverted:", event.reason);
|
|
3402
|
+
* break;
|
|
3403
|
+
* }
|
|
3404
|
+
* }
|
|
3405
|
+
* ```
|
|
3406
|
+
*/
|
|
3407
|
+
setProcessMaxVotersStream(processId, maxVoters) {
|
|
3408
|
+
if (!this.initialized) {
|
|
3409
|
+
throw new Error(
|
|
3410
|
+
"SDK must be initialized before setting process maxVoters. Call sdk.init() first."
|
|
3411
|
+
);
|
|
3412
|
+
}
|
|
3413
|
+
this.ensureProvider();
|
|
3414
|
+
return this.processOrchestrator.setProcessMaxVotersStream(processId, maxVoters);
|
|
3415
|
+
}
|
|
3416
|
+
/**
|
|
3417
|
+
* Sets the maximum number of voters for a process.
|
|
3418
|
+
* This is the simplified method that waits for transaction completion.
|
|
3419
|
+
*
|
|
3420
|
+
* For real-time transaction status updates, use setProcessMaxVotersStream() instead.
|
|
3421
|
+
*
|
|
3422
|
+
* Requires a signer with a provider for blockchain interactions.
|
|
3423
|
+
*
|
|
3424
|
+
* @param processId - The process ID
|
|
3425
|
+
* @param maxVoters - The new maximum number of voters
|
|
3426
|
+
* @returns Promise resolving when the maxVoters is updated
|
|
3427
|
+
* @throws Error if signer does not have a provider
|
|
3428
|
+
*
|
|
3429
|
+
* @example
|
|
3430
|
+
* ```typescript
|
|
3431
|
+
* await sdk.setProcessMaxVoters("0x1234567890abcdef...", 500);
|
|
3432
|
+
* console.log("MaxVoters updated successfully");
|
|
3433
|
+
* ```
|
|
3434
|
+
*/
|
|
3435
|
+
async setProcessMaxVoters(processId, maxVoters) {
|
|
3436
|
+
if (!this.initialized) {
|
|
3437
|
+
throw new Error(
|
|
3438
|
+
"SDK must be initialized before setting process maxVoters. Call sdk.init() first."
|
|
3439
|
+
);
|
|
3440
|
+
}
|
|
3441
|
+
this.ensureProvider();
|
|
3442
|
+
return this.processOrchestrator.setProcessMaxVoters(processId, maxVoters);
|
|
3443
|
+
}
|
|
3275
3444
|
/**
|
|
3276
3445
|
* Resolve contract address based on configuration priority:
|
|
3277
3446
|
* 1. Custom addresses from user config (if provided)
|