mirror of https://github.com/waku-org/js-waku.git
Replace deprecated `multihashes` with `multiformats`
This commit is contained in:
parent
e8ba7f6440
commit
1d8e3837ea
|
@ -28,7 +28,7 @@
|
|||
"libp2p-websockets": "^0.16.1",
|
||||
"long": "^4.0.0",
|
||||
"multiaddr": "^10.0.1",
|
||||
"multihashes": "^4.0.3",
|
||||
"multiformats": "^9.6.5",
|
||||
"peer-id": "^0.16.0",
|
||||
"protobufjs": "^6.8.8",
|
||||
"uint8arrays": "^3.0.0",
|
||||
|
@ -1091,11 +1091,6 @@
|
|||
"resolved": "https://registry.npmjs.org/@leichtgewicht/ip-codec/-/ip-codec-2.0.3.tgz",
|
||||
"integrity": "sha512-nkalE/f1RvRGChwBnEIoBfSEYOXnCRdleKuv6+lePbMDrMZXeDQnqak5XDOeBgrPPyPfAdcCu/B5z+v3VhplGg=="
|
||||
},
|
||||
"node_modules/@multiformats/base-x": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@multiformats/base-x/-/base-x-4.0.1.tgz",
|
||||
"integrity": "sha512-eMk0b9ReBbV23xXU693TAIrLyeO5iTgBZGSJfpqriG8UkYvr/hC9u9pyMlAakDNHWmbhMZCDs6KQO0jzKD8OTw=="
|
||||
},
|
||||
"node_modules/@noble/ed25519": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/@noble/ed25519/-/ed25519-1.5.1.tgz",
|
||||
|
@ -8570,41 +8565,10 @@
|
|||
"multiaddr": "^10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/multibase": {
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/multibase/-/multibase-4.0.4.tgz",
|
||||
"integrity": "sha512-8/JmrdSGzlw6KTgAJCOqUBSGd1V6186i/X8dDCGy/lbCKrQ+1QB6f3HE+wPr7Tpdj4U3gutaj9jG2rNX6UpiJg==",
|
||||
"dependencies": {
|
||||
"@multiformats/base-x": "^4.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.0.0",
|
||||
"npm": ">=6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/multiformats": {
|
||||
"version": "9.6.4",
|
||||
"resolved": "https://registry.npmjs.org/multiformats/-/multiformats-9.6.4.tgz",
|
||||
"integrity": "sha512-fCCB6XMrr6CqJiHNjfFNGT0v//dxOBMrOMqUIzpPc/mmITweLEyhvMpY9bF+jZ9z3vaMAau5E8B68DW77QMXkg=="
|
||||
},
|
||||
"node_modules/multihashes": {
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/multihashes/-/multihashes-4.0.3.tgz",
|
||||
"integrity": "sha512-0AhMH7Iu95XjDLxIeuCOOE4t9+vQZsACyKZ9Fxw2pcsRmlX4iCn1mby0hS0bb+nQOVpdQYWPpnyusw4da5RPhA==",
|
||||
"dependencies": {
|
||||
"multibase": "^4.0.1",
|
||||
"uint8arrays": "^3.0.0",
|
||||
"varint": "^5.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.0.0",
|
||||
"npm": ">=6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/multihashes/node_modules/varint": {
|
||||
"version": "5.0.2",
|
||||
"resolved": "https://registry.npmjs.org/varint/-/varint-5.0.2.tgz",
|
||||
"integrity": "sha512-lKxKYG6H03yCZUpAGOPOsMcGxd1RHCu1iKvEHYDPmTyq2HueGhD73ssNBqqQWfvYs04G9iUFRvmAVLW20Jw6ow=="
|
||||
"version": "9.6.5",
|
||||
"resolved": "https://registry.npmjs.org/multiformats/-/multiformats-9.6.5.tgz",
|
||||
"integrity": "sha512-vMwf/FUO+qAPvl3vlSZEgEVFY/AxeZq5yg761ScF3CZsXgmTi/HGkicUiNN0CI4PW8FiY2P0OLklOcmQjdQJhw=="
|
||||
},
|
||||
"node_modules/multistream-select": {
|
||||
"version": "3.0.2",
|
||||
|
@ -13593,11 +13557,6 @@
|
|||
"resolved": "https://registry.npmjs.org/@leichtgewicht/ip-codec/-/ip-codec-2.0.3.tgz",
|
||||
"integrity": "sha512-nkalE/f1RvRGChwBnEIoBfSEYOXnCRdleKuv6+lePbMDrMZXeDQnqak5XDOeBgrPPyPfAdcCu/B5z+v3VhplGg=="
|
||||
},
|
||||
"@multiformats/base-x": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@multiformats/base-x/-/base-x-4.0.1.tgz",
|
||||
"integrity": "sha512-eMk0b9ReBbV23xXU693TAIrLyeO5iTgBZGSJfpqriG8UkYvr/hC9u9pyMlAakDNHWmbhMZCDs6KQO0jzKD8OTw=="
|
||||
},
|
||||
"@noble/ed25519": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/@noble/ed25519/-/ed25519-1.5.1.tgz",
|
||||
|
@ -19422,35 +19381,10 @@
|
|||
"multiaddr": "^10.0.0"
|
||||
}
|
||||
},
|
||||
"multibase": {
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/multibase/-/multibase-4.0.4.tgz",
|
||||
"integrity": "sha512-8/JmrdSGzlw6KTgAJCOqUBSGd1V6186i/X8dDCGy/lbCKrQ+1QB6f3HE+wPr7Tpdj4U3gutaj9jG2rNX6UpiJg==",
|
||||
"requires": {
|
||||
"@multiformats/base-x": "^4.0.1"
|
||||
}
|
||||
},
|
||||
"multiformats": {
|
||||
"version": "9.6.4",
|
||||
"resolved": "https://registry.npmjs.org/multiformats/-/multiformats-9.6.4.tgz",
|
||||
"integrity": "sha512-fCCB6XMrr6CqJiHNjfFNGT0v//dxOBMrOMqUIzpPc/mmITweLEyhvMpY9bF+jZ9z3vaMAau5E8B68DW77QMXkg=="
|
||||
},
|
||||
"multihashes": {
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/multihashes/-/multihashes-4.0.3.tgz",
|
||||
"integrity": "sha512-0AhMH7Iu95XjDLxIeuCOOE4t9+vQZsACyKZ9Fxw2pcsRmlX4iCn1mby0hS0bb+nQOVpdQYWPpnyusw4da5RPhA==",
|
||||
"requires": {
|
||||
"multibase": "^4.0.1",
|
||||
"uint8arrays": "^3.0.0",
|
||||
"varint": "^5.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"varint": {
|
||||
"version": "5.0.2",
|
||||
"resolved": "https://registry.npmjs.org/varint/-/varint-5.0.2.tgz",
|
||||
"integrity": "sha512-lKxKYG6H03yCZUpAGOPOsMcGxd1RHCu1iKvEHYDPmTyq2HueGhD73ssNBqqQWfvYs04G9iUFRvmAVLW20Jw6ow=="
|
||||
}
|
||||
}
|
||||
"version": "9.6.5",
|
||||
"resolved": "https://registry.npmjs.org/multiformats/-/multiformats-9.6.5.tgz",
|
||||
"integrity": "sha512-vMwf/FUO+qAPvl3vlSZEgEVFY/AxeZq5yg761ScF3CZsXgmTi/HGkicUiNN0CI4PW8FiY2P0OLklOcmQjdQJhw=="
|
||||
},
|
||||
"multistream-select": {
|
||||
"version": "3.0.2",
|
||||
|
|
|
@ -87,7 +87,7 @@
|
|||
"libp2p-websockets": "^0.16.1",
|
||||
"long": "^4.0.0",
|
||||
"multiaddr": "^10.0.1",
|
||||
"multihashes": "^4.0.3",
|
||||
"multiformats": "^9.6.5",
|
||||
"peer-id": "^0.16.0",
|
||||
"protobufjs": "^6.8.8",
|
||||
"uint8arrays": "^3.0.0",
|
||||
|
|
|
@ -41,16 +41,25 @@ export class ENR extends Map<ENRKey, ENRValue> {
|
|||
super(Object.entries(kvs));
|
||||
this.seq = seq;
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
static async create(
|
||||
kvs: Record<ENRKey, ENRValue> = {},
|
||||
seq: SequenceNumber = BigInt(1),
|
||||
signature: Uint8Array | null = null
|
||||
): Promise<ENR> {
|
||||
const enr = new ENR(kvs, seq, signature);
|
||||
try {
|
||||
const publicKey = this.publicKey;
|
||||
const publicKey = enr.publicKey;
|
||||
if (publicKey) {
|
||||
const keypair = createKeypair(this.keypairType, undefined, publicKey);
|
||||
this.peerId = createPeerIdFromKeypair(keypair);
|
||||
const keypair = createKeypair(enr.keypairType, undefined, publicKey);
|
||||
enr.peerId = await createPeerIdFromKeypair(keypair);
|
||||
}
|
||||
} catch (e) {
|
||||
dbg("Could not calculate peer id for ENR", e);
|
||||
}
|
||||
|
||||
return enr;
|
||||
}
|
||||
|
||||
static createV4(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { keys } from "libp2p-crypto";
|
||||
import mh from "multihashes";
|
||||
import { identity } from "multiformats/hashes/identity";
|
||||
import PeerId from "peer-id";
|
||||
|
||||
const { keysPBM, supportedKeys } = keys;
|
||||
|
@ -33,7 +33,9 @@ export function createKeypair(
|
|||
}
|
||||
}
|
||||
|
||||
export function createPeerIdFromKeypair(keypair: IKeypair): PeerId {
|
||||
export async function createPeerIdFromKeypair(
|
||||
keypair: IKeypair
|
||||
): Promise<PeerId> {
|
||||
switch (keypair.type) {
|
||||
case KeypairType.secp256k1: {
|
||||
// manually create a peer id to avoid expensive ops
|
||||
|
@ -47,8 +49,8 @@ export function createPeerIdFromKeypair(keypair: IKeypair): PeerId {
|
|||
const pubKey = new supportedKeys.secp256k1.Secp256k1PublicKey(
|
||||
keypair.publicKey
|
||||
);
|
||||
const id = mh.encode(pubKey.bytes, "identity");
|
||||
return new PeerId(id, privKey, pubKey);
|
||||
const id = await identity.digest(pubKey.bytes);
|
||||
return new PeerId(id.bytes, privKey, pubKey);
|
||||
}
|
||||
default:
|
||||
throw new Error(ERR_TYPE_NOT_IMPLEMENTED);
|
||||
|
|
Loading…
Reference in New Issue