chore(eth-pm): bump @waku/*
This commit is contained in:
parent
acd5386cd2
commit
cbab4aa471
|
@ -10,7 +10,11 @@
|
||||||
"@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",
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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";
|
||||||
|
|
|
@ -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";
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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";
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue