make pbkdf2 async

This commit is contained in:
Pavel Prichodko 2022-06-06 11:05:44 +02:00 committed by Felicio Mununga
parent 817b877634
commit 643f7faa92
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
2 changed files with 23 additions and 11 deletions

View File

@ -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)

View File

@ -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'),
export async function createSymKeyFromPassword(
password: string
): Promise<Uint8Array> {
return new Promise((resolve, reject) => {
pbkdf2(
utf8ToBytes(password),
'',
65356,
AESKeyLength,
'sha256'
)
'sha256',
(err, buf) => {
if (err) {
reject(err)
} else {
resolve(buf)
}
}
)
})
}