@vess-id/ai-identity 0.3.0 → 0.3.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 (90) hide show
  1. package/dist/agent/agent-did-manager.d.ts +50 -0
  2. package/dist/agent/agent-did-manager.d.ts.map +1 -0
  3. package/dist/auth/auth-provider.d.ts +51 -0
  4. package/dist/auth/auth-provider.d.ts.map +1 -0
  5. package/dist/auth/index.d.ts +2 -0
  6. package/dist/auth/index.d.ts.map +1 -0
  7. package/dist/client.d.ts +80 -0
  8. package/dist/client.d.ts.map +1 -0
  9. package/dist/config/index.d.ts +30 -0
  10. package/dist/config/index.d.ts.map +1 -0
  11. package/dist/constraint/__tests__/fixtures/constraint.fixtures.d.ts +56 -0
  12. package/dist/constraint/__tests__/fixtures/constraint.fixtures.d.ts.map +1 -0
  13. package/dist/constraint/constraint-evaluator.d.ts +72 -0
  14. package/dist/constraint/constraint-evaluator.d.ts.map +1 -0
  15. package/dist/constraint/index.d.ts +5 -0
  16. package/dist/constraint/index.d.ts.map +1 -0
  17. package/dist/did/agent.d.ts +52 -0
  18. package/dist/did/agent.d.ts.map +1 -0
  19. package/dist/did/did-utils.d.ts +75 -0
  20. package/dist/did/did-utils.d.ts.map +1 -0
  21. package/dist/did/key-manager.d.ts +19 -0
  22. package/dist/did/key-manager.d.ts.map +1 -0
  23. package/dist/gateway/gateway-client.d.ts +103 -0
  24. package/dist/gateway/gateway-client.d.ts.map +1 -0
  25. package/dist/gateway/index.d.ts +2 -0
  26. package/dist/gateway/index.d.ts.map +1 -0
  27. package/dist/grant/grant-manager.d.ts +140 -0
  28. package/dist/grant/grant-manager.d.ts.map +1 -0
  29. package/dist/grant/index.d.ts +2 -0
  30. package/dist/grant/index.d.ts.map +1 -0
  31. package/dist/identity/device-enroll-manager.d.ts +111 -0
  32. package/dist/identity/device-enroll-manager.d.ts.map +1 -0
  33. package/dist/identity/user-identity-manager.d.ts +69 -0
  34. package/dist/identity/user-identity-manager.d.ts.map +1 -0
  35. package/dist/identity/user-key-pair-manager.d.ts +22 -0
  36. package/dist/identity/user-key-pair-manager.d.ts.map +1 -0
  37. package/dist/index.d.ts +32 -3077
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +350 -45
  40. package/dist/index.js.map +1 -1
  41. package/dist/index.mjs +350 -49
  42. package/dist/index.mjs.map +1 -1
  43. package/dist/memory/memory-manager.d.ts +71 -0
  44. package/dist/memory/memory-manager.d.ts.map +1 -0
  45. package/dist/monitoring/metrics-manager.d.ts +74 -0
  46. package/dist/monitoring/metrics-manager.d.ts.map +1 -0
  47. package/dist/organization/disclosure-config-manager.d.ts +61 -0
  48. package/dist/organization/disclosure-config-manager.d.ts.map +1 -0
  49. package/dist/organization/key-rotation-manager.d.ts +63 -0
  50. package/dist/organization/key-rotation-manager.d.ts.map +1 -0
  51. package/dist/organization/organization-manager.d.ts +38 -0
  52. package/dist/organization/organization-manager.d.ts.map +1 -0
  53. package/dist/registry/access-orchestrator.d.ts +183 -0
  54. package/dist/registry/access-orchestrator.d.ts.map +1 -0
  55. package/dist/registry/action-registry-json.d.ts +1363 -0
  56. package/dist/registry/action-registry-json.d.ts.map +1 -0
  57. package/dist/registry/action-registry.d.ts +65 -0
  58. package/dist/registry/action-registry.d.ts.map +1 -0
  59. package/dist/registry/index.d.ts +4 -0
  60. package/dist/registry/index.d.ts.map +1 -0
  61. package/dist/revocation/revocation-manager.d.ts +98 -0
  62. package/dist/revocation/revocation-manager.d.ts.map +1 -0
  63. package/dist/state/index.d.ts +3 -0
  64. package/dist/state/index.d.ts.map +1 -0
  65. package/dist/state/json-state-store.d.ts +24 -0
  66. package/dist/state/json-state-store.d.ts.map +1 -0
  67. package/dist/state/state-store.interface.d.ts +37 -0
  68. package/dist/state/state-store.interface.d.ts.map +1 -0
  69. package/dist/storage/filesystem-key-storage.d.ts +16 -0
  70. package/dist/storage/filesystem-key-storage.d.ts.map +1 -0
  71. package/dist/storage/index.d.ts +4 -0
  72. package/dist/storage/index.d.ts.map +1 -0
  73. package/dist/storage/key-storage.interface.d.ts +42 -0
  74. package/dist/storage/key-storage.interface.d.ts.map +1 -0
  75. package/dist/storage/memory-key-storage.d.ts +17 -0
  76. package/dist/storage/memory-key-storage.d.ts.map +1 -0
  77. package/dist/tool/tool-manager.d.ts +44 -0
  78. package/dist/tool/tool-manager.d.ts.map +1 -0
  79. package/dist/utils/crypto.d.ts +22 -0
  80. package/dist/utils/crypto.d.ts.map +1 -0
  81. package/dist/utils/sdjwt-client.d.ts +168 -0
  82. package/dist/utils/sdjwt-client.d.ts.map +1 -0
  83. package/dist/vc/api-vc-manager.d.ts +40 -0
  84. package/dist/vc/api-vc-manager.d.ts.map +1 -0
  85. package/dist/vc/vc-manager.d.ts +55 -0
  86. package/dist/vc/vc-manager.d.ts.map +1 -0
  87. package/dist/vp/vp-manager.d.ts +40 -0
  88. package/dist/vp/vp-manager.d.ts.map +1 -0
  89. package/package.json +2 -2
  90. package/dist/index.d.mts +0 -3078
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGrD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAGrD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AACrE,YAAY,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAC/E,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,4BAA4B,EAC5B,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACjE,OAAO,EACL,aAAa,EACb,cAAc,EACd,WAAW,EACX,iBAAiB,GAClB,MAAM,yBAAyB,CAAA;AAGhC,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,GAChB,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EACL,uBAAuB,EACvB,4BAA4B,EAC5B,0BAA0B,GAC3B,MAAM,0CAA0C,CAAA;AAGjD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAC5F,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,iCAAiC,CAAA;AAGxC,OAAO,EACL,mBAAmB,EACnB,0BAA0B,EAC1B,0BAA0B,EAC1B,mBAAmB,EACpB,MAAM,mCAAmC,CAAA;AAG1C,cAAc,WAAW,CAAA;AAGzB,YAAY,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAGzD,OAAO,EACL,aAAa,EACb,YAAY,GACb,MAAM,0BAA0B,CAAA;AACjC,YAAY,EACV,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,0BAA0B,CAAA;AAGjC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnD,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAErD,cAAc,YAAY,CAAA;AAG1B,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAGlD,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,uBAAuB,EACvB,aAAa,EACb,eAAe,GAChB,MAAM,iBAAiB,CAAA;AAGxB,cAAc,4BAA4B,CAAA;AAG1C,eAAO,MAAM,OAAO,UAAU,CAAA"}
package/dist/index.js CHANGED
@@ -37,12 +37,16 @@ __export(index_exports, {
37
37
  AgentDIDManager: () => AgentDIDManager,
38
38
  AgentManager: () => AgentManager,
39
39
  AllowAllAbac: () => AllowAllAbac,
40
+ AuthProvider: () => AuthProvider,
40
41
  ConstraintEvaluator: () => ConstraintEvaluator,
41
42
  DeviceEnrollManager: () => DeviceEnrollManager,
42
43
  DisclosureConfigManager: () => DisclosureConfigManager,
43
44
  DummyCreds: () => DummyCreds,
44
45
  DummyVpVerifier: () => DummyVpVerifier,
45
46
  FilesystemKeyStorage: () => FilesystemKeyStorage,
47
+ GatewayClient: () => GatewayClient,
48
+ GatewayError: () => GatewayError,
49
+ JsonStateStore: () => JsonStateStore,
46
50
  KeyManager: () => KeyManager,
47
51
  KeyRotationManager: () => KeyRotationManager,
48
52
  MemoryKeyStorage: () => MemoryKeyStorage,
@@ -100,26 +104,26 @@ function configure(config) {
100
104
  function getConfig() {
101
105
  return globalConfig;
102
106
  }
103
- function getDidApiUrl(path3) {
107
+ function getDidApiUrl(path4) {
104
108
  const baseUrl = globalConfig.didApi?.baseUrl || process.env.DID_API_BASE_URL;
105
109
  if (!baseUrl) {
106
110
  throw new Error("DID API base URL not configured");
107
111
  }
108
- return `${baseUrl}${path3}`;
112
+ return `${baseUrl}${path4}`;
109
113
  }
110
- function getIssuerApiUrl(path3) {
114
+ function getIssuerApiUrl(path4) {
111
115
  const baseUrl = globalConfig.issuerApi?.baseUrl || process.env.ISSUER_API_BASE_URL;
112
116
  if (!baseUrl) {
113
117
  throw new Error("Issuer API base URL not configured");
114
118
  }
115
- return `${baseUrl}${path3}`;
119
+ return `${baseUrl}${path4}`;
116
120
  }
117
- function getVerifierApiUrl(path3) {
121
+ function getVerifierApiUrl(path4) {
118
122
  const baseUrl = globalConfig.verifierApi?.baseUrl || process.env.VERIFIER_API_BASE_URL;
119
123
  if (!baseUrl) {
120
124
  throw new Error("Verifier API base URL not configured");
121
125
  }
122
- return `${baseUrl}${path3}`;
126
+ return `${baseUrl}${path4}`;
123
127
  }
124
128
  function getApiHeaders(apiType) {
125
129
  const headers = {
@@ -966,12 +970,12 @@ var AgentDIDManager = class {
966
970
  * List all agent DIDs
967
971
  */
968
972
  async listAgentDIDs() {
969
- const fs3 = await import("fs/promises");
970
- const path3 = await import("path");
971
- const os2 = await import("os");
972
- const mappingDir = path3.join(os2.homedir(), ".vess-aidentity", "agent-dids");
973
+ const fs4 = await import("fs/promises");
974
+ const path4 = await import("path");
975
+ const os3 = await import("os");
976
+ const mappingDir = path4.join(os3.homedir(), ".vess-aidentity", "agent-dids");
973
977
  try {
974
- const files = await fs3.readdir(mappingDir);
978
+ const files = await fs4.readdir(mappingDir);
975
979
  const results = [];
976
980
  for (const file of files) {
977
981
  if (file.endsWith(".did")) {
@@ -992,24 +996,24 @@ var AgentDIDManager = class {
992
996
  * Save agent ID -> DID mapping to persistent storage
993
997
  */
994
998
  async saveAgentDIDMapping(agentId, did) {
995
- const fs3 = await import("fs/promises");
996
- const path3 = await import("path");
997
- const os2 = await import("os");
998
- const mappingDir = path3.join(os2.homedir(), ".vess-aidentity", "agent-dids");
999
- await fs3.mkdir(mappingDir, { recursive: true });
1000
- const mappingFile = path3.join(mappingDir, `${agentId}.did`);
1001
- await fs3.writeFile(mappingFile, did, "utf-8");
999
+ const fs4 = await import("fs/promises");
1000
+ const path4 = await import("path");
1001
+ const os3 = await import("os");
1002
+ const mappingDir = path4.join(os3.homedir(), ".vess-aidentity", "agent-dids");
1003
+ await fs4.mkdir(mappingDir, { recursive: true });
1004
+ const mappingFile = path4.join(mappingDir, `${agentId}.did`);
1005
+ await fs4.writeFile(mappingFile, did, "utf-8");
1002
1006
  }
1003
1007
  /**
1004
1008
  * Load agent ID -> DID mapping from persistent storage
1005
1009
  */
1006
1010
  async loadAgentDIDMapping(agentId) {
1007
- const fs3 = await import("fs/promises");
1008
- const path3 = await import("path");
1009
- const os2 = await import("os");
1010
- const mappingFile = path3.join(os2.homedir(), ".vess", "agent-dids", `${agentId}.did`);
1011
+ const fs4 = await import("fs/promises");
1012
+ const path4 = await import("path");
1013
+ const os3 = await import("os");
1014
+ const mappingFile = path4.join(os3.homedir(), ".vess", "agent-dids", `${agentId}.did`);
1011
1015
  try {
1012
- return await fs3.readFile(mappingFile, "utf-8");
1016
+ return await fs4.readFile(mappingFile, "utf-8");
1013
1017
  } catch {
1014
1018
  return null;
1015
1019
  }
@@ -1018,12 +1022,12 @@ var AgentDIDManager = class {
1018
1022
  * Delete agent ID -> DID mapping from persistent storage
1019
1023
  */
1020
1024
  async deleteAgentDIDMapping(agentId) {
1021
- const fs3 = await import("fs/promises");
1022
- const path3 = await import("path");
1023
- const os2 = await import("os");
1024
- const mappingFile = path3.join(os2.homedir(), ".vess", "agent-dids", `${agentId}.did`);
1025
+ const fs4 = await import("fs/promises");
1026
+ const path4 = await import("path");
1027
+ const os3 = await import("os");
1028
+ const mappingFile = path4.join(os3.homedir(), ".vess", "agent-dids", `${agentId}.did`);
1025
1029
  try {
1026
- await fs3.unlink(mappingFile);
1030
+ await fs4.unlink(mappingFile);
1027
1031
  } catch {
1028
1032
  }
1029
1033
  }
@@ -1295,24 +1299,24 @@ var UserIdentityManager = class {
1295
1299
  * Save current user DID to persistent storage
1296
1300
  */
1297
1301
  async saveUserDID(did) {
1298
- const fs3 = await import("fs/promises");
1299
- const path3 = await import("path");
1300
- const os2 = await import("os");
1301
- const configDir = path3.join(os2.homedir(), ".vess-aidentity");
1302
- await fs3.mkdir(configDir, { recursive: true });
1303
- const userDIDFile = path3.join(configDir, "user-did.txt");
1304
- await fs3.writeFile(userDIDFile, did, "utf-8");
1302
+ const fs4 = await import("fs/promises");
1303
+ const path4 = await import("path");
1304
+ const os3 = await import("os");
1305
+ const configDir = path4.join(os3.homedir(), ".vess-aidentity");
1306
+ await fs4.mkdir(configDir, { recursive: true });
1307
+ const userDIDFile = path4.join(configDir, "user-did.txt");
1308
+ await fs4.writeFile(userDIDFile, did, "utf-8");
1305
1309
  }
1306
1310
  /**
1307
1311
  * Load current user DID from persistent storage
1308
1312
  */
1309
1313
  async loadUserDID() {
1310
- const fs3 = await import("fs/promises");
1311
- const path3 = await import("path");
1312
- const os2 = await import("os");
1313
- const userDIDFile = path3.join(os2.homedir(), ".vess-aidentity", "user-did.txt");
1314
+ const fs4 = await import("fs/promises");
1315
+ const path4 = await import("path");
1316
+ const os3 = await import("os");
1317
+ const userDIDFile = path4.join(os3.homedir(), ".vess-aidentity", "user-did.txt");
1314
1318
  try {
1315
- return await fs3.readFile(userDIDFile, "utf-8");
1319
+ return await fs4.readFile(userDIDFile, "utf-8");
1316
1320
  } catch {
1317
1321
  return null;
1318
1322
  }
@@ -1321,12 +1325,12 @@ var UserIdentityManager = class {
1321
1325
  * Clear saved user DID
1322
1326
  */
1323
1327
  async clearUserDID() {
1324
- const fs3 = await import("fs/promises");
1325
- const path3 = await import("path");
1326
- const os2 = await import("os");
1327
- const userDIDFile = path3.join(os2.homedir(), ".vess-aidentity", "user-did.txt");
1328
+ const fs4 = await import("fs/promises");
1329
+ const path4 = await import("path");
1330
+ const os3 = await import("os");
1331
+ const userDIDFile = path4.join(os3.homedir(), ".vess-aidentity", "user-did.txt");
1328
1332
  try {
1329
- await fs3.unlink(userDIDFile);
1333
+ await fs4.unlink(userDIDFile);
1330
1334
  } catch {
1331
1335
  }
1332
1336
  }
@@ -4027,6 +4031,303 @@ function evaluateConstraints(constraints, context, currentInvocations, expiresAt
4027
4031
  return defaultConstraintEvaluator.evaluate(constraints, context, currentInvocations, expiresAt);
4028
4032
  }
4029
4033
 
4034
+ // src/state/json-state-store.ts
4035
+ var fs2 = __toESM(require("fs/promises"));
4036
+ var path2 = __toESM(require("path"));
4037
+ var os2 = __toESM(require("os"));
4038
+ var JsonStateStore = class {
4039
+ filePath;
4040
+ data = null;
4041
+ constructor(filePath) {
4042
+ this.filePath = filePath || path2.join(os2.homedir(), ".vess", "state.json");
4043
+ }
4044
+ async get(key) {
4045
+ const data = await this.load();
4046
+ return getNestedValue(data, key);
4047
+ }
4048
+ async set(key, value) {
4049
+ const data = await this.load();
4050
+ setNestedValue(data, key, value);
4051
+ await this.save(data);
4052
+ }
4053
+ async delete(key) {
4054
+ const data = await this.load();
4055
+ const existed = getNestedValue(data, key) !== void 0;
4056
+ if (existed) {
4057
+ deleteNestedValue(data, key);
4058
+ await this.save(data);
4059
+ }
4060
+ return existed;
4061
+ }
4062
+ async has(key) {
4063
+ const data = await this.load();
4064
+ return getNestedValue(data, key) !== void 0;
4065
+ }
4066
+ async getAll() {
4067
+ return { ...await this.load() };
4068
+ }
4069
+ async clear() {
4070
+ this.data = {};
4071
+ await this.save(this.data);
4072
+ }
4073
+ /**
4074
+ * Get the file path used by this store (useful for diagnostics)
4075
+ */
4076
+ getFilePath() {
4077
+ return this.filePath;
4078
+ }
4079
+ async load() {
4080
+ if (this.data !== null) {
4081
+ return this.data;
4082
+ }
4083
+ try {
4084
+ const raw = await fs2.readFile(this.filePath, "utf-8");
4085
+ this.data = JSON.parse(raw);
4086
+ } catch (err) {
4087
+ if (err.code === "ENOENT") {
4088
+ this.data = {};
4089
+ } else if (err instanceof SyntaxError) {
4090
+ this.data = {};
4091
+ } else {
4092
+ throw err;
4093
+ }
4094
+ }
4095
+ return this.data;
4096
+ }
4097
+ async save(data) {
4098
+ this.data = data;
4099
+ const dir = path2.dirname(this.filePath);
4100
+ await fs2.mkdir(dir, { recursive: true, mode: 448 });
4101
+ const tmpPath = this.filePath + ".tmp";
4102
+ await fs2.writeFile(tmpPath, JSON.stringify(data, null, 2), { encoding: "utf-8", mode: 384 });
4103
+ await fs2.rename(tmpPath, this.filePath);
4104
+ }
4105
+ };
4106
+ function getNestedValue(obj, key) {
4107
+ const parts = key.split(".");
4108
+ let current = obj;
4109
+ for (const part of parts) {
4110
+ if (current === null || current === void 0 || typeof current !== "object") {
4111
+ return void 0;
4112
+ }
4113
+ current = current[part];
4114
+ }
4115
+ return current;
4116
+ }
4117
+ function setNestedValue(obj, key, value) {
4118
+ const parts = key.split(".");
4119
+ let current = obj;
4120
+ for (let i = 0; i < parts.length - 1; i++) {
4121
+ const part = parts[i];
4122
+ if (current[part] === void 0 || current[part] === null || typeof current[part] !== "object") {
4123
+ current[part] = {};
4124
+ }
4125
+ current = current[part];
4126
+ }
4127
+ current[parts[parts.length - 1]] = value;
4128
+ }
4129
+ function deleteNestedValue(obj, key) {
4130
+ const parts = key.split(".");
4131
+ let current = obj;
4132
+ for (let i = 0; i < parts.length - 1; i++) {
4133
+ const part = parts[i];
4134
+ if (current[part] === void 0 || typeof current[part] !== "object") {
4135
+ return;
4136
+ }
4137
+ current = current[part];
4138
+ }
4139
+ delete current[parts[parts.length - 1]];
4140
+ }
4141
+
4142
+ // src/gateway/gateway-client.ts
4143
+ var GatewayClient = class {
4144
+ baseUrl;
4145
+ stateStore;
4146
+ apiKey;
4147
+ sessionToken;
4148
+ constructor(options) {
4149
+ this.baseUrl = options.baseUrl.replace(/\/+$/, "").replace(/\/v1$/, "");
4150
+ this.stateStore = options.stateStore;
4151
+ this.apiKey = options.apiKey;
4152
+ this.sessionToken = options.sessionToken;
4153
+ }
4154
+ /**
4155
+ * Set session token for authenticated requests
4156
+ */
4157
+ setSessionToken(token) {
4158
+ this.sessionToken = token;
4159
+ }
4160
+ /**
4161
+ * Fetch events from the Gateway.
4162
+ * If cursor is not provided, attempts to load it from StateStore.
4163
+ *
4164
+ * NOTE: The /events long-poll endpoint may not be implemented on the API server yet.
4165
+ * This client is designed to work once the endpoint is available.
4166
+ */
4167
+ async getEvents(options = {}) {
4168
+ let cursor = options.cursor;
4169
+ if (!cursor && this.stateStore) {
4170
+ cursor = await this.stateStore.get("events.cursor");
4171
+ }
4172
+ const params = new URLSearchParams();
4173
+ if (cursor) params.set("cursor", cursor);
4174
+ if (options.limit) params.set("limit", String(options.limit));
4175
+ if (options.waitSeconds !== void 0) params.set("wait", String(options.waitSeconds));
4176
+ const url = `${this.baseUrl}/api/v1/events?${params.toString()}`;
4177
+ const response = await fetch(url, {
4178
+ method: "GET",
4179
+ headers: this.buildHeaders()
4180
+ });
4181
+ if (!response.ok) {
4182
+ const body = await response.text().catch(() => "");
4183
+ throw new GatewayError(
4184
+ `getEvents failed: ${response.status} ${response.statusText}`,
4185
+ response.status,
4186
+ body
4187
+ );
4188
+ }
4189
+ const result = await response.json();
4190
+ if (result.cursor && this.stateStore) {
4191
+ await this.stateStore.set("events.cursor", result.cursor);
4192
+ }
4193
+ return result;
4194
+ }
4195
+ /**
4196
+ * Acknowledge an event (mark as processed).
4197
+ *
4198
+ * NOTE: The /events/:id/ack endpoint may not be implemented on the API server yet.
4199
+ */
4200
+ async ackEvent(eventId) {
4201
+ const url = `${this.baseUrl}/api/v1/events/${encodeURIComponent(eventId)}/ack`;
4202
+ const response = await fetch(url, {
4203
+ method: "POST",
4204
+ headers: this.buildHeaders()
4205
+ });
4206
+ if (!response.ok) {
4207
+ const body = await response.text().catch(() => "");
4208
+ throw new GatewayError(
4209
+ `ackEvent failed: ${response.status} ${response.statusText}`,
4210
+ response.status,
4211
+ body
4212
+ );
4213
+ }
4214
+ return await response.json();
4215
+ }
4216
+ /**
4217
+ * Validate an API key against the Gateway.
4218
+ *
4219
+ * @param apiKey API key to validate
4220
+ * @param projectId Optional project scope
4221
+ * @param requiredScopes Scopes the caller needs — callers should pass the
4222
+ * scopes relevant to their context (e.g. MCP passes
4223
+ * ['mcp:tools:*', 'mcp:memory:*']).
4224
+ */
4225
+ async validateApiKey(apiKey, projectId, requiredScopes) {
4226
+ const url = `${this.baseUrl}/api/mcp/api-keys/validate`;
4227
+ const body = { projectId };
4228
+ if (requiredScopes && requiredScopes.length > 0) {
4229
+ body.requiredScopes = requiredScopes;
4230
+ }
4231
+ const response = await fetch(url, {
4232
+ method: "POST",
4233
+ headers: {
4234
+ "Content-Type": "application/json",
4235
+ "X-API-Key": apiKey
4236
+ },
4237
+ body: JSON.stringify(body)
4238
+ });
4239
+ if (!response.ok) {
4240
+ return { valid: false };
4241
+ }
4242
+ return await response.json();
4243
+ }
4244
+ buildHeaders() {
4245
+ const headers = {
4246
+ "Content-Type": "application/json"
4247
+ };
4248
+ if (this.apiKey) {
4249
+ headers["X-API-Key"] = this.apiKey;
4250
+ }
4251
+ if (this.sessionToken) {
4252
+ headers["Authorization"] = `Bearer ${this.sessionToken}`;
4253
+ }
4254
+ return headers;
4255
+ }
4256
+ };
4257
+ var GatewayError = class extends Error {
4258
+ constructor(message, statusCode, responseBody) {
4259
+ super(message);
4260
+ this.statusCode = statusCode;
4261
+ this.responseBody = responseBody;
4262
+ this.name = "GatewayError";
4263
+ }
4264
+ };
4265
+
4266
+ // src/auth/auth-provider.ts
4267
+ var AuthProvider = class {
4268
+ stateStore;
4269
+ gatewayClient;
4270
+ constructor(stateStore, gatewayClient) {
4271
+ this.stateStore = stateStore;
4272
+ this.gatewayClient = gatewayClient;
4273
+ }
4274
+ /**
4275
+ * Authenticate with an API key. Validates against the Gateway and
4276
+ * persists the result in the StateStore.
4277
+ *
4278
+ * @returns The validation result
4279
+ */
4280
+ async login(apiKey, apiUrl, projectId) {
4281
+ const result = await this.gatewayClient.validateApiKey(apiKey, projectId);
4282
+ if (result.valid) {
4283
+ const authState = {
4284
+ apiKey,
4285
+ apiUrl,
4286
+ userId: result.userId,
4287
+ projectId: result.projectId || projectId,
4288
+ scopes: result.scopes,
4289
+ authenticatedAt: (/* @__PURE__ */ new Date()).toISOString()
4290
+ };
4291
+ await this.stateStore.set("auth", authState);
4292
+ }
4293
+ return result;
4294
+ }
4295
+ /**
4296
+ * Get the current auth state from the StateStore.
4297
+ * Returns undefined if not authenticated.
4298
+ */
4299
+ async getAuthState() {
4300
+ return this.stateStore.get("auth");
4301
+ }
4302
+ /**
4303
+ * Check if we have stored auth credentials
4304
+ */
4305
+ async isAuthenticated() {
4306
+ const auth = await this.getAuthState();
4307
+ return auth !== void 0 && auth.apiKey !== void 0;
4308
+ }
4309
+ /**
4310
+ * Clear auth state (logout)
4311
+ */
4312
+ async logout() {
4313
+ await this.stateStore.delete("auth");
4314
+ }
4315
+ /**
4316
+ * Get the stored API key, or undefined if not authenticated
4317
+ */
4318
+ async getApiKey() {
4319
+ const auth = await this.getAuthState();
4320
+ return auth?.apiKey;
4321
+ }
4322
+ /**
4323
+ * Get the stored API URL, or undefined if not authenticated
4324
+ */
4325
+ async getApiUrl() {
4326
+ const auth = await this.getAuthState();
4327
+ return auth?.apiUrl;
4328
+ }
4329
+ };
4330
+
4030
4331
  // src/registry/action-registry.ts
4031
4332
  var import_ajv = __toESM(require("ajv"));
4032
4333
  var import_ajv_formats = __toESM(require("ajv-formats"));
@@ -4897,12 +5198,16 @@ var version = "0.0.1";
4897
5198
  AgentDIDManager,
4898
5199
  AgentManager,
4899
5200
  AllowAllAbac,
5201
+ AuthProvider,
4900
5202
  ConstraintEvaluator,
4901
5203
  DeviceEnrollManager,
4902
5204
  DisclosureConfigManager,
4903
5205
  DummyCreds,
4904
5206
  DummyVpVerifier,
4905
5207
  FilesystemKeyStorage,
5208
+ GatewayClient,
5209
+ GatewayError,
5210
+ JsonStateStore,
4906
5211
  KeyManager,
4907
5212
  KeyRotationManager,
4908
5213
  MemoryKeyStorage,