pdf-oxide-fips 0.3.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/LICENSE-APACHE +176 -0
  2. package/LICENSE-MIT +25 -0
  3. package/README.md +218 -0
  4. package/lib/builders/annotation-builder.d.ts +198 -0
  5. package/lib/builders/annotation-builder.js +317 -0
  6. package/lib/builders/conversion-options-builder.d.ts +106 -0
  7. package/lib/builders/conversion-options-builder.js +214 -0
  8. package/lib/builders/document-builder.d.ts +381 -0
  9. package/lib/builders/document-builder.js +770 -0
  10. package/lib/builders/index.d.ts +13 -0
  11. package/lib/builders/index.js +13 -0
  12. package/lib/builders/metadata-builder.d.ts +201 -0
  13. package/lib/builders/metadata-builder.js +285 -0
  14. package/lib/builders/pdf-builder.d.ts +216 -0
  15. package/lib/builders/pdf-builder.js +350 -0
  16. package/lib/builders/search-options-builder.d.ts +73 -0
  17. package/lib/builders/search-options-builder.js +129 -0
  18. package/lib/builders/streaming-table.d.ts +64 -0
  19. package/lib/builders/streaming-table.js +140 -0
  20. package/lib/document-editor-manager.d.ts +139 -0
  21. package/lib/document-editor-manager.js +256 -0
  22. package/lib/document-editor.d.ts +124 -0
  23. package/lib/document-editor.js +318 -0
  24. package/lib/errors.d.ts +382 -0
  25. package/lib/errors.js +1115 -0
  26. package/lib/form-field-manager.d.ts +299 -0
  27. package/lib/form-field-manager.js +568 -0
  28. package/lib/hybrid-ml-manager.d.ts +142 -0
  29. package/lib/hybrid-ml-manager.js +208 -0
  30. package/lib/index.d.ts +205 -0
  31. package/lib/index.js +693 -0
  32. package/lib/managers/accessibility-manager.d.ts +148 -0
  33. package/lib/managers/accessibility-manager.js +234 -0
  34. package/lib/managers/annotation-manager.d.ts +219 -0
  35. package/lib/managers/annotation-manager.js +359 -0
  36. package/lib/managers/barcode-manager.d.ts +82 -0
  37. package/lib/managers/barcode-manager.js +263 -0
  38. package/lib/managers/batch-manager.d.ts +185 -0
  39. package/lib/managers/batch-manager.js +385 -0
  40. package/lib/managers/cache-manager.d.ts +181 -0
  41. package/lib/managers/cache-manager.js +384 -0
  42. package/lib/managers/compliance-manager.d.ts +103 -0
  43. package/lib/managers/compliance-manager.js +453 -0
  44. package/lib/managers/content-manager.d.ts +120 -0
  45. package/lib/managers/content-manager.js +294 -0
  46. package/lib/managers/document-utility-manager.d.ts +369 -0
  47. package/lib/managers/document-utility-manager.js +730 -0
  48. package/lib/managers/dom-pdf-creator.d.ts +104 -0
  49. package/lib/managers/dom-pdf-creator.js +299 -0
  50. package/lib/managers/editing-manager.d.ts +248 -0
  51. package/lib/managers/editing-manager.js +387 -0
  52. package/lib/managers/enterprise-manager.d.ts +192 -0
  53. package/lib/managers/enterprise-manager.js +307 -0
  54. package/lib/managers/extended-managers.d.ts +122 -0
  55. package/lib/managers/extended-managers.js +664 -0
  56. package/lib/managers/extraction-manager.d.ts +246 -0
  57. package/lib/managers/extraction-manager.js +482 -0
  58. package/lib/managers/final-utilities.d.ts +127 -0
  59. package/lib/managers/final-utilities.js +657 -0
  60. package/lib/managers/hybrid-ml-advanced.d.ts +136 -0
  61. package/lib/managers/hybrid-ml-advanced.js +722 -0
  62. package/lib/managers/index.d.ts +64 -0
  63. package/lib/managers/index.js +69 -0
  64. package/lib/managers/layer-manager.d.ts +203 -0
  65. package/lib/managers/layer-manager.js +401 -0
  66. package/lib/managers/metadata-manager.d.ts +148 -0
  67. package/lib/managers/metadata-manager.js +280 -0
  68. package/lib/managers/ocr-manager.d.ts +194 -0
  69. package/lib/managers/ocr-manager.js +582 -0
  70. package/lib/managers/optimization-manager.d.ts +102 -0
  71. package/lib/managers/optimization-manager.js +213 -0
  72. package/lib/managers/outline-manager.d.ts +101 -0
  73. package/lib/managers/outline-manager.js +169 -0
  74. package/lib/managers/page-manager.d.ts +142 -0
  75. package/lib/managers/page-manager.js +235 -0
  76. package/lib/managers/pattern-detection.d.ts +169 -0
  77. package/lib/managers/pattern-detection.js +322 -0
  78. package/lib/managers/rendering-manager.d.ts +353 -0
  79. package/lib/managers/rendering-manager.js +679 -0
  80. package/lib/managers/search-manager.d.ts +235 -0
  81. package/lib/managers/search-manager.js +329 -0
  82. package/lib/managers/security-manager.d.ts +161 -0
  83. package/lib/managers/security-manager.js +292 -0
  84. package/lib/managers/signature-manager.d.ts +738 -0
  85. package/lib/managers/signature-manager.js +1509 -0
  86. package/lib/managers/streams.d.ts +262 -0
  87. package/lib/managers/streams.js +477 -0
  88. package/lib/managers/xfa-manager.d.ts +227 -0
  89. package/lib/managers/xfa-manager.js +539 -0
  90. package/lib/native-loader.d.ts +7 -0
  91. package/lib/native-loader.js +62 -0
  92. package/lib/native.d.ts +16 -0
  93. package/lib/native.js +69 -0
  94. package/lib/pdf-creator-manager.d.ts +200 -0
  95. package/lib/pdf-creator-manager.js +381 -0
  96. package/lib/properties.d.ts +79 -0
  97. package/lib/properties.js +454 -0
  98. package/lib/result-accessors-manager.d.ts +346 -0
  99. package/lib/result-accessors-manager.js +706 -0
  100. package/lib/thumbnail-manager.d.ts +121 -0
  101. package/lib/thumbnail-manager.js +205 -0
  102. package/lib/timestamp.d.ts +54 -0
  103. package/lib/timestamp.js +115 -0
  104. package/lib/tsa-client.d.ts +44 -0
  105. package/lib/tsa-client.js +67 -0
  106. package/lib/types/common.d.ts +189 -0
  107. package/lib/types/common.js +17 -0
  108. package/lib/types/document-types.d.ts +352 -0
  109. package/lib/types/document-types.js +82 -0
  110. package/lib/types/index.d.ts +5 -0
  111. package/lib/types/index.js +5 -0
  112. package/lib/types/manager-types.d.ts +179 -0
  113. package/lib/types/manager-types.js +100 -0
  114. package/lib/types/native-bindings.d.ts +439 -0
  115. package/lib/types/native-bindings.js +7 -0
  116. package/lib/workers/index.d.ts +6 -0
  117. package/lib/workers/index.js +5 -0
  118. package/lib/workers/pool.d.ts +64 -0
  119. package/lib/workers/pool.js +192 -0
  120. package/lib/workers/worker.d.ts +5 -0
  121. package/lib/workers/worker.js +99 -0
  122. package/package.json +79 -0
  123. package/prebuilds/darwin-arm64/pdf_oxide.node +0 -0
  124. package/prebuilds/darwin-x64/pdf_oxide.node +0 -0
  125. package/prebuilds/linux-arm64/pdf_oxide.node +0 -0
  126. package/prebuilds/linux-x64/pdf_oxide.node +0 -0
  127. package/prebuilds/win32-x64/pdf_oxide.node +0 -0
@@ -0,0 +1,738 @@
1
+ /**
2
+ * SignatureManager - Canonical Signature Manager (merged from 3 implementations)
3
+ *
4
+ * Consolidates:
5
+ * - src/signature-manager.ts SignatureManager (verification + basic field management)
6
+ * - src/managers/barcode-signature-rendering.ts SignaturesManager (certificate loading + signing + detail info)
7
+ * - src/managers/signature-creation-manager.ts SignatureCreationManager (complete signing workflow + LTV + timestamps)
8
+ *
9
+ * Provides comprehensive digital signature operations with full type safety
10
+ * and FFI integration.
11
+ */
12
+ import { EventEmitter } from 'events';
13
+ /**
14
+ * Signature algorithms
15
+ */
16
+ export declare enum SignatureAlgorithm {
17
+ RSA2048 = "RSA2048",
18
+ RSA3072 = "RSA3072",
19
+ RSA4096 = "RSA4096",
20
+ ECDSAP256 = "ECDSA_P256",
21
+ ECDSAP384 = "ECDSA_P384",
22
+ ECDSAP521 = "ECDSA_P521",
23
+ RSA_SHA256 = "RSA_SHA256",
24
+ RSA_SHA384 = "RSA_SHA384",
25
+ RSA_SHA512 = "RSA_SHA512",
26
+ ECDSA_SHA256 = "ECDSA_SHA256",
27
+ ECDSA_SHA384 = "ECDSA_SHA384",
28
+ ECDSA_SHA512 = "ECDSA_SHA512",
29
+ ED25519 = "ED25519"
30
+ }
31
+ /**
32
+ * Digest algorithms for signature
33
+ */
34
+ export declare enum DigestAlgorithm {
35
+ SHA256 = "SHA256",
36
+ SHA384 = "SHA384",
37
+ SHA512 = "SHA512",
38
+ SHA512_256 = "SHA512_256"
39
+ }
40
+ /**
41
+ * Signature type enumeration
42
+ */
43
+ export declare enum SignatureType {
44
+ APPROVAL = "approval",
45
+ CERTIFICATION = "certification",
46
+ USAGE_RIGHTS = "usage_rights"
47
+ }
48
+ /**
49
+ * Certification permission level
50
+ */
51
+ export declare enum CertificationPermission {
52
+ NO_CHANGES = 1,
53
+ FORM_FILLING = 2,
54
+ FORM_FILLING_ANNOTATIONS = 3
55
+ }
56
+ /**
57
+ * Certificate format enumeration
58
+ */
59
+ export declare enum CertificateFormat {
60
+ PFX = "pfx",
61
+ PEM = "pem",
62
+ DER = "der",
63
+ P12 = "p12",
64
+ CER = "cer"
65
+ }
66
+ /**
67
+ * Timestamp response status
68
+ */
69
+ export declare enum TimestampStatus {
70
+ SUCCESS = "success",
71
+ FAILED = "failed",
72
+ TIMEOUT = "timeout",
73
+ INVALID_RESPONSE = "invalid_response"
74
+ }
75
+ export interface DigitalSignature {
76
+ signatureName: string;
77
+ signingDate?: Date;
78
+ reason?: string;
79
+ location?: string;
80
+ signer?: string;
81
+ isCertified: boolean;
82
+ algorithm?: SignatureAlgorithm;
83
+ }
84
+ export interface SignatureField {
85
+ fieldName: string;
86
+ pageIndex: number;
87
+ isSigned: boolean;
88
+ signature?: DigitalSignature;
89
+ }
90
+ export interface SignatureValidationResult {
91
+ isValid: boolean;
92
+ signatures: DigitalSignature[];
93
+ issues: string[];
94
+ }
95
+ export interface SignatureConfig {
96
+ algorithm?: SignatureAlgorithm;
97
+ digestAlgorithm?: DigestAlgorithm;
98
+ reason?: string;
99
+ location?: string;
100
+ }
101
+ export interface Certificate {
102
+ subject: string;
103
+ issuer: string;
104
+ serial: string;
105
+ notBefore: number;
106
+ notAfter: number;
107
+ isValid: boolean;
108
+ }
109
+ export interface Signature {
110
+ signerName: string;
111
+ signingTime: number;
112
+ reason?: string;
113
+ location?: string;
114
+ certificate: Certificate;
115
+ isValid: boolean;
116
+ }
117
+ export interface CertificateInfo {
118
+ readonly subject: string;
119
+ readonly issuer: string;
120
+ readonly serialNumber: string;
121
+ readonly validFrom: Date;
122
+ readonly validTo: Date;
123
+ readonly isValid: boolean;
124
+ readonly isSelfSigned: boolean;
125
+ readonly keyUsage?: readonly string[];
126
+ readonly extendedKeyUsage?: readonly string[];
127
+ readonly subjectAltNames?: readonly string[];
128
+ readonly thumbprint?: string;
129
+ readonly publicKeyAlgorithm?: string;
130
+ readonly signatureAlgorithm?: string;
131
+ }
132
+ export interface CertificateChain {
133
+ readonly certificates: readonly CertificateInfo[];
134
+ readonly isComplete: boolean;
135
+ readonly validationStatus: 'valid' | 'invalid' | 'unknown';
136
+ readonly validationMessages?: readonly string[];
137
+ }
138
+ export interface LoadedCertificate {
139
+ readonly certificateId: string;
140
+ readonly info: CertificateInfo;
141
+ readonly hasPrivateKey: boolean;
142
+ readonly chain?: CertificateChain;
143
+ }
144
+ export interface SignatureAppearance {
145
+ readonly showName?: boolean;
146
+ readonly showDate?: boolean;
147
+ readonly showReason?: boolean;
148
+ readonly showLocation?: boolean;
149
+ readonly showLabels?: boolean;
150
+ readonly imageData?: Buffer;
151
+ readonly imagePath?: string;
152
+ readonly backgroundColor?: string;
153
+ readonly textColor?: string;
154
+ readonly borderColor?: string;
155
+ readonly borderWidth?: number;
156
+ readonly font?: string;
157
+ readonly fontSize?: number;
158
+ readonly customText?: string;
159
+ }
160
+ export interface SignatureFieldConfig {
161
+ readonly fieldName: string;
162
+ readonly pageIndex: number;
163
+ readonly x: number;
164
+ readonly y: number;
165
+ readonly width: number;
166
+ readonly height: number;
167
+ readonly appearance?: SignatureAppearance;
168
+ readonly tooltip?: string;
169
+ readonly isRequired?: boolean;
170
+ readonly isReadOnly?: boolean;
171
+ }
172
+ export interface SigningOptions {
173
+ readonly reason?: string;
174
+ readonly location?: string;
175
+ readonly contactInfo?: string;
176
+ readonly signatureType?: SignatureType;
177
+ readonly certificationPermission?: CertificationPermission;
178
+ readonly algorithm?: SignatureAlgorithm;
179
+ readonly digestAlgorithm?: DigestAlgorithm;
180
+ readonly appearance?: SignatureAppearance;
181
+ readonly embedTimestamp?: boolean;
182
+ readonly timestampServerUrl?: string;
183
+ readonly enableLtv?: boolean;
184
+ readonly ocspResponderUrl?: string;
185
+ readonly crlDistributionPoints?: readonly string[];
186
+ }
187
+ export interface TimestampConfig {
188
+ readonly serverUrl: string;
189
+ readonly username?: string;
190
+ readonly password?: string;
191
+ readonly hashAlgorithm?: DigestAlgorithm;
192
+ readonly timeout?: number;
193
+ readonly policy?: string;
194
+ readonly nonce?: boolean;
195
+ readonly certReq?: boolean;
196
+ }
197
+ export interface SigningResult {
198
+ readonly success: boolean;
199
+ readonly signatureId?: string;
200
+ readonly signingTime?: Date;
201
+ readonly timestampTime?: Date;
202
+ readonly error?: string;
203
+ readonly warnings?: readonly string[];
204
+ }
205
+ export interface TimestampResult {
206
+ readonly status: TimestampStatus;
207
+ readonly timestamp?: Date;
208
+ readonly serialNumber?: string;
209
+ readonly tsaName?: string;
210
+ readonly error?: string;
211
+ }
212
+ /**
213
+ * Opaque handle to signing credentials loaded via FFI.
214
+ * Wraps a native pointer returned by pdf_credentials_from_pkcs12 or pdf_credentials_from_pem.
215
+ */
216
+ export interface SigningCredentials {
217
+ /** Internal native handle - do not access directly */
218
+ readonly _handle: any;
219
+ /** Source type: 'pkcs12' or 'pem' */
220
+ readonly sourceType: 'pkcs12' | 'pem';
221
+ }
222
+ /**
223
+ * Options for FFI-based document signing operations.
224
+ */
225
+ export interface SignOptions {
226
+ /** Reason for signing the document */
227
+ readonly reason?: string;
228
+ /** Location where the document was signed */
229
+ readonly location?: string;
230
+ /** Contact information for the signer */
231
+ readonly contact?: string;
232
+ /** Digest algorithm (0=SHA1, 1=SHA256, 2=SHA384, 3=SHA512). Defaults to SHA256 (1). */
233
+ readonly algorithm?: number;
234
+ /** Signature subfilter (0=PKCS7_DETACHED, 1=PKCS7_SHA1, 2=CADES_DETACHED). Defaults to PKCS7_DETACHED (0). */
235
+ readonly subfilter?: number;
236
+ }
237
+ /**
238
+ * FFI digest algorithm constants for use with SignOptions.algorithm
239
+ */
240
+ export declare enum FfiDigestAlgorithm {
241
+ SHA1 = 0,
242
+ SHA256 = 1,
243
+ SHA384 = 2,
244
+ SHA512 = 3
245
+ }
246
+ /**
247
+ * FFI signature subfilter constants for use with SignOptions.subfilter
248
+ */
249
+ export declare enum FfiSignatureSubFilter {
250
+ PKCS7_DETACHED = 0,
251
+ PKCS7_SHA1 = 1,
252
+ CADES_DETACHED = 2
253
+ }
254
+ /**
255
+ * Canonical Signature Manager - all signature operations in one class.
256
+ *
257
+ * Provides:
258
+ * - Verification (from root SignatureManager)
259
+ * - Certificate loading (from SignatureCreationManager)
260
+ * - Document signing with timestamps and LTV (from SignatureCreationManager)
261
+ * - Detailed signature info (from SignaturesManager)
262
+ */
263
+ export declare class SignatureManager extends EventEmitter {
264
+ private document;
265
+ private resultCache;
266
+ private maxCacheSize;
267
+ private native;
268
+ private readonly loadedCertificates;
269
+ private readonly createdFields;
270
+ constructor(document: any);
271
+ getSignatures(): Promise<DigitalSignature[]>;
272
+ getSignatureFields(): Promise<SignatureField[]>;
273
+ verifySignatures(): Promise<SignatureValidationResult>;
274
+ verifySignature(signatureName: string): Promise<SignatureValidationResult>;
275
+ isCertified(): Promise<boolean>;
276
+ getSignatureCount(): Promise<number>;
277
+ isSigned(): Promise<boolean>;
278
+ loadCertificateFromFile(filePath: string, password?: string, format?: CertificateFormat): Promise<LoadedCertificate | null>;
279
+ loadCertificateFromBytes(certData: Buffer, password?: string, format?: CertificateFormat): Promise<LoadedCertificate | null>;
280
+ loadCertificateFromPem(certificatePem: string, privateKeyPem?: string, privateKeyPassword?: string): Promise<LoadedCertificate | null>;
281
+ getCertificateInfo(certificateId: string): Promise<CertificateInfo | null>;
282
+ getCertificateChain(certificateId: string): Promise<CertificateChain | null>;
283
+ validateCertificate(certificateId: string): Promise<{
284
+ valid: boolean;
285
+ errors: string[];
286
+ warnings: string[];
287
+ }>;
288
+ getLoadedCertificates(): readonly LoadedCertificate[];
289
+ unloadCertificate(certificateId: string): boolean;
290
+ addSignatureField(config: SignatureFieldConfig): Promise<boolean>;
291
+ removeSignatureField(fieldName: string): Promise<boolean>;
292
+ getSignatureFieldNames(): Promise<string[]>;
293
+ hasSignatureField(fieldName: string): Promise<boolean>;
294
+ updateSignatureFieldAppearance(fieldName: string, appearance: SignatureAppearance): Promise<boolean>;
295
+ signDocument(fieldName: string, certificate: LoadedCertificate | string, options?: SigningOptions): Promise<SigningResult>;
296
+ certifyDocument(fieldName: string, certificate: LoadedCertificate | string, permission: CertificationPermission, options?: Omit<SigningOptions, 'signatureType' | 'certificationPermission'>): Promise<SigningResult>;
297
+ signInvisibly(certificate: LoadedCertificate | string, options?: Omit<SigningOptions, 'appearance'>): Promise<SigningResult>;
298
+ counterSign(certificate: LoadedCertificate | string, options?: SigningOptions): Promise<SigningResult>;
299
+ signMultipleFields(signings: Array<{
300
+ fieldName: string;
301
+ certificate: LoadedCertificate | string;
302
+ options?: SigningOptions;
303
+ }>): Promise<SigningResult[]>;
304
+ prepareForExternalSigning(fieldName: string, options?: {
305
+ estimatedSize?: number;
306
+ digestAlgorithm?: DigestAlgorithm;
307
+ }): Promise<{
308
+ hash: Buffer;
309
+ byteRange: [number, number, number, number];
310
+ } | null>;
311
+ embedTimestamp(fieldName: string, config: TimestampConfig): Promise<TimestampResult>;
312
+ addDocumentTimestamp(config: TimestampConfig): Promise<TimestampResult>;
313
+ validateTimestamp(fieldName: string): Promise<{
314
+ valid: boolean;
315
+ timestamp?: Date;
316
+ errors: string[];
317
+ }>;
318
+ getTimestampInfo(fieldName: string): Promise<{
319
+ timestamp?: Date;
320
+ tsaName?: string;
321
+ serialNumber?: string;
322
+ policy?: string;
323
+ } | null>;
324
+ enableLtvForSignature(fieldName: string, options?: {
325
+ ocspResponderUrl?: string;
326
+ crlDistributionPoints?: readonly string[];
327
+ }): Promise<boolean>;
328
+ enableLtvForAllSignatures(options?: {
329
+ ocspResponderUrl?: string;
330
+ crlDistributionPoints?: readonly string[];
331
+ }): Promise<number>;
332
+ addValidationInfo(fieldName: string, info: {
333
+ ocspResponse?: Buffer;
334
+ crl?: Buffer;
335
+ certificates?: readonly Buffer[];
336
+ }): Promise<boolean>;
337
+ hasLtvEnabled(fieldName: string): Promise<boolean>;
338
+ getSignerName(index: number): Promise<string>;
339
+ getSigningTime(index: number): Promise<number>;
340
+ getSigningReason(index: number): Promise<string | null>;
341
+ getSigningLocation(index: number): Promise<string | null>;
342
+ getCertificateSubject(index: number): Promise<string>;
343
+ getCertificateIssuer(index: number): Promise<string>;
344
+ getCertificateSerial(index: number): Promise<string>;
345
+ getCertificateValidity(index: number): Promise<[number, number]>;
346
+ getSignatureDetails(index: number): Promise<Signature | null>;
347
+ isCertificateValidByIndex(index: number): Promise<boolean>;
348
+ /**
349
+ * Load signing credentials from a PKCS#12 (.p12/.pfx) file.
350
+ *
351
+ * Calls the native `pdf_credentials_from_pkcs12` FFI function to load
352
+ * a certificate and private key from a PKCS#12 container.
353
+ *
354
+ * @param filePath - Path to the .p12 or .pfx file
355
+ * @param password - Password to decrypt the PKCS#12 file
356
+ * @returns SigningCredentials handle for use with signing methods
357
+ * @throws SignatureException if the file cannot be loaded or the password is incorrect
358
+ *
359
+ * @example
360
+ * ```typescript
361
+ * const credentials = await sigManager.loadCredentialsPkcs12('/path/to/cert.p12', 'password');
362
+ * const signed = await sigManager.signWithPkcs12(pdfData, '/path/to/cert.p12', 'password');
363
+ * ```
364
+ */
365
+ loadCredentialsPkcs12(filePath: string, password: string): Promise<SigningCredentials>;
366
+ /**
367
+ * Load signing credentials from PEM certificate and key files.
368
+ *
369
+ * Calls the native `pdf_credentials_from_pem` FFI function to load
370
+ * credentials from separate PEM-encoded certificate and private key files.
371
+ *
372
+ * @param certFile - Path to the PEM certificate file
373
+ * @param keyFile - Path to the PEM private key file
374
+ * @param keyPassword - Optional password for an encrypted private key
375
+ * @returns SigningCredentials handle for use with signing methods
376
+ * @throws SignatureException if the files cannot be loaded
377
+ *
378
+ * @example
379
+ * ```typescript
380
+ * const credentials = await sigManager.loadCredentialsPem('/path/to/cert.pem', '/path/to/key.pem');
381
+ * ```
382
+ */
383
+ loadCredentialsPem(certFile: string, keyFile: string, keyPassword?: string): Promise<SigningCredentials>;
384
+ /**
385
+ * Free signing credentials when they are no longer needed.
386
+ *
387
+ * Calls the native `pdf_credentials_free` FFI function to release
388
+ * memory associated with the credentials handle.
389
+ *
390
+ * @param credentials - The credentials handle to free
391
+ *
392
+ * @example
393
+ * ```typescript
394
+ * const credentials = await sigManager.loadCredentialsPkcs12(path, password);
395
+ * // ... use credentials for signing ...
396
+ * sigManager.freeCredentials(credentials);
397
+ * ```
398
+ */
399
+ freeCredentials(credentials: SigningCredentials): void;
400
+ /**
401
+ * Sign a PDF document in memory using PKCS#12 credentials.
402
+ *
403
+ * Loads credentials from a PKCS#12 file, signs the PDF data, and returns
404
+ * the signed PDF bytes. Credentials are automatically freed after signing.
405
+ *
406
+ * @param pdfData - Buffer containing the PDF document bytes
407
+ * @param filePath - Path to the .p12 or .pfx certificate file
408
+ * @param password - Password for the PKCS#12 file
409
+ * @param options - Optional signing parameters (reason, location, contact, algorithm, subfilter)
410
+ * @returns Buffer containing the signed PDF document
411
+ * @throws SignatureException if credential loading or signing fails
412
+ *
413
+ * @example
414
+ * ```typescript
415
+ * const pdfData = await fs.readFile('document.pdf');
416
+ * const signed = await sigManager.signWithPkcs12(pdfData, 'cert.p12', 'password', {
417
+ * reason: 'Approval',
418
+ * location: 'New York',
419
+ * contact: 'signer@example.com',
420
+ * });
421
+ * await fs.writeFile('signed.pdf', signed);
422
+ * ```
423
+ */
424
+ signWithPkcs12(pdfData: Buffer, filePath: string, password: string, options?: SignOptions): Promise<Buffer>;
425
+ /**
426
+ * Sign a PDF document in memory using PEM credentials.
427
+ *
428
+ * Loads credentials from PEM files, signs the PDF data, and returns
429
+ * the signed PDF bytes. Credentials are automatically freed after signing.
430
+ *
431
+ * @param pdfData - Buffer containing the PDF document bytes
432
+ * @param certFile - Path to the PEM certificate file
433
+ * @param keyFile - Path to the PEM private key file
434
+ * @param options - Optional signing parameters (reason, location, contact, algorithm, subfilter)
435
+ * @returns Buffer containing the signed PDF document
436
+ * @throws SignatureException if credential loading or signing fails
437
+ *
438
+ * @example
439
+ * ```typescript
440
+ * const pdfData = await fs.readFile('document.pdf');
441
+ * const signed = await sigManager.signWithPem(pdfData, 'cert.pem', 'key.pem', {
442
+ * reason: 'Review complete',
443
+ * location: 'London',
444
+ * });
445
+ * await fs.writeFile('signed.pdf', signed);
446
+ * ```
447
+ */
448
+ signWithPem(pdfData: Buffer, certFile: string, keyFile: string, options?: SignOptions): Promise<Buffer>;
449
+ /**
450
+ * Sign a PDF document in memory using pre-loaded credentials.
451
+ *
452
+ * Calls the native `pdf_document_sign` FFI function to apply a digital
453
+ * signature to the PDF data using the provided credentials handle.
454
+ *
455
+ * @param pdfData - Buffer containing the PDF document bytes
456
+ * @param credentials - Pre-loaded signing credentials handle
457
+ * @param options - Optional signing parameters
458
+ * @returns Buffer containing the signed PDF document
459
+ * @throws SignatureException if signing fails
460
+ *
461
+ * @example
462
+ * ```typescript
463
+ * const credentials = await sigManager.loadCredentialsPkcs12(path, password);
464
+ * const signed = await sigManager.signWithCredentials(pdfData, credentials, {
465
+ * reason: 'Approved',
466
+ * algorithm: FfiDigestAlgorithm.SHA256,
467
+ * subfilter: FfiSignatureSubFilter.PKCS7_DETACHED,
468
+ * });
469
+ * sigManager.freeCredentials(credentials);
470
+ * ```
471
+ */
472
+ signWithCredentials(pdfData: Buffer, credentials: SigningCredentials, options?: SignOptions): Promise<Buffer>;
473
+ /**
474
+ * Sign a PDF file on disk and write the signed output to another file.
475
+ *
476
+ * Calls the native `pdf_document_sign_file` FFI function, which reads
477
+ * the input file, applies a digital signature, and writes the result
478
+ * to the output path.
479
+ *
480
+ * @param inputPath - Path to the input PDF file
481
+ * @param outputPath - Path to write the signed PDF file
482
+ * @param credentials - Pre-loaded signing credentials handle
483
+ * @param options - Optional signing parameters
484
+ * @throws SignatureException if file signing fails
485
+ *
486
+ * @example
487
+ * ```typescript
488
+ * const credentials = await sigManager.loadCredentialsPkcs12('cert.p12', 'pass');
489
+ * await sigManager.signFile('input.pdf', 'signed.pdf', credentials, {
490
+ * reason: 'Final approval',
491
+ * location: 'Berlin',
492
+ * });
493
+ * sigManager.freeCredentials(credentials);
494
+ * ```
495
+ */
496
+ signFile(inputPath: string, outputPath: string, credentials: SigningCredentials, options?: SignOptions): Promise<void>;
497
+ /**
498
+ * Embed Long-Term Validation (LTV) data into a signed PDF.
499
+ *
500
+ * Calls the native `pdf_embed_ltv_data` FFI function to add OCSP responses
501
+ * and/or CRL data to the document's DSS (Document Security Store), enabling
502
+ * long-term signature validation even after certificates expire.
503
+ *
504
+ * @param pdfData - Buffer containing the signed PDF document bytes
505
+ * @param ocspData - Optional OCSP response data to embed
506
+ * @param crlData - Optional CRL data to embed
507
+ * @returns Buffer containing the PDF with embedded LTV data
508
+ * @throws SignatureException if LTV embedding fails
509
+ *
510
+ * @example
511
+ * ```typescript
512
+ * const signedPdf = await sigManager.signWithPkcs12(pdfData, 'cert.p12', 'pass');
513
+ * const ocspResponse = await fetch('http://ocsp.example.com/...').then(r => r.buffer());
514
+ * const ltvPdf = await sigManager.embedLtv(signedPdf, ocspResponse);
515
+ * await fs.writeFile('signed-ltv.pdf', ltvPdf);
516
+ * ```
517
+ */
518
+ embedLtv(pdfData: Buffer, ocspData?: Buffer, crlData?: Buffer): Promise<Buffer>;
519
+ /**
520
+ * Save signed PDF bytes to a file.
521
+ *
522
+ * Calls the native `pdf_document_save_signed` FFI function to write
523
+ * signed PDF data to disk.
524
+ *
525
+ * @param pdfData - Buffer containing the signed PDF bytes
526
+ * @param outputPath - Path to write the signed PDF file
527
+ * @throws SignatureException or IoException if saving fails
528
+ *
529
+ * @example
530
+ * ```typescript
531
+ * const signed = await sigManager.signWithPkcs12(pdfData, 'cert.p12', 'pass');
532
+ * await sigManager.saveSigned(signed, '/output/signed.pdf');
533
+ * ```
534
+ */
535
+ saveSigned(pdfData: Buffer, outputPath: string): Promise<void>;
536
+ /**
537
+ * Load signing credentials from raw DER-encoded certificate and key bytes.
538
+ *
539
+ * Calls the native `pdf_credentials_from_der` FFI function to create
540
+ * credentials from in-memory DER-encoded certificate data and an optional
541
+ * private key.
542
+ *
543
+ * @param certData - Buffer containing DER-encoded certificate bytes
544
+ * @param keyData - Optional Buffer containing DER-encoded private key bytes
545
+ * @returns SigningCredentials handle for use with signing methods
546
+ * @throws SignatureException if credential loading fails
547
+ *
548
+ * @example
549
+ * ```typescript
550
+ * const certDer = await fs.readFile('cert.der');
551
+ * const keyDer = await fs.readFile('key.der');
552
+ * const credentials = await sigManager.loadCredentialsFromDer(certDer, keyDer);
553
+ * const signed = await sigManager.signWithCredentials(pdfData, credentials);
554
+ * sigManager.freeCredentials(credentials);
555
+ * ```
556
+ */
557
+ loadCredentialsFromDer(certData: Buffer, keyData?: Buffer): Promise<SigningCredentials>;
558
+ /**
559
+ * Add a certificate chain entry to existing signing credentials.
560
+ *
561
+ * Calls the native `pdf_credentials_add_chain_cert` FFI function to append
562
+ * an intermediate or root CA certificate to the credential's certificate chain.
563
+ * This is used to build a complete certification chain for signature validation.
564
+ *
565
+ * @param credentials - The signing credentials handle to modify
566
+ * @param certData - Buffer containing DER-encoded certificate bytes
567
+ * @throws SignatureException if the chain certificate cannot be added
568
+ *
569
+ * @example
570
+ * ```typescript
571
+ * const credentials = await sigManager.loadCredentialsFromDer(certDer, keyDer);
572
+ * const intermediateCa = await fs.readFile('intermediate-ca.der');
573
+ * await sigManager.addChainCert(credentials, intermediateCa);
574
+ * ```
575
+ */
576
+ addChainCert(credentials: SigningCredentials, certData: Buffer): Promise<void>;
577
+ /**
578
+ * Get the certificate handle from signing credentials.
579
+ *
580
+ * Calls the native `pdf_credentials_get_certificate` FFI function to extract
581
+ * the certificate handle from a credentials object. The returned handle can be
582
+ * used with certificate inspection methods like getCertificateCn, getCertificateIssuer,
583
+ * and getCertificateSize.
584
+ *
585
+ * @param credentials - The signing credentials handle
586
+ * @returns An opaque certificate handle for use with certificate inspection methods
587
+ * @throws SignatureException if the certificate cannot be retrieved
588
+ *
589
+ * @example
590
+ * ```typescript
591
+ * const credentials = await sigManager.loadCredentialsPkcs12('cert.p12', 'pass');
592
+ * const certHandle = await sigManager.getCertificate(credentials);
593
+ * const cn = await sigManager.getCertificateCn(certHandle);
594
+ * console.log(`Certificate CN: ${cn}`);
595
+ * sigManager.freeCredentials(credentials);
596
+ * ```
597
+ */
598
+ getCertificate(credentials: SigningCredentials): Promise<any>;
599
+ /**
600
+ * Load a certificate from raw DER bytes for inspection.
601
+ *
602
+ * Calls the native `pdf_certificate_load_from_bytes` FFI function to create
603
+ * a certificate handle from DER-encoded bytes. This is useful for inspecting
604
+ * certificate properties without creating full signing credentials.
605
+ *
606
+ * @param certData - Buffer containing DER-encoded certificate bytes
607
+ * @returns An opaque certificate handle for use with certificate inspection methods
608
+ * @throws SignatureException if the certificate cannot be loaded
609
+ *
610
+ * @example
611
+ * ```typescript
612
+ * const certDer = await fs.readFile('cert.der');
613
+ * const certHandle = await sigManager.loadCertificateFromDerBytes(certDer);
614
+ * const cn = await sigManager.getCertificateCn(certHandle);
615
+ * const issuer = await sigManager.getCertificateIssuerFromHandle(certHandle);
616
+ * const size = await sigManager.getCertificateSize(certHandle);
617
+ * ```
618
+ */
619
+ loadCertificateFromDerBytes(certData: Buffer): Promise<any>;
620
+ /**
621
+ * Get the common name (CN) from a certificate handle.
622
+ *
623
+ * Calls the native `pdf_certificate_get_cn` FFI function to extract
624
+ * the subject common name from a certificate.
625
+ *
626
+ * @param certHandle - An opaque certificate handle obtained from getCertificate or loadCertificateFromDerBytes
627
+ * @returns The certificate common name string
628
+ * @throws SignatureException if the CN cannot be retrieved
629
+ *
630
+ * @example
631
+ * ```typescript
632
+ * const credentials = await sigManager.loadCredentialsPkcs12('cert.p12', 'pass');
633
+ * const certHandle = await sigManager.getCertificate(credentials);
634
+ * const cn = await sigManager.getCertificateCn(certHandle);
635
+ * console.log(`Signer: ${cn}`);
636
+ * ```
637
+ */
638
+ getCertificateCn(certHandle: any): Promise<string>;
639
+ /**
640
+ * Get the issuer name from a certificate handle.
641
+ *
642
+ * Calls the native `pdf_certificate_get_issuer` FFI function to extract
643
+ * the issuer distinguished name from a certificate.
644
+ *
645
+ * @param certHandle - An opaque certificate handle obtained from getCertificate or loadCertificateFromDerBytes
646
+ * @returns The certificate issuer name string
647
+ * @throws SignatureException if the issuer cannot be retrieved
648
+ *
649
+ * @example
650
+ * ```typescript
651
+ * const certHandle = await sigManager.loadCertificateFromDerBytes(certDer);
652
+ * const issuer = await sigManager.getCertificateIssuerFromHandle(certHandle);
653
+ * console.log(`Issued by: ${issuer}`);
654
+ * ```
655
+ */
656
+ getCertificateIssuerFromHandle(certHandle: any): Promise<string>;
657
+ /**
658
+ * Get the size in bytes of a certificate.
659
+ *
660
+ * Calls the native `pdf_certificate_get_size` FFI function to get the
661
+ * size of the DER-encoded certificate data.
662
+ *
663
+ * @param certHandle - An opaque certificate handle obtained from getCertificate or loadCertificateFromDerBytes
664
+ * @returns The certificate size in bytes
665
+ * @throws SignatureException if the size cannot be retrieved
666
+ *
667
+ * @example
668
+ * ```typescript
669
+ * const certHandle = await sigManager.loadCertificateFromDerBytes(certDer);
670
+ * const size = await sigManager.getCertificateSize(certHandle);
671
+ * console.log(`Certificate size: ${size} bytes`);
672
+ * ```
673
+ */
674
+ getCertificateSize(certHandle: any): Promise<number>;
675
+ /**
676
+ * Free a certificate handle when it is no longer needed.
677
+ *
678
+ * Calls the native `pdf_certificate_free` FFI function to release
679
+ * memory associated with the certificate handle.
680
+ *
681
+ * @param certHandle - The certificate handle to free
682
+ *
683
+ * @example
684
+ * ```typescript
685
+ * const certHandle = await sigManager.loadCertificateFromDerBytes(certDer);
686
+ * const cn = await sigManager.getCertificateCn(certHandle);
687
+ * sigManager.freeCertificate(certHandle);
688
+ * ```
689
+ */
690
+ freeCertificate(certHandle: any): void;
691
+ /**
692
+ * Add an RFC 3161 timestamp to an existing signature via a Time Stamp Authority.
693
+ *
694
+ * Calls the native `pdf_add_timestamp` FFI function.
695
+ *
696
+ * @param pdfData - Buffer containing the signed PDF document bytes
697
+ * @param signatureIndex - Index of the signature to timestamp (0-based)
698
+ * @param tsaUrl - URL of the Time Stamp Authority server
699
+ * @returns Buffer containing the timestamped PDF bytes
700
+ * @throws SignatureException if timestamping fails
701
+ */
702
+ addTimestamp(pdfData: Buffer, signatureIndex: number, tsaUrl: string): Promise<Buffer>;
703
+ /**
704
+ * Sign PDF data with a visible signature appearance on a specific page.
705
+ *
706
+ * @param pdfData - Buffer containing PDF bytes to sign
707
+ * @param credentials - Pre-loaded signing credentials
708
+ * @param pageNum - Page number for appearance (0-based)
709
+ * @param x - X coordinate of appearance box
710
+ * @param y - Y coordinate of appearance box
711
+ * @param width - Width of appearance box
712
+ * @param height - Height of appearance box
713
+ * @param options - Optional signing parameters
714
+ * @returns Buffer containing signed PDF bytes
715
+ * @throws SignatureException if signing fails
716
+ */
717
+ signWithAppearance(pdfData: Buffer, credentials: SigningCredentials, pageNum: number, x: number, y: number, width: number, height: number, options?: SignOptions): Promise<Buffer>;
718
+ clearCache(): void;
719
+ getCacheStats(): Record<string, any>;
720
+ destroy(): void;
721
+ /**
722
+ * Sign a PDF from raw bytes using PEM credentials.
723
+ *
724
+ * Calls the native `signPdfBytes` FFI function (two-pass ByteRange writer).
725
+ * Credentials are loaded and freed within this call.
726
+ *
727
+ * @param pdfData - Buffer containing the PDF document bytes
728
+ * @param certPem - PEM-encoded certificate string
729
+ * @param keyPem - PEM-encoded private key string
730
+ * @param reason - Optional signature reason
731
+ * @param location - Optional signature location
732
+ * @returns Buffer containing the signed PDF
733
+ */
734
+ signPdfData(pdfData: Buffer, certPem: string, keyPem: string, reason?: string, location?: string): Promise<Buffer>;
735
+ private setCached;
736
+ private clearCachePattern;
737
+ }
738
+ export default SignatureManager;