diff --git a/.cspell.json b/.cspell.json index 4d79829a48..41e08ddc95 100644 --- a/.cspell.json +++ b/.cspell.json @@ -63,6 +63,7 @@ "libp", "lightpush", "livechat", + "localstorage", "Merkle", "mkdir", "mplex", diff --git a/package-lock.json b/package-lock.json index 2ec7f04338..fd854090bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24321,7 +24321,6 @@ "version": "3.0.5", "resolved": "https://registry.npmjs.org/node-localstorage/-/node-localstorage-3.0.5.tgz", "integrity": "sha512-GCwtK33iwVXboZWYcqQHu3aRvXEBwmPkAMRBLeaX86ufhqslyUkLGsi4aW3INEfdQYpUB5M9qtYf3eHvAk2VBg==", - "dev": true, "dependencies": { "write-file-atomic": "^5.0.1" }, @@ -24333,7 +24332,6 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-5.0.1.tgz", "integrity": "sha512-+QU2zd6OTD8XWIJCbffaiQeH9U73qIqafo1x6V1snCWYGJf6cVE0cDR4D8xRzcEnfI21IFrUPzPGtcPf8AC+Rw==", - "dev": true, "dependencies": { "imurmurhash": "^0.1.4", "signal-exit": "^4.0.1" @@ -36494,15 +36492,15 @@ }, "packages/core": { "name": "@waku/core", - "version": "0.0.27", + "version": "0.0.28", "license": "MIT OR Apache-2.0", "dependencies": { "@libp2p/ping": "^1.0.12", - "@waku/enr": "^0.0.21", - "@waku/interfaces": "0.0.22", - "@waku/message-hash": "^0.1.11", + "@waku/enr": "^0.0.22", + "@waku/interfaces": "0.0.23", + "@waku/message-hash": "^0.1.12", "@waku/proto": "0.0.6", - "@waku/utils": "0.0.15", + "@waku/utils": "0.0.16", "debug": "^4.3.4", "it-all": "^3.0.4", "it-length-prefixed": "^9.0.4", @@ -36557,14 +36555,15 @@ "version": "0.0.1", "license": "MIT OR Apache-2.0", "dependencies": { - "@waku/core": "0.0.27", - "@waku/enr": "0.0.21", - "@waku/interfaces": "0.0.22", + "@waku/core": "0.0.28", + "@waku/enr": "0.0.22", + "@waku/interfaces": "0.0.23", "@waku/proto": "^0.0.6", - "@waku/utils": "0.0.15", + "@waku/utils": "0.0.16", "debug": "^4.3.4", "dns-query": "^0.11.2", "hi-base32": "^0.5.1", + "node-localstorage": "^3.0.5", "uint8arrays": "^5.0.1" }, "devDependencies": { @@ -36581,7 +36580,6 @@ "chai-as-promised": "^7.1.1", "cspell": "^8.6.1", "mocha": "^10.3.0", - "node-localstorage": "^3.0.5", "npm-run-all": "^4.1.5", "rollup": "^4.12.0", "sinon": "^17.0.1" @@ -36608,7 +36606,7 @@ }, "packages/enr": { "name": "@waku/enr", - "version": "0.0.21", + "version": "0.0.22", "license": "MIT OR Apache-2.0", "dependencies": { "@ethersproject/rlp": "^5.7.0", @@ -36616,7 +36614,7 @@ "@libp2p/peer-id": "^4.0.4", "@multiformats/multiaddr": "^12.0.0", "@noble/secp256k1": "^1.7.1", - "@waku/utils": "0.0.15", + "@waku/utils": "0.0.16", "debug": "^4.3.4", "js-sha3": "^0.9.2" }, @@ -36628,7 +36626,7 @@ "@types/chai": "^4.3.11", "@types/mocha": "^10.0.6", "@waku/build-utils": "*", - "@waku/interfaces": "0.0.22", + "@waku/interfaces": "0.0.23", "chai": "^4.3.10", "cspell": "^8.6.1", "fast-check": "^3.15.1", @@ -36657,7 +36655,7 @@ }, "packages/interfaces": { "name": "@waku/interfaces", - "version": "0.0.22", + "version": "0.0.23", "license": "MIT OR Apache-2.0", "dependencies": { "@waku/proto": "^0.0.6" @@ -36675,14 +36673,14 @@ }, "packages/message-encryption": { "name": "@waku/message-encryption", - "version": "0.0.25", + "version": "0.0.26", "license": "MIT OR Apache-2.0", "dependencies": { "@noble/secp256k1": "^1.7.1", - "@waku/core": "0.0.27", - "@waku/interfaces": "0.0.22", + "@waku/core": "0.0.28", + "@waku/interfaces": "0.0.23", "@waku/proto": "0.0.6", - "@waku/utils": "0.0.15", + "@waku/utils": "0.0.16", "debug": "^4.3.4", "js-sha3": "^0.9.2", "uint8arrays": "^5.0.1" @@ -36719,11 +36717,11 @@ }, "packages/message-hash": { "name": "@waku/message-hash", - "version": "0.1.11", + "version": "0.1.12", "license": "MIT OR Apache-2.0", "dependencies": { "@noble/hashes": "^1.3.2", - "@waku/utils": "0.0.15" + "@waku/utils": "0.0.16" }, "devDependencies": { "@rollup/plugin-commonjs": "^25.0.7", @@ -36733,7 +36731,7 @@ "@types/debug": "^4.1.12", "@types/mocha": "^10.0.6", "@waku/build-utils": "*", - "@waku/interfaces": "0.0.22", + "@waku/interfaces": "0.0.23", "chai": "^4.3.10", "cspell": "^8.6.1", "fast-check": "^3.15.1", @@ -36801,15 +36799,15 @@ }, "packages/relay": { "name": "@waku/relay", - "version": "0.0.10", + "version": "0.0.11", "license": "MIT OR Apache-2.0", "dependencies": { "@chainsafe/libp2p-gossipsub": "^12.0.0", "@noble/hashes": "^1.3.2", - "@waku/core": "0.0.27", - "@waku/interfaces": "0.0.22", + "@waku/core": "0.0.28", + "@waku/interfaces": "0.0.23", "@waku/proto": "0.0.6", - "@waku/utils": "0.0.15", + "@waku/utils": "0.0.16", "chai": "^4.3.10", "debug": "^4.3.4", "fast-check": "^3.15.1" @@ -36842,7 +36840,7 @@ }, "packages/sdk": { "name": "@waku/sdk", - "version": "0.0.23", + "version": "0.0.24", "license": "MIT OR Apache-2.0", "dependencies": { "@chainsafe/libp2p-noise": "^14.1.0", @@ -36852,11 +36850,11 @@ "@libp2p/ping": "^1.0.12", "@libp2p/websockets": "^8.0.11", "@noble/hashes": "^1.3.3", - "@waku/core": "0.0.27", + "@waku/core": "0.0.28", "@waku/discovery": "0.0.1", - "@waku/interfaces": "0.0.22", - "@waku/relay": "0.0.10", - "@waku/utils": "0.0.15", + "@waku/interfaces": "0.0.23", + "@waku/relay": "0.0.11", + "@waku/utils": "0.0.16", "libp2p": "^1.1.2" }, "devDependencies": { @@ -36940,11 +36938,11 @@ }, "packages/utils": { "name": "@waku/utils", - "version": "0.0.15", + "version": "0.0.16", "license": "MIT OR Apache-2.0", "dependencies": { "@noble/hashes": "^1.3.2", - "@waku/interfaces": "0.0.22", + "@waku/interfaces": "0.0.23", "chai": "^4.3.10", "debug": "^4.3.4", "uint8arrays": "^5.0.1" diff --git a/packages/discovery/package.json b/packages/discovery/package.json index d70a540713..b583a6bec5 100644 --- a/packages/discovery/package.json +++ b/packages/discovery/package.json @@ -59,7 +59,8 @@ "debug": "^4.3.4", "dns-query": "^0.11.2", "hi-base32": "^0.5.1", - "uint8arrays": "^5.0.1" + "uint8arrays": "^5.0.1", + "node-localstorage": "^3.0.5" }, "devDependencies": { "@libp2p/peer-id": "^4.0.4", @@ -75,7 +76,6 @@ "chai-as-promised": "^7.1.1", "cspell": "^8.6.1", "mocha": "^10.3.0", - "node-localstorage": "^3.0.5", "npm-run-all": "^4.1.5", "rollup": "^4.12.0", "sinon": "^17.0.1" diff --git a/packages/discovery/src/local-peer-cache/index.spec.ts b/packages/discovery/src/local-peer-cache/index.spec.ts index 28cb0677d5..6a3f07624c 100644 --- a/packages/discovery/src/local-peer-cache/index.spec.ts +++ b/packages/discovery/src/local-peer-cache/index.spec.ts @@ -17,16 +17,6 @@ import { LocalPeerCacheDiscovery } from "./index.js"; chai.use(chaiAsPromised); -// dynamically importing the local storage polyfill for node -if (typeof window === "undefined") { - try { - const { LocalStorage } = await import("node-localstorage"); - global.localStorage = new LocalStorage("./scratch"); - } catch (error) { - console.error("Failed to load localStorage polyfill:", error); - } -} - const mockPeers = [ { id: "16Uiu2HAm4v86W3bmT1BiH6oSPzcsSr24iDQpSN5Qa992BCjjwgrD", diff --git a/packages/discovery/src/local-peer-cache/index.ts b/packages/discovery/src/local-peer-cache/index.ts index 14a79013e7..7b5e8faa1b 100644 --- a/packages/discovery/src/local-peer-cache/index.ts +++ b/packages/discovery/src/local-peer-cache/index.ts @@ -28,6 +28,16 @@ export const DEFAULT_LOCAL_TAG_NAME = Tags.LOCAL; const DEFAULT_LOCAL_TAG_VALUE = 50; const DEFAULT_LOCAL_TAG_TTL = 100_000_000; +// dynamically importing the local storage polyfill for node environments +if (typeof window === "undefined") { + try { + const { LocalStorage } = await import("node-localstorage"); + global.localStorage = new LocalStorage("./mock-localstorage"); + } catch (error) { + log.error("Failed to load localStorage polyfill:", error); + } +} + export class LocalPeerCacheDiscovery extends TypedEventEmitter implements PeerDiscovery, Startable