jose 6.2.10 → 6.2.12
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/types/index.d.ts +1 -2
- package/dist/types/jwe/compact/decrypt.d.ts +12 -25
- package/dist/types/jwe/compact/encrypt.d.ts +18 -32
- package/dist/types/jwe/flattened/decrypt.d.ts +12 -25
- package/dist/types/jwe/flattened/encrypt.d.ts +24 -50
- package/dist/types/jwe/general/decrypt.d.ts +15 -30
- package/dist/types/jwe/general/encrypt.d.ts +29 -52
- package/dist/types/jwk/embedded.d.ts +5 -8
- package/dist/types/jwk/thumbprint.d.ts +7 -9
- package/dist/types/jwks/local.d.ts +10 -13
- package/dist/types/jwks/remote.d.ts +29 -41
- package/dist/types/jws/compact/sign.d.ts +8 -13
- package/dist/types/jws/compact/verify.d.ts +14 -26
- package/dist/types/jws/flattened/sign.d.ts +10 -19
- package/dist/types/jws/flattened/verify.d.ts +14 -26
- package/dist/types/jws/general/sign.d.ts +19 -33
- package/dist/types/jws/general/verify.d.ts +17 -32
- package/dist/types/jwt/decrypt.d.ts +20 -27
- package/dist/types/jwt/encrypt.d.ts +30 -35
- package/dist/types/jwt/sign.d.ts +8 -13
- package/dist/types/jwt/unsecured.d.ts +10 -19
- package/dist/types/jwt/verify.d.ts +19 -22
- package/dist/types/key/export.d.ts +10 -10
- package/dist/types/key/generate_key_pair.d.ts +15 -22
- package/dist/types/key/generate_secret.d.ts +12 -19
- package/dist/types/key/import.d.ts +25 -31
- package/dist/types/types.d.ts +184 -319
- package/dist/types/util/base64url.d.ts +7 -7
- package/dist/types/util/decode_jwt.d.ts +5 -7
- package/dist/types/util/decode_protected_header.d.ts +6 -5
- package/dist/types/util/errors.d.ts +50 -88
- package/dist/webapi/index.js +70 -32
- package/dist/webapi/jwe/compact/decrypt.js +6 -8
- package/dist/webapi/jwe/compact/encrypt.js +25 -48
- package/dist/webapi/jwe/flattened/decrypt.js +14 -14
- package/dist/webapi/jwe/flattened/encrypt.js +34 -64
- package/dist/webapi/jwe/general/decrypt.js +38 -49
- package/dist/webapi/jwe/general/encrypt.js +100 -172
- package/dist/webapi/jwk/embedded.js +29 -32
- package/dist/webapi/jwk/thumbprint.js +51 -70
- package/dist/webapi/jwks/local.js +53 -64
- package/dist/webapi/jwks/remote.js +88 -136
- package/dist/webapi/jws/compact/sign.js +19 -21
- package/dist/webapi/jws/compact/verify.js +7 -8
- package/dist/webapi/jws/flattened/sign.js +22 -31
- package/dist/webapi/jws/flattened/verify.js +11 -24
- package/dist/webapi/jws/general/sign.js +55 -73
- package/dist/webapi/jws/general/verify.js +43 -69
- package/dist/webapi/jwt/decrypt.js +12 -20
- package/dist/webapi/jwt/encrypt.js +43 -70
- package/dist/webapi/jwt/sign.js +17 -16
- package/dist/webapi/jwt/unsecured.js +31 -40
- package/dist/webapi/jwt/verify.js +12 -14
- package/dist/webapi/key/export.js +32 -41
- package/dist/webapi/key/generate_key_pair.js +32 -49
- package/dist/webapi/key/generate_secret.js +35 -40
- package/dist/webapi/key/import.js +48 -56
- package/dist/webapi/lib/asn1.js +128 -169
- package/dist/webapi/lib/buffer_utils.js +72 -41
- package/dist/webapi/lib/content_encryption.js +75 -119
- package/dist/webapi/lib/deflate.js +35 -47
- package/dist/webapi/lib/jwe_algorithms.js +102 -93
- package/dist/webapi/lib/jwe_decrypt.js +178 -234
- package/dist/webapi/lib/jwe_encrypt.js +71 -138
- package/dist/webapi/lib/jws_algorithms.js +62 -61
- package/dist/webapi/lib/jws_sign.js +43 -82
- package/dist/webapi/lib/jws_verify.js +78 -131
- package/dist/webapi/lib/jwt_claims_set.js +123 -209
- package/dist/webapi/lib/key.js +147 -139
- package/dist/webapi/lib/key_algorithm.js +13 -8
- package/dist/webapi/lib/key_descriptor.js +8 -6
- package/dist/webapi/lib/key_management.js +169 -235
- package/dist/webapi/lib/validate.js +122 -0
- package/dist/webapi/util/base64url.js +14 -37
- package/dist/webapi/util/decode_jwt.js +32 -31
- package/dist/webapi/util/decode_protected_header.js +18 -23
- package/dist/webapi/util/errors.js +94 -84
- package/package.json +17 -81
- package/dist/webapi/lib/base64.js +0 -22
- package/dist/webapi/lib/crypto_key.js +0 -28
- package/dist/webapi/lib/helpers.js +0 -42
- package/dist/webapi/lib/invalid_key_input.js +0 -26
- package/dist/webapi/lib/is_key_like.js +0 -17
- package/dist/webapi/lib/jwk_metadata.js +0 -20
- package/dist/webapi/lib/jwk_to_key.js +0 -17
- package/dist/webapi/lib/key_options.js +0 -6
- package/dist/webapi/lib/options.js +0 -74
- package/dist/webapi/lib/signing.js +0 -26
- package/dist/webapi/lib/type_checks.js +0 -33
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { JOSENotSupported, JWEInvalid, JWSInvalid } from '../util/errors.js';
|
|
2
|
-
import { isObject } from './type_checks.js';
|
|
3
|
-
export const JWS_RECOGNIZED = { __proto__: null, b64: true };
|
|
4
|
-
export const JWE_RECOGNIZED = { __proto__: null };
|
|
5
|
-
export function validateAlgorithms(option, algorithms) {
|
|
6
|
-
if (algorithms !== undefined &&
|
|
7
|
-
(!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== 'string'))) {
|
|
8
|
-
throw new TypeError(`"${option}" option must be an array of strings`);
|
|
9
|
-
}
|
|
10
|
-
if (!algorithms) {
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
return new Set(algorithms);
|
|
14
|
-
}
|
|
15
|
-
export function validateCritDuplicates(Err, protectedHeader) {
|
|
16
|
-
const { crit } = protectedHeader ?? {};
|
|
17
|
-
if (Array.isArray(crit) && new Set(crit).size !== crit.length) {
|
|
18
|
-
throw new Err('"crit" (Critical) Header Parameter MUST NOT contain duplicate values');
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
export function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
22
|
-
if (joseHeader.crit !== undefined && protectedHeader?.crit === undefined) {
|
|
23
|
-
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
24
|
-
}
|
|
25
|
-
if (!protectedHeader || protectedHeader.crit === undefined) {
|
|
26
|
-
return [];
|
|
27
|
-
}
|
|
28
|
-
if (!Array.isArray(protectedHeader.crit) ||
|
|
29
|
-
protectedHeader.crit.length === 0 ||
|
|
30
|
-
protectedHeader.crit.some((input) => typeof input !== 'string' || input.length === 0)) {
|
|
31
|
-
throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
32
|
-
}
|
|
33
|
-
const recognized = recognizedOption === undefined
|
|
34
|
-
? recognizedDefault
|
|
35
|
-
: { __proto__: null, ...recognizedOption, ...recognizedDefault };
|
|
36
|
-
for (const parameter of protectedHeader.crit) {
|
|
37
|
-
if (!(parameter in recognized)) {
|
|
38
|
-
throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
|
|
39
|
-
}
|
|
40
|
-
if (!Object.hasOwn(joseHeader, parameter) || joseHeader[parameter] === undefined) {
|
|
41
|
-
throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
42
|
-
}
|
|
43
|
-
if (recognized[parameter] &&
|
|
44
|
-
(!Object.hasOwn(protectedHeader, parameter) || protectedHeader[parameter] === undefined)) {
|
|
45
|
-
throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return protectedHeader.crit;
|
|
49
|
-
}
|
|
50
|
-
export function validateB64(protectedHeader, extensions) {
|
|
51
|
-
if (extensions.includes('b64')) {
|
|
52
|
-
const b64 = protectedHeader.b64;
|
|
53
|
-
if (typeof b64 !== 'boolean') {
|
|
54
|
-
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
55
|
-
}
|
|
56
|
-
return b64;
|
|
57
|
-
}
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
export function serializeJoseHeader(Err, header) {
|
|
61
|
-
let serialized;
|
|
62
|
-
let parsed;
|
|
63
|
-
try {
|
|
64
|
-
serialized = JSON.stringify(header);
|
|
65
|
-
parsed = JSON.parse(serialized);
|
|
66
|
-
}
|
|
67
|
-
catch (cause) {
|
|
68
|
-
throw new Err('JOSE Header is not valid JSON', { cause });
|
|
69
|
-
}
|
|
70
|
-
if (!isObject(parsed)) {
|
|
71
|
-
throw new Err('JOSE Header is not a JSON object');
|
|
72
|
-
}
|
|
73
|
-
return [parsed, serialized];
|
|
74
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { checkCryptoKey, checkModulusLength } from './crypto_key.js';
|
|
2
|
-
async function getSigKey(entry, key, usage) {
|
|
3
|
-
if (key instanceof Uint8Array) {
|
|
4
|
-
return crypto.subtle.importKey('raw', key, entry.subtle, false, [
|
|
5
|
-
usage,
|
|
6
|
-
]);
|
|
7
|
-
}
|
|
8
|
-
checkCryptoKey(key, entry.subtle, usage);
|
|
9
|
-
if (entry.minRsaBits)
|
|
10
|
-
checkModulusLength(entry.alg, key);
|
|
11
|
-
return key;
|
|
12
|
-
}
|
|
13
|
-
export async function sign(entry, key, data) {
|
|
14
|
-
const cryptoKey = await getSigKey(entry, key, 'sign');
|
|
15
|
-
const signature = await crypto.subtle.sign(entry.signing, cryptoKey, data);
|
|
16
|
-
return new Uint8Array(signature);
|
|
17
|
-
}
|
|
18
|
-
export async function verify(entry, key, signature, data) {
|
|
19
|
-
const cryptoKey = await getSigKey(entry, key, 'verify');
|
|
20
|
-
try {
|
|
21
|
-
return await crypto.subtle.verify(entry.signing, cryptoKey, signature, data);
|
|
22
|
-
}
|
|
23
|
-
catch {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export function assertUint8Array(input, label) {
|
|
2
|
-
if (!(input instanceof Uint8Array)) {
|
|
3
|
-
throw new TypeError(`${label} must be an instance of Uint8Array`);
|
|
4
|
-
}
|
|
5
|
-
}
|
|
6
|
-
export function isObject(input) {
|
|
7
|
-
if (typeof input !== 'object' ||
|
|
8
|
-
input === null ||
|
|
9
|
-
Object.prototype.toString.call(input) !== '[object Object]') {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
const prototype = Object.getPrototypeOf(input);
|
|
13
|
-
return prototype === null || Object.getPrototypeOf(prototype) === null;
|
|
14
|
-
}
|
|
15
|
-
export function isJwkSet(input) {
|
|
16
|
-
return (isObject(input) &&
|
|
17
|
-
Array.isArray(input.keys) &&
|
|
18
|
-
Array.from(input.keys).every(isObject));
|
|
19
|
-
}
|
|
20
|
-
export function isDisjoint(...headers) {
|
|
21
|
-
const parameters = new Set();
|
|
22
|
-
for (const header of headers) {
|
|
23
|
-
if (!header)
|
|
24
|
-
continue;
|
|
25
|
-
for (const parameter of Object.keys(header)) {
|
|
26
|
-
if (parameters.has(parameter)) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
parameters.add(parameter);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return true;
|
|
33
|
-
}
|