@maci-protocol/website 0.0.0-ci.d0dddbc → 0.0.0-ci.d4be71b
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maci-protocol/website",
|
|
3
|
-
"version": "0.0.0-ci.
|
|
3
|
+
"version": "0.0.0-ci.d4be71b",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@docusaurus/module-type-aliases": "^3.8.1",
|
|
42
42
|
"@docusaurus/tsconfig": "^3.8.1",
|
|
43
43
|
"@docusaurus/types": "^3.8.1",
|
|
44
|
-
"@types/node": "^
|
|
44
|
+
"@types/node": "^22.15.17",
|
|
45
45
|
"@types/react": "^19.1.8",
|
|
46
46
|
"ts-node": "^10.9.2",
|
|
47
47
|
"typescript": "^5.8.3"
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"engines": {
|
|
62
62
|
"node": ">=18.0"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "e23a1a52f7a9ede9c18c13cadd7aebb27a66aa88"
|
|
65
65
|
}
|
|
@@ -19,7 +19,7 @@ The MACI smart contracts handle the on-chain aspects - both the functionality an
|
|
|
19
19
|
|
|
20
20
|
The MACI smart contracts are written in [Solidity](https://soliditylang.org/).
|
|
21
21
|
|
|
22
|
-
Contracts are released through the [`@maci-
|
|
22
|
+
Contracts are released through the [`@maci-contracts`](https://www.npmjs.com/package/maci-contracts) NPM package.
|
|
23
23
|
|
|
24
24
|
[Learn more about MACI contracts](/docs/technical-references/smart-contracts/)
|
|
25
25
|
|
|
@@ -29,12 +29,12 @@ The TypeScript libraries manage the business logic between the smart contracts a
|
|
|
29
29
|
|
|
30
30
|
The MACI [TypeScript](https://www.typescriptlang.org/) libraries are released through the following NPM packages:
|
|
31
31
|
|
|
32
|
-
- [`@maci-
|
|
33
|
-
- [`@maci-
|
|
34
|
-
- [`@maci-
|
|
35
|
-
- [`@maci-
|
|
36
|
-
- [`@maci-
|
|
37
|
-
- [`@maci-
|
|
32
|
+
- [`@maci-cli`](https://www.npmjs.com/package/maci-cli)
|
|
33
|
+
- [`@maci-core`](https://www.npmjs.com/package/maci-core)
|
|
34
|
+
- [`@maci-crypto`](https://www.npmjs.com/package/maci-crypto)
|
|
35
|
+
- [`@maci-domainobjs`](https://www.npmjs.com/package/maci-domainobjs)
|
|
36
|
+
- [`@maci-integrationtests`](https://www.npmjs.com/package/maci-integrationtests)
|
|
37
|
+
- [`@maci-sdk`](https://www.npmjs.com/package/maci-sdk)
|
|
38
38
|
|
|
39
39
|
## Circuits
|
|
40
40
|
|
|
@@ -43,6 +43,6 @@ MACI has multiple circuits that ensure all off-chain computation is completed co
|
|
|
43
43
|
The circuits for these zero-knowledge proofs are written
|
|
44
44
|
in [Circom](https://iden3.io/circom).
|
|
45
45
|
|
|
46
|
-
The MACI circuits are released through the [`@maci-
|
|
46
|
+
The MACI circuits are released through the [`@maci-circuits`](https://www.npmjs.com/package/maci-circuits) NPM package.
|
|
47
47
|
|
|
48
48
|
[Learn more about MACI circuits](/docs/technical-references/zk-snark-circuits/)
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: MACI SDK
|
|
3
|
-
description: How to use the MACI SDK
|
|
4
|
-
sidebar_label: MACI SDK
|
|
5
|
-
sidebar_position: 6
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
In this guide we will be looking at how to use the MACI SDK to interact with the MACI protocol.
|
|
9
|
-
|
|
10
|
-
## Installation
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
-
npm install @maci-protocol/sdk
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
## Browser compatibility
|
|
17
|
-
|
|
18
|
-
As the SDK imports functions from the `@maci-protocol/contracts` package which uses hardhat, certain functionality is not browser compatible.
|
|
19
|
-
However, all it takes to use browser compatible functions is to import from `@maci-protocol/sdk/browser`.
|
|
20
|
-
|
|
21
|
-
As an example, we can import the `signUp` function from the `@maci-protocol/sdk/browser` package.
|
|
22
|
-
|
|
23
|
-
```typescript
|
|
24
|
-
import { signUp } from "@maci-protocol/sdk/browser";
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
Let's take a look at an example of how to use the `joinPoll` function to register a user to a poll.
|
|
28
|
-
|
|
29
|
-
### JoinPoll
|
|
30
|
-
|
|
31
|
-
This step is required to register a user to a specific poll for which they want to vote. In short, it requires the user to generate a zk-SNARK proof that they know the private key to a public key registered to the MACI contract (proving they passed the initial gatekeeping requirements). This forces them to join with the same MACI key to each poll, greatly increasing the value of the key. Should they have been allowed to join with a throwaway key, they could simply sell their key for polls they do not care about.
|
|
32
|
-
|
|
33
|
-
**How does the flow look like?**
|
|
34
|
-
|
|
35
|
-
1. Reconstruct the MACI state tree by pulling all public keys from the MACI contract (events from RPC or from Subgraph)
|
|
36
|
-
2. Generate a merkle tree inclusion proof for the user's public key
|
|
37
|
-
3. Generate a zk-SNARK proof that the user knows the private key to the public key in the merkle tree inclusion proof
|
|
38
|
-
4. Call the `joinPoll` function on the Poll smart contract
|
|
39
|
-
|
|
40
|
-
**How to use the SDK for this?**
|
|
41
|
-
|
|
42
|
-
> This example is browser specific, as it uses the `@maci-protocol/sdk/browser` package and WASM for witness generation
|
|
43
|
-
|
|
44
|
-
Option 1: Use the `joinPoll` function from the `@maci-protocol/sdk/browser` package.
|
|
45
|
-
|
|
46
|
-
1. Download the `pollJoining` zk artifacts using [downloadPollJoiningArtifactsBrowser](https://github.com/privacy-scaling-explorations/maci/blob/dev/packages/sdk/ts/proof/download.ts#L46)
|
|
47
|
-
|
|
48
|
-
```typescript
|
|
49
|
-
import { downloadPollJoiningArtifactsBrowser } from "@maci-protocol/sdk/browser";
|
|
50
|
-
|
|
51
|
-
const artifacts = await downloadPollJoiningArtifactsBrowser({
|
|
52
|
-
testing: true,
|
|
53
|
-
stateTreeDepth: 10,
|
|
54
|
-
});
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
2. Use the `joinPoll` function to join the poll
|
|
58
|
-
|
|
59
|
-
```typescript
|
|
60
|
-
import { joinPoll } from "@maci-protocol/sdk/browser";
|
|
61
|
-
|
|
62
|
-
const joinedPollData = await joinPoll({
|
|
63
|
-
maciAddress: PUBLIC_MACI_ADDRESS,
|
|
64
|
-
privateKey: maciKeypair.privateKey.serialize(),
|
|
65
|
-
signer,
|
|
66
|
-
pollId,
|
|
67
|
-
inclusionProof,
|
|
68
|
-
pollJoiningZkey: artifacts.zKey as unknown as string,
|
|
69
|
-
pollWasm: artifacts.wasm as unknown as string,
|
|
70
|
-
sgDataArg: DEFAULT_SG_DATA,
|
|
71
|
-
ivcpDataArg: DEFAULT_IVCP_DATA,
|
|
72
|
-
blocksPerBatch: 1000,
|
|
73
|
-
});
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
This is not really efficient, as we are using the user RPC to fetch events, which can be quite slow and prone to errors. A better approach is to use a Subgraph to fetch the events.
|
|
77
|
-
|
|
78
|
-
Option 2: Fetch the MACI keys using a subgraph and reconstruct the state tree locally.
|
|
79
|
-
|
|
80
|
-
1. Deploy the subgraph - instructions [here](/guides/subgraph)
|
|
81
|
-
2. Fetch the MACI keys
|
|
82
|
-
|
|
83
|
-
```typescript
|
|
84
|
-
import { MaciSubgraph } from "@maci-protocol/sdk/browser";
|
|
85
|
-
|
|
86
|
-
const subgraph = new MaciSubgraph("https://api.studio.thegraph.com/query/x/maci/version/latest");
|
|
87
|
-
|
|
88
|
-
const keys = await subgraph.getKeys();
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
3. Generate the merkle tree
|
|
92
|
-
|
|
93
|
-
```typescript
|
|
94
|
-
import { generateSignUpTreeFromKeys } from "@maci-protocol/sdk/browser";
|
|
95
|
-
|
|
96
|
-
const signUpTree = generateSignUpTreeFromKeys(keys);
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
4. Generate the inclusion proof - you will need to know the index of the user's public key in the merkle tree
|
|
100
|
-
|
|
101
|
-
```typescript
|
|
102
|
-
const inclusionProof = signUpTree.generateProof(publicKeyIndex);
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
5. Generate the zk-SNARK proof and join the poll
|
|
106
|
-
|
|
107
|
-
```typescript
|
|
108
|
-
import { joinPoll } from "@maci-protocol/sdk/browser";
|
|
109
|
-
|
|
110
|
-
const joinedPollData = await joinPoll({
|
|
111
|
-
maciAddress: PUBLIC_MACI_ADDRESS,
|
|
112
|
-
privateKey: maciKeypair.privateKey.serialize(),
|
|
113
|
-
signer,
|
|
114
|
-
pollId,
|
|
115
|
-
inclusionProof,
|
|
116
|
-
pollJoiningZkey: artifacts.zKey as unknown as string,
|
|
117
|
-
pollWasm: artifacts.wasm as unknown as string,
|
|
118
|
-
sgDataArg: DEFAULT_SG_DATA,
|
|
119
|
-
ivcpDataArg: DEFAULT_IVCP_DATA,
|
|
120
|
-
});
|
|
121
|
-
```
|