@kya-os/mcp-i-cloudflare 1.17.0 → 1.18.1

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 (268) hide show
  1. package/README.md +273 -54
  2. package/dist/adapter.d.ts +3 -17
  3. package/dist/adapter.d.ts.map +1 -1
  4. package/dist/adapter.js +39 -477
  5. package/dist/adapter.js.map +1 -1
  6. package/dist/agent.d.ts +59 -35
  7. package/dist/agent.d.ts.map +1 -1
  8. package/dist/agent.js +386 -404
  9. package/dist/agent.js.map +1 -1
  10. package/dist/app.d.ts.map +1 -1
  11. package/dist/app.js +150 -94
  12. package/dist/app.js.map +1 -1
  13. package/dist/audit/deployment-binding.d.ts +16 -16
  14. package/dist/authority-outcome.d.ts +110 -0
  15. package/dist/authority-outcome.d.ts.map +1 -0
  16. package/dist/authority-outcome.js +154 -0
  17. package/dist/authority-outcome.js.map +1 -0
  18. package/dist/config.d.ts +8 -77
  19. package/dist/config.d.ts.map +1 -1
  20. package/dist/config.js +0 -83
  21. package/dist/config.js.map +1 -1
  22. package/dist/delegation-http/bearer-retry.d.ts +84 -32
  23. package/dist/delegation-http/bearer-retry.d.ts.map +1 -1
  24. package/dist/delegation-http/bearer-retry.js +124 -139
  25. package/dist/delegation-http/bearer-retry.js.map +1 -1
  26. package/dist/delegation-http/connect-gate.d.ts +47 -0
  27. package/dist/delegation-http/connect-gate.d.ts.map +1 -0
  28. package/dist/delegation-http/connect-gate.js +104 -0
  29. package/dist/delegation-http/connect-gate.js.map +1 -0
  30. package/dist/delegation-http/constants.d.ts +4 -49
  31. package/dist/delegation-http/constants.d.ts.map +1 -1
  32. package/dist/delegation-http/constants.js +4 -58
  33. package/dist/delegation-http/constants.js.map +1 -1
  34. package/dist/delegation-http/issuer-binding.d.ts +26 -0
  35. package/dist/delegation-http/issuer-binding.d.ts.map +1 -0
  36. package/dist/delegation-http/issuer-binding.js +51 -0
  37. package/dist/delegation-http/issuer-binding.js.map +1 -0
  38. package/dist/delegation-http/lazy-auth-gate.d.ts +88 -0
  39. package/dist/delegation-http/lazy-auth-gate.d.ts.map +1 -0
  40. package/dist/delegation-http/lazy-auth-gate.js +203 -0
  41. package/dist/delegation-http/lazy-auth-gate.js.map +1 -0
  42. package/dist/delegation-http/native-challenge.d.ts +52 -0
  43. package/dist/delegation-http/native-challenge.d.ts.map +1 -0
  44. package/dist/delegation-http/native-challenge.js +124 -0
  45. package/dist/delegation-http/native-challenge.js.map +1 -0
  46. package/dist/delegation-http/native-consent-redirect.d.ts +21 -0
  47. package/dist/delegation-http/native-consent-redirect.d.ts.map +1 -0
  48. package/dist/delegation-http/native-consent-redirect.js +43 -0
  49. package/dist/delegation-http/native-consent-redirect.js.map +1 -0
  50. package/dist/delegation-http/native-http.d.ts +1 -86
  51. package/dist/delegation-http/native-http.d.ts.map +1 -1
  52. package/dist/delegation-http/native-http.js +2 -130
  53. package/dist/delegation-http/native-http.js.map +1 -1
  54. package/dist/delegation-http/native-oauth-state-do.d.ts +13 -35
  55. package/dist/delegation-http/native-oauth-state-do.d.ts.map +1 -1
  56. package/dist/delegation-http/native-oauth-state-do.js +10 -165
  57. package/dist/delegation-http/native-oauth-state-do.js.map +1 -1
  58. package/dist/delegation-http/protected-resource.d.ts +37 -0
  59. package/dist/delegation-http/protected-resource.d.ts.map +1 -0
  60. package/dist/delegation-http/protected-resource.js +43 -0
  61. package/dist/delegation-http/protected-resource.js.map +1 -0
  62. package/dist/delegation-http/request-proof.d.ts +20 -0
  63. package/dist/delegation-http/request-proof.d.ts.map +1 -0
  64. package/dist/delegation-http/request-proof.js +29 -0
  65. package/dist/delegation-http/request-proof.js.map +1 -0
  66. package/dist/delegation-http/sid.d.ts +4 -12
  67. package/dist/delegation-http/sid.d.ts.map +1 -1
  68. package/dist/delegation-http/sid.js +4 -19
  69. package/dist/delegation-http/sid.js.map +1 -1
  70. package/dist/delegation-http/well-known-capability.d.ts +8 -12
  71. package/dist/delegation-http/well-known-capability.d.ts.map +1 -1
  72. package/dist/delegation-http/well-known-capability.js +9 -18
  73. package/dist/delegation-http/well-known-capability.js.map +1 -1
  74. package/dist/helpers/env-mapper.d.ts.map +1 -1
  75. package/dist/helpers/env-mapper.js +7 -29
  76. package/dist/helpers/env-mapper.js.map +1 -1
  77. package/dist/index.d.ts +2 -4
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +11 -8
  80. package/dist/index.js.map +1 -1
  81. package/dist/proof-generator.d.ts +24 -17
  82. package/dist/proof-generator.d.ts.map +1 -1
  83. package/dist/proof-generator.js +42 -56
  84. package/dist/proof-generator.js.map +1 -1
  85. package/dist/runtime/amount-limit-refusal.d.ts +3 -0
  86. package/dist/runtime/amount-limit-refusal.d.ts.map +1 -0
  87. package/dist/runtime/amount-limit-refusal.js +7 -0
  88. package/dist/runtime/amount-limit-refusal.js.map +1 -0
  89. package/dist/runtime/oauth-handler.d.ts +1 -1
  90. package/dist/runtime/oauth-handler.d.ts.map +1 -1
  91. package/dist/runtime/oauth-handler.js +31 -34
  92. package/dist/runtime/oauth-handler.js.map +1 -1
  93. package/dist/runtime.d.ts +34 -10
  94. package/dist/runtime.d.ts.map +1 -1
  95. package/dist/runtime.js +65 -16
  96. package/dist/runtime.js.map +1 -1
  97. package/dist/security/admission-refusal.d.ts +3 -3
  98. package/dist/security/admission-refusal.d.ts.map +1 -1
  99. package/dist/security/admission-refusal.js +14 -6
  100. package/dist/security/admission-refusal.js.map +1 -1
  101. package/dist/security/holder-binding.d.ts +34 -0
  102. package/dist/security/holder-binding.d.ts.map +1 -0
  103. package/dist/security/holder-binding.js +75 -0
  104. package/dist/security/holder-binding.js.map +1 -0
  105. package/dist/security/mcp-admission.d.ts +29 -1
  106. package/dist/security/mcp-admission.d.ts.map +1 -1
  107. package/dist/security/mcp-admission.js +78 -12
  108. package/dist/security/mcp-admission.js.map +1 -1
  109. package/dist/security/native-holder-admission.d.ts +39 -0
  110. package/dist/security/native-holder-admission.d.ts.map +1 -0
  111. package/dist/security/native-holder-admission.js +65 -0
  112. package/dist/security/native-holder-admission.js.map +1 -0
  113. package/dist/security/outcome-proof.d.ts +39 -0
  114. package/dist/security/outcome-proof.d.ts.map +1 -0
  115. package/dist/security/outcome-proof.js +54 -0
  116. package/dist/security/outcome-proof.js.map +1 -0
  117. package/dist/security/request-nonce-store.d.ts +43 -0
  118. package/dist/security/request-nonce-store.d.ts.map +1 -0
  119. package/dist/security/request-nonce-store.js +129 -0
  120. package/dist/security/request-nonce-store.js.map +1 -0
  121. package/dist/security/routed-request.d.ts +41 -0
  122. package/dist/security/routed-request.d.ts.map +1 -0
  123. package/dist/security/routed-request.js +86 -0
  124. package/dist/security/routed-request.js.map +1 -0
  125. package/dist/security/sign-in-amr.d.ts +23 -0
  126. package/dist/security/sign-in-amr.d.ts.map +1 -0
  127. package/dist/security/sign-in-amr.js +44 -0
  128. package/dist/security/sign-in-amr.js.map +1 -0
  129. package/dist/services/approval-route.d.ts +3 -2
  130. package/dist/services/approval-route.d.ts.map +1 -1
  131. package/dist/services/approval-route.js.map +1 -1
  132. package/dist/services/checkpoint-decision.d.ts +56 -0
  133. package/dist/services/checkpoint-decision.d.ts.map +1 -0
  134. package/dist/services/checkpoint-decision.js +109 -0
  135. package/dist/services/checkpoint-decision.js.map +1 -0
  136. package/dist/services/consent-page-renderer.d.ts.map +1 -1
  137. package/dist/services/consent-page-renderer.js +2 -3
  138. package/dist/services/consent-page-renderer.js.map +1 -1
  139. package/dist/services/consent.service.d.ts +11 -49
  140. package/dist/services/consent.service.d.ts.map +1 -1
  141. package/dist/services/consent.service.js +81 -307
  142. package/dist/services/consent.service.js.map +1 -1
  143. package/dist/services/credential-auth.handler.d.ts.map +1 -1
  144. package/dist/services/credential-auth.handler.js +2 -8
  145. package/dist/services/credential-auth.handler.js.map +1 -1
  146. package/dist/services/delegation-authority.d.ts +53 -0
  147. package/dist/services/delegation-authority.d.ts.map +1 -0
  148. package/dist/services/delegation-authority.js +130 -0
  149. package/dist/services/delegation-authority.js.map +1 -0
  150. package/dist/services/delegation-trust.d.ts +35 -64
  151. package/dist/services/delegation-trust.d.ts.map +1 -1
  152. package/dist/services/delegation-trust.js +98 -279
  153. package/dist/services/delegation-trust.js.map +1 -1
  154. package/dist/services/delegation.service.d.ts +83 -105
  155. package/dist/services/delegation.service.d.ts.map +1 -1
  156. package/dist/services/delegation.service.js +166 -518
  157. package/dist/services/delegation.service.js.map +1 -1
  158. package/dist/services/idp-token-storage.d.ts +32 -12
  159. package/dist/services/idp-token-storage.d.ts.map +1 -1
  160. package/dist/services/idp-token-storage.js +79 -36
  161. package/dist/services/idp-token-storage.js.map +1 -1
  162. package/dist/services/issuer-keys.d.ts +55 -0
  163. package/dist/services/issuer-keys.d.ts.map +1 -0
  164. package/dist/services/issuer-keys.js +184 -0
  165. package/dist/services/issuer-keys.js.map +1 -0
  166. package/dist/services/oauth-security.service.d.ts +17 -1
  167. package/dist/services/oauth-security.service.d.ts.map +1 -1
  168. package/dist/services/oauth-security.service.js +29 -10
  169. package/dist/services/oauth-security.service.js.map +1 -1
  170. package/dist/services/proof.service.d.ts +10 -0
  171. package/dist/services/proof.service.d.ts.map +1 -1
  172. package/dist/services/proof.service.js +28 -6
  173. package/dist/services/proof.service.js.map +1 -1
  174. package/dist/services/resource-audience.d.ts +12 -9
  175. package/dist/services/resource-audience.d.ts.map +1 -1
  176. package/dist/services/resource-audience.js +12 -9
  177. package/dist/services/resource-audience.js.map +1 -1
  178. package/dist/services/unenforceable-tool-protection.d.ts +32 -0
  179. package/dist/services/unenforceable-tool-protection.d.ts.map +1 -0
  180. package/dist/services/unenforceable-tool-protection.js +90 -0
  181. package/dist/services/unenforceable-tool-protection.js.map +1 -0
  182. package/dist/services/upstream-fetch.d.ts +14 -0
  183. package/dist/services/upstream-fetch.d.ts.map +1 -0
  184. package/dist/services/upstream-fetch.js +56 -0
  185. package/dist/services/upstream-fetch.js.map +1 -0
  186. package/dist/types.d.ts +5 -18
  187. package/dist/types.d.ts.map +1 -1
  188. package/dist/utils/oauth-profile.d.ts +19 -0
  189. package/dist/utils/oauth-profile.d.ts.map +1 -1
  190. package/dist/utils/oauth-profile.js +54 -1
  191. package/dist/utils/oauth-profile.js.map +1 -1
  192. package/dist/utils/tool-security-schemes.d.ts +65 -0
  193. package/dist/utils/tool-security-schemes.d.ts.map +1 -0
  194. package/dist/utils/tool-security-schemes.js +168 -0
  195. package/dist/utils/tool-security-schemes.js.map +1 -0
  196. package/package.json +5 -6
  197. package/dist/delegation-http/anchor-do.d.ts +0 -84
  198. package/dist/delegation-http/anchor-do.d.ts.map +0 -1
  199. package/dist/delegation-http/anchor-do.js +0 -412
  200. package/dist/delegation-http/anchor-do.js.map +0 -1
  201. package/dist/delegation-http/anchor-registration-validate.d.ts +0 -61
  202. package/dist/delegation-http/anchor-registration-validate.d.ts.map +0 -1
  203. package/dist/delegation-http/anchor-registration-validate.js +0 -191
  204. package/dist/delegation-http/anchor-registration-validate.js.map +0 -1
  205. package/dist/delegation-http/anchor-registration.d.ts +0 -62
  206. package/dist/delegation-http/anchor-registration.d.ts.map +0 -1
  207. package/dist/delegation-http/anchor-registration.js +0 -337
  208. package/dist/delegation-http/anchor-registration.js.map +0 -1
  209. package/dist/delegation-http/anchor-routing.d.ts +0 -20
  210. package/dist/delegation-http/anchor-routing.d.ts.map +0 -1
  211. package/dist/delegation-http/anchor-routing.js +0 -27
  212. package/dist/delegation-http/anchor-routing.js.map +0 -1
  213. package/dist/delegation-http/challenge-middleware.d.ts +0 -28
  214. package/dist/delegation-http/challenge-middleware.d.ts.map +0 -1
  215. package/dist/delegation-http/challenge-middleware.js +0 -190
  216. package/dist/delegation-http/challenge-middleware.js.map +0 -1
  217. package/dist/delegation-http/challenge.d.ts +0 -102
  218. package/dist/delegation-http/challenge.d.ts.map +0 -1
  219. package/dist/delegation-http/challenge.js +0 -223
  220. package/dist/delegation-http/challenge.js.map +0 -1
  221. package/dist/delegation-http/consent-anchor-bridge.d.ts +0 -70
  222. package/dist/delegation-http/consent-anchor-bridge.d.ts.map +0 -1
  223. package/dist/delegation-http/consent-anchor-bridge.js +0 -1130
  224. package/dist/delegation-http/consent-anchor-bridge.js.map +0 -1
  225. package/dist/delegation-http/consent-preparation-page.d.ts +0 -18
  226. package/dist/delegation-http/consent-preparation-page.d.ts.map +0 -1
  227. package/dist/delegation-http/consent-preparation-page.js +0 -172
  228. package/dist/delegation-http/consent-preparation-page.js.map +0 -1
  229. package/dist/delegation-http/credential-consent.d.ts +0 -149
  230. package/dist/delegation-http/credential-consent.d.ts.map +0 -1
  231. package/dist/delegation-http/credential-consent.js +0 -338
  232. package/dist/delegation-http/credential-consent.js.map +0 -1
  233. package/dist/delegation-http/native-capabilities.d.ts +0 -4
  234. package/dist/delegation-http/native-capabilities.d.ts.map +0 -1
  235. package/dist/delegation-http/native-capabilities.js +0 -53
  236. package/dist/delegation-http/native-capabilities.js.map +0 -1
  237. package/dist/delegation-http/native-oauth-state.d.ts +0 -28
  238. package/dist/delegation-http/native-oauth-state.d.ts.map +0 -1
  239. package/dist/delegation-http/native-oauth-state.js +0 -146
  240. package/dist/delegation-http/native-oauth-state.js.map +0 -1
  241. package/dist/delegation-http/native-oauth.d.ts +0 -26
  242. package/dist/delegation-http/native-oauth.d.ts.map +0 -1
  243. package/dist/delegation-http/native-oauth.js +0 -393
  244. package/dist/delegation-http/native-oauth.js.map +0 -1
  245. package/dist/delegation-http/native-pickup.d.ts +0 -20
  246. package/dist/delegation-http/native-pickup.d.ts.map +0 -1
  247. package/dist/delegation-http/native-pickup.js +0 -227
  248. package/dist/delegation-http/native-pickup.js.map +0 -1
  249. package/dist/delegation-http/pickup-routes.d.ts +0 -43
  250. package/dist/delegation-http/pickup-routes.d.ts.map +0 -1
  251. package/dist/delegation-http/pickup-routes.js +0 -166
  252. package/dist/delegation-http/pickup-routes.js.map +0 -1
  253. package/dist/delegation-http/register.d.ts +0 -26
  254. package/dist/delegation-http/register.d.ts.map +0 -1
  255. package/dist/delegation-http/register.js +0 -95
  256. package/dist/delegation-http/register.js.map +0 -1
  257. package/dist/delegation-http/registrar-auth.d.ts +0 -24
  258. package/dist/delegation-http/registrar-auth.d.ts.map +0 -1
  259. package/dist/delegation-http/registrar-auth.js +0 -61
  260. package/dist/delegation-http/registrar-auth.js.map +0 -1
  261. package/dist/delegation-http/remote-issuer.d.ts +0 -52
  262. package/dist/delegation-http/remote-issuer.d.ts.map +0 -1
  263. package/dist/delegation-http/remote-issuer.js +0 -324
  264. package/dist/delegation-http/remote-issuer.js.map +0 -1
  265. package/dist/delegation-http/types.d.ts +0 -116
  266. package/dist/delegation-http/types.d.ts.map +0 -1
  267. package/dist/delegation-http/types.js +0 -11
  268. package/dist/delegation-http/types.js.map +0 -1
@@ -1,27 +0,0 @@
1
- /**
2
- * draft-kya-http-02 delegation layer — pickup-anchor durable-object routing.
3
- *
4
- * Anchor state lives in the existing `MCP_OBJECT` durable object (no new DO class,
5
- * no wrangler migration). Each anchor gets its OWN instance, named `pickup:<sid>`,
6
- * so the §13 first-poll race is serialized by the DO input gate and never collides
7
- * with the MCP session namespace (which uses `DO_ROUTING_STRATEGY`).
8
- *
9
- * @module @kya-os/mcp-i-cloudflare/delegation-http/anchor-routing
10
- */
11
- /** Durable-object instance name for an anchor: one instance per sid. */
12
- export function anchorInstanceId(sid) {
13
- return `pickup:${sid}`;
14
- }
15
- /**
16
- * Resolve the durable-object stub for an anchor's dedicated instance. Throws when
17
- * `MCP_OBJECT` is not bound (the anchor layer cannot function without it).
18
- */
19
- export function getAnchorStub(env, sid) {
20
- const namespace = env.MCP_OBJECT;
21
- if (!namespace) {
22
- throw new Error("[kya-http] MCP_OBJECT durable object namespace is not bound; cannot route pickup anchor");
23
- }
24
- const id = namespace.idFromName(anchorInstanceId(sid));
25
- return namespace.get(id);
26
- }
27
- //# sourceMappingURL=anchor-routing.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"anchor-routing.js","sourceRoot":"","sources":["../../src/delegation-http/anchor-routing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,wEAAwE;AACxE,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,OAAO,UAAU,GAAG,EAAE,CAAC;AACzB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAC3B,GAAkB,EAClB,GAAW;IAEX,MAAM,SAAS,GAAG,GAAG,CAAC,UAAU,CAAC;IACjC,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,yFAAyF,CAC1F,CAAC;IACJ,CAAC;IACD,MAAM,EAAE,GAAG,SAAS,CAAC,UAAU,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC;IACvD,OAAO,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAC3B,CAAC"}
@@ -1,28 +0,0 @@
1
- /**
2
- * draft-kya-http-02 delegation layer — §8.1 challenge emitter middleware.
3
- *
4
- * Triggers on JSON-RPC responses whose `result._meta.errorType ===
5
- * "authorization_required"` (the existing `DelegationRequiredError` → `result._meta`
6
- * mapping in `adapter.ts`), mints a sid, creates the pickup anchor (which MUST exist
7
- * before the 401 leaves), signs the `challenge_proof`, and emits the §8.1 401 in
8
- * `negotiated`/`always` mode. Returns `null` to pass the original response through.
9
- *
10
- * @module @kya-os/mcp-i-cloudflare/delegation-http/challenge-middleware
11
- */
12
- import type { CloudflareEnv } from "../types";
13
- import type { HttpChallengeConfig } from "../config";
14
- import type { CloudflareProofGenerator } from "../proof-generator";
15
- import type { getAnchorStub } from "./anchor-routing";
16
- /**
17
- * Emit a §8.1 delegation challenge in place of an `authorization_required` MCP
18
- * response, or return `null` to pass the original response through untouched.
19
- *
20
- * `negotiated` (default): when the caller is NOT kya-capable, the ORIGINAL MCP error
21
- * response is returned (so existing MCP/OAuth clients still see the unmodified error),
22
- * never a 401. `always`: every `authorization_required` becomes a 401.
23
- */
24
- export declare function maybeEmitDelegationChallenge(request: Request, response: Response, env: CloudflareEnv, cfg: Required<HttpChallengeConfig>, deps: {
25
- getAnchorStub: typeof getAnchorStub;
26
- proofGenerator: () => Promise<CloudflareProofGenerator>;
27
- }): Promise<Response | null>;
28
- //# sourceMappingURL=challenge-middleware.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"challenge-middleware.d.ts","sourceRoot":"","sources":["../../src/delegation-http/challenge-middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AA+GtD;;;;;;;GAOG;AACH,wBAAsB,4BAA4B,CAChD,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,aAAa,EAClB,GAAG,EAAE,QAAQ,CAAC,mBAAmB,CAAC,EAClC,IAAI,EAAE;IACJ,aAAa,EAAE,OAAO,aAAa,CAAC;IACpC,cAAc,EAAE,MAAM,OAAO,CAAC,wBAAwB,CAAC,CAAC;CACzD,GACA,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAwG1B"}
@@ -1,190 +0,0 @@
1
- /**
2
- * draft-kya-http-02 delegation layer — §8.1 challenge emitter middleware.
3
- *
4
- * Triggers on JSON-RPC responses whose `result._meta.errorType ===
5
- * "authorization_required"` (the existing `DelegationRequiredError` → `result._meta`
6
- * mapping in `adapter.ts`), mints a sid, creates the pickup anchor (which MUST exist
7
- * before the 401 leaves), signs the `challenge_proof`, and emits the §8.1 401 in
8
- * `negotiated`/`always` mode. Returns `null` to pass the original response through.
9
- *
10
- * @module @kya-os/mcp-i-cloudflare/delegation-http/challenge-middleware
11
- */
12
- import { sha256Hex } from "./hash";
13
- import { INTERNAL_PICKUP_CREATE } from "./constants";
14
- import { buildChallengeResponse, buildFetcherChallengeResponse, buildConsentUri, signChallengeProof, } from "./challenge";
15
- /**
16
- * Inspect a cloned JSON-RPC response body for the `authorization_required` trigger.
17
- * Returns the parsed meta when present, otherwise `null` (pass through untouched).
18
- */
19
- async function readAuthorizationRequiredMeta(response) {
20
- let parsed;
21
- try {
22
- parsed = await response.clone().json();
23
- }
24
- catch {
25
- // Non-JSON or unreadable body: not a delegation error.
26
- return null;
27
- }
28
- const result = parsed
29
- ?.result;
30
- const meta = result?._meta;
31
- if (!meta || meta.errorType !== "authorization_required") {
32
- return null;
33
- }
34
- return meta;
35
- }
36
- /**
37
- * INTERACTIVE AI-agent fetcher User-Agents — agents that fetch on behalf of a human in
38
- * a live session (so they can relay a consent link) but collapse 4xx/5xx bodies and
39
- * never surface a 401 challenge to the LLM. Deliberately EXCLUDES indexing crawlers
40
- * (e.g. GPTBot, OAI-SearchBot, PerplexityBot): a crawler has no user to relay consent
41
- * to, so it stays on the spec path — matching the engine PEPs' `ai_agent` (NOT bot)
42
- * contract. TRANSITIONAL worker-local heuristic; the durable signal is the
43
- * `KYA-Accept-Challenge` opt-in header, and this list retires as frameworks adopt it.
44
- */
45
- const AI_AGENT_FETCHER_UA = /\b(claude-user|chatgpt-user)\b/i;
46
- /**
47
- * A cooperative agent fetcher that should receive the body-readable HTTP 200 envelope
48
- * instead of a 401 it would silently drop: the caller opts in via `KYA-Accept-Challenge`
49
- * (any non-empty value — the durable, primary signal), OR its User-Agent matches a known
50
- * agent fetcher (the transitional heuristic). Mirrors the other PEPs' `serveBodyReadable200`
51
- * predicate. A cooperative-UX bridge, NOT an access control.
52
- */
53
- function callerWantsBodyReadable200(request) {
54
- const accept = request.headers.get("KYA-Accept-Challenge");
55
- if (accept && accept.trim().length > 0) {
56
- return true;
57
- }
58
- const ua = request.headers.get("User-Agent") ?? "";
59
- return AI_AGENT_FETCHER_UA.test(ua);
60
- }
61
- /**
62
- * A signature-capable caller (RFC 9421 `Signature-Input` with a `kya` label) that can
63
- * read a 4xx and handle the dual `WWW-Authenticate` wire — it keeps the spec 401.
64
- */
65
- function callerIsSignatureCapable(request) {
66
- const signatureInput = request.headers.get("Signature-Input");
67
- return !!signatureInput && /(^|,)\s*kya\s*=/.test(signatureInput);
68
- }
69
- /** Pull the required scopes out of the adapter meta, defaulting to an empty list. */
70
- function readRequiredScopes(meta) {
71
- if (Array.isArray(meta.requiredScopes)) {
72
- return meta.requiredScopes.filter((scope) => typeof scope === "string");
73
- }
74
- return [];
75
- }
76
- /**
77
- * Derive a deterministic anchor sid (`kya-` + 32 hex) from the MCP session, the
78
- * required scopes, AND the `minAssurance` (W1 creation-bounding). Repeated
79
- * `authorization_required` results for the same caller+scopes+assurance reuse one
80
- * `pickup:<sid>` anchor instead of minting a fresh durable object per request. A
81
- * session-less caller collapses to one anchor per (scope-set, assurance); the MCP
82
- * session id (when present) separates clients.
83
- *
84
- * `minAssurance` is part of the key because `reduceCreate` reuses a still-live anchor
85
- * without mutating its fields: if it were omitted, a later challenge advertising a new
86
- * `min_assurance` would reuse an anchor (and consent surface) still carrying the old
87
- * value — so a changed assurance MUST derive a distinct anchor.
88
- */
89
- function deriveAnchorSid(request, requiredScopes, minAssurance) {
90
- const session = request.headers.get("mcp-session-id") ?? "";
91
- const scopeKey = [...requiredScopes].sort().join(" ");
92
- return `kya-${sha256Hex(`${session}\n${scopeKey}\n${minAssurance ?? ""}`).slice(0, 32)}`;
93
- }
94
- /**
95
- * Emit a §8.1 delegation challenge in place of an `authorization_required` MCP
96
- * response, or return `null` to pass the original response through untouched.
97
- *
98
- * `negotiated` (default): when the caller is NOT kya-capable, the ORIGINAL MCP error
99
- * response is returned (so existing MCP/OAuth clients still see the unmodified error),
100
- * never a 401. `always`: every `authorization_required` becomes a 401.
101
- */
102
- export async function maybeEmitDelegationChallenge(request, response, env, cfg, deps) {
103
- const meta = await readAuthorizationRequiredMeta(response);
104
- if (!meta) {
105
- // Not a delegation error — pass through untouched.
106
- return null;
107
- }
108
- // Selection: a cooperative agent fetcher gets the body-readable 200; a
109
- // signature-capable client gets the spec 401. In `negotiated` mode a caller that is
110
- // NEITHER is handed back the original MCP error (never a challenge it can't read).
111
- const wantsBodyReadable200 = callerWantsBodyReadable200(request);
112
- const signatureCapable = callerIsSignatureCapable(request);
113
- if (cfg.mode === "negotiated" && !wantsBodyReadable200 && !signatureCapable) {
114
- return response;
115
- }
116
- // W4: pin the challenge host to the configured realm when set, falling back to the
117
- // request Host only when unset — so a Host-header-reflecting deployment cannot get
118
- // an org-signed challenge (and consent/pickup links) pointing at an attacker host.
119
- const host = cfg.realm || new URL(request.url).host;
120
- const requiredScopes = readRequiredScopes(meta);
121
- const minAssurance = typeof meta.minAssurance === "string" ? meta.minAssurance : undefined;
122
- const sid = deriveAnchorSid(request, requiredScopes, minAssurance);
123
- const verdict = {
124
- requiredScopes,
125
- minAssurance,
126
- authorizationHost: host,
127
- realm: host,
128
- sid,
129
- pollIntervalS: cfg.pollIntervalS,
130
- };
131
- // The anchor MUST exist before the 401 leaves: a caller could poll the pickup URL
132
- // the instant it reads the challenge. Create-then-respond ordering is enforced here
133
- // by awaiting the DO create — AND verifying it persisted (201) — before
134
- // signing/building the response. If the create fails (non-201) or the durable
135
- // object is unreachable, we suppress the challenge and fall through (return null)
136
- // to the original MCP `authorization_required` error rather than advertise a
137
- // consent/pickup URI for an anchor that was never persisted (clients would poll a
138
- // §13 404/invalid-session forever).
139
- const anchorStub = deps.getAnchorStub(env, sid);
140
- let anchorPersisted = false;
141
- try {
142
- const createResponse = await anchorStub.fetch(`https://do${INTERNAL_PICKUP_CREATE}`, {
143
- method: "POST",
144
- headers: { "Content-Type": "application/json" },
145
- body: JSON.stringify({
146
- sid,
147
- requiredScopes: verdict.requiredScopes,
148
- ...(verdict.minAssurance !== undefined
149
- ? { minAssurance: verdict.minAssurance }
150
- : {}),
151
- pollIntervalS: cfg.pollIntervalS,
152
- anchorTtlS: cfg.anchorTtlS,
153
- delegationExpiresInS: cfg.delegationExpiresInS,
154
- }),
155
- });
156
- // reduceCreate returns 201 for both a fresh anchor and the idempotent reuse of a
157
- // still-live one (W1 deterministic sid), so 201 is the only success status.
158
- anchorPersisted = createResponse.status === 201;
159
- if (!anchorPersisted) {
160
- console.warn(`[kya-http] pickup anchor create returned ${createResponse.status} (sid=${sid}); suppressing §8.1 challenge`);
161
- }
162
- }
163
- catch (error) {
164
- console.warn(`[kya-http] pickup anchor create failed (sid=${sid}); suppressing §8.1 challenge:`, error instanceof Error ? error.message : String(error));
165
- anchorPersisted = false;
166
- }
167
- if (!anchorPersisted) {
168
- return null;
169
- }
170
- try {
171
- const challengeProof = await signChallengeProof(await deps.proofGenerator(), {
172
- sid,
173
- consent_uri: buildConsentUri(verdict),
174
- required_scopes: verdict.requiredScopes,
175
- });
176
- // Cooperative fetchers get the body-readable 200; everyone else the spec 401.
177
- return wantsBodyReadable200
178
- ? buildFetcherChallengeResponse(verdict, challengeProof)
179
- : buildChallengeResponse(verdict, challengeProof);
180
- }
181
- catch (error) {
182
- // The anchor persisted, but signing/building the challenge failed (e.g. a proof
183
- // generator outage). Suppress the 401 and fall through to the original MCP error
184
- // rather than throwing into a bare 500 — symmetric with the create-failure path
185
- // above. The orphaned anchor is harmless: it expires via its ≤600s TTL.
186
- console.warn(`[kya-http] challenge proof signing failed (sid=${sid}); suppressing §8.1 challenge:`, error instanceof Error ? error.message : String(error));
187
- return null;
188
- }
189
- }
190
- //# sourceMappingURL=challenge-middleware.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"challenge-middleware.js","sourceRoot":"","sources":["../../src/delegation-http/challenge-middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAOH,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EACL,sBAAsB,EACtB,6BAA6B,EAC7B,eAAe,EACf,kBAAkB,GACnB,MAAM,aAAa,CAAC;AASrB;;;GAGG;AACH,KAAK,UAAU,6BAA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AAC,CACvD,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -1,102 +0,0 @@
1
- /**
2
- * draft-kya-http-02 delegation layer — §8.1 challenge emitter (builders + signing).
3
- *
4
- * Byte-exact against the vendored golden fixture
5
- * `src/__tests__/fixtures/kya-http/challenge.delegation.full.json`. The wire format
6
- * is frozen: param order is `CHALLENGE_PARAM_ORDER`, the separator is `", "`, every
7
- * value is a quoted string, `scope` is space-joined, and `min_assurance` is omitted
8
- * ENTIRELY when absent (the whole `min_assurance="…"` token is dropped, not emitted
9
- * empty).
10
- *
11
- * The worker is its own Tier-2 authorization host: `consent_uri`/`pickup_uri` point
12
- * at `authorizationHost`, while the Bearer challenge's `resource_metadata` points at
13
- * the `realm` (the protected resource origin).
14
- *
15
- * @module @kya-os/mcp-i-cloudflare/delegation-http/challenge
16
- */
17
- import type { ChallengeVerdictInput } from "./types";
18
- import type { CloudflareProofGenerator } from "../proof-generator";
19
- /**
20
- * Build the `WWW-Authenticate: Delegation …` header value (§8.1), byte-exact.
21
- *
22
- * Params are emitted in `CHALLENGE_PARAM_ORDER`, joined by `", "`, every value
23
- * quoted. `min_assurance` is dropped entirely when `i.minAssurance` is absent.
24
- */
25
- export declare function buildWWWAuthenticateDelegation(i: ChallengeVerdictInput): string;
26
- /**
27
- * Build the companion `WWW-Authenticate: Bearer …` header value. `resource_metadata`
28
- * points at the protected resource (`realm`), not the authorization host.
29
- */
30
- export declare function buildWWWAuthenticateBearer(realm: string): string;
31
- /** The consent surface URL on the worker's authorization host: `…/consent?sid=<sid>`. */
32
- export declare function buildConsentUri(i: ChallengeVerdictInput): string;
33
- /** The pickup endpoint URL on the worker's authorization host: `…/api/delegation/pickup/<sid>`. */
34
- export declare function buildPickupUri(i: ChallengeVerdictInput): string;
35
- /**
36
- * Build the human-facing `instructions` string (§8.1), gated on the host's
37
- * declared pickup profile (`ChallengeVerdictInput.pickupProfile`).
38
- *
39
- * DEFAULT (no profile): the reviewed token-first choreography — generate an
40
- * unpadded-base64url 32-byte token, establish the binding with it, relay the
41
- * consent link after 202 pending, poll with the SAME token, retry as plain
42
- * Bearer. No did:key polls and no signed retries: this runtime's pickup
43
- * surface treats signature-only polls as no-identity polls, and its mint
44
- * does not `cnf`-bind the delegation to a pickup key, so those directives
45
- * would dead-end a compliant agent (signed poll never binds; signed retry of
46
- * a non-holder-bound VC is refused as `kyaos/holder-mismatch`).
47
- *
48
- * The explicit pickupProfile opt-in retains the reviewed binding-first legacy
49
- * envelope for hosts that support signed pickup. It does not make that legacy
50
- * credential holder-bound. Strict native challenges and their mandatory fresh
51
- * retry proofs are emitted by native-http.ts from the registered native contract.
52
- */
53
- export declare function buildInstructions(i: ChallengeVerdictInput): string;
54
- /**
55
- * Build the §8.1 401 JSON body. Key order mirrors the golden fixture's `http.body`.
56
- * `min_assurance` is omitted when absent.
57
- */
58
- export declare function buildChallengeBody(i: ChallengeVerdictInput, challengeProof: string): object;
59
- /**
60
- * Build the full §8.1 401 `Response`: dual `WWW-Authenticate` challenges (Delegation
61
- * first, then Bearer), `Retry-After`, JSON content type, and `Cache-Control:
62
- * no-store`. Under the native profile the unsigned consent hint headers
63
- * (`KYA-Auth-Required`/`KYA-Auth-Url`/`Link`/`KYA-Action`) are mirrored from the
64
- * fetcher-200 envelope so header-only surfaces see the consent target on the 401
65
- * too; the default legacy envelope stays 1.13.6-shaped.
66
- */
67
- export declare function buildChallengeResponse(i: ChallengeVerdictInput, challengeProof: string): Response;
68
- /**
69
- * Build the body-readable §8.1 **200** `Response` for AI-agent fetchers that drop 4xx
70
- * bodies (draft-kya-http-02 fetcher-compatibility envelope). REUSES `buildChallengeBody`
71
- * so the JSON body is BYTE-IDENTICAL to the 401 — the org-signed `challenge_proof` binds
72
- * the body content, not the HTTP envelope, so the same proof verifies at 200 or 401.
73
- *
74
- * Differs from the 401 (`buildChallengeResponse`) only in the envelope:
75
- * - status `200`, not `401`
76
- * - NO `WWW-Authenticate` (a 200 carrying it is reinterpreted as a 401 by some fetchers,
77
- * re-dropping the body)
78
- * - NO `Retry-After` (cadence lives in the body `poll_interval_s` + instructions)
79
- * - adds the consent hint headers `KYA-Auth-Required`/`KYA-Auth-Url`/`Link` and the
80
- * `KYA-Action: challenge` discriminator.
81
- *
82
- * The authoritative consent target is the proof-covered body `consent_uri`; the
83
- * `KYA-Auth-Url`/`Link` headers are UNSIGNED hints for fetchers that only surface
84
- * headers. Selection is a cooperative-UX bridge, NOT an access control.
85
- */
86
- export declare function buildFetcherChallengeResponse(i: ChallengeVerdictInput, challengeProof: string): Response;
87
- /**
88
- * Sign the `challenge_proof`: a verifiable 3-segment compact JWS whose `requestHash`
89
- * commits to `{ sid, consent_uri, required_scopes }`.
90
- *
91
- * Implemented over the public `CloudflareProofGenerator.generateProof` seam: the
92
- * challenge fields are canonicalized into the proof's request, so the signed
93
- * `requestHash` cryptographically covers them. A verifier recomputes
94
- * `sha256(canonical({ method: "kyaos/challenge", params }))` and checks it equals the
95
- * payload's `requestHash`, then verifies the Ed25519 signature.
96
- */
97
- export declare function signChallengeProof(gen: CloudflareProofGenerator, payload: {
98
- sid: string;
99
- consent_uri: string;
100
- required_scopes: string[];
101
- }): Promise<string>;
102
- //# sourceMappingURL=challenge.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"challenge.d.ts","sourceRoot":"","sources":["../../src/delegation-http/challenge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAUnE;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC5C,CAAC,EAAE,qBAAqB,GACvB,MAAM,CAqBR;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED,yFAAyF;AACzF,wBAAgB,eAAe,CAAC,CAAC,EAAE,qBAAqB,GAAG,MAAM,CAEhE;AAED,mGAAmG;AACnG,wBAAgB,cAAc,CAAC,CAAC,EAAE,qBAAqB,GAAG,MAAM,CAE/D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,qBAAqB,GAAG,MAAM,CAmBlE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,CAAC,EAAE,qBAAqB,EACxB,cAAc,EAAE,MAAM,GACrB,MAAM,CAsCR;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,CAAC,EAAE,qBAAqB,EACxB,cAAc,EAAE,MAAM,GACrB,QAAQ,CAmBV;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,6BAA6B,CAC3C,CAAC,EAAE,qBAAqB,EACxB,cAAc,EAAE,MAAM,GACrB,QAAQ,CAcV;AAED;;;;;;;;;GASG;AACH,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,wBAAwB,EAC7B,OAAO,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,EAAE,CAAA;CAAE,GACvE,OAAO,CAAC,MAAM,CAAC,CAmBjB"}
@@ -1,223 +0,0 @@
1
- /**
2
- * draft-kya-http-02 delegation layer — §8.1 challenge emitter (builders + signing).
3
- *
4
- * Byte-exact against the vendored golden fixture
5
- * `src/__tests__/fixtures/kya-http/challenge.delegation.full.json`. The wire format
6
- * is frozen: param order is `CHALLENGE_PARAM_ORDER`, the separator is `", "`, every
7
- * value is a quoted string, `scope` is space-joined, and `min_assurance` is omitted
8
- * ENTIRELY when absent (the whole `min_assurance="…"` token is dropped, not emitted
9
- * empty).
10
- *
11
- * The worker is its own Tier-2 authorization host: `consent_uri`/`pickup_uri` point
12
- * at `authorizationHost`, while the Bearer challenge's `resource_metadata` points at
13
- * the `realm` (the protected resource origin).
14
- *
15
- * @module @kya-os/mcp-i-cloudflare/delegation-http/challenge
16
- */
17
- import { CHALLENGE_PARAM_ORDER, KYAOS_ERRORS } from "./constants";
18
- /**
19
- * The JSON-RPC method label committed inside the `challenge_proof` JWS. The proof's
20
- * `requestHash` is `sha256(canonical({ method, params: { sid, consent_uri,
21
- * required_scopes } }))`, so the signed proof cryptographically covers the three
22
- * challenge fields. Verifiers recompute this hash to confirm coverage.
23
- */
24
- const CHALLENGE_PROOF_METHOD = "kyaos/challenge";
25
- /**
26
- * Build the `WWW-Authenticate: Delegation …` header value (§8.1), byte-exact.
27
- *
28
- * Params are emitted in `CHALLENGE_PARAM_ORDER`, joined by `", "`, every value
29
- * quoted. `min_assurance` is dropped entirely when `i.minAssurance` is absent.
30
- */
31
- export function buildWWWAuthenticateDelegation(i) {
32
- const values = {
33
- realm: i.realm,
34
- sid: i.sid,
35
- consent_uri: buildConsentUri(i),
36
- pickup_uri: buildPickupUri(i),
37
- scope: i.requiredScopes.join(" "),
38
- min_assurance: i.minAssurance,
39
- interval: String(i.pollIntervalS),
40
- kind: "delegation",
41
- };
42
- const params = CHALLENGE_PARAM_ORDER.filter(
43
- // min_assurance is the only optional param: omit the whole token when absent.
44
- (key) => values[key] !== undefined).map((key) => `${key}="${values[key]}"`);
45
- return `Delegation ${params.join(", ")}`;
46
- }
47
- /**
48
- * Build the companion `WWW-Authenticate: Bearer …` header value. `resource_metadata`
49
- * points at the protected resource (`realm`), not the authorization host.
50
- */
51
- export function buildWWWAuthenticateBearer(realm) {
52
- return `Bearer resource_metadata="https://${realm}/.well-known/oauth-protected-resource"`;
53
- }
54
- /** The consent surface URL on the worker's authorization host: `…/consent?sid=<sid>`. */
55
- export function buildConsentUri(i) {
56
- return `https://${i.authorizationHost}/consent?sid=${i.sid}`;
57
- }
58
- /** The pickup endpoint URL on the worker's authorization host: `…/api/delegation/pickup/<sid>`. */
59
- export function buildPickupUri(i) {
60
- return `https://${i.authorizationHost}/api/delegation/pickup/${i.sid}`;
61
- }
62
- /**
63
- * Build the human-facing `instructions` string (§8.1), gated on the host's
64
- * declared pickup profile (`ChallengeVerdictInput.pickupProfile`).
65
- *
66
- * DEFAULT (no profile): the reviewed token-first choreography — generate an
67
- * unpadded-base64url 32-byte token, establish the binding with it, relay the
68
- * consent link after 202 pending, poll with the SAME token, retry as plain
69
- * Bearer. No did:key polls and no signed retries: this runtime's pickup
70
- * surface treats signature-only polls as no-identity polls, and its mint
71
- * does not `cnf`-bind the delegation to a pickup key, so those directives
72
- * would dead-end a compliant agent (signed poll never binds; signed retry of
73
- * a non-holder-bound VC is refused as `kyaos/holder-mismatch`).
74
- *
75
- * The explicit pickupProfile opt-in retains the reviewed binding-first legacy
76
- * envelope for hosts that support signed pickup. It does not make that legacy
77
- * credential holder-bound. Strict native challenges and their mandatory fresh
78
- * retry proofs are emitted by native-http.ts from the registered native contract.
79
- */
80
- export function buildInstructions(i) {
81
- const consentUri = buildConsentUri(i);
82
- const pickupUri = buildPickupUri(i);
83
- if (i.pickupProfile === "kya-http/2") {
84
- return (`This action requires human authorization. First establish your pickup binding at ${pickupUri}. ` +
85
- `If you can sign HTTP requests, sign each poll with an ephemeral did:key; otherwise generate one random 32-byte token encoded as unpadded base64url and send it as X-KYA-Pickup-Token on EVERY poll. ` +
86
- `After receiving 202 pending, show your user this link and ask them to approve: ${consentUri}. ` +
87
- `Continue polling ${pickupUri} every ${i.pollIntervalS} seconds with the same binding. ` +
88
- `When the response status is 200, take the 'delegation' value and retry your original request with header 'Authorization: Bearer <delegation>'.`);
89
- }
90
- return (`This action requires human authorization. Generate one random 32-byte token encoded as unpadded base64url and keep it for this authorization request. ` +
91
- `First establish your pickup binding at ${pickupUri} by sending that token as X-KYA-Pickup-Token. ` +
92
- `After receiving 202 pending, show your user this link and ask them to approve: ${consentUri}. ` +
93
- `Continue polling ${pickupUri} every ${i.pollIntervalS} seconds with the same X-KYA-Pickup-Token on EVERY poll. ` +
94
- `When the response status is 200, take the 'delegation' value and retry your original request with header 'Authorization: Bearer <delegation>'.`);
95
- }
96
- /**
97
- * Build the §8.1 401 JSON body. Key order mirrors the golden fixture's `http.body`.
98
- * `min_assurance` is omitted when absent.
99
- */
100
- export function buildChallengeBody(i, challengeProof) {
101
- const kyaos = {
102
- sid: i.sid,
103
- consent_uri: buildConsentUri(i),
104
- pickup_uri: buildPickupUri(i),
105
- required_scopes: i.requiredScopes,
106
- };
107
- if (i.minAssurance !== undefined) {
108
- kyaos.min_assurance = i.minAssurance;
109
- }
110
- kyaos.poll_interval_s = i.pollIntervalS;
111
- kyaos.challenge_proof = challengeProof;
112
- if (i.pickupProfile === "kya-http/2") {
113
- // Machine-readable choreography descriptor: agents that parse structure
114
- // instead of prose read the pin header and retry presentation from here.
115
- // Key order mirrors the golden fixture's `kyaos.action`. NATIVE PROFILE
116
- // ONLY: checkpoint's legacy-drift boundary treats this block's presence
117
- // as a reviewed signal of native pickup support, so the default legacy
118
- // body stays 1.13.6-shaped (no action block).
119
- kyaos.action = {
120
- type: "delegation",
121
- consent_uri: buildConsentUri(i),
122
- pickup_uri: buildPickupUri(i),
123
- poll_interval_s: i.pollIntervalS,
124
- pin: { header: "X-KYA-Pickup-Token" },
125
- retry: {
126
- header: "Authorization",
127
- scheme: "Bearer",
128
- value_from: "delegation",
129
- },
130
- };
131
- }
132
- return {
133
- error: KYAOS_ERRORS.authorizationRequired,
134
- kyaos,
135
- instructions: buildInstructions(i),
136
- };
137
- }
138
- /**
139
- * Build the full §8.1 401 `Response`: dual `WWW-Authenticate` challenges (Delegation
140
- * first, then Bearer), `Retry-After`, JSON content type, and `Cache-Control:
141
- * no-store`. Under the native profile the unsigned consent hint headers
142
- * (`KYA-Auth-Required`/`KYA-Auth-Url`/`Link`/`KYA-Action`) are mirrored from the
143
- * fetcher-200 envelope so header-only surfaces see the consent target on the 401
144
- * too; the default legacy envelope stays 1.13.6-shaped.
145
- */
146
- export function buildChallengeResponse(i, challengeProof) {
147
- const consentUri = buildConsentUri(i);
148
- const headers = new Headers();
149
- headers.append("WWW-Authenticate", buildWWWAuthenticateDelegation(i));
150
- headers.append("WWW-Authenticate", buildWWWAuthenticateBearer(i.realm));
151
- headers.set("Retry-After", String(i.pollIntervalS));
152
- headers.set("Content-Type", "application/json");
153
- headers.set("Cache-Control", "no-store");
154
- if (i.pickupProfile === "kya-http/2") {
155
- headers.set("KYA-Auth-Required", "true");
156
- headers.set("KYA-Auth-Url", consentUri);
157
- headers.set("Link", `<${consentUri}>; rel="kya-authorize"`);
158
- headers.set("KYA-Action", "challenge");
159
- }
160
- return new Response(JSON.stringify(buildChallengeBody(i, challengeProof)), {
161
- status: 401,
162
- headers,
163
- });
164
- }
165
- /**
166
- * Build the body-readable §8.1 **200** `Response` for AI-agent fetchers that drop 4xx
167
- * bodies (draft-kya-http-02 fetcher-compatibility envelope). REUSES `buildChallengeBody`
168
- * so the JSON body is BYTE-IDENTICAL to the 401 — the org-signed `challenge_proof` binds
169
- * the body content, not the HTTP envelope, so the same proof verifies at 200 or 401.
170
- *
171
- * Differs from the 401 (`buildChallengeResponse`) only in the envelope:
172
- * - status `200`, not `401`
173
- * - NO `WWW-Authenticate` (a 200 carrying it is reinterpreted as a 401 by some fetchers,
174
- * re-dropping the body)
175
- * - NO `Retry-After` (cadence lives in the body `poll_interval_s` + instructions)
176
- * - adds the consent hint headers `KYA-Auth-Required`/`KYA-Auth-Url`/`Link` and the
177
- * `KYA-Action: challenge` discriminator.
178
- *
179
- * The authoritative consent target is the proof-covered body `consent_uri`; the
180
- * `KYA-Auth-Url`/`Link` headers are UNSIGNED hints for fetchers that only surface
181
- * headers. Selection is a cooperative-UX bridge, NOT an access control.
182
- */
183
- export function buildFetcherChallengeResponse(i, challengeProof) {
184
- const consentUri = buildConsentUri(i);
185
- const headers = new Headers();
186
- headers.set("Content-Type", "application/json");
187
- headers.set("Cache-Control", "no-store");
188
- headers.set("KYA-Auth-Required", "true");
189
- headers.set("KYA-Auth-Url", consentUri);
190
- headers.set("Link", `<${consentUri}>; rel="kya-authorize"`);
191
- headers.set("KYA-Action", "challenge");
192
- return new Response(JSON.stringify(buildChallengeBody(i, challengeProof)), {
193
- status: 200,
194
- headers,
195
- });
196
- }
197
- /**
198
- * Sign the `challenge_proof`: a verifiable 3-segment compact JWS whose `requestHash`
199
- * commits to `{ sid, consent_uri, required_scopes }`.
200
- *
201
- * Implemented over the public `CloudflareProofGenerator.generateProof` seam: the
202
- * challenge fields are canonicalized into the proof's request, so the signed
203
- * `requestHash` cryptographically covers them. A verifier recomputes
204
- * `sha256(canonical({ method: "kyaos/challenge", params }))` and checks it equals the
205
- * payload's `requestHash`, then verifies the Ed25519 signature.
206
- */
207
- export async function signChallengeProof(gen, payload) {
208
- const proof = await gen.generateProof({
209
- method: CHALLENGE_PROOF_METHOD,
210
- params: {
211
- sid: payload.sid,
212
- consent_uri: payload.consent_uri,
213
- required_scopes: payload.required_scopes,
214
- },
215
- }, { data: { sid: payload.sid } }, {
216
- // The session binds the proof to this anchor; sid is the natural nonce.
217
- nonce: payload.sid,
218
- audience: payload.consent_uri,
219
- sessionId: payload.sid,
220
- });
221
- return proof.jws;
222
- }
223
- //# sourceMappingURL=challenge.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"challenge.js","sourceRoot":"","sources":["../../src/delegation-http/challenge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIlE;;;;;GAKG;AACH,MAAM,sBAAsB,GAAG,iBAAiB,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,UAAU,8BAA8B,CAC5C,CAAwB;IAExB,MAAM,MAAM,GAGR;QACF,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,GAAG,EAAE,CAAC,CAAC,GAAG;QACV,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC;QAC/B,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC;QAC7B,KAAK,EAAE,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC;QACjC,aAA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