@zuplo/cli 7.4.4 → 7.4.6

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 (229) hide show
  1. package/dist/common/settings.d.ts +1 -0
  2. package/dist/common/settings.d.ts.map +1 -1
  3. package/dist/common/settings.js +3 -0
  4. package/dist/common/settings.js.map +1 -1
  5. package/dist/deploy/classify-build-probe.d.ts +14 -0
  6. package/dist/deploy/classify-build-probe.d.ts.map +1 -0
  7. package/dist/deploy/classify-build-probe.js +35 -0
  8. package/dist/deploy/classify-build-probe.js.map +1 -0
  9. package/dist/deploy/classify-build-probe.test.d.ts +2 -0
  10. package/dist/deploy/classify-build-probe.test.d.ts.map +1 -0
  11. package/dist/deploy/classify-build-probe.test.js +51 -0
  12. package/dist/deploy/classify-build-probe.test.js.map +1 -0
  13. package/dist/deploy/handler.js +20 -5
  14. package/dist/deploy/handler.js.map +1 -1
  15. package/dist/deploy/poll-deployment.d.ts +8 -4
  16. package/dist/deploy/poll-deployment.d.ts.map +1 -1
  17. package/dist/deploy/poll-deployment.js +32 -4
  18. package/dist/deploy/poll-deployment.js.map +1 -1
  19. package/dist/deploy/poll-deployment.test.d.ts +2 -0
  20. package/dist/deploy/poll-deployment.test.d.ts.map +1 -0
  21. package/dist/deploy/poll-deployment.test.js +158 -0
  22. package/dist/deploy/poll-deployment.test.js.map +1 -0
  23. package/dist/tsconfig.tsbuildinfo +1 -1
  24. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/jwks/remote.d.ts +4 -4
  25. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/jws/general/verify.d.ts +3 -3
  26. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/jwt/encrypt.d.ts +8 -14
  27. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/jwt/sign.d.ts +8 -14
  28. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/types/jwt/unsecured.d.ts +9 -15
  29. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jwe/compact/encrypt.js +30 -8
  30. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +8 -4
  31. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +6 -13
  32. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jwe/general/decrypt.js +19 -19
  33. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jwe/general/encrypt.js +27 -20
  34. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jwk/embedded.js +15 -1
  35. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jwk/thumbprint.js +11 -5
  36. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jwks/local.js +45 -53
  37. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jwks/remote.js +82 -103
  38. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jws/compact/sign.js +10 -9
  39. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jws/flattened/sign.js +2 -1
  40. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jws/flattened/verify.js +8 -7
  41. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jws/general/sign.js +5 -3
  42. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jws/general/verify.js +51 -21
  43. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jwt/decrypt.js +7 -9
  44. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jwt/encrypt.js +21 -50
  45. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jwt/sign.js +8 -41
  46. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/jwt/unsecured.js +21 -42
  47. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/key/generate_key_pair.js +6 -2
  48. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/key/generate_secret.js +7 -6
  49. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/key/import.js +16 -12
  50. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/asn1.js +7 -2
  51. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/content_encryption.js +7 -15
  52. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/deflate.js +8 -0
  53. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/helpers.js +1 -1
  54. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +85 -28
  55. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +40 -12
  56. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/jwk_metadata.js +20 -0
  57. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/jws_sign.js +47 -36
  58. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/jws_verify.js +77 -45
  59. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +82 -47
  60. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/key.js +24 -9
  61. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/key_management.js +10 -4
  62. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/key_options.js +6 -0
  63. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/options.js +26 -0
  64. package/node_modules/@modelcontextprotocol/client/node_modules/jose/dist/webapi/lib/type_checks.js +11 -13
  65. package/node_modules/@modelcontextprotocol/client/node_modules/jose/package.json +1 -1
  66. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwks/remote.d.ts +4 -4
  67. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/general/verify.d.ts +3 -3
  68. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/encrypt.d.ts +8 -14
  69. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/sign.d.ts +8 -14
  70. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/unsecured.d.ts +9 -15
  71. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/compact/encrypt.js +30 -8
  72. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +8 -4
  73. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +6 -13
  74. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/general/decrypt.js +19 -19
  75. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/general/encrypt.js +27 -20
  76. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwk/embedded.js +15 -1
  77. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwk/thumbprint.js +11 -5
  78. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwks/local.js +45 -53
  79. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwks/remote.js +82 -103
  80. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/compact/sign.js +10 -9
  81. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/flattened/sign.js +2 -1
  82. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/flattened/verify.js +8 -7
  83. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/general/sign.js +5 -3
  84. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/general/verify.js +51 -21
  85. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/decrypt.js +7 -9
  86. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/encrypt.js +21 -50
  87. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/sign.js +8 -41
  88. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/unsecured.js +21 -42
  89. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/key/generate_key_pair.js +6 -2
  90. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/key/generate_secret.js +7 -6
  91. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/key/import.js +16 -12
  92. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/asn1.js +7 -2
  93. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/content_encryption.js +7 -15
  94. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/deflate.js +8 -0
  95. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/helpers.js +1 -1
  96. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +85 -28
  97. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +40 -12
  98. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwk_metadata.js +20 -0
  99. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jws_sign.js +47 -36
  100. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jws_verify.js +77 -45
  101. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +82 -47
  102. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key.js +24 -9
  103. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key_management.js +10 -4
  104. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key_options.js +6 -0
  105. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/options.js +26 -0
  106. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/type_checks.js +11 -13
  107. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/package.json +1 -1
  108. package/node_modules/@posthog/core/dist/logs/index.js +1 -1
  109. package/node_modules/@posthog/core/dist/logs/index.mjs +1 -1
  110. package/node_modules/@posthog/core/dist/logs/logs-utils.d.ts +4 -13
  111. package/node_modules/@posthog/core/dist/logs/logs-utils.d.ts.map +1 -1
  112. package/node_modules/@posthog/core/dist/logs/logs-utils.js +160 -26
  113. package/node_modules/@posthog/core/dist/logs/logs-utils.mjs +160 -26
  114. package/node_modules/@posthog/core/dist/metrics/index.js +1 -1
  115. package/node_modules/@posthog/core/dist/metrics/index.mjs +1 -1
  116. package/node_modules/@posthog/core/dist/posthog-core-stateless.d.ts +12 -18
  117. package/node_modules/@posthog/core/dist/posthog-core-stateless.d.ts.map +1 -1
  118. package/node_modules/@posthog/core/dist/posthog-core-stateless.js +15 -47
  119. package/node_modules/@posthog/core/dist/posthog-core-stateless.mjs +15 -47
  120. package/node_modules/@posthog/core/dist/posthog-core.d.ts.map +1 -1
  121. package/node_modules/@posthog/core/dist/posthog-core.js +12 -7
  122. package/node_modules/@posthog/core/dist/posthog-core.mjs +12 -7
  123. package/node_modules/@posthog/core/dist/types.d.ts +4 -1
  124. package/node_modules/@posthog/core/dist/types.d.ts.map +1 -1
  125. package/node_modules/@posthog/core/dist/utils/index.d.ts +1 -1
  126. package/node_modules/@posthog/core/dist/utils/index.d.ts.map +1 -1
  127. package/node_modules/@posthog/core/dist/utils/index.js +14 -24
  128. package/node_modules/@posthog/core/dist/utils/index.mjs +2 -2
  129. package/node_modules/@posthog/core/dist/utils/json-utils.d.ts +15 -0
  130. package/node_modules/@posthog/core/dist/utils/json-utils.d.ts.map +1 -1
  131. package/node_modules/@posthog/core/dist/utils/json-utils.js +24 -0
  132. package/node_modules/@posthog/core/dist/utils/json-utils.mjs +1 -1
  133. package/node_modules/@posthog/core/package.json +2 -2
  134. package/node_modules/@posthog/core/src/logs/index.spec.ts +77 -0
  135. package/node_modules/@posthog/core/src/logs/index.ts +2 -2
  136. package/node_modules/@posthog/core/src/logs/logs-utils.spec.ts +314 -9
  137. package/node_modules/@posthog/core/src/logs/logs-utils.ts +215 -27
  138. package/node_modules/@posthog/core/src/metrics/index.spec.ts +15 -1
  139. package/node_modules/@posthog/core/src/metrics/index.ts +1 -1
  140. package/node_modules/@posthog/core/src/posthog-core-stateless.ts +40 -65
  141. package/node_modules/@posthog/core/src/posthog-core.ts +19 -12
  142. package/node_modules/@posthog/core/src/types.ts +3 -1
  143. package/node_modules/@posthog/core/src/utils/index.ts +3 -1
  144. package/node_modules/@posthog/core/src/utils/json-utils.ts +15 -8
  145. package/node_modules/@posthog/types/dist/capture-log.d.ts +10 -1
  146. package/node_modules/@posthog/types/dist/capture-log.d.ts.map +1 -1
  147. package/node_modules/@posthog/types/dist/index.d.ts +1 -1
  148. package/node_modules/@posthog/types/dist/index.d.ts.map +1 -1
  149. package/node_modules/@posthog/types/dist/posthog-config.d.ts +20 -5
  150. package/node_modules/@posthog/types/dist/posthog-config.d.ts.map +1 -1
  151. package/node_modules/@posthog/types/package.json +1 -1
  152. package/node_modules/@posthog/types/src/capture-log.ts +8 -1
  153. package/node_modules/@posthog/types/src/index.ts +1 -0
  154. package/node_modules/@posthog/types/src/posthog-config.ts +21 -5
  155. package/node_modules/@zuplo/core/customer.cli.minified.js +1 -1
  156. package/node_modules/@zuplo/core/index.minified.js +1 -1
  157. package/node_modules/@zuplo/core/package.json +1 -1
  158. package/node_modules/@zuplo/graphql/package.json +1 -1
  159. package/node_modules/@zuplo/openapi-tools/package.json +1 -1
  160. package/node_modules/@zuplo/otel/package.json +1 -1
  161. package/node_modules/@zuplo/runtime/out/esm/{chunk-IZE65N7D.js → chunk-CUK3VROF.js} +2 -2
  162. package/node_modules/@zuplo/runtime/out/esm/{chunk-4CDML74A.js → chunk-K4TBJG47.js} +2 -2
  163. package/node_modules/@zuplo/runtime/out/esm/{chunk-4VE55TG3.js → chunk-S4EBLGSU.js} +2 -2
  164. package/node_modules/@zuplo/runtime/out/esm/{chunk-4POCC75H.js → chunk-XF3IIUDX.js} +4 -4
  165. package/node_modules/@zuplo/runtime/out/esm/{chunk-4POCC75H.js.map → chunk-XF3IIUDX.js.map} +1 -1
  166. package/node_modules/@zuplo/runtime/out/esm/chunk-ZPOD3IK4.js +403 -0
  167. package/node_modules/@zuplo/runtime/out/esm/chunk-ZPOD3IK4.js.map +1 -0
  168. package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
  169. package/node_modules/@zuplo/runtime/out/esm/internal/index.js +1 -1
  170. package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +1 -1
  171. package/node_modules/@zuplo/runtime/out/esm/mocks/index.js +1 -1
  172. package/node_modules/@zuplo/runtime/out/esm/sdks/aws/index.js +1 -1
  173. package/node_modules/@zuplo/runtime/package.json +1 -1
  174. package/node_modules/fast-uri/index.js +201 -48
  175. package/node_modules/fast-uri/lib/schemes.js +9 -4
  176. package/node_modules/fast-uri/lib/utils.js +388 -91
  177. package/node_modules/fast-uri/package.json +1 -1
  178. package/node_modules/fast-uri/test/component-safe-serialization.test.js +105 -0
  179. package/node_modules/fast-uri/test/equal.test.js +31 -3
  180. package/node_modules/fast-uri/test/fixtures/uri-js-parse.json +2 -0
  181. package/node_modules/fast-uri/test/ipv6-canonical.test.js +34 -0
  182. package/node_modules/fast-uri/test/ipv6-validation.test.js +90 -0
  183. package/node_modules/fast-uri/test/malformed-percent.test.js +77 -0
  184. package/node_modules/fast-uri/test/malformed-urn.test.js +61 -0
  185. package/node_modules/fast-uri/test/parse.test.js +7 -3
  186. package/node_modules/fast-uri/test/query-fragment-normalization.test.js +33 -0
  187. package/node_modules/fast-uri/test/reserved-path-normalization.test.js +109 -0
  188. package/node_modules/fast-uri/test/scheme-validation.test.js +124 -0
  189. package/node_modules/fast-uri/test/security-normalization.test.js +101 -0
  190. package/node_modules/fast-uri/test/security.test.js +75 -3
  191. package/node_modules/fast-uri/test/urn-full-input.test.js +29 -0
  192. package/node_modules/fast-uri/test/websocket-query-preservation.test.js +24 -0
  193. package/node_modules/hono/dist/cjs/client/client.js +25 -11
  194. package/node_modules/hono/dist/cjs/client/utils.js +3 -0
  195. package/node_modules/hono/dist/cjs/helper/accepts/accepts.js +36 -2
  196. package/node_modules/hono/dist/cjs/jsx/dom/render.js +2 -0
  197. package/node_modules/hono/dist/cjs/middleware/etag/index.js +1 -1
  198. package/node_modules/hono/dist/cjs/request.js +8 -4
  199. package/node_modules/hono/dist/cjs/router/reg-exp-router/node.js +10 -3
  200. package/node_modules/hono/dist/cjs/router/reg-exp-router/router.js +47 -83
  201. package/node_modules/hono/dist/cjs/router/reg-exp-router/trie.js +2 -1
  202. package/node_modules/hono/dist/cjs/router/trie-router/node.js +4 -3
  203. package/node_modules/hono/dist/cjs/router/utils.js +27 -0
  204. package/node_modules/hono/dist/cjs/utils/cookie.js +1 -1
  205. package/node_modules/hono/dist/cjs/utils/stream.js +7 -1
  206. package/node_modules/hono/dist/client/client.js +25 -11
  207. package/node_modules/hono/dist/client/utils.js +3 -0
  208. package/node_modules/hono/dist/helper/accepts/accepts.js +36 -2
  209. package/node_modules/hono/dist/jsx/dom/render.js +2 -0
  210. package/node_modules/hono/dist/middleware/etag/index.js +1 -1
  211. package/node_modules/hono/dist/request.js +8 -4
  212. package/node_modules/hono/dist/router/reg-exp-router/node.js +6 -2
  213. package/node_modules/hono/dist/router/reg-exp-router/router.js +53 -84
  214. package/node_modules/hono/dist/router/reg-exp-router/trie.js +2 -1
  215. package/node_modules/hono/dist/router/trie-router/node.js +4 -3
  216. package/node_modules/hono/dist/router/utils.js +5 -0
  217. package/node_modules/hono/dist/types/router/reg-exp-router/node.d.ts +3 -0
  218. package/node_modules/hono/dist/types/router/utils.d.ts +1 -0
  219. package/node_modules/hono/dist/utils/cookie.js +1 -1
  220. package/node_modules/hono/dist/utils/stream.js +7 -1
  221. package/node_modules/hono/package.json +1 -1
  222. package/package.json +11 -11
  223. package/node_modules/@zuplo/runtime/out/esm/chunk-4SX4HBWT.js +0 -409
  224. package/node_modules/@zuplo/runtime/out/esm/chunk-4SX4HBWT.js.map +0 -1
  225. /package/node_modules/@zuplo/runtime/out/esm/{chunk-IZE65N7D.js.map → chunk-CUK3VROF.js.map} +0 -0
  226. /package/node_modules/@zuplo/runtime/out/esm/{chunk-4CDML74A.js.map → chunk-K4TBJG47.js.map} +0 -0
  227. /package/node_modules/@zuplo/runtime/out/esm/{chunk-4VE55TG3.js.map → chunk-S4EBLGSU.js.map} +0 -0
  228. /package/node_modules/@zuplo/runtime/out/esm/{chunk-4POCC75H.js.LEGAL.txt → chunk-XF3IIUDX.js.LEGAL.txt} +0 -0
  229. /package/node_modules/@zuplo/runtime/out/esm/{chunk-4SX4HBWT.js.LEGAL.txt → chunk-ZPOD3IK4.js.LEGAL.txt} +0 -0
@@ -1,21 +1,22 @@
1
- import { FlattenedSign } from '../flattened/sign.js';
2
- import { unencodedPayload } from '../../lib/jws_sign.js';
1
+ import { createCompactSignature } from '../../lib/jws_sign.js';
2
+ import { assertNotSet } from '../../lib/helpers.js';
3
3
  export class CompactSign {
4
- #flattened;
4
+ #payload;
5
5
  #protectedHeader;
6
6
  constructor(payload) {
7
- this.#flattened = new FlattenedSign(payload);
7
+ if (!(payload instanceof Uint8Array)) {
8
+ throw new TypeError('payload must be an instance of Uint8Array');
9
+ }
10
+ this.#payload = payload;
8
11
  }
9
12
  setProtectedHeader(protectedHeader) {
10
- this.#flattened.setProtectedHeader(protectedHeader);
13
+ assertNotSet(this.#protectedHeader, 'setProtectedHeader');
11
14
  this.#protectedHeader = protectedHeader;
12
15
  return this;
13
16
  }
14
17
  async sign(key, options) {
15
- if (unencodedPayload(this.#protectedHeader)) {
18
+ return createCompactSignature(this.#payload, this.#protectedHeader, options?.crit, key, () => {
16
19
  throw new TypeError('use the flattened module for creating JWS with b64: false');
17
- }
18
- const jws = await this.#flattened.sign(key, options);
19
- return `${jws.protected}.${jws.payload}.${jws.signature}`;
20
+ });
20
21
  }
21
22
  }
@@ -21,11 +21,12 @@ export class FlattenedSign {
21
21
  return this;
22
22
  }
23
23
  async sign(key, options) {
24
- return createSignature({
24
+ const [jws] = await createSignature({
25
25
  payload: this.#payload,
26
26
  protectedHeader: this.#protectedHeader,
27
27
  unprotectedHeader: this.#unprotectedHeader,
28
28
  crit: options?.crit,
29
29
  }, key);
30
+ return jws;
30
31
  }
31
32
  }
@@ -1,24 +1,25 @@
1
1
  import { JWSInvalid } from '../../util/errors.js';
2
2
  import { isObject } from '../../lib/type_checks.js';
3
- import { prepareVerify, verifySignature, verifyResult } from '../../lib/jws_verify.js';
3
+ import { encodeJsonUnencodedPayload, prepareVerify, snapshotJws, verifySignature, verifyResult, } from '../../lib/jws_verify.js';
4
4
  export async function flattenedVerify(jws, key, options) {
5
5
  if (!isObject(jws)) {
6
6
  throw new JWSInvalid('Flattened JWS must be an object');
7
7
  }
8
- if (jws.protected === undefined && jws.header === undefined) {
8
+ const snapshot = snapshotJws(jws);
9
+ if (snapshot.protected === undefined && snapshot.header === undefined) {
9
10
  throw new JWSInvalid('Flattened JWS must have either of the "protected" or "header" members');
10
11
  }
11
- if (jws.protected !== undefined && typeof jws.protected !== 'string') {
12
+ if (snapshot.protected !== undefined && typeof snapshot.protected !== 'string') {
12
13
  throw new JWSInvalid('JWS Protected Header incorrect type');
13
14
  }
14
- if (jws.payload === undefined) {
15
+ if (snapshot.payload === undefined) {
15
16
  throw new JWSInvalid('JWS Payload missing');
16
17
  }
17
- if (typeof jws.signature !== 'string') {
18
+ if (typeof snapshot.signature !== 'string') {
18
19
  throw new JWSInvalid('JWS Signature missing or incorrect type');
19
20
  }
20
- if (jws.header !== undefined && !isObject(jws.header)) {
21
+ if (snapshot.header !== undefined && !isObject(snapshot.header)) {
21
22
  throw new JWSInvalid('JWS Unprotected Header incorrect type');
22
23
  }
23
- return verifyResult(jws, await verifySignature(jws, prepareVerify(options), key));
24
+ return verifyResult(snapshot, await verifySignature(snapshot, prepareVerify(options), key, encodeJsonUnencodedPayload));
24
25
  }
@@ -51,20 +51,22 @@ export class GeneralSign {
51
51
  payload: '',
52
52
  };
53
53
  const encoded = [];
54
+ let b64;
54
55
  for (let i = 0; i < this.#signatures.length; i++) {
55
56
  const signature = this.#signatures[i];
56
57
  const [protectedHeader, unprotectedHeader, key, crit] = signature.state;
57
- const { payload, ...rest } = await createSignature({
58
+ const [{ payload, ...rest }, signatureB64] = await createSignature({
58
59
  payload: this.#payload,
59
60
  protectedHeader,
60
61
  unprotectedHeader,
61
62
  crit,
62
63
  encoded,
63
64
  }, key);
64
- if (i === 0) {
65
+ if (b64 === undefined) {
66
+ b64 = signatureB64;
65
67
  jws.payload = payload;
66
68
  }
67
- else if (jws.payload !== payload) {
69
+ else if (b64 !== signatureB64) {
68
70
  throw new JWSInvalid('inconsistent use of JWS Unencoded Payload (RFC7797)');
69
71
  }
70
72
  jws.signatures.push(rest);
@@ -1,41 +1,71 @@
1
- import { prepareVerify, verifySignature, verifyResult } from '../../lib/jws_verify.js';
1
+ import { encodeJsonUnencodedPayload, parseProtectedHeader, prepareVerify, snapshotJws, verifySignature, verifyResult, } from '../../lib/jws_verify.js';
2
2
  import { JWSInvalid, JWSSignatureVerificationFailed } from '../../util/errors.js';
3
3
  import { isObject } from '../../lib/type_checks.js';
4
+ function snapshotSignature(signature, payload) {
5
+ try {
6
+ const jws = snapshotJws(signature, [payload]);
7
+ const { protected: encodedProtected, header, signature: encodedSignature } = jws;
8
+ if (encodedProtected === undefined && header === undefined)
9
+ return undefined;
10
+ if (encodedProtected !== undefined && typeof encodedProtected !== 'string')
11
+ return undefined;
12
+ if (typeof encodedSignature !== 'string')
13
+ return undefined;
14
+ if (header !== undefined && !isObject(header))
15
+ return undefined;
16
+ const protectedHeader = parseProtectedHeader(encodedProtected);
17
+ const { b64, crit } = protectedHeader;
18
+ return [
19
+ jws,
20
+ protectedHeader,
21
+ Array.isArray(crit) && crit.includes('b64')
22
+ ? typeof b64 === 'boolean'
23
+ ? b64
24
+ ? 1
25
+ : 2
26
+ : 0
27
+ : 1,
28
+ ];
29
+ }
30
+ catch {
31
+ return undefined;
32
+ }
33
+ }
4
34
  export async function generalVerify(jws, key, options) {
5
35
  if (!isObject(jws)) {
6
36
  throw new JWSInvalid('General JWS must be an object');
7
37
  }
8
- const { signatures, payload } = jws;
9
- if (!Array.isArray(signatures) || !signatures.every(isObject)) {
38
+ const { signatures, payload: inputPayload } = jws;
39
+ if (!Array.isArray(signatures)) {
40
+ throw new JWSInvalid('JWS Signatures missing or incorrect type');
41
+ }
42
+ const signatureEntries = Array.from(signatures);
43
+ if (!signatureEntries.every(isObject)) {
10
44
  throw new JWSInvalid('JWS Signatures missing or incorrect type');
11
45
  }
12
46
  let shared;
13
47
  try {
14
- if (payload === undefined)
48
+ if (inputPayload === undefined)
15
49
  throw new Error();
16
50
  shared = prepareVerify(options);
17
51
  }
18
52
  catch {
19
53
  throw new JWSSignatureVerificationFailed();
20
54
  }
21
- for (const signature of signatures) {
55
+ const payload = inputPayload instanceof Uint8Array ? new Uint8Array(inputPayload) : inputPayload;
56
+ const candidates = signatureEntries
57
+ .map((signature) => snapshotSignature(signature, payload))
58
+ .filter((candidate) => candidate !== undefined);
59
+ let modes = 0;
60
+ for (const [, , mode] of candidates) {
61
+ modes |= mode;
62
+ if (modes === 3) {
63
+ throw new JWSInvalid('inconsistent use of JWS Unencoded Payload (RFC7797)');
64
+ }
65
+ }
66
+ for (const candidate of candidates) {
22
67
  try {
23
- const { protected: encodedProtected, header, signature: encodedSignature } = signature;
24
- if (encodedProtected === undefined && header === undefined)
25
- throw new Error();
26
- if (encodedProtected !== undefined && typeof encodedProtected !== 'string') {
27
- throw new Error();
28
- }
29
- if (typeof encodedSignature !== 'string')
30
- throw new Error();
31
- if (header !== undefined && !isObject(header))
32
- throw new Error();
33
- return verifyResult(signature, await verifySignature({
34
- header,
35
- payload,
36
- protected: encodedProtected,
37
- signature: encodedSignature,
38
- }, shared, key));
68
+ return verifyResult(candidate[0], await verifySignature(candidate[0], shared, key, encodeJsonUnencodedPayload, candidate[1]));
39
69
  }
40
70
  catch {
41
71
  }
@@ -5,15 +5,13 @@ export async function jwtDecrypt(jwt, key, options) {
5
5
  const decrypted = await decryptCompact(jwt, prepareDecrypt(options), key);
6
6
  const protectedHeader = decrypted[1];
7
7
  const payload = validateClaimsSet(protectedHeader, decrypted[0], options);
8
- if (protectedHeader.iss !== undefined && protectedHeader.iss !== payload.iss) {
9
- throw new JWTClaimValidationFailed('replicated "iss" claim header parameter mismatch', payload, 'iss', 'mismatch');
10
- }
11
- if (protectedHeader.sub !== undefined && protectedHeader.sub !== payload.sub) {
12
- throw new JWTClaimValidationFailed('replicated "sub" claim header parameter mismatch', payload, 'sub', 'mismatch');
13
- }
14
- if (protectedHeader.aud !== undefined &&
15
- JSON.stringify(protectedHeader.aud) !== JSON.stringify(payload.aud)) {
16
- throw new JWTClaimValidationFailed('replicated "aud" claim header parameter mismatch', payload, 'aud', 'mismatch');
8
+ for (const claim of ['iss', 'sub', 'aud']) {
9
+ if (protectedHeader[claim] !== undefined &&
10
+ (claim === 'aud'
11
+ ? JSON.stringify(protectedHeader.aud) !== JSON.stringify(payload.aud)
12
+ : protectedHeader[claim] !== payload[claim])) {
13
+ throw new JWTClaimValidationFailed(`replicated "${claim}" claim header parameter mismatch`, payload, claim, 'mismatch');
14
+ }
17
15
  }
18
16
  const result = { payload, protectedHeader };
19
17
  if (typeof key === 'function') {
@@ -1,7 +1,8 @@
1
- import { CompactEncrypt } from '../jwe/compact/encrypt.js';
2
- import { JWTClaimsBuilder } from '../lib/jwt_claims_set.js';
1
+ import { createJWE } from '../lib/jwe_encrypt.js';
2
+ import { JWTClaimsBuilder, jwtClaim, jwtData } from '../lib/jwt_claims_set.js';
3
3
  import { assertNotSet } from '../lib/helpers.js';
4
- export class EncryptJWT {
4
+ const EncryptJWT_base = JWTClaimsBuilder;
5
+ export class EncryptJWT extends EncryptJWT_base {
5
6
  #cek;
6
7
  #iv;
7
8
  #keyManagementParameters;
@@ -9,38 +10,6 @@ export class EncryptJWT {
9
10
  #replicateIssuerAsHeader;
10
11
  #replicateSubjectAsHeader;
11
12
  #replicateAudienceAsHeader;
12
- #jwt;
13
- constructor(payload = {}) {
14
- this.#jwt = new JWTClaimsBuilder(payload);
15
- }
16
- setIssuer(issuer) {
17
- this.#jwt.iss = issuer;
18
- return this;
19
- }
20
- setSubject(subject) {
21
- this.#jwt.sub = subject;
22
- return this;
23
- }
24
- setAudience(audience) {
25
- this.#jwt.aud = audience;
26
- return this;
27
- }
28
- setJti(jwtId) {
29
- this.#jwt.jti = jwtId;
30
- return this;
31
- }
32
- setNotBefore(input) {
33
- this.#jwt.nbf = input;
34
- return this;
35
- }
36
- setExpirationTime(input) {
37
- this.#jwt.exp = input;
38
- return this;
39
- }
40
- setIssuedAt(input) {
41
- this.#jwt.iat = input;
42
- return this;
43
- }
44
13
  setProtectedHeader(protectedHeader) {
45
14
  assertNotSet(this.#protectedHeader, 'setProtectedHeader');
46
15
  this.#protectedHeader = protectedHeader;
@@ -74,28 +43,30 @@ export class EncryptJWT {
74
43
  return this;
75
44
  }
76
45
  async encrypt(key, options) {
77
- const enc = new CompactEncrypt(this.#jwt.data());
46
+ const plaintext = jwtData(this);
78
47
  if (this.#protectedHeader &&
79
48
  (this.#replicateIssuerAsHeader ||
80
49
  this.#replicateSubjectAsHeader ||
81
50
  this.#replicateAudienceAsHeader)) {
82
51
  this.#protectedHeader = {
83
52
  ...this.#protectedHeader,
84
- iss: this.#replicateIssuerAsHeader ? this.#jwt.iss : undefined,
85
- sub: this.#replicateSubjectAsHeader ? this.#jwt.sub : undefined,
86
- aud: this.#replicateAudienceAsHeader ? this.#jwt.aud : undefined,
53
+ iss: this.#replicateIssuerAsHeader ? jwtClaim(this, 'iss') : undefined,
54
+ sub: this.#replicateSubjectAsHeader ? jwtClaim(this, 'sub') : undefined,
55
+ aud: this.#replicateAudienceAsHeader ? jwtClaim(this, 'aud') : undefined,
87
56
  };
88
57
  }
89
- enc.setProtectedHeader(this.#protectedHeader);
90
- if (this.#iv) {
91
- enc.setInitializationVector(this.#iv);
92
- }
93
- if (this.#cek) {
94
- enc.setContentEncryptionKey(this.#cek);
95
- }
96
- if (this.#keyManagementParameters) {
97
- enc.setKeyManagementParameters(this.#keyManagementParameters);
98
- }
99
- return enc.encrypt(key, options);
58
+ const jwe = await createJWE([
59
+ plaintext,
60
+ this.#protectedHeader,
61
+ undefined,
62
+ undefined,
63
+ undefined,
64
+ this.#cek,
65
+ this.#iv,
66
+ this.#keyManagementParameters,
67
+ undefined,
68
+ false,
69
+ ], key, options);
70
+ return [jwe.protected, jwe.encrypted_key, jwe.iv, jwe.ciphertext, jwe.tag].join('.');
100
71
  }
101
72
  }
@@ -1,51 +1,18 @@
1
- import { CompactSign } from '../jws/compact/sign.js';
2
- import { unencodedPayload } from '../lib/jws_sign.js';
1
+ import { createCompactSignature } from '../lib/jws_sign.js';
3
2
  import { JWTInvalid } from '../util/errors.js';
4
- import { JWTClaimsBuilder } from '../lib/jwt_claims_set.js';
5
- export class SignJWT {
3
+ import { JWTClaimsBuilder, jwtData } from '../lib/jwt_claims_set.js';
4
+ import { assertNotSet } from '../lib/helpers.js';
5
+ const SignJWT_base = JWTClaimsBuilder;
6
+ export class SignJWT extends SignJWT_base {
6
7
  #protectedHeader;
7
- #jwt;
8
- constructor(payload = {}) {
9
- this.#jwt = new JWTClaimsBuilder(payload);
10
- }
11
- setIssuer(issuer) {
12
- this.#jwt.iss = issuer;
13
- return this;
14
- }
15
- setSubject(subject) {
16
- this.#jwt.sub = subject;
17
- return this;
18
- }
19
- setAudience(audience) {
20
- this.#jwt.aud = audience;
21
- return this;
22
- }
23
- setJti(jwtId) {
24
- this.#jwt.jti = jwtId;
25
- return this;
26
- }
27
- setNotBefore(input) {
28
- this.#jwt.nbf = input;
29
- return this;
30
- }
31
- setExpirationTime(input) {
32
- this.#jwt.exp = input;
33
- return this;
34
- }
35
- setIssuedAt(input) {
36
- this.#jwt.iat = input;
37
- return this;
38
- }
39
8
  setProtectedHeader(protectedHeader) {
9
+ assertNotSet(this.#protectedHeader, 'setProtectedHeader');
40
10
  this.#protectedHeader = protectedHeader;
41
11
  return this;
42
12
  }
43
13
  async sign(key, options) {
44
- const sig = new CompactSign(this.#jwt.data());
45
- sig.setProtectedHeader(this.#protectedHeader);
46
- if (unencodedPayload(this.#protectedHeader)) {
14
+ return createCompactSignature(jwtData(this), this.#protectedHeader, options?.crit, key, () => {
47
15
  throw new JWTInvalid('JWTs MUST NOT use unencoded payload');
48
- }
49
- return sig.sign(key, options);
16
+ });
50
17
  }
51
18
  }
@@ -1,46 +1,15 @@
1
1
  import * as b64u from '../util/base64url.js';
2
- import { strictDecoder } from '../lib/buffer_utils.js';
3
- import { decodeBase64url } from '../lib/helpers.js';
4
- import { JWTInvalid } from '../util/errors.js';
5
- import { validateClaimsSet, JWTClaimsBuilder } from '../lib/jwt_claims_set.js';
6
- export class UnsecuredJWT {
7
- #jwt;
8
- constructor(payload = {}) {
9
- this.#jwt = new JWTClaimsBuilder(payload);
10
- }
2
+ import { decodeBase64url, parseJoseHeader } from '../lib/helpers.js';
3
+ import { JWSInvalid, JWTInvalid } from '../util/errors.js';
4
+ import { validateClaimsSet, JWTClaimsBuilder, jwtData } from '../lib/jwt_claims_set.js';
5
+ import { JWS_RECOGNIZED, validateB64, validateCrit } from '../lib/options.js';
6
+ const UnsecuredJWT_base = JWTClaimsBuilder;
7
+ export class UnsecuredJWT extends UnsecuredJWT_base {
11
8
  encode() {
12
9
  const header = b64u.encode(JSON.stringify({ alg: 'none' }));
13
- const payload = b64u.encode(this.#jwt.data());
10
+ const payload = b64u.encode(jwtData(this));
14
11
  return `${header}.${payload}.`;
15
12
  }
16
- setIssuer(issuer) {
17
- this.#jwt.iss = issuer;
18
- return this;
19
- }
20
- setSubject(subject) {
21
- this.#jwt.sub = subject;
22
- return this;
23
- }
24
- setAudience(audience) {
25
- this.#jwt.aud = audience;
26
- return this;
27
- }
28
- setJti(jwtId) {
29
- this.#jwt.jti = jwtId;
30
- return this;
31
- }
32
- setNotBefore(input) {
33
- this.#jwt.nbf = input;
34
- return this;
35
- }
36
- setExpirationTime(input) {
37
- this.#jwt.exp = input;
38
- return this;
39
- }
40
- setIssuedAt(input) {
41
- this.#jwt.iat = input;
42
- return this;
43
- }
44
13
  static decode(jwt, options) {
45
14
  if (typeof jwt !== 'string') {
46
15
  throw new JWTInvalid('Unsecured JWT must be a string');
@@ -50,14 +19,24 @@ export class UnsecuredJWT {
50
19
  throw new JWTInvalid('Invalid Unsecured JWT');
51
20
  }
52
21
  let header;
22
+ let b64;
53
23
  try {
54
- header = JSON.parse(strictDecoder.decode(b64u.decode(encodedHeader)));
55
- if (header.alg !== 'none')
56
- throw new Error();
24
+ header = parseJoseHeader(encodedHeader, JWSInvalid, 'JWS Protected Header is invalid');
25
+ const extensions = validateCrit(JWSInvalid, JWS_RECOGNIZED, undefined, header, header);
26
+ b64 = validateB64(header, extensions);
57
27
  }
58
- catch {
28
+ catch (cause) {
29
+ if (!(cause instanceof JWSInvalid)) {
30
+ throw cause;
31
+ }
32
+ throw new JWTInvalid('Invalid Unsecured JWT', { cause });
33
+ }
34
+ if (header.alg !== 'none') {
59
35
  throw new JWTInvalid('Invalid Unsecured JWT');
60
36
  }
37
+ if (!b64) {
38
+ throw new JWTInvalid('JWTs MUST NOT use unencoded payload');
39
+ }
61
40
  const payload = validateClaimsSet(header, decodeBase64url(encodedPayload, 'payload', JWTInvalid), options);
62
41
  return { payload, header };
63
42
  }
@@ -1,13 +1,17 @@
1
1
  import { JOSENotSupported } from '../util/errors.js';
2
+ import { validateExtractableOption } from '../lib/key_options.js';
2
3
  import { keyAlgorithm, unsupportedAlg, algArgument } from '../lib/key_algorithm.js';
3
4
  function getModulusLengthOption(options) {
4
5
  const modulusLength = options?.modulusLength ?? 2048;
5
- if (typeof modulusLength !== 'number' || modulusLength < 2048) {
6
+ if (typeof modulusLength !== 'number' ||
7
+ !Number.isInteger(modulusLength) ||
8
+ modulusLength < 2048) {
6
9
  throw new JOSENotSupported('Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used');
7
10
  }
8
11
  return modulusLength;
9
12
  }
10
13
  export async function generateKeyPair(alg, options) {
14
+ const extractable = validateExtractableOption(options?.extractable);
11
15
  const entry = keyAlgorithm(alg, algArgument);
12
16
  if (entry.secret) {
13
17
  unsupportedAlg(algArgument);
@@ -41,7 +45,7 @@ export async function generateKeyPair(alg, options) {
41
45
  }
42
46
  : entry.subtle;
43
47
  }
44
- return crypto.subtle.generateKey(algorithm, options?.extractable ?? false, [
48
+ return crypto.subtle.generateKey(algorithm, extractable ?? false, [
45
49
  ...entry.usages[1],
46
50
  ...entry.usages[0],
47
51
  ]);
@@ -1,5 +1,7 @@
1
1
  import { unsupportedAlg, algArgument } from '../lib/key_algorithm.js';
2
+ import { validateExtractableOption } from '../lib/key_options.js';
2
3
  export async function generateSecret(alg, options) {
4
+ const extractable = validateExtractableOption(options?.extractable);
3
5
  let length;
4
6
  let algorithm;
5
7
  let keyUsages;
@@ -7,19 +9,18 @@ export async function generateSecret(alg, options) {
7
9
  case 'HS256':
8
10
  case 'HS384':
9
11
  case 'HS512':
10
- length = parseInt(alg.slice(-3), 10);
12
+ length = +alg.slice(-3);
11
13
  algorithm = { name: 'HMAC', hash: `SHA-${length}`, length };
12
14
  keyUsages = ['sign', 'verify'];
13
15
  break;
14
16
  case 'A128CBC-HS256':
15
17
  case 'A192CBC-HS384':
16
18
  case 'A256CBC-HS512':
17
- length = parseInt(alg.slice(-3), 10);
18
- return crypto.getRandomValues(new Uint8Array(length >> 3));
19
+ return crypto.getRandomValues(new Uint8Array(+alg.slice(-3) >> 3));
19
20
  case 'A128KW':
20
21
  case 'A192KW':
21
22
  case 'A256KW':
22
- length = parseInt(alg.slice(1, 4), 10);
23
+ length = +alg.slice(1, 4);
23
24
  algorithm = { name: 'AES-KW', length };
24
25
  keyUsages = ['wrapKey', 'unwrapKey'];
25
26
  break;
@@ -29,12 +30,12 @@ export async function generateSecret(alg, options) {
29
30
  case 'A128GCM':
30
31
  case 'A192GCM':
31
32
  case 'A256GCM':
32
- length = parseInt(alg.slice(1, 4), 10);
33
+ length = +alg.slice(1, 4);
33
34
  algorithm = { name: 'AES-GCM', length };
34
35
  keyUsages = ['encrypt', 'decrypt'];
35
36
  break;
36
37
  default:
37
38
  unsupportedAlg(algArgument);
38
39
  }
39
- return crypto.subtle.generateKey(algorithm, options?.extractable ?? false, keyUsages);
40
+ return crypto.subtle.generateKey(algorithm, extractable ?? false, keyUsages);
40
41
  }
@@ -4,6 +4,8 @@ import { jwkToKey } from '../lib/jwk_to_key.js';
4
4
  import { keyAlgorithm } from '../lib/key_algorithm.js';
5
5
  import { JOSENotSupported } from '../util/errors.js';
6
6
  import { isObject } from '../lib/type_checks.js';
7
+ import { validateExtractableOption } from '../lib/key_options.js';
8
+ import { normalizeJwk } from '../lib/jwk_metadata.js';
7
9
  export async function importSPKI(spki, alg, options) {
8
10
  if (typeof spki !== 'string' || spki.indexOf('-----BEGIN PUBLIC KEY-----') !== 0) {
9
11
  throw new TypeError('"spki" must be SPKI formatted string');
@@ -26,31 +28,33 @@ export async function importJWK(jwk, alg, options) {
26
28
  if (!isObject(jwk)) {
27
29
  throw new TypeError('JWK must be an object');
28
30
  }
29
- alg ??= jwk.alg;
30
- const ext = options?.extractable ?? jwk.ext;
31
- if (jwk.kty !== 'oct' && !alg) {
31
+ const normalized = normalizeJwk(jwk);
32
+ const extractable = validateExtractableOption(options?.extractable);
33
+ const { alg: jwkAlg } = normalized;
34
+ alg ??= jwkAlg;
35
+ const ext = extractable ?? normalized.ext;
36
+ if (normalized.kty !== 'oct' && !alg) {
32
37
  throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
33
38
  }
34
- switch (jwk.kty) {
39
+ switch (normalized.kty) {
35
40
  case 'oct':
36
- if (typeof jwk.k !== 'string' || !jwk.k) {
41
+ if (typeof normalized.k !== 'string') {
37
42
  throw new TypeError('missing "k" (Key Value) Parameter value');
38
43
  }
39
- return decodeBase64URL(jwk.k);
40
- case 'RSA':
41
- return jwkToKey(keyAlgorithm(alg), { ...jwk, alg, ext });
44
+ return decodeBase64URL(normalized.k);
42
45
  case 'AKP': {
43
- if (typeof jwk.alg !== 'string' || !jwk.alg) {
46
+ if (typeof jwkAlg !== 'string' || !jwkAlg) {
44
47
  throw new TypeError('missing "alg" (Algorithm) Parameter value');
45
48
  }
46
- if (alg !== undefined && alg !== jwk.alg) {
49
+ if (alg !== jwkAlg) {
47
50
  throw new TypeError('JWK alg and alg option value mismatch');
48
51
  }
49
- return jwkToKey(keyAlgorithm(jwk.alg), { ...jwk, ext });
52
+ return jwkToKey(keyAlgorithm(alg), { ...normalized, ext });
50
53
  }
54
+ case 'RSA':
51
55
  case 'EC':
52
56
  case 'OKP':
53
- return jwkToKey(keyAlgorithm(alg), { ...jwk, alg, ext });
57
+ return jwkToKey(keyAlgorithm(alg), { ...normalized, alg, ext });
54
58
  default:
55
59
  throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
56
60
  }
@@ -3,6 +3,7 @@ import { encodeBase64, decodeBase64 } from '../lib/base64.js';
3
3
  import { JOSENotSupported } from '../util/errors.js';
4
4
  import { keyAlgorithm, unsupportedAlg, algArgument } from './key_algorithm.js';
5
5
  import { isCryptoKey, isKeyObject } from './is_key_like.js';
6
+ import { validateExtractableOption } from './key_options.js';
6
7
  const formatPEM = (b64, descriptor) => {
7
8
  const newlined = (b64.match(/.{1,64}/g) || []).join('\n');
8
9
  return `-----BEGIN ${descriptor}-----\n${newlined}\n-----END ${descriptor}-----`;
@@ -112,6 +113,7 @@ const parseECAlgorithmIdentifier = (state) => {
112
113
  throw new Error('Unsupported named curve');
113
114
  };
114
115
  const genericImport = async (keyFormat, keyData, alg, options) => {
116
+ const extractable = validateExtractableOption(options?.extractable);
115
117
  const entry = keyAlgorithm(alg, algArgument);
116
118
  if (entry.secret) {
117
119
  unsupportedAlg(algArgument);
@@ -131,7 +133,7 @@ const genericImport = async (keyFormat, keyData, alg, options) => {
131
133
  else {
132
134
  algorithm = entry.subtle;
133
135
  }
134
- return crypto.subtle.importKey(keyFormat, keyData, algorithm, options?.extractable ?? isPublic, entry.usages[isPublic ? 0 : 1]);
136
+ return crypto.subtle.importKey(keyFormat, keyData, algorithm, extractable ?? isPublic, entry.usages[isPublic ? 0 : 1]);
135
137
  };
136
138
  const processPEMData = (pem, pattern) => {
137
139
  return decodeBase64(pem.replace(pattern, ''));
@@ -147,7 +149,10 @@ export const fromSPKI = (pem, alg, options) => {
147
149
  function spkiFromX509(buf) {
148
150
  const state = createASN1State(buf);
149
151
  expectTag(state, 0x30, 'Invalid certificate structure');
150
- parseLength(state);
152
+ const certificateLength = parseLength(state);
153
+ if (certificateLength < 0 || state.pos + certificateLength > state.data.length) {
154
+ throw new Error('Unexpected end of ASN.1 input');
155
+ }
151
156
  expectTag(state, 0x30, 'Invalid tbsCertificate structure');
152
157
  parseLength(state);
153
158
  if (buf[state.pos] === 0xa0) {