@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.umd.js CHANGED
@@ -564,11 +564,26 @@
564
564
  throw error;
565
565
  }
566
566
  }
567
- isAddressAbleToVote(processId, address) {
568
- return this.request({
567
+ async getAddressWeight(processId, address) {
568
+ const participant = await this.request({
569
569
  method: "GET",
570
570
  url: `/processes/${processId}/participants/${address}`
571
571
  });
572
+ return participant.weight;
573
+ }
574
+ async isAddressAbleToVote(processId, address) {
575
+ try {
576
+ await this.request({
577
+ method: "GET",
578
+ url: `/processes/${processId}/participants/${address}`
579
+ });
580
+ return true;
581
+ } catch (error) {
582
+ if (error?.code === 40001) {
583
+ return false;
584
+ }
585
+ throw error;
586
+ }
572
587
  }
573
588
  getInfo() {
574
589
  return this.request({
@@ -1217,8 +1232,8 @@
1217
1232
  duration,
1218
1233
  timeRemaining,
1219
1234
  result: rawProcess.result,
1220
- voteCount: Number(rawProcess.voteCount),
1221
- voteOverwriteCount: Number(rawProcess.voteOverwriteCount),
1235
+ votersCount: Number(rawProcess.votersCount),
1236
+ overwrittenVotesCount: Number(rawProcess.overwrittenVotesCount),
1222
1237
  metadataURI: rawProcess.metadataURI,
1223
1238
  raw: rawProcess
1224
1239
  };
@@ -2032,9 +2047,15 @@
2032
2047
  assertMerkleCensusProof(proof);
2033
2048
  return proof;
2034
2049
  } else {
2035
- const proof = await this.apiService.census.getCensusProof(censusRoot, voterAddress);
2036
- assertMerkleCensusProof(proof);
2037
- return proof;
2050
+ const weight = await this.apiService.sequencer.getAddressWeight(processId, voterAddress);
2051
+ return {
2052
+ root: censusRoot,
2053
+ address: voterAddress,
2054
+ weight,
2055
+ censusOrigin: CensusOrigin.CensusOriginMerkleTree,
2056
+ value: "",
2057
+ siblings: ""
2058
+ };
2038
2059
  }
2039
2060
  }
2040
2061
  if (censusOrigin === CensusOrigin.CensusOriginCSP) {
@@ -2844,29 +2865,55 @@
2844
2865
  return this.voteOrchestrator.hasAddressVoted(processId, address);
2845
2866
  }
2846
2867
  /**
2847
- * Check if an address is able to vote in a process and get participant information.
2868
+ * Check if an address is able to vote in a process (i.e., is in the census).
2848
2869
  *
2849
2870
  * Does NOT require a provider - uses API calls only.
2850
2871
  *
2851
2872
  * @param processId - The process ID
2852
2873
  * @param address - The voter's address
2853
- * @returns Promise resolving to participant information (key and weight)
2874
+ * @returns Promise resolving to boolean indicating if the address can vote
2854
2875
  *
2855
2876
  * @example
2856
2877
  * ```typescript
2857
- * const participantInfo = await sdk.isAddressAbleToVote(processId, "0x1234567890abcdef...");
2858
- * console.log("Address:", participantInfo.key);
2859
- * console.log("Weight:", participantInfo.weight);
2878
+ * const canVote = await sdk.isAddressAbleToVote(processId, "0x1234567890abcdef...");
2879
+ * if (canVote) {
2880
+ * console.log("This address can vote");
2881
+ * } else {
2882
+ * console.log("This address is not in the census");
2883
+ * }
2860
2884
  * ```
2861
2885
  */
2862
2886
  async isAddressAbleToVote(processId, address) {
2863
2887
  if (!this.initialized) {
2864
2888
  throw new Error(
2865
- "SDK must be initialized before checking participant info. Call sdk.init() first."
2889
+ "SDK must be initialized before checking if address can vote. Call sdk.init() first."
2866
2890
  );
2867
2891
  }
2868
2892
  return this.apiService.sequencer.isAddressAbleToVote(processId, address);
2869
2893
  }
2894
+ /**
2895
+ * Get the voting weight for an address in a process.
2896
+ *
2897
+ * Does NOT require a provider - uses API calls only.
2898
+ *
2899
+ * @param processId - The process ID
2900
+ * @param address - The voter's address
2901
+ * @returns Promise resolving to the address weight as a string
2902
+ *
2903
+ * @example
2904
+ * ```typescript
2905
+ * const weight = await sdk.getAddressWeight(processId, "0x1234567890abcdef...");
2906
+ * console.log("Address weight:", weight);
2907
+ * ```
2908
+ */
2909
+ async getAddressWeight(processId, address) {
2910
+ if (!this.initialized) {
2911
+ throw new Error(
2912
+ "SDK must be initialized before getting address weight. Call sdk.init() first."
2913
+ );
2914
+ }
2915
+ return this.apiService.sequencer.getAddressWeight(processId, address);
2916
+ }
2870
2917
  /**
2871
2918
  * Watch vote status changes in real-time using an async generator.
2872
2919
  * This method yields each status change as it happens, perfect for showing
@@ -174,36 +174,14 @@ interface GetProcessResponse {
174
174
  organizationId: string;
175
175
  encryptionKey: EncryptionKey;
176
176
  stateRoot: string;
177
- result: string[];
178
- startTime: number;
177
+ result: string[] | null;
178
+ startTime: string;
179
179
  duration: number;
180
180
  metadataURI: string;
181
181
  ballotMode: BallotMode;
182
182
  census: CensusData;
183
- metadata: {
184
- title: Record<string, string>;
185
- description: Record<string, string>;
186
- media: {
187
- header: string;
188
- logo: string;
189
- };
190
- questions: {
191
- title: Record<string, string>;
192
- description: Record<string, string>;
193
- choices: {
194
- title: Record<string, string>;
195
- value: number;
196
- meta: Record<string, string>;
197
- }[];
198
- meta: Record<string, string>;
199
- }[];
200
- processType: {
201
- name: string;
202
- properties: Record<string, string>;
203
- };
204
- };
205
- voteCount: string;
206
- voteOverwrittenCount: string;
183
+ votersCount: string;
184
+ overwrittenVotesCount: string;
207
185
  isAcceptingVotes: boolean;
208
186
  sequencerStats: {
209
187
  stateTransitionCount: number;
@@ -531,7 +509,8 @@ declare class VocdoniSequencerService extends BaseService {
531
509
  submitVote(vote: VoteRequest): Promise<void>;
532
510
  getVoteStatus(processId: string, voteId: string): Promise<VoteStatusResponse>;
533
511
  hasAddressVoted(processId: string, address: string): Promise<boolean>;
534
- isAddressAbleToVote(processId: string, address: string): Promise<ParticipantInfoResponse>;
512
+ getAddressWeight(processId: string, address: string): Promise<string>;
513
+ isAddressAbleToVote(processId: string, address: string): Promise<boolean>;
535
514
  getInfo(): Promise<InfoResponse>;
536
515
  pushMetadata(metadata: ElectionMetadata): Promise<string>;
537
516
  getMetadata(hashOrUrl: string): Promise<ElectionMetadata>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vocdoni/davinci-sdk",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
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.26",
75
+ "@vocdoni/davinci-contracts": "0.0.28",
76
76
  "axios": "^1.8.4",
77
77
  "ethers": "^6.7.1",
78
78
  "snarkjs": "^0.7.5"