@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.
- package/README.md +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +4157 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4123 -0
- package/dist/index.mjs.map +1 -0
- package/dist/libs/const.d.ts +117 -0
- package/dist/libs/contract/config.d.ts +29 -0
- package/dist/libs/contract/contract.d.ts +37 -0
- package/dist/libs/contract/index.d.ts +1 -0
- package/dist/libs/contract/ts/AMaci.client.d.ts +216 -0
- package/dist/libs/contract/ts/AMaci.types.d.ts +203 -0
- package/dist/libs/contract/ts/Maci.client.d.ts +206 -0
- package/dist/libs/contract/ts/Maci.types.d.ts +217 -0
- package/dist/libs/contract/ts/OracleMaci.client.d.ts +206 -0
- package/dist/libs/contract/ts/OracleMaci.types.d.ts +253 -0
- package/dist/libs/contract/ts/Registry.client.d.ts +128 -0
- package/dist/libs/contract/ts/Registry.types.d.ts +110 -0
- package/dist/libs/contract/types.d.ts +50 -0
- package/dist/libs/contract/utils.d.ts +67 -0
- package/dist/libs/contract/vars.d.ts +65 -0
- package/dist/libs/errors/index.d.ts +28 -0
- package/dist/libs/errors/types.d.ts +14 -0
- package/dist/libs/http/http.d.ts +16 -0
- package/dist/libs/http/index.d.ts +1 -0
- package/dist/libs/index.d.ts +4 -0
- package/dist/libs/indexer/index.d.ts +1 -0
- package/dist/libs/indexer/indexer.d.ts +133 -0
- package/dist/libs/indexer/types.d.ts +7 -0
- package/dist/libs/query/account.d.ts +7 -0
- package/dist/libs/query/circuit.d.ts +8 -0
- package/dist/libs/query/index.d.ts +6 -0
- package/dist/libs/query/operator.d.ts +9 -0
- package/dist/libs/query/proof.d.ts +7 -0
- package/dist/libs/query/round.d.ts +11 -0
- package/dist/libs/query/transaction.d.ts +9 -0
- package/dist/maci.d.ts +151 -0
- package/dist/types/index.d.ts +254 -0
- package/dist/utils/index.d.ts +1 -0
- package/package.json +154 -0
- package/src/index.ts +11 -0
- package/src/libs/const.ts +196 -0
- package/src/libs/contract/config.ts +117 -0
- package/src/libs/contract/contract.ts +330 -0
- package/src/libs/contract/index.ts +1 -0
- package/src/libs/contract/ts/AMaci.client.ts +893 -0
- package/src/libs/contract/ts/AMaci.types.ts +252 -0
- package/src/libs/contract/ts/Maci.client.ts +906 -0
- package/src/libs/contract/ts/Maci.types.ts +263 -0
- package/src/libs/contract/ts/OracleMaci.client.ts +561 -0
- package/src/libs/contract/ts/OracleMaci.types.ts +254 -0
- package/src/libs/contract/ts/Registry.client.ts +466 -0
- package/src/libs/contract/ts/Registry.types.ts +127 -0
- package/src/libs/contract/types.ts +57 -0
- package/src/libs/contract/utils.ts +175 -0
- package/src/libs/contract/vars.ts +420 -0
- package/src/libs/errors/index.ts +122 -0
- package/src/libs/errors/types.ts +14 -0
- package/src/libs/http/http.ts +152 -0
- package/src/libs/http/index.ts +1 -0
- package/src/libs/index.ts +4 -0
- package/src/libs/indexer/index.ts +1 -0
- package/src/libs/indexer/indexer.ts +240 -0
- package/src/libs/indexer/types.ts +8 -0
- package/src/libs/query/account.ts +39 -0
- package/src/libs/query/circuit.ts +99 -0
- package/src/libs/query/index.ts +6 -0
- package/src/libs/query/operator.ts +263 -0
- package/src/libs/query/proof.ts +76 -0
- package/src/libs/query/round.ts +533 -0
- package/src/libs/query/transaction.ts +204 -0
- package/src/maci.ts +313 -0
- package/src/types/index.ts +301 -0
- package/src/utils/index.ts +44 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by @cosmwasm/ts-codegen@1.11.1.
|
|
3
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
4
|
+
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export type Addr = string;
|
|
8
|
+
export interface InstantiateMsg {
|
|
9
|
+
admin: Addr;
|
|
10
|
+
amaci_code_id: number;
|
|
11
|
+
operator: Addr;
|
|
12
|
+
}
|
|
13
|
+
export type ExecuteMsg =
|
|
14
|
+
| {
|
|
15
|
+
set_maci_operator: {
|
|
16
|
+
operator: Addr;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
| {
|
|
20
|
+
set_maci_operator_pubkey: {
|
|
21
|
+
pubkey: PubKey;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
| {
|
|
25
|
+
set_maci_operator_identity: {
|
|
26
|
+
identity: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
| {
|
|
30
|
+
create_round: {
|
|
31
|
+
certification_system: Uint256;
|
|
32
|
+
circuit_type: Uint256;
|
|
33
|
+
max_option: Uint256;
|
|
34
|
+
max_voter: Uint256;
|
|
35
|
+
operator: Addr;
|
|
36
|
+
pre_deactivate_root: Uint256;
|
|
37
|
+
round_info: RoundInfo;
|
|
38
|
+
voice_credit_amount: Uint256;
|
|
39
|
+
voting_time: VotingTime;
|
|
40
|
+
whitelist?: Whitelist | null;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
| {
|
|
44
|
+
set_validators: {
|
|
45
|
+
addresses: ValidatorSet;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
| {
|
|
49
|
+
remove_validator: {
|
|
50
|
+
address: Addr;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
| {
|
|
54
|
+
update_amaci_code_id: {
|
|
55
|
+
amaci_code_id: number;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
| {
|
|
59
|
+
change_operator: {
|
|
60
|
+
address: Addr;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
export type Uint256 = string;
|
|
64
|
+
export type Timestamp = Uint64;
|
|
65
|
+
export type Uint64 = string;
|
|
66
|
+
export interface PubKey {
|
|
67
|
+
x: Uint256;
|
|
68
|
+
y: Uint256;
|
|
69
|
+
}
|
|
70
|
+
export interface RoundInfo {
|
|
71
|
+
description: string;
|
|
72
|
+
link: string;
|
|
73
|
+
title: string;
|
|
74
|
+
}
|
|
75
|
+
export interface VotingTime {
|
|
76
|
+
end_time: Timestamp;
|
|
77
|
+
start_time: Timestamp;
|
|
78
|
+
}
|
|
79
|
+
export interface Whitelist {
|
|
80
|
+
users: WhitelistConfig[];
|
|
81
|
+
}
|
|
82
|
+
export interface WhitelistConfig {
|
|
83
|
+
addr: Addr;
|
|
84
|
+
}
|
|
85
|
+
export interface ValidatorSet {
|
|
86
|
+
addresses: Addr[];
|
|
87
|
+
}
|
|
88
|
+
export type QueryMsg =
|
|
89
|
+
| {
|
|
90
|
+
admin: {};
|
|
91
|
+
}
|
|
92
|
+
| {
|
|
93
|
+
operator: {};
|
|
94
|
+
}
|
|
95
|
+
| {
|
|
96
|
+
is_maci_operator: {
|
|
97
|
+
address: Addr;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
| {
|
|
101
|
+
is_validator: {
|
|
102
|
+
address: Addr;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
| {
|
|
106
|
+
get_validators: {};
|
|
107
|
+
}
|
|
108
|
+
| {
|
|
109
|
+
get_validator_operator: {
|
|
110
|
+
address: Addr;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
| {
|
|
114
|
+
get_maci_operator_pubkey: {
|
|
115
|
+
address: Addr;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
| {
|
|
119
|
+
get_maci_operator_identity: {
|
|
120
|
+
address: Addr;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
export interface AdminResponse {
|
|
124
|
+
admin: Addr;
|
|
125
|
+
}
|
|
126
|
+
export type String = string;
|
|
127
|
+
export type Boolean = boolean;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Whitelist as RegistryWhitelist } from './ts/Registry.types';
|
|
2
|
+
import { Whitelist as MaciWhitelist } from './ts/Maci.types';
|
|
3
|
+
import { OfflineSigner } from '@cosmjs/proto-signing';
|
|
4
|
+
|
|
5
|
+
export enum MaciCircuitType {
|
|
6
|
+
IP1V = '0',
|
|
7
|
+
QV = '1',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export enum MaciCertSystemType {
|
|
11
|
+
GROTH16 = 'groth16',
|
|
12
|
+
PLONK = 'plonk',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export enum MaciRoundType {
|
|
16
|
+
MACI = '0',
|
|
17
|
+
AMACI = '1',
|
|
18
|
+
ORACLE_MACI = '2',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface CreateRoundParams {
|
|
22
|
+
signer: OfflineSigner;
|
|
23
|
+
title: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
link?: string;
|
|
26
|
+
startVoting: Date;
|
|
27
|
+
endVoting: Date;
|
|
28
|
+
maxVoter: string;
|
|
29
|
+
maxOption: string;
|
|
30
|
+
circuitType: MaciCircuitType;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type CreateAMaciRoundParams = {
|
|
34
|
+
operator: string;
|
|
35
|
+
whitelist: RegistryWhitelist;
|
|
36
|
+
voiceCreditAmount: string;
|
|
37
|
+
preDeactivateRoot?: string;
|
|
38
|
+
} & CreateRoundParams;
|
|
39
|
+
|
|
40
|
+
export type CreateMaciRoundParams = {
|
|
41
|
+
operatorPubkey: string;
|
|
42
|
+
whitelist: MaciWhitelist;
|
|
43
|
+
certSystemType: MaciCertSystemType;
|
|
44
|
+
} & CreateRoundParams;
|
|
45
|
+
|
|
46
|
+
export type CreateOracleMaciRoundParams = {
|
|
47
|
+
operatorPubkey: string;
|
|
48
|
+
whitelistEcosystem: string;
|
|
49
|
+
whitelistSnapshotHeight: string;
|
|
50
|
+
whitelistVotingPowerArgs: {
|
|
51
|
+
mode: string;
|
|
52
|
+
slope: string;
|
|
53
|
+
threshold: string;
|
|
54
|
+
};
|
|
55
|
+
whitelistBackendPubkey?: string;
|
|
56
|
+
feegrantOperator?: string;
|
|
57
|
+
} & CreateRoundParams;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { MaciCertSystemType, MaciCircuitType, MaciRoundType } from './types';
|
|
2
|
+
import { CIRCUIT_INFO } from './vars';
|
|
3
|
+
|
|
4
|
+
type MixedData<T> = T | Array<MixedData<T>> | { [key: string]: MixedData<T> };
|
|
5
|
+
|
|
6
|
+
export const stringizing = (
|
|
7
|
+
o: MixedData<bigint>,
|
|
8
|
+
path: MixedData<bigint>[] = []
|
|
9
|
+
): MixedData<string> => {
|
|
10
|
+
if (path.includes(o)) {
|
|
11
|
+
throw new Error('loop nesting!');
|
|
12
|
+
}
|
|
13
|
+
const newPath = [...path, o];
|
|
14
|
+
|
|
15
|
+
if (Array.isArray(o)) {
|
|
16
|
+
return o.map((item) => stringizing(item, newPath));
|
|
17
|
+
} else if (typeof o === 'object') {
|
|
18
|
+
const output: { [key: string]: MixedData<string> } = {};
|
|
19
|
+
for (const key in o) {
|
|
20
|
+
output[key] = stringizing(o[key], newPath);
|
|
21
|
+
}
|
|
22
|
+
return output;
|
|
23
|
+
} else {
|
|
24
|
+
return o.toString();
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export function getContractParams(
|
|
29
|
+
type: MaciRoundType,
|
|
30
|
+
circuitType: MaciCircuitType,
|
|
31
|
+
proofSystem: MaciCertSystemType,
|
|
32
|
+
maxVoter: string,
|
|
33
|
+
maxOption: string
|
|
34
|
+
) {
|
|
35
|
+
let parameters: {
|
|
36
|
+
state_tree_depth: string;
|
|
37
|
+
int_state_tree_depth: string;
|
|
38
|
+
vote_option_tree_depth: string;
|
|
39
|
+
message_batch_size: string;
|
|
40
|
+
};
|
|
41
|
+
let groth16ProcessVkey = null;
|
|
42
|
+
let groth16TallyVkey = null;
|
|
43
|
+
let plonkProcessVkey = null;
|
|
44
|
+
let plonkTallyVkey = null;
|
|
45
|
+
let maciVoteType = null;
|
|
46
|
+
let maciCertSystem = null;
|
|
47
|
+
|
|
48
|
+
switch (circuitType) {
|
|
49
|
+
case MaciCircuitType.IP1V:
|
|
50
|
+
maciVoteType = '0';
|
|
51
|
+
break;
|
|
52
|
+
case MaciCircuitType.QV:
|
|
53
|
+
maciVoteType = '1';
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
throw new Error(
|
|
57
|
+
`Invalid circuit type ${circuitType}, only support 1P1V and QV`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
switch (proofSystem) {
|
|
62
|
+
case MaciCertSystemType.GROTH16:
|
|
63
|
+
maciCertSystem = '0';
|
|
64
|
+
break;
|
|
65
|
+
case MaciCertSystemType.PLONK:
|
|
66
|
+
maciCertSystem = '1';
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
throw new Error(
|
|
70
|
+
`Invalid proof system ${proofSystem}, only support GROTH16 and PLONK`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (Number(maxVoter) <= 25 && Number(maxOption) <= 5) {
|
|
75
|
+
// state_tree_depth: 2
|
|
76
|
+
// vote_option_tree_depth: 1
|
|
77
|
+
parameters = CIRCUIT_INFO['2-1-1-5'].parameter;
|
|
78
|
+
if (proofSystem === MaciCertSystemType.GROTH16) {
|
|
79
|
+
groth16ProcessVkey = CIRCUIT_INFO['2-1-1-5']['groth16'].process_vkey;
|
|
80
|
+
groth16TallyVkey = CIRCUIT_INFO['2-1-1-5']['groth16'].tally_vkey;
|
|
81
|
+
} else if (proofSystem === MaciCertSystemType.PLONK) {
|
|
82
|
+
plonkProcessVkey = CIRCUIT_INFO['2-1-1-5']['plonk']?.process_vkey;
|
|
83
|
+
plonkTallyVkey = CIRCUIT_INFO['2-1-1-5']['plonk']?.tally_vkey;
|
|
84
|
+
}
|
|
85
|
+
} else if (Number(maxVoter) <= 625 && Number(maxOption) <= 25) {
|
|
86
|
+
// state_tree_depth: 4
|
|
87
|
+
// vote_option_tree_depth: 2
|
|
88
|
+
parameters = CIRCUIT_INFO['4-2-2-25'].parameter;
|
|
89
|
+
if (proofSystem === MaciCertSystemType.GROTH16) {
|
|
90
|
+
groth16ProcessVkey = CIRCUIT_INFO['4-2-2-25']['groth16'].process_vkey;
|
|
91
|
+
groth16TallyVkey = CIRCUIT_INFO['4-2-2-25']['groth16'].tally_vkey;
|
|
92
|
+
} else if (proofSystem === MaciCertSystemType.PLONK) {
|
|
93
|
+
plonkProcessVkey = CIRCUIT_INFO['4-2-2-25']['plonk']?.process_vkey;
|
|
94
|
+
plonkTallyVkey = CIRCUIT_INFO['4-2-2-25']['plonk']?.tally_vkey;
|
|
95
|
+
}
|
|
96
|
+
} else if (Number(maxVoter) <= 15625 && Number(maxOption) <= 125) {
|
|
97
|
+
// state_tree_depth: 6
|
|
98
|
+
// vote_option_tree_depth: 3
|
|
99
|
+
parameters = CIRCUIT_INFO['6-3-3-125'].parameter;
|
|
100
|
+
if (proofSystem === MaciCertSystemType.GROTH16) {
|
|
101
|
+
groth16ProcessVkey = CIRCUIT_INFO['6-3-3-125']['groth16'].process_vkey;
|
|
102
|
+
groth16TallyVkey = CIRCUIT_INFO['6-3-3-125']['groth16'].tally_vkey;
|
|
103
|
+
} else if (proofSystem === MaciCertSystemType.PLONK) {
|
|
104
|
+
plonkProcessVkey = CIRCUIT_INFO['6-3-3-125']['plonk']?.process_vkey;
|
|
105
|
+
plonkTallyVkey = CIRCUIT_INFO['6-3-3-125']['plonk']?.tally_vkey;
|
|
106
|
+
}
|
|
107
|
+
} else if (Number(maxVoter) <= 1953125 && Number(maxOption) <= 125) {
|
|
108
|
+
// state_tree_depth: 9
|
|
109
|
+
// vote_option_tree_depth: 3
|
|
110
|
+
parameters = CIRCUIT_INFO['9-4-3-625'].parameter;
|
|
111
|
+
if (proofSystem === MaciCertSystemType.GROTH16) {
|
|
112
|
+
groth16ProcessVkey = CIRCUIT_INFO['9-4-3-625']['groth16'].process_vkey;
|
|
113
|
+
groth16TallyVkey = CIRCUIT_INFO['9-4-3-625']['groth16'].tally_vkey;
|
|
114
|
+
} else if (proofSystem === MaciCertSystemType.PLONK) {
|
|
115
|
+
throw new Error('PLONK is not supported for MACI-9');
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
throw new Error('Number of voters or options is too large.');
|
|
119
|
+
}
|
|
120
|
+
switch (type) {
|
|
121
|
+
case MaciRoundType.MACI:
|
|
122
|
+
return {
|
|
123
|
+
parameters,
|
|
124
|
+
groth16ProcessVkey,
|
|
125
|
+
groth16TallyVkey,
|
|
126
|
+
plonkProcessVkey,
|
|
127
|
+
plonkTallyVkey,
|
|
128
|
+
maciVoteType,
|
|
129
|
+
maciCertSystem,
|
|
130
|
+
};
|
|
131
|
+
case MaciRoundType.AMACI:
|
|
132
|
+
return {
|
|
133
|
+
// parameters,
|
|
134
|
+
// groth16ProcessVkey,
|
|
135
|
+
// groth16TallyVkey,
|
|
136
|
+
// plonkProcessVkey,
|
|
137
|
+
// plonkTallyVkey,
|
|
138
|
+
};
|
|
139
|
+
case MaciRoundType.ORACLE_MACI:
|
|
140
|
+
return {
|
|
141
|
+
parameters: CIRCUIT_INFO['9-4-3-625'].parameter,
|
|
142
|
+
groth16ProcessVkey: CIRCUIT_INFO['9-4-3-625']['groth16'].process_vkey,
|
|
143
|
+
groth16TallyVkey: CIRCUIT_INFO['9-4-3-625']['groth16'].tally_vkey,
|
|
144
|
+
plonkProcessVkey: null,
|
|
145
|
+
plonkTallyVkey: null,
|
|
146
|
+
maciVoteType,
|
|
147
|
+
maciCertSystem: '0',
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Converts a hexadecimal string to a decimal string.
|
|
154
|
+
* @param hexString - The hexadecimal string to convert.
|
|
155
|
+
* @returns The decimal string representation of the input.
|
|
156
|
+
*/
|
|
157
|
+
function hexToDecimalString(hexString: string) {
|
|
158
|
+
const decimalString = BigInt('0x' + hexString).toString(10);
|
|
159
|
+
return decimalString;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Parses a public key string into its x and y coordinates.
|
|
164
|
+
* @param publickKey - The public key string to parse (128 characters long).
|
|
165
|
+
* @returns An object containing the x and y coordinates as decimal strings.
|
|
166
|
+
*/
|
|
167
|
+
export function parsePubkey(publickKey: string) {
|
|
168
|
+
const x = publickKey.slice(0, 64);
|
|
169
|
+
const y = publickKey.slice(64);
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
x: hexToDecimalString(x),
|
|
173
|
+
y: hexToDecimalString(y),
|
|
174
|
+
};
|
|
175
|
+
}
|