diff --git a/package-lock.json b/package-lock.json index 488d3334a8..c6155fc6fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17997,7 +17997,7 @@ "@libp2p/mplex": "^5.1.1", "@libp2p/peer-id": "^1.1.10", "@libp2p/websockets": "^3.0.3", - "@multiformats/multiaddr": "^10.4.0", + "@multiformats/multiaddr": "^11.0.6", "@noble/secp256k1": "^1.3.4", "debug": "^4.3.4", "dns-query": "^0.11.2", @@ -18066,6 +18066,44 @@ "engines": { "node": ">=16" } + }, + "packages/core/node_modules/@multiformats/multiaddr": { + "version": "11.0.6", + "resolved": "https://registry.npmjs.org/@multiformats/multiaddr/-/multiaddr-11.0.6.tgz", + "integrity": "sha512-5TvEdCc5uFqcwGA+IwSw49swyHtUbwjhjwF3WQcV9vkzTv1C8oEWhoD2QcsiomDRk8rdqqRyDH6wlZExvLnxjw==", + "dependencies": { + "@chainsafe/is-ip": "^1.0.0", + "dns-over-http-resolver": "^2.1.0", + "err-code": "^3.0.1", + "multiformats": "^10.0.0", + "uint8arrays": "^4.0.2", + "varint": "^6.0.0" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "packages/core/node_modules/@multiformats/multiaddr/node_modules/uint8arrays": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-4.0.2.tgz", + "integrity": "sha512-8CWXXZdOvVrIL4SeY/Gnp+idxxiGK4XFkP4FY26Sx/fpTz/b6vv4BVWELMDzQweSyyhdcuAcU14H6izzB6k1Cw==", + "dependencies": { + "multiformats": "^10.0.0" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "packages/core/node_modules/multiformats": { + "version": "10.0.2", + "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-10.0.2.tgz", + "integrity": "sha512-nJEHLFOYhO4L+aNApHhCnWqa31FyqAHv9Q77AhmwU3KsM2f1j7tuJpCk5ByZ33smzycNCpSG5klNIejIyfFx2A==", + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } } }, "dependencies": { @@ -26378,7 +26416,7 @@ "@libp2p/peer-id": "^1.1.10", "@libp2p/peer-id-factory": "^1.0.15", "@libp2p/websockets": "^3.0.3", - "@multiformats/multiaddr": "^10.4.0", + "@multiformats/multiaddr": "^11.0.6", "@noble/secp256k1": "^1.3.4", "@rollup/plugin-commonjs": "^22.0.0", "@rollup/plugin-json": "^4.1.0", @@ -26440,6 +26478,36 @@ "uint8arraylist": "^2.3.2", "uint8arrays": "^3.0.0", "uuid": "^8.3.2" + }, + "dependencies": { + "@multiformats/multiaddr": { + "version": "11.0.6", + "resolved": "https://registry.npmjs.org/@multiformats/multiaddr/-/multiaddr-11.0.6.tgz", + "integrity": "sha512-5TvEdCc5uFqcwGA+IwSw49swyHtUbwjhjwF3WQcV9vkzTv1C8oEWhoD2QcsiomDRk8rdqqRyDH6wlZExvLnxjw==", + "requires": { + "@chainsafe/is-ip": "^1.0.0", + "dns-over-http-resolver": "^2.1.0", + "err-code": "^3.0.1", + "multiformats": "^10.0.0", + "uint8arrays": "^4.0.2", + "varint": "^6.0.0" + }, + "dependencies": { + "uint8arrays": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-4.0.2.tgz", + "integrity": "sha512-8CWXXZdOvVrIL4SeY/Gnp+idxxiGK4XFkP4FY26Sx/fpTz/b6vv4BVWELMDzQweSyyhdcuAcU14H6izzB6k1Cw==", + "requires": { + "multiformats": "^10.0.0" + } + } + } + }, + "multiformats": { + "version": "10.0.2", + "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-10.0.2.tgz", + "integrity": "sha512-nJEHLFOYhO4L+aNApHhCnWqa31FyqAHv9Q77AhmwU3KsM2f1j7tuJpCk5ByZ33smzycNCpSG5klNIejIyfFx2A==" + } } }, "js-yaml": { diff --git a/packages/core/package.json b/packages/core/package.json index 33fe7a6b47..a92193d0fe 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -114,7 +114,7 @@ "@libp2p/mplex": "^5.1.1", "@libp2p/peer-id": "^1.1.10", "@libp2p/websockets": "^3.0.3", - "@multiformats/multiaddr": "^10.4.0", + "@multiformats/multiaddr": "^11.0.6", "@noble/secp256k1": "^1.3.4", "debug": "^4.3.4", "dns-query": "^0.11.2", diff --git a/packages/core/src/lib/enr/enr.spec.ts b/packages/core/src/lib/enr/enr.spec.ts index 5d5c096443..0db843eae0 100644 --- a/packages/core/src/lib/enr/enr.spec.ts +++ b/packages/core/src/lib/enr/enr.spec.ts @@ -1,5 +1,5 @@ import { createSecp256k1PeerId } from "@libp2p/peer-id-factory"; -import { Multiaddr } from "@multiformats/multiaddr"; +import { multiaddr } from "@multiformats/multiaddr"; import { assert, expect } from "chai"; import { equals } from "uint8arrays/equals"; @@ -17,15 +17,11 @@ describe("ENR", function () { const peerId = await createSecp256k1PeerId(); const enr = await ENR.createFromPeerId(peerId); const keypair = await createKeypairFromPeerId(peerId); - enr.setLocationMultiaddr(new Multiaddr("/ip4/18.223.219.100/udp/9000")); + enr.setLocationMultiaddr(multiaddr("/ip4/18.223.219.100/udp/9000")); enr.multiaddrs = [ - new Multiaddr( - "/dns4/node1.do-ams.wakuv2.test.statusim.net/tcp/443/wss" - ), - new Multiaddr( - "/dns6/node2.ac-chi.wakuv2.test.statusim.net/tcp/443/wss" - ), - new Multiaddr( + multiaddr("/dns4/node1.do-ams.wakuv2.test.statusim.net/tcp/443/wss"), + multiaddr("/dns6/node2.ac-chi.wakuv2.test.statusim.net/tcp/443/wss"), + multiaddr( "/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:1234/wss" ), ]; @@ -44,8 +40,8 @@ describe("ENR", function () { if (!enr2.signature) throw "enr.signature is undefined"; expect(bytesToHex(enr2.signature)).to.be.equal(bytesToHex(enr.signature)); - const multiaddr = enr2.getLocationMultiaddr("udp")!; - expect(multiaddr.toString()).to.be.equal("/ip4/18.223.219.100/udp/9000"); + const ma = enr2.getLocationMultiaddr("udp")!; + expect(ma.toString()).to.be.equal("/ip4/18.223.219.100/udp/9000"); expect(enr2.multiaddrs).to.not.be.undefined; expect(enr2.multiaddrs!.length).to.be.equal(3); const multiaddrsAsStr = enr2.multiaddrs!.map((ma) => ma.toString()); @@ -113,12 +109,12 @@ describe("ENR", function () { const peerId = await createSecp256k1PeerId(); const enr = await ENR.createFromPeerId(peerId); const keypair = await createKeypairFromPeerId(peerId); - enr.setLocationMultiaddr(new Multiaddr("/ip4/18.223.219.100/udp/9000")); + enr.setLocationMultiaddr(multiaddr("/ip4/18.223.219.100/udp/9000")); enr.set("id", new Uint8Array([0])); const txt = await enr.encodeTxt(keypair.privateKey); - ENR.decodeTxt(txt); + await ENR.decodeTxt(txt); assert.fail("Expect error here"); } catch (err: unknown) { const e = err as Error; @@ -200,7 +196,7 @@ describe("ENR", function () { "b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" ); record = await ENR.createV4(getPublicKey(privateKey)); - record.setLocationMultiaddr(new Multiaddr("/ip4/127.0.0.1/udp/30303")); + record.setLocationMultiaddr(multiaddr("/ip4/127.0.0.1/udp/30303")); record.seq = seq; await record.encodeTxt(privateKey); }); @@ -248,7 +244,7 @@ describe("ENR", function () { }); it("should get / set UDP multiaddr", () => { - const multi0 = new Multiaddr("/ip4/127.0.0.1/udp/30303"); + const multi0 = multiaddr("/ip4/127.0.0.1/udp/30303"); const tuples0 = multi0.tuples(); if (!tuples0[0][1] || !tuples0[1][1]) { @@ -262,7 +258,7 @@ describe("ENR", function () { multi0.toString() ); // set the multiaddr - const multi1 = new Multiaddr("/ip4/0.0.0.0/udp/30300"); + const multi1 = multiaddr("/ip4/0.0.0.0/udp/30300"); record.setLocationMultiaddr(multi1); // and get the multiaddr expect(record.getLocationMultiaddr("udp")!.toString()).to.equal( @@ -275,7 +271,7 @@ describe("ENR", function () { }); it("should get / set TCP multiaddr", () => { - const multi0 = new Multiaddr("/ip4/127.0.0.1/tcp/30303"); + const multi0 = multiaddr("/ip4/127.0.0.1/tcp/30303"); const tuples0 = multi0.tuples(); if (!tuples0[0][1] || !tuples0[1][1]) { @@ -290,7 +286,7 @@ describe("ENR", function () { multi0.toString() ); // set the multiaddr - const multi1 = new Multiaddr("/ip4/0.0.0.0/tcp/30300"); + const multi1 = multiaddr("/ip4/0.0.0.0/tcp/30300"); record.setLocationMultiaddr(multi1); // and get the multiaddr expect(record.getLocationMultiaddr("tcp")!.toString()).to.equal( @@ -324,43 +320,43 @@ describe("ENR", function () { it("should properly create location multiaddrs - udp4", () => { expect(enr.getLocationMultiaddr("udp4")).to.deep.equal( - new Multiaddr(`/ip4/${ip4}/udp/${udp}`) + multiaddr(`/ip4/${ip4}/udp/${udp}`) ); }); it("should properly create location multiaddrs - tcp4", () => { expect(enr.getLocationMultiaddr("tcp4")).to.deep.equal( - new Multiaddr(`/ip4/${ip4}/tcp/${tcp}`) + multiaddr(`/ip4/${ip4}/tcp/${tcp}`) ); }); it("should properly create location multiaddrs - udp6", () => { expect(enr.getLocationMultiaddr("udp6")).to.deep.equal( - new Multiaddr(`/ip6/${ip6}/udp/${udp}`) + multiaddr(`/ip6/${ip6}/udp/${udp}`) ); }); it("should properly create location multiaddrs - tcp6", () => { expect(enr.getLocationMultiaddr("tcp6")).to.deep.equal( - new Multiaddr(`/ip6/${ip6}/tcp/${tcp}`) + multiaddr(`/ip6/${ip6}/tcp/${tcp}`) ); }); it("should properly create location multiaddrs - udp", () => { // default to ip4 expect(enr.getLocationMultiaddr("udp")).to.deep.equal( - new Multiaddr(`/ip4/${ip4}/udp/${udp}`) + multiaddr(`/ip4/${ip4}/udp/${udp}`) ); // if ip6 is set, use it enr.ip = undefined; expect(enr.getLocationMultiaddr("udp")).to.deep.equal( - new Multiaddr(`/ip6/${ip6}/udp/${udp}`) + multiaddr(`/ip6/${ip6}/udp/${udp}`) ); // if ip6 does not exist, use ip4 enr.ip6 = undefined; enr.ip = ip4; expect(enr.getLocationMultiaddr("udp")).to.deep.equal( - new Multiaddr(`/ip4/${ip4}/udp/${udp}`) + multiaddr(`/ip4/${ip4}/udp/${udp}`) ); enr.ip6 = ip6; }); @@ -368,18 +364,18 @@ describe("ENR", function () { it("should properly create location multiaddrs - tcp", () => { // default to ip4 expect(enr.getLocationMultiaddr("tcp")).to.deep.equal( - new Multiaddr(`/ip4/${ip4}/tcp/${tcp}`) + multiaddr(`/ip4/${ip4}/tcp/${tcp}`) ); // if ip6 is set, use it enr.ip = undefined; expect(enr.getLocationMultiaddr("tcp")).to.deep.equal( - new Multiaddr(`/ip6/${ip6}/tcp/${tcp}`) + multiaddr(`/ip6/${ip6}/tcp/${tcp}`) ); // if ip6 does not exist, use ip4 enr.ip6 = undefined; enr.ip = ip4; expect(enr.getLocationMultiaddr("tcp")).to.deep.equal( - new Multiaddr(`/ip4/${ip4}/tcp/${tcp}`) + multiaddr(`/ip4/${ip4}/tcp/${tcp}`) ); enr.ip6 = ip6; }); diff --git a/packages/core/src/lib/enr/multiaddr_from_fields.ts b/packages/core/src/lib/enr/multiaddr_from_fields.ts index f12bee403e..49574f9d12 100644 --- a/packages/core/src/lib/enr/multiaddr_from_fields.ts +++ b/packages/core/src/lib/enr/multiaddr_from_fields.ts @@ -1,4 +1,5 @@ -import { Multiaddr } from "@multiformats/multiaddr"; +import { multiaddr } from "@multiformats/multiaddr"; +import type { Multiaddr } from "@multiformats/multiaddr"; import { convertToString } from "@multiformats/multiaddr/convert"; export function multiaddrFromFields( @@ -7,14 +8,10 @@ export function multiaddrFromFields( ipBytes: Uint8Array, protocolBytes: Uint8Array ): Multiaddr { - let ma = new Multiaddr( - "/" + ipFamily + "/" + convertToString(ipFamily, ipBytes) - ); + let ma = multiaddr("/" + ipFamily + "/" + convertToString(ipFamily, ipBytes)); ma = ma.encapsulate( - new Multiaddr( - "/" + protocol + "/" + convertToString(protocol, protocolBytes) - ) + multiaddr("/" + protocol + "/" + convertToString(protocol, protocolBytes)) ); return ma; diff --git a/packages/core/src/lib/enr/multiaddrs_codec.spec.ts b/packages/core/src/lib/enr/multiaddrs_codec.spec.ts index 16cdad56f9..c430e8f9e7 100644 --- a/packages/core/src/lib/enr/multiaddrs_codec.spec.ts +++ b/packages/core/src/lib/enr/multiaddrs_codec.spec.ts @@ -1,4 +1,4 @@ -import { Multiaddr } from "@multiformats/multiaddr"; +import { multiaddr } from "@multiformats/multiaddr"; import { expect } from "chai"; import { decodeMultiaddrs, encodeMultiaddrs } from "./multiaddrs_codec"; @@ -6,13 +6,11 @@ import { decodeMultiaddrs, encodeMultiaddrs } from "./multiaddrs_codec"; describe("ENR multiaddrs codec", function () { it("Sample", async () => { const multiaddrs = [ - new Multiaddr( - "/dns4/node-01.do-ams3.wakuv2.test.statusim.net/tcp/443/wss" - ), - new Multiaddr( + multiaddr("/dns4/node-01.do-ams3.wakuv2.test.statusim.net/tcp/443/wss"), + multiaddr( "/dns6/node-01.ac-cn-hongkong-c.wakuv2.test.statusim.net/tcp/443/wss" ), - new Multiaddr( + multiaddr( "/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:1234/wss" ), ]; diff --git a/packages/core/src/lib/enr/multiaddrs_codec.ts b/packages/core/src/lib/enr/multiaddrs_codec.ts index c23df779ca..c7d204eb5f 100644 --- a/packages/core/src/lib/enr/multiaddrs_codec.ts +++ b/packages/core/src/lib/enr/multiaddrs_codec.ts @@ -1,4 +1,5 @@ -import { Multiaddr } from "@multiformats/multiaddr"; +import { multiaddr } from "@multiformats/multiaddr"; +import type { Multiaddr } from "@multiformats/multiaddr"; import { MULTIADDR_LENGTH_SIZE } from "./constants"; @@ -19,8 +20,8 @@ export function decodeMultiaddrs(bytes: Uint8Array): Multiaddr[] { const multiaddrBytes = bytes.slice(index, index + size); index += size; - const multiaddr = new Multiaddr(multiaddrBytes); - multiaddrs.push(multiaddr); + const ma = multiaddr(multiaddrBytes); + multiaddrs.push(ma); } return multiaddrs; } diff --git a/packages/core/src/lib/peer_discovery_dns/fetch_nodes.spec.ts b/packages/core/src/lib/peer_discovery_dns/fetch_nodes.spec.ts index ac98e4c786..01db0c1993 100644 --- a/packages/core/src/lib/peer_discovery_dns/fetch_nodes.spec.ts +++ b/packages/core/src/lib/peer_discovery_dns/fetch_nodes.spec.ts @@ -1,5 +1,5 @@ import { createSecp256k1PeerId } from "@libp2p/peer-id-factory"; -import { Multiaddr } from "@multiformats/multiaddr"; +import { multiaddr } from "@multiformats/multiaddr"; import { expect } from "chai"; import { ENR, Waku2 } from "../enr"; @@ -9,11 +9,11 @@ import { fetchNodesUntilCapabilitiesFulfilled } from "./fetch_nodes"; async function createEnr(waku2: Waku2): Promise { const peerId = await createSecp256k1PeerId(); const enr = await ENR.createFromPeerId(peerId); - enr.setLocationMultiaddr(new Multiaddr("/ip4/18.223.219.100/udp/9000")); + enr.setLocationMultiaddr(multiaddr("/ip4/18.223.219.100/udp/9000")); enr.multiaddrs = [ - new Multiaddr("/dns4/node1.do-ams.wakuv2.test.statusim.net/tcp/443/wss"), - new Multiaddr("/dns6/node2.ac-chi.wakuv2.test.statusim.net/tcp/443/wss"), - new Multiaddr( + multiaddr("/dns4/node1.do-ams.wakuv2.test.statusim.net/tcp/443/wss"), + multiaddr("/dns6/node2.ac-chi.wakuv2.test.statusim.net/tcp/443/wss"), + multiaddr( "/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:1234/wss" ), ]; diff --git a/packages/core/src/lib/peer_discovery_static_list.ts b/packages/core/src/lib/peer_discovery_static_list.ts index 0e091550d8..a50d089e35 100644 --- a/packages/core/src/lib/peer_discovery_static_list.ts +++ b/packages/core/src/lib/peer_discovery_static_list.ts @@ -5,7 +5,8 @@ import type { import { symbol } from "@libp2p/interface-peer-discovery"; import type { PeerInfo } from "@libp2p/interface-peer-info"; import { CustomEvent, EventEmitter } from "@libp2p/interfaces/events"; -import { Multiaddr } from "@multiformats/multiaddr"; +import type { Multiaddr } from "@multiformats/multiaddr"; +import { multiaddr } from "@multiformats/multiaddr"; import debug from "debug"; import { multiaddrsToPeerInfo } from "./multiaddr_to_peer_info"; @@ -52,7 +53,7 @@ export class PeerDiscoveryStaticPeers const peerMas = peers.map((peer: string | Multiaddr) => { if (typeof peer === "string") { - return new Multiaddr(peer); + return multiaddr(peer); } else { return peer; } diff --git a/packages/core/src/lib/predefined_bootstrap_nodes.ts b/packages/core/src/lib/predefined_bootstrap_nodes.ts index 2f28e1c3ee..cfe4bf2983 100644 --- a/packages/core/src/lib/predefined_bootstrap_nodes.ts +++ b/packages/core/src/lib/predefined_bootstrap_nodes.ts @@ -1,4 +1,5 @@ -import { Multiaddr } from "@multiformats/multiaddr"; +import type { Multiaddr } from "@multiformats/multiaddr"; +import { multiaddr } from "@multiformats/multiaddr"; import { getPseudoRandomSubset } from "./random_subset"; @@ -41,7 +42,7 @@ export function getPredefinedBootstrapNodes( nodes = Object.values(nodes) as string[]; - nodes = nodes.map((node: string) => new Multiaddr(node)); + nodes = nodes.map((node: string) => multiaddr(node)); return getPseudoRandomSubset(nodes, wantedNumber); } diff --git a/packages/core/src/lib/waku.node.spec.ts b/packages/core/src/lib/waku.node.spec.ts index a0ec3f1c25..3418c80281 100644 --- a/packages/core/src/lib/waku.node.spec.ts +++ b/packages/core/src/lib/waku.node.spec.ts @@ -141,6 +141,9 @@ describe("Decryption Keys", () => { waku1.addPeerToAddressBook( waku2.libp2p.peerId, + // TODO: Upgrade libp2p package. + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore: New multiaddr type but they seem mostly compatible waku2.libp2p.getMultiaddrs() ); diff --git a/packages/core/src/lib/waku.ts b/packages/core/src/lib/waku.ts index 2262767a20..ca8449c02c 100644 --- a/packages/core/src/lib/waku.ts +++ b/packages/core/src/lib/waku.ts @@ -137,6 +137,8 @@ export class WakuNode implements Waku { codecs.push(FilterCodec); } + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore: new Multiaddr is not backward compatible return this.libp2p.dialProtocol(peer, codecs); } diff --git a/packages/core/src/lib/waku_relay/index.node.spec.ts b/packages/core/src/lib/waku_relay/index.node.spec.ts index 89d63281a4..931a2c0e32 100644 --- a/packages/core/src/lib/waku_relay/index.node.spec.ts +++ b/packages/core/src/lib/waku_relay/index.node.spec.ts @@ -64,6 +64,9 @@ describe("Waku Relay [node only]", () => { log("Instances started, adding waku2 to waku1's address book"); waku1.addPeerToAddressBook( waku2.libp2p.peerId, + // TODO: Upgrade libp2p package. + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore: New multiaddr type but they seem mostly compatible waku2.libp2p.getMultiaddrs() ); @@ -279,10 +282,16 @@ describe("Waku Relay [node only]", () => { waku1.addPeerToAddressBook( waku2.libp2p.peerId, + // TODO: Upgrade libp2p package. + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore: New multiaddr type but they seem mostly compatible waku2.libp2p.getMultiaddrs() ); waku3.addPeerToAddressBook( waku2.libp2p.peerId, + // TODO: Upgrade libp2p package. + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore: New multiaddr type but they seem mostly compatible waku2.libp2p.getMultiaddrs() );