Generation of content topic is the same for chats and communities
This commit is contained in:
parent
9f6abaf952
commit
43ecd31e76
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue