@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/CHANGELOG.md +49 -0
- package/README.md +57 -17
- package/dist/index.cjs +181 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +71 -1
- package/dist/index.d.ts +71 -1
- package/dist/index.js +179 -0
- package/dist/index.js.map +1 -1
- package/gigapdf.wasm +0 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,55 @@ 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.71.1] - 2026-06-23
|
|
8
|
+
|
|
9
|
+
Documentation-only patch. No code changes — the WASM blob is byte-for-byte
|
|
10
|
+
identical to 0.71.0.
|
|
11
|
+
|
|
12
|
+
### Documentation
|
|
13
|
+
|
|
14
|
+
- Complete overhaul of the SDK documentation for 0.71: API reference (signature
|
|
15
|
+
matrix for B / B-T / LTV signing, full ~263-method surface, removal of the
|
|
16
|
+
phantom OCR methods `doc.ocr` / `ocrText` / `extractText`), USAGE guide (the
|
|
17
|
+
four signing-signature levels + the host-fetch two-phase model + an SSRF note),
|
|
18
|
+
COOKBOOK (added `signTimestamped` / `signLtv` recipes and an image-watermark
|
|
19
|
+
recipe), plus the README and `sdk/README` (npm). No behavioural change — the
|
|
20
|
+
WASM is identical to 0.71.0.
|
|
21
|
+
|
|
22
|
+
## [0.71.0] - 2026-06-23
|
|
23
|
+
|
|
24
|
+
Long-term validation release: PAdES-LTV builds on the B-T timestamped signatures
|
|
25
|
+
from 0.70 by embedding the validation material (certificate chain + revocation
|
|
26
|
+
responses) so a signature keeps verifying long after its certificates expire or
|
|
27
|
+
are revoked. The public API is additive — existing behaviour is unchanged.
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
|
|
31
|
+
- **PAdES-LTV (B-LT / B-LTA).** New SDK `GigaPdfDoc.signLtv()` (async) produces a
|
|
32
|
+
long-term-validation signature: it first builds a B-T signature
|
|
33
|
+
(`signTimestamped`), then embeds a Document Security Store (`/DSS` with
|
|
34
|
+
`/Certs`, `/OCSPs`, `/CRLs`, and per-signature `/VRI`) carrying the revocation
|
|
35
|
+
material for the certificate chain (B-LT). With `archiveTimestamp` it also adds
|
|
36
|
+
a `/DocTimeStamp` document timestamp (`ETSI.RFC3161` subfilter) over the whole
|
|
37
|
+
updated file for B-LTA, refreshing the long-term trust anchor. The engine
|
|
38
|
+
computes *which* OCSP/CRL endpoints to query from the certificates' AIA / CRL-DP
|
|
39
|
+
extensions; the host fetches them (the WASM core has no network stack, same
|
|
40
|
+
pure-data two-phase model as the TSA). OCSP requests follow RFC 6960; CRLs are
|
|
41
|
+
parsed as `CertificateList`. The exported `defaultOcspPost` and `defaultCrlGet`
|
|
42
|
+
perform the round trips via `fetch`, and the `revocationFetch` / `crlFetch`
|
|
43
|
+
hooks let the host add auth/proxy/retries **and apply its own SSRF allow-list**.
|
|
44
|
+
|
|
45
|
+
### Fixed
|
|
46
|
+
|
|
47
|
+
- **B-T `id-aa-timeStampToken` now carries the bare `TimeStampToken`.**
|
|
48
|
+
`signFinishTimestamped` / `signTimestamped` previously embedded the TSA's raw
|
|
49
|
+
`TimeStampResp` (`SEQUENCE { PKIStatusInfo, TimeStampToken }`) verbatim in the
|
|
50
|
+
`id-aa-timeStampToken` unsigned attribute. The engine now unwraps the response
|
|
51
|
+
to the bare `TimeStampToken` (a CMS `ContentInfo`) before embedding it — as
|
|
52
|
+
required by RFC 3161 §3.3.2 / ETSI EN 319 122 — matching the B-LTA
|
|
53
|
+
document-timestamp path. Both a raw `TimeStampResp` and an already-unwrapped
|
|
54
|
+
token are accepted (the `PKIStatusInfo` gate is still enforced).
|
|
55
|
+
|
|
7
56
|
## [0.70.0] - 2026-06-23
|
|
8
57
|
|
|
9
58
|
Fidelity + standards release: advanced (PAdES-B-T) timestamped signatures,
|
package/README.md
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
# @qrcommunication/gigapdf-lib
|
|
2
2
|
|
|
3
3
|
TypeScript SDK for **gigapdf-lib** — a zero-dependency Rust→WASM PDF engine.
|
|
4
|
-
Read, edit, render,
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
Read, edit, render, search, **sign** (self-signed · PKCS#12 · PAdES-B-T timestamped
|
|
5
|
+
· PAdES-LTV), encrypt, fill & build forms, annotate, redact, and convert PDFs ↔
|
|
6
|
+
Office/HTML/RTF/Markdown/CSV — plus a native HTML/CSS→PDF renderer with a built-in
|
|
7
|
+
JavaScript engine, and a unified editable model that lowers/raises every format.
|
|
8
|
+
The engine `.wasm` is self-contained: **no third-party runtime dependencies**.
|
|
9
|
+
(OCR is a separate host-side native crate, `gigapdf-ocr-rten`.)
|
|
7
10
|
|
|
8
11
|
## Install
|
|
9
12
|
|
|
@@ -28,7 +31,7 @@ const doc = giga.open(pdfBytes); // Uint8Array
|
|
|
28
31
|
// Read
|
|
29
32
|
const lines = doc.structuredText(1); // [{ text, x, y, w, h }]
|
|
30
33
|
const hits = doc.search("invoice"); // [{ page, text, x, y, w, h }]
|
|
31
|
-
const
|
|
34
|
+
const text = doc.toText(); // whole-document plain text (exact, no OCR)
|
|
32
35
|
|
|
33
36
|
// Edit (operates on the real content stream — no cosmetic overlay)
|
|
34
37
|
doc.replaceText(1, 0, "New value");
|
|
@@ -171,9 +174,30 @@ const signed2 = doc.signP12(p12Bytes, "p12-password", {
|
|
|
171
174
|
date: "D:20260618120000Z",
|
|
172
175
|
location: "Paris",
|
|
173
176
|
});
|
|
177
|
+
|
|
178
|
+
// (c) PAdES-B-T — add an RFC 3161 trusted timestamp (async: one TSA round trip).
|
|
179
|
+
// Identity is the p12 above, or a self-signed id (random + notBefore/notAfter).
|
|
180
|
+
const timestamped = await doc.signTimestamped({
|
|
181
|
+
p12: p12Bytes, password: "p12-password", name: "Jane Doe",
|
|
182
|
+
tsaUrl: "https://freetsa.org/tsr",
|
|
183
|
+
// tsaFetch: custom fetch (auth / proxy / SSRF allow-list — recommended in prod)
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// (d) PAdES-LTV — B-T plus a /DSS (chain + OCSP/CRL the host fetches), so the
|
|
187
|
+
// signature validates long-term. archiveTimestamp adds a B-LTA doc timestamp.
|
|
188
|
+
const ltv = await doc.signLtv({
|
|
189
|
+
p12: p12Bytes, password: "p12-password",
|
|
190
|
+
tsaUrl: "https://freetsa.org/tsr", archiveTimestamp: true,
|
|
191
|
+
// revocationFetch / crlFetch: override the OCSP/CRL HTTP (SSRF allow-list)
|
|
192
|
+
});
|
|
174
193
|
doc.close();
|
|
175
194
|
```
|
|
176
195
|
|
|
196
|
+
> Timestamping and LTV need network the WASM core can't perform, so the engine
|
|
197
|
+
> emits the request bytes and the SDK does the HTTP. The OCSP/CRL/TSA URLs are
|
|
198
|
+
> **host-supplied** (LTV URLs come from the certificates) — in production pass
|
|
199
|
+
> `tsaFetch` / `revocationFetch` / `crlFetch` to apply your own SSRF allow-list.
|
|
200
|
+
|
|
177
201
|
### Annotate, then flatten
|
|
178
202
|
|
|
179
203
|
```ts
|
|
@@ -210,14 +234,23 @@ const pdf = giga.htmlRender(html, fonts, 595, 842, 36); // A4 in points, 36pt m
|
|
|
210
234
|
// giga.htmlRenderWith(html, fonts, { pageSize: "A4", header, footer });
|
|
211
235
|
```
|
|
212
236
|
|
|
213
|
-
### Make a scanned PDF searchable (OCR → invisible text layer)
|
|
237
|
+
### Make a scanned PDF searchable (host OCR → invisible text layer)
|
|
238
|
+
|
|
239
|
+
OCR itself runs **host-side** — it lives in the separate native crate
|
|
240
|
+
`gigapdf-ocr-rten` (PaddleOCR PP-OCR on a pure-Rust runtime), whose model weights
|
|
241
|
+
are far heavier than the lean WASM core. This SDK provides the **text-layer**
|
|
242
|
+
side: `addTextLayer` stamps recognized words back onto the page so the scan
|
|
243
|
+
becomes selectable & searchable. (For PDFs that already carry text, use
|
|
244
|
+
`toText`/`structuredText`/`search` — exact, no OCR needed.)
|
|
214
245
|
|
|
215
246
|
```ts
|
|
216
247
|
const doc = giga.open(scannedPdf);
|
|
217
248
|
const scale = 2; // rasterise at 2× = 144 dpi for OCR
|
|
218
249
|
for (let page = 1; page <= doc.pageCount(); page++) {
|
|
219
250
|
const { height } = doc.pageInfo(page);
|
|
220
|
-
const
|
|
251
|
+
const png = doc.renderPage(page, scale); // raster the page for your OCR service…
|
|
252
|
+
const words = await ocrService(png); // … your host OCR → [{ x, y, w, h, text }]
|
|
253
|
+
// boxes in raster pixels (top-left)
|
|
221
254
|
// Map each word box back to PDF user space (bottom-left, Y up) and stamp an
|
|
222
255
|
// invisible (render-mode 3) text layer — selectable & searchable, pixel-aligned.
|
|
223
256
|
doc.addTextLayer(page, words.map((w) => ({
|
|
@@ -269,15 +302,18 @@ Or call `GigaPdfEngine.load(bytes)` with bytes you read yourself.
|
|
|
269
302
|
- **`GigaPdfEngine`** — `load`/`loadDefault`, `open`/`openEncrypted`,
|
|
270
303
|
`txtToPdf`/`htmlToPdf`/`rtfToPdf`/`officeToPdf`/`imageToPdf` (PNG/JPEG/GIF/WebP/AVIF → A4 page),
|
|
271
304
|
`mergePdfs` (concatenate many PDFs), `fontCatalog`/`fontRequestUrl`/`parseCssFontUrl`.
|
|
272
|
-
- **`GigaPdfDoc`** — text intelligence (`textRuns`, `structuredText`,
|
|
273
|
-
`
|
|
305
|
+
- **`GigaPdfDoc`** — text intelligence (`textRuns`, `structuredText`,
|
|
306
|
+
`pageBlocks`, `search`, `toText`, `elements`, `elementAt`, `documentLanguage`),
|
|
307
|
+
editing (`replaceText`, `setTextRunStyle` (per-character restyle),
|
|
274
308
|
`removeElement`, `moveElement`, `transformElement` (full affine — move + resize
|
|
275
309
|
+ rotate in place), `reorderElement` (native z-order — bring to front / send to
|
|
276
310
|
back), `setPathStyle` (in-place vector restyle: fill/stroke/width/dash + **real
|
|
277
311
|
opacity**), `setElementOpacity` (constant opacity on any element — text/image/shape),
|
|
278
|
-
`duplicateElement`, `redact`),
|
|
312
|
+
`duplicateElement`, `redact`, `redactPii` (irreversible — erases image pixels)),
|
|
313
|
+
vector drawing
|
|
279
314
|
(`addRectangle`, `drawLine`, `addEllipse`, `addPolygon`, `addPath` (SVG path),
|
|
280
|
-
`addImage` (PNG/JPEG, alpha + opacity)
|
|
315
|
+
`addImage` (PNG/JPEG, alpha + opacity), `addImageWatermark` (stamp an image
|
|
316
|
+
across pages), `addSvg` (native vector)), pages (`rotatePage`, `deletePage`,
|
|
281
317
|
`movePage`, `appendPages`, `extractPages`, `resizePage`, `addPage`, `copyPage`,
|
|
282
318
|
`pageInfo`),
|
|
283
319
|
`renderPage` (and `renderPageNoText` — a text-free background for editors that
|
|
@@ -287,12 +323,14 @@ Or call `GigaPdfEngine.load(bytes)` with bytes you read yourself.
|
|
|
287
323
|
fonts (base-14 `addStandardText`, embed **any** TrueType/OpenType
|
|
288
324
|
via `embedFont`/`addText`, font-aware editing `replaceText`,
|
|
289
325
|
the document's own faces `embeddedFonts`/`extractFont`, `neededFonts`),
|
|
290
|
-
conversions (`toText/Html/Docx/Pptx/Odp/Odt/Xlsx/Ods/Rtf/PdfA`,
|
|
291
|
-
engine-level `gridsToXlsx`/`gridsToOds` to
|
|
292
|
-
host-built table grid), security
|
|
293
|
-
(`saveEncrypted
|
|
294
|
-
|
|
295
|
-
|
|
326
|
+
conversions (`toText/Html/Docx/Pptx/Odp/Odt/Xlsx/Ods/Rtf/PdfA`, `toModel` for
|
|
327
|
+
the unified editable model, plus engine-level `gridsToXlsx`/`gridsToOds` to
|
|
328
|
+
emit Office output from a host-built table grid), security
|
|
329
|
+
(`saveEncrypted` (AES-256 R6) + `permissionsToP`/`getPermissions`; **digital
|
|
330
|
+
signatures**: self-signed `sign`, **PKCS#12** `signP12`, **PAdES-B-T** timestamped
|
|
331
|
+
`signTimestamped` (RFC 3161 TSA), **PAdES-LTV** `signLtv` (DSS + OCSP/CRL, B-LT/B-LTA)),
|
|
332
|
+
metadata (`getMetadata`, `setMetadata`), embedded files (`attachments` — extract
|
|
333
|
+
every `/EmbeddedFiles` entry with its decoded bytes), annotations (`addSquare`,
|
|
296
334
|
`addHighlight`, `addLineAnnotation`, `addFreeText`, `addUnderline`,
|
|
297
335
|
`addStrikeOut`, `addInk`, `addStamp`, `annotations`, `removeAnnotation`,
|
|
298
336
|
`flattenAnnotations`), links (`links`, `addUriLink`, `addGotoLink`, named
|
|
@@ -300,7 +338,9 @@ Or call `GigaPdfEngine.load(bytes)` with bytes you read yourself.
|
|
|
300
338
|
(`outline`, `setOutline`), forms — read/fill (`fields`, `setTextField`,
|
|
301
339
|
`setCheckbox`, `setRadio`, `setChoice`) **and create**
|
|
302
340
|
(`addTextField`, `addCheckbox`, `addRadioGroup`, `addComboBox`, `addListBox`,
|
|
303
|
-
each with an optional `FieldStyle`)
|
|
341
|
+
each with an optional `FieldStyle`) plus `flattenForm` / `flattenFormXObjects`,
|
|
342
|
+
margins & running header/footer (`pageMargins`/`setPageMargins`,
|
|
343
|
+
`setHeader`/`setFooter`/`headerFooter`), and optional-content layers (`layers`,
|
|
304
344
|
`addLayer`, `setLayerVisibility`, `setLayerLocked`, `removeLayer`).
|
|
305
345
|
- **HTML rendering engine** (on `GigaPdfEngine`) — `htmlNeededFonts(html)`
|
|
306
346
|
returns the Google fonts to download (phase 1); `htmlRender(html, fonts,
|
package/dist/index.cjs
CHANGED
|
@@ -22,6 +22,8 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
GigaPdfDoc: () => GigaPdfDoc,
|
|
24
24
|
GigaPdfEngine: () => GigaPdfEngine,
|
|
25
|
+
defaultCrlGet: () => defaultCrlGet,
|
|
26
|
+
defaultOcspPost: () => defaultOcspPost,
|
|
25
27
|
defaultTsaPost: () => defaultTsaPost
|
|
26
28
|
});
|
|
27
29
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -912,6 +914,47 @@ function packHtmlFonts(fonts) {
|
|
|
912
914
|
}
|
|
913
915
|
return buf;
|
|
914
916
|
}
|
|
917
|
+
async function defaultOcspPost(req, url) {
|
|
918
|
+
const res = await fetch(url, {
|
|
919
|
+
method: "POST",
|
|
920
|
+
headers: { "Content-Type": "application/ocsp-request" },
|
|
921
|
+
body: req,
|
|
922
|
+
redirect: "error"
|
|
923
|
+
});
|
|
924
|
+
if (!res.ok) {
|
|
925
|
+
throw new Error(`OCSP HTTP ${res.status}`);
|
|
926
|
+
}
|
|
927
|
+
return new Uint8Array(await res.arrayBuffer());
|
|
928
|
+
}
|
|
929
|
+
async function defaultCrlGet(url) {
|
|
930
|
+
const res = await fetch(url, { method: "GET", redirect: "error" });
|
|
931
|
+
if (!res.ok) {
|
|
932
|
+
throw new Error(`CRL HTTP ${res.status}`);
|
|
933
|
+
}
|
|
934
|
+
return new Uint8Array(await res.arrayBuffer());
|
|
935
|
+
}
|
|
936
|
+
function hexToBytes(hex) {
|
|
937
|
+
const out = new Uint8Array(hex.length >> 1);
|
|
938
|
+
for (let i = 0; i < out.length; i++) {
|
|
939
|
+
out[i] = parseInt(hex.substr(i * 2, 2), 16);
|
|
940
|
+
}
|
|
941
|
+
return out;
|
|
942
|
+
}
|
|
943
|
+
function frameBlobs(blobs) {
|
|
944
|
+
let total = 4;
|
|
945
|
+
for (const b of blobs) total += 4 + b.length;
|
|
946
|
+
const out = new Uint8Array(total);
|
|
947
|
+
const view = new DataView(out.buffer);
|
|
948
|
+
view.setUint32(0, blobs.length, true);
|
|
949
|
+
let pos = 4;
|
|
950
|
+
for (const b of blobs) {
|
|
951
|
+
view.setUint32(pos, b.length, true);
|
|
952
|
+
pos += 4;
|
|
953
|
+
out.set(b, pos);
|
|
954
|
+
pos += b.length;
|
|
955
|
+
}
|
|
956
|
+
return out;
|
|
957
|
+
}
|
|
915
958
|
var RGB = (rgb) => rgb & 16777215;
|
|
916
959
|
function styleArgs(s = {}) {
|
|
917
960
|
const hasBorder = s.border === null ? 0 : 1;
|
|
@@ -1850,6 +1893,142 @@ var GigaPdfDoc = class {
|
|
|
1850
1893
|
}
|
|
1851
1894
|
return out;
|
|
1852
1895
|
}
|
|
1896
|
+
/**
|
|
1897
|
+
* Sign with **long-term validation** material embedded (PAdES-B-LT, or B-LTA
|
|
1898
|
+
* with `opts.archiveTimestamp`). Builds a B-T signature ({@link signTimestamped}),
|
|
1899
|
+
* then fetches the certificate chain's revocation material (OCSP responses /
|
|
1900
|
+
* CRLs, by URL **from the certificates** — the engine computes which URLs, the
|
|
1901
|
+
* host fetches) and stores it in a `/DSS`, so the signature validates long after
|
|
1902
|
+
* the certificates expire or are revoked. With `archiveTimestamp` a document
|
|
1903
|
+
* timestamp over the whole file (DSS included) is added for renewable archival.
|
|
1904
|
+
*
|
|
1905
|
+
* `async`, multi-round-trip: one TSA POST for the B-T timestamp, one OCSP/CRL
|
|
1906
|
+
* fetch per chain certificate, and (if `archiveTimestamp`) a second TSA POST.
|
|
1907
|
+
* Unreachable responders are skipped — the DSS is built from whatever resolves;
|
|
1908
|
+
* a self-signed identity (no AIA/CRL-DP) simply yields a `/DSS/Certs`-only store.
|
|
1909
|
+
* Override `tsaFetch`/`revocationFetch`/`crlFetch` to add auth, proxies, or an
|
|
1910
|
+
* SSRF allow-list. Throws on a fatal failure (bad identity, B-T signature, or a
|
|
1911
|
+
* malformed PDF the DSS can't chain to).
|
|
1912
|
+
*/
|
|
1913
|
+
async signLtv(opts) {
|
|
1914
|
+
const signed = await this.signTimestamped(opts);
|
|
1915
|
+
const nonce = opts.nonce ?? new Uint8Array(0);
|
|
1916
|
+
const targetsJson = this.withSignedPdf(signed, (pdfPtr, pdfLen) => {
|
|
1917
|
+
const noncePtr = this.g._toWasm(nonce);
|
|
1918
|
+
try {
|
|
1919
|
+
return dec.decode(
|
|
1920
|
+
this.g._buffer(
|
|
1921
|
+
(o) => this.ex().gp_ltv_targets(pdfPtr, pdfLen, noncePtr, nonce.length, o)
|
|
1922
|
+
)
|
|
1923
|
+
);
|
|
1924
|
+
} finally {
|
|
1925
|
+
this.g._free(noncePtr, nonce.length);
|
|
1926
|
+
}
|
|
1927
|
+
});
|
|
1928
|
+
const targets = targetsJson ? JSON.parse(targetsJson) : [];
|
|
1929
|
+
const certs = [];
|
|
1930
|
+
const ocsps = [];
|
|
1931
|
+
const crls = [];
|
|
1932
|
+
const ocspPost = opts.revocationFetch ?? defaultOcspPost;
|
|
1933
|
+
const crlGet = opts.crlFetch ?? defaultCrlGet;
|
|
1934
|
+
for (const target of targets) {
|
|
1935
|
+
certs.push(hexToBytes(target.certHex));
|
|
1936
|
+
for (const source of target.sources) {
|
|
1937
|
+
try {
|
|
1938
|
+
if (source.kind === "ocsp") {
|
|
1939
|
+
ocsps.push(await ocspPost(hexToBytes(source.requestHex), source.url));
|
|
1940
|
+
} else {
|
|
1941
|
+
crls.push(await crlGet(source.url));
|
|
1942
|
+
}
|
|
1943
|
+
} catch {
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
let lt = this.applyDss(signed, certs, ocsps, crls);
|
|
1948
|
+
if (opts.archiveTimestamp) {
|
|
1949
|
+
lt = await this.appendDocumentTimestamp(lt, opts);
|
|
1950
|
+
}
|
|
1951
|
+
return lt;
|
|
1952
|
+
}
|
|
1953
|
+
/** Run `fn` with `pdf` copied into wasm memory, freeing it afterwards. */
|
|
1954
|
+
withSignedPdf(pdf, fn) {
|
|
1955
|
+
const ptr = this.g._toWasm(pdf);
|
|
1956
|
+
try {
|
|
1957
|
+
return fn(ptr, pdf.length);
|
|
1958
|
+
} finally {
|
|
1959
|
+
this.g._free(ptr, pdf.length);
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
/** Add the `/DSS` to `signed` as an incremental update (B-LT). */
|
|
1963
|
+
applyDss(signed, certs, ocsps, crls) {
|
|
1964
|
+
const certsBuf = frameBlobs(certs);
|
|
1965
|
+
const ocspsBuf = frameBlobs(ocsps);
|
|
1966
|
+
const crlsBuf = frameBlobs(crls);
|
|
1967
|
+
const pdfPtr = this.g._toWasm(signed);
|
|
1968
|
+
const cPtr = this.g._toWasm(certsBuf);
|
|
1969
|
+
const oPtr = this.g._toWasm(ocspsBuf);
|
|
1970
|
+
const rPtr = this.g._toWasm(crlsBuf);
|
|
1971
|
+
let out;
|
|
1972
|
+
try {
|
|
1973
|
+
out = this.g._buffer(
|
|
1974
|
+
(res) => this.ex().gp_apply_dss(
|
|
1975
|
+
pdfPtr,
|
|
1976
|
+
signed.length,
|
|
1977
|
+
cPtr,
|
|
1978
|
+
certsBuf.length,
|
|
1979
|
+
oPtr,
|
|
1980
|
+
ocspsBuf.length,
|
|
1981
|
+
rPtr,
|
|
1982
|
+
crlsBuf.length,
|
|
1983
|
+
res
|
|
1984
|
+
)
|
|
1985
|
+
);
|
|
1986
|
+
} finally {
|
|
1987
|
+
this.g._free(pdfPtr, signed.length);
|
|
1988
|
+
this.g._free(cPtr, certsBuf.length);
|
|
1989
|
+
this.g._free(oPtr, ocspsBuf.length);
|
|
1990
|
+
this.g._free(rPtr, crlsBuf.length);
|
|
1991
|
+
}
|
|
1992
|
+
if (out.length === 0) {
|
|
1993
|
+
throw new Error("LTV failed: could not add the /DSS to the signed PDF");
|
|
1994
|
+
}
|
|
1995
|
+
return out;
|
|
1996
|
+
}
|
|
1997
|
+
/** Append a document timestamp over the whole `pdf` (B-LTA), TSA round trip
|
|
1998
|
+
* included. */
|
|
1999
|
+
async appendDocumentTimestamp(pdf, opts) {
|
|
2000
|
+
const nonce = opts.nonce ?? new Uint8Array(0);
|
|
2001
|
+
const pdfPtr = this.g._toWasm(pdf);
|
|
2002
|
+
const noncePtr = this.g._toWasm(nonce);
|
|
2003
|
+
let request;
|
|
2004
|
+
try {
|
|
2005
|
+
request = this.g._buffer(
|
|
2006
|
+
(o) => this.ex().gp_doc_timestamp_prepare(this.h, pdfPtr, pdf.length, noncePtr, nonce.length, o)
|
|
2007
|
+
);
|
|
2008
|
+
} finally {
|
|
2009
|
+
this.g._free(pdfPtr, pdf.length);
|
|
2010
|
+
this.g._free(noncePtr, nonce.length);
|
|
2011
|
+
}
|
|
2012
|
+
if (request.length === 0) {
|
|
2013
|
+
throw new Error("LTV archive timestamp failed: could not build the timestamp request");
|
|
2014
|
+
}
|
|
2015
|
+
const response = opts.tsaFetch ? await opts.tsaFetch(request, opts.tsaUrl) : await defaultTsaPost(opts.tsaUrl, request);
|
|
2016
|
+
const tokenPtr = this.g._toWasm(response);
|
|
2017
|
+
let out;
|
|
2018
|
+
try {
|
|
2019
|
+
out = this.g._buffer(
|
|
2020
|
+
(o) => this.ex().gp_doc_timestamp_finish(this.h, tokenPtr, response.length, o)
|
|
2021
|
+
);
|
|
2022
|
+
} finally {
|
|
2023
|
+
this.g._free(tokenPtr, response.length);
|
|
2024
|
+
}
|
|
2025
|
+
if (out.length === 0) {
|
|
2026
|
+
throw new Error(
|
|
2027
|
+
"LTV archive timestamp failed: TSA response rejected or token too large for the reserved space"
|
|
2028
|
+
);
|
|
2029
|
+
}
|
|
2030
|
+
return out;
|
|
2031
|
+
}
|
|
1853
2032
|
// metadata
|
|
1854
2033
|
getMetadata(key) {
|
|
1855
2034
|
return this.g._withStr(
|
|
@@ -2250,6 +2429,8 @@ var GigaPdfDoc = class {
|
|
|
2250
2429
|
0 && (module.exports = {
|
|
2251
2430
|
GigaPdfDoc,
|
|
2252
2431
|
GigaPdfEngine,
|
|
2432
|
+
defaultCrlGet,
|
|
2433
|
+
defaultOcspPost,
|
|
2253
2434
|
defaultTsaPost
|
|
2254
2435
|
});
|
|
2255
2436
|
//# sourceMappingURL=index.cjs.map
|