Merge pull request #147 from waku-org/chore/js-waku-0.0.2

This commit is contained in:
fryorcraken.eth 2022-11-20 12:30:09 +11:00 committed by GitHub
commit 229e1aea78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 3582 additions and 2940 deletions

View File

@ -10,14 +10,18 @@
"@material-ui/icons": "^4.11.2", "@material-ui/icons": "^4.11.2",
"ethers": "5.7.1", "ethers": "5.7.1",
"fontsource-roboto": "^4.0.0", "fontsource-roboto": "^4.0.0",
"js-waku": "0.30.0", "@waku/create": "0.0.4",
"@waku/core": "0.0.6",
"@waku/interfaces": "0.0.5",
"@waku/byte-utils": "0.0.2",
"@waku/message-encryption": "0.0.4",
"protobufjs": "^7.1.0", "protobufjs": "^7.1.0",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"uint8arrays": "^3.1.0" "uint8arrays": "^3.1.0"
}, },
"scripts": { "scripts": {
"start": "GENERATE_SOURCEMAP=false PORT=3001 craco start", "start": "GENERATE_SOURCEMAP=false PORT=3004 craco start",
"build": "GENERATE_SOURCEMAP=false craco build", "build": "GENERATE_SOURCEMAP=false craco build",
"fix": "run-s fix:*", "fix": "run-s fix:*",
"test": "run-s build test:*", "test": "run-s build test:*",

File diff suppressed because it is too large Load Diff

View File

@ -2,8 +2,8 @@ import "@ethersproject/shims";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import "./App.css"; import "./App.css";
import type { WakuPrivacy } from "js-waku/lib/interfaces"; import type { WakuPrivacy } from "@waku/interfaces";
import { AsymDecoder, SymDecoder } from "js-waku/lib/waku_message/version_1"; import { AsymDecoder, SymDecoder } from "@waku/message-encryption";
import { KeyPair, PublicKeyMessageEncryptionKey } from "./crypto"; import { KeyPair, PublicKeyMessageEncryptionKey } from "./crypto";
import { Message } from "./messaging/Messages"; import { Message } from "./messaging/Messages";
import "fontsource-roboto"; import "fontsource-roboto";

View File

@ -6,8 +6,8 @@ import {
PublicKeyMessageEncryptionKey, PublicKeyMessageEncryptionKey,
} from "./crypto"; } from "./crypto";
import { PublicKeyMessage } from "./messaging/wire"; import { PublicKeyMessage } from "./messaging/wire";
import type { WakuPrivacy } from "js-waku/lib/interfaces"; import type { WakuPrivacy } from "@waku/interfaces";
import { SymEncoder } from "js-waku/lib/waku_message/version_1"; import { SymEncoder } from "@waku/message-encryption";
import { PublicKeyContentTopic } from "./waku"; import { PublicKeyContentTopic } from "./waku";
import type { TypedDataSigner } from "@ethersproject/abstract-signer"; import type { TypedDataSigner } from "@ethersproject/abstract-signer";

View File

@ -1,14 +1,15 @@
import "@ethersproject/shims"; import "@ethersproject/shims";
import { PublicKeyMessage } from "./messaging/wire"; import { PublicKeyMessage } from "./messaging/wire";
import { generatePrivateKey, getPublicKey, utils } from "js-waku"; import { generatePrivateKey, getPublicKey } from "@waku/message-encryption";
import { PublicKeyContentTopic } from "./waku"; import { PublicKeyContentTopic } from "./waku";
import { keccak256, _TypedDataEncoder, recoverAddress } from "ethers/lib/utils"; import { keccak256, _TypedDataEncoder, recoverAddress } from "ethers/lib/utils";
import { equals } from "uint8arrays/equals"; import { equals } from "uint8arrays/equals";
import type { TypedDataSigner } from "@ethersproject/abstract-signer"; import type { TypedDataSigner } from "@ethersproject/abstract-signer";
import { bytesToHex, hexToBytes, utf8ToBytes } from "@waku/byte-utils";
export const PublicKeyMessageEncryptionKey = utils.hexToBytes( export const PublicKeyMessageEncryptionKey = hexToBytes(
keccak256(utils.utf8ToBytes(PublicKeyContentTopic)) keccak256(utf8ToBytes(PublicKeyContentTopic))
); );
export interface KeyPair { export interface KeyPair {
@ -43,8 +44,8 @@ export async function createPublicKeyMessage(
return new PublicKeyMessage({ return new PublicKeyMessage({
encryptionPublicKey: encryptionPublicKey, encryptionPublicKey: encryptionPublicKey,
ethAddress: utils.hexToBytes(address), ethAddress: hexToBytes(address),
signature: utils.hexToBytes(signature), signature: hexToBytes(signature),
}); });
} }
@ -57,7 +58,7 @@ function buildMsgParams(encryptionPublicKey: Uint8Array, fromAddress: string) {
value: { value: {
message: message:
"By signing this message you certify that messages addressed to `ownerAddress` must be encrypted with `encryptionPublicKey`", "By signing this message you certify that messages addressed to `ownerAddress` must be encrypted with `encryptionPublicKey`",
encryptionPublicKey: utils.bytesToHex(encryptionPublicKey), encryptionPublicKey: bytesToHex(encryptionPublicKey),
ownerAddress: fromAddress, ownerAddress: fromAddress,
}, },
// Refers to the keys of the *types* object below. // Refers to the keys of the *types* object below.
@ -86,7 +87,7 @@ export async function signEncryptionKey(
console.log("TYPED SIGNED:" + JSON.stringify(result)); console.log("TYPED SIGNED:" + JSON.stringify(result));
return utils.hexToBytes(result); return hexToBytes(result);
} }
/** /**
@ -95,7 +96,7 @@ export async function signEncryptionKey(
export function validatePublicKeyMessage(msg: PublicKeyMessage): boolean { export function validatePublicKeyMessage(msg: PublicKeyMessage): boolean {
const { domain, types, value } = buildMsgParams( const { domain, types, value } = buildMsgParams(
msg.encryptionPublicKey, msg.encryptionPublicKey,
"0x" + utils.bytesToHex(msg.ethAddress) "0x" + bytesToHex(msg.ethAddress)
); );
try { try {
@ -103,9 +104,9 @@ export function validatePublicKeyMessage(msg: PublicKeyMessage): boolean {
const recovered = recoverAddress(hash, msg.signature); const recovered = recoverAddress(hash, msg.signature);
console.log("Recovered", recovered); console.log("Recovered", recovered);
console.log("ethAddress", "0x" + utils.bytesToHex(msg.ethAddress)); console.log("ethAddress", "0x" + bytesToHex(msg.ethAddress));
return equals(utils.hexToBytes(recovered), msg.ethAddress); return equals(hexToBytes(recovered), msg.ethAddress);
} catch (e) { } catch (e) {
console.error("Could not recover public key from signature", e); console.error("Could not recover public key from signature", e);
return false; return false;

View File

@ -1,5 +1,5 @@
import { KeyPair } from "../crypto"; import { KeyPair } from "../crypto";
import { utils } from "js-waku"; import { bytesToHex, hexToBytes } from "@waku/byte-utils";
/** /**
* Save key pair to storage, encrypted with password * Save key pair to storage, encrypted with password
@ -11,9 +11,9 @@ export async function saveKeyPairToStorage(
const { salt, iv, cipher } = await encryptKey(EncryptionKeyPair, password); const { salt, iv, cipher } = await encryptKey(EncryptionKeyPair, password);
const data = { const data = {
salt: utils.bytesToHex(salt), salt: bytesToHex(salt),
iv: utils.bytesToHex(iv), iv: bytesToHex(iv),
cipher: utils.bytesToHex(new Uint8Array(cipher)), cipher: bytesToHex(new Uint8Array(cipher)),
}; };
localStorage.setItem("cipherEncryptionKeyPair", JSON.stringify(data)); localStorage.setItem("cipherEncryptionKeyPair", JSON.stringify(data));
@ -29,9 +29,9 @@ export async function loadKeyPairFromStorage(
if (!str) return; if (!str) return;
const data = JSON.parse(str); const data = JSON.parse(str);
const salt = utils.hexToBytes(data.salt); const salt = hexToBytes(data.salt);
const iv = utils.hexToBytes(data.iv); const iv = hexToBytes(data.iv);
const cipher = utils.hexToBytes(data.cipher); const cipher = hexToBytes(data.cipher);
return await decryptKey(salt, iv, cipher, password); return await decryptKey(salt, iv, cipher, password);
} }

View File

@ -1,5 +1,5 @@
import Messages, { Message } from "./Messages"; import Messages, { Message } from "./Messages";
import type { WakuPrivacy } from "js-waku/lib/interfaces"; import type { WakuPrivacy } from "@waku/interfaces";
import SendMessage from "./SendMessage"; import SendMessage from "./SendMessage";
import { makeStyles } from "@material-ui/core"; import { makeStyles } from "@material-ui/core";

View File

@ -7,11 +7,11 @@ import {
TextField, TextField,
} from "@material-ui/core"; } from "@material-ui/core";
import React, { ChangeEvent, useState, KeyboardEvent } from "react"; import React, { ChangeEvent, useState, KeyboardEvent } from "react";
import { utils } from "js-waku"; import type { WakuPrivacy } from "@waku/interfaces";
import type { WakuPrivacy } from "js-waku/lib/interfaces"; import { AsymEncoder } from "@waku/message-encryption";
import { AsymEncoder } from "js-waku/lib/waku_message/version_1";
import { PrivateMessage } from "./wire"; import { PrivateMessage } from "./wire";
import { PrivateMessageContentTopic } from "../waku"; import { PrivateMessageContentTopic } from "../waku";
import { hexToBytes } from "@waku/byte-utils";
const useStyles = makeStyles((theme) => ({ const useStyles = makeStyles((theme) => ({
formControl: { formControl: {
@ -113,7 +113,7 @@ async function sendMessage(
callback: (res: boolean) => void callback: (res: boolean) => void
) { ) {
const privateMessage = new PrivateMessage({ const privateMessage = new PrivateMessage({
toAddress: utils.hexToBytes(recipientAddress), toAddress: hexToBytes(recipientAddress),
message: message, message: message,
}); });
const payload = privateMessage.encode(); const payload = privateMessage.encode();

View File

@ -1,15 +1,13 @@
import { Dispatch, SetStateAction } from "react"; import { Dispatch, SetStateAction } from "react";
import { Protocols, utils } from "js-waku"; import type { Message as WakuMessage, WakuPrivacy } from "@waku/interfaces";
import type { import { Protocols } from "@waku/interfaces";
Message as WakuMessage,
WakuPrivacy,
} from "js-waku/lib/interfaces";
import { PrivateMessage, PublicKeyMessage } from "./messaging/wire"; import { PrivateMessage, PublicKeyMessage } from "./messaging/wire";
import { validatePublicKeyMessage } from "./crypto"; import { validatePublicKeyMessage } from "./crypto";
import { Message } from "./messaging/Messages"; import { Message } from "./messaging/Messages";
import { equals } from "uint8arrays/equals"; import { equals } from "uint8arrays/equals";
import { waitForRemotePeer } from "js-waku/lib/wait_for_remote_peer"; import { waitForRemotePeer } from "@waku/core/lib/wait_for_remote_peer";
import { createPrivacyNode } from "js-waku/lib/create_waku"; import { createPrivacyNode } from "@waku/create";
import { bytesToHex, hexToBytes } from "@waku/byte-utils";
export const PublicKeyContentTopic = "/eth-pm/1/public-key/proto"; export const PublicKeyContentTopic = "/eth-pm/1/public-key/proto";
export const PrivateMessageContentTopic = "/eth-pm/1/private-message/proto"; export const PrivateMessageContentTopic = "/eth-pm/1/private-message/proto";
@ -31,7 +29,7 @@ export function handlePublicKeyMessage(
if (!msg.payload) return; if (!msg.payload) return;
const publicKeyMsg = PublicKeyMessage.decode(msg.payload); const publicKeyMsg = PublicKeyMessage.decode(msg.payload);
if (!publicKeyMsg) return; if (!publicKeyMsg) return;
if (myAddress && equals(publicKeyMsg.ethAddress, utils.hexToBytes(myAddress))) if (myAddress && equals(publicKeyMsg.ethAddress, hexToBytes(myAddress)))
return; return;
const res = validatePublicKeyMessage(publicKeyMsg); const res = validatePublicKeyMessage(publicKeyMsg);
@ -40,7 +38,7 @@ export function handlePublicKeyMessage(
if (res) { if (res) {
setter((prevPks: Map<string, Uint8Array>) => { setter((prevPks: Map<string, Uint8Array>) => {
prevPks.set( prevPks.set(
utils.bytesToHex(publicKeyMsg.ethAddress), bytesToHex(publicKeyMsg.ethAddress),
publicKeyMsg.encryptionPublicKey publicKeyMsg.encryptionPublicKey
); );
return new Map(prevPks); return new Map(prevPks);
@ -60,7 +58,7 @@ export async function handlePrivateMessage(
console.log("Failed to decode Private Message"); console.log("Failed to decode Private Message");
return; return;
} }
if (!equals(privateMessage.toAddress, utils.hexToBytes(address))) return; if (!equals(privateMessage.toAddress, hexToBytes(address))) return;
const timestamp = wakuMsg.timestamp ? wakuMsg.timestamp : new Date(); const timestamp = wakuMsg.timestamp ? wakuMsg.timestamp : new Date();

View File

@ -34,10 +34,10 @@
<div id="messages"></div> <div id="messages"></div>
<script type='module'> <script type='module'>
import {utils} from 'https://unpkg.com/js-waku@0.30.0/bundle/index.js'; import * as utils from 'https://unpkg.com/@waku/byte-utils@0.0.2/bundle/index.js';
import {createLightNode} from 'https://unpkg.com/js-waku@0.30.0/bundle/lib/create_waku.js' import {createLightNode} from 'https://unpkg.com/@waku/create@0.0.4/bundle/index.js'
import {waitForRemotePeer} from 'https://unpkg.com/js-waku@0.30.0/bundle/lib/wait_for_remote_peer.js' import {waitForRemotePeer} from 'https://unpkg.com/@waku/core@0.0.6/bundle/lib/wait_for_remote_peer.js'
import {EncoderV0, DecoderV0} from 'https://unpkg.com/js-waku@0.30.0/bundle/lib/waku_message/version_0.js' import {EncoderV0, DecoderV0} from 'https://unpkg.com/@waku/core@0.0.6/bundle/lib/waku_message/version_0.js'
const peerIdDiv = document.getElementById('peer-id'); const peerIdDiv = document.getElementById('peer-id');
const remotePeerIdDiv = document.getElementById('remote-peer-id'); const remotePeerIdDiv = document.getElementById('remote-peer-id');

View File

@ -13,33 +13,35 @@
}, },
"private": true, "private": true,
"dependencies": { "dependencies": {
"@angular/animations": "~14.2.0", "@angular/animations": "~14.2.10",
"@angular/common": "~14.2.0", "@angular/common": "~14.2.10",
"@angular/compiler": "~14.2.0", "@angular/compiler": "~14.2.10",
"@angular/core": "~14.2.0", "@angular/core": "~14.2.10",
"@angular/forms": "~14.2.0", "@angular/forms": "~14.2.10",
"@angular/platform-browser": "~14.2.0", "@angular/platform-browser": "~14.2.10",
"@angular/platform-browser-dynamic": "~14.2.0", "@angular/platform-browser-dynamic": "~14.2.10",
"@angular/router": "~14.2.0", "@angular/router": "~14.2.10",
"js-waku": "0.30.0", "@waku/core": "^0.0.6",
"protobufjs": "^7.1.0", "@waku/create": "^0.0.4",
"rxjs": "~7.5.0", "@waku/interfaces": "^0.0.5",
"tslib": "^2.3.0", "protobufjs": "^7.1.2",
"rxjs": "~7.5.7",
"tslib": "^2.4.1",
"zone.js": "~0.11.8" "zone.js": "~0.11.8"
}, },
"browser": { "browser": {
"util": false "util": false
}, },
"devDependencies": { "devDependencies": {
"@angular-devkit/build-angular": "~14.2.1", "@angular-devkit/build-angular": "~14.2.9",
"@angular/cli": "~14.2.1", "@angular/cli": "~14.2.9",
"@angular/compiler-cli": "~14.2.0", "@angular/compiler-cli": "~14.2.10",
"@types/jasmine": "~4.3.0", "@types/jasmine": "~4.3.0",
"@types/node": "^17.0.21", "@types/node": "^17.0.45",
"is-ci-cli": "^2.2.0", "is-ci-cli": "^2.2.0",
"jasmine-core": "~4.3.0", "jasmine-core": "~4.3.0",
"karma": "~6.4.0", "karma": "~6.4.1",
"karma-chrome-launcher": "~3.1.0", "karma-chrome-launcher": "~3.1.1",
"karma-coverage": "~2.2.0", "karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0", "karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.0.0", "karma-jasmine-html-reporter": "~2.0.0",

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,9 @@
import { Component, OnInit } from "@angular/core"; import { Component, OnInit } from "@angular/core";
import { WakuService } from "../waku.service"; import { WakuService } from "../waku.service";
import type { WakuPrivacy } from "js-waku/lib/interfaces"; import type { WakuPrivacy } from "@waku/interfaces";
import protobuf from "protobufjs"; import protobuf from "protobufjs";
import { DecoderV0, EncoderV0 } from "js-waku/lib/waku_message/version_0"; import { DecoderV0, EncoderV0 } from "@waku/core/lib/waku_message/version_0";
import type { MessageV0 } from "js-waku/lib/waku_message/version_0"; import type { MessageV0 } from "@waku/core/lib/waku_message/version_0";
const ProtoChatMessage = new protobuf.Type("ChatMessage") const ProtoChatMessage = new protobuf.Type("ChatMessage")
.add(new protobuf.Field("timestamp", 1, "uint32")) .add(new protobuf.Field("timestamp", 1, "uint32"))

View File

@ -1,8 +1,8 @@
import { Injectable } from "@angular/core"; import { Injectable } from "@angular/core";
import { BehaviorSubject, Subject } from "rxjs"; import { BehaviorSubject, Subject } from "rxjs";
import { createPrivacyNode } from "js-waku/lib/create_waku"; import { createPrivacyNode } from "@waku/create";
import { waitForRemotePeer } from "js-waku/lib/wait_for_remote_peer"; import { waitForRemotePeer } from "@waku/core/lib/wait_for_remote_peer";
import type { WakuPrivacy } from "js-waku/lib/interfaces.js"; import type { WakuPrivacy } from "@waku/interfaces";
@Injectable({ @Injectable({
providedIn: "root", providedIn: "root",

View File

@ -13,8 +13,8 @@
<div id='status'></div> <div id='status'></div>
<label for='textInput'>Message text</label> <label for='textInput'>Message text</label>
<input id='textInput' placeholder='Type your message here' type='text' disabled> <input disabled id='textInput' placeholder='Type your message here' type='text'>
<button id='sendButton' type='button' disabled>Send Message using Relay</button> <button disabled id='sendButton' type='button'>Send Message using Relay</button>
<div><h1>Messages</h1></div> <div><h1>Messages</h1></div>
<div id='messages'></div> <div id='messages'></div>
@ -26,10 +26,10 @@
* Recommended payload is protobuf. Using simple utf-8 string for demo purposes only. * Recommended payload is protobuf. Using simple utf-8 string for demo purposes only.
*/ */
import {utils} from 'https://unpkg.com/js-waku@0.30.0/bundle/index.js'; import {bytesToUtf8, utf8ToBytes} from 'https://unpkg.com/@waku/byte-utils@0.0.2/bundle/index.js';
import {createPrivacyNode} from 'https://unpkg.com/js-waku@0.30.0/bundle/lib/create_waku.js' import {createPrivacyNode} from 'https://unpkg.com/@waku/create@0.0.4/bundle/index.js'
import {waitForRemotePeer} from 'https://unpkg.com/js-waku@0.30.0/bundle/lib/wait_for_remote_peer.js' import {waitForRemotePeer} from 'https://unpkg.com/@waku/core@0.0.6/bundle/lib/wait_for_remote_peer.js'
import {DecoderV0, EncoderV0} from "https://unpkg.com/js-waku@0.30.0/bundle/lib/waku_message/version_0.js"; import {DecoderV0, EncoderV0} from "https://unpkg.com/@waku/core@0.0.6/bundle/lib/waku_message/version_0.js";
const statusDiv = document.getElementById('status'); const statusDiv = document.getElementById('status');
const messagesDiv = document.getElementById('messages'); const messagesDiv = document.getElementById('messages');
@ -76,7 +76,7 @@
// structure of their choice. // structure of their choice.
// //
// https://js-waku.wakuconnect.dev/classes/waku_message.WakuMessage.html#payloadAsUtf8 // https://js-waku.wakuconnect.dev/classes/waku_message.WakuMessage.html#payloadAsUtf8
const text = utils.bytesToUtf8(message.payload); const text = bytesToUtf8(message.payload);
messagesDiv.innerHTML = `<p>${text}</p><br />` + messagesDiv.innerHTML; messagesDiv.innerHTML = `<p>${text}</p><br />` + messagesDiv.innerHTML;
}, [contentTopic]); }, [contentTopic]);
@ -92,7 +92,7 @@
// function that sends the text input over Waku Relay, the gossipsub // function that sends the text input over Waku Relay, the gossipsub
// protocol. // protocol.
sendButton.onclick = async () => { sendButton.onclick = async () => {
const payload = utils.utf8ToBytes(textInput.value) const payload = utf8ToBytes(textInput.value)
await waku.relay.send(encoder, {payload}); await waku.relay.send(encoder, {payload});
console.log('Message sent!'); console.log('Message sent!');

View File

@ -7,7 +7,8 @@
"@testing-library/jest-dom": "^5.16.5", "@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.3.0", "@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.5.0", "@testing-library/user-event": "^13.5.0",
"js-waku": "0.30.0", "@waku/core": "^0.0.6",
"@waku/create": "^0.0.4",
"protobufjs": "^7.0.0", "protobufjs": "^7.0.0",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
import * as React from "react"; import * as React from "react";
import protobuf from "protobufjs"; import protobuf from "protobufjs";
import { createPrivacyNode } from "js-waku/lib/create_waku"; import { createPrivacyNode } from "@waku/create";
import { waitForRemotePeer } from "js-waku/lib/wait_for_remote_peer"; import { waitForRemotePeer } from "@waku/core/lib/wait_for_remote_peer";
import { DecoderV0, EncoderV0 } from "js-waku/lib/waku_message/version_0"; import { DecoderV0, EncoderV0 } from "@waku/core/lib/waku_message/version_0";
const ContentTopic = `/js-waku-examples/1/chat/proto`; const ContentTopic = `/js-waku-examples/1/chat/proto`;
const Encoder = new EncoderV0(ContentTopic); const Encoder = new EncoderV0(ContentTopic);

View File

@ -13,10 +13,10 @@
<div id='timestamp'></div> <div id='timestamp'></div>
<script type='module'> <script type='module'>
import {Protocols} from 'https://unpkg.com/js-waku@0.30.0/bundle/index.js'; import {defaultLibp2p, defaultPeerDiscovery} from 'https://unpkg.com/@waku/create@0.0.4/bundle/index.js'
import {createLightNode} from 'https://unpkg.com/js-waku@0.30.0/bundle/lib/create_waku.js' import {waitForRemotePeer} from 'https://unpkg.com/@waku/core@0.0.6/bundle/lib/wait_for_remote_peer.js'
import {waitForRemotePeer} from 'https://unpkg.com/js-waku@0.30.0/bundle/lib/wait_for_remote_peer.js' import {wakuStore, WakuNode} from 'https://unpkg.com/@waku/core@0.0.6/bundle/index.js'
import {DecoderV0} from 'https://unpkg.com/js-waku@0.30.0/bundle/lib/waku_message/version_0.js' import {DecoderV0} from 'https://unpkg.com/@waku/core@0.0.6/bundle/lib/waku_message/version_0.js'
/** /**
* This example demonstrates how to use the js-waku minified bundle * This example demonstrates how to use the js-waku minified bundle
@ -28,13 +28,19 @@
const timestampDiv = document.getElementById('timestamp'); const timestampDiv = document.getElementById('timestamp');
timestampDiv.innerHTML = '<p>Creating waku.</p>'; timestampDiv.innerHTML = '<p>Creating waku.</p>';
const node = await createLightNode({defaultBootstrap: true});
const libp2p = await defaultLibp2p(
undefined,
{peerDiscovery: [defaultPeerDiscovery()]},
);
const store = wakuStore();
const node = new WakuNode({}, libp2p, store,);
timestampDiv.innerHTML = '<p>Starting waku.</p>'; timestampDiv.innerHTML = '<p>Starting waku.</p>';
await node.start(); await node.start();
timestampDiv.innerHTML = '<p>Connecting to a peer.</p>'; timestampDiv.innerHTML = '<p>Connecting to a peer.</p>';
await waitForRemotePeer(node, [Protocols.Store]); await waitForRemotePeer(node, ["store"]);
timestampDiv.innerHTML = '<p>Retrieving messages.</p>'; timestampDiv.innerHTML = '<p>Retrieving messages.</p>';
const callback = (wakuMessage) => { const callback = (wakuMessage) => {

View File

@ -7,7 +7,9 @@
"@testing-library/jest-dom": "^5.16.4", "@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.2.0", "@testing-library/react": "^13.2.0",
"@testing-library/user-event": "^14.1.1", "@testing-library/user-event": "^14.1.1",
"js-waku": "0.30.0", "@waku/byte-utils": "^0.0.2",
"@waku/core": "^0.0.6",
"@waku/create": "^0.0.4",
"protobufjs": "^7.1.0", "protobufjs": "^7.1.0",
"react": "^18.1.0", "react": "^18.1.0",
"react-dom": "^18.1.0", "react-dom": "^18.1.0",

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,9 @@
import { utils } from "js-waku";
import * as React from "react"; import * as React from "react";
import protobuf from "protobufjs"; import protobuf from "protobufjs";
import { createLightNode } from "js-waku/lib/create_waku"; import {createLightNode} from "@waku/create";
import { waitForRemotePeer } from "js-waku/lib/wait_for_remote_peer"; import {waitForRemotePeer} from "@waku/core/lib/wait_for_remote_peer";
import { DecoderV0 } from "js-waku/lib/waku_message/version_0"; import {DecoderV0} from "@waku/core/lib/waku_message/version_0";
import {bytesToUtf8} from "@waku/byte-utils"
const ContentTopic = "/toy-chat/2/huilong/proto"; const ContentTopic = "/toy-chat/2/huilong/proto";
const Decoder = new DecoderV0(ContentTopic); const Decoder = new DecoderV0(ContentTopic);
@ -109,7 +109,7 @@ function decodeMessage(wakuMessage) {
const time = new Date(); const time = new Date();
time.setTime(Number(timestamp)); time.setTime(Number(timestamp));
const utf8Text = utils.bytesToUtf8(text); const utf8Text = bytesToUtf8(text);
return { return {
text: utf8Text, text: utf8Text,

View File

@ -4,9 +4,13 @@
"private": true, "private": true,
"homepage": "/web-chat", "homepage": "/web-chat",
"dependencies": { "dependencies": {
"@libp2p/bootstrap": "^5.0.0",
"@livechat/ui-kit": "^0.5.0-20", "@livechat/ui-kit": "^0.5.0-20",
"@multiformats/multiaddr": "^10.4.0", "@multiformats/multiaddr": "11.0.7",
"js-waku": "0.30.0", "@waku/byte-utils": "^0.0.2",
"@waku/core": "^0.0.6",
"@waku/create": "^0.0.4",
"@waku/interfaces": "^0.0.5",
"process": "^0.11.10", "process": "^0.11.10",
"protons-runtime": "^3.1.0", "protons-runtime": "^3.1.0",
"react": "^17.0.2", "react": "^17.0.2",
@ -29,7 +33,7 @@
"url": "^0.11.0" "url": "^0.11.0"
}, },
"scripts": { "scripts": {
"start": "PORT=3003 react-scripts start", "start": "GENERATE_SOURCEMAP=false PORT=3003 react-scripts start",
"build": "react-scripts build", "build": "react-scripts build",
"test:unit": "exit 0", "test:unit": "exit 0",
"fix": "run-s fix:*", "fix": "run-s fix:*",

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,5 @@
import { useEffect, useReducer, useState } from "react"; import { useEffect, useReducer, useState } from "react";
import "./App.css"; import "./App.css";
import { PageDirection, Protocols } from "js-waku";
import handleCommand from "./command"; import handleCommand from "./command";
import Room from "./Room"; import Room from "./Room";
import { WakuContext } from "./WakuContext"; import { WakuContext } from "./WakuContext";
@ -10,13 +9,14 @@ import { Message } from "./Message";
import { import {
Fleet, Fleet,
getPredefinedBootstrapNodes, getPredefinedBootstrapNodes,
} from "js-waku/lib/predefined_bootstrap_nodes"; } from "@waku/core/lib/predefined_bootstrap_nodes";
import { waitForRemotePeer } from "js-waku/lib/wait_for_remote_peer"; import { waitForRemotePeer } from "@waku/core/lib/wait_for_remote_peer";
import { PeerDiscoveryStaticPeers } from "js-waku/lib/peer_discovery_static_list"; import { Protocols, WakuLight } from "@waku/interfaces";
import type { WakuLight } from "js-waku/lib/interfaces";
import process from "process"; import process from "process";
import { createLightNode } from "js-waku/lib/create_waku"; import { createLightNode } from "@waku/create";
import { DecoderV0, MessageV0 } from "js-waku/lib/waku_message/version_0"; import { DecoderV0, MessageV0 } from "@waku/core/lib/waku_message/version_0";
import { PageDirection } from "@waku/interfaces";
import { bootstrap } from "@libp2p/bootstrap";
const themes = { const themes = {
AuthorName: { AuthorName: {
@ -203,9 +203,7 @@ async function initWaku(setter: (waku: WakuLight) => void) {
const waku = await createLightNode({ const waku = await createLightNode({
libp2p: { libp2p: {
peerDiscovery: [ peerDiscovery: [
new PeerDiscoveryStaticPeers( bootstrap({ list: getPredefinedBootstrapNodes(selectFleetEnv()) }),
getPredefinedBootstrapNodes(selectFleetEnv())
),
], ],
}, },
}); });

View File

@ -1,4 +1,4 @@
import { MessageV0 } from "js-waku/lib/waku_message/version_0"; import { MessageV0 } from "@waku/core/lib/waku_message/version_0";
import { ChatMessage } from "./chat_message"; import { ChatMessage } from "./chat_message";
export class Message { export class Message {

View File

@ -1,4 +1,4 @@
import type { Message as WakuMessage } from "js-waku/lib/interfaces"; import type { Message as WakuMessage } from "@waku/interfaces";
import { ChatContentTopic } from "./App"; import { ChatContentTopic } from "./App";
import ChatList from "./ChatList"; import ChatList from "./ChatList";
import MessageInput from "./MessageInput"; import MessageInput from "./MessageInput";
@ -7,7 +7,7 @@ import { TitleBar } from "@livechat/ui-kit";
import { Message } from "./Message"; import { Message } from "./Message";
import { ChatMessage } from "./chat_message"; import { ChatMessage } from "./chat_message";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { EncoderV0 } from "js-waku/lib/waku_message/version_0"; import { EncoderV0 } from "@waku/core/lib/waku_message/version_0";
interface Props { interface Props {
messages: Message[]; messages: Message[];

View File

@ -1,5 +1,5 @@
import { createContext, useContext } from "react"; import { createContext, useContext } from "react";
import type { WakuLight } from "js-waku/lib/interfaces"; import type { WakuLight } from "@waku/interfaces";
export type WakuContextType = { export type WakuContextType = {
waku?: WakuLight; waku?: WakuLight;

View File

@ -1,4 +1,4 @@
import { utils } from "js-waku"; import { utf8ToBytes, bytesToUtf8 } from "@waku/byte-utils";
import * as proto from "./proto/chat_message"; import * as proto from "./proto/chat_message";
/** /**
@ -20,7 +20,7 @@ export class ChatMessage {
text: string text: string
): ChatMessage { ): ChatMessage {
const timestampNumber = BigInt(Math.floor(timestamp.valueOf() / 1000)); const timestampNumber = BigInt(Math.floor(timestamp.valueOf() / 1000));
const payload = utils.utf8ToBytes(text); const payload = utf8ToBytes(text);
return new ChatMessage({ return new ChatMessage({
timestamp: timestampNumber, timestamp: timestampNumber,
@ -47,7 +47,7 @@ export class ChatMessage {
} }
get timestamp(): Date { get timestamp(): Date {
return new Date(Number(this.proto.timestamp * BigInt(1000))); return new Date(Number(BigInt(this.proto.timestamp) * BigInt(1000)));
} }
get nick(): string { get nick(): string {
@ -59,6 +59,6 @@ export class ChatMessage {
return ""; return "";
} }
return utils.bytesToUtf8(this.proto.payload); return bytesToUtf8(this.proto.payload);
} }
} }

View File

@ -1,5 +1,5 @@
import { multiaddr } from "@multiformats/multiaddr"; import { multiaddr } from "@multiformats/multiaddr";
import type { WakuLight } from "js-waku/lib/interfaces"; import type { WakuLight } from "@waku/interfaces";
function help(): string[] { function help(): string[] {
return [ return [
@ -44,7 +44,9 @@ function connect(
if (!peerId) { if (!peerId) {
return ["Peer Id needed to dial"]; return ["Peer Id needed to dial"];
} }
waku.addPeerToAddressBook(peerId, [peerMultiaddr]); waku
.dial(peerMultiaddr)
.catch((e) => console.error(`Failed to dial ${peerMultiaddr}`, e));
return [ return [
`${peerId}: ${peerMultiaddr.toString()} added to address book, autodial in progress`, `${peerId}: ${peerMultiaddr.toString()} added to address book, autodial in progress`,
]; ];