edockit 0.2.4 → 0.4.0-dev.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.
Files changed (69) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +81 -175
  3. package/TRUSTED-LIST.md +308 -0
  4. package/dist/certificate-c46e14a0.js +560 -0
  5. package/dist/certificate-c46e14a0.js.map +1 -0
  6. package/dist/certificate-fc0e06f7.js +571 -0
  7. package/dist/certificate-fc0e06f7.js.map +1 -0
  8. package/dist/core/canonicalization/XMLCanonicalizer.d.ts +9 -3
  9. package/dist/core/rsa-digestinfo-workaround.d.ts +29 -0
  10. package/dist/core/trustedlist/build.d.ts +41 -0
  11. package/dist/core/trustedlist/bundled-provider.d.ts +2 -0
  12. package/dist/core/trustedlist/contract.d.ts +19 -0
  13. package/dist/core/trustedlist/dom.d.ts +12 -0
  14. package/dist/core/trustedlist/extract.d.ts +6 -0
  15. package/dist/core/trustedlist/http.d.ts +8 -0
  16. package/dist/core/trustedlist/identity.d.ts +7 -0
  17. package/dist/core/trustedlist/index.d.ts +18 -0
  18. package/dist/core/trustedlist/loader.d.ts +5 -0
  19. package/dist/core/trustedlist/matcher.d.ts +11 -0
  20. package/dist/core/trustedlist/normalize.d.ts +14 -0
  21. package/dist/core/trustedlist/reference-provider.d.ts +12 -0
  22. package/dist/core/trustedlist/types.d.ts +114 -0
  23. package/dist/core/unzip.d.ts +0 -0
  24. package/dist/core/verification.d.ts +50 -0
  25. package/dist/data/trusted-list.d.ts +3 -0
  26. package/dist/identity-1a3dddc3.js +902 -0
  27. package/dist/identity-1a3dddc3.js.map +1 -0
  28. package/dist/identity-b3a70fc1.js +897 -0
  29. package/dist/identity-b3a70fc1.js.map +1 -0
  30. package/dist/index.cjs.js +1275 -7892
  31. package/dist/index.cjs.js.map +1 -1
  32. package/dist/index.d.ts +4 -2
  33. package/dist/index.esm.js +783 -7399
  34. package/dist/index.esm.js.map +1 -1
  35. package/dist/index.umd.js +12 -15
  36. package/dist/index.umd.js.map +1 -1
  37. package/dist/loader-1ac52e12.js +217 -0
  38. package/dist/loader-1ac52e12.js.map +1 -0
  39. package/dist/loader-43d8e17a.js +222 -0
  40. package/dist/loader-43d8e17a.js.map +1 -0
  41. package/dist/normalize-60f2d7e6.js +6270 -0
  42. package/dist/normalize-60f2d7e6.js.map +1 -0
  43. package/dist/normalize-70da6516.js +6214 -0
  44. package/dist/normalize-70da6516.js.map +1 -0
  45. package/dist/reference-provider-1cd85b7b.js +217 -0
  46. package/dist/reference-provider-1cd85b7b.js.map +1 -0
  47. package/dist/reference-provider-53240217.js +211 -0
  48. package/dist/reference-provider-53240217.js.map +1 -0
  49. package/dist/trusted-list-build.cjs.js +575 -0
  50. package/dist/trusted-list-build.cjs.js.map +1 -0
  51. package/dist/trusted-list-build.d.ts +4 -0
  52. package/dist/trusted-list-build.esm.js +564 -0
  53. package/dist/trusted-list-build.esm.js.map +1 -0
  54. package/dist/trusted-list-bundled.cjs.js +30436 -0
  55. package/dist/trusted-list-bundled.cjs.js.map +1 -0
  56. package/dist/trusted-list-bundled.d.ts +1 -0
  57. package/dist/trusted-list-bundled.esm.js +30432 -0
  58. package/dist/trusted-list-bundled.esm.js.map +1 -0
  59. package/dist/trusted-list-http.cjs.js +85 -0
  60. package/dist/trusted-list-http.cjs.js.map +1 -0
  61. package/dist/trusted-list-http.d.ts +1 -0
  62. package/dist/trusted-list-http.esm.js +81 -0
  63. package/dist/trusted-list-http.esm.js.map +1 -0
  64. package/dist/trusted-list.cjs.js +35 -0
  65. package/dist/trusted-list.cjs.js.map +1 -0
  66. package/dist/trusted-list.d.ts +9 -0
  67. package/dist/trusted-list.esm.js +10 -0
  68. package/dist/trusted-list.esm.js.map +1 -0
  69. package/package.json +34 -2
@@ -0,0 +1,571 @@
1
+ /*!
2
+ * MIT License
3
+ * Copyright (c) 2025 Edgars Jēkabsons, ZenomyTech SIA
4
+ */
5
+ 'use strict';
6
+
7
+ var x509 = require('@peculiar/x509');
8
+
9
+ /**
10
+ * Recursive DOM traversal to find elements with a given tag name
11
+ * (Fallback method when XPath is not available or fails)
12
+ *
13
+ * @param parent The parent element to search within
14
+ * @param selector CSS-like selector with namespace support (e.g., "ds:SignedInfo, SignedInfo")
15
+ * @returns Array of matching elements
16
+ */
17
+ function findElementsByTagNameRecursive(parent, selector) {
18
+ const results = [];
19
+ const selectors = selector.split(",").map((s) => s.trim());
20
+ // Parse each selector part to extract namespace and local name
21
+ const parsedSelectors = [];
22
+ for (const sel of selectors) {
23
+ const parts = sel.split(/\\:|:/).filter(Boolean);
24
+ if (parts.length === 1) {
25
+ parsedSelectors.push({ name: parts[0] });
26
+ }
27
+ else if (parts.length === 2) {
28
+ parsedSelectors.push({ ns: parts[0], name: parts[1] });
29
+ }
30
+ }
31
+ // Recursive search function - keep the original node references
32
+ function searchNode(node) {
33
+ if (!node)
34
+ return;
35
+ if (node.nodeType === 1) {
36
+ // Element node - make sure we're working with an actual DOM Element
37
+ const element = node;
38
+ const nodeName = element.nodeName;
39
+ const localName = element.localName;
40
+ // Check if this element matches any of our selectors
41
+ for (const sel of parsedSelectors) {
42
+ // Match by full nodeName (which might include namespace prefix)
43
+ if (sel.ns && nodeName === `${sel.ns}:${sel.name}`) {
44
+ results.push(element); // Store the actual DOM element reference
45
+ break;
46
+ }
47
+ // Match by local name only
48
+ if (localName === sel.name || nodeName === sel.name) {
49
+ results.push(element); // Store the actual DOM element reference
50
+ break;
51
+ }
52
+ // Match by checking if nodeName ends with the local name
53
+ if (nodeName.endsWith(`:${sel.name}`)) {
54
+ results.push(element); // Store the actual DOM element reference
55
+ break;
56
+ }
57
+ }
58
+ }
59
+ // Search all child nodes
60
+ if (node.childNodes) {
61
+ for (let i = 0; i < node.childNodes.length; i++) {
62
+ searchNode(node.childNodes[i]);
63
+ }
64
+ }
65
+ }
66
+ searchNode(parent);
67
+ return results;
68
+ }
69
+ // Known XML namespaces used in XML Signatures and related standards
70
+ const NAMESPACES = {
71
+ ds: "http://www.w3.org/2000/09/xmldsig#",
72
+ dsig11: "http://www.w3.org/2009/xmldsig11#",
73
+ dsig2: "http://www.w3.org/2010/xmldsig2#",
74
+ ec: "http://www.w3.org/2001/10/xml-exc-c14n#",
75
+ dsig_more: "http://www.w3.org/2001/04/xmldsig-more#",
76
+ xenc: "http://www.w3.org/2001/04/xmlenc#",
77
+ xenc11: "http://www.w3.org/2009/xmlenc11#",
78
+ xades: "http://uri.etsi.org/01903/v1.3.2#",
79
+ xades141: "http://uri.etsi.org/01903/v1.4.1#",
80
+ asic: "http://uri.etsi.org/02918/v1.2.1#",
81
+ };
82
+ /**
83
+ * Create an XML parser that works in both browser and Node environments
84
+ */
85
+ function createXMLParser() {
86
+ // Check if we're in a browser environment with native DOM support
87
+ if (typeof window !== "undefined" && window.DOMParser) {
88
+ return new window.DOMParser();
89
+ }
90
+ // We're in Node.js, so use xmldom
91
+ try {
92
+ // Import dynamically to avoid bundling issues
93
+ const { DOMParser } = require("@xmldom/xmldom");
94
+ return new DOMParser();
95
+ }
96
+ catch (e) {
97
+ throw new Error("XML DOM parser not available. In Node.js environments, please install @xmldom/xmldom package.");
98
+ }
99
+ }
100
+ /**
101
+ * Uses XPath to find a single element in an XML document
102
+ *
103
+ * @param parent The parent element or document to search within
104
+ * @param xpathExpression The XPath expression to evaluate
105
+ * @param namespaces Optional namespace mapping (defaults to common XML signature namespaces)
106
+ * @returns The found element or null
107
+ */
108
+ function queryByXPath(parent, xpathExpression, namespaces = NAMESPACES) {
109
+ try {
110
+ // Browser environment with native XPath
111
+ if (typeof document !== "undefined" && typeof document.evaluate === "function") {
112
+ // Use the document that owns the parent node, not the global document
113
+ const ownerDoc = "ownerDocument" in parent ? parent.ownerDocument : parent;
114
+ if (!ownerDoc || typeof ownerDoc.evaluate !== "function") {
115
+ // XMLDocuments from DOMParser don't have evaluate - silently return null
116
+ // (caller should use DOM traversal fallback)
117
+ return null;
118
+ }
119
+ const nsResolver = createNsResolverForBrowser(namespaces);
120
+ const result = ownerDoc.evaluate(xpathExpression, parent, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
121
+ return result.singleNodeValue;
122
+ }
123
+ // Node.js environment with xpath module
124
+ else {
125
+ const xpath = require("xpath");
126
+ const nsResolver = createNsResolverForNode(namespaces);
127
+ // Use a try-catch here to handle specific XPath issues
128
+ try {
129
+ const nodes = xpath.select(xpathExpression, parent, nsResolver);
130
+ return nodes.length > 0 ? nodes[0] : null;
131
+ }
132
+ catch (err) {
133
+ // If we get a namespace error, try a simpler XPath with just local-name()
134
+ if (typeof err === "object" &&
135
+ err !== null &&
136
+ "message" in err &&
137
+ typeof err.message === "string" &&
138
+ err.message.includes("Cannot resolve QName")) {
139
+ // Extract the element name we're looking for from the XPath
140
+ const match = xpathExpression.match(/local-name\(\)='([^']+)'/);
141
+ if (match && match[1]) {
142
+ const elementName = match[1];
143
+ const simplifiedXPath = `.//*[local-name()='${elementName}']`;
144
+ const nodes = xpath.select(simplifiedXPath, parent);
145
+ return nodes.length > 0 ? nodes[0] : null;
146
+ }
147
+ }
148
+ throw err; // Re-throw if we couldn't handle it
149
+ }
150
+ }
151
+ }
152
+ catch (e) {
153
+ console.error(`XPath evaluation failed for "${xpathExpression}":`, e);
154
+ return null;
155
+ }
156
+ }
157
+ /**
158
+ * Uses XPath to find all matching elements in an XML document
159
+ *
160
+ * @param parent The parent element or document to search within
161
+ * @param xpathExpression The XPath expression to evaluate
162
+ * @param namespaces Optional namespace mapping (defaults to common XML signature namespaces)
163
+ * @returns Array of matching elements
164
+ */
165
+ function queryAllByXPath(parent, xpathExpression, namespaces = NAMESPACES) {
166
+ try {
167
+ // Browser environment with native XPath
168
+ if (typeof document !== "undefined" && typeof document.evaluate === "function") {
169
+ // Use the document that owns the parent node, not the global document
170
+ const ownerDoc = "ownerDocument" in parent ? parent.ownerDocument : parent;
171
+ if (!ownerDoc || typeof ownerDoc.evaluate !== "function") {
172
+ // XMLDocuments from DOMParser don't have evaluate - silently return empty
173
+ // (caller should use DOM traversal fallback)
174
+ return [];
175
+ }
176
+ const nsResolver = createNsResolverForBrowser(namespaces);
177
+ const result = ownerDoc.evaluate(xpathExpression, parent, nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
178
+ const elements = [];
179
+ for (let i = 0; i < result.snapshotLength; i++) {
180
+ elements.push(result.snapshotItem(i));
181
+ }
182
+ return elements;
183
+ }
184
+ // Node.js environment with xpath module
185
+ else {
186
+ const xpath = require("xpath");
187
+ const nsResolver = createNsResolverForNode(namespaces);
188
+ // Use a try-catch here to handle specific XPath issues
189
+ try {
190
+ const nodes = xpath.select(xpathExpression, parent, nsResolver);
191
+ return nodes;
192
+ }
193
+ catch (err) {
194
+ // If we get a namespace error, try a simpler XPath with just local-name()
195
+ if (typeof err === "object" &&
196
+ err !== null &&
197
+ "message" in err &&
198
+ typeof err.message === "string" &&
199
+ err.message.includes("Cannot resolve QName")) {
200
+ // Extract the element name we're looking for from the XPath
201
+ const match = xpathExpression.match(/local-name\(\)='([^']+)'/);
202
+ if (match && match[1]) {
203
+ const elementName = match[1];
204
+ const simplifiedXPath = `.//*[local-name()='${elementName}']`;
205
+ const nodes = xpath.select(simplifiedXPath, parent);
206
+ return nodes;
207
+ }
208
+ }
209
+ throw err; // Re-throw if we couldn't handle it
210
+ }
211
+ }
212
+ }
213
+ catch (e) {
214
+ console.error(`XPath evaluation failed for "${xpathExpression}":`, e);
215
+ return [];
216
+ }
217
+ }
218
+ /**
219
+ * Helper function to create a namespace resolver for browser environments
220
+ */
221
+ function createNsResolverForBrowser(namespaces) {
222
+ return function (prefix) {
223
+ if (prefix === null)
224
+ return null;
225
+ return namespaces[prefix] || null;
226
+ };
227
+ }
228
+ /**
229
+ * Helper function to create a namespace resolver for Node.js environments
230
+ */
231
+ function createNsResolverForNode(namespaces) {
232
+ return namespaces;
233
+ }
234
+ /**
235
+ * Converts a CSS-like selector (with namespace support) to an XPath expression
236
+ *
237
+ * @param selector CSS-like selector (e.g., "ds:SignedInfo, SignedInfo")
238
+ * @returns Equivalent XPath expression
239
+ */
240
+ function selectorToXPath(selector) {
241
+ // Split by comma to handle alternative selectors
242
+ const parts = selector.split(",").map((s) => s.trim());
243
+ const xpathParts = [];
244
+ for (const part of parts) {
245
+ // Handle namespaced selectors (both prefix:name and prefix\\:name formats)
246
+ const segments = part.split(/\\:|:/).filter(Boolean);
247
+ if (segments.length === 1) {
248
+ // Simple element name without namespace
249
+ // Match any element with the right local name
250
+ xpathParts.push(`.//*[local-name()='${segments[0]}']`);
251
+ }
252
+ else if (segments.length === 2) {
253
+ // Element with namespace prefix - only use local-name() or specific namespace prefix
254
+ // that we know is registered, avoiding the generic 'ns:' prefix
255
+ xpathParts.push(`.//${segments[0]}:${segments[1]} | .//*[local-name()='${segments[1]}']`);
256
+ }
257
+ }
258
+ // Join with | operator (XPath's OR)
259
+ return xpathParts.join(" | ");
260
+ }
261
+ /**
262
+ * Enhanced querySelector that uses XPath for better namespace handling
263
+ * (Drop-in replacement for the original querySelector function)
264
+ *
265
+ * @param parent The parent element or document to search within
266
+ * @param selector A CSS-like selector (with namespace handling)
267
+ * @returns The found element or null
268
+ */
269
+ function querySelector(parent, selector) {
270
+ // First try native querySelector if we're in a browser
271
+ if (typeof parent.querySelector === "function") {
272
+ try {
273
+ const result = parent.querySelector(selector);
274
+ if (result)
275
+ return result;
276
+ }
277
+ catch (e) {
278
+ // Fallback to XPath if querySelector fails (e.g., due to namespace issues)
279
+ }
280
+ }
281
+ // First try with our enhanced DOM traversal methods (more reliable in some cases)
282
+ const elements = findElementsByTagNameRecursive(parent, selector);
283
+ if (elements.length > 0) {
284
+ return elements[0];
285
+ }
286
+ // Then try XPath as a fallback
287
+ try {
288
+ const xpath = selectorToXPath(selector);
289
+ return queryByXPath(parent, xpath);
290
+ }
291
+ catch (e) {
292
+ console.warn("XPath query failed, using direct DOM traversal as fallback");
293
+ return null;
294
+ }
295
+ }
296
+ /**
297
+ * Enhanced querySelectorAll that uses XPath for better namespace handling
298
+ * (Drop-in replacement for the original querySelectorAll function)
299
+ *
300
+ * @param parent The parent element or document to search within
301
+ * @param selector A CSS-like selector (with namespace handling)
302
+ * @returns Array of matching elements
303
+ */
304
+ function querySelectorAll(parent, selector) {
305
+ // First try native querySelectorAll if we're in a browser
306
+ if (typeof parent.querySelectorAll === "function") {
307
+ try {
308
+ const results = parent.querySelectorAll(selector);
309
+ if (results.length > 0) {
310
+ const elements = [];
311
+ for (let i = 0; i < results.length; i++) {
312
+ elements.push(results[i]);
313
+ }
314
+ return elements;
315
+ }
316
+ }
317
+ catch (e) {
318
+ // Fallback to XPath if querySelectorAll fails (e.g., due to namespace issues)
319
+ }
320
+ }
321
+ // First try with our enhanced DOM traversal methods (more reliable in some cases)
322
+ const elements = findElementsByTagNameRecursive(parent, selector);
323
+ if (elements.length > 0) {
324
+ return elements;
325
+ }
326
+ // Then try XPath as a fallback
327
+ try {
328
+ const xpath = selectorToXPath(selector);
329
+ return queryAllByXPath(parent, xpath);
330
+ }
331
+ catch (e) {
332
+ console.warn("XPath query failed, using direct DOM traversal as fallback");
333
+ return [];
334
+ }
335
+ }
336
+ /**
337
+ * Serialize a DOM node to XML string
338
+ */
339
+ function serializeToXML(node) {
340
+ // Check if we're in a browser environment with native XMLSerializer
341
+ if (typeof window !== "undefined" && window.XMLSerializer) {
342
+ return new window.XMLSerializer().serializeToString(node);
343
+ }
344
+ // If we're using xmldom
345
+ try {
346
+ const { XMLSerializer } = require("@xmldom/xmldom");
347
+ return new XMLSerializer().serializeToString(node);
348
+ }
349
+ catch (e) {
350
+ throw new Error("XML Serializer not available. In Node.js environments, please install @xmldom/xmldom package.");
351
+ }
352
+ }
353
+
354
+ /**
355
+ * Format a certificate string as a proper PEM certificate
356
+ * @param certBase64 Base64-encoded certificate
357
+ * @returns Formatted PEM certificate
358
+ */
359
+ function formatPEM(certBase64) {
360
+ if (!certBase64)
361
+ return "";
362
+ // Remove any whitespace from the base64 string
363
+ const cleanBase64 = certBase64.replace(/\s+/g, "");
364
+ // Split the base64 into lines of 64 characters
365
+ const lines = [];
366
+ for (let i = 0; i < cleanBase64.length; i += 64) {
367
+ lines.push(cleanBase64.substring(i, i + 64));
368
+ }
369
+ // Format as PEM certificate
370
+ return `-----BEGIN CERTIFICATE-----\n${lines.join("\n")}\n-----END CERTIFICATE-----`;
371
+ }
372
+ /**
373
+ * Extract subject information from an X.509 certificate
374
+ * @param certificate X509Certificate instance
375
+ * @returns Signer information object
376
+ */
377
+ function extractSignerInfo(certificate) {
378
+ const result = {
379
+ validFrom: certificate.notBefore,
380
+ validTo: certificate.notAfter,
381
+ issuer: {},
382
+ };
383
+ // Try to extract fields using various approaches
384
+ // Approach 1: Try direct access to typed subject properties
385
+ try {
386
+ if (typeof certificate.subject === "object" && certificate.subject !== null) {
387
+ // Handle subject properties
388
+ const subject = certificate.subject;
389
+ result.commonName = subject.commonName;
390
+ result.organization = subject.organizationName;
391
+ result.country = subject.countryName;
392
+ }
393
+ // Handle issuer properties
394
+ if (typeof certificate.issuer === "object" && certificate.issuer !== null) {
395
+ const issuer = certificate.issuer;
396
+ result.issuer.commonName = issuer.commonName;
397
+ result.issuer.organization = issuer.organizationName;
398
+ result.issuer.country = issuer.countryName;
399
+ }
400
+ }
401
+ catch (e) {
402
+ console.warn("Could not extract subject/issuer as objects:", e);
403
+ }
404
+ // Approach 2: Parse subject/issuer as strings if they are strings
405
+ try {
406
+ if (typeof certificate.subject === "string") {
407
+ const subjectStr = certificate.subject;
408
+ // Parse the string format (usually CN=name,O=org,C=country)
409
+ const subjectParts = subjectStr.split(",");
410
+ for (const part of subjectParts) {
411
+ const [key, value] = part.trim().split("=");
412
+ if (key === "CN")
413
+ result.commonName = result.commonName || value;
414
+ if (key === "O")
415
+ result.organization = result.organization || value;
416
+ if (key === "C")
417
+ result.country = result.country || value;
418
+ if (key === "SN")
419
+ result.surname = value;
420
+ if (key === "G" || key === "GN")
421
+ result.givenName = value;
422
+ if (key === "SERIALNUMBER" || key === "2.5.4.5")
423
+ result.serialNumber = value?.replace("PNOLV-", "");
424
+ }
425
+ }
426
+ if (typeof certificate.issuer === "string") {
427
+ const issuerStr = certificate.issuer;
428
+ // Parse the string format
429
+ const issuerParts = issuerStr.split(",");
430
+ for (const part of issuerParts) {
431
+ const [key, value] = part.trim().split("=");
432
+ if (key === "CN")
433
+ result.issuer.commonName = result.issuer.commonName || value;
434
+ if (key === "O")
435
+ result.issuer.organization = result.issuer.organization || value;
436
+ if (key === "C")
437
+ result.issuer.country = result.issuer.country || value;
438
+ }
439
+ }
440
+ }
441
+ catch (e) {
442
+ console.warn("Could not extract subject/issuer as strings:", e);
443
+ }
444
+ // Approach 3: Try to use getField method if available
445
+ try {
446
+ if ("subjectName" in certificate && certificate.subjectName?.getField) {
447
+ const subjectName = certificate.subjectName;
448
+ // Only set if not already set from previous approaches
449
+ result.commonName = result.commonName || subjectName.getField("CN")?.[0];
450
+ result.surname = result.surname || subjectName.getField("SN")?.[0];
451
+ result.givenName = result.givenName || subjectName.getField("G")?.[0];
452
+ result.serialNumber =
453
+ result.serialNumber || subjectName.getField("2.5.4.5")?.[0]?.replace("PNOLV-", "");
454
+ result.country = result.country || subjectName.getField("C")?.[0];
455
+ result.organization = result.organization || subjectName.getField("O")?.[0];
456
+ }
457
+ }
458
+ catch (e) {
459
+ console.warn("Could not extract fields using getField method:", e);
460
+ }
461
+ // Get the serial number from the certificate if not found in subject
462
+ if (!result.serialNumber && certificate.serialNumber) {
463
+ result.serialNumber = certificate.serialNumber;
464
+ }
465
+ return result;
466
+ }
467
+ /**
468
+ * Parse a certificate from base64 data
469
+ * @param certData Base64-encoded certificate data
470
+ * @returns Parsed certificate information
471
+ */
472
+ async function parseCertificate(certData) {
473
+ try {
474
+ let pemCert = certData;
475
+ // Check if it's already in PEM format, if not, convert it
476
+ if (!certData.includes("-----BEGIN CERTIFICATE-----")) {
477
+ // Only clean non-PEM format data before conversion
478
+ const cleanedCertData = certData.replace(/[\r\n\s]/g, "");
479
+ pemCert = formatPEM(cleanedCertData);
480
+ }
481
+ const cert = new x509.X509Certificate(pemCert);
482
+ const signerInfo = extractSignerInfo(cert);
483
+ return {
484
+ subject: {
485
+ commonName: signerInfo.commonName,
486
+ organization: signerInfo.organization,
487
+ country: signerInfo.country,
488
+ surname: signerInfo.surname,
489
+ givenName: signerInfo.givenName,
490
+ serialNumber: signerInfo.serialNumber,
491
+ },
492
+ validFrom: signerInfo.validFrom,
493
+ validTo: signerInfo.validTo,
494
+ issuer: signerInfo.issuer,
495
+ serialNumber: cert.serialNumber,
496
+ };
497
+ }
498
+ catch (error) {
499
+ console.error("Certificate parsing error:", error);
500
+ throw new Error("Failed to parse certificate: " + (error instanceof Error ? error.message : String(error)));
501
+ }
502
+ }
503
+ /**
504
+ * Check if a certificate was valid at a specific time
505
+ * @param cert Certificate object or info
506
+ * @param checkTime The time to check validity against (defaults to current time)
507
+ * @returns Validity check result
508
+ */
509
+ function checkCertificateValidity(cert, checkTime = new Date()) {
510
+ // Extract validity dates based on input type
511
+ const validFrom = "notBefore" in cert ? cert.notBefore : cert.validFrom;
512
+ const validTo = "notAfter" in cert ? cert.notAfter : cert.validTo;
513
+ // Check if certificate is valid at the specified time
514
+ if (checkTime < validFrom) {
515
+ return {
516
+ isValid: false,
517
+ reason: `Certificate not yet valid. Valid from ${validFrom.toISOString()}`,
518
+ };
519
+ }
520
+ if (checkTime > validTo) {
521
+ return {
522
+ isValid: false,
523
+ reason: `Certificate expired. Valid until ${validTo.toISOString()}`,
524
+ };
525
+ }
526
+ return { isValid: true };
527
+ }
528
+ /**
529
+ * Helper function to get signer display name from certificate
530
+ * @param certInfo Certificate information
531
+ * @returns Formatted display name
532
+ */
533
+ function getSignerDisplayName(certInfo) {
534
+ const { subject } = certInfo;
535
+ if (subject.givenName && subject.surname) {
536
+ return `${subject.givenName} ${subject.surname}`;
537
+ }
538
+ if (subject.commonName) {
539
+ return subject.commonName;
540
+ }
541
+ // Fallback to serial number if available
542
+ return subject.serialNumber || "Unknown Signer";
543
+ }
544
+ /**
545
+ * Helper function to format certificate validity period in a human-readable format
546
+ * @param certInfo Certificate information
547
+ * @returns Formatted validity period
548
+ */
549
+ function formatValidityPeriod(certInfo) {
550
+ const { validFrom, validTo } = certInfo;
551
+ const formatDate = (date) => {
552
+ return date.toLocaleDateString(undefined, {
553
+ year: "numeric",
554
+ month: "long",
555
+ day: "numeric",
556
+ });
557
+ };
558
+ return `${formatDate(validFrom)} to ${formatDate(validTo)}`;
559
+ }
560
+
561
+ exports.checkCertificateValidity = checkCertificateValidity;
562
+ exports.createXMLParser = createXMLParser;
563
+ exports.extractSignerInfo = extractSignerInfo;
564
+ exports.formatPEM = formatPEM;
565
+ exports.formatValidityPeriod = formatValidityPeriod;
566
+ exports.getSignerDisplayName = getSignerDisplayName;
567
+ exports.parseCertificate = parseCertificate;
568
+ exports.querySelector = querySelector;
569
+ exports.querySelectorAll = querySelectorAll;
570
+ exports.serializeToXML = serializeToXML;
571
+ //# sourceMappingURL=certificate-fc0e06f7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"certificate-fc0e06f7.js","sources":["../src/utils/xmlParser.ts","../src/core/certificate.ts"],"sourcesContent":[null,null],"names":["X509Certificate"],"mappings":";;;;;;;;AAAA;;;;;;;AAOG;AACa,SAAA,8BAA8B,CAAC,MAAY,EAAE,QAAgB,EAAA;IAC3E,MAAM,OAAO,GAAc,EAAE,CAAC;IAC9B,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;;IAG3D,MAAM,eAAe,GAAyC,EAAE,CAAC;AACjE,IAAA,KAAK,MAAM,GAAG,IAAI,SAAS,EAAE;AAC3B,QAAA,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACjD,QAAA,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,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oC,iCAAA,EAAA,OAAO,CAAC,WAAW,EAAE,CAAE,CAAA;SACpE,CAAC;KACH;AAED,IAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC;AAyBD;;;;AAIG;AACG,SAAU,oBAAoB,CAAC,QAAyB,EAAA;AAC5D,IAAA,MAAM,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;IAE7B,IAAI,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,OAAO,EAAE;QACxC,OAAO,CAAA,EAAG,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,OAAO,CAAA,CAAE,CAAC;KAClD;AAED,IAAA,IAAI,OAAO,CAAC,UAAU,EAAE;QACtB,OAAO,OAAO,CAAC,UAAU,CAAC;KAC3B;;AAGD,IAAA,OAAO,OAAO,CAAC,YAAY,IAAI,gBAAgB,CAAC;AAClD,CAAC;AAED;;;;AAIG;AACG,SAAU,oBAAoB,CAAC,QAAyB,EAAA;AAC5D,IAAA,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;AAExC,IAAA,MAAM,UAAU,GAAG,CAAC,IAAU,KAAI;AAChC,QAAA,OAAO,IAAI,CAAC,kBAAkB,CAAC,SAAS,EAAE;AACxC,YAAA,IAAI,EAAE,SAAS;AACf,YAAA,KAAK,EAAE,MAAM;AACb,YAAA,GAAG,EAAE,SAAS;AACf,SAAA,CAAC,CAAC;AACL,KAAC,CAAC;IAEF,OAAO,CAAA,EAAG,UAAU,CAAC,SAAS,CAAC,CAAO,IAAA,EAAA,UAAU,CAAC,OAAO,CAAC,CAAA,CAAE,CAAC;AAC9D;;;;;;;;;;;;;"}
@@ -8,8 +8,11 @@ interface CanonMethod {
8
8
  declare const CANONICALIZATION_METHODS: {
9
9
  default: string;
10
10
  "http://www.w3.org/TR/2001/REC-xml-c14n-20010315": string;
11
+ "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments": string;
11
12
  "http://www.w3.org/2006/12/xml-c14n11": string;
13
+ "http://www.w3.org/2006/12/xml-c14n11#WithComments": string;
12
14
  "http://www.w3.org/2001/10/xml-exc-c14n#": string;
15
+ "http://www.w3.org/2001/10/xml-exc-c14n#WithComments": string;
13
16
  };
14
17
  declare const NODE_TYPES: {
15
18
  ELEMENT_NODE: number;
@@ -19,6 +22,10 @@ interface ExcC14NOptions {
19
22
  inclusiveNamespacePrefixList?: string[];
20
23
  isStartingNode?: boolean;
21
24
  }
25
+ interface CanonicalizeOptions {
26
+ inclusiveNamespacePrefixList?: string[];
27
+ isStartingNode?: boolean;
28
+ }
22
29
  interface WhitespaceInfo {
23
30
  hasMixedContent?: boolean;
24
31
  hasExistingLinebreaks?: boolean;
@@ -39,9 +46,8 @@ declare class XMLCanonicalizer {
39
46
  static collectUsedNamespaces(node: Node, allVisibleNamespaces?: Map<string, string>, inclusivePrefixList?: string[]): Map<string, string>;
40
47
  static isBase64Element(node: Node): boolean;
41
48
  static analyzeWhitespace(node: Node): void;
42
- canonicalize(node: NodeWithWhitespace, visibleNamespaces?: Map<string, string>, options?: {
43
- isStartingNode: boolean;
44
- }): string;
49
+ canonicalize(node: NodeWithWhitespace, visibleNamespaces?: Map<string, string>, options?: CanonicalizeOptions): string;
50
+ private canonicalizeStandard;
45
51
  canonicalizeExclusive(node: NodeWithWhitespace, visibleNamespaces?: Map<string, string>, options?: ExcC14NOptions): string;
46
52
  static c14n(node: Node): string;
47
53
  static c14n11(node: Node): string;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * RSA DigestInfo Workaround
3
+ *
4
+ * Some older signing tools (particularly pre-Java 8) produced RSA signatures with
5
+ * non-standard DigestInfo format - missing the NULL parameter in AlgorithmIdentifier.
6
+ *
7
+ * Standard DigestInfo for SHA-1: 30 21 30 09 06 05 2b0e03021a 05 00 04 14 [hash]
8
+ * Non-standard (missing NULL): 30 1f 30 07 06 05 2b0e03021a 04 14 [hash]
9
+ *
10
+ * Web Crypto API's subtle.verify() is strict and rejects the non-standard format.
11
+ * This module provides a fallback that manually performs RSA verification using
12
+ * BigInt math, which works in both browser and Node.js environments.
13
+ */
14
+ /**
15
+ * Verify RSA signature with non-standard DigestInfo format.
16
+ *
17
+ * This function performs RSA signature verification that tolerates
18
+ * non-standard DigestInfo formats (missing NULL in AlgorithmIdentifier).
19
+ *
20
+ * - Node.js: Uses native crypto.publicDecrypt() for speed
21
+ * - Browser: Uses BigInt math (Web Crypto doesn't expose raw RSA)
22
+ *
23
+ * @param publicKeyData SPKI-formatted public key
24
+ * @param signatureBytes Raw signature bytes
25
+ * @param dataToVerify The data that was signed
26
+ * @param hashAlgorithm Hash algorithm name (e.g., "SHA-1", "SHA-256")
27
+ * @returns true if signature is valid, false otherwise
28
+ */
29
+ export declare function verifyRsaWithNonStandardDigestInfo(publicKeyData: ArrayBuffer, signatureBytes: Uint8Array, dataToVerify: Uint8Array, hashAlgorithm: string): Promise<boolean>;