@certysign/sdk 2.2.0 → 2.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certysign/sdk",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Official Node.js SDK for CertySign — hash-based digital signing, X.509 certificates, and PKI services. Documents never leave your system.",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -103,7 +103,7 @@ class SignatureEmbedder {
103
103
  if (!entry) throw new Error('embedInPdf: at least one signature entry is required');
104
104
 
105
105
  const signerEmail = entry.signerEmail || entry.recipientEmail || entry.signerName || 'CertySign';
106
- const certSerial = entry.certSerialNumber || '';
106
+ let certSerial = entry.certSerialNumber || '';
107
107
  const signDate = entry.timestamp ? new Date(entry.timestamp) :
108
108
  entry.signedAt ? new Date(entry.signedAt) : new Date();
109
109
  const reason = entry.reason || 'Digital signature';
@@ -119,6 +119,32 @@ class SignatureEmbedder {
119
119
  throw new Error('embedInPdf: either signCallback or signature is required');
120
120
  }
121
121
 
122
+ // ── Auto-resolve cert serial from PEM if not explicitly provided ──
123
+ if (!certSerial && certPem) {
124
+ try {
125
+ const parsedCert = forge.certificateFromPem(certPem);
126
+ certSerial = (parsedCert.serialNumber || '').toUpperCase();
127
+ } catch { /* ignore parse errors — stamp will show empty cert serial */ }
128
+ }
129
+
130
+ // ── signCallback pre-flight: discover cert serial before drawing stamp ──
131
+ // When using signCallback without a known cert serial, we call the callback
132
+ // with a dummy hash to learn the certificate. Then we re-call with the real
133
+ // ByteRange hash below. This ensures the visual stamp shows the cert serial.
134
+ let preflightResult = null;
135
+ if (signCallback && !certSerial) {
136
+ const dummyHash = '0'.repeat(64); // SHA-256 dummy
137
+ preflightResult = await signCallback(dummyHash);
138
+ const preflightCertPem = preflightResult.data?.certificate || preflightResult.certificate;
139
+ certSerial = preflightResult.data?.certSerialNumber || preflightResult.certSerialNumber || '';
140
+ if (!certSerial && preflightCertPem) {
141
+ try {
142
+ const parsedCert = forge.certificateFromPem(preflightCertPem);
143
+ certSerial = (parsedCert.serialNumber || '').toUpperCase();
144
+ } catch { /* ignore */ }
145
+ }
146
+ }
147
+
122
148
  // ── Determine target page ──
123
149
  const pos = entry.signaturePosition || {};
124
150
  const pageIdx = pos.page