diff --git a/packages/status-js/src/client.ts b/packages/status-js/src/client.ts index c30d394c..f09f2dc6 100644 --- a/packages/status-js/src/client.ts +++ b/packages/status-js/src/client.ts @@ -191,13 +191,13 @@ class Community { ) } - private observeChannelMessages(chats: string[]) { + private async observeChannelMessages(chats: string[]) { const contentTopics: string[] = [] for (const chatId of chats) { const id = `${this.communityPublicKey}${chatId}` const channelContentTopic = idToContentTopic(id) - const symKey = createSymKeyFromPassword(id) + const symKey = await createSymKeyFromPassword(id) contentTopics.push(channelContentTopic) diff --git a/packages/status-js/src/encryption.ts b/packages/status-js/src/encryption.ts index 80df1548..c2d7a8f4 100644 --- a/packages/status-js/src/encryption.ts +++ b/packages/status-js/src/encryption.ts @@ -1,13 +1,25 @@ -import pbkdf2 from 'pbkdf2' +import { utf8ToBytes } from 'ethereum-cryptography/utils' +import { pbkdf2 } from 'pbkdf2' const AESKeyLength = 32 // bytes -export function createSymKeyFromPassword(password: string): Uint8Array { - return pbkdf2.pbkdf2Sync( - Buffer.from(password, 'utf-8'), - '', - 65356, - AESKeyLength, - 'sha256' - ) +export async function createSymKeyFromPassword( + password: string +): Promise { + return new Promise((resolve, reject) => { + pbkdf2( + utf8ToBytes(password), + '', + 65356, + AESKeyLength, + 'sha256', + (err, buf) => { + if (err) { + reject(err) + } else { + resolve(buf) + } + } + ) + }) }