Skip to content

Commit

Permalink
fix all lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
weboko committed Feb 16, 2024
1 parent 291189e commit 1802817
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 121 deletions.
32 changes: 16 additions & 16 deletions src/codec.spec.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import {
createDecoder,
createEncoder,
DecodedMessage,
DecodedMessage
} from "@waku/core/lib/message/version_0";
import type { IProtoMessage } from "@waku/interfaces";
import {
generatePrivateKey,
generateSymmetricKey,
getPublicKey,
getPublicKey
} from "@waku/message-encryption";
import {
createDecoder as createAsymDecoder,
createEncoder as createAsymEncoder,
createEncoder as createAsymEncoder
} from "@waku/message-encryption/ecies";
import {
createDecoder as createSymDecoder,
createEncoder as createSymEncoder,
createEncoder as createSymEncoder
} from "@waku/message-encryption/symmetric";
import { expect } from "chai";

import {
createRLNDecoder,
createRLNEncoder,
RLNDecoder,
RLNEncoder,
RLNEncoder
} from "./codec.js";
import { createRLN } from "./create.js";
import { RlnMessage } from "./message.js";
Expand All @@ -38,7 +38,7 @@ const EMPTY_PROTO_MESSAGE = {
ephemeral: undefined,
meta: undefined,
rateLimitProof: undefined,
version: undefined,
version: undefined
};

describe("RLN codec with version 0", () => {
Expand All @@ -54,11 +54,11 @@ describe("RLN codec with version 0", () => {
encoder: createEncoder({ contentTopic: TestContentTopic }),
rlnInstance,
index,
credential,
credential
});
const rlnDecoder = createRLNDecoder({
rlnInstance,
decoder: createDecoder(TestContentTopic),
decoder: createDecoder(TestContentTopic)
});

const bytes = await rlnEncoder.toWire({ payload });
Expand Down Expand Up @@ -139,7 +139,7 @@ describe("RLN codec with version 1", () => {
const rlnEncoder = new RLNEncoder(
createSymEncoder({
contentTopic: TestContentTopic,
symKey,
symKey
}),
rlnInstance,
index,
Expand Down Expand Up @@ -186,7 +186,7 @@ describe("RLN codec with version 1", () => {
const rlnEncoder = new RLNEncoder(
createSymEncoder({
contentTopic: TestContentTopic,
symKey,
symKey
}),
rlnInstance,
index,
Expand Down Expand Up @@ -233,7 +233,7 @@ describe("RLN codec with version 1", () => {
const rlnEncoder = new RLNEncoder(
createAsymEncoder({
contentTopic: TestContentTopic,
publicKey,
publicKey
}),
rlnInstance,
index,
Expand Down Expand Up @@ -281,7 +281,7 @@ describe("RLN codec with version 1", () => {
const rlnEncoder = new RLNEncoder(
createAsymEncoder({
contentTopic: TestContentTopic,
publicKey,
publicKey
}),
rlnInstance,
index,
Expand Down Expand Up @@ -384,11 +384,11 @@ describe("RLN codec with version 0 and meta setter", () => {
encoder: createEncoder({ contentTopic: TestContentTopic, metaSetter }),
rlnInstance,
index,
credential,
credential
});
const rlnDecoder = createRLNDecoder({
rlnInstance,
decoder: createDecoder(TestContentTopic),
decoder: createDecoder(TestContentTopic)
});

const bytes = await rlnEncoder.toWire({ payload });
Expand All @@ -403,7 +403,7 @@ describe("RLN codec with version 0 and meta setter", () => {

const expectedMeta = metaSetter({
...EMPTY_PROTO_MESSAGE,
payload: protoResult!.payload,
payload: protoResult!.payload
});

expect(msg!.meta).to.deep.eq(expectedMeta);
Expand Down Expand Up @@ -449,7 +449,7 @@ describe("RLN codec with version 0 and meta setter", () => {

const expectedMeta = metaSetter({
...EMPTY_PROTO_MESSAGE,
payload: msg!.payload,
payload: msg!.payload
});

expect(msg!.meta).to.deep.eq(expectedMeta);
Expand Down
7 changes: 5 additions & 2 deletions src/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
IEncoder,
IMessage,
IProtoMessage,
IRateLimitProof,
IRateLimitProof
} from "@waku/interfaces";
import debug from "debug";

Expand Down Expand Up @@ -86,7 +86,10 @@ export const createRLNEncoder = (options: RLNEncoderOptions): RLNEncoder => {
export class RLNDecoder<T extends IDecodedMessage>
implements IDecoder<RlnMessage<T>>
{
constructor(private rlnInstance: RLNInstance, private decoder: IDecoder<T>) {}
constructor(
private rlnInstance: RLNInstance,
private decoder: IDecoder<T>
) {}

get pubsubTopic(): string {
return this.decoder.pubsubTopic;
Expand Down
6 changes: 3 additions & 3 deletions src/contract/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const RLN_REGISTRY_ABI = [
"function transferOwnership(address newOwner)",
"function upgradeTo(address newImplementation)",
"function upgradeToAndCall(address newImplementation, bytes data) payable",
"function usingStorageIndex() view returns (uint16)",
"function usingStorageIndex() view returns (uint16)"
];

// ref https://github.com/waku-org/waku-rln-contract/blob/19fded82bca07e7b535b429dc507cfb83f10dfcf/deployments/sepolia/WakuRlnStorage_0.json#L3
Expand Down Expand Up @@ -58,11 +58,11 @@ export const RLN_STORAGE_ABI = [
"function transferOwnership(address newOwner)",
"function verifier() view returns (address)",
"function withdraw() pure",
"function withdrawalBalance(address) view returns (uint256)",
"function withdrawalBalance(address) view returns (uint256)"
];

export const SEPOLIA_CONTRACT = {
chainId: 11155111,
address: "0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4",
abi: RLN_REGISTRY_ABI,
abi: RLN_REGISTRY_ABI
};
16 changes: 8 additions & 8 deletions src/contract/rln_contract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ describe("RLN Contract abstraction", () => {
const voidSigner = new ethers.VoidSigner(SEPOLIA_CONTRACT.address);
const rlnContract = new RLNContract(rlnInstance, {
registryAddress: SEPOLIA_CONTRACT.address,
signer: voidSigner,
signer: voidSigner
});

rlnContract["storageContract"] = {
queryFilter: () => Promise.resolve([mockEvent()]),
queryFilter: () => Promise.resolve([mockEvent()])
} as unknown as ethers.Contract;
rlnContract["_membersFilter"] = {
address: "",
topics: [],
topics: []
} as unknown as ethers.EventFilter;

await rlnContract.fetchMembers(rlnInstance);
Expand All @@ -43,17 +43,17 @@ describe("RLN Contract abstraction", () => {
const voidSigner = new ethers.VoidSigner(SEPOLIA_CONTRACT.address);
const rlnContract = new RLNContract(rlnInstance, {
registryAddress: SEPOLIA_CONTRACT.address,
signer: voidSigner,
signer: voidSigner
});

rlnContract["storageIndex"] = 1;
rlnContract["_membersFilter"] = {
address: "",
topics: [],
topics: []
} as unknown as ethers.EventFilter;
rlnContract["registryContract"] = {
"register(uint16,uint256)": () =>
Promise.resolve({ wait: () => Promise.resolve(undefined) }),
Promise.resolve({ wait: () => Promise.resolve(undefined) })
} as unknown as ethers.Contract;
const contractSpy = chai.spy.on(
rlnContract["registryContract"],
Expand All @@ -72,7 +72,7 @@ function mockEvent(): ethers.Event {
return {
args: {
idCommitment: { _hex: "0xb3df1c4e5600ef2b" },
index: ethers.BigNumber.from(1),
},
index: ethers.BigNumber.from(1)
}
} as unknown as ethers.Event;
}
15 changes: 9 additions & 6 deletions src/contract/rln_contract.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { hexToBytes } from "@waku/utils/bytes";
import debug from "debug";
import { ethers } from "ethers";

import type { IdentityCredential } from "../identity.js";
Expand All @@ -9,6 +10,8 @@ import { zeroPadLE } from "../utils/index.js";

import { RLN_REGISTRY_ABI, RLN_STORAGE_ABI } from "./constants.js";

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

type Member = {
idCommitment: string;
index: ethers.BigNumber;
Expand Down Expand Up @@ -130,7 +133,7 @@ export class RLNContract {
const registeredMemberEvents = await queryFilter(this.contract, {
fromBlock: this.deployBlock,
...options,
membersFilter: this.membersFilter,
membersFilter: this.membersFilter
});
this.processEvents(rlnInstance, registeredMemberEvents);
}
Expand Down Expand Up @@ -185,7 +188,7 @@ export class RLNContract {
rlnInstance.zerokit.insertMember(idCommitment);
this._members.set(index.toNumber(), {
index,
idCommitment: _idCommitment?._hex,
idCommitment: _idCommitment?._hex
});
});

Expand Down Expand Up @@ -254,8 +257,8 @@ export class RLNContract {
membership: {
address,
treeIndex: membershipId,
chainId: network.chainId,
},
chainId: network.chainId
}
};
}

Expand All @@ -280,7 +283,7 @@ async function queryFilter(
fromBlock,
membersFilter,
fetchRange = BLOCK_RANGE,
fetchChunks = FETCH_CHUNK,
fetchChunks = FETCH_CHUNK
} = options;

if (!fromBlock) {
Expand Down Expand Up @@ -346,7 +349,7 @@ function* takeN<T>(array: T[], size: number): Iterable<T[]> {

function ignoreErrors<T>(promise: Promise<T>, defaultValue: T): Promise<T> {
return promise.catch((err) => {
console.error(`Ignoring an error during query: ${err?.message}`);
log(`Ignoring an error during query: ${err?.message}`);
return defaultValue;
});
}
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RLNDecoder, RLNEncoder } from "./codec.js";
import {
RLN_REGISTRY_ABI,
RLN_STORAGE_ABI,
SEPOLIA_CONTRACT,
SEPOLIA_CONTRACT
} from "./contract/index.js";
import { RLNContract } from "./contract/index.js";
import { createRLN } from "./create.js";
Expand All @@ -26,5 +26,5 @@ export {
RLN_STORAGE_ABI,
RLN_REGISTRY_ABI,
SEPOLIA_CONTRACT,
extractMetaMaskSigner,
extractMetaMaskSigner
};
2 changes: 1 addition & 1 deletion src/keystore/cipher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { keccak256 } from "ethereum-cryptography/keccak";
import {
bytesToHex,
concatBytes,
hexToBytes,
hexToBytes
} from "ethereum-cryptography/utils";

import type { Keccak256Hash, Password } from "./types.js";
Expand Down
Loading

0 comments on commit 1802817

Please sign in to comment.