chore(deps): bump @multiformats/multiaddr to 11.0.6

This commit is contained in:
fryorcraken.eth 2022-10-30 21:32:24 +11:00
parent 81f3af0f66
commit 2e60d90d7d
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
12 changed files with 132 additions and 56 deletions

72
package-lock.json generated
View File

@ -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": {

View File

@ -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",

View File

@ -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;
});

View File

@ -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;

View File

@ -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"
),
];

View File

@ -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;
}

View File

@ -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<ENR> {
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"
),
];

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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()
);

View File

@ -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);
}

View File

@ -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()
);