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.
Files changed (89) hide show
  1. package/dist/types/index.d.ts +1 -2
  2. package/dist/types/jwe/compact/decrypt.d.ts +12 -25
  3. package/dist/types/jwe/compact/encrypt.d.ts +18 -32
  4. package/dist/types/jwe/flattened/decrypt.d.ts +12 -25
  5. package/dist/types/jwe/flattened/encrypt.d.ts +24 -50
  6. package/dist/types/jwe/general/decrypt.d.ts +15 -30
  7. package/dist/types/jwe/general/encrypt.d.ts +29 -52
  8. package/dist/types/jwk/embedded.d.ts +5 -8
  9. package/dist/types/jwk/thumbprint.d.ts +7 -9
  10. package/dist/types/jwks/local.d.ts +10 -13
  11. package/dist/types/jwks/remote.d.ts +29 -41
  12. package/dist/types/jws/compact/sign.d.ts +8 -13
  13. package/dist/types/jws/compact/verify.d.ts +14 -26
  14. package/dist/types/jws/flattened/sign.d.ts +10 -19
  15. package/dist/types/jws/flattened/verify.d.ts +14 -26
  16. package/dist/types/jws/general/sign.d.ts +19 -33
  17. package/dist/types/jws/general/verify.d.ts +17 -32
  18. package/dist/types/jwt/decrypt.d.ts +20 -27
  19. package/dist/types/jwt/encrypt.d.ts +30 -35
  20. package/dist/types/jwt/sign.d.ts +8 -13
  21. package/dist/types/jwt/unsecured.d.ts +10 -19
  22. package/dist/types/jwt/verify.d.ts +19 -22
  23. package/dist/types/key/export.d.ts +10 -10
  24. package/dist/types/key/generate_key_pair.d.ts +15 -22
  25. package/dist/types/key/generate_secret.d.ts +12 -19
  26. package/dist/types/key/import.d.ts +25 -31
  27. package/dist/types/types.d.ts +184 -319
  28. package/dist/types/util/base64url.d.ts +7 -7
  29. package/dist/types/util/decode_jwt.d.ts +5 -7
  30. package/dist/types/util/decode_protected_header.d.ts +6 -5
  31. package/dist/types/util/errors.d.ts +50 -88
  32. package/dist/webapi/index.js +70 -32
  33. package/dist/webapi/jwe/compact/decrypt.js +6 -8
  34. package/dist/webapi/jwe/compact/encrypt.js +25 -48
  35. package/dist/webapi/jwe/flattened/decrypt.js +14 -14
  36. package/dist/webapi/jwe/flattened/encrypt.js +34 -64
  37. package/dist/webapi/jwe/general/decrypt.js +38 -49
  38. package/dist/webapi/jwe/general/encrypt.js +100 -172
  39. package/dist/webapi/jwk/embedded.js +29 -32
  40. package/dist/webapi/jwk/thumbprint.js +51 -70
  41. package/dist/webapi/jwks/local.js +53 -64
  42. package/dist/webapi/jwks/remote.js +88 -136
  43. package/dist/webapi/jws/compact/sign.js +19 -21
  44. package/dist/webapi/jws/compact/verify.js +7 -8
  45. package/dist/webapi/jws/flattened/sign.js +22 -31
  46. package/dist/webapi/jws/flattened/verify.js +11 -24
  47. package/dist/webapi/jws/general/sign.js +55 -73
  48. package/dist/webapi/jws/general/verify.js +43 -69
  49. package/dist/webapi/jwt/decrypt.js +12 -20
  50. package/dist/webapi/jwt/encrypt.js +43 -70
  51. package/dist/webapi/jwt/sign.js +17 -16
  52. package/dist/webapi/jwt/unsecured.js +31 -40
  53. package/dist/webapi/jwt/verify.js +12 -14
  54. package/dist/webapi/key/export.js +32 -41
  55. package/dist/webapi/key/generate_key_pair.js +32 -49
  56. package/dist/webapi/key/generate_secret.js +35 -40
  57. package/dist/webapi/key/import.js +48 -56
  58. package/dist/webapi/lib/asn1.js +128 -169
  59. package/dist/webapi/lib/buffer_utils.js +72 -41
  60. package/dist/webapi/lib/content_encryption.js +75 -119
  61. package/dist/webapi/lib/deflate.js +35 -47
  62. package/dist/webapi/lib/jwe_algorithms.js +102 -93
  63. package/dist/webapi/lib/jwe_decrypt.js +178 -234
  64. package/dist/webapi/lib/jwe_encrypt.js +71 -138
  65. package/dist/webapi/lib/jws_algorithms.js +62 -61
  66. package/dist/webapi/lib/jws_sign.js +43 -82
  67. package/dist/webapi/lib/jws_verify.js +78 -131
  68. package/dist/webapi/lib/jwt_claims_set.js +123 -209
  69. package/dist/webapi/lib/key.js +147 -139
  70. package/dist/webapi/lib/key_algorithm.js +13 -8
  71. package/dist/webapi/lib/key_descriptor.js +8 -6
  72. package/dist/webapi/lib/key_management.js +169 -235
  73. package/dist/webapi/lib/validate.js +122 -0
  74. package/dist/webapi/util/base64url.js +14 -37
  75. package/dist/webapi/util/decode_jwt.js +32 -31
  76. package/dist/webapi/util/decode_protected_header.js +18 -23
  77. package/dist/webapi/util/errors.js +94 -84
  78. package/package.json +17 -81
  79. package/dist/webapi/lib/base64.js +0 -22
  80. package/dist/webapi/lib/crypto_key.js +0 -28
  81. package/dist/webapi/lib/helpers.js +0 -42
  82. package/dist/webapi/lib/invalid_key_input.js +0 -26
  83. package/dist/webapi/lib/is_key_like.js +0 -17
  84. package/dist/webapi/lib/jwk_metadata.js +0 -20
  85. package/dist/webapi/lib/jwk_to_key.js +0 -17
  86. package/dist/webapi/lib/key_options.js +0 -6
  87. package/dist/webapi/lib/options.js +0 -74
  88. package/dist/webapi/lib/signing.js +0 -26
  89. package/dist/webapi/lib/type_checks.js +0 -33
@@ -1,32 +1,33 @@
1
- import { decode as b64u } from './base64url.js';
2
- import { strictDecoder } from '../lib/buffer_utils.js';
3
- import { isObject } from '../lib/type_checks.js';
4
- import { JWTInvalid } from './errors.js';
5
- export function decodeJwt(jwt) {
6
- if (typeof jwt !== 'string')
7
- throw new JWTInvalid('JWTs must use Compact JWS serialization, JWT must be a string');
8
- const { 1: payload, length } = jwt.split('.');
9
- if (length === 5)
10
- throw new JWTInvalid('Only JWTs using Compact JWS serialization can be decoded');
11
- if (length !== 3)
12
- throw new JWTInvalid('Invalid JWT');
13
- if (!payload)
14
- throw new JWTInvalid('JWTs must contain a payload');
15
- let decoded;
16
- try {
17
- decoded = b64u(payload);
18
- }
19
- catch {
20
- throw new JWTInvalid('Failed to base64url decode the payload');
21
- }
22
- let result;
23
- try {
24
- result = JSON.parse(strictDecoder.decode(decoded));
25
- }
26
- catch {
27
- throw new JWTInvalid('Failed to parse the decoded payload as JSON');
28
- }
29
- if (!isObject(result))
30
- throw new JWTInvalid('Invalid JWT Claims Set');
31
- return result;
1
+ import { decode as b64u } from "./base64url.js";
2
+ import { strictDecoder } from "../lib/buffer_utils.js";
3
+ import { isObject } from "../lib/validate.js";
4
+ import { JWTInvalid } from "./errors.js";
5
+ function decodeJwt(jwt) {
6
+ if (typeof jwt != "string")
7
+ throw new JWTInvalid("JWTs must use Compact JWS serialization, JWT must be a string");
8
+ const { 1: payload, length } = jwt.split(".");
9
+ if (length === 5)
10
+ throw new JWTInvalid("Only JWTs using Compact JWS serialization can be decoded");
11
+ if (length !== 3)
12
+ throw new JWTInvalid("Invalid JWT");
13
+ if (!payload)
14
+ throw new JWTInvalid("JWTs must contain a payload");
15
+ let decoded;
16
+ try {
17
+ decoded = b64u(payload);
18
+ } catch {
19
+ throw new JWTInvalid("Failed to base64url decode the payload");
20
+ }
21
+ let result;
22
+ try {
23
+ result = JSON.parse(strictDecoder.decode(decoded));
24
+ } catch {
25
+ throw new JWTInvalid("Failed to parse the decoded payload as JSON");
26
+ }
27
+ if (!isObject(result))
28
+ throw new JWTInvalid("Invalid JWT Claims Set");
29
+ return result;
32
30
  }
31
+ export {
32
+ decodeJwt
33
+ };
@@ -1,24 +1,19 @@
1
- import { parseJoseHeader } from '../lib/helpers.js';
2
- export function decodeProtectedHeader(token) {
3
- let protectedB64u;
4
- if (typeof token === 'string') {
5
- const parts = token.split('.');
6
- if (parts.length === 3 || parts.length === 5) {
7
- ;
8
- [protectedB64u] = parts;
9
- }
10
- }
11
- else if (typeof token === 'object' && token) {
12
- if ('protected' in token) {
13
- protectedB64u = token.protected;
14
- }
15
- else {
16
- throw new TypeError('Token does not contain a Protected Header');
17
- }
18
- }
19
- const invalid = 'Invalid Token or Protected Header formatting';
20
- if (typeof protectedB64u !== 'string' || !protectedB64u) {
21
- throw new TypeError(invalid);
22
- }
23
- return parseJoseHeader(protectedB64u, TypeError, invalid);
1
+ import { parseJoseHeader } from "../lib/validate.js";
2
+ function decodeProtectedHeader(token) {
3
+ let protectedB64u;
4
+ if (typeof token == "string") {
5
+ const parts = token.split(".");
6
+ (parts.length === 3 || parts.length === 5) && ([protectedB64u] = parts);
7
+ } else if (typeof token == "object" && token)
8
+ if ("protected" in token)
9
+ protectedB64u = token.protected;
10
+ else
11
+ throw new TypeError("Token does not contain a Protected Header");
12
+ const invalid = "Invalid Token or Protected Header formatting";
13
+ if (typeof protectedB64u != "string" || !protectedB64u)
14
+ throw new TypeError(invalid);
15
+ return parseJoseHeader(protectedB64u, TypeError, invalid);
24
16
  }
17
+ export {
18
+ decodeProtectedHeader
19
+ };
@@ -1,99 +1,109 @@
1
- export class JOSEError extends Error {
2
- static code = 'ERR_JOSE_GENERIC';
3
- code = 'ERR_JOSE_GENERIC';
4
- constructor(message, options) {
5
- super(message, options);
6
- this.name = this.constructor.name;
7
- Error.captureStackTrace?.(this, this.constructor);
8
- }
1
+ class JOSEError extends Error {
2
+ static code = "ERR_JOSE_GENERIC";
3
+ code = "ERR_JOSE_GENERIC";
4
+ constructor(message, options) {
5
+ super(message, options), this.name = this.constructor.name, Error.captureStackTrace?.(this, this.constructor);
6
+ }
9
7
  }
10
- export class JWTClaimValidationFailed extends JOSEError {
11
- static code = 'ERR_JWT_CLAIM_VALIDATION_FAILED';
12
- code = 'ERR_JWT_CLAIM_VALIDATION_FAILED';
13
- claim;
14
- reason;
15
- payload;
16
- constructor(message, payload, claim = 'unspecified', reason = 'unspecified') {
17
- super(message, { cause: { claim, reason, payload } });
18
- this.claim = claim;
19
- this.reason = reason;
20
- this.payload = payload;
21
- }
8
+ class JWTClaimValidationFailed extends JOSEError {
9
+ static code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
10
+ code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
11
+ claim;
12
+ reason;
13
+ payload;
14
+ constructor(message, payload, claim = "unspecified", reason = "unspecified") {
15
+ super(message, { cause: { claim, reason, payload } }), this.claim = claim, this.reason = reason, this.payload = payload;
16
+ }
22
17
  }
23
- export class JWTExpired extends JOSEError {
24
- static code = 'ERR_JWT_EXPIRED';
25
- code = 'ERR_JWT_EXPIRED';
26
- claim;
27
- reason;
28
- payload;
29
- constructor(message, payload, claim = 'unspecified', reason = 'unspecified') {
30
- super(message, { cause: { claim, reason, payload } });
31
- this.claim = claim;
32
- this.reason = reason;
33
- this.payload = payload;
34
- }
18
+ class JWTExpired extends JOSEError {
19
+ static code = "ERR_JWT_EXPIRED";
20
+ code = "ERR_JWT_EXPIRED";
21
+ claim;
22
+ reason;
23
+ payload;
24
+ constructor(message, payload, claim = "unspecified", reason = "unspecified") {
25
+ super(message, { cause: { claim, reason, payload } }), this.claim = claim, this.reason = reason, this.payload = payload;
26
+ }
35
27
  }
36
- export class JOSEAlgNotAllowed extends JOSEError {
37
- static code = 'ERR_JOSE_ALG_NOT_ALLOWED';
38
- code = 'ERR_JOSE_ALG_NOT_ALLOWED';
28
+ class JOSEAlgNotAllowed extends JOSEError {
29
+ static code = "ERR_JOSE_ALG_NOT_ALLOWED";
30
+ code = "ERR_JOSE_ALG_NOT_ALLOWED";
39
31
  }
40
- export class JOSENotSupported extends JOSEError {
41
- static code = 'ERR_JOSE_NOT_SUPPORTED';
42
- code = 'ERR_JOSE_NOT_SUPPORTED';
32
+ class JOSENotSupported extends JOSEError {
33
+ static code = "ERR_JOSE_NOT_SUPPORTED";
34
+ code = "ERR_JOSE_NOT_SUPPORTED";
43
35
  }
44
- export class JWEDecryptionFailed extends JOSEError {
45
- static code = 'ERR_JWE_DECRYPTION_FAILED';
46
- code = 'ERR_JWE_DECRYPTION_FAILED';
47
- constructor(message = 'decryption operation failed', options) {
48
- super(message, options);
49
- }
36
+ class JWEDecryptionFailed extends JOSEError {
37
+ static code = "ERR_JWE_DECRYPTION_FAILED";
38
+ code = "ERR_JWE_DECRYPTION_FAILED";
39
+ constructor(message = "decryption operation failed", options) {
40
+ super(message, options);
41
+ }
50
42
  }
51
- export class JWEInvalid extends JOSEError {
52
- static code = 'ERR_JWE_INVALID';
53
- code = 'ERR_JWE_INVALID';
43
+ class JWEInvalid extends JOSEError {
44
+ static code = "ERR_JWE_INVALID";
45
+ code = "ERR_JWE_INVALID";
54
46
  }
55
- export class JWSInvalid extends JOSEError {
56
- static code = 'ERR_JWS_INVALID';
57
- code = 'ERR_JWS_INVALID';
47
+ class JWSInvalid extends JOSEError {
48
+ static code = "ERR_JWS_INVALID";
49
+ code = "ERR_JWS_INVALID";
58
50
  }
59
- export class JWTInvalid extends JOSEError {
60
- static code = 'ERR_JWT_INVALID';
61
- code = 'ERR_JWT_INVALID';
51
+ class JWTInvalid extends JOSEError {
52
+ static code = "ERR_JWT_INVALID";
53
+ code = "ERR_JWT_INVALID";
62
54
  }
63
- export class JWKInvalid extends JOSEError {
64
- static code = 'ERR_JWK_INVALID';
65
- code = 'ERR_JWK_INVALID';
55
+ class JWKInvalid extends JOSEError {
56
+ static code = "ERR_JWK_INVALID";
57
+ code = "ERR_JWK_INVALID";
66
58
  }
67
- export class JWKSInvalid extends JOSEError {
68
- static code = 'ERR_JWKS_INVALID';
69
- code = 'ERR_JWKS_INVALID';
59
+ class JWKSInvalid extends JOSEError {
60
+ static code = "ERR_JWKS_INVALID";
61
+ code = "ERR_JWKS_INVALID";
70
62
  }
71
- export class JWKSNoMatchingKey extends JOSEError {
72
- static code = 'ERR_JWKS_NO_MATCHING_KEY';
73
- code = 'ERR_JWKS_NO_MATCHING_KEY';
74
- constructor(message = 'no applicable key found in the JSON Web Key Set', options) {
75
- super(message, options);
76
- }
63
+ class JWKSNoMatchingKey extends JOSEError {
64
+ static code = "ERR_JWKS_NO_MATCHING_KEY";
65
+ code = "ERR_JWKS_NO_MATCHING_KEY";
66
+ constructor(message = "no applicable key found in the JSON Web Key Set", options) {
67
+ super(message, options);
68
+ }
77
69
  }
78
- export class JWKSMultipleMatchingKeys extends JOSEError {
79
- [Symbol.asyncIterator] = async function* () { };
80
- static code = 'ERR_JWKS_MULTIPLE_MATCHING_KEYS';
81
- code = 'ERR_JWKS_MULTIPLE_MATCHING_KEYS';
82
- constructor(message = 'multiple matching keys found in the JSON Web Key Set', options) {
83
- super(message, options);
84
- }
70
+ class JWKSMultipleMatchingKeys extends JOSEError {
71
+ [Symbol.asyncIterator] = async function* () {
72
+ };
73
+ static code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
74
+ code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
75
+ constructor(message = "multiple matching keys found in the JSON Web Key Set", options) {
76
+ super(message, options);
77
+ }
85
78
  }
86
- export class JWKSTimeout extends JOSEError {
87
- static code = 'ERR_JWKS_TIMEOUT';
88
- code = 'ERR_JWKS_TIMEOUT';
89
- constructor(message = 'request timed out', options) {
90
- super(message, options);
91
- }
79
+ class JWKSTimeout extends JOSEError {
80
+ static code = "ERR_JWKS_TIMEOUT";
81
+ code = "ERR_JWKS_TIMEOUT";
82
+ constructor(message = "request timed out", options) {
83
+ super(message, options);
84
+ }
92
85
  }
93
- export class JWSSignatureVerificationFailed extends JOSEError {
94
- static code = 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
95
- code = 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
96
- constructor(message = 'signature verification failed', options) {
97
- super(message, options);
98
- }
86
+ class JWSSignatureVerificationFailed extends JOSEError {
87
+ static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
88
+ code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
89
+ constructor(message = "signature verification failed", options) {
90
+ super(message, options);
91
+ }
99
92
  }
93
+ export {
94
+ JOSEAlgNotAllowed,
95
+ JOSEError,
96
+ JOSENotSupported,
97
+ JWEDecryptionFailed,
98
+ JWEInvalid,
99
+ JWKInvalid,
100
+ JWKSInvalid,
101
+ JWKSMultipleMatchingKeys,
102
+ JWKSNoMatchingKey,
103
+ JWKSTimeout,
104
+ JWSInvalid,
105
+ JWSSignatureVerificationFailed,
106
+ JWTClaimValidationFailed,
107
+ JWTExpired,
108
+ JWTInvalid
109
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jose",
3
- "version": "6.2.10",
3
+ "version": "6.2.12",
4
4
  "description": "JWA, JWS, JWE, JWT, JWK, JWKS for Node.js, Browser, Cloudflare Workers, Deno, Bun, and other Web-interoperable runtimes",
5
5
  "keywords": [
6
6
  "akp",
@@ -67,13 +67,9 @@
67
67
  "types": "./dist/types/index.d.ts",
68
68
  "default": "./dist/webapi/index.js"
69
69
  },
70
- "./jwk/embedded": {
71
- "types": "./dist/types/jwk/embedded.d.ts",
72
- "default": "./dist/webapi/jwk/embedded.js"
73
- },
74
- "./jwk/thumbprint": {
75
- "types": "./dist/types/jwk/thumbprint.d.ts",
76
- "default": "./dist/webapi/jwk/thumbprint.js"
70
+ "./jwk/*": {
71
+ "types": "./dist/types/jwk/*.d.ts",
72
+ "default": "./dist/webapi/jwk/*.js"
77
73
  },
78
74
  "./key/import": {
79
75
  "types": "./dist/types/key/import.d.ts",
@@ -91,89 +87,29 @@
91
87
  "types": "./dist/types/key/generate_secret.d.ts",
92
88
  "default": "./dist/webapi/key/generate_secret.js"
93
89
  },
94
- "./jwks/remote": {
95
- "types": "./dist/types/jwks/remote.d.ts",
96
- "default": "./dist/webapi/jwks/remote.js"
97
- },
98
- "./jwks/local": {
99
- "types": "./dist/types/jwks/local.d.ts",
100
- "default": "./dist/webapi/jwks/local.js"
101
- },
102
- "./jwt/sign": {
103
- "types": "./dist/types/jwt/sign.d.ts",
104
- "default": "./dist/webapi/jwt/sign.js"
105
- },
106
- "./jwt/verify": {
107
- "types": "./dist/types/jwt/verify.d.ts",
108
- "default": "./dist/webapi/jwt/verify.js"
109
- },
110
- "./jwt/encrypt": {
111
- "types": "./dist/types/jwt/encrypt.d.ts",
112
- "default": "./dist/webapi/jwt/encrypt.js"
113
- },
114
- "./jwt/decrypt": {
115
- "types": "./dist/types/jwt/decrypt.d.ts",
116
- "default": "./dist/webapi/jwt/decrypt.js"
117
- },
118
- "./jwt/unsecured": {
119
- "types": "./dist/types/jwt/unsecured.d.ts",
120
- "default": "./dist/webapi/jwt/unsecured.js"
90
+ "./jwks/*": {
91
+ "types": "./dist/types/jwks/*.d.ts",
92
+ "default": "./dist/webapi/jwks/*.js"
121
93
  },
122
94
  "./jwt/decode": {
123
95
  "types": "./dist/types/util/decode_jwt.d.ts",
124
96
  "default": "./dist/webapi/util/decode_jwt.js"
125
97
  },
98
+ "./jwt/*": {
99
+ "types": "./dist/types/jwt/*.d.ts",
100
+ "default": "./dist/webapi/jwt/*.js"
101
+ },
126
102
  "./decode/protected_header": {
127
103
  "types": "./dist/types/util/decode_protected_header.d.ts",
128
104
  "default": "./dist/webapi/util/decode_protected_header.js"
129
105
  },
130
- "./jws/compact/sign": {
131
- "types": "./dist/types/jws/compact/sign.d.ts",
132
- "default": "./dist/webapi/jws/compact/sign.js"
133
- },
134
- "./jws/compact/verify": {
135
- "types": "./dist/types/jws/compact/verify.d.ts",
136
- "default": "./dist/webapi/jws/compact/verify.js"
137
- },
138
- "./jws/flattened/sign": {
139
- "types": "./dist/types/jws/flattened/sign.d.ts",
140
- "default": "./dist/webapi/jws/flattened/sign.js"
141
- },
142
- "./jws/flattened/verify": {
143
- "types": "./dist/types/jws/flattened/verify.d.ts",
144
- "default": "./dist/webapi/jws/flattened/verify.js"
145
- },
146
- "./jws/general/sign": {
147
- "types": "./dist/types/jws/general/sign.d.ts",
148
- "default": "./dist/webapi/jws/general/sign.js"
149
- },
150
- "./jws/general/verify": {
151
- "types": "./dist/types/jws/general/verify.d.ts",
152
- "default": "./dist/webapi/jws/general/verify.js"
153
- },
154
- "./jwe/compact/encrypt": {
155
- "types": "./dist/types/jwe/compact/encrypt.d.ts",
156
- "default": "./dist/webapi/jwe/compact/encrypt.js"
157
- },
158
- "./jwe/compact/decrypt": {
159
- "types": "./dist/types/jwe/compact/decrypt.d.ts",
160
- "default": "./dist/webapi/jwe/compact/decrypt.js"
161
- },
162
- "./jwe/flattened/encrypt": {
163
- "types": "./dist/types/jwe/flattened/encrypt.d.ts",
164
- "default": "./dist/webapi/jwe/flattened/encrypt.js"
165
- },
166
- "./jwe/flattened/decrypt": {
167
- "types": "./dist/types/jwe/flattened/decrypt.d.ts",
168
- "default": "./dist/webapi/jwe/flattened/decrypt.js"
169
- },
170
- "./jwe/general/encrypt": {
171
- "types": "./dist/types/jwe/general/encrypt.d.ts",
172
- "default": "./dist/webapi/jwe/general/encrypt.js"
106
+ "./jws/*": {
107
+ "types": "./dist/types/jws/*.d.ts",
108
+ "default": "./dist/webapi/jws/*.js"
173
109
  },
174
- "./jwe/general/decrypt": {
175
- "types": "./dist/types/jwe/general/decrypt.d.ts",
176
- "default": "./dist/webapi/jwe/general/decrypt.js"
110
+ "./jwe/*": {
111
+ "types": "./dist/types/jwe/*.d.ts",
112
+ "default": "./dist/webapi/jwe/*.js"
177
113
  },
178
114
  "./errors": {
179
115
  "types": "./dist/types/util/errors.d.ts",
@@ -1,22 +0,0 @@
1
- export function encodeBase64(input) {
2
- if (Uint8Array.prototype.toBase64) {
3
- return input.toBase64();
4
- }
5
- const CHUNK_SIZE = 0x8000;
6
- const arr = [];
7
- for (let i = 0; i < input.length; i += CHUNK_SIZE) {
8
- arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
9
- }
10
- return btoa(arr.join(''));
11
- }
12
- export function decodeBase64(encoded) {
13
- if (Uint8Array.fromBase64) {
14
- return Uint8Array.fromBase64(encoded);
15
- }
16
- const binary = atob(encoded);
17
- const bytes = new Uint8Array(binary.length);
18
- for (let i = 0; i < binary.length; i++) {
19
- bytes[i] = binary.charCodeAt(i);
20
- }
21
- return bytes;
22
- }
@@ -1,28 +0,0 @@
1
- const unusable = (name, prop = 'algorithm.name') => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
2
- export function checkUsage(key, usage) {
3
- if (usage && !key.usages.includes(usage)) {
4
- throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
5
- }
6
- }
7
- export function checkModulusLength(alg, key) {
8
- const { modulusLength } = key.algorithm;
9
- if (typeof modulusLength !== 'number' || modulusLength < 2048) {
10
- throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
11
- }
12
- }
13
- export function checkCryptoKey(key, expected, usage) {
14
- const algorithm = key.algorithm;
15
- if (algorithm.name !== expected.name) {
16
- throw unusable(expected.name);
17
- }
18
- if (expected.hash && algorithm.hash?.name !== expected.hash) {
19
- throw unusable(expected.hash, 'algorithm.hash');
20
- }
21
- if (expected.namedCurve && algorithm.namedCurve !== expected.namedCurve) {
22
- throw unusable(expected.namedCurve, 'algorithm.namedCurve');
23
- }
24
- if (expected.length !== undefined && algorithm.length !== expected.length) {
25
- throw unusable(expected.length, 'algorithm.length');
26
- }
27
- checkUsage(key, usage);
28
- }
@@ -1,42 +0,0 @@
1
- import { decode } from '../util/base64url.js';
2
- import { encode, strictDecoder } from './buffer_utils.js';
3
- import { isObject } from './type_checks.js';
4
- export const unprotected = Symbol();
5
- export function assertNotSet(value, name) {
6
- if (value !== undefined) {
7
- throw new TypeError(`${name} can only be called once`);
8
- }
9
- }
10
- export function decodeBase64url(value, label, ErrorClass) {
11
- try {
12
- return decode(value);
13
- }
14
- catch {
15
- throw new ErrorClass(`Failed to base64url decode the ${label}`);
16
- }
17
- }
18
- export function encodeBase64url(value, label, ErrorClass) {
19
- try {
20
- return encode(value);
21
- }
22
- catch {
23
- throw new ErrorClass(`The ${label} is not a valid base64url string`);
24
- }
25
- }
26
- export async function digest(algorithm, data) {
27
- const subtleDigest = `SHA-${algorithm.slice(-3)}`;
28
- return new Uint8Array(await crypto.subtle.digest(subtleDigest, data));
29
- }
30
- export function parseJoseHeader(b64, ErrorClass, message) {
31
- let parsed;
32
- try {
33
- parsed = JSON.parse(strictDecoder.decode(decode(b64)));
34
- }
35
- catch {
36
- throw new ErrorClass(message);
37
- }
38
- if (!isObject(parsed)) {
39
- throw new ErrorClass(message);
40
- }
41
- return parsed;
42
- }
@@ -1,26 +0,0 @@
1
- function message(msg, actual, ...types) {
2
- if (types.length > 2) {
3
- const last = types.pop();
4
- msg += `one of type ${types.join(', ')}, or ${last}.`;
5
- }
6
- else if (types.length === 2) {
7
- msg += `one of type ${types[0]} or ${types[1]}.`;
8
- }
9
- else {
10
- msg += `of type ${types[0]}.`;
11
- }
12
- if (actual == null) {
13
- msg += ` Received ${actual}`;
14
- }
15
- else if (typeof actual === 'function' && actual.name) {
16
- msg += ` Received function ${actual.name}`;
17
- }
18
- else if (typeof actual === 'object' && actual != null) {
19
- if (actual.constructor?.name) {
20
- msg += ` Received an instance of ${actual.constructor.name}`;
21
- }
22
- }
23
- return msg;
24
- }
25
- export const invalidKeyInput = (actual, ...types) => message('Key must be ', actual, ...types);
26
- export const withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
@@ -1,17 +0,0 @@
1
- export function assertCryptoKey(key) {
2
- if (!isCryptoKey(key)) {
3
- throw new Error('CryptoKey instance expected');
4
- }
5
- }
6
- export const isCryptoKey = (key) => {
7
- if (key?.[Symbol.toStringTag] === 'CryptoKey')
8
- return true;
9
- try {
10
- return key instanceof CryptoKey;
11
- }
12
- catch {
13
- return false;
14
- }
15
- };
16
- export const isKeyObject = (key) => key?.[Symbol.toStringTag] === 'KeyObject';
17
- export const isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
@@ -1,20 +0,0 @@
1
- export function snapshotJwk(jwk) {
2
- return { __proto__: null, ...jwk };
3
- }
4
- export function normalizeJwk(jwk) {
5
- const normalized = snapshotJwk(jwk);
6
- if (normalized.ext !== undefined && typeof normalized.ext !== 'boolean') {
7
- throw new TypeError('"ext" (Extractable) Parameter must be a boolean');
8
- }
9
- if (normalized.key_ops !== undefined) {
10
- const value = normalized.key_ops;
11
- const keyOps = Array.isArray(value) ? [...value] : undefined;
12
- if (!keyOps ||
13
- keyOps.some((operation) => typeof operation !== 'string') ||
14
- new Set(keyOps).size !== keyOps.length) {
15
- throw new TypeError('"key_ops" (Key Operations) Parameter must be an array of unique strings');
16
- }
17
- normalized.key_ops = keyOps;
18
- }
19
- return normalized;
20
- }
@@ -1,17 +0,0 @@
1
- import { JOSENotSupported } from '../util/errors.js';
2
- export async function jwkToKey(entry, jwk) {
3
- if (jwk.kty === 'RSA' && 'oth' in jwk && jwk.oth !== undefined) {
4
- throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
5
- }
6
- if (!entry.kty.includes(jwk.kty)) {
7
- throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
8
- }
9
- const algorithm = entry.resolve?.({ kty: jwk.kty, crv: jwk.crv }) ?? entry.subtle;
10
- const isPrivate = !!(jwk.d || jwk.priv);
11
- const keyData = { ...jwk };
12
- if (keyData.kty !== 'AKP') {
13
- delete keyData.alg;
14
- }
15
- delete keyData.use;
16
- return crypto.subtle.importKey('jwk', keyData, algorithm, jwk.ext ?? !isPrivate, jwk.key_ops ?? entry.usages[isPrivate ? 1 : 0]);
17
- }
@@ -1,6 +0,0 @@
1
- export function validateExtractableOption(extractable) {
2
- if (extractable !== undefined && typeof extractable !== 'boolean') {
3
- throw new TypeError('"extractable" option must be a boolean');
4
- }
5
- return extractable;
6
- }