Do not process Public Key Message if field is missing

This commit is contained in:
Franck Royer 2021-07-02 10:52:35 +10:00
parent 370a347ff2
commit f9174cd3d2
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 8 additions and 1 deletions

View File

@ -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;

View File

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