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
package/dist/keys/keys.js CHANGED
@@ -1,13 +1,13 @@
1
- import { failureResult as e, rethrowIfInvariant as t, successResult as n } from "../result/result.js";
2
- import { DECODE_LIMIT_CODES as r, decodeFailureResult as i, rethrowDecodeRefusal as a } from "../internal/asn1/decode-refusal.js";
3
- import { explicitContext as o, integer as s, nullValue as c, objectIdentifier as l, octetString as u, readRootElement as d, readSequenceChildren as f, sequence as p, tlv as m } from "../internal/asn1/der.js";
4
- import { decodeObjectIdentifier as h, extractBitStringValue as g, hexToBytes as _, toArrayBuffer as v, toHex as y } from "../internal/asn1/asn1.js";
5
- import { OIDS as b } from "../internal/asn1/oids2.js";
6
- import { getCrypto as x } from "../internal/crypto/webcrypto.js";
7
- import { md5 as S } from "../internal/crypto/hash.js";
8
- import { createKdfBudget as C, decryptPbes2 as w, encryptPbes2 as T, isKdfIterationLimitError as E, isWrongPasswordError as D, parsePbes2AlgorithmIdentifier as O, wrongPasswordError as k } from "../internal/crypto/pbes2.js";
9
- import { base64Decode as A, base64Encode as j } from "../internal/shared/base64.js";
10
- import { parseTraditionalPemOrThrow as M, pemDecodeOrThrow as N, pemEncode as P, trimLwsp as F } from "../pem/pem.js";
1
+ import { decodeObjectIdentifier as e, extractBitStringValue as t, hexToBytes as n, toArrayBuffer as r, toHex as i } from "../internal/asn1/asn1.js";
2
+ import { DECODE_LIMIT_CODES as a, decodeFailureResult as o, decodeRefusalOf as s, rethrowDecodeRefusal as c } from "../internal/asn1/decode-refusal.js";
3
+ import { explicitContext as l, integer as u, nullValue as d, objectIdentifier as f, octetString as p, readRootElement as m, readSequenceChildren as h, sequence as g, tlv as _ } from "../internal/asn1/der.js";
4
+ import { OIDS as v } from "../internal/asn1/oids.js";
5
+ import { md5 as y } from "../internal/crypto/hash.js";
6
+ import { createKdfBudget as b, decryptPbes2 as x, encryptPbes2 as S, isKdfIterationLimitError as C, isWrongPasswordError as w, parsePbes2AlgorithmIdentifier as T, wrongPasswordError as E } from "../internal/crypto/pbes2.js";
7
+ import { getCrypto as D } from "../internal/crypto/webcrypto.js";
8
+ import { base64Decode as O, base64Encode as k } from "../internal/shared/base64.js";
9
+ import { parseTraditionalPemOrThrow as A, pemDecodeOrThrow as j, pemEncode as M, splitPemTextBlocksOrThrow as N, trimLwsp as P } from "../pem/pem.js";
10
+ import { failureResult as F, isResultError as I, rethrowIfInvariant as L, successResult as R, throwMicro509Error as z } from "../result/result.js";
11
11
  // src/keys/keys.ts
12
12
  /**
13
13
  * WebCrypto key generation plus import/export for PKCS#1, PKCS#8, SEC1, SPKI, and JWK.
@@ -50,7 +50,7 @@ async function generateKeyPair(e = {
50
50
  kind: "ecdsa",
51
51
  curve: "P-256"
52
52
  }) {
53
- let t = x().subtle, n = isRsaOaepInput(e) ? ["encrypt", "decrypt"] : ["sign", "verify"], r = await t.generateKey(toGenerateKeyAlgorithm(e), !0, n);
53
+ let t = D().subtle, n = isRsaOaepInput(e) ? ["encrypt", "decrypt"] : ["sign", "verify"], r = await t.generateKey(toGenerateKeyAlgorithm(e), !0, n);
54
54
  if (!("publicKey" in r) || !("privateKey" in r)) throw Error("Expected an asymmetric key pair");
55
55
  return wrapKeyPair(r.publicKey, r.privateKey);
56
56
  }
@@ -59,22 +59,22 @@ function wrapKeyPair(e, t) {
59
59
  publicKey: e,
60
60
  privateKey: t,
61
61
  async exportSpkiDer() {
62
- return new Uint8Array(await x().subtle.exportKey("spki", e));
62
+ return new Uint8Array(await D().subtle.exportKey("spki", e));
63
63
  },
64
64
  async exportSpkiPem() {
65
- return P("PUBLIC KEY", await this.exportSpkiDer());
65
+ return M("PUBLIC KEY", await this.exportSpkiDer());
66
66
  },
67
67
  async exportPkcs8Der() {
68
- return new Uint8Array(await x().subtle.exportKey("pkcs8", t));
68
+ return new Uint8Array(await D().subtle.exportKey("pkcs8", t));
69
69
  },
70
70
  async exportPkcs8Pem() {
71
- return P("PRIVATE KEY", await this.exportPkcs8Der());
71
+ return M("PRIVATE KEY", await this.exportPkcs8Der());
72
72
  },
73
73
  exportPublicJwk() {
74
- return x().subtle.exportKey("jwk", e);
74
+ return D().subtle.exportKey("jwk", e);
75
75
  },
76
76
  exportPrivateJwk() {
77
- return x().subtle.exportKey("jwk", t);
77
+ return D().subtle.exportKey("jwk", t);
78
78
  }
79
79
  };
80
80
  }
@@ -85,7 +85,7 @@ function wrapKeyPair(e, t) {
85
85
  * @see {@linkcode exportSpkiPem} for PEM output
86
86
  */
87
87
  async function exportSpkiDer(e) {
88
- return new Uint8Array(await x().subtle.exportKey("spki", e));
88
+ return new Uint8Array(await D().subtle.exportKey("spki", e));
89
89
  }
90
90
  /**
91
91
  * Export a private key as DER-encoded PKCS#8 PrivateKeyInfo.
@@ -95,7 +95,7 @@ async function exportSpkiDer(e) {
95
95
  * @see {@linkcode exportEncryptedPkcs8Der} for password-protected export
96
96
  */
97
97
  async function exportPkcs8Der(e) {
98
- return new Uint8Array(await x().subtle.exportKey("pkcs8", e));
98
+ return new Uint8Array(await D().subtle.exportKey("pkcs8", e));
99
99
  }
100
100
  /**
101
101
  * Export a public key as a JSON Web Key.
@@ -107,7 +107,7 @@ async function exportPkcs8Der(e) {
107
107
  * ```
108
108
  */
109
109
  function exportPublicJwk(e) {
110
- return x().subtle.exportKey("jwk", e);
110
+ return D().subtle.exportKey("jwk", e);
111
111
  }
112
112
  /**
113
113
  * Export a private key as a JSON Web Key.
@@ -116,7 +116,7 @@ function exportPublicJwk(e) {
116
116
  * @see {@linkcode exportPublicJwk} for public key export
117
117
  */
118
118
  function exportPrivateJwk(e) {
119
- return x().subtle.exportKey("jwk", e);
119
+ return D().subtle.exportKey("jwk", e);
120
120
  }
121
121
  /**
122
122
  * Export a private key as PEM-encoded PKCS#8 PrivateKeyInfo.
@@ -134,7 +134,7 @@ function exportPrivateJwk(e) {
134
134
  * @see {@linkcode exportEncryptedPkcs8Pem} for password-protected export
135
135
  */
136
136
  async function exportPkcs8Pem(e) {
137
- return P("PRIVATE KEY", await exportPkcs8Der(e));
137
+ return M("PRIVATE KEY", await exportPkcs8Der(e));
138
138
  }
139
139
  /**
140
140
  * Export a private key as DER-encoded PBES2-encrypted PKCS#8 EncryptedPrivateKeyInfo.
@@ -150,8 +150,8 @@ async function exportPkcs8Pem(e) {
150
150
  * @see {@linkcode exportEncryptedPkcs8Pem} for PEM output
151
151
  */
152
152
  async function exportEncryptedPkcs8Der(e, t) {
153
- let n = await exportPkcs8Der(e), r = await T(n, t);
154
- return p([r.algorithmIdentifierDer, u(r.encryptedData)]);
153
+ let n = await exportPkcs8Der(e), r = await S(n, t);
154
+ return g([r.algorithmIdentifierDer, p(r.encryptedData)]);
155
155
  }
156
156
  /**
157
157
  * Export a private key as PEM-encoded PBES2-encrypted PKCS#8 EncryptedPrivateKeyInfo.
@@ -168,7 +168,7 @@ async function exportEncryptedPkcs8Der(e, t) {
168
168
  * @see {@linkcode importEncryptedPkcs8Pem} for the inverse operation
169
169
  */
170
170
  async function exportEncryptedPkcs8Pem(e, t) {
171
- return P("ENCRYPTED PRIVATE KEY", await exportEncryptedPkcs8Der(e, t));
171
+ return M("ENCRYPTED PRIVATE KEY", await exportEncryptedPkcs8Der(e, t));
172
172
  }
173
173
  /**
174
174
  * Export an RSA private key as DER-encoded PKCS#1 RSAPrivateKey.
@@ -183,7 +183,7 @@ async function exportEncryptedPkcs8Pem(e, t) {
183
183
  */
184
184
  async function exportPkcs1Der(e) {
185
185
  let t = parsePkcs8PrivateKey(await exportPkcs8Der(e));
186
- if (t.algorithmOid !== b.rsaEncryption) throw Error("PKCS#1 export requires an RSA private key");
186
+ if (t.algorithmOid !== v.rsaEncryption) throw Error("PKCS#1 export requires an RSA private key");
187
187
  return t.privateKeyDer;
188
188
  }
189
189
  /**
@@ -195,7 +195,7 @@ async function exportPkcs1Der(e) {
195
195
  * @see {@linkcode exportEncryptedPkcs1Pem} for password-protected export
196
196
  */
197
197
  async function exportPkcs1Pem(e) {
198
- return P("RSA PRIVATE KEY", await exportPkcs1Der(e));
198
+ return M("RSA PRIVATE KEY", await exportPkcs1Der(e));
199
199
  }
200
200
  /**
201
201
  * Export an RSA private key as legacy `Proc-Type: 4,ENCRYPTED` PEM (PKCS#1).
@@ -227,7 +227,7 @@ async function exportEncryptedPkcs1Pem(e, t) {
227
227
  */
228
228
  async function exportSec1Der(e) {
229
229
  let t = parsePkcs8PrivateKey(await exportPkcs8Der(e));
230
- if (t.algorithmOid !== b.ecPublicKey) throw Error("SEC1 export requires an EC private key");
230
+ if (t.algorithmOid !== v.ecPublicKey) throw Error("SEC1 export requires an EC private key");
231
231
  return ensureSec1NamedCurveParameters(t.privateKeyDer, t.parametersOid);
232
232
  }
233
233
  /**
@@ -239,7 +239,7 @@ async function exportSec1Der(e) {
239
239
  * @see {@linkcode exportEncryptedSec1Pem} for password-protected export
240
240
  */
241
241
  async function exportSec1Pem(e) {
242
- return P("EC PRIVATE KEY", await exportSec1Der(e));
242
+ return M("EC PRIVATE KEY", await exportSec1Der(e));
243
243
  }
244
244
  /**
245
245
  * Export an EC private key as legacy `Proc-Type: 4,ENCRYPTED` PEM (SEC 1).
@@ -264,7 +264,7 @@ async function exportEncryptedSec1Pem(e, t) {
264
264
  * ```
265
265
  */
266
266
  async function exportSpkiPem(e) {
267
- return P("PUBLIC KEY", await exportSpkiDer(e));
267
+ return M("PUBLIC KEY", await exportSpkiDer(e));
268
268
  }
269
269
  /**
270
270
  * Derive the matching public key from an imported (or generated) private key.
@@ -299,7 +299,7 @@ async function exportSpkiPem(e) {
299
299
  async function derivePublicKey(e) {
300
300
  if (e.type !== "private") throw Error("derivePublicKey requires a private CryptoKey");
301
301
  if (!e.extractable) throw Error("Cannot derive public key from a non-extractable private key");
302
- let t = x().subtle, n = e.algorithm.name === "RSA-OAEP" ? "encrypt" : "verify", r = await t.exportKey("jwk", e);
302
+ let t = D().subtle, n = e.algorithm.name === "RSA-OAEP" ? "encrypt" : "verify", r = await t.exportKey("jwk", e);
303
303
  return t.importKey("jwk", toPublicJwk(r, n), e.algorithm, !0, [n]);
304
304
  }
305
305
  /**
@@ -314,8 +314,8 @@ async function derivePublicKey(e) {
314
314
  * @see {@linkcode importPkcs8Base64} for private key import
315
315
  */
316
316
  async function exportBinaryBase64(e) {
317
- if (e.type === "public") return j(await exportSpkiDer(e));
318
- if (e.type === "private") return j(await exportPkcs8Der(e));
317
+ if (e.type === "public") return k(await exportSpkiDer(e));
318
+ if (e.type === "private") return k(await exportPkcs8Der(e));
319
319
  throw Error("Cannot export secret/symmetric CryptoKey");
320
320
  }
321
321
  /**
@@ -336,28 +336,110 @@ async function exportBinaryBase64(e) {
336
336
  * @see {@linkcode importSpkiPem} for PEM input
337
337
  */
338
338
  async function importSpkiDerOrThrow(e, t) {
339
- let n = parseSpkiDer(e), r;
340
- t === void 0 ? r = inferKeyImportInput(n, "Unsupported SubjectPublicKeyInfo algorithm") : (assertSpkiMatchesRequestedAlgorithm(n, t), r = t);
339
+ assertRuntimeImportKind(t, !1);
340
+ let n = importStage("spki", "asn1", "invalid_asn1", () => parseSpkiDer(e)), r = importStage("spki", "algorithm", t === void 0 ? "unsupported_algorithm" : "algorithm_mismatch", () => t === void 0 ? inferKeyImportInput(n, "Unsupported algorithm") : (assertSpkiMatchesRequestedAlgorithm(n, t), t)), i = toImportAlgorithm(r), a = D().subtle, o = publicKeyUsages(r), s = new Uint8Array(e);
341
+ return await importBackendStage("spki", () => a.importKey("spki", s, i, !0, o));
342
+ }
343
+ function assertRuntimeImportKind(e, t) {
344
+ if (e !== void 0 && e.kind !== "rsa" && e.kind !== "ecdsa" && e.kind !== "ed25519") throw Error(`Unhandled ${t ? "PrivateKeyImportInput" : "PublicKeyImportInput"} kind: ${String(e)}`);
345
+ }
346
+ const B = [
347
+ "container",
348
+ "pem",
349
+ "base64",
350
+ "asn1",
351
+ "algorithm",
352
+ "backend"
353
+ ], V = [
354
+ "unsupported_container",
355
+ "multiple_blocks",
356
+ "encrypted_key",
357
+ "invalid_armor",
358
+ "invalid_base64",
359
+ "invalid_asn1",
360
+ "decode_limit",
361
+ "unsupported_algorithm",
362
+ "algorithm_mismatch",
363
+ "public_key_mismatch",
364
+ "backend_rejected"
365
+ ];
366
+ function importDiagnostic(e) {
367
+ if (!I(e)) return;
368
+ let t = e.error.details;
369
+ if (typeof t != "object" || !t || !("stage" in t) || !("reason" in t)) return;
370
+ let n = B.find((e) => e === t.stage), r = V.find((e) => e === t.reason), i = "container" in t ? [
371
+ "pkcs8",
372
+ "pkcs1",
373
+ "sec1",
374
+ "spki",
375
+ "jwk"
376
+ ].find((e) => e === t.container) : void 0;
377
+ return n === void 0 || r === void 0 ? void 0 : {
378
+ stage: n,
379
+ reason: r,
380
+ ...i === void 0 ? {} : { container: i }
381
+ };
382
+ }
383
+ function throwImportFailure(e, t, n, r = "malformed") {
384
+ return z(r, `Key import refused at ${t}: ${n}`, {
385
+ stage: t,
386
+ reason: n,
387
+ ...e === void 0 ? {} : { container: e }
388
+ });
389
+ }
390
+ function refuseImportStage(e, t, n, r) {
391
+ L(e);
392
+ let i = importDiagnostic(e);
393
+ i !== void 0 && throwImportFailure(t, i.stage, i.reason, I(e) && e.code === "limit_exceeded" ? "limit_exceeded" : "malformed"), s(e, a) !== void 0 && throwImportFailure(t, n, "decode_limit", "limit_exceeded"), throwImportFailure(t, n, r);
394
+ }
395
+ function importStage(e, t, n, r) {
341
396
  try {
342
- return await x().subtle.importKey("spki", new Uint8Array(e), toImportAlgorithm(r), !0, publicKeyUsages(r));
343
- } catch {
344
- throw Error("Malformed SubjectPublicKeyInfo");
397
+ return r();
398
+ } catch (r) {
399
+ return refuseImportStage(r, e, t, n);
400
+ }
401
+ }
402
+ async function importAsyncStage(e, t, n, r) {
403
+ try {
404
+ return await r();
405
+ } catch (r) {
406
+ return refuseImportStage(r, e, t, n);
407
+ }
408
+ }
409
+ /** Only the native import call is inside this boundary. Web IDL key-data validation may
410
+ * throw TypeError (for example an invalid JWK key_ops enum); that is untrusted input,
411
+ * not a JavaScript invariant failure. Algorithm/usage/buffer preparation stays outside.
412
+ */
413
+ async function importBackendStage(e, t) {
414
+ try {
415
+ return await t();
416
+ } catch (t) {
417
+ return t instanceof TypeError && throwImportFailure(e, "backend", "backend_rejected"), refuseImportStage(t, e, "backend", "backend_rejected");
345
418
  }
346
419
  }
420
+ function importPemBytes(e, t, n) {
421
+ return importStage(e, "pem", "invalid_armor", () => j(t, n));
422
+ }
423
+ function importBase64Bytes(e, t) {
424
+ return importStage(e, "base64", "invalid_base64", () => O(t));
425
+ }
347
426
  /** Runs a throwing key import and maps an EXPECTED failure to a `'malformed'` or `'limit_exceeded'` result; invariants rethrow. */
348
427
  async function importResult(e) {
349
428
  try {
350
- return n(await e());
429
+ return R(await e());
351
430
  } catch (e) {
352
- return t(e), i(e, r, "Malformed key");
431
+ L(e);
432
+ let t = importDiagnostic(e);
433
+ if (t !== void 0 && I(e)) return F(e.code === "limit_exceeded" ? "limit_exceeded" : "malformed", e.error.message, t);
434
+ throw e;
353
435
  }
354
436
  }
355
437
  /** Like {@link importResult} but distinguishes a typed wrong-password failure (`'invalid_password'`). */
356
- async function encryptedImportResult(a) {
438
+ async function encryptedImportResult(e) {
357
439
  try {
358
- return n(await a());
359
- } catch (n) {
360
- return t(n), D(n) ? e("invalid_password", n.message) : E(n) ? e("kdf_iterations_exceeded", n.message) : i(n, r, "Malformed encrypted key");
440
+ return R(await e());
441
+ } catch (e) {
442
+ return L(e), w(e) ? F("invalid_password", e.message) : C(e) ? F("kdf_iterations_exceeded", e.message) : o(e, a, "Malformed encrypted key");
361
443
  }
362
444
  }
363
445
  /**
@@ -382,7 +464,7 @@ function importSpkiDer(e, t) {
382
464
  * @see {@linkcode exportSpkiPem} for the inverse operation
383
465
  */
384
466
  function importSpkiPemOrThrow(e, t) {
385
- return importSpkiDerOrThrow(N("PUBLIC KEY", e), t);
467
+ return importSpkiDerOrThrow(importPemBytes("spki", "PUBLIC KEY", e), t);
386
468
  }
387
469
  /**
388
470
  * Import a public key from PEM-encoded SubjectPublicKeyInfo.
@@ -393,19 +475,41 @@ function importSpkiPem(e, t) {
393
475
  return importResult(() => importSpkiPemOrThrow(e, t));
394
476
  }
395
477
  /**
478
+ * Imports exactly one unencrypted private-key PEM block by its label: PKCS#8 `PRIVATE KEY`,
479
+ * PKCS#1 `RSA PRIVATE KEY`, or SEC1 `EC PRIVATE KEY`. Bundles (including a certificate plus key)
480
+ * are refused rather than selecting an arbitrary block. Non-PEM surrounding text follows the
481
+ * shared PEM scanner's behavior. Encrypted PKCS#8 and traditional encrypted PEM require the
482
+ * explicit password-taking import functions. No format guessing or decryption is attempted.
483
+ *
484
+ * Without `algorithm`, existing inference applies (RSA defaults to PKCS#1v1.5/SHA-256).
485
+ * An explicit descriptor additionally asserts key family/curve and selects RSA padding/hash.
486
+ */
487
+ async function importPrivateKeyPemOrThrow(e, t) {
488
+ assertRuntimeImportKind(t, !0);
489
+ let n = importStage(void 0, "pem", "invalid_armor", () => N(e));
490
+ n.length > 1 && throwImportFailure(void 0, "container", "multiple_blocks");
491
+ let r = n[0];
492
+ r === void 0 && throwImportFailure(void 0, "container", "unsupported_container"), r.label === "ENCRYPTED PRIVATE KEY" && throwImportFailure("pkcs8", "container", "encrypted_key"), r.label !== "PRIVATE KEY" && r.label !== "RSA PRIVATE KEY" && r.label !== "EC PRIVATE KEY" && throwImportFailure(void 0, "container", "unsupported_container");
493
+ let i = r.label === "RSA PRIVATE KEY" ? "pkcs1" : r.label === "EC PRIVATE KEY" ? "sec1" : "pkcs8";
494
+ switch (importStage(i, "pem", "invalid_armor", () => A(r.pem)).headers.size > 0 && throwImportFailure(i, "container", "encrypted_key"), r.label) {
495
+ case "PRIVATE KEY": return await importPkcs8PemOrThrow(r.pem, t);
496
+ case "RSA PRIVATE KEY": return t !== void 0 && t.kind !== "rsa" && throwImportFailure("pkcs1", "algorithm", "algorithm_mismatch"), await importPkcs1PemOrThrow(r.pem, t);
497
+ case "EC PRIVATE KEY": return t !== void 0 && t.kind !== "ecdsa" && throwImportFailure("sec1", "algorithm", "algorithm_mismatch"), await importSec1PemOrThrow(r.pem, t);
498
+ default: throwImportFailure(void 0, "container", "unsupported_container");
499
+ }
500
+ }
501
+ /** Result-returning counterpart of {@linkcode importPrivateKeyPemOrThrow}. */
502
+ function importPrivateKeyPem(e, t) {
503
+ return importResult(() => importPrivateKeyPemOrThrow(e, t));
504
+ }
505
+ /**
396
506
  * Import a public key from base64-encoded SubjectPublicKeyInfo (no PEM headers).
397
507
  *
398
508
  * @see {@linkcode exportBinaryBase64} for the inverse operation
399
509
  * @see {@linkcode importSpkiPem} for PEM input with headers
400
510
  */
401
511
  function importSpkiBase64OrThrow(e, t) {
402
- let n;
403
- try {
404
- n = A(e);
405
- } catch {
406
- throw Error("Invalid base64 SubjectPublicKeyInfo");
407
- }
408
- return importSpkiDerOrThrow(n, t);
512
+ return importSpkiDerOrThrow(importBase64Bytes("spki", e), t);
409
513
  }
410
514
  /**
411
515
  * Import a public key from base64-encoded SubjectPublicKeyInfo (no PEM headers).
@@ -440,22 +544,13 @@ function importSpkiBase64(e, t) {
440
544
  * @see {@linkcode importEncryptedPkcs8Der} for encrypted PKCS#8
441
545
  */
442
546
  async function importPkcs8DerOrThrow(e, t) {
443
- let n;
444
- try {
445
- n = parsePkcs8PrivateKey(e);
446
- } catch (e) {
447
- throw a(e, r), Error("Malformed PKCS#8 private key");
547
+ assertRuntimeImportKind(t, !0);
548
+ let n = importStage("pkcs8", "asn1", "invalid_asn1", () => parsePkcs8PrivateKey(e)), r = importStage("pkcs8", "algorithm", t === void 0 ? "unsupported_algorithm" : "algorithm_mismatch", () => t === void 0 ? inferKeyImportInput(n, "Unsupported algorithm") : (assertPkcs8MatchesRequestedAlgorithm(n, t), t)), i = toImportAlgorithm(r), a = D().subtle, o = privateKeyUsages(r), s = new Uint8Array(n.v1Der), c = await importBackendStage("pkcs8", () => a.importKey("pkcs8", s, i, !0, o));
549
+ if (n.declaredPublicKey !== void 0) {
550
+ let e = n.declaredPublicKey;
551
+ await importAsyncStage("pkcs8", "asn1", "public_key_mismatch", () => assertDeclaredPublicKeyMatches(c, e));
448
552
  }
449
- let i;
450
- t === void 0 ? i = inferKeyImportInput(n, "Unsupported PKCS#8 private key algorithm") : (assertPkcs8MatchesRequestedAlgorithm(n, t), i = t);
451
- let o;
452
- try {
453
- o = await x().subtle.importKey("pkcs8", new Uint8Array(n.v1Der), toImportAlgorithm(i), !0, privateKeyUsages(i));
454
- } catch {
455
- throw Error("Malformed PKCS#8 private key");
456
- }
457
- let s = n.declaredPublicKey;
458
- return s !== void 0 && await assertDeclaredPublicKeyMatches(o, s), o;
553
+ return c;
459
554
  }
460
555
  /**
461
556
  * Reject a OneAsymmetricKey whose `publicKey [1]` field is not the public key of
@@ -466,7 +561,7 @@ async function importPkcs8DerOrThrow(e, t) {
466
561
  * algorithm was used."
467
562
  */
468
563
  async function assertDeclaredPublicKeyMatches(e, t) {
469
- let n = await exportSpkiDer(await derivePublicKey(e)), r = f(n)[1];
564
+ let n = await exportSpkiDer(await derivePublicKey(e)), r = h(n)[1];
470
565
  if (r === void 0 || r.tag !== 3) throw Error("Malformed PKCS#8 private key");
471
566
  let i = r.value.slice(1);
472
567
  if (i.length !== t.length || i.some((e, n) => e !== t[n])) throw Error("PKCS#8 publicKey does not match the private key");
@@ -492,7 +587,7 @@ function importPkcs8Der(e, t) {
492
587
  * ```
493
588
  */
494
589
  function importPkcs8PemOrThrow(e, t) {
495
- return importPkcs8DerOrThrow(N("PRIVATE KEY", e), t);
590
+ return importPkcs8DerOrThrow(importPemBytes("pkcs8", "PRIVATE KEY", e), t);
496
591
  }
497
592
  /**
498
593
  * Import a private key from PEM-encoded PKCS#8 PrivateKeyInfo.
@@ -521,25 +616,25 @@ function importPkcs8Pem(e, t) {
521
616
  * @see {@linkcode exportEncryptedPkcs8Der} for the inverse operation
522
617
  */
523
618
  async function importEncryptedPkcs8DerOrThrow(e, t, n, r) {
524
- return await importEncryptedPkcs8WithBudget(e, t, n, C(r));
619
+ return await importEncryptedPkcs8WithBudget(e, t, n, b(r));
525
620
  }
526
621
  async function importEncryptedPkcs8WithBudget(e, t, n, r) {
527
- let i = readEncryptedPkcs8Envelope(e), a = await w(i.algorithmIdentifierDer, i.encryptedData, t, r);
622
+ let i = readEncryptedPkcs8Envelope(e), a = await x(i.algorithmIdentifierDer, i.encryptedData, t, r);
528
623
  return assertDecryptedPrivateKey(() => parsePkcs8PrivateKey(a), "Invalid password or encrypted content"), importPkcs8DerOrThrow(a, n);
529
624
  }
530
625
  /** Splits a DER `EncryptedPrivateKeyInfo` into its AlgorithmIdentifier DER and encryptedData bytes. */
531
626
  function readEncryptedPkcs8Envelope(e) {
532
627
  let t;
533
628
  try {
534
- t = f(e);
629
+ t = h(e);
535
630
  } catch (e) {
536
- throw a(e, r), Error("Malformed EncryptedPrivateKeyInfo");
631
+ throw c(e, a), Error("Malformed EncryptedPrivateKeyInfo");
537
632
  }
538
- let n = t[0], i = t[1];
539
- if (t.length !== 2 || n === void 0 || i === void 0 || i.tag !== 4) throw Error("Malformed EncryptedPrivateKeyInfo");
633
+ let n = t[0], r = t[1];
634
+ if (t.length !== 2 || n === void 0 || r === void 0 || r.tag !== 4) throw Error("Malformed EncryptedPrivateKeyInfo");
540
635
  return {
541
636
  algorithmIdentifierDer: e.slice(n.start - n.headerLength, n.end),
542
- encryptedData: i.value
637
+ encryptedData: r.value
543
638
  };
544
639
  }
545
640
  /**
@@ -550,7 +645,7 @@ function readEncryptedPkcs8Envelope(e) {
550
645
  * iteration count outside 1 to 4294967295.
551
646
  */
552
647
  function inspectEncryptedPkcs8Der(e) {
553
- return O(readEncryptedPkcs8Envelope(e).algorithmIdentifierDer);
648
+ return T(readEncryptedPkcs8Envelope(e).algorithmIdentifierDer);
554
649
  }
555
650
  /**
556
651
  * Import a private key from DER-encoded PBES2-encrypted PKCS#8 EncryptedPrivateKeyInfo.
@@ -573,8 +668,8 @@ function importEncryptedPkcs8Der(e, t, n, r) {
573
668
  * ```
574
669
  */
575
670
  async function importEncryptedPkcs8PemOrThrow(e, t, n, r) {
576
- let i = C(r);
577
- return await importEncryptedPkcs8WithBudget(N("ENCRYPTED PRIVATE KEY", e), t, n, i);
671
+ let i = b(r);
672
+ return await importEncryptedPkcs8WithBudget(j("ENCRYPTED PRIVATE KEY", e), t, n, i);
578
673
  }
579
674
  /**
580
675
  * Import a private key from PEM-encoded PBES2-encrypted PKCS#8 EncryptedPrivateKeyInfo.
@@ -592,8 +687,8 @@ function importEncryptedPkcs8Pem(e, t, n, r) {
592
687
  * @see {@linkcode exportPkcs1Der} for the inverse operation
593
688
  * @see {@linkcode importPkcs1Pem} for PEM input
594
689
  */
595
- function importPkcs1DerOrThrow(e, t = { kind: "rsa" }) {
596
- return importPkcs8DerOrThrow(wrapPkcs1InPkcs8(e), t);
690
+ async function importPkcs1DerOrThrow(e, t = { kind: "rsa" }) {
691
+ return assertRuntimeImportKind(t, !0), importStage("pkcs1", "asn1", "invalid_asn1", () => parsePkcs1PrivateKey(e)), await importAsyncStage("pkcs1", "backend", "backend_rejected", () => importPkcs8DerOrThrow(wrapPkcs1InPkcs8(e), t));
597
692
  }
598
693
  /**
599
694
  * Import an RSA private key from DER-encoded PKCS#1 RSAPrivateKey.
@@ -612,7 +707,7 @@ function importPkcs1Der(e, t = { kind: "rsa" }) {
612
707
  * @see {@linkcode importEncryptedPkcs1Pem} for encrypted PEM
613
708
  */
614
709
  function importPkcs1PemOrThrow(e, t = { kind: "rsa" }) {
615
- return importPkcs1DerOrThrow(N("RSA PRIVATE KEY", e), t);
710
+ return importPkcs1DerOrThrow(importPemBytes("pkcs1", "RSA PRIVATE KEY", e), t);
616
711
  }
617
712
  /**
618
713
  * Import an RSA private key from PEM-encoded PKCS#1 RSAPrivateKey.
@@ -649,13 +744,7 @@ function importEncryptedPkcs1Pem(e, t, n = { kind: "rsa" }) {
649
744
  * @see {@linkcode importPkcs8Pem} for PEM input with headers
650
745
  */
651
746
  function importPkcs8Base64OrThrow(e, t) {
652
- let n;
653
- try {
654
- n = A(e);
655
- } catch {
656
- throw Error("Invalid base64 PKCS#8 private key");
657
- }
658
- return importPkcs8DerOrThrow(n, t);
747
+ return importPkcs8DerOrThrow(importBase64Bytes("pkcs8", e), t);
659
748
  }
660
749
  /**
661
750
  * Import a private key from base64-encoded PKCS#8 PrivateKeyInfo (no PEM headers).
@@ -683,14 +772,9 @@ function importPkcs8Base64(e, t) {
683
772
  * @see {@linkcode importSec1Pem} for PEM input
684
773
  */
685
774
  async function importSec1DerOrThrow(e, t) {
686
- let n;
687
- try {
688
- n = parseSec1PrivateKey(e);
689
- } catch (e) {
690
- throw a(e, r), Error("Malformed SEC 1 private key");
691
- }
692
- let i;
693
- return t === void 0 ? i = inferSec1ImportInput(n) : (assertSec1MatchesRequestedAlgorithm(n, t), i = t), await importPkcs8DerOrThrow(wrapSec1InPkcs8(e, i.curve), i);
775
+ assertRuntimeImportKind(t, !0);
776
+ let n = importStage("sec1", "asn1", "invalid_asn1", () => parseSec1PrivateKey(e)), r = importStage("sec1", "algorithm", t === void 0 ? "unsupported_algorithm" : "algorithm_mismatch", () => t === void 0 ? inferSec1ImportInput(n) : (assertSec1MatchesRequestedAlgorithm(n, t), t));
777
+ return await importAsyncStage("sec1", "backend", "backend_rejected", () => importPkcs8DerOrThrow(wrapSec1InPkcs8(e, r.curve), r));
694
778
  }
695
779
  /**
696
780
  * Import an EC private key from DER-encoded SEC 1 ECPrivateKey.
@@ -711,7 +795,7 @@ function importSec1Der(e, t) {
711
795
  * @see {@linkcode importEncryptedSec1Pem} for encrypted PEM
712
796
  */
713
797
  function importSec1PemOrThrow(e, t) {
714
- return importSec1DerOrThrow(N("EC PRIVATE KEY", e), t);
798
+ return importSec1DerOrThrow(importPemBytes("sec1", "EC PRIVATE KEY", e), t);
715
799
  }
716
800
  /**
717
801
  * Import an EC private key from PEM-encoded SEC 1 ECPrivateKey.
@@ -758,13 +842,12 @@ function importEncryptedSec1Pem(e, t, n) {
758
842
  * @see {@linkcode exportPublicJwk} for the inverse operation
759
843
  */
760
844
  async function importPublicJwkOrThrow(e, t) {
761
- let n = t ?? inferJwkImportInput(e);
762
- assertPublicJwkMatchesRequestedAlgorithm(e, n);
763
- try {
764
- return await x().subtle.importKey("jwk", e, toImportAlgorithm(n), !0, publicKeyUsages(n));
765
- } catch {
766
- throw Error("Malformed public JWK");
767
- }
845
+ assertRuntimeImportKind(t, !1);
846
+ let n = importStage("jwk", "algorithm", t === void 0 ? "unsupported_algorithm" : "algorithm_mismatch", () => {
847
+ let n = t ?? inferJwkImportInput(e);
848
+ return assertPublicJwkMatchesRequestedAlgorithm(e, n), n;
849
+ }), r = toImportAlgorithm(n), i = D().subtle, a = publicKeyUsages(n);
850
+ return await importBackendStage("jwk", () => i.importKey("jwk", e, r, !0, a));
768
851
  }
769
852
  /**
770
853
  * Import a public verification key from a JSON Web Key.
@@ -797,13 +880,12 @@ function importPublicJwk(e, t) {
797
880
  * @see {@linkcode exportPrivateJwk} for the inverse operation
798
881
  */
799
882
  async function importPrivateJwkOrThrow(e, t) {
800
- let n = t ?? inferJwkImportInput(e);
801
- assertPrivateJwkMatchesRequestedAlgorithm(e, n);
802
- try {
803
- return await x().subtle.importKey("jwk", e, toImportAlgorithm(n), !0, privateKeyUsages(n));
804
- } catch {
805
- throw Error("Malformed private JWK");
806
- }
883
+ assertRuntimeImportKind(t, !0);
884
+ let n = importStage("jwk", "algorithm", t === void 0 ? "unsupported_algorithm" : "algorithm_mismatch", () => {
885
+ let n = t ?? inferJwkImportInput(e);
886
+ return assertPrivateJwkMatchesRequestedAlgorithm(e, n), n;
887
+ }), r = toImportAlgorithm(n), i = D().subtle, a = privateKeyUsages(n);
888
+ return await importBackendStage("jwk", () => i.importKey("jwk", e, r, !0, a));
807
889
  }
808
890
  /**
809
891
  * Import a private signing key from a JSON Web Key.
@@ -840,13 +922,13 @@ function importPrivateJwk(e, t) {
840
922
  * @see {@linkcode decryptRsaOaepOrThrow} for the inverse operation
841
923
  * @see `encryptRsaOaep` for the Result-returning variant
842
924
  */
843
- async function encryptRsaOaepOrThrow(e, n, r = {}) {
925
+ async function encryptRsaOaepOrThrow(e, t, n = {}) {
844
926
  let i = validateRsaOaepKey(e, "public", "encrypt");
845
927
  if (i !== void 0) throw Error(i);
846
928
  try {
847
- return new Uint8Array(await x().subtle.encrypt(toRsaOaepParams(r), e, v(n)));
929
+ return new Uint8Array(await D().subtle.encrypt(toRsaOaepParams(n), e, r(t)));
848
930
  } catch (e) {
849
- throw t(e), Error("Plaintext exceeds the RSA-OAEP capacity of the key (modulus bytes − 2 × hash bytes − 2)");
931
+ throw L(e), Error("Plaintext exceeds the RSA-OAEP capacity of the key (modulus bytes − 2 × hash bytes − 2)");
850
932
  }
851
933
  }
852
934
  /**
@@ -865,13 +947,13 @@ async function encryptRsaOaepOrThrow(e, n, r = {}) {
865
947
  *
866
948
  * @see `encryptRsaOaepOrThrow` for the throwing variant
867
949
  */
868
- async function encryptRsaOaep(r, i, a = {}) {
869
- let o = validateRsaOaepKey(r, "public", "encrypt");
870
- if (o !== void 0) return e("invalid_key", o);
950
+ async function encryptRsaOaep(e, t, n = {}) {
951
+ let r = validateRsaOaepKey(e, "public", "encrypt");
952
+ if (r !== void 0) return F("invalid_key", r);
871
953
  try {
872
- return n(await encryptRsaOaepOrThrow(r, i, a));
873
- } catch (n) {
874
- return t(n), e("message_too_long", n instanceof Error ? n.message : "Plaintext exceeds the RSA-OAEP capacity");
954
+ return R(await encryptRsaOaepOrThrow(e, t, n));
955
+ } catch (e) {
956
+ return L(e), F("message_too_long", e instanceof Error ? e.message : "Plaintext exceeds the RSA-OAEP capacity");
875
957
  }
876
958
  }
877
959
  /**
@@ -896,13 +978,13 @@ async function encryptRsaOaep(r, i, a = {}) {
896
978
  * @see {@linkcode encryptRsaOaepOrThrow} for the inverse operation
897
979
  * @see `decryptRsaOaep` for the Result-returning variant
898
980
  */
899
- async function decryptRsaOaepOrThrow(e, n, r = {}) {
981
+ async function decryptRsaOaepOrThrow(e, t, n = {}) {
900
982
  let i = validateRsaOaepKey(e, "private", "decrypt");
901
983
  if (i !== void 0) throw Error(i);
902
984
  try {
903
- return new Uint8Array(await x().subtle.decrypt(toRsaOaepParams(r), e, v(n)));
985
+ return new Uint8Array(await D().subtle.decrypt(toRsaOaepParams(n), e, r(t)));
904
986
  } catch (e) {
905
- throw t(e), Error("RSA-OAEP decryption failed: wrong key, wrong label, or corrupted ciphertext");
987
+ throw L(e), Error("RSA-OAEP decryption failed: wrong key, wrong label, or corrupted ciphertext");
906
988
  }
907
989
  }
908
990
  /**
@@ -920,13 +1002,13 @@ async function decryptRsaOaepOrThrow(e, n, r = {}) {
920
1002
  *
921
1003
  * @see `decryptRsaOaepOrThrow` for the throwing variant
922
1004
  */
923
- async function decryptRsaOaep(r, i, a = {}) {
924
- let o = validateRsaOaepKey(r, "private", "decrypt");
925
- if (o !== void 0) return e("invalid_key", o);
1005
+ async function decryptRsaOaep(e, t, n = {}) {
1006
+ let r = validateRsaOaepKey(e, "private", "decrypt");
1007
+ if (r !== void 0) return F("invalid_key", r);
926
1008
  try {
927
- return n(await decryptRsaOaepOrThrow(r, i, a));
928
- } catch (n) {
929
- return t(n), e("decryption_failed", n instanceof Error ? n.message : "RSA-OAEP decryption failed");
1009
+ return R(await decryptRsaOaepOrThrow(e, t, n));
1010
+ } catch (e) {
1011
+ return L(e), F("decryption_failed", e instanceof Error ? e.message : "RSA-OAEP decryption failed");
930
1012
  }
931
1013
  }
932
1014
  /** Map a {@linkcode KeyAlgorithmInput} to the WebCrypto `generateKey` algorithm parameter. */
@@ -974,12 +1056,12 @@ function assertDecryptedPrivateKey(e, t) {
974
1056
  try {
975
1057
  e();
976
1058
  } catch (e) {
977
- throw a(e, r), k(t);
1059
+ throw c(e, a), E(t);
978
1060
  }
979
1061
  }
980
1062
  /** Structural check for a PKCS#1 RSAPrivateKey, including optional multiprime fields. */
981
1063
  function parsePkcs1PrivateKey(e) {
982
- let t = f(e), n = t[0];
1064
+ let t = h(e), n = t[0];
983
1065
  if (n === void 0 || n.tag !== 2 || n.value.length !== 1 || !t.slice(1, 9).every((e) => e.tag === 2)) throw Error("Malformed PKCS#1 private key");
984
1066
  let r = n.value[0];
985
1067
  if (r === 0 && t.length === 9) return;
@@ -989,41 +1071,41 @@ function parsePkcs1PrivateKey(e) {
989
1071
  /** RFC 8017 Appendix A.1.2: OtherPrimeInfos is a non-empty SEQUENCE OF three-INTEGER entries. */
990
1072
  function isOtherPrimeInfosShape(e, t) {
991
1073
  if (t.tag !== 48) return !1;
992
- let n = e.slice(t.start - t.headerLength, t.end), r = f(n);
1074
+ let n = e.slice(t.start - t.headerLength, t.end), r = h(n);
993
1075
  return r.length !== 0 && r.every((e) => {
994
1076
  if (e.tag !== 48) return !1;
995
- let t = f(n.slice(e.start - e.headerLength, e.end));
1077
+ let t = h(n.slice(e.start - e.headerLength, e.end));
996
1078
  return t.length === 3 && t.every((e) => e.tag === 2);
997
1079
  });
998
1080
  }
999
1081
  /** Extract algorithm OID and inner key bytes from a PKCS#8 PrivateKeyInfo envelope. */
1000
- function parsePkcs8PrivateKey(e) {
1001
- let t = f(e), n = t[0], r = t[1], i = t[2];
1002
- if (t.length < 3 || n === void 0 || n.tag !== 2 || r === void 0 || r.tag !== 48 || i === void 0 || i.tag !== 4) throw Error("Malformed PKCS#8 private key");
1003
- let a = validateOneAsymmetricKeyTail(t.slice(3));
1004
- if (readPkcs8Version(n.value) !== (a === void 0 ? 0 : 1)) throw Error("Malformed PKCS#8 private key");
1005
- let o = e.slice(r.start - r.headerLength, r.end), c = f(o), l = c[0];
1082
+ function parsePkcs8PrivateKey(t) {
1083
+ let n = h(t), r = n[0], i = n[1], a = n[2];
1084
+ if (n.length < 3 || r === void 0 || r.tag !== 2 || i === void 0 || i.tag !== 48 || a === void 0 || a.tag !== 4) throw Error("Malformed PKCS#8 private key");
1085
+ let o = validateOneAsymmetricKeyTail(n.slice(3));
1086
+ if (readPkcs8Version(r.value) !== (o === void 0 ? 0 : 1)) throw Error("Malformed PKCS#8 private key");
1087
+ let s = t.slice(i.start - i.headerLength, i.end), c = h(s), l = c[0];
1006
1088
  if (l === void 0 || l.tag !== 6 || c.length < 1 || c.length > 2) throw Error("Malformed PKCS#8 private key");
1007
- let d = c[1], m = h(l.value);
1008
- return I.includes(m) && assertCurvePrivateKey(i.value), {
1009
- algorithmOid: m,
1089
+ let d = c[1], f = e(l.value);
1090
+ return H.includes(f) && assertCurvePrivateKey(a.value), {
1091
+ algorithmOid: f,
1010
1092
  ...d === void 0 ? {} : { parametersTag: d.tag },
1011
- ...d?.tag === 6 ? { parametersOid: h(d.value) } : {},
1012
- privateKeyDer: i.value,
1013
- v1Der: t.length === 3 ? e : p([
1014
- s(Uint8Array.of(0)),
1015
- o,
1016
- u(i.value)
1093
+ ...d?.tag === 6 ? { parametersOid: e(d.value) } : {},
1094
+ privateKeyDer: a.value,
1095
+ v1Der: n.length === 3 ? t : g([
1096
+ u(Uint8Array.of(0)),
1097
+ s,
1098
+ p(a.value)
1017
1099
  ]),
1018
- ...a === void 0 ? {} : { declaredPublicKey: a }
1100
+ ...o === void 0 ? {} : { declaredPublicKey: o }
1019
1101
  };
1020
1102
  }
1021
1103
  /** Algorithms whose `privateKey` field holds an RFC 8410 §7 `CurvePrivateKey`. */
1022
- const I = [
1023
- b.x25519,
1024
- b.x448,
1025
- b.ed25519,
1026
- b.ed448
1104
+ const H = [
1105
+ v.x25519,
1106
+ v.x448,
1107
+ v.ed25519,
1108
+ v.ed448
1027
1109
  ];
1028
1110
  /**
1029
1111
  * Reject a `privateKey` field that does not hold exactly one DER `CurvePrivateKey`.
@@ -1033,7 +1115,7 @@ const I = [
1033
1115
  * 'privateKey' field", and `CurvePrivateKey ::= OCTET STRING`.
1034
1116
  */
1035
1117
  function assertCurvePrivateKey(e) {
1036
- if (d(e).tag !== 4) throw Error("Malformed PKCS#8 private key");
1118
+ if (m(e).tag !== 4) throw Error("Malformed PKCS#8 private key");
1037
1119
  }
1038
1120
  /**
1039
1121
  * Validate the OneAsymmetricKey tail after `privateKey` and return the
@@ -1070,10 +1152,10 @@ function validateOneAsymmetricKeyTail(e) {
1070
1152
  * tag, so the members are read back under a universal constructed one.
1071
1153
  */
1072
1154
  function assertOneAsymmetricKeyAttributes(e) {
1073
- let t = m(48, e);
1074
- for (let e of f(t)) {
1155
+ let t = _(48, e);
1156
+ for (let e of h(t)) {
1075
1157
  if (e.tag !== 48) throw Error("Malformed PKCS#8 private key");
1076
- let n = f(t.slice(e.start - e.headerLength, e.end)), r = n[0], i = n[1];
1158
+ let n = h(t.slice(e.start - e.headerLength, e.end)), r = n[0], i = n[1];
1077
1159
  if (n.length !== 2 || r === void 0 || r.tag !== 6 || i === void 0 || i.tag !== 49) throw Error("Malformed PKCS#8 private key");
1078
1160
  }
1079
1161
  }
@@ -1095,15 +1177,15 @@ function readPkcs8Version(e) {
1095
1177
  * (ecPrivkeyVer1), privateKey OCTET STRING, parameters [0] ECParameters
1096
1178
  * {{ NamedCurve }} OPTIONAL, publicKey [1] BIT STRING OPTIONAL }`.
1097
1179
  */
1098
- function parseSec1PrivateKey(e) {
1099
- let t = f(e), n = t[0], r = t[1], i = t[2], a = t[3];
1100
- if (t.length < 2 || t.length > 4 || n === void 0 || n.tag !== 2 || n.value.length !== 1 || n.value[0] !== 1 || r === void 0 || r.tag !== 4 || i !== void 0 && i.tag !== 160 && i.tag !== 161 || a !== void 0 && (i?.tag !== 160 || a.tag !== 161)) throw Error("Malformed SEC 1 private key");
1101
- let o = i?.tag === 160 ? i : void 0;
1102
- if (o === void 0) return {};
1103
- let s = d(o.value);
1180
+ function parseSec1PrivateKey(t) {
1181
+ let n = h(t), r = n[0], i = n[1], a = n[2], o = n[3];
1182
+ if (n.length < 2 || n.length > 4 || r === void 0 || r.tag !== 2 || r.value.length !== 1 || r.value[0] !== 1 || i === void 0 || i.tag !== 4 || a !== void 0 && a.tag !== 160 && a.tag !== 161 || o !== void 0 && (a?.tag !== 160 || o.tag !== 161)) throw Error("Malformed SEC 1 private key");
1183
+ let s = a?.tag === 160 ? a : void 0;
1184
+ if (s === void 0) return {};
1185
+ let c = m(s.value);
1104
1186
  return {
1105
- parametersTag: s.tag,
1106
- ...s.tag === 6 ? { parametersOid: h(s.value) } : {}
1187
+ parametersTag: c.tag,
1188
+ ...c.tag === 6 ? { parametersOid: e(c.value) } : {}
1107
1189
  };
1108
1190
  }
1109
1191
  /**
@@ -1114,30 +1196,30 @@ function parseSec1PrivateKey(e) {
1114
1196
  * self-describing, so they re-import without an explicit curve.
1115
1197
  */
1116
1198
  function ensureSec1NamedCurveParameters(e, t) {
1117
- let n = f(e);
1199
+ let n = h(e);
1118
1200
  if (n.some((e) => e.tag === 160)) return new Uint8Array(e);
1119
1201
  if (t === void 0) throw Error("SEC1 export requires a named curve in the PKCS#8 privateKeyAlgorithm");
1120
1202
  let raw = (t) => e.slice(t.start - t.headerLength, t.end);
1121
- return p([
1203
+ return g([
1122
1204
  ...n.slice(0, 2).map(raw),
1123
- o(0, l(t)),
1205
+ l(0, f(t)),
1124
1206
  ...n.slice(2).map(raw)
1125
1207
  ]);
1126
1208
  }
1127
1209
  /** Wrap a PKCS#1 RSAPrivateKey in a PKCS#8 PrivateKeyInfo envelope for WebCrypto import. */
1128
1210
  function wrapPkcs1InPkcs8(e) {
1129
- return p([
1211
+ return g([
1130
1212
  Uint8Array.of(2, 1, 0),
1131
- p([l(b.rsaEncryption), c()]),
1132
- u(new Uint8Array(e))
1213
+ g([f(v.rsaEncryption), d()]),
1214
+ p(new Uint8Array(e))
1133
1215
  ]);
1134
1216
  }
1135
1217
  /** Wrap a SEC 1 ECPrivateKey in a PKCS#8 PrivateKeyInfo envelope for WebCrypto import. */
1136
1218
  function wrapSec1InPkcs8(e, t) {
1137
- return p([
1219
+ return g([
1138
1220
  Uint8Array.of(2, 1, 0),
1139
- p([l(b.ecPublicKey), l(curveToOid(t))]),
1140
- u(new Uint8Array(e))
1221
+ g([f(v.ecPublicKey), f(curveToOid(t))]),
1222
+ p(new Uint8Array(e))
1141
1223
  ]);
1142
1224
  }
1143
1225
  /** Project a private JWK onto its public-only members, discarding private key material. */
@@ -1160,19 +1242,19 @@ function toPublicJwk(e, t) {
1160
1242
  * Single source of truth for the NIST curve ↔ named-curve OID mapping, read in
1161
1243
  * both directions by {@linkcode curveToOid} and {@linkcode oidToCurve}.
1162
1244
  */
1163
- const L = [
1164
- ["P-256", b.prime256v1],
1165
- ["P-384", b.secp384r1],
1166
- ["P-521", b.secp521r1]
1245
+ const U = [
1246
+ ["P-256", v.prime256v1],
1247
+ ["P-384", v.secp384r1],
1248
+ ["P-521", v.secp521r1]
1167
1249
  ];
1168
1250
  /** Map a curve name to its ASN.1 OID string. */
1169
1251
  function curveToOid(e) {
1170
- for (let [t, n] of L) if (t === e) return n;
1252
+ for (let [t, n] of U) if (t === e) return n;
1171
1253
  throw Error(`Unsupported EC curve: ${e}`);
1172
1254
  }
1173
1255
  /** Map an ASN.1 curve OID string back to its curve name, or `undefined` if unrecognized. */
1174
1256
  function oidToCurve(e) {
1175
- for (let [t, n] of L) if (n === e) return t;
1257
+ for (let [t, n] of U) if (n === e) return t;
1176
1258
  }
1177
1259
  /** Map an {@linkcode RsaScheme} to the WebCrypto algorithm name string. */
1178
1260
  function rsaSchemeToWebCryptoAlgorithmName(e) {
@@ -1207,52 +1289,52 @@ function validateRsaOaepKey(e, t, n) {
1207
1289
  function toRsaOaepParams(e) {
1208
1290
  return {
1209
1291
  name: "RSA-OAEP",
1210
- ...e.label === void 0 ? {} : { label: v(e.label) }
1292
+ ...e.label === void 0 ? {} : { label: r(e.label) }
1211
1293
  };
1212
1294
  }
1213
1295
  /** Encrypt DER key material as an OpenSSL-style `Proc-Type: 4,ENCRYPTED` PEM block. */
1214
1296
  async function encryptTraditionalPem(e, t, n) {
1215
- let r = n.iv ?? x().getRandomValues(/* @__PURE__ */ new Uint8Array(16));
1216
- if (r.length !== 16) throw Error("Traditional PEM encryption requires a 16-byte IV");
1217
- let i = n.cipher ?? "AES-256-CBC", a = await importTraditionalPemAesKey(n.password, r.slice(0, 8), i, ["encrypt"]), o = new Uint8Array(await x().subtle.encrypt({
1297
+ let a = n.iv ?? D().getRandomValues(/* @__PURE__ */ new Uint8Array(16));
1298
+ if (a.length !== 16) throw Error("Traditional PEM encryption requires a 16-byte IV");
1299
+ let o = n.cipher ?? "AES-256-CBC", s = await importTraditionalPemAesKey(n.password, a.slice(0, 8), o, ["encrypt"]), c = new Uint8Array(await D().subtle.encrypt({
1218
1300
  name: "AES-CBC",
1219
- iv: v(r)
1220
- }, a, v(t))), s = j(o).match(/.{1,64}/g)?.join("\n") ?? "";
1301
+ iv: r(a)
1302
+ }, s, r(t))), l = k(c).match(/.{1,64}/g)?.join("\n") ?? "";
1221
1303
  return [
1222
1304
  `-----BEGIN ${e}-----`,
1223
1305
  "Proc-Type: 4,ENCRYPTED",
1224
- `DEK-Info: ${i},${y(r).toUpperCase()}`,
1306
+ `DEK-Info: ${o},${i(a).toUpperCase()}`,
1225
1307
  "",
1226
- s,
1308
+ l,
1227
1309
  `-----END ${e}-----`
1228
1310
  ].join("\n");
1229
1311
  }
1230
1312
  /** Decrypt a `Proc-Type: 4,ENCRYPTED` PEM block, RFC 1421 §4.6 headers, to plaintext DER. */
1231
- async function decryptTraditionalPem(e, t, n) {
1232
- let r = M(t);
1233
- if (r.label !== e) throw Error(`Expected ${e} PEM block`);
1234
- let i = r.headers.get("DEK-Info"), a = r.headers.get("Proc-Type");
1235
- if (a === void 0 || !isEncryptedProcType(a) || i === void 0) throw Error("Traditional PEM encryption headers missing");
1236
- let [o, s] = i.split(",").map(F);
1237
- if (!isTraditionalPemCipher(o) || s === void 0) throw Error("Only AES-128-CBC, AES-192-CBC, and AES-256-CBC traditional PEM encryption is supported");
1238
- if (!isTraditionalPemIvHex(s)) throw Error("Traditional PEM encryption requires a 16-byte IV encoded as 32 hex characters");
1239
- let c = _(s), l = await importTraditionalPemAesKey(n, c.slice(0, 8), o, ["decrypt"]);
1313
+ async function decryptTraditionalPem(e, t, i) {
1314
+ let a = A(t);
1315
+ if (a.label !== e) throw Error(`Expected ${e} PEM block`);
1316
+ let o = a.headers.get("DEK-Info"), s = a.headers.get("Proc-Type");
1317
+ if (s === void 0 || !isEncryptedProcType(s) || o === void 0) throw Error("Traditional PEM encryption headers missing");
1318
+ let [c, l] = o.split(",").map(P);
1319
+ if (!isTraditionalPemCipher(c) || l === void 0) throw Error("Only AES-128-CBC, AES-192-CBC, and AES-256-CBC traditional PEM encryption is supported");
1320
+ if (!isTraditionalPemIvHex(l)) throw Error("Traditional PEM encryption requires a 16-byte IV encoded as 32 hex characters");
1321
+ let u = n(l), d = await importTraditionalPemAesKey(i, u.slice(0, 8), c, ["decrypt"]);
1240
1322
  try {
1241
- return new Uint8Array(await x().subtle.decrypt({
1323
+ return new Uint8Array(await D().subtle.decrypt({
1242
1324
  name: "AES-CBC",
1243
- iv: v(c)
1244
- }, l, v(A(r.base64Body))));
1325
+ iv: r(u)
1326
+ }, d, r(O(a.base64Body))));
1245
1327
  } catch {
1246
- throw k("Invalid password or encrypted PEM content");
1328
+ throw E("Invalid password or encrypted PEM content");
1247
1329
  }
1248
1330
  }
1249
1331
  /** Derive and import an AES-CBC key for legacy PEM encryption using OpenSSL `EVP_BytesToKey`. */
1250
- function importTraditionalPemAesKey(e, t, n, r) {
1251
- let i = traditionalPemCipherKeyLength(n), a = opensslBytesToKey(e, t, i / 8);
1252
- return x().subtle.importKey("raw", v(a), {
1332
+ function importTraditionalPemAesKey(e, t, n, i) {
1333
+ let a = traditionalPemCipherKeyLength(n), o = opensslBytesToKey(e, t, a / 8);
1334
+ return D().subtle.importKey("raw", r(o), {
1253
1335
  name: "AES-CBC",
1254
- length: i
1255
- }, !1, r);
1336
+ length: a
1337
+ }, !1, i);
1256
1338
  }
1257
1339
  /**
1258
1340
  * RFC 1421 §4.6.1.1 `Proc-Type: 4,ENCRYPTED`.
@@ -1262,7 +1344,7 @@ function importTraditionalPemAesKey(e, t, n, r) {
1262
1344
  */
1263
1345
  function isEncryptedProcType(e) {
1264
1346
  let t = e.split(",");
1265
- return t.length === 2 && F(t[0] ?? "") === "4" && F(t[1] ?? "") === "ENCRYPTED";
1347
+ return t.length === 2 && P(t[0] ?? "") === "4" && P(t[1] ?? "") === "ENCRYPTED";
1266
1348
  }
1267
1349
  /** Type guard for the three AES-CBC ciphers supported by legacy PEM encryption. */
1268
1350
  function isTraditionalPemCipher(e) {
@@ -1285,7 +1367,7 @@ function opensslBytesToKey(e, t, n) {
1285
1367
  let r = new TextEncoder().encode(e), i = [], a = /* @__PURE__ */ new Uint8Array(), o = 0;
1286
1368
  for (; o < n;) {
1287
1369
  let e = new Uint8Array(a.length + r.length + t.length);
1288
- e.set(a, 0), e.set(r, a.length), e.set(t, a.length + r.length), a = S(e), i.push(a), o += a.length;
1370
+ e.set(a, 0), e.set(r, a.length), e.set(t, a.length + r.length), a = y(e), i.push(a), o += a.length;
1289
1371
  }
1290
1372
  let s = new Uint8Array(n), c = 0;
1291
1373
  for (let e of i) {
@@ -1294,23 +1376,23 @@ function opensslBytesToKey(e, t, n) {
1294
1376
  }
1295
1377
  return s;
1296
1378
  }
1297
- function parseSpkiDer(e) {
1379
+ function parseSpkiDer(n) {
1298
1380
  try {
1299
- let t = f(e);
1300
- if (t.length !== 2) throw Error("Malformed SubjectPublicKeyInfo");
1301
- let n = t[0], r = t[1];
1302
- if (n === void 0 || n.tag !== 48 || r === void 0 || r.tag !== 3) throw Error("Malformed SubjectPublicKeyInfo");
1303
- g(r);
1304
- let i = f(e.slice(n.start - n.headerLength, n.end)), a = i[0];
1305
- if (a === void 0 || a.tag !== 6 || i.length < 1 || i.length > 2) throw Error("Malformed SubjectPublicKeyInfo");
1306
- let o = i[1];
1381
+ let r = h(n);
1382
+ if (r.length !== 2) throw Error("Malformed SubjectPublicKeyInfo");
1383
+ let i = r[0], a = r[1];
1384
+ if (i === void 0 || i.tag !== 48 || a === void 0 || a.tag !== 3) throw Error("Malformed SubjectPublicKeyInfo");
1385
+ t(a);
1386
+ let o = h(n.slice(i.start - i.headerLength, i.end)), s = o[0];
1387
+ if (s === void 0 || s.tag !== 6 || o.length < 1 || o.length > 2) throw Error("Malformed SubjectPublicKeyInfo");
1388
+ let c = o[1];
1307
1389
  return {
1308
- algorithmOid: h(a.value),
1309
- ...o === void 0 ? {} : { parametersTag: o.tag },
1310
- ...o?.tag === 6 ? { parametersOid: h(o.value) } : {}
1390
+ algorithmOid: e(s.value),
1391
+ ...c === void 0 ? {} : { parametersTag: c.tag },
1392
+ ...c?.tag === 6 ? { parametersOid: e(c.value) } : {}
1311
1393
  };
1312
1394
  } catch (e) {
1313
- throw a(e, r), Error("Malformed SubjectPublicKeyInfo");
1395
+ throw c(e, a), Error("Malformed SubjectPublicKeyInfo");
1314
1396
  }
1315
1397
  }
1316
1398
  /**
@@ -1323,10 +1405,10 @@ function parseSpkiDer(e) {
1323
1405
  */
1324
1406
  function inferKeyImportInput(e, t) {
1325
1407
  switch (e.algorithmOid) {
1326
- case b.rsaEncryption:
1408
+ case v.rsaEncryption:
1327
1409
  if (e.parametersTag === void 0 || e.parametersTag === 5) return { kind: "rsa" };
1328
1410
  break;
1329
- case b.ecPublicKey: {
1411
+ case v.ecPublicKey: {
1330
1412
  let t = e.parametersTag === 6 && e.parametersOid !== void 0 ? oidToCurve(e.parametersOid) : void 0;
1331
1413
  if (t !== void 0) return {
1332
1414
  kind: "ecdsa",
@@ -1334,7 +1416,7 @@ function inferKeyImportInput(e, t) {
1334
1416
  };
1335
1417
  break;
1336
1418
  }
1337
- case b.ed25519: if (e.parametersTag === void 0) return { kind: "ed25519" };
1419
+ case v.ed25519: if (e.parametersTag === void 0) return { kind: "ed25519" };
1338
1420
  }
1339
1421
  throw Error(t);
1340
1422
  }
@@ -1419,13 +1501,13 @@ function rsaImportInputFromJwkAlg(e) {
1419
1501
  function assertSpkiMatchesRequestedAlgorithm(e, t) {
1420
1502
  switch (t.kind) {
1421
1503
  case "rsa":
1422
- if (e.algorithmOid !== b.rsaEncryption || e.parametersTag !== void 0 && e.parametersTag !== 5) throw Error("SubjectPublicKeyInfo algorithm does not match requested import algorithm");
1504
+ if (e.algorithmOid !== v.rsaEncryption || e.parametersTag !== void 0 && e.parametersTag !== 5) throw Error("SubjectPublicKeyInfo algorithm does not match requested import algorithm");
1423
1505
  return;
1424
1506
  case "ecdsa":
1425
- if (e.algorithmOid !== b.ecPublicKey || e.parametersTag !== 6 || e.parametersOid !== curveToOid(t.curve)) throw Error("SubjectPublicKeyInfo algorithm does not match requested import algorithm");
1507
+ if (e.algorithmOid !== v.ecPublicKey || e.parametersTag !== 6 || e.parametersOid !== curveToOid(t.curve)) throw Error("SubjectPublicKeyInfo algorithm does not match requested import algorithm");
1426
1508
  return;
1427
1509
  case "ed25519":
1428
- if (e.algorithmOid !== b.ed25519 || e.parametersTag !== void 0) throw Error("SubjectPublicKeyInfo algorithm does not match requested import algorithm");
1510
+ if (e.algorithmOid !== v.ed25519 || e.parametersTag !== void 0) throw Error("SubjectPublicKeyInfo algorithm does not match requested import algorithm");
1429
1511
  return;
1430
1512
  default: throw Error(`Unhandled PublicKeyImportInput kind: ${String(t)}`);
1431
1513
  }
@@ -1433,13 +1515,13 @@ function assertSpkiMatchesRequestedAlgorithm(e, t) {
1433
1515
  function assertPkcs8MatchesRequestedAlgorithm(e, t) {
1434
1516
  switch (t.kind) {
1435
1517
  case "rsa":
1436
- if (e.algorithmOid !== b.rsaEncryption || e.parametersTag !== void 0 && e.parametersTag !== 5) throw Error("PKCS#8 private key algorithm does not match requested import algorithm");
1518
+ if (e.algorithmOid !== v.rsaEncryption || e.parametersTag !== void 0 && e.parametersTag !== 5) throw Error("PKCS#8 private key algorithm does not match requested import algorithm");
1437
1519
  return;
1438
1520
  case "ecdsa":
1439
- if (e.algorithmOid !== b.ecPublicKey || e.parametersTag !== 6 || e.parametersOid !== curveToOid(t.curve)) throw Error("PKCS#8 private key algorithm does not match requested import algorithm");
1521
+ if (e.algorithmOid !== v.ecPublicKey || e.parametersTag !== 6 || e.parametersOid !== curveToOid(t.curve)) throw Error("PKCS#8 private key algorithm does not match requested import algorithm");
1440
1522
  return;
1441
1523
  case "ed25519":
1442
- if (e.algorithmOid !== b.ed25519 || e.parametersTag !== void 0) throw Error("PKCS#8 private key algorithm does not match requested import algorithm");
1524
+ if (e.algorithmOid !== v.ed25519 || e.parametersTag !== void 0) throw Error("PKCS#8 private key algorithm does not match requested import algorithm");
1443
1525
  return;
1444
1526
  default: throw Error(`Unhandled PrivateKeyImportInput kind: ${String(t)}`);
1445
1527
  }
@@ -1478,6 +1560,6 @@ function assertPrivateJwkMatchesRequestedAlgorithm(e, t) {
1478
1560
  default: throw Error(`Unhandled PrivateKeyImportInput kind: ${String(t)}`);
1479
1561
  }
1480
1562
  }
1481
- export { decryptRsaOaep, decryptRsaOaepOrThrow, derivePublicKey, encryptRsaOaep, encryptRsaOaepOrThrow, exportBinaryBase64, exportEncryptedPkcs1Pem, exportEncryptedPkcs8Der, exportEncryptedPkcs8Pem, exportEncryptedSec1Pem, exportPkcs1Der, exportPkcs1Pem, exportPkcs8Der, exportPkcs8Pem, exportPrivateJwk, exportPublicJwk, exportSec1Der, exportSec1Pem, exportSpkiDer, exportSpkiPem, generateKeyPair, importEncryptedPkcs1Pem, importEncryptedPkcs1PemOrThrow, importEncryptedPkcs8Der, importEncryptedPkcs8DerOrThrow, importEncryptedPkcs8Pem, importEncryptedPkcs8PemOrThrow, importEncryptedSec1Pem, importEncryptedSec1PemOrThrow, importPkcs1Der, importPkcs1DerOrThrow, importPkcs1Pem, importPkcs1PemOrThrow, importPkcs8Base64, importPkcs8Base64OrThrow, importPkcs8Der, importPkcs8DerOrThrow, importPkcs8Pem, importPkcs8PemOrThrow, importPrivateJwk, importPrivateJwkOrThrow, importPublicJwk, importPublicJwkOrThrow, importSec1Der, importSec1DerOrThrow, importSec1Pem, importSec1PemOrThrow, importSpkiBase64, importSpkiBase64OrThrow, importSpkiDer, importSpkiDerOrThrow, importSpkiPem, importSpkiPemOrThrow, inspectEncryptedPkcs8Der, O as parsePbes2AlgorithmIdentifier };
1563
+ export { decryptRsaOaep, decryptRsaOaepOrThrow, derivePublicKey, encryptRsaOaep, encryptRsaOaepOrThrow, exportBinaryBase64, exportEncryptedPkcs1Pem, exportEncryptedPkcs8Der, exportEncryptedPkcs8Pem, exportEncryptedSec1Pem, exportPkcs1Der, exportPkcs1Pem, exportPkcs8Der, exportPkcs8Pem, exportPrivateJwk, exportPublicJwk, exportSec1Der, exportSec1Pem, exportSpkiDer, exportSpkiPem, generateKeyPair, importEncryptedPkcs1Pem, importEncryptedPkcs1PemOrThrow, importEncryptedPkcs8Der, importEncryptedPkcs8DerOrThrow, importEncryptedPkcs8Pem, importEncryptedPkcs8PemOrThrow, importEncryptedSec1Pem, importEncryptedSec1PemOrThrow, importPkcs1Der, importPkcs1DerOrThrow, importPkcs1Pem, importPkcs1PemOrThrow, importPkcs8Base64, importPkcs8Base64OrThrow, importPkcs8Der, importPkcs8DerOrThrow, importPkcs8Pem, importPkcs8PemOrThrow, importPrivateJwk, importPrivateJwkOrThrow, importPrivateKeyPem, importPrivateKeyPemOrThrow, importPublicJwk, importPublicJwkOrThrow, importSec1Der, importSec1DerOrThrow, importSec1Pem, importSec1PemOrThrow, importSpkiBase64, importSpkiBase64OrThrow, importSpkiDer, importSpkiDerOrThrow, importSpkiPem, importSpkiPemOrThrow, inspectEncryptedPkcs8Der, T as parsePbes2AlgorithmIdentifier };
1482
1564
 
1483
1565
  //# sourceMappingURL=keys.js.map