@vocdoni/davinci-sdk 0.0.4 → 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/dist/contracts.d.ts +2 -2
- package/dist/index.d.ts +35 -37
- package/dist/index.js +60 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -13
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +60 -13
- package/dist/sequencer.d.ts +6 -27
- package/package.json +2 -2
package/dist/contracts.d.ts
CHANGED
|
@@ -470,8 +470,8 @@ declare class ProcessRegistryService extends SmartContractService {
|
|
|
470
470
|
latestStateRoot: bigint;
|
|
471
471
|
startTime: bigint;
|
|
472
472
|
duration: bigint;
|
|
473
|
-
|
|
474
|
-
|
|
473
|
+
votersCount: bigint;
|
|
474
|
+
overwrittenVotesCount: bigint;
|
|
475
475
|
creationBlock: bigint;
|
|
476
476
|
batchNumber: bigint;
|
|
477
477
|
metadataURI: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -489,36 +489,14 @@ interface GetProcessResponse {
|
|
|
489
489
|
organizationId: string;
|
|
490
490
|
encryptionKey: EncryptionKey;
|
|
491
491
|
stateRoot: string;
|
|
492
|
-
result: string[];
|
|
493
|
-
startTime:
|
|
492
|
+
result: string[] | null;
|
|
493
|
+
startTime: string;
|
|
494
494
|
duration: number;
|
|
495
495
|
metadataURI: string;
|
|
496
496
|
ballotMode: BallotMode;
|
|
497
497
|
census: CensusData;
|
|
498
|
-
|
|
499
|
-
|
|
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;
|
|
@@ -629,7 +607,8 @@ declare class VocdoniSequencerService extends BaseService {
|
|
|
629
607
|
submitVote(vote: VoteRequest): Promise<void>;
|
|
630
608
|
getVoteStatus(processId: string, voteId: string): Promise<VoteStatusResponse>;
|
|
631
609
|
hasAddressVoted(processId: string, address: string): Promise<boolean>;
|
|
632
|
-
|
|
610
|
+
getAddressWeight(processId: string, address: string): Promise<string>;
|
|
611
|
+
isAddressAbleToVote(processId: string, address: string): Promise<boolean>;
|
|
633
612
|
getInfo(): Promise<InfoResponse>;
|
|
634
613
|
pushMetadata(metadata: ElectionMetadata): Promise<string>;
|
|
635
614
|
getMetadata(hashOrUrl: string): Promise<ElectionMetadata>;
|
|
@@ -919,8 +898,8 @@ declare class ProcessRegistryService extends SmartContractService {
|
|
|
919
898
|
latestStateRoot: bigint;
|
|
920
899
|
startTime: bigint;
|
|
921
900
|
duration: bigint;
|
|
922
|
-
|
|
923
|
-
|
|
901
|
+
votersCount: bigint;
|
|
902
|
+
overwrittenVotesCount: bigint;
|
|
924
903
|
creationBlock: bigint;
|
|
925
904
|
batchNumber: bigint;
|
|
926
905
|
metadataURI: string;
|
|
@@ -1316,9 +1295,9 @@ interface ProcessInfo extends BaseProcess {
|
|
|
1316
1295
|
/** Process results (array of BigInt values) */
|
|
1317
1296
|
result: bigint[];
|
|
1318
1297
|
/** Number of votes cast */
|
|
1319
|
-
|
|
1298
|
+
votersCount: number;
|
|
1320
1299
|
/** Number of vote overwrites */
|
|
1321
|
-
|
|
1300
|
+
overwrittenVotesCount: number;
|
|
1322
1301
|
/** Metadata URI */
|
|
1323
1302
|
metadataURI: string;
|
|
1324
1303
|
/** Raw contract data (for advanced users) */
|
|
@@ -2216,22 +2195,41 @@ declare class DavinciSDK {
|
|
|
2216
2195
|
*/
|
|
2217
2196
|
hasAddressVoted(processId: string, address: string): Promise<boolean>;
|
|
2218
2197
|
/**
|
|
2219
|
-
* Check if an address is able to vote in a process
|
|
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.
|
|
2220
2219
|
*
|
|
2221
2220
|
* Does NOT require a provider - uses API calls only.
|
|
2222
2221
|
*
|
|
2223
2222
|
* @param processId - The process ID
|
|
2224
2223
|
* @param address - The voter's address
|
|
2225
|
-
* @returns Promise resolving to
|
|
2224
|
+
* @returns Promise resolving to the address weight as a string
|
|
2226
2225
|
*
|
|
2227
2226
|
* @example
|
|
2228
2227
|
* ```typescript
|
|
2229
|
-
* const
|
|
2230
|
-
* console.log("Address:",
|
|
2231
|
-
* console.log("Weight:", participantInfo.weight);
|
|
2228
|
+
* const weight = await sdk.getAddressWeight(processId, "0x1234567890abcdef...");
|
|
2229
|
+
* console.log("Address weight:", weight);
|
|
2232
2230
|
* ```
|
|
2233
2231
|
*/
|
|
2234
|
-
|
|
2232
|
+
getAddressWeight(processId: string, address: string): Promise<string>;
|
|
2235
2233
|
/**
|
|
2236
2234
|
* Watch vote status changes in real-time using an async generator.
|
|
2237
2235
|
* This method yields each status change as it happens, perfect for showing
|
package/dist/index.js
CHANGED
|
@@ -565,11 +565,26 @@ class VocdoniSequencerService extends BaseService {
|
|
|
565
565
|
throw error;
|
|
566
566
|
}
|
|
567
567
|
}
|
|
568
|
-
|
|
569
|
-
|
|
568
|
+
async getAddressWeight(processId, address) {
|
|
569
|
+
const participant = await this.request({
|
|
570
570
|
method: "GET",
|
|
571
571
|
url: `/processes/${processId}/participants/${address}`
|
|
572
572
|
});
|
|
573
|
+
return participant.weight;
|
|
574
|
+
}
|
|
575
|
+
async isAddressAbleToVote(processId, address) {
|
|
576
|
+
try {
|
|
577
|
+
await this.request({
|
|
578
|
+
method: "GET",
|
|
579
|
+
url: `/processes/${processId}/participants/${address}`
|
|
580
|
+
});
|
|
581
|
+
return true;
|
|
582
|
+
} catch (error) {
|
|
583
|
+
if (error?.code === 40001) {
|
|
584
|
+
return false;
|
|
585
|
+
}
|
|
586
|
+
throw error;
|
|
587
|
+
}
|
|
573
588
|
}
|
|
574
589
|
getInfo() {
|
|
575
590
|
return this.request({
|
|
@@ -1218,8 +1233,8 @@ class ProcessOrchestrationService {
|
|
|
1218
1233
|
duration,
|
|
1219
1234
|
timeRemaining,
|
|
1220
1235
|
result: rawProcess.result,
|
|
1221
|
-
|
|
1222
|
-
|
|
1236
|
+
votersCount: Number(rawProcess.votersCount),
|
|
1237
|
+
overwrittenVotesCount: Number(rawProcess.overwrittenVotesCount),
|
|
1223
1238
|
metadataURI: rawProcess.metadataURI,
|
|
1224
1239
|
raw: rawProcess
|
|
1225
1240
|
};
|
|
@@ -2033,9 +2048,15 @@ class VoteOrchestrationService {
|
|
|
2033
2048
|
assertMerkleCensusProof(proof);
|
|
2034
2049
|
return proof;
|
|
2035
2050
|
} else {
|
|
2036
|
-
const
|
|
2037
|
-
|
|
2038
|
-
|
|
2051
|
+
const weight = await this.apiService.sequencer.getAddressWeight(processId, voterAddress);
|
|
2052
|
+
return {
|
|
2053
|
+
root: censusRoot,
|
|
2054
|
+
address: voterAddress,
|
|
2055
|
+
weight,
|
|
2056
|
+
censusOrigin: CensusOrigin.CensusOriginMerkleTree,
|
|
2057
|
+
value: "",
|
|
2058
|
+
siblings: ""
|
|
2059
|
+
};
|
|
2039
2060
|
}
|
|
2040
2061
|
}
|
|
2041
2062
|
if (censusOrigin === CensusOrigin.CensusOriginCSP) {
|
|
@@ -2845,29 +2866,55 @@ class DavinciSDK {
|
|
|
2845
2866
|
return this.voteOrchestrator.hasAddressVoted(processId, address);
|
|
2846
2867
|
}
|
|
2847
2868
|
/**
|
|
2848
|
-
* Check if an address is able to vote in a process
|
|
2869
|
+
* Check if an address is able to vote in a process (i.e., is in the census).
|
|
2849
2870
|
*
|
|
2850
2871
|
* Does NOT require a provider - uses API calls only.
|
|
2851
2872
|
*
|
|
2852
2873
|
* @param processId - The process ID
|
|
2853
2874
|
* @param address - The voter's address
|
|
2854
|
-
* @returns Promise resolving to
|
|
2875
|
+
* @returns Promise resolving to boolean indicating if the address can vote
|
|
2855
2876
|
*
|
|
2856
2877
|
* @example
|
|
2857
2878
|
* ```typescript
|
|
2858
|
-
* const
|
|
2859
|
-
*
|
|
2860
|
-
*
|
|
2879
|
+
* const canVote = await sdk.isAddressAbleToVote(processId, "0x1234567890abcdef...");
|
|
2880
|
+
* if (canVote) {
|
|
2881
|
+
* console.log("This address can vote");
|
|
2882
|
+
* } else {
|
|
2883
|
+
* console.log("This address is not in the census");
|
|
2884
|
+
* }
|
|
2861
2885
|
* ```
|
|
2862
2886
|
*/
|
|
2863
2887
|
async isAddressAbleToVote(processId, address) {
|
|
2864
2888
|
if (!this.initialized) {
|
|
2865
2889
|
throw new Error(
|
|
2866
|
-
"SDK must be initialized before checking
|
|
2890
|
+
"SDK must be initialized before checking if address can vote. Call sdk.init() first."
|
|
2867
2891
|
);
|
|
2868
2892
|
}
|
|
2869
2893
|
return this.apiService.sequencer.isAddressAbleToVote(processId, address);
|
|
2870
2894
|
}
|
|
2895
|
+
/**
|
|
2896
|
+
* Get the voting weight for an address in a process.
|
|
2897
|
+
*
|
|
2898
|
+
* Does NOT require a provider - uses API calls only.
|
|
2899
|
+
*
|
|
2900
|
+
* @param processId - The process ID
|
|
2901
|
+
* @param address - The voter's address
|
|
2902
|
+
* @returns Promise resolving to the address weight as a string
|
|
2903
|
+
*
|
|
2904
|
+
* @example
|
|
2905
|
+
* ```typescript
|
|
2906
|
+
* const weight = await sdk.getAddressWeight(processId, "0x1234567890abcdef...");
|
|
2907
|
+
* console.log("Address weight:", weight);
|
|
2908
|
+
* ```
|
|
2909
|
+
*/
|
|
2910
|
+
async getAddressWeight(processId, address) {
|
|
2911
|
+
if (!this.initialized) {
|
|
2912
|
+
throw new Error(
|
|
2913
|
+
"SDK must be initialized before getting address weight. Call sdk.init() first."
|
|
2914
|
+
);
|
|
2915
|
+
}
|
|
2916
|
+
return this.apiService.sequencer.getAddressWeight(processId, address);
|
|
2917
|
+
}
|
|
2871
2918
|
/**
|
|
2872
2919
|
* Watch vote status changes in real-time using an async generator.
|
|
2873
2920
|
* This method yields each status change as it happens, perfect for showing
|