jose 5.6.1 → 5.6.2
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/dist/browser/jwks/remote.js +1 -1
- package/dist/browser/lib/decrypt_key_management.js +1 -1
- package/dist/browser/lib/encrypt_key_management.js +1 -1
- package/dist/browser/runtime/normalize_key.js +27 -6
- package/dist/node/cjs/jwks/remote.js +1 -1
- package/dist/node/cjs/lib/decrypt_key_management.js +1 -1
- package/dist/node/cjs/lib/encrypt_key_management.js +1 -1
- package/dist/node/esm/jwks/remote.js +1 -1
- package/dist/node/esm/lib/decrypt_key_management.js +1 -1
- package/dist/node/esm/lib/encrypt_key_management.js +1 -1
- package/package.json +1 -1
|
@@ -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.6.
|
|
13
|
+
const VERSION = 'v5.6.2';
|
|
14
14
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
15
15
|
}
|
|
16
16
|
export const experimental_jwksCache = Symbol();
|
|
@@ -11,8 +11,8 @@ import checkKeyType from './check_key_type.js';
|
|
|
11
11
|
import isObject from './is_object.js';
|
|
12
12
|
import { unwrap as aesGcmKw } from './aesgcmkw.js';
|
|
13
13
|
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options) {
|
|
14
|
-
key = (await normalize.normalizePrivateKey?.(key, alg)) || key;
|
|
15
14
|
checkKeyType(alg, key, 'decrypt');
|
|
15
|
+
key = (await normalize.normalizePrivateKey?.(key, alg)) || key;
|
|
16
16
|
switch (alg) {
|
|
17
17
|
case 'dir': {
|
|
18
18
|
if (encryptedKey !== undefined)
|
|
@@ -13,8 +13,8 @@ async function encryptKeyManagement(alg, enc, key, providedCek, providedParamete
|
|
|
13
13
|
let encryptedKey;
|
|
14
14
|
let parameters;
|
|
15
15
|
let cek;
|
|
16
|
-
key = (await normalize.normalizePublicKey?.(key, alg)) || key;
|
|
17
16
|
checkKeyType(alg, key, 'encrypt');
|
|
17
|
+
key = (await normalize.normalizePublicKey?.(key, alg)) || key;
|
|
18
18
|
switch (alg) {
|
|
19
19
|
case 'dir': {
|
|
20
20
|
cek = key;
|
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
import { decode } from './base64url.js';
|
|
2
2
|
import importJWK from './jwk_to_key.js';
|
|
3
3
|
const normalizeSecretKey = (k) => decode(k);
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
let privCache;
|
|
5
|
+
let pubCache;
|
|
6
|
+
const isKeyObject = (key) => {
|
|
7
|
+
return key?.[Symbol.toStringTag] === 'KeyObject';
|
|
8
|
+
};
|
|
9
|
+
const importAndCache = async (cache, key, jwk, alg) => {
|
|
10
|
+
let cached = cache.get(key);
|
|
11
|
+
if (cached?.[alg]) {
|
|
12
|
+
return cached[alg];
|
|
13
|
+
}
|
|
14
|
+
const cryptoKey = await importJWK({ ...jwk, alg });
|
|
15
|
+
if (!cached) {
|
|
16
|
+
cache.set(key, { [alg]: cryptoKey });
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
cached[alg] = cryptoKey;
|
|
20
|
+
}
|
|
21
|
+
return cryptoKey;
|
|
22
|
+
};
|
|
23
|
+
const normalizePublicKey = (key, alg) => {
|
|
24
|
+
if (isKeyObject(key)) {
|
|
6
25
|
let jwk = key.export({ format: 'jwk' });
|
|
7
26
|
delete jwk.d;
|
|
8
27
|
delete jwk.dp;
|
|
@@ -13,17 +32,19 @@ const normalizePublicKey = async (key, alg) => {
|
|
|
13
32
|
if (jwk.k) {
|
|
14
33
|
return normalizeSecretKey(jwk.k);
|
|
15
34
|
}
|
|
16
|
-
|
|
35
|
+
pubCache || (pubCache = new WeakMap());
|
|
36
|
+
return importAndCache(pubCache, key, jwk, alg);
|
|
17
37
|
}
|
|
18
38
|
return key;
|
|
19
39
|
};
|
|
20
|
-
const normalizePrivateKey =
|
|
21
|
-
if (key
|
|
40
|
+
const normalizePrivateKey = (key, alg) => {
|
|
41
|
+
if (isKeyObject(key)) {
|
|
22
42
|
let jwk = key.export({ format: 'jwk' });
|
|
23
43
|
if (jwk.k) {
|
|
24
44
|
return normalizeSecretKey(jwk.k);
|
|
25
45
|
}
|
|
26
|
-
|
|
46
|
+
privCache || (privCache = new WeakMap());
|
|
47
|
+
return importAndCache(privCache, key, jwk, alg);
|
|
27
48
|
}
|
|
28
49
|
return key;
|
|
29
50
|
};
|
|
@@ -13,7 +13,7 @@ function isCloudflareWorkers() {
|
|
|
13
13
|
let USER_AGENT;
|
|
14
14
|
if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
|
|
15
15
|
const NAME = 'jose';
|
|
16
|
-
const VERSION = 'v5.6.
|
|
16
|
+
const VERSION = 'v5.6.2';
|
|
17
17
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
18
18
|
}
|
|
19
19
|
exports.experimental_jwksCache = Symbol();
|
|
@@ -13,8 +13,8 @@ const check_key_type_js_1 = require("./check_key_type.js");
|
|
|
13
13
|
const is_object_js_1 = require("./is_object.js");
|
|
14
14
|
const aesgcmkw_js_1 = require("./aesgcmkw.js");
|
|
15
15
|
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options) {
|
|
16
|
-
key = (await normalize_key_js_1.default.normalizePrivateKey?.(key, alg)) || key;
|
|
17
16
|
(0, check_key_type_js_1.default)(alg, key, 'decrypt');
|
|
17
|
+
key = (await normalize_key_js_1.default.normalizePrivateKey?.(key, alg)) || key;
|
|
18
18
|
switch (alg) {
|
|
19
19
|
case 'dir': {
|
|
20
20
|
if (encryptedKey !== undefined)
|
|
@@ -15,8 +15,8 @@ async function encryptKeyManagement(alg, enc, key, providedCek, providedParamete
|
|
|
15
15
|
let encryptedKey;
|
|
16
16
|
let parameters;
|
|
17
17
|
let cek;
|
|
18
|
-
key = (await normalize_key_js_1.default.normalizePublicKey?.(key, alg)) || key;
|
|
19
18
|
(0, check_key_type_js_1.default)(alg, key, 'encrypt');
|
|
19
|
+
key = (await normalize_key_js_1.default.normalizePublicKey?.(key, alg)) || key;
|
|
20
20
|
switch (alg) {
|
|
21
21
|
case 'dir': {
|
|
22
22
|
cek = key;
|
|
@@ -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.6.
|
|
13
|
+
const VERSION = 'v5.6.2';
|
|
14
14
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
15
15
|
}
|
|
16
16
|
export const experimental_jwksCache = Symbol();
|
|
@@ -11,8 +11,8 @@ import checkKeyType from './check_key_type.js';
|
|
|
11
11
|
import isObject from './is_object.js';
|
|
12
12
|
import { unwrap as aesGcmKw } from './aesgcmkw.js';
|
|
13
13
|
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options) {
|
|
14
|
-
key = (await normalize.normalizePrivateKey?.(key, alg)) || key;
|
|
15
14
|
checkKeyType(alg, key, 'decrypt');
|
|
15
|
+
key = (await normalize.normalizePrivateKey?.(key, alg)) || key;
|
|
16
16
|
switch (alg) {
|
|
17
17
|
case 'dir': {
|
|
18
18
|
if (encryptedKey !== undefined)
|
|
@@ -13,8 +13,8 @@ async function encryptKeyManagement(alg, enc, key, providedCek, providedParamete
|
|
|
13
13
|
let encryptedKey;
|
|
14
14
|
let parameters;
|
|
15
15
|
let cek;
|
|
16
|
-
key = (await normalize.normalizePublicKey?.(key, alg)) || key;
|
|
17
16
|
checkKeyType(alg, key, 'encrypt');
|
|
17
|
+
key = (await normalize.normalizePublicKey?.(key, alg)) || key;
|
|
18
18
|
switch (alg) {
|
|
19
19
|
case 'dir': {
|
|
20
20
|
cek = key;
|