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",
"ethers": "5.7.1",
"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",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"uint8arrays": "^3.1.0"
},
"scripts": {
"start": "GENERATE_SOURCEMAP=false PORT=3001 craco start",
"start": "GENERATE_SOURCEMAP=false PORT=3004 craco start",
"build": "GENERATE_SOURCEMAP=false craco build",
"fix": "run-s fix:*",
"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 "./App.css";
import type { WakuPrivacy } from "js-waku/lib/interfaces";
import { AsymDecoder, SymDecoder } from "js-waku/lib/waku_message/version_1";
import type { WakuPrivacy } from "@waku/interfaces";
import { AsymDecoder, SymDecoder } from "@waku/message-encryption";
import { KeyPair, PublicKeyMessageEncryptionKey } from "./crypto";
import { Message } from "./messaging/Messages";
import "fontsource-roboto";

View File

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

View File

@ -1,14 +1,15 @@
import "@ethersproject/shims";
import { PublicKeyMessage } from "./messaging/wire";
import { generatePrivateKey, getPublicKey, utils } from "js-waku";
import { generatePrivateKey, getPublicKey } from "@waku/message-encryption";
import { PublicKeyContentTopic } from "./waku";
import { keccak256, _TypedDataEncoder, recoverAddress } from "ethers/lib/utils";
import { equals } from "uint8arrays/equals";
import type { TypedDataSigner } from "@ethersproject/abstract-signer";
import { bytesToHex, hexToBytes, utf8ToBytes } from "@waku/byte-utils";
export const PublicKeyMessageEncryptionKey = utils.hexToBytes(
keccak256(utils.utf8ToBytes(PublicKeyContentTopic))
export const PublicKeyMessageEncryptionKey = hexToBytes(
keccak256(utf8ToBytes(PublicKeyContentTopic))
);
export interface KeyPair {
@ -43,8 +44,8 @@ export async function createPublicKeyMessage(
return new PublicKeyMessage({
encryptionPublicKey: encryptionPublicKey,
ethAddress: utils.hexToBytes(address),
signature: utils.hexToBytes(signature),
ethAddress: hexToBytes(address),
signature: hexToBytes(signature),
});
}
@ -57,7 +58,7 @@ function buildMsgParams(encryptionPublicKey: Uint8Array, fromAddress: string) {
value: {
message:
"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,
},
// Refers to the keys of the *types* object below.
@ -86,7 +87,7 @@ export async function signEncryptionKey(
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 {
const { domain, types, value } = buildMsgParams(
msg.encryptionPublicKey,
"0x" + utils.bytesToHex(msg.ethAddress)
"0x" + bytesToHex(msg.ethAddress)
);
try {
@ -103,9 +104,9 @@ export function validatePublicKeyMessage(msg: PublicKeyMessage): boolean {
const recovered = recoverAddress(hash, msg.signature);
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) {
console.error("Could not recover public key from signature", e);
return false;

View File

@ -1,5 +1,5 @@
import { KeyPair } from "../crypto";
import { utils } from "js-waku";
import { bytesToHex, hexToBytes } from "@waku/byte-utils";
/**
* 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 data = {
salt: utils.bytesToHex(salt),
iv: utils.bytesToHex(iv),
cipher: utils.bytesToHex(new Uint8Array(cipher)),
salt: bytesToHex(salt),
iv: bytesToHex(iv),
cipher: bytesToHex(new Uint8Array(cipher)),
};
localStorage.setItem("cipherEncryptionKeyPair", JSON.stringify(data));
@ -29,9 +29,9 @@ export async function loadKeyPairFromStorage(
if (!str) return;
const data = JSON.parse(str);
const salt = utils.hexToBytes(data.salt);
const iv = utils.hexToBytes(data.iv);
const cipher = utils.hexToBytes(data.cipher);
const salt = hexToBytes(data.salt);
const iv = hexToBytes(data.iv);
const cipher = hexToBytes(data.cipher);
return await decryptKey(salt, iv, cipher, password);
}

View File

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

View File

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

View File

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

View File

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

View File

@ -13,33 +13,35 @@
},
"private": true,
"dependencies": {
"@angular/animations": "~14.2.0",
"@angular/common": "~14.2.0",
"@angular/compiler": "~14.2.0",
"@angular/core": "~14.2.0",
"@angular/forms": "~14.2.0",
"@angular/platform-browser": "~14.2.0",
"@angular/platform-browser-dynamic": "~14.2.0",
"@angular/router": "~14.2.0",
"js-waku": "0.30.0",
"protobufjs": "^7.1.0",
"rxjs": "~7.5.0",
"tslib": "^2.3.0",
"@angular/animations": "~14.2.10",
"@angular/common": "~14.2.10",
"@angular/compiler": "~14.2.10",
"@angular/core": "~14.2.10",
"@angular/forms": "~14.2.10",
"@angular/platform-browser": "~14.2.10",
"@angular/platform-browser-dynamic": "~14.2.10",
"@angular/router": "~14.2.10",
"@waku/core": "^0.0.6",
"@waku/create": "^0.0.4",
"@waku/interfaces": "^0.0.5",
"protobufjs": "^7.1.2",
"rxjs": "~7.5.7",
"tslib": "^2.4.1",
"zone.js": "~0.11.8"
},
"browser": {
"util": false
},
"devDependencies": {
"@angular-devkit/build-angular": "~14.2.1",
"@angular/cli": "~14.2.1",
"@angular/compiler-cli": "~14.2.0",
"@angular-devkit/build-angular": "~14.2.9",
"@angular/cli": "~14.2.9",
"@angular/compiler-cli": "~14.2.10",
"@types/jasmine": "~4.3.0",
"@types/node": "^17.0.21",
"@types/node": "^17.0.45",
"is-ci-cli": "^2.2.0",
"jasmine-core": "~4.3.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.1.0",
"karma": "~6.4.1",
"karma-chrome-launcher": "~3.1.1",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.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 { WakuService } from "../waku.service";
import type { WakuPrivacy } from "js-waku/lib/interfaces";
import type { WakuPrivacy } from "@waku/interfaces";
import protobuf from "protobufjs";
import { DecoderV0, EncoderV0 } from "js-waku/lib/waku_message/version_0";
import type { MessageV0 } from "js-waku/lib/waku_message/version_0";
import { DecoderV0, EncoderV0 } from "@waku/core/lib/waku_message/version_0";
import type { MessageV0 } from "@waku/core/lib/waku_message/version_0";
const ProtoChatMessage = new protobuf.Type("ChatMessage")
.add(new protobuf.Field("timestamp", 1, "uint32"))

View File

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

View File

@ -13,8 +13,8 @@
<div id='status'></div>
<label for='textInput'>Message text</label>
<input id='textInput' placeholder='Type your message here' type='text' disabled>
<button id='sendButton' type='button' disabled>Send Message using Relay</button>
<input disabled id='textInput' placeholder='Type your message here' type='text'>
<button disabled id='sendButton' type='button'>Send Message using Relay</button>
<div><h1>Messages</h1></div>
<div id='messages'></div>
@ -26,10 +26,10 @@
* 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 {createPrivacyNode} from 'https://unpkg.com/js-waku@0.30.0/bundle/lib/create_waku.js'
import {waitForRemotePeer} from 'https://unpkg.com/js-waku@0.30.0/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 {bytesToUtf8, utf8ToBytes} from 'https://unpkg.com/@waku/byte-utils@0.0.2/bundle/index.js';
import {createPrivacyNode} from 'https://unpkg.com/@waku/create@0.0.4/bundle/index.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/@waku/core@0.0.6/bundle/lib/waku_message/version_0.js";
const statusDiv = document.getElementById('status');
const messagesDiv = document.getElementById('messages');
@ -76,7 +76,7 @@
// structure of their choice.
//
// 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;
}, [contentTopic]);
@ -92,7 +92,7 @@
// function that sends the text input over Waku Relay, the gossipsub
// protocol.
sendButton.onclick = async () => {
const payload = utils.utf8ToBytes(textInput.value)
const payload = utf8ToBytes(textInput.value)
await waku.relay.send(encoder, {payload});
console.log('Message sent!');

View File

@ -7,7 +7,8 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.3.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",
"react": "^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 protobuf from "protobufjs";
import { createPrivacyNode } from "js-waku/lib/create_waku";
import { waitForRemotePeer } from "js-waku/lib/wait_for_remote_peer";
import { DecoderV0, EncoderV0 } from "js-waku/lib/waku_message/version_0";
import { createPrivacyNode } from "@waku/create";
import { waitForRemotePeer } from "@waku/core/lib/wait_for_remote_peer";
import { DecoderV0, EncoderV0 } from "@waku/core/lib/waku_message/version_0";
const ContentTopic = `/js-waku-examples/1/chat/proto`;
const Encoder = new EncoderV0(ContentTopic);

View File

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

View File

@ -7,7 +7,9 @@
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.2.0",
"@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",
"react": "^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 protobuf from "protobufjs";
import { createLightNode } from "js-waku/lib/create_waku";
import { waitForRemotePeer } from "js-waku/lib/wait_for_remote_peer";
import { DecoderV0 } from "js-waku/lib/waku_message/version_0";
import {createLightNode} from "@waku/create";
import {waitForRemotePeer} from "@waku/core/lib/wait_for_remote_peer";
import {DecoderV0} from "@waku/core/lib/waku_message/version_0";
import {bytesToUtf8} from "@waku/byte-utils"
const ContentTopic = "/toy-chat/2/huilong/proto";
const Decoder = new DecoderV0(ContentTopic);
@ -109,7 +109,7 @@ function decodeMessage(wakuMessage) {
const time = new Date();
time.setTime(Number(timestamp));
const utf8Text = utils.bytesToUtf8(text);
const utf8Text = bytesToUtf8(text);
return {
text: utf8Text,

View File

@ -4,9 +4,13 @@
"private": true,
"homepage": "/web-chat",
"dependencies": {
"@libp2p/bootstrap": "^5.0.0",
"@livechat/ui-kit": "^0.5.0-20",
"@multiformats/multiaddr": "^10.4.0",
"js-waku": "0.30.0",
"@multiformats/multiaddr": "11.0.7",
"@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",
"protons-runtime": "^3.1.0",
"react": "^17.0.2",
@ -29,7 +33,7 @@
"url": "^0.11.0"
},
"scripts": {
"start": "PORT=3003 react-scripts start",
"start": "GENERATE_SOURCEMAP=false PORT=3003 react-scripts start",
"build": "react-scripts build",
"test:unit": "exit 0",
"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 "./App.css";
import { PageDirection, Protocols } from "js-waku";
import handleCommand from "./command";
import Room from "./Room";
import { WakuContext } from "./WakuContext";
@ -10,13 +9,14 @@ import { Message } from "./Message";
import {
Fleet,
getPredefinedBootstrapNodes,
} from "js-waku/lib/predefined_bootstrap_nodes";
import { waitForRemotePeer } from "js-waku/lib/wait_for_remote_peer";
import { PeerDiscoveryStaticPeers } from "js-waku/lib/peer_discovery_static_list";
import type { WakuLight } from "js-waku/lib/interfaces";
} from "@waku/core/lib/predefined_bootstrap_nodes";
import { waitForRemotePeer } from "@waku/core/lib/wait_for_remote_peer";
import { Protocols, WakuLight } from "@waku/interfaces";
import process from "process";
import { createLightNode } from "js-waku/lib/create_waku";
import { DecoderV0, MessageV0 } from "js-waku/lib/waku_message/version_0";
import { createLightNode } from "@waku/create";
import { DecoderV0, MessageV0 } from "@waku/core/lib/waku_message/version_0";
import { PageDirection } from "@waku/interfaces";
import { bootstrap } from "@libp2p/bootstrap";
const themes = {
AuthorName: {
@ -203,9 +203,7 @@ async function initWaku(setter: (waku: WakuLight) => void) {
const waku = await createLightNode({
libp2p: {
peerDiscovery: [
new PeerDiscoveryStaticPeers(
getPredefinedBootstrapNodes(selectFleetEnv())
),
bootstrap({ list: 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";
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 ChatList from "./ChatList";
import MessageInput from "./MessageInput";
@ -7,7 +7,7 @@ import { TitleBar } from "@livechat/ui-kit";
import { Message } from "./Message";
import { ChatMessage } from "./chat_message";
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 {
messages: Message[];

View File

@ -1,5 +1,5 @@
import { createContext, useContext } from "react";
import type { WakuLight } from "js-waku/lib/interfaces";
import type { WakuLight } from "@waku/interfaces";
export type WakuContextType = {
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";
/**
@ -20,7 +20,7 @@ export class ChatMessage {
text: string
): ChatMessage {
const timestampNumber = BigInt(Math.floor(timestamp.valueOf() / 1000));
const payload = utils.utf8ToBytes(text);
const payload = utf8ToBytes(text);
return new ChatMessage({
timestamp: timestampNumber,
@ -47,7 +47,7 @@ export class ChatMessage {
}
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 {
@ -59,6 +59,6 @@ export class ChatMessage {
return "";
}
return utils.bytesToUtf8(this.proto.payload);
return bytesToUtf8(this.proto.payload);
}
}

View File

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