Long-term signatures (B-LTA)
Sign at PAdES B-T, B-LT and B-LTA, add document timestamps with your own time-stamp authority, and validate B-LTA files with NexPDF for Node.js.
License module
Signature levels and document timestamps need the signatures module (Business tier and above).
Verification needs the same module.
PAdES B-LTA keeps a signature verifiable for decades. On top of a timestamped signature with its validation data (B-LT), it adds a document timestamp: an RFC 3161 timestamp over the whole file, in an invisible signature field. Before the timestamp authority's certificate expires, you add another one (an archive timestamp), and so on.
Every level above B-B needs a timestamp authority (TSA), and B-LT and B-LTA also fetch OCSP
responses and CRLs. The WebAssembly engine makes no network calls itself: it signs, then builds
each request, and the SDK sends them with fetch (the global one of Node.js 18 and later, or the
fetch option) and gives the answers back to the engine.
Sign at a chosen level
doc.signOnline(p12, password, options) signs at any level and resolves to the signed PDF:
level | What you get | Needs |
|---|---|---|
B-B | Signature only (the default) | |
B-T | Plus a signature timestamp | tsaUrl or tsa |
B-LT | Plus certificates, OCSP responses and CRLs (DSS) | tsaUrl or tsa |
B-LTA | Plus a document timestamp | tsaUrl or tsa |
import { readFile, writeFile } from 'node:fs/promises';
import { PdfDocument } from '@nexdevit/nexpdf-node';
const doc = await PdfDocument.open('contract.pdf');
const signed = await doc.signOnline(await readFile('signer.p12'), 'p12-password', {
level: 'B-LTA',
tsaUrl: 'http://timestamp.digicert.com',
reason: 'Approved',
});
await writeFile('contract-lta.pdf', signed);The options are those of sign (name, reason, location, contact, field, appearance,
reserved) plus level, tsaUrl, tsa, hash (SHA-256, SHA-384 or SHA-512), ltv (also
add the DSS at B-B or B-T), timestamp (the B-LTA document timestamp's hash, field and
reserved), fetch, headers (extra headers for the TSA, such as Authorization) and
maxRounds (rounds of OCSP, CRL and issuer requests, default 16).
For external signing (HSM, smart card, cloud KMS), the last step at any level is
completeExternalSignatureOnline(prepared, cert, signature, { algorithm, level, tsaUrl }). See
Digital signatures.
Raise a signed file
On the bytes of a signed PDF, each level is one call:
| Call | Does |
|---|---|
timestampSignature(pdf, { tsaUrl }) | B-T: a signature timestamp on the last signature (before any other change) |
addLtvOnline(pdf) | B-LT: OCSP responses, CRLs and certificates of every signature into the DSS |
timestampDocument(pdf, { tsaUrl }) | A document timestamp; with ltv: true the DSS is added first (B-LTA, archive renewal) |
upgradeSignature(pdf, level, options) | Raises a freshly signed B-B file to level |
import { addLtvOnline, timestampDocument, timestampSignature } from '@nexdevit/nexpdf-node';
const tsaUrl = 'http://timestamp.digicert.com';
let pdf = doc.sign(await readFile('signer.p12'), 'p12-password', { reason: 'Approved' }); // B-B
pdf = await timestampSignature(pdf, { tsaUrl }); // B-T
pdf = await addLtvOnline(pdf); // B-LT
pdf = await timestampDocument(pdf, { tsaUrl }); // B-LTAtimestampDocument also takes field (default Timestamp<n>), reserved (bytes for the token,
default 16384) and hash. To renew an archive, call it again with ltv: true before the last
timestamp's certificate expires.
Your own TSA
Instead of tsaUrl, pass tsa: a function that receives the RFC 3161 request (DER bytes) and
returns the TSA's response (the DER body a TSA answers), or a Promise of it. Use it for an
authority behind your own client, a signing service or a test TSA. When both are given, tsa is
used. If it throws, the call fails with "TSA callback failed".
const tsa = async (request) => {
const res = await fetch(myTsaUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/timestamp-query', Authorization: `Bearer ${tsaToken}` },
body: request,
});
return new Uint8Array(await res.arrayBuffer());
};
const signedBt = await doc.signOnline(await readFile('signer.p12'), 'p12-password', { level: 'B-T', tsa });signOnline, completeExternalSignatureOnline, timestampSignature, timestampDocument and
upgradeSignature take tsa. It is the JavaScript form of the native SDKs' TSA callback.
The engine steps
The helpers above are built on engine functions that @nexdevit/nexpdf-node exports too, for hosts
that send the requests themselves:
| Level | Steps |
|---|---|
| B-T | signatureTimestampRequest(pdf, hash) (a TimeStampReq over the last signature, POST as application/timestamp-query), then addSignatureTimestamp(pdf, token) |
| B-LT | ltvRequestsJson(pdf, responsesJson) lists the HTTP requests still needed ([{"method","url","content_type","body"}], body in base64); call it again with the answers until it returns [], then addLtvWithResponses(pdf, responsesJson) |
| Document timestamp | doc.raw.prepareDocumentTimestamp(optionsJson) (the document with an empty timestamp field), documentTimestampRequest(prepared, hash), POST, then completeDocumentTimestamp(prepared, token) |
C_FUNCTIONS maps each C function to its name in the package.
Validate B-LTA
validateLtaJson(pdf, trustRootsPem) checks, for each document timestamp, whether the DSS
of the revision it timestamps holds every certificate and revocation entry needed for the earlier
signatures, their TSAs and earlier document timestamps. OCSP responses are verified: their
signature, the responder (the issuing CA or a delegated id-kp-OCSPSigning certificate), the
responder's chain to your roots, thisUpdate and nextUpdate around the protecting timestamp, and
the status.
import { validateLtaJson } from '@nexdevit/nexpdf-node';
const lta = JSON.parse(validateLtaJson(await readFile('contract-lta.pdf'), await readFile('roots.pem', 'utf8')));
console.log(lta.complete);
for (const t of lta.timestamps) {
console.log(t.field, t.time, t.valid, t.has_dss, t.complete, t.covers);
for (const i of t.issues) console.log(' ', i.field, i.role, i.subject, i.kind);
}Issue kinds: missing-certificate, missing-revocation, revoked, ocsp-bad-signature,
ocsp-unauthorized-responder, ocsp-untrusted-responder, ocsp-not-current and
ocsp-unknown-status.
Verify
verifySignatures(bytes, rootsPem) reports every signature and every document timestamp, offline. Two
fields are new in 1.1:
| Field | Meaning |
|---|---|
document_timestamp | true for a document timestamp. Then signer is the TSA, digest_ok checks the message imprint and trusted checks the TSA chain against your roots |
pades_level | B-B, B-T, B-LT or B-LTA |
import { verifySignatures } from '@nexdevit/nexpdf-node';
for (const s of verifySignatures(await readFile('contract-lta.pdf'))) {
const kind = s.document_timestamp ? 'timestamp' : 'signature';
console.log(kind, s.signer, s.pades_level, s.digest_ok && s.signature_ok);
}See Digital signatures for signing with PKCS#12 files and external devices.