Generation of content topic is the same for chats and communities

This commit is contained in:
Franck Royer 2021-10-06 12:52:41 +11:00
parent 9f6abaf952
commit 43ecd31e76
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 9 additions and 4 deletions

View File

@ -1,4 +1,4 @@
import { chatIdToContentTopic } from "./contentTopic"; import { idToContentTopic } from "./contentTopic";
import { createSymKeyFromPassword } from "./encryption"; import { createSymKeyFromPassword } from "./encryption";
import { ChatMessage, Content } from "./wire/chat_message"; import { ChatMessage, Content } from "./wire/chat_message";
@ -21,7 +21,7 @@ export class Chat {
} }
public get contentTopic(): string { public get contentTopic(): string {
return chatIdToContentTopic(this.id); return idToContentTopic(this.id);
} }
public createMessage(content: Content): ChatMessage { public createMessage(content: Content): ChatMessage {

View File

@ -4,8 +4,13 @@ import { keccak256 } from "js-sha3";
const TopicLength = 4; 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); const topic = Buffer.from(hash).slice(0, TopicLength);