Files
documenso/packages/signing/index.ts
2025-02-13 14:10:38 +11:00

22 lines
659 B
TypeScript

import { match } from 'ts-pattern';
import { env } from '@documenso/lib/utils/env';
import { signWithGoogleCloudHSM } from './transports/google-cloud-hsm';
import { signWithLocalCert } from './transports/local-cert';
export type SignOptions = {
pdf: Buffer;
};
export const signPdf = async ({ pdf }: SignOptions) => {
const transport = env('NEXT_PRIVATE_SIGNING_TRANSPORT') || 'local';
return await match(transport)
.with('local', async () => signWithLocalCert({ pdf }))
.with('gcloud-hsm', async () => signWithGoogleCloudHSM({ pdf }))
.otherwise(() => {
throw new Error(`Unsupported signing transport: ${transport}`);
});
};