@vocdoni/davinci-sdk 0.0.1 → 0.0.2
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 +46 -1
- package/dist/contracts.d.ts +57 -2
- package/dist/index.d.ts +1048 -7
- package/dist/index.js +1112 -84
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1112 -84
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +1112 -84
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { ContractTransactionResponse, ContractRunner, Signer, Wallet } from 'ethers';
|
|
2
|
+
import { ContractTransactionResponse, BaseContract, ContractEventName, EventFilter, ContractRunner, Signer, Wallet } from 'ethers';
|
|
3
3
|
import * as _vocdoni_davinci_contracts_dist_src_ProcessRegistry from '@vocdoni/davinci-contracts/dist/src/ProcessRegistry';
|
|
4
4
|
|
|
5
5
|
type AnyJson = boolean | number | string | null | JsonArray | JsonMap | any;
|
|
@@ -167,6 +167,22 @@ interface CensusProviders {
|
|
|
167
167
|
/** Required provider for CSP census proof generation */
|
|
168
168
|
csp?: CSPCensusProofProvider;
|
|
169
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Type guard to check if an object is a valid MerkleCensusProof
|
|
172
|
+
*/
|
|
173
|
+
declare function isMerkleCensusProof(proof: any): proof is MerkleCensusProof;
|
|
174
|
+
/**
|
|
175
|
+
* Type guard to check if an object is a valid CSPCensusProof
|
|
176
|
+
*/
|
|
177
|
+
declare function isCSPCensusProof(proof: any): proof is CSPCensusProof;
|
|
178
|
+
/**
|
|
179
|
+
* Assertion function to validate MerkleCensusProof
|
|
180
|
+
*/
|
|
181
|
+
declare function assertMerkleCensusProof(proof: unknown): asserts proof is MerkleCensusProof;
|
|
182
|
+
/**
|
|
183
|
+
* Assertion function to validate CSPCensusProof
|
|
184
|
+
*/
|
|
185
|
+
declare function assertCSPCensusProof(proof: unknown): asserts proof is CSPCensusProof;
|
|
170
186
|
interface PublishCensusResponse {
|
|
171
187
|
/** The Merkle root of the published census (hex-prefixed). */
|
|
172
188
|
root: string;
|
|
@@ -231,6 +247,10 @@ interface SnapshotsQueryParams {
|
|
|
231
247
|
/** Filter by user-defined query name. */
|
|
232
248
|
queryName?: string;
|
|
233
249
|
}
|
|
250
|
+
interface CensusSizeResponse {
|
|
251
|
+
/** The number of participants in the census. */
|
|
252
|
+
size: number;
|
|
253
|
+
}
|
|
234
254
|
interface HealthResponse {
|
|
235
255
|
/** Service status. */
|
|
236
256
|
status: string;
|
|
@@ -608,9 +628,14 @@ type TxStatusEvent<T = any> = {
|
|
|
608
628
|
};
|
|
609
629
|
/**
|
|
610
630
|
* Abstract base class providing common functionality for smart contract interactions.
|
|
611
|
-
* Implements transaction handling, status monitoring,
|
|
631
|
+
* Implements transaction handling, status monitoring, event normalization, and
|
|
632
|
+
* event listener management with automatic fallback for RPCs that don't support eth_newFilter.
|
|
612
633
|
*/
|
|
613
634
|
declare abstract class SmartContractService {
|
|
635
|
+
/** Active polling intervals for event listeners using fallback mode */
|
|
636
|
+
private pollingIntervals;
|
|
637
|
+
/** Default polling interval in milliseconds for event listener fallback */
|
|
638
|
+
protected eventPollingInterval: number;
|
|
614
639
|
/**
|
|
615
640
|
* Sends a transaction and yields status events during its lifecycle.
|
|
616
641
|
* This method handles the complete transaction flow from submission to completion,
|
|
@@ -681,6 +706,56 @@ declare abstract class SmartContractService {
|
|
|
681
706
|
* ```
|
|
682
707
|
*/
|
|
683
708
|
protected normalizeListener<Args extends any[]>(callback: (...args: Args) => void): (...listenerArgs: any[]) => void;
|
|
709
|
+
/**
|
|
710
|
+
* Sets up an event listener with automatic fallback for RPCs that don't support eth_newFilter.
|
|
711
|
+
* First attempts to use contract.on() which relies on eth_newFilter. If the RPC doesn't support
|
|
712
|
+
* this method (error code -32601), automatically falls back to polling with queryFilter.
|
|
713
|
+
*
|
|
714
|
+
* @template Args - Tuple type representing the event arguments
|
|
715
|
+
* @param contract - The contract instance to listen to
|
|
716
|
+
* @param eventFilter - The event filter to listen for
|
|
717
|
+
* @param callback - The callback function to invoke when the event occurs
|
|
718
|
+
*
|
|
719
|
+
* @example
|
|
720
|
+
* ```typescript
|
|
721
|
+
* this.setupEventListener(
|
|
722
|
+
* this.contract,
|
|
723
|
+
* this.contract.filters.Transfer(),
|
|
724
|
+
* (from: string, to: string, amount: bigint) => {
|
|
725
|
+
* console.log(`Transfer: ${from} -> ${to}: ${amount}`);
|
|
726
|
+
* }
|
|
727
|
+
* );
|
|
728
|
+
* ```
|
|
729
|
+
*/
|
|
730
|
+
protected setupEventListener<Args extends any[]>(contract: BaseContract, eventFilter: ContractEventName | EventFilter, callback: (...args: Args) => void): Promise<void>;
|
|
731
|
+
/**
|
|
732
|
+
* Checks if an error indicates that the RPC method is unsupported (eth_newFilter).
|
|
733
|
+
*
|
|
734
|
+
* @param error - The error to check
|
|
735
|
+
* @returns true if the error indicates unsupported method
|
|
736
|
+
*/
|
|
737
|
+
private isUnsupportedMethodError;
|
|
738
|
+
/**
|
|
739
|
+
* Sets up a polling-based event listener as fallback when eth_newFilter is not supported.
|
|
740
|
+
* Periodically queries for new events and invokes the callback for each new event found.
|
|
741
|
+
*
|
|
742
|
+
* @template Args - Tuple type representing the event arguments
|
|
743
|
+
* @param contract - The contract instance to poll
|
|
744
|
+
* @param eventFilter - The event filter to poll for
|
|
745
|
+
* @param callback - The callback function to invoke for each event
|
|
746
|
+
*/
|
|
747
|
+
private setupPollingListener;
|
|
748
|
+
/**
|
|
749
|
+
* Clears all active polling intervals.
|
|
750
|
+
* Should be called when removing all listeners or cleaning up the service.
|
|
751
|
+
*/
|
|
752
|
+
protected clearPollingIntervals(): void;
|
|
753
|
+
/**
|
|
754
|
+
* Sets the polling interval for event listeners using the fallback mechanism.
|
|
755
|
+
*
|
|
756
|
+
* @param intervalMs - Polling interval in milliseconds
|
|
757
|
+
*/
|
|
758
|
+
setEventPollingInterval(intervalMs: number): void;
|
|
684
759
|
}
|
|
685
760
|
|
|
686
761
|
/**
|
|
@@ -1162,10 +1237,65 @@ declare class ProcessOrchestrationService {
|
|
|
1162
1237
|
*/
|
|
1163
1238
|
getProcess(processId: string): Promise<ProcessInfo>;
|
|
1164
1239
|
/**
|
|
1165
|
-
* Creates a complete voting process
|
|
1166
|
-
* This method
|
|
1240
|
+
* Creates a complete voting process and returns an async generator that yields transaction status events.
|
|
1241
|
+
* This method allows you to monitor the transaction progress in real-time.
|
|
1242
|
+
*
|
|
1243
|
+
* @param config - Process configuration
|
|
1244
|
+
* @returns AsyncGenerator yielding transaction status events with ProcessCreationResult
|
|
1245
|
+
*
|
|
1246
|
+
* @example
|
|
1247
|
+
* ```typescript
|
|
1248
|
+
* const stream = sdk.createProcessStream({
|
|
1249
|
+
* title: "My Election",
|
|
1250
|
+
* description: "A simple election",
|
|
1251
|
+
* census: { ... },
|
|
1252
|
+
* ballot: { ... },
|
|
1253
|
+
* timing: { ... },
|
|
1254
|
+
* questions: [ ... ]
|
|
1255
|
+
* });
|
|
1256
|
+
*
|
|
1257
|
+
* for await (const event of stream) {
|
|
1258
|
+
* switch (event.status) {
|
|
1259
|
+
* case "pending":
|
|
1260
|
+
* console.log("Transaction pending:", event.hash);
|
|
1261
|
+
* break;
|
|
1262
|
+
* case "completed":
|
|
1263
|
+
* console.log("Process created:", event.response.processId);
|
|
1264
|
+
* console.log("Transaction hash:", event.response.transactionHash);
|
|
1265
|
+
* break;
|
|
1266
|
+
* case "failed":
|
|
1267
|
+
* console.error("Transaction failed:", event.error);
|
|
1268
|
+
* break;
|
|
1269
|
+
* case "reverted":
|
|
1270
|
+
* console.error("Transaction reverted:", event.reason);
|
|
1271
|
+
* break;
|
|
1272
|
+
* }
|
|
1273
|
+
* }
|
|
1274
|
+
* ```
|
|
1275
|
+
*/
|
|
1276
|
+
createProcessStream(config: ProcessConfig): AsyncGenerator<TxStatusEvent<ProcessCreationResult>>;
|
|
1277
|
+
/**
|
|
1278
|
+
* Creates a complete voting process with minimal configuration.
|
|
1279
|
+
* This is the ultra-easy method for end users that handles all the complex orchestration internally.
|
|
1280
|
+
*
|
|
1281
|
+
* For real-time transaction status updates, use createProcessStream() instead.
|
|
1282
|
+
*
|
|
1283
|
+
* The method automatically:
|
|
1284
|
+
* - Gets encryption keys and initial state root from the sequencer
|
|
1285
|
+
* - Handles process creation signatures
|
|
1286
|
+
* - Coordinates between sequencer API and on-chain contract calls
|
|
1287
|
+
* - Creates and pushes metadata
|
|
1288
|
+
* - Submits the on-chain transaction
|
|
1289
|
+
*
|
|
1290
|
+
* @param config - Simplified process configuration
|
|
1291
|
+
* @returns Promise resolving to the process creation result
|
|
1167
1292
|
*/
|
|
1168
1293
|
createProcess(config: ProcessConfig): Promise<ProcessCreationResult>;
|
|
1294
|
+
/**
|
|
1295
|
+
* Prepares all data needed for process creation
|
|
1296
|
+
* @private
|
|
1297
|
+
*/
|
|
1298
|
+
private prepareProcessCreation;
|
|
1169
1299
|
/**
|
|
1170
1300
|
* Validates and calculates timing parameters
|
|
1171
1301
|
*/
|
|
@@ -1178,6 +1308,200 @@ declare class ProcessOrchestrationService {
|
|
|
1178
1308
|
* Creates metadata from the simplified configuration
|
|
1179
1309
|
*/
|
|
1180
1310
|
private createMetadata;
|
|
1311
|
+
/**
|
|
1312
|
+
* Ends a voting process by setting its status to ENDED.
|
|
1313
|
+
* Returns an async generator that yields transaction status events.
|
|
1314
|
+
*
|
|
1315
|
+
* @param processId - The process ID to end
|
|
1316
|
+
* @returns AsyncGenerator yielding transaction status events
|
|
1317
|
+
*
|
|
1318
|
+
* @example
|
|
1319
|
+
* ```typescript
|
|
1320
|
+
* const stream = sdk.endProcessStream("0x1234567890abcdef...");
|
|
1321
|
+
*
|
|
1322
|
+
* for await (const event of stream) {
|
|
1323
|
+
* switch (event.status) {
|
|
1324
|
+
* case "pending":
|
|
1325
|
+
* console.log("Transaction pending:", event.hash);
|
|
1326
|
+
* break;
|
|
1327
|
+
* case "completed":
|
|
1328
|
+
* console.log("Process ended successfully");
|
|
1329
|
+
* break;
|
|
1330
|
+
* case "failed":
|
|
1331
|
+
* console.error("Transaction failed:", event.error);
|
|
1332
|
+
* break;
|
|
1333
|
+
* case "reverted":
|
|
1334
|
+
* console.error("Transaction reverted:", event.reason);
|
|
1335
|
+
* break;
|
|
1336
|
+
* }
|
|
1337
|
+
* }
|
|
1338
|
+
* ```
|
|
1339
|
+
*/
|
|
1340
|
+
endProcessStream(processId: string): AsyncGenerator<TxStatusEvent<{
|
|
1341
|
+
success: boolean;
|
|
1342
|
+
}>>;
|
|
1343
|
+
/**
|
|
1344
|
+
* Ends a voting process by setting its status to ENDED.
|
|
1345
|
+
* This is a simplified method that waits for transaction completion.
|
|
1346
|
+
*
|
|
1347
|
+
* For real-time transaction status updates, use endProcessStream() instead.
|
|
1348
|
+
*
|
|
1349
|
+
* @param processId - The process ID to end
|
|
1350
|
+
* @returns Promise resolving when the process is ended
|
|
1351
|
+
*
|
|
1352
|
+
* @example
|
|
1353
|
+
* ```typescript
|
|
1354
|
+
* await sdk.endProcess("0x1234567890abcdef...");
|
|
1355
|
+
* console.log("Process ended successfully");
|
|
1356
|
+
* ```
|
|
1357
|
+
*/
|
|
1358
|
+
endProcess(processId: string): Promise<void>;
|
|
1359
|
+
/**
|
|
1360
|
+
* Pauses a voting process by setting its status to PAUSED.
|
|
1361
|
+
* Returns an async generator that yields transaction status events.
|
|
1362
|
+
*
|
|
1363
|
+
* @param processId - The process ID to pause
|
|
1364
|
+
* @returns AsyncGenerator yielding transaction status events
|
|
1365
|
+
*
|
|
1366
|
+
* @example
|
|
1367
|
+
* ```typescript
|
|
1368
|
+
* const stream = sdk.pauseProcessStream("0x1234567890abcdef...");
|
|
1369
|
+
*
|
|
1370
|
+
* for await (const event of stream) {
|
|
1371
|
+
* switch (event.status) {
|
|
1372
|
+
* case "pending":
|
|
1373
|
+
* console.log("Transaction pending:", event.hash);
|
|
1374
|
+
* break;
|
|
1375
|
+
* case "completed":
|
|
1376
|
+
* console.log("Process paused successfully");
|
|
1377
|
+
* break;
|
|
1378
|
+
* case "failed":
|
|
1379
|
+
* console.error("Transaction failed:", event.error);
|
|
1380
|
+
* break;
|
|
1381
|
+
* case "reverted":
|
|
1382
|
+
* console.error("Transaction reverted:", event.reason);
|
|
1383
|
+
* break;
|
|
1384
|
+
* }
|
|
1385
|
+
* }
|
|
1386
|
+
* ```
|
|
1387
|
+
*/
|
|
1388
|
+
pauseProcessStream(processId: string): AsyncGenerator<TxStatusEvent<{
|
|
1389
|
+
success: boolean;
|
|
1390
|
+
}>>;
|
|
1391
|
+
/**
|
|
1392
|
+
* Pauses a voting process by setting its status to PAUSED.
|
|
1393
|
+
* This is a simplified method that waits for transaction completion.
|
|
1394
|
+
*
|
|
1395
|
+
* For real-time transaction status updates, use pauseProcessStream() instead.
|
|
1396
|
+
*
|
|
1397
|
+
* @param processId - The process ID to pause
|
|
1398
|
+
* @returns Promise resolving when the process is paused
|
|
1399
|
+
*
|
|
1400
|
+
* @example
|
|
1401
|
+
* ```typescript
|
|
1402
|
+
* await sdk.pauseProcess("0x1234567890abcdef...");
|
|
1403
|
+
* console.log("Process paused successfully");
|
|
1404
|
+
* ```
|
|
1405
|
+
*/
|
|
1406
|
+
pauseProcess(processId: string): Promise<void>;
|
|
1407
|
+
/**
|
|
1408
|
+
* Cancels a voting process by setting its status to CANCELED.
|
|
1409
|
+
* Returns an async generator that yields transaction status events.
|
|
1410
|
+
*
|
|
1411
|
+
* @param processId - The process ID to cancel
|
|
1412
|
+
* @returns AsyncGenerator yielding transaction status events
|
|
1413
|
+
*
|
|
1414
|
+
* @example
|
|
1415
|
+
* ```typescript
|
|
1416
|
+
* const stream = sdk.cancelProcessStream("0x1234567890abcdef...");
|
|
1417
|
+
*
|
|
1418
|
+
* for await (const event of stream) {
|
|
1419
|
+
* switch (event.status) {
|
|
1420
|
+
* case "pending":
|
|
1421
|
+
* console.log("Transaction pending:", event.hash);
|
|
1422
|
+
* break;
|
|
1423
|
+
* case "completed":
|
|
1424
|
+
* console.log("Process canceled successfully");
|
|
1425
|
+
* break;
|
|
1426
|
+
* case "failed":
|
|
1427
|
+
* console.error("Transaction failed:", event.error);
|
|
1428
|
+
* break;
|
|
1429
|
+
* case "reverted":
|
|
1430
|
+
* console.error("Transaction reverted:", event.reason);
|
|
1431
|
+
* break;
|
|
1432
|
+
* }
|
|
1433
|
+
* }
|
|
1434
|
+
* ```
|
|
1435
|
+
*/
|
|
1436
|
+
cancelProcessStream(processId: string): AsyncGenerator<TxStatusEvent<{
|
|
1437
|
+
success: boolean;
|
|
1438
|
+
}>>;
|
|
1439
|
+
/**
|
|
1440
|
+
* Cancels a voting process by setting its status to CANCELED.
|
|
1441
|
+
* This is a simplified method that waits for transaction completion.
|
|
1442
|
+
*
|
|
1443
|
+
* For real-time transaction status updates, use cancelProcessStream() instead.
|
|
1444
|
+
*
|
|
1445
|
+
* @param processId - The process ID to cancel
|
|
1446
|
+
* @returns Promise resolving when the process is canceled
|
|
1447
|
+
*
|
|
1448
|
+
* @example
|
|
1449
|
+
* ```typescript
|
|
1450
|
+
* await sdk.cancelProcess("0x1234567890abcdef...");
|
|
1451
|
+
* console.log("Process canceled successfully");
|
|
1452
|
+
* ```
|
|
1453
|
+
*/
|
|
1454
|
+
cancelProcess(processId: string): Promise<void>;
|
|
1455
|
+
/**
|
|
1456
|
+
* Resumes a voting process by setting its status to READY.
|
|
1457
|
+
* This is typically used to resume a paused process.
|
|
1458
|
+
* Returns an async generator that yields transaction status events.
|
|
1459
|
+
*
|
|
1460
|
+
* @param processId - The process ID to resume
|
|
1461
|
+
* @returns AsyncGenerator yielding transaction status events
|
|
1462
|
+
*
|
|
1463
|
+
* @example
|
|
1464
|
+
* ```typescript
|
|
1465
|
+
* const stream = sdk.resumeProcessStream("0x1234567890abcdef...");
|
|
1466
|
+
*
|
|
1467
|
+
* for await (const event of stream) {
|
|
1468
|
+
* switch (event.status) {
|
|
1469
|
+
* case "pending":
|
|
1470
|
+
* console.log("Transaction pending:", event.hash);
|
|
1471
|
+
* break;
|
|
1472
|
+
* case "completed":
|
|
1473
|
+
* console.log("Process resumed successfully");
|
|
1474
|
+
* break;
|
|
1475
|
+
* case "failed":
|
|
1476
|
+
* console.error("Transaction failed:", event.error);
|
|
1477
|
+
* break;
|
|
1478
|
+
* case "reverted":
|
|
1479
|
+
* console.error("Transaction reverted:", event.reason);
|
|
1480
|
+
* break;
|
|
1481
|
+
* }
|
|
1482
|
+
* }
|
|
1483
|
+
* ```
|
|
1484
|
+
*/
|
|
1485
|
+
resumeProcessStream(processId: string): AsyncGenerator<TxStatusEvent<{
|
|
1486
|
+
success: boolean;
|
|
1487
|
+
}>>;
|
|
1488
|
+
/**
|
|
1489
|
+
* Resumes a voting process by setting its status to READY.
|
|
1490
|
+
* This is typically used to resume a paused process.
|
|
1491
|
+
* This is a simplified method that waits for transaction completion.
|
|
1492
|
+
*
|
|
1493
|
+
* For real-time transaction status updates, use resumeProcessStream() instead.
|
|
1494
|
+
*
|
|
1495
|
+
* @param processId - The process ID to resume
|
|
1496
|
+
* @returns Promise resolving when the process is resumed
|
|
1497
|
+
*
|
|
1498
|
+
* @example
|
|
1499
|
+
* ```typescript
|
|
1500
|
+
* await sdk.resumeProcess("0x1234567890abcdef...");
|
|
1501
|
+
* console.log("Process resumed successfully");
|
|
1502
|
+
* ```
|
|
1503
|
+
*/
|
|
1504
|
+
resumeProcess(processId: string): Promise<void>;
|
|
1181
1505
|
}
|
|
1182
1506
|
|
|
1183
1507
|
/**
|
|
@@ -1256,7 +1580,43 @@ declare class VoteOrchestrationService {
|
|
|
1256
1580
|
*/
|
|
1257
1581
|
hasAddressVoted(processId: string, address: string): Promise<boolean>;
|
|
1258
1582
|
/**
|
|
1259
|
-
*
|
|
1583
|
+
* Watch vote status changes in real-time using an async generator.
|
|
1584
|
+
* Yields each status change as it happens, allowing for reactive UI updates.
|
|
1585
|
+
*
|
|
1586
|
+
* @param processId - The process ID
|
|
1587
|
+
* @param voteId - The vote ID
|
|
1588
|
+
* @param options - Optional configuration
|
|
1589
|
+
* @returns AsyncGenerator yielding vote status updates
|
|
1590
|
+
*
|
|
1591
|
+
* @example
|
|
1592
|
+
* ```typescript
|
|
1593
|
+
* const vote = await sdk.submitVote({ processId, choices: [1] });
|
|
1594
|
+
*
|
|
1595
|
+
* for await (const statusInfo of sdk.watchVoteStatus(vote.processId, vote.voteId)) {
|
|
1596
|
+
* console.log(`Vote status: ${statusInfo.status}`);
|
|
1597
|
+
*
|
|
1598
|
+
* switch (statusInfo.status) {
|
|
1599
|
+
* case VoteStatus.Pending:
|
|
1600
|
+
* console.log("⏳ Processing...");
|
|
1601
|
+
* break;
|
|
1602
|
+
* case VoteStatus.Verified:
|
|
1603
|
+
* console.log("✓ Verified");
|
|
1604
|
+
* break;
|
|
1605
|
+
* case VoteStatus.Settled:
|
|
1606
|
+
* console.log("✅ Settled");
|
|
1607
|
+
* break;
|
|
1608
|
+
* }
|
|
1609
|
+
* }
|
|
1610
|
+
* ```
|
|
1611
|
+
*/
|
|
1612
|
+
watchVoteStatus(processId: string, voteId: string, options?: {
|
|
1613
|
+
targetStatus?: VoteStatus;
|
|
1614
|
+
timeoutMs?: number;
|
|
1615
|
+
pollIntervalMs?: number;
|
|
1616
|
+
}): AsyncGenerator<VoteStatusInfo>;
|
|
1617
|
+
/**
|
|
1618
|
+
* Wait for a vote to reach a specific status.
|
|
1619
|
+
* This is a simpler alternative to watchVoteStatus() that returns only the final status.
|
|
1260
1620
|
*
|
|
1261
1621
|
* @param processId - The process ID
|
|
1262
1622
|
* @param voteId - The vote ID
|
|
@@ -1384,5 +1744,686 @@ declare function signProcessCreation(processId: string, signer: Signer | Wallet)
|
|
|
1384
1744
|
*/
|
|
1385
1745
|
declare function validateProcessId(processId: string): boolean;
|
|
1386
1746
|
|
|
1387
|
-
|
|
1388
|
-
|
|
1747
|
+
/**
|
|
1748
|
+
* Configuration interface for the DavinciSDK
|
|
1749
|
+
*/
|
|
1750
|
+
interface DavinciSDKConfig {
|
|
1751
|
+
/**
|
|
1752
|
+
* Ethers.js Signer for signing operations.
|
|
1753
|
+
* - For voting only: Can be a bare Wallet (no provider needed)
|
|
1754
|
+
* - For process/organization operations: Must be connected to a provider
|
|
1755
|
+
*/
|
|
1756
|
+
signer: Signer;
|
|
1757
|
+
/** Environment to use (dev, stg, prod) - used to set default URLs and chain if not explicitly provided */
|
|
1758
|
+
environment?: Environment;
|
|
1759
|
+
/** Sequencer API URL for Vocdoni services (optional, defaults based on environment) */
|
|
1760
|
+
sequencerUrl?: string;
|
|
1761
|
+
/** Census API URL for census management (optional, defaults based on environment) */
|
|
1762
|
+
censusUrl?: string;
|
|
1763
|
+
/** Chain name (optional, defaults based on environment) */
|
|
1764
|
+
chain?: 'sepolia' | 'mainnet';
|
|
1765
|
+
/** Custom contract addresses (optional, uses defaults if not provided) */
|
|
1766
|
+
contractAddresses?: {
|
|
1767
|
+
processRegistry?: string;
|
|
1768
|
+
organizationRegistry?: string;
|
|
1769
|
+
stateTransitionVerifier?: string;
|
|
1770
|
+
resultsVerifier?: string;
|
|
1771
|
+
sequencerRegistry?: string;
|
|
1772
|
+
};
|
|
1773
|
+
/** Whether to force using contract addresses from sequencer info (optional, defaults to false) */
|
|
1774
|
+
useSequencerAddresses?: boolean;
|
|
1775
|
+
/** Custom census proof providers (optional) */
|
|
1776
|
+
censusProviders?: CensusProviders;
|
|
1777
|
+
}
|
|
1778
|
+
/**
|
|
1779
|
+
* Internal configuration interface (without environment)
|
|
1780
|
+
*/
|
|
1781
|
+
interface InternalDavinciSDKConfig {
|
|
1782
|
+
signer: Signer;
|
|
1783
|
+
sequencerUrl: string;
|
|
1784
|
+
censusUrl: string;
|
|
1785
|
+
chain: 'sepolia' | 'mainnet';
|
|
1786
|
+
contractAddresses: {
|
|
1787
|
+
processRegistry?: string;
|
|
1788
|
+
organizationRegistry?: string;
|
|
1789
|
+
stateTransitionVerifier?: string;
|
|
1790
|
+
resultsVerifier?: string;
|
|
1791
|
+
sequencerRegistry?: string;
|
|
1792
|
+
};
|
|
1793
|
+
useSequencerAddresses: boolean;
|
|
1794
|
+
}
|
|
1795
|
+
/**
|
|
1796
|
+
* Simplified SDK class that encapsulates all Vocdoni DaVinci functionality
|
|
1797
|
+
*/
|
|
1798
|
+
declare class DavinciSDK {
|
|
1799
|
+
private config;
|
|
1800
|
+
private apiService;
|
|
1801
|
+
private _processRegistry?;
|
|
1802
|
+
private _organizationRegistry?;
|
|
1803
|
+
private _processOrchestrator?;
|
|
1804
|
+
private _voteOrchestrator?;
|
|
1805
|
+
private davinciCrypto?;
|
|
1806
|
+
private initialized;
|
|
1807
|
+
private censusProviders;
|
|
1808
|
+
constructor(config: DavinciSDKConfig);
|
|
1809
|
+
/**
|
|
1810
|
+
* Initialize the SDK and all its components
|
|
1811
|
+
* This must be called before using any SDK functionality
|
|
1812
|
+
*/
|
|
1813
|
+
init(): Promise<void>;
|
|
1814
|
+
/**
|
|
1815
|
+
* Get the API service for direct access to sequencer and census APIs
|
|
1816
|
+
*/
|
|
1817
|
+
get api(): VocdoniApiService;
|
|
1818
|
+
/**
|
|
1819
|
+
* Get the process registry service for process management.
|
|
1820
|
+
* Requires a signer with a provider for blockchain interactions.
|
|
1821
|
+
*
|
|
1822
|
+
* @throws Error if signer does not have a provider
|
|
1823
|
+
*/
|
|
1824
|
+
get processes(): ProcessRegistryService;
|
|
1825
|
+
/**
|
|
1826
|
+
* Get the organization registry service for organization management.
|
|
1827
|
+
* Requires a signer with a provider for blockchain interactions.
|
|
1828
|
+
*
|
|
1829
|
+
* @throws Error if signer does not have a provider
|
|
1830
|
+
*/
|
|
1831
|
+
get organizations(): OrganizationRegistryService;
|
|
1832
|
+
/**
|
|
1833
|
+
* Get or initialize the DavinciCrypto service for cryptographic operations
|
|
1834
|
+
*/
|
|
1835
|
+
getCrypto(): Promise<DavinciCrypto>;
|
|
1836
|
+
/**
|
|
1837
|
+
* Get the process orchestration service for simplified process creation.
|
|
1838
|
+
* Requires a signer with a provider for blockchain interactions.
|
|
1839
|
+
*
|
|
1840
|
+
* @throws Error if signer does not have a provider
|
|
1841
|
+
*/
|
|
1842
|
+
get processOrchestrator(): ProcessOrchestrationService;
|
|
1843
|
+
/**
|
|
1844
|
+
* Get the vote orchestration service for simplified voting
|
|
1845
|
+
*/
|
|
1846
|
+
get voteOrchestrator(): VoteOrchestrationService;
|
|
1847
|
+
/**
|
|
1848
|
+
* Gets user-friendly process information from the blockchain.
|
|
1849
|
+
* This method fetches raw contract data and transforms it into a user-friendly format
|
|
1850
|
+
* that matches the ProcessConfig interface used for creation, plus additional runtime data.
|
|
1851
|
+
*
|
|
1852
|
+
* Requires a signer with a provider for blockchain interactions.
|
|
1853
|
+
*
|
|
1854
|
+
* @param processId - The process ID to fetch
|
|
1855
|
+
* @returns Promise resolving to user-friendly process information
|
|
1856
|
+
* @throws Error if signer does not have a provider
|
|
1857
|
+
*
|
|
1858
|
+
* @example
|
|
1859
|
+
* ```typescript
|
|
1860
|
+
* const processInfo = await sdk.getProcess("0x1234567890abcdef...");
|
|
1861
|
+
*
|
|
1862
|
+
* // Access the same fields as ProcessConfig
|
|
1863
|
+
* console.log("Title:", processInfo.title);
|
|
1864
|
+
* console.log("Description:", processInfo.description);
|
|
1865
|
+
* console.log("Questions:", processInfo.questions);
|
|
1866
|
+
* console.log("Census size:", processInfo.census.size);
|
|
1867
|
+
* console.log("Ballot config:", processInfo.ballot);
|
|
1868
|
+
*
|
|
1869
|
+
* // Plus additional runtime information
|
|
1870
|
+
* console.log("Status:", processInfo.status);
|
|
1871
|
+
* console.log("Creator:", processInfo.creator);
|
|
1872
|
+
* console.log("Start date:", processInfo.startDate);
|
|
1873
|
+
* console.log("End date:", processInfo.endDate);
|
|
1874
|
+
* console.log("Duration:", processInfo.duration, "seconds");
|
|
1875
|
+
* console.log("Time remaining:", processInfo.timeRemaining, "seconds");
|
|
1876
|
+
*
|
|
1877
|
+
* // Access raw contract data if needed
|
|
1878
|
+
* console.log("Raw data:", processInfo.raw);
|
|
1879
|
+
* ```
|
|
1880
|
+
*/
|
|
1881
|
+
getProcess(processId: string): Promise<ProcessInfo>;
|
|
1882
|
+
/**
|
|
1883
|
+
* Creates a complete voting process and returns an async generator that yields transaction status events.
|
|
1884
|
+
* This method allows you to monitor the transaction progress in real-time, including pending, completed,
|
|
1885
|
+
* failed, and reverted states.
|
|
1886
|
+
*
|
|
1887
|
+
* Requires a signer with a provider for blockchain interactions.
|
|
1888
|
+
*
|
|
1889
|
+
* @param config - Simplified process configuration
|
|
1890
|
+
* @returns AsyncGenerator yielding transaction status events
|
|
1891
|
+
* @throws Error if signer does not have a provider
|
|
1892
|
+
*
|
|
1893
|
+
* @example
|
|
1894
|
+
* ```typescript
|
|
1895
|
+
* const stream = sdk.createProcessStream({
|
|
1896
|
+
* title: "My Election",
|
|
1897
|
+
* description: "A simple election",
|
|
1898
|
+
* census: {
|
|
1899
|
+
* type: CensusOrigin.CensusOriginMerkleTree,
|
|
1900
|
+
* root: "0x1234...",
|
|
1901
|
+
* size: 100,
|
|
1902
|
+
* uri: "ipfs://..."
|
|
1903
|
+
* },
|
|
1904
|
+
* ballot: {
|
|
1905
|
+
* numFields: 2,
|
|
1906
|
+
* maxValue: "3",
|
|
1907
|
+
* minValue: "0",
|
|
1908
|
+
* uniqueValues: false,
|
|
1909
|
+
* costFromWeight: false,
|
|
1910
|
+
* costExponent: 10000,
|
|
1911
|
+
* maxValueSum: "6",
|
|
1912
|
+
* minValueSum: "0"
|
|
1913
|
+
* },
|
|
1914
|
+
* timing: {
|
|
1915
|
+
* startDate: new Date("2024-12-01T10:00:00Z"),
|
|
1916
|
+
* duration: 3600 * 24
|
|
1917
|
+
* },
|
|
1918
|
+
* questions: [
|
|
1919
|
+
* {
|
|
1920
|
+
* title: "What is your favorite color?",
|
|
1921
|
+
* choices: [
|
|
1922
|
+
* { title: "Red", value: 0 },
|
|
1923
|
+
* { title: "Blue", value: 1 }
|
|
1924
|
+
* ]
|
|
1925
|
+
* }
|
|
1926
|
+
* ]
|
|
1927
|
+
* });
|
|
1928
|
+
*
|
|
1929
|
+
* // Monitor transaction progress
|
|
1930
|
+
* for await (const event of stream) {
|
|
1931
|
+
* switch (event.status) {
|
|
1932
|
+
* case TxStatus.Pending:
|
|
1933
|
+
* console.log("Transaction pending:", event.hash);
|
|
1934
|
+
* // Update UI to show pending state
|
|
1935
|
+
* break;
|
|
1936
|
+
* case TxStatus.Completed:
|
|
1937
|
+
* console.log("Process created:", event.response.processId);
|
|
1938
|
+
* console.log("Transaction hash:", event.response.transactionHash);
|
|
1939
|
+
* // Update UI to show success
|
|
1940
|
+
* break;
|
|
1941
|
+
* case TxStatus.Failed:
|
|
1942
|
+
* console.error("Transaction failed:", event.error);
|
|
1943
|
+
* // Update UI to show error
|
|
1944
|
+
* break;
|
|
1945
|
+
* case TxStatus.Reverted:
|
|
1946
|
+
* console.error("Transaction reverted:", event.reason);
|
|
1947
|
+
* // Update UI to show revert reason
|
|
1948
|
+
* break;
|
|
1949
|
+
* }
|
|
1950
|
+
* }
|
|
1951
|
+
* ```
|
|
1952
|
+
*/
|
|
1953
|
+
createProcessStream(config: ProcessConfig): AsyncGenerator<TxStatusEvent<ProcessCreationResult>, any, any>;
|
|
1954
|
+
/**
|
|
1955
|
+
* Creates a complete voting process with minimal configuration.
|
|
1956
|
+
* This is the ultra-easy method for end users that handles all the complex orchestration internally.
|
|
1957
|
+
*
|
|
1958
|
+
* For real-time transaction status updates, use createProcessStream() instead.
|
|
1959
|
+
*
|
|
1960
|
+
* Requires a signer with a provider for blockchain interactions.
|
|
1961
|
+
*
|
|
1962
|
+
* The method automatically:
|
|
1963
|
+
* - Gets encryption keys and initial state root from the sequencer
|
|
1964
|
+
* - Handles process creation signatures
|
|
1965
|
+
* - Coordinates between sequencer API and on-chain contract calls
|
|
1966
|
+
* - Creates and pushes metadata
|
|
1967
|
+
* - Submits the on-chain transaction
|
|
1968
|
+
*
|
|
1969
|
+
* @param config - Simplified process configuration
|
|
1970
|
+
* @returns Promise resolving to the process creation result
|
|
1971
|
+
* @throws Error if signer does not have a provider
|
|
1972
|
+
*
|
|
1973
|
+
* @example
|
|
1974
|
+
* ```typescript
|
|
1975
|
+
* // Option 1: Using duration (traditional approach)
|
|
1976
|
+
* const result1 = await sdk.createProcess({
|
|
1977
|
+
* title: "My Election",
|
|
1978
|
+
* description: "A simple election",
|
|
1979
|
+
* census: {
|
|
1980
|
+
* type: CensusOrigin.CensusOriginMerkleTree,
|
|
1981
|
+
* root: "0x1234...",
|
|
1982
|
+
* size: 100,
|
|
1983
|
+
* uri: "ipfs://your-census-uri"
|
|
1984
|
+
* },
|
|
1985
|
+
* ballot: {
|
|
1986
|
+
* numFields: 2,
|
|
1987
|
+
* maxValue: "3",
|
|
1988
|
+
* minValue: "0",
|
|
1989
|
+
* uniqueValues: false,
|
|
1990
|
+
* costFromWeight: false,
|
|
1991
|
+
* costExponent: 10000,
|
|
1992
|
+
* maxValueSum: "6",
|
|
1993
|
+
* minValueSum: "0"
|
|
1994
|
+
* },
|
|
1995
|
+
* timing: {
|
|
1996
|
+
* startDate: new Date("2024-12-01T10:00:00Z"),
|
|
1997
|
+
* duration: 3600 * 24
|
|
1998
|
+
* },
|
|
1999
|
+
* questions: [
|
|
2000
|
+
* {
|
|
2001
|
+
* title: "What is your favorite color?",
|
|
2002
|
+
* choices: [
|
|
2003
|
+
* { title: "Red", value: 0 },
|
|
2004
|
+
* { title: "Blue", value: 1 }
|
|
2005
|
+
* ]
|
|
2006
|
+
* }
|
|
2007
|
+
* ]
|
|
2008
|
+
* });
|
|
2009
|
+
*
|
|
2010
|
+
* // Option 2: Using start and end dates
|
|
2011
|
+
* const result2 = await sdk.createProcess({
|
|
2012
|
+
* title: "Weekend Vote",
|
|
2013
|
+
* timing: {
|
|
2014
|
+
* startDate: "2024-12-07T09:00:00Z",
|
|
2015
|
+
* endDate: "2024-12-08T18:00:00Z"
|
|
2016
|
+
* }
|
|
2017
|
+
* });
|
|
2018
|
+
* ```
|
|
2019
|
+
*/
|
|
2020
|
+
createProcess(config: ProcessConfig): Promise<ProcessCreationResult>;
|
|
2021
|
+
/**
|
|
2022
|
+
* Submit a vote with simplified configuration.
|
|
2023
|
+
* This is the ultra-easy method for end users that handles all the complex voting workflow internally.
|
|
2024
|
+
*
|
|
2025
|
+
* Does NOT require a provider - can be used with a bare Wallet for signing only.
|
|
2026
|
+
*
|
|
2027
|
+
* The method automatically:
|
|
2028
|
+
* - Fetches process information and validates voting is allowed
|
|
2029
|
+
* - Gets census proof (Merkle tree based)
|
|
2030
|
+
* - Generates cryptographic proofs and encrypts the vote
|
|
2031
|
+
* - Signs and submits the vote to the sequencer
|
|
2032
|
+
*
|
|
2033
|
+
* @param config - Simplified vote configuration
|
|
2034
|
+
* @returns Promise resolving to vote submission result
|
|
2035
|
+
*
|
|
2036
|
+
* @example
|
|
2037
|
+
* ```typescript
|
|
2038
|
+
* // Submit a vote with voter's private key
|
|
2039
|
+
* const voteResult = await sdk.submitVote({
|
|
2040
|
+
* processId: "0x1234567890abcdef...",
|
|
2041
|
+
* choices: [1, 0], // Vote for option 1 in question 1, option 0 in question 2
|
|
2042
|
+
* voterKey: "0x1234567890abcdef..." // Voter's private key
|
|
2043
|
+
* });
|
|
2044
|
+
*
|
|
2045
|
+
* console.log("Vote ID:", voteResult.voteId);
|
|
2046
|
+
* console.log("Status:", voteResult.status);
|
|
2047
|
+
*
|
|
2048
|
+
* // Submit a vote with a Wallet instance
|
|
2049
|
+
* import { Wallet } from "ethers";
|
|
2050
|
+
* const voterWallet = new Wallet("0x...");
|
|
2051
|
+
*
|
|
2052
|
+
* const voteResult2 = await sdk.submitVote({
|
|
2053
|
+
* processId: "0x1234567890abcdef...",
|
|
2054
|
+
* choices: [2], // Single question vote
|
|
2055
|
+
* voterKey: voterWallet
|
|
2056
|
+
* });
|
|
2057
|
+
* ```
|
|
2058
|
+
*/
|
|
2059
|
+
submitVote(config: VoteConfig): Promise<VoteResult>;
|
|
2060
|
+
/**
|
|
2061
|
+
* Get the status of a submitted vote.
|
|
2062
|
+
*
|
|
2063
|
+
* Does NOT require a provider - uses API calls only.
|
|
2064
|
+
*
|
|
2065
|
+
* @param processId - The process ID
|
|
2066
|
+
* @param voteId - The vote ID returned from submitVote()
|
|
2067
|
+
* @returns Promise resolving to vote status information
|
|
2068
|
+
*
|
|
2069
|
+
* @example
|
|
2070
|
+
* ```typescript
|
|
2071
|
+
* const statusInfo = await sdk.getVoteStatus(processId, voteId);
|
|
2072
|
+
* console.log("Vote status:", statusInfo.status);
|
|
2073
|
+
* // Possible statuses: "pending", "verified", "aggregated", "processed", "settled", "error"
|
|
2074
|
+
* ```
|
|
2075
|
+
*/
|
|
2076
|
+
getVoteStatus(processId: string, voteId: string): Promise<VoteStatusInfo>;
|
|
2077
|
+
/**
|
|
2078
|
+
* Check if an address has voted in a process.
|
|
2079
|
+
*
|
|
2080
|
+
* Does NOT require a provider - uses API calls only.
|
|
2081
|
+
*
|
|
2082
|
+
* @param processId - The process ID
|
|
2083
|
+
* @param address - The voter's address
|
|
2084
|
+
* @returns Promise resolving to boolean indicating if the address has voted
|
|
2085
|
+
*
|
|
2086
|
+
* @example
|
|
2087
|
+
* ```typescript
|
|
2088
|
+
* const hasVoted = await sdk.hasAddressVoted(processId, "0x1234567890abcdef...");
|
|
2089
|
+
* if (hasVoted) {
|
|
2090
|
+
* console.log("This address has already voted");
|
|
2091
|
+
* }
|
|
2092
|
+
* ```
|
|
2093
|
+
*/
|
|
2094
|
+
hasAddressVoted(processId: string, address: string): Promise<boolean>;
|
|
2095
|
+
/**
|
|
2096
|
+
* Watch vote status changes in real-time using an async generator.
|
|
2097
|
+
* This method yields each status change as it happens, perfect for showing
|
|
2098
|
+
* progress indicators in UI applications.
|
|
2099
|
+
*
|
|
2100
|
+
* Does NOT require a provider - uses API calls only.
|
|
2101
|
+
*
|
|
2102
|
+
* @param processId - The process ID
|
|
2103
|
+
* @param voteId - The vote ID
|
|
2104
|
+
* @param options - Optional configuration
|
|
2105
|
+
* @returns AsyncGenerator yielding vote status updates
|
|
2106
|
+
*
|
|
2107
|
+
* @example
|
|
2108
|
+
* ```typescript
|
|
2109
|
+
* // Submit vote
|
|
2110
|
+
* const voteResult = await sdk.submitVote({
|
|
2111
|
+
* processId: "0x1234567890abcdef...",
|
|
2112
|
+
* choices: [1]
|
|
2113
|
+
* });
|
|
2114
|
+
*
|
|
2115
|
+
* // Watch status changes in real-time
|
|
2116
|
+
* for await (const statusInfo of sdk.watchVoteStatus(voteResult.processId, voteResult.voteId)) {
|
|
2117
|
+
* console.log(`Vote status: ${statusInfo.status}`);
|
|
2118
|
+
*
|
|
2119
|
+
* switch (statusInfo.status) {
|
|
2120
|
+
* case VoteStatus.Pending:
|
|
2121
|
+
* console.log("⏳ Processing...");
|
|
2122
|
+
* break;
|
|
2123
|
+
* case VoteStatus.Verified:
|
|
2124
|
+
* console.log("✓ Vote verified");
|
|
2125
|
+
* break;
|
|
2126
|
+
* case VoteStatus.Aggregated:
|
|
2127
|
+
* console.log("📊 Vote aggregated");
|
|
2128
|
+
* break;
|
|
2129
|
+
* case VoteStatus.Settled:
|
|
2130
|
+
* console.log("✅ Vote settled");
|
|
2131
|
+
* break;
|
|
2132
|
+
* }
|
|
2133
|
+
* }
|
|
2134
|
+
* ```
|
|
2135
|
+
*/
|
|
2136
|
+
watchVoteStatus(processId: string, voteId: string, options?: {
|
|
2137
|
+
targetStatus?: VoteStatus;
|
|
2138
|
+
timeoutMs?: number;
|
|
2139
|
+
pollIntervalMs?: number;
|
|
2140
|
+
}): AsyncGenerator<VoteStatusInfo, any, any>;
|
|
2141
|
+
/**
|
|
2142
|
+
* Wait for a vote to reach a specific status.
|
|
2143
|
+
* This is a simpler alternative to watchVoteStatus() that returns only the final status.
|
|
2144
|
+
* Useful for waiting for vote confirmation and processing without needing to handle each intermediate status.
|
|
2145
|
+
*
|
|
2146
|
+
* Does NOT require a provider - uses API calls only.
|
|
2147
|
+
*
|
|
2148
|
+
* @param processId - The process ID
|
|
2149
|
+
* @param voteId - The vote ID
|
|
2150
|
+
* @param targetStatus - The target status to wait for (default: "settled")
|
|
2151
|
+
* @param timeoutMs - Maximum time to wait in milliseconds (default: 300000 = 5 minutes)
|
|
2152
|
+
* @param pollIntervalMs - Polling interval in milliseconds (default: 5000 = 5 seconds)
|
|
2153
|
+
* @returns Promise resolving to final vote status
|
|
2154
|
+
*
|
|
2155
|
+
* @example
|
|
2156
|
+
* ```typescript
|
|
2157
|
+
* // Submit vote and wait for it to be settled
|
|
2158
|
+
* const voteResult = await sdk.submitVote({
|
|
2159
|
+
* processId: "0x1234567890abcdef...",
|
|
2160
|
+
* choices: [1]
|
|
2161
|
+
* });
|
|
2162
|
+
*
|
|
2163
|
+
* // Wait for the vote to be fully processed
|
|
2164
|
+
* const finalStatus = await sdk.waitForVoteStatus(
|
|
2165
|
+
* voteResult.processId,
|
|
2166
|
+
* voteResult.voteId,
|
|
2167
|
+
* VoteStatus.Settled, // Wait until vote is settled
|
|
2168
|
+
* 300000, // 5 minute timeout
|
|
2169
|
+
* 5000 // Check every 5 seconds
|
|
2170
|
+
* );
|
|
2171
|
+
*
|
|
2172
|
+
* console.log("Vote final status:", finalStatus.status);
|
|
2173
|
+
* ```
|
|
2174
|
+
*/
|
|
2175
|
+
waitForVoteStatus(processId: string, voteId: string, targetStatus?: VoteStatus, timeoutMs?: number, pollIntervalMs?: number): Promise<VoteStatusInfo>;
|
|
2176
|
+
/**
|
|
2177
|
+
* Ends a voting process by setting its status to ENDED and returns an async generator
|
|
2178
|
+
* that yields transaction status events. This method allows you to monitor the
|
|
2179
|
+
* transaction progress in real-time.
|
|
2180
|
+
*
|
|
2181
|
+
* Requires a signer with a provider for blockchain interactions.
|
|
2182
|
+
*
|
|
2183
|
+
* @param processId - The process ID to end
|
|
2184
|
+
* @returns AsyncGenerator yielding transaction status events
|
|
2185
|
+
* @throws Error if signer does not have a provider
|
|
2186
|
+
*
|
|
2187
|
+
* @example
|
|
2188
|
+
* ```typescript
|
|
2189
|
+
* const stream = sdk.endProcessStream("0x1234567890abcdef...");
|
|
2190
|
+
*
|
|
2191
|
+
* for await (const event of stream) {
|
|
2192
|
+
* switch (event.status) {
|
|
2193
|
+
* case TxStatus.Pending:
|
|
2194
|
+
* console.log("Transaction pending:", event.hash);
|
|
2195
|
+
* break;
|
|
2196
|
+
* case TxStatus.Completed:
|
|
2197
|
+
* console.log("Process ended successfully");
|
|
2198
|
+
* break;
|
|
2199
|
+
* case TxStatus.Failed:
|
|
2200
|
+
* console.error("Transaction failed:", event.error);
|
|
2201
|
+
* break;
|
|
2202
|
+
* case TxStatus.Reverted:
|
|
2203
|
+
* console.error("Transaction reverted:", event.reason);
|
|
2204
|
+
* break;
|
|
2205
|
+
* }
|
|
2206
|
+
* }
|
|
2207
|
+
* ```
|
|
2208
|
+
*/
|
|
2209
|
+
endProcessStream(processId: string): AsyncGenerator<TxStatusEvent<{
|
|
2210
|
+
success: boolean;
|
|
2211
|
+
}>, any, any>;
|
|
2212
|
+
/**
|
|
2213
|
+
* Ends a voting process by setting its status to ENDED.
|
|
2214
|
+
* This is the simplified method that waits for transaction completion.
|
|
2215
|
+
*
|
|
2216
|
+
* For real-time transaction status updates, use endProcessStream() instead.
|
|
2217
|
+
*
|
|
2218
|
+
* Requires a signer with a provider for blockchain interactions.
|
|
2219
|
+
*
|
|
2220
|
+
* @param processId - The process ID to end
|
|
2221
|
+
* @returns Promise resolving when the process is ended
|
|
2222
|
+
* @throws Error if signer does not have a provider
|
|
2223
|
+
*
|
|
2224
|
+
* @example
|
|
2225
|
+
* ```typescript
|
|
2226
|
+
* await sdk.endProcess("0x1234567890abcdef...");
|
|
2227
|
+
* console.log("Process ended successfully");
|
|
2228
|
+
* ```
|
|
2229
|
+
*/
|
|
2230
|
+
endProcess(processId: string): Promise<void>;
|
|
2231
|
+
/**
|
|
2232
|
+
* Pauses a voting process by setting its status to PAUSED and returns an async generator
|
|
2233
|
+
* that yields transaction status events. This method allows you to monitor the
|
|
2234
|
+
* transaction progress in real-time.
|
|
2235
|
+
*
|
|
2236
|
+
* Requires a signer with a provider for blockchain interactions.
|
|
2237
|
+
*
|
|
2238
|
+
* @param processId - The process ID to pause
|
|
2239
|
+
* @returns AsyncGenerator yielding transaction status events
|
|
2240
|
+
* @throws Error if signer does not have a provider
|
|
2241
|
+
*
|
|
2242
|
+
* @example
|
|
2243
|
+
* ```typescript
|
|
2244
|
+
* const stream = sdk.pauseProcessStream("0x1234567890abcdef...");
|
|
2245
|
+
*
|
|
2246
|
+
* for await (const event of stream) {
|
|
2247
|
+
* switch (event.status) {
|
|
2248
|
+
* case TxStatus.Pending:
|
|
2249
|
+
* console.log("Transaction pending:", event.hash);
|
|
2250
|
+
* break;
|
|
2251
|
+
* case TxStatus.Completed:
|
|
2252
|
+
* console.log("Process paused successfully");
|
|
2253
|
+
* break;
|
|
2254
|
+
* case TxStatus.Failed:
|
|
2255
|
+
* console.error("Transaction failed:", event.error);
|
|
2256
|
+
* break;
|
|
2257
|
+
* case TxStatus.Reverted:
|
|
2258
|
+
* console.error("Transaction reverted:", event.reason);
|
|
2259
|
+
* break;
|
|
2260
|
+
* }
|
|
2261
|
+
* }
|
|
2262
|
+
* ```
|
|
2263
|
+
*/
|
|
2264
|
+
pauseProcessStream(processId: string): AsyncGenerator<TxStatusEvent<{
|
|
2265
|
+
success: boolean;
|
|
2266
|
+
}>, any, any>;
|
|
2267
|
+
/**
|
|
2268
|
+
* Pauses a voting process by setting its status to PAUSED.
|
|
2269
|
+
* This is the simplified method that waits for transaction completion.
|
|
2270
|
+
*
|
|
2271
|
+
* For real-time transaction status updates, use pauseProcessStream() instead.
|
|
2272
|
+
*
|
|
2273
|
+
* Requires a signer with a provider for blockchain interactions.
|
|
2274
|
+
*
|
|
2275
|
+
* @param processId - The process ID to pause
|
|
2276
|
+
* @returns Promise resolving when the process is paused
|
|
2277
|
+
* @throws Error if signer does not have a provider
|
|
2278
|
+
*
|
|
2279
|
+
* @example
|
|
2280
|
+
* ```typescript
|
|
2281
|
+
* await sdk.pauseProcess("0x1234567890abcdef...");
|
|
2282
|
+
* console.log("Process paused successfully");
|
|
2283
|
+
* ```
|
|
2284
|
+
*/
|
|
2285
|
+
pauseProcess(processId: string): Promise<void>;
|
|
2286
|
+
/**
|
|
2287
|
+
* Cancels a voting process by setting its status to CANCELED and returns an async generator
|
|
2288
|
+
* that yields transaction status events. This method allows you to monitor the
|
|
2289
|
+
* transaction progress in real-time.
|
|
2290
|
+
*
|
|
2291
|
+
* Requires a signer with a provider for blockchain interactions.
|
|
2292
|
+
*
|
|
2293
|
+
* @param processId - The process ID to cancel
|
|
2294
|
+
* @returns AsyncGenerator yielding transaction status events
|
|
2295
|
+
* @throws Error if signer does not have a provider
|
|
2296
|
+
*
|
|
2297
|
+
* @example
|
|
2298
|
+
* ```typescript
|
|
2299
|
+
* const stream = sdk.cancelProcessStream("0x1234567890abcdef...");
|
|
2300
|
+
*
|
|
2301
|
+
* for await (const event of stream) {
|
|
2302
|
+
* switch (event.status) {
|
|
2303
|
+
* case TxStatus.Pending:
|
|
2304
|
+
* console.log("Transaction pending:", event.hash);
|
|
2305
|
+
* break;
|
|
2306
|
+
* case TxStatus.Completed:
|
|
2307
|
+
* console.log("Process canceled successfully");
|
|
2308
|
+
* break;
|
|
2309
|
+
* case TxStatus.Failed:
|
|
2310
|
+
* console.error("Transaction failed:", event.error);
|
|
2311
|
+
* break;
|
|
2312
|
+
* case TxStatus.Reverted:
|
|
2313
|
+
* console.error("Transaction reverted:", event.reason);
|
|
2314
|
+
* break;
|
|
2315
|
+
* }
|
|
2316
|
+
* }
|
|
2317
|
+
* ```
|
|
2318
|
+
*/
|
|
2319
|
+
cancelProcessStream(processId: string): AsyncGenerator<TxStatusEvent<{
|
|
2320
|
+
success: boolean;
|
|
2321
|
+
}>, any, any>;
|
|
2322
|
+
/**
|
|
2323
|
+
* Cancels a voting process by setting its status to CANCELED.
|
|
2324
|
+
* This is the simplified method that waits for transaction completion.
|
|
2325
|
+
*
|
|
2326
|
+
* For real-time transaction status updates, use cancelProcessStream() instead.
|
|
2327
|
+
*
|
|
2328
|
+
* Requires a signer with a provider for blockchain interactions.
|
|
2329
|
+
*
|
|
2330
|
+
* @param processId - The process ID to cancel
|
|
2331
|
+
* @returns Promise resolving when the process is canceled
|
|
2332
|
+
* @throws Error if signer does not have a provider
|
|
2333
|
+
*
|
|
2334
|
+
* @example
|
|
2335
|
+
* ```typescript
|
|
2336
|
+
* await sdk.cancelProcess("0x1234567890abcdef...");
|
|
2337
|
+
* console.log("Process canceled successfully");
|
|
2338
|
+
* ```
|
|
2339
|
+
*/
|
|
2340
|
+
cancelProcess(processId: string): Promise<void>;
|
|
2341
|
+
/**
|
|
2342
|
+
* Resumes a voting process by setting its status to READY and returns an async generator
|
|
2343
|
+
* that yields transaction status events. This is typically used to resume a paused process.
|
|
2344
|
+
*
|
|
2345
|
+
* Requires a signer with a provider for blockchain interactions.
|
|
2346
|
+
*
|
|
2347
|
+
* @param processId - The process ID to resume
|
|
2348
|
+
* @returns AsyncGenerator yielding transaction status events
|
|
2349
|
+
* @throws Error if signer does not have a provider
|
|
2350
|
+
*
|
|
2351
|
+
* @example
|
|
2352
|
+
* ```typescript
|
|
2353
|
+
* const stream = sdk.resumeProcessStream("0x1234567890abcdef...");
|
|
2354
|
+
*
|
|
2355
|
+
* for await (const event of stream) {
|
|
2356
|
+
* switch (event.status) {
|
|
2357
|
+
* case TxStatus.Pending:
|
|
2358
|
+
* console.log("Transaction pending:", event.hash);
|
|
2359
|
+
* break;
|
|
2360
|
+
* case TxStatus.Completed:
|
|
2361
|
+
* console.log("Process resumed successfully");
|
|
2362
|
+
* break;
|
|
2363
|
+
* case TxStatus.Failed:
|
|
2364
|
+
* console.error("Transaction failed:", event.error);
|
|
2365
|
+
* break;
|
|
2366
|
+
* case TxStatus.Reverted:
|
|
2367
|
+
* console.error("Transaction reverted:", event.reason);
|
|
2368
|
+
* break;
|
|
2369
|
+
* }
|
|
2370
|
+
* }
|
|
2371
|
+
* ```
|
|
2372
|
+
*/
|
|
2373
|
+
resumeProcessStream(processId: string): AsyncGenerator<TxStatusEvent<{
|
|
2374
|
+
success: boolean;
|
|
2375
|
+
}>, any, any>;
|
|
2376
|
+
/**
|
|
2377
|
+
* Resumes a voting process by setting its status to READY.
|
|
2378
|
+
* This is typically used to resume a paused process.
|
|
2379
|
+
* This is the simplified method that waits for transaction completion.
|
|
2380
|
+
*
|
|
2381
|
+
* For real-time transaction status updates, use resumeProcessStream() instead.
|
|
2382
|
+
*
|
|
2383
|
+
* Requires a signer with a provider for blockchain interactions.
|
|
2384
|
+
*
|
|
2385
|
+
* @param processId - The process ID to resume
|
|
2386
|
+
* @returns Promise resolving when the process is resumed
|
|
2387
|
+
* @throws Error if signer does not have a provider
|
|
2388
|
+
*
|
|
2389
|
+
* @example
|
|
2390
|
+
* ```typescript
|
|
2391
|
+
* await sdk.resumeProcess("0x1234567890abcdef...");
|
|
2392
|
+
* console.log("Process resumed successfully");
|
|
2393
|
+
* ```
|
|
2394
|
+
*/
|
|
2395
|
+
resumeProcess(processId: string): Promise<void>;
|
|
2396
|
+
/**
|
|
2397
|
+
* Resolve contract address based on configuration priority:
|
|
2398
|
+
* 1. If useSequencerAddresses is true: addresses from sequencer (highest priority)
|
|
2399
|
+
* 2. Custom addresses from config (if provided by user)
|
|
2400
|
+
* 3. Default deployed addresses from npm package
|
|
2401
|
+
*/
|
|
2402
|
+
private resolveContractAddress;
|
|
2403
|
+
/**
|
|
2404
|
+
* Get default contract address from deployed addresses
|
|
2405
|
+
*/
|
|
2406
|
+
private getDefaultContractAddress;
|
|
2407
|
+
/**
|
|
2408
|
+
* Update contract addresses from sequencer info if useSequencerAddresses is enabled
|
|
2409
|
+
* Sequencer addresses have priority over user-provided addresses
|
|
2410
|
+
*/
|
|
2411
|
+
private updateContractAddressesFromSequencer;
|
|
2412
|
+
/**
|
|
2413
|
+
* Get the current configuration
|
|
2414
|
+
*/
|
|
2415
|
+
getConfig(): Readonly<InternalDavinciSDKConfig>;
|
|
2416
|
+
/**
|
|
2417
|
+
* Check if the SDK has been initialized
|
|
2418
|
+
*/
|
|
2419
|
+
isInitialized(): boolean;
|
|
2420
|
+
/**
|
|
2421
|
+
* Ensures that the signer has a provider for blockchain operations.
|
|
2422
|
+
* @throws Error if the signer does not have a provider
|
|
2423
|
+
* @private
|
|
2424
|
+
*/
|
|
2425
|
+
private ensureProvider;
|
|
2426
|
+
}
|
|
2427
|
+
|
|
2428
|
+
export { BaseService, CensusOrigin, CircomProof, ContractServiceError, DEFAULT_ENVIRONMENT_URLS, DavinciCrypto, DavinciSDK, ElectionMetadataTemplate, ElectionResultsTypeNames, OrganizationAdministratorError, OrganizationCreateError, OrganizationDeleteError, OrganizationRegistryService, OrganizationUpdateError, ProcessCensusError, ProcessCreateError, ProcessDurationError, ProcessOrchestrationService, ProcessRegistryService, ProcessResultError, ProcessStateTransitionError, ProcessStatus, ProcessStatusError, SmartContractService, TxStatus, VocdoniApiService, VocdoniCensusService, VocdoniSequencerService, VoteOrchestrationService, VoteStatus, assertCSPCensusProof, assertMerkleCensusProof, createProcessSignatureMessage, deployedAddresses, getElectionMetadataTemplate, getEnvironmentChain, getEnvironmentConfig, getEnvironmentUrls, isCSPCensusProof, isMerkleCensusProof, resolveConfiguration, resolveUrls, signProcessCreation, validateProcessId };
|
|
2429
|
+
export type { AbstainProperties, AnyJson, ApiError, ApprovalProperties, BallotMode, BaseCensusProof, BaseProcess, BudgetProperties, CSPCensusProof, CSPCensusProofProvider, CSPSignOutput, Census, CensusParticipant, CensusProof, CensusProviders, CensusSizeResponse, ChainConfig, Choice, ChoiceProperties, CircomProofOptions, CreateProcessRequest, CreateProcessResponse, CustomMeta, DavinciCryptoCiphertext, DavinciCryptoInputs, DavinciCryptoOptions, DavinciCryptoOutput, DavinciSDKConfig, DeployedAddresses, ElectionMetadata, ElectionResultsType, EncryptionKey, EntityCallback, Environment, EnvironmentConfig, EnvironmentOptions, GetProcessResponse, Groth16Proof, HealthResponse, IChoice, IQuestion, InfoResponse, JsonArray, JsonMap, ListProcessesResponse, MerkleCensusProof, MerkleCensusProofProvider, MultiLanguage, OrganizationAdministratorAddedCallback, OrganizationAdministratorRemovedCallback, OrganizationCreatedCallback, OrganizationInfo, OrganizationUpdatedCallback, ProcessCensusUpdatedCallback, ProcessConfig, ProcessCreatedCallback, ProcessCreationResult, ProcessDurationChangedCallback, ProcessInfo, ProcessResultsSetCallback, ProcessStateRootUpdatedCallback, ProcessStatusChangedCallback, ProofInputs, ProtocolVersion, PublishCensusResponse, QuadraticProperties, Question, SequencerStats, ServiceUrls, Snapshot, SnapshotsQueryParams, SnapshotsResponse, TxStatusEvent, VocdoniApiServiceConfig, VoteBallot, VoteCiphertext, VoteConfig, VoteProof, VoteRequest, VoteResult, VoteStatusInfo, VoteStatusResponse, WorkerStats, WorkersResponse };
|