import type { EncryptionPublicKey } from '../../domain/keypair.js' import type { Result } from '../../framework/types/result.js' import { BaseError } from '../../framework/error/mod.js' import { makeError, makeSuccess } from '../../framework/types/result.js' import { encrypt as encryptContents } from './internal/encrypt.js' export class EncryptError extends BaseError { public readonly _tag = 'EncryptError' constructor(public readonly cause: unknown) { super(`failed encrypt contents: ${cause}`) } } export interface EncryptDto { publicJwk: EncryptionPublicKey contents: string } export function buildEncrypt() { return async function encrypt( dto: EncryptDto, ): Promise> { try { const encrypted = await encryptContents(dto.publicJwk, dto.contents) return makeSuccess(encrypted) } catch (cause: unknown) { return makeError(new EncryptError(cause)) } } }