mirror of
https://github.com/documenso/documenso.git
synced 2025-11-09 20:12:31 +10:00
20 lines
615 B
TypeScript
20 lines
615 B
TypeScript
import { match } from 'ts-pattern';
|
|
|
|
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 = process.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}`);
|
|
});
|
|
};
|