import type { Result } from '../../framework/types/result.js' import type { SigningKeypair } from '../../domain/keypair.js' import { makeError, makeSuccess } from '../../framework/types/result.js' import { buildSerde } from './internal/serde.js' import { generateKeypair } from './internal/generate-keypair.js' import { BaseError } from '../../framework/error/mod.js' export class CreateSigningKeypairError extends BaseError { public readonly _tag = 'CreateSigningKeypairError' constructor(public readonly cause: unknown) { super(`failed to create signing keypair: ${cause}`) } } export function buildCreateKeypair() { return async function createKeypair(): Promise< Result > { try { const { privateKey, publicKey } = await generateKeypair() const serde = buildSerde() const keypair = await serde.serialize({ privateKey, publicKey }) return makeSuccess(keypair) } catch (cause) { return makeError(new CreateSigningKeypairError(cause)) } } }