From 76d1d4faf5d6ec7b8c366187cb64a7fe05582fdf Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Fri, 10 Mar 2023 15:50:24 +1100 Subject: [PATCH 1/5] chore: new empty message-hash package --- package-lock.json | 86 ++++++++++++++++++++ package.json | 1 + packages/message-hash/.eslintrc.cjs | 6 ++ packages/message-hash/.mocharc.json | 11 +++ packages/message-hash/.prettierignore | 4 + packages/message-hash/README.md | 26 ++++++ packages/message-hash/karma.conf.cjs | 45 +++++++++++ packages/message-hash/package.json | 103 ++++++++++++++++++++++++ packages/message-hash/rollup.config.js | 24 ++++++ packages/message-hash/src/index.ts | 0 packages/message-hash/tsconfig.dev.json | 3 + packages/message-hash/tsconfig.json | 10 +++ release-please-config.json | 1 + 13 files changed, 320 insertions(+) create mode 100644 packages/message-hash/.eslintrc.cjs create mode 100644 packages/message-hash/.mocharc.json create mode 100644 packages/message-hash/.prettierignore create mode 100644 packages/message-hash/README.md create mode 100644 packages/message-hash/karma.conf.cjs create mode 100644 packages/message-hash/package.json create mode 100644 packages/message-hash/rollup.config.js create mode 100644 packages/message-hash/src/index.ts create mode 100644 packages/message-hash/tsconfig.dev.json create mode 100644 packages/message-hash/tsconfig.json diff --git a/package-lock.json b/package-lock.json index 50270ea3fb..b9c200f05d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "packages/interfaces", "packages/enr", "packages/core", + "packages/message-hash", "packages/peer-exchange", "packages/dns-discovery", "packages/message-encryption", @@ -6107,6 +6108,10 @@ "resolved": "packages/message-encryption", "link": true }, + "node_modules/@waku/message-hash": { + "resolved": "packages/message-hash", + "link": true + }, "node_modules/@waku/peer-exchange": { "resolved": "packages/peer-exchange", "link": true @@ -29587,6 +29592,49 @@ "node": ">=16" } }, + "packages/message-hash": { + "name": "@waku/message-hash", + "version": "0.0.10", + "license": "MIT OR Apache-2.0", + "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": "*", + "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" + }, + "engines": { + "node": ">=16" + } + }, "packages/peer-exchange": { "name": "@waku/peer-exchange", "version": "0.0.9", @@ -34673,6 +34721,44 @@ "typescript": "^4.9.5" } }, + "@waku/message-hash": { + "version": "file:packages/message-hash", + "requires": { + "@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": "*", + "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" + } + }, "@waku/peer-exchange": { "version": "file:packages/peer-exchange", "requires": { diff --git a/package.json b/package.json index 77b7033cc4..23bd821123 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "packages/interfaces", "packages/enr", "packages/core", + "packages/message-hash", "packages/peer-exchange", "packages/dns-discovery", "packages/message-encryption", diff --git a/packages/message-hash/.eslintrc.cjs b/packages/message-hash/.eslintrc.cjs new file mode 100644 index 0000000000..324f1f526d --- /dev/null +++ b/packages/message-hash/.eslintrc.cjs @@ -0,0 +1,6 @@ +module.exports = { + parserOptions: { + tsconfigRootDir: __dirname, + project: "./tsconfig.dev.json", + }, +}; diff --git a/packages/message-hash/.mocharc.json b/packages/message-hash/.mocharc.json new file mode 100644 index 0000000000..8b0b97b620 --- /dev/null +++ b/packages/message-hash/.mocharc.json @@ -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 +} diff --git a/packages/message-hash/.prettierignore b/packages/message-hash/.prettierignore new file mode 100644 index 0000000000..fecb37a393 --- /dev/null +++ b/packages/message-hash/.prettierignore @@ -0,0 +1,4 @@ +build +bundle +dist +node_modules diff --git a/packages/message-hash/README.md b/packages/message-hash/README.md new file mode 100644 index 0000000000..4d936787a5 --- /dev/null +++ b/packages/message-hash/README.md @@ -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. diff --git a/packages/message-hash/karma.conf.cjs b/packages/message-hash/karma.conf.cjs new file mode 100644 index 0000000000..20d52e751f --- /dev/null +++ b/packages/message-hash/karma.conf.cjs @@ -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/lib/**/!(node).spec.ts"], + preprocessors: { + "src/lib/**/!(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", + }, + }); +}; diff --git a/packages/message-hash/package.json b/packages/message-hash/package.json new file mode 100644 index 0000000000..b5b8ad05a1 --- /dev/null +++ b/packages/message-hash/package.json @@ -0,0 +1,103 @@ +{ + "name": "@waku/message-hash", + "version": "0.0.10", + "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" + }, + "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": "*", + "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" + ] +} diff --git a/packages/message-hash/rollup.config.js b/packages/message-hash/rollup.config.js new file mode 100644 index 0000000000..8af2ba4bd1 --- /dev/null +++ b/packages/message-hash/rollup.config.js @@ -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, + }), + ], +}; diff --git a/packages/message-hash/src/index.ts b/packages/message-hash/src/index.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/message-hash/tsconfig.dev.json b/packages/message-hash/tsconfig.dev.json new file mode 100644 index 0000000000..4f7c34af3c --- /dev/null +++ b/packages/message-hash/tsconfig.dev.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tsconfig.dev" +} diff --git a/packages/message-hash/tsconfig.json b/packages/message-hash/tsconfig.json new file mode 100644 index 0000000000..eebbc51585 --- /dev/null +++ b/packages/message-hash/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig", + "compilerOptions": { + "outDir": "dist/", + "rootDir": "src", + "tsBuildInfoFile": "dist/.tsbuildinfo" + }, + "include": ["src"], + "exclude": ["src/**/*.spec.ts", "src/test_utils"] +} diff --git a/release-please-config.json b/release-please-config.json index edb95e5272..116708d338 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -11,6 +11,7 @@ "packages/interfaces": {}, "packages/enr": {}, "packages/peer-exchange": {}, + "packages/message-hash": {}, "packages/core": {}, "packages/dns-discovery": {}, "packages/message-encryption": {}, From fe574613290875d1c142aa51c18641346208401d Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Mon, 13 Mar 2023 14:50:46 +1100 Subject: [PATCH 2/5] feat: implement deterministic message hash logic --- .release-please-manifest.json | 1 + .size-limit.cjs | 5 ++ package-lock.json | 10 +++- packages/message-hash/package.json | 7 ++- packages/message-hash/src/index.spec.ts | 68 +++++++++++++++++++++++++ packages/message-hash/src/index.ts | 33 ++++++++++++ release-please-config.json | 2 +- 7 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 packages/message-hash/src/index.spec.ts diff --git a/.release-please-manifest.json b/.release-please-manifest.json index e0a9768aa1..39f303fd5f 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -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", diff --git a/.size-limit.cjs b/.size-limit.cjs index c74ee498cd..8b277194ce 100644 --- a/.size-limit.cjs +++ b/.size-limit.cjs @@ -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 }", + }, ]; diff --git a/package-lock.json b/package-lock.json index b9c200f05d..e12185721f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,9 +9,9 @@ "packages/utils", "packages/proto", "packages/interfaces", + "packages/message-hash", "packages/enr", "packages/core", - "packages/message-hash", "packages/peer-exchange", "packages/dns-discovery", "packages/message-encryption", @@ -29596,6 +29596,10 @@ "name": "@waku/message-hash", "version": "0.0.10", "license": "MIT OR Apache-2.0", + "dependencies": { + "@noble/hashes": "^1.2.0", + "@waku/utils": "*" + }, "devDependencies": { "@rollup/plugin-commonjs": "^24.0.1", "@rollup/plugin-json": "^6.0.0", @@ -29606,6 +29610,7 @@ "@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", @@ -34724,6 +34729,7 @@ "@waku/message-hash": { "version": "file:packages/message-hash", "requires": { + "@noble/hashes": "^1.2.0", "@rollup/plugin-commonjs": "^24.0.1", "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-node-resolve": "^15.0.1", @@ -34733,6 +34739,8 @@ "@typescript-eslint/eslint-plugin": "^5.54.1", "@typescript-eslint/parser": "^5.51.0", "@waku/build-utils": "*", + "@waku/interfaces": "*", + "@waku/utils": "*", "chai": "^4.3.7", "cspell": "^6.28.0", "eslint": "^8.35.0", diff --git a/packages/message-hash/package.json b/packages/message-hash/package.json index b5b8ad05a1..2ec2476796 100644 --- a/packages/message-hash/package.json +++ b/packages/message-hash/package.json @@ -1,6 +1,6 @@ { "name": "@waku/message-hash", - "version": "0.0.10", + "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", @@ -51,6 +51,10 @@ "engines": { "node": ">=16" }, + "dependencies": { + "@noble/hashes": "^1.2.0", + "@waku/utils": "*" + }, "devDependencies": { "@rollup/plugin-commonjs": "^24.0.1", "@rollup/plugin-json": "^6.0.0", @@ -61,6 +65,7 @@ "@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", diff --git a/packages/message-hash/src/index.spec.ts b/packages/message-hash/src/index.spec.ts new file mode 100644 index 0000000000..d88a92af79 --- /dev/null +++ b/packages/message-hash/src/index.spec.ts @@ -0,0 +1,68 @@ +import type { IProtoMessage } from "@waku/interfaces"; +import { bytesToHex, hexToBytes } from "@waku/utils/bytes"; +import { expect } from "chai"; + +import { messageHash } from "./index.js"; + +// https://rfc.vac.dev/spec/14/#test-vectors +describe("RFC Test Vectors", () => { + it("Waku message hash computation", () => { + const expectedHash = + "4fdde1099c9f77f6dae8147b6b3179aba1fc8e14a7bf35203fc253ee479f135f"; + + const pubSubTopic = "/waku/2/default-waku/proto"; + const message: IProtoMessage = { + payload: hexToBytes("0x010203045445535405060708"), + contentTopic: "/waku/2/default-content/proto", + meta: hexToBytes("0x73757065722d736563726574"), + ephemeral: undefined, + rateLimitProof: undefined, + timestamp: undefined, + version: undefined, + }; + + const hash = messageHash(pubSubTopic, message); + + expect(bytesToHex(hash)).to.equal(expectedHash); + }); + + it("Waku message hash computation (meta attribute not present)", () => { + const expectedHash = + "87619d05e563521d9126749b45bd4cc2430df0607e77e23572d874ed9c1aaa62"; + + const pubSubTopic = "/waku/2/default-waku/proto"; + const message: IProtoMessage = { + payload: hexToBytes("0x010203045445535405060708"), + contentTopic: "/waku/2/default-content/proto", + meta: undefined, + ephemeral: undefined, + rateLimitProof: undefined, + timestamp: undefined, + version: undefined, + }; + + const hash = messageHash(pubSubTopic, message); + + expect(bytesToHex(hash)).to.equal(expectedHash); + }); + + it("Waku message hash computation (payload length 0)", () => { + const expectedHash = + "e1a9596237dbe2cc8aaf4b838c46a7052df6bc0d42ba214b998a8bfdbe8487d6"; + + const pubSubTopic = "/waku/2/default-waku/proto"; + const message: IProtoMessage = { + payload: new Uint8Array(), + contentTopic: "/waku/2/default-content/proto", + meta: hexToBytes("0x73757065722d736563726574"), + ephemeral: undefined, + rateLimitProof: undefined, + timestamp: undefined, + version: undefined, + }; + + const hash = messageHash(pubSubTopic, message); + + expect(bytesToHex(hash)).to.equal(expectedHash); + }); +}); diff --git a/packages/message-hash/src/index.ts b/packages/message-hash/src/index.ts index e69de29bb2..897f07d865 100644 --- a/packages/message-hash/src/index.ts +++ b/packages/message-hash/src/index.ts @@ -0,0 +1,33 @@ +import { sha256 } from "@noble/hashes/sha256"; +import type { IProtoMessage } from "@waku/interfaces"; +import { concat, utf8ToBytes } from "@waku/utils/bytes"; + +/** + * Deterministic Message Hashing as defined in + * [14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/#deterministic-message-hashing) + */ +export function messageHash( + pubsubTopic: string, + message: IProtoMessage +): Uint8Array { + const pubsubTopicBytes = utf8ToBytes(pubsubTopic); + const contentTopicBytes = utf8ToBytes(message.contentTopic); + + let bytesToHash; + + if (message.meta) { + bytesToHash = concat([ + pubsubTopicBytes, + message.payload, + contentTopicBytes, + message.meta, + ]); + } else { + bytesToHash = concat([ + pubsubTopicBytes, + message.payload, + contentTopicBytes, + ]); + } + return sha256(bytesToHash); +} diff --git a/release-please-config.json b/release-please-config.json index 116708d338..f9faf22ca7 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -9,9 +9,9 @@ "packages/utils": {}, "packages/proto": {}, "packages/interfaces": {}, + "packages/message-hash": {}, "packages/enr": {}, "packages/peer-exchange": {}, - "packages/message-hash": {}, "packages/core": {}, "packages/dns-discovery": {}, "packages/message-encryption": {}, From 71985038a2934057ac92db93477f34fb67ee22a1 Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Tue, 14 Mar 2023 11:38:59 +1100 Subject: [PATCH 3/5] test: fix karma config --- packages/message-hash/karma.conf.cjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/message-hash/karma.conf.cjs b/packages/message-hash/karma.conf.cjs index 20d52e751f..c189f3b1e1 100644 --- a/packages/message-hash/karma.conf.cjs +++ b/packages/message-hash/karma.conf.cjs @@ -4,9 +4,9 @@ const webpack = require("webpack"); module.exports = function (config) { config.set({ frameworks: ["webpack", "mocha"], - files: ["src/lib/**/!(node).spec.ts"], + files: ["src/**/!(node).spec.ts"], preprocessors: { - "src/lib/**/!(node).spec.ts": ["webpack"], + "src/**/!(node).spec.ts": ["webpack"], }, envPreprocessor: ["CI"], reporters: ["progress"], From c781e49e1ecd67efd1e8eb728c6995fa56edea71 Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Tue, 14 Mar 2023 15:27:47 +1100 Subject: [PATCH 4/5] chore: improve var name --- packages/message-hash/src/index.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/message-hash/src/index.ts b/packages/message-hash/src/index.ts index 897f07d865..7c5a8220b8 100644 --- a/packages/message-hash/src/index.ts +++ b/packages/message-hash/src/index.ts @@ -13,21 +13,17 @@ export function messageHash( const pubsubTopicBytes = utf8ToBytes(pubsubTopic); const contentTopicBytes = utf8ToBytes(message.contentTopic); - let bytesToHash; + let bytes; if (message.meta) { - bytesToHash = concat([ + bytes = concat([ pubsubTopicBytes, message.payload, contentTopicBytes, message.meta, ]); } else { - bytesToHash = concat([ - pubsubTopicBytes, - message.payload, - contentTopicBytes, - ]); + bytes = concat([pubsubTopicBytes, message.payload, contentTopicBytes]); } - return sha256(bytesToHash); + return sha256(bytes); } From c8c2cbfbb199b799b7ff4203e643b30a154b7775 Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Mon, 20 Mar 2023 15:44:48 +1100 Subject: [PATCH 5/5] chore: ignore changelog file as it's handled by release please --- packages/message-hash/.prettierignore | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/message-hash/.prettierignore b/packages/message-hash/.prettierignore index fecb37a393..d8763f9fc7 100644 --- a/packages/message-hash/.prettierignore +++ b/packages/message-hash/.prettierignore @@ -2,3 +2,4 @@ build bundle dist node_modules +CHANGELOG.md