Skip to content

Commit

Permalink
fix: await key gen before returning
Browse files Browse the repository at this point in the history
  • Loading branch information
rygine committed Mar 12, 2024
1 parent 6056942 commit c261f25
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions src/keystore/InMemoryKeystore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
generateUserPreferencesTopic,
} from '../crypto/selfEncryption'
import type { KeystoreInterface } from '..'
import { generateHmac, hkdfHmacKey } from '../crypto/encryption'
import { exportHmacKey, generateHmac, hkdfHmacKey } from '../crypto/encryption'

const { ErrorCode } = keystore

Expand Down Expand Up @@ -598,35 +598,35 @@ export default class InMemoryKeystore implements KeystoreInterface {

const hmacKeys: keystore.GetConversationHmacKeysResponse['hmacKeys'] = {}

this.v2Store.topics.forEach(async (topicData) => {
if (topicData.invitation?.topic) {
const keyMaterial = getKeyMaterial(topicData.invitation)
const values = await Promise.all(
[
thirtyDayPeriodsSinceEpoch - 1,
thirtyDayPeriodsSinceEpoch,
thirtyDayPeriodsSinceEpoch + 1,
].map(async (value) => {
const salt = `${value}-${this.accountAddress}`
const hmacKey = await hkdfHmacKey(
keyMaterial,
new TextEncoder().encode(salt)
)
return {
thirtyDayPeriodsSinceEpoch: value,
// convert CryptoKey to Uint8Array to match the proto
hmacKey: new Uint8Array(
await crypto.subtle.exportKey('raw', hmacKey)
),
}
})
)
await Promise.all(
this.v2Store.topics.map(async (topicData) => {
if (topicData.invitation?.topic) {
const keyMaterial = getKeyMaterial(topicData.invitation)
const values = await Promise.all(
[
thirtyDayPeriodsSinceEpoch - 1,
thirtyDayPeriodsSinceEpoch,
thirtyDayPeriodsSinceEpoch + 1,
].map(async (value) => {
const salt = `${value}-${this.accountAddress}`
const hmacKey = await hkdfHmacKey(
keyMaterial,
new TextEncoder().encode(salt)
)
return {
thirtyDayPeriodsSinceEpoch: value,
// convert CryptoKey to Uint8Array to match the proto
hmacKey: await exportHmacKey(hmacKey),
}
})
)

hmacKeys[topicData.invitation.topic] = {
values,
hmacKeys[topicData.invitation.topic] = {
values,
}
}
}
})
})
)

return { hmacKeys }
}
Expand Down

0 comments on commit c261f25

Please sign in to comment.