@maci-protocol/sdk 0.0.0-ci.01622be
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/CHANGELOG.md +80 -0
- package/LICENSE +21 -0
- package/README.md +12 -0
- package/build/package.json +65 -0
- package/build/ts/browser/index.d.ts +13 -0
- package/build/ts/browser/index.d.ts.map +1 -0
- package/build/ts/browser/index.js +38 -0
- package/build/ts/browser/index.js.map +1 -0
- package/build/ts/browser/joinPoll.d.ts +10 -0
- package/build/ts/browser/joinPoll.d.ts.map +1 -0
- package/build/ts/browser/joinPoll.js +88 -0
- package/build/ts/browser/joinPoll.js.map +1 -0
- package/build/ts/browser/utils.d.ts +18 -0
- package/build/ts/browser/utils.d.ts.map +1 -0
- package/build/ts/browser/utils.js +37 -0
- package/build/ts/browser/utils.js.map +1 -0
- package/build/ts/deploy/index.d.ts +6 -0
- package/build/ts/deploy/index.d.ts.map +1 -0
- package/build/ts/deploy/index.js +12 -0
- package/build/ts/deploy/index.js.map +1 -0
- package/build/ts/deploy/maci.d.ts +8 -0
- package/build/ts/deploy/maci.d.ts.map +1 -0
- package/build/ts/deploy/maci.js +87 -0
- package/build/ts/deploy/maci.js.map +1 -0
- package/build/ts/deploy/poll.d.ts +8 -0
- package/build/ts/deploy/poll.d.ts.map +1 -0
- package/build/ts/deploy/poll.js +114 -0
- package/build/ts/deploy/poll.js.map +1 -0
- package/build/ts/deploy/types.d.ts +217 -0
- package/build/ts/deploy/types.d.ts.map +1 -0
- package/build/ts/deploy/types.js +3 -0
- package/build/ts/deploy/types.js.map +1 -0
- package/build/ts/deploy/utils.d.ts +11 -0
- package/build/ts/deploy/utils.d.ts.map +1 -0
- package/build/ts/deploy/utils.js +22 -0
- package/build/ts/deploy/utils.js.map +1 -0
- package/build/ts/deploy/verifyingKeysRegistry.d.ts +7 -0
- package/build/ts/deploy/verifyingKeysRegistry.d.ts.map +1 -0
- package/build/ts/deploy/verifyingKeysRegistry.js +14 -0
- package/build/ts/deploy/verifyingKeysRegistry.js.map +1 -0
- package/build/ts/index.d.ts +16 -0
- package/build/ts/index.d.ts.map +1 -0
- package/build/ts/index.js +86 -0
- package/build/ts/index.js.map +1 -0
- package/build/ts/maci/index.d.ts +6 -0
- package/build/ts/maci/index.d.ts.map +1 -0
- package/build/ts/maci/index.js +17 -0
- package/build/ts/maci/index.js.map +1 -0
- package/build/ts/maci/merge.d.ts +9 -0
- package/build/ts/maci/merge.d.ts.map +1 -0
- package/build/ts/maci/merge.js +29 -0
- package/build/ts/maci/merge.js.map +1 -0
- package/build/ts/maci/policy.d.ts +53 -0
- package/build/ts/maci/policy.d.ts.map +1 -0
- package/build/ts/maci/policy.js +166 -0
- package/build/ts/maci/policy.js.map +1 -0
- package/build/ts/maci/state.d.ts +8 -0
- package/build/ts/maci/state.d.ts.map +1 -0
- package/build/ts/maci/state.js +82 -0
- package/build/ts/maci/state.js.map +1 -0
- package/build/ts/maci/types.d.ts +208 -0
- package/build/ts/maci/types.d.ts.map +1 -0
- package/build/ts/maci/types.js +20 -0
- package/build/ts/maci/types.js.map +1 -0
- package/build/ts/maciKeys/__tests__/keypair.test.d.ts +2 -0
- package/build/ts/maciKeys/__tests__/keypair.test.d.ts.map +1 -0
- package/build/ts/maciKeys/__tests__/keypair.test.js +24 -0
- package/build/ts/maciKeys/__tests__/keypair.test.js.map +1 -0
- package/build/ts/maciKeys/__tests__/publicKeys.test.d.ts +2 -0
- package/build/ts/maciKeys/__tests__/publicKeys.test.d.ts.map +1 -0
- package/build/ts/maciKeys/__tests__/publicKeys.test.js +22 -0
- package/build/ts/maciKeys/__tests__/publicKeys.test.js.map +1 -0
- package/build/ts/maciKeys/index.d.ts +4 -0
- package/build/ts/maciKeys/index.d.ts.map +1 -0
- package/build/ts/maciKeys/index.js +8 -0
- package/build/ts/maciKeys/index.js.map +1 -0
- package/build/ts/maciKeys/keypair.d.ts +9 -0
- package/build/ts/maciKeys/keypair.d.ts.map +1 -0
- package/build/ts/maciKeys/keypair.js +20 -0
- package/build/ts/maciKeys/keypair.js.map +1 -0
- package/build/ts/maciKeys/publicKeys.d.ts +8 -0
- package/build/ts/maciKeys/publicKeys.d.ts.map +1 -0
- package/build/ts/maciKeys/publicKeys.js +23 -0
- package/build/ts/maciKeys/publicKeys.js.map +1 -0
- package/build/ts/maciKeys/types.d.ts +23 -0
- package/build/ts/maciKeys/types.d.ts.map +1 -0
- package/build/ts/maciKeys/types.js +3 -0
- package/build/ts/maciKeys/types.js.map +1 -0
- package/build/ts/poll/index.d.ts +4 -0
- package/build/ts/poll/index.d.ts.map +1 -0
- package/build/ts/poll/index.js +9 -0
- package/build/ts/poll/index.js.map +1 -0
- package/build/ts/poll/poll.d.ts +14 -0
- package/build/ts/poll/poll.d.ts.map +1 -0
- package/build/ts/poll/poll.js +62 -0
- package/build/ts/poll/poll.js.map +1 -0
- package/build/ts/poll/types.d.ts +151 -0
- package/build/ts/poll/types.d.ts.map +1 -0
- package/build/ts/poll/types.js +3 -0
- package/build/ts/poll/types.js.map +1 -0
- package/build/ts/poll/utils.d.ts +9 -0
- package/build/ts/poll/utils.d.ts.map +1 -0
- package/build/ts/poll/utils.js +43 -0
- package/build/ts/poll/utils.js.map +1 -0
- package/build/ts/proof/__tests__/download.test.d.ts +2 -0
- package/build/ts/proof/__tests__/download.test.d.ts.map +1 -0
- package/build/ts/proof/__tests__/download.test.js +53 -0
- package/build/ts/proof/__tests__/download.test.js.map +1 -0
- package/build/ts/proof/download.d.ts +9 -0
- package/build/ts/proof/download.d.ts.map +1 -0
- package/build/ts/proof/download.js +47 -0
- package/build/ts/proof/download.js.map +1 -0
- package/build/ts/proof/generate.d.ts +8 -0
- package/build/ts/proof/generate.d.ts.map +1 -0
- package/build/ts/proof/generate.js +127 -0
- package/build/ts/proof/generate.js.map +1 -0
- package/build/ts/proof/index.d.ts +4 -0
- package/build/ts/proof/index.d.ts.map +1 -0
- package/build/ts/proof/index.js +8 -0
- package/build/ts/proof/index.js.map +1 -0
- package/build/ts/proof/prove.d.ts +8 -0
- package/build/ts/proof/prove.d.ts.map +1 -0
- package/build/ts/proof/prove.js +81 -0
- package/build/ts/proof/prove.js.map +1 -0
- package/build/ts/proof/types.d.ts +201 -0
- package/build/ts/proof/types.d.ts.map +1 -0
- package/build/ts/proof/types.js +3 -0
- package/build/ts/proof/types.js.map +1 -0
- package/build/ts/proof/utils.d.ts +10 -0
- package/build/ts/proof/utils.d.ts.map +1 -0
- package/build/ts/proof/utils.js +24 -0
- package/build/ts/proof/utils.js.map +1 -0
- package/build/ts/relayer/__tests__/messages.test.d.ts +2 -0
- package/build/ts/relayer/__tests__/messages.test.d.ts.map +1 -0
- package/build/ts/relayer/__tests__/messages.test.js +76 -0
- package/build/ts/relayer/__tests__/messages.test.js.map +1 -0
- package/build/ts/relayer/__tests__/utils.test.d.ts +2 -0
- package/build/ts/relayer/__tests__/utils.test.d.ts.map +1 -0
- package/build/ts/relayer/__tests__/utils.test.js +73 -0
- package/build/ts/relayer/__tests__/utils.test.js.map +1 -0
- package/build/ts/relayer/index.d.ts +3 -0
- package/build/ts/relayer/index.d.ts.map +1 -0
- package/build/ts/relayer/index.js +8 -0
- package/build/ts/relayer/index.js.map +1 -0
- package/build/ts/relayer/messages.d.ts +23 -0
- package/build/ts/relayer/messages.d.ts.map +1 -0
- package/build/ts/relayer/messages.js +66 -0
- package/build/ts/relayer/messages.js.map +1 -0
- package/build/ts/relayer/types.d.ts +168 -0
- package/build/ts/relayer/types.d.ts.map +1 -0
- package/build/ts/relayer/types.js +3 -0
- package/build/ts/relayer/types.js.map +1 -0
- package/build/ts/relayer/utils.d.ts +12 -0
- package/build/ts/relayer/utils.d.ts.map +1 -0
- package/build/ts/relayer/utils.js +37 -0
- package/build/ts/relayer/utils.js.map +1 -0
- package/build/ts/tally/commitments.d.ts +9 -0
- package/build/ts/tally/commitments.d.ts.map +1 -0
- package/build/ts/tally/commitments.js +43 -0
- package/build/ts/tally/commitments.js.map +1 -0
- package/build/ts/tally/index.d.ts +5 -0
- package/build/ts/tally/index.d.ts.map +1 -0
- package/build/ts/tally/index.js +11 -0
- package/build/ts/tally/index.js.map +1 -0
- package/build/ts/tally/results.d.ts +14 -0
- package/build/ts/tally/results.d.ts.map +1 -0
- package/build/ts/tally/results.js +44 -0
- package/build/ts/tally/results.js.map +1 -0
- package/build/ts/tally/types.d.ts +206 -0
- package/build/ts/tally/types.d.ts.map +1 -0
- package/build/ts/tally/types.js +3 -0
- package/build/ts/tally/types.js.map +1 -0
- package/build/ts/tally/utils.d.ts +24 -0
- package/build/ts/tally/utils.d.ts.map +1 -0
- package/build/ts/tally/utils.js +50 -0
- package/build/ts/tally/utils.js.map +1 -0
- package/build/ts/tally/verification.d.ts +7 -0
- package/build/ts/tally/verification.d.ts.map +1 -0
- package/build/ts/tally/verification.js +62 -0
- package/build/ts/tally/verification.js.map +1 -0
- package/build/ts/trees/index.d.ts +3 -0
- package/build/ts/trees/index.d.ts.map +1 -0
- package/build/ts/trees/index.js +7 -0
- package/build/ts/trees/index.js.map +1 -0
- package/build/ts/trees/stateTree.d.ts +27 -0
- package/build/ts/trees/stateTree.d.ts.map +1 -0
- package/build/ts/trees/stateTree.js +104 -0
- package/build/ts/trees/stateTree.js.map +1 -0
- package/build/ts/trees/types.d.ts +55 -0
- package/build/ts/trees/types.d.ts.map +1 -0
- package/build/ts/trees/types.js +3 -0
- package/build/ts/trees/types.js.map +1 -0
- package/build/ts/user/index.d.ts +5 -0
- package/build/ts/user/index.d.ts.map +1 -0
- package/build/ts/user/index.js +17 -0
- package/build/ts/user/index.js.map +1 -0
- package/build/ts/user/joinPoll.d.ts +8 -0
- package/build/ts/user/joinPoll.d.ts.map +1 -0
- package/build/ts/user/joinPoll.js +84 -0
- package/build/ts/user/joinPoll.js.map +1 -0
- package/build/ts/user/signup.d.ts +20 -0
- package/build/ts/user/signup.d.ts.map +1 -0
- package/build/ts/user/signup.js +79 -0
- package/build/ts/user/signup.js.map +1 -0
- package/build/ts/user/types.d.ts +464 -0
- package/build/ts/user/types.d.ts.map +1 -0
- package/build/ts/user/types.js +3 -0
- package/build/ts/user/types.js.map +1 -0
- package/build/ts/user/utils.d.ts +80 -0
- package/build/ts/user/utils.d.ts.map +1 -0
- package/build/ts/user/utils.js +253 -0
- package/build/ts/user/utils.js.map +1 -0
- package/build/ts/utils/cid.d.ts +23 -0
- package/build/ts/utils/cid.d.ts.map +1 -0
- package/build/ts/utils/cid.js +72 -0
- package/build/ts/utils/cid.js.map +1 -0
- package/build/ts/utils/constants.d.ts +2 -0
- package/build/ts/utils/constants.d.ts.map +1 -0
- package/build/ts/utils/constants.js +5 -0
- package/build/ts/utils/constants.js.map +1 -0
- package/build/ts/utils/contracts.d.ts +15 -0
- package/build/ts/utils/contracts.d.ts.map +1 -0
- package/build/ts/utils/contracts.js +26 -0
- package/build/ts/utils/contracts.js.map +1 -0
- package/build/ts/utils/files.d.ts +9 -0
- package/build/ts/utils/files.d.ts.map +1 -0
- package/build/ts/utils/files.js +20 -0
- package/build/ts/utils/files.js.map +1 -0
- package/build/ts/utils/formatting.d.ts +8 -0
- package/build/ts/utils/formatting.d.ts.map +1 -0
- package/build/ts/utils/formatting.js +11 -0
- package/build/ts/utils/formatting.js.map +1 -0
- package/build/ts/utils/fundWallet.d.ts +7 -0
- package/build/ts/utils/fundWallet.d.ts.map +1 -0
- package/build/ts/utils/fundWallet.js +20 -0
- package/build/ts/utils/fundWallet.js.map +1 -0
- package/build/ts/utils/index.d.ts +12 -0
- package/build/ts/utils/index.d.ts.map +1 -0
- package/build/ts/utils/index.js +28 -0
- package/build/ts/utils/index.js.map +1 -0
- package/build/ts/utils/params.d.ts +7 -0
- package/build/ts/utils/params.d.ts.map +1 -0
- package/build/ts/utils/params.js +19 -0
- package/build/ts/utils/params.js.map +1 -0
- package/build/ts/utils/proofs.d.ts +13 -0
- package/build/ts/utils/proofs.d.ts.map +1 -0
- package/build/ts/utils/proofs.js +41 -0
- package/build/ts/utils/proofs.js.map +1 -0
- package/build/ts/utils/timeTravel.d.ts +7 -0
- package/build/ts/utils/timeTravel.d.ts.map +1 -0
- package/build/ts/utils/timeTravel.js +14 -0
- package/build/ts/utils/timeTravel.js.map +1 -0
- package/build/ts/utils/trees.d.ts +13 -0
- package/build/ts/utils/trees.d.ts.map +1 -0
- package/build/ts/utils/trees.js +30 -0
- package/build/ts/utils/trees.js.map +1 -0
- package/build/ts/utils/types.d.ts +71 -0
- package/build/ts/utils/types.d.ts.map +1 -0
- package/build/ts/utils/types.js +3 -0
- package/build/ts/utils/types.js.map +1 -0
- package/build/ts/utils/utils.d.ts +24 -0
- package/build/ts/utils/utils.d.ts.map +1 -0
- package/build/ts/utils/utils.js +49 -0
- package/build/ts/utils/utils.js.map +1 -0
- package/build/ts/verifyingKeys/checkVerifyingKeys.d.ts +10 -0
- package/build/ts/verifyingKeys/checkVerifyingKeys.d.ts.map +1 -0
- package/build/ts/verifyingKeys/checkVerifyingKeys.js +66 -0
- package/build/ts/verifyingKeys/checkVerifyingKeys.js.map +1 -0
- package/build/ts/verifyingKeys/index.d.ts +5 -0
- package/build/ts/verifyingKeys/index.d.ts.map +1 -0
- package/build/ts/verifyingKeys/index.js +13 -0
- package/build/ts/verifyingKeys/index.js.map +1 -0
- package/build/ts/verifyingKeys/setVerifyingKeys.d.ts +7 -0
- package/build/ts/verifyingKeys/setVerifyingKeys.d.ts.map +1 -0
- package/build/ts/verifyingKeys/setVerifyingKeys.js +84 -0
- package/build/ts/verifyingKeys/setVerifyingKeys.js.map +1 -0
- package/build/ts/verifyingKeys/types.d.ts +235 -0
- package/build/ts/verifyingKeys/types.d.ts.map +1 -0
- package/build/ts/verifyingKeys/types.js +3 -0
- package/build/ts/verifyingKeys/types.js.map +1 -0
- package/build/ts/verifyingKeys/utils.d.ts +29 -0
- package/build/ts/verifyingKeys/utils.d.ts.map +1 -0
- package/build/ts/verifyingKeys/utils.js +116 -0
- package/build/ts/verifyingKeys/utils.js.map +1 -0
- package/build/ts/vote/generate.d.ts +8 -0
- package/build/ts/vote/generate.d.ts.map +1 -0
- package/build/ts/vote/generate.js +46 -0
- package/build/ts/vote/generate.js.map +1 -0
- package/build/ts/vote/index.d.ts +6 -0
- package/build/ts/vote/index.d.ts.map +1 -0
- package/build/ts/vote/index.js +15 -0
- package/build/ts/vote/index.js.map +1 -0
- package/build/ts/vote/invalidate.d.ts +13 -0
- package/build/ts/vote/invalidate.d.ts.map +1 -0
- package/build/ts/vote/invalidate.js +44 -0
- package/build/ts/vote/invalidate.js.map +1 -0
- package/build/ts/vote/publish.d.ts +14 -0
- package/build/ts/vote/publish.d.ts.map +1 -0
- package/build/ts/vote/publish.js +88 -0
- package/build/ts/vote/publish.js.map +1 -0
- package/build/ts/vote/submit.d.ts +13 -0
- package/build/ts/vote/submit.d.ts.map +1 -0
- package/build/ts/vote/submit.js +36 -0
- package/build/ts/vote/submit.js.map +1 -0
- package/build/ts/vote/types.d.ts +238 -0
- package/build/ts/vote/types.d.ts.map +1 -0
- package/build/ts/vote/types.js +3 -0
- package/build/ts/vote/types.js.map +1 -0
- package/build/ts/vote/utils.d.ts +16 -0
- package/build/ts/vote/utils.d.ts.map +1 -0
- package/build/ts/vote/utils.js +26 -0
- package/build/ts/vote/utils.js.map +1 -0
- package/build/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const contracts_1 = require("@maci-protocol/contracts");
|
|
4
|
+
const domainobjs_1 = require("@maci-protocol/domainobjs");
|
|
5
|
+
const ethers_1 = require("ethers");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
describe("utils", () => {
|
|
8
|
+
let mockPollContract;
|
|
9
|
+
let mockIpfsService;
|
|
10
|
+
const mockProvider = {
|
|
11
|
+
getBlockNumber: () => Promise.resolve(0),
|
|
12
|
+
};
|
|
13
|
+
const keypair = new domainobjs_1.Keypair();
|
|
14
|
+
const defaultMessages = [
|
|
15
|
+
{
|
|
16
|
+
publicKey: keypair.publicKey.asArray().map(String),
|
|
17
|
+
data: new Array(10).fill("0"),
|
|
18
|
+
hash: "hash1",
|
|
19
|
+
maciAddress: ethers_1.ZeroAddress,
|
|
20
|
+
poll: 0,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
publicKey: new domainobjs_1.Keypair().publicKey.asArray().map(String),
|
|
24
|
+
data: new Array(10).fill("0"),
|
|
25
|
+
hash: "hash2",
|
|
26
|
+
maciAddress: ethers_1.ZeroAddress,
|
|
27
|
+
poll: 0,
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
mockIpfsService = {
|
|
32
|
+
read: jest.fn().mockResolvedValue(defaultMessages),
|
|
33
|
+
};
|
|
34
|
+
jest.spyOn(contracts_1.IpfsService, "getInstance").mockReturnValue(mockIpfsService);
|
|
35
|
+
mockPollContract = {
|
|
36
|
+
queryFilter: jest.fn().mockResolvedValue([{ args: { _ipfsHash: "hash" } }]),
|
|
37
|
+
filters: {
|
|
38
|
+
IpfsHashAdded: jest.fn(),
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
jest.clearAllMocks();
|
|
44
|
+
});
|
|
45
|
+
test("should parse IpfsHashAdded events properly", async () => {
|
|
46
|
+
const { messages } = await (0, utils_1.parseIpfsHashAddedEvents)({
|
|
47
|
+
startBlock: 0,
|
|
48
|
+
provider: mockProvider,
|
|
49
|
+
pollContract: mockPollContract,
|
|
50
|
+
publicKeys: [keypair.publicKey.serialize()],
|
|
51
|
+
messageHashes: ["hash1"],
|
|
52
|
+
});
|
|
53
|
+
expect(messages).toStrictEqual([defaultMessages[0]]);
|
|
54
|
+
});
|
|
55
|
+
it("should parse IpfsHashAdded events properly without public keys and message hashes", async () => {
|
|
56
|
+
const { messages } = await (0, utils_1.parseIpfsHashAddedEvents)({
|
|
57
|
+
startBlock: 0,
|
|
58
|
+
provider: mockProvider,
|
|
59
|
+
pollContract: mockPollContract,
|
|
60
|
+
});
|
|
61
|
+
expect(messages).toStrictEqual(defaultMessages);
|
|
62
|
+
});
|
|
63
|
+
it("should return empty array if can't get messages from ipfs", async () => {
|
|
64
|
+
mockIpfsService.read = jest.fn().mockResolvedValue(null);
|
|
65
|
+
const { messages } = await (0, utils_1.parseIpfsHashAddedEvents)({
|
|
66
|
+
startBlock: 0,
|
|
67
|
+
provider: mockProvider,
|
|
68
|
+
pollContract: mockPollContract,
|
|
69
|
+
});
|
|
70
|
+
expect(messages).toHaveLength(0);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
//# sourceMappingURL=utils.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.test.js","sourceRoot":"","sources":["../../../../ts/relayer/__tests__/utils.test.ts"],"names":[],"mappings":";;AAAA,wDAA0E;AAC1E,0DAAoD;AACpD,mCAAoD;AAIpD,oCAAoD;AAEpD,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;IACrB,IAAI,gBAAsB,CAAC;IAC3B,IAAI,eAA4B,CAAC;IAEjC,MAAM,YAAY,GAAG;QACnB,cAAc,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;KAC7B,CAAC;IAEd,MAAM,OAAO,GAAG,IAAI,oBAAO,EAAE,CAAC;IAE9B,MAAM,eAAe,GAAmB;QACtC;YACE,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,MAAM,CAAqB;YACtE,IAAI,EAAE,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAa;YACzC,IAAI,EAAE,OAAO;YACb,WAAW,EAAE,oBAAW;YACxB,IAAI,EAAE,CAAC;SACR;QACD;YACE,SAAS,EAAE,IAAI,oBAAO,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,GAAG,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,IAAI,EAAE;QACjG,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,IAAA,gCAAwB,EAAC;YAClD,UAAU,EAAE,CAAC;YACb,QAAQ,EAAE,YAAY;YACtB,YAAY,EAAE,gBAAgB;SAC/B,CAAC,CAAC;QAEH,MAAM,CAAC,QAAQ,CAAC,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2DAA2D,EAAE,KAAK,IAAI,EAAE;QACzE,eAAe,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAEzD,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,IAAA,gCAAwB,EAAC;YAClD,UAAU,EAAE,CAAC;YACb,QAAQ,EAAE,YAAY;YACtB,YAAY,EAAE,gBAAgB;SAC/B,CAAC,CAAC;QAEH,MAAM,CAAC,QAAQ,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { getRelayedMessages, getMessageBatches, relayMessages } from "./messages";
|
|
2
|
+
export type { IGetRelayedMessagesArgs, IGetRelayedMessagesData, IMessageBatch, IGetMessageBatchesArgs, IGetMessageBatchesData, IRelayMessagesArgs, IRelayMessagesData, } from "./types";
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../ts/relayer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAClF,YAAY,EACV,uBAAuB,EACvB,uBAAuB,EACvB,aAAa,EACb,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.relayMessages = exports.getMessageBatches = exports.getRelayedMessages = void 0;
|
|
4
|
+
var messages_1 = require("./messages");
|
|
5
|
+
Object.defineProperty(exports, "getRelayedMessages", { enumerable: true, get: function () { return messages_1.getRelayedMessages; } });
|
|
6
|
+
Object.defineProperty(exports, "getMessageBatches", { enumerable: true, get: function () { return messages_1.getMessageBatches; } });
|
|
7
|
+
Object.defineProperty(exports, "relayMessages", { enumerable: true, get: function () { return messages_1.relayMessages; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/relayer/index.ts"],"names":[],"mappings":";;;AAAA,uCAAkF;AAAzE,8GAAA,kBAAkB,OAAA;AAAE,6GAAA,iBAAiB,OAAA;AAAE,yGAAA,aAAa,OAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { IGetMessageBatchesArgs, IGetMessageBatchesData, IGetRelayedMessagesArgs, IGetRelayedMessagesData, IRelayMessagesArgs, IRelayMessagesData } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Get relayed messages from Poll contract.
|
|
4
|
+
*
|
|
5
|
+
* @param args get relayed messages arguments
|
|
6
|
+
* @returns relayed messages
|
|
7
|
+
*/
|
|
8
|
+
export declare const getRelayedMessages: ({ maciAddress, pollId, signer, provider, startBlock, publicKeys, messageHashes, }: IGetRelayedMessagesArgs) => Promise<IGetRelayedMessagesData>;
|
|
9
|
+
/**
|
|
10
|
+
* Get message batches from relayer service.
|
|
11
|
+
*
|
|
12
|
+
* @param args get message batches arguments
|
|
13
|
+
* @returns message batches
|
|
14
|
+
*/
|
|
15
|
+
export declare const getMessageBatches: ({ url, limit, skip, ipfsHashes, maciContractAddress, poll, publicKeys, messageHashes, }: IGetMessageBatchesArgs) => Promise<IGetMessageBatchesData>;
|
|
16
|
+
/**
|
|
17
|
+
* Relay IPFS messages to Poll contract.
|
|
18
|
+
*
|
|
19
|
+
* @param args relay messages arguments
|
|
20
|
+
* @returns transaction hash
|
|
21
|
+
*/
|
|
22
|
+
export declare const relayMessages: ({ maciAddress, pollId, ipfsHash, messages, signer, provider, }: IRelayMessagesArgs) => Promise<IRelayMessagesData>;
|
|
23
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../ts/relayer/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EAEvB,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAMjB;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAU,mFAQtC,uBAAuB,KAAG,OAAO,CAAC,uBAAuB,CAY3D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAU,yFASrC,sBAAsB,KAAG,OAAO,CAAC,sBAAsB,CAoBzD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GAAU,gEAOjC,kBAAkB,KAAG,OAAO,CAAC,kBAAkB,CAcjD,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.relayMessages = exports.getMessageBatches = exports.getRelayedMessages = void 0;
|
|
4
|
+
const utils_1 = require("../poll/utils");
|
|
5
|
+
const utils_2 = require("./utils");
|
|
6
|
+
/**
|
|
7
|
+
* Get relayed messages from Poll contract.
|
|
8
|
+
*
|
|
9
|
+
* @param args get relayed messages arguments
|
|
10
|
+
* @returns relayed messages
|
|
11
|
+
*/
|
|
12
|
+
const getRelayedMessages = async ({ maciAddress, pollId, signer, provider, startBlock = 0, publicKeys, messageHashes, }) => {
|
|
13
|
+
const { poll: pollContract } = await (0, utils_1.getPollContracts)({ maciAddress, pollId, signer, provider });
|
|
14
|
+
const { messages } = await (0, utils_2.parseIpfsHashAddedEvents)({
|
|
15
|
+
pollContract,
|
|
16
|
+
startBlock,
|
|
17
|
+
publicKeys,
|
|
18
|
+
messageHashes,
|
|
19
|
+
provider,
|
|
20
|
+
});
|
|
21
|
+
return { messages };
|
|
22
|
+
};
|
|
23
|
+
exports.getRelayedMessages = getRelayedMessages;
|
|
24
|
+
/**
|
|
25
|
+
* Get message batches from relayer service.
|
|
26
|
+
*
|
|
27
|
+
* @param args get message batches arguments
|
|
28
|
+
* @returns message batches
|
|
29
|
+
*/
|
|
30
|
+
const getMessageBatches = async ({ url, limit, skip, ipfsHashes, maciContractAddress, poll, publicKeys, messageHashes, }) => {
|
|
31
|
+
const messageBatches = await fetch(`${url}/v1/messageBatches/get`, {
|
|
32
|
+
method: "GET",
|
|
33
|
+
headers: {
|
|
34
|
+
"Content-Type": "application/json",
|
|
35
|
+
},
|
|
36
|
+
body: JSON.stringify({
|
|
37
|
+
limit,
|
|
38
|
+
skip,
|
|
39
|
+
ipfsHashes,
|
|
40
|
+
poll,
|
|
41
|
+
maciContractAddress,
|
|
42
|
+
messageHashes,
|
|
43
|
+
publicKeys,
|
|
44
|
+
}),
|
|
45
|
+
})
|
|
46
|
+
.then((res) => res.json())
|
|
47
|
+
.then((res) => res);
|
|
48
|
+
return { messageBatches };
|
|
49
|
+
};
|
|
50
|
+
exports.getMessageBatches = getMessageBatches;
|
|
51
|
+
/**
|
|
52
|
+
* Relay IPFS messages to Poll contract.
|
|
53
|
+
*
|
|
54
|
+
* @param args relay messages arguments
|
|
55
|
+
* @returns transaction hash
|
|
56
|
+
*/
|
|
57
|
+
const relayMessages = async ({ maciAddress, pollId, ipfsHash, messages, signer, provider, }) => {
|
|
58
|
+
const { poll: pollContract } = await (0, utils_1.getPollContracts)({ maciAddress, pollId, signer, provider });
|
|
59
|
+
const messageHashes = await Promise.all(messages.map(({ data, publicKey }) => pollContract.hashMessageAndPublicKey({ data }, { x: publicKey[0], y: publicKey[1] })));
|
|
60
|
+
const receipt = await pollContract.relayMessagesBatch(messageHashes, ipfsHash).then((tx) => tx.wait());
|
|
61
|
+
return {
|
|
62
|
+
hash: receipt?.hash,
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
exports.relayMessages = relayMessages;
|
|
66
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../../ts/relayer/messages.ts"],"names":[],"mappings":";;;AAUA,yCAAiD;AAEjD,mCAAmD;AAEnD;;;;;GAKG;AACI,MAAM,kBAAkB,GAAG,KAAK,EAAE,EACvC,WAAW,EACX,MAAM,EACN,MAAM,EACN,QAAQ,EACR,UAAU,GAAG,CAAC,EACd,UAAU,EACV,aAAa,GACW,EAAoC,EAAE;IAC9D,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,MAAM,IAAA,wBAAgB,EAAC,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IAEjG,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,IAAA,gCAAwB,EAAC;QAClD,YAAY;QACZ,UAAU;QACV,UAAU;QACV,aAAa;QACb,QAAQ;KACT,CAAC,CAAC;IAEH,OAAO,EAAE,QAAQ,EAAE,CAAC;AACtB,CAAC,CAAC;AApBW,QAAA,kBAAkB,sBAoB7B;AAEF;;;;;GAKG;AACI,MAAM,iBAAiB,GAAG,KAAK,EAAE,EACtC,GAAG,EACH,KAAK,EACL,IAAI,EACJ,UAAU,EACV,mBAAmB,EACnB,IAAI,EACJ,UAAU,EACV,aAAa,GACU,EAAmC,EAAE;IAC5D,MAAM,cAAc,GAAG,MAAM,KAAK,CAAC,GAAG,GAAG,wBAAwB,EAAE;QACjE,MAAM,EAAE,KAAK;QACb,O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CAAC,CAAC;AArBW,QAAA,aAAa,iBAqBxB"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import type { IIpfsMessage } from "@maci-protocol/contracts";
|
|
2
|
+
import type { Poll } from "@maci-protocol/contracts/typechain-types";
|
|
3
|
+
import type { Provider, Signer } from "ethers";
|
|
4
|
+
/**
|
|
5
|
+
* Interface that represents get relayed messages arguments
|
|
6
|
+
*/
|
|
7
|
+
export interface IGetRelayedMessagesArgs {
|
|
8
|
+
/**
|
|
9
|
+
* MACI contract address
|
|
10
|
+
*/
|
|
11
|
+
maciAddress: string;
|
|
12
|
+
/**
|
|
13
|
+
* Poll id
|
|
14
|
+
*/
|
|
15
|
+
pollId: number;
|
|
16
|
+
/**
|
|
17
|
+
* Signer
|
|
18
|
+
*/
|
|
19
|
+
signer: Signer;
|
|
20
|
+
/**
|
|
21
|
+
* Provider
|
|
22
|
+
*/
|
|
23
|
+
provider: Provider;
|
|
24
|
+
/**
|
|
25
|
+
* Start block
|
|
26
|
+
*/
|
|
27
|
+
startBlock?: number;
|
|
28
|
+
/**
|
|
29
|
+
* User public keys (optional)
|
|
30
|
+
*/
|
|
31
|
+
publicKeys?: string[];
|
|
32
|
+
/**
|
|
33
|
+
* Message hashes (optional)
|
|
34
|
+
*/
|
|
35
|
+
messageHashes?: string[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Interface that represents get message batches arguments
|
|
39
|
+
*/
|
|
40
|
+
export interface IGetMessageBatchesArgs {
|
|
41
|
+
/**
|
|
42
|
+
* Relayer service url
|
|
43
|
+
*/
|
|
44
|
+
url: string;
|
|
45
|
+
/**
|
|
46
|
+
* Limit
|
|
47
|
+
*/
|
|
48
|
+
limit: number;
|
|
49
|
+
/**
|
|
50
|
+
* Skip
|
|
51
|
+
*/
|
|
52
|
+
skip: number;
|
|
53
|
+
/**
|
|
54
|
+
* Poll id
|
|
55
|
+
*/
|
|
56
|
+
poll: number;
|
|
57
|
+
/**
|
|
58
|
+
* MACI contract address
|
|
59
|
+
*/
|
|
60
|
+
maciContractAddress: string;
|
|
61
|
+
/**
|
|
62
|
+
* IPFS hashes of message batches (optional)
|
|
63
|
+
*/
|
|
64
|
+
ipfsHashes?: string[];
|
|
65
|
+
/**
|
|
66
|
+
* User public keys (optional)
|
|
67
|
+
*/
|
|
68
|
+
publicKeys?: string[];
|
|
69
|
+
/**
|
|
70
|
+
* Message hashes (optional)
|
|
71
|
+
*/
|
|
72
|
+
messageHashes?: string[];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Interface for the arguments for IpfsHashAdded events parsing
|
|
76
|
+
*/
|
|
77
|
+
export interface IParseIpfsHashAddedEventsArgs {
|
|
78
|
+
/**
|
|
79
|
+
* Poll contract
|
|
80
|
+
*/
|
|
81
|
+
pollContract: Poll;
|
|
82
|
+
/**
|
|
83
|
+
* Start block
|
|
84
|
+
*/
|
|
85
|
+
startBlock: number;
|
|
86
|
+
/**
|
|
87
|
+
* Provider
|
|
88
|
+
*/
|
|
89
|
+
provider: Provider;
|
|
90
|
+
/**
|
|
91
|
+
* User public keys (optional)
|
|
92
|
+
*/
|
|
93
|
+
publicKeys?: string[];
|
|
94
|
+
/**
|
|
95
|
+
* Message hashes (optional)
|
|
96
|
+
*/
|
|
97
|
+
messageHashes?: string[];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Interface for the return type for getting relayed messages
|
|
101
|
+
*/
|
|
102
|
+
export interface IGetRelayedMessagesData {
|
|
103
|
+
/**
|
|
104
|
+
* Uploaded IPFS messages
|
|
105
|
+
*/
|
|
106
|
+
messages: IIpfsMessage[];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Interface for the return type for getting message batches from relayer service
|
|
110
|
+
*/
|
|
111
|
+
export interface IGetMessageBatchesData {
|
|
112
|
+
/**
|
|
113
|
+
* Relayer message batches
|
|
114
|
+
*/
|
|
115
|
+
messageBatches: IMessageBatch[];
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Interface that represents message batch
|
|
119
|
+
*/
|
|
120
|
+
export interface IMessageBatch {
|
|
121
|
+
/**
|
|
122
|
+
* Messages
|
|
123
|
+
*/
|
|
124
|
+
messages: IIpfsMessage[];
|
|
125
|
+
/**
|
|
126
|
+
* IPFS hash
|
|
127
|
+
*/
|
|
128
|
+
ipfsHash?: string;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Interface that represents relay messages arguments
|
|
132
|
+
*/
|
|
133
|
+
export interface IRelayMessagesArgs {
|
|
134
|
+
/**
|
|
135
|
+
* Poll id
|
|
136
|
+
*/
|
|
137
|
+
pollId: number;
|
|
138
|
+
/**
|
|
139
|
+
* MACI contract address
|
|
140
|
+
*/
|
|
141
|
+
maciAddress: string;
|
|
142
|
+
/**
|
|
143
|
+
* IPFS hash
|
|
144
|
+
*/
|
|
145
|
+
ipfsHash: string;
|
|
146
|
+
/**
|
|
147
|
+
* IPFS Messages
|
|
148
|
+
*/
|
|
149
|
+
messages: IIpfsMessage[];
|
|
150
|
+
/**
|
|
151
|
+
* Signer
|
|
152
|
+
*/
|
|
153
|
+
signer?: Signer;
|
|
154
|
+
/**
|
|
155
|
+
* Provider
|
|
156
|
+
*/
|
|
157
|
+
provider?: Provider;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Interface that represents return data for relay messages
|
|
161
|
+
*/
|
|
162
|
+
export interface IRelayMessagesData {
|
|
163
|
+
/**
|
|
164
|
+
* Transaction hash
|
|
165
|
+
*/
|
|
166
|
+
hash?: string;
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../ts/relayer/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0CAA0C,CAAC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AY,EAAE,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,cAAc,EAAE,aAAa,EAAE,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,QAAQ,EAAE,YAAY,EAAE,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,QAAQ,EAAE,YAAY,EAAE,CAAC;IAEzB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../ts/relayer/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type IIpfsMessage } from "@maci-protocol/contracts";
|
|
2
|
+
import type { IParseIpfsHashAddedEventsArgs } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Parse the ipfs hash events from the Poll contract
|
|
5
|
+
*
|
|
6
|
+
* @param args parsing params
|
|
7
|
+
* @returns ipfs messages
|
|
8
|
+
*/
|
|
9
|
+
export declare const parseIpfsHashAddedEvents: ({ pollContract, startBlock, provider, publicKeys, messageHashes, }: IParseIpfsHashAddedEventsArgs) => Promise<{
|
|
10
|
+
messages: IIpfsMessage[];
|
|
11
|
+
}>;
|
|
12
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../ts/relayer/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAe,MAAM,0BAA0B,CAAC;AAG1E,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAI7D;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,GAAU,oEAM5C,6BAA6B,KAAG,OAAO,CAAC;IAAE,QAAQ,EAAE,YAAY,EAAE,CAAA;CAAE,CAwCtE,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseIpfsHashAddedEvents = void 0;
|
|
4
|
+
const contracts_1 = require("@maci-protocol/contracts");
|
|
5
|
+
const domainobjs_1 = require("@maci-protocol/domainobjs");
|
|
6
|
+
const constants_1 = require("../utils/constants");
|
|
7
|
+
/**
|
|
8
|
+
* Parse the ipfs hash events from the Poll contract
|
|
9
|
+
*
|
|
10
|
+
* @param args parsing params
|
|
11
|
+
* @returns ipfs messages
|
|
12
|
+
*/
|
|
13
|
+
const parseIpfsHashAddedEvents = async ({ pollContract, startBlock, provider, publicKeys, messageHashes, }) => {
|
|
14
|
+
const ipfsService = contracts_1.IpfsService.getInstance();
|
|
15
|
+
const currentBlock = await provider.getBlockNumber();
|
|
16
|
+
const ipfsHashes = [];
|
|
17
|
+
for (let block = startBlock; block <= currentBlock; block += constants_1.BLOCKS_STEP) {
|
|
18
|
+
const toBlock = Math.min(block + constants_1.BLOCKS_STEP - 1, currentBlock);
|
|
19
|
+
// eslint-disable-next-line no-await-in-loop
|
|
20
|
+
const events = await pollContract.queryFilter(pollContract.filters.IpfsHashAdded(), block, toBlock);
|
|
21
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
22
|
+
ipfsHashes.push(...events.map((event) => event.args._ipfsHash));
|
|
23
|
+
}
|
|
24
|
+
const messages = await Promise.all(ipfsHashes.map((ipfsHash) => ipfsService.read(ipfsHash))).then((data) => data.reduce((acc, items) => {
|
|
25
|
+
acc?.push(...(items || [])
|
|
26
|
+
.filter((message) => publicKeys && publicKeys.length > 0
|
|
27
|
+
? publicKeys.some((publicKey) => domainobjs_1.PublicKey.deserialize(publicKey).equals(new domainobjs_1.PublicKey([BigInt(message.publicKey[0]), BigInt(message.publicKey[1])])))
|
|
28
|
+
: true)
|
|
29
|
+
.filter((message) => messageHashes && messageHashes.length > 0 ? messageHashes.some((hash) => message.hash === hash) : true));
|
|
30
|
+
return acc ?? [];
|
|
31
|
+
}, []));
|
|
32
|
+
return {
|
|
33
|
+
messages: messages ?? [],
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
exports.parseIpfsHashAddedEvents = parseIpfsHashAddedEvents;
|
|
37
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../ts/relayer/utils.ts"],"names":[],"mappings":";;;AAAA,wDAA0E;AAC1E,0DAAsD;AAItD,kDAAiD;AAEjD;;;;;GAKG;AACI,MAAM,wBAAwB,GAAG,KAAK,EAAE,EAC7C,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,UAAU,EACV,aAAa,GACiB,EAAyC,EAAE;IACzE,MAAM,WAAW,GAAG,uBAAW,CAAC,WAAW,EAAE,CAAC;IAC9C,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,cAAc,EAAE,CAAC;IACrD,MAAM,UAAU,GAAa,EAAE,CAAC;IAEhC,KAAK,IAAI,KAAK,GAAG,UAAU,EAAE,KAAK,IAAI,YAAY,EAAE,KAAK,IAAI,uBAAW,EAAE,CAAC;QACzE,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,uBAAW,GAAG,CAAC,EAAE,YAAY,CAAC,CAAC;QAChE,4CAA4C;QAC5C,MAAM,MAAM,GAAG,MAAM,YAAY,C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AAC;QAEF,OAAO,GAAG,IAAI,EAAE,CAAC;IACnB,CAAC,EAAE,EAAE,CAAC,CACT,CAAC;IAEF,OAAO;QACL,QAAQ,EAAE,QAAQ,IAAI,EAAE;KACzB,CAAC;AACJ,CAAC,CAAC;AA9CW,QAAA,wBAAwB,4BA8CnC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IGenerateTallyCommitmentsArgs, ITallyCommitments } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Generate the tally commitments for this current batch of proving
|
|
4
|
+
* @param tallyData - The tally data
|
|
5
|
+
* @param voteOptionTreeDepth - The vote option tree depth
|
|
6
|
+
* @returns The commitments to the Tally data
|
|
7
|
+
*/
|
|
8
|
+
export declare const generateTallyCommitments: ({ tallyData, voteOptionTreeDepth, }: IGenerateTallyCommitmentsArgs) => ITallyCommitments;
|
|
9
|
+
//# sourceMappingURL=commitments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commitments.d.ts","sourceRoot":"","sources":["../../../ts/tally/commitments.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,6BAA6B,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEhF;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,GAAI,qCAGtC,6BAA6B,KAAG,iBAyClC,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateTallyCommitments = void 0;
|
|
4
|
+
const core_1 = require("@maci-protocol/core");
|
|
5
|
+
const crypto_1 = require("@maci-protocol/crypto");
|
|
6
|
+
/**
|
|
7
|
+
* Generate the tally commitments for this current batch of proving
|
|
8
|
+
* @param tallyData - The tally data
|
|
9
|
+
* @param voteOptionTreeDepth - The vote option tree depth
|
|
10
|
+
* @returns The commitments to the Tally data
|
|
11
|
+
*/
|
|
12
|
+
const generateTallyCommitments = ({ tallyData, voteOptionTreeDepth, }) => {
|
|
13
|
+
// compute newResultsCommitment
|
|
14
|
+
const newResultsCommitment = (0, crypto_1.generateTreeCommitment)(tallyData.results.tally.map((x) => BigInt(x)), BigInt(tallyData.results.salt), voteOptionTreeDepth);
|
|
15
|
+
// compute newSpentVoiceCreditsCommitment
|
|
16
|
+
const newSpentVoiceCreditsCommitment = (0, crypto_1.hash2)([
|
|
17
|
+
BigInt(tallyData.totalSpentVoiceCredits.spent),
|
|
18
|
+
BigInt(tallyData.totalSpentVoiceCredits.salt),
|
|
19
|
+
]);
|
|
20
|
+
let newTallyCommitment;
|
|
21
|
+
let newPerVoteOptionSpentVoiceCreditsCommitment;
|
|
22
|
+
if (tallyData.mode === core_1.EMode.QV) {
|
|
23
|
+
// compute newPerVoteOptionSpentVoiceCreditsCommitment
|
|
24
|
+
newPerVoteOptionSpentVoiceCreditsCommitment = (0, crypto_1.generateTreeCommitment)(tallyData.perVoteOptionSpentVoiceCredits.tally.map((x) => BigInt(x)), BigInt(tallyData.perVoteOptionSpentVoiceCredits.salt), voteOptionTreeDepth);
|
|
25
|
+
// compute newTallyCommitment
|
|
26
|
+
newTallyCommitment = (0, crypto_1.hash3)([
|
|
27
|
+
newResultsCommitment,
|
|
28
|
+
newSpentVoiceCreditsCommitment,
|
|
29
|
+
newPerVoteOptionSpentVoiceCreditsCommitment,
|
|
30
|
+
]);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
newTallyCommitment = (0, crypto_1.hashLeftRight)(newResultsCommitment, newSpentVoiceCreditsCommitment);
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
newTallyCommitment,
|
|
37
|
+
newSpentVoiceCreditsCommitment,
|
|
38
|
+
newPerVoteOptionSpentVoiceCreditsCommitment,
|
|
39
|
+
newResultsCommitment,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
exports.generateTallyCommitments = generateTallyCommitments;
|
|
43
|
+
//# sourceMappingURL=commitments.js.map
|
|
@@ -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8BAA8B,CAAC,CAAC;IAC3F,CAAC;IAED,OAAO;QACL,kBAAkB;QAClB,8BAA8B;QAC9B,2CAA2C;QAC3C,oBAAoB;KACrB,CAAC;AACJ,CAAC,CAAC;AA5CW,QAAA,wBAAwB,4BA4CnC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { generateTallyCommitments } from "./commitments";
|
|
2
|
+
export { verify } from "./verification";
|
|
3
|
+
export type { ITallyData, IVerifyArgs, IGenerateTallyCommitmentsArgs, ITallyCommitments, ITallyVotesInputs, IGetResultPerOptionArgs, IGetResultsArgs, } from "./types";
|
|
4
|
+
export { getResultPerOption, getResults } from "./results";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../ts/tally/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,YAAY,EACV,UAAU,EACV,WAAW,EACX,6BAA6B,EAC7B,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,eAAe,GAChB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getResults = exports.getResultPerOption = exports.verify = exports.generateTallyCommitments = void 0;
|
|
4
|
+
var commitments_1 = require("./commitments");
|
|
5
|
+
Object.defineProperty(exports, "generateTallyCommitments", { enumerable: true, get: function () { return commitments_1.generateTallyCommitments; } });
|
|
6
|
+
var verification_1 = require("./verification");
|
|
7
|
+
Object.defineProperty(exports, "verify", { enumerable: true, get: function () { return verification_1.verify; } });
|
|
8
|
+
var results_1 = require("./results");
|
|
9
|
+
Object.defineProperty(exports, "getResultPerOption", { enumerable: true, get: function () { return results_1.getResultPerOption; } });
|
|
10
|
+
Object.defineProperty(exports, "getResults", { enumerable: true, get: function () { return results_1.getResults; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/tally/index.ts"],"names":[],"mappings":";;;AAAA,6CAAyD;AAAhD,uHAAA,wBAAwB,OAAA;AACjC,+CAAwC;AAA/B,sGAAA,MAAM,OAAA;AAUf,qCAA2D;AAAlD,6GAAA,kBAAkB,OAAA;AAAE,qGAAA,UAAU,OAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IGetResultPerOptionArgs, IGetResultsArgs } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Get result per option
|
|
4
|
+
* @param {IGetResultPerOptionsArgs} - The arguments to get result per option
|
|
5
|
+
* @returns The result per option
|
|
6
|
+
*/
|
|
7
|
+
export declare const getResultPerOption: ({ maciAddress, pollId, index, signer, }: IGetResultPerOptionArgs) => Promise<bigint>;
|
|
8
|
+
/**
|
|
9
|
+
* Get all results from the Tally contract
|
|
10
|
+
* @param {IGetResultsArgs} - The arguments to get all the results
|
|
11
|
+
* @returns The results array (The final result of vote option n is in index n-1)
|
|
12
|
+
*/
|
|
13
|
+
export declare const getResults: ({ maciAddress, pollId, signer }: IGetResultsArgs) => Promise<bigint[]>;
|
|
14
|
+
//# sourceMappingURL=results.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.d.ts","sourceRoot":"","sources":["../../../ts/tally/results.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAExE;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAU,yCAKtC,uBAAuB,KAAG,OAAO,CAAC,MAAM,CAc1C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAU,iCAAiC,eAAe,KAAG,OAAO,CAAC,MAAM,EAAE,CAwBnG,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getResults = exports.getResultPerOption = void 0;
|
|
4
|
+
const typechain_types_1 = require("@maci-protocol/contracts/typechain-types");
|
|
5
|
+
/**
|
|
6
|
+
* Get result per option
|
|
7
|
+
* @param {IGetResultPerOptionsArgs} - The arguments to get result per option
|
|
8
|
+
* @returns The result per option
|
|
9
|
+
*/
|
|
10
|
+
const getResultPerOption = async ({ maciAddress, pollId, index, signer, }) => {
|
|
11
|
+
const maciContract = typechain_types_1.MACI__factory.connect(maciAddress, signer);
|
|
12
|
+
const pollContracts = await maciContract.getPoll(pollId);
|
|
13
|
+
const tallyContract = typechain_types_1.Tally__factory.connect(pollContracts.tally, signer);
|
|
14
|
+
const result = await tallyContract.tallyResults(index);
|
|
15
|
+
if (!result.flag) {
|
|
16
|
+
throw new Error("Tally result is not set");
|
|
17
|
+
}
|
|
18
|
+
return result.value;
|
|
19
|
+
};
|
|
20
|
+
exports.getResultPerOption = getResultPerOption;
|
|
21
|
+
/**
|
|
22
|
+
* Get all results from the Tally contract
|
|
23
|
+
* @param {IGetResultsArgs} - The arguments to get all the results
|
|
24
|
+
* @returns The results array (The final result of vote option n is in index n-1)
|
|
25
|
+
*/
|
|
26
|
+
const getResults = async ({ maciAddress, pollId, signer }) => {
|
|
27
|
+
const maciContract = typechain_types_1.MACI__factory.connect(maciAddress, signer);
|
|
28
|
+
const pollContracts = await maciContract.getPoll(pollId);
|
|
29
|
+
const pollContract = typechain_types_1.Poll__factory.connect(pollContracts.poll, signer);
|
|
30
|
+
const numberOfVoteOptions = await pollContract.voteOptions();
|
|
31
|
+
const tallyContract = typechain_types_1.Tally__factory.connect(pollContracts.tally, signer);
|
|
32
|
+
const results = [];
|
|
33
|
+
for (let i = 0; i < numberOfVoteOptions; i += 1) {
|
|
34
|
+
// eslint-disable-next-line no-await-in-loop
|
|
35
|
+
const result = await tallyContract.tallyResults(i);
|
|
36
|
+
if (!result.flag) {
|
|
37
|
+
throw new Error(`Tally result for option ${i} is not set`);
|
|
38
|
+
}
|
|
39
|
+
results.push(result.value);
|
|
40
|
+
}
|
|
41
|
+
return results;
|
|
42
|
+
};
|
|
43
|
+
exports.getResults = getResults;
|
|
44
|
+
//# sourceMappingURL=results.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.js","sourceRoot":"","sources":["../../../ts/tally/results.ts"],"names":[],"mappings":";;;AAAA,8EAIkD;AAIlD;;;;GAIG;AACI,MAAM,kBAAkB,GAAG,KAAK,EAAE,EACvC,WAAW,EACX,MAAM,EACN,KAAK,EACL,MAAM,GACkB,EAAmB,EAAE;IAC7C,MAAM,YAAY,GAAG,+BAAW,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAE9D,MAAM,aAAa,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAEzD,MAAM,aAAa,GAAG,gCAAY,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAExE,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAEvD,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,MAAM,CAAC,KAAK,CAAC;AACtB,CAAC,CAAC;AAnBW,QAAA,kBAAkB,sBAmB7B;AAEF;;;;GAIG;AACI,MAAM,UAAU,GAAG,KAAK,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAmB,EAAqB,EAAE;IACtG,MAAM,YAAY,GAAG,+BAAW,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,C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