@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.
- package/README.md +27 -7
- package/dist/index.js +751 -187
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +748 -187
- package/dist/index.mjs.map +1 -1
- package/dist/libs/circom/tree.d.ts +20 -20
- package/dist/libs/contract/ts/AMaci.client.d.ts +1 -1
- package/dist/libs/contract/ts/Maci.client.d.ts +21 -47
- package/dist/libs/contract/ts/Maci.types.d.ts +40 -31
- package/dist/libs/contract/ts/OracleMaci.client.d.ts +52 -52
- package/dist/libs/contract/ts/OracleMaci.types.d.ts +17 -7
- package/dist/libs/contract/ts/Registry.client.d.ts +2 -2
- package/dist/libs/contract/types.d.ts +2 -2
- package/dist/libs/errors/types.d.ts +1 -0
- package/dist/libs/http/http.d.ts +1 -1
- package/dist/libs/index.d.ts +3 -0
- package/dist/libs/indexer/indexer.d.ts +11 -2
- package/dist/libs/maci/index.d.ts +1 -0
- package/dist/libs/maci/maci.d.ts +64 -5
- package/dist/libs/oracle-certificate/oracle-certificate.d.ts +1 -21
- package/dist/libs/oracle-certificate/types.d.ts +12 -0
- package/dist/libs/query/event.d.ts +7 -0
- package/dist/libs/query/index.d.ts +1 -0
- package/dist/maci.d.ts +7 -5
- package/dist/types/index.d.ts +22 -0
- package/package.json +1 -1
- package/src/libs/const.ts +3 -2
- package/src/libs/contract/contract.ts +2 -6
- package/src/libs/contract/ts/AMaci.client.ts +868 -874
- package/src/libs/contract/ts/AMaci.types.ts +216 -216
- package/src/libs/contract/ts/Maci.client.ts +748 -888
- package/src/libs/contract/ts/Maci.types.ts +229 -224
- package/src/libs/contract/ts/OracleMaci.client.ts +623 -348
- package/src/libs/contract/ts/OracleMaci.types.ts +191 -138
- package/src/libs/contract/ts/Registry.client.ts +438 -446
- package/src/libs/contract/ts/Registry.types.ts +97 -97
- package/src/libs/contract/types.ts +6 -2
- package/src/libs/contract/utils.ts +9 -0
- package/src/libs/errors/types.ts +1 -0
- package/src/libs/http/http.ts +3 -7
- package/src/libs/index.ts +3 -0
- package/src/libs/indexer/indexer.ts +18 -0
- package/src/libs/maci/index.ts +1 -0
- package/src/libs/maci/maci.ts +302 -10
- package/src/libs/oracle-certificate/oracle-certificate.ts +19 -73
- package/src/libs/oracle-certificate/types.ts +15 -1
- package/src/libs/query/event.ts +78 -0
- package/src/libs/query/index.ts +1 -0
- package/src/maci.ts +27 -5
- package/src/types/index.ts +28 -0
package/dist/index.js
CHANGED
|
@@ -33,13 +33,16 @@ __export(src_exports, {
|
|
|
33
33
|
Circom: () => Circom,
|
|
34
34
|
Circuit: () => Circuit,
|
|
35
35
|
Contract: () => Contract,
|
|
36
|
+
Event: () => Event,
|
|
36
37
|
Http: () => Http,
|
|
37
38
|
Indexer: () => Indexer,
|
|
39
|
+
MACI: () => MACI,
|
|
38
40
|
MaciCertSystemType: () => MaciCertSystemType,
|
|
39
41
|
MaciCircuitType: () => MaciCircuitType,
|
|
40
42
|
MaciClient: () => MaciClient2,
|
|
41
43
|
MaciRoundType: () => MaciRoundType,
|
|
42
44
|
Operator: () => Operator,
|
|
45
|
+
OracleCertificate: () => OracleCertificate,
|
|
43
46
|
Proof: () => Proof,
|
|
44
47
|
Round: () => Round,
|
|
45
48
|
Scalar: () => import_ffjavascript2.Scalar,
|
|
@@ -179,11 +182,12 @@ var Http = class {
|
|
|
179
182
|
getFetch() {
|
|
180
183
|
return this.customFetch || fetch;
|
|
181
184
|
}
|
|
182
|
-
async fetch(url) {
|
|
185
|
+
async fetch(url, options) {
|
|
183
186
|
try {
|
|
184
187
|
const fetchFn = this.getFetch();
|
|
185
188
|
const response = await fetchFn(url, {
|
|
186
|
-
...this.defaultOptions
|
|
189
|
+
...this.defaultOptions,
|
|
190
|
+
...options
|
|
187
191
|
});
|
|
188
192
|
if (!response.ok) {
|
|
189
193
|
throw new HttpError(
|
|
@@ -294,7 +298,8 @@ var ERROR = {
|
|
|
294
298
|
ERROR_ROUND_NOT_FOUND: "ERROR_ROUND_NOT_FOUND",
|
|
295
299
|
ERROR_ROUNDS_NOT_FOUND: "ERROR_ROUNDS_NOT_FOUND",
|
|
296
300
|
ERROR_TRANSACTION_NOT_FOUND: "ERROR_TRANSACTION_NOT_FOUND",
|
|
297
|
-
ERROR_TRANSACTIONS_NOT_FOUND: "ERROR_TRANSACTIONS_NOT_FOUND"
|
|
301
|
+
ERROR_TRANSACTIONS_NOT_FOUND: "ERROR_TRANSACTIONS_NOT_FOUND",
|
|
302
|
+
ERROR_SIGN_UP_EVENTS_NOT_FOUND: "ERROR_SIGN_UP_EVENTS_NOT_FOUND"
|
|
298
303
|
};
|
|
299
304
|
|
|
300
305
|
// src/libs/query/account.ts
|
|
@@ -470,7 +475,7 @@ function getDefaultParams(network = "mainnet") {
|
|
|
470
475
|
rpcEndpoint: "https://vota-rpc.dorafactory.org",
|
|
471
476
|
restEndpoint: "https://vota-rest.dorafactory.org",
|
|
472
477
|
apiEndpoint: "https://vota-api.dorafactory.org",
|
|
473
|
-
certificateApiEndpoint: "https://vota-certificate-api.dorafactory.org",
|
|
478
|
+
certificateApiEndpoint: "https://vota-certificate-api.dorafactory.org/api/v1",
|
|
474
479
|
registryAddress: "dora1smg5qp5trjdkcekdjssqpjehdjf6n4cjss0clyvqcud3t3u3948s8rmgg4",
|
|
475
480
|
maciCodeId: 106,
|
|
476
481
|
oracleCodeId: 111,
|
|
@@ -484,7 +489,7 @@ function getDefaultParams(network = "mainnet") {
|
|
|
484
489
|
rpcEndpoint: "https://vota-testnet-rpc.dorafactory.org",
|
|
485
490
|
restEndpoint: "https://vota-testnet-rest.dorafactory.org",
|
|
486
491
|
apiEndpoint: "https://vota-testnet-api.dorafactory.org",
|
|
487
|
-
certificateApiEndpoint: "https://vota-testnet-certificate-api.dorafactory.org",
|
|
492
|
+
certificateApiEndpoint: "https://vota-testnet-certificate-api.dorafactory.org/api/v1",
|
|
488
493
|
registryAddress: "dora13c8aecstyxrhax9znvvh5zey89edrmd2k5va57pxvpe3fxtfsfeqlhsjnd",
|
|
489
494
|
maciCodeId: 107,
|
|
490
495
|
oracleCodeId: 110,
|
|
@@ -1487,6 +1492,63 @@ var Proof = class {
|
|
|
1487
1492
|
}
|
|
1488
1493
|
};
|
|
1489
1494
|
|
|
1495
|
+
// src/libs/query/event.ts
|
|
1496
|
+
var Event = class {
|
|
1497
|
+
constructor(http) {
|
|
1498
|
+
this.http = http;
|
|
1499
|
+
}
|
|
1500
|
+
async getSignUpEventByPubKey(contractAddress, pubKey) {
|
|
1501
|
+
try {
|
|
1502
|
+
const STATE_IDX_BY_PUB_KEY_QUERY = `
|
|
1503
|
+
query signUpEvents($limit: Int, $after: Cursor) {
|
|
1504
|
+
signUpEvents(
|
|
1505
|
+
first: $limit, after: $after,
|
|
1506
|
+
filter: {
|
|
1507
|
+
contractAddress: {
|
|
1508
|
+
equalTo: "${contractAddress}"
|
|
1509
|
+
}
|
|
1510
|
+
pubKey: {
|
|
1511
|
+
equalTo: "${pubKey.map((n) => `\\"${n}\\"`).join(",")}"
|
|
1512
|
+
}
|
|
1513
|
+
}) {
|
|
1514
|
+
nodes {
|
|
1515
|
+
id
|
|
1516
|
+
blockHeight
|
|
1517
|
+
txHash
|
|
1518
|
+
contractAddress
|
|
1519
|
+
timestamp
|
|
1520
|
+
pubKey
|
|
1521
|
+
stateIdx
|
|
1522
|
+
balance
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
`;
|
|
1527
|
+
const response = await this.http.fetchGraphql(
|
|
1528
|
+
STATE_IDX_BY_PUB_KEY_QUERY,
|
|
1529
|
+
""
|
|
1530
|
+
);
|
|
1531
|
+
if (!response || !response.data || !response.data.signUpEvents || !response.data.signUpEvents.nodes || response.data.signUpEvents.nodes.length === 0) {
|
|
1532
|
+
return {
|
|
1533
|
+
code: 404,
|
|
1534
|
+
error: {
|
|
1535
|
+
message: `No signUpEvents found for pubKey ${pubKey.map((n) => `"${n}"`).join(",")}`,
|
|
1536
|
+
type: ERROR.ERROR_SIGN_UP_EVENTS_NOT_FOUND
|
|
1537
|
+
}
|
|
1538
|
+
};
|
|
1539
|
+
}
|
|
1540
|
+
return {
|
|
1541
|
+
code: 200,
|
|
1542
|
+
data: {
|
|
1543
|
+
signUpEvents: response.data.signUpEvents.nodes
|
|
1544
|
+
}
|
|
1545
|
+
};
|
|
1546
|
+
} catch (error) {
|
|
1547
|
+
return handleError(error);
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
};
|
|
1551
|
+
|
|
1490
1552
|
// src/libs/indexer/indexer.ts
|
|
1491
1553
|
var Indexer = class {
|
|
1492
1554
|
/**
|
|
@@ -1509,6 +1571,7 @@ var Indexer = class {
|
|
|
1509
1571
|
this.operator = new Operator(this.http, this.registryAddress);
|
|
1510
1572
|
this.proof = new Proof(this.http);
|
|
1511
1573
|
this.transaction = new Transaction(this.http);
|
|
1574
|
+
this.event = new Event(this.http);
|
|
1512
1575
|
}
|
|
1513
1576
|
/**
|
|
1514
1577
|
* @method balanceOf
|
|
@@ -1650,6 +1713,16 @@ var Indexer = class {
|
|
|
1650
1713
|
async getProofByContractAddress(address) {
|
|
1651
1714
|
return await this.proof.getProofByContractAddress(address);
|
|
1652
1715
|
}
|
|
1716
|
+
/**
|
|
1717
|
+
* @method getStateIdxByPubKey
|
|
1718
|
+
* @description Get the state index of a specific public key.
|
|
1719
|
+
* @param {string} contractAddress - The contract address.
|
|
1720
|
+
* @param {bigint[]} pubKey - The public key.
|
|
1721
|
+
* @returns {Promise<SignUpEventsResponse>} The sign up events response.
|
|
1722
|
+
*/
|
|
1723
|
+
async getSignUpEventByPubKey(contractAddress, pubKey) {
|
|
1724
|
+
return await this.event.getSignUpEventByPubKey(contractAddress, pubKey);
|
|
1725
|
+
}
|
|
1653
1726
|
};
|
|
1654
1727
|
|
|
1655
1728
|
// src/libs/contract/config.ts
|
|
@@ -1684,16 +1757,6 @@ var MaciQueryClient = class {
|
|
|
1684
1757
|
get_msg_chain_length: {}
|
|
1685
1758
|
});
|
|
1686
1759
|
};
|
|
1687
|
-
this.getDMsgChainLength = async () => {
|
|
1688
|
-
return this.client.queryContractSmart(this.contractAddress, {
|
|
1689
|
-
get_d_msg_chain_length: {}
|
|
1690
|
-
});
|
|
1691
|
-
};
|
|
1692
|
-
this.getProcessedDMsgCount = async () => {
|
|
1693
|
-
return this.client.queryContractSmart(this.contractAddress, {
|
|
1694
|
-
get_processed_d_msg_count: {}
|
|
1695
|
-
});
|
|
1696
|
-
};
|
|
1697
1760
|
this.getProcessedMsgCount = async () => {
|
|
1698
1761
|
return this.client.queryContractSmart(this.contractAddress, {
|
|
1699
1762
|
get_processed_msg_count: {}
|
|
@@ -1716,9 +1779,7 @@ var MaciQueryClient = class {
|
|
|
1716
1779
|
get_all_result: {}
|
|
1717
1780
|
});
|
|
1718
1781
|
};
|
|
1719
|
-
this.getStateIdxInc = async ({
|
|
1720
|
-
address
|
|
1721
|
-
}) => {
|
|
1782
|
+
this.getStateIdxInc = async ({ address }) => {
|
|
1722
1783
|
return this.client.queryContractSmart(this.contractAddress, {
|
|
1723
1784
|
get_state_idx_inc: {
|
|
1724
1785
|
address
|
|
@@ -1746,6 +1807,13 @@ var MaciQueryClient = class {
|
|
|
1746
1807
|
}
|
|
1747
1808
|
});
|
|
1748
1809
|
};
|
|
1810
|
+
this.whiteBalanceOf = async ({ sender }) => {
|
|
1811
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
1812
|
+
white_balance_of: {
|
|
1813
|
+
sender
|
|
1814
|
+
}
|
|
1815
|
+
});
|
|
1816
|
+
};
|
|
1749
1817
|
this.voteOptionMap = async () => {
|
|
1750
1818
|
return this.client.queryContractSmart(this.contractAddress, {
|
|
1751
1819
|
vote_option_map: {}
|
|
@@ -1778,8 +1846,6 @@ var MaciQueryClient = class {
|
|
|
1778
1846
|
this.getPeriod = this.getPeriod.bind(this);
|
|
1779
1847
|
this.getNumSignUp = this.getNumSignUp.bind(this);
|
|
1780
1848
|
this.getMsgChainLength = this.getMsgChainLength.bind(this);
|
|
1781
|
-
this.getDMsgChainLength = this.getDMsgChainLength.bind(this);
|
|
1782
|
-
this.getProcessedDMsgCount = this.getProcessedDMsgCount.bind(this);
|
|
1783
1849
|
this.getProcessedMsgCount = this.getProcessedMsgCount.bind(this);
|
|
1784
1850
|
this.getProcessedUserCount = this.getProcessedUserCount.bind(this);
|
|
1785
1851
|
this.getResult = this.getResult.bind(this);
|
|
@@ -1788,6 +1854,7 @@ var MaciQueryClient = class {
|
|
|
1788
1854
|
this.getVoiceCreditBalance = this.getVoiceCreditBalance.bind(this);
|
|
1789
1855
|
this.whiteList = this.whiteList.bind(this);
|
|
1790
1856
|
this.isWhiteList = this.isWhiteList.bind(this);
|
|
1857
|
+
this.whiteBalanceOf = this.whiteBalanceOf.bind(this);
|
|
1791
1858
|
this.voteOptionMap = this.voteOptionMap.bind(this);
|
|
1792
1859
|
this.maxVoteOptions = this.maxVoteOptions.bind(this);
|
|
1793
1860
|
this.queryTotalFeeGrant = this.queryTotalFeeGrant.bind(this);
|
|
@@ -1920,68 +1987,6 @@ var MaciClient = class extends MaciQueryClient {
|
|
|
1920
1987
|
_funds
|
|
1921
1988
|
);
|
|
1922
1989
|
};
|
|
1923
|
-
this.publishDeactivateMessage = async ({
|
|
1924
|
-
encPubKey,
|
|
1925
|
-
message
|
|
1926
|
-
}, fee = "auto", memo, _funds) => {
|
|
1927
|
-
return await this.client.execute(
|
|
1928
|
-
this.sender,
|
|
1929
|
-
this.contractAddress,
|
|
1930
|
-
{
|
|
1931
|
-
publish_deactivate_message: {
|
|
1932
|
-
enc_pub_key: encPubKey,
|
|
1933
|
-
message
|
|
1934
|
-
}
|
|
1935
|
-
},
|
|
1936
|
-
fee,
|
|
1937
|
-
memo,
|
|
1938
|
-
_funds
|
|
1939
|
-
);
|
|
1940
|
-
};
|
|
1941
|
-
this.processDeactivateMessage = async ({
|
|
1942
|
-
groth16Proof,
|
|
1943
|
-
newDeactivateCommitment,
|
|
1944
|
-
newDeactivateRoot,
|
|
1945
|
-
size
|
|
1946
|
-
}, fee = "auto", memo, _funds) => {
|
|
1947
|
-
return await this.client.execute(
|
|
1948
|
-
this.sender,
|
|
1949
|
-
this.contractAddress,
|
|
1950
|
-
{
|
|
1951
|
-
process_deactivate_message: {
|
|
1952
|
-
groth16_proof: groth16Proof,
|
|
1953
|
-
new_deactivate_commitment: newDeactivateCommitment,
|
|
1954
|
-
new_deactivate_root: newDeactivateRoot,
|
|
1955
|
-
size
|
|
1956
|
-
}
|
|
1957
|
-
},
|
|
1958
|
-
fee,
|
|
1959
|
-
memo,
|
|
1960
|
-
_funds
|
|
1961
|
-
);
|
|
1962
|
-
};
|
|
1963
|
-
this.addNewKey = async ({
|
|
1964
|
-
d,
|
|
1965
|
-
groth16Proof,
|
|
1966
|
-
nullifier,
|
|
1967
|
-
pubkey
|
|
1968
|
-
}, fee = "auto", memo, _funds) => {
|
|
1969
|
-
return await this.client.execute(
|
|
1970
|
-
this.sender,
|
|
1971
|
-
this.contractAddress,
|
|
1972
|
-
{
|
|
1973
|
-
add_new_key: {
|
|
1974
|
-
d,
|
|
1975
|
-
groth16_proof: groth16Proof,
|
|
1976
|
-
nullifier,
|
|
1977
|
-
pubkey
|
|
1978
|
-
}
|
|
1979
|
-
},
|
|
1980
|
-
fee,
|
|
1981
|
-
memo,
|
|
1982
|
-
_funds
|
|
1983
|
-
);
|
|
1984
|
-
};
|
|
1985
1990
|
this.publishMessage = async ({
|
|
1986
1991
|
encPubKey,
|
|
1987
1992
|
message
|
|
@@ -2002,7 +2007,8 @@ var MaciClient = class extends MaciQueryClient {
|
|
|
2002
2007
|
};
|
|
2003
2008
|
this.processMessage = async ({
|
|
2004
2009
|
groth16Proof,
|
|
2005
|
-
newStateCommitment
|
|
2010
|
+
newStateCommitment,
|
|
2011
|
+
plonkProof
|
|
2006
2012
|
}, fee = "auto", memo, _funds) => {
|
|
2007
2013
|
return await this.client.execute(
|
|
2008
2014
|
this.sender,
|
|
@@ -2010,7 +2016,8 @@ var MaciClient = class extends MaciQueryClient {
|
|
|
2010
2016
|
{
|
|
2011
2017
|
process_message: {
|
|
2012
2018
|
groth16_proof: groth16Proof,
|
|
2013
|
-
new_state_commitment: newStateCommitment
|
|
2019
|
+
new_state_commitment: newStateCommitment,
|
|
2020
|
+
plonk_proof: plonkProof
|
|
2014
2021
|
}
|
|
2015
2022
|
},
|
|
2016
2023
|
fee,
|
|
@@ -2032,7 +2039,8 @@ var MaciClient = class extends MaciQueryClient {
|
|
|
2032
2039
|
};
|
|
2033
2040
|
this.processTally = async ({
|
|
2034
2041
|
groth16Proof,
|
|
2035
|
-
newTallyCommitment
|
|
2042
|
+
newTallyCommitment,
|
|
2043
|
+
plonkProof
|
|
2036
2044
|
}, fee = "auto", memo, _funds) => {
|
|
2037
2045
|
return await this.client.execute(
|
|
2038
2046
|
this.sender,
|
|
@@ -2040,7 +2048,8 @@ var MaciClient = class extends MaciQueryClient {
|
|
|
2040
2048
|
{
|
|
2041
2049
|
process_tally: {
|
|
2042
2050
|
groth16_proof: groth16Proof,
|
|
2043
|
-
new_tally_commitment: newTallyCommitment
|
|
2051
|
+
new_tally_commitment: newTallyCommitment,
|
|
2052
|
+
plonk_proof: plonkProof
|
|
2044
2053
|
}
|
|
2045
2054
|
},
|
|
2046
2055
|
fee,
|
|
@@ -2133,9 +2142,6 @@ var MaciClient = class extends MaciQueryClient {
|
|
|
2133
2142
|
this.signUp = this.signUp.bind(this);
|
|
2134
2143
|
this.startProcessPeriod = this.startProcessPeriod.bind(this);
|
|
2135
2144
|
this.stopVotingPeriod = this.stopVotingPeriod.bind(this);
|
|
2136
|
-
this.publishDeactivateMessage = this.publishDeactivateMessage.bind(this);
|
|
2137
|
-
this.processDeactivateMessage = this.processDeactivateMessage.bind(this);
|
|
2138
|
-
this.addNewKey = this.addNewKey.bind(this);
|
|
2139
2145
|
this.publishMessage = this.publishMessage.bind(this);
|
|
2140
2146
|
this.processMessage = this.processMessage.bind(this);
|
|
2141
2147
|
this.stopProcessingPeriod = this.stopProcessingPeriod.bind(this);
|
|
@@ -2218,9 +2224,7 @@ var AMaciQueryClient = class {
|
|
|
2218
2224
|
get_all_result: {}
|
|
2219
2225
|
});
|
|
2220
2226
|
};
|
|
2221
|
-
this.getStateIdxInc = async ({
|
|
2222
|
-
address
|
|
2223
|
-
}) => {
|
|
2227
|
+
this.getStateIdxInc = async ({ address }) => {
|
|
2224
2228
|
return this.client.queryContractSmart(this.contractAddress, {
|
|
2225
2229
|
get_state_idx_inc: {
|
|
2226
2230
|
address
|
|
@@ -2659,9 +2663,7 @@ var RegistryQueryClient = class {
|
|
|
2659
2663
|
operator: {}
|
|
2660
2664
|
});
|
|
2661
2665
|
};
|
|
2662
|
-
this.isMaciOperator = async ({
|
|
2663
|
-
address
|
|
2664
|
-
}) => {
|
|
2666
|
+
this.isMaciOperator = async ({ address }) => {
|
|
2665
2667
|
return this.client.queryContractSmart(this.contractAddress, {
|
|
2666
2668
|
is_maci_operator: {
|
|
2667
2669
|
address
|
|
@@ -2920,9 +2922,7 @@ var OracleMaciQueryClient = class {
|
|
|
2920
2922
|
get_processed_user_count: {}
|
|
2921
2923
|
});
|
|
2922
2924
|
};
|
|
2923
|
-
this.getResult = async ({
|
|
2924
|
-
index
|
|
2925
|
-
}) => {
|
|
2925
|
+
this.getResult = async ({ index }) => {
|
|
2926
2926
|
return this.client.queryContractSmart(this.contractAddress, {
|
|
2927
2927
|
get_result: {
|
|
2928
2928
|
index
|
|
@@ -2934,9 +2934,7 @@ var OracleMaciQueryClient = class {
|
|
|
2934
2934
|
get_all_result: {}
|
|
2935
2935
|
});
|
|
2936
2936
|
};
|
|
2937
|
-
this.getStateIdxInc = async ({
|
|
2938
|
-
address
|
|
2939
|
-
}) => {
|
|
2937
|
+
this.getStateIdxInc = async ({ address }) => {
|
|
2940
2938
|
return this.client.queryContractSmart(this.contractAddress, {
|
|
2941
2939
|
get_state_idx_inc: {
|
|
2942
2940
|
address
|
|
@@ -3066,147 +3064,259 @@ var OracleMaciClient = class extends OracleMaciQueryClient {
|
|
|
3066
3064
|
stateTreeDepth,
|
|
3067
3065
|
voteOptionTreeDepth
|
|
3068
3066
|
}, fee = "auto", memo, _funds) => {
|
|
3069
|
-
return await this.client.execute(
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3067
|
+
return await this.client.execute(
|
|
3068
|
+
this.sender,
|
|
3069
|
+
this.contractAddress,
|
|
3070
|
+
{
|
|
3071
|
+
set_params: {
|
|
3072
|
+
int_state_tree_depth: intStateTreeDepth,
|
|
3073
|
+
message_batch_size: messageBatchSize,
|
|
3074
|
+
state_tree_depth: stateTreeDepth,
|
|
3075
|
+
vote_option_tree_depth: voteOptionTreeDepth
|
|
3076
|
+
}
|
|
3077
|
+
},
|
|
3078
|
+
fee,
|
|
3079
|
+
memo,
|
|
3080
|
+
_funds
|
|
3081
|
+
);
|
|
3077
3082
|
};
|
|
3078
3083
|
this.setRoundInfo = async ({
|
|
3079
3084
|
roundInfo
|
|
3080
3085
|
}, fee = "auto", memo, _funds) => {
|
|
3081
|
-
return await this.client.execute(
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
+
return await this.client.execute(
|
|
3087
|
+
this.sender,
|
|
3088
|
+
this.contractAddress,
|
|
3089
|
+
{
|
|
3090
|
+
set_round_info: {
|
|
3091
|
+
round_info: roundInfo
|
|
3092
|
+
}
|
|
3093
|
+
},
|
|
3094
|
+
fee,
|
|
3095
|
+
memo,
|
|
3096
|
+
_funds
|
|
3097
|
+
);
|
|
3086
3098
|
};
|
|
3087
3099
|
this.setVoteOptionsMap = async ({
|
|
3088
3100
|
voteOptionMap
|
|
3089
3101
|
}, fee = "auto", memo, _funds) => {
|
|
3090
|
-
return await this.client.execute(
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3102
|
+
return await this.client.execute(
|
|
3103
|
+
this.sender,
|
|
3104
|
+
this.contractAddress,
|
|
3105
|
+
{
|
|
3106
|
+
set_vote_options_map: {
|
|
3107
|
+
vote_option_map: voteOptionMap
|
|
3108
|
+
}
|
|
3109
|
+
},
|
|
3110
|
+
fee,
|
|
3111
|
+
memo,
|
|
3112
|
+
_funds
|
|
3113
|
+
);
|
|
3095
3114
|
};
|
|
3096
3115
|
this.startVotingPeriod = async (fee = "auto", memo, _funds) => {
|
|
3097
|
-
return await this.client.execute(
|
|
3098
|
-
|
|
3099
|
-
|
|
3116
|
+
return await this.client.execute(
|
|
3117
|
+
this.sender,
|
|
3118
|
+
this.contractAddress,
|
|
3119
|
+
{
|
|
3120
|
+
start_voting_period: {}
|
|
3121
|
+
},
|
|
3122
|
+
fee,
|
|
3123
|
+
memo,
|
|
3124
|
+
_funds
|
|
3125
|
+
);
|
|
3100
3126
|
};
|
|
3101
3127
|
this.signUp = async ({
|
|
3102
3128
|
amount,
|
|
3103
3129
|
certificate,
|
|
3104
3130
|
pubkey
|
|
3105
3131
|
}, fee = "auto", memo, _funds) => {
|
|
3106
|
-
return await this.client.execute(
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3132
|
+
return await this.client.execute(
|
|
3133
|
+
this.sender,
|
|
3134
|
+
this.contractAddress,
|
|
3135
|
+
{
|
|
3136
|
+
sign_up: {
|
|
3137
|
+
amount,
|
|
3138
|
+
certificate,
|
|
3139
|
+
pubkey
|
|
3140
|
+
}
|
|
3141
|
+
},
|
|
3142
|
+
fee,
|
|
3143
|
+
memo,
|
|
3144
|
+
_funds
|
|
3145
|
+
);
|
|
3113
3146
|
};
|
|
3114
3147
|
this.startProcessPeriod = async (fee = "auto", memo, _funds) => {
|
|
3115
|
-
return await this.client.execute(
|
|
3116
|
-
|
|
3117
|
-
|
|
3148
|
+
return await this.client.execute(
|
|
3149
|
+
this.sender,
|
|
3150
|
+
this.contractAddress,
|
|
3151
|
+
{
|
|
3152
|
+
start_process_period: {}
|
|
3153
|
+
},
|
|
3154
|
+
fee,
|
|
3155
|
+
memo,
|
|
3156
|
+
_funds
|
|
3157
|
+
);
|
|
3118
3158
|
};
|
|
3119
3159
|
this.stopVotingPeriod = async (fee = "auto", memo, _funds) => {
|
|
3120
|
-
return await this.client.execute(
|
|
3121
|
-
|
|
3122
|
-
|
|
3160
|
+
return await this.client.execute(
|
|
3161
|
+
this.sender,
|
|
3162
|
+
this.contractAddress,
|
|
3163
|
+
{
|
|
3164
|
+
stop_voting_period: {}
|
|
3165
|
+
},
|
|
3166
|
+
fee,
|
|
3167
|
+
memo,
|
|
3168
|
+
_funds
|
|
3169
|
+
);
|
|
3123
3170
|
};
|
|
3124
3171
|
this.publishMessage = async ({
|
|
3125
3172
|
encPubKey,
|
|
3126
3173
|
message
|
|
3127
3174
|
}, fee = "auto", memo, _funds) => {
|
|
3128
|
-
return await this.client.execute(
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3175
|
+
return await this.client.execute(
|
|
3176
|
+
this.sender,
|
|
3177
|
+
this.contractAddress,
|
|
3178
|
+
{
|
|
3179
|
+
publish_message: {
|
|
3180
|
+
enc_pub_key: encPubKey,
|
|
3181
|
+
message
|
|
3182
|
+
}
|
|
3183
|
+
},
|
|
3184
|
+
fee,
|
|
3185
|
+
memo,
|
|
3186
|
+
_funds
|
|
3187
|
+
);
|
|
3134
3188
|
};
|
|
3135
3189
|
this.processMessage = async ({
|
|
3136
3190
|
groth16Proof,
|
|
3137
3191
|
newStateCommitment,
|
|
3138
3192
|
plonkProof
|
|
3139
3193
|
}, fee = "auto", memo, _funds) => {
|
|
3140
|
-
return await this.client.execute(
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3194
|
+
return await this.client.execute(
|
|
3195
|
+
this.sender,
|
|
3196
|
+
this.contractAddress,
|
|
3197
|
+
{
|
|
3198
|
+
process_message: {
|
|
3199
|
+
groth16_proof: groth16Proof,
|
|
3200
|
+
new_state_commitment: newStateCommitment,
|
|
3201
|
+
plonk_proof: plonkProof
|
|
3202
|
+
}
|
|
3203
|
+
},
|
|
3204
|
+
fee,
|
|
3205
|
+
memo,
|
|
3206
|
+
_funds
|
|
3207
|
+
);
|
|
3147
3208
|
};
|
|
3148
3209
|
this.stopProcessingPeriod = async (fee = "auto", memo, _funds) => {
|
|
3149
|
-
return await this.client.execute(
|
|
3150
|
-
|
|
3151
|
-
|
|
3210
|
+
return await this.client.execute(
|
|
3211
|
+
this.sender,
|
|
3212
|
+
this.contractAddress,
|
|
3213
|
+
{
|
|
3214
|
+
stop_processing_period: {}
|
|
3215
|
+
},
|
|
3216
|
+
fee,
|
|
3217
|
+
memo,
|
|
3218
|
+
_funds
|
|
3219
|
+
);
|
|
3152
3220
|
};
|
|
3153
3221
|
this.processTally = async ({
|
|
3154
3222
|
groth16Proof,
|
|
3155
3223
|
newTallyCommitment,
|
|
3156
3224
|
plonkProof
|
|
3157
3225
|
}, fee = "auto", memo, _funds) => {
|
|
3158
|
-
return await this.client.execute(
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3226
|
+
return await this.client.execute(
|
|
3227
|
+
this.sender,
|
|
3228
|
+
this.contractAddress,
|
|
3229
|
+
{
|
|
3230
|
+
process_tally: {
|
|
3231
|
+
groth16_proof: groth16Proof,
|
|
3232
|
+
new_tally_commitment: newTallyCommitment,
|
|
3233
|
+
plonk_proof: plonkProof
|
|
3234
|
+
}
|
|
3235
|
+
},
|
|
3236
|
+
fee,
|
|
3237
|
+
memo,
|
|
3238
|
+
_funds
|
|
3239
|
+
);
|
|
3165
3240
|
};
|
|
3166
3241
|
this.stopTallyingPeriod = async ({
|
|
3167
3242
|
results,
|
|
3168
3243
|
salt
|
|
3169
3244
|
}, fee = "auto", memo, _funds) => {
|
|
3170
|
-
return await this.client.execute(
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3245
|
+
return await this.client.execute(
|
|
3246
|
+
this.sender,
|
|
3247
|
+
this.contractAddress,
|
|
3248
|
+
{
|
|
3249
|
+
stop_tallying_period: {
|
|
3250
|
+
results,
|
|
3251
|
+
salt
|
|
3252
|
+
}
|
|
3253
|
+
},
|
|
3254
|
+
fee,
|
|
3255
|
+
memo,
|
|
3256
|
+
_funds
|
|
3257
|
+
);
|
|
3176
3258
|
};
|
|
3177
3259
|
this.grant = async ({
|
|
3178
3260
|
baseAmount,
|
|
3179
3261
|
grantee
|
|
3180
3262
|
}, fee = "auto", memo, _funds) => {
|
|
3181
|
-
return await this.client.execute(
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3263
|
+
return await this.client.execute(
|
|
3264
|
+
this.sender,
|
|
3265
|
+
this.contractAddress,
|
|
3266
|
+
{
|
|
3267
|
+
grant: {
|
|
3268
|
+
base_amount: baseAmount,
|
|
3269
|
+
grantee
|
|
3270
|
+
}
|
|
3271
|
+
},
|
|
3272
|
+
fee,
|
|
3273
|
+
memo,
|
|
3274
|
+
_funds
|
|
3275
|
+
);
|
|
3187
3276
|
};
|
|
3188
3277
|
this.revoke = async ({
|
|
3189
3278
|
grantee
|
|
3190
3279
|
}, fee = "auto", memo, _funds) => {
|
|
3191
|
-
return await this.client.execute(
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3280
|
+
return await this.client.execute(
|
|
3281
|
+
this.sender,
|
|
3282
|
+
this.contractAddress,
|
|
3283
|
+
{
|
|
3284
|
+
revoke: {
|
|
3285
|
+
grantee
|
|
3286
|
+
}
|
|
3287
|
+
},
|
|
3288
|
+
fee,
|
|
3289
|
+
memo,
|
|
3290
|
+
_funds
|
|
3291
|
+
);
|
|
3196
3292
|
};
|
|
3197
3293
|
this.bond = async (fee = "auto", memo, _funds) => {
|
|
3198
|
-
return await this.client.execute(
|
|
3199
|
-
|
|
3200
|
-
|
|
3294
|
+
return await this.client.execute(
|
|
3295
|
+
this.sender,
|
|
3296
|
+
this.contractAddress,
|
|
3297
|
+
{
|
|
3298
|
+
bond: {}
|
|
3299
|
+
},
|
|
3300
|
+
fee,
|
|
3301
|
+
memo,
|
|
3302
|
+
_funds
|
|
3303
|
+
);
|
|
3201
3304
|
};
|
|
3202
3305
|
this.withdraw = async ({
|
|
3203
3306
|
amount
|
|
3204
3307
|
}, fee = "auto", memo, _funds) => {
|
|
3205
|
-
return await this.client.execute(
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3308
|
+
return await this.client.execute(
|
|
3309
|
+
this.sender,
|
|
3310
|
+
this.contractAddress,
|
|
3311
|
+
{
|
|
3312
|
+
withdraw: {
|
|
3313
|
+
amount
|
|
3314
|
+
}
|
|
3315
|
+
},
|
|
3316
|
+
fee,
|
|
3317
|
+
memo,
|
|
3318
|
+
_funds
|
|
3319
|
+
);
|
|
3210
3320
|
};
|
|
3211
3321
|
this.client = client;
|
|
3212
3322
|
this.sender = sender;
|
|
@@ -3732,6 +3842,13 @@ function getContractParams(type, circuitType, proofSystem, maxVoter, maxOption)
|
|
|
3732
3842
|
// plonkTallyVkey,
|
|
3733
3843
|
};
|
|
3734
3844
|
case "2" /* ORACLE_MACI */:
|
|
3845
|
+
if (circuitType === "0" /* IP1V */) {
|
|
3846
|
+
groth16ProcessVkey = CIRCUIT_INFO["9-4-3-625"]["groth16"].process_1p1v_vkey;
|
|
3847
|
+
groth16TallyVkey = CIRCUIT_INFO["9-4-3-625"]["groth16"].tally_1p1v_vkey;
|
|
3848
|
+
} else if (circuitType === "1" /* QV */) {
|
|
3849
|
+
groth16ProcessVkey = CIRCUIT_INFO["9-4-3-625"]["groth16"].process_qv_vkey;
|
|
3850
|
+
groth16TallyVkey = CIRCUIT_INFO["9-4-3-625"]["groth16"].tally_qv_vkey;
|
|
3851
|
+
}
|
|
3735
3852
|
return {
|
|
3736
3853
|
parameters: CIRCUIT_INFO["9-4-3-625"].parameter,
|
|
3737
3854
|
groth16ProcessVkey,
|
|
@@ -3814,7 +3931,6 @@ var Contract = class {
|
|
|
3814
3931
|
}
|
|
3815
3932
|
}
|
|
3816
3933
|
});
|
|
3817
|
-
console.log(`Deploy tx: ${res.transactionHash} - ${contractAddress}`);
|
|
3818
3934
|
return contractAddress;
|
|
3819
3935
|
}
|
|
3820
3936
|
async createMaciRound({
|
|
@@ -3875,7 +3991,7 @@ var Contract = class {
|
|
|
3875
3991
|
certification_system: maciCertSystem,
|
|
3876
3992
|
qtr_lib: QTR_LIB
|
|
3877
3993
|
},
|
|
3878
|
-
|
|
3994
|
+
`[MACI] ${title}`,
|
|
3879
3995
|
"auto"
|
|
3880
3996
|
);
|
|
3881
3997
|
return instantiateResponse;
|
|
@@ -3943,7 +4059,7 @@ var Contract = class {
|
|
|
3943
4059
|
qtr_lib: QTR_LIB,
|
|
3944
4060
|
feegrant_operator: this.feegrantOperator
|
|
3945
4061
|
},
|
|
3946
|
-
|
|
4062
|
+
`[Oracle MACI] ${title}`,
|
|
3947
4063
|
"auto"
|
|
3948
4064
|
);
|
|
3949
4065
|
return instantiateResponse;
|
|
@@ -4006,6 +4122,32 @@ var Contract = class {
|
|
|
4006
4122
|
}
|
|
4007
4123
|
};
|
|
4008
4124
|
|
|
4125
|
+
// src/libs/oracle-certificate/oracle-certificate.ts
|
|
4126
|
+
var OracleCertificate = class {
|
|
4127
|
+
constructor({ certificateApiEndpoint, http }) {
|
|
4128
|
+
this.certificateApiEndpoint = certificateApiEndpoint;
|
|
4129
|
+
this.http = http;
|
|
4130
|
+
}
|
|
4131
|
+
async sign(data) {
|
|
4132
|
+
const response = await this.http.fetch(
|
|
4133
|
+
`${this.certificateApiEndpoint}/${data.ecosystem}/sign`,
|
|
4134
|
+
{
|
|
4135
|
+
method: "POST",
|
|
4136
|
+
headers: {
|
|
4137
|
+
"Content-Type": "application/json"
|
|
4138
|
+
},
|
|
4139
|
+
body: JSON.stringify({
|
|
4140
|
+
address: data.address,
|
|
4141
|
+
height: data.height,
|
|
4142
|
+
contractAddress: data.contractAddress
|
|
4143
|
+
})
|
|
4144
|
+
}
|
|
4145
|
+
);
|
|
4146
|
+
const signatureData = await response.json();
|
|
4147
|
+
return signatureData;
|
|
4148
|
+
}
|
|
4149
|
+
};
|
|
4150
|
+
|
|
4009
4151
|
// src/libs/circom/index.ts
|
|
4010
4152
|
var import_proto_signing = require("@cosmjs/proto-signing");
|
|
4011
4153
|
|
|
@@ -4261,6 +4403,413 @@ var Circom = class {
|
|
|
4261
4403
|
}
|
|
4262
4404
|
};
|
|
4263
4405
|
|
|
4406
|
+
// src/libs/maci/maci.ts
|
|
4407
|
+
var import_stargate2 = require("@cosmjs/stargate");
|
|
4408
|
+
var import_tx = require("cosmjs-types/cosmwasm/wasm/v1/tx");
|
|
4409
|
+
function isErrorResponse(response) {
|
|
4410
|
+
return typeof response === "object" && response !== null && "error" in response && typeof response.error === "object" && "message" in response.error;
|
|
4411
|
+
}
|
|
4412
|
+
var MACI = class {
|
|
4413
|
+
constructor({
|
|
4414
|
+
circom,
|
|
4415
|
+
contract,
|
|
4416
|
+
indexer,
|
|
4417
|
+
oracleCertificate
|
|
4418
|
+
}) {
|
|
4419
|
+
this.circom = circom;
|
|
4420
|
+
this.contract = contract;
|
|
4421
|
+
this.indexer = indexer;
|
|
4422
|
+
this.oracleCertificate = oracleCertificate;
|
|
4423
|
+
}
|
|
4424
|
+
async getStateIdxInc({
|
|
4425
|
+
signer,
|
|
4426
|
+
address,
|
|
4427
|
+
contractAddress
|
|
4428
|
+
}) {
|
|
4429
|
+
const client = await this.contract.maciClient({
|
|
4430
|
+
signer,
|
|
4431
|
+
contractAddress
|
|
4432
|
+
});
|
|
4433
|
+
const stateIdx = await client.getStateIdxInc({ address });
|
|
4434
|
+
return stateIdx;
|
|
4435
|
+
}
|
|
4436
|
+
async getVoiceCreditBalance({
|
|
4437
|
+
signer,
|
|
4438
|
+
stateIdx,
|
|
4439
|
+
contractAddress
|
|
4440
|
+
}) {
|
|
4441
|
+
const client = await this.contract.maciClient({
|
|
4442
|
+
signer,
|
|
4443
|
+
contractAddress
|
|
4444
|
+
});
|
|
4445
|
+
const voiceCredit = await client.getVoiceCreditBalance({
|
|
4446
|
+
index: stateIdx.toString()
|
|
4447
|
+
});
|
|
4448
|
+
return voiceCredit;
|
|
4449
|
+
}
|
|
4450
|
+
async getStateIdxByPubKey({
|
|
4451
|
+
contractAddress,
|
|
4452
|
+
pubKey
|
|
4453
|
+
}) {
|
|
4454
|
+
const response = await this.indexer.getSignUpEventByPubKey(
|
|
4455
|
+
contractAddress,
|
|
4456
|
+
pubKey
|
|
4457
|
+
);
|
|
4458
|
+
if (isErrorResponse(response)) {
|
|
4459
|
+
return -1;
|
|
4460
|
+
}
|
|
4461
|
+
return response.data.signUpEvents[0].stateIdx;
|
|
4462
|
+
}
|
|
4463
|
+
// only for maci and oracle maci, amaci will set the voice credit when deploy the contract
|
|
4464
|
+
async queryWhitelistBalanceOf({
|
|
4465
|
+
signer,
|
|
4466
|
+
address,
|
|
4467
|
+
contractAddress,
|
|
4468
|
+
certificate,
|
|
4469
|
+
mode = "maci"
|
|
4470
|
+
}) {
|
|
4471
|
+
if (mode === "amaci") {
|
|
4472
|
+
const isWhiteListed = await this.isWhitelisted({
|
|
4473
|
+
signer,
|
|
4474
|
+
address,
|
|
4475
|
+
contractAddress
|
|
4476
|
+
});
|
|
4477
|
+
if (isWhiteListed) {
|
|
4478
|
+
const round = await this.indexer.getRoundById(contractAddress);
|
|
4479
|
+
if (!isErrorResponse(round)) {
|
|
4480
|
+
return round.data.round.voiceCreditAmount;
|
|
4481
|
+
} else {
|
|
4482
|
+
throw new Error(
|
|
4483
|
+
`Failed to query amaci voice credit: ${round.error.type}`
|
|
4484
|
+
);
|
|
4485
|
+
}
|
|
4486
|
+
} else {
|
|
4487
|
+
return "0";
|
|
4488
|
+
}
|
|
4489
|
+
}
|
|
4490
|
+
if (certificate) {
|
|
4491
|
+
const client = await this.contract.oracleMaciClient({
|
|
4492
|
+
signer,
|
|
4493
|
+
contractAddress
|
|
4494
|
+
});
|
|
4495
|
+
const balance = await client.whiteBalanceOf({
|
|
4496
|
+
amount: address,
|
|
4497
|
+
certificate,
|
|
4498
|
+
sender: address
|
|
4499
|
+
});
|
|
4500
|
+
return balance;
|
|
4501
|
+
} else {
|
|
4502
|
+
const client = await this.contract.maciClient({
|
|
4503
|
+
signer,
|
|
4504
|
+
contractAddress
|
|
4505
|
+
});
|
|
4506
|
+
const balance = await client.whiteBalanceOf({
|
|
4507
|
+
sender: address
|
|
4508
|
+
});
|
|
4509
|
+
return balance;
|
|
4510
|
+
}
|
|
4511
|
+
}
|
|
4512
|
+
async isWhitelisted({
|
|
4513
|
+
signer,
|
|
4514
|
+
address,
|
|
4515
|
+
contractAddress
|
|
4516
|
+
}) {
|
|
4517
|
+
const client = await this.contract.amaciClient({
|
|
4518
|
+
signer,
|
|
4519
|
+
contractAddress
|
|
4520
|
+
});
|
|
4521
|
+
const isWhitelisted = await client.isWhiteList({
|
|
4522
|
+
sender: address
|
|
4523
|
+
});
|
|
4524
|
+
return isWhitelisted;
|
|
4525
|
+
}
|
|
4526
|
+
async getOracleWhitelistConfig({
|
|
4527
|
+
signer,
|
|
4528
|
+
contractAddress
|
|
4529
|
+
}) {
|
|
4530
|
+
const client = await this.contract.oracleMaciClient({
|
|
4531
|
+
signer,
|
|
4532
|
+
contractAddress
|
|
4533
|
+
});
|
|
4534
|
+
const snapshotHeight = await client.queryOracleWhitelistConfig();
|
|
4535
|
+
return snapshotHeight;
|
|
4536
|
+
}
|
|
4537
|
+
async getRoundInfo({ contractAddress }) {
|
|
4538
|
+
const roundInfo = await this.indexer.getRoundById(contractAddress);
|
|
4539
|
+
if (isErrorResponse(roundInfo)) {
|
|
4540
|
+
throw new Error(`Failed to get round info: ${roundInfo.error.type}`);
|
|
4541
|
+
}
|
|
4542
|
+
return roundInfo.data.round;
|
|
4543
|
+
}
|
|
4544
|
+
async getRoundCircuitType({ contractAddress }) {
|
|
4545
|
+
const roundInfo = await this.getRoundInfo({ contractAddress });
|
|
4546
|
+
return roundInfo.circuitType;
|
|
4547
|
+
}
|
|
4548
|
+
async queryRoundIsQv({ contractAddress }) {
|
|
4549
|
+
const circuitType = await this.getRoundCircuitType({ contractAddress });
|
|
4550
|
+
return circuitType === "1";
|
|
4551
|
+
}
|
|
4552
|
+
async queryRoundGasStation({ contractAddress }) {
|
|
4553
|
+
const roundInfo = await this.getRoundInfo({ contractAddress });
|
|
4554
|
+
return roundInfo.gasStationEnable;
|
|
4555
|
+
}
|
|
4556
|
+
async requestOracleCertificate({
|
|
4557
|
+
signer,
|
|
4558
|
+
ecosystem,
|
|
4559
|
+
address,
|
|
4560
|
+
contractAddress
|
|
4561
|
+
}) {
|
|
4562
|
+
const oracleWhitelistConfig = await this.getOracleWhitelistConfig({
|
|
4563
|
+
signer,
|
|
4564
|
+
contractAddress
|
|
4565
|
+
});
|
|
4566
|
+
const signResponse = await this.oracleCertificate.sign({
|
|
4567
|
+
ecosystem,
|
|
4568
|
+
address,
|
|
4569
|
+
contractAddress,
|
|
4570
|
+
height: oracleWhitelistConfig.snapshot_height
|
|
4571
|
+
});
|
|
4572
|
+
return signResponse;
|
|
4573
|
+
}
|
|
4574
|
+
async signup({
|
|
4575
|
+
signer,
|
|
4576
|
+
address,
|
|
4577
|
+
contractAddress,
|
|
4578
|
+
oracleCertificate,
|
|
4579
|
+
gasStation = false
|
|
4580
|
+
}) {
|
|
4581
|
+
try {
|
|
4582
|
+
const maciAccount = await this.circom.genKeypairFromSign(signer, address);
|
|
4583
|
+
const client = await this.contract.contractClient({
|
|
4584
|
+
signer
|
|
4585
|
+
});
|
|
4586
|
+
if (oracleCertificate) {
|
|
4587
|
+
return await this.signupOracle({
|
|
4588
|
+
client,
|
|
4589
|
+
address,
|
|
4590
|
+
pubKey: maciAccount.pubKey,
|
|
4591
|
+
contractAddress,
|
|
4592
|
+
oracleCertificate,
|
|
4593
|
+
gasStation
|
|
4594
|
+
});
|
|
4595
|
+
} else {
|
|
4596
|
+
return await this.signupSimple({
|
|
4597
|
+
client,
|
|
4598
|
+
address,
|
|
4599
|
+
pubKey: maciAccount.pubKey,
|
|
4600
|
+
contractAddress,
|
|
4601
|
+
gasStation
|
|
4602
|
+
});
|
|
4603
|
+
}
|
|
4604
|
+
} catch (error) {
|
|
4605
|
+
throw Error(`Signup failed! ${error}`);
|
|
4606
|
+
}
|
|
4607
|
+
}
|
|
4608
|
+
async processVoteOptions({
|
|
4609
|
+
selectedOptions,
|
|
4610
|
+
contractAddress,
|
|
4611
|
+
voiceCreditBalance
|
|
4612
|
+
}) {
|
|
4613
|
+
const idxSet = /* @__PURE__ */ new Set();
|
|
4614
|
+
for (const option of selectedOptions) {
|
|
4615
|
+
if (idxSet.has(option.idx)) {
|
|
4616
|
+
throw new Error(
|
|
4617
|
+
`Duplicate option index (${option.idx}) is not allowed`
|
|
4618
|
+
);
|
|
4619
|
+
}
|
|
4620
|
+
idxSet.add(option.idx);
|
|
4621
|
+
}
|
|
4622
|
+
const options = selectedOptions.filter((o) => !!o.vc).sort((a, b) => a.idx - b.idx);
|
|
4623
|
+
const isQv = await this.queryRoundIsQv({ contractAddress });
|
|
4624
|
+
const usedVc = options.reduce((s, o) => s + (isQv ? o.vc * o.vc : o.vc), 0);
|
|
4625
|
+
if (Number(voiceCreditBalance) < usedVc) {
|
|
4626
|
+
throw new Error("Insufficient voice credit balance");
|
|
4627
|
+
}
|
|
4628
|
+
return options;
|
|
4629
|
+
}
|
|
4630
|
+
async vote({
|
|
4631
|
+
signer,
|
|
4632
|
+
address,
|
|
4633
|
+
stateIdx,
|
|
4634
|
+
contractAddress,
|
|
4635
|
+
selectedOptions,
|
|
4636
|
+
operatorCoordPubKey,
|
|
4637
|
+
gasStation = false
|
|
4638
|
+
}) {
|
|
4639
|
+
if (stateIdx === -1) {
|
|
4640
|
+
throw new Error("State index is not set, Please signup first");
|
|
4641
|
+
}
|
|
4642
|
+
try {
|
|
4643
|
+
const voiceCreditBalance = await this.getVoiceCreditBalance({
|
|
4644
|
+
signer,
|
|
4645
|
+
stateIdx,
|
|
4646
|
+
contractAddress
|
|
4647
|
+
});
|
|
4648
|
+
const options = await this.processVoteOptions({
|
|
4649
|
+
selectedOptions,
|
|
4650
|
+
contractAddress,
|
|
4651
|
+
voiceCreditBalance
|
|
4652
|
+
});
|
|
4653
|
+
const maciAccount = await this.circom.genKeypairFromSign(signer, address);
|
|
4654
|
+
const plan = options.map((o) => {
|
|
4655
|
+
return [o.idx, o.vc];
|
|
4656
|
+
});
|
|
4657
|
+
const payload = batchGenMessage(
|
|
4658
|
+
stateIdx,
|
|
4659
|
+
maciAccount,
|
|
4660
|
+
operatorCoordPubKey,
|
|
4661
|
+
plan
|
|
4662
|
+
);
|
|
4663
|
+
const client = await this.contract.contractClient({
|
|
4664
|
+
signer
|
|
4665
|
+
});
|
|
4666
|
+
return await this.publishMessage({
|
|
4667
|
+
client,
|
|
4668
|
+
address,
|
|
4669
|
+
payload,
|
|
4670
|
+
contractAddress,
|
|
4671
|
+
gasStation
|
|
4672
|
+
});
|
|
4673
|
+
} catch (error) {
|
|
4674
|
+
throw Error(`Vote failed! ${error}`);
|
|
4675
|
+
}
|
|
4676
|
+
}
|
|
4677
|
+
async publishMessage({
|
|
4678
|
+
client,
|
|
4679
|
+
address,
|
|
4680
|
+
payload,
|
|
4681
|
+
contractAddress,
|
|
4682
|
+
gasStation
|
|
4683
|
+
}) {
|
|
4684
|
+
const msgs = payload.map(
|
|
4685
|
+
({ msg, encPubkeys }) => ({
|
|
4686
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
4687
|
+
value: import_tx.MsgExecuteContract.fromPartial({
|
|
4688
|
+
sender: address,
|
|
4689
|
+
contract: contractAddress,
|
|
4690
|
+
msg: new TextEncoder().encode(
|
|
4691
|
+
JSON.stringify(
|
|
4692
|
+
stringizing({
|
|
4693
|
+
publish_message: {
|
|
4694
|
+
enc_pub_key: {
|
|
4695
|
+
x: encPubkeys[0],
|
|
4696
|
+
y: encPubkeys[1]
|
|
4697
|
+
},
|
|
4698
|
+
message: {
|
|
4699
|
+
data: msg
|
|
4700
|
+
}
|
|
4701
|
+
}
|
|
4702
|
+
})
|
|
4703
|
+
)
|
|
4704
|
+
)
|
|
4705
|
+
})
|
|
4706
|
+
})
|
|
4707
|
+
);
|
|
4708
|
+
const gasPrice = import_stargate2.GasPrice.fromString("100000000000peaka");
|
|
4709
|
+
const fee = (0, import_stargate2.calculateFee)(2e7 * msgs.length, gasPrice);
|
|
4710
|
+
if (gasStation) {
|
|
4711
|
+
const grantFee = {
|
|
4712
|
+
amount: fee.amount,
|
|
4713
|
+
gas: fee.gas,
|
|
4714
|
+
granter: contractAddress
|
|
4715
|
+
};
|
|
4716
|
+
return client.signAndBroadcast(address, msgs, grantFee);
|
|
4717
|
+
}
|
|
4718
|
+
return client.signAndBroadcast(address, msgs, fee);
|
|
4719
|
+
}
|
|
4720
|
+
async signupSimple({
|
|
4721
|
+
client,
|
|
4722
|
+
address,
|
|
4723
|
+
pubKey,
|
|
4724
|
+
contractAddress,
|
|
4725
|
+
gasStation
|
|
4726
|
+
}) {
|
|
4727
|
+
const gasPrice = import_stargate2.GasPrice.fromString("100000000000peaka");
|
|
4728
|
+
const fee = (0, import_stargate2.calculateFee)(6e7, gasPrice);
|
|
4729
|
+
if (gasStation === true) {
|
|
4730
|
+
const grantFee = {
|
|
4731
|
+
amount: fee.amount,
|
|
4732
|
+
gas: fee.gas,
|
|
4733
|
+
granter: contractAddress
|
|
4734
|
+
};
|
|
4735
|
+
return client.execute(
|
|
4736
|
+
address,
|
|
4737
|
+
contractAddress,
|
|
4738
|
+
{
|
|
4739
|
+
sign_up: {
|
|
4740
|
+
pubkey: {
|
|
4741
|
+
x: pubKey[0].toString(),
|
|
4742
|
+
y: pubKey[1].toString()
|
|
4743
|
+
}
|
|
4744
|
+
}
|
|
4745
|
+
},
|
|
4746
|
+
grantFee
|
|
4747
|
+
);
|
|
4748
|
+
}
|
|
4749
|
+
return client.execute(
|
|
4750
|
+
address,
|
|
4751
|
+
contractAddress,
|
|
4752
|
+
{
|
|
4753
|
+
sign_up: {
|
|
4754
|
+
pubkey: {
|
|
4755
|
+
x: pubKey[0].toString(),
|
|
4756
|
+
y: pubKey[1].toString()
|
|
4757
|
+
}
|
|
4758
|
+
}
|
|
4759
|
+
},
|
|
4760
|
+
fee
|
|
4761
|
+
);
|
|
4762
|
+
}
|
|
4763
|
+
async signupOracle({
|
|
4764
|
+
client,
|
|
4765
|
+
address,
|
|
4766
|
+
pubKey,
|
|
4767
|
+
contractAddress,
|
|
4768
|
+
oracleCertificate,
|
|
4769
|
+
gasStation
|
|
4770
|
+
}) {
|
|
4771
|
+
const gasPrice = import_stargate2.GasPrice.fromString("100000000000peaka");
|
|
4772
|
+
const fee = (0, import_stargate2.calculateFee)(6e7, gasPrice);
|
|
4773
|
+
if (gasStation === true) {
|
|
4774
|
+
const grantFee = {
|
|
4775
|
+
amount: fee.amount,
|
|
4776
|
+
gas: fee.gas,
|
|
4777
|
+
granter: contractAddress
|
|
4778
|
+
};
|
|
4779
|
+
return client.execute(
|
|
4780
|
+
address,
|
|
4781
|
+
contractAddress,
|
|
4782
|
+
{
|
|
4783
|
+
sign_up: {
|
|
4784
|
+
pubkey: {
|
|
4785
|
+
x: pubKey[0].toString(),
|
|
4786
|
+
y: pubKey[1].toString()
|
|
4787
|
+
},
|
|
4788
|
+
amount: oracleCertificate.amount,
|
|
4789
|
+
certificate: oracleCertificate.signature
|
|
4790
|
+
}
|
|
4791
|
+
},
|
|
4792
|
+
grantFee
|
|
4793
|
+
);
|
|
4794
|
+
}
|
|
4795
|
+
return client.execute(
|
|
4796
|
+
address,
|
|
4797
|
+
contractAddress,
|
|
4798
|
+
{
|
|
4799
|
+
sign_up: {
|
|
4800
|
+
pubkey: {
|
|
4801
|
+
x: pubKey[0].toString(),
|
|
4802
|
+
y: pubKey[1].toString()
|
|
4803
|
+
},
|
|
4804
|
+
amount: oracleCertificate.amount,
|
|
4805
|
+
certificate: oracleCertificate.signature
|
|
4806
|
+
}
|
|
4807
|
+
},
|
|
4808
|
+
fee
|
|
4809
|
+
);
|
|
4810
|
+
}
|
|
4811
|
+
};
|
|
4812
|
+
|
|
4264
4813
|
// src/maci.ts
|
|
4265
4814
|
var MaciClient2 = class {
|
|
4266
4815
|
/**
|
|
@@ -4278,12 +4827,14 @@ var MaciClient2 = class {
|
|
|
4278
4827
|
customFetch,
|
|
4279
4828
|
defaultOptions,
|
|
4280
4829
|
feegrantOperator,
|
|
4281
|
-
whitelistBackendPubkey
|
|
4830
|
+
whitelistBackendPubkey,
|
|
4831
|
+
certificateApiEndpoint
|
|
4282
4832
|
}) {
|
|
4283
4833
|
const defaultParams = getDefaultParams(network);
|
|
4284
4834
|
this.rpcEndpoint = rpcEndpoint || defaultParams.rpcEndpoint;
|
|
4285
4835
|
this.restEndpoint = restEndpoint || defaultParams.restEndpoint;
|
|
4286
4836
|
this.apiEndpoint = apiEndpoint || defaultParams.apiEndpoint;
|
|
4837
|
+
this.certificateApiEndpoint = certificateApiEndpoint || defaultParams.certificateApiEndpoint;
|
|
4287
4838
|
this.registryAddress = registryAddress || defaultParams.registryAddress;
|
|
4288
4839
|
this.maciCodeId = maciCodeId || defaultParams.maciCodeId;
|
|
4289
4840
|
this.oracleCodeId = oracleCodeId || defaultParams.oracleCodeId;
|
|
@@ -4310,6 +4861,16 @@ var MaciClient2 = class {
|
|
|
4310
4861
|
whitelistBackendPubkey: this.whitelistBackendPubkey
|
|
4311
4862
|
});
|
|
4312
4863
|
this.circom = new Circom({ network });
|
|
4864
|
+
this.oracleCertificate = new OracleCertificate({
|
|
4865
|
+
certificateApiEndpoint: this.certificateApiEndpoint,
|
|
4866
|
+
http: this.http
|
|
4867
|
+
});
|
|
4868
|
+
this.maci = new MACI({
|
|
4869
|
+
circom: this.circom,
|
|
4870
|
+
contract: this.contract,
|
|
4871
|
+
indexer: this.indexer,
|
|
4872
|
+
oracleCertificate: this.oracleCertificate
|
|
4873
|
+
});
|
|
4313
4874
|
}
|
|
4314
4875
|
async oracleMaciClient({
|
|
4315
4876
|
signer,
|
|
@@ -4497,13 +5058,16 @@ var import_blake_hash2 = __toESM(require("blake-hash"));
|
|
|
4497
5058
|
Circom,
|
|
4498
5059
|
Circuit,
|
|
4499
5060
|
Contract,
|
|
5061
|
+
Event,
|
|
4500
5062
|
Http,
|
|
4501
5063
|
Indexer,
|
|
5064
|
+
MACI,
|
|
4502
5065
|
MaciCertSystemType,
|
|
4503
5066
|
MaciCircuitType,
|
|
4504
5067
|
MaciClient,
|
|
4505
5068
|
MaciRoundType,
|
|
4506
5069
|
Operator,
|
|
5070
|
+
OracleCertificate,
|
|
4507
5071
|
Proof,
|
|
4508
5072
|
Round,
|
|
4509
5073
|
Scalar,
|