@sphereon/ssi-sdk-ext.x509-utils 0.28.1-feature.esm.cjs.9 → 0.28.1-feature.jose.vcdm.20

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/dist/index.cjs CHANGED
@@ -1,11 +1,71 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __defProp = Object.defineProperty;
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
2
8
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
4
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
5
- }) : x)(function(x) {
6
- if (typeof require !== "undefined") return require.apply(this, arguments);
7
- throw Error('Dynamic require of "' + x + '" is not supported');
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/index.ts
32
+ var index_exports = {};
33
+ __export(index_exports, {
34
+ JwkKeyUse: () => JwkKeyUse,
35
+ PEMToBinary: () => PEMToBinary,
36
+ PEMToDer: () => PEMToDer,
37
+ PEMToHex: () => PEMToHex,
38
+ PEMToJwk: () => PEMToJwk,
39
+ RSASigner: () => RSASigner,
40
+ SubjectAlternativeGeneralName: () => SubjectAlternativeGeneralName,
41
+ areCertificatesEqual: () => areCertificatesEqual,
42
+ assertCertificateMatchesClientIdScheme: () => assertCertificateMatchesClientIdScheme,
43
+ base64ToHex: () => base64ToHex,
44
+ cryptoSubtleImportRSAKey: () => cryptoSubtleImportRSAKey,
45
+ derToPEM: () => derToPEM,
46
+ generateRSAKeyAsPEM: () => generateRSAKeyAsPEM,
47
+ getCertificateInfo: () => getCertificateInfo,
48
+ getCertificateSubjectPublicKeyJWK: () => getCertificateSubjectPublicKeyJWK,
49
+ getIssuerDN: () => getIssuerDN,
50
+ getSubjectAlternativeNames: () => getSubjectAlternativeNames,
51
+ getSubjectDN: () => getSubjectDN,
52
+ getX509AlgorithmProvider: () => getX509AlgorithmProvider,
53
+ hexKeyFromPEMBasedJwk: () => hexKeyFromPEMBasedJwk,
54
+ hexToBase64: () => hexToBase64,
55
+ hexToPEM: () => hexToPEM,
56
+ jwkToPEM: () => jwkToPEM,
57
+ parseCertificate: () => parseCertificate,
58
+ pemCertChainTox5c: () => pemCertChainTox5c,
59
+ pemOrDerToX509Certificate: () => pemOrDerToX509Certificate,
60
+ privateKeyHexFromPEM: () => privateKeyHexFromPEM,
61
+ publicKeyHexFromPEM: () => publicKeyHexFromPEM,
62
+ signAlgorithmToSchemeAndHashAlg: () => signAlgorithmToSchemeAndHashAlg,
63
+ toKeyObject: () => toKeyObject,
64
+ validateCertificateChainMatchesClientIdScheme: () => validateCertificateChainMatchesClientIdScheme,
65
+ validateX509CertificateChain: () => validateX509CertificateChain,
66
+ x5cToPemCertChain: () => x5cToPemCertChain
8
67
  });
68
+ module.exports = __toCommonJS(index_exports);
9
69
 
10
70
  // src/types/index.ts
11
71
  var JwkKeyUse = /* @__PURE__ */ function(JwkKeyUse2) {
@@ -15,7 +75,7 @@ var JwkKeyUse = /* @__PURE__ */ function(JwkKeyUse2) {
15
75
  }({});
16
76
 
17
77
  // src/x509/rsa-key.ts
18
- var _tostring = require('uint8arrays/to-string');
78
+ var u8a2 = __toESM(require("uint8arrays"), 1);
19
79
 
20
80
  // src/x509/crypto.ts
21
81
  var globalCrypto = /* @__PURE__ */ __name((setGlobal, suppliedCrypto) => {
@@ -27,10 +87,10 @@ var globalCrypto = /* @__PURE__ */ __name((setGlobal, suppliedCrypto) => {
27
87
  } else if (typeof global.crypto !== "undefined") {
28
88
  webcrypto = global.crypto;
29
89
  } else {
30
- if (typeof _optionalChain([global, 'access', _ => _.window, 'optionalAccess', _2 => _2.crypto, 'optionalAccess', _3 => _3.subtle]) !== "undefined") {
90
+ if (typeof global.window?.crypto?.subtle !== "undefined") {
31
91
  webcrypto = global.window.crypto;
32
92
  } else {
33
- webcrypto = __require("crypto");
93
+ webcrypto = require("crypto");
34
94
  }
35
95
  }
36
96
  if (setGlobal) {
@@ -40,10 +100,10 @@ var globalCrypto = /* @__PURE__ */ __name((setGlobal, suppliedCrypto) => {
40
100
  }, "globalCrypto");
41
101
 
42
102
  // src/x509/x509-utils.ts
43
- var _pkijs = require('pkijs');
44
- var _fromstring = require('uint8arrays/from-string');
45
-
46
- var _keyto = require('@trust/keyto'); var _keyto2 = _interopRequireDefault(_keyto);
103
+ var import_pkijs = require("pkijs");
104
+ var u8a = __toESM(require("uint8arrays"), 1);
105
+ var import_keyto = __toESM(require("@trust/keyto"), 1);
106
+ var { fromString, toString } = u8a;
47
107
  function pemCertChainTox5c(cert, maxDepth) {
48
108
  if (!maxDepth) {
49
109
  maxDepth = 0;
@@ -73,16 +133,16 @@ __name(x5cToPemCertChain, "x5cToPemCertChain");
73
133
  var pemOrDerToX509Certificate = /* @__PURE__ */ __name((cert) => {
74
134
  let DER = typeof cert === "string" ? cert : void 0;
75
135
  if (typeof cert === "object" && !(cert instanceof Uint8Array)) {
76
- return _pkijs.Certificate.fromBER(cert.rawData);
136
+ return import_pkijs.Certificate.fromBER(cert.rawData);
77
137
  } else if (typeof cert !== "string") {
78
- return _pkijs.Certificate.fromBER(cert);
138
+ return import_pkijs.Certificate.fromBER(cert);
79
139
  } else if (cert.includes("CERTIFICATE")) {
80
140
  DER = PEMToDer(cert);
81
141
  }
82
142
  if (!DER) {
83
143
  throw Error("Invalid cert input value supplied. PEM, DER, Bytes and X509Certificate object are supported");
84
144
  }
85
- return _pkijs.Certificate.fromBER(_fromstring.fromString.call(void 0, DER, "base64pad"));
145
+ return import_pkijs.Certificate.fromBER(fromString(DER, "base64pad"));
86
146
  }, "pemOrDerToX509Certificate");
87
147
  var areCertificatesEqual = /* @__PURE__ */ __name((cert1, cert2) => {
88
148
  return cert1.signatureValue.isEqual(cert2.signatureValue);
@@ -99,10 +159,10 @@ var toKeyObject = /* @__PURE__ */ __name((PEM, visibility = "public") => {
99
159
  };
100
160
  }, "toKeyObject");
101
161
  var jwkToPEM = /* @__PURE__ */ __name((jwk, visibility = "public") => {
102
- return _keyto2.default.from(jwk, "jwk").toString("pem", visibility === "public" ? "public_pkcs8" : "private_pkcs8");
162
+ return import_keyto.default.from(jwk, "jwk").toString("pem", visibility === "public" ? "public_pkcs8" : "private_pkcs8");
103
163
  }, "jwkToPEM");
104
164
  var PEMToJwk = /* @__PURE__ */ __name((pem, visibility = "public") => {
105
- return _keyto2.default.from(pem, "pem").toJwk(visibility);
165
+ return import_keyto.default.from(pem, "pem").toJwk(visibility);
106
166
  }, "PEMToJwk");
107
167
  var privateKeyHexFromPEM = /* @__PURE__ */ __name((PEM) => {
108
168
  return PEMToHex(PEM);
@@ -141,19 +201,19 @@ var PEMToHex = /* @__PURE__ */ __name((PEM, headerKey) => {
141
201
  }, "PEMToHex");
142
202
  function PEMToBinary(pem) {
143
203
  const pemContents = pem.replace(/^[^]*-----BEGIN [^-]+-----/, "").replace(/-----END [^-]+-----[^]*$/, "").replace(/\s/g, "");
144
- return _fromstring.fromString.call(void 0, pemContents, "base64pad");
204
+ return fromString(pemContents, "base64pad");
145
205
  }
146
206
  __name(PEMToBinary, "PEMToBinary");
147
207
  var base64ToHex = /* @__PURE__ */ __name((input, inputEncoding) => {
148
208
  const base64NoNewlines = input.replace(/[^0-9A-Za-z_\-~\/+=]*/g, "");
149
- return _tostring.toString.call(void 0, _fromstring.fromString.call(void 0, base64NoNewlines, inputEncoding ? inputEncoding : "base64pad"), "base16");
209
+ return toString(fromString(base64NoNewlines, inputEncoding ? inputEncoding : "base64pad"), "base16");
150
210
  }, "base64ToHex");
151
211
  var hexToBase64 = /* @__PURE__ */ __name((input, targetEncoding) => {
152
212
  let hex = typeof input === "string" ? input : input.toString(16);
153
213
  if (hex.length % 2 === 1) {
154
214
  hex = `0${hex}`;
155
215
  }
156
- return _tostring.toString.call(void 0, _fromstring.fromString.call(void 0, hex, "base16"), targetEncoding ? targetEncoding : "base64pad");
216
+ return toString(fromString(hex, "base16"), targetEncoding ? targetEncoding : "base64pad");
157
217
  }, "hexToBase64");
158
218
  var hexToPEM = /* @__PURE__ */ __name((hex, type) => {
159
219
  const base64 = hexToBase64(hex, "base64pad");
@@ -174,7 +234,7 @@ function PEMToDer(pem) {
174
234
  }
175
235
  __name(PEMToDer, "PEMToDer");
176
236
  function derToPEM(cert, headerKey) {
177
- const key = _nullishCoalesce(headerKey, () => ( "CERTIFICATE"));
237
+ const key = headerKey ?? "CERTIFICATE";
178
238
  if (cert.includes(key)) {
179
239
  return cert;
180
240
  }
@@ -190,6 +250,7 @@ ${matches.join("\n")}
190
250
  __name(derToPEM, "derToPEM");
191
251
 
192
252
  // src/x509/rsa-key.ts
253
+ var { toString: toString2 } = u8a2;
193
254
  var usage = /* @__PURE__ */ __name((jwk) => {
194
255
  if (jwk.key_ops && jwk.key_ops.length > 0) {
195
256
  return jwk.key_ops;
@@ -207,13 +268,13 @@ var usage = /* @__PURE__ */ __name((jwk) => {
207
268
  }
208
269
  if (jwk.kty === "RSA") {
209
270
  if (jwk.d) {
210
- return _optionalChain([jwk, 'access', _4 => _4.alg, 'optionalAccess', _5 => _5.toUpperCase, 'call', _6 => _6(), 'optionalAccess', _7 => _7.includes, 'call', _8 => _8("QAEP")]) ? [
271
+ return jwk.alg?.toUpperCase()?.includes("QAEP") ? [
211
272
  "encrypt"
212
273
  ] : [
213
274
  "sign"
214
275
  ];
215
276
  }
216
- return _optionalChain([jwk, 'access', _9 => _9.alg, 'optionalAccess', _10 => _10.toUpperCase, 'call', _11 => _11(), 'optionalAccess', _12 => _12.includes, 'call', _13 => _13("QAEP")]) ? [
277
+ return jwk.alg?.toUpperCase()?.includes("QAEP") ? [
217
278
  "decrypt"
218
279
  ] : [
219
280
  "verify"
@@ -274,20 +335,20 @@ var generateRSAKeyAsPEM = /* @__PURE__ */ __name(async (scheme, hashAlgorithm, m
274
335
  const keypair = await globalCrypto(false).subtle.generateKey(params, true, keyUsage);
275
336
  const pkcs8 = await globalCrypto(false).subtle.exportKey("pkcs8", keypair.privateKey);
276
337
  const uint8Array = new Uint8Array(pkcs8);
277
- return derToPEM(_tostring.toString.call(void 0, uint8Array, "base64pad"), "RSA PRIVATE KEY");
338
+ return derToPEM(toString2(uint8Array, "base64pad"), "RSA PRIVATE KEY");
278
339
  }, "generateRSAKeyAsPEM");
279
340
 
280
341
  // src/x509/rsa-signer.ts
281
-
282
-
342
+ var u8a3 = __toESM(require("uint8arrays"), 1);
343
+ var { fromString: fromString2, toString: toString3 } = u8a3;
283
344
  var RSASigner = class {
284
345
  static {
285
346
  __name(this, "RSASigner");
286
347
  }
287
-
288
-
289
-
290
-
348
+ hashAlgorithm;
349
+ jwk;
350
+ key;
351
+ scheme;
291
352
  /**
292
353
  *
293
354
  * @param key Either in PEM or JWK format (no raw hex keys here!)
@@ -295,12 +356,12 @@ var RSASigner = class {
295
356
  */
296
357
  constructor(key, opts) {
297
358
  if (typeof key === "string") {
298
- this.jwk = PEMToJwk(key, _optionalChain([opts, 'optionalAccess', _14 => _14.visibility]));
359
+ this.jwk = PEMToJwk(key, opts?.visibility);
299
360
  } else {
300
361
  this.jwk = key;
301
362
  }
302
- this.hashAlgorithm = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _15 => _15.hashAlgorithm]), () => ( "SHA-256"));
303
- this.scheme = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _16 => _16.scheme]), () => ( "RSA-PSS"));
363
+ this.hashAlgorithm = opts?.hashAlgorithm ?? "SHA-256";
364
+ this.scheme = opts?.scheme ?? "RSA-PSS";
304
365
  }
305
366
  getImportParams() {
306
367
  if (this.scheme === "RSA-PSS") {
@@ -322,7 +383,7 @@ var RSASigner = class {
322
383
  }
323
384
  bufferToString(buf) {
324
385
  const uint8Array = new Uint8Array(buf);
325
- return _tostring.toString.call(void 0, uint8Array, "base64url");
386
+ return toString3(uint8Array, "base64url");
326
387
  }
327
388
  async sign(data) {
328
389
  const input = data;
@@ -335,7 +396,7 @@ var RSASigner = class {
335
396
  }
336
397
  async verify(data, signature) {
337
398
  const jws = signature.includes(".") ? signature.split(".")[2] : signature;
338
- const input = typeof data == "string" ? _fromstring.fromString.call(void 0, data, "utf-8") : data;
399
+ const input = typeof data == "string" ? fromString2(data, "utf-8") : data;
339
400
  let key = await this.getKey();
340
401
  if (!key.usages.includes("verify")) {
341
402
  const verifyJwk = {
@@ -346,27 +407,27 @@ var RSASigner = class {
346
407
  delete verifyJwk.key_ops;
347
408
  key = await cryptoSubtleImportRSAKey(verifyJwk, this.scheme, this.hashAlgorithm);
348
409
  }
349
- const verificationResult = await globalCrypto(false).subtle.verify(this.getImportParams(), key, _fromstring.fromString.call(void 0, jws, "base64url"), input);
410
+ const verificationResult = await globalCrypto(false).subtle.verify(this.getImportParams(), key, fromString2(jws, "base64url"), input);
350
411
  return verificationResult;
351
412
  }
352
413
  };
353
414
 
354
415
  // src/x509/x509-validator.ts
355
- var _asn1schema = require('@peculiar/asn1-schema');
356
- var _asn1x509 = require('@peculiar/asn1-x509');
357
- var _x509 = require('@peculiar/x509');
358
- var _jsx509utils = require('js-x509-utils'); var _jsx509utils2 = _interopRequireDefault(_jsx509utils);
359
-
360
- var _tsyringe = require('tsyringe');
361
-
362
-
416
+ var import_asn1_schema = require("@peculiar/asn1-schema");
417
+ var import_asn1_x509 = require("@peculiar/asn1-x509");
418
+ var import_x509 = require("@peculiar/x509");
419
+ var import_js_x509_utils = __toESM(require("js-x509-utils"), 1);
420
+ var import_pkijs2 = require("pkijs");
421
+ var import_tsyringe = require("tsyringe");
422
+ var u8a4 = __toESM(require("uint8arrays"), 1);
423
+ var { fromString: fromString3, toString: toString4 } = u8a4;
363
424
  var defaultCryptoEngine = /* @__PURE__ */ __name(() => {
364
425
  const name = "crypto";
365
- _pkijs.setEngine.call(void 0, name, new (0, _pkijs.CryptoEngine)({
426
+ (0, import_pkijs2.setEngine)(name, new import_pkijs2.CryptoEngine({
366
427
  name,
367
428
  crypto: globalCrypto(false)
368
429
  }));
369
- return _pkijs.getCrypto.call(void 0, true);
430
+ return (0, import_pkijs2.getCrypto)(true);
370
431
  }, "defaultCryptoEngine");
371
432
  var getCertificateInfo = /* @__PURE__ */ __name(async (certificate, opts) => {
372
433
  let publicKeyJWK;
@@ -381,7 +442,7 @@ var getCertificateInfo = /* @__PURE__ */ __name(async (certificate, opts) => {
381
442
  subject: {
382
443
  dn: getSubjectDN(certificate),
383
444
  subjectAlternativeNames: getSubjectAlternativeNames(certificate, {
384
- typeFilter: _optionalChain([opts, 'optionalAccess', _17 => _17.sanTypeFilter])
445
+ typeFilter: opts?.sanTypeFilter
385
446
  })
386
447
  },
387
448
  publicKeyJWK,
@@ -429,14 +490,14 @@ var validateX509CertificateChainImpl = /* @__PURE__ */ __name(async ({ reversed,
429
490
  ...chain
430
491
  ].reverse();
431
492
  const trustedCerts = trustedPEMs ? await Promise.all(trustedPEMs.map((raw) => parseCertificate(raw))) : void 0;
432
- const blindlyTrusted = await _asyncNullishCoalesce((await Promise.all(blindlyTrustedAnchors.map((raw) => {
493
+ const blindlyTrusted = (await Promise.all(blindlyTrustedAnchors.map((raw) => {
433
494
  try {
434
495
  return parseCertificate(raw);
435
496
  } catch (e) {
436
497
  console.log(`Failed to parse blindly trusted certificate ${raw}. Error: ${e.message}`);
437
498
  return void 0;
438
499
  }
439
- }))).filter((cert) => cert !== void 0), async () => ( []));
500
+ }))).filter((cert) => cert !== void 0) ?? [];
440
501
  const leafCert = x5cOrdereredChain[0];
441
502
  const chainLength = chain.length;
442
503
  var foundTrustAnchor = void 0;
@@ -451,7 +512,7 @@ var validateX509CertificateChainImpl = /* @__PURE__ */ __name(async ({ reversed,
451
512
  critical: false,
452
513
  message: `Certificate chain validation success as single cert if blindly trusted. WARNING: ONLY USE FOR TESTING PURPOSES.`,
453
514
  detailMessage: `Blindly trusted certificate ${blindlyTrustedCert.certificateInfo.subject.dn.DN} was found in the chain.`,
454
- trustAnchor: _optionalChain([blindlyTrustedCert, 'optionalAccess', _18 => _18.certificateInfo]),
515
+ trustAnchor: blindlyTrustedCert?.certificateInfo,
455
516
  verificationTime,
456
517
  certificateChain: x5cOrdereredChain.map((cert) => cert.certificateInfo),
457
518
  ...client && {
@@ -477,7 +538,7 @@ var validateX509CertificateChainImpl = /* @__PURE__ */ __name(async ({ reversed,
477
538
  critical: true,
478
539
  certificateChain: x5cOrdereredChain.map((cert) => cert.certificateInfo),
479
540
  message: `Certificate chain validation failed for ${leafCert.certificateInfo.subject.dn.DN}.`,
480
- detailMessage: `The certificate ${currentCert.certificateInfo.subject.dn.DN} with issuer ${currentCert.x509Certificate.issuer}, is not signed by the previous certificate ${_optionalChain([previousCert, 'optionalAccess', _19 => _19.certificateInfo, 'access', _20 => _20.subject, 'access', _21 => _21.dn, 'access', _22 => _22.DN])} with subject string ${_optionalChain([previousCert, 'optionalAccess', _23 => _23.x509Certificate, 'access', _24 => _24.subject])}.`,
541
+ detailMessage: `The certificate ${currentCert.certificateInfo.subject.dn.DN} with issuer ${currentCert.x509Certificate.issuer}, is not signed by the previous certificate ${previousCert?.certificateInfo.subject.dn.DN} with subject string ${previousCert?.x509Certificate.subject}.`,
481
542
  verificationTime,
482
543
  ...client && {
483
544
  client
@@ -487,8 +548,8 @@ var validateX509CertificateChainImpl = /* @__PURE__ */ __name(async ({ reversed,
487
548
  }
488
549
  const result = await currentCert.x509Certificate.verify({
489
550
  date: verificationTime,
490
- publicKey: _optionalChain([previousCert, 'optionalAccess', _25 => _25.x509Certificate, 'optionalAccess', _26 => _26.publicKey])
491
- }, _nullishCoalesce(_nullishCoalesce(_optionalChain([_pkijs.getCrypto.call(void 0, ), 'optionalAccess', _27 => _27.crypto]), () => ( crypto)), () => ( global.crypto)));
551
+ publicKey: previousCert?.x509Certificate?.publicKey
552
+ }, (0, import_pkijs2.getCrypto)()?.crypto ?? crypto ?? global.crypto);
492
553
  if (!result) {
493
554
  if (i == 0 && !reversed && !disallowReversedChain) {
494
555
  return await validateX509CertificateChainImpl({
@@ -513,14 +574,14 @@ var validateX509CertificateChainImpl = /* @__PURE__ */ __name(async ({ reversed,
513
574
  }
514
575
  };
515
576
  }
516
- foundTrustAnchor = _nullishCoalesce(foundTrustAnchor, () => ( _optionalChain([trustedCerts, 'optionalAccess', _28 => _28.find, 'call', _29 => _29((trusted) => isSameCertificate(trusted.x509Certificate, currentCert.x509Certificate))])));
577
+ foundTrustAnchor = foundTrustAnchor ?? trustedCerts?.find((trusted) => isSameCertificate(trusted.x509Certificate, currentCert.x509Certificate));
517
578
  if (i === 0 && chainLength === 1 && allowSingleNoCAChainElement) {
518
579
  return {
519
580
  error: false,
520
581
  critical: false,
521
582
  message: `Certificate chain succeeded as allow single cert result is allowed: ${leafCert.certificateInfo.subject.dn.DN}.`,
522
583
  certificateChain: x5cOrdereredChain.map((cert) => cert.certificateInfo),
523
- trustAnchor: _optionalChain([foundTrustAnchor, 'optionalAccess', _30 => _30.certificateInfo]),
584
+ trustAnchor: foundTrustAnchor?.certificateInfo,
524
585
  verificationTime,
525
586
  ...client && {
526
587
  client
@@ -528,14 +589,14 @@ var validateX509CertificateChainImpl = /* @__PURE__ */ __name(async ({ reversed,
528
589
  };
529
590
  }
530
591
  }
531
- if (_optionalChain([foundTrustAnchor, 'optionalAccess', _31 => _31.certificateInfo]) || allowNoTrustAnchorsFound) {
592
+ if (foundTrustAnchor?.certificateInfo || allowNoTrustAnchorsFound) {
532
593
  return {
533
594
  error: false,
534
595
  critical: false,
535
596
  message: `Certificate chain was valid`,
536
597
  certificateChain: x5cOrdereredChain.map((cert) => cert.certificateInfo),
537
- detailMessage: foundTrustAnchor ? `The leaf certificate ${leafCert.certificateInfo.subject.dn.DN} is part of a chain with trust anchor ${_optionalChain([foundTrustAnchor, 'optionalAccess', _32 => _32.certificateInfo, 'access', _33 => _33.subject, 'access', _34 => _34.dn, 'access', _35 => _35.DN])}.` : `The leaf certificate ${leafCert.certificateInfo.subject.dn.DN} and chain were valid, but no trust anchor has been found. Ignoring as user allowed (allowNoTrustAnchorsFound: ${allowNoTrustAnchorsFound}).)`,
538
- trustAnchor: _optionalChain([foundTrustAnchor, 'optionalAccess', _36 => _36.certificateInfo]),
598
+ detailMessage: foundTrustAnchor ? `The leaf certificate ${leafCert.certificateInfo.subject.dn.DN} is part of a chain with trust anchor ${foundTrustAnchor?.certificateInfo.subject.dn.DN}.` : `The leaf certificate ${leafCert.certificateInfo.subject.dn.DN} and chain were valid, but no trust anchor has been found. Ignoring as user allowed (allowNoTrustAnchorsFound: ${allowNoTrustAnchorsFound}).)`,
599
+ trustAnchor: foundTrustAnchor?.certificateInfo,
539
600
  verificationTime,
540
601
  ...client && {
541
602
  client
@@ -557,13 +618,13 @@ var validateX509CertificateChainImpl = /* @__PURE__ */ __name(async ({ reversed,
557
618
  var isSameCertificate = /* @__PURE__ */ __name((cert1, cert2) => {
558
619
  return cert1.rawData.toString() === cert2.rawData.toString();
559
620
  }, "isSameCertificate");
560
- var algorithmProvider = _tsyringe.container.resolve(_x509.AlgorithmProvider);
621
+ var algorithmProvider = import_tsyringe.container.resolve(import_x509.AlgorithmProvider);
561
622
  var getX509AlgorithmProvider = /* @__PURE__ */ __name(() => {
562
623
  return algorithmProvider;
563
624
  }, "getX509AlgorithmProvider");
564
625
  var parseCertificate = /* @__PURE__ */ __name(async (rawCert) => {
565
- const x509Certificate = new (0, _x509.X509Certificate)(rawCert);
566
- const publicKeyInfo = _asn1schema.AsnParser.parse(x509Certificate.publicKey.rawData, _asn1x509.SubjectPublicKeyInfo);
626
+ const x509Certificate = new import_x509.X509Certificate(rawCert);
627
+ const publicKeyInfo = import_asn1_schema.AsnParser.parse(x509Certificate.publicKey.rawData, import_asn1_x509.SubjectPublicKeyInfo);
567
628
  const publicKeyRaw = new Uint8Array(publicKeyInfo.subjectPublicKey);
568
629
  let publicKeyJwk = void 0;
569
630
  try {
@@ -612,7 +673,7 @@ var getSubjectDN = /* @__PURE__ */ __name((cert) => {
612
673
  var getDNObject = /* @__PURE__ */ __name((typesAndValues) => {
613
674
  const DN = {};
614
675
  for (const typeAndValue of typesAndValues) {
615
- const type = _nullishCoalesce(rdnmap[typeAndValue.type], () => ( typeAndValue.type));
676
+ const type = rdnmap[typeAndValue.type] ?? typeAndValue.type;
616
677
  DN[type] = typeAndValue.value.getValue();
617
678
  }
618
679
  return DN;
@@ -621,22 +682,22 @@ var getDNString = /* @__PURE__ */ __name((typesAndValues) => {
621
682
  return Object.entries(getDNObject(typesAndValues)).map(([key, value]) => `${key}=${value}`).join(",");
622
683
  }, "getDNString");
623
684
  var getCertificateSubjectPublicKeyJWK = /* @__PURE__ */ __name(async (pemOrDerCert) => {
624
- const pemOrDerStr = typeof pemOrDerCert === "string" ? _tostring.toString.call(void 0, _fromstring.fromString.call(void 0, pemOrDerCert, "base64pad"), "base64pad") : pemOrDerCert instanceof Uint8Array ? _tostring.toString.call(void 0, pemOrDerCert, "base64pad") : _tostring.toString.call(void 0, _fromstring.fromString.call(void 0, pemOrDerCert.toString("base64"), "base64pad"), "base64pad");
685
+ const pemOrDerStr = typeof pemOrDerCert === "string" ? toString4(fromString3(pemOrDerCert, "base64pad"), "base64pad") : pemOrDerCert instanceof Uint8Array ? toString4(pemOrDerCert, "base64pad") : toString4(fromString3(pemOrDerCert.toString("base64"), "base64pad"), "base64pad");
625
686
  const pem = derToPEM(pemOrDerStr);
626
687
  const certificate = pemOrDerToX509Certificate(pem);
627
688
  var jwk;
628
689
  try {
629
- const subtle = _pkijs.getCrypto.call(void 0, true).subtle;
690
+ const subtle = (0, import_pkijs2.getCrypto)(true).subtle;
630
691
  const pk = await certificate.getPublicKey(void 0, defaultCryptoEngine());
631
692
  jwk = await subtle.exportKey("jwk", pk);
632
693
  } catch (error) {
633
- console.log(`Error in primary get JWK from cert:`, _optionalChain([error, 'optionalAccess', _37 => _37.message]));
694
+ console.log(`Error in primary get JWK from cert:`, error?.message);
634
695
  }
635
696
  if (!jwk) {
636
697
  try {
637
- jwk = await _jsx509utils2.default.toJwk(pem, "pem");
698
+ jwk = await import_js_x509_utils.default.toJwk(pem, "pem");
638
699
  } catch (error) {
639
- console.log(`Error in secondary get JWK from cert as well:`, _optionalChain([error, 'optionalAccess', _38 => _38.message]));
700
+ console.log(`Error in secondary get JWK from cert as well:`, error?.message);
640
701
  }
641
702
  }
642
703
  if (!jwk) {
@@ -685,13 +746,13 @@ var validateCertificateChainMatchesClientIdScheme = /* @__PURE__ */ __name(async
685
746
  }, "validateCertificateChainMatchesClientIdScheme");
686
747
  var getSubjectAlternativeNames = /* @__PURE__ */ __name((certificate, opts) => {
687
748
  let typeFilter;
688
- if (_optionalChain([opts, 'optionalAccess', _39 => _39.clientIdSchemeFilter])) {
749
+ if (opts?.clientIdSchemeFilter) {
689
750
  typeFilter = opts.clientIdSchemeFilter === "x509_san_dns" ? [
690
751
  2
691
752
  ] : [
692
753
  6
693
754
  ];
694
- } else if (_optionalChain([opts, 'optionalAccess', _40 => _40.typeFilter])) {
755
+ } else if (opts?.typeFilter) {
695
756
  typeFilter = Array.isArray(opts.typeFilter) ? opts.typeFilter : [
696
757
  opts.typeFilter
697
758
  ];
@@ -701,7 +762,7 @@ var getSubjectAlternativeNames = /* @__PURE__ */ __name((certificate, opts) => {
701
762
  6
702
763
  ];
703
764
  }
704
- const parsedValue = _optionalChain([certificate, 'access', _41 => _41.extensions, 'optionalAccess', _42 => _42.find, 'call', _43 => _43((ext) => ext.extnID === _pkijs.id_SubjectAltName), 'optionalAccess', _44 => _44.parsedValue]);
765
+ const parsedValue = certificate.extensions?.find((ext) => ext.extnID === import_pkijs2.id_SubjectAltName)?.parsedValue;
705
766
  if (!parsedValue) {
706
767
  return [];
707
768
  }
@@ -713,39 +774,4 @@ var getSubjectAlternativeNames = /* @__PURE__ */ __name((certificate, opts) => {
713
774
  };
714
775
  });
715
776
  }, "getSubjectAlternativeNames");
716
-
717
-
718
-
719
-
720
-
721
-
722
-
723
-
724
-
725
-
726
-
727
-
728
-
729
-
730
-
731
-
732
-
733
-
734
-
735
-
736
-
737
-
738
-
739
-
740
-
741
-
742
-
743
-
744
-
745
-
746
-
747
-
748
-
749
-
750
- exports.JwkKeyUse = JwkKeyUse; exports.PEMToBinary = PEMToBinary; exports.PEMToDer = PEMToDer; exports.PEMToHex = PEMToHex; exports.PEMToJwk = PEMToJwk; exports.RSASigner = RSASigner; exports.SubjectAlternativeGeneralName = SubjectAlternativeGeneralName; exports.areCertificatesEqual = areCertificatesEqual; exports.assertCertificateMatchesClientIdScheme = assertCertificateMatchesClientIdScheme; exports.base64ToHex = base64ToHex; exports.cryptoSubtleImportRSAKey = cryptoSubtleImportRSAKey; exports.derToPEM = derToPEM; exports.generateRSAKeyAsPEM = generateRSAKeyAsPEM; exports.getCertificateInfo = getCertificateInfo; exports.getCertificateSubjectPublicKeyJWK = getCertificateSubjectPublicKeyJWK; exports.getIssuerDN = getIssuerDN; exports.getSubjectAlternativeNames = getSubjectAlternativeNames; exports.getSubjectDN = getSubjectDN; exports.getX509AlgorithmProvider = getX509AlgorithmProvider; exports.hexKeyFromPEMBasedJwk = hexKeyFromPEMBasedJwk; exports.hexToBase64 = hexToBase64; exports.hexToPEM = hexToPEM; exports.jwkToPEM = jwkToPEM; exports.parseCertificate = parseCertificate; exports.pemCertChainTox5c = pemCertChainTox5c; exports.pemOrDerToX509Certificate = pemOrDerToX509Certificate; exports.privateKeyHexFromPEM = privateKeyHexFromPEM; exports.publicKeyHexFromPEM = publicKeyHexFromPEM; exports.signAlgorithmToSchemeAndHashAlg = signAlgorithmToSchemeAndHashAlg; exports.toKeyObject = toKeyObject; exports.validateCertificateChainMatchesClientIdScheme = validateCertificateChainMatchesClientIdScheme; exports.validateX509CertificateChain = validateX509CertificateChain; exports.x5cToPemCertChain = x5cToPemCertChain;
751
777
  //# sourceMappingURL=index.cjs.map