@qrcommunication/gigapdf-lib 0.70.0 → 0.71.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 +34 -0
- 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,40 @@ 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.0] - 2026-06-23
|
|
8
|
+
|
|
9
|
+
Long-term validation release: PAdES-LTV builds on the B-T timestamped signatures
|
|
10
|
+
from 0.70 by embedding the validation material (certificate chain + revocation
|
|
11
|
+
responses) so a signature keeps verifying long after its certificates expire or
|
|
12
|
+
are revoked. The public API is additive — existing behaviour is unchanged.
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- **PAdES-LTV (B-LT / B-LTA).** New SDK `GigaPdfDoc.signLtv()` (async) produces a
|
|
17
|
+
long-term-validation signature: it first builds a B-T signature
|
|
18
|
+
(`signTimestamped`), then embeds a Document Security Store (`/DSS` with
|
|
19
|
+
`/Certs`, `/OCSPs`, `/CRLs`, and per-signature `/VRI`) carrying the revocation
|
|
20
|
+
material for the certificate chain (B-LT). With `archiveTimestamp` it also adds
|
|
21
|
+
a `/DocTimeStamp` document timestamp (`ETSI.RFC3161` subfilter) over the whole
|
|
22
|
+
updated file for B-LTA, refreshing the long-term trust anchor. The engine
|
|
23
|
+
computes *which* OCSP/CRL endpoints to query from the certificates' AIA / CRL-DP
|
|
24
|
+
extensions; the host fetches them (the WASM core has no network stack, same
|
|
25
|
+
pure-data two-phase model as the TSA). OCSP requests follow RFC 6960; CRLs are
|
|
26
|
+
parsed as `CertificateList`. The exported `defaultOcspPost` and `defaultCrlGet`
|
|
27
|
+
perform the round trips via `fetch`, and the `revocationFetch` / `crlFetch`
|
|
28
|
+
hooks let the host add auth/proxy/retries **and apply its own SSRF allow-list**.
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
|
|
32
|
+
- **B-T `id-aa-timeStampToken` now carries the bare `TimeStampToken`.**
|
|
33
|
+
`signFinishTimestamped` / `signTimestamped` previously embedded the TSA's raw
|
|
34
|
+
`TimeStampResp` (`SEQUENCE { PKIStatusInfo, TimeStampToken }`) verbatim in the
|
|
35
|
+
`id-aa-timeStampToken` unsigned attribute. The engine now unwraps the response
|
|
36
|
+
to the bare `TimeStampToken` (a CMS `ContentInfo`) before embedding it — as
|
|
37
|
+
required by RFC 3161 §3.3.2 / ETSI EN 319 122 — matching the B-LTA
|
|
38
|
+
document-timestamp path. Both a raw `TimeStampResp` and an already-unwrapped
|
|
39
|
+
token are accepted (the `PKIStatusInfo` gate is still enforced).
|
|
40
|
+
|
|
7
41
|
## [0.70.0] - 2026-06-23
|
|
8
42
|
|
|
9
43
|
Fidelity + standards release: advanced (PAdES-B-T) timestamped signatures,
|
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
|