mirror of
https://github.com/logos-messaging/js-rln.git
synced 2026-01-02 13:43:06 +00:00
chore: tests setup (#13)
This commit is contained in:
parent
af3dc15d82
commit
2cbbbf3690
@ -2,7 +2,7 @@
|
|||||||
"version": "0.1",
|
"version": "0.1",
|
||||||
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json",
|
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json",
|
||||||
"language": "en",
|
"language": "en",
|
||||||
"words": ["Waku"],
|
"words": ["Waku", "keypair", "merkle", "zkey", "circom", "zerokit"],
|
||||||
"flagWords": [],
|
"flagWords": [],
|
||||||
"ignorePaths": [
|
"ignorePaths": [
|
||||||
"package.json",
|
"package.json",
|
||||||
@ -13,7 +13,8 @@
|
|||||||
"build",
|
"build",
|
||||||
"gen",
|
"gen",
|
||||||
"proto",
|
"proto",
|
||||||
"*.spec.ts"
|
"*.spec.ts",
|
||||||
|
"src/resources.ts"
|
||||||
],
|
],
|
||||||
"patterns": [
|
"patterns": [
|
||||||
{
|
{
|
||||||
|
|||||||
@ -44,7 +44,7 @@ let memKeys = rlnInstance.generateMembershipKey();
|
|||||||
|
|
||||||
#### Adding membership keys into merkle tree
|
#### Adding membership keys into merkle tree
|
||||||
```js
|
```js
|
||||||
rlnInstance.inserMember(memKeys.IDCommitment);
|
rlnInstance.insertMember(memKeys.IDCommitment);
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Generating a proof
|
#### Generating a proof
|
||||||
@ -63,8 +63,8 @@ const proof = await rlnInstance.generateProof(uint8Msg, index, epoch, memKeys.ID
|
|||||||
```js
|
```js
|
||||||
try {
|
try {
|
||||||
// verify the proof
|
// verify the proof
|
||||||
const verifResult = rlnInstance.verifyProof(proof);
|
const verificationResult = rlnInstance.verifyProof(proof);
|
||||||
console.log("Is proof verified?", verifResult ? "yes" : "no");
|
console.log("Is proof verified?", verificationResult ? "yes" : "no");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("Invalid proof")
|
console.log("Invalid proof")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,11 +10,11 @@ rln.create().then(async rlnInstance => {
|
|||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
if (i == index) {
|
if (i == index) {
|
||||||
// insert the current peer's pk
|
// insert the current peer's pk
|
||||||
rlnInstance.inserMember(memKeys.IDCommitment);
|
rlnInstance.insertMember(memKeys.IDCommitment);
|
||||||
} else {
|
} else {
|
||||||
// create a new key pair
|
// create a new key pair
|
||||||
let memKeys = rlnInstance.generateMembershipKey(); // TODO: handle error
|
let memKeys = rlnInstance.generateMembershipKey(); // TODO: handle error
|
||||||
rlnInstance.inserMember(memKeys.IDCommitment);
|
rlnInstance.insertMember(memKeys.IDCommitment);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
4
example/package-lock.json
generated
4
example/package-lock.json
generated
@ -19,7 +19,7 @@
|
|||||||
},
|
},
|
||||||
"..": {
|
"..": {
|
||||||
"name": "@waku/rln",
|
"name": "@waku/rln",
|
||||||
"version": "0.0.4",
|
"version": "0.0.5",
|
||||||
"license": "MIT OR Apache-2.0",
|
"license": "MIT OR Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@waku/zerokit-rln-wasm": "^0.0.1"
|
"@waku/zerokit-rln-wasm": "^0.0.1"
|
||||||
@ -49,6 +49,7 @@
|
|||||||
"eslint-plugin-import": "^2.25.3",
|
"eslint-plugin-import": "^2.25.3",
|
||||||
"eslint-plugin-prettier": "^4.0.0",
|
"eslint-plugin-prettier": "^4.0.0",
|
||||||
"fast-check": "^2.14.0",
|
"fast-check": "^2.14.0",
|
||||||
|
"file-loader": "^6.2.0",
|
||||||
"gh-pages": "^3.2.3",
|
"gh-pages": "^3.2.3",
|
||||||
"husky": "^7.0.4",
|
"husky": "^7.0.4",
|
||||||
"ignore-loader": "^0.1.2",
|
"ignore-loader": "^0.1.2",
|
||||||
@ -70,6 +71,7 @@
|
|||||||
"rollup-plugin-copy": "^3.4.0",
|
"rollup-plugin-copy": "^3.4.0",
|
||||||
"size-limit": "^8.0.0",
|
"size-limit": "^8.0.0",
|
||||||
"tail": "^2.2.0",
|
"tail": "^2.2.0",
|
||||||
|
"ts-jest": "^29.0.1",
|
||||||
"ts-loader": "^9.3.1",
|
"ts-loader": "^9.3.1",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"typedoc": "^0.23.10",
|
"typedoc": "^0.23.10",
|
||||||
|
|||||||
@ -9,7 +9,6 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
experiments: {
|
experiments: {
|
||||||
asyncWebAssembly: true,
|
asyncWebAssembly: true,
|
||||||
syncWebAssembly: true
|
|
||||||
},
|
},
|
||||||
mode: "development",
|
mode: "development",
|
||||||
plugins: [
|
plugins: [
|
||||||
|
|||||||
@ -1,13 +1,32 @@
|
|||||||
process.env.CHROME_BIN = require("puppeteer").executablePath();
|
process.env.CHROME_BIN = require("puppeteer").executablePath();
|
||||||
const webpack = require("webpack");
|
|
||||||
|
const os = require("os");
|
||||||
|
const path = require("path");
|
||||||
|
const ResolveTypeScriptPlugin = require("resolve-typescript-plugin");
|
||||||
|
|
||||||
|
const output = {
|
||||||
|
path:
|
||||||
|
path.join(os.tmpdir(), "_karma_webpack_") +
|
||||||
|
Math.floor(Math.random() * 1000000),
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = function (config) {
|
module.exports = function (config) {
|
||||||
config.set({
|
config.set({
|
||||||
frameworks: ["webpack", "mocha"],
|
frameworks: ["webpack", "mocha"],
|
||||||
files: ["src/**/!(node).spec.ts"],
|
|
||||||
preprocessors: {
|
preprocessors: {
|
||||||
"src/**/!(node).spec.ts": ["webpack"],
|
"**/*.ts": ["webpack"],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
files: [
|
||||||
|
"src/**/*.spec.ts",
|
||||||
|
"src/**/*.ts",
|
||||||
|
{
|
||||||
|
pattern: `${output.path}/**/*`,
|
||||||
|
watched: false,
|
||||||
|
included: false,
|
||||||
|
served: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
envPreprocessor: ["CI"],
|
envPreprocessor: ["CI"],
|
||||||
reporters: ["progress"],
|
reporters: ["progress"],
|
||||||
browsers: ["ChromeHeadless"],
|
browsers: ["ChromeHeadless"],
|
||||||
@ -19,37 +38,30 @@ module.exports = function (config) {
|
|||||||
},
|
},
|
||||||
webpack: {
|
webpack: {
|
||||||
mode: "production",
|
mode: "production",
|
||||||
|
resolve: {
|
||||||
|
// Add `.ts` and `.tsx` as a resolvable extension.
|
||||||
|
extensions: [".ts", ".tsx", ".js"],
|
||||||
|
plugins: [new ResolveTypeScriptPlugin()],
|
||||||
|
},
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
test: /\.(js|tsx?)$/,
|
test: /\.wasm$/,
|
||||||
use: [
|
type: "asset/resource",
|
||||||
{
|
|
||||||
loader: "ts-loader",
|
|
||||||
options: { configFile: "tsconfig.karma.json" },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
exclude: /(node_modules)|(node\.spec\.ts)/,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /node\.spec\.ts$/,
|
test: /\.(js|tsx?)$/,
|
||||||
use: "ignore-loader",
|
loader: "ts-loader",
|
||||||
|
exclude: /node_modules|\.d\.ts$/,
|
||||||
|
options: { configFile: "tsconfig.karma.json" },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.d\.ts$/,
|
||||||
|
loader: "ignore-loader",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
plugins: [
|
output,
|
||||||
new webpack.DefinePlugin({
|
|
||||||
"process.env.CI": process.env.CI || false,
|
|
||||||
}),
|
|
||||||
new webpack.ProvidePlugin({
|
|
||||||
process: "process/browser.js",
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
resolve: {
|
|
||||||
extensions: [".ts", ".js"],
|
|
||||||
},
|
|
||||||
stats: { warnings: false },
|
|
||||||
devtool: "inline-source-map",
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
64
package-lock.json
generated
64
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@waku/rln",
|
"name": "@waku/rln",
|
||||||
"version": "0.0.4",
|
"version": "0.0.5",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@waku/rln",
|
"name": "@waku/rln",
|
||||||
"version": "0.0.4",
|
"version": "0.0.5",
|
||||||
"license": "MIT OR Apache-2.0",
|
"license": "MIT OR Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@waku/zerokit-rln-wasm": "^0.0.1"
|
"@waku/zerokit-rln-wasm": "^0.0.1"
|
||||||
@ -53,6 +53,7 @@
|
|||||||
"prettier": "^2.1.1",
|
"prettier": "^2.1.1",
|
||||||
"process": "^0.11.10",
|
"process": "^0.11.10",
|
||||||
"puppeteer": "^13.0.1",
|
"puppeteer": "^13.0.1",
|
||||||
|
"resolve-typescript-plugin": "^1.2.0",
|
||||||
"rollup": "^2.75.0",
|
"rollup": "^2.75.0",
|
||||||
"rollup-plugin-copy": "^3.4.0",
|
"rollup-plugin-copy": "^3.4.0",
|
||||||
"size-limit": "^8.0.0",
|
"size-limit": "^8.0.0",
|
||||||
@ -3621,6 +3622,20 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
|
"node_modules/fsevents": {
|
||||||
|
"version": "2.3.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
|
||||||
|
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
|
||||||
|
"dev": true,
|
||||||
|
"hasInstallScript": true,
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"darwin"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/function-bind": {
|
"node_modules/function-bind": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
@ -6492,6 +6507,27 @@
|
|||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/resolve-typescript-plugin": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/resolve-typescript-plugin/-/resolve-typescript-plugin-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-f0tu3fDdKcSmbgpLDNBKiMYPPG7D19tYCnph9B7GIlMMIWnbiLjAqqPXZVeO3POQSNF7ZYK4Ox+Gmvo116ERWQ==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"tslib": "2.3.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^12 || ^14 || >=16"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"webpack": "^4.0.0 || ^5.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/resolve-typescript-plugin/node_modules/tslib": {
|
||||||
|
"version": "2.3.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz",
|
||||||
|
"integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"node_modules/restore-cursor": {
|
"node_modules/restore-cursor": {
|
||||||
"version": "3.1.0",
|
"version": "3.1.0",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
@ -10630,6 +10666,13 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"fsevents": {
|
||||||
|
"version": "2.3.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
|
||||||
|
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
|
||||||
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
"function-bind": {
|
"function-bind": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"dev": true
|
"dev": true
|
||||||
@ -12438,6 +12481,23 @@
|
|||||||
"global-dirs": "^0.1.1"
|
"global-dirs": "^0.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"resolve-typescript-plugin": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/resolve-typescript-plugin/-/resolve-typescript-plugin-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-f0tu3fDdKcSmbgpLDNBKiMYPPG7D19tYCnph9B7GIlMMIWnbiLjAqqPXZVeO3POQSNF7ZYK4Ox+Gmvo116ERWQ==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"tslib": "2.3.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"tslib": {
|
||||||
|
"version": "2.3.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz",
|
||||||
|
"integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==",
|
||||||
|
"dev": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"restore-cursor": {
|
"restore-cursor": {
|
||||||
"version": "3.1.0",
|
"version": "3.1.0",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@waku/rln",
|
"name": "@waku/rln",
|
||||||
"version": "0.0.5",
|
"version": "0.0.6",
|
||||||
"description": "Rate Limit Nullifier for js-waku",
|
"description": "Rate Limit Nullifier for js-waku",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
@ -34,8 +34,7 @@
|
|||||||
"test:lint": "eslint src --ext .ts",
|
"test:lint": "eslint src --ext .ts",
|
||||||
"test:prettier": "prettier \"src/**/*.ts\" \"./*.json\" \"*.*js\" \".github/**/*.yml\" --list-different",
|
"test:prettier": "prettier \"src/**/*.ts\" \"./*.json\" \"*.*js\" \".github/**/*.yml\" --list-different",
|
||||||
"test:spelling": "cspell \"{*.md,.github/*.md,src/**/*.ts}\"",
|
"test:spelling": "cspell \"{*.md,.github/*.md,src/**/*.ts}\"",
|
||||||
"test:tsc": "tsc -p tsconfig.dev.json",
|
"test:tsc": "tsc",
|
||||||
"test:node": "TS_NODE_PROJECT=./tsconfig.dev.json mocha",
|
|
||||||
"test:browser": "karma start karma.conf.cjs",
|
"test:browser": "karma start karma.conf.cjs",
|
||||||
"watch:build": "tsc -p tsconfig.json -w",
|
"watch:build": "tsc -p tsconfig.json -w",
|
||||||
"watch:test": "mocha --watch",
|
"watch:test": "mocha --watch",
|
||||||
@ -94,6 +93,7 @@
|
|||||||
"prettier": "^2.1.1",
|
"prettier": "^2.1.1",
|
||||||
"process": "^0.11.10",
|
"process": "^0.11.10",
|
||||||
"puppeteer": "^13.0.1",
|
"puppeteer": "^13.0.1",
|
||||||
|
"resolve-typescript-plugin": "^1.2.0",
|
||||||
"rollup": "^2.75.0",
|
"rollup": "^2.75.0",
|
||||||
"rollup-plugin-copy": "^3.4.0",
|
"rollup-plugin-copy": "^3.4.0",
|
||||||
"size-limit": "^8.0.0",
|
"size-limit": "^8.0.0",
|
||||||
|
|||||||
9
src/index.spec.ts
Normal file
9
src/index.spec.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import * as rln from "./index";
|
||||||
|
|
||||||
|
describe("Waku Filter", () => {
|
||||||
|
it("test", async function () {
|
||||||
|
const rlnInstance = await rln.create();
|
||||||
|
console.log(rlnInstance.generateMembershipKey());
|
||||||
|
// TODO: write test
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -6,7 +6,6 @@ export async function create(): Promise<RLNInstance> {
|
|||||||
// asynchronously. This file does the single async import, so
|
// asynchronously. This file does the single async import, so
|
||||||
// that no one else needs to worry about it again.
|
// that no one else needs to worry about it again.
|
||||||
const rlnModule = await import("./rln.js");
|
const rlnModule = await import("./rln.js");
|
||||||
|
|
||||||
return await rlnModule.create();
|
return await rlnModule.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -168,7 +168,7 @@ export class RLNInstance {
|
|||||||
return new MembershipKey(memKeys);
|
return new MembershipKey(memKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
inserMember(idCommitment: Uint8Array): void {
|
insertMember(idCommitment: Uint8Array): void {
|
||||||
zerokitRLN.insertMember(this.zkRLN, idCommitment);
|
zerokitRLN.insertMember(this.zkRLN, idCommitment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user