@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.umd.js
CHANGED
|
@@ -193,18 +193,20 @@
|
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
var CensusOrigin = /* @__PURE__ */ ((CensusOrigin2) => {
|
|
196
|
-
CensusOrigin2[CensusOrigin2["
|
|
197
|
-
CensusOrigin2[CensusOrigin2["
|
|
196
|
+
CensusOrigin2[CensusOrigin2["OffchainStatic"] = 1] = "OffchainStatic";
|
|
197
|
+
CensusOrigin2[CensusOrigin2["OffchainDynamic"] = 2] = "OffchainDynamic";
|
|
198
|
+
CensusOrigin2[CensusOrigin2["Onchain"] = 3] = "Onchain";
|
|
199
|
+
CensusOrigin2[CensusOrigin2["CSP"] = 4] = "CSP";
|
|
198
200
|
return CensusOrigin2;
|
|
199
201
|
})(CensusOrigin || {});
|
|
200
202
|
function isBaseCensusProof(proof) {
|
|
201
203
|
return !!proof && typeof proof.root === "string" && typeof proof.address === "string" && typeof proof.censusOrigin === "number" && Object.values(CensusOrigin).includes(proof.censusOrigin);
|
|
202
204
|
}
|
|
203
205
|
function isMerkleCensusProof(proof) {
|
|
204
|
-
return isBaseCensusProof(proof) && proof.censusOrigin === 1 /*
|
|
206
|
+
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";
|
|
205
207
|
}
|
|
206
208
|
function isCSPCensusProof(proof) {
|
|
207
|
-
return isBaseCensusProof(proof) && proof.censusOrigin ===
|
|
209
|
+
return isBaseCensusProof(proof) && proof.censusOrigin === 4 /* CSP */ && typeof proof.weight === "string" && typeof proof.processId === "string" && typeof proof.publicKey === "string" && typeof proof.signature === "string";
|
|
208
210
|
}
|
|
209
211
|
function assertMerkleCensusProof(proof) {
|
|
210
212
|
if (!isMerkleCensusProof(proof)) {
|
|
@@ -224,12 +226,27 @@
|
|
|
224
226
|
return CensusType2;
|
|
225
227
|
})(CensusType || {});
|
|
226
228
|
class Census {
|
|
227
|
-
constructor(type) {
|
|
229
|
+
constructor(type, censusOrigin) {
|
|
228
230
|
this._censusId = null;
|
|
229
231
|
this._censusRoot = null;
|
|
230
232
|
this._censusURI = null;
|
|
231
233
|
this._size = null;
|
|
232
234
|
this._type = type;
|
|
235
|
+
if (censusOrigin !== void 0) {
|
|
236
|
+
this._censusOrigin = censusOrigin;
|
|
237
|
+
} else {
|
|
238
|
+
switch (type) {
|
|
239
|
+
case "plain" /* PLAIN */:
|
|
240
|
+
case "weighted" /* WEIGHTED */:
|
|
241
|
+
this._censusOrigin = CensusOrigin.OffchainStatic;
|
|
242
|
+
break;
|
|
243
|
+
case "csp" /* CSP */:
|
|
244
|
+
this._censusOrigin = CensusOrigin.CSP;
|
|
245
|
+
break;
|
|
246
|
+
default:
|
|
247
|
+
throw new Error(`Unknown census type: ${type}`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
233
250
|
}
|
|
234
251
|
get censusId() {
|
|
235
252
|
return this._censusId;
|
|
@@ -250,24 +267,20 @@
|
|
|
250
267
|
return this._censusRoot !== null && this._censusURI !== null;
|
|
251
268
|
}
|
|
252
269
|
/**
|
|
253
|
-
*
|
|
270
|
+
* Get the census origin (OffchainStatic, OffchainDynamic, Onchain, or CSP)
|
|
254
271
|
*/
|
|
255
272
|
get censusOrigin() {
|
|
256
|
-
|
|
257
|
-
case "plain" /* PLAIN */:
|
|
258
|
-
case "weighted" /* WEIGHTED */:
|
|
259
|
-
return CensusOrigin.CensusOriginMerkleTree;
|
|
260
|
-
case "csp" /* CSP */:
|
|
261
|
-
return CensusOrigin.CensusOriginCSP;
|
|
262
|
-
default:
|
|
263
|
-
throw new Error(`Unknown census type: ${this._type}`);
|
|
264
|
-
}
|
|
273
|
+
return this._censusOrigin;
|
|
265
274
|
}
|
|
266
275
|
}
|
|
267
276
|
|
|
268
277
|
class PlainCensus extends Census {
|
|
269
|
-
|
|
270
|
-
|
|
278
|
+
/**
|
|
279
|
+
* Creates a new PlainCensus
|
|
280
|
+
* @param censusOrigin - The census origin (defaults to OffchainStatic for backward compatibility)
|
|
281
|
+
*/
|
|
282
|
+
constructor(censusOrigin) {
|
|
283
|
+
super(CensusType.PLAIN, censusOrigin);
|
|
271
284
|
this._participants = /* @__PURE__ */ new Set();
|
|
272
285
|
}
|
|
273
286
|
/**
|
|
@@ -325,8 +338,12 @@
|
|
|
325
338
|
}
|
|
326
339
|
|
|
327
340
|
class WeightedCensus extends Census {
|
|
328
|
-
|
|
329
|
-
|
|
341
|
+
/**
|
|
342
|
+
* Creates a new WeightedCensus
|
|
343
|
+
* @param censusOrigin - The census origin (defaults to OffchainStatic for backward compatibility)
|
|
344
|
+
*/
|
|
345
|
+
constructor(censusOrigin) {
|
|
346
|
+
super(CensusType.WEIGHTED, censusOrigin);
|
|
330
347
|
this._participants = /* @__PURE__ */ new Map();
|
|
331
348
|
}
|
|
332
349
|
/**
|
|
@@ -418,7 +435,7 @@
|
|
|
418
435
|
|
|
419
436
|
class CspCensus extends Census {
|
|
420
437
|
constructor(publicKey, cspURI, size) {
|
|
421
|
-
super(CensusType.CSP);
|
|
438
|
+
super(CensusType.CSP, CensusOrigin.CSP);
|
|
422
439
|
if (!/^(0x)?[0-9a-fA-F]+$/.test(publicKey)) {
|
|
423
440
|
throw new Error("Public key is missing or invalid");
|
|
424
441
|
}
|
|
@@ -442,8 +459,16 @@
|
|
|
442
459
|
}
|
|
443
460
|
|
|
444
461
|
class PublishedCensus extends Census {
|
|
445
|
-
|
|
446
|
-
|
|
462
|
+
/**
|
|
463
|
+
* Creates a PublishedCensus from existing census data
|
|
464
|
+
* @param type - The census type (PLAIN, WEIGHTED, or CSP)
|
|
465
|
+
* @param root - The census root
|
|
466
|
+
* @param uri - The census URI
|
|
467
|
+
* @param size - The census size (number of participants)
|
|
468
|
+
* @param censusOrigin - The census origin (optional - defaults based on type if not provided)
|
|
469
|
+
*/
|
|
470
|
+
constructor(type, root, uri, size, censusOrigin) {
|
|
471
|
+
super(type, censusOrigin);
|
|
447
472
|
this._censusRoot = root;
|
|
448
473
|
this._censusURI = uri;
|
|
449
474
|
this._size = size;
|
|
@@ -942,6 +967,8 @@
|
|
|
942
967
|
}
|
|
943
968
|
class ProcessCensusError extends ContractServiceError {
|
|
944
969
|
}
|
|
970
|
+
class CensusNotUpdatable extends ContractServiceError {
|
|
971
|
+
}
|
|
945
972
|
class ProcessDurationError extends ContractServiceError {
|
|
946
973
|
}
|
|
947
974
|
class ProcessStateTransitionError extends ContractServiceError {
|
|
@@ -1121,12 +1148,12 @@
|
|
|
1121
1148
|
cb
|
|
1122
1149
|
).catch((err) => console.error("Error setting up ProcessDurationChanged listener:", err));
|
|
1123
1150
|
}
|
|
1124
|
-
|
|
1151
|
+
onStateTransitioned(cb) {
|
|
1125
1152
|
this.setupEventListener(
|
|
1126
1153
|
this.contract,
|
|
1127
|
-
this.contract.filters.
|
|
1154
|
+
this.contract.filters.ProcessStateTransitioned(),
|
|
1128
1155
|
cb
|
|
1129
|
-
).catch((err) => console.error("Error setting up
|
|
1156
|
+
).catch((err) => console.error("Error setting up ProcessStateTransitioned listener:", err));
|
|
1130
1157
|
}
|
|
1131
1158
|
onProcessResultsSet(cb) {
|
|
1132
1159
|
this.setupEventListener(
|
|
@@ -2020,7 +2047,7 @@
|
|
|
2020
2047
|
signature,
|
|
2021
2048
|
voteId
|
|
2022
2049
|
};
|
|
2023
|
-
if (process.census.censusOrigin === CensusOrigin.
|
|
2050
|
+
if (process.census.censusOrigin === CensusOrigin.CSP) {
|
|
2024
2051
|
voteRequest.censusProof = censusProof;
|
|
2025
2052
|
}
|
|
2026
2053
|
await this.submitVoteRequest(voteRequest);
|
|
@@ -2136,7 +2163,7 @@
|
|
|
2136
2163
|
* Get census proof based on census origin type
|
|
2137
2164
|
*/
|
|
2138
2165
|
async getCensusProof(censusOrigin, censusRoot, voterAddress, processId) {
|
|
2139
|
-
if (censusOrigin === CensusOrigin.
|
|
2166
|
+
if (censusOrigin === CensusOrigin.OffchainStatic || censusOrigin === CensusOrigin.OffchainDynamic || censusOrigin === CensusOrigin.Onchain) {
|
|
2140
2167
|
if (this.censusProviders.merkle) {
|
|
2141
2168
|
const proof = await this.censusProviders.merkle({
|
|
2142
2169
|
censusRoot,
|
|
@@ -2150,13 +2177,13 @@
|
|
|
2150
2177
|
root: censusRoot,
|
|
2151
2178
|
address: voterAddress,
|
|
2152
2179
|
weight,
|
|
2153
|
-
censusOrigin
|
|
2180
|
+
censusOrigin,
|
|
2154
2181
|
value: "",
|
|
2155
2182
|
siblings: ""
|
|
2156
2183
|
};
|
|
2157
2184
|
}
|
|
2158
2185
|
}
|
|
2159
|
-
if (censusOrigin === CensusOrigin.
|
|
2186
|
+
if (censusOrigin === CensusOrigin.CSP) {
|
|
2160
2187
|
if (!this.censusProviders.csp) {
|
|
2161
2188
|
throw new Error(
|
|
2162
2189
|
"CSP voting requires a CSP census proof provider. Pass one via VoteOrchestrationService(..., { csp: yourFn })."
|
|
@@ -2730,7 +2757,7 @@
|
|
|
2730
2757
|
* title: "My Election",
|
|
2731
2758
|
* description: "A simple election",
|
|
2732
2759
|
* census: {
|
|
2733
|
-
* type: CensusOrigin.
|
|
2760
|
+
* type: CensusOrigin.OffchainStatic,
|
|
2734
2761
|
* root: "0x1234...",
|
|
2735
2762
|
* size: 100,
|
|
2736
2763
|
* uri: "ipfs://..."
|
|
@@ -2817,7 +2844,7 @@
|
|
|
2817
2844
|
* title: "My Election",
|
|
2818
2845
|
* description: "A simple election",
|
|
2819
2846
|
* census: {
|
|
2820
|
-
* type: CensusOrigin.
|
|
2847
|
+
* type: CensusOrigin.OffchainStatic,
|
|
2821
2848
|
* root: "0x1234...",
|
|
2822
2849
|
* size: 100,
|
|
2823
2850
|
* uri: "ipfs://your-census-uri"
|
|
@@ -3516,6 +3543,7 @@
|
|
|
3516
3543
|
|
|
3517
3544
|
exports.BaseService = BaseService;
|
|
3518
3545
|
exports.Census = Census;
|
|
3546
|
+
exports.CensusNotUpdatable = CensusNotUpdatable;
|
|
3519
3547
|
exports.CensusOrchestrator = CensusOrchestrator;
|
|
3520
3548
|
exports.CensusOrigin = CensusOrigin;
|
|
3521
3549
|
exports.CensusType = CensusType;
|
package/dist/sequencer.d.ts
CHANGED
|
@@ -99,10 +99,14 @@ declare class BaseService {
|
|
|
99
99
|
* Census origin types
|
|
100
100
|
*/
|
|
101
101
|
declare enum CensusOrigin {
|
|
102
|
-
/**
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
|
|
102
|
+
/** Offchain static Merkle Tree census */
|
|
103
|
+
OffchainStatic = 1,
|
|
104
|
+
/** Offchain dynamic Merkle Tree census */
|
|
105
|
+
OffchainDynamic = 2,
|
|
106
|
+
/** Onchain Merkle Tree census */
|
|
107
|
+
Onchain = 3,
|
|
108
|
+
/** Credential Service Provider (CSP) census using EdDSA BLS12-377 */
|
|
109
|
+
CSP = 4
|
|
106
110
|
}
|
|
107
111
|
interface BaseCensusProof {
|
|
108
112
|
/** The Merkle root (hex-prefixed). */
|
|
@@ -111,18 +115,18 @@ interface BaseCensusProof {
|
|
|
111
115
|
address: string;
|
|
112
116
|
/** The weight as a decimal string. */
|
|
113
117
|
weight: string;
|
|
114
|
-
/** Census origin type:
|
|
118
|
+
/** Census origin type: OffchainStatic/OffchainDynamic/Onchain for merkle proofs, CSP for csp proofs */
|
|
115
119
|
censusOrigin: CensusOrigin;
|
|
116
120
|
}
|
|
117
121
|
interface MerkleCensusProof extends BaseCensusProof {
|
|
118
|
-
censusOrigin: CensusOrigin.
|
|
122
|
+
censusOrigin: CensusOrigin.OffchainStatic | CensusOrigin.OffchainDynamic | CensusOrigin.Onchain;
|
|
119
123
|
/** The leaf value (hex-prefixed weight). */
|
|
120
124
|
value: string;
|
|
121
125
|
/** The serialized sibling path (hex-prefixed). */
|
|
122
126
|
siblings: string;
|
|
123
127
|
}
|
|
124
128
|
interface CSPCensusProof extends BaseCensusProof {
|
|
125
|
-
censusOrigin: CensusOrigin.
|
|
129
|
+
censusOrigin: CensusOrigin.CSP;
|
|
126
130
|
/** The process id signed with the address (hex-prefixed). */
|
|
127
131
|
processId: string;
|
|
128
132
|
/** The public key of the csp (hex-prefixed). */
|
|
@@ -181,6 +185,7 @@ interface GetProcessResponse {
|
|
|
181
185
|
ballotMode: BallotMode;
|
|
182
186
|
census: CensusData;
|
|
183
187
|
votersCount: string;
|
|
188
|
+
maxVoters: string;
|
|
184
189
|
overwrittenVotesCount: string;
|
|
185
190
|
isAcceptingVotes: boolean;
|
|
186
191
|
sequencerStats: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vocdoni/davinci-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"@ethereumjs/common": "^4.4.0",
|
|
75
|
-
"@vocdoni/davinci-contracts": "0.0.
|
|
75
|
+
"@vocdoni/davinci-contracts": "0.0.31",
|
|
76
76
|
"axios": "^1.8.4",
|
|
77
77
|
"ethers": "^6.7.1",
|
|
78
78
|
"snarkjs": "^0.7.5"
|