@blamejs/core 0.18.53 → 0.18.55

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 (64) hide show
  1. package/CHANGELOG.md +228 -0
  2. package/NOTICE +1 -1
  3. package/README.md +5 -5
  4. package/lib/agent-audit.js +27 -2
  5. package/lib/ai-adverse-decision.js +18 -2
  6. package/lib/audit-sign.js +24 -5
  7. package/lib/auth/passkey.js +4 -1
  8. package/lib/codepoint-class.js +72 -0
  9. package/lib/cookies.js +7 -10
  10. package/lib/credential-hash.js +8 -1
  11. package/lib/crypto.js +7 -5
  12. package/lib/db-file-lifecycle.js +14 -3
  13. package/lib/db.js +505 -49
  14. package/lib/guard-auth.js +34 -11
  15. package/lib/guard-filename.js +41 -33
  16. package/lib/guard-html.js +10 -2
  17. package/lib/guard-list-unsubscribe.js +6 -1
  18. package/lib/guard-managesieve-command.js +73 -12
  19. package/lib/guard-regex.js +3 -5
  20. package/lib/guard-smtp-command.js +20 -4
  21. package/lib/guard-svg.js +6 -1
  22. package/lib/guard-yaml.js +60 -15
  23. package/lib/http-client.js +17 -3
  24. package/lib/mail-agent.js +29 -13
  25. package/lib/mail-arc-sign.js +40 -7
  26. package/lib/mail-auth.js +134 -22
  27. package/lib/mail-crypto-pgp.js +1 -1
  28. package/lib/mail-dkim.js +80 -11
  29. package/lib/mail-helo.js +10 -0
  30. package/lib/mail-rbl.js +10 -3
  31. package/lib/mail-send-deliver.js +151 -32
  32. package/lib/mail-server-imap.js +186 -89
  33. package/lib/mail-server-jmap.js +31 -4
  34. package/lib/mail-server-managesieve.js +198 -42
  35. package/lib/mail-server-mx.js +191 -38
  36. package/lib/mail-server-net.js +281 -1
  37. package/lib/mail-server-pop3.js +89 -41
  38. package/lib/mail-server-rate-limit.js +104 -6
  39. package/lib/mail-server-submission.js +183 -35
  40. package/lib/mail-server-tls.js +48 -3
  41. package/lib/mail-store.js +33 -11
  42. package/lib/mail.js +355 -17
  43. package/lib/mcp.js +11 -3
  44. package/lib/middleware/bearer-auth.js +6 -1
  45. package/lib/middleware/fetch-metadata.js +5 -1
  46. package/lib/middleware/headers.js +7 -10
  47. package/lib/middleware/require-mtls.js +8 -1
  48. package/lib/network-dns-resolver.js +71 -8
  49. package/lib/network-dns.js +26 -0
  50. package/lib/network-smtp-policy.js +42 -10
  51. package/lib/network-tls.js +18 -0
  52. package/lib/redact.js +13 -3
  53. package/lib/retention.js +22 -2
  54. package/lib/safe-mount-info.js +39 -6
  55. package/lib/safe-smtp.js +96 -1
  56. package/lib/safe-url.js +8 -2
  57. package/lib/self-update.js +4 -1
  58. package/lib/vendor/MANIFEST.json +12 -12
  59. package/lib/vendor/blamejs-pki.cjs +672 -75
  60. package/lib/watcher.js +31 -6
  61. package/lib/ws-client.js +17 -2
  62. package/lib/yaml-lex.js +55 -1
  63. package/package.json +1 -1
  64. package/sbom.cdx.json +6 -6
@@ -1,4 +1,4 @@
1
- // @blamejs/pki v0.5.28 — vendored (Apache-2.0). Zero-dep pure CJS.
1
+ // @blamejs/pki v0.5.31 — vendored (Apache-2.0). Zero-dep pure CJS.
2
2
  // https://github.com/blamejs/pki Exports: x509, crl, pkcs12, key, webcrypto, schema, csr, cms, ...
3
3
  // Backs lib/mtls-engine-default.js (PQC-capable CA + PKCS#12 engine).
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -141,7 +141,7 @@ var require_package = __commonJS({
141
141
  "node_modules/@blamejs/pki/package.json"(exports2, module2) {
142
142
  module2.exports = {
143
143
  name: "@blamejs/pki",
144
- version: "0.5.28",
144
+ version: "0.5.31",
145
145
  description: "Pure-JavaScript PKI toolkit that owns its stack \u2014 X.509, ASN.1/DER, CMS, PQC-first.",
146
146
  license: "Apache-2.0",
147
147
  author: "blamejs contributors",
@@ -1957,6 +1957,41 @@ var require_oid = __commonJS({
1957
1957
  // The arc is RSA-dedicated, so a consumer can classify the whole family by its prefix; one member is
1958
1958
  // registered here so that prefix can be derived from the registry rather than a dotted-decimal literal.
1959
1959
  teletrustRsaSig: { base: [1, 3, 36, 3, 3, 1], of: { "rsaSignatureWithripemd160": 2 } },
1960
+ // TeleTrusT (BSI) signatureScheme arc (1.3.36.3.4) -- the ISO/IEC 9796-2 RSA signatures giving message
1961
+ // recovery (schemes 1/2/3: two deterministic, one randomized). ISO/IEC 9796-2 is titled "integer
1962
+ // factorization based mechanisms", so EVERY scheme it defines is RSA and the standard has no non-RSA
1963
+ // member; each node is registered so a consumer can name it -- e.g. the CMP keySpec RSA exclusion, which
1964
+ // must recognize RSA wherever it is standardized. ISO/IEC 9796-2 assigns no algorithm OIDs of its own;
1965
+ // this registrant tree is the de-facto registry. The .2 (deterministic) and .3 (randomized) sub-arcs are
1966
+ // RSA-dedicated in full -- every descendant is RSA -- so a consumer prefix-matches each to catch a hash
1967
+ // variant added later; the per-hash leaves are registered for readability. The `...Withrsa-even-exp`
1968
+ // nodes (.2.1 / .3.1) are the even-public-exponent RSA variants the registrant marks "not used"; they are
1969
+ // RSA (the registrant names them `sigS_ISO9796-2Withrsa_even-exp`), so the sub-arc prefix classifies them
1970
+ // correctly, not wrongly. .1 is ISO/IEC 9796-1, also RSA, on the same arc. The PARENT node (.4) is generic
1971
+ // "signatureScheme" and the sibling authentication arc (.5) is mixed (its .5.3 children are ECC), so
1972
+ // neither is RSA-dedicated -- a consumer must not prefix-match the parent or .5.
1973
+ teletrustSigScheme: { base: [1, 3, 36, 3, 4], of: {
1974
+ "sigS-ISO9796-1": 1,
1975
+ "sigS-ISO9796-1-DFUE": [1, 1],
1976
+ "sigS-ISO9796-2": 2,
1977
+ "sigS-ISO9796-2Withrsa-even-exp": [2, 1],
1978
+ "sigS-ISO9796-2Withrsa": [2, 2],
1979
+ "sigS-ISO9796-2Withrsa-sha1": [2, 2, 1],
1980
+ "sigS-ISO9796-2Withrsa-ripemd160": [2, 2, 2],
1981
+ "sigS-ISO9796-2Withrsa-sha224": [2, 2, 3],
1982
+ "sigS-ISO9796-2Withrsa-sha256": [2, 2, 4],
1983
+ "sigS-ISO9796-2Withrsa-sha384": [2, 2, 5],
1984
+ "sigS-ISO9796-2Withrsa-sha512": [2, 2, 6],
1985
+ "sigS-ISO9796-2rnd": 3,
1986
+ "sigS-ISO9796-2rndWithrsa-even-exp": [3, 1],
1987
+ "sigS-ISO9796-2rndWithrsa": [3, 2],
1988
+ "sigS-ISO9796-2rndWithrsa-sha1": [3, 2, 1],
1989
+ "sigS-ISO9796-2rndWithrsa-ripemd160": [3, 2, 2],
1990
+ "sigS-ISO9796-2rndWithrsa-sha224": [3, 2, 3],
1991
+ "sigS-ISO9796-2rndWithrsa-sha256": [3, 2, 4],
1992
+ "sigS-ISO9796-2rndWithrsa-sha384": [3, 2, 5],
1993
+ "sigS-ISO9796-2rndWithrsa-sha512": [3, 2, 6]
1994
+ } },
1960
1995
  // X.509 directory encryptionAlgorithm arc (2.5.8.1). id-ea-rsa (.1) is the X.509 `rsa` public-key
1961
1996
  // identifier, distinct from PKCS#1 rsaEncryption. Registered so a consumer can name it -- e.g. the
1962
1997
  // CMP keySpec RSA exclusion, which must recognize RSA wherever it is standardized.
@@ -5721,6 +5756,7 @@ var require_asn1_der = __commonJS({
5721
5756
  return _asBuffer(buf, "build.raw");
5722
5757
  }
5723
5758
  };
5759
+ intrinsic.freeze(build);
5724
5760
  function _intContent(v, who) {
5725
5761
  if (Buffer.isBuffer(v)) {
5726
5762
  if (v.length === 0) throw new Asn1Error("asn1/bad-integer", who + ": INTEGER content is empty");
@@ -18378,7 +18414,10 @@ var require_sign_scheme = __commonJS({
18378
18414
  }
18379
18415
  function _assertKeyMatchesScheme(key, imp, E) {
18380
18416
  var ka = key.algorithm || {};
18381
- if (_toUpperCase(_String(ka.name)) !== _toUpperCase(_String(imp.name))) throw E("bad-input", "the signer CryptoKey algorithm (" + ka.name + ") does not match the certificate's key algorithm (" + imp.name + ")");
18417
+ if (_toUpperCase(_String(ka.name)) !== _toUpperCase(_String(imp.name))) {
18418
+ var hint = _toUpperCase(_String(ka.name)) === "RSA-PSS" && _toUpperCase(_String(imp.name)) === "RSASSA-PKCS1-V1_5" ? "; this CryptoKey is bound to RSASSA-PSS -- pass opts.pss to sign with RSASSA-PSS" : "";
18419
+ throw E("bad-input", "the signer CryptoKey algorithm (" + ka.name + ") does not match the certificate's key algorithm (" + imp.name + ")" + hint);
18420
+ }
18382
18421
  if (imp.hash && (!ka.hash || ka.hash.name !== imp.hash)) throw E("bad-input", "the signer CryptoKey hash (" + (ka.hash && ka.hash.name) + ") does not match the signing digest (" + imp.hash + ")");
18383
18422
  if (imp.namedCurve && ka.namedCurve !== imp.namedCurve) throw E("bad-input", "the signer CryptoKey curve (" + ka.namedCurve + ") does not match the certificate curve (" + imp.namedCurve + ")");
18384
18423
  }
@@ -18401,7 +18440,10 @@ var require_sign_scheme = __commonJS({
18401
18440
  return { mldsa: _normPkcs8(key.mldsa, "the composite ML-DSA component key", E), trad: _normPkcs8(key.trad, "the composite traditional component key", E) };
18402
18441
  }
18403
18442
  function _importKey(key, imp, E) {
18404
- if (key && typeof key === "object" && !_isBuffer(key) && !_isU8(key) && key.type === "private") {
18443
+ if (key && typeof key === "object" && !_isBuffer(key) && !_isU8(key) && typeof key.type === "string" && key.algorithm != null) {
18444
+ if (key.type !== "private") {
18445
+ throw E("bad-input", "the signing key is a WebCrypto CryptoKey of type " + _stringify(key.type) + '; a signing key must be a private key (type "private")');
18446
+ }
18405
18447
  _assertKeyMatchesScheme(key, imp, E);
18406
18448
  return webcrypto.adoptKey(key, imp, ["sign"], E, "bad-input");
18407
18449
  }
@@ -18417,7 +18459,9 @@ var require_sign_scheme = __commonJS({
18417
18459
  throw E("bad-input", "the signer PEM private key could not be decoded", e);
18418
18460
  }
18419
18461
  owned = true;
18420
- } else throw E("bad-input", "a signer key must be a CryptoKey, a PKCS#8 DER Buffer, or a PKCS#8 PEM string");
18462
+ } else if (intrinsic.types.isKeyObject(key)) {
18463
+ throw E("bad-input", "the signing key is a node:crypto KeyObject, not a WebCrypto CryptoKey; pass a CryptoKey (e.g. from pki.key.generate) or export it to a PKCS#8 DER Buffer or PEM string");
18464
+ } else throw E("bad-input", "a signer key must be a WebCrypto CryptoKey, a PKCS#8 DER Buffer, or a PKCS#8 PEM string");
18421
18465
  var imported = subtle.importKey("pkcs8", der, imp, false, ["sign"]);
18422
18466
  if (!owned) return imported;
18423
18467
  return imported.then(function(k) {
@@ -18457,35 +18501,101 @@ var require_sign_scheme = __commonJS({
18457
18501
  var require_ip_utils = __commonJS({
18458
18502
  "node_modules/@blamejs/pki/lib/ip-utils.js"(exports2, module2) {
18459
18503
  "use strict";
18460
- var IPV4_RE = /^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}$/;
18504
+ var intrinsic = require_guard_intrinsic();
18505
+ var _slice = intrinsic.uncurry(String.prototype.slice);
18506
+ var _padStart = intrinsic.uncurry(String.prototype.padStart);
18507
+ var _charCodeAt = intrinsic.uncurry(String.prototype.charCodeAt);
18508
+ var _lastIndexOf = intrinsic.uncurry(String.prototype.lastIndexOf);
18509
+ var _toLowerCase = intrinsic.toLowerCase;
18510
+ var _indexOf = intrinsic.stringIndexOf;
18511
+ var _numToString = intrinsic.numberToString;
18512
+ var _bufferFrom = intrinsic.bufferFrom;
18513
+ var _bufferAlloc = intrinsic.bufferAlloc;
18514
+ var _defineProperty = intrinsic.defineProperty;
18515
+ var _Number = intrinsic.Number;
18516
+ function _push(arr, v) {
18517
+ _defineProperty(arr, arr.length, { value: v, writable: true, enumerable: true, configurable: true });
18518
+ }
18519
+ function _splitOn(str, sep) {
18520
+ var out = [], from = 0, at;
18521
+ while ((at = _indexOf(str, sep, from)) !== -1) {
18522
+ _push(out, _slice(str, from, at));
18523
+ from = at + sep.length;
18524
+ }
18525
+ _push(out, _slice(str, from));
18526
+ return out;
18527
+ }
18528
+ function _isDigitCode(c) {
18529
+ return c >= 48 && c <= 57;
18530
+ }
18531
+ function _isHexCode(c) {
18532
+ return c >= 48 && c <= 57 || c >= 97 && c <= 102 || c >= 65 && c <= 70;
18533
+ }
18534
+ function _isOctet(p) {
18535
+ var n = p.length, i, c;
18536
+ if (n < 1 || n > 3) return false;
18537
+ for (i = 0; i < n; i += 1) {
18538
+ c = _charCodeAt(p, i);
18539
+ if (!_isDigitCode(c)) return false;
18540
+ }
18541
+ if (n > 1 && _charCodeAt(p, 0) === 48) return false;
18542
+ return _Number(p) <= 255;
18543
+ }
18461
18544
  function isIPv4(s) {
18462
- return typeof s === "string" && IPV4_RE.test(s);
18545
+ if (typeof s !== "string") return false;
18546
+ var parts = _splitOn(s, ".");
18547
+ if (parts.length !== 4) return false;
18548
+ for (var i = 0; i < 4; i += 1) {
18549
+ if (!_isOctet(parts[i])) return false;
18550
+ }
18551
+ return true;
18552
+ }
18553
+ function _isHexGroup(g) {
18554
+ var n = g.length, i;
18555
+ if (n < 1 || n > 4) return false;
18556
+ for (i = 0; i < n; i += 1) {
18557
+ if (!_isHexCode(_charCodeAt(g, i))) return false;
18558
+ }
18559
+ return true;
18560
+ }
18561
+ function _isDottedQuadShape(t) {
18562
+ var q = _splitOn(t, "."), i, p, j;
18563
+ if (q.length !== 4) return false;
18564
+ for (i = 0; i < 4; i += 1) {
18565
+ p = q[i];
18566
+ if (p.length < 1 || p.length > 3) return false;
18567
+ for (j = 0; j < p.length; j += 1) {
18568
+ if (!_isDigitCode(_charCodeAt(p, j))) return false;
18569
+ }
18570
+ }
18571
+ return true;
18463
18572
  }
18464
18573
  var IPV6_TEXT_MAX_LEN = 45;
18465
18574
  function expandIpv6Hex(ip) {
18466
- if (typeof ip !== "string" || ip.length > IPV6_TEXT_MAX_LEN || ip.indexOf(":") === -1) return null;
18467
- var dual = ip.match(/^(.*):(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/);
18468
- if (dual) {
18469
- if (!isIPv4(dual[2])) return null;
18470
- var v4 = dual[2].split(".").map(Number);
18471
- ip = dual[1] + ":" + (v4[0] << 8 | v4[1]).toString(16) + ":" + (v4[2] << 8 | v4[3]).toString(16);
18472
- }
18473
- var dbl = ip.split("::");
18575
+ if (typeof ip !== "string" || ip.length > IPV6_TEXT_MAX_LEN || _indexOf(ip, ":") === -1) return null;
18576
+ var lastColon = _lastIndexOf(ip, ":");
18577
+ var tail = _slice(ip, lastColon + 1);
18578
+ if (_indexOf(tail, ".") !== -1) {
18579
+ if (!_isDottedQuadShape(tail) || !isIPv4(tail)) return null;
18580
+ var q = _splitOn(tail, "."), o0 = _Number(q[0]), o1 = _Number(q[1]), o2 = _Number(q[2]), o3 = _Number(q[3]);
18581
+ ip = _slice(ip, 0, lastColon) + ":" + _numToString(o0 << 8 | o1, 16) + ":" + _numToString(o2 << 8 | o3, 16);
18582
+ }
18583
+ var dbl = _splitOn(ip, "::");
18474
18584
  if (dbl.length > 2) return null;
18475
- var left = dbl[0] === "" ? [] : dbl[0].split(":");
18476
- var right = dbl.length === 2 ? dbl[1] === "" ? [] : dbl[1].split(":") : [];
18585
+ var left = dbl[0] === "" ? [] : _splitOn(dbl[0], ":");
18586
+ var right = dbl.length === 2 ? dbl[1] === "" ? [] : _splitOn(dbl[1], ":") : [];
18477
18587
  if (dbl.length === 1 && left.length !== 8) return null;
18478
18588
  var fill = 8 - left.length - right.length;
18479
18589
  if (dbl.length === 2 ? fill < 1 : fill !== 0) return null;
18480
18590
  var groups = left, i;
18481
- for (i = 0; i < fill; i += 1) groups = groups.concat(["0"]);
18482
- groups = groups.concat(right);
18591
+ for (i = 0; i < fill; i += 1) _push(groups, "0");
18592
+ for (i = 0; i < right.length; i += 1) _push(groups, right[i]);
18483
18593
  if (groups.length !== 8) return null;
18484
18594
  var hex = "";
18485
18595
  for (i = 0; i < 8; i += 1) {
18486
18596
  var g = groups[i];
18487
- if (g.length < 1 || g.length > 4 || !/^[0-9a-f]+$/i.test(g)) return null;
18488
- hex += g.toLowerCase().padStart(4, "0");
18597
+ if (!_isHexGroup(g)) return null;
18598
+ hex += _padStart(_toLowerCase(g), 4, "0");
18489
18599
  }
18490
18600
  return hex;
18491
18601
  }
@@ -18493,11 +18603,15 @@ var require_ip_utils = __commonJS({
18493
18603
  return isIPv4(s) || expandIpv6Hex(s) !== null;
18494
18604
  }
18495
18605
  function packIpLiteral(s) {
18496
- if (isIPv4(s)) return Buffer.from(s.split(".").map(Number));
18606
+ if (isIPv4(s)) {
18607
+ var parts = _splitOn(s, "."), buf = _bufferAlloc(4), i;
18608
+ for (i = 0; i < 4; i += 1) buf[i] = _Number(parts[i]);
18609
+ return buf;
18610
+ }
18497
18611
  var hex = expandIpv6Hex(s);
18498
- return hex === null ? null : Buffer.from(hex, "hex");
18612
+ return hex === null ? null : _bufferFrom(hex, "hex");
18499
18613
  }
18500
- module2.exports = { isIPv4, expandIpv6Hex, isIpLiteral, packIpLiteral, IPV4_RE };
18614
+ module2.exports = { isIPv4, expandIpv6Hex, isIpLiteral, packIpLiteral };
18501
18615
  }
18502
18616
  });
18503
18617
 
@@ -18515,10 +18629,275 @@ var require_pki_build = __commonJS({
18515
18629
  var _bufferEquals = intrinsic.bufferEquals;
18516
18630
  var oid = require_oid();
18517
18631
  var ipUtils = require_ip_utils();
18632
+ var _packIpLiteral = ipUtils.packIpLiteral;
18518
18633
  var nodeCrypto = require("crypto");
18519
18634
  var _keyEquals = intrinsic.uncurry(nodeCrypto.KeyObject.prototype.equals);
18635
+ var _charCodeAt = intrinsic.uncurry(String.prototype.charCodeAt);
18636
+ var _stringIndexOf = intrinsic.stringIndexOf;
18637
+ var _stringLastIndexOf = intrinsic.uncurry(String.prototype.lastIndexOf);
18638
+ var _sliceStr = intrinsic.uncurry(String.prototype.slice);
18639
+ var _String = intrinsic.String;
18640
+ var _objectKeys = intrinsic.keys;
18641
+ var _isBufferChk = intrinsic.isBuffer;
18642
+ var _stringify = intrinsic.stringify;
18643
+ function _isAlphaCode(c) {
18644
+ return c >= 65 && c <= 90 || c >= 97 && c <= 122;
18645
+ }
18646
+ function _isDigitCode(c) {
18647
+ return c >= 48 && c <= 57;
18648
+ }
18649
+ function _isHexCode(c) {
18650
+ return c >= 48 && c <= 57 || c >= 97 && c <= 102 || c >= 65 && c <= 70;
18651
+ }
18652
+ function _isUnreserved(c) {
18653
+ return _isAlphaCode(c) || _isDigitCode(c) || c === 45 || c === 46 || c === 95 || c === 126;
18654
+ }
18655
+ function _isSubDelim(c) {
18656
+ switch (c) {
18657
+ case 33:
18658
+ case 36:
18659
+ case 38:
18660
+ case 39:
18661
+ case 40:
18662
+ case 41:
18663
+ case 42:
18664
+ case 43:
18665
+ case 44:
18666
+ case 59:
18667
+ case 61:
18668
+ return true;
18669
+ default:
18670
+ return false;
18671
+ }
18672
+ }
18673
+ function _isUserinfoByte(c) {
18674
+ return _isUnreserved(c) || _isSubDelim(c) || c === 58;
18675
+ }
18676
+ function _isUriByte(c) {
18677
+ return _isUnreserved(c) || _isSubDelim(c) || c === 58 || c === 47 || c === 63 || c === 35 || c === 64;
18678
+ }
18679
+ function _isAtextByte(c) {
18680
+ if (_isAlphaCode(c) || _isDigitCode(c)) return true;
18681
+ switch (c) {
18682
+ case 33:
18683
+ case 35:
18684
+ case 36:
18685
+ case 37:
18686
+ case 38:
18687
+ case 39:
18688
+ // ! # $ % & '
18689
+ case 42:
18690
+ case 43:
18691
+ case 45:
18692
+ case 47:
18693
+ case 61:
18694
+ case 63:
18695
+ // * + - / = ?
18696
+ case 94:
18697
+ case 95:
18698
+ case 96:
18699
+ case 123:
18700
+ case 124:
18701
+ case 125:
18702
+ case 126:
18703
+ return true;
18704
+ default:
18705
+ return false;
18706
+ }
18707
+ }
18708
+ function _looksLikeIPv4Shape(s) {
18709
+ var n = s.length, i, c, sawDot = false, atomEmpty = true;
18710
+ if (n === 0) return false;
18711
+ for (i = 0; i < n; i += 1) {
18712
+ c = _charCodeAt(s, i);
18713
+ if (c === 46) {
18714
+ if (atomEmpty) return false;
18715
+ sawDot = true;
18716
+ atomEmpty = true;
18717
+ } else if (_isDigitCode(c)) {
18718
+ atomEmpty = false;
18719
+ } else return false;
18720
+ }
18721
+ return sawDot && !atomEmpty;
18722
+ }
18723
+ function _componentBytesOk(s, from, to, byteOk) {
18724
+ var i = from, c;
18725
+ while (i < to) {
18726
+ c = _charCodeAt(s, i);
18727
+ if (c === 37) {
18728
+ if (i + 2 >= to || !_isHexCode(_charCodeAt(s, i + 1)) || !_isHexCode(_charCodeAt(s, i + 2))) return false;
18729
+ i += 3;
18730
+ } else if (byteOk(c)) {
18731
+ i += 1;
18732
+ } else return false;
18733
+ }
18734
+ return true;
18735
+ }
18736
+ function _validUriHost(s, from, to) {
18737
+ if (to <= from) return false;
18738
+ var host = _sliceStr(s, from, to), len = host.length;
18739
+ if (_looksLikeIPv4Shape(host)) return _packIpLiteral(host) !== null;
18740
+ var end = _charCodeAt(host, len - 1) === 46 ? len - 1 : len;
18741
+ if (end > 253) return false;
18742
+ var firstDot = _stringIndexOf(host, ".", 0);
18743
+ if (firstDot === -1 || firstDot >= end) return false;
18744
+ return _labelsValid(host, 0, len, _isHostLabelRange, true);
18745
+ }
18746
+ function _validUriAuthority(s, from, to) {
18747
+ var i, c, at = -1;
18748
+ for (i = from; i < to; i += 1) {
18749
+ c = _charCodeAt(s, i);
18750
+ if (c === 64) {
18751
+ if (at !== -1) return false;
18752
+ at = i;
18753
+ }
18754
+ }
18755
+ var hostStart = at === -1 ? from : at + 1;
18756
+ if (at !== -1 && !_componentBytesOk(s, from, at, _isUserinfoByte)) return false;
18757
+ var colon = -1;
18758
+ for (i = hostStart; i < to; i += 1) {
18759
+ if (_charCodeAt(s, i) === 58) {
18760
+ colon = i;
18761
+ break;
18762
+ }
18763
+ }
18764
+ var hostEnd = colon === -1 ? to : colon;
18765
+ if (!_validUriHost(s, hostStart, hostEnd)) return false;
18766
+ if (colon !== -1) {
18767
+ for (i = colon + 1; i < to; i += 1) {
18768
+ if (!_isDigitCode(_charCodeAt(s, i))) return false;
18769
+ }
18770
+ }
18771
+ return true;
18772
+ }
18773
+ function _looksLikeUri(s) {
18774
+ var n = s.length, i, c;
18775
+ if (n === 0 || !_isAlphaCode(_charCodeAt(s, 0))) return false;
18776
+ i = 1;
18777
+ while (i < n) {
18778
+ c = _charCodeAt(s, i);
18779
+ if (_isAlphaCode(c) || _isDigitCode(c) || c === 43 || c === 45 || c === 46) i += 1;
18780
+ else break;
18781
+ }
18782
+ if (i + 3 > n || _charCodeAt(s, i) !== 58 || _charCodeAt(s, i + 1) !== 47 || _charCodeAt(s, i + 2) !== 47) return false;
18783
+ i += 3;
18784
+ var authStart = i, authEnd = n;
18785
+ for (; i < n; i += 1) {
18786
+ c = _charCodeAt(s, i);
18787
+ if (c === 47 || c === 63 || c === 35) {
18788
+ authEnd = i;
18789
+ break;
18790
+ }
18791
+ }
18792
+ if (authEnd === authStart) return false;
18793
+ if (!_validUriAuthority(s, authStart, authEnd)) return false;
18794
+ var sawHash = false;
18795
+ i = authEnd;
18796
+ while (i < n) {
18797
+ c = _charCodeAt(s, i);
18798
+ if (c === 37) {
18799
+ if (i + 2 >= n || !_isHexCode(_charCodeAt(s, i + 1)) || !_isHexCode(_charCodeAt(s, i + 2))) return false;
18800
+ i += 3;
18801
+ continue;
18802
+ }
18803
+ if (c === 35) {
18804
+ if (sawHash) return false;
18805
+ sawHash = true;
18806
+ }
18807
+ if (!_isUriByte(c)) return false;
18808
+ i += 1;
18809
+ }
18810
+ return true;
18811
+ }
18812
+ function _isDnsLabelRange(s, from, to) {
18813
+ var len = to - from, i, c;
18814
+ if (len < 1 || len > 63) return false;
18815
+ for (i = from; i < to; i += 1) {
18816
+ c = _charCodeAt(s, i);
18817
+ if (_isAlphaCode(c) || _isDigitCode(c)) continue;
18818
+ if (i === to - 1) return false;
18819
+ if (c === 95) continue;
18820
+ if (c === 45 && i !== from) continue;
18821
+ return false;
18822
+ }
18823
+ return true;
18824
+ }
18825
+ function _isHostLabelRange(s, from, to) {
18826
+ var len = to - from, i, c, edge;
18827
+ if (len < 1 || len > 63) return false;
18828
+ for (i = from; i < to; i += 1) {
18829
+ c = _charCodeAt(s, i);
18830
+ edge = i === from || i === to - 1;
18831
+ if (_isAlphaCode(c) || _isDigitCode(c)) continue;
18832
+ if (c === 45 && !edge) continue;
18833
+ return false;
18834
+ }
18835
+ return true;
18836
+ }
18837
+ function _labelsValid(s, from, to, labelFn, allowRootDot) {
18838
+ if (allowRootDot && to - from >= 1 && _charCodeAt(s, to - 1) === 46) to -= 1;
18839
+ if (to <= from) return false;
18840
+ var start = from, dot;
18841
+ for (; ; ) {
18842
+ dot = _stringIndexOf(s, ".", start);
18843
+ var end = dot === -1 || dot >= to ? to : dot;
18844
+ if (!labelFn(s, start, end)) return false;
18845
+ if (end === to) return true;
18846
+ start = end + 1;
18847
+ }
18848
+ }
18849
+ function _looksLikeDnsName(s) {
18850
+ var n = s.length, start = 0;
18851
+ if (n < 1) return false;
18852
+ var end = _charCodeAt(s, n - 1) === 46 ? n - 1 : n;
18853
+ if (end < 1 || end > 253) return false;
18854
+ if (end >= 2 && _charCodeAt(s, 0) === 42 && _charCodeAt(s, 1) === 46) start = 2;
18855
+ if (start >= end) return false;
18856
+ return _labelsValid(s, start, n, _isDnsLabelRange, true);
18857
+ }
18858
+ function _looksLikeEmail(s) {
18859
+ if (s.length > 254) return false;
18860
+ var at = _stringIndexOf(s, "@", 0);
18861
+ if (at < 1 || at > 64 || _stringLastIndexOf(s, "@") !== at) return false;
18862
+ var i, c, atomEmpty = true;
18863
+ for (i = 0; i < at; i += 1) {
18864
+ c = _charCodeAt(s, i);
18865
+ if (c === 46) {
18866
+ if (atomEmpty) return false;
18867
+ atomEmpty = true;
18868
+ } else if (_isAtextByte(c)) {
18869
+ atomEmpty = false;
18870
+ } else return false;
18871
+ }
18872
+ if (atomEmpty) return false;
18873
+ var dStart = at + 1, dLen = s.length - dStart;
18874
+ if (dLen < 1 || dLen > 253 || _stringIndexOf(s, ".", dStart) === -1) return false;
18875
+ return _labelsValid(s, dStart, s.length, _isHostLabelRange, false);
18876
+ }
18877
+ function _isDottedOid(s) {
18878
+ var n = s.length, i, c, d0, arcs = 0;
18879
+ if (n < 3) return false;
18880
+ c = _charCodeAt(s, 0);
18881
+ if (c < 48 || c > 50) return false;
18882
+ i = 1;
18883
+ while (i < n) {
18884
+ if (_charCodeAt(s, i) !== 46) return false;
18885
+ i += 1;
18886
+ if (i >= n) return false;
18887
+ d0 = _charCodeAt(s, i);
18888
+ if (d0 === 48) {
18889
+ i += 1;
18890
+ } else if (d0 >= 49 && d0 <= 57) {
18891
+ i += 1;
18892
+ while (i < n && _isDigitCode(_charCodeAt(s, i))) i += 1;
18893
+ } else {
18894
+ return false;
18895
+ }
18896
+ arcs += 1;
18897
+ }
18898
+ return arcs >= 1;
18899
+ }
18520
18900
  var b = asn1.build;
18521
- var DOTTED_OID_RE = /^[0-2](?:\.(?:0|[1-9]\d*))+$/;
18522
18901
  var KU_BIT = {
18523
18902
  digitalSignature: 0,
18524
18903
  nonRepudiation: 1,
@@ -18604,15 +18983,30 @@ var require_pki_build = __commonJS({
18604
18983
  return asn1.decode(nameDer).children.length === 0;
18605
18984
  }
18606
18985
  function ia5Content(s) {
18607
- s = String(s);
18986
+ s = _String(s);
18608
18987
  for (var i = 0; i < s.length; i++) {
18609
- if (s.charCodeAt(i) > 127) throw E("bad-input", "value requires 7-bit ASCII (IA5String): " + JSON.stringify(s));
18988
+ if (_charCodeAt(s, i) > 127) throw E("bad-input", "value requires 7-bit ASCII (IA5String): " + _stringify(s));
18610
18989
  }
18611
- return Buffer.from(s, "latin1");
18990
+ return _bufferFrom(s, "latin1");
18991
+ }
18992
+ function _classifyBareGeneralName(s) {
18993
+ if (_packIpLiteral(s) !== null) return { iPAddress: s };
18994
+ if (_looksLikeIPv4Shape(s)) {
18995
+ throw E("bad-input", "the bare GeneralName string " + _stringify(s) + " looks like an IPv4 address but is not a valid one; pass { iPAddress: ... } for an address or { dNSName: ... } for a name");
18996
+ }
18997
+ if (_looksLikeUri(s)) return { uniformResourceIdentifier: s };
18998
+ if (_looksLikeEmail(s)) return { rfc822Name: s };
18999
+ if (_looksLikeDnsName(s)) return { dNSName: s };
19000
+ var _qs = _stringify(s);
19001
+ throw E("bad-input", "cannot classify the bare GeneralName string " + _qs + " as a dNSName, rfc822Name, iPAddress, or URI; pass an explicit form object, e.g. { dNSName: " + _qs + " }");
18612
19002
  }
18613
19003
  function encodeGeneralName(entry) {
18614
- if (!entry || typeof entry !== "object" || Buffer.isBuffer(entry)) throw E("bad-input", "a GeneralName must be an object with exactly one name form");
18615
- var keys = Object.keys(entry);
19004
+ if (typeof entry === "string") {
19005
+ if (entry === "") throw E("bad-input", "an empty GeneralName value is not permitted (RFC 5280 sec. 4.2.1.6)");
19006
+ entry = _classifyBareGeneralName(entry);
19007
+ }
19008
+ if (!entry || typeof entry !== "object" || _isBufferChk(entry)) throw E("bad-input", "a GeneralName must be an object with exactly one name form");
19009
+ var keys = _objectKeys(entry);
18616
19010
  if (keys.length !== 1) throw E("bad-input", "a GeneralName entry must have exactly one form, got " + keys.length);
18617
19011
  var k = keys[0], v = entry[k];
18618
19012
  if (v == null || v === "") throw E("bad-input", "an empty GeneralName value is not permitted (RFC 5280 sec. 4.2.1.6)");
@@ -18627,10 +19021,10 @@ var require_pki_build = __commonJS({
18627
19021
  case "iPAddress":
18628
19022
  var ipBuf = v;
18629
19023
  if (typeof v === "string") {
18630
- ipBuf = ipUtils.packIpLiteral(v);
18631
- if (ipBuf === null) throw E("bad-input", "iPAddress string is not a valid IPv4 or IPv6 literal: " + JSON.stringify(v));
19024
+ ipBuf = _packIpLiteral(v);
19025
+ if (ipBuf === null) throw E("bad-input", "iPAddress string is not a valid IPv4 or IPv6 literal: " + _stringify(v));
18632
19026
  }
18633
- if (!Buffer.isBuffer(ipBuf) || ipBuf.length !== 4 && ipBuf.length !== 16) throw E("bad-input", "iPAddress must be a 4- or 16-octet Buffer or an IPv4/IPv6 string");
19027
+ if (!_isBufferChk(ipBuf) || ipBuf.length !== 4 && ipBuf.length !== 16) throw E("bad-input", "iPAddress must be a 4- or 16-octet Buffer or an IPv4/IPv6 string");
18634
19028
  return b.contextPrimitive(7, ipBuf);
18635
19029
  case "directoryName":
18636
19030
  return b.explicit(4, encodeName(v));
@@ -18665,7 +19059,7 @@ var require_pki_build = __commonJS({
18665
19059
  function _resolveOid(n, label) {
18666
19060
  var dotted = O(n);
18667
19061
  if (dotted != null) return dotted;
18668
- if (typeof n === "string" && DOTTED_OID_RE.test(n)) {
19062
+ if (typeof n === "string" && _isDottedOid(n)) {
18669
19063
  try {
18670
19064
  b.oid(n);
18671
19065
  } catch (e) {
@@ -24151,7 +24545,14 @@ var require_cmp_session = __commonJS({
24151
24545
  crlUpdate: { name: "crlUpdate", requestOid: "crlStatusList", responseOid: "crls", value: "crlStatus", read: "readCrls" }
24152
24546
  });
24153
24547
  var KNOWN_REVOKE_KEYS = { certificate: 1, certDetails: 1, reason: 1 };
24154
- var RSA_ARCS = ["rsaEncryption", "rsaSignatureWithripemd160", "id-TA-RSA-v1-5-SHA-256"].map(function(n) {
24548
+ var RSA_ARCS = [
24549
+ "rsaEncryption",
24550
+ "rsaSignatureWithripemd160",
24551
+ "id-TA-RSA-v1-5-SHA-256",
24552
+ "sigS-ISO9796-1-DFUE",
24553
+ "sigS-ISO9796-2Withrsa",
24554
+ "sigS-ISO9796-2rndWithrsa"
24555
+ ].map(function(n) {
24155
24556
  return oid.toArcs(oid.byName(n)).slice(0, -1);
24156
24557
  });
24157
24558
  var RSA_OFF_ARC = /* @__PURE__ */ Object.create(null);
@@ -24179,8 +24580,13 @@ var require_cmp_session = __commonJS({
24179
24580
  "sqMod-nWithRSA",
24180
24581
  "mdc2WithRSA",
24181
24582
  // the X.500 directory signatureAlgorithm RSA OIDs (2.5.8.3.1, 2.5.8.3.100)
24182
- "sm3WithRSAEncryption"
24583
+ "sm3WithRSAEncryption",
24183
24584
  // the Chinese GM/T RSA-with-SM3 signature (1.2.156.10197.1.504)
24585
+ // The TeleTrusT signatureScheme (ISO/IEC 9796-2) sub-arcs are prefix-matched in RSA_ARCS, but the strict-
24586
+ // descendant match skips each arc NODE itself, so the three bare nodes are named here (1.3.36.3.4.1/.2/.3).
24587
+ "sigS-ISO9796-1",
24588
+ "sigS-ISO9796-2",
24589
+ "sigS-ISO9796-2rnd"
24184
24590
  ].forEach(function(n) {
24185
24591
  var d = oid.byName(n);
24186
24592
  if (d) RSA_OFF_ARC[d] = 1;
@@ -25298,6 +25704,7 @@ var require_path_validate = __commonJS({
25298
25704
  }
25299
25705
  var NS = pkix.makeNS("path", PathError, oid);
25300
25706
  var EXT_DECODERS = pkix.certExtensionDecoders(NS).byOid;
25707
+ var ANCHOR_SPKI_SCHEMA = pkix.spki(NS);
25301
25708
  var subtle = webcrypto.webcrypto.subtle;
25302
25709
  var OID = {
25303
25710
  basicConstraints: oid.byName("basicConstraints"),
@@ -25781,7 +26188,7 @@ var require_path_validate = __commonJS({
25781
26188
  return { tag: st.tag, base: st.base };
25782
26189
  });
25783
26190
  }
25784
- function initialize(certs, params, seeds) {
26191
+ function initialize(certs, params, seeds, anchor) {
25785
26192
  var n = certs.length;
25786
26193
  return {
25787
26194
  validPolicyTree: rootNode(),
@@ -25794,10 +26201,10 @@ var require_path_validate = __commonJS({
25794
26201
  explicitPolicy: params.initialExplicitPolicy ? 0 : n + 1,
25795
26202
  inhibitAnyPolicy: params.initialAnyPolicyInhibit ? 0 : n + 1,
25796
26203
  policyMapping: params.initialPolicyMappingInhibit ? 0 : n + 1,
25797
- workingPublicKeyAlgorithm: params.trustAnchor.algorithm,
25798
- workingPublicKey: params.trustAnchor.publicKey,
25799
- workingPublicKeyParameters: params.trustAnchor.parameters || null,
25800
- workingIssuerName: params.trustAnchor.name,
26204
+ workingPublicKeyAlgorithm: anchor.algorithm,
26205
+ workingPublicKey: anchor.publicKey,
26206
+ workingPublicKeyParameters: anchor.parameters || null,
26207
+ workingIssuerName: anchor.name,
25801
26208
  maxPathLength: n,
25802
26209
  userInitialPolicySet: params.userInitialPolicySet || [OID.anyPolicy],
25803
26210
  results: []
@@ -26110,6 +26517,7 @@ var require_path_validate = __commonJS({
26110
26517
  var n = certs.length;
26111
26518
  if (n < 1) throw E("path/empty-path", "validate: the certification path is empty");
26112
26519
  if (!opts.trustAnchor) throw E("path/bad-input", "validate: a trustAnchor is required");
26520
+ var anchor = toAnchor(opts.trustAnchor, "validate");
26113
26521
  guard.time.assertValid(opts.time, E, "path/bad-input", "validate: opts.time (the always-on validity-window check date)");
26114
26522
  guard.limits.cap(opts.maxPolicyNodes, "validate: opts.maxPolicyNodes", void 0, { E, code: "path/bad-input", min: 1 });
26115
26523
  if (opts.userInitialPolicySet !== void 0) {
@@ -26128,7 +26536,7 @@ var require_path_validate = __commonJS({
26128
26536
  var purposeOpts = resolvePurposeOpts(opts);
26129
26537
  var requiredEku = purposeOpts.requiredEku;
26130
26538
  var checkPurpose = purposeOpts.checkPurpose;
26131
- var state = initialize(certs, opts, seeds);
26539
+ var state = initialize(certs, opts, seeds, anchor);
26132
26540
  state._n = n;
26133
26541
  state.requiredEku = requiredEku;
26134
26542
  var verifier = opts.verifier || null;
@@ -26138,7 +26546,7 @@ var require_path_validate = __commonJS({
26138
26546
  var failed = false;
26139
26547
  var revocationRan = false, revocationWaived = false, revocationUndetermined = false;
26140
26548
  var anchorDistrustApplied = false, anchorPurposeApplied = false;
26141
- if (!checkPurpose && opts.trustAnchor && _hasPurposeScopedMetadata(opts.trustAnchor)) {
26549
+ if (!checkPurpose && _hasPurposeScopedMetadata(anchor)) {
26142
26550
  throw E("path/bad-input", "validate: the trust anchor carries purpose-scoped metadata (distrustAfter / purposes), which is keyed by key purpose -- supply opts.checkPurpose to say which purpose this validation is for, or the constraint cannot be applied");
26143
26551
  }
26144
26552
  for (var idx = 0; idx < n; idx++) {
@@ -26295,7 +26703,7 @@ var require_path_validate = __commonJS({
26295
26703
  }
26296
26704
  if (requireCriticalExt(liap, "inhibitAnyPolicy", checks)) failed = true;
26297
26705
  if (requiredEku && ekuPurposeFails(cert, requiredEku, checks)) failed = true;
26298
- var ta = opts.trustAnchor;
26706
+ var ta = anchor;
26299
26707
  var distrustDate = assertAnchorConstraints(ta, checkPurpose);
26300
26708
  if (distrustDate != null) {
26301
26709
  anchorDistrustApplied = true;
@@ -26936,11 +27344,13 @@ var require_path_validate = __commonJS({
26936
27344
  if (!ta || typeof ta !== "object") return false;
26937
27345
  return guard.list.anyMatches(["distrustAfter", "purposes"], function(k) {
26938
27346
  var m = ta[k];
26939
- return !!m && typeof m === "object" && Object.keys(m).length > 0;
27347
+ return !!m && typeof m === "object" && intrinsic.getOwnPropertyNames(m).length > 0;
26940
27348
  });
26941
27349
  }
26942
27350
  function assertAnchorConstraints(ta, checkPurpose) {
26943
- var d = checkPurpose && ta && ta.distrustAfter && intrinsic.hasOwn(ta.distrustAfter, checkPurpose) ? ta.distrustAfter[checkPurpose] : null;
27351
+ if (!checkPurpose || !ta) return null;
27352
+ var da = ta.distrustAfter;
27353
+ var d = da && intrinsic.hasOwn(da, checkPurpose) ? da[checkPurpose] : null;
26944
27354
  if (d == null) return null;
26945
27355
  return guard.time.assertValid(d, E, "path/bad-input", "trustAnchor.distrustAfter." + checkPurpose);
26946
27356
  }
@@ -26973,22 +27383,191 @@ var require_path_validate = __commonJS({
26973
27383
  }
26974
27384
  return { requiredEku, checkPurpose };
26975
27385
  }
26976
- function toAnchor(entry) {
26977
- if (entry && typeof entry === "object" && !Buffer.isBuffer(entry) && entry.name && entry.publicKey && entry.algorithm) {
26978
- if (!intrinsic.isArray(entry.name.rdns) || !Buffer.isBuffer(entry.publicKey) || typeof entry.algorithm !== "string") {
26979
- throw E("path/bad-input", "build: a trustAnchor tuple must be { name: { rdns: [...] }, publicKey: Buffer, algorithm: OID string }");
27386
+ function _snapshotConstraintMap(m, E2, code, who) {
27387
+ var out = {};
27388
+ var proto = intrinsic.getPrototypeOf(m);
27389
+ if (proto !== null && proto !== intrinsic.ObjectProto) throw E2(code, who + ": a trustAnchor constraint map must be a plain object (its own entries only), not one with a custom or cross-realm prototype");
27390
+ var keys = intrinsic.getOwnPropertyNames(m);
27391
+ if (intrinsic.ownKeys(m).length !== keys.length) throw E2(code, who + ": a trustAnchor constraint map must not have symbol-keyed entries");
27392
+ for (var i = 0; i < keys.length; i++) {
27393
+ if (keys[i] === "__proto__") throw E2(code, who + ": a trustAnchor constraint map must not have an own __proto__ entry");
27394
+ var d = intrinsic.getOwnPropertyDescriptor(m, keys[i]);
27395
+ if (!d || !intrinsic.hasOwn(d, "value")) throw E2(code, who + ": a trustAnchor constraint-map entry must be a data property, not an accessor");
27396
+ var v = d.value;
27397
+ if (intrinsic.types.isDate(v)) v = new intrinsic.Date(guard.time.instantOf(v));
27398
+ intrinsic.defineProperty(out, keys[i], { value: v, enumerable: true, configurable: true, writable: true });
27399
+ }
27400
+ return out;
27401
+ }
27402
+ function _normalizeConstraintField(v, E2, code, who) {
27403
+ if (v === null || v === void 0) return v;
27404
+ if (typeof v !== "object" || intrinsic.isBuffer(v)) throw E2(code, who + ": a trustAnchor constraint map must be a plain object");
27405
+ return _snapshotConstraintMap(v, E2, code, who);
27406
+ }
27407
+ function _captureConstraintMap(entry, key, E2, code, who) {
27408
+ var d = intrinsic.getOwnPropertyDescriptor(entry, key);
27409
+ if (d === void 0) {
27410
+ if (key in entry) throw E2(code, who + ": a trustAnchor " + key + " must be an own data property, not inherited");
27411
+ return void 0;
27412
+ }
27413
+ if (!intrinsic.hasOwn(d, "value")) throw E2(code, who + ": a trustAnchor " + key + " must be a data property, not an accessor");
27414
+ if (intrinsic.types.isProxy(d.value)) throw E2(code, who + ": a trustAnchor " + key + " map must not be a Proxy");
27415
+ return d.value;
27416
+ }
27417
+ function _captureOwnData(entry, key) {
27418
+ var d = intrinsic.getOwnPropertyDescriptor(entry, key);
27419
+ return d && intrinsic.hasOwn(d, "value") ? d.value : void 0;
27420
+ }
27421
+ function _copyAtv(atv) {
27422
+ var out = {};
27423
+ var t = atv.type;
27424
+ if (t !== void 0) intrinsic.defineProperty(out, "type", { value: t, enumerable: true, configurable: true, writable: true });
27425
+ var v = atv.value;
27426
+ if (v !== void 0) intrinsic.defineProperty(out, "value", { value: v, enumerable: true, configurable: true, writable: true });
27427
+ var nm = atv.name;
27428
+ if (nm !== void 0) intrinsic.defineProperty(out, "name", { value: nm, enumerable: true, configurable: true, writable: true });
27429
+ return out;
27430
+ }
27431
+ function _copyRdnsDeep(rdns) {
27432
+ if (!intrinsic.isArray(rdns)) return rdns;
27433
+ var out = [];
27434
+ out.length = rdns.length;
27435
+ for (var i = 0; i < rdns.length; i++) {
27436
+ if (!intrinsic.hasOwn(rdns, i)) continue;
27437
+ var rdn = rdns[i], val;
27438
+ if (intrinsic.isArray(rdn)) {
27439
+ var rdnOut = [];
27440
+ rdnOut.length = rdn.length;
27441
+ for (var j = 0; j < rdn.length; j++) {
27442
+ if (!intrinsic.hasOwn(rdn, j)) continue;
27443
+ var atv = rdn[j] !== null && typeof rdn[j] === "object" ? _copyAtv(rdn[j]) : rdn[j];
27444
+ intrinsic.defineProperty(rdnOut, j, { value: atv, enumerable: true, configurable: true, writable: true });
27445
+ }
27446
+ val = rdnOut;
27447
+ } else {
27448
+ val = rdn;
26980
27449
  }
26981
- return entry;
27450
+ intrinsic.defineProperty(out, i, { value: val, enumerable: true, configurable: true, writable: true });
27451
+ }
27452
+ return out;
27453
+ }
27454
+ function toAnchor(entry, verb) {
27455
+ var who = verb || "build";
27456
+ var isTuple = false, alg = null, pubRaw = null, nameRaw = null, pk = null, purposesSnap, distrustSnap;
27457
+ var subjectDerRaw, labelRaw, mozRaw;
27458
+ if (intrinsic.types.isProxy(entry)) {
27459
+ throw E("path/bad-input", who + ": a trustAnchor must not be a Proxy");
27460
+ }
27461
+ if (entry !== null && typeof entry === "object") {
27462
+ var proto = intrinsic.getPrototypeOf(entry);
27463
+ while (proto !== null) {
27464
+ if (intrinsic.types.isProxy(proto)) throw E("path/bad-input", who + ": a trustAnchor must not inherit from a Proxy");
27465
+ proto = intrinsic.getPrototypeOf(proto);
27466
+ }
27467
+ }
27468
+ try {
27469
+ if (entry && typeof entry === "object" && !Buffer.isBuffer(entry) && !guard.parsed.isRecorded(entry)) {
27470
+ var pRaw = _captureConstraintMap(entry, "purposes", E, "path/bad-input", who);
27471
+ purposesSnap = _normalizeConstraintField(pRaw, E, "path/bad-input", who);
27472
+ var dRaw = _captureConstraintMap(entry, "distrustAfter", E, "path/bad-input", who);
27473
+ distrustSnap = _normalizeConstraintField(dRaw, E, "path/bad-input", who);
27474
+ subjectDerRaw = _captureOwnData(entry, "subjectDer");
27475
+ labelRaw = _captureOwnData(entry, "label");
27476
+ mozRaw = _captureOwnData(entry, "mozillaCaPolicy");
27477
+ pubRaw = entry.publicKey;
27478
+ if (guard.bytes.isByteSource(pubRaw)) {
27479
+ pk = guard.bytes.snapshot(pubRaw, PathError, "path/bad-input", who + ": trustAnchor publicKey");
27480
+ }
27481
+ nameRaw = entry.name;
27482
+ alg = entry.algorithm;
27483
+ isTuple = !!(nameRaw && pubRaw && alg);
27484
+ }
27485
+ } catch (e) {
27486
+ throw E("path/bad-input", who + ": a trustAnchor accessor threw", e);
27487
+ }
27488
+ if (isTuple) {
27489
+ var algStr;
27490
+ try {
27491
+ if (typeof alg === "string") {
27492
+ algStr = alg;
27493
+ } else if (alg !== null && typeof alg === "object") {
27494
+ if (intrinsic.types.isProxy(alg)) throw E("path/bad-input", who + ": a trustAnchor algorithm must not be a Proxy");
27495
+ var algOidD = intrinsic.getOwnPropertyDescriptor(alg, "oid");
27496
+ if (algOidD && !intrinsic.hasOwn(algOidD, "value")) throw E("path/bad-input", who + ": a trustAnchor algorithm.oid must be a data property, not an accessor");
27497
+ var algOid = algOidD ? algOidD.value : void 0;
27498
+ algStr = typeof algOid === "string" ? algOid : null;
27499
+ } else {
27500
+ algStr = null;
27501
+ }
27502
+ } catch (e) {
27503
+ throw E("path/bad-input", who + ": a trustAnchor algorithm.oid accessor threw", e);
27504
+ }
27505
+ var nameOut = {};
27506
+ try {
27507
+ var nsrc = nameRaw !== null && typeof nameRaw === "object" ? nameRaw : null;
27508
+ if (nsrc !== null && intrinsic.types.isProxy(nsrc)) throw E("path/bad-input", who + ": a trustAnchor name must not be a Proxy");
27509
+ var rdnsD = nsrc ? intrinsic.getOwnPropertyDescriptor(nsrc, "rdns") : void 0;
27510
+ if (rdnsD && !intrinsic.hasOwn(rdnsD, "value")) throw E("path/bad-input", who + ": a trustAnchor name.rdns must be a data property, not an accessor");
27511
+ var rdnsVal = rdnsD ? rdnsD.value : void 0;
27512
+ if (rdnsVal !== void 0) {
27513
+ intrinsic.defineProperty(nameOut, "rdns", { value: _copyRdnsDeep(rdnsVal), enumerable: true, configurable: true, writable: true });
27514
+ }
27515
+ var bytesD = nsrc ? intrinsic.getOwnPropertyDescriptor(nsrc, "bytes") : void 0;
27516
+ if (bytesD && !intrinsic.hasOwn(bytesD, "value")) throw E("path/bad-input", who + ": a trustAnchor name.bytes must be a data property, not an accessor");
27517
+ var nBytes = bytesD ? bytesD.value : void 0;
27518
+ if (nBytes !== void 0) {
27519
+ intrinsic.defineProperty(nameOut, "bytes", { value: nBytes, enumerable: true, configurable: true, writable: true });
27520
+ }
27521
+ var dnD = nsrc ? intrinsic.getOwnPropertyDescriptor(nsrc, "dn") : void 0;
27522
+ if (dnD && !intrinsic.hasOwn(dnD, "value")) throw E("path/bad-input", who + ": a trustAnchor name.dn must be a data property, not an accessor");
27523
+ var nDn = dnD ? dnD.value : void 0;
27524
+ if (typeof nDn === "string") {
27525
+ intrinsic.defineProperty(nameOut, "dn", { value: nDn, enumerable: true, configurable: true, writable: true });
27526
+ }
27527
+ } catch (e) {
27528
+ throw E("path/bad-input", who + ": trustAnchor name could not be materialized", e);
27529
+ }
27530
+ var nameHasRdns = intrinsic.hasOwn(nameOut, "rdns") && intrinsic.isArray(nameOut.rdns);
27531
+ if (!nameHasRdns || !Buffer.isBuffer(pubRaw) || algStr === null) {
27532
+ throw E("path/bad-input", who + ": a trustAnchor tuple must be { name: { rdns: [...] }, publicKey: Buffer, algorithm: an OID string or a SubjectPublicKeyInfo algorithm carrying an oid }");
27533
+ }
27534
+ guard.identifier.assertCanonicalOid(algStr, E, "path/bad-input", who + ": trustAnchor algorithm " + algStr);
27535
+ var spkiAlg;
27536
+ try {
27537
+ spkiAlg = schema.walk(ANCHOR_SPKI_SCHEMA, asn1.decode(pk), NS).result.algorithm;
27538
+ } catch (e) {
27539
+ throw E("path/bad-input", who + ": trustAnchor publicKey is not a valid SubjectPublicKeyInfo", e);
27540
+ }
27541
+ if (spkiAlg.oid !== algStr) {
27542
+ throw E("path/bad-input", who + ": trustAnchor algorithm " + algStr + " does not match its publicKey key algorithm " + spkiAlg.oid);
27543
+ }
27544
+ var flat = {};
27545
+ intrinsic.defineProperty(flat, "name", { value: nameOut, enumerable: true, configurable: true, writable: true });
27546
+ if (purposesSnap !== void 0) intrinsic.defineProperty(flat, "purposes", { value: purposesSnap, enumerable: true, configurable: true, writable: true });
27547
+ if (distrustSnap !== void 0) intrinsic.defineProperty(flat, "distrustAfter", { value: distrustSnap, enumerable: true, configurable: true, writable: true });
27548
+ if (subjectDerRaw !== void 0) intrinsic.defineProperty(flat, "subjectDer", { value: subjectDerRaw, enumerable: true, configurable: true, writable: true });
27549
+ if (labelRaw !== void 0) intrinsic.defineProperty(flat, "label", { value: labelRaw, enumerable: true, configurable: true, writable: true });
27550
+ if (mozRaw !== void 0) intrinsic.defineProperty(flat, "mozillaCaPolicy", { value: mozRaw, enumerable: true, configurable: true, writable: true });
27551
+ intrinsic.defineProperty(flat, "publicKey", { value: pk, enumerable: true, configurable: true, writable: true });
27552
+ intrinsic.defineProperty(flat, "algorithm", { value: spkiAlg.oid, enumerable: true, configurable: true, writable: true });
27553
+ intrinsic.defineProperty(flat, "parameters", { value: spkiAlg.parameters, enumerable: true, configurable: true, writable: true });
27554
+ return flat;
27555
+ }
27556
+ if (entry && typeof entry === "object" && ("purposes" in entry || "distrustAfter" in entry)) {
27557
+ throw E("path/bad-input", who + ": a trustAnchor certificate must not carry purposes / distrustAfter -- put per-purpose constraints on a { name, publicKey, algorithm, purposes, distrustAfter } tuple (or a pki.trust anchor), not on a parsed certificate");
26982
27558
  }
26983
27559
  var cert;
26984
27560
  try {
26985
27561
  cert = coerceCert(entry);
26986
27562
  } catch (e) {
26987
- throw E("path/bad-input", "build: a trustAnchor entry must be a { name, publicKey, algorithm } tuple or a certificate", e);
27563
+ throw E("path/bad-input", who + ": a trustAnchor entry must be a { name, publicKey, algorithm } tuple or a certificate", e);
26988
27564
  }
26989
27565
  var spki = cert.subjectPublicKeyInfo;
26990
27566
  return { name: cert.subject, publicKey: spki.bytes, algorithm: spki.algorithm.oid, parameters: spki.algorithm.parameters, subjectDer: cert.subject.bytes };
26991
27567
  }
27568
+ function anchorFromCert(cert) {
27569
+ return toAnchor(cert, "anchorFromCert");
27570
+ }
26992
27571
  function identityKey(cert) {
26993
27572
  var san = findExt(cert, OID.subjectAltName);
26994
27573
  return cert.subject.bytes.toString("hex") + "|" + (san ? san.value.toString("hex") : "") + "|" + cert.subjectPublicKeyInfo.bytes.toString("hex");
@@ -27170,7 +27749,9 @@ var require_path_validate = __commonJS({
27170
27749
  var poolDerKeys = /* @__PURE__ */ new Set();
27171
27750
  for (var pdk = 0; pdk < pool.length; pdk++) intrinsic.setAdd(poolDerKeys, certDerKey(pool[pdk]));
27172
27751
  if (!intrinsic.isArray(opts.trustAnchors) || opts.trustAnchors.length === 0) throw E("path/bad-input", "build: opts.trustAnchors must be a non-empty array of anchor tuples or root certificates");
27173
- var anchors = opts.trustAnchors.map(toAnchor);
27752
+ var anchors = opts.trustAnchors.map(function(a) {
27753
+ return toAnchor(a, "build");
27754
+ });
27174
27755
  guard.time.assertValid(opts.time, E, "path/bad-input", "build: opts.time (the validity-window check date, forwarded to validate)");
27175
27756
  var effectiveMaxCerts = guard.limits.cap(opts.maxPathCerts, "build: opts.maxPathCerts", constants.LIMITS.PATH_MAX_CERTS, { E, code: "path/bad-input", min: 1 });
27176
27757
  var depthCeiling = effectiveMaxCerts - 1;
@@ -27325,6 +27906,7 @@ var require_path_validate = __commonJS({
27325
27906
  module2.exports = {
27326
27907
  validate,
27327
27908
  build,
27909
+ anchorFromCert,
27328
27910
  crlChecker,
27329
27911
  ocspChecker,
27330
27912
  verifyOcspResponse,
@@ -30473,7 +31055,7 @@ var require_x509_sign = __commonJS({
30473
31055
  }
30474
31056
  );
30475
31057
  guard.identifier.assertKnownKeys(opts, KNOWN_SIGN_OPTS, _err, "x509/bad-input", "pki.x509.sign has an unknown option ");
30476
- if (issuer.key == null) throw _err("x509/bad-input", "a signing key (issuer.key, a PKCS#8 private key) is required");
31058
+ if (issuer.key == null) throw _err("x509/bad-input", "a signing key (issuer.key, a WebCrypto CryptoKey or a PKCS#8 private key DER/PEM) is required");
30477
31059
  var spki = _reqDer(spec.subjectPublicKey, "spec.subjectPublicKey (the SPKI DER of the certified key)");
30478
31060
  _assertValidSpki(spki, "spec.subjectPublicKey");
30479
31061
  var subjectDer = _encodeName(spec.subject == null ? [] : spec.subject);
@@ -31085,7 +31667,7 @@ var require_attrcert_sign = __commonJS({
31085
31667
  if (!spec || typeof spec !== "object" || Buffer.isBuffer(spec)) throw _err("attrcert/bad-input", "the attribute-certificate spec must be an object");
31086
31668
  guard.identifier.assertKnownKeys(spec, KNOWN_SPEC_KEYS, _err, "attrcert/bad-input", "unknown spec field ");
31087
31669
  issuer = issuer || {};
31088
- if (issuer.key == null) throw _err("attrcert/bad-input", "a signing key (issuer.key, the AA's PKCS#8 private key) is required");
31670
+ if (issuer.key == null) throw _err("attrcert/bad-input", "a signing key (issuer.key, the AA's WebCrypto CryptoKey or PKCS#8 private key DER/PEM) is required");
31089
31671
  var issuerDnSpec, aaSpki;
31090
31672
  if (issuer.cert != null) {
31091
31673
  var aaCert = _parseCert(issuer.cert, "issuer.cert");
@@ -31803,7 +32385,7 @@ var require_crl_sign = __commonJS({
31803
32385
  }
31804
32386
  );
31805
32387
  guard.identifier.assertKnownKeys(opts, KNOWN_SIGN_OPTS, _err, "crl/bad-input", "pki.crl.sign has an unknown option ");
31806
- if (issuer.key == null) throw _err("crl/bad-input", "a signing key (issuer.key, a PKCS#8 private key) is required");
32388
+ if (issuer.key == null) throw _err("crl/bad-input", "a signing key (issuer.key, a WebCrypto CryptoKey or a PKCS#8 private key DER/PEM) is required");
31807
32389
  var issuerDer, issuerSpki, issuerCert = null;
31808
32390
  if (byCert) {
31809
32391
  issuerCert = _parseIssuerCert(issuer.cert);
@@ -37384,6 +37966,19 @@ var require_acme = __commonJS({
37384
37966
  sleep: 1,
37385
37967
  clock: 1
37386
37968
  };
37969
+ var _METHOD_OPTS = {
37970
+ finalize: { csr: 1, identifiers: 1 },
37971
+ poll: { maxPolls: 1, maxTotalWait: 1, onRetryAfter: 1 },
37972
+ download: { expectedSpki: 1, identifiers: 1, requireBinding: 1, selectChain: 1, maxAlternates: 1 },
37973
+ revoke: { certAlg: 1, certJwk: 1, certKey: 1, certificate: 1, reason: 1 },
37974
+ keyChange: { newAlg: 1, newJwk: 1, newKey: 1 },
37975
+ renewalWindow: { random: 1, clock: 1, replaced: 1, previous: 1 }
37976
+ };
37977
+ function _gateOpts(bag, whitelist, name) {
37978
+ bag = guard.identifier.optionsObject(bag, E, "acme/bad-input", "pki.acme " + name + " options");
37979
+ guard.identifier.assertKnownKeys(bag, whitelist, E, "acme/bad-input", "unknown " + name + " option ");
37980
+ return bag;
37981
+ }
37387
37982
  function client(directoryUrl, opts) {
37388
37983
  opts = guard.identifier.optionsObject(opts, E, "acme/bad-input", "pki.acme.client options");
37389
37984
  guard.identifier.assertKnownKeys(opts, _CLIENT_OPTS, E, "acme/bad-input", "unknown pki.acme.client option ");
@@ -37638,7 +38233,7 @@ var require_acme = __commonJS({
37638
38233
  });
37639
38234
  }
37640
38235
  function _finalizeBody(order, o) {
37641
- o = o || {};
38236
+ o = _gateOpts(o, _METHOD_OPTS.finalize, "finalize");
37642
38237
  if (!_isObject(order) || !_isString(order.finalize)) throw E("acme/bad-input", "finalize requires the order object with its finalize URL");
37643
38238
  if (!Array.isArray(order.identifiers)) throw E("acme/bad-input", "finalize requires the order's identifiers to enforce the RFC 8555 sec. 7.4 CSR-set match");
37644
38239
  return _post(_clientUrl(order.finalize), finalize, { csr: o.csr, identifiers: order.identifiers, accountJwk }, "kid").then(function(res) {
@@ -37646,9 +38241,9 @@ var require_acme = __commonJS({
37646
38241
  });
37647
38242
  }
37648
38243
  function _poll(kind, url, budget) {
37649
- budget = budget || {};
37650
38244
  var capPolls, capWait;
37651
38245
  try {
38246
+ budget = _gateOpts(budget, _METHOD_OPTS.poll, "poll");
37652
38247
  capPolls = budget.maxPolls != null ? guard.limits.cap(budget.maxPolls, "maxPolls", maxPolls, { E, code: "acme/bad-input", min: 1, max: 1e3 }) : maxPolls;
37653
38248
  capWait = budget.maxTotalWait != null ? guard.limits.cap(budget.maxTotalWait, "maxTotalWait", maxTotalWait, { E, code: "acme/bad-input", min: 0, max: retryAfter.MAX_RETRY_AFTER_SECONDS }) : maxTotalWait;
37654
38249
  url = _clientUrl(url);
@@ -37747,8 +38342,8 @@ var require_acme = __commonJS({
37747
38342
  }
37748
38343
  }
37749
38344
  function _downloadCertificate(url, opts2) {
37750
- opts2 = opts2 || {};
37751
38345
  return Promise.resolve().then(function() {
38346
+ opts2 = _gateOpts(opts2, _METHOD_OPTS.download, "downloadCertificate");
37752
38347
  var select = opts2.selectChain;
37753
38348
  if (select !== void 0 && typeof select !== "function") throw E("acme/bad-input", "downloadCertificate opts.selectChain must be a function");
37754
38349
  var maxAlt = guard.limits.cap(opts2.maxAlternates, "maxAlternates", DEFAULT_MAX_ALTERNATES, { E, code: "acme/bad-input", min: 0, max: 64 });
@@ -37797,22 +38392,24 @@ var require_acme = __commonJS({
37797
38392
  });
37798
38393
  }
37799
38394
  function _revokeCert(o) {
37800
- o = o || {};
37801
- if (!Buffer.isBuffer(o.certificate)) return Promise.reject(E("acme/bad-input", "revokeCert requires a DER certificate Buffer (opts.certificate)"));
37802
- var certKeyMode = o.certKey != null || _isObject(o.certJwk) || o.certAlg != null;
37803
- if (certKeyMode && !(o.certKey != null && _isObject(o.certJwk) && _isString(o.certAlg))) return Promise.reject(E("acme/bad-input", "revokeCert certificate-key mode requires certKey, certJwk, AND certAlg together, or none (RFC 8555 sec. 7.6)"));
37804
- var extra = { certificate: o.certificate };
37805
- if (o.reason !== void 0) extra.reason = o.reason;
37806
- return _resource("revokeCert").then(function(url) {
37807
- if (certKeyMode) {
37808
- return _postJws(url, function(nonce) {
37809
- return revokeCert(Object.assign({}, extra, { key: o.certKey, alg: o.certAlg, nonce, url, jwk: o.certJwk }));
37810
- }).then(function() {
38395
+ return _promised(function() {
38396
+ o = _gateOpts(o, _METHOD_OPTS.revoke, "revokeCert");
38397
+ if (!Buffer.isBuffer(o.certificate)) throw E("acme/bad-input", "revokeCert requires a DER certificate Buffer (opts.certificate)");
38398
+ var certKeyMode = o.certKey != null || _isObject(o.certJwk) || o.certAlg != null;
38399
+ if (certKeyMode && !(o.certKey != null && _isObject(o.certJwk) && _isString(o.certAlg))) throw E("acme/bad-input", "revokeCert certificate-key mode requires certKey, certJwk, AND certAlg together, or none (RFC 8555 sec. 7.6)");
38400
+ var extra = { certificate: o.certificate };
38401
+ if (o.reason !== void 0) extra.reason = o.reason;
38402
+ return _resource("revokeCert").then(function(url) {
38403
+ if (certKeyMode) {
38404
+ return _postJws(url, function(nonce) {
38405
+ return revokeCert(Object.assign({}, extra, { key: o.certKey, alg: o.certAlg, nonce, url, jwk: o.certJwk }));
38406
+ }).then(function() {
38407
+ return true;
38408
+ });
38409
+ }
38410
+ return _post(url, revokeCert, extra, "kid").then(function() {
37811
38411
  return true;
37812
38412
  });
37813
- }
37814
- return _post(url, revokeCert, extra, "kid").then(function() {
37815
- return true;
37816
38413
  });
37817
38414
  });
37818
38415
  }
@@ -37836,7 +38433,7 @@ var require_acme = __commonJS({
37836
38433
  });
37837
38434
  }
37838
38435
  function _keyChangeBody(o) {
37839
- o = o || {};
38436
+ o = _gateOpts(o, _METHOD_OPTS.keyChange, "keyChange");
37840
38437
  if (!o.newKey || !_isObject(o.newJwk) || !_isString(o.newAlg)) throw E("acme/bad-input", "keyChange requires newKey, newJwk, and newAlg");
37841
38438
  var account = _requireKid();
37842
38439
  return _resource("keyChange").then(function(url) {
@@ -37895,8 +38492,8 @@ var require_acme = __commonJS({
37895
38492
  });
37896
38493
  }
37897
38494
  function _renewalWindow(certDer, o) {
37898
- o = o || {};
37899
38495
  return Promise.resolve().then(function() {
38496
+ o = _gateOpts(o, _METHOD_OPTS.renewalWindow, "renewalWindow");
37900
38497
  if (!Buffer.isBuffer(certDer)) throw E("acme/bad-input", "renewalWindow requires a DER certificate Buffer");
37901
38498
  if (o.random !== void 0 && typeof o.random !== "function") throw E("acme/bad-input", "renewalWindow opts.random must be a function returning a number in [0, 1]");
37902
38499
  if (o.clock !== void 0 && typeof o.clock !== "function") throw E("acme/bad-input", "renewalWindow opts.clock must be a function returning epoch milliseconds");