jose 4.1.2 → 4.1.3
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/lib/crypto_key.js +1 -1
- package/dist/browser/runtime/asn1.js +2 -3
- package/dist/browser/runtime/base64url.js +2 -4
- package/dist/browser/runtime/env.js +11 -0
- package/dist/browser/runtime/fetch_jwks.js +3 -5
- package/dist/browser/runtime/generate.js +1 -1
- package/dist/browser/runtime/jwk_to_key.js +1 -1
- package/dist/browser/runtime/subtle_dsa.js +1 -1
- package/dist/browser/runtime/webcrypto.js +8 -4
- package/dist/node/cjs/lib/crypto_key.js +3 -3
- package/dist/node/cjs/runtime/{global.js → env.js} +0 -0
- package/dist/node/esm/lib/crypto_key.js +1 -1
- package/dist/node/esm/runtime/{global.js → env.js} +0 -0
- package/package.json +1 -1
- package/dist/browser/runtime/global.js +0 -27
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isCloudflareWorkers, isNodeJs } from '../runtime/
|
|
1
|
+
import { isCloudflareWorkers, isNodeJs } from '../runtime/env.js';
|
|
2
2
|
function unusable(name, prop = 'algorithm.name') {
|
|
3
3
|
return new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
4
4
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { isCloudflareWorkers, isNodeJs } from './env.js';
|
|
2
2
|
import crypto, { isCryptoKey } from './webcrypto.js';
|
|
3
3
|
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
4
4
|
import { encodeBase64 } from './base64url.js';
|
|
@@ -54,8 +54,7 @@ const genericImport = async (replace, keyFormat, pem, alg, options) => {
|
|
|
54
54
|
var _a;
|
|
55
55
|
let algorithm;
|
|
56
56
|
let keyUsages;
|
|
57
|
-
const keyData = new Uint8Array(
|
|
58
|
-
.atob(pem.replace(replace, ''))
|
|
57
|
+
const keyData = new Uint8Array(atob(pem.replace(replace, ''))
|
|
59
58
|
.split('')
|
|
60
59
|
.map((c) => c.charCodeAt(0)));
|
|
61
60
|
const isPublic = keyFormat === 'spki';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { encoder, decoder } from '../lib/buffer_utils.js';
|
|
2
|
-
import globalThis from './global.js';
|
|
3
2
|
export const encodeBase64 = (input) => {
|
|
4
3
|
let unencoded = input;
|
|
5
4
|
if (typeof unencoded === 'string') {
|
|
@@ -10,14 +9,13 @@ export const encodeBase64 = (input) => {
|
|
|
10
9
|
for (let i = 0; i < unencoded.length; i += CHUNK_SIZE) {
|
|
11
10
|
arr.push(String.fromCharCode.apply(null, unencoded.subarray(i, i + CHUNK_SIZE)));
|
|
12
11
|
}
|
|
13
|
-
return
|
|
12
|
+
return btoa(arr.join(''));
|
|
14
13
|
};
|
|
15
14
|
export const encode = (input) => {
|
|
16
15
|
return encodeBase64(input).replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
|
|
17
16
|
};
|
|
18
17
|
export const decodeBase64 = (encoded) => {
|
|
19
|
-
return new Uint8Array(
|
|
20
|
-
.atob(encoded)
|
|
18
|
+
return new Uint8Array(atob(encoded)
|
|
21
19
|
.split('')
|
|
22
20
|
.map((c) => c.charCodeAt(0)));
|
|
23
21
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JOSEError, JWKSTimeout } from '../util/errors.js';
|
|
2
|
-
import
|
|
2
|
+
import { isCloudflareWorkers } from './env.js';
|
|
3
3
|
const fetchJwks = async (url, timeout) => {
|
|
4
4
|
let controller;
|
|
5
5
|
let id;
|
|
@@ -11,8 +11,7 @@ const fetchJwks = async (url, timeout) => {
|
|
|
11
11
|
controller.abort();
|
|
12
12
|
}, timeout);
|
|
13
13
|
}
|
|
14
|
-
const response = await
|
|
15
|
-
.fetch(url.href, {
|
|
14
|
+
const response = await fetch(url.href, {
|
|
16
15
|
signal: controller ? controller.signal : undefined,
|
|
17
16
|
redirect: 'manual',
|
|
18
17
|
method: 'GET',
|
|
@@ -23,8 +22,7 @@ const fetchJwks = async (url, timeout) => {
|
|
|
23
22
|
mode: 'cors',
|
|
24
23
|
}
|
|
25
24
|
: undefined),
|
|
26
|
-
})
|
|
27
|
-
.catch((err) => {
|
|
25
|
+
}).catch((err) => {
|
|
28
26
|
if (timedOut)
|
|
29
27
|
throw new JWKSTimeout();
|
|
30
28
|
throw err;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isCloudflareWorkers, isNodeJs } from './
|
|
1
|
+
import { isCloudflareWorkers, isNodeJs } from './env.js';
|
|
2
2
|
import { JOSENotSupported } from '../util/errors.js';
|
|
3
3
|
export default function subtleDsa(alg, namedCurve) {
|
|
4
4
|
const length = parseInt(alg.substr(-3), 10);
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
export default globalThis.crypto;
|
|
1
|
+
export default crypto;
|
|
3
2
|
export function isCryptoKey(key) {
|
|
4
|
-
|
|
3
|
+
try {
|
|
4
|
+
return (key != null &&
|
|
5
|
+
typeof key.extractable === 'boolean' &&
|
|
6
|
+
typeof key.algorithm.name === 'string' &&
|
|
7
|
+
typeof key.type === 'string');
|
|
8
|
+
}
|
|
9
|
+
catch (_a) {
|
|
5
10
|
return false;
|
|
6
11
|
}
|
|
7
|
-
return key != null && key instanceof globalThis.CryptoKey;
|
|
8
12
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.checkEncCryptoKey = exports.checkSigCryptoKey = void 0;
|
|
4
|
-
const
|
|
4
|
+
const env_js_1 = require("../runtime/env.js");
|
|
5
5
|
function unusable(name, prop = 'algorithm.name') {
|
|
6
6
|
return new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
7
7
|
}
|
|
@@ -74,12 +74,12 @@ function checkSigCryptoKey(key, alg, ...usages) {
|
|
|
74
74
|
throw unusable(`SHA-${expected}`, 'algorithm.hash');
|
|
75
75
|
break;
|
|
76
76
|
}
|
|
77
|
-
case (0,
|
|
77
|
+
case (0, env_js_1.isNodeJs)() && 'EdDSA': {
|
|
78
78
|
if (key.algorithm.name !== 'NODE-ED25519' && key.algorithm.name !== 'NODE-ED448')
|
|
79
79
|
throw unusable('NODE-ED25519 or NODE-ED448');
|
|
80
80
|
break;
|
|
81
81
|
}
|
|
82
|
-
case (0,
|
|
82
|
+
case (0, env_js_1.isCloudflareWorkers)() && 'EdDSA': {
|
|
83
83
|
if (!isAlgorithm(key.algorithm, 'NODE-ED25519'))
|
|
84
84
|
throw unusable('NODE-ED25519');
|
|
85
85
|
break;
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isCloudflareWorkers, isNodeJs } from '../runtime/
|
|
1
|
+
import { isCloudflareWorkers, isNodeJs } from '../runtime/env.js';
|
|
2
2
|
function unusable(name, prop = 'algorithm.name') {
|
|
3
3
|
return new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
4
4
|
}
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
function getGlobal() {
|
|
2
|
-
if (typeof globalThis !== 'undefined')
|
|
3
|
-
return globalThis;
|
|
4
|
-
if (typeof self !== 'undefined')
|
|
5
|
-
return self;
|
|
6
|
-
if (typeof window !== 'undefined')
|
|
7
|
-
return window;
|
|
8
|
-
throw new Error('unable to locate global object');
|
|
9
|
-
}
|
|
10
|
-
export default getGlobal();
|
|
11
|
-
export function isCloudflareWorkers() {
|
|
12
|
-
try {
|
|
13
|
-
return getGlobal().WebSocketPair !== undefined;
|
|
14
|
-
}
|
|
15
|
-
catch (_a) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
export function isNodeJs() {
|
|
20
|
-
var _a, _b;
|
|
21
|
-
try {
|
|
22
|
-
return ((_b = (_a = getGlobal().process) === null || _a === void 0 ? void 0 : _a.versions) === null || _b === void 0 ? void 0 : _b.node) !== undefined;
|
|
23
|
-
}
|
|
24
|
-
catch (_c) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
}
|