1 import type { PrivateKeyReference, PublicKeyReference, SessionKey } from '@proton/crypto';
2 import { CryptoProxy } from '@proton/crypto';
3 import { uint8ArrayToBase64String } from '@proton/shared/lib/helpers/encoding';
5 export const decryptKeyPacket = async ({
9 armoredMessage?: string;
10 decryptionKeys: PrivateKeyReference[];
12 const sessionKey = await CryptoProxy.decryptSessionKey({
17 throw new Error('Missing session key');
19 const message = await CryptoProxy.decryptMessage({
21 sessionKeys: sessionKey,
24 return { message, sessionKey };
27 export const encryptAndSignKeyPacket = async ({
34 sessionKey: SessionKey;
35 binaryData: Uint8Array;
36 encryptionKey: PublicKeyReference;
37 signingKey: PrivateKeyReference;
38 context?: Parameters<typeof CryptoProxy.signMessage<any>>[0]['context'];
40 const result = await CryptoProxy.encryptSessionKey({
42 encryptionKeys: [encryptionKey],
46 const signature = await CryptoProxy.signMessage({
48 signingKeys: [signingKey],
54 keyPacket: uint8ArrayToBase64String(result),