@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/index.mjs CHANGED
@@ -563,11 +563,26 @@ class VocdoniSequencerService extends BaseService {
563
563
  throw error;
564
564
  }
565
565
  }
566
- isAddressAbleToVote(processId, address) {
567
- return this.request({
566
+ async getAddressWeight(processId, address) {
567
+ const participant = await this.request({
568
568
  method: "GET",
569
569
  url: `/processes/${processId}/participants/${address}`
570
570
  });
571
+ return participant.weight;
572
+ }
573
+ async isAddressAbleToVote(processId, address) {
574
+ try {
575
+ await this.request({
576
+ method: "GET",
577
+ url: `/processes/${processId}/participants/${address}`
578
+ });
579
+ return true;
580
+ } catch (error) {
581
+ if (error?.code === 40001) {
582
+ return false;
583
+ }
584
+ throw error;
585
+ }
571
586
  }
572
587
  getInfo() {
573
588
  return this.request({
@@ -1216,8 +1231,8 @@ class ProcessOrchestrationService {
1216
1231
  duration,
1217
1232
  timeRemaining,
1218
1233
  result: rawProcess.result,
1219
- voteCount: Number(rawProcess.voteCount),
1220
- voteOverwriteCount: Number(rawProcess.voteOverwriteCount),
1234
+ votersCount: Number(rawProcess.votersCount),
1235
+ overwrittenVotesCount: Number(rawProcess.overwrittenVotesCount),
1221
1236
  metadataURI: rawProcess.metadataURI,
1222
1237
  raw: rawProcess
1223
1238
  };
@@ -2031,9 +2046,15 @@ class VoteOrchestrationService {
2031
2046
  assertMerkleCensusProof(proof);
2032
2047
  return proof;
2033
2048
  } else {
2034
- const proof = await this.apiService.census.getCensusProof(censusRoot, voterAddress);
2035
- assertMerkleCensusProof(proof);
2036
- return proof;
2049
+ const weight = await this.apiService.sequencer.getAddressWeight(processId, voterAddress);
2050
+ return {
2051
+ root: censusRoot,
2052
+ address: voterAddress,
2053
+ weight,
2054
+ censusOrigin: CensusOrigin.CensusOriginMerkleTree,
2055
+ value: "",
2056
+ siblings: ""
2057
+ };
2037
2058
  }
2038
2059
  }
2039
2060
  if (censusOrigin === CensusOrigin.CensusOriginCSP) {
@@ -2843,29 +2864,55 @@ class DavinciSDK {
2843
2864
  return this.voteOrchestrator.hasAddressVoted(processId, address);
2844
2865
  }
2845
2866
  /**
2846
- * Check if an address is able to vote in a process and get participant information.
2867
+ * Check if an address is able to vote in a process (i.e., is in the census).
2847
2868
  *
2848
2869
  * Does NOT require a provider - uses API calls only.
2849
2870
  *
2850
2871
  * @param processId - The process ID
2851
2872
  * @param address - The voter's address
2852
- * @returns Promise resolving to participant information (key and weight)
2873
+ * @returns Promise resolving to boolean indicating if the address can vote
2853
2874
  *
2854
2875
  * @example
2855
2876
  * ```typescript
2856
- * const participantInfo = await sdk.isAddressAbleToVote(processId, "0x1234567890abcdef...");
2857
- * console.log("Address:", participantInfo.key);
2858
- * console.log("Weight:", participantInfo.weight);
2877
+ * const canVote = await sdk.isAddressAbleToVote(processId, "0x1234567890abcdef...");
2878
+ * if (canVote) {
2879
+ * console.log("This address can vote");
2880
+ * } else {
2881
+ * console.log("This address is not in the census");
2882
+ * }
2859
2883
  * ```
2860
2884
  */
2861
2885
  async isAddressAbleToVote(processId, address) {
2862
2886
  if (!this.initialized) {
2863
2887
  throw new Error(
2864
- "SDK must be initialized before checking participant info. Call sdk.init() first."
2888
+ "SDK must be initialized before checking if address can vote. Call sdk.init() first."
2865
2889
  );
2866
2890
  }
2867
2891
  return this.apiService.sequencer.isAddressAbleToVote(processId, address);
2868
2892
  }
2893
+ /**
2894
+ * Get the voting weight for an address in a process.
2895
+ *
2896
+ * Does NOT require a provider - uses API calls only.
2897
+ *
2898
+ * @param processId - The process ID
2899
+ * @param address - The voter's address
2900
+ * @returns Promise resolving to the address weight as a string
2901
+ *
2902
+ * @example
2903
+ * ```typescript
2904
+ * const weight = await sdk.getAddressWeight(processId, "0x1234567890abcdef...");
2905
+ * console.log("Address weight:", weight);
2906
+ * ```
2907
+ */
2908
+ async getAddressWeight(processId, address) {
2909
+ if (!this.initialized) {
2910
+ throw new Error(
2911
+ "SDK must be initialized before getting address weight. Call sdk.init() first."
2912
+ );
2913
+ }
2914
+ return this.apiService.sequencer.getAddressWeight(processId, address);
2915
+ }
2869
2916
  /**
2870
2917
  * Watch vote status changes in real-time using an async generator.
2871
2918
  * This method yields each status change as it happens, perfect for showing