Extract is message signed logic

This commit is contained in:
Franck Royer 2022-05-20 10:18:09 +10:00
parent bd9d592fda
commit 5648f72d3d
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 5 additions and 1 deletions

View File

@ -98,7 +98,7 @@ export function clearDecode(
start += sizeOfPayloadSizeField; start += sizeOfPayloadSizeField;
const payload = buf.slice(start, start + payloadSize); const payload = buf.slice(start, start + payloadSize);
const isSigned = (buf.readUIntLE(0, 1) & IsSignedMask) == IsSignedMask; const isSigned = isMessageSigned(buf);
if (isSigned) { if (isSigned) {
const signature = getSignature(buf); const signature = getSignature(buf);
const hash = getHash(buf, isSigned); const hash = getHash(buf, isSigned);
@ -131,6 +131,10 @@ function getPayloadSize(
return payloadSizeDataView.getInt32(0, true); 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/). * 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]. * The data MUST be flags | payload-length | payload | [signature].