diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0375dd8fe4..90acc57d56 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,19 +21,10 @@ jobs: with: node-version: ${{ env.NODE_JS }} - uses: bahmutov/npm-install@v1 + - run: npm run build - run: npm run check - run: npm run doc - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: ${{ env.NODE_JS }} - - uses: bahmutov/npm-install@v1 - - run: npm run build - proto: runs-on: ubuntu-latest steps: @@ -61,6 +52,7 @@ jobs: with: node-version: ${{ env.NODE_JS }} - uses: bahmutov/npm-install@v1 + - run: npm run build - run: npm run test:browser node: @@ -84,6 +76,7 @@ jobs: with: node-version: ${{ env.NODE_JS }} - uses: bahmutov/npm-install@v1 + - run: npm run build - run: npm run test:node env: DEBUG: "waku:nwaku*,waku:test*" @@ -130,7 +123,7 @@ jobs: node-version: ${{ env.NODE_JS }} - uses: bahmutov/npm-install@v1 - + - run: npm run build - run: npm run test:node env: DEBUG: "waku:nwaku*,waku:test*" @@ -146,7 +139,7 @@ jobs: name: Release runs-on: ubuntu-latest if: github.event_name == 'push' && github.ref == 'refs/heads/master' - needs: [check, build, proto, browser, node] + needs: [check, proto, browser, node] steps: - name: Checkout uses: actions/checkout@v2 diff --git a/.gitignore b/.gitignore index ac07995727..038613d5b3 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ src/**.js coverage *.log *.tsbuildinfo +docs diff --git a/.size-limit.cjs b/.size-limit.cjs index 64b384d8de..9d4a1b12c8 100644 --- a/.size-limit.cjs +++ b/.size-limit.cjs @@ -7,11 +7,11 @@ module.exports = [ { name: "Waku default setup", path: [ - "packages/core/bundle/index.js", - "packages/core/bundle/lib/create_waku.js", + "packages/create/bundle/index.js", + "packages/core/bundle/lib/wait_for_remote_peer.js" ], import: { - "./packages/core/bundle/lib/create_waku.js": "{ createLightNode }", + "./packages/create/bundle/index.js": "{ createLightNode }", "./packages/core/bundle/lib/wait_for_remote_peer.js": "{ waitForRemotePeer }", "./packages/core/bundle/lib/waku_message/version_0.js": diff --git a/bors.toml b/bors.toml index 60984f4bd6..b5274599df 100644 --- a/bors.toml +++ b/bors.toml @@ -1,6 +1,5 @@ status = [ "check", - "build", "proto", "browser", "node", diff --git a/ci/deploy.js b/ci/deploy.js index e8672c0a15..c49b5e91ce 100644 --- a/ci/deploy.js +++ b/ci/deploy.js @@ -1,40 +1,45 @@ -import { promisify } from 'util' -import { publish } from 'gh-pages' +import { promisify } from "util"; + +import { publish } from "gh-pages"; /* fix for "Unhandled promise rejections" */ -process.on('unhandledRejection', err => { throw err }) +process.on("unhandledRejection", (err) => { + throw err; +}); -const ghpublish = promisify(publish) +const ghpublish = promisify(publish); -const Args = process.argv.slice(2) -const USE_HTTPS = Args[0] && Args[0].toUpperCase() === 'HTTPS' +const Args = process.argv.slice(2); +const USE_HTTPS = Args[0] && Args[0].toUpperCase() === "HTTPS"; -const branch = 'gh-pages' -const org = 'waku-org' -const repo = 'js-waku' +const branch = "gh-pages"; +const org = "waku-org"; +const repo = "js-waku"; /* use SSH auth by default */ let repoUrl = USE_HTTPS ? `https://github.com/${org}/${repo}.git` - : `git@github.com:${org}/${repo}.git` + : `git@github.com:${org}/${repo}.git`; /* alternative auth using GitHub user and API token */ if (typeof process.env.GH_USER !== "undefined") { - repoUrl = ( - 'https://' + process.env.GH_USER + - ':' + process.env.GH_TOKEN + - '@' + `github.com/${org}/${repo}.git` - ) + repoUrl = + "https://" + + process.env.GH_USER + + ":" + + process.env.GH_TOKEN + + "@" + + `github.com/${org}/${repo}.git`; } -const main = async (url, branch)=> { - console.log(`Pushing to: ${url}`) - console.log(`On branch: ${branch}`) - await ghpublish('build/docs', { +const main = async (url, branch) => { + console.log(`Pushing to: ${url}`); + console.log(`On branch: ${branch}`); + await ghpublish("docs", { repo: url, branch: branch, dotfiles: true, - silent: false - }) -} + silent: false, + }); +}; -main(repoUrl, branch) +main(repoUrl, branch); diff --git a/package-lock.json b/package-lock.json index d42cd04e84..bf113920af 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,8 @@ "husky": "^8.0.1", "lerna": "^6.0.1", "lint-staged": "^13.0.3", - "size-limit": "^8.1.0" + "size-limit": "^8.1.0", + "typedoc": "^0.23.19" } }, "node_modules/@achingbrain/ip-address": { @@ -5275,6 +5276,18 @@ "resolved": "packages/core", "link": true }, + "node_modules/@waku/create": { + "resolved": "packages/create", + "link": true + }, + "node_modules/@waku/interfaces": { + "resolved": "packages/interfaces", + "link": true + }, + "node_modules/@waku/tests": { + "resolved": "packages/tests", + "link": true + }, "node_modules/@webassemblyjs/ast": { "version": "1.11.1", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.1.tgz", @@ -22353,6 +22366,7 @@ "@libp2p/websockets": "^3.0.3", "@multiformats/multiaddr": "^11.0.6", "@noble/secp256k1": "^1.3.4", + "@waku/interfaces": "*", "debug": "^4.3.4", "dns-query": "^0.11.2", "hi-base32": "^0.5.1", @@ -22420,7 +22434,6 @@ "tail": "^2.2.0", "ts-loader": "^9.3.1", "ts-node": "^10.9.1", - "typedoc": "^0.23.10", "typescript": "^4.6.3" }, "engines": { @@ -22464,6 +22477,163 @@ "node": ">=16.0.0", "npm": ">=7.0.0" } + }, + "packages/create": { + "name": "@waku/create", + "version": "0.0.1", + "license": "MIT OR Apache-2.0", + "dependencies": { + "@waku/core": "*", + "@waku/interfaces": "*" + }, + "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/interfaces": { + "name": "@waku/interfaces", + "version": "0.0.1", + "license": "MIT OR Apache-2.0", + "dependencies": { + "@chainsafe/libp2p-gossipsub": "^4.1.1", + "@libp2p/interface-connection": "^3.0.2", + "@libp2p/interface-peer-id": "^1.0.5", + "@libp2p/interface-peer-store": "^1.2.2", + "@multiformats/multiaddr": "^11.0.6", + "libp2p": "0.38.0" + }, + "devDependencies": { + "@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", + "semantic-release": "^19.0.5", + "semantic-release-monorepo": "^7.0.5", + "typescript": "^4.6.3" + }, + "engines": { + "node": ">=16" + } + }, + "packages/interfaces/node_modules/@libp2p/interface-connection": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@libp2p/interface-connection/-/interface-connection-3.0.2.tgz", + "integrity": "sha512-38R2GQ6BCOtwMi5uWU5MLr+xfEpRmVK9gqOp7jNx+6T7TVn8ji4725XLXNfpzprbOrzZkqf2iER84s8+yX4pMA==", + "dependencies": { + "@libp2p/interface-peer-id": "^1.0.0", + "@libp2p/interfaces": "^3.0.0", + "@multiformats/multiaddr": "^11.0.0", + "it-stream-types": "^1.0.4", + "uint8arraylist": "^2.1.1" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "packages/interfaces/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/interfaces/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/interfaces/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/tests": { + "name": "@waku/tests", + "version": "0.0.1", + "license": "MIT OR Apache-2.0", + "dependencies": { + "@waku/core": "*", + "@waku/create": "*", + "@waku/interfaces": "*" + }, + "devDependencies": { + "@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", + "typescript": "^4.6.3" + }, + "engines": { + "node": ">=16" + } } }, "dependencies": { @@ -26703,6 +26873,7 @@ "@types/uuid": "^8.3.0", "@typescript-eslint/eslint-plugin": "^5.8.1", "@typescript-eslint/parser": "^5.8.1", + "@waku/interfaces": "*", "app-root-path": "^3.0.0", "chai": "^4.3.4", "cspell": "^5.14.0", @@ -26742,11 +26913,10 @@ "puppeteer": "^13.0.1", "rollup": "^2.75.0", "semantic-release": "^19.0.5", - "semantic-release-monorepo": "*", + "semantic-release-monorepo": "^7.0.5", "tail": "^2.2.0", "ts-loader": "^9.3.1", "ts-node": "^10.9.1", - "typedoc": "^0.23.10", "typescript": "^4.6.3", "uint8arraylist": "^2.3.2", "uint8arrays": "^3.0.0", @@ -26783,6 +26953,128 @@ } } }, + "@waku/create": { + "version": "file:packages/create", + "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", + "@waku/core": "*", + "@waku/interfaces": "*", + "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" + } + }, + "@waku/interfaces": { + "version": "file:packages/interfaces", + "requires": { + "@chainsafe/libp2p-gossipsub": "^4.1.1", + "@libp2p/interface-connection": "^3.0.2", + "@libp2p/interface-peer-id": "^1.0.5", + "@libp2p/interface-peer-store": "^1.2.2", + "@multiformats/multiaddr": "^11.0.6", + "@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", + "libp2p": "0.38.0", + "npm-run-all": "^4.1.5", + "prettier": "^2.1.1", + "semantic-release": "^19.0.5", + "semantic-release-monorepo": "^7.0.5", + "typescript": "^4.6.3" + }, + "dependencies": { + "@libp2p/interface-connection": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@libp2p/interface-connection/-/interface-connection-3.0.2.tgz", + "integrity": "sha512-38R2GQ6BCOtwMi5uWU5MLr+xfEpRmVK9gqOp7jNx+6T7TVn8ji4725XLXNfpzprbOrzZkqf2iER84s8+yX4pMA==", + "requires": { + "@libp2p/interface-peer-id": "^1.0.0", + "@libp2p/interfaces": "^3.0.0", + "@multiformats/multiaddr": "^11.0.0", + "it-stream-types": "^1.0.4", + "uint8arraylist": "^2.1.1" + } + }, + "@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/tests": { + "version": "file:packages/tests", + "requires": { + "@typescript-eslint/eslint-plugin": "^5.8.1", + "@typescript-eslint/parser": "^5.8.1", + "@waku/core": "*", + "@waku/create": "*", + "@waku/interfaces": "*", + "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", + "typescript": "^4.6.3" + } + }, "@webassemblyjs/ast": { "version": "1.11.1", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.1.tgz", diff --git a/package.json b/package.json index dcd72a79f2..e596fd9995 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,9 @@ "test:browser": "lerna run test:browser", "test:node": "lerna run test:node", "proto": "lerna run proto", - "doc": "lerna run doc", + "doc": "run-s doc:*", + "doc:html": "typedoc # --treatWarningsAsErrors", + "doc:cname": "echo 'js.waku.org' > docs/CNAME", "release": "lerna run --concurrency 1 release -- --" }, "devDependencies": { @@ -22,7 +24,8 @@ "husky": "^8.0.1", "lerna": "^6.0.1", "lint-staged": "^13.0.3", - "size-limit": "^8.1.0" + "size-limit": "^8.1.0", + "typedoc": "^0.23.19" }, "lint-staged": { "*.ts": [ diff --git a/packages/core/package.json b/packages/core/package.json index fbe8d1676d..f49a3064f1 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -9,12 +9,9 @@ "types": "./dist/index.d.ts", "import": "./dist/index.js" }, - "./lib/create_waku": { - "types": "./dist/lib/create_waku.d.ts", - "import": "./dist/lib/create_waku.js" - }, - "./lib/interfaces": { - "types": "./dist/lib/interfaces.d.ts" + "./lib/enr": { + "types": "./dist/lib/enr/index.d.ts", + "import": "./dist/lib/enr/index.js" }, "./lib/peer_discovery_dns": { "types": "./dist/lib/peer_discovery_dns/index.d.ts", @@ -28,6 +25,10 @@ "types": "./dist/lib/predefined_bootstrap_nodes.d.ts", "import": "./dist/lib/predefined_bootstrap_nodes.js" }, + "./lib/utils": { + "types": "./dist/lib/utils.d.ts", + "import": "./dist/lib/utils.js" + }, "./lib/wait_for_remote_peer": { "types": "./dist/lib/wait_for_remote_peer.d.ts", "import": "./dist/lib/wait_for_remote_peer.js" @@ -83,19 +84,16 @@ "nwaku:build": "(PROC=$(nproc --all 2>/dev/null || echo 2); cd ../../nwaku; make -j$PROC update; NIMFLAGS=\"-d:chronicles_colors=off -d:chronicles_sinks=textlines -d:chronicles_log_level=TRACE\" make -j$PROC wakunode2)", "nwaku:force-build": "(cd ../../nwaku && rm -rf ./build/ ./vendor) && run-s nwaku:build", "check": "run-s check:*", + "check:tsc": "tsc -p tsconfig.dev.json", "check:lint": "eslint src --ext .ts", "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", "proto": "rimraf src/proto/*.ts; protons src/proto/*.proto", "watch:build": "tsc -p tsconfig.json -w", "watch:test": "mocha --watch", - "doc": "run-s doc:*", - "doc:html": "typedoc --treatWarningsAsErrors", - "doc:cname": "echo 'js.waku.org' > build/docs/CNAME", "prepublish": "npm run build", "deploy": "node ci/deploy.js", "reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build", @@ -124,6 +122,7 @@ "@libp2p/websockets": "^3.0.3", "@multiformats/multiaddr": "^11.0.6", "@noble/secp256k1": "^1.3.4", + "@waku/interfaces": "*", "debug": "^4.3.4", "dns-query": "^0.11.2", "hi-base32": "^0.5.1", @@ -191,7 +190,6 @@ "tail": "^2.2.0", "ts-loader": "^9.3.1", "ts-node": "^10.9.1", - "typedoc": "^0.23.10", "typescript": "^4.6.3" }, "release": { @@ -207,7 +205,7 @@ "releaseRules": [ { "breaking": true, - "release": "major" + "release": "patch" }, { "revert": true, @@ -215,7 +213,7 @@ }, { "type": "feat", - "release": "minor" + "release": "patch" }, { "type": "fix", @@ -276,6 +274,9 @@ "@semantic-release/git" ] }, + "typedoc": { + "entryPoint": "./src/index.ts" + }, "files": [ "dist", "bundle", diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js index c4867c7c61..4b2cd71a2d 100644 --- a/packages/core/rollup.config.js +++ b/packages/core/rollup.config.js @@ -5,10 +5,11 @@ import json from "@rollup/plugin-json"; export default { input: { index: "dist/index.js", - "lib/create_waku": "dist/lib/create_waku.js", + "lib/enr": "dist/lib/enr/index.js", "lib/peer_discovery_dns": "dist/lib/peer_discovery_dns/index.js", "lib/peer_discovery_static_list": "dist/lib/peer_discovery_static_list.js", "lib/predefined_bootstrap_nodes": "dist/lib/predefined_bootstrap_nodes.js", + "lib/utils": "dist/lib/utils.js", "lib/wait_for_remote_peer": "dist/lib/wait_for_remote_peer.js", "lib/waku_message/version_0": "dist/lib/waku_message/version_0.js", "lib/waku_message/version_1": "dist/lib/waku_message/version_1.js", diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index f78145d5a3..cef0c3a427 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -14,7 +14,7 @@ export * as proto_message from "./proto/message"; export * as proto_topic_only_message from "./proto/topic_only_message"; export * as waku from "./lib/waku"; -export { WakuNode, Protocols } from "./lib/waku"; +export { WakuNode } from "./lib/waku"; export * as waku_filter from "./lib/waku_filter"; export { WakuFilter } from "./lib/waku_filter"; diff --git a/packages/core/src/lib/interfaces.ts b/packages/core/src/lib/interfaces.ts deleted file mode 100644 index 3d158de236..0000000000 --- a/packages/core/src/lib/interfaces.ts +++ /dev/null @@ -1,93 +0,0 @@ -import type { Stream } from "@libp2p/interface-connection"; -import type { PeerId } from "@libp2p/interface-peer-id"; -import type { Multiaddr } from "@multiformats/multiaddr"; -import type { Libp2p } from "libp2p"; - -import type { Protocols } from "./waku"; -import type { WakuFilter } from "./waku_filter"; -import type { WakuLightPush } from "./waku_light_push"; -import type { WakuRelay } from "./waku_relay"; -import type { WakuStore } from "./waku_store"; - -export interface Waku { - libp2p: Libp2p; - relay?: WakuRelay; - store?: WakuStore; - filter?: WakuFilter; - lightPush?: WakuLightPush; - - dial(peer: PeerId | Multiaddr, protocols?: Protocols[]): Promise; - - addPeerToAddressBook( - peerId: PeerId | string, - multiaddrs: Multiaddr[] | string[] - ): void; - - start(): Promise; - - stop(): Promise; - - isStarted(): boolean; -} - -export interface WakuLight extends Waku { - relay: undefined; - store: WakuStore; - filter: WakuFilter; - lightPush: WakuLightPush; -} - -export interface WakuPrivacy extends Waku { - relay: WakuRelay; - store: undefined; - filter: undefined; - lightPush: undefined; -} - -export interface WakuFull extends Waku { - relay: WakuRelay; - store: WakuStore; - filter: WakuFilter; - lightPush: WakuLightPush; -} - -export interface RateLimitProof { - proof: Uint8Array; - merkleRoot: Uint8Array; - epoch: Uint8Array; - shareX: Uint8Array; - shareY: Uint8Array; - nullifier: Uint8Array; - rlnIdentifier: Uint8Array; -} - -export interface ProtoMessage { - payload: Uint8Array | undefined; - contentTopic: string | undefined; - version: number | undefined; - timestamp: bigint | undefined; - rateLimitProof: RateLimitProof | undefined; -} - -export interface Message { - payload: Uint8Array | undefined; - contentTopic: string | undefined; - timestamp: Date | undefined; - rateLimitProof: RateLimitProof | undefined; -} - -export interface Encoder { - contentTopic: string; - toWire: (message: Partial) => Promise; - toProtoObj: (message: Partial) => Promise; -} - -export interface Decoder { - contentTopic: string; - fromWireToProtoObj: (bytes: Uint8Array) => Promise; - fromProtoObj: (proto: ProtoMessage) => Promise; -} - -export interface SendResult { - recipients: PeerId[]; -} diff --git a/packages/core/src/lib/to_proto_message.ts b/packages/core/src/lib/to_proto_message.ts index edb8a7695d..a2a60fd0c4 100644 --- a/packages/core/src/lib/to_proto_message.ts +++ b/packages/core/src/lib/to_proto_message.ts @@ -1,6 +1,6 @@ -import { WakuMessage as WakuMessageProto } from "../proto/message"; +import { ProtoMessage } from "@waku/interfaces"; -import { ProtoMessage } from "./interfaces"; +import { WakuMessage as WakuMessageProto } from "../proto/message"; const EmptyMessage: ProtoMessage = { payload: undefined, diff --git a/packages/core/src/lib/wait_for_remote_peer.ts b/packages/core/src/lib/wait_for_remote_peer.ts index dd58bc13d3..caa254239a 100644 --- a/packages/core/src/lib/wait_for_remote_peer.ts +++ b/packages/core/src/lib/wait_for_remote_peer.ts @@ -1,26 +1,15 @@ -import type { GossipSub } from "@chainsafe/libp2p-gossipsub"; -import { Peer, PeerProtocolsChangeData } from "@libp2p/interface-peer-store"; +import { PeerProtocolsChangeData } from "@libp2p/interface-peer-store"; +import type { PointToPointProtocol, Relay, Waku } from "@waku/interfaces"; +import { Protocols } from "@waku/interfaces"; import debug from "debug"; -import type { Libp2p } from "libp2p"; import { pEvent } from "p-event"; -import type { Waku } from "./interfaces"; -import { Protocols } from "./waku"; import { FilterCodec } from "./waku_filter"; import { LightPushCodec } from "./waku_light_push"; import { StoreCodec } from "./waku_store"; const log = debug("waku:wait-for-remote-peer"); -interface WakuProtocol { - libp2p: Libp2p; - peers: () => Promise; -} - -interface WakuGossipSubProtocol extends GossipSub { - getMeshPeers: () => string[]; -} - /** * Wait for a remote peer to be ready given the passed protocols. * Must be used after attempting to connect to nodes, using @@ -90,7 +79,7 @@ export async function waitForRemotePeer( * Wait for a peer with the given protocol to be connected. */ async function waitForConnectedPeer( - waku: WakuProtocol, + waku: PointToPointProtocol, codecs: string[] ): Promise { const peers = await waku.peers(); @@ -119,9 +108,7 @@ async function waitForConnectedPeer( * Wait for a peer with the given protocol to be connected and in the gossipsub * mesh. */ -async function waitForGossipSubPeerInMesh( - waku: WakuGossipSubProtocol -): Promise { +async function waitForGossipSubPeerInMesh(waku: Relay): Promise { let peers = waku.getMeshPeers(); while (peers.length == 0) { diff --git a/packages/core/src/lib/waku.spec.ts b/packages/core/src/lib/waku.spec.ts deleted file mode 100644 index efde19c331..0000000000 --- a/packages/core/src/lib/waku.spec.ts +++ /dev/null @@ -1,43 +0,0 @@ -import type { PeerId } from "@libp2p/interface-peer-id"; -import { expect } from "chai"; - -import { createWaku } from "./create_waku"; -import type { Waku } from "./interfaces"; - -describe("Waku Dial", function () { - describe("Bootstrap [live data]", function () { - let waku: Waku; - - afterEach(function () { - !!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e)); - }); - - before(function () { - if (process.env.CI) { - this.skip(); - } - }); - - it("Enabling default [live data]", async function () { - // This test depends on fleets.status.im being online. - // This dependence must be removed once DNS discovery is implemented - this.timeout(20_000); - - waku = await createWaku({ - defaultBootstrap: true, - }); - await waku.start(); - - const connectedPeerID: PeerId = await new Promise((resolve) => { - waku.libp2p.connectionManager.addEventListener( - "peer:connect", - (evt) => { - resolve(evt.detail.remotePeer); - } - ); - }); - - expect(connectedPeerID).to.not.be.undefined; - }); - }); -}); diff --git a/packages/core/src/lib/waku.ts b/packages/core/src/lib/waku.ts index ca8449c02c..f792eb6c56 100644 --- a/packages/core/src/lib/waku.ts +++ b/packages/core/src/lib/waku.ts @@ -4,10 +4,11 @@ import type { PubSub } from "@libp2p/interface-pubsub"; import { peerIdFromString } from "@libp2p/peer-id"; import type { Multiaddr } from "@multiformats/multiaddr"; import { multiaddr } from "@multiformats/multiaddr"; +import type { Waku } from "@waku/interfaces"; +import { Protocols } from "@waku/interfaces"; import debug from "debug"; import type { Libp2p } from "libp2p"; -import { Waku } from "./interfaces"; import { FilterCodec, WakuFilter } from "./waku_filter"; import { LightPushCodec, WakuLightPush } from "./waku_light_push"; import { EncoderV0 } from "./waku_message/version_0"; @@ -21,13 +22,6 @@ export const DefaultRelayKeepAliveValueSecs = 5 * 60; const log = debug("waku:waku"); -export enum Protocols { - Relay = "relay", - Store = "store", - LightPush = "lightpush", - Filter = "filter", -} - export interface WakuOptions { /** * Set keep alive frequency in seconds: Waku will send a `/ipfs/ping/1.0.0` diff --git a/packages/core/src/lib/waku_filter/index.ts b/packages/core/src/lib/waku_filter/index.ts index 65e6b45981..a2f9c3c7d6 100644 --- a/packages/core/src/lib/waku_filter/index.ts +++ b/packages/core/src/lib/waku_filter/index.ts @@ -2,6 +2,13 @@ import type { Stream } from "@libp2p/interface-connection"; import type { PeerId } from "@libp2p/interface-peer-id"; import type { Peer } from "@libp2p/interface-peer-store"; import type { IncomingStreamData } from "@libp2p/interface-registrar"; +import type { + Callback, + Decoder, + Filter, + Message, + ProtocolOptions, +} from "@waku/interfaces"; import debug from "debug"; import all from "it-all"; import * as lp from "it-length-prefixed"; @@ -11,7 +18,6 @@ import type { Libp2p } from "libp2p"; import { WakuMessage as WakuMessageProto } from "../../proto/message"; import { DefaultPubSubTopic } from "../constants"; import { groupByContentTopic } from "../group_by"; -import { Decoder, Message } from "../interfaces"; import { selectConnection } from "../select_connection"; import { getPeersForProtocol, @@ -39,21 +45,6 @@ export interface CreateOptions { pubSubTopic?: string; } -export type FilterSubscriptionOpts = { - /** - * The Pubsub topic for the subscription - */ - pubsubTopic?: string; - /** - * Optionally specify a PeerId for the subscription. If not included, will use a random peer. - */ - peerId?: PeerId; -}; - -export type FilterCallback = ( - msg: T -) => void | Promise; - export type UnsubscribeFunction = () => Promise; /** @@ -63,9 +54,9 @@ export type UnsubscribeFunction = () => Promise; * - https://github.com/status-im/go-waku/issues/245 * - https://github.com/status-im/nwaku/issues/948 */ -export class WakuFilter { +export class WakuFilter implements Filter { pubSubTopic: string; - private subscriptions: Map>; + private subscriptions: Map>; private decoders: Map< string, // content topic Set> @@ -88,10 +79,10 @@ export class WakuFilter { */ async subscribe( decoders: Decoder[], - callback: FilterCallback, - opts?: FilterSubscriptionOpts + callback: Callback, + opts?: ProtocolOptions ): Promise { - const topic = opts?.pubsubTopic ?? this.pubSubTopic; + const topic = opts?.pubSubTopic ?? this.pubSubTopic; const groupedDecoders = groupByContentTopic(decoders); const contentTopics = Array.from(groupedDecoders.keys()); @@ -212,7 +203,7 @@ export class WakuFilter { } } - private addCallback(requestId: string, callback: FilterCallback): void { + private addCallback(requestId: string, callback: Callback): void { this.subscriptions.set(requestId, callback); } diff --git a/packages/core/src/lib/waku_light_push/index.ts b/packages/core/src/lib/waku_light_push/index.ts index 0674213dcd..78600fe9d2 100644 --- a/packages/core/src/lib/waku_light_push/index.ts +++ b/packages/core/src/lib/waku_light_push/index.ts @@ -1,5 +1,11 @@ import type { PeerId } from "@libp2p/interface-peer-id"; import type { Peer } from "@libp2p/interface-peer-store"; +import type { + Encoder, + Message, + ProtocolOptions, + SendResult, +} from "@waku/interfaces"; import debug from "debug"; import all from "it-all"; import * as lp from "it-length-prefixed"; @@ -9,7 +15,6 @@ import { Uint8ArrayList } from "uint8arraylist"; import { PushResponse } from "../../proto/light_push"; import { DefaultPubSubTopic } from "../constants"; -import { Encoder, Message, SendResult } from "../interfaces"; import { selectConnection } from "../select_connection"; import { getPeersForProtocol, @@ -36,11 +41,6 @@ export interface CreateOptions { pubSubTopic?: string; } -export interface PushOptions { - peerId?: PeerId; - pubSubTopic?: string; -} - /** * Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/). */ @@ -54,7 +54,7 @@ export class WakuLightPush { async push( encoder: Encoder, message: Partial, - opts?: PushOptions + opts?: ProtocolOptions ): Promise { const pubSubTopic = opts?.pubSubTopic ? opts.pubSubTopic : this.pubSubTopic; diff --git a/packages/core/src/lib/waku_message/topic_only_message.ts b/packages/core/src/lib/waku_message/topic_only_message.ts index f72bb8bd63..9514847d21 100644 --- a/packages/core/src/lib/waku_message/topic_only_message.ts +++ b/packages/core/src/lib/waku_message/topic_only_message.ts @@ -1,7 +1,7 @@ +import type { Decoder, Message, ProtoMessage } from "@waku/interfaces"; import debug from "debug"; import * as proto from "../../proto/topic_only_message"; -import type { Decoder, Message, ProtoMessage } from "../interfaces"; const log = debug("waku:message:topic-only"); diff --git a/packages/core/src/lib/waku_message/version_0.ts b/packages/core/src/lib/waku_message/version_0.ts index aa83150f8d..4220a20c9c 100644 --- a/packages/core/src/lib/waku_message/version_0.ts +++ b/packages/core/src/lib/waku_message/version_0.ts @@ -1,8 +1,13 @@ +import type { + Decoder, + Encoder, + Message, + ProtoMessage, + RateLimitProof, +} from "@waku/interfaces"; import debug from "debug"; import * as proto from "../../proto/message"; -import { Decoder, Message, ProtoMessage, RateLimitProof } from "../interfaces"; -import { Encoder } from "../interfaces"; const log = debug("waku:message:version-0"); diff --git a/packages/core/src/lib/waku_message/version_1.ts b/packages/core/src/lib/waku_message/version_1.ts index 0a9a6117c6..3b6d46a8e3 100644 --- a/packages/core/src/lib/waku_message/version_1.ts +++ b/packages/core/src/lib/waku_message/version_1.ts @@ -1,9 +1,9 @@ import * as secp from "@noble/secp256k1"; +import type { Decoder, Encoder, Message, ProtoMessage } from "@waku/interfaces"; import debug from "debug"; import * as proto from "../../proto/message"; import { keccak256, randomBytes, sign } from "../crypto"; -import { Decoder, Encoder, Message, ProtoMessage } from "../interfaces"; import { concat, hexToBytes } from "../utils"; import { Symmetric } from "./constants"; diff --git a/packages/core/src/lib/waku_relay/index.ts b/packages/core/src/lib/waku_relay/index.ts index b5cbeb48e6..420bf10cbe 100644 --- a/packages/core/src/lib/waku_relay/index.ts +++ b/packages/core/src/lib/waku_relay/index.ts @@ -8,10 +8,17 @@ import { TopicStr, } from "@chainsafe/libp2p-gossipsub/dist/src/types"; import { SignaturePolicy } from "@chainsafe/libp2p-gossipsub/types"; +import type { + Callback, + Decoder, + Encoder, + Message, + Relay, + SendResult, +} from "@waku/interfaces"; import debug from "debug"; import { DefaultPubSubTopic } from "../constants"; -import { Decoder, Encoder, Message, SendResult } from "../interfaces"; import { pushOrInitMapSet } from "../push_or_init_map"; import { TopicOnlyDecoder } from "../waku_message/topic_only_message"; @@ -19,8 +26,6 @@ import * as constants from "./constants"; const log = debug("waku:relay"); -export type Callback = (msg: T) => void; - export type Observer = { decoder: Decoder; callback: Callback; @@ -49,7 +54,7 @@ export type CreateOptions = { * * @implements {require('libp2p-interfaces/src/pubsub')} */ -export class WakuRelay extends GossipSub { +export class WakuRelay extends GossipSub implements Relay { pubSubTopic: string; defaultDecoder: Decoder; public static multicodec: string = constants.RelayCodecs[0]; diff --git a/packages/core/src/lib/waku_store/index.ts b/packages/core/src/lib/waku_store/index.ts index 9a7f833b1f..9f02bec8dd 100644 --- a/packages/core/src/lib/waku_store/index.ts +++ b/packages/core/src/lib/waku_store/index.ts @@ -1,6 +1,7 @@ import type { Connection } from "@libp2p/interface-connection"; import type { PeerId } from "@libp2p/interface-peer-id"; import { Peer } from "@libp2p/interface-peer-store"; +import { Decoder, Message } from "@waku/interfaces"; import debug from "debug"; import all from "it-all"; import * as lp from "it-length-prefixed"; @@ -10,7 +11,6 @@ import { Uint8ArrayList } from "uint8arraylist"; import * as proto from "../../proto/store"; import { DefaultPubSubTopic } from "../constants"; -import { Decoder, Message } from "../interfaces"; import { selectConnection } from "../select_connection"; import { getPeersForProtocol, selectPeerForProtocol } from "../select_peer"; import { toProtoMessage } from "../to_proto_message"; diff --git a/packages/core/typedoc.json b/packages/core/typedoc.json deleted file mode 100644 index 31019f4fff..0000000000 --- a/packages/core/typedoc.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "entryPoints": [ - "./src/index.ts", - "./src/lib/create_waku.ts", - "./src/lib/interfaces.ts", - "./src/lib/peer_discovery_dns.ts", - "./src/lib/peer_discovery_static_list.ts", - "./src/lib/predefined_bootstrap_nodes.ts", - "./src/lib/wait_for_remote_peer.ts", - "./src/lib/waku_message/version_0.ts", - "./src/lib/waku_message/version_1.ts", - "./src/lib/waku_message/topic_only_message.ts" - ], - "out": "build/docs", - "exclude": ["**/*.spec.ts"], - "excludeInternal": true, - "validation": { - "invalidLink": true, - "notExported": true - } -} diff --git a/packages/create/.eslintrc.cjs b/packages/create/.eslintrc.cjs new file mode 100644 index 0000000000..324f1f526d --- /dev/null +++ b/packages/create/.eslintrc.cjs @@ -0,0 +1,6 @@ +module.exports = { + parserOptions: { + tsconfigRootDir: __dirname, + project: "./tsconfig.dev.json", + }, +}; diff --git a/packages/create/.prettierignore b/packages/create/.prettierignore new file mode 100644 index 0000000000..fecb37a393 --- /dev/null +++ b/packages/create/.prettierignore @@ -0,0 +1,4 @@ +build +bundle +dist +node_modules diff --git a/packages/create/package.json b/packages/create/package.json new file mode 100644 index 0000000000..c092b0bebe --- /dev/null +++ b/packages/create/package.json @@ -0,0 +1,180 @@ +{ + "name": "@waku/create", + "version": "0.0.1", + "description": "Easily create a Waku node", + "types": "./dist/index.d.ts", + "module": "./dist/index.js", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js" + } + }, + "type": "module", + "author": "Waku Team", + "homepage": "https://github.com/waku-org/js-waku/tree/master/packages/create#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", + "decentralized", + "secure", + "communication", + "web3", + "ethereum", + "dapps", + "privacy" + ], + "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 --ext .ts --ext .cjs --fix", + "check": "run-s check:*", + "check:lint": "eslint src --ext .ts", + "check:prettier": "prettier . --list-different", + "check:spelling": "cspell \"{README.md,src/**/*.ts}\"", + "check:tsc": "tsc -p tsconfig.dev.json", + "prepublish": "npm run build", + "reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build", + "release": "semantic-release" + }, + "engines": { + "node": ">=16" + }, + "dependencies": { + "@waku/core": "*", + "@waku/interfaces": "*" + }, + "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" + }, + "release": { + "branches": [ + "master" + ], + "extends": "semantic-release-monorepo", + "plugins": [ + [ + "@semantic-release/commit-analyzer", + { + "preset": "conventionalcommits", + "releaseRules": [ + { + "breaking": true, + "release": "patch" + }, + { + "revert": true, + "release": "patch" + }, + { + "type": "feat", + "release": "patch" + }, + { + "type": "fix", + "release": "patch" + }, + { + "type": "doc", + "release": "patch" + }, + { + "type": "test", + "release": "patch" + }, + { + "scope": "deps", + "release": "patch" + }, + { + "scope": "no-release", + "release": false + } + ] + } + ], + [ + "@semantic-release/release-notes-generator", + { + "preset": "conventionalcommits", + "presetConfig": { + "types": [ + { + "type": "feat", + "section": "Features" + }, + { + "type": "fix", + "section": "Bug Fixes" + }, + { + "type": "chore", + "section": "Trivial Changes" + }, + { + "type": "doc", + "section": "Documentation" + }, + { + "type": "test", + "section": "Tests" + } + ] + } + } + ], + "@semantic-release/changelog", + "@semantic-release/npm", + "@semantic-release/github", + "@semantic-release/git" + ] + }, + "typedoc": { + "entryPoint": "./src/index.ts" + }, + "files": [ + "dist", + "bundle", + "src/*.ts", + "src/lib/**/*.ts", + "src/proto/**/*.ts", + "!**/*.spec.*", + "!**/*.json", + "CHANGELOG.md", + "LICENSE", + "README.md" + ] +} diff --git a/packages/create/rollup.config.js b/packages/create/rollup.config.js new file mode 100644 index 0000000000..a03dc334f0 --- /dev/null +++ b/packages/create/rollup.config.js @@ -0,0 +1,21 @@ +import { nodeResolve } from "@rollup/plugin-node-resolve"; +import commonjs from "@rollup/plugin-commonjs"; +import json from "@rollup/plugin-json"; + +export default { + input: { + index: "dist/index.js", + }, + output: { + dir: "bundle", + format: "esm", + }, + plugins: [ + commonjs(), + json(), + nodeResolve({ + browser: true, + preferBuiltins: false, + }), + ], +}; diff --git a/packages/core/src/lib/create_waku.ts b/packages/create/src/index.ts similarity index 78% rename from packages/core/src/lib/create_waku.ts rename to packages/create/src/index.ts index f0c1d2c8ee..89a6015f4e 100644 --- a/packages/core/src/lib/create_waku.ts +++ b/packages/create/src/index.ts @@ -3,17 +3,23 @@ import type { PeerDiscovery } from "@libp2p/interface-peer-discovery"; import { Mplex } from "@libp2p/mplex"; import { WebSockets } from "@libp2p/websockets"; import { all as filterAll } from "@libp2p/websockets/filters"; -import { createLibp2p, Libp2pOptions } from "libp2p"; +import { + waku, + waku_relay, + WakuFilter, + WakuLightPush, + WakuNode, + WakuRelay, + WakuStore, +} from "@waku/core"; +import { PeerDiscoveryStaticPeers } from "@waku/core/lib/peer_discovery_static_list"; +import { getPredefinedBootstrapNodes } from "@waku/core/lib/predefined_bootstrap_nodes"; +import type { WakuFull, WakuLight, WakuPrivacy } from "@waku/interfaces"; import type { Libp2p } from "libp2p"; +import { createLibp2p, Libp2pOptions } from "libp2p"; -import type { Waku, WakuFull, WakuLight, WakuPrivacy } from "./interfaces"; -import { PeerDiscoveryStaticPeers } from "./peer_discovery_static_list"; -import { getPredefinedBootstrapNodes } from "./predefined_bootstrap_nodes"; -import { WakuNode, WakuOptions } from "./waku"; -import { WakuFilter } from "./waku_filter"; -import { WakuLightPush } from "./waku_light_push"; -import { CreateOptions as RelayCreateOptions, WakuRelay } from "./waku_relay"; -import { WakuStore } from "./waku_store"; +type WakuOptions = waku.WakuOptions; +type RelayCreateOptions = waku_relay.CreateOptions; export interface CreateOptions { /** @@ -26,8 +32,6 @@ export interface CreateOptions { * * The usage of the default pubsub topic is recommended. * See [Waku v2 Topic Usage Recommendations](https://rfc.vac.dev/spec/23/) for details. - * - * @default {@link index.DefaultPubSubTopic} */ pubSubTopic?: string; /** @@ -139,35 +143,6 @@ export async function createFullNode( ) as WakuFull; } -/** - * @deprecated use { @link createLightNode }, { @link createPrivacyNode } or - * { @link index.waku.WakuNode.constructor } instead. - */ -export async function createWaku( - options?: CreateOptions & WakuOptions & Partial -): Promise { - const libp2pOptions = options?.libp2p ?? {}; - const peerDiscovery = libp2pOptions.peerDiscovery ?? []; - if (options?.defaultBootstrap) { - peerDiscovery.push(defaultPeerDiscovery()); - Object.assign(libp2pOptions, { peerDiscovery }); - } - - const libp2p = await defaultLibp2p(new WakuRelay(options), libp2pOptions); - - const wakuStore = new WakuStore(libp2p, options); - const wakuLightPush = new WakuLightPush(libp2p, options); - const wakuFilter = new WakuFilter(libp2p, options); - - return new WakuNode( - options ?? {}, - libp2p, - wakuStore, - wakuLightPush, - wakuFilter - ); -} - export function defaultPeerDiscovery(): PeerDiscovery { return new PeerDiscoveryStaticPeers(getPredefinedBootstrapNodes()); } diff --git a/packages/create/tsconfig.dev.json b/packages/create/tsconfig.dev.json new file mode 100644 index 0000000000..ffc27ef6ba --- /dev/null +++ b/packages/create/tsconfig.dev.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig", + "compilerOptions": { + "module": "esnext", + "noEmit": true + }, + "exclude": [] +} diff --git a/packages/create/tsconfig.json b/packages/create/tsconfig.json new file mode 100644 index 0000000000..7b01b30897 --- /dev/null +++ b/packages/create/tsconfig.json @@ -0,0 +1,54 @@ +{ + "compilerOptions": { + "incremental": true, + "target": "es2020", + "outDir": "dist/", + "rootDir": "src", + "moduleResolution": "node", + "module": "es2020", + "declaration": true, + "sourceMap": true, + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, + "resolveJsonModule": true /* Include modules imported with .json extension. */, + "tsBuildInfoFile": "dist/.tsbuildinfo", + "strict": true /* Enable all strict type-checking options. */, + + /* Strict Type-Checking Options */ + "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */, + "strictNullChecks": true /* Enable strict null checks. */, + "strictFunctionTypes": true /* Enable strict checking of function types. */, + "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */, + "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */, + "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */, + + /* Additional Checks */ + "noUnusedLocals": true /* Report errors on unused locals. */, + "noUnusedParameters": true /* Report errors on unused parameters. */, + "noImplicitReturns": true /* Report error when not all code paths in function return a value. */, + "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */, + "forceConsistentCasingInFileNames": true, + + /* Debugging Options */ + "traceResolution": false /* Report module resolution log messages. */, + "listEmittedFiles": false /* Print names of generated files part of the compilation. */, + "listFiles": false /* Print names of files part of the compilation. */, + "pretty": true /* Stylize errors and messages using color and context. */, + + // Due to broken types in indirect dependencies + "skipLibCheck": true, + + /* Experimental Options */ + // "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */, + // "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */, + + "lib": ["es2020", "dom"], + "types": ["node", "mocha"], + "typeRoots": ["node_modules/@types", "src/types"] + }, + "include": ["src"], + "exclude": ["src/**/*.spec.ts", "src/test_utils"], + "compileOnSave": false, + "ts-node": { + "files": true + } +} diff --git a/packages/interfaces/.eslintrc.cjs b/packages/interfaces/.eslintrc.cjs new file mode 100644 index 0000000000..324f1f526d --- /dev/null +++ b/packages/interfaces/.eslintrc.cjs @@ -0,0 +1,6 @@ +module.exports = { + parserOptions: { + tsconfigRootDir: __dirname, + project: "./tsconfig.dev.json", + }, +}; diff --git a/packages/interfaces/.prettierignore b/packages/interfaces/.prettierignore new file mode 100644 index 0000000000..fecb37a393 --- /dev/null +++ b/packages/interfaces/.prettierignore @@ -0,0 +1,4 @@ +build +bundle +dist +node_modules diff --git a/packages/interfaces/package.json b/packages/interfaces/package.json new file mode 100644 index 0000000000..79abebd2e3 --- /dev/null +++ b/packages/interfaces/package.json @@ -0,0 +1,178 @@ +{ + "name": "@waku/interfaces", + "version": "0.0.1", + "description": "Definition of Waku interfaces", + "types": "./dist/index.d.ts", + "module": "./dist/index.js", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js" + } + }, + "type": "module", + "author": "Waku Team", + "homepage": "https://github.com/waku-org/js-waku/tree/master/packages/interfaces#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", + "decentralized", + "secure", + "communication", + "web3", + "ethereum", + "dapps", + "privacy" + ], + "scripts": { + "build": "tsc", + "fix": "run-s fix:*", + "fix:prettier": "prettier . --write", + "fix:lint": "eslint src --ext .ts --ext .cjs --fix", + "check": "run-s check:*", + "check:lint": "eslint src --ext .ts", + "check:prettier": "prettier . --list-different", + "check:spelling": "cspell \"{README.md,src/**/*.ts}\"", + "check:tsc": "tsc -p tsconfig.dev.json", + "prepublish": "npm run build", + "reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build", + "release": "semantic-release" + }, + "engines": { + "node": ">=16" + }, + "dependencies": { + "@chainsafe/libp2p-gossipsub": "^4.1.1", + "@libp2p/interface-connection": "^3.0.2", + "@libp2p/interface-peer-id": "^1.0.5", + "@libp2p/interface-peer-store": "^1.2.2", + "@multiformats/multiaddr": "^11.0.6", + "libp2p": "0.38.0" + }, + "devDependencies": { + "@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", + "semantic-release": "^19.0.5", + "semantic-release-monorepo": "^7.0.5", + "typescript": "^4.6.3" + }, + "release": { + "branches": [ + "master" + ], + "extends": "semantic-release-monorepo", + "plugins": [ + [ + "@semantic-release/commit-analyzer", + { + "preset": "conventionalcommits", + "releaseRules": [ + { + "breaking": true, + "release": "patch" + }, + { + "revert": true, + "release": "patch" + }, + { + "type": "feat", + "release": "patch" + }, + { + "type": "fix", + "release": "patch" + }, + { + "type": "doc", + "release": "patch" + }, + { + "type": "test", + "release": "patch" + }, + { + "scope": "deps", + "release": "patch" + }, + { + "scope": "no-release", + "release": false + } + ] + } + ], + [ + "@semantic-release/release-notes-generator", + { + "preset": "conventionalcommits", + "presetConfig": { + "types": [ + { + "type": "feat", + "section": "Features" + }, + { + "type": "fix", + "section": "Bug Fixes" + }, + { + "type": "chore", + "section": "Trivial Changes" + }, + { + "type": "doc", + "section": "Documentation" + }, + { + "type": "test", + "section": "Tests" + } + ] + } + } + ], + "@semantic-release/changelog", + "@semantic-release/npm", + "@semantic-release/github", + "@semantic-release/git" + ] + }, + "typedoc": { + "entryPoint": "./src/index.ts" + }, + "files": [ + "dist", + "bundle", + "src/*.ts", + "src/lib/**/*.ts", + "src/proto/**/*.ts", + "!**/*.spec.*", + "!**/*.json", + "CHANGELOG.md", + "LICENSE", + "README.md" + ] +} diff --git a/packages/interfaces/src/index.ts b/packages/interfaces/src/index.ts new file mode 100644 index 0000000000..f95555a6aa --- /dev/null +++ b/packages/interfaces/src/index.ts @@ -0,0 +1,187 @@ +import type { GossipSub } from "@chainsafe/libp2p-gossipsub"; +import type { Stream } from "@libp2p/interface-connection"; +import type { PeerId } from "@libp2p/interface-peer-id"; +import type { Peer } from "@libp2p/interface-peer-store"; +import type { Multiaddr } from "@multiformats/multiaddr"; +import type { Libp2p } from "libp2p"; + +export enum Protocols { + Relay = "relay", + Store = "store", + LightPush = "lightpush", + Filter = "filter", +} + +export interface PointToPointProtocol { + libp2p: Libp2p; + peers: () => Promise; +} + +export type ProtocolOptions = { + pubSubTopic?: string; + /** + * Optionally specify an PeerId for the protocol request. If not included, will use a random peer. + */ + peerId?: PeerId; +}; + +export type Callback = (msg: T) => void | Promise; + +export interface Filter extends PointToPointProtocol { + subscribe: ( + decoders: Decoder[], + callback: Callback, + opts?: ProtocolOptions + ) => Promise<() => Promise>; +} + +export interface LightPush extends PointToPointProtocol { + push: ( + encoder: Encoder, + message: Partial, + opts?: ProtocolOptions + ) => Promise; +} + +export enum PageDirection { + BACKWARD = "backward", + FORWARD = "forward", +} + +export interface TimeFilter { + startTime: Date; + endTime: Date; +} + +export type StoreQueryOptions = { + /** + * The direction in which pages are retrieved: + * - { @link PageDirection.BACKWARD }: Most recent page first. + * - { @link PageDirection.FORWARD }: Oldest page first. + * + * Note: This does not affect the ordering of messages with the page + * (the oldest message is always first). + * + * @default { @link PageDirection.BACKWARD } + */ + pageDirection?: PageDirection; + /** + * The number of message per page. + */ + pageSize?: number; + /** + * Retrieve messages with a timestamp within the provided values. + */ + timeFilter?: TimeFilter; +} & ProtocolOptions; + +export interface Store extends PointToPointProtocol { + queryOrderedCallback: ( + decoders: Decoder[], + callback: (message: T) => Promise | boolean | void, + options?: StoreQueryOptions + ) => Promise; + queryCallbackOnPromise: ( + decoders: Decoder[], + callback: ( + message: Promise + ) => Promise | boolean | void, + options?: StoreQueryOptions + ) => Promise; + queryGenerator: ( + decoders: Decoder[], + options?: StoreQueryOptions + ) => AsyncGenerator[]>; +} + +export interface Relay extends GossipSub { + send: (encoder: Encoder, message: Partial) => Promise; + addObserver: ( + decoder: Decoder, + callback: Callback + ) => () => void; + getMeshPeers: () => string[]; +} + +export interface Waku { + libp2p: Libp2p; + relay?: Relay; + store?: Store; + filter?: Filter; + lightPush?: LightPush; + + dial(peer: PeerId | Multiaddr, protocols?: Protocols[]): Promise; + + addPeerToAddressBook( + peerId: PeerId | string, + multiaddrs: Multiaddr[] | string[] + ): void; + + start(): Promise; + + stop(): Promise; + + isStarted(): boolean; +} + +export interface WakuLight extends Waku { + relay: undefined; + store: Store; + filter: Filter; + lightPush: LightPush; +} + +export interface WakuPrivacy extends Waku { + relay: Relay; + store: undefined; + filter: undefined; + lightPush: undefined; +} + +export interface WakuFull extends Waku { + relay: Relay; + store: Store; + filter: Filter; + lightPush: LightPush; +} + +export interface RateLimitProof { + proof: Uint8Array; + merkleRoot: Uint8Array; + epoch: Uint8Array; + shareX: Uint8Array; + shareY: Uint8Array; + nullifier: Uint8Array; + rlnIdentifier: Uint8Array; +} + +export interface ProtoMessage { + payload: Uint8Array | undefined; + contentTopic: string | undefined; + version: number | undefined; + timestamp: bigint | undefined; + rateLimitProof: RateLimitProof | undefined; +} + +export interface Message { + payload: Uint8Array | undefined; + contentTopic: string | undefined; + timestamp: Date | undefined; + rateLimitProof: RateLimitProof | undefined; +} + +export interface Encoder { + contentTopic: string; + toWire: (message: Partial) => Promise; + toProtoObj: (message: Partial) => Promise; +} + +export interface Decoder { + contentTopic: string; + fromWireToProtoObj: (bytes: Uint8Array) => Promise; + fromProtoObj: (proto: ProtoMessage) => Promise; +} + +export interface SendResult { + recipients: PeerId[]; +} diff --git a/packages/interfaces/tsconfig.dev.json b/packages/interfaces/tsconfig.dev.json new file mode 100644 index 0000000000..ffc27ef6ba --- /dev/null +++ b/packages/interfaces/tsconfig.dev.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig", + "compilerOptions": { + "module": "esnext", + "noEmit": true + }, + "exclude": [] +} diff --git a/packages/interfaces/tsconfig.json b/packages/interfaces/tsconfig.json new file mode 100644 index 0000000000..7b01b30897 --- /dev/null +++ b/packages/interfaces/tsconfig.json @@ -0,0 +1,54 @@ +{ + "compilerOptions": { + "incremental": true, + "target": "es2020", + "outDir": "dist/", + "rootDir": "src", + "moduleResolution": "node", + "module": "es2020", + "declaration": true, + "sourceMap": true, + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, + "resolveJsonModule": true /* Include modules imported with .json extension. */, + "tsBuildInfoFile": "dist/.tsbuildinfo", + "strict": true /* Enable all strict type-checking options. */, + + /* Strict Type-Checking Options */ + "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */, + "strictNullChecks": true /* Enable strict null checks. */, + "strictFunctionTypes": true /* Enable strict checking of function types. */, + "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */, + "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */, + "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */, + + /* Additional Checks */ + "noUnusedLocals": true /* Report errors on unused locals. */, + "noUnusedParameters": true /* Report errors on unused parameters. */, + "noImplicitReturns": true /* Report error when not all code paths in function return a value. */, + "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */, + "forceConsistentCasingInFileNames": true, + + /* Debugging Options */ + "traceResolution": false /* Report module resolution log messages. */, + "listEmittedFiles": false /* Print names of generated files part of the compilation. */, + "listFiles": false /* Print names of files part of the compilation. */, + "pretty": true /* Stylize errors and messages using color and context. */, + + // Due to broken types in indirect dependencies + "skipLibCheck": true, + + /* Experimental Options */ + // "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */, + // "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */, + + "lib": ["es2020", "dom"], + "types": ["node", "mocha"], + "typeRoots": ["node_modules/@types", "src/types"] + }, + "include": ["src"], + "exclude": ["src/**/*.spec.ts", "src/test_utils"], + "compileOnSave": false, + "ts-node": { + "files": true + } +} diff --git a/packages/tests/.eslintrc.cjs b/packages/tests/.eslintrc.cjs new file mode 100644 index 0000000000..8de4a3fd8d --- /dev/null +++ b/packages/tests/.eslintrc.cjs @@ -0,0 +1,9 @@ +module.exports = { + parserOptions: { + tsconfigRootDir: __dirname, + project: "./tsconfig.dev.json", + }, + rules: { + "@typescript-eslint/no-non-null-assertion": "off", + }, +}; diff --git a/packages/tests/.mocharc.json b/packages/tests/.mocharc.json new file mode 100644 index 0000000000..b4cde4e22d --- /dev/null +++ b/packages/tests/.mocharc.json @@ -0,0 +1,11 @@ +{ + "extension": ["ts"], + "spec": "tests/*.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 +} diff --git a/packages/tests/.prettierignore b/packages/tests/.prettierignore new file mode 100644 index 0000000000..fecb37a393 --- /dev/null +++ b/packages/tests/.prettierignore @@ -0,0 +1,4 @@ +build +bundle +dist +node_modules diff --git a/packages/tests/package.json b/packages/tests/package.json new file mode 100644 index 0000000000..296fb881e8 --- /dev/null +++ b/packages/tests/package.json @@ -0,0 +1,76 @@ +{ + "name": "@waku/tests", + "private": true, + "version": "0.0.1", + "description": "Waku tests", + "types": "./dist/index.d.ts", + "module": "./dist/index.js", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js" + } + }, + "type": "module", + "author": "Waku Team", + "homepage": "https://github.com/waku-org/js-waku/tree/master/packages/tests#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", + "decentralized", + "secure", + "communication", + "web3", + "ethereum", + "dapps", + "privacy" + ], + "scripts": { + "build": "tsc", + "fix": "run-s fix:*", + "fix:prettier": "prettier . --write", + "fix:lint": "eslint src tests --ext .ts --ext .cjs --fix", + "pretest": "run-s pretest:*", + "pretest:1-init-git-submodules": "[ -f '../../nwaku/build/wakunode2' ] || git submodule update --init --recursive", + "pretest:2-build-nwaku": "[ -f '../../nwaku/build/wakunode2' ] || run-s nwaku:build", + "nwaku:build": "(PROC=$(nproc --all 2>/dev/null || echo 2); cd ../../nwaku; make -j$PROC update; NIMFLAGS=\"-d:chronicles_colors=off -d:chronicles_sinks=textlines -d:chronicles_log_level=TRACE\" make -j$PROC wakunode2)", + "nwaku:force-build": "(cd ../../nwaku && rm -rf ./build/ ./vendor) && run-s nwaku:build", + "check": "run-s check:*", + "check:prettier": "prettier . --list-different", + "check:lint": "eslint src tests --ext .ts", + "check:spelling": "cspell \"{README.md,{tests,src}/**/*.ts}\"", + "check:tsc": "tsc -p tsconfig.json", + "test": "run-s test:*", + "test:node": "TS_NODE_PROJECT=./tsconfig.json mocha", + "reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build" + }, + "engines": { + "node": ">=16" + }, + "dependencies": { + "@waku/core": "*", + "@waku/create": "*", + "@waku/interfaces": "*" + }, + "devDependencies": { + "@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", + "typescript": "^4.6.3" + } +} diff --git a/packages/core/src/test_utils/async_fs.ts b/packages/tests/src/async_fs.ts similarity index 100% rename from packages/core/src/test_utils/async_fs.ts rename to packages/tests/src/async_fs.ts diff --git a/packages/core/src/test_utils/constants.ts b/packages/tests/src/constants.ts similarity index 100% rename from packages/core/src/test_utils/constants.ts rename to packages/tests/src/constants.ts diff --git a/packages/core/src/test_utils/delay.ts b/packages/tests/src/delay.ts similarity index 100% rename from packages/core/src/test_utils/delay.ts rename to packages/tests/src/delay.ts diff --git a/packages/core/src/test_utils/index.ts b/packages/tests/src/index.ts similarity index 100% rename from packages/core/src/test_utils/index.ts rename to packages/tests/src/index.ts diff --git a/packages/core/src/test_utils/log_file.ts b/packages/tests/src/log_file.ts similarity index 100% rename from packages/core/src/test_utils/log_file.ts rename to packages/tests/src/log_file.ts diff --git a/packages/core/src/test_utils/nwaku.ts b/packages/tests/src/nwaku.ts similarity index 98% rename from packages/core/src/test_utils/nwaku.ts rename to packages/tests/src/nwaku.ts index 3027963bb5..15ef495690 100644 --- a/packages/core/src/test_utils/nwaku.ts +++ b/packages/tests/src/nwaku.ts @@ -1,24 +1,20 @@ -/** - * @hidden - * @module - */ - import { ChildProcess, spawn } from "child_process"; import type { PeerId } from "@libp2p/interface-peer-id"; import { peerIdFromString } from "@libp2p/peer-id"; import { Multiaddr, multiaddr } from "@multiformats/multiaddr"; +import { DefaultPubSubTopic } from "@waku/core"; +import { utils } from "@waku/core"; import appRoot from "app-root-path"; import debug from "debug"; import portfinder from "portfinder"; -import { DefaultPubSubTopic } from "../lib/constants"; -import { bytesToHex, hexToBytes } from "../lib/utils"; - import { existsAsync, mkdirAsync, openAsync } from "./async_fs"; import { delay } from "./delay"; import waitForLine from "./log_file"; +const { bytesToHex, hexToBytes } = utils; + const log = debug("waku:nwaku"); const WAKU_SERVICE_NODE_DIR = diff --git a/packages/core/src/lib/enr/enr.node.spec.ts b/packages/tests/tests/enr.node.spec.ts similarity index 76% rename from packages/core/src/lib/enr/enr.node.spec.ts rename to packages/tests/tests/enr.node.spec.ts index f8daa69747..3bfabbe2e3 100644 --- a/packages/core/src/lib/enr/enr.node.spec.ts +++ b/packages/tests/tests/enr.node.spec.ts @@ -1,15 +1,14 @@ +import { ENR } from "@waku/core/lib/enr"; +import { waitForRemotePeer } from "@waku/core/lib/wait_for_remote_peer"; +import { createPrivacyNode } from "@waku/create"; +import type { WakuPrivacy } from "@waku/interfaces"; +import { Protocols } from "@waku/interfaces"; import { expect } from "chai"; -import { makeLogFileName, NOISE_KEY_1, Nwaku } from "../../test_utils"; -import { createWaku } from "../create_waku"; -import type { Waku } from "../interfaces"; -import { waitForRemotePeer } from "../wait_for_remote_peer"; -import { Protocols } from "../waku"; - -import { ENR } from "./enr"; +import { makeLogFileName, NOISE_KEY_1, Nwaku } from "../src"; describe("ENR Interop: nwaku", function () { - let waku: Waku; + let waku: WakuPrivacy; let nwaku: Nwaku; afterEach(async function () { @@ -28,10 +27,12 @@ describe("ENR Interop: nwaku", function () { }); const multiAddrWithId = await nwaku.getMultiaddrWithId(); - waku = await createWaku({ + waku = await createPrivacyNode({ staticNoiseKey: NOISE_KEY_1, }); await waku.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku.dial(multiAddrWithId); await waitForRemotePeer(waku, [Protocols.Relay]); @@ -60,10 +61,12 @@ describe("ENR Interop: nwaku", function () { }); const multiAddrWithId = await nwaku.getMultiaddrWithId(); - waku = await createWaku({ + waku = await createPrivacyNode({ staticNoiseKey: NOISE_KEY_1, }); await waku.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku.dial(multiAddrWithId); await waitForRemotePeer(waku, [Protocols.Relay]); @@ -92,10 +95,12 @@ describe("ENR Interop: nwaku", function () { }); const multiAddrWithId = await nwaku.getMultiaddrWithId(); - waku = await createWaku({ + waku = await createPrivacyNode({ staticNoiseKey: NOISE_KEY_1, }); await waku.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku.dial(multiAddrWithId); await waitForRemotePeer(waku, [Protocols.Relay]); diff --git a/packages/core/src/lib/waku_filter/index.node.spec.ts b/packages/tests/tests/filter.node.spec.ts similarity index 83% rename from packages/core/src/lib/waku_filter/index.node.spec.ts rename to packages/tests/tests/filter.node.spec.ts index 205335de36..561e58d8b8 100644 --- a/packages/core/src/lib/waku_filter/index.node.spec.ts +++ b/packages/tests/tests/filter.node.spec.ts @@ -1,14 +1,14 @@ +import { bytesToUtf8, utf8ToBytes } from "@waku/core/lib/utils"; +import { waitForRemotePeer } from "@waku/core/lib/wait_for_remote_peer"; +import { DecoderV0, EncoderV0 } from "@waku/core/lib/waku_message/version_0"; +import { createFullNode } from "@waku/create"; +import type { Message, WakuFull } from "@waku/interfaces"; +import { Protocols } from "@waku/interfaces"; import { expect } from "chai"; import debug from "debug"; -import { makeLogFileName, NOISE_KEY_1, Nwaku } from "../../test_utils"; -import { delay } from "../../test_utils/delay"; -import { createFullNode } from "../create_waku"; -import type { Message, WakuFull } from "../interfaces"; -import { bytesToUtf8, utf8ToBytes } from "../utils"; -import { waitForRemotePeer } from "../wait_for_remote_peer"; -import { Protocols } from "../waku"; -import { DecoderV0, EncoderV0 } from "../waku_message/version_0"; +import { makeLogFileName, NOISE_KEY_1, Nwaku } from "../src"; +import { delay } from "../src/delay"; const log = debug("waku:test"); @@ -34,6 +34,8 @@ describe("Waku Filter", () => { libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }, }); await waku.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku.dial(await nwaku.getMultiaddrWithId()); await waitForRemotePeer(waku, [Protocols.Filter, Protocols.LightPush]); }); diff --git a/packages/core/src/lib/waku_light_push/index.node.spec.ts b/packages/tests/tests/light_push.node.spec.ts similarity index 80% rename from packages/core/src/lib/waku_light_push/index.node.spec.ts rename to packages/tests/tests/light_push.node.spec.ts index 6a9eeb92f6..f937e54a22 100644 --- a/packages/core/src/lib/waku_light_push/index.node.spec.ts +++ b/packages/tests/tests/light_push.node.spec.ts @@ -1,3 +1,9 @@ +import { bytesToUtf8, utf8ToBytes } from "@waku/core/lib/utils"; +import { waitForRemotePeer } from "@waku/core/lib/wait_for_remote_peer"; +import { EncoderV0 } from "@waku/core/lib/waku_message/version_0"; +import { createFullNode } from "@waku/create"; +import type { WakuFull } from "@waku/interfaces"; +import { Protocols } from "@waku/interfaces"; import { expect } from "chai"; import debug from "debug"; @@ -6,14 +12,8 @@ import { MessageRpcResponse, NOISE_KEY_1, Nwaku, -} from "../../test_utils"; -import { delay } from "../../test_utils/delay"; -import { createFullNode } from "../create_waku"; -import type { WakuFull } from "../interfaces"; -import { bytesToUtf8, utf8ToBytes } from "../utils"; -import { waitForRemotePeer } from "../wait_for_remote_peer"; -import { Protocols } from "../waku"; -import { EncoderV0 } from "../waku_message/version_0"; +} from "../src"; +import { delay } from "../src/delay"; const log = debug("waku:test:lightpush"); @@ -39,6 +39,8 @@ describe("Waku Light Push [node only]", () => { staticNoiseKey: NOISE_KEY_1, }); await waku.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku.dial(await nwaku.getMultiaddrWithId()); await waitForRemotePeer(waku, [Protocols.LightPush]); @@ -73,6 +75,8 @@ describe("Waku Light Push [node only]", () => { staticNoiseKey: NOISE_KEY_1, }); await waku.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku.dial(await nwaku.getMultiaddrWithId()); await waitForRemotePeer(waku, [Protocols.LightPush]); diff --git a/packages/core/src/test_utils/log_file.node.spec.ts b/packages/tests/tests/log_file.node.spec.ts similarity index 90% rename from packages/core/src/test_utils/log_file.node.spec.ts rename to packages/tests/tests/log_file.node.spec.ts index c72d3098d0..0d40474b6f 100644 --- a/packages/core/src/test_utils/log_file.node.spec.ts +++ b/packages/tests/tests/log_file.node.spec.ts @@ -1,6 +1,6 @@ import { expect } from "chai"; -import { makeLogFileName } from "./log_file"; +import { makeLogFileName } from "../src"; describe("This", function () { describe("Is", function () { diff --git a/packages/core/src/test_utils/nwaku.node.spec.ts b/packages/tests/tests/nwaku.node.spec.ts similarity index 90% rename from packages/core/src/test_utils/nwaku.node.spec.ts rename to packages/tests/tests/nwaku.node.spec.ts index d2f7e05222..5299aab3f6 100644 --- a/packages/core/src/test_utils/nwaku.node.spec.ts +++ b/packages/tests/tests/nwaku.node.spec.ts @@ -1,6 +1,6 @@ import { expect } from "chai"; -import { argsToArray, defaultArgs } from "./nwaku"; +import { argsToArray, defaultArgs } from "../src"; describe("nwaku", () => { it("Correctly serialized arguments", function () { diff --git a/packages/core/src/lib/waku_relay/index.node.spec.ts b/packages/tests/tests/relay.node.spec.ts similarity index 93% rename from packages/core/src/lib/waku_relay/index.node.spec.ts rename to packages/tests/tests/relay.node.spec.ts index 931a2c0e32..cef9e21c88 100644 --- a/packages/core/src/lib/waku_relay/index.node.spec.ts +++ b/packages/tests/tests/relay.node.spec.ts @@ -1,4 +1,26 @@ import { PeerId } from "@libp2p/interface-peer-id"; +import { + DefaultPubSubTopic, + generatePrivateKey, + generateSymmetricKey, + getPublicKey, +} from "@waku/core"; +import { bytesToUtf8, utf8ToBytes } from "@waku/core/lib/utils"; +import { waitForRemotePeer } from "@waku/core/lib/wait_for_remote_peer"; +import { + DecoderV0, + EncoderV0, + MessageV0, +} from "@waku/core/lib/waku_message/version_0"; +import { + AsymDecoder, + AsymEncoder, + SymDecoder, + SymEncoder, +} from "@waku/core/lib/waku_message/version_1"; +import { createPrivacyNode } from "@waku/create"; +import type { Message, WakuPrivacy } from "@waku/interfaces"; +import { Protocols } from "@waku/interfaces"; import { expect } from "chai"; import debug from "debug"; @@ -9,26 +31,8 @@ import { NOISE_KEY_2, NOISE_KEY_3, Nwaku, -} from "../../test_utils"; -import { delay } from "../../test_utils/delay"; -import { DefaultPubSubTopic } from "../constants"; -import { createPrivacyNode } from "../create_waku"; -import { - generatePrivateKey, - generateSymmetricKey, - getPublicKey, -} from "../crypto"; -import type { Message, WakuPrivacy } from "../interfaces"; -import { bytesToUtf8, utf8ToBytes } from "../utils"; -import { waitForRemotePeer } from "../wait_for_remote_peer"; -import { Protocols } from "../waku"; -import { DecoderV0, EncoderV0, MessageV0 } from "../waku_message/version_0.js"; -import { - AsymDecoder, - AsymEncoder, - SymDecoder, - SymEncoder, -} from "../waku_message/version_1.js"; +} from "../src"; +import { delay } from "../src/delay"; const log = debug("waku:test"); @@ -342,6 +346,8 @@ describe("Waku Relay [node only]", () => { nwaku = new Nwaku(this.test?.ctx?.currentTest?.title + ""); await nwaku.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku.dial(await nwaku.getMultiaddrWithId()); await waitForRemotePeer(waku, [Protocols.Relay]); }); @@ -439,7 +445,11 @@ describe("Waku Relay [node only]", () => { const nwakuMultiaddr = await nwaku.getMultiaddrWithId(); await Promise.all([ + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos waku1.dial(nwakuMultiaddr), + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos waku2.dial(nwakuMultiaddr), ]); diff --git a/packages/core/src/lib/waku_store/index.node.spec.ts b/packages/tests/tests/store.node.spec.ts similarity index 87% rename from packages/core/src/lib/waku_store/index.node.spec.ts rename to packages/tests/tests/store.node.spec.ts index aa841db6e6..fb779059b2 100644 --- a/packages/core/src/lib/waku_store/index.node.spec.ts +++ b/packages/tests/tests/store.node.spec.ts @@ -1,31 +1,25 @@ -import { expect } from "chai"; -import debug from "debug"; - -import { - makeLogFileName, - NOISE_KEY_1, - NOISE_KEY_2, - Nwaku, -} from "../../test_utils"; -import { createFullNode } from "../create_waku"; import { generatePrivateKey, generateSymmetricKey, getPublicKey, -} from "../crypto"; -import type { Message, WakuFull } from "../interfaces"; -import { bytesToUtf8, utf8ToBytes } from "../utils"; -import { waitForRemotePeer } from "../wait_for_remote_peer"; -import { Protocols } from "../waku"; -import { DecoderV0, EncoderV0 } from "../waku_message/version_0.js"; +} from "@waku/core"; +import { PageDirection } from "@waku/core"; +import { bytesToUtf8, utf8ToBytes } from "@waku/core/lib/utils"; +import { waitForRemotePeer } from "@waku/core/lib/wait_for_remote_peer"; +import { DecoderV0, EncoderV0 } from "@waku/core/lib/waku_message/version_0"; import { AsymDecoder, AsymEncoder, SymDecoder, SymEncoder, -} from "../waku_message/version_1.js"; +} from "@waku/core/lib/waku_message/version_1"; +import { createFullNode } from "@waku/create"; +import type { Message, WakuFull } from "@waku/interfaces"; +import { Protocols } from "@waku/interfaces"; +import { expect } from "chai"; +import debug from "debug"; -import { PageDirection } from "./history_rpc"; +import { makeLogFileName, NOISE_KEY_1, NOISE_KEY_2, Nwaku } from "../src"; const log = debug("waku:test:store"); @@ -67,6 +61,8 @@ describe("Waku Store", () => { staticNoiseKey: NOISE_KEY_1, }); await waku.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku.dial(await nwaku.getMultiaddrWithId()); await waitForRemotePeer(waku, [Protocols.Store]); @@ -98,6 +94,8 @@ describe("Waku Store", () => { staticNoiseKey: NOISE_KEY_1, }); await waku.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku.dial(await nwaku.getMultiaddrWithId()); await waitForRemotePeer(waku, [Protocols.Store]); @@ -138,6 +136,8 @@ describe("Waku Store", () => { staticNoiseKey: NOISE_KEY_1, }); await waku.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku.dial(await nwaku.getMultiaddrWithId()); await waitForRemotePeer(waku, [Protocols.Store]); @@ -179,6 +179,8 @@ describe("Waku Store", () => { staticNoiseKey: NOISE_KEY_1, }); await waku.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku.dial(await nwaku.getMultiaddrWithId()); await waitForRemotePeer(waku, [Protocols.Store]); @@ -218,6 +220,8 @@ describe("Waku Store", () => { staticNoiseKey: NOISE_KEY_1, }); await waku.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku.dial(await nwaku.getMultiaddrWithId()); await waitForRemotePeer(waku, [Protocols.Store]); @@ -261,6 +265,8 @@ describe("Waku Store", () => { staticNoiseKey: NOISE_KEY_1, }); await waku.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku.dial(await nwaku.getMultiaddrWithId()); await waitForRemotePeer(waku, [Protocols.Store]); @@ -343,7 +349,11 @@ describe("Waku Store", () => { log("Waku nodes created"); await Promise.all([ + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos waku1.dial(nimWakuMultiaddr), + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos waku2.dial(nimWakuMultiaddr), ]); @@ -425,6 +435,8 @@ describe("Waku Store", () => { staticNoiseKey: NOISE_KEY_1, }); await waku.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku.dial(await nwaku.getMultiaddrWithId()); await waitForRemotePeer(waku, [Protocols.Store]); @@ -486,6 +498,8 @@ describe("Waku Store", () => { staticNoiseKey: NOISE_KEY_1, }); await waku.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku.dial(await nwaku.getMultiaddrWithId()); await waitForRemotePeer(waku, [Protocols.Store]); @@ -545,6 +559,8 @@ describe("Waku Store, custom pubsub topic", () => { pubSubTopic: customPubSubTopic, }); await waku.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku.dial(await nwaku.getMultiaddrWithId()); await waitForRemotePeer(waku, [Protocols.Store]); diff --git a/packages/core/src/lib/wait_for_remote_peer.node.spec.ts b/packages/tests/tests/wait_for_remote_peer.node.spec.ts similarity index 83% rename from packages/core/src/lib/wait_for_remote_peer.node.spec.ts rename to packages/tests/tests/wait_for_remote_peer.node.spec.ts index 67793a890b..9ba26feeb3 100644 --- a/packages/core/src/lib/wait_for_remote_peer.node.spec.ts +++ b/packages/tests/tests/wait_for_remote_peer.node.spec.ts @@ -1,12 +1,11 @@ +import { waitForRemotePeer } from "@waku/core/lib/wait_for_remote_peer"; +import { createLightNode, createPrivacyNode } from "@waku/create"; +import type { WakuLight, WakuPrivacy } from "@waku/interfaces"; +import { Protocols } from "@waku/interfaces"; import { expect } from "chai"; -import { makeLogFileName, NOISE_KEY_1, Nwaku } from "../test_utils"; -import { delay } from "../test_utils/delay"; - -import { createLightNode, createPrivacyNode } from "./create_waku"; -import type { WakuLight, WakuPrivacy } from "./interfaces"; -import { waitForRemotePeer } from "./wait_for_remote_peer"; -import { Protocols } from "./waku"; +import { makeLogFileName, NOISE_KEY_1, Nwaku } from "../src"; +import { delay } from "../src/delay"; describe("Wait for remote peer", function () { let waku1: WakuPrivacy; @@ -37,6 +36,8 @@ describe("Wait for remote peer", function () { staticNoiseKey: NOISE_KEY_1, }); await waku1.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku1.dial(multiAddrWithId); await delay(1000); await waitForRemotePeer(waku1, [Protocols.Relay]); @@ -65,6 +66,8 @@ describe("Wait for remote peer", function () { const waitPromise = waitForRemotePeer(waku1, [Protocols.Relay]); await delay(1000); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku1.dial(multiAddrWithId); await waitPromise; @@ -110,6 +113,8 @@ describe("Wait for remote peer", function () { staticNoiseKey: NOISE_KEY_1, }); await waku2.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku2.dial(multiAddrWithId); await delay(1000); await waitForRemotePeer(waku2, [Protocols.Store]); @@ -139,6 +144,8 @@ describe("Wait for remote peer", function () { await waku2.start(); const waitPromise = waitForRemotePeer(waku2, [Protocols.Store], 2000); await delay(1000); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku2.dial(multiAddrWithId); await waitPromise; @@ -165,6 +172,8 @@ describe("Wait for remote peer", function () { staticNoiseKey: NOISE_KEY_1, }); await waku2.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku2.dial(multiAddrWithId); await waitForRemotePeer(waku2, [Protocols.LightPush]); @@ -193,6 +202,8 @@ describe("Wait for remote peer", function () { staticNoiseKey: NOISE_KEY_1, }); await waku2.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku2.dial(multiAddrWithId); await waitForRemotePeer(waku2, [Protocols.Filter]); @@ -222,6 +233,8 @@ describe("Wait for remote peer", function () { staticNoiseKey: NOISE_KEY_1, }); await waku2.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku2.dial(multiAddrWithId); await waitForRemotePeer(waku2); @@ -258,10 +271,12 @@ describe("Wait for remote peer", function () { staticNoiseKey: NOISE_KEY_1, }); await waku1.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku1.dial(multiAddrWithId); await waitForRemotePeer(waku1); - const peers = await waku1.relay.getMeshPeers(); + const peers = waku1.relay.getMeshPeers(); const nimPeerId = multiAddrWithId.getPeerId(); diff --git a/packages/core/src/lib/waku.node.spec.ts b/packages/tests/tests/waku.node.spec.ts similarity index 82% rename from packages/core/src/lib/waku.node.spec.ts rename to packages/tests/tests/waku.node.spec.ts index 3418c80281..8999460ffb 100644 --- a/packages/core/src/lib/waku.node.spec.ts +++ b/packages/tests/tests/waku.node.spec.ts @@ -1,21 +1,15 @@ import type { PeerId } from "@libp2p/interface-peer-id"; +import { generateSymmetricKey } from "@waku/core"; +import { PeerDiscoveryStaticPeers } from "@waku/core/lib/peer_discovery_static_list"; +import { bytesToUtf8, utf8ToBytes } from "@waku/core/lib/utils"; +import { waitForRemotePeer } from "@waku/core/lib/wait_for_remote_peer"; +import { SymDecoder, SymEncoder } from "@waku/core/lib/waku_message/version_1"; +import { createLightNode, createPrivacyNode } from "@waku/create"; +import type { Message, Waku, WakuLight, WakuPrivacy } from "@waku/interfaces"; +import { Protocols } from "@waku/interfaces"; import { expect } from "chai"; -import { - makeLogFileName, - NOISE_KEY_1, - NOISE_KEY_2, - Nwaku, -} from "../test_utils/"; - -import { createLightNode, createPrivacyNode } from "./create_waku"; -import { generateSymmetricKey } from "./crypto"; -import type { Message, Waku, WakuLight, WakuPrivacy } from "./interfaces"; -import { PeerDiscoveryStaticPeers } from "./peer_discovery_static_list"; -import { bytesToUtf8, utf8ToBytes } from "./utils"; -import { waitForRemotePeer } from "./wait_for_remote_peer"; -import { Protocols } from "./waku"; -import { SymDecoder, SymEncoder } from "./waku_message/version_1.js"; +import { makeLogFileName, NOISE_KEY_1, NOISE_KEY_2, Nwaku } from "../src/"; const TestContentTopic = "/test/1/waku/utf8"; @@ -44,6 +38,8 @@ describe("Waku Dial [node only]", function () { staticNoiseKey: NOISE_KEY_1, }); await waku.start(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos await waku.dial(multiAddrWithId); await waitForRemotePeer(waku); @@ -70,6 +66,8 @@ describe("Waku Dial [node only]", function () { waku = await createLightNode({ staticNoiseKey: NOISE_KEY_1, libp2p: { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos peerDiscovery: [new PeerDiscoveryStaticPeers([multiAddrWithId])], }, }); @@ -97,6 +95,8 @@ describe("Waku Dial [node only]", function () { staticNoiseKey: NOISE_KEY_1, libp2p: { peerDiscovery: [ + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TODO: uniformize usage of multiaddr lib across repos new PeerDiscoveryStaticPeers([await nwaku.getMultiaddrWithId()]), ], }, diff --git a/packages/tests/tsconfig.dev.json b/packages/tests/tsconfig.dev.json new file mode 100644 index 0000000000..d64199f6ad --- /dev/null +++ b/packages/tests/tsconfig.dev.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig", + "compilerOptions": { + "module": "esnext", + "noEmit": true + }, + "include": ["src", "tests"] +} diff --git a/packages/tests/tsconfig.json b/packages/tests/tsconfig.json new file mode 100644 index 0000000000..49df3977af --- /dev/null +++ b/packages/tests/tsconfig.json @@ -0,0 +1,53 @@ +{ + "compilerOptions": { + "incremental": true, + "target": "es2020", + "outDir": "dist/", + "moduleResolution": "node", + "module": "es2020", + "declaration": true, + "sourceMap": true, + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, + "resolveJsonModule": true /* Include modules imported with .json extension. */, + "tsBuildInfoFile": "dist/.tsbuildinfo", + "strict": true /* Enable all strict type-checking options. */, + + /* Strict Type-Checking Options */ + "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */, + "strictNullChecks": true /* Enable strict null checks. */, + "strictFunctionTypes": true /* Enable strict checking of function types. */, + "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */, + "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */, + "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */, + + /* Additional Checks */ + "noUnusedLocals": true /* Report errors on unused locals. */, + "noUnusedParameters": true /* Report errors on unused parameters. */, + "noImplicitReturns": true /* Report error when not all code paths in function return a value. */, + "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */, + "forceConsistentCasingInFileNames": true, + + /* Debugging Options */ + "traceResolution": false /* Report module resolution log messages. */, + "listEmittedFiles": false /* Print names of generated files part of the compilation. */, + "listFiles": false /* Print names of files part of the compilation. */, + "pretty": true /* Stylize errors and messages using color and context. */, + + // Due to broken types in indirect dependencies + "skipLibCheck": true, + + /* Experimental Options */ + // "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */, + // "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */, + + "lib": ["es2020", "dom"], + "types": ["node", "mocha"], + "typeRoots": ["node_modules/@types", "src/types"] + }, + "include": ["src"], + "exclude": [], + "compileOnSave": false, + "ts-node": { + "files": true + } +} diff --git a/packages/tests/tsconfig.karma.json b/packages/tests/tsconfig.karma.json new file mode 100644 index 0000000000..c540c783ff --- /dev/null +++ b/packages/tests/tsconfig.karma.json @@ -0,0 +1,6 @@ +{ + "extends": "./tsconfig.dev", + "compilerOptions": { + "noEmit": false + } +} diff --git a/typedoc.json b/typedoc.json new file mode 100644 index 0000000000..c381a4fcb7 --- /dev/null +++ b/typedoc.json @@ -0,0 +1,11 @@ +{ + "entryPointStrategy": "packages", + "entryPoints": ["packages/core", "packages/interfaces", "packages/create"], + "out": "docs", + "exclude": ["**/*.spec.ts"], + "excludeInternal": true, + "validation": { + "invalidLink": true, + "notExported": true + } +}