mirror of
https://github.com/status-im/wakuconnect-chat-sdk.git
synced 2025-02-11 19:47:22 +00:00
19 lines
501 B
TypeScript
19 lines
501 B
TypeScript
import { Buffer } from "buffer";
|
|
|
|
import { keccak256 } from "js-sha3";
|
|
|
|
const TopicLength = 4;
|
|
|
|
/**
|
|
* Get the content topic of for a given Chat or Community
|
|
* @param id The Chat id or Community id (hex string prefixed with 0x).
|
|
* @returns string The Waku v2 Content Topic.
|
|
*/
|
|
export function idToContentTopic(id: string): string {
|
|
const hash = keccak256.arrayBuffer(id);
|
|
|
|
const topic = Buffer.from(hash).slice(0, TopicLength);
|
|
|
|
return "/waku/1/" + "0x" + topic.toString("hex") + "/rfc26";
|
|
}
|