jose 5.8.0 → 5.9.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 (45) hide show
  1. package/README.md +21 -17
  2. package/dist/browser/jwks/remote.js +1 -1
  3. package/dist/browser/jws/flattened/sign.js +2 -2
  4. package/dist/browser/jws/flattened/verify.js +10 -2
  5. package/dist/browser/lib/check_key_type.js +40 -9
  6. package/dist/browser/lib/invalid_key_input.js +1 -0
  7. package/dist/browser/lib/is_jwk.js +13 -0
  8. package/dist/browser/runtime/get_sign_verify_key.js +1 -1
  9. package/dist/browser/runtime/normalize_key.js +21 -4
  10. package/dist/node/cjs/jwks/remote.js +1 -1
  11. package/dist/node/cjs/jws/flattened/sign.js +1 -1
  12. package/dist/node/cjs/jws/flattened/verify.js +9 -1
  13. package/dist/node/cjs/lib/check_key_type.js +41 -9
  14. package/dist/node/cjs/lib/invalid_key_input.js +1 -0
  15. package/dist/node/cjs/lib/is_jwk.js +20 -0
  16. package/dist/node/cjs/runtime/base64url.js +1 -1
  17. package/dist/node/cjs/runtime/check_key_length.js +11 -1
  18. package/dist/node/cjs/runtime/get_named_curve.js +4 -0
  19. package/dist/node/cjs/runtime/get_sign_verify_key.js +8 -1
  20. package/dist/node/cjs/runtime/node_key.js +51 -14
  21. package/dist/node/cjs/runtime/sign.js +3 -3
  22. package/dist/node/cjs/runtime/verify.js +3 -3
  23. package/dist/node/esm/jwks/remote.js +1 -1
  24. package/dist/node/esm/jws/flattened/sign.js +2 -2
  25. package/dist/node/esm/jws/flattened/verify.js +10 -2
  26. package/dist/node/esm/lib/check_key_type.js +40 -9
  27. package/dist/node/esm/lib/invalid_key_input.js +1 -0
  28. package/dist/node/esm/lib/is_jwk.js +13 -0
  29. package/dist/node/esm/runtime/base64url.js +1 -1
  30. package/dist/node/esm/runtime/check_key_length.js +11 -1
  31. package/dist/node/esm/runtime/get_named_curve.js +4 -0
  32. package/dist/node/esm/runtime/get_sign_verify_key.js +8 -1
  33. package/dist/node/esm/runtime/node_key.js +52 -15
  34. package/dist/node/esm/runtime/sign.js +3 -3
  35. package/dist/node/esm/runtime/verify.js +3 -3
  36. package/dist/types/jws/compact/sign.d.ts +2 -2
  37. package/dist/types/jws/compact/verify.d.ts +3 -3
  38. package/dist/types/jws/flattened/sign.d.ts +2 -2
  39. package/dist/types/jws/flattened/verify.d.ts +3 -3
  40. package/dist/types/jws/general/sign.d.ts +2 -2
  41. package/dist/types/jws/general/verify.d.ts +3 -3
  42. package/dist/types/jwt/sign.d.ts +2 -2
  43. package/dist/types/jwt/verify.d.ts +3 -3
  44. package/dist/types/types.d.ts +129 -29
  45. package/package.json +1 -1
@@ -8,9 +8,9 @@ const sign_js_1 = require("./sign.js");
8
8
  const get_sign_verify_key_js_1 = require("./get_sign_verify_key.js");
9
9
  const oneShotVerify = (0, node_util_1.promisify)(crypto.verify);
10
10
  const verify = async (alg, key, signature, data) => {
11
- const keyObject = (0, get_sign_verify_key_js_1.default)(alg, key, 'verify');
11
+ const k = (0, get_sign_verify_key_js_1.default)(alg, key, 'verify');
12
12
  if (alg.startsWith('HS')) {
13
- const expected = await (0, sign_js_1.default)(alg, keyObject, data);
13
+ const expected = await (0, sign_js_1.default)(alg, k, data);
14
14
  const actual = signature;
15
15
  try {
16
16
  return crypto.timingSafeEqual(actual, expected);
@@ -20,7 +20,7 @@ const verify = async (alg, key, signature, data) => {
20
20
  }
21
21
  }
22
22
  const algorithm = (0, dsa_digest_js_1.default)(alg);
23
- const keyInput = (0, node_key_js_1.default)(alg, keyObject);
23
+ const keyInput = (0, node_key_js_1.default)(alg, k);
24
24
  try {
25
25
  return await oneShotVerify(algorithm, data, keyInput, signature);
26
26
  }
@@ -10,7 +10,7 @@ function isCloudflareWorkers() {
10
10
  let USER_AGENT;
11
11
  if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
12
12
  const NAME = 'jose';
13
- const VERSION = 'v5.8.0';
13
+ const VERSION = 'v5.9.0';
14
14
  USER_AGENT = `${NAME}/${VERSION}`;
15
15
  }
16
16
  export const jwksCache = Symbol();
@@ -3,7 +3,7 @@ import sign from '../../runtime/sign.js';
3
3
  import isDisjoint from '../../lib/is_disjoint.js';
4
4
  import { JWSInvalid } from '../../util/errors.js';
5
5
  import { encoder, decoder, concat } from '../../lib/buffer_utils.js';
6
- import checkKeyType from '../../lib/check_key_type.js';
6
+ import { checkKeyTypeWithJwk } from '../../lib/check_key_type.js';
7
7
  import validateCrit from '../../lib/validate_crit.js';
8
8
  export class FlattenedSign {
9
9
  _payload;
@@ -52,7 +52,7 @@ export class FlattenedSign {
52
52
  if (typeof alg !== 'string' || !alg) {
53
53
  throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
54
54
  }
55
- checkKeyType(alg, key, 'sign');
55
+ checkKeyTypeWithJwk(alg, key, 'sign');
56
56
  let payload = this._payload;
57
57
  if (b64) {
58
58
  payload = encoder.encode(base64url(payload));
@@ -4,9 +4,11 @@ import { JOSEAlgNotAllowed, JWSInvalid, JWSSignatureVerificationFailed } from '.
4
4
  import { concat, encoder, decoder } from '../../lib/buffer_utils.js';
5
5
  import isDisjoint from '../../lib/is_disjoint.js';
6
6
  import isObject from '../../lib/is_object.js';
7
- import checkKeyType from '../../lib/check_key_type.js';
7
+ import { checkKeyTypeWithJwk } from '../../lib/check_key_type.js';
8
8
  import validateCrit from '../../lib/validate_crit.js';
9
9
  import validateAlgorithms from '../../lib/validate_algorithms.js';
10
+ import { isJWK } from '../../lib/is_jwk.js';
11
+ import { importJWK } from '../../key/import.js';
10
12
  export async function flattenedVerify(jws, key, options) {
11
13
  if (!isObject(jws)) {
12
14
  throw new JWSInvalid('Flattened JWS must be an object');
@@ -71,8 +73,14 @@ export async function flattenedVerify(jws, key, options) {
71
73
  if (typeof key === 'function') {
72
74
  key = await key(parsedProt, jws);
73
75
  resolvedKey = true;
76
+ checkKeyTypeWithJwk(alg, key, 'verify');
77
+ if (isJWK(key)) {
78
+ key = await importJWK(key, alg);
79
+ }
80
+ }
81
+ else {
82
+ checkKeyTypeWithJwk(alg, key, 'verify');
74
83
  }
75
- checkKeyType(alg, key, 'verify');
76
84
  const data = concat(encoder.encode(jws.protected ?? ''), encoder.encode('.'), typeof jws.payload === 'string' ? encoder.encode(jws.payload) : jws.payload);
77
85
  let signature;
78
86
  try {
@@ -1,19 +1,49 @@
1
1
  import { withAlg as invalidKeyInput } from './invalid_key_input.js';
2
2
  import isKeyLike, { types } from '../runtime/is_key_like.js';
3
+ import * as jwk from './is_jwk.js';
3
4
  const tag = (key) => key?.[Symbol.toStringTag];
4
- const symmetricTypeCheck = (alg, key) => {
5
+ const jwkMatchesOp = (alg, key, usage) => {
6
+ if (key.use !== undefined && key.use !== 'sig') {
7
+ throw new TypeError('Invalid key for this operation, when present its use must be sig');
8
+ }
9
+ if (key.key_ops !== undefined && key.key_ops.includes?.(usage) !== true) {
10
+ throw new TypeError(`Invalid key for this operation, when present its key_ops must include ${usage}`);
11
+ }
12
+ if (key.alg !== undefined && key.alg !== alg) {
13
+ throw new TypeError(`Invalid key for this operation, when present its alg must be ${alg}`);
14
+ }
15
+ return true;
16
+ };
17
+ const symmetricTypeCheck = (alg, key, usage, allowJwk) => {
5
18
  if (key instanceof Uint8Array)
6
19
  return;
20
+ if (allowJwk && jwk.isJWK(key)) {
21
+ if (jwk.isSecretJWK(key) && jwkMatchesOp(alg, key, usage))
22
+ return;
23
+ throw new TypeError(`JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present`);
24
+ }
7
25
  if (!isKeyLike(key)) {
8
- throw new TypeError(invalidKeyInput(alg, key, ...types, 'Uint8Array'));
26
+ throw new TypeError(invalidKeyInput(alg, key, ...types, 'Uint8Array', allowJwk ? 'JSON Web Key' : null));
9
27
  }
10
28
  if (key.type !== 'secret') {
11
29
  throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
12
30
  }
13
31
  };
14
- const asymmetricTypeCheck = (alg, key, usage) => {
32
+ const asymmetricTypeCheck = (alg, key, usage, allowJwk) => {
33
+ if (allowJwk && jwk.isJWK(key)) {
34
+ switch (usage) {
35
+ case 'sign':
36
+ if (jwk.isPrivateJWK(key) && jwkMatchesOp(alg, key, usage))
37
+ return;
38
+ throw new TypeError(`JSON Web Key for this operation be a private JWK`);
39
+ case 'verify':
40
+ if (jwk.isPublicJWK(key) && jwkMatchesOp(alg, key, usage))
41
+ return;
42
+ throw new TypeError(`JSON Web Key for this operation be a public JWK`);
43
+ }
44
+ }
15
45
  if (!isKeyLike(key)) {
16
- throw new TypeError(invalidKeyInput(alg, key, ...types));
46
+ throw new TypeError(invalidKeyInput(alg, key, ...types, allowJwk ? 'JSON Web Key' : null));
17
47
  }
18
48
  if (key.type === 'secret') {
19
49
  throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
@@ -31,16 +61,17 @@ const asymmetricTypeCheck = (alg, key, usage) => {
31
61
  throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
32
62
  }
33
63
  };
34
- const checkKeyType = (alg, key, usage) => {
64
+ function checkKeyType(allowJwk, alg, key, usage) {
35
65
  const symmetric = alg.startsWith('HS') ||
36
66
  alg === 'dir' ||
37
67
  alg.startsWith('PBES2') ||
38
68
  /^A\d{3}(?:GCM)?KW$/.test(alg);
39
69
  if (symmetric) {
40
- symmetricTypeCheck(alg, key);
70
+ symmetricTypeCheck(alg, key, usage, allowJwk);
41
71
  }
42
72
  else {
43
- asymmetricTypeCheck(alg, key, usage);
73
+ asymmetricTypeCheck(alg, key, usage, allowJwk);
44
74
  }
45
- };
46
- export default checkKeyType;
75
+ }
76
+ export default checkKeyType.bind(undefined, false);
77
+ export const checkKeyTypeWithJwk = checkKeyType.bind(undefined, true);
@@ -1,4 +1,5 @@
1
1
  function message(msg, actual, ...types) {
2
+ types = types.filter(Boolean);
2
3
  if (types.length > 2) {
3
4
  const last = types.pop();
4
5
  msg += `one of type ${types.join(', ')}, or ${last}.`;
@@ -0,0 +1,13 @@
1
+ import isObject from './is_object.js';
2
+ export function isJWK(key) {
3
+ return isObject(key) && typeof key.kty === 'string';
4
+ }
5
+ export function isPrivateJWK(key) {
6
+ return key.kty !== 'oct' && typeof key.d === 'string';
7
+ }
8
+ export function isPublicJWK(key) {
9
+ return key.kty !== 'oct' && typeof key.d === 'undefined';
10
+ }
11
+ export function isSecretJWK(key) {
12
+ return isJWK(key) && key.kty === 'oct' && typeof key.k === 'string';
13
+ }
@@ -11,4 +11,4 @@ const encode = (input) => Buffer.from(input).toString('base64url');
11
11
  export const decodeBase64 = (input) => new Uint8Array(Buffer.from(input, 'base64'));
12
12
  export const encodeBase64 = (input) => Buffer.from(input).toString('base64');
13
13
  export { encode };
14
- export const decode = (input) => new Uint8Array(Buffer.from(normalize(input), 'base64'));
14
+ export const decode = (input) => new Uint8Array(Buffer.from(normalize(input), 'base64url'));
@@ -1,5 +1,15 @@
1
+ import { KeyObject } from 'node:crypto';
1
2
  export default (key, alg) => {
2
- const { modulusLength } = key.asymmetricKeyDetails;
3
+ let modulusLength;
4
+ try {
5
+ if (key instanceof KeyObject) {
6
+ modulusLength = key.asymmetricKeyDetails?.modulusLength;
7
+ }
8
+ else {
9
+ modulusLength = Buffer.from(key.n, 'base64url').byteLength << 3;
10
+ }
11
+ }
12
+ catch { }
3
13
  if (typeof modulusLength !== 'number' || modulusLength < 2048) {
4
14
  throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
5
15
  }
@@ -4,6 +4,7 @@ import { isCryptoKey } from './webcrypto.js';
4
4
  import isKeyObject from './is_key_object.js';
5
5
  import invalidKeyInput from '../lib/invalid_key_input.js';
6
6
  import { types } from './is_key_like.js';
7
+ import { isJWK } from '../lib/is_jwk.js';
7
8
  export const weakMap = new WeakMap();
8
9
  const namedCurveToJOSE = (namedCurve) => {
9
10
  switch (namedCurve) {
@@ -27,6 +28,9 @@ const getNamedCurve = (kee, raw) => {
27
28
  else if (isKeyObject(kee)) {
28
29
  key = kee;
29
30
  }
31
+ else if (isJWK(kee)) {
32
+ return kee.crv;
33
+ }
30
34
  else {
31
35
  throw new TypeError(invalidKeyInput(kee, ...types));
32
36
  }
@@ -3,6 +3,7 @@ import { isCryptoKey } from './webcrypto.js';
3
3
  import { checkSigCryptoKey } from '../lib/crypto_key.js';
4
4
  import invalidKeyInput from '../lib/invalid_key_input.js';
5
5
  import { types } from './is_key_like.js';
6
+ import * as jwk from '../lib/is_jwk.js';
6
7
  export default function getSignVerifyKey(alg, key, usage) {
7
8
  if (key instanceof Uint8Array) {
8
9
  if (!alg.startsWith('HS')) {
@@ -17,5 +18,11 @@ export default function getSignVerifyKey(alg, key, usage) {
17
18
  checkSigCryptoKey(key, alg, usage);
18
19
  return KeyObject.from(key);
19
20
  }
20
- throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array'));
21
+ if (jwk.isJWK(key)) {
22
+ if (alg.startsWith('HS')) {
23
+ return createSecretKey(Buffer.from(key.k, 'base64url'));
24
+ }
25
+ return key;
26
+ }
27
+ throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array', 'JSON Web Key'));
21
28
  }
@@ -1,11 +1,7 @@
1
- import { constants } from 'node:crypto';
1
+ import { constants, KeyObject } from 'node:crypto';
2
2
  import getNamedCurve from './get_named_curve.js';
3
3
  import { JOSENotSupported } from '../util/errors.js';
4
4
  import checkKeyLength from './check_key_length.js';
5
- const PSS = {
6
- padding: constants.RSA_PKCS1_PSS_PADDING,
7
- saltLength: constants.RSA_PSS_SALTLEN_DIGEST,
8
- };
9
5
  const ecCurveAlgMap = new Map([
10
6
  ['ES256', 'P-256'],
11
7
  ['ES256K', 'secp256k1'],
@@ -13,25 +9,57 @@ const ecCurveAlgMap = new Map([
13
9
  ['ES512', 'P-521'],
14
10
  ]);
15
11
  export default function keyForCrypto(alg, key) {
12
+ let asymmetricKeyType;
13
+ let asymmetricKeyDetails;
14
+ let isJWK;
15
+ if (key instanceof KeyObject) {
16
+ asymmetricKeyType = key.asymmetricKeyType;
17
+ asymmetricKeyDetails = key.asymmetricKeyDetails;
18
+ }
19
+ else {
20
+ isJWK = true;
21
+ switch (key.kty) {
22
+ case 'RSA':
23
+ asymmetricKeyType = 'rsa';
24
+ break;
25
+ case 'EC':
26
+ asymmetricKeyType = 'ec';
27
+ break;
28
+ case 'OKP': {
29
+ if (key.crv === 'Ed25519') {
30
+ asymmetricKeyType = 'ed25519';
31
+ break;
32
+ }
33
+ if (key.crv === 'Ed448') {
34
+ asymmetricKeyType = 'ed448';
35
+ break;
36
+ }
37
+ throw new TypeError('Invalid key for this operation, its crv must be Ed25519 or Ed448');
38
+ }
39
+ default:
40
+ throw new TypeError('Invalid key for this operation, its kty must be RSA, OKP, or EC');
41
+ }
42
+ }
43
+ let options;
16
44
  switch (alg) {
17
45
  case 'EdDSA':
18
- if (!['ed25519', 'ed448'].includes(key.asymmetricKeyType)) {
46
+ if (!['ed25519', 'ed448'].includes(asymmetricKeyType)) {
19
47
  throw new TypeError('Invalid key for this operation, its asymmetricKeyType must be ed25519 or ed448');
20
48
  }
21
- return key;
49
+ break;
22
50
  case 'RS256':
23
51
  case 'RS384':
24
52
  case 'RS512':
25
- if (key.asymmetricKeyType !== 'rsa') {
53
+ if (asymmetricKeyType !== 'rsa') {
26
54
  throw new TypeError('Invalid key for this operation, its asymmetricKeyType must be rsa');
27
55
  }
28
56
  checkKeyLength(key, alg);
29
- return key;
57
+ break;
30
58
  case 'PS256':
31
59
  case 'PS384':
32
60
  case 'PS512':
33
- if (key.asymmetricKeyType === 'rsa-pss') {
34
- const { hashAlgorithm, mgf1HashAlgorithm, saltLength } = key.asymmetricKeyDetails;
61
+ if (asymmetricKeyType === 'rsa-pss') {
62
+ const { hashAlgorithm, mgf1HashAlgorithm, saltLength } = asymmetricKeyDetails;
35
63
  const length = parseInt(alg.slice(-3), 10);
36
64
  if (hashAlgorithm !== undefined &&
37
65
  (hashAlgorithm !== `sha${length}` || mgf1HashAlgorithm !== hashAlgorithm)) {
@@ -41,16 +69,20 @@ export default function keyForCrypto(alg, key) {
41
69
  throw new TypeError(`Invalid key for this operation, its RSA-PSS parameter saltLength does not meet the requirements of "alg" ${alg}`);
42
70
  }
43
71
  }
44
- else if (key.asymmetricKeyType !== 'rsa') {
72
+ else if (asymmetricKeyType !== 'rsa') {
45
73
  throw new TypeError('Invalid key for this operation, its asymmetricKeyType must be rsa or rsa-pss');
46
74
  }
47
75
  checkKeyLength(key, alg);
48
- return { key, ...PSS };
76
+ options = {
77
+ padding: constants.RSA_PKCS1_PSS_PADDING,
78
+ saltLength: constants.RSA_PSS_SALTLEN_DIGEST,
79
+ };
80
+ break;
49
81
  case 'ES256':
50
82
  case 'ES256K':
51
83
  case 'ES384':
52
84
  case 'ES512': {
53
- if (key.asymmetricKeyType !== 'ec') {
85
+ if (asymmetricKeyType !== 'ec') {
54
86
  throw new TypeError('Invalid key for this operation, its asymmetricKeyType must be ec');
55
87
  }
56
88
  const actual = getNamedCurve(key);
@@ -58,9 +90,14 @@ export default function keyForCrypto(alg, key) {
58
90
  if (actual !== expected) {
59
91
  throw new TypeError(`Invalid key curve for the algorithm, its curve must be ${expected}, got ${actual}`);
60
92
  }
61
- return { dsaEncoding: 'ieee-p1363', key };
93
+ options = { dsaEncoding: 'ieee-p1363' };
94
+ break;
62
95
  }
63
96
  default:
64
97
  throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
65
98
  }
99
+ if (isJWK) {
100
+ return { format: 'jwk', key, ...options };
101
+ }
102
+ return options ? { ...options, key } : key;
66
103
  }
@@ -6,12 +6,12 @@ import nodeKey from './node_key.js';
6
6
  import getSignKey from './get_sign_verify_key.js';
7
7
  const oneShotSign = promisify(crypto.sign);
8
8
  const sign = async (alg, key, data) => {
9
- const keyObject = getSignKey(alg, key, 'sign');
9
+ const k = getSignKey(alg, key, 'sign');
10
10
  if (alg.startsWith('HS')) {
11
- const hmac = crypto.createHmac(hmacDigest(alg), keyObject);
11
+ const hmac = crypto.createHmac(hmacDigest(alg), k);
12
12
  hmac.update(data);
13
13
  return hmac.digest();
14
14
  }
15
- return oneShotSign(nodeDigest(alg), data, nodeKey(alg, keyObject));
15
+ return oneShotSign(nodeDigest(alg), data, nodeKey(alg, k));
16
16
  };
17
17
  export default sign;
@@ -6,9 +6,9 @@ import sign from './sign.js';
6
6
  import getVerifyKey from './get_sign_verify_key.js';
7
7
  const oneShotVerify = promisify(crypto.verify);
8
8
  const verify = async (alg, key, signature, data) => {
9
- const keyObject = getVerifyKey(alg, key, 'verify');
9
+ const k = getVerifyKey(alg, key, 'verify');
10
10
  if (alg.startsWith('HS')) {
11
- const expected = await sign(alg, keyObject, data);
11
+ const expected = await sign(alg, k, data);
12
12
  const actual = signature;
13
13
  try {
14
14
  return crypto.timingSafeEqual(actual, expected);
@@ -18,7 +18,7 @@ const verify = async (alg, key, signature, data) => {
18
18
  }
19
19
  }
20
20
  const algorithm = nodeDigest(alg);
21
- const keyInput = nodeKey(alg, keyObject);
21
+ const keyInput = nodeKey(alg, k);
22
22
  try {
23
23
  return await oneShotVerify(algorithm, data, keyInput, signature);
24
24
  }
@@ -1,4 +1,4 @@
1
- import type { CompactJWSHeaderParameters, KeyLike, SignOptions } from '../../types';
1
+ import type { JWK, CompactJWSHeaderParameters, KeyLike, SignOptions } from '../../types';
2
2
  /**
3
3
  * The CompactSign class is used to build and sign Compact JWS strings.
4
4
  *
@@ -23,5 +23,5 @@ export declare class CompactSign {
23
23
  * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
24
24
  * @param options JWS Sign options.
25
25
  */
26
- sign(key: KeyLike | Uint8Array, options?: SignOptions): Promise<string>;
26
+ sign(key: KeyLike | Uint8Array | JWK, options?: SignOptions): Promise<string>;
27
27
  }
@@ -1,11 +1,11 @@
1
- import type { CompactVerifyResult, FlattenedJWSInput, GetKeyFunction, CompactJWSHeaderParameters, KeyLike, VerifyOptions, ResolvedKey } from '../../types';
1
+ import type { JWK, CompactVerifyResult, FlattenedJWSInput, GenericGetKeyFunction, CompactJWSHeaderParameters, KeyLike, VerifyOptions, ResolvedKey } from '../../types';
2
2
  /**
3
3
  * Interface for Compact JWS Verification dynamic key resolution. No token components have been
4
4
  * verified at the time of this function call.
5
5
  *
6
6
  * @see [createRemoteJWKSet](../functions/jwks_remote.createRemoteJWKSet.md#function-createremotejwkset) to verify using a remote JSON Web Key Set.
7
7
  */
8
- export interface CompactVerifyGetKey extends GetKeyFunction<CompactJWSHeaderParameters, FlattenedJWSInput> {
8
+ export interface CompactVerifyGetKey extends GenericGetKeyFunction<CompactJWSHeaderParameters, FlattenedJWSInput, KeyLike | JWK | Uint8Array> {
9
9
  }
10
10
  /**
11
11
  * Verifies the signature and format of and afterwards decodes the Compact JWS.
@@ -18,7 +18,7 @@ export interface CompactVerifyGetKey extends GetKeyFunction<CompactJWSHeaderPara
18
18
  * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
19
19
  * @param options JWS Verify options.
20
20
  */
21
- export declare function compactVerify(jws: string | Uint8Array, key: KeyLike | Uint8Array, options?: VerifyOptions): Promise<CompactVerifyResult>;
21
+ export declare function compactVerify(jws: string | Uint8Array, key: KeyLike | Uint8Array | JWK, options?: VerifyOptions): Promise<CompactVerifyResult>;
22
22
  /**
23
23
  * @param jws Compact JWS.
24
24
  * @param getKey Function resolving a key to verify the JWS with. See
@@ -1,4 +1,4 @@
1
- import type { KeyLike, FlattenedJWS, JWSHeaderParameters, SignOptions } from '../../types';
1
+ import type { JWK, KeyLike, FlattenedJWS, JWSHeaderParameters, SignOptions } from '../../types';
2
2
  /**
3
3
  * The FlattenedSign class is used to build and sign Flattened JWS objects.
4
4
  *
@@ -31,5 +31,5 @@ export declare class FlattenedSign {
31
31
  * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
32
32
  * @param options JWS Sign options.
33
33
  */
34
- sign(key: KeyLike | Uint8Array, options?: SignOptions): Promise<FlattenedJWS>;
34
+ sign(key: KeyLike | Uint8Array | JWK, options?: SignOptions): Promise<FlattenedJWS>;
35
35
  }
@@ -1,11 +1,11 @@
1
- import type { FlattenedVerifyResult, KeyLike, FlattenedJWSInput, JWSHeaderParameters, VerifyOptions, GetKeyFunction, ResolvedKey } from '../../types';
1
+ import type { JWK, FlattenedVerifyResult, KeyLike, FlattenedJWSInput, JWSHeaderParameters, VerifyOptions, GenericGetKeyFunction, ResolvedKey } from '../../types';
2
2
  /**
3
3
  * Interface for Flattened JWS Verification dynamic key resolution. No token components have been
4
4
  * verified at the time of this function call.
5
5
  *
6
6
  * @see [createRemoteJWKSet](../functions/jwks_remote.createRemoteJWKSet.md#function-createremotejwkset) to verify using a remote JSON Web Key Set.
7
7
  */
8
- export interface FlattenedVerifyGetKey extends GetKeyFunction<JWSHeaderParameters | undefined, FlattenedJWSInput> {
8
+ export interface FlattenedVerifyGetKey extends GenericGetKeyFunction<JWSHeaderParameters | undefined, FlattenedJWSInput, KeyLike | JWK | Uint8Array> {
9
9
  }
10
10
  /**
11
11
  * Verifies the signature and format of and afterwards decodes the Flattened JWS.
@@ -18,7 +18,7 @@ export interface FlattenedVerifyGetKey extends GetKeyFunction<JWSHeaderParameter
18
18
  * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
19
19
  * @param options JWS Verify options.
20
20
  */
21
- export declare function flattenedVerify(jws: FlattenedJWSInput, key: KeyLike | Uint8Array, options?: VerifyOptions): Promise<FlattenedVerifyResult>;
21
+ export declare function flattenedVerify(jws: FlattenedJWSInput, key: KeyLike | Uint8Array | JWK, options?: VerifyOptions): Promise<FlattenedVerifyResult>;
22
22
  /**
23
23
  * @param jws Flattened JWS.
24
24
  * @param getKey Function resolving a key to verify the JWS with. See
@@ -1,4 +1,4 @@
1
- import type { KeyLike, GeneralJWS, JWSHeaderParameters, SignOptions } from '../../types';
1
+ import type { JWK, KeyLike, GeneralJWS, JWSHeaderParameters, SignOptions } from '../../types';
2
2
  export interface Signature {
3
3
  /**
4
4
  * Sets the JWS Protected Header on the Signature object.
@@ -38,7 +38,7 @@ export declare class GeneralSign {
38
38
  * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
39
39
  * @param options JWS Sign options.
40
40
  */
41
- addSignature(key: KeyLike | Uint8Array, options?: SignOptions): Signature;
41
+ addSignature(key: KeyLike | Uint8Array | JWK, options?: SignOptions): Signature;
42
42
  /** Signs and resolves the value of the General JWS object. */
43
43
  sign(): Promise<GeneralJWS>;
44
44
  }
@@ -1,11 +1,11 @@
1
- import type { GeneralJWSInput, GeneralVerifyResult, FlattenedJWSInput, GetKeyFunction, JWSHeaderParameters, KeyLike, VerifyOptions, ResolvedKey } from '../../types';
1
+ import type { JWK, GeneralJWSInput, GeneralVerifyResult, FlattenedJWSInput, GenericGetKeyFunction, JWSHeaderParameters, KeyLike, VerifyOptions, ResolvedKey } from '../../types';
2
2
  /**
3
3
  * Interface for General JWS Verification dynamic key resolution. No token components have been
4
4
  * verified at the time of this function call.
5
5
  *
6
6
  * @see [createRemoteJWKSet](../functions/jwks_remote.createRemoteJWKSet.md#function-createremotejwkset) to verify using a remote JSON Web Key Set.
7
7
  */
8
- export interface GeneralVerifyGetKey extends GetKeyFunction<JWSHeaderParameters, FlattenedJWSInput> {
8
+ export interface GeneralVerifyGetKey extends GenericGetKeyFunction<JWSHeaderParameters, FlattenedJWSInput, KeyLike | JWK | Uint8Array> {
9
9
  }
10
10
  /**
11
11
  * Verifies the signature and format of and afterwards decodes the General JWS.
@@ -18,7 +18,7 @@ export interface GeneralVerifyGetKey extends GetKeyFunction<JWSHeaderParameters,
18
18
  * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
19
19
  * @param options JWS Verify options.
20
20
  */
21
- export declare function generalVerify(jws: GeneralJWSInput, key: KeyLike | Uint8Array, options?: VerifyOptions): Promise<GeneralVerifyResult>;
21
+ export declare function generalVerify(jws: GeneralJWSInput, key: KeyLike | Uint8Array | JWK, options?: VerifyOptions): Promise<GeneralVerifyResult>;
22
22
  /**
23
23
  * @param jws General JWS.
24
24
  * @param getKey Function resolving a key to verify the JWS with. See
@@ -1,4 +1,4 @@
1
- import type { JWTHeaderParameters, KeyLike, SignOptions } from '../types';
1
+ import type { JWK, JWTHeaderParameters, KeyLike, SignOptions } from '../types';
2
2
  import { ProduceJWT } from './produce';
3
3
  /**
4
4
  * The SignJWT class is used to build and sign Compact JWS formatted JSON Web Tokens.
@@ -22,5 +22,5 @@ export declare class SignJWT extends ProduceJWT {
22
22
  * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
23
23
  * @param options JWT Sign options.
24
24
  */
25
- sign(key: KeyLike | Uint8Array, options?: SignOptions): Promise<string>;
25
+ sign(key: KeyLike | Uint8Array | JWK, options?: SignOptions): Promise<string>;
26
26
  }
@@ -1,4 +1,4 @@
1
- import type { JWTPayload, KeyLike, VerifyOptions, JWTClaimVerificationOptions, JWTHeaderParameters, GetKeyFunction, FlattenedJWSInput, JWTVerifyResult, ResolvedKey } from '../types';
1
+ import type { JWK, JWTPayload, KeyLike, VerifyOptions, JWTClaimVerificationOptions, JWTHeaderParameters, GenericGetKeyFunction, FlattenedJWSInput, JWTVerifyResult, ResolvedKey } from '../types';
2
2
  /** Combination of JWS Verification options and JWT Claims Set verification options. */
3
3
  export interface JWTVerifyOptions extends VerifyOptions, JWTClaimVerificationOptions {
4
4
  }
@@ -8,7 +8,7 @@ export interface JWTVerifyOptions extends VerifyOptions, JWTClaimVerificationOpt
8
8
  *
9
9
  * @see [createRemoteJWKSet](../functions/jwks_remote.createRemoteJWKSet.md#function-createremotejwkset) to verify using a remote JSON Web Key Set.
10
10
  */
11
- export interface JWTVerifyGetKey extends GetKeyFunction<JWTHeaderParameters, FlattenedJWSInput> {
11
+ export interface JWTVerifyGetKey extends GenericGetKeyFunction<JWTHeaderParameters, FlattenedJWSInput, KeyLike | JWK | Uint8Array> {
12
12
  }
13
13
  /**
14
14
  * Verifies the JWT format (to be a JWS Compact format), verifies the JWS signature, validates the
@@ -22,7 +22,7 @@ export interface JWTVerifyGetKey extends GetKeyFunction<JWTHeaderParameters, Fla
22
22
  * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
23
23
  * @param options JWT Decryption and JWT Claims Set validation options.
24
24
  */
25
- export declare function jwtVerify<PayloadType = JWTPayload>(jwt: string | Uint8Array, key: KeyLike | Uint8Array, options?: JWTVerifyOptions): Promise<JWTVerifyResult<PayloadType>>;
25
+ export declare function jwtVerify<PayloadType = JWTPayload>(jwt: string | Uint8Array, key: KeyLike | Uint8Array | JWK, options?: JWTVerifyOptions): Promise<JWTVerifyResult<PayloadType>>;
26
26
  /**
27
27
  * @param jwt JSON Web Token value (encoded as JWS).
28
28
  * @param getKey Function resolving a key to verify the JWT with. See