@kya-os/checkpoint-shared 1.4.0 → 1.5.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 (161) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/beacon-types/index.d.mts +448 -432
  3. package/dist/beacon-types/index.d.mts.map +1 -0
  4. package/dist/beacon-types/index.d.ts +448 -432
  5. package/dist/beacon-types/index.d.ts.map +1 -0
  6. package/dist/beacon-types/index.js +286 -182
  7. package/dist/beacon-types/index.mjs +284 -180
  8. package/dist/beacon-types/index.mjs.map +1 -0
  9. package/dist/browser-posture-cookie-Dmq9Brf_.d.mts +5 -0
  10. package/dist/browser-posture-cookie-Dmq9Brf_.d.mts.map +1 -0
  11. package/dist/browser-posture-cookie-Dmq9Brf_.d.ts +5 -0
  12. package/dist/browser-posture-cookie-Dmq9Brf_.d.ts.map +1 -0
  13. package/dist/browser-posture-cookie.d.mts +2 -0
  14. package/dist/browser-posture-cookie.d.ts +2 -0
  15. package/dist/browser-posture-cookie.js +1 -0
  16. package/dist/browser-posture-cookie.mjs +2 -0
  17. package/dist/browser-posture-cookie.mjs.map +1 -0
  18. package/dist/browser-posture-report.d.mts +48 -44
  19. package/dist/browser-posture-report.d.mts.map +1 -0
  20. package/dist/browser-posture-report.d.ts +48 -44
  21. package/dist/browser-posture-report.d.ts.map +1 -0
  22. package/dist/browser-posture-report.js +1 -1
  23. package/dist/browser-posture-report.mjs +2 -1
  24. package/dist/browser-posture-report.mjs.map +1 -0
  25. package/dist/browser-posture.d.mts +82 -75
  26. package/dist/browser-posture.d.mts.map +1 -0
  27. package/dist/browser-posture.d.ts +82 -75
  28. package/dist/browser-posture.d.ts.map +1 -0
  29. package/dist/browser-posture.js +167 -18993
  30. package/dist/browser-posture.mjs +166 -18990
  31. package/dist/browser-posture.mjs.map +1 -0
  32. package/dist/browser.d.mts +323 -316
  33. package/dist/browser.d.mts.map +1 -0
  34. package/dist/browser.d.ts +323 -316
  35. package/dist/browser.d.ts.map +1 -0
  36. package/dist/browser.js +1 -1
  37. package/dist/browser.mjs +2 -1
  38. package/dist/browser.mjs.map +1 -0
  39. package/dist/canonical-signer/index.d.mts +38 -33
  40. package/dist/canonical-signer/index.d.mts.map +1 -0
  41. package/dist/canonical-signer/index.d.ts +38 -33
  42. package/dist/canonical-signer/index.d.ts.map +1 -0
  43. package/dist/canonical-signer/index.js +411 -181
  44. package/dist/canonical-signer/index.mjs +383 -175
  45. package/dist/canonical-signer/index.mjs.map +1 -0
  46. package/dist/clearance.d.mts +30 -0
  47. package/dist/clearance.d.mts.map +1 -0
  48. package/dist/clearance.d.ts +30 -0
  49. package/dist/clearance.d.ts.map +1 -0
  50. package/dist/clearance.js +120 -0
  51. package/dist/clearance.mjs +112 -0
  52. package/dist/clearance.mjs.map +1 -0
  53. package/dist/client-ip-1y2iXAYW.js +237 -0
  54. package/dist/client-ip-HOfe6ucV.mjs +215 -0
  55. package/dist/client-ip-HOfe6ucV.mjs.map +1 -0
  56. package/dist/deploy/index.d.mts +339 -339
  57. package/dist/deploy/index.d.mts.map +1 -0
  58. package/dist/deploy/index.d.ts +339 -339
  59. package/dist/deploy/index.d.ts.map +1 -0
  60. package/dist/deploy/index.js +505 -413
  61. package/dist/deploy/index.mjs +504 -410
  62. package/dist/deploy/index.mjs.map +1 -0
  63. package/dist/errors/index.d.mts +101 -101
  64. package/dist/errors/index.d.mts.map +1 -0
  65. package/dist/errors/index.d.ts +101 -101
  66. package/dist/errors/index.d.ts.map +1 -0
  67. package/dist/errors/index.js +341 -314
  68. package/dist/errors/index.mjs +340 -311
  69. package/dist/errors/index.mjs.map +1 -0
  70. package/dist/external-jr_S4iSS.d.mts +4187 -0
  71. package/dist/external-jr_S4iSS.d.mts.map +1 -0
  72. package/dist/external-jr_S4iSS.d.ts +4187 -0
  73. package/dist/external-jr_S4iSS.d.ts.map +1 -0
  74. package/dist/gateway/index.d.mts +138 -132
  75. package/dist/gateway/index.d.mts.map +1 -0
  76. package/dist/gateway/index.d.ts +138 -132
  77. package/dist/gateway/index.d.ts.map +1 -0
  78. package/dist/gateway/index.js +117 -81
  79. package/dist/gateway/index.mjs +116 -78
  80. package/dist/gateway/index.mjs.map +1 -0
  81. package/dist/gateway-client-ip.d.mts +59 -0
  82. package/dist/gateway-client-ip.d.mts.map +1 -0
  83. package/dist/gateway-client-ip.d.ts +59 -0
  84. package/dist/gateway-client-ip.d.ts.map +1 -0
  85. package/dist/gateway-client-ip.js +149 -0
  86. package/dist/gateway-client-ip.mjs +139 -0
  87. package/dist/gateway-client-ip.mjs.map +1 -0
  88. package/dist/index.d.mts +14901 -14246
  89. package/dist/index.d.mts.map +1 -0
  90. package/dist/index.d.ts +14901 -14246
  91. package/dist/index.d.ts.map +1 -0
  92. package/dist/index.js +15180 -31025
  93. package/dist/index.mjs +15065 -30942
  94. package/dist/index.mjs.map +1 -0
  95. package/dist/mcpi/agentshield-api/index.d.mts +45 -44
  96. package/dist/mcpi/agentshield-api/index.d.mts.map +1 -0
  97. package/dist/mcpi/agentshield-api/index.d.ts +45 -44
  98. package/dist/mcpi/agentshield-api/index.d.ts.map +1 -0
  99. package/dist/mcpi/agentshield-api/index.js +0 -2
  100. package/dist/mcpi/agentshield-api/index.mjs +1 -1
  101. package/dist/mcpi/approval-grant/index.d.mts +63 -61
  102. package/dist/mcpi/approval-grant/index.d.mts.map +1 -0
  103. package/dist/mcpi/approval-grant/index.d.ts +63 -61
  104. package/dist/mcpi/approval-grant/index.d.ts.map +1 -0
  105. package/dist/mcpi/approval-grant/index.js +220 -140
  106. package/dist/mcpi/approval-grant/index.mjs +219 -137
  107. package/dist/mcpi/approval-grant/index.mjs.map +1 -0
  108. package/dist/mcpi/dashboard-config/index.d.mts +2323 -2318
  109. package/dist/mcpi/dashboard-config/index.d.mts.map +1 -0
  110. package/dist/mcpi/dashboard-config/index.d.ts +2323 -2318
  111. package/dist/mcpi/dashboard-config/index.d.ts.map +1 -0
  112. package/dist/mcpi/dashboard-config/index.js +605 -458
  113. package/dist/mcpi/dashboard-config/index.mjs +604 -455
  114. package/dist/mcpi/dashboard-config/index.mjs.map +1 -0
  115. package/dist/mcpi/multibase-ed25519.d.mts +10 -8
  116. package/dist/mcpi/multibase-ed25519.d.mts.map +1 -0
  117. package/dist/mcpi/multibase-ed25519.d.ts +10 -8
  118. package/dist/mcpi/multibase-ed25519.d.ts.map +1 -0
  119. package/dist/mcpi/multibase-ed25519.js +182 -106
  120. package/dist/mcpi/multibase-ed25519.mjs +181 -103
  121. package/dist/mcpi/multibase-ed25519.mjs.map +1 -0
  122. package/dist/patterns-CkRVOdtV.js +243 -0
  123. package/dist/patterns-DzkGy_qk.mjs +173 -0
  124. package/dist/patterns-DzkGy_qk.mjs.map +1 -0
  125. package/dist/project-verification-key-C3L5rd8a.js +41 -0
  126. package/dist/project-verification-key-CgSVX9_m.mjs +37 -0
  127. package/dist/project-verification-key-CgSVX9_m.mjs.map +1 -0
  128. package/dist/rolldown-runtime-iY2fYEqi.mjs +19 -0
  129. package/dist/schemas-BmjNLAE7.js +5677 -0
  130. package/dist/schemas-DxY-dk9y.mjs +5511 -0
  131. package/dist/schemas-DxY-dk9y.mjs.map +1 -0
  132. package/dist/signals/index.d.mts +125 -115
  133. package/dist/signals/index.d.mts.map +1 -0
  134. package/dist/signals/index.d.ts +125 -115
  135. package/dist/signals/index.d.ts.map +1 -0
  136. package/dist/signals/index.js +1693 -1536
  137. package/dist/signals/index.mjs +1692 -1533
  138. package/dist/signals/index.mjs.map +1 -0
  139. package/dist/test-fixtures/index.d.mts +124 -119
  140. package/dist/test-fixtures/index.d.mts.map +1 -0
  141. package/dist/test-fixtures/index.d.ts +124 -119
  142. package/dist/test-fixtures/index.d.ts.map +1 -0
  143. package/dist/test-fixtures/index.js +460 -228
  144. package/dist/test-fixtures/index.mjs +459 -225
  145. package/dist/test-fixtures/index.mjs.map +1 -0
  146. package/dist/tool-protection/index.d.mts +343 -343
  147. package/dist/tool-protection/index.d.mts.map +1 -0
  148. package/dist/tool-protection/index.d.ts +343 -343
  149. package/dist/tool-protection/index.d.ts.map +1 -0
  150. package/dist/tool-protection/index.js +366 -285
  151. package/dist/tool-protection/index.mjs +365 -282
  152. package/dist/tool-protection/index.mjs.map +1 -0
  153. package/fixtures/bot-signal-resolution.json +142 -0
  154. package/fixtures/browser-posture-claims.json +421 -0
  155. package/fixtures/browser-posture-headers.json +46 -0
  156. package/fixtures/detection/reason-codes.json +10 -1
  157. package/fixtures/kya-http/challenge.delegation.fetcher-200.json +9 -3
  158. package/fixtures/kya-http/challenge.delegation.full.json +9 -3
  159. package/fixtures/kya-http/challenge.delegation.minimal.json +9 -3
  160. package/fixtures/kya-http/error-codes.json +7 -2
  161. package/package.json +20 -6
@@ -1,248 +1,482 @@
1
- // src/test-fixtures/vault-wire-contract.ts
2
- var VAULT_WIRE_CONTRACT_TEST_KEYPAIR = {
3
- /** 32 bytes of 0x01, base64-encoded. Load into the signer via `loadSigningKey`. */
4
- privateKeyBase64: "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE=",
5
- /** Raw 32-byte Ed25519 public key derived from the private seed, base64-encoded. */
6
- publicKeyBase64: "iojj3XQJ8ZX9UtstPLpdcspnCb8dlBIb83SIAbQPb1w="
1
+ //#region src/test-fixtures/vault-wire-contract.ts
2
+ /**
3
+ * Shared test fixture for the #1532 gateway ↔ vault wire contract.
4
+ *
5
+ * **DO NOT IMPORT FROM PRODUCTION CODE.** This file is exposed only via
6
+ * the `@kya-os/checkpoint-shared/test-fixtures` subpath export so
7
+ * production bundles that import from the root package entry point
8
+ * can't reach it — the tree-shaker has no path to these symbols unless
9
+ * a caller explicitly imports from the test-fixtures subpath.
10
+ *
11
+ * ## Purpose
12
+ *
13
+ * #1532 spans two services that must agree byte-for-byte on:
14
+ *
15
+ * 1. The shape of the JWT assertion the gateway signs
16
+ * 2. The HTTP request body the gateway POSTs to the vault endpoint
17
+ * 3. The claims the vault endpoint extracts after verifying the JWT
18
+ *
19
+ * This fixture pins a known-good input/output pair that both sides'
20
+ * unit tests import. If either side's implementation drifts from the
21
+ * contract (wrong field order, wrong base64url encoding, wrong key
22
+ * derivation, etc), the test against this fixture fails loudly without
23
+ * requiring a live end-to-end test.
24
+ *
25
+ * The fixture values below were generated ONCE by running the gateway
26
+ * side's `signAssertion` function against a deterministic seed + the
27
+ * canonical claims. Ed25519 is deterministic per RFC 8032 §5.1.6, so
28
+ * the same inputs ALWAYS produce the same signature — which is what
29
+ * lets us commit `expectedJwt` as a string literal and assert equality
30
+ * across both sides' test runs.
31
+ *
32
+ * ## Test keypair (NOT PRODUCTION)
33
+ *
34
+ * The private key below is 32 bytes of `0x01` — the simplest possible
35
+ * deterministic seed. It is NOT a real private key and must NEVER be
36
+ * used to sign any real vault assertion. Its only purpose is to produce
37
+ * reproducible fixture bytes that both engineers can check against.
38
+ *
39
+ * The corresponding public key was derived via Node's
40
+ * `createPublicKey(privateKey)` and is included here for Engineer 2's
41
+ * vault-side verification tests — vault tests don't need to reconstruct
42
+ * the private half, only to verify signatures against this public key.
43
+ *
44
+ * ## Claim fixture
45
+ *
46
+ * The `canonicalPayload` matches the wire contract §2.2 sample verbatim:
47
+ * eight claims in the exact order `iss, projectId, userDid, toolName,
48
+ * sessionId, nonce, iat, exp`. Field order is load-bearing because
49
+ * `JSON.stringify` preserves insertion order in V8 and the resulting
50
+ * byte sequence is what Ed25519 signs over — reordering would produce
51
+ * a different signature, breaking cross-service determinism.
52
+ *
53
+ * The `iat`/`exp` timestamps are frozen at `1712975940` / `1712976000`
54
+ * (60-second window ending 2024-04-13T01:20:00Z-ish). Tests that run
55
+ * against this fixture must either (a) not validate `exp` against wall
56
+ * clock time, or (b) use `vi.useFakeTimers({ now: 1712975940000 })` to
57
+ * freeze the clock inside the fixture window.
58
+ */
59
+ /**
60
+ * Test keypair for the wire-contract fixture. Ed25519 private seed is
61
+ * 32 bytes of `0x01`; public key is derived from it.
62
+ *
63
+ * **DO NOT USE IN PRODUCTION.**
64
+ */
65
+ const VAULT_WIRE_CONTRACT_TEST_KEYPAIR = {
66
+ /** 32 bytes of 0x01, base64-encoded. Load into the signer via `loadSigningKey`. */
67
+ privateKeyBase64: "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE=",
68
+ /** Raw 32-byte Ed25519 public key derived from the private seed, base64-encoded. */
69
+ publicKeyBase64: "iojj3XQJ8ZX9UtstPLpdcspnCb8dlBIb83SIAbQPb1w="
7
70
  };
8
- var VAULT_WIRE_CONTRACT_EXPECTED_HEADER = {
9
- alg: "EdDSA",
10
- typ: "JWT",
11
- crv: "Ed25519"
71
+ /**
72
+ * The canonical JWT header both sides expect. Wire contract §2.1:
73
+ * `alg` is `EdDSA` (NOT `Ed25519` — common mistake), `typ` is `JWT`,
74
+ * `crv` is included for disambiguation per RFC 8037 §3.1.
75
+ */
76
+ const VAULT_WIRE_CONTRACT_EXPECTED_HEADER = {
77
+ alg: "EdDSA",
78
+ typ: "JWT",
79
+ crv: "Ed25519"
12
80
  };
13
- var VAULT_WIRE_CONTRACT_CANONICAL_PAYLOAD = {
14
- iss: "did:web:gateway.knowthat.ai",
15
- projectId: "00000000-0000-0000-0000-000000000001",
16
- userDid: "alice@example.test",
17
- toolName: "create_issue",
18
- sessionId: "gateway-oauth-test-sess-01",
19
- nonce: "0123456789abcdef",
20
- iat: 1712975940,
21
- exp: 1712976e3
81
+ /**
82
+ * The canonical payload both sides assert against. Wire contract §2.2
83
+ * order is load-bearing — rearranging these fields will produce a
84
+ * different `expectedJwt` because `JSON.stringify` preserves insertion
85
+ * order.
86
+ */
87
+ const VAULT_WIRE_CONTRACT_CANONICAL_PAYLOAD = {
88
+ iss: "did:web:gateway.knowthat.ai",
89
+ projectId: "00000000-0000-0000-0000-000000000001",
90
+ userDid: "alice@example.test",
91
+ toolName: "create_issue",
92
+ sessionId: "gateway-oauth-test-sess-01",
93
+ nonce: "0123456789abcdef",
94
+ iat: 1712975940,
95
+ exp: 1712976e3
22
96
  };
23
- var VAULT_WIRE_CONTRACT_EXPECTED_JWT = "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCIsImNydiI6IkVkMjU1MTkifQ.eyJpc3MiOiJkaWQ6d2ViOmdhdGV3YXkua25vd3RoYXQuYWkiLCJwcm9qZWN0SWQiOiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDEiLCJ1c2VyRGlkIjoiYWxpY2VAZXhhbXBsZS50ZXN0IiwidG9vbE5hbWUiOiJjcmVhdGVfaXNzdWUiLCJzZXNzaW9uSWQiOiJnYXRld2F5LW9hdXRoLXRlc3Qtc2Vzcy0wMSIsIm5vbmNlIjoiMDEyMzQ1Njc4OWFiY2RlZiIsImlhdCI6MTcxMjk3NTk0MCwiZXhwIjoxNzEyOTc2MDAwfQ.i-7vlvhLiohx6Qg0pXjfmllaDoZ_Fiu8KYW7vovHlQOPw9gsDrOECtM5qymv8bTf__hZKQeU8PyxBHtDusTDAg";
24
- var VAULT_WIRE_CONTRACT_EXPECTED_REQUEST_BODY = {
25
- userDid: "alice@example.test",
26
- envVarNames: ["GITHUB_TOKEN"],
27
- toolName: "create_issue",
28
- sessionId: "gateway-oauth-test-sess-01",
29
- assertion: VAULT_WIRE_CONTRACT_EXPECTED_JWT
97
+ /**
98
+ * The deterministic JWT produced by signing
99
+ * {@link VAULT_WIRE_CONTRACT_CANONICAL_PAYLOAD} with the private half of
100
+ * {@link VAULT_WIRE_CONTRACT_TEST_KEYPAIR}, via the gateway-side
101
+ * `signAssertion` helper.
102
+ *
103
+ * Generated ONCE by running:
104
+ *
105
+ * ```
106
+ * pnpm --filter @kya-os/checkpoint-gateway exec tsx -e "..."
107
+ * ```
108
+ *
109
+ * and committed as a string literal. DO NOT regenerate this value
110
+ * without understanding that both sides of the contract will need to
111
+ * re-validate. If your implementation produces a different JWT for the
112
+ * same canonical inputs, the bug is in YOUR code, not the fixture.
113
+ *
114
+ * Ed25519's deterministic signing property (RFC 8032 §5.1.6) is what
115
+ * makes this string stable across runs, machines, and invocations.
116
+ */
117
+ const VAULT_WIRE_CONTRACT_EXPECTED_JWT = "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCIsImNydiI6IkVkMjU1MTkifQ.eyJpc3MiOiJkaWQ6d2ViOmdhdGV3YXkua25vd3RoYXQuYWkiLCJwcm9qZWN0SWQiOiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDEiLCJ1c2VyRGlkIjoiYWxpY2VAZXhhbXBsZS50ZXN0IiwidG9vbE5hbWUiOiJjcmVhdGVfaXNzdWUiLCJzZXNzaW9uSWQiOiJnYXRld2F5LW9hdXRoLXRlc3Qtc2Vzcy0wMSIsIm5vbmNlIjoiMDEyMzQ1Njc4OWFiY2RlZiIsImlhdCI6MTcxMjk3NTk0MCwiZXhwIjoxNzEyOTc2MDAwfQ.i-7vlvhLiohx6Qg0pXjfmllaDoZ_Fiu8KYW7vovHlQOPw9gsDrOECtM5qymv8bTf__hZKQeU8PyxBHtDusTDAg";
118
+ /**
119
+ * The expected HTTP request body the gateway sends to the vault
120
+ * endpoint for the canonical payload. Wire contract §2.4 — all 5
121
+ * fields are required, `assertion` is the full JWT from
122
+ * {@link VAULT_WIRE_CONTRACT_EXPECTED_JWT}, and `userDid` MUST match
123
+ * the assertion's `userDid` claim (the vault side rejects mismatches
124
+ * with a 403).
125
+ */
126
+ const VAULT_WIRE_CONTRACT_EXPECTED_REQUEST_BODY = {
127
+ userDid: "alice@example.test",
128
+ envVarNames: ["GITHUB_TOKEN"],
129
+ toolName: "create_issue",
130
+ sessionId: "gateway-oauth-test-sess-01",
131
+ assertion: VAULT_WIRE_CONTRACT_EXPECTED_JWT
30
132
  };
31
- var VAULT_WIRE_CONTRACT_URL_PATH = "/api/v1/gateway/vault/00000000-0000-0000-0000-000000000001/resolve";
133
+ /**
134
+ * The canonical vault endpoint URL path for the fixture's projectId.
135
+ * Both sides use this to verify their URL construction logic. Base URL
136
+ * is NOT included — this is the path portion only.
137
+ *
138
+ * Path note: the gateway's vault endpoint lives under
139
+ * `/api/v1/gateway/vault/...`, NOT `/api/v1/vault/...`. The unprefixed
140
+ * `/api/v1/vault/{projectId}/resolve` path is owned by the #1299
141
+ * (VAULT-5) KYA-OS worker flow, which uses `X-API-Key` auth and is
142
+ * architecturally incompatible with #1532's Ed25519-only model per
143
+ * #1542 Decision 1 = B. The gateway gets its own parallel namespace
144
+ * under `/api/v1/gateway/vault/*` so the two flows can coexist
145
+ * without the KYA-OS handler needing auth-branching logic.
146
+ *
147
+ * See the corrected wire contract §2.4 on issue #1532.
148
+ */
149
+ const VAULT_WIRE_CONTRACT_URL_PATH = "/api/v1/gateway/vault/00000000-0000-0000-0000-000000000001/resolve";
32
150
 
33
- // src/test-fixtures/mcpi-delegation-fixture.ts
34
- var MCPI_DELEGATION_TEST_KEYPAIR = {
35
- /** 32 bytes of 0x01, base64-encoded. */
36
- privateKeyBase64: "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE=",
37
- /** Raw 32-byte Ed25519 public key derived from the private seed, base64-encoded. */
38
- publicKeyBase64: "iojj3XQJ8ZX9UtstPLpdcspnCb8dlBIb83SIAbQPb1w="
151
+ //#endregion
152
+ //#region src/test-fixtures/mcpi-delegation-fixture.ts
153
+ /**
154
+ * Shared test fixture for #1531 gateway OAuth ↔ KYA-OS delegation credential contract.
155
+ *
156
+ * **DO NOT IMPORT FROM PRODUCTION CODE.** Exposed only via the
157
+ * `@kya-os/checkpoint-shared/test-fixtures` subpath export.
158
+ *
159
+ * ## Purpose
160
+ *
161
+ * #1531 spans two services that must agree on the VC-JWT wire format:
162
+ *
163
+ * 1. Engineer 2's authorization server (Vercel) — issues the VC-JWT
164
+ * 2. Engineer 1's gateway resolver (Fly) — verifies the VC-JWT
165
+ *
166
+ * This fixture pins a known-good VC-JWT that both sides' tests import.
167
+ * If either side drifts from the contract, the test against this fixture
168
+ * fails loudly.
169
+ *
170
+ * ## Test keypair (NOT PRODUCTION)
171
+ *
172
+ * Reuses the #1532 convention: private key is 32 bytes of `0x01`.
173
+ * Ed25519 is deterministic (RFC 8032 §5.1.6), so same inputs always
174
+ * produce the same signature — which is what makes the expected JWT
175
+ * string stable across runs.
176
+ *
177
+ * ## VC-JWT structure
178
+ *
179
+ * The JWT follows the KYA-OS §6.2 DelegationCredential as W3C VC pattern:
180
+ * - Header: { alg: "EdDSA", typ: "JWT", kid: "<issuer-key-id>" }
181
+ * - Payload: { iss, sub, aud, iat, exp, vc: { ... W3C VC ... }, orgId, orgSlug, sessionId }
182
+ * - vc.credentialSubject.delegation contains the KYA-OS delegation record
183
+ * - vc.credentialStatus contains StatusList2021 revocation reference
184
+ *
185
+ * ## Clock note
186
+ *
187
+ * Timestamps are frozen at iat=1712975940 (April 2024). Tests that validate
188
+ * expiry must use vi.useFakeTimers({ now: 1712975940000 }).
189
+ */
190
+ /** Ed25519 test keypair. DO NOT USE IN PRODUCTION. */
191
+ const MCPI_DELEGATION_TEST_KEYPAIR = {
192
+ /** 32 bytes of 0x01, base64-encoded. */
193
+ privateKeyBase64: "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE=",
194
+ /** Raw 32-byte Ed25519 public key derived from the private seed, base64-encoded. */
195
+ publicKeyBase64: "iojj3XQJ8ZX9UtstPLpdcspnCb8dlBIb83SIAbQPb1w="
39
196
  };
40
- var MCPI_DELEGATION_ISSUER_DID = "did:web:kya.vouched.id:orgs:test-org";
41
- var MCPI_DELEGATION_ISSUER_KID = "did:web:kya.vouched.id:orgs:test-org#key-1";
42
- var MCPI_DELEGATION_AGENT_DID = "did:key:z6MkTestAgent123";
43
- var MCPI_DELEGATION_USER_DID = "did:key:z6MkTestUser456";
44
- var MCPI_DELEGATION_STATUS_LIST_URL = "https://kya.vouched.id/api/v1/gateway/oauth/status-list";
45
- var MCPI_DELEGATION_AUDIENCE = "https://gateway.knowthat.ai";
46
- var MCPI_DELEGATION_CANONICAL_PAYLOAD = {
47
- iss: "did:web:kya.vouched.id:orgs:test-org",
48
- sub: "did:key:z6MkTestAgent123",
49
- aud: "https://gateway.knowthat.ai",
50
- iat: 1712975940,
51
- exp: 1712979540,
52
- vc: {
53
- // Pinned to the legacy `modelcontextprotocol-identity.io` host ON PURPOSE.
54
- // This array is signed over by MCPI_DELEGATION_EXPECTED_JWT (below) and must
55
- // byte-match it, and it must agree with the counterparty's pinned context in
56
- // xmcp-i (`packages/contracts/src/delegation/schemas.ts`). The live minter's
57
- // host migration (`vc-jwt.service.ts` → `schema.kya-os.org`) deliberately does
58
- // NOT move this vector — that requires re-signing both sides of the #1531
59
- // contract in lockstep. Do not "fix" this URL without regenerating the JWT.
60
- "@context": [
61
- "https://www.w3.org/2018/credentials/v1",
62
- "https://schema.modelcontextprotocol-identity.io/xmcp-i/credentials/delegation.v1.0.0.json"
63
- ],
64
- type: ["VerifiableCredential", "DelegationCredential"],
65
- issuer: "did:web:kya.vouched.id:orgs:test-org",
66
- issuanceDate: "2024-04-13T02:39:00.000Z",
67
- expirationDate: "2024-04-13T03:39:00.000Z",
68
- credentialSubject: {
69
- id: "did:key:z6MkTestAgent123",
70
- delegation: {
71
- id: "del-test-001",
72
- issuerDid: "did:web:kya.vouched.id:orgs:test-org",
73
- subjectDid: "did:key:z6MkTestAgent123",
74
- userDid: "did:key:z6MkTestUser456",
75
- userIdentifier: "alice@vouched.id",
76
- scopes: ["mcp"],
77
- constraints: {
78
- notBefore: 1712975940,
79
- notAfter: 1712979540,
80
- scopes: ["mcp"],
81
- audience: "https://gateway.knowthat.ai"
82
- },
83
- status: "active"
84
- }
85
- },
86
- credentialStatus: {
87
- id: "https://kya.vouched.id/api/v1/gateway/oauth/status-list#42",
88
- type: "StatusList2021Entry",
89
- statusPurpose: "revocation",
90
- statusListIndex: "42",
91
- statusListCredential: "https://kya.vouched.id/api/v1/gateway/oauth/status-list"
92
- }
93
- },
94
- orgId: "00000000-0000-0000-0000-000000000010",
95
- orgSlug: "test-org",
96
- sessionId: "00000000-0000-0000-0000-000000000020"
197
+ /** DID of the org issuer (signs the VC-JWT). */
198
+ const MCPI_DELEGATION_ISSUER_DID = "did:web:kya.vouched.id:orgs:test-org";
199
+ /**
200
+ * Key ID of the OAuth signing key in the DID document.
201
+ *
202
+ * DR-1 / E1-P1 moved delegation issuance from the gateway operational DID
203
+ * to per-org issuer DIDs. The verifier resolves the org DID document and
204
+ * looks up that org's `#key-1` method.
205
+ */
206
+ const MCPI_DELEGATION_ISSUER_KID = "did:web:kya.vouched.id:orgs:test-org#key-1";
207
+ /** DID of the test MCP client (agent). */
208
+ const MCPI_DELEGATION_AGENT_DID = "did:key:z6MkTestAgent123";
209
+ /** DID of the authorizing user. */
210
+ const MCPI_DELEGATION_USER_DID = "did:key:z6MkTestUser456";
211
+ /** StatusList2021 endpoint URL. */
212
+ const MCPI_DELEGATION_STATUS_LIST_URL = "https://kya.vouched.id/api/v1/gateway/oauth/status-list";
213
+ /** Audience claim — the gateway's HTTPS origin. */
214
+ const MCPI_DELEGATION_AUDIENCE = "https://gateway.knowthat.ai";
215
+ /**
216
+ * The canonical JWT payload. Field order is load-bearing because
217
+ * JSON.stringify preserves insertion order and Ed25519 signs over
218
+ * the resulting bytes.
219
+ */
220
+ const MCPI_DELEGATION_CANONICAL_PAYLOAD = {
221
+ iss: "did:web:kya.vouched.id:orgs:test-org",
222
+ sub: "did:key:z6MkTestAgent123",
223
+ aud: "https://gateway.knowthat.ai",
224
+ iat: 1712975940,
225
+ exp: 1712979540,
226
+ vc: {
227
+ "@context": ["https://www.w3.org/2018/credentials/v1", "https://schema.modelcontextprotocol-identity.io/xmcp-i/credentials/delegation.v1.0.0.json"],
228
+ type: ["VerifiableCredential", "DelegationCredential"],
229
+ issuer: "did:web:kya.vouched.id:orgs:test-org",
230
+ issuanceDate: "2024-04-13T02:39:00.000Z",
231
+ expirationDate: "2024-04-13T03:39:00.000Z",
232
+ credentialSubject: {
233
+ id: "did:key:z6MkTestAgent123",
234
+ delegation: {
235
+ id: "del-test-001",
236
+ issuerDid: "did:web:kya.vouched.id:orgs:test-org",
237
+ subjectDid: "did:key:z6MkTestAgent123",
238
+ userDid: "did:key:z6MkTestUser456",
239
+ userIdentifier: "alice@vouched.id",
240
+ scopes: ["mcp"],
241
+ constraints: {
242
+ notBefore: 1712975940,
243
+ notAfter: 1712979540,
244
+ scopes: ["mcp"],
245
+ audience: "https://gateway.knowthat.ai"
246
+ },
247
+ status: "active"
248
+ }
249
+ },
250
+ credentialStatus: {
251
+ id: "https://kya.vouched.id/api/v1/gateway/oauth/status-list#42",
252
+ type: "StatusList2021Entry",
253
+ statusPurpose: "revocation",
254
+ statusListIndex: "42",
255
+ statusListCredential: "https://kya.vouched.id/api/v1/gateway/oauth/status-list"
256
+ }
257
+ },
258
+ orgId: "00000000-0000-0000-0000-000000000010",
259
+ orgSlug: "test-org",
260
+ sessionId: "00000000-0000-0000-0000-000000000020"
97
261
  };
98
- var MCPI_DELEGATION_EXPECTED_HEADER = {
99
- alg: "EdDSA",
100
- typ: "JWT",
101
- kid: "did:web:kya.vouched.id:orgs:test-org#key-1"
262
+ const MCPI_DELEGATION_EXPECTED_HEADER = {
263
+ alg: "EdDSA",
264
+ typ: "JWT",
265
+ kid: "did:web:kya.vouched.id:orgs:test-org#key-1"
102
266
  };
103
- var MCPI_DELEGATION_EXPECTED_JWT = "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCIsImtpZCI6ImRpZDp3ZWI6a3lhLnZvdWNoZWQuaWQ6b3Jnczp0ZXN0LW9yZyNrZXktMSJ9.eyJpc3MiOiJkaWQ6d2ViOmt5YS52b3VjaGVkLmlkOm9yZ3M6dGVzdC1vcmciLCJzdWIiOiJkaWQ6a2V5Ono2TWtUZXN0QWdlbnQxMjMiLCJhdWQiOiJodHRwczovL2dhdGV3YXkua25vd3RoYXQuYWkiLCJpYXQiOjE3MTI5NzU5NDAsImV4cCI6MTcxMjk3OTU0MCwidmMiOnsiQGNvbnRleHQiOlsiaHR0cHM6Ly93d3cudzMub3JnLzIwMTgvY3JlZGVudGlhbHMvdjEiLCJodHRwczovL3NjaGVtYS5tb2RlbGNvbnRleHRwcm90b2NvbC1pZGVudGl0eS5pby94bWNwLWkvY3JlZGVudGlhbHMvZGVsZWdhdGlvbi52MS4wLjAuanNvbiJdLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiRGVsZWdhdGlvbkNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiZGlkOndlYjpreWEudm91Y2hlZC5pZDpvcmdzOnRlc3Qtb3JnIiwiaXNzdWFuY2VEYXRlIjoiMjAyNC0wNC0xM1QwMjozOTowMC4wMDBaIiwiZXhwaXJhdGlvbkRhdGUiOiIyMDI0LTA0LTEzVDAzOjM5OjAwLjAwMFoiLCJjcmVkZW50aWFsU3ViamVjdCI6eyJpZCI6ImRpZDprZXk6ejZNa1Rlc3RBZ2VudDEyMyIsImRlbGVnYXRpb24iOnsiaWQiOiJkZWwtdGVzdC0wMDEiLCJpc3N1ZXJEaWQiOiJkaWQ6d2ViOmt5YS52b3VjaGVkLmlkOm9yZ3M6dGVzdC1vcmciLCJzdWJqZWN0RGlkIjoiZGlkOmtleTp6Nk1rVGVzdEFnZW50MTIzIiwidXNlckRpZCI6ImRpZDprZXk6ejZNa1Rlc3RVc2VyNDU2IiwidXNlcklkZW50aWZpZXIiOiJhbGljZUB2b3VjaGVkLmlkIiwic2NvcGVzIjpbIm1jcCJdLCJjb25zdHJhaW50cyI6eyJub3RCZWZvcmUiOjE3MTI5NzU5NDAsIm5vdEFmdGVyIjoxNzEyOTc5NTQwLCJzY29wZXMiOlsibWNwIl0sImF1ZGllbmNlIjoiaHR0cHM6Ly9nYXRld2F5Lmtub3d0aGF0LmFpIn0sInN0YXR1cyI6ImFjdGl2ZSJ9fSwiY3JlZGVudGlhbFN0YXR1cyI6eyJpZCI6Imh0dHBzOi8va3lhLnZvdWNoZWQuaWQvYXBpL3YxL2dhdGV3YXkvb2F1dGgvc3RhdHVzLWxpc3QjNDIiLCJ0eXBlIjoiU3RhdHVzTGlzdDIwMjFFbnRyeSIsInN0YXR1c1B1cnBvc2UiOiJyZXZvY2F0aW9uIiwic3RhdHVzTGlzdEluZGV4IjoiNDIiLCJzdGF0dXNMaXN0Q3JlZGVudGlhbCI6Imh0dHBzOi8va3lhLnZvdWNoZWQuaWQvYXBpL3YxL2dhdGV3YXkvb2F1dGgvc3RhdHVzLWxpc3QifX0sIm9yZ0lkIjoiMDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDEwIiwib3JnU2x1ZyI6InRlc3Qtb3JnIiwic2Vzc2lvbklkIjoiMDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDIwIn0.KEF-cDuLUb-OTJHAXhK2A7VGWpGzdIRY0v4jK-0OXoPqKEadPOHAw1EaEl2V_1NeGyw69V3CRtKug_gx9ZIUBA";
267
+ /**
268
+ * The deterministic VC-JWT produced by signing
269
+ * {@link MCPI_DELEGATION_CANONICAL_PAYLOAD} with the private half of
270
+ * {@link MCPI_DELEGATION_TEST_KEYPAIR}.
271
+ *
272
+ * Generated ONCE. DO NOT regenerate without understanding that both
273
+ * sides of the #1531 contract will need to re-validate.
274
+ *
275
+ * Size: ~1.8KB — well within the 8KB HTTP header budget.
276
+ */
277
+ const MCPI_DELEGATION_EXPECTED_JWT = "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCIsImtpZCI6ImRpZDp3ZWI6a3lhLnZvdWNoZWQuaWQ6b3Jnczp0ZXN0LW9yZyNrZXktMSJ9.eyJpc3MiOiJkaWQ6d2ViOmt5YS52b3VjaGVkLmlkOm9yZ3M6dGVzdC1vcmciLCJzdWIiOiJkaWQ6a2V5Ono2TWtUZXN0QWdlbnQxMjMiLCJhdWQiOiJodHRwczovL2dhdGV3YXkua25vd3RoYXQuYWkiLCJpYXQiOjE3MTI5NzU5NDAsImV4cCI6MTcxMjk3OTU0MCwidmMiOnsiQGNvbnRleHQiOlsiaHR0cHM6Ly93d3cudzMub3JnLzIwMTgvY3JlZGVudGlhbHMvdjEiLCJodHRwczovL3NjaGVtYS5tb2RlbGNvbnRleHRwcm90b2NvbC1pZGVudGl0eS5pby94bWNwLWkvY3JlZGVudGlhbHMvZGVsZWdhdGlvbi52MS4wLjAuanNvbiJdLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiRGVsZWdhdGlvbkNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiZGlkOndlYjpreWEudm91Y2hlZC5pZDpvcmdzOnRlc3Qtb3JnIiwiaXNzdWFuY2VEYXRlIjoiMjAyNC0wNC0xM1QwMjozOTowMC4wMDBaIiwiZXhwaXJhdGlvbkRhdGUiOiIyMDI0LTA0LTEzVDAzOjM5OjAwLjAwMFoiLCJjcmVkZW50aWFsU3ViamVjdCI6eyJpZCI6ImRpZDprZXk6ejZNa1Rlc3RBZ2VudDEyMyIsImRlbGVnYXRpb24iOnsiaWQiOiJkZWwtdGVzdC0wMDEiLCJpc3N1ZXJEaWQiOiJkaWQ6d2ViOmt5YS52b3VjaGVkLmlkOm9yZ3M6dGVzdC1vcmciLCJzdWJqZWN0RGlkIjoiZGlkOmtleTp6Nk1rVGVzdEFnZW50MTIzIiwidXNlckRpZCI6ImRpZDprZXk6ejZNa1Rlc3RVc2VyNDU2IiwidXNlcklkZW50aWZpZXIiOiJhbGljZUB2b3VjaGVkLmlkIiwic2NvcGVzIjpbIm1jcCJdLCJjb25zdHJhaW50cyI6eyJub3RCZWZvcmUiOjE3MTI5NzU5NDAsIm5vdEFmdGVyIjoxNzEyOTc5NTQwLCJzY29wZXMiOlsibWNwIl0sImF1ZGllbmNlIjoiaHR0cHM6Ly9nYXRld2F5Lmtub3d0aGF0LmFpIn0sInN0YXR1cyI6ImFjdGl2ZSJ9fSwiY3JlZGVudGlhbFN0YXR1cyI6eyJpZCI6Imh0dHBzOi8va3lhLnZvdWNoZWQuaWQvYXBpL3YxL2dhdGV3YXkvb2F1dGgvc3RhdHVzLWxpc3QjNDIiLCJ0eXBlIjoiU3RhdHVzTGlzdDIwMjFFbnRyeSIsInN0YXR1c1B1cnBvc2UiOiJyZXZvY2F0aW9uIiwic3RhdHVzTGlzdEluZGV4IjoiNDIiLCJzdGF0dXNMaXN0Q3JlZGVudGlhbCI6Imh0dHBzOi8va3lhLnZvdWNoZWQuaWQvYXBpL3YxL2dhdGV3YXkvb2F1dGgvc3RhdHVzLWxpc3QifX0sIm9yZ0lkIjoiMDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDEwIiwib3JnU2x1ZyI6InRlc3Qtb3JnIiwic2Vzc2lvbklkIjoiMDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDIwIn0.KEF-cDuLUb-OTJHAXhK2A7VGWpGzdIRY0v4jK-0OXoPqKEadPOHAw1EaEl2V_1NeGyw69V3CRtKug_gx9ZIUBA";
104
278
 
105
- // src/test-fixtures/fetcher-200-predicate.ts
106
- var FETCHER_200_PREDICATE_VECTORS = [
107
- {
108
- description: "opt-in header present, non-agent detection \u2192 200 (header is the primary signal)",
109
- headers: { "kya-accept-challenge": "delegation" },
110
- detectionClass: "human",
111
- isAgent: false,
112
- expected: true
113
- },
114
- {
115
- description: "opt-in header present, detection absent \u2192 200",
116
- headers: { "kya-accept-challenge": "delegation" },
117
- detectionClass: null,
118
- isAgent: false,
119
- expected: true
120
- },
121
- {
122
- description: "detected ai_agent (isAgent agrees), no opt-in \u2192 200 (transitional UA heuristic)",
123
- headers: {},
124
- detectionClass: "ai_agent",
125
- isAgent: true,
126
- expected: true
127
- },
128
- {
129
- description: "Accept: text/html on a detected agent \u2192 200 (Accept MUST NOT branch the body)",
130
- headers: { accept: "text/markdown, text/html, */*" },
131
- detectionClass: "ai_agent",
132
- isAgent: true,
133
- expected: true
134
- },
135
- {
136
- description: "ai_agent class but isAgent=false (signals disagree) \u2192 401 (require both, matches .NET + worker)",
137
- headers: {},
138
- detectionClass: "ai_agent",
139
- isAgent: false,
140
- expected: false
141
- },
142
- {
143
- description: "human, no opt-in \u2192 401 (spec path)",
144
- headers: {},
145
- detectionClass: "human",
146
- isAgent: false,
147
- expected: false
148
- },
149
- {
150
- description: "bot, no opt-in \u2192 401 (non-cooperative / spoofer lands on spec path)",
151
- headers: {},
152
- detectionClass: "bot",
153
- isAgent: false,
154
- expected: false
155
- },
156
- {
157
- description: "incomplete_data, no opt-in \u2192 401",
158
- headers: {},
159
- detectionClass: "incomplete_data",
160
- isAgent: false,
161
- expected: false
162
- },
163
- {
164
- description: "no signals at all \u2192 401",
165
- headers: {},
166
- detectionClass: null,
167
- isAgent: false,
168
- expected: false
169
- },
170
- {
171
- description: "empty opt-in value is ignored, human \u2192 401",
172
- headers: { "kya-accept-challenge": "" },
173
- detectionClass: "human",
174
- isAgent: false,
175
- expected: false
176
- }
279
+ //#endregion
280
+ //#region src/test-fixtures/fetcher-200-predicate.ts
281
+ /**
282
+ * The frozen cross-PEP predicate vectors. Keep additions semantic (a new
283
+ * distinct case), never a re-statement of an existing one.
284
+ */
285
+ const FETCHER_200_PREDICATE_VECTORS = [
286
+ {
287
+ description: "opt-in header present, non-agent detection → 200 (header is the primary signal)",
288
+ headers: { "kya-accept-challenge": "delegation" },
289
+ detectionClass: "human",
290
+ isAgent: false,
291
+ expected: true
292
+ },
293
+ {
294
+ description: "opt-in header present, detection absent → 200",
295
+ headers: { "kya-accept-challenge": "delegation" },
296
+ detectionClass: null,
297
+ isAgent: false,
298
+ expected: true
299
+ },
300
+ {
301
+ description: "detected ai_agent (isAgent agrees), no opt-in → 200 (transitional UA heuristic)",
302
+ headers: {},
303
+ detectionClass: "ai_agent",
304
+ isAgent: true,
305
+ expected: true
306
+ },
307
+ {
308
+ description: "Accept: text/html on a detected agent → 200 (Accept MUST NOT branch the body)",
309
+ headers: { accept: "text/markdown, text/html, */*" },
310
+ detectionClass: "ai_agent",
311
+ isAgent: true,
312
+ expected: true
313
+ },
314
+ {
315
+ description: "ai_agent class but isAgent=false (signals disagree) → 401 (require both, matches .NET + worker)",
316
+ headers: {},
317
+ detectionClass: "ai_agent",
318
+ isAgent: false,
319
+ expected: false
320
+ },
321
+ {
322
+ description: "human, no opt-in → 401 (spec path)",
323
+ headers: {},
324
+ detectionClass: "human",
325
+ isAgent: false,
326
+ expected: false
327
+ },
328
+ {
329
+ description: "bot, no opt-in → 401 (non-cooperative / spoofer lands on spec path)",
330
+ headers: {},
331
+ detectionClass: "bot",
332
+ isAgent: false,
333
+ expected: false
334
+ },
335
+ {
336
+ description: "incomplete_data, no opt-in → 401",
337
+ headers: {},
338
+ detectionClass: "incomplete_data",
339
+ isAgent: false,
340
+ expected: false
341
+ },
342
+ {
343
+ description: "no signals at all → 401",
344
+ headers: {},
345
+ detectionClass: null,
346
+ isAgent: false,
347
+ expected: false
348
+ },
349
+ {
350
+ description: "empty opt-in value is ignored, human → 401",
351
+ headers: { "kya-accept-challenge": "" },
352
+ detectionClass: "human",
353
+ isAgent: false,
354
+ expected: false
355
+ }
177
356
  ];
178
357
 
179
- // src/mcpi/delegation-verdict.ts
180
- var REASON_KIND_MAP = {
181
- // --- gateway: apps/gateway/src/lib/mcpi-auth-resolver.ts ---
182
- missing_bearer_token: "claim",
183
- parse_error: "claim",
184
- did_resolve_failed: "resolve",
185
- signature_invalid: "signature",
186
- audience_mismatch: "claim",
187
- expired: "time",
188
- not_yet_valid: "time",
189
- revoked: "revocation",
190
- delegation_inactive: "revocation",
191
- missing_claim: "claim",
192
- claim_invalid: "claim",
193
- // --- gateway: apps/gateway/src/lib/dashboard-delegation-verifier.ts ---
194
- not_configured: "claim",
195
- header_missing: "claim",
196
- claim_mismatch: "claim",
197
- malformed: "claim",
198
- // --- engine-rust: rust/crates/kya-os-engine/src/types.rs BlockReason ---
199
- Revoked: "revocation",
200
- InvalidSignature: "signature",
201
- Unauthenticated: "claim",
202
- Expired: "time",
203
- OutOfScope: "scope"
358
+ //#endregion
359
+ //#region src/mcpi/delegation-verdict.ts
360
+ /**
361
+ * Every raw reason discriminator either runtime can natively emit for the
362
+ * delegation path, mapped onto the coarse taxonomy above.
363
+ *
364
+ * Gateway (`McpiAuthErrorReason` in `mcpi-auth-resolver.ts`,
365
+ * `DashboardVerifyFailure['reason']` in `dashboard-delegation-verifier.ts`):
366
+ * snake_case. Engine (`BlockReason` in `rust/crates/kya-os-engine/src/types.rs`):
367
+ * PascalCase variant names. Unrecognized input is a harness bug (an emitter
368
+ * started producing a reason string neither side has ever emitted before) —
369
+ * `toCoarseReasonKind` throws rather than silently defaulting, so a new raw
370
+ * reason gets a deliberate classification instead of landing in the wrong
371
+ * bucket unnoticed.
372
+ */
373
+ const REASON_KIND_MAP = {
374
+ missing_bearer_token: "claim",
375
+ parse_error: "claim",
376
+ did_resolve_failed: "resolve",
377
+ signature_invalid: "signature",
378
+ audience_mismatch: "claim",
379
+ expired: "time",
380
+ not_yet_valid: "time",
381
+ revoked: "revocation",
382
+ delegation_inactive: "revocation",
383
+ missing_claim: "claim",
384
+ claim_invalid: "claim",
385
+ not_configured: "claim",
386
+ header_missing: "claim",
387
+ claim_mismatch: "claim",
388
+ malformed: "claim",
389
+ Revoked: "revocation",
390
+ InvalidSignature: "signature",
391
+ Unauthenticated: "claim",
392
+ Expired: "time",
393
+ OutOfScope: "scope"
204
394
  };
395
+ /** Map a runtime's native reason discriminator onto the coarse taxonomy. */
205
396
  function toCoarseReasonKind(rawReasonKind) {
206
- const coarse = REASON_KIND_MAP[rawReasonKind];
207
- if (!coarse) {
208
- throw new Error(
209
- `toCoarseReasonKind: unrecognized raw reason kind ${JSON.stringify(rawReasonKind)} \u2014 add it to REASON_KIND_MAP in delegation-verdict.ts with a deliberate coarse classification`
210
- );
211
- }
212
- return coarse;
397
+ const coarse = REASON_KIND_MAP[rawReasonKind];
398
+ if (!coarse) throw new Error(`toCoarseReasonKind: unrecognized raw reason kind ${JSON.stringify(rawReasonKind)} — add it to REASON_KIND_MAP in delegation-verdict.ts with a deliberate coarse classification`);
399
+ return coarse;
213
400
  }
401
+ /** Build a `Permit` verdict. */
214
402
  function permitDelegationVerdict() {
215
- return { kind: "Permit", reason: null };
403
+ return {
404
+ kind: "Permit",
405
+ reason: null
406
+ };
216
407
  }
408
+ /** Build a `Block` verdict from a runtime-native reason discriminator. */
217
409
  function blockDelegationVerdict(rawReasonKind) {
218
- return { kind: "Block", reason: { kind: toCoarseReasonKind(rawReasonKind) } };
410
+ return {
411
+ kind: "Block",
412
+ reason: { kind: toCoarseReasonKind(rawReasonKind) }
413
+ };
219
414
  }
220
415
 
221
- // src/test-fixtures/verdict-evidence-fixture.ts
416
+ //#endregion
417
+ //#region src/test-fixtures/verdict-evidence-fixture.ts
418
+ /**
419
+ * Shared test fixture for P20 verdict-evidence tests (`buildVerdictEvidence`,
420
+ * `reconstructConfidenceFromEvidence` — see `../core/verdict-evidence.ts`).
421
+ *
422
+ * **DO NOT IMPORT FROM PRODUCTION CODE.** Exposed only via the
423
+ * `@kya-os/checkpoint-shared/test-fixtures` subpath export.
424
+ *
425
+ * ## Purpose
426
+ *
427
+ * Four independent test suites each need "one signal, minimal defaults" and
428
+ * "two independent signals whose Noisy-Or reconstruction is a known,
429
+ * hand-verified number" — checkpoint-shared's own unit tests, the
430
+ * enforcement-metadata envelope tests, the activity-log read-side tests, and
431
+ * the pixel-route persistence test. Before this fixture existed, all four
432
+ * hardcoded the SAME two fixtures and the SAME derivation comment
433
+ * independently — a change to one could silently drift from the others.
434
+ * This is the one place that number is computed; every test imports it
435
+ * rather than re-deriving it.
436
+ *
437
+ * ## The known reconstruction
438
+ *
439
+ * `TWO_SIGNAL_EVIDENCE_FIXTURE`'s Noisy-Or confidence, by hand — INCLUDING
440
+ * the `UNCALIBRATED_NOISY_OR_PRIOR` (0.10) leak term every live verdict
441
+ * folds in (bestbrian, PR #4747 review — the earlier version of this
442
+ * fixture omitted it and asserted the wrong number, 94.2):
443
+ *
444
+ * 1 - (1 - 0.10) * (1 - 1.0*0.9) * (1 - 0.6*0.7)
445
+ * = 1 - 0.9 * 0.1 * 0.58
446
+ * = 1 - 0.0522
447
+ * = 0.9478 -> 94.78 (0-100 scale)
448
+ */
449
+ /** A minimal, valid `DetectionSignal`-shaped wire object with sane defaults. */
222
450
  function detectionSignalFixture(overrides = {}) {
223
- return {
224
- signalType: "pattern",
225
- confidence: 80,
226
- weight: 0.4,
227
- source: "tier3_ua_pattern",
228
- explanation: "Matches a known agent UA pattern",
229
- ...overrides
230
- };
451
+ return {
452
+ signalType: "pattern",
453
+ confidence: 80,
454
+ weight: .4,
455
+ source: "tier3_ua_pattern",
456
+ explanation: "Matches a known agent UA pattern",
457
+ ...overrides
458
+ };
231
459
  }
232
- var TWO_SIGNAL_EVIDENCE_FIXTURE = [
233
- detectionSignalFixture({
234
- source: "known_scraper_ua",
235
- signalType: "pattern",
236
- weight: 1,
237
- confidence: 90
238
- }),
239
- detectionSignalFixture({
240
- source: "datacenter_ip",
241
- signalType: "network",
242
- weight: 0.6,
243
- confidence: 70
244
- })
245
- ];
246
- var TWO_SIGNAL_EVIDENCE_EXPECTED_CONFIDENCE = 94.78;
460
+ /**
461
+ * Two independent signals (a pattern match at weight 1.0/confidence 90, a
462
+ * network match at weight 0.6/confidence 70) whose combined Noisy-Or
463
+ * confidence is the hand-verified 94.78 — see the module doc above.
464
+ */
465
+ const TWO_SIGNAL_EVIDENCE_FIXTURE = [detectionSignalFixture({
466
+ source: "known_scraper_ua",
467
+ signalType: "pattern",
468
+ weight: 1,
469
+ confidence: 90
470
+ }), detectionSignalFixture({
471
+ source: "datacenter_ip",
472
+ signalType: "network",
473
+ weight: .6,
474
+ confidence: 70
475
+ })];
476
+ /** The confidence (0-100 scale) `TWO_SIGNAL_EVIDENCE_FIXTURE` reconstructs to,
477
+ * including the Noisy-Or prior — see the module doc above. */
478
+ const TWO_SIGNAL_EVIDENCE_EXPECTED_CONFIDENCE = 94.78;
247
479
 
480
+ //#endregion
248
481
  export { FETCHER_200_PREDICATE_VECTORS, MCPI_DELEGATION_AGENT_DID, MCPI_DELEGATION_AUDIENCE, MCPI_DELEGATION_CANONICAL_PAYLOAD, MCPI_DELEGATION_EXPECTED_HEADER, MCPI_DELEGATION_EXPECTED_JWT, MCPI_DELEGATION_ISSUER_DID, MCPI_DELEGATION_ISSUER_KID, MCPI_DELEGATION_STATUS_LIST_URL, MCPI_DELEGATION_TEST_KEYPAIR, MCPI_DELEGATION_USER_DID, TWO_SIGNAL_EVIDENCE_EXPECTED_CONFIDENCE, TWO_SIGNAL_EVIDENCE_FIXTURE, VAULT_WIRE_CONTRACT_CANONICAL_PAYLOAD, VAULT_WIRE_CONTRACT_EXPECTED_HEADER, VAULT_WIRE_CONTRACT_EXPECTED_JWT, VAULT_WIRE_CONTRACT_EXPECTED_REQUEST_BODY, VAULT_WIRE_CONTRACT_TEST_KEYPAIR, VAULT_WIRE_CONTRACT_URL_PATH, blockDelegationVerdict, detectionSignalFixture, permitDelegationVerdict, toCoarseReasonKind };
482
+ //# sourceMappingURL=index.mjs.map