mirror of https://github.com/waku-org/js-waku.git
Do not attempt to decrypt other's messages
This commit is contained in:
parent
6921242877
commit
5661c7d1ec
|
@ -26,6 +26,7 @@ function App() {
|
|||
const [publicKeyMsg, setPublicKeyMsg] = useState<PublicKeyMessage>();
|
||||
const [publicKeys, setPublicKeys] = useState<Map<string, string>>(new Map());
|
||||
const [messages, setMessages] = useState<Message[]>([]);
|
||||
const [address, setAddress] = useState<string>();
|
||||
|
||||
useEffect(() => {
|
||||
if (provider) return;
|
||||
|
@ -38,6 +39,13 @@ function App() {
|
|||
}
|
||||
}, [provider]);
|
||||
|
||||
useEffect(() => {
|
||||
provider
|
||||
?.getSigner()
|
||||
.getAddress()
|
||||
.then((address) => setAddress(address));
|
||||
});
|
||||
|
||||
const broadcastPublicKey = () => {
|
||||
if (!ethDmKeyPair) return;
|
||||
if (!provider) return;
|
||||
|
@ -72,6 +80,7 @@ function App() {
|
|||
setPublicKeys={setPublicKeys}
|
||||
setWaku={setWaku}
|
||||
waku={waku}
|
||||
address={address}
|
||||
/>
|
||||
<KeyPairHandling
|
||||
ethDmKeyPair={ethDmKeyPair}
|
||||
|
|
|
@ -11,6 +11,7 @@ interface Props {
|
|||
ethDmKeyPair: KeyPair | undefined;
|
||||
setPublicKeys: Dispatch<SetStateAction<Map<string, string>>>;
|
||||
setMessages: Dispatch<SetStateAction<Message[]>>;
|
||||
address: string | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,6 +23,7 @@ export default function InitWaku({
|
|||
ethDmKeyPair,
|
||||
setPublicKeys,
|
||||
setMessages,
|
||||
address,
|
||||
}: Props) {
|
||||
useEffect(() => {
|
||||
if (waku) return;
|
||||
|
@ -41,9 +43,15 @@ export default function InitWaku({
|
|||
setPublicKeys
|
||||
);
|
||||
|
||||
const observerDirectMessage = ethDmKeyPair
|
||||
? handleDirectMessage.bind({}, setMessages, ethDmKeyPair.privateKey)
|
||||
: undefined;
|
||||
const observerDirectMessage =
|
||||
ethDmKeyPair && address
|
||||
? handleDirectMessage.bind(
|
||||
{},
|
||||
setMessages,
|
||||
ethDmKeyPair.privateKey,
|
||||
address
|
||||
)
|
||||
: undefined;
|
||||
|
||||
useEffect(() => {
|
||||
if (!waku) return;
|
||||
|
@ -116,11 +124,14 @@ function handlePublicKeyMessage(
|
|||
async function handleDirectMessage(
|
||||
setter: Dispatch<SetStateAction<Message[]>>,
|
||||
privateKey: string,
|
||||
address: string,
|
||||
wakuMsg: WakuMessage
|
||||
) {
|
||||
console.log('Waku Message received:', wakuMsg);
|
||||
if (!wakuMsg.payload) return;
|
||||
const directMessage: DirectMessage = decode(wakuMsg.payload);
|
||||
if (directMessage.toAddress !== address) return;
|
||||
|
||||
const text = await decryptMessage(privateKey, directMessage);
|
||||
|
||||
const timestamp = wakuMsg.timestamp ? wakuMsg.timestamp : new Date();
|
||||
|
|
|
@ -8,7 +8,6 @@ import { DirectMessage, PublicKeyMessage } from './messages';
|
|||
export interface KeyPair {
|
||||
privateKey: string;
|
||||
publicKey: string;
|
||||
address: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue