@the-ai-company/cbio-node-runtime 0.31.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 (70) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +46 -0
  3. package/dist/agent/agent.d.ts +234 -0
  4. package/dist/agent/agent.js +565 -0
  5. package/dist/agent/agent.js.map +1 -0
  6. package/dist/audit/ActivityLog.d.ts +25 -0
  7. package/dist/audit/ActivityLog.js +66 -0
  8. package/dist/audit/ActivityLog.js.map +1 -0
  9. package/dist/errors.d.ts +28 -0
  10. package/dist/errors.js +37 -0
  11. package/dist/errors.js.map +1 -0
  12. package/dist/http/authClient.d.ts +26 -0
  13. package/dist/http/authClient.js +132 -0
  14. package/dist/http/authClient.js.map +1 -0
  15. package/dist/http/localAuthProxy.d.ts +33 -0
  16. package/dist/http/localAuthProxy.js +93 -0
  17. package/dist/http/localAuthProxy.js.map +1 -0
  18. package/dist/http/secretAcquisition.d.ts +54 -0
  19. package/dist/http/secretAcquisition.js +177 -0
  20. package/dist/http/secretAcquisition.js.map +1 -0
  21. package/dist/protocol/childSecretNaming.d.ts +7 -0
  22. package/dist/protocol/childSecretNaming.js +12 -0
  23. package/dist/protocol/childSecretNaming.js.map +1 -0
  24. package/dist/protocol/crypto.d.ts +23 -0
  25. package/dist/protocol/crypto.js +37 -0
  26. package/dist/protocol/crypto.js.map +1 -0
  27. package/dist/protocol/identity.d.ts +8 -0
  28. package/dist/protocol/identity.js +16 -0
  29. package/dist/protocol/identity.js.map +1 -0
  30. package/dist/runtime/index.d.ts +14 -0
  31. package/dist/runtime/index.js +11 -0
  32. package/dist/runtime/index.js.map +1 -0
  33. package/dist/sealed/index.d.ts +6 -0
  34. package/dist/sealed/index.js +6 -0
  35. package/dist/sealed/index.js.map +1 -0
  36. package/dist/sealed/seal.d.ts +19 -0
  37. package/dist/sealed/seal.js +56 -0
  38. package/dist/sealed/seal.js.map +1 -0
  39. package/dist/storage/fs.d.ts +16 -0
  40. package/dist/storage/fs.js +68 -0
  41. package/dist/storage/fs.js.map +1 -0
  42. package/dist/storage/memory.d.ts +11 -0
  43. package/dist/storage/memory.js +19 -0
  44. package/dist/storage/memory.js.map +1 -0
  45. package/dist/storage/provider.d.ts +12 -0
  46. package/dist/storage/provider.js +6 -0
  47. package/dist/storage/provider.js.map +1 -0
  48. package/dist/vault/secretPolicy.d.ts +3 -0
  49. package/dist/vault/secretPolicy.js +14 -0
  50. package/dist/vault/secretPolicy.js.map +1 -0
  51. package/dist/vault/vault.d.ts +91 -0
  52. package/dist/vault/vault.js +534 -0
  53. package/dist/vault/vault.js.map +1 -0
  54. package/docs/ARCHITECTURE.md +100 -0
  55. package/docs/REFERENCE.md +184 -0
  56. package/docs/TODO-multi-vault.md +29 -0
  57. package/docs/WORKS_WITH_CUSTOM_FETCH.md +196 -0
  58. package/docs/es/README.md +27 -0
  59. package/docs/fr/README.md +27 -0
  60. package/docs/ja/README.md +27 -0
  61. package/docs/ko/README.md +27 -0
  62. package/docs/pt/README.md +27 -0
  63. package/docs/spec/runtime/README.md +27 -0
  64. package/docs/spec/runtime/activity-log.md +67 -0
  65. package/docs/spec/runtime/managed-agent-record.md +52 -0
  66. package/docs/spec/runtime/merge-rules.md +52 -0
  67. package/docs/spec/runtime/secret-origin-policy.md +46 -0
  68. package/docs/zh/README.md +27 -0
  69. package/examples/minimal.ts +13 -0
  70. package/package.json +57 -0
@@ -0,0 +1,565 @@
1
+ import { derivePublicKey, LocalSigner, generateIdentityKeys } from "../protocol/crypto.js";
2
+ import { CbioVault } from "../vault/vault.js";
3
+ import { AuthClient } from "../http/authClient.js";
4
+ import { SecretAcquisition, } from "../http/secretAcquisition.js";
5
+ import { getChildIdentitySecretName, deriveRootAgentId, getVaultPath } from "../protocol/identity.js";
6
+ import { createIdentityRef, signIssuedAgentIdentity, signRevocationRecord, verifyIssuedAgentIdentity, verifyRevocationRecord, } from "@the-ai-company/cbio-protocol";
7
+ import { IdentityError, IdentityErrorCode } from "../errors.js";
8
+ const identityVaults = new WeakMap();
9
+ function getIssuedCapabilitiesFromRecord(record) {
10
+ if (!record || typeof record !== "object")
11
+ return null;
12
+ const issuedIdentity = record.issuedIdentity;
13
+ if (!issuedIdentity || typeof issuedIdentity !== "object")
14
+ return null;
15
+ const capabilities = issuedIdentity.capabilities;
16
+ if (capabilities === undefined)
17
+ return [];
18
+ if (!Array.isArray(capabilities))
19
+ return null;
20
+ for (const cap of capabilities) {
21
+ if (typeof cap !== "string" || !VALID_ISSUED_CAPABILITY_NAMES.has(cap))
22
+ return null;
23
+ }
24
+ return capabilities;
25
+ }
26
+ const VALID_ISSUED_CAPABILITY_NAMES = new Set([
27
+ "vault:list",
28
+ "vault:fetch",
29
+ "vault:acquire",
30
+ "admin:secrets",
31
+ "admin:issue",
32
+ "identity:sign",
33
+ ]);
34
+ function capabilityToRuntimePermission(capability) {
35
+ return capability;
36
+ }
37
+ /**
38
+ * CbioIdentity
39
+ *
40
+ * The primary Identity container. Represents an agent's identity and its associated vault.
41
+ * This is the high-privilege handle that contains administrative capabilities (.admin)
42
+ * and private keys.
43
+ */
44
+ export class CbioIdentity {
45
+ signer;
46
+ _vault;
47
+ admin;
48
+ agentId;
49
+ publicKey;
50
+ #issuedIdentity;
51
+ _authClient;
52
+ _secretAcquisition;
53
+ constructor(signer, _vault, agentId, publicKey) {
54
+ this.signer = signer;
55
+ this._vault = _vault;
56
+ this.agentId = agentId || "";
57
+ this.publicKey = publicKey || "";
58
+ const appendLog = (entry) => this._vault.appendActivityLogEntry(entry);
59
+ this._authClient = new AuthClient(this._vault, this.signer, appendLog);
60
+ this._secretAcquisition = new SecretAcquisition(this._vault, appendLog);
61
+ this.admin = new CbioAdmin(this, this._vault);
62
+ identityVaults.set(this, this._vault);
63
+ }
64
+ #bindIssuedIdentity(issuedIdentity) {
65
+ if (!verifyIssuedAgentIdentity(issuedIdentity)) {
66
+ throw new IdentityError(IdentityErrorCode.ISSUED_IDENTITY_INVALID, `Issued identity for '${this.publicKey}' failed protocol verification.`);
67
+ }
68
+ if (issuedIdentity.agent.public_key !== this.publicKey) {
69
+ throw new IdentityError(IdentityErrorCode.ISSUED_IDENTITY_INVALID, `Issued identity public_key does not match identity public key.`);
70
+ }
71
+ if (issuedIdentity.agent.agent_id !== this.agentId) {
72
+ throw new IdentityError(IdentityErrorCode.ISSUED_IDENTITY_INVALID, `Issued identity agent_id does not match identity agent id.`);
73
+ }
74
+ this.#issuedIdentity = issuedIdentity;
75
+ }
76
+ /**
77
+ * Primary entry point: Load identity from keys and initialize vault.
78
+ */
79
+ static async load(keys, options) {
80
+ const opts = options ?? {};
81
+ const priv = keys.privateKey;
82
+ const pub = keys.publicKey || derivePublicKey(priv);
83
+ const agentId = deriveRootAgentId(pub);
84
+ const signer = new LocalSigner({ publicKey: pub, privateKey: priv });
85
+ const identity = new CbioIdentity(signer, new CbioVault(), agentId, pub);
86
+ const storageKey = opts.storageKey ?? getVaultPath(pub);
87
+ const activityLogKeyIsDerived = opts.activityLog?.enabled !== false && opts.activityLog?.key === undefined;
88
+ const activityLogKey = opts.activityLog?.enabled === false
89
+ ? undefined
90
+ : (opts.activityLog?.key ?? storageKey.replace(/\.enc$/, "") + ".activity.jsonl");
91
+ await identity._vault.initFromStorage(signer, storageKey, opts.storage, activityLogKey, activityLogKeyIsDerived);
92
+ if (opts.issuedIdentity)
93
+ identity.#bindIssuedIdentity(opts.issuedIdentity);
94
+ return identity;
95
+ }
96
+ async fetchWithAuth(secretName, url, options) {
97
+ return this._authClient.fetchWithAuth(secretName, url, options ?? {});
98
+ }
99
+ createFetchWithAuth(secretName) {
100
+ return this._authClient.createFetchWithAuth(secretName);
101
+ }
102
+ async getPublicKey() {
103
+ return this.publicKey || this.signer.getPublicKey();
104
+ }
105
+ async getAgentId() {
106
+ return this.agentId || deriveRootAgentId(await this.getPublicKey());
107
+ }
108
+ async fetchJsonAndAddSecret(options) {
109
+ return this._secretAcquisition.fetchJsonAndAddSecret(options);
110
+ }
111
+ async fetchJsonAndUpdateSecret(options) {
112
+ return this._secretAcquisition.fetchJsonAndUpdateSecret(options);
113
+ }
114
+ hasSecret(secretName) {
115
+ return this._vault.hasSecret(secretName);
116
+ }
117
+ listSecretNames() {
118
+ return this._vault.listSecretNames();
119
+ }
120
+ /**
121
+ * Register a newly created child identity to the parent vault.
122
+ * @returns The child's publicKey (domain-level identifier). Use getChildIdentitySecretName(publicKey) from the protocol subpath for low-level vault access.
123
+ */
124
+ async registerChildIdentity(keys, options) {
125
+ return this.admin.children.registerChildIdentity(keys, options);
126
+ }
127
+ async authenticate(nonce) {
128
+ return this.signer.sign(nonce);
129
+ }
130
+ /**
131
+ * Create a standard Agent handle for this identity.
132
+ * The Agent handle DOES NOT have an .admin property and does not expose the signer/private key.
133
+ * This is the recommended handle to pass to an autonomous LLM.
134
+ *
135
+ * By default this returns a minimally privileged handle (`vault:fetch`, `vault:list`).
136
+ * Runtime permissions are only widened when passed explicitly or when
137
+ * `deriveFromIssuedIdentity` is set to `true`.
138
+ */
139
+ getAgent(options) {
140
+ const opts = options ?? {};
141
+ let finalPerms = opts.permissions;
142
+ if (!finalPerms && opts.deriveFromIssuedIdentity) {
143
+ finalPerms = {};
144
+ for (const cap of this.#issuedIdentity?.capabilities ?? []) {
145
+ finalPerms[capabilityToRuntimePermission(cap)] = true;
146
+ }
147
+ finalPerms["vault:fetch"] = true;
148
+ finalPerms["vault:list"] = true;
149
+ }
150
+ return new CbioAgent(this._authClient, this._secretAcquisition, this.agentId, this.publicKey, finalPerms);
151
+ }
152
+ }
153
+ /**
154
+ * CbioAgent
155
+ *
156
+ * A safety-wrapped version of an Identity designed for autonomous LLMs.
157
+ * It provides only the Standard facet (fetchWithAuth, etc.) by default and hides
158
+ * all administrative capabilities and private keys.
159
+ */
160
+ export class CbioAgent {
161
+ agentId;
162
+ publicKey;
163
+ #authClient;
164
+ #secretAcquisition;
165
+ #permissions;
166
+ constructor(authClient, secretAcquisition, agentId, publicKey, permissions) {
167
+ this.agentId = agentId;
168
+ this.publicKey = publicKey;
169
+ this.#authClient = authClient;
170
+ this.#secretAcquisition = secretAcquisition;
171
+ // Default to a restricted worker (vault:fetch, vault:list) if no permissions specified
172
+ this.#permissions = permissions || { "vault:fetch": true, "vault:list": true };
173
+ }
174
+ /**
175
+ * View the runtime permissions granted to this handle.
176
+ */
177
+ get permissions() {
178
+ return Object.freeze({ ...this.#permissions });
179
+ }
180
+ _checkPermission(permission) {
181
+ if (!this.#permissions[permission]) {
182
+ throw new IdentityError(IdentityErrorCode.PERMISSION_DENIED, `Agent handle does not have '${permission}' permission.`);
183
+ }
184
+ }
185
+ async fetchWithAuth(secretName, url, options) {
186
+ // vault:fetch is required for network auth
187
+ this._checkPermission("vault:fetch");
188
+ return this.#authClient.fetchWithAuth(secretName, url, options ?? {});
189
+ }
190
+ createFetchWithAuth(secretName) {
191
+ this._checkPermission("vault:fetch");
192
+ return this.#authClient.createFetchWithAuth(secretName);
193
+ }
194
+ async getPublicKey() {
195
+ return this.publicKey;
196
+ }
197
+ async getAgentId() {
198
+ return this.agentId;
199
+ }
200
+ async fetchJsonAndAddSecret(options) {
201
+ this._checkPermission("vault:acquire");
202
+ return this.#secretAcquisition.fetchJsonAndAddSecret(options);
203
+ }
204
+ async fetchJsonAndUpdateSecret(options) {
205
+ this._checkPermission("vault:acquire");
206
+ return this.#secretAcquisition.fetchJsonAndUpdateSecret(options);
207
+ }
208
+ hasSecret(secretName) {
209
+ this._checkPermission("vault:list");
210
+ return this.#secretAcquisition.hasSecret(secretName);
211
+ }
212
+ listSecretNames() {
213
+ this._checkPermission("vault:list");
214
+ return this.#secretAcquisition.listSecretNames();
215
+ }
216
+ /**
217
+ * Check if this agent handle has the specified runtime permission.
218
+ */
219
+ can(permission) {
220
+ return !!this.#permissions[permission];
221
+ }
222
+ }
223
+ /**
224
+ * CbioManagementFacet
225
+ *
226
+ * Provides administrative (high-risk) capabilities for a CbioIdentity.
227
+ */
228
+ class ManagedAgentSupport {
229
+ _identity;
230
+ _vault;
231
+ constructor(_identity, _vault) {
232
+ this._identity = _identity;
233
+ this._vault = _vault;
234
+ }
235
+ getSecret(secretName) {
236
+ return this._vault.getSecret(secretName);
237
+ }
238
+ async addSecret(secretName, secretValue, options) {
239
+ await this._vault.addSecret(secretName, secretValue, options);
240
+ }
241
+ _getManagedAgentRecord(publicKey) {
242
+ const secretName = getChildIdentitySecretName(publicKey);
243
+ const stored = this.getSecret(secretName);
244
+ if (!stored)
245
+ return null;
246
+ try {
247
+ const parsed = JSON.parse(stored);
248
+ return parsed;
249
+ }
250
+ catch {
251
+ return null;
252
+ }
253
+ }
254
+ _getManagedAgentRevocation(publicKey) {
255
+ const revocationKey = `cbio:revocation:${publicKey}`;
256
+ const stored = this.getSecret(revocationKey);
257
+ if (!stored)
258
+ return null;
259
+ try {
260
+ const parsed = JSON.parse(stored);
261
+ if (!verifyRevocationRecord(parsed))
262
+ return null;
263
+ if (parsed.issuer.public_key !== this._identity.publicKey)
264
+ return null;
265
+ if (parsed.issuer.agent_id !== this._identity.agentId)
266
+ return null;
267
+ if (parsed.target.kind !== "issued_agent_identity")
268
+ return null;
269
+ if (parsed.target.subject_agent_id !== deriveRootAgentId(publicKey))
270
+ return null;
271
+ const record = this._getManagedAgentRecord(publicKey);
272
+ const expectedSequence = record?.issuedIdentity?.issuance?.sequence;
273
+ if (expectedSequence !== undefined && parsed.target.sequence !== expectedSequence)
274
+ return null;
275
+ return parsed;
276
+ }
277
+ catch {
278
+ return null;
279
+ }
280
+ }
281
+ _isManagedAgentRevoked(publicKey) {
282
+ return this._getManagedAgentRevocation(publicKey) !== null;
283
+ }
284
+ _assertManagedAgentNotRevoked(publicKey) {
285
+ if (this._isManagedAgentRevoked(publicKey)) {
286
+ throw new IdentityError(IdentityErrorCode.PERMISSION_DENIED, `Managed agent '${publicKey}' has been revoked and cannot be loaded.`);
287
+ }
288
+ }
289
+ }
290
+ export class CbioVaultAdmin {
291
+ _identity;
292
+ _vault;
293
+ constructor(_identity, _vault) {
294
+ this._identity = _identity;
295
+ this._vault = _vault;
296
+ }
297
+ async addSecret(secretName, secretValue, options) {
298
+ await this._vault.addSecret(secretName, secretValue, options);
299
+ }
300
+ getSecret(secretName) {
301
+ return this._vault.getSecret(secretName);
302
+ }
303
+ hasSecret(secretName) {
304
+ return this._vault.hasSecret(secretName);
305
+ }
306
+ async deleteSecret(secretName) {
307
+ await this._vault.deleteSecret(secretName);
308
+ }
309
+ async setSecretAllowedOrigins(secretName, allowedOrigins) {
310
+ await this._vault.setSecretAllowedOrigins(secretName, allowedOrigins);
311
+ }
312
+ async getActivityLog() {
313
+ return this._vault.getActivityLog();
314
+ }
315
+ async getActivityLogMetadata() {
316
+ return this._vault.getActivityLogMetadata();
317
+ }
318
+ async mergeFrom(otherIdentity, options) {
319
+ const otherVault = identityVaults.get(otherIdentity);
320
+ if (!otherVault) {
321
+ throw new IdentityError(IdentityErrorCode.MERGE_IDENTITY_MISMATCH, "The source identity is not bound to a mergeable vault instance.");
322
+ }
323
+ return this._vault.mergeFrom(otherVault, options);
324
+ }
325
+ seal(kdk) {
326
+ return this._vault.seal(kdk);
327
+ }
328
+ loadFromSealedBlob(kdk, sealedBlob) {
329
+ this._vault.unseal(kdk, sealedBlob);
330
+ }
331
+ async serializeToBlob() {
332
+ return this._vault.serializeToBlob(this._identity.signer);
333
+ }
334
+ async saveVault() {
335
+ await this._vault.save(this._identity.signer);
336
+ }
337
+ /**
338
+ * One-time save of the vault to the given storage key.
339
+ * Does NOT change the bound storage for subsequent saveVault() or autosave.
340
+ * Binding is set during identity load (initFromStorage/initFromBlob).
341
+ */
342
+ async saveVaultAs(storageKey) {
343
+ await this._vault.save(this._identity.signer, storageKey);
344
+ }
345
+ }
346
+ export class CbioManagedAgentAdmin extends ManagedAgentSupport {
347
+ getManagedAgentCapabilities(publicKey) {
348
+ const record = this._getManagedAgentRecord(publicKey);
349
+ if (!record)
350
+ return { status: "missing", capabilities: [] };
351
+ if (this._isManagedAgentRevoked(publicKey)) {
352
+ return { status: "revoked", capabilities: [] };
353
+ }
354
+ const capabilities = getIssuedCapabilitiesFromRecord(record);
355
+ if (!capabilities) {
356
+ return { status: "invalid", capabilities: [] };
357
+ }
358
+ return { status: "active", capabilities };
359
+ }
360
+ async revokeManagedAgent(publicKey, reason) {
361
+ const secretName = getChildIdentitySecretName(publicKey);
362
+ if (!this._vault.hasSecret(secretName)) {
363
+ throw new IdentityError(IdentityErrorCode.SECRET_NOT_FOUND, `Managed agent with public key '${publicKey}' not found in this vault.`);
364
+ }
365
+ if (!(this._identity.signer instanceof LocalSigner)) {
366
+ throw new IdentityError(IdentityErrorCode.SIGNER_REQUIRES_PRIVATE_KEY, "Authority must have a LocalSigner to sign revocation records.");
367
+ }
368
+ const issuerPublicKey = await this._identity.getPublicKey();
369
+ const managedRecord = this._getManagedAgentRecord(publicKey);
370
+ const targetSequence = managedRecord?.issuedIdentity?.issuance?.sequence ?? 1;
371
+ const unsignedRevocation = {
372
+ cbio_protocol: "v1.0",
373
+ kind: "revocation_record",
374
+ issuer: createIdentityRef(issuerPublicKey),
375
+ target: {
376
+ kind: "issued_agent_identity",
377
+ subject_agent_id: deriveRootAgentId(publicKey),
378
+ sequence: targetSequence,
379
+ },
380
+ revocation: {
381
+ revoked_at: new Date().toISOString(),
382
+ reason,
383
+ },
384
+ };
385
+ const signedRevocation = signRevocationRecord(this._identity.signer.exportPrivateKey(), unsignedRevocation);
386
+ // Store the revocation record
387
+ const revocationKey = `cbio:revocation:${publicKey}`;
388
+ await this._vault.addSecret(revocationKey, JSON.stringify(signedRevocation));
389
+ }
390
+ async issueManagedAgent(options) {
391
+ const opts = options ?? {};
392
+ const issue = opts.issue ?? {};
393
+ const handle = opts.handle ?? {};
394
+ const storage = opts.storage ?? {};
395
+ const keys = issue.keys ?? generateIdentityKeys();
396
+ const publicKey = keys.publicKey || derivePublicKey(keys.privateKey);
397
+ const agentId = deriveRootAgentId(publicKey);
398
+ const secretName = issue.secretName ?? getChildIdentitySecretName(publicKey);
399
+ if (!(this._identity.signer instanceof LocalSigner)) {
400
+ throw new IdentityError(IdentityErrorCode.SIGNER_REQUIRES_PRIVATE_KEY, "CbioIdentity must have a LocalSigner to issue managed agents (requires private key access for signing).");
401
+ }
402
+ const issuerPublicKey = await this._identity.getPublicKey();
403
+ const unsignedIdentity = {
404
+ cbio_protocol: "v1.0",
405
+ kind: "issued_agent_identity",
406
+ agent: createIdentityRef(publicKey),
407
+ authority: createIdentityRef(issuerPublicKey),
408
+ issuance: {
409
+ issued_at: new Date().toISOString(),
410
+ sequence: 1,
411
+ },
412
+ capabilities: issue.issuedCapabilities,
413
+ };
414
+ const issuedIdentity = signIssuedAgentIdentity(this._identity.signer.exportPrivateKey(), unsignedIdentity);
415
+ const storageKey = storage.storageKey ?? getVaultPath(publicKey);
416
+ const record = {
417
+ agentId,
418
+ publicKey,
419
+ privateKey: keys.privateKey,
420
+ issuedIdentity,
421
+ storageKey,
422
+ };
423
+ const stored = JSON.stringify(record);
424
+ if (this._vault.hasSecret(secretName)) {
425
+ await this._vault.updateSecret(secretName, stored);
426
+ }
427
+ else {
428
+ await this._vault.addSecret(secretName, stored);
429
+ }
430
+ const childIdentity = await CbioIdentity.load({ privateKey: keys.privateKey, publicKey }, {
431
+ storage: storage.storage,
432
+ storageKey,
433
+ activityLog: storage.activityLog,
434
+ issuedIdentity,
435
+ });
436
+ return {
437
+ agentId,
438
+ publicKey,
439
+ agent: childIdentity.getAgent({ permissions: handle.runtimePermissions }),
440
+ };
441
+ }
442
+ async loadManagedAgent(publicKey, options) {
443
+ const opts = options ?? {};
444
+ this._assertManagedAgentNotRevoked(publicKey);
445
+ const secretName = getChildIdentitySecretName(publicKey);
446
+ const stored = this.getSecret(secretName);
447
+ if (!stored) {
448
+ throw new IdentityError(IdentityErrorCode.SECRET_NOT_FOUND, `Managed agent identity '${publicKey}' is not registered in this authority vault.`);
449
+ }
450
+ let parsed;
451
+ try {
452
+ parsed = JSON.parse(stored);
453
+ }
454
+ catch {
455
+ throw new IdentityError(IdentityErrorCode.ISSUED_IDENTITY_INVALID, `Managed agent identity '${publicKey}' is malformed in authority vault.`);
456
+ }
457
+ if (!parsed.privateKey || !parsed.publicKey || !parsed.issuedIdentity) {
458
+ throw new IdentityError(IdentityErrorCode.ISSUED_IDENTITY_INVALID, `Managed agent identity '${publicKey}' is malformed in authority vault.`);
459
+ }
460
+ // Verify protocol alignment
461
+ if (!verifyIssuedAgentIdentity(parsed.issuedIdentity)) {
462
+ throw new IdentityError(IdentityErrorCode.ISSUED_IDENTITY_INVALID, `Managed agent identity '${publicKey}' failed protocol verification.`);
463
+ }
464
+ const derivedPublicKey = derivePublicKey(parsed.privateKey);
465
+ const derivedAgentId = deriveRootAgentId(parsed.publicKey);
466
+ const authorityPublicKey = await this._identity.getPublicKey();
467
+ const authorityAgentId = await this._identity.getAgentId();
468
+ const issuedPublicKey = parsed.issuedIdentity.agent?.public_key;
469
+ const issuedAgentId = parsed.issuedIdentity.agent?.agent_id;
470
+ const issuedAuthorityPublicKey = parsed.issuedIdentity.authority?.public_key;
471
+ const issuedAuthorityAgentId = parsed.issuedIdentity.authority?.agent_id;
472
+ if (parsed.publicKey !== publicKey) {
473
+ throw new IdentityError(IdentityErrorCode.ISSUED_IDENTITY_INVALID, `Managed agent identity '${publicKey}' record publicKey does not match requested public key.`);
474
+ }
475
+ if (derivedPublicKey !== parsed.publicKey) {
476
+ throw new IdentityError(IdentityErrorCode.ISSUED_IDENTITY_INVALID, `Managed agent identity '${publicKey}' contains a privateKey/publicKey mismatch.`);
477
+ }
478
+ if ((parsed.agentId ?? derivedAgentId) !== derivedAgentId) {
479
+ throw new IdentityError(IdentityErrorCode.ISSUED_IDENTITY_INVALID, `Managed agent identity '${publicKey}' contains an invalid agentId.`);
480
+ }
481
+ if (issuedPublicKey !== parsed.publicKey) {
482
+ throw new IdentityError(IdentityErrorCode.ISSUED_IDENTITY_INVALID, `Managed agent identity '${publicKey}' issuedIdentity public_key does not match record publicKey.`);
483
+ }
484
+ if (issuedAgentId !== derivedAgentId) {
485
+ throw new IdentityError(IdentityErrorCode.ISSUED_IDENTITY_INVALID, `Managed agent identity '${publicKey}' issuedIdentity agent_id does not match record agentId.`);
486
+ }
487
+ if (issuedAuthorityPublicKey !== authorityPublicKey) {
488
+ throw new IdentityError(IdentityErrorCode.ISSUED_IDENTITY_INVALID, `Managed agent identity '${publicKey}' issuedIdentity authority public_key does not match this authority.`);
489
+ }
490
+ if (issuedAuthorityAgentId !== authorityAgentId) {
491
+ throw new IdentityError(IdentityErrorCode.ISSUED_IDENTITY_INVALID, `Managed agent identity '${publicKey}' issuedIdentity authority agent_id does not match this authority.`);
492
+ }
493
+ const storageKey = parsed.storageKey ?? opts.storage?.storageKey ?? getVaultPath(parsed.publicKey);
494
+ const childIdentity = await CbioIdentity.load({ privateKey: parsed.privateKey, publicKey: parsed.publicKey }, {
495
+ storage: opts.storage?.storage,
496
+ storageKey,
497
+ activityLog: opts.storage?.activityLog,
498
+ issuedIdentity: parsed.issuedIdentity,
499
+ });
500
+ return {
501
+ agentId: parsed.agentId ?? deriveRootAgentId(parsed.publicKey),
502
+ publicKey: parsed.publicKey,
503
+ agent: childIdentity.getAgent({ permissions: opts.handle?.runtimePermissions }),
504
+ };
505
+ }
506
+ }
507
+ export class CbioChildIdentityAdmin {
508
+ _identity;
509
+ _vault;
510
+ constructor(_identity, _vault) {
511
+ this._identity = _identity;
512
+ this._vault = _vault;
513
+ }
514
+ /**
515
+ * Registers a child identity in the parent vault.
516
+ * @returns The child's publicKey (domain-level identifier). Use getChildIdentitySecretName from @the-ai-company/cbio-node-runtime/protocol for vault lookups.
517
+ */
518
+ async registerChildIdentity(keys, options) {
519
+ if (!keys.privateKey)
520
+ throw new IdentityError(IdentityErrorCode.CHILD_IDENTITY_REQUIRES_PRIVATE_KEY, "Child identity requires privateKey.");
521
+ if (!(this._identity.signer instanceof LocalSigner)) {
522
+ throw new IdentityError(IdentityErrorCode.SIGNER_REQUIRES_PRIVATE_KEY, "CbioIdentity must have a LocalSigner to register child identities (requires private key access for signing).");
523
+ }
524
+ const pub = keys.publicKey || derivePublicKey(keys.privateKey);
525
+ const secretName = getChildIdentitySecretName(pub);
526
+ const issuerPublicKey = await this._identity.getPublicKey();
527
+ const unsignedIdentity = {
528
+ cbio_protocol: "v1.0",
529
+ kind: "issued_agent_identity",
530
+ agent: createIdentityRef(pub),
531
+ authority: createIdentityRef(issuerPublicKey),
532
+ issuance: {
533
+ issued_at: new Date().toISOString(),
534
+ sequence: 1,
535
+ },
536
+ capabilities: options?.issuedCapabilities,
537
+ };
538
+ const issuedIdentity = signIssuedAgentIdentity(this._identity.signer.exportPrivateKey(), unsignedIdentity);
539
+ const record = {
540
+ agentId: deriveRootAgentId(pub),
541
+ publicKey: pub,
542
+ privateKey: keys.privateKey,
543
+ issuedIdentity,
544
+ };
545
+ const stored = JSON.stringify(record);
546
+ if (this._vault.hasSecret(secretName)) {
547
+ await this._vault.updateSecret(secretName, stored);
548
+ }
549
+ else {
550
+ await this._vault.addSecret(secretName, stored);
551
+ }
552
+ return { publicKey: pub };
553
+ }
554
+ }
555
+ export class CbioAdmin {
556
+ vault;
557
+ managedAgents;
558
+ children;
559
+ constructor(identity, vault) {
560
+ this.vault = new CbioVaultAdmin(identity, vault);
561
+ this.managedAgents = new CbioManagedAgentAdmin(identity, vault);
562
+ this.children = new CbioChildIdentityAdmin(identity, vault);
563
+ }
564
+ }
565
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/agent/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,eAAe,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC5G,OAAO,EAAE,SAAS,EAAuC,MAAM,mBAAmB,CAAC;AACnF,OAAO,EAAE,UAAU,EAA6B,MAAM,uBAAuB,CAAC;AAC9E,OAAO,EACL,iBAAiB,GAIlB,MAAM,8BAA8B,CAAC;AAEtC,OAAO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GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;YACtC,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QACrD,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QAClD,CAAC;QACD,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;IAC5B,CAAC;CACF;AAED,MAAM,OAAO,SAAS;IACJ,KAAK,CAAiB;IACtB,aAAa,CAAwB;IACrC,QAAQ,CAAyB;IAEjD,YAAY,QAAsB,EAAE,KAAgB;QAClD,IAAI,CAAC,KAAK,GAAG,IAAI,cAAc,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QACjD,IAAI,CAAC,aAAa,GAAG,IAAI,qBAAqB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAChE,IAAI,CAAC,QAAQ,GAAG,IAAI,sBAAsB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC9D,CAAC;CACF"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * ActivityLog
3
+ *
4
+ * Audit log for fetchWithAuth/fetchJsonAndAddSecret/fetchJsonAndUpdateSecret. Separate from vault.
5
+ * No sensitive data. For dashboard/UI display. Optional, can be disabled.
6
+ * First line is metadata (_meta) for consumer identification.
7
+ */
8
+ import type { IStorageProvider } from '../storage/provider.js';
9
+ export interface ActivityLogMetadata {
10
+ v: number;
11
+ agentId: string;
12
+ storageKey: string;
13
+ }
14
+ export interface ActivityLogEntry {
15
+ ts: number;
16
+ action: 'fetchWithAuth' | 'fetchJsonAndAddSecret' | 'fetchJsonAndUpdateSecret';
17
+ secretName: string;
18
+ url: string;
19
+ method: string;
20
+ success: boolean;
21
+ error?: string;
22
+ }
23
+ export declare function appendActivityLog(storage: IStorageProvider, key: string, entry: ActivityLogEntry, metadata?: ActivityLogMetadata): Promise<void>;
24
+ export declare function readActivityLog(storage: IStorageProvider, key: string): Promise<ActivityLogEntry[]>;
25
+ export declare function readActivityLogMetadata(storage: IStorageProvider, key: string): Promise<ActivityLogMetadata | null>;