Danish Arora 87717981eb
chore: upgrade libp2p and related deps (#1482)
* 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
2023-08-16 20:18:13 +05:30

30 lines
780 B
TypeScript

import { sha256 } from "@noble/hashes/sha256";
import type { IProtoMessage } from "@waku/interfaces";
import { concat, utf8ToBytes } from "@waku/utils/bytes";
/**
* Deterministic Message Hashing as defined in
* [14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/#deterministic-message-hashing)
*/
export function messageHash(
pubsubTopic: string,
message: IProtoMessage
): Uint8Array {
const pubsubTopicBytes = utf8ToBytes(pubsubTopic);
const contentTopicBytes = utf8ToBytes(message.contentTopic);
let bytes;
if (message.meta) {
bytes = concat([
pubsubTopicBytes,
message.payload,
contentTopicBytes,
message.meta
]);
} else {
bytes = concat([pubsubTopicBytes, message.payload, contentTopicBytes]);
}
return sha256(bytes);
}