mirror of https://github.com/waku-org/waku-lab.git
feat: make peerId persistent, fix thrown errors (#93)
This commit is contained in:
parent
31738ba842
commit
eb13f3ebea
|
@ -8,9 +8,13 @@
|
|||
"name": "waku-dogfooding",
|
||||
"version": "0.0.1",
|
||||
"dependencies": {
|
||||
"@libp2p/peer-id": "^4.1.2",
|
||||
"@libp2p/crypto": "^4.0.1",
|
||||
"@libp2p/peer-id-factory": "^4.2.4",
|
||||
"@multiformats/multiaddr": "^12.3.1",
|
||||
"@waku/sdk": "0.0.28",
|
||||
"protobufjs": "^7.3.0"
|
||||
"libp2p": "^1.8.3",
|
||||
"protobufjs": "^7.3.0",
|
||||
"uint8arrays": "^5.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@libp2p/interface": "^1.7.0",
|
||||
|
@ -1005,9 +1009,9 @@
|
|||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "20.16.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.16.9.tgz",
|
||||
"integrity": "sha512-rkvIVJxsOfBejxK7I0FO5sa2WxFmJCzoDwcd88+fq/CUfynNywTo/1/T6hyFz22CyztsnLS9nVlHOnTI36RH5w==",
|
||||
"version": "20.16.10",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.16.10.tgz",
|
||||
"integrity": "sha512-vQUKgWTjEIRFCvK6CyriPH3MZYiYlNy0fKiEYHWbcoWLEgs4opurGGKlebrTLqdSMIbXImH6XExNiIyNUv3WpA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~6.19.2"
|
||||
|
@ -3403,9 +3407,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/eslint-module-utils": {
|
||||
"version": "2.11.1",
|
||||
"resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.11.1.tgz",
|
||||
"integrity": "sha512-EwcbfLOhwVMAfatfqLecR2yv3dE5+kQ8kx+Rrt0DvDXEVwW86KQ/xbMDQhtp5l42VXukD5SOF8mQQHbaNtO0CQ==",
|
||||
"version": "2.12.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.12.0.tgz",
|
||||
"integrity": "sha512-wALZ0HFoytlyh/1+4wuZ9FJCD/leWHQzzrxJ8+rebyReSLk7LApMyd3WJaLVoN+D5+WIdJyDK1c6JnE65V4Zyg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
@ -3528,9 +3532,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/eslint-plugin-react": {
|
||||
"version": "7.36.1",
|
||||
"resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.36.1.tgz",
|
||||
"integrity": "sha512-/qwbqNXZoq+VP30s1d4Nc1C5GTxjJQjk4Jzs4Wq2qzxFM7dSmuG2UkIjg2USMLh3A/aVcUNrK7v0J5U1XEGGwA==",
|
||||
"version": "7.37.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.37.0.tgz",
|
||||
"integrity": "sha512-IHBePmfWH5lKhJnJ7WB1V+v/GolbB0rjS8XYVCSQCZKaQCAUhMoVoOEn1Ef8Z8Wf0a7l8KTJvuZg5/e4qrZ6nA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
@ -7807,9 +7811,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/terser": {
|
||||
"version": "5.34.0",
|
||||
"resolved": "https://registry.npmjs.org/terser/-/terser-5.34.0.tgz",
|
||||
"integrity": "sha512-y5NUX+U9HhVsK/zihZwoq4r9dICLyV2jXGOriDAVOeKhq3LKVjgJbGO90FisozXLlJfvjHqgckGmJFBb9KYoWQ==",
|
||||
"version": "5.34.1",
|
||||
"resolved": "https://registry.npmjs.org/terser/-/terser-5.34.1.tgz",
|
||||
"integrity": "sha512-FsJZ7iZLd/BXkz+4xrRTGJ26o/6VTjQytUk8b8OxkwcD2I+79VPJlz7qss1+zE7h8GNIScFqXcDyJ/KqBYZFVA==",
|
||||
"dev": true,
|
||||
"license": "BSD-2-Clause",
|
||||
"dependencies": {
|
||||
|
@ -8170,9 +8174,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/update-browserslist-db": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.0.tgz",
|
||||
"integrity": "sha512-EdRAaAyk2cUE1wOf2DkEhzxqOQvFOoRJFNS6NeyJ01Gp2beMRpBAINjM2iDXE3KCuKhwnvHIQCJm6ThL2Z+HzQ==",
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.1.tgz",
|
||||
"integrity": "sha512-R8UzCaa9Az+38REPiJ1tXlImTJXlVfgHZsglwBD/k6nj76ctsH1E3q4doGrukiLQd3sGQYu56r5+lo5r94l29A==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
|
@ -8190,8 +8194,8 @@
|
|||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"escalade": "^3.1.2",
|
||||
"picocolors": "^1.0.1"
|
||||
"escalade": "^3.2.0",
|
||||
"picocolors": "^1.1.0"
|
||||
},
|
||||
"bin": {
|
||||
"update-browserslist-db": "cli.js"
|
||||
|
|
|
@ -7,9 +7,13 @@
|
|||
"start": "webpack-dev-server"
|
||||
},
|
||||
"dependencies": {
|
||||
"@libp2p/peer-id": "^4.1.2",
|
||||
"@libp2p/crypto": "^4.0.1",
|
||||
"@libp2p/peer-id-factory": "^4.2.4",
|
||||
"@multiformats/multiaddr": "^12.3.1",
|
||||
"@waku/sdk": "0.0.28",
|
||||
"protobufjs": "^7.3.0"
|
||||
"libp2p": "^1.8.3",
|
||||
"protobufjs": "^7.3.0",
|
||||
"uint8arrays": "^5.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@libp2p/interface": "^1.7.0",
|
||||
|
|
|
@ -7,6 +7,9 @@ import {
|
|||
LightNode,
|
||||
utils,
|
||||
} from "@waku/sdk";
|
||||
import { createFromPrivKey } from "@libp2p/peer-id-factory";
|
||||
import { unmarshalPrivateKey, generateKeyPairFromSeed } from "@libp2p/crypto/keys";
|
||||
import { fromString } from "uint8arrays";
|
||||
|
||||
import { Type, Field } from "protobufjs";
|
||||
import {
|
||||
|
@ -32,18 +35,31 @@ const messageSentEvent = new CustomEvent("messageSent");
|
|||
const messageReceivedEvent = new CustomEvent("messageReceived");
|
||||
|
||||
const wakuNode = async (): Promise<LightNode> => {
|
||||
let seed = localStorage.getItem("seed");
|
||||
|
||||
if (!seed) {
|
||||
seed = (await sha256(generateRandomNumber())).slice(0, 32)
|
||||
localStorage.setItem("seed", seed);
|
||||
}
|
||||
|
||||
const privateKey = await generateKeyPairFromSeed("Ed25519", fromString(seed));
|
||||
|
||||
return await createLightNode({
|
||||
networkConfig: {
|
||||
contentTopics: [DEFAULT_CONTENT_TOPIC],
|
||||
},
|
||||
defaultBootstrap: true,
|
||||
libp2p: {
|
||||
peerId: await createFromPrivKey(await unmarshalPrivateKey(privateKey.bytes))
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export async function app(telemetryClient: TelemetryClient) {
|
||||
const node = await wakuNode();
|
||||
(window as any).waku = node;
|
||||
|
||||
await node.start();
|
||||
|
||||
await waitForRemotePeer(node);
|
||||
|
||||
const peerId = node.libp2p.peerId.toString();
|
||||
|
@ -103,11 +119,8 @@ export async function app(telemetryClient: TelemetryClient) {
|
|||
timestamp: new Date(),
|
||||
});
|
||||
|
||||
console.log("===");
|
||||
console.log("light push successes: ", result.successes.length);
|
||||
console.log(result.successes);
|
||||
console.log("light push failures: ", result.failures.length);
|
||||
console.log(result.failures);
|
||||
console.log("DEBUG: light push successes: ", result.successes.length, result.successes);
|
||||
console.log("DEBUG: light push failures: ", result.failures.length, result.failures);
|
||||
|
||||
const successEvents = result
|
||||
.successes
|
||||
|
@ -311,10 +324,9 @@ export async function app(telemetryClient: TelemetryClient) {
|
|||
|
||||
(async () => {
|
||||
const telemetryClient = new TelemetryClient(TELEMETRY_URL, 5000);
|
||||
const { node, startLightPushSequence, startFilterSubscription } = await app(
|
||||
const { startLightPushSequence, startFilterSubscription } = await app(
|
||||
telemetryClient
|
||||
);
|
||||
(window as any).waku = node;
|
||||
|
||||
const runningScreen = document.getElementById("runningScreen");
|
||||
runningScreen.style.display = "block";
|
||||
|
@ -342,7 +354,7 @@ export async function app(telemetryClient: TelemetryClient) {
|
|||
|
||||
function startSequence() {
|
||||
const numMessages = Math.floor(Math.random() * 16) + 5;
|
||||
const messagePeriod = Math.floor(Math.random() * 2001) + 5000;
|
||||
const messagePeriod = Math.floor(Math.random() * 2001) + 5_000;
|
||||
startLightPushSequence(numMessages, messagePeriod);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { peerIdFromString } from "@libp2p/peer-id";
|
||||
import { Peer } from "@libp2p/interface";
|
||||
import type { LightNode } from "@waku/sdk";
|
||||
|
||||
|
@ -20,7 +19,7 @@ export const DEFAULT_EXTRA_DATA_STR = JSON.stringify(DEFAULT_EXTRA_DATA);
|
|||
|
||||
export const buildExtraData = async (node: LightNode, peerId: string): Promise<string> => {
|
||||
let extraData = { ...DEFAULT_EXTRA_DATA };
|
||||
const peer: Peer = await node.libp2p.peerStore.get(peerIdFromString(peerId));
|
||||
const peer: Peer = (await node.libp2p.peerStore.all()).find(p => p.id.toString() === peerId);
|
||||
|
||||
if (!peer || peerId === node.libp2p.peerId.toString()) {
|
||||
return JSON.stringify(extraData);
|
||||
|
|
Loading…
Reference in New Issue