From d8c21515fb57de3243c22e42c15087cfb60ce085 Mon Sep 17 00:00:00 2001 From: Valery Buchinsky Date: Thu, 11 Jan 2024 15:57:31 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20Added=20optional=20signingTime?= =?UTF-8?q?=20to=20all=20placeholder=20helpers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 +++ packages/placeholder-pdfkit/src/pdfkitAddPlaceholder.js | 4 +++- packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.js | 4 +++- packages/placeholder-plain/src/plainAddPlaceholder.js | 3 +++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc622232..18ea83e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ * [placeholder-pdf-lib] Includes an `AP` appearance stream for PDF/A compliance; * [placeholder-pdf-lib] Adds `Prop_Build` to describe the signing application; * [placeholder-pdf-lib] Does not require `{useObjectStreams: false}`; +* [placeholder-pdfkit] Accepts `signingTime`; +* [placeholder-pdfkit010] Accepts `signingTime`; +* [placeholder-plain] Accepts `signingTime`; * Bumped version of follow-redirects; ## [3.1.0] diff --git a/packages/placeholder-pdfkit/src/pdfkitAddPlaceholder.js b/packages/placeholder-pdfkit/src/pdfkitAddPlaceholder.js index 333edc8e..8afa73fe 100644 --- a/packages/placeholder-pdfkit/src/pdfkitAddPlaceholder.js +++ b/packages/placeholder-pdfkit/src/pdfkitAddPlaceholder.js @@ -13,6 +13,7 @@ import { * @property {string} contactInfo * @property {string} name * @property {string} location +* @property {Date} [signingTime] * @property {number} [signatureLength] * @property {string} [byteRangePlaceholder] * @property {string} [subFilter] One of SUBFILTER_* from \@signpdf/utils @@ -39,6 +40,7 @@ export const pdfkitAddPlaceholder = ({ contactInfo, name, location, + signingTime = undefined, signatureLength = DEFAULT_SIGNATURE_LENGTH, byteRangePlaceholder = DEFAULT_BYTE_RANGE_PLACEHOLDER, subFilter = SUBFILTER_ADOBE_PKCS7_DETACHED, @@ -58,7 +60,7 @@ export const pdfkitAddPlaceholder = ({ ], Contents: Buffer.from(String.fromCharCode(0).repeat(signatureLength)), Reason: new String(reason), // eslint-disable-line no-new-wrappers - M: new Date(), + M: signingTime ?? new Date(), ContactInfo: new String(contactInfo), // eslint-disable-line no-new-wrappers Name: new String(name), // eslint-disable-line no-new-wrappers Location: new String(location), // eslint-disable-line no-new-wrappers diff --git a/packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.js b/packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.js index cc3524bb..3ddeaed2 100644 --- a/packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.js +++ b/packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.js @@ -16,6 +16,7 @@ import {PDFKitReferenceMock} from './pdfkitReferenceMock'; * @property {string} contactInfo * @property {string} name * @property {string} location +* @property {Date} [signingTime] * @property {number} [signatureLength] * @property {string} [byteRangePlaceholder] * @property {string} [subFilter] One of SUBFILTER_* from \@signpdf/utils @@ -43,6 +44,7 @@ export const pdfkitAddPlaceholder = ({ contactInfo, name, location, + signingTime = undefined, signatureLength = DEFAULT_SIGNATURE_LENGTH, byteRangePlaceholder = DEFAULT_BYTE_RANGE_PLACEHOLDER, subFilter = SUBFILTER_ADOBE_PKCS7_DETACHED, @@ -62,7 +64,7 @@ export const pdfkitAddPlaceholder = ({ ], Contents: Buffer.from(String.fromCharCode(0).repeat(signatureLength)), Reason: new String(reason), // eslint-disable-line no-new-wrappers - M: new Date(), + M: signingTime ?? new Date(), ContactInfo: new String(contactInfo), // eslint-disable-line no-new-wrappers Name: new String(name), // eslint-disable-line no-new-wrappers Location: new String(location), // eslint-disable-line no-new-wrappers diff --git a/packages/placeholder-plain/src/plainAddPlaceholder.js b/packages/placeholder-plain/src/plainAddPlaceholder.js index 67ef3d4b..b53b6ccf 100644 --- a/packages/placeholder-plain/src/plainAddPlaceholder.js +++ b/packages/placeholder-plain/src/plainAddPlaceholder.js @@ -38,6 +38,7 @@ const getAcroFormRef = (slice) => { * @property {string} contactInfo * @property {string} name * @property {string} location +* @property {Date} [signingTime] * @property {number} [signatureLength] * @property {string} [subFilter] One of SUBFILTER_* from \@signpdf/utils * @property {number[]} [widgetRect] [x1, y1, x2, y2] widget rectangle @@ -61,6 +62,7 @@ export const plainAddPlaceholder = ({ contactInfo, name, location, + signingTime = undefined, signatureLength = DEFAULT_SIGNATURE_LENGTH, subFilter = SUBFILTER_ADOBE_PKCS7_DETACHED, widgetRect = [0, 0, 0, 0], @@ -118,6 +120,7 @@ export const plainAddPlaceholder = ({ contactInfo, name, location, + signingTime, signatureLength, subFilter, widgetRect, From c9cb659a52e42441e0898e7b35182a60fef25bbc Mon Sep 17 00:00:00 2001 From: Valery Buchinsky Date: Thu, 11 Jan 2024 16:11:08 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9C=A8=20Accept=20appName=20and=20add=20?= =?UTF-8?q?Prop=5FBuild=20in=20all=20placeholder=20helpers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 12 ++++++++- .../src/pdfkitAddPlaceholder.js | 8 ++++++ .../src/pdfkitAddPlaceholder.test.js | 24 ++++++++++++++++++ .../src/pdfkitAddPlaceholder.js | 8 ++++++ .../src/pdfkitAddPlaceholder.test.js | 25 +++++++++++++++++++ .../src/plainAddPlaceholder.js | 3 +++ .../src/plainAddPlaceholder.test.js | 16 ++++++++++++ 7 files changed, 95 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18ea83e5..2ad6e113 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,17 +4,27 @@ * [utils] Introduced `convertBuffer()` to allow inputs as `Buffer`, `Uint8Array` or `string`; * [utils] The `Signer` abstract class accepts an optional `signingTime`. + * [signpdf] Accepts `Buffer`, `Uint8Array` or `string` as input; + * [signer-p12] Accepts `Buffer`, `Uint8Array` or `string` as input; * [signer-p12] Respects `signingTime` as abstracted in `Signer`; + * [placeholder-pdf-lib] Accepts either a `PDFDoc` or a `PDFPage` to allow adding the placeholder to a specific page rather than always the first one; * [placeholder-pdf-lib] Accepts `signingTime`; * [placeholder-pdf-lib] Includes an `AP` appearance stream for PDF/A compliance; -* [placeholder-pdf-lib] Adds `Prop_Build` to describe the signing application; +* [placeholder-pdf-lib] Accepts `appName` and includes it in `Prop_Build` to allow describing the signing application; * [placeholder-pdf-lib] Does not require `{useObjectStreams: false}`; + * [placeholder-pdfkit] Accepts `signingTime`; +* [placeholder-pdfkit] Accepts `appName` and includes it in `Prop_Build` to allow describing the signing application; + * [placeholder-pdfkit010] Accepts `signingTime`; +* [placeholder-pdfkit010] Accepts `appName` and includes it in `Prop_Build` to allow describing the signing application; + * [placeholder-plain] Accepts `signingTime`; +* [placeholder-plain] Accepts `appName` and includes it in `Prop_Build` to allow describing the signing application; + * Bumped version of follow-redirects; ## [3.1.0] diff --git a/packages/placeholder-pdfkit/src/pdfkitAddPlaceholder.js b/packages/placeholder-pdfkit/src/pdfkitAddPlaceholder.js index 8afa73fe..fab6baea 100644 --- a/packages/placeholder-pdfkit/src/pdfkitAddPlaceholder.js +++ b/packages/placeholder-pdfkit/src/pdfkitAddPlaceholder.js @@ -18,6 +18,7 @@ import { * @property {string} [byteRangePlaceholder] * @property {string} [subFilter] One of SUBFILTER_* from \@signpdf/utils * @property {number[]} [widgetRect] [x1, y1, x2, y2] widget rectangle +* @property {string} [appName] Name of the application generating the signature */ /** @@ -45,6 +46,7 @@ export const pdfkitAddPlaceholder = ({ byteRangePlaceholder = DEFAULT_BYTE_RANGE_PLACEHOLDER, subFilter = SUBFILTER_ADOBE_PKCS7_DETACHED, widgetRect = [0, 0, 0, 0], + appName = undefined, }) => { /* eslint-disable no-underscore-dangle,no-param-reassign */ // Generate the signature placeholder @@ -64,6 +66,12 @@ export const pdfkitAddPlaceholder = ({ ContactInfo: new String(contactInfo), // eslint-disable-line no-new-wrappers Name: new String(name), // eslint-disable-line no-new-wrappers Location: new String(location), // eslint-disable-line no-new-wrappers + Prop_Build: { + Filter: {Name: 'Adobe.PPKLite'}, + ...( + appName ? {App: {Name: appName}} : {} + ), + }, }); if (!pdf._acroform) { diff --git a/packages/placeholder-pdfkit/src/pdfkitAddPlaceholder.test.js b/packages/placeholder-pdfkit/src/pdfkitAddPlaceholder.test.js index 8dfb386a..dc9b11c7 100644 --- a/packages/placeholder-pdfkit/src/pdfkitAddPlaceholder.test.js +++ b/packages/placeholder-pdfkit/src/pdfkitAddPlaceholder.test.js @@ -146,4 +146,28 @@ describe(pdfkitAddPlaceholder, () => { '**********', ]); }); + + it('sets the Prop_Build dictionary for the signature', async () => { + const {pdf} = createPdfkitDocument(PDFDocument, {}); + const widgetRect = [100, 100, 200, 200]; + const refs = pdfkitAddPlaceholder({ + ...defaults, + pdf, + pdfBuffer: Buffer.from([pdf]), + reason: 'test reason', + widgetRect, + appName: 'signpdf', + }); + expect(Object.keys(refs)).toEqual(expect.arrayContaining([ + 'signature', + 'form', + 'widget', + ])); + expect(pdf.page.dictionary.data.Annots).toHaveLength(1); + const widget = pdf.page.dictionary.data.Annots[0]; + const propBuild = widget.data.V.data.Prop_Build; + + expect(propBuild.Filter.Name).toEqual('Adobe.PPKLite'); + expect(propBuild.App.Name).toEqual('signpdf'); + }); }); diff --git a/packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.js b/packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.js index 3ddeaed2..b9bd0aa2 100644 --- a/packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.js +++ b/packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.js @@ -21,6 +21,7 @@ import {PDFKitReferenceMock} from './pdfkitReferenceMock'; * @property {string} [byteRangePlaceholder] * @property {string} [subFilter] One of SUBFILTER_* from \@signpdf/utils * @property {number[]} [widgetRect] [x1, y1, x2, y2] widget rectangle +* @property {string} [appName] Name of the application generating the signature */ /** @@ -49,6 +50,7 @@ export const pdfkitAddPlaceholder = ({ byteRangePlaceholder = DEFAULT_BYTE_RANGE_PLACEHOLDER, subFilter = SUBFILTER_ADOBE_PKCS7_DETACHED, widgetRect = [0, 0, 0, 0], + appName = undefined, }) => { /* eslint-disable no-underscore-dangle,no-param-reassign */ // Generate the signature placeholder @@ -68,6 +70,12 @@ export const pdfkitAddPlaceholder = ({ ContactInfo: new String(contactInfo), // eslint-disable-line no-new-wrappers Name: new String(name), // eslint-disable-line no-new-wrappers Location: new String(location), // eslint-disable-line no-new-wrappers + Prop_Build: { + Filter: {Name: 'Adobe.PPKLite'}, + ...( + appName ? {App: {Name: appName}} : {} + ), + }, }); // Check if pdf already contains acroform field diff --git a/packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.test.js b/packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.test.js index 07d3e508..34252213 100644 --- a/packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.test.js +++ b/packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.test.js @@ -143,6 +143,7 @@ describe(pdfkitAddPlaceholder, () => { 'form', 'widget', ])); + expect(pdf.page.dictionary.data.Annots).toHaveLength(1); expect(pdf.page.dictionary.data.Annots[0].data.Subtype).toEqual('Widget'); expect(pdf.page.dictionary.data.Annots[0].data.V.data.ByteRange).toEqual([ @@ -152,4 +153,28 @@ describe(pdfkitAddPlaceholder, () => { '**********', ]); }); + + it('sets the Prop_Build dictionary for the signature', async () => { + const {pdf} = createPdfkitDocument(PDFDocument, {}); + const widgetRect = [100, 100, 200, 200]; + const refs = pdfkitAddPlaceholder({ + ...defaults, + pdf, + pdfBuffer: Buffer.from([pdf]), + reason: 'test reason', + widgetRect, + appName: 'signpdf', + }); + expect(Object.keys(refs)).toEqual(expect.arrayContaining([ + 'signature', + 'form', + 'widget', + ])); + expect(pdf.page.dictionary.data.Annots).toHaveLength(1); + const widget = pdf.page.dictionary.data.Annots[0]; + const propBuild = widget.data.V.data.Prop_Build; + + expect(propBuild.Filter.Name).toEqual('Adobe.PPKLite'); + expect(propBuild.App.Name).toEqual('signpdf'); + }); }); diff --git a/packages/placeholder-plain/src/plainAddPlaceholder.js b/packages/placeholder-plain/src/plainAddPlaceholder.js index b53b6ccf..f26759b2 100644 --- a/packages/placeholder-plain/src/plainAddPlaceholder.js +++ b/packages/placeholder-plain/src/plainAddPlaceholder.js @@ -42,6 +42,7 @@ const getAcroFormRef = (slice) => { * @property {number} [signatureLength] * @property {string} [subFilter] One of SUBFILTER_* from \@signpdf/utils * @property {number[]} [widgetRect] [x1, y1, x2, y2] widget rectangle +* @property {string} [appName] Name of the application generating the signature */ /** @@ -66,6 +67,7 @@ export const plainAddPlaceholder = ({ signatureLength = DEFAULT_SIGNATURE_LENGTH, subFilter = SUBFILTER_ADOBE_PKCS7_DETACHED, widgetRect = [0, 0, 0, 0], + appName = undefined, }) => { let pdf = removeTrailingNewLine(pdfBuffer); const info = readPdf(pdf); @@ -124,6 +126,7 @@ export const plainAddPlaceholder = ({ signatureLength, subFilter, widgetRect, + appName, }); if (!getAcroFormRef(pdf.toString())) { diff --git a/packages/placeholder-plain/src/plainAddPlaceholder.test.js b/packages/placeholder-plain/src/plainAddPlaceholder.test.js index 9e6ed59a..100e3c9d 100644 --- a/packages/placeholder-plain/src/plainAddPlaceholder.test.js +++ b/packages/placeholder-plain/src/plainAddPlaceholder.test.js @@ -55,4 +55,20 @@ describe(plainAddPlaceholder, () => { expect(output).toBeInstanceOf(Buffer); expect(output.indexOf('/Rect [100 100 200 200]')).not.toBe(-1); }); + + it('sets the Prop_Build dictionary for the signature', async () => { + const input = readTestResource('w3dummy.pdf'); + const output = plainAddPlaceholder({ + pdfBuffer: input, + reason: 'Because I can', + location: 'some place', + name: 'example name', + contactInfo: 'emailfromp1289@gmail.com', + widgetRect: [100, 100, 200, 200], + appName: 'app-name-signpdf', + }); + expect(output).toBeInstanceOf(Buffer); + expect(output.indexOf('/Name /Adobe.PPKLite')).not.toBe(-1); + expect(output.indexOf('/Name /app-name-signpdf')).not.toBe(-1); + }); }); From 481e76124b9856e6af49920201727adc4195dbce Mon Sep 17 00:00:00 2001 From: Valery Buchinsky Date: Thu, 11 Jan 2024 15:59:55 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=93=A6=20Build=203.2.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dist/pdfkitAddPlaceholder.d.ts | 7 +++++- .../dist/pdfkitAddPlaceholder.d.ts.map | 2 +- .../dist/pdfkitAddPlaceholder.js | 22 +++++++++++++++---- .../dist/pdfkitAddPlaceholder.d.ts | 7 +++++- .../dist/pdfkitAddPlaceholder.d.ts.map | 2 +- .../dist/pdfkitAddPlaceholder.js | 21 +++++++++++++++--- .../dist/plainAddPlaceholder.d.ts | 7 +++++- .../dist/plainAddPlaceholder.d.ts.map | 2 +- .../dist/plainAddPlaceholder.js | 10 +++++++-- 9 files changed, 65 insertions(+), 15 deletions(-) diff --git a/packages/placeholder-pdfkit/dist/pdfkitAddPlaceholder.d.ts b/packages/placeholder-pdfkit/dist/pdfkitAddPlaceholder.d.ts index 9c831b12..361ebc40 100644 --- a/packages/placeholder-pdfkit/dist/pdfkitAddPlaceholder.d.ts +++ b/packages/placeholder-pdfkit/dist/pdfkitAddPlaceholder.d.ts @@ -1,4 +1,4 @@ -export function pdfkitAddPlaceholder({ pdf, reason, contactInfo, name, location, signatureLength, byteRangePlaceholder, subFilter, widgetRect, }: InputType): ReturnType; +export function pdfkitAddPlaceholder({ pdf, reason, contactInfo, name, location, signingTime, signatureLength, byteRangePlaceholder, subFilter, widgetRect, appName, }: InputType): ReturnType; export type InputType = { /** * PDFDocument @@ -9,6 +9,7 @@ export type InputType = { contactInfo: string; name: string; location: string; + signingTime?: Date; signatureLength?: number; byteRangePlaceholder?: string; /** @@ -19,6 +20,10 @@ export type InputType = { * [x1, y1, x2, y2] widget rectangle */ widgetRect?: number[]; + /** + * Name of the application generating the signature + */ + appName?: string; }; export type ReturnType = { signature: any; diff --git a/packages/placeholder-pdfkit/dist/pdfkitAddPlaceholder.d.ts.map b/packages/placeholder-pdfkit/dist/pdfkitAddPlaceholder.d.ts.map index 7c6ae9ba..919cce0c 100644 --- a/packages/placeholder-pdfkit/dist/pdfkitAddPlaceholder.d.ts.map +++ b/packages/placeholder-pdfkit/dist/pdfkitAddPlaceholder.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"pdfkitAddPlaceholder.d.ts","sourceRoot":"","sources":["../src/pdfkitAddPlaceholder.js"],"names":[],"mappings":"AAmCO,kJAHI,SAAS,GACP,UAAU,CAqEtB;;;;;SA7FY,MAAM;eACN,MAAM;YACN,MAAM;iBACN,MAAM;UACN,MAAM;cACN,MAAM;sBACN,MAAM;2BACN,MAAM;;;;gBACN,MAAM;;;;iBACN,MAAM,EAAE;;;eAKR,GAAG;UACH,GAAG;YACH,GAAG"} \ No newline at end of file +{"version":3,"file":"pdfkitAddPlaceholder.d.ts","sourceRoot":"","sources":["../src/pdfkitAddPlaceholder.js"],"names":[],"mappings":"AAqCO,wKAHI,SAAS,GACP,UAAU,CA6EtB;;;;;SAvGY,MAAM;eACN,MAAM;YACN,MAAM;iBACN,MAAM;UACN,MAAM;cACN,MAAM;kBACN,IAAI;sBACJ,MAAM;2BACN,MAAM;;;;gBACN,MAAM;;;;iBACN,MAAM,EAAE;;;;cACR,MAAM;;;eAKN,GAAG;UACH,GAAG;YACH,GAAG"} \ No newline at end of file diff --git a/packages/placeholder-pdfkit/dist/pdfkitAddPlaceholder.js b/packages/placeholder-pdfkit/dist/pdfkitAddPlaceholder.js index 58da0f1e..daadb2a3 100644 --- a/packages/placeholder-pdfkit/dist/pdfkitAddPlaceholder.js +++ b/packages/placeholder-pdfkit/dist/pdfkitAddPlaceholder.js @@ -13,10 +13,12 @@ var _utils = require("@signpdf/utils"); * @property {string} contactInfo * @property {string} name * @property {string} location +* @property {Date} [signingTime] * @property {number} [signatureLength] * @property {string} [byteRangePlaceholder] * @property {string} [subFilter] One of SUBFILTER_* from \@signpdf/utils * @property {number[]} [widgetRect] [x1, y1, x2, y2] widget rectangle +* @property {string} [appName] Name of the application generating the signature */ /** @@ -39,10 +41,12 @@ const pdfkitAddPlaceholder = ({ contactInfo, name, location, + signingTime = undefined, signatureLength = _utils.DEFAULT_SIGNATURE_LENGTH, byteRangePlaceholder = _utils.DEFAULT_BYTE_RANGE_PLACEHOLDER, subFilter = _utils.SUBFILTER_ADOBE_PKCS7_DETACHED, - widgetRect = [0, 0, 0, 0] + widgetRect = [0, 0, 0, 0], + appName = undefined }) => { /* eslint-disable no-underscore-dangle,no-param-reassign */ // Generate the signature placeholder @@ -54,14 +58,24 @@ const pdfkitAddPlaceholder = ({ Contents: Buffer.from(String.fromCharCode(0).repeat(signatureLength)), Reason: new String(reason), // eslint-disable-line no-new-wrappers - M: new Date(), + M: signingTime !== null && signingTime !== void 0 ? signingTime : new Date(), ContactInfo: new String(contactInfo), // eslint-disable-line no-new-wrappers Name: new String(name), // eslint-disable-line no-new-wrappers - Location: new String(location) // eslint-disable-line no-new-wrappers + Location: new String(location), + // eslint-disable-line no-new-wrappers + Prop_Build: { + Filter: { + Name: 'Adobe.PPKLite' + }, + ...(appName ? { + App: { + Name: appName + } + } : {}) + } }); - if (!pdf._acroform) { pdf.initForm(); } diff --git a/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts b/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts index 1e24dff0..c8d3e926 100644 --- a/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts +++ b/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts @@ -1,4 +1,4 @@ -export function pdfkitAddPlaceholder({ pdf, pdfBuffer, reason, contactInfo, name, location, signatureLength, byteRangePlaceholder, subFilter, widgetRect, }: InputType): ReturnType; +export function pdfkitAddPlaceholder({ pdf, pdfBuffer, reason, contactInfo, name, location, signingTime, signatureLength, byteRangePlaceholder, subFilter, widgetRect, appName, }: InputType): ReturnType; export type InputType = { /** * PDFDocument @@ -9,6 +9,7 @@ export type InputType = { contactInfo: string; name: string; location: string; + signingTime?: Date; signatureLength?: number; byteRangePlaceholder?: string; /** @@ -19,6 +20,10 @@ export type InputType = { * [x1, y1, x2, y2] widget rectangle */ widgetRect?: number[]; + /** + * Name of the application generating the signature + */ + appName?: string; }; export type ReturnType = { signature: any; diff --git a/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts.map b/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts.map index f4604ecd..966e3c86 100644 --- a/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts.map +++ b/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"pdfkitAddPlaceholder.d.ts","sourceRoot":"","sources":["../src/pdfkitAddPlaceholder.js"],"names":[],"mappings":"AAsCO,6JAHI,SAAS,GACP,UAAU,CAmHtB;;;;;SA3IY,MAAM;eACN,MAAM;YACN,MAAM;iBACN,MAAM;UACN,MAAM;cACN,MAAM;sBACN,MAAM;2BACN,MAAM;;;;gBACN,MAAM;;;;iBACN,MAAM,EAAE;;;eAKR,GAAG;UACH,GAAG;YACH,GAAG"} \ No newline at end of file +{"version":3,"file":"pdfkitAddPlaceholder.d.ts","sourceRoot":"","sources":["../src/pdfkitAddPlaceholder.js"],"names":[],"mappings":"AAwCO,mLAHI,SAAS,GACP,UAAU,CA2HtB;;;;;SArJY,MAAM;eACN,MAAM;YACN,MAAM;iBACN,MAAM;UACN,MAAM;cACN,MAAM;kBACN,IAAI;sBACJ,MAAM;2BACN,MAAM;;;;gBACN,MAAM;;;;iBACN,MAAM,EAAE;;;;cACR,MAAM;;;eAKN,GAAG;UACH,GAAG;YACH,GAAG"} \ No newline at end of file diff --git a/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.js b/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.js index 88d3a63d..fa0be4e3 100644 --- a/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.js +++ b/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.js @@ -16,10 +16,12 @@ var _pdfkitReferenceMock = require("./pdfkitReferenceMock"); * @property {string} contactInfo * @property {string} name * @property {string} location +* @property {Date} [signingTime] * @property {number} [signatureLength] * @property {string} [byteRangePlaceholder] * @property {string} [subFilter] One of SUBFILTER_* from \@signpdf/utils * @property {number[]} [widgetRect] [x1, y1, x2, y2] widget rectangle +* @property {string} [appName] Name of the application generating the signature */ /** @@ -43,10 +45,12 @@ const pdfkitAddPlaceholder = ({ contactInfo, name, location, + signingTime = undefined, signatureLength = _utils.DEFAULT_SIGNATURE_LENGTH, byteRangePlaceholder = _utils.DEFAULT_BYTE_RANGE_PLACEHOLDER, subFilter = _utils.SUBFILTER_ADOBE_PKCS7_DETACHED, - widgetRect = [0, 0, 0, 0] + widgetRect = [0, 0, 0, 0], + appName = undefined }) => { /* eslint-disable no-underscore-dangle,no-param-reassign */ // Generate the signature placeholder @@ -58,12 +62,23 @@ const pdfkitAddPlaceholder = ({ Contents: Buffer.from(String.fromCharCode(0).repeat(signatureLength)), Reason: new String(reason), // eslint-disable-line no-new-wrappers - M: new Date(), + M: signingTime !== null && signingTime !== void 0 ? signingTime : new Date(), ContactInfo: new String(contactInfo), // eslint-disable-line no-new-wrappers Name: new String(name), // eslint-disable-line no-new-wrappers - Location: new String(location) // eslint-disable-line no-new-wrappers + Location: new String(location), + // eslint-disable-line no-new-wrappers + Prop_Build: { + Filter: { + Name: 'Adobe.PPKLite' + }, + ...(appName ? { + App: { + Name: appName + } + } : {}) + } }); // Check if pdf already contains acroform field diff --git a/packages/placeholder-plain/dist/plainAddPlaceholder.d.ts b/packages/placeholder-plain/dist/plainAddPlaceholder.d.ts index 10320769..f18f592e 100644 --- a/packages/placeholder-plain/dist/plainAddPlaceholder.d.ts +++ b/packages/placeholder-plain/dist/plainAddPlaceholder.d.ts @@ -1,10 +1,11 @@ -export function plainAddPlaceholder({ pdfBuffer, reason, contactInfo, name, location, signatureLength, subFilter, widgetRect, }: InputType): Buffer; +export function plainAddPlaceholder({ pdfBuffer, reason, contactInfo, name, location, signingTime, signatureLength, subFilter, widgetRect, appName, }: InputType): Buffer; export type InputType = { pdfBuffer: Buffer; reason: string; contactInfo: string; name: string; location: string; + signingTime?: Date; signatureLength?: number; /** * One of SUBFILTER_* from \@signpdf/utils @@ -14,5 +15,9 @@ export type InputType = { * [x1, y1, x2, y2] widget rectangle */ widgetRect?: number[]; + /** + * Name of the application generating the signature + */ + appName?: string; }; //# sourceMappingURL=plainAddPlaceholder.d.ts.map \ No newline at end of file diff --git a/packages/placeholder-plain/dist/plainAddPlaceholder.d.ts.map b/packages/placeholder-plain/dist/plainAddPlaceholder.d.ts.map index e40bbc1e..3d2edf47 100644 --- a/packages/placeholder-plain/dist/plainAddPlaceholder.d.ts.map +++ b/packages/placeholder-plain/dist/plainAddPlaceholder.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"plainAddPlaceholder.d.ts","sourceRoot":"","sources":["../src/plainAddPlaceholder.js"],"names":[],"mappings":"AAyDO,iIAHI,SAAS,GACP,MAAM,CA6FlB;;eAjHY,MAAM;YACN,MAAM;iBACN,MAAM;UACN,MAAM;cACN,MAAM;sBACN,MAAM;;;;gBACN,MAAM;;;;iBACN,MAAM,EAAE"} \ No newline at end of file +{"version":3,"file":"plainAddPlaceholder.d.ts","sourceRoot":"","sources":["../src/plainAddPlaceholder.js"],"names":[],"mappings":"AA2DO,uJAHI,SAAS,GACP,MAAM,CAiGlB;;eAvHY,MAAM;YACN,MAAM;iBACN,MAAM;UACN,MAAM;cACN,MAAM;kBACN,IAAI;sBACJ,MAAM;;;;gBACN,MAAM;;;;iBACN,MAAM,EAAE;;;;cACR,MAAM"} \ No newline at end of file diff --git a/packages/placeholder-plain/dist/plainAddPlaceholder.js b/packages/placeholder-plain/dist/plainAddPlaceholder.js index 39015ae5..4a7e13f8 100644 --- a/packages/placeholder-plain/dist/plainAddPlaceholder.js +++ b/packages/placeholder-plain/dist/plainAddPlaceholder.js @@ -35,9 +35,11 @@ const getAcroFormRef = slice => { * @property {string} contactInfo * @property {string} name * @property {string} location +* @property {Date} [signingTime] * @property {number} [signatureLength] * @property {string} [subFilter] One of SUBFILTER_* from \@signpdf/utils * @property {number[]} [widgetRect] [x1, y1, x2, y2] widget rectangle +* @property {string} [appName] Name of the application generating the signature */ /** @@ -58,9 +60,11 @@ const plainAddPlaceholder = ({ contactInfo, name, location, + signingTime = undefined, signatureLength = _utils.DEFAULT_SIGNATURE_LENGTH, subFilter = _utils.SUBFILTER_ADOBE_PKCS7_DETACHED, - widgetRect = [0, 0, 0, 0] + widgetRect = [0, 0, 0, 0], + appName = undefined }) => { let pdf = (0, _utils.removeTrailingNewLine)(pdfBuffer); const info = (0, _readPdf.default)(pdf); @@ -101,9 +105,11 @@ const plainAddPlaceholder = ({ contactInfo, name, location, + signingTime, signatureLength, subFilter, - widgetRect + widgetRect, + appName }); if (!getAcroFormRef(pdf.toString())) { const rootIndex = (0, _getIndexFromRef.default)(info.xref, info.rootRef);