@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 +3 -3
- package/dist/contracts.d.ts +22 -10
- package/dist/index.d.ts +50 -20
- package/dist/index.js +59 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -32
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +59 -31
- package/dist/sequencer.d.ts +12 -7
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -192,18 +192,20 @@ class VocdoniCensusService extends BaseService {
|
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
var CensusOrigin = /* @__PURE__ */ ((CensusOrigin2) => {
|
|
195
|
-
CensusOrigin2[CensusOrigin2["
|
|
196
|
-
CensusOrigin2[CensusOrigin2["
|
|
195
|
+
CensusOrigin2[CensusOrigin2["OffchainStatic"] = 1] = "OffchainStatic";
|
|
196
|
+
CensusOrigin2[CensusOrigin2["OffchainDynamic"] = 2] = "OffchainDynamic";
|
|
197
|
+
CensusOrigin2[CensusOrigin2["Onchain"] = 3] = "Onchain";
|
|
198
|
+
CensusOrigin2[CensusOrigin2["CSP"] = 4] = "CSP";
|
|
197
199
|
return CensusOrigin2;
|
|
198
200
|
})(CensusOrigin || {});
|
|
199
201
|
function isBaseCensusProof(proof) {
|
|
200
202
|
return !!proof && typeof proof.root === "string" && typeof proof.address === "string" && typeof proof.censusOrigin === "number" && Object.values(CensusOrigin).includes(proof.censusOrigin);
|
|
201
203
|
}
|
|
202
204
|
function isMerkleCensusProof(proof) {
|
|
203
|
-
return isBaseCensusProof(proof) && proof.censusOrigin === 1 /*
|
|
205
|
+
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";
|
|
204
206
|
}
|
|
205
207
|
function isCSPCensusProof(proof) {
|
|
206
|
-
return isBaseCensusProof(proof) && proof.censusOrigin ===
|
|
208
|
+
return isBaseCensusProof(proof) && proof.censusOrigin === 4 /* CSP */ && typeof proof.weight === "string" && typeof proof.processId === "string" && typeof proof.publicKey === "string" && typeof proof.signature === "string";
|
|
207
209
|
}
|
|
208
210
|
function assertMerkleCensusProof(proof) {
|
|
209
211
|
if (!isMerkleCensusProof(proof)) {
|
|
@@ -223,12 +225,27 @@ var CensusType = /* @__PURE__ */ ((CensusType2) => {
|
|
|
223
225
|
return CensusType2;
|
|
224
226
|
})(CensusType || {});
|
|
225
227
|
class Census {
|
|
226
|
-
constructor(type) {
|
|
228
|
+
constructor(type, censusOrigin) {
|
|
227
229
|
this._censusId = null;
|
|
228
230
|
this._censusRoot = null;
|
|
229
231
|
this._censusURI = null;
|
|
230
232
|
this._size = null;
|
|
231
233
|
this._type = type;
|
|
234
|
+
if (censusOrigin !== void 0) {
|
|
235
|
+
this._censusOrigin = censusOrigin;
|
|
236
|
+
} else {
|
|
237
|
+
switch (type) {
|
|
238
|
+
case "plain" /* PLAIN */:
|
|
239
|
+
case "weighted" /* WEIGHTED */:
|
|
240
|
+
this._censusOrigin = CensusOrigin.OffchainStatic;
|
|
241
|
+
break;
|
|
242
|
+
case "csp" /* CSP */:
|
|
243
|
+
this._censusOrigin = CensusOrigin.CSP;
|
|
244
|
+
break;
|
|
245
|
+
default:
|
|
246
|
+
throw new Error(`Unknown census type: ${type}`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
232
249
|
}
|
|
233
250
|
get censusId() {
|
|
234
251
|
return this._censusId;
|
|
@@ -249,24 +266,20 @@ class Census {
|
|
|
249
266
|
return this._censusRoot !== null && this._censusURI !== null;
|
|
250
267
|
}
|
|
251
268
|
/**
|
|
252
|
-
*
|
|
269
|
+
* Get the census origin (OffchainStatic, OffchainDynamic, Onchain, or CSP)
|
|
253
270
|
*/
|
|
254
271
|
get censusOrigin() {
|
|
255
|
-
|
|
256
|
-
case "plain" /* PLAIN */:
|
|
257
|
-
case "weighted" /* WEIGHTED */:
|
|
258
|
-
return CensusOrigin.CensusOriginMerkleTree;
|
|
259
|
-
case "csp" /* CSP */:
|
|
260
|
-
return CensusOrigin.CensusOriginCSP;
|
|
261
|
-
default:
|
|
262
|
-
throw new Error(`Unknown census type: ${this._type}`);
|
|
263
|
-
}
|
|
272
|
+
return this._censusOrigin;
|
|
264
273
|
}
|
|
265
274
|
}
|
|
266
275
|
|
|
267
276
|
class PlainCensus extends Census {
|
|
268
|
-
|
|
269
|
-
|
|
277
|
+
/**
|
|
278
|
+
* Creates a new PlainCensus
|
|
279
|
+
* @param censusOrigin - The census origin (defaults to OffchainStatic for backward compatibility)
|
|
280
|
+
*/
|
|
281
|
+
constructor(censusOrigin) {
|
|
282
|
+
super(CensusType.PLAIN, censusOrigin);
|
|
270
283
|
this._participants = /* @__PURE__ */ new Set();
|
|
271
284
|
}
|
|
272
285
|
/**
|
|
@@ -324,8 +337,12 @@ class PlainCensus extends Census {
|
|
|
324
337
|
}
|
|
325
338
|
|
|
326
339
|
class WeightedCensus extends Census {
|
|
327
|
-
|
|
328
|
-
|
|
340
|
+
/**
|
|
341
|
+
* Creates a new WeightedCensus
|
|
342
|
+
* @param censusOrigin - The census origin (defaults to OffchainStatic for backward compatibility)
|
|
343
|
+
*/
|
|
344
|
+
constructor(censusOrigin) {
|
|
345
|
+
super(CensusType.WEIGHTED, censusOrigin);
|
|
329
346
|
this._participants = /* @__PURE__ */ new Map();
|
|
330
347
|
}
|
|
331
348
|
/**
|
|
@@ -417,7 +434,7 @@ class WeightedCensus extends Census {
|
|
|
417
434
|
|
|
418
435
|
class CspCensus extends Census {
|
|
419
436
|
constructor(publicKey, cspURI, size) {
|
|
420
|
-
super(CensusType.CSP);
|
|
437
|
+
super(CensusType.CSP, CensusOrigin.CSP);
|
|
421
438
|
if (!/^(0x)?[0-9a-fA-F]+$/.test(publicKey)) {
|
|
422
439
|
throw new Error("Public key is missing or invalid");
|
|
423
440
|
}
|
|
@@ -441,8 +458,16 @@ class CspCensus extends Census {
|
|
|
441
458
|
}
|
|
442
459
|
|
|
443
460
|
class PublishedCensus extends Census {
|
|
444
|
-
|
|
445
|
-
|
|
461
|
+
/**
|
|
462
|
+
* Creates a PublishedCensus from existing census data
|
|
463
|
+
* @param type - The census type (PLAIN, WEIGHTED, or CSP)
|
|
464
|
+
* @param root - The census root
|
|
465
|
+
* @param uri - The census URI
|
|
466
|
+
* @param size - The census size (number of participants)
|
|
467
|
+
* @param censusOrigin - The census origin (optional - defaults based on type if not provided)
|
|
468
|
+
*/
|
|
469
|
+
constructor(type, root, uri, size, censusOrigin) {
|
|
470
|
+
super(type, censusOrigin);
|
|
446
471
|
this._censusRoot = root;
|
|
447
472
|
this._censusURI = uri;
|
|
448
473
|
this._size = size;
|
|
@@ -941,6 +966,8 @@ class ProcessStatusError extends ContractServiceError {
|
|
|
941
966
|
}
|
|
942
967
|
class ProcessCensusError extends ContractServiceError {
|
|
943
968
|
}
|
|
969
|
+
class CensusNotUpdatable extends ContractServiceError {
|
|
970
|
+
}
|
|
944
971
|
class ProcessDurationError extends ContractServiceError {
|
|
945
972
|
}
|
|
946
973
|
class ProcessStateTransitionError extends ContractServiceError {
|
|
@@ -1120,12 +1147,12 @@ class ProcessRegistryService extends SmartContractService {
|
|
|
1120
1147
|
cb
|
|
1121
1148
|
).catch((err) => console.error("Error setting up ProcessDurationChanged listener:", err));
|
|
1122
1149
|
}
|
|
1123
|
-
|
|
1150
|
+
onStateTransitioned(cb) {
|
|
1124
1151
|
this.setupEventListener(
|
|
1125
1152
|
this.contract,
|
|
1126
|
-
this.contract.filters.
|
|
1153
|
+
this.contract.filters.ProcessStateTransitioned(),
|
|
1127
1154
|
cb
|
|
1128
|
-
).catch((err) => console.error("Error setting up
|
|
1155
|
+
).catch((err) => console.error("Error setting up ProcessStateTransitioned listener:", err));
|
|
1129
1156
|
}
|
|
1130
1157
|
onProcessResultsSet(cb) {
|
|
1131
1158
|
this.setupEventListener(
|
|
@@ -2019,7 +2046,7 @@ class VoteOrchestrationService {
|
|
|
2019
2046
|
signature,
|
|
2020
2047
|
voteId
|
|
2021
2048
|
};
|
|
2022
|
-
if (process.census.censusOrigin === CensusOrigin.
|
|
2049
|
+
if (process.census.censusOrigin === CensusOrigin.CSP) {
|
|
2023
2050
|
voteRequest.censusProof = censusProof;
|
|
2024
2051
|
}
|
|
2025
2052
|
await this.submitVoteRequest(voteRequest);
|
|
@@ -2135,7 +2162,7 @@ class VoteOrchestrationService {
|
|
|
2135
2162
|
* Get census proof based on census origin type
|
|
2136
2163
|
*/
|
|
2137
2164
|
async getCensusProof(censusOrigin, censusRoot, voterAddress, processId) {
|
|
2138
|
-
if (censusOrigin === CensusOrigin.
|
|
2165
|
+
if (censusOrigin === CensusOrigin.OffchainStatic || censusOrigin === CensusOrigin.OffchainDynamic || censusOrigin === CensusOrigin.Onchain) {
|
|
2139
2166
|
if (this.censusProviders.merkle) {
|
|
2140
2167
|
const proof = await this.censusProviders.merkle({
|
|
2141
2168
|
censusRoot,
|
|
@@ -2149,13 +2176,13 @@ class VoteOrchestrationService {
|
|
|
2149
2176
|
root: censusRoot,
|
|
2150
2177
|
address: voterAddress,
|
|
2151
2178
|
weight,
|
|
2152
|
-
censusOrigin
|
|
2179
|
+
censusOrigin,
|
|
2153
2180
|
value: "",
|
|
2154
2181
|
siblings: ""
|
|
2155
2182
|
};
|
|
2156
2183
|
}
|
|
2157
2184
|
}
|
|
2158
|
-
if (censusOrigin === CensusOrigin.
|
|
2185
|
+
if (censusOrigin === CensusOrigin.CSP) {
|
|
2159
2186
|
if (!this.censusProviders.csp) {
|
|
2160
2187
|
throw new Error(
|
|
2161
2188
|
"CSP voting requires a CSP census proof provider. Pass one via VoteOrchestrationService(..., { csp: yourFn })."
|
|
@@ -2729,7 +2756,7 @@ class DavinciSDK {
|
|
|
2729
2756
|
* title: "My Election",
|
|
2730
2757
|
* description: "A simple election",
|
|
2731
2758
|
* census: {
|
|
2732
|
-
* type: CensusOrigin.
|
|
2759
|
+
* type: CensusOrigin.OffchainStatic,
|
|
2733
2760
|
* root: "0x1234...",
|
|
2734
2761
|
* size: 100,
|
|
2735
2762
|
* uri: "ipfs://..."
|
|
@@ -2816,7 +2843,7 @@ class DavinciSDK {
|
|
|
2816
2843
|
* title: "My Election",
|
|
2817
2844
|
* description: "A simple election",
|
|
2818
2845
|
* census: {
|
|
2819
|
-
* type: CensusOrigin.
|
|
2846
|
+
* type: CensusOrigin.OffchainStatic,
|
|
2820
2847
|
* root: "0x1234...",
|
|
2821
2848
|
* size: 100,
|
|
2822
2849
|
* uri: "ipfs://your-census-uri"
|
|
@@ -3513,5 +3540,5 @@ class DavinciSDK {
|
|
|
3513
3540
|
}
|
|
3514
3541
|
}
|
|
3515
3542
|
|
|
3516
|
-
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 };
|
|
3543
|
+
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 };
|
|
3517
3544
|
//# sourceMappingURL=index.mjs.map
|