@waku/rln 0.0.12 → 0.0.13-d77370f
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 +37 -16
- package/bundle/assets/{rln_wasm_bg-a7027f94.wasm → rln_wasm_bg-4d82d6a4.wasm} +0 -0
- package/bundle/index.js +22916 -371
- package/dist/.tsbuildinfo +1 -1
- package/dist/codec.js +3 -1
- package/dist/codec.js.map +1 -1
- package/dist/constants.d.ts +7 -0
- package/dist/constants.js +14 -0
- package/dist/constants.js.map +1 -0
- package/dist/epoch.js +10 -3
- package/dist/epoch.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/message.d.ts +1 -0
- package/dist/message.js +5 -0
- package/dist/message.js.map +1 -1
- package/dist/rln.d.ts +4 -1
- package/dist/rln.js +30 -2
- package/dist/rln.js.map +1 -1
- package/dist/rln_contract.d.ts +24 -0
- package/dist/rln_contract.js +50 -0
- package/dist/rln_contract.js.map +1 -0
- package/package.json +5 -2
- package/src/codec.ts +3 -3
- package/src/constants.ts +14 -0
- package/src/epoch.ts +12 -3
- package/src/index.ts +13 -2
- package/src/message.ts +9 -0
- package/src/rln.ts +44 -2
- package/src/rln_contract.ts +104 -0
package/README.md
CHANGED
@@ -4,6 +4,7 @@ Browser library providing the cryptographic functions for Waku RLN Relay
|
|
4
4
|
https://rfc.vac.dev/spec/17/
|
5
5
|
|
6
6
|
### Install
|
7
|
+
|
7
8
|
```
|
8
9
|
npm install @waku/rln
|
9
10
|
|
@@ -13,6 +14,7 @@ yarn add @waku/rln
|
|
13
14
|
```
|
14
15
|
|
15
16
|
### Running example app
|
17
|
+
|
16
18
|
```
|
17
19
|
git clone https://github.com/waku-org/js-rln
|
18
20
|
|
@@ -26,10 +28,10 @@ npm start
|
|
26
28
|
|
27
29
|
Browse http://localhost:8080 and open the dev tools console to see the proof being generated and its verification
|
28
30
|
|
29
|
-
|
30
31
|
### Usage
|
31
32
|
|
32
33
|
#### Initializing the library
|
34
|
+
|
33
35
|
```js
|
34
36
|
import * as rln from "@waku/rln";
|
35
37
|
|
@@ -37,45 +39,60 @@ const rlnInstance = wait rln.create();
|
|
37
39
|
```
|
38
40
|
|
39
41
|
#### Generating RLN membership keypair
|
42
|
+
|
40
43
|
```js
|
41
44
|
let memKeys = rlnInstance.generateMembershipKey();
|
42
45
|
```
|
43
46
|
|
47
|
+
#### Generating RLN membership keypair using a seed
|
48
|
+
|
49
|
+
```js
|
50
|
+
let memKeys = rlnInstance.generateSeededMembershipKey(seed);
|
51
|
+
```
|
44
52
|
|
45
53
|
#### Adding membership keys into merkle tree
|
54
|
+
|
46
55
|
```js
|
47
56
|
rlnInstance.insertMember(memKeys.IDCommitment);
|
48
57
|
```
|
49
58
|
|
50
59
|
#### Generating a proof
|
60
|
+
|
51
61
|
```js
|
52
62
|
// prepare the message
|
53
|
-
const uint8Msg = Uint8Array.from(
|
63
|
+
const uint8Msg = Uint8Array.from(
|
64
|
+
"Hello World".split("").map((x) => x.charCodeAt())
|
65
|
+
);
|
54
66
|
|
55
67
|
// setting up the epoch (With 0s for the test)
|
56
68
|
const epoch = new Uint8Array(32);
|
57
69
|
|
58
70
|
// generating a proof
|
59
|
-
const proof = await rlnInstance.generateProof(
|
71
|
+
const proof = await rlnInstance.generateProof(
|
72
|
+
uint8Msg,
|
73
|
+
index,
|
74
|
+
epoch,
|
75
|
+
memKeys.IDKey
|
76
|
+
);
|
60
77
|
```
|
61
78
|
|
62
79
|
#### Verifying a proof
|
80
|
+
|
63
81
|
```js
|
64
82
|
try {
|
65
|
-
|
66
|
-
|
67
|
-
|
83
|
+
// verify the proof
|
84
|
+
const verificationResult = rlnInstance.verifyProof(proof);
|
85
|
+
console.log("Is proof verified?", verificationResult ? "yes" : "no");
|
68
86
|
} catch (err) {
|
69
|
-
|
87
|
+
console.log("Invalid proof");
|
70
88
|
}
|
71
89
|
```
|
72
90
|
|
73
|
-
|
74
|
-
|
75
91
|
### Updating circuit, verification key and zkey
|
92
|
+
|
76
93
|
The RLN specs defines the defaults. These values are fixed and should not
|
77
94
|
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
|
95
|
+
If they change, this file needs to be updated in `resources.ts` which
|
79
96
|
contains these values encoded in base64 in this format:
|
80
97
|
|
81
98
|
```
|
@@ -85,37 +102,41 @@ const zkey = "...";
|
|
85
102
|
export {verification_key, circuit, zkey};
|
86
103
|
```
|
87
104
|
|
88
|
-
A tool like GNU's `base64` could be used to encode this data.
|
105
|
+
A tool like GNU's `base64` could be used to encode this data.
|
89
106
|
|
90
107
|
### Updating zerokit
|
108
|
+
|
91
109
|
1. Make sure you have nodejs installed and a C compiler
|
92
110
|
2. Install wasm-pack
|
111
|
+
|
93
112
|
```
|
94
113
|
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
95
114
|
```
|
115
|
+
|
96
116
|
3. Compile RLN for wasm
|
117
|
+
|
97
118
|
```
|
98
119
|
git clone https://github.com/vacp2p/zerokit
|
99
120
|
cd zerokit/rln-wasm
|
100
121
|
wasm-pack build --release
|
101
122
|
```
|
102
|
-
4. Copy `pkg/rln*` into `src/zerokit`
|
103
123
|
|
124
|
+
4. Copy `pkg/rln*` into `src/zerokit`
|
104
125
|
|
105
126
|
## Bugs, Questions & Features
|
106
127
|
|
107
128
|
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
129
|
|
109
|
-
For more general discussion, help and latest news,
|
110
|
-
|
130
|
+
For more general discussion, help and latest news, join [Vac Discord](https://discord.gg/PQFdubGt6d) or [Telegram](https://t.me/vacp2p).
|
111
131
|
|
112
132
|
## License
|
133
|
+
|
113
134
|
Licensed and distributed under either of
|
114
135
|
|
115
|
-
|
136
|
+
- MIT license: [LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT
|
116
137
|
|
117
138
|
or
|
118
139
|
|
119
|
-
|
140
|
+
- Apache License, Version 2.0, ([LICENSE-APACHEv2](LICENSE-APACHEv2) or http://www.apache.org/licenses/LICENSE-2.0)
|
120
141
|
|
121
142
|
at your option. These files may not be copied, modified, or distributed except according to those terms.
|
Binary file
|