@vocdoni/davinci-sdk 0.0.3 → 0.0.5

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 CHANGED
@@ -549,6 +549,27 @@ if (hasVoted) {
549
549
  }
550
550
  ```
551
551
 
552
+ #### Checking if Address is Able to Vote
553
+
554
+ Get participant information including voting weight for an address:
555
+
556
+ ```typescript
557
+ const participantInfo = await sdk.isAddressAbleToVote(processId, voterAddress);
558
+
559
+ console.log('Address:', participantInfo.key);
560
+ console.log('Voting weight:', participantInfo.weight);
561
+
562
+ // Use this to verify voter eligibility before submitting a vote
563
+ if (participantInfo) {
564
+ console.log(`Address ${participantInfo.key} is eligible with weight ${participantInfo.weight}`);
565
+ }
566
+ ```
567
+
568
+ This method is useful for:
569
+ - Verifying voter eligibility before vote submission
570
+ - Displaying voting power/weight to users
571
+ - Building voter dashboards and analytics
572
+
552
573
  ## 💡 Examples
553
574
 
554
575
  ### Complete Voting Flow
@@ -293,9 +293,8 @@ type ProcessStatusChangedCallback = EntityCallback<[string, bigint, bigint]>;
293
293
  * @param processID - The process ID
294
294
  * @param root - The new census root
295
295
  * @param uri - The new census URI
296
- * @param maxVotes - The maximum number of votes
297
296
  */
298
- type ProcessCensusUpdatedCallback = EntityCallback<[string, string, string, bigint]>;
297
+ type ProcessCensusUpdatedCallback = EntityCallback<[string, string, string]>;
299
298
  /**
300
299
  * Callback for when a process duration changes.
301
300
  * @param processID - The process ID
@@ -372,7 +371,6 @@ interface BallotMode {
372
371
  }
373
372
  interface CensusData {
374
373
  censusOrigin: CensusOrigin;
375
- maxVotes: string;
376
374
  censusRoot: string;
377
375
  censusURI: string;
378
376
  }
@@ -420,6 +418,7 @@ interface CSPSignOutput {
420
418
  censusOrigin: CensusOrigin;
421
419
  root: string;
422
420
  address: string;
421
+ weight: string;
423
422
  processId: string;
424
423
  publicKey: string;
425
424
  signature: string;
@@ -430,7 +429,7 @@ interface RawResult<T = any> {
430
429
  }
431
430
  interface GoDavinciCryptoWasm {
432
431
  proofInputs(inputJson: string): RawResult<DavinciCryptoOutput>;
433
- cspSign(censusOrigin: number, privKey: string, processId: string, address: string): RawResult<CSPSignOutput>;
432
+ cspSign(censusOrigin: number, privKey: string, processId: string, address: string, weight: string): RawResult<CSPSignOutput>;
434
433
  cspVerify(cspProof: string): RawResult<boolean>;
435
434
  cspCensusRoot(censusOrigin: number, privKey: string): RawResult<{
436
435
  root: string;
@@ -471,8 +470,8 @@ declare class ProcessRegistryService extends SmartContractService {
471
470
  latestStateRoot: bigint;
472
471
  startTime: bigint;
473
472
  duration: bigint;
474
- voteCount: bigint;
475
- voteOverwriteCount: bigint;
473
+ votersCount: bigint;
474
+ overwrittenVotesCount: bigint;
476
475
  creationBlock: bigint;
477
476
  batchNumber: bigint;
478
477
  metadataURI: string;
package/dist/index.d.ts CHANGED
@@ -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,11 +265,11 @@ interface HealthResponse {
263
265
  declare class VocdoniCensusService extends BaseService {
264
266
  constructor(baseURL: string);
265
267
  /**
266
- * Constructs the URI for accessing a census by its root
267
- * @param censusRoot - The census root (hex-prefixed)
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(censusRoot: string): string;
272
+ getCensusUri(relativePath: string): string;
271
273
  createCensus(): Promise<string>;
272
274
  addParticipants(censusId: string, participants: CensusParticipant$1[]): Promise<void>;
273
275
  getParticipants(censusId: string): Promise<CensusParticipant$1[]>;
@@ -457,7 +459,6 @@ interface BallotMode {
457
459
  }
458
460
  interface CensusData {
459
461
  censusOrigin: CensusOrigin;
460
- maxVotes: string;
461
462
  censusRoot: string;
462
463
  censusURI: string;
463
464
  }
@@ -468,14 +469,13 @@ interface EncryptionKey {
468
469
 
469
470
  interface CreateProcessRequest {
470
471
  processId: string;
471
- censusRoot: string;
472
+ census: {
473
+ censusOrigin: CensusOrigin;
474
+ censusRoot: string;
475
+ censusURI: string;
476
+ };
472
477
  ballotMode: BallotMode;
473
478
  signature: string;
474
- /**
475
- * The censusOrigin specifies the origin type of the census used in the request.
476
- * This attribute allows the API to determine how the census data should be processed or verified.
477
- */
478
- censusOrigin: CensusOrigin;
479
479
  }
480
480
  interface CreateProcessResponse {
481
481
  processId: string;
@@ -489,36 +489,14 @@ interface GetProcessResponse {
489
489
  organizationId: string;
490
490
  encryptionKey: EncryptionKey;
491
491
  stateRoot: string;
492
- result: string[];
493
- startTime: number;
492
+ result: string[] | null;
493
+ startTime: string;
494
494
  duration: number;
495
495
  metadataURI: string;
496
496
  ballotMode: BallotMode;
497
497
  census: CensusData;
498
- metadata: {
499
- title: Record<string, string>;
500
- description: Record<string, string>;
501
- media: {
502
- header: string;
503
- logo: string;
504
- };
505
- questions: {
506
- title: Record<string, string>;
507
- description: Record<string, string>;
508
- choices: {
509
- title: Record<string, string>;
510
- value: number;
511
- meta: Record<string, string>;
512
- }[];
513
- meta: Record<string, string>;
514
- }[];
515
- processType: {
516
- name: string;
517
- properties: Record<string, string>;
518
- };
519
- };
520
- voteCount: string;
521
- voteOverwrittenCount: string;
498
+ votersCount: string;
499
+ overwrittenVotesCount: string;
522
500
  isAcceptingVotes: boolean;
523
501
  sequencerStats: {
524
502
  stateTransitionCount: number;
@@ -548,8 +526,8 @@ interface VoteProof {
548
526
  interface VoteRequest {
549
527
  /** The `processId` you obtained when creating the process. */
550
528
  processId: string;
551
- /** Your Merkle‐proof that you're in the census. */
552
- censusProof: CensusProof;
529
+ /** Your census proof (only required for CSP, not for MerkleTree). */
530
+ censusProof?: CensusProof;
553
531
  /** Your encrypted ballot. */
554
532
  ballot: VoteBallot;
555
533
  /** The zkSNARK proof that the ballot is well‐formed. */
@@ -615,6 +593,10 @@ interface WorkerStats {
615
593
  interface WorkersResponse {
616
594
  workers: WorkerStats[];
617
595
  }
596
+ interface ParticipantInfoResponse {
597
+ key: string;
598
+ weight: string;
599
+ }
618
600
 
619
601
  declare class VocdoniSequencerService extends BaseService {
620
602
  constructor(baseURL: string);
@@ -625,6 +607,8 @@ declare class VocdoniSequencerService extends BaseService {
625
607
  submitVote(vote: VoteRequest): Promise<void>;
626
608
  getVoteStatus(processId: string, voteId: string): Promise<VoteStatusResponse>;
627
609
  hasAddressVoted(processId: string, address: string): Promise<boolean>;
610
+ getAddressWeight(processId: string, address: string): Promise<string>;
611
+ isAddressAbleToVote(processId: string, address: string): Promise<boolean>;
628
612
  getInfo(): Promise<InfoResponse>;
629
613
  pushMetadata(metadata: ElectionMetadata): Promise<string>;
630
614
  getMetadata(hashOrUrl: string): Promise<ElectionMetadata>;
@@ -864,9 +848,8 @@ type ProcessStatusChangedCallback = EntityCallback<[string, bigint, bigint]>;
864
848
  * @param processID - The process ID
865
849
  * @param root - The new census root
866
850
  * @param uri - The new census URI
867
- * @param maxVotes - The maximum number of votes
868
851
  */
869
- type ProcessCensusUpdatedCallback = EntityCallback<[string, string, string, bigint]>;
852
+ type ProcessCensusUpdatedCallback = EntityCallback<[string, string, string]>;
870
853
  /**
871
854
  * Callback for when a process duration changes.
872
855
  * @param processID - The process ID
@@ -915,8 +898,8 @@ declare class ProcessRegistryService extends SmartContractService {
915
898
  latestStateRoot: bigint;
916
899
  startTime: bigint;
917
900
  duration: bigint;
918
- voteCount: bigint;
919
- voteOverwriteCount: bigint;
901
+ votersCount: bigint;
902
+ overwrittenVotesCount: bigint;
920
903
  creationBlock: bigint;
921
904
  batchNumber: bigint;
922
905
  metadataURI: string;
@@ -1094,6 +1077,7 @@ interface CSPSignOutput {
1094
1077
  censusOrigin: CensusOrigin;
1095
1078
  root: string;
1096
1079
  address: string;
1080
+ weight: string;
1097
1081
  processId: string;
1098
1082
  publicKey: string;
1099
1083
  signature: string;
@@ -1104,7 +1088,7 @@ interface RawResult<T = any> {
1104
1088
  }
1105
1089
  interface GoDavinciCryptoWasm {
1106
1090
  proofInputs(inputJson: string): RawResult<DavinciCryptoOutput>;
1107
- cspSign(censusOrigin: number, privKey: string, processId: string, address: string): RawResult<CSPSignOutput>;
1091
+ cspSign(censusOrigin: number, privKey: string, processId: string, address: string, weight: string): RawResult<CSPSignOutput>;
1108
1092
  cspVerify(cspProof: string): RawResult<boolean>;
1109
1093
  cspCensusRoot(censusOrigin: number, privKey: string): RawResult<{
1110
1094
  root: string;
@@ -1164,22 +1148,24 @@ declare class DavinciCrypto {
1164
1148
  * @param privKey - The private key in hex format
1165
1149
  * @param processId - The process ID in hex format
1166
1150
  * @param address - The address in hex format
1151
+ * @param weight - The vote weight as a decimal string
1167
1152
  * @returns The CSP proof as a parsed JSON object
1168
1153
  * @throws if called before `await init()`, or if Go returns an error
1169
1154
  */
1170
- cspSign(censusOrigin: CensusOrigin, privKey: string, processId: string, address: string): Promise<CSPSignOutput>;
1155
+ cspSign(censusOrigin: CensusOrigin, privKey: string, processId: string, address: string, weight: string): Promise<CSPSignOutput>;
1171
1156
  /**
1172
1157
  * Verify a CSP (Credential Service Provider) proof.
1173
1158
  * @param censusOrigin - The census origin type (e.g., CensusOrigin.CensusOriginCSP)
1174
1159
  * @param root - The census root
1175
1160
  * @param address - The address
1161
+ * @param weight - The vote weight as a decimal string
1176
1162
  * @param processId - The process ID
1177
1163
  * @param publicKey - The public key
1178
1164
  * @param signature - The signature
1179
1165
  * @returns The verification result
1180
1166
  * @throws if called before `await init()`, or if Go returns an error
1181
1167
  */
1182
- cspVerify(censusOrigin: CensusOrigin, root: string, address: string, processId: string, publicKey: string, signature: string): Promise<boolean>;
1168
+ cspVerify(censusOrigin: CensusOrigin, root: string, address: string, weight: string, processId: string, publicKey: string, signature: string): Promise<boolean>;
1183
1169
  /**
1184
1170
  * Generate a CSP (Credential Service Provider) census root.
1185
1171
  * @param censusOrigin - The census origin type (e.g., CensusOrigin.CensusOriginCSP)
@@ -1204,27 +1190,29 @@ interface BaseProcess {
1204
1190
  type: CensusOrigin;
1205
1191
  /** Census root */
1206
1192
  root: string;
1207
- /** Census size */
1208
- size: number;
1209
1193
  /** Census URI */
1210
1194
  uri: string;
1211
1195
  };
1212
1196
  /** Ballot configuration */
1213
1197
  ballot: BallotMode;
1214
1198
  /** Election questions and choices (required) */
1215
- questions: Array<{
1199
+ questions: Array<ProcessQuestion>;
1200
+ }
1201
+ /**
1202
+ * Question structure used in process configuration and metadata
1203
+ */
1204
+ type ProcessQuestion = {
1205
+ title: string;
1206
+ description?: string;
1207
+ choices: Array<{
1216
1208
  title: string;
1217
- description?: string;
1218
- choices: Array<{
1219
- title: string;
1220
- value: number;
1221
- }>;
1209
+ value: number;
1222
1210
  }>;
1223
- }
1211
+ };
1224
1212
  /**
1225
- * Configuration for creating a process
1213
+ * Base configuration shared by both process creation variants
1226
1214
  */
1227
- interface ProcessConfig extends Omit<BaseProcess, 'census'> {
1215
+ interface BaseProcessConfig {
1228
1216
  /**
1229
1217
  * Census - either a Census object (PlainCensus, WeightedCensus, CspCensus, PublishedCensus)
1230
1218
  * or manual configuration. If a Census object is provided and not published, it will be
@@ -1240,6 +1228,8 @@ interface ProcessConfig extends Omit<BaseProcess, 'census'> {
1240
1228
  /** Census URI */
1241
1229
  uri: string;
1242
1230
  };
1231
+ /** Ballot configuration */
1232
+ ballot: BallotMode;
1243
1233
  /** Process timing - use either duration-based or date-based configuration */
1244
1234
  timing: {
1245
1235
  /** Start date/time (Date object, ISO string, or Unix timestamp, default: now + 60 seconds) */
@@ -1250,6 +1240,31 @@ interface ProcessConfig extends Omit<BaseProcess, 'census'> {
1250
1240
  endDate?: Date | string | number;
1251
1241
  };
1252
1242
  }
1243
+ /**
1244
+ * Process configuration with metadata fields (title, description, questions)
1245
+ * The metadata will be created and uploaded automatically
1246
+ */
1247
+ interface ProcessConfigWithMetadata extends BaseProcessConfig {
1248
+ /** Process title */
1249
+ title: string;
1250
+ /** Process description (optional) */
1251
+ description?: string;
1252
+ /** Election questions and choices (at least one required) */
1253
+ questions: [ProcessQuestion, ...ProcessQuestion[]];
1254
+ }
1255
+ /**
1256
+ * Process configuration with a pre-existing metadata URI
1257
+ * No metadata upload will occur - the provided URI will be used directly
1258
+ */
1259
+ interface ProcessConfigWithMetadataUri extends BaseProcessConfig {
1260
+ /** Pre-existing metadata URI to use instead of uploading new metadata */
1261
+ metadataUri: string;
1262
+ }
1263
+ /**
1264
+ * Configuration for creating a process
1265
+ * Use either metadata fields (title, questions) or a pre-existing metadataUri
1266
+ */
1267
+ type ProcessConfig = ProcessConfigWithMetadata | ProcessConfigWithMetadataUri;
1253
1268
  /**
1254
1269
  * Result of process creation
1255
1270
  */
@@ -1280,9 +1295,9 @@ interface ProcessInfo extends BaseProcess {
1280
1295
  /** Process results (array of BigInt values) */
1281
1296
  result: bigint[];
1282
1297
  /** Number of votes cast */
1283
- voteCount: number;
1298
+ votersCount: number;
1284
1299
  /** Number of vote overwrites */
1285
- voteOverwriteCount: number;
1300
+ overwrittenVotesCount: number;
1286
1301
  /** Metadata URI */
1287
1302
  metadataURI: string;
1288
1303
  /** Raw contract data (for advanced users) */
@@ -1379,7 +1394,8 @@ declare class ProcessOrchestrationService {
1379
1394
  */
1380
1395
  private dateToUnixTimestamp;
1381
1396
  /**
1382
- * Creates metadata from the simplified configuration
1397
+ * Creates metadata from the configuration with metadata fields
1398
+ * This method should only be called with ProcessConfigWithMetadata
1383
1399
  */
1384
1400
  private createMetadata;
1385
1401
  /**
@@ -2178,6 +2194,42 @@ declare class DavinciSDK {
2178
2194
  * ```
2179
2195
  */
2180
2196
  hasAddressVoted(processId: string, address: string): Promise<boolean>;
2197
+ /**
2198
+ * Check if an address is able to vote in a process (i.e., is in the census).
2199
+ *
2200
+ * Does NOT require a provider - uses API calls only.
2201
+ *
2202
+ * @param processId - The process ID
2203
+ * @param address - The voter's address
2204
+ * @returns Promise resolving to boolean indicating if the address can vote
2205
+ *
2206
+ * @example
2207
+ * ```typescript
2208
+ * const canVote = await sdk.isAddressAbleToVote(processId, "0x1234567890abcdef...");
2209
+ * if (canVote) {
2210
+ * console.log("This address can vote");
2211
+ * } else {
2212
+ * console.log("This address is not in the census");
2213
+ * }
2214
+ * ```
2215
+ */
2216
+ isAddressAbleToVote(processId: string, address: string): Promise<boolean>;
2217
+ /**
2218
+ * Get the voting weight for an address in a process.
2219
+ *
2220
+ * Does NOT require a provider - uses API calls only.
2221
+ *
2222
+ * @param processId - The process ID
2223
+ * @param address - The voter's address
2224
+ * @returns Promise resolving to the address weight as a string
2225
+ *
2226
+ * @example
2227
+ * ```typescript
2228
+ * const weight = await sdk.getAddressWeight(processId, "0x1234567890abcdef...");
2229
+ * console.log("Address weight:", weight);
2230
+ * ```
2231
+ */
2232
+ getAddressWeight(processId: string, address: string): Promise<string>;
2181
2233
  /**
2182
2234
  * Watch vote status changes in real-time using an async generator.
2183
2235
  * This method yields each status change as it happens, perfect for showing
@@ -2507,4 +2559,4 @@ declare class DavinciSDK {
2507
2559
  }
2508
2560
 
2509
2561
  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 };
2510
- 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, ProcessCensusUpdatedCallback, ProcessConfig, ProcessCreatedCallback, ProcessCreationResult, ProcessDurationChangedCallback, ProcessInfo, 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 };
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 };