@vess-id/ai-identity 0.2.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.
- package/dist/agent/agent-did-manager.d.ts +50 -0
- package/dist/agent/agent-did-manager.d.ts.map +1 -0
- package/dist/auth/auth-provider.d.ts +51 -0
- package/dist/auth/auth-provider.d.ts.map +1 -0
- package/dist/auth/index.d.ts +2 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/client.d.ts +80 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/config/index.d.ts +30 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/constraint/__tests__/fixtures/constraint.fixtures.d.ts +56 -0
- package/dist/constraint/__tests__/fixtures/constraint.fixtures.d.ts.map +1 -0
- package/dist/constraint/constraint-evaluator.d.ts +72 -0
- package/dist/constraint/constraint-evaluator.d.ts.map +1 -0
- package/dist/constraint/index.d.ts +5 -0
- package/dist/constraint/index.d.ts.map +1 -0
- package/dist/did/agent.d.ts +52 -0
- package/dist/did/agent.d.ts.map +1 -0
- package/dist/did/did-utils.d.ts +75 -0
- package/dist/did/did-utils.d.ts.map +1 -0
- package/dist/did/key-manager.d.ts +19 -0
- package/dist/did/key-manager.d.ts.map +1 -0
- package/dist/gateway/gateway-client.d.ts +103 -0
- package/dist/gateway/gateway-client.d.ts.map +1 -0
- package/dist/gateway/index.d.ts +2 -0
- package/dist/gateway/index.d.ts.map +1 -0
- package/dist/grant/grant-manager.d.ts +140 -0
- package/dist/grant/grant-manager.d.ts.map +1 -0
- package/dist/grant/index.d.ts +2 -0
- package/dist/grant/index.d.ts.map +1 -0
- package/dist/identity/device-enroll-manager.d.ts +111 -0
- package/dist/identity/device-enroll-manager.d.ts.map +1 -0
- package/dist/identity/user-identity-manager.d.ts +69 -0
- package/dist/identity/user-identity-manager.d.ts.map +1 -0
- package/dist/identity/user-key-pair-manager.d.ts +22 -0
- package/dist/identity/user-key-pair-manager.d.ts.map +1 -0
- package/dist/index.d.ts +32 -3013
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +483 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +482 -49
- package/dist/index.mjs.map +1 -1
- package/dist/memory/memory-manager.d.ts +71 -0
- package/dist/memory/memory-manager.d.ts.map +1 -0
- package/dist/monitoring/metrics-manager.d.ts +74 -0
- package/dist/monitoring/metrics-manager.d.ts.map +1 -0
- package/dist/organization/disclosure-config-manager.d.ts +61 -0
- package/dist/organization/disclosure-config-manager.d.ts.map +1 -0
- package/dist/organization/key-rotation-manager.d.ts +63 -0
- package/dist/organization/key-rotation-manager.d.ts.map +1 -0
- package/dist/organization/organization-manager.d.ts +38 -0
- package/dist/organization/organization-manager.d.ts.map +1 -0
- package/dist/registry/access-orchestrator.d.ts +183 -0
- package/dist/registry/access-orchestrator.d.ts.map +1 -0
- package/dist/registry/action-registry-json.d.ts +1363 -0
- package/dist/registry/action-registry-json.d.ts.map +1 -0
- package/dist/registry/action-registry.d.ts +65 -0
- package/dist/registry/action-registry.d.ts.map +1 -0
- package/dist/registry/index.d.ts +4 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/revocation/revocation-manager.d.ts +98 -0
- package/dist/revocation/revocation-manager.d.ts.map +1 -0
- package/dist/state/index.d.ts +3 -0
- package/dist/state/index.d.ts.map +1 -0
- package/dist/state/json-state-store.d.ts +24 -0
- package/dist/state/json-state-store.d.ts.map +1 -0
- package/dist/state/state-store.interface.d.ts +37 -0
- package/dist/state/state-store.interface.d.ts.map +1 -0
- package/dist/storage/filesystem-key-storage.d.ts +16 -0
- package/dist/storage/filesystem-key-storage.d.ts.map +1 -0
- package/dist/storage/index.d.ts +4 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/key-storage.interface.d.ts +42 -0
- package/dist/storage/key-storage.interface.d.ts.map +1 -0
- package/dist/storage/memory-key-storage.d.ts +17 -0
- package/dist/storage/memory-key-storage.d.ts.map +1 -0
- package/dist/tool/tool-manager.d.ts +44 -0
- package/dist/tool/tool-manager.d.ts.map +1 -0
- package/dist/utils/crypto.d.ts +22 -0
- package/dist/utils/crypto.d.ts.map +1 -0
- package/dist/utils/sdjwt-client.d.ts +168 -0
- package/dist/utils/sdjwt-client.d.ts.map +1 -0
- package/dist/vc/api-vc-manager.d.ts +40 -0
- package/dist/vc/api-vc-manager.d.ts.map +1 -0
- package/dist/vc/vc-manager.d.ts +55 -0
- package/dist/vc/vc-manager.d.ts.map +1 -0
- package/dist/vp/vp-manager.d.ts +40 -0
- package/dist/vp/vp-manager.d.ts.map +1 -0
- package/package.json +2 -2
- package/dist/index.d.mts +0 -3014
|
@@ -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,11 +37,16 @@ __export(index_exports, {
|
|
|
37
37
|
AgentDIDManager: () => AgentDIDManager,
|
|
38
38
|
AgentManager: () => AgentManager,
|
|
39
39
|
AllowAllAbac: () => AllowAllAbac,
|
|
40
|
+
AuthProvider: () => AuthProvider,
|
|
40
41
|
ConstraintEvaluator: () => ConstraintEvaluator,
|
|
42
|
+
DeviceEnrollManager: () => DeviceEnrollManager,
|
|
41
43
|
DisclosureConfigManager: () => DisclosureConfigManager,
|
|
42
44
|
DummyCreds: () => DummyCreds,
|
|
43
45
|
DummyVpVerifier: () => DummyVpVerifier,
|
|
44
46
|
FilesystemKeyStorage: () => FilesystemKeyStorage,
|
|
47
|
+
GatewayClient: () => GatewayClient,
|
|
48
|
+
GatewayError: () => GatewayError,
|
|
49
|
+
JsonStateStore: () => JsonStateStore,
|
|
45
50
|
KeyManager: () => KeyManager,
|
|
46
51
|
KeyRotationManager: () => KeyRotationManager,
|
|
47
52
|
MemoryKeyStorage: () => MemoryKeyStorage,
|
|
@@ -99,26 +104,26 @@ function configure(config) {
|
|
|
99
104
|
function getConfig() {
|
|
100
105
|
return globalConfig;
|
|
101
106
|
}
|
|
102
|
-
function getDidApiUrl(
|
|
107
|
+
function getDidApiUrl(path4) {
|
|
103
108
|
const baseUrl = globalConfig.didApi?.baseUrl || process.env.DID_API_BASE_URL;
|
|
104
109
|
if (!baseUrl) {
|
|
105
110
|
throw new Error("DID API base URL not configured");
|
|
106
111
|
}
|
|
107
|
-
return `${baseUrl}${
|
|
112
|
+
return `${baseUrl}${path4}`;
|
|
108
113
|
}
|
|
109
|
-
function getIssuerApiUrl(
|
|
114
|
+
function getIssuerApiUrl(path4) {
|
|
110
115
|
const baseUrl = globalConfig.issuerApi?.baseUrl || process.env.ISSUER_API_BASE_URL;
|
|
111
116
|
if (!baseUrl) {
|
|
112
117
|
throw new Error("Issuer API base URL not configured");
|
|
113
118
|
}
|
|
114
|
-
return `${baseUrl}${
|
|
119
|
+
return `${baseUrl}${path4}`;
|
|
115
120
|
}
|
|
116
|
-
function getVerifierApiUrl(
|
|
121
|
+
function getVerifierApiUrl(path4) {
|
|
117
122
|
const baseUrl = globalConfig.verifierApi?.baseUrl || process.env.VERIFIER_API_BASE_URL;
|
|
118
123
|
if (!baseUrl) {
|
|
119
124
|
throw new Error("Verifier API base URL not configured");
|
|
120
125
|
}
|
|
121
|
-
return `${baseUrl}${
|
|
126
|
+
return `${baseUrl}${path4}`;
|
|
122
127
|
}
|
|
123
128
|
function getApiHeaders(apiType) {
|
|
124
129
|
const headers = {
|
|
@@ -965,12 +970,12 @@ var AgentDIDManager = class {
|
|
|
965
970
|
* List all agent DIDs
|
|
966
971
|
*/
|
|
967
972
|
async listAgentDIDs() {
|
|
968
|
-
const
|
|
969
|
-
const
|
|
970
|
-
const
|
|
971
|
-
const mappingDir =
|
|
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");
|
|
972
977
|
try {
|
|
973
|
-
const files = await
|
|
978
|
+
const files = await fs4.readdir(mappingDir);
|
|
974
979
|
const results = [];
|
|
975
980
|
for (const file of files) {
|
|
976
981
|
if (file.endsWith(".did")) {
|
|
@@ -991,24 +996,24 @@ var AgentDIDManager = class {
|
|
|
991
996
|
* Save agent ID -> DID mapping to persistent storage
|
|
992
997
|
*/
|
|
993
998
|
async saveAgentDIDMapping(agentId, did) {
|
|
994
|
-
const
|
|
995
|
-
const
|
|
996
|
-
const
|
|
997
|
-
const mappingDir =
|
|
998
|
-
await
|
|
999
|
-
const mappingFile =
|
|
1000
|
-
await
|
|
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");
|
|
1001
1006
|
}
|
|
1002
1007
|
/**
|
|
1003
1008
|
* Load agent ID -> DID mapping from persistent storage
|
|
1004
1009
|
*/
|
|
1005
1010
|
async loadAgentDIDMapping(agentId) {
|
|
1006
|
-
const
|
|
1007
|
-
const
|
|
1008
|
-
const
|
|
1009
|
-
const mappingFile =
|
|
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`);
|
|
1010
1015
|
try {
|
|
1011
|
-
return await
|
|
1016
|
+
return await fs4.readFile(mappingFile, "utf-8");
|
|
1012
1017
|
} catch {
|
|
1013
1018
|
return null;
|
|
1014
1019
|
}
|
|
@@ -1017,12 +1022,12 @@ var AgentDIDManager = class {
|
|
|
1017
1022
|
* Delete agent ID -> DID mapping from persistent storage
|
|
1018
1023
|
*/
|
|
1019
1024
|
async deleteAgentDIDMapping(agentId) {
|
|
1020
|
-
const
|
|
1021
|
-
const
|
|
1022
|
-
const
|
|
1023
|
-
const mappingFile =
|
|
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`);
|
|
1024
1029
|
try {
|
|
1025
|
-
await
|
|
1030
|
+
await fs4.unlink(mappingFile);
|
|
1026
1031
|
} catch {
|
|
1027
1032
|
}
|
|
1028
1033
|
}
|
|
@@ -1294,24 +1299,24 @@ var UserIdentityManager = class {
|
|
|
1294
1299
|
* Save current user DID to persistent storage
|
|
1295
1300
|
*/
|
|
1296
1301
|
async saveUserDID(did) {
|
|
1297
|
-
const
|
|
1298
|
-
const
|
|
1299
|
-
const
|
|
1300
|
-
const configDir =
|
|
1301
|
-
await
|
|
1302
|
-
const userDIDFile =
|
|
1303
|
-
await
|
|
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");
|
|
1304
1309
|
}
|
|
1305
1310
|
/**
|
|
1306
1311
|
* Load current user DID from persistent storage
|
|
1307
1312
|
*/
|
|
1308
1313
|
async loadUserDID() {
|
|
1309
|
-
const
|
|
1310
|
-
const
|
|
1311
|
-
const
|
|
1312
|
-
const userDIDFile =
|
|
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");
|
|
1313
1318
|
try {
|
|
1314
|
-
return await
|
|
1319
|
+
return await fs4.readFile(userDIDFile, "utf-8");
|
|
1315
1320
|
} catch {
|
|
1316
1321
|
return null;
|
|
1317
1322
|
}
|
|
@@ -1320,12 +1325,12 @@ var UserIdentityManager = class {
|
|
|
1320
1325
|
* Clear saved user DID
|
|
1321
1326
|
*/
|
|
1322
1327
|
async clearUserDID() {
|
|
1323
|
-
const
|
|
1324
|
-
const
|
|
1325
|
-
const
|
|
1326
|
-
const userDIDFile =
|
|
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");
|
|
1327
1332
|
try {
|
|
1328
|
-
await
|
|
1333
|
+
await fs4.unlink(userDIDFile);
|
|
1329
1334
|
} catch {
|
|
1330
1335
|
}
|
|
1331
1336
|
}
|
|
@@ -2838,6 +2843,137 @@ var UserKeyPairManager = class {
|
|
|
2838
2843
|
}
|
|
2839
2844
|
};
|
|
2840
2845
|
|
|
2846
|
+
// src/identity/device-enroll-manager.ts
|
|
2847
|
+
var DeviceEnrollManager = class {
|
|
2848
|
+
baseUrl;
|
|
2849
|
+
constructor(baseUrl) {
|
|
2850
|
+
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
|
2851
|
+
}
|
|
2852
|
+
/**
|
|
2853
|
+
* Start the device enrollment flow.
|
|
2854
|
+
* Sends the root DID public key to the Gateway and gets a user code.
|
|
2855
|
+
*
|
|
2856
|
+
* @param params - Root DID public info and client metadata
|
|
2857
|
+
* @returns Request ID, user code, and verification URL
|
|
2858
|
+
*/
|
|
2859
|
+
async startDeviceEnrollment(params) {
|
|
2860
|
+
const response = await fetch(`${this.baseUrl}/api/v1/device/start`, {
|
|
2861
|
+
method: "POST",
|
|
2862
|
+
headers: { "Content-Type": "application/json" },
|
|
2863
|
+
body: JSON.stringify({
|
|
2864
|
+
rootDid: params.rootDid,
|
|
2865
|
+
publicKeyJwk: params.publicKeyJwk,
|
|
2866
|
+
clientInfo: params.clientInfo,
|
|
2867
|
+
purpose: params.purpose || "root_did_enrollment"
|
|
2868
|
+
})
|
|
2869
|
+
});
|
|
2870
|
+
if (!response.ok) {
|
|
2871
|
+
const errorBody = await response.text();
|
|
2872
|
+
throw new Error(
|
|
2873
|
+
`Failed to start device enrollment: ${response.status} - ${errorBody}`
|
|
2874
|
+
);
|
|
2875
|
+
}
|
|
2876
|
+
const body = await response.json();
|
|
2877
|
+
if (!body.success) {
|
|
2878
|
+
throw new Error(`Failed to start device enrollment: ${JSON.stringify(body)}`);
|
|
2879
|
+
}
|
|
2880
|
+
return body.data;
|
|
2881
|
+
}
|
|
2882
|
+
/**
|
|
2883
|
+
* Start the device enrollment flow with server-side DID generation.
|
|
2884
|
+
* The server generates the real key pair on approval (not at start time).
|
|
2885
|
+
* Use this for remote/cloud-managed mode.
|
|
2886
|
+
*
|
|
2887
|
+
* @param params - Client metadata (no DID or key needed)
|
|
2888
|
+
* @returns Request ID, user code, and verification URL
|
|
2889
|
+
*/
|
|
2890
|
+
async startServerSideEnrollment(params) {
|
|
2891
|
+
const response = await fetch(`${this.baseUrl}/api/v1/device/start`, {
|
|
2892
|
+
method: "POST",
|
|
2893
|
+
headers: { "Content-Type": "application/json" },
|
|
2894
|
+
body: JSON.stringify({
|
|
2895
|
+
generateServerSide: true,
|
|
2896
|
+
clientInfo: params.clientInfo,
|
|
2897
|
+
purpose: params.purpose || "root_did_enrollment"
|
|
2898
|
+
})
|
|
2899
|
+
});
|
|
2900
|
+
if (!response.ok) {
|
|
2901
|
+
const errorBody = await response.text();
|
|
2902
|
+
throw new Error(
|
|
2903
|
+
`Failed to start device enrollment: ${response.status} - ${errorBody}`
|
|
2904
|
+
);
|
|
2905
|
+
}
|
|
2906
|
+
const body = await response.json();
|
|
2907
|
+
if (!body.success) {
|
|
2908
|
+
throw new Error(`Failed to start device enrollment: ${JSON.stringify(body)}`);
|
|
2909
|
+
}
|
|
2910
|
+
return body.data;
|
|
2911
|
+
}
|
|
2912
|
+
/**
|
|
2913
|
+
* Poll for enrollment status.
|
|
2914
|
+
* Call this periodically after startDeviceEnrollment() to check if
|
|
2915
|
+
* the user has approved the enrollment in the web UI.
|
|
2916
|
+
*
|
|
2917
|
+
* @param requestId - The request ID from startDeviceEnrollment()
|
|
2918
|
+
* @returns Current status and token if approved
|
|
2919
|
+
*/
|
|
2920
|
+
async pollDeviceEnrollment(requestId) {
|
|
2921
|
+
const response = await fetch(`${this.baseUrl}/api/v1/device/poll`, {
|
|
2922
|
+
method: "POST",
|
|
2923
|
+
headers: { "Content-Type": "application/json" },
|
|
2924
|
+
body: JSON.stringify({ requestId })
|
|
2925
|
+
});
|
|
2926
|
+
if (!response.ok) {
|
|
2927
|
+
const errorBody = await response.text();
|
|
2928
|
+
throw new Error(
|
|
2929
|
+
`Failed to poll device enrollment: ${response.status} - ${errorBody}`
|
|
2930
|
+
);
|
|
2931
|
+
}
|
|
2932
|
+
const body = await response.json();
|
|
2933
|
+
if (!body.success) {
|
|
2934
|
+
throw new Error(`Failed to poll device enrollment: ${JSON.stringify(body)}`);
|
|
2935
|
+
}
|
|
2936
|
+
return body.data;
|
|
2937
|
+
}
|
|
2938
|
+
/**
|
|
2939
|
+
* Convenience method: Start enrollment and poll until completion.
|
|
2940
|
+
* Returns the final result (approved, expired, or denied).
|
|
2941
|
+
*
|
|
2942
|
+
* @param params - Enrollment parameters (client-generated mode)
|
|
2943
|
+
* @param onUserCode - Callback when user code is available (present to user)
|
|
2944
|
+
* @param pollIntervalMs - Polling interval in ms (default: 3000)
|
|
2945
|
+
* @param maxPolls - Maximum number of poll attempts (default: 120)
|
|
2946
|
+
*/
|
|
2947
|
+
async enrollAndWait(params, onUserCode, pollIntervalMs = 3e3, maxPolls = 120) {
|
|
2948
|
+
const startResult = await this.startDeviceEnrollment(params);
|
|
2949
|
+
return this.pollUntilComplete(startResult, onUserCode, pollIntervalMs, maxPolls);
|
|
2950
|
+
}
|
|
2951
|
+
/**
|
|
2952
|
+
* Convenience method: Start server-side enrollment and poll until completion.
|
|
2953
|
+
* Returns the final result including the server-generated rootDid on approval.
|
|
2954
|
+
*
|
|
2955
|
+
* @param params - Client metadata (server-generated mode)
|
|
2956
|
+
* @param onUserCode - Callback when user code is available (present to user)
|
|
2957
|
+
* @param pollIntervalMs - Polling interval in ms (default: 3000)
|
|
2958
|
+
* @param maxPolls - Maximum number of poll attempts (default: 120)
|
|
2959
|
+
*/
|
|
2960
|
+
async enrollServerSideAndWait(params, onUserCode, pollIntervalMs = 3e3, maxPolls = 120) {
|
|
2961
|
+
const startResult = await this.startServerSideEnrollment(params);
|
|
2962
|
+
return this.pollUntilComplete(startResult, onUserCode, pollIntervalMs, maxPolls);
|
|
2963
|
+
}
|
|
2964
|
+
async pollUntilComplete(startResult, onUserCode, pollIntervalMs, maxPolls) {
|
|
2965
|
+
onUserCode(startResult);
|
|
2966
|
+
for (let i = 0; i < maxPolls; i++) {
|
|
2967
|
+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
2968
|
+
const pollResult = await this.pollDeviceEnrollment(startResult.requestId);
|
|
2969
|
+
if (pollResult.status !== "pending") {
|
|
2970
|
+
return pollResult;
|
|
2971
|
+
}
|
|
2972
|
+
}
|
|
2973
|
+
return { status: "expired" };
|
|
2974
|
+
}
|
|
2975
|
+
};
|
|
2976
|
+
|
|
2841
2977
|
// src/vc/api-vc-manager.ts
|
|
2842
2978
|
var import_ai_identity_types2 = require("@vess-id/ai-identity-types");
|
|
2843
2979
|
|
|
@@ -3895,6 +4031,303 @@ function evaluateConstraints(constraints, context, currentInvocations, expiresAt
|
|
|
3895
4031
|
return defaultConstraintEvaluator.evaluate(constraints, context, currentInvocations, expiresAt);
|
|
3896
4032
|
}
|
|
3897
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
|
+
|
|
3898
4331
|
// src/registry/action-registry.ts
|
|
3899
4332
|
var import_ajv = __toESM(require("ajv"));
|
|
3900
4333
|
var import_ajv_formats = __toESM(require("ajv-formats"));
|
|
@@ -4765,11 +5198,16 @@ var version = "0.0.1";
|
|
|
4765
5198
|
AgentDIDManager,
|
|
4766
5199
|
AgentManager,
|
|
4767
5200
|
AllowAllAbac,
|
|
5201
|
+
AuthProvider,
|
|
4768
5202
|
ConstraintEvaluator,
|
|
5203
|
+
DeviceEnrollManager,
|
|
4769
5204
|
DisclosureConfigManager,
|
|
4770
5205
|
DummyCreds,
|
|
4771
5206
|
DummyVpVerifier,
|
|
4772
5207
|
FilesystemKeyStorage,
|
|
5208
|
+
GatewayClient,
|
|
5209
|
+
GatewayError,
|
|
5210
|
+
JsonStateStore,
|
|
4773
5211
|
KeyManager,
|
|
4774
5212
|
KeyRotationManager,
|
|
4775
5213
|
MemoryKeyStorage,
|