jose 3.18.0 → 3.19.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 (51) hide show
  1. package/dist/browser/jwe/compact/decrypt.js +5 -1
  2. package/dist/browser/jwe/flattened/decrypt.js +5 -0
  3. package/dist/browser/jwk/embedded.js +2 -2
  4. package/dist/browser/jwk/from_key_like.js +2 -2
  5. package/dist/browser/jwk/parse.js +2 -31
  6. package/dist/browser/jwks/remote.js +1 -1
  7. package/dist/browser/jws/compact/verify.js +5 -1
  8. package/dist/browser/jws/flattened/verify.js +5 -0
  9. package/dist/browser/jwt/decrypt.js +5 -1
  10. package/dist/browser/jwt/verify.js +5 -1
  11. package/dist/browser/key/export.js +4 -2
  12. package/dist/browser/key/import.js +33 -3
  13. package/dist/browser/lib/decrypt_key_management.js +2 -2
  14. package/dist/node/cjs/jwe/compact/decrypt.js +5 -1
  15. package/dist/node/cjs/jwe/flattened/decrypt.js +5 -0
  16. package/dist/node/cjs/jwk/embedded.js +2 -2
  17. package/dist/node/cjs/jwk/from_key_like.js +2 -2
  18. package/dist/node/cjs/jwk/parse.js +2 -31
  19. package/dist/node/cjs/jwks/remote.js +1 -1
  20. package/dist/node/cjs/jws/compact/verify.js +5 -1
  21. package/dist/node/cjs/jws/flattened/verify.js +5 -0
  22. package/dist/node/cjs/jwt/decrypt.js +5 -1
  23. package/dist/node/cjs/jwt/verify.js +5 -1
  24. package/dist/node/cjs/key/export.js +4 -2
  25. package/dist/node/cjs/key/import.js +32 -2
  26. package/dist/node/cjs/lib/decrypt_key_management.js +2 -2
  27. package/dist/node/esm/jwe/compact/decrypt.js +5 -1
  28. package/dist/node/esm/jwe/flattened/decrypt.js +5 -0
  29. package/dist/node/esm/jwk/embedded.js +2 -2
  30. package/dist/node/esm/jwk/from_key_like.js +2 -2
  31. package/dist/node/esm/jwk/parse.js +2 -31
  32. package/dist/node/esm/jwks/remote.js +1 -1
  33. package/dist/node/esm/jws/compact/verify.js +5 -1
  34. package/dist/node/esm/jws/flattened/verify.js +5 -0
  35. package/dist/node/esm/jwt/decrypt.js +5 -1
  36. package/dist/node/esm/jwt/verify.js +5 -1
  37. package/dist/node/esm/key/export.js +4 -2
  38. package/dist/node/esm/key/import.js +33 -3
  39. package/dist/node/esm/lib/decrypt_key_management.js +2 -2
  40. package/dist/types/jwe/compact/decrypt.d.ts +3 -2
  41. package/dist/types/jwe/flattened/decrypt.d.ts +3 -2
  42. package/dist/types/jwe/general/decrypt.d.ts +3 -2
  43. package/dist/types/jws/compact/verify.d.ts +3 -2
  44. package/dist/types/jws/flattened/verify.d.ts +3 -2
  45. package/dist/types/jws/general/verify.d.ts +3 -2
  46. package/dist/types/jwt/decrypt.d.ts +3 -2
  47. package/dist/types/jwt/verify.d.ts +3 -2
  48. package/dist/types/key/export.d.ts +3 -4
  49. package/dist/types/key/import.d.ts +3 -4
  50. package/dist/types/types.d.ts +3 -0
  51. package/package.json +1 -1
@@ -19,7 +19,11 @@ async function compactDecrypt(jwe, key, options) {
19
19
  tag: (tag || undefined),
20
20
  encrypted_key: encryptedKey || undefined,
21
21
  }, key, options);
22
- return { plaintext: decrypted.plaintext, protectedHeader: decrypted.protectedHeader };
22
+ const result = { plaintext: decrypted.plaintext, protectedHeader: decrypted.protectedHeader };
23
+ if (typeof key === 'function') {
24
+ return { ...result, key: decrypted.key };
25
+ }
26
+ return result;
23
27
  }
24
28
  export { compactDecrypt };
25
29
  export default compactDecrypt;
@@ -92,8 +92,10 @@ async function flattenedDecrypt(jwe, key, options) {
92
92
  if (jwe.encrypted_key !== undefined) {
93
93
  encryptedKey = base64url(jwe.encrypted_key);
94
94
  }
95
+ let resolvedKey = false;
95
96
  if (typeof key === 'function') {
96
97
  key = await key(parsedProt, jwe);
98
+ resolvedKey = true;
97
99
  }
98
100
  let cek;
99
101
  try {
@@ -132,6 +134,9 @@ async function flattenedDecrypt(jwe, key, options) {
132
134
  if (jwe.header !== undefined) {
133
135
  result.unprotectedHeader = jwe.header;
134
136
  }
137
+ if (resolvedKey) {
138
+ return { ...result, key };
139
+ }
135
140
  return result;
136
141
  }
137
142
  export { flattenedDecrypt };
@@ -1,4 +1,4 @@
1
- import parseJwk from './parse.js';
1
+ import { importJWK } from '../key/import.js';
2
2
  import isObject from '../lib/is_object.js';
3
3
  import { JWSInvalid } from '../util/errors.js';
4
4
  async function EmbeddedJWK(protectedHeader, token) {
@@ -9,7 +9,7 @@ async function EmbeddedJWK(protectedHeader, token) {
9
9
  if (!isObject(joseHeader.jwk)) {
10
10
  throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a JSON object');
11
11
  }
12
- const key = await parseJwk(joseHeader.jwk, joseHeader.alg, true);
12
+ const key = (await importJWK({ ...joseHeader.jwk, ext: true }, joseHeader.alg, true));
13
13
  if (key.type !== 'public') {
14
14
  throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a public key');
15
15
  }
@@ -1,6 +1,6 @@
1
- import asJWK from '../runtime/key_to_jwk.js';
1
+ import { exportJWK } from '../key/export.js';
2
2
  async function fromKeyLike(key) {
3
- return asJWK(key);
3
+ return exportJWK(key);
4
4
  }
5
5
  export { fromKeyLike };
6
6
  export default fromKeyLike;
@@ -1,35 +1,6 @@
1
- import { decode as base64url } from '../runtime/base64url.js';
2
- import asKeyObject from '../runtime/jwk_to_key.js';
3
- import { JOSENotSupported } from '../util/errors.js';
4
- import isObject from '../lib/is_object.js';
1
+ import { importJWK } from '../key/import.js';
5
2
  async function parseJwk(jwk, alg, octAsKeyObject) {
6
- if (!isObject(jwk)) {
7
- throw new TypeError('JWK must be an object');
8
- }
9
- alg || (alg = jwk.alg);
10
- if (typeof alg !== 'string' || !alg) {
11
- throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
12
- }
13
- switch (jwk.kty) {
14
- case 'oct':
15
- if (typeof jwk.k !== 'string' || !jwk.k) {
16
- throw new TypeError('missing "k" (Key Value) Parameter value');
17
- }
18
- octAsKeyObject !== null && octAsKeyObject !== void 0 ? octAsKeyObject : (octAsKeyObject = jwk.ext !== true);
19
- if (octAsKeyObject) {
20
- return asKeyObject({ ...jwk, alg, ext: false });
21
- }
22
- return base64url(jwk.k);
23
- case 'RSA':
24
- if (jwk.oth !== undefined) {
25
- throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
26
- }
27
- case 'EC':
28
- case 'OKP':
29
- return asKeyObject({ ...jwk, alg });
30
- default:
31
- throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
32
- }
3
+ return importJWK(jwk, alg, octAsKeyObject);
33
4
  }
34
5
  export { parseJwk };
35
6
  export default parseJwk;
@@ -93,7 +93,7 @@ class RemoteJWKSet {
93
93
  }
94
94
  const cached = this._cached.get(jwk);
95
95
  if (cached[protectedHeader.alg] === undefined) {
96
- const keyObject = await parseJWK({ ...jwk, alg: protectedHeader.alg });
96
+ const keyObject = (await parseJWK({ ...jwk, alg: protectedHeader.alg, ext: true }));
97
97
  if (keyObject.type !== 'public') {
98
98
  throw new JWKSInvalid('JSON Web Key Set members must be public keys');
99
99
  }
@@ -17,7 +17,11 @@ async function compactVerify(jws, key, options) {
17
17
  protected: protectedHeader || undefined,
18
18
  signature: (signature || undefined),
19
19
  }, key, options);
20
- return { payload: verified.payload, protectedHeader: verified.protectedHeader };
20
+ const result = { payload: verified.payload, protectedHeader: verified.protectedHeader };
21
+ if (typeof key === 'function') {
22
+ return { ...result, key: verified.key };
23
+ }
24
+ return result;
21
25
  }
22
26
  export { compactVerify };
23
27
  export default compactVerify;
@@ -70,8 +70,10 @@ async function flattenedVerify(jws, key, options) {
70
70
  else if (typeof jws.payload !== 'string' && !(jws.payload instanceof Uint8Array)) {
71
71
  throw new JWSInvalid('JWS Payload must be a string or an Uint8Array instance');
72
72
  }
73
+ let resolvedKey = false;
73
74
  if (typeof key === 'function') {
74
75
  key = await key(parsedProt, jws);
76
+ resolvedKey = true;
75
77
  }
76
78
  checkKeyType(alg, key, 'verify');
77
79
  const data = concat(encoder.encode((_a = jws.protected) !== null && _a !== void 0 ? _a : ''), encoder.encode('.'), typeof jws.payload === 'string' ? encoder.encode(jws.payload) : jws.payload);
@@ -97,6 +99,9 @@ async function flattenedVerify(jws, key, options) {
97
99
  if (jws.header !== undefined) {
98
100
  result.unprotectedHeader = jws.header;
99
101
  }
102
+ if (resolvedKey) {
103
+ return { ...result, key };
104
+ }
100
105
  return result;
101
106
  }
102
107
  export { flattenedVerify };
@@ -15,7 +15,11 @@ async function jwtDecrypt(jwt, key, options) {
15
15
  JSON.stringify(protectedHeader.aud) !== JSON.stringify(payload.aud)) {
16
16
  throw new JWTClaimValidationFailed('replicated "aud" claim header parameter mismatch', 'aud', 'mismatch');
17
17
  }
18
- return { payload, protectedHeader };
18
+ const result = { payload, protectedHeader };
19
+ if (typeof key === 'function') {
20
+ return { ...result, key: decrypted.key };
21
+ }
22
+ return result;
19
23
  }
20
24
  export { jwtDecrypt };
21
25
  export default jwtDecrypt;
@@ -8,7 +8,11 @@ async function jwtVerify(jwt, key, options) {
8
8
  throw new JWTInvalid('JWTs MUST NOT use unencoded payload');
9
9
  }
10
10
  const payload = jwtPayload(verified.protectedHeader, verified.payload, options);
11
- return { payload, protectedHeader: verified.protectedHeader };
11
+ const result = { payload, protectedHeader: verified.protectedHeader };
12
+ if (typeof key === 'function') {
13
+ return { ...result, key: verified.key };
14
+ }
15
+ return result;
12
16
  }
13
17
  export { jwtVerify };
14
18
  export default jwtVerify;
@@ -1,10 +1,12 @@
1
1
  import { toSPKI as exportPublic } from '../runtime/asn1.js';
2
2
  import { toPKCS8 as exportPrivate } from '../runtime/asn1.js';
3
- import { fromKeyLike } from '../jwk/from_key_like.js';
3
+ import keyToJWK from '../runtime/key_to_jwk.js';
4
4
  export async function exportSPKI(key) {
5
5
  return exportPublic(key);
6
6
  }
7
7
  export async function exportPKCS8(key) {
8
8
  return exportPrivate(key);
9
9
  }
10
- export const exportJWK = (...args) => fromKeyLike(...args);
10
+ export async function exportJWK(key) {
11
+ return keyToJWK(key);
12
+ }
@@ -1,8 +1,10 @@
1
- import { encodeBase64, decodeBase64 } from '../runtime/base64url.js';
1
+ import { decode as decodeBase64URL, encodeBase64, decodeBase64 } from '../runtime/base64url.js';
2
2
  import { fromSPKI as importPublic } from '../runtime/asn1.js';
3
3
  import { fromPKCS8 as importPrivate } from '../runtime/asn1.js';
4
+ import asKeyObject from '../runtime/jwk_to_key.js';
5
+ import { JOSENotSupported } from '../util/errors.js';
4
6
  import formatPEM from '../lib/format_pem.js';
5
- import { parseJwk as importJwk } from '../jwk/parse.js';
7
+ import isObject from '../lib/is_object.js';
6
8
  function getElement(seq) {
7
9
  let result = [];
8
10
  let next = 0;
@@ -86,4 +88,32 @@ export async function importPKCS8(pkcs8, alg, options) {
86
88
  }
87
89
  return importPrivate(pkcs8, alg, options);
88
90
  }
89
- export const importJWK = (...args) => importJwk(...args);
91
+ export async function importJWK(jwk, alg, octAsKeyObject) {
92
+ if (!isObject(jwk)) {
93
+ throw new TypeError('JWK must be an object');
94
+ }
95
+ alg || (alg = jwk.alg);
96
+ if (typeof alg !== 'string' || !alg) {
97
+ throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
98
+ }
99
+ switch (jwk.kty) {
100
+ case 'oct':
101
+ if (typeof jwk.k !== 'string' || !jwk.k) {
102
+ throw new TypeError('missing "k" (Key Value) Parameter value');
103
+ }
104
+ octAsKeyObject !== null && octAsKeyObject !== void 0 ? octAsKeyObject : (octAsKeyObject = jwk.ext !== true);
105
+ if (octAsKeyObject) {
106
+ return asKeyObject({ ...jwk, alg, ext: false });
107
+ }
108
+ return decodeBase64URL(jwk.k);
109
+ case 'RSA':
110
+ if (jwk.oth !== undefined) {
111
+ throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
112
+ }
113
+ case 'EC':
114
+ case 'OKP':
115
+ return asKeyObject({ ...jwk, alg });
116
+ default:
117
+ throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
118
+ }
119
+ }
@@ -6,7 +6,7 @@ import { unwrap as aesGcmKw } from '../runtime/aesgcmkw.js';
6
6
  import { decode as base64url } from '../runtime/base64url.js';
7
7
  import { JOSENotSupported, JWEInvalid } from '../util/errors.js';
8
8
  import { bitLengths as cekLengths } from '../lib/cek.js';
9
- import { parseJwk } from '../jwk/parse.js';
9
+ import { importJWK } from '../key/import.js';
10
10
  import checkKeyType from './check_key_type.js';
11
11
  function assertEnryptedKey(encryptedKey) {
12
12
  if (!encryptedKey) {
@@ -38,7 +38,7 @@ async function decryptKeyManagement(alg, key, encryptedKey, joseHeader) {
38
38
  if (!ECDH.ecdhAllowed(key)) {
39
39
  throw new JOSENotSupported('ECDH-ES with the provided key is not allowed or not supported by your javascript runtime');
40
40
  }
41
- const epk = await parseJwk(joseHeader.epk, alg);
41
+ const epk = await importJWK(joseHeader.epk, alg);
42
42
  let partyUInfo;
43
43
  let partyVInfo;
44
44
  if (joseHeader.apu !== undefined)
@@ -22,7 +22,11 @@ async function compactDecrypt(jwe, key, options) {
22
22
  tag: (tag || undefined),
23
23
  encrypted_key: encryptedKey || undefined,
24
24
  }, key, options);
25
- return { plaintext: decrypted.plaintext, protectedHeader: decrypted.protectedHeader };
25
+ const result = { plaintext: decrypted.plaintext, protectedHeader: decrypted.protectedHeader };
26
+ if (typeof key === 'function') {
27
+ return { ...result, key: decrypted.key };
28
+ }
29
+ return result;
26
30
  }
27
31
  exports.compactDecrypt = compactDecrypt;
28
32
  exports.default = compactDecrypt;
@@ -95,8 +95,10 @@ async function flattenedDecrypt(jwe, key, options) {
95
95
  if (jwe.encrypted_key !== undefined) {
96
96
  encryptedKey = (0, base64url_js_1.decode)(jwe.encrypted_key);
97
97
  }
98
+ let resolvedKey = false;
98
99
  if (typeof key === 'function') {
99
100
  key = await key(parsedProt, jwe);
101
+ resolvedKey = true;
100
102
  }
101
103
  let cek;
102
104
  try {
@@ -135,6 +137,9 @@ async function flattenedDecrypt(jwe, key, options) {
135
137
  if (jwe.header !== undefined) {
136
138
  result.unprotectedHeader = jwe.header;
137
139
  }
140
+ if (resolvedKey) {
141
+ return { ...result, key };
142
+ }
138
143
  return result;
139
144
  }
140
145
  exports.flattenedDecrypt = flattenedDecrypt;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EmbeddedJWK = void 0;
4
- const parse_js_1 = require("./parse.js");
4
+ const import_js_1 = require("../key/import.js");
5
5
  const is_object_js_1 = require("../lib/is_object.js");
6
6
  const errors_js_1 = require("../util/errors.js");
7
7
  async function EmbeddedJWK(protectedHeader, token) {
@@ -12,7 +12,7 @@ async function EmbeddedJWK(protectedHeader, token) {
12
12
  if (!(0, is_object_js_1.default)(joseHeader.jwk)) {
13
13
  throw new errors_js_1.JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a JSON object');
14
14
  }
15
- const key = await (0, parse_js_1.default)(joseHeader.jwk, joseHeader.alg, true);
15
+ const key = (await (0, import_js_1.importJWK)({ ...joseHeader.jwk, ext: true }, joseHeader.alg, true));
16
16
  if (key.type !== 'public') {
17
17
  throw new errors_js_1.JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a public key');
18
18
  }
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fromKeyLike = void 0;
4
- const key_to_jwk_js_1 = require("../runtime/key_to_jwk.js");
4
+ const export_js_1 = require("../key/export.js");
5
5
  async function fromKeyLike(key) {
6
- return (0, key_to_jwk_js_1.default)(key);
6
+ return (0, export_js_1.exportJWK)(key);
7
7
  }
8
8
  exports.fromKeyLike = fromKeyLike;
9
9
  exports.default = fromKeyLike;
@@ -1,38 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseJwk = void 0;
4
- const base64url_js_1 = require("../runtime/base64url.js");
5
- const jwk_to_key_js_1 = require("../runtime/jwk_to_key.js");
6
- const errors_js_1 = require("../util/errors.js");
7
- const is_object_js_1 = require("../lib/is_object.js");
4
+ const import_js_1 = require("../key/import.js");
8
5
  async function parseJwk(jwk, alg, octAsKeyObject) {
9
- if (!(0, is_object_js_1.default)(jwk)) {
10
- throw new TypeError('JWK must be an object');
11
- }
12
- alg || (alg = jwk.alg);
13
- if (typeof alg !== 'string' || !alg) {
14
- throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
15
- }
16
- switch (jwk.kty) {
17
- case 'oct':
18
- if (typeof jwk.k !== 'string' || !jwk.k) {
19
- throw new TypeError('missing "k" (Key Value) Parameter value');
20
- }
21
- octAsKeyObject !== null && octAsKeyObject !== void 0 ? octAsKeyObject : (octAsKeyObject = jwk.ext !== true);
22
- if (octAsKeyObject) {
23
- return (0, jwk_to_key_js_1.default)({ ...jwk, alg, ext: false });
24
- }
25
- return (0, base64url_js_1.decode)(jwk.k);
26
- case 'RSA':
27
- if (jwk.oth !== undefined) {
28
- throw new errors_js_1.JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
29
- }
30
- case 'EC':
31
- case 'OKP':
32
- return (0, jwk_to_key_js_1.default)({ ...jwk, alg });
33
- default:
34
- throw new errors_js_1.JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
35
- }
6
+ return (0, import_js_1.importJWK)(jwk, alg, octAsKeyObject);
36
7
  }
37
8
  exports.parseJwk = parseJwk;
38
9
  exports.default = parseJwk;
@@ -96,7 +96,7 @@ class RemoteJWKSet {
96
96
  }
97
97
  const cached = this._cached.get(jwk);
98
98
  if (cached[protectedHeader.alg] === undefined) {
99
- const keyObject = await (0, parse_js_1.default)({ ...jwk, alg: protectedHeader.alg });
99
+ const keyObject = (await (0, parse_js_1.default)({ ...jwk, alg: protectedHeader.alg, ext: true }));
100
100
  if (keyObject.type !== 'public') {
101
101
  throw new errors_js_1.JWKSInvalid('JSON Web Key Set members must be public keys');
102
102
  }
@@ -20,7 +20,11 @@ async function compactVerify(jws, key, options) {
20
20
  protected: protectedHeader || undefined,
21
21
  signature: (signature || undefined),
22
22
  }, key, options);
23
- return { payload: verified.payload, protectedHeader: verified.protectedHeader };
23
+ const result = { payload: verified.payload, protectedHeader: verified.protectedHeader };
24
+ if (typeof key === 'function') {
25
+ return { ...result, key: verified.key };
26
+ }
27
+ return result;
24
28
  }
25
29
  exports.compactVerify = compactVerify;
26
30
  exports.default = compactVerify;
@@ -73,8 +73,10 @@ async function flattenedVerify(jws, key, options) {
73
73
  else if (typeof jws.payload !== 'string' && !(jws.payload instanceof Uint8Array)) {
74
74
  throw new errors_js_1.JWSInvalid('JWS Payload must be a string or an Uint8Array instance');
75
75
  }
76
+ let resolvedKey = false;
76
77
  if (typeof key === 'function') {
77
78
  key = await key(parsedProt, jws);
79
+ resolvedKey = true;
78
80
  }
79
81
  (0, check_key_type_js_1.default)(alg, key, 'verify');
80
82
  const data = (0, buffer_utils_js_1.concat)(buffer_utils_js_1.encoder.encode((_a = jws.protected) !== null && _a !== void 0 ? _a : ''), buffer_utils_js_1.encoder.encode('.'), typeof jws.payload === 'string' ? buffer_utils_js_1.encoder.encode(jws.payload) : jws.payload);
@@ -100,6 +102,9 @@ async function flattenedVerify(jws, key, options) {
100
102
  if (jws.header !== undefined) {
101
103
  result.unprotectedHeader = jws.header;
102
104
  }
105
+ if (resolvedKey) {
106
+ return { ...result, key };
107
+ }
103
108
  return result;
104
109
  }
105
110
  exports.flattenedVerify = flattenedVerify;
@@ -18,7 +18,11 @@ async function jwtDecrypt(jwt, key, options) {
18
18
  JSON.stringify(protectedHeader.aud) !== JSON.stringify(payload.aud)) {
19
19
  throw new errors_js_1.JWTClaimValidationFailed('replicated "aud" claim header parameter mismatch', 'aud', 'mismatch');
20
20
  }
21
- return { payload, protectedHeader };
21
+ const result = { payload, protectedHeader };
22
+ if (typeof key === 'function') {
23
+ return { ...result, key: decrypted.key };
24
+ }
25
+ return result;
22
26
  }
23
27
  exports.jwtDecrypt = jwtDecrypt;
24
28
  exports.default = jwtDecrypt;
@@ -11,7 +11,11 @@ async function jwtVerify(jwt, key, options) {
11
11
  throw new errors_js_1.JWTInvalid('JWTs MUST NOT use unencoded payload');
12
12
  }
13
13
  const payload = (0, jwt_claims_set_js_1.default)(verified.protectedHeader, verified.payload, options);
14
- return { payload, protectedHeader: verified.protectedHeader };
14
+ const result = { payload, protectedHeader: verified.protectedHeader };
15
+ if (typeof key === 'function') {
16
+ return { ...result, key: verified.key };
17
+ }
18
+ return result;
15
19
  }
16
20
  exports.jwtVerify = jwtVerify;
17
21
  exports.default = jwtVerify;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.exportJWK = exports.exportPKCS8 = exports.exportSPKI = void 0;
4
4
  const asn1_js_1 = require("../runtime/asn1.js");
5
5
  const asn1_js_2 = require("../runtime/asn1.js");
6
- const from_key_like_js_1 = require("../jwk/from_key_like.js");
6
+ const key_to_jwk_js_1 = require("../runtime/key_to_jwk.js");
7
7
  async function exportSPKI(key) {
8
8
  return (0, asn1_js_1.toSPKI)(key);
9
9
  }
@@ -12,5 +12,7 @@ async function exportPKCS8(key) {
12
12
  return (0, asn1_js_2.toPKCS8)(key);
13
13
  }
14
14
  exports.exportPKCS8 = exportPKCS8;
15
- const exportJWK = (...args) => (0, from_key_like_js_1.fromKeyLike)(...args);
15
+ async function exportJWK(key) {
16
+ return (0, key_to_jwk_js_1.default)(key);
17
+ }
16
18
  exports.exportJWK = exportJWK;
@@ -4,8 +4,10 @@ exports.importJWK = exports.importPKCS8 = exports.importX509 = exports.importSPK
4
4
  const base64url_js_1 = require("../runtime/base64url.js");
5
5
  const asn1_js_1 = require("../runtime/asn1.js");
6
6
  const asn1_js_2 = require("../runtime/asn1.js");
7
+ const jwk_to_key_js_1 = require("../runtime/jwk_to_key.js");
8
+ const errors_js_1 = require("../util/errors.js");
7
9
  const format_pem_js_1 = require("../lib/format_pem.js");
8
- const parse_js_1 = require("../jwk/parse.js");
10
+ const is_object_js_1 = require("../lib/is_object.js");
9
11
  function getElement(seq) {
10
12
  let result = [];
11
13
  let next = 0;
@@ -92,5 +94,33 @@ async function importPKCS8(pkcs8, alg, options) {
92
94
  return (0, asn1_js_2.fromPKCS8)(pkcs8, alg, options);
93
95
  }
94
96
  exports.importPKCS8 = importPKCS8;
95
- const importJWK = (...args) => (0, parse_js_1.parseJwk)(...args);
97
+ async function importJWK(jwk, alg, octAsKeyObject) {
98
+ if (!(0, is_object_js_1.default)(jwk)) {
99
+ throw new TypeError('JWK must be an object');
100
+ }
101
+ alg || (alg = jwk.alg);
102
+ if (typeof alg !== 'string' || !alg) {
103
+ throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
104
+ }
105
+ switch (jwk.kty) {
106
+ case 'oct':
107
+ if (typeof jwk.k !== 'string' || !jwk.k) {
108
+ throw new TypeError('missing "k" (Key Value) Parameter value');
109
+ }
110
+ octAsKeyObject !== null && octAsKeyObject !== void 0 ? octAsKeyObject : (octAsKeyObject = jwk.ext !== true);
111
+ if (octAsKeyObject) {
112
+ return (0, jwk_to_key_js_1.default)({ ...jwk, alg, ext: false });
113
+ }
114
+ return (0, base64url_js_1.decode)(jwk.k);
115
+ case 'RSA':
116
+ if (jwk.oth !== undefined) {
117
+ throw new errors_js_1.JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
118
+ }
119
+ case 'EC':
120
+ case 'OKP':
121
+ return (0, jwk_to_key_js_1.default)({ ...jwk, alg });
122
+ default:
123
+ throw new errors_js_1.JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
124
+ }
125
+ }
96
126
  exports.importJWK = importJWK;
@@ -8,7 +8,7 @@ const aesgcmkw_js_1 = require("../runtime/aesgcmkw.js");
8
8
  const base64url_js_1 = require("../runtime/base64url.js");
9
9
  const errors_js_1 = require("../util/errors.js");
10
10
  const cek_js_1 = require("../lib/cek.js");
11
- const parse_js_1 = require("../jwk/parse.js");
11
+ const import_js_1 = require("../key/import.js");
12
12
  const check_key_type_js_1 = require("./check_key_type.js");
13
13
  function assertEnryptedKey(encryptedKey) {
14
14
  if (!encryptedKey) {
@@ -40,7 +40,7 @@ async function decryptKeyManagement(alg, key, encryptedKey, joseHeader) {
40
40
  if (!ECDH.ecdhAllowed(key)) {
41
41
  throw new errors_js_1.JOSENotSupported('ECDH-ES with the provided key is not allowed or not supported by your javascript runtime');
42
42
  }
43
- const epk = await (0, parse_js_1.parseJwk)(joseHeader.epk, alg);
43
+ const epk = await (0, import_js_1.importJWK)(joseHeader.epk, alg);
44
44
  let partyUInfo;
45
45
  let partyVInfo;
46
46
  if (joseHeader.apu !== undefined)
@@ -19,7 +19,11 @@ async function compactDecrypt(jwe, key, options) {
19
19
  tag: (tag || undefined),
20
20
  encrypted_key: encryptedKey || undefined,
21
21
  }, key, options);
22
- return { plaintext: decrypted.plaintext, protectedHeader: decrypted.protectedHeader };
22
+ const result = { plaintext: decrypted.plaintext, protectedHeader: decrypted.protectedHeader };
23
+ if (typeof key === 'function') {
24
+ return { ...result, key: decrypted.key };
25
+ }
26
+ return result;
23
27
  }
24
28
  export { compactDecrypt };
25
29
  export default compactDecrypt;
@@ -92,8 +92,10 @@ async function flattenedDecrypt(jwe, key, options) {
92
92
  if (jwe.encrypted_key !== undefined) {
93
93
  encryptedKey = base64url(jwe.encrypted_key);
94
94
  }
95
+ let resolvedKey = false;
95
96
  if (typeof key === 'function') {
96
97
  key = await key(parsedProt, jwe);
98
+ resolvedKey = true;
97
99
  }
98
100
  let cek;
99
101
  try {
@@ -132,6 +134,9 @@ async function flattenedDecrypt(jwe, key, options) {
132
134
  if (jwe.header !== undefined) {
133
135
  result.unprotectedHeader = jwe.header;
134
136
  }
137
+ if (resolvedKey) {
138
+ return { ...result, key };
139
+ }
135
140
  return result;
136
141
  }
137
142
  export { flattenedDecrypt };
@@ -1,4 +1,4 @@
1
- import parseJwk from './parse.js';
1
+ import { importJWK } from '../key/import.js';
2
2
  import isObject from '../lib/is_object.js';
3
3
  import { JWSInvalid } from '../util/errors.js';
4
4
  async function EmbeddedJWK(protectedHeader, token) {
@@ -9,7 +9,7 @@ async function EmbeddedJWK(protectedHeader, token) {
9
9
  if (!isObject(joseHeader.jwk)) {
10
10
  throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a JSON object');
11
11
  }
12
- const key = await parseJwk(joseHeader.jwk, joseHeader.alg, true);
12
+ const key = (await importJWK({ ...joseHeader.jwk, ext: true }, joseHeader.alg, true));
13
13
  if (key.type !== 'public') {
14
14
  throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a public key');
15
15
  }
@@ -1,6 +1,6 @@
1
- import asJWK from '../runtime/key_to_jwk.js';
1
+ import { exportJWK } from '../key/export.js';
2
2
  async function fromKeyLike(key) {
3
- return asJWK(key);
3
+ return exportJWK(key);
4
4
  }
5
5
  export { fromKeyLike };
6
6
  export default fromKeyLike;
@@ -1,35 +1,6 @@
1
- import { decode as base64url } from '../runtime/base64url.js';
2
- import asKeyObject from '../runtime/jwk_to_key.js';
3
- import { JOSENotSupported } from '../util/errors.js';
4
- import isObject from '../lib/is_object.js';
1
+ import { importJWK } from '../key/import.js';
5
2
  async function parseJwk(jwk, alg, octAsKeyObject) {
6
- if (!isObject(jwk)) {
7
- throw new TypeError('JWK must be an object');
8
- }
9
- alg || (alg = jwk.alg);
10
- if (typeof alg !== 'string' || !alg) {
11
- throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
12
- }
13
- switch (jwk.kty) {
14
- case 'oct':
15
- if (typeof jwk.k !== 'string' || !jwk.k) {
16
- throw new TypeError('missing "k" (Key Value) Parameter value');
17
- }
18
- octAsKeyObject !== null && octAsKeyObject !== void 0 ? octAsKeyObject : (octAsKeyObject = jwk.ext !== true);
19
- if (octAsKeyObject) {
20
- return asKeyObject({ ...jwk, alg, ext: false });
21
- }
22
- return base64url(jwk.k);
23
- case 'RSA':
24
- if (jwk.oth !== undefined) {
25
- throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
26
- }
27
- case 'EC':
28
- case 'OKP':
29
- return asKeyObject({ ...jwk, alg });
30
- default:
31
- throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
32
- }
3
+ return importJWK(jwk, alg, octAsKeyObject);
33
4
  }
34
5
  export { parseJwk };
35
6
  export default parseJwk;
@@ -93,7 +93,7 @@ class RemoteJWKSet {
93
93
  }
94
94
  const cached = this._cached.get(jwk);
95
95
  if (cached[protectedHeader.alg] === undefined) {
96
- const keyObject = await parseJWK({ ...jwk, alg: protectedHeader.alg });
96
+ const keyObject = (await parseJWK({ ...jwk, alg: protectedHeader.alg, ext: true }));
97
97
  if (keyObject.type !== 'public') {
98
98
  throw new JWKSInvalid('JSON Web Key Set members must be public keys');
99
99
  }
@@ -17,7 +17,11 @@ async function compactVerify(jws, key, options) {
17
17
  protected: protectedHeader || undefined,
18
18
  signature: (signature || undefined),
19
19
  }, key, options);
20
- return { payload: verified.payload, protectedHeader: verified.protectedHeader };
20
+ const result = { payload: verified.payload, protectedHeader: verified.protectedHeader };
21
+ if (typeof key === 'function') {
22
+ return { ...result, key: verified.key };
23
+ }
24
+ return result;
21
25
  }
22
26
  export { compactVerify };
23
27
  export default compactVerify;
@@ -70,8 +70,10 @@ async function flattenedVerify(jws, key, options) {
70
70
  else if (typeof jws.payload !== 'string' && !(jws.payload instanceof Uint8Array)) {
71
71
  throw new JWSInvalid('JWS Payload must be a string or an Uint8Array instance');
72
72
  }
73
+ let resolvedKey = false;
73
74
  if (typeof key === 'function') {
74
75
  key = await key(parsedProt, jws);
76
+ resolvedKey = true;
75
77
  }
76
78
  checkKeyType(alg, key, 'verify');
77
79
  const data = concat(encoder.encode((_a = jws.protected) !== null && _a !== void 0 ? _a : ''), encoder.encode('.'), typeof jws.payload === 'string' ? encoder.encode(jws.payload) : jws.payload);
@@ -97,6 +99,9 @@ async function flattenedVerify(jws, key, options) {
97
99
  if (jws.header !== undefined) {
98
100
  result.unprotectedHeader = jws.header;
99
101
  }
102
+ if (resolvedKey) {
103
+ return { ...result, key };
104
+ }
100
105
  return result;
101
106
  }
102
107
  export { flattenedVerify };
@@ -15,7 +15,11 @@ async function jwtDecrypt(jwt, key, options) {
15
15
  JSON.stringify(protectedHeader.aud) !== JSON.stringify(payload.aud)) {
16
16
  throw new JWTClaimValidationFailed('replicated "aud" claim header parameter mismatch', 'aud', 'mismatch');
17
17
  }
18
- return { payload, protectedHeader };
18
+ const result = { payload, protectedHeader };
19
+ if (typeof key === 'function') {
20
+ return { ...result, key: decrypted.key };
21
+ }
22
+ return result;
19
23
  }
20
24
  export { jwtDecrypt };
21
25
  export default jwtDecrypt;
@@ -8,7 +8,11 @@ async function jwtVerify(jwt, key, options) {
8
8
  throw new JWTInvalid('JWTs MUST NOT use unencoded payload');
9
9
  }
10
10
  const payload = jwtPayload(verified.protectedHeader, verified.payload, options);
11
- return { payload, protectedHeader: verified.protectedHeader };
11
+ const result = { payload, protectedHeader: verified.protectedHeader };
12
+ if (typeof key === 'function') {
13
+ return { ...result, key: verified.key };
14
+ }
15
+ return result;
12
16
  }
13
17
  export { jwtVerify };
14
18
  export default jwtVerify;
@@ -1,10 +1,12 @@
1
1
  import { toSPKI as exportPublic } from '../runtime/asn1.js';
2
2
  import { toPKCS8 as exportPrivate } from '../runtime/asn1.js';
3
- import { fromKeyLike } from '../jwk/from_key_like.js';
3
+ import keyToJWK from '../runtime/key_to_jwk.js';
4
4
  export async function exportSPKI(key) {
5
5
  return exportPublic(key);
6
6
  }
7
7
  export async function exportPKCS8(key) {
8
8
  return exportPrivate(key);
9
9
  }
10
- export const exportJWK = (...args) => fromKeyLike(...args);
10
+ export async function exportJWK(key) {
11
+ return keyToJWK(key);
12
+ }
@@ -1,8 +1,10 @@
1
- import { encodeBase64, decodeBase64 } from '../runtime/base64url.js';
1
+ import { decode as decodeBase64URL, encodeBase64, decodeBase64 } from '../runtime/base64url.js';
2
2
  import { fromSPKI as importPublic } from '../runtime/asn1.js';
3
3
  import { fromPKCS8 as importPrivate } from '../runtime/asn1.js';
4
+ import asKeyObject from '../runtime/jwk_to_key.js';
5
+ import { JOSENotSupported } from '../util/errors.js';
4
6
  import formatPEM from '../lib/format_pem.js';
5
- import { parseJwk as importJwk } from '../jwk/parse.js';
7
+ import isObject from '../lib/is_object.js';
6
8
  function getElement(seq) {
7
9
  let result = [];
8
10
  let next = 0;
@@ -86,4 +88,32 @@ export async function importPKCS8(pkcs8, alg, options) {
86
88
  }
87
89
  return importPrivate(pkcs8, alg, options);
88
90
  }
89
- export const importJWK = (...args) => importJwk(...args);
91
+ export async function importJWK(jwk, alg, octAsKeyObject) {
92
+ if (!isObject(jwk)) {
93
+ throw new TypeError('JWK must be an object');
94
+ }
95
+ alg || (alg = jwk.alg);
96
+ if (typeof alg !== 'string' || !alg) {
97
+ throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
98
+ }
99
+ switch (jwk.kty) {
100
+ case 'oct':
101
+ if (typeof jwk.k !== 'string' || !jwk.k) {
102
+ throw new TypeError('missing "k" (Key Value) Parameter value');
103
+ }
104
+ octAsKeyObject !== null && octAsKeyObject !== void 0 ? octAsKeyObject : (octAsKeyObject = jwk.ext !== true);
105
+ if (octAsKeyObject) {
106
+ return asKeyObject({ ...jwk, alg, ext: false });
107
+ }
108
+ return decodeBase64URL(jwk.k);
109
+ case 'RSA':
110
+ if (jwk.oth !== undefined) {
111
+ throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
112
+ }
113
+ case 'EC':
114
+ case 'OKP':
115
+ return asKeyObject({ ...jwk, alg });
116
+ default:
117
+ throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
118
+ }
119
+ }
@@ -6,7 +6,7 @@ import { unwrap as aesGcmKw } from '../runtime/aesgcmkw.js';
6
6
  import { decode as base64url } from '../runtime/base64url.js';
7
7
  import { JOSENotSupported, JWEInvalid } from '../util/errors.js';
8
8
  import { bitLengths as cekLengths } from '../lib/cek.js';
9
- import { parseJwk } from '../jwk/parse.js';
9
+ import { importJWK } from '../key/import.js';
10
10
  import checkKeyType from './check_key_type.js';
11
11
  function assertEnryptedKey(encryptedKey) {
12
12
  if (!encryptedKey) {
@@ -38,7 +38,7 @@ async function decryptKeyManagement(alg, key, encryptedKey, joseHeader) {
38
38
  if (!ECDH.ecdhAllowed(key)) {
39
39
  throw new JOSENotSupported('ECDH-ES with the provided key is not allowed or not supported by your javascript runtime');
40
40
  }
41
- const epk = await parseJwk(joseHeader.epk, alg);
41
+ const epk = await importJWK(joseHeader.epk, alg);
42
42
  let partyUInfo;
43
43
  let partyVInfo;
44
44
  if (joseHeader.apu !== undefined)
@@ -1,7 +1,8 @@
1
- import type { KeyLike, DecryptOptions, JWEHeaderParameters, GetKeyFunction, FlattenedJWE, CompactDecryptResult } from '../../types';
1
+ import type { KeyLike, DecryptOptions, JWEHeaderParameters, GetKeyFunction, FlattenedJWE, CompactDecryptResult, ResolvedKey } from '../../types';
2
2
  export interface CompactDecryptGetKey extends GetKeyFunction<JWEHeaderParameters, FlattenedJWE> {
3
3
  }
4
- declare function compactDecrypt(jwe: string | Uint8Array, key: KeyLike | CompactDecryptGetKey, options?: DecryptOptions): Promise<CompactDecryptResult>;
4
+ declare function compactDecrypt(jwe: string | Uint8Array, key: KeyLike, options?: DecryptOptions): Promise<CompactDecryptResult>;
5
+ declare function compactDecrypt(jwe: string | Uint8Array, getKey: CompactDecryptGetKey, options?: DecryptOptions): Promise<CompactDecryptResult & ResolvedKey>;
5
6
  export { compactDecrypt };
6
7
  export default compactDecrypt;
7
8
  export type { KeyLike, DecryptOptions, CompactDecryptResult };
@@ -1,7 +1,8 @@
1
- import type { FlattenedDecryptResult, KeyLike, FlattenedJWE, JWEHeaderParameters, DecryptOptions, GetKeyFunction } from '../../types';
1
+ import type { FlattenedDecryptResult, KeyLike, FlattenedJWE, JWEHeaderParameters, DecryptOptions, GetKeyFunction, ResolvedKey } from '../../types';
2
2
  export interface FlattenedDecryptGetKey extends GetKeyFunction<JWEHeaderParameters | undefined, FlattenedJWE> {
3
3
  }
4
- declare function flattenedDecrypt(jwe: FlattenedJWE, key: KeyLike | FlattenedDecryptGetKey, options?: DecryptOptions): Promise<FlattenedDecryptResult>;
4
+ declare function flattenedDecrypt(jwe: FlattenedJWE, key: KeyLike, options?: DecryptOptions): Promise<FlattenedDecryptResult>;
5
+ declare function flattenedDecrypt(jwe: FlattenedJWE, getKey: FlattenedDecryptGetKey, options?: DecryptOptions): Promise<FlattenedDecryptResult & ResolvedKey>;
5
6
  export { flattenedDecrypt };
6
7
  export default flattenedDecrypt;
7
8
  export type { KeyLike, FlattenedJWE, JWEHeaderParameters, DecryptOptions, FlattenedDecryptResult };
@@ -1,7 +1,8 @@
1
- import type { KeyLike, DecryptOptions, JWEHeaderParameters, GetKeyFunction, FlattenedJWE, GeneralJWE, GeneralDecryptResult } from '../../types';
1
+ import type { KeyLike, DecryptOptions, JWEHeaderParameters, GetKeyFunction, FlattenedJWE, GeneralJWE, GeneralDecryptResult, ResolvedKey } from '../../types';
2
2
  export interface GeneralDecryptGetKey extends GetKeyFunction<JWEHeaderParameters, FlattenedJWE> {
3
3
  }
4
- declare function generalDecrypt(jwe: GeneralJWE, key: KeyLike | GeneralDecryptGetKey, options?: DecryptOptions): Promise<GeneralDecryptResult>;
4
+ declare function generalDecrypt(jwe: GeneralJWE, key: KeyLike, options?: DecryptOptions): Promise<GeneralDecryptResult>;
5
+ declare function generalDecrypt(jwe: GeneralJWE, getKey: GeneralDecryptGetKey, options?: DecryptOptions): Promise<GeneralDecryptResult & ResolvedKey>;
5
6
  export { generalDecrypt };
6
7
  export default generalDecrypt;
7
8
  export type { KeyLike, GeneralJWE, DecryptOptions, GeneralDecryptResult };
@@ -1,7 +1,8 @@
1
- import type { CompactVerifyResult, FlattenedJWSInput, GetKeyFunction, JWSHeaderParameters, KeyLike, VerifyOptions } from '../../types';
1
+ import type { CompactVerifyResult, FlattenedJWSInput, GetKeyFunction, JWSHeaderParameters, KeyLike, VerifyOptions, ResolvedKey } from '../../types';
2
2
  export interface CompactVerifyGetKey extends GetKeyFunction<JWSHeaderParameters, FlattenedJWSInput> {
3
3
  }
4
- declare function compactVerify(jws: string | Uint8Array, key: KeyLike | CompactVerifyGetKey, options?: VerifyOptions): Promise<CompactVerifyResult>;
4
+ declare function compactVerify(jws: string | Uint8Array, key: KeyLike, options?: VerifyOptions): Promise<CompactVerifyResult>;
5
+ declare function compactVerify(jws: string | Uint8Array, getKey: CompactVerifyGetKey, options?: VerifyOptions): Promise<CompactVerifyResult & ResolvedKey>;
5
6
  export { compactVerify };
6
7
  export default compactVerify;
7
8
  export type { KeyLike, VerifyOptions, CompactVerifyResult };
@@ -1,7 +1,8 @@
1
- import type { FlattenedVerifyResult, KeyLike, FlattenedJWSInput, JWSHeaderParameters, VerifyOptions, GetKeyFunction } from '../../types';
1
+ import type { FlattenedVerifyResult, KeyLike, FlattenedJWSInput, JWSHeaderParameters, VerifyOptions, GetKeyFunction, ResolvedKey } from '../../types';
2
2
  export interface FlattenedVerifyGetKey extends GetKeyFunction<JWSHeaderParameters | undefined, FlattenedJWSInput> {
3
3
  }
4
- declare function flattenedVerify(jws: FlattenedJWSInput, key: KeyLike | FlattenedVerifyGetKey, options?: VerifyOptions): Promise<FlattenedVerifyResult>;
4
+ declare function flattenedVerify(jws: FlattenedJWSInput, key: KeyLike, options?: VerifyOptions): Promise<FlattenedVerifyResult>;
5
+ declare function flattenedVerify(jws: FlattenedJWSInput, getKey: FlattenedVerifyGetKey, options?: VerifyOptions): Promise<FlattenedVerifyResult & ResolvedKey>;
5
6
  export { flattenedVerify };
6
7
  export default flattenedVerify;
7
8
  export type { KeyLike, FlattenedJWSInput, GetKeyFunction, JWSHeaderParameters, VerifyOptions, FlattenedVerifyResult, };
@@ -1,7 +1,8 @@
1
- import type { GeneralJWSInput, GeneralVerifyResult, FlattenedJWSInput, GetKeyFunction, JWSHeaderParameters, KeyLike, VerifyOptions } from '../../types';
1
+ import type { GeneralJWSInput, GeneralVerifyResult, FlattenedJWSInput, GetKeyFunction, JWSHeaderParameters, KeyLike, VerifyOptions, ResolvedKey } from '../../types';
2
2
  export interface GeneralVerifyGetKey extends GetKeyFunction<JWSHeaderParameters, FlattenedJWSInput> {
3
3
  }
4
- declare function generalVerify(jws: GeneralJWSInput, key: KeyLike | GeneralVerifyGetKey, options?: VerifyOptions): Promise<GeneralVerifyResult>;
4
+ declare function generalVerify(jws: GeneralJWSInput, key: KeyLike, options?: VerifyOptions): Promise<GeneralVerifyResult>;
5
+ declare function generalVerify(jws: GeneralJWSInput, getKey: GeneralVerifyGetKey, options?: VerifyOptions): Promise<GeneralVerifyResult & ResolvedKey>;
5
6
  export { generalVerify };
6
7
  export default generalVerify;
7
8
  export type { KeyLike, GeneralJWSInput, VerifyOptions, GeneralVerifyResult };
@@ -1,9 +1,10 @@
1
- import type { KeyLike, DecryptOptions, JWTPayload, JWTClaimVerificationOptions, GetKeyFunction, JWEHeaderParameters, FlattenedJWE, JWTDecryptResult } from '../types';
1
+ import type { KeyLike, DecryptOptions, JWTPayload, JWTClaimVerificationOptions, GetKeyFunction, JWEHeaderParameters, FlattenedJWE, JWTDecryptResult, ResolvedKey } from '../types';
2
2
  interface JWTDecryptOptions extends DecryptOptions, JWTClaimVerificationOptions {
3
3
  }
4
4
  export interface JWTDecryptGetKey extends GetKeyFunction<JWEHeaderParameters, FlattenedJWE> {
5
5
  }
6
- declare function jwtDecrypt(jwt: string | Uint8Array, key: KeyLike | JWTDecryptGetKey, options?: JWTDecryptOptions): Promise<JWTDecryptResult>;
6
+ declare function jwtDecrypt(jwt: string | Uint8Array, key: KeyLike, options?: JWTDecryptOptions): Promise<JWTDecryptResult>;
7
+ declare function jwtDecrypt(jwt: string | Uint8Array, getKey: JWTDecryptGetKey, options?: JWTDecryptOptions): Promise<JWTDecryptResult & ResolvedKey>;
7
8
  export { jwtDecrypt };
8
9
  export default jwtDecrypt;
9
10
  export type { KeyLike, DecryptOptions, JWTPayload, JWTDecryptOptions, JWTDecryptResult };
@@ -1,9 +1,10 @@
1
- import type { KeyLike, VerifyOptions, JWTPayload, JWTClaimVerificationOptions, JWSHeaderParameters, GetKeyFunction, FlattenedJWSInput, JWTVerifyResult } from '../types';
1
+ import type { KeyLike, VerifyOptions, JWTPayload, JWTClaimVerificationOptions, JWSHeaderParameters, GetKeyFunction, FlattenedJWSInput, JWTVerifyResult, ResolvedKey } from '../types';
2
2
  interface JWTVerifyOptions extends VerifyOptions, JWTClaimVerificationOptions {
3
3
  }
4
4
  export interface JWTVerifyGetKey extends GetKeyFunction<JWSHeaderParameters, FlattenedJWSInput> {
5
5
  }
6
- declare function jwtVerify(jwt: string | Uint8Array, key: KeyLike | JWTVerifyGetKey, options?: JWTVerifyOptions): Promise<JWTVerifyResult>;
6
+ declare function jwtVerify(jwt: string | Uint8Array, key: KeyLike, options?: JWTVerifyOptions): Promise<JWTVerifyResult>;
7
+ declare function jwtVerify(jwt: string | Uint8Array, getKey: JWTVerifyGetKey, options?: JWTVerifyOptions): Promise<JWTVerifyResult & ResolvedKey>;
7
8
  export { jwtVerify };
8
9
  export default jwtVerify;
9
10
  export type { KeyLike, JWTPayload, JWTVerifyOptions, JWSHeaderParameters, GetKeyFunction, JWTVerifyResult, };
@@ -1,6 +1,5 @@
1
- import { fromKeyLike } from '../jwk/from_key_like';
2
- import type { KeyLike } from '../types';
1
+ import type { JWK, KeyLike } from '../types';
3
2
  export declare function exportSPKI(key: Exclude<KeyLike, Uint8Array>): Promise<string>;
4
3
  export declare function exportPKCS8(key: Exclude<KeyLike, Uint8Array>): Promise<string>;
5
- export declare const exportJWK: typeof fromKeyLike;
6
- export type { KeyLike };
4
+ export declare function exportJWK(key: KeyLike): Promise<JWK>;
5
+ export type { KeyLike, JWK };
@@ -1,10 +1,9 @@
1
- import { parseJwk as importJwk } from '../jwk/parse';
2
- import type { KeyLike } from '../types';
1
+ import type { JWK, KeyLike } from '../types';
3
2
  export interface PEMImportOptions {
4
3
  extractable?: boolean;
5
4
  }
6
5
  export declare function importSPKI(spki: string, alg: string, options?: PEMImportOptions): Promise<Exclude<KeyLike, Uint8Array>>;
7
6
  export declare function importX509(x509: string, alg: string, options?: PEMImportOptions): Promise<Exclude<KeyLike, Uint8Array>>;
8
7
  export declare function importPKCS8(pkcs8: string, alg: string, options?: PEMImportOptions): Promise<Exclude<KeyLike, Uint8Array>>;
9
- export declare const importJWK: typeof importJwk;
10
- export type { KeyLike };
8
+ export declare function importJWK(jwk: JWK, alg?: string, octAsKeyObject?: boolean): Promise<KeyLike>;
9
+ export type { KeyLike, JWK };
@@ -169,3 +169,6 @@ export interface JWTDecryptResult {
169
169
  payload: JWTPayload
170
170
  protectedHeader: JWEHeaderParameters
171
171
  }
172
+ export interface ResolvedKey {
173
+ key: KeyLike
174
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jose",
3
- "version": "3.18.0",
3
+ "version": "3.19.0",
4
4
  "description": "Universal 'JSON Web Almost Everything' - JWA, JWS, JWE, JWT, JWK with no dependencies",
5
5
  "keywords": [
6
6
  "browser",