@qrcommunication/gigapdf-lib 0.68.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
@@ -1567,6 +1613,30 @@ declare class GigaPdfDoc {
1567
1613
  * user space. PNG alpha is honoured; `opacity` (0..1) sets an overall alpha.
1568
1614
  */
1569
1615
  addImage(page: number, data: Uint8Array, x: number, y: number, w: number, h: number, opacity?: number): boolean;
1616
+ /**
1617
+ * Stamp an **image watermark** across pages from raw image bytes. Accepts the
1618
+ * same five formats the engine decodes — **PNG, JPEG, WebP, GIF, AVIF**. The
1619
+ * image is embedded **once** and referenced on every target page.
1620
+ *
1621
+ * `opts.pages` is a list of 1-based page numbers; omit it (or pass `[]`) to
1622
+ * stamp every page. `opts.anchor` positions the image (`'center'` default, or a
1623
+ * corner) and `opts.offsetX`/`offsetY` nudge it (in points; in `tile` mode they
1624
+ * become the gaps between tiles). `opts.width`/`height` set the target size in
1625
+ * points (height keeps the source aspect ratio when omitted). `opts.rotationDeg`
1626
+ * rotates about the image centre and `opts.opacity` (0–1) sets the alpha.
1627
+ * Returns `false` if the image can't be decoded.
1628
+ */
1629
+ addImageWatermark(data: Uint8Array, opts?: {
1630
+ pages?: number[];
1631
+ anchor?: 'center' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
1632
+ offsetX?: number;
1633
+ offsetY?: number;
1634
+ width?: number;
1635
+ height?: number;
1636
+ rotationDeg?: number;
1637
+ opacity?: number;
1638
+ tile?: boolean;
1639
+ }): boolean;
1570
1640
  /**
1571
1641
  * Draw SVG markup on a page as **native vector paths** (crisp at any zoom, not
1572
1642
  * rasterized), fitting its `viewBox` into the box `(x, y, w, h)` in PDF points
@@ -1808,6 +1878,21 @@ declare class GigaPdfDoc {
1808
1878
  * missing certificate.
1809
1879
  */
1810
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>;
1811
1896
  getMetadata(key: string): string;
1812
1897
  /** Set an Info-dictionary entry (e.g. "Title", "Author"). */
1813
1898
  setMetadata(key: string, value: string): boolean;
@@ -1955,4 +2040,4 @@ declare class GigaPdfDoc {
1955
2040
  }): boolean;
1956
2041
  }
1957
2042
 
1958
- 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
@@ -1567,6 +1613,30 @@ declare class GigaPdfDoc {
1567
1613
  * user space. PNG alpha is honoured; `opacity` (0..1) sets an overall alpha.
1568
1614
  */
1569
1615
  addImage(page: number, data: Uint8Array, x: number, y: number, w: number, h: number, opacity?: number): boolean;
1616
+ /**
1617
+ * Stamp an **image watermark** across pages from raw image bytes. Accepts the
1618
+ * same five formats the engine decodes — **PNG, JPEG, WebP, GIF, AVIF**. The
1619
+ * image is embedded **once** and referenced on every target page.
1620
+ *
1621
+ * `opts.pages` is a list of 1-based page numbers; omit it (or pass `[]`) to
1622
+ * stamp every page. `opts.anchor` positions the image (`'center'` default, or a
1623
+ * corner) and `opts.offsetX`/`offsetY` nudge it (in points; in `tile` mode they
1624
+ * become the gaps between tiles). `opts.width`/`height` set the target size in
1625
+ * points (height keeps the source aspect ratio when omitted). `opts.rotationDeg`
1626
+ * rotates about the image centre and `opts.opacity` (0–1) sets the alpha.
1627
+ * Returns `false` if the image can't be decoded.
1628
+ */
1629
+ addImageWatermark(data: Uint8Array, opts?: {
1630
+ pages?: number[];
1631
+ anchor?: 'center' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
1632
+ offsetX?: number;
1633
+ offsetY?: number;
1634
+ width?: number;
1635
+ height?: number;
1636
+ rotationDeg?: number;
1637
+ opacity?: number;
1638
+ tile?: boolean;
1639
+ }): boolean;
1570
1640
  /**
1571
1641
  * Draw SVG markup on a page as **native vector paths** (crisp at any zoom, not
1572
1642
  * rasterized), fitting its `viewBox` into the box `(x, y, w, h)` in PDF points
@@ -1808,6 +1878,21 @@ declare class GigaPdfDoc {
1808
1878
  * missing certificate.
1809
1879
  */
1810
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>;
1811
1896
  getMetadata(key: string): string;
1812
1897
  /** Set an Info-dictionary entry (e.g. "Title", "Author"). */
1813
1898
  setMetadata(key: string, value: string): boolean;
@@ -1955,4 +2040,4 @@ declare class GigaPdfDoc {
1955
2040
  }): boolean;
1956
2041
  }
1957
2042
 
1958
- 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;
@@ -1214,6 +1226,49 @@ var GigaPdfDoc = class {
1214
1226
  (p, l) => this.ex().gp_add_image(this.h, page, p, l, x, y, w, h, opacity)
1215
1227
  ) === 0;
1216
1228
  }
1229
+ /**
1230
+ * Stamp an **image watermark** across pages from raw image bytes. Accepts the
1231
+ * same five formats the engine decodes — **PNG, JPEG, WebP, GIF, AVIF**. The
1232
+ * image is embedded **once** and referenced on every target page.
1233
+ *
1234
+ * `opts.pages` is a list of 1-based page numbers; omit it (or pass `[]`) to
1235
+ * stamp every page. `opts.anchor` positions the image (`'center'` default, or a
1236
+ * corner) and `opts.offsetX`/`offsetY` nudge it (in points; in `tile` mode they
1237
+ * become the gaps between tiles). `opts.width`/`height` set the target size in
1238
+ * points (height keeps the source aspect ratio when omitted). `opts.rotationDeg`
1239
+ * rotates about the image centre and `opts.opacity` (0–1) sets the alpha.
1240
+ * Returns `false` if the image can't be decoded.
1241
+ */
1242
+ addImageWatermark(data, opts = {}) {
1243
+ const anchorTag = {
1244
+ center: 0,
1245
+ "top-left": 1,
1246
+ "top-right": 2,
1247
+ "bottom-left": 3,
1248
+ "bottom-right": 4
1249
+ }[opts.anchor ?? "center"];
1250
+ const pages = opts.pages ?? [];
1251
+ const call = (pp, pc) => this.g._withBytes(
1252
+ data,
1253
+ (p, l) => this.ex().gp_add_image_watermark(
1254
+ this.h,
1255
+ p,
1256
+ l,
1257
+ pp,
1258
+ pc,
1259
+ anchorTag,
1260
+ opts.offsetX ?? 0,
1261
+ opts.offsetY ?? 0,
1262
+ opts.width ?? 0,
1263
+ opts.height ?? 0,
1264
+ opts.rotationDeg ?? 0,
1265
+ opts.opacity ?? 0.25,
1266
+ opts.tile ? 1 : 0
1267
+ )
1268
+ );
1269
+ const rc = pages.length === 0 ? call(0, 0) : this.g._withU32(pages, (pp, pc) => call(pp, pc));
1270
+ return rc === 0;
1271
+ }
1217
1272
  /**
1218
1273
  * Draw SVG markup on a page as **native vector paths** (crisp at any zoom, not
1219
1274
  * rasterized), fitting its `viewBox` into the box `(x, y, w, h)` in PDF points
@@ -1680,6 +1735,95 @@ var GigaPdfDoc = class {
1680
1735
  }
1681
1736
  return out;
1682
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
+ }
1683
1827
  // metadata
1684
1828
  getMetadata(key) {
1685
1829
  return this.g._withStr(
@@ -2078,6 +2222,7 @@ var GigaPdfDoc = class {
2078
2222
  };
2079
2223
  export {
2080
2224
  GigaPdfDoc,
2081
- GigaPdfEngine
2225
+ GigaPdfEngine,
2226
+ defaultTsaPost
2082
2227
  };
2083
2228
  //# sourceMappingURL=index.js.map