@dorafactory/maci-sdk 0.0.7 → 0.0.9

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.
Files changed (50) hide show
  1. package/README.md +27 -7
  2. package/dist/index.js +751 -187
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +748 -187
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/libs/circom/tree.d.ts +20 -20
  7. package/dist/libs/contract/ts/AMaci.client.d.ts +1 -1
  8. package/dist/libs/contract/ts/Maci.client.d.ts +21 -47
  9. package/dist/libs/contract/ts/Maci.types.d.ts +40 -31
  10. package/dist/libs/contract/ts/OracleMaci.client.d.ts +52 -52
  11. package/dist/libs/contract/ts/OracleMaci.types.d.ts +17 -7
  12. package/dist/libs/contract/ts/Registry.client.d.ts +2 -2
  13. package/dist/libs/contract/types.d.ts +2 -2
  14. package/dist/libs/errors/types.d.ts +1 -0
  15. package/dist/libs/http/http.d.ts +1 -1
  16. package/dist/libs/index.d.ts +3 -0
  17. package/dist/libs/indexer/indexer.d.ts +11 -2
  18. package/dist/libs/maci/index.d.ts +1 -0
  19. package/dist/libs/maci/maci.d.ts +64 -5
  20. package/dist/libs/oracle-certificate/oracle-certificate.d.ts +1 -21
  21. package/dist/libs/oracle-certificate/types.d.ts +12 -0
  22. package/dist/libs/query/event.d.ts +7 -0
  23. package/dist/libs/query/index.d.ts +1 -0
  24. package/dist/maci.d.ts +7 -5
  25. package/dist/types/index.d.ts +22 -0
  26. package/package.json +1 -1
  27. package/src/libs/const.ts +3 -2
  28. package/src/libs/contract/contract.ts +2 -6
  29. package/src/libs/contract/ts/AMaci.client.ts +868 -874
  30. package/src/libs/contract/ts/AMaci.types.ts +216 -216
  31. package/src/libs/contract/ts/Maci.client.ts +748 -888
  32. package/src/libs/contract/ts/Maci.types.ts +229 -224
  33. package/src/libs/contract/ts/OracleMaci.client.ts +623 -348
  34. package/src/libs/contract/ts/OracleMaci.types.ts +191 -138
  35. package/src/libs/contract/ts/Registry.client.ts +438 -446
  36. package/src/libs/contract/ts/Registry.types.ts +97 -97
  37. package/src/libs/contract/types.ts +6 -2
  38. package/src/libs/contract/utils.ts +9 -0
  39. package/src/libs/errors/types.ts +1 -0
  40. package/src/libs/http/http.ts +3 -7
  41. package/src/libs/index.ts +3 -0
  42. package/src/libs/indexer/indexer.ts +18 -0
  43. package/src/libs/maci/index.ts +1 -0
  44. package/src/libs/maci/maci.ts +302 -10
  45. package/src/libs/oracle-certificate/oracle-certificate.ts +19 -73
  46. package/src/libs/oracle-certificate/types.ts +15 -1
  47. package/src/libs/query/event.ts +78 -0
  48. package/src/libs/query/index.ts +1 -0
  49. package/src/maci.ts +27 -5
  50. package/src/types/index.ts +28 -0
@@ -1,7 +1,7 @@
1
- import { BalanceResponse, RoundResponse, RoundsResponse, OperatorResponse, OperatorsResponse, CircuitResponse, TransactionResponse, TransactionsResponse, CircuitsResponse, ProofResponse } from '../../types';
1
+ import { BalanceResponse, RoundResponse, RoundsResponse, OperatorResponse, OperatorsResponse, CircuitResponse, TransactionResponse, TransactionsResponse, CircuitsResponse, ProofResponse, SignUpEventsResponse } from '../../types';
2
2
  import { IndexerParams } from './types';
3
3
  import { Http } from '../http';
4
- import { Round, UserAccount, Circuit, Operator, Proof, Transaction } from '../query';
4
+ import { Round, UserAccount, Circuit, Operator, Proof, Transaction, Event } from '../query';
5
5
  /**
6
6
  * @class Indexer
7
7
  * @description This class is used to interact with Maci Indexer.
@@ -17,6 +17,7 @@ export declare class Indexer {
17
17
  operator: Operator;
18
18
  proof: Proof;
19
19
  transaction: Transaction;
20
+ event: Event;
20
21
  /**
21
22
  * @constructor
22
23
  * @param {IndexerParams} params - The parameters for the Maci Indexer instance.
@@ -130,4 +131,12 @@ export declare class Indexer {
130
131
  * @returns {Promise<ProofResponse>} The proof response.
131
132
  */
132
133
  getProofByContractAddress(address: string): Promise<ProofResponse>;
134
+ /**
135
+ * @method getStateIdxByPubKey
136
+ * @description Get the state index of a specific public key.
137
+ * @param {string} contractAddress - The contract address.
138
+ * @param {bigint[]} pubKey - The public key.
139
+ * @returns {Promise<SignUpEventsResponse>} The sign up events response.
140
+ */
141
+ getSignUpEventByPubKey(contractAddress: string, pubKey: bigint[]): Promise<SignUpEventsResponse>;
133
142
  }
@@ -0,0 +1 @@
1
+ export { MACI } from './maci';
@@ -1,14 +1,72 @@
1
1
  import { OfflineSigner } from '@cosmjs/proto-signing';
2
2
  import { Circom, PublicKey } from '../circom';
3
3
  import { Contract } from '../contract';
4
+ import { Indexer } from '../indexer';
5
+ import { OracleCertificate } from '../oracle-certificate';
4
6
  import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate';
7
+ import { CertificateEcosystem, ErrorResponse } from '../../types';
8
+ import { SignatureResponse } from '../oracle-certificate/types';
9
+ import { OracleWhitelistConfig } from '../contract/ts/OracleMaci.types';
10
+ export declare function isErrorResponse(response: unknown): response is ErrorResponse;
5
11
  export declare class MACI {
6
12
  circom: Circom;
7
13
  contract: Contract;
8
- constructor({ circom, contract }: {
14
+ indexer: Indexer;
15
+ oracleCertificate: OracleCertificate;
16
+ constructor({ circom, contract, indexer, oracleCertificate, }: {
9
17
  circom: Circom;
10
18
  contract: Contract;
19
+ indexer: Indexer;
20
+ oracleCertificate: OracleCertificate;
11
21
  });
22
+ getStateIdxInc({ signer, address, contractAddress, }: {
23
+ signer: OfflineSigner;
24
+ address: string;
25
+ contractAddress: string;
26
+ }): Promise<string>;
27
+ getVoiceCreditBalance({ signer, stateIdx, contractAddress, }: {
28
+ signer: OfflineSigner;
29
+ stateIdx: number;
30
+ contractAddress: string;
31
+ }): Promise<string>;
32
+ getStateIdxByPubKey({ contractAddress, pubKey, }: {
33
+ contractAddress: string;
34
+ pubKey: bigint[];
35
+ }): Promise<number>;
36
+ queryWhitelistBalanceOf({ signer, address, contractAddress, certificate, mode, }: {
37
+ signer: OfflineSigner;
38
+ address: string;
39
+ contractAddress: string;
40
+ certificate?: string;
41
+ mode?: 'maci' | 'amaci';
42
+ }): Promise<string>;
43
+ isWhitelisted({ signer, address, contractAddress, }: {
44
+ signer: OfflineSigner;
45
+ address: string;
46
+ contractAddress: string;
47
+ }): Promise<boolean>;
48
+ getOracleWhitelistConfig({ signer, contractAddress, }: {
49
+ signer: OfflineSigner;
50
+ contractAddress: string;
51
+ }): Promise<OracleWhitelistConfig>;
52
+ getRoundInfo({ contractAddress }: {
53
+ contractAddress: string;
54
+ }): Promise<import("../../types").RoundType>;
55
+ getRoundCircuitType({ contractAddress }: {
56
+ contractAddress: string;
57
+ }): Promise<string>;
58
+ queryRoundIsQv({ contractAddress }: {
59
+ contractAddress: string;
60
+ }): Promise<boolean>;
61
+ queryRoundGasStation({ contractAddress }: {
62
+ contractAddress: string;
63
+ }): Promise<boolean>;
64
+ requestOracleCertificate({ signer, ecosystem, address, contractAddress, }: {
65
+ signer: OfflineSigner;
66
+ ecosystem: CertificateEcosystem;
67
+ address: string;
68
+ contractAddress: string;
69
+ }): Promise<SignatureResponse>;
12
70
  signup({ signer, address, contractAddress, oracleCertificate, gasStation, }: {
13
71
  signer: OfflineSigner;
14
72
  address: string;
@@ -18,8 +76,9 @@ export declare class MACI {
18
76
  signature: string;
19
77
  };
20
78
  gasStation?: boolean;
21
- }): Promise<void>;
22
- submit: ({ signer, address, stateIdx, contractAddress, selectedOptions, operatorCoordPubKey, gasStation, }: {
79
+ }): Promise<import("@cosmjs/cosmwasm-stargate").ExecuteResult>;
80
+ private processVoteOptions;
81
+ vote({ signer, address, stateIdx, contractAddress, selectedOptions, operatorCoordPubKey, gasStation, }: {
23
82
  signer: OfflineSigner;
24
83
  address: string;
25
84
  stateIdx: number;
@@ -30,8 +89,8 @@ export declare class MACI {
30
89
  }[];
31
90
  operatorCoordPubKey: PublicKey;
32
91
  gasStation?: boolean;
33
- }) => Promise<void>;
34
- submitPlan({ client, address, payload, contractAddress, gasStation, }: {
92
+ }): Promise<import("@cosmjs/cosmwasm-stargate").DeliverTxResponse>;
93
+ publishMessage({ client, address, payload, contractAddress, gasStation, }: {
35
94
  client: SigningCosmWasmClient;
36
95
  address: string;
37
96
  payload: {
@@ -1,24 +1,4 @@
1
- import { OracleCertificateParams } from './types';
2
- /**
3
- * @class Indexer
4
- * @description This class is used to interact with Maci Indexer.
5
- */
6
- export interface SignatureRequest {
7
- address: string;
8
- height: string;
9
- contractAddress: string;
10
- amount?: string;
11
- }
12
- export interface SignatureResponse {
13
- code: number;
14
- data?: {
15
- signature: string;
16
- };
17
- error?: {
18
- message: string;
19
- type: string;
20
- };
21
- }
1
+ import { OracleCertificateParams, SignatureRequest, SignatureResponse } from './types';
22
2
  export declare class OracleCertificate {
23
3
  private certificateApiEndpoint;
24
4
  private http;
@@ -1,5 +1,17 @@
1
+ import { CertificateEcosystem } from '../../types';
1
2
  import { Http } from '../http/http';
2
3
  export type OracleCertificateParams = {
3
4
  certificateApiEndpoint: string;
4
5
  http: Http;
5
6
  };
7
+ export type SignatureRequest = {
8
+ ecosystem: CertificateEcosystem;
9
+ address: string;
10
+ height: string;
11
+ contractAddress: string;
12
+ };
13
+ export type SignatureResponse = {
14
+ signature: string;
15
+ amount: string;
16
+ snapshotHeight: string;
17
+ };
@@ -0,0 +1,7 @@
1
+ import { Http } from '../../libs';
2
+ import { SignUpEventsResponse } from '../../types';
3
+ export declare class Event {
4
+ http: Http;
5
+ constructor(http: Http);
6
+ getSignUpEventByPubKey(contractAddress: string, pubKey: bigint[]): Promise<SignUpEventsResponse>;
7
+ }
@@ -4,3 +4,4 @@ export { Operator } from './operator';
4
4
  export { Round } from './round';
5
5
  export { Transaction } from './transaction';
6
6
  export { Proof } from './proof';
7
+ export { Event } from './event';
package/dist/maci.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import { BalanceResponse, ClientParams, RoundResponse, RoundsResponse, OperatorResponse, OperatorsResponse, CircuitResponse, TransactionResponse, TransactionsResponse, CircuitsResponse, ProofResponse } from './types';
2
- import { Http, Indexer, Contract } from './libs';
2
+ import { Http, Indexer, Contract, OracleCertificate, Circom, MACI } from './libs';
3
3
  import { CreateAMaciRoundParams, CreateMaciRoundParams, CreateOracleMaciRoundParams } from './libs/contract/types';
4
4
  import { OfflineSigner } from '@cosmjs/proto-signing';
5
- import { Circom } from './libs/circom';
6
5
  /**
7
6
  * @class MaciClient
8
7
  * @description This class is used to interact with Maci Client.
@@ -11,20 +10,23 @@ export declare class MaciClient {
11
10
  rpcEndpoint: string;
12
11
  restEndpoint: string;
13
12
  apiEndpoint: string;
13
+ certificateApiEndpoint: string;
14
14
  registryAddress: string;
15
15
  maciCodeId: number;
16
16
  oracleCodeId: number;
17
+ feegrantOperator: string;
18
+ whitelistBackendPubkey: string;
17
19
  http: Http;
18
20
  indexer: Indexer;
19
21
  contract: Contract;
20
22
  circom: Circom;
21
- feegrantOperator: string;
22
- whitelistBackendPubkey: string;
23
+ oracleCertificate: OracleCertificate;
24
+ maci: MACI;
23
25
  /**
24
26
  * @constructor
25
27
  * @param {ClientParams} params - The parameters for the Maci Client instance.
26
28
  */
27
- constructor({ network, rpcEndpoint, restEndpoint, apiEndpoint, registryAddress, maciCodeId, oracleCodeId, customFetch, defaultOptions, feegrantOperator, whitelistBackendPubkey, }: ClientParams);
29
+ constructor({ network, rpcEndpoint, restEndpoint, apiEndpoint, registryAddress, maciCodeId, oracleCodeId, customFetch, defaultOptions, feegrantOperator, whitelistBackendPubkey, certificateApiEndpoint, }: ClientParams);
28
30
  oracleMaciClient({ signer, contractAddress, }: {
29
31
  signer: OfflineSigner;
30
32
  contractAddress: string;
@@ -13,11 +13,13 @@ export declare enum MaciRoundType {
13
13
  AMACI = "1",
14
14
  ORACLE_MACI = "2"
15
15
  }
16
+ export type CertificateEcosystem = 'cosmoshub' | 'doravota';
16
17
  export type ClientParams = {
17
18
  network: 'mainnet' | 'testnet';
18
19
  rpcEndpoint?: string;
19
20
  restEndpoint?: string;
20
21
  apiEndpoint?: string;
22
+ certificateApiEndpoint?: string;
21
23
  registryAddress?: string;
22
24
  maciCodeId?: number;
23
25
  oracleCodeId?: number;
@@ -122,6 +124,16 @@ export type CircuitType = {
122
124
  zipUrl: string;
123
125
  roundCount?: number;
124
126
  };
127
+ export type SignUpEventType = {
128
+ id: string;
129
+ blockHeight: string;
130
+ txHash: string;
131
+ contractAddress: string;
132
+ timestamp: string;
133
+ pubKey: string;
134
+ stateIdx: number;
135
+ balance: string;
136
+ };
125
137
  export type CircuitsCountGraphqlResponse = {
126
138
  data: {
127
139
  rounds: {
@@ -270,3 +282,13 @@ export type ProofGraphqlResponse = {
270
282
  proofData: ProofType;
271
283
  };
272
284
  };
285
+ export type SignUpEventsResponse = SuccessResponse<{
286
+ signUpEvents: SignUpEventType[];
287
+ }> | ErrorResponse;
288
+ export type SignUpEventsGraphqlResponse = {
289
+ data: {
290
+ signUpEvents: {
291
+ nodes: SignUpEventType[];
292
+ };
293
+ };
294
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dorafactory/maci-sdk",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "SDK for interacting with maci",
5
5
  "keywords": [
6
6
  "maci",
package/src/libs/const.ts CHANGED
@@ -166,7 +166,8 @@ export function getDefaultParams(
166
166
  rpcEndpoint: 'https://vota-rpc.dorafactory.org',
167
167
  restEndpoint: 'https://vota-rest.dorafactory.org',
168
168
  apiEndpoint: 'https://vota-api.dorafactory.org',
169
- certificateApiEndpoint: 'https://vota-certificate-api.dorafactory.org',
169
+ certificateApiEndpoint:
170
+ 'https://vota-certificate-api.dorafactory.org/api/v1',
170
171
  registryAddress:
171
172
  'dora1smg5qp5trjdkcekdjssqpjehdjf6n4cjss0clyvqcud3t3u3948s8rmgg4',
172
173
  maciCodeId: 106,
@@ -183,7 +184,7 @@ export function getDefaultParams(
183
184
  restEndpoint: 'https://vota-testnet-rest.dorafactory.org',
184
185
  apiEndpoint: 'https://vota-testnet-api.dorafactory.org',
185
186
  certificateApiEndpoint:
186
- 'https://vota-testnet-certificate-api.dorafactory.org',
187
+ 'https://vota-testnet-certificate-api.dorafactory.org/api/v1',
187
188
  registryAddress:
188
189
  'dora13c8aecstyxrhax9znvvh5zey89edrmd2k5va57pxvpe3fxtfsfeqlhsjnd',
189
190
  maciCodeId: 107,
@@ -115,7 +115,6 @@ export class Contract {
115
115
  }
116
116
  }
117
117
  });
118
- console.log(`Deploy tx: ${res.transactionHash} - ${contractAddress}`);
119
118
  return contractAddress;
120
119
  }
121
120
 
@@ -178,7 +177,7 @@ export class Contract {
178
177
  certification_system: maciCertSystem,
179
178
  qtr_lib: QTR_LIB,
180
179
  },
181
- 'MACI',
180
+ `[MACI] ${title}`,
182
181
  'auto'
183
182
  );
184
183
 
@@ -249,13 +248,10 @@ export class Contract {
249
248
  qtr_lib: QTR_LIB,
250
249
  feegrant_operator: this.feegrantOperator,
251
250
  },
252
- '[Oracle MACI]' + title,
251
+ `[Oracle MACI] ${title}`,
253
252
  'auto'
254
253
  );
255
254
 
256
- // console.log(
257
- // `Deploy tx: ${instantiateResponse.transactionHash} - ${instantiateResponse.contractAddress} `
258
- // );
259
255
  return instantiateResponse;
260
256
  }
261
257