mirror of
https://github.com/documenso/documenso
synced 2026-04-21 13:27:18 +00:00
Migrate from @documenso/pdf-sign and @cantoo/pdf-lib to @libpdf/core for all PDF manipulation and signing operations. This includes: - New signing transports for Google Cloud KMS and local certificates - Consolidated PDF operations using libpdf API - Added TSA (timestamp authority) helper for digital signatures - Removed deprecated flatten and insert utilities - Updated tests to use new PDF library
32 lines
814 B
TypeScript
32 lines
814 B
TypeScript
import { P12Signer } from '@libpdf/core';
|
|
import * as fs from 'node:fs';
|
|
|
|
import { env } from '@documenso/lib/utils/env';
|
|
|
|
const loadP12 = (): Uint8Array => {
|
|
const localFileContents = env('NEXT_PRIVATE_SIGNING_LOCAL_FILE_CONTENTS');
|
|
|
|
if (localFileContents) {
|
|
return Buffer.from(localFileContents, 'base64');
|
|
}
|
|
|
|
const localFilePath = env('NEXT_PRIVATE_SIGNING_LOCAL_FILE_PATH');
|
|
|
|
if (localFilePath) {
|
|
return fs.readFileSync(localFilePath);
|
|
}
|
|
|
|
if (env('NODE_ENV') !== 'production') {
|
|
return fs.readFileSync('./example/cert.p12');
|
|
}
|
|
|
|
throw new Error('No certificate found for local signing');
|
|
};
|
|
|
|
export const createLocalSigner = async () => {
|
|
const p12 = loadP12();
|
|
|
|
return await P12Signer.create(p12, env('NEXT_PRIVATE_SIGNING_PASSPHRASE') || '', {
|
|
buildChain: true,
|
|
});
|
|
};
|