@kya-os/mcp-i-runtime 1.2.5 → 1.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/auth/types.d.ts +1 -1
  3. package/dist/auth/types.d.ts.map +1 -1
  4. package/dist/config/remote-config.d.ts +3 -3
  5. package/dist/config/remote-config.js +4 -4
  6. package/dist/config/remote-config.js.map +1 -1
  7. package/dist/identity/user-did-manager.d.ts +4 -4
  8. package/dist/identity/user-did-manager.js +5 -5
  9. package/dist/identity/user-did-manager.js.map +1 -1
  10. package/dist/index.d.ts +4 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +11 -3
  13. package/dist/index.js.map +1 -1
  14. package/dist/runtime/audit.d.ts.map +1 -1
  15. package/dist/runtime/audit.js +22 -0
  16. package/dist/runtime/audit.js.map +1 -1
  17. package/dist/runtime/base.d.ts +14 -11
  18. package/dist/runtime/base.d.ts.map +1 -1
  19. package/dist/runtime/base.js +47 -25
  20. package/dist/runtime/base.js.map +1 -1
  21. package/dist/runtime/delegation-denial.d.ts +43 -0
  22. package/dist/runtime/delegation-denial.d.ts.map +1 -0
  23. package/dist/runtime/delegation-denial.js +83 -0
  24. package/dist/runtime/delegation-denial.js.map +1 -0
  25. package/dist/runtime/verified-delegation.d.ts +30 -0
  26. package/dist/runtime/verified-delegation.d.ts.map +1 -0
  27. package/dist/runtime/verified-delegation.js +62 -0
  28. package/dist/runtime/verified-delegation.js.map +1 -0
  29. package/dist/services/access-control.service.d.ts +2 -2
  30. package/dist/services/access-control.service.js +4 -4
  31. package/dist/services/access-control.service.js.map +1 -1
  32. package/dist/services/delegation-error-formatter.d.ts +15 -0
  33. package/dist/services/delegation-error-formatter.d.ts.map +1 -1
  34. package/dist/services/delegation-error-formatter.js +27 -1
  35. package/dist/services/delegation-error-formatter.js.map +1 -1
  36. package/dist/services/oauth-config.service.d.ts +4 -4
  37. package/dist/services/oauth-config.service.d.ts.map +1 -1
  38. package/dist/services/oauth-config.service.js +8 -8
  39. package/dist/services/oauth-config.service.js.map +1 -1
  40. package/dist/services/oauth-provider-registry.d.ts +3 -3
  41. package/dist/services/oauth-provider-registry.js +4 -4
  42. package/dist/services/oauth-provider-registry.js.map +1 -1
  43. package/dist/services/oauth-service.d.ts +8 -8
  44. package/dist/services/oauth-service.d.ts.map +1 -1
  45. package/dist/services/oauth-service.js +8 -8
  46. package/dist/services/oauth-service.js.map +1 -1
  47. package/dist/services/oauth-token-retrieval.service.d.ts +6 -6
  48. package/dist/services/oauth-token-retrieval.service.d.ts.map +1 -1
  49. package/dist/services/oauth-token-retrieval.service.js +5 -5
  50. package/dist/services/provider-resolver.d.ts +1 -1
  51. package/dist/services/provider-resolver.js +4 -4
  52. package/dist/services/provider-resolver.js.map +1 -1
  53. package/dist/services/session-registration.service.d.ts +4 -4
  54. package/dist/services/session-registration.service.d.ts.map +1 -1
  55. package/dist/services/session-registration.service.js +5 -5
  56. package/dist/services/session-registration.service.js.map +1 -1
  57. package/dist/services/tool-protection.service.d.ts +13 -13
  58. package/dist/services/tool-protection.service.js +16 -16
  59. package/dist/services/tool-protection.service.js.map +1 -1
  60. package/dist/types/tool-protection.d.ts +11 -4
  61. package/dist/types/tool-protection.d.ts.map +1 -1
  62. package/dist/types/tool-protection.js +8 -1
  63. package/dist/types/tool-protection.js.map +1 -1
  64. package/package.json +3 -3
  65. package/src/__tests__/index.test.ts +12 -0
  66. package/src/__tests__/integration/full-flow.test.ts +3 -3
  67. package/src/__tests__/runtime/audit-contracts-compat.test.ts +54 -0
  68. package/src/__tests__/runtime/audit.test.ts +172 -0
  69. package/src/__tests__/runtime/delegation-denial.test.ts +115 -0
  70. package/src/__tests__/runtime/process-tool-call-security.test.ts +323 -6
  71. package/src/__tests__/runtime/tool-protection-enforcement.test.ts +21 -6
  72. package/src/__tests__/runtime/verified-delegation.test.ts +129 -0
  73. package/src/__tests__/services/agentshield-integration.test.ts +3 -3
  74. package/src/__tests__/services/oauth-service-secret-resolution.test.ts +1 -1
  75. package/src/__tests__/services/provider-resolver-edge-cases.test.ts +2 -2
  76. package/src/__tests__/services/tool-protection.service.test.ts +1 -1
  77. package/src/auth/types.ts +1 -1
  78. package/src/config/remote-config.ts +4 -4
  79. package/src/identity/user-did-manager.ts +5 -5
  80. package/src/index.ts +15 -0
  81. package/src/runtime/audit.ts +26 -0
  82. package/src/runtime/base.ts +58 -27
  83. package/src/runtime/delegation-denial.ts +107 -0
  84. package/src/runtime/verified-delegation.ts +66 -0
  85. package/src/services/__tests__/access-control.proof-response-validation.test.ts +8 -8
  86. package/src/services/__tests__/delegation-error-formatter.test.ts +156 -0
  87. package/src/services/__tests__/oauth-config.service.test.ts +2 -2
  88. package/src/services/__tests__/oauth-provider-registry.test.ts +1 -1
  89. package/src/services/access-control.service.ts +4 -4
  90. package/src/services/delegation-error-formatter.ts +42 -1
  91. package/src/services/oauth-config.service.d.ts +4 -4
  92. package/src/services/oauth-config.service.ts +9 -9
  93. package/src/services/oauth-provider-registry.d.ts +2 -2
  94. package/src/services/oauth-provider-registry.ts +4 -4
  95. package/src/services/oauth-service.ts +10 -10
  96. package/src/services/oauth-token-retrieval.service.ts +8 -8
  97. package/src/services/provider-resolver.ts +4 -4
  98. package/src/services/session-registration.service.ts +6 -6
  99. package/src/services/tool-protection.service.ts +17 -17
  100. package/src/types/tool-protection.ts +13 -4
@@ -165,13 +165,19 @@ describe("processToolCall Security", () => {
165
165
  session
166
166
  );
167
167
 
168
- // Tool handler SHOULD be called
169
- expect(toolHandler).toHaveBeenCalledWith({ arg: "value" });
168
+ // Tool handler SHOULD be called, with the verified delegation second
169
+ expect(toolHandler).toHaveBeenCalledWith(
170
+ { arg: "value" },
171
+ expect.objectContaining({
172
+ id: "test-delegation",
173
+ scopes: ["tool:execute"],
174
+ })
175
+ );
170
176
  expect(result).toEqual({ result: "success" });
171
177
  });
172
178
 
173
- it("should allow delegation when user_identifier is email and AgentShield verifies it", async () => {
174
- // AgentShield may return email as user_identifier but internally link it to DID
179
+ it("should allow delegation when user_identifier is email and Checkpoint verifies it", async () => {
180
+ // Checkpoint may return email as user_identifier but internally link it to DID
175
181
  mockAccessControlService.verifyDelegation = vi.fn().mockResolvedValue({
176
182
  data: {
177
183
  valid: true,
@@ -179,7 +185,7 @@ describe("processToolCall Security", () => {
179
185
  credential: {
180
186
  scopes: ["tool:execute"],
181
187
  user_identifier: "user@example.com", // Email, not DID
182
- // No user_id field - AgentShield verified internally
188
+ // No user_id field - Checkpoint verified internally
183
189
  },
184
190
  },
185
191
  });
@@ -193,7 +199,7 @@ describe("processToolCall Security", () => {
193
199
 
194
200
  const toolHandler = vi.fn().mockResolvedValue({ result: "success" });
195
201
 
196
- // Should allow because email doesn't start with "did:" - trusted AgentShield verification
202
+ // Should allow because email doesn't start with "did:" - trusted Checkpoint verification
197
203
  const result = await runtime.processToolCall(
198
204
  "protected-tool",
199
205
  { arg: "value" },
@@ -1015,4 +1021,315 @@ describe("processToolCall Security", () => {
1015
1021
  );
1016
1022
  });
1017
1023
  });
1024
+
1025
+ describe("Verified Delegation Handoff", () => {
1026
+ const crisp = {
1027
+ units: "CHF",
1028
+ max_amount: "50.00",
1029
+ product_class: ["https://id.gs1.org/01/09506000134352"],
1030
+ };
1031
+
1032
+ function verifiedResponse(delegationId: string, scopes: string[]) {
1033
+ return {
1034
+ data: {
1035
+ valid: true,
1036
+ delegation_id: delegationId,
1037
+ credential: {
1038
+ agent_did: "did:key:zmock123",
1039
+ user_did: "did:key:zUser123",
1040
+ scopes,
1041
+ constraints: { not_after: 1_900_000_000, crisp },
1042
+ issued_at: 1_800_000_000,
1043
+ created_at: 1_800_000_000,
1044
+ authorization: { type: "none" },
1045
+ },
1046
+ },
1047
+ };
1048
+ }
1049
+
1050
+ const session = {
1051
+ id: "test-session",
1052
+ userDid: "did:key:zUser123",
1053
+ agentDid: "did:key:zmock123",
1054
+ delegationToken: "valid-token",
1055
+ };
1056
+
1057
+ it("passes the verifier's answer to the handler as the second argument", async () => {
1058
+ mockAccessControlService.verifyDelegation = vi
1059
+ .fn()
1060
+ .mockResolvedValue(
1061
+ verifiedResponse("delegation-1", ["tool:execute", "tool:read"])
1062
+ );
1063
+ const toolHandler = vi.fn().mockResolvedValue({ result: "success" });
1064
+
1065
+ await runtime.processToolCall(
1066
+ "protected-tool",
1067
+ { arg: "value" },
1068
+ toolHandler,
1069
+ session
1070
+ );
1071
+
1072
+ expect(toolHandler).toHaveBeenCalledTimes(1);
1073
+ expect(toolHandler).toHaveBeenCalledWith(
1074
+ { arg: "value" },
1075
+ {
1076
+ id: "delegation-1",
1077
+ agentDid: "did:key:zmock123",
1078
+ userDid: "did:key:zUser123",
1079
+ // Scopes come from the verifier, not from the tool's requiredScopes.
1080
+ scopes: ["tool:execute", "tool:read"],
1081
+ constraints: { not_after: 1_900_000_000, crisp },
1082
+ authorizationType: "none",
1083
+ expiresAt: 1_900_000_000,
1084
+ }
1085
+ );
1086
+ });
1087
+
1088
+ it("calls an unprotected tool's handler with exactly one argument", async () => {
1089
+ mockToolProtectionService.checkToolProtection = vi
1090
+ .fn()
1091
+ .mockResolvedValue(null);
1092
+ const toolHandler = vi.fn().mockResolvedValue({ result: "success" });
1093
+
1094
+ await runtime.processToolCall(
1095
+ "public-tool",
1096
+ { arg: "value" },
1097
+ toolHandler,
1098
+ session
1099
+ );
1100
+
1101
+ expect(toolHandler.mock.calls).toEqual([[{ arg: "value" }]]);
1102
+ });
1103
+
1104
+ it("calls the handler with exactly one argument when the verifier returns no credential", async () => {
1105
+ mockAccessControlService.verifyDelegation = vi.fn().mockResolvedValue({
1106
+ data: { valid: true, delegation_id: "kv-delegation" },
1107
+ });
1108
+ const toolHandler = vi.fn().mockResolvedValue({ result: "success" });
1109
+
1110
+ await runtime.processToolCall(
1111
+ "protected-tool",
1112
+ { arg: "value" },
1113
+ toolHandler,
1114
+ session
1115
+ );
1116
+
1117
+ expect(toolHandler.mock.calls).toEqual([[{ arg: "value" }]]);
1118
+ });
1119
+
1120
+ it("gives each of two interleaved calls its own verified delegation", async () => {
1121
+ const releaseFirstVerify: Array<() => void> = [];
1122
+ mockAccessControlService.verifyDelegation = vi
1123
+ .fn()
1124
+ .mockImplementationOnce(
1125
+ () =>
1126
+ new Promise((resolve) => {
1127
+ releaseFirstVerify.push(() =>
1128
+ resolve(verifiedResponse("delegation-first", ["tool:execute"]))
1129
+ );
1130
+ })
1131
+ )
1132
+ .mockResolvedValueOnce(
1133
+ verifiedResponse("delegation-second", ["tool:execute"])
1134
+ );
1135
+ const firstHandler = vi.fn().mockResolvedValue({ result: "first" });
1136
+ const secondHandler = vi.fn().mockResolvedValue({ result: "second" });
1137
+
1138
+ const firstCall = runtime.processToolCall(
1139
+ "protected-tool",
1140
+ { call: 1 },
1141
+ firstHandler,
1142
+ { ...session, delegationToken: "first-token" }
1143
+ );
1144
+ // Let the first call reach its (still pending) verify before starting the second.
1145
+ await vi.waitFor(() => expect(releaseFirstVerify).toHaveLength(1));
1146
+ await runtime.processToolCall(
1147
+ "protected-tool",
1148
+ { call: 2 },
1149
+ secondHandler,
1150
+ { ...session, delegationToken: "second-token" }
1151
+ );
1152
+ releaseFirstVerify[0]();
1153
+ await firstCall;
1154
+
1155
+ expect(firstHandler).toHaveBeenCalledWith(
1156
+ { call: 1 },
1157
+ expect.objectContaining({ id: "delegation-first" })
1158
+ );
1159
+ expect(secondHandler).toHaveBeenCalledWith(
1160
+ { call: 2 },
1161
+ expect.objectContaining({ id: "delegation-second" })
1162
+ );
1163
+ });
1164
+
1165
+ it("does not call the handler when verification fails", async () => {
1166
+ mockAccessControlService.verifyDelegation = vi.fn().mockResolvedValue({
1167
+ data: { valid: false, reason: "revoked" },
1168
+ });
1169
+ const toolHandler = vi.fn().mockResolvedValue({ result: "success" });
1170
+
1171
+ await expect(
1172
+ runtime.processToolCall(
1173
+ "protected-tool",
1174
+ { arg: "value" },
1175
+ toolHandler,
1176
+ session
1177
+ )
1178
+ ).rejects.toThrow(DelegationRequiredError);
1179
+ expect(toolHandler).not.toHaveBeenCalled();
1180
+ });
1181
+ });
1182
+
1183
+ describe("Verifier Denial Codes", () => {
1184
+ const session = {
1185
+ id: "test-session",
1186
+ userDid: "did:key:zUser123",
1187
+ agentDid: "did:key:zmock123",
1188
+ delegationToken: "presented-token",
1189
+ };
1190
+
1191
+ async function denialFor(
1192
+ verifyData: Record<string, unknown>,
1193
+ sessionOverrides: Record<string, unknown> = {}
1194
+ ) {
1195
+ mockAccessControlService.verifyDelegation = vi
1196
+ .fn()
1197
+ .mockResolvedValue({ data: verifyData });
1198
+ const toolHandler = vi.fn().mockResolvedValue({ result: "success" });
1199
+
1200
+ const error = await runtime
1201
+ .processToolCall(
1202
+ "protected-tool",
1203
+ { arg: "value" },
1204
+ toolHandler,
1205
+ { ...session, ...sessionOverrides }
1206
+ )
1207
+ .then(
1208
+ () => undefined,
1209
+ (thrown: unknown) => thrown
1210
+ );
1211
+
1212
+ expect(error).toBeInstanceOf(DelegationRequiredError);
1213
+ expect(toolHandler).not.toHaveBeenCalled();
1214
+ return error as DelegationRequiredError;
1215
+ }
1216
+
1217
+ it("reports a revoked grant without leaking the upstream message or details", async () => {
1218
+ const error = await denialFor({
1219
+ valid: false,
1220
+ error: {
1221
+ code: "delegation_revoked",
1222
+ message: "secret: revoked by admin",
1223
+ details: { reason: "secret fraud case 4411" },
1224
+ },
1225
+ });
1226
+
1227
+ expect(error.denial).toEqual({
1228
+ code: "delegation_revoked",
1229
+ message: "This authorization was revoked. Nothing was executed.",
1230
+ });
1231
+ expect(error.consentUrl).toBeTruthy();
1232
+ expect(error.resumeToken).toBeTruthy();
1233
+ expect(
1234
+ JSON.stringify({ message: error.message, denial: error.denial })
1235
+ ).not.toContain("secret");
1236
+ });
1237
+
1238
+ it("keeps agent_mismatch distinct from user_mismatch", async () => {
1239
+ const agentError = await denialFor({
1240
+ valid: false,
1241
+ error: { code: "agent_mismatch", message: "Agent DID mismatch" },
1242
+ });
1243
+ const userError = await denialFor({
1244
+ valid: false,
1245
+ error: { code: "user_mismatch", message: "User DID mismatch" },
1246
+ });
1247
+
1248
+ expect(agentError.denial?.code).toBe("agent_mismatch");
1249
+ expect(userError.denial?.code).toBe("user_mismatch");
1250
+ });
1251
+
1252
+ it("falls back to a legacy top-level reason only when it is an allowlisted code", async () => {
1253
+ const legacyError = await denialFor({
1254
+ valid: false,
1255
+ reason: "delegation_expired",
1256
+ });
1257
+ const freeTextError = await denialFor({
1258
+ valid: false,
1259
+ reason: "Delegation token invalid or expired",
1260
+ });
1261
+
1262
+ expect(legacyError.denial?.code).toBe("delegation_expired");
1263
+ expect(freeTextError.denial).toBeUndefined();
1264
+ });
1265
+
1266
+ it("reports a native holder binding mismatch from the runtime's own comparison", async () => {
1267
+ const error = await denialFor(
1268
+ {
1269
+ valid: true,
1270
+ delegation_id: "delegation-for-another-holder",
1271
+ credential: {
1272
+ agent_did: "did:key:zSomeoneElse",
1273
+ user_did: "did:key:zUser123",
1274
+ scopes: ["tool:execute"],
1275
+ issued_at: 1,
1276
+ created_at: 1,
1277
+ authorization: { type: "none" },
1278
+ },
1279
+ },
1280
+ { verifiedInvokerDid: "did:key:zAdmittedHolder" }
1281
+ );
1282
+
1283
+ expect(error.denial?.code).toBe("native_binding_mismatch");
1284
+ });
1285
+
1286
+ it("keeps the verifier's own denial code on the native rail", async () => {
1287
+ // A refused grant carries no credential, so a holder comparison against
1288
+ // it is meaningless and must not mask why Checkpoint refused it.
1289
+ const revokedError = await denialFor(
1290
+ {
1291
+ valid: false,
1292
+ error: { code: "delegation_revoked", message: "Revoked" },
1293
+ },
1294
+ { verifiedInvokerDid: "did:key:zAdmittedHolder" }
1295
+ );
1296
+ const unknownCodeError = await denialFor(
1297
+ {
1298
+ valid: false,
1299
+ error: { code: "project_not_found", message: "Project not found" },
1300
+ },
1301
+ { verifiedInvokerDid: "did:key:zAdmittedHolder" }
1302
+ );
1303
+
1304
+ expect(revokedError.denial?.code).toBe("delegation_revoked");
1305
+ expect(unknownCodeError.denial).toBeUndefined();
1306
+ });
1307
+
1308
+ it("leaves the denial undefined for a code outside the allowlist", async () => {
1309
+ const error = await denialFor({
1310
+ valid: false,
1311
+ error: { code: "project_not_found", message: "Project not found" },
1312
+ });
1313
+
1314
+ expect(error.denial).toBeUndefined();
1315
+ expect(error.consentUrl).toBeTruthy();
1316
+ });
1317
+
1318
+ it("leaves the denial undefined when no delegation was presented", async () => {
1319
+ const toolHandler = vi.fn();
1320
+
1321
+ const error = await runtime
1322
+ .processToolCall("protected-tool", {}, toolHandler, {
1323
+ id: "test-session",
1324
+ })
1325
+ .then(
1326
+ () => undefined,
1327
+ (thrown: unknown) => thrown
1328
+ );
1329
+
1330
+ expect(error).toBeInstanceOf(DelegationRequiredError);
1331
+ expect((error as DelegationRequiredError).denial).toBeUndefined();
1332
+ expect(mockAccessControlService.verifyDelegation).not.toHaveBeenCalled();
1333
+ });
1334
+ });
1018
1335
  });
@@ -115,7 +115,10 @@ describe("MCPIRuntimeBase - Tool Protection Enforcement", () => {
115
115
  })
116
116
  );
117
117
 
118
- expect(mockHandler).toHaveBeenCalledWith({ arg: "value" });
118
+ expect(mockHandler).toHaveBeenCalledWith(
119
+ { arg: "value" },
120
+ expect.objectContaining({ id: "test-delegation-id" })
121
+ );
119
122
  expect(result).toEqual({ result: "success" });
120
123
  });
121
124
 
@@ -164,7 +167,10 @@ describe("MCPIRuntimeBase - Tool Protection Enforcement", () => {
164
167
  })
165
168
  );
166
169
 
167
- expect(mockHandler).toHaveBeenCalledWith({ arg: "value" });
170
+ expect(mockHandler).toHaveBeenCalledWith(
171
+ { arg: "value" },
172
+ expect.objectContaining({ id: "test-delegation-id" })
173
+ );
168
174
  expect(result).toEqual({ result: "success" });
169
175
  });
170
176
 
@@ -388,7 +394,10 @@ describe("MCPIRuntimeBase - Tool Protection Enforcement", () => {
388
394
  );
389
395
 
390
396
  expect(mockAccessControlService.verifyDelegation).toHaveBeenCalled();
391
- expect(mockHandler).toHaveBeenCalledWith({ arg: "value" });
397
+ expect(mockHandler).toHaveBeenCalledWith(
398
+ { arg: "value" },
399
+ expect.objectContaining({ id: "test-delegation-id" })
400
+ );
392
401
  expect(result).toEqual({ result: "success" });
393
402
  });
394
403
 
@@ -428,7 +437,10 @@ describe("MCPIRuntimeBase - Tool Protection Enforcement", () => {
428
437
  sessionWithUserA
429
438
  );
430
439
 
431
- expect(mockHandler).toHaveBeenCalledWith({ arg: "value" });
440
+ expect(mockHandler).toHaveBeenCalledWith(
441
+ { arg: "value" },
442
+ expect.objectContaining({ id: "test-delegation-id" })
443
+ );
432
444
  expect(result).toEqual({ result: "success" });
433
445
  });
434
446
 
@@ -469,12 +481,15 @@ describe("MCPIRuntimeBase - Tool Protection Enforcement", () => {
469
481
  sessionWithoutUserDid
470
482
  );
471
483
 
472
- expect(mockHandler).toHaveBeenCalledWith({ arg: "value" });
484
+ expect(mockHandler).toHaveBeenCalledWith(
485
+ { arg: "value" },
486
+ expect.objectContaining({ id: "test-delegation-id" })
487
+ );
473
488
  expect(result).toEqual({ result: "success" });
474
489
  });
475
490
 
476
491
  it("should include user_did in verification request when session.userDid is set", async () => {
477
- // ✅ SECURITY: Verify user_did is sent to AgentShield for user-scoped verification
492
+ // ✅ SECURITY: Verify user_did is sent to Checkpoint for user-scoped verification
478
493
  // This prevents cross-user delegation leakage (Priority 3 fallback issue)
479
494
  mockToolProtectionService.checkToolProtection.mockResolvedValue({
480
495
  requiresDelegation: true,
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Tests for toVerifiedDelegation: the pure mapping from a verify response to
3
+ * the VerifiedDelegation that protected tool handlers receive.
4
+ */
5
+
6
+ import { describe, it, expect } from "vitest";
7
+ import type { VerifyDelegationResponse } from "@kya-os/contracts/agentshield-api";
8
+ import { toVerifiedDelegation } from "../../runtime/verified-delegation";
9
+
10
+ const NOT_AFTER_SECONDS = 1_900_000_000;
11
+
12
+ function checkpointVerifyResponse(
13
+ overrides: Partial<VerifyDelegationResponse> = {}
14
+ ): VerifyDelegationResponse {
15
+ return {
16
+ valid: true,
17
+ delegation_id: "0d6f4c1e-2b1a-4d8e-9a57-5b2f1c7e9d10",
18
+ credential: {
19
+ agent_did: "did:web:knowthat.ai:agents:kya-commerce",
20
+ user_did: "did:key:zUser",
21
+ scopes: ["place_order:execute"],
22
+ constraints: {
23
+ not_before: 0,
24
+ not_after: NOT_AFTER_SECONDS,
25
+ crisp: {
26
+ units: "CHF",
27
+ max_amount: "50.00",
28
+ product_class: ["https://id.gs1.org/01/09506000134352"],
29
+ },
30
+ },
31
+ issued_at: 1_800_000_000,
32
+ created_at: 1_800_000_000,
33
+ authorization: { type: "none" },
34
+ },
35
+ ...overrides,
36
+ };
37
+ }
38
+
39
+ describe("toVerifiedDelegation", () => {
40
+ it("maps a valid verify response, including nested crisp constraints", () => {
41
+ const verified = toVerifiedDelegation(checkpointVerifyResponse());
42
+
43
+ expect(verified).toEqual({
44
+ id: "0d6f4c1e-2b1a-4d8e-9a57-5b2f1c7e9d10",
45
+ agentDid: "did:web:knowthat.ai:agents:kya-commerce",
46
+ userDid: "did:key:zUser",
47
+ scopes: ["place_order:execute"],
48
+ constraints: {
49
+ not_before: 0,
50
+ not_after: NOT_AFTER_SECONDS,
51
+ crisp: {
52
+ units: "CHF",
53
+ max_amount: "50.00",
54
+ product_class: ["https://id.gs1.org/01/09506000134352"],
55
+ },
56
+ },
57
+ authorizationType: "none",
58
+ expiresAt: NOT_AFTER_SECONDS,
59
+ });
60
+ });
61
+
62
+ it("returns undefined when the verifier did not accept the delegation", () => {
63
+ expect(
64
+ toVerifiedDelegation(checkpointVerifyResponse({ valid: false }))
65
+ ).toBeUndefined();
66
+ });
67
+
68
+ it("returns undefined when the verifier returned no credential (KV and memory verifiers)", () => {
69
+ expect(
70
+ toVerifiedDelegation({ valid: true, delegation_id: "kv-delegation" })
71
+ ).toBeUndefined();
72
+ });
73
+
74
+ it.each([
75
+ ["zero", 0],
76
+ ["negative", -1],
77
+ ["a string", "1900000000"],
78
+ ])("sets no expiresAt when not_after is %s", (_label, notAfter) => {
79
+ const response = checkpointVerifyResponse();
80
+ response.credential!.constraints = { not_after: notAfter };
81
+
82
+ const verified = toVerifiedDelegation(response);
83
+
84
+ expect(verified).toBeDefined();
85
+ expect(verified).not.toHaveProperty("expiresAt");
86
+ });
87
+
88
+ it("sets no expiresAt and no constraints when the credential has none", () => {
89
+ const response = checkpointVerifyResponse();
90
+ delete response.credential!.constraints;
91
+
92
+ const verified = toVerifiedDelegation(response);
93
+
94
+ expect(verified).not.toHaveProperty("expiresAt");
95
+ expect(verified).not.toHaveProperty("constraints");
96
+ });
97
+
98
+ it("omits id when the response carries no delegation_id", () => {
99
+ const verified = toVerifiedDelegation(
100
+ checkpointVerifyResponse({ delegation_id: undefined })
101
+ );
102
+
103
+ expect(verified).not.toHaveProperty("id");
104
+ expect(verified?.scopes).toEqual(["place_order:execute"]);
105
+ });
106
+
107
+ it("copies scopes and constraints, so mutating the output leaves the input unchanged", () => {
108
+ const response = checkpointVerifyResponse();
109
+ const verified = toVerifiedDelegation(response)!;
110
+
111
+ verified.scopes.push("admin:everything");
112
+ (verified.constraints!.crisp as Record<string, unknown>).max_amount =
113
+ "999999.00";
114
+
115
+ expect(response.credential!.scopes).toEqual(["place_order:execute"]);
116
+ expect(
117
+ (response.credential!.constraints!.crisp as Record<string, unknown>)
118
+ .max_amount
119
+ ).toBe("50.00");
120
+ });
121
+
122
+ it("treats a non-array scopes field as no scopes rather than trusting it", () => {
123
+ const response = checkpointVerifyResponse();
124
+ (response.credential as unknown as Record<string, unknown>).scopes =
125
+ "place_order:execute";
126
+
127
+ expect(toVerifiedDelegation(response)?.scopes).toEqual([]);
128
+ });
129
+ });
@@ -1,7 +1,7 @@
1
1
  /**
2
- * AgentShield Integration Tests
2
+ * Checkpoint Integration Tests
3
3
  *
4
- * Tests for AgentShield API integration including:
4
+ * Tests for Checkpoint API integration including:
5
5
  * - Tool protection config fetching
6
6
  * - API authentication
7
7
  * - Error handling
@@ -47,7 +47,7 @@ function mockFetchWithTools(tools: Record<string, Partial<ToolProtection>>) {
47
47
  });
48
48
  }
49
49
 
50
- describe("AgentShield Integration", () => {
50
+ describe("Checkpoint Integration", () => {
51
51
  let service: ToolProtectionService;
52
52
  let cache: InMemoryToolProtectionCache;
53
53
  let config: ToolProtectionServiceConfig;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Tests the MCP-I provider-registry model where:
5
5
  * - Client secrets are NOT sent via the API response
6
- * - Agents receive metadata.clientSecretName from AgentShield
6
+ * - Agents receive metadata.clientSecretName from Checkpoint
7
7
  * - Secrets are resolved at runtime from secure storage
8
8
  *
9
9
  * @package @kya-os/mcp-i-core
@@ -416,7 +416,7 @@ describe("ProviderResolver - Edge Cases", () => {
416
416
  await resolver.resolveProvider(toolProtection, "test-project");
417
417
  } catch (error) {
418
418
  const message = (error as Error).message;
419
- expect(message).toContain("AgentShield dashboard");
419
+ expect(message).toContain("Checkpoint dashboard");
420
420
  expect(message).toContain("Configure");
421
421
  }
422
422
  });
@@ -526,7 +526,7 @@ describe("ProviderResolver - Edge Cases", () => {
526
526
  };
527
527
 
528
528
  // Registry has providers but configuredProvider is null
529
- // This simulates AgentShield returning all providers but none configured
529
+ // This simulates Checkpoint returning all providers but none configured
530
530
  (mockRegistry.hasProvider as any).mockReturnValue(false);
531
531
  (mockRegistry.getConfiguredProvider as any).mockReturnValue(null);
532
532
  (mockRegistry.getAllProviders as any).mockReturnValue([
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Tool Protection Service Tests
3
3
  *
4
- * Tests for fetching and caching tool protection configurations from AgentShield API
4
+ * Tests for fetching and caching tool protection configurations from Checkpoint API
5
5
  */
6
6
 
7
7
  import { describe, test, expect, beforeEach, vi, afterEach } from "vitest";
package/src/auth/types.ts CHANGED
@@ -19,7 +19,7 @@ export interface VerifyDelegationResult {
19
19
  /** The delegation record (if found) */
20
20
  delegation?: DelegationRecord;
21
21
 
22
- /** Credential from AgentShield API (includes authorization method) */
22
+ /** Credential from Checkpoint API (includes authorization method) */
23
23
  credential?: {
24
24
  agent_did: string;
25
25
  user_did: string;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Remote Configuration Fetching
3
3
  *
4
- * Service for fetching configuration from remote APIs (AgentShield dashboard)
4
+ * Service for fetching configuration from remote APIs (Checkpoint dashboard)
5
5
  * with caching support for performance optimization.
6
6
  *
7
7
  * C2 (#2916) classification: **product-layer, no DIF equivalent.** These are
@@ -85,9 +85,9 @@ export interface RemoteConfigCache {
85
85
  }
86
86
 
87
87
  /**
88
- * Fetch configuration from remote API (AgentShield dashboard)
88
+ * Fetch configuration from remote API (Checkpoint dashboard)
89
89
  *
90
- * Attempts to fetch configuration from the AgentShield API with caching support.
90
+ * Attempts to fetch configuration from the Checkpoint API with caching support.
91
91
  * Falls back gracefully if remote fetch fails.
92
92
  *
93
93
  * @param options - Remote config options
@@ -136,7 +136,7 @@ export async function fetchRemoteConfig(
136
136
  console.error(
137
137
  '[RemoteConfig] projectId is required for user-scoped delegation. ' +
138
138
  'Agent-only scoping has been deprecated due to security concerns (cross-user delegation leakage). ' +
139
- 'Please configure AGENTSHIELD_PROJECT_ID environment variable.'
139
+ 'Please configure CHECKPOINT_PROJECT_ID environment variable.'
140
140
  );
141
141
  return null;
142
142
  }
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * Phase 5: Anonymous Sessions Until OAuth
7
7
  * - Sessions start anonymous (no userDid) until OAuth completes
8
- * - User DIDs are resolved via AgentShield identity/resolve after OAuth
8
+ * - User DIDs are resolved via Checkpoint identity/resolve after OAuth
9
9
  * - Eliminates DID fragmentation (same user = same DID across sessions)
10
10
  *
11
11
  * DID Resolution Priority:
@@ -253,7 +253,7 @@ export class UserDidManager {
253
253
  *
254
254
  * @remarks
255
255
  * - Phase 5: Sessions start anonymous, no ephemeral DID generation
256
- * - User DIDs are resolved via AgentShield after OAuth completes
256
+ * - User DIDs are resolved via Checkpoint after OAuth completes
257
257
  * - Returns null if no existing DID found (instead of generating ephemeral)
258
258
  */
259
259
  async getOrCreateUserDid(
@@ -354,18 +354,18 @@ export class UserDidManager {
354
354
  }
355
355
 
356
356
  // PHASE 5: No ephemeral DID generation - session stays anonymous
357
- // User DID will be resolved via AgentShield after OAuth completes
357
+ // User DID will be resolved via Checkpoint after OAuth completes
358
358
  return null;
359
359
  }
360
360
 
361
361
  /**
362
362
  * Set user DID for a session (Phase 5: After OAuth resolution)
363
363
  *
364
- * Called after AgentShield identity/resolve returns a persistent user DID.
364
+ * Called after Checkpoint identity/resolve returns a persistent user DID.
365
365
  * Caches the DID and optionally stores in session storage.
366
366
  *
367
367
  * @param sessionId - MCP session ID
368
- * @param userDid - Persistent user DID from AgentShield
368
+ * @param userDid - Persistent user DID from Checkpoint
369
369
  * @param oauthIdentity - OAuth identity for creating persistent mappings
370
370
  */
371
371
  async setUserDidForSession(