mirror of
https://github.com/logos-messaging/logos-messaging-js.git
synced 2026-01-15 06:23:09 +00:00
* chore: update noise * update: package.lock * update: @chainsafe/libp2p-gossipsub * rm unwanted libp2p interface deps & bump up libp2p * refactor code for new deps * update: new package.lock * setup prettier, refactor eslint and rm trailing commas * update package.lock * fix build * import type for interface * fix imports for merge * update typedoc exports * add: CustomEvent import * use new libp2p interface * add aegir as dev dep for tests
69 lines
2.1 KiB
TypeScript
69 lines
2.1 KiB
TypeScript
import type { IProtoMessage } from "@waku/interfaces";
|
|
import { bytesToHex, hexToBytes } from "@waku/utils/bytes";
|
|
import { expect } from "chai";
|
|
|
|
import { messageHash } from "./index.js";
|
|
|
|
// https://rfc.vac.dev/spec/14/#test-vectors
|
|
describe("RFC Test Vectors", () => {
|
|
it("Waku message hash computation", () => {
|
|
const expectedHash =
|
|
"4fdde1099c9f77f6dae8147b6b3179aba1fc8e14a7bf35203fc253ee479f135f";
|
|
|
|
const pubSubTopic = "/waku/2/default-waku/proto";
|
|
const message: IProtoMessage = {
|
|
payload: hexToBytes("0x010203045445535405060708"),
|
|
contentTopic: "/waku/2/default-content/proto",
|
|
meta: hexToBytes("0x73757065722d736563726574"),
|
|
ephemeral: undefined,
|
|
rateLimitProof: undefined,
|
|
timestamp: undefined,
|
|
version: undefined
|
|
};
|
|
|
|
const hash = messageHash(pubSubTopic, message);
|
|
|
|
expect(bytesToHex(hash)).to.equal(expectedHash);
|
|
});
|
|
|
|
it("Waku message hash computation (meta attribute not present)", () => {
|
|
const expectedHash =
|
|
"87619d05e563521d9126749b45bd4cc2430df0607e77e23572d874ed9c1aaa62";
|
|
|
|
const pubSubTopic = "/waku/2/default-waku/proto";
|
|
const message: IProtoMessage = {
|
|
payload: hexToBytes("0x010203045445535405060708"),
|
|
contentTopic: "/waku/2/default-content/proto",
|
|
meta: undefined,
|
|
ephemeral: undefined,
|
|
rateLimitProof: undefined,
|
|
timestamp: undefined,
|
|
version: undefined
|
|
};
|
|
|
|
const hash = messageHash(pubSubTopic, message);
|
|
|
|
expect(bytesToHex(hash)).to.equal(expectedHash);
|
|
});
|
|
|
|
it("Waku message hash computation (payload length 0)", () => {
|
|
const expectedHash =
|
|
"e1a9596237dbe2cc8aaf4b838c46a7052df6bc0d42ba214b998a8bfdbe8487d6";
|
|
|
|
const pubSubTopic = "/waku/2/default-waku/proto";
|
|
const message: IProtoMessage = {
|
|
payload: new Uint8Array(),
|
|
contentTopic: "/waku/2/default-content/proto",
|
|
meta: hexToBytes("0x73757065722d736563726574"),
|
|
ephemeral: undefined,
|
|
rateLimitProof: undefined,
|
|
timestamp: undefined,
|
|
version: undefined
|
|
};
|
|
|
|
const hash = messageHash(pubSubTopic, message);
|
|
|
|
expect(bytesToHex(hash)).to.equal(expectedHash);
|
|
});
|
|
});
|