From 43ecd31e768753c2854b63a68ab7200ce9577ba5 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Wed, 6 Oct 2021 12:52:41 +1100 Subject: [PATCH] Generation of content topic is the same for chats and communities --- packages/status-communities/src/chat.ts | 4 ++-- packages/status-communities/src/contentTopic.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/status-communities/src/chat.ts b/packages/status-communities/src/chat.ts index 184d50dd..95457c87 100644 --- a/packages/status-communities/src/chat.ts +++ b/packages/status-communities/src/chat.ts @@ -1,4 +1,4 @@ -import { chatIdToContentTopic } from "./contentTopic"; +import { idToContentTopic } from "./contentTopic"; import { createSymKeyFromPassword } from "./encryption"; import { ChatMessage, Content } from "./wire/chat_message"; @@ -21,7 +21,7 @@ export class Chat { } public get contentTopic(): string { - return chatIdToContentTopic(this.id); + return idToContentTopic(this.id); } public createMessage(content: Content): ChatMessage { diff --git a/packages/status-communities/src/contentTopic.ts b/packages/status-communities/src/contentTopic.ts index 07bba7b2..0c78777f 100644 --- a/packages/status-communities/src/contentTopic.ts +++ b/packages/status-communities/src/contentTopic.ts @@ -4,8 +4,13 @@ import { keccak256 } from "js-sha3"; const TopicLength = 4; -export function chatIdToContentTopic(chatId: string): string { - const hash = keccak256.arrayBuffer(chatId); +/** + * 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);