import type { EncryptionPublicKey } from '../../../domain/keypair.js' import { importJWK, CompactEncrypt } from 'jose' import { ENCRYPTION_ENCODING, ENCRYPTION_KEYPAIR_ALGORITHM, } from './algorithm.js' export async function encrypt(publicJwk: EncryptionPublicKey, content: string) { const publicKey = await importJWK(publicJwk, ENCRYPTION_KEYPAIR_ALGORITHM) return new CompactEncrypt(new TextEncoder().encode(content)) .setProtectedHeader({ alg: ENCRYPTION_KEYPAIR_ALGORITHM, enc: ENCRYPTION_ENCODING, }) .encrypt(publicKey) }