@kya-os/checkpoint-shared 1.3.1 → 1.5.0

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