@qrcommunication/gigapdf-lib 0.69.0 → 0.70.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -372,6 +372,16 @@ declare class GigaPdfEngine {
372
372
  /** Raise a model to an EPUB e-book (`.epub`). */
373
373
  modelToEpub(model: GigaDocument): Uint8Array;
374
374
  }
375
+ /**
376
+ * Default TSA round trip for {@link GigaPdfDoc.signTimestamped}: POST the
377
+ * RFC 3161 `TimeStampReq` to `url` as `application/timestamp-query` and return
378
+ * the raw `TimeStampResp` (`application/timestamp-reply`) body. Works in both
379
+ * Node and the browser via the global `fetch`.
380
+ *
381
+ * No SSRF allow-listing is performed here — the URL is host-supplied. Consumers
382
+ * that need to restrict it should pass their own `tsaFetch`.
383
+ */
384
+ declare function defaultTsaPost(url: string, req: Uint8Array): Promise<Uint8Array>;
375
385
  /** A Google font the HTML engine needs (resolved from the catalogue). */
376
386
  interface HtmlFontRequest {
377
387
  family: string;
@@ -1178,6 +1188,42 @@ interface SignP12Options {
1178
1188
  /** `/ContactInfo` — how to reach the signer. */
1179
1189
  contactInfo?: string;
1180
1190
  }
1191
+ /**
1192
+ * Options for {@link GigaPdfDoc.signTimestamped} — a PAdES-B-T signature with an
1193
+ * RFC 3161 trusted timestamp embedded in the SignerInfo (`ETSI.CAdES.detached`
1194
+ * subfilter, `signing-certificate-v2` signed attribute, `id-aa-timeStampToken`
1195
+ * unsigned attribute).
1196
+ *
1197
+ * The signing identity is either an imported PKCS#12 (`p12` + `password`) or, if
1198
+ * `p12` is omitted, a freshly generated self-signed digital ID (`random` +
1199
+ * `notBefore`/`notAfter`).
1200
+ */
1201
+ interface SignTsaOptions extends SignP12Options {
1202
+ /** TSA endpoint URL, e.g. `"https://freetsa.org/tsr"`. */
1203
+ tsaUrl: string;
1204
+ /**
1205
+ * Optional override for the TSA round trip — lets the host add auth headers,
1206
+ * proxies, retries, **and apply its own SSRF allow-list** (the engine only
1207
+ * emits the request; the URL is host-supplied). Receives the `TimeStampReq`
1208
+ * DER and the URL, must resolve to the raw `TimeStampResp` bytes. When omitted,
1209
+ * {@link defaultTsaPost} POSTs `application/timestamp-query` via `fetch`.
1210
+ */
1211
+ tsaFetch?: (req: Uint8Array, url: string) => Promise<Uint8Array>;
1212
+ /** PKCS#12 identity bytes. Omit to sign with a generated self-signed ID. */
1213
+ p12?: Uint8Array;
1214
+ /** PKCS#12 passphrase. */
1215
+ password?: string;
1216
+ /** Self-signed path: ≥ 256 bytes from `crypto.getRandomValues`. */
1217
+ random?: Uint8Array;
1218
+ /** Self-signed path: RSA modulus size in bits (default 2048). */
1219
+ keyBits?: number;
1220
+ /** Self-signed path: certificate `notBefore`, UTCTime `YYMMDDHHMMSSZ`. */
1221
+ notBefore?: string;
1222
+ /** Self-signed path: certificate `notAfter`, UTCTime `YYMMDDHHMMSSZ`. */
1223
+ notAfter?: string;
1224
+ /** Optional 8–16 random bytes echoed by the TSA (request/response correlation). */
1225
+ nonce?: Uint8Array;
1226
+ }
1181
1227
  /**
1182
1228
  * A markup annotation (rect corners in PDF user space, origin bottom-left).
1183
1229
  * Carries the common metadata plus the type-specific geometry a host editor
@@ -1832,6 +1878,21 @@ declare class GigaPdfDoc {
1832
1878
  * missing certificate.
1833
1879
  */
1834
1880
  signP12(p12: Uint8Array, password: string, opts?: SignP12Options): Uint8Array;
1881
+ /**
1882
+ * Sign with an embedded **RFC 3161 trusted timestamp** (PAdES-B-T). Unlike
1883
+ * {@link sign}/{@link signP12} this is `async`: the timestamp requires a
1884
+ * network round trip to a TSA, so the method runs the engine's two-phase flow
1885
+ * — build the signature → POST the `TimeStampReq` to the TSA → embed the
1886
+ * returned token — with the HTTP in between.
1887
+ *
1888
+ * The signing identity is `opts.p12` (+ `opts.password`) when supplied, else a
1889
+ * generated self-signed digital ID from `opts.random` (+ `notBefore`/
1890
+ * `notAfter`). `opts.tsaUrl` is the TSA endpoint (e.g. FreeTSA
1891
+ * `https://freetsa.org/tsr`); pass `opts.tsaFetch` to customise the request
1892
+ * (auth, proxy, SSRF allow-list). Throws a single generic error on any failure
1893
+ * (bad identity, TSA HTTP error, malformed response, or signature too large).
1894
+ */
1895
+ signTimestamped(opts: SignTsaOptions): Promise<Uint8Array>;
1835
1896
  getMetadata(key: string): string;
1836
1897
  /** Set an Info-dictionary entry (e.g. "Title", "Author"). */
1837
1898
  setMetadata(key: string, value: string): boolean;
@@ -1979,4 +2040,4 @@ declare class GigaPdfDoc {
1979
2040
  }): boolean;
1980
2041
  }
1981
2042
 
1982
- export { type AnnotationInfo, type Attachment, type Box, type DecodedImage, type DocumentLanguage, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, type GigaBlock, type GigaBlockAddr, type GigaBlockKind, type GigaBorderStyle, type GigaCellValue, type GigaCharStyle, type GigaDocument, type GigaGeneric, type GigaHeading, type GigaImageRef, type GigaInline, type GigaInlineRun, type GigaLinkTarget, type GigaList, type GigaListItem, type GigaListMarker, type GigaMergeRange, type GigaOutlineNode, type GigaPage, type GigaPageGeometry, type GigaParaPatch, type GigaParagraph, type GigaParagraphStyle, type GigaPathSeg, GigaPdfDoc, GigaPdfEngine, type GigaPlaceholder, type GigaPlaceholderRole, type GigaRect, type GigaRotation, type GigaSection, type GigaShape, type GigaSheet, type GigaSheetBlock, type GigaSheetCell, type GigaSheetRow, type GigaSlide, type GigaSlideBlock, type GigaStylePatch, type GigaTable, type GigaTableCell, type GigaTableRow, type GigaTextBox, type HeaderFooterAlign, type HeaderFooterSpec, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type HtmlResource, type HtmlResourceNeed, type ImageElementInfo, type LayerInfo, type LinkInfo, type ModelOp, type NamedDest, type OutlineEntry, type PageInfo, type PageMargins, type PathSegment, type PdfPermissions, type RadioOption, type SearchHit, type SignP12Options, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet };
2043
+ export { type AnnotationInfo, type Attachment, type Box, type DecodedImage, type DocumentLanguage, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, type GigaBlock, type GigaBlockAddr, type GigaBlockKind, type GigaBorderStyle, type GigaCellValue, type GigaCharStyle, type GigaDocument, type GigaGeneric, type GigaHeading, type GigaImageRef, type GigaInline, type GigaInlineRun, type GigaLinkTarget, type GigaList, type GigaListItem, type GigaListMarker, type GigaMergeRange, type GigaOutlineNode, type GigaPage, type GigaPageGeometry, type GigaParaPatch, type GigaParagraph, type GigaParagraphStyle, type GigaPathSeg, GigaPdfDoc, GigaPdfEngine, type GigaPlaceholder, type GigaPlaceholderRole, type GigaRect, type GigaRotation, type GigaSection, type GigaShape, type GigaSheet, type GigaSheetBlock, type GigaSheetCell, type GigaSheetRow, type GigaSlide, type GigaSlideBlock, type GigaStylePatch, type GigaTable, type GigaTableCell, type GigaTableRow, type GigaTextBox, type HeaderFooterAlign, type HeaderFooterSpec, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type HtmlResource, type HtmlResourceNeed, type ImageElementInfo, type LayerInfo, type LinkInfo, type ModelOp, type NamedDest, type OutlineEntry, type PageInfo, type PageMargins, type PathSegment, type PdfPermissions, type RadioOption, type SearchHit, type SignP12Options, type SignTsaOptions, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet, defaultTsaPost };
package/dist/index.d.ts CHANGED
@@ -372,6 +372,16 @@ declare class GigaPdfEngine {
372
372
  /** Raise a model to an EPUB e-book (`.epub`). */
373
373
  modelToEpub(model: GigaDocument): Uint8Array;
374
374
  }
375
+ /**
376
+ * Default TSA round trip for {@link GigaPdfDoc.signTimestamped}: POST the
377
+ * RFC 3161 `TimeStampReq` to `url` as `application/timestamp-query` and return
378
+ * the raw `TimeStampResp` (`application/timestamp-reply`) body. Works in both
379
+ * Node and the browser via the global `fetch`.
380
+ *
381
+ * No SSRF allow-listing is performed here — the URL is host-supplied. Consumers
382
+ * that need to restrict it should pass their own `tsaFetch`.
383
+ */
384
+ declare function defaultTsaPost(url: string, req: Uint8Array): Promise<Uint8Array>;
375
385
  /** A Google font the HTML engine needs (resolved from the catalogue). */
376
386
  interface HtmlFontRequest {
377
387
  family: string;
@@ -1178,6 +1188,42 @@ interface SignP12Options {
1178
1188
  /** `/ContactInfo` — how to reach the signer. */
1179
1189
  contactInfo?: string;
1180
1190
  }
1191
+ /**
1192
+ * Options for {@link GigaPdfDoc.signTimestamped} — a PAdES-B-T signature with an
1193
+ * RFC 3161 trusted timestamp embedded in the SignerInfo (`ETSI.CAdES.detached`
1194
+ * subfilter, `signing-certificate-v2` signed attribute, `id-aa-timeStampToken`
1195
+ * unsigned attribute).
1196
+ *
1197
+ * The signing identity is either an imported PKCS#12 (`p12` + `password`) or, if
1198
+ * `p12` is omitted, a freshly generated self-signed digital ID (`random` +
1199
+ * `notBefore`/`notAfter`).
1200
+ */
1201
+ interface SignTsaOptions extends SignP12Options {
1202
+ /** TSA endpoint URL, e.g. `"https://freetsa.org/tsr"`. */
1203
+ tsaUrl: string;
1204
+ /**
1205
+ * Optional override for the TSA round trip — lets the host add auth headers,
1206
+ * proxies, retries, **and apply its own SSRF allow-list** (the engine only
1207
+ * emits the request; the URL is host-supplied). Receives the `TimeStampReq`
1208
+ * DER and the URL, must resolve to the raw `TimeStampResp` bytes. When omitted,
1209
+ * {@link defaultTsaPost} POSTs `application/timestamp-query` via `fetch`.
1210
+ */
1211
+ tsaFetch?: (req: Uint8Array, url: string) => Promise<Uint8Array>;
1212
+ /** PKCS#12 identity bytes. Omit to sign with a generated self-signed ID. */
1213
+ p12?: Uint8Array;
1214
+ /** PKCS#12 passphrase. */
1215
+ password?: string;
1216
+ /** Self-signed path: ≥ 256 bytes from `crypto.getRandomValues`. */
1217
+ random?: Uint8Array;
1218
+ /** Self-signed path: RSA modulus size in bits (default 2048). */
1219
+ keyBits?: number;
1220
+ /** Self-signed path: certificate `notBefore`, UTCTime `YYMMDDHHMMSSZ`. */
1221
+ notBefore?: string;
1222
+ /** Self-signed path: certificate `notAfter`, UTCTime `YYMMDDHHMMSSZ`. */
1223
+ notAfter?: string;
1224
+ /** Optional 8–16 random bytes echoed by the TSA (request/response correlation). */
1225
+ nonce?: Uint8Array;
1226
+ }
1181
1227
  /**
1182
1228
  * A markup annotation (rect corners in PDF user space, origin bottom-left).
1183
1229
  * Carries the common metadata plus the type-specific geometry a host editor
@@ -1832,6 +1878,21 @@ declare class GigaPdfDoc {
1832
1878
  * missing certificate.
1833
1879
  */
1834
1880
  signP12(p12: Uint8Array, password: string, opts?: SignP12Options): Uint8Array;
1881
+ /**
1882
+ * Sign with an embedded **RFC 3161 trusted timestamp** (PAdES-B-T). Unlike
1883
+ * {@link sign}/{@link signP12} this is `async`: the timestamp requires a
1884
+ * network round trip to a TSA, so the method runs the engine's two-phase flow
1885
+ * — build the signature → POST the `TimeStampReq` to the TSA → embed the
1886
+ * returned token — with the HTTP in between.
1887
+ *
1888
+ * The signing identity is `opts.p12` (+ `opts.password`) when supplied, else a
1889
+ * generated self-signed digital ID from `opts.random` (+ `notBefore`/
1890
+ * `notAfter`). `opts.tsaUrl` is the TSA endpoint (e.g. FreeTSA
1891
+ * `https://freetsa.org/tsr`); pass `opts.tsaFetch` to customise the request
1892
+ * (auth, proxy, SSRF allow-list). Throws a single generic error on any failure
1893
+ * (bad identity, TSA HTTP error, malformed response, or signature too large).
1894
+ */
1895
+ signTimestamped(opts: SignTsaOptions): Promise<Uint8Array>;
1835
1896
  getMetadata(key: string): string;
1836
1897
  /** Set an Info-dictionary entry (e.g. "Title", "Author"). */
1837
1898
  setMetadata(key: string, value: string): boolean;
@@ -1979,4 +2040,4 @@ declare class GigaPdfDoc {
1979
2040
  }): boolean;
1980
2041
  }
1981
2042
 
1982
- export { type AnnotationInfo, type Attachment, type Box, type DecodedImage, type DocumentLanguage, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, type GigaBlock, type GigaBlockAddr, type GigaBlockKind, type GigaBorderStyle, type GigaCellValue, type GigaCharStyle, type GigaDocument, type GigaGeneric, type GigaHeading, type GigaImageRef, type GigaInline, type GigaInlineRun, type GigaLinkTarget, type GigaList, type GigaListItem, type GigaListMarker, type GigaMergeRange, type GigaOutlineNode, type GigaPage, type GigaPageGeometry, type GigaParaPatch, type GigaParagraph, type GigaParagraphStyle, type GigaPathSeg, GigaPdfDoc, GigaPdfEngine, type GigaPlaceholder, type GigaPlaceholderRole, type GigaRect, type GigaRotation, type GigaSection, type GigaShape, type GigaSheet, type GigaSheetBlock, type GigaSheetCell, type GigaSheetRow, type GigaSlide, type GigaSlideBlock, type GigaStylePatch, type GigaTable, type GigaTableCell, type GigaTableRow, type GigaTextBox, type HeaderFooterAlign, type HeaderFooterSpec, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type HtmlResource, type HtmlResourceNeed, type ImageElementInfo, type LayerInfo, type LinkInfo, type ModelOp, type NamedDest, type OutlineEntry, type PageInfo, type PageMargins, type PathSegment, type PdfPermissions, type RadioOption, type SearchHit, type SignP12Options, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet };
2043
+ export { type AnnotationInfo, type Attachment, type Box, type DecodedImage, type DocumentLanguage, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, type GigaBlock, type GigaBlockAddr, type GigaBlockKind, type GigaBorderStyle, type GigaCellValue, type GigaCharStyle, type GigaDocument, type GigaGeneric, type GigaHeading, type GigaImageRef, type GigaInline, type GigaInlineRun, type GigaLinkTarget, type GigaList, type GigaListItem, type GigaListMarker, type GigaMergeRange, type GigaOutlineNode, type GigaPage, type GigaPageGeometry, type GigaParaPatch, type GigaParagraph, type GigaParagraphStyle, type GigaPathSeg, GigaPdfDoc, GigaPdfEngine, type GigaPlaceholder, type GigaPlaceholderRole, type GigaRect, type GigaRotation, type GigaSection, type GigaShape, type GigaSheet, type GigaSheetBlock, type GigaSheetCell, type GigaSheetRow, type GigaSlide, type GigaSlideBlock, type GigaStylePatch, type GigaTable, type GigaTableCell, type GigaTableRow, type GigaTextBox, type HeaderFooterAlign, type HeaderFooterSpec, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type HtmlResource, type HtmlResourceNeed, type ImageElementInfo, type LayerInfo, type LinkInfo, type ModelOp, type NamedDest, type OutlineEntry, type PageInfo, type PageMargins, type PathSegment, type PdfPermissions, type RadioOption, type SearchHit, type SignP12Options, type SignTsaOptions, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet, defaultTsaPost };
package/dist/index.js CHANGED
@@ -828,6 +828,18 @@ var GigaPdfEngine = class _GigaPdfEngine {
828
828
  );
829
829
  }
830
830
  };
831
+ async function defaultTsaPost(url, req) {
832
+ const res = await fetch(url, {
833
+ method: "POST",
834
+ headers: { "Content-Type": "application/timestamp-query" },
835
+ body: req,
836
+ redirect: "error"
837
+ });
838
+ if (!res.ok) {
839
+ throw new Error(`TSA HTTP ${res.status}`);
840
+ }
841
+ return new Uint8Array(await res.arrayBuffer());
842
+ }
831
843
  function packHtmlResources(resources) {
832
844
  let size = 4;
833
845
  for (const r of resources) size += 4 + enc.encode(r.url).length + 4 + r.bytes.length;
@@ -1723,6 +1735,95 @@ var GigaPdfDoc = class {
1723
1735
  }
1724
1736
  return out;
1725
1737
  }
1738
+ /**
1739
+ * Sign with an embedded **RFC 3161 trusted timestamp** (PAdES-B-T). Unlike
1740
+ * {@link sign}/{@link signP12} this is `async`: the timestamp requires a
1741
+ * network round trip to a TSA, so the method runs the engine's two-phase flow
1742
+ * — build the signature → POST the `TimeStampReq` to the TSA → embed the
1743
+ * returned token — with the HTTP in between.
1744
+ *
1745
+ * The signing identity is `opts.p12` (+ `opts.password`) when supplied, else a
1746
+ * generated self-signed digital ID from `opts.random` (+ `notBefore`/
1747
+ * `notAfter`). `opts.tsaUrl` is the TSA endpoint (e.g. FreeTSA
1748
+ * `https://freetsa.org/tsr`); pass `opts.tsaFetch` to customise the request
1749
+ * (auth, proxy, SSRF allow-list). Throws a single generic error on any failure
1750
+ * (bad identity, TSA HTTP error, malformed response, or signature too large).
1751
+ */
1752
+ async signTimestamped(opts) {
1753
+ const usingP12 = opts.p12 != null && opts.p12.length > 0;
1754
+ if (!usingP12 && (opts.random == null || opts.random.length < 256)) {
1755
+ throw new Error(
1756
+ "signTimestamped: self-signed path needs `random` \u2265 256 bytes (or pass a `p12`)"
1757
+ );
1758
+ }
1759
+ const fields = [
1760
+ opts.name ?? "",
1761
+ opts.reason ?? "",
1762
+ opts.date ?? "",
1763
+ opts.location ?? "",
1764
+ opts.contactInfo ?? "",
1765
+ opts.notBefore ?? "",
1766
+ opts.notAfter ?? ""
1767
+ ].join(" ");
1768
+ const rand = opts.random ?? new Uint8Array(0);
1769
+ const p12 = opts.p12 ?? new Uint8Array(0);
1770
+ const nonce = opts.nonce ?? new Uint8Array(0);
1771
+ const keyBits = opts.keyBits ?? 2048;
1772
+ const rPtr = this.g._toWasm(rand);
1773
+ const p12Ptr = this.g._toWasm(p12);
1774
+ const noncePtr = this.g._toWasm(nonce);
1775
+ let request;
1776
+ try {
1777
+ request = this.g._withStr(
1778
+ opts.password ?? "",
1779
+ (pwP, pwL) => this.g._withStr(
1780
+ fields,
1781
+ (fP, fL) => this.g._buffer(
1782
+ (o) => this.ex().gp_sign_prepare_tsa(
1783
+ this.h,
1784
+ fP,
1785
+ fL,
1786
+ rPtr,
1787
+ rand.length,
1788
+ keyBits,
1789
+ p12Ptr,
1790
+ p12.length,
1791
+ pwP,
1792
+ pwL,
1793
+ noncePtr,
1794
+ nonce.length,
1795
+ o
1796
+ )
1797
+ )
1798
+ )
1799
+ );
1800
+ } finally {
1801
+ this.g._free(rPtr, rand.length);
1802
+ this.g._free(p12Ptr, p12.length);
1803
+ this.g._free(noncePtr, nonce.length);
1804
+ }
1805
+ if (request.length === 0) {
1806
+ throw new Error(
1807
+ "timestamped signing failed: invalid identity or could not build the timestamp request"
1808
+ );
1809
+ }
1810
+ const response = opts.tsaFetch ? await opts.tsaFetch(request, opts.tsaUrl) : await defaultTsaPost(opts.tsaUrl, request);
1811
+ const tokenPtr = this.g._toWasm(response);
1812
+ let out;
1813
+ try {
1814
+ out = this.g._buffer(
1815
+ (o) => this.ex().gp_sign_finish_tsa(this.h, tokenPtr, response.length, o)
1816
+ );
1817
+ } finally {
1818
+ this.g._free(tokenPtr, response.length);
1819
+ }
1820
+ if (out.length === 0) {
1821
+ throw new Error(
1822
+ "timestamped signing failed: TSA response rejected or signature too large for the reserved space"
1823
+ );
1824
+ }
1825
+ return out;
1826
+ }
1726
1827
  // metadata
1727
1828
  getMetadata(key) {
1728
1829
  return this.g._withStr(
@@ -2121,6 +2222,7 @@ var GigaPdfDoc = class {
2121
2222
  };
2122
2223
  export {
2123
2224
  GigaPdfDoc,
2124
- GigaPdfEngine
2225
+ GigaPdfEngine,
2226
+ defaultTsaPost
2125
2227
  };
2126
2228
  //# sourceMappingURL=index.js.map