jose 4.12.1 → 4.13.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.
package/README.md CHANGED
@@ -38,7 +38,7 @@ const jose = require('jose')
38
38
 
39
39
  **`example`** Deno import
40
40
  ```js
41
- import * as jose from 'https://deno.land/x/jose@v4.12.1/index.ts'
41
+ import * as jose from 'https://deno.land/x/jose@v4.13.0/index.ts'
42
42
  ```
43
43
 
44
44
  - JSON Web Tokens (JWT)
@@ -4,7 +4,7 @@ import { JWSInvalid } from '../util/errors.js';
4
4
  export async function EmbeddedJWK(protectedHeader, token) {
5
5
  const joseHeader = {
6
6
  ...protectedHeader,
7
- ...token.header,
7
+ ...token === null || token === void 0 ? void 0 : token.header,
8
8
  };
9
9
  if (!isObject(joseHeader.jwk)) {
10
10
  throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a JSON object');
@@ -100,14 +100,17 @@ export class LocalJWKSet {
100
100
  async function importWithAlgCache(cache, jwk, alg) {
101
101
  const cached = cache.get(jwk) || cache.set(jwk, {}).get(jwk);
102
102
  if (cached[alg] === undefined) {
103
- const keyObject = await importJWK({ ...jwk, ext: true }, alg);
104
- if (keyObject.type !== 'public') {
103
+ const key = await importJWK({ ...jwk, ext: true }, alg);
104
+ if (key instanceof Uint8Array || key.type !== 'public') {
105
105
  throw new JWKSInvalid('JSON Web Key Set members must be public keys');
106
106
  }
107
- cached[alg] = keyObject;
107
+ cached[alg] = key;
108
108
  }
109
109
  return cached[alg];
110
110
  }
111
111
  export function createLocalJWKSet(jwks) {
112
- return LocalJWKSet.prototype.getKey.bind(new LocalJWKSet(jwks));
112
+ const set = new LocalJWKSet(jwks);
113
+ return async function (protectedHeader, token) {
114
+ return set.getKey(protectedHeader, token);
115
+ };
113
116
  }
@@ -77,5 +77,8 @@ class RemoteJWKSet extends LocalJWKSet {
77
77
  }
78
78
  }
79
79
  export function createRemoteJWKSet(url, options) {
80
- return RemoteJWKSet.prototype.getKey.bind(new RemoteJWKSet(url, options));
80
+ const set = new RemoteJWKSet(url, options);
81
+ return async function (protectedHeader, token) {
82
+ return set.getKey(protectedHeader, token);
83
+ };
81
84
  }
@@ -7,7 +7,7 @@ const errors_js_1 = require("../util/errors.js");
7
7
  async function EmbeddedJWK(protectedHeader, token) {
8
8
  const joseHeader = {
9
9
  ...protectedHeader,
10
- ...token.header,
10
+ ...token === null || token === void 0 ? void 0 : token.header,
11
11
  };
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');
@@ -105,15 +105,18 @@ exports.LocalJWKSet = LocalJWKSet;
105
105
  async function importWithAlgCache(cache, jwk, alg) {
106
106
  const cached = cache.get(jwk) || cache.set(jwk, {}).get(jwk);
107
107
  if (cached[alg] === undefined) {
108
- const keyObject = await (0, import_js_1.importJWK)({ ...jwk, ext: true }, alg);
109
- if (keyObject.type !== 'public') {
108
+ const key = await (0, import_js_1.importJWK)({ ...jwk, ext: true }, alg);
109
+ if (key instanceof Uint8Array || key.type !== 'public') {
110
110
  throw new errors_js_1.JWKSInvalid('JSON Web Key Set members must be public keys');
111
111
  }
112
- cached[alg] = keyObject;
112
+ cached[alg] = key;
113
113
  }
114
114
  return cached[alg];
115
115
  }
116
116
  function createLocalJWKSet(jwks) {
117
- return LocalJWKSet.prototype.getKey.bind(new LocalJWKSet(jwks));
117
+ const set = new LocalJWKSet(jwks);
118
+ return async function (protectedHeader, token) {
119
+ return set.getKey(protectedHeader, token);
120
+ };
118
121
  }
119
122
  exports.createLocalJWKSet = createLocalJWKSet;
@@ -80,6 +80,9 @@ class RemoteJWKSet extends local_js_1.LocalJWKSet {
80
80
  }
81
81
  }
82
82
  function createRemoteJWKSet(url, options) {
83
- return RemoteJWKSet.prototype.getKey.bind(new RemoteJWKSet(url, options));
83
+ const set = new RemoteJWKSet(url, options);
84
+ return async function (protectedHeader, token) {
85
+ return set.getKey(protectedHeader, token);
86
+ };
84
87
  }
85
88
  exports.createRemoteJWKSet = createRemoteJWKSet;
@@ -4,7 +4,7 @@ import { JWSInvalid } from '../util/errors.js';
4
4
  export async function EmbeddedJWK(protectedHeader, token) {
5
5
  const joseHeader = {
6
6
  ...protectedHeader,
7
- ...token.header,
7
+ ...token === null || token === void 0 ? void 0 : token.header,
8
8
  };
9
9
  if (!isObject(joseHeader.jwk)) {
10
10
  throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a JSON object');
@@ -100,14 +100,17 @@ export class LocalJWKSet {
100
100
  async function importWithAlgCache(cache, jwk, alg) {
101
101
  const cached = cache.get(jwk) || cache.set(jwk, {}).get(jwk);
102
102
  if (cached[alg] === undefined) {
103
- const keyObject = await importJWK({ ...jwk, ext: true }, alg);
104
- if (keyObject.type !== 'public') {
103
+ const key = await importJWK({ ...jwk, ext: true }, alg);
104
+ if (key instanceof Uint8Array || key.type !== 'public') {
105
105
  throw new JWKSInvalid('JSON Web Key Set members must be public keys');
106
106
  }
107
- cached[alg] = keyObject;
107
+ cached[alg] = key;
108
108
  }
109
109
  return cached[alg];
110
110
  }
111
111
  export function createLocalJWKSet(jwks) {
112
- return LocalJWKSet.prototype.getKey.bind(new LocalJWKSet(jwks));
112
+ const set = new LocalJWKSet(jwks);
113
+ return async function (protectedHeader, token) {
114
+ return set.getKey(protectedHeader, token);
115
+ };
113
116
  }
@@ -77,5 +77,8 @@ class RemoteJWKSet extends LocalJWKSet {
77
77
  }
78
78
  }
79
79
  export function createRemoteJWKSet(url, options) {
80
- return RemoteJWKSet.prototype.getKey.bind(new RemoteJWKSet(url, options));
80
+ const set = new RemoteJWKSet(url, options);
81
+ return async function (protectedHeader, token) {
82
+ return set.getKey(protectedHeader, token);
83
+ };
81
84
  }
@@ -30,4 +30,4 @@ export declare function compactDecrypt(jwe: string | Uint8Array, key: KeyLike |
30
30
  * @param getKey Function resolving Private Key or Secret to decrypt the JWE with.
31
31
  * @param options JWE Decryption options.
32
32
  */
33
- export declare function compactDecrypt(jwe: string | Uint8Array, getKey: CompactDecryptGetKey, options?: DecryptOptions): Promise<CompactDecryptResult & ResolvedKey>;
33
+ export declare function compactDecrypt<T extends KeyLike = KeyLike>(jwe: string | Uint8Array, getKey: CompactDecryptGetKey, options?: DecryptOptions): Promise<CompactDecryptResult & ResolvedKey<T>>;
@@ -40,4 +40,4 @@ export declare function flattenedDecrypt(jwe: FlattenedJWE, key: KeyLike | Uint8
40
40
  * @param getKey Function resolving Private Key or Secret to decrypt the JWE with.
41
41
  * @param options JWE Decryption options.
42
42
  */
43
- export declare function flattenedDecrypt(jwe: FlattenedJWE, getKey: FlattenedDecryptGetKey, options?: DecryptOptions): Promise<FlattenedDecryptResult & ResolvedKey>;
43
+ export declare function flattenedDecrypt<T extends KeyLike = KeyLike>(jwe: FlattenedJWE, getKey: FlattenedDecryptGetKey, options?: DecryptOptions): Promise<FlattenedDecryptResult & ResolvedKey<T>>;
@@ -44,4 +44,4 @@ export declare function generalDecrypt(jwe: GeneralJWE, key: KeyLike | Uint8Arra
44
44
  * @param getKey Function resolving Private Key or Secret to decrypt the JWE with.
45
45
  * @param options JWE Decryption options.
46
46
  */
47
- export declare function generalDecrypt(jwe: GeneralJWE, getKey: GeneralDecryptGetKey, options?: DecryptOptions): Promise<GeneralDecryptResult & ResolvedKey>;
47
+ export declare function generalDecrypt<T extends KeyLike = KeyLike>(jwe: GeneralJWE, getKey: GeneralDecryptGetKey, options?: DecryptOptions): Promise<GeneralDecryptResult & ResolvedKey<T>>;
@@ -1,4 +1,4 @@
1
- import type { FlattenedJWSInput, JWSHeaderParameters } from '../types';
1
+ import type { KeyLike, FlattenedJWSInput, JWSHeaderParameters } from '../types';
2
2
  /**
3
3
  * EmbeddedJWK is an implementation of a GetKeyFunction intended to be used with the JWS/JWT verify
4
4
  * operations whenever you need to opt-in to verify signatures with a public key embedded in the
@@ -20,4 +20,4 @@ import type { FlattenedJWSInput, JWSHeaderParameters } from '../types';
20
20
  * console.log(payload)
21
21
  * ```
22
22
  */
23
- export declare function EmbeddedJWK(protectedHeader: JWSHeaderParameters, token: FlattenedJWSInput): Promise<import("../types.d").KeyLike>;
23
+ export declare function EmbeddedJWK<T extends KeyLike = KeyLike>(protectedHeader?: JWSHeaderParameters, token?: FlattenedJWSInput): Promise<T>;
@@ -2,11 +2,11 @@ import type { KeyLike, JWSHeaderParameters, JSONWebKeySet, FlattenedJWSInput } f
2
2
  /** @private */
3
3
  export declare function isJWKSLike(jwks: unknown): jwks is JSONWebKeySet;
4
4
  /** @private */
5
- export declare class LocalJWKSet {
5
+ export declare class LocalJWKSet<T extends KeyLike = KeyLike> {
6
6
  protected _jwks?: JSONWebKeySet;
7
7
  private _cached;
8
8
  constructor(jwks: unknown);
9
- getKey(protectedHeader?: JWSHeaderParameters, token?: FlattenedJWSInput): Promise<KeyLike>;
9
+ getKey(protectedHeader?: JWSHeaderParameters, token?: FlattenedJWSInput): Promise<T>;
10
10
  }
11
11
  /**
12
12
  * Returns a function that resolves to a key object from a locally stored, or otherwise available,
@@ -82,4 +82,4 @@ export declare class LocalJWKSet {
82
82
  *
83
83
  * @param jwks JSON Web Key Set formatted object.
84
84
  */
85
- export declare function createLocalJWKSet(jwks: JSONWebKeySet): (protectedHeader?: JWSHeaderParameters | undefined, token?: FlattenedJWSInput | undefined) => Promise<KeyLike>;
85
+ export declare function createLocalJWKSet<T extends KeyLike = KeyLike>(jwks: JSONWebKeySet): (protectedHeader?: JWSHeaderParameters, token?: FlattenedJWSInput) => Promise<T>;
@@ -89,4 +89,4 @@ export interface RemoteJWKSetOptions {
89
89
  * @param url URL to fetch the JSON Web Key Set from.
90
90
  * @param options Options for the remote JSON Web Key Set.
91
91
  */
92
- export declare function createRemoteJWKSet(url: URL, options?: RemoteJWKSetOptions): (protectedHeader?: JWSHeaderParameters | undefined, token?: FlattenedJWSInput | undefined) => Promise<KeyLike>;
92
+ export declare function createRemoteJWKSet<T extends KeyLike = KeyLike>(url: URL, options?: RemoteJWKSetOptions): (protectedHeader?: JWSHeaderParameters, token?: FlattenedJWSInput) => Promise<T>;
@@ -34,4 +34,4 @@ export declare function compactVerify(jws: string | Uint8Array, key: KeyLike | U
34
34
  * @param getKey Function resolving a key to verify the JWS with.
35
35
  * @param options JWS Verify options.
36
36
  */
37
- export declare function compactVerify(jws: string | Uint8Array, getKey: CompactVerifyGetKey, options?: VerifyOptions): Promise<CompactVerifyResult & ResolvedKey>;
37
+ export declare function compactVerify<T extends KeyLike = KeyLike>(jws: string | Uint8Array, getKey: CompactVerifyGetKey, options?: VerifyOptions): Promise<CompactVerifyResult & ResolvedKey<T>>;
@@ -39,4 +39,4 @@ export declare function flattenedVerify(jws: FlattenedJWSInput, key: KeyLike | U
39
39
  * @param getKey Function resolving a key to verify the JWS with.
40
40
  * @param options JWS Verify options.
41
41
  */
42
- export declare function flattenedVerify(jws: FlattenedJWSInput, getKey: FlattenedVerifyGetKey, options?: VerifyOptions): Promise<FlattenedVerifyResult & ResolvedKey>;
42
+ export declare function flattenedVerify<T extends KeyLike = KeyLike>(jws: FlattenedJWSInput, getKey: FlattenedVerifyGetKey, options?: VerifyOptions): Promise<FlattenedVerifyResult & ResolvedKey<T>>;
@@ -42,4 +42,4 @@ export declare function generalVerify(jws: GeneralJWSInput, key: KeyLike | Uint8
42
42
  * @param getKey Function resolving a key to verify the JWS with.
43
43
  * @param options JWS Verify options.
44
44
  */
45
- export declare function generalVerify(jws: GeneralJWSInput, getKey: GeneralVerifyGetKey, options?: VerifyOptions): Promise<GeneralVerifyResult & ResolvedKey>;
45
+ export declare function generalVerify<T extends KeyLike = KeyLike>(jws: GeneralJWSInput, getKey: GeneralVerifyGetKey, options?: VerifyOptions): Promise<GeneralVerifyResult & ResolvedKey<T>>;
@@ -38,4 +38,4 @@ export declare function jwtDecrypt(jwt: string | Uint8Array, key: KeyLike | Uint
38
38
  * @param getKey Function resolving Private Key or Secret to decrypt and verify the JWT with.
39
39
  * @param options JWT Decryption and JWT Claims Set validation options.
40
40
  */
41
- export declare function jwtDecrypt(jwt: string | Uint8Array, getKey: JWTDecryptGetKey, options?: JWTDecryptOptions): Promise<JWTDecryptResult & ResolvedKey>;
41
+ export declare function jwtDecrypt<T extends KeyLike = KeyLike>(jwt: string | Uint8Array, getKey: JWTDecryptGetKey, options?: JWTDecryptOptions): Promise<JWTDecryptResult & ResolvedKey<T>>;
@@ -105,4 +105,4 @@ export declare function jwtVerify(jwt: string | Uint8Array, key: KeyLike | Uint8
105
105
  * @param getKey Function resolving a key to verify the JWT with.
106
106
  * @param options JWT Decryption and JWT Claims Set validation options.
107
107
  */
108
- export declare function jwtVerify(jwt: string | Uint8Array, getKey: JWTVerifyGetKey, options?: JWTVerifyOptions): Promise<JWTVerifyResult & ResolvedKey>;
108
+ export declare function jwtVerify<T extends KeyLike = KeyLike>(jwt: string | Uint8Array, getKey: JWTVerifyGetKey, options?: JWTVerifyOptions): Promise<JWTVerifyResult & ResolvedKey<T>>;
@@ -1,9 +1,9 @@
1
1
  import type { KeyLike } from '../types';
2
- export interface GenerateKeyPairResult {
2
+ export interface GenerateKeyPairResult<T extends KeyLike = KeyLike> {
3
3
  /** The generated Private Key. */
4
- privateKey: KeyLike;
4
+ privateKey: T;
5
5
  /** Public Key corresponding to the generated Private Key. */
6
- publicKey: KeyLike;
6
+ publicKey: T;
7
7
  }
8
8
  export interface GenerateKeyPairOptions {
9
9
  /**
@@ -41,4 +41,4 @@ export interface GenerateKeyPairOptions {
41
41
  * @param alg JWA Algorithm Identifier to be used with the generated key pair.
42
42
  * @param options Additional options passed down to the key pair generation.
43
43
  */
44
- export declare function generateKeyPair(alg: string, options?: GenerateKeyPairOptions): Promise<GenerateKeyPairResult>;
44
+ export declare function generateKeyPair<T extends KeyLike = KeyLike>(alg: string, options?: GenerateKeyPairOptions): Promise<GenerateKeyPairResult<T>>;
@@ -23,4 +23,4 @@ export interface GenerateSecretOptions {
23
23
  * @param alg JWA Algorithm Identifier to be used with the generated secret.
24
24
  * @param options Additional options passed down to the secret generation.
25
25
  */
26
- export declare function generateSecret(alg: string, options?: GenerateSecretOptions): Promise<KeyLike | Uint8Array>;
26
+ export declare function generateSecret<T extends KeyLike = KeyLike>(alg: string, options?: GenerateSecretOptions): Promise<T | Uint8Array>;
@@ -27,7 +27,7 @@ export interface PEMImportOptions {
27
27
  * @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
28
28
  * with the imported key, its presence is only enforced in Web Crypto API runtimes.
29
29
  */
30
- export declare function importSPKI(spki: string, alg: string, options?: PEMImportOptions): Promise<KeyLike>;
30
+ export declare function importSPKI<T extends KeyLike = KeyLike>(spki: string, alg: string, options?: PEMImportOptions): Promise<T>;
31
31
  /**
32
32
  * Imports the SPKI from an X.509 string certificate as a runtime-specific public key representation
33
33
  * (KeyObject or CryptoKey). See [Algorithm Key
@@ -55,7 +55,7 @@ export declare function importSPKI(spki: string, alg: string, options?: PEMImpor
55
55
  * @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
56
56
  * with the imported key, its presence is only enforced in Web Crypto API runtimes.
57
57
  */
58
- export declare function importX509(x509: string, alg: string, options?: PEMImportOptions): Promise<KeyLike>;
58
+ export declare function importX509<T extends KeyLike = KeyLike>(x509: string, alg: string, options?: PEMImportOptions): Promise<T>;
59
59
  /**
60
60
  * Imports a PEM-encoded PKCS#8 string as a runtime-specific private key representation (KeyObject
61
61
  * or CryptoKey). See [Algorithm Key Requirements](https://github.com/panva/jose/issues/210) to
@@ -77,7 +77,7 @@ export declare function importX509(x509: string, alg: string, options?: PEMImpor
77
77
  * @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
78
78
  * with the imported key, its presence is only enforced in Web Crypto API runtimes.
79
79
  */
80
- export declare function importPKCS8(pkcs8: string, alg: string, options?: PEMImportOptions): Promise<KeyLike>;
80
+ export declare function importPKCS8<T extends KeyLike = KeyLike>(pkcs8: string, alg: string, options?: PEMImportOptions): Promise<T>;
81
81
  /**
82
82
  * Imports a JWK to a runtime-specific key representation (KeyLike). Either JWK "alg" (Algorithm)
83
83
  * Parameter must be present or the optional "alg" argument. When running on a runtime using [Web
@@ -116,4 +116,4 @@ export declare function importPKCS8(pkcs8: string, alg: string, options?: PEMImp
116
116
  * @param octAsKeyObject Forces a symmetric key to be imported to a KeyObject or CryptoKey. Default
117
117
  * is true unless JWK "ext" (Extractable) is true.
118
118
  */
119
- export declare function importJWK(jwk: JWK, alg?: string, octAsKeyObject?: boolean): Promise<KeyLike | Uint8Array>;
119
+ export declare function importJWK<T extends KeyLike = KeyLike>(jwk: JWK, alg?: string, octAsKeyObject?: boolean): Promise<T | Uint8Array>;
@@ -601,9 +601,9 @@ export interface JWTDecryptResult {
601
601
  protectedHeader: CompactJWEHeaderParameters
602
602
  }
603
603
 
604
- export interface ResolvedKey {
604
+ export interface ResolvedKey<T extends KeyLike = KeyLike> {
605
605
  /** Key resolved from the key resolver function. */
606
- key: KeyLike | Uint8Array
606
+ key: T | Uint8Array
607
607
  }
608
608
 
609
609
  /** Recognized Compact JWS Header Parameters, any other Header Members may also be present. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jose",
3
- "version": "4.12.1",
3
+ "version": "4.13.0",
4
4
  "description": "'JSON Web Almost Everything' - JWA, JWS, JWE, JWT, JWK, JWKS for Node.js, Browser, Cloudflare Workers, Deno, Bun, and other Web-interoperable runtimes",
5
5
  "keywords": [
6
6
  "browser",