diff --git a/package.json b/package.json index eea20e6..5a36a4c 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@lumeweb/dht-web", + "name": "@lumeweb/hyperswarm-web", "type": "module", "version": "0.1.0", "main": "dist/index.js", @@ -8,21 +8,16 @@ }, "devDependencies": { "@types/random-number-csprng": "^1.0.0", - "@types/ws": "^8.5.3", - "esbuild": "^0.14.48", - "prettier": "^2.7.1", - "rimraf": "^3.0.2" + "@types/ws": "^8.5.4", + "esbuild": "^0.14.54", + "prettier": "^2.8.3", + "rimraf": "^3.0.2", + "typescript": "^4.9.5" }, "dependencies": { - "@derhuerst/round-robin-scheduler": "^1.0.4", "@hyperswarm/dht-relay": "^0.3.0", - "buffer": "^6.0.3", - "libkernel": "^0.1.41", - "libkmodule": "^0.2.12", - "libskynet": "^0.0.48", - "msgpackr": "^1.6.1", - "random-number-csprng": "^1.0.2", - "safe-buffer": "^5.2.1", - "websocket-pool": "^1.3.1" + "@lumeweb/kernel-peer-discovery-client": "git+https://git.lumeweb.com/LumeWeb/kernel-peer-discovery-client.git", + "@lumeweb/libkernel-universal": "git+https://git.lumeweb.com/LumeWeb/libkernel-universal.git", + "hyperswarm": "^4.3.7" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml new file mode 100644 index 0000000..7daead0 --- /dev/null +++ b/pnpm-lock.yaml @@ -0,0 +1,781 @@ +lockfileVersion: 5.4 + +specifiers: + '@hyperswarm/dht-relay': ^0.3.0 + '@lumeweb/kernel-peer-discovery-client': git+https://git.lumeweb.com/LumeWeb/kernel-peer-discovery-client.git + '@lumeweb/libkernel-universal': git+https://git.lumeweb.com/LumeWeb/libkernel-universal.git + '@types/random-number-csprng': ^1.0.0 + '@types/ws': ^8.5.4 + esbuild: ^0.14.54 + hyperswarm: ^4.3.7 + prettier: ^2.8.3 + rimraf: ^3.0.2 + typescript: ^4.9.5 + +dependencies: + '@hyperswarm/dht-relay': 0.3.0 + '@lumeweb/kernel-peer-discovery-client': git.lumeweb.com/LumeWeb/kernel-peer-discovery-client/ad426dafb19be8f79c64bb11c1c014b1031c96d0 + '@lumeweb/libkernel-universal': git.lumeweb.com/LumeWeb/libkernel-universal/ae9c6eeb60cd5e350012c3e393ff8b846326e468 + hyperswarm: 4.3.7 + +devDependencies: + '@types/random-number-csprng': 1.0.0 + '@types/ws': 8.5.4 + esbuild: 0.14.54 + prettier: 2.8.3 + rimraf: 3.0.2 + typescript: 4.9.5 + +packages: + + /@esbuild/linux-loong64/0.14.54: + resolution: {integrity: sha512-bZBrLAIX1kpWelV0XemxBZllyRmM6vgFQQG2GdNb+r3Fkp0FOh1NJSvekXDs7jq70k4euu1cryLMfU+mTXlEpw==} + engines: {node: '>=12'} + cpu: [loong64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@hyperswarm/dht-relay/0.3.0: + resolution: {integrity: sha512-HOg8B+WNdI0/l6LCDdXhau7BmMhd0Eq//EvmlMvR1MlwJ7T8YCDaXm1EeqCnOSvTf7/DP90O8Jd23yXd3B9OiQ==} + dependencies: + '@hyperswarm/dht': 6.4.4 + '@hyperswarm/secret-stream': 6.1.2 + b4a: 1.6.1 + compact-encoding: 2.11.0 + compact-encoding-net: 1.2.0 + events: 3.3.0 + protomux: 3.4.1 + safety-catch: 1.0.2 + sodium-universal: 3.1.0 + streamx: 2.13.2 + timeout-refresh: 2.0.1 + dev: false + + /@hyperswarm/dht/6.4.4: + resolution: {integrity: sha512-yqOZ4iaOS9MYIMdC03lZ8scam+ptspTwL0rMFJILF+LU3LT8QjUCRHRUbUOaZFjZ0tf0g7+DICRILMTRwSQ/Ug==} + hasBin: true + dependencies: + '@hyperswarm/secret-stream': 6.1.2 + b4a: 1.6.1 + bogon: 1.1.0 + compact-encoding: 2.11.0 + compact-encoding-net: 1.2.0 + debugging-stream: 2.0.0 + dht-rpc: 6.6.2 + events: 3.3.0 + hypercore-crypto: 3.3.1 + noise-curve-ed: 2.0.1 + noise-handshake: 3.0.2 + record-cache: 1.2.0 + safety-catch: 1.0.2 + sodium-universal: 4.0.0 + xache: 1.1.0 + dev: false + + /@hyperswarm/secret-stream/6.1.2: + resolution: {integrity: sha512-oem+ZEG+wOU1K47qGi51pKyqG1N3F+zz42xmReHeGZVR84y+K+6VQIXCON4EozYad8HEGCixpupt8yH8W4sMxg==} + dependencies: + b4a: 1.6.1 + hypercore-crypto: 3.3.1 + noise-curve-ed: 2.0.1 + noise-handshake: 3.0.2 + sodium-secretstream: 1.1.0 + sodium-universal: 4.0.0 + streamx: 2.13.2 + timeout-refresh: 2.0.1 + dev: false + + /@skynetlabs/libskynet/0.0.48: + resolution: {integrity: sha512-wFqPLVuGyfuEU1PsE7AMC+ANcoJiz7iruJPUrNZC0riDv1qMrZw+tx44HlBXLJ1H50JZiGtRPr9zLgkPFhf9OA==} + dev: false + + /@types/node/18.11.18: + resolution: {integrity: sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==} + dev: true + + /@types/random-number-csprng/1.0.0: + resolution: {integrity: sha512-JmNWSCGbay5HGkHb/WF0Ju3XTHP0tMLUhAOk4fsw+b1GQ9rC/WP9uLeuulWLVERCg3KoyTCNzsJX4jSi4ShKaw==} + dev: true + + /@types/ws/8.5.4: + resolution: {integrity: sha512-zdQDHKUgcX/zBc4GrwsE/7dVdAD8JR4EuiAXiiUhhfyIJXXb2+PrGshFyeXWQPMmmZ2XxgaqclgpIC7eTXc1mg==} + dependencies: + '@types/node': 18.11.18 + dev: true + + /b4a/1.6.1: + resolution: {integrity: sha512-AsKjNhz72yxteo/0EtQEiwkMUgk/tGmycXlbG4g3Ard2/ULtNLUykGOkeK0egmN27h0xMAhb76jYccW+XTBExA==} + dev: false + + /balanced-match/1.0.2: + resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} + dev: true + + /blake2b-wasm/2.4.0: + resolution: {integrity: sha512-S1kwmW2ZhZFFFOghcx73+ZajEfKBqhP82JMssxtLVMxlaPea1p9uoLiUZ5WYyHn0KddwbLc+0vh4wR0KBNoT5w==} + dependencies: + b4a: 1.6.1 + nanoassert: 2.0.0 + dev: false + + /blake2b/2.1.4: + resolution: {integrity: sha512-AyBuuJNI64gIvwx13qiICz6H6hpmjvYS5DGkG6jbXMOT8Z3WUJ3V1X0FlhIoT1b/5JtHE3ki+xjtMvu1nn+t9A==} + dependencies: + blake2b-wasm: 2.4.0 + nanoassert: 2.0.0 + dev: false + + /bogon/1.1.0: + resolution: {integrity: sha512-a6SnToksXHuUlgeMvI/txWmTcKz7c7iBa8f0HbXL4toN1Uza/CTQ4F7n9jSDX49TCpxv3KUP100q4sZfwLyLiw==} + dependencies: + compact-encoding: 2.11.0 + compact-encoding-net: 1.2.0 + dev: false + + /brace-expansion/1.1.11: + resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==} + dependencies: + balanced-match: 1.0.2 + concat-map: 0.0.1 + dev: true + + /chacha20-universal/1.0.4: + resolution: {integrity: sha512-/IOxdWWNa7nRabfe7+oF+jVkGjlr2xUL4J8l/OvzZhj+c9RpMqoo3Dq+5nU1j/BflRV4BKnaQ4+4oH1yBpQG1Q==} + dependencies: + nanoassert: 2.0.0 + dev: false + + /compact-encoding-net/1.2.0: + resolution: {integrity: sha512-LVXpNpF7PGQeHRVVLGgYWzuVoYAaDZvKUsUxRioGfkotzvOh4AzoQF1HBH3zMNaSnx7gJXuUr3hkjnijaH/Eng==} + dependencies: + compact-encoding: 2.11.0 + dev: false + + /compact-encoding/2.11.0: + resolution: {integrity: sha512-CRfTuyy9Tg7EwxNKvIq3yFIr2JnJLyVr9Yj234VsDCL59hdXcZH3TdzY/2kwbAqVogIoRBJjnNKCEnXbxTIEeg==} + dependencies: + b4a: 1.6.1 + dev: false + + /concat-map/0.0.1: + resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} + dev: true + + /debugging-stream/2.0.0: + resolution: {integrity: sha512-xwfl6wB/3xc553uwtGnSa94jFxnGOc02C0WU2Nmzwr80gzeqn1FX4VcbvoKIhe8L/lPq4BTQttAbrTN94uN8rA==} + dependencies: + streamx: 2.13.2 + dev: false + + /dht-rpc/6.6.2: + resolution: {integrity: sha512-tOG4cEwere/Vi5y8zJb1D55ApPFRMyHwgVLmjPeROQhYc0/L2ZYw/h4u3XqGYI0i+vweBN2ZEJ99vk9iBsxd3A==} + dependencies: + b4a: 1.6.1 + compact-encoding: 2.11.0 + compact-encoding-net: 1.2.0 + events: 3.3.0 + fast-fifo: 1.1.0 + kademlia-routing-table: 1.0.1 + nat-sampler: 1.0.1 + sodium-universal: 4.0.0 + streamx: 2.13.2 + time-ordered-set: 1.0.2 + udx-native: 1.5.3 + dev: false + + /esbuild-android-64/0.14.54: + resolution: {integrity: sha512-Tz2++Aqqz0rJ7kYBfz+iqyE3QMycD4vk7LBRyWaAVFgFtQ/O8EJOnVmTOiDWYZ/uYzB4kvP+bqejYdVKzE5lAQ==} + engines: {node: '>=12'} + cpu: [x64] + os: [android] + requiresBuild: true + dev: true + optional: true + + /esbuild-android-arm64/0.14.54: + resolution: {integrity: sha512-F9E+/QDi9sSkLaClO8SOV6etqPd+5DgJje1F9lOWoNncDdOBL2YF59IhsWATSt0TLZbYCf3pNlTHvVV5VfHdvg==} + engines: {node: '>=12'} + cpu: [arm64] + os: [android] + requiresBuild: true + dev: true + optional: true + + /esbuild-darwin-64/0.14.54: + resolution: {integrity: sha512-jtdKWV3nBviOd5v4hOpkVmpxsBy90CGzebpbO9beiqUYVMBtSc0AL9zGftFuBon7PNDcdvNCEuQqw2x0wP9yug==} + engines: {node: '>=12'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /esbuild-darwin-arm64/0.14.54: + resolution: {integrity: sha512-OPafJHD2oUPyvJMrsCvDGkRrVCar5aVyHfWGQzY1dWnzErjrDuSETxwA2HSsyg2jORLY8yBfzc1MIpUkXlctmw==} + engines: {node: '>=12'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /esbuild-freebsd-64/0.14.54: + resolution: {integrity: sha512-OKwd4gmwHqOTp4mOGZKe/XUlbDJ4Q9TjX0hMPIDBUWWu/kwhBAudJdBoxnjNf9ocIB6GN6CPowYpR/hRCbSYAg==} + engines: {node: '>=12'} + cpu: [x64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + + /esbuild-freebsd-arm64/0.14.54: + resolution: {integrity: sha512-sFwueGr7OvIFiQT6WeG0jRLjkjdqWWSrfbVwZp8iMP+8UHEHRBvlaxL6IuKNDwAozNUmbb8nIMXa7oAOARGs1Q==} + engines: {node: '>=12'} + cpu: [arm64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-32/0.14.54: + resolution: {integrity: sha512-1ZuY+JDI//WmklKlBgJnglpUL1owm2OX+8E1syCD6UAxcMM/XoWd76OHSjl/0MR0LisSAXDqgjT3uJqT67O3qw==} + engines: {node: '>=12'} + cpu: [ia32] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-64/0.14.54: + resolution: {integrity: sha512-EgjAgH5HwTbtNsTqQOXWApBaPVdDn7XcK+/PtJwZLT1UmpLoznPd8c5CxqsH2dQK3j05YsB3L17T8vE7cp4cCg==} + engines: {node: '>=12'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-arm/0.14.54: + resolution: {integrity: sha512-qqz/SjemQhVMTnvcLGoLOdFpCYbz4v4fUo+TfsWG+1aOu70/80RV6bgNpR2JCrppV2moUQkww+6bWxXRL9YMGw==} + engines: {node: '>=12'} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-arm64/0.14.54: + resolution: {integrity: sha512-WL71L+0Rwv+Gv/HTmxTEmpv0UgmxYa5ftZILVi2QmZBgX3q7+tDeOQNqGtdXSdsL8TQi1vIaVFHUPDe0O0kdig==} + engines: {node: '>=12'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-mips64le/0.14.54: + resolution: {integrity: sha512-qTHGQB8D1etd0u1+sB6p0ikLKRVuCWhYQhAHRPkO+OF3I/iSlTKNNS0Lh2Oc0g0UFGguaFZZiPJdJey3AGpAlw==} + engines: {node: '>=12'} + cpu: [mips64el] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-ppc64le/0.14.54: + resolution: {integrity: sha512-j3OMlzHiqwZBDPRCDFKcx595XVfOfOnv68Ax3U4UKZ3MTYQB5Yz3X1mn5GnodEVYzhtZgxEBidLWeIs8FDSfrQ==} + engines: {node: '>=12'} + cpu: [ppc64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-riscv64/0.14.54: + resolution: {integrity: sha512-y7Vt7Wl9dkOGZjxQZnDAqqn+XOqFD7IMWiewY5SPlNlzMX39ocPQlOaoxvT4FllA5viyV26/QzHtvTjVNOxHZg==} + engines: {node: '>=12'} + cpu: [riscv64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-s390x/0.14.54: + resolution: {integrity: sha512-zaHpW9dziAsi7lRcyV4r8dhfG1qBidQWUXweUjnw+lliChJqQr+6XD71K41oEIC3Mx1KStovEmlzm+MkGZHnHA==} + engines: {node: '>=12'} + cpu: [s390x] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-netbsd-64/0.14.54: + resolution: {integrity: sha512-PR01lmIMnfJTgeU9VJTDY9ZerDWVFIUzAtJuDHwwceppW7cQWjBBqP48NdeRtoP04/AtO9a7w3viI+PIDr6d+w==} + engines: {node: '>=12'} + cpu: [x64] + os: [netbsd] + requiresBuild: true + dev: true + optional: true + + /esbuild-openbsd-64/0.14.54: + resolution: {integrity: sha512-Qyk7ikT2o7Wu76UsvvDS5q0amJvmRzDyVlL0qf5VLsLchjCa1+IAvd8kTBgUxD7VBUUVgItLkk609ZHUc1oCaw==} + engines: {node: '>=12'} + cpu: [x64] + os: [openbsd] + requiresBuild: true + dev: true + optional: true + + /esbuild-sunos-64/0.14.54: + resolution: {integrity: sha512-28GZ24KmMSeKi5ueWzMcco6EBHStL3B6ubM7M51RmPwXQGLe0teBGJocmWhgwccA1GeFXqxzILIxXpHbl9Q/Kw==} + engines: {node: '>=12'} + cpu: [x64] + os: [sunos] + requiresBuild: true + dev: true + optional: true + + /esbuild-windows-32/0.14.54: + resolution: {integrity: sha512-T+rdZW19ql9MjS7pixmZYVObd9G7kcaZo+sETqNH4RCkuuYSuv9AGHUVnPoP9hhuE1WM1ZimHz1CIBHBboLU7w==} + engines: {node: '>=12'} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /esbuild-windows-64/0.14.54: + resolution: {integrity: sha512-AoHTRBUuYwXtZhjXZbA1pGfTo8cJo3vZIcWGLiUcTNgHpJJMC1rVA44ZereBHMJtotyN71S8Qw0npiCIkW96cQ==} + engines: {node: '>=12'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /esbuild-windows-arm64/0.14.54: + resolution: {integrity: sha512-M0kuUvXhot1zOISQGXwWn6YtS+Y/1RT9WrVIOywZnJHo3jCDyewAc79aKNQWFCQm+xNHVTq9h8dZKvygoXQQRg==} + engines: {node: '>=12'} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /esbuild/0.14.54: + resolution: {integrity: sha512-Cy9llcy8DvET5uznocPyqL3BFRrFXSVqbgpMJ9Wz8oVjZlh/zUSNbPRbov0VX7VxN2JH1Oa0uNxZ7eLRb62pJA==} + engines: {node: '>=12'} + hasBin: true + requiresBuild: true + optionalDependencies: + '@esbuild/linux-loong64': 0.14.54 + esbuild-android-64: 0.14.54 + esbuild-android-arm64: 0.14.54 + esbuild-darwin-64: 0.14.54 + esbuild-darwin-arm64: 0.14.54 + esbuild-freebsd-64: 0.14.54 + esbuild-freebsd-arm64: 0.14.54 + esbuild-linux-32: 0.14.54 + esbuild-linux-64: 0.14.54 + esbuild-linux-arm: 0.14.54 + esbuild-linux-arm64: 0.14.54 + esbuild-linux-mips64le: 0.14.54 + esbuild-linux-ppc64le: 0.14.54 + esbuild-linux-riscv64: 0.14.54 + esbuild-linux-s390x: 0.14.54 + esbuild-netbsd-64: 0.14.54 + esbuild-openbsd-64: 0.14.54 + esbuild-sunos-64: 0.14.54 + esbuild-windows-32: 0.14.54 + esbuild-windows-64: 0.14.54 + esbuild-windows-arm64: 0.14.54 + dev: true + + /events/3.3.0: + resolution: {integrity: sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==} + engines: {node: '>=0.8.x'} + dev: false + + /fast-fifo/1.1.0: + resolution: {integrity: sha512-Kl29QoNbNvn4nhDsLYjyIAaIqaJB6rBx5p3sL9VjaefJ+eMFBWVZiaoguaoZfzEKr5RhAti0UgM8703akGPJ6g==} + dev: false + + /fs.realpath/1.0.0: + resolution: {integrity: sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==} + dev: true + + /function-bind/1.1.1: + resolution: {integrity: sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==} + dev: false + + /glob/7.2.3: + resolution: {integrity: sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==} + dependencies: + fs.realpath: 1.0.0 + inflight: 1.0.6 + inherits: 2.0.4 + minimatch: 3.1.2 + once: 1.4.0 + path-is-absolute: 1.0.1 + dev: true + + /has/1.0.3: + resolution: {integrity: sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==} + engines: {node: '>= 0.4.0'} + dependencies: + function-bind: 1.1.1 + dev: false + + /hypercore-crypto/3.3.1: + resolution: {integrity: sha512-Fo0ZBMDW3P7HFh58AQdxsVop0Xh0Bper4Pyl5Dpc+tvGos6je2ufJpeepaHaI0mNkKq4we1ikd47kTnx2XJd/w==} + dependencies: + b4a: 1.6.1 + compact-encoding: 2.11.0 + sodium-universal: 4.0.0 + dev: false + + /hyperswarm/4.3.7: + resolution: {integrity: sha512-COL8cMmBUa0ElZ85oFT1KQnZh1UkfJ75VavyypXZplGErlajqbnI2CDNF9K7cGiIk7xXR0RI6otx3495WSOB2Q==} + dependencies: + '@hyperswarm/dht': 6.4.4 + b4a: 1.6.1 + events: 3.3.0 + safety-catch: 1.0.2 + shuffled-priority-queue: 2.1.0 + dev: false + + /inflight/1.0.6: + resolution: {integrity: sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==} + dependencies: + once: 1.4.0 + wrappy: 1.0.2 + dev: true + + /inherits/2.0.4: + resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} + dev: true + + /is-core-module/2.11.0: + resolution: {integrity: sha512-RRjxlvLDkD1YJwDbroBHMb+cukurkDWNyHx7D3oNB5x9rb5ogcksMC5wHCadcXoo67gVr/+3GFySh3134zi6rw==} + dependencies: + has: 1.0.3 + dev: false + + /kademlia-routing-table/1.0.1: + resolution: {integrity: sha512-dKk19sC3/+kWhBIvOKCthxVV+JH0NrswSBq4sA4eOkkPMqQM1rRuOWte1WSKXeP8r9Nx4NuiH2gny3lMddJTpw==} + dev: false + + /libkernel/0.1.48: + resolution: {integrity: sha512-h86j/D+5gnpw/h8DTQE1C9hWFRmQnw5ZU9L3fYTZIPqPEIIU40z+tnDp66Zbb6mcfYCr8+SGkhcCy3XsyHOvyQ==} + dependencies: + '@skynetlabs/libskynet': 0.0.48 + libskynet: 0.0.64 + dev: false + + /libkmodule/0.2.53: + resolution: {integrity: sha512-fwMcssu6mwH+xeuUwUFdGDYQgGvwuVs0RMtbBPEYHvPPOBDNbdesPmlax/+XwDn6XiGggg+wSvq7st2m4VbwEw==} + dependencies: + libskynet: 0.1.9 + dev: false + + /libskynet/0.0.64: + resolution: {integrity: sha512-OPIxvxNTbo7H6KWU1YgQkfksNGTSQYVDsmGTji05/Gv2ZpwTOVJF4AMvggCHyLije8fNe4ZXRrBEtLQI3kpAaQ==} + dev: false + + /libskynet/0.1.9: + resolution: {integrity: sha512-lYP4GUbDZXUd0PyTyHz7RBPXGSBFmFZrc2JirnV7tlL4ii3Zi6m79z73zGWoiDBrHI25RR9s9gdm/LdBeXz9nQ==} + dev: false + + /minimatch/3.1.2: + resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==} + dependencies: + brace-expansion: 1.1.11 + dev: true + + /nanoassert/2.0.0: + resolution: {integrity: sha512-7vO7n28+aYO4J+8w96AzhmU8G+Y/xpPDJz/se19ICsqj/momRbb9mh9ZUtkoJ5X3nTnPdhEJyc0qnM6yAsHBaA==} + dev: false + + /napi-macros/2.2.2: + resolution: {integrity: sha512-hmEVtAGYzVQpCKdbQea4skABsdXW4RUh5t5mJ2zzqowJS2OyXZTU1KhDVFhx+NlWZ4ap9mqR9TcDO3LTTttd+g==} + dev: false + + /nat-sampler/1.0.1: + resolution: {integrity: sha512-yQvyNN7xbqR8crTKk3U8gRgpcV1Az+vfCEijiHu9oHHsnIl8n3x+yXNHl42M6L3czGynAVoOT9TqBfS87gDdcw==} + dev: false + + /node-gyp-build/4.6.0: + resolution: {integrity: sha512-NTZVKn9IylLwUzaKjkas1e4u2DLNcV4rdYagA4PWdPwW87Bi7z+BznyKSRwS/761tV/lzCGXplWsiaMjLqP2zQ==} + hasBin: true + dev: false + + /noise-curve-ed/2.0.1: + resolution: {integrity: sha512-8HMZ40Wmarg8RQjVemLrjB49JSL6eGeOD+tlzaQW5/p+hNPfHFEMC3UZZ57zUqUprMuz6GN+gsPExpz2DWL+iA==} + dependencies: + b4a: 1.6.1 + nanoassert: 2.0.0 + sodium-universal: 4.0.0 + dev: false + + /noise-handshake/3.0.2: + resolution: {integrity: sha512-4RQ9/6R/GLKA3DPcLDeo954ZBZezHBNpc4YnhyisZ9DPiTRnc81aGdCbH3J9pHllDfj82/f9wKHRRsU7C6pNEg==} + dependencies: + b4a: 1.6.1 + nanoassert: 2.0.0 + sodium-universal: 4.0.0 + dev: false + + /once/1.4.0: + resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==} + dependencies: + wrappy: 1.0.2 + dev: true + + /path-is-absolute/1.0.1: + resolution: {integrity: sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==} + engines: {node: '>=0.10.0'} + dev: true + + /path-parse/1.0.7: + resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==} + dev: false + + /prettier/2.8.3: + resolution: {integrity: sha512-tJ/oJ4amDihPoufT5sM0Z1SKEuKay8LfVAMlbbhnnkvt6BUserZylqo2PN+p9KeljLr0OHa2rXHU1T8reeoTrw==} + engines: {node: '>=10.13.0'} + hasBin: true + dev: true + + /protomux/3.4.1: + resolution: {integrity: sha512-V8MDCiDGqxM4/hGOewmezbCX7HZfcYGtpdO0MK6pEhBLSknENuqqE98OEWyQuwDalfHULVO8ml7LSwTB5g5Z6g==} + dependencies: + b4a: 1.6.1 + compact-encoding: 2.11.0 + queue-tick: 1.0.1 + safety-catch: 1.0.2 + dev: false + + /queue-tick/1.0.1: + resolution: {integrity: sha512-kJt5qhMxoszgU/62PLP1CJytzd2NKetjSRnyuj31fDd3Rlcz3fzlFdFLD1SItunPwyqEOkca6GbV612BWfaBag==} + dev: false + + /record-cache/1.2.0: + resolution: {integrity: sha512-kyy3HWCez2WrotaL3O4fTn0rsIdfRKOdQQcEJ9KpvmKmbffKVvwsloX063EgRUlpJIXHiDQFhJcTbZequ2uTZw==} + dependencies: + b4a: 1.6.1 + dev: false + + /resolve/1.22.1: + resolution: {integrity: sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw==} + hasBin: true + dependencies: + is-core-module: 2.11.0 + path-parse: 1.0.7 + supports-preserve-symlinks-flag: 1.0.0 + dev: false + + /rimraf/3.0.2: + resolution: {integrity: sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==} + hasBin: true + dependencies: + glob: 7.2.3 + dev: true + + /safety-catch/1.0.2: + resolution: {integrity: sha512-C1UYVZ4dtbBxEtvOcpjBaaD27nP8MlvyAQEp2fOTOEe6pfUpk1cDUxij6BR1jZup6rSyUTaBBplK7LanskrULA==} + dev: false + + /sha256-universal/1.2.1: + resolution: {integrity: sha512-ghn3muhdn1ailCQqqceNxRgkOeZSVfSE13RQWEg6njB+itsFzGVSJv+O//2hvNXZuxVIRyNzrgsZ37SPDdGJJw==} + dependencies: + b4a: 1.6.1 + sha256-wasm: 2.2.2 + dev: false + + /sha256-wasm/2.2.2: + resolution: {integrity: sha512-qKSGARvao+JQlFiA+sjJZhJ/61gmW/3aNLblB2rsgIxDlDxsJPHo8a1seXj12oKtuHVgJSJJ7QEGBUYQN741lQ==} + dependencies: + b4a: 1.6.1 + nanoassert: 2.0.0 + dev: false + + /sha512-universal/1.2.1: + resolution: {integrity: sha512-kehYuigMoRkIngCv7rhgruLJNNHDnitGTBdkcYbCbooL8Cidj/bS78MDxByIjcc69M915WxcQTgZetZ1JbeQTQ==} + dependencies: + b4a: 1.6.1 + sha512-wasm: 2.3.4 + dev: false + + /sha512-wasm/2.3.4: + resolution: {integrity: sha512-akWoxJPGCB3aZCrZ+fm6VIFhJ/p8idBv7AWGFng/CZIrQo51oQNsvDbTSRXWAzIiZJvpy16oIDiCCPqTe21sKg==} + dependencies: + b4a: 1.6.1 + nanoassert: 2.0.0 + dev: false + + /shuffled-priority-queue/2.1.0: + resolution: {integrity: sha512-xhdh7fHyMsr0m/w2kDfRJuBFRS96b9l8ZPNWGaQ+PMvnUnZ/Eh+gJJ9NsHBd7P9k0399WYlCLzsy18EaMfyadA==} + dependencies: + unordered-set: 2.0.1 + dev: false + + /siphash24/1.3.1: + resolution: {integrity: sha512-moemC3ZKiTzH29nbFo3Iw8fbemWWod4vNs/WgKbQ54oEs6mE6XVlguxvinYjB+UmaE0PThgyED9fUkWvirT8hA==} + dependencies: + nanoassert: 2.0.0 + dev: false + + /sodium-javascript/0.8.0: + resolution: {integrity: sha512-rEBzR5mPxPES+UjyMDvKPIXy9ImF17KOJ32nJNi9uIquWpS/nfj+h6m05J5yLJaGXjgM72LmQoUbWZVxh/rmGg==} + dependencies: + blake2b: 2.1.4 + chacha20-universal: 1.0.4 + nanoassert: 2.0.0 + sha256-universal: 1.2.1 + sha512-universal: 1.2.1 + siphash24: 1.3.1 + xsalsa20: 1.2.0 + dev: false + + /sodium-native/3.4.1: + resolution: {integrity: sha512-PaNN/roiFWzVVTL6OqjzYct38NSXewdl2wz8SRB51Br/MLIJPrbM3XexhVWkq7D3UWMysfrhKVf1v1phZq6MeQ==} + requiresBuild: true + dependencies: + node-gyp-build: 4.6.0 + dev: false + + /sodium-native/4.0.1: + resolution: {integrity: sha512-OQTaxrVLtMvrnfcwZVsOTHe58MfDApJiHJNoOwcmmrhwvlYkfaUt2WuzRio8PgEMOd96R5aDHY49DCtock1zsA==} + requiresBuild: true + dependencies: + node-gyp-build: 4.6.0 + dev: false + + /sodium-secretstream/1.1.0: + resolution: {integrity: sha512-Qg7D2xomELDjDCWAmE4izk1aecG/il8pQIGmSWFaKgah/V58BVWG/PuSZF6vseTpcqnetIFGaOWzmPNzyTD50A==} + dependencies: + b4a: 1.6.1 + sodium-universal: 4.0.0 + dev: false + + /sodium-universal/3.1.0: + resolution: {integrity: sha512-N2gxk68Kg2qZLSJ4h0NffEhp4BjgWHCHXVlDi1aG1hA3y+ZeWEmHqnpml8Hy47QzfL1xLy5nwr9LcsWAg2Ep0A==} + dependencies: + blake2b: 2.1.4 + chacha20-universal: 1.0.4 + nanoassert: 2.0.0 + resolve: 1.22.1 + sha256-universal: 1.2.1 + sha512-universal: 1.2.1 + siphash24: 1.3.1 + sodium-javascript: 0.8.0 + sodium-native: 3.4.1 + xsalsa20: 1.2.0 + dev: false + + /sodium-universal/4.0.0: + resolution: {integrity: sha512-iKHl8XnBV96k1c75gwwzANFdephw/MDWSjQAjPmBE+du0y3P23Q8uf7AcdcfFsYAMwLg7WVBfSAIBtV/JvRsjA==} + dependencies: + blake2b: 2.1.4 + chacha20-universal: 1.0.4 + nanoassert: 2.0.0 + sha256-universal: 1.2.1 + sha512-universal: 1.2.1 + siphash24: 1.3.1 + sodium-javascript: 0.8.0 + sodium-native: 4.0.1 + xsalsa20: 1.2.0 + dev: false + + /streamx/2.13.2: + resolution: {integrity: sha512-+TWqixPhGDXEG9L/XczSbhfkmwAtGs3BJX5QNU6cvno+pOLKeszByWcnaTu6dg8efsTYqR8ZZuXWHhZfgrxMvA==} + dependencies: + fast-fifo: 1.1.0 + queue-tick: 1.0.1 + dev: false + + /supports-preserve-symlinks-flag/1.0.0: + resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==} + engines: {node: '>= 0.4'} + dev: false + + /time-ordered-set/1.0.2: + resolution: {integrity: sha512-vGO99JkxvgX+u+LtOKQEpYf31Kj3i/GNwVstfnh4dyINakMgeZCpew1e3Aj+06hEslhtHEd52g7m5IV+o1K8Mw==} + dev: false + + /timeout-refresh/2.0.1: + resolution: {integrity: sha512-SVqEcMZBsZF9mA78rjzCrYrUs37LMJk3ShZ851ygZYW1cMeIjs9mL57KO6Iv5mmjSQnOe/29/VAfGXo+oRCiVw==} + dev: false + + /typescript/4.9.5: + resolution: {integrity: sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==} + engines: {node: '>=4.2.0'} + hasBin: true + dev: true + + /udx-native/1.5.3: + resolution: {integrity: sha512-xoMrEYR5Hahsvx04w06WSc52Sq0Xe2KQtbucyixhIlg/paWN+PXN1J3Ca6h/67K9fo1kB+j8C3fAik/Jv5Q1Mg==} + requiresBuild: true + dependencies: + b4a: 1.6.1 + events: 3.3.0 + napi-macros: 2.2.2 + node-gyp-build: 4.6.0 + streamx: 2.13.2 + dev: false + + /unordered-set/2.0.1: + resolution: {integrity: sha512-eUmNTPzdx+q/WvOHW0bgGYLWvWHNT3PTKEQLg0MAQhc0AHASHVHoP/9YytYd4RBVariqno/mEUhVZN98CmD7bg==} + dev: false + + /wrappy/1.0.2: + resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==} + dev: true + + /xache/1.1.0: + resolution: {integrity: sha512-RQGZDHLy/uCvnIrAvaorZH/e6Dfrtxj16iVlGjkj4KD2/G/dNXNqhk5IdSucv5nSSnDK00y8Y/2csyRdHveJ+Q==} + dev: false + + /xsalsa20/1.2.0: + resolution: {integrity: sha512-FIr/DEeoHfj7ftfylnoFt3rAIRoWXpx2AoDfrT2qD2wtp7Dp+COajvs/Icb7uHqRW9m60f5iXZwdsJJO3kvb7w==} + dev: false + + git.lumeweb.com/LumeWeb/kernel-peer-discovery-client/ad426dafb19be8f79c64bb11c1c014b1031c96d0: + resolution: {commit: ad426dafb19be8f79c64bb11c1c014b1031c96d0, repo: https://git.lumeweb.com/LumeWeb/kernel-peer-discovery-client.git, type: git} + name: '@lumeweb/kernel-peer-discovery-client' + version: 0.1.0 + dependencies: + '@hyperswarm/dht-relay': 0.3.0 + '@lumeweb/libkernel-universal': git.lumeweb.com/LumeWeb/libkernel-universal/ae9c6eeb60cd5e350012c3e393ff8b846326e468 + '@lumeweb/peer-discovery': git.lumeweb.com/LumeWeb/peer-discovery/d2bd926275103d60fdd3c7c432eae5c278f49261 + hyperswarm: 4.3.7 + libkernel: 0.1.48 + libkmodule: 0.2.53 + dev: false + + git.lumeweb.com/LumeWeb/libkernel-universal/ae9c6eeb60cd5e350012c3e393ff8b846326e468: + resolution: {commit: ae9c6eeb60cd5e350012c3e393ff8b846326e468, repo: https://git.lumeweb.com/LumeWeb/libkernel-universal.git, type: git} + name: '@lumeweb/libkernel-universal' + version: 0.1.0 + dependencies: + '@siaweb/libweb': git.lumeweb.com/LumeWeb/libsiaweb/5e6cdba3e7d9a4b94e21ddcd5f2b5138fb440ee8 + libkernel: 0.1.48 + libkmodule: 0.2.53 + dev: false + + git.lumeweb.com/LumeWeb/libsiaweb/5e6cdba3e7d9a4b94e21ddcd5f2b5138fb440ee8: + resolution: {commit: 5e6cdba3e7d9a4b94e21ddcd5f2b5138fb440ee8, repo: https://git.lumeweb.com/LumeWeb/libsiaweb.git, type: git} + name: '@siaweb/libweb' + version: 0.1.0 + dev: false + + git.lumeweb.com/LumeWeb/peer-discovery/d2bd926275103d60fdd3c7c432eae5c278f49261: + resolution: {commit: d2bd926275103d60fdd3c7c432eae5c278f49261, repo: https://git.lumeweb.com/LumeWeb/peer-discovery.git, type: git} + name: '@lumeweb/peer-discovery' + version: 0.1.0 + dependencies: + b4a: 1.6.1 + dev: false diff --git a/src/index.ts b/src/index.ts index 857b1d9..b55cb4e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,99 +2,80 @@ import DhtNode from "@hyperswarm/dht-relay"; // @ts-ignore import Stream from "@hyperswarm/dht-relay/ws"; -// @ts-ignore -import createRoundRobin from "@derhuerst/round-robin-scheduler"; -// @ts-ignore -// @ts-ignore -import { blake2b, errTuple, hexToBuf } from "libskynet"; -// @ts-ignore -import { registryRead } from "libkmodule"; +import { createClient } from "@lumeweb/kernel-peer-discovery-client"; +import type { + PeerDiscoveryClient, + Peer, +} from "@lumeweb/kernel-peer-discovery-client"; +import { load } from "@lumeweb/libkernel-universal"; -import { unpack } from "msgpackr"; +// @ts-ignore +import Hyperswarm from "hyperswarm"; import randomNumber from "random-number-csprng"; +import EventEmitter from "node:events"; -const REGISTRY_DHT_KEY = "lumeweb-dht-node"; - -export default class DHT { +export default class HyperswarmWeb extends EventEmitter { private _options: any; - private _relays: Map = new Map(); - private _activeRelays: Map = new Map(); - private _maxConnections = 10; - private _inited = false; - - constructor(opts = {}) { - // @ts-ignore + private _relays: Set = new Set(); + private _activeRelay: Hyperswarm; + private _discovery: PeerDiscoveryClient; + constructor(opts: any = {}) { + super(); opts.custodial = false; this._options = opts; + this._discovery = createClient(); } ready(): Promise { - if (this._inited) { - return Promise.resolve(); - } - - this._inited = true; - return this.fillConnections(); + return this.ensureConnection(); } - get relays(): string[] { - return [...this._relays.keys()]; - } + private async ensureConnection(): Promise { + const logErr = (await load()).logErr; - get relayServers(): string[] { - return [...this._relays.values()]; - } - - public async addRelay(pubkey: string): Promise { - let entry: errTuple = await registryRead( - hexToBuf(pubkey).shift() as Uint8Array, - hashDataKey(REGISTRY_DHT_KEY) - ); - - if (entry[1] || !entry[0]?.exists) { - return false; + if (this._activeRelay) { + return; } - let host; + const relays = this.relays; - try { - host = unpack(entry[0].entryData); - } catch (e) { - return false; + do { + const index = await randomNumber(0, relays.length - 1); + const relay = relays[index]; + + let ret; + try { + ret = await this._discovery.discover(relay); + } catch (e) { + logErr(e); + relays.splice(index, 1); + continue; + } + + ret = ret as Peer; + + const connection = `wss://${ret.host}:${ret.port}`; + + if (!(await this.isServerAvailable(connection))) { + relays.splice(index, 1); + continue; + } + + this._activeRelay = new DhtNode( + new Stream(true, new WebSocket(connection)), + this._options + ); + + this._activeRelay.on("close", () => { + this._activeRelay = undefined; + }); + } while (relays.length > 0); + + if (!this._activeRelay) { + throw new Error("Failed to find an available relay"); } - const [domain, port] = host.split(":"); - - if (isNaN(parseInt(port))) { - return false; - } - - this._relays.set(pubkey, `wss://${domain}:${port}/`); - - if (this._inited) { - await this.fillConnections(); - } - - return true; - } - - public removeRelay(pubkey: string): boolean { - if (!this._relays.has(pubkey)) { - return false; - } - - if (this._activeRelays.has(pubkey)) { - this._activeRelays.get(pubkey).destroy(); - this._activeRelays.delete(pubkey); - } - - this._relays.delete(pubkey); - - return true; - } - - public clearRelays(): void { - [...this._relays.keys()].forEach(this.removeRelay); + await this._activeRelay.dht.ready(); } private async isServerAvailable(connection: string): Promise { @@ -109,99 +90,67 @@ export default class DHT { }); }); } - async connect(pubkey: string, options = {}): Promise { - if (this._activeRelays.size === 0) { - await this.fillConnections(); - } - if (this._activeRelays.size === 0) { - throw new Error("Failed to find an available relay"); + if (!this._activeRelay) { + await this.ensureConnection(); } - let index = 0; - - if (this._activeRelays.size > 1) { - index = await randomNumber(0, this._activeRelays.size - 1); - } - - const node = this._activeRelays.get([...this._activeRelays.keys()][index]); - - return node.connect(pubkey, options); + return this._activeRelay.connect(pubkey, options); } - private async fillConnections(): Promise { - let available: string[] = []; + get relays(): string[] { + return [...this._relays.values()]; + } - const updateAvailable = () => { - available = [...this._relays.keys()].filter( - (x) => ![...this._activeRelays.keys()].includes(x) - ); - }; - updateAvailable(); + public async addRelay(pubkey: string): Promise { + this._relays.add(pubkey); + } - let relayPromises = []; - while ( - this._activeRelays.size <= - Math.min(this._maxConnections, available.length) - ) { - if (0 === available.length) { - break; - } - - let relayIndex = 0; - - if (available.length > 1) { - relayIndex = await randomNumber(0, available.length - 1); - } - - const pubkey = available[relayIndex]; - const connection = this._relays.get(available[relayIndex]) as string; - - if (!(await this.isServerAvailable(connection))) { - available.splice(relayIndex, 1); - this.removeRelay(available[relayIndex]); - continue; - } - - const node = new DhtNode( - new Stream(true, new WebSocket(connection)), - this._options - ); - this._activeRelays.set(available[relayIndex], node); - updateAvailable(); - - relayPromises.push(node.ready()); - - node._protocol._stream.on("close", () => { - this._activeRelays.delete(pubkey); - }); + public removeRelay(pubkey: string): boolean { + if (!this._relays.has(pubkey)) { + return false; } - return Promise.allSettled(relayPromises); + this._relays.delete(pubkey); + + return true; + } + + public clearRelays(): void { + this._relays.clear(); + } + + on( + eventName: string | symbol, + listener: (...args: any[]) => void + ): Hyperswarm { + return this._activeRelay?.on(eventName, listener); + } + addListener( + eventName: string | symbol, + listener: (...args: any[]) => void + ): this { + return this.on(eventName, listener); + } + + off( + eventName: string | symbol, + listener: (...args: any[]) => void + ): Hyperswarm { + return this._activeRelay?.off(eventName, listener); + } + + removeListener( + eventName: string | symbol, + listener: (...args: any[]) => void + ): this { + return this.on(eventName, listener); + } + emit(eventName: string | symbol, ...args: any[]): boolean { + return this._activeRelay?.emit(eventName, ...args); + } + + once(eventName: string | symbol, listener: (...args: any[]) => void): this { + return this._activeRelay?.once(eventName, listener); } } - -export function hashDataKey(dataKey: string): Uint8Array { - return blake2b(encodeUtf8String(dataKey)); -} - -function encodeUtf8String(str: string): Uint8Array { - const byteArray = stringToUint8ArrayUtf8(str); - const encoded = new Uint8Array(8 + byteArray.length); - encoded.set(encodeNumber(byteArray.length)); - encoded.set(byteArray, 8); - return encoded; -} - -function stringToUint8ArrayUtf8(str: string): Uint8Array { - return new TextEncoder().encode(str); -} - -function encodeNumber(num: number): Uint8Array { - const encoded = new Uint8Array(8); - for (let index = 0; index < encoded.length; index++) { - encoded[index] = num & 0xff; - num = num >> 8; - } - return encoded; -}