@blamejs/core 0.18.54 → 0.18.56

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 (48) hide show
  1. package/CHANGELOG.md +146 -0
  2. package/NOTICE +5 -5
  3. package/README.md +9 -9
  4. package/lib/agent-audit.js +27 -2
  5. package/lib/audit-sign.js +24 -5
  6. package/lib/audit.js +26 -24
  7. package/lib/auth/passkey.js +4 -1
  8. package/lib/chain-writer.js +17 -0
  9. package/lib/db-file-lifecycle.js +14 -3
  10. package/lib/db.js +505 -49
  11. package/lib/guard-filename.js +8 -1
  12. package/lib/guard-html.js +10 -2
  13. package/lib/guard-list-unsubscribe.js +6 -1
  14. package/lib/guard-managesieve-command.js +24 -3
  15. package/lib/guard-smtp-command.js +20 -4
  16. package/lib/guard-svg.js +6 -1
  17. package/lib/http-client.js +17 -3
  18. package/lib/mail-agent.js +6 -4
  19. package/lib/mail-auth.js +59 -2
  20. package/lib/mail-server-imap.js +65 -34
  21. package/lib/mail-server-managesieve.js +65 -42
  22. package/lib/mail-server-mx.js +313 -40
  23. package/lib/mail-server-net.js +155 -1
  24. package/lib/mail-server-pop3.js +16 -19
  25. package/lib/mail-server-rate-limit.js +104 -6
  26. package/lib/mail-server-submission.js +162 -33
  27. package/lib/mail-server-tls.js +71 -11
  28. package/lib/mcp.js +11 -3
  29. package/lib/middleware/csrf-protect.js +37 -20
  30. package/lib/middleware/require-mtls.js +8 -1
  31. package/lib/network-tls.js +18 -0
  32. package/lib/safe-mount-info.js +39 -6
  33. package/lib/safe-smtp.js +96 -1
  34. package/lib/safe-url.js +8 -2
  35. package/lib/self-update.js +4 -1
  36. package/lib/session-stores.js +6 -3
  37. package/lib/vendor/MANIFEST.json +34 -34
  38. package/lib/vendor/blamejs-pki.cjs +396 -37
  39. package/lib/vendor/browser/noble-ciphers.mjs +15 -1
  40. package/lib/vendor/browser/noble-hashes.mjs +12 -4
  41. package/lib/vendor/browser/noble-post-quantum.mjs +78 -37
  42. package/lib/vendor/noble-ciphers.cjs +15 -1
  43. package/lib/vendor/noble-curves.cjs +46 -21
  44. package/lib/vendor/noble-post-quantum.cjs +184 -75
  45. package/lib/watcher.js +31 -6
  46. package/lib/ws-client.js +17 -2
  47. package/package.json +1 -1
  48. package/sbom.cdx.json +6 -6
@@ -1,4 +1,4 @@
1
- // @blamejs/pki v0.5.30 — 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.30",
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",
@@ -5756,6 +5756,7 @@ var require_asn1_der = __commonJS({
5756
5756
  return _asBuffer(buf, "build.raw");
5757
5757
  }
5758
5758
  };
5759
+ intrinsic.freeze(build);
5759
5760
  function _intContent(v, who) {
5760
5761
  if (Buffer.isBuffer(v)) {
5761
5762
  if (v.length === 0) throw new Asn1Error("asn1/bad-integer", who + ": INTEGER content is empty");
@@ -18413,7 +18414,10 @@ var require_sign_scheme = __commonJS({
18413
18414
  }
18414
18415
  function _assertKeyMatchesScheme(key, imp, E) {
18415
18416
  var ka = key.algorithm || {};
18416
- 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
+ }
18417
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 + ")");
18418
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 + ")");
18419
18423
  }
@@ -18436,7 +18440,10 @@ var require_sign_scheme = __commonJS({
18436
18440
  return { mldsa: _normPkcs8(key.mldsa, "the composite ML-DSA component key", E), trad: _normPkcs8(key.trad, "the composite traditional component key", E) };
18437
18441
  }
18438
18442
  function _importKey(key, imp, E) {
18439
- 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
+ }
18440
18447
  _assertKeyMatchesScheme(key, imp, E);
18441
18448
  return webcrypto.adoptKey(key, imp, ["sign"], E, "bad-input");
18442
18449
  }
@@ -18452,7 +18459,9 @@ var require_sign_scheme = __commonJS({
18452
18459
  throw E("bad-input", "the signer PEM private key could not be decoded", e);
18453
18460
  }
18454
18461
  owned = true;
18455
- } 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");
18456
18465
  var imported = subtle.importKey("pkcs8", der, imp, false, ["sign"]);
18457
18466
  if (!owned) return imported;
18458
18467
  return imported.then(function(k) {
@@ -18492,35 +18501,101 @@ var require_sign_scheme = __commonJS({
18492
18501
  var require_ip_utils = __commonJS({
18493
18502
  "node_modules/@blamejs/pki/lib/ip-utils.js"(exports2, module2) {
18494
18503
  "use strict";
18495
- 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
+ }
18496
18544
  function isIPv4(s) {
18497
- 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;
18498
18572
  }
18499
18573
  var IPV6_TEXT_MAX_LEN = 45;
18500
18574
  function expandIpv6Hex(ip) {
18501
- if (typeof ip !== "string" || ip.length > IPV6_TEXT_MAX_LEN || ip.indexOf(":") === -1) return null;
18502
- var dual = ip.match(/^(.*):(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/);
18503
- if (dual) {
18504
- if (!isIPv4(dual[2])) return null;
18505
- var v4 = dual[2].split(".").map(Number);
18506
- ip = dual[1] + ":" + (v4[0] << 8 | v4[1]).toString(16) + ":" + (v4[2] << 8 | v4[3]).toString(16);
18507
- }
18508
- 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, "::");
18509
18584
  if (dbl.length > 2) return null;
18510
- var left = dbl[0] === "" ? [] : dbl[0].split(":");
18511
- 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], ":") : [];
18512
18587
  if (dbl.length === 1 && left.length !== 8) return null;
18513
18588
  var fill = 8 - left.length - right.length;
18514
18589
  if (dbl.length === 2 ? fill < 1 : fill !== 0) return null;
18515
18590
  var groups = left, i;
18516
- for (i = 0; i < fill; i += 1) groups = groups.concat(["0"]);
18517
- 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]);
18518
18593
  if (groups.length !== 8) return null;
18519
18594
  var hex = "";
18520
18595
  for (i = 0; i < 8; i += 1) {
18521
18596
  var g = groups[i];
18522
- if (g.length < 1 || g.length > 4 || !/^[0-9a-f]+$/i.test(g)) return null;
18523
- hex += g.toLowerCase().padStart(4, "0");
18597
+ if (!_isHexGroup(g)) return null;
18598
+ hex += _padStart(_toLowerCase(g), 4, "0");
18524
18599
  }
18525
18600
  return hex;
18526
18601
  }
@@ -18528,11 +18603,15 @@ var require_ip_utils = __commonJS({
18528
18603
  return isIPv4(s) || expandIpv6Hex(s) !== null;
18529
18604
  }
18530
18605
  function packIpLiteral(s) {
18531
- 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
+ }
18532
18611
  var hex = expandIpv6Hex(s);
18533
- return hex === null ? null : Buffer.from(hex, "hex");
18612
+ return hex === null ? null : _bufferFrom(hex, "hex");
18534
18613
  }
18535
- module2.exports = { isIPv4, expandIpv6Hex, isIpLiteral, packIpLiteral, IPV4_RE };
18614
+ module2.exports = { isIPv4, expandIpv6Hex, isIpLiteral, packIpLiteral };
18536
18615
  }
18537
18616
  });
18538
18617
 
@@ -18550,10 +18629,275 @@ var require_pki_build = __commonJS({
18550
18629
  var _bufferEquals = intrinsic.bufferEquals;
18551
18630
  var oid = require_oid();
18552
18631
  var ipUtils = require_ip_utils();
18632
+ var _packIpLiteral = ipUtils.packIpLiteral;
18553
18633
  var nodeCrypto = require("crypto");
18554
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
+ }
18555
18900
  var b = asn1.build;
18556
- var DOTTED_OID_RE = /^[0-2](?:\.(?:0|[1-9]\d*))+$/;
18557
18901
  var KU_BIT = {
18558
18902
  digitalSignature: 0,
18559
18903
  nonRepudiation: 1,
@@ -18639,15 +18983,30 @@ var require_pki_build = __commonJS({
18639
18983
  return asn1.decode(nameDer).children.length === 0;
18640
18984
  }
18641
18985
  function ia5Content(s) {
18642
- s = String(s);
18986
+ s = _String(s);
18643
18987
  for (var i = 0; i < s.length; i++) {
18644
- 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));
18645
18989
  }
18646
- 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 + " }");
18647
19002
  }
18648
19003
  function encodeGeneralName(entry) {
18649
- if (!entry || typeof entry !== "object" || Buffer.isBuffer(entry)) throw E("bad-input", "a GeneralName must be an object with exactly one name form");
18650
- 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);
18651
19010
  if (keys.length !== 1) throw E("bad-input", "a GeneralName entry must have exactly one form, got " + keys.length);
18652
19011
  var k = keys[0], v = entry[k];
18653
19012
  if (v == null || v === "") throw E("bad-input", "an empty GeneralName value is not permitted (RFC 5280 sec. 4.2.1.6)");
@@ -18662,10 +19021,10 @@ var require_pki_build = __commonJS({
18662
19021
  case "iPAddress":
18663
19022
  var ipBuf = v;
18664
19023
  if (typeof v === "string") {
18665
- ipBuf = ipUtils.packIpLiteral(v);
18666
- 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));
18667
19026
  }
18668
- 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");
18669
19028
  return b.contextPrimitive(7, ipBuf);
18670
19029
  case "directoryName":
18671
19030
  return b.explicit(4, encodeName(v));
@@ -18700,7 +19059,7 @@ var require_pki_build = __commonJS({
18700
19059
  function _resolveOid(n, label) {
18701
19060
  var dotted = O(n);
18702
19061
  if (dotted != null) return dotted;
18703
- if (typeof n === "string" && DOTTED_OID_RE.test(n)) {
19062
+ if (typeof n === "string" && _isDottedOid(n)) {
18704
19063
  try {
18705
19064
  b.oid(n);
18706
19065
  } catch (e) {
@@ -30696,7 +31055,7 @@ var require_x509_sign = __commonJS({
30696
31055
  }
30697
31056
  );
30698
31057
  guard.identifier.assertKnownKeys(opts, KNOWN_SIGN_OPTS, _err, "x509/bad-input", "pki.x509.sign has an unknown option ");
30699
- 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");
30700
31059
  var spki = _reqDer(spec.subjectPublicKey, "spec.subjectPublicKey (the SPKI DER of the certified key)");
30701
31060
  _assertValidSpki(spki, "spec.subjectPublicKey");
30702
31061
  var subjectDer = _encodeName(spec.subject == null ? [] : spec.subject);
@@ -31308,7 +31667,7 @@ var require_attrcert_sign = __commonJS({
31308
31667
  if (!spec || typeof spec !== "object" || Buffer.isBuffer(spec)) throw _err("attrcert/bad-input", "the attribute-certificate spec must be an object");
31309
31668
  guard.identifier.assertKnownKeys(spec, KNOWN_SPEC_KEYS, _err, "attrcert/bad-input", "unknown spec field ");
31310
31669
  issuer = issuer || {};
31311
- 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");
31312
31671
  var issuerDnSpec, aaSpki;
31313
31672
  if (issuer.cert != null) {
31314
31673
  var aaCert = _parseCert(issuer.cert, "issuer.cert");
@@ -32026,7 +32385,7 @@ var require_crl_sign = __commonJS({
32026
32385
  }
32027
32386
  );
32028
32387
  guard.identifier.assertKnownKeys(opts, KNOWN_SIGN_OPTS, _err, "crl/bad-input", "pki.crl.sign has an unknown option ");
32029
- 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");
32030
32389
  var issuerDer, issuerSpki, issuerCert = null;
32031
32390
  if (byCert) {
32032
32391
  issuerCert = _parseIssuerCert(issuer.cert);
@@ -1,4 +1,4 @@
1
- // XChaCha20-Poly1305 — vendored from @noble/ciphers v2.3.0 by Paul Miller
1
+ // XChaCha20-Poly1305 — vendored from @noble/ciphers v2.4.0 by Paul Miller
2
2
  // License: MIT — https://github.com/paulmillr/noble-ciphers
3
3
  // Browser build (ESM), bundled with esbuild from the same install as the
4
4
  // server bundle beside it. Exports: xchacha20poly1305
@@ -71,6 +71,17 @@ function byteSwap32(arr) {
71
71
  return arr;
72
72
  }
73
73
  var swap32IfBE = isLE ? (u) => u : byteSwap32;
74
+ function overlapBytes(a, b) {
75
+ if (!a.byteLength || !b.byteLength)
76
+ return false;
77
+ return a.buffer === b.buffer && // best we can do, may fail with an obscure Proxy
78
+ a.byteOffset < b.byteOffset + b.byteLength && // a starts before b end
79
+ b.byteOffset < a.byteOffset + a.byteLength;
80
+ }
81
+ function complexOverlapBytes(input, output) {
82
+ if (overlapBytes(input, output) && input.byteOffset < output.byteOffset)
83
+ throw new Error("complex overlap of input and output is not supported");
84
+ }
74
85
  function checkOpts(defaults, opts) {
75
86
  aobject(defaults, "defaults");
76
87
  aobject(opts, "opts");
@@ -238,7 +249,10 @@ function createCipher(core, opts) {
238
249
  abytes(nonce, void 0, "nonce");
239
250
  abytes(data, void 0, "data");
240
251
  const len = data.length;
252
+ const hasOutput = output !== void 0;
241
253
  output = getOutput(len, output, false);
254
+ if (hasOutput)
255
+ complexOverlapBytes(data, output);
242
256
  anumber(counter);
243
257
  if (counter < 0 || counter >= MAX_COUNTER)
244
258
  throw new Error("arx: counter overflow");
@@ -1,4 +1,4 @@
1
- // @noble/hashes v2.3.0 — vendored from Paul Miller
1
+ // @noble/hashes v2.4.0 — vendored from Paul Miller
2
2
  // License: MIT — https://github.com/paulmillr/noble-hashes
3
3
  // Browser build (ESM), bundled with esbuild. The server side uses node:crypto
4
4
  // for these, so there is no .cjs beside it.
@@ -89,6 +89,14 @@ var aobject = (value, label) => {
89
89
  if (value === null || typeof value !== "object" || Array.isArray(value))
90
90
  throw new TypeError((label === "object" ? "" : `"${label}" `) + "expected object, got type=" + typeof value);
91
91
  };
92
+ var aopts = (value, label) => {
93
+ aobject(value, label);
94
+ const proto = Object.getPrototypeOf(value);
95
+ if (proto !== Object.prototype && proto !== null)
96
+ throw new TypeError(`"${label}" expected plain object`);
97
+ if (Object.hasOwn(value, "__proto__"))
98
+ throw new TypeError(`"${label}.__proto__" is not allowed`);
99
+ };
92
100
  function aexists(instance, checkFinished = true) {
93
101
  if (instance.destroyed)
94
102
  throw new Error("hash was destroyed");
@@ -128,10 +136,10 @@ function byteSwap32(arr) {
128
136
  }
129
137
  var swap32IfBE = isLE ? (u) => u : byteSwap32;
130
138
  function checkOpts(defaults, opts, title = "opts") {
131
- aobject(defaults, "defaults");
139
+ aopts(defaults, "defaults");
132
140
  if (opts !== void 0)
133
- aobject(opts, title);
134
- const merged = Object.assign(defaults, opts);
141
+ aopts(opts, title);
142
+ const merged = Object.assign(/* @__PURE__ */ Object.create(null), defaults, opts);
135
143
  return merged;
136
144
  }
137
145
  function createHasher(hashCons, info = {}) {