Skip to content

Commit 07d6402

Browse files
authored
Readme updates (#17)
* Update readme with config for Vite and Next js * Update Readme for example project * Update Readme to library update * Resolve indentation in readme * Update Readme PR Fix
1 parent bd0d5ce commit 07d6402

File tree

2 files changed

+87
-23
lines changed

2 files changed

+87
-23
lines changed

README.md

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ interface ZKState {
3535
const { useInitZkStore, useZKStore, useGetLatestProof } =
3636
createZKState<ZKState>(
3737
// replace './zkStatesWorker.ts` with the path to the previously defined web worker
38-
new Worker(new URL("./zkStatesWorker.ts", import.meta.url)),
38+
new Worker(new URL("./zkStatesWorker.ts", import.meta.url),{
39+
type:"module",
40+
}),
3941

4042
// zustand state definition https://github.com/pmndrs/zustand
4143
(set) => ({
@@ -48,8 +50,82 @@ const { useInitZkStore, useZKStore, useGetLatestProof } =
4850
num: state.num + 1,
4951
};
5052
}),
51-
})
53+
}),
54+
// Define state properties that should trigger proof generation when mutated.
55+
// You can define assertions in the Actions so that the proofs are generated based only on VALID STATE TRANSITIONS
56+
["num"]
5257
);
5358
```
5459

55-
<!-- TODO: properly document functions -->
60+
## Configuring your project
61+
62+
ZkStates leverages SnarkyJS to enable proof generation in the browser. to enable SnarkyJS for the web, we must set the COOP and COEP headers. When using a Vite project we also need to install a plugin to enable topLevelAwait for the web worker.
63+
64+
### Next.js
65+
66+
Open `next.config.js` and make sure you add these two configs.
67+
68+
```ts
69+
const nextConfig = {
70+
webpack(config) {
71+
config.resolve.alias = {
72+
...config.resolve.alias,
73+
snarkyjs: require('path').resolve('node_modules/snarkyjs')
74+
};
75+
config.experiments = { ...config.experiments, topLevelAwait: true };
76+
return config;
77+
},
78+
79+
async headers() {
80+
return [
81+
{
82+
source: '/(.*)',
83+
headers: [
84+
{
85+
key: 'Cross-Origin-Opener-Policy',
86+
value: 'same-origin',
87+
},
88+
{
89+
key: 'Cross-Origin-Embedder-Policy',
90+
value: 'require-corp',
91+
},
92+
],
93+
},
94+
];
95+
}
96+
};
97+
```
98+
### Vite React.js
99+
100+
add [vite-plugin-top-level-await](https://github.com/Menci/vite-plugin-top-level-await)
101+
102+
```sh
103+
# using npm
104+
npm install vite-plugin-top-level-await
105+
106+
# using yarn
107+
yarn add vite-plugin-top-level-await
108+
```
109+
After installing the Vite plugin open the `vite.config.ts` and add these two entries:
110+
111+
112+
```ts
113+
export default defineConfig({
114+
plugins: [
115+
topLevelAwait(),
116+
{
117+
name: "isolation",
118+
configureServer(server) {
119+
server.middlewares.use((_req, res, next) => {
120+
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
121+
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
122+
next();
123+
});
124+
},
125+
},
126+
],
127+
});
128+
```
129+
130+
131+
<!-- TODO: properly document functions -->

examples/tictactoe/README.md

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
1-
# React + TypeScript + Vite
1+
# TicTacToe Example project zkStates
22

3-
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
3+
This is an Example project that showcases the use of the zKState library.
44

5-
Currently, two official plugins are available:
5+
For every move made on the TicTacToe board a new proof is generated.
66

7-
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8-
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
7+
## To run the application
98

10-
## Expanding the ESLint configuration
9+
```sh
10+
# using yarn
11+
yarn
1112

12-
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
13+
yarn dev
1314

14-
- Configure the top-level `parserOptions` property like this:
15-
16-
```js
17-
parserOptions: {
18-
ecmaVersion: 'latest',
19-
sourceType: 'module',
20-
project: ['./tsconfig.json', './tsconfig.node.json'],
21-
tsconfigRootDir: __dirname,
22-
},
2315
```
24-
25-
- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
26-
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
27-
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list

0 commit comments

Comments
 (0)