chore(eth-pm): bump @waku/*

This commit is contained in:
fryorcraken.eth 2022-11-04 16:38:22 +11:00
parent acd5386cd2
commit cbab4aa471
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
9 changed files with 490 additions and 326 deletions

View File

@ -10,7 +10,11 @@
"@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",

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();