@waku/rln 0.0.13 → 0.0.14-88a28a1

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 CHANGED
@@ -1,9 +1,34 @@
1
- # js-rln
1
+ # `@waku/rln`
2
2
 
3
- Browser library providing the cryptographic functions for Waku RLN Relay
4
- https://rfc.vac.dev/spec/17/
3
+ This browser library enables the usage of RLN with Waku, as specified in the [Waku v2 RLN Relay RFC](https://rfc.vac.dev/spec/17/).
5
4
 
6
- ### Install
5
+ ## Purpose
6
+
7
+ ### RLN Cryptography
8
+
9
+ The RLN cryptographic function are provided by [zerokit](https://github.com/vacp2p/zerokit/).
10
+ This is imported via the `@waku/zerokit-rln-wasm` dependencies which contains a WASM extract of zerokit's RLN functions.
11
+
12
+ Note that RLN Credentials generated with `zerokit`, and hence `@waku/rln`, are compatible with semaphore credentials.
13
+
14
+ Note that the WASM blob uses browser APIs, **NodeJS is not supported**.
15
+
16
+ ### Waku Interfaces
17
+
18
+ This library implements the [`IEncoder`](https://github.com/waku-org/js-waku/blob/604ba1a889f1994bd27f5749107c3a5b2ef490d5/packages/interfaces/src/message.ts#L43)
19
+ and [`IDecoder`](https://github.com/waku-org/js-waku/blob/604ba1a889f1994bd27f5749107c3a5b2ef490d5/packages/interfaces/src/message.ts#L58)
20
+ interfaces of [js-waku](https://github.com/waku-org/js-waku).
21
+
22
+ This enables a seamless usage with js-waku applications, as demonstrated in the [rln-js example](https://github.com/waku-org/js-waku-examples/tree/master/examples/rln-js).
23
+
24
+ ### Comparison to Existing Work
25
+
26
+ [Rate-Limiting-Nullifier/rlnjs](https://github.com/Rate-Limiting-Nullifier/rlnjs)
27
+ is an existing JavaScript / TypeScript library that already provides RLN cryptographic functionalities for the browser.
28
+
29
+ The core difference is that `@waku/rln` uses [zerokit](https://github.com/vacp2p/zerokit/) for cryptography and provide opinionated interfaces to use RLN specifically in the context of Waku.
30
+
31
+ ## Install
7
32
 
8
33
  ```
9
34
  npm install @waku/rln
@@ -13,7 +38,15 @@ npm install @waku/rln
13
38
  yarn add @waku/rln
14
39
  ```
15
40
 
16
- ### Running example app
41
+ Or to use ESM import directly from a `<script>` tag:
42
+
43
+ ```html
44
+ <script type="module">
45
+ import * as rln from "https://unpkg.com/@waku/rln@0.0.13/bundle/index.js";
46
+ </script>
47
+ ```
48
+
49
+ ## Running example app
17
50
 
18
51
  ```
19
52
  git clone https://github.com/waku-org/js-rln
@@ -23,40 +56,41 @@ cd js-rln/example
23
56
  npm install # or yarn
24
57
 
25
58
  npm start
26
-
27
59
  ```
28
60
 
29
61
  Browse http://localhost:8080 and open the dev tools console to see the proof being generated and its verification
30
62
 
31
- ### Usage
63
+ ## Usage
32
64
 
33
- #### Initializing the library
65
+ ### Initializing the Library
34
66
 
35
67
  ```js
36
68
  import * as rln from "@waku/rln";
37
69
 
38
- const rlnInstance = wait rln.create();
70
+ const rlnInstance = await rln.create();
39
71
  ```
40
72
 
41
- #### Generating RLN membership keypair
73
+ ### Generating RLN Membership Keypair
42
74
 
43
75
  ```js
44
76
  let memKeys = rlnInstance.generateMembershipKey();
45
77
  ```
46
78
 
47
- #### Generating RLN membership keypair using a seed
79
+ ### Generating RLN Membership Keypair Using a Seed
80
+
81
+ This can be used to generate credentials from a signature hash (e.g. signed by an Ethereum account).
48
82
 
49
83
  ```js
50
84
  let memKeys = rlnInstance.generateSeededMembershipKey(seed);
51
85
  ```
52
86
 
53
- #### Adding membership keys into merkle tree
87
+ ### Adding Membership Keys Into Merkle Tree
54
88
 
55
89
  ```js
56
90
  rlnInstance.insertMember(memKeys.IDCommitment);
57
91
  ```
58
92
 
59
- #### Generating a proof
93
+ ### Generating a Proof
60
94
 
61
95
  ```js
62
96
  // prepare the message
@@ -76,22 +110,23 @@ const proof = await rlnInstance.generateProof(
76
110
  );
77
111
  ```
78
112
 
79
- #### Verifying a proof
113
+ ### Verifying a Proof
80
114
 
81
115
  ```js
82
116
  try {
83
117
  // verify the proof
84
- const verificationResult = rlnInstance.verifyProof(proof);
118
+ const verificationResult = rlnInstance.verifyProof(proof, uint8Msg);
85
119
  console.log("Is proof verified?", verificationResult ? "yes" : "no");
86
120
  } catch (err) {
87
121
  console.log("Invalid proof");
88
122
  }
89
123
  ```
90
124
 
91
- ### Updating circuit, verification key and zkey
125
+ ### Updating Circuit, Verification Key and Zkey
92
126
 
93
- The RLN specs defines the defaults. These values are fixed and should not
94
- change. Currently, these [resources](https://github.com/vacp2p/zerokit/tree/master/rln/resources/tree_height_20) are being used.
127
+ The RLN specs defines the defaults.
128
+ These values are fixed and should not change.
129
+ Currently, these [resources](https://github.com/vacp2p/zerokit/tree/master/rln/resources/tree_height_20) are being used.
95
130
  If they change, this file needs to be updated in `resources.ts` which
96
131
  contains these values encoded in base64 in this format:
97
132
 
@@ -104,9 +139,9 @@ export {verification_key, circuit, zkey};
104
139
 
105
140
  A tool like GNU's `base64` could be used to encode this data.
106
141
 
107
- ### Updating zerokit
142
+ ### Updating Zerokit
108
143
 
109
- 1. Make sure you have nodejs installed and a C compiler
144
+ 1. Make sure you have NodeJS installed and a C compiler
110
145
  2. Install wasm-pack
111
146
 
112
147
  ```
@@ -137,6 +172,6 @@ Licensed and distributed under either of
137
172
 
138
173
  or
139
174
 
140
- - Apache License, Version 2.0, ([LICENSE-APACHEv2](LICENSE-APACHEv2) or http://www.apache.org/licenses/LICENSE-2.0)
175
+ - Apache License, Version 2.0, ([LICENSE-APACHE-v2](LICENSE-APACHE-v2) or http://www.apache.org/licenses/LICENSE-2.0)
141
176
 
142
177
  at your option. These files may not be copied, modified, or distributed except according to those terms.