@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/CHANGELOG.md CHANGED
@@ -4,6 +4,53 @@ All notable changes to `@qrcommunication/gigapdf-lib` are documented here.
4
4
  The format follows [Keep a Changelog](https://keepachangelog.com/) and the
5
5
  project adheres to [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [0.70.0] - 2026-06-23
8
+
9
+ Fidelity + standards release: advanced (PAdES-B-T) timestamped signatures,
10
+ richer shading and JPEG decoding at the rasteriser, complex-script text shaping
11
+ for Indic writing systems, CFF flex curves, and RTF image import. The public API
12
+ is additive — existing behaviour is unchanged.
13
+
14
+ ### Added
15
+
16
+ - **PAdES-B-T trusted timestamps (RFC 3161).** New SDK
17
+ `GigaPdfDoc.signTimestamped()` (async) embeds an RFC 3161 timestamp token in
18
+ the SignerInfo for an *advanced*-level PAdES-B-T signature — `ETSI.CAdES.detached`
19
+ subfilter, `signing-certificate-v2` (ESS) signed attribute, and the
20
+ `id-aa-timeStampToken` unsigned attribute. Uses the engine's pure-data
21
+ two-phase TSA flow (core emits the `TimeStampReq`, host POSTs it, core embeds
22
+ the returned token) since the WASM core has no network stack; `tsaFetch` lets
23
+ the host add auth/proxy/retries **and apply its own SSRF allow-list**, and the
24
+ exported `defaultTsaPost` POSTs `application/timestamp-query` via `fetch`
25
+ (e.g. FreeTSA). Signs with an imported PKCS#12 or a freshly generated
26
+ self-signed identity.
27
+ - **Mesh shadings at the rasteriser.** Free-form (type 4), lattice (type 5),
28
+ Coons (type 6) and tensor (type 7) shadings are now rendered as Gouraud
29
+ triangles (pure, zero-dep decoder; Coons/tensor patches tessellated per
30
+ ISO 32000-1 §8.7.4.5.7), with per-vertex colour resolved through
31
+ `Separation`/`DeviceN`/`ICCBased`/`CMYK`/`Gray`. Axial (2) and radial (3)
32
+ shadings are unchanged.
33
+ - **Arithmetic-coded JPEG decoding.** SOF9 (sequential) and SOF10 (progressive)
34
+ JPEGs now decode via a hand-rolled ISO/IEC 10918-1 Annex MQ arithmetic decoder
35
+ with the F.1.4 DC/AC context models and `DAC` conditioning. Baseline/Huffman
36
+ paths are unchanged; lossless (SOF3/SOF11) and 12-bit Huffman (SOF1) remain
37
+ gracefully unsupported.
38
+ - **Indic complex-script shaping.** A syllabic reordering machine for the
39
+ Brahmi-derived scripts (Devanagari, Bengali, Gurmukhi, Gujarati, Oriya, Tamil,
40
+ Telugu, Kannada, Malayalam) — reph and pre-base matra reordering — plus the
41
+ missing OpenType lookups: GSUB 2 (multiple), GSUB 3 (alternate), GSUB 8
42
+ (reverse chaining single) and GPOS 3 (cursive attachment). Latin and the
43
+ existing contextual paths are unchanged.
44
+ - **CFF/Type2 flex operators.** The Type2 charstring interpreter now implements
45
+ the four flex operators (`flex`, `flex1`, `hflex`, `hflex1`, Adobe TN #5177),
46
+ each emitting two cubic curves — CFF glyphs using flex no longer drop or
47
+ mis-render contour segments.
48
+ - **RTF image import.** RTF import parses the `\pict` group, extracting
49
+ `\pngblip`/`\jpegblip` payloads as `<img src="data:image/…;base64,…">`
50
+ (display size recovered from `\picwgoal`/`\pichgoal`), reusing the HTML
51
+ engine's image-embed pipeline. DIB/BMP, WMF/EMF and binary `\bin` payloads are
52
+ skipped (documented limits), guarded by a PNG/JPEG magic-byte check.
53
+
7
54
  ## [0.69.0] - 2026-06-23
8
55
 
9
56
  Image-watermark release: stamp a raster image across any range of pages, with
package/dist/index.cjs CHANGED
@@ -21,7 +21,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  GigaPdfDoc: () => GigaPdfDoc,
24
- GigaPdfEngine: () => GigaPdfEngine
24
+ GigaPdfEngine: () => GigaPdfEngine,
25
+ defaultTsaPost: () => defaultTsaPost
25
26
  });
26
27
  module.exports = __toCommonJS(index_exports);
27
28
  var import_node_fs = require("./node-fs.js");
@@ -853,6 +854,18 @@ var GigaPdfEngine = class _GigaPdfEngine {
853
854
  );
854
855
  }
855
856
  };
857
+ async function defaultTsaPost(url, req) {
858
+ const res = await fetch(url, {
859
+ method: "POST",
860
+ headers: { "Content-Type": "application/timestamp-query" },
861
+ body: req,
862
+ redirect: "error"
863
+ });
864
+ if (!res.ok) {
865
+ throw new Error(`TSA HTTP ${res.status}`);
866
+ }
867
+ return new Uint8Array(await res.arrayBuffer());
868
+ }
856
869
  function packHtmlResources(resources) {
857
870
  let size = 4;
858
871
  for (const r of resources) size += 4 + enc.encode(r.url).length + 4 + r.bytes.length;
@@ -1748,6 +1761,95 @@ var GigaPdfDoc = class {
1748
1761
  }
1749
1762
  return out;
1750
1763
  }
1764
+ /**
1765
+ * Sign with an embedded **RFC 3161 trusted timestamp** (PAdES-B-T). Unlike
1766
+ * {@link sign}/{@link signP12} this is `async`: the timestamp requires a
1767
+ * network round trip to a TSA, so the method runs the engine's two-phase flow
1768
+ * — build the signature → POST the `TimeStampReq` to the TSA → embed the
1769
+ * returned token — with the HTTP in between.
1770
+ *
1771
+ * The signing identity is `opts.p12` (+ `opts.password`) when supplied, else a
1772
+ * generated self-signed digital ID from `opts.random` (+ `notBefore`/
1773
+ * `notAfter`). `opts.tsaUrl` is the TSA endpoint (e.g. FreeTSA
1774
+ * `https://freetsa.org/tsr`); pass `opts.tsaFetch` to customise the request
1775
+ * (auth, proxy, SSRF allow-list). Throws a single generic error on any failure
1776
+ * (bad identity, TSA HTTP error, malformed response, or signature too large).
1777
+ */
1778
+ async signTimestamped(opts) {
1779
+ const usingP12 = opts.p12 != null && opts.p12.length > 0;
1780
+ if (!usingP12 && (opts.random == null || opts.random.length < 256)) {
1781
+ throw new Error(
1782
+ "signTimestamped: self-signed path needs `random` \u2265 256 bytes (or pass a `p12`)"
1783
+ );
1784
+ }
1785
+ const fields = [
1786
+ opts.name ?? "",
1787
+ opts.reason ?? "",
1788
+ opts.date ?? "",
1789
+ opts.location ?? "",
1790
+ opts.contactInfo ?? "",
1791
+ opts.notBefore ?? "",
1792
+ opts.notAfter ?? ""
1793
+ ].join(" ");
1794
+ const rand = opts.random ?? new Uint8Array(0);
1795
+ const p12 = opts.p12 ?? new Uint8Array(0);
1796
+ const nonce = opts.nonce ?? new Uint8Array(0);
1797
+ const keyBits = opts.keyBits ?? 2048;
1798
+ const rPtr = this.g._toWasm(rand);
1799
+ const p12Ptr = this.g._toWasm(p12);
1800
+ const noncePtr = this.g._toWasm(nonce);
1801
+ let request;
1802
+ try {
1803
+ request = this.g._withStr(
1804
+ opts.password ?? "",
1805
+ (pwP, pwL) => this.g._withStr(
1806
+ fields,
1807
+ (fP, fL) => this.g._buffer(
1808
+ (o) => this.ex().gp_sign_prepare_tsa(
1809
+ this.h,
1810
+ fP,
1811
+ fL,
1812
+ rPtr,
1813
+ rand.length,
1814
+ keyBits,
1815
+ p12Ptr,
1816
+ p12.length,
1817
+ pwP,
1818
+ pwL,
1819
+ noncePtr,
1820
+ nonce.length,
1821
+ o
1822
+ )
1823
+ )
1824
+ )
1825
+ );
1826
+ } finally {
1827
+ this.g._free(rPtr, rand.length);
1828
+ this.g._free(p12Ptr, p12.length);
1829
+ this.g._free(noncePtr, nonce.length);
1830
+ }
1831
+ if (request.length === 0) {
1832
+ throw new Error(
1833
+ "timestamped signing failed: invalid identity or could not build the timestamp request"
1834
+ );
1835
+ }
1836
+ const response = opts.tsaFetch ? await opts.tsaFetch(request, opts.tsaUrl) : await defaultTsaPost(opts.tsaUrl, request);
1837
+ const tokenPtr = this.g._toWasm(response);
1838
+ let out;
1839
+ try {
1840
+ out = this.g._buffer(
1841
+ (o) => this.ex().gp_sign_finish_tsa(this.h, tokenPtr, response.length, o)
1842
+ );
1843
+ } finally {
1844
+ this.g._free(tokenPtr, response.length);
1845
+ }
1846
+ if (out.length === 0) {
1847
+ throw new Error(
1848
+ "timestamped signing failed: TSA response rejected or signature too large for the reserved space"
1849
+ );
1850
+ }
1851
+ return out;
1852
+ }
1751
1853
  // metadata
1752
1854
  getMetadata(key) {
1753
1855
  return this.g._withStr(
@@ -2147,6 +2249,7 @@ var GigaPdfDoc = class {
2147
2249
  // Annotate the CommonJS export names for ESM import in node:
2148
2250
  0 && (module.exports = {
2149
2251
  GigaPdfDoc,
2150
- GigaPdfEngine
2252
+ GigaPdfEngine,
2253
+ defaultTsaPost
2151
2254
  });
2152
2255
  //# sourceMappingURL=index.cjs.map