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); }