make pbkdf2 async
This commit is contained in:
parent
62bd4650a3
commit
5de124efc7
|
@ -191,13 +191,13 @@ class Community {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private observeChannelMessages(chats: string[]) {
|
private async observeChannelMessages(chats: string[]) {
|
||||||
const contentTopics: string[] = []
|
const contentTopics: string[] = []
|
||||||
|
|
||||||
for (const chatId of chats) {
|
for (const chatId of chats) {
|
||||||
const id = `${this.communityPublicKey}${chatId}`
|
const id = `${this.communityPublicKey}${chatId}`
|
||||||
const channelContentTopic = idToContentTopic(id)
|
const channelContentTopic = idToContentTopic(id)
|
||||||
const symKey = createSymKeyFromPassword(id)
|
const symKey = await createSymKeyFromPassword(id)
|
||||||
|
|
||||||
contentTopics.push(channelContentTopic)
|
contentTopics.push(channelContentTopic)
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,25 @@
|
||||||
import pbkdf2 from 'pbkdf2'
|
import { utf8ToBytes } from 'ethereum-cryptography/utils'
|
||||||
|
import { pbkdf2 } from 'pbkdf2'
|
||||||
|
|
||||||
const AESKeyLength = 32 // bytes
|
const AESKeyLength = 32 // bytes
|
||||||
|
|
||||||
export function createSymKeyFromPassword(password: string): Uint8Array {
|
export async function createSymKeyFromPassword(
|
||||||
return pbkdf2.pbkdf2Sync(
|
password: string
|
||||||
Buffer.from(password, 'utf-8'),
|
): Promise<Uint8Array> {
|
||||||
'',
|
return new Promise((resolve, reject) => {
|
||||||
65356,
|
pbkdf2(
|
||||||
AESKeyLength,
|
utf8ToBytes(password),
|
||||||
'sha256'
|
'',
|
||||||
)
|
65356,
|
||||||
|
AESKeyLength,
|
||||||
|
'sha256',
|
||||||
|
(err, buf) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err)
|
||||||
|
} else {
|
||||||
|
resolve(buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue