@qrcommunication/gigapdf-lib 0.70.0 → 0.71.1

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
@@ -1224,6 +1224,51 @@ interface SignTsaOptions extends SignP12Options {
1224
1224
  /** Optional 8–16 random bytes echoed by the TSA (request/response correlation). */
1225
1225
  nonce?: Uint8Array;
1226
1226
  }
1227
+ /**
1228
+ * Options for {@link GigaPdfDoc.signLtv} — a PAdES long-term validation
1229
+ * signature: a B-T signature, then a `/DSS` (Document Security Store) carrying
1230
+ * the certificate chain + OCSP/CRL revocation material the host fetched (B-LT),
1231
+ * optionally finished with a document timestamp over the whole file (B-LTA).
1232
+ *
1233
+ * Extends {@link SignTsaOptions}: the B-T signature is produced exactly as
1234
+ * {@link GigaPdfDoc.signTimestamped}, then the LTV material is added. The OCSP/CRL
1235
+ * URLs come from the **certificates**, so the host fetches them — supply
1236
+ * `revocationFetch`/`crlFetch` to add auth, proxies, or an SSRF allow-list (the
1237
+ * engine only computes which URLs to fetch).
1238
+ */
1239
+ interface SignLtvOptions extends SignTsaOptions {
1240
+ /**
1241
+ * Add a B-LTA **document timestamp** over the whole file (DSS included) after
1242
+ * the DSS. Requires a second TSA round trip. Default `false` (B-LT only).
1243
+ */
1244
+ archiveTimestamp?: boolean;
1245
+ /**
1246
+ * Override the OCSP round trip — receives the DER `OCSPRequest` and the
1247
+ * responder URL, must resolve to the raw `OCSPResponse` bytes. When omitted,
1248
+ * {@link defaultOcspPost} POSTs `application/ocsp-request` via `fetch`. Throw to
1249
+ * skip an unreachable responder (the DSS is built from whatever succeeds).
1250
+ */
1251
+ revocationFetch?: (req: Uint8Array, url: string) => Promise<Uint8Array>;
1252
+ /**
1253
+ * Override the CRL fetch — receives the CRL distribution-point URL, must
1254
+ * resolve to the raw `CertificateList` (CRL) bytes. When omitted,
1255
+ * {@link defaultCrlGet} GETs the URL. Throw to skip an unreachable CRL.
1256
+ */
1257
+ crlFetch?: (url: string) => Promise<Uint8Array>;
1258
+ }
1259
+ /**
1260
+ * Default OCSP round trip for {@link GigaPdfDoc.signLtv}: POST the DER
1261
+ * `OCSPRequest` to `url` as `application/ocsp-request` and return the raw
1262
+ * `OCSPResponse` body. No SSRF allow-listing — the URL comes from the
1263
+ * certificate's AIA extension; pass `revocationFetch` to restrict it.
1264
+ */
1265
+ declare function defaultOcspPost(req: Uint8Array, url: string): Promise<Uint8Array>;
1266
+ /**
1267
+ * Default CRL fetch for {@link GigaPdfDoc.signLtv}: GET the `CertificateList`
1268
+ * (CRL) from `url`. No SSRF allow-listing — the URL comes from the certificate's
1269
+ * CRL-DP extension; pass `crlFetch` to restrict it.
1270
+ */
1271
+ declare function defaultCrlGet(url: string): Promise<Uint8Array>;
1227
1272
  /**
1228
1273
  * A markup annotation (rect corners in PDF user space, origin bottom-left).
1229
1274
  * Carries the common metadata plus the type-specific geometry a host editor
@@ -1893,6 +1938,31 @@ declare class GigaPdfDoc {
1893
1938
  * (bad identity, TSA HTTP error, malformed response, or signature too large).
1894
1939
  */
1895
1940
  signTimestamped(opts: SignTsaOptions): Promise<Uint8Array>;
1941
+ /**
1942
+ * Sign with **long-term validation** material embedded (PAdES-B-LT, or B-LTA
1943
+ * with `opts.archiveTimestamp`). Builds a B-T signature ({@link signTimestamped}),
1944
+ * then fetches the certificate chain's revocation material (OCSP responses /
1945
+ * CRLs, by URL **from the certificates** — the engine computes which URLs, the
1946
+ * host fetches) and stores it in a `/DSS`, so the signature validates long after
1947
+ * the certificates expire or are revoked. With `archiveTimestamp` a document
1948
+ * timestamp over the whole file (DSS included) is added for renewable archival.
1949
+ *
1950
+ * `async`, multi-round-trip: one TSA POST for the B-T timestamp, one OCSP/CRL
1951
+ * fetch per chain certificate, and (if `archiveTimestamp`) a second TSA POST.
1952
+ * Unreachable responders are skipped — the DSS is built from whatever resolves;
1953
+ * a self-signed identity (no AIA/CRL-DP) simply yields a `/DSS/Certs`-only store.
1954
+ * Override `tsaFetch`/`revocationFetch`/`crlFetch` to add auth, proxies, or an
1955
+ * SSRF allow-list. Throws on a fatal failure (bad identity, B-T signature, or a
1956
+ * malformed PDF the DSS can't chain to).
1957
+ */
1958
+ signLtv(opts: SignLtvOptions): Promise<Uint8Array>;
1959
+ /** Run `fn` with `pdf` copied into wasm memory, freeing it afterwards. */
1960
+ private withSignedPdf;
1961
+ /** Add the `/DSS` to `signed` as an incremental update (B-LT). */
1962
+ private applyDss;
1963
+ /** Append a document timestamp over the whole `pdf` (B-LTA), TSA round trip
1964
+ * included. */
1965
+ private appendDocumentTimestamp;
1896
1966
  getMetadata(key: string): string;
1897
1967
  /** Set an Info-dictionary entry (e.g. "Title", "Author"). */
1898
1968
  setMetadata(key: string, value: string): boolean;
@@ -2040,4 +2110,4 @@ declare class GigaPdfDoc {
2040
2110
  }): boolean;
2041
2111
  }
2042
2112
 
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 };
2113
+ 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 SignLtvOptions, type SignP12Options, type SignTsaOptions, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet, defaultCrlGet, defaultOcspPost, defaultTsaPost };
package/dist/index.d.ts CHANGED
@@ -1224,6 +1224,51 @@ interface SignTsaOptions extends SignP12Options {
1224
1224
  /** Optional 8–16 random bytes echoed by the TSA (request/response correlation). */
1225
1225
  nonce?: Uint8Array;
1226
1226
  }
1227
+ /**
1228
+ * Options for {@link GigaPdfDoc.signLtv} — a PAdES long-term validation
1229
+ * signature: a B-T signature, then a `/DSS` (Document Security Store) carrying
1230
+ * the certificate chain + OCSP/CRL revocation material the host fetched (B-LT),
1231
+ * optionally finished with a document timestamp over the whole file (B-LTA).
1232
+ *
1233
+ * Extends {@link SignTsaOptions}: the B-T signature is produced exactly as
1234
+ * {@link GigaPdfDoc.signTimestamped}, then the LTV material is added. The OCSP/CRL
1235
+ * URLs come from the **certificates**, so the host fetches them — supply
1236
+ * `revocationFetch`/`crlFetch` to add auth, proxies, or an SSRF allow-list (the
1237
+ * engine only computes which URLs to fetch).
1238
+ */
1239
+ interface SignLtvOptions extends SignTsaOptions {
1240
+ /**
1241
+ * Add a B-LTA **document timestamp** over the whole file (DSS included) after
1242
+ * the DSS. Requires a second TSA round trip. Default `false` (B-LT only).
1243
+ */
1244
+ archiveTimestamp?: boolean;
1245
+ /**
1246
+ * Override the OCSP round trip — receives the DER `OCSPRequest` and the
1247
+ * responder URL, must resolve to the raw `OCSPResponse` bytes. When omitted,
1248
+ * {@link defaultOcspPost} POSTs `application/ocsp-request` via `fetch`. Throw to
1249
+ * skip an unreachable responder (the DSS is built from whatever succeeds).
1250
+ */
1251
+ revocationFetch?: (req: Uint8Array, url: string) => Promise<Uint8Array>;
1252
+ /**
1253
+ * Override the CRL fetch — receives the CRL distribution-point URL, must
1254
+ * resolve to the raw `CertificateList` (CRL) bytes. When omitted,
1255
+ * {@link defaultCrlGet} GETs the URL. Throw to skip an unreachable CRL.
1256
+ */
1257
+ crlFetch?: (url: string) => Promise<Uint8Array>;
1258
+ }
1259
+ /**
1260
+ * Default OCSP round trip for {@link GigaPdfDoc.signLtv}: POST the DER
1261
+ * `OCSPRequest` to `url` as `application/ocsp-request` and return the raw
1262
+ * `OCSPResponse` body. No SSRF allow-listing — the URL comes from the
1263
+ * certificate's AIA extension; pass `revocationFetch` to restrict it.
1264
+ */
1265
+ declare function defaultOcspPost(req: Uint8Array, url: string): Promise<Uint8Array>;
1266
+ /**
1267
+ * Default CRL fetch for {@link GigaPdfDoc.signLtv}: GET the `CertificateList`
1268
+ * (CRL) from `url`. No SSRF allow-listing — the URL comes from the certificate's
1269
+ * CRL-DP extension; pass `crlFetch` to restrict it.
1270
+ */
1271
+ declare function defaultCrlGet(url: string): Promise<Uint8Array>;
1227
1272
  /**
1228
1273
  * A markup annotation (rect corners in PDF user space, origin bottom-left).
1229
1274
  * Carries the common metadata plus the type-specific geometry a host editor
@@ -1893,6 +1938,31 @@ declare class GigaPdfDoc {
1893
1938
  * (bad identity, TSA HTTP error, malformed response, or signature too large).
1894
1939
  */
1895
1940
  signTimestamped(opts: SignTsaOptions): Promise<Uint8Array>;
1941
+ /**
1942
+ * Sign with **long-term validation** material embedded (PAdES-B-LT, or B-LTA
1943
+ * with `opts.archiveTimestamp`). Builds a B-T signature ({@link signTimestamped}),
1944
+ * then fetches the certificate chain's revocation material (OCSP responses /
1945
+ * CRLs, by URL **from the certificates** — the engine computes which URLs, the
1946
+ * host fetches) and stores it in a `/DSS`, so the signature validates long after
1947
+ * the certificates expire or are revoked. With `archiveTimestamp` a document
1948
+ * timestamp over the whole file (DSS included) is added for renewable archival.
1949
+ *
1950
+ * `async`, multi-round-trip: one TSA POST for the B-T timestamp, one OCSP/CRL
1951
+ * fetch per chain certificate, and (if `archiveTimestamp`) a second TSA POST.
1952
+ * Unreachable responders are skipped — the DSS is built from whatever resolves;
1953
+ * a self-signed identity (no AIA/CRL-DP) simply yields a `/DSS/Certs`-only store.
1954
+ * Override `tsaFetch`/`revocationFetch`/`crlFetch` to add auth, proxies, or an
1955
+ * SSRF allow-list. Throws on a fatal failure (bad identity, B-T signature, or a
1956
+ * malformed PDF the DSS can't chain to).
1957
+ */
1958
+ signLtv(opts: SignLtvOptions): Promise<Uint8Array>;
1959
+ /** Run `fn` with `pdf` copied into wasm memory, freeing it afterwards. */
1960
+ private withSignedPdf;
1961
+ /** Add the `/DSS` to `signed` as an incremental update (B-LT). */
1962
+ private applyDss;
1963
+ /** Append a document timestamp over the whole `pdf` (B-LTA), TSA round trip
1964
+ * included. */
1965
+ private appendDocumentTimestamp;
1896
1966
  getMetadata(key: string): string;
1897
1967
  /** Set an Info-dictionary entry (e.g. "Title", "Author"). */
1898
1968
  setMetadata(key: string, value: string): boolean;
@@ -2040,4 +2110,4 @@ declare class GigaPdfDoc {
2040
2110
  }): boolean;
2041
2111
  }
2042
2112
 
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 };
2113
+ 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 SignLtvOptions, type SignP12Options, type SignTsaOptions, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet, defaultCrlGet, defaultOcspPost, defaultTsaPost };
package/dist/index.js CHANGED
@@ -886,6 +886,47 @@ function packHtmlFonts(fonts) {
886
886
  }
887
887
  return buf;
888
888
  }
889
+ async function defaultOcspPost(req, url) {
890
+ const res = await fetch(url, {
891
+ method: "POST",
892
+ headers: { "Content-Type": "application/ocsp-request" },
893
+ body: req,
894
+ redirect: "error"
895
+ });
896
+ if (!res.ok) {
897
+ throw new Error(`OCSP HTTP ${res.status}`);
898
+ }
899
+ return new Uint8Array(await res.arrayBuffer());
900
+ }
901
+ async function defaultCrlGet(url) {
902
+ const res = await fetch(url, { method: "GET", redirect: "error" });
903
+ if (!res.ok) {
904
+ throw new Error(`CRL HTTP ${res.status}`);
905
+ }
906
+ return new Uint8Array(await res.arrayBuffer());
907
+ }
908
+ function hexToBytes(hex) {
909
+ const out = new Uint8Array(hex.length >> 1);
910
+ for (let i = 0; i < out.length; i++) {
911
+ out[i] = parseInt(hex.substr(i * 2, 2), 16);
912
+ }
913
+ return out;
914
+ }
915
+ function frameBlobs(blobs) {
916
+ let total = 4;
917
+ for (const b of blobs) total += 4 + b.length;
918
+ const out = new Uint8Array(total);
919
+ const view = new DataView(out.buffer);
920
+ view.setUint32(0, blobs.length, true);
921
+ let pos = 4;
922
+ for (const b of blobs) {
923
+ view.setUint32(pos, b.length, true);
924
+ pos += 4;
925
+ out.set(b, pos);
926
+ pos += b.length;
927
+ }
928
+ return out;
929
+ }
889
930
  var RGB = (rgb) => rgb & 16777215;
890
931
  function styleArgs(s = {}) {
891
932
  const hasBorder = s.border === null ? 0 : 1;
@@ -1824,6 +1865,142 @@ var GigaPdfDoc = class {
1824
1865
  }
1825
1866
  return out;
1826
1867
  }
1868
+ /**
1869
+ * Sign with **long-term validation** material embedded (PAdES-B-LT, or B-LTA
1870
+ * with `opts.archiveTimestamp`). Builds a B-T signature ({@link signTimestamped}),
1871
+ * then fetches the certificate chain's revocation material (OCSP responses /
1872
+ * CRLs, by URL **from the certificates** — the engine computes which URLs, the
1873
+ * host fetches) and stores it in a `/DSS`, so the signature validates long after
1874
+ * the certificates expire or are revoked. With `archiveTimestamp` a document
1875
+ * timestamp over the whole file (DSS included) is added for renewable archival.
1876
+ *
1877
+ * `async`, multi-round-trip: one TSA POST for the B-T timestamp, one OCSP/CRL
1878
+ * fetch per chain certificate, and (if `archiveTimestamp`) a second TSA POST.
1879
+ * Unreachable responders are skipped — the DSS is built from whatever resolves;
1880
+ * a self-signed identity (no AIA/CRL-DP) simply yields a `/DSS/Certs`-only store.
1881
+ * Override `tsaFetch`/`revocationFetch`/`crlFetch` to add auth, proxies, or an
1882
+ * SSRF allow-list. Throws on a fatal failure (bad identity, B-T signature, or a
1883
+ * malformed PDF the DSS can't chain to).
1884
+ */
1885
+ async signLtv(opts) {
1886
+ const signed = await this.signTimestamped(opts);
1887
+ const nonce = opts.nonce ?? new Uint8Array(0);
1888
+ const targetsJson = this.withSignedPdf(signed, (pdfPtr, pdfLen) => {
1889
+ const noncePtr = this.g._toWasm(nonce);
1890
+ try {
1891
+ return dec.decode(
1892
+ this.g._buffer(
1893
+ (o) => this.ex().gp_ltv_targets(pdfPtr, pdfLen, noncePtr, nonce.length, o)
1894
+ )
1895
+ );
1896
+ } finally {
1897
+ this.g._free(noncePtr, nonce.length);
1898
+ }
1899
+ });
1900
+ const targets = targetsJson ? JSON.parse(targetsJson) : [];
1901
+ const certs = [];
1902
+ const ocsps = [];
1903
+ const crls = [];
1904
+ const ocspPost = opts.revocationFetch ?? defaultOcspPost;
1905
+ const crlGet = opts.crlFetch ?? defaultCrlGet;
1906
+ for (const target of targets) {
1907
+ certs.push(hexToBytes(target.certHex));
1908
+ for (const source of target.sources) {
1909
+ try {
1910
+ if (source.kind === "ocsp") {
1911
+ ocsps.push(await ocspPost(hexToBytes(source.requestHex), source.url));
1912
+ } else {
1913
+ crls.push(await crlGet(source.url));
1914
+ }
1915
+ } catch {
1916
+ }
1917
+ }
1918
+ }
1919
+ let lt = this.applyDss(signed, certs, ocsps, crls);
1920
+ if (opts.archiveTimestamp) {
1921
+ lt = await this.appendDocumentTimestamp(lt, opts);
1922
+ }
1923
+ return lt;
1924
+ }
1925
+ /** Run `fn` with `pdf` copied into wasm memory, freeing it afterwards. */
1926
+ withSignedPdf(pdf, fn) {
1927
+ const ptr = this.g._toWasm(pdf);
1928
+ try {
1929
+ return fn(ptr, pdf.length);
1930
+ } finally {
1931
+ this.g._free(ptr, pdf.length);
1932
+ }
1933
+ }
1934
+ /** Add the `/DSS` to `signed` as an incremental update (B-LT). */
1935
+ applyDss(signed, certs, ocsps, crls) {
1936
+ const certsBuf = frameBlobs(certs);
1937
+ const ocspsBuf = frameBlobs(ocsps);
1938
+ const crlsBuf = frameBlobs(crls);
1939
+ const pdfPtr = this.g._toWasm(signed);
1940
+ const cPtr = this.g._toWasm(certsBuf);
1941
+ const oPtr = this.g._toWasm(ocspsBuf);
1942
+ const rPtr = this.g._toWasm(crlsBuf);
1943
+ let out;
1944
+ try {
1945
+ out = this.g._buffer(
1946
+ (res) => this.ex().gp_apply_dss(
1947
+ pdfPtr,
1948
+ signed.length,
1949
+ cPtr,
1950
+ certsBuf.length,
1951
+ oPtr,
1952
+ ocspsBuf.length,
1953
+ rPtr,
1954
+ crlsBuf.length,
1955
+ res
1956
+ )
1957
+ );
1958
+ } finally {
1959
+ this.g._free(pdfPtr, signed.length);
1960
+ this.g._free(cPtr, certsBuf.length);
1961
+ this.g._free(oPtr, ocspsBuf.length);
1962
+ this.g._free(rPtr, crlsBuf.length);
1963
+ }
1964
+ if (out.length === 0) {
1965
+ throw new Error("LTV failed: could not add the /DSS to the signed PDF");
1966
+ }
1967
+ return out;
1968
+ }
1969
+ /** Append a document timestamp over the whole `pdf` (B-LTA), TSA round trip
1970
+ * included. */
1971
+ async appendDocumentTimestamp(pdf, opts) {
1972
+ const nonce = opts.nonce ?? new Uint8Array(0);
1973
+ const pdfPtr = this.g._toWasm(pdf);
1974
+ const noncePtr = this.g._toWasm(nonce);
1975
+ let request;
1976
+ try {
1977
+ request = this.g._buffer(
1978
+ (o) => this.ex().gp_doc_timestamp_prepare(this.h, pdfPtr, pdf.length, noncePtr, nonce.length, o)
1979
+ );
1980
+ } finally {
1981
+ this.g._free(pdfPtr, pdf.length);
1982
+ this.g._free(noncePtr, nonce.length);
1983
+ }
1984
+ if (request.length === 0) {
1985
+ throw new Error("LTV archive timestamp failed: could not build the timestamp request");
1986
+ }
1987
+ const response = opts.tsaFetch ? await opts.tsaFetch(request, opts.tsaUrl) : await defaultTsaPost(opts.tsaUrl, request);
1988
+ const tokenPtr = this.g._toWasm(response);
1989
+ let out;
1990
+ try {
1991
+ out = this.g._buffer(
1992
+ (o) => this.ex().gp_doc_timestamp_finish(this.h, tokenPtr, response.length, o)
1993
+ );
1994
+ } finally {
1995
+ this.g._free(tokenPtr, response.length);
1996
+ }
1997
+ if (out.length === 0) {
1998
+ throw new Error(
1999
+ "LTV archive timestamp failed: TSA response rejected or token too large for the reserved space"
2000
+ );
2001
+ }
2002
+ return out;
2003
+ }
1827
2004
  // metadata
1828
2005
  getMetadata(key) {
1829
2006
  return this.g._withStr(
@@ -2223,6 +2400,8 @@ var GigaPdfDoc = class {
2223
2400
  export {
2224
2401
  GigaPdfDoc,
2225
2402
  GigaPdfEngine,
2403
+ defaultCrlGet,
2404
+ defaultOcspPost,
2226
2405
  defaultTsaPost
2227
2406
  };
2228
2407
  //# sourceMappingURL=index.js.map