From f9174cd3d2161deb80aec39f9a6058ce630539ce Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Fri, 2 Jul 2021 10:52:35 +1000 Subject: [PATCH] Do not process Public Key Message if field is missing --- examples/eth-dm/src/InitWaku.tsx | 1 + examples/eth-dm/src/messaging/wire.ts | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/eth-dm/src/InitWaku.tsx b/examples/eth-dm/src/InitWaku.tsx index a1c5b07708..3ef45e0c76 100644 --- a/examples/eth-dm/src/InitWaku.tsx +++ b/examples/eth-dm/src/InitWaku.tsx @@ -121,6 +121,7 @@ function handlePublicKeyMessage( ) { if (!msg.payload) return; const publicKeyMsg = PublicKeyMessage.decode(msg.payload); + if (!publicKeyMsg) return; const ethDmPublicKey = bytesToHexStr(publicKeyMsg.ethDmPublicKey); if (ethDmPublicKey === myPublicKey) return; diff --git a/examples/eth-dm/src/messaging/wire.ts b/examples/eth-dm/src/messaging/wire.ts index 803bc04b1c..da5dbe52a2 100644 --- a/examples/eth-dm/src/messaging/wire.ts +++ b/examples/eth-dm/src/messaging/wire.ts @@ -30,10 +30,16 @@ export class PublicKeyMessage { return PublicKeyMessage.Type.encode(message).finish(); } - public static decode(bytes: Uint8Array | Buffer): PublicKeyMessage { + public static decode( + bytes: Uint8Array | Buffer + ): PublicKeyMessage | undefined { const payload = PublicKeyMessage.Type.decode( bytes ) as unknown as PublicKeyMessagePayload; + if (!payload.signature || !payload.ethDmPublicKey || !payload.ethAddress) { + console.log('Field missing on decoded Public Key Message', payload); + return; + } return new PublicKeyMessage(payload); }