micro509 0.17.1 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/CHANGELOG.md +78 -6
  2. package/dist/crypto/crypto.d.ts +2 -3
  3. package/dist/crypto.d.ts +6 -0
  4. package/dist/der/der.d.ts +14 -4
  5. package/dist/der/der.js +19 -19
  6. package/dist/der.d.ts +26 -2
  7. package/dist/der.js +4 -4
  8. package/dist/index.d.ts +82 -15
  9. package/dist/index.js +19 -19
  10. package/dist/internal/asn1/asn1.d.ts +1 -2
  11. package/dist/internal/asn1/der.d.ts +1 -2
  12. package/dist/internal/asn1/oids.js +71 -353
  13. package/dist/internal/asn1/oids.js.map +1 -1
  14. package/dist/internal/asn1/oids.json.js +357 -0
  15. package/dist/internal/asn1/oids.json.js.map +1 -0
  16. package/dist/internal/crypto/algorithm-names.js +1 -1
  17. package/dist/internal/crypto/pbes2.d.ts +1 -2
  18. package/dist/internal/crypto/pbes2.js +70 -70
  19. package/dist/internal/crypto/prime-ec.js +37 -0
  20. package/dist/internal/crypto/prime-ec.js.map +1 -0
  21. package/dist/internal/crypto/rsa-pss.js +50 -50
  22. package/dist/internal/crypto/sig-verify.d.ts +1 -2
  23. package/dist/internal/crypto/sig-verify.js +60 -60
  24. package/dist/internal/crypto/signing.d.ts +1 -2
  25. package/dist/internal/crypto/signing.js +26 -26
  26. package/dist/internal/jose/json-data.js +108 -0
  27. package/dist/internal/jose/json-data.js.map +1 -0
  28. package/dist/internal/jose/strict-json.d.ts +1 -2
  29. package/dist/internal/shared/dn.d.ts +1 -2
  30. package/dist/internal/shared/dn.js +1 -1
  31. package/dist/internal/shared/ip.d.ts +1 -2
  32. package/dist/internal/verify/name-constraints-engine.js +64 -64
  33. package/dist/internal/verify/policy-engine.js +1 -1
  34. package/dist/internal/verify/verify-path.d.ts +1 -2
  35. package/dist/internal/verify/verify-path.js +19 -19
  36. package/dist/internal/x509/directory-name.js +10 -10
  37. package/dist/internal/x509/extension-errors.d.ts +1 -2
  38. package/dist/internal/x509/extension-registry.js +18 -18
  39. package/dist/internal/x509/general-name-profile.js +9 -9
  40. package/dist/internal/x509/general-name.js +32 -32
  41. package/dist/internal/x509/name-fields.js +1 -1
  42. package/dist/jose/base64url.d.ts +4 -0
  43. package/dist/jose/base64url.js +14 -0
  44. package/dist/jose/base64url.js.map +1 -0
  45. package/dist/jose/errors.d.ts +9 -3
  46. package/dist/jose/errors.js.map +1 -1
  47. package/dist/jose/jwe.d.ts +64 -0
  48. package/dist/jose/jwe.js +188 -0
  49. package/dist/jose/jwe.js.map +1 -0
  50. package/dist/jose/jwks.d.ts +38 -10
  51. package/dist/jose/jwks.js +156 -96
  52. package/dist/jose/jwks.js.map +1 -1
  53. package/dist/jose/jws.d.ts +8 -6
  54. package/dist/jose/jws.js +216 -170
  55. package/dist/jose/jws.js.map +1 -1
  56. package/dist/jose/jwt.d.ts +8 -2
  57. package/dist/jose/jwt.js +98 -98
  58. package/dist/jose/remote-jwks.d.ts +1 -2
  59. package/dist/jose/remote-jwks.js +106 -108
  60. package/dist/jose/remote-jwks.js.map +1 -1
  61. package/dist/jose.d.ts +15 -4
  62. package/dist/jose.js +7 -5
  63. package/dist/kdf/argon2.d.ts +7 -2
  64. package/dist/kdf.d.ts +6 -0
  65. package/dist/keys/keys.d.ts +31 -6
  66. package/dist/keys/keys.js +315 -233
  67. package/dist/keys/keys.js.map +1 -1
  68. package/dist/keys.d.ts +11 -2
  69. package/dist/keys.js +2 -2
  70. package/dist/pem/pem.d.ts +1 -2
  71. package/dist/pem/pem.js +40 -25
  72. package/dist/pem/pem.js.map +1 -1
  73. package/dist/pem.d.ts +6 -0
  74. package/dist/pkcs/pfx.d.ts +2 -3
  75. package/dist/pkcs/pfx.js +142 -142
  76. package/dist/pkcs/pkcs12-mac.d.ts +1 -2
  77. package/dist/pkcs/pkcs12-mac.js +122 -122
  78. package/dist/pkcs/pkcs7.d.ts +14 -3
  79. package/dist/pkcs/pkcs7.js +268 -248
  80. package/dist/pkcs/pkcs7.js.map +1 -1
  81. package/dist/pkcs.d.ts +10 -1
  82. package/dist/pkcs.js +4 -4
  83. package/dist/result/result.d.ts +1 -2
  84. package/dist/result.d.ts +6 -0
  85. package/dist/revocation/chain.d.ts +2 -3
  86. package/dist/revocation/chain.js +52 -52
  87. package/dist/revocation/crl.d.ts +2 -3
  88. package/dist/revocation/crl.js +319 -319
  89. package/dist/revocation/crl.js.map +1 -1
  90. package/dist/revocation/ocsp.d.ts +2 -3
  91. package/dist/revocation/ocsp.js +395 -395
  92. package/dist/revocation/revocation.d.ts +2 -3
  93. package/dist/revocation/revocation.js +22 -22
  94. package/dist/revocation.d.ts +12 -3
  95. package/dist/revocation.js +4 -4
  96. package/dist/ssh/ssh.d.ts +2 -3
  97. package/dist/ssh/ssh.js +165 -170
  98. package/dist/ssh/ssh.js.map +1 -1
  99. package/dist/ssh/wire.d.ts +1 -2
  100. package/dist/ssh/wire.js +10 -10
  101. package/dist/ssh.d.ts +8 -0
  102. package/dist/verify/identity.d.ts +1 -2
  103. package/dist/verify/identity.js +31 -31
  104. package/dist/verify/name-constraints.d.ts +9 -2
  105. package/dist/verify/policy.d.ts +9 -2
  106. package/dist/verify/verify.d.ts +3 -4
  107. package/dist/verify/verify.js +121 -121
  108. package/dist/verify.d.ts +9 -0
  109. package/dist/x509/certificate.d.ts +4 -5
  110. package/dist/x509/certificate.js +40 -40
  111. package/dist/x509/csr.d.ts +3 -4
  112. package/dist/x509/csr.js +15 -15
  113. package/dist/x509/extensions.d.ts +1 -2
  114. package/dist/x509/extensions.js +165 -165
  115. package/dist/x509/extensions.js.map +1 -1
  116. package/dist/x509/fingerprint.d.ts +1 -2
  117. package/dist/x509/name-text.d.ts +1 -2
  118. package/dist/x509/name.d.ts +1 -2
  119. package/dist/x509/name.js +15 -15
  120. package/dist/x509/parse.d.ts +3 -4
  121. package/dist/x509/parse.js +423 -423
  122. package/dist/x509.d.ts +17 -4
  123. package/dist/x509.js +8 -8
  124. package/package.json +22 -23
  125. package/dist/internal/asn1/oids2.js +0 -75
  126. package/dist/internal/asn1/oids2.js.map +0 -1
@@ -1,7 +1,7 @@
1
- import { DECODE_LIMIT_CODES as e, rethrowDecodeRefusal as t } from "../asn1/decode-refusal.js";
2
- import { explicitContext as n, integerFromNumber as r, nullValue as i, objectIdentifier as a, readRootElement as o, sequence as s } from "../asn1/der.js";
3
- import { childrenOf as c, decodeNonNegativeIntegerNumber as l, decodeObjectIdentifier as u, requireElement as d } from "../asn1/asn1.js";
4
- import { OIDS as f } from "../asn1/oids2.js";
1
+ import { childrenOf as e, decodeNonNegativeIntegerNumber as t, decodeObjectIdentifier as n, requireElement as r } from "../asn1/asn1.js";
2
+ import { DECODE_LIMIT_CODES as i, rethrowDecodeRefusal as a } from "../asn1/decode-refusal.js";
3
+ import { explicitContext as o, integerFromNumber as s, nullValue as c, objectIdentifier as l, readRootElement as u, sequence as d } from "../asn1/der.js";
4
+ import { OIDS as f } from "../asn1/oids.js";
5
5
  /** Return the canonical {@linkcode RsaPssParameters} profile for a given hash algorithm. */
6
6
  function rsaPssParametersForHash(e) {
7
7
  switch (e) {
@@ -28,12 +28,12 @@ function rsaPssParametersForHash(e) {
28
28
  }
29
29
  /** DER-encode an {@linkcode RsaPssParameters} profile as an ASN.1 RSASSA-PSS-params SEQUENCE. */
30
30
  function encodeRsaPssParameters(e) {
31
- let t = hashOidForName(e.hash), i = encodeHashAlgorithmIdentifier(t);
32
- return s([
33
- n(0, i),
34
- n(1, s([a(f.mgf1), encodeHashAlgorithmIdentifier(t)])),
35
- n(2, r(e.saltLength)),
36
- ...e.trailerField === 1 ? [] : [n(3, r(e.trailerField))]
31
+ let t = hashOidForName(e.hash), n = encodeHashAlgorithmIdentifier(t);
32
+ return d([
33
+ o(0, n),
34
+ o(1, d([l(f.mgf1), encodeHashAlgorithmIdentifier(t)])),
35
+ o(2, s(e.saltLength)),
36
+ ...e.trailerField === 1 ? [] : [o(3, s(e.trailerField))]
37
37
  ]);
38
38
  }
39
39
  /**
@@ -44,23 +44,23 @@ function encodeRsaPssParameters(e) {
44
44
  *
45
45
  * @throws `limit_exceeded` on an OID sub-identifier over 64 octets.
46
46
  */
47
- function parseRsaPssParameters(n) {
48
- if (n === void 0) return unsupportedResult("default_hash_sha1");
47
+ function parseRsaPssParameters(e) {
48
+ if (e === void 0) return unsupportedResult("default_hash_sha1");
49
49
  try {
50
- let e = o(n, { maxDepth: 64 });
51
- if (e.tag !== 48) throw Error("RSA-PSS parameters must be a SEQUENCE");
52
- return validateRsaPssParameterProfile(parseRsaPssParameterFields(n, e));
53
- } catch (n) {
54
- return t(n, e), {
50
+ let t = u(e, { maxDepth: 64 });
51
+ if (t.tag !== 48) throw Error("RSA-PSS parameters must be a SEQUENCE");
52
+ return validateRsaPssParameterProfile(parseRsaPssParameterFields(e, t));
53
+ } catch (e) {
54
+ return a(e, i), {
55
55
  ok: !1,
56
56
  code: "malformed_rsa_pss_parameters",
57
- reason: n instanceof Error ? n.message : "Malformed RSA-PSS parameters"
57
+ reason: e instanceof Error ? e.message : "Malformed RSA-PSS parameters"
58
58
  };
59
59
  }
60
60
  }
61
61
  /** Parses the optional context-specific RSA-PSS fields into their defaulted state. */
62
- function parseRsaPssParameterFields(e, t) {
63
- let n = {
62
+ function parseRsaPssParameterFields(t, n) {
63
+ let r = {
64
64
  hashOid: f.sha1,
65
65
  maskGenAlgorithm: {
66
66
  oid: f.mgf1,
@@ -73,8 +73,8 @@ function parseRsaPssParameterFields(e, t) {
73
73
  sawSaltLength: !1,
74
74
  sawTrailerField: !1
75
75
  };
76
- for (let r of c(e, t)) parseRsaPssParameterField(e, r, n);
77
- return n;
76
+ for (let i of e(t, n)) parseRsaPssParameterField(t, i, r);
77
+ return r;
78
78
  }
79
79
  function parseRsaPssParameterField(e, t, n) {
80
80
  switch (t.tag) {
@@ -113,43 +113,43 @@ function validateRsaPssParameterProfile(e) {
113
113
  } : unsupportedResult("unsupported_trailer_field") : unsupportedResult("unsupported_salt_length");
114
114
  }
115
115
  /** Unwrap an explicit context tag and assert it contains exactly one child element. */
116
- function requireSingleExplicitChild(e, t, n) {
117
- let r = c(e, t);
118
- if (r.length !== 1) throw Error(`RSA-PSS ${n} must wrap exactly one value`);
119
- return d(r[0], `RSA-PSS ${n}`);
116
+ function requireSingleExplicitChild(t, n, i) {
117
+ let a = e(t, n);
118
+ if (a.length !== 1) throw Error(`RSA-PSS ${i} must wrap exactly one value`);
119
+ return r(a[0], `RSA-PSS ${i}`);
120
120
  }
121
121
  /** Extract a non-negative integer from an explicit context-tagged wrapper. */
122
- function parseExplicitInteger(e, t, n, r) {
123
- let i = requireSingleExplicitChild(e, t, n);
124
- if (i.tag !== 2) throw Error(`RSA-PSS ${n} must be an INTEGER`);
125
- return l(i.value, r);
122
+ function parseExplicitInteger(e, n, r, i) {
123
+ let a = requireSingleExplicitChild(e, n, r);
124
+ if (a.tag !== 2) throw Error(`RSA-PSS ${r} must be an INTEGER`);
125
+ return t(a.value, i);
126
126
  }
127
127
  /** Parse an AlgorithmIdentifier SEQUENCE and return the algorithm OID. */
128
- function parseHashAlgorithmIdentifier(e, t, n) {
129
- if (t.tag !== 48) throw Error(`RSA-PSS ${n} must be a SEQUENCE`);
130
- let r = c(e, t);
131
- if (r.length === 0 || r.length > 2) throw Error(`Malformed RSA-PSS ${n} AlgorithmIdentifier`);
132
- let i = d(r[0], `${n} OID`);
133
- if (i.tag !== 6) throw Error(`Malformed RSA-PSS ${n} AlgorithmIdentifier`);
134
- if (r.length === 2 && d(r[1], `${n} parameters`).tag !== 5) throw Error(`RSA-PSS ${n} AlgorithmIdentifier parameters must be NULL when present`);
135
- return u(i.value);
128
+ function parseHashAlgorithmIdentifier(t, i, a) {
129
+ if (i.tag !== 48) throw Error(`RSA-PSS ${a} must be a SEQUENCE`);
130
+ let o = e(t, i);
131
+ if (o.length === 0 || o.length > 2) throw Error(`Malformed RSA-PSS ${a} AlgorithmIdentifier`);
132
+ let s = r(o[0], `${a} OID`);
133
+ if (s.tag !== 6) throw Error(`Malformed RSA-PSS ${a} AlgorithmIdentifier`);
134
+ if (o.length === 2 && r(o[1], `${a} parameters`).tag !== 5) throw Error(`RSA-PSS ${a} AlgorithmIdentifier parameters must be NULL when present`);
135
+ return n(s.value);
136
136
  }
137
137
  /** Parse an MGF AlgorithmIdentifier SEQUENCE into OID and optional inner hash OID. */
138
- function parseMaskGenAlgorithmIdentifier(e, t) {
139
- if (t.tag !== 48) throw Error("RSA-PSS maskGenAlgorithm must be a SEQUENCE");
140
- let n = c(e, t);
141
- if (n.length === 0 || n.length > 2) throw Error("Malformed RSA-PSS maskGenAlgorithm AlgorithmIdentifier");
142
- let r = d(n[0], "maskGenAlgorithm OID");
143
- if (r.tag !== 6) throw Error("Malformed RSA-PSS maskGenAlgorithm AlgorithmIdentifier");
144
- let i = u(r.value);
145
- return i === f.mgf1 ? {
146
- oid: i,
147
- hashOid: parseHashAlgorithmIdentifier(e, d(n[1], "maskGenAlgorithm parameters"), "MGF1 hashAlgorithm")
148
- } : { oid: i };
138
+ function parseMaskGenAlgorithmIdentifier(t, i) {
139
+ if (i.tag !== 48) throw Error("RSA-PSS maskGenAlgorithm must be a SEQUENCE");
140
+ let a = e(t, i);
141
+ if (a.length === 0 || a.length > 2) throw Error("Malformed RSA-PSS maskGenAlgorithm AlgorithmIdentifier");
142
+ let o = r(a[0], "maskGenAlgorithm OID");
143
+ if (o.tag !== 6) throw Error("Malformed RSA-PSS maskGenAlgorithm AlgorithmIdentifier");
144
+ let s = n(o.value);
145
+ return s === f.mgf1 ? {
146
+ oid: s,
147
+ hashOid: parseHashAlgorithmIdentifier(t, r(a[1], "maskGenAlgorithm parameters"), "MGF1 hashAlgorithm")
148
+ } : { oid: s };
149
149
  }
150
150
  /** DER-encode a hash AlgorithmIdentifier as `SEQUENCE { OID, NULL }`. */
151
151
  function encodeHashAlgorithmIdentifier(e) {
152
- return s([a(e), i()]);
152
+ return d([l(e), c()]);
153
153
  }
154
154
  /** Map a hash algorithm name to its ASN.1 OID string. */
155
155
  function hashOidForName(e) {
@@ -24,5 +24,4 @@ export interface VerifySignedDataSuccess {
24
24
  readonly valid: boolean;
25
25
  }
26
26
  /** Result of a full signature verification: validity, unsupported params, or a runtime verification failure. */
27
- export type VerifySignedDataResult = VerifySignedDataSuccess | VerifySignatureConfigFailure | VerifySignedDataFailure;
28
- //# sourceMappingURL=sig-verify.d.ts.map
27
+ export type VerifySignedDataResult = VerifySignedDataSuccess | VerifySignatureConfigFailure | VerifySignedDataFailure;
@@ -1,8 +1,8 @@
1
- import { DECODE_LIMIT_CODES as e, rethrowDecodeRefusal as t } from "../asn1/decode-refusal.js";
2
- import { readElement as n } from "../asn1/der.js";
3
- import { alternateEcdsaSignatureEncoding as r, derEcdsaSignatureToRaw as i } from "./ecdsa.js";
4
- import { toArrayBuffer as a } from "../asn1/asn1.js";
5
- import { OIDS as o } from "../asn1/oids2.js";
1
+ import { toArrayBuffer as e } from "../asn1/asn1.js";
2
+ import { DECODE_LIMIT_CODES as t, rethrowDecodeRefusal as n } from "../asn1/decode-refusal.js";
3
+ import { readElement as r } from "../asn1/der.js";
4
+ import { OIDS as i } from "../asn1/oids.js";
5
+ import { alternateEcdsaSignatureEncoding as a, derEcdsaSignatureToRaw as o } from "./ecdsa.js";
6
6
  import { parseRsaPssParameters as s } from "./rsa-pss.js";
7
7
  import { getCrypto as c } from "./webcrypto.js";
8
8
  import { importSpkiDerOrThrow as l } from "../../keys/keys.js";
@@ -14,46 +14,46 @@ import { importSpkiDerOrThrow as l } from "../../keys/keys.js";
14
14
  * @module
15
15
  */
16
16
  /** Non-throwing variant of {@linkcode getVerifySignatureConfig} — returns a typed result union. */
17
- function getVerifySignatureConfigResult(e, t, n, r, i = "issuer") {
17
+ function getVerifySignatureConfigResult(e, t, n, r, a = "issuer") {
18
18
  switch (e) {
19
- case o.sha256WithRSAEncryption: {
19
+ case i.sha256WithRSAEncryption: {
20
20
  let e = requireDerNullOrAbsentSignatureAlgorithmParameters(t, "SHA-256 with RSA");
21
- return e === void 0 ? requireRsaPublicKey(n, "SHA-256", "pkcs1-v1_5", i) : e;
21
+ return e === void 0 ? requireRsaPublicKey(n, "SHA-256", "pkcs1-v1_5", a) : e;
22
22
  }
23
- case o.sha384WithRSAEncryption: {
23
+ case i.sha384WithRSAEncryption: {
24
24
  let e = requireDerNullOrAbsentSignatureAlgorithmParameters(t, "SHA-384 with RSA");
25
- return e === void 0 ? requireRsaPublicKey(n, "SHA-384", "pkcs1-v1_5", i) : e;
25
+ return e === void 0 ? requireRsaPublicKey(n, "SHA-384", "pkcs1-v1_5", a) : e;
26
26
  }
27
- case o.sha512WithRSAEncryption: {
27
+ case i.sha512WithRSAEncryption: {
28
28
  let e = requireDerNullOrAbsentSignatureAlgorithmParameters(t, "SHA-512 with RSA");
29
- return e === void 0 ? requireRsaPublicKey(n, "SHA-512", "pkcs1-v1_5", i) : e;
29
+ return e === void 0 ? requireRsaPublicKey(n, "SHA-512", "pkcs1-v1_5", a) : e;
30
30
  }
31
- case o.rsassaPss: return requireRsaPssVerifyConfig(t, n, i);
32
- case o.ecdsaWithSHA256: {
31
+ case i.rsassaPss: return requireRsaPssVerifyConfig(t, n, a);
32
+ case i.ecdsaWithSHA256: {
33
33
  let e = requireAbsentSignatureAlgorithmParameters(t, "ECDSA with SHA-256");
34
- return e === void 0 ? requireEcPublicKey(n, r, "SHA-256", i) : e;
34
+ return e === void 0 ? requireEcPublicKey(n, r, "SHA-256", a) : e;
35
35
  }
36
- case o.ecdsaWithSHA384: {
36
+ case i.ecdsaWithSHA384: {
37
37
  let e = requireAbsentSignatureAlgorithmParameters(t, "ECDSA with SHA-384");
38
- return e === void 0 ? requireEcPublicKey(n, r, "SHA-384", i) : e;
38
+ return e === void 0 ? requireEcPublicKey(n, r, "SHA-384", a) : e;
39
39
  }
40
- case o.ecdsaWithSHA512: {
40
+ case i.ecdsaWithSHA512: {
41
41
  let e = requireAbsentSignatureAlgorithmParameters(t, "ECDSA with SHA-512");
42
- return e === void 0 ? requireEcPublicKey(n, r, "SHA-512", i) : e;
42
+ return e === void 0 ? requireEcPublicKey(n, r, "SHA-512", a) : e;
43
43
  }
44
- case o.ed25519: {
44
+ case i.ed25519: {
45
45
  let e = requireAbsentSignatureAlgorithmParameters(t, "Ed25519");
46
- return e === void 0 ? n === o.ed25519 ? ok({
46
+ return e === void 0 ? n === i.ed25519 ? ok({
47
47
  importAlgorithm: { kind: "ed25519" },
48
48
  verifyParams: { name: "Ed25519" }
49
- }) : unsupported("Ed25519", `requires Ed25519 ${i} public key`) : e;
49
+ }) : unsupported("Ed25519", `requires Ed25519 ${a} public key`) : e;
50
50
  }
51
51
  default: return unsupported(e, "unrecognized signature algorithm OID");
52
52
  }
53
53
  }
54
54
  /** Validate that the public key OID is `rsaEncryption` and return an RSA verification config result. */
55
- function requireRsaPublicKey(e, t, n = "pkcs1-v1_5", r = "issuer", i) {
56
- return e === o.rsaEncryption ? ok({
55
+ function requireRsaPublicKey(e, t, n = "pkcs1-v1_5", r = "issuer", a) {
56
+ return e === i.rsaEncryption ? ok({
57
57
  importAlgorithm: {
58
58
  kind: "rsa",
59
59
  hash: t,
@@ -61,15 +61,15 @@ function requireRsaPublicKey(e, t, n = "pkcs1-v1_5", r = "issuer", i) {
61
61
  },
62
62
  verifyParams: n === "pss" ? {
63
63
  name: "RSA-PSS",
64
- saltLength: i ?? 0
64
+ saltLength: a ?? 0
65
65
  } : { name: "RSASSA-PKCS1-v1_5" }
66
66
  }) : unsupported("RSA", `requires RSA ${r} public key`);
67
67
  }
68
68
  /** Validate that the public key OID is `ecPublicKey`, resolve the curve, and return an ECDSA verification config result. */
69
69
  function requireEcPublicKey(e, t, n, r = "issuer") {
70
- if (e !== o.ecPublicKey) return unsupported("ECDSA", `requires EC ${r} public key`);
70
+ if (e !== i.ecPublicKey) return unsupported("ECDSA", `requires EC ${r} public key`);
71
71
  switch (t) {
72
- case o.prime256v1: return ok({
72
+ case i.prime256v1: return ok({
73
73
  importAlgorithm: {
74
74
  kind: "ecdsa",
75
75
  curve: "P-256"
@@ -80,7 +80,7 @@ function requireEcPublicKey(e, t, n, r = "issuer") {
80
80
  },
81
81
  ecdsaRawSignatureBytes: 64
82
82
  });
83
- case o.secp384r1: return ok({
83
+ case i.secp384r1: return ok({
84
84
  importAlgorithm: {
85
85
  kind: "ecdsa",
86
86
  curve: "P-384"
@@ -91,7 +91,7 @@ function requireEcPublicKey(e, t, n, r = "issuer") {
91
91
  },
92
92
  ecdsaRawSignatureBytes: 96
93
93
  });
94
- case o.secp521r1: return ok({
94
+ case i.secp521r1: return ok({
95
95
  importAlgorithm: {
96
96
  kind: "ecdsa",
97
97
  curve: "P-521"
@@ -115,73 +115,73 @@ function requireEcPublicKey(e, t, n, r = "issuer") {
115
115
  * @throws `limit_exceeded` on algorithm parameters or a public key that exceed
116
116
  * a micro509 decoding limit.
117
117
  */
118
- async function verifySignedDataDetailed(n, r, i, a, o, s, c) {
119
- let u = getVerifySignatureConfigResult(n, r, i, a);
118
+ async function verifySignedDataDetailed(e, r, i, a, o, s, c) {
119
+ let u = getVerifySignatureConfigResult(e, r, i, a);
120
120
  if (!u.ok) return u;
121
121
  try {
122
122
  return await verifyWithConfiguredKey(await l(o, u.value.importAlgorithm), u.value, s, c, "auto");
123
- } catch (n) {
124
- return t(n, e), verificationError(n instanceof Error ? n.message : "signature verification failed");
123
+ } catch (e) {
124
+ return n(e, t), verificationError(e instanceof Error ? e.message : "signature verification failed");
125
125
  }
126
126
  }
127
127
  /** Execute verification for imported SPKI and caller-owned keys with the same configuration. */
128
- async function verifyWithConfiguredKey(n, o, s, l, u) {
128
+ async function verifyWithConfiguredKey(r, i, s, l, u) {
129
129
  try {
130
- if (u === "der" && o.ecdsaRawSignatureBytes !== void 0) try {
131
- s = i(s, o.ecdsaRawSignatureBytes / 2);
132
- } catch (n) {
133
- return t(n, e), {
130
+ if (u === "der" && i.ecdsaRawSignatureBytes !== void 0) try {
131
+ s = o(s, i.ecdsaRawSignatureBytes / 2);
132
+ } catch (e) {
133
+ return n(e, t), {
134
134
  ok: !0,
135
135
  valid: !1
136
136
  };
137
137
  }
138
- let d = c().subtle, f = a(s), p = a(l);
139
- if (await d.verify(o.verifyParams, n, f, p)) return {
138
+ let d = c().subtle, f = e(s), p = e(l);
139
+ if (await d.verify(i.verifyParams, r, f, p)) return {
140
140
  ok: !0,
141
141
  valid: !0
142
142
  };
143
- if (u === "auto" && o.ecdsaRawSignatureBytes !== void 0) {
144
- let e = r(s, o.ecdsaRawSignatureBytes / 2);
145
- if (e !== void 0) return {
143
+ if (u === "auto" && i.ecdsaRawSignatureBytes !== void 0) {
144
+ let t = a(s, i.ecdsaRawSignatureBytes / 2);
145
+ if (t !== void 0) return {
146
146
  ok: !0,
147
- valid: await d.verify(o.verifyParams, n, a(e), p)
147
+ valid: await d.verify(i.verifyParams, r, e(t), p)
148
148
  };
149
149
  }
150
150
  return {
151
151
  ok: !0,
152
152
  valid: !1
153
153
  };
154
- } catch (n) {
155
- return t(n, e), verificationError(n instanceof Error ? n.message : "signature verification failed");
154
+ } catch (e) {
155
+ return n(e, t), verificationError(e instanceof Error ? e.message : "signature verification failed");
156
156
  }
157
157
  }
158
158
  /** Resolve a caller-owned key without exporting it, then run the shared verifier. */
159
- async function verifySignedDataWithKeyDetailed(e, t, n, r, i, a) {
159
+ async function verifySignedDataWithKeyDetailed(e, t, n, r, a, o) {
160
160
  if (e.type !== "public" || !e.usages.includes("verify")) return verificationError("Signature verification requires a public key with verify usage");
161
161
  let s = e.algorithm, c, l;
162
162
  switch (s.name) {
163
163
  case "RSASSA-PKCS1-v1_5":
164
164
  case "RSA-PSS":
165
- c = o.rsaEncryption;
165
+ c = i.rsaEncryption;
166
166
  break;
167
167
  case "ECDSA":
168
- if (c = o.ecPublicKey, "namedCurve" in s) switch (s.namedCurve) {
168
+ if (c = i.ecPublicKey, "namedCurve" in s) switch (s.namedCurve) {
169
169
  case "P-256":
170
- l = o.prime256v1;
170
+ l = i.prime256v1;
171
171
  break;
172
172
  case "P-384":
173
- l = o.secp384r1;
173
+ l = i.secp384r1;
174
174
  break;
175
- case "P-521": l = o.secp521r1;
175
+ case "P-521": l = i.secp521r1;
176
176
  }
177
177
  break;
178
178
  case "Ed25519":
179
- c = o.ed25519;
179
+ c = i.ed25519;
180
180
  break;
181
181
  default: return unsupported(s.name, "unsupported public key algorithm");
182
182
  }
183
183
  let u = getVerifySignatureConfigResult(t, n, c, l);
184
- return u.ok ? a !== "raw" && a !== "der" ? unsupported(t, "signature encoding must be raw or der") : a === "der" && u.value.ecdsaRawSignatureBytes === void 0 ? unsupported(t, "DER signature encoding requires ECDSA") : s.name === u.value.verifyParams.name ? u.value.importAlgorithm.kind === "rsa" && (!("hash" in s) || typeof s.hash != "object" || s.hash === null || !("name" in s.hash) || s.hash.name !== u.value.importAlgorithm.hash) ? unsupported(t, "signature hash does not match the RSA public key") : await verifyWithConfiguredKey(e, u.value, r, i, a) : unsupported(t, "signature scheme does not match the public key") : u;
184
+ return u.ok ? o !== "raw" && o !== "der" ? unsupported(t, "signature encoding must be raw or der") : o === "der" && u.value.ecdsaRawSignatureBytes === void 0 ? unsupported(t, "DER signature encoding requires ECDSA") : s.name === u.value.verifyParams.name ? u.value.importAlgorithm.kind === "rsa" && (!("hash" in s) || typeof s.hash != "object" || s.hash === null || !("name" in s.hash) || s.hash.name !== u.value.importAlgorithm.hash) ? unsupported(t, "signature hash does not match the RSA public key") : await verifyWithConfiguredKey(e, u.value, r, a, o) : unsupported(t, "signature scheme does not match the public key") : u;
185
185
  }
186
186
  /** Parse RSA-PSS algorithm parameters and build a verification config, or return failure. */
187
187
  function requireRsaPssVerifyConfig(e, t, n) {
@@ -189,14 +189,14 @@ function requireRsaPssVerifyConfig(e, t, n) {
189
189
  return r.ok ? requireRsaPublicKey(t, r.value.hash, "pss", n, r.value.saltLength) : unsupported("RSA-PSS", r.reason);
190
190
  }
191
191
  /** RFC 4055 §5 requires generators to encode NULL and implementations to accept absent parameters too. */
192
- function requireDerNullOrAbsentSignatureAlgorithmParameters(r, i) {
193
- if (r === void 0) return;
192
+ function requireDerNullOrAbsentSignatureAlgorithmParameters(e, i) {
193
+ if (e === void 0) return;
194
194
  let a = "signature AlgorithmIdentifier parameters must be DER NULL or absent";
195
195
  try {
196
- let e = n(r);
197
- return e.tag !== 5 || e.length !== 0 || e.end !== r.length ? unsupported(i, a) : void 0;
198
- } catch (n) {
199
- return t(n, e), unsupported(i, a);
196
+ let t = r(e);
197
+ return t.tag !== 5 || t.length !== 0 || t.end !== e.length ? unsupported(i, a) : void 0;
198
+ } catch (e) {
199
+ return n(e, t), unsupported(i, a);
200
200
  }
201
201
  }
202
202
  function requireAbsentSignatureAlgorithmParameters(e, t) {
@@ -12,5 +12,4 @@ export type SignatureProfileInput = {
12
12
  readonly kind: "rsa-pss";
13
13
  /** Salt length in bytes. Must match the key's hash digest size. */
14
14
  readonly saltLength?: 32 | 48 | 64;
15
- };
16
- //# sourceMappingURL=signing.d.ts.map
15
+ };
@@ -1,6 +1,6 @@
1
1
  import { nullValue as e, objectIdentifier as t, sequence as n } from "../asn1/der.js";
2
- import { ecdsaSignatureToDer as r } from "./ecdsa.js";
3
- import { OIDS as i } from "../asn1/oids2.js";
2
+ import { OIDS as r } from "../asn1/oids.js";
3
+ import { ecdsaSignatureToDer as i } from "./ecdsa.js";
4
4
  import { encodeRsaPssParameters as a, rsaPssParametersForHash as o } from "./rsa-pss.js";
5
5
  import { getCrypto as s } from "./webcrypto.js";
6
6
  // src/internal/crypto/signing.ts
@@ -12,35 +12,35 @@ import { getCrypto as s } from "./webcrypto.js";
12
12
  */
13
13
  /** Resolve a private key and optional profile into a {@linkcode SignatureAlgorithmIdentifier}. */
14
14
  function getSignatureAlgorithm(t, n = {}) {
15
- let r = t.algorithm;
15
+ let i = t.algorithm;
16
16
  if (n.kind === "rsa-pss") return getRsaPssSignatureAlgorithm(t, n.saltLength);
17
- if (r.name === "RSASSA-PKCS1-v1_5") {
18
- if (!hasHash(r)) throw Error("RSA key is missing hash metadata");
19
- switch (r.hash.name) {
17
+ if (i.name === "RSASSA-PKCS1-v1_5") {
18
+ if (!hasHash(i)) throw Error("RSA key is missing hash metadata");
19
+ switch (i.hash.name) {
20
20
  case "SHA-256": return {
21
- algorithmOid: i.sha256WithRSAEncryption,
21
+ algorithmOid: r.sha256WithRSAEncryption,
22
22
  parameters: e(),
23
23
  signParams: { name: "RSASSA-PKCS1-v1_5" }
24
24
  };
25
25
  case "SHA-384": return {
26
- algorithmOid: i.sha384WithRSAEncryption,
26
+ algorithmOid: r.sha384WithRSAEncryption,
27
27
  parameters: e(),
28
28
  signParams: { name: "RSASSA-PKCS1-v1_5" }
29
29
  };
30
30
  case "SHA-512": return {
31
- algorithmOid: i.sha512WithRSAEncryption,
31
+ algorithmOid: r.sha512WithRSAEncryption,
32
32
  parameters: e(),
33
33
  signParams: { name: "RSASSA-PKCS1-v1_5" }
34
34
  };
35
- default: throw Error(`Unsupported RSA hash: ${r.hash.name}`);
35
+ default: throw Error(`Unsupported RSA hash: ${i.hash.name}`);
36
36
  }
37
37
  }
38
- if (r.name === "RSA-PSS") throw Error("RSA-PSS signing requires an explicit signature profile");
39
- if (r.name === "ECDSA") {
40
- if (!hasNamedCurve(r)) throw Error("ECDSA key is missing namedCurve metadata");
41
- switch (r.namedCurve) {
38
+ if (i.name === "RSA-PSS") throw Error("RSA-PSS signing requires an explicit signature profile");
39
+ if (i.name === "ECDSA") {
40
+ if (!hasNamedCurve(i)) throw Error("ECDSA key is missing namedCurve metadata");
41
+ switch (i.namedCurve) {
42
42
  case "P-256": return {
43
- algorithmOid: i.ecdsaWithSHA256,
43
+ algorithmOid: r.ecdsaWithSHA256,
44
44
  signParams: {
45
45
  name: "ECDSA",
46
46
  hash: "SHA-256"
@@ -48,7 +48,7 @@ function getSignatureAlgorithm(t, n = {}) {
48
48
  ecdsaRawSignatureBytes: 64
49
49
  };
50
50
  case "P-384": return {
51
- algorithmOid: i.ecdsaWithSHA384,
51
+ algorithmOid: r.ecdsaWithSHA384,
52
52
  signParams: {
53
53
  name: "ECDSA",
54
54
  hash: "SHA-384"
@@ -56,31 +56,31 @@ function getSignatureAlgorithm(t, n = {}) {
56
56
  ecdsaRawSignatureBytes: 96
57
57
  };
58
58
  case "P-521": return {
59
- algorithmOid: i.ecdsaWithSHA512,
59
+ algorithmOid: r.ecdsaWithSHA512,
60
60
  signParams: {
61
61
  name: "ECDSA",
62
62
  hash: "SHA-512"
63
63
  },
64
64
  ecdsaRawSignatureBytes: 132
65
65
  };
66
- default: throw Error(`Unsupported curve: ${r.namedCurve}`);
66
+ default: throw Error(`Unsupported curve: ${i.namedCurve}`);
67
67
  }
68
68
  }
69
- if (r.name === "Ed25519") return {
70
- algorithmOid: i.ed25519,
69
+ if (i.name === "Ed25519") return {
70
+ algorithmOid: r.ed25519,
71
71
  signParams: { name: "Ed25519" }
72
72
  };
73
- throw Error(`Unsupported signing key algorithm: ${r.name}`);
73
+ throw Error(`Unsupported signing key algorithm: ${i.name}`);
74
74
  }
75
75
  /** Build an RSA-PSS {@linkcode SignatureAlgorithmIdentifier} from an RSA-PSS private key. */
76
76
  function getRsaPssSignatureAlgorithm(e, t) {
77
77
  let n = e.algorithm;
78
78
  if (n.name !== "RSA-PSS") throw Error("RSA-PSS signature profile requires an RSA-PSS private key");
79
79
  if (!hasHash(n)) throw Error("RSA-PSS key is missing hash metadata");
80
- let r = rsaPssHashFromWebCryptoName(n.hash.name), s = o(r);
81
- if (t !== void 0 && t !== s.saltLength) throw Error(`Unsupported RSA-PSS saltLength ${t} for ${r}; expected ${s.saltLength}`);
80
+ let i = rsaPssHashFromWebCryptoName(n.hash.name), s = o(i);
81
+ if (t !== void 0 && t !== s.saltLength) throw Error(`Unsupported RSA-PSS saltLength ${t} for ${i}; expected ${s.saltLength}`);
82
82
  return {
83
- algorithmOid: i.rsassaPss,
83
+ algorithmOid: r.rsassaPss,
84
84
  parameters: a(s),
85
85
  signParams: {
86
86
  name: "RSA-PSS",
@@ -95,8 +95,8 @@ function encodeAlgorithmIdentifier(e) {
95
95
  }
96
96
  /** Sign `data` and return a DER-encoded signature. ECDSA raw signatures are auto-converted to DER. */
97
97
  async function signBytes(e, t, n) {
98
- let i = new Uint8Array(n), a = new Uint8Array(await s().subtle.sign(t.signParams, e, i));
99
- return t.ecdsaRawSignatureBytes === void 0 ? a : r(a, t.ecdsaRawSignatureBytes);
98
+ let r = new Uint8Array(n), a = new Uint8Array(await s().subtle.sign(t.signParams, e, r));
99
+ return t.ecdsaRawSignatureBytes === void 0 ? a : i(a, t.ecdsaRawSignatureBytes);
100
100
  }
101
101
  /** Type guard: does this key algorithm carry a `hash` property (RSA keys). */
102
102
  function hasHash(e) {
@@ -0,0 +1,108 @@
1
+ // src/internal/jose/json-data.ts
2
+ const e = Symbol("JSON data refusal");
3
+ function refuse(t) {
4
+ throw {
5
+ marker: e,
6
+ code: t
7
+ };
8
+ }
9
+ function isRefusal(t) {
10
+ return typeof t == "object" && !!t && "marker" in t && t.marker === e;
11
+ }
12
+ function bytes(e, t) {
13
+ e.bytes += t, e.bytes > e.maxBytes && refuse("limit_exceeded");
14
+ }
15
+ function node(e) {
16
+ ++e.nodes > e.maxNodes && refuse("limit_exceeded");
17
+ }
18
+ /** Counts the UTF-8 bytes of the shortest JSON string spelling without allocating it. */
19
+ function string(e, t) {
20
+ t.length > e.maxBytes - e.bytes && refuse("limit_exceeded"), bytes(e, 2);
21
+ for (let n = 0; n < t.length; n++) {
22
+ let r = t.charCodeAt(n);
23
+ if (r >= 55296 && r <= 56319) {
24
+ let r = t.charCodeAt(++n);
25
+ r >= 56320 && r <= 57343 || refuse("invalid_json"), bytes(e, 4);
26
+ } else bytes(e, characterBytes(r));
27
+ }
28
+ return t;
29
+ }
30
+ function characterBytes(e) {
31
+ return e >= 56320 && e <= 57343 && refuse("invalid_json"), e === 34 || e === 92 ? 2 : e < 32 ? [
32
+ 8,
33
+ 9,
34
+ 10,
35
+ 12,
36
+ 13
37
+ ].includes(e) ? 2 : 6 : e < 128 ? 1 : e < 2048 ? 2 : 3;
38
+ }
39
+ /** Reflection can execute proxy traps or encounter a revoked proxy; that is an input refusal. */
40
+ function inspect(e) {
41
+ try {
42
+ return e();
43
+ } catch {
44
+ return refuse("invalid_json");
45
+ }
46
+ }
47
+ function arrayLength(e, t) {
48
+ let n = inspect(() => Object.getOwnPropertyDescriptor(e, "length"))?.value;
49
+ return (typeof n != "number" || !Number.isSafeInteger(n) || n < 0) && refuse("invalid_json"), n > t.maxNodes - t.nodes && refuse("limit_exceeded"), n;
50
+ }
51
+ function dataMember(e, t) {
52
+ let n = inspect(() => Object.getOwnPropertyDescriptor(e, t));
53
+ return n !== void 0 && "value" in n && n.enumerable || refuse("invalid_json"), n.value;
54
+ }
55
+ function checkPrototype(e, t) {
56
+ let n = inspect(() => Object.getPrototypeOf(e));
57
+ (t ? n !== Array.prototype : n !== null && n !== Object.prototype) && refuse("invalid_json");
58
+ }
59
+ function copy(e, t, n) {
60
+ if (node(t), e === null || typeof e == "boolean") return bytes(t, e === null || e ? 4 : 5), e;
61
+ if (typeof e == "string") return string(t, e);
62
+ if (typeof e == "number") return Number.isFinite(e) || refuse("invalid_json"), bytes(t, String(e).length), e;
63
+ typeof e != "object" && refuse("invalid_json"), n >= t.maxDepth && refuse("limit_exceeded"), t.active.has(e) && refuse("invalid_json");
64
+ let r = inspect(() => Array.isArray(e));
65
+ checkPrototype(e, r), t.active.add(e), r && arrayLength(e, t);
66
+ let i = inspect(() => Reflect.ownKeys(e));
67
+ i.length > t.maxNodes - t.nodes + +!!r && refuse("limit_exceeded"), bytes(t, 2);
68
+ let a = r ? copyArray(e, i, t, n) : copyObject(e, i, t, n);
69
+ return t.active.delete(e), a;
70
+ }
71
+ function copyArray(e, t, n, r) {
72
+ let i = arrayLength(e, n);
73
+ t.length !== i + 1 && refuse("invalid_json");
74
+ let a = [];
75
+ for (let t = 0; t < i; t++) t > 0 && bytes(n, 1), a.push(copy(dataMember(e, String(t)), n, r + 1));
76
+ return Object.freeze(a);
77
+ }
78
+ function copyObject(e, t, n, r) {
79
+ let i = {};
80
+ for (let [a, o] of t.entries()) typeof o != "string" && refuse("invalid_json"), node(n), string(n, o), bytes(n, a > 0 ? 2 : 1), Object.defineProperty(i, o, {
81
+ value: copy(dataMember(e, o), n, r + 1),
82
+ enumerable: !0
83
+ });
84
+ return Object.freeze(i);
85
+ }
86
+ /** Copies plain JSON data without invoking getters, coercion or `toJSON`. */
87
+ function snapshotJsonData(e, t) {
88
+ try {
89
+ return {
90
+ ok: !0,
91
+ value: copy(e, {
92
+ ...t,
93
+ bytes: 0,
94
+ nodes: 0,
95
+ active: /* @__PURE__ */ new Set()
96
+ }, 0)
97
+ };
98
+ } catch (e) {
99
+ if (isRefusal(e)) return {
100
+ ok: !1,
101
+ code: e.code
102
+ };
103
+ throw e;
104
+ }
105
+ }
106
+ export { snapshotJsonData };
107
+
108
+ //# sourceMappingURL=json-data.js.map