Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use identity credentials, and expose hash, bulk insert and delete members functions #58

Merged
merged 3 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,24 @@ import * as rln from "@waku/rln";
const rlnInstance = await rln.create();
```

### Generating RLN Membership Keypair
#### Generating RLN membership credentials
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting nitpick

Suggested change
#### Generating RLN membership credentials
#### Generating RLN Membership Credentials


```js
let memKeys = rlnInstance.generateMembershipKey();
let credentials = rlnInstance.generateIdentityCredentials();
```

### Generating RLN Membership Keypair Using a Seed

This can be used to generate credentials from a signature hash (e.g. signed by an Ethereum account).

```js
let memKeys = rlnInstance.generateSeededMembershipKey(seed);
let credentials = rlnInstance.generateSeededIdentityCredentials(seed);
```

### Adding Membership Keys Into Merkle Tree

```js
rlnInstance.insertMember(memKeys.IDCommitment);
rlnInstance.insertMember(credentials.IDCommitment);
```

### Generating a Proof
Expand All @@ -106,7 +106,7 @@ const proof = await rlnInstance.generateProof(
uint8Msg,
index,
epoch,
memKeys.IDKey
credentials.IDSecretHash
);
```

Expand Down
10 changes: 5 additions & 5 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as rln from "@waku/rln";

rln.create().then(async rlnInstance => {
let memKeys = rlnInstance.generateMembershipKey();
let credentials = rlnInstance.generateIdentityCredentials();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let credentials = rlnInstance.generateIdentityCredentials();
const credentials = rlnInstance.generateIdentityCredentials();

no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, didn't you/we said we could remove this example? cc @weboko

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was on js-noise, although I think we can remove it here too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before we were talking about noise's example.
We can remove that one but I'd keep it since it helps to test changes in one repo.


//peer's index in the Merkle Tree
const index = 5
Expand All @@ -10,11 +10,11 @@ rln.create().then(async rlnInstance => {
for (let i = 0; i < 10; i++) {
if (i == index) {
// insert the current peer's pk
rlnInstance.insertMember(memKeys.IDCommitment);
rlnInstance.insertMember(credentials.IDCommitment);
} else {
// create a new key pair
let memKeys = rlnInstance.generateMembershipKey(); // TODO: handle error
rlnInstance.insertMember(memKeys.IDCommitment);
let credentials = rlnInstance.generateIdentityCredentials(); // TODO: handle error
rlnInstance.insertMember(credentials.IDCommitment);

}
}
Expand All @@ -27,7 +27,7 @@ rln.create().then(async rlnInstance => {

console.log("Generating proof...");
console.time("proof_gen_timer");
let proof = await rlnInstance.generateRLNProof(uint8Msg, index, epoch, memKeys.IDKey)
let proof = await rlnInstance.generateRLNProof(uint8Msg, index, epoch, credentials.IDSecretHash)
console.timeEnd("proof_gen_timer");
console.log("Proof", proof)

Expand Down
3 changes: 2 additions & 1 deletion karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ module.exports = function (config) {
envPreprocessor: ["CI"],
reporters: ["progress"],
browsers: ["ChromeHeadless"],
pingTimeout: 60000,
singleRun: true,
client: {
mocha: {
timeout: 6000, // Default is 2s
timeout: 60000, // Default is 2s
},
},
webpack: {
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@waku/rln",
"version": "0.0.14",
"version": "0.1.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big bump :)
Probably time to sort out automated release management?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was thinking about it as well. I can duplicate from js-wakuto other repos or (just saying) we can move all waku libs to js-waku repo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think until we expect someone to use RLN in prod we leave it out. We can then reconsider when RLN is used beyond POCs

"description": "Rate Limit Nullifier for js-waku",
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
Expand Down Expand Up @@ -130,7 +130,7 @@
},
"dependencies": {
"@waku/utils": "^0.0.4",
"@waku/zerokit-rln-wasm": "^0.0.5",
"@waku/zerokit-rln-wasm": "^0.0.10",
"ethers": "^5.7.2"
}
}
42 changes: 21 additions & 21 deletions src/codec.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ const EMPTY_PUBSUB_TOPIC = "";
describe("RLN codec with version 0", () => {
it("toWire", async function () {
const rlnInstance = await rln.create();
const memKeys = rlnInstance.generateMembershipKey();
const credential = rlnInstance.generateIdentityCredentials();
const index = 0;
const payload = new Uint8Array([1, 2, 3, 4, 5]);

rlnInstance.insertMember(memKeys.IDCommitment);
rlnInstance.insertMember(credential.IDCommitment);

const rlnEncoder = createRLNEncoder({
encoder: createEncoder({ contentTopic: TestContentTopic }),
rlnInstance,
index,
membershipKey: memKeys,
credential,
});
const rlnDecoder = createRLNDecoder({
rlnInstance,
Expand Down Expand Up @@ -76,17 +76,17 @@ describe("RLN codec with version 0", () => {

it("toProtoObj", async function () {
const rlnInstance = await rln.create();
const memKeys = rlnInstance.generateMembershipKey();
const credential = rlnInstance.generateIdentityCredentials();
const index = 0;
const payload = new Uint8Array([1, 2, 3, 4, 5]);

rlnInstance.insertMember(memKeys.IDCommitment);
rlnInstance.insertMember(credential.IDCommitment);

const rlnEncoder = new RLNEncoder(
createEncoder({ contentTopic: TestContentTopic }),
rlnInstance,
index,
memKeys
credential
);
const rlnDecoder = new RLNDecoder(
rlnInstance,
Expand Down Expand Up @@ -119,11 +119,11 @@ describe("RLN codec with version 0", () => {
describe("RLN codec with version 1", () => {
it("Symmetric, toWire", async function () {
const rlnInstance = await rln.create();
const memKeys = rlnInstance.generateMembershipKey();
const credential = rlnInstance.generateIdentityCredentials();
const index = 0;
const payload = new Uint8Array([1, 2, 3, 4, 5]);

rlnInstance.insertMember(memKeys.IDCommitment);
rlnInstance.insertMember(credential.IDCommitment);

const symKey = generateSymmetricKey();

Expand All @@ -134,7 +134,7 @@ describe("RLN codec with version 1", () => {
}),
rlnInstance,
index,
memKeys
credential
);
const rlnDecoder = new RLNDecoder(
rlnInstance,
Expand Down Expand Up @@ -166,11 +166,11 @@ describe("RLN codec with version 1", () => {

it("Symmetric, toProtoObj", async function () {
const rlnInstance = await rln.create();
const memKeys = rlnInstance.generateMembershipKey();
const credential = rlnInstance.generateIdentityCredentials();
const index = 0;
const payload = new Uint8Array([1, 2, 3, 4, 5]);

rlnInstance.insertMember(memKeys.IDCommitment);
rlnInstance.insertMember(credential.IDCommitment);

const symKey = generateSymmetricKey();

Expand All @@ -181,7 +181,7 @@ describe("RLN codec with version 1", () => {
}),
rlnInstance,
index,
memKeys
credential
);
const rlnDecoder = new RLNDecoder(
rlnInstance,
Expand Down Expand Up @@ -212,11 +212,11 @@ describe("RLN codec with version 1", () => {

it("Asymmetric, toWire", async function () {
const rlnInstance = await rln.create();
const memKeys = rlnInstance.generateMembershipKey();
const credential = rlnInstance.generateIdentityCredentials();
const index = 0;
const payload = new Uint8Array([1, 2, 3, 4, 5]);

rlnInstance.insertMember(memKeys.IDCommitment);
rlnInstance.insertMember(credential.IDCommitment);

const privateKey = generatePrivateKey();
const publicKey = getPublicKey(privateKey);
Expand All @@ -228,7 +228,7 @@ describe("RLN codec with version 1", () => {
}),
rlnInstance,
index,
memKeys
credential
);
const rlnDecoder = new RLNDecoder(
rlnInstance,
Expand Down Expand Up @@ -260,11 +260,11 @@ describe("RLN codec with version 1", () => {

it("Asymmetric, toProtoObj", async function () {
const rlnInstance = await rln.create();
const memKeys = rlnInstance.generateMembershipKey();
const credential = rlnInstance.generateIdentityCredentials();
const index = 0;
const payload = new Uint8Array([1, 2, 3, 4, 5]);

rlnInstance.insertMember(memKeys.IDCommitment);
rlnInstance.insertMember(credential.IDCommitment);

const privateKey = generatePrivateKey();
const publicKey = getPublicKey(privateKey);
Expand All @@ -276,7 +276,7 @@ describe("RLN codec with version 1", () => {
}),
rlnInstance,
index,
memKeys
credential
);
const rlnDecoder = new RLNDecoder(
rlnInstance,
Expand Down Expand Up @@ -309,17 +309,17 @@ describe("RLN codec with version 1", () => {
describe("RLN Codec - epoch", () => {
it("toProtoObj", async function () {
const rlnInstance = await rln.create();
const memKeys = rlnInstance.generateMembershipKey();
const credential = rlnInstance.generateIdentityCredentials();
const index = 0;
const payload = new Uint8Array([1, 2, 3, 4, 5]);

rlnInstance.insertMember(memKeys.IDCommitment);
rlnInstance.insertMember(credential.IDCommitment);

const rlnEncoder = new RLNEncoder(
createEncoder({ contentTopic: TestContentTopic }),
rlnInstance,
index,
memKeys
credential
);
const rlnDecoder = new RLNDecoder(
rlnInstance,
Expand Down
14 changes: 7 additions & 7 deletions src/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ import type {
import debug from "debug";

import { RlnMessage, toRLNSignal } from "./message.js";
import { MembershipKey, RLNInstance } from "./rln.js";
import { IdentityCredential, RLNInstance } from "./rln.js";

const log = debug("waku:rln:encoder");

export class RLNEncoder implements IEncoder {
private readonly idKey: Uint8Array;
private readonly idSecretHash: Uint8Array;

constructor(
private encoder: IEncoder,
private rlnInstance: RLNInstance,
private index: number,
membershipKey: MembershipKey
identityCredential: IdentityCredential
) {
if (index < 0) throw "invalid membership index";
this.idKey = membershipKey.IDKey;
this.idSecretHash = identityCredential.IDSecretHash;
}

async toWire(message: IMessage): Promise<Uint8Array | undefined> {
Expand All @@ -50,7 +50,7 @@ export class RLNEncoder implements IEncoder {
signal,
this.index,
message.timestamp,
this.idKey
this.idSecretHash
);
console.timeEnd("proof_gen_timer");
return proof;
Expand All @@ -69,15 +69,15 @@ type RLNEncoderOptions = {
encoder: IEncoder;
rlnInstance: RLNInstance;
index: number;
membershipKey: MembershipKey;
credential: IdentityCredential;
};

export const createRLNEncoder = (options: RLNEncoderOptions): RLNEncoder => {
return new RLNEncoder(
options.encoder,
options.rlnInstance,
options.index,
options.membershipKey
options.credential
);
};

Expand Down
Loading