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