mirror of
https://github.com/waku-org/js-waku.git
synced 2025-02-20 16:18:21 +00:00
tests: fix karma
This commit is contained in:
parent
8a00bc1b85
commit
9cc32c1032
201
package-lock.json
generated
201
package-lock.json
generated
@ -182,9 +182,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@babel/parser": {
|
"node_modules/@babel/parser": {
|
||||||
"version": "7.20.0",
|
"version": "7.20.1",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.20.0.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.20.1.tgz",
|
||||||
"integrity": "sha512-G9VgAhEaICnz8iiJeGJQyVl6J2nTjbW0xeisva0PK6XcKsga7BIaqm4ZF8Rg1Wbaqmy6znspNqhPaPkyukujzg==",
|
"integrity": "sha512-hp0AYxaZJhxULfM1zyp7Wgr+pSUKBcP3M+PHnSzWGdXOzg/kHWIgiUWARvubhUKGOEw3xqY4x+lyZ9ytBVcELw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"bin": {
|
"bin": {
|
||||||
"parser": "bin/babel-parser.js"
|
"parser": "bin/babel-parser.js"
|
||||||
@ -5272,6 +5272,10 @@
|
|||||||
"integrity": "sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==",
|
"integrity": "sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/@waku/byte-utils": {
|
||||||
|
"resolved": "packages/byte-utils",
|
||||||
|
"link": true
|
||||||
|
},
|
||||||
"node_modules/@waku/core": {
|
"node_modules/@waku/core": {
|
||||||
"resolved": "packages/core",
|
"resolved": "packages/core",
|
||||||
"link": true
|
"link": true
|
||||||
@ -22353,6 +22357,64 @@
|
|||||||
"url": "https://github.com/sponsors/sindresorhus"
|
"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": {
|
"packages/core": {
|
||||||
"name": "@waku/core",
|
"name": "@waku/core",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
@ -22525,6 +22587,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"packages/dns-discovery": {
|
"packages/dns-discovery": {
|
||||||
|
"name": "@waku/dns-discovery",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"license": "MIT OR Apache-2.0",
|
"license": "MIT OR Apache-2.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@ -22558,8 +22621,15 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"packages/enr": {
|
"packages/enr": {
|
||||||
|
"name": "@waku/enr",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"license": "MIT OR Apache-2.0",
|
"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": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-commonjs": "^22.0.0",
|
"@rollup/plugin-commonjs": "^22.0.0",
|
||||||
"@rollup/plugin-json": "^4.1.0",
|
"@rollup/plugin-json": "^4.1.0",
|
||||||
@ -22572,6 +22642,7 @@
|
|||||||
"@semantic-release/release-notes-generator": "^10.0.3",
|
"@semantic-release/release-notes-generator": "^10.0.3",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
||||||
"@typescript-eslint/parser": "^5.8.1",
|
"@typescript-eslint/parser": "^5.8.1",
|
||||||
|
"chai": "^4.3.6",
|
||||||
"cspell": "^5.14.0",
|
"cspell": "^5.14.0",
|
||||||
"eslint": "^8.6.0",
|
"eslint": "^8.6.0",
|
||||||
"eslint-config-prettier": "^8.3.0",
|
"eslint-config-prettier": "^8.3.0",
|
||||||
@ -22584,12 +22655,51 @@
|
|||||||
"rollup": "^2.75.0",
|
"rollup": "^2.75.0",
|
||||||
"semantic-release": "^19.0.5",
|
"semantic-release": "^19.0.5",
|
||||||
"semantic-release-monorepo": "^7.0.5",
|
"semantic-release-monorepo": "^7.0.5",
|
||||||
|
"ts-loader": "^9.4.1",
|
||||||
"typescript": "^4.6.3"
|
"typescript": "^4.6.3"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16"
|
"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": {
|
"packages/interfaces": {
|
||||||
"name": "@waku/interfaces",
|
"name": "@waku/interfaces",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
@ -22839,9 +22949,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@babel/parser": {
|
"@babel/parser": {
|
||||||
"version": "7.20.0",
|
"version": "7.20.1",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.20.0.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.20.1.tgz",
|
||||||
"integrity": "sha512-G9VgAhEaICnz8iiJeGJQyVl6J2nTjbW0xeisva0PK6XcKsga7BIaqm4ZF8Rg1Wbaqmy6znspNqhPaPkyukujzg==",
|
"integrity": "sha512-hp0AYxaZJhxULfM1zyp7Wgr+pSUKBcP3M+PHnSzWGdXOzg/kHWIgiUWARvubhUKGOEw3xqY4x+lyZ9ytBVcELw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@chainsafe/is-ip": {
|
"@chainsafe/is-ip": {
|
||||||
@ -26909,6 +27019,51 @@
|
|||||||
"integrity": "sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==",
|
"integrity": "sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==",
|
||||||
"dev": true
|
"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": {
|
"@waku/core": {
|
||||||
"version": "file:packages/core",
|
"version": "file:packages/core",
|
||||||
"requires": {
|
"requires": {
|
||||||
@ -27090,6 +27245,9 @@
|
|||||||
"@waku/enr": {
|
"@waku/enr": {
|
||||||
"version": "file:packages/enr",
|
"version": "file:packages/enr",
|
||||||
"requires": {
|
"requires": {
|
||||||
|
"@libp2p/crypto": "^1.0.4",
|
||||||
|
"@multiformats/multiaddr": "^11.0.6",
|
||||||
|
"@noble/secp256k1": "^1.7.0",
|
||||||
"@rollup/plugin-commonjs": "^22.0.0",
|
"@rollup/plugin-commonjs": "^22.0.0",
|
||||||
"@rollup/plugin-json": "^4.1.0",
|
"@rollup/plugin-json": "^4.1.0",
|
||||||
"@rollup/plugin-node-resolve": "^13.3.0",
|
"@rollup/plugin-node-resolve": "^13.3.0",
|
||||||
@ -27101,6 +27259,8 @@
|
|||||||
"@semantic-release/release-notes-generator": "^10.0.3",
|
"@semantic-release/release-notes-generator": "^10.0.3",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
||||||
"@typescript-eslint/parser": "^5.8.1",
|
"@typescript-eslint/parser": "^5.8.1",
|
||||||
|
"@waku/byte-utils": "*",
|
||||||
|
"chai": "^4.3.6",
|
||||||
"cspell": "^5.14.0",
|
"cspell": "^5.14.0",
|
||||||
"eslint": "^8.6.0",
|
"eslint": "^8.6.0",
|
||||||
"eslint-config-prettier": "^8.3.0",
|
"eslint-config-prettier": "^8.3.0",
|
||||||
@ -27113,7 +27273,36 @@
|
|||||||
"rollup": "^2.75.0",
|
"rollup": "^2.75.0",
|
||||||
"semantic-release": "^19.0.5",
|
"semantic-release": "^19.0.5",
|
||||||
"semantic-release-monorepo": "^7.0.5",
|
"semantic-release-monorepo": "^7.0.5",
|
||||||
|
"ts-loader": "^9.4.1",
|
||||||
"typescript": "^4.6.3"
|
"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": {
|
"@waku/interfaces": {
|
||||||
|
@ -50,7 +50,9 @@
|
|||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16"
|
"node": ">=16"
|
||||||
},
|
},
|
||||||
"dependencies": {},
|
"dependencies": {
|
||||||
|
"uint8arrays": "^4.0.2"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-commonjs": "^22.0.0",
|
"@rollup/plugin-commonjs": "^22.0.0",
|
||||||
"@rollup/plugin-json": "^4.1.0",
|
"@rollup/plugin-json": "^4.1.0",
|
||||||
|
@ -74,27 +74,3 @@ export async function sign(
|
|||||||
export function keccak256(input: Uint8Array): Uint8Array {
|
export function keccak256(input: Uint8Array): Uint8Array {
|
||||||
return new Uint8Array(sha3.keccak256.arrayBuffer(input));
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
6
packages/dns-discovery/.eslintrc.cjs
Normal file
6
packages/dns-discovery/.eslintrc.cjs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
module.exports = {
|
||||||
|
parserOptions: {
|
||||||
|
tsconfigRootDir: __dirname,
|
||||||
|
project: "./tsconfig.dev.json",
|
||||||
|
},
|
||||||
|
};
|
4
packages/dns-discovery/.prettierignore
Normal file
4
packages/dns-discovery/.prettierignore
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
build
|
||||||
|
bundle
|
||||||
|
dist
|
||||||
|
node_modules
|
6
packages/enr/.eslintrc.cjs
Normal file
6
packages/enr/.eslintrc.cjs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
module.exports = {
|
||||||
|
parserOptions: {
|
||||||
|
tsconfigRootDir: __dirname,
|
||||||
|
project: "./tsconfig.dev.json",
|
||||||
|
},
|
||||||
|
};
|
11
packages/enr/.mocharc.json
Normal file
11
packages/enr/.mocharc.json
Normal file
@ -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
|
||||||
|
}
|
4
packages/enr/.prettierignore
Normal file
4
packages/enr/.prettierignore
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
build
|
||||||
|
bundle
|
||||||
|
dist
|
||||||
|
node_modules
|
45
packages/enr/karma.conf.cjs
Normal file
45
packages/enr/karma.conf.cjs
Normal file
@ -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:prettier": "prettier . --list-different",
|
||||||
"check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
|
"check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
|
||||||
"check:tsc": "tsc -p tsconfig.dev.json",
|
"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",
|
"prepublish": "npm run build",
|
||||||
"reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build",
|
"reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build",
|
||||||
"release": "semantic-release"
|
"release": "semantic-release"
|
||||||
@ -50,7 +53,12 @@
|
|||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16"
|
"node": ">=16"
|
||||||
},
|
},
|
||||||
"dependencies": {},
|
"dependencies": {
|
||||||
|
"@libp2p/crypto": "^1.0.4",
|
||||||
|
"@multiformats/multiaddr": "^11.0.6",
|
||||||
|
"@noble/secp256k1": "^1.7.0",
|
||||||
|
"@waku/byte-utils": "*"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-commonjs": "^22.0.0",
|
"@rollup/plugin-commonjs": "^22.0.0",
|
||||||
"@rollup/plugin-json": "^4.1.0",
|
"@rollup/plugin-json": "^4.1.0",
|
||||||
@ -63,6 +71,7 @@
|
|||||||
"@semantic-release/release-notes-generator": "^10.0.3",
|
"@semantic-release/release-notes-generator": "^10.0.3",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
||||||
"@typescript-eslint/parser": "^5.8.1",
|
"@typescript-eslint/parser": "^5.8.1",
|
||||||
|
"chai": "^4.3.6",
|
||||||
"cspell": "^5.14.0",
|
"cspell": "^5.14.0",
|
||||||
"eslint": "^8.6.0",
|
"eslint": "^8.6.0",
|
||||||
"eslint-config-prettier": "^8.3.0",
|
"eslint-config-prettier": "^8.3.0",
|
||||||
@ -75,6 +84,7 @@
|
|||||||
"rollup": "^2.75.0",
|
"rollup": "^2.75.0",
|
||||||
"semantic-release": "^19.0.5",
|
"semantic-release": "^19.0.5",
|
||||||
"semantic-release-monorepo": "^7.0.5",
|
"semantic-release-monorepo": "^7.0.5",
|
||||||
|
"ts-loader": "^9.4.1",
|
||||||
"typescript": "^4.6.3"
|
"typescript": "^4.6.3"
|
||||||
},
|
},
|
||||||
"release": {
|
"release": {
|
||||||
|
61
packages/enr/src/crypto.ts
Normal file
61
packages/enr/src/crypto.ts
Normal file
@ -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 { createSecp256k1PeerId } from "@libp2p/peer-id-factory";
|
||||||
import { multiaddr } from "@multiformats/multiaddr";
|
import { multiaddr } from "@multiformats/multiaddr";
|
||||||
|
import { bytesToHex, hexToBytes, utf8ToBytes } from "@waku/byte-utils";
|
||||||
import { assert, expect } from "chai";
|
import { assert, expect } from "chai";
|
||||||
import { equals } from "uint8arrays/equals";
|
import { equals } from "uint8arrays/equals";
|
||||||
|
|
||||||
import { getPublicKey } from "../crypto";
|
import { ERR_INVALID_ID } from "./constants.js";
|
||||||
import { bytesToHex, hexToBytes, utf8ToBytes } from "../utils";
|
import { getPublicKey } from "./crypto.js";
|
||||||
|
import { ENR } from "./enr.js";
|
||||||
import { ERR_INVALID_ID } from "./constants";
|
import { createKeypairFromPeerId, IKeypair } from "./keypair/index.js";
|
||||||
import { ENR } from "./enr";
|
import { Waku2 } from "./waku2_codec.js";
|
||||||
import { createKeypairFromPeerId, IKeypair } from "./keypair";
|
|
||||||
import { Waku2 } from "./waku2_codec";
|
|
||||||
|
|
||||||
describe("ENR", function () {
|
describe("ENR", function () {
|
||||||
describe("Txt codec", () => {
|
describe("Txt codec", () => {
|
||||||
|
@ -5,14 +5,22 @@ import {
|
|||||||
convertToBytes,
|
convertToBytes,
|
||||||
convertToString,
|
convertToString,
|
||||||
} from "@multiformats/multiaddr/convert";
|
} from "@multiformats/multiaddr/convert";
|
||||||
|
import {
|
||||||
|
bytesToHex,
|
||||||
|
bytesToUtf8,
|
||||||
|
hexToBytes,
|
||||||
|
utf8ToBytes,
|
||||||
|
} from "@waku/byte-utils";
|
||||||
import debug from "debug";
|
import debug from "debug";
|
||||||
import { fromString } from "uint8arrays/from-string";
|
import { fromString } from "uint8arrays/from-string";
|
||||||
import { toString } from "uint8arrays/to-string";
|
import { toString } from "uint8arrays/to-string";
|
||||||
|
|
||||||
import { compressPublicKey, keccak256, verifySignature } from "../crypto";
|
import {
|
||||||
import { bytesToHex, bytesToUtf8, hexToBytes, utf8ToBytes } from "../utils";
|
ERR_INVALID_ID,
|
||||||
|
ERR_NO_SIGNATURE,
|
||||||
import { ERR_INVALID_ID, ERR_NO_SIGNATURE, MAX_RECORD_SIZE } from "./constants";
|
MAX_RECORD_SIZE,
|
||||||
|
} from "./constants.js";
|
||||||
|
import { compressPublicKey, keccak256, verifySignature } from "./crypto.js";
|
||||||
import {
|
import {
|
||||||
createKeypair,
|
createKeypair,
|
||||||
createKeypairFromPeerId,
|
createKeypairFromPeerId,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
export * from "./constants";
|
export * from "./constants.js";
|
||||||
export * from "./enr";
|
export * from "./enr.js";
|
||||||
export * from "./types";
|
export * from "./types.js";
|
||||||
export * from "./keypair";
|
export * from "./keypair/index.js";
|
||||||
export * from "./waku2_codec";
|
export * from "./waku2_codec.js";
|
||||||
|
@ -3,12 +3,12 @@ import { supportedKeys } from "@libp2p/crypto/keys";
|
|||||||
import type { PeerId } from "@libp2p/interface-peer-id";
|
import type { PeerId } from "@libp2p/interface-peer-id";
|
||||||
import { peerIdFromKeys } from "@libp2p/peer-id";
|
import { peerIdFromKeys } from "@libp2p/peer-id";
|
||||||
|
|
||||||
import { Secp256k1Keypair } from "./secp256k1";
|
import { Secp256k1Keypair } from "./secp256k1.js";
|
||||||
import { IKeypair, KeypairType } from "./types";
|
import { IKeypair, KeypairType } from "./types.js";
|
||||||
|
|
||||||
export const ERR_TYPE_NOT_IMPLEMENTED = "Keypair type not implemented";
|
export const ERR_TYPE_NOT_IMPLEMENTED = "Keypair type not implemented";
|
||||||
export * from "./types";
|
export * from "./types.js";
|
||||||
export * from "./secp256k1";
|
export * from "./secp256k1.js";
|
||||||
|
|
||||||
export function createKeypair(
|
export function createKeypair(
|
||||||
type: KeypairType,
|
type: KeypairType,
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import * as secp from "@noble/secp256k1";
|
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 {
|
export class Secp256k1Keypair implements IKeypair {
|
||||||
readonly type: KeypairType;
|
readonly type: KeypairType;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { convertToBytes } from "@multiformats/multiaddr/convert";
|
import { convertToBytes } from "@multiformats/multiaddr/convert";
|
||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { multiaddrFromFields } from "./multiaddr_from_fields";
|
import { multiaddrFromFields } from "./multiaddr_from_fields.js";
|
||||||
|
|
||||||
describe("Multiaddr from fields", () => {
|
describe("Multiaddr from fields", () => {
|
||||||
it("tcp ip4 address", function () {
|
it("tcp ip4 address", function () {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { multiaddr } from "@multiformats/multiaddr";
|
import { multiaddr } from "@multiformats/multiaddr";
|
||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { decodeMultiaddrs, encodeMultiaddrs } from "./multiaddrs_codec";
|
import { decodeMultiaddrs, encodeMultiaddrs } from "./multiaddrs_codec.js";
|
||||||
|
|
||||||
describe("ENR multiaddrs codec", function () {
|
describe("ENR multiaddrs codec", function () {
|
||||||
it("Sample", async () => {
|
it("Sample", async () => {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { multiaddr } from "@multiformats/multiaddr";
|
import { multiaddr } from "@multiformats/multiaddr";
|
||||||
import type { 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[] {
|
export function decodeMultiaddrs(bytes: Uint8Array): Multiaddr[] {
|
||||||
const multiaddrs = [];
|
const multiaddrs = [];
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import * as secp from "@noble/secp256k1";
|
import * as secp from "@noble/secp256k1";
|
||||||
|
import { bytesToHex } from "@waku/byte-utils";
|
||||||
|
|
||||||
import { keccak256 } from "../crypto";
|
import { keccak256 } from "./crypto.js";
|
||||||
import { bytesToHex } from "../utils";
|
import { NodeId } from "./types.js";
|
||||||
|
|
||||||
import { NodeId } from "./types";
|
|
||||||
|
|
||||||
export async function sign(
|
export async function sign(
|
||||||
privKey: Uint8Array,
|
privKey: Uint8Array,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { decodeWaku2, encodeWaku2, Waku2 } from "./waku2_codec";
|
import { decodeWaku2, encodeWaku2, Waku2 } from "./waku2_codec.js";
|
||||||
|
|
||||||
const waku2FieldEncodings = {
|
const waku2FieldEncodings = {
|
||||||
relay: 1,
|
relay: 1,
|
||||||
|
6
packages/enr/tsconfig.karma.json
Normal file
6
packages/enr/tsconfig.karma.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.dev",
|
||||||
|
"compilerOptions": {
|
||||||
|
"noEmit": false
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user