From 453085245e0ed419987a665de14445d3199b0352 Mon Sep 17 00:00:00 2001 From: Sasha Date: Wed, 24 Jan 2024 20:59:00 +0100 Subject: [PATCH] update README, fix tests --- README.md | 22 +++++++++++++++++++++- src/codec.spec.ts | 18 +++++++++--------- src/index.spec.ts | 6 +++--- src/rln_contract.spec.ts | 4 ++-- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 9c58302..87eb2a5 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,16 @@ Browse http://localhost:8080 and open the dev tools console to see the proof bei ```js import * as rln from "@waku/rln"; -const rlnInstance = await rln.create(); +const rlnInstance = await rln.createRLN(); +``` + +### Starting RLN to listen to a contract + +```js +import * as rln from "@waku/rln"; + +const rlnInstance = await rln.createRLN(); +await rlnInstance.start(); // will use default Sepolia contract ``` #### Generating RLN Membership Credentials @@ -94,6 +103,17 @@ let credentials = rlnInstance.generateSeededIdentityCredentials(seed); rlnInstance.insertMember(credentials.IDCommitment); ``` +### Registering Membership on a contract + +```js +import * as rln from "@waku/rln"; + +const rlnInstance = await rln.createRLN(); +await rlnInstance.start(); // will use default Sepolia contract + +const membershipInfo = await rlnInstance.contract.registerWithKey(credentials); +``` + ### Generating a Proof ```js diff --git a/src/codec.spec.ts b/src/codec.spec.ts index 5f6249f..a707b4b 100644 --- a/src/codec.spec.ts +++ b/src/codec.spec.ts @@ -44,7 +44,7 @@ const EMPTY_PROTO_MESSAGE = { describe("RLN codec with version 0", () => { it("toWire", async function () { - const rlnInstance = await rln.create(); + const rlnInstance = await rln.createRLN(); const credential = rlnInstance.generateIdentityCredentials(); const index = 0; const payload = new Uint8Array([1, 2, 3, 4, 5]); @@ -85,7 +85,7 @@ describe("RLN codec with version 0", () => { }); it("toProtoObj", async function () { - const rlnInstance = await rln.create(); + const rlnInstance = await rln.createRLN(); const credential = rlnInstance.generateIdentityCredentials(); const index = 0; const payload = new Uint8Array([1, 2, 3, 4, 5]); @@ -128,7 +128,7 @@ describe("RLN codec with version 0", () => { describe("RLN codec with version 1", () => { it("Symmetric, toWire", async function () { - const rlnInstance = await rln.create(); + const rlnInstance = await rln.createRLN(); const credential = rlnInstance.generateIdentityCredentials(); const index = 0; const payload = new Uint8Array([1, 2, 3, 4, 5]); @@ -175,7 +175,7 @@ describe("RLN codec with version 1", () => { }); it("Symmetric, toProtoObj", async function () { - const rlnInstance = await rln.create(); + const rlnInstance = await rln.createRLN(); const credential = rlnInstance.generateIdentityCredentials(); const index = 0; const payload = new Uint8Array([1, 2, 3, 4, 5]); @@ -221,7 +221,7 @@ describe("RLN codec with version 1", () => { }); it("Asymmetric, toWire", async function () { - const rlnInstance = await rln.create(); + const rlnInstance = await rln.createRLN(); const credential = rlnInstance.generateIdentityCredentials(); const index = 0; const payload = new Uint8Array([1, 2, 3, 4, 5]); @@ -269,7 +269,7 @@ describe("RLN codec with version 1", () => { }); it("Asymmetric, toProtoObj", async function () { - const rlnInstance = await rln.create(); + const rlnInstance = await rln.createRLN(); const credential = rlnInstance.generateIdentityCredentials(); const index = 0; const payload = new Uint8Array([1, 2, 3, 4, 5]); @@ -318,7 +318,7 @@ describe("RLN codec with version 1", () => { describe("RLN Codec - epoch", () => { it("toProtoObj", async function () { - const rlnInstance = await rln.create(); + const rlnInstance = await rln.createRLN(); const credential = rlnInstance.generateIdentityCredentials(); const index = 0; const payload = new Uint8Array([1, 2, 3, 4, 5]); @@ -374,7 +374,7 @@ describe("RLN codec with version 0 and meta setter", () => { }; it("toWire", async function () { - const rlnInstance = await rln.create(); + const rlnInstance = await rln.createRLN(); const credential = rlnInstance.generateIdentityCredentials(); const index = 0; const payload = new Uint8Array([1, 2, 3, 4, 5]); @@ -422,7 +422,7 @@ describe("RLN codec with version 0 and meta setter", () => { }); it("toProtoObj", async function () { - const rlnInstance = await rln.create(); + const rlnInstance = await rln.createRLN(); const credential = rlnInstance.generateIdentityCredentials(); const index = 0; const payload = new Uint8Array([1, 2, 3, 4, 5]); diff --git a/src/index.spec.ts b/src/index.spec.ts index 30f5fea..25a78cd 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -4,7 +4,7 @@ import * as rln from "./index.js"; describe("js-rln", () => { it("should verify a proof", async function () { - const rlnInstance = await rln.create(); + const rlnInstance = await rln.createRLN(); const credential = rlnInstance.generateIdentityCredentials(); @@ -59,7 +59,7 @@ describe("js-rln", () => { } }); it("should verify a proof with a seeded membership key generation", async function () { - const rlnInstance = await rln.create(); + const rlnInstance = await rln.createRLN(); const seed = "This is a test seed"; const credential = rlnInstance.generateSeededIdentityCredential(seed); @@ -115,7 +115,7 @@ describe("js-rln", () => { }); it("should generate the same membership key if the same seed is provided", async function () { - const rlnInstance = await rln.create(); + const rlnInstance = await rln.createRLN(); const seed = "This is a test seed"; const memKeys1 = rlnInstance.generateSeededIdentityCredential(seed); const memKeys2 = rlnInstance.generateSeededIdentityCredential(seed); diff --git a/src/rln_contract.spec.ts b/src/rln_contract.spec.ts index 05c2737..7116e9b 100644 --- a/src/rln_contract.spec.ts +++ b/src/rln_contract.spec.ts @@ -8,7 +8,7 @@ chai.use(spies); describe("RLN Contract abstraction", () => { it("should be able to fetch members from events and store to rln instance", async () => { - const rlnInstance = await rln.create(); + const rlnInstance = await rln.createRLN(); rlnInstance.insertMember = () => undefined; const insertMemberSpy = chai.spy.on(rlnInstance, "insertMember"); @@ -36,7 +36,7 @@ describe("RLN Contract abstraction", () => { const mockSignature = "0xdeb8a6b00a8e404deb1f52d3aa72ed7f60a2ff4484c737eedaef18a0aacb2dfb4d5d74ac39bb71fa358cf2eb390565a35b026cc6272f2010d4351e17670311c21c"; - const rlnInstance = await rln.create(); + const rlnInstance = await rln.createRLN(); const voidSigner = new ethers.VoidSigner(rln.SEPOLIA_CONTRACT.address); const rlnContract = new rln.RLNContract(rlnInstance, { registryAddress: rln.SEPOLIA_CONTRACT.address,