From 5648f72d3d7cc81554e07fc6c01f091138879892 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Fri, 20 May 2022 10:18:09 +1000 Subject: [PATCH] Extract is message signed logic --- src/lib/waku_message/version_1.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/waku_message/version_1.ts b/src/lib/waku_message/version_1.ts index 6ba8f0f388..f497e4bcbe 100644 --- a/src/lib/waku_message/version_1.ts +++ b/src/lib/waku_message/version_1.ts @@ -98,7 +98,7 @@ export function clearDecode( start += sizeOfPayloadSizeField; const payload = buf.slice(start, start + payloadSize); - const isSigned = (buf.readUIntLE(0, 1) & IsSignedMask) == IsSignedMask; + const isSigned = isMessageSigned(buf); if (isSigned) { const signature = getSignature(buf); const hash = getHash(buf, isSigned); @@ -131,6 +131,10 @@ function getPayloadSize( return payloadSizeDataView.getInt32(0, true); } +function isMessageSigned(message: Buffer): boolean { + return (message.readUIntLE(0, 1) & IsSignedMask) == IsSignedMask; +} + /** * Proceed with Asymmetric encryption of the data as per [26/WAKU-PAYLOAD](https://rfc.vac.dev/spec/26/). * The data MUST be flags | payload-length | payload | [signature].