@the-ai-company/cbio-node-runtime 1.63.7 → 1.64.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.
- package/README.md +11 -5
- package/dist/clients/agent/client.d.ts +2 -2
- package/dist/clients/agent/client.js +46 -49
- package/dist/clients/agent/client.js.map +1 -1
- package/dist/clients/agent/contracts.d.ts +5 -5
- package/dist/clients/owner/client.js +209 -195
- package/dist/clients/owner/client.js.map +1 -1
- package/dist/clients/owner/contracts.d.ts +47 -48
- package/dist/protocol/childSecretNaming.d.ts +1 -1
- package/dist/protocol/childSecretNaming.js +2 -2
- package/dist/protocol/childSecretNaming.js.map +1 -1
- package/dist/protocol/crypto.d.ts +4 -4
- package/dist/protocol/crypto.js +14 -14
- package/dist/protocol/crypto.js.map +1 -1
- package/dist/protocol/identity.d.ts +2 -2
- package/dist/protocol/identity.js +4 -4
- package/dist/protocol/identity.js.map +1 -1
- package/dist/public-types.d.ts +1 -1
- package/dist/public-types.js +1 -1
- package/dist/public-types.js.map +1 -1
- package/dist/runtime/bootstrap.d.ts +6 -6
- package/dist/runtime/bootstrap.js +26 -26
- package/dist/runtime/bootstrap.js.map +1 -1
- package/dist/runtime/identity.d.ts +6 -6
- package/dist/runtime/identity.js +14 -12
- package/dist/runtime/identity.js.map +1 -1
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.js +1 -1
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/owner-session.d.ts +1 -5
- package/dist/runtime/owner-session.js +4 -5
- package/dist/runtime/owner-session.js.map +1 -1
- package/dist/runtime/vault-metadata.d.ts +2 -2
- package/dist/runtime/vault-metadata.js +2 -2
- package/dist/runtime/vault-metadata.js.map +1 -1
- package/dist/vault-core/contracts.d.ts +235 -238
- package/dist/vault-core/contracts.js +25 -34
- package/dist/vault-core/contracts.js.map +1 -1
- package/dist/vault-core/core.d.ts +41 -42
- package/dist/vault-core/core.js +251 -274
- package/dist/vault-core/core.js.map +1 -1
- package/dist/vault-core/defaults.d.ts +25 -25
- package/dist/vault-core/defaults.js +95 -95
- package/dist/vault-core/defaults.js.map +1 -1
- package/dist/vault-core/errors.d.ts +1 -1
- package/dist/vault-core/errors.js.map +1 -1
- package/dist/vault-core/index.d.ts +2 -2
- package/dist/vault-core/index.js +2 -2
- package/dist/vault-core/index.js.map +1 -1
- package/dist/vault-core/persistence.d.ts +19 -19
- package/dist/vault-core/persistence.js +78 -67
- package/dist/vault-core/persistence.js.map +1 -1
- package/dist/vault-core/ports.d.ts +23 -23
- package/dist/vault-core/tool-metadata.js +6 -6
- package/dist/vault-core/tool-metadata.js.map +1 -1
- package/dist/vault-ingress/defaults.d.ts +2 -2
- package/dist/vault-ingress/defaults.js +10 -10
- package/dist/vault-ingress/defaults.js.map +1 -1
- package/dist/vault-ingress/index.d.ts +46 -47
- package/dist/vault-ingress/index.js +34 -37
- package/dist/vault-ingress/index.js.map +1 -1
- package/dist/vault-ingress/remote-transport.d.ts +2 -2
- package/dist/vault-ingress/remote-transport.js +27 -27
- package/dist/vault-ingress/remote-transport.js.map +1 -1
- package/docs/ARCHITECTURE.md +1 -1
- package/docs/CUSTODY_MODEL.md +3 -3
- package/docs/IDENTITY_MODEL.md +4 -4
- package/docs/REFERENCE.md +27 -2
- package/docs/api/README.md +3 -4
- package/docs/api/classes/IdentityError.md +1 -1
- package/docs/api/classes/OwnerClientError.md +1 -1
- package/docs/api/classes/PersistentVaultAgentIdentityRegistry.md +6 -6
- package/docs/api/classes/PersistentVaultAgentSecretGrantRegistry.md +12 -12
- package/docs/api/classes/PersistentVaultAuditLog.md +1 -1
- package/docs/api/classes/PersistentVaultSecretCustody.md +7 -7
- package/docs/api/classes/PersistentVaultSecretDestinationGrantRegistry.md +12 -12
- package/docs/api/classes/PersistentVaultSecretRepository.md +7 -7
- package/docs/api/classes/VaultCore.md +53 -69
- package/docs/api/classes/VaultCoreError.md +1 -1
- package/docs/api/enumerations/AuditOperation.md +137 -0
- package/docs/api/enumerations/DispatchStatus.md +1 -1
- package/docs/api/enumerations/IdentityErrorCode.md +1 -1
- package/docs/api/enumerations/OwnerClientErrorCode.md +1 -1
- package/docs/api/functions/createAgentClient.md +1 -1
- package/docs/api/functions/createIdentity.md +2 -2
- package/docs/api/functions/createOwnerClient.md +1 -1
- package/docs/api/functions/createOwnerSession.md +1 -1
- package/docs/api/functions/createPersistentVaultCoreDependencies.md +3 -3
- package/docs/api/functions/createVault.md +1 -1
- package/docs/api/functions/createVaultCore.md +1 -1
- package/docs/api/functions/createVaultCoreDependencies.md +1 -1
- package/docs/api/functions/createVaultService.md +1 -1
- package/docs/api/functions/createWorkspaceStorage.md +1 -1
- package/docs/api/functions/deriveRootAgentId.md +3 -3
- package/docs/api/functions/deriveVaultWorkingKeyFromPassword.md +4 -4
- package/docs/api/functions/getDefaultWorkspaceDir.md +1 -1
- package/docs/api/functions/handleVaultAgentControlHttp.md +1 -1
- package/docs/api/functions/handleVaultHttpDispatch.md +1 -1
- package/docs/api/functions/initializeVaultCustody.md +1 -1
- package/docs/api/functions/listVaults.md +1 -1
- package/docs/api/functions/readVaultProfile.md +3 -3
- package/docs/api/functions/recoverVault.md +4 -4
- package/docs/api/functions/recoverVaultWorkingKey.md +1 -1
- package/docs/api/functions/restoreIdentity.md +3 -3
- package/docs/api/functions/updateVaultMetadata.md +1 -1
- package/docs/api/functions/writeVaultProfile.md +3 -3
- package/docs/api/interfaces/AgentClient.md +3 -3
- package/docs/api/interfaces/AgentDispatchIntent.md +7 -7
- package/docs/api/interfaces/AgentDispatchTransport.md +1 -1
- package/docs/api/interfaces/AgentIdentity.md +3 -3
- package/docs/api/interfaces/AgentIdentityRecord.md +11 -11
- package/docs/api/interfaces/AgentRequestResult.md +9 -9
- package/docs/api/interfaces/AgentRuntimeManifest.md +13 -13
- package/docs/api/interfaces/AgentSecretGrant.md +11 -11
- package/docs/api/interfaces/AgentSigner.md +1 -1
- package/docs/api/interfaces/AgentVisibleRequestRecord.md +13 -13
- package/docs/api/interfaces/AgentVisibleSecretRecord.md +13 -13
- package/docs/api/interfaces/AuditEntry.md +45 -25
- package/docs/api/interfaces/CbioRuntime.md +10 -10
- package/docs/api/interfaces/CreateAgentClientOptions.md +1 -1
- package/docs/api/interfaces/CreateIdentityOptions.md +1 -1
- package/docs/api/interfaces/CreateOwnerClientOptions.md +3 -13
- package/docs/api/interfaces/CreateOwnerSessionOptions.md +4 -10
- package/docs/api/interfaces/CreatePersistentVaultCoreDependenciesOptions.md +3 -3
- package/docs/api/interfaces/CreateVaultOptions.md +2 -2
- package/docs/api/interfaces/CreatedVault.md +1 -1
- package/docs/api/interfaces/DefaultPolicyEngineOptions.md +9 -9
- package/docs/api/interfaces/DispatchAuthorization.md +11 -11
- package/docs/api/interfaces/DispatchInstruction.md +9 -9
- package/docs/api/interfaces/DispatchRequest.md +11 -11
- package/docs/api/interfaces/DispatchResult.md +11 -11
- package/docs/api/interfaces/IStorageProvider.md +1 -1
- package/docs/api/interfaces/InitializeVaultCustodyOptions.md +1 -1
- package/docs/api/interfaces/InitializedVaultCustody.md +1 -1
- package/docs/api/interfaces/OwnerAgentProvisionResult.md +3 -3
- package/docs/api/interfaces/OwnerClient.md +43 -11
- package/docs/api/interfaces/OwnerCreateSecretInput.md +3 -3
- package/docs/api/interfaces/OwnerRemoveSecretInput.md +3 -3
- package/docs/api/interfaces/OwnerRequestRecord.md +19 -19
- package/docs/api/interfaces/OwnerSensitiveActionConfirmation.md +1 -1
- package/docs/api/interfaces/OwnerSensitiveActionContext.md +1 -1
- package/docs/api/interfaces/OwnerSession.md +3 -3
- package/docs/api/interfaces/OwnerUpdateSecretInput.md +3 -3
- package/docs/api/interfaces/OwnerVisibleRequestRecord.md +21 -21
- package/docs/api/interfaces/RecoverVaultOptions.md +4 -4
- package/docs/api/interfaces/RecoveredVault.md +1 -1
- package/docs/api/interfaces/RequestRecord.md +19 -19
- package/docs/api/interfaces/RestoreIdentityOptions.md +1 -1
- package/docs/api/interfaces/SecretAlias.md +1 -1
- package/docs/api/interfaces/SecretDestinationGrant.md +11 -11
- package/docs/api/interfaces/SecretId.md +1 -1
- package/docs/api/interfaces/SecretRecord.md +13 -13
- package/docs/api/interfaces/Signer.md +1 -1
- package/docs/api/interfaces/VaultApproveDispatchInput.md +5 -5
- package/docs/api/interfaces/VaultAuditQueryInput.md +7 -7
- package/docs/api/interfaces/VaultCoreDependenciesOptions.md +5 -5
- package/docs/api/interfaces/VaultCreateAgentInput.md +3 -3
- package/docs/api/interfaces/VaultExportSecretInput.md +3 -3
- package/docs/api/interfaces/VaultGetRequestInput.md +5 -5
- package/docs/api/interfaces/VaultGrantAgentSecretInput.md +7 -7
- package/docs/api/interfaces/VaultGrantSecretDestinationInput.md +7 -7
- package/docs/api/interfaces/VaultId.md +1 -1
- package/docs/api/interfaces/VaultImportAgentInput.md +5 -5
- package/docs/api/interfaces/VaultIssueSessionTokenInput.md +5 -5
- package/docs/api/interfaces/VaultListAgentsInput.md +3 -3
- package/docs/api/interfaces/VaultListGrantsInput.md +7 -7
- package/docs/api/interfaces/VaultListRequestsInput.md +5 -5
- package/docs/api/interfaces/VaultListSecretsInput.md +3 -3
- package/docs/api/interfaces/VaultMetadata.md +1 -1
- package/docs/api/interfaces/VaultObject.md +1 -1
- package/docs/api/interfaces/VaultPrincipal.md +1 -1
- package/docs/api/interfaces/VaultProfile.md +1 -1
- package/docs/api/interfaces/VaultReadAgentPrivateKeyInput.md +5 -5
- package/docs/api/interfaces/VaultReadSecretPlaintextInput.md +3 -3
- package/docs/api/interfaces/VaultRevokeAgentSecretInput.md +7 -7
- package/docs/api/interfaces/VaultRevokeSecretDestinationInput.md +7 -7
- package/docs/api/interfaces/VaultRevokeSessionTokenInput.md +1 -1
- package/docs/api/interfaces/VaultService.md +8 -24
- package/docs/api/interfaces/VaultUpdateAgentInput.md +5 -5
- package/docs/api/type-aliases/AgentId.md +1 -1
- package/docs/api/type-aliases/CbioRuntimeModule.md +1 -1
- package/docs/api/type-aliases/DispatchApprovalDecision.md +1 -1
- package/docs/api/type-aliases/GrantStatus.md +1 -1
- package/docs/api/type-aliases/SecretLifecycleStatus.md +1 -1
- package/docs/api/type-aliases/VaultPrincipalKind.md +1 -1
- package/docs/api/variables/DEFAULT_VAULT_KEY_CUSTODY_BLOB_KEY.md +1 -1
- package/docs/zh/README.md +9 -3
- package/examples/process-isolation.ts +21 -21
- package/package.json +2 -2
- package/docs/api/enumerations/AuditAction.md +0 -143
- package/docs/api/enumerations/AuditOutcome.md +0 -35
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
import { OwnerClientError, OwnerClientErrorCode } from "../../errors.js";
|
|
2
2
|
import { createRequestIdValue, } from "../../internal/id-factory.js";
|
|
3
3
|
import { createIdentity, restoreIdentity } from "../../runtime/identity.js";
|
|
4
|
-
import { SystemClock } from "../../vault-core/index.js";
|
|
4
|
+
import { SystemClock, VaultCoreError } from "../../vault-core/index.js";
|
|
5
5
|
const VAULT_MASTER_ID = "vault-master";
|
|
6
6
|
class DefaultOwnerClient {
|
|
7
7
|
_vault;
|
|
8
|
-
_rootAgentIdInput;
|
|
9
|
-
_signer;
|
|
10
8
|
_clock;
|
|
11
9
|
_skipWarmup;
|
|
12
|
-
|
|
10
|
+
_password_verifier;
|
|
13
11
|
_sensitiveActionVerifier;
|
|
14
|
-
|
|
15
|
-
constructor(_vault,
|
|
12
|
+
_root_agent_id;
|
|
13
|
+
constructor(_vault, _clock = new SystemClock(), _skipWarmup = false, _password_verifier, _sensitiveActionVerifier) {
|
|
16
14
|
this._vault = _vault;
|
|
17
|
-
this._rootAgentIdInput = _rootAgentIdInput;
|
|
18
|
-
this._signer = _signer;
|
|
19
15
|
this._clock = _clock;
|
|
20
16
|
this._skipWarmup = _skipWarmup;
|
|
21
|
-
this.
|
|
17
|
+
this._password_verifier = _password_verifier;
|
|
22
18
|
this._sensitiveActionVerifier = _sensitiveActionVerifier;
|
|
23
|
-
this.
|
|
19
|
+
this._root_agent_id = VAULT_MASTER_ID;
|
|
24
20
|
}
|
|
25
21
|
async _confirmSensitiveAction(confirmation, context) {
|
|
26
22
|
const normalizedPassword = confirmation.password.trim();
|
|
@@ -37,60 +33,81 @@ class DefaultOwnerClient {
|
|
|
37
33
|
}
|
|
38
34
|
return;
|
|
39
35
|
}
|
|
40
|
-
if (!this.
|
|
41
|
-
throw new OwnerClientError(OwnerClientErrorCode.SENSITIVE_ACTION_VERIFIER_REQUIRED, "OwnerClient: sensitiveActionVerifier or
|
|
36
|
+
if (!this._password_verifier) {
|
|
37
|
+
throw new OwnerClientError(OwnerClientErrorCode.SENSITIVE_ACTION_VERIFIER_REQUIRED, "OwnerClient: sensitiveActionVerifier or password_verifier is required for sensitive reads");
|
|
42
38
|
}
|
|
43
|
-
const valid = await this.
|
|
39
|
+
const valid = await this._password_verifier(normalizedPassword);
|
|
44
40
|
if (!valid) {
|
|
45
41
|
throw new OwnerClientError(OwnerClientErrorCode.SENSITIVE_ACTION_INVALID_PASSWORD, "invalid vault password");
|
|
46
42
|
}
|
|
47
43
|
}
|
|
48
44
|
async ownerCreateSecret(input) {
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
},
|
|
59
|
-
alias:
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
45
|
+
const isBatch = Array.isArray(input);
|
|
46
|
+
const items = isBatch ? input : [input];
|
|
47
|
+
const requested_at = this._clock.nowIso();
|
|
48
|
+
// Phase 1: 并行校验(所有别名不得已存在)
|
|
49
|
+
// 通过 ownerListSecrets 获取当前所有别名,批量对比,避免逐个网络往返
|
|
50
|
+
const existing = await this._vault.ownerListSecrets({ vault_id: this._vault.vault_id, owner: { kind: "owner", id: this._root_agent_id } });
|
|
51
|
+
const existingAliases = new Set(existing.map(s => s.alias.value));
|
|
52
|
+
const duplicates = items.filter(item => existingAliases.has(item.alias));
|
|
53
|
+
if (duplicates.length > 0) {
|
|
54
|
+
const names = duplicates.map(d => `"${d.alias}"`).join(", ");
|
|
55
|
+
throw new VaultCoreError(`secret alias already exists: ${names}`, "VAULT_ALIAS_ALREADY_EXISTS");
|
|
56
|
+
}
|
|
57
|
+
// Phase 2: 并行写入(校验全过才到这里)
|
|
58
|
+
const results = await Promise.all(items.map(item => {
|
|
59
|
+
return this._vault.ownerCreateSecret({
|
|
60
|
+
kind: "owner.create_secret",
|
|
61
|
+
vault_id: this._vault.vault_id,
|
|
62
|
+
request_id: createRequestIdValue("create_secret"),
|
|
63
|
+
owner: { kind: "owner", id: this._root_agent_id },
|
|
64
|
+
alias: item.alias,
|
|
65
|
+
plaintext: item.plaintext,
|
|
66
|
+
source: { kind: "manual" },
|
|
67
|
+
requested_at: item.requested_at ?? requested_at,
|
|
68
|
+
});
|
|
69
|
+
}));
|
|
70
|
+
return isBatch ? results : results[0];
|
|
64
71
|
}
|
|
65
72
|
async ownerUpdateSecret(input) {
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
73
|
+
const isBatch = Array.isArray(input);
|
|
74
|
+
const items = isBatch ? input : [input];
|
|
75
|
+
const requested_at = this._clock.nowIso();
|
|
76
|
+
// Phase 1: 并行校验(所有别名必须已存在)
|
|
77
|
+
const existing = await this._vault.ownerListSecrets({ vault_id: this._vault.vault_id, owner: { kind: "owner", id: this._root_agent_id } });
|
|
78
|
+
const existingAliases = new Set(existing.map(s => s.alias.value));
|
|
79
|
+
const missing = items.filter(item => !existingAliases.has(item.alias));
|
|
80
|
+
if (missing.length > 0) {
|
|
81
|
+
const names = missing.map(d => `"${d.alias}"`).join(", ");
|
|
82
|
+
throw new VaultCoreError(`secret not found: ${names}`, "VAULT_SECRET_NOT_FOUND");
|
|
83
|
+
}
|
|
84
|
+
// Phase 2: 并行写入
|
|
85
|
+
const results = await Promise.all(items.map(item => {
|
|
86
|
+
return this._vault.ownerUpdateSecret({
|
|
87
|
+
kind: "owner.update_secret",
|
|
88
|
+
vault_id: this._vault.vault_id,
|
|
89
|
+
request_id: createRequestIdValue("update_secret"),
|
|
90
|
+
owner: { kind: "owner", id: this._root_agent_id },
|
|
91
|
+
alias: item.alias,
|
|
92
|
+
plaintext: item.plaintext,
|
|
93
|
+
source: { kind: "manual" },
|
|
94
|
+
requested_at: item.requested_at ?? requested_at,
|
|
95
|
+
});
|
|
96
|
+
}));
|
|
97
|
+
return isBatch ? results : results[0];
|
|
81
98
|
}
|
|
82
99
|
async ownerReadAudit(query = {}) {
|
|
83
|
-
const
|
|
84
|
-
const
|
|
100
|
+
const requested_at = this._clock.nowIso();
|
|
101
|
+
const request_id = createRequestIdValue("read_audit");
|
|
85
102
|
return this._vault.ownerReadAudit({
|
|
86
|
-
|
|
103
|
+
vault_id: this._vault.vault_id,
|
|
87
104
|
actor: {
|
|
88
105
|
kind: "owner",
|
|
89
|
-
id: this.
|
|
106
|
+
id: this._root_agent_id,
|
|
90
107
|
},
|
|
91
|
-
query: { ...query,
|
|
92
|
-
|
|
93
|
-
|
|
108
|
+
query: { ...query, vault_id: this._vault.vault_id.value },
|
|
109
|
+
request_id,
|
|
110
|
+
requested_at,
|
|
94
111
|
});
|
|
95
112
|
}
|
|
96
113
|
async ownerExportSecret(input) {
|
|
@@ -101,17 +118,17 @@ class DefaultOwnerClient {
|
|
|
101
118
|
action: "export_secret",
|
|
102
119
|
subject: input.alias,
|
|
103
120
|
});
|
|
104
|
-
const
|
|
105
|
-
const
|
|
121
|
+
const requested_at = input.requested_at ?? this._clock.nowIso();
|
|
122
|
+
const request_id = createRequestIdValue("export_secret");
|
|
106
123
|
return this._vault.ownerExportSecret({
|
|
107
|
-
|
|
124
|
+
vault_id: this._vault.vault_id,
|
|
108
125
|
actor: {
|
|
109
126
|
kind: "owner",
|
|
110
|
-
id: this.
|
|
127
|
+
id: this._root_agent_id,
|
|
111
128
|
},
|
|
112
129
|
alias: input.alias,
|
|
113
|
-
|
|
114
|
-
|
|
130
|
+
request_id,
|
|
131
|
+
requested_at,
|
|
115
132
|
});
|
|
116
133
|
}
|
|
117
134
|
async ownerReadSecretPlaintext(input) {
|
|
@@ -123,14 +140,14 @@ class DefaultOwnerClient {
|
|
|
123
140
|
subject: input.alias,
|
|
124
141
|
});
|
|
125
142
|
const exported = await this._vault.ownerExportSecret({
|
|
126
|
-
|
|
143
|
+
vault_id: this._vault.vault_id,
|
|
127
144
|
actor: {
|
|
128
145
|
kind: "owner",
|
|
129
|
-
id: this.
|
|
146
|
+
id: this._root_agent_id,
|
|
130
147
|
},
|
|
131
148
|
alias: input.alias,
|
|
132
|
-
|
|
133
|
-
|
|
149
|
+
request_id: createRequestIdValue("read_secret_plaintext"),
|
|
150
|
+
requested_at: input.requested_at ?? this._clock.nowIso(),
|
|
134
151
|
});
|
|
135
152
|
return exported.plaintext;
|
|
136
153
|
}
|
|
@@ -140,161 +157,161 @@ class DefaultOwnerClient {
|
|
|
140
157
|
verificationCode: input.verificationCode,
|
|
141
158
|
}, {
|
|
142
159
|
action: "read_agent_private_key",
|
|
143
|
-
subject: input.
|
|
160
|
+
subject: input.root_agent_id,
|
|
144
161
|
});
|
|
145
162
|
const agents = await this._vault.ownerListAgents({
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
163
|
+
vault_id: this._vault.vault_id,
|
|
164
|
+
request_id: createRequestIdValue("read_agent_private_key"),
|
|
165
|
+
requested_at: input.requested_at ?? this._clock.nowIso(),
|
|
149
166
|
actor: {
|
|
150
167
|
kind: "owner",
|
|
151
|
-
id: this.
|
|
168
|
+
id: this._root_agent_id,
|
|
152
169
|
},
|
|
153
170
|
});
|
|
154
|
-
const agent = agents.find((record) => record.
|
|
155
|
-
if (!agent?.
|
|
171
|
+
const agent = agents.find((record) => record.root_agent_id === input.root_agent_id);
|
|
172
|
+
if (!agent?.private_key) {
|
|
156
173
|
throw new OwnerClientError(OwnerClientErrorCode.AGENT_PRIVATE_KEY_NOT_FOUND, "agent private key not found");
|
|
157
174
|
}
|
|
158
|
-
return agent.
|
|
175
|
+
return agent.private_key;
|
|
159
176
|
}
|
|
160
177
|
async _ownerRegisterManagedAgentIdentity(input) {
|
|
161
|
-
const
|
|
162
|
-
const
|
|
178
|
+
const requested_at = input.requested_at ?? this._clock.nowIso();
|
|
179
|
+
const request_id = createRequestIdValue("register_agent.identity");
|
|
163
180
|
const agentRecord = {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
181
|
+
vault_id: this._vault.vault_id,
|
|
182
|
+
root_agent_id: input.root_agent_id,
|
|
183
|
+
public_key: input.public_key,
|
|
184
|
+
private_key: input.private_key,
|
|
168
185
|
metadata: input.metadata,
|
|
169
186
|
nickname: input.nickname,
|
|
170
187
|
};
|
|
171
188
|
await this._vault.ownerRegisterAgentIdentity({
|
|
172
|
-
|
|
173
|
-
|
|
189
|
+
vault_id: this._vault.vault_id,
|
|
190
|
+
request_id,
|
|
174
191
|
owner: {
|
|
175
192
|
kind: "owner",
|
|
176
|
-
id: this.
|
|
193
|
+
id: this._root_agent_id,
|
|
177
194
|
},
|
|
178
195
|
agentRecord,
|
|
179
|
-
|
|
196
|
+
requested_at,
|
|
180
197
|
});
|
|
181
198
|
return agentRecord;
|
|
182
199
|
}
|
|
183
200
|
async ownerImportAgent(input) {
|
|
184
|
-
const identity = restoreIdentity(input.
|
|
201
|
+
const identity = restoreIdentity(input.private_key, { nickname: input.nickname });
|
|
185
202
|
const agent = await this._ownerRegisterManagedAgentIdentity({
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
203
|
+
root_agent_id: identity.root_agent_id,
|
|
204
|
+
public_key: identity.public_key,
|
|
205
|
+
private_key: identity.private_key,
|
|
189
206
|
metadata: input.metadata,
|
|
190
207
|
nickname: input.nickname,
|
|
191
|
-
|
|
208
|
+
requested_at: input.requested_at,
|
|
192
209
|
});
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
210
|
+
const session_token = await this.ownerIssueSessionToken({
|
|
211
|
+
root_agent_id: agent.root_agent_id,
|
|
212
|
+
requested_at: input.requested_at,
|
|
196
213
|
});
|
|
197
214
|
return {
|
|
198
215
|
agent: {
|
|
199
216
|
...agent,
|
|
200
|
-
|
|
217
|
+
private_key: undefined,
|
|
201
218
|
},
|
|
202
|
-
|
|
219
|
+
session_token,
|
|
203
220
|
};
|
|
204
221
|
}
|
|
205
222
|
async ownerCreateAgent(input) {
|
|
206
223
|
const identity = createIdentity();
|
|
207
224
|
const agent = await this._ownerRegisterManagedAgentIdentity({
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
225
|
+
root_agent_id: identity.root_agent_id,
|
|
226
|
+
public_key: identity.public_key,
|
|
227
|
+
private_key: identity.private_key,
|
|
211
228
|
metadata: input.metadata,
|
|
212
229
|
nickname: input.nickname,
|
|
213
|
-
|
|
230
|
+
requested_at: input.requested_at,
|
|
214
231
|
});
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
232
|
+
const session_token = await this.ownerIssueSessionToken({
|
|
233
|
+
root_agent_id: agent.root_agent_id,
|
|
234
|
+
requested_at: input.requested_at,
|
|
218
235
|
});
|
|
219
236
|
return {
|
|
220
237
|
agent: {
|
|
221
238
|
...agent,
|
|
222
|
-
|
|
239
|
+
private_key: undefined,
|
|
223
240
|
},
|
|
224
|
-
|
|
241
|
+
session_token,
|
|
225
242
|
};
|
|
226
243
|
}
|
|
227
244
|
async ownerUpdateAgent(input) {
|
|
228
|
-
const
|
|
229
|
-
const
|
|
245
|
+
const requested_at = input.requested_at ?? this._clock.nowIso();
|
|
246
|
+
const request_id = createRequestIdValue("update_agent.identity");
|
|
230
247
|
const updated = await this._vault.ownerUpdateAgentIdentity({
|
|
231
|
-
|
|
232
|
-
|
|
248
|
+
vault_id: this._vault.vault_id,
|
|
249
|
+
request_id,
|
|
233
250
|
owner: {
|
|
234
251
|
kind: "owner",
|
|
235
|
-
id: this.
|
|
252
|
+
id: this._root_agent_id,
|
|
236
253
|
},
|
|
237
254
|
metadata: input.metadata,
|
|
238
|
-
|
|
255
|
+
root_agent_id: input.root_agent_id,
|
|
239
256
|
nickname: input.nickname,
|
|
240
|
-
|
|
257
|
+
requested_at,
|
|
241
258
|
});
|
|
242
259
|
return {
|
|
243
260
|
...updated,
|
|
244
|
-
|
|
261
|
+
private_key: undefined,
|
|
245
262
|
};
|
|
246
263
|
}
|
|
247
264
|
async ownerGrantAgentSecret(input) {
|
|
248
|
-
const
|
|
265
|
+
const requested_at = input.requested_at ?? this._clock.nowIso();
|
|
249
266
|
return this._vault.ownerGrantAgentSecret({
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
actor: { kind: "owner", id: this.
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
267
|
+
vault_id: this._vault.vault_id,
|
|
268
|
+
request_id: createRequestIdValue("grant_agent_secret"),
|
|
269
|
+
actor: { kind: "owner", id: this._root_agent_id },
|
|
270
|
+
root_agent_id: input.root_agent_id,
|
|
271
|
+
secret_alias: input.secret_alias,
|
|
272
|
+
requested_at,
|
|
256
273
|
});
|
|
257
274
|
}
|
|
258
275
|
async ownerGrantSecretDestination(input) {
|
|
259
|
-
const
|
|
276
|
+
const requested_at = input.requested_at ?? this._clock.nowIso();
|
|
260
277
|
return this._vault.ownerGrantSecretDestination({
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
actor: { kind: "owner", id: this.
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
278
|
+
vault_id: this._vault.vault_id,
|
|
279
|
+
request_id: createRequestIdValue("grant_secret_destination"),
|
|
280
|
+
actor: { kind: "owner", id: this._root_agent_id },
|
|
281
|
+
secret_alias: input.secret_alias,
|
|
282
|
+
site_id: input.site_id,
|
|
283
|
+
requested_at,
|
|
267
284
|
});
|
|
268
285
|
}
|
|
269
286
|
async ownerRevokeAgentSecret(input) {
|
|
270
|
-
const
|
|
287
|
+
const requested_at = input.requested_at ?? this._clock.nowIso();
|
|
271
288
|
return this._vault.ownerRevokeAgentSecret({
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
actor: { kind: "owner", id: this.
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
289
|
+
vault_id: this._vault.vault_id,
|
|
290
|
+
request_id: createRequestIdValue("revoke_agent_secret"),
|
|
291
|
+
actor: { kind: "owner", id: this._root_agent_id },
|
|
292
|
+
root_agent_id: input.root_agent_id,
|
|
293
|
+
secret_alias: input.secret_alias,
|
|
294
|
+
requested_at,
|
|
278
295
|
});
|
|
279
296
|
}
|
|
280
297
|
async ownerRevokeSecretDestination(input) {
|
|
281
|
-
const
|
|
298
|
+
const requested_at = input.requested_at ?? this._clock.nowIso();
|
|
282
299
|
return this._vault.ownerRevokeSecretDestination({
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
actor: { kind: "owner", id: this.
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
300
|
+
vault_id: this._vault.vault_id,
|
|
301
|
+
request_id: createRequestIdValue("revoke_secret_destination"),
|
|
302
|
+
actor: { kind: "owner", id: this._root_agent_id },
|
|
303
|
+
secret_alias: input.secret_alias,
|
|
304
|
+
site_id: input.site_id,
|
|
305
|
+
requested_at,
|
|
289
306
|
});
|
|
290
307
|
}
|
|
291
308
|
async ownerListGrants(input = {}) {
|
|
292
|
-
const
|
|
309
|
+
const requested_at = this._clock.nowIso();
|
|
293
310
|
return this._vault.ownerListGrants({
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
actor: { kind: "owner", id: this.
|
|
297
|
-
|
|
311
|
+
vault_id: this._vault.vault_id,
|
|
312
|
+
request_id: createRequestIdValue("list_grants"),
|
|
313
|
+
actor: { kind: "owner", id: this._root_agent_id },
|
|
314
|
+
requested_at,
|
|
298
315
|
});
|
|
299
316
|
}
|
|
300
317
|
async ownerRemoveSecret(input) {
|
|
@@ -305,94 +322,94 @@ class DefaultOwnerClient {
|
|
|
305
322
|
action: "delete_secret",
|
|
306
323
|
subject: input.alias,
|
|
307
324
|
});
|
|
308
|
-
const
|
|
309
|
-
const
|
|
325
|
+
const requested_at = input.requested_at ?? this._clock.nowIso();
|
|
326
|
+
const request_id = createRequestIdValue("remove_secret");
|
|
310
327
|
await this._vault.ownerRemoveSecret({
|
|
311
328
|
kind: "owner.remove_secret",
|
|
312
|
-
|
|
313
|
-
|
|
329
|
+
vault_id: this._vault.vault_id,
|
|
330
|
+
request_id,
|
|
314
331
|
owner: {
|
|
315
332
|
kind: "owner",
|
|
316
|
-
id: this.
|
|
333
|
+
id: this._root_agent_id,
|
|
317
334
|
},
|
|
318
335
|
alias: input.alias,
|
|
319
|
-
|
|
336
|
+
requested_at,
|
|
320
337
|
});
|
|
321
338
|
}
|
|
322
339
|
async ownerListAgents(input = {}) {
|
|
323
|
-
const
|
|
324
|
-
const
|
|
340
|
+
const requested_at = input.requested_at ?? this._clock.nowIso();
|
|
341
|
+
const request_id = createRequestIdValue("list_agents");
|
|
325
342
|
const agents = await this._vault.ownerListAgents({
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
343
|
+
vault_id: this._vault.vault_id,
|
|
344
|
+
request_id,
|
|
345
|
+
requested_at,
|
|
329
346
|
actor: {
|
|
330
347
|
kind: "owner",
|
|
331
|
-
id: this.
|
|
348
|
+
id: this._root_agent_id,
|
|
332
349
|
},
|
|
333
350
|
});
|
|
334
351
|
return agents.map((agent) => ({
|
|
335
352
|
...agent,
|
|
336
|
-
|
|
353
|
+
private_key: undefined,
|
|
337
354
|
}));
|
|
338
355
|
}
|
|
339
356
|
async ownerListRequests(input = {}) {
|
|
340
|
-
const
|
|
341
|
-
const
|
|
357
|
+
const requested_at = input.requested_at ?? this._clock.nowIso();
|
|
358
|
+
const request_id = createRequestIdValue("list_requests");
|
|
342
359
|
return this._vault.ownerListRequests({
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
actor: { kind: "owner", id: this.
|
|
347
|
-
|
|
360
|
+
vault_id: this._vault.vault_id,
|
|
361
|
+
request_id,
|
|
362
|
+
requested_at,
|
|
363
|
+
actor: { kind: "owner", id: this._root_agent_id },
|
|
364
|
+
root_agent_id: input.root_agent_id,
|
|
348
365
|
});
|
|
349
366
|
}
|
|
350
367
|
async ownerGetRequest(input) {
|
|
351
|
-
const
|
|
352
|
-
const
|
|
368
|
+
const requested_at = input.requested_at ?? this._clock.nowIso();
|
|
369
|
+
const request_id = createRequestIdValue("get_request");
|
|
353
370
|
return this._vault.ownerGetRequest({
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
371
|
+
vault_id: this._vault.vault_id,
|
|
372
|
+
request_id,
|
|
373
|
+
requested_at,
|
|
357
374
|
actor: {
|
|
358
375
|
kind: "owner",
|
|
359
|
-
id: this.
|
|
376
|
+
id: this._root_agent_id,
|
|
360
377
|
},
|
|
361
|
-
|
|
378
|
+
target_request_id: input.request_id,
|
|
362
379
|
});
|
|
363
380
|
}
|
|
364
381
|
async ownerListSecrets(input = {}) {
|
|
365
|
-
const
|
|
366
|
-
const
|
|
382
|
+
const requested_at = input.requested_at ?? this._clock.nowIso();
|
|
383
|
+
const request_id = createRequestIdValue("list_secrets");
|
|
367
384
|
return this._vault.ownerListSecrets({
|
|
368
|
-
|
|
385
|
+
vault_id: this._vault.vault_id,
|
|
369
386
|
owner: {
|
|
370
387
|
kind: "owner",
|
|
371
|
-
id: this.
|
|
388
|
+
id: this._root_agent_id,
|
|
372
389
|
},
|
|
373
|
-
|
|
390
|
+
request_id,
|
|
374
391
|
});
|
|
375
392
|
}
|
|
376
393
|
async ownerIssueSessionToken(input) {
|
|
377
|
-
const
|
|
378
|
-
const
|
|
394
|
+
const requested_at = input.requested_at ?? this._clock.nowIso();
|
|
395
|
+
const request_id = createRequestIdValue("issue_session_token");
|
|
379
396
|
return this._vault.ownerIssueSessionToken({
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
397
|
+
vault_id: this._vault.vault_id,
|
|
398
|
+
request_id,
|
|
399
|
+
root_agent_id: input.root_agent_id,
|
|
383
400
|
actor: {
|
|
384
401
|
kind: "owner",
|
|
385
|
-
id: this.
|
|
402
|
+
id: this._root_agent_id,
|
|
386
403
|
},
|
|
387
|
-
|
|
404
|
+
requested_at,
|
|
388
405
|
});
|
|
389
406
|
}
|
|
390
407
|
async ownerRevokeSessionToken(input) {
|
|
391
408
|
return this._vault.ownerRevokeSessionToken({
|
|
392
|
-
|
|
409
|
+
vault_id: this._vault.vault_id,
|
|
393
410
|
actor: {
|
|
394
411
|
kind: "owner",
|
|
395
|
-
id: this.
|
|
412
|
+
id: this._root_agent_id,
|
|
396
413
|
},
|
|
397
414
|
token: input.token,
|
|
398
415
|
});
|
|
@@ -400,27 +417,27 @@ class DefaultOwnerClient {
|
|
|
400
417
|
async ownerIssueAllSessionTokens() {
|
|
401
418
|
return this._vault.ownerIssueAllAgentSessionTokens({
|
|
402
419
|
kind: "owner",
|
|
403
|
-
id: this.
|
|
420
|
+
id: this._root_agent_id,
|
|
404
421
|
});
|
|
405
422
|
}
|
|
406
423
|
async ownerApproveDispatch(input) {
|
|
407
|
-
const
|
|
424
|
+
const requested_at = this._clock.nowIso();
|
|
408
425
|
return this._vault.ownerApproveDispatch({
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
actor: { kind: "owner", id: this.
|
|
426
|
+
vault_id: this._vault.vault_id,
|
|
427
|
+
request_id: input.request_id,
|
|
428
|
+
actor: { kind: "owner", id: this._root_agent_id },
|
|
412
429
|
decision: input.decision,
|
|
413
|
-
|
|
430
|
+
requested_at,
|
|
414
431
|
});
|
|
415
432
|
}
|
|
416
|
-
async ownerDenyDispatch(
|
|
417
|
-
const
|
|
433
|
+
async ownerDenyDispatch(request_id) {
|
|
434
|
+
const requested_at = this._clock.nowIso();
|
|
418
435
|
await this._vault.ownerApproveDispatch({
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
actor: { kind: "owner", id: this.
|
|
436
|
+
vault_id: this._vault.vault_id,
|
|
437
|
+
request_id,
|
|
438
|
+
actor: { kind: "owner", id: this._root_agent_id },
|
|
422
439
|
decision: "deny",
|
|
423
|
-
|
|
440
|
+
requested_at,
|
|
424
441
|
});
|
|
425
442
|
}
|
|
426
443
|
ownerOnPendingDispatch(callback) {
|
|
@@ -428,10 +445,7 @@ class DefaultOwnerClient {
|
|
|
428
445
|
}
|
|
429
446
|
}
|
|
430
447
|
export async function createOwnerClient(options) {
|
|
431
|
-
const
|
|
432
|
-
const rootAgentId = identity.rootAgentId;
|
|
433
|
-
const client = new DefaultOwnerClient(options.vault, rootAgentId, undefined, // signer no longer directly used in simple owner client
|
|
434
|
-
options.clock ?? new SystemClock(), options.skipWarmup ?? false, options.passwordVerifier, options.sensitiveActionVerifier);
|
|
448
|
+
const client = new DefaultOwnerClient(options.vault, options.clock ?? new SystemClock(), options.skipWarmup ?? false, options.password_verifier, options.sensitiveActionVerifier);
|
|
435
449
|
if (!options.skipWarmup) {
|
|
436
450
|
try {
|
|
437
451
|
await client.ownerIssueAllSessionTokens();
|