jose 4.11.2 → 4.11.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/README.md +1 -1
- package/dist/browser/lib/crypto_key.js +5 -5
- package/dist/browser/runtime/asn1.js +13 -8
- package/dist/browser/runtime/generate.js +13 -13
- package/dist/browser/runtime/jwk_to_key.js +12 -14
- package/dist/browser/runtime/subtle_dsa.js +3 -3
- package/dist/deno/README.md +51 -0
- package/dist/node/cjs/lib/crypto_key.js +5 -5
- package/dist/node/esm/lib/crypto_key.js +5 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,13 +71,13 @@ export function checkSigCryptoKey(key, alg, ...usages) {
|
|
|
71
71
|
throw unusable(`SHA-${expected}`, 'algorithm.hash');
|
|
72
72
|
break;
|
|
73
73
|
}
|
|
74
|
-
case isCloudflareWorkers() && 'EdDSA': {
|
|
75
|
-
if (!isAlgorithm(key.algorithm, 'NODE-ED25519'))
|
|
76
|
-
throw unusable('NODE-ED25519');
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
74
|
case 'EdDSA': {
|
|
80
75
|
if (key.algorithm.name !== 'Ed25519' && key.algorithm.name !== 'Ed448') {
|
|
76
|
+
if (isCloudflareWorkers()) {
|
|
77
|
+
if (isAlgorithm(key.algorithm, 'NODE-ED25519'))
|
|
78
|
+
break;
|
|
79
|
+
throw unusable('Ed25519, Ed448, or NODE-ED25519');
|
|
80
|
+
}
|
|
81
81
|
throw unusable('Ed25519 or Ed448');
|
|
82
82
|
}
|
|
83
83
|
break;
|
|
@@ -57,7 +57,7 @@ const getNamedCurve = (keyData) => {
|
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
59
|
const genericImport = async (replace, keyFormat, pem, alg, options) => {
|
|
60
|
-
var _a;
|
|
60
|
+
var _a, _b;
|
|
61
61
|
let algorithm;
|
|
62
62
|
let keyUsages;
|
|
63
63
|
const keyData = new Uint8Array(atob(pem.replace(replace, ''))
|
|
@@ -108,12 +108,6 @@ const genericImport = async (replace, keyFormat, pem, alg, options) => {
|
|
|
108
108
|
keyUsages = isPublic ? [] : ['deriveBits'];
|
|
109
109
|
break;
|
|
110
110
|
}
|
|
111
|
-
case isCloudflareWorkers() && 'EdDSA': {
|
|
112
|
-
const namedCurve = getNamedCurve(keyData).toUpperCase();
|
|
113
|
-
algorithm = { name: `NODE-${namedCurve}`, namedCurve: `NODE-${namedCurve}` };
|
|
114
|
-
keyUsages = isPublic ? ['verify'] : ['sign'];
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
111
|
case 'EdDSA':
|
|
118
112
|
algorithm = { name: getNamedCurve(keyData) };
|
|
119
113
|
keyUsages = isPublic ? ['verify'] : ['sign'];
|
|
@@ -121,7 +115,18 @@ const genericImport = async (replace, keyFormat, pem, alg, options) => {
|
|
|
121
115
|
default:
|
|
122
116
|
throw new JOSENotSupported('Invalid or unsupported "alg" (Algorithm) value');
|
|
123
117
|
}
|
|
124
|
-
|
|
118
|
+
try {
|
|
119
|
+
return await crypto.subtle.importKey(keyFormat, keyData, algorithm, (_a = options === null || options === void 0 ? void 0 : options.extractable) !== null && _a !== void 0 ? _a : false, keyUsages);
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
if (algorithm.name === 'Ed25519' &&
|
|
123
|
+
(err === null || err === void 0 ? void 0 : err.name) === 'NotSupportedError' &&
|
|
124
|
+
isCloudflareWorkers()) {
|
|
125
|
+
algorithm = { name: 'NODE-ED25519', namedCurve: 'NODE-ED25519' };
|
|
126
|
+
return await crypto.subtle.importKey(keyFormat, keyData, algorithm, (_b = options === null || options === void 0 ? void 0 : options.extractable) !== null && _b !== void 0 ? _b : false, keyUsages);
|
|
127
|
+
}
|
|
128
|
+
throw err;
|
|
129
|
+
}
|
|
125
130
|
};
|
|
126
131
|
export const fromPKCS8 = (pem, alg, options) => {
|
|
127
132
|
return genericImport(/(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g, 'pkcs8', pem, alg, options);
|
|
@@ -51,7 +51,7 @@ function getModulusLengthOption(options) {
|
|
|
51
51
|
return modulusLength;
|
|
52
52
|
}
|
|
53
53
|
export async function generateKeyPair(alg, options) {
|
|
54
|
-
var _a, _b, _c;
|
|
54
|
+
var _a, _b, _c, _d;
|
|
55
55
|
let algorithm;
|
|
56
56
|
let keyUsages;
|
|
57
57
|
switch (alg) {
|
|
@@ -101,17 +101,6 @@ export async function generateKeyPair(alg, options) {
|
|
|
101
101
|
algorithm = { name: 'ECDSA', namedCurve: 'P-521' };
|
|
102
102
|
keyUsages = ['sign', 'verify'];
|
|
103
103
|
break;
|
|
104
|
-
case isCloudflareWorkers() && 'EdDSA':
|
|
105
|
-
switch (options === null || options === void 0 ? void 0 : options.crv) {
|
|
106
|
-
case undefined:
|
|
107
|
-
case 'Ed25519':
|
|
108
|
-
algorithm = { name: 'NODE-ED25519', namedCurve: 'NODE-ED25519' };
|
|
109
|
-
keyUsages = ['sign', 'verify'];
|
|
110
|
-
break;
|
|
111
|
-
default:
|
|
112
|
-
throw new JOSENotSupported('Invalid or unsupported crv option provided');
|
|
113
|
-
}
|
|
114
|
-
break;
|
|
115
104
|
case 'EdDSA':
|
|
116
105
|
keyUsages = ['sign', 'verify'];
|
|
117
106
|
const crv = (_a = options === null || options === void 0 ? void 0 : options.crv) !== null && _a !== void 0 ? _a : 'Ed25519';
|
|
@@ -149,5 +138,16 @@ export async function generateKeyPair(alg, options) {
|
|
|
149
138
|
default:
|
|
150
139
|
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
151
140
|
}
|
|
152
|
-
|
|
141
|
+
try {
|
|
142
|
+
return (await crypto.subtle.generateKey(algorithm, (_c = options === null || options === void 0 ? void 0 : options.extractable) !== null && _c !== void 0 ? _c : false, keyUsages));
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
if (algorithm.name === 'Ed25519' &&
|
|
146
|
+
(err === null || err === void 0 ? void 0 : err.name) === 'NotSupportedError' &&
|
|
147
|
+
isCloudflareWorkers()) {
|
|
148
|
+
algorithm = { name: 'NODE-ED25519', namedCurve: 'NODE-ED25519' };
|
|
149
|
+
return (await crypto.subtle.generateKey(algorithm, (_d = options === null || options === void 0 ? void 0 : options.extractable) !== null && _d !== void 0 ? _d : false, keyUsages));
|
|
150
|
+
}
|
|
151
|
+
throw err;
|
|
152
|
+
}
|
|
153
153
|
}
|
|
@@ -99,19 +99,6 @@ function subtleMapping(jwk) {
|
|
|
99
99
|
}
|
|
100
100
|
break;
|
|
101
101
|
}
|
|
102
|
-
case isCloudflareWorkers() && 'OKP':
|
|
103
|
-
if (jwk.alg !== 'EdDSA') {
|
|
104
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
105
|
-
}
|
|
106
|
-
switch (jwk.crv) {
|
|
107
|
-
case 'Ed25519':
|
|
108
|
-
algorithm = { name: 'NODE-ED25519', namedCurve: 'NODE-ED25519' };
|
|
109
|
-
keyUsages = jwk.d ? ['sign'] : ['verify'];
|
|
110
|
-
break;
|
|
111
|
-
default:
|
|
112
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
113
|
-
}
|
|
114
|
-
break;
|
|
115
102
|
case 'OKP': {
|
|
116
103
|
switch (jwk.alg) {
|
|
117
104
|
case 'EdDSA':
|
|
@@ -149,6 +136,17 @@ const parse = async (jwk) => {
|
|
|
149
136
|
const keyData = { ...jwk };
|
|
150
137
|
delete keyData.alg;
|
|
151
138
|
delete keyData.use;
|
|
152
|
-
|
|
139
|
+
try {
|
|
140
|
+
return await crypto.subtle.importKey('jwk', keyData, ...rest);
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
if (algorithm.name === 'Ed25519' &&
|
|
144
|
+
(err === null || err === void 0 ? void 0 : err.name) === 'NotSupportedError' &&
|
|
145
|
+
isCloudflareWorkers()) {
|
|
146
|
+
rest[0] = { name: 'NODE-ED25519', namedCurve: 'NODE-ED25519' };
|
|
147
|
+
return await crypto.subtle.importKey('jwk', keyData, ...rest);
|
|
148
|
+
}
|
|
149
|
+
throw err;
|
|
150
|
+
}
|
|
153
151
|
};
|
|
154
152
|
export default parse;
|
|
@@ -19,10 +19,10 @@ export default function subtleDsa(alg, algorithm) {
|
|
|
19
19
|
case 'ES384':
|
|
20
20
|
case 'ES512':
|
|
21
21
|
return { hash, name: 'ECDSA', namedCurve: algorithm.namedCurve };
|
|
22
|
-
case isCloudflareWorkers() && 'EdDSA':
|
|
23
|
-
const { namedCurve } = algorithm;
|
|
24
|
-
return { name: namedCurve, namedCurve };
|
|
25
22
|
case 'EdDSA':
|
|
23
|
+
if (isCloudflareWorkers() && algorithm.name === 'NODE-ED25519') {
|
|
24
|
+
return { name: 'NODE-ED25519', namedCurve: 'NODE-ED25519' };
|
|
25
|
+
}
|
|
26
26
|
return { name: algorithm.name };
|
|
27
27
|
default:
|
|
28
28
|
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# `jose` Modules API Documentation
|
|
2
|
+
|
|
3
|
+
> "JSON Web Almost Everything" - JWA, JWS, JWE, JWT, JWK, JWKS with no dependencies using runtime's native crypto.
|
|
4
|
+
|
|
5
|
+
## [💗 Help the project](https://github.com/panva/jose/blob/v4.11.3/docs/https://github.com/sponsors/panva)
|
|
6
|
+
|
|
7
|
+
## Available modules
|
|
8
|
+
|
|
9
|
+
**`example`** Deno import
|
|
10
|
+
```js
|
|
11
|
+
import * as jose from 'https://deno.land/x/jose@v4.11.3/index.ts'
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
- JSON Web Tokens (JWT)
|
|
15
|
+
- [Signing](https://github.com/panva/jose/blob/v4.11.3/docs/classes/jwt_sign.SignJWT.md#readme)
|
|
16
|
+
- [Verification & JWT Claims Set Validation](https://github.com/panva/jose/blob/v4.11.3/docs/functions/jwt_verify.jwtVerify.md#readme)
|
|
17
|
+
- Encrypted JSON Web Tokens
|
|
18
|
+
- [Encryption](https://github.com/panva/jose/blob/v4.11.3/docs/classes/jwt_encrypt.EncryptJWT.md#readme)
|
|
19
|
+
- [Decryption & JWT Claims Set Validation](https://github.com/panva/jose/blob/v4.11.3/docs/functions/jwt_decrypt.jwtDecrypt.md#readme)
|
|
20
|
+
- Key Import
|
|
21
|
+
- [JWK Import](https://github.com/panva/jose/blob/v4.11.3/docs/functions/key_import.importJWK.md#readme)
|
|
22
|
+
- [Public Key Import (SPKI)](https://github.com/panva/jose/blob/v4.11.3/docs/functions/key_import.importSPKI.md#readme)
|
|
23
|
+
- [Public Key Import (X.509 Certificate)](https://github.com/panva/jose/blob/v4.11.3/docs/functions/key_import.importX509.md#readme)
|
|
24
|
+
- [Private Key Import (PKCS #8)](https://github.com/panva/jose/blob/v4.11.3/docs/functions/key_import.importPKCS8.md#readme)
|
|
25
|
+
- JSON Web Encryption (JWE)
|
|
26
|
+
- Encryption - [Compact](https://github.com/panva/jose/blob/v4.11.3/docs/classes/jwe_compact_encrypt.CompactEncrypt.md#readme), [Flattened](https://github.com/panva/jose/blob/v4.11.3/docs/classes/jwe_flattened_encrypt.FlattenedEncrypt.md#readme), [General](https://github.com/panva/jose/blob/v4.11.3/docs/classes/jwe_general_encrypt.GeneralEncrypt.md#readme)
|
|
27
|
+
- Decryption - [Compact](https://github.com/panva/jose/blob/v4.11.3/docs/functions/jwe_compact_decrypt.compactDecrypt.md#readme), [Flattened](https://github.com/panva/jose/blob/v4.11.3/docs/functions/jwe_flattened_decrypt.flattenedDecrypt.md#readme), [General](https://github.com/panva/jose/blob/v4.11.3/docs/functions/jwe_general_decrypt.generalDecrypt.md#readme)
|
|
28
|
+
- JSON Web Signature (JWS)
|
|
29
|
+
- Signing - [Compact](https://github.com/panva/jose/blob/v4.11.3/docs/classes/jws_compact_sign.CompactSign.md#readme), [Flattened](https://github.com/panva/jose/blob/v4.11.3/docs/classes/jws_flattened_sign.FlattenedSign.md#readme), [General](https://github.com/panva/jose/blob/v4.11.3/docs/classes/jws_general_sign.GeneralSign.md#readme)
|
|
30
|
+
- Verification - [Compact](https://github.com/panva/jose/blob/v4.11.3/docs/functions/jws_compact_verify.compactVerify.md#readme), [Flattened](https://github.com/panva/jose/blob/v4.11.3/docs/functions/jws_flattened_verify.flattenedVerify.md#readme), [General](https://github.com/panva/jose/blob/v4.11.3/docs/functions/jws_general_verify.generalVerify.md#readme)
|
|
31
|
+
- JSON Web Key (JWK)
|
|
32
|
+
- [Calculating JWK Thumbprint](https://github.com/panva/jose/blob/v4.11.3/docs/functions/jwk_thumbprint.calculateJwkThumbprint.md#readme)
|
|
33
|
+
- [Calculating JWK Thumbprint URI](https://github.com/panva/jose/blob/v4.11.3/docs/functions/jwk_thumbprint.calculateJwkThumbprintUri.md#readme)
|
|
34
|
+
- [Verification using a JWK Embedded in a JWS Header](https://github.com/panva/jose/blob/v4.11.3/docs/functions/jwk_embedded.EmbeddedJWK.md#readme)
|
|
35
|
+
- JSON Web Key Set (JWKS)
|
|
36
|
+
- [Verify using a local JWKSet](https://github.com/panva/jose/blob/v4.11.3/docs/functions/jwks_local.createLocalJWKSet.md#readme)
|
|
37
|
+
- [Verify using a remote JWKSet](https://github.com/panva/jose/blob/v4.11.3/docs/functions/jwks_remote.createRemoteJWKSet.md#readme)
|
|
38
|
+
- Key Pair or Secret Generation
|
|
39
|
+
- [Asymmetric Key Pair Generation](https://github.com/panva/jose/blob/v4.11.3/docs/functions/key_generate_key_pair.generateKeyPair.md#readme)
|
|
40
|
+
- [Symmetric Secret Generation](https://github.com/panva/jose/blob/v4.11.3/docs/functions/key_generate_secret.generateSecret.md#readme)
|
|
41
|
+
- Key Export
|
|
42
|
+
- [JWK Export](https://github.com/panva/jose/blob/v4.11.3/docs/functions/key_export.exportJWK.md#readme)
|
|
43
|
+
- [Private Key Export](https://github.com/panva/jose/blob/v4.11.3/docs/functions/key_export.exportPKCS8.md#readme)
|
|
44
|
+
- [Public Key Export](https://github.com/panva/jose/blob/v4.11.3/docs/functions/key_export.exportSPKI.md#readme)
|
|
45
|
+
- Utilities
|
|
46
|
+
- [Decoding Token's Protected Header](https://github.com/panva/jose/blob/v4.11.3/docs/functions/util_decode_protected_header.decodeProtectedHeader.md#readme)
|
|
47
|
+
- [Decoding JWT Claims Set](https://github.com/panva/jose/blob/v4.11.3/docs/functions/util_decode_jwt.decodeJwt.md#readme)
|
|
48
|
+
- [Unsecured JWT](https://github.com/panva/jose/blob/v4.11.3/docs/classes/jwt_unsecured.UnsecuredJWT.md#readme)
|
|
49
|
+
- [JOSE Errors](https://github.com/panva/jose/blob/v4.11.3/docs/modules/util_errors.md#readme)
|
|
50
|
+
|
|
51
|
+
[support-sponsor]: https://github.com/sponsors/panva
|
|
@@ -74,13 +74,13 @@ function checkSigCryptoKey(key, alg, ...usages) {
|
|
|
74
74
|
throw unusable(`SHA-${expected}`, 'algorithm.hash');
|
|
75
75
|
break;
|
|
76
76
|
}
|
|
77
|
-
case (0, env_js_1.isCloudflareWorkers)() && 'EdDSA': {
|
|
78
|
-
if (!isAlgorithm(key.algorithm, 'NODE-ED25519'))
|
|
79
|
-
throw unusable('NODE-ED25519');
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
77
|
case 'EdDSA': {
|
|
83
78
|
if (key.algorithm.name !== 'Ed25519' && key.algorithm.name !== 'Ed448') {
|
|
79
|
+
if ((0, env_js_1.isCloudflareWorkers)()) {
|
|
80
|
+
if (isAlgorithm(key.algorithm, 'NODE-ED25519'))
|
|
81
|
+
break;
|
|
82
|
+
throw unusable('Ed25519, Ed448, or NODE-ED25519');
|
|
83
|
+
}
|
|
84
84
|
throw unusable('Ed25519 or Ed448');
|
|
85
85
|
}
|
|
86
86
|
break;
|
|
@@ -71,13 +71,13 @@ export function checkSigCryptoKey(key, alg, ...usages) {
|
|
|
71
71
|
throw unusable(`SHA-${expected}`, 'algorithm.hash');
|
|
72
72
|
break;
|
|
73
73
|
}
|
|
74
|
-
case isCloudflareWorkers() && 'EdDSA': {
|
|
75
|
-
if (!isAlgorithm(key.algorithm, 'NODE-ED25519'))
|
|
76
|
-
throw unusable('NODE-ED25519');
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
74
|
case 'EdDSA': {
|
|
80
75
|
if (key.algorithm.name !== 'Ed25519' && key.algorithm.name !== 'Ed448') {
|
|
76
|
+
if (isCloudflareWorkers()) {
|
|
77
|
+
if (isAlgorithm(key.algorithm, 'NODE-ED25519'))
|
|
78
|
+
break;
|
|
79
|
+
throw unusable('Ed25519, Ed448, or NODE-ED25519');
|
|
80
|
+
}
|
|
81
81
|
throw unusable('Ed25519 or Ed448');
|
|
82
82
|
}
|
|
83
83
|
break;
|
package/package.json
CHANGED