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", "$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json",
"language": "en", "language": "en",
"words": [ "words": [
"asym",
"backoff", "backoff",
"backoffs", "backoffs",
"bitjson", "bitjson",

View File

@ -10,7 +10,7 @@
"@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.28.1", "js-waku": "0.29.0",
"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",

View File

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

View File

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

View File

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

View File

@ -7,8 +7,9 @@ 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, WakuMessage } from "js-waku"; import { utils } from "js-waku";
import type { WakuLight } from "js-waku/lib/interfaces"; import type { WakuLight } from "js-waku/lib/interfaces";
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";
@ -104,45 +105,26 @@ export default function SendMessage({ waku, recipients }: Props) {
); );
} }
async function encodeEncryptedWakuMessage( async function sendMessage(
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(
waku: WakuLight, waku: WakuLight,
recipientAddress: string, recipientAddress: string,
recipientPublicKey: Uint8Array, recipientPublicKey: Uint8Array,
message: string, message: string,
callback: (res: boolean) => void callback: (res: boolean) => void
) { ) {
encodeEncryptedWakuMessage(message, recipientPublicKey, recipientAddress) const privateMessage = new PrivateMessage({
.then((msg) => { toAddress: utils.hexToBytes(recipientAddress),
message: message,
});
const payload = privateMessage.encode();
const encoder = new AsymEncoder(
PrivateMessageContentTopic,
recipientPublicKey
);
console.log("pushing"); console.log("pushing");
waku.lightPush const res = await waku.lightPush.push(encoder, { payload });
.push(msg)
.then((res) => {
console.log("Message sent", res); console.log("Message sent", res);
callback(res?.isSuccess ?? false); callback(Boolean(res.recipients.length));
})
.catch((e) => {
console.error("Failed to send message", e);
callback(false);
});
})
.catch((e) => {
console.error("Cannot encode & encrypt message", e);
callback(false);
});
} }

View File

@ -1,6 +1,6 @@
import { Dispatch, SetStateAction } from "react"; import { Dispatch, SetStateAction } from "react";
import { Protocols, utils, WakuMessage } from "js-waku"; import { Protocols, utils } from "js-waku";
import type { WakuLight } from "js-waku/lib/interfaces"; import type { WakuLight, Message as WakuMessage } 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";