chore(message-hash): use timestamp in nanoseconds instead of milliseconds (#2094)

* chore: convert timestamp from miliseconds to nanoseconds

* chore: test against hash accounting for nanoseconds instead of milliseconds
the hash used was calculated using timestamp in milliseconds, instead of nanoseconds (not part of the RFC test vectors)Y
This commit is contained in:
Danish Arora 2024-08-01 15:19:35 +05:30 committed by GitHub
parent 33a9172bbb
commit fea4f2577b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View File

@ -95,7 +95,7 @@ describe("RFC Test Vectors", () => {
it("Waku message hash computation (message is IDecodedMessage)", () => { it("Waku message hash computation (message is IDecodedMessage)", () => {
const expectedHash = const expectedHash =
"bd81b27902ad51f49e8f73ff8db4a96994040c9421da88b7ee8ba07bd39070b2"; "3f11bc950dce0e3ffdcf205ae6414c01130bb5d9f20644869bff80407fa52c8f";
const pubsubTopic = "/waku/2/default-waku/proto"; const pubsubTopic = "/waku/2/default-waku/proto";
const message: IDecodedMessage = { const message: IDecodedMessage = {
payload: new Uint8Array(), payload: new Uint8Array(),

View File

@ -40,7 +40,15 @@ function tryConvertTimestampToBytes(
return; return;
} }
return numberToBytes(timestamp.valueOf()); let bigIntTimestamp: bigint;
if (typeof timestamp === "bigint") {
bigIntTimestamp = timestamp;
} else {
bigIntTimestamp = BigInt(timestamp.valueOf()) * 1000000n;
}
return numberToBytes(bigIntTimestamp);
} }
export function messageHashStr( export function messageHashStr(