Use js-waku from npmjs.com instead of local build

This commit is contained in:
Franck Royer 2022-05-02 16:27:52 +10:00
parent 3b15a32f12
commit 507413665a
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
21 changed files with 26082 additions and 12043 deletions

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@
"eth-sig-util": "^3.0.1",
"ethers": "^5.5.4",
"fontsource-roboto": "^4.0.0",
"js-waku": "file:../../build/main",
"js-waku": "^0.19.2",
"protobufjs": "^6.11.2",
"react": "^17.0.2",
"react-dom": "^17.0.2"
@ -56,12 +56,17 @@
"devDependencies": {
"@ethersproject/shims": "^5.5.0",
"@types/node": "^17.0.17",
"assert": "^2.0.0",
"buffer": "^6.0.3",
"cra-webpack-rewired": "^1.0.1",
"crypto-browserify": "^3.12.0",
"cspell": "^5.18.4",
"eslint": "^8.9.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.5.1",
"process": "^0.11.10",
"react-scripts": "5.0.0",
"stream-browserify": "^3.0.0",
"typescript": "^4.5.5"
}
}

View File

@ -1,7 +1,7 @@
import "@ethersproject/shims";
import { PublicKeyMessage } from "./messaging/wire";
import { hexToBytes, bytesToHex } from "js-waku/lib/utils";
import { utils } from "js-waku";
import * as sigUtil from "eth-sig-util";
import { equals } from "uint8arrays/equals";
@ -29,8 +29,8 @@ export async function createPublicKeyMessage(
return new PublicKeyMessage({
encryptionPublicKey: encryptionPublicKey,
ethAddress: hexToBytes(address),
signature: hexToBytes(signature),
ethAddress: utils.hexToBytes(address),
signature: utils.hexToBytes(signature),
});
}
@ -43,7 +43,7 @@ function buildMsgParams(encryptionPublicKey: Uint8Array, fromAddress: string) {
message: {
message:
"By signing this message you certify that messages addressed to `ownerAddress` must be encrypted with `encryptionPublicKey`",
encryptionPublicKey: bytesToHex(encryptionPublicKey),
encryptionPublicKey: utils.bytesToHex(encryptionPublicKey),
ownerAddress: fromAddress,
},
// Refers to the keys of the *types* object below.
@ -81,7 +81,7 @@ export async function signEncryptionKey(
console.log("TYPED SIGNED:" + JSON.stringify(result));
return hexToBytes(result);
return utils.hexToBytes(result);
}
/**
@ -90,13 +90,16 @@ export async function signEncryptionKey(
export function validatePublicKeyMessage(msg: PublicKeyMessage): boolean {
const recovered = sigUtil.recoverTypedSignature_v4({
data: JSON.parse(
buildMsgParams(msg.encryptionPublicKey, "0x" + bytesToHex(msg.ethAddress))
buildMsgParams(
msg.encryptionPublicKey,
"0x" + utils.bytesToHex(msg.ethAddress)
)
),
sig: "0x" + bytesToHex(msg.signature),
sig: "0x" + utils.bytesToHex(msg.signature),
});
console.log("Recovered", recovered);
console.log("ethAddress", "0x" + bytesToHex(msg.ethAddress));
console.log("ethAddress", "0x" + utils.bytesToHex(msg.ethAddress));
return equals(hexToBytes(recovered), msg.ethAddress);
return equals(utils.hexToBytes(recovered), msg.ethAddress);
}

View File

@ -7,8 +7,7 @@ import {
TextField,
} from "@material-ui/core";
import React, { ChangeEvent, useState, KeyboardEvent } from "react";
import { Waku, WakuMessage } from "js-waku";
import { bytesToHex, hexToBytes } from "js-waku/lib/utils";
import { utils, Waku, WakuMessage } from "js-waku";
import { PrivateMessage } from "./wire";
import { PrivateMessageContentTopic } from "../waku";
import * as sigUtil from "eth-sig-util";
@ -111,7 +110,7 @@ async function encodeEncryptedWakuMessage(
address: string
): Promise<WakuMessage> {
const privateMessage = new PrivateMessage({
toAddress: hexToBytes(address),
toAddress: utils.hexToBytes(address),
message: message,
});
@ -119,7 +118,7 @@ async function encodeEncryptedWakuMessage(
const encObj = sigUtil.encrypt(
Buffer.from(publicKey).toString("base64"),
{ data: bytesToHex(payload) },
{ data: utils.bytesToHex(payload) },
"x25519-xsalsa20-poly1305"
);

View File

@ -1,9 +1,8 @@
import { Dispatch, SetStateAction } from "react";
import { Waku, WakuMessage } from "js-waku";
import { utils, Waku, WakuMessage } from "js-waku";
import { PrivateMessage, PublicKeyMessage } from "./messaging/wire";
import { validatePublicKeyMessage } from "./crypto";
import { Message } from "./messaging/Messages";
import { bytesToHex, hexToBytes } from "js-waku/lib/utils";
import { equals } from "uint8arrays/equals";
export const PublicKeyContentTopic =
@ -37,7 +36,7 @@ export function handlePublicKeyMessage(
if (!msg.payload) return;
const publicKeyMsg = PublicKeyMessage.decode(msg.payload);
if (!publicKeyMsg) return;
if (myAddress && equals(publicKeyMsg.ethAddress, hexToBytes(myAddress)))
if (myAddress && equals(publicKeyMsg.ethAddress, utils.hexToBytes(myAddress)))
return;
const res = validatePublicKeyMessage(publicKeyMsg);
@ -46,7 +45,7 @@ export function handlePublicKeyMessage(
if (res) {
setPublicKeys((prevPks: Map<string, Uint8Array>) => {
prevPks.set(
bytesToHex(publicKeyMsg.ethAddress),
utils.bytesToHex(publicKeyMsg.ethAddress),
publicKeyMsg.encryptionPublicKey
);
return new Map(prevPks);
@ -79,7 +78,7 @@ export async function handlePrivateMessage(
console.log("Failed to decode Private Message");
return;
}
if (!equals(privateMessage.toAddress, hexToBytes(address))) return;
if (!equals(privateMessage.toAddress, utils.hexToBytes(address))) return;
const timestamp = wakuMsg.timestamp ? wakuMsg.timestamp : new Date();

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@
"eth-sig-util": "^3.0.1",
"ethers": "^5.5.4",
"fontsource-roboto": "^4.0.0",
"js-waku": "file:../../build/main",
"js-waku": "^0.19.2",
"protobufjs": "^6.11.2",
"react": "^17.0.2",
"react-dom": "^17.0.2"
@ -56,12 +56,17 @@
"devDependencies": {
"@ethersproject/shims": "^5.5.0",
"@types/node": "^17.0.19",
"assert": "^2.0.0",
"buffer": "^6.0.3",
"cra-webpack-rewired": "^1.0.1",
"crypto-browserify": "^3.12.0",
"cspell": "^5.18.4",
"eslint": "^8.9.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.5.1",
"process": "^0.11.10",
"react-scripts": "5.0.0",
"stream-browserify": "^3.0.0",
"typescript": "^4.5.5"
}
}

View File

@ -1,14 +1,13 @@
import "@ethersproject/shims";
import { PublicKeyMessage } from "./messaging/wire";
import { hexToBytes, bytesToHex } from "js-waku/lib/utils";
import { generatePrivateKey, getPublicKey } from "js-waku";
import { generatePrivateKey, getPublicKey, utils } from "js-waku";
import * as sigUtil from "eth-sig-util";
import { PublicKeyContentTopic } from "./waku";
import { keccak256 } from "ethers/lib/utils";
import { equals } from "uint8arrays/equals";
export const PublicKeyMessageEncryptionKey = hexToBytes(
export const PublicKeyMessageEncryptionKey = utils.hexToBytes(
keccak256(Buffer.from(PublicKeyContentTopic, "utf-8"))
);
@ -50,8 +49,8 @@ export async function createPublicKeyMessage(
return new PublicKeyMessage({
encryptionPublicKey: encryptionPublicKey,
ethAddress: hexToBytes(address),
signature: hexToBytes(signature),
ethAddress: utils.hexToBytes(address),
signature: utils.hexToBytes(signature),
});
}
@ -64,7 +63,7 @@ function buildMsgParams(encryptionPublicKey: Uint8Array, fromAddress: string) {
message: {
message:
"By signing this message you certify that messages addressed to `ownerAddress` must be encrypted with `encryptionPublicKey`",
encryptionPublicKey: bytesToHex(encryptionPublicKey),
encryptionPublicKey: utils.bytesToHex(encryptionPublicKey),
ownerAddress: fromAddress,
},
// Refers to the keys of the *types* object below.
@ -102,7 +101,7 @@ export async function signEncryptionKey(
console.log("TYPED SIGNED:" + JSON.stringify(result));
return hexToBytes(result);
return utils.hexToBytes(result);
}
/**
@ -111,13 +110,16 @@ export async function signEncryptionKey(
export function validatePublicKeyMessage(msg: PublicKeyMessage): boolean {
const recovered = sigUtil.recoverTypedSignature_v4({
data: JSON.parse(
buildMsgParams(msg.encryptionPublicKey, "0x" + bytesToHex(msg.ethAddress))
buildMsgParams(
msg.encryptionPublicKey,
"0x" + utils.bytesToHex(msg.ethAddress)
)
),
sig: "0x" + bytesToHex(msg.signature),
sig: "0x" + utils.bytesToHex(msg.signature),
});
console.log("Recovered", recovered);
console.log("ethAddress", "0x" + bytesToHex(msg.ethAddress));
console.log("ethAddress", "0x" + utils.bytesToHex(msg.ethAddress));
return equals(hexToBytes(recovered), msg.ethAddress);
return equals(utils.hexToBytes(recovered), msg.ethAddress);
}

View File

@ -1,5 +1,5 @@
import { KeyPair } from "../crypto";
import { bytesToHex, hexToBytes } from "js-waku/lib/utils";
import { utils } from "js-waku";
/**
* Save keypair to storage, encrypted with password
@ -11,9 +11,9 @@ export async function saveKeyPairToStorage(
const { salt, iv, cipher } = await encryptKey(EncryptionKeyPair, password);
const data = {
salt: bytesToHex(salt),
iv: bytesToHex(iv),
cipher: bytesToHex(cipher),
salt: utils.bytesToHex(salt),
iv: utils.bytesToHex(iv),
cipher: utils.bytesToHex(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 = hexToBytes(data.salt);
const iv = hexToBytes(data.iv);
const cipher = hexToBytes(data.cipher);
const salt = utils.hexToBytes(data.salt);
const iv = utils.hexToBytes(data.iv);
const cipher = utils.hexToBytes(data.cipher);
return await decryptKey(salt, iv, cipher, password);
}

View File

@ -7,8 +7,7 @@ import {
TextField,
} from "@material-ui/core";
import React, { ChangeEvent, useState, KeyboardEvent } from "react";
import { Waku, WakuMessage } from "js-waku";
import { hexToBytes } from "js-waku/lib/utils";
import { utils, Waku, WakuMessage } from "js-waku";
import { PrivateMessage } from "./wire";
import { PrivateMessageContentTopic } from "../waku";
@ -110,7 +109,7 @@ async function encodeEncryptedWakuMessage(
address: string
): Promise<WakuMessage> {
const privateMessage = new PrivateMessage({
toAddress: hexToBytes(address),
toAddress: utils.hexToBytes(address),
message: message,
});

View File

@ -1,9 +1,8 @@
import { Dispatch, SetStateAction } from "react";
import { Waku, WakuMessage } from "js-waku";
import { utils, Waku, WakuMessage } from "js-waku";
import { PrivateMessage, PublicKeyMessage } from "./messaging/wire";
import { validatePublicKeyMessage } from "./crypto";
import { Message } from "./messaging/Messages";
import { bytesToHex, hexToBytes } from "js-waku/lib/utils";
import { equals } from "uint8arrays/equals";
export const PublicKeyContentTopic = "/eth-pm/1/public-key/proto";
@ -35,7 +34,7 @@ export function handlePublicKeyMessage(
if (!msg.payload) return;
const publicKeyMsg = PublicKeyMessage.decode(msg.payload);
if (!publicKeyMsg) return;
if (myAddress && equals(publicKeyMsg.ethAddress, hexToBytes(myAddress)))
if (myAddress && equals(publicKeyMsg.ethAddress, utils.hexToBytes(myAddress)))
return;
const res = validatePublicKeyMessage(publicKeyMsg);
@ -44,7 +43,7 @@ export function handlePublicKeyMessage(
if (res) {
setter((prevPks: Map<string, Uint8Array>) => {
prevPks.set(
bytesToHex(publicKeyMsg.ethAddress),
utils.bytesToHex(publicKeyMsg.ethAddress),
publicKeyMsg.encryptionPublicKey
);
return new Map(prevPks);
@ -64,7 +63,7 @@ export async function handlePrivateMessage(
console.log("Failed to decode Private Message");
return;
}
if (!equals(privateMessage.toAddress, hexToBytes(address))) return;
if (!equals(privateMessage.toAddress, utils.hexToBytes(address))) return;
const timestamp = wakuMsg.timestamp ? wakuMsg.timestamp : new Date();

View File

@ -1,12 +1,14 @@
{
"name": "@waku/relay-angular-chat",
"version": "0.1.0",
"homepage": "/examples/relay-angular-chat",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
"test": "ng test",
"test-ci": "ng test --watch=false"
},
"private": true,
"dependencies": {
@ -19,7 +21,7 @@
"@angular/platform-browser-dynamic": "~13.2.0",
"@angular/router": "~13.2.0",
"crypto-browserify": "^3.12.0",
"js-waku": "file:../../build/esm",
"js-waku": "^0.19.2",
"protons": "^2.0.3",
"rxjs": "~7.5.0",
"stream-browserify": "^3.0.0",
@ -31,7 +33,7 @@
"@angular/cli": "~13.2.2",
"@angular/compiler-cli": "~13.2.0",
"@types/bl": "^5.0.2",
"@types/jasmine": "~4.0.0",
"@types/jasmine": "~3.10.0",
"@types/node": "^17.0.21",
"jasmine-core": "~4.0.0",
"karma": "~6.3.0",

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,7 @@
"@testing-library/react": "^12.1.2",
"@testing-library/user-event": "^14.0.4",
"it-pipe": "^2.0.3",
"js-waku": "file:../../",
"js-waku": "^0.19.2",
"protobufjs": "^6.11.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,7 @@
"assert": "^2.0.0",
"buffer": "^6.0.3",
"crypto-browserify": "^3.12.0",
"js-waku": "file:../../build/esm",
"js-waku": "^0.19.2",
"protons": "^2.0.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",

View File

@ -6,9 +6,14 @@ module.exports = {
if (!config.resolve) config.resolve = {};
if (!config.resolve.fallback) config.resolve.fallback = {};
Object.assign(config.resolve.fallback, {
assert: require.resolve("assert"),
buffer: require.resolve("buffer"),
crypto: require.resolve("crypto-browserify"),
http: require.resolve("http-browserify"),
https: require.resolve("https-browserify"),
stream: require.resolve("stream-browserify"),
url: require.resolve("url"),
zlib: require.resolve("browserify-zlib"),
});
if (!config.plugins) config.plugins = [];
@ -34,9 +39,14 @@ module.exports = {
if (!config.resolve) config.resolve = {};
if (!config.resolve.fallback) config.resolve.fallback = {};
Object.assign(config.resolve.fallback, {
assert: require.resolve("assert"),
buffer: require.resolve("buffer"),
crypto: require.resolve("crypto-browserify"),
http: require.resolve("http-browserify"),
https: require.resolve("https-browserify"),
stream: require.resolve("stream-browserify"),
url: require.resolve("url"),
zlib: require.resolve("browserify-zlib"),
});
if (!config.plugins) config.plugins = [];

File diff suppressed because it is too large Load Diff

View File

@ -5,9 +5,12 @@
"homepage": "/examples/web-chat",
"dependencies": {
"@livechat/ui-kit": "^0.5.0-20",
"browserify-zlib": "^0.2.0",
"buffer": "^6.0.3",
"crypto-browserify": "^3.12.0",
"js-waku": "file:../../build/main",
"http-browserify": "^1.7.0",
"https-browserify": "^1.0.0",
"js-waku": "^0.19.2",
"process": "^0.11.10",
"react": "^17.0.2",
"react-dom": "^17.0.2",
@ -22,13 +25,15 @@
"@types/node": "^17.0.17",
"@types/react": "^18.0.2",
"@types/react-dom": "^18.0.0",
"assert": "^2.0.0",
"cra-webpack-rewired": "^1.0.1",
"cspell": "^5.18.4",
"gh-pages": "^3.2.3",
"npm-run-all": "^4.1.5",
"prettier": "^2.5.1",
"react-scripts": "5.0.0",
"typescript": "^4.5.5"
"typescript": "^4.5.5",
"url": "^0.11.0"
},
"scripts": {
"start": "cra-webpack-rewired start",

View File

@ -1,8 +1,9 @@
import { useEffect, useReducer, useState } from "react";
import "./App.css";
import {
PageDirection,
discovery,
getPredefinedBootstrapNodes,
PageDirection,
Waku,
WakuMessage,
} from "js-waku";
@ -12,7 +13,6 @@ import { WakuContext } from "./WakuContext";
import { ThemeProvider } from "@livechat/ui-kit";
import { generate } from "server-name-generator";
import { Message } from "./Message";
import { Fleet } from "js-waku/lib/discovery/predefined";
const themes = {
AuthorName: {
@ -198,9 +198,9 @@ async function initWaku(setter: (waku: Waku) => void) {
function selectFleetEnv() {
// Works with react-scripts
if (process?.env?.NODE_ENV === "development") {
return Fleet.Test;
return discovery.predefined.Fleet.Test;
} else {
return Fleet.Prod;
return discovery.predefined.Fleet.Prod;
}
}