@vocdoni/davinci-sdk 0.0.2 → 0.0.4
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 +272 -42
- package/dist/contracts.d.ts +13 -58
- package/dist/index.d.ts +314 -179
- package/dist/index.js +630 -357
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +624 -351
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +3176 -2903
- package/dist/sequencer.d.ts +21 -15
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -113,7 +113,7 @@ declare enum CensusOrigin {
|
|
|
113
113
|
/** Indicates that the census is provided by a Credential Service Provider (CSP) */
|
|
114
114
|
CensusOriginCSP = 2
|
|
115
115
|
}
|
|
116
|
-
interface CensusParticipant {
|
|
116
|
+
interface CensusParticipant$1 {
|
|
117
117
|
key: string;
|
|
118
118
|
weight?: string;
|
|
119
119
|
}
|
|
@@ -194,6 +194,8 @@ interface PublishCensusResponse {
|
|
|
194
194
|
publishedAt: string;
|
|
195
195
|
/** The constructed URI for accessing the census */
|
|
196
196
|
uri: string;
|
|
197
|
+
/** The size of the census. */
|
|
198
|
+
size: number;
|
|
197
199
|
}
|
|
198
200
|
interface Snapshot {
|
|
199
201
|
/** ISO timestamp of the snapshot date. */
|
|
@@ -263,14 +265,14 @@ interface HealthResponse {
|
|
|
263
265
|
declare class VocdoniCensusService extends BaseService {
|
|
264
266
|
constructor(baseURL: string);
|
|
265
267
|
/**
|
|
266
|
-
* Constructs the URI for accessing a census
|
|
267
|
-
* @param
|
|
268
|
+
* Constructs the URI for accessing a census
|
|
269
|
+
* @param relativePath - The relative path
|
|
268
270
|
* @returns The constructed URI for the census
|
|
269
271
|
*/
|
|
270
|
-
getCensusUri(
|
|
272
|
+
getCensusUri(relativePath: string): string;
|
|
271
273
|
createCensus(): Promise<string>;
|
|
272
|
-
addParticipants(censusId: string, participants: CensusParticipant[]): Promise<void>;
|
|
273
|
-
getParticipants(censusId: string): Promise<CensusParticipant[]>;
|
|
274
|
+
addParticipants(censusId: string, participants: CensusParticipant$1[]): Promise<void>;
|
|
275
|
+
getParticipants(censusId: string): Promise<CensusParticipant$1[]>;
|
|
274
276
|
getCensusRoot(censusId: string): Promise<string>;
|
|
275
277
|
getCensusSizeById(censusId: string): Promise<number>;
|
|
276
278
|
getCensusSizeByRoot(censusRoot: string): Promise<number>;
|
|
@@ -283,6 +285,168 @@ declare class VocdoniCensusService extends BaseService {
|
|
|
283
285
|
getHealth(): Promise<HealthResponse>;
|
|
284
286
|
}
|
|
285
287
|
|
|
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
|
+
/**
|
|
304
|
+
* Abstract base class for all census types
|
|
305
|
+
*/
|
|
306
|
+
declare abstract class Census {
|
|
307
|
+
protected _censusId: string | null;
|
|
308
|
+
protected _censusRoot: string | null;
|
|
309
|
+
protected _censusURI: string | null;
|
|
310
|
+
protected _type: CensusType;
|
|
311
|
+
protected _size: number | null;
|
|
312
|
+
constructor(type: CensusType);
|
|
313
|
+
get censusId(): string | null;
|
|
314
|
+
get censusRoot(): string | null;
|
|
315
|
+
get censusURI(): string | null;
|
|
316
|
+
get type(): CensusType;
|
|
317
|
+
get size(): number | null;
|
|
318
|
+
get isPublished(): boolean;
|
|
319
|
+
/**
|
|
320
|
+
* Convert CensusType to CensusOrigin enum for API compatibility
|
|
321
|
+
*/
|
|
322
|
+
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
|
+
/**
|
|
347
|
+
* Get addresses only
|
|
348
|
+
*/
|
|
349
|
+
get addresses(): string[];
|
|
350
|
+
private validateAddress;
|
|
351
|
+
/**
|
|
352
|
+
* Internal method called after publishing
|
|
353
|
+
* @internal
|
|
354
|
+
*/
|
|
355
|
+
_setPublishedData(root: string, uri: string, size: number, censusId?: string): void;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Participant with flexible weight type for WeightedCensus
|
|
360
|
+
* Weight can be string, number, or bigint - will be normalized to string internally
|
|
361
|
+
*/
|
|
362
|
+
interface WeightedParticipant {
|
|
363
|
+
key: string;
|
|
364
|
+
weight: string | number | bigint;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Weighted census where participants can have different voting power
|
|
368
|
+
* Requires specifying weight for each participant
|
|
369
|
+
*/
|
|
370
|
+
declare class WeightedCensus extends Census {
|
|
371
|
+
private _participants;
|
|
372
|
+
constructor();
|
|
373
|
+
/**
|
|
374
|
+
* Add participant(s) with custom weights
|
|
375
|
+
* Weight can be provided as string, number, or bigint - will be converted to string internally
|
|
376
|
+
* @param participant - Single participant or array of participants with custom weights
|
|
377
|
+
*/
|
|
378
|
+
add(participant: WeightedParticipant | WeightedParticipant[]): void;
|
|
379
|
+
/**
|
|
380
|
+
* Remove participant by address
|
|
381
|
+
*/
|
|
382
|
+
remove(address: string): void;
|
|
383
|
+
/**
|
|
384
|
+
* Get all participants as CensusParticipant array
|
|
385
|
+
*/
|
|
386
|
+
get participants(): CensusParticipant[];
|
|
387
|
+
/**
|
|
388
|
+
* Get participant addresses
|
|
389
|
+
*/
|
|
390
|
+
get addresses(): string[];
|
|
391
|
+
/**
|
|
392
|
+
* Get weight for specific address
|
|
393
|
+
*/
|
|
394
|
+
getWeight(address: string): string | undefined;
|
|
395
|
+
/**
|
|
396
|
+
* Normalizes weight from string, number, or bigint to string
|
|
397
|
+
*/
|
|
398
|
+
private normalizeWeight;
|
|
399
|
+
private validateParticipant;
|
|
400
|
+
/**
|
|
401
|
+
* Internal method called after publishing
|
|
402
|
+
* @internal
|
|
403
|
+
*/
|
|
404
|
+
_setPublishedData(root: string, uri: string, size: number, censusId?: string): void;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* CSP (Certificate Service Provider) census
|
|
409
|
+
* Uses a public key and CSP server URI instead of a participant list
|
|
410
|
+
*/
|
|
411
|
+
declare class CspCensus extends Census {
|
|
412
|
+
private _publicKey;
|
|
413
|
+
private _cspURI;
|
|
414
|
+
constructor(publicKey: string, cspURI: string, size: number);
|
|
415
|
+
get publicKey(): string;
|
|
416
|
+
get cspURI(): string;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Published census - represents a census that has already been published
|
|
421
|
+
* Use this when you have the census root, URI, and size from a previous publication
|
|
422
|
+
*/
|
|
423
|
+
declare class PublishedCensus extends Census {
|
|
424
|
+
constructor(type: CensusType, root: string, uri: string, size: number);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Orchestrates census creation and publishing
|
|
429
|
+
*/
|
|
430
|
+
declare class CensusOrchestrator {
|
|
431
|
+
private censusService;
|
|
432
|
+
constructor(censusService: VocdoniCensusService);
|
|
433
|
+
/**
|
|
434
|
+
* Publishes a PlainCensus or WeightedCensus
|
|
435
|
+
* Creates a working census, adds participants, and publishes it
|
|
436
|
+
*/
|
|
437
|
+
publish(census: PlainCensus | WeightedCensus): Promise<void>;
|
|
438
|
+
/**
|
|
439
|
+
* Gets census data for process creation
|
|
440
|
+
* Throws if census is not published
|
|
441
|
+
*/
|
|
442
|
+
getCensusData(census: Census): {
|
|
443
|
+
type: CensusOrigin;
|
|
444
|
+
root: string;
|
|
445
|
+
uri: string;
|
|
446
|
+
size: number;
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
|
|
286
450
|
interface BallotMode {
|
|
287
451
|
numFields: number;
|
|
288
452
|
maxValue: string;
|
|
@@ -293,9 +457,8 @@ interface BallotMode {
|
|
|
293
457
|
maxValueSum: string;
|
|
294
458
|
minValueSum: string;
|
|
295
459
|
}
|
|
296
|
-
interface
|
|
460
|
+
interface CensusData {
|
|
297
461
|
censusOrigin: CensusOrigin;
|
|
298
|
-
maxVotes: string;
|
|
299
462
|
censusRoot: string;
|
|
300
463
|
censusURI: string;
|
|
301
464
|
}
|
|
@@ -306,14 +469,13 @@ interface EncryptionKey {
|
|
|
306
469
|
|
|
307
470
|
interface CreateProcessRequest {
|
|
308
471
|
processId: string;
|
|
309
|
-
|
|
472
|
+
census: {
|
|
473
|
+
censusOrigin: CensusOrigin;
|
|
474
|
+
censusRoot: string;
|
|
475
|
+
censusURI: string;
|
|
476
|
+
};
|
|
310
477
|
ballotMode: BallotMode;
|
|
311
478
|
signature: string;
|
|
312
|
-
/**
|
|
313
|
-
* The censusOrigin specifies the origin type of the census used in the request.
|
|
314
|
-
* This attribute allows the API to determine how the census data should be processed or verified.
|
|
315
|
-
*/
|
|
316
|
-
censusOrigin: CensusOrigin;
|
|
317
479
|
}
|
|
318
480
|
interface CreateProcessResponse {
|
|
319
481
|
processId: string;
|
|
@@ -332,7 +494,7 @@ interface GetProcessResponse {
|
|
|
332
494
|
duration: number;
|
|
333
495
|
metadataURI: string;
|
|
334
496
|
ballotMode: BallotMode;
|
|
335
|
-
census:
|
|
497
|
+
census: CensusData;
|
|
336
498
|
metadata: {
|
|
337
499
|
title: Record<string, string>;
|
|
338
500
|
description: Record<string, string>;
|
|
@@ -386,8 +548,8 @@ interface VoteProof {
|
|
|
386
548
|
interface VoteRequest {
|
|
387
549
|
/** The `processId` you obtained when creating the process. */
|
|
388
550
|
processId: string;
|
|
389
|
-
/** Your
|
|
390
|
-
censusProof
|
|
551
|
+
/** Your census proof (only required for CSP, not for MerkleTree). */
|
|
552
|
+
censusProof?: CensusProof;
|
|
391
553
|
/** Your encrypted ballot. */
|
|
392
554
|
ballot: VoteBallot;
|
|
393
555
|
/** The zkSNARK proof that the ballot is well‐formed. */
|
|
@@ -453,6 +615,10 @@ interface WorkerStats {
|
|
|
453
615
|
interface WorkersResponse {
|
|
454
616
|
workers: WorkerStats[];
|
|
455
617
|
}
|
|
618
|
+
interface ParticipantInfoResponse {
|
|
619
|
+
key: string;
|
|
620
|
+
weight: string;
|
|
621
|
+
}
|
|
456
622
|
|
|
457
623
|
declare class VocdoniSequencerService extends BaseService {
|
|
458
624
|
constructor(baseURL: string);
|
|
@@ -463,6 +629,7 @@ declare class VocdoniSequencerService extends BaseService {
|
|
|
463
629
|
submitVote(vote: VoteRequest): Promise<void>;
|
|
464
630
|
getVoteStatus(processId: string, voteId: string): Promise<VoteStatusResponse>;
|
|
465
631
|
hasAddressVoted(processId: string, address: string): Promise<boolean>;
|
|
632
|
+
isAddressAbleToVote(processId: string, address: string): Promise<ParticipantInfoResponse>;
|
|
466
633
|
getInfo(): Promise<InfoResponse>;
|
|
467
634
|
pushMetadata(metadata: ElectionMetadata): Promise<string>;
|
|
468
635
|
getMetadata(hashOrUrl: string): Promise<ElectionMetadata>;
|
|
@@ -481,118 +648,6 @@ declare class VocdoniApiService {
|
|
|
481
648
|
constructor(config: VocdoniApiServiceConfig);
|
|
482
649
|
}
|
|
483
650
|
|
|
484
|
-
/**
|
|
485
|
-
* Supported environment types
|
|
486
|
-
*/
|
|
487
|
-
type Environment = 'dev' | 'stg' | 'prod';
|
|
488
|
-
/**
|
|
489
|
-
* URL configuration for each service
|
|
490
|
-
*/
|
|
491
|
-
interface ServiceUrls {
|
|
492
|
-
/** Sequencer API URL */
|
|
493
|
-
sequencer: string;
|
|
494
|
-
/** Census API URL */
|
|
495
|
-
census: string;
|
|
496
|
-
}
|
|
497
|
-
/**
|
|
498
|
-
* Chain configuration for each environment
|
|
499
|
-
*/
|
|
500
|
-
interface ChainConfig {
|
|
501
|
-
/** Chain name/ID */
|
|
502
|
-
chain: 'sepolia' | 'mainnet';
|
|
503
|
-
}
|
|
504
|
-
/**
|
|
505
|
-
* Environment-based URL configuration
|
|
506
|
-
*/
|
|
507
|
-
interface EnvironmentConfig {
|
|
508
|
-
dev: ServiceUrls & ChainConfig;
|
|
509
|
-
stg: ServiceUrls & ChainConfig;
|
|
510
|
-
prod: ServiceUrls & ChainConfig;
|
|
511
|
-
}
|
|
512
|
-
/**
|
|
513
|
-
* Configuration options for environment setup
|
|
514
|
-
*/
|
|
515
|
-
interface EnvironmentOptions {
|
|
516
|
-
/** Environment to use (defaults to 'prod') */
|
|
517
|
-
environment?: Environment;
|
|
518
|
-
/** Custom URLs to override defaults */
|
|
519
|
-
customUrls?: Partial<ServiceUrls>;
|
|
520
|
-
/** Custom chain to override default */
|
|
521
|
-
customChain?: ChainConfig['chain'];
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
/**
|
|
525
|
-
* Default URL and chain configuration for all environments
|
|
526
|
-
*/
|
|
527
|
-
declare const DEFAULT_ENVIRONMENT_URLS: EnvironmentConfig;
|
|
528
|
-
/**
|
|
529
|
-
* Get URLs and chain configuration for a specific environment
|
|
530
|
-
*/
|
|
531
|
-
declare function getEnvironmentConfig(environment: Environment): ServiceUrls & ChainConfig;
|
|
532
|
-
/**
|
|
533
|
-
* Get only URLs for a specific environment
|
|
534
|
-
*/
|
|
535
|
-
declare function getEnvironmentUrls(environment: Environment): ServiceUrls;
|
|
536
|
-
/**
|
|
537
|
-
* Get chain configuration for a specific environment
|
|
538
|
-
*/
|
|
539
|
-
declare function getEnvironmentChain(environment: Environment): ChainConfig['chain'];
|
|
540
|
-
/**
|
|
541
|
-
* Resolve URLs and chain based on environment and custom overrides
|
|
542
|
-
*/
|
|
543
|
-
declare function resolveConfiguration(options?: EnvironmentOptions): ServiceUrls & ChainConfig;
|
|
544
|
-
/**
|
|
545
|
-
* Resolve only URLs based on environment and custom overrides
|
|
546
|
-
*/
|
|
547
|
-
declare function resolveUrls(options?: EnvironmentOptions): ServiceUrls;
|
|
548
|
-
|
|
549
|
-
/**
|
|
550
|
-
* Interface defining the structure of deployed contract addresses across different networks.
|
|
551
|
-
* Each contract has addresses for both Sepolia testnet and Ethereum mainnet.
|
|
552
|
-
*/
|
|
553
|
-
interface DeployedAddresses {
|
|
554
|
-
/** Process Registry contract addresses */
|
|
555
|
-
processRegistry: {
|
|
556
|
-
/** Sepolia testnet address */
|
|
557
|
-
sepolia: string;
|
|
558
|
-
/** Ethereum mainnet address */
|
|
559
|
-
mainnet: string;
|
|
560
|
-
};
|
|
561
|
-
/** Organization Registry contract addresses */
|
|
562
|
-
organizationRegistry: {
|
|
563
|
-
/** Sepolia testnet address */
|
|
564
|
-
sepolia: string;
|
|
565
|
-
/** Ethereum mainnet address */
|
|
566
|
-
mainnet: string;
|
|
567
|
-
};
|
|
568
|
-
/** State Transition Verifier contract addresses */
|
|
569
|
-
stateTransitionVerifierGroth16: {
|
|
570
|
-
/** Sepolia testnet address */
|
|
571
|
-
sepolia: string;
|
|
572
|
-
/** Ethereum mainnet address */
|
|
573
|
-
mainnet: string;
|
|
574
|
-
};
|
|
575
|
-
/** Results Verifier contract addresses */
|
|
576
|
-
resultsVerifierGroth16: {
|
|
577
|
-
/** Sepolia testnet address */
|
|
578
|
-
sepolia: string;
|
|
579
|
-
/** Ethereum mainnet address */
|
|
580
|
-
mainnet: string;
|
|
581
|
-
};
|
|
582
|
-
/** Sequencer Registry contract addresses */
|
|
583
|
-
sequencerRegistry: {
|
|
584
|
-
/** Sepolia testnet address */
|
|
585
|
-
sepolia: string;
|
|
586
|
-
/** Ethereum mainnet address */
|
|
587
|
-
mainnet: string;
|
|
588
|
-
};
|
|
589
|
-
}
|
|
590
|
-
/**
|
|
591
|
-
* Deployed contract addresses imported from @vocdoni/davinci-contracts package.
|
|
592
|
-
* These addresses are used to interact with the Vocdoni voting protocol contracts
|
|
593
|
-
* on different networks.
|
|
594
|
-
*/
|
|
595
|
-
declare const deployedAddresses: DeployedAddresses;
|
|
596
651
|
/**
|
|
597
652
|
* Enum representing the possible states of a transaction during its lifecycle.
|
|
598
653
|
* Used to track and report transaction status in the event stream.
|
|
@@ -729,10 +784,13 @@ declare abstract class SmartContractService {
|
|
|
729
784
|
*/
|
|
730
785
|
protected setupEventListener<Args extends any[]>(contract: BaseContract, eventFilter: ContractEventName | EventFilter, callback: (...args: Args) => void): Promise<void>;
|
|
731
786
|
/**
|
|
732
|
-
* Checks if an error indicates that the RPC method is unsupported
|
|
787
|
+
* Checks if an error indicates that the RPC method is unsupported or filter operations are not working.
|
|
788
|
+
* This includes:
|
|
789
|
+
* - Method not found (-32601): RPC doesn't support eth_newFilter
|
|
790
|
+
* - Filter not found (-32000): RPC doesn't properly maintain filters
|
|
733
791
|
*
|
|
734
792
|
* @param error - The error to check
|
|
735
|
-
* @returns true if the error indicates unsupported
|
|
793
|
+
* @returns true if the error indicates unsupported or broken filter functionality
|
|
736
794
|
*/
|
|
737
795
|
private isUnsupportedMethodError;
|
|
738
796
|
/**
|
|
@@ -811,9 +869,8 @@ type ProcessStatusChangedCallback = EntityCallback<[string, bigint, bigint]>;
|
|
|
811
869
|
* @param processID - The process ID
|
|
812
870
|
* @param root - The new census root
|
|
813
871
|
* @param uri - The new census URI
|
|
814
|
-
* @param maxVotes - The maximum number of votes
|
|
815
872
|
*/
|
|
816
|
-
type ProcessCensusUpdatedCallback = EntityCallback<[string, string, string
|
|
873
|
+
type ProcessCensusUpdatedCallback = EntityCallback<[string, string, string]>;
|
|
817
874
|
/**
|
|
818
875
|
* Callback for when a process duration changes.
|
|
819
876
|
* @param processID - The process ID
|
|
@@ -872,13 +929,13 @@ declare class ProcessRegistryService extends SmartContractService {
|
|
|
872
929
|
}>;
|
|
873
930
|
getRVerifier(): Promise<string>;
|
|
874
931
|
getSTVerifier(): Promise<string>;
|
|
875
|
-
newProcess(status: ProcessStatus, startTime: number, duration: number, ballotMode: BallotMode, census:
|
|
932
|
+
newProcess(status: ProcessStatus, startTime: number, duration: number, ballotMode: BallotMode, census: CensusData, metadata: string, encryptionKey: EncryptionKey, initStateRoot: bigint): AsyncGenerator<TxStatusEvent<{
|
|
876
933
|
success: boolean;
|
|
877
934
|
}>, void, unknown>;
|
|
878
935
|
setProcessStatus(processID: string, newStatus: ProcessStatus): AsyncGenerator<TxStatusEvent<{
|
|
879
936
|
success: boolean;
|
|
880
937
|
}>, void, unknown>;
|
|
881
|
-
setProcessCensus(processID: string, census:
|
|
938
|
+
setProcessCensus(processID: string, census: CensusData): AsyncGenerator<TxStatusEvent<{
|
|
882
939
|
success: boolean;
|
|
883
940
|
}>, void, unknown>;
|
|
884
941
|
setProcessDuration(processID: string, duration: number): AsyncGenerator<TxStatusEvent<{
|
|
@@ -1041,6 +1098,7 @@ interface CSPSignOutput {
|
|
|
1041
1098
|
censusOrigin: CensusOrigin;
|
|
1042
1099
|
root: string;
|
|
1043
1100
|
address: string;
|
|
1101
|
+
weight: string;
|
|
1044
1102
|
processId: string;
|
|
1045
1103
|
publicKey: string;
|
|
1046
1104
|
signature: string;
|
|
@@ -1051,7 +1109,7 @@ interface RawResult<T = any> {
|
|
|
1051
1109
|
}
|
|
1052
1110
|
interface GoDavinciCryptoWasm {
|
|
1053
1111
|
proofInputs(inputJson: string): RawResult<DavinciCryptoOutput>;
|
|
1054
|
-
cspSign(censusOrigin: number, privKey: string, processId: string, address: string): RawResult<CSPSignOutput>;
|
|
1112
|
+
cspSign(censusOrigin: number, privKey: string, processId: string, address: string, weight: string): RawResult<CSPSignOutput>;
|
|
1055
1113
|
cspVerify(cspProof: string): RawResult<boolean>;
|
|
1056
1114
|
cspCensusRoot(censusOrigin: number, privKey: string): RawResult<{
|
|
1057
1115
|
root: string;
|
|
@@ -1111,22 +1169,24 @@ declare class DavinciCrypto {
|
|
|
1111
1169
|
* @param privKey - The private key in hex format
|
|
1112
1170
|
* @param processId - The process ID in hex format
|
|
1113
1171
|
* @param address - The address in hex format
|
|
1172
|
+
* @param weight - The vote weight as a decimal string
|
|
1114
1173
|
* @returns The CSP proof as a parsed JSON object
|
|
1115
1174
|
* @throws if called before `await init()`, or if Go returns an error
|
|
1116
1175
|
*/
|
|
1117
|
-
cspSign(censusOrigin: CensusOrigin, privKey: string, processId: string, address: string): Promise<CSPSignOutput>;
|
|
1176
|
+
cspSign(censusOrigin: CensusOrigin, privKey: string, processId: string, address: string, weight: string): Promise<CSPSignOutput>;
|
|
1118
1177
|
/**
|
|
1119
1178
|
* Verify a CSP (Credential Service Provider) proof.
|
|
1120
1179
|
* @param censusOrigin - The census origin type (e.g., CensusOrigin.CensusOriginCSP)
|
|
1121
1180
|
* @param root - The census root
|
|
1122
1181
|
* @param address - The address
|
|
1182
|
+
* @param weight - The vote weight as a decimal string
|
|
1123
1183
|
* @param processId - The process ID
|
|
1124
1184
|
* @param publicKey - The public key
|
|
1125
1185
|
* @param signature - The signature
|
|
1126
1186
|
* @returns The verification result
|
|
1127
1187
|
* @throws if called before `await init()`, or if Go returns an error
|
|
1128
1188
|
*/
|
|
1129
|
-
cspVerify(censusOrigin: CensusOrigin, root: string, address: string, processId: string, publicKey: string, signature: string): Promise<boolean>;
|
|
1189
|
+
cspVerify(censusOrigin: CensusOrigin, root: string, address: string, weight: string, processId: string, publicKey: string, signature: string): Promise<boolean>;
|
|
1130
1190
|
/**
|
|
1131
1191
|
* Generate a CSP (Credential Service Provider) census root.
|
|
1132
1192
|
* @param censusOrigin - The census origin type (e.g., CensusOrigin.CensusOriginCSP)
|
|
@@ -1151,27 +1211,46 @@ interface BaseProcess {
|
|
|
1151
1211
|
type: CensusOrigin;
|
|
1152
1212
|
/** Census root */
|
|
1153
1213
|
root: string;
|
|
1154
|
-
/** Census size */
|
|
1155
|
-
size: number;
|
|
1156
1214
|
/** Census URI */
|
|
1157
1215
|
uri: string;
|
|
1158
1216
|
};
|
|
1159
1217
|
/** Ballot configuration */
|
|
1160
1218
|
ballot: BallotMode;
|
|
1161
1219
|
/** Election questions and choices (required) */
|
|
1162
|
-
questions: Array<
|
|
1220
|
+
questions: Array<ProcessQuestion>;
|
|
1221
|
+
}
|
|
1222
|
+
/**
|
|
1223
|
+
* Question structure used in process configuration and metadata
|
|
1224
|
+
*/
|
|
1225
|
+
type ProcessQuestion = {
|
|
1226
|
+
title: string;
|
|
1227
|
+
description?: string;
|
|
1228
|
+
choices: Array<{
|
|
1163
1229
|
title: string;
|
|
1164
|
-
|
|
1165
|
-
choices: Array<{
|
|
1166
|
-
title: string;
|
|
1167
|
-
value: number;
|
|
1168
|
-
}>;
|
|
1230
|
+
value: number;
|
|
1169
1231
|
}>;
|
|
1170
|
-
}
|
|
1232
|
+
};
|
|
1171
1233
|
/**
|
|
1172
|
-
*
|
|
1234
|
+
* Base configuration shared by both process creation variants
|
|
1173
1235
|
*/
|
|
1174
|
-
interface
|
|
1236
|
+
interface BaseProcessConfig {
|
|
1237
|
+
/**
|
|
1238
|
+
* Census - either a Census object (PlainCensus, WeightedCensus, CspCensus, PublishedCensus)
|
|
1239
|
+
* or manual configuration. If a Census object is provided and not published, it will be
|
|
1240
|
+
* automatically published.
|
|
1241
|
+
*/
|
|
1242
|
+
census: Census | {
|
|
1243
|
+
/** Census type - MerkleTree or CSP */
|
|
1244
|
+
type: CensusOrigin;
|
|
1245
|
+
/** Census root */
|
|
1246
|
+
root: string;
|
|
1247
|
+
/** Census size */
|
|
1248
|
+
size: number;
|
|
1249
|
+
/** Census URI */
|
|
1250
|
+
uri: string;
|
|
1251
|
+
};
|
|
1252
|
+
/** Ballot configuration */
|
|
1253
|
+
ballot: BallotMode;
|
|
1175
1254
|
/** Process timing - use either duration-based or date-based configuration */
|
|
1176
1255
|
timing: {
|
|
1177
1256
|
/** Start date/time (Date object, ISO string, or Unix timestamp, default: now + 60 seconds) */
|
|
@@ -1182,6 +1261,31 @@ interface ProcessConfig extends BaseProcess {
|
|
|
1182
1261
|
endDate?: Date | string | number;
|
|
1183
1262
|
};
|
|
1184
1263
|
}
|
|
1264
|
+
/**
|
|
1265
|
+
* Process configuration with metadata fields (title, description, questions)
|
|
1266
|
+
* The metadata will be created and uploaded automatically
|
|
1267
|
+
*/
|
|
1268
|
+
interface ProcessConfigWithMetadata extends BaseProcessConfig {
|
|
1269
|
+
/** Process title */
|
|
1270
|
+
title: string;
|
|
1271
|
+
/** Process description (optional) */
|
|
1272
|
+
description?: string;
|
|
1273
|
+
/** Election questions and choices (at least one required) */
|
|
1274
|
+
questions: [ProcessQuestion, ...ProcessQuestion[]];
|
|
1275
|
+
}
|
|
1276
|
+
/**
|
|
1277
|
+
* Process configuration with a pre-existing metadata URI
|
|
1278
|
+
* No metadata upload will occur - the provided URI will be used directly
|
|
1279
|
+
*/
|
|
1280
|
+
interface ProcessConfigWithMetadataUri extends BaseProcessConfig {
|
|
1281
|
+
/** Pre-existing metadata URI to use instead of uploading new metadata */
|
|
1282
|
+
metadataUri: string;
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* Configuration for creating a process
|
|
1286
|
+
* Use either metadata fields (title, questions) or a pre-existing metadataUri
|
|
1287
|
+
*/
|
|
1288
|
+
type ProcessConfig = ProcessConfigWithMetadata | ProcessConfigWithMetadataUri;
|
|
1185
1289
|
/**
|
|
1186
1290
|
* Result of process creation
|
|
1187
1291
|
*/
|
|
@@ -1229,7 +1333,13 @@ declare class ProcessOrchestrationService {
|
|
|
1229
1333
|
private organizationRegistry;
|
|
1230
1334
|
private getCrypto;
|
|
1231
1335
|
private signer;
|
|
1336
|
+
private censusOrchestrator;
|
|
1232
1337
|
constructor(processRegistry: ProcessRegistryService, apiService: VocdoniApiService, organizationRegistry: OrganizationRegistryService, getCrypto: () => Promise<DavinciCrypto>, signer: Signer);
|
|
1338
|
+
/**
|
|
1339
|
+
* Handles census - auto-publishes if needed and returns census config
|
|
1340
|
+
* @private
|
|
1341
|
+
*/
|
|
1342
|
+
private handleCensus;
|
|
1233
1343
|
/**
|
|
1234
1344
|
* Gets user-friendly process information by transforming raw contract data
|
|
1235
1345
|
* @param processId - The process ID to fetch
|
|
@@ -1305,7 +1415,8 @@ declare class ProcessOrchestrationService {
|
|
|
1305
1415
|
*/
|
|
1306
1416
|
private dateToUnixTimestamp;
|
|
1307
1417
|
/**
|
|
1308
|
-
* Creates metadata from the
|
|
1418
|
+
* Creates metadata from the configuration with metadata fields
|
|
1419
|
+
* This method should only be called with ProcessConfigWithMetadata
|
|
1309
1420
|
*/
|
|
1310
1421
|
private createMetadata;
|
|
1311
1422
|
/**
|
|
@@ -1541,6 +1652,15 @@ interface VoteStatusInfo {
|
|
|
1541
1652
|
/** The process ID */
|
|
1542
1653
|
processId: string;
|
|
1543
1654
|
}
|
|
1655
|
+
/**
|
|
1656
|
+
* Configuration options for VoteOrchestrationService
|
|
1657
|
+
*/
|
|
1658
|
+
interface VoteOrchestrationConfig {
|
|
1659
|
+
/** Whether to verify downloaded circuit files match expected hashes (default: true) */
|
|
1660
|
+
verifyCircuitFiles?: boolean;
|
|
1661
|
+
/** Whether to verify the generated proof is valid before submission (default: true) */
|
|
1662
|
+
verifyProof?: boolean;
|
|
1663
|
+
}
|
|
1544
1664
|
/**
|
|
1545
1665
|
* Service that orchestrates the complete voting workflow
|
|
1546
1666
|
* Handles all the complex cryptographic operations and API calls internally
|
|
@@ -1550,7 +1670,9 @@ declare class VoteOrchestrationService {
|
|
|
1550
1670
|
private getCrypto;
|
|
1551
1671
|
private signer;
|
|
1552
1672
|
private censusProviders;
|
|
1553
|
-
|
|
1673
|
+
private readonly verifyCircuitFiles;
|
|
1674
|
+
private readonly verifyProof;
|
|
1675
|
+
constructor(apiService: VocdoniApiService, getCrypto: () => Promise<DavinciCrypto>, signer: Signer, censusProviders?: CensusProviders, config?: VoteOrchestrationConfig);
|
|
1554
1676
|
/**
|
|
1555
1677
|
* Submit a vote with simplified configuration
|
|
1556
1678
|
* This method handles all the complex orchestration internally:
|
|
@@ -1754,43 +1876,42 @@ interface DavinciSDKConfig {
|
|
|
1754
1876
|
* - For process/organization operations: Must be connected to a provider
|
|
1755
1877
|
*/
|
|
1756
1878
|
signer: Signer;
|
|
1757
|
-
/**
|
|
1758
|
-
|
|
1759
|
-
/**
|
|
1760
|
-
sequencerUrl?: string;
|
|
1761
|
-
/** Census API URL for census management (optional, defaults based on environment) */
|
|
1879
|
+
/** Sequencer API URL for Vocdoni services (required) */
|
|
1880
|
+
sequencerUrl: string;
|
|
1881
|
+
/** Census API URL for census management (optional, only needed when creating censuses from scratch) */
|
|
1762
1882
|
censusUrl?: string;
|
|
1763
|
-
/**
|
|
1764
|
-
|
|
1765
|
-
/** Custom contract addresses (optional, uses defaults if not provided) */
|
|
1766
|
-
contractAddresses?: {
|
|
1883
|
+
/** Custom contract addresses (optional, fetched from sequencer if not provided) */
|
|
1884
|
+
addresses?: {
|
|
1767
1885
|
processRegistry?: string;
|
|
1768
1886
|
organizationRegistry?: string;
|
|
1769
1887
|
stateTransitionVerifier?: string;
|
|
1770
1888
|
resultsVerifier?: string;
|
|
1771
1889
|
sequencerRegistry?: string;
|
|
1772
1890
|
};
|
|
1773
|
-
/** Whether to force using contract addresses from sequencer info (optional, defaults to false) */
|
|
1774
|
-
useSequencerAddresses?: boolean;
|
|
1775
1891
|
/** Custom census proof providers (optional) */
|
|
1776
1892
|
censusProviders?: CensusProviders;
|
|
1893
|
+
/** Whether to verify downloaded circuit files match expected hashes (optional, defaults to true) */
|
|
1894
|
+
verifyCircuitFiles?: boolean;
|
|
1895
|
+
/** Whether to verify the generated proof is valid before submission (optional, defaults to true) */
|
|
1896
|
+
verifyProof?: boolean;
|
|
1777
1897
|
}
|
|
1778
1898
|
/**
|
|
1779
|
-
* Internal configuration interface
|
|
1899
|
+
* Internal configuration interface
|
|
1780
1900
|
*/
|
|
1781
1901
|
interface InternalDavinciSDKConfig {
|
|
1782
1902
|
signer: Signer;
|
|
1783
1903
|
sequencerUrl: string;
|
|
1784
|
-
censusUrl
|
|
1785
|
-
|
|
1786
|
-
contractAddresses: {
|
|
1904
|
+
censusUrl?: string;
|
|
1905
|
+
customAddresses: {
|
|
1787
1906
|
processRegistry?: string;
|
|
1788
1907
|
organizationRegistry?: string;
|
|
1789
1908
|
stateTransitionVerifier?: string;
|
|
1790
1909
|
resultsVerifier?: string;
|
|
1791
1910
|
sequencerRegistry?: string;
|
|
1792
1911
|
};
|
|
1793
|
-
|
|
1912
|
+
fetchAddressesFromSequencer: boolean;
|
|
1913
|
+
verifyCircuitFiles: boolean;
|
|
1914
|
+
verifyProof: boolean;
|
|
1794
1915
|
}
|
|
1795
1916
|
/**
|
|
1796
1917
|
* Simplified SDK class that encapsulates all Vocdoni DaVinci functionality
|
|
@@ -2023,6 +2144,7 @@ declare class DavinciSDK {
|
|
|
2023
2144
|
* This is the ultra-easy method for end users that handles all the complex voting workflow internally.
|
|
2024
2145
|
*
|
|
2025
2146
|
* Does NOT require a provider - can be used with a bare Wallet for signing only.
|
|
2147
|
+
* IMPORTANT: Requires censusUrl to be configured in the SDK for fetching census proofs (unless using custom census providers).
|
|
2026
2148
|
*
|
|
2027
2149
|
* The method automatically:
|
|
2028
2150
|
* - Fetches process information and validates voting is allowed
|
|
@@ -2032,6 +2154,7 @@ declare class DavinciSDK {
|
|
|
2032
2154
|
*
|
|
2033
2155
|
* @param config - Simplified vote configuration
|
|
2034
2156
|
* @returns Promise resolving to vote submission result
|
|
2157
|
+
* @throws Error if censusUrl is not configured (unless using custom census providers)
|
|
2035
2158
|
*
|
|
2036
2159
|
* @example
|
|
2037
2160
|
* ```typescript
|
|
@@ -2092,6 +2215,23 @@ declare class DavinciSDK {
|
|
|
2092
2215
|
* ```
|
|
2093
2216
|
*/
|
|
2094
2217
|
hasAddressVoted(processId: string, address: string): Promise<boolean>;
|
|
2218
|
+
/**
|
|
2219
|
+
* Check if an address is able to vote in a process and get participant information.
|
|
2220
|
+
*
|
|
2221
|
+
* Does NOT require a provider - uses API calls only.
|
|
2222
|
+
*
|
|
2223
|
+
* @param processId - The process ID
|
|
2224
|
+
* @param address - The voter's address
|
|
2225
|
+
* @returns Promise resolving to participant information (key and weight)
|
|
2226
|
+
*
|
|
2227
|
+
* @example
|
|
2228
|
+
* ```typescript
|
|
2229
|
+
* const participantInfo = await sdk.isAddressAbleToVote(processId, "0x1234567890abcdef...");
|
|
2230
|
+
* console.log("Address:", participantInfo.key);
|
|
2231
|
+
* console.log("Weight:", participantInfo.weight);
|
|
2232
|
+
* ```
|
|
2233
|
+
*/
|
|
2234
|
+
isAddressAbleToVote(processId: string, address: string): Promise<ParticipantInfoResponse>;
|
|
2095
2235
|
/**
|
|
2096
2236
|
* Watch vote status changes in real-time using an async generator.
|
|
2097
2237
|
* This method yields each status change as it happens, perfect for showing
|
|
@@ -2395,20 +2535,15 @@ declare class DavinciSDK {
|
|
|
2395
2535
|
resumeProcess(processId: string): Promise<void>;
|
|
2396
2536
|
/**
|
|
2397
2537
|
* Resolve contract address based on configuration priority:
|
|
2398
|
-
* 1.
|
|
2399
|
-
* 2.
|
|
2400
|
-
* 3. Default deployed addresses from npm package
|
|
2538
|
+
* 1. Custom addresses from user config (if provided)
|
|
2539
|
+
* 2. Addresses from sequencer (fetched during init if no custom addresses provided)
|
|
2401
2540
|
*/
|
|
2402
2541
|
private resolveContractAddress;
|
|
2403
2542
|
/**
|
|
2404
|
-
*
|
|
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
|
|
2543
|
+
* Fetch contract addresses from sequencer info
|
|
2544
|
+
* This is called during init() if custom addresses are not provided
|
|
2410
2545
|
*/
|
|
2411
|
-
private
|
|
2546
|
+
private fetchContractAddressesFromSequencer;
|
|
2412
2547
|
/**
|
|
2413
2548
|
* Get the current configuration
|
|
2414
2549
|
*/
|
|
@@ -2425,5 +2560,5 @@ declare class DavinciSDK {
|
|
|
2425
2560
|
private ensureProvider;
|
|
2426
2561
|
}
|
|
2427
2562
|
|
|
2428
|
-
export { BaseService, CensusOrigin, CircomProof, ContractServiceError,
|
|
2429
|
-
export type { AbstainProperties, AnyJson, ApiError, ApprovalProperties, BallotMode, BaseCensusProof, BaseProcess, BudgetProperties, CSPCensusProof, CSPCensusProofProvider, CSPSignOutput,
|
|
2563
|
+
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 };
|
|
2564
|
+
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 };
|