@waku/rln 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # js-rln
2
+
3
+ Browser library providing the cryptographic functions for Waku RLN Relay
4
+ https://rfc.vac.dev/spec/17/
5
+
6
+ ### Install
7
+ ```
8
+ npm install @waku/rln
9
+
10
+ # or with yarn
11
+
12
+ yarn add @waku/rln
13
+ ```
14
+
15
+ ### Running example app
16
+ ```
17
+ git clone https://github.com/waku-org/js-rln
18
+
19
+ cd js-rln/example
20
+
21
+ npm install # or yarn
22
+
23
+ npm start
24
+
25
+ ```
26
+
27
+ Browse http://localhost:8080 and open the dev tools console to see the proof being generated and its verification
28
+
29
+
30
+ ### Usage
31
+
32
+ #### Initializing the library
33
+ ```js
34
+ import * as rln from "@waku/rln";
35
+
36
+ const rlnInstance = wait rln.create();
37
+ ```
38
+
39
+ #### Generating RLN membership keypair
40
+ ```js
41
+ let memKeys = rlnInstance.generateMembershipKey();
42
+ ```
43
+
44
+
45
+ #### Adding membership keys into merkle tree
46
+ ```js
47
+ rlnInstance.inserMember(memKeys.IDCommitment);
48
+ ```
49
+
50
+ #### Generating a proof
51
+ ```js
52
+ // prepare the message
53
+ const uint8Msg = Uint8Array.from("Hello World".split("").map(x => x.charCodeAt()));
54
+
55
+ // setting up the epoch (With 0s for the test)
56
+ const epoch = new Uint8Array(32);
57
+
58
+ // generating a proof
59
+ const proof = await rlnInstance.generateProof(uint8Msg, index, epoch, memKeys.IDKey)
60
+ ```
61
+
62
+ #### Verifying a proof
63
+ ```js
64
+ try {
65
+ // verify the proof
66
+ const verifResult = rlnInstance.verifyProof(proof);
67
+ console.log("Is proof verified?", verifResult ? "yes" : "no");
68
+ } catch (err) {
69
+ console.log("Invalid proof")
70
+ }
71
+ ```
72
+
73
+
74
+
75
+ ### Updating circuit, verification key and zkey
76
+ The RLN specs defines the defaults. These values are fixed and should not
77
+ change. Currently, these [resources](https://github.com/vacp2p/zerokit/tree/master/rln/resources/tree_height_20) are being used.
78
+ If they change, this file needs to be updated in `resources.ts` which
79
+ contains these values encoded in base64 in this format:
80
+
81
+ ```
82
+ const verification_key = "...";
83
+ const circuit = "..."; // wasm file generated by circom
84
+ const zkey = "...";
85
+ export {verification_key, circuit, zkey};
86
+ ```
87
+
88
+ A tool like GNU's `base64` could be used to encode this data.
89
+
90
+ ### Updating zerokit
91
+ 1. Make sure you have nodejs installed and a C compiler
92
+ 2. Install wasm-pack
93
+ ```
94
+ curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
95
+ ```
96
+ 3. Compile RLN for wasm
97
+ ```
98
+ git clone https://github.com/vacp2p/zerokit
99
+ cd zerokit/rln-wasm
100
+ wasm-pack build --release
101
+ ```
102
+ 4. Copy `pkg/rln*` into `src/zerokit`
103
+
104
+
105
+ ## Bugs, Questions & Features
106
+
107
+ If you encounter any bug or would like to propose new features, feel free to [open an issue](https://github.com/waku-org/js-rln/issues/new/).
108
+
109
+ For more general discussion, help and latest news, join [Vac Discord](https://discord.gg/PQFdubGt6d) or [Telegram](https://t.me/vacp2p).
110
+
111
+
112
+ ## License
113
+ Licensed and distributed under either of
114
+
115
+ * MIT license: [LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT
116
+
117
+ or
118
+
119
+ * Apache License, Version 2.0, ([LICENSE-APACHEv2](LICENSE-APACHEv2) or http://www.apache.org/licenses/LICENSE-2.0)
120
+
121
+ at your option. These files may not be copied, modified, or distributed except according to those terms.
Binary file
@@ -0,0 +1,10 @@
1
+ // reexport the create function, dynamically imported from rln.ts
2
+ async function create() {
3
+ // A dependency graph that contains any wasm must all be imported
4
+ // asynchronously. This file does the single async import, so
5
+ // that no one else needs to worry about it again.
6
+ const rlnModule = await import('./rln-f87f6dbe.js');
7
+ return await rlnModule.create();
8
+ }
9
+
10
+ export { create };