mirror of https://github.com/waku-org/js-waku.git
tests: fix karma
This commit is contained in:
parent
8a00bc1b85
commit
9cc32c1032
|
@ -182,9 +182,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@babel/parser": {
|
||||
"version": "7.20.0",
|
||||
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.20.0.tgz",
|
||||
"integrity": "sha512-G9VgAhEaICnz8iiJeGJQyVl6J2nTjbW0xeisva0PK6XcKsga7BIaqm4ZF8Rg1Wbaqmy6znspNqhPaPkyukujzg==",
|
||||
"version": "7.20.1",
|
||||
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.20.1.tgz",
|
||||
"integrity": "sha512-hp0AYxaZJhxULfM1zyp7Wgr+pSUKBcP3M+PHnSzWGdXOzg/kHWIgiUWARvubhUKGOEw3xqY4x+lyZ9ytBVcELw==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"parser": "bin/babel-parser.js"
|
||||
|
@ -5272,6 +5272,10 @@
|
|||
"integrity": "sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@waku/byte-utils": {
|
||||
"resolved": "packages/byte-utils",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@waku/core": {
|
||||
"resolved": "packages/core",
|
||||
"link": true
|
||||
|
@ -22353,6 +22357,64 @@
|
|||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"packages/byte-utils": {
|
||||
"name": "@waku/byte-utils",
|
||||
"version": "0.0.1",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"uint8arrays": "^4.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^22.0.0",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
"@rollup/plugin-node-resolve": "^13.3.0",
|
||||
"@semantic-release/changelog": "^6.0.1",
|
||||
"@semantic-release/commit-analyzer": "^9.0.2",
|
||||
"@semantic-release/git": "^10.0.1",
|
||||
"@semantic-release/github": "^8.0.6",
|
||||
"@semantic-release/npm": "^9.0.1",
|
||||
"@semantic-release/release-notes-generator": "^10.0.3",
|
||||
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
||||
"@typescript-eslint/parser": "^5.8.1",
|
||||
"cspell": "^5.14.0",
|
||||
"eslint": "^8.6.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-eslint-comments": "^3.2.0",
|
||||
"eslint-plugin-functional": "^4.0.2",
|
||||
"eslint-plugin-import": "^2.25.3",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"prettier": "^2.1.1",
|
||||
"rollup": "^2.75.0",
|
||||
"semantic-release": "^19.0.5",
|
||||
"semantic-release-monorepo": "^7.0.5",
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
}
|
||||
},
|
||||
"packages/byte-utils/node_modules/multiformats": {
|
||||
"version": "10.0.2",
|
||||
"resolved": "https://registry.npmjs.org/multiformats/-/multiformats-10.0.2.tgz",
|
||||
"integrity": "sha512-nJEHLFOYhO4L+aNApHhCnWqa31FyqAHv9Q77AhmwU3KsM2f1j7tuJpCk5ByZ33smzycNCpSG5klNIejIyfFx2A==",
|
||||
"engines": {
|
||||
"node": ">=16.0.0",
|
||||
"npm": ">=7.0.0"
|
||||
}
|
||||
},
|
||||
"packages/byte-utils/node_modules/uint8arrays": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-4.0.2.tgz",
|
||||
"integrity": "sha512-8CWXXZdOvVrIL4SeY/Gnp+idxxiGK4XFkP4FY26Sx/fpTz/b6vv4BVWELMDzQweSyyhdcuAcU14H6izzB6k1Cw==",
|
||||
"dependencies": {
|
||||
"multiformats": "^10.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.0.0",
|
||||
"npm": ">=7.0.0"
|
||||
}
|
||||
},
|
||||
"packages/core": {
|
||||
"name": "@waku/core",
|
||||
"version": "0.0.1",
|
||||
|
@ -22525,6 +22587,7 @@
|
|||
}
|
||||
},
|
||||
"packages/dns-discovery": {
|
||||
"name": "@waku/dns-discovery",
|
||||
"version": "0.0.1",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"devDependencies": {
|
||||
|
@ -22558,8 +22621,15 @@
|
|||
}
|
||||
},
|
||||
"packages/enr": {
|
||||
"name": "@waku/enr",
|
||||
"version": "0.0.1",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@libp2p/crypto": "^1.0.4",
|
||||
"@multiformats/multiaddr": "^11.0.6",
|
||||
"@noble/secp256k1": "^1.7.0",
|
||||
"@waku/byte-utils": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^22.0.0",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
|
@ -22572,6 +22642,7 @@
|
|||
"@semantic-release/release-notes-generator": "^10.0.3",
|
||||
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
||||
"@typescript-eslint/parser": "^5.8.1",
|
||||
"chai": "^4.3.6",
|
||||
"cspell": "^5.14.0",
|
||||
"eslint": "^8.6.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
|
@ -22584,12 +22655,51 @@
|
|||
"rollup": "^2.75.0",
|
||||
"semantic-release": "^19.0.5",
|
||||
"semantic-release-monorepo": "^7.0.5",
|
||||
"ts-loader": "^9.4.1",
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
}
|
||||
},
|
||||
"packages/enr/node_modules/@multiformats/multiaddr": {
|
||||
"version": "11.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@multiformats/multiaddr/-/multiaddr-11.0.6.tgz",
|
||||
"integrity": "sha512-5TvEdCc5uFqcwGA+IwSw49swyHtUbwjhjwF3WQcV9vkzTv1C8oEWhoD2QcsiomDRk8rdqqRyDH6wlZExvLnxjw==",
|
||||
"dependencies": {
|
||||
"@chainsafe/is-ip": "^1.0.0",
|
||||
"dns-over-http-resolver": "^2.1.0",
|
||||
"err-code": "^3.0.1",
|
||||
"multiformats": "^10.0.0",
|
||||
"uint8arrays": "^4.0.2",
|
||||
"varint": "^6.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.0.0",
|
||||
"npm": ">=7.0.0"
|
||||
}
|
||||
},
|
||||
"packages/enr/node_modules/multiformats": {
|
||||
"version": "10.0.2",
|
||||
"resolved": "https://registry.npmjs.org/multiformats/-/multiformats-10.0.2.tgz",
|
||||
"integrity": "sha512-nJEHLFOYhO4L+aNApHhCnWqa31FyqAHv9Q77AhmwU3KsM2f1j7tuJpCk5ByZ33smzycNCpSG5klNIejIyfFx2A==",
|
||||
"engines": {
|
||||
"node": ">=16.0.0",
|
||||
"npm": ">=7.0.0"
|
||||
}
|
||||
},
|
||||
"packages/enr/node_modules/uint8arrays": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-4.0.2.tgz",
|
||||
"integrity": "sha512-8CWXXZdOvVrIL4SeY/Gnp+idxxiGK4XFkP4FY26Sx/fpTz/b6vv4BVWELMDzQweSyyhdcuAcU14H6izzB6k1Cw==",
|
||||
"dependencies": {
|
||||
"multiformats": "^10.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.0.0",
|
||||
"npm": ">=7.0.0"
|
||||
}
|
||||
},
|
||||
"packages/interfaces": {
|
||||
"name": "@waku/interfaces",
|
||||
"version": "0.0.1",
|
||||
|
@ -22839,9 +22949,9 @@
|
|||
}
|
||||
},
|
||||
"@babel/parser": {
|
||||
"version": "7.20.0",
|
||||
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.20.0.tgz",
|
||||
"integrity": "sha512-G9VgAhEaICnz8iiJeGJQyVl6J2nTjbW0xeisva0PK6XcKsga7BIaqm4ZF8Rg1Wbaqmy6znspNqhPaPkyukujzg==",
|
||||
"version": "7.20.1",
|
||||
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.20.1.tgz",
|
||||
"integrity": "sha512-hp0AYxaZJhxULfM1zyp7Wgr+pSUKBcP3M+PHnSzWGdXOzg/kHWIgiUWARvubhUKGOEw3xqY4x+lyZ9ytBVcELw==",
|
||||
"dev": true
|
||||
},
|
||||
"@chainsafe/is-ip": {
|
||||
|
@ -26909,6 +27019,51 @@
|
|||
"integrity": "sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==",
|
||||
"dev": true
|
||||
},
|
||||
"@waku/byte-utils": {
|
||||
"version": "file:packages/byte-utils",
|
||||
"requires": {
|
||||
"@rollup/plugin-commonjs": "^22.0.0",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
"@rollup/plugin-node-resolve": "^13.3.0",
|
||||
"@semantic-release/changelog": "^6.0.1",
|
||||
"@semantic-release/commit-analyzer": "^9.0.2",
|
||||
"@semantic-release/git": "^10.0.1",
|
||||
"@semantic-release/github": "^8.0.6",
|
||||
"@semantic-release/npm": "^9.0.1",
|
||||
"@semantic-release/release-notes-generator": "^10.0.3",
|
||||
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
||||
"@typescript-eslint/parser": "^5.8.1",
|
||||
"cspell": "^5.14.0",
|
||||
"eslint": "^8.6.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-eslint-comments": "^3.2.0",
|
||||
"eslint-plugin-functional": "^4.0.2",
|
||||
"eslint-plugin-import": "^2.25.3",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"prettier": "^2.1.1",
|
||||
"rollup": "^2.75.0",
|
||||
"semantic-release": "^19.0.5",
|
||||
"semantic-release-monorepo": "^7.0.5",
|
||||
"typescript": "^4.6.3",
|
||||
"uint8arrays": "^4.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"multiformats": {
|
||||
"version": "10.0.2",
|
||||
"resolved": "https://registry.npmjs.org/multiformats/-/multiformats-10.0.2.tgz",
|
||||
"integrity": "sha512-nJEHLFOYhO4L+aNApHhCnWqa31FyqAHv9Q77AhmwU3KsM2f1j7tuJpCk5ByZ33smzycNCpSG5klNIejIyfFx2A=="
|
||||
},
|
||||
"uint8arrays": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-4.0.2.tgz",
|
||||
"integrity": "sha512-8CWXXZdOvVrIL4SeY/Gnp+idxxiGK4XFkP4FY26Sx/fpTz/b6vv4BVWELMDzQweSyyhdcuAcU14H6izzB6k1Cw==",
|
||||
"requires": {
|
||||
"multiformats": "^10.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"@waku/core": {
|
||||
"version": "file:packages/core",
|
||||
"requires": {
|
||||
|
@ -27090,6 +27245,9 @@
|
|||
"@waku/enr": {
|
||||
"version": "file:packages/enr",
|
||||
"requires": {
|
||||
"@libp2p/crypto": "^1.0.4",
|
||||
"@multiformats/multiaddr": "^11.0.6",
|
||||
"@noble/secp256k1": "^1.7.0",
|
||||
"@rollup/plugin-commonjs": "^22.0.0",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
"@rollup/plugin-node-resolve": "^13.3.0",
|
||||
|
@ -27101,6 +27259,8 @@
|
|||
"@semantic-release/release-notes-generator": "^10.0.3",
|
||||
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
||||
"@typescript-eslint/parser": "^5.8.1",
|
||||
"@waku/byte-utils": "*",
|
||||
"chai": "^4.3.6",
|
||||
"cspell": "^5.14.0",
|
||||
"eslint": "^8.6.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
|
@ -27113,7 +27273,36 @@
|
|||
"rollup": "^2.75.0",
|
||||
"semantic-release": "^19.0.5",
|
||||
"semantic-release-monorepo": "^7.0.5",
|
||||
"ts-loader": "^9.4.1",
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@multiformats/multiaddr": {
|
||||
"version": "11.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@multiformats/multiaddr/-/multiaddr-11.0.6.tgz",
|
||||
"integrity": "sha512-5TvEdCc5uFqcwGA+IwSw49swyHtUbwjhjwF3WQcV9vkzTv1C8oEWhoD2QcsiomDRk8rdqqRyDH6wlZExvLnxjw==",
|
||||
"requires": {
|
||||
"@chainsafe/is-ip": "^1.0.0",
|
||||
"dns-over-http-resolver": "^2.1.0",
|
||||
"err-code": "^3.0.1",
|
||||
"multiformats": "^10.0.0",
|
||||
"uint8arrays": "^4.0.2",
|
||||
"varint": "^6.0.0"
|
||||
}
|
||||
},
|
||||
"multiformats": {
|
||||
"version": "10.0.2",
|
||||
"resolved": "https://registry.npmjs.org/multiformats/-/multiformats-10.0.2.tgz",
|
||||
"integrity": "sha512-nJEHLFOYhO4L+aNApHhCnWqa31FyqAHv9Q77AhmwU3KsM2f1j7tuJpCk5ByZ33smzycNCpSG5klNIejIyfFx2A=="
|
||||
},
|
||||
"uint8arrays": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-4.0.2.tgz",
|
||||
"integrity": "sha512-8CWXXZdOvVrIL4SeY/Gnp+idxxiGK4XFkP4FY26Sx/fpTz/b6vv4BVWELMDzQweSyyhdcuAcU14H6izzB6k1Cw==",
|
||||
"requires": {
|
||||
"multiformats": "^10.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"@waku/interfaces": {
|
||||
|
|
|
@ -50,7 +50,9 @@
|
|||
"engines": {
|
||||
"node": ">=16"
|
||||
},
|
||||
"dependencies": {},
|
||||
"dependencies": {
|
||||
"uint8arrays": "^4.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^22.0.0",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
|
|
|
@ -74,27 +74,3 @@ export async function sign(
|
|||
export function keccak256(input: Uint8Array): Uint8Array {
|
||||
return new Uint8Array(sha3.keccak256.arrayBuffer(input));
|
||||
}
|
||||
|
||||
export function compressPublicKey(publicKey: Uint8Array): Uint8Array {
|
||||
if (publicKey.length === 64) {
|
||||
publicKey = concat([new Uint8Array([4]), publicKey], 65);
|
||||
}
|
||||
const point = secp.Point.fromHex(publicKey);
|
||||
return point.toRawBytes(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify an ECDSA signature.
|
||||
*/
|
||||
export function verifySignature(
|
||||
signature: Uint8Array,
|
||||
message: Uint8Array | string,
|
||||
publicKey: Uint8Array
|
||||
): boolean {
|
||||
try {
|
||||
const _signature = secp.Signature.fromCompact(signature.slice(0, 64));
|
||||
return secp.verify(_signature, message, publicKey);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
module.exports = {
|
||||
parserOptions: {
|
||||
tsconfigRootDir: __dirname,
|
||||
project: "./tsconfig.dev.json",
|
||||
},
|
||||
};
|
|
@ -0,0 +1,4 @@
|
|||
build
|
||||
bundle
|
||||
dist
|
||||
node_modules
|
|
@ -0,0 +1,6 @@
|
|||
module.exports = {
|
||||
parserOptions: {
|
||||
tsconfigRootDir: __dirname,
|
||||
project: "./tsconfig.dev.json",
|
||||
},
|
||||
};
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"extension": ["ts"],
|
||||
"spec": "src/**/*.spec.ts",
|
||||
"require": ["ts-node/register", "isomorphic-fetch", "jsdom-global/register"],
|
||||
"loader": "ts-node/esm",
|
||||
"node-option": [
|
||||
"experimental-specifier-resolution=node",
|
||||
"loader=ts-node/esm"
|
||||
],
|
||||
"exit": true
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
build
|
||||
bundle
|
||||
dist
|
||||
node_modules
|
|
@ -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/**/*.ts"],
|
||||
preprocessors: {
|
||||
"src/**/*.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",
|
||||
},
|
||||
});
|
||||
};
|
|
@ -43,6 +43,9 @@
|
|||
"check:prettier": "prettier . --list-different",
|
||||
"check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
|
||||
"check:tsc": "tsc -p tsconfig.dev.json",
|
||||
"test": "run-s test:*",
|
||||
"test:node": "TS_NODE_PROJECT=./tsconfig.dev.json mocha",
|
||||
"test:browser": "karma start karma.conf.cjs",
|
||||
"prepublish": "npm run build",
|
||||
"reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build",
|
||||
"release": "semantic-release"
|
||||
|
@ -50,7 +53,12 @@
|
|||
"engines": {
|
||||
"node": ">=16"
|
||||
},
|
||||
"dependencies": {},
|
||||
"dependencies": {
|
||||
"@libp2p/crypto": "^1.0.4",
|
||||
"@multiformats/multiaddr": "^11.0.6",
|
||||
"@noble/secp256k1": "^1.7.0",
|
||||
"@waku/byte-utils": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^22.0.0",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
|
@ -63,6 +71,7 @@
|
|||
"@semantic-release/release-notes-generator": "^10.0.3",
|
||||
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
||||
"@typescript-eslint/parser": "^5.8.1",
|
||||
"chai": "^4.3.6",
|
||||
"cspell": "^5.14.0",
|
||||
"eslint": "^8.6.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
|
@ -75,6 +84,7 @@
|
|||
"rollup": "^2.75.0",
|
||||
"semantic-release": "^19.0.5",
|
||||
"semantic-release-monorepo": "^7.0.5",
|
||||
"ts-loader": "^9.4.1",
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"release": {
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
import * as secp from "@noble/secp256k1";
|
||||
import { concat } from "@waku/byte-utils";
|
||||
import sha3 from "js-sha3";
|
||||
|
||||
export const randomBytes = secp.utils.randomBytes;
|
||||
|
||||
/**
|
||||
* Return the public key for the given private key, to be used for asymmetric
|
||||
* encryption.
|
||||
*/
|
||||
export const getPublicKey = secp.getPublicKey;
|
||||
|
||||
/**
|
||||
* ECDSA Sign a message with the given private key.
|
||||
*
|
||||
* @param message The message to sign, usually a hash.
|
||||
* @param privateKey The ECDSA private key to use to sign the message.
|
||||
*
|
||||
* @returns The signature and the recovery id concatenated.
|
||||
*/
|
||||
export async function sign(
|
||||
message: Uint8Array,
|
||||
privateKey: Uint8Array
|
||||
): Promise<Uint8Array> {
|
||||
const [signature, recoveryId] = await secp.sign(message, privateKey, {
|
||||
recovered: true,
|
||||
der: false,
|
||||
});
|
||||
return concat(
|
||||
[signature, new Uint8Array([recoveryId])],
|
||||
signature.length + 1
|
||||
);
|
||||
}
|
||||
|
||||
export function keccak256(input: Uint8Array): Uint8Array {
|
||||
return new Uint8Array(sha3.keccak256.arrayBuffer(input));
|
||||
}
|
||||
|
||||
export function compressPublicKey(publicKey: Uint8Array): Uint8Array {
|
||||
if (publicKey.length === 64) {
|
||||
publicKey = concat([new Uint8Array([4]), publicKey], 65);
|
||||
}
|
||||
const point = secp.Point.fromHex(publicKey);
|
||||
return point.toRawBytes(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify an ECDSA signature.
|
||||
*/
|
||||
export function verifySignature(
|
||||
signature: Uint8Array,
|
||||
message: Uint8Array | string,
|
||||
publicKey: Uint8Array
|
||||
): boolean {
|
||||
try {
|
||||
const _signature = secp.Signature.fromCompact(signature.slice(0, 64));
|
||||
return secp.verify(_signature, message, publicKey);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,15 +1,14 @@
|
|||
import { createSecp256k1PeerId } from "@libp2p/peer-id-factory";
|
||||
import { multiaddr } from "@multiformats/multiaddr";
|
||||
import { bytesToHex, hexToBytes, utf8ToBytes } from "@waku/byte-utils";
|
||||
import { assert, expect } from "chai";
|
||||
import { equals } from "uint8arrays/equals";
|
||||
|
||||
import { getPublicKey } from "../crypto";
|
||||
import { bytesToHex, hexToBytes, utf8ToBytes } from "../utils";
|
||||
|
||||
import { ERR_INVALID_ID } from "./constants";
|
||||
import { ENR } from "./enr";
|
||||
import { createKeypairFromPeerId, IKeypair } from "./keypair";
|
||||
import { Waku2 } from "./waku2_codec";
|
||||
import { ERR_INVALID_ID } from "./constants.js";
|
||||
import { getPublicKey } from "./crypto.js";
|
||||
import { ENR } from "./enr.js";
|
||||
import { createKeypairFromPeerId, IKeypair } from "./keypair/index.js";
|
||||
import { Waku2 } from "./waku2_codec.js";
|
||||
|
||||
describe("ENR", function () {
|
||||
describe("Txt codec", () => {
|
||||
|
|
|
@ -5,14 +5,22 @@ import {
|
|||
convertToBytes,
|
||||
convertToString,
|
||||
} from "@multiformats/multiaddr/convert";
|
||||
import {
|
||||
bytesToHex,
|
||||
bytesToUtf8,
|
||||
hexToBytes,
|
||||
utf8ToBytes,
|
||||
} from "@waku/byte-utils";
|
||||
import debug from "debug";
|
||||
import { fromString } from "uint8arrays/from-string";
|
||||
import { toString } from "uint8arrays/to-string";
|
||||
|
||||
import { compressPublicKey, keccak256, verifySignature } from "../crypto";
|
||||
import { bytesToHex, bytesToUtf8, hexToBytes, utf8ToBytes } from "../utils";
|
||||
|
||||
import { ERR_INVALID_ID, ERR_NO_SIGNATURE, MAX_RECORD_SIZE } from "./constants";
|
||||
import {
|
||||
ERR_INVALID_ID,
|
||||
ERR_NO_SIGNATURE,
|
||||
MAX_RECORD_SIZE,
|
||||
} from "./constants.js";
|
||||
import { compressPublicKey, keccak256, verifySignature } from "./crypto.js";
|
||||
import {
|
||||
createKeypair,
|
||||
createKeypairFromPeerId,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
export * from "./constants";
|
||||
export * from "./enr";
|
||||
export * from "./types";
|
||||
export * from "./keypair";
|
||||
export * from "./waku2_codec";
|
||||
export * from "./constants.js";
|
||||
export * from "./enr.js";
|
||||
export * from "./types.js";
|
||||
export * from "./keypair/index.js";
|
||||
export * from "./waku2_codec.js";
|
||||
|
|
|
@ -3,12 +3,12 @@ import { supportedKeys } from "@libp2p/crypto/keys";
|
|||
import type { PeerId } from "@libp2p/interface-peer-id";
|
||||
import { peerIdFromKeys } from "@libp2p/peer-id";
|
||||
|
||||
import { Secp256k1Keypair } from "./secp256k1";
|
||||
import { IKeypair, KeypairType } from "./types";
|
||||
import { Secp256k1Keypair } from "./secp256k1.js";
|
||||
import { IKeypair, KeypairType } from "./types.js";
|
||||
|
||||
export const ERR_TYPE_NOT_IMPLEMENTED = "Keypair type not implemented";
|
||||
export * from "./types";
|
||||
export * from "./secp256k1";
|
||||
export * from "./types.js";
|
||||
export * from "./secp256k1.js";
|
||||
|
||||
export function createKeypair(
|
||||
type: KeypairType,
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import * as secp from "@noble/secp256k1";
|
||||
|
||||
import { compressPublicKey, randomBytes } from "../../crypto";
|
||||
import { compressPublicKey, randomBytes } from "../crypto.js";
|
||||
|
||||
import { IKeypair, KeypairType } from "./types";
|
||||
import { IKeypair, KeypairType } from "./types.js";
|
||||
|
||||
export class Secp256k1Keypair implements IKeypair {
|
||||
readonly type: KeypairType;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { convertToBytes } from "@multiformats/multiaddr/convert";
|
||||
import { expect } from "chai";
|
||||
|
||||
import { multiaddrFromFields } from "./multiaddr_from_fields";
|
||||
import { multiaddrFromFields } from "./multiaddr_from_fields.js";
|
||||
|
||||
describe("Multiaddr from fields", () => {
|
||||
it("tcp ip4 address", function () {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { multiaddr } from "@multiformats/multiaddr";
|
||||
import { expect } from "chai";
|
||||
|
||||
import { decodeMultiaddrs, encodeMultiaddrs } from "./multiaddrs_codec";
|
||||
import { decodeMultiaddrs, encodeMultiaddrs } from "./multiaddrs_codec.js";
|
||||
|
||||
describe("ENR multiaddrs codec", function () {
|
||||
it("Sample", async () => {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { multiaddr } from "@multiformats/multiaddr";
|
||||
import type { Multiaddr } from "@multiformats/multiaddr";
|
||||
|
||||
import { MULTIADDR_LENGTH_SIZE } from "./constants";
|
||||
import { MULTIADDR_LENGTH_SIZE } from "./constants.js";
|
||||
|
||||
export function decodeMultiaddrs(bytes: Uint8Array): Multiaddr[] {
|
||||
const multiaddrs = [];
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import * as secp from "@noble/secp256k1";
|
||||
import { bytesToHex } from "@waku/byte-utils";
|
||||
|
||||
import { keccak256 } from "../crypto";
|
||||
import { bytesToHex } from "../utils";
|
||||
|
||||
import { NodeId } from "./types";
|
||||
import { keccak256 } from "./crypto.js";
|
||||
import { NodeId } from "./types.js";
|
||||
|
||||
export async function sign(
|
||||
privKey: Uint8Array,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { expect } from "chai";
|
||||
|
||||
import { decodeWaku2, encodeWaku2, Waku2 } from "./waku2_codec";
|
||||
import { decodeWaku2, encodeWaku2, Waku2 } from "./waku2_codec.js";
|
||||
|
||||
const waku2FieldEncodings = {
|
||||
relay: 1,
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"extends": "./tsconfig.dev",
|
||||
"compilerOptions": {
|
||||
"noEmit": false
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue