repocairn 0.1.2 → 0.1.4

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 (233) hide show
  1. package/README.md +13 -2
  2. package/dist/graphify-source.d.ts +17 -0
  3. package/dist/graphify-source.js +87 -0
  4. package/dist/graphify-source.js.map +1 -0
  5. package/dist/index-command.js +3 -1
  6. package/dist/index-command.js.map +1 -1
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.js +1 -0
  9. package/dist/index.js.map +1 -1
  10. package/dist/indexer.d.ts +1 -0
  11. package/dist/indexer.js +2 -1
  12. package/dist/indexer.js.map +1 -1
  13. package/dist/signals.d.ts +13 -0
  14. package/dist/signals.js +84 -0
  15. package/dist/signals.js.map +1 -0
  16. package/dist/tree-sitter-extract.js +134 -1
  17. package/dist/tree-sitter-extract.js.map +1 -1
  18. package/node_modules/body-parser/node_modules/content-type/README.md +2 -0
  19. package/node_modules/body-parser/node_modules/content-type/dist/index.d.ts +20 -0
  20. package/node_modules/body-parser/node_modules/content-type/dist/index.js +20 -14
  21. package/node_modules/body-parser/node_modules/content-type/dist/index.js.map +1 -1
  22. package/node_modules/body-parser/node_modules/content-type/package.json +1 -1
  23. package/node_modules/eventsource-parser/dist/index.cjs +2 -2
  24. package/node_modules/eventsource-parser/dist/index.cjs.map +1 -1
  25. package/node_modules/eventsource-parser/dist/index.js +2 -2
  26. package/node_modules/eventsource-parser/dist/index.js.map +1 -1
  27. package/node_modules/eventsource-parser/package.json +1 -1
  28. package/node_modules/eventsource-parser/src/parse.ts +4 -2
  29. package/node_modules/express-rate-limit/dist/index.cjs +6 -1
  30. package/node_modules/express-rate-limit/dist/index.mjs +6 -1
  31. package/node_modules/express-rate-limit/package.json +6 -6
  32. package/node_modules/fast-uri/index.js +37 -1
  33. package/node_modules/fast-uri/package.json +1 -1
  34. package/node_modules/fast-uri/test/security.test.js +136 -0
  35. package/node_modules/hono/dist/cjs/client/client.js +3 -3
  36. package/node_modules/hono/dist/cjs/client/utils.js +1 -1
  37. package/node_modules/hono/dist/cjs/context.js +32 -13
  38. package/node_modules/hono/dist/cjs/helper/proxy/index.js +4 -0
  39. package/node_modules/hono/dist/cjs/hono-base.js +3 -2
  40. package/node_modules/hono/dist/cjs/jsx/base.js +27 -23
  41. package/node_modules/hono/dist/cjs/jsx/hooks/index.js +16 -13
  42. package/node_modules/hono/dist/cjs/jsx/intrinsic-element/components.js +1 -1
  43. package/node_modules/hono/dist/cjs/middleware/cache/index.js +103 -8
  44. package/node_modules/hono/dist/cjs/middleware/compress/index.js +5 -0
  45. package/node_modules/hono/dist/cjs/middleware/cors/index.js +17 -14
  46. package/node_modules/hono/dist/cjs/middleware/csrf/index.js +1 -1
  47. package/node_modules/hono/dist/cjs/middleware/etag/digest.js +47 -1
  48. package/node_modules/hono/dist/cjs/middleware/etag/index.js +6 -3
  49. package/node_modules/hono/dist/cjs/middleware/jwk/jwk.js +9 -4
  50. package/node_modules/hono/dist/cjs/middleware/jwt/jwt.js +9 -4
  51. package/node_modules/hono/dist/cjs/middleware/language/language.js +10 -6
  52. package/node_modules/hono/dist/cjs/middleware/method-not-allowed/index.js +90 -0
  53. package/node_modules/hono/dist/cjs/middleware/pretty-json/index.js +3 -1
  54. package/node_modules/hono/dist/cjs/middleware/secure-headers/secure-headers.js +6 -3
  55. package/node_modules/hono/dist/cjs/request.js +6 -8
  56. package/node_modules/hono/dist/cjs/router/linear-router/router.js +7 -2
  57. package/node_modules/hono/dist/cjs/router/pattern-router/router.js +3 -9
  58. package/node_modules/hono/dist/cjs/router/reg-exp-router/node.js +55 -56
  59. package/node_modules/hono/dist/cjs/router/reg-exp-router/router.js +64 -85
  60. package/node_modules/hono/dist/cjs/router/reg-exp-router/trie.js +13 -5
  61. package/node_modules/hono/dist/cjs/router/trie-router/node.js +44 -68
  62. package/node_modules/hono/dist/cjs/router/trie-router/router.js +3 -11
  63. package/node_modules/hono/dist/cjs/router.js +1 -1
  64. package/node_modules/hono/dist/cjs/utils/cookie.js +3 -2
  65. package/node_modules/hono/dist/cjs/utils/ipaddr.js +5 -3
  66. package/node_modules/hono/dist/cjs/utils/stream.js +5 -2
  67. package/node_modules/hono/dist/cjs/utils/url.js +9 -9
  68. package/node_modules/hono/dist/client/client.js +3 -3
  69. package/node_modules/hono/dist/client/utils.js +1 -1
  70. package/node_modules/hono/dist/context.js +32 -13
  71. package/node_modules/hono/dist/helper/proxy/index.js +4 -0
  72. package/node_modules/hono/dist/hono-base.js +3 -2
  73. package/node_modules/hono/dist/jsx/base.js +27 -23
  74. package/node_modules/hono/dist/jsx/hooks/index.js +16 -13
  75. package/node_modules/hono/dist/jsx/intrinsic-element/components.js +1 -1
  76. package/node_modules/hono/dist/middleware/cache/index.js +103 -8
  77. package/node_modules/hono/dist/middleware/compress/index.js +5 -0
  78. package/node_modules/hono/dist/middleware/cors/index.js +17 -14
  79. package/node_modules/hono/dist/middleware/csrf/index.js +1 -1
  80. package/node_modules/hono/dist/middleware/etag/digest.js +47 -1
  81. package/node_modules/hono/dist/middleware/etag/index.js +6 -3
  82. package/node_modules/hono/dist/middleware/jwk/jwk.js +9 -4
  83. package/node_modules/hono/dist/middleware/jwt/jwt.js +9 -4
  84. package/node_modules/hono/dist/middleware/language/language.js +10 -6
  85. package/node_modules/hono/dist/middleware/method-not-allowed/index.js +68 -0
  86. package/node_modules/hono/dist/middleware/pretty-json/index.js +3 -1
  87. package/node_modules/hono/dist/middleware/secure-headers/secure-headers.js +6 -3
  88. package/node_modules/hono/dist/request.js +7 -9
  89. package/node_modules/hono/dist/router/linear-router/router.js +7 -2
  90. package/node_modules/hono/dist/router/pattern-router/router.js +3 -9
  91. package/node_modules/hono/dist/router/reg-exp-router/node.js +55 -56
  92. package/node_modules/hono/dist/router/reg-exp-router/router.js +64 -85
  93. package/node_modules/hono/dist/router/reg-exp-router/trie.js +13 -5
  94. package/node_modules/hono/dist/router/trie-router/node.js +44 -68
  95. package/node_modules/hono/dist/router/trie-router/router.js +3 -11
  96. package/node_modules/hono/dist/router.js +1 -1
  97. package/node_modules/hono/dist/types/client/types.d.ts +1 -1
  98. package/node_modules/hono/dist/types/context.d.ts +4 -0
  99. package/node_modules/hono/dist/types/hono-base.d.ts +4 -3
  100. package/node_modules/hono/dist/types/jsx/base.d.ts +4 -2
  101. package/node_modules/hono/dist/types/jsx/dom/index.d.ts +5 -5
  102. package/node_modules/hono/dist/types/jsx/dom/intrinsic-element/components.d.ts +2 -2
  103. package/node_modules/hono/dist/types/jsx/dom/server.d.ts +5 -5
  104. package/node_modules/hono/dist/types/jsx/hooks/index.d.ts +8 -6
  105. package/node_modules/hono/dist/types/jsx/index.d.ts +5 -5
  106. package/node_modules/hono/dist/types/middleware/cache/index.d.ts +6 -4
  107. package/node_modules/hono/dist/types/middleware/cors/index.d.ts +1 -1
  108. package/node_modules/hono/dist/types/middleware/jsx-renderer/index.d.ts +2 -2
  109. package/node_modules/hono/dist/types/middleware/jwk/jwk.d.ts +2 -0
  110. package/node_modules/hono/dist/types/middleware/jwt/jwt.d.ts +2 -0
  111. package/node_modules/hono/dist/types/middleware/method-not-allowed/index.d.ts +49 -0
  112. package/node_modules/hono/dist/types/middleware/secure-headers/permissions-policy.d.ts +3 -3
  113. package/node_modules/hono/dist/types/router/reg-exp-router/node.d.ts +1 -1
  114. package/node_modules/hono/dist/types/router/reg-exp-router/trie.d.ts +2 -1
  115. package/node_modules/hono/dist/types/router/trie-router/node.d.ts +1 -2
  116. package/node_modules/hono/dist/types/router/trie-router/router.d.ts +0 -1
  117. package/node_modules/hono/dist/types/router.d.ts +1 -1
  118. package/node_modules/hono/dist/types/utils/headers.d.ts +2 -2
  119. package/node_modules/hono/dist/types/utils/url.d.ts +1 -0
  120. package/node_modules/hono/dist/utils/cookie.js +4 -3
  121. package/node_modules/hono/dist/utils/ipaddr.js +5 -3
  122. package/node_modules/hono/dist/utils/stream.js +5 -2
  123. package/node_modules/hono/dist/utils/url.js +7 -8
  124. package/node_modules/hono/package.json +10 -3
  125. package/node_modules/ip-address/README.md +163 -149
  126. package/node_modules/ip-address/dist/address-error.d.ts +11 -0
  127. package/node_modules/ip-address/dist/address-error.js.map +1 -1
  128. package/node_modules/ip-address/dist/common.d.ts +6 -0
  129. package/node_modules/ip-address/dist/common.js +17 -1
  130. package/node_modules/ip-address/dist/common.js.map +1 -1
  131. package/node_modules/ip-address/dist/ipv4.d.ts +22 -6
  132. package/node_modules/ip-address/dist/ipv4.js +25 -18
  133. package/node_modules/ip-address/dist/ipv4.js.map +1 -1
  134. package/node_modules/ip-address/dist/ipv6.d.ts +19 -5
  135. package/node_modules/ip-address/dist/ipv6.js +61 -33
  136. package/node_modules/ip-address/dist/ipv6.js.map +1 -1
  137. package/node_modules/ip-address/package.json +5 -3
  138. package/node_modules/jose/README.md +13 -13
  139. package/node_modules/jose/dist/types/index.d.ts +6 -5
  140. package/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +17 -11
  141. package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +8 -19
  142. package/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +17 -11
  143. package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +8 -19
  144. package/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +18 -13
  145. package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +21 -21
  146. package/node_modules/jose/dist/types/jwk/embedded.d.ts +8 -12
  147. package/node_modules/jose/dist/types/jwk/thumbprint.d.ts +0 -15
  148. package/node_modules/jose/dist/types/jwks/local.d.ts +12 -21
  149. package/node_modules/jose/dist/types/jwks/remote.d.ts +34 -165
  150. package/node_modules/jose/dist/types/jws/compact/sign.d.ts +2 -13
  151. package/node_modules/jose/dist/types/jws/compact/verify.d.ts +17 -13
  152. package/node_modules/jose/dist/types/jws/flattened/sign.d.ts +2 -13
  153. package/node_modules/jose/dist/types/jws/flattened/verify.d.ts +17 -13
  154. package/node_modules/jose/dist/types/jws/general/sign.d.ts +16 -17
  155. package/node_modules/jose/dist/types/jws/general/verify.d.ts +18 -15
  156. package/node_modules/jose/dist/types/jwt/decrypt.d.ts +17 -11
  157. package/node_modules/jose/dist/types/jwt/encrypt.d.ts +11 -34
  158. package/node_modules/jose/dist/types/jwt/sign.d.ts +2 -13
  159. package/node_modules/jose/dist/types/jwt/unsecured.d.ts +4 -13
  160. package/node_modules/jose/dist/types/jwt/verify.d.ts +14 -13
  161. package/node_modules/jose/dist/types/key/export.d.ts +0 -14
  162. package/node_modules/jose/dist/types/key/generate_key_pair.d.ts +7 -14
  163. package/node_modules/jose/dist/types/key/generate_secret.d.ts +16 -14
  164. package/node_modules/jose/dist/types/key/import.d.ts +18 -28
  165. package/node_modules/jose/dist/types/types.d.ts +243 -224
  166. package/node_modules/jose/dist/types/util/base64url.d.ts +11 -4
  167. package/node_modules/jose/dist/types/util/decode_jwt.d.ts +1 -9
  168. package/node_modules/jose/dist/types/util/decode_protected_header.d.ts +0 -8
  169. package/node_modules/jose/dist/types/util/errors.d.ts +128 -121
  170. package/node_modules/jose/dist/webapi/jwe/compact/decrypt.js +4 -22
  171. package/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +5 -153
  172. package/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +16 -111
  173. package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +23 -3
  174. package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +70 -82
  175. package/node_modules/jose/dist/webapi/jwk/embedded.js +5 -3
  176. package/node_modules/jose/dist/webapi/jwks/local.js +32 -73
  177. package/node_modules/jose/dist/webapi/jwks/remote.js +19 -28
  178. package/node_modules/jose/dist/webapi/jws/compact/sign.js +5 -2
  179. package/node_modules/jose/dist/webapi/jws/compact/verify.js +4 -16
  180. package/node_modules/jose/dist/webapi/jws/flattened/sign.js +7 -65
  181. package/node_modules/jose/dist/webapi/jws/flattened/verify.js +3 -89
  182. package/node_modules/jose/dist/webapi/jws/general/sign.js +19 -15
  183. package/node_modules/jose/dist/webapi/jws/general/verify.js +29 -9
  184. package/node_modules/jose/dist/webapi/jwt/decrypt.js +5 -5
  185. package/node_modules/jose/dist/webapi/jwt/sign.js +2 -3
  186. package/node_modules/jose/dist/webapi/jwt/unsecured.js +4 -3
  187. package/node_modules/jose/dist/webapi/jwt/verify.js +6 -6
  188. package/node_modules/jose/dist/webapi/key/export.js +37 -4
  189. package/node_modules/jose/dist/webapi/key/generate_key_pair.js +33 -82
  190. package/node_modules/jose/dist/webapi/key/generate_secret.js +2 -2
  191. package/node_modules/jose/dist/webapi/key/import.js +8 -8
  192. package/node_modules/jose/dist/webapi/lib/asn1.js +53 -122
  193. package/node_modules/jose/dist/webapi/lib/buffer_utils.js +1 -0
  194. package/node_modules/jose/dist/webapi/lib/content_encryption.js +34 -109
  195. package/node_modules/jose/dist/webapi/lib/crypto_key.js +18 -126
  196. package/node_modules/jose/dist/webapi/lib/helpers.js +23 -0
  197. package/node_modules/jose/dist/webapi/lib/invalid_key_input.js +0 -1
  198. package/node_modules/jose/dist/webapi/lib/jwe_algorithms.js +107 -0
  199. package/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +186 -0
  200. package/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +114 -0
  201. package/node_modules/jose/dist/webapi/lib/jwk_to_key.js +8 -98
  202. package/node_modules/jose/dist/webapi/lib/jws_algorithms.js +73 -0
  203. package/node_modules/jose/dist/webapi/lib/jws_sign.js +74 -0
  204. package/node_modules/jose/dist/webapi/lib/jws_verify.js +107 -0
  205. package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +68 -109
  206. package/node_modules/jose/dist/webapi/lib/key.js +132 -0
  207. package/node_modules/jose/dist/webapi/lib/key_algorithm.js +10 -0
  208. package/node_modules/jose/dist/webapi/lib/key_descriptor.js +7 -0
  209. package/node_modules/jose/dist/webapi/lib/key_management.js +162 -92
  210. package/node_modules/jose/dist/webapi/lib/options.js +48 -0
  211. package/node_modules/jose/dist/webapi/lib/signing.js +14 -56
  212. package/node_modules/jose/dist/webapi/lib/type_checks.js +13 -18
  213. package/node_modules/jose/dist/webapi/util/base64url.js +13 -4
  214. package/node_modules/jose/dist/webapi/util/decode_jwt.js +2 -2
  215. package/node_modules/jose/dist/webapi/util/decode_protected_header.js +5 -15
  216. package/node_modules/jose/dist/webapi/util/errors.js +1 -1
  217. package/node_modules/jose/package.json +2 -4
  218. package/node_modules/type-is/node_modules/content-type/README.md +2 -0
  219. package/node_modules/type-is/node_modules/content-type/dist/index.d.ts +20 -0
  220. package/node_modules/type-is/node_modules/content-type/dist/index.js +20 -14
  221. package/node_modules/type-is/node_modules/content-type/dist/index.js.map +1 -1
  222. package/node_modules/type-is/node_modules/content-type/package.json +1 -1
  223. package/package.json +5 -3
  224. package/node_modules/jose/dist/webapi/lib/aesgcmkw.js +0 -15
  225. package/node_modules/jose/dist/webapi/lib/aeskw.js +0 -25
  226. package/node_modules/jose/dist/webapi/lib/check_key_type.js +0 -122
  227. package/node_modules/jose/dist/webapi/lib/ecdhes.js +0 -52
  228. package/node_modules/jose/dist/webapi/lib/key_to_jwk.js +0 -34
  229. package/node_modules/jose/dist/webapi/lib/normalize_key.js +0 -166
  230. package/node_modules/jose/dist/webapi/lib/pbes2kw.js +0 -42
  231. package/node_modules/jose/dist/webapi/lib/rsaes.js +0 -24
  232. package/node_modules/jose/dist/webapi/lib/validate_algorithms.js +0 -10
  233. package/node_modules/jose/dist/webapi/lib/validate_crit.js +0 -33
@@ -1,166 +0,0 @@
1
- import { isJWK } from './type_checks.js';
2
- import { decode } from '../util/base64url.js';
3
- import { jwkToKey } from './jwk_to_key.js';
4
- import { isCryptoKey, isKeyObject } from './is_key_like.js';
5
- const unusableForAlg = 'given KeyObject instance cannot be used for this algorithm';
6
- let cache;
7
- const handleJWK = async (key, jwk, alg, freeze = false) => {
8
- cache ||= new WeakMap();
9
- let cached = cache.get(key);
10
- if (cached?.[alg]) {
11
- return cached[alg];
12
- }
13
- const cryptoKey = await jwkToKey({ ...jwk, alg });
14
- if (freeze)
15
- Object.freeze(key);
16
- if (!cached) {
17
- cache.set(key, { [alg]: cryptoKey });
18
- }
19
- else {
20
- cached[alg] = cryptoKey;
21
- }
22
- return cryptoKey;
23
- };
24
- const handleKeyObject = (keyObject, alg) => {
25
- cache ||= new WeakMap();
26
- let cached = cache.get(keyObject);
27
- if (cached?.[alg]) {
28
- return cached[alg];
29
- }
30
- const isPublic = keyObject.type === 'public';
31
- const extractable = isPublic ? true : false;
32
- let cryptoKey;
33
- if (keyObject.asymmetricKeyType === 'x25519') {
34
- switch (alg) {
35
- case 'ECDH-ES':
36
- case 'ECDH-ES+A128KW':
37
- case 'ECDH-ES+A192KW':
38
- case 'ECDH-ES+A256KW':
39
- break;
40
- default:
41
- throw new TypeError(unusableForAlg);
42
- }
43
- cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ['deriveBits']);
44
- }
45
- if (keyObject.asymmetricKeyType === 'ed25519') {
46
- if (alg !== 'EdDSA' && alg !== 'Ed25519') {
47
- throw new TypeError(unusableForAlg);
48
- }
49
- cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
50
- isPublic ? 'verify' : 'sign',
51
- ]);
52
- }
53
- switch (keyObject.asymmetricKeyType) {
54
- case 'ml-dsa-44':
55
- case 'ml-dsa-65':
56
- case 'ml-dsa-87': {
57
- if (alg !== keyObject.asymmetricKeyType.toUpperCase()) {
58
- throw new TypeError(unusableForAlg);
59
- }
60
- cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
61
- isPublic ? 'verify' : 'sign',
62
- ]);
63
- }
64
- }
65
- if (keyObject.asymmetricKeyType === 'rsa') {
66
- let hash;
67
- switch (alg) {
68
- case 'RSA-OAEP':
69
- hash = 'SHA-1';
70
- break;
71
- case 'RS256':
72
- case 'PS256':
73
- case 'RSA-OAEP-256':
74
- hash = 'SHA-256';
75
- break;
76
- case 'RS384':
77
- case 'PS384':
78
- case 'RSA-OAEP-384':
79
- hash = 'SHA-384';
80
- break;
81
- case 'RS512':
82
- case 'PS512':
83
- case 'RSA-OAEP-512':
84
- hash = 'SHA-512';
85
- break;
86
- default:
87
- throw new TypeError(unusableForAlg);
88
- }
89
- if (alg.startsWith('RSA-OAEP')) {
90
- return keyObject.toCryptoKey({
91
- name: 'RSA-OAEP',
92
- hash,
93
- }, extractable, isPublic ? ['encrypt'] : ['decrypt']);
94
- }
95
- cryptoKey = keyObject.toCryptoKey({
96
- name: alg.startsWith('PS') ? 'RSA-PSS' : 'RSASSA-PKCS1-v1_5',
97
- hash,
98
- }, extractable, [isPublic ? 'verify' : 'sign']);
99
- }
100
- if (keyObject.asymmetricKeyType === 'ec') {
101
- const nist = new Map([
102
- ['prime256v1', 'P-256'],
103
- ['secp384r1', 'P-384'],
104
- ['secp521r1', 'P-521'],
105
- ]);
106
- const namedCurve = nist.get(keyObject.asymmetricKeyDetails?.namedCurve);
107
- if (!namedCurve) {
108
- throw new TypeError(unusableForAlg);
109
- }
110
- const expectedCurve = { ES256: 'P-256', ES384: 'P-384', ES512: 'P-521' };
111
- if (expectedCurve[alg] && namedCurve === expectedCurve[alg]) {
112
- cryptoKey = keyObject.toCryptoKey({
113
- name: 'ECDSA',
114
- namedCurve,
115
- }, extractable, [isPublic ? 'verify' : 'sign']);
116
- }
117
- if (alg.startsWith('ECDH-ES')) {
118
- cryptoKey = keyObject.toCryptoKey({
119
- name: 'ECDH',
120
- namedCurve,
121
- }, extractable, isPublic ? [] : ['deriveBits']);
122
- }
123
- }
124
- if (!cryptoKey) {
125
- throw new TypeError(unusableForAlg);
126
- }
127
- if (!cached) {
128
- cache.set(keyObject, { [alg]: cryptoKey });
129
- }
130
- else {
131
- cached[alg] = cryptoKey;
132
- }
133
- return cryptoKey;
134
- };
135
- export async function normalizeKey(key, alg) {
136
- if (key instanceof Uint8Array) {
137
- return key;
138
- }
139
- if (isCryptoKey(key)) {
140
- return key;
141
- }
142
- if (isKeyObject(key)) {
143
- if (key.type === 'secret') {
144
- return key.export();
145
- }
146
- if ('toCryptoKey' in key && typeof key.toCryptoKey === 'function') {
147
- try {
148
- return handleKeyObject(key, alg);
149
- }
150
- catch (err) {
151
- if (err instanceof TypeError) {
152
- throw err;
153
- }
154
- }
155
- }
156
- let jwk = key.export({ format: 'jwk' });
157
- return handleJWK(key, jwk, alg);
158
- }
159
- if (isJWK(key)) {
160
- if (key.k) {
161
- return decode(key.k);
162
- }
163
- return handleJWK(key, key, alg, true);
164
- }
165
- throw new Error('unreachable');
166
- }
@@ -1,42 +0,0 @@
1
- import { encode as b64u } from '../util/base64url.js';
2
- import * as aeskw from './aeskw.js';
3
- import { checkEncCryptoKey } from './crypto_key.js';
4
- import { concat, encode } from './buffer_utils.js';
5
- import { JWEInvalid } from '../util/errors.js';
6
- function getCryptoKey(key, alg) {
7
- if (key instanceof Uint8Array) {
8
- return crypto.subtle.importKey('raw', key, 'PBKDF2', false, [
9
- 'deriveBits',
10
- ]);
11
- }
12
- checkEncCryptoKey(key, alg, 'deriveBits');
13
- return key;
14
- }
15
- const concatSalt = (alg, p2sInput) => concat(encode(alg), Uint8Array.of(0x00), p2sInput);
16
- async function deriveKey(p2s, alg, p2c, key) {
17
- if (!(p2s instanceof Uint8Array) || p2s.length < 8) {
18
- throw new JWEInvalid('PBES2 Salt Input must be 8 or more octets');
19
- }
20
- if (!Number.isSafeInteger(p2c) || Math.sign(p2c) !== 1) {
21
- throw new JWEInvalid('PBES2 Count Input must be a positive integer');
22
- }
23
- const salt = concatSalt(alg, p2s);
24
- const keylen = parseInt(alg.slice(13, 16), 10);
25
- const subtleAlg = {
26
- hash: `SHA-${alg.slice(8, 11)}`,
27
- iterations: p2c,
28
- name: 'PBKDF2',
29
- salt,
30
- };
31
- const cryptoKey = await getCryptoKey(key, alg);
32
- return new Uint8Array(await crypto.subtle.deriveBits(subtleAlg, cryptoKey, keylen));
33
- }
34
- export async function wrap(alg, key, cek, p2c = 2048, p2s = crypto.getRandomValues(new Uint8Array(16))) {
35
- const derived = await deriveKey(p2s, alg, p2c, key);
36
- const encryptedKey = await aeskw.wrap(alg.slice(-6), derived, cek);
37
- return { encryptedKey, p2c, p2s: b64u(p2s) };
38
- }
39
- export async function unwrap(alg, key, encryptedKey, p2c, p2s) {
40
- const derived = await deriveKey(p2s, alg, p2c, key);
41
- return aeskw.unwrap(alg.slice(-6), derived, encryptedKey);
42
- }
@@ -1,24 +0,0 @@
1
- import { checkEncCryptoKey } from './crypto_key.js';
2
- import { checkKeyLength } from './signing.js';
3
- import { JOSENotSupported } from '../util/errors.js';
4
- const subtleAlgorithm = (alg) => {
5
- switch (alg) {
6
- case 'RSA-OAEP':
7
- case 'RSA-OAEP-256':
8
- case 'RSA-OAEP-384':
9
- case 'RSA-OAEP-512':
10
- return 'RSA-OAEP';
11
- default:
12
- throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
13
- }
14
- };
15
- export async function encrypt(alg, key, cek) {
16
- checkEncCryptoKey(key, alg, 'encrypt');
17
- checkKeyLength(alg, key);
18
- return new Uint8Array(await crypto.subtle.encrypt(subtleAlgorithm(alg), key, cek));
19
- }
20
- export async function decrypt(alg, key, encryptedKey) {
21
- checkEncCryptoKey(key, alg, 'decrypt');
22
- checkKeyLength(alg, key);
23
- return new Uint8Array(await crypto.subtle.decrypt(subtleAlgorithm(alg), key, encryptedKey));
24
- }
@@ -1,10 +0,0 @@
1
- export function validateAlgorithms(option, algorithms) {
2
- if (algorithms !== undefined &&
3
- (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== 'string'))) {
4
- throw new TypeError(`"${option}" option must be an array of strings`);
5
- }
6
- if (!algorithms) {
7
- return undefined;
8
- }
9
- return new Set(algorithms);
10
- }
@@ -1,33 +0,0 @@
1
- import { JOSENotSupported, JWEInvalid, JWSInvalid } from '../util/errors.js';
2
- export function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
3
- if (joseHeader.crit !== undefined && protectedHeader?.crit === undefined) {
4
- throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
5
- }
6
- if (!protectedHeader || protectedHeader.crit === undefined) {
7
- return new Set();
8
- }
9
- if (!Array.isArray(protectedHeader.crit) ||
10
- protectedHeader.crit.length === 0 ||
11
- protectedHeader.crit.some((input) => typeof input !== 'string' || input.length === 0)) {
12
- throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
13
- }
14
- let recognized;
15
- if (recognizedOption !== undefined) {
16
- recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
17
- }
18
- else {
19
- recognized = recognizedDefault;
20
- }
21
- for (const parameter of protectedHeader.crit) {
22
- if (!recognized.has(parameter)) {
23
- throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
24
- }
25
- if (joseHeader[parameter] === undefined) {
26
- throw new Err(`Extension Header Parameter "${parameter}" is missing`);
27
- }
28
- if (recognized.get(parameter) && protectedHeader[parameter] === undefined) {
29
- throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
30
- }
31
- }
32
- return new Set(protectedHeader.crit);
33
- }