jose 4.1.5 → 4.3.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/README.md +16 -1
- package/dist/browser/index.js +1 -0
- package/dist/browser/jwe/flattened/encrypt.js +15 -4
- package/dist/browser/jwe/general/decrypt.js +3 -0
- package/dist/browser/jwe/general/encrypt.js +171 -0
- package/dist/browser/jwks/remote.js +16 -12
- package/dist/browser/jws/general/sign.js +25 -29
- package/dist/browser/lib/cek.js +5 -6
- package/dist/browser/lib/decrypt_key_management.js +1 -1
- package/dist/browser/lib/encrypt_key_management.js +1 -1
- package/dist/browser/lib/iv.js +4 -11
- package/dist/browser/runtime/aeskw.js +2 -1
- package/dist/browser/runtime/asn1.js +2 -1
- package/dist/browser/runtime/decrypt.js +2 -1
- package/dist/browser/runtime/ecdhes.js +5 -4
- package/dist/browser/runtime/encrypt.js +2 -1
- package/dist/browser/runtime/get_sign_verify_key.js +3 -2
- package/dist/browser/runtime/key_to_jwk.js +2 -1
- package/dist/browser/runtime/pbes2kw.js +2 -1
- package/dist/browser/runtime/rsaes.js +3 -2
- package/dist/node/cjs/index.js +9 -7
- package/dist/node/cjs/jwe/flattened/encrypt.js +16 -5
- package/dist/node/cjs/jwe/general/decrypt.js +3 -0
- package/dist/node/cjs/jwe/general/encrypt.js +175 -0
- package/dist/node/cjs/jwks/remote.js +16 -12
- package/dist/node/cjs/jws/general/sign.js +25 -29
- package/dist/node/cjs/lib/cek.js +5 -6
- 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/cjs/lib/iv.js +4 -11
- package/dist/node/cjs/runtime/aeskw.js +4 -3
- package/dist/node/cjs/runtime/asn1.js +2 -1
- package/dist/node/cjs/runtime/decrypt.js +5 -4
- package/dist/node/cjs/runtime/ecdhes.js +5 -4
- package/dist/node/cjs/runtime/encrypt.js +5 -4
- package/dist/node/cjs/runtime/get_named_curve.js +2 -1
- package/dist/node/cjs/runtime/get_sign_verify_key.js +3 -2
- package/dist/node/cjs/runtime/key_to_jwk.js +2 -1
- package/dist/node/cjs/runtime/pbes2kw.js +2 -1
- package/dist/node/cjs/runtime/rsaes.js +4 -3
- package/dist/node/esm/index.js +1 -0
- package/dist/node/esm/jwe/flattened/encrypt.js +15 -4
- package/dist/node/esm/jwe/general/decrypt.js +3 -0
- package/dist/node/esm/jwe/general/encrypt.js +171 -0
- package/dist/node/esm/jwks/remote.js +16 -12
- package/dist/node/esm/jws/general/sign.js +25 -29
- package/dist/node/esm/lib/cek.js +5 -6
- package/dist/node/esm/lib/decrypt_key_management.js +1 -1
- package/dist/node/esm/lib/encrypt_key_management.js +1 -1
- package/dist/node/esm/lib/iv.js +4 -11
- package/dist/node/esm/runtime/aeskw.js +4 -3
- package/dist/node/esm/runtime/asn1.js +2 -1
- package/dist/node/esm/runtime/decrypt.js +5 -4
- package/dist/node/esm/runtime/ecdhes.js +5 -4
- package/dist/node/esm/runtime/encrypt.js +5 -4
- package/dist/node/esm/runtime/get_named_curve.js +2 -1
- package/dist/node/esm/runtime/get_sign_verify_key.js +3 -2
- package/dist/node/esm/runtime/key_to_jwk.js +2 -1
- package/dist/node/esm/runtime/pbes2kw.js +2 -1
- package/dist/node/esm/runtime/rsaes.js +4 -3
- package/dist/types/index.d.ts +3 -1
- package/dist/types/jwe/compact/decrypt.d.ts +2 -2
- package/dist/types/jwe/compact/encrypt.d.ts +2 -2
- package/dist/types/jwe/flattened/encrypt.d.ts +1 -0
- package/dist/types/jwe/general/encrypt.d.ts +20 -0
- package/dist/types/jws/compact/sign.d.ts +2 -2
- package/dist/types/jws/compact/verify.d.ts +2 -2
- package/dist/types/jws/general/sign.d.ts +3 -0
- package/dist/types/jwt/decrypt.d.ts +2 -2
- package/dist/types/jwt/encrypt.d.ts +2 -2
- package/dist/types/jwt/sign.d.ts +2 -2
- package/dist/types/jwt/verify.d.ts +2 -2
- package/dist/types/types.d.ts +17 -14
- package/package.json +1 -1
|
@@ -8,6 +8,7 @@ import { checkEncCryptoKey } from '../lib/crypto_key.js';
|
|
|
8
8
|
import isKeyObject from './is_key_object.js';
|
|
9
9
|
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
10
10
|
import supported from './ciphers.js';
|
|
11
|
+
import { types } from './is_key_like.js';
|
|
11
12
|
function checkKeySize(key, alg) {
|
|
12
13
|
if (key.symmetricKeySize << 3 !== parseInt(alg.substr(1, 3), 10)) {
|
|
13
14
|
throw new TypeError(`Invalid key size for alg: ${alg}`);
|
|
@@ -24,9 +25,9 @@ function ensureKeyObject(key, alg, usage) {
|
|
|
24
25
|
checkEncCryptoKey(key, alg, usage);
|
|
25
26
|
return KeyObject.from(key);
|
|
26
27
|
}
|
|
27
|
-
throw new TypeError(invalidKeyInput(key,
|
|
28
|
+
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array'));
|
|
28
29
|
}
|
|
29
|
-
export const wrap =
|
|
30
|
+
export const wrap = (alg, key, cek) => {
|
|
30
31
|
const size = parseInt(alg.substr(1, 3), 10);
|
|
31
32
|
const algorithm = `aes${size}-wrap`;
|
|
32
33
|
if (!supported(algorithm)) {
|
|
@@ -37,7 +38,7 @@ export const wrap = async (alg, key, cek) => {
|
|
|
37
38
|
const cipher = createCipheriv(algorithm, keyObject, Buffer.alloc(8, 0xa6));
|
|
38
39
|
return concat(cipher.update(cek), cipher.final());
|
|
39
40
|
};
|
|
40
|
-
export const unwrap =
|
|
41
|
+
export const unwrap = (alg, key, encryptedKey) => {
|
|
41
42
|
const size = parseInt(alg.substr(1, 3), 10);
|
|
42
43
|
const algorithm = `aes${size}-wrap`;
|
|
43
44
|
if (!supported(algorithm)) {
|
|
@@ -3,6 +3,7 @@ import { Buffer } from 'buffer';
|
|
|
3
3
|
import { isCryptoKey } from './webcrypto.js';
|
|
4
4
|
import isKeyObject from './is_key_object.js';
|
|
5
5
|
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
6
|
+
import { types } from './is_key_like.js';
|
|
6
7
|
const genericExport = (keyType, keyFormat, key) => {
|
|
7
8
|
let keyObject;
|
|
8
9
|
if (isCryptoKey(key)) {
|
|
@@ -15,7 +16,7 @@ const genericExport = (keyType, keyFormat, key) => {
|
|
|
15
16
|
keyObject = key;
|
|
16
17
|
}
|
|
17
18
|
else {
|
|
18
|
-
throw new TypeError(invalidKeyInput(key,
|
|
19
|
+
throw new TypeError(invalidKeyInput(key, ...types));
|
|
19
20
|
}
|
|
20
21
|
if (keyObject.type !== keyType) {
|
|
21
22
|
throw new TypeError(`key is not a ${keyType} key`);
|
|
@@ -10,7 +10,8 @@ import { checkEncCryptoKey } from '../lib/crypto_key.js';
|
|
|
10
10
|
import isKeyObject from './is_key_object.js';
|
|
11
11
|
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
12
12
|
import supported from './ciphers.js';
|
|
13
|
-
|
|
13
|
+
import { types } from './is_key_like.js';
|
|
14
|
+
function cbcDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
14
15
|
const keySize = parseInt(enc.substr(1, 3), 10);
|
|
15
16
|
if (isKeyObject(cek)) {
|
|
16
17
|
cek = cek.export();
|
|
@@ -44,7 +45,7 @@ async function cbcDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
|
44
45
|
}
|
|
45
46
|
return plaintext;
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
+
function gcmDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
48
49
|
const keySize = parseInt(enc.substr(1, 3), 10);
|
|
49
50
|
const algorithm = `aes-${keySize}-gcm`;
|
|
50
51
|
if (!supported(algorithm)) {
|
|
@@ -64,7 +65,7 @@ async function gcmDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
|
64
65
|
throw new JWEDecryptionFailed();
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
|
-
const decrypt =
|
|
68
|
+
const decrypt = (enc, cek, ciphertext, iv, tag, aad) => {
|
|
68
69
|
let key;
|
|
69
70
|
if (isCryptoKey(cek)) {
|
|
70
71
|
checkEncCryptoKey(cek, enc, 'decrypt');
|
|
@@ -74,7 +75,7 @@ const decrypt = async (enc, cek, ciphertext, iv, tag, aad) => {
|
|
|
74
75
|
key = cek;
|
|
75
76
|
}
|
|
76
77
|
else {
|
|
77
|
-
throw new TypeError(invalidKeyInput(cek,
|
|
78
|
+
throw new TypeError(invalidKeyInput(cek, ...types, 'Uint8Array'));
|
|
78
79
|
}
|
|
79
80
|
checkCekLength(enc, key);
|
|
80
81
|
checkIvLength(enc, iv);
|
|
@@ -8,8 +8,9 @@ import { isCryptoKey } from './webcrypto.js';
|
|
|
8
8
|
import { checkEncCryptoKey } from '../lib/crypto_key.js';
|
|
9
9
|
import isKeyObject from './is_key_object.js';
|
|
10
10
|
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
11
|
+
import { types } from './is_key_like.js';
|
|
11
12
|
const generateKeyPair = promisify(generateKeyPairCb);
|
|
12
|
-
export const deriveKey =
|
|
13
|
+
export const deriveKey = (publicKee, privateKee, algorithm, keyLength, apu = new Uint8Array(0), apv = new Uint8Array(0)) => {
|
|
13
14
|
let publicKey;
|
|
14
15
|
if (isCryptoKey(publicKee)) {
|
|
15
16
|
checkEncCryptoKey(publicKee, 'ECDH-ES');
|
|
@@ -19,7 +20,7 @@ export const deriveKey = async (publicKee, privateKee, algorithm, keyLength, apu
|
|
|
19
20
|
publicKey = publicKee;
|
|
20
21
|
}
|
|
21
22
|
else {
|
|
22
|
-
throw new TypeError(invalidKeyInput(publicKee,
|
|
23
|
+
throw new TypeError(invalidKeyInput(publicKee, ...types));
|
|
23
24
|
}
|
|
24
25
|
let privateKey;
|
|
25
26
|
if (isCryptoKey(privateKee)) {
|
|
@@ -30,7 +31,7 @@ export const deriveKey = async (publicKee, privateKee, algorithm, keyLength, apu
|
|
|
30
31
|
privateKey = privateKee;
|
|
31
32
|
}
|
|
32
33
|
else {
|
|
33
|
-
throw new TypeError(invalidKeyInput(privateKee,
|
|
34
|
+
throw new TypeError(invalidKeyInput(privateKee, ...types));
|
|
34
35
|
}
|
|
35
36
|
const value = concat(lengthAndInput(encoder.encode(algorithm)), lengthAndInput(apu), lengthAndInput(apv), uint32be(keyLength));
|
|
36
37
|
const sharedSecret = diffieHellman({ privateKey, publicKey });
|
|
@@ -45,7 +46,7 @@ export const generateEpk = async (kee) => {
|
|
|
45
46
|
key = kee;
|
|
46
47
|
}
|
|
47
48
|
else {
|
|
48
|
-
throw new TypeError(invalidKeyInput(kee,
|
|
49
|
+
throw new TypeError(invalidKeyInput(kee, ...types));
|
|
49
50
|
}
|
|
50
51
|
switch (key.asymmetricKeyType) {
|
|
51
52
|
case 'x25519':
|
|
@@ -9,7 +9,8 @@ import isKeyObject from './is_key_object.js';
|
|
|
9
9
|
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
10
10
|
import { JOSENotSupported } from '../util/errors.js';
|
|
11
11
|
import supported from './ciphers.js';
|
|
12
|
-
|
|
12
|
+
import { types } from './is_key_like.js';
|
|
13
|
+
function cbcEncrypt(enc, plaintext, cek, iv, aad) {
|
|
13
14
|
const keySize = parseInt(enc.substr(1, 3), 10);
|
|
14
15
|
if (isKeyObject(cek)) {
|
|
15
16
|
cek = cek.export();
|
|
@@ -26,7 +27,7 @@ async function cbcEncrypt(enc, plaintext, cek, iv, aad) {
|
|
|
26
27
|
const tag = cbcTag(aad, iv, ciphertext, macSize, macKey, keySize);
|
|
27
28
|
return { ciphertext, tag };
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
+
function gcmEncrypt(enc, plaintext, cek, iv, aad) {
|
|
30
31
|
const keySize = parseInt(enc.substr(1, 3), 10);
|
|
31
32
|
const algorithm = `aes-${keySize}-gcm`;
|
|
32
33
|
if (!supported(algorithm)) {
|
|
@@ -41,7 +42,7 @@ async function gcmEncrypt(enc, plaintext, cek, iv, aad) {
|
|
|
41
42
|
const tag = cipher.getAuthTag();
|
|
42
43
|
return { ciphertext, tag };
|
|
43
44
|
}
|
|
44
|
-
const encrypt =
|
|
45
|
+
const encrypt = (enc, plaintext, cek, iv, aad) => {
|
|
45
46
|
let key;
|
|
46
47
|
if (isCryptoKey(cek)) {
|
|
47
48
|
checkEncCryptoKey(cek, enc, 'encrypt');
|
|
@@ -51,7 +52,7 @@ const encrypt = async (enc, plaintext, cek, iv, aad) => {
|
|
|
51
52
|
key = cek;
|
|
52
53
|
}
|
|
53
54
|
else {
|
|
54
|
-
throw new TypeError(invalidKeyInput(cek,
|
|
55
|
+
throw new TypeError(invalidKeyInput(cek, ...types, 'Uint8Array'));
|
|
55
56
|
}
|
|
56
57
|
checkCekLength(enc, key);
|
|
57
58
|
checkIvLength(enc, iv);
|
|
@@ -4,6 +4,7 @@ import { JOSENotSupported } from '../util/errors.js';
|
|
|
4
4
|
import { isCryptoKey } from './webcrypto.js';
|
|
5
5
|
import isKeyObject from './is_key_object.js';
|
|
6
6
|
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
7
|
+
import { types } from './is_key_like.js';
|
|
7
8
|
const p256 = Buffer.from([42, 134, 72, 206, 61, 3, 1, 7]);
|
|
8
9
|
const p384 = Buffer.from([43, 129, 4, 0, 34]);
|
|
9
10
|
const p521 = Buffer.from([43, 129, 4, 0, 35]);
|
|
@@ -33,7 +34,7 @@ const getNamedCurve = (kee, raw) => {
|
|
|
33
34
|
key = kee;
|
|
34
35
|
}
|
|
35
36
|
else {
|
|
36
|
-
throw new TypeError(invalidKeyInput(kee,
|
|
37
|
+
throw new TypeError(invalidKeyInput(kee, ...types));
|
|
37
38
|
}
|
|
38
39
|
if (key.type === 'secret') {
|
|
39
40
|
throw new TypeError('only "private" or "public" type keys can be used for this operation');
|
|
@@ -3,10 +3,11 @@ import { isCryptoKey } from './webcrypto.js';
|
|
|
3
3
|
import { checkSigCryptoKey } from '../lib/crypto_key.js';
|
|
4
4
|
import getSecretKey from './secret_key.js';
|
|
5
5
|
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
6
|
+
import { types } from './is_key_like.js';
|
|
6
7
|
export default function getSignVerifyKey(alg, key, usage) {
|
|
7
8
|
if (key instanceof Uint8Array) {
|
|
8
9
|
if (!alg.startsWith('HS')) {
|
|
9
|
-
throw new TypeError(invalidKeyInput(key,
|
|
10
|
+
throw new TypeError(invalidKeyInput(key, ...types));
|
|
10
11
|
}
|
|
11
12
|
return getSecretKey(key);
|
|
12
13
|
}
|
|
@@ -17,5 +18,5 @@ export default function getSignVerifyKey(alg, key, usage) {
|
|
|
17
18
|
checkSigCryptoKey(key, alg, usage);
|
|
18
19
|
return KeyObject.from(key);
|
|
19
20
|
}
|
|
20
|
-
throw new TypeError(invalidKeyInput(key,
|
|
21
|
+
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array'));
|
|
21
22
|
}
|
|
@@ -6,6 +6,7 @@ import getNamedCurve from './get_named_curve.js';
|
|
|
6
6
|
import { isCryptoKey } from './webcrypto.js';
|
|
7
7
|
import isKeyObject from './is_key_object.js';
|
|
8
8
|
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
9
|
+
import { types } from './is_key_like.js';
|
|
9
10
|
const [major, minor] = process.version
|
|
10
11
|
.substr(1)
|
|
11
12
|
.split('.')
|
|
@@ -29,7 +30,7 @@ const keyToJWK = (key) => {
|
|
|
29
30
|
};
|
|
30
31
|
}
|
|
31
32
|
else {
|
|
32
|
-
throw new TypeError(invalidKeyInput(key,
|
|
33
|
+
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array'));
|
|
33
34
|
}
|
|
34
35
|
if (jwkExportSupported) {
|
|
35
36
|
return keyObject.export({ format: 'jwk' });
|
|
@@ -9,6 +9,7 @@ import { isCryptoKey } from './webcrypto.js';
|
|
|
9
9
|
import { checkEncCryptoKey } from '../lib/crypto_key.js';
|
|
10
10
|
import isKeyObject from './is_key_object.js';
|
|
11
11
|
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
12
|
+
import { types } from './is_key_like.js';
|
|
12
13
|
const pbkdf2 = promisify(pbkdf2cb);
|
|
13
14
|
function getPassword(key, alg) {
|
|
14
15
|
if (isKeyObject(key)) {
|
|
@@ -21,7 +22,7 @@ function getPassword(key, alg) {
|
|
|
21
22
|
checkEncCryptoKey(key, alg, 'deriveBits', 'deriveKey');
|
|
22
23
|
return KeyObject.from(key).export();
|
|
23
24
|
}
|
|
24
|
-
throw new TypeError(invalidKeyInput(key,
|
|
25
|
+
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array'));
|
|
25
26
|
}
|
|
26
27
|
export const encrypt = async (alg, key, cek, p2c = Math.floor(Math.random() * 2049) + 2048, p2s = random(new Uint8Array(16))) => {
|
|
27
28
|
checkP2s(p2s);
|
|
@@ -4,6 +4,7 @@ import { isCryptoKey } from './webcrypto.js';
|
|
|
4
4
|
import { checkEncCryptoKey } from '../lib/crypto_key.js';
|
|
5
5
|
import isKeyObject from './is_key_object.js';
|
|
6
6
|
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
7
|
+
import { types } from './is_key_like.js';
|
|
7
8
|
const checkKey = (key, alg) => {
|
|
8
9
|
if (key.asymmetricKeyType !== 'rsa') {
|
|
9
10
|
throw new TypeError('Invalid key for this operation, its asymmetricKeyType must be rsa');
|
|
@@ -45,16 +46,16 @@ function ensureKeyObject(key, alg, ...usages) {
|
|
|
45
46
|
checkEncCryptoKey(key, alg, ...usages);
|
|
46
47
|
return KeyObject.from(key);
|
|
47
48
|
}
|
|
48
|
-
throw new TypeError(invalidKeyInput(key,
|
|
49
|
+
throw new TypeError(invalidKeyInput(key, ...types));
|
|
49
50
|
}
|
|
50
|
-
export const encrypt =
|
|
51
|
+
export const encrypt = (alg, key, cek) => {
|
|
51
52
|
const padding = resolvePadding(alg);
|
|
52
53
|
const oaepHash = resolveOaepHash(alg);
|
|
53
54
|
const keyObject = ensureKeyObject(key, alg, 'wrapKey', 'encrypt');
|
|
54
55
|
checkKey(keyObject, alg);
|
|
55
56
|
return publicEncrypt({ key: keyObject, oaepHash, padding }, cek);
|
|
56
57
|
};
|
|
57
|
-
export const decrypt =
|
|
58
|
+
export const decrypt = (alg, key, encryptedKey) => {
|
|
58
59
|
const padding = resolvePadding(alg);
|
|
59
60
|
const oaepHash = resolveOaepHash(alg);
|
|
60
61
|
const keyObject = ensureKeyObject(key, alg, 'unwrapKey', 'decrypt');
|
package/dist/types/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export { flattenedDecrypt } from './jwe/flattened/decrypt';
|
|
|
4
4
|
export type { FlattenedDecryptGetKey } from './jwe/flattened/decrypt';
|
|
5
5
|
export { generalDecrypt } from './jwe/general/decrypt';
|
|
6
6
|
export type { GeneralDecryptGetKey } from './jwe/general/decrypt';
|
|
7
|
+
export { GeneralEncrypt } from './jwe/general/encrypt';
|
|
8
|
+
export type { Recipient } from './jwe/general/encrypt';
|
|
7
9
|
export { compactVerify } from './jws/compact/verify';
|
|
8
10
|
export type { CompactVerifyGetKey } from './jws/compact/verify';
|
|
9
11
|
export { flattenedVerify } from './jws/flattened/verify';
|
|
@@ -40,4 +42,4 @@ export type { GenerateKeyPairResult, GenerateKeyPairOptions } from './key/genera
|
|
|
40
42
|
export { generateSecret } from './key/generate_secret';
|
|
41
43
|
export type { GenerateSecretOptions } from './key/generate_secret';
|
|
42
44
|
export * as base64url from './util/base64url';
|
|
43
|
-
export type { KeyLike, JWK, FlattenedJWSInput, GeneralJWSInput, FlattenedJWS, GeneralJWS, JoseHeaderParameters, JWSHeaderParameters, JWEKeyManagementHeaderParameters, FlattenedJWE, GeneralJWE, JWEHeaderParameters, CritOption, DecryptOptions, EncryptOptions, JWTClaimVerificationOptions, VerifyOptions, SignOptions, JWTPayload, DeflateFunction, InflateFunction, FlattenedDecryptResult, GeneralDecryptResult, CompactDecryptResult, FlattenedVerifyResult, GeneralVerifyResult, CompactVerifyResult, JWTVerifyResult, JWTDecryptResult, ResolvedKey, } from './types';
|
|
45
|
+
export type { KeyLike, JWK, FlattenedJWSInput, GeneralJWSInput, FlattenedJWS, GeneralJWS, JoseHeaderParameters, JWSHeaderParameters, JWEKeyManagementHeaderParameters, FlattenedJWE, GeneralJWE, JWEHeaderParameters, CritOption, DeflateOption, DecryptOptions, EncryptOptions, JWTClaimVerificationOptions, VerifyOptions, SignOptions, JWTPayload, DeflateFunction, InflateFunction, FlattenedDecryptResult, GeneralDecryptResult, CompactDecryptResult, FlattenedVerifyResult, GeneralVerifyResult, CompactVerifyResult, JWTVerifyResult, JWTDecryptResult, ResolvedKey, CompactJWEHeaderParameters, CompactJWSHeaderParameters, JWTHeaderParameters, } from './types';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { KeyLike, DecryptOptions,
|
|
2
|
-
export interface CompactDecryptGetKey extends GetKeyFunction<
|
|
1
|
+
import type { KeyLike, DecryptOptions, CompactJWEHeaderParameters, GetKeyFunction, FlattenedJWE, CompactDecryptResult, ResolvedKey } from '../../types';
|
|
2
|
+
export interface CompactDecryptGetKey extends GetKeyFunction<CompactJWEHeaderParameters, FlattenedJWE> {
|
|
3
3
|
}
|
|
4
4
|
export declare function compactDecrypt(jwe: string | Uint8Array, key: KeyLike | Uint8Array, options?: DecryptOptions): Promise<CompactDecryptResult>;
|
|
5
5
|
export declare function compactDecrypt(jwe: string | Uint8Array, getKey: CompactDecryptGetKey, options?: DecryptOptions): Promise<CompactDecryptResult & ResolvedKey>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { KeyLike, JWEKeyManagementHeaderParameters,
|
|
1
|
+
import type { KeyLike, JWEKeyManagementHeaderParameters, CompactJWEHeaderParameters, EncryptOptions } from '../../types';
|
|
2
2
|
export declare class CompactEncrypt {
|
|
3
3
|
private _flattened;
|
|
4
4
|
constructor(plaintext: Uint8Array);
|
|
5
5
|
setContentEncryptionKey(cek: Uint8Array): this;
|
|
6
6
|
setInitializationVector(iv: Uint8Array): this;
|
|
7
|
-
setProtectedHeader(protectedHeader:
|
|
7
|
+
setProtectedHeader(protectedHeader: CompactJWEHeaderParameters): this;
|
|
8
8
|
setKeyManagementParameters(parameters: JWEKeyManagementHeaderParameters): this;
|
|
9
9
|
encrypt(key: KeyLike | Uint8Array, options?: EncryptOptions): Promise<string>;
|
|
10
10
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { KeyLike, GeneralJWE, JWEHeaderParameters, CritOption, DeflateOption } from '../../types';
|
|
2
|
+
export interface Recipient {
|
|
3
|
+
setUnprotectedHeader(unprotectedHeader: JWEHeaderParameters): Recipient;
|
|
4
|
+
addRecipient(...args: Parameters<GeneralEncrypt['addRecipient']>): Recipient;
|
|
5
|
+
encrypt(...args: Parameters<GeneralEncrypt['encrypt']>): Promise<GeneralJWE>;
|
|
6
|
+
done(): GeneralEncrypt;
|
|
7
|
+
}
|
|
8
|
+
export declare class GeneralEncrypt {
|
|
9
|
+
private _plaintext;
|
|
10
|
+
private _recipients;
|
|
11
|
+
private _protectedHeader;
|
|
12
|
+
private _unprotectedHeader;
|
|
13
|
+
private _aad;
|
|
14
|
+
constructor(plaintext: Uint8Array);
|
|
15
|
+
addRecipient(key: KeyLike | Uint8Array, options?: CritOption): Recipient;
|
|
16
|
+
setProtectedHeader(protectedHeader: JWEHeaderParameters): this;
|
|
17
|
+
setSharedUnprotectedHeader(sharedUnprotectedHeader: JWEHeaderParameters): this;
|
|
18
|
+
setAdditionalAuthenticatedData(aad: Uint8Array): this;
|
|
19
|
+
encrypt(options?: DeflateOption): Promise<GeneralJWE>;
|
|
20
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CompactJWSHeaderParameters, KeyLike, SignOptions } from '../../types';
|
|
2
2
|
export declare class CompactSign {
|
|
3
3
|
private _flattened;
|
|
4
4
|
constructor(payload: Uint8Array);
|
|
5
|
-
setProtectedHeader(protectedHeader:
|
|
5
|
+
setProtectedHeader(protectedHeader: CompactJWSHeaderParameters): this;
|
|
6
6
|
sign(key: KeyLike | Uint8Array, options?: SignOptions): Promise<string>;
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CompactVerifyResult, FlattenedJWSInput, GetKeyFunction,
|
|
2
|
-
export interface CompactVerifyGetKey extends GetKeyFunction<
|
|
1
|
+
import type { CompactVerifyResult, FlattenedJWSInput, GetKeyFunction, CompactJWSHeaderParameters, KeyLike, VerifyOptions, ResolvedKey } from '../../types';
|
|
2
|
+
export interface CompactVerifyGetKey extends GetKeyFunction<CompactJWSHeaderParameters, FlattenedJWSInput> {
|
|
3
3
|
}
|
|
4
4
|
export declare function compactVerify(jws: string | Uint8Array, key: KeyLike | Uint8Array, options?: VerifyOptions): Promise<CompactVerifyResult>;
|
|
5
5
|
export declare function compactVerify(jws: string | Uint8Array, getKey: CompactVerifyGetKey, options?: VerifyOptions): Promise<CompactVerifyResult & ResolvedKey>;
|
|
@@ -2,6 +2,9 @@ import type { KeyLike, GeneralJWS, JWSHeaderParameters, SignOptions } from '../.
|
|
|
2
2
|
export interface Signature {
|
|
3
3
|
setProtectedHeader(protectedHeader: JWSHeaderParameters): Signature;
|
|
4
4
|
setUnprotectedHeader(unprotectedHeader: JWSHeaderParameters): Signature;
|
|
5
|
+
addSignature(...args: Parameters<GeneralSign['addSignature']>): Signature;
|
|
6
|
+
sign(...args: Parameters<GeneralSign['sign']>): Promise<GeneralJWS>;
|
|
7
|
+
done(): GeneralSign;
|
|
5
8
|
}
|
|
6
9
|
export declare class GeneralSign {
|
|
7
10
|
private _payload;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { KeyLike, DecryptOptions, JWTClaimVerificationOptions, GetKeyFunction,
|
|
1
|
+
import type { KeyLike, DecryptOptions, JWTClaimVerificationOptions, GetKeyFunction, CompactJWEHeaderParameters, FlattenedJWE, JWTDecryptResult, ResolvedKey } from '../types';
|
|
2
2
|
export interface JWTDecryptOptions extends DecryptOptions, JWTClaimVerificationOptions {
|
|
3
3
|
}
|
|
4
|
-
export interface JWTDecryptGetKey extends GetKeyFunction<
|
|
4
|
+
export interface JWTDecryptGetKey extends GetKeyFunction<CompactJWEHeaderParameters, FlattenedJWE> {
|
|
5
5
|
}
|
|
6
6
|
export declare function jwtDecrypt(jwt: string | Uint8Array, key: KeyLike | Uint8Array, options?: JWTDecryptOptions): Promise<JWTDecryptResult>;
|
|
7
7
|
export declare function jwtDecrypt(jwt: string | Uint8Array, getKey: JWTDecryptGetKey, options?: JWTDecryptOptions): Promise<JWTDecryptResult & ResolvedKey>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EncryptOptions,
|
|
1
|
+
import type { EncryptOptions, CompactJWEHeaderParameters, JWEKeyManagementHeaderParameters, KeyLike } from '../types';
|
|
2
2
|
import { ProduceJWT } from './produce';
|
|
3
3
|
export declare class EncryptJWT extends ProduceJWT {
|
|
4
4
|
private _cek;
|
|
@@ -8,7 +8,7 @@ export declare class EncryptJWT extends ProduceJWT {
|
|
|
8
8
|
private _replicateIssuerAsHeader;
|
|
9
9
|
private _replicateSubjectAsHeader;
|
|
10
10
|
private _replicateAudienceAsHeader;
|
|
11
|
-
setProtectedHeader(protectedHeader:
|
|
11
|
+
setProtectedHeader(protectedHeader: CompactJWEHeaderParameters): this;
|
|
12
12
|
setKeyManagementParameters(parameters: JWEKeyManagementHeaderParameters): this;
|
|
13
13
|
setContentEncryptionKey(cek: Uint8Array): this;
|
|
14
14
|
setInitializationVector(iv: Uint8Array): this;
|
package/dist/types/jwt/sign.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { JWTHeaderParameters, KeyLike, SignOptions } from '../types';
|
|
2
2
|
import { ProduceJWT } from './produce';
|
|
3
3
|
export declare class SignJWT extends ProduceJWT {
|
|
4
4
|
private _protectedHeader;
|
|
5
|
-
setProtectedHeader(protectedHeader:
|
|
5
|
+
setProtectedHeader(protectedHeader: JWTHeaderParameters): this;
|
|
6
6
|
sign(key: KeyLike | Uint8Array, options?: SignOptions): Promise<string>;
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { KeyLike, VerifyOptions, JWTClaimVerificationOptions,
|
|
1
|
+
import type { KeyLike, VerifyOptions, JWTClaimVerificationOptions, JWTHeaderParameters, GetKeyFunction, FlattenedJWSInput, JWTVerifyResult, ResolvedKey } from '../types';
|
|
2
2
|
export interface JWTVerifyOptions extends VerifyOptions, JWTClaimVerificationOptions {
|
|
3
3
|
}
|
|
4
|
-
export interface JWTVerifyGetKey extends GetKeyFunction<
|
|
4
|
+
export interface JWTVerifyGetKey extends GetKeyFunction<JWTHeaderParameters, FlattenedJWSInput> {
|
|
5
5
|
}
|
|
6
6
|
export declare function jwtVerify(jwt: string | Uint8Array, key: KeyLike | Uint8Array, options?: JWTVerifyOptions): Promise<JWTVerifyResult>;
|
|
7
7
|
export declare function jwtVerify(jwt: string | Uint8Array, getKey: JWTVerifyGetKey, options?: JWTVerifyOptions): Promise<JWTVerifyResult & ResolvedKey>;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -35,20 +35,16 @@
|
|
|
35
35
|
*
|
|
36
36
|
* @example Import a PEM-encoded SPKI Public Key
|
|
37
37
|
* ```js
|
|
38
|
-
* import { importSPKI } from 'jose'
|
|
39
|
-
*
|
|
40
38
|
* const algorithm = 'ES256'
|
|
41
39
|
* const spki = `-----BEGIN PUBLIC KEY-----
|
|
42
40
|
* MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEFlHHWfLk0gLBbsLTcuCrbCqoHqmM
|
|
43
41
|
* YJepMC+Q+Dd6RBmBiA41evUsNMwLeN+PNFqib+xwi9JkJ8qhZkq8Y/IzGg==
|
|
44
42
|
* -----END PUBLIC KEY-----`
|
|
45
|
-
* const ecPublicKey = await importSPKI(spki, algorithm)
|
|
43
|
+
* const ecPublicKey = await jose.importSPKI(spki, algorithm)
|
|
46
44
|
* ```
|
|
47
45
|
*
|
|
48
46
|
* @example Import a X.509 Certificate
|
|
49
47
|
* ```js
|
|
50
|
-
* import { importX509 } from 'jose'
|
|
51
|
-
*
|
|
52
48
|
* const algorithm = 'ES256'
|
|
53
49
|
* const x509 = `-----BEGIN CERTIFICATE-----
|
|
54
50
|
* MIIBXjCCAQSgAwIBAgIGAXvykuMKMAoGCCqGSM49BAMCMDYxNDAyBgNVBAMMK3Np
|
|
@@ -60,34 +56,30 @@
|
|
|
60
56
|
* 1yyMTRe66MhEXID9+uVub7woMkNYd0LhSHwKSPMUUTkCIFQGsfm1ecXOpeGOufAh
|
|
61
57
|
* v+A1QWZMuTWqYt+uh/YSRNDn
|
|
62
58
|
* -----END CERTIFICATE-----`
|
|
63
|
-
* const ecPublicKey = await importX509(x509, algorithm)
|
|
59
|
+
* const ecPublicKey = await jose.importX509(x509, algorithm)
|
|
64
60
|
* ```
|
|
65
61
|
*
|
|
66
62
|
* @example Import a PEM-encoded PKCS8 Private Key
|
|
67
63
|
* ```js
|
|
68
|
-
* import { importPKCS8 } from 'jose'
|
|
69
|
-
*
|
|
70
64
|
* const algorithm = 'ES256'
|
|
71
65
|
* const pkcs8 = `-----BEGIN PRIVATE KEY-----
|
|
72
66
|
* MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgiyvo0X+VQ0yIrOaN
|
|
73
67
|
* nlrnUclopnvuuMfoc8HHly3505OhRANCAAQWUcdZ8uTSAsFuwtNy4KtsKqgeqYxg
|
|
74
68
|
* l6kwL5D4N3pEGYGIDjV69Sw0zAt43480WqJv7HCL0mQnyqFmSrxj8jMa
|
|
75
69
|
* -----END PRIVATE KEY-----`
|
|
76
|
-
* const ecPrivateKey = await importPKCS8(pkcs8, algorithm)
|
|
70
|
+
* const ecPrivateKey = await jose.importPKCS8(pkcs8, algorithm)
|
|
77
71
|
* ```
|
|
78
72
|
*
|
|
79
73
|
* @example Import a JSON Web Key (JWK)
|
|
80
74
|
* ```js
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* const ecPublicKey = await importJWK({
|
|
75
|
+
* const ecPublicKey = await jose.importJWK({
|
|
84
76
|
* crv: 'P-256',
|
|
85
77
|
* kty: 'EC',
|
|
86
78
|
* x: 'ySK38C1jBdLwDsNWKzzBHqKYEE5Cgv-qjWvorUXk9fw',
|
|
87
79
|
* y: '_LeQBw07cf5t57Iavn4j-BqJsAD1dpoz8gokd3sBsOo'
|
|
88
80
|
* }, 'ES256')
|
|
89
81
|
*
|
|
90
|
-
* const rsaPublicKey = await importJWK({
|
|
82
|
+
* const rsaPublicKey = await jose.importJWK({
|
|
91
83
|
* kty: 'RSA',
|
|
92
84
|
* e: 'AQAB',
|
|
93
85
|
* n: '12oBZRhCiZFJLcPg59LkZZ9mdhSMTKAQZYq32k_ti5SBB6jerkh-WzOMAO664r_qyLkqHUSp3u5SbXtseZEpN3XPWGKSxjsy-1JyEFTdLSYe6f9gfrmxkUF_7DTpq0gn6rntP05g2-wFW50YO7mosfdslfrTJYWHFhJALabAeYirYD7-9kqq9ebfFMF4sRRELbv9oi36As6Q9B3Qb5_C1rAzqfao_PCsf9EPsTZsVVVkA5qoIAr47lo1ipfiBPxUCCNSdvkmDTYgvvRm6ZoMjFbvOtgyts55fXKdMWv7I9HMD5HwE9uW839PWA514qhbcIsXEYSFMPMV6fnlsiZvQQ'
|
|
@@ -200,9 +192,10 @@ export interface DecryptOptions extends CritOption {
|
|
|
200
192
|
contentEncryptionAlgorithms?: string[]
|
|
201
193
|
inflateRaw?: InflateFunction
|
|
202
194
|
}
|
|
203
|
-
export interface
|
|
195
|
+
export interface DeflateOption {
|
|
204
196
|
deflateRaw?: DeflateFunction
|
|
205
197
|
}
|
|
198
|
+
export interface EncryptOptions extends CritOption, DeflateOption {}
|
|
206
199
|
export interface JWTClaimVerificationOptions {
|
|
207
200
|
audience?: string | string[]
|
|
208
201
|
clockTolerance?: string | number
|
|
@@ -265,3 +258,13 @@ export interface JWTDecryptResult {
|
|
|
265
258
|
export interface ResolvedKey {
|
|
266
259
|
key: KeyLike | Uint8Array
|
|
267
260
|
}
|
|
261
|
+
export interface CompactJWSHeaderParameters extends JWSHeaderParameters {
|
|
262
|
+
alg: string
|
|
263
|
+
}
|
|
264
|
+
export interface JWTHeaderParameters extends CompactJWSHeaderParameters {
|
|
265
|
+
b64: never
|
|
266
|
+
}
|
|
267
|
+
export interface CompactJWEHeaderParameters extends JWEHeaderParameters {
|
|
268
|
+
alg: string
|
|
269
|
+
enc: string
|
|
270
|
+
}
|