Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / docs-core / lib / Crypto / deriveGcmKey.ts
blob73754527ce7fa349d08d91192c34b5603efde206
1 import type { SessionKey } from '@proton/crypto'
2 import { HKDF_SALT_SIZE } from './Constants'
3 import { deriveKey } from '@proton/crypto/lib/subtle/aesGcm'
5 export async function deriveGcmKey(sessionKey: SessionKey, salt: Uint8Array, info: Uint8Array) {
6   if (sessionKey.algorithm !== 'aes256') {
7     throw new Error('Unexpected session key algorithm')
8   }
10   if (salt.length !== HKDF_SALT_SIZE) {
11     throw new Error('Unexpected salt size')
12   }
14   return deriveKey(sessionKey.data, salt, info)