@dorafactory/maci-sdk 0.0.3 → 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.
@@ -10,10 +10,12 @@ export declare class Contract {
10
10
  registryAddress: string;
11
11
  maciCodeId: number;
12
12
  oracleCodeId: number;
13
- constructor({ rpcEndpoint, registryAddress, maciCodeId, oracleCodeId, }: ContractParams);
13
+ feegrantOperator: string;
14
+ whitelistBackendPubkey: string;
15
+ constructor({ rpcEndpoint, registryAddress, maciCodeId, oracleCodeId, feegrantOperator, whitelistBackendPubkey, }: ContractParams);
14
16
  createAMaciRound({ signer, startVoting, endVoting, operator, whitelist, title, description, link, maxVoter, maxOption, voiceCreditAmount, circuitType, preDeactivateRoot, }: CreateAMaciRoundParams): Promise<string>;
15
17
  createMaciRound({ signer, operatorPubkey, startVoting, endVoting, whitelist, title, description, link, maxVoter, maxOption, circuitType, certSystemType, }: CreateMaciRoundParams): Promise<import("@cosmjs/cosmwasm-stargate").InstantiateResult>;
16
- createOracleMaciRound({ signer, operatorPubkey, startVoting, endVoting, title, description, link, maxVoter, maxOption, circuitType, whitelistBackendPubkey, whitelistEcosystem, whitelistSnapshotHeight, whitelistVotingPowerArgs, feegrantOperator, }: CreateOracleMaciRoundParams): Promise<import("@cosmjs/cosmwasm-stargate").InstantiateResult>;
18
+ createOracleMaciRound({ signer, operatorPubkey, startVoting, endVoting, title, description, link, maxVoter, maxOption, circuitType, whitelistEcosystem, whitelistSnapshotHeight, whitelistVotingPowerArgs, }: CreateOracleMaciRoundParams): Promise<import("@cosmjs/cosmwasm-stargate").InstantiateResult>;
17
19
  queryRoundInfo({ signer, roundAddress, }: {
18
20
  signer: OfflineSigner;
19
21
  roundAddress: string;
@@ -26,13 +26,11 @@ export type CreateMaciRoundParams = {
26
26
  } & CreateRoundParams;
27
27
  export type CreateOracleMaciRoundParams = {
28
28
  operatorPubkey: string;
29
- whitelistEcosystem: string;
29
+ whitelistEcosystem: 'cosmoshub' | 'doravota';
30
30
  whitelistSnapshotHeight: string;
31
31
  whitelistVotingPowerArgs: {
32
- mode: string;
32
+ mode: 'slope' | 'threshold';
33
33
  slope: string;
34
34
  threshold: string;
35
35
  };
36
- whitelistBackendPubkey?: string;
37
- feegrantOperator?: string;
38
36
  } & CreateRoundParams;
@@ -55,13 +55,4 @@ export declare function getContractParams(type: MaciRoundType, circuitType: Maci
55
55
  maciVoteType?: undefined;
56
56
  maciCertSystem?: undefined;
57
57
  };
58
- /**
59
- * Parses a public key string into its x and y coordinates.
60
- * @param publickKey - The public key string to parse (128 characters long).
61
- * @returns An object containing the x and y coordinates as decimal strings.
62
- */
63
- export declare function parsePubkey(publickKey: string): {
64
- x: string;
65
- y: string;
66
- };
67
58
  export {};
package/dist/maci.d.ts CHANGED
@@ -16,11 +16,13 @@ export declare class MaciClient {
16
16
  http: Http;
17
17
  indexer: Indexer;
18
18
  contract: Contract;
19
+ feegrantOperator: string;
20
+ whitelistBackendPubkey: string;
19
21
  /**
20
22
  * @constructor
21
23
  * @param {ClientParams} params - The parameters for the Maci Client instance.
22
24
  */
23
- constructor({ network, rpcEndpoint, restEndpoint, apiEndpoint, registryAddress, maciCodeId, oracleCodeId, customFetch, defaultOptions, }: ClientParams);
25
+ constructor({ network, rpcEndpoint, restEndpoint, apiEndpoint, registryAddress, maciCodeId, oracleCodeId, customFetch, defaultOptions, feegrantOperator, whitelistBackendPubkey, }: ClientParams);
24
26
  oracleMaciClient({ signer, contractAddress, }: {
25
27
  signer: OfflineSigner;
26
28
  contractAddress: string;
@@ -23,12 +23,16 @@ export type ClientParams = {
23
23
  oracleCodeId?: number;
24
24
  customFetch?: typeof fetch;
25
25
  defaultOptions?: FetchOptions;
26
+ feegrantOperator?: string;
27
+ whitelistBackendPubkey?: string;
26
28
  };
27
29
  export type ContractParams = {
28
30
  rpcEndpoint: string;
29
31
  registryAddress: string;
30
32
  maciCodeId: number;
31
33
  oracleCodeId: number;
34
+ whitelistBackendPubkey: string;
35
+ feegrantOperator: string;
32
36
  };
33
37
  export type TransactionType = {
34
38
  id: string;
@@ -1 +1,17 @@
1
1
  export declare function isValidAddress(address: string): boolean;
2
+ /**
3
+ * Converts a hexadecimal string to a decimal string.
4
+ * @param hexString - The hexadecimal string to convert.
5
+ * @returns The decimal string representation of the input.
6
+ */
7
+ export declare function hexToDecimalString(hexString: string): string;
8
+ /**
9
+ * Parses a public key string into its x and y coordinates.
10
+ * @param publickKey - The public key string to parse (128 characters long).
11
+ * @returns An object containing the x and y coordinates as decimal strings.
12
+ */
13
+ export declare function decompressPublicKey(compressedPubkey: string): {
14
+ x: string;
15
+ y: string;
16
+ };
17
+ export declare function compressPublicKey(decompressedPubkey: any[]): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dorafactory/maci-sdk",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "SDK for interacting with maci",
5
5
  "keywords": [
6
6
  "maci",
package/src/index.ts CHANGED
@@ -10,3 +10,4 @@ export { Circuit } from './libs/query';
10
10
  export { Operator } from './libs/query';
11
11
  export { Proof } from './libs/query';
12
12
  export { Transaction } from './libs/query';
13
+ export * from './utils';
@@ -27,9 +27,10 @@ import {
27
27
  CreateMaciRoundParams,
28
28
  CreateOracleMaciRoundParams,
29
29
  } from './types';
30
- import { getContractParams, parsePubkey } from './utils';
30
+ import { getContractParams } from './utils';
31
31
  import { QTR_LIB } from './vars';
32
32
  import { MaciRoundType, MaciCertSystemType } from '../../types';
33
+ import { decompressPublicKey } from '../../utils';
33
34
 
34
35
  export const prefix = 'dora';
35
36
 
@@ -38,17 +39,23 @@ export class Contract {
38
39
  public registryAddress: string;
39
40
  public maciCodeId: number;
40
41
  public oracleCodeId: number;
42
+ public feegrantOperator: string;
43
+ public whitelistBackendPubkey: string;
41
44
 
42
45
  constructor({
43
46
  rpcEndpoint,
44
47
  registryAddress,
45
48
  maciCodeId,
46
49
  oracleCodeId,
50
+ feegrantOperator,
51
+ whitelistBackendPubkey,
47
52
  }: ContractParams) {
48
53
  this.rpcEndpoint = rpcEndpoint;
49
54
  this.registryAddress = registryAddress;
50
55
  this.maciCodeId = maciCodeId;
51
56
  this.oracleCodeId = oracleCodeId;
57
+ this.feegrantOperator = feegrantOperator;
58
+ this.whitelistBackendPubkey = whitelistBackendPubkey;
52
59
  }
53
60
 
54
61
  async createAMaciRound({
@@ -131,7 +138,7 @@ export class Contract {
131
138
  const [{ address }] = await signer.getAccounts();
132
139
  const client = await createContractClientByWallet(this.rpcEndpoint, signer);
133
140
  const { x: operatorPubkeyX, y: operatorPubkeyY } =
134
- parsePubkey(operatorPubkey);
141
+ decompressPublicKey(operatorPubkey);
135
142
  const {
136
143
  parameters,
137
144
  groth16ProcessVkey,
@@ -189,18 +196,16 @@ export class Contract {
189
196
  maxVoter,
190
197
  maxOption,
191
198
  circuitType,
192
- whitelistBackendPubkey,
193
199
  whitelistEcosystem,
194
200
  whitelistSnapshotHeight,
195
201
  whitelistVotingPowerArgs,
196
- feegrantOperator,
197
202
  }: CreateOracleMaciRoundParams) {
198
203
  const start_time = (startVoting.getTime() * 1_000_000).toString();
199
204
  const end_time = (endVoting.getTime() * 1_000_000).toString();
200
205
  const [{ address }] = await signer.getAccounts();
201
206
  const client = await createContractClientByWallet(this.rpcEndpoint, signer);
202
207
  const { x: operatorPubkeyX, y: operatorPubkeyY } =
203
- parsePubkey(operatorPubkey);
208
+ decompressPublicKey(operatorPubkey);
204
209
  const {
205
210
  parameters,
206
211
  groth16ProcessVkey,
@@ -235,14 +240,14 @@ export class Contract {
235
240
  plonk_process_vkey: plonkProcessVkey,
236
241
  plonk_tally_vkey: plonkTallyVkey,
237
242
  max_vote_options: maxOption,
238
- whitelist_backend_pubkey: whitelistBackendPubkey,
243
+ whitelist_backend_pubkey: this.whitelistBackendPubkey,
239
244
  whitelist_ecosystem: whitelistEcosystem,
240
245
  whitelist_snapshot_height: whitelistSnapshotHeight,
241
246
  whitelist_voting_power_args: whitelistVotingPowerArgs,
242
247
  circuit_type: maciVoteType,
243
248
  certification_system: maciCertSystem,
244
249
  qtr_lib: QTR_LIB,
245
- feegrant_operator: feegrantOperator,
250
+ feegrant_operator: this.feegrantOperator,
246
251
  },
247
252
  '[Oracle MACI]' + title,
248
253
  'auto'
@@ -30,13 +30,13 @@ export type CreateMaciRoundParams = {
30
30
 
31
31
  export type CreateOracleMaciRoundParams = {
32
32
  operatorPubkey: string;
33
- whitelistEcosystem: string;
33
+ whitelistEcosystem: 'cosmoshub' | 'doravota';
34
34
  whitelistSnapshotHeight: string;
35
35
  whitelistVotingPowerArgs: {
36
- mode: string;
36
+ mode: 'slope' | 'threshold';
37
37
  slope: string;
38
38
  threshold: string;
39
39
  };
40
- whitelistBackendPubkey?: string;
41
- feegrantOperator?: string;
40
+ // whitelistBackendPubkey?: string;
41
+ // feegrantOperator?: string;
42
42
  } & CreateRoundParams;
@@ -152,28 +152,3 @@ export function getContractParams(
152
152
  };
153
153
  }
154
154
  }
155
-
156
- /**
157
- * Converts a hexadecimal string to a decimal string.
158
- * @param hexString - The hexadecimal string to convert.
159
- * @returns The decimal string representation of the input.
160
- */
161
- function hexToDecimalString(hexString: string) {
162
- const decimalString = BigInt('0x' + hexString).toString(10);
163
- return decimalString;
164
- }
165
-
166
- /**
167
- * Parses a public key string into its x and y coordinates.
168
- * @param publickKey - The public key string to parse (128 characters long).
169
- * @returns An object containing the x and y coordinates as decimal strings.
170
- */
171
- export function parsePubkey(publickKey: string) {
172
- const x = publickKey.slice(0, 64);
173
- const y = publickKey.slice(64);
174
-
175
- return {
176
- x: hexToDecimalString(x),
177
- y: hexToDecimalString(y),
178
- };
179
- }
package/src/maci.ts CHANGED
@@ -36,6 +36,9 @@ export class MaciClient {
36
36
  public indexer: Indexer;
37
37
  public contract: Contract;
38
38
 
39
+ public feegrantOperator: string;
40
+ public whitelistBackendPubkey: string;
41
+
39
42
  /**
40
43
  * @constructor
41
44
  * @param {ClientParams} params - The parameters for the Maci Client instance.
@@ -50,6 +53,8 @@ export class MaciClient {
50
53
  oracleCodeId,
51
54
  customFetch,
52
55
  defaultOptions,
56
+ feegrantOperator,
57
+ whitelistBackendPubkey,
53
58
  }: ClientParams) {
54
59
  const defaultParams = getDefaultParams(network);
55
60
 
@@ -59,6 +64,10 @@ export class MaciClient {
59
64
  this.registryAddress = registryAddress || defaultParams.registryAddress;
60
65
  this.maciCodeId = maciCodeId || defaultParams.maciCodeId;
61
66
  this.oracleCodeId = oracleCodeId || defaultParams.oracleCodeId;
67
+ this.feegrantOperator =
68
+ feegrantOperator || defaultParams.oracleFeegrantOperator;
69
+ this.whitelistBackendPubkey =
70
+ whitelistBackendPubkey || defaultParams.oracleWhitelistBackendPubkey;
62
71
 
63
72
  this.http = new Http(
64
73
  this.apiEndpoint,
@@ -77,6 +86,8 @@ export class MaciClient {
77
86
  registryAddress: this.registryAddress,
78
87
  maciCodeId: this.maciCodeId,
79
88
  oracleCodeId: this.oracleCodeId,
89
+ feegrantOperator: this.feegrantOperator,
90
+ whitelistBackendPubkey: this.whitelistBackendPubkey,
80
91
  });
81
92
  }
82
93
 
@@ -27,6 +27,8 @@ export type ClientParams = {
27
27
  oracleCodeId?: number;
28
28
  customFetch?: typeof fetch;
29
29
  defaultOptions?: FetchOptions;
30
+ feegrantOperator?: string;
31
+ whitelistBackendPubkey?: string;
30
32
  };
31
33
 
32
34
  export type ContractParams = {
@@ -34,6 +36,8 @@ export type ContractParams = {
34
36
  registryAddress: string;
35
37
  maciCodeId: number;
36
38
  oracleCodeId: number;
39
+ whitelistBackendPubkey: string;
40
+ feegrantOperator: string;
37
41
  };
38
42
 
39
43
  export type TransactionType = {
@@ -15,30 +15,46 @@ export function isValidAddress(address: string): boolean {
15
15
  return address.startsWith('dora') && verifyIsBech32(address) === undefined;
16
16
  }
17
17
 
18
- // export async function fetchBaseUrl(url: string) {
19
- // const response = await fetch(url);
20
- // return response;
21
- // }
22
-
23
- // export async function fetchPages<T>(
24
- // query: string,
25
- // after: string,
26
- // limit: number | null = 10
27
- // ): Promise<T> {
28
- // const isFirstPage = after === 'first';
29
- // // after = isFirstPage ? null : after;
30
-
31
- // const response = await fetch(apiEndpoint, {
32
- // method: 'POST',
33
- // headers: {
34
- // 'Content-Type': 'application/json',
35
- // Accept: 'application/json',
36
- // },
37
- // body: JSON.stringify({
38
- // query,
39
- // variables: { limit, after: isFirstPage ? undefined : after },
40
- // }),
41
- // }).then((res) => res.json());
42
-
43
- // return response;
44
- // }
18
+ /**
19
+ * Converts a hexadecimal string to a decimal string.
20
+ * @param hexString - The hexadecimal string to convert.
21
+ * @returns The decimal string representation of the input.
22
+ */
23
+ export function hexToDecimalString(hexString: string) {
24
+ const decimalString = BigInt('0x' + hexString).toString(10);
25
+ return decimalString;
26
+ }
27
+
28
+ function padWithZerosIfNeeded(inputString: string) {
29
+ if (inputString.length === 64) {
30
+ return inputString;
31
+ } else if (inputString.length < 64) {
32
+ const zerosToAdd = 64 - inputString.length;
33
+ const zeroPadding = '0'.repeat(zerosToAdd);
34
+ return zeroPadding + inputString;
35
+ }
36
+ throw new Error('Invalid input string length');
37
+ }
38
+
39
+ /**
40
+ * Parses a public key string into its x and y coordinates.
41
+ * @param publickKey - The public key string to parse (128 characters long).
42
+ * @returns An object containing the x and y coordinates as decimal strings.
43
+ */
44
+ export function decompressPublicKey(compressedPubkey: string) {
45
+ const x = compressedPubkey.slice(0, 64);
46
+ const y = compressedPubkey.slice(64);
47
+
48
+ return {
49
+ x: hexToDecimalString(x),
50
+ y: hexToDecimalString(y),
51
+ };
52
+ }
53
+
54
+ export function compressPublicKey(decompressedPubkey: any[]) {
55
+ const x = decompressedPubkey[0];
56
+ const y = decompressedPubkey[1];
57
+ const compressedPubkey =
58
+ padWithZerosIfNeeded(x.toString(16)) + padWithZerosIfNeeded(y.toString(16));
59
+ return compressedPubkey;
60
+ }