@vocdoni/davinci-sdk 0.0.6 → 0.0.7

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
@@ -321,7 +321,7 @@ For advanced use cases, you can still provide census data manually:
321
321
  ```typescript
322
322
  const process = await sdk.createProcess({
323
323
  census: {
324
- type: CensusOrigin.CensusOriginMerkleTree,
324
+ type: CensusOrigin.OffchainStatic,
325
325
  root: "0xabc...",
326
326
  size: 100,
327
327
  uri: "ipfs://..."
@@ -406,7 +406,7 @@ const processResult = await sdk.createProcess({
406
406
 
407
407
  // Census configuration
408
408
  census: {
409
- type: CensusOrigin.CensusOriginMerkleTree,
409
+ type: CensusOrigin.OffchainStatic,
410
410
  root: "0x...",
411
411
  size: 1000,
412
412
  uri: "ipfs://..."
@@ -662,7 +662,7 @@ async function completeVotingExample() {
662
662
  title: "Community Budget Allocation",
663
663
  description: "Decide how to allocate our community budget",
664
664
  census: {
665
- type: CensusOrigin.CensusOriginMerkleTree,
665
+ type: CensusOrigin.OffchainStatic,
666
666
  root: publishResult.root,
667
667
  size: censusSize,
668
668
  uri: publishResult.uri
@@ -224,6 +224,11 @@ declare class ProcessStatusError extends ContractServiceError {
224
224
  */
225
225
  declare class ProcessCensusError extends ContractServiceError {
226
226
  }
227
+ /**
228
+ * Error thrown when the census origin does not allow to modify the census root or uri.
229
+ */
230
+ declare class CensusNotUpdatable extends ContractServiceError {
231
+ }
227
232
  /**
228
233
  * Error thrown when process duration change fails.
229
234
  */
@@ -302,12 +307,15 @@ type ProcessCensusUpdatedCallback = EntityCallback<[string, string, string]>;
302
307
  */
303
308
  type ProcessDurationChangedCallback = EntityCallback<[string, bigint]>;
304
309
  /**
305
- * Callback for when a process state root is updated.
310
+ * Callback for when a process state transitions (valid state transition published).
306
311
  * @param processID - The process ID
307
312
  * @param sender - Address of the account that updated the state root
308
- * @param newStateRoot - The new state root
313
+ * @param oldStateRoot - The state root before the state transition
314
+ * @param newStateRoot - The new state root after the state transition
315
+ * @param newVotersCount - The number of single voters for the process updated after the state transition
316
+ * @param newOverwrittenVotesCount - The number of votes that has been overwritten updated after the state transition
309
317
  */
310
- type ProcessStateRootUpdatedCallback = EntityCallback<[string, string, bigint]>;
318
+ type ProcessStateTransitionedCallback = EntityCallback<[string, string, bigint, bigint, bigint, bigint]>;
311
319
  /**
312
320
  * Callback for when process results are set.
313
321
  * @param processID - The process ID
@@ -359,10 +367,14 @@ declare class OrganizationRegistryService extends SmartContractService {
359
367
  * Census origin types
360
368
  */
361
369
  declare enum CensusOrigin {
362
- /** Indicates that the census is derived from a Merkle Tree structure */
363
- CensusOriginMerkleTree = 1,
364
- /** Indicates that the census is provided by a Credential Service Provider (CSP) */
365
- CensusOriginCSP = 2
370
+ /** Offchain static Merkle Tree census */
371
+ OffchainStatic = 1,
372
+ /** Offchain dynamic Merkle Tree census */
373
+ OffchainDynamic = 2,
374
+ /** Onchain Merkle Tree census */
375
+ Onchain = 3,
376
+ /** Credential Service Provider (CSP) census using EdDSA BLS12-377 */
377
+ CSP = 4
366
378
  }
367
379
 
368
380
  interface BallotMode {
@@ -523,11 +535,11 @@ declare class ProcessRegistryService extends SmartContractService {
523
535
  onProcessStatusChanged(cb: ProcessStatusChangedCallback): void;
524
536
  onCensusUpdated(cb: ProcessCensusUpdatedCallback): void;
525
537
  onProcessDurationChanged(cb: ProcessDurationChangedCallback): void;
526
- onStateRootUpdated(cb: ProcessStateRootUpdatedCallback): void;
538
+ onStateTransitioned(cb: ProcessStateTransitionedCallback): void;
527
539
  onProcessResultsSet(cb: ProcessResultsSetCallback): void;
528
540
  onProcessMaxVotersChanged(cb: ProcessMaxVotersChangedCallback): void;
529
541
  removeAllListeners(): void;
530
542
  }
531
543
 
532
- export { ContractServiceError, OrganizationAdministratorError, OrganizationCreateError, OrganizationDeleteError, OrganizationRegistryService, OrganizationUpdateError, ProcessCensusError, ProcessCreateError, ProcessDurationError, ProcessRegistryService, ProcessResultError, ProcessStateTransitionError, ProcessStatus, ProcessStatusError, SmartContractService, TxStatus };
533
- export type { EntityCallback, OrganizationAdministratorAddedCallback, OrganizationAdministratorRemovedCallback, OrganizationCreatedCallback, OrganizationInfo, OrganizationUpdatedCallback, ProcessCensusUpdatedCallback, ProcessCreatedCallback, ProcessDurationChangedCallback, ProcessMaxVotersChangedCallback, ProcessResultsSetCallback, ProcessStateRootUpdatedCallback, ProcessStatusChangedCallback, TxStatusEvent };
544
+ export { CensusNotUpdatable, ContractServiceError, OrganizationAdministratorError, OrganizationCreateError, OrganizationDeleteError, OrganizationRegistryService, OrganizationUpdateError, ProcessCensusError, ProcessCreateError, ProcessDurationError, ProcessRegistryService, ProcessResultError, ProcessStateTransitionError, ProcessStatus, ProcessStatusError, SmartContractService, TxStatus };
545
+ export type { EntityCallback, OrganizationAdministratorAddedCallback, OrganizationAdministratorRemovedCallback, OrganizationCreatedCallback, OrganizationInfo, OrganizationUpdatedCallback, ProcessCensusUpdatedCallback, ProcessCreatedCallback, ProcessDurationChangedCallback, ProcessMaxVotersChangedCallback, ProcessResultsSetCallback, ProcessStateTransitionedCallback, ProcessStatusChangedCallback, TxStatusEvent };
package/dist/index.d.ts CHANGED
@@ -108,10 +108,14 @@ declare class BaseService {
108
108
  * Census origin types
109
109
  */
110
110
  declare enum CensusOrigin {
111
- /** Indicates that the census is derived from a Merkle Tree structure */
112
- CensusOriginMerkleTree = 1,
113
- /** Indicates that the census is provided by a Credential Service Provider (CSP) */
114
- CensusOriginCSP = 2
111
+ /** Offchain static Merkle Tree census */
112
+ OffchainStatic = 1,
113
+ /** Offchain dynamic Merkle Tree census */
114
+ OffchainDynamic = 2,
115
+ /** Onchain Merkle Tree census */
116
+ Onchain = 3,
117
+ /** Credential Service Provider (CSP) census using EdDSA BLS12-377 */
118
+ CSP = 4
115
119
  }
116
120
  interface CensusParticipant$1 {
117
121
  key: string;
@@ -124,18 +128,18 @@ interface BaseCensusProof {
124
128
  address: string;
125
129
  /** The weight as a decimal string. */
126
130
  weight: string;
127
- /** Census origin type: CensusOriginMerkleTree for merkle proofs, CensusOriginCSP for csp proofs */
131
+ /** Census origin type: OffchainStatic/OffchainDynamic/Onchain for merkle proofs, CSP for csp proofs */
128
132
  censusOrigin: CensusOrigin;
129
133
  }
130
134
  interface MerkleCensusProof extends BaseCensusProof {
131
- censusOrigin: CensusOrigin.CensusOriginMerkleTree;
135
+ censusOrigin: CensusOrigin.OffchainStatic | CensusOrigin.OffchainDynamic | CensusOrigin.Onchain;
132
136
  /** The leaf value (hex-prefixed weight). */
133
137
  value: string;
134
138
  /** The serialized sibling path (hex-prefixed). */
135
139
  siblings: string;
136
140
  }
137
141
  interface CSPCensusProof extends BaseCensusProof {
138
- censusOrigin: CensusOrigin.CensusOriginCSP;
142
+ censusOrigin: CensusOrigin.CSP;
139
143
  /** The process id signed with the address (hex-prefixed). */
140
144
  processId: string;
141
145
  /** The public key of the csp (hex-prefixed). */
@@ -308,8 +312,9 @@ declare abstract class Census {
308
312
  protected _censusRoot: string | null;
309
313
  protected _censusURI: string | null;
310
314
  protected _type: CensusType;
315
+ protected _censusOrigin: CensusOrigin;
311
316
  protected _size: number | null;
312
- constructor(type: CensusType);
317
+ constructor(type: CensusType, censusOrigin?: CensusOrigin);
313
318
  get censusId(): string | null;
314
319
  get censusRoot(): string | null;
315
320
  get censusURI(): string | null;
@@ -317,7 +322,7 @@ declare abstract class Census {
317
322
  get size(): number | null;
318
323
  get isPublished(): boolean;
319
324
  /**
320
- * Convert CensusType to CensusOrigin enum for API compatibility
325
+ * Get the census origin (OffchainStatic, OffchainDynamic, Onchain, or CSP)
321
326
  */
322
327
  get censusOrigin(): CensusOrigin;
323
328
  }
@@ -328,7 +333,11 @@ declare abstract class Census {
328
333
  */
329
334
  declare class PlainCensus extends Census {
330
335
  private _participants;
331
- constructor();
336
+ /**
337
+ * Creates a new PlainCensus
338
+ * @param censusOrigin - The census origin (defaults to OffchainStatic for backward compatibility)
339
+ */
340
+ constructor(censusOrigin?: CensusOrigin);
332
341
  /**
333
342
  * Add participant(s) with automatic weight=1
334
343
  * @param addresses - Single address or array of addresses
@@ -369,7 +378,11 @@ interface WeightedParticipant {
369
378
  */
370
379
  declare class WeightedCensus extends Census {
371
380
  private _participants;
372
- constructor();
381
+ /**
382
+ * Creates a new WeightedCensus
383
+ * @param censusOrigin - The census origin (defaults to OffchainStatic for backward compatibility)
384
+ */
385
+ constructor(censusOrigin?: CensusOrigin);
373
386
  /**
374
387
  * Add participant(s) with custom weights
375
388
  * Weight can be provided as string, number, or bigint - will be converted to string internally
@@ -421,7 +434,15 @@ declare class CspCensus extends Census {
421
434
  * Use this when you have the census root, URI, and size from a previous publication
422
435
  */
423
436
  declare class PublishedCensus extends Census {
424
- constructor(type: CensusType, root: string, uri: string, size: number);
437
+ /**
438
+ * Creates a PublishedCensus from existing census data
439
+ * @param type - The census type (PLAIN, WEIGHTED, or CSP)
440
+ * @param root - The census root
441
+ * @param uri - The census URI
442
+ * @param size - The census size (number of participants)
443
+ * @param censusOrigin - The census origin (optional - defaults based on type if not provided)
444
+ */
445
+ constructor(type: CensusType, root: string, uri: string, size: number, censusOrigin?: CensusOrigin);
425
446
  }
426
447
 
427
448
  /**
@@ -496,6 +517,7 @@ interface GetProcessResponse {
496
517
  ballotMode: BallotMode;
497
518
  census: CensusData;
498
519
  votersCount: string;
520
+ maxVoters: string;
499
521
  overwrittenVotesCount: string;
500
522
  isAcceptingVotes: boolean;
501
523
  sequencerStats: {
@@ -857,12 +879,15 @@ type ProcessCensusUpdatedCallback = EntityCallback<[string, string, string]>;
857
879
  */
858
880
  type ProcessDurationChangedCallback = EntityCallback<[string, bigint]>;
859
881
  /**
860
- * Callback for when a process state root is updated.
882
+ * Callback for when a process state transitions (valid state transition published).
861
883
  * @param processID - The process ID
862
884
  * @param sender - Address of the account that updated the state root
863
- * @param newStateRoot - The new state root
885
+ * @param oldStateRoot - The state root before the state transition
886
+ * @param newStateRoot - The new state root after the state transition
887
+ * @param newVotersCount - The number of single voters for the process updated after the state transition
888
+ * @param newOverwrittenVotesCount - The number of votes that has been overwritten updated after the state transition
864
889
  */
865
- type ProcessStateRootUpdatedCallback = EntityCallback<[string, string, bigint]>;
890
+ type ProcessStateTransitionedCallback = EntityCallback<[string, string, bigint, bigint, bigint, bigint]>;
866
891
  /**
867
892
  * Callback for when process results are set.
868
893
  * @param processID - The process ID
@@ -951,7 +976,7 @@ declare class ProcessRegistryService extends SmartContractService {
951
976
  onProcessStatusChanged(cb: ProcessStatusChangedCallback): void;
952
977
  onCensusUpdated(cb: ProcessCensusUpdatedCallback): void;
953
978
  onProcessDurationChanged(cb: ProcessDurationChangedCallback): void;
954
- onStateRootUpdated(cb: ProcessStateRootUpdatedCallback): void;
979
+ onStateTransitioned(cb: ProcessStateTransitionedCallback): void;
955
980
  onProcessResultsSet(cb: ProcessResultsSetCallback): void;
956
981
  onProcessMaxVotersChanged(cb: ProcessMaxVotersChangedCallback): void;
957
982
  removeAllListeners(): void;
@@ -1877,6 +1902,11 @@ declare class ProcessStatusError extends ContractServiceError {
1877
1902
  */
1878
1903
  declare class ProcessCensusError extends ContractServiceError {
1879
1904
  }
1905
+ /**
1906
+ * Error thrown when the census origin does not allow to modify the census root or uri.
1907
+ */
1908
+ declare class CensusNotUpdatable extends ContractServiceError {
1909
+ }
1880
1910
  /**
1881
1911
  * Error thrown when process duration change fails.
1882
1912
  */
@@ -2064,7 +2094,7 @@ declare class DavinciSDK {
2064
2094
  * title: "My Election",
2065
2095
  * description: "A simple election",
2066
2096
  * census: {
2067
- * type: CensusOrigin.CensusOriginMerkleTree,
2097
+ * type: CensusOrigin.OffchainStatic,
2068
2098
  * root: "0x1234...",
2069
2099
  * size: 100,
2070
2100
  * uri: "ipfs://..."
@@ -2145,7 +2175,7 @@ declare class DavinciSDK {
2145
2175
  * title: "My Election",
2146
2176
  * description: "A simple election",
2147
2177
  * census: {
2148
- * type: CensusOrigin.CensusOriginMerkleTree,
2178
+ * type: CensusOrigin.OffchainStatic,
2149
2179
  * root: "0x1234...",
2150
2180
  * size: 100,
2151
2181
  * uri: "ipfs://your-census-uri"
@@ -2683,5 +2713,5 @@ declare class DavinciSDK {
2683
2713
  private ensureProvider;
2684
2714
  }
2685
2715
 
2686
- export { BaseService, Census, CensusOrchestrator, CensusOrigin, CensusType, CircomProof, ContractServiceError, CspCensus, DavinciCrypto, DavinciSDK, ElectionMetadataTemplate, ElectionResultsTypeNames, OrganizationAdministratorError, OrganizationCreateError, OrganizationDeleteError, OrganizationRegistryService, OrganizationUpdateError, PlainCensus, ProcessCensusError, ProcessCreateError, ProcessDurationError, ProcessOrchestrationService, ProcessRegistryService, ProcessResultError, ProcessStateTransitionError, ProcessStatus, ProcessStatusError, PublishedCensus, SmartContractService, TxStatus, VocdoniApiService, VocdoniCensusService, VocdoniSequencerService, VoteOrchestrationService, VoteStatus, WeightedCensus, assertCSPCensusProof, assertMerkleCensusProof, createProcessSignatureMessage, getElectionMetadataTemplate, isCSPCensusProof, isMerkleCensusProof, signProcessCreation, validateProcessId };
2687
- export type { AbstainProperties, AnyJson, ApiError, ApprovalProperties, BallotMode, BaseCensusProof, BaseProcess, BudgetProperties, CSPCensusProof, CSPCensusProofProvider, CSPSignOutput, CensusData, CensusParticipant$1 as CensusParticipant, CensusProof, CensusProviders, CensusSizeResponse, Choice, ChoiceProperties, CircomProofOptions, CreateProcessRequest, CreateProcessResponse, CustomMeta, DavinciCryptoCiphertext, DavinciCryptoInputs, DavinciCryptoOptions, DavinciCryptoOutput, DavinciSDKConfig, ElectionMetadata, ElectionResultsType, EncryptionKey, EntityCallback, GetProcessResponse, Groth16Proof, HealthResponse, IChoice, IQuestion, InfoResponse, JsonArray, JsonMap, ListProcessesResponse, MerkleCensusProof, MerkleCensusProofProvider, MultiLanguage, OrganizationAdministratorAddedCallback, OrganizationAdministratorRemovedCallback, OrganizationCreatedCallback, OrganizationInfo, OrganizationUpdatedCallback, ParticipantInfoResponse, ProcessCensusUpdatedCallback, ProcessConfig, ProcessConfigWithMetadata, ProcessConfigWithMetadataUri, ProcessCreatedCallback, ProcessCreationResult, ProcessDurationChangedCallback, ProcessInfo, ProcessMaxVotersChangedCallback, ProcessQuestion, ProcessResultsSetCallback, ProcessStateRootUpdatedCallback, ProcessStatusChangedCallback, ProofInputs, ProtocolVersion, PublishCensusResponse, QuadraticProperties, Question, SequencerStats, Snapshot, SnapshotsQueryParams, SnapshotsResponse, TxStatusEvent, VocdoniApiServiceConfig, VoteBallot, VoteCiphertext, VoteConfig, VoteOrchestrationConfig, VoteProof, VoteRequest, VoteResult, VoteStatusInfo, VoteStatusResponse, WeightedParticipant, WorkerStats, WorkersResponse };
2716
+ export { BaseService, Census, CensusNotUpdatable, 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 };
2717
+ export type { AbstainProperties, AnyJson, ApiError, ApprovalProperties, BallotMode, BaseCensusProof, BaseProcess, BudgetProperties, CSPCensusProof, CSPCensusProofProvider, CSPSignOutput, CensusData, CensusParticipant$1 as CensusParticipant, CensusProof, CensusProviders, CensusSizeResponse, Choice, ChoiceProperties, CircomProofOptions, CreateProcessRequest, CreateProcessResponse, CustomMeta, DavinciCryptoCiphertext, DavinciCryptoInputs, DavinciCryptoOptions, DavinciCryptoOutput, DavinciSDKConfig, ElectionMetadata, ElectionResultsType, EncryptionKey, EntityCallback, GetProcessResponse, Groth16Proof, HealthResponse, IChoice, IQuestion, InfoResponse, JsonArray, JsonMap, ListProcessesResponse, MerkleCensusProof, MerkleCensusProofProvider, MultiLanguage, OrganizationAdministratorAddedCallback, OrganizationAdministratorRemovedCallback, OrganizationCreatedCallback, OrganizationInfo, OrganizationUpdatedCallback, ParticipantInfoResponse, ProcessCensusUpdatedCallback, ProcessConfig, ProcessConfigWithMetadata, ProcessConfigWithMetadataUri, ProcessCreatedCallback, ProcessCreationResult, ProcessDurationChangedCallback, ProcessInfo, ProcessMaxVotersChangedCallback, ProcessQuestion, ProcessResultsSetCallback, ProcessStateTransitionedCallback, ProcessStatusChangedCallback, ProofInputs, ProtocolVersion, PublishCensusResponse, QuadraticProperties, Question, SequencerStats, Snapshot, SnapshotsQueryParams, SnapshotsResponse, TxStatusEvent, VocdoniApiServiceConfig, VoteBallot, VoteCiphertext, VoteConfig, VoteOrchestrationConfig, VoteProof, VoteRequest, VoteResult, VoteStatusInfo, VoteStatusResponse, WeightedParticipant, WorkerStats, WorkersResponse };
package/dist/index.js CHANGED
@@ -194,18 +194,20 @@ class VocdoniCensusService extends BaseService {
194
194
  }
195
195
 
196
196
  var CensusOrigin = /* @__PURE__ */ ((CensusOrigin2) => {
197
- CensusOrigin2[CensusOrigin2["CensusOriginMerkleTree"] = 1] = "CensusOriginMerkleTree";
198
- CensusOrigin2[CensusOrigin2["CensusOriginCSP"] = 2] = "CensusOriginCSP";
197
+ CensusOrigin2[CensusOrigin2["OffchainStatic"] = 1] = "OffchainStatic";
198
+ CensusOrigin2[CensusOrigin2["OffchainDynamic"] = 2] = "OffchainDynamic";
199
+ CensusOrigin2[CensusOrigin2["Onchain"] = 3] = "Onchain";
200
+ CensusOrigin2[CensusOrigin2["CSP"] = 4] = "CSP";
199
201
  return CensusOrigin2;
200
202
  })(CensusOrigin || {});
201
203
  function isBaseCensusProof(proof) {
202
204
  return !!proof && typeof proof.root === "string" && typeof proof.address === "string" && typeof proof.censusOrigin === "number" && Object.values(CensusOrigin).includes(proof.censusOrigin);
203
205
  }
204
206
  function isMerkleCensusProof(proof) {
205
- return isBaseCensusProof(proof) && proof.censusOrigin === 1 /* CensusOriginMerkleTree */ && typeof proof.weight === "string" && typeof proof.value === "string" && typeof proof.siblings === "string";
207
+ return isBaseCensusProof(proof) && (proof.censusOrigin === 1 /* OffchainStatic */ || proof.censusOrigin === 2 /* OffchainDynamic */ || proof.censusOrigin === 3 /* Onchain */) && typeof proof.weight === "string" && typeof proof.value === "string" && typeof proof.siblings === "string";
206
208
  }
207
209
  function isCSPCensusProof(proof) {
208
- return isBaseCensusProof(proof) && proof.censusOrigin === 2 /* CensusOriginCSP */ && typeof proof.weight === "string" && typeof proof.processId === "string" && typeof proof.publicKey === "string" && typeof proof.signature === "string";
210
+ return isBaseCensusProof(proof) && proof.censusOrigin === 4 /* CSP */ && typeof proof.weight === "string" && typeof proof.processId === "string" && typeof proof.publicKey === "string" && typeof proof.signature === "string";
209
211
  }
210
212
  function assertMerkleCensusProof(proof) {
211
213
  if (!isMerkleCensusProof(proof)) {
@@ -225,12 +227,27 @@ var CensusType = /* @__PURE__ */ ((CensusType2) => {
225
227
  return CensusType2;
226
228
  })(CensusType || {});
227
229
  class Census {
228
- constructor(type) {
230
+ constructor(type, censusOrigin) {
229
231
  this._censusId = null;
230
232
  this._censusRoot = null;
231
233
  this._censusURI = null;
232
234
  this._size = null;
233
235
  this._type = type;
236
+ if (censusOrigin !== void 0) {
237
+ this._censusOrigin = censusOrigin;
238
+ } else {
239
+ switch (type) {
240
+ case "plain" /* PLAIN */:
241
+ case "weighted" /* WEIGHTED */:
242
+ this._censusOrigin = CensusOrigin.OffchainStatic;
243
+ break;
244
+ case "csp" /* CSP */:
245
+ this._censusOrigin = CensusOrigin.CSP;
246
+ break;
247
+ default:
248
+ throw new Error(`Unknown census type: ${type}`);
249
+ }
250
+ }
234
251
  }
235
252
  get censusId() {
236
253
  return this._censusId;
@@ -251,24 +268,20 @@ class Census {
251
268
  return this._censusRoot !== null && this._censusURI !== null;
252
269
  }
253
270
  /**
254
- * Convert CensusType to CensusOrigin enum for API compatibility
271
+ * Get the census origin (OffchainStatic, OffchainDynamic, Onchain, or CSP)
255
272
  */
256
273
  get censusOrigin() {
257
- switch (this._type) {
258
- case "plain" /* PLAIN */:
259
- case "weighted" /* WEIGHTED */:
260
- return CensusOrigin.CensusOriginMerkleTree;
261
- case "csp" /* CSP */:
262
- return CensusOrigin.CensusOriginCSP;
263
- default:
264
- throw new Error(`Unknown census type: ${this._type}`);
265
- }
274
+ return this._censusOrigin;
266
275
  }
267
276
  }
268
277
 
269
278
  class PlainCensus extends Census {
270
- constructor() {
271
- super(CensusType.PLAIN);
279
+ /**
280
+ * Creates a new PlainCensus
281
+ * @param censusOrigin - The census origin (defaults to OffchainStatic for backward compatibility)
282
+ */
283
+ constructor(censusOrigin) {
284
+ super(CensusType.PLAIN, censusOrigin);
272
285
  this._participants = /* @__PURE__ */ new Set();
273
286
  }
274
287
  /**
@@ -326,8 +339,12 @@ class PlainCensus extends Census {
326
339
  }
327
340
 
328
341
  class WeightedCensus extends Census {
329
- constructor() {
330
- super(CensusType.WEIGHTED);
342
+ /**
343
+ * Creates a new WeightedCensus
344
+ * @param censusOrigin - The census origin (defaults to OffchainStatic for backward compatibility)
345
+ */
346
+ constructor(censusOrigin) {
347
+ super(CensusType.WEIGHTED, censusOrigin);
331
348
  this._participants = /* @__PURE__ */ new Map();
332
349
  }
333
350
  /**
@@ -419,7 +436,7 @@ class WeightedCensus extends Census {
419
436
 
420
437
  class CspCensus extends Census {
421
438
  constructor(publicKey, cspURI, size) {
422
- super(CensusType.CSP);
439
+ super(CensusType.CSP, CensusOrigin.CSP);
423
440
  if (!/^(0x)?[0-9a-fA-F]+$/.test(publicKey)) {
424
441
  throw new Error("Public key is missing or invalid");
425
442
  }
@@ -443,8 +460,16 @@ class CspCensus extends Census {
443
460
  }
444
461
 
445
462
  class PublishedCensus extends Census {
446
- constructor(type, root, uri, size) {
447
- super(type);
463
+ /**
464
+ * Creates a PublishedCensus from existing census data
465
+ * @param type - The census type (PLAIN, WEIGHTED, or CSP)
466
+ * @param root - The census root
467
+ * @param uri - The census URI
468
+ * @param size - The census size (number of participants)
469
+ * @param censusOrigin - The census origin (optional - defaults based on type if not provided)
470
+ */
471
+ constructor(type, root, uri, size, censusOrigin) {
472
+ super(type, censusOrigin);
448
473
  this._censusRoot = root;
449
474
  this._censusURI = uri;
450
475
  this._size = size;
@@ -943,6 +968,8 @@ class ProcessStatusError extends ContractServiceError {
943
968
  }
944
969
  class ProcessCensusError extends ContractServiceError {
945
970
  }
971
+ class CensusNotUpdatable extends ContractServiceError {
972
+ }
946
973
  class ProcessDurationError extends ContractServiceError {
947
974
  }
948
975
  class ProcessStateTransitionError extends ContractServiceError {
@@ -1122,12 +1149,12 @@ class ProcessRegistryService extends SmartContractService {
1122
1149
  cb
1123
1150
  ).catch((err) => console.error("Error setting up ProcessDurationChanged listener:", err));
1124
1151
  }
1125
- onStateRootUpdated(cb) {
1152
+ onStateTransitioned(cb) {
1126
1153
  this.setupEventListener(
1127
1154
  this.contract,
1128
- this.contract.filters.ProcessStateRootUpdated(),
1155
+ this.contract.filters.ProcessStateTransitioned(),
1129
1156
  cb
1130
- ).catch((err) => console.error("Error setting up StateRootUpdated listener:", err));
1157
+ ).catch((err) => console.error("Error setting up ProcessStateTransitioned listener:", err));
1131
1158
  }
1132
1159
  onProcessResultsSet(cb) {
1133
1160
  this.setupEventListener(
@@ -2021,7 +2048,7 @@ class VoteOrchestrationService {
2021
2048
  signature,
2022
2049
  voteId
2023
2050
  };
2024
- if (process.census.censusOrigin === CensusOrigin.CensusOriginCSP) {
2051
+ if (process.census.censusOrigin === CensusOrigin.CSP) {
2025
2052
  voteRequest.censusProof = censusProof;
2026
2053
  }
2027
2054
  await this.submitVoteRequest(voteRequest);
@@ -2137,7 +2164,7 @@ class VoteOrchestrationService {
2137
2164
  * Get census proof based on census origin type
2138
2165
  */
2139
2166
  async getCensusProof(censusOrigin, censusRoot, voterAddress, processId) {
2140
- if (censusOrigin === CensusOrigin.CensusOriginMerkleTree) {
2167
+ if (censusOrigin === CensusOrigin.OffchainStatic || censusOrigin === CensusOrigin.OffchainDynamic || censusOrigin === CensusOrigin.Onchain) {
2141
2168
  if (this.censusProviders.merkle) {
2142
2169
  const proof = await this.censusProviders.merkle({
2143
2170
  censusRoot,
@@ -2151,13 +2178,13 @@ class VoteOrchestrationService {
2151
2178
  root: censusRoot,
2152
2179
  address: voterAddress,
2153
2180
  weight,
2154
- censusOrigin: CensusOrigin.CensusOriginMerkleTree,
2181
+ censusOrigin,
2155
2182
  value: "",
2156
2183
  siblings: ""
2157
2184
  };
2158
2185
  }
2159
2186
  }
2160
- if (censusOrigin === CensusOrigin.CensusOriginCSP) {
2187
+ if (censusOrigin === CensusOrigin.CSP) {
2161
2188
  if (!this.censusProviders.csp) {
2162
2189
  throw new Error(
2163
2190
  "CSP voting requires a CSP census proof provider. Pass one via VoteOrchestrationService(..., { csp: yourFn })."
@@ -2731,7 +2758,7 @@ class DavinciSDK {
2731
2758
  * title: "My Election",
2732
2759
  * description: "A simple election",
2733
2760
  * census: {
2734
- * type: CensusOrigin.CensusOriginMerkleTree,
2761
+ * type: CensusOrigin.OffchainStatic,
2735
2762
  * root: "0x1234...",
2736
2763
  * size: 100,
2737
2764
  * uri: "ipfs://..."
@@ -2818,7 +2845,7 @@ class DavinciSDK {
2818
2845
  * title: "My Election",
2819
2846
  * description: "A simple election",
2820
2847
  * census: {
2821
- * type: CensusOrigin.CensusOriginMerkleTree,
2848
+ * type: CensusOrigin.OffchainStatic,
2822
2849
  * root: "0x1234...",
2823
2850
  * size: 100,
2824
2851
  * uri: "ipfs://your-census-uri"
@@ -3517,6 +3544,7 @@ class DavinciSDK {
3517
3544
 
3518
3545
  exports.BaseService = BaseService;
3519
3546
  exports.Census = Census;
3547
+ exports.CensusNotUpdatable = CensusNotUpdatable;
3520
3548
  exports.CensusOrchestrator = CensusOrchestrator;
3521
3549
  exports.CensusOrigin = CensusOrigin;
3522
3550
  exports.CensusType = CensusType;