@dorafactory/maci-sdk 0.0.1

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 (74) hide show
  1. package/README.md +1 -0
  2. package/dist/index.d.ts +11 -0
  3. package/dist/index.js +4157 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.mjs +4123 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/dist/libs/const.d.ts +117 -0
  8. package/dist/libs/contract/config.d.ts +29 -0
  9. package/dist/libs/contract/contract.d.ts +37 -0
  10. package/dist/libs/contract/index.d.ts +1 -0
  11. package/dist/libs/contract/ts/AMaci.client.d.ts +216 -0
  12. package/dist/libs/contract/ts/AMaci.types.d.ts +203 -0
  13. package/dist/libs/contract/ts/Maci.client.d.ts +206 -0
  14. package/dist/libs/contract/ts/Maci.types.d.ts +217 -0
  15. package/dist/libs/contract/ts/OracleMaci.client.d.ts +206 -0
  16. package/dist/libs/contract/ts/OracleMaci.types.d.ts +253 -0
  17. package/dist/libs/contract/ts/Registry.client.d.ts +128 -0
  18. package/dist/libs/contract/ts/Registry.types.d.ts +110 -0
  19. package/dist/libs/contract/types.d.ts +50 -0
  20. package/dist/libs/contract/utils.d.ts +67 -0
  21. package/dist/libs/contract/vars.d.ts +65 -0
  22. package/dist/libs/errors/index.d.ts +28 -0
  23. package/dist/libs/errors/types.d.ts +14 -0
  24. package/dist/libs/http/http.d.ts +16 -0
  25. package/dist/libs/http/index.d.ts +1 -0
  26. package/dist/libs/index.d.ts +4 -0
  27. package/dist/libs/indexer/index.d.ts +1 -0
  28. package/dist/libs/indexer/indexer.d.ts +133 -0
  29. package/dist/libs/indexer/types.d.ts +7 -0
  30. package/dist/libs/query/account.d.ts +7 -0
  31. package/dist/libs/query/circuit.d.ts +8 -0
  32. package/dist/libs/query/index.d.ts +6 -0
  33. package/dist/libs/query/operator.d.ts +9 -0
  34. package/dist/libs/query/proof.d.ts +7 -0
  35. package/dist/libs/query/round.d.ts +11 -0
  36. package/dist/libs/query/transaction.d.ts +9 -0
  37. package/dist/maci.d.ts +151 -0
  38. package/dist/types/index.d.ts +254 -0
  39. package/dist/utils/index.d.ts +1 -0
  40. package/package.json +154 -0
  41. package/src/index.ts +11 -0
  42. package/src/libs/const.ts +196 -0
  43. package/src/libs/contract/config.ts +117 -0
  44. package/src/libs/contract/contract.ts +330 -0
  45. package/src/libs/contract/index.ts +1 -0
  46. package/src/libs/contract/ts/AMaci.client.ts +893 -0
  47. package/src/libs/contract/ts/AMaci.types.ts +252 -0
  48. package/src/libs/contract/ts/Maci.client.ts +906 -0
  49. package/src/libs/contract/ts/Maci.types.ts +263 -0
  50. package/src/libs/contract/ts/OracleMaci.client.ts +561 -0
  51. package/src/libs/contract/ts/OracleMaci.types.ts +254 -0
  52. package/src/libs/contract/ts/Registry.client.ts +466 -0
  53. package/src/libs/contract/ts/Registry.types.ts +127 -0
  54. package/src/libs/contract/types.ts +57 -0
  55. package/src/libs/contract/utils.ts +175 -0
  56. package/src/libs/contract/vars.ts +420 -0
  57. package/src/libs/errors/index.ts +122 -0
  58. package/src/libs/errors/types.ts +14 -0
  59. package/src/libs/http/http.ts +152 -0
  60. package/src/libs/http/index.ts +1 -0
  61. package/src/libs/index.ts +4 -0
  62. package/src/libs/indexer/index.ts +1 -0
  63. package/src/libs/indexer/indexer.ts +240 -0
  64. package/src/libs/indexer/types.ts +8 -0
  65. package/src/libs/query/account.ts +39 -0
  66. package/src/libs/query/circuit.ts +99 -0
  67. package/src/libs/query/index.ts +6 -0
  68. package/src/libs/query/operator.ts +263 -0
  69. package/src/libs/query/proof.ts +76 -0
  70. package/src/libs/query/round.ts +533 -0
  71. package/src/libs/query/transaction.ts +204 -0
  72. package/src/maci.ts +313 -0
  73. package/src/types/index.ts +301 -0
  74. package/src/utils/index.ts +44 -0
@@ -0,0 +1,301 @@
1
+ import { FetchOptions } from '../libs/http/http';
2
+
3
+ export type ClientParams = {
4
+ network: 'mainnet' | 'testnet';
5
+ rpcEndpoint?: string;
6
+ restEndpoint?: string;
7
+ apiEndpoint?: string;
8
+ registryAddress?: string;
9
+ maciCodeId?: number;
10
+ oracleCodeId?: number;
11
+ customFetch?: typeof fetch;
12
+ defaultOptions?: FetchOptions;
13
+ };
14
+
15
+ export type ContractParams = {
16
+ rpcEndpoint: string;
17
+ registryAddress: string;
18
+ maciCodeId: number;
19
+ oracleCodeId: number;
20
+ };
21
+
22
+ export type TransactionType = {
23
+ id: string;
24
+ blockHeight: string;
25
+ txHash: string;
26
+ timestamp: string;
27
+ type: string;
28
+ status: string;
29
+ circuitName: string;
30
+ fee: string;
31
+ gasUsed: string;
32
+ gasWanted: string;
33
+ caller: string;
34
+ contractAddress: string;
35
+ };
36
+
37
+ export type RoundType = {
38
+ id: string;
39
+ blockHeight: string;
40
+ txHash: string;
41
+ caller: string;
42
+ admin: string;
43
+ operator: string;
44
+ contractAddress: string;
45
+ circuitName: string;
46
+ timestamp: string;
47
+ votingStart: string;
48
+ votingEnd: string;
49
+ status: string;
50
+ period: string;
51
+ actionType: string;
52
+ roundTitle: string;
53
+ roundDescription: string;
54
+ roundLink: string;
55
+ coordinatorPubkeyX: string;
56
+ coordinatorPubkeyY: string;
57
+ voteOptionMap: string;
58
+ results: string;
59
+ allResult: string;
60
+ gasStationEnable: boolean;
61
+ totalGrant: string;
62
+ baseGrant: string;
63
+ totalBond: string;
64
+ circuitType: string;
65
+ circuitPower: string;
66
+ certificationSystem: string;
67
+ codeId: string;
68
+ maciType: string;
69
+ voiceCreditAmount: string;
70
+ preDeactivateRoot: string;
71
+ identity: string;
72
+ operatorLogoUrl?: string;
73
+ operatorMoniker?: string;
74
+ resultsList?: {
75
+ v: number;
76
+ v2: number;
77
+ }[];
78
+ };
79
+
80
+ export type ProofType = {
81
+ nodes: {
82
+ id: string;
83
+ blockHeight: string;
84
+ txHash: string;
85
+ contractAddress: string;
86
+ timestamp: string;
87
+ actionType: string;
88
+ commitment: string;
89
+ proof: string;
90
+ }[];
91
+ };
92
+
93
+ export type OperatorType = {
94
+ id: string;
95
+ validatorAddress: string;
96
+ operatorAddress: string;
97
+ coordinatorPubkeyX: string;
98
+ coordinatorPubkeyY: string;
99
+ identity: string;
100
+ logoUrl: string;
101
+ moniker: string;
102
+ activeRoundsCount: number;
103
+ completedRoundsCount: number;
104
+ };
105
+
106
+ export type CircuitType = {
107
+ maciType: string;
108
+ circuitType: string;
109
+ displayName: string;
110
+ repoUrl: string;
111
+ zipUrl: string;
112
+ roundCount?: number;
113
+ };
114
+
115
+ export type CircuitsCountGraphqlResponse = {
116
+ data: {
117
+ rounds: {
118
+ totalCount: number;
119
+ };
120
+ };
121
+ };
122
+
123
+ export type ErrorResponse = {
124
+ code: number;
125
+ error: {
126
+ message: string;
127
+ type: string;
128
+ };
129
+ };
130
+
131
+ export type SuccessResponse<T> = {
132
+ code: 200;
133
+ data: T;
134
+ };
135
+
136
+ export type CircuitResponse =
137
+ | SuccessResponse<{
138
+ circuit: CircuitType;
139
+ }>
140
+ | ErrorResponse;
141
+
142
+ export type CircuitsResponse =
143
+ | SuccessResponse<{
144
+ circuits: CircuitType[];
145
+ }>
146
+ | ErrorResponse;
147
+
148
+ export type BalanceResponse =
149
+ | SuccessResponse<{
150
+ balance: string;
151
+ }>
152
+ | ErrorResponse;
153
+
154
+ export type OperatorResponse =
155
+ | SuccessResponse<{
156
+ operator: OperatorType;
157
+ }>
158
+ | ErrorResponse;
159
+
160
+ export type OperatorsResponse =
161
+ | SuccessResponse<{
162
+ operators: {
163
+ pageInfo: {
164
+ endCursor: string;
165
+ hasNextPage: boolean;
166
+ };
167
+ edges: {
168
+ cursor: string;
169
+ node: OperatorType;
170
+ }[];
171
+ totalCount: number;
172
+ };
173
+ }>
174
+ | ErrorResponse;
175
+
176
+ export type OperatorsGraphqlResponse = {
177
+ data: {
178
+ operators: {
179
+ pageInfo: {
180
+ endCursor: string;
181
+ hasNextPage: boolean;
182
+ };
183
+ edges: {
184
+ cursor: string;
185
+ node: OperatorType;
186
+ }[];
187
+ totalCount: number;
188
+ };
189
+ };
190
+ };
191
+
192
+ export type RoundsCountGraphqlResponse = {
193
+ data: {
194
+ activeRoundsCount: {
195
+ totalCount: number;
196
+ };
197
+ completedRoundsCount: {
198
+ totalCount: number;
199
+ };
200
+ };
201
+ };
202
+
203
+ export type TransactionGraphqlResponse = {
204
+ data: {
205
+ transaction: TransactionType;
206
+ };
207
+ };
208
+
209
+ export type TransactionResponse =
210
+ | SuccessResponse<{
211
+ transaction: TransactionType;
212
+ }>
213
+ | ErrorResponse;
214
+
215
+ export type TransactionsGraphqlResponse = {
216
+ data: {
217
+ transactions: {
218
+ pageInfo: {
219
+ endCursor: string;
220
+ hasNextPage: boolean;
221
+ };
222
+ edges: {
223
+ cursor: string;
224
+ node: TransactionType;
225
+ }[];
226
+ totalCount: number;
227
+ };
228
+ };
229
+ };
230
+
231
+ export type TransactionsResponse =
232
+ | SuccessResponse<{
233
+ transactions: {
234
+ pageInfo: {
235
+ endCursor: string;
236
+ hasNextPage: boolean;
237
+ };
238
+ edges: {
239
+ cursor: string;
240
+ node: TransactionType;
241
+ }[];
242
+ totalCount: number;
243
+ };
244
+ }>
245
+ | ErrorResponse;
246
+
247
+ export type RoundResponse =
248
+ | SuccessResponse<{
249
+ round: RoundType;
250
+ }>
251
+ | ErrorResponse;
252
+
253
+ export type RoundsResponse =
254
+ | SuccessResponse<{
255
+ rounds: {
256
+ pageInfo: {
257
+ endCursor: string;
258
+ hasNextPage: boolean;
259
+ };
260
+ edges: {
261
+ cursor: string;
262
+ node: RoundType;
263
+ }[];
264
+ totalCount: number;
265
+ };
266
+ }>
267
+ | ErrorResponse;
268
+
269
+ export type RoundGraphqlResponse = {
270
+ data: {
271
+ round: RoundType;
272
+ };
273
+ };
274
+
275
+ export type RoundsGraphqlResponse = {
276
+ data: {
277
+ rounds: {
278
+ pageInfo: {
279
+ endCursor: string;
280
+ hasNextPage: boolean;
281
+ };
282
+ edges: {
283
+ cursor: string;
284
+ node: RoundType;
285
+ }[];
286
+ totalCount: number;
287
+ };
288
+ };
289
+ };
290
+
291
+ export type ProofResponse =
292
+ | SuccessResponse<{
293
+ proofData: ProofType;
294
+ }>
295
+ | ErrorResponse;
296
+
297
+ export type ProofGraphqlResponse = {
298
+ data: {
299
+ proofData: ProofType;
300
+ };
301
+ };
@@ -0,0 +1,44 @@
1
+ import { decode } from 'bech32';
2
+
3
+ function verifyIsBech32(address: string): Error | undefined {
4
+ try {
5
+ decode(address);
6
+ } catch (error) {
7
+ return error instanceof Error ? error : new Error('Unknown error');
8
+ }
9
+
10
+ return undefined;
11
+ }
12
+
13
+ export function isValidAddress(address: string): boolean {
14
+ // An address is valid if it starts with `dora` and is Bech32 format.
15
+ return address.startsWith('dora') && verifyIsBech32(address) === undefined;
16
+ }
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
+ // }