@certysign/sdk 2.2.0 → 2.4.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.4.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",
@@ -53,6 +53,8 @@ class HashSigningResource {
53
53
  reason = 'Digital signature',
54
54
  location = 'Nairobi, Kenya',
55
55
  hashAlgorithm = 'sha256',
56
+ signerName,
57
+ signerEmail,
56
58
  metadata = {}
57
59
  } = options;
58
60
 
@@ -69,6 +71,8 @@ class HashSigningResource {
69
71
  fileName,
70
72
  reason,
71
73
  location,
74
+ signerName,
75
+ signerEmail,
72
76
  metadata
73
77
  }
74
78
  });
@@ -99,13 +103,15 @@ class HashSigningResource {
99
103
  fileName,
100
104
  reason = 'Digital signature',
101
105
  location = 'Nairobi, Kenya',
106
+ signerName,
107
+ signerEmail,
102
108
  metadata = {}
103
109
  } = options;
104
110
 
105
111
  if (!documentHash) throw new Error('signHash: documentHash is required');
106
112
 
107
113
  return this._http.post('/sdk/v1/sign/hash', {
108
- data: { documentHash, hashAlgorithm, fileName, reason, location, metadata }
114
+ data: { documentHash, hashAlgorithm, fileName, reason, location, signerName, signerEmail, metadata }
109
115
  });
110
116
  }
111
117
 
@@ -132,6 +138,8 @@ class HashSigningResource {
132
138
  documents,
133
139
  reason = 'Batch digital signature',
134
140
  hashAlgorithm = 'sha256',
141
+ signerName,
142
+ signerEmail,
135
143
  metadata = {}
136
144
  } = options;
137
145
 
@@ -148,7 +156,7 @@ class HashSigningResource {
148
156
  });
149
157
 
150
158
  return this._http.post('/sdk/v1/sign/hash/batch', {
151
- data: { documents: hashed, reason, metadata }
159
+ data: { documents: hashed, reason, signerName, signerEmail, metadata }
152
160
  });
153
161
  }
154
162
 
@@ -159,12 +167,12 @@ class HashSigningResource {
159
167
  * @returns {Promise<BatchHashSignResult>}
160
168
  */
161
169
  async batchSignHashes(options) {
162
- const { documents, reason = 'Batch digital signature', metadata = {} } = options;
170
+ const { documents, reason = 'Batch digital signature', signerName, signerEmail, metadata = {} } = options;
163
171
 
164
172
  if (!documents?.length) throw new Error('batchSignHashes: documents array is required');
165
173
 
166
174
  return this._http.post('/sdk/v1/sign/hash/batch', {
167
- data: { documents, reason, metadata }
175
+ data: { documents, reason, signerName, signerEmail, metadata }
168
176
  });
169
177
  }
170
178
 
@@ -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