chore(eth-pm): bump js-waku to 0.29.0

This commit is contained in:
fryorcraken.eth 2022-09-20 14:21:52 +10:00
parent 875cbbc16f
commit ba919b3a53
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
8 changed files with 120 additions and 175 deletions

View File

@ -3,6 +3,7 @@
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json",
"language": "en",
"words": [
"asym",
"backoff",
"backoffs",
"bitjson",

View File

@ -10,7 +10,7 @@
"@material-ui/icons": "^4.11.2",
"ethers": "5.7.1",
"fontsource-roboto": "^4.0.0",
"js-waku": "0.28.1",
"js-waku": "0.29.0",
"protobufjs": "^7.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",

View File

@ -14,7 +14,7 @@ specifiers:
eslint: ^8.9.0
ethers: 5.7.1
fontsource-roboto: ^4.0.0
js-waku: 0.28.1
js-waku: 0.29.0
npm-run-all: ^4.1.5
prettier: ^2.5.1
protobufjs: ^7.1.0
@ -27,14 +27,14 @@ specifiers:
dependencies:
'@ethersproject/abstract-signer': 5.7.0
'@ethersproject/providers': 5.7.0
'@material-ui/core': 4.12.4_x6vcehmdzjj6pm7ndhhuigqb3i
'@material-ui/icons': 4.11.3_3v7i52wmmfi3wwfybpvt6ex6wq
'@material-ui/core': 4.12.4_zxljzmqdrxwnuenbkrz77w74uy
'@material-ui/icons': 4.11.3_upnjamd3tbaukgopcqqdlc7jbm
ethers: 5.7.1
fontsource-roboto: 4.0.0
js-waku: 0.28.1_undici@5.10.0
js-waku: 0.29.0_undici@5.10.0
protobufjs: 7.1.0
react: 17.0.2
react-dom: 17.0.2_react@17.0.2
react: 18.2.0
react-dom: 18.2.0_react@18.2.0
uint8arrays: 3.1.0
devDependencies:
@ -47,7 +47,7 @@ devDependencies:
eslint: 8.21.0
npm-run-all: 4.1.5
prettier: 2.7.1
react-scripts: 5.0.1_eqoi5id72ccwlxlz5mj7wjr7gu
react-scripts: 5.0.1_zqc2lflk57y5fs7vjdkkfoejyi
typescript: 4.8.2
packages:
@ -3284,7 +3284,7 @@ packages:
- utf-8-validate
dev: false
/@material-ui/core/4.12.4_x6vcehmdzjj6pm7ndhhuigqb3i:
/@material-ui/core/4.12.4_zxljzmqdrxwnuenbkrz77w74uy:
resolution: {integrity: sha512-tr7xekNlM9LjA6pagJmL8QCgZXaubWUwkJnoYcMKd4gw/t4XiyvnTkjdGrUVicyB2BsdaAv1tvow45bPM4sSwQ==}
engines: {node: '>=8.0.0'}
peerDependencies:
@ -3296,23 +3296,23 @@ packages:
optional: true
dependencies:
'@babel/runtime': 7.18.9
'@material-ui/styles': 4.11.5_x6vcehmdzjj6pm7ndhhuigqb3i
'@material-ui/system': 4.12.2_x6vcehmdzjj6pm7ndhhuigqb3i
'@material-ui/styles': 4.11.5_zxljzmqdrxwnuenbkrz77w74uy
'@material-ui/system': 4.12.2_zxljzmqdrxwnuenbkrz77w74uy
'@material-ui/types': 5.1.0_@types+react@18.0.17
'@material-ui/utils': 4.11.3_sfoxds7t5ydpegc3knd667wn6m
'@material-ui/utils': 4.11.3_biqbaboplfbrettd7655fr4n2y
'@types/react': 18.0.17
'@types/react-transition-group': 4.4.5
clsx: 1.2.1
hoist-non-react-statics: 3.3.2
popper.js: 1.16.1-lts
prop-types: 15.8.1
react: 17.0.2
react-dom: 17.0.2_react@17.0.2
react: 18.2.0
react-dom: 18.2.0_react@18.2.0
react-is: 17.0.2
react-transition-group: 4.4.5_sfoxds7t5ydpegc3knd667wn6m
react-transition-group: 4.4.5_biqbaboplfbrettd7655fr4n2y
dev: false
/@material-ui/icons/4.11.3_3v7i52wmmfi3wwfybpvt6ex6wq:
/@material-ui/icons/4.11.3_upnjamd3tbaukgopcqqdlc7jbm:
resolution: {integrity: sha512-IKHlyx6LDh8n19vzwH5RtHIOHl9Tu90aAAxcbWME6kp4dmvODM3UvOHJeMIDzUbd4muuJKHmlNoBN+mDY4XkBA==}
engines: {node: '>=8.0.0'}
peerDependencies:
@ -3325,13 +3325,13 @@ packages:
optional: true
dependencies:
'@babel/runtime': 7.18.9
'@material-ui/core': 4.12.4_x6vcehmdzjj6pm7ndhhuigqb3i
'@material-ui/core': 4.12.4_zxljzmqdrxwnuenbkrz77w74uy
'@types/react': 18.0.17
react: 17.0.2
react-dom: 17.0.2_react@17.0.2
react: 18.2.0
react-dom: 18.2.0_react@18.2.0
dev: false
/@material-ui/styles/4.11.5_x6vcehmdzjj6pm7ndhhuigqb3i:
/@material-ui/styles/4.11.5_zxljzmqdrxwnuenbkrz77w74uy:
resolution: {integrity: sha512-o/41ot5JJiUsIETME9wVLAJrmIWL3j0R0Bj2kCOLbSfqEkKf0fmaPt+5vtblUh5eXr2S+J/8J3DaCb10+CzPGA==}
engines: {node: '>=8.0.0'}
peerDependencies:
@ -3345,7 +3345,7 @@ packages:
'@babel/runtime': 7.18.9
'@emotion/hash': 0.8.0
'@material-ui/types': 5.1.0_@types+react@18.0.17
'@material-ui/utils': 4.11.3_sfoxds7t5ydpegc3knd667wn6m
'@material-ui/utils': 4.11.3_biqbaboplfbrettd7655fr4n2y
'@types/react': 18.0.17
clsx: 1.2.1
csstype: 2.6.20
@ -3359,11 +3359,11 @@ packages:
jss-plugin-rule-value-function: 10.9.2
jss-plugin-vendor-prefixer: 10.9.2
prop-types: 15.8.1
react: 17.0.2
react-dom: 17.0.2_react@17.0.2
react: 18.2.0
react-dom: 18.2.0_react@18.2.0
dev: false
/@material-ui/system/4.12.2_x6vcehmdzjj6pm7ndhhuigqb3i:
/@material-ui/system/4.12.2_zxljzmqdrxwnuenbkrz77w74uy:
resolution: {integrity: sha512-6CSKu2MtmiJgcCGf6nBQpM8fLkuB9F55EKfbdTC80NND5wpTmKzwdhLYLH3zL4cLlK0gVaaltW7/wMuyTnN0Lw==}
engines: {node: '>=8.0.0'}
peerDependencies:
@ -3375,12 +3375,12 @@ packages:
optional: true
dependencies:
'@babel/runtime': 7.18.9
'@material-ui/utils': 4.11.3_sfoxds7t5ydpegc3knd667wn6m
'@material-ui/utils': 4.11.3_biqbaboplfbrettd7655fr4n2y
'@types/react': 18.0.17
csstype: 2.6.20
prop-types: 15.8.1
react: 17.0.2
react-dom: 17.0.2_react@17.0.2
react: 18.2.0
react-dom: 18.2.0_react@18.2.0
dev: false
/@material-ui/types/5.1.0_@types+react@18.0.17:
@ -3394,7 +3394,7 @@ packages:
'@types/react': 18.0.17
dev: false
/@material-ui/utils/4.11.3_sfoxds7t5ydpegc3knd667wn6m:
/@material-ui/utils/4.11.3_biqbaboplfbrettd7655fr4n2y:
resolution: {integrity: sha512-ZuQPV4rBK/V1j2dIkSSEcH5uT6AaHuKWFfotADHsC0wVL1NLd2WkFCm4ZZbX33iO4ydl6V0GPngKm8HZQ2oujg==}
engines: {node: '>=8.0.0'}
peerDependencies:
@ -3403,8 +3403,8 @@ packages:
dependencies:
'@babel/runtime': 7.18.9
prop-types: 15.8.1
react: 17.0.2
react-dom: 17.0.2_react@17.0.2
react: 18.2.0
react-dom: 18.2.0_react@18.2.0
react-is: 17.0.2
dev: false
@ -8487,8 +8487,8 @@ packages:
/js-tokens/4.0.0:
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
/js-waku/0.28.1_undici@5.10.0:
resolution: {integrity: sha512-0h9TpV6jywyjdes8hr9tFV/5iJh3LQN3sQFYHcXyi4cK+4htNiMrCRjBSqRBtfhs/j+4tOkrht8gRJRLHdA5RA==}
/js-waku/0.29.0_undici@5.10.0:
resolution: {integrity: sha512-44GOpNbkFt/1/bDZ3tcaeemehaZaxw404QmTvHw7FUwY6dtvGsDEERLEw1TERUljDESFjvEOcJjYnLcNDY1MHg==}
engines: {node: '>=16'}
dependencies:
'@chainsafe/libp2p-gossipsub': 4.1.1_undici@5.10.0
@ -10735,15 +10735,14 @@ packages:
- vue-template-compiler
dev: true
/react-dom/17.0.2_react@17.0.2:
resolution: {integrity: sha512-s4h96KtLDUQlsENhMn1ar8t2bEa+q/YAtj8pPPdIjPDGBDIVNsrD9aXNWqspUe6AzKCIG0C1HZZLqLV7qpOBGA==}
/react-dom/18.2.0_react@18.2.0:
resolution: {integrity: sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==}
peerDependencies:
react: 17.0.2
react: ^18.2.0
dependencies:
loose-envify: 1.4.0
object-assign: 4.1.1
react: 17.0.2
scheduler: 0.20.2
react: 18.2.0
scheduler: 0.23.0
dev: false
/react-error-overlay/6.0.11:
@ -10765,7 +10764,7 @@ packages:
engines: {node: '>=0.10.0'}
dev: true
/react-scripts/5.0.1_eqoi5id72ccwlxlz5mj7wjr7gu:
/react-scripts/5.0.1_zqc2lflk57y5fs7vjdkkfoejyi:
resolution: {integrity: sha512-8VAmEm/ZAwQzJ+GOMLbBsTdDKOpuZh7RPs0UymvBR2vRk4iZWCskjbFnxqjrzoIvlNNRZ3QJFx6/qDSi6zSnaQ==}
engines: {node: '>=14.0.0'}
hasBin: true
@ -10809,7 +10808,7 @@ packages:
postcss-normalize: 10.0.1_mu2kzpkteq3ketk6piffleamkq
postcss-preset-env: 7.7.2_postcss@8.4.16
prompts: 2.4.2
react: 17.0.2
react: 18.2.0
react-app-polyfill: 3.0.0
react-dev-utils: 12.0.1_6powqha3uet7brcqpdvamgrsxu
react-refresh: 0.11.0
@ -10862,7 +10861,7 @@ packages:
- webpack-plugin-serve
dev: true
/react-transition-group/4.4.5_sfoxds7t5ydpegc3knd667wn6m:
/react-transition-group/4.4.5_biqbaboplfbrettd7655fr4n2y:
resolution: {integrity: sha512-pZcd1MCJoiKiBR2NRxeCRg13uCXbydPnmB4EOeRrY7480qNWO8IIgQG6zlDkm6uRMsURXPuKq0GWtiM59a5Q6g==}
peerDependencies:
react: '>=16.6.0'
@ -10872,16 +10871,15 @@ packages:
dom-helpers: 5.2.1
loose-envify: 1.4.0
prop-types: 15.8.1
react: 17.0.2
react-dom: 17.0.2_react@17.0.2
react: 18.2.0
react-dom: 18.2.0_react@18.2.0
dev: false
/react/17.0.2:
resolution: {integrity: sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA==}
/react/18.2.0:
resolution: {integrity: sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==}
engines: {node: '>=0.10.0'}
dependencies:
loose-envify: 1.4.0
object-assign: 4.1.1
/read-cache/1.0.0:
resolution: {integrity: sha512-Owdv/Ft7IjOgm/i0xvNDZ1LrRANRfew4b2prF3OWMQLxLfu3bS8FVhCsrSCMK4lR56Y9ya+AThoTpDCTxCmpRA==}
@ -11202,11 +11200,10 @@ packages:
xmlchars: 2.2.0
dev: true
/scheduler/0.20.2:
resolution: {integrity: sha512-2eWfGgAqqWFGqtdMmcL5zCMK1U8KlXv8SQFGglL3CEtd0aDVDWgeF/YoCmvln55m5zSk3J/20hTaSBeSObsQDQ==}
/scheduler/0.23.0:
resolution: {integrity: sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw==}
dependencies:
loose-envify: 1.4.0
object-assign: 4.1.1
dev: false
/schema-utils/2.7.0:

View File

@ -3,6 +3,7 @@ import "@ethersproject/shims";
import React, { useEffect, useState } from "react";
import "./App.css";
import type { WakuLight } from "js-waku/lib/interfaces";
import { AsymDecoder, SymDecoder } from "js-waku/lib/waku_message/version_1";
import { KeyPair, PublicKeyMessageEncryptionKey } from "./crypto";
import { Message } from "./messaging/Messages";
import "fontsource-roboto";
@ -26,7 +27,6 @@ import {
} from "./waku";
import { Web3Provider } from "@ethersproject/providers/src.ts/web3-provider";
import ConnectWallet from "./ConnectWallet";
import { waku_message } from "js-waku";
const theme = createMuiTheme({
palette: {
@ -72,6 +72,8 @@ function App() {
const [encryptionKeyPair, setEncryptionKeyPair] = useState<
KeyPair | undefined
>();
const [privateMessageDecoder, setPrivateMessageDecoder] =
useState<AsymDecoder>();
const [publicKeys, setPublicKeys] = useState<Map<string, Uint8Array>>(
new Map()
);
@ -109,14 +111,15 @@ function App() {
setPublicKeys
);
const publicKeyMessageDecoder = new SymDecoder(
PublicKeyContentTopic,
PublicKeyMessageEncryptionKey
);
let unsubscribe: undefined | (() => Promise<void>);
waku.filter.addDecryptionKey(PublicKeyMessageEncryptionKey, {
method: waku_message.DecryptionMethod.Symmetric,
contentTopics: [PublicKeyContentTopic],
});
waku.filter
.subscribe(observerPublicKeyMessage, [PublicKeyContentTopic])
.subscribe([publicKeyMessageDecoder], observerPublicKeyMessage)
.then(
(_unsubscribe) => {
console.log("subscribed to ", PublicKeyContentTopic);
@ -128,9 +131,8 @@ function App() {
);
return function cleanUp() {
if (!waku) return;
waku.filter.deleteDecryptionKey(PublicKeyMessageEncryptionKey);
if (typeof unsubscribe === "undefined") return;
unsubscribe().then(
() => {
console.log("unsubscribed to ", PublicKeyContentTopic);
@ -141,25 +143,16 @@ function App() {
}, [waku, address]);
useEffect(() => {
if (!waku) return;
if (!encryptionKeyPair) return;
waku.filter.addDecryptionKey(encryptionKeyPair.privateKey, {
method: waku_message.DecryptionMethod.Asymmetric,
contentTopics: [PrivateMessageContentTopic],
});
return function cleanUp() {
if (!waku) return;
if (!encryptionKeyPair) return;
waku.filter.deleteDecryptionKey(encryptionKeyPair.privateKey);
};
}, [waku, encryptionKeyPair]);
setPrivateMessageDecoder(
new AsymDecoder(PrivateMessageContentTopic, encryptionKeyPair.privateKey)
);
}, [encryptionKeyPair]);
useEffect(() => {
if (!waku) return;
if (!encryptionKeyPair) return;
if (!privateMessageDecoder) return;
if (!address) return;
const observerPrivateMessage = handlePrivateMessage.bind(
@ -170,23 +163,20 @@ function App() {
let unsubscribe: undefined | (() => Promise<void>);
waku.filter
.subscribe(observerPrivateMessage, [PrivateMessageContentTopic])
.then(
(_unsubscribe) => {
unsubscribe = _unsubscribe;
},
(e) => {
console.error("Failed to subscribe", e);
}
);
waku.filter.subscribe([privateMessageDecoder], observerPrivateMessage).then(
(_unsubscribe) => {
unsubscribe = _unsubscribe;
},
(e) => {
console.error("Failed to subscribe", e);
}
);
return function cleanUp() {
if (!waku) return;
if (typeof unsubscribe === "undefined") return;
unsubscribe().catch((e) => console.error("Failed to unsubscribe", e));
};
}, [waku, address, encryptionKeyPair]);
}, [waku, address, privateMessageDecoder]);
useEffect(() => {
if (!waku) return;
@ -252,7 +242,7 @@ function App() {
/>
<BroadcastPublicKey
address={address}
EncryptionKeyPair={encryptionKeyPair}
encryptionKeyPair={encryptionKeyPair}
waku={waku}
signer={provider?.getSigner()}
/>

View File

@ -6,66 +6,53 @@ import {
PublicKeyMessageEncryptionKey,
} from "./crypto";
import { PublicKeyMessage } from "./messaging/wire";
import { WakuMessage } from "js-waku";
import { WakuLight } from "js-waku/lib/interfaces";
import type { WakuLight } from "js-waku/lib/interfaces";
import { SymEncoder } from "js-waku/lib/waku_message/version_1";
import { PublicKeyContentTopic } from "./waku";
import type { TypedDataSigner } from "@ethersproject/abstract-signer";
interface Props {
EncryptionKeyPair: KeyPair | undefined;
encryptionKeyPair: KeyPair | undefined;
waku: WakuLight | undefined;
address: string | undefined;
signer: TypedDataSigner | undefined;
}
export default function BroadcastPublicKey({
EncryptionKeyPair,
encryptionKeyPair,
waku,
address,
signer,
}: Props) {
const [publicKeyMsg, setPublicKeyMsg] = useState<PublicKeyMessage>();
const broadcastPublicKey = () => {
if (!EncryptionKeyPair) return;
const broadcastPublicKey = async () => {
if (!encryptionKeyPair) return;
if (!address) return;
if (!waku) return;
if (!signer) return;
if (publicKeyMsg) {
encodePublicKeyWakuMessage(publicKeyMsg)
.then((wakuMsg) => {
waku.lightPush.push(wakuMsg).catch((e) => {
console.error("Failed to send Public Key Message", e);
});
})
.catch((e) => {
console.log("Failed to encode Public Key Message in Waku Message", e);
});
} else {
createPublicKeyMessage(address, EncryptionKeyPair.publicKey, signer)
.then((msg) => {
setPublicKeyMsg(msg);
encodePublicKeyWakuMessage(msg)
.then((wakuMsg) => {
waku.lightPush
.push(wakuMsg)
.then((res) => console.log("Public Key Message pushed", res))
.catch((e) => {
console.error("Failed to send Public Key Message", e);
});
})
.catch((e) => {
console.log(
"Failed to encode Public Key Message in Waku Message",
e
);
});
})
.catch((e) => {
console.error("Failed to create public key message", e);
});
}
const _publicKeyMessage = await (async () => {
if (!publicKeyMsg) {
const pkm = await createPublicKeyMessage(
address,
encryptionKeyPair.publicKey,
signer
);
setPublicKeyMsg(pkm);
return pkm;
}
return publicKeyMsg;
})();
const payload = _publicKeyMessage.encode();
const publicKeyMessageEncoder = new SymEncoder(
PublicKeyContentTopic,
PublicKeyMessageEncryptionKey
);
waku.lightPush.push(publicKeyMessageEncoder, { payload });
};
return (
@ -73,18 +60,9 @@ export default function BroadcastPublicKey({
variant="contained"
color="primary"
onClick={broadcastPublicKey}
disabled={!EncryptionKeyPair || !waku || !address || !signer}
disabled={!encryptionKeyPair || !waku || !address || !signer}
>
Broadcast Encryption Public Key
</Button>
);
}
async function encodePublicKeyWakuMessage(
publicKeyMessage: PublicKeyMessage
): Promise<WakuMessage> {
const payload = publicKeyMessage.encode();
return await WakuMessage.fromBytes(payload, PublicKeyContentTopic, {
symKey: PublicKeyMessageEncryptionKey,
});
}

View File

@ -41,9 +41,6 @@ export async function createPublicKeyMessage(
signer
);
console.log("Asking wallet to sign Public Key Message");
console.log("Public Key Message signed");
return new PublicKeyMessage({
encryptionPublicKey: encryptionPublicKey,
ethAddress: utils.hexToBytes(address),

View File

@ -7,8 +7,9 @@ import {
TextField,
} from "@material-ui/core";
import React, { ChangeEvent, useState, KeyboardEvent } from "react";
import { utils, WakuMessage } from "js-waku";
import { utils } from "js-waku";
import type { WakuLight } from "js-waku/lib/interfaces";
import { AsymEncoder } from "js-waku/lib/waku_message/version_1";
import { PrivateMessage } from "./wire";
import { PrivateMessageContentTopic } from "../waku";
@ -104,45 +105,26 @@ export default function SendMessage({ waku, recipients }: Props) {
);
}
async function encodeEncryptedWakuMessage(
message: string,
publicKey: Uint8Array,
address: string
): Promise<WakuMessage> {
const privateMessage = new PrivateMessage({
toAddress: utils.hexToBytes(address),
message: message,
});
const payload = privateMessage.encode();
return WakuMessage.fromBytes(payload, PrivateMessageContentTopic, {
encPublicKey: publicKey,
});
}
function sendMessage(
async function sendMessage(
waku: WakuLight,
recipientAddress: string,
recipientPublicKey: Uint8Array,
message: string,
callback: (res: boolean) => void
) {
encodeEncryptedWakuMessage(message, recipientPublicKey, recipientAddress)
.then((msg) => {
console.log("pushing");
waku.lightPush
.push(msg)
.then((res) => {
console.log("Message sent", res);
callback(res?.isSuccess ?? false);
})
.catch((e) => {
console.error("Failed to send message", e);
callback(false);
});
})
.catch((e) => {
console.error("Cannot encode & encrypt message", e);
callback(false);
});
const privateMessage = new PrivateMessage({
toAddress: utils.hexToBytes(recipientAddress),
message: message,
});
const payload = privateMessage.encode();
const encoder = new AsymEncoder(
PrivateMessageContentTopic,
recipientPublicKey
);
console.log("pushing");
const res = await waku.lightPush.push(encoder, { payload });
console.log("Message sent", res);
callback(Boolean(res.recipients.length));
}

View File

@ -1,6 +1,6 @@
import { Dispatch, SetStateAction } from "react";
import { Protocols, utils, WakuMessage } from "js-waku";
import type { WakuLight } from "js-waku/lib/interfaces";
import { Protocols, utils } from "js-waku";
import type { WakuLight, Message as WakuMessage } from "js-waku/lib/interfaces";
import { PrivateMessage, PublicKeyMessage } from "./messaging/wire";
import { validatePublicKeyMessage } from "./crypto";
import { Message } from "./messaging/Messages";