chore: get dns-discovery to compile (almost)

This commit is contained in:
fryorcraken.eth 2022-11-03 14:11:42 +11:00
parent 9cc32c1032
commit 25dfe9d969
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
19 changed files with 255 additions and 46 deletions

124
package-lock.json generated
View File

@ -22438,8 +22438,6 @@
"@noble/secp256k1": "^1.3.4", "@noble/secp256k1": "^1.3.4",
"@waku/interfaces": "*", "@waku/interfaces": "*",
"debug": "^4.3.4", "debug": "^4.3.4",
"dns-query": "^0.11.2",
"hi-base32": "^0.5.1",
"it-all": "^1.0.6", "it-all": "^1.0.6",
"it-length-prefixed": "^8.0.2", "it-length-prefixed": "^8.0.2",
"it-pipe": "^2.0.4", "it-pipe": "^2.0.4",
@ -22452,7 +22450,6 @@
"uuid": "^8.3.2" "uuid": "^8.3.2"
}, },
"devDependencies": { "devDependencies": {
"@libp2p/peer-id-factory": "^1.0.15",
"@rollup/plugin-commonjs": "^22.0.0", "@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-json": "^4.1.0", "@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.3.0", "@rollup/plugin-node-resolve": "^13.3.0",
@ -22590,7 +22587,21 @@
"name": "@waku/dns-discovery", "name": "@waku/dns-discovery",
"version": "0.0.1", "version": "0.0.1",
"license": "MIT OR Apache-2.0", "license": "MIT OR Apache-2.0",
"dependencies": {
"@libp2p/interface-peer-discovery": "^1.0.0",
"@libp2p/interface-peer-info": "^1.0.1",
"@libp2p/interfaces": "^3.0.2",
"@libp2p/peer-id": "^1.1.10",
"@waku/byte-utils": "*",
"@waku/enr": "*",
"debug": "^4.3.4",
"dns-query": "^0.11.2",
"hi-base32": "^0.5.1",
"uint8arrays": "^3.0.0"
},
"devDependencies": { "devDependencies": {
"@libp2p/peer-id-factory": "^1.0.15",
"@multiformats/multiaddr": "^11.0.6",
"@rollup/plugin-commonjs": "^22.0.0", "@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-json": "^4.1.0", "@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.3.0", "@rollup/plugin-node-resolve": "^13.3.0",
@ -22602,6 +22613,7 @@
"@semantic-release/release-notes-generator": "^10.0.3", "@semantic-release/release-notes-generator": "^10.0.3",
"@typescript-eslint/eslint-plugin": "^5.8.1", "@typescript-eslint/eslint-plugin": "^5.8.1",
"@typescript-eslint/parser": "^5.8.1", "@typescript-eslint/parser": "^5.8.1",
"chai": "^4.3.4",
"cspell": "^5.14.0", "cspell": "^5.14.0",
"eslint": "^8.6.0", "eslint": "^8.6.0",
"eslint-config-prettier": "^8.3.0", "eslint-config-prettier": "^8.3.0",
@ -22620,6 +22632,53 @@
"node": ">=16" "node": ">=16"
} }
}, },
"packages/dns-discovery/node_modules/@chainsafe/is-ip": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@chainsafe/is-ip/-/is-ip-2.0.1.tgz",
"integrity": "sha512-nqSJ8u2a1Rv9FYbyI8qpDhTYujaKEyLknNrTejLYoSWmdeg+2WB7R6BZqPZYfrJzDxVi3rl6ZQuoaEvpKRZWgQ==",
"dev": true
},
"packages/dns-discovery/node_modules/@multiformats/multiaddr": {
"version": "11.0.7",
"resolved": "https://registry.npmjs.org/@multiformats/multiaddr/-/multiaddr-11.0.7.tgz",
"integrity": "sha512-rCqYS3Qz/dm4H/1Lvda11OBZf1tH8rst69GWK9jDy8AY+3n+NBBdErA/SRtdcRx6hPtQ8lAB5UhHlzIVbViv1Q==",
"dev": true,
"dependencies": {
"@chainsafe/is-ip": "^2.0.1",
"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/dns-discovery/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==",
"dev": true,
"dependencies": {
"multiformats": "^10.0.0"
},
"engines": {
"node": ">=16.0.0",
"npm": ">=7.0.0"
}
},
"packages/dns-discovery/node_modules/multiformats": {
"version": "10.0.2",
"resolved": "https://registry.npmjs.org/multiformats/-/multiformats-10.0.2.tgz",
"integrity": "sha512-nJEHLFOYhO4L+aNApHhCnWqa31FyqAHv9Q77AhmwU3KsM2f1j7tuJpCk5ByZ33smzycNCpSG5klNIejIyfFx2A==",
"dev": true,
"engines": {
"node": ">=16.0.0",
"npm": ">=7.0.0"
}
},
"packages/enr": { "packages/enr": {
"name": "@waku/enr", "name": "@waku/enr",
"version": "0.0.1", "version": "0.0.1",
@ -22631,6 +22690,7 @@
"@waku/byte-utils": "*" "@waku/byte-utils": "*"
}, },
"devDependencies": { "devDependencies": {
"@libp2p/peer-id-factory": "^1.0.15",
"@rollup/plugin-commonjs": "^22.0.0", "@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-json": "^4.1.0", "@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.3.0", "@rollup/plugin-node-resolve": "^13.3.0",
@ -27080,7 +27140,6 @@
"@libp2p/interfaces": "^3.0.2", "@libp2p/interfaces": "^3.0.2",
"@libp2p/mplex": "^5.1.1", "@libp2p/mplex": "^5.1.1",
"@libp2p/peer-id": "^1.1.10", "@libp2p/peer-id": "^1.1.10",
"@libp2p/peer-id-factory": "^1.0.15",
"@libp2p/websockets": "^3.0.3", "@libp2p/websockets": "^3.0.3",
"@multiformats/multiaddr": "^11.0.6", "@multiformats/multiaddr": "^11.0.6",
"@noble/secp256k1": "^1.3.4", "@noble/secp256k1": "^1.3.4",
@ -27107,7 +27166,6 @@
"chai": "^4.3.4", "chai": "^4.3.4",
"cspell": "^5.14.0", "cspell": "^5.14.0",
"debug": "^4.3.4", "debug": "^4.3.4",
"dns-query": "^0.11.2",
"eslint": "^8.6.0", "eslint": "^8.6.0",
"eslint-config-prettier": "^8.3.0", "eslint-config-prettier": "^8.3.0",
"eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-eslint-comments": "^3.2.0",
@ -27116,7 +27174,6 @@
"eslint-plugin-prettier": "^4.0.0", "eslint-plugin-prettier": "^4.0.0",
"fast-check": "^2.14.0", "fast-check": "^2.14.0",
"gh-pages": "^3.2.3", "gh-pages": "^3.2.3",
"hi-base32": "^0.5.1",
"ignore-loader": "^0.1.2", "ignore-loader": "^0.1.2",
"isomorphic-fetch": "^3.0.0", "isomorphic-fetch": "^3.0.0",
"it-all": "^1.0.6", "it-all": "^1.0.6",
@ -27216,6 +27273,12 @@
"@waku/dns-discovery": { "@waku/dns-discovery": {
"version": "file:packages/dns-discovery", "version": "file:packages/dns-discovery",
"requires": { "requires": {
"@libp2p/interface-peer-discovery": "^1.0.0",
"@libp2p/interface-peer-info": "^1.0.1",
"@libp2p/interfaces": "^3.0.2",
"@libp2p/peer-id": "^1.1.10",
"@libp2p/peer-id-factory": "^1.0.15",
"@multiformats/multiaddr": "^11.0.6",
"@rollup/plugin-commonjs": "^22.0.0", "@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-json": "^4.1.0", "@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.3.0", "@rollup/plugin-node-resolve": "^13.3.0",
@ -27227,25 +27290,72 @@
"@semantic-release/release-notes-generator": "^10.0.3", "@semantic-release/release-notes-generator": "^10.0.3",
"@typescript-eslint/eslint-plugin": "^5.8.1", "@typescript-eslint/eslint-plugin": "^5.8.1",
"@typescript-eslint/parser": "^5.8.1", "@typescript-eslint/parser": "^5.8.1",
"@waku/byte-utils": "*",
"@waku/enr": "*",
"chai": "^4.3.4",
"cspell": "^5.14.0", "cspell": "^5.14.0",
"debug": "^4.3.4",
"dns-query": "^0.11.2",
"eslint": "^8.6.0", "eslint": "^8.6.0",
"eslint-config-prettier": "^8.3.0", "eslint-config-prettier": "^8.3.0",
"eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-functional": "^4.0.2", "eslint-plugin-functional": "^4.0.2",
"eslint-plugin-import": "^2.25.3", "eslint-plugin-import": "^2.25.3",
"eslint-plugin-prettier": "^4.0.0", "eslint-plugin-prettier": "^4.0.0",
"hi-base32": "^0.5.1",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"prettier": "^2.1.1", "prettier": "^2.1.1",
"rollup": "^2.75.0", "rollup": "^2.75.0",
"semantic-release": "^19.0.5", "semantic-release": "^19.0.5",
"semantic-release-monorepo": "^7.0.5", "semantic-release-monorepo": "^7.0.5",
"typescript": "^4.6.3" "typescript": "^4.6.3",
"uint8arrays": "^3.0.0"
},
"dependencies": {
"@chainsafe/is-ip": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@chainsafe/is-ip/-/is-ip-2.0.1.tgz",
"integrity": "sha512-nqSJ8u2a1Rv9FYbyI8qpDhTYujaKEyLknNrTejLYoSWmdeg+2WB7R6BZqPZYfrJzDxVi3rl6ZQuoaEvpKRZWgQ==",
"dev": true
},
"@multiformats/multiaddr": {
"version": "11.0.7",
"resolved": "https://registry.npmjs.org/@multiformats/multiaddr/-/multiaddr-11.0.7.tgz",
"integrity": "sha512-rCqYS3Qz/dm4H/1Lvda11OBZf1tH8rst69GWK9jDy8AY+3n+NBBdErA/SRtdcRx6hPtQ8lAB5UhHlzIVbViv1Q==",
"dev": true,
"requires": {
"@chainsafe/is-ip": "^2.0.1",
"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==",
"dev": true,
"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==",
"dev": true
}
} }
}, },
"@waku/enr": { "@waku/enr": {
"version": "file:packages/enr", "version": "file:packages/enr",
"requires": { "requires": {
"@libp2p/crypto": "^1.0.4", "@libp2p/crypto": "^1.0.4",
"@libp2p/peer-id-factory": "^1.0.15",
"@multiformats/multiaddr": "^11.0.6", "@multiformats/multiaddr": "^11.0.6",
"@noble/secp256k1": "^1.7.0", "@noble/secp256k1": "^1.7.0",
"@rollup/plugin-commonjs": "^22.0.0", "@rollup/plugin-commonjs": "^22.0.0",

View File

@ -9,14 +9,6 @@
"types": "./dist/index.d.ts", "types": "./dist/index.d.ts",
"import": "./dist/index.js" "import": "./dist/index.js"
}, },
"./lib/enr": {
"types": "./dist/lib/enr/index.d.ts",
"import": "./dist/lib/enr/index.js"
},
"./lib/peer_discovery_dns": {
"types": "./dist/lib/peer_discovery_dns/index.d.ts",
"import": "./dist/lib/peer_discovery_dns/index.js"
},
"./lib/peer_discovery_static_list": { "./lib/peer_discovery_static_list": {
"types": "./dist/lib/peer_discovery_static_list.d.ts", "types": "./dist/lib/peer_discovery_static_list.d.ts",
"import": "./dist/lib/peer_discovery_static_list.js" "import": "./dist/lib/peer_discovery_static_list.js"
@ -124,8 +116,6 @@
"@noble/secp256k1": "^1.3.4", "@noble/secp256k1": "^1.3.4",
"@waku/interfaces": "*", "@waku/interfaces": "*",
"debug": "^4.3.4", "debug": "^4.3.4",
"dns-query": "^0.11.2",
"hi-base32": "^0.5.1",
"it-all": "^1.0.6", "it-all": "^1.0.6",
"it-length-prefixed": "^8.0.2", "it-length-prefixed": "^8.0.2",
"it-pipe": "^2.0.4", "it-pipe": "^2.0.4",
@ -138,7 +128,6 @@
"uuid": "^8.3.2" "uuid": "^8.3.2"
}, },
"devDependencies": { "devDependencies": {
"@libp2p/peer-id-factory": "^1.0.15",
"@rollup/plugin-commonjs": "^22.0.0", "@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-json": "^4.1.0", "@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.3.0", "@rollup/plugin-node-resolve": "^13.3.0",

View File

@ -5,8 +5,6 @@ import json from "@rollup/plugin-json";
export default { export default {
input: { input: {
index: "dist/index.js", index: "dist/index.js",
"lib/enr": "dist/lib/enr/index.js",
"lib/peer_discovery_dns": "dist/lib/peer_discovery_dns/index.js",
"lib/peer_discovery_static_list": "dist/lib/peer_discovery_static_list.js", "lib/peer_discovery_static_list": "dist/lib/peer_discovery_static_list.js",
"lib/predefined_bootstrap_nodes": "dist/lib/predefined_bootstrap_nodes.js", "lib/predefined_bootstrap_nodes": "dist/lib/predefined_bootstrap_nodes.js",
"lib/utils": "dist/lib/utils.js", "lib/utils": "dist/lib/utils.js",

View File

@ -0,0 +1,45 @@
process.env.CHROME_BIN = require("puppeteer").executablePath();
const webpack = require("webpack");
module.exports = function (config) {
config.set({
frameworks: ["webpack", "mocha"],
files: ["src/**/*.ts"],
preprocessors: {
"src/**/*.ts": ["webpack"],
},
envPreprocessor: ["CI"],
reporters: ["progress"],
browsers: ["ChromeHeadless"],
singleRun: true,
client: {
mocha: {
timeout: 6000, // Default is 2s
},
},
webpack: {
mode: "development",
module: {
rules: [{ test: /\.([cm]?ts|tsx)$/, loader: "ts-loader" }],
},
plugins: [
new webpack.DefinePlugin({
"process.env.CI": process.env.CI || false,
}),
new webpack.ProvidePlugin({
process: "process/browser.js",
}),
],
resolve: {
extensions: [".ts", ".tsx", ".js"],
extensionAlias: {
".js": [".js", ".ts"],
".cjs": [".cjs", ".cts"],
".mjs": [".mjs", ".mts"],
},
},
stats: { warnings: false },
devtool: "inline-source-map",
},
});
};

View File

@ -50,8 +50,22 @@
"engines": { "engines": {
"node": ">=16" "node": ">=16"
}, },
"dependencies": {}, "dependencies": {
"@waku/enr": "*",
"@waku/byte-utils": "*",
"hi-base32": "^0.5.1",
"debug": "^4.3.4",
"dns-query": "^0.11.2",
"uint8arrays": "^3.0.0",
"@libp2p/interface-peer-discovery": "^1.0.0",
"@libp2p/interface-peer-info": "^1.0.1",
"@libp2p/interfaces": "^3.0.2",
"@libp2p/peer-id": "^1.1.10"
},
"devDependencies": { "devDependencies": {
"@multiformats/multiaddr": "^11.0.6",
"@libp2p/peer-id-factory": "^1.0.15",
"chai": "^4.3.4",
"@rollup/plugin-commonjs": "^22.0.0", "@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-json": "^4.1.0", "@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.3.0", "@rollup/plugin-node-resolve": "^13.3.0",

View File

@ -1,6 +1,6 @@
import { expect } from "chai"; import { expect } from "chai";
import { DnsClient, DnsNodeDiscovery } from "./dns"; import { DnsClient, DnsNodeDiscovery } from "./dns.js";
import testData from "./testdata.json" assert { type: "json" }; import testData from "./testdata.json" assert { type: "json" };
const mockData = testData.dns; const mockData = testData.dns;

View File

@ -1,13 +1,12 @@
import { ENR } from "@waku/enr";
import debug from "debug"; import debug from "debug";
import { ENR } from "../enr"; import { DnsOverHttps } from "./dns_over_https.js";
import { ENRTree } from "./enrtree.js";
import { DnsOverHttps } from "./dns_over_https";
import { ENRTree } from "./enrtree";
import { import {
fetchNodesUntilCapabilitiesFulfilled, fetchNodesUntilCapabilitiesFulfilled,
yieldNodesUntilCapabilitiesFulfilled, yieldNodesUntilCapabilitiesFulfilled,
} from "./fetch_nodes"; } from "./fetch_nodes.js";
const log = debug("waku:discovery:dns"); const log = debug("waku:discovery:dns");

View File

@ -1,9 +1,8 @@
import { bytesToUtf8 } from "@waku/byte-utils";
import debug from "debug"; import debug from "debug";
import { Endpoint, query, toEndpoint } from "dns-query"; import { Endpoint, query, toEndpoint } from "dns-query";
import { bytesToUtf8 } from "../utils"; import { DnsClient } from "./dns.js";
import { DnsClient } from "./dns";
const log = debug("waku:dns-over-https"); const log = debug("waku:dns-over-https");

View File

@ -1,6 +1,6 @@
import { expect } from "chai"; import { expect } from "chai";
import { ENRTree } from "./enrtree"; import { ENRTree } from "./enrtree.js";
import testData from "./testdata.json" assert { type: "json" }; import testData from "./testdata.json" assert { type: "json" };
const dns = testData.dns; const dns = testData.dns;

View File

@ -1,10 +1,9 @@
import { utf8ToBytes } from "@waku/byte-utils";
import { ENR } from "@waku/enr";
import { keccak256, verifySignature } from "@waku/enr/crypto";
import base32 from "hi-base32"; import base32 from "hi-base32";
import { fromString } from "uint8arrays/from-string"; import { fromString } from "uint8arrays/from-string";
import { keccak256, verifySignature } from "../crypto";
import { ENR } from "../enr";
import { utf8ToBytes } from "../utils";
export type ENRRootValues = { export type ENRRootValues = {
eRoot: string; eRoot: string;
lRoot: string; lRoot: string;

View File

@ -1,10 +1,9 @@
import { createSecp256k1PeerId } from "@libp2p/peer-id-factory"; import { createSecp256k1PeerId } from "@libp2p/peer-id-factory";
import { multiaddr } from "@multiformats/multiaddr"; import { multiaddr } from "@multiformats/multiaddr";
import { ENR, Waku2 } from "@waku/enr";
import { expect } from "chai"; import { expect } from "chai";
import { ENR, Waku2 } from "../enr"; import { fetchNodesUntilCapabilitiesFulfilled } from "./fetch_nodes.js";
import { fetchNodesUntilCapabilitiesFulfilled } from "./fetch_nodes";
async function createEnr(waku2: Waku2): Promise<ENR> { async function createEnr(waku2: Waku2): Promise<ENR> {
const peerId = await createSecp256k1PeerId(); const peerId = await createSecp256k1PeerId();

View File

@ -1,8 +1,7 @@
import { ENR, Waku2 } from "@waku/enr";
import debug from "debug"; import debug from "debug";
import { ENR, Waku2 } from "../enr"; import { NodeCapabilityCount } from "./dns.js";
import { NodeCapabilityCount } from "./dns";
const log = debug("waku:discovery:fetch_nodes"); const log = debug("waku:discovery:fetch_nodes");

View File

@ -1,6 +1,6 @@
import { expect } from "chai"; import { expect } from "chai";
import { getPseudoRandomSubset } from "../random_subset"; import { getPseudoRandomSubset } from "./random_subset.js";
describe("Discovery", () => { describe("Discovery", () => {
it("returns all values when wanted number matches available values", function () { it("returns all values when wanted number matches available values", function () {

View File

@ -5,12 +5,11 @@ 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 { ENR } from "@waku/enr";
import debug from "debug"; import debug from "debug";
import { ENR } from "../enr"; import { DnsNodeDiscovery, NodeCapabilityCount } from "./dns.js";
import { multiaddrsToPeerInfo } from "../multiaddr_to_peer_info"; import { multiaddrsToPeerInfo } from "./multiaddr_to_peer_info.js";
import { DnsNodeDiscovery, NodeCapabilityCount } from "./dns";
const log = debug("waku:peer-discovery-dns"); const log = debug("waku:peer-discovery-dns");

View File

@ -0,0 +1,17 @@
import { PeerInfo } from "@libp2p/interface-peer-info";
import { peerIdFromString } from "@libp2p/peer-id";
import { Multiaddr } from "@multiformats/multiaddr";
export function multiaddrsToPeerInfo(mas: Multiaddr[]): PeerInfo[] {
return mas
.map((ma) => {
const peerIdStr = ma.getPeerId();
const protocols: string[] = [];
return {
id: peerIdStr ? peerIdFromString(peerIdStr) : null,
multiaddrs: [ma.decapsulateCode(421)],
protocols,
};
})
.filter((peerInfo): peerInfo is PeerInfo => peerInfo.id !== null);
}

View File

@ -0,0 +1,30 @@
/**
* Return pseudo random subset of the input.
*/
export function getPseudoRandomSubset<T>(
values: T[],
wantedNumber: number
): T[] {
if (values.length <= wantedNumber || values.length <= 1) {
return values;
}
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;
}

View File

@ -0,0 +1,6 @@
{
"extends": "./tsconfig.dev",
"compilerOptions": {
"noEmit": false
}
}

View File

@ -8,6 +8,10 @@
".": { ".": {
"types": "./dist/index.d.ts", "types": "./dist/index.d.ts",
"import": "./dist/index.js" "import": "./dist/index.js"
},
"./crypto": {
"types": "./dist/crypto.d.ts",
"import": "./dist/crypto.js"
} }
}, },
"type": "module", "type": "module",
@ -60,6 +64,7 @@
"@waku/byte-utils": "*" "@waku/byte-utils": "*"
}, },
"devDependencies": { "devDependencies": {
"@libp2p/peer-id-factory": "^1.0.15",
"@rollup/plugin-commonjs": "^22.0.0", "@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-json": "^4.1.0", "@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.3.0", "@rollup/plugin-node-resolve": "^13.3.0",

View File

@ -5,6 +5,7 @@ import { nodeResolve } from "@rollup/plugin-node-resolve";
export default { export default {
input: { input: {
index: "dist/index.js", index: "dist/index.js",
crypto: "dist/crypto.js",
}, },
output: { output: {
dir: "bundle", dir: "bundle",