Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre 3.2.0 #222

Merged
merged 3 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +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]
Expand Down
7 changes: 6 additions & 1 deletion packages/placeholder-pdfkit/dist/pdfkitAddPlaceholder.d.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,6 +9,7 @@ export type InputType = {
contactInfo: string;
name: string;
location: string;
signingTime?: Date;
signatureLength?: number;
byteRangePlaceholder?: string;
/**
Expand All @@ -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;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 18 additions & 4 deletions packages/placeholder-pdfkit/dist/pdfkitAddPlaceholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

/**
Expand All @@ -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
Expand All @@ -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();
}
Expand Down
12 changes: 11 additions & 1 deletion packages/placeholder-pdfkit/src/pdfkitAddPlaceholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ 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
* @property {number[]} [widgetRect] [x1, y1, x2, y2] widget rectangle
* @property {string} [appName] Name of the application generating the signature
*/

/**
Expand All @@ -39,10 +41,12 @@ export const pdfkitAddPlaceholder = ({
contactInfo,
name,
location,
signingTime = undefined,
signatureLength = DEFAULT_SIGNATURE_LENGTH,
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
Expand All @@ -58,10 +62,16 @@ 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
Prop_Build: {
Filter: {Name: 'Adobe.PPKLite'},
...(
appName ? {App: {Name: appName}} : {}
),
},
});

if (!pdf._acroform) {
Expand Down
24 changes: 24 additions & 0 deletions packages/placeholder-pdfkit/src/pdfkitAddPlaceholder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,6 +9,7 @@ export type InputType = {
contactInfo: string;
name: string;
location: string;
signingTime?: Date;
signatureLength?: number;
byteRangePlaceholder?: string;
/**
Expand All @@ -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;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

/**
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 11 additions & 1 deletion packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ 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
* @property {number[]} [widgetRect] [x1, y1, x2, y2] widget rectangle
* @property {string} [appName] Name of the application generating the signature
*/

/**
Expand All @@ -43,10 +45,12 @@ export const pdfkitAddPlaceholder = ({
contactInfo,
name,
location,
signingTime = undefined,
signatureLength = DEFAULT_SIGNATURE_LENGTH,
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
Expand All @@ -62,10 +66,16 @@ 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
Prop_Build: {
Filter: {Name: 'Adobe.PPKLite'},
...(
appName ? {App: {Name: appName}} : {}
),
},
});

// Check if pdf already contains acroform field
Expand Down
25 changes: 25 additions & 0 deletions packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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');
});
});
7 changes: 6 additions & 1 deletion packages/placeholder-plain/dist/plainAddPlaceholder.d.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading