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: deterministic message hashing #1233

Merged
merged 5 commits into from
May 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"packages/utils": "0.0.4",
"packages/proto": "0.0.4",
"packages/interfaces": "0.0.11",
"packages/message-hash": "0.1.0",
"packages/enr": "0.0.10",
"packages/peer-exchange": "0.0.9",
"packages/core": "0.0.16",
Expand Down
5 changes: 5 additions & 0 deletions .size-limit.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ module.exports = [
path: "packages/core/bundle/index.js",
import: "{ wakuStore }",
},
{
name: "Deterministic Message Hashing",
path: "packages/message-hash/bundle/index.js",
import: "{ messageHash }",
},
];
94 changes: 94 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"packages/interfaces",
"packages/enr",
"packages/core",
"packages/message-hash",
"packages/peer-exchange",
"packages/dns-discovery",
"packages/message-encryption",
Expand Down
6 changes: 6 additions & 0 deletions packages/message-hash/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
parserOptions: {
tsconfigRootDir: __dirname,
project: "./tsconfig.dev.json",
},
};
11 changes: 11 additions & 0 deletions packages/message-hash/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extension": ["ts"],
"spec": "src/**/*.spec.ts",
"require": ["ts-node/register", "isomorphic-fetch"],
"loader": "ts-node/esm",
"node-option": [
"experimental-specifier-resolution=node",
"loader=ts-node/esm"
],
"exit": true
}
5 changes: 5 additions & 0 deletions packages/message-hash/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build
bundle
dist
node_modules
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add CHANGELOG to ignore

CHANGELOG.md
26 changes: 26 additions & 0 deletions packages/message-hash/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[![NPM](https://nodei.co/npm/@waku/message-hash.png)](https://npmjs.org/package/@waku/message-hash)

![GitHub Action](https://img.shields.io/github/workflow/status/waku-org/js-waku/CI)
[![Discord chat](https://img.shields.io/discord/864066763682218004.svg?logo=discord&colorB=7289DA)](https://discord.gg/Nrac59MfSX)

# @waku/message-hash

TypeScript implementation of the _Deterministic Message Hashing_ as specified in [14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/).

See [JS-Waku README](https://github.com/waku-org/js-waku) for more information.

## Contributing

See [CONTRIBUTING.md](https://github.com/waku-org/js-waku/blob/master/CONTRIBUTING.md).

## License

Licensed and distributed under either of

- MIT license: [LICENSE-MIT](https://github.com/waku-org/js-waku/blob/master/LICENSE-MIT) or http://opensource.org/licenses/MIT

or

- Apache License, Version 2.0, ([LICENSE-APACHE-v2](https://github.com/waku-org/js-waku/blob/master/LICENSE-APACHE-v2) or http://www.apache.org/licenses/LICENSE-2.0)

at your option. These files may not be copied, modified, or distributed except according to those terms.
45 changes: 45 additions & 0 deletions packages/message-hash/karma.conf.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
process.env.CHROME_BIN = require("puppeteer").executablePath();
const webpack = require("webpack");

module.exports = function (config) {
config.set({
frameworks: ["webpack", "mocha"],
files: ["src/**/!(node).spec.ts"],
preprocessors: {
"src/**/!(node).spec.ts": ["webpack"],
},
envPreprocessor: ["CI"],
reporters: ["progress"],
browsers: ["ChromeHeadless"],
singleRun: true,
client: {
mocha: {
timeout: 6000, // Default is 2s
},
},
webpack: {
mode: "development",
module: {
rules: [{ test: /\.([cm]?ts|tsx)$/, loader: "ts-loader" }],
},
plugins: [
new webpack.DefinePlugin({
"process.env.CI": process.env.CI || false,
}),
new webpack.ProvidePlugin({
process: "process/browser.js",
}),
],
resolve: {
extensions: [".ts", ".tsx", ".js"],
extensionAlias: {
".js": [".js", ".ts"],
".cjs": [".cjs", ".cts"],
".mjs": [".mjs", ".mts"],
},
},
stats: { warnings: false },
devtool: "inline-source-map",
},
});
};
108 changes: 108 additions & 0 deletions packages/message-hash/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"name": "@waku/message-hash",
"version": "0.1.0",
"description": "TypeScript implementation of the Deterministic Message Hashing as specified in 14/WAKU2-MESSAGE",
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
}
},
"type": "module",
"homepage": "https://github.com/waku-org/js-waku/tree/master/packages/message-hash#readme",
"repository": {
"type": "git",
"url": "https://github.com/waku-org/js-waku.git"
},
"bugs": {
"url": "https://github.com/waku-org/js-waku/issues"
},
"license": "MIT OR Apache-2.0",
"keywords": [
"waku",
"decentralised",
"communication",
"web3",
"ethereum",
"dapps"
],
"scripts": {
"build": "run-s build:**",
"build:esm": "tsc",
"build:bundle": "rollup --config rollup.config.js",
"fix": "run-s fix:*",
"fix:prettier": "prettier . --write",
"fix:lint": "eslint src *.js --fix",
"check": "run-s check:*",
"check:tsc": "tsc -p tsconfig.dev.json",
"check:lint": "eslint src *.js",
"check:prettier": "prettier . --list-different",
"check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
"test": "run-s test:*",
"test:node": "TS_NODE_PROJECT=./tsconfig.dev.json mocha",
"test:browser": "karma start karma.conf.cjs",
"watch:build": "tsc -p tsconfig.json -w",
"watch:test": "mocha --watch",
"prepublish": "npm run build",
"reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build"
},
"engines": {
"node": ">=16"
},
"dependencies": {
"@noble/hashes": "^1.2.0",
"@waku/utils": "*"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@types/chai": "^4.3.4",
"@types/debug": "^4.1.7",
"@types/mocha": "^10.0.1",
"@typescript-eslint/eslint-plugin": "^5.54.1",
"@typescript-eslint/parser": "^5.51.0",
"@waku/build-utils": "*",
"@waku/interfaces": "*",
"chai": "^4.3.7",
"cspell": "^6.28.0",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-functional": "^5.0.4",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"fast-check": "^3.7.0",
"ignore-loader": "^0.1.2",
"isomorphic-fetch": "^3.0.0",
"karma": "^6.4.1",
"karma-chrome-launcher": "^3.1.1",
"karma-mocha": "^2.0.1",
"karma-webpack": "^5.0.0",
"mocha": "^10.2.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.4",
"process": "^0.11.10",
"puppeteer": "^19.7.2",
"rollup": "^3.15.0",
"ts-loader": "^9.4.2",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
},
"typedoc": {
"entryPoint": "./src/index.ts"
},
"files": [
"dist",
"bundle",
"src/*.ts",
"src/lib/**/*.ts",
"!**/*.spec.*",
"!**/*.json",
"CHANGELOG.md",
"LICENSE",
"README.md"
]
}
24 changes: 24 additions & 0 deletions packages/message-hash/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import { extractExports } from "@waku/build-utils";

import * as packageJson from "./package.json" assert { type: "json" };

const input = extractExports(packageJson);

export default {
input,
output: {
dir: "bundle",
format: "esm",
},
plugins: [
commonjs(),
json(),
nodeResolve({
browser: true,
preferBuiltins: false,
}),
],
};
Loading