mirror of
https://github.com/waku-org/js-waku.git
synced 2025-01-13 14:05:24 +00:00
fix: Imports paths
Import paths were not valid.
This commit is contained in:
parent
157e42e148
commit
ab9919ba6d
@ -5,7 +5,7 @@ import type {
|
|||||||
import { symbol } from "@libp2p/interface-peer-discovery";
|
import { symbol } from "@libp2p/interface-peer-discovery";
|
||||||
import type { PeerInfo } from "@libp2p/interface-peer-info";
|
import type { PeerInfo } from "@libp2p/interface-peer-info";
|
||||||
import { CustomEvent, EventEmitter } from "@libp2p/interfaces/events";
|
import { CustomEvent, EventEmitter } from "@libp2p/interfaces/events";
|
||||||
import { peerIdFromString } from "@libp2p/peer-id/src";
|
import { peerIdFromString } from "@libp2p/peer-id";
|
||||||
import { Multiaddr } from "@multiformats/multiaddr";
|
import { Multiaddr } from "@multiformats/multiaddr";
|
||||||
import debug from "debug";
|
import debug from "debug";
|
||||||
|
|
||||||
|
@ -1,12 +1,30 @@
|
|||||||
import { shuffle } from "@chainsafe/libp2p-gossipsub/utils/shuffle";
|
/**
|
||||||
|
* Return pseudo random subset of the input.
|
||||||
|
*/
|
||||||
export function getPseudoRandomSubset<T>(
|
export function getPseudoRandomSubset<T>(
|
||||||
values: T[],
|
values: T[],
|
||||||
wantedNumber: number
|
wantedNumber: number
|
||||||
): T[] {
|
): T[] {
|
||||||
if (values.length <= wantedNumber) {
|
if (values.length <= wantedNumber || values.length <= 1) {
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
return shuffle(values).slice(0, wantedNumber);
|
return shuffle(values).slice(0, wantedNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function shuffle<T>(arr: T[]): T[] {
|
||||||
|
if (arr.length <= 1) {
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
const randInt = (): number => {
|
||||||
|
return Math.floor(Math.random() * Math.floor(arr.length));
|
||||||
|
};
|
||||||
|
|
||||||
|
for (let i = 0; i < arr.length; i++) {
|
||||||
|
const j = randInt();
|
||||||
|
const tmp = arr[i];
|
||||||
|
arr[i] = arr[j];
|
||||||
|
arr[j] = tmp;
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Secp256k1PublicKey } from "@libp2p/crypto/dist/src/keys/secp256k1-class";
|
import { supportedKeys } from "@libp2p/crypto/keys";
|
||||||
import { peerIdFromKeys } from "@libp2p/peer-id";
|
import { peerIdFromKeys } from "@libp2p/peer-id";
|
||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
@ -25,7 +25,9 @@ describe("createPeerIdFromKeypair", function () {
|
|||||||
it("should properly create a PeerId from a secp256k1 keypair without private key", async function () {
|
it("should properly create a PeerId from a secp256k1 keypair without private key", async function () {
|
||||||
const keypair = await generateKeypair(KeypairType.secp256k1);
|
const keypair = await generateKeypair(KeypairType.secp256k1);
|
||||||
delete (keypair as Secp256k1Keypair)._privateKey;
|
delete (keypair as Secp256k1Keypair)._privateKey;
|
||||||
const pubKey = new Secp256k1PublicKey(keypair.publicKey);
|
const pubKey = new supportedKeys.secp256k1.Secp256k1PublicKey(
|
||||||
|
keypair.publicKey
|
||||||
|
);
|
||||||
|
|
||||||
const expectedPeerId = await peerIdFromKeys(pubKey.bytes);
|
const expectedPeerId = await peerIdFromKeys(pubKey.bytes);
|
||||||
const actualPeerId = await createPeerIdFromKeypair(keypair);
|
const actualPeerId = await createPeerIdFromKeypair(keypair);
|
||||||
|
@ -3,7 +3,7 @@ import type { PeerId } from "@libp2p/interface-peer-id";
|
|||||||
import { Mplex } from "@libp2p/mplex";
|
import { Mplex } from "@libp2p/mplex";
|
||||||
import { peerIdFromString } from "@libp2p/peer-id";
|
import { peerIdFromString } from "@libp2p/peer-id";
|
||||||
import { WebSockets } from "@libp2p/websockets";
|
import { WebSockets } from "@libp2p/websockets";
|
||||||
import filters from "@libp2p/websockets/filters";
|
import { all as filterAll } from "@libp2p/websockets/filters";
|
||||||
import { Multiaddr, multiaddr } from "@multiformats/multiaddr";
|
import { Multiaddr, multiaddr } from "@multiformats/multiaddr";
|
||||||
import debug from "debug";
|
import debug from "debug";
|
||||||
import { createLibp2p, Libp2p, Libp2pOptions } from "libp2p";
|
import { createLibp2p, Libp2p, Libp2pOptions } from "libp2p";
|
||||||
@ -91,7 +91,7 @@ export async function createWaku(options?: CreateOptions): Promise<Waku> {
|
|||||||
|
|
||||||
// TODO: Use options
|
// TODO: Use options
|
||||||
const libp2pOpts = {
|
const libp2pOpts = {
|
||||||
transports: new WebSockets({ filter: filters.all }),
|
transports: new WebSockets({ filter: filterAll }),
|
||||||
streamMuxers: [new Mplex()],
|
streamMuxers: [new Mplex()],
|
||||||
pubsub: new WakuRelay(),
|
pubsub: new WakuRelay(),
|
||||||
connectionEncryption: [new Noise()],
|
connectionEncryption: [new Noise()],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user