diff --git a/dist/SignPdfError.js b/dist/SignPdfError.js deleted file mode 100644 index a46e7f97..00000000 --- a/dist/SignPdfError.js +++ /dev/null @@ -1,30 +0,0 @@ -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = exports.ERROR_VERIFY_SIGNATURE = exports.ERROR_TYPE_UNKNOWN = exports.ERROR_TYPE_PARSE = exports.ERROR_TYPE_INPUT = void 0; -const ERROR_TYPE_UNKNOWN = 1; -exports.ERROR_TYPE_UNKNOWN = ERROR_TYPE_UNKNOWN; -const ERROR_TYPE_INPUT = 2; -exports.ERROR_TYPE_INPUT = ERROR_TYPE_INPUT; -const ERROR_TYPE_PARSE = 3; -exports.ERROR_TYPE_PARSE = ERROR_TYPE_PARSE; -const ERROR_VERIFY_SIGNATURE = 4; -exports.ERROR_VERIFY_SIGNATURE = ERROR_VERIFY_SIGNATURE; - -class SignPdfError extends Error { - constructor(msg, type = ERROR_TYPE_UNKNOWN) { - super(msg); - this.type = type; - } - -} // Shorthand - - -SignPdfError.TYPE_UNKNOWN = ERROR_TYPE_UNKNOWN; -SignPdfError.TYPE_INPUT = ERROR_TYPE_INPUT; -SignPdfError.TYPE_PARSE = ERROR_TYPE_PARSE; -SignPdfError.VERIFY_SIGNATURE = ERROR_VERIFY_SIGNATURE; -var _default = SignPdfError; -exports.default = _default; \ No newline at end of file diff --git a/dist/helpers/const.d.ts.map b/dist/helpers/const.d.ts.map deleted file mode 100644 index d3877a4a..00000000 --- a/dist/helpers/const.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../src/helpers/const.js"],"names":[],"mappings":"AAAA,4CAA6C;AAC7C,0DAA2D;AAC3D,mEAAoE;AACpE,2DAA4D;AAC5D,6DAA8D;AAC9D,kEAAmE"} \ No newline at end of file diff --git a/dist/helpers/const.js b/dist/helpers/const.js deleted file mode 100644 index 7b2d8672..00000000 --- a/dist/helpers/const.js +++ /dev/null @@ -1,18 +0,0 @@ -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.SUBFILTER_ETSI_CADES_DETACHED = exports.SUBFILTER_ADOBE_X509_SHA1 = exports.SUBFILTER_ADOBE_PKCS7_SHA1 = exports.SUBFILTER_ADOBE_PKCS7_DETACHED = exports.DEFAULT_SIGNATURE_LENGTH = exports.DEFAULT_BYTE_RANGE_PLACEHOLDER = void 0; -const DEFAULT_SIGNATURE_LENGTH = 8192; -exports.DEFAULT_SIGNATURE_LENGTH = DEFAULT_SIGNATURE_LENGTH; -const DEFAULT_BYTE_RANGE_PLACEHOLDER = '**********'; -exports.DEFAULT_BYTE_RANGE_PLACEHOLDER = DEFAULT_BYTE_RANGE_PLACEHOLDER; -const SUBFILTER_ADOBE_PKCS7_DETACHED = 'adbe.pkcs7.detached'; -exports.SUBFILTER_ADOBE_PKCS7_DETACHED = SUBFILTER_ADOBE_PKCS7_DETACHED; -const SUBFILTER_ADOBE_PKCS7_SHA1 = 'adbe.pkcs7.sha1'; -exports.SUBFILTER_ADOBE_PKCS7_SHA1 = SUBFILTER_ADOBE_PKCS7_SHA1; -const SUBFILTER_ADOBE_X509_SHA1 = 'adbe.x509.rsa.sha1'; -exports.SUBFILTER_ADOBE_X509_SHA1 = SUBFILTER_ADOBE_X509_SHA1; -const SUBFILTER_ETSI_CADES_DETACHED = 'ETSI.CAdES.detached'; -exports.SUBFILTER_ETSI_CADES_DETACHED = SUBFILTER_ETSI_CADES_DETACHED; \ No newline at end of file diff --git a/dist/helpers/extractSignature.d.ts b/dist/helpers/extractSignature.d.ts deleted file mode 100644 index 076088bb..00000000 --- a/dist/helpers/extractSignature.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -export default extractSignature; -/** - * Basic implementation of signature extraction. - * - * Really basic. Would work in the simplest of cases where there is only one signature - * in a document and ByteRange is only used once in it. - * - * @param {Buffer} pdf - * @returns {Object} {ByteRange: Number[], signature: Buffer, signedData: Buffer} - */ -declare function extractSignature(pdf: Buffer, signatureCount?: number): any; -//# sourceMappingURL=extractSignature.d.ts.map \ No newline at end of file diff --git a/dist/helpers/extractSignature.d.ts.map b/dist/helpers/extractSignature.d.ts.map deleted file mode 100644 index c7b355ca..00000000 --- a/dist/helpers/extractSignature.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"extractSignature.d.ts","sourceRoot":"","sources":["../../src/helpers/extractSignature.js"],"names":[],"mappings":";AAaA;;;;;;;;GAQG;AACH,uCAHW,MAAM,gCAsDhB"} \ No newline at end of file diff --git a/dist/helpers/findByteRange.d.ts b/dist/helpers/findByteRange.d.ts deleted file mode 100644 index c76d37b8..00000000 --- a/dist/helpers/findByteRange.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -export default findByteRange; -/** - * Finds ByteRange information within a given PDF Buffer if one exists - * - * @param {Buffer} pdf - * @returns {Object} {byteRangePlaceholder: String, byteRangeStrings: String[], byteRange: String[]} - */ -declare function findByteRange(pdf: Buffer): any; -//# sourceMappingURL=findByteRange.d.ts.map \ No newline at end of file diff --git a/dist/helpers/findByteRange.d.ts.map b/dist/helpers/findByteRange.d.ts.map deleted file mode 100644 index decbc4d8..00000000 --- a/dist/helpers/findByteRange.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"findByteRange.d.ts","sourceRoot":"","sources":["../../src/helpers/findByteRange.js"],"names":[],"mappings":";AAGA;;;;;GAKG;AACH,oCAHW,MAAM,OA4BhB"} \ No newline at end of file diff --git a/dist/helpers/index.d.ts b/dist/helpers/index.d.ts deleted file mode 100644 index d17f3702..00000000 --- a/dist/helpers/index.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -export { default as extractSignature } from "./extractSignature"; -export { default as pdfkitAddPlaceholder } from "./pdfkitAddPlaceholder"; -export { default as plainAddPlaceholder } from "./plainAddPlaceholder"; -export { default as removeTrailingNewLine } from "./removeTrailingNewLine"; -export { default as findByteRange } from "./findByteRange"; -//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/helpers/index.js b/dist/helpers/index.js deleted file mode 100644 index 3c44df91..00000000 --- a/dist/helpers/index.js +++ /dev/null @@ -1,49 +0,0 @@ -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -Object.defineProperty(exports, "extractSignature", { - enumerable: true, - get: function () { - return _extractSignature.default; - } -}); -Object.defineProperty(exports, "findByteRange", { - enumerable: true, - get: function () { - return _findByteRange.default; - } -}); -Object.defineProperty(exports, "pdfkitAddPlaceholder", { - enumerable: true, - get: function () { - return _pdfkitAddPlaceholder.default; - } -}); -Object.defineProperty(exports, "plainAddPlaceholder", { - enumerable: true, - get: function () { - return _plainAddPlaceholder.default; - } -}); -Object.defineProperty(exports, "removeTrailingNewLine", { - enumerable: true, - get: function () { - return _removeTrailingNewLine.default; - } -}); - -var _extractSignature = _interopRequireDefault(require("./extractSignature")); - -var _pdfkitAddPlaceholder = _interopRequireDefault(require("./pdfkitAddPlaceholder")); - -var _plainAddPlaceholder = _interopRequireDefault(require("./plainAddPlaceholder")); - -var _removeTrailingNewLine = _interopRequireDefault(require("./removeTrailingNewLine")); - -var _findByteRange = _interopRequireDefault(require("./findByteRange")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -'This string is added so that jest collects coverage for this file'; // eslint-disable-line \ No newline at end of file diff --git a/dist/helpers/pdfkit/abstract_reference.d.ts.map b/dist/helpers/pdfkit/abstract_reference.d.ts.map deleted file mode 100644 index 2de634d1..00000000 --- a/dist/helpers/pdfkit/abstract_reference.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"abstract_reference.d.ts","sourceRoot":"","sources":["../../../src/helpers/pdfkit/abstract_reference.js"],"names":[],"mappings":";AAWA;IACI,iBAEC;CACJ"} \ No newline at end of file diff --git a/dist/helpers/pdfkit/pdfobject.d.ts.map b/dist/helpers/pdfkit/pdfobject.d.ts.map deleted file mode 100644 index f66e3475..00000000 --- a/dist/helpers/pdfkit/pdfobject.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"pdfobject.d.ts","sourceRoot":"","sources":["../../../src/helpers/pdfkit/pdfobject.js"],"names":[],"mappings":"AA8BA;IACI,kDAuFC;IAED,8BAMC;CACJ"} \ No newline at end of file diff --git a/dist/helpers/pdfkitAddPlaceholder.d.ts b/dist/helpers/pdfkitAddPlaceholder.d.ts deleted file mode 100644 index 5baa7bd6..00000000 --- a/dist/helpers/pdfkitAddPlaceholder.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -export default pdfkitAddPlaceholder; -/** - * Adds the objects that are needed for Adobe.PPKLite to read the signature. - * Also includes a placeholder for the actual signature. - * Returns an Object with all the added PDFReferences. - * @param {PDFDocument} pdf - * @param {string} reason - * @returns {object} - */ -declare function pdfkitAddPlaceholder({ pdf, pdfBuffer, reason, contactInfo, name, location, signatureLength, byteRangePlaceholder, subFilter, }: PDFDocument): object; -//# sourceMappingURL=pdfkitAddPlaceholder.d.ts.map \ No newline at end of file diff --git a/dist/helpers/pdfkitAddPlaceholder.d.ts.map b/dist/helpers/pdfkitAddPlaceholder.d.ts.map deleted file mode 100644 index eae35ac8..00000000 --- a/dist/helpers/pdfkitAddPlaceholder.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"pdfkitAddPlaceholder.d.ts","sourceRoot":"","sources":["../../src/helpers/pdfkitAddPlaceholder.js"],"names":[],"mappings":";AAGA;;;;;;;GAOG;AACH,gKAFa,MAAM,CAgHlB"} \ No newline at end of file diff --git a/dist/helpers/pdfkitReferenceMock.d.ts.map b/dist/helpers/pdfkitReferenceMock.d.ts.map deleted file mode 100644 index 73dee447..00000000 --- a/dist/helpers/pdfkitReferenceMock.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"pdfkitReferenceMock.d.ts","sourceRoot":"","sources":["../../src/helpers/pdfkitReferenceMock.js"],"names":[],"mappings":";AAEA;IACI,8CAMC;IAJG,WAAkB;IAMtB,mBAEC;CACJ;iCAdgC,6BAA6B"} \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/createBufferPageWithAnnotation.d.ts.map b/dist/helpers/plainAddPlaceholder/createBufferPageWithAnnotation.d.ts.map deleted file mode 100644 index ea957c04..00000000 --- a/dist/helpers/plainAddPlaceholder/createBufferPageWithAnnotation.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"createBufferPageWithAnnotation.d.ts","sourceRoot":"","sources":["../../../src/helpers/plainAddPlaceholder/createBufferPageWithAnnotation.js"],"names":[],"mappings":";AAGA,yGAkCC"} \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/createBufferRootWithAcroform.d.ts.map b/dist/helpers/plainAddPlaceholder/createBufferRootWithAcroform.d.ts.map deleted file mode 100644 index 212271a4..00000000 --- a/dist/helpers/plainAddPlaceholder/createBufferRootWithAcroform.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"createBufferRootWithAcroform.d.ts","sourceRoot":"","sources":["../../../src/helpers/plainAddPlaceholder/createBufferRootWithAcroform.js"],"names":[],"mappings":";AAEA,sFAUC"} \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/createBufferTrailer.d.ts b/dist/helpers/plainAddPlaceholder/createBufferTrailer.d.ts deleted file mode 100644 index 4ba23112..00000000 --- a/dist/helpers/plainAddPlaceholder/createBufferTrailer.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export default createBufferTrailer; -declare function createBufferTrailer(pdf: any, info: any, addedReferences: any): Buffer; -//# sourceMappingURL=createBufferTrailer.d.ts.map \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/createBufferTrailer.d.ts.map b/dist/helpers/plainAddPlaceholder/createBufferTrailer.d.ts.map deleted file mode 100644 index caa0b970..00000000 --- a/dist/helpers/plainAddPlaceholder/createBufferTrailer.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"createBufferTrailer.d.ts","sourceRoot":"","sources":["../../../src/helpers/plainAddPlaceholder/createBufferTrailer.js"],"names":[],"mappings":";AAAA,wFAyBC"} \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/findObject.d.ts.map b/dist/helpers/plainAddPlaceholder/findObject.d.ts.map deleted file mode 100644 index ff43464b..00000000 --- a/dist/helpers/plainAddPlaceholder/findObject.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"findObject.d.ts","sourceRoot":"","sources":["../../../src/helpers/plainAddPlaceholder/findObject.js"],"names":[],"mappings":";AAEA;;;;GAIG;AACH,iCAJW,MAAM,sCAEJ,MAAM,CAalB"} \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/getIndexFromRef.d.ts.map b/dist/helpers/plainAddPlaceholder/getIndexFromRef.d.ts.map deleted file mode 100644 index c454c6d8..00000000 --- a/dist/helpers/plainAddPlaceholder/getIndexFromRef.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"getIndexFromRef.d.ts","sourceRoot":"","sources":["../../../src/helpers/plainAddPlaceholder/getIndexFromRef.js"],"names":[],"mappings":";AAEA;;;;GAIG;AACH,2CAJW,MAAM,OACN,MAAM,GACJ,MAAM,CAalB"} \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/getPageRef.d.ts.map b/dist/helpers/plainAddPlaceholder/getPageRef.d.ts.map deleted file mode 100644 index 00c54011..00000000 --- a/dist/helpers/plainAddPlaceholder/getPageRef.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"getPageRef.d.ts","sourceRoot":"","sources":["../../../src/helpers/plainAddPlaceholder/getPageRef.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,8CAHW,MAAM,qBAYhB"} \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/getPagesDictionaryRef.d.ts.map b/dist/helpers/plainAddPlaceholder/getPagesDictionaryRef.d.ts.map deleted file mode 100644 index 6d6c5294..00000000 --- a/dist/helpers/plainAddPlaceholder/getPagesDictionaryRef.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"getPagesDictionaryRef.d.ts","sourceRoot":"","sources":["../../../src/helpers/plainAddPlaceholder/getPagesDictionaryRef.js"],"names":[],"mappings":"AAEA;;GAEG;AAEH,iEAWC"} \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/index.d.ts b/dist/helpers/plainAddPlaceholder/index.d.ts deleted file mode 100644 index 0325c480..00000000 --- a/dist/helpers/plainAddPlaceholder/index.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -export default plainAddPlaceholder; -/** - * Adds a signature placeholder to a PDF Buffer. - * - * This contrasts with the default pdfkit-based implementation. - * Parsing is done using simple string operations. - * Adding is done with `Buffer.concat`. - * This allows node-signpdf to be used on any PDF and - * not only on a freshly created through PDFKit one. - */ -declare function plainAddPlaceholder({ pdfBuffer, reason, contactInfo, name, location, signatureLength, subFilter, }: { - pdfBuffer: any; - reason: any; - contactInfo?: string; - name?: string; - location?: string; - signatureLength?: number; - subFilter?: string; -}): Buffer; -//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/index.d.ts.map b/dist/helpers/plainAddPlaceholder/index.d.ts.map deleted file mode 100644 index 031109c2..00000000 --- a/dist/helpers/plainAddPlaceholder/index.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/plainAddPlaceholder/index.js"],"names":[],"mappings":";AAoBA;;;;;;;;GAQG;AACH;;;;;;;;WAoFC"} \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/readPdf.d.ts b/dist/helpers/plainAddPlaceholder/readPdf.d.ts deleted file mode 100644 index e51fcdac..00000000 --- a/dist/helpers/plainAddPlaceholder/readPdf.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -export default readPdf; -/** - * Simplified parsing of a PDF Buffer. - * Extracts reference table, root info and trailer start. - * - * See section 7.5.5 (File Trailer) of the PDF specs. - * - * @param {Buffer} pdfBuffer - */ -declare function readPdf(pdfBuffer: Buffer): { - xref: any; - rootRef: any; - root: any; - infoRef: any; - trailerStart: number; - previousXrefs: any[]; - xRefPosition: string; -}; -//# sourceMappingURL=readPdf.d.ts.map \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/readPdf.d.ts.map b/dist/helpers/plainAddPlaceholder/readPdf.d.ts.map deleted file mode 100644 index 1388049f..00000000 --- a/dist/helpers/plainAddPlaceholder/readPdf.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"readPdf.d.ts","sourceRoot":"","sources":["../../../src/helpers/plainAddPlaceholder/readPdf.js"],"names":[],"mappings":";AAkBA;;;;;;;GAOG;AACH,oCAFW,MAAM;;;;;;;;EA2BhB"} \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/readRefTable.d.ts b/dist/helpers/plainAddPlaceholder/readRefTable.d.ts deleted file mode 100644 index 0d9015fe..00000000 --- a/dist/helpers/plainAddPlaceholder/readRefTable.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -export function getLastTrailerPosition(pdf: any): number; -export function getXref(pdf: any, position: any): { - size: any; - prev: string; - xRefContent: Map; -}; -export function getFullXrefTable(pdf: any): any; -export default readRefTable; -/** - * @param {Buffer} pdfBuffer - * @returns {object} - */ -declare function readRefTable(pdf: any): object; -//# sourceMappingURL=readRefTable.d.ts.map \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/readRefTable.d.ts.map b/dist/helpers/plainAddPlaceholder/readRefTable.d.ts.map deleted file mode 100644 index 3848c5e1..00000000 --- a/dist/helpers/plainAddPlaceholder/readRefTable.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"readRefTable.d.ts","sourceRoot":"","sources":["../../../src/helpers/plainAddPlaceholder/readRefTable.js"],"names":[],"mappings":"AAGO,yDASN;AAEM;;;;EAmEN;AAEM,gDAgBN;;AAED;;;GAGG;AACH,yCAFa,MAAM,CAYlB"} \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/xrefToRefMap.d.ts.map b/dist/helpers/plainAddPlaceholder/xrefToRefMap.d.ts.map deleted file mode 100644 index 56e3ff0c..00000000 --- a/dist/helpers/plainAddPlaceholder/xrefToRefMap.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"xrefToRefMap.d.ts","sourceRoot":"","sources":["../../../src/helpers/plainAddPlaceholder/xrefToRefMap.js"],"names":[],"mappings":";AAEA,8DA2CC"} \ No newline at end of file diff --git a/dist/helpers/removeTrailingNewLine.d.ts b/dist/helpers/removeTrailingNewLine.d.ts deleted file mode 100644 index 9b71ef66..00000000 --- a/dist/helpers/removeTrailingNewLine.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -export default removeTrailingNewLine; -/** - * Removes a trailing new line if there is such. - * - * Also makes sure the file ends with an EOF line as per spec. - * @param {Buffer} pdf - * @returns {Buffer} - */ -declare function removeTrailingNewLine(pdf: Buffer): Buffer; -//# sourceMappingURL=removeTrailingNewLine.d.ts.map \ No newline at end of file diff --git a/dist/helpers/removeTrailingNewLine.d.ts.map b/dist/helpers/removeTrailingNewLine.d.ts.map deleted file mode 100644 index fed5c0b2..00000000 --- a/dist/helpers/removeTrailingNewLine.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"removeTrailingNewLine.d.ts","sourceRoot":"","sources":["../../src/helpers/removeTrailingNewLine.js"],"names":[],"mappings":";AAWA;;;;;;GAMG;AACH,4CAHW,MAAM,GACJ,MAAM,CAuBlB"} \ No newline at end of file diff --git a/dist/signpdf.d.ts b/dist/signpdf.d.ts deleted file mode 100644 index f78e85bd..00000000 --- a/dist/signpdf.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -export { default as SignPdfError } from "./SignPdfError"; -export * from "./helpers"; -export * from "./helpers/const"; -export class SignPdf { - byteRangePlaceholder: string; - lastSignature: string; - sign(pdfBuffer: any, p12Buffer: any, additionalOptions?: {}): Buffer; -} -declare const _default: SignPdf; -export default _default; -//# sourceMappingURL=signpdf.d.ts.map \ No newline at end of file diff --git a/dist/signpdf.d.ts.map b/dist/signpdf.d.ts.map deleted file mode 100644 index 79efa55a..00000000 --- a/dist/signpdf.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"signpdf.d.ts","sourceRoot":"","sources":["../src/signpdf.js"],"names":[],"mappings":";;;AAUA;IAEQ,6BAA0D;IAC1D,sBAAyB;IAG7B,qEA0KC;CACJ"} \ No newline at end of file diff --git a/packages/placeholder-pdfkit010/dist/index.d.ts b/packages/placeholder-pdfkit010/dist/index.d.ts new file mode 100644 index 00000000..09d16c83 --- /dev/null +++ b/packages/placeholder-pdfkit010/dist/index.d.ts @@ -0,0 +1,4 @@ +export * from "./pdfkitAddPlaceholder"; +export * from "./pdfkitReferenceMock"; +export { default as PDFObject } from "./pdfkit/pdfobject"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/helpers/index.d.ts.map b/packages/placeholder-pdfkit010/dist/index.d.ts.map similarity index 55% rename from dist/helpers/index.d.ts.map rename to packages/placeholder-pdfkit010/dist/index.d.ts.map index a035e746..6e08bd54 100644 --- a/dist/helpers/index.d.ts.map +++ b/packages/placeholder-pdfkit010/dist/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.js"],"names":[],"mappings":""} \ No newline at end of file +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":""} \ No newline at end of file diff --git a/packages/placeholder-pdfkit010/dist/index.js b/packages/placeholder-pdfkit010/dist/index.js new file mode 100644 index 00000000..d10b5dc5 --- /dev/null +++ b/packages/placeholder-pdfkit010/dist/index.js @@ -0,0 +1,40 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +var _exportNames = { + PDFObject: true +}; +Object.defineProperty(exports, "PDFObject", { + enumerable: true, + get: function () { + return _pdfobject.default; + } +}); +var _pdfkitAddPlaceholder = require("./pdfkitAddPlaceholder"); +Object.keys(_pdfkitAddPlaceholder).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; + if (key in exports && exports[key] === _pdfkitAddPlaceholder[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _pdfkitAddPlaceholder[key]; + } + }); +}); +var _pdfkitReferenceMock = require("./pdfkitReferenceMock"); +Object.keys(_pdfkitReferenceMock).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; + if (key in exports && exports[key] === _pdfkitReferenceMock[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _pdfkitReferenceMock[key]; + } + }); +}); +var _pdfobject = _interopRequireDefault(require("./pdfkit/pdfobject")); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } \ No newline at end of file diff --git a/dist/helpers/pdfkit/abstract_reference.d.ts b/packages/placeholder-pdfkit010/dist/pdfkit/abstract_reference.d.ts similarity index 100% rename from dist/helpers/pdfkit/abstract_reference.d.ts rename to packages/placeholder-pdfkit010/dist/pdfkit/abstract_reference.d.ts diff --git a/packages/placeholder-pdfkit010/dist/pdfkit/abstract_reference.d.ts.map b/packages/placeholder-pdfkit010/dist/pdfkit/abstract_reference.d.ts.map new file mode 100644 index 00000000..e3f37b0b --- /dev/null +++ b/packages/placeholder-pdfkit010/dist/pdfkit/abstract_reference.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"abstract_reference.d.ts","sourceRoot":"","sources":["../../src/pdfkit/abstract_reference.js"],"names":[],"mappings":";AAWA;IACI,iBAEC;CACJ"} \ No newline at end of file diff --git a/dist/helpers/pdfkit/abstract_reference.js b/packages/placeholder-pdfkit010/dist/pdfkit/abstract_reference.js similarity index 88% rename from dist/helpers/pdfkit/abstract_reference.js rename to packages/placeholder-pdfkit010/dist/pdfkit/abstract_reference.js index d68dbff2..62bf7118 100644 --- a/dist/helpers/pdfkit/abstract_reference.js +++ b/packages/placeholder-pdfkit010/dist/pdfkit/abstract_reference.js @@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; - /* PDFAbstractReference by Devon Govett used below. The class is part of pdfkit. See https://github.com/foliojs/pdfkit @@ -15,12 +14,10 @@ Modifications may have been applied for the purposes of node-signpdf. /* PDFAbstractReference - abstract class for PDF reference */ + class PDFAbstractReference { toString() { throw new Error('Must be implemented by subclasses'); } - } - -var _default = PDFAbstractReference; -exports.default = _default; \ No newline at end of file +var _default = exports.default = PDFAbstractReference; \ No newline at end of file diff --git a/dist/helpers/pdfkit/pdfobject.d.ts b/packages/placeholder-pdfkit010/dist/pdfkit/pdfobject.d.ts similarity index 100% rename from dist/helpers/pdfkit/pdfobject.d.ts rename to packages/placeholder-pdfkit010/dist/pdfkit/pdfobject.d.ts diff --git a/packages/placeholder-pdfkit010/dist/pdfkit/pdfobject.d.ts.map b/packages/placeholder-pdfkit010/dist/pdfkit/pdfobject.d.ts.map new file mode 100644 index 00000000..b4915996 --- /dev/null +++ b/packages/placeholder-pdfkit010/dist/pdfkit/pdfobject.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"pdfobject.d.ts","sourceRoot":"","sources":["../../src/pdfkit/pdfobject.js"],"names":[],"mappings":"AA8BA;IACI,kDAuFC;IAED,8BAMC;CACJ"} \ No newline at end of file diff --git a/dist/helpers/pdfkit/pdfobject.js b/packages/placeholder-pdfkit010/dist/pdfkit/pdfobject.js similarity index 83% rename from dist/helpers/pdfkit/pdfobject.js rename to packages/placeholder-pdfkit010/dist/pdfkit/pdfobject.js index 498ab532..dc70f68d 100644 --- a/dist/helpers/pdfkit/pdfobject.js +++ b/packages/placeholder-pdfkit010/dist/pdfkit/pdfobject.js @@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; - var _abstract_reference = _interopRequireDefault(require("./abstract_reference")); - function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - /* PDFObject by Devon Govett used below. The class is part of pdfkit. See https://github.com/foliojs/pdfkit @@ -20,8 +17,8 @@ Modifications may have been applied for the purposes of node-signpdf. PDFObject - converts JavaScript types into their corresponding PDF types. By Devon Govett */ -const pad = (str, length) => (Array(length + 1).join('0') + str).slice(-length); +const pad = (str, length) => (Array(length + 1).join('0') + str).slice(-length); const escapableRe = /[\n\r\t\b\f()\\]/g; const escapable = { '\n': '\\n', @@ -32,88 +29,84 @@ const escapable = { '\\': '\\\\', '(': '\\(', ')': '\\)' -}; // Convert little endian UTF-16 to big endian +}; +// Convert little endian UTF-16 to big endian const swapBytes = buff => buff.swap16(); - class PDFObject { static convert(object, encryptFn = null) { // String literals are converted to the PDF name type if (typeof object === 'string') { - return `/${object}`; // String objects are converted to PDF strings (UTF-16) - } + return `/${object}`; + // String objects are converted to PDF strings (UTF-16) + } if (object instanceof String) { - let string = object; // Detect if this is a unicode string - + let string = object; + // Detect if this is a unicode string let isUnicode = false; - for (let i = 0, end = string.length; i < end; i += 1) { if (string.charCodeAt(i) > 0x7f) { isUnicode = true; break; } - } // If so, encode it as big endian UTF-16 - + } + // If so, encode it as big endian UTF-16 let stringBuffer; - if (isUnicode) { stringBuffer = swapBytes(Buffer.from(`\ufeff${string}`, 'utf16le')); } else { stringBuffer = Buffer.from(string, 'ascii'); - } // Encrypt the string when necessary - + } + // Encrypt the string when necessary if (encryptFn) { string = encryptFn(stringBuffer).toString('binary'); } else { string = stringBuffer.toString('binary'); - } // Escape characters as required by the spec - + } + // Escape characters as required by the spec string = string.replace(escapableRe, c => escapable[c]); - return `(${string})`; // Buffers are converted to PDF hex strings - } + return `(${string})`; + // Buffers are converted to PDF hex strings + } if (Buffer.isBuffer(object)) { return `<${object.toString('hex')}>`; } - if (object instanceof _abstract_reference.default) { return object.toString(); } - if (object instanceof Date) { - let string = `D:${pad(object.getUTCFullYear(), 4)}${pad(object.getUTCMonth() + 1, 2)}${pad(object.getUTCDate(), 2)}${pad(object.getUTCHours(), 2)}${pad(object.getUTCMinutes(), 2)}${pad(object.getUTCSeconds(), 2)}Z`; // Encrypt the string when necessary + let string = `D:${pad(object.getUTCFullYear(), 4)}${pad(object.getUTCMonth() + 1, 2)}${pad(object.getUTCDate(), 2)}${pad(object.getUTCHours(), 2)}${pad(object.getUTCMinutes(), 2)}${pad(object.getUTCSeconds(), 2)}Z`; + // Encrypt the string when necessary if (encryptFn) { - string = encryptFn(Buffer.from(string, 'ascii')).toString('binary'); // Escape characters as required by the spec + string = encryptFn(Buffer.from(string, 'ascii')).toString('binary'); + // Escape characters as required by the spec string = string.replace(escapableRe, c => escapable[c]); } - return `(${string})`; } - if (Array.isArray(object)) { const items = object.map(e => PDFObject.convert(e, encryptFn)).join(' '); return `[${items}]`; } - if ({}.toString.call(object) === '[object Object]') { const out = ['<<']; - let streamData; // @todo this can probably be refactored into a reduce + let streamData; + // @todo this can probably be refactored into a reduce Object.entries(object).forEach(([key, val]) => { let checkedValue = ''; - if (val.toString().indexOf('<<') !== -1) { checkedValue = val; } else { checkedValue = PDFObject.convert(val, encryptFn); } - if (key === 'stream') { streamData = `${key}\n${val}\nendstream`; } else { @@ -121,29 +114,21 @@ class PDFObject { } }); out.push('>>'); - if (streamData) { out.push(streamData); } - return out.join('\n'); } - if (typeof object === 'number') { return PDFObject.number(object); } - return `${object}`; } - static number(n) { if (n > -1e21 && n < 1e21) { return Math.round(n * 1e6) / 1e6; } - throw new Error(`unsupported number: ${n}`); } - } - exports.default = PDFObject; \ No newline at end of file diff --git a/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts b/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts new file mode 100644 index 00000000..92b6a0bd --- /dev/null +++ b/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts @@ -0,0 +1,24 @@ +export function pdfkitAddPlaceholder({ pdf, pdfBuffer, reason, contactInfo, name, location, signatureLength, byteRangePlaceholder, subFilter, }: InputType): ReturnType; +export type InputType = { + /** + * PDFDocument + */ + pdf: object; + pdfBuffer: Buffer; + reason: string; + contactInfo: string; + name: string; + location: string; + signatureLength?: number; + byteRangePlaceholder?: string; + /** + * One of SUBFILTER_* from + */ + subFilter?: string; +}; +export type ReturnType = { + signature: any; + form: any; + widget: any; +}; +//# sourceMappingURL=pdfkitAddPlaceholder.d.ts.map \ No newline at end of file diff --git a/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts.map b/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts.map new file mode 100644 index 00000000..4040b3b3 --- /dev/null +++ b/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"pdfkitAddPlaceholder.d.ts","sourceRoot":"","sources":["../src/pdfkitAddPlaceholder.js"],"names":[],"mappings":"AAmCO,iJAHI,SAAS,GACP,UAAU,CAkHtB;;;;;SAzIY,MAAM;eACN,MAAM;YACN,MAAM;iBACN,MAAM;UACN,MAAM;cACN,MAAM;sBACN,MAAM;2BACN,MAAM;;;;gBACN,MAAM;;;eAKN,GAAG;UACH,GAAG;YACH,GAAG"} \ No newline at end of file diff --git a/dist/helpers/pdfkitAddPlaceholder.js b/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.js similarity index 59% rename from dist/helpers/pdfkitAddPlaceholder.js rename to packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.js index fe266ec1..0c74c1aa 100644 --- a/dist/helpers/pdfkitAddPlaceholder.js +++ b/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.js @@ -3,34 +3,48 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = void 0; - -var _const = require("./const"); - -var _pdfkitReferenceMock = _interopRequireDefault(require("./pdfkitReferenceMock")); +exports.pdfkitAddPlaceholder = void 0; +var _utils = require("@signpdf/utils"); +var _pdfkitReferenceMock = require("./pdfkitReferenceMock"); +// eslint-disable-next-line import/no-unresolved -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +/** +* @typedef {object} InputType +* @property {object} pdf PDFDocument +* @property {Buffer} pdfBuffer +* @property {string} reason +* @property {string} contactInfo +* @property {string} name +* @property {string} location +* @property {number} [signatureLength] +* @property {string} [byteRangePlaceholder] +* @property {string} [subFilter] One of SUBFILTER_* from @signpdf/utils +*/ -// eslint-disable-next-line import/no-unresolved +/** +* @typedef {object} ReturnType +* @property {any} signature +* @property {any} form +* @property {any} widget + */ /** * Adds the objects that are needed for Adobe.PPKLite to read the signature. * Also includes a placeholder for the actual signature. * Returns an Object with all the added PDFReferences. - * @param {PDFDocument} pdf - * @param {string} reason - * @returns {object} + * @param {InputType} + * @returns {ReturnType} */ const pdfkitAddPlaceholder = ({ pdf, pdfBuffer, reason, - contactInfo = 'emailfromp1289@gmail.com', - name = 'Name from p12', - location = 'Location from p12', - signatureLength = _const.DEFAULT_SIGNATURE_LENGTH, - byteRangePlaceholder = _const.DEFAULT_BYTE_RANGE_PLACEHOLDER, - subFilter = _const.SUBFILTER_ADOBE_PKCS7_DETACHED + contactInfo, + name, + location, + signatureLength = _utils.DEFAULT_SIGNATURE_LENGTH, + byteRangePlaceholder = _utils.DEFAULT_BYTE_RANGE_PLACEHOLDER, + subFilter = _utils.SUBFILTER_ADOBE_PKCS7_DETACHED }) => { /* eslint-disable no-underscore-dangle,no-param-reassign */ // Generate the signature placeholder @@ -48,46 +62,45 @@ const pdfkitAddPlaceholder = ({ Name: new String(name), // eslint-disable-line no-new-wrappers Location: new String(location) // eslint-disable-line no-new-wrappers + }); - }); // Check if pdf already contains acroform field - - const acroFormPosition = pdfBuffer.lastIndexOf('/Type /AcroForm'); - const isAcroFormExists = acroFormPosition !== -1; + // Check if pdf already contains acroform field + const isAcroFormExists = typeof pdf._root.data.AcroForm !== 'undefined'; let fieldIds = []; let acroFormId; - if (isAcroFormExists) { - let acroFormStart = acroFormPosition; // 10 is the distance between "/Type /AcroForm" and AcroFrom ID - + /* FIXME: We're working with a PDFDocument. + * Needing to work with strings here doesn't make sense. + * It only exists to support plainAddPlaceholder the reference to /AcroForm + * would be external to PDFKit at this point. + */ + + const acroFormPosition = pdfBuffer.lastIndexOf('/Type /AcroForm'); + let acroFormStart = acroFormPosition; + // 10 is the distance between "/Type /AcroForm" and AcroFrom ID const charsUntilIdEnd = 10; - const acroFormIdEnd = acroFormPosition - charsUntilIdEnd; // Let's find AcroForm ID by trying to find the "\n" before the ID + const acroFormIdEnd = acroFormPosition - charsUntilIdEnd; + // Let's find AcroForm ID by trying to find the "\n" before the ID // 12 is a enough space to find the "\n" // (generally it's 2 or 3, but I'm giving a big space though) - const maxAcroFormIdLength = 12; - let foundAcroFormId = ''; let index = charsUntilIdEnd + 1; - for (index; index < charsUntilIdEnd + maxAcroFormIdLength; index += 1) { const acroFormIdString = pdfBuffer.slice(acroFormPosition - index, acroFormIdEnd).toString(); - if (acroFormIdString[0] === '\n') { break; } - - foundAcroFormId = acroFormIdString; acroFormStart = acroFormPosition - index; } - const pdfSlice = pdfBuffer.slice(acroFormStart); const acroForm = pdfSlice.slice(0, pdfSlice.indexOf('endobj')).toString(); - acroFormId = parseInt(foundAcroFormId); + acroFormId = parseInt(pdf._root.data.AcroForm.toString()); const acroFormFields = acroForm.slice(acroForm.indexOf('/Fields [') + 9, acroForm.indexOf(']')); - fieldIds = acroFormFields.split(' ').filter((element, i) => i % 3 === 0).map(fieldId => new _pdfkitReferenceMock.default(fieldId)); + fieldIds = acroFormFields.split(' ').filter((element, i) => i % 3 === 0).map(fieldId => new _pdfkitReferenceMock.PDFKitReferenceMock(fieldId)); } + const signatureName = 'Signature'; - const signatureName = 'Signature'; // Generate signature annotation widget - + // Generate signature annotation widget const widget = pdf.ref({ Type: 'Annot', Subtype: 'Widget', @@ -98,12 +111,11 @@ const pdfkitAddPlaceholder = ({ // eslint-disable-line no-new-wrappers F: 4, P: pdf.page.dictionary // eslint-disable-line no-underscore-dangle - }); - pdf.page.dictionary.data.Annots = [widget]; // Include the widget in a page + pdf.page.dictionary.data.Annots = [widget]; + // Include the widget in a page let form; - if (!isAcroFormExists) { // Create a form (with the widget) and link in the _root form = pdf.ref({ @@ -119,7 +131,6 @@ const pdfkitAddPlaceholder = ({ Fields: [...fieldIds, widget] }, acroFormId); } - pdf._root.data.AcroForm = form; return { signature, @@ -128,6 +139,4 @@ const pdfkitAddPlaceholder = ({ }; /* eslint-enable no-underscore-dangle,no-param-reassign */ }; - -var _default = pdfkitAddPlaceholder; -exports.default = _default; \ No newline at end of file +exports.pdfkitAddPlaceholder = pdfkitAddPlaceholder; \ No newline at end of file diff --git a/dist/helpers/pdfkitReferenceMock.d.ts b/packages/placeholder-pdfkit010/dist/pdfkitReferenceMock.d.ts similarity index 67% rename from dist/helpers/pdfkitReferenceMock.d.ts rename to packages/placeholder-pdfkit010/dist/pdfkitReferenceMock.d.ts index ce5cdf6d..47719691 100644 --- a/dist/helpers/pdfkitReferenceMock.d.ts +++ b/packages/placeholder-pdfkit010/dist/pdfkitReferenceMock.d.ts @@ -1,5 +1,4 @@ -export default PDFKitReferenceMock; -declare class PDFKitReferenceMock extends PDFAbstractReference { +export class PDFKitReferenceMock extends PDFAbstractReference { constructor(index: any, additionalData?: any); index: any; toString(): string; diff --git a/packages/placeholder-pdfkit010/dist/pdfkitReferenceMock.d.ts.map b/packages/placeholder-pdfkit010/dist/pdfkitReferenceMock.d.ts.map new file mode 100644 index 00000000..84ae6736 --- /dev/null +++ b/packages/placeholder-pdfkit010/dist/pdfkitReferenceMock.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"pdfkitReferenceMock.d.ts","sourceRoot":"","sources":["../src/pdfkitReferenceMock.js"],"names":[],"mappings":"AAEA;IACI,8CAMC;IAJG,WAAkB;IAMtB,mBAEC;CACJ;iCAdgC,6BAA6B"} \ No newline at end of file diff --git a/dist/helpers/pdfkitReferenceMock.js b/packages/placeholder-pdfkit010/dist/pdfkitReferenceMock.js similarity index 85% rename from dist/helpers/pdfkitReferenceMock.js rename to packages/placeholder-pdfkit010/dist/pdfkitReferenceMock.js index 0930df58..925f3b29 100644 --- a/dist/helpers/pdfkitReferenceMock.js +++ b/packages/placeholder-pdfkit010/dist/pdfkitReferenceMock.js @@ -3,27 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = void 0; - +exports.PDFKitReferenceMock = void 0; var _abstract_reference = _interopRequireDefault(require("./pdfkit/abstract_reference")); - function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - class PDFKitReferenceMock extends _abstract_reference.default { constructor(index, additionalData = undefined) { super(); this.index = index; - if (typeof additionalData !== 'undefined') { Object.assign(this, additionalData); } } - toString() { return `${this.index} 0 R`; } - } - -var _default = PDFKitReferenceMock; -exports.default = _default; \ No newline at end of file +exports.PDFKitReferenceMock = PDFKitReferenceMock; \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/createBufferPageWithAnnotation.d.ts b/packages/placeholder-plain/dist/createBufferPageWithAnnotation.d.ts similarity index 100% rename from dist/helpers/plainAddPlaceholder/createBufferPageWithAnnotation.d.ts rename to packages/placeholder-plain/dist/createBufferPageWithAnnotation.d.ts diff --git a/packages/placeholder-plain/dist/createBufferPageWithAnnotation.d.ts.map b/packages/placeholder-plain/dist/createBufferPageWithAnnotation.d.ts.map new file mode 100644 index 00000000..ab4a19cc --- /dev/null +++ b/packages/placeholder-plain/dist/createBufferPageWithAnnotation.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"createBufferPageWithAnnotation.d.ts","sourceRoot":"","sources":["../src/createBufferPageWithAnnotation.js"],"names":[],"mappings":";AAGA,yGAkCC"} \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/createBufferPageWithAnnotation.js b/packages/placeholder-plain/dist/createBufferPageWithAnnotation.js similarity index 90% rename from dist/helpers/plainAddPlaceholder/createBufferPageWithAnnotation.js rename to packages/placeholder-plain/dist/createBufferPageWithAnnotation.js index 1a046096..68283189 100644 --- a/dist/helpers/plainAddPlaceholder/createBufferPageWithAnnotation.js +++ b/packages/placeholder-plain/dist/createBufferPageWithAnnotation.js @@ -4,21 +4,17 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; - var _findObject = _interopRequireDefault(require("./findObject")); - var _getIndexFromRef = _interopRequireDefault(require("./getIndexFromRef")); - function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - const createBufferPageWithAnnotation = (pdf, info, pagesRef, widget) => { - const pagesDictionary = (0, _findObject.default)(pdf, info.xref, pagesRef).toString(); // Extend page dictionary with newly created annotations + const pagesDictionary = (0, _findObject.default)(pdf, info.xref, pagesRef).toString(); + // Extend page dictionary with newly created annotations let annotsStart; let annotsEnd; let annots; annotsStart = pagesDictionary.indexOf('/Annots'); - if (annotsStart > -1) { annotsEnd = pagesDictionary.indexOf(']', annotsStart); annots = pagesDictionary.substr(annotsStart, annotsEnd + 1 - annotsStart); @@ -28,20 +24,15 @@ const createBufferPageWithAnnotation = (pdf, info, pagesRef, widget) => { annotsEnd = pagesDictionary.length; annots = '/Annots ['; } - const pagesDictionaryIndex = (0, _getIndexFromRef.default)(info.xref, pagesRef); const widgetValue = widget.toString(); annots = `${annots} ${widgetValue}]`; // add the trailing ] back const preAnnots = pagesDictionary.substr(0, annotsStart); let postAnnots = ''; - if (pagesDictionary.length > annotsEnd) { postAnnots = pagesDictionary.substr(annotsEnd + 1); } - return Buffer.concat([Buffer.from(`${pagesDictionaryIndex} 0 obj\n`), Buffer.from('<<\n'), Buffer.from(`${preAnnots + annots + postAnnots}\n`), Buffer.from('\n>>\nendobj\n')]); }; - -var _default = createBufferPageWithAnnotation; -exports.default = _default; \ No newline at end of file +var _default = exports.default = createBufferPageWithAnnotation; \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/createBufferRootWithAcroform.d.ts b/packages/placeholder-plain/dist/createBufferRootWithAcroform.d.ts similarity index 100% rename from dist/helpers/plainAddPlaceholder/createBufferRootWithAcroform.d.ts rename to packages/placeholder-plain/dist/createBufferRootWithAcroform.d.ts diff --git a/packages/placeholder-plain/dist/createBufferRootWithAcroform.d.ts.map b/packages/placeholder-plain/dist/createBufferRootWithAcroform.d.ts.map new file mode 100644 index 00000000..b9a07211 --- /dev/null +++ b/packages/placeholder-plain/dist/createBufferRootWithAcroform.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"createBufferRootWithAcroform.d.ts","sourceRoot":"","sources":["../src/createBufferRootWithAcroform.js"],"names":[],"mappings":";AAEA,sFAUC"} \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/createBufferRootWithAcroform.js b/packages/placeholder-plain/dist/createBufferRootWithAcroform.js similarity index 88% rename from dist/helpers/plainAddPlaceholder/createBufferRootWithAcroform.js rename to packages/placeholder-plain/dist/createBufferRootWithAcroform.js index 4a34369c..bdb180e0 100644 --- a/dist/helpers/plainAddPlaceholder/createBufferRootWithAcroform.js +++ b/packages/placeholder-plain/dist/createBufferRootWithAcroform.js @@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; - var _getIndexFromRef = _interopRequireDefault(require("./getIndexFromRef")); - function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - const createBufferRootWithAcroform = (pdf, info, form) => { const rootIndex = (0, _getIndexFromRef.default)(info.xref, info.rootRef); return Buffer.concat([Buffer.from(`${rootIndex} 0 obj\n`), Buffer.from('<<\n'), Buffer.from(`${info.root}\n`), Buffer.from(`/AcroForm ${form}`), Buffer.from('\n>>\nendobj\n')]); }; - -var _default = createBufferRootWithAcroform; -exports.default = _default; \ No newline at end of file +var _default = exports.default = createBufferRootWithAcroform; \ No newline at end of file diff --git a/packages/placeholder-plain/dist/createBufferTrailer.d.ts b/packages/placeholder-plain/dist/createBufferTrailer.d.ts new file mode 100644 index 00000000..7ed371e4 --- /dev/null +++ b/packages/placeholder-plain/dist/createBufferTrailer.d.ts @@ -0,0 +1,9 @@ +export default createBufferTrailer; +/** + * @param {Buffer} pdf + * @param {import("./readPdf").ReadPdfReturnType} info + * @param {Map} addedReferences + * @returns {Buffer} + */ +declare function createBufferTrailer(pdf: Buffer, info: import("./readPdf").ReadPdfReturnType, addedReferences: Map): Buffer; +//# sourceMappingURL=createBufferTrailer.d.ts.map \ No newline at end of file diff --git a/packages/placeholder-plain/dist/createBufferTrailer.d.ts.map b/packages/placeholder-plain/dist/createBufferTrailer.d.ts.map new file mode 100644 index 00000000..629b5026 --- /dev/null +++ b/packages/placeholder-plain/dist/createBufferTrailer.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"createBufferTrailer.d.ts","sourceRoot":"","sources":["../src/createBufferTrailer.js"],"names":[],"mappings":";AAAA;;;;;GAKG;AACH,0CALW,MAAM,QACN,OAAO,WAAW,EAAE,iBAAiB,mBACrC,IAAI,MAAM,EAAE,MAAM,CAAC,GACjB,MAAM,CA2BlB"} \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/createBufferTrailer.js b/packages/placeholder-plain/dist/createBufferTrailer.js similarity index 81% rename from dist/helpers/plainAddPlaceholder/createBufferTrailer.js rename to packages/placeholder-plain/dist/createBufferTrailer.js index c982767b..fa7d567f 100644 --- a/dist/helpers/plainAddPlaceholder/createBufferTrailer.js +++ b/packages/placeholder-plain/dist/createBufferTrailer.js @@ -4,7 +4,12 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; - +/** + * @param {Buffer} pdf + * @param {import("./readPdf").ReadPdfReturnType} info + * @param {Map} addedReferences + * @returns {Buffer} + */ const createBufferTrailer = (pdf, info, addedReferences) => { let rows = []; rows[0] = '0000000000 65535 f '; // info.xref.tableRows[0]; @@ -16,6 +21,4 @@ const createBufferTrailer = (pdf, info, addedReferences) => { rows = rows.filter(row => row !== undefined); return Buffer.concat([Buffer.from('xref\n'), Buffer.from(`${info.xref.startingIndex} 1\n`), Buffer.from(rows.join('\n')), Buffer.from('\ntrailer\n'), Buffer.from('<<\n'), Buffer.from(`/Size ${info.xref.maxIndex + 1}\n`), Buffer.from(`/Root ${info.rootRef}\n`), Buffer.from(info.infoRef ? `/Info ${info.infoRef}\n` : ''), Buffer.from(`/Prev ${info.xRefPosition}\n`), Buffer.from('>>\n'), Buffer.from('startxref\n'), Buffer.from(`${pdf.length}\n`), Buffer.from('%%EOF')]); }; - -var _default = createBufferTrailer; -exports.default = _default; \ No newline at end of file +var _default = exports.default = createBufferTrailer; \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/findObject.d.ts b/packages/placeholder-plain/dist/findObject.d.ts similarity index 81% rename from dist/helpers/plainAddPlaceholder/findObject.d.ts rename to packages/placeholder-plain/dist/findObject.d.ts index 3ca75e34..f6732b23 100644 --- a/dist/helpers/plainAddPlaceholder/findObject.d.ts +++ b/packages/placeholder-plain/dist/findObject.d.ts @@ -2,7 +2,7 @@ export default findObject; /** * @param {Buffer} pdf * @param {Map} refTable - * @returns {object} + * @returns {Buffer} */ -declare function findObject(pdf: Buffer, refTable: Map, ref: any): object; +declare function findObject(pdf: Buffer, refTable: Map, ref: any): Buffer; //# sourceMappingURL=findObject.d.ts.map \ No newline at end of file diff --git a/packages/placeholder-plain/dist/findObject.d.ts.map b/packages/placeholder-plain/dist/findObject.d.ts.map new file mode 100644 index 00000000..3eebfa0b --- /dev/null +++ b/packages/placeholder-plain/dist/findObject.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"findObject.d.ts","sourceRoot":"","sources":["../src/findObject.js"],"names":[],"mappings":";AAEA;;;;GAIG;AACH,iCAJW,MAAM,sCAEJ,MAAM,CAalB"} \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/findObject.js b/packages/placeholder-plain/dist/findObject.js similarity index 79% rename from dist/helpers/plainAddPlaceholder/findObject.js rename to packages/placeholder-plain/dist/findObject.js index db6c7b3e..0ec858d1 100644 --- a/dist/helpers/plainAddPlaceholder/findObject.js +++ b/packages/placeholder-plain/dist/findObject.js @@ -4,26 +4,22 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; - var _getIndexFromRef = _interopRequireDefault(require("./getIndexFromRef")); - function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - /** * @param {Buffer} pdf * @param {Map} refTable - * @returns {object} + * @returns {Buffer} */ const findObject = (pdf, refTable, ref) => { const index = (0, _getIndexFromRef.default)(refTable, ref); const offset = refTable.offsets.get(index); let slice = pdf.slice(offset); - slice = slice.slice(0, slice.indexOf('endobj', 'utf8')); // FIXME: What if it is a stream? + slice = slice.slice(0, slice.indexOf('endobj', 'utf8')); + // FIXME: What if it is a stream? slice = slice.slice(slice.indexOf('<<', 'utf8') + 2); slice = slice.slice(0, slice.lastIndexOf('>>', 'utf8')); return slice; }; - -var _default = findObject; -exports.default = _default; \ No newline at end of file +var _default = exports.default = findObject; \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/getIndexFromRef.d.ts b/packages/placeholder-plain/dist/getIndexFromRef.d.ts similarity index 100% rename from dist/helpers/plainAddPlaceholder/getIndexFromRef.d.ts rename to packages/placeholder-plain/dist/getIndexFromRef.d.ts diff --git a/packages/placeholder-plain/dist/getIndexFromRef.d.ts.map b/packages/placeholder-plain/dist/getIndexFromRef.d.ts.map new file mode 100644 index 00000000..9d453580 --- /dev/null +++ b/packages/placeholder-plain/dist/getIndexFromRef.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"getIndexFromRef.d.ts","sourceRoot":"","sources":["../src/getIndexFromRef.js"],"names":[],"mappings":";AAEA;;;;GAIG;AACH,2CAJW,MAAM,OACN,MAAM,GACJ,MAAM,CAalB"} \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/getIndexFromRef.js b/packages/placeholder-plain/dist/getIndexFromRef.js similarity index 50% rename from dist/helpers/plainAddPlaceholder/getIndexFromRef.js rename to packages/placeholder-plain/dist/getIndexFromRef.js index 1db2ed46..84315f3b 100644 --- a/dist/helpers/plainAddPlaceholder/getIndexFromRef.js +++ b/packages/placeholder-plain/dist/getIndexFromRef.js @@ -4,11 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; - -var _SignPdfError = _interopRequireDefault(require("../../SignPdfError")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +var _utils = require("@signpdf/utils"); /** * @param {object} refTable * @param {string} ref @@ -17,13 +13,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de const getIndexFromRef = (refTable, ref) => { let [index] = ref.split(' '); index = parseInt(index); - if (!refTable.offsets.has(index)) { - throw new _SignPdfError.default(`Failed to locate object "${ref}".`, _SignPdfError.default.TYPE_PARSE); + throw new _utils.SignPdfError(`Failed to locate object "${ref}".`, _utils.SignPdfError.TYPE_PARSE); } - return index; }; - -var _default = getIndexFromRef; -exports.default = _default; \ No newline at end of file +var _default = exports.default = getIndexFromRef; \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/getPageRef.d.ts b/packages/placeholder-plain/dist/getPageRef.d.ts similarity index 100% rename from dist/helpers/plainAddPlaceholder/getPageRef.d.ts rename to packages/placeholder-plain/dist/getPageRef.d.ts diff --git a/packages/placeholder-plain/dist/getPageRef.d.ts.map b/packages/placeholder-plain/dist/getPageRef.d.ts.map new file mode 100644 index 00000000..20489a0d --- /dev/null +++ b/packages/placeholder-plain/dist/getPageRef.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"getPageRef.d.ts","sourceRoot":"","sources":["../src/getPageRef.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,8CAHW,MAAM,qBAYhB"} \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/getPageRef.js b/packages/placeholder-plain/dist/getPageRef.js similarity index 99% rename from dist/helpers/plainAddPlaceholder/getPageRef.js rename to packages/placeholder-plain/dist/getPageRef.js index f7dc95b8..3402e976 100644 --- a/dist/helpers/plainAddPlaceholder/getPageRef.js +++ b/packages/placeholder-plain/dist/getPageRef.js @@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = getPageRef; - var _getPagesDictionaryRef = _interopRequireDefault(require("./getPagesDictionaryRef")); - var _findObject = _interopRequireDefault(require("./findObject")); - function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - /** * Finds the reference to a page. * diff --git a/dist/helpers/plainAddPlaceholder/getPagesDictionaryRef.d.ts b/packages/placeholder-plain/dist/getPagesDictionaryRef.d.ts similarity index 100% rename from dist/helpers/plainAddPlaceholder/getPagesDictionaryRef.d.ts rename to packages/placeholder-plain/dist/getPagesDictionaryRef.d.ts diff --git a/packages/placeholder-plain/dist/getPagesDictionaryRef.d.ts.map b/packages/placeholder-plain/dist/getPagesDictionaryRef.d.ts.map new file mode 100644 index 00000000..ea733329 --- /dev/null +++ b/packages/placeholder-plain/dist/getPagesDictionaryRef.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"getPagesDictionaryRef.d.ts","sourceRoot":"","sources":["../src/getPagesDictionaryRef.js"],"names":[],"mappings":"AAEA;;GAEG;AAEH,iEAWC"} \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/getPagesDictionaryRef.js b/packages/placeholder-plain/dist/getPagesDictionaryRef.js similarity index 52% rename from dist/helpers/plainAddPlaceholder/getPagesDictionaryRef.js rename to packages/placeholder-plain/dist/getPagesDictionaryRef.js index 375de63b..d001b7ac 100644 --- a/dist/helpers/plainAddPlaceholder/getPagesDictionaryRef.js +++ b/packages/placeholder-plain/dist/getPagesDictionaryRef.js @@ -4,21 +4,16 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = getPagesDictionaryRef; - -var _SignPdfError = _interopRequireDefault(require("../../SignPdfError")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +var _utils = require("@signpdf/utils"); /** * @param {Object} info As extracted from readRef() */ + function getPagesDictionaryRef(info) { const pagesRefRegex = /\/Pages\s+(\d+\s+\d+\s+R)/g; const match = pagesRefRegex.exec(info.root); - if (match === null) { - throw new _SignPdfError.default('Failed to find the pages descriptor. This is probably a problem in node-signpdf.', _SignPdfError.default.TYPE_PARSE); + throw new _utils.SignPdfError('Failed to find the pages descriptor. This is probably a problem in node-signpdf.', _utils.SignPdfError.TYPE_PARSE); } - return match[1]; } \ No newline at end of file diff --git a/packages/placeholder-plain/dist/plainAddPlaceholder.d.ts b/packages/placeholder-plain/dist/plainAddPlaceholder.d.ts new file mode 100644 index 00000000..a00eea4d --- /dev/null +++ b/packages/placeholder-plain/dist/plainAddPlaceholder.d.ts @@ -0,0 +1,14 @@ +export function plainAddPlaceholder({ pdfBuffer, reason, contactInfo, name, location, signatureLength, subFilter, }: InputType): Buffer; +export type InputType = { + pdfBuffer: Buffer; + reason: string; + contactInfo: string; + name: string; + location: string; + signatureLength?: number; + /** + * One of SUBFILTER_* from + */ + subFilter?: 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 new file mode 100644 index 00000000..26500ca9 --- /dev/null +++ b/packages/placeholder-plain/dist/plainAddPlaceholder.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"plainAddPlaceholder.d.ts","sourceRoot":"","sources":["../src/plainAddPlaceholder.js"],"names":[],"mappings":"AAwDO,qHAHI,SAAS,GACP,MAAM,CA2FlB;;eA9GY,MAAM;YACN,MAAM;iBACN,MAAM;UACN,MAAM;cACN,MAAM;sBACN,MAAM;;;;gBACN,MAAM"} \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/index.js b/packages/placeholder-plain/dist/plainAddPlaceholder.js similarity index 59% rename from dist/helpers/plainAddPlaceholder/index.js rename to packages/placeholder-plain/dist/plainAddPlaceholder.js index 764dbfe2..8022c336 100644 --- a/dist/helpers/plainAddPlaceholder/index.js +++ b/packages/placeholder-plain/dist/plainAddPlaceholder.js @@ -3,37 +3,42 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = void 0; - -var _pdfobject = _interopRequireDefault(require("../pdfkit/pdfobject")); - -var _pdfkitReferenceMock = _interopRequireDefault(require("../pdfkitReferenceMock")); - -var _removeTrailingNewLine = _interopRequireDefault(require("../removeTrailingNewLine")); - -var _const = require("../const"); - -var _pdfkitAddPlaceholder = _interopRequireDefault(require("../pdfkitAddPlaceholder")); - +exports.plainAddPlaceholder = void 0; +var _placeholderPdfkit = require("@signpdf/placeholder-pdfkit010"); +var _utils = require("@signpdf/utils"); var _getIndexFromRef = _interopRequireDefault(require("./getIndexFromRef")); - var _readPdf = _interopRequireDefault(require("./readPdf")); - var _getPageRef = _interopRequireDefault(require("./getPageRef")); - var _createBufferRootWithAcroform = _interopRequireDefault(require("./createBufferRootWithAcroform")); - var _createBufferPageWithAnnotation = _interopRequireDefault(require("./createBufferPageWithAnnotation")); - var _createBufferTrailer = _interopRequireDefault(require("./createBufferTrailer")); - function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +/* eslint-disable no-underscore-dangle */ -const isContainBufferRootWithAcroform = pdf => { +/** + * @param {string} pdf + * @returns {string | undefined} + */ +const getAcroFormRef = slice => { const bufferRootWithAcroformRefRegex = /\/AcroForm\s+(\d+\s\d+\sR)/g; - const match = bufferRootWithAcroformRefRegex.exec(pdf.toString()); - return match != null && match[1] != null && match[1] !== ''; + const match = bufferRootWithAcroformRefRegex.exec(slice); + if (match != null && match[1] != null && match[1] !== '') { + return match[1]; + } + return undefined; }; + +/** +* @typedef {object} InputType +* @property {Buffer} pdfBuffer +* @property {string} reason +* @property {string} contactInfo +* @property {string} name +* @property {string} location +* @property {number} [signatureLength] +* @property {string} [subFilter] One of SUBFILTER_* from @signpdf/utils +*/ + /** * Adds a signature placeholder to a PDF Buffer. * @@ -42,34 +47,35 @@ const isContainBufferRootWithAcroform = pdf => { * Adding is done with `Buffer.concat`. * This allows node-signpdf to be used on any PDF and * not only on a freshly created through PDFKit one. + * + * @param {InputType} + * @returns {Buffer} */ - - const plainAddPlaceholder = ({ pdfBuffer, reason, - contactInfo = 'emailfromp1289@gmail.com', - name = 'Name from p12', - location = 'Location from p12', - signatureLength = _const.DEFAULT_SIGNATURE_LENGTH, - subFilter = _const.SUBFILTER_ADOBE_PKCS7_DETACHED + contactInfo, + name, + location, + signatureLength = _utils.DEFAULT_SIGNATURE_LENGTH, + subFilter = _utils.SUBFILTER_ADOBE_PKCS7_DETACHED }) => { - let pdf = (0, _removeTrailingNewLine.default)(pdfBuffer); + let pdf = (0, _utils.removeTrailingNewLine)(pdfBuffer); const info = (0, _readPdf.default)(pdf); const pageRef = (0, _getPageRef.default)(pdf, info); const pageIndex = (0, _getIndexFromRef.default)(info.xref, pageRef); const addedReferences = new Map(); const pdfKitMock = { - ref: (input, additionalIndex) => { + ref: (input, knownIndex) => { info.xref.maxIndex += 1; - const index = additionalIndex != null ? additionalIndex : info.xref.maxIndex; + const index = knownIndex != null ? knownIndex : info.xref.maxIndex; addedReferences.set(index, pdf.length + 1); // + 1 new line - pdf = Buffer.concat([pdf, Buffer.from('\n'), Buffer.from(`${index} 0 obj\n`), Buffer.from(_pdfobject.default.convert(input)), Buffer.from('\nendobj\n')]); - return new _pdfkitReferenceMock.default(info.xref.maxIndex); + pdf = Buffer.concat([pdf, Buffer.from('\n'), Buffer.from(`${index} 0 obj\n`), Buffer.from(_placeholderPdfkit.PDFObject.convert(input)), Buffer.from('\nendobj\n')]); + return new _placeholderPdfkit.PDFKitReferenceMock(info.xref.maxIndex); }, page: { - dictionary: new _pdfkitReferenceMock.default(pageIndex, { + dictionary: new _placeholderPdfkit.PDFKitReferenceMock(pageIndex, { data: { Annots: [] } @@ -79,10 +85,14 @@ const plainAddPlaceholder = ({ data: {} } }; + const acroFormRef = getAcroFormRef(info.root); + if (acroFormRef) { + pdfKitMock._root.data.AcroForm = acroFormRef; + } const { form, widget - } = (0, _pdfkitAddPlaceholder.default)({ + } = (0, _placeholderPdfkit.pdfkitAddPlaceholder)({ pdf: pdfKitMock, pdfBuffer, reason, @@ -92,18 +102,14 @@ const plainAddPlaceholder = ({ signatureLength, subFilter }); - - if (!isContainBufferRootWithAcroform(pdf)) { + if (!getAcroFormRef(pdf.toString())) { const rootIndex = (0, _getIndexFromRef.default)(info.xref, info.rootRef); addedReferences.set(rootIndex, pdf.length + 1); pdf = Buffer.concat([pdf, Buffer.from('\n'), (0, _createBufferRootWithAcroform.default)(pdf, info, form)]); } - addedReferences.set(pageIndex, pdf.length + 1); pdf = Buffer.concat([pdf, Buffer.from('\n'), (0, _createBufferPageWithAnnotation.default)(pdf, info, pageRef, widget)]); pdf = Buffer.concat([pdf, Buffer.from('\n'), (0, _createBufferTrailer.default)(pdf, info, addedReferences)]); return pdf; }; - -var _default = plainAddPlaceholder; -exports.default = _default; \ No newline at end of file +exports.plainAddPlaceholder = plainAddPlaceholder; \ No newline at end of file diff --git a/packages/placeholder-plain/dist/readPdf.d.ts b/packages/placeholder-plain/dist/readPdf.d.ts new file mode 100644 index 00000000..b5d2a226 --- /dev/null +++ b/packages/placeholder-plain/dist/readPdf.d.ts @@ -0,0 +1,32 @@ +export function getValue(trailer: Buffer, key: string): string; +export default readPdf; +export type ReadPdfReturnType = { + xref: import("./readRefTable").ReadRefTableReturnType; + rootRef: string; + root: Buffer; + infoRef: string; + trailerStart: number; + previousXrefs: any[]; + xRefPosition: number; +}; +/** + * @typedef {object} ReadPdfReturnType + * @prop {import("./readRefTable").ReadRefTableReturnType} xref + * @prop {string} rootRef + * @prop {Buffer} root + * @prop {string} infoRef + * @prop {number} trailerStart + * @prop {*[]} previousXrefs + * @prop {number} xRefPosition + */ +/** + * Simplified parsing of a PDF Buffer. + * Extracts reference table, root info and trailer start. + * + * See section 7.5.5 (File Trailer) of the PDF specs. + * + * @param {Buffer} pdfBuffer + * @returns {ReadPdfReturnType} + */ +declare function readPdf(pdfBuffer: Buffer): ReadPdfReturnType; +//# sourceMappingURL=readPdf.d.ts.map \ No newline at end of file diff --git a/packages/placeholder-plain/dist/readPdf.d.ts.map b/packages/placeholder-plain/dist/readPdf.d.ts.map new file mode 100644 index 00000000..704c50b3 --- /dev/null +++ b/packages/placeholder-plain/dist/readPdf.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"readPdf.d.ts","sourceRoot":"","sources":["../src/readPdf.js"],"names":[],"mappings":"AAQO,kCAJI,MAAM,OACN,MAAM,GACJ,MAAM,CAelB;;;UAIS,OAAO,gBAAgB,EAAE,sBAAsB;aAC/C,MAAM;UACN,MAAM;aACN,MAAM;kBACN,MAAM;mBACN,KAAG;kBACH,MAAM;;AARhB;;;;;;;;;GASG;AAEH;;;;;;;;GAQG;AACH,oCAHW,MAAM,GACJ,iBAAiB,CA2B7B"} \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/readPdf.js b/packages/placeholder-plain/dist/readPdf.js similarity index 69% rename from dist/helpers/plainAddPlaceholder/readPdf.js rename to packages/placeholder-plain/dist/readPdf.js index 1bba2255..1ecee0b1 100644 --- a/dist/helpers/plainAddPlaceholder/readPdf.js +++ b/packages/placeholder-plain/dist/readPdf.js @@ -3,30 +3,39 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = void 0; - +exports.getValue = exports.default = void 0; var _readRefTable = _interopRequireDefault(require("./readRefTable")); - var _findObject = _interopRequireDefault(require("./findObject")); - function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +/** + * @param {Buffer} trailer + * @param {string} key + * @returns {string} + */ const getValue = (trailer, key) => { let index = trailer.indexOf(key); - if (index === -1) { return undefined; } - const slice = trailer.slice(index); index = slice.indexOf('/', 1); - if (index === -1) { index = slice.indexOf('>', 1); } - return slice.slice(key.length + 1, index).toString().trim(); // key + at least one space }; + +/** + * @typedef {object} ReadPdfReturnType + * @prop {import("./readRefTable").ReadRefTableReturnType} xref + * @prop {string} rootRef + * @prop {Buffer} root + * @prop {string} infoRef + * @prop {number} trailerStart + * @prop {*[]} previousXrefs + * @prop {number} xRefPosition + */ + /** * Simplified parsing of a PDF Buffer. * Extracts reference table, root info and trailer start. @@ -34,13 +43,13 @@ const getValue = (trailer, key) => { * See section 7.5.5 (File Trailer) of the PDF specs. * * @param {Buffer} pdfBuffer + * @returns {ReadPdfReturnType} */ - - +exports.getValue = getValue; const readPdf = pdfBuffer => { // Extract the trailer dictionary. - const trailerStart = pdfBuffer.lastIndexOf('trailer'); // The trailer is followed by xref. Then an EOF. EOF's length is 6 characters. - + const trailerStart = pdfBuffer.lastIndexOf('trailer'); + // The trailer is followed by xref. Then an EOF. EOF's length is 6 characters. const trailer = pdfBuffer.slice(trailerStart, pdfBuffer.length - 6); let xRefPosition = trailer.slice(trailer.lastIndexOf('startxref') + 10).toString(); xRefPosition = parseInt(xRefPosition); @@ -58,6 +67,4 @@ const readPdf = pdfBuffer => { xRefPosition }; }; - -var _default = readPdf; -exports.default = _default; \ No newline at end of file +var _default = exports.default = readPdf; \ No newline at end of file diff --git a/packages/placeholder-plain/dist/readRefTable.d.ts b/packages/placeholder-plain/dist/readRefTable.d.ts new file mode 100644 index 00000000..ff488e36 --- /dev/null +++ b/packages/placeholder-plain/dist/readRefTable.d.ts @@ -0,0 +1,26 @@ +export function getLastTrailerPosition(pdf: any): number; +export function getXref(pdf: any, position: any): { + size: any; + prev: string; + xRefContent: Map; +}; +export function getFullXrefTable(pdf: Buffer): GetFullXrefTableReturnType; +export default readRefTable; +export type GetFullXrefTableReturnType = Map; +export type ReadRefTableReturnType = { + startingIndex: number; + maxIndex: number; + offsets: GetFullXrefTableReturnType; +}; +/** + * @typedef {object} ReadRefTableReturnType + * @prop {number} startingIndex + * @prop {number} maxIndex + * @prop {GetFullXrefTableReturnType} offsets + */ +/** + * @param {Buffer} pdfBuffer + * @returns {ReadRefTableReturnType} + */ +declare function readRefTable(pdf: any): ReadRefTableReturnType; +//# sourceMappingURL=readRefTable.d.ts.map \ No newline at end of file diff --git a/packages/placeholder-plain/dist/readRefTable.d.ts.map b/packages/placeholder-plain/dist/readRefTable.d.ts.map new file mode 100644 index 00000000..e1b42a58 --- /dev/null +++ b/packages/placeholder-plain/dist/readRefTable.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"readRefTable.d.ts","sourceRoot":"","sources":["../src/readRefTable.js"],"names":[],"mappings":"AAGO,yDASN;AAEM;;;;EAmEN;AAUM,sCAHI,MAAM,8BAmBhB;;yCAvBY,aAAS;;mBA2BZ,MAAM;cACN,MAAM;;;AAHhB;;;;;GAKG;AAEH;;;GAGG;AACH,yCAFa,sBAAsB,CAYlC"} \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/readRefTable.js b/packages/placeholder-plain/dist/readRefTable.js similarity index 74% rename from dist/helpers/plainAddPlaceholder/readRefTable.js rename to packages/placeholder-plain/dist/readRefTable.js index 8c8a75c2..990a41f6 100644 --- a/dist/helpers/plainAddPlaceholder/readRefTable.js +++ b/packages/placeholder-plain/dist/readRefTable.js @@ -4,75 +4,55 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.getXref = exports.getLastTrailerPosition = exports.getFullXrefTable = exports.default = void 0; - -var _SignPdfError = _interopRequireDefault(require("../../SignPdfError")); - +var _utils = require("@signpdf/utils"); var _xrefToRefMap = _interopRequireDefault(require("./xrefToRefMap")); - function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - const getLastTrailerPosition = pdf => { const trailerStart = pdf.lastIndexOf(Buffer.from('trailer', 'utf8')); const trailer = pdf.slice(trailerStart, pdf.length - 6); const xRefPosition = trailer.slice(trailer.lastIndexOf(Buffer.from('startxref', 'utf8')) + 10).toString(); return parseInt(xRefPosition); }; - exports.getLastTrailerPosition = getLastTrailerPosition; - const getXref = (pdf, position) => { let refTable = pdf.slice(position); // slice starting from where xref starts - const realPosition = refTable.indexOf(Buffer.from('xref', 'utf8')); - if (realPosition === -1) { - throw new _SignPdfError.default(`Could not find xref anywhere at or after ${position}.`, _SignPdfError.default.TYPE_PARSE); + throw new _utils.SignPdfError(`Could not find xref anywhere at or after ${position}.`, _utils.SignPdfError.TYPE_PARSE); } - if (realPosition > 0) { const prefix = refTable.slice(0, realPosition); - if (prefix.toString().replace(/\s*/g, '') !== '') { - throw new _SignPdfError.default(`Expected xref at ${position} but found other content.`, _SignPdfError.default.TYPE_PARSE); + throw new _utils.SignPdfError(`Expected xref at ${position} but found other content.`, _utils.SignPdfError.TYPE_PARSE); } } - const nextEofPosition = refTable.indexOf(Buffer.from('%%EOF', 'utf8')); - if (nextEofPosition === -1) { - throw new _SignPdfError.default('Expected EOF after xref and trailer but could not find one.', _SignPdfError.default.TYPE_PARSE); + throw new _utils.SignPdfError('Expected EOF after xref and trailer but could not find one.', _utils.SignPdfError.TYPE_PARSE); } - refTable = refTable.slice(0, nextEofPosition); refTable = refTable.slice(realPosition + 4); // move ahead with the "xref" - refTable = refTable.slice(refTable.indexOf('\n') + 1); // move after the next new line - // extract the size + // extract the size let size = refTable.toString().split('/Size')[1]; - if (!size) { - throw new _SignPdfError.default('Size not found in xref table.', _SignPdfError.default.TYPE_PARSE); + throw new _utils.SignPdfError('Size not found in xref table.', _utils.SignPdfError.TYPE_PARSE); } - size = /^\s*(\d+)/.exec(size); - if (size === null) { - throw new _SignPdfError.default('Failed to parse size of xref table.', _SignPdfError.default.TYPE_PARSE); + throw new _utils.SignPdfError('Failed to parse size of xref table.', _utils.SignPdfError.TYPE_PARSE); } - size = parseInt(size[1]); const [objects, infos] = refTable.toString().split('trailer'); const isContainingPrev = infos.split('/Prev')[1] != null; let prev; - if (isContainingPrev) { const pagesRefRegex = /Prev (\d+)/g; const match = pagesRefRegex.exec(infos); const [, prevPosition] = match; prev = prevPosition; } - const xRefContent = (0, _xrefToRefMap.default)(objects); return { size, @@ -81,29 +61,39 @@ const getXref = (pdf, position) => { }; }; -exports.getXref = getXref; +/** + * @typedef {Map<*, *>} GetFullXrefTableReturnType + */ +/** + * @param {Buffer} pdf + * @returns {GetFullXrefTableReturnType} + */ +exports.getXref = getXref; const getFullXrefTable = pdf => { const lastTrailerPosition = getLastTrailerPosition(pdf); const lastXrefTable = getXref(pdf, lastTrailerPosition); - if (lastXrefTable.prev === undefined) { return lastXrefTable.xRefContent; } - const pdfWithoutLastTrailer = pdf.slice(0, lastTrailerPosition); const partOfXrefTable = getFullXrefTable(pdfWithoutLastTrailer); const mergedXrefTable = new Map([...partOfXrefTable, ...lastXrefTable.xRefContent]); return mergedXrefTable; }; + /** - * @param {Buffer} pdfBuffer - * @returns {object} + * @typedef {object} ReadRefTableReturnType + * @prop {number} startingIndex + * @prop {number} maxIndex + * @prop {GetFullXrefTableReturnType} offsets */ - +/** + * @param {Buffer} pdfBuffer + * @returns {ReadRefTableReturnType} + */ exports.getFullXrefTable = getFullXrefTable; - const readRefTable = pdf => { const fullXrefTable = getFullXrefTable(pdf); const startingIndex = 0; @@ -114,6 +104,4 @@ const readRefTable = pdf => { offsets: fullXrefTable }; }; - -var _default = readRefTable; -exports.default = _default; \ No newline at end of file +var _default = exports.default = readRefTable; \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/xrefToRefMap.d.ts b/packages/placeholder-plain/dist/xrefToRefMap.d.ts similarity index 100% rename from dist/helpers/plainAddPlaceholder/xrefToRefMap.d.ts rename to packages/placeholder-plain/dist/xrefToRefMap.d.ts diff --git a/packages/placeholder-plain/dist/xrefToRefMap.d.ts.map b/packages/placeholder-plain/dist/xrefToRefMap.d.ts.map new file mode 100644 index 00000000..70ad0368 --- /dev/null +++ b/packages/placeholder-plain/dist/xrefToRefMap.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"xrefToRefMap.d.ts","sourceRoot":"","sources":["../src/xrefToRefMap.js"],"names":[],"mappings":";AAEA,8DA2CC"} \ No newline at end of file diff --git a/dist/helpers/plainAddPlaceholder/xrefToRefMap.js b/packages/placeholder-plain/dist/xrefToRefMap.js similarity index 58% rename from dist/helpers/plainAddPlaceholder/xrefToRefMap.js rename to packages/placeholder-plain/dist/xrefToRefMap.js index 5c78727b..0fec1015 100644 --- a/dist/helpers/plainAddPlaceholder/xrefToRefMap.js +++ b/packages/placeholder-plain/dist/xrefToRefMap.js @@ -4,11 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; - -var _SignPdfError = _interopRequireDefault(require("../../SignPdfError")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +var _utils = require("@signpdf/utils"); const xrefToRefMap = xrefString => { const lines = xrefString.split('\n').filter(l => l !== ''); let index = 0; @@ -16,39 +12,30 @@ const xrefToRefMap = xrefString => { const xref = new Map(); lines.forEach(line => { const split = line.split(' '); - if (split.length === 2) { index = parseInt(split[0]); expectedLines = parseInt(split[1]); return; } - if (expectedLines <= 0) { - throw new _SignPdfError.default('Too many lines in xref table.', _SignPdfError.default.TYPE_PARSE); + throw new _utils.SignPdfError('Too many lines in xref table.', _utils.SignPdfError.TYPE_PARSE); } - expectedLines -= 1; const [offset,, inUse] = split; - if (inUse.trim() === 'f') { index += 1; return; } - if (inUse.trim() !== 'n') { - throw new _SignPdfError.default(`Unknown in-use flag "${inUse}". Expected "n" or "f".`, _SignPdfError.default.TYPE_PARSE); + throw new _utils.SignPdfError(`Unknown in-use flag "${inUse}". Expected "n" or "f".`, _utils.SignPdfError.TYPE_PARSE); } - if (!/^\d+$/.test(offset.trim())) { - throw new _SignPdfError.default(`Expected integer offset. Got "${offset}".`, _SignPdfError.default.TYPE_PARSE); + throw new _utils.SignPdfError(`Expected integer offset. Got "${offset}".`, _utils.SignPdfError.TYPE_PARSE); } - const storeOffset = parseInt(offset.trim()); xref.set(index, storeOffset); index += 1; }); return xref; }; - -var _default = xrefToRefMap; -exports.default = _default; \ No newline at end of file +var _default = exports.default = xrefToRefMap; \ No newline at end of file diff --git a/packages/signpdf/dist/signpdf.d.ts b/packages/signpdf/dist/signpdf.d.ts new file mode 100644 index 00000000..fb1d59a3 --- /dev/null +++ b/packages/signpdf/dist/signpdf.d.ts @@ -0,0 +1,23 @@ +/** + * @typedef {object} SignerOptions + * @prop {string} [passphrase] + * @prop {boolean} [asn1StrictParsing] + */ +export class SignPdf { + byteRangePlaceholder: "**********"; + lastSignature: string; + /** + * @param {Buffer} pdfBuffer + * @param {Buffer} p12Buffer + * @param {SignerOptions} additionalOptions + * @returns {Buffer} + */ + sign(pdfBuffer: Buffer, p12Buffer: Buffer, additionalOptions?: SignerOptions): Buffer; +} +declare const _default: SignPdf; +export default _default; +export type SignerOptions = { + passphrase?: string; + asn1StrictParsing?: boolean; +}; +//# sourceMappingURL=signpdf.d.ts.map \ No newline at end of file diff --git a/packages/signpdf/dist/signpdf.d.ts.map b/packages/signpdf/dist/signpdf.d.ts.map new file mode 100644 index 00000000..8384fb8c --- /dev/null +++ b/packages/signpdf/dist/signpdf.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"signpdf.d.ts","sourceRoot":"","sources":["../src/signpdf.js"],"names":[],"mappings":"AAQA;;;;GAIG;AAEH;IAEQ,mCAA0D;IAC1D,sBAAyB;IAG7B;;;;;OAKG;IACH,gBALW,MAAM,aACN,MAAM,sBACN,aAAa,GACX,MAAM,CA4KlB;CACJ;;;;iBA3LS,MAAM;wBACN,OAAO"} \ No newline at end of file diff --git a/dist/signpdf.js b/packages/signpdf/dist/signpdf.js similarity index 50% rename from dist/signpdf.js rename to packages/signpdf/dist/signpdf.js index 58d876de..a5157d0a 100644 --- a/dist/signpdf.js +++ b/packages/signpdf/dist/signpdf.js @@ -3,86 +3,52 @@ Object.defineProperty(exports, "__esModule", { value: true }); -var _exportNames = { - SignPdf: true, - SignPdfError: true -}; -exports.SignPdf = void 0; -Object.defineProperty(exports, "SignPdfError", { - enumerable: true, - get: function () { - return _SignPdfError.default; - } -}); -exports.default = void 0; - +exports.default = exports.SignPdf = void 0; var _nodeForge = _interopRequireDefault(require("node-forge")); - -var _SignPdfError = _interopRequireDefault(require("./SignPdfError")); - -var _helpers = require("./helpers"); - -Object.keys(_helpers).forEach(function (key) { - if (key === "default" || key === "__esModule") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _helpers[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function () { - return _helpers[key]; - } - }); -}); - -var _const = require("./helpers/const"); - -Object.keys(_const).forEach(function (key) { - if (key === "default" || key === "__esModule") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _const[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function () { - return _const[key]; - } - }); -}); - +var _utils = require("@signpdf/utils"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +/** + * @typedef {object} SignerOptions + * @prop {string} [passphrase] + * @prop {boolean} [asn1StrictParsing] + */ class SignPdf { constructor() { - this.byteRangePlaceholder = _const.DEFAULT_BYTE_RANGE_PLACEHOLDER; + this.byteRangePlaceholder = _utils.DEFAULT_BYTE_RANGE_PLACEHOLDER; this.lastSignature = null; } + /** + * @param {Buffer} pdfBuffer + * @param {Buffer} p12Buffer + * @param {SignerOptions} additionalOptions + * @returns {Buffer} + */ sign(pdfBuffer, p12Buffer, additionalOptions = {}) { const options = { asn1StrictParsing: false, passphrase: '', ...additionalOptions }; - if (!(pdfBuffer instanceof Buffer)) { - throw new _SignPdfError.default('PDF expected as Buffer.', _SignPdfError.default.TYPE_INPUT); + throw new _utils.SignPdfError('PDF expected as Buffer.', _utils.SignPdfError.TYPE_INPUT); } - if (!(p12Buffer instanceof Buffer)) { - throw new _SignPdfError.default('p12 certificate expected as Buffer.', _SignPdfError.default.TYPE_INPUT); + throw new _utils.SignPdfError('p12 certificate expected as Buffer.', _utils.SignPdfError.TYPE_INPUT); } + let pdf = (0, _utils.removeTrailingNewLine)(pdfBuffer); - let pdf = (0, _helpers.removeTrailingNewLine)(pdfBuffer); // Find the ByteRange placeholder. - + // Find the ByteRange placeholder. const { byteRangePlaceholder - } = (0, _helpers.findByteRange)(pdf); - + } = (0, _utils.findByteRange)(pdf); if (!byteRangePlaceholder) { - throw new _SignPdfError.default(`Could not find empty ByteRange placeholder: ${byteRangePlaceholder}`, _SignPdfError.default.TYPE_PARSE); + throw new _utils.SignPdfError(`Could not find empty ByteRange placeholder: ${byteRangePlaceholder}`, _utils.SignPdfError.TYPE_PARSE); } + const byteRangePos = pdf.indexOf(byteRangePlaceholder); - const byteRangePos = pdf.indexOf(byteRangePlaceholder); // Calculate the actual ByteRange that needs to replace the placeholder. - + // Calculate the actual ByteRange that needs to replace the placeholder. const byteRangeEnd = byteRangePos + byteRangePlaceholder.length; const contentsTagPos = pdf.indexOf('/Contents ', byteRangeEnd); const placeholderPos = pdf.indexOf('<', contentsTagPos); @@ -94,57 +60,56 @@ class SignPdf { byteRange[2] = byteRange[1] + placeholderLengthWithBrackets; byteRange[3] = pdf.length - byteRange[2]; let actualByteRange = `/ByteRange [${byteRange.join(' ')}]`; - actualByteRange += ' '.repeat(byteRangePlaceholder.length - actualByteRange.length); // Replace the /ByteRange placeholder with the actual ByteRange + actualByteRange += ' '.repeat(byteRangePlaceholder.length - actualByteRange.length); - pdf = Buffer.concat([pdf.slice(0, byteRangePos), Buffer.from(actualByteRange), pdf.slice(byteRangeEnd)]); // Remove the placeholder signature + // Replace the /ByteRange placeholder with the actual ByteRange + pdf = Buffer.concat([pdf.slice(0, byteRangePos), Buffer.from(actualByteRange), pdf.slice(byteRangeEnd)]); - pdf = Buffer.concat([pdf.slice(0, byteRange[1]), pdf.slice(byteRange[2], byteRange[2] + byteRange[3])]); // Convert Buffer P12 to a forge implementation. + // Remove the placeholder signature + pdf = Buffer.concat([pdf.slice(0, byteRange[1]), pdf.slice(byteRange[2], byteRange[2] + byteRange[3])]); + // Convert Buffer P12 to a forge implementation. const forgeCert = _nodeForge.default.util.createBuffer(p12Buffer.toString('binary')); - const p12Asn1 = _nodeForge.default.asn1.fromDer(forgeCert); + const p12 = _nodeForge.default.pkcs12.pkcs12FromAsn1(p12Asn1, options.asn1StrictParsing, options.passphrase); - const p12 = _nodeForge.default.pkcs12.pkcs12FromAsn1(p12Asn1, options.asn1StrictParsing, options.passphrase); // Extract safe bags by type. + // Extract safe bags by type. // We will need all the certificates and the private key. - - const certBags = p12.getBags({ bagType: _nodeForge.default.pki.oids.certBag })[_nodeForge.default.pki.oids.certBag]; - const keyBags = p12.getBags({ bagType: _nodeForge.default.pki.oids.pkcs8ShroudedKeyBag })[_nodeForge.default.pki.oids.pkcs8ShroudedKeyBag]; + const privateKey = keyBags[0].key; + // Here comes the actual PKCS#7 signing. + const p7 = _nodeForge.default.pkcs7.createSignedData(); + // Start off by setting the content. + p7.content = _nodeForge.default.util.createBuffer(pdf.toString('binary')); - const privateKey = keyBags[0].key; // Here comes the actual PKCS#7 signing. - - const p7 = _nodeForge.default.pkcs7.createSignedData(); // Start off by setting the content. - - - p7.content = _nodeForge.default.util.createBuffer(pdf.toString('binary')); // Then add all the certificates (-cacerts & -clcerts) + // Then add all the certificates (-cacerts & -clcerts) // Keep track of the last found client certificate. // This will be the public key that will be bundled in the signature. - let certificate; Object.keys(certBags).forEach(i => { const { publicKey } = certBags[i].cert; - p7.addCertificate(certBags[i].cert); // Try to find the certificate that matches the private key. + p7.addCertificate(certBags[i].cert); + // Try to find the certificate that matches the private key. if (privateKey.n.compareTo(publicKey.n) === 0 && privateKey.e.compareTo(publicKey.e) === 0) { certificate = certBags[i].cert; } }); - if (typeof certificate === 'undefined') { - throw new _SignPdfError.default('Failed to find a certificate that matches the private key.', _SignPdfError.default.TYPE_INPUT); - } // Add a sha256 signer. That's what Adobe.PPKLite adbe.pkcs7.detached expects. + throw new _utils.SignPdfError('Failed to find a certificate that matches the private key.', _utils.SignPdfError.TYPE_INPUT); + } + + // Add a sha256 signer. That's what Adobe.PPKLite adbe.pkcs7.detached expects. // Note that the authenticatedAttributes order is relevant for correct // EU signature validation: // https://ec.europa.eu/digital-building-blocks/DSS/webapp-demo/validation - - p7.addSigner({ key: privateKey, certificate, @@ -159,38 +124,36 @@ class SignPdf { // Would be useful to match the creation time of the document for example. value: new Date() }, { - type: _nodeForge.default.pki.oids.messageDigest // value will be auto-populated at signing time - + type: _nodeForge.default.pki.oids.messageDigest + // value will be auto-populated at signing time }] - }); // Sign in detached mode. + }); + // Sign in detached mode. p7.sign({ detached: true - }); // Check if the PDF has a good enough placeholder to fit the signature. + }); - const raw = _nodeForge.default.asn1.toDer(p7.toAsn1()).getBytes(); // placeholderLength represents the length of the HEXified symbols but we're + // Check if the PDF has a good enough placeholder to fit the signature. + const raw = _nodeForge.default.asn1.toDer(p7.toAsn1()).getBytes(); + // placeholderLength represents the length of the HEXified symbols but we're // checking the actual lengths. - - if (raw.length * 2 > placeholderLength) { - throw new _SignPdfError.default(`Signature exceeds placeholder length: ${raw.length * 2} > ${placeholderLength}`, _SignPdfError.default.TYPE_INPUT); + throw new _utils.SignPdfError(`Signature exceeds placeholder length: ${raw.length * 2} > ${placeholderLength}`, _utils.SignPdfError.TYPE_INPUT); } + let signature = Buffer.from(raw, 'binary').toString('hex'); + // Store the HEXified signature. At least useful in tests. + this.lastSignature = signature; - let signature = Buffer.from(raw, 'binary').toString('hex'); // Store the HEXified signature. At least useful in tests. - - this.lastSignature = signature; // Pad the signature with zeroes so the it is the same length as the placeholder + // Pad the signature with zeroes so the it is the same length as the placeholder + signature += Buffer.from(String.fromCharCode(0).repeat(placeholderLength / 2 - raw.length)).toString('hex'); - signature += Buffer.from(String.fromCharCode(0).repeat(placeholderLength / 2 - raw.length)).toString('hex'); // Place it in the document. - - pdf = Buffer.concat([pdf.slice(0, byteRange[1]), Buffer.from(`<${signature}>`), pdf.slice(byteRange[1])]); // Magic. Done. + // Place it in the document. + pdf = Buffer.concat([pdf.slice(0, byteRange[1]), Buffer.from(`<${signature}>`), pdf.slice(byteRange[1])]); + // Magic. Done. return pdf; } - } - exports.SignPdf = SignPdf; - -var _default = new SignPdf(); - -exports.default = _default; \ No newline at end of file +var _default = exports.default = new SignPdf(); \ No newline at end of file diff --git a/dist/SignPdfError.d.ts b/packages/utils/dist/SignPdfError.d.ts similarity index 81% rename from dist/SignPdfError.d.ts rename to packages/utils/dist/SignPdfError.d.ts index 177c9a5f..31f95d8f 100644 --- a/dist/SignPdfError.d.ts +++ b/packages/utils/dist/SignPdfError.d.ts @@ -2,12 +2,11 @@ export const ERROR_TYPE_UNKNOWN: 1; export const ERROR_TYPE_INPUT: 2; export const ERROR_TYPE_PARSE: 3; export const ERROR_VERIFY_SIGNATURE: 4; -export default SignPdfError; -declare class SignPdfError extends Error { +export class SignPdfError extends Error { constructor(msg: any, type?: number); type: number; } -declare namespace SignPdfError { +export namespace SignPdfError { export { ERROR_TYPE_UNKNOWN as TYPE_UNKNOWN }; export { ERROR_TYPE_INPUT as TYPE_INPUT }; export { ERROR_TYPE_PARSE as TYPE_PARSE }; diff --git a/dist/SignPdfError.d.ts.map b/packages/utils/dist/SignPdfError.d.ts.map similarity index 63% rename from dist/SignPdfError.d.ts.map rename to packages/utils/dist/SignPdfError.d.ts.map index 98cdca99..b8f6e738 100644 --- a/dist/SignPdfError.d.ts.map +++ b/packages/utils/dist/SignPdfError.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"SignPdfError.d.ts","sourceRoot":"","sources":["../src/SignPdfError.js"],"names":[],"mappings":"AAAA,mCAAoC;AACpC,iCAAkC;AAClC,iCAAkC;AAClC,uCAAwC;;AAExC;IACI,qCAGC;IADG,aAAgB;CAEvB"} \ No newline at end of file +{"version":3,"file":"SignPdfError.d.ts","sourceRoot":"","sources":["../src/SignPdfError.js"],"names":[],"mappings":"AAAA,mCAAoC;AACpC,iCAAkC;AAClC,iCAAkC;AAClC,uCAAwC;AAExC;IACI,qCAGC;IADG,aAAgB;CAEvB"} \ No newline at end of file diff --git a/packages/utils/dist/SignPdfError.js b/packages/utils/dist/SignPdfError.js new file mode 100644 index 00000000..0fe141c3 --- /dev/null +++ b/packages/utils/dist/SignPdfError.js @@ -0,0 +1,23 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.SignPdfError = exports.ERROR_VERIFY_SIGNATURE = exports.ERROR_TYPE_UNKNOWN = exports.ERROR_TYPE_PARSE = exports.ERROR_TYPE_INPUT = void 0; +const ERROR_TYPE_UNKNOWN = exports.ERROR_TYPE_UNKNOWN = 1; +const ERROR_TYPE_INPUT = exports.ERROR_TYPE_INPUT = 2; +const ERROR_TYPE_PARSE = exports.ERROR_TYPE_PARSE = 3; +const ERROR_VERIFY_SIGNATURE = exports.ERROR_VERIFY_SIGNATURE = 4; +class SignPdfError extends Error { + constructor(msg, type = ERROR_TYPE_UNKNOWN) { + super(msg); + this.type = type; + } +} + +// Shorthand +exports.SignPdfError = SignPdfError; +SignPdfError.TYPE_UNKNOWN = ERROR_TYPE_UNKNOWN; +SignPdfError.TYPE_INPUT = ERROR_TYPE_INPUT; +SignPdfError.TYPE_PARSE = ERROR_TYPE_PARSE; +SignPdfError.VERIFY_SIGNATURE = ERROR_VERIFY_SIGNATURE; \ No newline at end of file diff --git a/dist/helpers/const.d.ts b/packages/utils/dist/const.d.ts similarity index 100% rename from dist/helpers/const.d.ts rename to packages/utils/dist/const.d.ts diff --git a/packages/utils/dist/const.d.ts.map b/packages/utils/dist/const.d.ts.map new file mode 100644 index 00000000..08f3a1e4 --- /dev/null +++ b/packages/utils/dist/const.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../src/const.js"],"names":[],"mappings":"AAAA,4CAA6C;AAC7C,0DAA2D;AAC3D,mEAAoE;AACpE,2DAA4D;AAC5D,6DAA8D;AAC9D,kEAAmE"} \ No newline at end of file diff --git a/packages/utils/dist/const.js b/packages/utils/dist/const.js new file mode 100644 index 00000000..ef4db4db --- /dev/null +++ b/packages/utils/dist/const.js @@ -0,0 +1,12 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.SUBFILTER_ETSI_CADES_DETACHED = exports.SUBFILTER_ADOBE_X509_SHA1 = exports.SUBFILTER_ADOBE_PKCS7_SHA1 = exports.SUBFILTER_ADOBE_PKCS7_DETACHED = exports.DEFAULT_SIGNATURE_LENGTH = exports.DEFAULT_BYTE_RANGE_PLACEHOLDER = void 0; +const DEFAULT_SIGNATURE_LENGTH = exports.DEFAULT_SIGNATURE_LENGTH = 8192; +const DEFAULT_BYTE_RANGE_PLACEHOLDER = exports.DEFAULT_BYTE_RANGE_PLACEHOLDER = '**********'; +const SUBFILTER_ADOBE_PKCS7_DETACHED = exports.SUBFILTER_ADOBE_PKCS7_DETACHED = 'adbe.pkcs7.detached'; +const SUBFILTER_ADOBE_PKCS7_SHA1 = exports.SUBFILTER_ADOBE_PKCS7_SHA1 = 'adbe.pkcs7.sha1'; +const SUBFILTER_ADOBE_X509_SHA1 = exports.SUBFILTER_ADOBE_X509_SHA1 = 'adbe.x509.rsa.sha1'; +const SUBFILTER_ETSI_CADES_DETACHED = exports.SUBFILTER_ETSI_CADES_DETACHED = 'ETSI.CAdES.detached'; \ No newline at end of file diff --git a/packages/utils/dist/extractSignature.d.ts b/packages/utils/dist/extractSignature.d.ts new file mode 100644 index 00000000..8e5418a9 --- /dev/null +++ b/packages/utils/dist/extractSignature.d.ts @@ -0,0 +1,2 @@ +export function extractSignature(pdf: Buffer, signatureCount?: number): any; +//# sourceMappingURL=extractSignature.d.ts.map \ No newline at end of file diff --git a/packages/utils/dist/extractSignature.d.ts.map b/packages/utils/dist/extractSignature.d.ts.map new file mode 100644 index 00000000..c78b8650 --- /dev/null +++ b/packages/utils/dist/extractSignature.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"extractSignature.d.ts","sourceRoot":"","sources":["../src/extractSignature.js"],"names":[],"mappings":"AAsBO,sCAHI,MAAM,gCAsDhB"} \ No newline at end of file diff --git a/dist/helpers/extractSignature.js b/packages/utils/dist/extractSignature.js similarity index 67% rename from dist/helpers/extractSignature.js rename to packages/utils/dist/extractSignature.js index 0d300240..f54dd017 100644 --- a/dist/helpers/extractSignature.js +++ b/packages/utils/dist/extractSignature.js @@ -3,21 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = void 0; - -var _SignPdfError = _interopRequireDefault(require("../SignPdfError")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +exports.extractSignature = void 0; +var _SignPdfError = require("./SignPdfError"); const getSubstringIndex = (str, substring, n) => { let times = 0; let index = null; - while (times < n && index !== -1) { index = str.indexOf(substring, index + 1); times += 1; } - return index; }; /** @@ -29,33 +23,25 @@ const getSubstringIndex = (str, substring, n) => { * @param {Buffer} pdf * @returns {Object} {ByteRange: Number[], signature: Buffer, signedData: Buffer} */ - - const extractSignature = (pdf, signatureCount = 1) => { if (!(pdf instanceof Buffer)) { - throw new _SignPdfError.default('PDF expected as Buffer.', _SignPdfError.default.TYPE_INPUT); - } // const byteRangePos = pdf.indexOf('/ByteRange ['); - + throw new _SignPdfError.SignPdfError('PDF expected as Buffer.', _SignPdfError.SignPdfError.TYPE_INPUT); + } + // const byteRangePos = pdf.indexOf('/ByteRange ['); const byteRangePos = getSubstringIndex(pdf, '/ByteRange [', signatureCount); - if (byteRangePos === -1) { - throw new _SignPdfError.default('Failed to locate ByteRange.', _SignPdfError.default.TYPE_PARSE); + throw new _SignPdfError.SignPdfError('Failed to locate ByteRange.', _SignPdfError.SignPdfError.TYPE_PARSE); } - const byteRangeEnd = pdf.indexOf(']', byteRangePos); - if (byteRangeEnd === -1) { - throw new _SignPdfError.default('Failed to locate the end of the ByteRange.', _SignPdfError.default.TYPE_PARSE); + throw new _SignPdfError.SignPdfError('Failed to locate the end of the ByteRange.', _SignPdfError.SignPdfError.TYPE_PARSE); } - const byteRange = pdf.slice(byteRangePos, byteRangeEnd + 1).toString(); const matches = /\/ByteRange \[(\d+) +(\d+) +(\d+) +(\d+) *\]/.exec(byteRange); - if (matches === null) { - throw new _SignPdfError.default('Failed to parse the ByteRange.', _SignPdfError.default.TYPE_PARSE); + throw new _SignPdfError.SignPdfError('Failed to parse the ByteRange.', _SignPdfError.SignPdfError.TYPE_PARSE); } - const ByteRange = matches.slice(1).map(Number); const signedData = Buffer.concat([pdf.slice(ByteRange[0], ByteRange[0] + ByteRange[1]), pdf.slice(ByteRange[2], ByteRange[2] + ByteRange[3])]); const signatureHex = pdf.slice(ByteRange[0] + ByteRange[1] + 1, ByteRange[2]).toString('binary').replace(/(?:00|>)+$/, ''); @@ -66,6 +52,4 @@ const extractSignature = (pdf, signatureCount = 1) => { signedData }; }; - -var _default = extractSignature; -exports.default = _default; \ No newline at end of file +exports.extractSignature = extractSignature; \ No newline at end of file diff --git a/packages/utils/dist/findByteRange.d.ts b/packages/utils/dist/findByteRange.d.ts new file mode 100644 index 00000000..1a0ecd95 --- /dev/null +++ b/packages/utils/dist/findByteRange.d.ts @@ -0,0 +1,2 @@ +export function findByteRange(pdf: Buffer, placeholder?: string): any; +//# sourceMappingURL=findByteRange.d.ts.map \ No newline at end of file diff --git a/packages/utils/dist/findByteRange.d.ts.map b/packages/utils/dist/findByteRange.d.ts.map new file mode 100644 index 00000000..993f6035 --- /dev/null +++ b/packages/utils/dist/findByteRange.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"findByteRange.d.ts","sourceRoot":"","sources":["../src/findByteRange.js"],"names":[],"mappings":"AASO,mCAHI,MAAM,6BA4BhB"} \ No newline at end of file diff --git a/dist/helpers/findByteRange.js b/packages/utils/dist/findByteRange.js similarity index 57% rename from dist/helpers/findByteRange.js rename to packages/utils/dist/findByteRange.js index c3853bf0..86030a11 100644 --- a/dist/helpers/findByteRange.js +++ b/packages/utils/dist/findByteRange.js @@ -3,32 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = void 0; - -var _SignPdfError = _interopRequireDefault(require("../SignPdfError")); - +exports.findByteRange = void 0; +var _SignPdfError = require("./SignPdfError"); var _const = require("./const"); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - /** * Finds ByteRange information within a given PDF Buffer if one exists * * @param {Buffer} pdf * @returns {Object} {byteRangePlaceholder: String, byteRangeStrings: String[], byteRange: String[]} */ -const findByteRange = pdf => { +const findByteRange = (pdf, placeholder = _const.DEFAULT_BYTE_RANGE_PLACEHOLDER) => { if (!(pdf instanceof Buffer)) { - throw new _SignPdfError.default('PDF expected as Buffer.', _SignPdfError.default.TYPE_INPUT); + throw new _SignPdfError.SignPdfError('PDF expected as Buffer.', _SignPdfError.SignPdfError.TYPE_INPUT); } - const byteRangeStrings = pdf.toString().match(/\/ByteRange\s*\[{1}\s*(?:(?:\d*|\/\*{10})\s+){3}(?:\d+|\/\*{10}){1}\s*]{1}/g); - if (!byteRangeStrings) { - throw new _SignPdfError.default('No ByteRangeStrings found within PDF buffer', _SignPdfError.default.TYPE_PARSE); + throw new _SignPdfError.SignPdfError('No ByteRangeStrings found within PDF buffer', _SignPdfError.SignPdfError.TYPE_PARSE); } - - const byteRangePlaceholder = byteRangeStrings.find(s => s.includes(`/${_const.DEFAULT_BYTE_RANGE_PLACEHOLDER}`)); + const byteRangePlaceholder = byteRangeStrings.find(s => s.includes(`/${placeholder}`)); const byteRanges = byteRangeStrings.map(brs => brs.match(/[^[\s]*(?:\d|\/\*{10})/g)); return { byteRangePlaceholder, @@ -36,6 +28,4 @@ const findByteRange = pdf => { byteRanges }; }; - -var _default = findByteRange; -exports.default = _default; \ No newline at end of file +exports.findByteRange = findByteRange; \ No newline at end of file diff --git a/packages/utils/dist/index.d.ts b/packages/utils/dist/index.d.ts new file mode 100644 index 00000000..6fe8d0c4 --- /dev/null +++ b/packages/utils/dist/index.d.ts @@ -0,0 +1,6 @@ +export * from "./const"; +export * from "./extractSignature"; +export * from "./findByteRange"; +export * from "./removeTrailingNewLine"; +export * from "./SignPdfError"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/packages/utils/dist/index.d.ts.map b/packages/utils/dist/index.d.ts.map new file mode 100644 index 00000000..6e08bd54 --- /dev/null +++ b/packages/utils/dist/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":""} \ No newline at end of file diff --git a/packages/utils/dist/index.js b/packages/utils/dist/index.js new file mode 100644 index 00000000..fac505a1 --- /dev/null +++ b/packages/utils/dist/index.js @@ -0,0 +1,60 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +var _const = require("./const"); +Object.keys(_const).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (key in exports && exports[key] === _const[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _const[key]; + } + }); +}); +var _extractSignature = require("./extractSignature"); +Object.keys(_extractSignature).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (key in exports && exports[key] === _extractSignature[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _extractSignature[key]; + } + }); +}); +var _findByteRange = require("./findByteRange"); +Object.keys(_findByteRange).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (key in exports && exports[key] === _findByteRange[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _findByteRange[key]; + } + }); +}); +var _removeTrailingNewLine = require("./removeTrailingNewLine"); +Object.keys(_removeTrailingNewLine).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (key in exports && exports[key] === _removeTrailingNewLine[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _removeTrailingNewLine[key]; + } + }); +}); +var _SignPdfError = require("./SignPdfError"); +Object.keys(_SignPdfError).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (key in exports && exports[key] === _SignPdfError[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _SignPdfError[key]; + } + }); +}); \ No newline at end of file diff --git a/packages/utils/dist/removeTrailingNewLine.d.ts b/packages/utils/dist/removeTrailingNewLine.d.ts new file mode 100644 index 00000000..e688e875 --- /dev/null +++ b/packages/utils/dist/removeTrailingNewLine.d.ts @@ -0,0 +1,2 @@ +export function removeTrailingNewLine(pdf: Buffer): Buffer; +//# sourceMappingURL=removeTrailingNewLine.d.ts.map \ No newline at end of file diff --git a/packages/utils/dist/removeTrailingNewLine.d.ts.map b/packages/utils/dist/removeTrailingNewLine.d.ts.map new file mode 100644 index 00000000..e1e26ea4 --- /dev/null +++ b/packages/utils/dist/removeTrailingNewLine.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"removeTrailingNewLine.d.ts","sourceRoot":"","sources":["../src/removeTrailingNewLine.js"],"names":[],"mappings":"AAkBO,2CAHI,MAAM,GACJ,MAAM,CAuBlB"} \ No newline at end of file diff --git a/dist/helpers/removeTrailingNewLine.js b/packages/utils/dist/removeTrailingNewLine.js similarity index 60% rename from dist/helpers/removeTrailingNewLine.js rename to packages/utils/dist/removeTrailingNewLine.js index 74f19c47..b2474131 100644 --- a/dist/helpers/removeTrailingNewLine.js +++ b/packages/utils/dist/removeTrailingNewLine.js @@ -3,21 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = void 0; - -var _SignPdfError = _interopRequireDefault(require("../SignPdfError")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +exports.removeTrailingNewLine = void 0; +var _SignPdfError = require("./SignPdfError"); const sliceLastChar = (pdf, character) => { const lastChar = pdf.slice(pdf.length - 1).toString(); - if (lastChar === character) { return pdf.slice(0, pdf.length - 1); } - return pdf; }; + /** * Removes a trailing new line if there is such. * @@ -25,24 +20,17 @@ const sliceLastChar = (pdf, character) => { * @param {Buffer} pdf * @returns {Buffer} */ - - const removeTrailingNewLine = pdf => { if (!(pdf instanceof Buffer)) { - throw new _SignPdfError.default('PDF expected as Buffer.', _SignPdfError.default.TYPE_INPUT); + throw new _SignPdfError.SignPdfError('PDF expected as Buffer.', _SignPdfError.SignPdfError.TYPE_INPUT); } - let output = pdf; output = sliceLastChar(output, '\n'); output = sliceLastChar(output, '\r'); const lastLine = output.slice(output.length - 6).toString(); - if (lastLine !== '\n%%EOF') { - throw new _SignPdfError.default('A PDF file must end with an EOF line.', _SignPdfError.default.TYPE_PARSE); + throw new _SignPdfError.SignPdfError('A PDF file must end with an EOF line.', _SignPdfError.SignPdfError.TYPE_PARSE); } - return output; }; - -var _default = removeTrailingNewLine; -exports.default = _default; \ No newline at end of file +exports.removeTrailingNewLine = removeTrailingNewLine; \ No newline at end of file